aboutsummaryrefslogtreecommitdiffstats
path: root/src/window.c
diff options
context:
space:
mode:
authorKen Raeburn2015-11-01 01:42:21 -0400
committerKen Raeburn2015-11-01 01:42:21 -0400
commit39372e1a1032521be74575bb06f95a3898fbae30 (patch)
tree754bd242a23d2358ea116126fcb0a629947bd9ec /src/window.c
parent6a3121904d76e3b2f63007341d48c5c1af55de80 (diff)
parente11aaee266da52937a3a031cb108fe13f68958c3 (diff)
downloademacs-39372e1a1032521be74575bb06f95a3898fbae30.tar.gz
emacs-39372e1a1032521be74575bb06f95a3898fbae30.zip
merge from trunk
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c2776
1 files changed, 1704 insertions, 1072 deletions
diff --git a/src/window.c b/src/window.c
index b02b30cd0b2..91a066d6f13 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-2013 Free Software 3 Copyright (C) 1985-1987, 1993-1998, 2000-2015 Free Software
4 Foundation, Inc. 4 Foundation, Inc.
5 5
6This file is part of GNU Emacs. 6This file is part of GNU Emacs.
@@ -20,12 +20,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 20
21#include <config.h> 21#include <config.h>
22 22
23#define WINDOW_INLINE EXTERN_INLINE
24
25#include <stdio.h> 23#include <stdio.h>
26 24
27#include "lisp.h" 25#include "lisp.h"
28#include "character.h"
29#include "buffer.h" 26#include "buffer.h"
30#include "keyboard.h" 27#include "keyboard.h"
31#include "keymap.h" 28#include "keymap.h"
@@ -37,54 +34,27 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
37#include "disptab.h" 34#include "disptab.h"
38#include "dispextern.h" 35#include "dispextern.h"
39#include "blockinput.h" 36#include "blockinput.h"
40#include "intervals.h"
41#include "termhooks.h" /* For FRAME_TERMINAL. */ 37#include "termhooks.h" /* For FRAME_TERMINAL. */
42 38#ifdef HAVE_WINDOW_SYSTEM
43#ifdef HAVE_X_WINDOWS 39#include TERM_HEADER
44#include "xterm.h" 40#endif /* HAVE_WINDOW_SYSTEM */
45#endif /* HAVE_X_WINDOWS */
46#ifdef HAVE_NTGUI
47#include "w32term.h"
48#endif
49#ifdef MSDOS 41#ifdef MSDOS
50#include "msdos.h" 42#include "msdos.h"
51#endif 43#endif
52#ifdef HAVE_NS
53#include "nsterm.h"
54#endif
55 44
56Lisp_Object Qwindowp, Qwindow_live_p; 45static ptrdiff_t count_windows (struct window *);
57static Lisp_Object Qwindow_valid_p; 46static ptrdiff_t get_leaf_windows (struct window *, struct window **,
58static Lisp_Object Qwindow_configuration_p; 47 ptrdiff_t);
59static Lisp_Object Qrecord_window_buffer; 48static void window_scroll_pixel_based (Lisp_Object, int, bool, bool);
60static Lisp_Object Qwindow_deletable_p, Qdelete_window, Qdisplay_buffer; 49static void window_scroll_line_based (Lisp_Object, int, bool, bool);
61static Lisp_Object Qreplace_buffer_in_windows, Qget_mru_window;
62static Lisp_Object Qwindow_resize_root_window, Qwindow_resize_root_window_vertically;
63static Lisp_Object Qscroll_up, Qscroll_down, Qscroll_command;
64static Lisp_Object Qsafe, Qabove, Qbelow, Qwindow_size, Qclone_of;
65
66static int displayed_window_lines (struct window *);
67static int count_windows (struct window *);
68static int get_leaf_windows (struct window *, struct window **, int);
69static void window_scroll (Lisp_Object, EMACS_INT, bool, int);
70static void window_scroll_pixel_based (Lisp_Object, int, bool, int);
71static void window_scroll_line_based (Lisp_Object, int, bool, int);
72static Lisp_Object window_list (void);
73static int add_window_to_list (struct window *, void *);
74static Lisp_Object next_window (Lisp_Object, Lisp_Object,
75 Lisp_Object, int);
76static void decode_next_window_args (Lisp_Object *, Lisp_Object *,
77 Lisp_Object *);
78static void foreach_window (struct frame *, 50static void foreach_window (struct frame *,
79 int (* fn) (struct window *, void *), 51 bool (* fn) (struct window *, void *),
80 void *); 52 void *);
81static int foreach_window_1 (struct window *, 53static bool foreach_window_1 (struct window *,
82 int (* fn) (struct window *, void *), 54 bool (* fn) (struct window *, void *),
83 void *); 55 void *);
84static Lisp_Object window_list_1 (Lisp_Object, Lisp_Object, Lisp_Object); 56static bool window_resize_check (struct window *, bool);
85static int window_resize_check (struct window *, bool);
86static void window_resize_apply (struct window *, bool); 57static void window_resize_apply (struct window *, bool);
87static Lisp_Object select_window (Lisp_Object, Lisp_Object, int);
88static void select_window_1 (Lisp_Object, bool); 58static void select_window_1 (Lisp_Object, bool);
89 59
90static struct window *set_window_fringes (struct window *, Lisp_Object, 60static struct window *set_window_fringes (struct window *, Lisp_Object,
@@ -92,7 +62,8 @@ static struct window *set_window_fringes (struct window *, Lisp_Object,
92static struct window *set_window_margins (struct window *, Lisp_Object, 62static struct window *set_window_margins (struct window *, Lisp_Object,
93 Lisp_Object); 63 Lisp_Object);
94static struct window *set_window_scroll_bars (struct window *, Lisp_Object, 64static struct window *set_window_scroll_bars (struct window *, Lisp_Object,
95 Lisp_Object, Lisp_Object); 65 Lisp_Object, Lisp_Object,
66 Lisp_Object);
96static void apply_window_adjustment (struct window *); 67static void apply_window_adjustment (struct window *);
97 68
98/* This is the window in which the terminal's cursor should 69/* This is the window in which the terminal's cursor should
@@ -119,16 +90,10 @@ Lisp_Object minibuf_window;
119 shown as the selected window when the minibuffer is selected. */ 90 shown as the selected window when the minibuffer is selected. */
120Lisp_Object minibuf_selected_window; 91Lisp_Object minibuf_selected_window;
121 92
122/* Hook run at end of temp_output_buffer_show. */ 93/* Incremented for each window created. */
123static Lisp_Object Qtemp_buffer_show_hook; 94static EMACS_INT sequence_number;
124
125/* Nonzero after init_window_once has finished. */
126static int window_initialized;
127
128/* Hook to run when window config changes. */
129static Lisp_Object Qwindow_configuration_change_hook;
130 95
131/* Used by the function window_scroll_pixel_based */ 96/* Used by the function window_scroll_pixel_based. */
132static int window_scroll_pixel_based_preserve_x; 97static int window_scroll_pixel_based_preserve_x;
133static int window_scroll_pixel_based_preserve_y; 98static int window_scroll_pixel_based_preserve_y;
134 99
@@ -148,66 +113,85 @@ wset_combination_limit (struct window *w, Lisp_Object val)
148{ 113{
149 w->combination_limit = val; 114 w->combination_limit = val;
150} 115}
116
151static void 117static void
152wset_dedicated (struct window *w, Lisp_Object val) 118wset_dedicated (struct window *w, Lisp_Object val)
153{ 119{
154 w->dedicated = val; 120 w->dedicated = val;
155} 121}
122
156static void 123static void
157wset_display_table (struct window *w, Lisp_Object val) 124wset_display_table (struct window *w, Lisp_Object val)
158{ 125{
159 w->display_table = val; 126 w->display_table = val;
160} 127}
128
161static void 129static void
162wset_new_normal (struct window *w, Lisp_Object val) 130wset_new_normal (struct window *w, Lisp_Object val)
163{ 131{
164 w->new_normal = val; 132 w->new_normal = val;
165} 133}
134
166static void 135static void
167wset_new_total (struct window *w, Lisp_Object val) 136wset_new_total (struct window *w, Lisp_Object val)
168{ 137{
169 w->new_total = val; 138 w->new_total = val;
170} 139}
140
171static void 141static void
172wset_normal_cols (struct window *w, Lisp_Object val) 142wset_normal_cols (struct window *w, Lisp_Object val)
173{ 143{
174 w->normal_cols = val; 144 w->normal_cols = val;
175} 145}
146
176static void 147static void
177wset_normal_lines (struct window *w, Lisp_Object val) 148wset_normal_lines (struct window *w, Lisp_Object val)
178{ 149{
179 w->normal_lines = val; 150 w->normal_lines = val;
180} 151}
152
181static void 153static void
182wset_parent (struct window *w, Lisp_Object val) 154wset_parent (struct window *w, Lisp_Object val)
183{ 155{
184 w->parent = val; 156 w->parent = val;
185} 157}
158
186static void 159static void
187wset_pointm (struct window *w, Lisp_Object val) 160wset_pointm (struct window *w, Lisp_Object val)
188{ 161{
189 w->pointm = val; 162 w->pointm = val;
190} 163}
164
165static void
166wset_old_pointm (struct window *w, Lisp_Object val)
167{
168 w->old_pointm = val;
169}
170
191static void 171static void
192wset_start (struct window *w, Lisp_Object val) 172wset_start (struct window *w, Lisp_Object val)
193{ 173{
194 w->start = val; 174 w->start = val;
195} 175}
176
196static void 177static void
197wset_temslot (struct window *w, Lisp_Object val) 178wset_temslot (struct window *w, Lisp_Object val)
198{ 179{
199 w->temslot = val; 180 w->temslot = val;
200} 181}
182
201static void 183static void
202wset_vertical_scroll_bar_type (struct window *w, Lisp_Object val) 184wset_vertical_scroll_bar_type (struct window *w, Lisp_Object val)
203{ 185{
204 w->vertical_scroll_bar_type = val; 186 w->vertical_scroll_bar_type = val;
205} 187}
188
206static void 189static void
207wset_window_parameters (struct window *w, Lisp_Object val) 190wset_window_parameters (struct window *w, Lisp_Object val)
208{ 191{
209 w->window_parameters = val; 192 w->window_parameters = val;
210} 193}
194
211static void 195static void
212wset_combination (struct window *w, bool horflag, Lisp_Object val) 196wset_combination (struct window *w, bool horflag, Lisp_Object val)
213{ 197{
@@ -221,7 +205,21 @@ wset_combination (struct window *w, bool horflag, Lisp_Object val)
221 w->horizontal = horflag; 205 w->horizontal = horflag;
222} 206}
223 207
224/* Nonzero if leaf window W doesn't reflect the actual state 208static void
209wset_update_mode_line (struct window *w)
210{
211 /* If this window is the selected window on its frame, set the
212 global variable update_mode_lines, so that x_consider_frame_title
213 will consider this frame's title for rtedisplay. */
214 Lisp_Object fselected_window = XFRAME (WINDOW_FRAME (w))->selected_window;
215
216 if (WINDOWP (fselected_window) && XWINDOW (fselected_window) == w)
217 update_mode_lines = 42;
218 else
219 w->update_mode_line = true;
220}
221
222/* True if leaf window W doesn't reflect the actual state
225 of displayed buffer due to its text or overlays change. */ 223 of displayed buffer due to its text or overlays change. */
226 224
227bool 225bool
@@ -284,7 +282,7 @@ adjust_window_count (struct window *w, int arg)
284 b->window_count += arg; 282 b->window_count += arg;
285 eassert (b->window_count >= 0); 283 eassert (b->window_count >= 0);
286 /* These should be recalculated by redisplay code. */ 284 /* These should be recalculated by redisplay code. */
287 w->window_end_valid = 0; 285 w->window_end_valid = false;
288 w->base_line_pos = 0; 286 w->base_line_pos = 0;
289 } 287 }
290} 288}
@@ -314,7 +312,7 @@ DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0,
314DEFUN ("window-valid-p", Fwindow_valid_p, Swindow_valid_p, 1, 1, 0, 312DEFUN ("window-valid-p", Fwindow_valid_p, Swindow_valid_p, 1, 1, 0,
315 doc: /* Return t if OBJECT is a valid window and nil otherwise. 313 doc: /* Return t if OBJECT is a valid window and nil otherwise.
316A valid window is either a window that displays a buffer or an internal 314A valid window is either a window that displays a buffer or an internal
317window. Deleted windows are not live. */) 315window. Windows that have been deleted are not valid. */)
318 (Lisp_Object object) 316 (Lisp_Object object)
319{ 317{
320 return WINDOW_VALID_P (object) ? Qt : Qnil; 318 return WINDOW_VALID_P (object) ? Qt : Qnil;
@@ -465,17 +463,18 @@ selected windows appears and to which many commands apply. */)
465 return selected_window; 463 return selected_window;
466} 464}
467 465
468int window_select_count; 466EMACS_INT window_select_count;
469 467
470/* If select_window is called with inhibit_point_swap non-zero it will 468/* If select_window is called with inhibit_point_swap true it will
471 not store point of the old selected window's buffer back into that 469 not store point of the old selected window's buffer back into that
472 window's pointm slot. This is needed by Fset_window_configuration to 470 window's pointm slot. This is needed by Fset_window_configuration to
473 avoid that the display routine is called with selected_window set to 471 avoid that the display routine is called with selected_window set to
474 Qnil causing a subsequent crash. */ 472 Qnil causing a subsequent crash. */
475static Lisp_Object 473static Lisp_Object
476select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap) 474select_window (Lisp_Object window, Lisp_Object norecord,
475 bool inhibit_point_swap)
477{ 476{
478 register struct window *w; 477 struct window *w;
479 struct frame *sf; 478 struct frame *sf;
480 479
481 CHECK_LIVE_WINDOW (window); 480 CHECK_LIVE_WINDOW (window);
@@ -491,6 +490,15 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
491 record_buffer before returning here. */ 490 record_buffer before returning here. */
492 goto record_and_return; 491 goto record_and_return;
493 492
493 if (NILP (norecord))
494 { /* Mark the window for redisplay since the selected-window has
495 a different mode-line. */
496 wset_redisplay (XWINDOW (selected_window));
497 wset_redisplay (w);
498 }
499 else
500 redisplay_other_windows ();
501
494 sf = SELECTED_FRAME (); 502 sf = SELECTED_FRAME ();
495 if (XFRAME (WINDOW_FRAME (w)) != sf) 503 if (XFRAME (WINDOW_FRAME (w)) != sf)
496 { 504 {
@@ -509,7 +517,6 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
509 517
510 select_window_1 (window, inhibit_point_swap); 518 select_window_1 (window, inhibit_point_swap);
511 bset_last_selected_window (XBUFFER (w->contents), window); 519 bset_last_selected_window (XBUFFER (w->contents), window);
512 windows_or_buffers_changed++;
513 520
514 record_and_return: 521 record_and_return:
515 /* record_buffer can run QUIT, so make sure it is run only after we have 522 /* record_buffer can run QUIT, so make sure it is run only after we have
@@ -549,21 +556,13 @@ select_window_1 (Lisp_Object window, bool inhibit_point_swap)
549 than one window. It also matters when 556 than one window. It also matters when
550 redisplay_window has altered point after scrolling, 557 redisplay_window has altered point after scrolling,
551 because it makes the change only in the window. */ 558 because it makes the change only in the window. */
552 { 559 set_point_from_marker (XWINDOW (window)->pointm);
553 register ptrdiff_t new_point = marker_position (XWINDOW (window)->pointm);
554 if (new_point < BEGV)
555 SET_PT (BEGV);
556 else if (new_point > ZV)
557 SET_PT (ZV);
558 else
559 SET_PT (new_point);
560 }
561} 560}
562 561
563DEFUN ("select-window", Fselect_window, Sselect_window, 1, 2, 0, 562DEFUN ("select-window", Fselect_window, Sselect_window, 1, 2, 0,
564 doc: /* Select WINDOW which must be a live window. 563 doc: /* Select WINDOW which must be a live window.
565Also make WINDOW's frame the selected frame and WINDOW that frame's 564Also make WINDOW's frame the selected frame and WINDOW that frame's
566selected window. In addition, make WINDOW's buffer current and set that 565selected window. In addition, make WINDOW's buffer current and set its
567buffer's value of `point' to the value of WINDOW's `window-point'. 566buffer's value of `point' to the value of WINDOW's `window-point'.
568Return WINDOW. 567Return WINDOW.
569 568
@@ -571,11 +570,20 @@ Optional second arg NORECORD non-nil means do not put this buffer at the
571front of the buffer list and do not make this window the most recently 570front of the buffer list and do not make this window the most recently
572selected one. 571selected one.
573 572
574Note that the main editor command loop sets the current buffer to the 573Run `buffer-list-update-hook' unless NORECORD is non-nil. Note that
575buffer of the selected window before each command. */) 574applications and internal routines often select a window temporarily for
576 (register Lisp_Object window, Lisp_Object norecord) 575various purposes; mostly, to simplify coding. As a rule, such
576selections should be not recorded and therefore will not pollute
577`buffer-list-update-hook'. Selections that "really count" are those
578causing a visible change in the next redisplay of WINDOW's frame and
579should be always recorded. So if you think of running a function each
580time a window gets selected put it on `buffer-list-update-hook'.
581
582Also note that the main editor command loop sets the current buffer to
583the buffer of the selected window before each command. */)
584 (Lisp_Object window, Lisp_Object norecord)
577{ 585{
578 return select_window (window, norecord, 0); 586 return select_window (window, norecord, false);
579} 587}
580 588
581DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0, 589DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0,
@@ -644,7 +652,7 @@ DEFUN ("window-combination-limit", Fwindow_combination_limit, Swindow_combinatio
644WINDOW must be a valid window used in horizontal or vertical combination. 652WINDOW must be a valid window used in horizontal or vertical combination.
645If the return value is nil, child windows of WINDOW can be recombined with 653If the return value is nil, child windows of WINDOW can be recombined with
646WINDOW's siblings. A return value of t means that child windows of 654WINDOW's siblings. A return value of t means that child windows of
647WINDOW are never \(re-)combined with WINDOW's siblings. */) 655WINDOW are never (re-)combined with WINDOW's siblings. */)
648 (Lisp_Object window) 656 (Lisp_Object window)
649{ 657{
650 struct window *w; 658 struct window *w;
@@ -661,7 +669,7 @@ DEFUN ("set-window-combination-limit", Fset_window_combination_limit, Sset_windo
661WINDOW must be a valid window used in horizontal or vertical combination. 669WINDOW must be a valid window used in horizontal or vertical combination.
662If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's 670If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's
663siblings. LIMIT t means that child windows of WINDOW are never 671siblings. LIMIT t means that child windows of WINDOW are never
664\(re-)combined with WINDOW's siblings. Other values are reserved for 672(re-)combined with WINDOW's siblings. Other values are reserved for
665future use. */) 673future use. */)
666 (Lisp_Object window, Lisp_Object limit) 674 (Lisp_Object window, Lisp_Object limit)
667{ 675{
@@ -686,39 +694,112 @@ selected one. */)
686 return make_number (decode_live_window (window)->use_time); 694 return make_number (decode_live_window (window)->use_time);
687} 695}
688 696
689DEFUN ("window-total-height", Fwindow_total_height, Swindow_total_height, 0, 1, 0, 697DEFUN ("window-pixel-width", Fwindow_pixel_width, Swindow_pixel_width, 0, 1, 0,
690 doc: /* Return the total height, in lines, of window WINDOW. 698 doc: /* Return the width of window WINDOW in pixels.
691WINDOW must be a valid window and defaults to the selected one. 699WINDOW must be a valid window and defaults to the selected one.
692 700
693The return value includes the mode line and header line, if any. 701The return value includes the fringes and margins of WINDOW as well as
694If WINDOW is an internal window, the total height is the height 702any vertical dividers or scroll bars belonging to WINDOW. If WINDOW is
695of the screen areas spanned by its children. 703an internal window, its pixel width is the width of the screen areas
704spanned by its children. */)
705 (Lisp_Object window)
706{
707 return make_number (decode_valid_window (window)->pixel_width);
708}
709
710DEFUN ("window-pixel-height", Fwindow_pixel_height, Swindow_pixel_height, 0, 1, 0,
711 doc: /* Return the height of window WINDOW in pixels.
712WINDOW must be a valid window and defaults to the selected one.
696 713
697On a graphical display, this total height is reported as an 714The return value includes the mode line and header line and the bottom
698integer multiple of the default character height. */) 715divider, if any. If WINDOW is an internal window, its pixel height is
716the height of the screen areas spanned by its children. */)
699 (Lisp_Object window) 717 (Lisp_Object window)
700{ 718{
701 return make_number (decode_valid_window (window)->total_lines); 719 return make_number (decode_valid_window (window)->pixel_height);
702} 720}
703 721
704DEFUN ("window-total-width", Fwindow_total_width, Swindow_total_width, 0, 1, 0, 722DEFUN ("window-total-height", Fwindow_total_height, Swindow_total_height, 0, 2, 0,
705 doc: /* Return the total width, in columns, of window WINDOW. 723 doc: /* Return the height of window WINDOW in lines.
706WINDOW must be a valid window and defaults to the selected one. 724WINDOW must be a valid window and defaults to the selected one.
707 725
708The return value includes any vertical dividers or scroll bars 726The return value includes the heights of WINDOW's mode and header line
709belonging to WINDOW. If WINDOW is an internal window, the total width 727and its bottom divider, if any. If WINDOW is an internal window, the
710is the width of the screen areas spanned by its children. 728total height is the height of the screen areas spanned by its children.
711 729
712On a graphical display, this total width is reported as an 730If WINDOW's pixel height is not an integral multiple of its frame's
713integer multiple of the default character width. */) 731character height, the number of lines occupied by WINDOW is rounded
714 (Lisp_Object window) 732internally. This is done in a way such that, if WINDOW is a parent
733window, the sum of the total heights of all its children internally
734equals the total height of WINDOW.
735
736If the optional argument ROUND is `ceiling', return the smallest integer
737larger than WINDOW's pixel height divided by the character height of
738WINDOW's frame. ROUND `floor' means to return the largest integer
739smaller than WINDOW's pixel height divided by the character height of
740WINDOW's frame. Any other value of ROUND means to return the internal
741total height of WINDOW. */)
742 (Lisp_Object window, Lisp_Object round)
743{
744 struct window *w = decode_valid_window (window);
745
746 if (! EQ (round, Qfloor) && ! EQ (round, Qceiling))
747 return make_number (w->total_lines);
748 else
749 {
750 int unit = FRAME_LINE_HEIGHT (WINDOW_XFRAME (w));
751
752 return make_number (EQ (round, Qceiling)
753 ? ((w->pixel_height + unit - 1) /unit)
754 : (w->pixel_height / unit));
755 }
756}
757
758DEFUN ("window-total-width", Fwindow_total_width, Swindow_total_width, 0, 2, 0,
759 doc: /* Return the total width of window WINDOW in columns.
760WINDOW must be a valid window and defaults to the selected one.
761
762The return value includes the widths of WINDOW's fringes, margins,
763scroll bars and its right divider, if any. If WINDOW is an internal
764window, the total width is the width of the screen areas spanned by its
765children.
766
767If WINDOW's pixel width is not an integral multiple of its frame's
768character width, the number of lines occupied by WINDOW is rounded
769internally. This is done in a way such that, if WINDOW is a parent
770window, the sum of the total widths of all its children internally
771equals the total width of WINDOW.
772
773If the optional argument ROUND is `ceiling', return the smallest integer
774larger than WINDOW's pixel width divided by the character width of
775WINDOW's frame. ROUND `floor' means to return the largest integer
776smaller than WINDOW's pixel width divided by the character width of
777WINDOW's frame. Any other value of ROUND means to return the internal
778total width of WINDOW. */)
779 (Lisp_Object window, Lisp_Object round)
715{ 780{
716 return make_number (decode_valid_window (window)->total_cols); 781 struct window *w = decode_valid_window (window);
782
783 if (! EQ (round, Qfloor) && ! EQ (round, Qceiling))
784 return make_number (w->total_cols);
785 else
786 {
787 int unit = FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w));
788
789 return make_number (EQ (round, Qceiling)
790 ? ((w->pixel_width + unit - 1) /unit)
791 : (w->pixel_width / unit));
792 }
717} 793}
718 794
719DEFUN ("window-new-total", Fwindow_new_total, Swindow_new_total, 0, 1, 0, 795DEFUN ("window-new-total", Fwindow_new_total, Swindow_new_total, 0, 1, 0,
720 doc: /* Return the new total size of window WINDOW. 796 doc: /* Return the new total size of window WINDOW.
721WINDOW must be a valid window and defaults to the selected one. */) 797WINDOW must be a valid window and defaults to the selected one.
798
799The new total size of WINDOW is the value set by the last call of
800`set-window-new-total' for WINDOW. If it is valid, it will be shortly
801installed as WINDOW's total height (see `window-total-height') or total
802width (see `window-total-width'). */)
722 (Lisp_Object window) 803 (Lisp_Object window)
723{ 804{
724 return decode_valid_window (window)->new_total; 805 return decode_valid_window (window)->new_total;
@@ -727,7 +808,25 @@ WINDOW must be a valid window and defaults to the selected one. */)
727DEFUN ("window-normal-size", Fwindow_normal_size, Swindow_normal_size, 0, 2, 0, 808DEFUN ("window-normal-size", Fwindow_normal_size, Swindow_normal_size, 0, 2, 0,
728 doc: /* Return the normal height of window WINDOW. 809 doc: /* Return the normal height of window WINDOW.
729WINDOW must be a valid window and defaults to the selected one. 810WINDOW must be a valid window and defaults to the selected one.
730If HORIZONTAL is non-nil, return the normal width of WINDOW. */) 811If HORIZONTAL is non-nil, return the normal width of WINDOW.
812
813The normal height of a frame's root window or a window that is
814horizontally combined (a window that has a left or right sibling) is
8151.0. The normal height of a window that is vertically combined (has a
816sibling above or below) is the fraction of the window's height with
817respect to its parent. The sum of the normal heights of all windows in a
818vertical combination equals 1.0.
819
820Similarly, the normal width of a frame's root window or a window that is
821vertically combined equals 1.0. The normal width of a window that is
822horizontally combined is the fraction of the window's width with respect
823to its parent. The sum of the normal widths of all windows in a
824horizontal combination equals 1.0.
825
826The normal sizes of windows are used to restore the proportional sizes
827of windows after they have been shrunk to their minimum sizes; for
828example when a frame is temporarily made very small and afterwards gets
829re-enlarged to its previous size. */)
731 (Lisp_Object window, Lisp_Object horizontal) 830 (Lisp_Object window, Lisp_Object horizontal)
732{ 831{
733 struct window *w = decode_valid_window (window); 832 struct window *w = decode_valid_window (window);
@@ -737,12 +836,45 @@ If HORIZONTAL is non-nil, return the normal width of WINDOW. */)
737 836
738DEFUN ("window-new-normal", Fwindow_new_normal, Swindow_new_normal, 0, 1, 0, 837DEFUN ("window-new-normal", Fwindow_new_normal, Swindow_new_normal, 0, 1, 0,
739 doc: /* Return new normal size of window WINDOW. 838 doc: /* Return new normal size of window WINDOW.
740WINDOW must be a valid window and defaults to the selected one. */) 839WINDOW must be a valid window and defaults to the selected one.
840
841The new normal size of WINDOW is the value set by the last call of
842`set-window-new-normal' for WINDOW. If valid, it will be shortly
843installed as WINDOW's normal size (see `window-normal-size'). */)
741 (Lisp_Object window) 844 (Lisp_Object window)
742{ 845{
743 return decode_valid_window (window)->new_normal; 846 return decode_valid_window (window)->new_normal;
744} 847}
745 848
849DEFUN ("window-new-pixel", Fwindow_new_pixel, Swindow_new_pixel, 0, 1, 0,
850 doc: /* Return new pixel size of window WINDOW.
851WINDOW must be a valid window and defaults to the selected one.
852
853The new pixel size of WINDOW is the value set by the last call of
854`set-window-new-pixel' for WINDOW. If it is valid, it will be shortly
855installed as WINDOW's pixel height (see `window-pixel-height') or pixel
856width (see `window-pixel-width'). */)
857 (Lisp_Object window)
858{
859 return decode_valid_window (window)->new_pixel;
860}
861
862DEFUN ("window-pixel-left", Fwindow_pixel_left, Swindow_pixel_left, 0, 1, 0,
863 doc: /* Return left pixel edge of window WINDOW.
864WINDOW must be a valid window and defaults to the selected one. */)
865 (Lisp_Object window)
866{
867 return make_number (decode_valid_window (window)->pixel_left);
868}
869
870DEFUN ("window-pixel-top", Fwindow_pixel_top, Swindow_pixel_top, 0, 1, 0,
871 doc: /* Return top pixel edge of window WINDOW.
872WINDOW must be a valid window and defaults to the selected one. */)
873 (Lisp_Object window)
874{
875 return make_number (decode_valid_window (window)->pixel_top);
876}
877
746DEFUN ("window-left-column", Fwindow_left_column, Swindow_left_column, 0, 1, 0, 878DEFUN ("window-left-column", Fwindow_left_column, Swindow_left_column, 0, 1, 0,
747 doc: /* Return left column of window WINDOW. 879 doc: /* Return left column of window WINDOW.
748This is the distance, in columns, between the left edge of WINDOW and 880This is the distance, in columns, between the left edge of WINDOW and
@@ -767,79 +899,146 @@ WINDOW must be a valid window and defaults to the selected one. */)
767 return make_number (decode_valid_window (window)->top_line); 899 return make_number (decode_valid_window (window)->top_line);
768} 900}
769 901
770/* Return the number of lines of W's body. Don't count any mode or 902/* Return the number of lines/pixels of W's body. Don't count any mode
771 header line of W. */ 903 or header line or horizontal divider of W. Rounds down to nearest
772 904 integer when not working pixelwise. */
773static int 905static int
774window_body_lines (struct window *w) 906window_body_height (struct window *w, bool pixelwise)
775{ 907{
776 int height = w->total_lines; 908 int height = (w->pixel_height
777 909 - WINDOW_HEADER_LINE_HEIGHT (w)
778 if (!MINI_WINDOW_P (w)) 910 - (WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w)
779 { 911 ? WINDOW_SCROLL_BAR_AREA_HEIGHT (w)
780 if (WINDOW_WANTS_MODELINE_P (w)) 912 : 0)
781 --height; 913 - WINDOW_MODE_LINE_HEIGHT (w)
782 if (WINDOW_WANTS_HEADER_LINE_P (w)) 914 - WINDOW_BOTTOM_DIVIDER_WIDTH (w));
783 --height; 915
784 } 916 /* Don't return a negative value. */
785 917 return max (pixelwise
786 return height; 918 ? height
787} 919 : height / FRAME_LINE_HEIGHT (WINDOW_XFRAME (w)),
788 920 0);
789/* Return the number of columns of W's body. Don't count columns 921}
790 occupied by the scroll bar or the vertical bar separating W from its 922
791 right sibling. On window-systems don't count fringes or display 923/* Return the number of columns/pixels of W's body. Don't count columns
792 margins either. */ 924 occupied by the scroll bar or the divider/vertical bar separating W
793 925 from its right sibling or margins. On window-systems don't count
926 fringes either. Round down to nearest integer when not working
927 pixelwise. */
794int 928int
795window_body_cols (struct window *w) 929window_body_width (struct window *w, bool pixelwise)
796{ 930{
797 struct frame *f = XFRAME (WINDOW_FRAME (w)); 931 struct frame *f = XFRAME (WINDOW_FRAME (w));
798 int width = w->total_cols;
799
800 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
801 /* Scroll bars occupy a few columns. */
802 width -= WINDOW_CONFIG_SCROLL_BAR_COLS (w);
803 else if (!FRAME_WINDOW_P (f)
804 && !WINDOW_RIGHTMOST_P (w) && !WINDOW_FULL_WIDTH_P (w))
805 /* The column of `|' characters separating side-by-side windows
806 occupies one column only. */
807 width -= 1;
808
809 /* Display margins cannot be used for normal text. */
810 width -= WINDOW_LEFT_MARGIN_COLS (w) + WINDOW_RIGHT_MARGIN_COLS (w);
811 932
812 if (FRAME_WINDOW_P (f)) 933 int width = (w->pixel_width
813 /* On window-systems, fringes cannot be used for normal text. */ 934 - WINDOW_RIGHT_DIVIDER_WIDTH (w)
814 width -= WINDOW_FRINGE_COLS (w); 935 - (WINDOW_HAS_VERTICAL_SCROLL_BAR (w)
936 ? WINDOW_SCROLL_BAR_AREA_WIDTH (w)
937 : (/* A vertical bar is either 1 or 0. */
938 !FRAME_WINDOW_P (f)
939 && !WINDOW_RIGHTMOST_P (w)
940 && !WINDOW_RIGHT_DIVIDER_WIDTH (w)))
941 - WINDOW_MARGINS_WIDTH (w)
942 - (FRAME_WINDOW_P (f)
943 ? WINDOW_FRINGES_WIDTH (w)
944 : 0));
945
946 /* Don't return a negative value. */
947 return max (pixelwise
948 ? width
949 : width / FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w)),
950 0);
951}
952
953DEFUN ("window-body-height", Fwindow_body_height, Swindow_body_height, 0, 2, 0,
954 doc: /* Return the height of WINDOW's text area.
955WINDOW must be a live window and defaults to the selected one. Optional
956argument PIXELWISE non-nil means return the height of WINDOW's text area
957in pixels. The return value does not include the mode line or header
958line or any horizontal divider.
959
960If PIXELWISE is nil, return the largest integer smaller than WINDOW's
961pixel height divided by the character height of WINDOW's frame. This
962means that if a line at the bottom of the text area is only partially
963visible, that line is not counted. */)
964 (Lisp_Object window, Lisp_Object pixelwise)
965{
966 return make_number (window_body_height (decode_live_window (window),
967 !NILP (pixelwise)));
968}
969
970DEFUN ("window-body-width", Fwindow_body_width, Swindow_body_width, 0, 2, 0,
971 doc: /* Return the width of WINDOW's text area.
972WINDOW must be a live window and defaults to the selected one. Optional
973argument PIXELWISE non-nil means return the width in pixels. The return
974value does not include any vertical dividers, fringes or marginal areas,
975or scroll bars.
976
977If PIXELWISE is nil, return the largest integer smaller than WINDOW's
978pixel width divided by the character width of WINDOW's frame. This
979means that if a column at the right of the text area is only partially
980visible, that column is not counted.
981
982Note that the returned value includes the column reserved for the
983continuation glyph. */)
984 (Lisp_Object window, Lisp_Object pixelwise)
985{
986 return make_number (window_body_width (decode_live_window (window),
987 !NILP (pixelwise)));
988}
989
990DEFUN ("window-mode-line-height", Fwindow_mode_line_height,
991 Swindow_mode_line_height, 0, 1, 0,
992 doc: /* Return the height in pixels of WINDOW's mode-line.
993WINDOW must be a live window and defaults to the selected one. */)
994 (Lisp_Object window)
995{
996 return (make_number (WINDOW_MODE_LINE_HEIGHT (decode_live_window (window))));
997}
815 998
816 return width; 999DEFUN ("window-header-line-height", Fwindow_header_line_height,
1000 Swindow_header_line_height, 0, 1, 0,
1001 doc: /* Return the height in pixels of WINDOW's header-line.
1002WINDOW must be a live window and defaults to the selected one. */)
1003 (Lisp_Object window)
1004{
1005 return (make_number (WINDOW_HEADER_LINE_HEIGHT (decode_live_window (window))));
817} 1006}
818 1007
819DEFUN ("window-body-height", Fwindow_body_height, Swindow_body_height, 0, 1, 0, 1008DEFUN ("window-right-divider-width", Fwindow_right_divider_width,
820 doc: /* Return the height, in lines, of WINDOW's text area. 1009 Swindow_right_divider_width, 0, 1, 0,
821WINDOW must be a live window and defaults to the selected one. 1010 doc: /* Return the width in pixels of WINDOW's right divider.
1011WINDOW must be a live window and defaults to the selected one. */)
1012 (Lisp_Object window)
1013{
1014 return (make_number (WINDOW_RIGHT_DIVIDER_WIDTH (decode_live_window (window))));
1015}
822 1016
823The returned height does not include the mode line or header line. 1017DEFUN ("window-bottom-divider-width", Fwindow_bottom_divider_width,
824On a graphical display, the height is expressed as an integer multiple 1018 Swindow_bottom_divider_width, 0, 1, 0,
825of the default character height. If a line at the bottom of the text 1019 doc: /* Return the width in pixels of WINDOW's bottom divider.
826area is only partially visible, that counts as a whole line; to 1020WINDOW must be a live window and defaults to the selected one. */)
827exclude partially-visible lines, use `window-text-height'. */)
828 (Lisp_Object window) 1021 (Lisp_Object window)
829{ 1022{
830 return make_number (window_body_lines (decode_live_window (window))); 1023 return (make_number (WINDOW_BOTTOM_DIVIDER_WIDTH (decode_live_window (window))));
831} 1024}
832 1025
833DEFUN ("window-body-width", Fwindow_body_width, Swindow_body_width, 0, 1, 0, 1026DEFUN ("window-scroll-bar-width", Fwindow_scroll_bar_width,
834 doc: /* Return the width, in columns, of WINDOW's text area. 1027 Swindow_scroll_bar_width, 0, 1, 0,
835WINDOW must be a live window and defaults to the selected one. 1028 doc: /* Return the width in pixels of WINDOW's vertical scrollbar.
1029WINDOW must be a live window and defaults to the selected one. */)
1030 (Lisp_Object window)
1031{
1032 return (make_number (WINDOW_SCROLL_BAR_AREA_WIDTH (decode_live_window (window))));
1033}
836 1034
837The return value does not include any vertical dividers, fringe or 1035DEFUN ("window-scroll-bar-height", Fwindow_scroll_bar_height,
838marginal areas, or scroll bars. On a graphical display, the width is 1036 Swindow_scroll_bar_height, 0, 1, 0,
839expressed as an integer multiple of the default character width. */) 1037 doc: /* Return the height in pixels of WINDOW's horizontal scrollbar.
1038WINDOW must be a live window and defaults to the selected one. */)
840 (Lisp_Object window) 1039 (Lisp_Object window)
841{ 1040{
842 return make_number (window_body_cols (decode_live_window (window))); 1041 return (make_number (WINDOW_SCROLL_BAR_AREA_HEIGHT (decode_live_window (window))));
843} 1042}
844 1043
845DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0, 1044DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0,
@@ -866,9 +1065,11 @@ set_window_hscroll (struct window *w, EMACS_INT hscroll)
866 1065
867 /* Prevent redisplay shortcuts when changing the hscroll. */ 1066 /* Prevent redisplay shortcuts when changing the hscroll. */
868 if (w->hscroll != new_hscroll) 1067 if (w->hscroll != new_hscroll)
869 XBUFFER (w->contents)->prevent_redisplay_optimizations_p = 1; 1068 XBUFFER (w->contents)->prevent_redisplay_optimizations_p = true;
870 1069
871 w->hscroll = new_hscroll; 1070 w->hscroll = new_hscroll;
1071 w->suspend_auto_hscroll = true;
1072
872 return make_number (new_hscroll); 1073 return make_number (new_hscroll);
873} 1074}
874 1075
@@ -911,189 +1112,17 @@ end-trigger value is reset to nil. */)
911 return value; 1112 return value;
912} 1113}
913 1114
914DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0,
915 doc: /* Return a list of the edge coordinates of WINDOW.
916WINDOW must be a valid window and defaults to the selected one.
917
918The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
919count by lines, and LEFT and RIGHT count by columns, all relative to 0,
9200 at top left corner of frame.
921
922RIGHT is one more than the rightmost column occupied by WINDOW. BOTTOM
923is one more than the bottommost row occupied by WINDOW. The edges
924include the space used by WINDOW's scroll bar, display margins, fringes,
925header line, and/or mode line. For the edges of just the text area, use
926`window-inside-edges'. */)
927 (Lisp_Object window)
928{
929 register struct window *w = decode_valid_window (window);
930
931 return list4i (WINDOW_LEFT_EDGE_COL (w), WINDOW_TOP_EDGE_LINE (w),
932 WINDOW_RIGHT_EDGE_COL (w), WINDOW_BOTTOM_EDGE_LINE (w));
933}
934
935DEFUN ("window-pixel-edges", Fwindow_pixel_edges, Swindow_pixel_edges, 0, 1, 0,
936 doc: /* Return a list of the edge pixel coordinates of WINDOW.
937WINDOW must be a valid window and defaults to the selected one.
938
939The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
9400, 0 at the top left corner of the frame.
941
942RIGHT is one more than the rightmost x position occupied by WINDOW.
943BOTTOM is one more than the bottommost y position occupied by WINDOW.
944The pixel edges include the space used by WINDOW's scroll bar, display
945margins, fringes, header line, and/or mode line. For the pixel edges
946of just the text area, use `window-inside-pixel-edges'. */)
947 (Lisp_Object window)
948{
949 register struct window *w = decode_valid_window (window);
950
951 return list4i (WINDOW_LEFT_EDGE_X (w), WINDOW_TOP_EDGE_Y (w),
952 WINDOW_RIGHT_EDGE_X (w), WINDOW_BOTTOM_EDGE_Y (w));
953}
954
955static void
956calc_absolute_offset (struct window *w, int *add_x, int *add_y)
957{
958 struct frame *f = XFRAME (w->frame);
959 *add_y = f->top_pos;
960#ifdef FRAME_MENUBAR_HEIGHT
961 *add_y += FRAME_MENUBAR_HEIGHT (f);
962#endif
963#ifdef FRAME_TOOLBAR_TOP_HEIGHT
964 *add_y += FRAME_TOOLBAR_TOP_HEIGHT (f);
965#elif FRAME_TOOLBAR_HEIGHT
966 *add_y += FRAME_TOOLBAR_HEIGHT (f);
967#endif
968#ifdef FRAME_NS_TITLEBAR_HEIGHT
969 *add_y += FRAME_NS_TITLEBAR_HEIGHT (f);
970#endif
971 *add_x = f->left_pos;
972#ifdef FRAME_TOOLBAR_LEFT_WIDTH
973 *add_x += FRAME_TOOLBAR_LEFT_WIDTH (f);
974#endif
975}
976
977DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges,
978 Swindow_absolute_pixel_edges, 0, 1, 0,
979 doc: /* Return a list of the edge pixel coordinates of WINDOW.
980WINDOW must be a valid window and defaults to the selected one.
981
982The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
9830, 0 at the top left corner of the display.
984
985RIGHT is one more than the rightmost x position occupied by WINDOW.
986BOTTOM is one more than the bottommost y position occupied by WINDOW.
987The pixel edges include the space used by WINDOW's scroll bar, display
988margins, fringes, header line, and/or mode line. For the pixel edges
989of just the text area, use `window-inside-absolute-pixel-edges'. */)
990 (Lisp_Object window)
991{
992 register struct window *w = decode_valid_window (window);
993 int add_x, add_y;
994
995 calc_absolute_offset (w, &add_x, &add_y);
996
997 return list4i (WINDOW_LEFT_EDGE_X (w) + add_x,
998 WINDOW_TOP_EDGE_Y (w) + add_y,
999 WINDOW_RIGHT_EDGE_X (w) + add_x,
1000 WINDOW_BOTTOM_EDGE_Y (w) + add_y);
1001}
1002
1003DEFUN ("window-inside-edges", Fwindow_inside_edges, Swindow_inside_edges, 0, 1, 0,
1004 doc: /* Return a list of the edge coordinates of WINDOW.
1005WINDOW must be a live window and defaults to the selected one.
1006
1007The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
1008count by lines, and LEFT and RIGHT count by columns, all relative to 0,
10090 at top left corner of frame.
1010
1011RIGHT is one more than the rightmost column of WINDOW's text area.
1012BOTTOM is one more than the bottommost row of WINDOW's text area. The
1013inside edges do not include the space used by the WINDOW's scroll bar,
1014display margins, fringes, header line, and/or mode line. */)
1015 (Lisp_Object window)
1016{
1017 register struct window *w = decode_live_window (window);
1018
1019 return list4i ((WINDOW_BOX_LEFT_EDGE_COL (w)
1020 + WINDOW_LEFT_MARGIN_COLS (w)
1021 + WINDOW_LEFT_FRINGE_COLS (w)),
1022 (WINDOW_TOP_EDGE_LINE (w)
1023 + WINDOW_HEADER_LINE_LINES (w)),
1024 (WINDOW_BOX_RIGHT_EDGE_COL (w)
1025 - WINDOW_RIGHT_MARGIN_COLS (w)
1026 - WINDOW_RIGHT_FRINGE_COLS (w)),
1027 (WINDOW_BOTTOM_EDGE_LINE (w)
1028 - WINDOW_MODE_LINE_LINES (w)));
1029}
1030
1031DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges, Swindow_inside_pixel_edges, 0, 1, 0,
1032 doc: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1033WINDOW must be a live window and defaults to the selected one.
1034
1035The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1036(0,0) at the top left corner of the frame's window area.
1037
1038RIGHT is one more than the rightmost x position of WINDOW's text area.
1039BOTTOM is one more than the bottommost y position of WINDOW's text area.
1040The inside edges do not include the space used by WINDOW's scroll bar,
1041display margins, fringes, header line, and/or mode line. */)
1042 (Lisp_Object window)
1043{
1044 register struct window *w = decode_live_window (window);
1045
1046 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w)
1047 + WINDOW_LEFT_MARGIN_WIDTH (w)
1048 + WINDOW_LEFT_FRINGE_WIDTH (w)),
1049 (WINDOW_TOP_EDGE_Y (w)
1050 + WINDOW_HEADER_LINE_HEIGHT (w)),
1051 (WINDOW_BOX_RIGHT_EDGE_X (w)
1052 - WINDOW_RIGHT_MARGIN_WIDTH (w)
1053 - WINDOW_RIGHT_FRINGE_WIDTH (w)),
1054 (WINDOW_BOTTOM_EDGE_Y (w)
1055 - WINDOW_MODE_LINE_HEIGHT (w)));
1056}
1057
1058DEFUN ("window-inside-absolute-pixel-edges",
1059 Fwindow_inside_absolute_pixel_edges,
1060 Swindow_inside_absolute_pixel_edges, 0, 1, 0,
1061 doc: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1062WINDOW must be a live window and defaults to the selected one.
1063
1064The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1065(0,0) at the top left corner of the frame's window area.
1066
1067RIGHT is one more than the rightmost x position of WINDOW's text area.
1068BOTTOM is one more than the bottommost y position of WINDOW's text area.
1069The inside edges do not include the space used by WINDOW's scroll bar,
1070display margins, fringes, header line, and/or mode line. */)
1071 (Lisp_Object window)
1072{
1073 register struct window *w = decode_live_window (window);
1074 int add_x, add_y;
1075
1076 calc_absolute_offset (w, &add_x, &add_y);
1077
1078 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w)
1079 + WINDOW_LEFT_MARGIN_WIDTH (w)
1080 + WINDOW_LEFT_FRINGE_WIDTH (w) + add_x),
1081 (WINDOW_TOP_EDGE_Y (w)
1082 + WINDOW_HEADER_LINE_HEIGHT (w) + add_y),
1083 (WINDOW_BOX_RIGHT_EDGE_X (w)
1084 - WINDOW_RIGHT_MARGIN_WIDTH (w)
1085 - WINDOW_RIGHT_FRINGE_WIDTH (w) + add_x),
1086 (WINDOW_BOTTOM_EDGE_Y (w)
1087 - WINDOW_MODE_LINE_HEIGHT (w) + add_y));
1088}
1089
1090/* Test if the character at column X, row Y is within window W. 1115/* Test if the character at column X, row Y is within window W.
1091 If it is not, return ON_NOTHING; 1116 If it is not, return ON_NOTHING;
1117 if it is on the window's vertical divider, return
1118 ON_RIGHT_DIVIDER;
1119 if it is on the window's horizontal divider, return
1120 ON_BOTTOM_DIVIDER;
1092 if it is in the window's text area, return ON_TEXT; 1121 if it is in the window's text area, return ON_TEXT;
1093 if it is on the window's modeline, return ON_MODE_LINE; 1122 if it is on the window's modeline, return ON_MODE_LINE;
1094 if it is on the border between the window and its right sibling, 1123 if it is on the border between the window and its right sibling,
1095 return ON_VERTICAL_BORDER. 1124 return ON_VERTICAL_BORDER;
1096 if it is on a scroll bar, return ON_SCROLL_BAR. 1125 if it is on a scroll bar, return ON_SCROLL_BAR;
1097 if it is on the window's top line, return ON_HEADER_LINE; 1126 if it is on the window's top line, return ON_HEADER_LINE;
1098 if it is in left or right fringe of the window, 1127 if it is in left or right fringe of the window,
1099 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE; 1128 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
@@ -1121,25 +1150,52 @@ coordinates_in_window (register struct window *w, int x, int y)
1121 if (y < top_y || y >= bottom_y || x < left_x || x >= right_x) 1150 if (y < top_y || y >= bottom_y || x < left_x || x >= right_x)
1122 return ON_NOTHING; 1151 return ON_NOTHING;
1123 1152
1124 /* On the mode line or header line? */ 1153 /* On the horizontal window divider (which prevails the vertical
1125 if ((WINDOW_WANTS_MODELINE_P (w) 1154 divider)? */
1126 && y >= bottom_y - CURRENT_MODE_LINE_HEIGHT (w) 1155 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w) > 0
1127 && (part = ON_MODE_LINE)) 1156 && y >= (bottom_y - WINDOW_BOTTOM_DIVIDER_WIDTH (w))
1128 || (WINDOW_WANTS_HEADER_LINE_P (w) 1157 && y <= bottom_y)
1129 && y < top_y + CURRENT_HEADER_LINE_HEIGHT (w) 1158 return ON_BOTTOM_DIVIDER;
1130 && (part = ON_HEADER_LINE))) 1159 /* On vertical window divider? */
1160 else if (!WINDOW_RIGHTMOST_P (w)
1161 && WINDOW_RIGHT_DIVIDER_WIDTH (w) > 0
1162 && x >= right_x - WINDOW_RIGHT_DIVIDER_WIDTH (w)
1163 && x <= right_x)
1164 return ON_RIGHT_DIVIDER;
1165 /* On the horizontal scroll bar? (Including the empty space at its
1166 right!) */
1167 else if ((WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w)
1168 && y >= (bottom_y
1169 - WINDOW_SCROLL_BAR_AREA_HEIGHT (w)
1170 - CURRENT_MODE_LINE_HEIGHT (w)
1171 - WINDOW_BOTTOM_DIVIDER_WIDTH (w))
1172 && y <= (bottom_y
1173 - CURRENT_MODE_LINE_HEIGHT (w)
1174 - WINDOW_BOTTOM_DIVIDER_WIDTH (w))))
1175 return ON_HORIZONTAL_SCROLL_BAR;
1176 /* On the mode or header line? */
1177 else if ((WINDOW_WANTS_MODELINE_P (w)
1178 && y >= (bottom_y
1179 - CURRENT_MODE_LINE_HEIGHT (w)
1180 - WINDOW_BOTTOM_DIVIDER_WIDTH (w))
1181 && y <= bottom_y - WINDOW_BOTTOM_DIVIDER_WIDTH (w)
1182 && (part = ON_MODE_LINE))
1183 || (WINDOW_WANTS_HEADER_LINE_P (w)
1184 && y < top_y + CURRENT_HEADER_LINE_HEIGHT (w)
1185 && (part = ON_HEADER_LINE)))
1131 { 1186 {
1132 /* If it's under/over the scroll bar portion of the mode/header 1187 /* If it's under/over the scroll bar portion of the mode/header
1133 line, say it's on the vertical line. That's to be able to 1188 line, say it's on the vertical line. That's to be able to
1134 resize windows horizontally in case we're using toolkit scroll 1189 resize windows horizontally in case we're using toolkit scroll
1135 bars. Note: If scrollbars are on the left, the window that 1190 bars. Note: If scrollbars are on the left, the window that
1136 must be eventually resized is that on the left of WINDOW. */ 1191 must be eventually resized is that on the left of WINDOW. */
1137 if ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) 1192 if ((WINDOW_RIGHT_DIVIDER_WIDTH (w) == 0)
1138 && !WINDOW_LEFTMOST_P (w) 1193 && ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)
1139 && eabs (x - left_x) < grabbable_width) 1194 && !WINDOW_LEFTMOST_P (w)
1140 || (!WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) 1195 && eabs (x - left_x) < grabbable_width)
1141 && !WINDOW_RIGHTMOST_P (w) 1196 || (!WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)
1142 && eabs (x - right_x) < grabbable_width)) 1197 && !WINDOW_RIGHTMOST_P (w)
1198 && eabs (x - right_x) < grabbable_width)))
1143 return ON_VERTICAL_BORDER; 1199 return ON_VERTICAL_BORDER;
1144 else 1200 else
1145 return part; 1201 return part;
@@ -1150,7 +1206,7 @@ coordinates_in_window (register struct window *w, int x, int y)
1150 if (w->pseudo_window_p) 1206 if (w->pseudo_window_p)
1151 { 1207 {
1152 left_x = 0; 1208 left_x = 0;
1153 right_x = WINDOW_TOTAL_WIDTH (w) - 1; 1209 right_x = WINDOW_PIXEL_WIDTH (w) - 1;
1154 } 1210 }
1155 else 1211 else
1156 { 1212 {
@@ -1160,7 +1216,7 @@ coordinates_in_window (register struct window *w, int x, int y)
1160 1216
1161 /* Outside any interesting column? */ 1217 /* Outside any interesting column? */
1162 if (x < left_x || x > right_x) 1218 if (x < left_x || x > right_x)
1163 return ON_SCROLL_BAR; 1219 return ON_VERTICAL_SCROLL_BAR;
1164 1220
1165 lmargin_width = window_box_width (w, LEFT_MARGIN_AREA); 1221 lmargin_width = window_box_width (w, LEFT_MARGIN_AREA);
1166 rmargin_width = window_box_width (w, RIGHT_MARGIN_AREA); 1222 rmargin_width = window_box_width (w, RIGHT_MARGIN_AREA);
@@ -1171,6 +1227,7 @@ coordinates_in_window (register struct window *w, int x, int y)
1171 if (FRAME_WINDOW_P (f)) 1227 if (FRAME_WINDOW_P (f))
1172 { 1228 {
1173 if (!w->pseudo_window_p 1229 if (!w->pseudo_window_p
1230 && WINDOW_RIGHT_DIVIDER_WIDTH (w) == 0
1174 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w) 1231 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w)
1175 && !WINDOW_RIGHTMOST_P (w) 1232 && !WINDOW_RIGHTMOST_P (w)
1176 && (eabs (x - right_x) < grabbable_width)) 1233 && (eabs (x - right_x) < grabbable_width))
@@ -1179,7 +1236,10 @@ coordinates_in_window (register struct window *w, int x, int y)
1179 /* Need to say "x > right_x" rather than >=, since on character 1236 /* Need to say "x > right_x" rather than >=, since on character
1180 terminals, the vertical line's x coordinate is right_x. */ 1237 terminals, the vertical line's x coordinate is right_x. */
1181 else if (!w->pseudo_window_p 1238 else if (!w->pseudo_window_p
1239 && WINDOW_RIGHT_DIVIDER_WIDTH (w) == 0
1182 && !WINDOW_RIGHTMOST_P (w) 1240 && !WINDOW_RIGHTMOST_P (w)
1241 /* Why check ux if we are not the rightmost window? Also
1242 shouldn't a pseudo window always be rightmost? */
1183 && x > right_x - ux) 1243 && x > right_x - ux)
1184 return ON_VERTICAL_BORDER; 1244 return ON_VERTICAL_BORDER;
1185 1245
@@ -1190,8 +1250,8 @@ coordinates_in_window (register struct window *w, int x, int y)
1190 ? (x >= left_x + WINDOW_LEFT_FRINGE_WIDTH (w)) 1250 ? (x >= left_x + WINDOW_LEFT_FRINGE_WIDTH (w))
1191 : (x < left_x + lmargin_width))) 1251 : (x < left_x + lmargin_width)))
1192 return ON_LEFT_MARGIN; 1252 return ON_LEFT_MARGIN;
1193 1253 else
1194 return ON_LEFT_FRINGE; 1254 return ON_LEFT_FRINGE;
1195 } 1255 }
1196 1256
1197 if (x >= text_right) 1257 if (x >= text_right)
@@ -1201,8 +1261,8 @@ coordinates_in_window (register struct window *w, int x, int y)
1201 ? (x < right_x - WINDOW_RIGHT_FRINGE_WIDTH (w)) 1261 ? (x < right_x - WINDOW_RIGHT_FRINGE_WIDTH (w))
1202 : (x >= right_x - rmargin_width))) 1262 : (x >= right_x - rmargin_width)))
1203 return ON_RIGHT_MARGIN; 1263 return ON_RIGHT_MARGIN;
1204 1264 else
1205 return ON_RIGHT_FRINGE; 1265 return ON_RIGHT_FRINGE;
1206 } 1266 }
1207 1267
1208 /* Everything special ruled out - must be on text area */ 1268 /* Everything special ruled out - must be on text area */
@@ -1221,6 +1281,8 @@ window_relative_x_coord (struct window *w, enum window_part part, int x)
1221 case ON_TEXT: 1281 case ON_TEXT:
1222 return x - window_box_left (w, TEXT_AREA); 1282 return x - window_box_left (w, TEXT_AREA);
1223 1283
1284 case ON_HEADER_LINE:
1285 case ON_MODE_LINE:
1224 case ON_LEFT_FRINGE: 1286 case ON_LEFT_FRINGE:
1225 return x - left_x; 1287 return x - left_x;
1226 1288
@@ -1235,15 +1297,23 @@ window_relative_x_coord (struct window *w, enum window_part part, int x)
1235 case ON_RIGHT_MARGIN: 1297 case ON_RIGHT_MARGIN:
1236 return (x + 1 1298 return (x + 1
1237 - ((w->pseudo_window_p) 1299 - ((w->pseudo_window_p)
1238 ? WINDOW_TOTAL_WIDTH (w) 1300 ? WINDOW_PIXEL_WIDTH (w)
1239 : WINDOW_BOX_RIGHT_EDGE_X (w)) 1301 : WINDOW_BOX_RIGHT_EDGE_X (w))
1240 + window_box_width (w, RIGHT_MARGIN_AREA) 1302 + window_box_width (w, RIGHT_MARGIN_AREA)
1241 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)) 1303 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
1242 ? WINDOW_RIGHT_FRINGE_WIDTH (w) : 0)); 1304 ? WINDOW_RIGHT_FRINGE_WIDTH (w) : 0));
1243 }
1244 1305
1245 /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */ 1306 case ON_NOTHING:
1246 return 0; 1307 case ON_VERTICAL_BORDER:
1308 case ON_VERTICAL_SCROLL_BAR:
1309 case ON_HORIZONTAL_SCROLL_BAR:
1310 case ON_RIGHT_DIVIDER:
1311 case ON_BOTTOM_DIVIDER:
1312 return 0;
1313
1314 default:
1315 emacs_abort ();
1316 }
1247} 1317}
1248 1318
1249 1319
@@ -1253,12 +1323,14 @@ DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
1253WINDOW must be a live window and defaults to the selected one. 1323WINDOW must be a live window and defaults to the selected one.
1254COORDINATES is a cons of the form (X . Y), X and Y being distances 1324COORDINATES is a cons of the form (X . Y), X and Y being distances
1255measured in characters from the upper-left corner of the frame. 1325measured in characters from the upper-left corner of the frame.
1256\(0 . 0) denotes the character in the upper left corner of the 1326(0 . 0) denotes the character in the upper left corner of the
1257frame. 1327frame.
1258If COORDINATES are in the text portion of WINDOW, 1328If COORDINATES are in the text portion of WINDOW,
1259 the coordinates relative to the window are returned. 1329 the coordinates relative to the window are returned.
1330If they are in the bottom divider of WINDOW, `bottom-divider' is returned.
1331If they are in the right divider of WINDOW, `right-divider' is returned.
1260If they are in the mode line of WINDOW, `mode-line' is returned. 1332If they are in the mode line of WINDOW, `mode-line' is returned.
1261If they are in the top mode line of WINDOW, `header-line' is returned. 1333If they are in the header line of WINDOW, `header-line' is returned.
1262If they are in the left fringe of WINDOW, `left-fringe' is returned. 1334If they are in the left fringe of WINDOW, `left-fringe' is returned.
1263If they are in the right fringe of WINDOW, `right-fringe' is returned. 1335If they are in the right fringe of WINDOW, `right-fringe' is returned.
1264If they are on the border between WINDOW and its right sibling, 1336If they are on the border between WINDOW and its right sibling,
@@ -1316,10 +1388,19 @@ If they are in the windows's left or right marginal areas, `left-margin'\n\
1316 case ON_RIGHT_MARGIN: 1388 case ON_RIGHT_MARGIN:
1317 return Qright_margin; 1389 return Qright_margin;
1318 1390
1319 case ON_SCROLL_BAR: 1391 case ON_VERTICAL_SCROLL_BAR:
1320 /* Historically we are supposed to return nil in this case. */ 1392 /* Historically we are supposed to return nil in this case. */
1321 return Qnil; 1393 return Qnil;
1322 1394
1395 case ON_HORIZONTAL_SCROLL_BAR:
1396 return Qnil;
1397
1398 case ON_RIGHT_DIVIDER:
1399 return Qright_divider;
1400
1401 case ON_BOTTOM_DIVIDER:
1402 return Qbottom_divider;
1403
1323 default: 1404 default:
1324 emacs_abort (); 1405 emacs_abort ();
1325 } 1406 }
@@ -1333,7 +1414,7 @@ If they are in the windows's left or right marginal areas, `left-margin'\n\
1333 Check if window W contains coordinates *CW->x and *CW->y. If it 1414 Check if window W contains coordinates *CW->x and *CW->y. If it
1334 does, return W in *CW->window, as Lisp_Object, and return in 1415 does, return W in *CW->window, as Lisp_Object, and return in
1335 *CW->part the part of the window under coordinates *X,*Y. Return 1416 *CW->part the part of the window under coordinates *X,*Y. Return
1336 zero from this function to stop iterating over windows. */ 1417 false from this function to stop iterating over windows. */
1337 1418
1338struct check_window_data 1419struct check_window_data
1339{ 1420{
@@ -1342,22 +1423,19 @@ struct check_window_data
1342 enum window_part *part; 1423 enum window_part *part;
1343}; 1424};
1344 1425
1345static int 1426static bool
1346check_window_containing (struct window *w, void *user_data) 1427check_window_containing (struct window *w, void *user_data)
1347{ 1428{
1348 struct check_window_data *cw = user_data; 1429 struct check_window_data *cw = user_data;
1349 enum window_part found; 1430 enum window_part found = coordinates_in_window (w, cw->x, cw->y);
1350 int continue_p = 1; 1431 if (found == ON_NOTHING)
1351 1432 return true;
1352 found = coordinates_in_window (w, cw->x, cw->y); 1433 else
1353 if (found != ON_NOTHING)
1354 { 1434 {
1355 *cw->part = found; 1435 *cw->part = found;
1356 XSETWINDOW (*cw->window, w); 1436 XSETWINDOW (*cw->window, w);
1357 continue_p = 0; 1437 return false;
1358 } 1438 }
1359
1360 return continue_p;
1361} 1439}
1362 1440
1363 1441
@@ -1368,7 +1446,7 @@ check_window_containing (struct window *w, void *user_data)
1368 set *PART to the id of that element. 1446 set *PART to the id of that element.
1369 1447
1370 If there is no window under X, Y return nil and leave *PART 1448 If there is no window under X, Y return nil and leave *PART
1371 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows. 1449 unmodified. TOOL_BAR_P means detect tool-bar windows.
1372 1450
1373 This function was previously implemented with a loop cycling over 1451 This function was previously implemented with a loop cycling over
1374 windows with Fnext_window, and starting with the frame's selected 1452 windows with Fnext_window, and starting with the frame's selected
@@ -1394,6 +1472,7 @@ window_from_coordinates (struct frame *f, int x, int y,
1394 cw.window = &window, cw.x = x, cw.y = y; cw.part = part; 1472 cw.window = &window, cw.x = x, cw.y = y; cw.part = part;
1395 foreach_window (f, check_window_containing, &cw); 1473 foreach_window (f, check_window_containing, &cw);
1396 1474
1475#if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
1397 /* If not found above, see if it's in the tool bar window, if a tool 1476 /* If not found above, see if it's in the tool bar window, if a tool
1398 bar exists. */ 1477 bar exists. */
1399 if (NILP (window) 1478 if (NILP (window)
@@ -1406,6 +1485,7 @@ window_from_coordinates (struct frame *f, int x, int y,
1406 *part = ON_TEXT; 1485 *part = ON_TEXT;
1407 window = f->tool_bar_window; 1486 window = f->tool_bar_window;
1408 } 1487 }
1488#endif
1409 1489
1410 return window; 1490 return window;
1411} 1491}
@@ -1428,7 +1508,7 @@ column 0. */)
1428 + FRAME_INTERNAL_BORDER_WIDTH (f)), 1508 + FRAME_INTERNAL_BORDER_WIDTH (f)),
1429 (FRAME_PIXEL_Y_FROM_CANON_Y (f, y) 1509 (FRAME_PIXEL_Y_FROM_CANON_Y (f, y)
1430 + FRAME_INTERNAL_BORDER_WIDTH (f)), 1510 + FRAME_INTERNAL_BORDER_WIDTH (f)),
1431 0, 0); 1511 0, false);
1432} 1512}
1433 1513
1434DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0, 1514DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0,
@@ -1452,6 +1532,14 @@ correct to return the top-level value of `point', outside of any
1452 return Fmarker_position (w->pointm); 1532 return Fmarker_position (w->pointm);
1453} 1533}
1454 1534
1535DEFUN ("window-old-point", Fwindow_old_point, Swindow_old_point, 0, 1, 0,
1536 doc: /* Return old value of point in WINDOW.
1537WINDOW must be a live window and defaults to the selected one. */)
1538 (Lisp_Object window)
1539{
1540 return Fmarker_position (decode_live_window (window)->old_pointm);
1541}
1542
1455DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0, 1543DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0,
1456 doc: /* Return position at which display currently starts in WINDOW. 1544 doc: /* Return position at which display currently starts in WINDOW.
1457WINDOW must be a live window and defaults to the selected one. 1545WINDOW must be a live window and defaults to the selected one.
@@ -1499,10 +1587,13 @@ if it isn't already recorded. */)
1499 || b->clip_changed 1587 || b->clip_changed
1500 || b->prevent_redisplay_optimizations_p 1588 || b->prevent_redisplay_optimizations_p
1501 || window_outdated (w)) 1589 || window_outdated (w))
1502 && !noninteractive) 1590 /* Don't call display routines if we didn't yet create any real
1591 frames, because the glyph matrices are not yet allocated in
1592 that case. This could happen in some code that runs in the
1593 daemon during initialization (e.g., see bug#20565). */
1594 && !(noninteractive || FRAME_INITIAL_P (WINDOW_XFRAME (w))))
1503 { 1595 {
1504 struct text_pos startp; 1596 struct text_pos startp;
1505 ptrdiff_t charpos = marker_position (w->start);
1506 struct it it; 1597 struct it it;
1507 struct buffer *old_buffer = NULL; 1598 struct buffer *old_buffer = NULL;
1508 void *itdata = NULL; 1599 void *itdata = NULL;
@@ -1520,12 +1611,7 @@ if it isn't already recorded. */)
1520 `-l' containing a call to `rmail' with subsequent other 1611 `-l' containing a call to `rmail' with subsequent other
1521 commands. At the end, W->start happened to be BEG, while 1612 commands. At the end, W->start happened to be BEG, while
1522 rmail had already narrowed the buffer. */ 1613 rmail had already narrowed the buffer. */
1523 if (charpos < BEGV) 1614 CLIP_TEXT_POS_FROM_MARKER (startp, w->start);
1524 SET_TEXT_POS (startp, BEGV, BEGV_BYTE);
1525 else if (charpos > ZV)
1526 SET_TEXT_POS (startp, ZV, ZV_BYTE);
1527 else
1528 SET_TEXT_POS_FROM_MARKER (startp, w->start);
1529 1615
1530 itdata = bidi_shelve_cache (); 1616 itdata = bidi_shelve_cache ();
1531 start_display (&it, w, startp); 1617 start_display (&it, w, startp);
@@ -1533,7 +1619,7 @@ if it isn't already recorded. */)
1533 if (it.current_y < it.last_visible_y) 1619 if (it.current_y < it.last_visible_y)
1534 move_it_past_eol (&it); 1620 move_it_past_eol (&it);
1535 value = make_number (IT_CHARPOS (it)); 1621 value = make_number (IT_CHARPOS (it));
1536 bidi_unshelve_cache (itdata, 0); 1622 bidi_unshelve_cache (itdata, false);
1537 1623
1538 if (old_buffer) 1624 if (old_buffer)
1539 set_buffer_internal (old_buffer); 1625 set_buffer_internal (old_buffer);
@@ -1574,7 +1660,7 @@ Return POS. */)
1574 set_marker_restricted (w->pointm, pos, w->contents); 1660 set_marker_restricted (w->pointm, pos, w->contents);
1575 /* We have to make sure that redisplay updates the window to show 1661 /* We have to make sure that redisplay updates the window to show
1576 the new value of point. */ 1662 the new value of point. */
1577 ++windows_or_buffers_changed; 1663 wset_redisplay (w);
1578 } 1664 }
1579 1665
1580 return pos; 1666 return pos;
@@ -1591,13 +1677,13 @@ overriding motion of point in order to display at this exact start. */)
1591 1677
1592 set_marker_restricted (w->start, pos, w->contents); 1678 set_marker_restricted (w->start, pos, w->contents);
1593 /* This is not right, but much easier than doing what is right. */ 1679 /* This is not right, but much easier than doing what is right. */
1594 w->start_at_line_beg = 0; 1680 w->start_at_line_beg = false;
1595 if (NILP (noforce)) 1681 if (NILP (noforce))
1596 w->force_start = 1; 1682 w->force_start = true;
1597 w->update_mode_line = 1; 1683 wset_update_mode_line (w);
1598 if (w != XWINDOW (selected_window)) 1684 /* Bug#15957. */
1599 /* Enforce full redisplay. FIXME: make it more selective. */ 1685 w->window_end_valid = false;
1600 windows_or_buffers_changed++; 1686 wset_redisplay (w);
1601 1687
1602 return pos; 1688 return pos;
1603} 1689}
@@ -1611,8 +1697,10 @@ Return nil if that position is scrolled vertically out of view. If a
1611character is only partially visible, nil is returned, unless the 1697character is only partially visible, nil is returned, unless the
1612optional argument PARTIALLY is non-nil. If POS is only out of view 1698optional argument PARTIALLY is non-nil. If POS is only out of view
1613because of horizontal scrolling, return non-nil. If POS is t, it 1699because of horizontal scrolling, return non-nil. If POS is t, it
1614specifies the position of the last visible glyph in WINDOW. POS 1700specifies either the first position displayed on the last visible
1615defaults to point in WINDOW; WINDOW defaults to the selected window. 1701screen line in WINDOW, or the end-of-buffer position, whichever comes
1702first. POS defaults to point in WINDOW; WINDOW defaults to the
1703selected window.
1616 1704
1617If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil, 1705If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1618the return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]), 1706the return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
@@ -1621,15 +1709,16 @@ of the window. The remaining elements are omitted if the character after
1621POS is fully visible; otherwise, RTOP and RBOT are the number of pixels 1709POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1622off-window at the top and bottom of the screen line ("row") containing 1710off-window at the top and bottom of the screen line ("row") containing
1623POS, ROWH is the visible height of that row, and VPOS is the row number 1711POS, ROWH is the visible height of that row, and VPOS is the row number
1624\(zero-based). */) 1712(zero-based). */)
1625 (Lisp_Object pos, Lisp_Object window, Lisp_Object partially) 1713 (Lisp_Object pos, Lisp_Object window, Lisp_Object partially)
1626{ 1714{
1627 register struct window *w; 1715 struct window *w;
1628 register EMACS_INT posint; 1716 EMACS_INT posint;
1629 register struct buffer *buf; 1717 struct buffer *buf;
1630 struct text_pos top; 1718 struct text_pos top;
1631 Lisp_Object in_window = Qnil; 1719 Lisp_Object in_window = Qnil;
1632 int rtop, rbot, rowh, vpos, fully_p = 1; 1720 int rtop, rbot, rowh, vpos;
1721 bool fully_p = true;
1633 int x, y; 1722 int x, y;
1634 1723
1635 w = decode_live_window (window); 1724 w = decode_live_window (window);
@@ -1654,9 +1743,12 @@ POS, ROWH is the visible height of that row, and VPOS is the row number
1654 || (posint >= CHARPOS (top) && posint <= BUF_ZV (buf))) 1743 || (posint >= CHARPOS (top) && posint <= BUF_ZV (buf)))
1655 && CHARPOS (top) >= BUF_BEGV (buf) 1744 && CHARPOS (top) >= BUF_BEGV (buf)
1656 && CHARPOS (top) <= BUF_ZV (buf) 1745 && CHARPOS (top) <= BUF_ZV (buf)
1657 && pos_visible_p (w, posint, &x, &y, &rtop, &rbot, &rowh, &vpos) 1746 && pos_visible_p (w, posint, &x, &y, &rtop, &rbot, &rowh, &vpos))
1658 && (fully_p = !rtop && !rbot, (!NILP (partially) || fully_p))) 1747 {
1659 in_window = Qt; 1748 fully_p = !rtop && !rbot;
1749 if (!NILP (partially) || fully_p)
1750 in_window = Qt;
1751 }
1660 1752
1661 if (!NILP (in_window) && !NILP (partially)) 1753 if (!NILP (in_window) && !NILP (partially))
1662 { 1754 {
@@ -1961,7 +2053,7 @@ unshow_buffer (register struct window *w)
1961 2053
1962 eassert (b == XMARKER (w->pointm)->buffer); 2054 eassert (b == XMARKER (w->pointm)->buffer);
1963 2055
1964#if 0 2056#if false
1965 if (w == XWINDOW (selected_window) 2057 if (w == XWINDOW (selected_window)
1966 || ! EQ (buf, XWINDOW (selected_window)->contents)) 2058 || ! EQ (buf, XWINDOW (selected_window)->contents))
1967 /* Do this except when the selected window's buffer 2059 /* Do this except when the selected window's buffer
@@ -2000,14 +2092,14 @@ unshow_buffer (register struct window *w)
2000 bset_last_selected_window (b, Qnil); 2092 bset_last_selected_window (b, Qnil);
2001} 2093}
2002 2094
2003/* Put NEW into the window structure in place of OLD. SETFLAG zero 2095/* Put NEW into the window structure in place of OLD. SETFLAG false
2004 means change window structure only. Otherwise store geometry and 2096 means change window structure only. Otherwise store geometry and
2005 other settings as well. */ 2097 other settings as well. */
2006static void 2098static void
2007replace_window (Lisp_Object old, Lisp_Object new, int setflag) 2099replace_window (Lisp_Object old, Lisp_Object new, bool setflag)
2008{ 2100{
2009 register Lisp_Object tem; 2101 Lisp_Object tem;
2010 register struct window *o = XWINDOW (old), *n = XWINDOW (new); 2102 struct window *o = XWINDOW (old), *n = XWINDOW (new);
2011 2103
2012 /* If OLD is its frame's root window, then NEW is the new 2104 /* If OLD is its frame's root window, then NEW is the new
2013 root window for that frame. */ 2105 root window for that frame. */
@@ -2016,6 +2108,10 @@ replace_window (Lisp_Object old, Lisp_Object new, int setflag)
2016 2108
2017 if (setflag) 2109 if (setflag)
2018 { 2110 {
2111 n->pixel_left = o->pixel_left;
2112 n->pixel_top = o->pixel_top;
2113 n->pixel_width = o->pixel_width;
2114 n->pixel_height = o->pixel_height;
2019 n->left_col = o->left_col; 2115 n->left_col = o->left_col;
2020 n->top_line = o->top_line; 2116 n->top_line = o->top_line;
2021 n->total_cols = o->total_cols; 2117 n->total_cols = o->total_cols;
@@ -2027,15 +2123,17 @@ replace_window (Lisp_Object old, Lisp_Object new, int setflag)
2027 n->desired_matrix = n->current_matrix = 0; 2123 n->desired_matrix = n->current_matrix = 0;
2028 n->vscroll = 0; 2124 n->vscroll = 0;
2029 memset (&n->cursor, 0, sizeof (n->cursor)); 2125 memset (&n->cursor, 0, sizeof (n->cursor));
2030 memset (&n->last_cursor, 0, sizeof (n->last_cursor));
2031 memset (&n->phys_cursor, 0, sizeof (n->phys_cursor)); 2126 memset (&n->phys_cursor, 0, sizeof (n->phys_cursor));
2032 n->phys_cursor_type = -1; 2127 n->last_cursor_vpos = 0;
2128#ifdef HAVE_WINDOW_SYSTEM
2129 n->phys_cursor_type = NO_CURSOR;
2033 n->phys_cursor_width = -1; 2130 n->phys_cursor_width = -1;
2034 n->must_be_updated_p = 0; 2131#endif
2035 n->pseudo_window_p = 0; 2132 n->must_be_updated_p = false;
2133 n->pseudo_window_p = false;
2036 n->window_end_vpos = 0; 2134 n->window_end_vpos = 0;
2037 n->window_end_pos = 0; 2135 n->window_end_pos = 0;
2038 n->window_end_valid = 0; 2136 n->window_end_valid = false;
2039 } 2137 }
2040 2138
2041 tem = o->next; 2139 tem = o->next;
@@ -2094,13 +2192,13 @@ recombine_windows (Lisp_Object window)
2094 wset_parent (c, parent); 2192 wset_parent (c, parent);
2095 2193
2096 if (horflag) 2194 if (horflag)
2097 wset_normal_cols (c, 2195 wset_normal_cols
2098 make_float ((double) c->total_cols 2196 (c, make_float ((double) c->pixel_width
2099 / (double) p->total_cols)); 2197 / (double) p->pixel_width));
2100 else 2198 else
2101 wset_normal_lines (c, 2199 wset_normal_lines
2102 make_float ((double) c->total_lines 2200 (c, make_float ((double) c->pixel_height
2103 / (double) p->total_lines)); 2201 / (double) p->pixel_height));
2104 2202
2105 if (NILP (c->next)) 2203 if (NILP (c->next))
2106 { 2204 {
@@ -2120,7 +2218,7 @@ recombine_windows (Lisp_Object window)
2120 } 2218 }
2121 2219
2122 /* WINDOW can be deleted now. */ 2220 /* WINDOW can be deleted now. */
2123 wset_combination (w, 0, Qnil); 2221 wset_combination (w, false, Qnil);
2124 } 2222 }
2125 } 2223 }
2126} 2224}
@@ -2141,14 +2239,14 @@ delete_deletable_window (Lisp_Object window)
2141 pointer. This is a callback function for foreach_window, used in 2239 pointer. This is a callback function for foreach_window, used in
2142 the window_list function. */ 2240 the window_list function. */
2143 2241
2144static int 2242static bool
2145add_window_to_list (struct window *w, void *user_data) 2243add_window_to_list (struct window *w, void *user_data)
2146{ 2244{
2147 Lisp_Object *list = user_data; 2245 Lisp_Object *list = user_data;
2148 Lisp_Object window; 2246 Lisp_Object window;
2149 XSETWINDOW (window, w); 2247 XSETWINDOW (window, w);
2150 *list = Fcons (window, *list); 2248 *list = Fcons (window, *list);
2151 return 1; 2249 return true;
2152} 2250}
2153 2251
2154 2252
@@ -2156,7 +2254,7 @@ add_window_to_list (struct window *w, void *user_data)
2156 Vwindow_list is a list, return that list. Otherwise, build a new 2254 Vwindow_list is a list, return that list. Otherwise, build a new
2157 list, cache it in Vwindow_list, and return that. */ 2255 list, cache it in Vwindow_list, and return that. */
2158 2256
2159static Lisp_Object 2257Lisp_Object
2160window_list (void) 2258window_list (void)
2161{ 2259{
2162 if (!CONSP (Vwindow_list)) 2260 if (!CONSP (Vwindow_list))
@@ -2166,16 +2264,14 @@ window_list (void)
2166 Vwindow_list = Qnil; 2264 Vwindow_list = Qnil;
2167 FOR_EACH_FRAME (tail, frame) 2265 FOR_EACH_FRAME (tail, frame)
2168 { 2266 {
2169 Lisp_Object args[2]; 2267 Lisp_Object arglist = Qnil;
2170 2268
2171 /* We are visiting windows in canonical order, and add 2269 /* We are visiting windows in canonical order, and add
2172 new windows at the front of args[1], which means we 2270 new windows at the front of args[1], which means we
2173 have to reverse this list at the end. */ 2271 have to reverse this list at the end. */
2174 args[1] = Qnil; 2272 foreach_window (XFRAME (frame), add_window_to_list, &arglist);
2175 foreach_window (XFRAME (frame), add_window_to_list, &args[1]); 2273 arglist = Fnreverse (arglist);
2176 args[0] = Vwindow_list; 2274 Vwindow_list = CALLN (Fnconc, Vwindow_list, arglist);
2177 args[1] = Fnreverse (args[1]);
2178 Vwindow_list = Fnconc (2, args);
2179 } 2275 }
2180 } 2276 }
2181 2277
@@ -2183,7 +2279,7 @@ window_list (void)
2183} 2279}
2184 2280
2185 2281
2186/* Value is non-zero if WINDOW satisfies the constraints given by 2282/* Value is true if WINDOW satisfies the constraints given by
2187 OWINDOW, MINIBUF and ALL_FRAMES. 2283 OWINDOW, MINIBUF and ALL_FRAMES.
2188 2284
2189 MINIBUF t means WINDOW may be minibuffer windows. 2285 MINIBUF t means WINDOW may be minibuffer windows.
@@ -2205,20 +2301,20 @@ candidate_window_p (Lisp_Object window, Lisp_Object owindow,
2205{ 2301{
2206 struct window *w = XWINDOW (window); 2302 struct window *w = XWINDOW (window);
2207 struct frame *f = XFRAME (w->frame); 2303 struct frame *f = XFRAME (w->frame);
2208 bool candidate_p = 1; 2304 bool candidate_p = true;
2209 2305
2210 if (!BUFFERP (w->contents)) 2306 if (!BUFFERP (w->contents))
2211 candidate_p = 0; 2307 candidate_p = false;
2212 else if (MINI_WINDOW_P (w) 2308 else if (MINI_WINDOW_P (w)
2213 && (EQ (minibuf, Qlambda) 2309 && (EQ (minibuf, Qlambda)
2214 || (WINDOWP (minibuf) && !EQ (minibuf, window)))) 2310 || (WINDOWP (minibuf) && !EQ (minibuf, window))))
2215 { 2311 {
2216 /* If MINIBUF is `lambda' don't consider any mini-windows. 2312 /* If MINIBUF is `lambda' don't consider any mini-windows.
2217 If it is a window, consider only that one. */ 2313 If it is a window, consider only that one. */
2218 candidate_p = 0; 2314 candidate_p = false;
2219 } 2315 }
2220 else if (EQ (all_frames, Qt)) 2316 else if (EQ (all_frames, Qt))
2221 candidate_p = 1; 2317 candidate_p = true;
2222 else if (NILP (all_frames)) 2318 else if (NILP (all_frames))
2223 { 2319 {
2224 eassert (WINDOWP (owindow)); 2320 eassert (WINDOWP (owindow));
@@ -2298,12 +2394,13 @@ decode_next_window_args (Lisp_Object *window, Lisp_Object *minibuf, Lisp_Object
2298 2394
2299 2395
2300/* Return the next or previous window of WINDOW in cyclic ordering 2396/* Return the next or previous window of WINDOW in cyclic ordering
2301 of windows. NEXT_P non-zero means return the next window. See the 2397 of windows. NEXT_P means return the next window. See the
2302 documentation string of next-window for the meaning of MINIBUF and 2398 documentation string of next-window for the meaning of MINIBUF and
2303 ALL_FRAMES. */ 2399 ALL_FRAMES. */
2304 2400
2305static Lisp_Object 2401static Lisp_Object
2306next_window (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames, int next_p) 2402next_window (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames,
2403 bool next_p)
2307{ 2404{
2308 decode_next_window_args (&window, &minibuf, &all_frames); 2405 decode_next_window_args (&window, &minibuf, &all_frames);
2309 2406
@@ -2401,7 +2498,7 @@ windows, eventually ending up back at the window you started with.
2401`previous-window' traverses the same cycle, in the reverse order. */) 2498`previous-window' traverses the same cycle, in the reverse order. */)
2402 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames) 2499 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2403{ 2500{
2404 return next_window (window, minibuf, all_frames, 1); 2501 return next_window (window, minibuf, all_frames, true);
2405} 2502}
2406 2503
2407 2504
@@ -2441,7 +2538,7 @@ started with. `next-window' traverses the same cycle, in the
2441reverse order. */) 2538reverse order. */)
2442 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames) 2539 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2443{ 2540{
2444 return next_window (window, minibuf, all_frames, 0); 2541 return next_window (window, minibuf, all_frames, false);
2445} 2542}
2446 2543
2447 2544
@@ -2539,7 +2636,7 @@ be listed first but no error is signaled. */)
2539 Qnil, look at just the selected frame; 2636 Qnil, look at just the selected frame;
2540 Qvisible, look at visible frames; 2637 Qvisible, look at visible frames;
2541 a frame, just look at windows on that frame. 2638 a frame, just look at windows on that frame.
2542 If MINI is non-zero, perform the operation on minibuffer windows too. */ 2639 If MINI, perform the operation on minibuffer windows too. */
2543 2640
2544enum window_loop 2641enum window_loop
2545{ 2642{
@@ -2551,12 +2648,12 @@ enum window_loop
2551}; 2648};
2552 2649
2553static Lisp_Object 2650static Lisp_Object
2554window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frames) 2651window_loop (enum window_loop type, Lisp_Object obj, bool mini,
2652 Lisp_Object frames)
2555{ 2653{
2556 Lisp_Object window, windows, best_window, frame_arg; 2654 Lisp_Object window, windows, best_window, frame_arg;
2557 int frame_best_window_flag = 0; 2655 bool frame_best_window_flag = false;
2558 struct frame *f; 2656 struct frame *f;
2559 struct gcpro gcpro1;
2560 2657
2561 /* If we're only looping through windows on a particular frame, 2658 /* If we're only looping through windows on a particular frame,
2562 frame points to that frame. If we're looping through windows 2659 frame points to that frame. If we're looping through windows
@@ -2590,7 +2687,6 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame
2590 window = FRAME_SELECTED_WINDOW (SELECTED_FRAME ()); 2687 window = FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2591 2688
2592 windows = window_list_1 (window, mini ? Qt : Qnil, frame_arg); 2689 windows = window_list_1 (window, mini ? Qt : Qnil, frame_arg);
2593 GCPRO1 (windows);
2594 best_window = Qnil; 2690 best_window = Qnil;
2595 2691
2596 for (; CONSP (windows); windows = XCDR (windows)) 2692 for (; CONSP (windows); windows = XCDR (windows))
@@ -2614,18 +2710,18 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame
2614 if (EQ (w->contents, obj) 2710 if (EQ (w->contents, obj)
2615 /* Don't find any minibuffer window except the one that 2711 /* Don't find any minibuffer window except the one that
2616 is currently in use. */ 2712 is currently in use. */
2617 && (MINI_WINDOW_P (w) ? EQ (window, minibuf_window) : 1)) 2713 && (!MINI_WINDOW_P (w) || EQ (window, minibuf_window)))
2618 { 2714 {
2619 if (EQ (window, selected_window)) 2715 if (EQ (window, selected_window))
2620 /* Preferably return the selected window. */ 2716 /* Preferably return the selected window. */
2621 RETURN_UNGCPRO (window); 2717 return window;
2622 else if (EQ (XWINDOW (window)->frame, selected_frame) 2718 else if (EQ (XWINDOW (window)->frame, selected_frame)
2623 && !frame_best_window_flag) 2719 && !frame_best_window_flag)
2624 /* Prefer windows on the current frame (but don't 2720 /* Prefer windows on the current frame (but don't
2625 choose another one if we have one already). */ 2721 choose another one if we have one already). */
2626 { 2722 {
2627 best_window = window; 2723 best_window = window;
2628 frame_best_window_flag = 1; 2724 frame_best_window_flag = true;
2629 } 2725 }
2630 else if (NILP (best_window)) 2726 else if (NILP (best_window))
2631 best_window = window; 2727 best_window = window;
@@ -2642,7 +2738,7 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame
2642 /* Make WINDOW show the buffer returned by 2738 /* Make WINDOW show the buffer returned by
2643 other_buffer_safely, don't run any hooks. */ 2739 other_buffer_safely, don't run any hooks. */
2644 set_window_buffer 2740 set_window_buffer
2645 (window, other_buffer_safely (w->contents), 0, 0); 2741 (window, other_buffer_safely (w->contents), false, false);
2646 /* If WINDOW is the selected window, make its buffer 2742 /* If WINDOW is the selected window, make its buffer
2647 current. But do so only if the window shows the 2743 current. But do so only if the window shows the
2648 current buffer (Bug#6454). */ 2744 current buffer (Bug#6454). */
@@ -2655,10 +2751,10 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame
2655 case REDISPLAY_BUFFER_WINDOWS: 2751 case REDISPLAY_BUFFER_WINDOWS:
2656 if (EQ (w->contents, obj)) 2752 if (EQ (w->contents, obj))
2657 { 2753 {
2658 mark_window_display_accurate (window, 0); 2754 mark_window_display_accurate (window, false);
2659 w->update_mode_line = 1; 2755 w->update_mode_line = true;
2660 XBUFFER (obj)->prevent_redisplay_optimizations_p = 1; 2756 XBUFFER (obj)->prevent_redisplay_optimizations_p = true;
2661 ++update_mode_lines; 2757 update_mode_lines = 27;
2662 best_window = window; 2758 best_window = window;
2663 } 2759 }
2664 break; 2760 break;
@@ -2684,7 +2780,6 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame
2684 } 2780 }
2685 } 2781 }
2686 2782
2687 UNGCPRO;
2688 return best_window; 2783 return best_window;
2689} 2784}
2690 2785
@@ -2694,7 +2789,7 @@ extern void check_all_windows (void) EXTERNALLY_VISIBLE;
2694void 2789void
2695check_all_windows (void) 2790check_all_windows (void)
2696{ 2791{
2697 window_loop (CHECK_ALL_WINDOWS, Qnil, 1, Qt); 2792 window_loop (CHECK_ALL_WINDOWS, Qnil, true, Qt);
2698} 2793}
2699 2794
2700DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 0, 2, 0, 2795DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 0, 2, 0,
@@ -2725,15 +2820,39 @@ selected frame and no others. */)
2725 buffer = Fget_buffer (buffer_or_name); 2820 buffer = Fget_buffer (buffer_or_name);
2726 2821
2727 if (BUFFERP (buffer)) 2822 if (BUFFERP (buffer))
2728 return window_loop (GET_BUFFER_WINDOW, buffer, 1, all_frames); 2823 return window_loop (GET_BUFFER_WINDOW, buffer, true, all_frames);
2729 else 2824 else
2730 return Qnil; 2825 return Qnil;
2731} 2826}
2732 2827
2828
2829static Lisp_Object
2830resize_root_window (Lisp_Object window, Lisp_Object delta, Lisp_Object horizontal, Lisp_Object ignore, Lisp_Object pixelwise)
2831{
2832 return call5 (Qwindow_resize_root_window, window, delta, horizontal, ignore, pixelwise);
2833}
2834
2835/* Placeholder used by temacs -nw before window.el is loaded. */
2836DEFUN ("window--sanitize-window-sizes", Fwindow__sanitize_window_sizes,
2837 Swindow__sanitize_window_sizes, 2, 2, 0,
2838 doc: /* */
2839 attributes: const)
2840 (Lisp_Object frame, Lisp_Object horizontal)
2841{
2842 return Qnil;
2843}
2844
2845Lisp_Object
2846sanitize_window_sizes (Lisp_Object frame, Lisp_Object horizontal)
2847{
2848 return call2 (Qwindow_sanitize_window_sizes, frame, horizontal);
2849}
2850
2851
2733static Lisp_Object 2852static Lisp_Object
2734resize_root_window (Lisp_Object window, Lisp_Object delta, Lisp_Object horizontal, Lisp_Object ignore) 2853window_pixel_to_total (Lisp_Object frame, Lisp_Object horizontal)
2735{ 2854{
2736 return call4 (Qwindow_resize_root_window, window, delta, horizontal, ignore); 2855 return call2 (Qwindow_pixel_to_total, frame, horizontal);
2737} 2856}
2738 2857
2739 2858
@@ -2758,7 +2877,7 @@ window-start value is reasonable when this function is called. */)
2758 struct frame *f; 2877 struct frame *f;
2759 Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta; 2878 Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta;
2760 ptrdiff_t startpos IF_LINT (= 0), startbyte IF_LINT (= 0); 2879 ptrdiff_t startpos IF_LINT (= 0), startbyte IF_LINT (= 0);
2761 int top IF_LINT (= 0), new_top, resize_failed; 2880 int top IF_LINT (= 0), new_top;
2762 2881
2763 w = decode_valid_window (window); 2882 w = decode_valid_window (window);
2764 XSETWINDOW (window, w); 2883 XSETWINDOW (window, w);
@@ -2797,8 +2916,8 @@ window-start value is reasonable when this function is called. */)
2797 { 2916 {
2798 startpos = marker_position (w->start); 2917 startpos = marker_position (w->start);
2799 startbyte = marker_byte_position (w->start); 2918 startbyte = marker_byte_position (w->start);
2800 top = WINDOW_TOP_EDGE_LINE (w) 2919 top = (WINDOW_TOP_EDGE_LINE (w)
2801 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w))); 2920 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w))));
2802 /* Make sure WINDOW is the frame's selected window. */ 2921 /* Make sure WINDOW is the frame's selected window. */
2803 if (!EQ (window, FRAME_SELECTED_WINDOW (f))) 2922 if (!EQ (window, FRAME_SELECTED_WINDOW (f)))
2804 { 2923 {
@@ -2815,7 +2934,7 @@ window-start value is reasonable when this function is called. */)
2815 parents and comparing each one with WINDOW. If it isn't we 2934 parents and comparing each one with WINDOW. If it isn't we
2816 need a new selected window for this frame. */ 2935 need a new selected window for this frame. */
2817 swindow = FRAME_SELECTED_WINDOW (f); 2936 swindow = FRAME_SELECTED_WINDOW (f);
2818 while (1) 2937 while (true)
2819 { 2938 {
2820 pwindow = swindow; 2939 pwindow = swindow;
2821 while (!NILP (pwindow) && !EQ (window, pwindow)) 2940 while (!NILP (pwindow) && !EQ (window, pwindow))
@@ -2842,61 +2961,71 @@ window-start value is reasonable when this function is called. */)
2842 block_input (); 2961 block_input ();
2843 if (!FRAME_INITIAL_P (f)) 2962 if (!FRAME_INITIAL_P (f))
2844 { 2963 {
2845 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); 2964 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
2846 2965
2847 /* We are going to free the glyph matrices of WINDOW, and with 2966 /* We are going to free the glyph matrices of WINDOW, and with
2848 that we might lose any information about glyph rows that have 2967 that we might lose any information about glyph rows that have
2849 some of their glyphs highlighted in mouse face. (These rows 2968 some of their glyphs highlighted in mouse face. (These rows
2850 are marked with a non-zero mouse_face_p flag.) If WINDOW 2969 are marked with a mouse_face_p flag.) If WINDOW
2851 indeed has some glyphs highlighted in mouse face, signal to 2970 indeed has some glyphs highlighted in mouse face, signal to
2852 frame's up-to-date hook that mouse highlight was overwritten, 2971 frame's up-to-date hook that mouse highlight was overwritten,
2853 so that it will arrange for redisplaying the highlight. */ 2972 so that it will arrange for redisplaying the highlight. */
2854 if (EQ (hlinfo->mouse_face_window, window)) 2973 if (EQ (hlinfo->mouse_face_window, window))
2855 { 2974 reset_mouse_highlight (hlinfo);
2856 hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
2857 hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
2858 hlinfo->mouse_face_window = Qnil;
2859 }
2860 } 2975 }
2861 free_window_matrices (r); 2976 free_window_matrices (r);
2862 2977
2863 windows_or_buffers_changed++; 2978 fset_redisplay (f);
2864 Vwindow_list = Qnil; 2979 Vwindow_list = Qnil;
2865 FRAME_WINDOW_SIZES_CHANGED (f) = 1; 2980 FRAME_WINDOW_SIZES_CHANGED (f) = true;
2866 resize_failed = 0; 2981 bool resize_failed = false;
2867 2982
2868 if (!WINDOW_LEAF_P (w)) 2983 if (!WINDOW_LEAF_P (w))
2869 { 2984 {
2870 /* Resize child windows vertically. */ 2985 /* Resize child windows vertically. */
2871 XSETINT (delta, r->total_lines - w->total_lines); 2986 XSETINT (delta, r->pixel_height - w->pixel_height);
2987 w->pixel_top = r->pixel_top;
2872 w->top_line = r->top_line; 2988 w->top_line = r->top_line;
2873 resize_root_window (window, delta, Qnil, Qnil); 2989 resize_root_window (window, delta, Qnil, Qnil, Qt);
2874 if (window_resize_check (w, 0)) 2990 if (window_resize_check (w, false))
2875 window_resize_apply (w, 0); 2991 {
2992 window_resize_apply (w, false);
2993 window_pixel_to_total (w->frame, Qnil);
2994 }
2876 else 2995 else
2877 { 2996 {
2878 resize_root_window (window, delta, Qnil, Qt); 2997 resize_root_window (window, delta, Qnil, Qt, Qt);
2879 if (window_resize_check (w, 0)) 2998 if (window_resize_check (w, false))
2880 window_resize_apply (w, 0); 2999 {
3000 window_resize_apply (w, false);
3001 window_pixel_to_total (w->frame, Qnil);
3002 }
2881 else 3003 else
2882 resize_failed = 1; 3004 resize_failed = true;
2883 } 3005 }
2884 3006
2885 /* Resize child windows horizontally. */ 3007 /* Resize child windows horizontally. */
2886 if (!resize_failed) 3008 if (!resize_failed)
2887 { 3009 {
2888 w->left_col = r->left_col; 3010 w->left_col = r->left_col;
2889 XSETINT (delta, r->total_cols - w->total_cols); 3011 w->pixel_left = r->pixel_left;
2890 resize_root_window (window, delta, Qt, Qnil); 3012 XSETINT (delta, r->pixel_width - w->pixel_width);
2891 if (window_resize_check (w, 1)) 3013 resize_root_window (window, delta, Qt, Qnil, Qt);
2892 window_resize_apply (w, 1); 3014 if (window_resize_check (w, true))
3015 {
3016 window_resize_apply (w, true);
3017 window_pixel_to_total (w->frame, Qt);
3018 }
2893 else 3019 else
2894 { 3020 {
2895 resize_root_window (window, delta, Qt, Qt); 3021 resize_root_window (window, delta, Qt, Qt, Qt);
2896 if (window_resize_check (w, 1)) 3022 if (window_resize_check (w, true))
2897 window_resize_apply (w, 1); 3023 {
3024 window_resize_apply (w, true);
3025 window_pixel_to_total (w->frame, Qt);
3026 }
2898 else 3027 else
2899 resize_failed = 1; 3028 resize_failed = true;
2900 } 3029 }
2901 } 3030 }
2902 3031
@@ -2932,10 +3061,10 @@ window-start value is reasonable when this function is called. */)
2932 if (WINDOWP (r->contents)) 3061 if (WINDOWP (r->contents))
2933 { 3062 {
2934 delete_all_child_windows (r->contents); 3063 delete_all_child_windows (r->contents);
2935 wset_combination (r, 0, Qnil); 3064 wset_combination (r, false, Qnil);
2936 } 3065 }
2937 3066
2938 replace_window (root, window, 1); 3067 replace_window (root, window, true);
2939 3068
2940 /* This must become SWINDOW anyway ....... */ 3069 /* This must become SWINDOW anyway ....... */
2941 if (BUFFERP (w->contents) && !resize_failed) 3070 if (BUFFERP (w->contents) && !resize_failed)
@@ -2959,18 +3088,18 @@ window-start value is reasonable when this function is called. */)
2959 pos = *vmotion (startpos, startbyte, -top, w); 3088 pos = *vmotion (startpos, startbyte, -top, w);
2960 3089
2961 set_marker_both (w->start, w->contents, pos.bufpos, pos.bytepos); 3090 set_marker_both (w->start, w->contents, pos.bufpos, pos.bytepos);
2962 w->window_end_valid = 0; 3091 w->window_end_valid = false;
2963 w->start_at_line_beg = (pos.bytepos == BEGV_BYTE 3092 w->start_at_line_beg = (pos.bytepos == BEGV_BYTE
2964 || FETCH_BYTE (pos.bytepos - 1) == '\n'); 3093 || FETCH_BYTE (pos.bytepos - 1) == '\n');
2965 /* We need to do this, so that the window-scroll-functions 3094 /* We need to do this, so that the window-scroll-functions
2966 get called. */ 3095 get called. */
2967 w->optional_new_start = 1; 3096 w->optional_new_start = true;
2968 3097
2969 set_buffer_internal (obuf); 3098 set_buffer_internal (obuf);
2970 } 3099 }
2971 } 3100 }
2972 3101
2973 adjust_glyphs (f); 3102 adjust_frame_glyphs (f);
2974 unblock_input (); 3103 unblock_input ();
2975 3104
2976 run_window_configuration_change_hook (f); 3105 run_window_configuration_change_hook (f);
@@ -2999,66 +3128,9 @@ replace_buffer_in_windows_safely (Lisp_Object buffer)
2999 considers frames on the current keyboard. So loop manually over 3128 considers frames on the current keyboard. So loop manually over
3000 frames, and handle each one. */ 3129 frames, and handle each one. */
3001 FOR_EACH_FRAME (tail, frame) 3130 FOR_EACH_FRAME (tail, frame)
3002 window_loop (REPLACE_BUFFER_IN_WINDOWS_SAFELY, buffer, 1, frame); 3131 window_loop (REPLACE_BUFFER_IN_WINDOWS_SAFELY, buffer, true, frame);
3003 } 3132 }
3004} 3133}
3005
3006/* If *ROWS or *COLS are too small a size for FRAME, set them to the
3007 minimum allowable size. */
3008
3009void
3010check_frame_size (struct frame *frame, int *rows, int *cols)
3011{
3012 /* For height, we have to see:
3013 how many windows the frame has at minimum (one or two),
3014 and whether it has a menu bar or other special stuff at the top. */
3015 int min_height
3016 = ((FRAME_MINIBUF_ONLY_P (frame) || ! FRAME_HAS_MINIBUF_P (frame))
3017 ? MIN_SAFE_WINDOW_HEIGHT
3018 : 2 * MIN_SAFE_WINDOW_HEIGHT);
3019
3020 if (FRAME_TOP_MARGIN (frame) > 0)
3021 min_height += FRAME_TOP_MARGIN (frame);
3022
3023 if (*rows < min_height)
3024 *rows = min_height;
3025 if (*cols < MIN_SAFE_WINDOW_WIDTH)
3026 *cols = MIN_SAFE_WINDOW_WIDTH;
3027}
3028
3029/* Adjust the margins of window W if text area is too small.
3030 Return 1 if window width is ok after adjustment; 0 if window
3031 is still too narrow. */
3032
3033static int
3034adjust_window_margins (struct window *w)
3035{
3036 int box_cols = (WINDOW_TOTAL_COLS (w)
3037 - WINDOW_FRINGE_COLS (w)
3038 - WINDOW_SCROLL_BAR_COLS (w));
3039 int margin_cols = (WINDOW_LEFT_MARGIN_COLS (w)
3040 + WINDOW_RIGHT_MARGIN_COLS (w));
3041
3042 if (box_cols - margin_cols >= MIN_SAFE_WINDOW_WIDTH)
3043 return 1;
3044
3045 if (margin_cols < 0 || box_cols < MIN_SAFE_WINDOW_WIDTH)
3046 return 0;
3047
3048 /* Window's text area is too narrow, but reducing the window
3049 margins will fix that. */
3050 margin_cols = box_cols - MIN_SAFE_WINDOW_WIDTH;
3051 if (WINDOW_RIGHT_MARGIN_COLS (w) > 0)
3052 {
3053 if (WINDOW_LEFT_MARGIN_COLS (w) > 0)
3054 w->left_margin_cols = w->right_margin_cols = margin_cols / 2;
3055 else
3056 w->right_margin_cols = margin_cols;
3057 }
3058 else
3059 w->left_margin_cols = margin_cols;
3060 return 1;
3061}
3062 3134
3063/* The following three routines are needed for running a window's 3135/* The following three routines are needed for running a window's
3064 configuration change hook. */ 3136 configuration change hook. */
@@ -3092,7 +3164,9 @@ run_window_configuration_change_hook (struct frame *f)
3092 = Fdefault_value (Qwindow_configuration_change_hook); 3164 = Fdefault_value (Qwindow_configuration_change_hook);
3093 XSETFRAME (frame, f); 3165 XSETFRAME (frame, f);
3094 3166
3095 if (NILP (Vrun_hooks) || !NILP (inhibit_lisp_code)) 3167 if (NILP (Vrun_hooks)
3168 || !(f->can_x_set_window_size)
3169 || !(f->after_make_frame))
3096 return; 3170 return;
3097 3171
3098 /* Use the right buffer. Matters when running the local hooks. */ 3172 /* Use the right buffer. Matters when running the local hooks. */
@@ -3142,11 +3216,23 @@ If FRAME is omitted or nil, it defaults to the selected frame. */)
3142 return Qnil; 3216 return Qnil;
3143} 3217}
3144 3218
3145/* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero 3219DEFUN ("run-window-scroll-functions", Frun_window_scroll_functions,
3146 means it's allowed to run hooks. See make_frame for a case where 3220 Srun_window_scroll_functions, 0, 1, 0,
3147 it's not allowed. KEEP_MARGINS_P non-zero means that the current 3221 doc: /* Run `window-scroll-functions' for WINDOW.
3148 margins, fringes, and scroll-bar settings of the window are not 3222If WINDOW is omitted or nil, it defaults to the selected window. */)
3149 reset from the buffer's local settings. */ 3223 (Lisp_Object window)
3224{
3225 if (! NILP (Vwindow_scroll_functions))
3226 run_hook_with_args_2 (Qwindow_scroll_functions, window,
3227 Fmarker_position (decode_live_window (window)->start));
3228 return Qnil;
3229}
3230
3231/* Make WINDOW display BUFFER. RUN_HOOKS_P means it's allowed
3232 to run hooks. See make_frame for a case where it's not allowed.
3233 KEEP_MARGINS_P means that the current margins, fringes, and
3234 scroll-bar settings of the window are not reset from the buffer's
3235 local settings. */
3150 3236
3151void 3237void
3152set_window_buffer (Lisp_Object window, Lisp_Object buffer, 3238set_window_buffer (Lisp_Object window, Lisp_Object buffer,
@@ -3155,7 +3241,7 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
3155 struct window *w = XWINDOW (window); 3241 struct window *w = XWINDOW (window);
3156 struct buffer *b = XBUFFER (buffer); 3242 struct buffer *b = XBUFFER (buffer);
3157 ptrdiff_t count = SPECPDL_INDEX (); 3243 ptrdiff_t count = SPECPDL_INDEX ();
3158 int samebuf = EQ (buffer, w->contents); 3244 bool samebuf = EQ (buffer, w->contents);
3159 3245
3160 wset_buffer (w, buffer); 3246 wset_buffer (w, buffer);
3161 3247
@@ -3172,40 +3258,43 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
3172 3258
3173 w->window_end_pos = 0; 3259 w->window_end_pos = 0;
3174 w->window_end_vpos = 0; 3260 w->window_end_vpos = 0;
3175 memset (&w->last_cursor, 0, sizeof w->last_cursor); 3261 w->last_cursor_vpos = 0;
3176 3262
3177 if (!(keep_margins_p && samebuf)) 3263 if (!(keep_margins_p && samebuf))
3178 { /* If we're not actually changing the buffer, don't reset hscroll and 3264 { /* If we're not actually changing the buffer, don't reset hscroll
3179 vscroll. This case happens for example when called from 3265 and vscroll. This case happens for example when called from
3180 change_frame_size_1, where we use a dummy call to 3266 change_frame_size_1, where we use a dummy call to
3181 Fset_window_buffer on the frame's selected window (and no other) 3267 Fset_window_buffer on the frame's selected window (and no
3182 just in order to run window-configuration-change-hook. 3268 other) just in order to run window-configuration-change-hook
3183 Resetting hscroll and vscroll here is problematic for things like 3269 (no longer true since change_frame_size_1 directly calls
3184 image-mode and doc-view-mode since it resets the image's position 3270 run_window_configuration_change_hook). Resetting hscroll and
3185 whenever we resize the frame. */ 3271 vscroll here is problematic for things like image-mode and
3186 w->hscroll = w->min_hscroll = 0; 3272 doc-view-mode since it resets the image's position whenever we
3273 resize the frame. */
3274 w->hscroll = w->min_hscroll = w->hscroll_whole = 0;
3275 w->suspend_auto_hscroll = false;
3187 w->vscroll = 0; 3276 w->vscroll = 0;
3188 set_marker_both (w->pointm, buffer, BUF_PT (b), BUF_PT_BYTE (b)); 3277 set_marker_both (w->pointm, buffer, BUF_PT (b), BUF_PT_BYTE (b));
3278 set_marker_both (w->old_pointm, buffer, BUF_PT (b), BUF_PT_BYTE (b));
3189 set_marker_restricted (w->start, 3279 set_marker_restricted (w->start,
3190 make_number (b->last_window_start), 3280 make_number (b->last_window_start),
3191 buffer); 3281 buffer);
3192 w->start_at_line_beg = 0; 3282 w->start_at_line_beg = false;
3193 w->force_start = 0; 3283 w->force_start = false;
3194 } 3284 }
3195 /* Maybe we could move this into the `if' but it's not obviously safe and 3285 /* Maybe we could move this into the `if' but it's not obviously safe and
3196 I doubt it's worth the trouble. */ 3286 I doubt it's worth the trouble. */
3197 windows_or_buffers_changed++; 3287 wset_redisplay (w);
3198 3288
3199 /* We must select BUFFER for running the window-scroll-functions. */ 3289 wset_update_mode_line (w);
3200 /* We can't check ! NILP (Vwindow_scroll_functions) here 3290
3201 because that might itself be a local variable. */ 3291 /* We must select BUFFER to run the window-scroll-functions and to look up
3202 if (window_initialized) 3292 the buffer-local value of Vwindow_point_insertion_type. */
3203 { 3293 record_unwind_current_buffer ();
3204 record_unwind_current_buffer (); 3294 Fset_buffer (buffer);
3205 Fset_buffer (buffer);
3206 }
3207 3295
3208 XMARKER (w->pointm)->insertion_type = !NILP (Vwindow_point_insertion_type); 3296 XMARKER (w->pointm)->insertion_type = !NILP (Vwindow_point_insertion_type);
3297 XMARKER (w->old_pointm)->insertion_type = !NILP (Vwindow_point_insertion_type);
3209 3298
3210 if (!keep_margins_p) 3299 if (!keep_margins_p)
3211 { 3300 {
@@ -3214,7 +3303,9 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
3214 BVAR (b, right_fringe_width), 3303 BVAR (b, right_fringe_width),
3215 BVAR (b, fringes_outside_margins)); 3304 BVAR (b, fringes_outside_margins));
3216 set_window_scroll_bars (w, BVAR (b, scroll_bar_width), 3305 set_window_scroll_bars (w, BVAR (b, scroll_bar_width),
3217 BVAR (b, vertical_scroll_bar_type), Qnil); 3306 BVAR (b, vertical_scroll_bar_type),
3307 BVAR (b, scroll_bar_height),
3308 BVAR (b, horizontal_scroll_bar_type));
3218 set_window_margins (w, BVAR (b, left_margin_cols), 3309 set_window_margins (w, BVAR (b, left_margin_cols),
3219 BVAR (b, right_margin_cols)); 3310 BVAR (b, right_margin_cols));
3220 apply_window_adjustment (w); 3311 apply_window_adjustment (w);
@@ -3225,14 +3316,15 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
3225 if (! NILP (Vwindow_scroll_functions)) 3316 if (! NILP (Vwindow_scroll_functions))
3226 run_hook_with_args_2 (Qwindow_scroll_functions, window, 3317 run_hook_with_args_2 (Qwindow_scroll_functions, window,
3227 Fmarker_position (w->start)); 3318 Fmarker_position (w->start));
3228 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w))); 3319 if (!samebuf)
3320 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w)));
3229 } 3321 }
3230 3322
3231 unbind_to (count, Qnil); 3323 unbind_to (count, Qnil);
3232} 3324}
3233 3325
3234DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 3, 0, 3326DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 3, 0,
3235 doc: /* Make WINDOW display BUFFER-OR-NAME as its contents. 3327 doc: /* Make WINDOW display BUFFER-OR-NAME.
3236WINDOW must be a live window and defaults to the selected one. 3328WINDOW must be a live window and defaults to the selected one.
3237BUFFER-OR-NAME must be a buffer or the name of an existing buffer. 3329BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
3238 3330
@@ -3280,7 +3372,7 @@ This function runs `window-scroll-functions' before running
3280 unshow_buffer (w); 3372 unshow_buffer (w);
3281 } 3373 }
3282 3374
3283 set_window_buffer (window, buffer, 1, !NILP (keep_margins)); 3375 set_window_buffer (window, buffer, true, !NILP (keep_margins));
3284 3376
3285 return Qnil; 3377 return Qnil;
3286} 3378}
@@ -3301,19 +3393,19 @@ displaying that buffer. */)
3301{ 3393{
3302 if (NILP (object)) 3394 if (NILP (object))
3303 { 3395 {
3304 windows_or_buffers_changed++; 3396 windows_or_buffers_changed = 29;
3305 update_mode_lines++; 3397 update_mode_lines = 28;
3306 return Qt; 3398 return Qt;
3307 } 3399 }
3308 3400
3309 if (WINDOWP (object)) 3401 if (WINDOWP (object))
3310 { 3402 {
3311 struct window *w = XWINDOW (object); 3403 struct window *w = XWINDOW (object);
3312 mark_window_display_accurate (object, 0); 3404 mark_window_display_accurate (object, false);
3313 w->update_mode_line = 1; 3405 w->update_mode_line = true;
3314 if (BUFFERP (w->contents)) 3406 if (BUFFERP (w->contents))
3315 XBUFFER (w->contents)->prevent_redisplay_optimizations_p = 1; 3407 XBUFFER (w->contents)->prevent_redisplay_optimizations_p = true;
3316 ++update_mode_lines; 3408 update_mode_lines = 29;
3317 return Qt; 3409 return Qt;
3318 } 3410 }
3319 3411
@@ -3324,7 +3416,7 @@ displaying that buffer. */)
3324 { 3416 {
3325 /* If buffer is live and shown in at least one window, find 3417 /* If buffer is live and shown in at least one window, find
3326 all windows showing this buffer and force update of them. */ 3418 all windows showing this buffer and force update of them. */
3327 object = window_loop (REDISPLAY_BUFFER_WINDOWS, object, 0, Qvisible); 3419 object = window_loop (REDISPLAY_BUFFER_WINDOWS, object, false, Qvisible);
3328 return NILP (object) ? Qnil : Qt; 3420 return NILP (object) ? Qnil : Qt;
3329 } 3421 }
3330 3422
@@ -3353,18 +3445,17 @@ temp_output_buffer_show (register Lisp_Object buf)
3353 3445
3354 if (!NILP (Vtemp_buffer_show_function)) 3446 if (!NILP (Vtemp_buffer_show_function))
3355 call1 (Vtemp_buffer_show_function, buf); 3447 call1 (Vtemp_buffer_show_function, buf);
3356 else 3448 else if (WINDOW_LIVE_P (window = display_buffer (buf, Qnil, Qnil)))
3357 { 3449 {
3358 window = display_buffer (buf, Qnil, Qnil);
3359
3360 if (!EQ (XWINDOW (window)->frame, selected_frame)) 3450 if (!EQ (XWINDOW (window)->frame, selected_frame))
3361 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window))); 3451 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
3362 Vminibuf_scroll_window = window; 3452 Vminibuf_scroll_window = window;
3363 w = XWINDOW (window); 3453 w = XWINDOW (window);
3364 w->hscroll = 0; 3454 w->hscroll = w->min_hscroll = w->hscroll_whole = 0;
3365 w->min_hscroll = 0; 3455 w->suspend_auto_hscroll = false;
3366 set_marker_restricted_both (w->start, buf, BEG, BEG); 3456 set_marker_restricted_both (w->start, buf, BEG, BEG);
3367 set_marker_restricted_both (w->pointm, buf, BEG, BEG); 3457 set_marker_restricted_both (w->pointm, buf, BEG, BEG);
3458 set_marker_restricted_both (w->old_pointm, buf, BEG, BEG);
3368 3459
3369 /* Run temp-buffer-show-hook, with the chosen window selected 3460 /* Run temp-buffer-show-hook, with the chosen window selected
3370 and its buffer current. */ 3461 and its buffer current. */
@@ -3382,14 +3473,23 @@ temp_output_buffer_show (register Lisp_Object buf)
3382 record_unwind_protect (select_window_norecord, prev_window); 3473 record_unwind_protect (select_window_norecord, prev_window);
3383 Fselect_window (window, Qt); 3474 Fselect_window (window, Qt);
3384 Fset_buffer (w->contents); 3475 Fset_buffer (w->contents);
3385 Frun_hooks (1, &Qtemp_buffer_show_hook); 3476 run_hook (Qtemp_buffer_show_hook);
3386 unbind_to (count, Qnil); 3477 unbind_to (count, Qnil);
3387 } 3478 }
3388 } 3479 }
3389} 3480}
3390 3481
3482/* Allocate basically initialized window. */
3483
3484static struct window *
3485allocate_window (void)
3486{
3487 return ALLOCATE_ZEROED_PSEUDOVECTOR
3488 (struct window, current_matrix, PVEC_WINDOW);
3489}
3490
3391/* Make new window, have it replace WINDOW in window-tree, and make 3491/* Make new window, have it replace WINDOW in window-tree, and make
3392 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only 3492 WINDOW its only vertical child (HORFLAG means make WINDOW its only
3393 horizontal child). */ 3493 horizontal child). */
3394static void 3494static void
3395make_parent_window (Lisp_Object window, bool horflag) 3495make_parent_window (Lisp_Object window, bool horflag)
@@ -3406,7 +3506,9 @@ make_parent_window (Lisp_Object window, bool horflag)
3406 adjust_window_count (p, 1); 3506 adjust_window_count (p, 1);
3407 XSETWINDOW (parent, p); 3507 XSETWINDOW (parent, p);
3408 3508
3409 replace_window (window, parent, 1); 3509 p->sequence_number = ++sequence_number;
3510
3511 replace_window (window, parent, true);
3410 3512
3411 wset_next (o, Qnil); 3513 wset_next (o, Qnil);
3412 wset_prev (o, Qnil); 3514 wset_prev (o, Qnil);
@@ -3414,6 +3516,7 @@ make_parent_window (Lisp_Object window, bool horflag)
3414 /* ...but now P becomes an internal window. */ 3516 /* ...but now P becomes an internal window. */
3415 wset_start (p, Qnil); 3517 wset_start (p, Qnil);
3416 wset_pointm (p, Qnil); 3518 wset_pointm (p, Qnil);
3519 wset_old_pointm (p, Qnil);
3417 wset_buffer (p, Qnil); 3520 wset_buffer (p, Qnil);
3418 wset_combination (p, horflag, window); 3521 wset_combination (p, horflag, window);
3419 wset_combination_limit (p, Qnil); 3522 wset_combination_limit (p, Qnil);
@@ -3434,9 +3537,12 @@ make_window (void)
3434 wset_normal_cols (w, make_float (1.0)); 3537 wset_normal_cols (w, make_float (1.0));
3435 wset_new_total (w, make_number (0)); 3538 wset_new_total (w, make_number (0));
3436 wset_new_normal (w, make_number (0)); 3539 wset_new_normal (w, make_number (0));
3540 wset_new_pixel (w, make_number (0));
3437 wset_start (w, Fmake_marker ()); 3541 wset_start (w, Fmake_marker ());
3438 wset_pointm (w, Fmake_marker ()); 3542 wset_pointm (w, Fmake_marker ());
3543 wset_old_pointm (w, Fmake_marker ());
3439 wset_vertical_scroll_bar_type (w, Qt); 3544 wset_vertical_scroll_bar_type (w, Qt);
3545 wset_horizontal_scroll_bar_type (w, Qt);
3440 /* These Lisp fields are marked specially so they're not set to nil by 3546 /* These Lisp fields are marked specially so they're not set to nil by
3441 allocate_window. */ 3547 allocate_window. */
3442 wset_prev_buffers (w, Qnil); 3548 wset_prev_buffers (w, Qnil);
@@ -3446,11 +3552,15 @@ make_window (void)
3446 non-Lisp data, so do it only for slots which should not be zero. */ 3552 non-Lisp data, so do it only for slots which should not be zero. */
3447 w->nrows_scale_factor = w->ncols_scale_factor = 1; 3553 w->nrows_scale_factor = w->ncols_scale_factor = 1;
3448 w->left_fringe_width = w->right_fringe_width = -1; 3554 w->left_fringe_width = w->right_fringe_width = -1;
3449 w->phys_cursor_type = -1; 3555 w->mode_line_height = w->header_line_height = -1;
3556#ifdef HAVE_WINDOW_SYSTEM
3557 w->phys_cursor_type = NO_CURSOR;
3450 w->phys_cursor_width = -1; 3558 w->phys_cursor_width = -1;
3559#endif
3560 w->sequence_number = ++sequence_number;
3451 w->scroll_bar_width = -1; 3561 w->scroll_bar_width = -1;
3562 w->scroll_bar_height = -1;
3452 w->column_number_displayed = -1; 3563 w->column_number_displayed = -1;
3453
3454 /* Reset window_list. */ 3564 /* Reset window_list. */
3455 Vwindow_list = Qnil; 3565 Vwindow_list = Qnil;
3456 /* Return window. */ 3566 /* Return window. */
@@ -3458,6 +3568,34 @@ make_window (void)
3458 return window; 3568 return window;
3459} 3569}
3460 3570
3571DEFUN ("set-window-new-pixel", Fset_window_new_pixel, Sset_window_new_pixel, 2, 3, 0,
3572 doc: /* Set new pixel size of WINDOW to SIZE.
3573WINDOW must be a valid window and defaults to the selected one.
3574Return SIZE.
3575
3576Optional argument ADD non-nil means add SIZE to the new pixel size of
3577WINDOW and return the sum.
3578
3579The new pixel size of WINDOW, if valid, will be shortly installed as
3580WINDOW's pixel height (see `window-pixel-height') or pixel width (see
3581`window-pixel-width').
3582
3583Note: This function does not operate on any child windows of WINDOW. */)
3584 (Lisp_Object window, Lisp_Object size, Lisp_Object add)
3585{
3586 struct window *w = decode_valid_window (window);
3587 EMACS_INT size_min = NILP (add) ? 0 : - XINT (w->new_pixel);
3588 EMACS_INT size_max = size_min + min (INT_MAX, MOST_POSITIVE_FIXNUM);
3589
3590 CHECK_RANGED_INTEGER (size, size_min, size_max);
3591 if (NILP (add))
3592 wset_new_pixel (w, size);
3593 else
3594 wset_new_pixel (w, make_number (XINT (w->new_pixel) + XINT (size)));
3595
3596 return w->new_pixel;
3597}
3598
3461DEFUN ("set-window-new-total", Fset_window_new_total, Sset_window_new_total, 2, 3, 0, 3599DEFUN ("set-window-new-total", Fset_window_new_total, Sset_window_new_total, 2, 3, 0,
3462 doc: /* Set new total size of WINDOW to SIZE. 3600 doc: /* Set new total size of WINDOW to SIZE.
3463WINDOW must be a valid window and defaults to the selected one. 3601WINDOW must be a valid window and defaults to the selected one.
@@ -3466,6 +3604,10 @@ Return SIZE.
3466Optional argument ADD non-nil means add SIZE to the new total size of 3604Optional argument ADD non-nil means add SIZE to the new total size of
3467WINDOW and return the sum. 3605WINDOW and return the sum.
3468 3606
3607The new total size of WINDOW, if valid, will be shortly installed as
3608WINDOW's total height (see `window-total-height') or total width (see
3609`window-total-width').
3610
3469Note: This function does not operate on any child windows of WINDOW. */) 3611Note: This function does not operate on any child windows of WINDOW. */)
3470 (Lisp_Object window, Lisp_Object size, Lisp_Object add) 3612 (Lisp_Object window, Lisp_Object size, Lisp_Object add)
3471{ 3613{
@@ -3485,6 +3627,9 @@ DEFUN ("set-window-new-normal", Fset_window_new_normal, Sset_window_new_normal,
3485WINDOW must be a valid window and defaults to the selected one. 3627WINDOW must be a valid window and defaults to the selected one.
3486Return SIZE. 3628Return SIZE.
3487 3629
3630The new normal size of WINDOW, if valid, will be shortly installed as
3631WINDOW's normal size (see `window-normal-size').
3632
3488Note: This function does not operate on any child windows of WINDOW. */) 3633Note: This function does not operate on any child windows of WINDOW. */)
3489 (Lisp_Object window, Lisp_Object size) 3634 (Lisp_Object window, Lisp_Object size)
3490{ 3635{
@@ -3492,16 +3637,17 @@ Note: This function does not operate on any child windows of WINDOW. */)
3492 return size; 3637 return size;
3493} 3638}
3494 3639
3495/* Return 1 if setting w->total_lines (w->total_cols if HORFLAG is 3640/* Return true if setting w->pixel_height (w->pixel_width if HORFLAG)
3496 non-zero) to w->new_total would result in correct heights (widths) 3641 to w->new_pixel would result in correct heights (widths)
3497 for window W and recursively all child windows of W. 3642 for window W and recursively all child windows of W.
3498 3643
3499 Note: This function does not check any of `window-fixed-size-p', 3644 Note: This function does not check any of `window-fixed-size-p',
3500 `window-min-height' or `window-min-width'. It does check that window 3645 `window-min-height' or `window-min-width'. It does check that window
3501 sizes do not drop below one line (two columns). */ 3646 sizes do not drop below one line (two columns). */
3502static int 3647static bool
3503window_resize_check (struct window *w, bool horflag) 3648window_resize_check (struct window *w, bool horflag)
3504{ 3649{
3650 struct frame *f = XFRAME (w->frame);
3505 struct window *c; 3651 struct window *c;
3506 3652
3507 if (WINDOW_VERTICAL_COMBINATION_P (w)) 3653 if (WINDOW_VERTICAL_COMBINATION_P (w))
@@ -3513,26 +3659,33 @@ window_resize_check (struct window *w, bool horflag)
3513 { 3659 {
3514 while (c) 3660 while (c)
3515 { 3661 {
3516 if ((XINT (c->new_total) != XINT (w->new_total)) 3662 if (XINT (c->new_pixel) != XINT (w->new_pixel)
3517 || !window_resize_check (c, horflag)) 3663 || !window_resize_check (c, horflag))
3518 return 0; 3664 return false;
3665
3519 c = NILP (c->next) ? 0 : XWINDOW (c->next); 3666 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3520 } 3667 }
3521 return 1; 3668
3669 return true;
3522 } 3670 }
3523 else 3671 else
3524 /* The sum of the heights of the child windows of W must equal 3672 /* The sum of the heights of the child windows of W must equal
3525 W's height. */ 3673 W's height. */
3526 { 3674 {
3527 int sum_of_sizes = 0; 3675 int remaining_pixels = XINT (w->new_pixel);
3676
3528 while (c) 3677 while (c)
3529 { 3678 {
3530 if (!window_resize_check (c, horflag)) 3679 if (!window_resize_check (c, horflag))
3531 return 0; 3680 return false;
3532 sum_of_sizes = sum_of_sizes + XINT (c->new_total); 3681
3682 remaining_pixels -= XINT (c->new_pixel);
3683 if (remaining_pixels < 0)
3684 return false;
3533 c = NILP (c->next) ? 0 : XWINDOW (c->next); 3685 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3534 } 3686 }
3535 return (sum_of_sizes == XINT (w->new_total)); 3687
3688 return remaining_pixels == 0;
3536 } 3689 }
3537 } 3690 }
3538 else if (WINDOW_HORIZONTAL_COMBINATION_P (w)) 3691 else if (WINDOW_HORIZONTAL_COMBINATION_P (w))
@@ -3543,39 +3696,49 @@ window_resize_check (struct window *w, bool horflag)
3543 /* The sum of the widths of the child windows of W must equal W's 3696 /* The sum of the widths of the child windows of W must equal W's
3544 width. */ 3697 width. */
3545 { 3698 {
3546 int sum_of_sizes = 0; 3699 int remaining_pixels = XINT (w->new_pixel);
3700
3547 while (c) 3701 while (c)
3548 { 3702 {
3549 if (!window_resize_check (c, horflag)) 3703 if (!window_resize_check (c, horflag))
3550 return 0; 3704 return false;
3551 sum_of_sizes = sum_of_sizes + XINT (c->new_total); 3705
3706 remaining_pixels -= XINT (c->new_pixel);
3707 if (remaining_pixels < 0)
3708 return false;
3552 c = NILP (c->next) ? 0 : XWINDOW (c->next); 3709 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3553 } 3710 }
3554 return (sum_of_sizes == XINT (w->new_total)); 3711
3712 return remaining_pixels == 0;
3555 } 3713 }
3556 else 3714 else
3557 /* All child windows of W must have the same height as W. */ 3715 /* All child windows of W must have the same height as W. */
3558 { 3716 {
3559 while (c) 3717 while (c)
3560 { 3718 {
3561 if ((XINT (c->new_total) != XINT (w->new_total)) 3719 if (XINT (c->new_pixel) != XINT (w->new_pixel)
3562 || !window_resize_check (c, horflag)) 3720 || !window_resize_check (c, horflag))
3563 return 0; 3721 return false;
3722
3564 c = NILP (c->next) ? 0 : XWINDOW (c->next); 3723 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3565 } 3724 }
3566 return 1; 3725
3726 return true;
3567 } 3727 }
3568 } 3728 }
3569 else 3729 else
3570 /* A leaf window. Make sure it's not too small. The following 3730 /* A leaf window. Make sure it's not too small. The following
3571 hardcodes the values of `window-safe-min-width' (2) and 3731 hardcodes the values of `window-safe-min-width' (2) and
3572 `window-safe-min-height' (1) which are defined in window.el. */ 3732 `window-safe-min-height' (1) which are defined in window.el. */
3573 return XINT (w->new_total) >= (horflag ? 2 : 1); 3733 return (XINT (w->new_pixel) >= (horflag
3734 ? (2 * FRAME_COLUMN_WIDTH (f))
3735 : FRAME_LINE_HEIGHT (f)));
3574} 3736}
3575 3737
3576/* Set w->total_lines (w->total_cols if HORIZONTAL is non-zero) to 3738
3577 w->new_total for window W and recursively all child windows of W. 3739/* Set w->pixel_height (w->pixel_width if HORFLAG) to
3578 Also calculate and assign the new vertical (horizontal) start 3740 w->new_pixel for window W and recursively all child windows of W.
3741 Also calculate and assign the new vertical (horizontal) pixel start
3579 positions of each of these windows. 3742 positions of each of these windows.
3580 3743
3581 This function does not perform any error checks. Make sure you have 3744 This function does not perform any error checks. Make sure you have
@@ -3584,25 +3747,30 @@ static void
3584window_resize_apply (struct window *w, bool horflag) 3747window_resize_apply (struct window *w, bool horflag)
3585{ 3748{
3586 struct window *c; 3749 struct window *c;
3587 int pos; 3750 int edge;
3751 int unit = (horflag
3752 ? FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w))
3753 : FRAME_LINE_HEIGHT (WINDOW_XFRAME (w)));
3588 3754
3589 /* Note: Assigning new_normal requires that the new total size of the 3755 /* Note: Assigning new_normal requires that the new total size of the
3590 parent window has been set *before*. */ 3756 parent window has been set *before*. */
3591 if (horflag) 3757 if (horflag)
3592 { 3758 {
3593 w->total_cols = XFASTINT (w->new_total); 3759 w->pixel_width = XFASTINT (w->new_pixel);
3760 w->total_cols = w->pixel_width / unit;
3594 if (NUMBERP (w->new_normal)) 3761 if (NUMBERP (w->new_normal))
3595 wset_normal_cols (w, w->new_normal); 3762 wset_normal_cols (w, w->new_normal);
3596 3763
3597 pos = w->left_col; 3764 edge = w->pixel_left;
3598 } 3765 }
3599 else 3766 else
3600 { 3767 {
3601 w->total_lines = XFASTINT (w->new_total); 3768 w->pixel_height = XFASTINT (w->new_pixel);
3769 w->total_lines = w->pixel_height / unit;
3602 if (NUMBERP (w->new_normal)) 3770 if (NUMBERP (w->new_normal))
3603 wset_normal_lines (w, w->new_normal); 3771 wset_normal_lines (w, w->new_normal);
3604 3772
3605 pos = w->top_line; 3773 edge = w->pixel_top;
3606 } 3774 }
3607 3775
3608 if (WINDOW_VERTICAL_COMBINATION_P (w)) 3776 if (WINDOW_VERTICAL_COMBINATION_P (w))
@@ -3612,12 +3780,19 @@ window_resize_apply (struct window *w, bool horflag)
3612 while (c) 3780 while (c)
3613 { 3781 {
3614 if (horflag) 3782 if (horflag)
3615 c->left_col = pos; 3783 {
3784 c->pixel_left = edge;
3785 c->left_col = edge / unit;
3786 }
3616 else 3787 else
3617 c->top_line = pos; 3788 {
3789 c->pixel_top = edge;
3790 c->top_line = edge / unit;
3791 }
3618 window_resize_apply (c, horflag); 3792 window_resize_apply (c, horflag);
3619 if (!horflag) 3793 if (!horflag)
3620 pos = pos + c->total_lines; 3794 edge = edge + c->pixel_height;
3795
3621 c = NILP (c->next) ? 0 : XWINDOW (c->next); 3796 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3622 } 3797 }
3623 } 3798 }
@@ -3628,18 +3803,90 @@ window_resize_apply (struct window *w, bool horflag)
3628 while (c) 3803 while (c)
3629 { 3804 {
3630 if (horflag) 3805 if (horflag)
3631 c->left_col = pos; 3806 {
3807 c->pixel_left = edge;
3808 c->left_col = edge / unit;
3809 }
3632 else 3810 else
3633 c->top_line = pos; 3811 {
3812 c->pixel_top = edge;
3813 c->top_line = edge / unit;
3814 }
3815
3634 window_resize_apply (c, horflag); 3816 window_resize_apply (c, horflag);
3635 if (horflag) 3817 if (horflag)
3636 pos = pos + c->total_cols; 3818 edge = edge + c->pixel_width;
3819
3637 c = NILP (c->next) ? 0 : XWINDOW (c->next); 3820 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3638 } 3821 }
3639 } 3822 }
3823 else
3824 /* Bug#15957. */
3825 w->window_end_valid = false;
3640} 3826}
3641 3827
3642 3828
3829/* Set w->total_lines (w->total_cols if HORFLAG) to
3830 w->new_total for window W and recursively all child windows of W.
3831 Also calculate and assign the new vertical (horizontal) start
3832 positions of each of these windows. */
3833static void
3834window_resize_apply_total (struct window *w, bool horflag)
3835{
3836 struct window *c;
3837 int edge;
3838
3839 /* Note: Assigning new_normal requires that the new total size of the
3840 parent window has been set *before*. */
3841 if (horflag)
3842 {
3843 w->total_cols = XFASTINT (w->new_total);
3844 edge = w->left_col;
3845 }
3846 else
3847 {
3848 w->total_lines = XFASTINT (w->new_total);
3849 edge = w->top_line;
3850 }
3851
3852 if (WINDOW_VERTICAL_COMBINATION_P (w))
3853 /* W is a vertical combination. */
3854 {
3855 c = XWINDOW (w->contents);
3856 while (c)
3857 {
3858 if (horflag)
3859 c->left_col = edge;
3860 else
3861 c->top_line = edge;
3862
3863 window_resize_apply_total (c, horflag);
3864 if (!horflag)
3865 edge = edge + c->total_lines;
3866
3867 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3868 }
3869 }
3870 else if (WINDOW_HORIZONTAL_COMBINATION_P (w))
3871 /* W is a horizontal combination. */
3872 {
3873 c = XWINDOW (w->contents);
3874 while (c)
3875 {
3876 if (horflag)
3877 c->left_col = edge;
3878 else
3879 c->top_line = edge;
3880
3881 window_resize_apply_total (c, horflag);
3882 if (horflag)
3883 edge = edge + c->total_cols;
3884
3885 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3886 }
3887 }
3888}
3889
3643DEFUN ("window-resize-apply", Fwindow_resize_apply, Swindow_resize_apply, 0, 2, 0, 3890DEFUN ("window-resize-apply", Fwindow_resize_apply, Swindow_resize_apply, 0, 2, 0,
3644 doc: /* Apply requested size values for window-tree of FRAME. 3891 doc: /* Apply requested size values for window-tree of FRAME.
3645If FRAME is omitted or nil, it defaults to the selected frame. 3892If FRAME is omitted or nil, it defaults to the selected frame.
@@ -3647,9 +3894,14 @@ If FRAME is omitted or nil, it defaults to the selected frame.
3647Optional argument HORIZONTAL omitted or nil means apply requested 3894Optional argument HORIZONTAL omitted or nil means apply requested
3648height values. HORIZONTAL non-nil means apply requested width values. 3895height values. HORIZONTAL non-nil means apply requested width values.
3649 3896
3650This function checks whether the requested values sum up to a valid 3897The requested size values are those set by `set-window-new-pixel' and
3651window layout, recursively assigns the new sizes of all child windows 3898`set-window-new-normal'. This function checks whether the requested
3652and calculates and assigns the new start positions of these windows. 3899values sum up to a valid window layout, recursively assigns the new
3900sizes of all child windows and calculates and assigns the new start
3901positions of these windows.
3902
3903Return t if the requested values have been applied correctly, nil
3904otherwise.
3653 3905
3654Note: This function does not check any of `window-fixed-size-p', 3906Note: This function does not check any of `window-fixed-size-p',
3655`window-min-height' or `window-min-width'. All these checks have to 3907`window-min-height' or `window-min-width'. All these checks have to
@@ -3661,80 +3913,170 @@ be applied on the Elisp level. */)
3661 bool horflag = !NILP (horizontal); 3913 bool horflag = !NILP (horizontal);
3662 3914
3663 if (!window_resize_check (r, horflag) 3915 if (!window_resize_check (r, horflag)
3664 || (XINT (r->new_total) 3916 || (XINT (r->new_pixel)
3665 != (horflag ? r->total_cols : r->total_lines))) 3917 != (horflag ? r->pixel_width : r->pixel_height)))
3666 return Qnil; 3918 return Qnil;
3667 3919
3668 block_input (); 3920 block_input ();
3669 window_resize_apply (r, horflag); 3921 window_resize_apply (r, horflag);
3670 3922
3671 windows_or_buffers_changed++; 3923 fset_redisplay (f);
3672 FRAME_WINDOW_SIZES_CHANGED (f) = 1; 3924 FRAME_WINDOW_SIZES_CHANGED (f) = true;
3673 3925
3674 adjust_glyphs (f); 3926 adjust_frame_glyphs (f);
3675 unblock_input (); 3927 unblock_input ();
3676 3928
3677 run_window_configuration_change_hook (f); 3929 return Qt;
3930}
3931
3932
3933DEFUN ("window-resize-apply-total", Fwindow_resize_apply_total, Swindow_resize_apply_total, 0, 2, 0,
3934 doc: /* Apply requested total size values for window-tree of FRAME.
3935If FRAME is omitted or nil, it defaults to the selected frame.
3936
3937This function does not assign pixel or normal size values. You should
3938have run `window-resize-apply' before running this.
3939
3940Optional argument HORIZONTAL omitted or nil means apply requested
3941height values. HORIZONTAL non-nil means apply requested width
3942values. */)
3943 (Lisp_Object frame, Lisp_Object horizontal)
3944{
3945 struct frame *f = decode_live_frame (frame);
3946 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
3947
3948 block_input ();
3949 /* Necessary when deleting the top-/or leftmost window. */
3950 r->left_col = 0;
3951 r->top_line = FRAME_TOP_MARGIN (f);
3952 window_resize_apply_total (r, !NILP (horizontal));
3953 /* Handle the mini window. */
3954 if (FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
3955 {
3956 struct window *m = XWINDOW (f->minibuffer_window);
3957
3958 if (NILP (horizontal))
3959 {
3960 m->top_line = r->top_line + r->total_lines;
3961 m->total_lines = XFASTINT (m->new_total);
3962 }
3963 else
3964 m->total_cols = XFASTINT (m->new_total);
3965 }
3966
3967 unblock_input ();
3678 3968
3679 return Qt; 3969 return Qt;
3680} 3970}
3681 3971
3682 3972
3683/* Resize frame F's windows when number of lines of F is set to SIZE. 3973/* Resize frame F's windows when number of lines of F is set to SIZE.
3684 HORFLAG 1 means resize windows when number of columns of F is set to 3974 HORFLAG means resize windows when number of columns of F is set to
3685 SIZE. 3975 SIZE. PIXELWISE means to interpret SIZE as pixels. */
3686
3687 This function can delete all windows but the selected one in order to
3688 satisfy the request. The result will be meaningful if and only if
3689 F's windows have meaningful sizes when you call this. */
3690void 3976void
3691resize_frame_windows (struct frame *f, int size, bool horflag) 3977resize_frame_windows (struct frame *f, int size, bool horflag, bool pixelwise)
3692{ 3978{
3693 Lisp_Object root = f->root_window; 3979 Lisp_Object root = f->root_window;
3694 struct window *r = XWINDOW (root); 3980 struct window *r = XWINDOW (root);
3695 Lisp_Object mini = f->minibuffer_window; 3981 Lisp_Object mini = f->minibuffer_window;
3696 struct window *m; 3982 struct window *m;
3983 /* old_size is the old size of the frame's root window. */
3984 int old_size = horflag ? r->total_cols : r->total_lines;
3985 int old_pixel_size = horflag ? r->pixel_width : r->pixel_height;
3697 /* new_size is the new size of the frame's root window. */ 3986 /* new_size is the new size of the frame's root window. */
3698 int new_size = (horflag 3987 int new_size, new_pixel_size;
3699 ? size 3988 int unit = horflag ? FRAME_COLUMN_WIDTH (f) : FRAME_LINE_HEIGHT (f);
3700 : (size
3701 - FRAME_TOP_MARGIN (f)
3702 - ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
3703 ? 1 : 0)));
3704 3989
3705 r->top_line = FRAME_TOP_MARGIN (f); 3990 /* Don't let the size drop below one unit. This is more comforting
3706 if (WINDOW_LEAF_P (r)) 3991 when we are called from x_set_tool_bar_lines since the latter may
3992 have implicitly given us a zero or negative height. */
3993 if (pixelwise)
3994 {
3995 /* Note: This does not include the size for internal borders
3996 since these are not part of the frame's text area. */
3997 new_pixel_size = max (horflag
3998 ? size
3999 : (size
4000 - ((FRAME_HAS_MINIBUF_P (f)
4001 && !FRAME_MINIBUF_ONLY_P (f))
4002 ? FRAME_LINE_HEIGHT (f) : 0)),
4003 unit);
4004 new_size = new_pixel_size / unit;
4005 }
4006 else
4007 {
4008 new_size = max (size - (!horflag
4009 && FRAME_HAS_MINIBUF_P (f)
4010 && !FRAME_MINIBUF_ONLY_P (f)),
4011 1);
4012 new_pixel_size = new_size * unit;
4013 }
4014
4015 if (new_pixel_size == old_pixel_size
4016 && (horflag || r->pixel_top == FRAME_TOP_MARGIN_HEIGHT (f)))
4017 ;
4018 else if (WINDOW_LEAF_P (r))
3707 /* For a leaf root window just set the size. */ 4019 /* For a leaf root window just set the size. */
3708 if (horflag) 4020 if (horflag)
3709 r->total_cols = new_size; 4021 {
4022 r->total_cols = new_size;
4023 r->pixel_width = new_pixel_size;
4024 }
3710 else 4025 else
3711 r->total_lines = new_size; 4026 {
4027 r->top_line = FRAME_TOP_MARGIN (f);
4028 r->pixel_top = FRAME_TOP_MARGIN_HEIGHT (f);
4029
4030 r->total_lines = new_size;
4031 r->pixel_height = new_pixel_size;
4032 }
3712 else 4033 else
3713 { 4034 {
3714 /* old_size is the old size of the frame's root window. */
3715 int old_size = horflag ? r->total_cols : r->total_lines;
3716 Lisp_Object delta; 4035 Lisp_Object delta;
3717 4036
3718 XSETINT (delta, new_size - old_size); 4037 if (!horflag)
4038 {
4039 r->top_line = FRAME_TOP_MARGIN (f);
4040 r->pixel_top = FRAME_TOP_MARGIN_HEIGHT (f);
4041 }
4042
4043 if (pixelwise)
4044 XSETINT (delta, new_pixel_size - old_pixel_size);
4045 else
4046 XSETINT (delta, new_size - old_size);
4047
3719 /* Try a "normal" resize first. */ 4048 /* Try a "normal" resize first. */
3720 resize_root_window (root, delta, horflag ? Qt : Qnil, Qnil); 4049 resize_root_window (root, delta, horflag ? Qt : Qnil, Qnil,
4050 pixelwise ? Qt : Qnil);
3721 if (window_resize_check (r, horflag) 4051 if (window_resize_check (r, horflag)
3722 && new_size == XINT (r->new_total)) 4052 && new_pixel_size == XINT (r->new_pixel))
3723 window_resize_apply (r, horflag); 4053 {
4054 window_resize_apply (r, horflag);
4055 window_pixel_to_total (r->frame, horflag ? Qt : Qnil);
4056 }
3724 else 4057 else
3725 { 4058 {
3726 /* Try with "reasonable" minimum sizes next. */ 4059 /* Try with "reasonable" minimum sizes next. */
3727 resize_root_window (root, delta, horflag ? Qt : Qnil, Qt); 4060 resize_root_window (root, delta, horflag ? Qt : Qnil, Qt,
4061 pixelwise ? Qt : Qnil);
3728 if (window_resize_check (r, horflag) 4062 if (window_resize_check (r, horflag)
3729 && new_size == XINT (r->new_total)) 4063 && new_pixel_size == XINT (r->new_pixel))
3730 window_resize_apply (r, horflag); 4064 {
4065 window_resize_apply (r, horflag);
4066 window_pixel_to_total (r->frame, horflag ? Qt : Qnil);
4067#if false /* Let's try without safe sizes and/or killing other windows. */
4068 }
3731 else 4069 else
3732 { 4070 {
3733 /* Finally, try with "safe" minimum sizes. */ 4071 /* Finally, try with "safe" minimum sizes. */
3734 resize_root_window (root, delta, horflag ? Qt : Qnil, Qsafe); 4072 resize_root_window (root, delta, horflag ? Qt : Qnil, Qsafe,
4073 pixelwise ? Qt : Qnil);
3735 if (window_resize_check (r, horflag) 4074 if (window_resize_check (r, horflag)
3736 && new_size == XINT (r->new_total)) 4075 && new_pixel_size == XINT (r->new_pixel))
3737 window_resize_apply (r, horflag); 4076 {
4077 window_resize_apply (r, horflag);
4078 window_pixel_to_total (r->frame, horflag ? Qt : Qnil);
4079 }
3738 else 4080 else
3739 { 4081 {
3740 /* We lost. Delete all windows but the frame's 4082 /* We lost. Delete all windows but the frame's
@@ -3742,10 +4084,17 @@ resize_frame_windows (struct frame *f, int size, bool horflag)
3742 root = f->selected_window; 4084 root = f->selected_window;
3743 Fdelete_other_windows_internal (root, Qnil); 4085 Fdelete_other_windows_internal (root, Qnil);
3744 if (horflag) 4086 if (horflag)
3745 XWINDOW (root)->total_cols = new_size; 4087 {
4088 XWINDOW (root)->total_cols = new_size;
4089 XWINDOW (root)->pixel_width = new_pixel_size;
4090 }
3746 else 4091 else
3747 XWINDOW (root)->total_lines = new_size; 4092 {
4093 XWINDOW (root)->total_lines = new_size;
4094 XWINDOW (root)->pixel_height = new_pixel_size;
4095 }
3748 } 4096 }
4097#endif /* false */
3749 } 4098 }
3750 } 4099 }
3751 } 4100 }
@@ -3754,42 +4103,47 @@ resize_frame_windows (struct frame *f, int size, bool horflag)
3754 { 4103 {
3755 m = XWINDOW (mini); 4104 m = XWINDOW (mini);
3756 if (horflag) 4105 if (horflag)
3757 m->total_cols = size; 4106 {
4107 m->total_cols = size;
4108 m->pixel_width = new_pixel_size;
4109 }
3758 else 4110 else
3759 { 4111 {
3760 /* Are we sure we always want 1 line here? */ 4112 /* Are we sure we always want 1 line here? */
3761 m->total_lines = 1; 4113 m->total_lines = 1;
4114 m->pixel_height = FRAME_LINE_HEIGHT (f);
3762 m->top_line = r->top_line + r->total_lines; 4115 m->top_line = r->top_line + r->total_lines;
4116 m->pixel_top = r->pixel_top + r->pixel_height;
3763 } 4117 }
3764 } 4118 }
3765 4119
3766 windows_or_buffers_changed++; 4120 fset_redisplay (f);
3767} 4121}
3768 4122
3769 4123
3770DEFUN ("split-window-internal", Fsplit_window_internal, Ssplit_window_internal, 4, 4, 0, 4124DEFUN ("split-window-internal", Fsplit_window_internal, Ssplit_window_internal, 4, 4, 0,
3771 doc: /* Split window OLD. 4125 doc: /* Split window OLD.
3772Second argument TOTAL-SIZE specifies the number of lines or columns of the 4126Second argument PIXEL-SIZE specifies the number of pixels of the
3773new window. In any case TOTAL-SIZE must be a positive integer. 4127new window. It must be a positive integer.
3774 4128
3775Third argument SIDE nil (or `below') specifies that the new window shall 4129Third argument SIDE nil (or `below') specifies that the new window shall
3776be located below WINDOW. SIDE `above' means the new window shall be 4130be located below WINDOW. SIDE `above' means the new window shall be
3777located above WINDOW. In both cases TOTAL-SIZE specifies the number of 4131located above WINDOW. In both cases PIXEL-SIZE specifies the pixel
3778lines of the new window including space reserved for the mode and/or 4132height of the new window including space reserved for the mode and/or
3779header line. 4133header line.
3780 4134
3781SIDE t (or `right') specifies that the new window shall be located on 4135SIDE t (or `right') specifies that the new window shall be located on
3782the right side of WINDOW. SIDE `left' means the new window shall be 4136the right side of WINDOW. SIDE `left' means the new window shall be
3783located on the left of WINDOW. In both cases TOTAL-SIZE specifies the 4137located on the left of WINDOW. In both cases PIXEL-SIZE specifies the
3784number of columns of the new window including space reserved for fringes 4138width of the new window including space reserved for fringes and the
3785and the scrollbar or a divider column. 4139scrollbar or a divider column.
3786 4140
3787Fourth argument NORMAL-SIZE specifies the normal size of the new window 4141Fourth argument NORMAL-SIZE specifies the normal size of the new window
3788according to the SIDE argument. 4142according to the SIDE argument.
3789 4143
3790The new total and normal sizes of all involved windows must have been 4144The new pixel and normal sizes of all involved windows must have been
3791set correctly. See the code of `split-window' for how this is done. */) 4145set correctly. See the code of `split-window' for how this is done. */)
3792 (Lisp_Object old, Lisp_Object total_size, Lisp_Object side, Lisp_Object normal_size) 4146 (Lisp_Object old, Lisp_Object pixel_size, Lisp_Object side, Lisp_Object normal_size)
3793{ 4147{
3794 /* OLD (*o) is the window we have to split. (*p) is either OLD's 4148 /* OLD (*o) is the window we have to split. (*p) is either OLD's
3795 parent window or an internal window we have to install as OLD's new 4149 parent window or an internal window we have to install as OLD's new
@@ -3797,30 +4151,33 @@ set correctly. See the code of `split-window' for how this is done. */)
3797 provided OLD is a leaf window, or to the frame's selected window. 4151 provided OLD is a leaf window, or to the frame's selected window.
3798 NEW (*n) is the new window created with some parameters taken from 4152 NEW (*n) is the new window created with some parameters taken from
3799 REFERENCE (*r). */ 4153 REFERENCE (*r). */
3800 register Lisp_Object new, frame, reference; 4154 Lisp_Object new, frame, reference;
3801 register struct window *o, *p, *n, *r; 4155 struct window *o, *p, *n, *r, *c;
3802 struct frame *f; 4156 struct frame *f;
3803 bool horflag 4157 bool horflag
3804 /* HORFLAG is 1 when we split side-by-side, 0 otherwise. */ 4158 /* HORFLAG is true when we split side-by-side, false otherwise. */
3805 = EQ (side, Qt) || EQ (side, Qleft) || EQ (side, Qright); 4159 = EQ (side, Qt) || EQ (side, Qleft) || EQ (side, Qright);
3806 int combination_limit = 0;
3807 4160
3808 CHECK_WINDOW (old); 4161 CHECK_WINDOW (old);
3809 o = XWINDOW (old); 4162 o = XWINDOW (old);
3810 frame = WINDOW_FRAME (o); 4163 frame = WINDOW_FRAME (o);
3811 f = XFRAME (frame); 4164 f = XFRAME (frame);
3812 4165
3813 CHECK_NUMBER (total_size); 4166 CHECK_NUMBER (pixel_size);
4167 EMACS_INT total_size
4168 = XINT (pixel_size) / (horflag
4169 ? FRAME_COLUMN_WIDTH (f)
4170 : FRAME_LINE_HEIGHT (f));
3814 4171
3815 /* Set combination_limit to 1 if we have to make a new parent window. 4172 /* Set combination_limit if we have to make a new parent window.
3816 We do that if either `window-combination-limit' is t, or OLD has no 4173 We do that if either `window-combination-limit' is t, or OLD has no
3817 parent, or OLD is ortho-combined. */ 4174 parent, or OLD is ortho-combined. */
3818 combination_limit = 4175 bool combination_limit
3819 EQ (Vwindow_combination_limit, Qt) 4176 = (EQ (Vwindow_combination_limit, Qt)
3820 || NILP (o->parent) 4177 || NILP (o->parent)
3821 || (horflag 4178 || (horflag
3822 ? WINDOW_VERTICAL_COMBINATION_P (XWINDOW (o->parent)) 4179 ? WINDOW_VERTICAL_COMBINATION_P (XWINDOW (o->parent))
3823 : WINDOW_HORIZONTAL_COMBINATION_P (XWINDOW (o->parent))); 4180 : WINDOW_HORIZONTAL_COMBINATION_P (XWINDOW (o->parent))));
3824 4181
3825 /* We need a live reference window to initialize some parameters. */ 4182 /* We need a live reference window to initialize some parameters. */
3826 if (WINDOW_LIVE_P (old)) 4183 if (WINDOW_LIVE_P (old))
@@ -3834,7 +4191,7 @@ set correctly. See the code of `split-window' for how this is done. */)
3834 /* The following bugs are caught by `split-window'. */ 4191 /* The following bugs are caught by `split-window'. */
3835 if (MINI_WINDOW_P (o)) 4192 if (MINI_WINDOW_P (o))
3836 error ("Attempt to split minibuffer window"); 4193 error ("Attempt to split minibuffer window");
3837 else if (XINT (total_size) < (horflag ? 2 : 1)) 4194 else if (total_size < (horflag ? 2 : 1))
3838 error ("Size of new window too small (after split)"); 4195 error ("Size of new window too small (after split)");
3839 else if (!combination_limit && !NILP (Vwindow_combination_resize)) 4196 else if (!combination_limit && !NILP (Vwindow_combination_resize))
3840 /* `window-combination-resize' non-nil means try to resize OLD's siblings 4197 /* `window-combination-resize' non-nil means try to resize OLD's siblings
@@ -3842,26 +4199,25 @@ set correctly. See the code of `split-window' for how this is done. */)
3842 { 4199 {
3843 p = XWINDOW (o->parent); 4200 p = XWINDOW (o->parent);
3844 /* Temporarily pretend we split the parent window. */ 4201 /* Temporarily pretend we split the parent window. */
3845 wset_new_total 4202 wset_new_pixel
3846 (p, make_number ((horflag ? p->total_cols : p->total_lines) 4203 (p, make_number ((horflag ? p->pixel_width : p->pixel_height)
3847 - XINT (total_size))); 4204 - XINT (pixel_size)));
3848 if (!window_resize_check (p, horflag)) 4205 if (!window_resize_check (p, horflag))
3849 error ("Window sizes don't fit"); 4206 error ("Window sizes don't fit");
3850 else 4207 else
3851 /* Undo the temporary pretension. */ 4208 /* Undo the temporary pretension. */
3852 wset_new_total (p, make_number 4209 wset_new_pixel (p, make_number (horflag ? p->pixel_width : p->pixel_height));
3853 (horflag ? p->total_cols : p->total_lines));
3854 } 4210 }
3855 else 4211 else
3856 { 4212 {
3857 if (!window_resize_check (o, horflag)) 4213 if (!window_resize_check (o, horflag))
3858 error ("Resizing old window failed"); 4214 error ("Resizing old window failed");
3859 else if (XINT (total_size) + XINT (o->new_total) 4215 else if (XINT (pixel_size) + XINT (o->new_pixel)
3860 != (horflag ? o->total_cols : o->total_lines)) 4216 != (horflag ? o->pixel_width : o->pixel_height))
3861 error ("Sum of sizes of old and new window don't fit"); 4217 error ("Sum of sizes of old and new window don't fit");
3862 } 4218 }
3863 4219
3864 /* This is our point of no return. */ 4220 /* This is our point of no return. */
3865 if (combination_limit) 4221 if (combination_limit)
3866 { 4222 {
3867 /* Save the old value of o->normal_cols/lines. It gets corrupted 4223 /* Save the old value of o->normal_cols/lines. It gets corrupted
@@ -3877,15 +4233,17 @@ set correctly. See the code of `split-window' for how this is done. */)
3877 that its children get merged into another window. */ 4233 that its children get merged into another window. */
3878 wset_combination_limit (p, Qt); 4234 wset_combination_limit (p, Qt);
3879 /* These get applied below. */ 4235 /* These get applied below. */
3880 wset_new_total (p, make_number 4236 wset_new_pixel
3881 (horflag ? o->total_cols : o->total_lines)); 4237 (p, make_number (horflag ? o->pixel_width : o->pixel_height));
4238 wset_new_total
4239 (p, make_number (horflag ? o->total_cols : o->total_lines));
3882 wset_new_normal (p, new_normal); 4240 wset_new_normal (p, new_normal);
3883 } 4241 }
3884 else 4242 else
3885 p = XWINDOW (o->parent); 4243 p = XWINDOW (o->parent);
3886 4244
3887 windows_or_buffers_changed++; 4245 fset_redisplay (f);
3888 FRAME_WINDOW_SIZES_CHANGED (f) = 1; 4246 FRAME_WINDOW_SIZES_CHANGED (f) = true;
3889 new = make_window (); 4247 new = make_window ();
3890 n = XWINDOW (new); 4248 n = XWINDOW (new);
3891 wset_frame (n, frame); 4249 wset_frame (n, frame);
@@ -3910,8 +4268,8 @@ set correctly. See the code of `split-window' for how this is done. */)
3910 wset_next (o, new); 4268 wset_next (o, new);
3911 } 4269 }
3912 4270
3913 n->window_end_valid = 0; 4271 n->window_end_valid = false;
3914 memset (&n->last_cursor, 0, sizeof n->last_cursor); 4272 n->last_cursor_vpos = 0;
3915 4273
3916 /* Get special geometry settings from reference window. */ 4274 /* Get special geometry settings from reference window. */
3917 n->left_margin_cols = r->left_margin_cols; 4275 n->left_margin_cols = r->left_margin_cols;
@@ -3920,31 +4278,49 @@ set correctly. See the code of `split-window' for how this is done. */)
3920 n->right_fringe_width = r->right_fringe_width; 4278 n->right_fringe_width = r->right_fringe_width;
3921 n->fringes_outside_margins = r->fringes_outside_margins; 4279 n->fringes_outside_margins = r->fringes_outside_margins;
3922 n->scroll_bar_width = r->scroll_bar_width; 4280 n->scroll_bar_width = r->scroll_bar_width;
4281 n->scroll_bar_height = r->scroll_bar_height;
3923 wset_vertical_scroll_bar_type (n, r->vertical_scroll_bar_type); 4282 wset_vertical_scroll_bar_type (n, r->vertical_scroll_bar_type);
4283 wset_horizontal_scroll_bar_type (n, r->horizontal_scroll_bar_type);
3924 4284
3925 /* Directly assign orthogonal coordinates and sizes. */ 4285 /* Directly assign orthogonal coordinates and sizes. */
3926 if (horflag) 4286 if (horflag)
3927 { 4287 {
4288 n->pixel_top = o->pixel_top;
3928 n->top_line = o->top_line; 4289 n->top_line = o->top_line;
4290 n->pixel_height = o->pixel_height;
3929 n->total_lines = o->total_lines; 4291 n->total_lines = o->total_lines;
3930 } 4292 }
3931 else 4293 else
3932 { 4294 {
4295 n->pixel_left = o->pixel_left;
3933 n->left_col = o->left_col; 4296 n->left_col = o->left_col;
4297 n->pixel_width = o->pixel_width;
3934 n->total_cols = o->total_cols; 4298 n->total_cols = o->total_cols;
3935 } 4299 }
3936 4300
3937 /* Iso-coordinates and sizes are assigned by window_resize_apply, 4301 /* Iso-coordinates and sizes are assigned by window_resize_apply,
3938 get them ready here. */ 4302 get them ready here. */
3939 wset_new_total (n, total_size); 4303 wset_new_pixel (n, pixel_size);
4304 EMACS_INT sum = 0;
4305 c = XWINDOW (p->contents);
4306 while (c)
4307 {
4308 if (c != n)
4309 sum = sum + XINT (c->new_total);
4310 c = NILP (c->next) ? 0 : XWINDOW (c->next);
4311 }
4312 wset_new_total (n, make_number ((horflag
4313 ? p->total_cols
4314 : p->total_lines)
4315 - sum));
3940 wset_new_normal (n, normal_size); 4316 wset_new_normal (n, normal_size);
3941 4317
3942 block_input (); 4318 block_input ();
3943 window_resize_apply (p, horflag); 4319 window_resize_apply (p, horflag);
3944 adjust_glyphs (f); 4320 adjust_frame_glyphs (f);
3945 /* Set buffer of NEW to buffer of reference window. Don't run 4321 /* Set buffer of NEW to buffer of reference window. Don't run
3946 any hooks. */ 4322 any hooks. */
3947 set_window_buffer (new, r->contents, 0, 1); 4323 set_window_buffer (new, r->contents, false, true);
3948 unblock_input (); 4324 unblock_input ();
3949 4325
3950 /* Maybe we should run the scroll functions in Elisp (which already 4326 /* Maybe we should run the scroll functions in Elisp (which already
@@ -3961,12 +4337,12 @@ DEFUN ("delete-window-internal", Fdelete_window_internal, Sdelete_window_interna
3961 doc: /* Remove WINDOW from its frame. 4337 doc: /* Remove WINDOW from its frame.
3962WINDOW defaults to the selected window. Return nil. 4338WINDOW defaults to the selected window. Return nil.
3963Signal an error when WINDOW is the only window on its frame. */) 4339Signal an error when WINDOW is the only window on its frame. */)
3964 (register Lisp_Object window) 4340 (Lisp_Object window)
3965{ 4341{
3966 register Lisp_Object parent, sibling, frame, root; 4342 Lisp_Object parent, sibling, frame, root;
3967 struct window *w, *p, *s, *r; 4343 struct window *w, *p, *s, *r;
3968 struct frame *f; 4344 struct frame *f;
3969 bool horflag, before_sibling = 0; 4345 bool horflag, before_sibling = false;
3970 4346
3971 w = decode_any_window (window); 4347 w = decode_any_window (window);
3972 XSETWINDOW (window, w); 4348 XSETWINDOW (window, w);
@@ -3996,9 +4372,9 @@ Signal an error when WINDOW is the only window on its frame. */)
3996 if (NILP (w->prev)) 4372 if (NILP (w->prev))
3997 /* Get SIBLING below (on the right of) WINDOW. */ 4373 /* Get SIBLING below (on the right of) WINDOW. */
3998 { 4374 {
3999 /* before_sibling 1 means WINDOW is the first child of its 4375 /* before_sibling means WINDOW is the first child of its
4000 parent and thus before the sibling. */ 4376 parent and thus before the sibling. */
4001 before_sibling = 1; 4377 before_sibling = true;
4002 sibling = w->next; 4378 sibling = w->next;
4003 s = XWINDOW (sibling); 4379 s = XWINDOW (sibling);
4004 wset_prev (s, Qnil); 4380 wset_prev (s, Qnil);
@@ -4015,15 +4391,14 @@ Signal an error when WINDOW is the only window on its frame. */)
4015 } 4391 }
4016 4392
4017 if (window_resize_check (r, horflag) 4393 if (window_resize_check (r, horflag)
4018 && (XINT (r->new_total) 4394 && (XINT (r->new_pixel)
4019 == (horflag ? r->total_cols : r->total_lines))) 4395 == (horflag ? r->pixel_width : r->pixel_height)))
4020 /* We can delete WINDOW now. */ 4396 /* We can delete WINDOW now. */
4021 { 4397 {
4022 4398
4023 /* Block input. */ 4399 /* Block input. */
4024 block_input (); 4400 block_input ();
4025 window_resize_apply (p, horflag); 4401 window_resize_apply (p, horflag);
4026
4027 /* If this window is referred to by the dpyinfo's mouse 4402 /* If this window is referred to by the dpyinfo's mouse
4028 highlight, invalidate that slot to be safe (Bug#9904). */ 4403 highlight, invalidate that slot to be safe (Bug#9904). */
4029 if (!FRAME_INITIAL_P (f)) 4404 if (!FRAME_INITIAL_P (f))
@@ -4034,9 +4409,9 @@ Signal an error when WINDOW is the only window on its frame. */)
4034 hlinfo->mouse_face_window = Qnil; 4409 hlinfo->mouse_face_window = Qnil;
4035 } 4410 }
4036 4411
4037 windows_or_buffers_changed++; 4412 fset_redisplay (f);
4038 Vwindow_list = Qnil; 4413 Vwindow_list = Qnil;
4039 FRAME_WINDOW_SIZES_CHANGED (f) = 1; 4414 FRAME_WINDOW_SIZES_CHANGED (f) = true;
4040 4415
4041 wset_next (w, Qnil); /* Don't delete w->next too. */ 4416 wset_next (w, Qnil); /* Don't delete w->next too. */
4042 free_window_matrices (w); 4417 free_window_matrices (w);
@@ -4044,12 +4419,13 @@ Signal an error when WINDOW is the only window on its frame. */)
4044 if (WINDOWP (w->contents)) 4419 if (WINDOWP (w->contents))
4045 { 4420 {
4046 delete_all_child_windows (w->contents); 4421 delete_all_child_windows (w->contents);
4047 wset_combination (w, 0, Qnil); 4422 wset_combination (w, false, Qnil);
4048 } 4423 }
4049 else 4424 else
4050 { 4425 {
4051 unshow_buffer (w); 4426 unshow_buffer (w);
4052 unchain_marker (XMARKER (w->pointm)); 4427 unchain_marker (XMARKER (w->pointm));
4428 unchain_marker (XMARKER (w->old_pointm));
4053 unchain_marker (XMARKER (w->start)); 4429 unchain_marker (XMARKER (w->start));
4054 wset_buffer (w, Qnil); 4430 wset_buffer (w, Qnil);
4055 } 4431 }
@@ -4059,18 +4435,18 @@ Signal an error when WINDOW is the only window on its frame. */)
4059 PARENT. */ 4435 PARENT. */
4060 { 4436 {
4061 /* Put SIBLING into PARENT's place. */ 4437 /* Put SIBLING into PARENT's place. */
4062 replace_window (parent, sibling, 0); 4438 replace_window (parent, sibling, false);
4063 /* Have SIBLING inherit the following three slot values from 4439 /* Have SIBLING inherit the following three slot values from
4064 PARENT (the combination_limit slot is not inherited). */ 4440 PARENT (the combination_limit slot is not inherited). */
4065 wset_normal_cols (s, p->normal_cols); 4441 wset_normal_cols (s, p->normal_cols);
4066 wset_normal_lines (s, p->normal_lines); 4442 wset_normal_lines (s, p->normal_lines);
4067 /* Mark PARENT as deleted. */ 4443 /* Mark PARENT as deleted. */
4068 wset_combination (p, 0, Qnil); 4444 wset_combination (p, false, Qnil);
4069 /* Try to merge SIBLING into its new parent. */ 4445 /* Try to merge SIBLING into its new parent. */
4070 recombine_windows (sibling); 4446 recombine_windows (sibling);
4071 } 4447 }
4072 4448
4073 adjust_glyphs (f); 4449 adjust_frame_glyphs (f);
4074 4450
4075 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f))) 4451 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f)))
4076 /* We deleted the frame's selected window. */ 4452 /* We deleted the frame's selected window. */
@@ -4134,64 +4510,91 @@ Signal an error when WINDOW is the only window on its frame. */)
4134/* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we 4510/* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we
4135 can. */ 4511 can. */
4136void 4512void
4137grow_mini_window (struct window *w, int delta) 4513grow_mini_window (struct window *w, int delta, bool pixelwise)
4138{ 4514{
4139 struct frame *f = XFRAME (w->frame); 4515 struct frame *f = XFRAME (w->frame);
4140 struct window *r; 4516 struct window *r;
4141 Lisp_Object root, value; 4517 Lisp_Object root, height;
4518 int line_height, pixel_height;
4142 4519
4143 eassert (MINI_WINDOW_P (w)); 4520 eassert (MINI_WINDOW_P (w));
4144 eassert (delta >= 0); 4521 eassert (delta >= 0);
4145 4522
4146 root = FRAME_ROOT_WINDOW (f); 4523 if (delta > 0)
4147 r = XWINDOW (root);
4148 value = call2 (Qwindow_resize_root_window_vertically,
4149 root, make_number (- delta));
4150 if (INTEGERP (value) && window_resize_check (r, 0))
4151 { 4524 {
4152 block_input (); 4525 root = FRAME_ROOT_WINDOW (f);
4153 window_resize_apply (r, 0); 4526 r = XWINDOW (root);
4527 height = call3 (Qwindow_resize_root_window_vertically,
4528 root, make_number (- delta), pixelwise ? Qt : Qnil);
4529 if (INTEGERP (height) && window_resize_check (r, false))
4530 {
4531 block_input ();
4532 window_resize_apply (r, false);
4154 4533
4155 /* Grow the mini-window. */ 4534 if (pixelwise)
4156 w->top_line = r->top_line + r->total_lines; 4535 {
4157 w->total_lines -= XINT (value); 4536 pixel_height = min (-XINT (height), INT_MAX - w->pixel_height);
4158 /* Enforce full redisplay. FIXME: make it more selective. */ 4537 line_height = pixel_height / FRAME_LINE_HEIGHT (f);
4159 windows_or_buffers_changed++; 4538 }
4160 adjust_glyphs (f); 4539 else
4161 unblock_input (); 4540 {
4541 line_height = min (-XINT (height),
4542 ((INT_MAX - w->pixel_height)
4543 / FRAME_LINE_HEIGHT (f)));
4544 pixel_height = line_height * FRAME_LINE_HEIGHT (f);
4545 }
4546
4547 /* Grow the mini-window. */
4548 w->pixel_top = r->pixel_top + r->pixel_height;
4549 w->top_line = r->top_line + r->total_lines;
4550 /* Make sure the mini-window has always at least one line. */
4551 w->pixel_height = max (w->pixel_height + pixel_height,
4552 FRAME_LINE_HEIGHT (f));
4553 w->total_lines = max (w->total_lines + line_height, 1);
4554
4555 /* Enforce full redisplay of the frame. */
4556 /* FIXME: Shouldn't window--resize-root-window-vertically do it? */
4557 fset_redisplay (f);
4558 adjust_frame_glyphs (f);
4559 unblock_input ();
4560 }
4162 } 4561 }
4163} 4562}
4164 4563
4165 4564/* Shrink mini-window W to one line. */
4166/* Shrink mini-window W. */
4167void 4565void
4168shrink_mini_window (struct window *w) 4566shrink_mini_window (struct window *w, bool pixelwise)
4169{ 4567{
4170 struct frame *f = XFRAME (w->frame); 4568 struct frame *f = XFRAME (w->frame);
4171 struct window *r; 4569 struct window *r;
4172 Lisp_Object root, value; 4570 Lisp_Object root, delta;
4173 EMACS_INT size; 4571 EMACS_INT height, unit;
4174 4572
4175 eassert (MINI_WINDOW_P (w)); 4573 eassert (MINI_WINDOW_P (w));
4176 4574
4177 size = w->total_lines; 4575 height = pixelwise ? w->pixel_height : w->total_lines;
4178 if (size > 1) 4576 unit = pixelwise ? FRAME_LINE_HEIGHT (f) : 1;
4577 if (height > unit)
4179 { 4578 {
4180 root = FRAME_ROOT_WINDOW (f); 4579 root = FRAME_ROOT_WINDOW (f);
4181 r = XWINDOW (root); 4580 r = XWINDOW (root);
4182 value = call2 (Qwindow_resize_root_window_vertically, 4581 delta = call3 (Qwindow_resize_root_window_vertically,
4183 root, make_number (size - 1)); 4582 root, make_number (height - unit),
4184 if (INTEGERP (value) && window_resize_check (r, 0)) 4583 pixelwise ? Qt : Qnil);
4584 if (INTEGERP (delta) && window_resize_check (r, false))
4185 { 4585 {
4186 block_input (); 4586 block_input ();
4187 window_resize_apply (r, 0); 4587 window_resize_apply (r, false);
4188 4588
4189 /* Shrink the mini-window. */ 4589 /* Shrink the mini-window. */
4190 w->top_line = r->top_line + r->total_lines; 4590 w->top_line = r->top_line + r->total_lines;
4191 w->total_lines = 1; 4591 w->total_lines = 1;
4192 /* Enforce full redisplay. FIXME: make it more selective. */ 4592 w->pixel_top = r->pixel_top + r->pixel_height;
4193 windows_or_buffers_changed++; 4593 w->pixel_height = FRAME_LINE_HEIGHT (f);
4194 adjust_glyphs (f); 4594 /* Enforce full redisplay of the frame. */
4595 /* FIXME: Shouldn't window--resize-root-window-vertically do it? */
4596 fset_redisplay (f);
4597 adjust_frame_glyphs (f);
4195 unblock_input (); 4598 unblock_input ();
4196 } 4599 }
4197 /* If the above failed for whatever strange reason we must make a 4600 /* If the above failed for whatever strange reason we must make a
@@ -4219,26 +4622,27 @@ DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini
4219 error ("Cannot resize a minibuffer-only frame"); 4622 error ("Cannot resize a minibuffer-only frame");
4220 4623
4221 r = XWINDOW (FRAME_ROOT_WINDOW (f)); 4624 r = XWINDOW (FRAME_ROOT_WINDOW (f));
4222 height = r->total_lines + w->total_lines; 4625 height = r->pixel_height + w->pixel_height;
4223 if (window_resize_check (r, 0) 4626 if (window_resize_check (r, false)
4224 && XINT (w->new_total) > 0 4627 && XINT (w->new_pixel) > 0
4225 && height == XINT (r->new_total) + XINT (w->new_total)) 4628 && height == XINT (r->new_pixel) + XINT (w->new_pixel))
4226 { 4629 {
4227 block_input (); 4630 block_input ();
4228 window_resize_apply (r, 0); 4631 window_resize_apply (r, false);
4229 4632
4230 w->total_lines = XFASTINT (w->new_total); 4633 w->pixel_height = XFASTINT (w->new_pixel);
4634 w->total_lines = w->pixel_height / FRAME_LINE_HEIGHT (f);
4635 w->pixel_top = r->pixel_top + r->pixel_height;
4231 w->top_line = r->top_line + r->total_lines; 4636 w->top_line = r->top_line + r->total_lines;
4232 4637
4233 windows_or_buffers_changed++; 4638 fset_redisplay (f);
4234 FRAME_WINDOW_SIZES_CHANGED (f) = 1; 4639 FRAME_WINDOW_SIZES_CHANGED (f) = true;
4235 adjust_glyphs (f); 4640 adjust_frame_glyphs (f);
4236 unblock_input (); 4641 unblock_input ();
4237
4238 run_window_configuration_change_hook (f);
4239 return Qt; 4642 return Qt;
4240 } 4643 }
4241 else error ("Failed to resize minibuffer window"); 4644 else
4645 error ("Failed to resize minibuffer window");
4242} 4646}
4243 4647
4244/* Mark window cursors off for all windows in the window tree rooted 4648/* Mark window cursors off for all windows in the window tree rooted
@@ -4254,7 +4658,7 @@ mark_window_cursors_off (struct window *w)
4254 if (WINDOWP (w->contents)) 4658 if (WINDOWP (w->contents))
4255 mark_window_cursors_off (XWINDOW (w->contents)); 4659 mark_window_cursors_off (XWINDOW (w->contents));
4256 else 4660 else
4257 w->phys_cursor_on_p = 0; 4661 w->phys_cursor_on_p = false;
4258 4662
4259 w = NILP (w->next) ? 0 : XWINDOW (w->next); 4663 w = NILP (w->next) ? 0 : XWINDOW (w->next);
4260 } 4664 }
@@ -4283,24 +4687,32 @@ window_internal_height (struct window *w)
4283 4687
4284 return ht; 4688 return ht;
4285} 4689}
4690
4286 4691
4287/************************************************************************ 4692/************************************************************************
4288 Window Scrolling 4693 Window Scrolling
4289 ***********************************************************************/ 4694 ***********************************************************************/
4290 4695
4291/* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll 4696/* Scroll contents of window WINDOW up. If WHOLE, scroll
4292 N screen-fulls, which is defined as the height of the window minus 4697 N screen-fulls, which is defined as the height of the window minus
4293 next_screen_context_lines. If WHOLE is zero, scroll up N lines 4698 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4294 instead. Negative values of N mean scroll down. NOERROR non-zero 4699 instead. Negative values of N mean scroll down. NOERROR
4295 means don't signal an error if we try to move over BEGV or ZV, 4700 means don't signal an error if we try to move over BEGV or ZV,
4296 respectively. */ 4701 respectively. */
4297 4702
4298static void 4703static void
4299window_scroll (Lisp_Object window, EMACS_INT n, bool whole, int noerror) 4704window_scroll (Lisp_Object window, EMACS_INT n, bool whole, bool noerror)
4300{ 4705{
4301 immediate_quit = 1; 4706 ptrdiff_t count = SPECPDL_INDEX ();
4707
4708 immediate_quit = true;
4302 n = clip_to_bounds (INT_MIN, n, INT_MAX); 4709 n = clip_to_bounds (INT_MIN, n, INT_MAX);
4303 4710
4711 wset_redisplay (XWINDOW (window));
4712
4713 if (whole && Vfast_but_imprecise_scrolling)
4714 specbind (Qfontification_functions, Qnil);
4715
4304 /* If we must, use the pixel-based version which is much slower than 4716 /* If we must, use the pixel-based version which is much slower than
4305 the line-based one but can handle varying line heights. */ 4717 the line-based one but can handle varying line heights. */
4306 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window)->frame))) 4718 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window)->frame)))
@@ -4308,7 +4720,11 @@ window_scroll (Lisp_Object window, EMACS_INT n, bool whole, int noerror)
4308 else 4720 else
4309 window_scroll_line_based (window, n, whole, noerror); 4721 window_scroll_line_based (window, n, whole, noerror);
4310 4722
4311 immediate_quit = 0; 4723 unbind_to (count, Qnil);
4724
4725 /* Bug#15957. */
4726 XWINDOW (window)->window_end_valid = false;
4727 immediate_quit = false;
4312} 4728}
4313 4729
4314 4730
@@ -4317,18 +4733,20 @@ window_scroll (Lisp_Object window, EMACS_INT n, bool whole, int noerror)
4317 descriptions. */ 4733 descriptions. */
4318 4734
4319static void 4735static void
4320window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror) 4736window_scroll_pixel_based (Lisp_Object window, int n, bool whole, bool noerror)
4321{ 4737{
4322 struct it it; 4738 struct it it;
4323 struct window *w = XWINDOW (window); 4739 struct window *w = XWINDOW (window);
4324 struct text_pos start; 4740 struct text_pos start;
4325 int this_scroll_margin; 4741 int this_scroll_margin;
4326 /* True if we fiddled the window vscroll field without really scrolling. */ 4742 /* True if we fiddled the window vscroll field without really scrolling. */
4327 int vscrolled = 0; 4743 bool vscrolled = false;
4328 int x, y, rtop, rbot, rowh, vpos; 4744 int x, y, rtop, rbot, rowh, vpos;
4329 void *itdata = NULL; 4745 void *itdata = NULL;
4330 int window_total_lines; 4746 int window_total_lines;
4331 int frame_line_height = default_line_pixel_height (w); 4747 int frame_line_height = default_line_pixel_height (w);
4748 bool adjust_old_pointm = !NILP (Fequal (Fwindow_point (window),
4749 Fwindow_old_point (window)));
4332 4750
4333 SET_TEXT_POS_FROM_MARKER (start, w->start); 4751 SET_TEXT_POS_FROM_MARKER (start, w->start);
4334 /* Scrolling a minibuffer window via scroll bar when the echo area 4752 /* Scrolling a minibuffer window via scroll bar when the echo area
@@ -4340,7 +4758,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4340 /* If PT is not visible in WINDOW, move back one half of 4758 /* If PT is not visible in WINDOW, move back one half of
4341 the screen. Allow PT to be partially visible, otherwise 4759 the screen. Allow PT to be partially visible, otherwise
4342 something like (scroll-down 1) with PT in the line before 4760 something like (scroll-down 1) with PT in the line before
4343 the partially visible one would recenter. */ 4761 the partially visible one would recenter. */
4344 4762
4345 if (!pos_visible_p (w, PT, &x, &y, &rtop, &rbot, &rowh, &vpos)) 4763 if (!pos_visible_p (w, PT, &x, &y, &rtop, &rbot, &rowh, &vpos))
4346 { 4764 {
@@ -4355,8 +4773,8 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4355 /* The function move_iterator_vertically may move over more than 4773 /* The function move_iterator_vertically may move over more than
4356 the specified y-distance. If it->w is small, e.g. a 4774 the specified y-distance. If it->w is small, e.g. a
4357 mini-buffer window, we may end up in front of the window's 4775 mini-buffer window, we may end up in front of the window's
4358 display area. This is the case when Start displaying at the 4776 display area. Start displaying at the start of the line
4359 start of the line containing PT in this case. */ 4777 containing PT in this case. */
4360 if (it.current_y <= 0) 4778 if (it.current_y <= 0)
4361 { 4779 {
4362 init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID); 4780 init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID);
@@ -4365,17 +4783,22 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4365 } 4783 }
4366 4784
4367 start = it.current.pos; 4785 start = it.current.pos;
4368 bidi_unshelve_cache (itdata, 0); 4786 bidi_unshelve_cache (itdata, false);
4369 } 4787 }
4370 else if (auto_window_vscroll_p) 4788 else if (auto_window_vscroll_p)
4371 { 4789 {
4372 if (rtop || rbot) /* partially visible */ 4790 if (rtop || rbot) /* Partially visible. */
4373 { 4791 {
4374 int px; 4792 int px;
4375 int dy = frame_line_height; 4793 int dy = frame_line_height;
4794 /* In the below we divide the window box height by the
4795 frame's line height to make the result predictable when
4796 the window box is not an integral multiple of the line
4797 height. This is important to ensure we get back to the
4798 same position when scrolling up, then down. */
4376 if (whole) 4799 if (whole)
4377 dy = max ((window_box_height (w) 4800 dy = max ((window_box_height (w) / dy
4378 - next_screen_context_lines * dy), 4801 - next_screen_context_lines) * dy,
4379 dy); 4802 dy);
4380 dy *= n; 4803 dy *= n;
4381 4804
@@ -4413,11 +4836,11 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4413 spos = min (XINT (Fline_end_position (Qnil)) + 1, ZV); 4836 spos = min (XINT (Fline_end_position (Qnil)) + 1, ZV);
4414 set_marker_restricted (w->start, make_number (spos), 4837 set_marker_restricted (w->start, make_number (spos),
4415 w->contents); 4838 w->contents);
4416 w->start_at_line_beg = 1; 4839 w->start_at_line_beg = true;
4417 w->update_mode_line = 1; 4840 wset_update_mode_line (w);
4418 /* Set force_start so that redisplay_window will run the 4841 /* Set force_start so that redisplay_window will run the
4419 window-scroll-functions. */ 4842 window-scroll-functions. */
4420 w->force_start = 1; 4843 w->force_start = true;
4421 return; 4844 return;
4422 } 4845 }
4423 } 4846 }
@@ -4457,8 +4880,12 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4457 { 4880 {
4458 ptrdiff_t start_pos = IT_CHARPOS (it); 4881 ptrdiff_t start_pos = IT_CHARPOS (it);
4459 int dy = frame_line_height; 4882 int dy = frame_line_height;
4460 dy = max ((window_box_height (w) 4883 /* In the below we divide the window box height by the frame's
4461 - next_screen_context_lines * dy), 4884 line height to make the result predictable when the window
4885 box is not an integral multiple of the line height. This is
4886 important to ensure we get back to the same position when
4887 scrolling up, then down. */
4888 dy = max ((window_box_height (w) / dy - next_screen_context_lines) * dy,
4462 dy) * n; 4889 dy) * n;
4463 4890
4464 /* Note that move_it_vertically always moves the iterator to the 4891 /* Note that move_it_vertically always moves the iterator to the
@@ -4503,11 +4930,11 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4503 visible. */ 4930 visible. */
4504 w->vscroll = (it.last_visible_y 4931 w->vscroll = (it.last_visible_y
4505 - it.current_y + it.max_ascent + it.max_descent); 4932 - it.current_y + it.max_ascent + it.max_descent);
4506 adjust_glyphs (it.f); 4933 adjust_frame_glyphs (it.f);
4507 } 4934 }
4508 else 4935 else
4509 { 4936 {
4510 bidi_unshelve_cache (itdata, 0); 4937 bidi_unshelve_cache (itdata, false);
4511 if (noerror) 4938 if (noerror)
4512 return; 4939 return;
4513 else if (n < 0) /* could happen with empty buffers */ 4940 else if (n < 0) /* could happen with empty buffers */
@@ -4524,7 +4951,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4524 w->vscroll = 0; 4951 w->vscroll = 0;
4525 else 4952 else
4526 { 4953 {
4527 bidi_unshelve_cache (itdata, 0); 4954 bidi_unshelve_cache (itdata, false);
4528 if (noerror) 4955 if (noerror)
4529 return; 4956 return;
4530 else 4957 else
@@ -4534,10 +4961,10 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4534 4961
4535 /* If control gets here, then we vscrolled. */ 4962 /* If control gets here, then we vscrolled. */
4536 4963
4537 XBUFFER (w->contents)->prevent_redisplay_optimizations_p = 1; 4964 XBUFFER (w->contents)->prevent_redisplay_optimizations_p = true;
4538 4965
4539 /* Don't try to change the window start below. */ 4966 /* Don't try to change the window start below. */
4540 vscrolled = 1; 4967 vscrolled = true;
4541 } 4968 }
4542 4969
4543 if (! vscrolled) 4970 if (! vscrolled)
@@ -4558,10 +4985,10 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4558 IT_BYTEPOS (it)); 4985 IT_BYTEPOS (it));
4559 bytepos = marker_byte_position (w->start); 4986 bytepos = marker_byte_position (w->start);
4560 w->start_at_line_beg = (pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n'); 4987 w->start_at_line_beg = (pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n');
4561 w->update_mode_line = 1; 4988 wset_update_mode_line (w);
4562 /* Set force_start so that redisplay_window will run the 4989 /* Set force_start so that redisplay_window will run the
4563 window-scroll-functions. */ 4990 window-scroll-functions. */
4564 w->force_start = 1; 4991 w->force_start = true;
4565 } 4992 }
4566 4993
4567 /* The rest of this function uses current_y in a nonstandard way, 4994 /* The rest of this function uses current_y in a nonstandard way,
@@ -4594,8 +5021,8 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4594 This is necessary because we set it.current_y to 0, above. */ 5021 This is necessary because we set it.current_y to 0, above. */
4595 move_it_to (&it, -1, 5022 move_it_to (&it, -1,
4596 window_scroll_pixel_based_preserve_x, 5023 window_scroll_pixel_based_preserve_x,
4597 window_scroll_pixel_based_preserve_y 5024 (window_scroll_pixel_based_preserve_y
4598 - (WINDOW_WANTS_HEADER_LINE_P (w) ? 1 : 0 ), 5025 - WINDOW_WANTS_HEADER_LINE_P (w)),
4599 -1, MOVE_TO_Y | MOVE_TO_X); 5026 -1, MOVE_TO_Y | MOVE_TO_X);
4600 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it)); 5027 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4601 } 5028 }
@@ -4614,7 +5041,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4614 else if (n < 0) 5041 else if (n < 0)
4615 { 5042 {
4616 ptrdiff_t charpos, bytepos; 5043 ptrdiff_t charpos, bytepos;
4617 int partial_p; 5044 bool partial_p;
4618 5045
4619 /* Save our position, for the 5046 /* Save our position, for the
4620 window_scroll_pixel_based_preserve_y case. */ 5047 window_scroll_pixel_based_preserve_y case. */
@@ -4633,6 +5060,32 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4633 charpos = IT_CHARPOS (it); 5060 charpos = IT_CHARPOS (it);
4634 bytepos = IT_BYTEPOS (it); 5061 bytepos = IT_BYTEPOS (it);
4635 5062
5063 /* If PT is in the screen line at the last fully visible line,
5064 move_it_to will stop at X = 0 in that line, because the
5065 required Y coordinate is reached there. See if we can get to
5066 PT without descending lower in Y, and if we can, it means we
5067 reached PT before the scroll margin. */
5068 if (charpos != PT)
5069 {
5070 struct it it2;
5071 void *it_data;
5072
5073 it2 = it;
5074 it_data = bidi_shelve_cache ();
5075 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
5076 if (IT_CHARPOS (it) == PT && it.current_y == it2.current_y)
5077 {
5078 charpos = IT_CHARPOS (it);
5079 bytepos = IT_BYTEPOS (it);
5080 bidi_unshelve_cache (it_data, true);
5081 }
5082 else
5083 {
5084 it = it2;
5085 bidi_unshelve_cache (it_data, false);
5086 }
5087 }
5088
4636 /* See if point is on a partially visible line at the end. */ 5089 /* See if point is on a partially visible line at the end. */
4637 if (it.what == IT_EOB) 5090 if (it.what == IT_EOB)
4638 partial_p = it.current_y + it.ascent + it.descent > it.last_visible_y; 5091 partial_p = it.current_y + it.ascent + it.descent > it.last_visible_y;
@@ -4673,7 +5126,14 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4673 SET_PT_BOTH (charpos, bytepos); 5126 SET_PT_BOTH (charpos, bytepos);
4674 } 5127 }
4675 } 5128 }
4676 bidi_unshelve_cache (itdata, 0); 5129 bidi_unshelve_cache (itdata, false);
5130
5131 if (adjust_old_pointm)
5132 Fset_marker (w->old_pointm,
5133 ((w == XWINDOW (selected_window))
5134 ? make_number (BUF_PT (XBUFFER (w->contents)))
5135 : Fmarker_position (w->pointm)),
5136 w->contents);
4677} 5137}
4678 5138
4679 5139
@@ -4681,9 +5141,9 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4681 See the comment of window_scroll for parameter descriptions. */ 5141 See the comment of window_scroll for parameter descriptions. */
4682 5142
4683static void 5143static void
4684window_scroll_line_based (Lisp_Object window, int n, bool whole, int noerror) 5144window_scroll_line_based (Lisp_Object window, int n, bool whole, bool noerror)
4685{ 5145{
4686 register struct window *w = XWINDOW (window); 5146 struct window *w = XWINDOW (window);
4687 /* Fvertical_motion enters redisplay, which can trigger 5147 /* Fvertical_motion enters redisplay, which can trigger
4688 fontification, which in turn can modify buffer text (e.g., if the 5148 fontification, which in turn can modify buffer text (e.g., if the
4689 fontification functions replace escape sequences with faces, as 5149 fontification functions replace escape sequences with faces, as
@@ -4698,6 +5158,8 @@ window_scroll_line_based (Lisp_Object window, int n, bool whole, int noerror)
4698 ptrdiff_t startpos = marker_position (w->start); 5158 ptrdiff_t startpos = marker_position (w->start);
4699 ptrdiff_t startbyte = marker_byte_position (w->start); 5159 ptrdiff_t startbyte = marker_byte_position (w->start);
4700 Lisp_Object original_pos = Qnil; 5160 Lisp_Object original_pos = Qnil;
5161 bool adjust_old_pointm = !NILP (Fequal (Fwindow_point (window),
5162 Fwindow_old_point (window)));
4701 5163
4702 /* If scrolling screen-fulls, compute the number of lines to 5164 /* If scrolling screen-fulls, compute the number of lines to
4703 scroll from the window's height. */ 5165 scroll from the window's height. */
@@ -4711,8 +5173,9 @@ window_scroll_line_based (Lisp_Object window, int n, bool whole, int noerror)
4711 || NILP (Fget (KVAR (current_kboard, Vlast_command), Qscroll_command))) 5173 || NILP (Fget (KVAR (current_kboard, Vlast_command), Qscroll_command)))
4712 { 5174 {
4713 struct position posit 5175 struct position posit
4714 = *compute_motion (startpos, startbyte, 0, 0, 0, 5176 = *compute_motion (startpos, startbyte, 0, 0, false,
4715 PT, ht, 0, -1, w->hscroll, 0, w); 5177 PT, ht, 0, -1, w->hscroll, 0, w);
5178
4716 window_scroll_preserve_vpos = posit.vpos; 5179 window_scroll_preserve_vpos = posit.vpos;
4717 window_scroll_preserve_hpos = posit.hpos + w->hscroll; 5180 window_scroll_preserve_hpos = posit.hpos + w->hscroll;
4718 } 5181 }
@@ -4726,14 +5189,14 @@ window_scroll_line_based (Lisp_Object window, int n, bool whole, int noerror)
4726 5189
4727 if (NILP (tem)) 5190 if (NILP (tem))
4728 { 5191 {
4729 Fvertical_motion (make_number (- (ht / 2)), window); 5192 Fvertical_motion (make_number (- (ht / 2)), window, Qnil);
4730 startpos = PT; 5193 startpos = PT;
4731 startbyte = PT_BYTE; 5194 startbyte = PT_BYTE;
4732 } 5195 }
4733 5196
4734 SET_PT_BOTH (startpos, startbyte); 5197 SET_PT_BOTH (startpos, startbyte);
4735 lose = n < 0 && PT == BEGV; 5198 lose = n < 0 && PT == BEGV;
4736 Fvertical_motion (make_number (n), window); 5199 Fvertical_motion (make_number (n), window, Qnil);
4737 pos = PT; 5200 pos = PT;
4738 pos_byte = PT_BYTE; 5201 pos_byte = PT_BYTE;
4739 bolp = Fbolp (); 5202 bolp = Fbolp ();
@@ -4756,16 +5219,16 @@ window_scroll_line_based (Lisp_Object window, int n, bool whole, int noerror)
4756 5219
4757 set_marker_restricted_both (w->start, w->contents, pos, pos_byte); 5220 set_marker_restricted_both (w->start, w->contents, pos, pos_byte);
4758 w->start_at_line_beg = !NILP (bolp); 5221 w->start_at_line_beg = !NILP (bolp);
4759 w->update_mode_line = 1; 5222 wset_update_mode_line (w);
4760 /* Set force_start so that redisplay_window will run 5223 /* Set force_start so that redisplay_window will run
4761 the window-scroll-functions. */ 5224 the window-scroll-functions. */
4762 w->force_start = 1; 5225 w->force_start = true;
4763 5226
4764 if (!NILP (Vscroll_preserve_screen_position) 5227 if (!NILP (Vscroll_preserve_screen_position)
4765 && (whole || !EQ (Vscroll_preserve_screen_position, Qt))) 5228 && (whole || !EQ (Vscroll_preserve_screen_position, Qt)))
4766 { 5229 {
4767 SET_PT_BOTH (pos, pos_byte); 5230 SET_PT_BOTH (pos, pos_byte);
4768 Fvertical_motion (original_pos, window); 5231 Fvertical_motion (original_pos, window, Qnil);
4769 } 5232 }
4770 /* If we scrolled forward, put point enough lines down 5233 /* If we scrolled forward, put point enough lines down
4771 that it is outside the scroll margin. */ 5234 that it is outside the scroll margin. */
@@ -4776,7 +5239,7 @@ window_scroll_line_based (Lisp_Object window, int n, bool whole, int noerror)
4776 if (this_scroll_margin > 0) 5239 if (this_scroll_margin > 0)
4777 { 5240 {
4778 SET_PT_BOTH (pos, pos_byte); 5241 SET_PT_BOTH (pos, pos_byte);
4779 Fvertical_motion (make_number (this_scroll_margin), window); 5242 Fvertical_motion (make_number (this_scroll_margin), window, Qnil);
4780 top_margin = PT; 5243 top_margin = PT;
4781 } 5244 }
4782 else 5245 else
@@ -4788,7 +5251,7 @@ window_scroll_line_based (Lisp_Object window, int n, bool whole, int noerror)
4788 else if (!NILP (Vscroll_preserve_screen_position)) 5251 else if (!NILP (Vscroll_preserve_screen_position))
4789 { 5252 {
4790 SET_PT_BOTH (pos, pos_byte); 5253 SET_PT_BOTH (pos, pos_byte);
4791 Fvertical_motion (original_pos, window); 5254 Fvertical_motion (original_pos, window, Qnil);
4792 } 5255 }
4793 else 5256 else
4794 SET_PT (top_margin); 5257 SET_PT (top_margin);
@@ -4800,7 +5263,8 @@ window_scroll_line_based (Lisp_Object window, int n, bool whole, int noerror)
4800 /* If we scrolled backward, put point near the end of the window 5263 /* If we scrolled backward, put point near the end of the window
4801 but not within the scroll margin. */ 5264 but not within the scroll margin. */
4802 SET_PT_BOTH (pos, pos_byte); 5265 SET_PT_BOTH (pos, pos_byte);
4803 tem = Fvertical_motion (make_number (ht - this_scroll_margin), window); 5266 tem = Fvertical_motion (make_number (ht - this_scroll_margin), window,
5267 Qnil);
4804 if (XFASTINT (tem) == ht - this_scroll_margin) 5268 if (XFASTINT (tem) == ht - this_scroll_margin)
4805 bottom_margin = PT; 5269 bottom_margin = PT;
4806 else 5270 else
@@ -4814,10 +5278,10 @@ window_scroll_line_based (Lisp_Object window, int n, bool whole, int noerror)
4814 if (!NILP (Vscroll_preserve_screen_position)) 5278 if (!NILP (Vscroll_preserve_screen_position))
4815 { 5279 {
4816 SET_PT_BOTH (pos, pos_byte); 5280 SET_PT_BOTH (pos, pos_byte);
4817 Fvertical_motion (original_pos, window); 5281 Fvertical_motion (original_pos, window, Qnil);
4818 } 5282 }
4819 else 5283 else
4820 Fvertical_motion (make_number (-1), window); 5284 Fvertical_motion (make_number (-1), window, Qnil);
4821 } 5285 }
4822 } 5286 }
4823 } 5287 }
@@ -4828,6 +5292,13 @@ window_scroll_line_based (Lisp_Object window, int n, bool whole, int noerror)
4828 else 5292 else
4829 xsignal0 (Qend_of_buffer); 5293 xsignal0 (Qend_of_buffer);
4830 } 5294 }
5295
5296 if (adjust_old_pointm)
5297 Fset_marker (w->old_pointm,
5298 ((w == XWINDOW (selected_window))
5299 ? make_number (BUF_PT (XBUFFER (w->contents)))
5300 : Fmarker_position (w->pointm)),
5301 w->contents);
4831} 5302}
4832 5303
4833 5304
@@ -4850,19 +5321,16 @@ scroll_command (Lisp_Object n, int direction)
4850 { 5321 {
4851 record_unwind_protect (save_excursion_restore, save_excursion_save ()); 5322 record_unwind_protect (save_excursion_restore, save_excursion_save ());
4852 Fset_buffer (XWINDOW (selected_window)->contents); 5323 Fset_buffer (XWINDOW (selected_window)->contents);
4853
4854 /* Make redisplay consider other windows than just selected_window. */
4855 ++windows_or_buffers_changed;
4856 } 5324 }
4857 5325
4858 if (NILP (n)) 5326 if (NILP (n))
4859 window_scroll (selected_window, direction, 1, 0); 5327 window_scroll (selected_window, direction, true, false);
4860 else if (EQ (n, Qminus)) 5328 else if (EQ (n, Qminus))
4861 window_scroll (selected_window, -direction, 1, 0); 5329 window_scroll (selected_window, -direction, true, false);
4862 else 5330 else
4863 { 5331 {
4864 n = Fprefix_numeric_value (n); 5332 n = Fprefix_numeric_value (n);
4865 window_scroll (selected_window, XINT (n) * direction, 0, 0); 5333 window_scroll (selected_window, XINT (n) * direction, false, false);
4866 } 5334 }
4867 5335
4868 unbind_to (count, Qnil); 5336 unbind_to (count, Qnil);
@@ -4908,8 +5376,10 @@ specifies the window. This takes precedence over
4908 if (MINI_WINDOW_P (XWINDOW (selected_window)) 5376 if (MINI_WINDOW_P (XWINDOW (selected_window))
4909 && !NILP (Vminibuf_scroll_window)) 5377 && !NILP (Vminibuf_scroll_window))
4910 window = Vminibuf_scroll_window; 5378 window = Vminibuf_scroll_window;
4911 /* If buffer is specified, scroll that buffer. */ 5379 /* If buffer is specified and live, scroll that buffer. */
4912 else if (!NILP (Vother_window_scroll_buffer)) 5380 else if (!NILP (Vother_window_scroll_buffer)
5381 && BUFFERP (Vother_window_scroll_buffer)
5382 && BUFFER_LIVE_P (XBUFFER (Vother_window_scroll_buffer)))
4913 { 5383 {
4914 window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil); 5384 window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil);
4915 if (NILP (window)) 5385 if (NILP (window))
@@ -4962,24 +5432,25 @@ specifies the window to scroll. This takes precedence over
4962 5432
4963 /* Don't screw up if window_scroll gets an error. */ 5433 /* Don't screw up if window_scroll gets an error. */
4964 record_unwind_protect (save_excursion_restore, save_excursion_save ()); 5434 record_unwind_protect (save_excursion_restore, save_excursion_save ());
4965 ++windows_or_buffers_changed;
4966 5435
4967 Fset_buffer (w->contents); 5436 Fset_buffer (w->contents);
4968 SET_PT_BOTH (marker_position (w->pointm), marker_byte_position (w->pointm)); 5437 SET_PT_BOTH (marker_position (w->pointm), marker_byte_position (w->pointm));
5438 SET_PT_BOTH (marker_position (w->old_pointm), marker_byte_position (w->old_pointm));
4969 5439
4970 if (NILP (arg)) 5440 if (NILP (arg))
4971 window_scroll (window, 1, 1, 1); 5441 window_scroll (window, 1, true, true);
4972 else if (EQ (arg, Qminus)) 5442 else if (EQ (arg, Qminus))
4973 window_scroll (window, -1, 1, 1); 5443 window_scroll (window, -1, true, true);
4974 else 5444 else
4975 { 5445 {
4976 if (CONSP (arg)) 5446 if (CONSP (arg))
4977 arg = XCAR (arg); 5447 arg = XCAR (arg);
4978 CHECK_NUMBER (arg); 5448 CHECK_NUMBER (arg);
4979 window_scroll (window, XINT (arg), 0, 1); 5449 window_scroll (window, XINT (arg), false, true);
4980 } 5450 }
4981 5451
4982 set_marker_both (w->pointm, Qnil, PT, PT_BYTE); 5452 set_marker_both (w->pointm, Qnil, PT, PT_BYTE);
5453 set_marker_both (w->old_pointm, Qnil, PT, PT_BYTE);
4983 unbind_to (count, Qnil); 5454 unbind_to (count, Qnil);
4984 5455
4985 return Qnil; 5456 return Qnil;
@@ -4998,13 +5469,15 @@ by this function. This happens in an interactive call. */)
4998{ 5469{
4999 struct window *w = XWINDOW (selected_window); 5470 struct window *w = XWINDOW (selected_window);
5000 EMACS_INT requested_arg = (NILP (arg) 5471 EMACS_INT requested_arg = (NILP (arg)
5001 ? window_body_cols (w) - 2 5472 ? window_body_width (w, 0) - 2
5002 : XINT (Fprefix_numeric_value (arg))); 5473 : XINT (Fprefix_numeric_value (arg)));
5003 Lisp_Object result = set_window_hscroll (w, w->hscroll + requested_arg); 5474 Lisp_Object result = set_window_hscroll (w, w->hscroll + requested_arg);
5004 5475
5005 if (!NILP (set_minimum)) 5476 if (!NILP (set_minimum))
5006 w->min_hscroll = w->hscroll; 5477 w->min_hscroll = w->hscroll;
5007 5478
5479 w->suspend_auto_hscroll = true;
5480
5008 return result; 5481 return result;
5009} 5482}
5010 5483
@@ -5021,13 +5494,15 @@ by this function. This happens in an interactive call. */)
5021{ 5494{
5022 struct window *w = XWINDOW (selected_window); 5495 struct window *w = XWINDOW (selected_window);
5023 EMACS_INT requested_arg = (NILP (arg) 5496 EMACS_INT requested_arg = (NILP (arg)
5024 ? window_body_cols (w) - 2 5497 ? window_body_width (w, 0) - 2
5025 : XINT (Fprefix_numeric_value (arg))); 5498 : XINT (Fprefix_numeric_value (arg)));
5026 Lisp_Object result = set_window_hscroll (w, w->hscroll - requested_arg); 5499 Lisp_Object result = set_window_hscroll (w, w->hscroll - requested_arg);
5027 5500
5028 if (!NILP (set_minimum)) 5501 if (!NILP (set_minimum))
5029 w->min_hscroll = w->hscroll; 5502 w->min_hscroll = w->hscroll;
5030 5503
5504 w->suspend_auto_hscroll = true;
5505
5031 return result; 5506 return result;
5032} 5507}
5033 5508
@@ -5052,7 +5527,6 @@ displayed_window_lines (struct window *w)
5052{ 5527{
5053 struct it it; 5528 struct it it;
5054 struct text_pos start; 5529 struct text_pos start;
5055 ptrdiff_t charpos = marker_position (w->start);
5056 int height = window_box_height (w); 5530 int height = window_box_height (w);
5057 struct buffer *old_buffer; 5531 struct buffer *old_buffer;
5058 int bottom_y; 5532 int bottom_y;
@@ -5069,18 +5543,13 @@ displayed_window_lines (struct window *w)
5069 /* In case W->start is out of the accessible range, do something 5543 /* In case W->start is out of the accessible range, do something
5070 reasonable. This happens in Info mode when Info-scroll-down 5544 reasonable. This happens in Info mode when Info-scroll-down
5071 calls (recenter -1) while W->start is 1. */ 5545 calls (recenter -1) while W->start is 1. */
5072 if (charpos < BEGV) 5546 CLIP_TEXT_POS_FROM_MARKER (start, w->start);
5073 SET_TEXT_POS (start, BEGV, BEGV_BYTE);
5074 else if (charpos > ZV)
5075 SET_TEXT_POS (start, ZV, ZV_BYTE);
5076 else
5077 SET_TEXT_POS_FROM_MARKER (start, w->start);
5078 5547
5079 itdata = bidi_shelve_cache (); 5548 itdata = bidi_shelve_cache ();
5080 start_display (&it, w, start); 5549 start_display (&it, w, start);
5081 move_it_vertically (&it, height); 5550 move_it_vertically (&it, height);
5082 bottom_y = line_bottom_y (&it); 5551 bottom_y = line_bottom_y (&it);
5083 bidi_unshelve_cache (itdata, 0); 5552 bidi_unshelve_cache (itdata, false);
5084 5553
5085 /* rms: On a non-window display, 5554 /* rms: On a non-window display,
5086 the value of it.vpos at the bottom of the screen 5555 the value of it.vpos at the bottom of the screen
@@ -5124,14 +5593,16 @@ and redisplay normally--don't erase and redraw the frame. */)
5124{ 5593{
5125 struct window *w = XWINDOW (selected_window); 5594 struct window *w = XWINDOW (selected_window);
5126 struct buffer *buf = XBUFFER (w->contents); 5595 struct buffer *buf = XBUFFER (w->contents);
5127 struct buffer *obuf = current_buffer; 5596 bool center_p = false;
5128 bool center_p = 0;
5129 ptrdiff_t charpos, bytepos; 5597 ptrdiff_t charpos, bytepos;
5130 EMACS_INT iarg IF_LINT (= 0); 5598 EMACS_INT iarg IF_LINT (= 0);
5131 int this_scroll_margin; 5599 int this_scroll_margin;
5132 5600
5601 if (buf != current_buffer)
5602 error ("`recenter'ing a window that does not display current-buffer.");
5603
5133 /* If redisplay is suppressed due to an error, try again. */ 5604 /* If redisplay is suppressed due to an error, try again. */
5134 obuf->display_error_modiff = 0; 5605 buf->display_error_modiff = 0;
5135 5606
5136 if (NILP (arg)) 5607 if (NILP (arg))
5137 { 5608 {
@@ -5144,17 +5615,17 @@ and redisplay normally--don't erase and redraw the frame. */)
5144 /* Invalidate pixel data calculated for all compositions. */ 5615 /* Invalidate pixel data calculated for all compositions. */
5145 for (i = 0; i < n_compositions; i++) 5616 for (i = 0; i < n_compositions; i++)
5146 composition_table[i]->font = NULL; 5617 composition_table[i]->font = NULL;
5147 5618#if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
5148 WINDOW_XFRAME (w)->minimize_tool_bar_window_p = 1; 5619 WINDOW_XFRAME (w)->minimize_tool_bar_window_p = 1;
5149 5620#endif
5150 Fredraw_frame (WINDOW_FRAME (w)); 5621 Fredraw_frame (WINDOW_FRAME (w));
5151 SET_FRAME_GARBAGED (WINDOW_XFRAME (w)); 5622 SET_FRAME_GARBAGED (WINDOW_XFRAME (w));
5152 } 5623 }
5153 5624
5154 center_p = 1; 5625 center_p = true;
5155 } 5626 }
5156 else if (CONSP (arg)) /* Just C-u. */ 5627 else if (CONSP (arg)) /* Just C-u. */
5157 center_p = 1; 5628 center_p = true;
5158 else 5629 else
5159 { 5630 {
5160 arg = Fprefix_numeric_value (arg); 5631 arg = Fprefix_numeric_value (arg);
@@ -5162,17 +5633,14 @@ and redisplay normally--don't erase and redraw the frame. */)
5162 iarg = XINT (arg); 5633 iarg = XINT (arg);
5163 } 5634 }
5164 5635
5165 set_buffer_internal (buf);
5166
5167 /* Do this after making BUF current 5636 /* Do this after making BUF current
5168 in case scroll_margin is buffer-local. */ 5637 in case scroll_margin is buffer-local. */
5169 this_scroll_margin = 5638 this_scroll_margin
5170 max (0, min (scroll_margin, w->total_lines / 4)); 5639 = max (0, min (scroll_margin, w->total_lines / 4));
5171 5640
5172 /* Handle centering on a graphical frame specially. Such frames can 5641 /* Don't use redisplay code for initial frames, as the necessary
5173 have variable-height lines and centering point on the basis of 5642 data structures might not be set up yet then. */
5174 line counts would lead to strange effects. */ 5643 if (!FRAME_INITIAL_P (XFRAME (w->frame)))
5175 if (FRAME_WINDOW_P (XFRAME (w->frame)))
5176 { 5644 {
5177 if (center_p) 5645 if (center_p)
5178 { 5646 {
@@ -5185,7 +5653,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5185 move_it_vertically_backward (&it, window_box_height (w) / 2); 5653 move_it_vertically_backward (&it, window_box_height (w) / 2);
5186 charpos = IT_CHARPOS (it); 5654 charpos = IT_CHARPOS (it);
5187 bytepos = IT_BYTEPOS (it); 5655 bytepos = IT_BYTEPOS (it);
5188 bidi_unshelve_cache (itdata, 0); 5656 bidi_unshelve_cache (itdata, false);
5189 } 5657 }
5190 else if (iarg < 0) 5658 else if (iarg < 0)
5191 { 5659 {
@@ -5194,9 +5662,11 @@ and redisplay normally--don't erase and redraw the frame. */)
5194 ptrdiff_t nlines = min (PTRDIFF_MAX, -iarg); 5662 ptrdiff_t nlines = min (PTRDIFF_MAX, -iarg);
5195 int extra_line_spacing; 5663 int extra_line_spacing;
5196 int h = window_box_height (w); 5664 int h = window_box_height (w);
5665 int ht = window_internal_height (w);
5197 void *itdata = bidi_shelve_cache (); 5666 void *itdata = bidi_shelve_cache ();
5198 5667
5199 iarg = - max (-iarg, this_scroll_margin); 5668 nlines = clip_to_bounds (this_scroll_margin + 1, nlines,
5669 ht - this_scroll_margin);
5200 5670
5201 SET_TEXT_POS (pt, PT, PT_BYTE); 5671 SET_TEXT_POS (pt, PT, PT_BYTE);
5202 start_display (&it, w, pt); 5672 start_display (&it, w, pt);
@@ -5215,7 +5685,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5215 h -= it.current_y; 5685 h -= it.current_y;
5216 else 5686 else
5217 { 5687 {
5218 /* Last line has no newline */ 5688 /* Last line has no newline. */
5219 h -= line_bottom_y (&it); 5689 h -= line_bottom_y (&it);
5220 it.vpos++; 5690 it.vpos++;
5221 } 5691 }
@@ -5233,7 +5703,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5233 } 5703 }
5234 if (h <= 0) 5704 if (h <= 0)
5235 { 5705 {
5236 bidi_unshelve_cache (itdata, 0); 5706 bidi_unshelve_cache (itdata, false);
5237 return Qnil; 5707 return Qnil;
5238 } 5708 }
5239 5709
@@ -5256,17 +5726,37 @@ and redisplay normally--don't erase and redraw the frame. */)
5256 charpos = IT_CHARPOS (it); 5726 charpos = IT_CHARPOS (it);
5257 bytepos = IT_BYTEPOS (it); 5727 bytepos = IT_BYTEPOS (it);
5258 5728
5259 bidi_unshelve_cache (itdata, 0); 5729 bidi_unshelve_cache (itdata, false);
5260 } 5730 }
5261 else 5731 else
5262 { 5732 {
5263 struct position pos; 5733 struct it it;
5734 struct text_pos pt;
5735 ptrdiff_t nlines = min (PTRDIFF_MAX, iarg);
5736 int ht = window_internal_height (w);
5737 void *itdata = bidi_shelve_cache ();
5738
5739 nlines = clip_to_bounds (this_scroll_margin, nlines,
5740 ht - this_scroll_margin - 1);
5264 5741
5265 iarg = max (iarg, this_scroll_margin); 5742 SET_TEXT_POS (pt, PT, PT_BYTE);
5743 start_display (&it, w, pt);
5266 5744
5267 pos = *vmotion (PT, PT_BYTE, -iarg, w); 5745 /* Move to the beginning of screen line containing PT. */
5268 charpos = pos.bufpos; 5746 move_it_by_lines (&it, 0);
5269 bytepos = pos.bytepos; 5747
5748 /* Move back to find the point which is ARG screen lines above PT. */
5749 if (nlines > 0)
5750 {
5751 it.current_y = 0;
5752 it.vpos = 0;
5753 move_it_by_lines (&it, -nlines);
5754 }
5755
5756 charpos = IT_CHARPOS (it);
5757 bytepos = IT_BYTEPOS (it);
5758
5759 bidi_unshelve_cache (itdata, false);
5270 } 5760 }
5271 } 5761 }
5272 else 5762 else
@@ -5290,33 +5780,60 @@ and redisplay normally--don't erase and redraw the frame. */)
5290 5780
5291 /* Set the new window start. */ 5781 /* Set the new window start. */
5292 set_marker_both (w->start, w->contents, charpos, bytepos); 5782 set_marker_both (w->start, w->contents, charpos, bytepos);
5293 w->window_end_valid = 0; 5783 w->window_end_valid = false;
5294 5784
5295 w->optional_new_start = 1; 5785 w->optional_new_start = true;
5296 5786
5297 w->start_at_line_beg = (bytepos == BEGV_BYTE || 5787 w->start_at_line_beg = (bytepos == BEGV_BYTE
5298 FETCH_BYTE (bytepos - 1) == '\n'); 5788 || FETCH_BYTE (bytepos - 1) == '\n');
5789
5790 wset_redisplay (w);
5299 5791
5300 set_buffer_internal (obuf);
5301 return Qnil; 5792 return Qnil;
5302} 5793}
5303 5794
5304DEFUN ("window-text-height", Fwindow_text_height, Swindow_text_height, 5795DEFUN ("window-text-width", Fwindow_text_width, Swindow_text_width,
5305 0, 1, 0, 5796 0, 2, 0,
5306 doc: /* Return the height in lines of the text display area of WINDOW. 5797 doc: /* Return the width in columns of the text display area of WINDOW.
5307WINDOW must be a live window and defaults to the selected one. 5798WINDOW must be a live window and defaults to the selected one.
5308 5799
5309The returned height does not include the mode line, any header line, 5800The returned width does not include dividers, scrollbars, margins,
5310nor any partial-height lines at the bottom of the text area. */) 5801fringes, nor any partial-width columns at the right of the text
5311 (Lisp_Object window) 5802area.
5803
5804Optional argument PIXELWISE non-nil, means to return the width in
5805pixels. */)
5806 (Lisp_Object window, Lisp_Object pixelwise)
5312{ 5807{
5313 struct window *w = decode_live_window (window); 5808 struct window *w = decode_live_window (window);
5314 int pixel_height = window_box_height (w); 5809
5315 int line_height = pixel_height / FRAME_LINE_HEIGHT (XFRAME (w->frame)); 5810 if (NILP (pixelwise))
5316 return make_number (line_height); 5811 return make_number (window_box_width (w, TEXT_AREA)
5812 / FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w)));
5813 else
5814 return make_number (window_box_width (w, TEXT_AREA));
5317} 5815}
5318 5816
5817DEFUN ("window-text-height", Fwindow_text_height, Swindow_text_height,
5818 0, 2, 0,
5819 doc: /* Return the height in lines of the text display area of WINDOW.
5820WINDOW must be a live window and defaults to the selected one.
5821
5822The returned height does not include dividers, the mode line, any header
5823line, nor any partial-height lines at the bottom of the text area.
5319 5824
5825Optional argument PIXELWISE non-nil, means to return the height in
5826pixels. */)
5827 (Lisp_Object window, Lisp_Object pixelwise)
5828{
5829 struct window *w = decode_live_window (window);
5830
5831 if (NILP (pixelwise))
5832 return make_number (window_box_height (w)
5833 / FRAME_LINE_HEIGHT (WINDOW_XFRAME (w)));
5834 else
5835 return make_number (window_box_height (w));
5836}
5320 5837
5321DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line, 5838DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line,
5322 1, 1, "P", 5839 1, 1, "P",
@@ -5329,7 +5846,7 @@ zero means top of window, negative means relative to bottom of window. */)
5329 struct window *w = XWINDOW (selected_window); 5846 struct window *w = XWINDOW (selected_window);
5330 int lines, start; 5847 int lines, start;
5331 Lisp_Object window; 5848 Lisp_Object window;
5332#if 0 5849#if false
5333 int this_scroll_margin; 5850 int this_scroll_margin;
5334#endif 5851#endif
5335 5852
@@ -5343,17 +5860,17 @@ zero means top of window, negative means relative to bottom of window. */)
5343 if (start < BEGV || start > ZV) 5860 if (start < BEGV || start > ZV)
5344 { 5861 {
5345 int height = window_internal_height (w); 5862 int height = window_internal_height (w);
5346 Fvertical_motion (make_number (- (height / 2)), window); 5863 Fvertical_motion (make_number (- (height / 2)), window, Qnil);
5347 set_marker_both (w->start, w->contents, PT, PT_BYTE); 5864 set_marker_both (w->start, w->contents, PT, PT_BYTE);
5348 w->start_at_line_beg = !NILP (Fbolp ()); 5865 w->start_at_line_beg = !NILP (Fbolp ());
5349 w->force_start = 1; 5866 w->force_start = true;
5350 } 5867 }
5351 else 5868 else
5352 Fgoto_char (w->start); 5869 Fgoto_char (w->start);
5353 5870
5354 lines = displayed_window_lines (w); 5871 lines = displayed_window_lines (w);
5355 5872
5356#if 0 5873#if false
5357 this_scroll_margin = max (0, min (scroll_margin, lines / 4)); 5874 this_scroll_margin = max (0, min (scroll_margin, lines / 4));
5358#endif 5875#endif
5359 5876
@@ -5366,11 +5883,11 @@ zero means top of window, negative means relative to bottom of window. */)
5366 if (iarg < 0) 5883 if (iarg < 0)
5367 iarg = iarg + lines; 5884 iarg = iarg + lines;
5368 5885
5369#if 0 /* This code would prevent move-to-window-line from moving point 5886#if false /* This code would prevent move-to-window-line from moving point
5370 to a place inside the scroll margins (which would cause the 5887 to a place inside the scroll margins (which would cause the
5371 next redisplay to scroll). I wrote this code, but then concluded 5888 next redisplay to scroll). I wrote this code, but then concluded
5372 it is probably better not to install it. However, it is here 5889 it is probably better not to install it. However, it is here
5373 inside #if 0 so as not to lose it. -- rms. */ 5890 inside #if false so as not to lose it. -- rms. */
5374 5891
5375 /* Don't let it get into the margin at either top or bottom. */ 5892 /* Don't let it get into the margin at either top or bottom. */
5376 iarg = max (iarg, this_scroll_margin); 5893 iarg = max (iarg, this_scroll_margin);
@@ -5384,7 +5901,7 @@ zero means top of window, negative means relative to bottom of window. */)
5384 if (w->vscroll) 5901 if (w->vscroll)
5385 XSETINT (arg, XINT (arg) + 1); 5902 XSETINT (arg, XINT (arg) + 1);
5386 5903
5387 return Fvertical_motion (arg, window); 5904 return Fvertical_motion (arg, window, Qnil);
5388} 5905}
5389 5906
5390 5907
@@ -5409,26 +5926,34 @@ struct save_window_data
5409 5926
5410 /* All fields above are traced by the GC. 5927 /* All fields above are traced by the GC.
5411 From `frame-cols' down, the fields are ignored by the GC. */ 5928 From `frame-cols' down, the fields are ignored by the GC. */
5412 5929 /* We should be able to do without the following two. */
5413 int frame_cols, frame_lines, frame_menu_bar_lines; 5930 int frame_cols, frame_lines;
5414 int frame_tool_bar_lines; 5931 /* These two should get eventually replaced by their pixel
5932 counterparts. */
5933 int frame_menu_bar_lines, frame_tool_bar_lines;
5934 int frame_text_width, frame_text_height;
5935 /* These are currently unused. We need them as soon as we convert
5936 to pixels. */
5937 int frame_menu_bar_height, frame_tool_bar_height;
5415 }; 5938 };
5416 5939
5417/* This is saved as a Lisp_Vector */ 5940/* This is saved as a Lisp_Vector. */
5418struct saved_window 5941struct saved_window
5419{ 5942{
5420 struct vectorlike_header header; 5943 struct vectorlike_header header;
5421 5944
5422 Lisp_Object window, buffer, start, pointm, mark; 5945 Lisp_Object window, buffer, start, pointm, old_pointm;
5946 Lisp_Object pixel_left, pixel_top, pixel_height, pixel_width;
5423 Lisp_Object left_col, top_line, total_cols, total_lines; 5947 Lisp_Object left_col, top_line, total_cols, total_lines;
5424 Lisp_Object normal_cols, normal_lines; 5948 Lisp_Object normal_cols, normal_lines;
5425 Lisp_Object hscroll, min_hscroll; 5949 Lisp_Object hscroll, min_hscroll, hscroll_whole, suspend_auto_hscroll;
5426 Lisp_Object parent, prev; 5950 Lisp_Object parent, prev;
5427 Lisp_Object start_at_line_beg; 5951 Lisp_Object start_at_line_beg;
5428 Lisp_Object display_table; 5952 Lisp_Object display_table;
5429 Lisp_Object left_margin_cols, right_margin_cols; 5953 Lisp_Object left_margin_cols, right_margin_cols;
5430 Lisp_Object left_fringe_width, right_fringe_width, fringes_outside_margins; 5954 Lisp_Object left_fringe_width, right_fringe_width, fringes_outside_margins;
5431 Lisp_Object scroll_bar_width, vertical_scroll_bar_type, dedicated; 5955 Lisp_Object scroll_bar_width, vertical_scroll_bar_type, dedicated;
5956 Lisp_Object scroll_bar_height, horizontal_scroll_bar_type;
5432 Lisp_Object combination_limit, window_parameters; 5957 Lisp_Object combination_limit, window_parameters;
5433}; 5958};
5434 5959
@@ -5472,6 +5997,7 @@ the return value is nil. Otherwise the value is t. */)
5472 Lisp_Object frame; 5997 Lisp_Object frame;
5473 struct frame *f; 5998 struct frame *f;
5474 ptrdiff_t old_point = -1; 5999 ptrdiff_t old_point = -1;
6000 USE_SAFE_ALLOCA;
5475 6001
5476 CHECK_WINDOW_CONFIGURATION (configuration); 6002 CHECK_WINDOW_CONFIGURATION (configuration);
5477 6003
@@ -5527,23 +6053,12 @@ the return value is nil. Otherwise the value is t. */)
5527 { 6053 {
5528 Lisp_Object window; 6054 Lisp_Object window;
5529 Lisp_Object dead_windows = Qnil; 6055 Lisp_Object dead_windows = Qnil;
5530 register Lisp_Object tem, par, pers; 6056 Lisp_Object tem, par, pers;
5531 register struct window *w; 6057 struct window *w;
5532 register struct saved_window *p; 6058 struct saved_window *p;
5533 struct window *root_window; 6059 struct window *root_window;
5534 struct window **leaf_windows; 6060 struct window **leaf_windows;
5535 int n_leaf_windows; 6061 ptrdiff_t i, k, n_leaf_windows;
5536 ptrdiff_t k;
5537 int i, n;
5538
5539 /* If the frame has been resized since this window configuration was
5540 made, we change the frame to the size specified in the
5541 configuration, restore the configuration, and then resize it
5542 back. We keep track of the prevailing height in these variables. */
5543 int previous_frame_lines = FRAME_LINES (f);
5544 int previous_frame_cols = FRAME_COLS (f);
5545 int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
5546 int previous_frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f);
5547 6062
5548 /* Don't do this within the main loop below: This may call Lisp 6063 /* Don't do this within the main loop below: This may call Lisp
5549 code and is thus potentially unsafe while input is blocked. */ 6064 code and is thus potentially unsafe while input is blocked. */
@@ -5560,27 +6075,12 @@ the return value is nil. Otherwise the value is t. */)
5560 call1 (Qrecord_window_buffer, window); 6075 call1 (Qrecord_window_buffer, window);
5561 } 6076 }
5562 6077
6078 /* Disallow x_set_window_size, temporarily. */
6079 f->can_x_set_window_size = false;
5563 /* The mouse highlighting code could get screwed up 6080 /* The mouse highlighting code could get screwed up
5564 if it runs during this. */ 6081 if it runs during this. */
5565 block_input (); 6082 block_input ();
5566 6083
5567 if (data->frame_lines != previous_frame_lines
5568 || data->frame_cols != previous_frame_cols)
5569 change_frame_size (f, data->frame_lines,
5570 data->frame_cols, 0, 0, 0);
5571#if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5572 if (data->frame_menu_bar_lines
5573 != previous_frame_menu_bar_lines)
5574 x_set_menu_bar_lines (f, make_number (data->frame_menu_bar_lines),
5575 make_number (0));
5576#ifdef HAVE_WINDOW_SYSTEM
5577 if (data->frame_tool_bar_lines
5578 != previous_frame_tool_bar_lines)
5579 x_set_tool_bar_lines (f, make_number (data->frame_tool_bar_lines),
5580 make_number (0));
5581#endif
5582#endif
5583
5584 /* "Swap out" point from the selected window's buffer 6084 /* "Swap out" point from the selected window's buffer
5585 into the window itself. (Normally the pointm of the selected 6085 into the window itself. (Normally the pointm of the selected
5586 window holds garbage.) We do this now, before 6086 window holds garbage.) We do this now, before
@@ -5595,16 +6095,16 @@ the return value is nil. Otherwise the value is t. */)
5595 BUF_PT_BYTE (XBUFFER (w->contents))); 6095 BUF_PT_BYTE (XBUFFER (w->contents)));
5596 } 6096 }
5597 6097
5598 windows_or_buffers_changed++; 6098 fset_redisplay (f);
5599 FRAME_WINDOW_SIZES_CHANGED (f) = 1; 6099 FRAME_WINDOW_SIZES_CHANGED (f) = true;
5600 6100
5601 /* Problem: Freeing all matrices and later allocating them again 6101 /* Problem: Freeing all matrices and later allocating them again
5602 is a serious redisplay flickering problem. What we would 6102 is a serious redisplay flickering problem. What we would
5603 really like to do is to free only those matrices not reused 6103 really like to do is to free only those matrices not reused
5604 below. */ 6104 below. */
5605 root_window = XWINDOW (FRAME_ROOT_WINDOW (f)); 6105 root_window = XWINDOW (FRAME_ROOT_WINDOW (f));
5606 leaf_windows = alloca (count_windows (root_window) 6106 ptrdiff_t nwindows = count_windows (root_window);
5607 * sizeof *leaf_windows); 6107 SAFE_NALLOCA (leaf_windows, 1, nwindows);
5608 n_leaf_windows = get_leaf_windows (root_window, leaf_windows, 0); 6108 n_leaf_windows = get_leaf_windows (root_window, leaf_windows, 0);
5609 6109
5610 /* Kludge Alert! 6110 /* Kludge Alert!
@@ -5648,6 +6148,10 @@ the return value is nil. Otherwise the value is t. */)
5648 /* If we squirreled away the buffer, restore it now. */ 6148 /* If we squirreled away the buffer, restore it now. */
5649 if (BUFFERP (w->combination_limit)) 6149 if (BUFFERP (w->combination_limit))
5650 wset_buffer (w, w->combination_limit); 6150 wset_buffer (w, w->combination_limit);
6151 w->pixel_left = XFASTINT (p->pixel_left);
6152 w->pixel_top = XFASTINT (p->pixel_top);
6153 w->pixel_width = XFASTINT (p->pixel_width);
6154 w->pixel_height = XFASTINT (p->pixel_height);
5651 w->left_col = XFASTINT (p->left_col); 6155 w->left_col = XFASTINT (p->left_col);
5652 w->top_line = XFASTINT (p->top_line); 6156 w->top_line = XFASTINT (p->top_line);
5653 w->total_cols = XFASTINT (p->total_cols); 6157 w->total_cols = XFASTINT (p->total_cols);
@@ -5655,7 +6159,9 @@ the return value is nil. Otherwise the value is t. */)
5655 wset_normal_cols (w, p->normal_cols); 6159 wset_normal_cols (w, p->normal_cols);
5656 wset_normal_lines (w, p->normal_lines); 6160 wset_normal_lines (w, p->normal_lines);
5657 w->hscroll = XFASTINT (p->hscroll); 6161 w->hscroll = XFASTINT (p->hscroll);
6162 w->suspend_auto_hscroll = !NILP (p->suspend_auto_hscroll);
5658 w->min_hscroll = XFASTINT (p->min_hscroll); 6163 w->min_hscroll = XFASTINT (p->min_hscroll);
6164 w->hscroll_whole = XFASTINT (p->hscroll_whole);
5659 wset_display_table (w, p->display_table); 6165 wset_display_table (w, p->display_table);
5660 w->left_margin_cols = XINT (p->left_margin_cols); 6166 w->left_margin_cols = XINT (p->left_margin_cols);
5661 w->right_margin_cols = XINT (p->right_margin_cols); 6167 w->right_margin_cols = XINT (p->right_margin_cols);
@@ -5663,7 +6169,9 @@ the return value is nil. Otherwise the value is t. */)
5663 w->right_fringe_width = XINT (p->right_fringe_width); 6169 w->right_fringe_width = XINT (p->right_fringe_width);
5664 w->fringes_outside_margins = !NILP (p->fringes_outside_margins); 6170 w->fringes_outside_margins = !NILP (p->fringes_outside_margins);
5665 w->scroll_bar_width = XINT (p->scroll_bar_width); 6171 w->scroll_bar_width = XINT (p->scroll_bar_width);
6172 w->scroll_bar_height = XINT (p->scroll_bar_height);
5666 wset_vertical_scroll_bar_type (w, p->vertical_scroll_bar_type); 6173 wset_vertical_scroll_bar_type (w, p->vertical_scroll_bar_type);
6174 wset_horizontal_scroll_bar_type (w, p->horizontal_scroll_bar_type);
5667 wset_dedicated (w, p->dedicated); 6175 wset_dedicated (w, p->dedicated);
5668 wset_combination_limit (w, p->combination_limit); 6176 wset_combination_limit (w, p->combination_limit);
5669 /* Restore any window parameters that have been saved. 6177 /* Restore any window parameters that have been saved.
@@ -5694,18 +6202,15 @@ the return value is nil. Otherwise the value is t. */)
5694 wset_buffer (w, p->buffer); 6202 wset_buffer (w, p->buffer);
5695 w->start_at_line_beg = !NILP (p->start_at_line_beg); 6203 w->start_at_line_beg = !NILP (p->start_at_line_beg);
5696 set_marker_restricted (w->start, p->start, w->contents); 6204 set_marker_restricted (w->start, p->start, w->contents);
5697 set_marker_restricted (w->pointm, p->pointm, 6205 set_marker_restricted (w->pointm, p->pointm, w->contents);
5698 w->contents); 6206 set_marker_restricted (w->old_pointm, p->old_pointm, w->contents);
5699 Fset_marker (BVAR (XBUFFER (w->contents), mark),
5700 p->mark, w->contents);
5701
5702 /* As documented in Fcurrent_window_configuration, don't 6207 /* As documented in Fcurrent_window_configuration, don't
5703 restore the location of point in the buffer which was 6208 restore the location of point in the buffer which was
5704 current when the window configuration was recorded. */ 6209 current when the window configuration was recorded. */
5705 if (!EQ (p->buffer, new_current_buffer) 6210 if (!EQ (p->buffer, new_current_buffer)
5706 && XBUFFER (p->buffer) == current_buffer) 6211 && XBUFFER (p->buffer) == current_buffer)
5707 Fgoto_char (w->pointm); 6212 Fgoto_char (w->pointm);
5708 } 6213 }
5709 else if (BUFFERP (w->contents) && BUFFER_LIVE_P (XBUFFER (w->contents))) 6214 else if (BUFFERP (w->contents) && BUFFER_LIVE_P (XBUFFER (w->contents)))
5710 /* Keep window's old buffer; make sure the markers are real. */ 6215 /* Keep window's old buffer; make sure the markers are real. */
5711 { 6216 {
@@ -5717,21 +6222,27 @@ the return value is nil. Otherwise the value is t. */)
5717 (w->pointm, w->contents, 6222 (w->pointm, w->contents,
5718 BUF_PT (XBUFFER (w->contents)), 6223 BUF_PT (XBUFFER (w->contents)),
5719 BUF_PT_BYTE (XBUFFER (w->contents))); 6224 BUF_PT_BYTE (XBUFFER (w->contents)));
5720 w->start_at_line_beg = 1; 6225 if (XMARKER (w->old_pointm)->buffer == 0)
6226 set_marker_restricted_both
6227 (w->old_pointm, w->contents,
6228 BUF_PT (XBUFFER (w->contents)),
6229 BUF_PT_BYTE (XBUFFER (w->contents)));
6230 w->start_at_line_beg = true;
5721 } 6231 }
5722 else if (!NILP (w->start)) 6232 else if (!NILP (w->start))
5723 /* Leaf window has no live buffer, get one. */ 6233 /* Leaf window has no live buffer, get one. */
5724 { 6234 {
5725 /* Get the buffer via other_buffer_safely in order to 6235 /* Get the buffer via other_buffer_safely in order to
5726 avoid showing an unimportant buffer and, if necessary, to 6236 avoid showing an unimportant buffer and, if necessary, to
5727 recreate *scratch* in the course (part of Juanma's bs-show 6237 recreate *scratch* in the course (part of Juanma's bs-show
5728 scenario from March 2011). */ 6238 scenario from March 2011). */
5729 wset_buffer (w, other_buffer_safely (Fcurrent_buffer ())); 6239 wset_buffer (w, other_buffer_safely (Fcurrent_buffer ()));
5730 /* This will set the markers to beginning of visible 6240 /* This will set the markers to beginning of visible
5731 range. */ 6241 range. */
5732 set_marker_restricted_both (w->start, w->contents, 0, 0); 6242 set_marker_restricted_both (w->start, w->contents, 0, 0);
5733 set_marker_restricted_both (w->pointm, w->contents, 0, 0); 6243 set_marker_restricted_both (w->pointm, w->contents, 0, 0);
5734 w->start_at_line_beg = 1; 6244 set_marker_restricted_both (w->old_pointm, w->contents, 0, 0);
6245 w->start_at_line_beg = true;
5735 if (!NILP (w->dedicated)) 6246 if (!NILP (w->dedicated))
5736 /* Record this window as dead. */ 6247 /* Record this window as dead. */
5737 dead_windows = Fcons (window, dead_windows); 6248 dead_windows = Fcons (window, dead_windows);
@@ -5751,9 +6262,13 @@ the return value is nil. Otherwise the value is t. */)
5751 /* In the following call to `select-window', prevent "swapping out 6262 /* In the following call to `select-window', prevent "swapping out
5752 point" in the old selected window using the buffer that has 6263 point" in the old selected window using the buffer that has
5753 been restored into it. We already swapped out that point from 6264 been restored into it. We already swapped out that point from
5754 that window's old buffer. */ 6265 that window's old buffer.
5755 select_window (data->current_window, Qnil, 1); 6266
5756 BVAR (XBUFFER (XWINDOW (selected_window)->contents), last_selected_window) 6267 Do not record the buffer here. We do that in a separate call
6268 to select_window below. See also Bug#16207. */
6269 select_window (data->current_window, Qt, true);
6270 BVAR (XBUFFER (XWINDOW (selected_window)->contents),
6271 last_selected_window)
5757 = selected_window; 6272 = selected_window;
5758 6273
5759 if (NILP (data->focus_frame) 6274 if (NILP (data->focus_frame)
@@ -5761,32 +6276,17 @@ the return value is nil. Otherwise the value is t. */)
5761 && FRAME_LIVE_P (XFRAME (data->focus_frame)))) 6276 && FRAME_LIVE_P (XFRAME (data->focus_frame))))
5762 Fredirect_frame_focus (frame, data->focus_frame); 6277 Fredirect_frame_focus (frame, data->focus_frame);
5763 6278
5764 /* Set the screen height to the value it had before this function. */
5765 if (previous_frame_lines != FRAME_LINES (f)
5766 || previous_frame_cols != FRAME_COLS (f))
5767 change_frame_size (f, previous_frame_lines, previous_frame_cols,
5768 0, 0, 0);
5769#if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5770 if (previous_frame_menu_bar_lines != FRAME_MENU_BAR_LINES (f))
5771 x_set_menu_bar_lines (f, make_number (previous_frame_menu_bar_lines),
5772 make_number (0));
5773#ifdef HAVE_WINDOW_SYSTEM
5774 if (previous_frame_tool_bar_lines != FRAME_TOOL_BAR_LINES (f))
5775 x_set_tool_bar_lines (f, make_number (previous_frame_tool_bar_lines),
5776 make_number (0));
5777#endif
5778#endif
5779
5780 /* Now, free glyph matrices in windows that were not reused. */ 6279 /* Now, free glyph matrices in windows that were not reused. */
5781 for (i = n = 0; i < n_leaf_windows; ++i) 6280 for (i = 0; i < n_leaf_windows; i++)
5782 { 6281 if (NILP (leaf_windows[i]->contents))
5783 if (NILP (leaf_windows[i]->contents)) 6282 free_window_matrices (leaf_windows[i]);
5784 free_window_matrices (leaf_windows[i]); 6283
5785 else if (EQ (leaf_windows[i]->contents, new_current_buffer)) 6284 /* Allow x_set_window_size again and apply frame size changes if
5786 ++n; 6285 needed. */
5787 } 6286 f->can_x_set_window_size = true;
6287 adjust_frame_size (f, -1, -1, 1, false, Qset_window_configuration);
5788 6288
5789 adjust_glyphs (f); 6289 adjust_frame_glyphs (f);
5790 unblock_input (); 6290 unblock_input ();
5791 6291
5792 /* Scan dead buffer windows. */ 6292 /* Scan dead buffer windows. */
@@ -5797,6 +6297,10 @@ the return value is nil. Otherwise the value is t. */)
5797 delete_deletable_window (window); 6297 delete_deletable_window (window);
5798 } 6298 }
5799 6299
6300 /* Record the selected window's buffer here. The window should
6301 already be the selected one from the call above. */
6302 select_window (data->current_window, Qnil, false);
6303
5800 /* Fselect_window will have made f the selected frame, so we 6304 /* Fselect_window will have made f the selected frame, so we
5801 reselect the proper frame here. Fhandle_switch_frame will change the 6305 reselect the proper frame here. Fhandle_switch_frame will change the
5802 selected window too, but that doesn't make the call to 6306 selected window too, but that doesn't make the call to
@@ -5820,9 +6324,11 @@ the return value is nil. Otherwise the value is t. */)
5820 Vminibuf_scroll_window = data->minibuf_scroll_window; 6324 Vminibuf_scroll_window = data->minibuf_scroll_window;
5821 minibuf_selected_window = data->minibuf_selected_window; 6325 minibuf_selected_window = data->minibuf_selected_window;
5822 6326
6327 SAFE_FREE ();
5823 return (FRAME_LIVE_P (f) ? Qt : Qnil); 6328 return (FRAME_LIVE_P (f) ? Qt : Qnil);
5824} 6329}
5825 6330
6331
5826void 6332void
5827restore_window_configuration (Lisp_Object configuration) 6333restore_window_configuration (Lisp_Object configuration)
5828{ 6334{
@@ -5848,12 +6354,13 @@ delete_all_child_windows (Lisp_Object window)
5848 if (WINDOWP (w->contents)) 6354 if (WINDOWP (w->contents))
5849 { 6355 {
5850 delete_all_child_windows (w->contents); 6356 delete_all_child_windows (w->contents);
5851 wset_combination (w, 0, Qnil); 6357 wset_combination (w, false, Qnil);
5852 } 6358 }
5853 else if (BUFFERP (w->contents)) 6359 else if (BUFFERP (w->contents))
5854 { 6360 {
5855 unshow_buffer (w); 6361 unshow_buffer (w);
5856 unchain_marker (XMARKER (w->pointm)); 6362 unchain_marker (XMARKER (w->pointm));
6363 unchain_marker (XMARKER (w->old_pointm));
5857 unchain_marker (XMARKER (w->start)); 6364 unchain_marker (XMARKER (w->start));
5858 /* Since combination limit makes sense for an internal windows 6365 /* Since combination limit makes sense for an internal windows
5859 only, we use this slot to save the buffer for the sake of 6366 only, we use this slot to save the buffer for the sake of
@@ -5865,10 +6372,10 @@ delete_all_child_windows (Lisp_Object window)
5865 Vwindow_list = Qnil; 6372 Vwindow_list = Qnil;
5866} 6373}
5867 6374
5868static int 6375static ptrdiff_t
5869count_windows (register struct window *window) 6376count_windows (struct window *window)
5870{ 6377{
5871 register int count = 1; 6378 ptrdiff_t count = 1;
5872 if (!NILP (window->next)) 6379 if (!NILP (window->next))
5873 count += count_windows (XWINDOW (window->next)); 6380 count += count_windows (XWINDOW (window->next));
5874 if (WINDOWP (window->contents)) 6381 if (WINDOWP (window->contents))
@@ -5879,8 +6386,8 @@ count_windows (register struct window *window)
5879 6386
5880/* Fill vector FLAT with leaf windows under W, starting at index I. 6387/* Fill vector FLAT with leaf windows under W, starting at index I.
5881 Value is last index + 1. */ 6388 Value is last index + 1. */
5882static int 6389static ptrdiff_t
5883get_leaf_windows (struct window *w, struct window **flat, int i) 6390get_leaf_windows (struct window *w, struct window **flat, ptrdiff_t i)
5884{ 6391{
5885 while (w) 6392 while (w)
5886 { 6393 {
@@ -5934,12 +6441,12 @@ get_phys_cursor_glyph (struct window *w)
5934} 6441}
5935 6442
5936 6443
5937static int 6444static ptrdiff_t
5938save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i) 6445save_window_save (Lisp_Object window, struct Lisp_Vector *vector, ptrdiff_t i)
5939{ 6446{
5940 register struct saved_window *p; 6447 struct saved_window *p;
5941 register struct window *w; 6448 struct window *w;
5942 register Lisp_Object tem, pers, par; 6449 Lisp_Object tem, pers, par;
5943 6450
5944 for (; !NILP (window); window = w->next) 6451 for (; !NILP (window); window = w->next)
5945 { 6452 {
@@ -5949,6 +6456,10 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
5949 wset_temslot (w, make_number (i)); i++; 6456 wset_temslot (w, make_number (i)); i++;
5950 p->window = window; 6457 p->window = window;
5951 p->buffer = (WINDOW_LEAF_P (w) ? w->contents : Qnil); 6458 p->buffer = (WINDOW_LEAF_P (w) ? w->contents : Qnil);
6459 p->pixel_left = make_number (w->pixel_left);
6460 p->pixel_top = make_number (w->pixel_top);
6461 p->pixel_width = make_number (w->pixel_width);
6462 p->pixel_height = make_number (w->pixel_height);
5952 p->left_col = make_number (w->left_col); 6463 p->left_col = make_number (w->left_col);
5953 p->top_line = make_number (w->top_line); 6464 p->top_line = make_number (w->top_line);
5954 p->total_cols = make_number (w->total_cols); 6465 p->total_cols = make_number (w->total_cols);
@@ -5956,7 +6467,9 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
5956 p->normal_cols = w->normal_cols; 6467 p->normal_cols = w->normal_cols;
5957 p->normal_lines = w->normal_lines; 6468 p->normal_lines = w->normal_lines;
5958 XSETFASTINT (p->hscroll, w->hscroll); 6469 XSETFASTINT (p->hscroll, w->hscroll);
6470 p->suspend_auto_hscroll = w->suspend_auto_hscroll ? Qt : Qnil;
5959 XSETFASTINT (p->min_hscroll, w->min_hscroll); 6471 XSETFASTINT (p->min_hscroll, w->min_hscroll);
6472 XSETFASTINT (p->hscroll_whole, w->hscroll_whole);
5960 p->display_table = w->display_table; 6473 p->display_table = w->display_table;
5961 p->left_margin_cols = make_number (w->left_margin_cols); 6474 p->left_margin_cols = make_number (w->left_margin_cols);
5962 p->right_margin_cols = make_number (w->right_margin_cols); 6475 p->right_margin_cols = make_number (w->right_margin_cols);
@@ -5964,7 +6477,9 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
5964 p->right_fringe_width = make_number (w->right_fringe_width); 6477 p->right_fringe_width = make_number (w->right_fringe_width);
5965 p->fringes_outside_margins = w->fringes_outside_margins ? Qt : Qnil; 6478 p->fringes_outside_margins = w->fringes_outside_margins ? Qt : Qnil;
5966 p->scroll_bar_width = make_number (w->scroll_bar_width); 6479 p->scroll_bar_width = make_number (w->scroll_bar_width);
6480 p->scroll_bar_height = make_number (w->scroll_bar_height);
5967 p->vertical_scroll_bar_type = w->vertical_scroll_bar_type; 6481 p->vertical_scroll_bar_type = w->vertical_scroll_bar_type;
6482 p->horizontal_scroll_bar_type = w->horizontal_scroll_bar_type;
5968 p->dedicated = w->dedicated; 6483 p->dedicated = w->dedicated;
5969 p->combination_limit = w->combination_limit; 6484 p->combination_limit = w->combination_limit;
5970 p->window_parameters = Qnil; 6485 p->window_parameters = Qnil;
@@ -6026,32 +6541,27 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
6026 BUF_PT_BYTE (XBUFFER (w->contents))); 6541 BUF_PT_BYTE (XBUFFER (w->contents)));
6027 else 6542 else
6028 p->pointm = Fcopy_marker (w->pointm, Qnil); 6543 p->pointm = Fcopy_marker (w->pointm, Qnil);
6544 p->old_pointm = Fcopy_marker (w->old_pointm, Qnil);
6029 XMARKER (p->pointm)->insertion_type 6545 XMARKER (p->pointm)->insertion_type
6030 = !NILP (Vwindow_point_insertion_type); 6546 = !NILP (buffer_local_value /* Don't signal error if void. */
6547 (Qwindow_point_insertion_type, w->contents));
6548 XMARKER (p->old_pointm)->insertion_type
6549 = !NILP (buffer_local_value /* Don't signal error if void. */
6550 (Qwindow_point_insertion_type, w->contents));
6031 6551
6032 p->start = Fcopy_marker (w->start, Qnil); 6552 p->start = Fcopy_marker (w->start, Qnil);
6033 p->start_at_line_beg = w->start_at_line_beg ? Qt : Qnil; 6553 p->start_at_line_beg = w->start_at_line_beg ? Qt : Qnil;
6034
6035 tem = BVAR (XBUFFER (w->contents), mark);
6036 p->mark = Fcopy_marker (tem, Qnil);
6037 } 6554 }
6038 else 6555 else
6039 { 6556 {
6040 p->pointm = Qnil; 6557 p->pointm = Qnil;
6558 p->old_pointm = Qnil;
6041 p->start = Qnil; 6559 p->start = Qnil;
6042 p->mark = Qnil;
6043 p->start_at_line_beg = Qnil; 6560 p->start_at_line_beg = Qnil;
6044 } 6561 }
6045 6562
6046 if (NILP (w->parent)) 6563 p->parent = NILP (w->parent) ? Qnil : XWINDOW (w->parent)->temslot;
6047 p->parent = Qnil; 6564 p->prev = NILP (w->prev) ? Qnil : XWINDOW (w->prev)->temslot;
6048 else
6049 p->parent = XWINDOW (w->parent)->temslot;
6050
6051 if (NILP (w->prev))
6052 p->prev = Qnil;
6053 else
6054 p->prev = XWINDOW (w->prev)->temslot;
6055 6565
6056 if (WINDOWP (w->contents)) 6566 if (WINDOWP (w->contents))
6057 i = save_window_save (w->contents, vector, i); 6567 i = save_window_save (w->contents, vector, i);
@@ -6065,8 +6575,8 @@ DEFUN ("current-window-configuration", Fcurrent_window_configuration,
6065 doc: /* Return an object representing the current window configuration of FRAME. 6575 doc: /* Return an object representing the current window configuration of FRAME.
6066If FRAME is nil or omitted, use the selected frame. 6576If FRAME is nil or omitted, use the selected frame.
6067This describes the number of windows, their sizes and current buffers, 6577This describes the number of windows, their sizes and current buffers,
6068and for each displayed buffer, where display starts, and the positions of 6578and for each displayed buffer, where display starts, and the position of
6069point and mark. An exception is made for point in the current buffer: 6579point. An exception is made for point in the current buffer:
6070its value is -not- saved. 6580its value is -not- saved.
6071This also records the currently selected frame, and FRAME's focus 6581This also records the currently selected frame, and FRAME's focus
6072redirection (see `redirect-frame-focus'). The variable 6582redirection (see `redirect-frame-focus'). The variable
@@ -6074,10 +6584,9 @@ redirection (see `redirect-frame-focus'). The variable
6074saved by this function. */) 6584saved by this function. */)
6075 (Lisp_Object frame) 6585 (Lisp_Object frame)
6076{ 6586{
6077 register Lisp_Object tem; 6587 Lisp_Object tem;
6078 register int n_windows; 6588 ptrdiff_t i, n_windows;
6079 register struct save_window_data *data; 6589 struct save_window_data *data;
6080 register int i;
6081 struct frame *f = decode_live_frame (frame); 6590 struct frame *f = decode_live_frame (frame);
6082 6591
6083 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f))); 6592 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
@@ -6088,6 +6597,10 @@ saved by this function. */)
6088 data->frame_lines = FRAME_LINES (f); 6597 data->frame_lines = FRAME_LINES (f);
6089 data->frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f); 6598 data->frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
6090 data->frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f); 6599 data->frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f);
6600 data->frame_text_width = FRAME_TEXT_WIDTH (f);
6601 data->frame_text_height = FRAME_TEXT_HEIGHT (f);
6602 data->frame_menu_bar_height = FRAME_MENU_BAR_HEIGHT (f);
6603 data->frame_tool_bar_height = FRAME_TOOL_BAR_HEIGHT (f);
6091 data->selected_frame = selected_frame; 6604 data->selected_frame = selected_frame;
6092 data->current_window = FRAME_SELECTED_WINDOW (f); 6605 data->current_window = FRAME_SELECTED_WINDOW (f);
6093 XSETBUFFER (data->f_current_buffer, current_buffer); 6606 XSETBUFFER (data->f_current_buffer, current_buffer);
@@ -6111,11 +6624,10 @@ static void
6111apply_window_adjustment (struct window *w) 6624apply_window_adjustment (struct window *w)
6112{ 6625{
6113 eassert (w); 6626 eassert (w);
6114 adjust_window_margins (w);
6115 clear_glyph_matrix (w->current_matrix); 6627 clear_glyph_matrix (w->current_matrix);
6116 w->window_end_valid = 0; 6628 w->window_end_valid = false;
6117 windows_or_buffers_changed++; 6629 wset_redisplay (w);
6118 adjust_glyphs (XFRAME (WINDOW_FRAME (w))); 6630 adjust_frame_glyphs (XFRAME (WINDOW_FRAME (w)));
6119} 6631}
6120 6632
6121 6633
@@ -6123,25 +6635,42 @@ apply_window_adjustment (struct window *w)
6123 Marginal Areas 6635 Marginal Areas
6124 ***********************************************************************/ 6636 ***********************************************************************/
6125 6637
6638static int
6639extract_dimension (Lisp_Object dimension)
6640{
6641 if (NILP (dimension))
6642 return -1;
6643 CHECK_RANGED_INTEGER (dimension, 0, INT_MAX);
6644 return XINT (dimension);
6645}
6646
6126static struct window * 6647static struct window *
6127set_window_margins (struct window *w, Lisp_Object left_width, 6648set_window_margins (struct window *w, Lisp_Object left_width,
6128 Lisp_Object right_width) 6649 Lisp_Object right_width)
6129{ 6650{
6130 int left, right; 6651 int unit = WINDOW_FRAME_COLUMN_WIDTH (w);
6131 6652 int left = NILP (left_width) ? 0 : extract_dimension (left_width);
6132 /* FIXME: what about margins that are too wide? */ 6653 int right = NILP (right_width) ? 0 : extract_dimension (right_width);
6133 left = (NILP (left_width) ? 0
6134 : (CHECK_NATNUM (left_width), XINT (left_width)));
6135 right = (NILP (right_width) ? 0
6136 : (CHECK_NATNUM (right_width), XINT (right_width)));
6137 6654
6138 if (w->left_margin_cols != left || w->right_margin_cols != right) 6655 if (w->left_margin_cols != left || w->right_margin_cols != right)
6139 { 6656 {
6140 w->left_margin_cols = left; 6657 /* Don't change anything if new margins won't fit. */
6141 w->right_margin_cols = right; 6658 if ((WINDOW_PIXEL_WIDTH (w)
6142 return w; 6659 - WINDOW_FRINGES_WIDTH (w)
6660 - WINDOW_SCROLL_BAR_AREA_WIDTH (w)
6661 - (left + right) * unit)
6662 >= MIN_SAFE_WINDOW_PIXEL_WIDTH (w))
6663 {
6664 w->left_margin_cols = left;
6665 w->right_margin_cols = right;
6666
6667 return w;
6668 }
6669 else
6670 return NULL;
6143 } 6671 }
6144 return NULL; 6672 else
6673 return NULL;
6145} 6674}
6146 6675
6147DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins, 6676DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins,
@@ -6174,8 +6703,10 @@ as nil. */)
6174 (Lisp_Object window) 6703 (Lisp_Object window)
6175{ 6704{
6176 struct window *w = decode_live_window (window); 6705 struct window *w = decode_live_window (window);
6177 return Fcons (w->left_margin_cols ? make_number (w->left_margin_cols) : Qnil, 6706 return Fcons (w->left_margin_cols
6178 w->right_margin_cols ? make_number (w->right_margin_cols) : Qnil); 6707 ? make_number (w->left_margin_cols) : Qnil,
6708 w->right_margin_cols
6709 ? make_number (w->right_margin_cols) : Qnil);
6179} 6710}
6180 6711
6181 6712
@@ -6188,12 +6719,9 @@ static struct window *
6188set_window_fringes (struct window *w, Lisp_Object left_width, 6719set_window_fringes (struct window *w, Lisp_Object left_width,
6189 Lisp_Object right_width, Lisp_Object outside_margins) 6720 Lisp_Object right_width, Lisp_Object outside_margins)
6190{ 6721{
6191 int left, right, outside = !NILP (outside_margins); 6722 bool outside = !NILP (outside_margins);
6192 6723 int left = extract_dimension (left_width);
6193 left = (NILP (left_width) ? -1 6724 int right = extract_dimension (right_width);
6194 : (CHECK_NATNUM (left_width), XINT (left_width)));
6195 right = (NILP (right_width) ? -1
6196 : (CHECK_NATNUM (right_width), XINT (right_width)));
6197 6725
6198 /* Do nothing on a tty or if nothing to actually change. */ 6726 /* Do nothing on a tty or if nothing to actually change. */
6199 if (FRAME_WINDOW_P (WINDOW_XFRAME (w)) 6727 if (FRAME_WINDOW_P (WINDOW_XFRAME (w))
@@ -6201,12 +6729,25 @@ set_window_fringes (struct window *w, Lisp_Object left_width,
6201 || w->right_fringe_width != right 6729 || w->right_fringe_width != right
6202 || w->fringes_outside_margins != outside)) 6730 || w->fringes_outside_margins != outside))
6203 { 6731 {
6732 if (left > 0 || right > 0)
6733 {
6734 /* Don't change anything if new fringes don't fit. */
6735 if ((WINDOW_PIXEL_WIDTH (w)
6736 - WINDOW_MARGINS_WIDTH (w)
6737 - WINDOW_SCROLL_BAR_AREA_WIDTH (w)
6738 - max (left, 0) - max (right, 0))
6739 < MIN_SAFE_WINDOW_PIXEL_WIDTH (w))
6740 return NULL;
6741 }
6742
6204 w->left_fringe_width = left; 6743 w->left_fringe_width = left;
6205 w->right_fringe_width = right; 6744 w->right_fringe_width = right;
6206 w->fringes_outside_margins = outside; 6745 w->fringes_outside_margins = outside;
6746
6207 return w; 6747 return w;
6208 } 6748 }
6209 return NULL; 6749 else
6750 return NULL;
6210} 6751}
6211 6752
6212DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes, 6753DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes,
@@ -6257,9 +6798,11 @@ Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6257 6798
6258static struct window * 6799static struct window *
6259set_window_scroll_bars (struct window *w, Lisp_Object width, 6800set_window_scroll_bars (struct window *w, Lisp_Object width,
6260 Lisp_Object vertical_type, Lisp_Object horizontal_type) 6801 Lisp_Object vertical_type, Lisp_Object height,
6802 Lisp_Object horizontal_type)
6261{ 6803{
6262 int iwidth = (NILP (width) ? -1 : (CHECK_NATNUM (width), XINT (width))); 6804 int iwidth = extract_dimension (width);
6805 bool changed = false;
6263 6806
6264 if (iwidth == 0) 6807 if (iwidth == 0)
6265 vertical_type = Qnil; 6808 vertical_type = Qnil;
@@ -6273,33 +6816,78 @@ set_window_scroll_bars (struct window *w, Lisp_Object width,
6273 if (w->scroll_bar_width != iwidth 6816 if (w->scroll_bar_width != iwidth
6274 || !EQ (w->vertical_scroll_bar_type, vertical_type)) 6817 || !EQ (w->vertical_scroll_bar_type, vertical_type))
6275 { 6818 {
6276 w->scroll_bar_width = iwidth; 6819 /* Don't change anything if new scroll bar won't fit. */
6277 wset_vertical_scroll_bar_type (w, vertical_type); 6820 if ((WINDOW_PIXEL_WIDTH (w)
6278 return w; 6821 - WINDOW_MARGINS_WIDTH (w)
6822 - WINDOW_FRINGES_WIDTH (w)
6823 - max (iwidth, 0))
6824 >= MIN_SAFE_WINDOW_PIXEL_WIDTH (w))
6825 {
6826 w->scroll_bar_width = iwidth;
6827 wset_vertical_scroll_bar_type (w, vertical_type);
6828 changed = true;
6829 }
6279 } 6830 }
6280 return NULL; 6831
6832#if USE_HORIZONTAL_SCROLL_BARS
6833 {
6834 int iheight = extract_dimension (height);
6835
6836 if (MINI_WINDOW_P (w) || iheight == 0)
6837 horizontal_type = Qnil;
6838
6839 if (!(NILP (horizontal_type)
6840 || EQ (horizontal_type, Qbottom)
6841 || EQ (horizontal_type, Qt)))
6842 error ("Invalid type of horizontal scroll bar");
6843
6844 if (w->scroll_bar_height != iheight
6845 || !EQ (w->horizontal_scroll_bar_type, horizontal_type))
6846 {
6847 /* Don't change anything if new scroll bar won't fit. */
6848 if ((WINDOW_PIXEL_HEIGHT (w)
6849 - WINDOW_HEADER_LINE_HEIGHT (w)
6850 - WINDOW_MODE_LINE_HEIGHT (w)
6851 - max (iheight, 0))
6852 >= MIN_SAFE_WINDOW_PIXEL_HEIGHT (w))
6853 {
6854 w->scroll_bar_height = iheight;
6855 wset_horizontal_scroll_bar_type (w, horizontal_type);
6856 changed = true;
6857 }
6858 }
6859 }
6860#else
6861 wset_horizontal_scroll_bar_type (w, Qnil);
6862#endif
6863
6864 return changed ? w : NULL;
6281} 6865}
6282 6866
6283DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars, 6867DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars,
6284 Sset_window_scroll_bars, 2, 4, 0, 6868 Sset_window_scroll_bars, 1, 5, 0,
6285 doc: /* Set width and type of scroll bars of window WINDOW. 6869 doc: /* Set width and type of scroll bars of window WINDOW.
6286WINDOW must be a live window and defaults to the selected one. 6870WINDOW must be a live window and defaults to the selected one.
6287 6871
6288Second parameter WIDTH specifies the pixel width for the scroll bar; 6872Second parameter WIDTH specifies the pixel width for the vertical scroll
6289this is automatically adjusted to a multiple of the frame column width. 6873bar. If WIDTH is nil, use the scroll-bar width of WINDOW's frame.
6290Third parameter VERTICAL-TYPE specifies the type of the vertical scroll 6874Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6291bar: left, right, or nil. 6875bar: left, right, or nil. If VERTICAL-TYPE is t, this means use the
6292If WIDTH is nil, use the frame's scroll-bar width. 6876frame's scroll-bar type.
6293If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6294Fourth parameter HORIZONTAL-TYPE is currently unused.
6295 6877
6296Return t if scroll bars was actually changed and nil otherwise. */) 6878Fourth parameter HEIGHT specifies the pixel height for the horizontal
6297 (Lisp_Object window, Lisp_Object width, 6879scroll bar. If HEIGHT is nil, use the scroll-bar height of WINDOW's
6298 Lisp_Object vertical_type, Lisp_Object horizontal_type) 6880frame. Fifth parameter HORIZONTAL-TYPE specifies the type of the
6881horizontal scroll bar: nil, bottom, or t. If HORIZONTAL-TYPE is t, this
6882means to use the frame's horizontal scroll-bar type.
6883
6884Return t if scroll bars were actually changed and nil otherwise. */)
6885 (Lisp_Object window, Lisp_Object width, Lisp_Object vertical_type,
6886 Lisp_Object height, Lisp_Object horizontal_type)
6299{ 6887{
6300 struct window *w 6888 struct window *w
6301 = set_window_scroll_bars (decode_live_window (window), 6889 = set_window_scroll_bars (decode_live_window (window),
6302 width, vertical_type, horizontal_type); 6890 width, vertical_type, height, horizontal_type);
6303 return w ? (apply_window_adjustment (w), Qt) : Qnil; 6891 return w ? (apply_window_adjustment (w), Qt) : Qnil;
6304} 6892}
6305 6893
@@ -6309,21 +6897,25 @@ DEFUN ("window-scroll-bars", Fwindow_scroll_bars, Swindow_scroll_bars,
6309 doc: /* Get width and type of scroll bars of window WINDOW. 6897 doc: /* Get width and type of scroll bars of window WINDOW.
6310WINDOW must be a live window and defaults to the selected one. 6898WINDOW must be a live window and defaults to the selected one.
6311 6899
6312Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE). 6900Value is a list of the form (WIDTH COLUMNS VERTICAL-TYPE HEIGHT LINES
6313If WIDTH is nil or TYPE is t, the window is using the frame's corresponding 6901HORIZONTAL-TYPE). If WIDTH or HEIGHT is nil or VERTICAL-TYPE or
6902HORIZONTAL-TYPE is t, the window is using the frame's corresponding
6314value. */) 6903value. */)
6315 (Lisp_Object window) 6904 (Lisp_Object window)
6316{ 6905{
6317 struct window *w = decode_live_window (window); 6906 struct window *w = decode_live_window (window);
6318 6907
6319 return list4 (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w) 6908 return Fcons (((w->scroll_bar_width >= 0)
6320 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w) 6909 ? make_number (w->scroll_bar_width)
6321 : WINDOW_SCROLL_BAR_AREA_WIDTH (w))), 6910 : Qnil),
6322 make_number (WINDOW_SCROLL_BAR_COLS (w)), 6911 list5 (make_number (WINDOW_SCROLL_BAR_COLS (w)),
6323 w->vertical_scroll_bar_type, Qnil); 6912 w->vertical_scroll_bar_type,
6913 ((w->scroll_bar_height >= 0)
6914 ? make_number (w->scroll_bar_height)
6915 : Qnil),
6916 make_number (WINDOW_SCROLL_BAR_LINES (w)),
6917 w->horizontal_scroll_bar_type));
6324} 6918}
6325
6326
6327 6919
6328/*********************************************************************** 6920/***********************************************************************
6329 Smooth scrolling 6921 Smooth scrolling
@@ -6381,10 +6973,10 @@ If PIXELS-P is non-nil, the return value is VSCROLL. */)
6381 /* Adjust glyph matrix of the frame if the virtual display 6973 /* Adjust glyph matrix of the frame if the virtual display
6382 area becomes larger than before. */ 6974 area becomes larger than before. */
6383 if (w->vscroll < 0 && w->vscroll < old_dy) 6975 if (w->vscroll < 0 && w->vscroll < old_dy)
6384 adjust_glyphs (f); 6976 adjust_frame_glyphs (f);
6385 6977
6386 /* Prevent redisplay shortcuts. */ 6978 /* Prevent redisplay shortcuts. */
6387 XBUFFER (w->contents)->prevent_redisplay_optimizations_p = 1; 6979 XBUFFER (w->contents)->prevent_redisplay_optimizations_p = true;
6388 } 6980 }
6389 } 6981 }
6390 6982
@@ -6397,7 +6989,7 @@ If PIXELS-P is non-nil, the return value is VSCROLL. */)
6397 additional argument USER_DATA. Stops when FN returns 0. */ 6989 additional argument USER_DATA. Stops when FN returns 0. */
6398 6990
6399static void 6991static void
6400foreach_window (struct frame *f, int (*fn) (struct window *, void *), 6992foreach_window (struct frame *f, bool (*fn) (struct window *, void *),
6401 void *user_data) 6993 void *user_data)
6402{ 6994{
6403 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */ 6995 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
@@ -6409,14 +7001,15 @@ foreach_window (struct frame *f, int (*fn) (struct window *, void *),
6409/* Helper function for foreach_window. Call FN for all leaf windows 7001/* Helper function for foreach_window. Call FN for all leaf windows
6410 reachable from W. FN is called with the first argument being a 7002 reachable from W. FN is called with the first argument being a
6411 pointer to the leaf window, and with additional argument USER_DATA. 7003 pointer to the leaf window, and with additional argument USER_DATA.
6412 Stop when FN returns 0. Value is 0 if stopped by FN. */ 7004 Stop when FN returns false. Value is false if stopped by FN. */
6413 7005
6414static int 7006static bool
6415foreach_window_1 (struct window *w, int (*fn) (struct window *, void *), void *user_data) 7007foreach_window_1 (struct window *w, bool (*fn) (struct window *, void *),
7008 void *user_data)
6416{ 7009{
6417 int cont; 7010 bool cont;
6418 7011
6419 for (cont = 1; w && cont;) 7012 for (cont = true; w && cont;)
6420 { 7013 {
6421 if (WINDOWP (w->contents)) 7014 if (WINDOWP (w->contents))
6422 cont = foreach_window_1 (XWINDOW (w->contents), fn, user_data); 7015 cont = foreach_window_1 (XWINDOW (w->contents), fn, user_data);
@@ -6433,7 +7026,7 @@ foreach_window_1 (struct window *w, int (*fn) (struct window *, void *), void *u
6433 Initialization 7026 Initialization
6434 ***********************************************************************/ 7027 ***********************************************************************/
6435 7028
6436/* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2 7029/* Return true if window configurations CONFIGURATION1 and CONFIGURATION2
6437 describe the same state of affairs. This is used by Fequal. 7030 describe the same state of affairs. This is used by Fequal.
6438 7031
6439 IGNORE_POSITIONS means ignore non-matching scroll positions 7032 IGNORE_POSITIONS means ignore non-matching scroll positions
@@ -6472,7 +7065,7 @@ compare_window_configurations (Lisp_Object configuration1,
6472 || !EQ (d1->focus_frame, d2->focus_frame) 7065 || !EQ (d1->focus_frame, d2->focus_frame)
6473 /* Verify that the two configurations have the same number of windows. */ 7066 /* Verify that the two configurations have the same number of windows. */
6474 || sws1->header.size != sws2->header.size) 7067 || sws1->header.size != sws2->header.size)
6475 return 0; 7068 return false;
6476 7069
6477 for (i = 0; i < sws1->header.size; i++) 7070 for (i = 0; i < sws1->header.size; i++)
6478 { 7071 {
@@ -6488,6 +7081,10 @@ compare_window_configurations (Lisp_Object configuration1,
6488 != EQ (d2->current_window, sw2->window) 7081 != EQ (d2->current_window, sw2->window)
6489 /* Windows' buffers must match. */ 7082 /* Windows' buffers must match. */
6490 || !EQ (sw1->buffer, sw2->buffer) 7083 || !EQ (sw1->buffer, sw2->buffer)
7084 || !EQ (sw1->pixel_left, sw2->pixel_left)
7085 || !EQ (sw1->pixel_top, sw2->pixel_top)
7086 || !EQ (sw1->pixel_height, sw2->pixel_height)
7087 || !EQ (sw1->pixel_width, sw2->pixel_width)
6491 || !EQ (sw1->left_col, sw2->left_col) 7088 || !EQ (sw1->left_col, sw2->left_col)
6492 || !EQ (sw1->top_line, sw2->top_line) 7089 || !EQ (sw1->top_line, sw2->top_line)
6493 || !EQ (sw1->total_cols, sw2->total_cols) 7090 || !EQ (sw1->total_cols, sw2->total_cols)
@@ -6502,29 +7099,30 @@ compare_window_configurations (Lisp_Object configuration1,
6502 || !EQ (sw1->min_hscroll, sw2->min_hscroll) 7099 || !EQ (sw1->min_hscroll, sw2->min_hscroll)
6503 || !EQ (sw1->start_at_line_beg, sw2->start_at_line_beg) 7100 || !EQ (sw1->start_at_line_beg, sw2->start_at_line_beg)
6504 || NILP (Fequal (sw1->start, sw2->start)) 7101 || NILP (Fequal (sw1->start, sw2->start))
6505 || NILP (Fequal (sw1->pointm, sw2->pointm)) 7102 || NILP (Fequal (sw1->pointm, sw2->pointm))))
6506 || NILP (Fequal (sw1->mark, sw2->mark))))
6507 || !EQ (sw1->left_margin_cols, sw2->left_margin_cols) 7103 || !EQ (sw1->left_margin_cols, sw2->left_margin_cols)
6508 || !EQ (sw1->right_margin_cols, sw2->right_margin_cols) 7104 || !EQ (sw1->right_margin_cols, sw2->right_margin_cols)
6509 || !EQ (sw1->left_fringe_width, sw2->left_fringe_width) 7105 || !EQ (sw1->left_fringe_width, sw2->left_fringe_width)
6510 || !EQ (sw1->right_fringe_width, sw2->right_fringe_width) 7106 || !EQ (sw1->right_fringe_width, sw2->right_fringe_width)
6511 || !EQ (sw1->fringes_outside_margins, sw2->fringes_outside_margins) 7107 || !EQ (sw1->fringes_outside_margins, sw2->fringes_outside_margins)
6512 || !EQ (sw1->scroll_bar_width, sw2->scroll_bar_width) 7108 || !EQ (sw1->scroll_bar_width, sw2->scroll_bar_width)
6513 || !EQ (sw1->vertical_scroll_bar_type, sw2->vertical_scroll_bar_type)) 7109 || !EQ (sw1->scroll_bar_height, sw2->scroll_bar_height)
6514 return 0; 7110 || !EQ (sw1->vertical_scroll_bar_type, sw2->vertical_scroll_bar_type)
7111 || !EQ (sw1->horizontal_scroll_bar_type, sw2->horizontal_scroll_bar_type))
7112 return false;
6515 } 7113 }
6516 7114
6517 return 1; 7115 return true;
6518} 7116}
6519 7117
6520DEFUN ("compare-window-configurations", Fcompare_window_configurations, 7118DEFUN ("compare-window-configurations", Fcompare_window_configurations,
6521 Scompare_window_configurations, 2, 2, 0, 7119 Scompare_window_configurations, 2, 2, 0,
6522 doc: /* Compare two window configurations as regards the structure of windows. 7120 doc: /* Compare two window configurations as regards the structure of windows.
6523This function ignores details such as the values of point and mark 7121This function ignores details such as the values of point
6524and scrolling positions. */) 7122and scrolling positions. */)
6525 (Lisp_Object x, Lisp_Object y) 7123 (Lisp_Object x, Lisp_Object y)
6526{ 7124{
6527 if (compare_window_configurations (x, y, 1)) 7125 if (compare_window_configurations (x, y, true))
6528 return Qt; 7126 return Qt;
6529 return Qnil; 7127 return Qnil;
6530} 7128}
@@ -6537,9 +7135,6 @@ init_window_once (void)
6537 Vterminal_frame = selected_frame; 7135 Vterminal_frame = selected_frame;
6538 minibuf_window = f->minibuffer_window; 7136 minibuf_window = f->minibuffer_window;
6539 selected_window = f->selected_window; 7137 selected_window = f->selected_window;
6540 last_nonminibuf_frame = f;
6541
6542 window_initialized = 1;
6543} 7138}
6544 7139
6545void 7140void
@@ -6567,6 +7162,8 @@ syms_of_window (void)
6567 DEFSYM (Qdelete_window, "delete-window"); 7162 DEFSYM (Qdelete_window, "delete-window");
6568 DEFSYM (Qwindow_resize_root_window, "window--resize-root-window"); 7163 DEFSYM (Qwindow_resize_root_window, "window--resize-root-window");
6569 DEFSYM (Qwindow_resize_root_window_vertically, "window--resize-root-window-vertically"); 7164 DEFSYM (Qwindow_resize_root_window_vertically, "window--resize-root-window-vertically");
7165 DEFSYM (Qwindow_sanitize_window_sizes, "window--sanitize-window-sizes");
7166 DEFSYM (Qwindow_pixel_to_total, "window--pixel-to-total");
6570 DEFSYM (Qsafe, "safe"); 7167 DEFSYM (Qsafe, "safe");
6571 DEFSYM (Qdisplay_buffer, "display-buffer"); 7168 DEFSYM (Qdisplay_buffer, "display-buffer");
6572 DEFSYM (Qreplace_buffer_in_windows, "replace-buffer-in-windows"); 7169 DEFSYM (Qreplace_buffer_in_windows, "replace-buffer-in-windows");
@@ -6575,8 +7172,9 @@ syms_of_window (void)
6575 DEFSYM (Qwindow_size, "window-size"); 7172 DEFSYM (Qwindow_size, "window-size");
6576 DEFSYM (Qtemp_buffer_show_hook, "temp-buffer-show-hook"); 7173 DEFSYM (Qtemp_buffer_show_hook, "temp-buffer-show-hook");
6577 DEFSYM (Qabove, "above"); 7174 DEFSYM (Qabove, "above");
6578 DEFSYM (Qbelow, "below");
6579 DEFSYM (Qclone_of, "clone-of"); 7175 DEFSYM (Qclone_of, "clone-of");
7176 DEFSYM (Qfloor, "floor");
7177 DEFSYM (Qceiling, "ceiling");
6580 7178
6581 staticpro (&Vwindow_list); 7179 staticpro (&Vwindow_list);
6582 7180
@@ -6604,15 +7202,15 @@ the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */
6604 doc: /* Non-nil means to use `mode-line-inactive' face in non-selected windows. 7202 doc: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6605If the minibuffer is active, the `minibuffer-scroll-window' mode line 7203If the minibuffer is active, the `minibuffer-scroll-window' mode line
6606is displayed in the `mode-line' face. */); 7204is displayed in the `mode-line' face. */);
6607 mode_line_in_non_selected_windows = 1; 7205 mode_line_in_non_selected_windows = true;
6608 7206
6609 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer, 7207 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer,
6610 doc: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */); 7208 doc: /* If this is a live buffer, \\[scroll-other-window] should scroll its window. */);
6611 Vother_window_scroll_buffer = Qnil; 7209 Vother_window_scroll_buffer = Qnil;
6612 7210
6613 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p, 7211 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p,
6614 doc: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */); 7212 doc: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
6615 auto_window_vscroll_p = 1; 7213 auto_window_vscroll_p = true;
6616 7214
6617 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines, 7215 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines,
6618 doc: /* Number of lines of continuity when scrolling by screenfuls. */); 7216 doc: /* Number of lines of continuity when scrolling by screenfuls. */);
@@ -6634,6 +7232,7 @@ on their symbols to be controlled by this variable. */);
6634 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type, 7232 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type,
6635 doc: /* Type of marker to use for `window-point'. */); 7233 doc: /* Type of marker to use for `window-point'. */);
6636 Vwindow_point_insertion_type = Qnil; 7234 Vwindow_point_insertion_type = Qnil;
7235 DEFSYM (Qwindow_point_insertion_type, "window_point_insertion_type");
6637 7236
6638 DEFVAR_LISP ("window-configuration-change-hook", 7237 DEFVAR_LISP ("window-configuration-change-hook",
6639 Vwindow_configuration_change_hook, 7238 Vwindow_configuration_change_hook,
@@ -6725,6 +7324,28 @@ Parameters not saved by `current-window-configuration' or
6725respectively are not installed by `window-state-put'. */); 7324respectively are not installed by `window-state-put'. */);
6726 Vwindow_persistent_parameters = list1 (Fcons (Qclone_of, Qt)); 7325 Vwindow_persistent_parameters = list1 (Fcons (Qclone_of, Qt));
6727 7326
7327 DEFVAR_BOOL ("window-resize-pixelwise", window_resize_pixelwise,
7328 doc: /* Non-nil means resize windows pixelwise.
7329This currently affects the functions: `split-window', `maximize-window',
7330`minimize-window', `fit-window-to-buffer' and `fit-frame-to-buffer', and
7331all functions that symmetrically resize a parent window.
7332
7333Note that when a frame's pixel size is not a multiple of the
7334frame's character size, at least one window may get resized
7335pixelwise even if this option is nil. */);
7336 window_resize_pixelwise = false;
7337
7338 DEFVAR_BOOL ("fast-but-imprecise-scrolling",
7339 Vfast_but_imprecise_scrolling,
7340 doc: /* When non-nil, accelerate scrolling operations.
7341This comes into play when scrolling rapidly over previously
7342unfontified buffer regions. Only those portions of the buffer which
7343are actually going to be displayed get fontified.
7344
7345Note that this optimization can cause the portion of the buffer
7346displayed after a scrolling operation to be somewhat inaccurate. */);
7347 Vfast_but_imprecise_scrolling = false;
7348
6728 defsubr (&Sselected_window); 7349 defsubr (&Sselected_window);
6729 defsubr (&Sminibuffer_window); 7350 defsubr (&Sminibuffer_window);
6730 defsubr (&Swindow_minibuffer_p); 7351 defsubr (&Swindow_minibuffer_p);
@@ -6747,31 +7368,39 @@ respectively are not installed by `window-state-put'. */);
6747 defsubr (&Swindow_combination_limit); 7368 defsubr (&Swindow_combination_limit);
6748 defsubr (&Sset_window_combination_limit); 7369 defsubr (&Sset_window_combination_limit);
6749 defsubr (&Swindow_use_time); 7370 defsubr (&Swindow_use_time);
6750 defsubr (&Swindow_top_line); 7371 defsubr (&Swindow_pixel_width);
6751 defsubr (&Swindow_left_column); 7372 defsubr (&Swindow_pixel_height);
6752 defsubr (&Swindow_total_height);
6753 defsubr (&Swindow_total_width); 7373 defsubr (&Swindow_total_width);
7374 defsubr (&Swindow_total_height);
6754 defsubr (&Swindow_normal_size); 7375 defsubr (&Swindow_normal_size);
7376 defsubr (&Swindow_new_pixel);
6755 defsubr (&Swindow_new_total); 7377 defsubr (&Swindow_new_total);
6756 defsubr (&Swindow_new_normal); 7378 defsubr (&Swindow_new_normal);
7379 defsubr (&Swindow_pixel_left);
7380 defsubr (&Swindow_pixel_top);
7381 defsubr (&Swindow_left_column);
7382 defsubr (&Swindow_top_line);
7383 defsubr (&Sset_window_new_pixel);
6757 defsubr (&Sset_window_new_total); 7384 defsubr (&Sset_window_new_total);
6758 defsubr (&Sset_window_new_normal); 7385 defsubr (&Sset_window_new_normal);
6759 defsubr (&Swindow_resize_apply); 7386 defsubr (&Swindow_resize_apply);
7387 defsubr (&Swindow_resize_apply_total);
6760 defsubr (&Swindow_body_height); 7388 defsubr (&Swindow_body_height);
6761 defsubr (&Swindow_body_width); 7389 defsubr (&Swindow_body_width);
6762 defsubr (&Swindow_hscroll); 7390 defsubr (&Swindow_hscroll);
6763 defsubr (&Sset_window_hscroll); 7391 defsubr (&Sset_window_hscroll);
6764 defsubr (&Swindow_redisplay_end_trigger); 7392 defsubr (&Swindow_redisplay_end_trigger);
6765 defsubr (&Sset_window_redisplay_end_trigger); 7393 defsubr (&Sset_window_redisplay_end_trigger);
6766 defsubr (&Swindow_edges); 7394 defsubr (&Swindow_mode_line_height);
6767 defsubr (&Swindow_pixel_edges); 7395 defsubr (&Swindow_header_line_height);
6768 defsubr (&Swindow_absolute_pixel_edges); 7396 defsubr (&Swindow_right_divider_width);
6769 defsubr (&Swindow_inside_edges); 7397 defsubr (&Swindow_bottom_divider_width);
6770 defsubr (&Swindow_inside_pixel_edges); 7398 defsubr (&Swindow_scroll_bar_width);
6771 defsubr (&Swindow_inside_absolute_pixel_edges); 7399 defsubr (&Swindow_scroll_bar_height);
6772 defsubr (&Scoordinates_in_window_p); 7400 defsubr (&Scoordinates_in_window_p);
6773 defsubr (&Swindow_at); 7401 defsubr (&Swindow_at);
6774 defsubr (&Swindow_point); 7402 defsubr (&Swindow_point);
7403 defsubr (&Swindow_old_point);
6775 defsubr (&Swindow_start); 7404 defsubr (&Swindow_start);
6776 defsubr (&Swindow_end); 7405 defsubr (&Swindow_end);
6777 defsubr (&Sset_window_point); 7406 defsubr (&Sset_window_point);
@@ -6782,12 +7411,14 @@ respectively are not installed by `window-state-put'. */);
6782 defsubr (&Sset_window_display_table); 7411 defsubr (&Sset_window_display_table);
6783 defsubr (&Snext_window); 7412 defsubr (&Snext_window);
6784 defsubr (&Sprevious_window); 7413 defsubr (&Sprevious_window);
7414 defsubr (&Swindow__sanitize_window_sizes);
6785 defsubr (&Sget_buffer_window); 7415 defsubr (&Sget_buffer_window);
6786 defsubr (&Sdelete_other_windows_internal); 7416 defsubr (&Sdelete_other_windows_internal);
6787 defsubr (&Sdelete_window_internal); 7417 defsubr (&Sdelete_window_internal);
6788 defsubr (&Sresize_mini_window_internal); 7418 defsubr (&Sresize_mini_window_internal);
6789 defsubr (&Sset_window_buffer); 7419 defsubr (&Sset_window_buffer);
6790 defsubr (&Srun_window_configuration_change_hook); 7420 defsubr (&Srun_window_configuration_change_hook);
7421 defsubr (&Srun_window_scroll_functions);
6791 defsubr (&Sselect_window); 7422 defsubr (&Sselect_window);
6792 defsubr (&Sforce_window_update); 7423 defsubr (&Sforce_window_update);
6793 defsubr (&Ssplit_window_internal); 7424 defsubr (&Ssplit_window_internal);
@@ -6799,6 +7430,7 @@ respectively are not installed by `window-state-put'. */);
6799 defsubr (&Sscroll_other_window); 7430 defsubr (&Sscroll_other_window);
6800 defsubr (&Sminibuffer_selected_window); 7431 defsubr (&Sminibuffer_selected_window);
6801 defsubr (&Srecenter); 7432 defsubr (&Srecenter);
7433 defsubr (&Swindow_text_width);
6802 defsubr (&Swindow_text_height); 7434 defsubr (&Swindow_text_height);
6803 defsubr (&Smove_to_window_line); 7435 defsubr (&Smove_to_window_line);
6804 defsubr (&Swindow_configuration_p); 7436 defsubr (&Swindow_configuration_p);