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