Commit | Line | Data |
---|---|---|
7ab12479 JB |
1 | /* Window creation, deletion and examination for GNU Emacs. |
2 | Does not include redisplay. | |
4a2f9c6a | 3 | Copyright (C) 1985,86,87,93,94,95,96,97,1998 Free Software Foundation, Inc. |
7ab12479 JB |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
7 | GNU Emacs is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
1113d9db | 9 | the Free Software Foundation; either version 2, or (at your option) |
7ab12479 JB |
10 | any later version. |
11 | ||
12 | GNU Emacs is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU Emacs; see the file COPYING. If not, write to | |
3b7ad313 EN |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
7ab12479 | 21 | |
18160b98 | 22 | #include <config.h> |
7ab12479 JB |
23 | #include "lisp.h" |
24 | #include "buffer.h" | |
44fa5b1e | 25 | #include "frame.h" |
7ab12479 JB |
26 | #include "window.h" |
27 | #include "commands.h" | |
28 | #include "indent.h" | |
29 | #include "termchar.h" | |
30 | #include "disptab.h" | |
f8026fd8 | 31 | #include "keyboard.h" |
dfcf069d | 32 | #include "dispextern.h" |
5500c422 GM |
33 | #include "blockinput.h" |
34 | #include "intervals.h" | |
35 | ||
6d55d620 | 36 | #ifdef HAVE_X_WINDOWS |
dfcf069d | 37 | #include "xterm.h" |
5500c422 GM |
38 | #endif /* HAVE_X_WINDOWS */ |
39 | ||
40 | #ifndef max | |
41 | #define max(a, b) ((a) < (b) ? (b) : (a)) | |
dfcf069d | 42 | #endif |
7ab12479 | 43 | |
5500c422 | 44 | |
3f8ab7bd | 45 | Lisp_Object Qwindowp, Qwindow_live_p, Qwindow_configuration_p; |
fbad6f9a | 46 | Lisp_Object Qfixed_window_size, Qleft_bitmap_area, Qright_bitmap_area; |
233a4a2c | 47 | extern Lisp_Object Qheight, Qwidth; |
7ab12479 | 48 | |
5e14b1fc | 49 | static struct window *decode_window P_ ((Lisp_Object)); |
b7354ddf | 50 | static Lisp_Object select_window_1 P_ ((Lisp_Object, int)); |
5500c422 GM |
51 | static int count_windows P_ ((struct window *)); |
52 | static int get_leaf_windows P_ ((struct window *, struct window **, int)); | |
53 | static void window_scroll P_ ((Lisp_Object, int, int, int)); | |
54 | static void window_scroll_pixel_based P_ ((Lisp_Object, int, int, int)); | |
55 | static void window_scroll_line_based P_ ((Lisp_Object, int, int, int)); | |
233a4a2c GM |
56 | static int window_min_size_1 P_ ((struct window *, int)); |
57 | static int window_min_size P_ ((struct window *, int, int *)); | |
58 | static int window_fixed_size_p P_ ((struct window *, int, int)); | |
59 | static void size_window P_ ((Lisp_Object, int, int, int)); | |
5500c422 | 60 | |
b7354ddf | 61 | |
7ab12479 JB |
62 | /* This is the window in which the terminal's cursor should |
63 | be left when nothing is being done with it. This must | |
64 | always be a leaf window, and its buffer is selected by | |
65 | the top level editing loop at the end of each command. | |
66 | ||
67 | This value is always the same as | |
44fa5b1e | 68 | FRAME_SELECTED_WINDOW (selected_frame). */ |
7ab12479 JB |
69 | |
70 | Lisp_Object selected_window; | |
71 | ||
5500c422 GM |
72 | /* The mini-buffer window of the selected frame. |
73 | Note that you cannot test for mini-bufferness of an arbitrary window | |
74 | by comparing against this; but you can test for mini-bufferness of | |
7ab12479 | 75 | the selected window. */ |
5500c422 | 76 | |
7ab12479 JB |
77 | Lisp_Object minibuf_window; |
78 | ||
79 | /* Non-nil means it is the window for C-M-v to scroll | |
5500c422 GM |
80 | when the mini-buffer is selected. */ |
81 | ||
7ab12479 JB |
82 | Lisp_Object Vminibuf_scroll_window; |
83 | ||
84 | /* Non-nil means this is the buffer whose window C-M-v should scroll. */ | |
5500c422 | 85 | |
7ab12479 JB |
86 | Lisp_Object Vother_window_scroll_buffer; |
87 | ||
7ab12479 | 88 | /* Non-nil means it's function to call to display temp buffers. */ |
5500c422 | 89 | |
7ab12479 JB |
90 | Lisp_Object Vtemp_buffer_show_function; |
91 | ||
92 | /* If a window gets smaller than either of these, it is removed. */ | |
5500c422 | 93 | |
7ab12479 JB |
94 | int window_min_height; |
95 | int window_min_width; | |
96 | ||
97 | /* Nonzero implies Fdisplay_buffer should create windows. */ | |
5500c422 | 98 | |
7ab12479 JB |
99 | int pop_up_windows; |
100 | ||
44fa5b1e | 101 | /* Nonzero implies make new frames for Fdisplay_buffer. */ |
5500c422 | 102 | |
44fa5b1e | 103 | int pop_up_frames; |
7ab12479 JB |
104 | |
105 | /* Non-nil means use this function instead of default */ | |
5500c422 | 106 | |
44fa5b1e | 107 | Lisp_Object Vpop_up_frame_function; |
7ab12479 JB |
108 | |
109 | /* Function to call to handle Fdisplay_buffer. */ | |
5500c422 | 110 | |
7ab12479 JB |
111 | Lisp_Object Vdisplay_buffer_function; |
112 | ||
a90712c2 | 113 | /* List of buffer *names* for buffers that should have their own frames. */ |
5500c422 | 114 | |
a90712c2 RS |
115 | Lisp_Object Vspecial_display_buffer_names; |
116 | ||
117 | /* List of regexps for buffer names that should have their own frames. */ | |
5500c422 | 118 | |
a90712c2 RS |
119 | Lisp_Object Vspecial_display_regexps; |
120 | ||
121 | /* Function to pop up a special frame. */ | |
5500c422 | 122 | |
a90712c2 RS |
123 | Lisp_Object Vspecial_display_function; |
124 | ||
855d8627 | 125 | /* List of buffer *names* for buffers to appear in selected window. */ |
5500c422 | 126 | |
855d8627 RS |
127 | Lisp_Object Vsame_window_buffer_names; |
128 | ||
129 | /* List of regexps for buffer names to appear in selected window. */ | |
5500c422 | 130 | |
855d8627 RS |
131 | Lisp_Object Vsame_window_regexps; |
132 | ||
a58ec57d | 133 | /* Hook run at end of temp_output_buffer_show. */ |
5500c422 | 134 | |
a58ec57d RS |
135 | Lisp_Object Qtemp_buffer_show_hook; |
136 | ||
37962e60 | 137 | /* Fdisplay_buffer always splits the largest window |
7ab12479 | 138 | if that window is more than this high. */ |
5500c422 | 139 | |
7ab12479 JB |
140 | int split_height_threshold; |
141 | ||
142 | /* Number of lines of continuity in scrolling by screenfuls. */ | |
5500c422 | 143 | |
7ab12479 JB |
144 | int next_screen_context_lines; |
145 | ||
146 | /* Incremented for each window created. */ | |
5500c422 | 147 | |
7ab12479 JB |
148 | static int sequence_number; |
149 | ||
5b03d3c0 | 150 | /* Nonzero after init_window_once has finished. */ |
5500c422 | 151 | |
5b03d3c0 RS |
152 | static int window_initialized; |
153 | ||
543f5fb1 | 154 | /* Hook to run when window config changes. */ |
5500c422 | 155 | |
543f5fb1 RS |
156 | Lisp_Object Qwindow_configuration_change_hook; |
157 | Lisp_Object Vwindow_configuration_change_hook; | |
158 | ||
9317a85d RS |
159 | /* Nonzero means scroll commands try to put point |
160 | at the same screen height as previously. */ | |
9317a85d | 161 | |
5500c422 GM |
162 | Lisp_Object Vscroll_preserve_screen_position; |
163 | ||
164 | #if 0 /* This isn't used anywhere. */ | |
91a78190 | 165 | /* Nonzero means we can split a frame even if it is "unsplittable". */ |
eddd51c2 | 166 | static int inhibit_frame_unsplittable; |
5500c422 | 167 | #endif /* 0 */ |
7d601aaa | 168 | |
7ab12479 | 169 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
dba06815 | 170 | |
9317a85d RS |
171 | extern int scroll_margin; |
172 | ||
dba06815 | 173 | extern Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions; |
7ab12479 JB |
174 | \f |
175 | DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0, | |
413430c5 EN |
176 | "Returns t if OBJECT is a window.") |
177 | (object) | |
178 | Lisp_Object object; | |
7ab12479 | 179 | { |
413430c5 | 180 | return WINDOWP (object) ? Qt : Qnil; |
7ab12479 JB |
181 | } |
182 | ||
806b4d9b | 183 | DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0, |
413430c5 EN |
184 | "Returns t if OBJECT is a window which is currently visible.") |
185 | (object) | |
186 | Lisp_Object object; | |
605be8af | 187 | { |
413430c5 | 188 | return (WINDOWP (object) && ! NILP (XWINDOW (object)->buffer) ? Qt : Qnil); |
605be8af JB |
189 | } |
190 | ||
7ab12479 JB |
191 | Lisp_Object |
192 | make_window () | |
193 | { | |
cffec418 | 194 | Lisp_Object val; |
7ab12479 | 195 | register struct window *p; |
cffec418 KH |
196 | register struct Lisp_Vector *vec; |
197 | int i; | |
198 | ||
199 | vec = allocate_vectorlike ((EMACS_INT) VECSIZE (struct window)); | |
200 | for (i = 0; i < VECSIZE (struct window); i++) | |
201 | vec->contents[i] = Qnil; | |
202 | vec->size = VECSIZE (struct window); | |
5500c422 | 203 | p = (struct window *) vec; |
d834a2e9 KH |
204 | XSETFASTINT (p->sequence_number, ++sequence_number); |
205 | XSETFASTINT (p->left, 0); | |
206 | XSETFASTINT (p->top, 0); | |
207 | XSETFASTINT (p->height, 0); | |
208 | XSETFASTINT (p->width, 0); | |
209 | XSETFASTINT (p->hscroll, 0); | |
7ab12479 JB |
210 | p->start = Fmake_marker (); |
211 | p->pointm = Fmake_marker (); | |
d834a2e9 | 212 | XSETFASTINT (p->use_time, 0); |
44fa5b1e | 213 | p->frame = Qnil; |
7ab12479 JB |
214 | p->display_table = Qnil; |
215 | p->dedicated = Qnil; | |
5500c422 GM |
216 | p->pseudo_window_p = 0; |
217 | bzero (&p->cursor, sizeof (p->cursor)); | |
218 | bzero (&p->last_cursor, sizeof (p->last_cursor)); | |
219 | bzero (&p->phys_cursor, sizeof (p->phys_cursor)); | |
220 | p->desired_matrix = p->current_matrix = 0; | |
221 | p->phys_cursor_type = -1; | |
222 | p->must_be_updated_p = 0; | |
223 | XSETFASTINT (p->window_end_vpos, 0); | |
224 | XSETFASTINT (p->window_end_pos, 0); | |
225 | p->window_end_valid = Qnil; | |
226 | p->vscroll = 0; | |
cffec418 | 227 | XSETWINDOW (val, p); |
5500c422 | 228 | XSETFASTINT (p->last_point, 0); |
7ab12479 JB |
229 | return val; |
230 | } | |
231 | ||
232 | DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0, | |
233 | "Return the window that the cursor now appears in and commands apply to.") | |
234 | () | |
235 | { | |
236 | return selected_window; | |
237 | } | |
238 | ||
83762ba4 JB |
239 | DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0, |
240 | "Return the window used now for minibuffers.\n\ | |
241 | If the optional argument FRAME is specified, return the minibuffer window\n\ | |
242 | used by that frame.") | |
243 | (frame) | |
244 | Lisp_Object frame; | |
7ab12479 | 245 | { |
83762ba4 | 246 | if (NILP (frame)) |
74112613 | 247 | XSETFRAME (frame, selected_frame); |
83762ba4 JB |
248 | else |
249 | CHECK_LIVE_FRAME (frame, 0); | |
83762ba4 JB |
250 | |
251 | return FRAME_MINIBUF_WINDOW (XFRAME (frame)); | |
7ab12479 JB |
252 | } |
253 | ||
605be8af | 254 | DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, Swindow_minibuffer_p, 0, 1, 0, |
7ab12479 JB |
255 | "Returns non-nil if WINDOW is a minibuffer window.") |
256 | (window) | |
257 | Lisp_Object window; | |
258 | { | |
259 | struct window *w = decode_window (window); | |
260 | return (MINI_WINDOW_P (w) ? Qt : Qnil); | |
261 | } | |
262 | ||
263 | DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p, | |
264 | Spos_visible_in_window_p, 0, 2, 0, | |
44fa5b1e | 265 | "Return t if position POS is currently on the frame in WINDOW.\n\ |
7ab12479 JB |
266 | Returns nil if that position is scrolled vertically out of view.\n\ |
267 | POS defaults to point; WINDOW, to the selected window.") | |
268 | (pos, window) | |
269 | Lisp_Object pos, window; | |
270 | { | |
271 | register struct window *w; | |
7ab12479 JB |
272 | register int posint; |
273 | register struct buffer *buf; | |
9a132b1f GM |
274 | struct text_pos top; |
275 | Lisp_Object in_window; | |
7ab12479 | 276 | |
265a9e55 | 277 | if (NILP (pos)) |
5ce7b543 | 278 | posint = PT; |
7ab12479 JB |
279 | else |
280 | { | |
281 | CHECK_NUMBER_COERCE_MARKER (pos, 0); | |
282 | posint = XINT (pos); | |
283 | } | |
284 | ||
605be8af | 285 | w = decode_window (window); |
9a132b1f | 286 | buf = XBUFFER (w->buffer); |
5500c422 | 287 | SET_TEXT_POS_FROM_MARKER (top, w->start); |
7ab12479 | 288 | |
5500c422 GM |
289 | /* If position above window, it's not visible. */ |
290 | if (posint < CHARPOS (top)) | |
9a132b1f GM |
291 | in_window = Qnil; |
292 | else if (XFASTINT (w->last_modified) >= BUF_MODIFF (buf) | |
293 | && XFASTINT (w->last_overlay_modified) >= BUF_OVERLAY_MODIFF (buf) | |
294 | && posint < BUF_Z (buf) - XFASTINT (w->window_end_pos)) | |
295 | /* If frame is up to date, and POSINT is < window end pos, use | |
296 | that info. This doesn't work for POSINT == end pos, because | |
297 | the window end pos is actually the position _after_ the last | |
298 | char in the window. */ | |
299 | in_window = Qt; | |
300 | else if (posint > BUF_ZV (buf)) | |
301 | in_window = Qnil; | |
302 | else if (CHARPOS (top) < BUF_BEGV (buf) || CHARPOS (top) > BUF_ZV (buf)) | |
303 | /* If window start is out of range, do something reasonable. */ | |
304 | in_window = Qnil; | |
7ab12479 JB |
305 | else |
306 | { | |
5500c422 | 307 | struct it it; |
5500c422 GM |
308 | start_display (&it, w, top); |
309 | move_it_to (&it, posint, 0, it.last_visible_y, -1, | |
9a132b1f GM |
310 | MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y); |
311 | in_window = IT_CHARPOS (it) == posint ? Qt : Qnil; | |
7ab12479 | 312 | } |
9a132b1f GM |
313 | |
314 | return in_window; | |
7ab12479 JB |
315 | } |
316 | \f | |
317 | static struct window * | |
318 | decode_window (window) | |
319 | register Lisp_Object window; | |
320 | { | |
265a9e55 | 321 | if (NILP (window)) |
7ab12479 JB |
322 | return XWINDOW (selected_window); |
323 | ||
605be8af | 324 | CHECK_LIVE_WINDOW (window, 0); |
7ab12479 JB |
325 | return XWINDOW (window); |
326 | } | |
327 | ||
328 | DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0, | |
329 | "Return the buffer that WINDOW is displaying.") | |
330 | (window) | |
331 | Lisp_Object window; | |
332 | { | |
333 | return decode_window (window)->buffer; | |
334 | } | |
335 | ||
336 | DEFUN ("window-height", Fwindow_height, Swindow_height, 0, 1, 0, | |
337 | "Return the number of lines in WINDOW (including its mode line).") | |
338 | (window) | |
339 | Lisp_Object window; | |
340 | { | |
341 | return decode_window (window)->height; | |
342 | } | |
343 | ||
344 | DEFUN ("window-width", Fwindow_width, Swindow_width, 0, 1, 0, | |
3b5908ef RS |
345 | "Return the number of display columns in WINDOW.\n\ |
346 | This is the width that is usable columns available for text in WINDOW.\n\ | |
347 | If you want to find out how many columns WINDOW takes up,\n\ | |
348 | use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))).") | |
7ab12479 JB |
349 | (window) |
350 | Lisp_Object window; | |
351 | { | |
ee61d94e | 352 | return make_number (window_internal_width (decode_window (window))); |
7ab12479 JB |
353 | } |
354 | ||
355 | DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0, | |
356 | "Return the number of columns by which WINDOW is scrolled from left margin.") | |
357 | (window) | |
358 | Lisp_Object window; | |
359 | { | |
360 | return decode_window (window)->hscroll; | |
361 | } | |
362 | ||
363 | DEFUN ("set-window-hscroll", Fset_window_hscroll, Sset_window_hscroll, 2, 2, 0, | |
364 | "Set number of columns WINDOW is scrolled from left margin to NCOL.\n\ | |
365 | NCOL should be zero or positive.") | |
366 | (window, ncol) | |
367 | register Lisp_Object window, ncol; | |
368 | { | |
369 | register struct window *w; | |
370 | ||
371 | CHECK_NUMBER (ncol, 1); | |
d834a2e9 | 372 | if (XINT (ncol) < 0) XSETFASTINT (ncol, 0); |
7ab12479 | 373 | w = decode_window (window); |
7f4161e0 | 374 | if (XINT (w->hscroll) != XINT (ncol)) |
1479ef51 | 375 | XBUFFER (w->buffer)->clip_changed = 1; /* Prevent redisplay shortcuts */ |
7ab12479 JB |
376 | w->hscroll = ncol; |
377 | return ncol; | |
378 | } | |
379 | ||
190eb263 RS |
380 | DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger, |
381 | Swindow_redisplay_end_trigger, 0, 1, 0, | |
382 | "Return WINDOW's redisplay end trigger value.\n\ | |
383 | See `set-window-redisplay-end-trigger' for more information.") | |
384 | (window) | |
385 | Lisp_Object window; | |
386 | { | |
387 | return decode_window (window)->redisplay_end_trigger; | |
388 | } | |
389 | ||
390 | DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger, | |
391 | Sset_window_redisplay_end_trigger, 2, 2, 0, | |
392 | "Set WINDOW's redisplay end trigger value to VALUE.\n\ | |
393 | VALUE should be a buffer position (typically a marker) or nil.\n\ | |
76854cf2 RS |
394 | If it is a buffer position, then if redisplay in WINDOW reaches a position\n\ |
395 | beyond VALUE, the functions in `redisplay-end-trigger-functions' are called\n\ | |
396 | with two arguments: WINDOW, and the end trigger value.\n\ | |
397 | Afterwards the end-trigger value is reset to nil.") | |
190eb263 RS |
398 | (window, value) |
399 | register Lisp_Object window, value; | |
400 | { | |
401 | register struct window *w; | |
402 | ||
403 | w = decode_window (window); | |
404 | w->redisplay_end_trigger = value; | |
405 | return value; | |
406 | } | |
407 | ||
7ab12479 JB |
408 | DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0, |
409 | "Return a list of the edge coordinates of WINDOW.\n\ | |
44fa5b1e | 410 | \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.\n\ |
7ab12479 JB |
411 | RIGHT is one more than the rightmost column used by WINDOW,\n\ |
412 | and BOTTOM is one more than the bottommost row used by WINDOW\n\ | |
413 | and its mode-line.") | |
414 | (window) | |
415 | Lisp_Object window; | |
416 | { | |
417 | register struct window *w = decode_window (window); | |
418 | ||
419 | return Fcons (w->left, Fcons (w->top, | |
111e5992 | 420 | Fcons (make_number (WINDOW_RIGHT_EDGE (w)), |
7ab12479 JB |
421 | Fcons (make_number (XFASTINT (w->top) |
422 | + XFASTINT (w->height)), | |
423 | Qnil)))); | |
424 | } | |
425 | ||
fbad6f9a | 426 | /* Test if the character at column *X, row *Y is within window W. |
d5783c40 JB |
427 | If it is not, return 0; |
428 | if it is in the window's text area, | |
429 | set *x and *y to its location relative to the upper left corner | |
430 | of the window, and | |
431 | return 1; | |
432 | if it is on the window's modeline, return 2; | |
433 | if it is on the border between the window and its right sibling, | |
5500c422 GM |
434 | return 3. |
435 | if it is on the window's top line, return 4; | |
fbad6f9a GM |
436 | if it is in the bitmap area to the left/right of the window, |
437 | return 5 or 6, and convert *X and *Y to window-relative corrdinates. | |
5500c422 GM |
438 | |
439 | X and Y are frame relative pixel coordinates. */ | |
440 | ||
d5783c40 JB |
441 | static int |
442 | coordinates_in_window (w, x, y) | |
443 | register struct window *w; | |
444 | register int *x, *y; | |
445 | { | |
5500c422 GM |
446 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
447 | int left_x, right_x, top_y, bottom_y; | |
448 | int flags_area_width = FRAME_FLAGS_AREA_WIDTH (f); | |
d5783c40 | 449 | |
5500c422 GM |
450 | if (w->pseudo_window_p) |
451 | { | |
452 | left_x = 0; | |
453 | right_x = XFASTINT (w->width) * CANON_Y_UNIT (f); | |
454 | top_y = WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w); | |
455 | bottom_y = WINDOW_DISPLAY_BOTTOM_EDGE_PIXEL_Y (w); | |
456 | } | |
457 | else | |
458 | { | |
459 | left_x = WINDOW_DISPLAY_LEFT_EDGE_PIXEL_X (w); | |
460 | right_x = WINDOW_DISPLAY_RIGHT_EDGE_PIXEL_X (w); | |
461 | top_y = WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w); | |
462 | bottom_y = WINDOW_DISPLAY_BOTTOM_EDGE_PIXEL_Y (w); | |
463 | } | |
37962e60 | 464 | |
5500c422 GM |
465 | if (*y < top_y |
466 | || *y >= bottom_y | |
467 | || *x < (left_x | |
468 | - flags_area_width | |
469 | - (FRAME_LEFT_SCROLL_BAR_WIDTH (f) | |
470 | * CANON_X_UNIT (f))) | |
471 | || *x > right_x + flags_area_width) | |
472 | /* Completely outside anything interesting. */ | |
473 | return 0; | |
474 | else if (WINDOW_WANTS_MODELINE_P (w) | |
475 | && *y >= bottom_y - CURRENT_MODE_LINE_HEIGHT (w)) | |
476 | /* On the mode line. */ | |
477 | return 2; | |
478 | else if (WINDOW_WANTS_TOP_LINE_P (w) | |
479 | && *y < top_y + CURRENT_TOP_LINE_HEIGHT (w)) | |
480 | /* On the top line. */ | |
481 | return 4; | |
482 | else if (*x < left_x || *x >= right_x) | |
fbad6f9a GM |
483 | { |
484 | /* Other lines than the mode line don't include flags areas and | |
485 | scroll bars on the left. */ | |
486 | ||
487 | /* Convert X and Y to window-relative pixel coordinates. */ | |
488 | *x -= left_x; | |
489 | *y -= top_y; | |
490 | return *x < left_x ? 5 : 6; | |
491 | } | |
5500c422 GM |
492 | else if (!w->pseudo_window_p |
493 | && !WINDOW_RIGHTMOST_P (w) | |
494 | && *x >= right_x - CANON_X_UNIT (f)) | |
495 | /* On the border on the right side of the window? Assume that | |
496 | this area begins at RIGHT_X minus a canonical char width. */ | |
497 | return 3; | |
498 | else | |
499 | { | |
500 | /* Convert X and Y to window-relative pixel coordinates. */ | |
501 | *x -= left_x; | |
502 | *y -= top_y; | |
503 | return 1; | |
504 | } | |
d5783c40 JB |
505 | } |
506 | ||
507 | DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p, | |
508 | Scoordinates_in_window_p, 2, 2, 0, | |
509 | "Return non-nil if COORDINATES are in WINDOW.\n\ | |
1113d9db | 510 | COORDINATES is a cons of the form (X . Y), X and Y being distances\n\ |
44fa5b1e | 511 | measured in characters from the upper-left corner of the frame.\n\ |
1113d9db | 512 | (0 . 0) denotes the character in the upper left corner of the\n\ |
44fa5b1e | 513 | frame.\n\ |
d5783c40 JB |
514 | If COORDINATES are in the text portion of WINDOW,\n\ |
515 | the coordinates relative to the window are returned.\n\ | |
e5d77022 | 516 | If they are in the mode line of WINDOW, `mode-line' is returned.\n\ |
5500c422 | 517 | If they are in the top mode line of WINDOW, `top-line' is returned.\n\ |
fbad6f9a GM |
518 | If they are in the bitmap-area to the left of the window,\n\ |
519 | `left-bitmap-area' is returned, if they are in the area on the right of\n\ | |
520 | the window, `right-bitmap-area' is returned.\n\ | |
d5783c40 | 521 | If they are on the border between WINDOW and its right sibling,\n\ |
e5d77022 | 522 | `vertical-line' is returned.") |
d5783c40 JB |
523 | (coordinates, window) |
524 | register Lisp_Object coordinates, window; | |
525 | { | |
5500c422 GM |
526 | struct window *w; |
527 | struct frame *f; | |
d5783c40 | 528 | int x, y; |
5500c422 | 529 | Lisp_Object lx, ly; |
d5783c40 | 530 | |
605be8af | 531 | CHECK_LIVE_WINDOW (window, 0); |
5500c422 GM |
532 | w = XWINDOW (window); |
533 | f = XFRAME (w->frame); | |
d5783c40 | 534 | CHECK_CONS (coordinates, 1); |
5500c422 GM |
535 | lx = Fcar (coordinates); |
536 | ly = Fcdr (coordinates); | |
537 | CHECK_NUMBER_OR_FLOAT (lx, 1); | |
538 | CHECK_NUMBER_OR_FLOAT (ly, 1); | |
539 | x = PIXEL_X_FROM_CANON_X (f, lx); | |
540 | y = PIXEL_Y_FROM_CANON_Y (f, ly); | |
541 | ||
542 | switch (coordinates_in_window (w, &x, &y)) | |
d5783c40 JB |
543 | { |
544 | case 0: /* NOT in window at all. */ | |
545 | return Qnil; | |
546 | ||
547 | case 1: /* In text part of window. */ | |
5500c422 GM |
548 | /* X and Y are now window relative pixel coordinates. |
549 | Convert them to canonical char units before returning | |
550 | them. */ | |
551 | return Fcons (CANON_X_FROM_PIXEL_X (f, x), | |
552 | CANON_Y_FROM_PIXEL_Y (f, y)); | |
d5783c40 JB |
553 | |
554 | case 2: /* In mode line of window. */ | |
555 | return Qmode_line; | |
37962e60 | 556 | |
d5783c40 | 557 | case 3: /* On right border of window. */ |
e5d77022 | 558 | return Qvertical_line; |
d5783c40 | 559 | |
5500c422 GM |
560 | case 4: |
561 | return Qtop_line; | |
562 | ||
fbad6f9a GM |
563 | case 5: |
564 | return Qleft_bitmap_area; | |
565 | ||
566 | case 6: | |
567 | return Qright_bitmap_area; | |
568 | ||
d5783c40 JB |
569 | default: |
570 | abort (); | |
571 | } | |
572 | } | |
573 | ||
5500c422 GM |
574 | /* Find the window containing frame-relative pixel position X/Y and |
575 | return it as a Lisp_Object. If X, Y is on the window's modeline, | |
576 | set *PART to 1; if it is on the separating line between the window | |
577 | and its right sibling, set it to 2; otherwise set it to 0. If | |
578 | there is no window under X, Y return nil and leave *PART | |
579 | unmodified. TOOLBAR_P non-zero means detect toolbar windows. */ | |
580 | ||
7ab12479 | 581 | Lisp_Object |
5500c422 | 582 | window_from_coordinates (frame, x, y, part, toolbar_p) |
44fa5b1e | 583 | FRAME_PTR frame; |
7ab12479 | 584 | int x, y; |
d5783c40 | 585 | int *part; |
5500c422 | 586 | int toolbar_p; |
7ab12479 JB |
587 | { |
588 | register Lisp_Object tem, first; | |
5500c422 | 589 | int found; |
7ab12479 | 590 | |
44fa5b1e | 591 | tem = first = FRAME_SELECTED_WINDOW (frame); |
7ab12479 | 592 | |
d5783c40 | 593 | do |
7ab12479 | 594 | { |
5500c422 | 595 | found = coordinates_in_window (XWINDOW (tem), &x, &y); |
7ab12479 JB |
596 | |
597 | if (found) | |
598 | { | |
d5783c40 | 599 | *part = found - 1; |
7ab12479 JB |
600 | return tem; |
601 | } | |
602 | ||
d5783c40 | 603 | tem = Fnext_window (tem, Qt, Qlambda); |
7ab12479 | 604 | } |
5500c422 GM |
605 | while (!EQ (tem, first)); |
606 | ||
607 | /* See if it's in the toolbar window, if a toolbar exists. */ | |
608 | if (toolbar_p | |
609 | && WINDOWP (frame->toolbar_window) | |
610 | && XFASTINT (XWINDOW (frame->toolbar_window)->height) | |
611 | && coordinates_in_window (XWINDOW (frame->toolbar_window), &x, &y)) | |
612 | { | |
613 | *part = 0; | |
614 | return frame->toolbar_window; | |
615 | } | |
37962e60 | 616 | |
d5783c40 | 617 | return Qnil; |
7ab12479 JB |
618 | } |
619 | ||
ab17c3f2 | 620 | DEFUN ("window-at", Fwindow_at, Swindow_at, 2, 3, 0, |
b0c33a94 | 621 | "Return window containing coordinates X and Y on FRAME.\n\ |
44fa5b1e JB |
622 | If omitted, FRAME defaults to the currently selected frame.\n\ |
623 | The top left corner of the frame is considered to be row 0,\n\ | |
95605e15 | 624 | column 0.") |
b0c33a94 RS |
625 | (x, y, frame) |
626 | Lisp_Object x, y, frame; | |
7ab12479 JB |
627 | { |
628 | int part; | |
5500c422 | 629 | struct frame *f; |
7ab12479 | 630 | |
44fa5b1e | 631 | if (NILP (frame)) |
74112613 | 632 | XSETFRAME (frame, selected_frame); |
d5783c40 | 633 | else |
44fa5b1e | 634 | CHECK_LIVE_FRAME (frame, 2); |
5500c422 | 635 | f = XFRAME (frame); |
7ab12479 | 636 | |
5500c422 GM |
637 | /* Check that arguments are integers or floats. */ |
638 | CHECK_NUMBER_OR_FLOAT (x, 0); | |
639 | CHECK_NUMBER_OR_FLOAT (y, 1); | |
640 | ||
641 | return window_from_coordinates (f, | |
642 | PIXEL_X_FROM_CANON_X (f, x), | |
643 | PIXEL_Y_FROM_CANON_Y (f, y), | |
644 | &part, 0); | |
7ab12479 JB |
645 | } |
646 | ||
647 | DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0, | |
648 | "Return current value of point in WINDOW.\n\ | |
649 | For a nonselected window, this is the value point would have\n\ | |
650 | if that window were selected.\n\ | |
651 | \n\ | |
652 | Note that, when WINDOW is the selected window and its buffer\n\ | |
653 | is also currently selected, the value returned is the same as (point).\n\ | |
654 | It would be more strictly correct to return the `top-level' value\n\ | |
655 | of point, outside of any save-excursion forms.\n\ | |
656 | But that is hard to define.") | |
657 | (window) | |
658 | Lisp_Object window; | |
659 | { | |
660 | register struct window *w = decode_window (window); | |
661 | ||
662 | if (w == XWINDOW (selected_window) | |
663 | && current_buffer == XBUFFER (w->buffer)) | |
664 | return Fpoint (); | |
665 | return Fmarker_position (w->pointm); | |
666 | } | |
667 | ||
668 | DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0, | |
0fea6c40 RS |
669 | "Return position at which display currently starts in WINDOW.\n\ |
670 | This is updated by redisplay or by calling `set-window-start'.") | |
7ab12479 JB |
671 | (window) |
672 | Lisp_Object window; | |
673 | { | |
674 | return Fmarker_position (decode_window (window)->start); | |
675 | } | |
676 | ||
8646118f RS |
677 | /* This is text temporarily removed from the doc string below. |
678 | ||
7250968e RS |
679 | This function returns nil if the position is not currently known.\n\ |
680 | That happens when redisplay is preempted and doesn't finish.\n\ | |
681 | If in that case you want to compute where the end of the window would\n\ | |
682 | have been if redisplay had finished, do this:\n\ | |
683 | (save-excursion\n\ | |
684 | (goto-char (window-start window))\n\ | |
685 | (vertical-motion (1- (window-height window)) window)\n\ | |
8646118f RS |
686 | (point))") */ |
687 | ||
478292ed | 688 | DEFUN ("window-end", Fwindow_end, Swindow_end, 0, 2, 0, |
8646118f RS |
689 | "Return position at which display currently ends in WINDOW.\n\ |
690 | This is updated by redisplay, when it runs to completion.\n\ | |
691 | Simply changing the buffer text or setting `window-start'\n\ | |
478292ed RS |
692 | does not update this value.\n\ |
693 | If UP-TO-DATE is non-nil, compute the up-to-date position\n\ | |
694 | if it isn't already recorded.") | |
695 | (window, update) | |
696 | Lisp_Object window, update; | |
7ab12479 JB |
697 | { |
698 | Lisp_Object value; | |
699 | struct window *w = decode_window (window); | |
5a41ab94 RS |
700 | Lisp_Object buf; |
701 | ||
702 | buf = w->buffer; | |
703 | CHECK_BUFFER (buf, 0); | |
704 | ||
8646118f | 705 | #if 0 /* This change broke some things. We should make it later. */ |
7250968e RS |
706 | /* If we don't know the end position, return nil. |
707 | The user can compute it with vertical-motion if he wants to. | |
708 | It would be nicer to do it automatically, | |
709 | but that's so slow that it would probably bother people. */ | |
710 | if (NILP (w->window_end_valid)) | |
711 | return Qnil; | |
8646118f | 712 | #endif |
7250968e | 713 | |
478292ed RS |
714 | if (! NILP (update) |
715 | && ! (! NILP (w->window_end_valid) | |
716 | && XFASTINT (w->last_modified) >= MODIFF)) | |
717 | { | |
718 | int opoint = PT, opoint_byte = PT_BYTE; | |
719 | TEMP_SET_PT_BOTH (XMARKER (w->start)->charpos, | |
720 | XMARKER (w->start)->bytepos); | |
721 | Fvertical_motion (make_number (window_internal_height (w)), Qnil); | |
722 | XSETINT (value, PT); | |
723 | TEMP_SET_PT_BOTH (opoint, opoint_byte); | |
724 | } | |
725 | else | |
726 | XSETINT (value, | |
727 | BUF_Z (XBUFFER (buf)) - XFASTINT (w->window_end_pos)); | |
7ab12479 JB |
728 | |
729 | return value; | |
730 | } | |
731 | ||
732 | DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0, | |
733 | "Make point value in WINDOW be at position POS in WINDOW's buffer.") | |
734 | (window, pos) | |
735 | Lisp_Object window, pos; | |
736 | { | |
737 | register struct window *w = decode_window (window); | |
738 | ||
739 | CHECK_NUMBER_COERCE_MARKER (pos, 1); | |
e90c4fe6 RS |
740 | if (w == XWINDOW (selected_window) |
741 | && XBUFFER (w->buffer) == current_buffer) | |
7ab12479 JB |
742 | Fgoto_char (pos); |
743 | else | |
744 | set_marker_restricted (w->pointm, pos, w->buffer); | |
745 | ||
746 | return pos; | |
747 | } | |
748 | ||
749 | DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0, | |
750 | "Make display in WINDOW start at position POS in WINDOW's buffer.\n\ | |
751 | Optional third arg NOFORCE non-nil inhibits next redisplay\n\ | |
752 | from overriding motion of point in order to display at this exact start.") | |
753 | (window, pos, noforce) | |
754 | Lisp_Object window, pos, noforce; | |
755 | { | |
756 | register struct window *w = decode_window (window); | |
757 | ||
758 | CHECK_NUMBER_COERCE_MARKER (pos, 1); | |
759 | set_marker_restricted (w->start, pos, w->buffer); | |
760 | /* this is not right, but much easier than doing what is right. */ | |
761 | w->start_at_line_beg = Qnil; | |
265a9e55 | 762 | if (NILP (noforce)) |
7ab12479 JB |
763 | w->force_start = Qt; |
764 | w->update_mode_line = Qt; | |
d834a2e9 | 765 | XSETFASTINT (w->last_modified, 0); |
3cd21523 | 766 | XSETFASTINT (w->last_overlay_modified, 0); |
62c07cc7 JB |
767 | if (!EQ (window, selected_window)) |
768 | windows_or_buffers_changed++; | |
7ab12479 JB |
769 | return pos; |
770 | } | |
771 | ||
772 | DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p, | |
773 | 1, 1, 0, | |
774 | "Return WINDOW's dedicated object, usually t or nil.\n\ | |
1f18c48f | 775 | See also `set-window-dedicated-p'.") |
7ab12479 JB |
776 | (window) |
777 | Lisp_Object window; | |
778 | { | |
779 | return decode_window (window)->dedicated; | |
780 | } | |
781 | ||
d207b766 RS |
782 | DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p, |
783 | Sset_window_dedicated_p, 2, 2, 0, | |
784 | "Control whether WINDOW is dedicated to the buffer it displays.\n\ | |
785 | If it is dedicated, Emacs will not automatically change\n\ | |
786 | which buffer appears in it.\n\ | |
787 | The second argument is the new value for the dedication flag;\n\ | |
788 | non-nil means yes.") | |
7ab12479 JB |
789 | (window, arg) |
790 | Lisp_Object window, arg; | |
791 | { | |
792 | register struct window *w = decode_window (window); | |
793 | ||
265a9e55 | 794 | if (NILP (arg)) |
7ab12479 JB |
795 | w->dedicated = Qnil; |
796 | else | |
d207b766 | 797 | w->dedicated = Qt; |
7ab12479 JB |
798 | |
799 | return w->dedicated; | |
800 | } | |
801 | ||
802 | DEFUN ("window-display-table", Fwindow_display_table, Swindow_display_table, | |
803 | 0, 1, 0, | |
804 | "Return the display-table that WINDOW is using.") | |
805 | (window) | |
806 | Lisp_Object window; | |
807 | { | |
808 | return decode_window (window)->display_table; | |
809 | } | |
810 | ||
5500c422 GM |
811 | /* Get the display table for use on window W. This is either W's |
812 | display table or W's buffer's display table. Ignore the specified | |
813 | tables if they are not valid; if no valid table is specified, | |
814 | return 0. */ | |
7ab12479 | 815 | |
319315f1 | 816 | struct Lisp_Char_Table * |
7ab12479 JB |
817 | window_display_table (w) |
818 | struct window *w; | |
819 | { | |
820 | Lisp_Object tem; | |
821 | tem = w->display_table; | |
319315f1 RS |
822 | if (DISP_TABLE_P (tem)) |
823 | return XCHAR_TABLE (tem); | |
171d003c RS |
824 | if (NILP (w->buffer)) |
825 | return 0; | |
826 | ||
7ab12479 | 827 | tem = XBUFFER (w->buffer)->display_table; |
319315f1 RS |
828 | if (DISP_TABLE_P (tem)) |
829 | return XCHAR_TABLE (tem); | |
7ab12479 | 830 | tem = Vstandard_display_table; |
319315f1 RS |
831 | if (DISP_TABLE_P (tem)) |
832 | return XCHAR_TABLE (tem); | |
7ab12479 JB |
833 | return 0; |
834 | } | |
835 | ||
3a2712f9 | 836 | DEFUN ("set-window-display-table", Fset_window_display_table, Sset_window_display_table, 2, 2, 0, |
7ab12479 JB |
837 | "Set WINDOW's display-table to TABLE.") |
838 | (window, table) | |
839 | register Lisp_Object window, table; | |
840 | { | |
841 | register struct window *w; | |
7ab12479 JB |
842 | |
843 | w = decode_window (window); | |
844 | w->display_table = table; | |
845 | return table; | |
846 | } | |
847 | \f | |
848 | /* Record info on buffer window w is displaying | |
849 | when it is about to cease to display that buffer. */ | |
dfcf069d | 850 | static void |
7ab12479 JB |
851 | unshow_buffer (w) |
852 | register struct window *w; | |
853 | { | |
12cae7c0 | 854 | Lisp_Object buf; |
b73ea88e | 855 | struct buffer *b; |
7ab12479 | 856 | |
12cae7c0 | 857 | buf = w->buffer; |
b73ea88e RS |
858 | b = XBUFFER (buf); |
859 | if (b != XMARKER (w->pointm)->buffer) | |
7ab12479 JB |
860 | abort (); |
861 | ||
b73ea88e RS |
862 | if (w == XWINDOW (b->last_selected_window)) |
863 | b->last_selected_window = Qnil; | |
86e48436 | 864 | |
573f41ab | 865 | #if 0 |
7ab12479 JB |
866 | if (w == XWINDOW (selected_window) |
867 | || ! EQ (buf, XWINDOW (selected_window)->buffer)) | |
868 | /* Do this except when the selected window's buffer | |
869 | is being removed from some other window. */ | |
573f41ab RS |
870 | #endif |
871 | /* last_window_start records the start position that this buffer | |
872 | had in the last window to be disconnected from it. | |
873 | Now that this statement is unconditional, | |
874 | it is possible for the buffer to be displayed in the | |
875 | selected window, while last_window_start reflects another | |
876 | window which was recently showing the same buffer. | |
877 | Some people might say that might be a good thing. Let's see. */ | |
b73ea88e | 878 | b->last_window_start = marker_position (w->start); |
7ab12479 JB |
879 | |
880 | /* Point in the selected window's buffer | |
881 | is actually stored in that buffer, and the window's pointm isn't used. | |
882 | So don't clobber point in that buffer. */ | |
883 | if (! EQ (buf, XWINDOW (selected_window)->buffer)) | |
b73ea88e RS |
884 | temp_set_point_both (b, |
885 | clip_to_bounds (BUF_BEGV (b), | |
886 | XMARKER (w->pointm)->charpos, | |
887 | BUF_ZV (b)), | |
888 | clip_to_bounds (BUF_BEGV_BYTE (b), | |
889 | marker_byte_position (w->pointm), | |
890 | BUF_ZV_BYTE (b))); | |
7ab12479 JB |
891 | } |
892 | ||
893 | /* Put replacement into the window structure in place of old. */ | |
dfcf069d | 894 | static void |
7ab12479 JB |
895 | replace_window (old, replacement) |
896 | Lisp_Object old, replacement; | |
897 | { | |
898 | register Lisp_Object tem; | |
899 | register struct window *o = XWINDOW (old), *p = XWINDOW (replacement); | |
900 | ||
44fa5b1e JB |
901 | /* If OLD is its frame's root_window, then replacement is the new |
902 | root_window for that frame. */ | |
7ab12479 | 903 | |
7f4161e0 | 904 | if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame)))) |
44fa5b1e | 905 | FRAME_ROOT_WINDOW (XFRAME (o->frame)) = replacement; |
7ab12479 JB |
906 | |
907 | p->left = o->left; | |
908 | p->top = o->top; | |
909 | p->width = o->width; | |
910 | p->height = o->height; | |
5500c422 GM |
911 | p->desired_matrix = p->current_matrix = 0; |
912 | p->vscroll = 0; | |
913 | bzero (&p->cursor, sizeof (p->cursor)); | |
914 | bzero (&p->last_cursor, sizeof (p->last_cursor)); | |
915 | bzero (&p->phys_cursor, sizeof (p->phys_cursor)); | |
916 | p->phys_cursor_type = -1; | |
917 | p->must_be_updated_p = 0; | |
918 | p->pseudo_window_p = 0; | |
919 | XSETFASTINT (p->window_end_vpos, 0); | |
920 | XSETFASTINT (p->window_end_pos, 0); | |
921 | p->window_end_valid = Qnil; | |
7ab12479 JB |
922 | |
923 | p->next = tem = o->next; | |
265a9e55 | 924 | if (!NILP (tem)) |
7ab12479 JB |
925 | XWINDOW (tem)->prev = replacement; |
926 | ||
927 | p->prev = tem = o->prev; | |
265a9e55 | 928 | if (!NILP (tem)) |
7ab12479 JB |
929 | XWINDOW (tem)->next = replacement; |
930 | ||
931 | p->parent = tem = o->parent; | |
265a9e55 | 932 | if (!NILP (tem)) |
7ab12479 JB |
933 | { |
934 | if (EQ (XWINDOW (tem)->vchild, old)) | |
935 | XWINDOW (tem)->vchild = replacement; | |
936 | if (EQ (XWINDOW (tem)->hchild, old)) | |
937 | XWINDOW (tem)->hchild = replacement; | |
938 | } | |
939 | ||
940 | /*** Here, if replacement is a vertical combination | |
941 | and so is its new parent, we should make replacement's | |
942 | children be children of that parent instead. ***/ | |
943 | } | |
944 | ||
945 | DEFUN ("delete-window", Fdelete_window, Sdelete_window, 0, 1, "", | |
946 | "Remove WINDOW from the display. Default is selected window.") | |
947 | (window) | |
948 | register Lisp_Object window; | |
543f5fb1 RS |
949 | { |
950 | delete_window (window); | |
951 | ||
952 | if (! NILP (Vwindow_configuration_change_hook) | |
953 | && ! NILP (Vrun_hooks)) | |
954 | call1 (Vrun_hooks, Qwindow_configuration_change_hook); | |
955 | ||
956 | return Qnil; | |
957 | } | |
958 | ||
5e14b1fc | 959 | void |
543f5fb1 RS |
960 | delete_window (window) |
961 | register Lisp_Object window; | |
7ab12479 JB |
962 | { |
963 | register Lisp_Object tem, parent, sib; | |
964 | register struct window *p; | |
965 | register struct window *par; | |
5500c422 | 966 | FRAME_PTR frame; |
7ab12479 | 967 | |
605be8af JB |
968 | /* Because this function is called by other C code on non-leaf |
969 | windows, the CHECK_LIVE_WINDOW macro would choke inappropriately, | |
970 | so we can't decode_window here. */ | |
265a9e55 | 971 | if (NILP (window)) |
7ab12479 JB |
972 | window = selected_window; |
973 | else | |
974 | CHECK_WINDOW (window, 0); | |
7ab12479 | 975 | p = XWINDOW (window); |
605be8af JB |
976 | |
977 | /* It's okay to delete an already-deleted window. */ | |
978 | if (NILP (p->buffer) | |
979 | && NILP (p->hchild) | |
980 | && NILP (p->vchild)) | |
296b535c | 981 | return; |
605be8af | 982 | |
7ab12479 | 983 | parent = p->parent; |
265a9e55 | 984 | if (NILP (parent)) |
7ab12479 JB |
985 | error ("Attempt to delete minibuffer or sole ordinary window"); |
986 | par = XWINDOW (parent); | |
987 | ||
988 | windows_or_buffers_changed++; | |
5500c422 GM |
989 | frame = XFRAME (WINDOW_FRAME (p)); |
990 | FRAME_WINDOW_SIZES_CHANGED (frame) = 1; | |
7ab12479 | 991 | |
605be8af JB |
992 | /* Are we trying to delete any frame's selected window? */ |
993 | { | |
0def0403 | 994 | Lisp_Object frame, pwindow; |
605be8af | 995 | |
0def0403 RS |
996 | /* See if the frame's selected window is either WINDOW |
997 | or any subwindow of it, by finding all that window's parents | |
998 | and comparing each one with WINDOW. */ | |
999 | frame = WINDOW_FRAME (XWINDOW (window)); | |
1000 | pwindow = FRAME_SELECTED_WINDOW (XFRAME (frame)); | |
1001 | ||
1002 | while (!NILP (pwindow)) | |
1003 | { | |
1004 | if (EQ (window, pwindow)) | |
1005 | break; | |
1006 | pwindow = XWINDOW (pwindow)->parent; | |
1007 | } | |
1008 | ||
1009 | if (EQ (window, pwindow)) | |
605be8af | 1010 | { |
89bca612 RS |
1011 | Lisp_Object alternative; |
1012 | alternative = Fnext_window (window, Qlambda, Qnil); | |
605be8af JB |
1013 | |
1014 | /* If we're about to delete the selected window on the | |
1015 | selected frame, then we should use Fselect_window to select | |
1016 | the new window. On the other hand, if we're about to | |
1017 | delete the selected window on any other frame, we shouldn't do | |
1018 | anything but set the frame's selected_window slot. */ | |
1019 | if (EQ (window, selected_window)) | |
1020 | Fselect_window (alternative); | |
1021 | else | |
0def0403 | 1022 | FRAME_SELECTED_WINDOW (XFRAME (frame)) = alternative; |
605be8af JB |
1023 | } |
1024 | } | |
7ab12479 JB |
1025 | |
1026 | tem = p->buffer; | |
1027 | /* tem is null for dummy parent windows | |
1028 | (which have inferiors but not any contents themselves) */ | |
265a9e55 | 1029 | if (!NILP (tem)) |
7ab12479 JB |
1030 | { |
1031 | unshow_buffer (p); | |
1032 | unchain_marker (p->pointm); | |
1033 | unchain_marker (p->start); | |
7ab12479 JB |
1034 | } |
1035 | ||
5500c422 GM |
1036 | /* Free window glyph matrices. |
1037 | It is sure that they are allocated again when ADJUST_GLYPHS | |
1038 | is called. */ | |
1039 | free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (frame))); | |
1040 | ||
7ab12479 | 1041 | tem = p->next; |
265a9e55 | 1042 | if (!NILP (tem)) |
7ab12479 JB |
1043 | XWINDOW (tem)->prev = p->prev; |
1044 | ||
1045 | tem = p->prev; | |
265a9e55 | 1046 | if (!NILP (tem)) |
7ab12479 JB |
1047 | XWINDOW (tem)->next = p->next; |
1048 | ||
1049 | if (EQ (window, par->hchild)) | |
1050 | par->hchild = p->next; | |
1051 | if (EQ (window, par->vchild)) | |
1052 | par->vchild = p->next; | |
1053 | ||
1054 | /* Find one of our siblings to give our space to. */ | |
1055 | sib = p->prev; | |
265a9e55 | 1056 | if (NILP (sib)) |
7ab12479 JB |
1057 | { |
1058 | /* If p gives its space to its next sibling, that sibling needs | |
1059 | to have its top/left side pulled back to where p's is. | |
1060 | set_window_{height,width} will re-position the sibling's | |
1061 | children. */ | |
1062 | sib = p->next; | |
7f4161e0 JB |
1063 | XWINDOW (sib)->top = p->top; |
1064 | XWINDOW (sib)->left = p->left; | |
7ab12479 JB |
1065 | } |
1066 | ||
1067 | /* Stretch that sibling. */ | |
265a9e55 | 1068 | if (!NILP (par->vchild)) |
7ab12479 JB |
1069 | set_window_height (sib, |
1070 | XFASTINT (XWINDOW (sib)->height) + XFASTINT (p->height), | |
1071 | 1); | |
265a9e55 | 1072 | if (!NILP (par->hchild)) |
7ab12479 JB |
1073 | set_window_width (sib, |
1074 | XFASTINT (XWINDOW (sib)->width) + XFASTINT (p->width), | |
1075 | 1); | |
1076 | ||
1077 | /* If parent now has only one child, | |
1078 | put the child into the parent's place. */ | |
7ab12479 | 1079 | tem = par->hchild; |
265a9e55 | 1080 | if (NILP (tem)) |
7ab12479 | 1081 | tem = par->vchild; |
265a9e55 | 1082 | if (NILP (XWINDOW (tem)->next)) |
7ab12479 | 1083 | replace_window (parent, tem); |
605be8af JB |
1084 | |
1085 | /* Since we may be deleting combination windows, we must make sure that | |
1086 | not only p but all its children have been marked as deleted. */ | |
1087 | if (! NILP (p->hchild)) | |
1088 | delete_all_subwindows (XWINDOW (p->hchild)); | |
1089 | else if (! NILP (p->vchild)) | |
1090 | delete_all_subwindows (XWINDOW (p->vchild)); | |
1091 | ||
1092 | /* Mark this window as deleted. */ | |
1093 | p->buffer = p->hchild = p->vchild = Qnil; | |
5500c422 GM |
1094 | |
1095 | /* Adjust glyph matrices. */ | |
1096 | adjust_glyphs (frame); | |
7ab12479 JB |
1097 | } |
1098 | \f | |
7ab12479 | 1099 | |
44fa5b1e | 1100 | extern Lisp_Object next_frame (), prev_frame (); |
7ab12479 | 1101 | |
26f6279d JB |
1102 | /* This comment supplies the doc string for `next-window', |
1103 | for make-docfile to see. We cannot put this in the real DEFUN | |
1104 | due to limits in the Unix cpp. | |
1105 | ||
1106 | DEFUN ("next-window", Ffoo, Sfoo, 0, 3, 0, | |
7ab12479 | 1107 | "Return next window after WINDOW in canonical ordering of windows.\n\ |
d5783c40 JB |
1108 | If omitted, WINDOW defaults to the selected window.\n\ |
1109 | \n\ | |
1110 | Optional second arg MINIBUF t means count the minibuffer window even\n\ | |
1111 | if not active. MINIBUF nil or omitted means count the minibuffer iff\n\ | |
1112 | it is active. MINIBUF neither t nor nil means not to count the\n\ | |
1113 | minibuffer even if it is active.\n\ | |
1114 | \n\ | |
44fa5b1e JB |
1115 | Several frames may share a single minibuffer; if the minibuffer\n\ |
1116 | counts, all windows on all frames that share that minibuffer count\n\ | |
ed160f1f | 1117 | too. Therefore, `next-window' can be used to iterate through the\n\ |
44fa5b1e JB |
1118 | set of windows even when the minibuffer is on another frame. If the\n\ |
1119 | minibuffer does not count, only windows from WINDOW's frame count.\n\ | |
d5783c40 | 1120 | \n\ |
44fa5b1e JB |
1121 | Optional third arg ALL-FRAMES t means include windows on all frames.\n\ |
1122 | ALL-FRAMES nil or omitted means cycle within the frames as specified\n\ | |
89bca612 | 1123 | above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\ |
f812f9c6 | 1124 | ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\ |
1f4c5d09 | 1125 | If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\ |
89bca612 | 1126 | Anything else means restrict to WINDOW's frame.\n\ |
dbc4e1c1 JB |
1127 | \n\ |
1128 | If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\ | |
1129 | `next-window' to iterate through the entire cycle of acceptable\n\ | |
1130 | windows, eventually ending up back at the window you started with.\n\ | |
1131 | `previous-window' traverses the same cycle, in the reverse order.") | |
26f6279d JB |
1132 | (window, minibuf, all_frames) */ |
1133 | ||
1134 | DEFUN ("next-window", Fnext_window, Snext_window, 0, 3, 0, | |
1135 | 0) | |
44fa5b1e JB |
1136 | (window, minibuf, all_frames) |
1137 | register Lisp_Object window, minibuf, all_frames; | |
7ab12479 JB |
1138 | { |
1139 | register Lisp_Object tem; | |
d5783c40 | 1140 | Lisp_Object start_window; |
7ab12479 | 1141 | |
265a9e55 | 1142 | if (NILP (window)) |
7ab12479 JB |
1143 | window = selected_window; |
1144 | else | |
605be8af | 1145 | CHECK_LIVE_WINDOW (window, 0); |
7ab12479 | 1146 | |
d5783c40 JB |
1147 | start_window = window; |
1148 | ||
1149 | /* minibuf == nil may or may not include minibuffers. | |
1150 | Decide if it does. */ | |
265a9e55 | 1151 | if (NILP (minibuf)) |
fbdc1545 RS |
1152 | minibuf = (minibuf_level ? minibuf_window : Qlambda); |
1153 | else if (! EQ (minibuf, Qt)) | |
1154 | minibuf = Qlambda; | |
1155 | /* Now minibuf can be t => count all minibuffer windows, | |
1156 | lambda => count none of them, | |
1157 | or a specific minibuffer window (the active one) to count. */ | |
d5783c40 | 1158 | |
1bb80f72 | 1159 | /* all_frames == nil doesn't specify which frames to include. */ |
44fa5b1e | 1160 | if (NILP (all_frames)) |
fbdc1545 | 1161 | all_frames = (! EQ (minibuf, Qlambda) |
1bb80f72 RS |
1162 | ? (FRAME_MINIBUF_WINDOW |
1163 | (XFRAME | |
1164 | (WINDOW_FRAME | |
1165 | (XWINDOW (window))))) | |
1166 | : Qnil); | |
89bca612 RS |
1167 | else if (EQ (all_frames, Qvisible)) |
1168 | ; | |
f812f9c6 RS |
1169 | else if (XFASTINT (all_frames) == 0) |
1170 | ; | |
1f4c5d09 RS |
1171 | else if (FRAMEP (all_frames) && ! EQ (all_frames, Fwindow_frame (window))) |
1172 | /* If all_frames is a frame and window arg isn't on that frame, just | |
1173 | return the first window on the frame. */ | |
1174 | return Fframe_first_window (all_frames); | |
44fa5b1e JB |
1175 | else if (! EQ (all_frames, Qt)) |
1176 | all_frames = Qnil; | |
644b477c RS |
1177 | /* Now all_frames is t meaning search all frames, |
1178 | nil meaning search just current frame, | |
f812f9c6 RS |
1179 | visible meaning search just visible frames, |
1180 | 0 meaning search visible and iconified frames, | |
644b477c | 1181 | or a window, meaning search the frame that window belongs to. */ |
7ab12479 JB |
1182 | |
1183 | /* Do this loop at least once, to get the next window, and perhaps | |
1184 | again, if we hit the minibuffer and that is not acceptable. */ | |
1185 | do | |
1186 | { | |
1187 | /* Find a window that actually has a next one. This loop | |
1188 | climbs up the tree. */ | |
265a9e55 JB |
1189 | while (tem = XWINDOW (window)->next, NILP (tem)) |
1190 | if (tem = XWINDOW (window)->parent, !NILP (tem)) | |
7ab12479 | 1191 | window = tem; |
d5783c40 | 1192 | else |
7ab12479 | 1193 | { |
44fa5b1e JB |
1194 | /* We've reached the end of this frame. |
1195 | Which other frames are acceptable? */ | |
1196 | tem = WINDOW_FRAME (XWINDOW (window)); | |
44fa5b1e | 1197 | if (! NILP (all_frames)) |
1bb80f72 RS |
1198 | { |
1199 | Lisp_Object tem1; | |
1200 | ||
1201 | tem1 = tem; | |
1202 | tem = next_frame (tem, all_frames); | |
1203 | /* In the case where the minibuffer is active, | |
1204 | and we include its frame as well as the selected one, | |
1205 | next_frame may get stuck in that frame. | |
1206 | If that happens, go back to the selected frame | |
1207 | so we can complete the cycle. */ | |
1208 | if (EQ (tem, tem1)) | |
74112613 | 1209 | XSETFRAME (tem, selected_frame); |
1bb80f72 | 1210 | } |
44fa5b1e | 1211 | tem = FRAME_ROOT_WINDOW (XFRAME (tem)); |
d5783c40 | 1212 | |
7ab12479 JB |
1213 | break; |
1214 | } | |
1215 | ||
1216 | window = tem; | |
d5783c40 | 1217 | |
7ab12479 JB |
1218 | /* If we're in a combination window, find its first child and |
1219 | recurse on that. Otherwise, we've found the window we want. */ | |
1220 | while (1) | |
1221 | { | |
265a9e55 | 1222 | if (!NILP (XWINDOW (window)->hchild)) |
7ab12479 | 1223 | window = XWINDOW (window)->hchild; |
265a9e55 | 1224 | else if (!NILP (XWINDOW (window)->vchild)) |
7ab12479 JB |
1225 | window = XWINDOW (window)->vchild; |
1226 | else break; | |
1227 | } | |
1228 | } | |
5c4d25a6 | 1229 | /* Which windows are acceptable? |
d5783c40 | 1230 | Exit the loop and accept this window if |
fbdc1545 RS |
1231 | this isn't a minibuffer window, |
1232 | or we're accepting all minibuffer windows, | |
1233 | or this is the active minibuffer and we are accepting that one, or | |
d5783c40 | 1234 | we've come all the way around and we're back at the original window. */ |
7ab12479 | 1235 | while (MINI_WINDOW_P (XWINDOW (window)) |
d5783c40 | 1236 | && ! EQ (minibuf, Qt) |
fbdc1545 | 1237 | && ! EQ (minibuf, window) |
7f4161e0 | 1238 | && ! EQ (window, start_window)); |
7ab12479 JB |
1239 | |
1240 | return window; | |
1241 | } | |
1242 | ||
26f6279d JB |
1243 | /* This comment supplies the doc string for `previous-window', |
1244 | for make-docfile to see. We cannot put this in the real DEFUN | |
1245 | due to limits in the Unix cpp. | |
1246 | ||
1247 | DEFUN ("previous-window", Ffoo, Sfoo, 0, 3, 0, | |
5c4d25a6 | 1248 | "Return the window preceding WINDOW in canonical ordering of windows.\n\ |
d5783c40 JB |
1249 | If omitted, WINDOW defaults to the selected window.\n\ |
1250 | \n\ | |
1251 | Optional second arg MINIBUF t means count the minibuffer window even\n\ | |
1252 | if not active. MINIBUF nil or omitted means count the minibuffer iff\n\ | |
1253 | it is active. MINIBUF neither t nor nil means not to count the\n\ | |
1254 | minibuffer even if it is active.\n\ | |
1255 | \n\ | |
44fa5b1e JB |
1256 | Several frames may share a single minibuffer; if the minibuffer\n\ |
1257 | counts, all windows on all frames that share that minibuffer count\n\ | |
ed160f1f | 1258 | too. Therefore, `previous-window' can be used to iterate through\n\ |
44fa5b1e | 1259 | the set of windows even when the minibuffer is on another frame. If\n\ |
ed160f1f | 1260 | the minibuffer does not count, only windows from WINDOW's frame count\n\ |
d5783c40 | 1261 | \n\ |
44fa5b1e JB |
1262 | Optional third arg ALL-FRAMES t means include windows on all frames.\n\ |
1263 | ALL-FRAMES nil or omitted means cycle within the frames as specified\n\ | |
89bca612 | 1264 | above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\ |
f812f9c6 | 1265 | ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\ |
1f4c5d09 | 1266 | If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\ |
89bca612 | 1267 | Anything else means restrict to WINDOW's frame.\n\ |
dbc4e1c1 JB |
1268 | \n\ |
1269 | If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\ | |
1270 | `previous-window' to iterate through the entire cycle of acceptable\n\ | |
1271 | windows, eventually ending up back at the window you started with.\n\ | |
1272 | `next-window' traverses the same cycle, in the reverse order.") | |
26f6279d JB |
1273 | (window, minibuf, all_frames) */ |
1274 | ||
1275 | ||
1276 | DEFUN ("previous-window", Fprevious_window, Sprevious_window, 0, 3, 0, | |
1277 | 0) | |
44fa5b1e JB |
1278 | (window, minibuf, all_frames) |
1279 | register Lisp_Object window, minibuf, all_frames; | |
7ab12479 JB |
1280 | { |
1281 | register Lisp_Object tem; | |
d5783c40 | 1282 | Lisp_Object start_window; |
7ab12479 | 1283 | |
265a9e55 | 1284 | if (NILP (window)) |
7ab12479 JB |
1285 | window = selected_window; |
1286 | else | |
605be8af | 1287 | CHECK_LIVE_WINDOW (window, 0); |
7ab12479 | 1288 | |
d5783c40 JB |
1289 | start_window = window; |
1290 | ||
1291 | /* minibuf == nil may or may not include minibuffers. | |
1292 | Decide if it does. */ | |
265a9e55 | 1293 | if (NILP (minibuf)) |
fbdc1545 RS |
1294 | minibuf = (minibuf_level ? minibuf_window : Qlambda); |
1295 | else if (! EQ (minibuf, Qt)) | |
1296 | minibuf = Qlambda; | |
1297 | /* Now minibuf can be t => count all minibuffer windows, | |
1298 | lambda => count none of them, | |
1299 | or a specific minibuffer window (the active one) to count. */ | |
d5783c40 | 1300 | |
44fa5b1e JB |
1301 | /* all_frames == nil doesn't specify which frames to include. |
1302 | Decide which frames it includes. */ | |
1303 | if (NILP (all_frames)) | |
fbdc1545 | 1304 | all_frames = (! EQ (minibuf, Qlambda) |
44fa5b1e JB |
1305 | ? (FRAME_MINIBUF_WINDOW |
1306 | (XFRAME | |
1307 | (WINDOW_FRAME | |
d5783c40 JB |
1308 | (XWINDOW (window))))) |
1309 | : Qnil); | |
89bca612 RS |
1310 | else if (EQ (all_frames, Qvisible)) |
1311 | ; | |
f812f9c6 RS |
1312 | else if (XFASTINT (all_frames) == 0) |
1313 | ; | |
1f4c5d09 RS |
1314 | else if (FRAMEP (all_frames) && ! EQ (all_frames, Fwindow_frame (window))) |
1315 | /* If all_frames is a frame and window arg isn't on that frame, just | |
1316 | return the first window on the frame. */ | |
1317 | return Fframe_first_window (all_frames); | |
44fa5b1e JB |
1318 | else if (! EQ (all_frames, Qt)) |
1319 | all_frames = Qnil; | |
644b477c RS |
1320 | /* Now all_frames is t meaning search all frames, |
1321 | nil meaning search just current frame, | |
f812f9c6 RS |
1322 | visible meaning search just visible frames, |
1323 | 0 meaning search visible and iconified frames, | |
644b477c | 1324 | or a window, meaning search the frame that window belongs to. */ |
7ab12479 JB |
1325 | |
1326 | /* Do this loop at least once, to get the previous window, and perhaps | |
1327 | again, if we hit the minibuffer and that is not acceptable. */ | |
1328 | do | |
1329 | { | |
1330 | /* Find a window that actually has a previous one. This loop | |
1331 | climbs up the tree. */ | |
265a9e55 JB |
1332 | while (tem = XWINDOW (window)->prev, NILP (tem)) |
1333 | if (tem = XWINDOW (window)->parent, !NILP (tem)) | |
7ab12479 | 1334 | window = tem; |
d5783c40 | 1335 | else |
7ab12479 | 1336 | { |
44fa5b1e JB |
1337 | /* We have found the top window on the frame. |
1338 | Which frames are acceptable? */ | |
1339 | tem = WINDOW_FRAME (XWINDOW (window)); | |
44fa5b1e | 1340 | if (! NILP (all_frames)) |
dbc4e1c1 JB |
1341 | /* It's actually important that we use prev_frame here, |
1342 | rather than next_frame. All the windows acceptable | |
1343 | according to the given parameters should form a ring; | |
1344 | Fnext_window and Fprevious_window should go back and | |
1345 | forth around the ring. If we use next_frame here, | |
1346 | then Fnext_window and Fprevious_window take different | |
1347 | paths through the set of acceptable windows. | |
1348 | window_loop assumes that these `ring' requirement are | |
1349 | met. */ | |
1bb80f72 RS |
1350 | { |
1351 | Lisp_Object tem1; | |
1352 | ||
1353 | tem1 = tem; | |
1354 | tem = prev_frame (tem, all_frames); | |
1355 | /* In the case where the minibuffer is active, | |
1356 | and we include its frame as well as the selected one, | |
1357 | next_frame may get stuck in that frame. | |
1358 | If that happens, go back to the selected frame | |
1359 | so we can complete the cycle. */ | |
1360 | if (EQ (tem, tem1)) | |
74112613 | 1361 | XSETFRAME (tem, selected_frame); |
1bb80f72 | 1362 | } |
644b477c RS |
1363 | /* If this frame has a minibuffer, find that window first, |
1364 | because it is conceptually the last window in that frame. */ | |
5e12e32f JB |
1365 | if (FRAME_HAS_MINIBUF_P (XFRAME (tem))) |
1366 | tem = FRAME_MINIBUF_WINDOW (XFRAME (tem)); | |
1367 | else | |
644b477c | 1368 | tem = FRAME_ROOT_WINDOW (XFRAME (tem)); |
d5783c40 | 1369 | |
7ab12479 JB |
1370 | break; |
1371 | } | |
1372 | ||
1373 | window = tem; | |
1374 | /* If we're in a combination window, find its last child and | |
1375 | recurse on that. Otherwise, we've found the window we want. */ | |
1376 | while (1) | |
1377 | { | |
265a9e55 | 1378 | if (!NILP (XWINDOW (window)->hchild)) |
7ab12479 | 1379 | window = XWINDOW (window)->hchild; |
265a9e55 | 1380 | else if (!NILP (XWINDOW (window)->vchild)) |
7ab12479 JB |
1381 | window = XWINDOW (window)->vchild; |
1382 | else break; | |
265a9e55 | 1383 | while (tem = XWINDOW (window)->next, !NILP (tem)) |
7ab12479 JB |
1384 | window = tem; |
1385 | } | |
1386 | } | |
5c4d25a6 | 1387 | /* Which windows are acceptable? |
d5783c40 | 1388 | Exit the loop and accept this window if |
fbdc1545 RS |
1389 | this isn't a minibuffer window, |
1390 | or we're accepting all minibuffer windows, | |
1391 | or this is the active minibuffer and we are accepting that one, or | |
d5783c40 | 1392 | we've come all the way around and we're back at the original window. */ |
7ab12479 | 1393 | while (MINI_WINDOW_P (XWINDOW (window)) |
fbdc1545 RS |
1394 | && ! EQ (minibuf, Qt) |
1395 | && ! EQ (minibuf, window) | |
1396 | && ! EQ (window, start_window)); | |
7ab12479 JB |
1397 | |
1398 | return window; | |
1399 | } | |
1400 | ||
62c07cc7 | 1401 | DEFUN ("other-window", Fother_window, Sother_window, 1, 2, "p", |
44fa5b1e JB |
1402 | "Select the ARG'th different window on this frame.\n\ |
1403 | All windows on current frame are arranged in a cyclic order.\n\ | |
7ab12479 JB |
1404 | This command selects the window ARG steps away in that order.\n\ |
1405 | A negative ARG moves in the opposite order. If the optional second\n\ | |
44fa5b1e | 1406 | argument ALL_FRAMES is non-nil, cycle through all frames.") |
413430c5 EN |
1407 | (arg, all_frames) |
1408 | register Lisp_Object arg, all_frames; | |
7ab12479 JB |
1409 | { |
1410 | register int i; | |
1411 | register Lisp_Object w; | |
1412 | ||
413430c5 | 1413 | CHECK_NUMBER (arg, 0); |
7ab12479 | 1414 | w = selected_window; |
413430c5 | 1415 | i = XINT (arg); |
7ab12479 JB |
1416 | |
1417 | while (i > 0) | |
1418 | { | |
44fa5b1e | 1419 | w = Fnext_window (w, Qnil, all_frames); |
7ab12479 JB |
1420 | i--; |
1421 | } | |
1422 | while (i < 0) | |
1423 | { | |
44fa5b1e | 1424 | w = Fprevious_window (w, Qnil, all_frames); |
7ab12479 JB |
1425 | i++; |
1426 | } | |
1427 | Fselect_window (w); | |
1428 | return Qnil; | |
1429 | } | |
1430 | \f | |
1431 | /* Look at all windows, performing an operation specified by TYPE | |
1432 | with argument OBJ. | |
75d8f668 | 1433 | If FRAMES is Qt, look at all frames; |
75d8f668 | 1434 | Qnil, look at just the selected frame; |
89bca612 | 1435 | Qvisible, look at visible frames; |
75d8f668 | 1436 | a frame, just look at windows on that frame. |
7ab12479 JB |
1437 | If MINI is non-zero, perform the operation on minibuffer windows too. |
1438 | */ | |
1439 | ||
1440 | enum window_loop | |
1441 | { | |
1442 | WINDOW_LOOP_UNUSED, | |
1443 | GET_BUFFER_WINDOW, /* Arg is buffer */ | |
1444 | GET_LRU_WINDOW, /* Arg is t for full-width windows only */ | |
1445 | DELETE_OTHER_WINDOWS, /* Arg is window not to delete */ | |
1446 | DELETE_BUFFER_WINDOWS, /* Arg is buffer */ | |
1447 | GET_LARGEST_WINDOW, | |
3f8ab7bd RS |
1448 | UNSHOW_BUFFER, /* Arg is buffer */ |
1449 | CHECK_ALL_WINDOWS | |
7ab12479 JB |
1450 | }; |
1451 | ||
1452 | static Lisp_Object | |
44fa5b1e | 1453 | window_loop (type, obj, mini, frames) |
7ab12479 | 1454 | enum window_loop type; |
44fa5b1e | 1455 | register Lisp_Object obj, frames; |
7ab12479 JB |
1456 | int mini; |
1457 | { | |
1458 | register Lisp_Object w; | |
1459 | register Lisp_Object best_window; | |
1460 | register Lisp_Object next_window; | |
4b206065 | 1461 | register Lisp_Object last_window; |
44fa5b1e | 1462 | FRAME_PTR frame; |
89bca612 RS |
1463 | Lisp_Object frame_arg; |
1464 | frame_arg = Qt; | |
44fa5b1e JB |
1465 | |
1466 | /* If we're only looping through windows on a particular frame, | |
1467 | frame points to that frame. If we're looping through windows | |
1468 | on all frames, frame is 0. */ | |
1469 | if (FRAMEP (frames)) | |
1470 | frame = XFRAME (frames); | |
1471 | else if (NILP (frames)) | |
1472 | frame = selected_frame; | |
7ab12479 | 1473 | else |
44fa5b1e | 1474 | frame = 0; |
89bca612 RS |
1475 | if (frame) |
1476 | frame_arg = Qlambda; | |
f812f9c6 RS |
1477 | else if (XFASTINT (frames) == 0) |
1478 | frame_arg = frames; | |
89bca612 RS |
1479 | else if (EQ (frames, Qvisible)) |
1480 | frame_arg = frames; | |
7ab12479 | 1481 | |
89bca612 RS |
1482 | /* frame_arg is Qlambda to stick to one frame, |
1483 | Qvisible to consider all visible frames, | |
1484 | or Qt otherwise. */ | |
1485 | ||
7ab12479 | 1486 | /* Pick a window to start with. */ |
017b2bad | 1487 | if (WINDOWP (obj)) |
4b206065 | 1488 | w = obj; |
44fa5b1e | 1489 | else if (frame) |
4b206065 | 1490 | w = FRAME_SELECTED_WINDOW (frame); |
7ab12479 | 1491 | else |
4b206065 JB |
1492 | w = FRAME_SELECTED_WINDOW (selected_frame); |
1493 | ||
1494 | /* Figure out the last window we're going to mess with. Since | |
1495 | Fnext_window, given the same options, is guaranteed to go in a | |
1496 | ring, we can just use Fprevious_window to find the last one. | |
1497 | ||
1498 | We can't just wait until we hit the first window again, because | |
1499 | it might be deleted. */ | |
1500 | ||
89bca612 | 1501 | last_window = Fprevious_window (w, mini ? Qt : Qnil, frame_arg); |
7ab12479 | 1502 | |
7ab12479 | 1503 | best_window = Qnil; |
4b206065 | 1504 | for (;;) |
7ab12479 JB |
1505 | { |
1506 | /* Pick the next window now, since some operations will delete | |
1507 | the current window. */ | |
89bca612 | 1508 | next_window = Fnext_window (w, mini ? Qt : Qnil, frame_arg); |
7ab12479 | 1509 | |
d29a5631 RS |
1510 | /* Note that we do not pay attention here to whether |
1511 | the frame is visible, since Fnext_window skips non-visible frames | |
1512 | if that is desired, under the control of frame_arg. */ | |
75d8f668 | 1513 | if (! MINI_WINDOW_P (XWINDOW (w)) |
65a04b96 RS |
1514 | /* For UNSHOW_BUFFER, we must always consider all windows. */ |
1515 | || type == UNSHOW_BUFFER | |
7ab12479 JB |
1516 | || (mini && minibuf_level > 0)) |
1517 | switch (type) | |
1518 | { | |
1519 | case GET_BUFFER_WINDOW: | |
5c204627 RS |
1520 | if (XBUFFER (XWINDOW (w)->buffer) == XBUFFER (obj) |
1521 | /* Don't find any minibuffer window | |
1522 | except the one that is currently in use. */ | |
1523 | && (MINI_WINDOW_P (XWINDOW (w)) | |
1524 | ? EQ (w, minibuf_window) : 1)) | |
7ab12479 JB |
1525 | return w; |
1526 | break; | |
1527 | ||
1528 | case GET_LRU_WINDOW: | |
1529 | /* t as arg means consider only full-width windows */ | |
111e5992 | 1530 | if (!NILP (obj) && !WINDOW_FULL_WIDTH_P (XWINDOW (w))) |
7ab12479 | 1531 | break; |
7ab12479 JB |
1532 | /* Ignore dedicated windows and minibuffers. */ |
1533 | if (MINI_WINDOW_P (XWINDOW (w)) | |
265a9e55 | 1534 | || !NILP (XWINDOW (w)->dedicated)) |
7ab12479 | 1535 | break; |
265a9e55 | 1536 | if (NILP (best_window) |
7ab12479 JB |
1537 | || (XFASTINT (XWINDOW (best_window)->use_time) |
1538 | > XFASTINT (XWINDOW (w)->use_time))) | |
1539 | best_window = w; | |
1540 | break; | |
1541 | ||
1542 | case DELETE_OTHER_WINDOWS: | |
1543 | if (XWINDOW (w) != XWINDOW (obj)) | |
1544 | Fdelete_window (w); | |
1545 | break; | |
1546 | ||
1547 | case DELETE_BUFFER_WINDOWS: | |
1548 | if (EQ (XWINDOW (w)->buffer, obj)) | |
1549 | { | |
3548e138 RS |
1550 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (w))); |
1551 | ||
1552 | /* If this window is dedicated, and in a frame of its own, | |
1553 | kill the frame. */ | |
1554 | if (EQ (w, FRAME_ROOT_WINDOW (f)) | |
1555 | && !NILP (XWINDOW (w)->dedicated) | |
1556 | && other_visible_frames (f)) | |
7ab12479 | 1557 | { |
3548e138 RS |
1558 | /* Skip the other windows on this frame. |
1559 | There might be one, the minibuffer! */ | |
1560 | if (! EQ (w, last_window)) | |
1561 | while (f == XFRAME (WINDOW_FRAME (XWINDOW (next_window)))) | |
1562 | { | |
1563 | /* As we go, check for the end of the loop. | |
1564 | We mustn't start going around a second time. */ | |
1565 | if (EQ (next_window, last_window)) | |
1566 | { | |
1567 | last_window = w; | |
1568 | break; | |
1569 | } | |
1570 | next_window = Fnext_window (next_window, | |
1571 | mini ? Qt : Qnil, | |
1572 | frame_arg); | |
1573 | } | |
1574 | /* Now we can safely delete the frame. */ | |
1575 | Fdelete_frame (WINDOW_FRAME (XWINDOW (w)), Qnil); | |
7ab12479 JB |
1576 | } |
1577 | else | |
3548e138 RS |
1578 | /* If we're deleting the buffer displayed in the only window |
1579 | on the frame, find a new buffer to display there. */ | |
1580 | if (NILP (XWINDOW (w)->parent)) | |
1581 | { | |
1582 | Lisp_Object new_buffer; | |
b7354ddf RS |
1583 | new_buffer = Fother_buffer (obj, Qnil, |
1584 | XWINDOW (w)->frame); | |
3548e138 RS |
1585 | if (NILP (new_buffer)) |
1586 | new_buffer | |
1587 | = Fget_buffer_create (build_string ("*scratch*")); | |
1588 | Fset_window_buffer (w, new_buffer); | |
1589 | if (EQ (w, selected_window)) | |
1590 | Fset_buffer (XWINDOW (w)->buffer); | |
1591 | } | |
1592 | else | |
1593 | Fdelete_window (w); | |
7ab12479 JB |
1594 | } |
1595 | break; | |
1596 | ||
1597 | case GET_LARGEST_WINDOW: | |
7ab12479 JB |
1598 | /* Ignore dedicated windows and minibuffers. */ |
1599 | if (MINI_WINDOW_P (XWINDOW (w)) | |
265a9e55 | 1600 | || !NILP (XWINDOW (w)->dedicated)) |
7ab12479 JB |
1601 | break; |
1602 | { | |
1603 | struct window *best_window_ptr = XWINDOW (best_window); | |
1604 | struct window *w_ptr = XWINDOW (w); | |
6b54027b RS |
1605 | if (NILP (best_window) |
1606 | || (XFASTINT (w_ptr->height) * XFASTINT (w_ptr->width) | |
1607 | > (XFASTINT (best_window_ptr->height) | |
1608 | * XFASTINT (best_window_ptr->width)))) | |
7ab12479 JB |
1609 | best_window = w; |
1610 | } | |
1611 | break; | |
1612 | ||
1613 | case UNSHOW_BUFFER: | |
1614 | if (EQ (XWINDOW (w)->buffer, obj)) | |
1615 | { | |
1616 | /* Find another buffer to show in this window. */ | |
12cae7c0 | 1617 | Lisp_Object another_buffer; |
38ab08d1 | 1618 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (w))); |
b7354ddf | 1619 | another_buffer = Fother_buffer (obj, Qnil, XWINDOW (w)->frame); |
265a9e55 | 1620 | if (NILP (another_buffer)) |
7ab12479 JB |
1621 | another_buffer |
1622 | = Fget_buffer_create (build_string ("*scratch*")); | |
38ab08d1 RS |
1623 | /* If this window is dedicated, and in a frame of its own, |
1624 | kill the frame. */ | |
1625 | if (EQ (w, FRAME_ROOT_WINDOW (f)) | |
596122a7 | 1626 | && !NILP (XWINDOW (w)->dedicated) |
38ab08d1 | 1627 | && other_visible_frames (f)) |
45945a7b RS |
1628 | { |
1629 | /* Skip the other windows on this frame. | |
1630 | There might be one, the minibuffer! */ | |
1631 | if (! EQ (w, last_window)) | |
1632 | while (f == XFRAME (WINDOW_FRAME (XWINDOW (next_window)))) | |
1633 | { | |
1634 | /* As we go, check for the end of the loop. | |
1635 | We mustn't start going around a second time. */ | |
1636 | if (EQ (next_window, last_window)) | |
1637 | { | |
1638 | last_window = w; | |
1639 | break; | |
1640 | } | |
1641 | next_window = Fnext_window (next_window, | |
1642 | mini ? Qt : Qnil, | |
1643 | frame_arg); | |
1644 | } | |
1645 | /* Now we can safely delete the frame. */ | |
1646 | Fdelete_frame (WINDOW_FRAME (XWINDOW (w)), Qnil); | |
1647 | } | |
38ab08d1 | 1648 | else |
38ab08d1 RS |
1649 | { |
1650 | /* Otherwise show a different buffer in the window. */ | |
1651 | XWINDOW (w)->dedicated = Qnil; | |
1652 | Fset_window_buffer (w, another_buffer); | |
1653 | if (EQ (w, selected_window)) | |
1654 | Fset_buffer (XWINDOW (w)->buffer); | |
1655 | } | |
7ab12479 JB |
1656 | } |
1657 | break; | |
3f8ab7bd RS |
1658 | |
1659 | /* Check for a window that has a killed buffer. */ | |
1660 | case CHECK_ALL_WINDOWS: | |
1661 | if (! NILP (XWINDOW (w)->buffer) | |
1662 | && NILP (XBUFFER (XWINDOW (w)->buffer)->name)) | |
1663 | abort (); | |
7ab12479 | 1664 | } |
4b206065 JB |
1665 | |
1666 | if (EQ (w, last_window)) | |
1667 | break; | |
1668 | ||
7ab12479 JB |
1669 | w = next_window; |
1670 | } | |
7ab12479 JB |
1671 | |
1672 | return best_window; | |
37962e60 | 1673 | } |
605be8af | 1674 | |
3f8ab7bd RS |
1675 | /* Used for debugging. Abort if any window has a dead buffer. */ |
1676 | ||
233a4a2c | 1677 | void |
3f8ab7bd RS |
1678 | check_all_windows () |
1679 | { | |
1680 | window_loop (CHECK_ALL_WINDOWS, Qnil, 1, Qt); | |
1681 | } | |
1682 | ||
7ab12479 JB |
1683 | DEFUN ("get-lru-window", Fget_lru_window, Sget_lru_window, 0, 1, 0, |
1684 | "Return the window least recently selected or used for display.\n\ | |
89bca612 | 1685 | If optional argument FRAME is `visible', search all visible frames.\n\ |
cee67da9 | 1686 | If FRAME is 0, search all visible and iconified frames.\n\ |
89bca612 RS |
1687 | If FRAME is t, search all frames.\n\ |
1688 | If FRAME is nil, search only the selected frame.\n\ | |
1689 | If FRAME is a frame, search only that frame.") | |
1690 | (frame) | |
1691 | Lisp_Object frame; | |
7ab12479 JB |
1692 | { |
1693 | register Lisp_Object w; | |
1694 | /* First try for a window that is full-width */ | |
89bca612 | 1695 | w = window_loop (GET_LRU_WINDOW, Qt, 0, frame); |
265a9e55 | 1696 | if (!NILP (w) && !EQ (w, selected_window)) |
7ab12479 JB |
1697 | return w; |
1698 | /* If none of them, try the rest */ | |
89bca612 | 1699 | return window_loop (GET_LRU_WINDOW, Qnil, 0, frame); |
7ab12479 JB |
1700 | } |
1701 | ||
1702 | DEFUN ("get-largest-window", Fget_largest_window, Sget_largest_window, 0, 1, 0, | |
1703 | "Return the largest window in area.\n\ | |
89bca612 | 1704 | If optional argument FRAME is `visible', search all visible frames.\n\ |
cee67da9 | 1705 | If FRAME is 0, search all visible and iconified frames.\n\ |
89bca612 RS |
1706 | If FRAME is t, search all frames.\n\ |
1707 | If FRAME is nil, search only the selected frame.\n\ | |
1708 | If FRAME is a frame, search only that frame.") | |
44fa5b1e JB |
1709 | (frame) |
1710 | Lisp_Object frame; | |
7ab12479 JB |
1711 | { |
1712 | return window_loop (GET_LARGEST_WINDOW, Qnil, 0, | |
44fa5b1e | 1713 | frame); |
7ab12479 JB |
1714 | } |
1715 | ||
1716 | DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 1, 2, 0, | |
1717 | "Return a window currently displaying BUFFER, or nil if none.\n\ | |
89bca612 | 1718 | If optional argument FRAME is `visible', search all visible frames.\n\ |
f812f9c6 | 1719 | If optional argument FRAME is 0, search all visible and iconified frames.\n\ |
89bca612 | 1720 | If FRAME is t, search all frames.\n\ |
1bc981d2 | 1721 | If FRAME is nil, search only the selected frame.\n\ |
89bca612 | 1722 | If FRAME is a frame, search only that frame.") |
44fa5b1e JB |
1723 | (buffer, frame) |
1724 | Lisp_Object buffer, frame; | |
7ab12479 JB |
1725 | { |
1726 | buffer = Fget_buffer (buffer); | |
017b2bad | 1727 | if (BUFFERP (buffer)) |
44fa5b1e | 1728 | return window_loop (GET_BUFFER_WINDOW, buffer, 1, frame); |
7ab12479 JB |
1729 | else |
1730 | return Qnil; | |
1731 | } | |
1732 | ||
1733 | DEFUN ("delete-other-windows", Fdelete_other_windows, Sdelete_other_windows, | |
1734 | 0, 1, "", | |
44fa5b1e | 1735 | "Make WINDOW (or the selected window) fill its frame.\n\ |
f16a1ed3 RS |
1736 | Only the frame WINDOW is on is affected.\n\ |
1737 | This function tries to reduce display jumps\n\ | |
1738 | by keeping the text previously visible in WINDOW\n\ | |
1739 | in the same place on the frame. Doing this depends on\n\ | |
1740 | the value of (window-start WINDOW), so if calling this function\n\ | |
1741 | in a program gives strange scrolling, make sure the window-start\n\ | |
1742 | value is reasonable when this function is called.") | |
7ab12479 JB |
1743 | (window) |
1744 | Lisp_Object window; | |
1745 | { | |
1746 | struct window *w; | |
00d3d838 | 1747 | int startpos; |
7ab12479 JB |
1748 | int top; |
1749 | ||
265a9e55 | 1750 | if (NILP (window)) |
7ab12479 JB |
1751 | window = selected_window; |
1752 | else | |
605be8af | 1753 | CHECK_LIVE_WINDOW (window, 0); |
7ab12479 JB |
1754 | |
1755 | w = XWINDOW (window); | |
a2b38b3c | 1756 | |
00d3d838 | 1757 | startpos = marker_position (w->start); |
5500c422 | 1758 | top = XFASTINT (w->top) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w))); |
7ab12479 | 1759 | |
a2b38b3c RS |
1760 | if (MINI_WINDOW_P (w) && top > 0) |
1761 | error ("Can't expand minibuffer to full frame"); | |
1762 | ||
70728a80 | 1763 | window_loop (DELETE_OTHER_WINDOWS, window, 0, WINDOW_FRAME (w)); |
7ab12479 | 1764 | |
00d3d838 KH |
1765 | /* Try to minimize scrolling, by setting the window start to the point |
1766 | will cause the text at the old window start to be at the same place | |
1767 | on the frame. But don't try to do this if the window start is | |
1768 | outside the visible portion (as might happen when the display is | |
1769 | not current, due to typeahead). */ | |
1770 | if (startpos >= BUF_BEGV (XBUFFER (w->buffer)) | |
1771 | && startpos <= BUF_ZV (XBUFFER (w->buffer))) | |
1772 | { | |
1773 | struct position pos; | |
1774 | struct buffer *obuf = current_buffer; | |
1775 | ||
1776 | Fset_buffer (w->buffer); | |
1777 | /* This computation used to temporarily move point, but that can | |
1778 | have unwanted side effects due to text properties. */ | |
0383eb57 | 1779 | pos = *vmotion (startpos, -top, w); |
4d047f50 | 1780 | |
b73ea88e RS |
1781 | set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos); |
1782 | w->start_at_line_beg = ((pos.bytepos == BEGV_BYTE | |
1783 | || FETCH_BYTE (pos.bytepos - 1) == '\n') ? Qt | |
00d3d838 | 1784 | : Qnil); |
80622eec RS |
1785 | /* We need to do this, so that the window-scroll-functions |
1786 | get called. */ | |
4d047f50 | 1787 | w->optional_new_start = Qt; |
00d3d838 KH |
1788 | |
1789 | set_buffer_internal (obuf); | |
1790 | } | |
5500c422 | 1791 | |
7ab12479 JB |
1792 | return Qnil; |
1793 | } | |
1794 | ||
1795 | DEFUN ("delete-windows-on", Fdelete_windows_on, Sdelete_windows_on, | |
3cbbb729 | 1796 | 1, 2, "bDelete windows on (buffer): ", |
26f6279d JB |
1797 | "Delete all windows showing BUFFER.\n\ |
1798 | Optional second argument FRAME controls which frames are affected.\n\ | |
c520265e RS |
1799 | If optional argument FRAME is `visible', search all visible frames.\n\ |
1800 | If FRAME is 0, search all visible and iconified frames.\n\ | |
1801 | If FRAME is nil, search all frames.\n\ | |
1802 | If FRAME is t, search only the selected frame.\n\ | |
1803 | If FRAME is a frame, search only that frame.") | |
26f6279d JB |
1804 | (buffer, frame) |
1805 | Lisp_Object buffer, frame; | |
7ab12479 | 1806 | { |
26f6279d JB |
1807 | /* FRAME uses t and nil to mean the opposite of what window_loop |
1808 | expects. */ | |
c520265e RS |
1809 | if (NILP (frame)) |
1810 | frame = Qt; | |
1811 | else if (EQ (frame, Qt)) | |
1812 | frame = Qnil; | |
26f6279d | 1813 | |
265a9e55 | 1814 | if (!NILP (buffer)) |
7ab12479 JB |
1815 | { |
1816 | buffer = Fget_buffer (buffer); | |
1817 | CHECK_BUFFER (buffer, 0); | |
26f6279d | 1818 | window_loop (DELETE_BUFFER_WINDOWS, buffer, 0, frame); |
7ab12479 | 1819 | } |
5500c422 | 1820 | |
7ab12479 JB |
1821 | return Qnil; |
1822 | } | |
1823 | ||
1824 | DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows, | |
1825 | Sreplace_buffer_in_windows, | |
1826 | 1, 1, "bReplace buffer in windows: ", | |
1827 | "Replace BUFFER with some other buffer in all windows showing it.") | |
1828 | (buffer) | |
1829 | Lisp_Object buffer; | |
1830 | { | |
265a9e55 | 1831 | if (!NILP (buffer)) |
7ab12479 JB |
1832 | { |
1833 | buffer = Fget_buffer (buffer); | |
1834 | CHECK_BUFFER (buffer, 0); | |
1835 | window_loop (UNSHOW_BUFFER, buffer, 0, Qt); | |
1836 | } | |
1837 | return Qnil; | |
1838 | } | |
ff58478b RS |
1839 | |
1840 | /* Replace BUFFER with some other buffer in all windows | |
1841 | of all frames, even those on other keyboards. */ | |
1842 | ||
1843 | void | |
1844 | replace_buffer_in_all_windows (buffer) | |
1845 | Lisp_Object buffer; | |
1846 | { | |
27abb84f | 1847 | #ifdef MULTI_KBOARD |
ff58478b RS |
1848 | Lisp_Object tail, frame; |
1849 | ||
ff58478b RS |
1850 | /* A single call to window_loop won't do the job |
1851 | because it only considers frames on the current keyboard. | |
1852 | So loop manually over frames, and handle each one. */ | |
1853 | FOR_EACH_FRAME (tail, frame) | |
db7f721d | 1854 | window_loop (UNSHOW_BUFFER, buffer, 1, frame); |
ff58478b | 1855 | #else |
db7f721d | 1856 | window_loop (UNSHOW_BUFFER, buffer, 1, Qt); |
ff58478b RS |
1857 | #endif |
1858 | } | |
7ab12479 JB |
1859 | \f |
1860 | /* Set the height of WINDOW and all its inferiors. */ | |
a481b3ea JB |
1861 | |
1862 | /* The smallest acceptable dimensions for a window. Anything smaller | |
1863 | might crash Emacs. */ | |
5500c422 | 1864 | |
a481b3ea JB |
1865 | #define MIN_SAFE_WINDOW_WIDTH (2) |
1866 | #define MIN_SAFE_WINDOW_HEIGHT (2) | |
1867 | ||
1868 | /* Make sure that window_min_height and window_min_width are | |
1869 | not too small; if they are, set them to safe minima. */ | |
1870 | ||
1871 | static void | |
1872 | check_min_window_sizes () | |
1873 | { | |
1874 | /* Smaller values might permit a crash. */ | |
1875 | if (window_min_width < MIN_SAFE_WINDOW_WIDTH) | |
1876 | window_min_width = MIN_SAFE_WINDOW_WIDTH; | |
1877 | if (window_min_height < MIN_SAFE_WINDOW_HEIGHT) | |
1878 | window_min_height = MIN_SAFE_WINDOW_HEIGHT; | |
1879 | } | |
1880 | ||
1881 | /* If *ROWS or *COLS are too small a size for FRAME, set them to the | |
1882 | minimum allowable size. */ | |
5500c422 | 1883 | |
605be8af | 1884 | void |
a481b3ea | 1885 | check_frame_size (frame, rows, cols) |
605be8af JB |
1886 | FRAME_PTR frame; |
1887 | int *rows, *cols; | |
a481b3ea | 1888 | { |
628df3bf | 1889 | /* For height, we have to see: |
37962e60 | 1890 | whether the frame has a minibuffer, |
628df3bf JB |
1891 | whether it wants a mode line, and |
1892 | whether it has a menu bar. */ | |
a481b3ea | 1893 | int min_height = |
79f92720 JB |
1894 | (FRAME_MINIBUF_ONLY_P (frame) ? MIN_SAFE_WINDOW_HEIGHT - 1 |
1895 | : (! FRAME_HAS_MINIBUF_P (frame)) ? MIN_SAFE_WINDOW_HEIGHT | |
a481b3ea | 1896 | : 2 * MIN_SAFE_WINDOW_HEIGHT - 1); |
5500c422 GM |
1897 | |
1898 | if (FRAME_TOP_MARGIN (frame) > 0) | |
1899 | min_height += FRAME_TOP_MARGIN (frame); | |
a481b3ea JB |
1900 | |
1901 | if (*rows < min_height) | |
1902 | *rows = min_height; | |
1903 | if (*cols < MIN_SAFE_WINDOW_WIDTH) | |
1904 | *cols = MIN_SAFE_WINDOW_WIDTH; | |
1905 | } | |
1906 | ||
c1636aa6 | 1907 | |
233a4a2c GM |
1908 | /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means |
1909 | check if W's width can be changed, otherwise check W's height. | |
1910 | CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's | |
1911 | siblings, too. If none of the siblings is resizable, WINDOW isn't | |
1912 | either. */ | |
c1636aa6 | 1913 | |
233a4a2c GM |
1914 | static int |
1915 | window_fixed_size_p (w, width_p, check_siblings_p) | |
1916 | struct window *w; | |
1917 | int width_p, check_siblings_p; | |
1918 | { | |
1919 | int fixed_p; | |
1920 | struct window *c; | |
1921 | ||
1922 | if (!NILP (w->hchild)) | |
1923 | { | |
1924 | c = XWINDOW (w->hchild); | |
1925 | ||
1926 | if (width_p) | |
1927 | { | |
1928 | /* A horiz. combination is fixed-width if all of if its | |
1929 | children are. */ | |
1930 | while (c && window_fixed_size_p (c, width_p, 0)) | |
1931 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; | |
1932 | fixed_p = c == NULL; | |
1933 | } | |
1934 | else | |
1935 | { | |
1936 | /* A horiz. combination is fixed-height if one of if its | |
1937 | children is. */ | |
1938 | while (c && !window_fixed_size_p (c, width_p, 0)) | |
1939 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; | |
1940 | fixed_p = c != NULL; | |
1941 | } | |
1942 | } | |
1943 | else if (!NILP (w->vchild)) | |
1944 | { | |
1945 | c = XWINDOW (w->vchild); | |
1946 | ||
1947 | if (width_p) | |
1948 | { | |
1949 | /* A vert. combination is fixed-width if one of if its | |
1950 | children is. */ | |
1951 | while (c && !window_fixed_size_p (c, width_p, 0)) | |
1952 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; | |
1953 | fixed_p = c != NULL; | |
1954 | } | |
1955 | else | |
1956 | { | |
1957 | /* A vert. combination is fixed-height if all of if its | |
1958 | children are. */ | |
1959 | while (c && window_fixed_size_p (c, width_p, 0)) | |
1960 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; | |
1961 | fixed_p = c == NULL; | |
1962 | } | |
1963 | } | |
1964 | else if (BUFFERP (w->buffer)) | |
1965 | { | |
1966 | Lisp_Object val; | |
1967 | struct buffer *old = current_buffer; | |
1968 | ||
1969 | current_buffer = XBUFFER (w->buffer); | |
1970 | val = find_symbol_value (Qfixed_window_size); | |
1971 | current_buffer = old; | |
1972 | ||
1973 | fixed_p = 0; | |
1974 | if (!EQ (val, Qunbound)) | |
1975 | { | |
1976 | fixed_p = !NILP (val); | |
1977 | ||
1978 | if (fixed_p | |
1979 | && ((EQ (val, Qheight) && width_p) | |
1980 | || (EQ (val, Qwidth) && !width_p))) | |
1981 | fixed_p = 0; | |
1982 | } | |
1983 | ||
1984 | /* Can't tell if this one is resizable without looking at | |
1985 | siblings. If all siblings are fixed-size this one is too. */ | |
1986 | if (!fixed_p && check_siblings_p && WINDOWP (w->parent)) | |
1987 | { | |
1988 | Lisp_Object child; | |
1989 | ||
1990 | for (child = w->prev; !NILP (child); child = XWINDOW (child)->prev) | |
1991 | if (!window_fixed_size_p (XWINDOW (child), width_p, 0)) | |
1992 | break; | |
1993 | ||
1994 | if (NILP (child)) | |
1995 | for (child = w->next; !NILP (child); child = XWINDOW (child)->next) | |
1996 | if (!window_fixed_size_p (XWINDOW (child), width_p, 0)) | |
1997 | break; | |
1998 | ||
1999 | if (NILP (child)) | |
2000 | fixed_p = 1; | |
2001 | } | |
2002 | } | |
2003 | else | |
2004 | fixed_p = 1; | |
2005 | ||
2006 | return fixed_p; | |
2007 | } | |
2008 | ||
2009 | ||
2010 | /* Return the minimum size of window W, not taking fixed-width windows | |
2011 | into account. WIDTH_P non-zero means return the minimum width, | |
2012 | otherwise return the minimum height. If W is a combination window, | |
2013 | compute the minimum size from the minimum sizes of W's children. */ | |
2014 | ||
2015 | static int | |
2016 | window_min_size_1 (w, width_p) | |
c1636aa6 GM |
2017 | struct window *w; |
2018 | int width_p; | |
2019 | { | |
233a4a2c | 2020 | struct window *c; |
c1636aa6 GM |
2021 | int size; |
2022 | ||
233a4a2c GM |
2023 | if (!NILP (w->hchild)) |
2024 | { | |
2025 | c = XWINDOW (w->hchild); | |
2026 | size = 0; | |
2027 | ||
2028 | if (width_p) | |
2029 | { | |
2030 | /* The min width of a horizontal combination is | |
2031 | the sum of the min widths of its children. */ | |
2032 | while (c) | |
2033 | { | |
2034 | size += window_min_size_1 (c, width_p); | |
2035 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; | |
2036 | } | |
2037 | } | |
2038 | else | |
2039 | { | |
2040 | /* The min height a horizontal combination equals | |
2041 | the maximum of all min height of its children. */ | |
2042 | while (c) | |
2043 | { | |
2044 | int min_size = window_min_size_1 (c, width_p); | |
2045 | size = max (min_size, size); | |
2046 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; | |
2047 | } | |
2048 | } | |
2049 | } | |
2050 | else if (!NILP (w->vchild)) | |
2051 | { | |
2052 | c = XWINDOW (w->vchild); | |
2053 | size = 0; | |
2054 | ||
2055 | if (width_p) | |
2056 | { | |
2057 | /* The min width of a vertical combination is | |
2058 | the maximum of the min widths of its children. */ | |
2059 | while (c) | |
2060 | { | |
2061 | int min_size = window_min_size_1 (c, width_p); | |
2062 | size = max (min_size, size); | |
2063 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; | |
2064 | } | |
2065 | } | |
2066 | else | |
2067 | { | |
2068 | /* The min height of a vertical combination equals | |
2069 | the sum of the min height of its children. */ | |
2070 | while (c) | |
2071 | { | |
2072 | size += window_min_size_1 (c, width_p); | |
2073 | c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL; | |
2074 | } | |
2075 | } | |
2076 | } | |
c1636aa6 GM |
2077 | else |
2078 | { | |
233a4a2c GM |
2079 | if (width_p) |
2080 | size = window_min_width; | |
c1636aa6 | 2081 | else |
233a4a2c GM |
2082 | { |
2083 | if (MINI_WINDOW_P (w) | |
2084 | || (!WINDOW_WANTS_MODELINE_P (w) | |
2085 | && !WINDOW_WANTS_TOP_LINE_P (w))) | |
2086 | size = 1; | |
2087 | else | |
2088 | size = window_min_height; | |
2089 | } | |
c1636aa6 GM |
2090 | } |
2091 | ||
2092 | return size; | |
2093 | } | |
2094 | ||
2095 | ||
233a4a2c GM |
2096 | /* Return the minimum size of window W, taking fixed-size windows into |
2097 | account. WIDTH_P non-zero means return the minimum width, | |
2098 | otherwise return the minimum height. Set *FIXED to 1 if W is | |
2099 | fixed-size unless FIXED is null. */ | |
7ab12479 | 2100 | |
233a4a2c GM |
2101 | static int |
2102 | window_min_size (w, width_p, fixed) | |
2103 | struct window *w; | |
2104 | int width_p, *fixed; | |
2105 | { | |
2106 | int size, fixed_p; | |
2107 | ||
2108 | fixed_p = window_fixed_size_p (w, width_p, 1); | |
2109 | if (fixed) | |
2110 | *fixed = fixed_p; | |
2111 | ||
2112 | if (fixed_p) | |
2113 | size = width_p ? XFASTINT (w->width) : XFASTINT (w->height); | |
2114 | else | |
2115 | size = window_min_size_1 (w, width_p); | |
2116 | ||
2117 | return size; | |
2118 | } | |
2119 | ||
2120 | ||
2121 | /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set | |
2122 | WINDOW's width. Resize WINDOW's children, if any, so that they | |
2123 | keep their proportionate size relative to WINDOW. Propagate | |
2124 | WINDOW's top or left edge position to children. Delete windows | |
2125 | that become too small unless NODELETE_P is non-zero. */ | |
2126 | ||
2127 | static void | |
2128 | size_window (window, size, width_p, nodelete_p) | |
7ab12479 | 2129 | Lisp_Object window; |
233a4a2c | 2130 | int size, width_p, nodelete_p; |
7ab12479 | 2131 | { |
233a4a2c GM |
2132 | struct window *w = XWINDOW (window); |
2133 | struct window *c; | |
2134 | Lisp_Object child, *forward, *sideward; | |
2135 | int old_size, min_size; | |
7ab12479 | 2136 | |
a481b3ea | 2137 | check_min_window_sizes (); |
233a4a2c | 2138 | |
b5f05b50 GM |
2139 | /* If the window has been "too small" at one point, |
2140 | don't delete it for being "too small" in the future. | |
2141 | Preserve it as long as that is at all possible. */ | |
233a4a2c GM |
2142 | if (width_p) |
2143 | { | |
2144 | old_size = XFASTINT (w->width); | |
2145 | min_size = window_min_width; | |
2146 | } | |
2147 | else | |
2148 | { | |
2149 | old_size = XFASTINT (w->height); | |
2150 | min_size = window_min_height; | |
2151 | } | |
2152 | ||
2153 | if (old_size < window_min_width) | |
b5f05b50 GM |
2154 | w->too_small_ok = Qt; |
2155 | ||
233a4a2c GM |
2156 | /* Maybe delete WINDOW if it's too small. */ |
2157 | if (!nodelete_p && !NILP (w->parent)) | |
7ab12479 | 2158 | { |
233a4a2c | 2159 | int min_size; |
b5f05b50 GM |
2160 | |
2161 | if (!MINI_WINDOW_P (w) && !NILP (w->too_small_ok)) | |
233a4a2c | 2162 | min_size = width_p ? MIN_SAFE_WINDOW_WIDTH : MIN_SAFE_WINDOW_HEIGHT; |
b5f05b50 | 2163 | else |
233a4a2c | 2164 | min_size = width_p ? window_min_width : window_min_height; |
b5f05b50 | 2165 | |
233a4a2c | 2166 | if (size < min_size) |
c1636aa6 GM |
2167 | { |
2168 | delete_window (window); | |
2169 | return; | |
2170 | } | |
7ab12479 JB |
2171 | } |
2172 | ||
233a4a2c | 2173 | /* Set redisplay hints. */ |
d834a2e9 | 2174 | XSETFASTINT (w->last_modified, 0); |
3cd21523 | 2175 | XSETFASTINT (w->last_overlay_modified, 0); |
7ab12479 | 2176 | windows_or_buffers_changed++; |
29aeee73 RS |
2177 | FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w))) = 1; |
2178 | ||
233a4a2c GM |
2179 | if (width_p) |
2180 | { | |
2181 | sideward = &w->vchild; | |
2182 | forward = &w->hchild; | |
2183 | XSETFASTINT (w->width, size); | |
2184 | } | |
2185 | else | |
2186 | { | |
2187 | sideward = &w->hchild; | |
2188 | forward = &w->vchild; | |
2189 | XSETFASTINT (w->height, size); | |
2190 | } | |
2191 | ||
2192 | if (!NILP (*sideward)) | |
7ab12479 | 2193 | { |
233a4a2c | 2194 | for (child = *sideward; !NILP (child); child = c->next) |
7ab12479 | 2195 | { |
233a4a2c GM |
2196 | c = XWINDOW (child); |
2197 | if (width_p) | |
2198 | c->left = w->left; | |
2199 | else | |
2200 | c->top = w->top; | |
2201 | size_window (child, size, width_p, nodelete_p); | |
7ab12479 JB |
2202 | } |
2203 | } | |
233a4a2c | 2204 | else if (!NILP (*forward)) |
7ab12479 | 2205 | { |
233a4a2c GM |
2206 | int fixed_size, each, extra, n; |
2207 | int resize_fixed_p, nfixed; | |
2208 | int last_pos, first_pos, nchildren; | |
2209 | ||
2210 | /* Determine the fixed-size portion of the this window, and the | |
2211 | number of child windows. */ | |
2212 | fixed_size = nchildren = nfixed = 0; | |
2213 | for (child = *forward; !NILP (child); child = c->next, ++nchildren) | |
7ab12479 JB |
2214 | { |
2215 | c = XWINDOW (child); | |
233a4a2c GM |
2216 | if (window_fixed_size_p (c, width_p, 0)) |
2217 | { | |
2218 | fixed_size += (width_p | |
2219 | ? XFASTINT (c->width) : XFASTINT (c->height)); | |
2220 | ++nfixed; | |
2221 | } | |
2222 | } | |
7ab12479 | 2223 | |
233a4a2c GM |
2224 | /* If the new size is smaller than fixed_size, or if there |
2225 | aren't any resizable windows, allow resizing fixed-size | |
2226 | windows. */ | |
2227 | resize_fixed_p = nfixed == nchildren || size < fixed_size; | |
2228 | ||
2229 | /* Compute how many lines/columns to add to each child. The | |
2230 | value of extra takes care of rounding errors. */ | |
2231 | n = resize_fixed_p ? nchildren : nchildren - nfixed; | |
2232 | each = (size - old_size) / n; | |
2233 | extra = (size - old_size) - n * each; | |
2234 | ||
2235 | /* Compute new children heights and edge positions. */ | |
2236 | first_pos = width_p ? XFASTINT (w->left) : XFASTINT (w->top); | |
2237 | last_pos = first_pos; | |
2238 | for (child = *forward; !NILP (child); child = c->next) | |
2239 | { | |
2240 | int new_size, old_size; | |
2241 | ||
2242 | c = XWINDOW (child); | |
2243 | old_size = width_p ? XFASTINT (c->width) : XFASTINT (c->height); | |
2244 | new_size = old_size; | |
7ab12479 | 2245 | |
233a4a2c GM |
2246 | /* The top or left edge position of this child equals the |
2247 | bottom or right edge of its predecessor. */ | |
2248 | if (width_p) | |
2249 | c->left = make_number (last_pos); | |
2250 | else | |
2251 | c->top = make_number (last_pos); | |
7ab12479 | 2252 | |
233a4a2c GM |
2253 | /* If this child can be resized, do it. */ |
2254 | if (resize_fixed_p || !window_fixed_size_p (c, width_p, 0)) | |
2255 | { | |
2256 | new_size = old_size + each + extra; | |
2257 | extra = 0; | |
2258 | } | |
2259 | ||
2260 | /* Set new height. Note that size_window also propagates | |
2261 | edge positions to children, so it's not a no-op if we | |
2262 | didn't change the child's size. */ | |
2263 | size_window (child, new_size, width_p, 1); | |
2264 | ||
2265 | /* Remember the bottom/right edge position of this child; it | |
2266 | will be used to set the top/left edge of the next child. */ | |
2267 | last_pos += new_size; | |
7ab12479 | 2268 | } |
233a4a2c GM |
2269 | |
2270 | /* We should have covered the parent exactly with child windows. */ | |
2271 | xassert (size == last_pos - first_pos); | |
2272 | ||
7ab12479 | 2273 | /* Now delete any children that became too small. */ |
233a4a2c GM |
2274 | if (!nodelete_p) |
2275 | for (child = *forward; !NILP (child); child = c->next) | |
7ab12479 | 2276 | { |
233a4a2c GM |
2277 | int child_size; |
2278 | c = XWINDOW (child); | |
2279 | child_size = width_p ? XFASTINT (c->width) : XFASTINT (c->height); | |
2280 | size_window (child, child_size, width_p, 0); | |
7ab12479 JB |
2281 | } |
2282 | } | |
2283 | } | |
2284 | ||
233a4a2c GM |
2285 | /* Set WINDOW's height to HEIGHT, and recursively change the height of |
2286 | WINDOW's children. NODELETE non-zero means don't delete windows | |
2287 | that become too small in the process. (The caller should check | |
2288 | later and do so if appropriate.) */ | |
7ab12479 | 2289 | |
5e14b1fc | 2290 | void |
233a4a2c | 2291 | set_window_height (window, height, nodelete) |
7ab12479 | 2292 | Lisp_Object window; |
233a4a2c | 2293 | int height; |
7ab12479 JB |
2294 | int nodelete; |
2295 | { | |
233a4a2c GM |
2296 | size_window (window, height, 0, nodelete); |
2297 | } | |
7ab12479 | 2298 | |
7ab12479 | 2299 | |
233a4a2c GM |
2300 | /* Set WINDOW's width to WIDTH, and recursively change the width of |
2301 | WINDOW's children. NODELETE non-zero means don't delete windows | |
2302 | that become too small in the process. (The caller should check | |
2303 | later and do so if appropriate.) */ | |
7ab12479 | 2304 | |
233a4a2c GM |
2305 | void |
2306 | set_window_width (window, width, nodelete) | |
2307 | Lisp_Object window; | |
2308 | int width; | |
2309 | int nodelete; | |
2310 | { | |
2311 | size_window (window, width, 1, nodelete); | |
7ab12479 | 2312 | } |
233a4a2c | 2313 | |
7ab12479 | 2314 | \f |
1d8d96fa | 2315 | int window_select_count; |
7ab12479 | 2316 | |
5b03d3c0 RS |
2317 | Lisp_Object |
2318 | Fset_window_buffer_unwind (obuf) | |
2319 | Lisp_Object obuf; | |
2320 | { | |
2321 | Fset_buffer (obuf); | |
2322 | return Qnil; | |
2323 | } | |
2324 | ||
7ab12479 | 2325 | |
5500c422 GM |
2326 | /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero |
2327 | means it's allowed to run hooks. See make_frame for a case where | |
2328 | it's not allowed. */ | |
7ab12479 | 2329 | |
5500c422 GM |
2330 | void |
2331 | set_window_buffer (window, buffer, run_hooks_p) | |
2332 | Lisp_Object window, buffer; | |
2333 | int run_hooks_p; | |
2334 | { | |
2335 | struct window *w = XWINDOW (window); | |
2336 | struct buffer *b = XBUFFER (buffer); | |
2337 | int count = specpdl_ptr - specpdl; | |
7ab12479 JB |
2338 | |
2339 | w->buffer = buffer; | |
86e48436 RS |
2340 | |
2341 | if (EQ (window, selected_window)) | |
5500c422 | 2342 | b->last_selected_window = window; |
beb4e312 RS |
2343 | |
2344 | /* Update time stamps of buffer display. */ | |
5500c422 GM |
2345 | if (INTEGERP (b->display_count)) |
2346 | XSETINT (b->display_count, XINT (b->display_count) + 1); | |
2347 | b->display_time = Fcurrent_time (); | |
86e48436 | 2348 | |
d834a2e9 | 2349 | XSETFASTINT (w->window_end_pos, 0); |
5500c422 GM |
2350 | XSETFASTINT (w->window_end_vpos, 0); |
2351 | bzero (&w->last_cursor, sizeof w->last_cursor); | |
5a41ab94 | 2352 | w->window_end_valid = Qnil; |
dba06815 | 2353 | XSETFASTINT (w->hscroll, 0); |
5500c422 | 2354 | set_marker_both (w->pointm, buffer, BUF_PT (b), BUF_PT_BYTE (b)); |
7ab12479 | 2355 | set_marker_restricted (w->start, |
5500c422 | 2356 | make_number (b->last_window_start), |
7ab12479 JB |
2357 | buffer); |
2358 | w->start_at_line_beg = Qnil; | |
e36ab06b | 2359 | w->force_start = Qnil; |
d834a2e9 | 2360 | XSETFASTINT (w->last_modified, 0); |
3cd21523 | 2361 | XSETFASTINT (w->last_overlay_modified, 0); |
7ab12479 | 2362 | windows_or_buffers_changed++; |
5b03d3c0 RS |
2363 | |
2364 | /* We must select BUFFER for running the window-scroll-functions. | |
2365 | If WINDOW is selected, switch permanently. | |
2366 | Otherwise, switch but go back to the ambient buffer afterward. */ | |
7ab12479 JB |
2367 | if (EQ (window, selected_window)) |
2368 | Fset_buffer (buffer); | |
5b03d3c0 RS |
2369 | /* We can't check ! NILP (Vwindow_scroll_functions) here |
2370 | because that might itself be a local variable. */ | |
2371 | else if (window_initialized) | |
2372 | { | |
2373 | record_unwind_protect (Fset_window_buffer_unwind, Fcurrent_buffer ()); | |
2374 | Fset_buffer (buffer); | |
2375 | } | |
2376 | ||
5500c422 GM |
2377 | /* Set left and right marginal area width from buffer. */ |
2378 | Fset_window_margins (b->left_margin_width, b->right_margin_width, | |
2379 | window); | |
7ab12479 | 2380 | |
5500c422 GM |
2381 | if (run_hooks_p) |
2382 | { | |
2383 | if (! NILP (Vwindow_scroll_functions)) | |
2384 | run_hook_with_args_2 (Qwindow_scroll_functions, window, | |
2385 | Fmarker_position (w->start)); | |
2386 | ||
2387 | if (! NILP (Vwindow_configuration_change_hook) | |
2388 | && ! NILP (Vrun_hooks)) | |
2389 | call1 (Vrun_hooks, Qwindow_configuration_change_hook); | |
2390 | } | |
543f5fb1 | 2391 | |
5b03d3c0 | 2392 | unbind_to (count, Qnil); |
5500c422 | 2393 | } |
5b03d3c0 | 2394 | |
5500c422 GM |
2395 | |
2396 | DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 2, 0, | |
2397 | "Make WINDOW display BUFFER as its contents.\n\ | |
2398 | BUFFER can be a buffer or buffer name.") | |
2399 | (window, buffer) | |
2400 | register Lisp_Object window, buffer; | |
2401 | { | |
2402 | register Lisp_Object tem; | |
2403 | register struct window *w = decode_window (window); | |
2404 | struct buffer *b; | |
2405 | ||
2406 | buffer = Fget_buffer (buffer); | |
2407 | CHECK_BUFFER (buffer, 1); | |
2408 | ||
2409 | if (NILP (XBUFFER (buffer)->name)) | |
2410 | error ("Attempt to display deleted buffer"); | |
2411 | ||
2412 | tem = w->buffer; | |
2413 | if (NILP (tem)) | |
2414 | error ("Window is deleted"); | |
2415 | else if (! EQ (tem, Qt)) /* w->buffer is t when the window | |
2416 | is first being set up. */ | |
2417 | { | |
2418 | if (!NILP (w->dedicated) && !EQ (tem, buffer)) | |
2419 | error ("Window is dedicated to `%s'", | |
2420 | XSTRING (XBUFFER (tem)->name)->data); | |
2421 | ||
2422 | unshow_buffer (w); | |
2423 | } | |
2424 | ||
2425 | set_window_buffer (window, buffer, 1); | |
7ab12479 JB |
2426 | return Qnil; |
2427 | } | |
2428 | ||
2429 | DEFUN ("select-window", Fselect_window, Sselect_window, 1, 1, 0, | |
2430 | "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\ | |
beb4e312 RS |
2431 | If WINDOW is not already selected, also make WINDOW's buffer current.\n\ |
2432 | Note that the main editor command loop\n\ | |
2433 | selects the buffer of the selected window before each command.") | |
7ab12479 JB |
2434 | (window) |
2435 | register Lisp_Object window; | |
b7354ddf RS |
2436 | { |
2437 | return select_window_1 (window, 1); | |
2438 | } | |
2439 | \f | |
2440 | static Lisp_Object | |
2441 | select_window_1 (window, recordflag) | |
2442 | register Lisp_Object window; | |
2443 | int recordflag; | |
7ab12479 JB |
2444 | { |
2445 | register struct window *w; | |
2446 | register struct window *ow = XWINDOW (selected_window); | |
2447 | ||
605be8af | 2448 | CHECK_LIVE_WINDOW (window, 0); |
7ab12479 JB |
2449 | |
2450 | w = XWINDOW (window); | |
2451 | ||
265a9e55 | 2452 | if (NILP (w->buffer)) |
7ab12479 JB |
2453 | error ("Trying to select deleted window or non-leaf window"); |
2454 | ||
d834a2e9 | 2455 | XSETFASTINT (w->use_time, ++window_select_count); |
7ab12479 JB |
2456 | if (EQ (window, selected_window)) |
2457 | return window; | |
2458 | ||
596ae0cf RS |
2459 | if (! NILP (ow->buffer)) |
2460 | set_marker_both (ow->pointm, ow->buffer, | |
2461 | BUF_PT (XBUFFER (ow->buffer)), | |
2462 | BUF_PT_BYTE (XBUFFER (ow->buffer))); | |
7ab12479 JB |
2463 | |
2464 | selected_window = window; | |
44fa5b1e | 2465 | if (XFRAME (WINDOW_FRAME (w)) != selected_frame) |
7ab12479 | 2466 | { |
44fa5b1e | 2467 | XFRAME (WINDOW_FRAME (w))->selected_window = window; |
147a6615 RS |
2468 | /* Use this rather than Fhandle_switch_frame |
2469 | so that FRAME_FOCUS_FRAME is moved appropriately as we | |
2470 | move around in the state where a minibuffer in a separate | |
2471 | frame is active. */ | |
2472 | Fselect_frame (WINDOW_FRAME (w), Qnil); | |
7ab12479 JB |
2473 | } |
2474 | else | |
44fa5b1e | 2475 | selected_frame->selected_window = window; |
7ab12479 | 2476 | |
b7354ddf RS |
2477 | if (recordflag) |
2478 | record_buffer (w->buffer); | |
7ab12479 JB |
2479 | Fset_buffer (w->buffer); |
2480 | ||
86e48436 RS |
2481 | XBUFFER (w->buffer)->last_selected_window = window; |
2482 | ||
7ab12479 JB |
2483 | /* Go to the point recorded in the window. |
2484 | This is important when the buffer is in more | |
2485 | than one window. It also matters when | |
2486 | redisplay_window has altered point after scrolling, | |
2487 | because it makes the change only in the window. */ | |
2488 | { | |
2489 | register int new_point = marker_position (w->pointm); | |
2490 | if (new_point < BEGV) | |
2491 | SET_PT (BEGV); | |
a9c95e08 | 2492 | else if (new_point > ZV) |
7ab12479 JB |
2493 | SET_PT (ZV); |
2494 | else | |
2495 | SET_PT (new_point); | |
2496 | } | |
2497 | ||
2498 | windows_or_buffers_changed++; | |
2499 | return window; | |
2500 | } | |
b7354ddf | 2501 | \f |
441a127e RS |
2502 | /* Deiconify the frame containing the window WINDOW, |
2503 | unless it is the selected frame; | |
2504 | then return WINDOW. | |
2505 | ||
2506 | The reason for the exception for the selected frame | |
2507 | is that it seems better not to change the selected frames visibility | |
2508 | merely because of displaying a different buffer in it. | |
2509 | The deiconification is useful when a buffer gets shown in | |
2510 | another frame that you were not using lately. */ | |
d07f802a RS |
2511 | |
2512 | static Lisp_Object | |
2513 | display_buffer_1 (window) | |
2514 | Lisp_Object window; | |
2515 | { | |
d07f802a RS |
2516 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (window))); |
2517 | FRAME_SAMPLE_VISIBILITY (f); | |
60117126 RS |
2518 | if (f != selected_frame) |
2519 | { | |
2520 | if (FRAME_ICONIFIED_P (f)) | |
2521 | Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window))); | |
37962e60 | 2522 | else if (FRAME_VISIBLE_P (f)) |
60117126 RS |
2523 | Fraise_frame (WINDOW_FRAME (XWINDOW (window))); |
2524 | } | |
d07f802a RS |
2525 | return window; |
2526 | } | |
2527 | ||
4628f7a4 | 2528 | DEFUN ("special-display-p", Fspecial_display_p, Sspecial_display_p, 1, 1, 0, |
0f7d64d2 GV |
2529 | "Returns non-nil if a buffer named BUFFER-NAME would be created specially.\n\ |
2530 | The value is actually t if the frame should be called with default frame\n\ | |
2531 | parameters, and a list of frame parameters if they were specified.\n\ | |
4628f7a4 EN |
2532 | See `special-display-buffer-names', and `special-display-regexps'.") |
2533 | (buffer_name) | |
2534 | Lisp_Object buffer_name; | |
2535 | { | |
2536 | Lisp_Object tem; | |
2537 | ||
2538 | CHECK_STRING (buffer_name, 1); | |
2539 | ||
2540 | tem = Fmember (buffer_name, Vspecial_display_buffer_names); | |
2541 | if (!NILP (tem)) | |
2542 | return Qt; | |
2543 | ||
2544 | tem = Fassoc (buffer_name, Vspecial_display_buffer_names); | |
2545 | if (!NILP (tem)) | |
2546 | return XCDR (tem); | |
2547 | ||
2548 | for (tem = Vspecial_display_regexps; CONSP (tem); tem = XCDR (tem)) | |
2549 | { | |
2550 | Lisp_Object car = XCAR (tem); | |
2551 | if (STRINGP (car) | |
2552 | && fast_string_match (car, buffer_name) >= 0) | |
2553 | return Qt; | |
2554 | else if (CONSP (car) | |
2555 | && STRINGP (XCAR (car)) | |
2556 | && fast_string_match (XCAR (car), buffer_name) >= 0) | |
0057b00a | 2557 | return XCDR (car); |
4628f7a4 EN |
2558 | } |
2559 | return Qnil; | |
2560 | } | |
2561 | ||
2562 | DEFUN ("same-window-p", Fsame_window_p, Ssame_window_p, 1, 1, 0, | |
0f7d64d2 | 2563 | "Returns non-nil if a new buffer named BUFFER-NAME would use the same window.\n\ |
4628f7a4 EN |
2564 | See `same-window-buffer-names' and `same-window-regexps'.") |
2565 | (buffer_name) | |
2566 | Lisp_Object buffer_name; | |
2567 | { | |
2568 | Lisp_Object tem; | |
2569 | ||
2570 | CHECK_STRING (buffer_name, 1); | |
2571 | ||
2572 | tem = Fmember (buffer_name, Vsame_window_buffer_names); | |
2573 | if (!NILP (tem)) | |
2574 | return Qt; | |
2575 | ||
2576 | tem = Fassoc (buffer_name, Vsame_window_buffer_names); | |
2577 | if (!NILP (tem)) | |
2578 | return Qt; | |
2579 | ||
2580 | for (tem = Vsame_window_regexps; CONSP (tem); tem = XCDR (tem)) | |
2581 | { | |
2582 | Lisp_Object car = XCAR (tem); | |
2583 | if (STRINGP (car) | |
2584 | && fast_string_match (car, buffer_name) >= 0) | |
2585 | return Qt; | |
2586 | else if (CONSP (car) | |
2587 | && STRINGP (XCAR (car)) | |
2588 | && fast_string_match (XCAR (car), buffer_name) >= 0) | |
2589 | return Qt; | |
2590 | } | |
2591 | return Qnil; | |
2592 | } | |
2593 | ||
53f76081 RS |
2594 | /* Use B so the default is (other-buffer). */ |
2595 | DEFUN ("display-buffer", Fdisplay_buffer, Sdisplay_buffer, 1, 3, | |
2596 | "BDisplay buffer: \nP", | |
7ab12479 JB |
2597 | "Make BUFFER appear in some window but don't select it.\n\ |
2598 | BUFFER can be a buffer or a buffer name.\n\ | |
2599 | If BUFFER is shown already in some window, just use that one,\n\ | |
2600 | unless the window is the selected window and the optional second\n\ | |
46d3268a | 2601 | argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).\n\ |
5141b901 | 2602 | If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.\n\ |
5abcf432 RS |
2603 | Returns the window displaying BUFFER.\n\ |
2604 | \n\ | |
2605 | The variables `special-display-buffer-names', `special-display-regexps',\n\ | |
2606 | `same-window-buffer-names', and `same-window-regexps' customize how certain\n\ | |
53f76081 RS |
2607 | buffer names are handled.\n\ |
2608 | \n\ | |
2609 | If optional argument FRAME is `visible', search all visible frames.\n\ | |
2610 | If FRAME is 0, search all visible and iconified frames.\n\ | |
2611 | If FRAME is t, search all frames.\n\ | |
2612 | If FRAME is a frame, search only that frame.\n\ | |
2613 | If FRAME is nil, search only the selected frame\n\ | |
2614 | (actually the last nonminibuffer frame),\n\ | |
2615 | unless `pop-up-frames' is non-nil,\n\ | |
2616 | which means search visible and iconified frames.") | |
2617 | (buffer, not_this_window, frame) | |
2618 | register Lisp_Object buffer, not_this_window, frame; | |
7ab12479 | 2619 | { |
aee631c2 | 2620 | register Lisp_Object window, tem, swp; |
7ab12479 | 2621 | |
aee631c2 | 2622 | swp = Qnil; |
7ab12479 JB |
2623 | buffer = Fget_buffer (buffer); |
2624 | CHECK_BUFFER (buffer, 0); | |
2625 | ||
265a9e55 | 2626 | if (!NILP (Vdisplay_buffer_function)) |
7ab12479 JB |
2627 | return call2 (Vdisplay_buffer_function, buffer, not_this_window); |
2628 | ||
265a9e55 | 2629 | if (NILP (not_this_window) |
7ab12479 | 2630 | && XBUFFER (XWINDOW (selected_window)->buffer) == XBUFFER (buffer)) |
d07f802a | 2631 | return display_buffer_1 (selected_window); |
7ab12479 | 2632 | |
855d8627 RS |
2633 | /* See if the user has specified this buffer should appear |
2634 | in the selected window. */ | |
2635 | if (NILP (not_this_window)) | |
2636 | { | |
aee631c2 RS |
2637 | swp = Fsame_window_p (XBUFFER (buffer)->name); |
2638 | if (!NILP (swp) && !no_switch_window (selected_window)) | |
c63dc4a2 RS |
2639 | { |
2640 | Fswitch_to_buffer (buffer, Qnil); | |
d07f802a | 2641 | return display_buffer_1 (selected_window); |
c63dc4a2 | 2642 | } |
855d8627 RS |
2643 | } |
2644 | ||
e8edb3ae | 2645 | /* If pop_up_frames, |
73dc5198 KH |
2646 | look for a window showing BUFFER on any visible or iconified frame. |
2647 | Otherwise search only the current frame. */ | |
53f76081 RS |
2648 | if (! NILP (frame)) |
2649 | tem = frame; | |
2650 | else if (pop_up_frames || last_nonminibuf_frame == 0) | |
73dc5198 KH |
2651 | XSETFASTINT (tem, 0); |
2652 | else | |
73dc5198 KH |
2653 | XSETFRAME (tem, last_nonminibuf_frame); |
2654 | window = Fget_buffer_window (buffer, tem); | |
265a9e55 JB |
2655 | if (!NILP (window) |
2656 | && (NILP (not_this_window) || !EQ (window, selected_window))) | |
f812f9c6 | 2657 | { |
d07f802a | 2658 | return display_buffer_1 (window); |
f812f9c6 | 2659 | } |
7ab12479 | 2660 | |
a90712c2 | 2661 | /* Certain buffer names get special handling. */ |
aee631c2 | 2662 | if (!NILP (Vspecial_display_function) && NILP (swp)) |
a90712c2 | 2663 | { |
4628f7a4 EN |
2664 | tem = Fspecial_display_p (XBUFFER (buffer)->name); |
2665 | if (EQ (tem, Qt)) | |
a90712c2 | 2666 | return call1 (Vspecial_display_function, buffer); |
4628f7a4 EN |
2667 | if (CONSP (tem)) |
2668 | return call2 (Vspecial_display_function, buffer, tem); | |
a90712c2 RS |
2669 | } |
2670 | ||
44fa5b1e JB |
2671 | /* If there are no frames open that have more than a minibuffer, |
2672 | we need to create a new frame. */ | |
2673 | if (pop_up_frames || last_nonminibuf_frame == 0) | |
7ab12479 | 2674 | { |
a90712c2 | 2675 | window = Fframe_selected_window (call0 (Vpop_up_frame_function)); |
7ab12479 | 2676 | Fset_window_buffer (window, buffer); |
d07f802a | 2677 | return display_buffer_1 (window); |
7ab12479 | 2678 | } |
7ab12479 | 2679 | |
43bad991 | 2680 | if (pop_up_windows |
44fa5b1e | 2681 | || FRAME_MINIBUF_ONLY_P (selected_frame) |
cee67da9 RS |
2682 | /* If the current frame is a special display frame, |
2683 | don't try to reuse its windows. */ | |
2684 | || !NILP (XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->dedicated) | |
43bad991 | 2685 | ) |
7ab12479 | 2686 | { |
12cae7c0 KH |
2687 | Lisp_Object frames; |
2688 | ||
37962e60 | 2689 | frames = Qnil; |
44fa5b1e | 2690 | if (FRAME_MINIBUF_ONLY_P (selected_frame)) |
74112613 | 2691 | XSETFRAME (frames, last_nonminibuf_frame); |
7ab12479 JB |
2692 | /* Don't try to create a window if would get an error */ |
2693 | if (split_height_threshold < window_min_height << 1) | |
2694 | split_height_threshold = window_min_height << 1; | |
2695 | ||
cee67da9 RS |
2696 | /* Note that both Fget_largest_window and Fget_lru_window |
2697 | ignore minibuffers and dedicated windows. | |
2698 | This means they can return nil. */ | |
7ab12479 | 2699 | |
cee67da9 RS |
2700 | /* If the frame we would try to split cannot be split, |
2701 | try other frames. */ | |
2702 | if (FRAME_NO_SPLIT_P (NILP (frames) ? selected_frame | |
2703 | : last_nonminibuf_frame)) | |
2704 | { | |
2705 | /* Try visible frames first. */ | |
2706 | window = Fget_largest_window (Qvisible); | |
2707 | /* If that didn't work, try iconified frames. */ | |
2708 | if (NILP (window)) | |
2709 | window = Fget_largest_window (make_number (0)); | |
2710 | if (NILP (window)) | |
2711 | window = Fget_largest_window (Qt); | |
2712 | } | |
2713 | else | |
2714 | window = Fget_largest_window (frames); | |
2715 | ||
92cca945 RS |
2716 | /* If we got a tall enough full-width window that can be split, |
2717 | split it. */ | |
265a9e55 | 2718 | if (!NILP (window) |
92cca945 | 2719 | && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame)) |
7ab12479 | 2720 | && window_height (window) >= split_height_threshold |
111e5992 | 2721 | && WINDOW_FULL_WIDTH_P (XWINDOW (window))) |
7ab12479 JB |
2722 | window = Fsplit_window (window, Qnil, Qnil); |
2723 | else | |
2724 | { | |
1942f68f RS |
2725 | Lisp_Object upper, lower, other; |
2726 | ||
44fa5b1e | 2727 | window = Fget_lru_window (frames); |
92cca945 RS |
2728 | /* If the LRU window is selected, and big enough, |
2729 | and can be split, split it. */ | |
cee67da9 | 2730 | if (!NILP (window) |
92cca945 | 2731 | && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame)) |
cee67da9 RS |
2732 | && (EQ (window, selected_window) |
2733 | || EQ (XWINDOW (window)->parent, Qnil)) | |
7ab12479 JB |
2734 | && window_height (window) >= window_min_height << 1) |
2735 | window = Fsplit_window (window, Qnil, Qnil); | |
cee67da9 | 2736 | /* If Fget_lru_window returned nil, try other approaches. */ |
48d9379d | 2737 | |
cee67da9 | 2738 | /* Try visible frames first. */ |
48d9379d RS |
2739 | if (NILP (window)) |
2740 | window = Fget_buffer_window (buffer, Qvisible); | |
cee67da9 RS |
2741 | if (NILP (window)) |
2742 | window = Fget_largest_window (Qvisible); | |
2743 | /* If that didn't work, try iconified frames. */ | |
48d9379d RS |
2744 | if (NILP (window)) |
2745 | window = Fget_buffer_window (buffer, make_number (0)); | |
cee67da9 RS |
2746 | if (NILP (window)) |
2747 | window = Fget_largest_window (make_number (0)); | |
2748 | /* Try invisible frames. */ | |
48d9379d RS |
2749 | if (NILP (window)) |
2750 | window = Fget_buffer_window (buffer, Qt); | |
cee67da9 RS |
2751 | if (NILP (window)) |
2752 | window = Fget_largest_window (Qt); | |
2753 | /* As a last resort, make a new frame. */ | |
2754 | if (NILP (window)) | |
2755 | window = Fframe_selected_window (call0 (Vpop_up_frame_function)); | |
1942f68f RS |
2756 | /* If window appears above or below another, |
2757 | even out their heights. */ | |
cac66e4f | 2758 | other = upper = lower = Qnil; |
1942f68f RS |
2759 | if (!NILP (XWINDOW (window)->prev)) |
2760 | other = upper = XWINDOW (window)->prev, lower = window; | |
2761 | if (!NILP (XWINDOW (window)->next)) | |
2762 | other = lower = XWINDOW (window)->next, upper = window; | |
2763 | if (!NILP (other) | |
2764 | /* Check that OTHER and WINDOW are vertically arrayed. */ | |
296b535c KH |
2765 | && !EQ (XWINDOW (other)->top, XWINDOW (window)->top) |
2766 | && (XFASTINT (XWINDOW (other)->height) | |
2767 | > XFASTINT (XWINDOW (window)->height))) | |
1942f68f | 2768 | { |
296b535c KH |
2769 | int total = (XFASTINT (XWINDOW (other)->height) |
2770 | + XFASTINT (XWINDOW (window)->height)); | |
8d77c0c8 KH |
2771 | Lisp_Object old_selected_window; |
2772 | old_selected_window = selected_window; | |
1942f68f | 2773 | |
8d77c0c8 | 2774 | selected_window = upper; |
296b535c KH |
2775 | change_window_height ((total / 2 |
2776 | - XFASTINT (XWINDOW (upper)->height)), | |
2777 | 0); | |
1942f68f RS |
2778 | selected_window = old_selected_window; |
2779 | } | |
7ab12479 JB |
2780 | } |
2781 | } | |
2782 | else | |
2783 | window = Fget_lru_window (Qnil); | |
2784 | ||
2785 | Fset_window_buffer (window, buffer); | |
d07f802a | 2786 | return display_buffer_1 (window); |
7ab12479 JB |
2787 | } |
2788 | ||
2789 | void | |
2790 | temp_output_buffer_show (buf) | |
2791 | register Lisp_Object buf; | |
2792 | { | |
2793 | register struct buffer *old = current_buffer; | |
2794 | register Lisp_Object window; | |
2795 | register struct window *w; | |
2796 | ||
bccd3dd1 RS |
2797 | XBUFFER (buf)->directory = current_buffer->directory; |
2798 | ||
7ab12479 | 2799 | Fset_buffer (buf); |
c6367666 | 2800 | BUF_SAVE_MODIFF (XBUFFER (buf)) = MODIFF; |
7ab12479 JB |
2801 | BEGV = BEG; |
2802 | ZV = Z; | |
2803 | SET_PT (BEG); | |
1479ef51 | 2804 | XBUFFER (buf)->clip_changed = 1; |
7ab12479 JB |
2805 | set_buffer_internal (old); |
2806 | ||
2807 | if (!EQ (Vtemp_buffer_show_function, Qnil)) | |
2808 | call1 (Vtemp_buffer_show_function, buf); | |
2809 | else | |
2810 | { | |
53f76081 | 2811 | window = Fdisplay_buffer (buf, Qnil, Qnil); |
7ab12479 | 2812 | |
44fa5b1e JB |
2813 | if (XFRAME (XWINDOW (window)->frame) != selected_frame) |
2814 | Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window))); | |
7ab12479 JB |
2815 | Vminibuf_scroll_window = window; |
2816 | w = XWINDOW (window); | |
d834a2e9 | 2817 | XSETFASTINT (w->hscroll, 0); |
b73ea88e RS |
2818 | set_marker_restricted_both (w->start, buf, 1, 1); |
2819 | set_marker_restricted_both (w->pointm, buf, 1, 1); | |
a58ec57d | 2820 | |
beb4e312 RS |
2821 | /* Run temp-buffer-show-hook, with the chosen window selected |
2822 | and it sbuffer current. */ | |
f52cca03 | 2823 | if (!NILP (Vrun_hooks)) |
2cccc823 | 2824 | { |
f52cca03 RS |
2825 | Lisp_Object tem; |
2826 | tem = Fboundp (Qtemp_buffer_show_hook); | |
2cccc823 RS |
2827 | if (!NILP (tem)) |
2828 | { | |
f52cca03 RS |
2829 | tem = Fsymbol_value (Qtemp_buffer_show_hook); |
2830 | if (!NILP (tem)) | |
2831 | { | |
2832 | int count = specpdl_ptr - specpdl; | |
b7354ddf RS |
2833 | Lisp_Object prev_window; |
2834 | prev_window = selected_window; | |
2cccc823 | 2835 | |
f52cca03 | 2836 | /* Select the window that was chosen, for running the hook. */ |
65a04b96 | 2837 | record_unwind_protect (Fselect_window, prev_window); |
b7354ddf | 2838 | select_window_1 (window, 0); |
beb4e312 | 2839 | Fset_buffer (w->buffer); |
f52cca03 | 2840 | call1 (Vrun_hooks, Qtemp_buffer_show_hook); |
b7354ddf | 2841 | select_window_1 (prev_window, 0); |
f52cca03 RS |
2842 | unbind_to (count, Qnil); |
2843 | } | |
2cccc823 RS |
2844 | } |
2845 | } | |
2846 | } | |
7ab12479 JB |
2847 | } |
2848 | \f | |
dfcf069d | 2849 | static void |
7ab12479 JB |
2850 | make_dummy_parent (window) |
2851 | Lisp_Object window; | |
2852 | { | |
cffec418 | 2853 | Lisp_Object new; |
7ab12479 | 2854 | register struct window *o, *p; |
cffec418 KH |
2855 | register struct Lisp_Vector *vec; |
2856 | int i; | |
7ab12479 | 2857 | |
cffec418 KH |
2858 | o = XWINDOW (window); |
2859 | vec = allocate_vectorlike ((EMACS_INT)VECSIZE (struct window)); | |
2860 | for (i = 0; i < VECSIZE (struct window); ++i) | |
2861 | vec->contents[i] = ((struct Lisp_Vector *)o)->contents[i]; | |
2862 | vec->size = VECSIZE (struct window); | |
2863 | p = (struct window *)vec; | |
2864 | XSETWINDOW (new, p); | |
7ab12479 | 2865 | |
d834a2e9 | 2866 | XSETFASTINT (p->sequence_number, ++sequence_number); |
7ab12479 JB |
2867 | |
2868 | /* Put new into window structure in place of window */ | |
2869 | replace_window (window, new); | |
2870 | ||
2871 | o->next = Qnil; | |
2872 | o->prev = Qnil; | |
2873 | o->vchild = Qnil; | |
2874 | o->hchild = Qnil; | |
2875 | o->parent = new; | |
2876 | ||
2877 | p->start = Qnil; | |
2878 | p->pointm = Qnil; | |
2879 | p->buffer = Qnil; | |
2880 | } | |
2881 | ||
2882 | DEFUN ("split-window", Fsplit_window, Ssplit_window, 0, 3, "", | |
2883 | "Split WINDOW, putting SIZE lines in the first of the pair.\n\ | |
2884 | WINDOW defaults to selected one and SIZE to half its size.\n\ | |
77ae0fe3 | 2885 | If optional third arg HORFLAG is non-nil, split side by side\n\ |
10f96191 RS |
2886 | and put SIZE columns in the first of the pair. In that case,\n\ |
2887 | SIZE includes that window's scroll bar, or the divider column to its right.") | |
77ae0fe3 KH |
2888 | (window, size, horflag) |
2889 | Lisp_Object window, size, horflag; | |
7ab12479 JB |
2890 | { |
2891 | register Lisp_Object new; | |
2892 | register struct window *o, *p; | |
c0807608 | 2893 | FRAME_PTR fo; |
77ae0fe3 | 2894 | register int size_int; |
7ab12479 | 2895 | |
265a9e55 | 2896 | if (NILP (window)) |
7ab12479 JB |
2897 | window = selected_window; |
2898 | else | |
605be8af | 2899 | CHECK_LIVE_WINDOW (window, 0); |
7ab12479 JB |
2900 | |
2901 | o = XWINDOW (window); | |
c0807608 | 2902 | fo = XFRAME (WINDOW_FRAME (o)); |
7ab12479 | 2903 | |
77ae0fe3 | 2904 | if (NILP (size)) |
7ab12479 | 2905 | { |
265a9e55 | 2906 | if (!NILP (horflag)) |
c0807608 | 2907 | /* Calculate the size of the left-hand window, by dividing |
25b33244 KH |
2908 | the usable space in columns by two. |
2909 | We round up, since the left-hand window may include | |
2910 | a dividing line, while the right-hand may not. */ | |
2911 | size_int = (XFASTINT (o->width) + 1) >> 1; | |
7ab12479 | 2912 | else |
77ae0fe3 | 2913 | size_int = XFASTINT (o->height) >> 1; |
7ab12479 JB |
2914 | } |
2915 | else | |
2916 | { | |
77ae0fe3 KH |
2917 | CHECK_NUMBER (size, 1); |
2918 | size_int = XINT (size); | |
7ab12479 JB |
2919 | } |
2920 | ||
2921 | if (MINI_WINDOW_P (o)) | |
2922 | error ("Attempt to split minibuffer window"); | |
233a4a2c GM |
2923 | else if (window_fixed_size_p (o, !NILP (horflag), 0)) |
2924 | error ("Attempt to split fixed-size window"); | |
7ab12479 | 2925 | |
a481b3ea | 2926 | check_min_window_sizes (); |
7ab12479 | 2927 | |
265a9e55 | 2928 | if (NILP (horflag)) |
7ab12479 | 2929 | { |
77ae0fe3 KH |
2930 | if (size_int < window_min_height) |
2931 | error ("Window height %d too small (after splitting)", size_int); | |
2932 | if (size_int + window_min_height > XFASTINT (o->height)) | |
37962e60 | 2933 | error ("Window height %d too small (after splitting)", |
77ae0fe3 | 2934 | XFASTINT (o->height) - size_int); |
265a9e55 JB |
2935 | if (NILP (o->parent) |
2936 | || NILP (XWINDOW (o->parent)->vchild)) | |
7ab12479 JB |
2937 | { |
2938 | make_dummy_parent (window); | |
2939 | new = o->parent; | |
2940 | XWINDOW (new)->vchild = window; | |
2941 | } | |
2942 | } | |
2943 | else | |
2944 | { | |
77ae0fe3 KH |
2945 | if (size_int < window_min_width) |
2946 | error ("Window width %d too small (after splitting)", size_int); | |
a59fed7e RS |
2947 | |
2948 | if (size_int + window_min_width > XFASTINT (o->width)) | |
37962e60 | 2949 | error ("Window width %d too small (after splitting)", |
a59fed7e | 2950 | XFASTINT (o->width) - size_int); |
265a9e55 JB |
2951 | if (NILP (o->parent) |
2952 | || NILP (XWINDOW (o->parent)->hchild)) | |
7ab12479 JB |
2953 | { |
2954 | make_dummy_parent (window); | |
2955 | new = o->parent; | |
2956 | XWINDOW (new)->hchild = window; | |
2957 | } | |
2958 | } | |
2959 | ||
2960 | /* Now we know that window's parent is a vertical combination | |
2961 | if we are dividing vertically, or a horizontal combination | |
2962 | if we are making side-by-side windows */ | |
2963 | ||
2964 | windows_or_buffers_changed++; | |
c0807608 | 2965 | FRAME_WINDOW_SIZES_CHANGED (fo) = 1; |
7ab12479 JB |
2966 | new = make_window (); |
2967 | p = XWINDOW (new); | |
2968 | ||
44fa5b1e | 2969 | p->frame = o->frame; |
7ab12479 | 2970 | p->next = o->next; |
265a9e55 | 2971 | if (!NILP (p->next)) |
7ab12479 JB |
2972 | XWINDOW (p->next)->prev = new; |
2973 | p->prev = window; | |
2974 | o->next = new; | |
2975 | p->parent = o->parent; | |
2976 | p->buffer = Qt; | |
5500c422 GM |
2977 | p->window_end_valid = Qnil; |
2978 | bzero (&p->last_cursor, sizeof p->last_cursor); | |
7ab12479 | 2979 | |
44fa5b1e | 2980 | /* Apportion the available frame space among the two new windows */ |
7ab12479 | 2981 | |
265a9e55 | 2982 | if (!NILP (horflag)) |
7ab12479 JB |
2983 | { |
2984 | p->height = o->height; | |
2985 | p->top = o->top; | |
a59fed7e | 2986 | XSETFASTINT (p->width, XFASTINT (o->width) - size_int); |
77ae0fe3 KH |
2987 | XSETFASTINT (o->width, size_int); |
2988 | XSETFASTINT (p->left, XFASTINT (o->left) + size_int); | |
7ab12479 JB |
2989 | } |
2990 | else | |
2991 | { | |
2992 | p->left = o->left; | |
2993 | p->width = o->width; | |
77ae0fe3 KH |
2994 | XSETFASTINT (p->height, XFASTINT (o->height) - size_int); |
2995 | XSETFASTINT (o->height, size_int); | |
2996 | XSETFASTINT (p->top, XFASTINT (o->top) + size_int); | |
7ab12479 JB |
2997 | } |
2998 | ||
5500c422 GM |
2999 | /* Adjust glyph matrices. */ |
3000 | adjust_glyphs (fo); | |
543f5fb1 | 3001 | Fset_window_buffer (new, o->buffer); |
7ab12479 JB |
3002 | return new; |
3003 | } | |
3004 | \f | |
3005 | DEFUN ("enlarge-window", Fenlarge_window, Senlarge_window, 1, 2, "p", | |
3006 | "Make current window ARG lines bigger.\n\ | |
3007 | From program, optional second arg non-nil means grow sideways ARG columns.") | |
413430c5 EN |
3008 | (arg, side) |
3009 | register Lisp_Object arg, side; | |
7ab12479 | 3010 | { |
413430c5 EN |
3011 | CHECK_NUMBER (arg, 0); |
3012 | change_window_height (XINT (arg), !NILP (side)); | |
543f5fb1 RS |
3013 | |
3014 | if (! NILP (Vwindow_configuration_change_hook)) | |
3015 | call1 (Vrun_hooks, Qwindow_configuration_change_hook); | |
3016 | ||
7ab12479 JB |
3017 | return Qnil; |
3018 | } | |
3019 | ||
3020 | DEFUN ("shrink-window", Fshrink_window, Sshrink_window, 1, 2, "p", | |
3021 | "Make current window ARG lines smaller.\n\ | |
413430c5 EN |
3022 | From program, optional second arg non-nil means shrink sideways arg columns.") |
3023 | (arg, side) | |
3024 | register Lisp_Object arg, side; | |
7ab12479 | 3025 | { |
413430c5 EN |
3026 | CHECK_NUMBER (arg, 0); |
3027 | change_window_height (-XINT (arg), !NILP (side)); | |
543f5fb1 RS |
3028 | |
3029 | if (! NILP (Vwindow_configuration_change_hook)) | |
3030 | call1 (Vrun_hooks, Qwindow_configuration_change_hook); | |
3031 | ||
7ab12479 JB |
3032 | return Qnil; |
3033 | } | |
3034 | ||
3035 | int | |
3036 | window_height (window) | |
3037 | Lisp_Object window; | |
3038 | { | |
3039 | register struct window *p = XWINDOW (window); | |
3040 | return XFASTINT (p->height); | |
3041 | } | |
3042 | ||
3043 | int | |
3044 | window_width (window) | |
3045 | Lisp_Object window; | |
3046 | { | |
3047 | register struct window *p = XWINDOW (window); | |
3048 | return XFASTINT (p->width); | |
3049 | } | |
3050 | ||
c1636aa6 | 3051 | |
7ab12479 | 3052 | #define CURBEG(w) \ |
05c2896a | 3053 | *(widthflag ? (int *) &(XWINDOW (w)->left) : (int *) &(XWINDOW (w)->top)) |
7ab12479 JB |
3054 | |
3055 | #define CURSIZE(w) \ | |
05c2896a | 3056 | *(widthflag ? (int *) &(XWINDOW (w)->width) : (int *) &(XWINDOW (w)->height)) |
7ab12479 | 3057 | |
233a4a2c GM |
3058 | |
3059 | /* Enlarge selected_window by DELTA. WIDTHFLAG non-zero means | |
3060 | increase its width. Siblings of the selected window are resized to | |
3061 | fullfil the size request. If they become too small in the process, | |
3062 | they will be deleted. */ | |
7ab12479 | 3063 | |
5e14b1fc | 3064 | void |
7ab12479 | 3065 | change_window_height (delta, widthflag) |
233a4a2c | 3066 | int delta, widthflag; |
7ab12479 | 3067 | { |
233a4a2c GM |
3068 | Lisp_Object parent, window, next, prev; |
3069 | struct window *p; | |
3070 | int *sizep, maximum; | |
5e14b1fc AS |
3071 | int (*sizefun) P_ ((Lisp_Object)) |
3072 | = widthflag ? window_width : window_height; | |
233a4a2c | 3073 | void (*setsizefun) P_ ((Lisp_Object, int, int)) |
5e14b1fc | 3074 | = (widthflag ? set_window_width : set_window_height); |
7ab12479 | 3075 | |
233a4a2c GM |
3076 | /* Check values of window_min_width and window_min_height for |
3077 | validity. */ | |
a481b3ea | 3078 | check_min_window_sizes (); |
7ab12479 | 3079 | |
233a4a2c | 3080 | /* Give up if this window cannot be resized. */ |
7ab12479 | 3081 | window = selected_window; |
233a4a2c GM |
3082 | if (window_fixed_size_p (XWINDOW (window), widthflag, 1)) |
3083 | error ("Window is not resizable"); | |
3084 | ||
3085 | /* Find the parent of the selected window. */ | |
7ab12479 JB |
3086 | while (1) |
3087 | { | |
3088 | p = XWINDOW (window); | |
3089 | parent = p->parent; | |
233a4a2c | 3090 | |
265a9e55 | 3091 | if (NILP (parent)) |
7ab12479 JB |
3092 | { |
3093 | if (widthflag) | |
3094 | error ("No other window to side of this one"); | |
3095 | break; | |
3096 | } | |
233a4a2c GM |
3097 | |
3098 | if (widthflag | |
3099 | ? !NILP (XWINDOW (parent)->hchild) | |
265a9e55 | 3100 | : !NILP (XWINDOW (parent)->vchild)) |
7ab12479 | 3101 | break; |
233a4a2c | 3102 | |
7ab12479 JB |
3103 | window = parent; |
3104 | } | |
3105 | ||
05c2896a | 3106 | sizep = &CURSIZE (window); |
7ab12479 | 3107 | |
7ab12479 JB |
3108 | { |
3109 | register int maxdelta; | |
7ab12479 | 3110 | |
265a9e55 | 3111 | maxdelta = (!NILP (parent) ? (*sizefun) (parent) - *sizep |
c1636aa6 GM |
3112 | : !NILP (p->next) ? ((*sizefun) (p->next) |
3113 | - window_min_size (XWINDOW (p->next), | |
233a4a2c | 3114 | widthflag, 0)) |
c1636aa6 GM |
3115 | : !NILP (p->prev) ? ((*sizefun) (p->prev) |
3116 | - window_min_size (XWINDOW (p->prev), | |
233a4a2c | 3117 | widthflag, 0)) |
44fa5b1e JB |
3118 | /* This is a frame with only one window, a minibuffer-only |
3119 | or a minibufferless frame. */ | |
d5783c40 | 3120 | : (delta = 0)); |
7ab12479 JB |
3121 | |
3122 | if (delta > maxdelta) | |
3123 | /* This case traps trying to make the minibuffer | |
44fa5b1e JB |
3124 | the full frame, or make the only window aside from the |
3125 | minibuffer the full frame. */ | |
7ab12479 | 3126 | delta = maxdelta; |
6b54027b | 3127 | } |
d5783c40 | 3128 | |
233a4a2c | 3129 | if (*sizep + delta < window_min_size (XWINDOW (window), widthflag, 0)) |
6b54027b | 3130 | { |
543f5fb1 | 3131 | delete_window (window); |
d5783c40 | 3132 | return; |
6b54027b RS |
3133 | } |
3134 | ||
3135 | if (delta == 0) | |
3136 | return; | |
7ab12479 | 3137 | |
db98a733 RS |
3138 | /* Find the total we can get from other siblings. */ |
3139 | maximum = 0; | |
3140 | for (next = p->next; ! NILP (next); next = XWINDOW (next)->next) | |
c1636aa6 | 3141 | maximum += (*sizefun) (next) - window_min_size (XWINDOW (next), |
233a4a2c | 3142 | widthflag, 0); |
db98a733 | 3143 | for (prev = p->prev; ! NILP (prev); prev = XWINDOW (prev)->prev) |
c1636aa6 | 3144 | maximum += (*sizefun) (prev) - window_min_size (XWINDOW (prev), |
233a4a2c | 3145 | widthflag, 0); |
db98a733 RS |
3146 | |
3147 | /* If we can get it all from them, do so. */ | |
c6b530ed | 3148 | if (delta <= maximum) |
7ab12479 | 3149 | { |
db98a733 RS |
3150 | Lisp_Object first_unaffected; |
3151 | Lisp_Object first_affected; | |
233a4a2c | 3152 | int fixed_p; |
db98a733 RS |
3153 | |
3154 | next = p->next; | |
3155 | prev = p->prev; | |
3156 | first_affected = window; | |
3157 | /* Look at one sibling at a time, | |
3158 | moving away from this window in both directions alternately, | |
3159 | and take as much as we can get without deleting that sibling. */ | |
233a4a2c | 3160 | while (delta != 0 && (!NILP (next) || !NILP (prev))) |
db98a733 | 3161 | { |
db98a733 RS |
3162 | if (! NILP (next)) |
3163 | { | |
c1636aa6 | 3164 | int this_one = ((*sizefun) (next) |
233a4a2c GM |
3165 | - window_min_size (XWINDOW (next), |
3166 | widthflag, &fixed_p)); | |
3167 | if (!fixed_p) | |
3168 | { | |
3169 | if (this_one > delta) | |
3170 | this_one = delta; | |
3171 | ||
3172 | (*setsizefun) (next, (*sizefun) (next) - this_one, 0); | |
3173 | (*setsizefun) (window, *sizep + this_one, 0); | |
db98a733 | 3174 | |
233a4a2c GM |
3175 | delta -= this_one; |
3176 | } | |
3177 | ||
db98a733 RS |
3178 | next = XWINDOW (next)->next; |
3179 | } | |
233a4a2c | 3180 | |
db98a733 RS |
3181 | if (delta == 0) |
3182 | break; | |
233a4a2c | 3183 | |
db98a733 RS |
3184 | if (! NILP (prev)) |
3185 | { | |
c1636aa6 | 3186 | int this_one = ((*sizefun) (prev) |
233a4a2c GM |
3187 | - window_min_size (XWINDOW (prev), |
3188 | widthflag, &fixed_p)); | |
3189 | if (!fixed_p) | |
3190 | { | |
3191 | if (this_one > delta) | |
3192 | this_one = delta; | |
3193 | ||
3194 | first_affected = prev; | |
3195 | ||
3196 | (*setsizefun) (prev, (*sizefun) (prev) - this_one, 0); | |
3197 | (*setsizefun) (window, *sizep + this_one, 0); | |
3198 | ||
3199 | delta -= this_one; | |
3200 | } | |
3201 | ||
db98a733 RS |
3202 | prev = XWINDOW (prev)->prev; |
3203 | } | |
3204 | } | |
3205 | ||
233a4a2c GM |
3206 | xassert (delta == 0); |
3207 | ||
db98a733 RS |
3208 | /* Now recalculate the edge positions of all the windows affected, |
3209 | based on the new sizes. */ | |
3210 | first_unaffected = next; | |
3211 | prev = first_affected; | |
3212 | for (next = XWINDOW (prev)->next; ! EQ (next, first_unaffected); | |
3213 | prev = next, next = XWINDOW (next)->next) | |
3214 | { | |
3215 | CURBEG (next) = CURBEG (prev) + (*sizefun) (prev); | |
3216 | /* This does not change size of NEXT, | |
3217 | but it propagates the new top edge to its children */ | |
3218 | (*setsizefun) (next, (*sizefun) (next), 0); | |
3219 | } | |
7ab12479 JB |
3220 | } |
3221 | else | |
3222 | { | |
3223 | register int delta1; | |
3224 | register int opht = (*sizefun) (parent); | |
3225 | ||
3226 | /* If trying to grow this window to or beyond size of the parent, | |
3227 | make delta1 so big that, on shrinking back down, | |
3228 | all the siblings end up with less than one line and are deleted. */ | |
3229 | if (opht <= *sizep + delta) | |
3230 | delta1 = opht * opht * 2; | |
7ab12479 | 3231 | else |
233a4a2c GM |
3232 | { |
3233 | /* Otherwise, make delta1 just right so that if we add | |
3234 | delta1 lines to this window and to the parent, and then | |
3235 | shrink the parent back to its original size, the new | |
3236 | proportional size of this window will increase by delta. | |
3237 | ||
3238 | The function size_window will compute the new height h' | |
3239 | of the window from delta1 as: | |
3240 | ||
3241 | e = delta1/n | |
3242 | x = delta1 - delta1/n * n for the 1st resizable child | |
3243 | h' = h + e + x | |
3244 | ||
3245 | where n is the number of children that can be resized. | |
3246 | We can ignore x by choosing a delta1 that is a multiple of | |
3247 | n. We want the height of this window to come out as | |
3248 | ||
3249 | h' = h + delta | |
3250 | ||
3251 | So, delta1 must be | |
3252 | ||
3253 | h + e = h + delta | |
3254 | delta1/n = delta | |
3255 | delta1 = n * delta. | |
3256 | ||
3257 | The number of children n rquals the number of resizable | |
3258 | children of this window + 1 because we know window itself | |
3259 | is resizable (otherwise we would have signalled an error. */ | |
3260 | ||
3261 | struct window *w = XWINDOW (window); | |
3262 | Lisp_Object s; | |
3263 | int n = 1; | |
3264 | ||
3265 | for (s = w->next; !NILP (s); s = XWINDOW (s)->next) | |
3266 | if (!window_fixed_size_p (XWINDOW (s), widthflag, 0)) | |
3267 | ++n; | |
3268 | for (s = w->prev; !NILP (s); s = XWINDOW (s)->prev) | |
3269 | if (!window_fixed_size_p (XWINDOW (s), widthflag, 0)) | |
3270 | ++n; | |
3271 | ||
3272 | delta1 = n * delta; | |
3273 | } | |
7ab12479 JB |
3274 | |
3275 | /* Add delta1 lines or columns to this window, and to the parent, | |
3276 | keeping things consistent while not affecting siblings. */ | |
05c2896a | 3277 | CURSIZE (parent) = opht + delta1; |
7ab12479 JB |
3278 | (*setsizefun) (window, *sizep + delta1, 0); |
3279 | ||
3280 | /* Squeeze out delta1 lines or columns from our parent, | |
3281 | shriking this window and siblings proportionately. | |
3282 | This brings parent back to correct size. | |
3283 | Delta1 was calculated so this makes this window the desired size, | |
3284 | taking it all out of the siblings. */ | |
3285 | (*setsizefun) (parent, opht, 0); | |
3286 | } | |
3287 | ||
d834a2e9 | 3288 | XSETFASTINT (p->last_modified, 0); |
3cd21523 | 3289 | XSETFASTINT (p->last_overlay_modified, 0); |
5500c422 GM |
3290 | |
3291 | /* Adjust glyph matrices. */ | |
3292 | adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window)))); | |
7ab12479 | 3293 | } |
c1636aa6 | 3294 | |
7ab12479 JB |
3295 | #undef CURBEG |
3296 | #undef CURSIZE | |
3297 | ||
5500c422 GM |
3298 | |
3299 | /* Mark window cursors off for all windows in the window tree rooted | |
3300 | at W by setting their phys_cursor_on_p flag to zero. Called from | |
3301 | xterm.c, e.g. when a frame is cleared and thereby all cursors on | |
3302 | the frame are cleared. */ | |
3303 | ||
3304 | void | |
3305 | mark_window_cursors_off (w) | |
3306 | struct window *w; | |
3307 | { | |
3308 | while (w) | |
3309 | { | |
3310 | if (!NILP (w->hchild)) | |
3311 | mark_window_cursors_off (XWINDOW (w->hchild)); | |
3312 | else if (!NILP (w->vchild)) | |
3313 | mark_window_cursors_off (XWINDOW (w->vchild)); | |
3314 | else | |
3315 | w->phys_cursor_on_p = 0; | |
3316 | ||
3317 | w = NILP (w->next) ? 0 : XWINDOW (w->next); | |
3318 | } | |
3319 | } | |
3320 | ||
3321 | ||
7ab12479 JB |
3322 | /* Return number of lines of text (not counting mode line) in W. */ |
3323 | ||
3324 | int | |
3325 | window_internal_height (w) | |
3326 | struct window *w; | |
3327 | { | |
3328 | int ht = XFASTINT (w->height); | |
3329 | ||
3330 | if (MINI_WINDOW_P (w)) | |
3331 | return ht; | |
3332 | ||
265a9e55 JB |
3333 | if (!NILP (w->parent) || !NILP (w->vchild) || !NILP (w->hchild) |
3334 | || !NILP (w->next) || !NILP (w->prev) | |
44fa5b1e | 3335 | || FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (w)))) |
7ab12479 JB |
3336 | return ht - 1; |
3337 | ||
3338 | return ht; | |
3339 | } | |
3340 | ||
535e0b8e JB |
3341 | |
3342 | /* Return the number of columns in W. | |
a3c87d4e | 3343 | Don't count columns occupied by scroll bars or the vertical bar |
535e0b8e | 3344 | separating W from the sibling to its right. */ |
5500c422 | 3345 | |
535e0b8e JB |
3346 | int |
3347 | window_internal_width (w) | |
3348 | struct window *w; | |
3349 | { | |
5500c422 | 3350 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
535e0b8e JB |
3351 | int width = XINT (w->width); |
3352 | ||
a3c87d4e | 3353 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) |
5500c422 GM |
3354 | /* Scroll bars occupy a few columns. */ |
3355 | width -= FRAME_SCROLL_BAR_COLS (f); | |
3356 | else if (!WINDOW_RIGHTMOST_P (w) && !WINDOW_FULL_WIDTH_P (w)) | |
3357 | /* The column of `|' characters separating side-by-side windows | |
3358 | occupies one column only. */ | |
3359 | width -= 1; | |
3360 | ||
3361 | /* On window-systems, areas to the left and right of the window | |
3362 | are used to display bitmaps there. */ | |
3363 | if (FRAME_WINDOW_P (f)) | |
3364 | width -= 2 * FRAME_FLAGS_AREA_COLS (f); | |
111e5992 RS |
3365 | |
3366 | return width; | |
535e0b8e JB |
3367 | } |
3368 | ||
5500c422 GM |
3369 | \f |
3370 | /************************************************************************ | |
3371 | Window Scrolling | |
3372 | ***********************************************************************/ | |
535e0b8e | 3373 | |
5500c422 GM |
3374 | /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll |
3375 | one screen-full, which is defined as the height of the window minus | |
3376 | next_screen_context_lines. If WHOLE is zero, scroll up N lines | |
3377 | instead. Negative values of N mean scroll down. NOERROR non-zero | |
3378 | means don't signal an error if we try to move over BEGV or ZV, | |
3379 | respectively. */ | |
7ab12479 | 3380 | |
101d1605 RS |
3381 | static void |
3382 | window_scroll (window, n, whole, noerror) | |
7ab12479 JB |
3383 | Lisp_Object window; |
3384 | int n; | |
101d1605 | 3385 | int whole; |
f8026fd8 | 3386 | int noerror; |
5500c422 GM |
3387 | { |
3388 | /* If we must, use the pixel-based version which is much slower than | |
3389 | the line-based one but can handle varying line heights. */ | |
3390 | if (FRAME_WINDOW_P (XFRAME (XWINDOW (window)->frame))) | |
3391 | window_scroll_pixel_based (window, n, whole, noerror); | |
3392 | else | |
3393 | window_scroll_line_based (window, n, whole, noerror); | |
3394 | } | |
3395 | ||
3396 | ||
3397 | /* Implementation of window_scroll that works based on pixel line | |
3398 | heights. See the comment of window_scroll for parameter | |
3399 | descriptions. */ | |
3400 | ||
3401 | static void | |
3402 | window_scroll_pixel_based (window, n, whole, noerror) | |
3403 | Lisp_Object window; | |
3404 | int n; | |
3405 | int whole; | |
3406 | int noerror; | |
3407 | { | |
3408 | struct it it; | |
3409 | struct window *w = XWINDOW (window); | |
3410 | struct text_pos start; | |
3411 | Lisp_Object tem; | |
3412 | int this_scroll_margin; | |
3413 | int preserve_y; | |
3414 | ||
3415 | SET_TEXT_POS_FROM_MARKER (start, w->start); | |
3416 | ||
3417 | /* If PT is not visible in WINDOW, move back one half of | |
3418 | the screen. */ | |
3419 | XSETFASTINT (tem, PT); | |
3420 | tem = Fpos_visible_in_window_p (tem, window); | |
3421 | if (NILP (tem)) | |
3422 | { | |
3423 | /* Move backward half the height of the window. Performance note: | |
3424 | vmotion used here is about 10% faster, but would give wrong | |
3425 | results for variable height lines. */ | |
3426 | init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID); | |
3427 | it.current_y = it.last_visible_y; | |
3428 | move_it_vertically (&it, -it.last_visible_y / 2); | |
3429 | ||
3430 | /* The function move_iterator_vertically may move over more than | |
3431 | the specified y-distance. If it->w is small, e.g. a | |
3432 | mini-buffer window, we may end up in front of the window's | |
3433 | display area. This is the case when Start displaying at the | |
3434 | start of the line containing PT in this case. */ | |
3435 | if (it.current_y <= 0) | |
3436 | { | |
3437 | init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID); | |
3438 | move_it_vertically (&it, 0); | |
3439 | it.current_y = 0; | |
3440 | } | |
3441 | ||
3442 | start = it.current.pos; | |
3443 | } | |
3444 | ||
3445 | /* If scroll_preserve_screen_position is non-zero, we try to set | |
3446 | point in the same window line as it is now, so get that line. */ | |
3447 | if (!NILP (Vscroll_preserve_screen_position)) | |
3448 | { | |
3449 | start_display (&it, w, start); | |
3450 | move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS); | |
3451 | preserve_y = it.current_y; | |
3452 | } | |
3453 | else | |
3454 | preserve_y = -1; | |
3455 | ||
3456 | /* Move iterator it from start the specified distance forward or | |
3457 | backward. The result is the new window start. */ | |
3458 | start_display (&it, w, start); | |
3459 | if (whole) | |
3460 | { | |
3461 | int screen_full = (it.last_visible_y | |
3462 | - next_screen_context_lines * CANON_Y_UNIT (it.f)); | |
3463 | int direction = n < 0 ? -1 : 1; | |
3464 | move_it_vertically (&it, direction * screen_full); | |
3465 | } | |
3466 | else | |
3467 | move_it_by_lines (&it, n, 1); | |
3468 | ||
3469 | /* End if we end up at ZV or BEGV. */ | |
3470 | if ((n > 0 && IT_CHARPOS (it) == ZV) | |
3471 | || (n < 0 && IT_CHARPOS (it) == CHARPOS (start))) | |
3472 | { | |
3473 | if (noerror) | |
3474 | return; | |
3475 | else if (IT_CHARPOS (it) == ZV) | |
3476 | Fsignal (Qend_of_buffer, Qnil); | |
3477 | else | |
3478 | Fsignal (Qbeginning_of_buffer, Qnil); | |
3479 | } | |
3480 | ||
3481 | /* Set the window start, and set up the window for redisplay. */ | |
3482 | set_marker_restricted (w->start, make_number (IT_CHARPOS (it)), w->buffer); | |
3483 | w->start_at_line_beg = Fbolp (); | |
3484 | w->update_mode_line = Qt; | |
3485 | XSETFASTINT (w->last_modified, 0); | |
3486 | XSETFASTINT (w->last_overlay_modified, 0); | |
3487 | /* Set force_start so that redisplay_window will run the | |
3488 | window-scroll-functions. */ | |
3489 | w->force_start = Qt; | |
3490 | ||
3491 | it.current_y = it.vpos = 0; | |
3492 | ||
3493 | /* Preserve the screen position if we must. */ | |
3494 | if (preserve_y >= 0) | |
3495 | { | |
3496 | move_it_to (&it, -1, -1, preserve_y, -1, MOVE_TO_Y); | |
3497 | SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it)); | |
3498 | } | |
3499 | else | |
3500 | { | |
3501 | /* Move PT out of scroll margins. */ | |
3502 | this_scroll_margin = max (0, scroll_margin); | |
3503 | this_scroll_margin = min (this_scroll_margin, XFASTINT (w->height) / 4); | |
3504 | this_scroll_margin *= CANON_Y_UNIT (it.f); | |
3505 | ||
3506 | if (n > 0) | |
3507 | { | |
3508 | /* We moved the window start towards ZV, so PT may be now | |
3509 | in the scroll margin at the top. */ | |
3510 | move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS); | |
3511 | while (it.current_y < this_scroll_margin) | |
3512 | move_it_by_lines (&it, 1, 1); | |
3513 | SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it)); | |
3514 | } | |
3515 | else if (n < 0) | |
3516 | { | |
3517 | /* We moved the window start towards BEGV, so PT may be now | |
3518 | in the scroll margin at the bottom. */ | |
3519 | move_it_to (&it, PT, -1, | |
3520 | it.last_visible_y - this_scroll_margin - 1, -1, | |
3521 | MOVE_TO_POS | MOVE_TO_Y); | |
3522 | ||
3523 | /* Don't put point on a partially visible line at the end. */ | |
3524 | if (it.current_y + it.max_ascent + it.max_descent | |
3525 | > it.last_visible_y) | |
3526 | move_it_by_lines (&it, -1, 0); | |
3527 | ||
3528 | SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it)); | |
3529 | } | |
3530 | } | |
3531 | } | |
3532 | ||
3533 | ||
3534 | /* Implementation of window_scroll that works based on screen lines. | |
3535 | See the comment of window_scroll for parameter descriptions. */ | |
3536 | ||
3537 | static void | |
3538 | window_scroll_line_based (window, n, whole, noerror) | |
3539 | Lisp_Object window; | |
3540 | int n; | |
3541 | int whole; | |
3542 | int noerror; | |
7ab12479 JB |
3543 | { |
3544 | register struct window *w = XWINDOW (window); | |
5500c422 | 3545 | register int opoint = PT, opoint_byte = PT_BYTE; |
b73ea88e | 3546 | register int pos, pos_byte; |
7ab12479 JB |
3547 | register int ht = window_internal_height (w); |
3548 | register Lisp_Object tem; | |
3549 | int lose; | |
5500c422 | 3550 | Lisp_Object bolp; |
345d45b2 | 3551 | int startpos; |
101d1605 RS |
3552 | struct position posit; |
3553 | int original_vpos; | |
3554 | ||
3555 | startpos = marker_position (w->start); | |
3556 | ||
3557 | posit = *compute_motion (startpos, 0, 0, 0, | |
3558 | PT, ht, 0, | |
3559 | window_internal_width (w), XINT (w->hscroll), | |
3560 | 0, w); | |
3561 | original_vpos = posit.vpos; | |
0a1f771a | 3562 | |
d834a2e9 | 3563 | XSETFASTINT (tem, PT); |
7ab12479 JB |
3564 | tem = Fpos_visible_in_window_p (tem, window); |
3565 | ||
265a9e55 | 3566 | if (NILP (tem)) |
7ab12479 | 3567 | { |
cd2be1dd | 3568 | Fvertical_motion (make_number (- (ht / 2)), window); |
345d45b2 | 3569 | startpos = PT; |
7ab12479 JB |
3570 | } |
3571 | ||
345d45b2 | 3572 | SET_PT (startpos); |
5ce7b543 | 3573 | lose = n < 0 && PT == BEGV; |
540b6aa0 | 3574 | Fvertical_motion (make_number (n), window); |
5ce7b543 | 3575 | pos = PT; |
b73ea88e | 3576 | pos_byte = PT_BYTE; |
7ab12479 | 3577 | bolp = Fbolp (); |
b73ea88e | 3578 | SET_PT_BOTH (opoint, opoint_byte); |
7ab12479 JB |
3579 | |
3580 | if (lose) | |
f8026fd8 JB |
3581 | { |
3582 | if (noerror) | |
3583 | return; | |
3584 | else | |
3585 | Fsignal (Qbeginning_of_buffer, Qnil); | |
3586 | } | |
7ab12479 JB |
3587 | |
3588 | if (pos < ZV) | |
7ab12479 | 3589 | { |
0c7da84e RS |
3590 | int this_scroll_margin = scroll_margin; |
3591 | ||
3592 | /* Don't use a scroll margin that is negative or too large. */ | |
3593 | if (this_scroll_margin < 0) | |
3594 | this_scroll_margin = 0; | |
3595 | ||
3596 | if (XINT (w->height) < 4 * scroll_margin) | |
3597 | this_scroll_margin = XINT (w->height) / 4; | |
3598 | ||
b73ea88e | 3599 | set_marker_restricted_both (w->start, w->buffer, pos, pos_byte); |
7ab12479 JB |
3600 | w->start_at_line_beg = bolp; |
3601 | w->update_mode_line = Qt; | |
d834a2e9 | 3602 | XSETFASTINT (w->last_modified, 0); |
3cd21523 | 3603 | XSETFASTINT (w->last_overlay_modified, 0); |
345d45b2 RS |
3604 | /* Set force_start so that redisplay_window will run |
3605 | the window-scroll-functions. */ | |
3606 | w->force_start = Qt; | |
0c7da84e | 3607 | |
5500c422 | 3608 | if (whole && !NILP (Vscroll_preserve_screen_position)) |
0c7da84e | 3609 | { |
b73ea88e | 3610 | SET_PT_BOTH (pos, pos_byte); |
101d1605 | 3611 | Fvertical_motion (make_number (original_vpos), window); |
0c7da84e | 3612 | } |
101d1605 RS |
3613 | /* If we scrolled forward, put point enough lines down |
3614 | that it is outside the scroll margin. */ | |
3615 | else if (n > 0) | |
0c7da84e | 3616 | { |
101d1605 RS |
3617 | int top_margin; |
3618 | ||
3619 | if (this_scroll_margin > 0) | |
3620 | { | |
b73ea88e | 3621 | SET_PT_BOTH (pos, pos_byte); |
101d1605 RS |
3622 | Fvertical_motion (make_number (this_scroll_margin), window); |
3623 | top_margin = PT; | |
3624 | } | |
3625 | else | |
3626 | top_margin = pos; | |
3627 | ||
3628 | if (top_margin <= opoint) | |
b73ea88e | 3629 | SET_PT_BOTH (opoint, opoint_byte); |
5500c422 | 3630 | else if (!NILP (Vscroll_preserve_screen_position)) |
101d1605 | 3631 | { |
b73ea88e | 3632 | SET_PT_BOTH (pos, pos_byte); |
101d1605 RS |
3633 | Fvertical_motion (make_number (original_vpos), window); |
3634 | } | |
9317a85d | 3635 | else |
335406fc | 3636 | SET_PT (top_margin); |
0c7da84e | 3637 | } |
101d1605 | 3638 | else if (n < 0) |
7ab12479 | 3639 | { |
101d1605 RS |
3640 | int bottom_margin; |
3641 | ||
0c7da84e RS |
3642 | /* If we scrolled backward, put point near the end of the window |
3643 | but not within the scroll margin. */ | |
b73ea88e | 3644 | SET_PT_BOTH (pos, pos_byte); |
0c7da84e | 3645 | tem = Fvertical_motion (make_number (ht - this_scroll_margin), window); |
101d1605 RS |
3646 | if (XFASTINT (tem) == ht - this_scroll_margin) |
3647 | bottom_margin = PT; | |
3648 | else | |
3649 | bottom_margin = PT + 1; | |
3650 | ||
3651 | if (bottom_margin > opoint) | |
b73ea88e | 3652 | SET_PT_BOTH (opoint, opoint_byte); |
7ab12479 | 3653 | else |
101d1605 | 3654 | { |
5500c422 | 3655 | if (!NILP (Vscroll_preserve_screen_position)) |
9317a85d | 3656 | { |
b73ea88e | 3657 | SET_PT_BOTH (pos, pos_byte); |
9317a85d RS |
3658 | Fvertical_motion (make_number (original_vpos), window); |
3659 | } | |
3660 | else | |
3661 | Fvertical_motion (make_number (-1), window); | |
101d1605 | 3662 | } |
7ab12479 JB |
3663 | } |
3664 | } | |
3665 | else | |
f8026fd8 JB |
3666 | { |
3667 | if (noerror) | |
3668 | return; | |
3669 | else | |
3670 | Fsignal (Qend_of_buffer, Qnil); | |
3671 | } | |
7ab12479 | 3672 | } |
5500c422 GM |
3673 | |
3674 | ||
3675 | /* Scroll selected_window up or down. If N is nil, scroll a | |
3676 | screen-full which is defined as the height of the window minus | |
3677 | next_screen_context_lines. If N is the symbol `-', scroll. | |
3678 | DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll | |
3679 | up. This is the guts of Fscroll_up and Fscroll_down. */ | |
7ab12479 JB |
3680 | |
3681 | static void | |
3682 | scroll_command (n, direction) | |
5500c422 | 3683 | Lisp_Object n; |
7ab12479 JB |
3684 | int direction; |
3685 | { | |
3686 | register int defalt; | |
3687 | int count = specpdl_ptr - specpdl; | |
3688 | ||
5500c422 GM |
3689 | xassert (abs (direction) == 1); |
3690 | ||
3691 | /* If selected window's buffer isn't current, make it current for | |
3692 | the moment. But don't screw up if window_scroll gets an error. */ | |
7ab12479 | 3693 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) |
95605e15 JB |
3694 | { |
3695 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
3696 | Fset_buffer (XWINDOW (selected_window)->buffer); | |
5500c422 GM |
3697 | |
3698 | /* Make redisplay consider other windows than just selected_window. */ | |
3699 | ++windows_or_buffers_changed; | |
95605e15 | 3700 | } |
7ab12479 JB |
3701 | |
3702 | defalt = (window_internal_height (XWINDOW (selected_window)) | |
3703 | - next_screen_context_lines); | |
3704 | defalt = direction * (defalt < 1 ? 1 : defalt); | |
3705 | ||
265a9e55 | 3706 | if (NILP (n)) |
101d1605 | 3707 | window_scroll (selected_window, defalt, 1, 0); |
7ab12479 | 3708 | else if (EQ (n, Qminus)) |
101d1605 | 3709 | window_scroll (selected_window, - defalt, 1, 0); |
7ab12479 JB |
3710 | else |
3711 | { | |
3712 | n = Fprefix_numeric_value (n); | |
101d1605 | 3713 | window_scroll (selected_window, XINT (n) * direction, 0, 0); |
7ab12479 | 3714 | } |
95605e15 JB |
3715 | |
3716 | unbind_to (count, Qnil); | |
7ab12479 JB |
3717 | } |
3718 | ||
3719 | DEFUN ("scroll-up", Fscroll_up, Sscroll_up, 0, 1, "P", | |
3720 | "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\ | |
3721 | A near full screen is `next-screen-context-lines' less than a full screen.\n\ | |
279e0e0c | 3722 | Negative ARG means scroll downward.\n\ |
dd394ff9 KH |
3723 | If ARG is the atom `-', scroll downward by nearly full screen.\n\ |
3724 | When calling from a program, supply as argument a number, nil, or `-'.") | |
413430c5 EN |
3725 | (arg) |
3726 | Lisp_Object arg; | |
7ab12479 | 3727 | { |
413430c5 | 3728 | scroll_command (arg, 1); |
7ab12479 JB |
3729 | return Qnil; |
3730 | } | |
3731 | ||
3732 | DEFUN ("scroll-down", Fscroll_down, Sscroll_down, 0, 1, "P", | |
a5fcbc4e | 3733 | "Scroll text of current window down ARG lines; or near full screen if no ARG.\n\ |
7ab12479 | 3734 | A near full screen is `next-screen-context-lines' less than a full screen.\n\ |
279e0e0c | 3735 | Negative ARG means scroll upward.\n\ |
dd394ff9 KH |
3736 | If ARG is the atom `-', scroll upward by nearly full screen.\n\ |
3737 | When calling from a program, supply as argument a number, nil, or `-'.") | |
413430c5 EN |
3738 | (arg) |
3739 | Lisp_Object arg; | |
7ab12479 | 3740 | { |
413430c5 | 3741 | scroll_command (arg, -1); |
7ab12479 JB |
3742 | return Qnil; |
3743 | } | |
ccd0664b RS |
3744 | \f |
3745 | DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling, Sother_window_for_scrolling, 0, 0, 0, | |
3746 | "Return the other window for \"other window scroll\" commands.\n\ | |
77b24de6 | 3747 | If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\ |
ccd0664b RS |
3748 | specifies the window.\n\ |
3749 | If `other-window-scroll-buffer' is non-nil, a window\n\ | |
3750 | showing that buffer is used.") | |
eb16ec06 | 3751 | () |
7ab12479 | 3752 | { |
ccd0664b | 3753 | Lisp_Object window; |
7ab12479 JB |
3754 | |
3755 | if (MINI_WINDOW_P (XWINDOW (selected_window)) | |
265a9e55 | 3756 | && !NILP (Vminibuf_scroll_window)) |
7ab12479 JB |
3757 | window = Vminibuf_scroll_window; |
3758 | /* If buffer is specified, scroll that buffer. */ | |
265a9e55 | 3759 | else if (!NILP (Vother_window_scroll_buffer)) |
7ab12479 JB |
3760 | { |
3761 | window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil); | |
265a9e55 | 3762 | if (NILP (window)) |
53f76081 | 3763 | window = Fdisplay_buffer (Vother_window_scroll_buffer, Qt, Qnil); |
7ab12479 JB |
3764 | } |
3765 | else | |
dbc4e1c1 JB |
3766 | { |
3767 | /* Nothing specified; look for a neighboring window on the same | |
3768 | frame. */ | |
3769 | window = Fnext_window (selected_window, Qnil, Qnil); | |
3770 | ||
3771 | if (EQ (window, selected_window)) | |
3772 | /* That didn't get us anywhere; look for a window on another | |
3773 | visible frame. */ | |
3774 | do | |
3775 | window = Fnext_window (window, Qnil, Qt); | |
3776 | while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window)))) | |
3777 | && ! EQ (window, selected_window)); | |
3778 | } | |
3779 | ||
605be8af | 3780 | CHECK_LIVE_WINDOW (window, 0); |
7ab12479 JB |
3781 | |
3782 | if (EQ (window, selected_window)) | |
3783 | error ("There is no other window"); | |
3784 | ||
ccd0664b RS |
3785 | return window; |
3786 | } | |
3787 | ||
3788 | DEFUN ("scroll-other-window", Fscroll_other_window, Sscroll_other_window, 0, 1, "P", | |
3789 | "Scroll next window upward ARG lines; or near full screen if no ARG.\n\ | |
dd394ff9 | 3790 | A near full screen is `next-screen-context-lines' less than a full screen.\n\ |
ccd0664b RS |
3791 | The next window is the one below the current one; or the one at the top\n\ |
3792 | if the current one is at the bottom. Negative ARG means scroll downward.\n\ | |
dd394ff9 KH |
3793 | If ARG is the atom `-', scroll downward by nearly full screen.\n\ |
3794 | When calling from a program, supply as argument a number, nil, or `-'.\n\ | |
ccd0664b RS |
3795 | \n\ |
3796 | If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\ | |
3797 | specifies the window to scroll.\n\ | |
3798 | If `other-window-scroll-buffer' is non-nil, scroll the window\n\ | |
3799 | showing that buffer, popping the buffer up if necessary.") | |
413430c5 EN |
3800 | (arg) |
3801 | register Lisp_Object arg; | |
ccd0664b RS |
3802 | { |
3803 | register Lisp_Object window; | |
2f787aa3 | 3804 | register int defalt; |
ccd0664b RS |
3805 | register struct window *w; |
3806 | register int count = specpdl_ptr - specpdl; | |
3807 | ||
3808 | window = Fother_window_for_scrolling (); | |
3809 | ||
7ab12479 | 3810 | w = XWINDOW (window); |
2f787aa3 KH |
3811 | defalt = window_internal_height (w) - next_screen_context_lines; |
3812 | if (defalt < 1) defalt = 1; | |
7ab12479 JB |
3813 | |
3814 | /* Don't screw up if window_scroll gets an error. */ | |
3815 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
5500c422 | 3816 | ++windows_or_buffers_changed; |
7ab12479 JB |
3817 | |
3818 | Fset_buffer (w->buffer); | |
3819 | SET_PT (marker_position (w->pointm)); | |
3820 | ||
413430c5 | 3821 | if (NILP (arg)) |
101d1605 | 3822 | window_scroll (window, defalt, 1, 1); |
413430c5 | 3823 | else if (EQ (arg, Qminus)) |
101d1605 | 3824 | window_scroll (window, -defalt, 1, 1); |
7ab12479 JB |
3825 | else |
3826 | { | |
413430c5 EN |
3827 | if (CONSP (arg)) |
3828 | arg = Fcar (arg); | |
3829 | CHECK_NUMBER (arg, 0); | |
101d1605 | 3830 | window_scroll (window, XINT (arg), 0, 1); |
7ab12479 JB |
3831 | } |
3832 | ||
b73ea88e | 3833 | set_marker_both (w->pointm, Qnil, PT, PT_BYTE); |
f4e7b2c2 | 3834 | unbind_to (count, Qnil); |
7ab12479 JB |
3835 | |
3836 | return Qnil; | |
3837 | } | |
3838 | \f | |
644b477c | 3839 | DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 1, "P", |
7ab12479 JB |
3840 | "Scroll selected window display ARG columns left.\n\ |
3841 | Default for ARG is window width minus 2.") | |
3842 | (arg) | |
3843 | register Lisp_Object arg; | |
3844 | { | |
3845 | ||
265a9e55 | 3846 | if (NILP (arg)) |
d834a2e9 | 3847 | XSETFASTINT (arg, window_internal_width (XWINDOW (selected_window)) - 2); |
7ab12479 JB |
3848 | else |
3849 | arg = Fprefix_numeric_value (arg); | |
3850 | ||
3851 | return | |
3852 | Fset_window_hscroll (selected_window, | |
3853 | make_number (XINT (XWINDOW (selected_window)->hscroll) | |
3854 | + XINT (arg))); | |
3855 | } | |
3856 | ||
644b477c | 3857 | DEFUN ("scroll-right", Fscroll_right, Sscroll_right, 0, 1, "P", |
7ab12479 JB |
3858 | "Scroll selected window display ARG columns right.\n\ |
3859 | Default for ARG is window width minus 2.") | |
3860 | (arg) | |
3861 | register Lisp_Object arg; | |
3862 | { | |
265a9e55 | 3863 | if (NILP (arg)) |
d834a2e9 | 3864 | XSETFASTINT (arg, window_internal_width (XWINDOW (selected_window)) - 2); |
7ab12479 JB |
3865 | else |
3866 | arg = Fprefix_numeric_value (arg); | |
3867 | ||
3868 | return | |
3869 | Fset_window_hscroll (selected_window, | |
3870 | make_number (XINT (XWINDOW (selected_window)->hscroll) | |
3871 | - XINT (arg))); | |
3872 | } | |
3873 | ||
3874 | DEFUN ("recenter", Frecenter, Srecenter, 0, 1, "P", | |
44fa5b1e | 3875 | "Center point in window and redisplay frame. With ARG, put point on line ARG.\n\ |
7ab12479 | 3876 | The desired position of point is always relative to the current window.\n\ |
44fa5b1e | 3877 | Just C-u as prefix means put point in the center of the window.\n\ |
413430c5 | 3878 | If ARG is omitted or nil, erases the entire frame and then\n\ |
44fa5b1e | 3879 | redraws with point in the center of the current window.") |
413430c5 EN |
3880 | (arg) |
3881 | register Lisp_Object arg; | |
7ab12479 JB |
3882 | { |
3883 | register struct window *w = XWINDOW (selected_window); | |
3884 | register int ht = window_internal_height (w); | |
113d9015 | 3885 | struct position pos; |
478292ed RS |
3886 | struct buffer *buf = XBUFFER (w->buffer); |
3887 | struct buffer *obuf = current_buffer; | |
7ab12479 | 3888 | |
413430c5 | 3889 | if (NILP (arg)) |
7ab12479 | 3890 | { |
44fa5b1e | 3891 | extern int frame_garbaged; |
7ab12479 | 3892 | |
44fa5b1e | 3893 | SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w))); |
413430c5 | 3894 | XSETFASTINT (arg, ht / 2); |
7ab12479 | 3895 | } |
413430c5 | 3896 | else if (CONSP (arg)) /* Just C-u. */ |
7ab12479 | 3897 | { |
413430c5 | 3898 | XSETFASTINT (arg, ht / 2); |
7ab12479 JB |
3899 | } |
3900 | else | |
3901 | { | |
413430c5 EN |
3902 | arg = Fprefix_numeric_value (arg); |
3903 | CHECK_NUMBER (arg, 0); | |
7ab12479 JB |
3904 | } |
3905 | ||
413430c5 EN |
3906 | if (XINT (arg) < 0) |
3907 | XSETINT (arg, XINT (arg) + ht); | |
7ab12479 | 3908 | |
478292ed | 3909 | set_buffer_internal (buf); |
6ec8bbd2 | 3910 | pos = *vmotion (PT, - XINT (arg), w); |
7ab12479 | 3911 | |
b73ea88e RS |
3912 | set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos); |
3913 | w->start_at_line_beg = ((pos.bytepos == BEGV_BYTE | |
3914 | || FETCH_BYTE (pos.bytepos - 1) == '\n') | |
113d9015 | 3915 | ? Qt : Qnil); |
7ab12479 | 3916 | w->force_start = Qt; |
478292ed | 3917 | set_buffer_internal (obuf); |
7ab12479 JB |
3918 | |
3919 | return Qnil; | |
3920 | } | |
3921 | \f | |
3922 | DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line, | |
3923 | 1, 1, "P", | |
3924 | "Position point relative to window.\n\ | |
19e3bf0a | 3925 | With no argument, position point at center of window.\n\ |
d81724c7 RS |
3926 | An argument specifies vertical position within the window;\n\ |
3927 | zero means top of window, negative means relative to bottom of window.") | |
7ab12479 JB |
3928 | (arg) |
3929 | register Lisp_Object arg; | |
3930 | { | |
3931 | register struct window *w = XWINDOW (selected_window); | |
3932 | register int height = window_internal_height (w); | |
3933 | register int start; | |
540b6aa0 | 3934 | Lisp_Object window; |
7ab12479 | 3935 | |
265a9e55 | 3936 | if (NILP (arg)) |
d834a2e9 | 3937 | XSETFASTINT (arg, height / 2); |
7ab12479 JB |
3938 | else |
3939 | { | |
3940 | arg = Fprefix_numeric_value (arg); | |
3941 | if (XINT (arg) < 0) | |
3942 | XSETINT (arg, XINT (arg) + height); | |
3943 | } | |
3944 | ||
3945 | start = marker_position (w->start); | |
74112613 | 3946 | XSETWINDOW (window, w); |
7ab12479 JB |
3947 | if (start < BEGV || start > ZV) |
3948 | { | |
cd2be1dd | 3949 | Fvertical_motion (make_number (- (height / 2)), window); |
b73ea88e | 3950 | set_marker_both (w->start, w->buffer, PT, PT_BYTE); |
7ab12479 JB |
3951 | w->start_at_line_beg = Fbolp (); |
3952 | w->force_start = Qt; | |
3953 | } | |
3954 | else | |
b73ea88e | 3955 | Fgoto_char (w->start); |
7ab12479 | 3956 | |
540b6aa0 | 3957 | return Fvertical_motion (arg, window); |
7ab12479 | 3958 | } |
5500c422 GM |
3959 | |
3960 | ||
7ab12479 | 3961 | \f |
5500c422 GM |
3962 | /*********************************************************************** |
3963 | Window Configuration | |
3964 | ***********************************************************************/ | |
3965 | ||
7ab12479 JB |
3966 | struct save_window_data |
3967 | { | |
f5ccc0cc | 3968 | EMACS_INT size_from_Lisp_Vector_struct; |
7ab12479 | 3969 | struct Lisp_Vector *next_from_Lisp_Vector_struct; |
8f6ea2e9 | 3970 | Lisp_Object frame_width, frame_height, frame_menu_bar_lines; |
5500c422 | 3971 | Lisp_Object frame_toolbar_lines; |
bdc727bf | 3972 | Lisp_Object selected_frame; |
7ab12479 JB |
3973 | Lisp_Object current_window; |
3974 | Lisp_Object current_buffer; | |
3975 | Lisp_Object minibuf_scroll_window; | |
3976 | Lisp_Object root_window; | |
bdc727bf | 3977 | Lisp_Object focus_frame; |
756b6edc RS |
3978 | /* Record the values of window-min-width and window-min-height |
3979 | so that window sizes remain consistent with them. */ | |
3980 | Lisp_Object min_width, min_height; | |
cbff28e8 RS |
3981 | /* A vector, each of whose elements is a struct saved_window |
3982 | for one window. */ | |
7ab12479 JB |
3983 | Lisp_Object saved_windows; |
3984 | }; | |
ff06df24 | 3985 | |
cbff28e8 | 3986 | /* This is saved as a Lisp_Vector */ |
7ab12479 JB |
3987 | struct saved_window |
3988 | { | |
3989 | /* these first two must agree with struct Lisp_Vector in lisp.h */ | |
f5ccc0cc | 3990 | EMACS_INT size_from_Lisp_Vector_struct; |
7ab12479 JB |
3991 | struct Lisp_Vector *next_from_Lisp_Vector_struct; |
3992 | ||
3993 | Lisp_Object window; | |
3994 | Lisp_Object buffer, start, pointm, mark; | |
3995 | Lisp_Object left, top, width, height, hscroll; | |
3996 | Lisp_Object parent, prev; | |
3997 | Lisp_Object start_at_line_beg; | |
3998 | Lisp_Object display_table; | |
3999 | }; | |
4000 | #define SAVED_WINDOW_VECTOR_SIZE 14 /* Arg to Fmake_vector */ | |
4001 | ||
4002 | #define SAVED_WINDOW_N(swv,n) \ | |
4003 | ((struct saved_window *) (XVECTOR ((swv)->contents[(n)]))) | |
4004 | ||
4005 | DEFUN ("window-configuration-p", Fwindow_configuration_p, Swindow_configuration_p, 1, 1, 0, | |
cbff28e8 | 4006 | "Return t if OBJECT is a window-configuration object.") |
413430c5 EN |
4007 | (object) |
4008 | Lisp_Object object; | |
7ab12479 | 4009 | { |
413430c5 | 4010 | if (WINDOW_CONFIGURATIONP (object)) |
7ab12479 JB |
4011 | return Qt; |
4012 | return Qnil; | |
4013 | } | |
4014 | ||
3f8ab7bd RS |
4015 | DEFUN ("window-configuration-frame", Fwindow_configuration_frame, Swindow_configuration_frame, 1, 1, 0, |
4016 | "Return the frame that CONFIG, a window-configuration object, is about.") | |
4017 | (config) | |
4018 | Lisp_Object config; | |
4019 | { | |
4020 | register struct save_window_data *data; | |
4021 | struct Lisp_Vector *saved_windows; | |
4022 | ||
4023 | if (! WINDOW_CONFIGURATIONP (config)) | |
4024 | wrong_type_argument (Qwindow_configuration_p, config); | |
4025 | ||
4026 | data = (struct save_window_data *) XVECTOR (config); | |
4027 | saved_windows = XVECTOR (data->saved_windows); | |
4028 | return XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame; | |
4029 | } | |
4030 | ||
d5b2799e RS |
4031 | DEFUN ("set-window-configuration", Fset_window_configuration, |
4032 | Sset_window_configuration, 1, 1, 0, | |
7ab12479 JB |
4033 | "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\ |
4034 | CONFIGURATION must be a value previously returned\n\ | |
3f8ab7bd RS |
4035 | by `current-window-configuration' (which see).\n\ |
4036 | If CONFIGURATION was made from a frame that is now deleted,\n\ | |
4037 | only frame-independent values can be restored. In this case,\n\ | |
4038 | the return value is nil. Otherwise the value is t.") | |
4039 | (configuration) | |
2f83aebe | 4040 | Lisp_Object configuration; |
7ab12479 | 4041 | { |
7ab12479 JB |
4042 | register struct save_window_data *data; |
4043 | struct Lisp_Vector *saved_windows; | |
7ab12479 | 4044 | Lisp_Object new_current_buffer; |
fd482be5 | 4045 | Lisp_Object frame; |
44fa5b1e | 4046 | FRAME_PTR f; |
d2b35234 | 4047 | int old_point = -1; |
7ab12479 | 4048 | |
017b2bad | 4049 | while (!WINDOW_CONFIGURATIONP (configuration)) |
3f8ab7bd | 4050 | wrong_type_argument (Qwindow_configuration_p, configuration); |
7ab12479 | 4051 | |
2f83aebe | 4052 | data = (struct save_window_data *) XVECTOR (configuration); |
7ab12479 JB |
4053 | saved_windows = XVECTOR (data->saved_windows); |
4054 | ||
7ab12479 | 4055 | new_current_buffer = data->current_buffer; |
265a9e55 | 4056 | if (NILP (XBUFFER (new_current_buffer)->name)) |
7ab12479 | 4057 | new_current_buffer = Qnil; |
d2b35234 RS |
4058 | else |
4059 | { | |
4060 | if (XBUFFER (new_current_buffer) == current_buffer) | |
4061 | old_point = PT; | |
cbff28e8 | 4062 | |
d2b35234 | 4063 | } |
7ab12479 | 4064 | |
fd482be5 JB |
4065 | frame = XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame; |
4066 | f = XFRAME (frame); | |
9ace597f | 4067 | |
fd482be5 JB |
4068 | /* If f is a dead frame, don't bother rebuilding its window tree. |
4069 | However, there is other stuff we should still try to do below. */ | |
4070 | if (FRAME_LIVE_P (f)) | |
7ab12479 | 4071 | { |
fd482be5 JB |
4072 | register struct window *w; |
4073 | register struct saved_window *p; | |
5500c422 GM |
4074 | struct window *root_window; |
4075 | struct window **leaf_windows; | |
4076 | int n_leaf_windows; | |
4077 | int k, i; | |
fd482be5 JB |
4078 | |
4079 | /* If the frame has been resized since this window configuration was | |
4080 | made, we change the frame to the size specified in the | |
4081 | configuration, restore the configuration, and then resize it | |
4082 | back. We keep track of the prevailing height in these variables. */ | |
4083 | int previous_frame_height = FRAME_HEIGHT (f); | |
4084 | int previous_frame_width = FRAME_WIDTH (f); | |
8f6ea2e9 | 4085 | int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f); |
5500c422 | 4086 | int previous_frame_toolbar_lines = FRAME_TOOLBAR_LINES (f); |
fd482be5 | 4087 | |
d2b35234 RS |
4088 | /* The mouse highlighting code could get screwed up |
4089 | if it runs during this. */ | |
4090 | BLOCK_INPUT; | |
4091 | ||
fd482be5 JB |
4092 | if (XFASTINT (data->frame_height) != previous_frame_height |
4093 | || XFASTINT (data->frame_width) != previous_frame_width) | |
f8ad443a AS |
4094 | change_frame_size (f, XFASTINT (data->frame_height), |
4095 | XFASTINT (data->frame_width), 0, 0); | |
e3678b64 | 4096 | #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS) |
8f6ea2e9 KH |
4097 | if (XFASTINT (data->frame_menu_bar_lines) |
4098 | != previous_frame_menu_bar_lines) | |
f8ad443a | 4099 | x_set_menu_bar_lines (f, data->frame_menu_bar_lines, make_number (0)); |
4314246f | 4100 | #ifdef HAVE_WINDOW_SYSTEM |
5500c422 GM |
4101 | if (XFASTINT (data->frame_toolbar_lines) |
4102 | != previous_frame_toolbar_lines) | |
4103 | x_set_toolbar_lines (f, data->frame_toolbar_lines, make_number (0)); | |
4314246f | 4104 | #endif |
217f2871 | 4105 | #endif |
fd482be5 | 4106 | |
596ae0cf RS |
4107 | if (! NILP (XWINDOW (selected_window)->buffer)) |
4108 | { | |
4109 | w = XWINDOW (selected_window); | |
4110 | set_marker_both (w->pointm, | |
4111 | w->buffer, | |
4112 | BUF_PT (XBUFFER (w->buffer)), | |
4113 | BUF_PT_BYTE (XBUFFER (w->buffer))); | |
4114 | } | |
4115 | ||
fd482be5 | 4116 | windows_or_buffers_changed++; |
29aeee73 | 4117 | FRAME_WINDOW_SIZES_CHANGED (f) = 1; |
fd482be5 | 4118 | |
5500c422 GM |
4119 | /* Problem: Freeing all matrices and later allocating them again |
4120 | is a serious redisplay flickering problem. What we would | |
4121 | really like to do is to free only those matrices not reused | |
4122 | below. */ | |
4123 | root_window = XWINDOW (FRAME_ROOT_WINDOW (f)); | |
4124 | leaf_windows | |
4125 | = (struct window **) alloca (count_windows (root_window) | |
4126 | * sizeof (struct window *)); | |
4127 | n_leaf_windows = get_leaf_windows (root_window, leaf_windows, 0); | |
4128 | ||
756b6edc RS |
4129 | /* Temporarily avoid any problems with windows that are smaller |
4130 | than they are supposed to be. */ | |
4131 | window_min_height = 1; | |
4132 | window_min_width = 1; | |
4133 | ||
fd482be5 JB |
4134 | /* Kludge Alert! |
4135 | Mark all windows now on frame as "deleted". | |
4136 | Restoring the new configuration "undeletes" any that are in it. | |
37962e60 | 4137 | |
fd482be5 JB |
4138 | Save their current buffers in their height fields, since we may |
4139 | need it later, if a buffer saved in the configuration is now | |
4140 | dead. */ | |
4141 | delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f))); | |
4142 | ||
4143 | for (k = 0; k < saved_windows->size; k++) | |
4144 | { | |
4145 | p = SAVED_WINDOW_N (saved_windows, k); | |
4146 | w = XWINDOW (p->window); | |
4147 | w->next = Qnil; | |
7ab12479 | 4148 | |
fd482be5 JB |
4149 | if (!NILP (p->parent)) |
4150 | w->parent = SAVED_WINDOW_N (saved_windows, | |
4151 | XFASTINT (p->parent))->window; | |
4152 | else | |
4153 | w->parent = Qnil; | |
7ab12479 | 4154 | |
fd482be5 | 4155 | if (!NILP (p->prev)) |
7ab12479 | 4156 | { |
fd482be5 JB |
4157 | w->prev = SAVED_WINDOW_N (saved_windows, |
4158 | XFASTINT (p->prev))->window; | |
4159 | XWINDOW (w->prev)->next = p->window; | |
4160 | } | |
4161 | else | |
4162 | { | |
4163 | w->prev = Qnil; | |
4164 | if (!NILP (w->parent)) | |
4165 | { | |
4166 | if (EQ (p->width, XWINDOW (w->parent)->width)) | |
4167 | { | |
4168 | XWINDOW (w->parent)->vchild = p->window; | |
4169 | XWINDOW (w->parent)->hchild = Qnil; | |
4170 | } | |
4171 | else | |
4172 | { | |
4173 | XWINDOW (w->parent)->hchild = p->window; | |
4174 | XWINDOW (w->parent)->vchild = Qnil; | |
4175 | } | |
4176 | } | |
4177 | } | |
4178 | ||
4179 | /* If we squirreled away the buffer in the window's height, | |
4180 | restore it now. */ | |
017b2bad | 4181 | if (BUFFERP (w->height)) |
fd482be5 JB |
4182 | w->buffer = w->height; |
4183 | w->left = p->left; | |
4184 | w->top = p->top; | |
4185 | w->width = p->width; | |
4186 | w->height = p->height; | |
4187 | w->hscroll = p->hscroll; | |
4188 | w->display_table = p->display_table; | |
d834a2e9 | 4189 | XSETFASTINT (w->last_modified, 0); |
3cd21523 | 4190 | XSETFASTINT (w->last_overlay_modified, 0); |
fd482be5 JB |
4191 | |
4192 | /* Reinstall the saved buffer and pointers into it. */ | |
4193 | if (NILP (p->buffer)) | |
4194 | w->buffer = p->buffer; | |
4195 | else | |
4196 | { | |
4197 | if (!NILP (XBUFFER (p->buffer)->name)) | |
4198 | /* If saved buffer is alive, install it. */ | |
4199 | { | |
4200 | w->buffer = p->buffer; | |
4201 | w->start_at_line_beg = p->start_at_line_beg; | |
b73ea88e RS |
4202 | set_marker_restricted (w->start, p->start, w->buffer); |
4203 | set_marker_restricted (w->pointm, p->pointm, w->buffer); | |
fd482be5 | 4204 | Fset_marker (XBUFFER (w->buffer)->mark, |
b73ea88e | 4205 | p->mark, w->buffer); |
fd482be5 JB |
4206 | |
4207 | /* As documented in Fcurrent_window_configuration, don't | |
4208 | save the location of point in the buffer which was current | |
4209 | when the window configuration was recorded. */ | |
6b54027b RS |
4210 | if (!EQ (p->buffer, new_current_buffer) |
4211 | && XBUFFER (p->buffer) == current_buffer) | |
fd482be5 JB |
4212 | Fgoto_char (w->pointm); |
4213 | } | |
52a68e98 RS |
4214 | else if (NILP (w->buffer) || NILP (XBUFFER (w->buffer)->name)) |
4215 | /* Else unless window has a live buffer, get one. */ | |
7ab12479 | 4216 | { |
fd482be5 JB |
4217 | w->buffer = Fcdr (Fcar (Vbuffer_alist)); |
4218 | /* This will set the markers to beginning of visible | |
4219 | range. */ | |
4220 | set_marker_restricted (w->start, make_number (0), w->buffer); | |
4221 | set_marker_restricted (w->pointm, make_number (0),w->buffer); | |
4222 | w->start_at_line_beg = Qt; | |
7ab12479 JB |
4223 | } |
4224 | else | |
fd482be5 | 4225 | /* Keeping window's old buffer; make sure the markers |
52a68e98 | 4226 | are real. */ |
7ab12479 | 4227 | { |
fd482be5 JB |
4228 | /* Set window markers at start of visible range. */ |
4229 | if (XMARKER (w->start)->buffer == 0) | |
4230 | set_marker_restricted (w->start, make_number (0), | |
4231 | w->buffer); | |
4232 | if (XMARKER (w->pointm)->buffer == 0) | |
b73ea88e RS |
4233 | set_marker_restricted_both (w->pointm, w->buffer, |
4234 | BUF_PT (XBUFFER (w->buffer)), | |
4235 | BUF_PT_BYTE (XBUFFER (w->buffer))); | |
fd482be5 | 4236 | w->start_at_line_beg = Qt; |
7ab12479 JB |
4237 | } |
4238 | } | |
4239 | } | |
9ace597f | 4240 | |
fd482be5 JB |
4241 | FRAME_ROOT_WINDOW (f) = data->root_window; |
4242 | Fselect_window (data->current_window); | |
396a830c RS |
4243 | XBUFFER (XWINDOW (selected_window)->buffer)->last_selected_window |
4244 | = selected_window; | |
7ab12479 | 4245 | |
db269683 | 4246 | if (NILP (data->focus_frame) |
017b2bad | 4247 | || (FRAMEP (data->focus_frame) |
db269683 JB |
4248 | && FRAME_LIVE_P (XFRAME (data->focus_frame)))) |
4249 | Fredirect_frame_focus (frame, data->focus_frame); | |
7ab12479 | 4250 | |
fd482be5 JB |
4251 | #if 0 /* I don't understand why this is needed, and it causes problems |
4252 | when the frame's old selected window has been deleted. */ | |
e4e59717 | 4253 | if (f != selected_frame && FRAME_WINDOW_P (f)) |
9a7c6fc3 RS |
4254 | do_switch_frame (WINDOW_FRAME (XWINDOW (data->root_window)), |
4255 | Qnil, 0); | |
fd482be5 JB |
4256 | #endif |
4257 | ||
4258 | /* Set the screen height to the value it had before this function. */ | |
4259 | if (previous_frame_height != FRAME_HEIGHT (f) | |
4260 | || previous_frame_width != FRAME_WIDTH (f)) | |
4261 | change_frame_size (f, previous_frame_height, previous_frame_width, | |
4262 | 0, 0); | |
e3678b64 | 4263 | #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS) |
8f6ea2e9 | 4264 | if (previous_frame_menu_bar_lines != FRAME_MENU_BAR_LINES (f)) |
f8ad443a AS |
4265 | x_set_menu_bar_lines (f, make_number (previous_frame_menu_bar_lines), |
4266 | make_number (0)); | |
4314246f | 4267 | #ifdef HAVE_WINDOW_SYSTEM |
5500c422 GM |
4268 | if (previous_frame_toolbar_lines != FRAME_TOOLBAR_LINES (f)) |
4269 | x_set_toolbar_lines (f, make_number (previous_frame_toolbar_lines), | |
4270 | make_number (0)); | |
4314246f | 4271 | #endif |
217f2871 | 4272 | #endif |
d2b35234 | 4273 | |
5500c422 GM |
4274 | /* Now, free glyph matrices in windows that were not reused. */ |
4275 | for (i = 0; i < n_leaf_windows; ++i) | |
4276 | if (NILP (leaf_windows[i]->buffer)) | |
4277 | { | |
4278 | /* Assert it's not reused as a combination. */ | |
4279 | xassert (NILP (leaf_windows[i]->hchild) | |
4280 | && NILP (leaf_windows[i]->vchild)); | |
4281 | free_window_matrices (leaf_windows[i]); | |
4282 | SET_FRAME_GARBAGED (f); | |
4283 | } | |
4284 | ||
4285 | adjust_glyphs (f); | |
4286 | ||
d2b35234 | 4287 | UNBLOCK_INPUT; |
756b6edc | 4288 | |
478292ed RS |
4289 | /* Fselect_window will have made f the selected frame, so we |
4290 | reselect the proper frame here. Fhandle_switch_frame will change the | |
4291 | selected window too, but that doesn't make the call to | |
4292 | Fselect_window above totally superfluous; it still sets f's | |
4293 | selected window. */ | |
4294 | if (FRAME_LIVE_P (XFRAME (data->selected_frame))) | |
4295 | do_switch_frame (data->selected_frame, Qnil, 0); | |
4296 | ||
4297 | if (! NILP (Vwindow_configuration_change_hook) | |
4298 | && ! NILP (Vrun_hooks)) | |
4299 | call1 (Vrun_hooks, Qwindow_configuration_change_hook); | |
4300 | } | |
bdc727bf JB |
4301 | |
4302 | if (!NILP (new_current_buffer)) | |
d2b35234 RS |
4303 | { |
4304 | Fset_buffer (new_current_buffer); | |
4305 | ||
4306 | /* If the buffer that is current now is the same | |
4307 | that was current before setting the window configuration, | |
4308 | don't alter its PT. */ | |
4309 | if (old_point >= 0) | |
4310 | SET_PT (old_point); | |
4311 | } | |
bdc727bf | 4312 | |
478292ed RS |
4313 | /* Restore the minimum heights recorded in the configuration. */ |
4314 | window_min_height = XINT (data->min_height); | |
4315 | window_min_width = XINT (data->min_width); | |
543f5fb1 | 4316 | |
478292ed | 4317 | Vminibuf_scroll_window = data->minibuf_scroll_window; |
543f5fb1 | 4318 | |
3f8ab7bd | 4319 | return (FRAME_LIVE_P (f) ? Qt : Qnil); |
7ab12479 JB |
4320 | } |
4321 | ||
44fa5b1e | 4322 | /* Mark all windows now on frame as deleted |
7ab12479 JB |
4323 | by setting their buffers to nil. */ |
4324 | ||
fd482be5 | 4325 | void |
7ab12479 JB |
4326 | delete_all_subwindows (w) |
4327 | register struct window *w; | |
4328 | { | |
265a9e55 | 4329 | if (!NILP (w->next)) |
7ab12479 | 4330 | delete_all_subwindows (XWINDOW (w->next)); |
265a9e55 | 4331 | if (!NILP (w->vchild)) |
7ab12479 | 4332 | delete_all_subwindows (XWINDOW (w->vchild)); |
265a9e55 | 4333 | if (!NILP (w->hchild)) |
7ab12479 | 4334 | delete_all_subwindows (XWINDOW (w->hchild)); |
605be8af JB |
4335 | |
4336 | w->height = w->buffer; /* See Fset_window_configuration for excuse. */ | |
4337 | ||
86e48436 RS |
4338 | if (!NILP (w->buffer)) |
4339 | unshow_buffer (w); | |
4340 | ||
605be8af JB |
4341 | /* We set all three of these fields to nil, to make sure that we can |
4342 | distinguish this dead window from any live window. Live leaf | |
4343 | windows will have buffer set, and combination windows will have | |
4344 | vchild or hchild set. */ | |
4345 | w->buffer = Qnil; | |
4346 | w->vchild = Qnil; | |
4347 | w->hchild = Qnil; | |
7ab12479 JB |
4348 | } |
4349 | \f | |
4350 | static int | |
4351 | count_windows (window) | |
4352 | register struct window *window; | |
4353 | { | |
4354 | register int count = 1; | |
265a9e55 | 4355 | if (!NILP (window->next)) |
7ab12479 | 4356 | count += count_windows (XWINDOW (window->next)); |
265a9e55 | 4357 | if (!NILP (window->vchild)) |
7ab12479 | 4358 | count += count_windows (XWINDOW (window->vchild)); |
265a9e55 | 4359 | if (!NILP (window->hchild)) |
7ab12479 JB |
4360 | count += count_windows (XWINDOW (window->hchild)); |
4361 | return count; | |
4362 | } | |
4363 | ||
5500c422 GM |
4364 | |
4365 | /* Fill vector FLAT with leaf windows under W, starting at index I. | |
4366 | Value is last index + 1. */ | |
4367 | ||
4368 | static int | |
4369 | get_leaf_windows (w, flat, i) | |
4370 | struct window *w; | |
4371 | struct window **flat; | |
4372 | int i; | |
4373 | { | |
4374 | while (w) | |
4375 | { | |
4376 | if (!NILP (w->hchild)) | |
4377 | i = get_leaf_windows (XWINDOW (w->hchild), flat, i); | |
4378 | else if (!NILP (w->vchild)) | |
4379 | i = get_leaf_windows (XWINDOW (w->vchild), flat, i); | |
4380 | else | |
4381 | flat[i++] = w; | |
4382 | ||
4383 | w = NILP (w->next) ? 0 : XWINDOW (w->next); | |
4384 | } | |
4385 | ||
4386 | return i; | |
4387 | } | |
4388 | ||
4389 | ||
4390 | /* Return a pointer to the glyph W's physical cursor is on. Value is | |
4391 | null if W's current matrix is invalid, so that no meaningfull glyph | |
4392 | can be returned. */ | |
4393 | ||
4394 | struct glyph * | |
4395 | get_phys_cursor_glyph (w) | |
4396 | struct window *w; | |
4397 | { | |
4398 | struct glyph_row *row; | |
4399 | struct glyph *glyph; | |
4400 | ||
4401 | if (w->phys_cursor.vpos >= 0 | |
4402 | && w->phys_cursor.vpos < w->current_matrix->nrows | |
4403 | && (row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos), | |
4404 | row->enabled_p) | |
4405 | && row->used[TEXT_AREA] > w->phys_cursor.hpos) | |
4406 | glyph = row->glyphs[TEXT_AREA] + w->phys_cursor.hpos; | |
4407 | else | |
4408 | glyph = NULL; | |
4409 | ||
4410 | return glyph; | |
4411 | } | |
4412 | ||
4413 | ||
7ab12479 JB |
4414 | static int |
4415 | save_window_save (window, vector, i) | |
4416 | Lisp_Object window; | |
4417 | struct Lisp_Vector *vector; | |
4418 | int i; | |
4419 | { | |
4420 | register struct saved_window *p; | |
4421 | register struct window *w; | |
4422 | register Lisp_Object tem; | |
4423 | ||
265a9e55 | 4424 | for (;!NILP (window); window = w->next) |
7ab12479 JB |
4425 | { |
4426 | p = SAVED_WINDOW_N (vector, i); | |
4427 | w = XWINDOW (window); | |
4428 | ||
d834a2e9 | 4429 | XSETFASTINT (w->temslot, i++); |
7ab12479 JB |
4430 | p->window = window; |
4431 | p->buffer = w->buffer; | |
4432 | p->left = w->left; | |
4433 | p->top = w->top; | |
4434 | p->width = w->width; | |
4435 | p->height = w->height; | |
4436 | p->hscroll = w->hscroll; | |
4437 | p->display_table = w->display_table; | |
265a9e55 | 4438 | if (!NILP (w->buffer)) |
7ab12479 JB |
4439 | { |
4440 | /* Save w's value of point in the window configuration. | |
4441 | If w is the selected window, then get the value of point | |
4442 | from the buffer; pointm is garbage in the selected window. */ | |
4443 | if (EQ (window, selected_window)) | |
4444 | { | |
4445 | p->pointm = Fmake_marker (); | |
b73ea88e RS |
4446 | set_marker_both (p->pointm, w->buffer, |
4447 | BUF_PT (XBUFFER (w->buffer)), | |
4448 | BUF_PT_BYTE (XBUFFER (w->buffer))); | |
7ab12479 JB |
4449 | } |
4450 | else | |
eeb82665 | 4451 | p->pointm = Fcopy_marker (w->pointm, Qnil); |
7ab12479 | 4452 | |
eeb82665 | 4453 | p->start = Fcopy_marker (w->start, Qnil); |
7ab12479 JB |
4454 | p->start_at_line_beg = w->start_at_line_beg; |
4455 | ||
4456 | tem = XBUFFER (w->buffer)->mark; | |
eeb82665 | 4457 | p->mark = Fcopy_marker (tem, Qnil); |
7ab12479 JB |
4458 | } |
4459 | else | |
4460 | { | |
4461 | p->pointm = Qnil; | |
4462 | p->start = Qnil; | |
4463 | p->mark = Qnil; | |
4464 | p->start_at_line_beg = Qnil; | |
4465 | } | |
4466 | ||
265a9e55 | 4467 | if (NILP (w->parent)) |
7ab12479 JB |
4468 | p->parent = Qnil; |
4469 | else | |
4470 | p->parent = XWINDOW (w->parent)->temslot; | |
4471 | ||
265a9e55 | 4472 | if (NILP (w->prev)) |
7ab12479 JB |
4473 | p->prev = Qnil; |
4474 | else | |
4475 | p->prev = XWINDOW (w->prev)->temslot; | |
4476 | ||
265a9e55 | 4477 | if (!NILP (w->vchild)) |
7ab12479 | 4478 | i = save_window_save (w->vchild, vector, i); |
265a9e55 | 4479 | if (!NILP (w->hchild)) |
7ab12479 JB |
4480 | i = save_window_save (w->hchild, vector, i); |
4481 | } | |
4482 | ||
4483 | return i; | |
4484 | } | |
4485 | ||
a0d76c27 EN |
4486 | DEFUN ("current-window-configuration", Fcurrent_window_configuration, |
4487 | Scurrent_window_configuration, 0, 1, 0, | |
44fa5b1e JB |
4488 | "Return an object representing the current window configuration of FRAME.\n\ |
4489 | If FRAME is nil or omitted, use the selected frame.\n\ | |
7ab12479 JB |
4490 | This describes the number of windows, their sizes and current buffers,\n\ |
4491 | and for each displayed buffer, where display starts, and the positions of\n\ | |
4492 | point and mark. An exception is made for point in the current buffer:\n\ | |
bdc727bf JB |
4493 | its value is -not- saved.\n\ |
4494 | This also records the currently selected frame, and FRAME's focus\n\ | |
4495 | redirection (see `redirect-frame-focus').") | |
44fa5b1e JB |
4496 | (frame) |
4497 | Lisp_Object frame; | |
7ab12479 JB |
4498 | { |
4499 | register Lisp_Object tem; | |
4500 | register int n_windows; | |
4501 | register struct save_window_data *data; | |
da2792e0 | 4502 | register struct Lisp_Vector *vec; |
7ab12479 | 4503 | register int i; |
44fa5b1e | 4504 | FRAME_PTR f; |
43bad991 | 4505 | |
44fa5b1e JB |
4506 | if (NILP (frame)) |
4507 | f = selected_frame; | |
43bad991 JB |
4508 | else |
4509 | { | |
44fa5b1e JB |
4510 | CHECK_LIVE_FRAME (frame, 0); |
4511 | f = XFRAME (frame); | |
43bad991 | 4512 | } |
7ab12479 | 4513 | |
44fa5b1e | 4514 | n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f))); |
da2792e0 KH |
4515 | vec = allocate_vectorlike (VECSIZE (struct save_window_data)); |
4516 | for (i = 0; i < VECSIZE (struct save_window_data); i++) | |
4517 | vec->contents[i] = Qnil; | |
4518 | vec->size = VECSIZE (struct save_window_data); | |
4519 | data = (struct save_window_data *)vec; | |
4520 | ||
d834a2e9 KH |
4521 | XSETFASTINT (data->frame_width, FRAME_WIDTH (f)); |
4522 | XSETFASTINT (data->frame_height, FRAME_HEIGHT (f)); | |
4523 | XSETFASTINT (data->frame_menu_bar_lines, FRAME_MENU_BAR_LINES (f)); | |
5500c422 | 4524 | XSETFASTINT (data->frame_toolbar_lines, FRAME_TOOLBAR_LINES (f)); |
74112613 | 4525 | XSETFRAME (data->selected_frame, selected_frame); |
44fa5b1e | 4526 | data->current_window = FRAME_SELECTED_WINDOW (f); |
74112613 | 4527 | XSETBUFFER (data->current_buffer, current_buffer); |
7ab12479 | 4528 | data->minibuf_scroll_window = Vminibuf_scroll_window; |
44fa5b1e | 4529 | data->root_window = FRAME_ROOT_WINDOW (f); |
bdc727bf | 4530 | data->focus_frame = FRAME_FOCUS_FRAME (f); |
74112613 KH |
4531 | XSETINT (data->min_height, window_min_height); |
4532 | XSETINT (data->min_width, window_min_width); | |
7ab12479 JB |
4533 | tem = Fmake_vector (make_number (n_windows), Qnil); |
4534 | data->saved_windows = tem; | |
4535 | for (i = 0; i < n_windows; i++) | |
4536 | XVECTOR (tem)->contents[i] | |
4537 | = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE), Qnil); | |
44fa5b1e | 4538 | save_window_save (FRAME_ROOT_WINDOW (f), |
7ab12479 | 4539 | XVECTOR (tem), 0); |
74112613 | 4540 | XSETWINDOW_CONFIGURATION (tem, data); |
7ab12479 JB |
4541 | return (tem); |
4542 | } | |
4543 | ||
4544 | DEFUN ("save-window-excursion", Fsave_window_excursion, Ssave_window_excursion, | |
4545 | 0, UNEVALLED, 0, | |
4546 | "Execute body, preserving window sizes and contents.\n\ | |
eb16ec06 RS |
4547 | Restore which buffer appears in which window, where display starts,\n\ |
4548 | and the value of point and mark for each window.\n\ | |
4549 | Also restore which buffer is current.\n\ | |
4550 | But do not preserve point in the current buffer.\n\ | |
7ab12479 JB |
4551 | Does not restore the value of point in current buffer.") |
4552 | (args) | |
4553 | Lisp_Object args; | |
4554 | { | |
4555 | register Lisp_Object val; | |
4556 | register int count = specpdl_ptr - specpdl; | |
4557 | ||
4558 | record_unwind_protect (Fset_window_configuration, | |
43bad991 | 4559 | Fcurrent_window_configuration (Qnil)); |
7ab12479 JB |
4560 | val = Fprogn (args); |
4561 | return unbind_to (count, val); | |
4562 | } | |
5500c422 GM |
4563 | |
4564 | \f | |
4565 | /*********************************************************************** | |
4566 | Marginal Areas | |
4567 | ***********************************************************************/ | |
4568 | ||
4569 | DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins, | |
4570 | 2, 3, "", | |
4571 | "Set width of marginal areas of window WINDOW.\n\ | |
4572 | If window is nil or omitted, set margins of the currently selected window.\n\ | |
4573 | First parameter LEFT-WIDTH specifies the number of character\n\ | |
4574 | cells to reserve for the left marginal area. Second parameter\n\ | |
4575 | RIGHT-WIDTH does the same for the right marginal area.\n\ | |
4576 | A nil width parameter means no margin.") | |
4577 | (left, right, window) | |
4578 | Lisp_Object window, left, right; | |
4579 | { | |
4580 | struct window *w = decode_window (window); | |
4581 | struct frame *f = XFRAME (w->frame); | |
4582 | ||
4583 | if (!NILP (left)) | |
4584 | CHECK_NUMBER_OR_FLOAT (left, 0); | |
4585 | if (!NILP (right)) | |
4586 | CHECK_NUMBER_OR_FLOAT (right, 0); | |
4587 | ||
4588 | /* Check widths < 0 and translate a zero width to nil. | |
4589 | Margins that are too wide have to be checked elsewhere. */ | |
4590 | if ((INTEGERP (left) && XINT (left) < 0) | |
4591 | || (FLOATP (left) && XFLOAT (left)->data <= 0)) | |
4592 | XSETFASTINT (left, 0); | |
4593 | if (INTEGERP (left) && XFASTINT (left) == 0) | |
4594 | left = Qnil; | |
4595 | ||
4596 | if ((INTEGERP (right) && XINT (right) < 0) | |
4597 | || (FLOATP (right) && XFLOAT (right)->data <= 0)) | |
4598 | XSETFASTINT (right, 0); | |
4599 | if (INTEGERP (right) && XFASTINT (right) == 0) | |
4600 | right = Qnil; | |
4601 | ||
4602 | w->left_margin_width = left; | |
4603 | w->right_margin_width = right; | |
4604 | ||
4605 | ++windows_or_buffers_changed; | |
4606 | adjust_glyphs (XFRAME (WINDOW_FRAME (w))); | |
4607 | return Qnil; | |
4608 | } | |
4609 | ||
4610 | ||
4611 | DEFUN ("window-margins", Fwindow_margins, Swindow_margins, | |
4612 | 0, 1, 0, | |
4613 | "Get width of marginal areas of window WINDOW.\n\ | |
4614 | If WINDOW is omitted or nil, use the currently selected window.\n\ | |
4615 | Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).\n\ | |
4616 | If a marginal area does not exist, its width will be returned\n\ | |
4617 | as nil.") | |
4618 | (window) | |
4619 | Lisp_Object window; | |
4620 | { | |
4621 | struct window *w = decode_window (window); | |
4622 | return Fcons (w->left_margin_width, w->right_margin_width); | |
4623 | } | |
4624 | ||
4625 | ||
7ab12479 | 4626 | \f |
5500c422 GM |
4627 | /*********************************************************************** |
4628 | Smooth scrolling | |
4629 | ***********************************************************************/ | |
4630 | ||
4631 | DEFUN ("window-vscroll", Fwindow_vscroll, Swindow_vscroll, 0, 1, 0, | |
4632 | "Return the amount by which WINDOW is scrolled vertically.\n\ | |
4633 | Use the selected window if WINDOW is nil or omitted.\n\ | |
4634 | Value is a multiple of the canonical character height of WINDOW.") | |
4635 | (window) | |
4636 | Lisp_Object window; | |
4637 | { | |
4638 | struct frame *f; | |
4639 | struct window *w; | |
4640 | ||
4641 | if (NILP (window)) | |
4642 | window = selected_window; | |
4643 | w = XWINDOW (window); | |
4644 | f = XFRAME (w->frame); | |
4645 | ||
4646 | if (FRAME_WINDOW_P (f)) | |
4647 | return CANON_Y_FROM_PIXEL_Y (f, w->vscroll); | |
4648 | else | |
4649 | return make_number (0); | |
4650 | } | |
4651 | ||
4652 | ||
4653 | DEFUN ("set-window-vscroll", Fset_window_vscroll, Sset_window_vscroll, | |
4654 | 1, 2, 0, | |
4655 | "Set amount by WINDOW should be scrolled vertically to VSCROLL.\n\ | |
4656 | WINDOW nil or omitted means use the selected window. VSCROLL is a\n\ | |
4657 | multiple of the canonical character height of WINDOW.") | |
4658 | (vscroll, window) | |
4659 | Lisp_Object vscroll, window; | |
4660 | { | |
4661 | struct window *w; | |
4662 | struct frame *f; | |
4663 | ||
4664 | CHECK_NUMBER_OR_FLOAT (vscroll, 0); | |
4665 | ||
4666 | if (NILP (window)) | |
4667 | window = selected_window; | |
4668 | w = XWINDOW (window); | |
4669 | f = XFRAME (w->frame); | |
4670 | ||
4671 | if (FRAME_WINDOW_P (f)) | |
4672 | { | |
4673 | int old_dy = w->vscroll; | |
4674 | w->vscroll = min (0, CANON_Y_UNIT (f) * XFLOATINT (vscroll)); | |
4675 | ||
4676 | /* Adjust glyph matrix of the frame if the virtual display | |
4677 | area becomes larger than before. */ | |
4678 | if (w->vscroll < 0 && w->vscroll < old_dy) | |
4679 | adjust_glyphs (f); | |
4680 | ||
4681 | /* Prevent redisplay shortcuts. */ | |
4682 | XBUFFER (w->buffer)->clip_changed = 1; | |
4683 | } | |
4684 | ||
4685 | return Qnil; | |
4686 | } | |
4687 | ||
4688 | ||
4689 | \f | |
4690 | /*********************************************************************** | |
4691 | Initialization | |
4692 | ***********************************************************************/ | |
4693 | ||
cbff28e8 RS |
4694 | /* Return 1 if window configurations C1 and C2 |
4695 | describe the same state of affairs. This is used by Fequal. */ | |
4696 | ||
4697 | int | |
2f8274be | 4698 | compare_window_configurations (c1, c2, ignore_positions) |
cbff28e8 | 4699 | Lisp_Object c1, c2; |
2f8274be | 4700 | int ignore_positions; |
cbff28e8 RS |
4701 | { |
4702 | register struct save_window_data *d1, *d2; | |
4703 | struct Lisp_Vector *sw1, *sw2; | |
4704 | int i; | |
4705 | ||
4706 | d1 = (struct save_window_data *) XVECTOR (c1); | |
4707 | d2 = (struct save_window_data *) XVECTOR (c2); | |
4708 | sw1 = XVECTOR (d1->saved_windows); | |
4709 | sw2 = XVECTOR (d2->saved_windows); | |
4710 | ||
4711 | if (! EQ (d1->frame_width, d2->frame_width)) | |
4712 | return 0; | |
4713 | if (! EQ (d1->frame_height, d2->frame_height)) | |
4714 | return 0; | |
4715 | if (! EQ (d1->frame_menu_bar_lines, d2->frame_menu_bar_lines)) | |
4716 | return 0; | |
4717 | if (! EQ (d1->selected_frame, d2->selected_frame)) | |
4718 | return 0; | |
4719 | /* Don't compare the current_window field directly. | |
4720 | Instead see w1_is_current and w2_is_current, below. */ | |
4721 | if (! EQ (d1->current_buffer, d2->current_buffer)) | |
4722 | return 0; | |
2f8274be RS |
4723 | if (! ignore_positions) |
4724 | if (! EQ (d1->minibuf_scroll_window, d2->minibuf_scroll_window)) | |
4725 | return 0; | |
cbff28e8 RS |
4726 | /* Don't compare the root_window field. |
4727 | We don't require the two configurations | |
4728 | to use the same window object, | |
4729 | and the two root windows must be equivalent | |
4730 | if everything else compares equal. */ | |
4731 | if (! EQ (d1->focus_frame, d2->focus_frame)) | |
4732 | return 0; | |
4733 | if (! EQ (d1->min_width, d2->min_width)) | |
4734 | return 0; | |
4735 | if (! EQ (d1->min_height, d2->min_height)) | |
4736 | return 0; | |
4737 | ||
4738 | /* Verify that the two confis have the same number of windows. */ | |
4739 | if (sw1->size != sw2->size) | |
4740 | return 0; | |
4741 | ||
4742 | for (i = 0; i < sw1->size; i++) | |
4743 | { | |
4744 | struct saved_window *p1, *p2; | |
4745 | int w1_is_current, w2_is_current; | |
4746 | ||
4747 | p1 = SAVED_WINDOW_N (sw1, i); | |
4748 | p2 = SAVED_WINDOW_N (sw2, i); | |
4749 | ||
4750 | /* Verify that the current windows in the two | |
4751 | configurations correspond to each other. */ | |
4752 | w1_is_current = EQ (d1->current_window, p1->window); | |
4753 | w2_is_current = EQ (d2->current_window, p2->window); | |
4754 | ||
4755 | if (w1_is_current != w2_is_current) | |
4756 | return 0; | |
4757 | ||
4758 | /* Verify that the corresponding windows do match. */ | |
4759 | if (! EQ (p1->buffer, p2->buffer)) | |
4760 | return 0; | |
4761 | if (! EQ (p1->left, p2->left)) | |
4762 | return 0; | |
4763 | if (! EQ (p1->top, p2->top)) | |
4764 | return 0; | |
4765 | if (! EQ (p1->width, p2->width)) | |
4766 | return 0; | |
4767 | if (! EQ (p1->height, p2->height)) | |
4768 | return 0; | |
cbff28e8 RS |
4769 | if (! EQ (p1->display_table, p2->display_table)) |
4770 | return 0; | |
4771 | if (! EQ (p1->parent, p2->parent)) | |
4772 | return 0; | |
4773 | if (! EQ (p1->prev, p2->prev)) | |
4774 | return 0; | |
2f8274be RS |
4775 | if (! ignore_positions) |
4776 | { | |
4777 | if (! EQ (p1->hscroll, p2->hscroll)) | |
4778 | return 0; | |
4779 | if (! EQ (p1->start_at_line_beg, p2->start_at_line_beg)) | |
4780 | return 0; | |
4781 | if (NILP (Fequal (p1->start, p2->start))) | |
4782 | return 0; | |
4783 | if (NILP (Fequal (p1->pointm, p2->pointm))) | |
4784 | return 0; | |
4785 | if (NILP (Fequal (p1->mark, p2->mark))) | |
4786 | return 0; | |
4787 | } | |
cbff28e8 RS |
4788 | } |
4789 | ||
4790 | return 1; | |
4791 | } | |
2f8274be RS |
4792 | |
4793 | DEFUN ("compare-window-configurations", Fcompare_window_configurations, | |
4794 | Scompare_window_configurations, 2, 2, 0, | |
4795 | "Compare two window configurations as regards the structure of windows.\n\ | |
4796 | This function ignores details such as the values of point and mark\n\ | |
4797 | and scrolling positions.") | |
4798 | (x, y) | |
4799 | Lisp_Object x, y; | |
4800 | { | |
4801 | if (compare_window_configurations (x, y, 1)) | |
4802 | return Qt; | |
4803 | return Qnil; | |
4804 | } | |
cbff28e8 | 4805 | \f |
dfcf069d | 4806 | void |
7ab12479 JB |
4807 | init_window_once () |
4808 | { | |
44fa5b1e | 4809 | selected_frame = make_terminal_frame (); |
bc6c324f | 4810 | XSETFRAME (Vterminal_frame, selected_frame); |
44fa5b1e JB |
4811 | minibuf_window = selected_frame->minibuffer_window; |
4812 | selected_window = selected_frame->selected_window; | |
4813 | last_nonminibuf_frame = selected_frame; | |
5b03d3c0 RS |
4814 | |
4815 | window_initialized = 1; | |
7ab12479 JB |
4816 | } |
4817 | ||
dfcf069d | 4818 | void |
7ab12479 JB |
4819 | syms_of_window () |
4820 | { | |
fbad6f9a GM |
4821 | Qleft_bitmap_area = intern ("left-bitmap-area"); |
4822 | staticpro (&Qleft_bitmap_area); | |
4823 | Qright_bitmap_area = intern ("right-bitmap-area"); | |
4824 | staticpro (&Qright_bitmap_area); | |
4825 | ||
233a4a2c GM |
4826 | Qfixed_window_size = intern ("fixed-window-size"); |
4827 | staticpro (&Qfixed_window_size); | |
4828 | ||
543f5fb1 RS |
4829 | staticpro (&Qwindow_configuration_change_hook); |
4830 | Qwindow_configuration_change_hook | |
4831 | = intern ("window-configuration-change-hook"); | |
4832 | ||
7ab12479 JB |
4833 | Qwindowp = intern ("windowp"); |
4834 | staticpro (&Qwindowp); | |
4835 | ||
3f8ab7bd RS |
4836 | Qwindow_configuration_p = intern ("window-configuration-p"); |
4837 | staticpro (&Qwindow_configuration_p); | |
4838 | ||
806b4d9b JB |
4839 | Qwindow_live_p = intern ("window-live-p"); |
4840 | staticpro (&Qwindow_live_p); | |
605be8af | 4841 | |
2cccc823 | 4842 | Qtemp_buffer_show_hook = intern ("temp-buffer-show-hook"); |
a58ec57d RS |
4843 | staticpro (&Qtemp_buffer_show_hook); |
4844 | ||
7ab12479 JB |
4845 | DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function, |
4846 | "Non-nil means call as function to display a help buffer.\n\ | |
c3ef6b1d | 4847 | The function is called with one argument, the buffer to be displayed.\n\ |
f52cca03 RS |
4848 | Used by `with-output-to-temp-buffer'.\n\ |
4849 | If this function is used, then it must do the entire job of showing\n\ | |
4850 | the buffer; `temp-buffer-show-hook' is not run unless this function runs it."); | |
7ab12479 JB |
4851 | Vtemp_buffer_show_function = Qnil; |
4852 | ||
4853 | DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function, | |
4854 | "If non-nil, function to call to handle `display-buffer'.\n\ | |
4855 | It will receive two args, the buffer and a flag which if non-nil means\n\ | |
4856 | that the currently selected window is not acceptable.\n\ | |
4857 | Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\ | |
4858 | work using this function."); | |
4859 | Vdisplay_buffer_function = Qnil; | |
4860 | ||
7ab12479 JB |
4861 | DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window, |
4862 | "Non-nil means it is the window that C-M-v in minibuffer should scroll."); | |
4863 | Vminibuf_scroll_window = Qnil; | |
4864 | ||
4865 | DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer, | |
4866 | "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window."); | |
4867 | Vother_window_scroll_buffer = Qnil; | |
4868 | ||
44fa5b1e | 4869 | DEFVAR_BOOL ("pop-up-frames", &pop_up_frames, |
700f75a4 | 4870 | "*Non-nil means `display-buffer' should make a separate frame."); |
44fa5b1e | 4871 | pop_up_frames = 0; |
7ab12479 | 4872 | |
44fa5b1e | 4873 | DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function, |
a90712c2 | 4874 | "Function to call to handle automatic new frame creation.\n\ |
44fa5b1e | 4875 | It is called with no arguments and should return a newly created frame.\n\ |
7ab12479 | 4876 | \n\ |
44fa5b1e JB |
4877 | A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\ |
4878 | where `pop-up-frame-alist' would hold the default frame parameters."); | |
4879 | Vpop_up_frame_function = Qnil; | |
7ab12479 | 4880 | |
a90712c2 RS |
4881 | DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names, |
4882 | "*List of buffer names that should have their own special frames.\n\ | |
4883 | Displaying a buffer whose name is in this list makes a special frame for it\n\ | |
524580a4 | 4884 | using `special-display-function'. See also `special-display-regexps'.\n\ |
3548e138 | 4885 | \n\ |
524580a4 RS |
4886 | An element of the list can be a list instead of just a string.\n\ |
4887 | There are two ways to use a list as an element:\n\ | |
4888 | (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)\n\ | |
4889 | In the first case, FRAME-PARAMETERS are used to create the frame.\n\ | |
4890 | In the latter case, FUNCTION is called with BUFFER as the first argument,\n\ | |
4891 | followed by OTHER-ARGS--it can display BUFFER in any way it likes.\n\ | |
4caa7448 RS |
4892 | All this is done by the function found in `special-display-function'.\n\ |
4893 | \n\ | |
4894 | If this variable appears \"not to work\", because you add a name to it\n\ | |
4895 | but that buffer still appears in the selected window, look at the\n\ | |
4896 | values of `same-window-buffer-names' and `same-window-regexps'.\n\ | |
4897 | Those variables take precedence over this one."); | |
a90712c2 RS |
4898 | Vspecial_display_buffer_names = Qnil; |
4899 | ||
4900 | DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps, | |
4901 | "*List of regexps saying which buffers should have their own special frames.\n\ | |
4902 | If a buffer name matches one of these regexps, it gets its own frame.\n\ | |
4903 | Displaying a buffer whose name is in this list makes a special frame for it\n\ | |
0a952b57 | 4904 | using `special-display-function'.\n\ |
3548e138 | 4905 | \n\ |
524580a4 RS |
4906 | An element of the list can be a list instead of just a string.\n\ |
4907 | There are two ways to use a list as an element:\n\ | |
4908 | (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)\n\ | |
4909 | In the first case, FRAME-PARAMETERS are used to create the frame.\n\ | |
4910 | In the latter case, FUNCTION is called with the buffer as first argument,\n\ | |
4911 | followed by OTHER-ARGS--it can display the buffer in any way it likes.\n\ | |
4caa7448 RS |
4912 | All this is done by the function found in `special-display-function'.\n\ |
4913 | \n\ | |
4914 | If this variable appears \"not to work\", because you add a regexp to it\n\ | |
4915 | but the matching buffers still appear in the selected window, look at the\n\ | |
4916 | values of `same-window-buffer-names' and `same-window-regexps'.\n\ | |
4917 | Those variables take precedence over this one."); | |
a90712c2 RS |
4918 | Vspecial_display_regexps = Qnil; |
4919 | ||
4920 | DEFVAR_LISP ("special-display-function", &Vspecial_display_function, | |
4921 | "Function to call to make a new frame for a special buffer.\n\ | |
0a952b57 RS |
4922 | It is called with two arguments, the buffer and optional buffer specific\n\ |
4923 | data, and should return a window displaying that buffer.\n\ | |
a90712c2 | 4924 | The default value makes a separate frame for the buffer,\n\ |
bdd3a802 | 4925 | using `special-display-frame-alist' to specify the frame parameters.\n\ |
a90712c2 RS |
4926 | \n\ |
4927 | A buffer is special if its is listed in `special-display-buffer-names'\n\ | |
4928 | or matches a regexp in `special-display-regexps'."); | |
4929 | Vspecial_display_function = Qnil; | |
4930 | ||
855d8627 RS |
4931 | DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names, |
4932 | "*List of buffer names that should appear in the selected window.\n\ | |
4933 | Displaying one of these buffers using `display-buffer' or `pop-to-buffer'\n\ | |
4934 | switches to it in the selected window, rather than making it appear\n\ | |
2e5ce1a0 | 4935 | in some other window.\n\ |
855d8627 RS |
4936 | \n\ |
4937 | An element of the list can be a cons cell instead of just a string.\n\ | |
4938 | Then the car must be a string, which specifies the buffer name.\n\ | |
4939 | This is for compatibility with `special-display-buffer-names';\n\ | |
4940 | the cdr of the cons cell is ignored.\n\ | |
4941 | \n\ | |
4942 | See also `same-window-regexps'."); | |
4943 | Vsame_window_buffer_names = Qnil; | |
4944 | ||
4945 | DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps, | |
4946 | "*List of regexps saying which buffers should appear in the selected window.\n\ | |
4947 | If a buffer name matches one of these regexps, then displaying it\n\ | |
4948 | using `display-buffer' or `pop-to-buffer' switches to it\n\ | |
4949 | in the selected window, rather than making it appear in some other window.\n\ | |
4950 | \n\ | |
4951 | An element of the list can be a cons cell instead of just a string.\n\ | |
4952 | Then the car must be a string, which specifies the buffer name.\n\ | |
4953 | This is for compatibility with `special-display-buffer-names';\n\ | |
4954 | the cdr of the cons cell is ignored.\n\ | |
4955 | \n\ | |
4956 | See also `same-window-buffer-names'."); | |
4957 | Vsame_window_regexps = Qnil; | |
4958 | ||
7ab12479 JB |
4959 | DEFVAR_BOOL ("pop-up-windows", &pop_up_windows, |
4960 | "*Non-nil means display-buffer should make new windows."); | |
4961 | pop_up_windows = 1; | |
4962 | ||
4963 | DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines, | |
4964 | "*Number of lines of continuity when scrolling by screenfuls."); | |
4965 | next_screen_context_lines = 2; | |
4966 | ||
4967 | DEFVAR_INT ("split-height-threshold", &split_height_threshold, | |
4968 | "*display-buffer would prefer to split the largest window if this large.\n\ | |
4969 | If there is only one window, it is split regardless of this value."); | |
4970 | split_height_threshold = 500; | |
4971 | ||
4972 | DEFVAR_INT ("window-min-height", &window_min_height, | |
4973 | "*Delete any window less than this tall (including its mode line)."); | |
4974 | window_min_height = 4; | |
4975 | ||
4976 | DEFVAR_INT ("window-min-width", &window_min_width, | |
4977 | "*Delete any window less than this wide."); | |
4978 | window_min_width = 10; | |
4979 | ||
5500c422 GM |
4980 | DEFVAR_LISP ("scroll-preserve-screen-position", |
4981 | &Vscroll_preserve_screen_position, | |
9317a85d | 4982 | "*Nonzero means scroll commands move point to keep its screen line unchanged."); |
5500c422 | 4983 | Vscroll_preserve_screen_position = Qnil; |
9317a85d | 4984 | |
543f5fb1 RS |
4985 | DEFVAR_LISP ("window-configuration-change-hook", |
4986 | &Vwindow_configuration_change_hook, | |
4987 | "Functions to call when window configuration changes.\n\ | |
e3e041eb | 4988 | The selected frame is the one whose configuration has changed."); |
543f5fb1 RS |
4989 | Vwindow_configuration_change_hook = Qnil; |
4990 | ||
7ab12479 JB |
4991 | defsubr (&Sselected_window); |
4992 | defsubr (&Sminibuffer_window); | |
4993 | defsubr (&Swindow_minibuffer_p); | |
4994 | defsubr (&Swindowp); | |
806b4d9b | 4995 | defsubr (&Swindow_live_p); |
7ab12479 JB |
4996 | defsubr (&Spos_visible_in_window_p); |
4997 | defsubr (&Swindow_buffer); | |
4998 | defsubr (&Swindow_height); | |
4999 | defsubr (&Swindow_width); | |
5000 | defsubr (&Swindow_hscroll); | |
5001 | defsubr (&Sset_window_hscroll); | |
190eb263 RS |
5002 | defsubr (&Swindow_redisplay_end_trigger); |
5003 | defsubr (&Sset_window_redisplay_end_trigger); | |
7ab12479 | 5004 | defsubr (&Swindow_edges); |
d5783c40 JB |
5005 | defsubr (&Scoordinates_in_window_p); |
5006 | defsubr (&Swindow_at); | |
7ab12479 JB |
5007 | defsubr (&Swindow_point); |
5008 | defsubr (&Swindow_start); | |
5009 | defsubr (&Swindow_end); | |
5010 | defsubr (&Sset_window_point); | |
5011 | defsubr (&Sset_window_start); | |
5012 | defsubr (&Swindow_dedicated_p); | |
d207b766 | 5013 | defsubr (&Sset_window_dedicated_p); |
7ab12479 JB |
5014 | defsubr (&Swindow_display_table); |
5015 | defsubr (&Sset_window_display_table); | |
5016 | defsubr (&Snext_window); | |
5017 | defsubr (&Sprevious_window); | |
5018 | defsubr (&Sother_window); | |
5019 | defsubr (&Sget_lru_window); | |
5020 | defsubr (&Sget_largest_window); | |
5021 | defsubr (&Sget_buffer_window); | |
5022 | defsubr (&Sdelete_other_windows); | |
5023 | defsubr (&Sdelete_windows_on); | |
5024 | defsubr (&Sreplace_buffer_in_windows); | |
5025 | defsubr (&Sdelete_window); | |
5026 | defsubr (&Sset_window_buffer); | |
5027 | defsubr (&Sselect_window); | |
4628f7a4 EN |
5028 | defsubr (&Sspecial_display_p); |
5029 | defsubr (&Ssame_window_p); | |
7ab12479 JB |
5030 | defsubr (&Sdisplay_buffer); |
5031 | defsubr (&Ssplit_window); | |
5032 | defsubr (&Senlarge_window); | |
5033 | defsubr (&Sshrink_window); | |
5034 | defsubr (&Sscroll_up); | |
5035 | defsubr (&Sscroll_down); | |
5036 | defsubr (&Sscroll_left); | |
5037 | defsubr (&Sscroll_right); | |
ccd0664b | 5038 | defsubr (&Sother_window_for_scrolling); |
7ab12479 JB |
5039 | defsubr (&Sscroll_other_window); |
5040 | defsubr (&Srecenter); | |
5041 | defsubr (&Smove_to_window_line); | |
5042 | defsubr (&Swindow_configuration_p); | |
3f8ab7bd | 5043 | defsubr (&Swindow_configuration_frame); |
7ab12479 JB |
5044 | defsubr (&Sset_window_configuration); |
5045 | defsubr (&Scurrent_window_configuration); | |
5046 | defsubr (&Ssave_window_excursion); | |
5500c422 GM |
5047 | defsubr (&Sset_window_margins); |
5048 | defsubr (&Swindow_margins); | |
5049 | defsubr (&Swindow_vscroll); | |
5050 | defsubr (&Sset_window_vscroll); | |
2f8274be | 5051 | defsubr (&Scompare_window_configurations); |
7ab12479 JB |
5052 | } |
5053 | ||
dfcf069d | 5054 | void |
7ab12479 JB |
5055 | keys_of_window () |
5056 | { | |
5057 | initial_define_key (control_x_map, '1', "delete-other-windows"); | |
5058 | initial_define_key (control_x_map, '2', "split-window"); | |
5059 | initial_define_key (control_x_map, '0', "delete-window"); | |
5060 | initial_define_key (control_x_map, 'o', "other-window"); | |
5061 | initial_define_key (control_x_map, '^', "enlarge-window"); | |
5062 | initial_define_key (control_x_map, '<', "scroll-left"); | |
5063 | initial_define_key (control_x_map, '>', "scroll-right"); | |
5064 | ||
5065 | initial_define_key (global_map, Ctl ('V'), "scroll-up"); | |
5066 | initial_define_key (meta_map, Ctl ('V'), "scroll-other-window"); | |
5067 | initial_define_key (meta_map, 'v', "scroll-down"); | |
5068 | ||
5069 | initial_define_key (global_map, Ctl('L'), "recenter"); | |
5070 | initial_define_key (meta_map, 'r', "move-to-window-line"); | |
5071 | } |