Commit | Line | Data |
---|---|---|
7ab12479 JB |
1 | /* Window creation, deletion and examination for GNU Emacs. |
2 | Does not include redisplay. | |
203eb0aa | 3 | Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 2000, |
8cabe764 GM |
4 | 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
5 | Free Software Foundation, Inc. | |
7ab12479 JB |
6 | |
7 | This file is part of GNU Emacs. | |
8 | ||
9ec0b715 | 9 | GNU Emacs is free software: you can redistribute it and/or modify |
7ab12479 | 10 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
11 | the Free Software Foundation, either version 3 of the License, or |
12 | (at your option) any later version. | |
7ab12479 JB |
13 | |
14 | GNU Emacs is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 20 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
7ab12479 | 21 | |
18160b98 | 22 | #include <config.h> |
4d553a13 KL |
23 | #include <stdio.h> |
24 | ||
7ab12479 JB |
25 | #include "lisp.h" |
26 | #include "buffer.h" | |
3e4731a3 | 27 | #include "keyboard.h" |
e35f6ff7 | 28 | #include "keymap.h" |
44fa5b1e | 29 | #include "frame.h" |
7ab12479 JB |
30 | #include "window.h" |
31 | #include "commands.h" | |
32 | #include "indent.h" | |
33 | #include "termchar.h" | |
34 | #include "disptab.h" | |
dfcf069d | 35 | #include "dispextern.h" |
5500c422 GM |
36 | #include "blockinput.h" |
37 | #include "intervals.h" | |
de509a60 | 38 | #include "termhooks.h" /* For FRAME_TERMINAL. */ |
5500c422 | 39 | |
6d55d620 | 40 | #ifdef HAVE_X_WINDOWS |
dfcf069d | 41 | #include "xterm.h" |
5500c422 | 42 | #endif /* HAVE_X_WINDOWS */ |
8f23f280 AI |
43 | #ifdef WINDOWSNT |
44 | #include "w32term.h" | |
45 | #endif | |
1e3c8885 EZ |
46 | #ifdef MSDOS |
47 | #include "msdos.h" | |
48 | #endif | |
e0f712ba | 49 | #ifdef MAC_OS |
1a578e9b AC |
50 | #include "macterm.h" |
51 | #endif | |
edfda783 AR |
52 | #ifdef HAVE_NS |
53 | #include "nsterm.h" | |
54 | #endif | |
5500c422 | 55 | |
5500c422 | 56 | |
3f8ab7bd | 57 | Lisp_Object Qwindowp, Qwindow_live_p, Qwindow_configuration_p; |
87478b52 | 58 | Lisp_Object Qdisplay_buffer; |
c525d842 | 59 | Lisp_Object Qscroll_up, Qscroll_down; |
90647b07 | 60 | Lisp_Object Qwindow_size_fixed; |
87478b52 | 61 | |
49b996e7 | 62 | extern Lisp_Object Qleft_margin, Qright_margin; |
7ab12479 | 63 | |
521b203e | 64 | static int displayed_window_lines P_ ((struct window *)); |
5e14b1fc | 65 | static struct window *decode_window P_ ((Lisp_Object)); |
5500c422 GM |
66 | static int count_windows P_ ((struct window *)); |
67 | static int get_leaf_windows P_ ((struct window *, struct window **, int)); | |
68 | static void window_scroll P_ ((Lisp_Object, int, int, int)); | |
69 | static void window_scroll_pixel_based P_ ((Lisp_Object, int, int, int)); | |
70 | static void window_scroll_line_based P_ ((Lisp_Object, int, int, int)); | |
047aaeb9 MR |
71 | static int window_min_size_1 P_ ((struct window *, int, int)); |
72 | static int window_min_size_2 P_ ((struct window *, int, int)); | |
73 | static int window_min_size P_ ((struct window *, int, int, int, int *)); | |
5fe0b054 | 74 | static void size_window P_ ((Lisp_Object, int, int, int, int, int)); |
f95464e4 | 75 | static int freeze_window_start P_ ((struct window *, void *)); |
f984d4fc | 76 | static int window_fixed_size_p P_ ((struct window *, int, int)); |
56ebfae2 | 77 | static void enlarge_window P_ ((Lisp_Object, int, int)); |
67492200 | 78 | static Lisp_Object window_list P_ ((void)); |
f95464e4 | 79 | static int add_window_to_list P_ ((struct window *, void *)); |
118ea242 GM |
80 | static int candidate_window_p P_ ((Lisp_Object, Lisp_Object, Lisp_Object, |
81 | Lisp_Object)); | |
67492200 GM |
82 | static Lisp_Object next_window P_ ((Lisp_Object, Lisp_Object, |
83 | Lisp_Object, int)); | |
84 | static void decode_next_window_args P_ ((Lisp_Object *, Lisp_Object *, | |
85 | Lisp_Object *)); | |
f95464e4 GM |
86 | static int foreach_window_1 P_ ((struct window *, |
87 | int (* fn) (struct window *, void *), | |
88 | void *)); | |
cd2904bd | 89 | static Lisp_Object window_list_1 P_ ((Lisp_Object, Lisp_Object, Lisp_Object)); |
b7354ddf | 90 | |
7ab12479 JB |
91 | /* This is the window in which the terminal's cursor should |
92 | be left when nothing is being done with it. This must | |
93 | always be a leaf window, and its buffer is selected by | |
94 | the top level editing loop at the end of each command. | |
95 | ||
96 | This value is always the same as | |
44fa5b1e | 97 | FRAME_SELECTED_WINDOW (selected_frame). */ |
7ab12479 JB |
98 | |
99 | Lisp_Object selected_window; | |
100 | ||
67492200 GM |
101 | /* A list of all windows for use by next_window and Fwindow_list. |
102 | Functions creating or deleting windows should invalidate this cache | |
103 | by setting it to nil. */ | |
104 | ||
105 | Lisp_Object Vwindow_list; | |
106 | ||
5500c422 GM |
107 | /* The mini-buffer window of the selected frame. |
108 | Note that you cannot test for mini-bufferness of an arbitrary window | |
109 | by comparing against this; but you can test for mini-bufferness of | |
7ab12479 | 110 | the selected window. */ |
5500c422 | 111 | |
7ab12479 JB |
112 | Lisp_Object minibuf_window; |
113 | ||
3f49fddc KS |
114 | /* Non-nil means it is the window whose mode line should be |
115 | shown as the selected window when the minibuffer is selected. */ | |
116 | ||
3dbab091 | 117 | Lisp_Object minibuf_selected_window; |
3f49fddc | 118 | |
7ab12479 | 119 | /* Non-nil means it is the window for C-M-v to scroll |
5500c422 GM |
120 | when the mini-buffer is selected. */ |
121 | ||
7ab12479 JB |
122 | Lisp_Object Vminibuf_scroll_window; |
123 | ||
124 | /* Non-nil means this is the buffer whose window C-M-v should scroll. */ | |
5500c422 | 125 | |
7ab12479 JB |
126 | Lisp_Object Vother_window_scroll_buffer; |
127 | ||
7ab12479 | 128 | /* Non-nil means it's function to call to display temp buffers. */ |
5500c422 | 129 | |
7ab12479 JB |
130 | Lisp_Object Vtemp_buffer_show_function; |
131 | ||
e56263e5 KS |
132 | /* Non-zero means line and page scrolling on tall lines (with images) |
133 | does partial scrolling by modifying window-vscroll. */ | |
134 | ||
135 | int auto_window_vscroll_p; | |
136 | ||
cc91894c KS |
137 | /* Non-zero means to use mode-line-inactive face in all windows but the |
138 | selected-window and the minibuffer-scroll-window when the | |
139 | minibuffer is active. */ | |
140 | int mode_line_in_non_selected_windows; | |
26124d5e | 141 | |
7ab12479 | 142 | /* If a window gets smaller than either of these, it is removed. */ |
5500c422 | 143 | |
31ade731 SM |
144 | EMACS_INT window_min_height; |
145 | EMACS_INT window_min_width; | |
7ab12479 | 146 | |
a58ec57d | 147 | /* Hook run at end of temp_output_buffer_show. */ |
5500c422 | 148 | |
a58ec57d RS |
149 | Lisp_Object Qtemp_buffer_show_hook; |
150 | ||
7ab12479 | 151 | /* Number of lines of continuity in scrolling by screenfuls. */ |
5500c422 | 152 | |
31ade731 | 153 | EMACS_INT next_screen_context_lines; |
7ab12479 JB |
154 | |
155 | /* Incremented for each window created. */ | |
5500c422 | 156 | |
7ab12479 JB |
157 | static int sequence_number; |
158 | ||
5b03d3c0 | 159 | /* Nonzero after init_window_once has finished. */ |
5500c422 | 160 | |
5b03d3c0 RS |
161 | static int window_initialized; |
162 | ||
543f5fb1 | 163 | /* Hook to run when window config changes. */ |
5500c422 | 164 | |
eeca6f6f SM |
165 | static Lisp_Object Qwindow_configuration_change_hook; |
166 | static Lisp_Object Vwindow_configuration_change_hook; | |
543f5fb1 | 167 | |
d0c38d63 | 168 | /* Non-nil means scroll commands try to put point |
9317a85d | 169 | at the same screen height as previously. */ |
9317a85d | 170 | |
5500c422 GM |
171 | Lisp_Object Vscroll_preserve_screen_position; |
172 | ||
a1562258 SM |
173 | /* Non-nil means that text is inserted before window's markers. */ |
174 | ||
175 | Lisp_Object Vwindow_point_insertion_type; | |
176 | ||
0d384044 RS |
177 | /* Incremented by 1 whenever a window is deleted. */ |
178 | ||
179 | int window_deletion_count; | |
180 | ||
66d43aea LT |
181 | /* Used by the function window_scroll_pixel_based */ |
182 | ||
c876b227 | 183 | static int window_scroll_pixel_based_preserve_x; |
66fe93d1 | 184 | static int window_scroll_pixel_based_preserve_y; |
66d43aea | 185 | |
c876b227 SM |
186 | /* Same for window_scroll_line_based. */ |
187 | ||
188 | static int window_scroll_preserve_hpos; | |
189 | static int window_scroll_preserve_vpos; | |
190 | ||
5500c422 | 191 | #if 0 /* This isn't used anywhere. */ |
91a78190 | 192 | /* Nonzero means we can split a frame even if it is "unsplittable". */ |
eddd51c2 | 193 | static int inhibit_frame_unsplittable; |
5500c422 | 194 | #endif /* 0 */ |
7d601aaa | 195 | |
31ade731 | 196 | extern EMACS_INT scroll_margin; |
9317a85d | 197 | |
dba06815 | 198 | extern Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions; |
7ab12479 JB |
199 | \f |
200 | DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0, | |
fdb82f93 PJ |
201 | doc: /* Returns t if OBJECT is a window. */) |
202 | (object) | |
413430c5 | 203 | Lisp_Object object; |
7ab12479 | 204 | { |
413430c5 | 205 | return WINDOWP (object) ? Qt : Qnil; |
7ab12479 JB |
206 | } |
207 | ||
806b4d9b | 208 | DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0, |
fdb82f93 | 209 | doc: /* Returns t if OBJECT is a window which is currently visible. */) |
413430c5 EN |
210 | (object) |
211 | Lisp_Object object; | |
605be8af | 212 | { |
9e571f49 | 213 | return WINDOW_LIVE_P (object) ? Qt : Qnil; |
605be8af JB |
214 | } |
215 | ||
7ab12479 JB |
216 | Lisp_Object |
217 | make_window () | |
218 | { | |
cffec418 | 219 | Lisp_Object val; |
7ab12479 | 220 | register struct window *p; |
cffec418 | 221 | |
26605be9 | 222 | p = allocate_window (); |
2a1893f4 SM |
223 | ++sequence_number; |
224 | XSETFASTINT (p->sequence_number, sequence_number); | |
949cf20f KS |
225 | XSETFASTINT (p->left_col, 0); |
226 | XSETFASTINT (p->top_line, 0); | |
227 | XSETFASTINT (p->total_lines, 0); | |
228 | XSETFASTINT (p->total_cols, 0); | |
d834a2e9 | 229 | XSETFASTINT (p->hscroll, 0); |
ea68264b | 230 | XSETFASTINT (p->min_hscroll, 0); |
949cf20f | 231 | p->orig_top_line = p->orig_total_lines = Qnil; |
7ab12479 JB |
232 | p->start = Fmake_marker (); |
233 | p->pointm = Fmake_marker (); | |
d834a2e9 | 234 | XSETFASTINT (p->use_time, 0); |
44fa5b1e | 235 | p->frame = Qnil; |
7ab12479 JB |
236 | p->display_table = Qnil; |
237 | p->dedicated = Qnil; | |
cfbb2395 | 238 | p->window_parameters = Qnil; |
5500c422 GM |
239 | p->pseudo_window_p = 0; |
240 | bzero (&p->cursor, sizeof (p->cursor)); | |
241 | bzero (&p->last_cursor, sizeof (p->last_cursor)); | |
242 | bzero (&p->phys_cursor, sizeof (p->phys_cursor)); | |
243 | p->desired_matrix = p->current_matrix = 0; | |
7a146de2 | 244 | p->nrows_scale_factor = p->ncols_scale_factor = 1; |
5500c422 | 245 | p->phys_cursor_type = -1; |
4b26579e | 246 | p->phys_cursor_width = -1; |
5500c422 GM |
247 | p->must_be_updated_p = 0; |
248 | XSETFASTINT (p->window_end_vpos, 0); | |
249 | XSETFASTINT (p->window_end_pos, 0); | |
250 | p->window_end_valid = Qnil; | |
251 | p->vscroll = 0; | |
cffec418 | 252 | XSETWINDOW (val, p); |
5500c422 | 253 | XSETFASTINT (p->last_point, 0); |
7bbb5782 | 254 | p->frozen_window_start_p = 0; |
6b448755 | 255 | p->last_cursor_off_p = p->cursor_off_p = 0; |
949cf20f KS |
256 | p->left_margin_cols = Qnil; |
257 | p->right_margin_cols = Qnil; | |
258 | p->left_fringe_width = Qnil; | |
259 | p->right_fringe_width = Qnil; | |
260 | p->fringes_outside_margins = Qnil; | |
261 | p->scroll_bar_width = Qnil; | |
262 | p->vertical_scroll_bar_type = Qt; | |
047aaeb9 | 263 | p->resize_proportionally = Qnil; |
67492200 GM |
264 | |
265 | Vwindow_list = Qnil; | |
7ab12479 JB |
266 | return val; |
267 | } | |
268 | ||
269 | DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0, | |
fdb82f93 PJ |
270 | doc: /* Return the window that the cursor now appears in and commands apply to. */) |
271 | () | |
7ab12479 JB |
272 | { |
273 | return selected_window; | |
274 | } | |
275 | ||
83762ba4 | 276 | DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0, |
fdb82f93 PJ |
277 | doc: /* Return the window used now for minibuffers. |
278 | If the optional argument FRAME is specified, return the minibuffer window | |
279 | used by that frame. */) | |
280 | (frame) | |
83762ba4 | 281 | Lisp_Object frame; |
7ab12479 | 282 | { |
83762ba4 | 283 | if (NILP (frame)) |
1ae1a37d | 284 | frame = selected_frame; |
b7826503 | 285 | CHECK_LIVE_FRAME (frame); |
83762ba4 | 286 | return FRAME_MINIBUF_WINDOW (XFRAME (frame)); |
7ab12479 JB |
287 | } |
288 | ||
605be8af | 289 | DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, Swindow_minibuffer_p, 0, 1, 0, |
6b61353c KH |
290 | doc: /* Returns non-nil if WINDOW is a minibuffer window. |
291 | WINDOW defaults to the selected window. */) | |
fdb82f93 | 292 | (window) |
7ab12479 JB |
293 | Lisp_Object window; |
294 | { | |
295 | struct window *w = decode_window (window); | |
53bb6b99 | 296 | return MINI_WINDOW_P (w) ? Qt : Qnil; |
81e4d465 MB |
297 | } |
298 | ||
299 | ||
7ab12479 | 300 | DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p, |
fdb82f93 | 301 | Spos_visible_in_window_p, 0, 3, 0, |
a0a37a6f | 302 | doc: /* Return non-nil if position POS is currently on the frame in WINDOW. |
fdb82f93 PJ |
303 | Return nil if that position is scrolled vertically out of view. |
304 | If a character is only partially visible, nil is returned, unless the | |
305 | optional argument PARTIALLY is non-nil. | |
a0a37a6f | 306 | If POS is only out of view because of horizontal scrolling, return non-nil. |
120b7781 | 307 | If POS is t, it specifies the position of the last visible glyph in WINDOW. |
0cc1039f KS |
308 | POS defaults to point in WINDOW; WINDOW defaults to the selected window. |
309 | ||
310 | If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil, | |
5a857365 KS |
311 | return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]), |
312 | where X and Y are the pixel coordinates relative to the top left corner | |
313 | of the window. The remaining elements are omitted if the character after | |
314 | POS is fully visible; otherwise, RTOP and RBOT are the number of pixels | |
120b7781 | 315 | off-window at the top and bottom of the row, ROWH is the height of the |
7bbc67d2 | 316 | display row, and VPOS is the row number (0-based) containing POS. */) |
fdb82f93 | 317 | (pos, window, partially) |
5cdb3cf3 | 318 | Lisp_Object pos, window, partially; |
7ab12479 JB |
319 | { |
320 | register struct window *w; | |
7ab12479 JB |
321 | register int posint; |
322 | register struct buffer *buf; | |
9a132b1f | 323 | struct text_pos top; |
0cc1039f | 324 | Lisp_Object in_window = Qnil; |
5a857365 | 325 | int rtop, rbot, rowh, vpos, fully_p = 1; |
0cc1039f | 326 | int x, y; |
7ab12479 | 327 | |
f28b75a9 MB |
328 | w = decode_window (window); |
329 | buf = XBUFFER (w->buffer); | |
330 | SET_TEXT_POS_FROM_MARKER (top, w->start); | |
331 | ||
120b7781 KS |
332 | if (EQ (pos, Qt)) |
333 | posint = -1; | |
334 | else if (!NILP (pos)) | |
7ab12479 | 335 | { |
b7826503 | 336 | CHECK_NUMBER_COERCE_MARKER (pos); |
7ab12479 JB |
337 | posint = XINT (pos); |
338 | } | |
f28b75a9 MB |
339 | else if (w == XWINDOW (selected_window)) |
340 | posint = PT; | |
341 | else | |
342 | posint = XMARKER (w->pointm)->charpos; | |
7ab12479 | 343 | |
0cc1039f KS |
344 | /* If position is above window start or outside buffer boundaries, |
345 | or if window start is out of range, position is not visible. */ | |
120b7781 KS |
346 | if ((EQ (pos, Qt) |
347 | || (posint >= CHARPOS (top) && posint <= BUF_ZV (buf))) | |
0cc1039f KS |
348 | && CHARPOS (top) >= BUF_BEGV (buf) |
349 | && CHARPOS (top) <= BUF_ZV (buf) | |
5a857365 | 350 | && pos_visible_p (w, posint, &x, &y, &rtop, &rbot, &rowh, &vpos) |
e56263e5 | 351 | && (fully_p = !rtop && !rbot, (!NILP (partially) || fully_p))) |
0cc1039f KS |
352 | in_window = Qt; |
353 | ||
354 | if (!NILP (in_window) && !NILP (partially)) | |
5a857365 KS |
355 | { |
356 | Lisp_Object part = Qnil; | |
357 | if (!fully_p) | |
358 | part = list4 (make_number (rtop), make_number (rbot), | |
359 | make_number (rowh), make_number (vpos)); | |
360 | in_window = Fcons (make_number (x), | |
361 | Fcons (make_number (y), part)); | |
362 | } | |
363 | ||
9a132b1f | 364 | return in_window; |
7ab12479 | 365 | } |
53bb6b99 | 366 | |
536833ab | 367 | DEFUN ("window-line-height", Fwindow_line_height, |
7bbc67d2 | 368 | Swindow_line_height, 0, 2, 0, |
536833ab KS |
369 | doc: /* Return height in pixels of text line LINE in window WINDOW. |
370 | If WINDOW is nil or omitted, use selected window. | |
371 | ||
7bbc67d2 KS |
372 | Return height of current line if LINE is omitted or nil. Return height of |
373 | header or mode line if LINE is `header-line' and `mode-line'. | |
374 | Otherwise, LINE is a text line number starting from 0. A negative number | |
375 | counts from the end of the window. | |
536833ab | 376 | |
7bbc67d2 | 377 | Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height |
536833ab | 378 | in pixels of the visible part of the line, VPOS and YPOS are the |
68e67a4e | 379 | vertical position in lines and pixels of the line, relative to the top |
120b7781 | 380 | of the first text line, and OFFBOT is the number of off-window pixels at |
68e67a4e KS |
381 | the bottom of the text line. If there are off-window pixels at the top |
382 | of the (first) text line, YPOS is negative. | |
536833ab KS |
383 | |
384 | Return nil if window display is not up-to-date. In that case, use | |
385 | `pos-visible-in-window-p' to obtain the information. */) | |
386 | (line, window) | |
387 | Lisp_Object line, window; | |
b3a10345 KS |
388 | { |
389 | register struct window *w; | |
390 | register struct buffer *b; | |
391 | struct glyph_row *row, *end_row; | |
536833ab | 392 | int max_y, crop, i, n; |
b3a10345 KS |
393 | |
394 | w = decode_window (window); | |
395 | ||
396 | if (noninteractive | |
b3a10345 | 397 | || w->pseudo_window_p) |
7bbc67d2 | 398 | return Qnil; |
b3a10345 KS |
399 | |
400 | CHECK_BUFFER (w->buffer); | |
401 | b = XBUFFER (w->buffer); | |
402 | ||
403 | /* Fail if current matrix is not up-to-date. */ | |
404 | if (NILP (w->window_end_valid) | |
405 | || current_buffer->clip_changed | |
406 | || current_buffer->prevent_redisplay_optimizations_p | |
407 | || XFASTINT (w->last_modified) < BUF_MODIFF (b) | |
408 | || XFASTINT (w->last_overlay_modified) < BUF_OVERLAY_MODIFF (b)) | |
409 | return Qnil; | |
410 | ||
7bbc67d2 KS |
411 | if (NILP (line)) |
412 | { | |
413 | i = w->cursor.vpos; | |
414 | if (i < 0 || i >= w->current_matrix->nrows | |
415 | || (row = MATRIX_ROW (w->current_matrix, i), !row->enabled_p)) | |
416 | return Qnil; | |
417 | max_y = window_text_bottom_y (w); | |
418 | goto found_row; | |
419 | } | |
420 | ||
536833ab | 421 | if (EQ (line, Qheader_line)) |
b3a10345 | 422 | { |
536833ab KS |
423 | if (!WINDOW_WANTS_HEADER_LINE_P (w)) |
424 | return Qnil; | |
425 | row = MATRIX_HEADER_LINE_ROW (w->current_matrix); | |
b3a10345 KS |
426 | if (!row->enabled_p) |
427 | return Qnil; | |
536833ab KS |
428 | return list4 (make_number (row->height), |
429 | make_number (0), make_number (0), | |
430 | make_number (0)); | |
b3a10345 | 431 | } |
536833ab KS |
432 | |
433 | if (EQ (line, Qmode_line)) | |
b3a10345 | 434 | { |
536833ab KS |
435 | row = MATRIX_MODE_LINE_ROW (w->current_matrix); |
436 | if (!row->enabled_p) | |
437 | return Qnil; | |
438 | return list4 (make_number (row->height), | |
439 | make_number (0), /* not accurate */ | |
440 | make_number (WINDOW_HEADER_LINE_HEIGHT (w) | |
441 | + window_text_bottom_y (w)), | |
442 | make_number (0)); | |
443 | } | |
b3a10345 | 444 | |
536833ab | 445 | CHECK_NUMBER (line); |
7bbc67d2 | 446 | n = XINT (line); |
536833ab KS |
447 | |
448 | row = MATRIX_FIRST_TEXT_ROW (w->current_matrix); | |
449 | end_row = MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w); | |
450 | max_y = window_text_bottom_y (w); | |
7bbc67d2 | 451 | i = 0; |
536833ab KS |
452 | |
453 | while ((n < 0 || i < n) | |
454 | && row <= end_row && row->enabled_p | |
455 | && row->y + row->height < max_y) | |
456 | row++, i++; | |
b3a10345 | 457 | |
536833ab KS |
458 | if (row > end_row || !row->enabled_p) |
459 | return Qnil; | |
460 | ||
7bbc67d2 | 461 | if (++n < 0) |
536833ab KS |
462 | { |
463 | if (-n > i) | |
464 | return Qnil; | |
7bbc67d2 KS |
465 | row += n; |
466 | i += n; | |
b3a10345 KS |
467 | } |
468 | ||
7bbc67d2 | 469 | found_row: |
536833ab KS |
470 | crop = max (0, (row->y + row->height) - max_y); |
471 | return list4 (make_number (row->height + min (0, row->y) - crop), | |
7bbc67d2 | 472 | make_number (i), |
536833ab KS |
473 | make_number (row->y), |
474 | make_number (crop)); | |
b3a10345 KS |
475 | } |
476 | ||
536833ab | 477 | |
7ab12479 JB |
478 | \f |
479 | static struct window * | |
480 | decode_window (window) | |
481 | register Lisp_Object window; | |
482 | { | |
265a9e55 | 483 | if (NILP (window)) |
7ab12479 JB |
484 | return XWINDOW (selected_window); |
485 | ||
b7826503 | 486 | CHECK_LIVE_WINDOW (window); |
7ab12479 JB |
487 | return XWINDOW (window); |
488 | } | |
489 | ||
6b61353c KH |
490 | static struct window * |
491 | decode_any_window (window) | |
492 | register Lisp_Object window; | |
493 | { | |
494 | if (NILP (window)) | |
495 | return XWINDOW (selected_window); | |
496 | ||
497 | CHECK_WINDOW (window); | |
498 | return XWINDOW (window); | |
499 | } | |
500 | ||
7ab12479 | 501 | DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0, |
c2755926 LT |
502 | doc: /* Return the buffer that WINDOW is displaying. |
503 | WINDOW defaults to the selected window. */) | |
fdb82f93 | 504 | (window) |
7ab12479 JB |
505 | Lisp_Object window; |
506 | { | |
507 | return decode_window (window)->buffer; | |
508 | } | |
509 | ||
510 | DEFUN ("window-height", Fwindow_height, Swindow_height, 0, 1, 0, | |
c85322d0 EZ |
511 | doc: /* Return the number of lines in WINDOW (including its mode line). |
512 | WINDOW defaults to the selected window. */) | |
fdb82f93 | 513 | (window) |
7ab12479 JB |
514 | Lisp_Object window; |
515 | { | |
6b61353c | 516 | return decode_any_window (window)->total_lines; |
7ab12479 JB |
517 | } |
518 | ||
519 | DEFUN ("window-width", Fwindow_width, Swindow_width, 0, 1, 0, | |
fdb82f93 PJ |
520 | doc: /* Return the number of display columns in WINDOW. |
521 | This is the width that is usable columns available for text in WINDOW. | |
522 | If you want to find out how many columns WINDOW takes up, | |
523 | use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */) | |
524 | (window) | |
7ab12479 JB |
525 | Lisp_Object window; |
526 | { | |
6b61353c | 527 | return make_number (window_box_text_cols (decode_any_window (window))); |
7ab12479 JB |
528 | } |
529 | ||
35ea56c9 MR |
530 | DEFUN ("window-full-width-p", Fwindow_full_width_p, Swindow_full_width_p, 0, 1, 0, |
531 | doc: /* Return t if WINDOW is as wide as its frame. | |
532 | WINDOW defaults to the selected window. */) | |
533 | (window) | |
534 | Lisp_Object window; | |
535 | { | |
536 | return WINDOW_FULL_WIDTH_P (decode_any_window (window)) ? Qt : Qnil; | |
537 | } | |
538 | ||
7ab12479 | 539 | DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0, |
c85322d0 EZ |
540 | doc: /* Return the number of columns by which WINDOW is scrolled from left margin. |
541 | WINDOW defaults to the selected window. */) | |
fdb82f93 | 542 | (window) |
7ab12479 JB |
543 | Lisp_Object window; |
544 | { | |
545 | return decode_window (window)->hscroll; | |
546 | } | |
547 | ||
548 | DEFUN ("set-window-hscroll", Fset_window_hscroll, Sset_window_hscroll, 2, 2, 0, | |
fdb82f93 | 549 | doc: /* Set number of columns WINDOW is scrolled from left margin to NCOL. |
a0a37a6f | 550 | Return NCOL. NCOL should be zero or positive. |
ebadb1e4 EZ |
551 | |
552 | Note that if `automatic-hscrolling' is non-nil, you cannot scroll the | |
120b7781 | 553 | window so that the location of point moves off-window. */) |
fdb82f93 | 554 | (window, ncol) |
ea68264b | 555 | Lisp_Object window, ncol; |
7ab12479 | 556 | { |
ea68264b GM |
557 | struct window *w = decode_window (window); |
558 | int hscroll; | |
7ab12479 | 559 | |
b7826503 | 560 | CHECK_NUMBER (ncol); |
ea68264b | 561 | hscroll = max (0, XINT (ncol)); |
177c0ea7 | 562 | |
ea68264b GM |
563 | /* Prevent redisplay shortcuts when changing the hscroll. */ |
564 | if (XINT (w->hscroll) != hscroll) | |
b1599b4c | 565 | XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1; |
177c0ea7 | 566 | |
c67fa410 | 567 | w->hscroll = make_number (hscroll); |
7ab12479 JB |
568 | return ncol; |
569 | } | |
570 | ||
190eb263 RS |
571 | DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger, |
572 | Swindow_redisplay_end_trigger, 0, 1, 0, | |
fdb82f93 | 573 | doc: /* Return WINDOW's redisplay end trigger value. |
c85322d0 | 574 | WINDOW defaults to the selected window. |
fdb82f93 PJ |
575 | See `set-window-redisplay-end-trigger' for more information. */) |
576 | (window) | |
190eb263 RS |
577 | Lisp_Object window; |
578 | { | |
579 | return decode_window (window)->redisplay_end_trigger; | |
580 | } | |
581 | ||
582 | DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger, | |
583 | Sset_window_redisplay_end_trigger, 2, 2, 0, | |
fdb82f93 PJ |
584 | doc: /* Set WINDOW's redisplay end trigger value to VALUE. |
585 | VALUE should be a buffer position (typically a marker) or nil. | |
586 | If it is a buffer position, then if redisplay in WINDOW reaches a position | |
587 | beyond VALUE, the functions in `redisplay-end-trigger-functions' are called | |
588 | with two arguments: WINDOW, and the end trigger value. | |
589 | Afterwards the end-trigger value is reset to nil. */) | |
590 | (window, value) | |
190eb263 RS |
591 | register Lisp_Object window, value; |
592 | { | |
593 | register struct window *w; | |
594 | ||
595 | w = decode_window (window); | |
596 | w->redisplay_end_trigger = value; | |
597 | return value; | |
598 | } | |
599 | ||
7ab12479 | 600 | DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0, |
fdb82f93 PJ |
601 | doc: /* Return a list of the edge coordinates of WINDOW. |
602 | \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame. | |
c99a9eb3 RS |
603 | RIGHT is one more than the rightmost column occupied by WINDOW, |
604 | and BOTTOM is one more than the bottommost row occupied by WINDOW. | |
605 | The edges include the space used by the window's scroll bar, | |
606 | display margins, fringes, header line, and mode line, if it has them. | |
607 | To get the edges of the actual text area, use `window-inside-edges'. */) | |
fdb82f93 | 608 | (window) |
7ab12479 JB |
609 | Lisp_Object window; |
610 | { | |
6b61353c | 611 | register struct window *w = decode_any_window (window); |
7ab12479 | 612 | |
949cf20f KS |
613 | return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w)), |
614 | Fcons (make_number (WINDOW_TOP_EDGE_LINE (w)), | |
615 | Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w)), | |
616 | Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w)), | |
617 | Qnil)))); | |
7ab12479 JB |
618 | } |
619 | ||
c99a9eb3 RS |
620 | DEFUN ("window-pixel-edges", Fwindow_pixel_edges, Swindow_pixel_edges, 0, 1, 0, |
621 | doc: /* Return a list of the edge pixel coordinates of WINDOW. | |
622 | \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame. | |
623 | RIGHT is one more than the rightmost x position occupied by WINDOW, | |
624 | and BOTTOM is one more than the bottommost y position occupied by WINDOW. | |
625 | The pixel edges include the space used by the window's scroll bar, | |
626 | display margins, fringes, header line, and mode line, if it has them. | |
627 | To get the edges of the actual text area, use `window-inside-pixel-edges'. */) | |
628 | (window) | |
629 | Lisp_Object window; | |
630 | { | |
6b61353c | 631 | register struct window *w = decode_any_window (window); |
c99a9eb3 RS |
632 | |
633 | return Fcons (make_number (WINDOW_LEFT_EDGE_X (w)), | |
634 | Fcons (make_number (WINDOW_TOP_EDGE_Y (w)), | |
635 | Fcons (make_number (WINDOW_RIGHT_EDGE_X (w)), | |
636 | Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w)), | |
637 | Qnil)))); | |
638 | } | |
639 | ||
640 | DEFUN ("window-inside-edges", Fwindow_inside_edges, Swindow_inside_edges, 0, 1, 0, | |
641 | doc: /* Return a list of the edge coordinates of WINDOW. | |
642 | \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame. | |
643 | RIGHT is one more than the rightmost column used by text in WINDOW, | |
644 | and BOTTOM is one more than the bottommost row used by text in WINDOW. | |
645 | The inside edges do not include the space used by the window's scroll bar, | |
646 | display margins, fringes, header line, and/or mode line. */) | |
647 | (window) | |
648 | Lisp_Object window; | |
649 | { | |
6b61353c | 650 | register struct window *w = decode_any_window (window); |
c99a9eb3 RS |
651 | |
652 | return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w) | |
653 | + WINDOW_LEFT_MARGIN_COLS (w) | |
654 | + WINDOW_LEFT_FRINGE_COLS (w)), | |
655 | make_number (WINDOW_TOP_EDGE_LINE (w) | |
656 | + WINDOW_HEADER_LINE_LINES (w)), | |
f3fbdb1f | 657 | make_number (WINDOW_BOX_RIGHT_EDGE_COL (w) |
c99a9eb3 RS |
658 | - WINDOW_RIGHT_MARGIN_COLS (w) |
659 | - WINDOW_RIGHT_FRINGE_COLS (w)), | |
660 | make_number (WINDOW_BOTTOM_EDGE_LINE (w) | |
661 | - WINDOW_MODE_LINE_LINES (w))); | |
662 | } | |
663 | ||
664 | DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges, Swindow_inside_pixel_edges, 0, 1, 0, | |
a0a37a6f | 665 | doc: /* Return a list of the edge pixel coordinates of WINDOW. |
c99a9eb3 RS |
666 | \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame. |
667 | RIGHT is one more than the rightmost x position used by text in WINDOW, | |
668 | and BOTTOM is one more than the bottommost y position used by text in WINDOW. | |
669 | The inside edges do not include the space used by the window's scroll bar, | |
670 | display margins, fringes, header line, and/or mode line. */) | |
671 | (window) | |
672 | Lisp_Object window; | |
673 | { | |
6b61353c | 674 | register struct window *w = decode_any_window (window); |
c99a9eb3 RS |
675 | |
676 | return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w) | |
677 | + WINDOW_LEFT_MARGIN_WIDTH (w) | |
678 | + WINDOW_LEFT_FRINGE_WIDTH (w)), | |
679 | make_number (WINDOW_TOP_EDGE_Y (w) | |
680 | + WINDOW_HEADER_LINE_HEIGHT (w)), | |
f3fbdb1f | 681 | make_number (WINDOW_BOX_RIGHT_EDGE_X (w) |
c99a9eb3 RS |
682 | - WINDOW_RIGHT_MARGIN_WIDTH (w) |
683 | - WINDOW_RIGHT_FRINGE_WIDTH (w)), | |
684 | make_number (WINDOW_BOTTOM_EDGE_Y (w) | |
685 | - WINDOW_MODE_LINE_HEIGHT (w))); | |
686 | } | |
687 | ||
fbad6f9a | 688 | /* Test if the character at column *X, row *Y is within window W. |
341f3858 | 689 | If it is not, return ON_NOTHING; |
d5783c40 JB |
690 | if it is in the window's text area, |
691 | set *x and *y to its location relative to the upper left corner | |
692 | of the window, and | |
341f3858 KS |
693 | return ON_TEXT; |
694 | if it is on the window's modeline, return ON_MODE_LINE; | |
d5783c40 | 695 | if it is on the border between the window and its right sibling, |
341f3858 | 696 | return ON_VERTICAL_BORDER. |
6487f669 RS |
697 | if it is on a scroll bar, |
698 | return ON_SCROLL_BAR. | |
341f3858 | 699 | if it is on the window's top line, return ON_HEADER_LINE; |
81d189fd | 700 | if it is in left or right fringe of the window, |
341f3858 KS |
701 | return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y |
702 | to window-relative coordinates; | |
49b996e7 | 703 | if it is in the marginal area to the left/right of the window, |
341f3858 KS |
704 | return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y |
705 | to window-relative coordinates. | |
5500c422 GM |
706 | |
707 | X and Y are frame relative pixel coordinates. */ | |
708 | ||
7442878f | 709 | static enum window_part |
d5783c40 JB |
710 | coordinates_in_window (w, x, y) |
711 | register struct window *w; | |
712 | register int *x, *y; | |
713 | { | |
b0228ace GM |
714 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
715 | int left_x, right_x, top_y, bottom_y; | |
7442878f | 716 | enum window_part part; |
949cf20f KS |
717 | int ux = FRAME_COLUMN_WIDTH (f); |
718 | int x0 = WINDOW_LEFT_EDGE_X (w); | |
719 | int x1 = WINDOW_RIGHT_EDGE_X (w); | |
dad75588 GM |
720 | /* The width of the area where the vertical line can be dragged. |
721 | (Between mode lines for instance. */ | |
722 | int grabbable_width = ux; | |
949cf20f | 723 | int lmargin_width, rmargin_width, text_left, text_right; |
b0228ace | 724 | |
466539bc EZ |
725 | /* In what's below, we subtract 1 when computing right_x because we |
726 | want the rightmost pixel, which is given by left_pixel+width-1. */ | |
5500c422 GM |
727 | if (w->pseudo_window_p) |
728 | { | |
729 | left_x = 0; | |
949cf20f KS |
730 | right_x = WINDOW_TOTAL_WIDTH (w) - 1; |
731 | top_y = WINDOW_TOP_EDGE_Y (w); | |
732 | bottom_y = WINDOW_BOTTOM_EDGE_Y (w); | |
5500c422 GM |
733 | } |
734 | else | |
735 | { | |
949cf20f KS |
736 | left_x = WINDOW_BOX_LEFT_EDGE_X (w); |
737 | right_x = WINDOW_BOX_RIGHT_EDGE_X (w) - 1; | |
738 | top_y = WINDOW_TOP_EDGE_Y (w); | |
739 | bottom_y = WINDOW_BOTTOM_EDGE_Y (w); | |
5500c422 | 740 | } |
37962e60 | 741 | |
949cf20f KS |
742 | /* Outside any interesting row? */ |
743 | if (*y < top_y || *y >= bottom_y) | |
744 | return ON_NOTHING; | |
745 | ||
1cb794ba GM |
746 | /* On the mode line or header line? If it's near the start of |
747 | the mode or header line of window that's has a horizontal | |
748 | sibling, say it's on the vertical line. That's to be able | |
749 | to resize windows horizontally in case we're using toolkit | |
750 | scroll bars. */ | |
b0228ace | 751 | |
1cb794ba | 752 | if (WINDOW_WANTS_MODELINE_P (w) |
6b61353c | 753 | && *y >= bottom_y - CURRENT_MODE_LINE_HEIGHT (w)) |
1cb794ba | 754 | { |
949cf20f KS |
755 | part = ON_MODE_LINE; |
756 | ||
757 | header_vertical_border_check: | |
b0228ace GM |
758 | /* We're somewhere on the mode line. We consider the place |
759 | between mode lines of horizontally adjacent mode lines | |
9d14503e | 760 | as the vertical border. If scroll bars on the left, |
b0228ace | 761 | return the right window. */ |
949cf20f KS |
762 | if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) |
763 | || WINDOW_RIGHTMOST_P (w)) | |
b0228ace | 764 | { |
1ea40aa2 | 765 | if (!WINDOW_LEFTMOST_P (w) && eabs (*x - x0) < grabbable_width) |
f8c62b70 | 766 | { |
3f489dc7 KS |
767 | /* Convert X and Y to window relative coordinates. |
768 | Vertical border is at the left edge of window. */ | |
f8c62b70 NR |
769 | *x = max (0, *x - x0); |
770 | *y -= top_y; | |
771 | return ON_VERTICAL_BORDER; | |
772 | } | |
b0228ace | 773 | } |
79fd290e | 774 | else |
b0228ace | 775 | { |
1ea40aa2 | 776 | if (eabs (*x - x1) < grabbable_width) |
f8c62b70 | 777 | { |
3f489dc7 KS |
778 | /* Convert X and Y to window relative coordinates. |
779 | Vertical border is at the right edge of window. */ | |
f8c62b70 NR |
780 | *x = min (x1, *x) - x0; |
781 | *y -= top_y; | |
782 | return ON_VERTICAL_BORDER; | |
783 | } | |
b0228ace | 784 | } |
949cf20f | 785 | |
cb639b8f KS |
786 | if (*x < x0 || *x >= x1) |
787 | return ON_NOTHING; | |
788 | ||
a5303820 KS |
789 | /* Convert X and Y to window relative coordinates. |
790 | Mode line starts at left edge of window. */ | |
791 | *x -= x0; | |
792 | *y -= top_y; | |
949cf20f | 793 | return part; |
b0228ace | 794 | } |
949cf20f KS |
795 | |
796 | if (WINDOW_WANTS_HEADER_LINE_P (w) | |
949cf20f | 797 | && *y < top_y + CURRENT_HEADER_LINE_HEIGHT (w)) |
1cb794ba | 798 | { |
949cf20f KS |
799 | part = ON_HEADER_LINE; |
800 | goto header_vertical_border_check; | |
1cb794ba | 801 | } |
949cf20f | 802 | |
cb639b8f KS |
803 | if (*x < x0 || *x >= x1) |
804 | return ON_NOTHING; | |
805 | ||
949cf20f KS |
806 | /* Outside any interesting column? */ |
807 | if (*x < left_x || *x > right_x) | |
4d1add72 KS |
808 | { |
809 | *y -= top_y; | |
810 | return ON_SCROLL_BAR; | |
811 | } | |
949cf20f KS |
812 | |
813 | lmargin_width = window_box_width (w, LEFT_MARGIN_AREA); | |
814 | rmargin_width = window_box_width (w, RIGHT_MARGIN_AREA); | |
79fd290e | 815 | |
949cf20f KS |
816 | text_left = window_box_left (w, TEXT_AREA); |
817 | text_right = text_left + window_box_width (w, TEXT_AREA); | |
818 | ||
819 | if (FRAME_WINDOW_P (f)) | |
fbad6f9a | 820 | { |
447e9da0 | 821 | if (!w->pseudo_window_p |
949cf20f | 822 | && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w) |
447e9da0 | 823 | && !WINDOW_RIGHTMOST_P (w) |
1ea40aa2 | 824 | && (eabs (*x - right_x) < grabbable_width)) |
f8c62b70 | 825 | { |
3f489dc7 KS |
826 | /* Convert X and Y to window relative coordinates. |
827 | Vertical border is at the right edge of window. */ | |
f8c62b70 NR |
828 | *x = min (right_x, *x) - left_x; |
829 | *y -= top_y; | |
830 | return ON_VERTICAL_BORDER; | |
831 | } | |
fbad6f9a | 832 | } |
447e9da0 GM |
833 | else |
834 | { | |
835 | /* Need to say "*x > right_x" rather than >=, since on character | |
836 | terminals, the vertical line's x coordinate is right_x. */ | |
949cf20f KS |
837 | if (!w->pseudo_window_p |
838 | && !WINDOW_RIGHTMOST_P (w) | |
839 | && *x > right_x - ux) | |
b0228ace GM |
840 | { |
841 | /* On the border on the right side of the window? Assume that | |
842 | this area begins at RIGHT_X minus a canonical char width. */ | |
f8c62b70 NR |
843 | *x = min (right_x, *x) - left_x; |
844 | *y -= top_y; | |
949cf20f | 845 | return ON_VERTICAL_BORDER; |
b0228ace | 846 | } |
447e9da0 | 847 | } |
b0228ace | 848 | |
949cf20f KS |
849 | if (*x < text_left) |
850 | { | |
851 | if (lmargin_width > 0 | |
852 | && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) | |
853 | ? (*x >= left_x + WINDOW_LEFT_FRINGE_WIDTH (w)) | |
854 | : (*x < left_x + lmargin_width))) | |
a5303820 | 855 | { |
6b61353c | 856 | *x -= left_x; |
a5303820 KS |
857 | if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)) |
858 | *x -= WINDOW_LEFT_FRINGE_WIDTH (w); | |
859 | *y -= top_y; | |
860 | return ON_LEFT_MARGIN; | |
861 | } | |
949cf20f KS |
862 | |
863 | /* Convert X and Y to window-relative pixel coordinates. */ | |
864 | *x -= left_x; | |
865 | *y -= top_y; | |
866 | return ON_LEFT_FRINGE; | |
867 | } | |
868 | ||
869 | if (*x >= text_right) | |
870 | { | |
871 | if (rmargin_width > 0 | |
872 | && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) | |
873 | ? (*x < right_x - WINDOW_RIGHT_FRINGE_WIDTH (w)) | |
874 | : (*x >= right_x - rmargin_width))) | |
a5303820 | 875 | { |
66d41723 KS |
876 | *x -= right_x - rmargin_width; |
877 | if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)) | |
878 | *x += WINDOW_RIGHT_FRINGE_WIDTH (w); | |
a5303820 KS |
879 | *y -= top_y; |
880 | return ON_RIGHT_MARGIN; | |
881 | } | |
949cf20f KS |
882 | |
883 | /* Convert X and Y to window-relative pixel coordinates. */ | |
884 | *x -= left_x + WINDOW_LEFT_FRINGE_WIDTH (w); | |
885 | *y -= top_y; | |
886 | return ON_RIGHT_FRINGE; | |
887 | } | |
888 | ||
889 | /* Everything special ruled out - must be on text area */ | |
66d41723 | 890 | *x -= text_left; |
949cf20f KS |
891 | *y -= top_y; |
892 | return ON_TEXT; | |
d5783c40 JB |
893 | } |
894 | ||
b0228ace | 895 | |
d5783c40 | 896 | DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p, |
fdb82f93 PJ |
897 | Scoordinates_in_window_p, 2, 2, 0, |
898 | doc: /* Return non-nil if COORDINATES are in WINDOW. | |
899 | COORDINATES is a cons of the form (X . Y), X and Y being distances | |
900 | measured in characters from the upper-left corner of the frame. | |
901 | \(0 . 0) denotes the character in the upper left corner of the | |
902 | frame. | |
903 | If COORDINATES are in the text portion of WINDOW, | |
904 | the coordinates relative to the window are returned. | |
905 | If they are in the mode line of WINDOW, `mode-line' is returned. | |
906 | If they are in the top mode line of WINDOW, `header-line' is returned. | |
81d189fd KS |
907 | If they are in the left fringe of WINDOW, `left-fringe' is returned. |
908 | If they are in the right fringe of WINDOW, `right-fringe' is returned. | |
fdb82f93 | 909 | If they are on the border between WINDOW and its right sibling, |
49b996e7 GM |
910 | `vertical-line' is returned. |
911 | If they are in the windows's left or right marginal areas, `left-margin'\n\ | |
912 | or `right-margin' is returned. */) | |
fdb82f93 | 913 | (coordinates, window) |
d5783c40 JB |
914 | register Lisp_Object coordinates, window; |
915 | { | |
5500c422 GM |
916 | struct window *w; |
917 | struct frame *f; | |
d5783c40 | 918 | int x, y; |
5500c422 | 919 | Lisp_Object lx, ly; |
d5783c40 | 920 | |
6b61353c | 921 | CHECK_WINDOW (window); |
5500c422 GM |
922 | w = XWINDOW (window); |
923 | f = XFRAME (w->frame); | |
b7826503 | 924 | CHECK_CONS (coordinates); |
5500c422 GM |
925 | lx = Fcar (coordinates); |
926 | ly = Fcdr (coordinates); | |
b7826503 PJ |
927 | CHECK_NUMBER_OR_FLOAT (lx); |
928 | CHECK_NUMBER_OR_FLOAT (ly); | |
81159bb9 RS |
929 | x = FRAME_PIXEL_X_FROM_CANON_X (f, lx) + FRAME_INTERNAL_BORDER_WIDTH (f); |
930 | y = FRAME_PIXEL_Y_FROM_CANON_Y (f, ly) + FRAME_INTERNAL_BORDER_WIDTH (f); | |
5500c422 GM |
931 | |
932 | switch (coordinates_in_window (w, &x, &y)) | |
d5783c40 | 933 | { |
7442878f | 934 | case ON_NOTHING: |
d5783c40 JB |
935 | return Qnil; |
936 | ||
7442878f GM |
937 | case ON_TEXT: |
938 | /* X and Y are now window relative pixel coordinates. Convert | |
939 | them to canonical char units before returning them. */ | |
949cf20f KS |
940 | return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f, x), |
941 | FRAME_CANON_Y_FROM_PIXEL_Y (f, y)); | |
d5783c40 | 942 | |
7442878f | 943 | case ON_MODE_LINE: |
d5783c40 | 944 | return Qmode_line; |
37962e60 | 945 | |
7442878f | 946 | case ON_VERTICAL_BORDER: |
e5d77022 | 947 | return Qvertical_line; |
d5783c40 | 948 | |
7442878f | 949 | case ON_HEADER_LINE: |
045dee35 | 950 | return Qheader_line; |
5500c422 | 951 | |
7442878f GM |
952 | case ON_LEFT_FRINGE: |
953 | return Qleft_fringe; | |
177c0ea7 | 954 | |
7442878f GM |
955 | case ON_RIGHT_FRINGE: |
956 | return Qright_fringe; | |
fbad6f9a | 957 | |
49b996e7 GM |
958 | case ON_LEFT_MARGIN: |
959 | return Qleft_margin; | |
177c0ea7 | 960 | |
49b996e7 GM |
961 | case ON_RIGHT_MARGIN: |
962 | return Qright_margin; | |
963 | ||
6487f669 RS |
964 | case ON_SCROLL_BAR: |
965 | /* Historically we are supposed to return nil in this case. */ | |
966 | return Qnil; | |
967 | ||
d5783c40 JB |
968 | default: |
969 | abort (); | |
970 | } | |
971 | } | |
972 | ||
67492200 GM |
973 | |
974 | /* Callback for foreach_window, used in window_from_coordinates. | |
f95464e4 GM |
975 | Check if window W contains coordinates specified by USER_DATA which |
976 | is actually a pointer to a struct check_window_data CW. | |
977 | ||
978 | Check if window W contains coordinates *CW->x and *CW->y. If it | |
979 | does, return W in *CW->window, as Lisp_Object, and return in | |
5372262f | 980 | *CW->part the part of the window under coordinates *X,*Y. Return |
f95464e4 GM |
981 | zero from this function to stop iterating over windows. */ |
982 | ||
983 | struct check_window_data | |
984 | { | |
985 | Lisp_Object *window; | |
341f3858 KS |
986 | int *x, *y; |
987 | enum window_part *part; | |
f95464e4 | 988 | }; |
67492200 GM |
989 | |
990 | static int | |
f95464e4 | 991 | check_window_containing (w, user_data) |
67492200 | 992 | struct window *w; |
f95464e4 | 993 | void *user_data; |
67492200 | 994 | { |
f95464e4 | 995 | struct check_window_data *cw = (struct check_window_data *) user_data; |
7442878f GM |
996 | enum window_part found; |
997 | int continue_p = 1; | |
67492200 | 998 | |
f95464e4 | 999 | found = coordinates_in_window (w, cw->x, cw->y); |
7442878f | 1000 | if (found != ON_NOTHING) |
67492200 | 1001 | { |
341f3858 | 1002 | *cw->part = found; |
f95464e4 | 1003 | XSETWINDOW (*cw->window, w); |
7442878f | 1004 | continue_p = 0; |
67492200 | 1005 | } |
177c0ea7 | 1006 | |
7442878f | 1007 | return continue_p; |
67492200 GM |
1008 | } |
1009 | ||
1010 | ||
5500c422 | 1011 | /* Find the window containing frame-relative pixel position X/Y and |
949cf20f KS |
1012 | return it as a Lisp_Object. |
1013 | ||
1014 | If X, Y is on one of the window's special `window_part' elements, | |
1015 | set *PART to the id of that element, and return X and Y converted | |
1016 | to window relative coordinates in WX and WY. | |
1017 | ||
341f3858 | 1018 | If there is no window under X, Y return nil and leave *PART |
67492200 GM |
1019 | unmodified. TOOL_BAR_P non-zero means detect tool-bar windows. |
1020 | ||
1021 | This function was previously implemented with a loop cycling over | |
1022 | windows with Fnext_window, and starting with the frame's selected | |
1023 | window. It turned out that this doesn't work with an | |
1024 | implementation of next_window using Vwindow_list, because | |
1025 | FRAME_SELECTED_WINDOW (F) is not always contained in the window | |
1026 | tree of F when this function is called asynchronously from | |
1027 | note_mouse_highlight. The original loop didn't terminate in this | |
1028 | case. */ | |
5500c422 | 1029 | |
7ab12479 | 1030 | Lisp_Object |
949cf20f | 1031 | window_from_coordinates (f, x, y, part, wx, wy, tool_bar_p) |
67492200 | 1032 | struct frame *f; |
7ab12479 | 1033 | int x, y; |
341f3858 | 1034 | enum window_part *part; |
949cf20f | 1035 | int *wx, *wy; |
9ea173e8 | 1036 | int tool_bar_p; |
7ab12479 | 1037 | { |
67492200 | 1038 | Lisp_Object window; |
f95464e4 | 1039 | struct check_window_data cw; |
341f3858 KS |
1040 | enum window_part dummy; |
1041 | ||
1042 | if (part == 0) | |
1043 | part = &dummy; | |
5500c422 | 1044 | |
67492200 | 1045 | window = Qnil; |
f95464e4 GM |
1046 | cw.window = &window, cw.x = &x, cw.y = &y; cw.part = part; |
1047 | foreach_window (f, check_window_containing, &cw); | |
177c0ea7 | 1048 | |
67492200 GM |
1049 | /* If not found above, see if it's in the tool bar window, if a tool |
1050 | bar exists. */ | |
1051 | if (NILP (window) | |
1052 | && tool_bar_p | |
1053 | && WINDOWP (f->tool_bar_window) | |
949cf20f | 1054 | && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window)) > 0 |
7442878f GM |
1055 | && (coordinates_in_window (XWINDOW (f->tool_bar_window), &x, &y) |
1056 | != ON_NOTHING)) | |
5500c422 | 1057 | { |
341f3858 | 1058 | *part = ON_TEXT; |
67492200 | 1059 | window = f->tool_bar_window; |
5500c422 | 1060 | } |
37962e60 | 1061 | |
949cf20f KS |
1062 | if (wx) *wx = x; |
1063 | if (wy) *wy = y; | |
1064 | ||
67492200 | 1065 | return window; |
7ab12479 JB |
1066 | } |
1067 | ||
ab17c3f2 | 1068 | DEFUN ("window-at", Fwindow_at, Swindow_at, 2, 3, 0, |
fdb82f93 PJ |
1069 | doc: /* Return window containing coordinates X and Y on FRAME. |
1070 | If omitted, FRAME defaults to the currently selected frame. | |
1071 | The top left corner of the frame is considered to be row 0, | |
1072 | column 0. */) | |
1073 | (x, y, frame) | |
1074 | Lisp_Object x, y, frame; | |
7ab12479 | 1075 | { |
5500c422 | 1076 | struct frame *f; |
7ab12479 | 1077 | |
44fa5b1e | 1078 | if (NILP (frame)) |
1ae1a37d | 1079 | frame = selected_frame; |
b7826503 | 1080 | CHECK_LIVE_FRAME (frame); |
5500c422 | 1081 | f = XFRAME (frame); |
7ab12479 | 1082 | |
5500c422 | 1083 | /* Check that arguments are integers or floats. */ |
b7826503 PJ |
1084 | CHECK_NUMBER_OR_FLOAT (x); |
1085 | CHECK_NUMBER_OR_FLOAT (y); | |
5500c422 | 1086 | |
177c0ea7 | 1087 | return window_from_coordinates (f, |
2c77cf3b RS |
1088 | (FRAME_PIXEL_X_FROM_CANON_X (f, x) |
1089 | + FRAME_INTERNAL_BORDER_WIDTH (f)), | |
1090 | (FRAME_PIXEL_Y_FROM_CANON_Y (f, y) | |
1091 | + FRAME_INTERNAL_BORDER_WIDTH (f)), | |
949cf20f | 1092 | 0, 0, 0, 0); |
7ab12479 JB |
1093 | } |
1094 | ||
1095 | DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0, | |
fdb82f93 | 1096 | doc: /* Return current value of point in WINDOW. |
c85322d0 EZ |
1097 | WINDOW defaults to the selected window. |
1098 | ||
fdb82f93 PJ |
1099 | For a nonselected window, this is the value point would have |
1100 | if that window were selected. | |
1101 | ||
1102 | Note that, when WINDOW is the selected window and its buffer | |
1103 | is also currently selected, the value returned is the same as (point). | |
1104 | It would be more strictly correct to return the `top-level' value | |
1105 | of point, outside of any save-excursion forms. | |
1106 | But that is hard to define. */) | |
1107 | (window) | |
7ab12479 JB |
1108 | Lisp_Object window; |
1109 | { | |
1110 | register struct window *w = decode_window (window); | |
1111 | ||
1112 | if (w == XWINDOW (selected_window) | |
1113 | && current_buffer == XBUFFER (w->buffer)) | |
1114 | return Fpoint (); | |
1115 | return Fmarker_position (w->pointm); | |
1116 | } | |
1117 | ||
1118 | DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0, | |
fdb82f93 | 1119 | doc: /* Return position at which display currently starts in WINDOW. |
c85322d0 | 1120 | WINDOW defaults to the selected window. |
fdb82f93 PJ |
1121 | This is updated by redisplay or by calling `set-window-start'. */) |
1122 | (window) | |
7ab12479 JB |
1123 | Lisp_Object window; |
1124 | { | |
1125 | return Fmarker_position (decode_window (window)->start); | |
1126 | } | |
1127 | ||
8646118f RS |
1128 | /* This is text temporarily removed from the doc string below. |
1129 | ||
fdb82f93 PJ |
1130 | This function returns nil if the position is not currently known. |
1131 | That happens when redisplay is preempted and doesn't finish. | |
1132 | If in that case you want to compute where the end of the window would | |
1133 | have been if redisplay had finished, do this: | |
1134 | (save-excursion | |
1135 | (goto-char (window-start window)) | |
1136 | (vertical-motion (1- (window-height window)) window) | |
8646118f RS |
1137 | (point))") */ |
1138 | ||
478292ed | 1139 | DEFUN ("window-end", Fwindow_end, Swindow_end, 0, 2, 0, |
fdb82f93 | 1140 | doc: /* Return position at which display currently ends in WINDOW. |
c85322d0 | 1141 | WINDOW defaults to the selected window. |
fdb82f93 PJ |
1142 | This is updated by redisplay, when it runs to completion. |
1143 | Simply changing the buffer text or setting `window-start' | |
1144 | does not update this value. | |
a0a37a6f LT |
1145 | Return nil if there is no recorded value. \(This can happen if the |
1146 | last redisplay of WINDOW was preempted, and did not finish.) | |
fdb82f93 PJ |
1147 | If UPDATE is non-nil, compute the up-to-date position |
1148 | if it isn't already recorded. */) | |
1149 | (window, update) | |
478292ed | 1150 | Lisp_Object window, update; |
7ab12479 JB |
1151 | { |
1152 | Lisp_Object value; | |
1153 | struct window *w = decode_window (window); | |
5a41ab94 | 1154 | Lisp_Object buf; |
31790df3 | 1155 | struct buffer *b; |
5a41ab94 RS |
1156 | |
1157 | buf = w->buffer; | |
b7826503 | 1158 | CHECK_BUFFER (buf); |
b3a10345 | 1159 | b = XBUFFER (buf); |
5a41ab94 | 1160 | |
8646118f | 1161 | #if 0 /* This change broke some things. We should make it later. */ |
7250968e RS |
1162 | /* If we don't know the end position, return nil. |
1163 | The user can compute it with vertical-motion if he wants to. | |
1164 | It would be nicer to do it automatically, | |
1165 | but that's so slow that it would probably bother people. */ | |
1166 | if (NILP (w->window_end_valid)) | |
1167 | return Qnil; | |
8646118f | 1168 | #endif |
7250968e | 1169 | |
478292ed RS |
1170 | if (! NILP (update) |
1171 | && ! (! NILP (w->window_end_valid) | |
dfc265a3 | 1172 | && XFASTINT (w->last_modified) >= BUF_MODIFF (b) |
4c9564e8 | 1173 | && XFASTINT (w->last_overlay_modified) >= BUF_OVERLAY_MODIFF (b)) |
41791a20 | 1174 | && !noninteractive) |
478292ed | 1175 | { |
cbc099e5 GM |
1176 | struct text_pos startp; |
1177 | struct it it; | |
b3a10345 KS |
1178 | struct buffer *old_buffer = NULL; |
1179 | ||
1180 | /* Cannot use Fvertical_motion because that function doesn't | |
1181 | cope with variable-height lines. */ | |
1182 | if (b != current_buffer) | |
1183 | { | |
1184 | old_buffer = current_buffer; | |
1185 | set_buffer_internal (b); | |
1186 | } | |
2d6d9df0 GM |
1187 | |
1188 | /* In case W->start is out of the range, use something | |
cb795ec4 | 1189 | reasonable. This situation occurred when loading a file with |
2d6d9df0 GM |
1190 | `-l' containing a call to `rmail' with subsequent other |
1191 | commands. At the end, W->start happened to be BEG, while | |
cbc099e5 | 1192 | rmail had already narrowed the buffer. */ |
2d6d9df0 | 1193 | if (XMARKER (w->start)->charpos < BEGV) |
cbc099e5 | 1194 | SET_TEXT_POS (startp, BEGV, BEGV_BYTE); |
2d6d9df0 | 1195 | else if (XMARKER (w->start)->charpos > ZV) |
cbc099e5 | 1196 | SET_TEXT_POS (startp, ZV, ZV_BYTE); |
2d6d9df0 | 1197 | else |
cbc099e5 GM |
1198 | SET_TEXT_POS_FROM_MARKER (startp, w->start); |
1199 | ||
cbc099e5 GM |
1200 | start_display (&it, w, startp); |
1201 | move_it_vertically (&it, window_box_height (w)); | |
c3c45f65 GM |
1202 | if (it.current_y < it.last_visible_y) |
1203 | move_it_past_eol (&it); | |
cbc099e5 | 1204 | value = make_number (IT_CHARPOS (it)); |
177c0ea7 | 1205 | |
99593a9d GM |
1206 | if (old_buffer) |
1207 | set_buffer_internal (old_buffer); | |
478292ed RS |
1208 | } |
1209 | else | |
b3a10345 | 1210 | XSETINT (value, BUF_Z (b) - XFASTINT (w->window_end_pos)); |
7ab12479 JB |
1211 | |
1212 | return value; | |
1213 | } | |
1214 | ||
1215 | DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0, | |
a0a37a6f LT |
1216 | doc: /* Make point value in WINDOW be at position POS in WINDOW's buffer. |
1217 | Return POS. */) | |
fdb82f93 | 1218 | (window, pos) |
7ab12479 JB |
1219 | Lisp_Object window, pos; |
1220 | { | |
1221 | register struct window *w = decode_window (window); | |
1222 | ||
b7826503 | 1223 | CHECK_NUMBER_COERCE_MARKER (pos); |
e90c4fe6 RS |
1224 | if (w == XWINDOW (selected_window) |
1225 | && XBUFFER (w->buffer) == current_buffer) | |
7ab12479 JB |
1226 | Fgoto_char (pos); |
1227 | else | |
1228 | set_marker_restricted (w->pointm, pos, w->buffer); | |
799417bd | 1229 | |
0685cb3c GM |
1230 | /* We have to make sure that redisplay updates the window to show |
1231 | the new value of point. */ | |
1232 | if (!EQ (window, selected_window)) | |
799417bd | 1233 | ++windows_or_buffers_changed; |
177c0ea7 | 1234 | |
7ab12479 JB |
1235 | return pos; |
1236 | } | |
1237 | ||
1238 | DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0, | |
fdb82f93 | 1239 | doc: /* Make display in WINDOW start at position POS in WINDOW's buffer. |
a0a37a6f | 1240 | Return POS. |
fdb82f93 PJ |
1241 | Optional third arg NOFORCE non-nil inhibits next redisplay |
1242 | from overriding motion of point in order to display at this exact start. */) | |
1243 | (window, pos, noforce) | |
7ab12479 JB |
1244 | Lisp_Object window, pos, noforce; |
1245 | { | |
1246 | register struct window *w = decode_window (window); | |
1247 | ||
b7826503 | 1248 | CHECK_NUMBER_COERCE_MARKER (pos); |
7ab12479 JB |
1249 | set_marker_restricted (w->start, pos, w->buffer); |
1250 | /* this is not right, but much easier than doing what is right. */ | |
1251 | w->start_at_line_beg = Qnil; | |
265a9e55 | 1252 | if (NILP (noforce)) |
7ab12479 JB |
1253 | w->force_start = Qt; |
1254 | w->update_mode_line = Qt; | |
d834a2e9 | 1255 | XSETFASTINT (w->last_modified, 0); |
3cd21523 | 1256 | XSETFASTINT (w->last_overlay_modified, 0); |
62c07cc7 JB |
1257 | if (!EQ (window, selected_window)) |
1258 | windows_or_buffers_changed++; | |
ce7fae7d | 1259 | |
7ab12479 JB |
1260 | return pos; |
1261 | } | |
1262 | ||
1263 | DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p, | |
1264 | 1, 1, 0, | |
fdb82f93 PJ |
1265 | doc: /* Return WINDOW's dedicated object, usually t or nil. |
1266 | See also `set-window-dedicated-p'. */) | |
1267 | (window) | |
7ab12479 JB |
1268 | Lisp_Object window; |
1269 | { | |
1270 | return decode_window (window)->dedicated; | |
1271 | } | |
1272 | ||
d207b766 RS |
1273 | DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p, |
1274 | Sset_window_dedicated_p, 2, 2, 0, | |
fdb82f93 PJ |
1275 | doc: /* Control whether WINDOW is dedicated to the buffer it displays. |
1276 | If it is dedicated, Emacs will not automatically change | |
1277 | which buffer appears in it. | |
1278 | The second argument is the new value for the dedication flag; | |
cfbb2395 | 1279 | non-nil means yes. */) |
fdb82f93 PJ |
1280 | (window, arg) |
1281 | Lisp_Object window, arg; | |
7ab12479 JB |
1282 | { |
1283 | register struct window *w = decode_window (window); | |
1284 | ||
2d0834cc | 1285 | w->dedicated = arg; |
7ab12479 JB |
1286 | |
1287 | return w->dedicated; | |
1288 | } | |
1289 | ||
cfbb2395 JB |
1290 | DEFUN ("window-parameters", Fwindow_parameters, Swindow_parameters, |
1291 | 0, 1, 0, | |
1292 | doc: /* Return the parameters-alist of window WINDOW. | |
1293 | It is a list of elements of the form (PARAMETER . VALUE). | |
cfbb2395 JB |
1294 | If WINDOW is omitted, return information on the currently selected window. */) |
1295 | (window) | |
1296 | Lisp_Object window; | |
1297 | { | |
927abf37 | 1298 | return Fcopy_alist (decode_window (window)->window_parameters); |
cfbb2395 JB |
1299 | } |
1300 | ||
1301 | DEFUN ("window-parameter", Fwindow_parameter, Swindow_parameter, | |
1302 | 2, 2, 0, | |
1303 | doc: /* Return WINDOW's value for parameter PARAMETER. | |
1304 | If WINDOW is nil, describe the currently selected window. */) | |
1305 | (window, parameter) | |
1306 | Lisp_Object window, parameter; | |
1307 | { | |
927abf37 JB |
1308 | Lisp_Object result; |
1309 | ||
1310 | result = Fassq (parameter, decode_window (window)->window_parameters); | |
1311 | return CDR_SAFE (result); | |
cfbb2395 JB |
1312 | } |
1313 | ||
1314 | ||
1315 | DEFUN ("set-window-parameter", Fset_window_parameter, | |
1316 | Sset_window_parameter, 3, 3, 0, | |
1317 | doc: /* Set window parameter PARAMETER to VALUE on WINDOW. | |
9d14503e | 1318 | If WINDOW is nil, use the currently selected window. |
927abf37 | 1319 | Return VALUE. */) |
cfbb2395 JB |
1320 | (window, parameter, value) |
1321 | Lisp_Object window, parameter, value; | |
1322 | { | |
1323 | register struct window *w = decode_window (window); | |
1324 | Lisp_Object old_alist_elt; | |
1325 | ||
1326 | old_alist_elt = Fassq (parameter, w->window_parameters); | |
1327 | if (EQ (old_alist_elt, Qnil)) | |
1328 | w->window_parameters = Fcons (Fcons (parameter, value), w->window_parameters); | |
1329 | else | |
1330 | Fsetcdr (old_alist_elt, value); | |
927abf37 | 1331 | return value; |
cfbb2395 JB |
1332 | } |
1333 | ||
1334 | ||
7ab12479 JB |
1335 | DEFUN ("window-display-table", Fwindow_display_table, Swindow_display_table, |
1336 | 0, 1, 0, | |
c85322d0 EZ |
1337 | doc: /* Return the display-table that WINDOW is using. |
1338 | WINDOW defaults to the selected window. */) | |
fdb82f93 | 1339 | (window) |
7ab12479 JB |
1340 | Lisp_Object window; |
1341 | { | |
1342 | return decode_window (window)->display_table; | |
1343 | } | |
1344 | ||
5500c422 GM |
1345 | /* Get the display table for use on window W. This is either W's |
1346 | display table or W's buffer's display table. Ignore the specified | |
1347 | tables if they are not valid; if no valid table is specified, | |
1348 | return 0. */ | |
7ab12479 | 1349 | |
319315f1 | 1350 | struct Lisp_Char_Table * |
7ab12479 JB |
1351 | window_display_table (w) |
1352 | struct window *w; | |
1353 | { | |
c756cdbe GM |
1354 | struct Lisp_Char_Table *dp = NULL; |
1355 | ||
1356 | if (DISP_TABLE_P (w->display_table)) | |
1357 | dp = XCHAR_TABLE (w->display_table); | |
1358 | else if (BUFFERP (w->buffer)) | |
1359 | { | |
1360 | struct buffer *b = XBUFFER (w->buffer); | |
177c0ea7 | 1361 | |
c756cdbe GM |
1362 | if (DISP_TABLE_P (b->display_table)) |
1363 | dp = XCHAR_TABLE (b->display_table); | |
1364 | else if (DISP_TABLE_P (Vstandard_display_table)) | |
1365 | dp = XCHAR_TABLE (Vstandard_display_table); | |
1366 | } | |
171d003c | 1367 | |
c756cdbe | 1368 | return dp; |
7ab12479 JB |
1369 | } |
1370 | ||
3a2712f9 | 1371 | DEFUN ("set-window-display-table", Fset_window_display_table, Sset_window_display_table, 2, 2, 0, |
fdb82f93 PJ |
1372 | doc: /* Set WINDOW's display-table to TABLE. */) |
1373 | (window, table) | |
7ab12479 JB |
1374 | register Lisp_Object window, table; |
1375 | { | |
1376 | register struct window *w; | |
7ab12479 JB |
1377 | |
1378 | w = decode_window (window); | |
1379 | w->display_table = table; | |
1380 | return table; | |
1381 | } | |
1382 | \f | |
1383 | /* Record info on buffer window w is displaying | |
1384 | when it is about to cease to display that buffer. */ | |
dfcf069d | 1385 | static void |
7ab12479 JB |
1386 | unshow_buffer (w) |
1387 | register struct window *w; | |
1388 | { | |
12cae7c0 | 1389 | Lisp_Object buf; |
b73ea88e | 1390 | struct buffer *b; |
7ab12479 | 1391 | |
12cae7c0 | 1392 | buf = w->buffer; |
b73ea88e RS |
1393 | b = XBUFFER (buf); |
1394 | if (b != XMARKER (w->pointm)->buffer) | |
7ab12479 JB |
1395 | abort (); |
1396 | ||
573f41ab | 1397 | #if 0 |
7ab12479 JB |
1398 | if (w == XWINDOW (selected_window) |
1399 | || ! EQ (buf, XWINDOW (selected_window)->buffer)) | |
1400 | /* Do this except when the selected window's buffer | |
1401 | is being removed from some other window. */ | |
573f41ab RS |
1402 | #endif |
1403 | /* last_window_start records the start position that this buffer | |
1404 | had in the last window to be disconnected from it. | |
1405 | Now that this statement is unconditional, | |
1406 | it is possible for the buffer to be displayed in the | |
1407 | selected window, while last_window_start reflects another | |
1408 | window which was recently showing the same buffer. | |
1409 | Some people might say that might be a good thing. Let's see. */ | |
b73ea88e | 1410 | b->last_window_start = marker_position (w->start); |
7ab12479 JB |
1411 | |
1412 | /* Point in the selected window's buffer | |
1413 | is actually stored in that buffer, and the window's pointm isn't used. | |
1414 | So don't clobber point in that buffer. */ | |
719eaeb1 GM |
1415 | if (! EQ (buf, XWINDOW (selected_window)->buffer) |
1416 | /* This line helps to fix Horsley's testbug.el bug. */ | |
8801a864 KR |
1417 | && !(WINDOWP (b->last_selected_window) |
1418 | && w != XWINDOW (b->last_selected_window) | |
719eaeb1 | 1419 | && EQ (buf, XWINDOW (b->last_selected_window)->buffer))) |
b73ea88e RS |
1420 | temp_set_point_both (b, |
1421 | clip_to_bounds (BUF_BEGV (b), | |
1422 | XMARKER (w->pointm)->charpos, | |
1423 | BUF_ZV (b)), | |
1424 | clip_to_bounds (BUF_BEGV_BYTE (b), | |
1425 | marker_byte_position (w->pointm), | |
1426 | BUF_ZV_BYTE (b))); | |
177c0ea7 | 1427 | |
8801a864 KR |
1428 | if (WINDOWP (b->last_selected_window) |
1429 | && w == XWINDOW (b->last_selected_window)) | |
719eaeb1 | 1430 | b->last_selected_window = Qnil; |
7ab12479 JB |
1431 | } |
1432 | ||
1433 | /* Put replacement into the window structure in place of old. */ | |
dfcf069d | 1434 | static void |
7ab12479 JB |
1435 | replace_window (old, replacement) |
1436 | Lisp_Object old, replacement; | |
1437 | { | |
1438 | register Lisp_Object tem; | |
1439 | register struct window *o = XWINDOW (old), *p = XWINDOW (replacement); | |
1440 | ||
44fa5b1e JB |
1441 | /* If OLD is its frame's root_window, then replacement is the new |
1442 | root_window for that frame. */ | |
7ab12479 | 1443 | |
7f4161e0 | 1444 | if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame)))) |
44fa5b1e | 1445 | FRAME_ROOT_WINDOW (XFRAME (o->frame)) = replacement; |
7ab12479 | 1446 | |
949cf20f KS |
1447 | p->left_col = o->left_col; |
1448 | p->top_line = o->top_line; | |
1449 | p->total_cols = o->total_cols; | |
1450 | p->total_lines = o->total_lines; | |
5500c422 GM |
1451 | p->desired_matrix = p->current_matrix = 0; |
1452 | p->vscroll = 0; | |
1453 | bzero (&p->cursor, sizeof (p->cursor)); | |
1454 | bzero (&p->last_cursor, sizeof (p->last_cursor)); | |
1455 | bzero (&p->phys_cursor, sizeof (p->phys_cursor)); | |
1456 | p->phys_cursor_type = -1; | |
4b26579e | 1457 | p->phys_cursor_width = -1; |
5500c422 GM |
1458 | p->must_be_updated_p = 0; |
1459 | p->pseudo_window_p = 0; | |
1460 | XSETFASTINT (p->window_end_vpos, 0); | |
1461 | XSETFASTINT (p->window_end_pos, 0); | |
1462 | p->window_end_valid = Qnil; | |
7bbb5782 | 1463 | p->frozen_window_start_p = 0; |
949cf20f | 1464 | p->orig_top_line = p->orig_total_lines = Qnil; |
7ab12479 JB |
1465 | |
1466 | p->next = tem = o->next; | |
265a9e55 | 1467 | if (!NILP (tem)) |
7ab12479 JB |
1468 | XWINDOW (tem)->prev = replacement; |
1469 | ||
1470 | p->prev = tem = o->prev; | |
265a9e55 | 1471 | if (!NILP (tem)) |
7ab12479 JB |
1472 | XWINDOW (tem)->next = replacement; |
1473 | ||
1474 | p->parent = tem = o->parent; | |
265a9e55 | 1475 | if (!NILP (tem)) |
7ab12479 JB |
1476 | { |
1477 | if (EQ (XWINDOW (tem)->vchild, old)) | |
1478 | XWINDOW (tem)->vchild = replacement; | |
1479 | if (EQ (XWINDOW (tem)->hchild, old)) | |
1480 | XWINDOW (tem)->hchild = replacement; | |
1481 | } | |
1482 | ||
1483 | /*** Here, if replacement is a vertical combination | |
1484 | and so is its new parent, we should make replacement's | |
1485 | children be children of that parent instead. ***/ | |
1486 | } | |
1487 | ||
1488 | DEFUN ("delete-window", Fdelete_window, Sdelete_window, 0, 1, "", | |
fdb82f93 PJ |
1489 | doc: /* Remove WINDOW from the display. Default is selected window. */) |
1490 | (window) | |
7ab12479 | 1491 | register Lisp_Object window; |
543f5fb1 | 1492 | { |
eeca6f6f SM |
1493 | struct frame *f; |
1494 | if (NILP (window)) | |
1495 | window = selected_window; | |
1496 | f = XFRAME (WINDOW_FRAME (XWINDOW (window))); | |
543f5fb1 RS |
1497 | delete_window (window); |
1498 | ||
eeca6f6f | 1499 | run_window_configuration_change_hook (f); |
543f5fb1 RS |
1500 | |
1501 | return Qnil; | |
1502 | } | |
1503 | ||
5e14b1fc | 1504 | void |
543f5fb1 RS |
1505 | delete_window (window) |
1506 | register Lisp_Object window; | |
7ab12479 JB |
1507 | { |
1508 | register Lisp_Object tem, parent, sib; | |
1509 | register struct window *p; | |
1510 | register struct window *par; | |
951f9df5 | 1511 | struct frame *f; |
7ab12479 | 1512 | |
605be8af JB |
1513 | /* Because this function is called by other C code on non-leaf |
1514 | windows, the CHECK_LIVE_WINDOW macro would choke inappropriately, | |
1515 | so we can't decode_window here. */ | |
eeca6f6f | 1516 | CHECK_WINDOW (window); |
7ab12479 | 1517 | p = XWINDOW (window); |
605be8af | 1518 | |
0d384044 | 1519 | /* It's a no-op to delete an already-deleted window. */ |
605be8af JB |
1520 | if (NILP (p->buffer) |
1521 | && NILP (p->hchild) | |
1522 | && NILP (p->vchild)) | |
296b535c | 1523 | return; |
605be8af | 1524 | |
7ab12479 | 1525 | parent = p->parent; |
265a9e55 | 1526 | if (NILP (parent)) |
7ab12479 JB |
1527 | error ("Attempt to delete minibuffer or sole ordinary window"); |
1528 | par = XWINDOW (parent); | |
1529 | ||
1530 | windows_or_buffers_changed++; | |
67492200 | 1531 | Vwindow_list = Qnil; |
951f9df5 GM |
1532 | f = XFRAME (WINDOW_FRAME (p)); |
1533 | FRAME_WINDOW_SIZES_CHANGED (f) = 1; | |
7ab12479 | 1534 | |
605be8af JB |
1535 | /* Are we trying to delete any frame's selected window? */ |
1536 | { | |
192c3131 | 1537 | Lisp_Object swindow, pwindow; |
605be8af | 1538 | |
0def0403 RS |
1539 | /* See if the frame's selected window is either WINDOW |
1540 | or any subwindow of it, by finding all that window's parents | |
1541 | and comparing each one with WINDOW. */ | |
192c3131 | 1542 | swindow = FRAME_SELECTED_WINDOW (f); |
0def0403 | 1543 | |
192c3131 | 1544 | while (1) |
0def0403 | 1545 | { |
192c3131 RS |
1546 | pwindow = swindow; |
1547 | while (!NILP (pwindow)) | |
1548 | { | |
1549 | if (EQ (window, pwindow)) | |
1550 | break; | |
1551 | pwindow = XWINDOW (pwindow)->parent; | |
1552 | } | |
1553 | ||
1554 | /* If the window being deleted is not a parent of SWINDOW, | |
1555 | then SWINDOW is ok as the new selected window. */ | |
1556 | if (!EQ (window, pwindow)) | |
0def0403 | 1557 | break; |
192c3131 | 1558 | /* Otherwise, try another window for SWINDOW. */ |
3b8c0c70 | 1559 | swindow = Fnext_window (swindow, Qlambda, Qnil); |
192c3131 RS |
1560 | |
1561 | /* If we get back to the frame's selected window, | |
1562 | it means there was no acceptable alternative, | |
1563 | so we cannot delete. */ | |
1564 | if (EQ (swindow, FRAME_SELECTED_WINDOW (f))) | |
1565 | error ("Cannot delete window"); | |
0def0403 RS |
1566 | } |
1567 | ||
192c3131 RS |
1568 | /* If we need to change SWINDOW, do it. */ |
1569 | if (! EQ (swindow, FRAME_SELECTED_WINDOW (f))) | |
605be8af | 1570 | { |
605be8af JB |
1571 | /* If we're about to delete the selected window on the |
1572 | selected frame, then we should use Fselect_window to select | |
1573 | the new window. On the other hand, if we're about to | |
1574 | delete the selected window on any other frame, we shouldn't do | |
1575 | anything but set the frame's selected_window slot. */ | |
192c3131 | 1576 | if (EQ (FRAME_SELECTED_WINDOW (f), selected_window)) |
14d87dc9 | 1577 | Fselect_window (swindow, Qnil); |
605be8af | 1578 | else |
192c3131 | 1579 | FRAME_SELECTED_WINDOW (f) = swindow; |
605be8af JB |
1580 | } |
1581 | } | |
7ab12479 | 1582 | |
0d384044 RS |
1583 | /* Now we know we can delete this one. */ |
1584 | window_deletion_count++; | |
1585 | ||
7ab12479 JB |
1586 | tem = p->buffer; |
1587 | /* tem is null for dummy parent windows | |
1588 | (which have inferiors but not any contents themselves) */ | |
265a9e55 | 1589 | if (!NILP (tem)) |
7ab12479 JB |
1590 | { |
1591 | unshow_buffer (p); | |
2d0834cc SM |
1592 | unchain_marker (XMARKER (p->pointm)); |
1593 | unchain_marker (XMARKER (p->start)); | |
7ab12479 JB |
1594 | } |
1595 | ||
05e71564 GM |
1596 | /* Free window glyph matrices. It is sure that they are allocated |
1597 | again when ADJUST_GLYPHS is called. Block input so that expose | |
1598 | events and other events that access glyph matrices are not | |
1599 | processed while we are changing them. */ | |
1600 | BLOCK_INPUT; | |
951f9df5 | 1601 | free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f))); |
5500c422 | 1602 | |
7ab12479 | 1603 | tem = p->next; |
265a9e55 | 1604 | if (!NILP (tem)) |
7ab12479 JB |
1605 | XWINDOW (tem)->prev = p->prev; |
1606 | ||
1607 | tem = p->prev; | |
265a9e55 | 1608 | if (!NILP (tem)) |
7ab12479 JB |
1609 | XWINDOW (tem)->next = p->next; |
1610 | ||
1611 | if (EQ (window, par->hchild)) | |
1612 | par->hchild = p->next; | |
1613 | if (EQ (window, par->vchild)) | |
1614 | par->vchild = p->next; | |
1615 | ||
1616 | /* Find one of our siblings to give our space to. */ | |
1617 | sib = p->prev; | |
265a9e55 | 1618 | if (NILP (sib)) |
7ab12479 JB |
1619 | { |
1620 | /* If p gives its space to its next sibling, that sibling needs | |
1621 | to have its top/left side pulled back to where p's is. | |
1622 | set_window_{height,width} will re-position the sibling's | |
1623 | children. */ | |
1624 | sib = p->next; | |
949cf20f KS |
1625 | XWINDOW (sib)->top_line = p->top_line; |
1626 | XWINDOW (sib)->left_col = p->left_col; | |
7ab12479 JB |
1627 | } |
1628 | ||
1629 | /* Stretch that sibling. */ | |
265a9e55 | 1630 | if (!NILP (par->vchild)) |
7ab12479 | 1631 | set_window_height (sib, |
949cf20f | 1632 | XFASTINT (XWINDOW (sib)->total_lines) + XFASTINT (p->total_lines), |
7ab12479 | 1633 | 1); |
265a9e55 | 1634 | if (!NILP (par->hchild)) |
7ab12479 | 1635 | set_window_width (sib, |
949cf20f | 1636 | XFASTINT (XWINDOW (sib)->total_cols) + XFASTINT (p->total_cols), |
7ab12479 JB |
1637 | 1); |
1638 | ||
1639 | /* If parent now has only one child, | |
1640 | put the child into the parent's place. */ | |
7ab12479 | 1641 | tem = par->hchild; |
265a9e55 | 1642 | if (NILP (tem)) |
7ab12479 | 1643 | tem = par->vchild; |
5494d7bc | 1644 | if (NILP (XWINDOW (tem)->next)) { |
7ab12479 | 1645 | replace_window (parent, tem); |
5494d7bc JD |
1646 | par = XWINDOW (tem); |
1647 | } | |
605be8af JB |
1648 | |
1649 | /* Since we may be deleting combination windows, we must make sure that | |
1650 | not only p but all its children have been marked as deleted. */ | |
1651 | if (! NILP (p->hchild)) | |
1652 | delete_all_subwindows (XWINDOW (p->hchild)); | |
1653 | else if (! NILP (p->vchild)) | |
1654 | delete_all_subwindows (XWINDOW (p->vchild)); | |
1655 | ||
1656 | /* Mark this window as deleted. */ | |
1657 | p->buffer = p->hchild = p->vchild = Qnil; | |
5500c422 | 1658 | |
5494d7bc JD |
1659 | if (! NILP (par->parent)) |
1660 | par = XWINDOW (par->parent); | |
1661 | ||
1662 | /* Check if we have a v/hchild with a v/hchild. In that case remove | |
1663 | one of them. */ | |
ae12ecd7 | 1664 | |
5494d7bc JD |
1665 | if (! NILP (par->vchild) && ! NILP (XWINDOW (par->vchild)->vchild)) |
1666 | { | |
1667 | p = XWINDOW (par->vchild); | |
1668 | par->vchild = p->vchild; | |
1669 | tem = p->vchild; | |
1670 | } | |
1671 | else if (! NILP (par->hchild) && ! NILP (XWINDOW (par->hchild)->hchild)) | |
1672 | { | |
1673 | p = XWINDOW (par->hchild); | |
1674 | par->hchild = p->hchild; | |
1675 | tem = p->hchild; | |
1676 | } | |
1677 | else | |
1678 | p = 0; | |
1679 | ||
1680 | if (p) | |
1681 | { | |
1682 | while (! NILP (tem)) { | |
1683 | XWINDOW (tem)->parent = p->parent; | |
1684 | if (NILP (XWINDOW (tem)->next)) | |
1685 | break; | |
1686 | tem = XWINDOW (tem)->next; | |
1687 | } | |
1688 | if (! NILP (tem)) { | |
1689 | /* The next of the v/hchild we are removing is now the next of the | |
1690 | last child for the v/hchild: | |
1691 | Before v/hchild -> v/hchild -> next1 -> next2 | |
1692 | | | |
1693 | -> next3 | |
1694 | After: v/hchild -> next1 -> next2 -> next3 | |
1695 | */ | |
1696 | XWINDOW (tem)->next = p->next; | |
1697 | if (! NILP (p->next)) | |
1698 | XWINDOW (p->next)->prev = tem; | |
1699 | } | |
1700 | p->next = p->prev = p->vchild = p->hchild = p->buffer = Qnil; | |
1701 | } | |
1702 | ||
1703 | ||
5500c422 | 1704 | /* Adjust glyph matrices. */ |
951f9df5 | 1705 | adjust_glyphs (f); |
05e71564 | 1706 | UNBLOCK_INPUT; |
7ab12479 | 1707 | } |
67492200 GM |
1708 | |
1709 | ||
7ab12479 | 1710 | \f |
67492200 GM |
1711 | /*********************************************************************** |
1712 | Window List | |
1713 | ***********************************************************************/ | |
1714 | ||
f95464e4 GM |
1715 | /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object |
1716 | pointer. This is a callback function for foreach_window, used in | |
1717 | function window_list. */ | |
67492200 GM |
1718 | |
1719 | static int | |
f95464e4 | 1720 | add_window_to_list (w, user_data) |
67492200 | 1721 | struct window *w; |
f95464e4 | 1722 | void *user_data; |
67492200 | 1723 | { |
f95464e4 | 1724 | Lisp_Object *list = (Lisp_Object *) user_data; |
67492200 GM |
1725 | Lisp_Object window; |
1726 | XSETWINDOW (window, w); | |
212116d6 | 1727 | *list = Fcons (window, *list); |
67492200 GM |
1728 | return 1; |
1729 | } | |
1730 | ||
1731 | ||
1732 | /* Return a list of all windows, for use by next_window. If | |
1733 | Vwindow_list is a list, return that list. Otherwise, build a new | |
1734 | list, cache it in Vwindow_list, and return that. */ | |
1735 | ||
1736 | static Lisp_Object | |
1737 | window_list () | |
1738 | { | |
1739 | if (!CONSP (Vwindow_list)) | |
1740 | { | |
1741 | Lisp_Object tail; | |
212116d6 | 1742 | |
67492200 GM |
1743 | Vwindow_list = Qnil; |
1744 | for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) | |
212116d6 GM |
1745 | { |
1746 | Lisp_Object args[2]; | |
1747 | ||
1748 | /* We are visiting windows in canonical order, and add | |
1749 | new windows at the front of args[1], which means we | |
1750 | have to reverse this list at the end. */ | |
1751 | args[1] = Qnil; | |
1752 | foreach_window (XFRAME (XCAR (tail)), add_window_to_list, &args[1]); | |
1753 | args[0] = Vwindow_list; | |
1754 | args[1] = Fnreverse (args[1]); | |
1755 | Vwindow_list = Fnconc (2, args); | |
1756 | } | |
67492200 | 1757 | } |
177c0ea7 | 1758 | |
67492200 GM |
1759 | return Vwindow_list; |
1760 | } | |
1761 | ||
1762 | ||
118ea242 GM |
1763 | /* Value is non-zero if WINDOW satisfies the constraints given by |
1764 | OWINDOW, MINIBUF and ALL_FRAMES. | |
67492200 | 1765 | |
118ea242 GM |
1766 | MINIBUF t means WINDOW may be minibuffer windows. |
1767 | `lambda' means WINDOW may not be a minibuffer window. | |
1768 | a window means a specific minibuffer window | |
67492200 | 1769 | |
118ea242 GM |
1770 | ALL_FRAMES t means search all frames, |
1771 | nil means search just current frame, | |
1772 | `visible' means search just visible frames, | |
1773 | 0 means search visible and iconified frames, | |
1774 | a window means search the frame that window belongs to, | |
1775 | a frame means consider windows on that frame, only. */ | |
67492200 GM |
1776 | |
1777 | static int | |
118ea242 GM |
1778 | candidate_window_p (window, owindow, minibuf, all_frames) |
1779 | Lisp_Object window, owindow, minibuf, all_frames; | |
67492200 GM |
1780 | { |
1781 | struct window *w = XWINDOW (window); | |
1782 | struct frame *f = XFRAME (w->frame); | |
1783 | int candidate_p = 1; | |
1784 | ||
1785 | if (!BUFFERP (w->buffer)) | |
1786 | candidate_p = 0; | |
1787 | else if (MINI_WINDOW_P (w) | |
1788 | && (EQ (minibuf, Qlambda) | |
1789 | || (WINDOWP (minibuf) && !EQ (minibuf, window)))) | |
1790 | { | |
1791 | /* If MINIBUF is `lambda' don't consider any mini-windows. | |
1792 | If it is a window, consider only that one. */ | |
1793 | candidate_p = 0; | |
1794 | } | |
118ea242 GM |
1795 | else if (EQ (all_frames, Qt)) |
1796 | candidate_p = 1; | |
67492200 | 1797 | else if (NILP (all_frames)) |
118ea242 GM |
1798 | { |
1799 | xassert (WINDOWP (owindow)); | |
1800 | candidate_p = EQ (w->frame, XWINDOW (owindow)->frame); | |
1801 | } | |
67492200 GM |
1802 | else if (EQ (all_frames, Qvisible)) |
1803 | { | |
1804 | FRAME_SAMPLE_VISIBILITY (f); | |
de509a60 SM |
1805 | candidate_p = FRAME_VISIBLE_P (f) |
1806 | && (FRAME_TERMINAL (XFRAME (w->frame)) | |
1807 | == FRAME_TERMINAL (XFRAME (selected_frame))); | |
1808 | ||
67492200 GM |
1809 | } |
1810 | else if (INTEGERP (all_frames) && XINT (all_frames) == 0) | |
1811 | { | |
1812 | FRAME_SAMPLE_VISIBILITY (f); | |
ca2d5566 SM |
1813 | candidate_p = (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f) |
1814 | #ifdef HAVE_X_WINDOWS | |
1815 | /* Yuck!! If we've just created the frame and the | |
1816 | window-manager requested the user to place it | |
1817 | manually, the window may still not be considered | |
1818 | `visible'. I'd argue it should be at least | |
1819 | something like `iconified', but don't know how to do | |
1820 | that yet. --Stef */ | |
1821 | || (FRAME_X_P (f) && f->output_data.x->asked_for_visible | |
1822 | && !f->output_data.x->has_been_visible) | |
1823 | #endif | |
de509a60 SM |
1824 | ) |
1825 | && (FRAME_TERMINAL (XFRAME (w->frame)) | |
1826 | == FRAME_TERMINAL (XFRAME (selected_frame))); | |
67492200 | 1827 | } |
67492200 GM |
1828 | else if (WINDOWP (all_frames)) |
1829 | candidate_p = (EQ (FRAME_MINIBUF_WINDOW (f), all_frames) | |
1830 | || EQ (XWINDOW (all_frames)->frame, w->frame) | |
1831 | || EQ (XWINDOW (all_frames)->frame, FRAME_FOCUS_FRAME (f))); | |
118ea242 GM |
1832 | else if (FRAMEP (all_frames)) |
1833 | candidate_p = EQ (all_frames, w->frame); | |
67492200 GM |
1834 | |
1835 | return candidate_p; | |
1836 | } | |
1837 | ||
1838 | ||
1839 | /* Decode arguments as allowed by Fnext_window, Fprevious_window, and | |
1840 | Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and | |
1841 | ALL_FRAMES. */ | |
1842 | ||
1843 | static void | |
1844 | decode_next_window_args (window, minibuf, all_frames) | |
1845 | Lisp_Object *window, *minibuf, *all_frames; | |
1846 | { | |
1847 | if (NILP (*window)) | |
1848 | *window = selected_window; | |
1849 | else | |
b7826503 | 1850 | CHECK_LIVE_WINDOW (*window); |
177c0ea7 | 1851 | |
67492200 GM |
1852 | /* MINIBUF nil may or may not include minibuffers. Decide if it |
1853 | does. */ | |
1854 | if (NILP (*minibuf)) | |
1855 | *minibuf = minibuf_level ? minibuf_window : Qlambda; | |
1856 | else if (!EQ (*minibuf, Qt)) | |
1857 | *minibuf = Qlambda; | |
177c0ea7 | 1858 | |
67492200 GM |
1859 | /* Now *MINIBUF can be t => count all minibuffer windows, `lambda' |
1860 | => count none of them, or a specific minibuffer window (the | |
1861 | active one) to count. */ | |
1862 | ||
1863 | /* ALL_FRAMES nil doesn't specify which frames to include. */ | |
1864 | if (NILP (*all_frames)) | |
1865 | *all_frames = (!EQ (*minibuf, Qlambda) | |
1866 | ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window)->frame)) | |
1867 | : Qnil); | |
1868 | else if (EQ (*all_frames, Qvisible)) | |
1869 | ; | |
0f8fe9a2 | 1870 | else if (EQ (*all_frames, make_number (0))) |
67492200 GM |
1871 | ; |
1872 | else if (FRAMEP (*all_frames)) | |
1873 | ; | |
1874 | else if (!EQ (*all_frames, Qt)) | |
1875 | *all_frames = Qnil; | |
177c0ea7 | 1876 | |
67492200 GM |
1877 | /* Now *ALL_FRAMES is t meaning search all frames, nil meaning |
1878 | search just current frame, `visible' meaning search just visible | |
1879 | frames, 0 meaning search visible and iconified frames, or a | |
1880 | window, meaning search the frame that window belongs to, or a | |
1881 | frame, meaning consider windows on that frame, only. */ | |
1882 | } | |
1883 | ||
1884 | ||
1885 | /* Return the next or previous window of WINDOW in canonical ordering | |
1886 | of windows. NEXT_P non-zero means return the next window. See the | |
1887 | documentation string of next-window for the meaning of MINIBUF and | |
1888 | ALL_FRAMES. */ | |
1889 | ||
1890 | static Lisp_Object | |
1891 | next_window (window, minibuf, all_frames, next_p) | |
1892 | Lisp_Object window, minibuf, all_frames; | |
1893 | int next_p; | |
1894 | { | |
1895 | decode_next_window_args (&window, &minibuf, &all_frames); | |
177c0ea7 | 1896 | |
67492200 GM |
1897 | /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just |
1898 | return the first window on the frame. */ | |
1899 | if (FRAMEP (all_frames) | |
1900 | && !EQ (all_frames, XWINDOW (window)->frame)) | |
1901 | return Fframe_first_window (all_frames); | |
177c0ea7 | 1902 | |
212116d6 | 1903 | if (next_p) |
67492200 GM |
1904 | { |
1905 | Lisp_Object list; | |
177c0ea7 | 1906 | |
67492200 GM |
1907 | /* Find WINDOW in the list of all windows. */ |
1908 | list = Fmemq (window, window_list ()); | |
1909 | ||
1910 | /* Scan forward from WINDOW to the end of the window list. */ | |
1911 | if (CONSP (list)) | |
1912 | for (list = XCDR (list); CONSP (list); list = XCDR (list)) | |
118ea242 | 1913 | if (candidate_window_p (XCAR (list), window, minibuf, all_frames)) |
67492200 GM |
1914 | break; |
1915 | ||
1916 | /* Scan from the start of the window list up to WINDOW. */ | |
1917 | if (!CONSP (list)) | |
1918 | for (list = Vwindow_list; | |
1919 | CONSP (list) && !EQ (XCAR (list), window); | |
1920 | list = XCDR (list)) | |
118ea242 | 1921 | if (candidate_window_p (XCAR (list), window, minibuf, all_frames)) |
67492200 GM |
1922 | break; |
1923 | ||
1924 | if (CONSP (list)) | |
1925 | window = XCAR (list); | |
1926 | } | |
1927 | else | |
1928 | { | |
1929 | Lisp_Object candidate, list; | |
177c0ea7 | 1930 | |
67492200 GM |
1931 | /* Scan through the list of windows for candidates. If there are |
1932 | candidate windows in front of WINDOW, the last one of these | |
1933 | is the one we want. If there are candidates following WINDOW | |
1934 | in the list, again the last one of these is the one we want. */ | |
1935 | candidate = Qnil; | |
1936 | for (list = window_list (); CONSP (list); list = XCDR (list)) | |
1937 | { | |
1938 | if (EQ (XCAR (list), window)) | |
1939 | { | |
1940 | if (WINDOWP (candidate)) | |
1941 | break; | |
1942 | } | |
118ea242 GM |
1943 | else if (candidate_window_p (XCAR (list), window, minibuf, |
1944 | all_frames)) | |
67492200 GM |
1945 | candidate = XCAR (list); |
1946 | } | |
1947 | ||
1948 | if (WINDOWP (candidate)) | |
1949 | window = candidate; | |
1950 | } | |
1951 | ||
1952 | return window; | |
1953 | } | |
7ab12479 | 1954 | |
7ab12479 | 1955 | |
26f6279d | 1956 | DEFUN ("next-window", Fnext_window, Snext_window, 0, 3, 0, |
fdb82f93 PJ |
1957 | doc: /* Return next window after WINDOW in canonical ordering of windows. |
1958 | If omitted, WINDOW defaults to the selected window. | |
1959 | ||
1960 | Optional second arg MINIBUF t means count the minibuffer window even | |
1961 | if not active. MINIBUF nil or omitted means count the minibuffer iff | |
1962 | it is active. MINIBUF neither t nor nil means not to count the | |
1963 | minibuffer even if it is active. | |
1964 | ||
1965 | Several frames may share a single minibuffer; if the minibuffer | |
1966 | counts, all windows on all frames that share that minibuffer count | |
1967 | too. Therefore, `next-window' can be used to iterate through the | |
1968 | set of windows even when the minibuffer is on another frame. If the | |
1969 | minibuffer does not count, only windows from WINDOW's frame count. | |
1970 | ||
1971 | Optional third arg ALL-FRAMES t means include windows on all frames. | |
1972 | ALL-FRAMES nil or omitted means cycle within the frames as specified | |
1973 | above. ALL-FRAMES = `visible' means include windows on all visible frames. | |
1974 | ALL-FRAMES = 0 means include windows on all visible and iconified frames. | |
1975 | If ALL-FRAMES is a frame, restrict search to windows on that frame. | |
1976 | Anything else means restrict to WINDOW's frame. | |
1977 | ||
1978 | If you use consistent values for MINIBUF and ALL-FRAMES, you can use | |
1979 | `next-window' to iterate through the entire cycle of acceptable | |
1980 | windows, eventually ending up back at the window you started with. | |
1981 | `previous-window' traverses the same cycle, in the reverse order. */) | |
1982 | (window, minibuf, all_frames) | |
67492200 | 1983 | Lisp_Object window, minibuf, all_frames; |
7ab12479 | 1984 | { |
67492200 | 1985 | return next_window (window, minibuf, all_frames, 1); |
7ab12479 JB |
1986 | } |
1987 | ||
67492200 | 1988 | |
26f6279d | 1989 | DEFUN ("previous-window", Fprevious_window, Sprevious_window, 0, 3, 0, |
fdb82f93 PJ |
1990 | doc: /* Return the window preceding WINDOW in canonical ordering of windows. |
1991 | If omitted, WINDOW defaults to the selected window. | |
1992 | ||
1993 | Optional second arg MINIBUF t means count the minibuffer window even | |
1994 | if not active. MINIBUF nil or omitted means count the minibuffer iff | |
1995 | it is active. MINIBUF neither t nor nil means not to count the | |
1996 | minibuffer even if it is active. | |
1997 | ||
1998 | Several frames may share a single minibuffer; if the minibuffer | |
1999 | counts, all windows on all frames that share that minibuffer count | |
2000 | too. Therefore, `previous-window' can be used to iterate through | |
2001 | the set of windows even when the minibuffer is on another frame. If | |
2002 | the minibuffer does not count, only windows from WINDOW's frame count | |
2003 | ||
2004 | Optional third arg ALL-FRAMES t means include windows on all frames. | |
2005 | ALL-FRAMES nil or omitted means cycle within the frames as specified | |
2006 | above. ALL-FRAMES = `visible' means include windows on all visible frames. | |
2007 | ALL-FRAMES = 0 means include windows on all visible and iconified frames. | |
2008 | If ALL-FRAMES is a frame, restrict search to windows on that frame. | |
2009 | Anything else means restrict to WINDOW's frame. | |
2010 | ||
2011 | If you use consistent values for MINIBUF and ALL-FRAMES, you can use | |
2012 | `previous-window' to iterate through the entire cycle of acceptable | |
2013 | windows, eventually ending up back at the window you started with. | |
2014 | `next-window' traverses the same cycle, in the reverse order. */) | |
2015 | (window, minibuf, all_frames) | |
67492200 | 2016 | Lisp_Object window, minibuf, all_frames; |
7ab12479 | 2017 | { |
67492200 | 2018 | return next_window (window, minibuf, all_frames, 0); |
7ab12479 JB |
2019 | } |
2020 | ||
67492200 | 2021 | |
62c07cc7 | 2022 | DEFUN ("other-window", Fother_window, Sother_window, 1, 2, "p", |
fdb82f93 PJ |
2023 | doc: /* Select the ARG'th different window on this frame. |
2024 | All windows on current frame are arranged in a cyclic order. | |
2025 | This command selects the window ARG steps away in that order. | |
c2755926 | 2026 | A negative ARG moves in the opposite order. The optional second |
8cd0d661 | 2027 | argument ALL-FRAMES has the same meaning as in `next-window', which see. */) |
fdb82f93 | 2028 | (arg, all_frames) |
67492200 | 2029 | Lisp_Object arg, all_frames; |
7ab12479 | 2030 | { |
67492200 GM |
2031 | Lisp_Object window; |
2032 | int i; | |
7ab12479 | 2033 | |
b7826503 | 2034 | CHECK_NUMBER (arg); |
67492200 | 2035 | window = selected_window; |
177c0ea7 | 2036 | |
67492200 GM |
2037 | for (i = XINT (arg); i > 0; --i) |
2038 | window = Fnext_window (window, Qnil, all_frames); | |
2039 | for (; i < 0; ++i) | |
2040 | window = Fprevious_window (window, Qnil, all_frames); | |
50e88778 | 2041 | |
14d87dc9 | 2042 | Fselect_window (window, Qnil); |
7ab12479 JB |
2043 | return Qnil; |
2044 | } | |
67492200 GM |
2045 | |
2046 | ||
2047 | DEFUN ("window-list", Fwindow_list, Swindow_list, 0, 3, 0, | |
fdb82f93 PJ |
2048 | doc: /* Return a list of windows on FRAME, starting with WINDOW. |
2049 | FRAME nil or omitted means use the selected frame. | |
2050 | WINDOW nil or omitted means use the selected window. | |
2051 | MINIBUF t means include the minibuffer window, even if it isn't active. | |
2052 | MINIBUF nil or omitted means include the minibuffer window only | |
2053 | if it's active. | |
2054 | MINIBUF neither nil nor t means never include the minibuffer window. */) | |
2055 | (frame, minibuf, window) | |
cd2904bd GM |
2056 | Lisp_Object frame, minibuf, window; |
2057 | { | |
cd2904bd | 2058 | if (NILP (window)) |
acc6289a SM |
2059 | window = FRAMEP (frame) ? XFRAME (frame)->selected_window : selected_window; |
2060 | CHECK_WINDOW (window); | |
cd2904bd GM |
2061 | if (NILP (frame)) |
2062 | frame = selected_frame; | |
2063 | ||
2064 | if (!EQ (frame, XWINDOW (window)->frame)) | |
2065 | error ("Window is on a different frame"); | |
2066 | ||
2067 | return window_list_1 (window, minibuf, frame); | |
2068 | } | |
2069 | ||
2070 | ||
2071 | /* Return a list of windows in canonical ordering. Arguments are like | |
2072 | for `next-window'. */ | |
2073 | ||
2074 | static Lisp_Object | |
2075 | window_list_1 (window, minibuf, all_frames) | |
069f5950 | 2076 | Lisp_Object window, minibuf, all_frames; |
67492200 | 2077 | { |
403de3b4 | 2078 | Lisp_Object tail, list, rest; |
67492200 GM |
2079 | |
2080 | decode_next_window_args (&window, &minibuf, &all_frames); | |
2081 | list = Qnil; | |
177c0ea7 | 2082 | |
67492200 | 2083 | for (tail = window_list (); CONSP (tail); tail = XCDR (tail)) |
118ea242 | 2084 | if (candidate_window_p (XCAR (tail), window, minibuf, all_frames)) |
67492200 | 2085 | list = Fcons (XCAR (tail), list); |
177c0ea7 | 2086 | |
403de3b4 RS |
2087 | /* Rotate the list to start with WINDOW. */ |
2088 | list = Fnreverse (list); | |
2089 | rest = Fmemq (window, list); | |
2090 | if (!NILP (rest) && !EQ (rest, list)) | |
2091 | { | |
1725a7c9 | 2092 | for (tail = list; !EQ (XCDR (tail), rest); tail = XCDR (tail)) |
403de3b4 RS |
2093 | ; |
2094 | XSETCDR (tail, Qnil); | |
2095 | list = nconc2 (rest, list); | |
2096 | } | |
2097 | return list; | |
67492200 GM |
2098 | } |
2099 | ||
2100 | ||
7ab12479 JB |
2101 | \f |
2102 | /* Look at all windows, performing an operation specified by TYPE | |
2103 | with argument OBJ. | |
75d8f668 | 2104 | If FRAMES is Qt, look at all frames; |
75d8f668 | 2105 | Qnil, look at just the selected frame; |
89bca612 | 2106 | Qvisible, look at visible frames; |
75d8f668 | 2107 | a frame, just look at windows on that frame. |
85fe3b5e | 2108 | If MINI is non-zero, perform the operation on minibuffer windows too. */ |
7ab12479 JB |
2109 | |
2110 | enum window_loop | |
2111 | { | |
2112 | WINDOW_LOOP_UNUSED, | |
2113 | GET_BUFFER_WINDOW, /* Arg is buffer */ | |
2114 | GET_LRU_WINDOW, /* Arg is t for full-width windows only */ | |
2115 | DELETE_OTHER_WINDOWS, /* Arg is window not to delete */ | |
2116 | DELETE_BUFFER_WINDOWS, /* Arg is buffer */ | |
2117 | GET_LARGEST_WINDOW, | |
3f8ab7bd | 2118 | UNSHOW_BUFFER, /* Arg is buffer */ |
6b61353c | 2119 | REDISPLAY_BUFFER_WINDOWS, /* Arg is buffer */ |
3f8ab7bd | 2120 | CHECK_ALL_WINDOWS |
7ab12479 JB |
2121 | }; |
2122 | ||
2123 | static Lisp_Object | |
44fa5b1e | 2124 | window_loop (type, obj, mini, frames) |
7ab12479 | 2125 | enum window_loop type; |
118ea242 | 2126 | Lisp_Object obj, frames; |
7ab12479 JB |
2127 | int mini; |
2128 | { | |
118ea242 GM |
2129 | Lisp_Object window, windows, best_window, frame_arg; |
2130 | struct frame *f; | |
ffdc852d | 2131 | struct gcpro gcpro1; |
177c0ea7 | 2132 | |
44fa5b1e JB |
2133 | /* If we're only looping through windows on a particular frame, |
2134 | frame points to that frame. If we're looping through windows | |
2135 | on all frames, frame is 0. */ | |
2136 | if (FRAMEP (frames)) | |
118ea242 | 2137 | f = XFRAME (frames); |
44fa5b1e | 2138 | else if (NILP (frames)) |
118ea242 | 2139 | f = SELECTED_FRAME (); |
7ab12479 | 2140 | else |
118ea242 | 2141 | f = NULL; |
177c0ea7 | 2142 | |
118ea242 | 2143 | if (f) |
89bca612 | 2144 | frame_arg = Qlambda; |
0f8fe9a2 | 2145 | else if (EQ (frames, make_number (0))) |
f812f9c6 | 2146 | frame_arg = frames; |
89bca612 RS |
2147 | else if (EQ (frames, Qvisible)) |
2148 | frame_arg = frames; | |
118ea242 GM |
2149 | else |
2150 | frame_arg = Qt; | |
7ab12479 | 2151 | |
89bca612 RS |
2152 | /* frame_arg is Qlambda to stick to one frame, |
2153 | Qvisible to consider all visible frames, | |
2154 | or Qt otherwise. */ | |
2155 | ||
7ab12479 | 2156 | /* Pick a window to start with. */ |
017b2bad | 2157 | if (WINDOWP (obj)) |
118ea242 GM |
2158 | window = obj; |
2159 | else if (f) | |
2160 | window = FRAME_SELECTED_WINDOW (f); | |
7ab12479 | 2161 | else |
118ea242 | 2162 | window = FRAME_SELECTED_WINDOW (SELECTED_FRAME ()); |
4b206065 | 2163 | |
cd2904bd | 2164 | windows = window_list_1 (window, mini ? Qt : Qnil, frame_arg); |
118ea242 | 2165 | GCPRO1 (windows); |
7ab12479 | 2166 | best_window = Qnil; |
118ea242 | 2167 | |
e67a1dea | 2168 | for (; CONSP (windows); windows = XCDR (windows)) |
7ab12479 | 2169 | { |
118ea242 | 2170 | struct window *w; |
177c0ea7 | 2171 | |
118ea242 GM |
2172 | window = XCAR (windows); |
2173 | w = XWINDOW (window); | |
177c0ea7 | 2174 | |
118ea242 GM |
2175 | /* Note that we do not pay attention here to whether the frame |
2176 | is visible, since Fwindow_list skips non-visible frames if | |
2177 | that is desired, under the control of frame_arg. */ | |
2178 | if (!MINI_WINDOW_P (w) | |
65a04b96 RS |
2179 | /* For UNSHOW_BUFFER, we must always consider all windows. */ |
2180 | || type == UNSHOW_BUFFER | |
7ab12479 JB |
2181 | || (mini && minibuf_level > 0)) |
2182 | switch (type) | |
2183 | { | |
2184 | case GET_BUFFER_WINDOW: | |
118ea242 | 2185 | if (EQ (w->buffer, obj) |
5c204627 RS |
2186 | /* Don't find any minibuffer window |
2187 | except the one that is currently in use. */ | |
118ea242 GM |
2188 | && (MINI_WINDOW_P (w) |
2189 | ? EQ (window, minibuf_window) | |
2190 | : 1)) | |
2191 | { | |
5ddc1b75 GM |
2192 | if (NILP (best_window)) |
2193 | best_window = window; | |
2194 | else if (EQ (window, selected_window)) | |
ca2d5566 SM |
2195 | /* Prefer to return selected-window. */ |
2196 | RETURN_UNGCPRO (window); | |
2197 | else if (EQ (Fwindow_frame (window), selected_frame)) | |
2198 | /* Prefer windows on the current frame. */ | |
5ddc1b75 | 2199 | best_window = window; |
118ea242 | 2200 | } |
7ab12479 JB |
2201 | break; |
2202 | ||
2203 | case GET_LRU_WINDOW: | |
20b69789 SM |
2204 | /* `obj' is an integer encoding a bitvector. |
2205 | `obj & 1' means consider only full-width windows. | |
2206 | `obj & 2' means consider also dedicated windows. */ | |
2207 | if (((XINT (obj) & 1) && !WINDOW_FULL_WIDTH_P (w)) | |
3f489dc7 | 2208 | || (!(XINT (obj) & 2) && !NILP (w->dedicated)) |
20b69789 SM |
2209 | /* Minibuffer windows are always ignored. */ |
2210 | || MINI_WINDOW_P (w)) | |
7ab12479 | 2211 | break; |
265a9e55 | 2212 | if (NILP (best_window) |
7ab12479 | 2213 | || (XFASTINT (XWINDOW (best_window)->use_time) |
118ea242 GM |
2214 | > XFASTINT (w->use_time))) |
2215 | best_window = window; | |
7ab12479 JB |
2216 | break; |
2217 | ||
2218 | case DELETE_OTHER_WINDOWS: | |
118ea242 GM |
2219 | if (!EQ (window, obj)) |
2220 | Fdelete_window (window); | |
7ab12479 JB |
2221 | break; |
2222 | ||
2223 | case DELETE_BUFFER_WINDOWS: | |
118ea242 | 2224 | if (EQ (w->buffer, obj)) |
7ab12479 | 2225 | { |
118ea242 | 2226 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
3548e138 RS |
2227 | |
2228 | /* If this window is dedicated, and in a frame of its own, | |
2229 | kill the frame. */ | |
118ea242 GM |
2230 | if (EQ (window, FRAME_ROOT_WINDOW (f)) |
2231 | && !NILP (w->dedicated) | |
3548e138 | 2232 | && other_visible_frames (f)) |
7ab12479 | 2233 | { |
3548e138 RS |
2234 | /* Skip the other windows on this frame. |
2235 | There might be one, the minibuffer! */ | |
118ea242 GM |
2236 | while (CONSP (XCDR (windows)) |
2237 | && EQ (XWINDOW (XCAR (windows))->frame, | |
2238 | XWINDOW (XCAR (XCDR (windows)))->frame)) | |
2239 | windows = XCDR (windows); | |
177c0ea7 | 2240 | |
3548e138 | 2241 | /* Now we can safely delete the frame. */ |
118ea242 GM |
2242 | Fdelete_frame (w->frame, Qnil); |
2243 | } | |
2244 | else if (NILP (w->parent)) | |
2245 | { | |
2246 | /* If we're deleting the buffer displayed in the | |
2247 | only window on the frame, find a new buffer to | |
2248 | display there. */ | |
2249 | Lisp_Object buffer; | |
2250 | buffer = Fother_buffer (obj, Qnil, w->frame); | |
949cf20f | 2251 | Fset_window_buffer (window, buffer, Qnil); |
118ea242 GM |
2252 | if (EQ (window, selected_window)) |
2253 | Fset_buffer (w->buffer); | |
7ab12479 JB |
2254 | } |
2255 | else | |
118ea242 | 2256 | Fdelete_window (window); |
7ab12479 JB |
2257 | } |
2258 | break; | |
2259 | ||
2260 | case GET_LARGEST_WINDOW: | |
20b69789 | 2261 | { /* nil `obj' means to ignore dedicated windows. */ |
118ea242 | 2262 | /* Ignore dedicated windows and minibuffers. */ |
3f489dc7 | 2263 | if (MINI_WINDOW_P (w) || (NILP (obj) && !NILP (w->dedicated))) |
118ea242 | 2264 | break; |
177c0ea7 | 2265 | |
c930dfab | 2266 | if (NILP (best_window)) |
118ea242 | 2267 | best_window = window; |
c930dfab GM |
2268 | else |
2269 | { | |
2270 | struct window *b = XWINDOW (best_window); | |
949cf20f KS |
2271 | if (XFASTINT (w->total_lines) * XFASTINT (w->total_cols) |
2272 | > XFASTINT (b->total_lines) * XFASTINT (b->total_cols)) | |
c930dfab GM |
2273 | best_window = window; |
2274 | } | |
7ab12479 JB |
2275 | } |
2276 | break; | |
2277 | ||
2278 | case UNSHOW_BUFFER: | |
118ea242 | 2279 | if (EQ (w->buffer, obj)) |
7ab12479 | 2280 | { |
118ea242 GM |
2281 | Lisp_Object buffer; |
2282 | struct frame *f = XFRAME (w->frame); | |
177c0ea7 | 2283 | |
7ab12479 | 2284 | /* Find another buffer to show in this window. */ |
118ea242 | 2285 | buffer = Fother_buffer (obj, Qnil, w->frame); |
177c0ea7 | 2286 | |
38ab08d1 RS |
2287 | /* If this window is dedicated, and in a frame of its own, |
2288 | kill the frame. */ | |
118ea242 GM |
2289 | if (EQ (window, FRAME_ROOT_WINDOW (f)) |
2290 | && !NILP (w->dedicated) | |
38ab08d1 | 2291 | && other_visible_frames (f)) |
45945a7b RS |
2292 | { |
2293 | /* Skip the other windows on this frame. | |
2294 | There might be one, the minibuffer! */ | |
118ea242 GM |
2295 | while (CONSP (XCDR (windows)) |
2296 | && EQ (XWINDOW (XCAR (windows))->frame, | |
2297 | XWINDOW (XCAR (XCDR (windows)))->frame)) | |
2298 | windows = XCDR (windows); | |
177c0ea7 | 2299 | |
45945a7b | 2300 | /* Now we can safely delete the frame. */ |
118ea242 | 2301 | Fdelete_frame (w->frame, Qnil); |
45945a7b | 2302 | } |
a5731348 SM |
2303 | else if (!NILP (w->dedicated) && !NILP (w->parent)) |
2304 | { | |
2305 | Lisp_Object window; | |
2306 | XSETWINDOW (window, w); | |
2307 | /* If this window is dedicated and not the only window | |
2308 | in its frame, then kill it. */ | |
2309 | Fdelete_window (window); | |
2310 | } | |
38ab08d1 | 2311 | else |
38ab08d1 RS |
2312 | { |
2313 | /* Otherwise show a different buffer in the window. */ | |
118ea242 | 2314 | w->dedicated = Qnil; |
949cf20f | 2315 | Fset_window_buffer (window, buffer, Qnil); |
118ea242 GM |
2316 | if (EQ (window, selected_window)) |
2317 | Fset_buffer (w->buffer); | |
38ab08d1 | 2318 | } |
7ab12479 JB |
2319 | } |
2320 | break; | |
3f8ab7bd | 2321 | |
6b61353c KH |
2322 | case REDISPLAY_BUFFER_WINDOWS: |
2323 | if (EQ (w->buffer, obj)) | |
2324 | { | |
2325 | mark_window_display_accurate (window, 0); | |
2326 | w->update_mode_line = Qt; | |
2327 | XBUFFER (obj)->prevent_redisplay_optimizations_p = 1; | |
2328 | ++update_mode_lines; | |
2329 | best_window = window; | |
2330 | } | |
2331 | break; | |
2332 | ||
3f8ab7bd RS |
2333 | /* Check for a window that has a killed buffer. */ |
2334 | case CHECK_ALL_WINDOWS: | |
118ea242 GM |
2335 | if (! NILP (w->buffer) |
2336 | && NILP (XBUFFER (w->buffer)->name)) | |
3f8ab7bd | 2337 | abort (); |
118ea242 | 2338 | break; |
6bbd7a29 GM |
2339 | |
2340 | case WINDOW_LOOP_UNUSED: | |
2341 | break; | |
7ab12479 | 2342 | } |
7ab12479 | 2343 | } |
7ab12479 | 2344 | |
118ea242 | 2345 | UNGCPRO; |
7ab12479 | 2346 | return best_window; |
37962e60 | 2347 | } |
605be8af | 2348 | |
3f8ab7bd RS |
2349 | /* Used for debugging. Abort if any window has a dead buffer. */ |
2350 | ||
233a4a2c | 2351 | void |
3f8ab7bd RS |
2352 | check_all_windows () |
2353 | { | |
2354 | window_loop (CHECK_ALL_WINDOWS, Qnil, 1, Qt); | |
2355 | } | |
2356 | ||
3cbb13c8 | 2357 | DEFUN ("get-lru-window", Fget_lru_window, Sget_lru_window, 0, 2, 0, |
fdb82f93 | 2358 | doc: /* Return the window least recently selected or used for display. |
a55ca73c EZ |
2359 | \(LRU means Least Recently Used.) |
2360 | ||
6b61353c | 2361 | Return a full-width window if possible. |
c2755926 | 2362 | A minibuffer window is never a candidate. |
3cbb13c8 SM |
2363 | A dedicated window is never a candidate, unless DEDICATED is non-nil, |
2364 | so if all windows are dedicated, the value is nil. | |
fdb82f93 PJ |
2365 | If optional argument FRAME is `visible', search all visible frames. |
2366 | If FRAME is 0, search all visible and iconified frames. | |
2367 | If FRAME is t, search all frames. | |
2368 | If FRAME is nil, search only the selected frame. | |
2369 | If FRAME is a frame, search only that frame. */) | |
3cbb13c8 SM |
2370 | (frame, dedicated) |
2371 | Lisp_Object frame, dedicated; | |
7ab12479 JB |
2372 | { |
2373 | register Lisp_Object w; | |
2374 | /* First try for a window that is full-width */ | |
20b69789 SM |
2375 | w = window_loop (GET_LRU_WINDOW, |
2376 | NILP (dedicated) ? make_number (1) : make_number (3), | |
2377 | 0, frame); | |
265a9e55 | 2378 | if (!NILP (w) && !EQ (w, selected_window)) |
7ab12479 JB |
2379 | return w; |
2380 | /* If none of them, try the rest */ | |
20b69789 SM |
2381 | return window_loop (GET_LRU_WINDOW, |
2382 | NILP (dedicated) ? make_number (0) : make_number (2), | |
2383 | 0, frame); | |
7ab12479 JB |
2384 | } |
2385 | ||
3cbb13c8 | 2386 | DEFUN ("get-largest-window", Fget_largest_window, Sget_largest_window, 0, 2, 0, |
fdb82f93 | 2387 | doc: /* Return the largest window in area. |
c2755926 | 2388 | A minibuffer window is never a candidate. |
3cbb13c8 SM |
2389 | A dedicated window is never a candidate unless DEDICATED is non-nil, |
2390 | so if all windows are dedicated, the value is nil. | |
fdb82f93 PJ |
2391 | If optional argument FRAME is `visible', search all visible frames. |
2392 | If FRAME is 0, search all visible and iconified frames. | |
2393 | If FRAME is t, search all frames. | |
2394 | If FRAME is nil, search only the selected frame. | |
2395 | If FRAME is a frame, search only that frame. */) | |
3cbb13c8 SM |
2396 | (frame, dedicated) |
2397 | Lisp_Object frame, dedicated; | |
7ab12479 | 2398 | { |
20b69789 | 2399 | return window_loop (GET_LARGEST_WINDOW, dedicated, 0, |
44fa5b1e | 2400 | frame); |
7ab12479 JB |
2401 | } |
2402 | ||
2403 | DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 1, 2, 0, | |
fdb82f93 | 2404 | doc: /* Return a window currently displaying BUFFER, or nil if none. |
c2755926 | 2405 | BUFFER can be a buffer or a buffer name. |
fdb82f93 PJ |
2406 | If optional argument FRAME is `visible', search all visible frames. |
2407 | If optional argument FRAME is 0, search all visible and iconified frames. | |
2408 | If FRAME is t, search all frames. | |
2409 | If FRAME is nil, search only the selected frame. | |
2410 | If FRAME is a frame, search only that frame. */) | |
2411 | (buffer, frame) | |
2412 | Lisp_Object buffer, frame; | |
7ab12479 JB |
2413 | { |
2414 | buffer = Fget_buffer (buffer); | |
017b2bad | 2415 | if (BUFFERP (buffer)) |
44fa5b1e | 2416 | return window_loop (GET_BUFFER_WINDOW, buffer, 1, frame); |
7ab12479 JB |
2417 | else |
2418 | return Qnil; | |
2419 | } | |
2420 | ||
2421 | DEFUN ("delete-other-windows", Fdelete_other_windows, Sdelete_other_windows, | |
fdb82f93 PJ |
2422 | 0, 1, "", |
2423 | doc: /* Make WINDOW (or the selected window) fill its frame. | |
2424 | Only the frame WINDOW is on is affected. | |
2425 | This function tries to reduce display jumps | |
2426 | by keeping the text previously visible in WINDOW | |
2427 | in the same place on the frame. Doing this depends on | |
2428 | the value of (window-start WINDOW), so if calling this function | |
2429 | in a program gives strange scrolling, make sure the window-start | |
2430 | value is reasonable when this function is called. */) | |
2431 | (window) | |
7ab12479 JB |
2432 | Lisp_Object window; |
2433 | { | |
2434 | struct window *w; | |
00d3d838 | 2435 | int startpos; |
85fe3b5e | 2436 | int top, new_top; |
7ab12479 | 2437 | |
265a9e55 | 2438 | if (NILP (window)) |
7ab12479 JB |
2439 | window = selected_window; |
2440 | else | |
b7826503 | 2441 | CHECK_LIVE_WINDOW (window); |
7ab12479 | 2442 | w = XWINDOW (window); |
a2b38b3c | 2443 | |
00d3d838 | 2444 | startpos = marker_position (w->start); |
949cf20f | 2445 | top = WINDOW_TOP_EDGE_LINE (w) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w))); |
7ab12479 | 2446 | |
a2b38b3c RS |
2447 | if (MINI_WINDOW_P (w) && top > 0) |
2448 | error ("Can't expand minibuffer to full frame"); | |
2449 | ||
70728a80 | 2450 | window_loop (DELETE_OTHER_WINDOWS, window, 0, WINDOW_FRAME (w)); |
7ab12479 | 2451 | |
00d3d838 KH |
2452 | /* Try to minimize scrolling, by setting the window start to the point |
2453 | will cause the text at the old window start to be at the same place | |
2454 | on the frame. But don't try to do this if the window start is | |
2455 | outside the visible portion (as might happen when the display is | |
2456 | not current, due to typeahead). */ | |
949cf20f | 2457 | new_top = WINDOW_TOP_EDGE_LINE (w) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w))); |
85fe3b5e GM |
2458 | if (new_top != top |
2459 | && startpos >= BUF_BEGV (XBUFFER (w->buffer)) | |
00d3d838 KH |
2460 | && startpos <= BUF_ZV (XBUFFER (w->buffer))) |
2461 | { | |
2462 | struct position pos; | |
2463 | struct buffer *obuf = current_buffer; | |
2464 | ||
2465 | Fset_buffer (w->buffer); | |
2466 | /* This computation used to temporarily move point, but that can | |
2467 | have unwanted side effects due to text properties. */ | |
0383eb57 | 2468 | pos = *vmotion (startpos, -top, w); |
4d047f50 | 2469 | |
b73ea88e | 2470 | set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos); |
85fe3b5e | 2471 | w->window_end_valid = Qnil; |
b73ea88e RS |
2472 | w->start_at_line_beg = ((pos.bytepos == BEGV_BYTE |
2473 | || FETCH_BYTE (pos.bytepos - 1) == '\n') ? Qt | |
00d3d838 | 2474 | : Qnil); |
80622eec RS |
2475 | /* We need to do this, so that the window-scroll-functions |
2476 | get called. */ | |
4d047f50 | 2477 | w->optional_new_start = Qt; |
00d3d838 KH |
2478 | |
2479 | set_buffer_internal (obuf); | |
2480 | } | |
5500c422 | 2481 | |
7ab12479 JB |
2482 | return Qnil; |
2483 | } | |
2484 | ||
2485 | DEFUN ("delete-windows-on", Fdelete_windows_on, Sdelete_windows_on, | |
fdb82f93 PJ |
2486 | 1, 2, "bDelete windows on (buffer): ", |
2487 | doc: /* Delete all windows showing BUFFER. | |
c2755926 | 2488 | BUFFER must be a buffer or the name of an existing buffer. |
fdb82f93 PJ |
2489 | Optional second argument FRAME controls which frames are affected. |
2490 | If optional argument FRAME is `visible', search all visible frames. | |
2491 | If FRAME is 0, search all visible and iconified frames. | |
2492 | If FRAME is nil, search all frames. | |
2493 | If FRAME is t, search only the selected frame. | |
2494 | If FRAME is a frame, search only that frame. */) | |
2495 | (buffer, frame) | |
26f6279d | 2496 | Lisp_Object buffer, frame; |
7ab12479 | 2497 | { |
26f6279d JB |
2498 | /* FRAME uses t and nil to mean the opposite of what window_loop |
2499 | expects. */ | |
c520265e RS |
2500 | if (NILP (frame)) |
2501 | frame = Qt; | |
2502 | else if (EQ (frame, Qt)) | |
2503 | frame = Qnil; | |
26f6279d | 2504 | |
265a9e55 | 2505 | if (!NILP (buffer)) |
7ab12479 JB |
2506 | { |
2507 | buffer = Fget_buffer (buffer); | |
b7826503 | 2508 | CHECK_BUFFER (buffer); |
26f6279d | 2509 | window_loop (DELETE_BUFFER_WINDOWS, buffer, 0, frame); |
7ab12479 | 2510 | } |
177c0ea7 | 2511 | |
7ab12479 JB |
2512 | return Qnil; |
2513 | } | |
2514 | ||
2515 | DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows, | |
fdb82f93 PJ |
2516 | Sreplace_buffer_in_windows, |
2517 | 1, 1, "bReplace buffer in windows: ", | |
c2755926 LT |
2518 | doc: /* Replace BUFFER with some other buffer in all windows showing it. |
2519 | BUFFER may be a buffer or the name of an existing buffer. */) | |
fdb82f93 | 2520 | (buffer) |
7ab12479 JB |
2521 | Lisp_Object buffer; |
2522 | { | |
265a9e55 | 2523 | if (!NILP (buffer)) |
7ab12479 JB |
2524 | { |
2525 | buffer = Fget_buffer (buffer); | |
b7826503 | 2526 | CHECK_BUFFER (buffer); |
7ab12479 JB |
2527 | window_loop (UNSHOW_BUFFER, buffer, 0, Qt); |
2528 | } | |
2529 | return Qnil; | |
2530 | } | |
ff58478b RS |
2531 | |
2532 | /* Replace BUFFER with some other buffer in all windows | |
2533 | of all frames, even those on other keyboards. */ | |
2534 | ||
2535 | void | |
2536 | replace_buffer_in_all_windows (buffer) | |
2537 | Lisp_Object buffer; | |
2538 | { | |
27abb84f | 2539 | #ifdef MULTI_KBOARD |
ff58478b RS |
2540 | Lisp_Object tail, frame; |
2541 | ||
ff58478b RS |
2542 | /* A single call to window_loop won't do the job |
2543 | because it only considers frames on the current keyboard. | |
2544 | So loop manually over frames, and handle each one. */ | |
2545 | FOR_EACH_FRAME (tail, frame) | |
db7f721d | 2546 | window_loop (UNSHOW_BUFFER, buffer, 1, frame); |
ff58478b | 2547 | #else |
db7f721d | 2548 | window_loop (UNSHOW_BUFFER, buffer, 1, Qt); |
ff58478b RS |
2549 | #endif |
2550 | } | |
7ab12479 JB |
2551 | \f |
2552 | /* Set the height of WINDOW and all its inferiors. */ | |
a481b3ea JB |
2553 | |
2554 | /* The smallest acceptable dimensions for a window. Anything smaller | |
2555 | might crash Emacs. */ | |
5500c422 | 2556 | |
a481b3ea | 2557 | #define MIN_SAFE_WINDOW_WIDTH (2) |
dc1ab1ee | 2558 | #define MIN_SAFE_WINDOW_HEIGHT (1) |
a481b3ea | 2559 | |
047aaeb9 MR |
2560 | /* For wp non-zero the total number of columns of window w. Otherwise |
2561 | the total number of lines of w. */ | |
a481b3ea | 2562 | |
047aaeb9 MR |
2563 | #define WINDOW_TOTAL_SIZE(w, wp) \ |
2564 | (wp ? WINDOW_TOTAL_COLS (w) : WINDOW_TOTAL_LINES (w)) | |
a481b3ea JB |
2565 | |
2566 | /* If *ROWS or *COLS are too small a size for FRAME, set them to the | |
2567 | minimum allowable size. */ | |
5500c422 | 2568 | |
605be8af | 2569 | void |
a481b3ea | 2570 | check_frame_size (frame, rows, cols) |
605be8af JB |
2571 | FRAME_PTR frame; |
2572 | int *rows, *cols; | |
a481b3ea | 2573 | { |
628df3bf | 2574 | /* For height, we have to see: |
54b8bcb5 RS |
2575 | how many windows the frame has at minimum (one or two), |
2576 | and whether it has a menu bar or other special stuff at the top. */ | |
2577 | int min_height | |
2578 | = ((FRAME_MINIBUF_ONLY_P (frame) || ! FRAME_HAS_MINIBUF_P (frame)) | |
2579 | ? MIN_SAFE_WINDOW_HEIGHT | |
2580 | : 2 * MIN_SAFE_WINDOW_HEIGHT); | |
177c0ea7 | 2581 | |
5500c422 GM |
2582 | if (FRAME_TOP_MARGIN (frame) > 0) |
2583 | min_height += FRAME_TOP_MARGIN (frame); | |
a481b3ea JB |
2584 | |
2585 | if (*rows < min_height) | |
2586 | *rows = min_height; | |
2587 | if (*cols < MIN_SAFE_WINDOW_WIDTH) | |
2588 | *cols = MIN_SAFE_WINDOW_WIDTH; | |
2589 | } | |
2590 | ||
233a4a2c GM |
2591 | /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means |
2592 | check if W's width can be changed, otherwise check W's height. | |
2593 | CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's | |
2594 | siblings, too. If none of the siblings is resizable, WINDOW isn't | |
2595 | either. */ | |
c1636aa6 | 2596 | |
233a4a2c GM |
2597 | static int |
2598 | window_fixed_size_p (w, width_p, check_siblings_p) | |
2599 | struct window *w; | |
2600 | int width_p, check_siblings_p; | |
2601 | { | |
2602 | int fixed_p; | |
2603 | struct window *c; | |
177c0ea7 | 2604 | |
233a4a2c GM |
2605 | if (!NILP (w->hchild)) |
2606 | { | |
2607 | c = XWINDOW (w->hchild); | |
177c0ea7 | 2608 | |
233a4a2c GM |
2609 | if (width_p) |
2610 | { | |
047aaeb9 | 2611 | /* A horizontal combination is fixed-width if all of if its |
233a4a2c GM |
2612 | children are. */ |
2613 | while (c && window_fixed_size_p (c, width_p, 0)) | |
2614 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; | |
2615 | fixed_p = c == NULL; | |
2616 | } | |
2617 | else | |
2618 | { | |
047aaeb9 | 2619 | /* A horizontal combination is fixed-height if one of if its |
233a4a2c GM |
2620 | children is. */ |
2621 | while (c && !window_fixed_size_p (c, width_p, 0)) | |
2622 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; | |
2623 | fixed_p = c != NULL; | |
2624 | } | |
2625 | } | |
2626 | else if (!NILP (w->vchild)) | |
2627 | { | |
2628 | c = XWINDOW (w->vchild); | |
177c0ea7 | 2629 | |
233a4a2c GM |
2630 | if (width_p) |
2631 | { | |
047aaeb9 | 2632 | /* A vertical combination is fixed-width if one of if its |
233a4a2c GM |
2633 | children is. */ |
2634 | while (c && !window_fixed_size_p (c, width_p, 0)) | |
2635 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; | |
2636 | fixed_p = c != NULL; | |
2637 | } | |
2638 | else | |
2639 | { | |
047aaeb9 | 2640 | /* A vertical combination is fixed-height if all of if its |
233a4a2c GM |
2641 | children are. */ |
2642 | while (c && window_fixed_size_p (c, width_p, 0)) | |
2643 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; | |
2644 | fixed_p = c == NULL; | |
2645 | } | |
2646 | } | |
2647 | else if (BUFFERP (w->buffer)) | |
2648 | { | |
3df0580e AS |
2649 | struct buffer *old = current_buffer; |
2650 | Lisp_Object val; | |
177c0ea7 | 2651 | |
3df0580e AS |
2652 | current_buffer = XBUFFER (w->buffer); |
2653 | val = find_symbol_value (Qwindow_size_fixed); | |
2654 | current_buffer = old; | |
a34dfd12 | 2655 | |
3df0580e AS |
2656 | fixed_p = 0; |
2657 | if (!EQ (val, Qunbound)) | |
2658 | { | |
2659 | fixed_p = !NILP (val); | |
177c0ea7 | 2660 | |
3df0580e AS |
2661 | if (fixed_p |
2662 | && ((EQ (val, Qheight) && width_p) | |
2663 | || (EQ (val, Qwidth) && !width_p))) | |
2664 | fixed_p = 0; | |
233a4a2c GM |
2665 | } |
2666 | ||
2667 | /* Can't tell if this one is resizable without looking at | |
2668 | siblings. If all siblings are fixed-size this one is too. */ | |
2669 | if (!fixed_p && check_siblings_p && WINDOWP (w->parent)) | |
2670 | { | |
2671 | Lisp_Object child; | |
177c0ea7 | 2672 | |
9beb8baa | 2673 | for (child = w->prev; WINDOWP (child); child = XWINDOW (child)->prev) |
233a4a2c GM |
2674 | if (!window_fixed_size_p (XWINDOW (child), width_p, 0)) |
2675 | break; | |
2676 | ||
2677 | if (NILP (child)) | |
9beb8baa | 2678 | for (child = w->next; WINDOWP (child); child = XWINDOW (child)->next) |
233a4a2c GM |
2679 | if (!window_fixed_size_p (XWINDOW (child), width_p, 0)) |
2680 | break; | |
2681 | ||
2682 | if (NILP (child)) | |
2683 | fixed_p = 1; | |
2684 | } | |
2685 | } | |
2686 | else | |
2687 | fixed_p = 1; | |
2688 | ||
2689 | return fixed_p; | |
2690 | } | |
177c0ea7 | 2691 | |
047aaeb9 MR |
2692 | /* Return minimum size of leaf window W. WIDTH_P non-zero means return |
2693 | the minimum width of W, WIDTH_P zero means return the minimum height | |
2694 | of W. SAFE_P non-zero means ignore window-min-height|width but just | |
2695 | return values that won't crash Emacs and don't hide components like | |
2696 | fringes, scrollbars, or modelines. If WIDTH_P is zero and W is the | |
2697 | minibuffer window, always return 1. */ | |
f1de8c77 MR |
2698 | |
2699 | static int | |
047aaeb9 | 2700 | window_min_size_2 (w, width_p, safe_p) |
f1de8c77 | 2701 | struct window *w; |
047aaeb9 | 2702 | int width_p, safe_p; |
f1de8c77 | 2703 | { |
047aaeb9 MR |
2704 | /* We should consider buffer-local values of window_min_height and |
2705 | window_min_width here. */ | |
f1de8c77 | 2706 | if (width_p) |
047aaeb9 MR |
2707 | { |
2708 | int safe_size = (MIN_SAFE_WINDOW_WIDTH | |
f1de8c77 | 2709 | + WINDOW_FRINGE_COLS (w) |
047aaeb9 MR |
2710 | + WINDOW_SCROLL_BAR_COLS (w)); |
2711 | ||
2712 | return safe_p ? safe_size : max (window_min_width, safe_size); | |
2713 | } | |
f1de8c77 | 2714 | else if (MINI_WINDOW_P (w)) |
047aaeb9 | 2715 | return 1; |
f1de8c77 | 2716 | else |
047aaeb9 MR |
2717 | { |
2718 | int safe_size = (MIN_SAFE_WINDOW_HEIGHT | |
2719 | + ((BUFFERP (w->buffer) | |
2720 | && !NILP (XBUFFER (w->buffer)->mode_line_format)) | |
2721 | ? 1 : 0)); | |
f1de8c77 | 2722 | |
047aaeb9 MR |
2723 | return safe_p ? safe_size : max (window_min_height, safe_size); |
2724 | } | |
f1de8c77 | 2725 | } |
233a4a2c | 2726 | |
047aaeb9 MR |
2727 | /* Return minimum size of window W, not taking fixed-width windows into |
2728 | account. WIDTH_P non-zero means return the minimum width, otherwise | |
2729 | return the minimum height. SAFE_P non-zero means ignore | |
2730 | window-min-height|width but just return values that won't crash Emacs | |
2731 | and don't hide components like fringes, scrollbars, or modelines. If | |
2732 | W is a combination window, compute the minimum size from the minimum | |
2733 | sizes of W's children. */ | |
233a4a2c GM |
2734 | |
2735 | static int | |
047aaeb9 | 2736 | window_min_size_1 (w, width_p, safe_p) |
c1636aa6 | 2737 | struct window *w; |
047aaeb9 | 2738 | int width_p, safe_p; |
c1636aa6 | 2739 | { |
233a4a2c | 2740 | struct window *c; |
c1636aa6 | 2741 | int size; |
177c0ea7 | 2742 | |
233a4a2c GM |
2743 | if (!NILP (w->hchild)) |
2744 | { | |
047aaeb9 | 2745 | /* W is a horizontal combination. */ |
233a4a2c GM |
2746 | c = XWINDOW (w->hchild); |
2747 | size = 0; | |
177c0ea7 | 2748 | |
233a4a2c GM |
2749 | if (width_p) |
2750 | { | |
047aaeb9 MR |
2751 | /* The minimum width of a horizontal combination is the sum of |
2752 | the minimum widths of its children. */ | |
233a4a2c GM |
2753 | while (c) |
2754 | { | |
047aaeb9 | 2755 | size += window_min_size_1 (c, 1, safe_p); |
233a4a2c GM |
2756 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; |
2757 | } | |
2758 | } | |
2759 | else | |
2760 | { | |
047aaeb9 MR |
2761 | /* The minimum height of a horizontal combination is the |
2762 | maximum of the minimum heights of its children. */ | |
233a4a2c GM |
2763 | while (c) |
2764 | { | |
047aaeb9 | 2765 | size = max (window_min_size_1 (c, 0, safe_p), size); |
233a4a2c GM |
2766 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; |
2767 | } | |
2768 | } | |
2769 | } | |
2770 | else if (!NILP (w->vchild)) | |
2771 | { | |
047aaeb9 | 2772 | /* W is a vertical combination. */ |
233a4a2c GM |
2773 | c = XWINDOW (w->vchild); |
2774 | size = 0; | |
177c0ea7 | 2775 | |
233a4a2c GM |
2776 | if (width_p) |
2777 | { | |
047aaeb9 MR |
2778 | /* The minimum width of a vertical combination is the maximum |
2779 | of the minimum widths of its children. */ | |
233a4a2c GM |
2780 | while (c) |
2781 | { | |
047aaeb9 | 2782 | size = max (window_min_size_1 (c, 1, safe_p), size); |
233a4a2c GM |
2783 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; |
2784 | } | |
2785 | } | |
2786 | else | |
2787 | { | |
047aaeb9 MR |
2788 | /* The minimum height of a vertical combination is the sum of |
2789 | the minimum height of its children. */ | |
233a4a2c GM |
2790 | while (c) |
2791 | { | |
047aaeb9 | 2792 | size += window_min_size_1 (c, 0, safe_p); |
233a4a2c GM |
2793 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; |
2794 | } | |
2795 | } | |
2796 | } | |
c1636aa6 | 2797 | else |
047aaeb9 MR |
2798 | /* W is a leaf window. */ |
2799 | size = window_min_size_2 (w, width_p, safe_p); | |
c1636aa6 GM |
2800 | |
2801 | return size; | |
2802 | } | |
2803 | ||
233a4a2c | 2804 | /* Return the minimum size of window W, taking fixed-size windows into |
047aaeb9 MR |
2805 | account. WIDTH_P non-zero means return the minimum width, otherwise |
2806 | return the minimum height. SAFE_P non-zero means ignore | |
2807 | window-min-height|width but just return values that won't crash Emacs | |
2808 | and don't hide components like fringes, scrollbars, or modelines. | |
2809 | IGNORE_FIXED_P non-zero means ignore if W is fixed-size. Set *FIXED | |
2810 | to 1 if W is fixed-size unless FIXED is null. */ | |
7ab12479 | 2811 | |
233a4a2c | 2812 | static int |
047aaeb9 | 2813 | window_min_size (w, width_p, safe_p, ignore_fixed_p, fixed) |
233a4a2c | 2814 | struct window *w; |
047aaeb9 | 2815 | int width_p, safe_p, ignore_fixed_p, *fixed; |
233a4a2c GM |
2816 | { |
2817 | int size, fixed_p; | |
2818 | ||
f984d4fc GM |
2819 | if (ignore_fixed_p) |
2820 | fixed_p = 0; | |
2821 | else | |
2822 | fixed_p = window_fixed_size_p (w, width_p, 1); | |
177c0ea7 | 2823 | |
233a4a2c GM |
2824 | if (fixed) |
2825 | *fixed = fixed_p; | |
177c0ea7 | 2826 | |
233a4a2c | 2827 | if (fixed_p) |
047aaeb9 | 2828 | size = WINDOW_TOTAL_SIZE (w, width_p); |
233a4a2c | 2829 | else |
047aaeb9 | 2830 | size = window_min_size_1 (w, width_p, safe_p); |
177c0ea7 | 2831 | |
233a4a2c GM |
2832 | return size; |
2833 | } | |
2834 | ||
2835 | ||
79fd290e | 2836 | /* Adjust the margins of window W if text area is too small. |
949cf20f KS |
2837 | Return 1 if window width is ok after adjustment; 0 if window |
2838 | is still too narrow. */ | |
2839 | ||
2840 | static int | |
2841 | adjust_window_margins (w) | |
2842 | struct window *w; | |
2843 | { | |
2844 | int box_cols = (WINDOW_TOTAL_COLS (w) | |
2845 | - WINDOW_FRINGE_COLS (w) | |
2846 | - WINDOW_SCROLL_BAR_COLS (w)); | |
2847 | int margin_cols = (WINDOW_LEFT_MARGIN_COLS (w) | |
2848 | + WINDOW_RIGHT_MARGIN_COLS (w)); | |
2849 | ||
2850 | if (box_cols - margin_cols >= MIN_SAFE_WINDOW_WIDTH) | |
2851 | return 1; | |
2852 | ||
2853 | if (margin_cols < 0 || box_cols < MIN_SAFE_WINDOW_WIDTH) | |
2854 | return 0; | |
2855 | ||
2856 | /* Window's text area is too narrow, but reducing the window | |
2857 | margins will fix that. */ | |
2858 | margin_cols = box_cols - MIN_SAFE_WINDOW_WIDTH; | |
2859 | if (WINDOW_RIGHT_MARGIN_COLS (w) > 0) | |
2860 | { | |
2861 | if (WINDOW_LEFT_MARGIN_COLS (w) > 0) | |
2862 | w->left_margin_cols = w->right_margin_cols | |
2863 | = make_number (margin_cols/2); | |
2864 | else | |
2865 | w->right_margin_cols = make_number (margin_cols); | |
2866 | } | |
2867 | else | |
2868 | w->left_margin_cols = make_number (margin_cols); | |
2869 | return 1; | |
2870 | } | |
2871 | ||
047aaeb9 MR |
2872 | /* Calculate new sizes for windows in the list FORWARD when their |
2873 | compound size goes from TOTAL to SIZE. TOTAL must be greater than | |
2874 | SIZE. The number of windows in FORWARD is NCHILDREN, and the number | |
2875 | that can shrink is SHRINKABLE. Fixed-size windows may be shrunk if | |
2876 | and only if RESIZE_FIXED_P is non-zero. WIDTH_P non-zero means | |
2877 | shrink columns, otherwise shrink lines. | |
6b61353c | 2878 | |
047aaeb9 MR |
2879 | SAFE_P zero means windows may be sized down to window-min-height |
2880 | lines (window-min-window columns for WIDTH_P non-zero). SAFE_P | |
2881 | non-zero means windows may be sized down to their minimum safe sizes | |
2882 | taking into account the space needed to display modelines, fringes, | |
2883 | and scrollbars. | |
6b61353c | 2884 | |
047aaeb9 MR |
2885 | This function returns an allocated array of new sizes that the caller |
2886 | must free. A size -1 means the window is fixed and RESIZE_FIXED_P is | |
2887 | zero. A size zero means the window shall be deleted. Array index 0 | |
2888 | refers to the first window in FORWARD, 1 to the second, and so on. | |
2889 | ||
2890 | This function resizes windows proportionally to their size. It also | |
2891 | tries to preserve smaller windows by resizing larger windows before | |
2892 | resizing any window to zero. If resize_proportionally is non-nil for | |
2893 | a specific window, it will attempt to strictly resize that window | |
2894 | proportionally, even at the expense of deleting smaller windows. */ | |
6b61353c | 2895 | static int * |
047aaeb9 MR |
2896 | shrink_windows (total, size, nchildren, shrinkable, resize_fixed_p, |
2897 | forward, width_p, safe_p) | |
2898 | int total, size, nchildren, shrinkable; | |
2899 | int resize_fixed_p, width_p, safe_p; | |
6b61353c KH |
2900 | Lisp_Object forward; |
2901 | { | |
2902 | int available_resize = 0; | |
047aaeb9 | 2903 | int *new_sizes, *min_sizes; |
6b61353c KH |
2904 | struct window *c; |
2905 | Lisp_Object child; | |
2906 | int smallest = total; | |
2907 | int total_removed = 0; | |
2908 | int total_shrink = total - size; | |
2909 | int i; | |
2910 | ||
2911 | new_sizes = xmalloc (sizeof (*new_sizes) * nchildren); | |
047aaeb9 | 2912 | min_sizes = xmalloc (sizeof (*min_sizes) * nchildren); |
6b61353c KH |
2913 | |
2914 | for (i = 0, child = forward; !NILP (child); child = c->next, ++i) | |
2915 | { | |
2916 | int child_size; | |
2917 | ||
2918 | c = XWINDOW (child); | |
047aaeb9 | 2919 | child_size = WINDOW_TOTAL_SIZE (c, width_p); |
6b61353c | 2920 | |
047aaeb9 | 2921 | if (!resize_fixed_p && window_fixed_size_p (c, width_p, 0)) |
6b61353c KH |
2922 | new_sizes[i] = -1; |
2923 | else | |
2924 | { | |
2925 | new_sizes[i] = child_size; | |
047aaeb9 MR |
2926 | min_sizes[i] = window_min_size_1 (c, width_p, safe_p); |
2927 | if (child_size > min_sizes[i] | |
2928 | && NILP (c->resize_proportionally)) | |
2929 | available_resize += child_size - min_sizes[i]; | |
6b61353c KH |
2930 | } |
2931 | } | |
2932 | /* We might need to shrink some windows to zero. Find the smallest | |
2933 | windows and set them to 0 until we can fulfil the new size. */ | |
2934 | ||
2935 | while (shrinkable > 1 && size + available_resize < total) | |
2936 | { | |
2937 | for (i = 0; i < nchildren; ++i) | |
2938 | if (new_sizes[i] > 0 && smallest > new_sizes[i]) | |
2939 | smallest = new_sizes[i]; | |
2940 | ||
2941 | for (i = 0; i < nchildren; ++i) | |
2942 | if (new_sizes[i] == smallest) | |
2943 | { | |
2944 | /* Resize this window down to zero. */ | |
2945 | new_sizes[i] = 0; | |
047aaeb9 MR |
2946 | if (smallest > min_sizes[i]) |
2947 | available_resize -= smallest - min_sizes[i]; | |
6b61353c KH |
2948 | available_resize += smallest; |
2949 | --shrinkable; | |
2950 | total_removed += smallest; | |
2951 | ||
ef614e04 JD |
2952 | /* We don't know what the smallest is now. */ |
2953 | smallest = total; | |
2954 | ||
6b61353c KH |
2955 | /* Out of for, just remove one window at the time and |
2956 | check again if we have enough space. */ | |
2957 | break; | |
2958 | } | |
2959 | } | |
2960 | ||
2961 | /* Now, calculate the new sizes. Try to shrink each window | |
2962 | proportional to its size. */ | |
2963 | for (i = 0; i < nchildren; ++i) | |
2964 | { | |
047aaeb9 | 2965 | if (new_sizes[i] > min_sizes[i]) |
6b61353c | 2966 | { |
047aaeb9 MR |
2967 | int to_shrink = total_shrink * new_sizes[i] / total; |
2968 | ||
2969 | if (new_sizes[i] - to_shrink < min_sizes[i]) | |
2970 | to_shrink = new_sizes[i] - min_sizes[i]; | |
6b61353c KH |
2971 | new_sizes[i] -= to_shrink; |
2972 | total_removed += to_shrink; | |
2973 | } | |
2974 | } | |
2975 | ||
2976 | /* Any reminder due to rounding, we just subtract from windows | |
2977 | that are left and still can be shrunk. */ | |
2978 | while (total_shrink > total_removed) | |
2979 | { | |
ef614e04 JD |
2980 | int nonzero_sizes = 0; |
2981 | int nonzero_idx = -1; | |
2982 | ||
2983 | for (i = 0; i < nchildren; ++i) | |
2984 | if (new_sizes[i] > 0) | |
2985 | { | |
2986 | ++nonzero_sizes; | |
2987 | nonzero_idx = i; | |
2988 | } | |
c49a0495 | 2989 | |
6b61353c | 2990 | for (i = 0; i < nchildren; ++i) |
047aaeb9 | 2991 | if (new_sizes[i] > min_sizes[i]) |
6b61353c KH |
2992 | { |
2993 | --new_sizes[i]; | |
2994 | ++total_removed; | |
2995 | ||
2996 | /* Out of for, just shrink one window at the time and | |
2997 | check again if we have enough space. */ | |
2998 | break; | |
2999 | } | |
ef614e04 | 3000 | |
ef614e04 JD |
3001 | /* Special case, only one window left. */ |
3002 | if (nonzero_sizes == 1) | |
3003 | break; | |
3004 | } | |
3005 | ||
3006 | /* Any surplus due to rounding, we add to windows that are left. */ | |
3007 | while (total_shrink < total_removed) | |
3008 | { | |
3009 | for (i = 0; i < nchildren; ++i) | |
3010 | { | |
3011 | if (new_sizes[i] != 0 && total_shrink < total_removed) | |
3012 | { | |
3013 | ++new_sizes[i]; | |
3014 | --total_removed; | |
3015 | break; | |
3016 | } | |
3017 | } | |
6b61353c KH |
3018 | } |
3019 | ||
047aaeb9 MR |
3020 | xfree (min_sizes); |
3021 | ||
6b61353c KH |
3022 | return new_sizes; |
3023 | } | |
949cf20f | 3024 | |
233a4a2c | 3025 | /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set |
047aaeb9 MR |
3026 | WINDOW's width. Resize WINDOW's children, if any, so that they keep |
3027 | their proportionate size relative to WINDOW. | |
5fe0b054 RS |
3028 | |
3029 | If FIRST_ONLY is 1, change only the first of WINDOW's children when | |
3030 | they are in series. If LAST_ONLY is 1, change only the last of | |
3031 | WINDOW's children when they are in series. | |
3032 | ||
3033 | Propagate WINDOW's top or left edge position to children. Delete | |
047aaeb9 MR |
3034 | windows that become too small unless NODELETE_P is 1. When |
3035 | NODELETE_P equals 2 do not honor settings for window-min-height and | |
3036 | window-min-width when resizing windows but use safe defaults instead. | |
3037 | This should give better behavior when resizing frames. */ | |
233a4a2c GM |
3038 | |
3039 | static void | |
5fe0b054 | 3040 | size_window (window, size, width_p, nodelete_p, first_only, last_only) |
7ab12479 | 3041 | Lisp_Object window; |
233a4a2c | 3042 | int size, width_p, nodelete_p; |
5fe0b054 | 3043 | int first_only, last_only; |
7ab12479 | 3044 | { |
233a4a2c GM |
3045 | struct window *w = XWINDOW (window); |
3046 | struct window *c; | |
3047 | Lisp_Object child, *forward, *sideward; | |
047aaeb9 | 3048 | int old_size = WINDOW_TOTAL_SIZE (w, width_p); |
7ab12479 | 3049 | |
7ae2f10f | 3050 | size = max (0, size); |
177c0ea7 | 3051 | |
047aaeb9 MR |
3052 | /* Delete WINDOW if it's too small. */ |
3053 | if (nodelete_p != 1 && !NILP (w->parent) | |
3054 | && size < window_min_size_1 (w, width_p, nodelete_p == 2)) | |
233a4a2c | 3055 | { |
047aaeb9 MR |
3056 | delete_window (window); |
3057 | return; | |
7ab12479 JB |
3058 | } |
3059 | ||
233a4a2c | 3060 | /* Set redisplay hints. */ |
7ae2f10f GM |
3061 | w->last_modified = make_number (0); |
3062 | w->last_overlay_modified = make_number (0); | |
7ab12479 | 3063 | windows_or_buffers_changed++; |
7ae2f10f | 3064 | FRAME_WINDOW_SIZES_CHANGED (XFRAME (w->frame)) = 1; |
29aeee73 | 3065 | |
233a4a2c GM |
3066 | if (width_p) |
3067 | { | |
3068 | sideward = &w->vchild; | |
3069 | forward = &w->hchild; | |
949cf20f KS |
3070 | w->total_cols = make_number (size); |
3071 | adjust_window_margins (w); | |
233a4a2c GM |
3072 | } |
3073 | else | |
3074 | { | |
3075 | sideward = &w->hchild; | |
3076 | forward = &w->vchild; | |
949cf20f KS |
3077 | w->total_lines = make_number (size); |
3078 | w->orig_total_lines = Qnil; | |
233a4a2c GM |
3079 | } |
3080 | ||
3081 | if (!NILP (*sideward)) | |
7ab12479 | 3082 | { |
5fe0b054 | 3083 | /* We have a chain of parallel siblings whose size should all change. */ |
233a4a2c | 3084 | for (child = *sideward; !NILP (child); child = c->next) |
7ab12479 | 3085 | { |
233a4a2c GM |
3086 | c = XWINDOW (child); |
3087 | if (width_p) | |
949cf20f | 3088 | c->left_col = w->left_col; |
233a4a2c | 3089 | else |
949cf20f | 3090 | c->top_line = w->top_line; |
5fe0b054 RS |
3091 | size_window (child, size, width_p, nodelete_p, |
3092 | first_only, last_only); | |
7ab12479 JB |
3093 | } |
3094 | } | |
5fe0b054 RS |
3095 | else if (!NILP (*forward) && last_only) |
3096 | { | |
3097 | /* Change the last in a series of siblings. */ | |
3098 | Lisp_Object last_child; | |
3099 | int child_size; | |
3100 | ||
3101 | for (child = *forward; !NILP (child); child = c->next) | |
3102 | { | |
3103 | c = XWINDOW (child); | |
3104 | last_child = child; | |
3105 | } | |
3106 | ||
047aaeb9 MR |
3107 | child_size = WINDOW_TOTAL_SIZE (c, width_p); |
3108 | size_window (last_child, size - old_size + child_size, | |
5fe0b054 RS |
3109 | width_p, nodelete_p, first_only, last_only); |
3110 | } | |
3111 | else if (!NILP (*forward) && first_only) | |
3112 | { | |
3113 | /* Change the first in a series of siblings. */ | |
3114 | int child_size; | |
3115 | ||
3116 | child = *forward; | |
3117 | c = XWINDOW (child); | |
3118 | ||
3119 | if (width_p) | |
3120 | c->left_col = w->left_col; | |
3121 | else | |
3122 | c->top_line = w->top_line; | |
3123 | ||
047aaeb9 MR |
3124 | child_size = WINDOW_TOTAL_SIZE (c, width_p); |
3125 | size_window (child, size - old_size + child_size, | |
5fe0b054 RS |
3126 | width_p, nodelete_p, first_only, last_only); |
3127 | } | |
233a4a2c | 3128 | else if (!NILP (*forward)) |
7ab12479 | 3129 | { |
233a4a2c GM |
3130 | int fixed_size, each, extra, n; |
3131 | int resize_fixed_p, nfixed; | |
8b6d9dc9 | 3132 | int last_pos, first_pos, nchildren, total; |
6b61353c | 3133 | int *new_sizes = NULL; |
233a4a2c | 3134 | |
5fe0b054 | 3135 | /* Determine the fixed-size portion of this window, and the |
233a4a2c | 3136 | number of child windows. */ |
8b6d9dc9 | 3137 | fixed_size = nchildren = nfixed = total = 0; |
233a4a2c | 3138 | for (child = *forward; !NILP (child); child = c->next, ++nchildren) |
7ab12479 | 3139 | { |
8b6d9dc9 | 3140 | int child_size; |
177c0ea7 | 3141 | |
7ab12479 | 3142 | c = XWINDOW (child); |
047aaeb9 | 3143 | child_size = WINDOW_TOTAL_SIZE (c, width_p); |
8b6d9dc9 | 3144 | total += child_size; |
177c0ea7 | 3145 | |
233a4a2c GM |
3146 | if (window_fixed_size_p (c, width_p, 0)) |
3147 | { | |
8b6d9dc9 | 3148 | fixed_size += child_size; |
233a4a2c GM |
3149 | ++nfixed; |
3150 | } | |
3151 | } | |
7ab12479 | 3152 | |
233a4a2c GM |
3153 | /* If the new size is smaller than fixed_size, or if there |
3154 | aren't any resizable windows, allow resizing fixed-size | |
3155 | windows. */ | |
3156 | resize_fixed_p = nfixed == nchildren || size < fixed_size; | |
3157 | ||
6b61353c | 3158 | /* Compute how many lines/columns to add/remove to each child. The |
233a4a2c GM |
3159 | value of extra takes care of rounding errors. */ |
3160 | n = resize_fixed_p ? nchildren : nchildren - nfixed; | |
6b61353c | 3161 | if (size < total && n > 1) |
047aaeb9 MR |
3162 | new_sizes = shrink_windows (total, size, nchildren, n, |
3163 | resize_fixed_p, *forward, width_p, | |
3164 | nodelete_p == 2); | |
6b61353c KH |
3165 | else |
3166 | { | |
3167 | each = (size - total) / n; | |
3168 | extra = (size - total) - n * each; | |
3169 | } | |
233a4a2c GM |
3170 | |
3171 | /* Compute new children heights and edge positions. */ | |
949cf20f | 3172 | first_pos = width_p ? XINT (w->left_col) : XINT (w->top_line); |
233a4a2c | 3173 | last_pos = first_pos; |
6b61353c | 3174 | for (n = 0, child = *forward; !NILP (child); child = c->next, ++n) |
233a4a2c GM |
3175 | { |
3176 | int new_size, old_size; | |
177c0ea7 | 3177 | |
233a4a2c | 3178 | c = XWINDOW (child); |
047aaeb9 | 3179 | old_size = WINDOW_TOTAL_SIZE (c, width_p); |
233a4a2c | 3180 | new_size = old_size; |
7ab12479 | 3181 | |
233a4a2c GM |
3182 | /* The top or left edge position of this child equals the |
3183 | bottom or right edge of its predecessor. */ | |
3184 | if (width_p) | |
949cf20f | 3185 | c->left_col = make_number (last_pos); |
233a4a2c | 3186 | else |
949cf20f | 3187 | c->top_line = make_number (last_pos); |
7ab12479 | 3188 | |
233a4a2c GM |
3189 | /* If this child can be resized, do it. */ |
3190 | if (resize_fixed_p || !window_fixed_size_p (c, width_p, 0)) | |
3191 | { | |
6b61353c | 3192 | new_size = new_sizes ? new_sizes[n] : old_size + each + extra; |
233a4a2c GM |
3193 | extra = 0; |
3194 | } | |
177c0ea7 | 3195 | |
047aaeb9 | 3196 | /* Set new size. Note that size_window also propagates |
233a4a2c GM |
3197 | edge positions to children, so it's not a no-op if we |
3198 | didn't change the child's size. */ | |
5fe0b054 | 3199 | size_window (child, new_size, width_p, 1, first_only, last_only); |
233a4a2c GM |
3200 | |
3201 | /* Remember the bottom/right edge position of this child; it | |
3202 | will be used to set the top/left edge of the next child. */ | |
6b61353c | 3203 | last_pos += new_size; |
7ab12479 | 3204 | } |
233a4a2c | 3205 | |
70fdbb46 | 3206 | xfree (new_sizes); |
6b61353c | 3207 | |
233a4a2c GM |
3208 | /* We should have covered the parent exactly with child windows. */ |
3209 | xassert (size == last_pos - first_pos); | |
177c0ea7 | 3210 | |
7ab12479 | 3211 | /* Now delete any children that became too small. */ |
047aaeb9 | 3212 | if (nodelete_p != 1) |
233a4a2c | 3213 | for (child = *forward; !NILP (child); child = c->next) |
7ab12479 | 3214 | { |
233a4a2c | 3215 | int child_size; |
047aaeb9 | 3216 | |
233a4a2c | 3217 | c = XWINDOW (child); |
047aaeb9 MR |
3218 | child_size = WINDOW_TOTAL_SIZE (c, width_p); |
3219 | size_window (child, child_size, width_p, nodelete_p, | |
3220 | first_only, last_only); | |
7ab12479 JB |
3221 | } |
3222 | } | |
3223 | } | |
3224 | ||
233a4a2c | 3225 | /* Set WINDOW's height to HEIGHT, and recursively change the height of |
047aaeb9 MR |
3226 | WINDOW's children. NODELETE zero means windows that have become |
3227 | smaller than window-min-height in the process may be deleted. | |
3228 | NODELETE 1 means never delete windows that become too small in the | |
3229 | process. (The caller should check later and do so if appropriate.) | |
3230 | NODELETE 2 means delete only windows that have become too small to be | |
3231 | displayed correctly. */ | |
7ab12479 | 3232 | |
5e14b1fc | 3233 | void |
233a4a2c | 3234 | set_window_height (window, height, nodelete) |
7ab12479 | 3235 | Lisp_Object window; |
233a4a2c | 3236 | int height; |
7ab12479 JB |
3237 | int nodelete; |
3238 | { | |
5fe0b054 | 3239 | size_window (window, height, 0, nodelete, 0, 0); |
233a4a2c | 3240 | } |
7ab12479 | 3241 | |
233a4a2c | 3242 | /* Set WINDOW's width to WIDTH, and recursively change the width of |
047aaeb9 MR |
3243 | WINDOW's children. NODELETE zero means windows that have become |
3244 | smaller than window-min-width in the process may be deleted. | |
3245 | NODELETE 1 means never delete windows that become too small in the | |
3246 | process. (The caller should check later and do so if appropriate.) | |
3247 | NODELETE 2 means delete only windows that have become too small to be | |
3248 | displayed correctly. */ | |
7ab12479 | 3249 | |
233a4a2c GM |
3250 | void |
3251 | set_window_width (window, width, nodelete) | |
3252 | Lisp_Object window; | |
3253 | int width; | |
3254 | int nodelete; | |
3255 | { | |
5fe0b054 | 3256 | size_window (window, width, 1, nodelete, 0, 0); |
7ab12479 | 3257 | } |
233a4a2c | 3258 | |
cdbc7fec KS |
3259 | /* Change window heights in windows rooted in WINDOW by N lines. */ |
3260 | ||
3261 | void | |
3262 | change_window_heights (window, n) | |
3263 | Lisp_Object window; | |
3264 | int n; | |
3265 | { | |
3266 | struct window *w = XWINDOW (window); | |
3267 | ||
949cf20f KS |
3268 | XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n); |
3269 | XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n); | |
cdbc7fec | 3270 | |
949cf20f KS |
3271 | if (INTEGERP (w->orig_top_line)) |
3272 | XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n); | |
3273 | if (INTEGERP (w->orig_total_lines)) | |
3274 | XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n); | |
cdbc7fec KS |
3275 | |
3276 | /* Handle just the top child in a vertical split. */ | |
3277 | if (!NILP (w->vchild)) | |
3278 | change_window_heights (w->vchild, n); | |
3279 | ||
3280 | /* Adjust all children in a horizontal split. */ | |
3281 | for (window = w->hchild; !NILP (window); window = w->next) | |
3282 | { | |
3283 | w = XWINDOW (window); | |
3284 | change_window_heights (window, n); | |
3285 | } | |
3286 | } | |
3287 | ||
7ab12479 | 3288 | \f |
1d8d96fa | 3289 | int window_select_count; |
7ab12479 | 3290 | |
5b03d3c0 RS |
3291 | Lisp_Object |
3292 | Fset_window_buffer_unwind (obuf) | |
3293 | Lisp_Object obuf; | |
3294 | { | |
3295 | Fset_buffer (obuf); | |
3296 | return Qnil; | |
3297 | } | |
3298 | ||
56613f06 SM |
3299 | EXFUN (Fset_window_fringes, 4); |
3300 | EXFUN (Fset_window_scroll_bars, 4); | |
7ab12479 | 3301 | |
6a44ffb3 SM |
3302 | static void |
3303 | run_funs (Lisp_Object funs) | |
3304 | { | |
3305 | for (; CONSP (funs); funs = XCDR (funs)) | |
3306 | if (!EQ (XCAR (funs), Qt)) | |
3307 | call0 (XCAR (funs)); | |
3308 | } | |
3309 | ||
3310 | static Lisp_Object select_window_norecord (Lisp_Object window); | |
3311 | ||
ef264c42 SM |
3312 | void |
3313 | run_window_configuration_change_hook (struct frame *f) | |
3314 | { | |
ef264c42 | 3315 | int count = SPECPDL_INDEX (); |
6a44ffb3 SM |
3316 | Lisp_Object frame, global_wcch |
3317 | = Fdefault_value (Qwindow_configuration_change_hook); | |
3318 | XSETFRAME (frame, f); | |
3319 | ||
3320 | if (NILP (Vrun_hooks)) | |
3321 | return; | |
3322 | ||
ef264c42 SM |
3323 | if (SELECTED_FRAME () != f) |
3324 | { | |
ef264c42 SM |
3325 | record_unwind_protect (Fselect_frame, Fselected_frame ()); |
3326 | Fselect_frame (frame); | |
3327 | } | |
6a44ffb3 SM |
3328 | |
3329 | /* Use the right buffer. Matters when running the local hooks. */ | |
3330 | if (current_buffer != XBUFFER (Fwindow_buffer (Qnil))) | |
3331 | { | |
3332 | record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
3333 | Fset_buffer (Fwindow_buffer (Qnil)); | |
3334 | } | |
3335 | ||
3336 | /* Look for buffer-local values. */ | |
3337 | { | |
3338 | Lisp_Object windows = Fwindow_list (frame, Qlambda, Qnil); | |
3339 | for (; CONSP (windows); windows = XCDR (windows)) | |
3340 | { | |
3341 | Lisp_Object window = XCAR (windows); | |
3342 | Lisp_Object buffer = Fwindow_buffer (window); | |
3343 | if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook, | |
3344 | buffer))) | |
3345 | { | |
3346 | int count = SPECPDL_INDEX (); | |
3347 | record_unwind_protect (select_window_norecord, Fselected_window ()); | |
3348 | select_window_norecord (window); | |
3349 | run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook, | |
3350 | buffer)); | |
ef264c42 SM |
3351 | unbind_to (count, Qnil); |
3352 | } | |
6a44ffb3 SM |
3353 | } |
3354 | } | |
047aaeb9 | 3355 | |
6a44ffb3 SM |
3356 | run_funs (global_wcch); |
3357 | unbind_to (count, Qnil); | |
ef264c42 SM |
3358 | } |
3359 | ||
5500c422 GM |
3360 | /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero |
3361 | means it's allowed to run hooks. See make_frame for a case where | |
949cf20f KS |
3362 | it's not allowed. KEEP_MARGINS_P non-zero means that the current |
3363 | margins, fringes, and scroll-bar settings of the window are not | |
3364 | reset from the buffer's local settings. */ | |
7ab12479 | 3365 | |
5500c422 | 3366 | void |
949cf20f | 3367 | set_window_buffer (window, buffer, run_hooks_p, keep_margins_p) |
5500c422 | 3368 | Lisp_Object window, buffer; |
949cf20f | 3369 | int run_hooks_p, keep_margins_p; |
5500c422 GM |
3370 | { |
3371 | struct window *w = XWINDOW (window); | |
3372 | struct buffer *b = XBUFFER (buffer); | |
aed13378 | 3373 | int count = SPECPDL_INDEX (); |
c3b232e4 | 3374 | int samebuf = EQ (buffer, w->buffer); |
7ab12479 JB |
3375 | |
3376 | w->buffer = buffer; | |
86e48436 RS |
3377 | |
3378 | if (EQ (window, selected_window)) | |
5500c422 | 3379 | b->last_selected_window = window; |
beb4e312 | 3380 | |
c49a0495 KS |
3381 | /* Let redisplay errors through. */ |
3382 | b->display_error_modiff = 0; | |
3383 | ||
beb4e312 | 3384 | /* Update time stamps of buffer display. */ |
5500c422 GM |
3385 | if (INTEGERP (b->display_count)) |
3386 | XSETINT (b->display_count, XINT (b->display_count) + 1); | |
3387 | b->display_time = Fcurrent_time (); | |
86e48436 | 3388 | |
d834a2e9 | 3389 | XSETFASTINT (w->window_end_pos, 0); |
5500c422 GM |
3390 | XSETFASTINT (w->window_end_vpos, 0); |
3391 | bzero (&w->last_cursor, sizeof w->last_cursor); | |
5a41ab94 | 3392 | w->window_end_valid = Qnil; |
c3b232e4 SM |
3393 | if (!(keep_margins_p && samebuf)) |
3394 | { /* If we're not actually changing the buffer, Don't reset hscroll and | |
3395 | vscroll. This case happens for example when called from | |
3396 | change_frame_size_1, where we use a dummy call to | |
3397 | Fset_window_buffer on the frame's selected window (and no other) | |
3398 | just in order to run window-configuration-change-hook. | |
3399 | Resetting hscroll and vscroll here is problematic for things like | |
3400 | image-mode and doc-view-mode since it resets the image's position | |
3401 | whenever we resize the frame. */ | |
3402 | w->hscroll = w->min_hscroll = make_number (0); | |
3403 | w->vscroll = 0; | |
3404 | set_marker_both (w->pointm, buffer, BUF_PT (b), BUF_PT_BYTE (b)); | |
3405 | set_marker_restricted (w->start, | |
3406 | make_number (b->last_window_start), | |
3407 | buffer); | |
3408 | w->start_at_line_beg = Qnil; | |
3409 | w->force_start = Qnil; | |
3410 | XSETFASTINT (w->last_modified, 0); | |
3411 | XSETFASTINT (w->last_overlay_modified, 0); | |
3412 | } | |
3413 | /* Maybe we could move this into the `if' but it's not obviously safe and | |
3414 | I doubt it's worth the trouble. */ | |
7ab12479 | 3415 | windows_or_buffers_changed++; |
5b03d3c0 RS |
3416 | |
3417 | /* We must select BUFFER for running the window-scroll-functions. | |
3418 | If WINDOW is selected, switch permanently. | |
3419 | Otherwise, switch but go back to the ambient buffer afterward. */ | |
7ab12479 JB |
3420 | if (EQ (window, selected_window)) |
3421 | Fset_buffer (buffer); | |
5b03d3c0 RS |
3422 | /* We can't check ! NILP (Vwindow_scroll_functions) here |
3423 | because that might itself be a local variable. */ | |
3424 | else if (window_initialized) | |
3425 | { | |
3426 | record_unwind_protect (Fset_window_buffer_unwind, Fcurrent_buffer ()); | |
3427 | Fset_buffer (buffer); | |
3428 | } | |
3429 | ||
a1562258 SM |
3430 | XMARKER (w->pointm)->insertion_type = !NILP (Vwindow_point_insertion_type); |
3431 | ||
949cf20f KS |
3432 | if (!keep_margins_p) |
3433 | { | |
3434 | /* Set left and right marginal area width etc. from buffer. */ | |
3435 | ||
79fd290e | 3436 | /* This may call adjust_window_margins three times, so |
949cf20f | 3437 | temporarily disable window margins. */ |
6b61353c KH |
3438 | Lisp_Object save_left = w->left_margin_cols; |
3439 | Lisp_Object save_right = w->right_margin_cols; | |
3440 | ||
949cf20f KS |
3441 | w->left_margin_cols = w->right_margin_cols = Qnil; |
3442 | ||
3443 | Fset_window_fringes (window, | |
3444 | b->left_fringe_width, b->right_fringe_width, | |
3445 | b->fringes_outside_margins); | |
3446 | ||
3447 | Fset_window_scroll_bars (window, | |
3448 | b->scroll_bar_width, | |
3449 | b->vertical_scroll_bar_type, Qnil); | |
3450 | ||
6b61353c KH |
3451 | w->left_margin_cols = save_left; |
3452 | w->right_margin_cols = save_right; | |
3453 | ||
949cf20f KS |
3454 | Fset_window_margins (window, |
3455 | b->left_margin_cols, b->right_margin_cols); | |
3456 | } | |
7ab12479 | 3457 | |
5500c422 GM |
3458 | if (run_hooks_p) |
3459 | { | |
3460 | if (! NILP (Vwindow_scroll_functions)) | |
3461 | run_hook_with_args_2 (Qwindow_scroll_functions, window, | |
3462 | Fmarker_position (w->start)); | |
ef264c42 | 3463 | run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w))); |
5500c422 | 3464 | } |
543f5fb1 | 3465 | |
5b03d3c0 | 3466 | unbind_to (count, Qnil); |
5500c422 | 3467 | } |
5b03d3c0 | 3468 | |
5500c422 | 3469 | |
949cf20f | 3470 | DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 3, 0, |
fdb82f93 | 3471 | doc: /* Make WINDOW display BUFFER as its contents. |
c2755926 | 3472 | BUFFER can be a buffer or the name of an existing buffer. |
ab80314b | 3473 | Optional third arg KEEP-MARGINS non-nil means that WINDOW's current |
949cf20f KS |
3474 | display margins, fringe widths, and scroll bar settings are maintained; |
3475 | the default is to reset these from BUFFER's local settings or the frame | |
6cb4a892 RS |
3476 | defaults. |
3477 | ||
3478 | This function runs the hook `window-scroll-functions'. */) | |
949cf20f | 3479 | (window, buffer, keep_margins) |
56613f06 | 3480 | register Lisp_Object window, buffer, keep_margins; |
5500c422 GM |
3481 | { |
3482 | register Lisp_Object tem; | |
3483 | register struct window *w = decode_window (window); | |
5500c422 | 3484 | |
bed0c171 | 3485 | XSETWINDOW (window, w); |
5500c422 | 3486 | buffer = Fget_buffer (buffer); |
b7826503 | 3487 | CHECK_BUFFER (buffer); |
5500c422 GM |
3488 | |
3489 | if (NILP (XBUFFER (buffer)->name)) | |
3490 | error ("Attempt to display deleted buffer"); | |
3491 | ||
3492 | tem = w->buffer; | |
3493 | if (NILP (tem)) | |
3494 | error ("Window is deleted"); | |
3495 | else if (! EQ (tem, Qt)) /* w->buffer is t when the window | |
3496 | is first being set up. */ | |
3497 | { | |
a1562258 SM |
3498 | if (!EQ (tem, buffer)) |
3499 | if (EQ (w->dedicated, Qt)) | |
3500 | error ("Window is dedicated to `%s'", SDATA (XBUFFER (tem)->name)); | |
3501 | else | |
3502 | w->dedicated = Qnil; | |
5500c422 GM |
3503 | |
3504 | unshow_buffer (w); | |
3505 | } | |
3506 | ||
949cf20f | 3507 | set_window_buffer (window, buffer, 1, !NILP (keep_margins)); |
7ab12479 JB |
3508 | return Qnil; |
3509 | } | |
3510 | ||
2d0834cc SM |
3511 | /* Note that selected_window can be nil |
3512 | when this is called from Fset_window_configuration. */ | |
3513 | ||
14d87dc9 | 3514 | DEFUN ("select-window", Fselect_window, Sselect_window, 1, 2, 0, |
fdb82f93 | 3515 | doc: /* Select WINDOW. Most editing will apply to WINDOW's buffer. |
e963215c | 3516 | If WINDOW is not already selected, make WINDOW's buffer current |
c2755926 | 3517 | and make WINDOW the frame's selected window. Return WINDOW. |
14d87dc9 SM |
3518 | Optional second arg NORECORD non-nil means |
3519 | do not put this buffer at the front of the list of recently selected ones. | |
282f7831 | 3520 | |
fdb82f93 PJ |
3521 | Note that the main editor command loop |
3522 | selects the buffer of the selected window before each command. */) | |
14d87dc9 SM |
3523 | (window, norecord) |
3524 | register Lisp_Object window, norecord; | |
7ab12479 JB |
3525 | { |
3526 | register struct window *w; | |
719eaeb1 | 3527 | register struct window *ow; |
1ae1a37d | 3528 | struct frame *sf; |
7ab12479 | 3529 | |
b7826503 | 3530 | CHECK_LIVE_WINDOW (window); |
7ab12479 JB |
3531 | |
3532 | w = XWINDOW (window); | |
50e88778 | 3533 | w->frozen_window_start_p = 0; |
7ab12479 | 3534 | |
2a1893f4 SM |
3535 | ++window_select_count; |
3536 | XSETFASTINT (w->use_time, window_select_count); | |
7ab12479 JB |
3537 | if (EQ (window, selected_window)) |
3538 | return window; | |
3539 | ||
ca2d5566 SM |
3540 | sf = SELECTED_FRAME (); |
3541 | if (XFRAME (WINDOW_FRAME (w)) != sf) | |
3542 | { | |
3543 | XFRAME (WINDOW_FRAME (w))->selected_window = window; | |
3544 | /* Use this rather than Fhandle_switch_frame | |
3545 | so that FRAME_FOCUS_FRAME is moved appropriately as we | |
3546 | move around in the state where a minibuffer in a separate | |
3547 | frame is active. */ | |
3548 | Fselect_frame (WINDOW_FRAME (w)); | |
3549 | /* Fselect_frame called us back so we've done all the work already. */ | |
3550 | eassert (EQ (window, selected_window)); | |
3551 | return window; | |
3552 | } | |
3553 | else | |
3554 | sf->selected_window = window; | |
3555 | ||
a46c0153 RS |
3556 | /* Store the current buffer's actual point into the |
3557 | old selected window. It belongs to that window, | |
3558 | and when the window is not selected, must be in the window. */ | |
719eaeb1 GM |
3559 | if (!NILP (selected_window)) |
3560 | { | |
3561 | ow = XWINDOW (selected_window); | |
3562 | if (! NILP (ow->buffer)) | |
3563 | set_marker_both (ow->pointm, ow->buffer, | |
3564 | BUF_PT (XBUFFER (ow->buffer)), | |
3565 | BUF_PT_BYTE (XBUFFER (ow->buffer))); | |
3566 | } | |
7ab12479 JB |
3567 | |
3568 | selected_window = window; | |
7ab12479 | 3569 | |
14d87dc9 | 3570 | if (NILP (norecord)) |
b7354ddf | 3571 | record_buffer (w->buffer); |
7ab12479 JB |
3572 | Fset_buffer (w->buffer); |
3573 | ||
86e48436 RS |
3574 | XBUFFER (w->buffer)->last_selected_window = window; |
3575 | ||
7ab12479 JB |
3576 | /* Go to the point recorded in the window. |
3577 | This is important when the buffer is in more | |
3578 | than one window. It also matters when | |
3579 | redisplay_window has altered point after scrolling, | |
3580 | because it makes the change only in the window. */ | |
3581 | { | |
3582 | register int new_point = marker_position (w->pointm); | |
3583 | if (new_point < BEGV) | |
3584 | SET_PT (BEGV); | |
a9c95e08 | 3585 | else if (new_point > ZV) |
7ab12479 JB |
3586 | SET_PT (ZV); |
3587 | else | |
3588 | SET_PT (new_point); | |
3589 | } | |
3590 | ||
3591 | windows_or_buffers_changed++; | |
3592 | return window; | |
3593 | } | |
14d87dc9 SM |
3594 | |
3595 | static Lisp_Object | |
3596 | select_window_norecord (window) | |
3597 | Lisp_Object window; | |
3598 | { | |
3599 | return Fselect_window (window, Qt); | |
3600 | } | |
b7354ddf | 3601 | \f |
87478b52 SM |
3602 | Lisp_Object |
3603 | display_buffer (buffer, not_this_window_p, override_frame) | |
3604 | Lisp_Object buffer, not_this_window_p, override_frame; | |
d07f802a | 3605 | { |
87478b52 | 3606 | return call3 (Qdisplay_buffer, buffer, not_this_window_p, override_frame); |
d07f802a RS |
3607 | } |
3608 | ||
6b61353c KH |
3609 | DEFUN ("force-window-update", Fforce_window_update, Sforce_window_update, |
3610 | 0, 1, 0, | |
5a1048a5 | 3611 | doc: /* Force all windows to be updated on next redisplay. |
6b61353c | 3612 | If optional arg OBJECT is a window, force redisplay of that window only. |
0cc1039f | 3613 | If OBJECT is a buffer or buffer name, force redisplay of all windows |
6b61353c KH |
3614 | displaying that buffer. */) |
3615 | (object) | |
3616 | Lisp_Object object; | |
3617 | { | |
3618 | if (NILP (object)) | |
3619 | { | |
3620 | windows_or_buffers_changed++; | |
3621 | update_mode_lines++; | |
3622 | return Qt; | |
3623 | } | |
3624 | ||
3625 | if (WINDOWP (object)) | |
3626 | { | |
3627 | struct window *w = XWINDOW (object); | |
3628 | mark_window_display_accurate (object, 0); | |
3629 | w->update_mode_line = Qt; | |
3630 | if (BUFFERP (w->buffer)) | |
3631 | XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1; | |
3632 | ++update_mode_lines; | |
3633 | return Qt; | |
3634 | } | |
0cc1039f | 3635 | |
6b61353c KH |
3636 | if (STRINGP (object)) |
3637 | object = Fget_buffer (object); | |
3638 | if (BUFFERP (object) && !NILP (XBUFFER (object)->name)) | |
3639 | { | |
3640 | /* Walk all windows looking for buffer, and force update | |
3641 | of each of those windows. */ | |
3642 | ||
3643 | object = window_loop (REDISPLAY_BUFFER_WINDOWS, object, 0, Qvisible); | |
3644 | return NILP (object) ? Qnil : Qt; | |
3645 | } | |
3646 | ||
3647 | /* If nothing suitable was found, just return. | |
3648 | We could signal an error, but this feature will typically be used | |
3649 | asynchronously in timers or process sentinels, so we don't. */ | |
3650 | return Qnil; | |
3651 | } | |
3652 | ||
3653 | ||
7ab12479 JB |
3654 | void |
3655 | temp_output_buffer_show (buf) | |
3656 | register Lisp_Object buf; | |
3657 | { | |
3658 | register struct buffer *old = current_buffer; | |
3659 | register Lisp_Object window; | |
3660 | register struct window *w; | |
3661 | ||
bccd3dd1 RS |
3662 | XBUFFER (buf)->directory = current_buffer->directory; |
3663 | ||
7ab12479 | 3664 | Fset_buffer (buf); |
c6367666 | 3665 | BUF_SAVE_MODIFF (XBUFFER (buf)) = MODIFF; |
7ab12479 JB |
3666 | BEGV = BEG; |
3667 | ZV = Z; | |
3668 | SET_PT (BEG); | |
06be4f85 | 3669 | #if 0 /* rms: there should be no reason for this. */ |
b1599b4c | 3670 | XBUFFER (buf)->prevent_redisplay_optimizations_p = 1; |
06be4f85 | 3671 | #endif |
7ab12479 JB |
3672 | set_buffer_internal (old); |
3673 | ||
e67a1dea | 3674 | if (!NILP (Vtemp_buffer_show_function)) |
7ab12479 JB |
3675 | call1 (Vtemp_buffer_show_function, buf); |
3676 | else | |
3677 | { | |
87478b52 | 3678 | window = display_buffer (buf, Qnil, Qnil); |
7ab12479 | 3679 | |
1ae1a37d | 3680 | if (!EQ (XWINDOW (window)->frame, selected_frame)) |
44fa5b1e | 3681 | Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window))); |
7ab12479 JB |
3682 | Vminibuf_scroll_window = window; |
3683 | w = XWINDOW (window); | |
d834a2e9 | 3684 | XSETFASTINT (w->hscroll, 0); |
ea68264b | 3685 | XSETFASTINT (w->min_hscroll, 0); |
2d0834cc SM |
3686 | set_marker_restricted_both (w->start, buf, BEG, BEG); |
3687 | set_marker_restricted_both (w->pointm, buf, BEG, BEG); | |
a58ec57d | 3688 | |
beb4e312 | 3689 | /* Run temp-buffer-show-hook, with the chosen window selected |
a5731348 | 3690 | and its buffer current. */ |
2d0834cc SM |
3691 | |
3692 | if (!NILP (Vrun_hooks) | |
3693 | && !NILP (Fboundp (Qtemp_buffer_show_hook)) | |
3694 | && !NILP (Fsymbol_value (Qtemp_buffer_show_hook))) | |
2cccc823 | 3695 | { |
2d0834cc SM |
3696 | int count = SPECPDL_INDEX (); |
3697 | Lisp_Object prev_window, prev_buffer; | |
3698 | prev_window = selected_window; | |
3699 | XSETBUFFER (prev_buffer, old); | |
0cc1039f | 3700 | |
2d0834cc SM |
3701 | /* Select the window that was chosen, for running the hook. |
3702 | Note: Both Fselect_window and select_window_norecord may | |
3703 | set-buffer to the buffer displayed in the window, | |
3704 | so we need to save the current buffer. --stef */ | |
3705 | record_unwind_protect (Fset_buffer, prev_buffer); | |
3706 | record_unwind_protect (select_window_norecord, prev_window); | |
3707 | Fselect_window (window, Qt); | |
3708 | Fset_buffer (w->buffer); | |
3709 | call1 (Vrun_hooks, Qtemp_buffer_show_hook); | |
3710 | unbind_to (count, Qnil); | |
2cccc823 RS |
3711 | } |
3712 | } | |
7ab12479 JB |
3713 | } |
3714 | \f | |
dfcf069d | 3715 | static void |
7ab12479 JB |
3716 | make_dummy_parent (window) |
3717 | Lisp_Object window; | |
3718 | { | |
cffec418 | 3719 | Lisp_Object new; |
7ab12479 | 3720 | register struct window *o, *p; |
cffec418 | 3721 | int i; |
7ab12479 | 3722 | |
cffec418 | 3723 | o = XWINDOW (window); |
26605be9 | 3724 | p = allocate_window (); |
cffec418 | 3725 | for (i = 0; i < VECSIZE (struct window); ++i) |
26605be9 GM |
3726 | ((struct Lisp_Vector *) p)->contents[i] |
3727 | = ((struct Lisp_Vector *)o)->contents[i]; | |
cffec418 | 3728 | XSETWINDOW (new, p); |
7ab12479 | 3729 | |
2a1893f4 SM |
3730 | ++sequence_number; |
3731 | XSETFASTINT (p->sequence_number, sequence_number); | |
7ab12479 JB |
3732 | |
3733 | /* Put new into window structure in place of window */ | |
3734 | replace_window (window, new); | |
3735 | ||
3736 | o->next = Qnil; | |
3737 | o->prev = Qnil; | |
3738 | o->vchild = Qnil; | |
3739 | o->hchild = Qnil; | |
3740 | o->parent = new; | |
3741 | ||
3742 | p->start = Qnil; | |
3743 | p->pointm = Qnil; | |
3744 | p->buffer = Qnil; | |
3745 | } | |
3746 | ||
3747 | DEFUN ("split-window", Fsplit_window, Ssplit_window, 0, 3, "", | |
fdb82f93 PJ |
3748 | doc: /* Split WINDOW, putting SIZE lines in the first of the pair. |
3749 | WINDOW defaults to selected one and SIZE to half its size. | |
3750 | If optional third arg HORFLAG is non-nil, split side by side | |
3751 | and put SIZE columns in the first of the pair. In that case, | |
876e2665 | 3752 | SIZE includes that window's scroll bar, or the divider column to its right. |
c2755926 LT |
3753 | Interactively, all arguments are nil. |
3754 | ||
3755 | Returns the newly created window (which is the lower or rightmost one). | |
19ca94ce RS |
3756 | The upper or leftmost window is the original one, and remains selected |
3757 | if it was selected before. | |
3758 | ||
c2755926 | 3759 | See Info node `(elisp)Splitting Windows' for more details and examples.*/) |
fdb82f93 | 3760 | (window, size, horflag) |
77ae0fe3 | 3761 | Lisp_Object window, size, horflag; |
7ab12479 JB |
3762 | { |
3763 | register Lisp_Object new; | |
3764 | register struct window *o, *p; | |
c0807608 | 3765 | FRAME_PTR fo; |
77ae0fe3 | 3766 | register int size_int; |
7ab12479 | 3767 | |
265a9e55 | 3768 | if (NILP (window)) |
7ab12479 JB |
3769 | window = selected_window; |
3770 | else | |
b7826503 | 3771 | CHECK_LIVE_WINDOW (window); |
7ab12479 JB |
3772 | |
3773 | o = XWINDOW (window); | |
c0807608 | 3774 | fo = XFRAME (WINDOW_FRAME (o)); |
7ab12479 | 3775 | |
77ae0fe3 | 3776 | if (NILP (size)) |
7ab12479 | 3777 | { |
265a9e55 | 3778 | if (!NILP (horflag)) |
c0807608 | 3779 | /* Calculate the size of the left-hand window, by dividing |
25b33244 KH |
3780 | the usable space in columns by two. |
3781 | We round up, since the left-hand window may include | |
3782 | a dividing line, while the right-hand may not. */ | |
949cf20f | 3783 | size_int = (XFASTINT (o->total_cols) + 1) >> 1; |
7ab12479 | 3784 | else |
949cf20f | 3785 | size_int = XFASTINT (o->total_lines) >> 1; |
7ab12479 JB |
3786 | } |
3787 | else | |
3788 | { | |
b7826503 | 3789 | CHECK_NUMBER (size); |
77ae0fe3 | 3790 | size_int = XINT (size); |
7ab12479 JB |
3791 | } |
3792 | ||
3793 | if (MINI_WINDOW_P (o)) | |
3794 | error ("Attempt to split minibuffer window"); | |
233a4a2c GM |
3795 | else if (window_fixed_size_p (o, !NILP (horflag), 0)) |
3796 | error ("Attempt to split fixed-size window"); | |
7ab12479 | 3797 | |
265a9e55 | 3798 | if (NILP (horflag)) |
7ab12479 | 3799 | { |
047aaeb9 MR |
3800 | int window_safe_height = window_min_size_2 (o, 0, 0); |
3801 | ||
f1de8c77 | 3802 | if (size_int < window_safe_height) |
77ae0fe3 | 3803 | error ("Window height %d too small (after splitting)", size_int); |
f1de8c77 | 3804 | if (size_int + window_safe_height > XFASTINT (o->total_lines)) |
37962e60 | 3805 | error ("Window height %d too small (after splitting)", |
949cf20f | 3806 | XFASTINT (o->total_lines) - size_int); |
265a9e55 JB |
3807 | if (NILP (o->parent) |
3808 | || NILP (XWINDOW (o->parent)->vchild)) | |
7ab12479 JB |
3809 | { |
3810 | make_dummy_parent (window); | |
3811 | new = o->parent; | |
3812 | XWINDOW (new)->vchild = window; | |
3813 | } | |
3814 | } | |
3815 | else | |
3816 | { | |
047aaeb9 MR |
3817 | int window_safe_width = window_min_size_2 (o, 1, 0); |
3818 | ||
f1de8c77 | 3819 | if (size_int < window_safe_width) |
77ae0fe3 | 3820 | error ("Window width %d too small (after splitting)", size_int); |
f1de8c77 | 3821 | if (size_int + window_safe_width > XFASTINT (o->total_cols)) |
37962e60 | 3822 | error ("Window width %d too small (after splitting)", |
949cf20f | 3823 | XFASTINT (o->total_cols) - size_int); |
265a9e55 JB |
3824 | if (NILP (o->parent) |
3825 | || NILP (XWINDOW (o->parent)->hchild)) | |
7ab12479 JB |
3826 | { |
3827 | make_dummy_parent (window); | |
3828 | new = o->parent; | |
3829 | XWINDOW (new)->hchild = window; | |
3830 | } | |
3831 | } | |
3832 | ||
3833 | /* Now we know that window's parent is a vertical combination | |
3834 | if we are dividing vertically, or a horizontal combination | |
3835 | if we are making side-by-side windows */ | |
3836 | ||
3837 | windows_or_buffers_changed++; | |
c0807608 | 3838 | FRAME_WINDOW_SIZES_CHANGED (fo) = 1; |
7ab12479 JB |
3839 | new = make_window (); |
3840 | p = XWINDOW (new); | |
3841 | ||
44fa5b1e | 3842 | p->frame = o->frame; |
7ab12479 | 3843 | p->next = o->next; |
265a9e55 | 3844 | if (!NILP (p->next)) |
7ab12479 JB |
3845 | XWINDOW (p->next)->prev = new; |
3846 | p->prev = window; | |
3847 | o->next = new; | |
3848 | p->parent = o->parent; | |
3849 | p->buffer = Qt; | |
5500c422 GM |
3850 | p->window_end_valid = Qnil; |
3851 | bzero (&p->last_cursor, sizeof p->last_cursor); | |
7ab12479 | 3852 | |
949cf20f KS |
3853 | /* Duplicate special geometry settings. */ |
3854 | ||
3855 | p->left_margin_cols = o->left_margin_cols; | |
3856 | p->right_margin_cols = o->right_margin_cols; | |
3857 | p->left_fringe_width = o->left_fringe_width; | |
3858 | p->right_fringe_width = o->right_fringe_width; | |
3859 | p->fringes_outside_margins = o->fringes_outside_margins; | |
3860 | p->scroll_bar_width = o->scroll_bar_width; | |
3861 | p->vertical_scroll_bar_type = o->vertical_scroll_bar_type; | |
3862 | ||
44fa5b1e | 3863 | /* Apportion the available frame space among the two new windows */ |
7ab12479 | 3864 | |
265a9e55 | 3865 | if (!NILP (horflag)) |
7ab12479 | 3866 | { |
949cf20f KS |
3867 | p->total_lines = o->total_lines; |
3868 | p->top_line = o->top_line; | |
3869 | XSETFASTINT (p->total_cols, XFASTINT (o->total_cols) - size_int); | |
3870 | XSETFASTINT (o->total_cols, size_int); | |
3871 | XSETFASTINT (p->left_col, XFASTINT (o->left_col) + size_int); | |
3872 | adjust_window_margins (p); | |
3873 | adjust_window_margins (o); | |
7ab12479 JB |
3874 | } |
3875 | else | |
3876 | { | |
949cf20f KS |
3877 | p->left_col = o->left_col; |
3878 | p->total_cols = o->total_cols; | |
3879 | XSETFASTINT (p->total_lines, XFASTINT (o->total_lines) - size_int); | |
3880 | XSETFASTINT (o->total_lines, size_int); | |
3881 | XSETFASTINT (p->top_line, XFASTINT (o->top_line) + size_int); | |
7ab12479 JB |
3882 | } |
3883 | ||
5500c422 GM |
3884 | /* Adjust glyph matrices. */ |
3885 | adjust_glyphs (fo); | |
949cf20f KS |
3886 | |
3887 | Fset_window_buffer (new, o->buffer, Qt); | |
7ab12479 JB |
3888 | return new; |
3889 | } | |
3890 | \f | |
56ebfae2 | 3891 | DEFUN ("enlarge-window", Fenlarge_window, Senlarge_window, 1, 2, "p", |
fdb82f93 PJ |
3892 | doc: /* Make current window ARG lines bigger. |
3893 | From program, optional second arg non-nil means grow sideways ARG columns. | |
f95284d2 | 3894 | Interactively, if an argument is not given, make the window one line bigger. |
5afc696a | 3895 | If HORIZONTAL is non-nil, enlarge horizontally instead of vertically. |
56ebfae2 RS |
3896 | This function can delete windows, even the second window, if they get |
3897 | too small. */) | |
3898 | (arg, horizontal) | |
3899 | Lisp_Object arg, horizontal; | |
7ab12479 | 3900 | { |
b7826503 | 3901 | CHECK_NUMBER (arg); |
56ebfae2 | 3902 | enlarge_window (selected_window, XINT (arg), !NILP (horizontal)); |
543f5fb1 | 3903 | |
eeca6f6f | 3904 | run_window_configuration_change_hook (SELECTED_FRAME ()); |
543f5fb1 | 3905 | |
7ab12479 JB |
3906 | return Qnil; |
3907 | } | |
3908 | ||
56ebfae2 | 3909 | DEFUN ("shrink-window", Fshrink_window, Sshrink_window, 1, 2, "p", |
fdb82f93 PJ |
3910 | doc: /* Make current window ARG lines smaller. |
3911 | From program, optional second arg non-nil means shrink sideways arg columns. | |
4797b6d9 JB |
3912 | Interactively, if an argument is not given, make the window one line smaller. |
3913 | Only siblings to the right or below are changed. */) | |
56ebfae2 RS |
3914 | (arg, side) |
3915 | Lisp_Object arg, side; | |
7ab12479 | 3916 | { |
b7826503 | 3917 | CHECK_NUMBER (arg); |
56ebfae2 | 3918 | enlarge_window (selected_window, -XINT (arg), !NILP (side)); |
543f5fb1 | 3919 | |
eeca6f6f | 3920 | run_window_configuration_change_hook (SELECTED_FRAME ()); |
543f5fb1 | 3921 | |
7ab12479 JB |
3922 | return Qnil; |
3923 | } | |
3924 | ||
3925 | int | |
3926 | window_height (window) | |
3927 | Lisp_Object window; | |
3928 | { | |
3929 | register struct window *p = XWINDOW (window); | |
949cf20f | 3930 | return WINDOW_TOTAL_LINES (p); |
7ab12479 JB |
3931 | } |
3932 | ||
3933 | int | |
3934 | window_width (window) | |
3935 | Lisp_Object window; | |
3936 | { | |
3937 | register struct window *p = XWINDOW (window); | |
949cf20f | 3938 | return WINDOW_TOTAL_COLS (p); |
7ab12479 JB |
3939 | } |
3940 | ||
177c0ea7 | 3941 | |
7ab12479 | 3942 | #define CURBEG(w) \ |
5afc696a | 3943 | *(horiz_flag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line)) |
7ab12479 JB |
3944 | |
3945 | #define CURSIZE(w) \ | |
5afc696a | 3946 | *(horiz_flag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines)) |
7ab12479 | 3947 | |
233a4a2c | 3948 | |
047aaeb9 MR |
3949 | /* Enlarge WINDOW by DELTA. HORIZ_FLAG nonzero means enlarge it |
3950 | horizontally; zero means do it vertically. | |
f95284d2 | 3951 | |
5afc696a | 3952 | Siblings of the selected window are resized to fulfill the size |
047aaeb9 | 3953 | request. If they become too small in the process, they may be |
56ebfae2 | 3954 | deleted. */ |
7ab12479 | 3955 | |
f984d4fc | 3956 | static void |
56ebfae2 | 3957 | enlarge_window (window, delta, horiz_flag) |
86c8e823 | 3958 | Lisp_Object window; |
56ebfae2 | 3959 | int delta, horiz_flag; |
7ab12479 | 3960 | { |
86c8e823 | 3961 | Lisp_Object parent, next, prev; |
233a4a2c | 3962 | struct window *p; |
3578db3c KR |
3963 | Lisp_Object *sizep; |
3964 | int maximum; | |
5e14b1fc | 3965 | int (*sizefun) P_ ((Lisp_Object)) |
5afc696a | 3966 | = horiz_flag ? window_width : window_height; |
233a4a2c | 3967 | void (*setsizefun) P_ ((Lisp_Object, int, int)) |
5afc696a | 3968 | = (horiz_flag ? set_window_width : set_window_height); |
7ab12479 | 3969 | |
233a4a2c | 3970 | /* Give up if this window cannot be resized. */ |
5afc696a | 3971 | if (window_fixed_size_p (XWINDOW (window), horiz_flag, 1)) |
233a4a2c GM |
3972 | error ("Window is not resizable"); |
3973 | ||
3974 | /* Find the parent of the selected window. */ | |
7ab12479 JB |
3975 | while (1) |
3976 | { | |
3977 | p = XWINDOW (window); | |
3978 | parent = p->parent; | |
177c0ea7 | 3979 | |
265a9e55 | 3980 | if (NILP (parent)) |
7ab12479 | 3981 | { |
5afc696a | 3982 | if (horiz_flag) |
7ab12479 JB |
3983 | error ("No other window to side of this one"); |
3984 | break; | |
3985 | } | |
177c0ea7 | 3986 | |
5afc696a | 3987 | if (horiz_flag |
233a4a2c | 3988 | ? !NILP (XWINDOW (parent)->hchild) |
265a9e55 | 3989 | : !NILP (XWINDOW (parent)->vchild)) |
7ab12479 | 3990 | break; |
177c0ea7 | 3991 | |
7ab12479 JB |
3992 | window = parent; |
3993 | } | |
3994 | ||
05c2896a | 3995 | sizep = &CURSIZE (window); |
7ab12479 | 3996 | |
7ab12479 JB |
3997 | { |
3998 | register int maxdelta; | |
7ab12479 | 3999 | |
f95284d2 RS |
4000 | /* Compute the maximum size increment this window can have. */ |
4001 | ||
56ebfae2 RS |
4002 | maxdelta = (!NILP (parent) ? (*sizefun) (parent) - XINT (*sizep) |
4003 | /* This is a main window followed by a minibuffer. */ | |
4004 | : !NILP (p->next) ? ((*sizefun) (p->next) | |
4005 | - window_min_size (XWINDOW (p->next), | |
047aaeb9 | 4006 | horiz_flag, 0, 0, 0)) |
56ebfae2 RS |
4007 | /* This is a minibuffer following a main window. */ |
4008 | : !NILP (p->prev) ? ((*sizefun) (p->prev) | |
4009 | - window_min_size (XWINDOW (p->prev), | |
047aaeb9 | 4010 | horiz_flag, 0, 0, 0)) |
56ebfae2 RS |
4011 | /* This is a frame with only one window, a minibuffer-only |
4012 | or a minibufferless frame. */ | |
4013 | : (delta = 0)); | |
7ab12479 JB |
4014 | |
4015 | if (delta > maxdelta) | |
4016 | /* This case traps trying to make the minibuffer | |
44fa5b1e JB |
4017 | the full frame, or make the only window aside from the |
4018 | minibuffer the full frame. */ | |
7ab12479 | 4019 | delta = maxdelta; |
6b54027b | 4020 | } |
d5783c40 | 4021 | |
047aaeb9 MR |
4022 | if (XINT (*sizep) + delta < window_min_size (XWINDOW (window), |
4023 | horiz_flag, 0, 0, 0)) | |
6b54027b | 4024 | { |
543f5fb1 | 4025 | delete_window (window); |
d5783c40 | 4026 | return; |
6b54027b RS |
4027 | } |
4028 | ||
4029 | if (delta == 0) | |
4030 | return; | |
7ab12479 | 4031 | |
f95284d2 | 4032 | /* Find the total we can get from other siblings without deleting them. */ |
db98a733 | 4033 | maximum = 0; |
9beb8baa | 4034 | for (next = p->next; WINDOWP (next); next = XWINDOW (next)->next) |
c1636aa6 | 4035 | maximum += (*sizefun) (next) - window_min_size (XWINDOW (next), |
047aaeb9 | 4036 | horiz_flag, 0, 0, 0); |
9beb8baa | 4037 | for (prev = p->prev; WINDOWP (prev); prev = XWINDOW (prev)->prev) |
56ebfae2 | 4038 | maximum += (*sizefun) (prev) - window_min_size (XWINDOW (prev), |
047aaeb9 | 4039 | horiz_flag, 0, 0, 0); |
db98a733 | 4040 | |
f95284d2 | 4041 | /* If we can get it all from them without deleting them, do so. */ |
c6b530ed | 4042 | if (delta <= maximum) |
7ab12479 | 4043 | { |
db98a733 RS |
4044 | Lisp_Object first_unaffected; |
4045 | Lisp_Object first_affected; | |
233a4a2c | 4046 | int fixed_p; |
db98a733 RS |
4047 | |
4048 | next = p->next; | |
4049 | prev = p->prev; | |
4050 | first_affected = window; | |
4051 | /* Look at one sibling at a time, | |
4052 | moving away from this window in both directions alternately, | |
4053 | and take as much as we can get without deleting that sibling. */ | |
f95284d2 | 4054 | while (delta != 0 |
56ebfae2 | 4055 | && (!NILP (next) || !NILP (prev))) |
db98a733 | 4056 | { |
db98a733 RS |
4057 | if (! NILP (next)) |
4058 | { | |
c1636aa6 | 4059 | int this_one = ((*sizefun) (next) |
047aaeb9 MR |
4060 | - window_min_size (XWINDOW (next), horiz_flag, |
4061 | 0, 0, &fixed_p)); | |
233a4a2c GM |
4062 | if (!fixed_p) |
4063 | { | |
4064 | if (this_one > delta) | |
4065 | this_one = delta; | |
177c0ea7 | 4066 | |
233a4a2c | 4067 | (*setsizefun) (next, (*sizefun) (next) - this_one, 0); |
3578db3c | 4068 | (*setsizefun) (window, XINT (*sizep) + this_one, 0); |
db98a733 | 4069 | |
233a4a2c GM |
4070 | delta -= this_one; |
4071 | } | |
177c0ea7 | 4072 | |
db98a733 RS |
4073 | next = XWINDOW (next)->next; |
4074 | } | |
177c0ea7 | 4075 | |
db98a733 RS |
4076 | if (delta == 0) |
4077 | break; | |
177c0ea7 | 4078 | |
56ebfae2 | 4079 | if (! NILP (prev)) |
db98a733 | 4080 | { |
c1636aa6 | 4081 | int this_one = ((*sizefun) (prev) |
047aaeb9 MR |
4082 | - window_min_size (XWINDOW (prev), horiz_flag, |
4083 | 0, 0, &fixed_p)); | |
233a4a2c GM |
4084 | if (!fixed_p) |
4085 | { | |
4086 | if (this_one > delta) | |
4087 | this_one = delta; | |
177c0ea7 | 4088 | |
233a4a2c | 4089 | first_affected = prev; |
177c0ea7 | 4090 | |
233a4a2c | 4091 | (*setsizefun) (prev, (*sizefun) (prev) - this_one, 0); |
3578db3c | 4092 | (*setsizefun) (window, XINT (*sizep) + this_one, 0); |
233a4a2c GM |
4093 | |
4094 | delta -= this_one; | |
4095 | } | |
177c0ea7 | 4096 | |
db98a733 RS |
4097 | prev = XWINDOW (prev)->prev; |
4098 | } | |
4099 | } | |
4100 | ||
233a4a2c GM |
4101 | xassert (delta == 0); |
4102 | ||
db98a733 RS |
4103 | /* Now recalculate the edge positions of all the windows affected, |
4104 | based on the new sizes. */ | |
4105 | first_unaffected = next; | |
4106 | prev = first_affected; | |
4107 | for (next = XWINDOW (prev)->next; ! EQ (next, first_unaffected); | |
4108 | prev = next, next = XWINDOW (next)->next) | |
4109 | { | |
3578db3c | 4110 | XSETINT (CURBEG (next), XINT (CURBEG (prev)) + (*sizefun) (prev)); |
db98a733 RS |
4111 | /* This does not change size of NEXT, |
4112 | but it propagates the new top edge to its children */ | |
4113 | (*setsizefun) (next, (*sizefun) (next), 0); | |
4114 | } | |
7ab12479 JB |
4115 | } |
4116 | else | |
4117 | { | |
4118 | register int delta1; | |
4119 | register int opht = (*sizefun) (parent); | |
4120 | ||
3578db3c | 4121 | if (opht <= XINT (*sizep) + delta) |
daf516d3 RS |
4122 | { |
4123 | /* If trying to grow this window to or beyond size of the parent, | |
4124 | just delete all the sibling windows. */ | |
dc1ab1ee | 4125 | Lisp_Object start, tem, next; |
daf516d3 | 4126 | |
dc1ab1ee RS |
4127 | start = XWINDOW (parent)->vchild; |
4128 | if (NILP (start)) | |
4129 | start = XWINDOW (parent)->hchild; | |
daf516d3 | 4130 | |
dc1ab1ee RS |
4131 | /* Delete any siblings that come after WINDOW. */ |
4132 | tem = XWINDOW (window)->next; | |
daf516d3 RS |
4133 | while (! NILP (tem)) |
4134 | { | |
4135 | next = XWINDOW (tem)->next; | |
dc1ab1ee RS |
4136 | delete_window (tem); |
4137 | tem = next; | |
4138 | } | |
4139 | ||
4140 | /* Delete any siblings that come after WINDOW. | |
4141 | Note that if START is not WINDOW, then WINDOW still | |
047aaeb9 | 4142 | has siblings, so WINDOW has not yet replaced its parent. */ |
dc1ab1ee RS |
4143 | tem = start; |
4144 | while (! EQ (tem, window)) | |
4145 | { | |
4146 | next = XWINDOW (tem)->next; | |
4147 | delete_window (tem); | |
daf516d3 RS |
4148 | tem = next; |
4149 | } | |
4150 | } | |
7ab12479 | 4151 | else |
233a4a2c GM |
4152 | { |
4153 | /* Otherwise, make delta1 just right so that if we add | |
4154 | delta1 lines to this window and to the parent, and then | |
4155 | shrink the parent back to its original size, the new | |
4156 | proportional size of this window will increase by delta. | |
4157 | ||
4158 | The function size_window will compute the new height h' | |
4159 | of the window from delta1 as: | |
177c0ea7 | 4160 | |
233a4a2c GM |
4161 | e = delta1/n |
4162 | x = delta1 - delta1/n * n for the 1st resizable child | |
4163 | h' = h + e + x | |
4164 | ||
4165 | where n is the number of children that can be resized. | |
4166 | We can ignore x by choosing a delta1 that is a multiple of | |
4167 | n. We want the height of this window to come out as | |
177c0ea7 | 4168 | |
233a4a2c GM |
4169 | h' = h + delta |
4170 | ||
4171 | So, delta1 must be | |
177c0ea7 | 4172 | |
233a4a2c GM |
4173 | h + e = h + delta |
4174 | delta1/n = delta | |
4175 | delta1 = n * delta. | |
4176 | ||
a5731348 | 4177 | The number of children n equals the number of resizable |
233a4a2c | 4178 | children of this window + 1 because we know window itself |
04bf5b65 | 4179 | is resizable (otherwise we would have signaled an error). |
047aaeb9 MR |
4180 | |
4181 | This reasoning is not correct when other windows become too | |
4182 | small and shrink_windows refuses to delete them. Below we | |
4183 | use resize_proportionally to work around this problem. */ | |
233a4a2c GM |
4184 | |
4185 | struct window *w = XWINDOW (window); | |
4186 | Lisp_Object s; | |
4187 | int n = 1; | |
4188 | ||
9beb8baa | 4189 | for (s = w->next; WINDOWP (s); s = XWINDOW (s)->next) |
5afc696a | 4190 | if (!window_fixed_size_p (XWINDOW (s), horiz_flag, 0)) |
233a4a2c | 4191 | ++n; |
9beb8baa | 4192 | for (s = w->prev; WINDOWP (s); s = XWINDOW (s)->prev) |
5afc696a | 4193 | if (!window_fixed_size_p (XWINDOW (s), horiz_flag, 0)) |
233a4a2c GM |
4194 | ++n; |
4195 | ||
4196 | delta1 = n * delta; | |
7ab12479 | 4197 | |
daf516d3 RS |
4198 | /* Add delta1 lines or columns to this window, and to the parent, |
4199 | keeping things consistent while not affecting siblings. */ | |
4200 | XSETINT (CURSIZE (parent), opht + delta1); | |
4201 | (*setsizefun) (window, XINT (*sizep) + delta1, 0); | |
4202 | ||
4203 | /* Squeeze out delta1 lines or columns from our parent, | |
047aaeb9 MR |
4204 | shrinking this window and siblings proportionately. This |
4205 | brings parent back to correct size. Delta1 was calculated | |
4206 | so this makes this window the desired size, taking it all | |
4207 | out of the siblings. | |
4208 | ||
4209 | Temporarily set resize_proportionally to Qt to assure that, | |
4210 | if necessary, shrink_windows deletes smaller windows rather | |
4211 | than shrink this window. */ | |
4212 | w->resize_proportionally = Qt; | |
daf516d3 | 4213 | (*setsizefun) (parent, opht, 0); |
047aaeb9 | 4214 | w->resize_proportionally = Qnil; |
daf516d3 | 4215 | } |
7ab12479 JB |
4216 | } |
4217 | ||
d834a2e9 | 4218 | XSETFASTINT (p->last_modified, 0); |
3cd21523 | 4219 | XSETFASTINT (p->last_overlay_modified, 0); |
5500c422 GM |
4220 | |
4221 | /* Adjust glyph matrices. */ | |
4222 | adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window)))); | |
7ab12479 | 4223 | } |
c1636aa6 | 4224 | |
0d384044 RS |
4225 | |
4226 | /* Adjust the size of WINDOW by DELTA, moving only its trailing edge. | |
4227 | HORIZ_FLAG nonzero means adjust the width, moving the right edge. | |
4228 | zero means adjust the height, moving the bottom edge. | |
4229 | ||
4230 | Following siblings of the selected window are resized to fulfill | |
4231 | the size request. If they become too small in the process, they | |
4232 | are not deleted; instead, we signal an error. */ | |
4233 | ||
4234 | static void | |
4235 | adjust_window_trailing_edge (window, delta, horiz_flag) | |
4236 | Lisp_Object window; | |
4237 | int delta, horiz_flag; | |
4238 | { | |
4239 | Lisp_Object parent, child; | |
4240 | struct window *p; | |
4241 | Lisp_Object old_config = Fcurrent_window_configuration (Qnil); | |
4242 | int delcount = window_deletion_count; | |
4243 | ||
0d384044 RS |
4244 | CHECK_WINDOW (window); |
4245 | ||
4246 | /* Give up if this window cannot be resized. */ | |
4247 | if (window_fixed_size_p (XWINDOW (window), horiz_flag, 1)) | |
4248 | error ("Window is not resizable"); | |
4249 | ||
4250 | while (1) | |
4251 | { | |
bd99e242 RS |
4252 | Lisp_Object first_parallel = Qnil; |
4253 | ||
c32de52a | 4254 | if (NILP (window)) |
0d384044 | 4255 | { |
5fe0b054 RS |
4256 | /* This happens if WINDOW on the previous iteration was |
4257 | at top level of the window tree. */ | |
0d384044 | 4258 | Fset_window_configuration (old_config); |
c32de52a | 4259 | error ("Specified window edge is fixed"); |
0d384044 RS |
4260 | } |
4261 | ||
c32de52a RS |
4262 | p = XWINDOW (window); |
4263 | parent = p->parent; | |
4264 | ||
bd99e242 RS |
4265 | /* See if this level has windows in parallel in the specified |
4266 | direction. If so, set FIRST_PARALLEL to the first one. */ | |
4267 | if (horiz_flag) | |
4268 | { | |
4269 | if (! NILP (parent) && !NILP (XWINDOW (parent)->vchild)) | |
4270 | first_parallel = XWINDOW (parent)->vchild; | |
5fe0b054 RS |
4271 | else if (NILP (parent) && !NILP (p->next)) |
4272 | { | |
4273 | /* Handle the vertical chain of main window and minibuffer | |
4274 | which has no parent. */ | |
4275 | first_parallel = window; | |
4276 | while (! NILP (XWINDOW (first_parallel)->prev)) | |
4277 | first_parallel = XWINDOW (first_parallel)->prev; | |
4278 | } | |
bd99e242 RS |
4279 | } |
4280 | else | |
4281 | { | |
4282 | if (! NILP (parent) && !NILP (XWINDOW (parent)->hchild)) | |
4283 | first_parallel = XWINDOW (parent)->hchild; | |
4284 | } | |
4285 | ||
c32de52a | 4286 | /* If this level's succession is in the desired dimension, |
5fe0b054 RS |
4287 | and this window is the last one, and there is no higher level, |
4288 | its trailing edge is fixed. */ | |
4289 | if (NILP (XWINDOW (window)->next) && NILP (first_parallel) | |
4290 | && NILP (parent)) | |
c32de52a RS |
4291 | { |
4292 | Fset_window_configuration (old_config); | |
4293 | error ("Specified window edge is fixed"); | |
4294 | } | |
4295 | ||
0d384044 RS |
4296 | /* Don't make this window too small. */ |
4297 | if (XINT (CURSIZE (window)) + delta | |
047aaeb9 | 4298 | < window_min_size_2 (XWINDOW (window), horiz_flag, 0)) |
0d384044 RS |
4299 | { |
4300 | Fset_window_configuration (old_config); | |
4301 | error ("Cannot adjust window size as specified"); | |
4302 | } | |
4303 | ||
4304 | /* Clear out some redisplay caches. */ | |
4305 | XSETFASTINT (p->last_modified, 0); | |
4306 | XSETFASTINT (p->last_overlay_modified, 0); | |
4307 | ||
4308 | /* Adjust this window's edge. */ | |
4309 | XSETINT (CURSIZE (window), | |
4310 | XINT (CURSIZE (window)) + delta); | |
4311 | ||
4312 | /* If this window has following siblings in the desired dimension, | |
bd99e242 RS |
4313 | make them smaller, and exit the loop. |
4314 | ||
0d384044 RS |
4315 | (If we reach the top of the tree and can never do this, |
4316 | we will fail and report an error, above.) */ | |
bd99e242 | 4317 | if (NILP (first_parallel)) |
0d384044 | 4318 | { |
c32de52a | 4319 | if (!NILP (p->next)) |
0d384044 | 4320 | { |
e99c7521 JD |
4321 | /* This may happen for the minibuffer. In that case |
4322 | the window_deletion_count check below does not work. */ | |
a53d44a8 | 4323 | if (XINT (CURSIZE (p->next)) - delta <= 0) |
e99c7521 JD |
4324 | { |
4325 | Fset_window_configuration (old_config); | |
4326 | error ("Cannot adjust window size as specified"); | |
4327 | } | |
4328 | ||
0d384044 RS |
4329 | XSETINT (CURBEG (p->next), |
4330 | XINT (CURBEG (p->next)) + delta); | |
4331 | size_window (p->next, XINT (CURSIZE (p->next)) - delta, | |
5fe0b054 | 4332 | horiz_flag, 0, 1, 0); |
0d384044 RS |
4333 | break; |
4334 | } | |
4335 | } | |
4336 | else | |
4337 | /* Here we have a chain of parallel siblings, in the other dimension. | |
4338 | Change the size of the other siblings. */ | |
bd99e242 | 4339 | for (child = first_parallel; |
0d384044 RS |
4340 | ! NILP (child); |
4341 | child = XWINDOW (child)->next) | |
4342 | if (! EQ (child, window)) | |
4343 | size_window (child, XINT (CURSIZE (child)) + delta, | |
5fe0b054 | 4344 | horiz_flag, 0, 0, 1); |
0d384044 RS |
4345 | |
4346 | window = parent; | |
4347 | } | |
4348 | ||
4349 | /* If we made a window so small it got deleted, | |
4350 | we failed. Report failure. */ | |
4351 | if (delcount != window_deletion_count) | |
4352 | { | |
4353 | Fset_window_configuration (old_config); | |
4354 | error ("Cannot adjust window size as specified"); | |
4355 | } | |
4356 | ||
4357 | /* Adjust glyph matrices. */ | |
4358 | adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window)))); | |
4359 | } | |
4360 | ||
7ab12479 JB |
4361 | #undef CURBEG |
4362 | #undef CURSIZE | |
4363 | ||
0d384044 RS |
4364 | DEFUN ("adjust-window-trailing-edge", Fadjust_window_trailing_edge, |
4365 | Sadjust_window_trailing_edge, 3, 3, 0, | |
4366 | doc: /* Adjust the bottom or right edge of WINDOW by DELTA. | |
56ebfae2 | 4367 | If HORIZONTAL is non-nil, that means adjust the width, moving the right edge. |
0d384044 RS |
4368 | Otherwise, adjust the height, moving the bottom edge. |
4369 | ||
4370 | Following siblings of the selected window are resized to fulfill | |
4371 | the size request. If they become too small in the process, they | |
4372 | are not deleted; instead, we signal an error. */) | |
4373 | (window, delta, horizontal) | |
4374 | Lisp_Object window, delta, horizontal; | |
4375 | { | |
4376 | CHECK_NUMBER (delta); | |
eeca6f6f SM |
4377 | if (NILP (window)) |
4378 | window = selected_window; | |
0d384044 RS |
4379 | adjust_window_trailing_edge (window, XINT (delta), !NILP (horizontal)); |
4380 | ||
eeca6f6f SM |
4381 | run_window_configuration_change_hook |
4382 | (XFRAME (WINDOW_FRAME (XWINDOW (window)))); | |
0d384044 RS |
4383 | |
4384 | return Qnil; | |
4385 | } | |
4386 | ||
5500c422 | 4387 | |
f984d4fc GM |
4388 | \f |
4389 | /*********************************************************************** | |
4390 | Resizing Mini-Windows | |
4391 | ***********************************************************************/ | |
4392 | ||
4393 | static void shrink_window_lowest_first P_ ((struct window *, int)); | |
f984d4fc | 4394 | |
43b4a21f GM |
4395 | enum save_restore_action |
4396 | { | |
4397 | CHECK_ORIG_SIZES, | |
4398 | SAVE_ORIG_SIZES, | |
4399 | RESTORE_ORIG_SIZES | |
4400 | }; | |
4401 | ||
177c0ea7 | 4402 | static int save_restore_orig_size P_ ((struct window *, |
43b4a21f | 4403 | enum save_restore_action)); |
f984d4fc GM |
4404 | |
4405 | /* Shrink windows rooted in window W to HEIGHT. Take the space needed | |
4406 | from lowest windows first. */ | |
4407 | ||
4408 | static void | |
4409 | shrink_window_lowest_first (w, height) | |
4410 | struct window *w; | |
4411 | int height; | |
4412 | { | |
4413 | struct window *c; | |
4414 | Lisp_Object child; | |
4415 | int old_height; | |
4416 | ||
4417 | xassert (!MINI_WINDOW_P (w)); | |
4418 | ||
4419 | /* Set redisplay hints. */ | |
4420 | XSETFASTINT (w->last_modified, 0); | |
4421 | XSETFASTINT (w->last_overlay_modified, 0); | |
4422 | windows_or_buffers_changed++; | |
4423 | FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w))) = 1; | |
4424 | ||
949cf20f KS |
4425 | old_height = XFASTINT (w->total_lines); |
4426 | XSETFASTINT (w->total_lines, height); | |
f984d4fc GM |
4427 | |
4428 | if (!NILP (w->hchild)) | |
4429 | { | |
4430 | for (child = w->hchild; !NILP (child); child = c->next) | |
4431 | { | |
4432 | c = XWINDOW (child); | |
949cf20f | 4433 | c->top_line = w->top_line; |
f984d4fc GM |
4434 | shrink_window_lowest_first (c, height); |
4435 | } | |
4436 | } | |
4437 | else if (!NILP (w->vchild)) | |
4438 | { | |
4439 | Lisp_Object last_child; | |
4440 | int delta = old_height - height; | |
4441 | int last_top; | |
6bbd7a29 GM |
4442 | |
4443 | last_child = Qnil; | |
177c0ea7 | 4444 | |
f984d4fc GM |
4445 | /* Find the last child. We are taking space from lowest windows |
4446 | first, so we iterate over children from the last child | |
4447 | backwards. */ | |
9beb8baa | 4448 | for (child = w->vchild; WINDOWP (child); child = XWINDOW (child)->next) |
f984d4fc GM |
4449 | last_child = child; |
4450 | ||
047aaeb9 | 4451 | /* Size children down to their safe heights. */ |
f984d4fc GM |
4452 | for (child = last_child; delta && !NILP (child); child = c->prev) |
4453 | { | |
4454 | int this_one; | |
177c0ea7 | 4455 | |
f984d4fc | 4456 | c = XWINDOW (child); |
047aaeb9 | 4457 | this_one = XFASTINT (c->total_lines) - window_min_size_1 (c, 0, 1); |
f984d4fc GM |
4458 | |
4459 | if (this_one > delta) | |
4460 | this_one = delta; | |
4461 | ||
949cf20f | 4462 | shrink_window_lowest_first (c, XFASTINT (c->total_lines) - this_one); |
f984d4fc GM |
4463 | delta -= this_one; |
4464 | } | |
4465 | ||
4466 | /* Compute new positions. */ | |
949cf20f | 4467 | last_top = XINT (w->top_line); |
f984d4fc GM |
4468 | for (child = w->vchild; !NILP (child); child = c->next) |
4469 | { | |
4470 | c = XWINDOW (child); | |
949cf20f KS |
4471 | c->top_line = make_number (last_top); |
4472 | shrink_window_lowest_first (c, XFASTINT (c->total_lines)); | |
4473 | last_top += XFASTINT (c->total_lines); | |
f984d4fc GM |
4474 | } |
4475 | } | |
4476 | } | |
4477 | ||
4478 | ||
43b4a21f GM |
4479 | /* Save, restore, or check positions and sizes in the window tree |
4480 | rooted at W. ACTION says what to do. | |
f984d4fc | 4481 | |
949cf20f KS |
4482 | If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and |
4483 | orig_total_lines members are valid for all windows in the window | |
4484 | tree. Value is non-zero if they are valid. | |
177c0ea7 | 4485 | |
43b4a21f | 4486 | If ACTION is SAVE_ORIG_SIZES, save members top and height in |
949cf20f | 4487 | orig_top_line and orig_total_lines for all windows in the tree. |
43b4a21f | 4488 | |
949cf20f KS |
4489 | If ACTION is RESTORE_ORIG_SIZES, restore top and height from values |
4490 | stored in orig_top_line and orig_total_lines for all windows. */ | |
43b4a21f GM |
4491 | |
4492 | static int | |
4493 | save_restore_orig_size (w, action) | |
f984d4fc | 4494 | struct window *w; |
43b4a21f | 4495 | enum save_restore_action action; |
f984d4fc | 4496 | { |
43b4a21f GM |
4497 | int success_p = 1; |
4498 | ||
f984d4fc GM |
4499 | while (w) |
4500 | { | |
4501 | if (!NILP (w->hchild)) | |
43b4a21f GM |
4502 | { |
4503 | if (!save_restore_orig_size (XWINDOW (w->hchild), action)) | |
4504 | success_p = 0; | |
4505 | } | |
f984d4fc | 4506 | else if (!NILP (w->vchild)) |
43b4a21f GM |
4507 | { |
4508 | if (!save_restore_orig_size (XWINDOW (w->vchild), action)) | |
4509 | success_p = 0; | |
4510 | } | |
177c0ea7 | 4511 | |
43b4a21f | 4512 | switch (action) |
f984d4fc | 4513 | { |
43b4a21f | 4514 | case CHECK_ORIG_SIZES: |
949cf20f | 4515 | if (!INTEGERP (w->orig_top_line) || !INTEGERP (w->orig_total_lines)) |
43b4a21f GM |
4516 | return 0; |
4517 | break; | |
4518 | ||
4519 | case SAVE_ORIG_SIZES: | |
949cf20f KS |
4520 | w->orig_top_line = w->top_line; |
4521 | w->orig_total_lines = w->total_lines; | |
43b4a21f GM |
4522 | XSETFASTINT (w->last_modified, 0); |
4523 | XSETFASTINT (w->last_overlay_modified, 0); | |
4524 | break; | |
4525 | ||
4526 | case RESTORE_ORIG_SIZES: | |
949cf20f KS |
4527 | xassert (INTEGERP (w->orig_top_line) && INTEGERP (w->orig_total_lines)); |
4528 | w->top_line = w->orig_top_line; | |
4529 | w->total_lines = w->orig_total_lines; | |
4530 | w->orig_total_lines = w->orig_top_line = Qnil; | |
43b4a21f GM |
4531 | XSETFASTINT (w->last_modified, 0); |
4532 | XSETFASTINT (w->last_overlay_modified, 0); | |
4533 | break; | |
4534 | ||
4535 | default: | |
4536 | abort (); | |
f984d4fc | 4537 | } |
43b4a21f | 4538 | |
f984d4fc GM |
4539 | w = NILP (w->next) ? NULL : XWINDOW (w->next); |
4540 | } | |
43b4a21f GM |
4541 | |
4542 | return success_p; | |
f984d4fc GM |
4543 | } |
4544 | ||
4545 | ||
4546 | /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can | |
4547 | without deleting other windows. */ | |
4548 | ||
4549 | void | |
4550 | grow_mini_window (w, delta) | |
4551 | struct window *w; | |
4552 | int delta; | |
4553 | { | |
4554 | struct frame *f = XFRAME (w->frame); | |
4555 | struct window *root; | |
177c0ea7 | 4556 | |
f984d4fc GM |
4557 | xassert (MINI_WINDOW_P (w)); |
4558 | xassert (delta >= 0); | |
177c0ea7 | 4559 | |
f984d4fc GM |
4560 | /* Compute how much we can enlarge the mini-window without deleting |
4561 | other windows. */ | |
4562 | root = XWINDOW (FRAME_ROOT_WINDOW (f)); | |
4563 | if (delta) | |
4564 | { | |
047aaeb9 | 4565 | int min_height = window_min_size (root, 0, 0, 0, 0); |
949cf20f | 4566 | if (XFASTINT (root->total_lines) - delta < min_height) |
8b8bd9c6 | 4567 | /* Note that the root window may already be smaller than |
eafa3196 | 4568 | min_height. */ |
949cf20f | 4569 | delta = max (0, XFASTINT (root->total_lines) - min_height); |
f984d4fc | 4570 | } |
177c0ea7 | 4571 | |
f984d4fc GM |
4572 | if (delta) |
4573 | { | |
4574 | /* Save original window sizes and positions, if not already done. */ | |
43b4a21f GM |
4575 | if (!save_restore_orig_size (root, CHECK_ORIG_SIZES)) |
4576 | save_restore_orig_size (root, SAVE_ORIG_SIZES); | |
f984d4fc GM |
4577 | |
4578 | /* Shrink other windows. */ | |
949cf20f | 4579 | shrink_window_lowest_first (root, XFASTINT (root->total_lines) - delta); |
f984d4fc GM |
4580 | |
4581 | /* Grow the mini-window. */ | |
949cf20f KS |
4582 | w->top_line = make_number (XFASTINT (root->top_line) + XFASTINT (root->total_lines)); |
4583 | w->total_lines = make_number (XFASTINT (w->total_lines) + delta); | |
f984d4fc GM |
4584 | XSETFASTINT (w->last_modified, 0); |
4585 | XSETFASTINT (w->last_overlay_modified, 0); | |
177c0ea7 | 4586 | |
f984d4fc GM |
4587 | adjust_glyphs (f); |
4588 | } | |
4589 | } | |
4590 | ||
4591 | ||
86c8e823 GM |
4592 | /* Shrink mini-window W. If there is recorded info about window sizes |
4593 | before a call to grow_mini_window, restore recorded window sizes. | |
4594 | Otherwise, if the mini-window is higher than 1 line, resize it to 1 | |
4595 | line. */ | |
f984d4fc GM |
4596 | |
4597 | void | |
4598 | shrink_mini_window (w) | |
4599 | struct window *w; | |
4600 | { | |
4601 | struct frame *f = XFRAME (w->frame); | |
4602 | struct window *root = XWINDOW (FRAME_ROOT_WINDOW (f)); | |
4603 | ||
43b4a21f | 4604 | if (save_restore_orig_size (root, CHECK_ORIG_SIZES)) |
f984d4fc | 4605 | { |
43b4a21f | 4606 | save_restore_orig_size (root, RESTORE_ORIG_SIZES); |
f984d4fc GM |
4607 | adjust_glyphs (f); |
4608 | FRAME_WINDOW_SIZES_CHANGED (f) = 1; | |
4609 | windows_or_buffers_changed = 1; | |
4610 | } | |
949cf20f | 4611 | else if (XFASTINT (w->total_lines) > 1) |
86c8e823 | 4612 | { |
0130fe1a GM |
4613 | /* Distribute the additional lines of the mini-window |
4614 | among the other windows. */ | |
86c8e823 GM |
4615 | Lisp_Object window; |
4616 | XSETWINDOW (window, w); | |
56ebfae2 | 4617 | enlarge_window (window, 1 - XFASTINT (w->total_lines), 0); |
86c8e823 | 4618 | } |
f984d4fc GM |
4619 | } |
4620 | ||
4621 | ||
4622 | \f | |
5500c422 GM |
4623 | /* Mark window cursors off for all windows in the window tree rooted |
4624 | at W by setting their phys_cursor_on_p flag to zero. Called from | |
4625 | xterm.c, e.g. when a frame is cleared and thereby all cursors on | |
4626 | the frame are cleared. */ | |
4627 | ||
4628 | void | |
4629 | mark_window_cursors_off (w) | |
4630 | struct window *w; | |
4631 | { | |
4632 | while (w) | |
4633 | { | |
4634 | if (!NILP (w->hchild)) | |
4635 | mark_window_cursors_off (XWINDOW (w->hchild)); | |
4636 | else if (!NILP (w->vchild)) | |
4637 | mark_window_cursors_off (XWINDOW (w->vchild)); | |
4638 | else | |
4639 | w->phys_cursor_on_p = 0; | |
4640 | ||
4641 | w = NILP (w->next) ? 0 : XWINDOW (w->next); | |
4642 | } | |
4643 | } | |
4644 | ||
4645 | ||
e9c195b1 | 4646 | /* Return number of lines of text (not counting mode lines) in W. */ |
7ab12479 JB |
4647 | |
4648 | int | |
4649 | window_internal_height (w) | |
4650 | struct window *w; | |
4651 | { | |
949cf20f | 4652 | int ht = XFASTINT (w->total_lines); |
7ab12479 | 4653 | |
e9c195b1 GM |
4654 | if (!MINI_WINDOW_P (w)) |
4655 | { | |
4656 | if (!NILP (w->parent) | |
4657 | || !NILP (w->vchild) | |
4658 | || !NILP (w->hchild) | |
4659 | || !NILP (w->next) | |
4660 | || !NILP (w->prev) | |
4661 | || WINDOW_WANTS_MODELINE_P (w)) | |
4662 | --ht; | |
7ab12479 | 4663 | |
e9c195b1 GM |
4664 | if (WINDOW_WANTS_HEADER_LINE_P (w)) |
4665 | --ht; | |
4666 | } | |
7ab12479 JB |
4667 | |
4668 | return ht; | |
4669 | } | |
4670 | ||
535e0b8e JB |
4671 | |
4672 | /* Return the number of columns in W. | |
a3c87d4e | 4673 | Don't count columns occupied by scroll bars or the vertical bar |
535e0b8e | 4674 | separating W from the sibling to its right. */ |
5500c422 | 4675 | |
535e0b8e | 4676 | int |
949cf20f | 4677 | window_box_text_cols (w) |
535e0b8e JB |
4678 | struct window *w; |
4679 | { | |
5500c422 | 4680 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
949cf20f | 4681 | int width = XINT (w->total_cols); |
535e0b8e | 4682 | |
949cf20f | 4683 | if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w)) |
5500c422 | 4684 | /* Scroll bars occupy a few columns. */ |
949cf20f KS |
4685 | width -= WINDOW_CONFIG_SCROLL_BAR_COLS (w); |
4686 | else if (!FRAME_WINDOW_P (f) | |
4687 | && !WINDOW_RIGHTMOST_P (w) && !WINDOW_FULL_WIDTH_P (w)) | |
5500c422 GM |
4688 | /* The column of `|' characters separating side-by-side windows |
4689 | occupies one column only. */ | |
4690 | width -= 1; | |
4691 | ||
5500c422 | 4692 | if (FRAME_WINDOW_P (f)) |
949cf20f KS |
4693 | /* On window-systems, fringes and display margins cannot be |
4694 | used for normal text. */ | |
4695 | width -= (WINDOW_FRINGE_COLS (w) | |
4696 | + WINDOW_LEFT_MARGIN_COLS (w) | |
4697 | + WINDOW_RIGHT_MARGIN_COLS (w)); | |
111e5992 RS |
4698 | |
4699 | return width; | |
535e0b8e JB |
4700 | } |
4701 | ||
5500c422 GM |
4702 | \f |
4703 | /************************************************************************ | |
4704 | Window Scrolling | |
4705 | ***********************************************************************/ | |
535e0b8e | 4706 | |
5500c422 | 4707 | /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll |
d4e7cf01 | 4708 | N screen-fulls, which is defined as the height of the window minus |
5500c422 GM |
4709 | next_screen_context_lines. If WHOLE is zero, scroll up N lines |
4710 | instead. Negative values of N mean scroll down. NOERROR non-zero | |
4711 | means don't signal an error if we try to move over BEGV or ZV, | |
4712 | respectively. */ | |
7ab12479 | 4713 | |
101d1605 RS |
4714 | static void |
4715 | window_scroll (window, n, whole, noerror) | |
7ab12479 JB |
4716 | Lisp_Object window; |
4717 | int n; | |
101d1605 | 4718 | int whole; |
f8026fd8 | 4719 | int noerror; |
5500c422 | 4720 | { |
cba59f77 RS |
4721 | immediate_quit = 1; |
4722 | ||
5500c422 GM |
4723 | /* If we must, use the pixel-based version which is much slower than |
4724 | the line-based one but can handle varying line heights. */ | |
4725 | if (FRAME_WINDOW_P (XFRAME (XWINDOW (window)->frame))) | |
4726 | window_scroll_pixel_based (window, n, whole, noerror); | |
4727 | else | |
4728 | window_scroll_line_based (window, n, whole, noerror); | |
cba59f77 RS |
4729 | |
4730 | immediate_quit = 0; | |
5500c422 GM |
4731 | } |
4732 | ||
4733 | ||
4734 | /* Implementation of window_scroll that works based on pixel line | |
4735 | heights. See the comment of window_scroll for parameter | |
4736 | descriptions. */ | |
4737 | ||
4738 | static void | |
4739 | window_scroll_pixel_based (window, n, whole, noerror) | |
4740 | Lisp_Object window; | |
4741 | int n; | |
4742 | int whole; | |
4743 | int noerror; | |
4744 | { | |
4745 | struct it it; | |
4746 | struct window *w = XWINDOW (window); | |
4747 | struct text_pos start; | |
5500c422 | 4748 | int this_scroll_margin; |
9d14503e | 4749 | /* True if we fiddled the window vscroll field without really scrolling. */ |
5cdb3cf3 | 4750 | int vscrolled = 0; |
5a857365 | 4751 | int x, y, rtop, rbot, rowh, vpos; |
5500c422 GM |
4752 | |
4753 | SET_TEXT_POS_FROM_MARKER (start, w->start); | |
177c0ea7 | 4754 | |
5500c422 | 4755 | /* If PT is not visible in WINDOW, move back one half of |
288d4e06 GM |
4756 | the screen. Allow PT to be partially visible, otherwise |
4757 | something like (scroll-down 1) with PT in the line before | |
4758 | the partially visible one would recenter. */ | |
5a857365 KS |
4759 | |
4760 | if (!pos_visible_p (w, PT, &x, &y, &rtop, &rbot, &rowh, &vpos)) | |
5500c422 GM |
4761 | { |
4762 | /* Move backward half the height of the window. Performance note: | |
4763 | vmotion used here is about 10% faster, but would give wrong | |
4764 | results for variable height lines. */ | |
4765 | init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID); | |
4766 | it.current_y = it.last_visible_y; | |
f204989e | 4767 | move_it_vertically_backward (&it, window_box_height (w) / 2); |
177c0ea7 | 4768 | |
5500c422 GM |
4769 | /* The function move_iterator_vertically may move over more than |
4770 | the specified y-distance. If it->w is small, e.g. a | |
4771 | mini-buffer window, we may end up in front of the window's | |
4772 | display area. This is the case when Start displaying at the | |
4773 | start of the line containing PT in this case. */ | |
4774 | if (it.current_y <= 0) | |
4775 | { | |
4776 | init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID); | |
f204989e | 4777 | move_it_vertically_backward (&it, 0); |
5500c422 GM |
4778 | it.current_y = 0; |
4779 | } | |
4780 | ||
4781 | start = it.current.pos; | |
4782 | } | |
e56263e5 KS |
4783 | else if (auto_window_vscroll_p) |
4784 | { | |
5a857365 | 4785 | if (rtop || rbot) /* partially visible */ |
e56263e5 KS |
4786 | { |
4787 | int px; | |
4788 | int dy = WINDOW_FRAME_LINE_HEIGHT (w); | |
4789 | if (whole) | |
e856c216 KS |
4790 | dy = max ((window_box_height (w) |
4791 | - next_screen_context_lines * dy), | |
4792 | dy); | |
e56263e5 KS |
4793 | dy *= n; |
4794 | ||
5a857365 | 4795 | if (n < 0) |
e56263e5 | 4796 | { |
5a857365 KS |
4797 | /* Only vscroll backwards if already vscrolled forwards. */ |
4798 | if (w->vscroll < 0 && rtop > 0) | |
4799 | { | |
4800 | px = max (0, -w->vscroll - min (rtop, -dy)); | |
4801 | Fset_window_vscroll (window, make_number (px), Qt); | |
4802 | return; | |
4803 | } | |
e56263e5 | 4804 | } |
5a857365 | 4805 | if (n > 0) |
e56263e5 | 4806 | { |
5a857365 KS |
4807 | /* Do vscroll if already vscrolled or only display line. */ |
4808 | if (rbot > 0 && (w->vscroll < 0 || vpos == 0)) | |
4809 | { | |
4810 | px = max (0, -w->vscroll + min (rbot, dy)); | |
4811 | Fset_window_vscroll (window, make_number (px), Qt); | |
4812 | return; | |
4813 | } | |
4814 | ||
4815 | /* Maybe modify window start instead of scrolling. */ | |
4816 | if (rbot > 0 || w->vscroll < 0) | |
4817 | { | |
4818 | int spos; | |
4819 | ||
4820 | Fset_window_vscroll (window, make_number (0), Qt); | |
4821 | /* If there are other text lines above the current row, | |
4822 | move window start to current row. Else to next row. */ | |
4823 | if (rbot > 0) | |
4824 | spos = XINT (Fline_beginning_position (Qnil)); | |
4825 | else | |
4826 | spos = min (XINT (Fline_end_position (Qnil)) + 1, ZV); | |
4827 | set_marker_restricted (w->start, make_number (spos), | |
4828 | w->buffer); | |
4829 | w->start_at_line_beg = Qt; | |
4830 | w->update_mode_line = Qt; | |
4831 | XSETFASTINT (w->last_modified, 0); | |
4832 | XSETFASTINT (w->last_overlay_modified, 0); | |
4833 | /* Set force_start so that redisplay_window will run the | |
4834 | window-scroll-functions. */ | |
4835 | w->force_start = Qt; | |
4836 | return; | |
4837 | } | |
e56263e5 KS |
4838 | } |
4839 | } | |
5a857365 | 4840 | /* Cancel previous vscroll. */ |
e56263e5 KS |
4841 | Fset_window_vscroll (window, make_number (0), Qt); |
4842 | } | |
5500c422 | 4843 | |
d0c38d63 | 4844 | /* If scroll_preserve_screen_position is non-nil, we try to set |
5500c422 GM |
4845 | point in the same window line as it is now, so get that line. */ |
4846 | if (!NILP (Vscroll_preserve_screen_position)) | |
4847 | { | |
c525d842 CY |
4848 | /* We preserve the goal pixel coordinate across consecutive |
4849 | calls to scroll-up or scroll-down. This avoids the | |
4850 | possibility of point becoming "stuck" on a tall line when | |
4851 | scrolling by one line. */ | |
66fe93d1 | 4852 | if (window_scroll_pixel_based_preserve_y < 0 |
7d619454 SM |
4853 | || (!EQ (current_kboard->Vlast_command, Qscroll_up) |
4854 | && !EQ (current_kboard->Vlast_command, Qscroll_down))) | |
c525d842 CY |
4855 | { |
4856 | start_display (&it, w, start); | |
4857 | move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS); | |
66fe93d1 | 4858 | window_scroll_pixel_based_preserve_y = it.current_y; |
c876b227 | 4859 | window_scroll_pixel_based_preserve_x = it.current_x; |
c525d842 | 4860 | } |
5500c422 GM |
4861 | } |
4862 | else | |
c876b227 SM |
4863 | window_scroll_pixel_based_preserve_y |
4864 | = window_scroll_pixel_based_preserve_x = -1; | |
5500c422 GM |
4865 | |
4866 | /* Move iterator it from start the specified distance forward or | |
4867 | backward. The result is the new window start. */ | |
4868 | start_display (&it, w, start); | |
4869 | if (whole) | |
4870 | { | |
e856c216 KS |
4871 | int start_pos = IT_CHARPOS (it); |
4872 | int dy = WINDOW_FRAME_LINE_HEIGHT (w); | |
4873 | dy = max ((window_box_height (w) | |
4874 | - next_screen_context_lines * dy), | |
4875 | dy) * n; | |
d72340d4 GM |
4876 | |
4877 | /* Note that move_it_vertically always moves the iterator to the | |
4878 | start of a line. So, if the last line doesn't have a newline, | |
4879 | we would end up at the start of the line ending at ZV. */ | |
4880 | if (dy <= 0) | |
e856c216 KS |
4881 | { |
4882 | move_it_vertically_backward (&it, -dy); | |
5a857365 | 4883 | /* Ensure we actually do move, e.g. in case we are currently |
e856c216 KS |
4884 | looking at an image that is taller that the window height. */ |
4885 | while (start_pos == IT_CHARPOS (it) | |
4886 | && start_pos > BEGV) | |
4887 | move_it_by_lines (&it, -1, 1); | |
4888 | } | |
d72340d4 | 4889 | else if (dy > 0) |
bed83ee4 | 4890 | { |
bed83ee4 KS |
4891 | move_it_to (&it, ZV, -1, it.current_y + dy, -1, |
4892 | MOVE_TO_POS | MOVE_TO_Y); | |
5a857365 | 4893 | /* Ensure we actually do move, e.g. in case we are currently |
bed83ee4 KS |
4894 | looking at an image that is taller that the window height. */ |
4895 | while (start_pos == IT_CHARPOS (it) | |
4896 | && start_pos < ZV) | |
4897 | move_it_by_lines (&it, 1, 1); | |
4898 | } | |
5500c422 GM |
4899 | } |
4900 | else | |
4901 | move_it_by_lines (&it, n, 1); | |
4902 | ||
96ae58c8 RS |
4903 | /* We failed if we find ZV is already on the screen (scrolling up, |
4904 | means there's nothing past the end), or if we can't start any | |
4905 | earlier (scrolling down, means there's nothing past the top). */ | |
5500c422 | 4906 | if ((n > 0 && IT_CHARPOS (it) == ZV) |
96ae58c8 | 4907 | || (n < 0 && IT_CHARPOS (it) == CHARPOS (start))) |
5500c422 | 4908 | { |
5cdb3cf3 MB |
4909 | if (IT_CHARPOS (it) == ZV) |
4910 | { | |
07ce8b53 RS |
4911 | if (it.current_y < it.last_visible_y |
4912 | && (it.current_y + it.max_ascent + it.max_descent | |
3f489dc7 | 4913 | > it.last_visible_y)) |
a74eca50 GM |
4914 | { |
4915 | /* The last line was only partially visible, make it fully | |
4916 | visible. */ | |
4917 | w->vscroll = (it.last_visible_y | |
4918 | - it.current_y + it.max_ascent + it.max_descent); | |
4919 | adjust_glyphs (it.f); | |
4920 | } | |
5cdb3cf3 MB |
4921 | else if (noerror) |
4922 | return; | |
cf402f3f | 4923 | else if (n < 0) /* could happen with empty buffers */ |
ba96a5cf | 4924 | xsignal0 (Qbeginning_of_buffer); |
5cdb3cf3 | 4925 | else |
ba96a5cf | 4926 | xsignal0 (Qend_of_buffer); |
5cdb3cf3 | 4927 | } |
5500c422 | 4928 | else |
5cdb3cf3 MB |
4929 | { |
4930 | if (w->vscroll != 0) | |
4931 | /* The first line was only partially visible, make it fully | |
4932 | visible. */ | |
4933 | w->vscroll = 0; | |
4934 | else if (noerror) | |
4935 | return; | |
4936 | else | |
ba96a5cf | 4937 | xsignal0 (Qbeginning_of_buffer); |
5cdb3cf3 MB |
4938 | } |
4939 | ||
4940 | /* If control gets here, then we vscrolled. */ | |
4941 | ||
4942 | XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1; | |
4943 | ||
4944 | /* Don't try to change the window start below. */ | |
4945 | vscrolled = 1; | |
5500c422 GM |
4946 | } |
4947 | ||
5cdb3cf3 MB |
4948 | if (! vscrolled) |
4949 | { | |
dad67609 RS |
4950 | int pos = IT_CHARPOS (it); |
4951 | int bytepos; | |
e68def1e AS |
4952 | |
4953 | /* If in the middle of a multi-glyph character move forward to | |
4954 | the next character. */ | |
4955 | if (in_display_vector_p (&it)) | |
4956 | { | |
4957 | ++pos; | |
4958 | move_it_to (&it, pos, -1, -1, -1, MOVE_TO_POS); | |
4959 | } | |
4960 | ||
5cdb3cf3 | 4961 | /* Set the window start, and set up the window for redisplay. */ |
dad67609 | 4962 | set_marker_restricted (w->start, make_number (pos), |
5cdb3cf3 | 4963 | w->buffer); |
dad67609 RS |
4964 | bytepos = XMARKER (w->start)->bytepos; |
4965 | w->start_at_line_beg = ((pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n') | |
4966 | ? Qt : Qnil); | |
5cdb3cf3 MB |
4967 | w->update_mode_line = Qt; |
4968 | XSETFASTINT (w->last_modified, 0); | |
4969 | XSETFASTINT (w->last_overlay_modified, 0); | |
4970 | /* Set force_start so that redisplay_window will run the | |
4971 | window-scroll-functions. */ | |
4972 | w->force_start = Qt; | |
4973 | } | |
177c0ea7 | 4974 | |
dc297565 RS |
4975 | /* The rest of this function uses current_y in a nonstandard way, |
4976 | not including the height of the header line if any. */ | |
5500c422 | 4977 | it.current_y = it.vpos = 0; |
177c0ea7 | 4978 | |
940f53e5 RS |
4979 | /* Move PT out of scroll margins. |
4980 | This code wants current_y to be zero at the window start position | |
4981 | even if there is a header line. */ | |
4982 | this_scroll_margin = max (0, scroll_margin); | |
4983 | this_scroll_margin = min (this_scroll_margin, XFASTINT (w->total_lines) / 4); | |
4984 | this_scroll_margin *= FRAME_LINE_HEIGHT (it.f); | |
4985 | ||
4986 | if (n > 0) | |
5500c422 | 4987 | { |
940f53e5 RS |
4988 | /* We moved the window start towards ZV, so PT may be now |
4989 | in the scroll margin at the top. */ | |
4990 | move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS); | |
bdf4ec93 RS |
4991 | if (IT_CHARPOS (it) == PT && it.current_y >= this_scroll_margin |
4992 | && (NILP (Vscroll_preserve_screen_position) | |
4993 | || EQ (Vscroll_preserve_screen_position, Qt))) | |
940f53e5 RS |
4994 | /* We found PT at a legitimate height. Leave it alone. */ |
4995 | ; | |
66fe93d1 | 4996 | else if (window_scroll_pixel_based_preserve_y >= 0) |
940f53e5 | 4997 | { |
fa3c3426 RS |
4998 | /* If we have a header line, take account of it. |
4999 | This is necessary because we set it.current_y to 0, above. */ | |
c876b227 SM |
5000 | move_it_to (&it, -1, |
5001 | window_scroll_pixel_based_preserve_x, | |
66fe93d1 LT |
5002 | window_scroll_pixel_based_preserve_y |
5003 | - (WINDOW_WANTS_HEADER_LINE_P (w) ? 1 : 0 ), | |
c876b227 | 5004 | -1, MOVE_TO_Y | MOVE_TO_X); |
940f53e5 RS |
5005 | SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it)); |
5006 | } | |
5007 | else | |
5500c422 | 5008 | { |
5500c422 | 5009 | while (it.current_y < this_scroll_margin) |
e9b2c961 RS |
5010 | { |
5011 | int prev = it.current_y; | |
5012 | move_it_by_lines (&it, 1, 1); | |
5013 | if (prev == it.current_y) | |
5014 | break; | |
5015 | } | |
5500c422 GM |
5016 | SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it)); |
5017 | } | |
940f53e5 RS |
5018 | } |
5019 | else if (n < 0) | |
5020 | { | |
5021 | int charpos, bytepos; | |
aed328bf | 5022 | int partial_p; |
940f53e5 | 5023 | |
66fe93d1 LT |
5024 | /* Save our position, for the |
5025 | window_scroll_pixel_based_preserve_y case. */ | |
940f53e5 RS |
5026 | charpos = IT_CHARPOS (it); |
5027 | bytepos = IT_BYTEPOS (it); | |
5cdb3cf3 | 5028 | |
940f53e5 RS |
5029 | /* We moved the window start towards BEGV, so PT may be now |
5030 | in the scroll margin at the bottom. */ | |
5031 | move_it_to (&it, PT, -1, | |
7ad53239 RS |
5032 | (it.last_visible_y - CURRENT_HEADER_LINE_HEIGHT (w) |
5033 | - this_scroll_margin - 1), | |
5034 | -1, | |
940f53e5 RS |
5035 | MOVE_TO_POS | MOVE_TO_Y); |
5036 | ||
aed328bf KS |
5037 | /* Save our position, in case it's correct. */ |
5038 | charpos = IT_CHARPOS (it); | |
5039 | bytepos = IT_BYTEPOS (it); | |
5040 | ||
5041 | /* See if point is on a partially visible line at the end. */ | |
5042 | if (it.what == IT_EOB) | |
5043 | partial_p = it.current_y + it.ascent + it.descent > it.last_visible_y; | |
5044 | else | |
5045 | { | |
5046 | move_it_by_lines (&it, 1, 1); | |
5047 | partial_p = it.current_y > it.last_visible_y; | |
5048 | } | |
5049 | ||
bdf4ec93 RS |
5050 | if (charpos == PT && !partial_p |
5051 | && (NILP (Vscroll_preserve_screen_position) | |
5052 | || EQ (Vscroll_preserve_screen_position, Qt))) | |
940f53e5 RS |
5053 | /* We found PT before we found the display margin, so PT is ok. */ |
5054 | ; | |
66fe93d1 | 5055 | else if (window_scroll_pixel_based_preserve_y >= 0) |
940f53e5 RS |
5056 | { |
5057 | SET_TEXT_POS_FROM_MARKER (start, w->start); | |
5058 | start_display (&it, w, start); | |
c525d842 CY |
5059 | /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT |
5060 | here because we called start_display again and did not | |
5061 | alter it.current_y this time. */ | |
c876b227 SM |
5062 | move_it_to (&it, -1, window_scroll_pixel_based_preserve_x, |
5063 | window_scroll_pixel_based_preserve_y, -1, | |
5064 | MOVE_TO_Y | MOVE_TO_X); | |
940f53e5 RS |
5065 | SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it)); |
5066 | } | |
5067 | else | |
5068 | { | |
aed328bf | 5069 | if (partial_p) |
5cdb3cf3 MB |
5070 | /* The last line was only partially visible, so back up two |
5071 | lines to make sure we're on a fully visible line. */ | |
5072 | { | |
5073 | move_it_by_lines (&it, -2, 0); | |
5074 | SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it)); | |
5075 | } | |
5076 | else | |
5077 | /* No, the position we saved is OK, so use it. */ | |
5078 | SET_PT_BOTH (charpos, bytepos); | |
5500c422 GM |
5079 | } |
5080 | } | |
5081 | } | |
5082 | ||
5083 | ||
5084 | /* Implementation of window_scroll that works based on screen lines. | |
5085 | See the comment of window_scroll for parameter descriptions. */ | |
5086 | ||
5087 | static void | |
5088 | window_scroll_line_based (window, n, whole, noerror) | |
5089 | Lisp_Object window; | |
5090 | int n; | |
5091 | int whole; | |
5092 | int noerror; | |
7ab12479 JB |
5093 | { |
5094 | register struct window *w = XWINDOW (window); | |
5500c422 | 5095 | register int opoint = PT, opoint_byte = PT_BYTE; |
b73ea88e | 5096 | register int pos, pos_byte; |
7ab12479 JB |
5097 | register int ht = window_internal_height (w); |
5098 | register Lisp_Object tem; | |
5099 | int lose; | |
5500c422 | 5100 | Lisp_Object bolp; |
345d45b2 | 5101 | int startpos; |
c876b227 | 5102 | Lisp_Object original_pos = Qnil; |
101d1605 | 5103 | |
d4e7cf01 GM |
5104 | /* If scrolling screen-fulls, compute the number of lines to |
5105 | scroll from the window's height. */ | |
5106 | if (whole) | |
5107 | n *= max (1, ht - next_screen_context_lines); | |
5108 | ||
101d1605 RS |
5109 | startpos = marker_position (w->start); |
5110 | ||
c876b227 SM |
5111 | if (!NILP (Vscroll_preserve_screen_position)) |
5112 | { | |
5113 | if (window_scroll_preserve_vpos <= 0 | |
5114 | || (!EQ (current_kboard->Vlast_command, Qscroll_up) | |
5115 | && !EQ (current_kboard->Vlast_command, Qscroll_down))) | |
5116 | { | |
5117 | struct position posit | |
5118 | = *compute_motion (startpos, 0, 0, 0, | |
5119 | PT, ht, 0, | |
5120 | -1, XINT (w->hscroll), | |
5121 | 0, w); | |
5122 | window_scroll_preserve_vpos = posit.vpos; | |
5123 | window_scroll_preserve_hpos = posit.hpos + XINT (w->hscroll); | |
5124 | } | |
5125 | ||
5126 | original_pos = Fcons (make_number (window_scroll_preserve_hpos), | |
5127 | make_number (window_scroll_preserve_vpos)); | |
5128 | } | |
0a1f771a | 5129 | |
d834a2e9 | 5130 | XSETFASTINT (tem, PT); |
6ffdb539 | 5131 | tem = Fpos_visible_in_window_p (tem, window, Qnil); |
7ab12479 | 5132 | |
265a9e55 | 5133 | if (NILP (tem)) |
7ab12479 | 5134 | { |
cd2be1dd | 5135 | Fvertical_motion (make_number (- (ht / 2)), window); |
345d45b2 | 5136 | startpos = PT; |
7ab12479 JB |
5137 | } |
5138 | ||
345d45b2 | 5139 | SET_PT (startpos); |
5ce7b543 | 5140 | lose = n < 0 && PT == BEGV; |
540b6aa0 | 5141 | Fvertical_motion (make_number (n), window); |
5ce7b543 | 5142 | pos = PT; |
b73ea88e | 5143 | pos_byte = PT_BYTE; |
7ab12479 | 5144 | bolp = Fbolp (); |
b73ea88e | 5145 | SET_PT_BOTH (opoint, opoint_byte); |
7ab12479 JB |
5146 | |
5147 | if (lose) | |
f8026fd8 JB |
5148 | { |
5149 | if (noerror) | |
5150 | return; | |
5151 | else | |
ba96a5cf | 5152 | xsignal0 (Qbeginning_of_buffer); |
f8026fd8 | 5153 | } |
7ab12479 JB |
5154 | |
5155 | if (pos < ZV) | |
7ab12479 | 5156 | { |
0c7da84e RS |
5157 | int this_scroll_margin = scroll_margin; |
5158 | ||
5159 | /* Don't use a scroll margin that is negative or too large. */ | |
5160 | if (this_scroll_margin < 0) | |
5161 | this_scroll_margin = 0; | |
5162 | ||
949cf20f KS |
5163 | if (XINT (w->total_lines) < 4 * scroll_margin) |
5164 | this_scroll_margin = XINT (w->total_lines) / 4; | |
0c7da84e | 5165 | |
b73ea88e | 5166 | set_marker_restricted_both (w->start, w->buffer, pos, pos_byte); |
7ab12479 JB |
5167 | w->start_at_line_beg = bolp; |
5168 | w->update_mode_line = Qt; | |
d834a2e9 | 5169 | XSETFASTINT (w->last_modified, 0); |
3cd21523 | 5170 | XSETFASTINT (w->last_overlay_modified, 0); |
345d45b2 RS |
5171 | /* Set force_start so that redisplay_window will run |
5172 | the window-scroll-functions. */ | |
5173 | w->force_start = Qt; | |
0c7da84e | 5174 | |
bdf4ec93 RS |
5175 | if (!NILP (Vscroll_preserve_screen_position) |
5176 | && (whole || !EQ (Vscroll_preserve_screen_position, Qt))) | |
0c7da84e | 5177 | { |
b73ea88e | 5178 | SET_PT_BOTH (pos, pos_byte); |
c876b227 | 5179 | Fvertical_motion (original_pos, window); |
0c7da84e | 5180 | } |
101d1605 RS |
5181 | /* If we scrolled forward, put point enough lines down |
5182 | that it is outside the scroll margin. */ | |
5183 | else if (n > 0) | |
0c7da84e | 5184 | { |
101d1605 RS |
5185 | int top_margin; |
5186 | ||
5187 | if (this_scroll_margin > 0) | |
5188 | { | |
b73ea88e | 5189 | SET_PT_BOTH (pos, pos_byte); |
101d1605 RS |
5190 | Fvertical_motion (make_number (this_scroll_margin), window); |
5191 | top_margin = PT; | |
5192 | } | |
5193 | else | |
5194 | top_margin = pos; | |
5195 | ||
5196 | if (top_margin <= opoint) | |
b73ea88e | 5197 | SET_PT_BOTH (opoint, opoint_byte); |
5500c422 | 5198 | else if (!NILP (Vscroll_preserve_screen_position)) |
101d1605 | 5199 | { |
b73ea88e | 5200 | SET_PT_BOTH (pos, pos_byte); |
c876b227 | 5201 | Fvertical_motion (original_pos, window); |
101d1605 | 5202 | } |
9317a85d | 5203 | else |
335406fc | 5204 | SET_PT (top_margin); |
0c7da84e | 5205 | } |
101d1605 | 5206 | else if (n < 0) |
7ab12479 | 5207 | { |
101d1605 RS |
5208 | int bottom_margin; |
5209 | ||
0c7da84e RS |
5210 | /* If we scrolled backward, put point near the end of the window |
5211 | but not within the scroll margin. */ | |
b73ea88e | 5212 | SET_PT_BOTH (pos, pos_byte); |
0c7da84e | 5213 | tem = Fvertical_motion (make_number (ht - this_scroll_margin), window); |
101d1605 RS |
5214 | if (XFASTINT (tem) == ht - this_scroll_margin) |
5215 | bottom_margin = PT; | |
5216 | else | |
5217 | bottom_margin = PT + 1; | |
5218 | ||
5219 | if (bottom_margin > opoint) | |
b73ea88e | 5220 | SET_PT_BOTH (opoint, opoint_byte); |
7ab12479 | 5221 | else |
101d1605 | 5222 | { |
5500c422 | 5223 | if (!NILP (Vscroll_preserve_screen_position)) |
9317a85d | 5224 | { |
b73ea88e | 5225 | SET_PT_BOTH (pos, pos_byte); |
c876b227 | 5226 | Fvertical_motion (original_pos, window); |
9317a85d RS |
5227 | } |
5228 | else | |
5229 | Fvertical_motion (make_number (-1), window); | |
101d1605 | 5230 | } |
7ab12479 JB |
5231 | } |
5232 | } | |
5233 | else | |
f8026fd8 JB |
5234 | { |
5235 | if (noerror) | |
5236 | return; | |
5237 | else | |
ba96a5cf | 5238 | xsignal0 (Qend_of_buffer); |
f8026fd8 | 5239 | } |
7ab12479 | 5240 | } |
5500c422 GM |
5241 | |
5242 | ||
5243 | /* Scroll selected_window up or down. If N is nil, scroll a | |
5244 | screen-full which is defined as the height of the window minus | |
5245 | next_screen_context_lines. If N is the symbol `-', scroll. | |
5246 | DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll | |
5247 | up. This is the guts of Fscroll_up and Fscroll_down. */ | |
7ab12479 JB |
5248 | |
5249 | static void | |
5250 | scroll_command (n, direction) | |
5500c422 | 5251 | Lisp_Object n; |
7ab12479 JB |
5252 | int direction; |
5253 | { | |
331379bf | 5254 | int count = SPECPDL_INDEX (); |
7ab12479 | 5255 | |
1ea40aa2 | 5256 | xassert (eabs (direction) == 1); |
5500c422 GM |
5257 | |
5258 | /* If selected window's buffer isn't current, make it current for | |
5259 | the moment. But don't screw up if window_scroll gets an error. */ | |
7ab12479 | 5260 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) |
95605e15 JB |
5261 | { |
5262 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
5263 | Fset_buffer (XWINDOW (selected_window)->buffer); | |
5500c422 GM |
5264 | |
5265 | /* Make redisplay consider other windows than just selected_window. */ | |
5266 | ++windows_or_buffers_changed; | |
95605e15 | 5267 | } |
7ab12479 | 5268 | |
265a9e55 | 5269 | if (NILP (n)) |
d4e7cf01 | 5270 | window_scroll (selected_window, direction, 1, 0); |
7ab12479 | 5271 | else if (EQ (n, Qminus)) |
d4e7cf01 | 5272 | window_scroll (selected_window, -direction, 1, 0); |
7ab12479 JB |
5273 | else |
5274 | { | |
5275 | n = Fprefix_numeric_value (n); | |
101d1605 | 5276 | window_scroll (selected_window, XINT (n) * direction, 0, 0); |
7ab12479 | 5277 | } |
95605e15 JB |
5278 | |
5279 | unbind_to (count, Qnil); | |
7ab12479 JB |
5280 | } |
5281 | ||
e0965597 | 5282 | DEFUN ("scroll-up", Fscroll_up, Sscroll_up, 0, 1, "^P", |
a0a37a6f LT |
5283 | doc: /* Scroll text of current window upward ARG lines. |
5284 | If ARG is omitted or nil, scroll upward by a near full screen. | |
fdb82f93 PJ |
5285 | A near full screen is `next-screen-context-lines' less than a full screen. |
5286 | Negative ARG means scroll downward. | |
5287 | If ARG is the atom `-', scroll downward by nearly full screen. | |
5288 | When calling from a program, supply as argument a number, nil, or `-'. */) | |
5289 | (arg) | |
413430c5 | 5290 | Lisp_Object arg; |
7ab12479 | 5291 | { |
413430c5 | 5292 | scroll_command (arg, 1); |
7ab12479 JB |
5293 | return Qnil; |
5294 | } | |
5295 | ||
e0965597 | 5296 | DEFUN ("scroll-down", Fscroll_down, Sscroll_down, 0, 1, "^P", |
a0a37a6f LT |
5297 | doc: /* Scroll text of current window down ARG lines. |
5298 | If ARG is omitted or nil, scroll down by a near full screen. | |
fdb82f93 PJ |
5299 | A near full screen is `next-screen-context-lines' less than a full screen. |
5300 | Negative ARG means scroll upward. | |
5301 | If ARG is the atom `-', scroll upward by nearly full screen. | |
5302 | When calling from a program, supply as argument a number, nil, or `-'. */) | |
5303 | (arg) | |
413430c5 | 5304 | Lisp_Object arg; |
7ab12479 | 5305 | { |
413430c5 | 5306 | scroll_command (arg, -1); |
7ab12479 JB |
5307 | return Qnil; |
5308 | } | |
ccd0664b RS |
5309 | \f |
5310 | DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling, Sother_window_for_scrolling, 0, 0, 0, | |
fdb82f93 | 5311 | doc: /* Return the other window for \"other window scroll\" commands. |
fdb82f93 | 5312 | If `other-window-scroll-buffer' is non-nil, a window |
a0a37a6f LT |
5313 | showing that buffer is used. |
5314 | If in the minibuffer, `minibuffer-scroll-window' if non-nil | |
5315 | specifies the window. This takes precedence over | |
5316 | `other-window-scroll-buffer'. */) | |
fdb82f93 | 5317 | () |
7ab12479 | 5318 | { |
ccd0664b | 5319 | Lisp_Object window; |
7ab12479 JB |
5320 | |
5321 | if (MINI_WINDOW_P (XWINDOW (selected_window)) | |
265a9e55 | 5322 | && !NILP (Vminibuf_scroll_window)) |
7ab12479 JB |
5323 | window = Vminibuf_scroll_window; |
5324 | /* If buffer is specified, scroll that buffer. */ | |
265a9e55 | 5325 | else if (!NILP (Vother_window_scroll_buffer)) |
7ab12479 JB |
5326 | { |
5327 | window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil); | |
265a9e55 | 5328 | if (NILP (window)) |
87478b52 | 5329 | window = display_buffer (Vother_window_scroll_buffer, Qt, Qnil); |
7ab12479 JB |
5330 | } |
5331 | else | |
dbc4e1c1 JB |
5332 | { |
5333 | /* Nothing specified; look for a neighboring window on the same | |
5334 | frame. */ | |
5335 | window = Fnext_window (selected_window, Qnil, Qnil); | |
5336 | ||
5337 | if (EQ (window, selected_window)) | |
5338 | /* That didn't get us anywhere; look for a window on another | |
5339 | visible frame. */ | |
5340 | do | |
5341 | window = Fnext_window (window, Qnil, Qt); | |
5342 | while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window)))) | |
5343 | && ! EQ (window, selected_window)); | |
5344 | } | |
5345 | ||
b7826503 | 5346 | CHECK_LIVE_WINDOW (window); |
7ab12479 JB |
5347 | |
5348 | if (EQ (window, selected_window)) | |
5349 | error ("There is no other window"); | |
5350 | ||
ccd0664b RS |
5351 | return window; |
5352 | } | |
5353 | ||
5354 | DEFUN ("scroll-other-window", Fscroll_other_window, Sscroll_other_window, 0, 1, "P", | |
fdb82f93 PJ |
5355 | doc: /* Scroll next window upward ARG lines; or near full screen if no ARG. |
5356 | A near full screen is `next-screen-context-lines' less than a full screen. | |
5357 | The next window is the one below the current one; or the one at the top | |
5358 | if the current one is at the bottom. Negative ARG means scroll downward. | |
5359 | If ARG is the atom `-', scroll downward by nearly full screen. | |
5360 | When calling from a program, supply as argument a number, nil, or `-'. | |
5361 | ||
fdb82f93 | 5362 | If `other-window-scroll-buffer' is non-nil, scroll the window |
a0a37a6f LT |
5363 | showing that buffer, popping the buffer up if necessary. |
5364 | If in the minibuffer, `minibuffer-scroll-window' if non-nil | |
5365 | specifies the window to scroll. This takes precedence over | |
5366 | `other-window-scroll-buffer'. */) | |
fdb82f93 | 5367 | (arg) |
d4e7cf01 | 5368 | Lisp_Object arg; |
ccd0664b | 5369 | { |
d4e7cf01 GM |
5370 | Lisp_Object window; |
5371 | struct window *w; | |
331379bf | 5372 | int count = SPECPDL_INDEX (); |
ccd0664b RS |
5373 | |
5374 | window = Fother_window_for_scrolling (); | |
7ab12479 | 5375 | w = XWINDOW (window); |
7ab12479 JB |
5376 | |
5377 | /* Don't screw up if window_scroll gets an error. */ | |
5378 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
5500c422 | 5379 | ++windows_or_buffers_changed; |
7ab12479 JB |
5380 | |
5381 | Fset_buffer (w->buffer); | |
5382 | SET_PT (marker_position (w->pointm)); | |
5383 | ||
413430c5 | 5384 | if (NILP (arg)) |
d4e7cf01 | 5385 | window_scroll (window, 1, 1, 1); |
413430c5 | 5386 | else if (EQ (arg, Qminus)) |
d4e7cf01 | 5387 | window_scroll (window, -1, 1, 1); |
7ab12479 JB |
5388 | else |
5389 | { | |
413430c5 EN |
5390 | if (CONSP (arg)) |
5391 | arg = Fcar (arg); | |
b7826503 | 5392 | CHECK_NUMBER (arg); |
101d1605 | 5393 | window_scroll (window, XINT (arg), 0, 1); |
7ab12479 JB |
5394 | } |
5395 | ||
b73ea88e | 5396 | set_marker_both (w->pointm, Qnil, PT, PT_BYTE); |
f4e7b2c2 | 5397 | unbind_to (count, Qnil); |
7ab12479 JB |
5398 | |
5399 | return Qnil; | |
5400 | } | |
5401 | \f | |
e0965597 | 5402 | DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 2, "^P\np", |
fdb82f93 | 5403 | doc: /* Scroll selected window display ARG columns left. |
2fe41216 EZ |
5404 | Default for ARG is window width minus 2. |
5405 | Value is the total amount of leftward horizontal scrolling in | |
5406 | effect after the change. | |
dc297565 RS |
5407 | If SET_MINIMUM is non-nil, the new scroll amount becomes the |
5408 | lower bound for automatic scrolling, i.e. automatic scrolling | |
2fe41216 | 5409 | will not scroll a window to a column less than the value returned |
dc297565 RS |
5410 | by this function. This happens in an interactive call. */) |
5411 | (arg, set_minimum) | |
5412 | register Lisp_Object arg, set_minimum; | |
7ab12479 | 5413 | { |
c67fa410 GM |
5414 | Lisp_Object result; |
5415 | int hscroll; | |
5416 | struct window *w = XWINDOW (selected_window); | |
177c0ea7 | 5417 | |
265a9e55 | 5418 | if (NILP (arg)) |
949cf20f | 5419 | XSETFASTINT (arg, window_box_text_cols (w) - 2); |
7ab12479 JB |
5420 | else |
5421 | arg = Fprefix_numeric_value (arg); | |
5422 | ||
c67fa410 GM |
5423 | hscroll = XINT (w->hscroll) + XINT (arg); |
5424 | result = Fset_window_hscroll (selected_window, make_number (hscroll)); | |
5425 | ||
dc297565 | 5426 | if (!NILP (set_minimum)) |
c67fa410 GM |
5427 | w->min_hscroll = w->hscroll; |
5428 | ||
5429 | return result; | |
7ab12479 JB |
5430 | } |
5431 | ||
e0965597 | 5432 | DEFUN ("scroll-right", Fscroll_right, Sscroll_right, 0, 2, "^P\np", |
fdb82f93 | 5433 | doc: /* Scroll selected window display ARG columns right. |
2fe41216 EZ |
5434 | Default for ARG is window width minus 2. |
5435 | Value is the total amount of leftward horizontal scrolling in | |
5436 | effect after the change. | |
dc297565 RS |
5437 | If SET_MINIMUM is non-nil, the new scroll amount becomes the |
5438 | lower bound for automatic scrolling, i.e. automatic scrolling | |
2fe41216 | 5439 | will not scroll a window to a column less than the value returned |
dc297565 RS |
5440 | by this function. This happens in an interactive call. */) |
5441 | (arg, set_minimum) | |
a93563fd | 5442 | register Lisp_Object arg, set_minimum; |
7ab12479 | 5443 | { |
c67fa410 GM |
5444 | Lisp_Object result; |
5445 | int hscroll; | |
5446 | struct window *w = XWINDOW (selected_window); | |
177c0ea7 | 5447 | |
265a9e55 | 5448 | if (NILP (arg)) |
949cf20f | 5449 | XSETFASTINT (arg, window_box_text_cols (w) - 2); |
7ab12479 JB |
5450 | else |
5451 | arg = Fprefix_numeric_value (arg); | |
5452 | ||
c67fa410 GM |
5453 | hscroll = XINT (w->hscroll) - XINT (arg); |
5454 | result = Fset_window_hscroll (selected_window, make_number (hscroll)); | |
177c0ea7 | 5455 | |
dc297565 | 5456 | if (!NILP (set_minimum)) |
c67fa410 GM |
5457 | w->min_hscroll = w->hscroll; |
5458 | ||
5459 | return result; | |
7ab12479 JB |
5460 | } |
5461 | ||
fa832261 KS |
5462 | DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window, Sminibuffer_selected_window, 0, 0, 0, |
5463 | doc: /* Return the window which was selected when entering the minibuffer. | |
5464 | Returns nil, if current window is not a minibuffer window. */) | |
5465 | () | |
5466 | { | |
5467 | if (minibuf_level > 0 | |
5468 | && MINI_WINDOW_P (XWINDOW (selected_window)) | |
fa832261 KS |
5469 | && WINDOW_LIVE_P (minibuf_selected_window)) |
5470 | return minibuf_selected_window; | |
5471 | ||
5472 | return Qnil; | |
5473 | } | |
5474 | ||
12c8b416 GM |
5475 | /* Value is the number of lines actually displayed in window W, |
5476 | as opposed to its height. */ | |
5477 | ||
5478 | static int | |
5479 | displayed_window_lines (w) | |
5480 | struct window *w; | |
5481 | { | |
5482 | struct it it; | |
5483 | struct text_pos start; | |
5484 | int height = window_box_height (w); | |
5485 | struct buffer *old_buffer; | |
5486 | int bottom_y; | |
5487 | ||
5488 | if (XBUFFER (w->buffer) != current_buffer) | |
5489 | { | |
5490 | old_buffer = current_buffer; | |
5491 | set_buffer_internal (XBUFFER (w->buffer)); | |
5492 | } | |
5493 | else | |
5494 | old_buffer = NULL; | |
5495 | ||
521b203e GM |
5496 | /* In case W->start is out of the accessible range, do something |
5497 | reasonable. This happens in Info mode when Info-scroll-down | |
5498 | calls (recenter -1) while W->start is 1. */ | |
5499 | if (XMARKER (w->start)->charpos < BEGV) | |
5500 | SET_TEXT_POS (start, BEGV, BEGV_BYTE); | |
5501 | else if (XMARKER (w->start)->charpos > ZV) | |
5502 | SET_TEXT_POS (start, ZV, ZV_BYTE); | |
5503 | else | |
5504 | SET_TEXT_POS_FROM_MARKER (start, w->start); | |
5505 | ||
12c8b416 GM |
5506 | start_display (&it, w, start); |
5507 | move_it_vertically (&it, height); | |
c8bc6f65 | 5508 | bottom_y = line_bottom_y (&it); |
12c8b416 | 5509 | |
1de65f51 RS |
5510 | /* rms: On a non-window display, |
5511 | the value of it.vpos at the bottom of the screen | |
5512 | seems to be 1 larger than window_box_height (w). | |
5513 | This kludge fixes a bug whereby (move-to-window-line -1) | |
5514 | when ZV is on the last screen line | |
5515 | moves to the previous screen line instead of the last one. */ | |
5516 | if (! FRAME_WINDOW_P (XFRAME (w->frame))) | |
5517 | height++; | |
5518 | ||
12c8b416 GM |
5519 | /* Add in empty lines at the bottom of the window. */ |
5520 | if (bottom_y < height) | |
5521 | { | |
949cf20f | 5522 | int uy = FRAME_LINE_HEIGHT (it.f); |
c8bc6f65 | 5523 | it.vpos += (height - bottom_y + uy - 1) / uy; |
12c8b416 GM |
5524 | } |
5525 | ||
c8bc6f65 GM |
5526 | if (old_buffer) |
5527 | set_buffer_internal (old_buffer); | |
5528 | ||
12c8b416 GM |
5529 | return it.vpos; |
5530 | } | |
5531 | ||
5532 | ||
7ab12479 | 5533 | DEFUN ("recenter", Frecenter, Srecenter, 0, 1, "P", |
fdb82f93 PJ |
5534 | doc: /* Center point in window and redisplay frame. |
5535 | With prefix argument ARG, recenter putting point on screen line ARG | |
5536 | relative to the current window. If ARG is negative, it counts up from the | |
5537 | bottom of the window. (ARG should be less than the height of the window.) | |
5538 | ||
7d1d98ee KS |
5539 | If ARG is omitted or nil, erase the entire frame and then redraw with point |
5540 | in the center of the current window. If `auto-resize-tool-bars' is set to | |
5541 | `grow-only', this resets the tool-bar's height to the minimum height needed. | |
5542 | ||
fdb82f93 PJ |
5543 | Just C-u as prefix means put point in the center of the window |
5544 | and redisplay normally--don't erase and redraw the frame. */) | |
5545 | (arg) | |
413430c5 | 5546 | register Lisp_Object arg; |
7ab12479 | 5547 | { |
6df47b59 | 5548 | struct window *w = XWINDOW (selected_window); |
478292ed RS |
5549 | struct buffer *buf = XBUFFER (w->buffer); |
5550 | struct buffer *obuf = current_buffer; | |
6df47b59 GM |
5551 | int center_p = 0; |
5552 | int charpos, bytepos; | |
f6b43440 RS |
5553 | int iarg; |
5554 | int this_scroll_margin; | |
7ab12479 | 5555 | |
0fa5d25b RS |
5556 | /* If redisplay is suppressed due to an error, try again. */ |
5557 | obuf->display_error_modiff = 0; | |
5558 | ||
413430c5 | 5559 | if (NILP (arg)) |
7ab12479 | 5560 | { |
f02d6d5c KH |
5561 | int i; |
5562 | ||
5563 | /* Invalidate pixel data calculated for all compositions. */ | |
5564 | for (i = 0; i < n_compositions; i++) | |
5565 | composition_table[i]->font = NULL; | |
7ab12479 | 5566 | |
7d1d98ee KS |
5567 | WINDOW_XFRAME (w)->minimize_tool_bar_window_p = 1; |
5568 | ||
5569 | Fredraw_frame (WINDOW_FRAME (w)); | |
5570 | SET_FRAME_GARBAGED (WINDOW_XFRAME (w)); | |
6df47b59 | 5571 | center_p = 1; |
7ab12479 | 5572 | } |
413430c5 | 5573 | else if (CONSP (arg)) /* Just C-u. */ |
6df47b59 | 5574 | center_p = 1; |
7ab12479 JB |
5575 | else |
5576 | { | |
413430c5 | 5577 | arg = Fprefix_numeric_value (arg); |
b7826503 | 5578 | CHECK_NUMBER (arg); |
ae12ecd7 | 5579 | iarg = XINT (arg); |
7ab12479 JB |
5580 | } |
5581 | ||
478292ed | 5582 | set_buffer_internal (buf); |
7ab12479 | 5583 | |
f6b43440 RS |
5584 | /* Do this after making BUF current |
5585 | in case scroll_margin is buffer-local. */ | |
5586 | this_scroll_margin = max (0, scroll_margin); | |
5587 | this_scroll_margin = min (this_scroll_margin, | |
5588 | XFASTINT (w->total_lines) / 4); | |
5589 | ||
521b203e | 5590 | /* Handle centering on a graphical frame specially. Such frames can |
6df47b59 GM |
5591 | have variable-height lines and centering point on the basis of |
5592 | line counts would lead to strange effects. */ | |
521b203e | 5593 | if (FRAME_WINDOW_P (XFRAME (w->frame))) |
6df47b59 | 5594 | { |
6df47b59 GM |
5595 | if (center_p) |
5596 | { | |
521b203e GM |
5597 | struct it it; |
5598 | struct text_pos pt; | |
177c0ea7 | 5599 | |
521b203e GM |
5600 | SET_TEXT_POS (pt, PT, PT_BYTE); |
5601 | start_display (&it, w, pt); | |
f204989e | 5602 | move_it_vertically_backward (&it, window_box_height (w) / 2); |
521b203e GM |
5603 | charpos = IT_CHARPOS (it); |
5604 | bytepos = IT_BYTEPOS (it); | |
6df47b59 | 5605 | } |
f6b43440 | 5606 | else if (iarg < 0) |
6df47b59 | 5607 | { |
521b203e GM |
5608 | struct it it; |
5609 | struct text_pos pt; | |
f6b43440 | 5610 | int nlines = -iarg; |
f204989e KS |
5611 | int extra_line_spacing; |
5612 | int h = window_box_height (w); | |
177c0ea7 | 5613 | |
f6b43440 RS |
5614 | iarg = - max (-iarg, this_scroll_margin); |
5615 | ||
521b203e GM |
5616 | SET_TEXT_POS (pt, PT, PT_BYTE); |
5617 | start_display (&it, w, pt); | |
f204989e KS |
5618 | |
5619 | /* Be sure we have the exact height of the full line containing PT. */ | |
5620 | move_it_by_lines (&it, 0, 1); | |
521b203e | 5621 | |
d466fa4d | 5622 | /* The amount of pixels we have to move back is the window |
521b203e GM |
5623 | height minus what's displayed in the line containing PT, |
5624 | and the lines below. */ | |
f204989e KS |
5625 | it.current_y = 0; |
5626 | it.vpos = 0; | |
d466fa4d GM |
5627 | move_it_by_lines (&it, nlines, 1); |
5628 | ||
f204989e KS |
5629 | if (it.vpos == nlines) |
5630 | h -= it.current_y; | |
5631 | else | |
5632 | { | |
5633 | /* Last line has no newline */ | |
5634 | h -= line_bottom_y (&it); | |
5635 | it.vpos++; | |
5636 | } | |
5637 | ||
5638 | /* Don't reserve space for extra line spacing of last line. */ | |
5639 | extra_line_spacing = it.max_extra_line_spacing; | |
d466fa4d GM |
5640 | |
5641 | /* If we can't move down NLINES lines because we hit | |
5642 | the end of the buffer, count in some empty lines. */ | |
5643 | if (it.vpos < nlines) | |
f204989e KS |
5644 | { |
5645 | nlines -= it.vpos; | |
5646 | extra_line_spacing = it.extra_line_spacing; | |
5647 | h -= nlines * (FRAME_LINE_HEIGHT (it.f) + extra_line_spacing); | |
5648 | } | |
5649 | if (h <= 0) | |
5650 | return Qnil; | |
201c831a | 5651 | |
f204989e | 5652 | /* Now find the new top line (starting position) of the window. */ |
521b203e | 5653 | start_display (&it, w, pt); |
f204989e KS |
5654 | it.current_y = 0; |
5655 | move_it_vertically_backward (&it, h); | |
5656 | ||
5657 | /* If extra line spacing is present, we may move too far | |
5658 | back. This causes the last line to be only partially | |
5659 | visible (which triggers redisplay to recenter that line | |
5660 | in the middle), so move forward. | |
5661 | But ignore extra line spacing on last line, as it is not | |
5662 | considered to be part of the visible height of the line. | |
5663 | */ | |
5664 | h += extra_line_spacing; | |
5665 | while (-it.current_y > h) | |
5666 | move_it_by_lines (&it, 1, 1); | |
5667 | ||
521b203e GM |
5668 | charpos = IT_CHARPOS (it); |
5669 | bytepos = IT_BYTEPOS (it); | |
6df47b59 | 5670 | } |
521b203e GM |
5671 | else |
5672 | { | |
5673 | struct position pos; | |
f6b43440 | 5674 | |
f6b43440 RS |
5675 | iarg = max (iarg, this_scroll_margin); |
5676 | ||
5677 | pos = *vmotion (PT, -iarg, w); | |
521b203e GM |
5678 | charpos = pos.bufpos; |
5679 | bytepos = pos.bytepos; | |
5680 | } | |
5681 | } | |
5682 | else | |
5683 | { | |
5684 | struct position pos; | |
5685 | int ht = window_internal_height (w); | |
5686 | ||
5687 | if (center_p) | |
a4429c5b | 5688 | iarg = ht / 2; |
f567c488 KS |
5689 | else if (iarg < 0) |
5690 | iarg += ht; | |
f6b43440 RS |
5691 | |
5692 | /* Don't let it get into the margin at either top or bottom. */ | |
5693 | iarg = max (iarg, this_scroll_margin); | |
5694 | iarg = min (iarg, ht - this_scroll_margin - 1); | |
177c0ea7 | 5695 | |
f6b43440 | 5696 | pos = *vmotion (PT, - iarg, w); |
6df47b59 GM |
5697 | charpos = pos.bufpos; |
5698 | bytepos = pos.bytepos; | |
5699 | } | |
5700 | ||
5701 | /* Set the new window start. */ | |
5702 | set_marker_both (w->start, w->buffer, charpos, bytepos); | |
2f3cad6c | 5703 | w->window_end_valid = Qnil; |
177c0ea7 | 5704 | |
95605b1b RS |
5705 | w->optional_new_start = Qt; |
5706 | ||
6df47b59 GM |
5707 | if (bytepos == BEGV_BYTE || FETCH_BYTE (bytepos - 1) == '\n') |
5708 | w->start_at_line_beg = Qt; | |
5709 | else | |
5710 | w->start_at_line_beg = Qnil; | |
177c0ea7 | 5711 | |
478292ed | 5712 | set_buffer_internal (obuf); |
7ab12479 JB |
5713 | return Qnil; |
5714 | } | |
b7617575 GM |
5715 | |
5716 | ||
81fe0836 | 5717 | DEFUN ("window-text-height", Fwindow_text_height, Swindow_text_height, |
fdb82f93 PJ |
5718 | 0, 1, 0, |
5719 | doc: /* Return the height in lines of the text display area of WINDOW. | |
c85322d0 | 5720 | WINDOW defaults to the selected window. |
fdb82f93 PJ |
5721 | This doesn't include the mode-line (or header-line if any) or any |
5722 | partial-height lines in the text display area. */) | |
5723 | (window) | |
81fe0836 MB |
5724 | Lisp_Object window; |
5725 | { | |
5726 | struct window *w = decode_window (window); | |
5727 | int pixel_height = window_box_height (w); | |
949cf20f | 5728 | int line_height = pixel_height / FRAME_LINE_HEIGHT (XFRAME (w->frame)); |
81fe0836 MB |
5729 | return make_number (line_height); |
5730 | } | |
5731 | ||
5732 | ||
7ab12479 JB |
5733 | \f |
5734 | DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line, | |
fdb82f93 PJ |
5735 | 1, 1, "P", |
5736 | doc: /* Position point relative to window. | |
5737 | With no argument, position point at center of window. | |
5738 | An argument specifies vertical position within the window; | |
5739 | zero means top of window, negative means relative to bottom of window. */) | |
5740 | (arg) | |
b7617575 | 5741 | Lisp_Object arg; |
7ab12479 | 5742 | { |
b7617575 GM |
5743 | struct window *w = XWINDOW (selected_window); |
5744 | int lines, start; | |
540b6aa0 | 5745 | Lisp_Object window; |
f6b43440 RS |
5746 | #if 0 |
5747 | int this_scroll_margin; | |
5748 | #endif | |
7ab12479 | 5749 | |
b7617575 | 5750 | window = selected_window; |
7ab12479 JB |
5751 | start = marker_position (w->start); |
5752 | if (start < BEGV || start > ZV) | |
5753 | { | |
b7617575 | 5754 | int height = window_internal_height (w); |
cd2be1dd | 5755 | Fvertical_motion (make_number (- (height / 2)), window); |
b73ea88e | 5756 | set_marker_both (w->start, w->buffer, PT, PT_BYTE); |
7ab12479 JB |
5757 | w->start_at_line_beg = Fbolp (); |
5758 | w->force_start = Qt; | |
5759 | } | |
5760 | else | |
b73ea88e | 5761 | Fgoto_char (w->start); |
7ab12479 | 5762 | |
b7617575 | 5763 | lines = displayed_window_lines (w); |
f6b43440 RS |
5764 | |
5765 | #if 0 | |
5766 | this_scroll_margin = max (0, scroll_margin); | |
5767 | this_scroll_margin = min (this_scroll_margin, lines / 4); | |
5768 | #endif | |
5769 | ||
b7617575 GM |
5770 | if (NILP (arg)) |
5771 | XSETFASTINT (arg, lines / 2); | |
5772 | else | |
5773 | { | |
f6b43440 RS |
5774 | int iarg = XINT (Fprefix_numeric_value (arg)); |
5775 | ||
5776 | if (iarg < 0) | |
5777 | iarg = iarg + lines; | |
5778 | ||
5779 | #if 0 /* This code would prevent move-to-window-line from moving point | |
5780 | to a place inside the scroll margins (which would cause the | |
5781 | next redisplay to scroll). I wrote this code, but then concluded | |
5782 | it is probably better not to install it. However, it is here | |
5783 | inside #if 0 so as not to lose it. -- rms. */ | |
5784 | ||
5785 | /* Don't let it get into the margin at either top or bottom. */ | |
5786 | iarg = max (iarg, this_scroll_margin); | |
5787 | iarg = min (iarg, lines - this_scroll_margin - 1); | |
5788 | #endif | |
5789 | ||
5790 | arg = make_number (iarg); | |
b7617575 GM |
5791 | } |
5792 | ||
c8bc6f65 | 5793 | /* Skip past a partially visible first line. */ |
163784df | 5794 | if (w->vscroll) |
163784df MB |
5795 | XSETINT (arg, XINT (arg) + 1); |
5796 | ||
540b6aa0 | 5797 | return Fvertical_motion (arg, window); |
7ab12479 | 5798 | } |
5500c422 GM |
5799 | |
5800 | ||
7ab12479 | 5801 | \f |
5500c422 GM |
5802 | /*********************************************************************** |
5803 | Window Configuration | |
5804 | ***********************************************************************/ | |
5805 | ||
7ab12479 JB |
5806 | struct save_window_data |
5807 | { | |
d0fdb6da | 5808 | EMACS_UINT size; |
7ab12479 | 5809 | struct Lisp_Vector *next_from_Lisp_Vector_struct; |
bdc727bf | 5810 | Lisp_Object selected_frame; |
7ab12479 JB |
5811 | Lisp_Object current_window; |
5812 | Lisp_Object current_buffer; | |
5813 | Lisp_Object minibuf_scroll_window; | |
3f49fddc | 5814 | Lisp_Object minibuf_selected_window; |
7ab12479 | 5815 | Lisp_Object root_window; |
bdc727bf | 5816 | Lisp_Object focus_frame; |
cbff28e8 RS |
5817 | /* A vector, each of whose elements is a struct saved_window |
5818 | for one window. */ | |
7ab12479 | 5819 | Lisp_Object saved_windows; |
b05b4e27 SM |
5820 | |
5821 | /* All fields above are traced by the GC. | |
5822 | From `fame-cols' down, the fields are ignored by the GC. */ | |
5823 | ||
5824 | int frame_cols, frame_lines, frame_menu_bar_lines; | |
5825 | int frame_tool_bar_lines; | |
7ab12479 | 5826 | }; |
ff06df24 | 5827 | |
cbff28e8 | 5828 | /* This is saved as a Lisp_Vector */ |
7ab12479 | 5829 | struct saved_window |
ea68264b GM |
5830 | { |
5831 | /* these first two must agree with struct Lisp_Vector in lisp.h */ | |
d0fdb6da | 5832 | EMACS_UINT size; |
ea68264b | 5833 | struct Lisp_Vector *next_from_Lisp_Vector_struct; |
7ab12479 | 5834 | |
ea68264b GM |
5835 | Lisp_Object window; |
5836 | Lisp_Object buffer, start, pointm, mark; | |
949cf20f KS |
5837 | Lisp_Object left_col, top_line, total_cols, total_lines; |
5838 | Lisp_Object hscroll, min_hscroll; | |
ea68264b GM |
5839 | Lisp_Object parent, prev; |
5840 | Lisp_Object start_at_line_beg; | |
5841 | Lisp_Object display_table; | |
949cf20f KS |
5842 | Lisp_Object orig_top_line, orig_total_lines; |
5843 | Lisp_Object left_margin_cols, right_margin_cols; | |
5844 | Lisp_Object left_fringe_width, right_fringe_width, fringes_outside_margins; | |
5845 | Lisp_Object scroll_bar_width, vertical_scroll_bar_type; | |
047aaeb9 | 5846 | Lisp_Object dedicated, resize_proportionally; |
ea68264b GM |
5847 | }; |
5848 | ||
7ab12479 JB |
5849 | #define SAVED_WINDOW_N(swv,n) \ |
5850 | ((struct saved_window *) (XVECTOR ((swv)->contents[(n)]))) | |
5851 | ||
5852 | DEFUN ("window-configuration-p", Fwindow_configuration_p, Swindow_configuration_p, 1, 1, 0, | |
fdb82f93 PJ |
5853 | doc: /* Return t if OBJECT is a window-configuration object. */) |
5854 | (object) | |
413430c5 | 5855 | Lisp_Object object; |
7ab12479 | 5856 | { |
6ad0381c | 5857 | return WINDOW_CONFIGURATIONP (object) ? Qt : Qnil; |
7ab12479 JB |
5858 | } |
5859 | ||
3f8ab7bd | 5860 | DEFUN ("window-configuration-frame", Fwindow_configuration_frame, Swindow_configuration_frame, 1, 1, 0, |
fdb82f93 PJ |
5861 | doc: /* Return the frame that CONFIG, a window-configuration object, is about. */) |
5862 | (config) | |
3f8ab7bd RS |
5863 | Lisp_Object config; |
5864 | { | |
5865 | register struct save_window_data *data; | |
5866 | struct Lisp_Vector *saved_windows; | |
5867 | ||
663fbbba | 5868 | CHECK_WINDOW_CONFIGURATION (config); |
3f8ab7bd RS |
5869 | |
5870 | data = (struct save_window_data *) XVECTOR (config); | |
5871 | saved_windows = XVECTOR (data->saved_windows); | |
5872 | return XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame; | |
5873 | } | |
5874 | ||
d5b2799e | 5875 | DEFUN ("set-window-configuration", Fset_window_configuration, |
fdb82f93 PJ |
5876 | Sset_window_configuration, 1, 1, 0, |
5877 | doc: /* Set the configuration of windows and buffers as specified by CONFIGURATION. | |
5878 | CONFIGURATION must be a value previously returned | |
5879 | by `current-window-configuration' (which see). | |
5880 | If CONFIGURATION was made from a frame that is now deleted, | |
5881 | only frame-independent values can be restored. In this case, | |
5882 | the return value is nil. Otherwise the value is t. */) | |
5883 | (configuration) | |
2f83aebe | 5884 | Lisp_Object configuration; |
7ab12479 | 5885 | { |
7ab12479 JB |
5886 | register struct save_window_data *data; |
5887 | struct Lisp_Vector *saved_windows; | |
7ab12479 | 5888 | Lisp_Object new_current_buffer; |
fd482be5 | 5889 | Lisp_Object frame; |
44fa5b1e | 5890 | FRAME_PTR f; |
72695e47 | 5891 | int old_point = -1; |
7ab12479 | 5892 | |
663fbbba | 5893 | CHECK_WINDOW_CONFIGURATION (configuration); |
7ab12479 | 5894 | |
2f83aebe | 5895 | data = (struct save_window_data *) XVECTOR (configuration); |
7ab12479 JB |
5896 | saved_windows = XVECTOR (data->saved_windows); |
5897 | ||
7ab12479 | 5898 | new_current_buffer = data->current_buffer; |
265a9e55 | 5899 | if (NILP (XBUFFER (new_current_buffer)->name)) |
7ab12479 | 5900 | new_current_buffer = Qnil; |
72695e47 | 5901 | else |
73cadfc1 DK |
5902 | { |
5903 | if (XBUFFER (new_current_buffer) == current_buffer) | |
e67a1dea SM |
5904 | /* The code further down "preserves point" by saving here PT in |
5905 | old_point and then setting it later back into PT. When the | |
5906 | current-selected-window and the final-selected-window both show | |
5907 | the current buffer, this suffers from the problem that the | |
5908 | current PT is the window-point of the current-selected-window, | |
5909 | while the final PT is the point of the final-selected-window, so | |
5910 | this copy from one PT to the other would end up moving the | |
5911 | window-point of the final-selected-window to the window-point of | |
5912 | the current-selected-window. So we have to be careful which | |
5913 | point of the current-buffer we copy into old_point. */ | |
5914 | if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer) | |
5915 | && WINDOWP (selected_window) | |
5916 | && EQ (XWINDOW (selected_window)->buffer, new_current_buffer) | |
5917 | && !EQ (selected_window, data->current_window)) | |
5918 | old_point = XMARKER (XWINDOW (data->current_window)->pointm)->charpos; | |
5919 | else | |
5920 | old_point = PT; | |
73cadfc1 | 5921 | else |
203eb0aa SM |
5922 | /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of |
5923 | point in new_current_buffer as of the last time this buffer was | |
5924 | used. This can be non-deterministic since it can be changed by | |
5925 | things like jit-lock by mere temporary selection of some random | |
5926 | window that happens to show this buffer. | |
5927 | So if possible we want this arbitrary choice of "which point" to | |
5928 | be the one from the to-be-selected-window so as to prevent this | |
5929 | window's cursor from being copied from another window. */ | |
5930 | if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer) | |
5931 | /* If current_window = selected_window, its point is in BUF_PT. */ | |
5932 | && !EQ (selected_window, data->current_window)) | |
5933 | old_point = XMARKER (XWINDOW (data->current_window)->pointm)->charpos; | |
5934 | else | |
5935 | old_point = BUF_PT (XBUFFER (new_current_buffer)); | |
73cadfc1 | 5936 | } |
7ab12479 | 5937 | |
fd482be5 JB |
5938 | frame = XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame; |
5939 | f = XFRAME (frame); | |
177c0ea7 | 5940 | |
fd482be5 JB |
5941 | /* If f is a dead frame, don't bother rebuilding its window tree. |
5942 | However, there is other stuff we should still try to do below. */ | |
5943 | if (FRAME_LIVE_P (f)) | |
7ab12479 | 5944 | { |
fd482be5 JB |
5945 | register struct window *w; |
5946 | register struct saved_window *p; | |
5500c422 GM |
5947 | struct window *root_window; |
5948 | struct window **leaf_windows; | |
5949 | int n_leaf_windows; | |
c4280705 | 5950 | int k, i, n; |
fd482be5 JB |
5951 | |
5952 | /* If the frame has been resized since this window configuration was | |
5953 | made, we change the frame to the size specified in the | |
5954 | configuration, restore the configuration, and then resize it | |
5955 | back. We keep track of the prevailing height in these variables. */ | |
949cf20f KS |
5956 | int previous_frame_lines = FRAME_LINES (f); |
5957 | int previous_frame_cols = FRAME_COLS (f); | |
8f6ea2e9 | 5958 | int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f); |
9ea173e8 | 5959 | int previous_frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f); |
fd482be5 | 5960 | |
d2b35234 RS |
5961 | /* The mouse highlighting code could get screwed up |
5962 | if it runs during this. */ | |
5963 | BLOCK_INPUT; | |
5964 | ||
b05b4e27 SM |
5965 | if (data->frame_lines != previous_frame_lines |
5966 | || data->frame_cols != previous_frame_cols) | |
5967 | change_frame_size (f, data->frame_lines, | |
5968 | data->frame_cols, 0, 0, 0); | |
e3678b64 | 5969 | #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS) |
b05b4e27 | 5970 | if (data->frame_menu_bar_lines |
8f6ea2e9 | 5971 | != previous_frame_menu_bar_lines) |
b05b4e27 SM |
5972 | x_set_menu_bar_lines (f, make_number (data->frame_menu_bar_lines), |
5973 | make_number (0)); | |
4314246f | 5974 | #ifdef HAVE_WINDOW_SYSTEM |
b05b4e27 | 5975 | if (data->frame_tool_bar_lines |
9ea173e8 | 5976 | != previous_frame_tool_bar_lines) |
b05b4e27 SM |
5977 | x_set_tool_bar_lines (f, make_number (data->frame_tool_bar_lines), |
5978 | make_number (0)); | |
4314246f | 5979 | #endif |
217f2871 | 5980 | #endif |
fd482be5 | 5981 | |
a46c0153 RS |
5982 | /* "Swap out" point from the selected window's buffer |
5983 | into the window itself. (Normally the pointm of the selected | |
5984 | window holds garbage.) We do this now, before | |
719eaeb1 GM |
5985 | restoring the window contents, and prevent it from |
5986 | being done later on when we select a new window. */ | |
596ae0cf RS |
5987 | if (! NILP (XWINDOW (selected_window)->buffer)) |
5988 | { | |
5989 | w = XWINDOW (selected_window); | |
5990 | set_marker_both (w->pointm, | |
5991 | w->buffer, | |
5992 | BUF_PT (XBUFFER (w->buffer)), | |
5993 | BUF_PT_BYTE (XBUFFER (w->buffer))); | |
5994 | } | |
5995 | ||
fd482be5 | 5996 | windows_or_buffers_changed++; |
29aeee73 | 5997 | FRAME_WINDOW_SIZES_CHANGED (f) = 1; |
fd482be5 | 5998 | |
5500c422 | 5999 | /* Problem: Freeing all matrices and later allocating them again |
177c0ea7 | 6000 | is a serious redisplay flickering problem. What we would |
5500c422 | 6001 | really like to do is to free only those matrices not reused |
9d14503e | 6002 | below. */ |
5500c422 GM |
6003 | root_window = XWINDOW (FRAME_ROOT_WINDOW (f)); |
6004 | leaf_windows | |
6005 | = (struct window **) alloca (count_windows (root_window) | |
6006 | * sizeof (struct window *)); | |
6007 | n_leaf_windows = get_leaf_windows (root_window, leaf_windows, 0); | |
6008 | ||
fd482be5 JB |
6009 | /* Kludge Alert! |
6010 | Mark all windows now on frame as "deleted". | |
6011 | Restoring the new configuration "undeletes" any that are in it. | |
37962e60 | 6012 | |
fd482be5 JB |
6013 | Save their current buffers in their height fields, since we may |
6014 | need it later, if a buffer saved in the configuration is now | |
6015 | dead. */ | |
6016 | delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f))); | |
6017 | ||
6018 | for (k = 0; k < saved_windows->size; k++) | |
6019 | { | |
6020 | p = SAVED_WINDOW_N (saved_windows, k); | |
6021 | w = XWINDOW (p->window); | |
6022 | w->next = Qnil; | |
7ab12479 | 6023 | |
fd482be5 JB |
6024 | if (!NILP (p->parent)) |
6025 | w->parent = SAVED_WINDOW_N (saved_windows, | |
6026 | XFASTINT (p->parent))->window; | |
6027 | else | |
6028 | w->parent = Qnil; | |
7ab12479 | 6029 | |
fd482be5 | 6030 | if (!NILP (p->prev)) |
7ab12479 | 6031 | { |
fd482be5 JB |
6032 | w->prev = SAVED_WINDOW_N (saved_windows, |
6033 | XFASTINT (p->prev))->window; | |
6034 | XWINDOW (w->prev)->next = p->window; | |
6035 | } | |
6036 | else | |
6037 | { | |
6038 | w->prev = Qnil; | |
6039 | if (!NILP (w->parent)) | |
6040 | { | |
949cf20f | 6041 | if (EQ (p->total_cols, XWINDOW (w->parent)->total_cols)) |
fd482be5 JB |
6042 | { |
6043 | XWINDOW (w->parent)->vchild = p->window; | |
6044 | XWINDOW (w->parent)->hchild = Qnil; | |
6045 | } | |
6046 | else | |
6047 | { | |
6048 | XWINDOW (w->parent)->hchild = p->window; | |
6049 | XWINDOW (w->parent)->vchild = Qnil; | |
6050 | } | |
6051 | } | |
6052 | } | |
6053 | ||
6054 | /* If we squirreled away the buffer in the window's height, | |
6055 | restore it now. */ | |
949cf20f KS |
6056 | if (BUFFERP (w->total_lines)) |
6057 | w->buffer = w->total_lines; | |
6058 | w->left_col = p->left_col; | |
6059 | w->top_line = p->top_line; | |
6060 | w->total_cols = p->total_cols; | |
6061 | w->total_lines = p->total_lines; | |
fd482be5 | 6062 | w->hscroll = p->hscroll; |
ea68264b | 6063 | w->min_hscroll = p->min_hscroll; |
fd482be5 | 6064 | w->display_table = p->display_table; |
949cf20f KS |
6065 | w->orig_top_line = p->orig_top_line; |
6066 | w->orig_total_lines = p->orig_total_lines; | |
6067 | w->left_margin_cols = p->left_margin_cols; | |
6068 | w->right_margin_cols = p->right_margin_cols; | |
6069 | w->left_fringe_width = p->left_fringe_width; | |
6070 | w->right_fringe_width = p->right_fringe_width; | |
6071 | w->fringes_outside_margins = p->fringes_outside_margins; | |
6072 | w->scroll_bar_width = p->scroll_bar_width; | |
6073 | w->vertical_scroll_bar_type = p->vertical_scroll_bar_type; | |
6ad0381c | 6074 | w->dedicated = p->dedicated; |
047aaeb9 | 6075 | w->resize_proportionally = p->resize_proportionally; |
d834a2e9 | 6076 | XSETFASTINT (w->last_modified, 0); |
3cd21523 | 6077 | XSETFASTINT (w->last_overlay_modified, 0); |
fd482be5 JB |
6078 | |
6079 | /* Reinstall the saved buffer and pointers into it. */ | |
6080 | if (NILP (p->buffer)) | |
6081 | w->buffer = p->buffer; | |
6082 | else | |
6083 | { | |
6084 | if (!NILP (XBUFFER (p->buffer)->name)) | |
6085 | /* If saved buffer is alive, install it. */ | |
6086 | { | |
6087 | w->buffer = p->buffer; | |
6088 | w->start_at_line_beg = p->start_at_line_beg; | |
b73ea88e RS |
6089 | set_marker_restricted (w->start, p->start, w->buffer); |
6090 | set_marker_restricted (w->pointm, p->pointm, w->buffer); | |
fd482be5 | 6091 | Fset_marker (XBUFFER (w->buffer)->mark, |
b73ea88e | 6092 | p->mark, w->buffer); |
fd482be5 JB |
6093 | |
6094 | /* As documented in Fcurrent_window_configuration, don't | |
243a5ce6 RS |
6095 | restore the location of point in the buffer which was |
6096 | current when the window configuration was recorded. */ | |
6b54027b RS |
6097 | if (!EQ (p->buffer, new_current_buffer) |
6098 | && XBUFFER (p->buffer) == current_buffer) | |
fd482be5 JB |
6099 | Fgoto_char (w->pointm); |
6100 | } | |
52a68e98 RS |
6101 | else if (NILP (w->buffer) || NILP (XBUFFER (w->buffer)->name)) |
6102 | /* Else unless window has a live buffer, get one. */ | |
7ab12479 | 6103 | { |
fd482be5 JB |
6104 | w->buffer = Fcdr (Fcar (Vbuffer_alist)); |
6105 | /* This will set the markers to beginning of visible | |
6106 | range. */ | |
6107 | set_marker_restricted (w->start, make_number (0), w->buffer); | |
6108 | set_marker_restricted (w->pointm, make_number (0),w->buffer); | |
6109 | w->start_at_line_beg = Qt; | |
7ab12479 JB |
6110 | } |
6111 | else | |
fd482be5 | 6112 | /* Keeping window's old buffer; make sure the markers |
52a68e98 | 6113 | are real. */ |
7ab12479 | 6114 | { |
fd482be5 JB |
6115 | /* Set window markers at start of visible range. */ |
6116 | if (XMARKER (w->start)->buffer == 0) | |
6117 | set_marker_restricted (w->start, make_number (0), | |
6118 | w->buffer); | |
6119 | if (XMARKER (w->pointm)->buffer == 0) | |
b73ea88e RS |
6120 | set_marker_restricted_both (w->pointm, w->buffer, |
6121 | BUF_PT (XBUFFER (w->buffer)), | |
6122 | BUF_PT_BYTE (XBUFFER (w->buffer))); | |
fd482be5 | 6123 | w->start_at_line_beg = Qt; |
7ab12479 JB |
6124 | } |
6125 | } | |
6126 | } | |
9ace597f | 6127 | |
fd482be5 | 6128 | FRAME_ROOT_WINDOW (f) = data->root_window; |
719eaeb1 GM |
6129 | /* Prevent "swapping out point" in the old selected window |
6130 | using the buffer that has been restored into it. | |
a46c0153 | 6131 | We already swapped out point that from that window's old buffer. */ |
719eaeb1 | 6132 | selected_window = Qnil; |
a46c0153 RS |
6133 | |
6134 | /* Arrange *not* to restore point in the buffer that was | |
6135 | current when the window configuration was saved. */ | |
243a5ce6 RS |
6136 | if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer)) |
6137 | set_marker_restricted (XWINDOW (data->current_window)->pointm, | |
18787f5e | 6138 | make_number (old_point), |
243a5ce6 | 6139 | XWINDOW (data->current_window)->buffer); |
177c0ea7 | 6140 | |
14d87dc9 | 6141 | Fselect_window (data->current_window, Qnil); |
396a830c RS |
6142 | XBUFFER (XWINDOW (selected_window)->buffer)->last_selected_window |
6143 | = selected_window; | |
7ab12479 | 6144 | |
db269683 | 6145 | if (NILP (data->focus_frame) |
017b2bad | 6146 | || (FRAMEP (data->focus_frame) |
db269683 JB |
6147 | && FRAME_LIVE_P (XFRAME (data->focus_frame)))) |
6148 | Fredirect_frame_focus (frame, data->focus_frame); | |
7ab12479 | 6149 | |
fd482be5 JB |
6150 | #if 0 /* I don't understand why this is needed, and it causes problems |
6151 | when the frame's old selected window has been deleted. */ | |
e4e59717 | 6152 | if (f != selected_frame && FRAME_WINDOW_P (f)) |
9a7c6fc3 | 6153 | do_switch_frame (WINDOW_FRAME (XWINDOW (data->root_window)), |
d12f6f83 | 6154 | 0, 0); |
fd482be5 JB |
6155 | #endif |
6156 | ||
6157 | /* Set the screen height to the value it had before this function. */ | |
949cf20f KS |
6158 | if (previous_frame_lines != FRAME_LINES (f) |
6159 | || previous_frame_cols != FRAME_COLS (f)) | |
6160 | change_frame_size (f, previous_frame_lines, previous_frame_cols, | |
2b653806 | 6161 | 0, 0, 0); |
e3678b64 | 6162 | #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS) |
8f6ea2e9 | 6163 | if (previous_frame_menu_bar_lines != FRAME_MENU_BAR_LINES (f)) |
f8ad443a AS |
6164 | x_set_menu_bar_lines (f, make_number (previous_frame_menu_bar_lines), |
6165 | make_number (0)); | |
4314246f | 6166 | #ifdef HAVE_WINDOW_SYSTEM |
9ea173e8 GM |
6167 | if (previous_frame_tool_bar_lines != FRAME_TOOL_BAR_LINES (f)) |
6168 | x_set_tool_bar_lines (f, make_number (previous_frame_tool_bar_lines), | |
6169 | make_number (0)); | |
4314246f | 6170 | #endif |
217f2871 | 6171 | #endif |
d2b35234 | 6172 | |
5500c422 | 6173 | /* Now, free glyph matrices in windows that were not reused. */ |
c4280705 GM |
6174 | for (i = n = 0; i < n_leaf_windows; ++i) |
6175 | { | |
6176 | if (NILP (leaf_windows[i]->buffer)) | |
6177 | { | |
6178 | /* Assert it's not reused as a combination. */ | |
177c0ea7 | 6179 | xassert (NILP (leaf_windows[i]->hchild) |
c4280705 GM |
6180 | && NILP (leaf_windows[i]->vchild)); |
6181 | free_window_matrices (leaf_windows[i]); | |
c4280705 GM |
6182 | } |
6183 | else if (EQ (leaf_windows[i]->buffer, new_current_buffer)) | |
6184 | ++n; | |
6185 | } | |
177c0ea7 | 6186 | |
5500c422 GM |
6187 | adjust_glyphs (f); |
6188 | ||
d2b35234 | 6189 | UNBLOCK_INPUT; |
756b6edc | 6190 | |
478292ed RS |
6191 | /* Fselect_window will have made f the selected frame, so we |
6192 | reselect the proper frame here. Fhandle_switch_frame will change the | |
6193 | selected window too, but that doesn't make the call to | |
6194 | Fselect_window above totally superfluous; it still sets f's | |
6195 | selected window. */ | |
6196 | if (FRAME_LIVE_P (XFRAME (data->selected_frame))) | |
d12f6f83 | 6197 | do_switch_frame (data->selected_frame, 0, 0); |
478292ed | 6198 | |
eeca6f6f | 6199 | run_window_configuration_change_hook (f); |
478292ed | 6200 | } |
bdc727bf JB |
6201 | |
6202 | if (!NILP (new_current_buffer)) | |
243a5ce6 | 6203 | Fset_buffer (new_current_buffer); |
bdc727bf | 6204 | |
478292ed | 6205 | Vminibuf_scroll_window = data->minibuf_scroll_window; |
3dbab091 | 6206 | minibuf_selected_window = data->minibuf_selected_window; |
543f5fb1 | 6207 | |
3f8ab7bd | 6208 | return (FRAME_LIVE_P (f) ? Qt : Qnil); |
7ab12479 JB |
6209 | } |
6210 | ||
44fa5b1e | 6211 | /* Mark all windows now on frame as deleted |
7ab12479 JB |
6212 | by setting their buffers to nil. */ |
6213 | ||
fd482be5 | 6214 | void |
7ab12479 JB |
6215 | delete_all_subwindows (w) |
6216 | register struct window *w; | |
6217 | { | |
265a9e55 | 6218 | if (!NILP (w->next)) |
7ab12479 | 6219 | delete_all_subwindows (XWINDOW (w->next)); |
265a9e55 | 6220 | if (!NILP (w->vchild)) |
7ab12479 | 6221 | delete_all_subwindows (XWINDOW (w->vchild)); |
265a9e55 | 6222 | if (!NILP (w->hchild)) |
7ab12479 | 6223 | delete_all_subwindows (XWINDOW (w->hchild)); |
605be8af | 6224 | |
949cf20f | 6225 | w->total_lines = w->buffer; /* See Fset_window_configuration for excuse. */ |
605be8af | 6226 | |
86e48436 RS |
6227 | if (!NILP (w->buffer)) |
6228 | unshow_buffer (w); | |
6229 | ||
605be8af JB |
6230 | /* We set all three of these fields to nil, to make sure that we can |
6231 | distinguish this dead window from any live window. Live leaf | |
6232 | windows will have buffer set, and combination windows will have | |
6233 | vchild or hchild set. */ | |
6234 | w->buffer = Qnil; | |
6235 | w->vchild = Qnil; | |
6236 | w->hchild = Qnil; | |
acf70840 GM |
6237 | |
6238 | Vwindow_list = Qnil; | |
7ab12479 JB |
6239 | } |
6240 | \f | |
6241 | static int | |
6242 | count_windows (window) | |
6243 | register struct window *window; | |
6244 | { | |
6245 | register int count = 1; | |
265a9e55 | 6246 | if (!NILP (window->next)) |
7ab12479 | 6247 | count += count_windows (XWINDOW (window->next)); |
265a9e55 | 6248 | if (!NILP (window->vchild)) |
7ab12479 | 6249 | count += count_windows (XWINDOW (window->vchild)); |
265a9e55 | 6250 | if (!NILP (window->hchild)) |
7ab12479 JB |
6251 | count += count_windows (XWINDOW (window->hchild)); |
6252 | return count; | |
6253 | } | |
6254 | ||
5500c422 | 6255 | |
177c0ea7 | 6256 | /* Fill vector FLAT with leaf windows under W, starting at index I. |
5500c422 GM |
6257 | Value is last index + 1. */ |
6258 | ||
6259 | static int | |
6260 | get_leaf_windows (w, flat, i) | |
6261 | struct window *w; | |
6262 | struct window **flat; | |
6263 | int i; | |
6264 | { | |
6265 | while (w) | |
6266 | { | |
6267 | if (!NILP (w->hchild)) | |
6268 | i = get_leaf_windows (XWINDOW (w->hchild), flat, i); | |
6269 | else if (!NILP (w->vchild)) | |
6270 | i = get_leaf_windows (XWINDOW (w->vchild), flat, i); | |
177c0ea7 | 6271 | else |
5500c422 GM |
6272 | flat[i++] = w; |
6273 | ||
6274 | w = NILP (w->next) ? 0 : XWINDOW (w->next); | |
6275 | } | |
6276 | ||
6277 | return i; | |
6278 | } | |
6279 | ||
6280 | ||
6281 | /* Return a pointer to the glyph W's physical cursor is on. Value is | |
6282 | null if W's current matrix is invalid, so that no meaningfull glyph | |
6283 | can be returned. */ | |
6284 | ||
6285 | struct glyph * | |
6286 | get_phys_cursor_glyph (w) | |
6287 | struct window *w; | |
6288 | { | |
6289 | struct glyph_row *row; | |
6290 | struct glyph *glyph; | |
6291 | ||
6292 | if (w->phys_cursor.vpos >= 0 | |
6293 | && w->phys_cursor.vpos < w->current_matrix->nrows | |
6294 | && (row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos), | |
6295 | row->enabled_p) | |
6296 | && row->used[TEXT_AREA] > w->phys_cursor.hpos) | |
6297 | glyph = row->glyphs[TEXT_AREA] + w->phys_cursor.hpos; | |
6298 | else | |
6299 | glyph = NULL; | |
6300 | ||
6301 | return glyph; | |
6302 | } | |
6303 | ||
6304 | ||
7ab12479 JB |
6305 | static int |
6306 | save_window_save (window, vector, i) | |
6307 | Lisp_Object window; | |
6308 | struct Lisp_Vector *vector; | |
6309 | int i; | |
6310 | { | |
6311 | register struct saved_window *p; | |
6312 | register struct window *w; | |
6313 | register Lisp_Object tem; | |
6314 | ||
265a9e55 | 6315 | for (;!NILP (window); window = w->next) |
7ab12479 JB |
6316 | { |
6317 | p = SAVED_WINDOW_N (vector, i); | |
6318 | w = XWINDOW (window); | |
6319 | ||
2a1893f4 | 6320 | XSETFASTINT (w->temslot, i); i++; |
7ab12479 JB |
6321 | p->window = window; |
6322 | p->buffer = w->buffer; | |
949cf20f KS |
6323 | p->left_col = w->left_col; |
6324 | p->top_line = w->top_line; | |
6325 | p->total_cols = w->total_cols; | |
6326 | p->total_lines = w->total_lines; | |
7ab12479 | 6327 | p->hscroll = w->hscroll; |
ea68264b | 6328 | p->min_hscroll = w->min_hscroll; |
7ab12479 | 6329 | p->display_table = w->display_table; |
949cf20f KS |
6330 | p->orig_top_line = w->orig_top_line; |
6331 | p->orig_total_lines = w->orig_total_lines; | |
6332 | p->left_margin_cols = w->left_margin_cols; | |
6333 | p->right_margin_cols = w->right_margin_cols; | |
6334 | p->left_fringe_width = w->left_fringe_width; | |
6335 | p->right_fringe_width = w->right_fringe_width; | |
6336 | p->fringes_outside_margins = w->fringes_outside_margins; | |
6337 | p->scroll_bar_width = w->scroll_bar_width; | |
6338 | p->vertical_scroll_bar_type = w->vertical_scroll_bar_type; | |
6ad0381c | 6339 | p->dedicated = w->dedicated; |
047aaeb9 | 6340 | p->resize_proportionally = w->resize_proportionally; |
265a9e55 | 6341 | if (!NILP (w->buffer)) |
7ab12479 JB |
6342 | { |
6343 | /* Save w's value of point in the window configuration. | |
6344 | If w is the selected window, then get the value of point | |
6345 | from the buffer; pointm is garbage in the selected window. */ | |
6346 | if (EQ (window, selected_window)) | |
6347 | { | |
6348 | p->pointm = Fmake_marker (); | |
b73ea88e RS |
6349 | set_marker_both (p->pointm, w->buffer, |
6350 | BUF_PT (XBUFFER (w->buffer)), | |
6351 | BUF_PT_BYTE (XBUFFER (w->buffer))); | |
7ab12479 JB |
6352 | } |
6353 | else | |
eeb82665 | 6354 | p->pointm = Fcopy_marker (w->pointm, Qnil); |
7ab12479 | 6355 | |
eeb82665 | 6356 | p->start = Fcopy_marker (w->start, Qnil); |
7ab12479 JB |
6357 | p->start_at_line_beg = w->start_at_line_beg; |
6358 | ||
6359 | tem = XBUFFER (w->buffer)->mark; | |
eeb82665 | 6360 | p->mark = Fcopy_marker (tem, Qnil); |
7ab12479 JB |
6361 | } |
6362 | else | |
6363 | { | |
6364 | p->pointm = Qnil; | |
6365 | p->start = Qnil; | |
6366 | p->mark = Qnil; | |
6367 | p->start_at_line_beg = Qnil; | |
6368 | } | |
6369 | ||
265a9e55 | 6370 | if (NILP (w->parent)) |
7ab12479 JB |
6371 | p->parent = Qnil; |
6372 | else | |
6373 | p->parent = XWINDOW (w->parent)->temslot; | |
6374 | ||
265a9e55 | 6375 | if (NILP (w->prev)) |
7ab12479 JB |
6376 | p->prev = Qnil; |
6377 | else | |
6378 | p->prev = XWINDOW (w->prev)->temslot; | |
6379 | ||
265a9e55 | 6380 | if (!NILP (w->vchild)) |
7ab12479 | 6381 | i = save_window_save (w->vchild, vector, i); |
265a9e55 | 6382 | if (!NILP (w->hchild)) |
7ab12479 JB |
6383 | i = save_window_save (w->hchild, vector, i); |
6384 | } | |
6385 | ||
6386 | return i; | |
6387 | } | |
6388 | ||
a0d76c27 | 6389 | DEFUN ("current-window-configuration", Fcurrent_window_configuration, |
fdb82f93 PJ |
6390 | Scurrent_window_configuration, 0, 1, 0, |
6391 | doc: /* Return an object representing the current window configuration of FRAME. | |
6392 | If FRAME is nil or omitted, use the selected frame. | |
6393 | This describes the number of windows, their sizes and current buffers, | |
6394 | and for each displayed buffer, where display starts, and the positions of | |
6395 | point and mark. An exception is made for point in the current buffer: | |
6396 | its value is -not- saved. | |
6397 | This also records the currently selected frame, and FRAME's focus | |
6398 | redirection (see `redirect-frame-focus'). */) | |
6399 | (frame) | |
44fa5b1e | 6400 | Lisp_Object frame; |
7ab12479 JB |
6401 | { |
6402 | register Lisp_Object tem; | |
6403 | register int n_windows; | |
6404 | register struct save_window_data *data; | |
6405 | register int i; | |
44fa5b1e | 6406 | FRAME_PTR f; |
43bad991 | 6407 | |
44fa5b1e | 6408 | if (NILP (frame)) |
1ae1a37d | 6409 | frame = selected_frame; |
b7826503 | 6410 | CHECK_LIVE_FRAME (frame); |
1ae1a37d | 6411 | f = XFRAME (frame); |
7ab12479 | 6412 | |
44fa5b1e | 6413 | n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f))); |
b05b4e27 SM |
6414 | data = ALLOCATE_PSEUDOVECTOR (struct save_window_data, frame_cols, |
6415 | PVEC_WINDOW_CONFIGURATION); | |
6416 | ||
6417 | data->frame_cols = FRAME_COLS (f); | |
6418 | data->frame_lines = FRAME_LINES (f); | |
6419 | data->frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f); | |
6420 | data->frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f); | |
1ae1a37d | 6421 | data->selected_frame = selected_frame; |
44fa5b1e | 6422 | data->current_window = FRAME_SELECTED_WINDOW (f); |
74112613 | 6423 | XSETBUFFER (data->current_buffer, current_buffer); |
3f49fddc | 6424 | data->minibuf_scroll_window = minibuf_level > 0 ? Vminibuf_scroll_window : Qnil; |
3dbab091 | 6425 | data->minibuf_selected_window = minibuf_level > 0 ? minibuf_selected_window : Qnil; |
44fa5b1e | 6426 | data->root_window = FRAME_ROOT_WINDOW (f); |
bdc727bf | 6427 | data->focus_frame = FRAME_FOCUS_FRAME (f); |
7ab12479 JB |
6428 | tem = Fmake_vector (make_number (n_windows), Qnil); |
6429 | data->saved_windows = tem; | |
6430 | for (i = 0; i < n_windows; i++) | |
6431 | XVECTOR (tem)->contents[i] | |
8a450f0a | 6432 | = Fmake_vector (make_number (VECSIZE (struct saved_window)), Qnil); |
a1d58e5b | 6433 | save_window_save (FRAME_ROOT_WINDOW (f), XVECTOR (tem), 0); |
74112613 | 6434 | XSETWINDOW_CONFIGURATION (tem, data); |
7ab12479 JB |
6435 | return (tem); |
6436 | } | |
6437 | ||
6438 | DEFUN ("save-window-excursion", Fsave_window_excursion, Ssave_window_excursion, | |
fdb82f93 | 6439 | 0, UNEVALLED, 0, |
a0a37a6f LT |
6440 | doc: /* Execute BODY, preserving window sizes and contents. |
6441 | Return the value of the last form in BODY. | |
fdb82f93 PJ |
6442 | Restore which buffer appears in which window, where display starts, |
6443 | and the value of point and mark for each window. | |
6444 | Also restore the choice of selected window. | |
6445 | Also restore which buffer is current. | |
6924dda6 | 6446 | Does not restore the value of point in current buffer. |
7254a30c | 6447 | usage: (save-window-excursion BODY...) */) |
fdb82f93 | 6448 | (args) |
7ab12479 JB |
6449 | Lisp_Object args; |
6450 | { | |
6451 | register Lisp_Object val; | |
aed13378 | 6452 | register int count = SPECPDL_INDEX (); |
7ab12479 JB |
6453 | |
6454 | record_unwind_protect (Fset_window_configuration, | |
43bad991 | 6455 | Fcurrent_window_configuration (Qnil)); |
7ab12479 JB |
6456 | val = Fprogn (args); |
6457 | return unbind_to (count, val); | |
6458 | } | |
5500c422 | 6459 | |
94e16dd5 KS |
6460 | |
6461 | \f | |
6462 | /*********************************************************************** | |
6463 | Window Split Tree | |
6464 | ***********************************************************************/ | |
6465 | ||
6466 | static Lisp_Object | |
c16e1cc3 | 6467 | window_tree (w) |
94e16dd5 KS |
6468 | struct window *w; |
6469 | { | |
6470 | Lisp_Object tail = Qnil; | |
6471 | Lisp_Object result = Qnil; | |
6472 | ||
6473 | while (w) | |
6474 | { | |
6475 | Lisp_Object wn; | |
6476 | ||
6477 | XSETWINDOW (wn, w); | |
6478 | if (!NILP (w->hchild)) | |
6479 | wn = Fcons (Qnil, Fcons (Fwindow_edges (wn), | |
c16e1cc3 | 6480 | window_tree (XWINDOW (w->hchild)))); |
94e16dd5 KS |
6481 | else if (!NILP (w->vchild)) |
6482 | wn = Fcons (Qt, Fcons (Fwindow_edges (wn), | |
c16e1cc3 | 6483 | window_tree (XWINDOW (w->vchild)))); |
94e16dd5 KS |
6484 | |
6485 | if (NILP (result)) | |
6486 | { | |
6487 | result = tail = Fcons (wn, Qnil); | |
6488 | } | |
6489 | else | |
6490 | { | |
6491 | XSETCDR (tail, Fcons (wn, Qnil)); | |
6492 | tail = XCDR (tail); | |
6493 | } | |
6494 | ||
6495 | w = NILP (w->next) ? 0 : XWINDOW (w->next); | |
6496 | } | |
6497 | ||
6498 | return result; | |
6499 | } | |
6500 | ||
6501 | ||
6502 | ||
c16e1cc3 | 6503 | DEFUN ("window-tree", Fwindow_tree, Swindow_tree, |
94e16dd5 | 6504 | 0, 1, 0, |
c16e1cc3 | 6505 | doc: /* Return the window tree for frame FRAME. |
94e16dd5 KS |
6506 | |
6507 | The return value is a list of the form (ROOT MINI), where ROOT | |
c16e1cc3 | 6508 | represents the window tree of the frame's root window, and MINI |
94e16dd5 KS |
6509 | is the frame's minibuffer window. |
6510 | ||
6511 | If the root window is not split, ROOT is the root window itself. | |
6512 | Otherwise, ROOT is a list (DIR EDGES W1 W2 ...) where DIR is nil for a | |
008171a4 | 6513 | horizontal split, and t for a vertical split, EDGES gives the combined |
94e16dd5 KS |
6514 | size and position of the subwindows in the split, and the rest of the |
6515 | elements are the subwindows in the split. Each of the subwindows may | |
6516 | again be a window or a list representing a window split, and so on. | |
6517 | EDGES is a list \(LEFT TOP RIGHT BOTTOM) as returned by `window-edges'. | |
6518 | ||
6519 | If FRAME is nil or omitted, return information on the currently | |
6520 | selected frame. */) | |
6521 | (frame) | |
6522 | Lisp_Object frame; | |
6523 | { | |
94e16dd5 KS |
6524 | FRAME_PTR f; |
6525 | ||
6526 | if (NILP (frame)) | |
6527 | frame = selected_frame; | |
6528 | ||
6529 | CHECK_FRAME (frame); | |
6530 | f = XFRAME (frame); | |
6531 | ||
6532 | if (!FRAME_LIVE_P (f)) | |
6533 | return Qnil; | |
6534 | ||
c16e1cc3 | 6535 | return window_tree (XWINDOW (FRAME_ROOT_WINDOW (f))); |
94e16dd5 KS |
6536 | } |
6537 | ||
5500c422 GM |
6538 | \f |
6539 | /*********************************************************************** | |
6540 | Marginal Areas | |
6541 | ***********************************************************************/ | |
6542 | ||
6543 | DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins, | |
a7bdfc08 | 6544 | 2, 3, 0, |
fdb82f93 | 6545 | doc: /* Set width of marginal areas of window WINDOW. |
6b61353c KH |
6546 | If WINDOW is nil, set margins of the currently selected window. |
6547 | Second arg LEFT-WIDTH specifies the number of character cells to | |
6548 | reserve for the left marginal area. Optional third arg RIGHT-WIDTH | |
6549 | does the same for the right marginal area. A nil width parameter | |
6550 | means no margin. */) | |
c10ce82e JB |
6551 | (window, left_width, right_width) |
6552 | Lisp_Object window, left_width, right_width; | |
5500c422 GM |
6553 | { |
6554 | struct window *w = decode_window (window); | |
5500c422 | 6555 | |
6b61353c KH |
6556 | /* Translate negative or zero widths to nil. |
6557 | Margins that are too wide have to be checked elsewhere. */ | |
949cf20f | 6558 | |
c10ce82e | 6559 | if (!NILP (left_width)) |
6b61353c | 6560 | { |
c10ce82e JB |
6561 | CHECK_NUMBER (left_width); |
6562 | if (XINT (left_width) <= 0) | |
6563 | left_width = Qnil; | |
6b61353c | 6564 | } |
5500c422 | 6565 | |
c10ce82e | 6566 | if (!NILP (right_width)) |
6b61353c | 6567 | { |
c10ce82e JB |
6568 | CHECK_NUMBER (right_width); |
6569 | if (XINT (right_width) <= 0) | |
6570 | right_width = Qnil; | |
6b61353c | 6571 | } |
5500c422 | 6572 | |
c10ce82e JB |
6573 | if (!EQ (w->left_margin_cols, left_width) |
6574 | || !EQ (w->right_margin_cols, right_width)) | |
949cf20f | 6575 | { |
c10ce82e JB |
6576 | w->left_margin_cols = left_width; |
6577 | w->right_margin_cols = right_width; | |
949cf20f KS |
6578 | |
6579 | adjust_window_margins (w); | |
6580 | ||
6581 | ++windows_or_buffers_changed; | |
6582 | adjust_glyphs (XFRAME (WINDOW_FRAME (w))); | |
6583 | } | |
5500c422 | 6584 | |
5500c422 GM |
6585 | return Qnil; |
6586 | } | |
6587 | ||
6588 | ||
6589 | DEFUN ("window-margins", Fwindow_margins, Swindow_margins, | |
6590 | 0, 1, 0, | |
fdb82f93 PJ |
6591 | doc: /* Get width of marginal areas of window WINDOW. |
6592 | If WINDOW is omitted or nil, use the currently selected window. | |
6593 | Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH). | |
6594 | If a marginal area does not exist, its width will be returned | |
6595 | as nil. */) | |
6596 | (window) | |
5500c422 GM |
6597 | Lisp_Object window; |
6598 | { | |
6599 | struct window *w = decode_window (window); | |
949cf20f KS |
6600 | return Fcons (w->left_margin_cols, w->right_margin_cols); |
6601 | } | |
6602 | ||
6603 | ||
6604 | \f | |
6605 | /*********************************************************************** | |
6606 | Fringes | |
6607 | ***********************************************************************/ | |
6608 | ||
6609 | DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes, | |
6610 | 2, 4, 0, | |
6b61353c KH |
6611 | doc: /* Set the fringe widths of window WINDOW. |
6612 | If WINDOW is nil, set the fringe widths of the currently selected | |
6613 | window. | |
6614 | Second arg LEFT-WIDTH specifies the number of pixels to reserve for | |
6615 | the left fringe. Optional third arg RIGHT-WIDTH specifies the right | |
6616 | fringe width. If a fringe width arg is nil, that means to use the | |
6617 | frame's default fringe width. Default fringe widths can be set with | |
6618 | the command `set-fringe-style'. | |
6619 | If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes | |
6620 | outside of the display margins. By default, fringes are drawn between | |
6621 | display marginal areas and the text area. */) | |
c10ce82e JB |
6622 | (window, left_width, right_width, outside_margins) |
6623 | Lisp_Object window, left_width, right_width, outside_margins; | |
949cf20f KS |
6624 | { |
6625 | struct window *w = decode_window (window); | |
6626 | ||
c10ce82e JB |
6627 | if (!NILP (left_width)) |
6628 | CHECK_NATNUM (left_width); | |
6629 | if (!NILP (right_width)) | |
6630 | CHECK_NATNUM (right_width); | |
5a857365 | 6631 | |
017e297e | 6632 | /* Do nothing on a tty. */ |
d46c6df5 NR |
6633 | if (FRAME_WINDOW_P (WINDOW_XFRAME (w)) |
6634 | && (!EQ (w->left_fringe_width, left_width) | |
6635 | || !EQ (w->right_fringe_width, right_width) | |
6636 | || !EQ (w->fringes_outside_margins, outside_margins))) | |
949cf20f | 6637 | { |
c10ce82e JB |
6638 | w->left_fringe_width = left_width; |
6639 | w->right_fringe_width = right_width; | |
949cf20f KS |
6640 | w->fringes_outside_margins = outside_margins; |
6641 | ||
6642 | adjust_window_margins (w); | |
6643 | ||
6644 | clear_glyph_matrix (w->current_matrix); | |
6645 | w->window_end_valid = Qnil; | |
6646 | ||
6647 | ++windows_or_buffers_changed; | |
6648 | adjust_glyphs (XFRAME (WINDOW_FRAME (w))); | |
6649 | } | |
6650 | ||
6651 | return Qnil; | |
6652 | } | |
6653 | ||
6654 | ||
6655 | DEFUN ("window-fringes", Fwindow_fringes, Swindow_fringes, | |
6656 | 0, 1, 0, | |
6657 | doc: /* Get width of fringes of window WINDOW. | |
6658 | If WINDOW is omitted or nil, use the currently selected window. | |
6b61353c | 6659 | Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */) |
949cf20f KS |
6660 | (window) |
6661 | Lisp_Object window; | |
6662 | { | |
6663 | struct window *w = decode_window (window); | |
d46c6df5 | 6664 | |
949cf20f KS |
6665 | return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w)), |
6666 | Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w)), | |
d46c6df5 NR |
6667 | Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) |
6668 | ? Qt : Qnil), Qnil))); | |
949cf20f KS |
6669 | } |
6670 | ||
6671 | ||
6672 | \f | |
6673 | /*********************************************************************** | |
6674 | Scroll bars | |
6675 | ***********************************************************************/ | |
6676 | ||
6677 | DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars, Sset_window_scroll_bars, | |
6678 | 2, 4, 0, | |
6679 | doc: /* Set width and type of scroll bars of window WINDOW. | |
6680 | If window is nil, set scroll bars of the currently selected window. | |
6681 | Second parameter WIDTH specifies the pixel width for the scroll bar; | |
6682 | this is automatically adjusted to a multiple of the frame column width. | |
6683 | Third parameter VERTICAL-TYPE specifies the type of the vertical scroll | |
6684 | bar: left, right, or nil. | |
6b61353c | 6685 | If WIDTH is nil, use the frame's scroll-bar width. |
a53d44a8 JB |
6686 | If VERTICAL-TYPE is t, use the frame's scroll-bar type. |
6687 | Fourth parameter HORIZONTAL-TYPE is currently unused. */) | |
79fd290e JB |
6688 | (window, width, vertical_type, horizontal_type) |
6689 | Lisp_Object window, width, vertical_type, horizontal_type; | |
949cf20f KS |
6690 | { |
6691 | struct window *w = decode_window (window); | |
6692 | ||
6693 | if (!NILP (width)) | |
0f8fe9a2 SM |
6694 | { |
6695 | CHECK_NATNUM (width); | |
949cf20f | 6696 | |
0f8fe9a2 SM |
6697 | if (XINT (width) == 0) |
6698 | vertical_type = Qnil; | |
6699 | } | |
949cf20f | 6700 | |
413a79ad | 6701 | if (!(NILP (vertical_type) |
0cc1039f | 6702 | || EQ (vertical_type, Qleft) |
6b61353c KH |
6703 | || EQ (vertical_type, Qright) |
6704 | || EQ (vertical_type, Qt))) | |
6705 | error ("Invalid type of vertical scroll bar"); | |
6706 | ||
949cf20f KS |
6707 | if (!EQ (w->scroll_bar_width, width) |
6708 | || !EQ (w->vertical_scroll_bar_type, vertical_type)) | |
6709 | { | |
6710 | w->scroll_bar_width = width; | |
6711 | w->vertical_scroll_bar_type = vertical_type; | |
6712 | ||
6713 | adjust_window_margins (w); | |
6714 | ||
6715 | clear_glyph_matrix (w->current_matrix); | |
6716 | w->window_end_valid = Qnil; | |
6717 | ||
6718 | ++windows_or_buffers_changed; | |
6719 | adjust_glyphs (XFRAME (WINDOW_FRAME (w))); | |
6720 | } | |
6721 | ||
6722 | return Qnil; | |
6723 | } | |
6724 | ||
6725 | ||
6726 | DEFUN ("window-scroll-bars", Fwindow_scroll_bars, Swindow_scroll_bars, | |
6727 | 0, 1, 0, | |
6728 | doc: /* Get width and type of scroll bars of window WINDOW. | |
6729 | If WINDOW is omitted or nil, use the currently selected window. | |
6b61353c KH |
6730 | Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE). |
6731 | If WIDTH is nil or TYPE is t, the window is using the frame's corresponding | |
6732 | value. */) | |
949cf20f KS |
6733 | (window) |
6734 | Lisp_Object window; | |
6735 | { | |
6736 | struct window *w = decode_window (window); | |
6737 | return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w) | |
6738 | ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w) | |
6739 | : WINDOW_SCROLL_BAR_AREA_WIDTH (w))), | |
6740 | Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w)), | |
6741 | Fcons (w->vertical_scroll_bar_type, | |
6742 | Fcons (Qnil, Qnil)))); | |
5500c422 GM |
6743 | } |
6744 | ||
6745 | ||
7ab12479 | 6746 | \f |
5500c422 GM |
6747 | /*********************************************************************** |
6748 | Smooth scrolling | |
6749 | ***********************************************************************/ | |
6750 | ||
0cc1039f | 6751 | DEFUN ("window-vscroll", Fwindow_vscroll, Swindow_vscroll, 0, 2, 0, |
fdb82f93 PJ |
6752 | doc: /* Return the amount by which WINDOW is scrolled vertically. |
6753 | Use the selected window if WINDOW is nil or omitted. | |
0cc1039f | 6754 | Normally, value is a multiple of the canonical character height of WINDOW; |
8cd0d661 | 6755 | optional second arg PIXELS-P means value is measured in pixels. */) |
0cc1039f KS |
6756 | (window, pixels_p) |
6757 | Lisp_Object window, pixels_p; | |
5500c422 | 6758 | { |
47004952 | 6759 | Lisp_Object result; |
5500c422 GM |
6760 | struct frame *f; |
6761 | struct window *w; | |
177c0ea7 | 6762 | |
5500c422 GM |
6763 | if (NILP (window)) |
6764 | window = selected_window; | |
47004952 | 6765 | else |
b7826503 | 6766 | CHECK_WINDOW (window); |
5500c422 GM |
6767 | w = XWINDOW (window); |
6768 | f = XFRAME (w->frame); | |
177c0ea7 | 6769 | |
5500c422 | 6770 | if (FRAME_WINDOW_P (f)) |
0cc1039f KS |
6771 | result = (NILP (pixels_p) |
6772 | ? FRAME_CANON_Y_FROM_PIXEL_Y (f, -w->vscroll) | |
6773 | : make_number (-w->vscroll)); | |
5500c422 | 6774 | else |
47004952 GM |
6775 | result = make_number (0); |
6776 | return result; | |
5500c422 GM |
6777 | } |
6778 | ||
6779 | ||
6780 | DEFUN ("set-window-vscroll", Fset_window_vscroll, Sset_window_vscroll, | |
0cc1039f | 6781 | 2, 3, 0, |
fdb82f93 | 6782 | doc: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL. |
0cc1039f KS |
6783 | WINDOW nil means use the selected window. Normally, VSCROLL is a |
6784 | non-negative multiple of the canonical character height of WINDOW; | |
8cd0d661 | 6785 | optional third arg PIXELS-P non-nil means that VSCROLL is in pixels. |
a0a37a6f LT |
6786 | If PIXELS-P is nil, VSCROLL may have to be rounded so that it |
6787 | corresponds to an integral number of pixels. The return value is the | |
6788 | result of this rounding. | |
6789 | If PIXELS-P is non-nil, the return value is VSCROLL. */) | |
0cc1039f KS |
6790 | (window, vscroll, pixels_p) |
6791 | Lisp_Object window, vscroll, pixels_p; | |
5500c422 GM |
6792 | { |
6793 | struct window *w; | |
6794 | struct frame *f; | |
177c0ea7 | 6795 | |
5500c422 GM |
6796 | if (NILP (window)) |
6797 | window = selected_window; | |
47004952 | 6798 | else |
b7826503 PJ |
6799 | CHECK_WINDOW (window); |
6800 | CHECK_NUMBER_OR_FLOAT (vscroll); | |
177c0ea7 | 6801 | |
5500c422 GM |
6802 | w = XWINDOW (window); |
6803 | f = XFRAME (w->frame); | |
6804 | ||
6805 | if (FRAME_WINDOW_P (f)) | |
6806 | { | |
6807 | int old_dy = w->vscroll; | |
177c0ea7 | 6808 | |
0cc1039f KS |
6809 | w->vscroll = - (NILP (pixels_p) |
6810 | ? FRAME_LINE_HEIGHT (f) * XFLOATINT (vscroll) | |
6811 | : XFLOATINT (vscroll)); | |
47004952 | 6812 | w->vscroll = min (w->vscroll, 0); |
5500c422 | 6813 | |
e56263e5 KS |
6814 | if (w->vscroll != old_dy) |
6815 | { | |
6816 | /* Adjust glyph matrix of the frame if the virtual display | |
6817 | area becomes larger than before. */ | |
6818 | if (w->vscroll < 0 && w->vscroll < old_dy) | |
6819 | adjust_glyphs (f); | |
177c0ea7 | 6820 | |
e56263e5 KS |
6821 | /* Prevent redisplay shortcuts. */ |
6822 | XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1; | |
6823 | } | |
5500c422 | 6824 | } |
177c0ea7 | 6825 | |
0cc1039f | 6826 | return Fwindow_vscroll (window, pixels_p); |
5500c422 | 6827 | } |
177c0ea7 | 6828 | |
7bbb5782 GM |
6829 | \f |
6830 | /* Call FN for all leaf windows on frame F. FN is called with the | |
6831 | first argument being a pointer to the leaf window, and with | |
f95464e4 | 6832 | additional argument USER_DATA. Stops when FN returns 0. */ |
7bbb5782 GM |
6833 | |
6834 | void | |
f95464e4 | 6835 | foreach_window (f, fn, user_data) |
7bbb5782 | 6836 | struct frame *f; |
f95464e4 GM |
6837 | int (* fn) P_ ((struct window *, void *)); |
6838 | void *user_data; | |
7bbb5782 | 6839 | { |
76fb556f YM |
6840 | /* Fdelete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */ |
6841 | if (WINDOWP (FRAME_ROOT_WINDOW (f))) | |
6842 | foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f)), fn, user_data); | |
7bbb5782 GM |
6843 | } |
6844 | ||
6845 | ||
6846 | /* Helper function for foreach_window. Call FN for all leaf windows | |
6847 | reachable from W. FN is called with the first argument being a | |
f95464e4 | 6848 | pointer to the leaf window, and with additional argument USER_DATA. |
67492200 | 6849 | Stop when FN returns 0. Value is 0 if stopped by FN. */ |
7bbb5782 | 6850 | |
67492200 | 6851 | static int |
f95464e4 | 6852 | foreach_window_1 (w, fn, user_data) |
7bbb5782 | 6853 | struct window *w; |
f95464e4 GM |
6854 | int (* fn) P_ ((struct window *, void *)); |
6855 | void *user_data; | |
7bbb5782 | 6856 | { |
67492200 | 6857 | int cont; |
177c0ea7 | 6858 | |
67492200 | 6859 | for (cont = 1; w && cont;) |
7bbb5782 GM |
6860 | { |
6861 | if (!NILP (w->hchild)) | |
f95464e4 | 6862 | cont = foreach_window_1 (XWINDOW (w->hchild), fn, user_data); |
7bbb5782 | 6863 | else if (!NILP (w->vchild)) |
f95464e4 | 6864 | cont = foreach_window_1 (XWINDOW (w->vchild), fn, user_data); |
177c0ea7 | 6865 | else |
0f532a9a | 6866 | cont = fn (w, user_data); |
177c0ea7 | 6867 | |
7bbb5782 GM |
6868 | w = NILP (w->next) ? 0 : XWINDOW (w->next); |
6869 | } | |
67492200 GM |
6870 | |
6871 | return cont; | |
7bbb5782 GM |
6872 | } |
6873 | ||
6874 | ||
6d194a45 | 6875 | /* Freeze or unfreeze the window start of W unless it is a |
f95464e4 | 6876 | mini-window or the selected window. FREEZE_P non-null means freeze |
7bbb5782 GM |
6877 | the window start. */ |
6878 | ||
67492200 | 6879 | static int |
7bbb5782 GM |
6880 | freeze_window_start (w, freeze_p) |
6881 | struct window *w; | |
f95464e4 | 6882 | void *freeze_p; |
7bbb5782 | 6883 | { |
08c1d235 SM |
6884 | if (MINI_WINDOW_P (w) |
6885 | || (WINDOWP (selected_window) /* Can be nil in corner cases. */ | |
6886 | && (w == XWINDOW (selected_window) | |
6887 | || (MINI_WINDOW_P (XWINDOW (selected_window)) | |
6888 | && ! NILP (Vminibuf_scroll_window) | |
6889 | && w == XWINDOW (Vminibuf_scroll_window))))) | |
f95464e4 | 6890 | freeze_p = NULL; |
177c0ea7 | 6891 | |
f95464e4 | 6892 | w->frozen_window_start_p = freeze_p != NULL; |
67492200 | 6893 | return 1; |
7bbb5782 GM |
6894 | } |
6895 | ||
6896 | ||
6897 | /* Freeze or unfreeze the window starts of all leaf windows on frame | |
6898 | F, except the selected window and a mini-window. FREEZE_P non-zero | |
6899 | means freeze the window start. */ | |
6900 | ||
6901 | void | |
6902 | freeze_window_starts (f, freeze_p) | |
6903 | struct frame *f; | |
6904 | int freeze_p; | |
6905 | { | |
cbccabec | 6906 | foreach_window (f, freeze_window_start, (void *) (freeze_p ? f : 0)); |
7bbb5782 | 6907 | } |
5500c422 GM |
6908 | |
6909 | \f | |
6910 | /*********************************************************************** | |
6911 | Initialization | |
6912 | ***********************************************************************/ | |
6913 | ||
cbff28e8 | 6914 | /* Return 1 if window configurations C1 and C2 |
9d14503e | 6915 | describe the same state of affairs. This is used by Fequal. */ |
cbff28e8 RS |
6916 | |
6917 | int | |
2f8274be | 6918 | compare_window_configurations (c1, c2, ignore_positions) |
cbff28e8 | 6919 | Lisp_Object c1, c2; |
2f8274be | 6920 | int ignore_positions; |
cbff28e8 RS |
6921 | { |
6922 | register struct save_window_data *d1, *d2; | |
6923 | struct Lisp_Vector *sw1, *sw2; | |
6924 | int i; | |
6925 | ||
663fbbba KS |
6926 | CHECK_WINDOW_CONFIGURATION (c1); |
6927 | CHECK_WINDOW_CONFIGURATION (c2); | |
177c0ea7 | 6928 | |
cbff28e8 RS |
6929 | d1 = (struct save_window_data *) XVECTOR (c1); |
6930 | d2 = (struct save_window_data *) XVECTOR (c2); | |
6931 | sw1 = XVECTOR (d1->saved_windows); | |
6932 | sw2 = XVECTOR (d2->saved_windows); | |
6933 | ||
b05b4e27 | 6934 | if (d1->frame_cols != d2->frame_cols) |
cbff28e8 | 6935 | return 0; |
b05b4e27 | 6936 | if (d1->frame_lines != d2->frame_lines) |
cbff28e8 | 6937 | return 0; |
b05b4e27 | 6938 | if (d1->frame_menu_bar_lines != d2->frame_menu_bar_lines) |
cbff28e8 RS |
6939 | return 0; |
6940 | if (! EQ (d1->selected_frame, d2->selected_frame)) | |
6941 | return 0; | |
6942 | /* Don't compare the current_window field directly. | |
6943 | Instead see w1_is_current and w2_is_current, below. */ | |
6944 | if (! EQ (d1->current_buffer, d2->current_buffer)) | |
6945 | return 0; | |
2f8274be | 6946 | if (! ignore_positions) |
3f49fddc KS |
6947 | { |
6948 | if (! EQ (d1->minibuf_scroll_window, d2->minibuf_scroll_window)) | |
6949 | return 0; | |
6950 | if (! EQ (d1->minibuf_selected_window, d2->minibuf_selected_window)) | |
6951 | return 0; | |
6952 | } | |
cbff28e8 RS |
6953 | /* Don't compare the root_window field. |
6954 | We don't require the two configurations | |
6955 | to use the same window object, | |
6956 | and the two root windows must be equivalent | |
6957 | if everything else compares equal. */ | |
6958 | if (! EQ (d1->focus_frame, d2->focus_frame)) | |
6959 | return 0; | |
cbff28e8 RS |
6960 | |
6961 | /* Verify that the two confis have the same number of windows. */ | |
6962 | if (sw1->size != sw2->size) | |
6963 | return 0; | |
6964 | ||
6965 | for (i = 0; i < sw1->size; i++) | |
6966 | { | |
6967 | struct saved_window *p1, *p2; | |
6968 | int w1_is_current, w2_is_current; | |
6969 | ||
6970 | p1 = SAVED_WINDOW_N (sw1, i); | |
6971 | p2 = SAVED_WINDOW_N (sw2, i); | |
6972 | ||
6973 | /* Verify that the current windows in the two | |
6974 | configurations correspond to each other. */ | |
6975 | w1_is_current = EQ (d1->current_window, p1->window); | |
6976 | w2_is_current = EQ (d2->current_window, p2->window); | |
6977 | ||
6978 | if (w1_is_current != w2_is_current) | |
6979 | return 0; | |
6980 | ||
6981 | /* Verify that the corresponding windows do match. */ | |
6982 | if (! EQ (p1->buffer, p2->buffer)) | |
6983 | return 0; | |
949cf20f | 6984 | if (! EQ (p1->left_col, p2->left_col)) |
cbff28e8 | 6985 | return 0; |
949cf20f | 6986 | if (! EQ (p1->top_line, p2->top_line)) |
cbff28e8 | 6987 | return 0; |
949cf20f | 6988 | if (! EQ (p1->total_cols, p2->total_cols)) |
cbff28e8 | 6989 | return 0; |
949cf20f | 6990 | if (! EQ (p1->total_lines, p2->total_lines)) |
cbff28e8 | 6991 | return 0; |
cbff28e8 RS |
6992 | if (! EQ (p1->display_table, p2->display_table)) |
6993 | return 0; | |
6994 | if (! EQ (p1->parent, p2->parent)) | |
6995 | return 0; | |
6996 | if (! EQ (p1->prev, p2->prev)) | |
6997 | return 0; | |
2f8274be RS |
6998 | if (! ignore_positions) |
6999 | { | |
7000 | if (! EQ (p1->hscroll, p2->hscroll)) | |
7001 | return 0; | |
ea68264b GM |
7002 | if (!EQ (p1->min_hscroll, p2->min_hscroll)) |
7003 | return 0; | |
2f8274be RS |
7004 | if (! EQ (p1->start_at_line_beg, p2->start_at_line_beg)) |
7005 | return 0; | |
7006 | if (NILP (Fequal (p1->start, p2->start))) | |
7007 | return 0; | |
7008 | if (NILP (Fequal (p1->pointm, p2->pointm))) | |
7009 | return 0; | |
7010 | if (NILP (Fequal (p1->mark, p2->mark))) | |
7011 | return 0; | |
7012 | } | |
949cf20f KS |
7013 | if (! EQ (p1->left_margin_cols, p2->left_margin_cols)) |
7014 | return 0; | |
7015 | if (! EQ (p1->right_margin_cols, p2->right_margin_cols)) | |
7016 | return 0; | |
7017 | if (! EQ (p1->left_fringe_width, p2->left_fringe_width)) | |
7018 | return 0; | |
7019 | if (! EQ (p1->right_fringe_width, p2->right_fringe_width)) | |
7020 | return 0; | |
7021 | if (! EQ (p1->fringes_outside_margins, p2->fringes_outside_margins)) | |
7022 | return 0; | |
7023 | if (! EQ (p1->scroll_bar_width, p2->scroll_bar_width)) | |
7024 | return 0; | |
7025 | if (! EQ (p1->vertical_scroll_bar_type, p2->vertical_scroll_bar_type)) | |
7026 | return 0; | |
cbff28e8 RS |
7027 | } |
7028 | ||
7029 | return 1; | |
7030 | } | |
2f8274be RS |
7031 | |
7032 | DEFUN ("compare-window-configurations", Fcompare_window_configurations, | |
7033 | Scompare_window_configurations, 2, 2, 0, | |
fdb82f93 PJ |
7034 | doc: /* Compare two window configurations as regards the structure of windows. |
7035 | This function ignores details such as the values of point and mark | |
7036 | and scrolling positions. */) | |
7037 | (x, y) | |
2f8274be RS |
7038 | Lisp_Object x, y; |
7039 | { | |
7040 | if (compare_window_configurations (x, y, 1)) | |
7041 | return Qt; | |
7042 | return Qnil; | |
7043 | } | |
cbff28e8 | 7044 | \f |
dfcf069d | 7045 | void |
7ab12479 JB |
7046 | init_window_once () |
7047 | { | |
3224dac1 | 7048 | struct frame *f = make_initial_frame (); |
1ae1a37d GM |
7049 | XSETFRAME (selected_frame, f); |
7050 | Vterminal_frame = selected_frame; | |
7051 | minibuf_window = f->minibuffer_window; | |
7052 | selected_window = f->selected_window; | |
7053 | last_nonminibuf_frame = f; | |
5b03d3c0 RS |
7054 | |
7055 | window_initialized = 1; | |
7ab12479 JB |
7056 | } |
7057 | ||
67492200 GM |
7058 | void |
7059 | init_window () | |
7060 | { | |
7061 | Vwindow_list = Qnil; | |
7062 | } | |
7063 | ||
dfcf069d | 7064 | void |
7ab12479 JB |
7065 | syms_of_window () |
7066 | { | |
c525d842 CY |
7067 | Qscroll_up = intern ("scroll-up"); |
7068 | staticpro (&Qscroll_up); | |
7069 | ||
7070 | Qscroll_down = intern ("scroll-down"); | |
7071 | staticpro (&Qscroll_down); | |
7072 | ||
8a37516b GM |
7073 | Qwindow_size_fixed = intern ("window-size-fixed"); |
7074 | staticpro (&Qwindow_size_fixed); | |
c0e7ccd3 | 7075 | Fset (Qwindow_size_fixed, Qnil); |
177c0ea7 | 7076 | |
543f5fb1 RS |
7077 | staticpro (&Qwindow_configuration_change_hook); |
7078 | Qwindow_configuration_change_hook | |
7079 | = intern ("window-configuration-change-hook"); | |
7080 | ||
7ab12479 JB |
7081 | Qwindowp = intern ("windowp"); |
7082 | staticpro (&Qwindowp); | |
7083 | ||
3f8ab7bd RS |
7084 | Qwindow_configuration_p = intern ("window-configuration-p"); |
7085 | staticpro (&Qwindow_configuration_p); | |
7086 | ||
806b4d9b JB |
7087 | Qwindow_live_p = intern ("window-live-p"); |
7088 | staticpro (&Qwindow_live_p); | |
605be8af | 7089 | |
87478b52 SM |
7090 | Qdisplay_buffer = intern ("display-buffer"); |
7091 | staticpro (&Qdisplay_buffer); | |
7092 | ||
2cccc823 | 7093 | Qtemp_buffer_show_hook = intern ("temp-buffer-show-hook"); |
a58ec57d RS |
7094 | staticpro (&Qtemp_buffer_show_hook); |
7095 | ||
67492200 | 7096 | staticpro (&Vwindow_list); |
8bfb170b KS |
7097 | |
7098 | minibuf_selected_window = Qnil; | |
3dbab091 | 7099 | staticpro (&minibuf_selected_window); |
67492200 | 7100 | |
c876b227 | 7101 | window_scroll_pixel_based_preserve_x = -1; |
66fe93d1 | 7102 | window_scroll_pixel_based_preserve_y = -1; |
c876b227 SM |
7103 | window_scroll_preserve_hpos = -1; |
7104 | window_scroll_preserve_vpos = -1; | |
66d43aea | 7105 | |
7ab12479 | 7106 | DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function, |
fdb82f93 PJ |
7107 | doc: /* Non-nil means call as function to display a help buffer. |
7108 | The function is called with one argument, the buffer to be displayed. | |
7109 | Used by `with-output-to-temp-buffer'. | |
7110 | If this function is used, then it must do the entire job of showing | |
7111 | the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */); | |
7ab12479 JB |
7112 | Vtemp_buffer_show_function = Qnil; |
7113 | ||
7ab12479 | 7114 | DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window, |
fdb82f93 | 7115 | doc: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */); |
7ab12479 JB |
7116 | Vminibuf_scroll_window = Qnil; |
7117 | ||
cc91894c | 7118 | DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows, |
26124d5e | 7119 | doc: /* Non-nil means to use `mode-line-inactive' face in non-selected windows. |
cc91894c KS |
7120 | If the minibuffer is active, the `minibuffer-scroll-window' mode line |
7121 | is displayed in the `mode-line' face. */); | |
7122 | mode_line_in_non_selected_windows = 1; | |
26124d5e | 7123 | |
7ab12479 | 7124 | DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer, |
fdb82f93 | 7125 | doc: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */); |
7ab12479 JB |
7126 | Vother_window_scroll_buffer = Qnil; |
7127 | ||
e56263e5 KS |
7128 | DEFVAR_BOOL ("auto-window-vscroll", &auto_window_vscroll_p, |
7129 | doc: /* *Non-nil means to automatically adjust `window-vscroll' to view tall lines. */); | |
7130 | auto_window_vscroll_p = 1; | |
7131 | ||
7ab12479 | 7132 | DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines, |
fdb82f93 | 7133 | doc: /* *Number of lines of continuity when scrolling by screenfuls. */); |
7ab12479 JB |
7134 | next_screen_context_lines = 2; |
7135 | ||
7ab12479 | 7136 | DEFVAR_INT ("window-min-height", &window_min_height, |
047aaeb9 MR |
7137 | doc: /* Allow deleting windows less than this tall. |
7138 | The value is measured in line units. If a window wants a modeline it | |
7139 | is counted as one line. | |
7140 | ||
7141 | Emacs honors settings of this variable when enlarging or shrinking | |
7142 | windows vertically. A value less than 1 is invalid. */); | |
7ab12479 JB |
7143 | window_min_height = 4; |
7144 | ||
7145 | DEFVAR_INT ("window-min-width", &window_min_width, | |
047aaeb9 MR |
7146 | doc: /* Allow deleting windows less than this wide. |
7147 | The value is measured in characters and includes any fringes or | |
7148 | the scrollbar. | |
7149 | ||
7150 | Emacs honors settings of this variable when enlarging or shrinking | |
7151 | windows horizontally. A value less than 2 is invalid. */); | |
7ab12479 JB |
7152 | window_min_width = 10; |
7153 | ||
5500c422 GM |
7154 | DEFVAR_LISP ("scroll-preserve-screen-position", |
7155 | &Vscroll_preserve_screen_position, | |
c876b227 | 7156 | doc: /* *Controls if scroll commands move point to keep its screen position unchanged. |
bdf4ec93 RS |
7157 | A value of nil means point does not keep its screen position except |
7158 | at the scroll margin or window boundary respectively. | |
7159 | A value of t means point keeps its screen position if the scroll | |
7160 | command moved it vertically out of the window, e.g. when scrolling | |
7161 | by full screens. | |
7162 | Any other value means point always keeps its screen position. */); | |
5500c422 | 7163 | Vscroll_preserve_screen_position = Qnil; |
9317a85d | 7164 | |
a1562258 SM |
7165 | DEFVAR_LISP ("window-point-insertion-type", &Vwindow_point_insertion_type, |
7166 | doc: /* Type of marker to use for `window-point'. */); | |
7167 | Vwindow_point_insertion_type = Qnil; | |
7168 | ||
543f5fb1 RS |
7169 | DEFVAR_LISP ("window-configuration-change-hook", |
7170 | &Vwindow_configuration_change_hook, | |
fdb82f93 | 7171 | doc: /* Functions to call when window configuration changes. |
6a44ffb3 SM |
7172 | The buffer-local part is run once per window, with the relevant window |
7173 | selected; while the global part is run only once for the modified frame, | |
7174 | with the relevant frame selected. */); | |
543f5fb1 RS |
7175 | Vwindow_configuration_change_hook = Qnil; |
7176 | ||
7ab12479 JB |
7177 | defsubr (&Sselected_window); |
7178 | defsubr (&Sminibuffer_window); | |
7179 | defsubr (&Swindow_minibuffer_p); | |
7180 | defsubr (&Swindowp); | |
806b4d9b | 7181 | defsubr (&Swindow_live_p); |
7ab12479 | 7182 | defsubr (&Spos_visible_in_window_p); |
536833ab | 7183 | defsubr (&Swindow_line_height); |
7ab12479 JB |
7184 | defsubr (&Swindow_buffer); |
7185 | defsubr (&Swindow_height); | |
7186 | defsubr (&Swindow_width); | |
35ea56c9 | 7187 | defsubr (&Swindow_full_width_p); |
7ab12479 JB |
7188 | defsubr (&Swindow_hscroll); |
7189 | defsubr (&Sset_window_hscroll); | |
190eb263 RS |
7190 | defsubr (&Swindow_redisplay_end_trigger); |
7191 | defsubr (&Sset_window_redisplay_end_trigger); | |
7ab12479 | 7192 | defsubr (&Swindow_edges); |
c99a9eb3 RS |
7193 | defsubr (&Swindow_pixel_edges); |
7194 | defsubr (&Swindow_inside_edges); | |
7195 | defsubr (&Swindow_inside_pixel_edges); | |
d5783c40 JB |
7196 | defsubr (&Scoordinates_in_window_p); |
7197 | defsubr (&Swindow_at); | |
7ab12479 JB |
7198 | defsubr (&Swindow_point); |
7199 | defsubr (&Swindow_start); | |
7200 | defsubr (&Swindow_end); | |
7201 | defsubr (&Sset_window_point); | |
7202 | defsubr (&Sset_window_start); | |
7203 | defsubr (&Swindow_dedicated_p); | |
d207b766 | 7204 | defsubr (&Sset_window_dedicated_p); |
7ab12479 JB |
7205 | defsubr (&Swindow_display_table); |
7206 | defsubr (&Sset_window_display_table); | |
7207 | defsubr (&Snext_window); | |
7208 | defsubr (&Sprevious_window); | |
7209 | defsubr (&Sother_window); | |
7210 | defsubr (&Sget_lru_window); | |
7211 | defsubr (&Sget_largest_window); | |
7212 | defsubr (&Sget_buffer_window); | |
7213 | defsubr (&Sdelete_other_windows); | |
7214 | defsubr (&Sdelete_windows_on); | |
7215 | defsubr (&Sreplace_buffer_in_windows); | |
7216 | defsubr (&Sdelete_window); | |
7217 | defsubr (&Sset_window_buffer); | |
7218 | defsubr (&Sselect_window); | |
6b61353c | 7219 | defsubr (&Sforce_window_update); |
7ab12479 JB |
7220 | defsubr (&Ssplit_window); |
7221 | defsubr (&Senlarge_window); | |
7222 | defsubr (&Sshrink_window); | |
0d384044 | 7223 | defsubr (&Sadjust_window_trailing_edge); |
7ab12479 JB |
7224 | defsubr (&Sscroll_up); |
7225 | defsubr (&Sscroll_down); | |
7226 | defsubr (&Sscroll_left); | |
7227 | defsubr (&Sscroll_right); | |
ccd0664b | 7228 | defsubr (&Sother_window_for_scrolling); |
7ab12479 | 7229 | defsubr (&Sscroll_other_window); |
fa832261 | 7230 | defsubr (&Sminibuffer_selected_window); |
7ab12479 | 7231 | defsubr (&Srecenter); |
81fe0836 | 7232 | defsubr (&Swindow_text_height); |
7ab12479 JB |
7233 | defsubr (&Smove_to_window_line); |
7234 | defsubr (&Swindow_configuration_p); | |
3f8ab7bd | 7235 | defsubr (&Swindow_configuration_frame); |
7ab12479 JB |
7236 | defsubr (&Sset_window_configuration); |
7237 | defsubr (&Scurrent_window_configuration); | |
7238 | defsubr (&Ssave_window_excursion); | |
c16e1cc3 | 7239 | defsubr (&Swindow_tree); |
5500c422 GM |
7240 | defsubr (&Sset_window_margins); |
7241 | defsubr (&Swindow_margins); | |
949cf20f KS |
7242 | defsubr (&Sset_window_fringes); |
7243 | defsubr (&Swindow_fringes); | |
7244 | defsubr (&Sset_window_scroll_bars); | |
7245 | defsubr (&Swindow_scroll_bars); | |
5500c422 GM |
7246 | defsubr (&Swindow_vscroll); |
7247 | defsubr (&Sset_window_vscroll); | |
2f8274be | 7248 | defsubr (&Scompare_window_configurations); |
67492200 | 7249 | defsubr (&Swindow_list); |
cfbb2395 JB |
7250 | defsubr (&Swindow_parameters); |
7251 | defsubr (&Swindow_parameter); | |
7252 | defsubr (&Sset_window_parameter); | |
7253 | ||
7ab12479 JB |
7254 | } |
7255 | ||
dfcf069d | 7256 | void |
7ab12479 JB |
7257 | keys_of_window () |
7258 | { | |
7259 | initial_define_key (control_x_map, '1', "delete-other-windows"); | |
7260 | initial_define_key (control_x_map, '2', "split-window"); | |
7261 | initial_define_key (control_x_map, '0', "delete-window"); | |
7262 | initial_define_key (control_x_map, 'o', "other-window"); | |
7263 | initial_define_key (control_x_map, '^', "enlarge-window"); | |
7264 | initial_define_key (control_x_map, '<', "scroll-left"); | |
7265 | initial_define_key (control_x_map, '>', "scroll-right"); | |
7266 | ||
7267 | initial_define_key (global_map, Ctl ('V'), "scroll-up"); | |
7268 | initial_define_key (meta_map, Ctl ('V'), "scroll-other-window"); | |
7269 | initial_define_key (meta_map, 'v', "scroll-down"); | |
7270 | ||
7271 | initial_define_key (global_map, Ctl('L'), "recenter"); | |
7272 | initial_define_key (meta_map, 'r', "move-to-window-line"); | |
7273 | } | |
6b61353c KH |
7274 | |
7275 | /* arch-tag: 90a9c576-0590-48f1-a5f1-6c96a0452d9f | |
2c2cd782 | 7276 | (do not change this comment) */ |