Commit | Line | Data |
---|---|---|
7ab12479 JB |
1 | /* Window creation, deletion and examination for GNU Emacs. |
2 | Does not include redisplay. | |
046fd69c | 3 | Copyright (C) 1985,86,87,93,94,95,96,1997 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" |
d2b35234 | 32 | #include "blockinput.h" |
7ab12479 | 33 | |
806b4d9b | 34 | Lisp_Object Qwindowp, Qwindow_live_p; |
7ab12479 | 35 | |
5e14b1fc | 36 | static struct window *decode_window P_ ((Lisp_Object)); |
7ab12479 JB |
37 | |
38 | /* This is the window in which the terminal's cursor should | |
39 | be left when nothing is being done with it. This must | |
40 | always be a leaf window, and its buffer is selected by | |
41 | the top level editing loop at the end of each command. | |
42 | ||
43 | This value is always the same as | |
44fa5b1e | 44 | FRAME_SELECTED_WINDOW (selected_frame). */ |
7ab12479 JB |
45 | |
46 | Lisp_Object selected_window; | |
47 | ||
44fa5b1e | 48 | /* The minibuffer window of the selected frame. |
7ab12479 JB |
49 | Note that you cannot test for minibufferness of an arbitrary window |
50 | by comparing against this; but you can test for minibufferness of | |
51 | the selected window. */ | |
52 | Lisp_Object minibuf_window; | |
53 | ||
54 | /* Non-nil means it is the window for C-M-v to scroll | |
55 | when the minibuffer is selected. */ | |
56 | Lisp_Object Vminibuf_scroll_window; | |
57 | ||
58 | /* Non-nil means this is the buffer whose window C-M-v should scroll. */ | |
59 | Lisp_Object Vother_window_scroll_buffer; | |
60 | ||
7ab12479 JB |
61 | /* Non-nil means it's function to call to display temp buffers. */ |
62 | Lisp_Object Vtemp_buffer_show_function; | |
63 | ||
64 | /* If a window gets smaller than either of these, it is removed. */ | |
65 | int window_min_height; | |
66 | int window_min_width; | |
67 | ||
68 | /* Nonzero implies Fdisplay_buffer should create windows. */ | |
69 | int pop_up_windows; | |
70 | ||
44fa5b1e JB |
71 | /* Nonzero implies make new frames for Fdisplay_buffer. */ |
72 | int pop_up_frames; | |
7ab12479 JB |
73 | |
74 | /* Non-nil means use this function instead of default */ | |
44fa5b1e | 75 | Lisp_Object Vpop_up_frame_function; |
7ab12479 JB |
76 | |
77 | /* Function to call to handle Fdisplay_buffer. */ | |
78 | Lisp_Object Vdisplay_buffer_function; | |
79 | ||
a90712c2 RS |
80 | /* List of buffer *names* for buffers that should have their own frames. */ |
81 | Lisp_Object Vspecial_display_buffer_names; | |
82 | ||
83 | /* List of regexps for buffer names that should have their own frames. */ | |
84 | Lisp_Object Vspecial_display_regexps; | |
85 | ||
86 | /* Function to pop up a special frame. */ | |
87 | Lisp_Object Vspecial_display_function; | |
88 | ||
855d8627 RS |
89 | /* List of buffer *names* for buffers to appear in selected window. */ |
90 | Lisp_Object Vsame_window_buffer_names; | |
91 | ||
92 | /* List of regexps for buffer names to appear in selected window. */ | |
93 | Lisp_Object Vsame_window_regexps; | |
94 | ||
a58ec57d RS |
95 | /* Hook run at end of temp_output_buffer_show. */ |
96 | Lisp_Object Qtemp_buffer_show_hook; | |
97 | ||
37962e60 | 98 | /* Fdisplay_buffer always splits the largest window |
7ab12479 JB |
99 | if that window is more than this high. */ |
100 | int split_height_threshold; | |
101 | ||
102 | /* Number of lines of continuity in scrolling by screenfuls. */ | |
103 | int next_screen_context_lines; | |
104 | ||
105 | /* Incremented for each window created. */ | |
106 | static int sequence_number; | |
107 | ||
5b03d3c0 RS |
108 | /* Nonzero after init_window_once has finished. */ |
109 | static int window_initialized; | |
110 | ||
543f5fb1 RS |
111 | /* Hook to run when window config changes. */ |
112 | Lisp_Object Qwindow_configuration_change_hook; | |
113 | Lisp_Object Vwindow_configuration_change_hook; | |
114 | ||
9317a85d RS |
115 | /* Nonzero means scroll commands try to put point |
116 | at the same screen height as previously. */ | |
117 | static int scroll_preserve_screen_position; | |
118 | ||
91a78190 | 119 | /* Nonzero means we can split a frame even if it is "unsplittable". */ |
eddd51c2 | 120 | static int inhibit_frame_unsplittable; |
7d601aaa | 121 | |
7ab12479 | 122 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
dba06815 | 123 | |
9317a85d RS |
124 | extern int scroll_margin; |
125 | ||
dba06815 | 126 | extern Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions; |
7ab12479 JB |
127 | \f |
128 | DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0, | |
413430c5 EN |
129 | "Returns t if OBJECT is a window.") |
130 | (object) | |
131 | Lisp_Object object; | |
7ab12479 | 132 | { |
413430c5 | 133 | return WINDOWP (object) ? Qt : Qnil; |
7ab12479 JB |
134 | } |
135 | ||
806b4d9b | 136 | DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0, |
413430c5 EN |
137 | "Returns t if OBJECT is a window which is currently visible.") |
138 | (object) | |
139 | Lisp_Object object; | |
605be8af | 140 | { |
413430c5 | 141 | return (WINDOWP (object) && ! NILP (XWINDOW (object)->buffer) ? Qt : Qnil); |
605be8af JB |
142 | } |
143 | ||
7ab12479 JB |
144 | Lisp_Object |
145 | make_window () | |
146 | { | |
cffec418 | 147 | Lisp_Object val; |
7ab12479 | 148 | register struct window *p; |
cffec418 KH |
149 | register struct Lisp_Vector *vec; |
150 | int i; | |
151 | ||
152 | vec = allocate_vectorlike ((EMACS_INT) VECSIZE (struct window)); | |
153 | for (i = 0; i < VECSIZE (struct window); i++) | |
154 | vec->contents[i] = Qnil; | |
155 | vec->size = VECSIZE (struct window); | |
156 | p = (struct window *)vec; | |
d834a2e9 KH |
157 | XSETFASTINT (p->sequence_number, ++sequence_number); |
158 | XSETFASTINT (p->left, 0); | |
159 | XSETFASTINT (p->top, 0); | |
160 | XSETFASTINT (p->height, 0); | |
161 | XSETFASTINT (p->width, 0); | |
162 | XSETFASTINT (p->hscroll, 0); | |
163 | XSETFASTINT (p->last_point_x, 0); | |
164 | XSETFASTINT (p->last_point_y, 0); | |
7ab12479 JB |
165 | p->start = Fmake_marker (); |
166 | p->pointm = Fmake_marker (); | |
d834a2e9 | 167 | XSETFASTINT (p->use_time, 0); |
44fa5b1e | 168 | p->frame = Qnil; |
7ab12479 JB |
169 | p->display_table = Qnil; |
170 | p->dedicated = Qnil; | |
cffec418 | 171 | XSETWINDOW (val, p); |
7ab12479 JB |
172 | return val; |
173 | } | |
174 | ||
175 | DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0, | |
176 | "Return the window that the cursor now appears in and commands apply to.") | |
177 | () | |
178 | { | |
179 | return selected_window; | |
180 | } | |
181 | ||
83762ba4 JB |
182 | DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0, |
183 | "Return the window used now for minibuffers.\n\ | |
184 | If the optional argument FRAME is specified, return the minibuffer window\n\ | |
185 | used by that frame.") | |
186 | (frame) | |
187 | Lisp_Object frame; | |
7ab12479 | 188 | { |
83762ba4 | 189 | if (NILP (frame)) |
74112613 | 190 | XSETFRAME (frame, selected_frame); |
83762ba4 JB |
191 | else |
192 | CHECK_LIVE_FRAME (frame, 0); | |
83762ba4 JB |
193 | |
194 | return FRAME_MINIBUF_WINDOW (XFRAME (frame)); | |
7ab12479 JB |
195 | } |
196 | ||
605be8af | 197 | DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, Swindow_minibuffer_p, 0, 1, 0, |
7ab12479 JB |
198 | "Returns non-nil if WINDOW is a minibuffer window.") |
199 | (window) | |
200 | Lisp_Object window; | |
201 | { | |
202 | struct window *w = decode_window (window); | |
203 | return (MINI_WINDOW_P (w) ? Qt : Qnil); | |
204 | } | |
205 | ||
206 | DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p, | |
207 | Spos_visible_in_window_p, 0, 2, 0, | |
44fa5b1e | 208 | "Return t if position POS is currently on the frame in WINDOW.\n\ |
7ab12479 JB |
209 | Returns nil if that position is scrolled vertically out of view.\n\ |
210 | POS defaults to point; WINDOW, to the selected window.") | |
211 | (pos, window) | |
212 | Lisp_Object pos, window; | |
213 | { | |
214 | register struct window *w; | |
215 | register int top; | |
216 | register int height; | |
217 | register int posint; | |
218 | register struct buffer *buf; | |
219 | struct position posval; | |
afdb2485 | 220 | int hscroll; |
7ab12479 | 221 | |
265a9e55 | 222 | if (NILP (pos)) |
5ce7b543 | 223 | posint = PT; |
7ab12479 JB |
224 | else |
225 | { | |
226 | CHECK_NUMBER_COERCE_MARKER (pos, 0); | |
227 | posint = XINT (pos); | |
228 | } | |
229 | ||
605be8af | 230 | w = decode_window (window); |
7ab12479 | 231 | top = marker_position (w->start); |
afdb2485 | 232 | hscroll = XINT (w->hscroll); |
7ab12479 JB |
233 | |
234 | if (posint < top) | |
235 | return Qnil; | |
236 | ||
237 | height = XFASTINT (w->height) - ! MINI_WINDOW_P (w); | |
238 | ||
239 | buf = XBUFFER (w->buffer); | |
3cd21523 RS |
240 | if (XFASTINT (w->last_modified) >= BUF_MODIFF (buf) |
241 | && XFASTINT (w->last_overlay_modified) >= BUF_OVERLAY_MODIFF (buf)) | |
7ab12479 | 242 | { |
44fa5b1e | 243 | /* If frame is up to date, |
7ab12479 JB |
244 | use the info recorded about how much text fit on it. */ |
245 | if (posint < BUF_Z (buf) - XFASTINT (w->window_end_pos) | |
246 | || (XFASTINT (w->window_end_vpos) < height)) | |
247 | return Qt; | |
248 | return Qnil; | |
249 | } | |
250 | else | |
251 | { | |
33eb4ede | 252 | if (posint > BUF_ZV (buf)) |
7ab12479 JB |
253 | return Qnil; |
254 | ||
61b5322b RS |
255 | /* w->start can be out of range. If it is, do something reasonable. */ |
256 | if (top < BUF_BEGV (buf) || top > BUF_ZV (buf)) | |
257 | return Qnil; | |
258 | ||
7ab12479 | 259 | /* If that info is not correct, calculate afresh */ |
5a255667 KH |
260 | /* BUG FIX for the 7th arg (TOHPOS). |
261 | ||
262 | '0' is harmless, however, ' - (1 << (BITS_PER_SHORT - 1))' is | |
263 | more appropriate here. In case of HSCROLL > 0, this can avoid | |
264 | needless calculation done until (HPOS == 0). | |
265 | ||
266 | We want to determine if the position POSINT is in HEIGHT or | |
267 | not. We don't have to do calculation until (HPOS == 0). We | |
268 | can stop it when VPOS goes beyond HEIGHT. */ | |
4efffd80 | 269 | posval = *compute_motion (top, 0, (hscroll ? 1 - hscroll : 0), 0, |
5a255667 | 270 | posint, height, - (1 << (BITS_PER_SHORT - 1)), |
535e0b8e | 271 | window_internal_width (w) - 1, |
e37f06d7 | 272 | hscroll, 0, w); |
7ab12479 JB |
273 | |
274 | return posval.vpos < height ? Qt : Qnil; | |
275 | } | |
276 | } | |
277 | \f | |
278 | static struct window * | |
279 | decode_window (window) | |
280 | register Lisp_Object window; | |
281 | { | |
265a9e55 | 282 | if (NILP (window)) |
7ab12479 JB |
283 | return XWINDOW (selected_window); |
284 | ||
605be8af | 285 | CHECK_LIVE_WINDOW (window, 0); |
7ab12479 JB |
286 | return XWINDOW (window); |
287 | } | |
288 | ||
289 | DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0, | |
290 | "Return the buffer that WINDOW is displaying.") | |
291 | (window) | |
292 | Lisp_Object window; | |
293 | { | |
294 | return decode_window (window)->buffer; | |
295 | } | |
296 | ||
297 | DEFUN ("window-height", Fwindow_height, Swindow_height, 0, 1, 0, | |
298 | "Return the number of lines in WINDOW (including its mode line).") | |
299 | (window) | |
300 | Lisp_Object window; | |
301 | { | |
302 | return decode_window (window)->height; | |
303 | } | |
304 | ||
305 | DEFUN ("window-width", Fwindow_width, Swindow_width, 0, 1, 0, | |
3b5908ef RS |
306 | "Return the number of display columns in WINDOW.\n\ |
307 | This is the width that is usable columns available for text in WINDOW.\n\ | |
308 | If you want to find out how many columns WINDOW takes up,\n\ | |
309 | use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))).") | |
7ab12479 JB |
310 | (window) |
311 | Lisp_Object window; | |
312 | { | |
ee61d94e | 313 | return make_number (window_internal_width (decode_window (window))); |
7ab12479 JB |
314 | } |
315 | ||
316 | DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0, | |
317 | "Return the number of columns by which WINDOW is scrolled from left margin.") | |
318 | (window) | |
319 | Lisp_Object window; | |
320 | { | |
321 | return decode_window (window)->hscroll; | |
322 | } | |
323 | ||
324 | DEFUN ("set-window-hscroll", Fset_window_hscroll, Sset_window_hscroll, 2, 2, 0, | |
325 | "Set number of columns WINDOW is scrolled from left margin to NCOL.\n\ | |
326 | NCOL should be zero or positive.") | |
327 | (window, ncol) | |
328 | register Lisp_Object window, ncol; | |
329 | { | |
330 | register struct window *w; | |
331 | ||
332 | CHECK_NUMBER (ncol, 1); | |
d834a2e9 | 333 | if (XINT (ncol) < 0) XSETFASTINT (ncol, 0); |
7ab12479 | 334 | w = decode_window (window); |
7f4161e0 | 335 | if (XINT (w->hscroll) != XINT (ncol)) |
1479ef51 | 336 | XBUFFER (w->buffer)->clip_changed = 1; /* Prevent redisplay shortcuts */ |
7ab12479 JB |
337 | w->hscroll = ncol; |
338 | return ncol; | |
339 | } | |
340 | ||
190eb263 RS |
341 | DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger, |
342 | Swindow_redisplay_end_trigger, 0, 1, 0, | |
343 | "Return WINDOW's redisplay end trigger value.\n\ | |
344 | See `set-window-redisplay-end-trigger' for more information.") | |
345 | (window) | |
346 | Lisp_Object window; | |
347 | { | |
348 | return decode_window (window)->redisplay_end_trigger; | |
349 | } | |
350 | ||
351 | DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger, | |
352 | Sset_window_redisplay_end_trigger, 2, 2, 0, | |
353 | "Set WINDOW's redisplay end trigger value to VALUE.\n\ | |
354 | VALUE should be a buffer position (typically a marker) or nil.\n\ | |
76854cf2 RS |
355 | If it is a buffer position, then if redisplay in WINDOW reaches a position\n\ |
356 | beyond VALUE, the functions in `redisplay-end-trigger-functions' are called\n\ | |
357 | with two arguments: WINDOW, and the end trigger value.\n\ | |
358 | Afterwards the end-trigger value is reset to nil.") | |
190eb263 RS |
359 | (window, value) |
360 | register Lisp_Object window, value; | |
361 | { | |
362 | register struct window *w; | |
363 | ||
364 | w = decode_window (window); | |
365 | w->redisplay_end_trigger = value; | |
366 | return value; | |
367 | } | |
368 | ||
7ab12479 JB |
369 | DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0, |
370 | "Return a list of the edge coordinates of WINDOW.\n\ | |
44fa5b1e | 371 | \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.\n\ |
7ab12479 JB |
372 | RIGHT is one more than the rightmost column used by WINDOW,\n\ |
373 | and BOTTOM is one more than the bottommost row used by WINDOW\n\ | |
374 | and its mode-line.") | |
375 | (window) | |
376 | Lisp_Object window; | |
377 | { | |
378 | register struct window *w = decode_window (window); | |
379 | ||
380 | return Fcons (w->left, Fcons (w->top, | |
111e5992 | 381 | Fcons (make_number (WINDOW_RIGHT_EDGE (w)), |
7ab12479 JB |
382 | Fcons (make_number (XFASTINT (w->top) |
383 | + XFASTINT (w->height)), | |
384 | Qnil)))); | |
385 | } | |
386 | ||
d5783c40 JB |
387 | /* Test if the character at column *x, row *y is within window *w. |
388 | If it is not, return 0; | |
389 | if it is in the window's text area, | |
390 | set *x and *y to its location relative to the upper left corner | |
391 | of the window, and | |
392 | return 1; | |
393 | if it is on the window's modeline, return 2; | |
394 | if it is on the border between the window and its right sibling, | |
395 | return 3. */ | |
396 | static int | |
397 | coordinates_in_window (w, x, y) | |
398 | register struct window *w; | |
399 | register int *x, *y; | |
400 | { | |
401 | register int left = XINT (w->left); | |
111e5992 RS |
402 | register int right_edge = WINDOW_RIGHT_EDGE (w); |
403 | register int left_margin = WINDOW_LEFT_MARGIN (w); | |
404 | register int right_margin = WINDOW_RIGHT_MARGIN (w); | |
d5783c40 JB |
405 | register int window_height = XINT (w->height); |
406 | register int top = XFASTINT (w->top); | |
111e5992 RS |
407 | |
408 | if ( *x < left || *x >= right_edge | |
d5783c40 JB |
409 | || *y < top || *y >= top + window_height) |
410 | return 0; | |
411 | ||
111e5992 RS |
412 | if (left_margin != left && *x < left_margin && *x >= left) |
413 | return 3; | |
414 | ||
415 | if (right_margin != right_edge && *x >= right_margin && *x < right_edge) | |
416 | return 3; | |
417 | ||
d5783c40 JB |
418 | /* Is the character is the mode line? */ |
419 | if (*y == top + window_height - 1 | |
05c2896a | 420 | && ! MINI_WINDOW_P (w)) |
d5783c40 | 421 | return 2; |
37962e60 | 422 | |
111e5992 | 423 | *x -= WINDOW_LEFT_MARGIN (w); |
d5783c40 JB |
424 | *y -= top; |
425 | return 1; | |
426 | } | |
427 | ||
428 | DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p, | |
429 | Scoordinates_in_window_p, 2, 2, 0, | |
430 | "Return non-nil if COORDINATES are in WINDOW.\n\ | |
1113d9db | 431 | COORDINATES is a cons of the form (X . Y), X and Y being distances\n\ |
44fa5b1e | 432 | measured in characters from the upper-left corner of the frame.\n\ |
1113d9db | 433 | (0 . 0) denotes the character in the upper left corner of the\n\ |
44fa5b1e | 434 | frame.\n\ |
d5783c40 JB |
435 | If COORDINATES are in the text portion of WINDOW,\n\ |
436 | the coordinates relative to the window are returned.\n\ | |
e5d77022 | 437 | If they are in the mode line of WINDOW, `mode-line' is returned.\n\ |
d5783c40 | 438 | If they are on the border between WINDOW and its right sibling,\n\ |
e5d77022 | 439 | `vertical-line' is returned.") |
d5783c40 JB |
440 | (coordinates, window) |
441 | register Lisp_Object coordinates, window; | |
442 | { | |
443 | int x, y; | |
444 | ||
605be8af | 445 | CHECK_LIVE_WINDOW (window, 0); |
d5783c40 JB |
446 | CHECK_CONS (coordinates, 1); |
447 | x = XINT (Fcar (coordinates)); | |
448 | y = XINT (Fcdr (coordinates)); | |
449 | ||
450 | switch (coordinates_in_window (XWINDOW (window), &x, &y)) | |
451 | { | |
452 | case 0: /* NOT in window at all. */ | |
453 | return Qnil; | |
454 | ||
455 | case 1: /* In text part of window. */ | |
34c0dab2 | 456 | return Fcons (make_number (x), make_number (y)); |
d5783c40 JB |
457 | |
458 | case 2: /* In mode line of window. */ | |
459 | return Qmode_line; | |
37962e60 | 460 | |
d5783c40 | 461 | case 3: /* On right border of window. */ |
e5d77022 | 462 | return Qvertical_line; |
d5783c40 JB |
463 | |
464 | default: | |
465 | abort (); | |
466 | } | |
467 | } | |
468 | ||
7ab12479 | 469 | /* Find the window containing column x, row y, and return it as a |
d5783c40 JB |
470 | Lisp_Object. If x, y is on the window's modeline, set *part |
471 | to 1; if it is on the separating line between the window and its | |
472 | right sibling, set it to 2; otherwise set it to 0. If there is no | |
473 | window under x, y return nil and leave *part unmodified. */ | |
7ab12479 | 474 | Lisp_Object |
44fa5b1e JB |
475 | window_from_coordinates (frame, x, y, part) |
476 | FRAME_PTR frame; | |
7ab12479 | 477 | int x, y; |
d5783c40 | 478 | int *part; |
7ab12479 JB |
479 | { |
480 | register Lisp_Object tem, first; | |
481 | ||
44fa5b1e | 482 | tem = first = FRAME_SELECTED_WINDOW (frame); |
7ab12479 | 483 | |
d5783c40 | 484 | do |
7ab12479 JB |
485 | { |
486 | int found = coordinates_in_window (XWINDOW (tem), &x, &y); | |
487 | ||
488 | if (found) | |
489 | { | |
d5783c40 | 490 | *part = found - 1; |
7ab12479 JB |
491 | return tem; |
492 | } | |
493 | ||
d5783c40 | 494 | tem = Fnext_window (tem, Qt, Qlambda); |
7ab12479 | 495 | } |
d5783c40 | 496 | while (! EQ (tem, first)); |
37962e60 | 497 | |
d5783c40 | 498 | return Qnil; |
7ab12479 JB |
499 | } |
500 | ||
ab17c3f2 | 501 | DEFUN ("window-at", Fwindow_at, Swindow_at, 2, 3, 0, |
b0c33a94 | 502 | "Return window containing coordinates X and Y on FRAME.\n\ |
44fa5b1e JB |
503 | If omitted, FRAME defaults to the currently selected frame.\n\ |
504 | The top left corner of the frame is considered to be row 0,\n\ | |
95605e15 | 505 | column 0.") |
b0c33a94 RS |
506 | (x, y, frame) |
507 | Lisp_Object x, y, frame; | |
7ab12479 JB |
508 | { |
509 | int part; | |
510 | ||
44fa5b1e | 511 | if (NILP (frame)) |
74112613 | 512 | XSETFRAME (frame, selected_frame); |
d5783c40 | 513 | else |
44fa5b1e | 514 | CHECK_LIVE_FRAME (frame, 2); |
b0c33a94 RS |
515 | CHECK_NUMBER (x, 0); |
516 | CHECK_NUMBER (y, 1); | |
7ab12479 | 517 | |
44fa5b1e | 518 | return window_from_coordinates (XFRAME (frame), |
b0c33a94 | 519 | XINT (x), XINT (y), |
7ab12479 JB |
520 | &part); |
521 | } | |
522 | ||
523 | DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0, | |
524 | "Return current value of point in WINDOW.\n\ | |
525 | For a nonselected window, this is the value point would have\n\ | |
526 | if that window were selected.\n\ | |
527 | \n\ | |
528 | Note that, when WINDOW is the selected window and its buffer\n\ | |
529 | is also currently selected, the value returned is the same as (point).\n\ | |
530 | It would be more strictly correct to return the `top-level' value\n\ | |
531 | of point, outside of any save-excursion forms.\n\ | |
532 | But that is hard to define.") | |
533 | (window) | |
534 | Lisp_Object window; | |
535 | { | |
536 | register struct window *w = decode_window (window); | |
537 | ||
538 | if (w == XWINDOW (selected_window) | |
539 | && current_buffer == XBUFFER (w->buffer)) | |
540 | return Fpoint (); | |
541 | return Fmarker_position (w->pointm); | |
542 | } | |
543 | ||
544 | DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0, | |
0fea6c40 RS |
545 | "Return position at which display currently starts in WINDOW.\n\ |
546 | This is updated by redisplay or by calling `set-window-start'.") | |
7ab12479 JB |
547 | (window) |
548 | Lisp_Object window; | |
549 | { | |
550 | return Fmarker_position (decode_window (window)->start); | |
551 | } | |
552 | ||
8646118f RS |
553 | /* This is text temporarily removed from the doc string below. |
554 | ||
7250968e RS |
555 | This function returns nil if the position is not currently known.\n\ |
556 | That happens when redisplay is preempted and doesn't finish.\n\ | |
557 | If in that case you want to compute where the end of the window would\n\ | |
558 | have been if redisplay had finished, do this:\n\ | |
559 | (save-excursion\n\ | |
560 | (goto-char (window-start window))\n\ | |
561 | (vertical-motion (1- (window-height window)) window)\n\ | |
8646118f RS |
562 | (point))") */ |
563 | ||
564 | DEFUN ("window-end", Fwindow_end, Swindow_end, 0, 1, 0, | |
565 | "Return position at which display currently ends in WINDOW.\n\ | |
566 | This is updated by redisplay, when it runs to completion.\n\ | |
567 | Simply changing the buffer text or setting `window-start'\n\ | |
568 | does not update this value.") | |
7ab12479 JB |
569 | (window) |
570 | Lisp_Object window; | |
571 | { | |
572 | Lisp_Object value; | |
573 | struct window *w = decode_window (window); | |
5a41ab94 RS |
574 | Lisp_Object buf; |
575 | ||
576 | buf = w->buffer; | |
577 | CHECK_BUFFER (buf, 0); | |
578 | ||
8646118f | 579 | #if 0 /* This change broke some things. We should make it later. */ |
7250968e RS |
580 | /* If we don't know the end position, return nil. |
581 | The user can compute it with vertical-motion if he wants to. | |
582 | It would be nicer to do it automatically, | |
583 | but that's so slow that it would probably bother people. */ | |
584 | if (NILP (w->window_end_valid)) | |
585 | return Qnil; | |
8646118f | 586 | #endif |
7250968e | 587 | |
74112613 KH |
588 | XSETINT (value, |
589 | BUF_Z (XBUFFER (buf)) - XFASTINT (w->window_end_pos)); | |
7ab12479 JB |
590 | |
591 | return value; | |
592 | } | |
593 | ||
594 | DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0, | |
595 | "Make point value in WINDOW be at position POS in WINDOW's buffer.") | |
596 | (window, pos) | |
597 | Lisp_Object window, pos; | |
598 | { | |
599 | register struct window *w = decode_window (window); | |
600 | ||
601 | CHECK_NUMBER_COERCE_MARKER (pos, 1); | |
602 | if (w == XWINDOW (selected_window)) | |
603 | Fgoto_char (pos); | |
604 | else | |
605 | set_marker_restricted (w->pointm, pos, w->buffer); | |
606 | ||
607 | return pos; | |
608 | } | |
609 | ||
610 | DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0, | |
611 | "Make display in WINDOW start at position POS in WINDOW's buffer.\n\ | |
612 | Optional third arg NOFORCE non-nil inhibits next redisplay\n\ | |
613 | from overriding motion of point in order to display at this exact start.") | |
614 | (window, pos, noforce) | |
615 | Lisp_Object window, pos, noforce; | |
616 | { | |
617 | register struct window *w = decode_window (window); | |
618 | ||
619 | CHECK_NUMBER_COERCE_MARKER (pos, 1); | |
620 | set_marker_restricted (w->start, pos, w->buffer); | |
621 | /* this is not right, but much easier than doing what is right. */ | |
622 | w->start_at_line_beg = Qnil; | |
265a9e55 | 623 | if (NILP (noforce)) |
7ab12479 JB |
624 | w->force_start = Qt; |
625 | w->update_mode_line = Qt; | |
d834a2e9 | 626 | XSETFASTINT (w->last_modified, 0); |
3cd21523 | 627 | XSETFASTINT (w->last_overlay_modified, 0); |
62c07cc7 JB |
628 | if (!EQ (window, selected_window)) |
629 | windows_or_buffers_changed++; | |
7ab12479 JB |
630 | return pos; |
631 | } | |
632 | ||
633 | DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p, | |
634 | 1, 1, 0, | |
635 | "Return WINDOW's dedicated object, usually t or nil.\n\ | |
1f18c48f | 636 | See also `set-window-dedicated-p'.") |
7ab12479 JB |
637 | (window) |
638 | Lisp_Object window; | |
639 | { | |
640 | return decode_window (window)->dedicated; | |
641 | } | |
642 | ||
d207b766 RS |
643 | DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p, |
644 | Sset_window_dedicated_p, 2, 2, 0, | |
645 | "Control whether WINDOW is dedicated to the buffer it displays.\n\ | |
646 | If it is dedicated, Emacs will not automatically change\n\ | |
647 | which buffer appears in it.\n\ | |
648 | The second argument is the new value for the dedication flag;\n\ | |
649 | non-nil means yes.") | |
7ab12479 JB |
650 | (window, arg) |
651 | Lisp_Object window, arg; | |
652 | { | |
653 | register struct window *w = decode_window (window); | |
654 | ||
265a9e55 | 655 | if (NILP (arg)) |
7ab12479 JB |
656 | w->dedicated = Qnil; |
657 | else | |
d207b766 | 658 | w->dedicated = Qt; |
7ab12479 JB |
659 | |
660 | return w->dedicated; | |
661 | } | |
662 | ||
663 | DEFUN ("window-display-table", Fwindow_display_table, Swindow_display_table, | |
664 | 0, 1, 0, | |
665 | "Return the display-table that WINDOW is using.") | |
666 | (window) | |
667 | Lisp_Object window; | |
668 | { | |
669 | return decode_window (window)->display_table; | |
670 | } | |
671 | ||
672 | /* Get the display table for use currently on window W. | |
673 | This is either W's display table or W's buffer's display table. | |
674 | Ignore the specified tables if they are not valid; | |
675 | if no valid table is specified, return 0. */ | |
676 | ||
319315f1 | 677 | struct Lisp_Char_Table * |
7ab12479 JB |
678 | window_display_table (w) |
679 | struct window *w; | |
680 | { | |
681 | Lisp_Object tem; | |
682 | tem = w->display_table; | |
319315f1 RS |
683 | if (DISP_TABLE_P (tem)) |
684 | return XCHAR_TABLE (tem); | |
7ab12479 | 685 | tem = XBUFFER (w->buffer)->display_table; |
319315f1 RS |
686 | if (DISP_TABLE_P (tem)) |
687 | return XCHAR_TABLE (tem); | |
7ab12479 | 688 | tem = Vstandard_display_table; |
319315f1 RS |
689 | if (DISP_TABLE_P (tem)) |
690 | return XCHAR_TABLE (tem); | |
7ab12479 JB |
691 | return 0; |
692 | } | |
693 | ||
3a2712f9 | 694 | DEFUN ("set-window-display-table", Fset_window_display_table, Sset_window_display_table, 2, 2, 0, |
7ab12479 JB |
695 | "Set WINDOW's display-table to TABLE.") |
696 | (window, table) | |
697 | register Lisp_Object window, table; | |
698 | { | |
699 | register struct window *w; | |
700 | register Lisp_Object z; /* Return value. */ | |
701 | ||
702 | w = decode_window (window); | |
703 | w->display_table = table; | |
704 | return table; | |
705 | } | |
706 | \f | |
707 | /* Record info on buffer window w is displaying | |
708 | when it is about to cease to display that buffer. */ | |
709 | static | |
710 | unshow_buffer (w) | |
711 | register struct window *w; | |
712 | { | |
12cae7c0 | 713 | Lisp_Object buf; |
b73ea88e | 714 | struct buffer *b; |
7ab12479 | 715 | |
12cae7c0 | 716 | buf = w->buffer; |
b73ea88e RS |
717 | b = XBUFFER (buf); |
718 | if (b != XMARKER (w->pointm)->buffer) | |
7ab12479 JB |
719 | abort (); |
720 | ||
b73ea88e RS |
721 | if (w == XWINDOW (b->last_selected_window)) |
722 | b->last_selected_window = Qnil; | |
86e48436 | 723 | |
573f41ab | 724 | #if 0 |
7ab12479 JB |
725 | if (w == XWINDOW (selected_window) |
726 | || ! EQ (buf, XWINDOW (selected_window)->buffer)) | |
727 | /* Do this except when the selected window's buffer | |
728 | is being removed from some other window. */ | |
573f41ab RS |
729 | #endif |
730 | /* last_window_start records the start position that this buffer | |
731 | had in the last window to be disconnected from it. | |
732 | Now that this statement is unconditional, | |
733 | it is possible for the buffer to be displayed in the | |
734 | selected window, while last_window_start reflects another | |
735 | window which was recently showing the same buffer. | |
736 | Some people might say that might be a good thing. Let's see. */ | |
b73ea88e | 737 | b->last_window_start = marker_position (w->start); |
7ab12479 JB |
738 | |
739 | /* Point in the selected window's buffer | |
740 | is actually stored in that buffer, and the window's pointm isn't used. | |
741 | So don't clobber point in that buffer. */ | |
742 | if (! EQ (buf, XWINDOW (selected_window)->buffer)) | |
b73ea88e RS |
743 | temp_set_point_both (b, |
744 | clip_to_bounds (BUF_BEGV (b), | |
745 | XMARKER (w->pointm)->charpos, | |
746 | BUF_ZV (b)), | |
747 | clip_to_bounds (BUF_BEGV_BYTE (b), | |
748 | marker_byte_position (w->pointm), | |
749 | BUF_ZV_BYTE (b))); | |
7ab12479 JB |
750 | } |
751 | ||
752 | /* Put replacement into the window structure in place of old. */ | |
753 | static | |
754 | replace_window (old, replacement) | |
755 | Lisp_Object old, replacement; | |
756 | { | |
757 | register Lisp_Object tem; | |
758 | register struct window *o = XWINDOW (old), *p = XWINDOW (replacement); | |
759 | ||
44fa5b1e JB |
760 | /* If OLD is its frame's root_window, then replacement is the new |
761 | root_window for that frame. */ | |
7ab12479 | 762 | |
7f4161e0 | 763 | if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame)))) |
44fa5b1e | 764 | FRAME_ROOT_WINDOW (XFRAME (o->frame)) = replacement; |
7ab12479 JB |
765 | |
766 | p->left = o->left; | |
767 | p->top = o->top; | |
768 | p->width = o->width; | |
769 | p->height = o->height; | |
770 | ||
771 | p->next = tem = o->next; | |
265a9e55 | 772 | if (!NILP (tem)) |
7ab12479 JB |
773 | XWINDOW (tem)->prev = replacement; |
774 | ||
775 | p->prev = tem = o->prev; | |
265a9e55 | 776 | if (!NILP (tem)) |
7ab12479 JB |
777 | XWINDOW (tem)->next = replacement; |
778 | ||
779 | p->parent = tem = o->parent; | |
265a9e55 | 780 | if (!NILP (tem)) |
7ab12479 JB |
781 | { |
782 | if (EQ (XWINDOW (tem)->vchild, old)) | |
783 | XWINDOW (tem)->vchild = replacement; | |
784 | if (EQ (XWINDOW (tem)->hchild, old)) | |
785 | XWINDOW (tem)->hchild = replacement; | |
786 | } | |
787 | ||
788 | /*** Here, if replacement is a vertical combination | |
789 | and so is its new parent, we should make replacement's | |
790 | children be children of that parent instead. ***/ | |
791 | } | |
792 | ||
793 | DEFUN ("delete-window", Fdelete_window, Sdelete_window, 0, 1, "", | |
794 | "Remove WINDOW from the display. Default is selected window.") | |
795 | (window) | |
796 | register Lisp_Object window; | |
543f5fb1 RS |
797 | { |
798 | delete_window (window); | |
799 | ||
800 | if (! NILP (Vwindow_configuration_change_hook) | |
801 | && ! NILP (Vrun_hooks)) | |
802 | call1 (Vrun_hooks, Qwindow_configuration_change_hook); | |
803 | ||
804 | return Qnil; | |
805 | } | |
806 | ||
5e14b1fc | 807 | void |
543f5fb1 RS |
808 | delete_window (window) |
809 | register Lisp_Object window; | |
7ab12479 JB |
810 | { |
811 | register Lisp_Object tem, parent, sib; | |
812 | register struct window *p; | |
813 | register struct window *par; | |
814 | ||
605be8af JB |
815 | /* Because this function is called by other C code on non-leaf |
816 | windows, the CHECK_LIVE_WINDOW macro would choke inappropriately, | |
817 | so we can't decode_window here. */ | |
265a9e55 | 818 | if (NILP (window)) |
7ab12479 JB |
819 | window = selected_window; |
820 | else | |
821 | CHECK_WINDOW (window, 0); | |
7ab12479 | 822 | p = XWINDOW (window); |
605be8af JB |
823 | |
824 | /* It's okay to delete an already-deleted window. */ | |
825 | if (NILP (p->buffer) | |
826 | && NILP (p->hchild) | |
827 | && NILP (p->vchild)) | |
296b535c | 828 | return; |
605be8af | 829 | |
7ab12479 | 830 | parent = p->parent; |
265a9e55 | 831 | if (NILP (parent)) |
7ab12479 JB |
832 | error ("Attempt to delete minibuffer or sole ordinary window"); |
833 | par = XWINDOW (parent); | |
834 | ||
835 | windows_or_buffers_changed++; | |
29aeee73 | 836 | FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (p))) = 1; |
7ab12479 | 837 | |
605be8af JB |
838 | /* Are we trying to delete any frame's selected window? */ |
839 | { | |
0def0403 | 840 | Lisp_Object frame, pwindow; |
605be8af | 841 | |
0def0403 RS |
842 | /* See if the frame's selected window is either WINDOW |
843 | or any subwindow of it, by finding all that window's parents | |
844 | and comparing each one with WINDOW. */ | |
845 | frame = WINDOW_FRAME (XWINDOW (window)); | |
846 | pwindow = FRAME_SELECTED_WINDOW (XFRAME (frame)); | |
847 | ||
848 | while (!NILP (pwindow)) | |
849 | { | |
850 | if (EQ (window, pwindow)) | |
851 | break; | |
852 | pwindow = XWINDOW (pwindow)->parent; | |
853 | } | |
854 | ||
855 | if (EQ (window, pwindow)) | |
605be8af | 856 | { |
89bca612 RS |
857 | Lisp_Object alternative; |
858 | alternative = Fnext_window (window, Qlambda, Qnil); | |
605be8af JB |
859 | |
860 | /* If we're about to delete the selected window on the | |
861 | selected frame, then we should use Fselect_window to select | |
862 | the new window. On the other hand, if we're about to | |
863 | delete the selected window on any other frame, we shouldn't do | |
864 | anything but set the frame's selected_window slot. */ | |
865 | if (EQ (window, selected_window)) | |
866 | Fselect_window (alternative); | |
867 | else | |
0def0403 | 868 | FRAME_SELECTED_WINDOW (XFRAME (frame)) = alternative; |
605be8af JB |
869 | } |
870 | } | |
7ab12479 JB |
871 | |
872 | tem = p->buffer; | |
873 | /* tem is null for dummy parent windows | |
874 | (which have inferiors but not any contents themselves) */ | |
265a9e55 | 875 | if (!NILP (tem)) |
7ab12479 JB |
876 | { |
877 | unshow_buffer (p); | |
878 | unchain_marker (p->pointm); | |
879 | unchain_marker (p->start); | |
7ab12479 JB |
880 | } |
881 | ||
882 | tem = p->next; | |
265a9e55 | 883 | if (!NILP (tem)) |
7ab12479 JB |
884 | XWINDOW (tem)->prev = p->prev; |
885 | ||
886 | tem = p->prev; | |
265a9e55 | 887 | if (!NILP (tem)) |
7ab12479 JB |
888 | XWINDOW (tem)->next = p->next; |
889 | ||
890 | if (EQ (window, par->hchild)) | |
891 | par->hchild = p->next; | |
892 | if (EQ (window, par->vchild)) | |
893 | par->vchild = p->next; | |
894 | ||
895 | /* Find one of our siblings to give our space to. */ | |
896 | sib = p->prev; | |
265a9e55 | 897 | if (NILP (sib)) |
7ab12479 JB |
898 | { |
899 | /* If p gives its space to its next sibling, that sibling needs | |
900 | to have its top/left side pulled back to where p's is. | |
901 | set_window_{height,width} will re-position the sibling's | |
902 | children. */ | |
903 | sib = p->next; | |
7f4161e0 JB |
904 | XWINDOW (sib)->top = p->top; |
905 | XWINDOW (sib)->left = p->left; | |
7ab12479 JB |
906 | } |
907 | ||
908 | /* Stretch that sibling. */ | |
265a9e55 | 909 | if (!NILP (par->vchild)) |
7ab12479 JB |
910 | set_window_height (sib, |
911 | XFASTINT (XWINDOW (sib)->height) + XFASTINT (p->height), | |
912 | 1); | |
265a9e55 | 913 | if (!NILP (par->hchild)) |
7ab12479 JB |
914 | set_window_width (sib, |
915 | XFASTINT (XWINDOW (sib)->width) + XFASTINT (p->width), | |
916 | 1); | |
917 | ||
918 | /* If parent now has only one child, | |
919 | put the child into the parent's place. */ | |
7ab12479 | 920 | tem = par->hchild; |
265a9e55 | 921 | if (NILP (tem)) |
7ab12479 | 922 | tem = par->vchild; |
265a9e55 | 923 | if (NILP (XWINDOW (tem)->next)) |
7ab12479 | 924 | replace_window (parent, tem); |
605be8af JB |
925 | |
926 | /* Since we may be deleting combination windows, we must make sure that | |
927 | not only p but all its children have been marked as deleted. */ | |
928 | if (! NILP (p->hchild)) | |
929 | delete_all_subwindows (XWINDOW (p->hchild)); | |
930 | else if (! NILP (p->vchild)) | |
931 | delete_all_subwindows (XWINDOW (p->vchild)); | |
932 | ||
933 | /* Mark this window as deleted. */ | |
934 | p->buffer = p->hchild = p->vchild = Qnil; | |
7ab12479 JB |
935 | } |
936 | \f | |
7ab12479 | 937 | |
44fa5b1e | 938 | extern Lisp_Object next_frame (), prev_frame (); |
7ab12479 | 939 | |
26f6279d JB |
940 | /* This comment supplies the doc string for `next-window', |
941 | for make-docfile to see. We cannot put this in the real DEFUN | |
942 | due to limits in the Unix cpp. | |
943 | ||
944 | DEFUN ("next-window", Ffoo, Sfoo, 0, 3, 0, | |
7ab12479 | 945 | "Return next window after WINDOW in canonical ordering of windows.\n\ |
d5783c40 JB |
946 | If omitted, WINDOW defaults to the selected window.\n\ |
947 | \n\ | |
948 | Optional second arg MINIBUF t means count the minibuffer window even\n\ | |
949 | if not active. MINIBUF nil or omitted means count the minibuffer iff\n\ | |
950 | it is active. MINIBUF neither t nor nil means not to count the\n\ | |
951 | minibuffer even if it is active.\n\ | |
952 | \n\ | |
44fa5b1e JB |
953 | Several frames may share a single minibuffer; if the minibuffer\n\ |
954 | counts, all windows on all frames that share that minibuffer count\n\ | |
ed160f1f | 955 | too. Therefore, `next-window' can be used to iterate through the\n\ |
44fa5b1e JB |
956 | set of windows even when the minibuffer is on another frame. If the\n\ |
957 | minibuffer does not count, only windows from WINDOW's frame count.\n\ | |
d5783c40 | 958 | \n\ |
44fa5b1e JB |
959 | Optional third arg ALL-FRAMES t means include windows on all frames.\n\ |
960 | ALL-FRAMES nil or omitted means cycle within the frames as specified\n\ | |
89bca612 | 961 | above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\ |
f812f9c6 | 962 | ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\ |
1f4c5d09 | 963 | If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\ |
89bca612 | 964 | Anything else means restrict to WINDOW's frame.\n\ |
dbc4e1c1 JB |
965 | \n\ |
966 | If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\ | |
967 | `next-window' to iterate through the entire cycle of acceptable\n\ | |
968 | windows, eventually ending up back at the window you started with.\n\ | |
969 | `previous-window' traverses the same cycle, in the reverse order.") | |
26f6279d JB |
970 | (window, minibuf, all_frames) */ |
971 | ||
972 | DEFUN ("next-window", Fnext_window, Snext_window, 0, 3, 0, | |
973 | 0) | |
44fa5b1e JB |
974 | (window, minibuf, all_frames) |
975 | register Lisp_Object window, minibuf, all_frames; | |
7ab12479 JB |
976 | { |
977 | register Lisp_Object tem; | |
d5783c40 | 978 | Lisp_Object start_window; |
7ab12479 | 979 | |
265a9e55 | 980 | if (NILP (window)) |
7ab12479 JB |
981 | window = selected_window; |
982 | else | |
605be8af | 983 | CHECK_LIVE_WINDOW (window, 0); |
7ab12479 | 984 | |
d5783c40 JB |
985 | start_window = window; |
986 | ||
987 | /* minibuf == nil may or may not include minibuffers. | |
988 | Decide if it does. */ | |
265a9e55 | 989 | if (NILP (minibuf)) |
fbdc1545 RS |
990 | minibuf = (minibuf_level ? minibuf_window : Qlambda); |
991 | else if (! EQ (minibuf, Qt)) | |
992 | minibuf = Qlambda; | |
993 | /* Now minibuf can be t => count all minibuffer windows, | |
994 | lambda => count none of them, | |
995 | or a specific minibuffer window (the active one) to count. */ | |
d5783c40 | 996 | |
1bb80f72 | 997 | /* all_frames == nil doesn't specify which frames to include. */ |
44fa5b1e | 998 | if (NILP (all_frames)) |
fbdc1545 | 999 | all_frames = (! EQ (minibuf, Qlambda) |
1bb80f72 RS |
1000 | ? (FRAME_MINIBUF_WINDOW |
1001 | (XFRAME | |
1002 | (WINDOW_FRAME | |
1003 | (XWINDOW (window))))) | |
1004 | : Qnil); | |
89bca612 RS |
1005 | else if (EQ (all_frames, Qvisible)) |
1006 | ; | |
f812f9c6 RS |
1007 | else if (XFASTINT (all_frames) == 0) |
1008 | ; | |
1f4c5d09 RS |
1009 | else if (FRAMEP (all_frames) && ! EQ (all_frames, Fwindow_frame (window))) |
1010 | /* If all_frames is a frame and window arg isn't on that frame, just | |
1011 | return the first window on the frame. */ | |
1012 | return Fframe_first_window (all_frames); | |
44fa5b1e JB |
1013 | else if (! EQ (all_frames, Qt)) |
1014 | all_frames = Qnil; | |
644b477c RS |
1015 | /* Now all_frames is t meaning search all frames, |
1016 | nil meaning search just current frame, | |
f812f9c6 RS |
1017 | visible meaning search just visible frames, |
1018 | 0 meaning search visible and iconified frames, | |
644b477c | 1019 | or a window, meaning search the frame that window belongs to. */ |
7ab12479 JB |
1020 | |
1021 | /* Do this loop at least once, to get the next window, and perhaps | |
1022 | again, if we hit the minibuffer and that is not acceptable. */ | |
1023 | do | |
1024 | { | |
1025 | /* Find a window that actually has a next one. This loop | |
1026 | climbs up the tree. */ | |
265a9e55 JB |
1027 | while (tem = XWINDOW (window)->next, NILP (tem)) |
1028 | if (tem = XWINDOW (window)->parent, !NILP (tem)) | |
7ab12479 | 1029 | window = tem; |
d5783c40 | 1030 | else |
7ab12479 | 1031 | { |
44fa5b1e JB |
1032 | /* We've reached the end of this frame. |
1033 | Which other frames are acceptable? */ | |
1034 | tem = WINDOW_FRAME (XWINDOW (window)); | |
44fa5b1e | 1035 | if (! NILP (all_frames)) |
1bb80f72 RS |
1036 | { |
1037 | Lisp_Object tem1; | |
1038 | ||
1039 | tem1 = tem; | |
1040 | tem = next_frame (tem, all_frames); | |
1041 | /* In the case where the minibuffer is active, | |
1042 | and we include its frame as well as the selected one, | |
1043 | next_frame may get stuck in that frame. | |
1044 | If that happens, go back to the selected frame | |
1045 | so we can complete the cycle. */ | |
1046 | if (EQ (tem, tem1)) | |
74112613 | 1047 | XSETFRAME (tem, selected_frame); |
1bb80f72 | 1048 | } |
44fa5b1e | 1049 | tem = FRAME_ROOT_WINDOW (XFRAME (tem)); |
d5783c40 | 1050 | |
7ab12479 JB |
1051 | break; |
1052 | } | |
1053 | ||
1054 | window = tem; | |
d5783c40 | 1055 | |
7ab12479 JB |
1056 | /* If we're in a combination window, find its first child and |
1057 | recurse on that. Otherwise, we've found the window we want. */ | |
1058 | while (1) | |
1059 | { | |
265a9e55 | 1060 | if (!NILP (XWINDOW (window)->hchild)) |
7ab12479 | 1061 | window = XWINDOW (window)->hchild; |
265a9e55 | 1062 | else if (!NILP (XWINDOW (window)->vchild)) |
7ab12479 JB |
1063 | window = XWINDOW (window)->vchild; |
1064 | else break; | |
1065 | } | |
1066 | } | |
5c4d25a6 | 1067 | /* Which windows are acceptable? |
d5783c40 | 1068 | Exit the loop and accept this window if |
fbdc1545 RS |
1069 | this isn't a minibuffer window, |
1070 | or we're accepting all minibuffer windows, | |
1071 | or this is the active minibuffer and we are accepting that one, or | |
d5783c40 | 1072 | we've come all the way around and we're back at the original window. */ |
7ab12479 | 1073 | while (MINI_WINDOW_P (XWINDOW (window)) |
d5783c40 | 1074 | && ! EQ (minibuf, Qt) |
fbdc1545 | 1075 | && ! EQ (minibuf, window) |
7f4161e0 | 1076 | && ! EQ (window, start_window)); |
7ab12479 JB |
1077 | |
1078 | return window; | |
1079 | } | |
1080 | ||
26f6279d JB |
1081 | /* This comment supplies the doc string for `previous-window', |
1082 | for make-docfile to see. We cannot put this in the real DEFUN | |
1083 | due to limits in the Unix cpp. | |
1084 | ||
1085 | DEFUN ("previous-window", Ffoo, Sfoo, 0, 3, 0, | |
5c4d25a6 | 1086 | "Return the window preceding WINDOW in canonical ordering of windows.\n\ |
d5783c40 JB |
1087 | If omitted, WINDOW defaults to the selected window.\n\ |
1088 | \n\ | |
1089 | Optional second arg MINIBUF t means count the minibuffer window even\n\ | |
1090 | if not active. MINIBUF nil or omitted means count the minibuffer iff\n\ | |
1091 | it is active. MINIBUF neither t nor nil means not to count the\n\ | |
1092 | minibuffer even if it is active.\n\ | |
1093 | \n\ | |
44fa5b1e JB |
1094 | Several frames may share a single minibuffer; if the minibuffer\n\ |
1095 | counts, all windows on all frames that share that minibuffer count\n\ | |
ed160f1f | 1096 | too. Therefore, `previous-window' can be used to iterate through\n\ |
44fa5b1e | 1097 | the set of windows even when the minibuffer is on another frame. If\n\ |
ed160f1f | 1098 | the minibuffer does not count, only windows from WINDOW's frame count\n\ |
d5783c40 | 1099 | \n\ |
44fa5b1e JB |
1100 | Optional third arg ALL-FRAMES t means include windows on all frames.\n\ |
1101 | ALL-FRAMES nil or omitted means cycle within the frames as specified\n\ | |
89bca612 | 1102 | above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\ |
f812f9c6 | 1103 | ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\ |
1f4c5d09 | 1104 | If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\ |
89bca612 | 1105 | Anything else means restrict to WINDOW's frame.\n\ |
dbc4e1c1 JB |
1106 | \n\ |
1107 | If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\ | |
1108 | `previous-window' to iterate through the entire cycle of acceptable\n\ | |
1109 | windows, eventually ending up back at the window you started with.\n\ | |
1110 | `next-window' traverses the same cycle, in the reverse order.") | |
26f6279d JB |
1111 | (window, minibuf, all_frames) */ |
1112 | ||
1113 | ||
1114 | DEFUN ("previous-window", Fprevious_window, Sprevious_window, 0, 3, 0, | |
1115 | 0) | |
44fa5b1e JB |
1116 | (window, minibuf, all_frames) |
1117 | register Lisp_Object window, minibuf, all_frames; | |
7ab12479 JB |
1118 | { |
1119 | register Lisp_Object tem; | |
d5783c40 | 1120 | Lisp_Object start_window; |
7ab12479 | 1121 | |
265a9e55 | 1122 | if (NILP (window)) |
7ab12479 JB |
1123 | window = selected_window; |
1124 | else | |
605be8af | 1125 | CHECK_LIVE_WINDOW (window, 0); |
7ab12479 | 1126 | |
d5783c40 JB |
1127 | start_window = window; |
1128 | ||
1129 | /* minibuf == nil may or may not include minibuffers. | |
1130 | Decide if it does. */ | |
265a9e55 | 1131 | if (NILP (minibuf)) |
fbdc1545 RS |
1132 | minibuf = (minibuf_level ? minibuf_window : Qlambda); |
1133 | else if (! EQ (minibuf, Qt)) | |
1134 | minibuf = Qlambda; | |
1135 | /* Now minibuf can be t => count all minibuffer windows, | |
1136 | lambda => count none of them, | |
1137 | or a specific minibuffer window (the active one) to count. */ | |
d5783c40 | 1138 | |
44fa5b1e JB |
1139 | /* all_frames == nil doesn't specify which frames to include. |
1140 | Decide which frames it includes. */ | |
1141 | if (NILP (all_frames)) | |
fbdc1545 | 1142 | all_frames = (! EQ (minibuf, Qlambda) |
44fa5b1e JB |
1143 | ? (FRAME_MINIBUF_WINDOW |
1144 | (XFRAME | |
1145 | (WINDOW_FRAME | |
d5783c40 JB |
1146 | (XWINDOW (window))))) |
1147 | : Qnil); | |
89bca612 RS |
1148 | else if (EQ (all_frames, Qvisible)) |
1149 | ; | |
f812f9c6 RS |
1150 | else if (XFASTINT (all_frames) == 0) |
1151 | ; | |
1f4c5d09 RS |
1152 | else if (FRAMEP (all_frames) && ! EQ (all_frames, Fwindow_frame (window))) |
1153 | /* If all_frames is a frame and window arg isn't on that frame, just | |
1154 | return the first window on the frame. */ | |
1155 | return Fframe_first_window (all_frames); | |
44fa5b1e JB |
1156 | else if (! EQ (all_frames, Qt)) |
1157 | all_frames = Qnil; | |
644b477c RS |
1158 | /* Now all_frames is t meaning search all frames, |
1159 | nil meaning search just current frame, | |
f812f9c6 RS |
1160 | visible meaning search just visible frames, |
1161 | 0 meaning search visible and iconified frames, | |
644b477c | 1162 | or a window, meaning search the frame that window belongs to. */ |
7ab12479 JB |
1163 | |
1164 | /* Do this loop at least once, to get the previous window, and perhaps | |
1165 | again, if we hit the minibuffer and that is not acceptable. */ | |
1166 | do | |
1167 | { | |
1168 | /* Find a window that actually has a previous one. This loop | |
1169 | climbs up the tree. */ | |
265a9e55 JB |
1170 | while (tem = XWINDOW (window)->prev, NILP (tem)) |
1171 | if (tem = XWINDOW (window)->parent, !NILP (tem)) | |
7ab12479 | 1172 | window = tem; |
d5783c40 | 1173 | else |
7ab12479 | 1174 | { |
44fa5b1e JB |
1175 | /* We have found the top window on the frame. |
1176 | Which frames are acceptable? */ | |
1177 | tem = WINDOW_FRAME (XWINDOW (window)); | |
44fa5b1e | 1178 | if (! NILP (all_frames)) |
dbc4e1c1 JB |
1179 | /* It's actually important that we use prev_frame here, |
1180 | rather than next_frame. All the windows acceptable | |
1181 | according to the given parameters should form a ring; | |
1182 | Fnext_window and Fprevious_window should go back and | |
1183 | forth around the ring. If we use next_frame here, | |
1184 | then Fnext_window and Fprevious_window take different | |
1185 | paths through the set of acceptable windows. | |
1186 | window_loop assumes that these `ring' requirement are | |
1187 | met. */ | |
1bb80f72 RS |
1188 | { |
1189 | Lisp_Object tem1; | |
1190 | ||
1191 | tem1 = tem; | |
1192 | tem = prev_frame (tem, all_frames); | |
1193 | /* In the case where the minibuffer is active, | |
1194 | and we include its frame as well as the selected one, | |
1195 | next_frame may get stuck in that frame. | |
1196 | If that happens, go back to the selected frame | |
1197 | so we can complete the cycle. */ | |
1198 | if (EQ (tem, tem1)) | |
74112613 | 1199 | XSETFRAME (tem, selected_frame); |
1bb80f72 | 1200 | } |
644b477c RS |
1201 | /* If this frame has a minibuffer, find that window first, |
1202 | because it is conceptually the last window in that frame. */ | |
5e12e32f JB |
1203 | if (FRAME_HAS_MINIBUF_P (XFRAME (tem))) |
1204 | tem = FRAME_MINIBUF_WINDOW (XFRAME (tem)); | |
1205 | else | |
644b477c | 1206 | tem = FRAME_ROOT_WINDOW (XFRAME (tem)); |
d5783c40 | 1207 | |
7ab12479 JB |
1208 | break; |
1209 | } | |
1210 | ||
1211 | window = tem; | |
1212 | /* If we're in a combination window, find its last child and | |
1213 | recurse on that. Otherwise, we've found the window we want. */ | |
1214 | while (1) | |
1215 | { | |
265a9e55 | 1216 | if (!NILP (XWINDOW (window)->hchild)) |
7ab12479 | 1217 | window = XWINDOW (window)->hchild; |
265a9e55 | 1218 | else if (!NILP (XWINDOW (window)->vchild)) |
7ab12479 JB |
1219 | window = XWINDOW (window)->vchild; |
1220 | else break; | |
265a9e55 | 1221 | while (tem = XWINDOW (window)->next, !NILP (tem)) |
7ab12479 JB |
1222 | window = tem; |
1223 | } | |
1224 | } | |
5c4d25a6 | 1225 | /* Which windows are acceptable? |
d5783c40 | 1226 | Exit the loop and accept this window if |
fbdc1545 RS |
1227 | this isn't a minibuffer window, |
1228 | or we're accepting all minibuffer windows, | |
1229 | or this is the active minibuffer and we are accepting that one, or | |
d5783c40 | 1230 | we've come all the way around and we're back at the original window. */ |
7ab12479 | 1231 | while (MINI_WINDOW_P (XWINDOW (window)) |
fbdc1545 RS |
1232 | && ! EQ (minibuf, Qt) |
1233 | && ! EQ (minibuf, window) | |
1234 | && ! EQ (window, start_window)); | |
7ab12479 JB |
1235 | |
1236 | return window; | |
1237 | } | |
1238 | ||
62c07cc7 | 1239 | DEFUN ("other-window", Fother_window, Sother_window, 1, 2, "p", |
44fa5b1e JB |
1240 | "Select the ARG'th different window on this frame.\n\ |
1241 | All windows on current frame are arranged in a cyclic order.\n\ | |
7ab12479 JB |
1242 | This command selects the window ARG steps away in that order.\n\ |
1243 | A negative ARG moves in the opposite order. If the optional second\n\ | |
44fa5b1e | 1244 | argument ALL_FRAMES is non-nil, cycle through all frames.") |
413430c5 EN |
1245 | (arg, all_frames) |
1246 | register Lisp_Object arg, all_frames; | |
7ab12479 JB |
1247 | { |
1248 | register int i; | |
1249 | register Lisp_Object w; | |
1250 | ||
413430c5 | 1251 | CHECK_NUMBER (arg, 0); |
7ab12479 | 1252 | w = selected_window; |
413430c5 | 1253 | i = XINT (arg); |
7ab12479 JB |
1254 | |
1255 | while (i > 0) | |
1256 | { | |
44fa5b1e | 1257 | w = Fnext_window (w, Qnil, all_frames); |
7ab12479 JB |
1258 | i--; |
1259 | } | |
1260 | while (i < 0) | |
1261 | { | |
44fa5b1e | 1262 | w = Fprevious_window (w, Qnil, all_frames); |
7ab12479 JB |
1263 | i++; |
1264 | } | |
1265 | Fselect_window (w); | |
1266 | return Qnil; | |
1267 | } | |
1268 | \f | |
1269 | /* Look at all windows, performing an operation specified by TYPE | |
1270 | with argument OBJ. | |
75d8f668 | 1271 | If FRAMES is Qt, look at all frames; |
75d8f668 | 1272 | Qnil, look at just the selected frame; |
89bca612 | 1273 | Qvisible, look at visible frames; |
75d8f668 | 1274 | a frame, just look at windows on that frame. |
7ab12479 JB |
1275 | If MINI is non-zero, perform the operation on minibuffer windows too. |
1276 | */ | |
1277 | ||
1278 | enum window_loop | |
1279 | { | |
1280 | WINDOW_LOOP_UNUSED, | |
1281 | GET_BUFFER_WINDOW, /* Arg is buffer */ | |
1282 | GET_LRU_WINDOW, /* Arg is t for full-width windows only */ | |
1283 | DELETE_OTHER_WINDOWS, /* Arg is window not to delete */ | |
1284 | DELETE_BUFFER_WINDOWS, /* Arg is buffer */ | |
1285 | GET_LARGEST_WINDOW, | |
a68c0d3b | 1286 | UNSHOW_BUFFER /* Arg is buffer */ |
7ab12479 JB |
1287 | }; |
1288 | ||
1289 | static Lisp_Object | |
44fa5b1e | 1290 | window_loop (type, obj, mini, frames) |
7ab12479 | 1291 | enum window_loop type; |
44fa5b1e | 1292 | register Lisp_Object obj, frames; |
7ab12479 JB |
1293 | int mini; |
1294 | { | |
1295 | register Lisp_Object w; | |
1296 | register Lisp_Object best_window; | |
1297 | register Lisp_Object next_window; | |
4b206065 | 1298 | register Lisp_Object last_window; |
44fa5b1e | 1299 | FRAME_PTR frame; |
89bca612 RS |
1300 | Lisp_Object frame_arg; |
1301 | frame_arg = Qt; | |
44fa5b1e JB |
1302 | |
1303 | /* If we're only looping through windows on a particular frame, | |
1304 | frame points to that frame. If we're looping through windows | |
1305 | on all frames, frame is 0. */ | |
1306 | if (FRAMEP (frames)) | |
1307 | frame = XFRAME (frames); | |
1308 | else if (NILP (frames)) | |
1309 | frame = selected_frame; | |
7ab12479 | 1310 | else |
44fa5b1e | 1311 | frame = 0; |
89bca612 RS |
1312 | if (frame) |
1313 | frame_arg = Qlambda; | |
f812f9c6 RS |
1314 | else if (XFASTINT (frames) == 0) |
1315 | frame_arg = frames; | |
89bca612 RS |
1316 | else if (EQ (frames, Qvisible)) |
1317 | frame_arg = frames; | |
7ab12479 | 1318 | |
89bca612 RS |
1319 | /* frame_arg is Qlambda to stick to one frame, |
1320 | Qvisible to consider all visible frames, | |
1321 | or Qt otherwise. */ | |
1322 | ||
7ab12479 | 1323 | /* Pick a window to start with. */ |
017b2bad | 1324 | if (WINDOWP (obj)) |
4b206065 | 1325 | w = obj; |
44fa5b1e | 1326 | else if (frame) |
4b206065 | 1327 | w = FRAME_SELECTED_WINDOW (frame); |
7ab12479 | 1328 | else |
4b206065 JB |
1329 | w = FRAME_SELECTED_WINDOW (selected_frame); |
1330 | ||
1331 | /* Figure out the last window we're going to mess with. Since | |
1332 | Fnext_window, given the same options, is guaranteed to go in a | |
1333 | ring, we can just use Fprevious_window to find the last one. | |
1334 | ||
1335 | We can't just wait until we hit the first window again, because | |
1336 | it might be deleted. */ | |
1337 | ||
89bca612 | 1338 | last_window = Fprevious_window (w, mini ? Qt : Qnil, frame_arg); |
7ab12479 | 1339 | |
7ab12479 | 1340 | best_window = Qnil; |
4b206065 | 1341 | for (;;) |
7ab12479 | 1342 | { |
75d8f668 JB |
1343 | FRAME_PTR w_frame = XFRAME (WINDOW_FRAME (XWINDOW (w))); |
1344 | ||
7ab12479 JB |
1345 | /* Pick the next window now, since some operations will delete |
1346 | the current window. */ | |
89bca612 | 1347 | next_window = Fnext_window (w, mini ? Qt : Qnil, frame_arg); |
7ab12479 | 1348 | |
d29a5631 RS |
1349 | /* Note that we do not pay attention here to whether |
1350 | the frame is visible, since Fnext_window skips non-visible frames | |
1351 | if that is desired, under the control of frame_arg. */ | |
75d8f668 | 1352 | if (! MINI_WINDOW_P (XWINDOW (w)) |
7ab12479 JB |
1353 | || (mini && minibuf_level > 0)) |
1354 | switch (type) | |
1355 | { | |
1356 | case GET_BUFFER_WINDOW: | |
5c204627 RS |
1357 | if (XBUFFER (XWINDOW (w)->buffer) == XBUFFER (obj) |
1358 | /* Don't find any minibuffer window | |
1359 | except the one that is currently in use. */ | |
1360 | && (MINI_WINDOW_P (XWINDOW (w)) | |
1361 | ? EQ (w, minibuf_window) : 1)) | |
7ab12479 JB |
1362 | return w; |
1363 | break; | |
1364 | ||
1365 | case GET_LRU_WINDOW: | |
1366 | /* t as arg means consider only full-width windows */ | |
111e5992 | 1367 | if (!NILP (obj) && !WINDOW_FULL_WIDTH_P (XWINDOW (w))) |
7ab12479 | 1368 | break; |
7ab12479 JB |
1369 | /* Ignore dedicated windows and minibuffers. */ |
1370 | if (MINI_WINDOW_P (XWINDOW (w)) | |
265a9e55 | 1371 | || !NILP (XWINDOW (w)->dedicated)) |
7ab12479 | 1372 | break; |
265a9e55 | 1373 | if (NILP (best_window) |
7ab12479 JB |
1374 | || (XFASTINT (XWINDOW (best_window)->use_time) |
1375 | > XFASTINT (XWINDOW (w)->use_time))) | |
1376 | best_window = w; | |
1377 | break; | |
1378 | ||
1379 | case DELETE_OTHER_WINDOWS: | |
1380 | if (XWINDOW (w) != XWINDOW (obj)) | |
1381 | Fdelete_window (w); | |
1382 | break; | |
1383 | ||
1384 | case DELETE_BUFFER_WINDOWS: | |
1385 | if (EQ (XWINDOW (w)->buffer, obj)) | |
1386 | { | |
3548e138 RS |
1387 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (w))); |
1388 | ||
1389 | /* If this window is dedicated, and in a frame of its own, | |
1390 | kill the frame. */ | |
1391 | if (EQ (w, FRAME_ROOT_WINDOW (f)) | |
1392 | && !NILP (XWINDOW (w)->dedicated) | |
1393 | && other_visible_frames (f)) | |
7ab12479 | 1394 | { |
3548e138 RS |
1395 | /* Skip the other windows on this frame. |
1396 | There might be one, the minibuffer! */ | |
1397 | if (! EQ (w, last_window)) | |
1398 | while (f == XFRAME (WINDOW_FRAME (XWINDOW (next_window)))) | |
1399 | { | |
1400 | /* As we go, check for the end of the loop. | |
1401 | We mustn't start going around a second time. */ | |
1402 | if (EQ (next_window, last_window)) | |
1403 | { | |
1404 | last_window = w; | |
1405 | break; | |
1406 | } | |
1407 | next_window = Fnext_window (next_window, | |
1408 | mini ? Qt : Qnil, | |
1409 | frame_arg); | |
1410 | } | |
1411 | /* Now we can safely delete the frame. */ | |
1412 | Fdelete_frame (WINDOW_FRAME (XWINDOW (w)), Qnil); | |
7ab12479 JB |
1413 | } |
1414 | else | |
3548e138 RS |
1415 | /* If we're deleting the buffer displayed in the only window |
1416 | on the frame, find a new buffer to display there. */ | |
1417 | if (NILP (XWINDOW (w)->parent)) | |
1418 | { | |
1419 | Lisp_Object new_buffer; | |
1420 | new_buffer = Fother_buffer (obj, Qnil); | |
1421 | if (NILP (new_buffer)) | |
1422 | new_buffer | |
1423 | = Fget_buffer_create (build_string ("*scratch*")); | |
1424 | Fset_window_buffer (w, new_buffer); | |
1425 | if (EQ (w, selected_window)) | |
1426 | Fset_buffer (XWINDOW (w)->buffer); | |
1427 | } | |
1428 | else | |
1429 | Fdelete_window (w); | |
7ab12479 JB |
1430 | } |
1431 | break; | |
1432 | ||
1433 | case GET_LARGEST_WINDOW: | |
7ab12479 JB |
1434 | /* Ignore dedicated windows and minibuffers. */ |
1435 | if (MINI_WINDOW_P (XWINDOW (w)) | |
265a9e55 | 1436 | || !NILP (XWINDOW (w)->dedicated)) |
7ab12479 JB |
1437 | break; |
1438 | { | |
1439 | struct window *best_window_ptr = XWINDOW (best_window); | |
1440 | struct window *w_ptr = XWINDOW (w); | |
6b54027b RS |
1441 | if (NILP (best_window) |
1442 | || (XFASTINT (w_ptr->height) * XFASTINT (w_ptr->width) | |
1443 | > (XFASTINT (best_window_ptr->height) | |
1444 | * XFASTINT (best_window_ptr->width)))) | |
7ab12479 JB |
1445 | best_window = w; |
1446 | } | |
1447 | break; | |
1448 | ||
1449 | case UNSHOW_BUFFER: | |
1450 | if (EQ (XWINDOW (w)->buffer, obj)) | |
1451 | { | |
1452 | /* Find another buffer to show in this window. */ | |
12cae7c0 | 1453 | Lisp_Object another_buffer; |
38ab08d1 | 1454 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (w))); |
12cae7c0 | 1455 | another_buffer = Fother_buffer (obj, Qnil); |
265a9e55 | 1456 | if (NILP (another_buffer)) |
7ab12479 JB |
1457 | another_buffer |
1458 | = Fget_buffer_create (build_string ("*scratch*")); | |
38ab08d1 RS |
1459 | /* If this window is dedicated, and in a frame of its own, |
1460 | kill the frame. */ | |
1461 | if (EQ (w, FRAME_ROOT_WINDOW (f)) | |
596122a7 | 1462 | && !NILP (XWINDOW (w)->dedicated) |
38ab08d1 | 1463 | && other_visible_frames (f)) |
45945a7b RS |
1464 | { |
1465 | /* Skip the other windows on this frame. | |
1466 | There might be one, the minibuffer! */ | |
1467 | if (! EQ (w, last_window)) | |
1468 | while (f == XFRAME (WINDOW_FRAME (XWINDOW (next_window)))) | |
1469 | { | |
1470 | /* As we go, check for the end of the loop. | |
1471 | We mustn't start going around a second time. */ | |
1472 | if (EQ (next_window, last_window)) | |
1473 | { | |
1474 | last_window = w; | |
1475 | break; | |
1476 | } | |
1477 | next_window = Fnext_window (next_window, | |
1478 | mini ? Qt : Qnil, | |
1479 | frame_arg); | |
1480 | } | |
1481 | /* Now we can safely delete the frame. */ | |
1482 | Fdelete_frame (WINDOW_FRAME (XWINDOW (w)), Qnil); | |
1483 | } | |
38ab08d1 | 1484 | else |
38ab08d1 RS |
1485 | { |
1486 | /* Otherwise show a different buffer in the window. */ | |
1487 | XWINDOW (w)->dedicated = Qnil; | |
1488 | Fset_window_buffer (w, another_buffer); | |
1489 | if (EQ (w, selected_window)) | |
1490 | Fset_buffer (XWINDOW (w)->buffer); | |
1491 | } | |
7ab12479 JB |
1492 | } |
1493 | break; | |
1494 | } | |
4b206065 JB |
1495 | |
1496 | if (EQ (w, last_window)) | |
1497 | break; | |
1498 | ||
7ab12479 JB |
1499 | w = next_window; |
1500 | } | |
7ab12479 JB |
1501 | |
1502 | return best_window; | |
37962e60 | 1503 | } |
605be8af | 1504 | |
7ab12479 JB |
1505 | DEFUN ("get-lru-window", Fget_lru_window, Sget_lru_window, 0, 1, 0, |
1506 | "Return the window least recently selected or used for display.\n\ | |
89bca612 | 1507 | If optional argument FRAME is `visible', search all visible frames.\n\ |
cee67da9 | 1508 | If FRAME is 0, search all visible and iconified frames.\n\ |
89bca612 RS |
1509 | If FRAME is t, search all frames.\n\ |
1510 | If FRAME is nil, search only the selected frame.\n\ | |
1511 | If FRAME is a frame, search only that frame.") | |
1512 | (frame) | |
1513 | Lisp_Object frame; | |
7ab12479 JB |
1514 | { |
1515 | register Lisp_Object w; | |
1516 | /* First try for a window that is full-width */ | |
89bca612 | 1517 | w = window_loop (GET_LRU_WINDOW, Qt, 0, frame); |
265a9e55 | 1518 | if (!NILP (w) && !EQ (w, selected_window)) |
7ab12479 JB |
1519 | return w; |
1520 | /* If none of them, try the rest */ | |
89bca612 | 1521 | return window_loop (GET_LRU_WINDOW, Qnil, 0, frame); |
7ab12479 JB |
1522 | } |
1523 | ||
1524 | DEFUN ("get-largest-window", Fget_largest_window, Sget_largest_window, 0, 1, 0, | |
1525 | "Return the largest window in area.\n\ | |
89bca612 | 1526 | If optional argument FRAME is `visible', search all visible frames.\n\ |
cee67da9 | 1527 | If FRAME is 0, search all visible and iconified frames.\n\ |
89bca612 RS |
1528 | If FRAME is t, search all frames.\n\ |
1529 | If FRAME is nil, search only the selected frame.\n\ | |
1530 | If FRAME is a frame, search only that frame.") | |
44fa5b1e JB |
1531 | (frame) |
1532 | Lisp_Object frame; | |
7ab12479 JB |
1533 | { |
1534 | return window_loop (GET_LARGEST_WINDOW, Qnil, 0, | |
44fa5b1e | 1535 | frame); |
7ab12479 JB |
1536 | } |
1537 | ||
1538 | DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 1, 2, 0, | |
1539 | "Return a window currently displaying BUFFER, or nil if none.\n\ | |
89bca612 | 1540 | If optional argument FRAME is `visible', search all visible frames.\n\ |
f812f9c6 | 1541 | If optional argument FRAME is 0, search all visible and iconified frames.\n\ |
89bca612 | 1542 | If FRAME is t, search all frames.\n\ |
1bc981d2 | 1543 | If FRAME is nil, search only the selected frame.\n\ |
89bca612 | 1544 | If FRAME is a frame, search only that frame.") |
44fa5b1e JB |
1545 | (buffer, frame) |
1546 | Lisp_Object buffer, frame; | |
7ab12479 JB |
1547 | { |
1548 | buffer = Fget_buffer (buffer); | |
017b2bad | 1549 | if (BUFFERP (buffer)) |
44fa5b1e | 1550 | return window_loop (GET_BUFFER_WINDOW, buffer, 1, frame); |
7ab12479 JB |
1551 | else |
1552 | return Qnil; | |
1553 | } | |
1554 | ||
1555 | DEFUN ("delete-other-windows", Fdelete_other_windows, Sdelete_other_windows, | |
1556 | 0, 1, "", | |
44fa5b1e | 1557 | "Make WINDOW (or the selected window) fill its frame.\n\ |
f16a1ed3 RS |
1558 | Only the frame WINDOW is on is affected.\n\ |
1559 | This function tries to reduce display jumps\n\ | |
1560 | by keeping the text previously visible in WINDOW\n\ | |
1561 | in the same place on the frame. Doing this depends on\n\ | |
1562 | the value of (window-start WINDOW), so if calling this function\n\ | |
1563 | in a program gives strange scrolling, make sure the window-start\n\ | |
1564 | value is reasonable when this function is called.") | |
7ab12479 JB |
1565 | (window) |
1566 | Lisp_Object window; | |
1567 | { | |
1568 | struct window *w; | |
00d3d838 | 1569 | int startpos; |
7ab12479 JB |
1570 | int top; |
1571 | ||
265a9e55 | 1572 | if (NILP (window)) |
7ab12479 JB |
1573 | window = selected_window; |
1574 | else | |
605be8af | 1575 | CHECK_LIVE_WINDOW (window, 0); |
7ab12479 JB |
1576 | |
1577 | w = XWINDOW (window); | |
a2b38b3c | 1578 | |
00d3d838 KH |
1579 | startpos = marker_position (w->start); |
1580 | top = XFASTINT (w->top) - FRAME_MENU_BAR_LINES (XFRAME (WINDOW_FRAME (w))); | |
7ab12479 | 1581 | |
a2b38b3c RS |
1582 | if (MINI_WINDOW_P (w) && top > 0) |
1583 | error ("Can't expand minibuffer to full frame"); | |
1584 | ||
70728a80 | 1585 | window_loop (DELETE_OTHER_WINDOWS, window, 0, WINDOW_FRAME (w)); |
7ab12479 | 1586 | |
00d3d838 KH |
1587 | /* Try to minimize scrolling, by setting the window start to the point |
1588 | will cause the text at the old window start to be at the same place | |
1589 | on the frame. But don't try to do this if the window start is | |
1590 | outside the visible portion (as might happen when the display is | |
1591 | not current, due to typeahead). */ | |
1592 | if (startpos >= BUF_BEGV (XBUFFER (w->buffer)) | |
1593 | && startpos <= BUF_ZV (XBUFFER (w->buffer))) | |
1594 | { | |
1595 | struct position pos; | |
1596 | struct buffer *obuf = current_buffer; | |
1597 | ||
1598 | Fset_buffer (w->buffer); | |
1599 | /* This computation used to temporarily move point, but that can | |
1600 | have unwanted side effects due to text properties. */ | |
0383eb57 | 1601 | pos = *vmotion (startpos, -top, w); |
4d047f50 | 1602 | |
b73ea88e RS |
1603 | set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos); |
1604 | w->start_at_line_beg = ((pos.bytepos == BEGV_BYTE | |
1605 | || FETCH_BYTE (pos.bytepos - 1) == '\n') ? Qt | |
00d3d838 | 1606 | : Qnil); |
80622eec RS |
1607 | /* We need to do this, so that the window-scroll-functions |
1608 | get called. */ | |
4d047f50 | 1609 | w->optional_new_start = Qt; |
00d3d838 KH |
1610 | |
1611 | set_buffer_internal (obuf); | |
1612 | } | |
7ab12479 JB |
1613 | return Qnil; |
1614 | } | |
1615 | ||
1616 | DEFUN ("delete-windows-on", Fdelete_windows_on, Sdelete_windows_on, | |
3cbbb729 | 1617 | 1, 2, "bDelete windows on (buffer): ", |
26f6279d JB |
1618 | "Delete all windows showing BUFFER.\n\ |
1619 | Optional second argument FRAME controls which frames are affected.\n\ | |
1620 | If nil or omitted, delete all windows showing BUFFER in any frame.\n\ | |
1621 | If t, delete only windows showing BUFFER in the selected frame.\n\ | |
89bca612 | 1622 | If `visible', delete all windows showing BUFFER in any visible frame.\n\ |
26f6279d JB |
1623 | If a frame, delete only windows showing BUFFER in that frame.") |
1624 | (buffer, frame) | |
1625 | Lisp_Object buffer, frame; | |
7ab12479 | 1626 | { |
26f6279d JB |
1627 | /* FRAME uses t and nil to mean the opposite of what window_loop |
1628 | expects. */ | |
1629 | if (! FRAMEP (frame)) | |
1630 | frame = NILP (frame) ? Qt : Qnil; | |
26f6279d | 1631 | |
265a9e55 | 1632 | if (!NILP (buffer)) |
7ab12479 JB |
1633 | { |
1634 | buffer = Fget_buffer (buffer); | |
1635 | CHECK_BUFFER (buffer, 0); | |
26f6279d | 1636 | window_loop (DELETE_BUFFER_WINDOWS, buffer, 0, frame); |
7ab12479 JB |
1637 | } |
1638 | return Qnil; | |
1639 | } | |
1640 | ||
1641 | DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows, | |
1642 | Sreplace_buffer_in_windows, | |
1643 | 1, 1, "bReplace buffer in windows: ", | |
1644 | "Replace BUFFER with some other buffer in all windows showing it.") | |
1645 | (buffer) | |
1646 | Lisp_Object buffer; | |
1647 | { | |
265a9e55 | 1648 | if (!NILP (buffer)) |
7ab12479 JB |
1649 | { |
1650 | buffer = Fget_buffer (buffer); | |
1651 | CHECK_BUFFER (buffer, 0); | |
1652 | window_loop (UNSHOW_BUFFER, buffer, 0, Qt); | |
1653 | } | |
1654 | return Qnil; | |
1655 | } | |
ff58478b RS |
1656 | |
1657 | /* Replace BUFFER with some other buffer in all windows | |
1658 | of all frames, even those on other keyboards. */ | |
1659 | ||
1660 | void | |
1661 | replace_buffer_in_all_windows (buffer) | |
1662 | Lisp_Object buffer; | |
1663 | { | |
27abb84f | 1664 | #ifdef MULTI_KBOARD |
ff58478b RS |
1665 | Lisp_Object tail, frame; |
1666 | ||
ff58478b RS |
1667 | /* A single call to window_loop won't do the job |
1668 | because it only considers frames on the current keyboard. | |
1669 | So loop manually over frames, and handle each one. */ | |
1670 | FOR_EACH_FRAME (tail, frame) | |
db7f721d | 1671 | window_loop (UNSHOW_BUFFER, buffer, 1, frame); |
ff58478b | 1672 | #else |
db7f721d | 1673 | window_loop (UNSHOW_BUFFER, buffer, 1, Qt); |
ff58478b RS |
1674 | #endif |
1675 | } | |
7ab12479 JB |
1676 | \f |
1677 | /* Set the height of WINDOW and all its inferiors. */ | |
a481b3ea JB |
1678 | |
1679 | /* The smallest acceptable dimensions for a window. Anything smaller | |
1680 | might crash Emacs. */ | |
1681 | #define MIN_SAFE_WINDOW_WIDTH (2) | |
1682 | #define MIN_SAFE_WINDOW_HEIGHT (2) | |
1683 | ||
1684 | /* Make sure that window_min_height and window_min_width are | |
1685 | not too small; if they are, set them to safe minima. */ | |
1686 | ||
1687 | static void | |
1688 | check_min_window_sizes () | |
1689 | { | |
1690 | /* Smaller values might permit a crash. */ | |
1691 | if (window_min_width < MIN_SAFE_WINDOW_WIDTH) | |
1692 | window_min_width = MIN_SAFE_WINDOW_WIDTH; | |
1693 | if (window_min_height < MIN_SAFE_WINDOW_HEIGHT) | |
1694 | window_min_height = MIN_SAFE_WINDOW_HEIGHT; | |
1695 | } | |
1696 | ||
1697 | /* If *ROWS or *COLS are too small a size for FRAME, set them to the | |
1698 | minimum allowable size. */ | |
605be8af | 1699 | void |
a481b3ea | 1700 | check_frame_size (frame, rows, cols) |
605be8af JB |
1701 | FRAME_PTR frame; |
1702 | int *rows, *cols; | |
a481b3ea | 1703 | { |
628df3bf | 1704 | /* For height, we have to see: |
37962e60 | 1705 | whether the frame has a minibuffer, |
628df3bf JB |
1706 | whether it wants a mode line, and |
1707 | whether it has a menu bar. */ | |
a481b3ea | 1708 | int min_height = |
79f92720 JB |
1709 | (FRAME_MINIBUF_ONLY_P (frame) ? MIN_SAFE_WINDOW_HEIGHT - 1 |
1710 | : (! FRAME_HAS_MINIBUF_P (frame)) ? MIN_SAFE_WINDOW_HEIGHT | |
a481b3ea | 1711 | : 2 * MIN_SAFE_WINDOW_HEIGHT - 1); |
628df3bf JB |
1712 | if (FRAME_MENU_BAR_LINES (frame) > 0) |
1713 | min_height += FRAME_MENU_BAR_LINES (frame); | |
a481b3ea JB |
1714 | |
1715 | if (*rows < min_height) | |
1716 | *rows = min_height; | |
1717 | if (*cols < MIN_SAFE_WINDOW_WIDTH) | |
1718 | *cols = MIN_SAFE_WINDOW_WIDTH; | |
1719 | } | |
1720 | ||
7ab12479 JB |
1721 | /* Normally the window is deleted if it gets too small. |
1722 | nodelete nonzero means do not do this. | |
1723 | (The caller should check later and do so if appropriate) */ | |
1724 | ||
5e14b1fc | 1725 | void |
7ab12479 JB |
1726 | set_window_height (window, height, nodelete) |
1727 | Lisp_Object window; | |
1728 | int height; | |
1729 | int nodelete; | |
1730 | { | |
1731 | register struct window *w = XWINDOW (window); | |
1732 | register struct window *c; | |
1733 | int oheight = XFASTINT (w->height); | |
1734 | int top, pos, lastbot, opos, lastobot; | |
1735 | Lisp_Object child; | |
1736 | ||
a481b3ea JB |
1737 | check_min_window_sizes (); |
1738 | ||
7ab12479 | 1739 | if (!nodelete |
265a9e55 | 1740 | && ! NILP (w->parent) |
c6b530ed RS |
1741 | && (MINI_WINDOW_P (w) |
1742 | ? height < 1 | |
1743 | : height < window_min_height)) | |
7ab12479 | 1744 | { |
543f5fb1 | 1745 | delete_window (window); |
7ab12479 JB |
1746 | return; |
1747 | } | |
1748 | ||
d834a2e9 | 1749 | XSETFASTINT (w->last_modified, 0); |
3cd21523 | 1750 | XSETFASTINT (w->last_overlay_modified, 0); |
7ab12479 | 1751 | windows_or_buffers_changed++; |
29aeee73 RS |
1752 | FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w))) = 1; |
1753 | ||
d834a2e9 | 1754 | XSETFASTINT (w->height, height); |
265a9e55 | 1755 | if (!NILP (w->hchild)) |
7ab12479 | 1756 | { |
265a9e55 | 1757 | for (child = w->hchild; !NILP (child); child = XWINDOW (child)->next) |
7ab12479 JB |
1758 | { |
1759 | XWINDOW (child)->top = w->top; | |
1760 | set_window_height (child, height, nodelete); | |
1761 | } | |
1762 | } | |
265a9e55 | 1763 | else if (!NILP (w->vchild)) |
7ab12479 JB |
1764 | { |
1765 | lastbot = top = XFASTINT (w->top); | |
1766 | lastobot = 0; | |
265a9e55 | 1767 | for (child = w->vchild; !NILP (child); child = c->next) |
7ab12479 JB |
1768 | { |
1769 | c = XWINDOW (child); | |
1770 | ||
1771 | opos = lastobot + XFASTINT (c->height); | |
1772 | ||
d834a2e9 | 1773 | XSETFASTINT (c->top, lastbot); |
7ab12479 JB |
1774 | |
1775 | pos = (((opos * height) << 1) + oheight) / (oheight << 1); | |
1776 | ||
1777 | /* Avoid confusion: inhibit deletion of child if becomes too small */ | |
1778 | set_window_height (child, pos + top - lastbot, 1); | |
1779 | ||
1780 | /* Now advance child to next window, | |
1781 | and set lastbot if child was not just deleted. */ | |
1782 | lastbot = pos + top; | |
1783 | lastobot = opos; | |
1784 | } | |
1785 | /* Now delete any children that became too small. */ | |
1786 | if (!nodelete) | |
265a9e55 | 1787 | for (child = w->vchild; !NILP (child); child = XWINDOW (child)->next) |
7ab12479 JB |
1788 | { |
1789 | set_window_height (child, XINT (XWINDOW (child)->height), 0); | |
1790 | } | |
1791 | } | |
1792 | } | |
1793 | ||
1794 | /* Recursively set width of WINDOW and its inferiors. */ | |
1795 | ||
5e14b1fc | 1796 | void |
7ab12479 JB |
1797 | set_window_width (window, width, nodelete) |
1798 | Lisp_Object window; | |
1799 | int width; | |
1800 | int nodelete; | |
1801 | { | |
1802 | register struct window *w = XWINDOW (window); | |
1803 | register struct window *c; | |
1804 | int owidth = XFASTINT (w->width); | |
1805 | int left, pos, lastright, opos, lastoright; | |
1806 | Lisp_Object child; | |
1807 | ||
abdced83 | 1808 | if (!nodelete && width < window_min_width && !NILP (w->parent)) |
7ab12479 | 1809 | { |
543f5fb1 | 1810 | delete_window (window); |
7ab12479 JB |
1811 | return; |
1812 | } | |
1813 | ||
d834a2e9 | 1814 | XSETFASTINT (w->last_modified, 0); |
3cd21523 | 1815 | XSETFASTINT (w->last_overlay_modified, 0); |
7ab12479 | 1816 | windows_or_buffers_changed++; |
29aeee73 RS |
1817 | FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w))) = 1; |
1818 | ||
d834a2e9 | 1819 | XSETFASTINT (w->width, width); |
265a9e55 | 1820 | if (!NILP (w->vchild)) |
7ab12479 | 1821 | { |
265a9e55 | 1822 | for (child = w->vchild; !NILP (child); child = XWINDOW (child)->next) |
7ab12479 JB |
1823 | { |
1824 | XWINDOW (child)->left = w->left; | |
1825 | set_window_width (child, width, nodelete); | |
1826 | } | |
1827 | } | |
265a9e55 | 1828 | else if (!NILP (w->hchild)) |
7ab12479 JB |
1829 | { |
1830 | lastright = left = XFASTINT (w->left); | |
1831 | lastoright = 0; | |
265a9e55 | 1832 | for (child = w->hchild; !NILP (child); child = c->next) |
7ab12479 JB |
1833 | { |
1834 | c = XWINDOW (child); | |
1835 | ||
1836 | opos = lastoright + XFASTINT (c->width); | |
1837 | ||
d834a2e9 | 1838 | XSETFASTINT (c->left, lastright); |
7ab12479 JB |
1839 | |
1840 | pos = (((opos * width) << 1) + owidth) / (owidth << 1); | |
1841 | ||
1842 | /* Inhibit deletion for becoming too small */ | |
1843 | set_window_width (child, pos + left - lastright, 1); | |
1844 | ||
1845 | /* Now advance child to next window, | |
1846 | and set lastright if child was not just deleted. */ | |
1847 | lastright = pos + left, lastoright = opos; | |
1848 | } | |
1849 | /* Delete children that became too small */ | |
1850 | if (!nodelete) | |
265a9e55 | 1851 | for (child = w->hchild; !NILP (child); child = XWINDOW (child)->next) |
7ab12479 JB |
1852 | { |
1853 | set_window_width (child, XINT (XWINDOW (child)->width), 0); | |
1854 | } | |
1855 | } | |
1856 | } | |
1857 | \f | |
1d8d96fa | 1858 | int window_select_count; |
7ab12479 | 1859 | |
5b03d3c0 RS |
1860 | Lisp_Object |
1861 | Fset_window_buffer_unwind (obuf) | |
1862 | Lisp_Object obuf; | |
1863 | { | |
1864 | Fset_buffer (obuf); | |
1865 | return Qnil; | |
1866 | } | |
1867 | ||
7ab12479 JB |
1868 | DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 2, 0, |
1869 | "Make WINDOW display BUFFER as its contents.\n\ | |
1870 | BUFFER can be a buffer or buffer name.") | |
1871 | (window, buffer) | |
1872 | register Lisp_Object window, buffer; | |
1873 | { | |
1874 | register Lisp_Object tem; | |
1875 | register struct window *w = decode_window (window); | |
5b03d3c0 | 1876 | int count = specpdl_ptr - specpdl; |
7ab12479 JB |
1877 | |
1878 | buffer = Fget_buffer (buffer); | |
1879 | CHECK_BUFFER (buffer, 1); | |
1880 | ||
265a9e55 | 1881 | if (NILP (XBUFFER (buffer)->name)) |
7ab12479 JB |
1882 | error ("Attempt to display deleted buffer"); |
1883 | ||
1884 | tem = w->buffer; | |
265a9e55 | 1885 | if (NILP (tem)) |
7ab12479 JB |
1886 | error ("Window is deleted"); |
1887 | else if (! EQ (tem, Qt)) /* w->buffer is t when the window | |
1888 | is first being set up. */ | |
1889 | { | |
265a9e55 | 1890 | if (!NILP (w->dedicated) && !EQ (tem, buffer)) |
3cf85532 RS |
1891 | error ("Window is dedicated to `%s'", |
1892 | XSTRING (XBUFFER (tem)->name)->data); | |
7ab12479 JB |
1893 | |
1894 | unshow_buffer (w); | |
1895 | } | |
1896 | ||
1897 | w->buffer = buffer; | |
86e48436 RS |
1898 | |
1899 | if (EQ (window, selected_window)) | |
1900 | XBUFFER (w->buffer)->last_selected_window = window; | |
850ebd4f RS |
1901 | if (INTEGERP (XBUFFER (buffer)->display_count)) |
1902 | XSETINT (XBUFFER (buffer)->display_count, | |
296b535c | 1903 | XINT (XBUFFER (buffer)->display_count) + 1); |
86e48436 | 1904 | |
d834a2e9 | 1905 | XSETFASTINT (w->window_end_pos, 0); |
5a41ab94 | 1906 | w->window_end_valid = Qnil; |
dba06815 | 1907 | XSETFASTINT (w->hscroll, 0); |
b73ea88e RS |
1908 | set_marker_both (w->pointm, buffer, |
1909 | BUF_PT (XBUFFER (buffer)), BUF_PT_BYTE (XBUFFER (buffer))); | |
7ab12479 JB |
1910 | set_marker_restricted (w->start, |
1911 | make_number (XBUFFER (buffer)->last_window_start), | |
1912 | buffer); | |
1913 | w->start_at_line_beg = Qnil; | |
e36ab06b | 1914 | w->force_start = Qnil; |
d834a2e9 | 1915 | XSETFASTINT (w->last_modified, 0); |
3cd21523 | 1916 | XSETFASTINT (w->last_overlay_modified, 0); |
7ab12479 | 1917 | windows_or_buffers_changed++; |
5b03d3c0 RS |
1918 | |
1919 | /* We must select BUFFER for running the window-scroll-functions. | |
1920 | If WINDOW is selected, switch permanently. | |
1921 | Otherwise, switch but go back to the ambient buffer afterward. */ | |
7ab12479 JB |
1922 | if (EQ (window, selected_window)) |
1923 | Fset_buffer (buffer); | |
5b03d3c0 RS |
1924 | /* We can't check ! NILP (Vwindow_scroll_functions) here |
1925 | because that might itself be a local variable. */ | |
1926 | else if (window_initialized) | |
1927 | { | |
1928 | record_unwind_protect (Fset_window_buffer_unwind, Fcurrent_buffer ()); | |
1929 | Fset_buffer (buffer); | |
1930 | } | |
1931 | ||
dba06815 RS |
1932 | if (! NILP (Vwindow_scroll_functions)) |
1933 | run_hook_with_args_2 (Qwindow_scroll_functions, window, | |
1934 | Fmarker_position (w->start)); | |
7ab12479 | 1935 | |
543f5fb1 RS |
1936 | if (! NILP (Vwindow_configuration_change_hook) |
1937 | && ! NILP (Vrun_hooks)) | |
1938 | call1 (Vrun_hooks, Qwindow_configuration_change_hook); | |
1939 | ||
5b03d3c0 RS |
1940 | unbind_to (count, Qnil); |
1941 | ||
7ab12479 JB |
1942 | return Qnil; |
1943 | } | |
1944 | ||
1945 | DEFUN ("select-window", Fselect_window, Sselect_window, 1, 1, 0, | |
1946 | "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\ | |
1947 | The main editor command loop selects the buffer of the selected window\n\ | |
1948 | before each command.") | |
1949 | (window) | |
1950 | register Lisp_Object window; | |
1951 | { | |
1952 | register struct window *w; | |
1953 | register struct window *ow = XWINDOW (selected_window); | |
1954 | ||
605be8af | 1955 | CHECK_LIVE_WINDOW (window, 0); |
7ab12479 JB |
1956 | |
1957 | w = XWINDOW (window); | |
1958 | ||
265a9e55 | 1959 | if (NILP (w->buffer)) |
7ab12479 JB |
1960 | error ("Trying to select deleted window or non-leaf window"); |
1961 | ||
d834a2e9 | 1962 | XSETFASTINT (w->use_time, ++window_select_count); |
7ab12479 JB |
1963 | if (EQ (window, selected_window)) |
1964 | return window; | |
1965 | ||
596ae0cf RS |
1966 | if (! NILP (ow->buffer)) |
1967 | set_marker_both (ow->pointm, ow->buffer, | |
1968 | BUF_PT (XBUFFER (ow->buffer)), | |
1969 | BUF_PT_BYTE (XBUFFER (ow->buffer))); | |
7ab12479 JB |
1970 | |
1971 | selected_window = window; | |
44fa5b1e | 1972 | if (XFRAME (WINDOW_FRAME (w)) != selected_frame) |
7ab12479 | 1973 | { |
44fa5b1e | 1974 | XFRAME (WINDOW_FRAME (w))->selected_window = window; |
147a6615 RS |
1975 | /* Use this rather than Fhandle_switch_frame |
1976 | so that FRAME_FOCUS_FRAME is moved appropriately as we | |
1977 | move around in the state where a minibuffer in a separate | |
1978 | frame is active. */ | |
1979 | Fselect_frame (WINDOW_FRAME (w), Qnil); | |
7ab12479 JB |
1980 | } |
1981 | else | |
44fa5b1e | 1982 | selected_frame->selected_window = window; |
7ab12479 JB |
1983 | |
1984 | record_buffer (w->buffer); | |
1985 | Fset_buffer (w->buffer); | |
1986 | ||
86e48436 RS |
1987 | XBUFFER (w->buffer)->last_selected_window = window; |
1988 | ||
7ab12479 JB |
1989 | /* Go to the point recorded in the window. |
1990 | This is important when the buffer is in more | |
1991 | than one window. It also matters when | |
1992 | redisplay_window has altered point after scrolling, | |
1993 | because it makes the change only in the window. */ | |
1994 | { | |
1995 | register int new_point = marker_position (w->pointm); | |
1996 | if (new_point < BEGV) | |
1997 | SET_PT (BEGV); | |
a9c95e08 | 1998 | else if (new_point > ZV) |
7ab12479 JB |
1999 | SET_PT (ZV); |
2000 | else | |
2001 | SET_PT (new_point); | |
2002 | } | |
2003 | ||
2004 | windows_or_buffers_changed++; | |
2005 | return window; | |
2006 | } | |
2007 | ||
441a127e RS |
2008 | /* Deiconify the frame containing the window WINDOW, |
2009 | unless it is the selected frame; | |
2010 | then return WINDOW. | |
2011 | ||
2012 | The reason for the exception for the selected frame | |
2013 | is that it seems better not to change the selected frames visibility | |
2014 | merely because of displaying a different buffer in it. | |
2015 | The deiconification is useful when a buffer gets shown in | |
2016 | another frame that you were not using lately. */ | |
d07f802a RS |
2017 | |
2018 | static Lisp_Object | |
2019 | display_buffer_1 (window) | |
2020 | Lisp_Object window; | |
2021 | { | |
d07f802a RS |
2022 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (window))); |
2023 | FRAME_SAMPLE_VISIBILITY (f); | |
60117126 RS |
2024 | if (f != selected_frame) |
2025 | { | |
2026 | if (FRAME_ICONIFIED_P (f)) | |
2027 | Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window))); | |
37962e60 | 2028 | else if (FRAME_VISIBLE_P (f)) |
60117126 RS |
2029 | Fraise_frame (WINDOW_FRAME (XWINDOW (window))); |
2030 | } | |
d07f802a RS |
2031 | return window; |
2032 | } | |
2033 | ||
4628f7a4 | 2034 | DEFUN ("special-display-p", Fspecial_display_p, Sspecial_display_p, 1, 1, 0, |
0f7d64d2 GV |
2035 | "Returns non-nil if a buffer named BUFFER-NAME would be created specially.\n\ |
2036 | The value is actually t if the frame should be called with default frame\n\ | |
2037 | parameters, and a list of frame parameters if they were specified.\n\ | |
4628f7a4 EN |
2038 | See `special-display-buffer-names', and `special-display-regexps'.") |
2039 | (buffer_name) | |
2040 | Lisp_Object buffer_name; | |
2041 | { | |
2042 | Lisp_Object tem; | |
2043 | ||
2044 | CHECK_STRING (buffer_name, 1); | |
2045 | ||
2046 | tem = Fmember (buffer_name, Vspecial_display_buffer_names); | |
2047 | if (!NILP (tem)) | |
2048 | return Qt; | |
2049 | ||
2050 | tem = Fassoc (buffer_name, Vspecial_display_buffer_names); | |
2051 | if (!NILP (tem)) | |
2052 | return XCDR (tem); | |
2053 | ||
2054 | for (tem = Vspecial_display_regexps; CONSP (tem); tem = XCDR (tem)) | |
2055 | { | |
2056 | Lisp_Object car = XCAR (tem); | |
2057 | if (STRINGP (car) | |
2058 | && fast_string_match (car, buffer_name) >= 0) | |
2059 | return Qt; | |
2060 | else if (CONSP (car) | |
2061 | && STRINGP (XCAR (car)) | |
2062 | && fast_string_match (XCAR (car), buffer_name) >= 0) | |
2063 | return XCDR (tem); | |
2064 | } | |
2065 | return Qnil; | |
2066 | } | |
2067 | ||
2068 | DEFUN ("same-window-p", Fsame_window_p, Ssame_window_p, 1, 1, 0, | |
0f7d64d2 | 2069 | "Returns non-nil if a new buffer named BUFFER-NAME would use the same window.\n\ |
4628f7a4 EN |
2070 | See `same-window-buffer-names' and `same-window-regexps'.") |
2071 | (buffer_name) | |
2072 | Lisp_Object buffer_name; | |
2073 | { | |
2074 | Lisp_Object tem; | |
2075 | ||
2076 | CHECK_STRING (buffer_name, 1); | |
2077 | ||
2078 | tem = Fmember (buffer_name, Vsame_window_buffer_names); | |
2079 | if (!NILP (tem)) | |
2080 | return Qt; | |
2081 | ||
2082 | tem = Fassoc (buffer_name, Vsame_window_buffer_names); | |
2083 | if (!NILP (tem)) | |
2084 | return Qt; | |
2085 | ||
2086 | for (tem = Vsame_window_regexps; CONSP (tem); tem = XCDR (tem)) | |
2087 | { | |
2088 | Lisp_Object car = XCAR (tem); | |
2089 | if (STRINGP (car) | |
2090 | && fast_string_match (car, buffer_name) >= 0) | |
2091 | return Qt; | |
2092 | else if (CONSP (car) | |
2093 | && STRINGP (XCAR (car)) | |
2094 | && fast_string_match (XCAR (car), buffer_name) >= 0) | |
2095 | return Qt; | |
2096 | } | |
2097 | return Qnil; | |
2098 | } | |
2099 | ||
35aaf00c | 2100 | DEFUN ("display-buffer", Fdisplay_buffer, Sdisplay_buffer, 1, 2, |
62a7e6eb | 2101 | "BDisplay buffer: \nP", /* Use B so the default is (other-buffer). */ |
7ab12479 JB |
2102 | "Make BUFFER appear in some window but don't select it.\n\ |
2103 | BUFFER can be a buffer or a buffer name.\n\ | |
2104 | If BUFFER is shown already in some window, just use that one,\n\ | |
2105 | unless the window is the selected window and the optional second\n\ | |
46d3268a | 2106 | argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).\n\ |
5141b901 | 2107 | If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.\n\ |
5abcf432 RS |
2108 | Returns the window displaying BUFFER.\n\ |
2109 | \n\ | |
2110 | The variables `special-display-buffer-names', `special-display-regexps',\n\ | |
2111 | `same-window-buffer-names', and `same-window-regexps' customize how certain\n\ | |
2112 | buffer names are handled.") | |
7ab12479 JB |
2113 | (buffer, not_this_window) |
2114 | register Lisp_Object buffer, not_this_window; | |
2115 | { | |
a90712c2 | 2116 | register Lisp_Object window, tem; |
7ab12479 JB |
2117 | |
2118 | buffer = Fget_buffer (buffer); | |
2119 | CHECK_BUFFER (buffer, 0); | |
2120 | ||
265a9e55 | 2121 | if (!NILP (Vdisplay_buffer_function)) |
7ab12479 JB |
2122 | return call2 (Vdisplay_buffer_function, buffer, not_this_window); |
2123 | ||
265a9e55 | 2124 | if (NILP (not_this_window) |
7ab12479 | 2125 | && XBUFFER (XWINDOW (selected_window)->buffer) == XBUFFER (buffer)) |
d07f802a | 2126 | return display_buffer_1 (selected_window); |
7ab12479 | 2127 | |
855d8627 RS |
2128 | /* See if the user has specified this buffer should appear |
2129 | in the selected window. */ | |
2130 | if (NILP (not_this_window)) | |
2131 | { | |
4628f7a4 | 2132 | tem = Fsame_window_p (XBUFFER (buffer)->name); |
855d8627 | 2133 | if (!NILP (tem)) |
c63dc4a2 RS |
2134 | { |
2135 | Fswitch_to_buffer (buffer, Qnil); | |
d07f802a | 2136 | return display_buffer_1 (selected_window); |
c63dc4a2 | 2137 | } |
855d8627 RS |
2138 | } |
2139 | ||
e8edb3ae | 2140 | /* If pop_up_frames, |
73dc5198 KH |
2141 | look for a window showing BUFFER on any visible or iconified frame. |
2142 | Otherwise search only the current frame. */ | |
2143 | if (pop_up_frames || last_nonminibuf_frame == 0) | |
2144 | XSETFASTINT (tem, 0); | |
2145 | else | |
73dc5198 KH |
2146 | XSETFRAME (tem, last_nonminibuf_frame); |
2147 | window = Fget_buffer_window (buffer, tem); | |
265a9e55 JB |
2148 | if (!NILP (window) |
2149 | && (NILP (not_this_window) || !EQ (window, selected_window))) | |
f812f9c6 | 2150 | { |
d07f802a | 2151 | return display_buffer_1 (window); |
f812f9c6 | 2152 | } |
7ab12479 | 2153 | |
a90712c2 | 2154 | /* Certain buffer names get special handling. */ |
4628f7a4 | 2155 | if (!NILP (Vspecial_display_function)) |
a90712c2 | 2156 | { |
4628f7a4 EN |
2157 | tem = Fspecial_display_p (XBUFFER (buffer)->name); |
2158 | if (EQ (tem, Qt)) | |
a90712c2 | 2159 | return call1 (Vspecial_display_function, buffer); |
4628f7a4 EN |
2160 | if (CONSP (tem)) |
2161 | return call2 (Vspecial_display_function, buffer, tem); | |
a90712c2 RS |
2162 | } |
2163 | ||
44fa5b1e JB |
2164 | /* If there are no frames open that have more than a minibuffer, |
2165 | we need to create a new frame. */ | |
2166 | if (pop_up_frames || last_nonminibuf_frame == 0) | |
7ab12479 | 2167 | { |
a90712c2 | 2168 | window = Fframe_selected_window (call0 (Vpop_up_frame_function)); |
7ab12479 | 2169 | Fset_window_buffer (window, buffer); |
d07f802a | 2170 | return display_buffer_1 (window); |
7ab12479 | 2171 | } |
7ab12479 | 2172 | |
43bad991 | 2173 | if (pop_up_windows |
44fa5b1e | 2174 | || FRAME_MINIBUF_ONLY_P (selected_frame) |
cee67da9 RS |
2175 | /* If the current frame is a special display frame, |
2176 | don't try to reuse its windows. */ | |
2177 | || !NILP (XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->dedicated) | |
43bad991 | 2178 | ) |
7ab12479 | 2179 | { |
12cae7c0 KH |
2180 | Lisp_Object frames; |
2181 | ||
37962e60 | 2182 | frames = Qnil; |
44fa5b1e | 2183 | if (FRAME_MINIBUF_ONLY_P (selected_frame)) |
74112613 | 2184 | XSETFRAME (frames, last_nonminibuf_frame); |
7ab12479 JB |
2185 | /* Don't try to create a window if would get an error */ |
2186 | if (split_height_threshold < window_min_height << 1) | |
2187 | split_height_threshold = window_min_height << 1; | |
2188 | ||
cee67da9 RS |
2189 | /* Note that both Fget_largest_window and Fget_lru_window |
2190 | ignore minibuffers and dedicated windows. | |
2191 | This means they can return nil. */ | |
7ab12479 | 2192 | |
cee67da9 RS |
2193 | /* If the frame we would try to split cannot be split, |
2194 | try other frames. */ | |
2195 | if (FRAME_NO_SPLIT_P (NILP (frames) ? selected_frame | |
2196 | : last_nonminibuf_frame)) | |
2197 | { | |
2198 | /* Try visible frames first. */ | |
2199 | window = Fget_largest_window (Qvisible); | |
2200 | /* If that didn't work, try iconified frames. */ | |
2201 | if (NILP (window)) | |
2202 | window = Fget_largest_window (make_number (0)); | |
2203 | if (NILP (window)) | |
2204 | window = Fget_largest_window (Qt); | |
2205 | } | |
2206 | else | |
2207 | window = Fget_largest_window (frames); | |
2208 | ||
92cca945 RS |
2209 | /* If we got a tall enough full-width window that can be split, |
2210 | split it. */ | |
265a9e55 | 2211 | if (!NILP (window) |
92cca945 | 2212 | && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame)) |
7ab12479 | 2213 | && window_height (window) >= split_height_threshold |
111e5992 | 2214 | && WINDOW_FULL_WIDTH_P (XWINDOW (window))) |
7ab12479 JB |
2215 | window = Fsplit_window (window, Qnil, Qnil); |
2216 | else | |
2217 | { | |
1942f68f RS |
2218 | Lisp_Object upper, lower, other; |
2219 | ||
44fa5b1e | 2220 | window = Fget_lru_window (frames); |
92cca945 RS |
2221 | /* If the LRU window is selected, and big enough, |
2222 | and can be split, split it. */ | |
cee67da9 | 2223 | if (!NILP (window) |
92cca945 | 2224 | && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame)) |
cee67da9 RS |
2225 | && (EQ (window, selected_window) |
2226 | || EQ (XWINDOW (window)->parent, Qnil)) | |
7ab12479 JB |
2227 | && window_height (window) >= window_min_height << 1) |
2228 | window = Fsplit_window (window, Qnil, Qnil); | |
cee67da9 | 2229 | /* If Fget_lru_window returned nil, try other approaches. */ |
48d9379d | 2230 | |
cee67da9 | 2231 | /* Try visible frames first. */ |
48d9379d RS |
2232 | if (NILP (window)) |
2233 | window = Fget_buffer_window (buffer, Qvisible); | |
cee67da9 RS |
2234 | if (NILP (window)) |
2235 | window = Fget_largest_window (Qvisible); | |
2236 | /* If that didn't work, try iconified frames. */ | |
48d9379d RS |
2237 | if (NILP (window)) |
2238 | window = Fget_buffer_window (buffer, make_number (0)); | |
cee67da9 RS |
2239 | if (NILP (window)) |
2240 | window = Fget_largest_window (make_number (0)); | |
2241 | /* Try invisible frames. */ | |
48d9379d RS |
2242 | if (NILP (window)) |
2243 | window = Fget_buffer_window (buffer, Qt); | |
cee67da9 RS |
2244 | if (NILP (window)) |
2245 | window = Fget_largest_window (Qt); | |
2246 | /* As a last resort, make a new frame. */ | |
2247 | if (NILP (window)) | |
2248 | window = Fframe_selected_window (call0 (Vpop_up_frame_function)); | |
1942f68f RS |
2249 | /* If window appears above or below another, |
2250 | even out their heights. */ | |
cac66e4f | 2251 | other = upper = lower = Qnil; |
1942f68f RS |
2252 | if (!NILP (XWINDOW (window)->prev)) |
2253 | other = upper = XWINDOW (window)->prev, lower = window; | |
2254 | if (!NILP (XWINDOW (window)->next)) | |
2255 | other = lower = XWINDOW (window)->next, upper = window; | |
2256 | if (!NILP (other) | |
2257 | /* Check that OTHER and WINDOW are vertically arrayed. */ | |
296b535c KH |
2258 | && !EQ (XWINDOW (other)->top, XWINDOW (window)->top) |
2259 | && (XFASTINT (XWINDOW (other)->height) | |
2260 | > XFASTINT (XWINDOW (window)->height))) | |
1942f68f | 2261 | { |
296b535c KH |
2262 | int total = (XFASTINT (XWINDOW (other)->height) |
2263 | + XFASTINT (XWINDOW (window)->height)); | |
8d77c0c8 KH |
2264 | Lisp_Object old_selected_window; |
2265 | old_selected_window = selected_window; | |
1942f68f | 2266 | |
8d77c0c8 | 2267 | selected_window = upper; |
296b535c KH |
2268 | change_window_height ((total / 2 |
2269 | - XFASTINT (XWINDOW (upper)->height)), | |
2270 | 0); | |
1942f68f RS |
2271 | selected_window = old_selected_window; |
2272 | } | |
7ab12479 JB |
2273 | } |
2274 | } | |
2275 | else | |
2276 | window = Fget_lru_window (Qnil); | |
2277 | ||
2278 | Fset_window_buffer (window, buffer); | |
d07f802a | 2279 | return display_buffer_1 (window); |
7ab12479 JB |
2280 | } |
2281 | ||
2282 | void | |
2283 | temp_output_buffer_show (buf) | |
2284 | register Lisp_Object buf; | |
2285 | { | |
2286 | register struct buffer *old = current_buffer; | |
2287 | register Lisp_Object window; | |
2288 | register struct window *w; | |
2289 | ||
bccd3dd1 RS |
2290 | XBUFFER (buf)->directory = current_buffer->directory; |
2291 | ||
7ab12479 | 2292 | Fset_buffer (buf); |
c6367666 | 2293 | BUF_SAVE_MODIFF (XBUFFER (buf)) = MODIFF; |
7ab12479 JB |
2294 | BEGV = BEG; |
2295 | ZV = Z; | |
2296 | SET_PT (BEG); | |
1479ef51 | 2297 | XBUFFER (buf)->clip_changed = 1; |
7ab12479 JB |
2298 | set_buffer_internal (old); |
2299 | ||
2300 | if (!EQ (Vtemp_buffer_show_function, Qnil)) | |
2301 | call1 (Vtemp_buffer_show_function, buf); | |
2302 | else | |
2303 | { | |
2304 | window = Fdisplay_buffer (buf, Qnil); | |
2305 | ||
44fa5b1e JB |
2306 | if (XFRAME (XWINDOW (window)->frame) != selected_frame) |
2307 | Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window))); | |
7ab12479 JB |
2308 | Vminibuf_scroll_window = window; |
2309 | w = XWINDOW (window); | |
d834a2e9 | 2310 | XSETFASTINT (w->hscroll, 0); |
b73ea88e RS |
2311 | set_marker_restricted_both (w->start, buf, 1, 1); |
2312 | set_marker_restricted_both (w->pointm, buf, 1, 1); | |
a58ec57d | 2313 | |
37962e60 | 2314 | /* Run temp-buffer-show-hook, with the chosen window selected. */ |
f52cca03 | 2315 | if (!NILP (Vrun_hooks)) |
2cccc823 | 2316 | { |
f52cca03 RS |
2317 | Lisp_Object tem; |
2318 | tem = Fboundp (Qtemp_buffer_show_hook); | |
2cccc823 RS |
2319 | if (!NILP (tem)) |
2320 | { | |
f52cca03 RS |
2321 | tem = Fsymbol_value (Qtemp_buffer_show_hook); |
2322 | if (!NILP (tem)) | |
2323 | { | |
2324 | int count = specpdl_ptr - specpdl; | |
2cccc823 | 2325 | |
f52cca03 RS |
2326 | /* Select the window that was chosen, for running the hook. */ |
2327 | record_unwind_protect (Fset_window_configuration, | |
2328 | Fcurrent_window_configuration (Qnil)); | |
2cccc823 | 2329 | |
f52cca03 RS |
2330 | Fselect_window (window); |
2331 | call1 (Vrun_hooks, Qtemp_buffer_show_hook); | |
2332 | unbind_to (count, Qnil); | |
2333 | } | |
2cccc823 RS |
2334 | } |
2335 | } | |
2336 | } | |
7ab12479 JB |
2337 | } |
2338 | \f | |
2339 | static | |
2340 | make_dummy_parent (window) | |
2341 | Lisp_Object window; | |
2342 | { | |
cffec418 | 2343 | Lisp_Object new; |
7ab12479 | 2344 | register struct window *o, *p; |
cffec418 KH |
2345 | register struct Lisp_Vector *vec; |
2346 | int i; | |
7ab12479 | 2347 | |
cffec418 KH |
2348 | o = XWINDOW (window); |
2349 | vec = allocate_vectorlike ((EMACS_INT)VECSIZE (struct window)); | |
2350 | for (i = 0; i < VECSIZE (struct window); ++i) | |
2351 | vec->contents[i] = ((struct Lisp_Vector *)o)->contents[i]; | |
2352 | vec->size = VECSIZE (struct window); | |
2353 | p = (struct window *)vec; | |
2354 | XSETWINDOW (new, p); | |
7ab12479 | 2355 | |
d834a2e9 | 2356 | XSETFASTINT (p->sequence_number, ++sequence_number); |
7ab12479 JB |
2357 | |
2358 | /* Put new into window structure in place of window */ | |
2359 | replace_window (window, new); | |
2360 | ||
2361 | o->next = Qnil; | |
2362 | o->prev = Qnil; | |
2363 | o->vchild = Qnil; | |
2364 | o->hchild = Qnil; | |
2365 | o->parent = new; | |
2366 | ||
2367 | p->start = Qnil; | |
2368 | p->pointm = Qnil; | |
2369 | p->buffer = Qnil; | |
2370 | } | |
2371 | ||
2372 | DEFUN ("split-window", Fsplit_window, Ssplit_window, 0, 3, "", | |
2373 | "Split WINDOW, putting SIZE lines in the first of the pair.\n\ | |
2374 | WINDOW defaults to selected one and SIZE to half its size.\n\ | |
77ae0fe3 | 2375 | If optional third arg HORFLAG is non-nil, split side by side\n\ |
7ab12479 | 2376 | and put SIZE columns in the first of the pair.") |
77ae0fe3 KH |
2377 | (window, size, horflag) |
2378 | Lisp_Object window, size, horflag; | |
7ab12479 JB |
2379 | { |
2380 | register Lisp_Object new; | |
2381 | register struct window *o, *p; | |
c0807608 | 2382 | FRAME_PTR fo; |
77ae0fe3 | 2383 | register int size_int; |
7ab12479 | 2384 | |
265a9e55 | 2385 | if (NILP (window)) |
7ab12479 JB |
2386 | window = selected_window; |
2387 | else | |
605be8af | 2388 | CHECK_LIVE_WINDOW (window, 0); |
7ab12479 JB |
2389 | |
2390 | o = XWINDOW (window); | |
c0807608 | 2391 | fo = XFRAME (WINDOW_FRAME (o)); |
7ab12479 | 2392 | |
77ae0fe3 | 2393 | if (NILP (size)) |
7ab12479 | 2394 | { |
265a9e55 | 2395 | if (!NILP (horflag)) |
c0807608 KH |
2396 | /* Calculate the size of the left-hand window, by dividing |
2397 | the usable space in columns by two. */ | |
a59fed7e | 2398 | size_int = XFASTINT (o->width) >> 1; |
7ab12479 | 2399 | else |
77ae0fe3 | 2400 | size_int = XFASTINT (o->height) >> 1; |
7ab12479 JB |
2401 | } |
2402 | else | |
2403 | { | |
77ae0fe3 KH |
2404 | CHECK_NUMBER (size, 1); |
2405 | size_int = XINT (size); | |
7ab12479 JB |
2406 | } |
2407 | ||
2408 | if (MINI_WINDOW_P (o)) | |
2409 | error ("Attempt to split minibuffer window"); | |
7ab12479 | 2410 | |
a481b3ea | 2411 | check_min_window_sizes (); |
7ab12479 | 2412 | |
265a9e55 | 2413 | if (NILP (horflag)) |
7ab12479 | 2414 | { |
77ae0fe3 KH |
2415 | if (size_int < window_min_height) |
2416 | error ("Window height %d too small (after splitting)", size_int); | |
2417 | if (size_int + window_min_height > XFASTINT (o->height)) | |
37962e60 | 2418 | error ("Window height %d too small (after splitting)", |
77ae0fe3 | 2419 | XFASTINT (o->height) - size_int); |
265a9e55 JB |
2420 | if (NILP (o->parent) |
2421 | || NILP (XWINDOW (o->parent)->vchild)) | |
7ab12479 JB |
2422 | { |
2423 | make_dummy_parent (window); | |
2424 | new = o->parent; | |
2425 | XWINDOW (new)->vchild = window; | |
2426 | } | |
2427 | } | |
2428 | else | |
2429 | { | |
77ae0fe3 KH |
2430 | if (size_int < window_min_width) |
2431 | error ("Window width %d too small (after splitting)", size_int); | |
a59fed7e RS |
2432 | |
2433 | if (size_int + window_min_width > XFASTINT (o->width)) | |
37962e60 | 2434 | error ("Window width %d too small (after splitting)", |
a59fed7e | 2435 | XFASTINT (o->width) - size_int); |
265a9e55 JB |
2436 | if (NILP (o->parent) |
2437 | || NILP (XWINDOW (o->parent)->hchild)) | |
7ab12479 JB |
2438 | { |
2439 | make_dummy_parent (window); | |
2440 | new = o->parent; | |
2441 | XWINDOW (new)->hchild = window; | |
2442 | } | |
2443 | } | |
2444 | ||
2445 | /* Now we know that window's parent is a vertical combination | |
2446 | if we are dividing vertically, or a horizontal combination | |
2447 | if we are making side-by-side windows */ | |
2448 | ||
2449 | windows_or_buffers_changed++; | |
c0807608 | 2450 | FRAME_WINDOW_SIZES_CHANGED (fo) = 1; |
7ab12479 JB |
2451 | new = make_window (); |
2452 | p = XWINDOW (new); | |
2453 | ||
44fa5b1e | 2454 | p->frame = o->frame; |
7ab12479 | 2455 | p->next = o->next; |
265a9e55 | 2456 | if (!NILP (p->next)) |
7ab12479 JB |
2457 | XWINDOW (p->next)->prev = new; |
2458 | p->prev = window; | |
2459 | o->next = new; | |
2460 | p->parent = o->parent; | |
2461 | p->buffer = Qt; | |
2462 | ||
44fa5b1e | 2463 | /* Apportion the available frame space among the two new windows */ |
7ab12479 | 2464 | |
265a9e55 | 2465 | if (!NILP (horflag)) |
7ab12479 JB |
2466 | { |
2467 | p->height = o->height; | |
2468 | p->top = o->top; | |
a59fed7e | 2469 | XSETFASTINT (p->width, XFASTINT (o->width) - size_int); |
77ae0fe3 KH |
2470 | XSETFASTINT (o->width, size_int); |
2471 | XSETFASTINT (p->left, XFASTINT (o->left) + size_int); | |
7ab12479 JB |
2472 | } |
2473 | else | |
2474 | { | |
2475 | p->left = o->left; | |
2476 | p->width = o->width; | |
77ae0fe3 KH |
2477 | XSETFASTINT (p->height, XFASTINT (o->height) - size_int); |
2478 | XSETFASTINT (o->height, size_int); | |
2479 | XSETFASTINT (p->top, XFASTINT (o->top) + size_int); | |
7ab12479 JB |
2480 | } |
2481 | ||
543f5fb1 RS |
2482 | Fset_window_buffer (new, o->buffer); |
2483 | ||
7ab12479 JB |
2484 | return new; |
2485 | } | |
2486 | \f | |
2487 | DEFUN ("enlarge-window", Fenlarge_window, Senlarge_window, 1, 2, "p", | |
2488 | "Make current window ARG lines bigger.\n\ | |
2489 | From program, optional second arg non-nil means grow sideways ARG columns.") | |
413430c5 EN |
2490 | (arg, side) |
2491 | register Lisp_Object arg, side; | |
7ab12479 | 2492 | { |
413430c5 EN |
2493 | CHECK_NUMBER (arg, 0); |
2494 | change_window_height (XINT (arg), !NILP (side)); | |
543f5fb1 RS |
2495 | |
2496 | if (! NILP (Vwindow_configuration_change_hook)) | |
2497 | call1 (Vrun_hooks, Qwindow_configuration_change_hook); | |
2498 | ||
7ab12479 JB |
2499 | return Qnil; |
2500 | } | |
2501 | ||
2502 | DEFUN ("shrink-window", Fshrink_window, Sshrink_window, 1, 2, "p", | |
2503 | "Make current window ARG lines smaller.\n\ | |
413430c5 EN |
2504 | From program, optional second arg non-nil means shrink sideways arg columns.") |
2505 | (arg, side) | |
2506 | register Lisp_Object arg, side; | |
7ab12479 | 2507 | { |
413430c5 EN |
2508 | CHECK_NUMBER (arg, 0); |
2509 | change_window_height (-XINT (arg), !NILP (side)); | |
543f5fb1 RS |
2510 | |
2511 | if (! NILP (Vwindow_configuration_change_hook)) | |
2512 | call1 (Vrun_hooks, Qwindow_configuration_change_hook); | |
2513 | ||
7ab12479 JB |
2514 | return Qnil; |
2515 | } | |
2516 | ||
2517 | int | |
2518 | window_height (window) | |
2519 | Lisp_Object window; | |
2520 | { | |
2521 | register struct window *p = XWINDOW (window); | |
2522 | return XFASTINT (p->height); | |
2523 | } | |
2524 | ||
2525 | int | |
2526 | window_width (window) | |
2527 | Lisp_Object window; | |
2528 | { | |
2529 | register struct window *p = XWINDOW (window); | |
2530 | return XFASTINT (p->width); | |
2531 | } | |
2532 | ||
05c2896a JB |
2533 | #define MINSIZE(w) \ |
2534 | (widthflag \ | |
2535 | ? window_min_width \ | |
2536 | : (MINI_WINDOW_P (XWINDOW (w)) ? 1 : window_min_height)) | |
7ab12479 JB |
2537 | |
2538 | #define CURBEG(w) \ | |
05c2896a | 2539 | *(widthflag ? (int *) &(XWINDOW (w)->left) : (int *) &(XWINDOW (w)->top)) |
7ab12479 JB |
2540 | |
2541 | #define CURSIZE(w) \ | |
05c2896a | 2542 | *(widthflag ? (int *) &(XWINDOW (w)->width) : (int *) &(XWINDOW (w)->height)) |
7ab12479 JB |
2543 | |
2544 | /* Unlike set_window_height, this function | |
2545 | also changes the heights of the siblings so as to | |
2546 | keep everything consistent. */ | |
2547 | ||
5e14b1fc | 2548 | void |
7ab12479 JB |
2549 | change_window_height (delta, widthflag) |
2550 | register int delta; | |
2551 | int widthflag; | |
2552 | { | |
2553 | register Lisp_Object parent; | |
2554 | Lisp_Object window; | |
2555 | register struct window *p; | |
2556 | int *sizep; | |
5e14b1fc AS |
2557 | int (*sizefun) P_ ((Lisp_Object)) |
2558 | = widthflag ? window_width : window_height; | |
2559 | register void (*setsizefun) P_ ((Lisp_Object, int, int)) | |
2560 | = (widthflag ? set_window_width : set_window_height); | |
db98a733 RS |
2561 | int maximum; |
2562 | Lisp_Object next, prev; | |
7ab12479 | 2563 | |
a481b3ea | 2564 | check_min_window_sizes (); |
7ab12479 JB |
2565 | |
2566 | window = selected_window; | |
2567 | while (1) | |
2568 | { | |
2569 | p = XWINDOW (window); | |
2570 | parent = p->parent; | |
265a9e55 | 2571 | if (NILP (parent)) |
7ab12479 JB |
2572 | { |
2573 | if (widthflag) | |
2574 | error ("No other window to side of this one"); | |
2575 | break; | |
2576 | } | |
265a9e55 JB |
2577 | if (widthflag ? !NILP (XWINDOW (parent)->hchild) |
2578 | : !NILP (XWINDOW (parent)->vchild)) | |
7ab12479 JB |
2579 | break; |
2580 | window = parent; | |
2581 | } | |
2582 | ||
05c2896a | 2583 | sizep = &CURSIZE (window); |
7ab12479 | 2584 | |
7ab12479 JB |
2585 | { |
2586 | register int maxdelta; | |
7ab12479 | 2587 | |
265a9e55 JB |
2588 | maxdelta = (!NILP (parent) ? (*sizefun) (parent) - *sizep |
2589 | : !NILP (p->next) ? (*sizefun) (p->next) - MINSIZE (p->next) | |
2590 | : !NILP (p->prev) ? (*sizefun) (p->prev) - MINSIZE (p->prev) | |
44fa5b1e JB |
2591 | /* This is a frame with only one window, a minibuffer-only |
2592 | or a minibufferless frame. */ | |
d5783c40 | 2593 | : (delta = 0)); |
7ab12479 JB |
2594 | |
2595 | if (delta > maxdelta) | |
2596 | /* This case traps trying to make the minibuffer | |
44fa5b1e JB |
2597 | the full frame, or make the only window aside from the |
2598 | minibuffer the full frame. */ | |
7ab12479 | 2599 | delta = maxdelta; |
6b54027b | 2600 | } |
d5783c40 | 2601 | |
6b54027b RS |
2602 | if (*sizep + delta < MINSIZE (window)) |
2603 | { | |
543f5fb1 | 2604 | delete_window (window); |
d5783c40 | 2605 | return; |
6b54027b RS |
2606 | } |
2607 | ||
2608 | if (delta == 0) | |
2609 | return; | |
7ab12479 | 2610 | |
db98a733 RS |
2611 | /* Find the total we can get from other siblings. */ |
2612 | maximum = 0; | |
2613 | for (next = p->next; ! NILP (next); next = XWINDOW (next)->next) | |
2614 | maximum += (*sizefun) (next) - MINSIZE (next); | |
2615 | for (prev = p->prev; ! NILP (prev); prev = XWINDOW (prev)->prev) | |
2616 | maximum += (*sizefun) (prev) - MINSIZE (prev); | |
2617 | ||
2618 | /* If we can get it all from them, do so. */ | |
c6b530ed | 2619 | if (delta <= maximum) |
7ab12479 | 2620 | { |
db98a733 RS |
2621 | Lisp_Object first_unaffected; |
2622 | Lisp_Object first_affected; | |
2623 | ||
2624 | next = p->next; | |
2625 | prev = p->prev; | |
2626 | first_affected = window; | |
2627 | /* Look at one sibling at a time, | |
2628 | moving away from this window in both directions alternately, | |
2629 | and take as much as we can get without deleting that sibling. */ | |
dc91fb5d | 2630 | while (delta != 0) |
db98a733 RS |
2631 | { |
2632 | if (delta == 0) | |
2633 | break; | |
2634 | if (! NILP (next)) | |
2635 | { | |
2636 | int this_one = (*sizefun) (next) - MINSIZE (next); | |
2637 | if (this_one > delta) | |
2638 | this_one = delta; | |
2639 | ||
2640 | (*setsizefun) (next, (*sizefun) (next) - this_one, 0); | |
2641 | (*setsizefun) (window, *sizep + this_one, 0); | |
2642 | ||
2643 | delta -= this_one; | |
2644 | next = XWINDOW (next)->next; | |
2645 | } | |
2646 | if (delta == 0) | |
2647 | break; | |
2648 | if (! NILP (prev)) | |
2649 | { | |
2650 | int this_one = (*sizefun) (prev) - MINSIZE (prev); | |
2651 | if (this_one > delta) | |
2652 | this_one = delta; | |
2653 | ||
2654 | first_affected = prev; | |
2655 | ||
2656 | (*setsizefun) (prev, (*sizefun) (prev) - this_one, 0); | |
2657 | (*setsizefun) (window, *sizep + this_one, 0); | |
2658 | ||
2659 | delta -= this_one; | |
2660 | prev = XWINDOW (prev)->prev; | |
2661 | } | |
2662 | } | |
2663 | ||
2664 | /* Now recalculate the edge positions of all the windows affected, | |
2665 | based on the new sizes. */ | |
2666 | first_unaffected = next; | |
2667 | prev = first_affected; | |
2668 | for (next = XWINDOW (prev)->next; ! EQ (next, first_unaffected); | |
2669 | prev = next, next = XWINDOW (next)->next) | |
2670 | { | |
2671 | CURBEG (next) = CURBEG (prev) + (*sizefun) (prev); | |
2672 | /* This does not change size of NEXT, | |
2673 | but it propagates the new top edge to its children */ | |
2674 | (*setsizefun) (next, (*sizefun) (next), 0); | |
2675 | } | |
7ab12479 JB |
2676 | } |
2677 | else | |
2678 | { | |
2679 | register int delta1; | |
2680 | register int opht = (*sizefun) (parent); | |
2681 | ||
2682 | /* If trying to grow this window to or beyond size of the parent, | |
2683 | make delta1 so big that, on shrinking back down, | |
2684 | all the siblings end up with less than one line and are deleted. */ | |
2685 | if (opht <= *sizep + delta) | |
2686 | delta1 = opht * opht * 2; | |
2687 | /* Otherwise, make delta1 just right so that if we add delta1 | |
2688 | lines to this window and to the parent, and then shrink | |
2689 | the parent back to its original size, the new proportional | |
2690 | size of this window will increase by delta. */ | |
2691 | else | |
2692 | delta1 = (delta * opht * 100) / ((opht - *sizep - delta) * 100); | |
2693 | ||
2694 | /* Add delta1 lines or columns to this window, and to the parent, | |
2695 | keeping things consistent while not affecting siblings. */ | |
05c2896a | 2696 | CURSIZE (parent) = opht + delta1; |
7ab12479 JB |
2697 | (*setsizefun) (window, *sizep + delta1, 0); |
2698 | ||
2699 | /* Squeeze out delta1 lines or columns from our parent, | |
2700 | shriking this window and siblings proportionately. | |
2701 | This brings parent back to correct size. | |
2702 | Delta1 was calculated so this makes this window the desired size, | |
2703 | taking it all out of the siblings. */ | |
2704 | (*setsizefun) (parent, opht, 0); | |
2705 | } | |
2706 | ||
d834a2e9 | 2707 | XSETFASTINT (p->last_modified, 0); |
3cd21523 | 2708 | XSETFASTINT (p->last_overlay_modified, 0); |
7ab12479 JB |
2709 | } |
2710 | #undef MINSIZE | |
2711 | #undef CURBEG | |
2712 | #undef CURSIZE | |
2713 | ||
2714 | \f | |
2715 | /* Return number of lines of text (not counting mode line) in W. */ | |
2716 | ||
2717 | int | |
2718 | window_internal_height (w) | |
2719 | struct window *w; | |
2720 | { | |
2721 | int ht = XFASTINT (w->height); | |
2722 | ||
2723 | if (MINI_WINDOW_P (w)) | |
2724 | return ht; | |
2725 | ||
265a9e55 JB |
2726 | if (!NILP (w->parent) || !NILP (w->vchild) || !NILP (w->hchild) |
2727 | || !NILP (w->next) || !NILP (w->prev) | |
44fa5b1e | 2728 | || FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (w)))) |
7ab12479 JB |
2729 | return ht - 1; |
2730 | ||
2731 | return ht; | |
2732 | } | |
2733 | ||
535e0b8e JB |
2734 | |
2735 | /* Return the number of columns in W. | |
a3c87d4e | 2736 | Don't count columns occupied by scroll bars or the vertical bar |
535e0b8e JB |
2737 | separating W from the sibling to its right. */ |
2738 | int | |
2739 | window_internal_width (w) | |
2740 | struct window *w; | |
2741 | { | |
2742 | FRAME_PTR f = XFRAME (WINDOW_FRAME (w)); | |
535e0b8e JB |
2743 | int width = XINT (w->width); |
2744 | ||
a3c87d4e JB |
2745 | /* Scroll bars occupy a few columns. */ |
2746 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
ca0d0bb9 | 2747 | return width - FRAME_SCROLL_BAR_COLS (f); |
535e0b8e JB |
2748 | |
2749 | /* The column of `|' characters separating side-by-side windows | |
2750 | occupies one column only. */ | |
111e5992 RS |
2751 | if (!WINDOW_RIGHTMOST_P (w) && !WINDOW_FULL_WIDTH_P (w)) |
2752 | return width - 1; | |
2753 | ||
2754 | return width; | |
535e0b8e JB |
2755 | } |
2756 | ||
2757 | ||
101d1605 | 2758 | /* Scroll contents of window WINDOW up N lines. |
9317a85d | 2759 | If WHOLE is nonzero, it means scroll N screenfuls instead. */ |
7ab12479 | 2760 | |
101d1605 RS |
2761 | static void |
2762 | window_scroll (window, n, whole, noerror) | |
7ab12479 JB |
2763 | Lisp_Object window; |
2764 | int n; | |
101d1605 | 2765 | int whole; |
f8026fd8 | 2766 | int noerror; |
7ab12479 JB |
2767 | { |
2768 | register struct window *w = XWINDOW (window); | |
5ce7b543 | 2769 | register int opoint = PT; |
b73ea88e RS |
2770 | register int opoint_byte = PT; |
2771 | register int pos, pos_byte; | |
7ab12479 JB |
2772 | register int ht = window_internal_height (w); |
2773 | register Lisp_Object tem; | |
2774 | int lose; | |
2775 | Lisp_Object bolp, nmoved; | |
345d45b2 | 2776 | int startpos; |
101d1605 RS |
2777 | struct position posit; |
2778 | int original_vpos; | |
2779 | ||
2780 | startpos = marker_position (w->start); | |
2781 | ||
2782 | posit = *compute_motion (startpos, 0, 0, 0, | |
2783 | PT, ht, 0, | |
2784 | window_internal_width (w), XINT (w->hscroll), | |
2785 | 0, w); | |
2786 | original_vpos = posit.vpos; | |
0a1f771a | 2787 | |
d834a2e9 | 2788 | XSETFASTINT (tem, PT); |
7ab12479 JB |
2789 | tem = Fpos_visible_in_window_p (tem, window); |
2790 | ||
265a9e55 | 2791 | if (NILP (tem)) |
7ab12479 | 2792 | { |
cd2be1dd | 2793 | Fvertical_motion (make_number (- (ht / 2)), window); |
345d45b2 | 2794 | startpos = PT; |
7ab12479 JB |
2795 | } |
2796 | ||
345d45b2 | 2797 | SET_PT (startpos); |
5ce7b543 | 2798 | lose = n < 0 && PT == BEGV; |
540b6aa0 | 2799 | Fvertical_motion (make_number (n), window); |
5ce7b543 | 2800 | pos = PT; |
b73ea88e | 2801 | pos_byte = PT_BYTE; |
7ab12479 | 2802 | bolp = Fbolp (); |
b73ea88e | 2803 | SET_PT_BOTH (opoint, opoint_byte); |
7ab12479 JB |
2804 | |
2805 | if (lose) | |
f8026fd8 JB |
2806 | { |
2807 | if (noerror) | |
2808 | return; | |
2809 | else | |
2810 | Fsignal (Qbeginning_of_buffer, Qnil); | |
2811 | } | |
7ab12479 JB |
2812 | |
2813 | if (pos < ZV) | |
7ab12479 | 2814 | { |
0c7da84e RS |
2815 | int this_scroll_margin = scroll_margin; |
2816 | ||
2817 | /* Don't use a scroll margin that is negative or too large. */ | |
2818 | if (this_scroll_margin < 0) | |
2819 | this_scroll_margin = 0; | |
2820 | ||
2821 | if (XINT (w->height) < 4 * scroll_margin) | |
2822 | this_scroll_margin = XINT (w->height) / 4; | |
2823 | ||
b73ea88e | 2824 | set_marker_restricted_both (w->start, w->buffer, pos, pos_byte); |
7ab12479 JB |
2825 | w->start_at_line_beg = bolp; |
2826 | w->update_mode_line = Qt; | |
d834a2e9 | 2827 | XSETFASTINT (w->last_modified, 0); |
3cd21523 | 2828 | XSETFASTINT (w->last_overlay_modified, 0); |
345d45b2 RS |
2829 | /* Set force_start so that redisplay_window will run |
2830 | the window-scroll-functions. */ | |
2831 | w->force_start = Qt; | |
0c7da84e | 2832 | |
9317a85d | 2833 | if (whole && scroll_preserve_screen_position) |
0c7da84e | 2834 | { |
b73ea88e | 2835 | SET_PT_BOTH (pos, pos_byte); |
101d1605 | 2836 | Fvertical_motion (make_number (original_vpos), window); |
0c7da84e | 2837 | } |
101d1605 RS |
2838 | /* If we scrolled forward, put point enough lines down |
2839 | that it is outside the scroll margin. */ | |
2840 | else if (n > 0) | |
0c7da84e | 2841 | { |
101d1605 RS |
2842 | int top_margin; |
2843 | ||
2844 | if (this_scroll_margin > 0) | |
2845 | { | |
b73ea88e | 2846 | SET_PT_BOTH (pos, pos_byte); |
101d1605 RS |
2847 | Fvertical_motion (make_number (this_scroll_margin), window); |
2848 | top_margin = PT; | |
2849 | } | |
2850 | else | |
2851 | top_margin = pos; | |
2852 | ||
2853 | if (top_margin <= opoint) | |
b73ea88e | 2854 | SET_PT_BOTH (opoint, opoint_byte); |
9317a85d | 2855 | else if (scroll_preserve_screen_position) |
101d1605 | 2856 | { |
b73ea88e | 2857 | SET_PT_BOTH (pos, pos_byte); |
101d1605 RS |
2858 | Fvertical_motion (make_number (original_vpos), window); |
2859 | } | |
9317a85d | 2860 | else |
335406fc | 2861 | SET_PT (top_margin); |
0c7da84e | 2862 | } |
101d1605 | 2863 | else if (n < 0) |
7ab12479 | 2864 | { |
101d1605 RS |
2865 | int bottom_margin; |
2866 | ||
0c7da84e RS |
2867 | /* If we scrolled backward, put point near the end of the window |
2868 | but not within the scroll margin. */ | |
b73ea88e | 2869 | SET_PT_BOTH (pos, pos_byte); |
0c7da84e | 2870 | tem = Fvertical_motion (make_number (ht - this_scroll_margin), window); |
101d1605 RS |
2871 | if (XFASTINT (tem) == ht - this_scroll_margin) |
2872 | bottom_margin = PT; | |
2873 | else | |
2874 | bottom_margin = PT + 1; | |
2875 | ||
2876 | if (bottom_margin > opoint) | |
b73ea88e | 2877 | SET_PT_BOTH (opoint, opoint_byte); |
7ab12479 | 2878 | else |
101d1605 | 2879 | { |
9317a85d RS |
2880 | if (scroll_preserve_screen_position) |
2881 | { | |
b73ea88e | 2882 | SET_PT_BOTH (pos, pos_byte); |
9317a85d RS |
2883 | Fvertical_motion (make_number (original_vpos), window); |
2884 | } | |
2885 | else | |
2886 | Fvertical_motion (make_number (-1), window); | |
101d1605 | 2887 | } |
7ab12479 JB |
2888 | } |
2889 | } | |
2890 | else | |
f8026fd8 JB |
2891 | { |
2892 | if (noerror) | |
2893 | return; | |
2894 | else | |
2895 | Fsignal (Qend_of_buffer, Qnil); | |
2896 | } | |
7ab12479 JB |
2897 | } |
2898 | \f | |
2899 | /* This is the guts of Fscroll_up and Fscroll_down. */ | |
2900 | ||
2901 | static void | |
2902 | scroll_command (n, direction) | |
2903 | register Lisp_Object n; | |
2904 | int direction; | |
2905 | { | |
2906 | register int defalt; | |
2907 | int count = specpdl_ptr - specpdl; | |
2908 | ||
95605e15 JB |
2909 | /* If selected window's buffer isn't current, make it current for the moment. |
2910 | But don't screw up if window_scroll gets an error. */ | |
7ab12479 | 2911 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) |
95605e15 JB |
2912 | { |
2913 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
2914 | Fset_buffer (XWINDOW (selected_window)->buffer); | |
2915 | } | |
7ab12479 JB |
2916 | |
2917 | defalt = (window_internal_height (XWINDOW (selected_window)) | |
2918 | - next_screen_context_lines); | |
2919 | defalt = direction * (defalt < 1 ? 1 : defalt); | |
2920 | ||
265a9e55 | 2921 | if (NILP (n)) |
101d1605 | 2922 | window_scroll (selected_window, defalt, 1, 0); |
7ab12479 | 2923 | else if (EQ (n, Qminus)) |
101d1605 | 2924 | window_scroll (selected_window, - defalt, 1, 0); |
7ab12479 JB |
2925 | else |
2926 | { | |
2927 | n = Fprefix_numeric_value (n); | |
101d1605 | 2928 | window_scroll (selected_window, XINT (n) * direction, 0, 0); |
7ab12479 | 2929 | } |
95605e15 JB |
2930 | |
2931 | unbind_to (count, Qnil); | |
7ab12479 JB |
2932 | } |
2933 | ||
2934 | DEFUN ("scroll-up", Fscroll_up, Sscroll_up, 0, 1, "P", | |
2935 | "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\ | |
2936 | A near full screen is `next-screen-context-lines' less than a full screen.\n\ | |
279e0e0c | 2937 | Negative ARG means scroll downward.\n\ |
7ab12479 | 2938 | When calling from a program, supply a number as argument or nil.") |
413430c5 EN |
2939 | (arg) |
2940 | Lisp_Object arg; | |
7ab12479 | 2941 | { |
413430c5 | 2942 | scroll_command (arg, 1); |
7ab12479 JB |
2943 | return Qnil; |
2944 | } | |
2945 | ||
2946 | DEFUN ("scroll-down", Fscroll_down, Sscroll_down, 0, 1, "P", | |
2947 | "Scroll text of current window downward ARG lines; or near full screen if no ARG.\n\ | |
2948 | A near full screen is `next-screen-context-lines' less than a full screen.\n\ | |
279e0e0c | 2949 | Negative ARG means scroll upward.\n\ |
7ab12479 | 2950 | When calling from a program, supply a number as argument or nil.") |
413430c5 EN |
2951 | (arg) |
2952 | Lisp_Object arg; | |
7ab12479 | 2953 | { |
413430c5 | 2954 | scroll_command (arg, -1); |
7ab12479 JB |
2955 | return Qnil; |
2956 | } | |
ccd0664b RS |
2957 | \f |
2958 | DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling, Sother_window_for_scrolling, 0, 0, 0, | |
2959 | "Return the other window for \"other window scroll\" commands.\n\ | |
77b24de6 | 2960 | If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\ |
ccd0664b RS |
2961 | specifies the window.\n\ |
2962 | If `other-window-scroll-buffer' is non-nil, a window\n\ | |
2963 | showing that buffer is used.") | |
eb16ec06 | 2964 | () |
7ab12479 | 2965 | { |
ccd0664b | 2966 | Lisp_Object window; |
7ab12479 JB |
2967 | |
2968 | if (MINI_WINDOW_P (XWINDOW (selected_window)) | |
265a9e55 | 2969 | && !NILP (Vminibuf_scroll_window)) |
7ab12479 JB |
2970 | window = Vminibuf_scroll_window; |
2971 | /* If buffer is specified, scroll that buffer. */ | |
265a9e55 | 2972 | else if (!NILP (Vother_window_scroll_buffer)) |
7ab12479 JB |
2973 | { |
2974 | window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil); | |
265a9e55 | 2975 | if (NILP (window)) |
7ab12479 JB |
2976 | window = Fdisplay_buffer (Vother_window_scroll_buffer, Qt); |
2977 | } | |
2978 | else | |
dbc4e1c1 JB |
2979 | { |
2980 | /* Nothing specified; look for a neighboring window on the same | |
2981 | frame. */ | |
2982 | window = Fnext_window (selected_window, Qnil, Qnil); | |
2983 | ||
2984 | if (EQ (window, selected_window)) | |
2985 | /* That didn't get us anywhere; look for a window on another | |
2986 | visible frame. */ | |
2987 | do | |
2988 | window = Fnext_window (window, Qnil, Qt); | |
2989 | while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window)))) | |
2990 | && ! EQ (window, selected_window)); | |
2991 | } | |
2992 | ||
605be8af | 2993 | CHECK_LIVE_WINDOW (window, 0); |
7ab12479 JB |
2994 | |
2995 | if (EQ (window, selected_window)) | |
2996 | error ("There is no other window"); | |
2997 | ||
ccd0664b RS |
2998 | return window; |
2999 | } | |
3000 | ||
3001 | DEFUN ("scroll-other-window", Fscroll_other_window, Sscroll_other_window, 0, 1, "P", | |
3002 | "Scroll next window upward ARG lines; or near full screen if no ARG.\n\ | |
3003 | The next window is the one below the current one; or the one at the top\n\ | |
3004 | if the current one is at the bottom. Negative ARG means scroll downward.\n\ | |
3005 | When calling from a program, supply a number as argument or nil.\n\ | |
3006 | \n\ | |
3007 | If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\ | |
3008 | specifies the window to scroll.\n\ | |
3009 | If `other-window-scroll-buffer' is non-nil, scroll the window\n\ | |
3010 | showing that buffer, popping the buffer up if necessary.") | |
413430c5 EN |
3011 | (arg) |
3012 | register Lisp_Object arg; | |
ccd0664b RS |
3013 | { |
3014 | register Lisp_Object window; | |
2f787aa3 | 3015 | register int defalt; |
ccd0664b RS |
3016 | register struct window *w; |
3017 | register int count = specpdl_ptr - specpdl; | |
3018 | ||
3019 | window = Fother_window_for_scrolling (); | |
3020 | ||
7ab12479 | 3021 | w = XWINDOW (window); |
2f787aa3 KH |
3022 | defalt = window_internal_height (w) - next_screen_context_lines; |
3023 | if (defalt < 1) defalt = 1; | |
7ab12479 JB |
3024 | |
3025 | /* Don't screw up if window_scroll gets an error. */ | |
3026 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
3027 | ||
3028 | Fset_buffer (w->buffer); | |
3029 | SET_PT (marker_position (w->pointm)); | |
3030 | ||
413430c5 | 3031 | if (NILP (arg)) |
101d1605 | 3032 | window_scroll (window, defalt, 1, 1); |
413430c5 | 3033 | else if (EQ (arg, Qminus)) |
101d1605 | 3034 | window_scroll (window, -defalt, 1, 1); |
7ab12479 JB |
3035 | else |
3036 | { | |
413430c5 EN |
3037 | if (CONSP (arg)) |
3038 | arg = Fcar (arg); | |
3039 | CHECK_NUMBER (arg, 0); | |
101d1605 | 3040 | window_scroll (window, XINT (arg), 0, 1); |
7ab12479 JB |
3041 | } |
3042 | ||
b73ea88e | 3043 | set_marker_both (w->pointm, Qnil, PT, PT_BYTE); |
f4e7b2c2 | 3044 | unbind_to (count, Qnil); |
7ab12479 JB |
3045 | |
3046 | return Qnil; | |
3047 | } | |
3048 | \f | |
644b477c | 3049 | DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 1, "P", |
7ab12479 JB |
3050 | "Scroll selected window display ARG columns left.\n\ |
3051 | Default for ARG is window width minus 2.") | |
3052 | (arg) | |
3053 | register Lisp_Object arg; | |
3054 | { | |
3055 | ||
265a9e55 | 3056 | if (NILP (arg)) |
d834a2e9 | 3057 | XSETFASTINT (arg, window_internal_width (XWINDOW (selected_window)) - 2); |
7ab12479 JB |
3058 | else |
3059 | arg = Fprefix_numeric_value (arg); | |
3060 | ||
3061 | return | |
3062 | Fset_window_hscroll (selected_window, | |
3063 | make_number (XINT (XWINDOW (selected_window)->hscroll) | |
3064 | + XINT (arg))); | |
3065 | } | |
3066 | ||
644b477c | 3067 | DEFUN ("scroll-right", Fscroll_right, Sscroll_right, 0, 1, "P", |
7ab12479 JB |
3068 | "Scroll selected window display ARG columns right.\n\ |
3069 | Default for ARG is window width minus 2.") | |
3070 | (arg) | |
3071 | register Lisp_Object arg; | |
3072 | { | |
265a9e55 | 3073 | if (NILP (arg)) |
d834a2e9 | 3074 | XSETFASTINT (arg, window_internal_width (XWINDOW (selected_window)) - 2); |
7ab12479 JB |
3075 | else |
3076 | arg = Fprefix_numeric_value (arg); | |
3077 | ||
3078 | return | |
3079 | Fset_window_hscroll (selected_window, | |
3080 | make_number (XINT (XWINDOW (selected_window)->hscroll) | |
3081 | - XINT (arg))); | |
3082 | } | |
3083 | ||
3084 | DEFUN ("recenter", Frecenter, Srecenter, 0, 1, "P", | |
44fa5b1e | 3085 | "Center point in window and redisplay frame. With ARG, put point on line ARG.\n\ |
7ab12479 | 3086 | The desired position of point is always relative to the current window.\n\ |
44fa5b1e | 3087 | Just C-u as prefix means put point in the center of the window.\n\ |
413430c5 | 3088 | If ARG is omitted or nil, erases the entire frame and then\n\ |
44fa5b1e | 3089 | redraws with point in the center of the current window.") |
413430c5 EN |
3090 | (arg) |
3091 | register Lisp_Object arg; | |
7ab12479 JB |
3092 | { |
3093 | register struct window *w = XWINDOW (selected_window); | |
3094 | register int ht = window_internal_height (w); | |
113d9015 | 3095 | struct position pos; |
7ab12479 | 3096 | |
413430c5 | 3097 | if (NILP (arg)) |
7ab12479 | 3098 | { |
44fa5b1e | 3099 | extern int frame_garbaged; |
7ab12479 | 3100 | |
44fa5b1e | 3101 | SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w))); |
413430c5 | 3102 | XSETFASTINT (arg, ht / 2); |
7ab12479 | 3103 | } |
413430c5 | 3104 | else if (CONSP (arg)) /* Just C-u. */ |
7ab12479 | 3105 | { |
413430c5 | 3106 | XSETFASTINT (arg, ht / 2); |
7ab12479 JB |
3107 | } |
3108 | else | |
3109 | { | |
413430c5 EN |
3110 | arg = Fprefix_numeric_value (arg); |
3111 | CHECK_NUMBER (arg, 0); | |
7ab12479 JB |
3112 | } |
3113 | ||
413430c5 EN |
3114 | if (XINT (arg) < 0) |
3115 | XSETINT (arg, XINT (arg) + ht); | |
7ab12479 | 3116 | |
6ec8bbd2 | 3117 | pos = *vmotion (PT, - XINT (arg), w); |
7ab12479 | 3118 | |
b73ea88e RS |
3119 | set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos); |
3120 | w->start_at_line_beg = ((pos.bytepos == BEGV_BYTE | |
3121 | || FETCH_BYTE (pos.bytepos - 1) == '\n') | |
113d9015 | 3122 | ? Qt : Qnil); |
7ab12479 JB |
3123 | w->force_start = Qt; |
3124 | ||
3125 | return Qnil; | |
3126 | } | |
3127 | \f | |
3128 | DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line, | |
3129 | 1, 1, "P", | |
3130 | "Position point relative to window.\n\ | |
19e3bf0a | 3131 | With no argument, position point at center of window.\n\ |
44fa5b1e | 3132 | An argument specifies frame line; zero means top of window,\n\ |
7ab12479 JB |
3133 | negative means relative to bottom of window.") |
3134 | (arg) | |
3135 | register Lisp_Object arg; | |
3136 | { | |
3137 | register struct window *w = XWINDOW (selected_window); | |
3138 | register int height = window_internal_height (w); | |
3139 | register int start; | |
540b6aa0 | 3140 | Lisp_Object window; |
7ab12479 | 3141 | |
265a9e55 | 3142 | if (NILP (arg)) |
d834a2e9 | 3143 | XSETFASTINT (arg, height / 2); |
7ab12479 JB |
3144 | else |
3145 | { | |
3146 | arg = Fprefix_numeric_value (arg); | |
3147 | if (XINT (arg) < 0) | |
3148 | XSETINT (arg, XINT (arg) + height); | |
3149 | } | |
3150 | ||
3151 | start = marker_position (w->start); | |
74112613 | 3152 | XSETWINDOW (window, w); |
7ab12479 JB |
3153 | if (start < BEGV || start > ZV) |
3154 | { | |
cd2be1dd | 3155 | Fvertical_motion (make_number (- (height / 2)), window); |
b73ea88e | 3156 | set_marker_both (w->start, w->buffer, PT, PT_BYTE); |
7ab12479 JB |
3157 | w->start_at_line_beg = Fbolp (); |
3158 | w->force_start = Qt; | |
3159 | } | |
3160 | else | |
b73ea88e | 3161 | Fgoto_char (w->start); |
7ab12479 | 3162 | |
540b6aa0 | 3163 | return Fvertical_motion (arg, window); |
7ab12479 JB |
3164 | } |
3165 | \f | |
3166 | struct save_window_data | |
3167 | { | |
f5ccc0cc | 3168 | EMACS_INT size_from_Lisp_Vector_struct; |
7ab12479 | 3169 | struct Lisp_Vector *next_from_Lisp_Vector_struct; |
8f6ea2e9 | 3170 | Lisp_Object frame_width, frame_height, frame_menu_bar_lines; |
bdc727bf | 3171 | Lisp_Object selected_frame; |
7ab12479 JB |
3172 | Lisp_Object current_window; |
3173 | Lisp_Object current_buffer; | |
3174 | Lisp_Object minibuf_scroll_window; | |
3175 | Lisp_Object root_window; | |
bdc727bf | 3176 | Lisp_Object focus_frame; |
756b6edc RS |
3177 | /* Record the values of window-min-width and window-min-height |
3178 | so that window sizes remain consistent with them. */ | |
3179 | Lisp_Object min_width, min_height; | |
7ab12479 JB |
3180 | /* A vector, interpreted as a struct saved_window */ |
3181 | Lisp_Object saved_windows; | |
3182 | }; | |
ff06df24 | 3183 | |
7ab12479 JB |
3184 | /* This is saved as a Lisp_Vector */ |
3185 | struct saved_window | |
3186 | { | |
3187 | /* these first two must agree with struct Lisp_Vector in lisp.h */ | |
f5ccc0cc | 3188 | EMACS_INT size_from_Lisp_Vector_struct; |
7ab12479 JB |
3189 | struct Lisp_Vector *next_from_Lisp_Vector_struct; |
3190 | ||
3191 | Lisp_Object window; | |
3192 | Lisp_Object buffer, start, pointm, mark; | |
3193 | Lisp_Object left, top, width, height, hscroll; | |
3194 | Lisp_Object parent, prev; | |
3195 | Lisp_Object start_at_line_beg; | |
3196 | Lisp_Object display_table; | |
3197 | }; | |
3198 | #define SAVED_WINDOW_VECTOR_SIZE 14 /* Arg to Fmake_vector */ | |
3199 | ||
3200 | #define SAVED_WINDOW_N(swv,n) \ | |
3201 | ((struct saved_window *) (XVECTOR ((swv)->contents[(n)]))) | |
3202 | ||
3203 | DEFUN ("window-configuration-p", Fwindow_configuration_p, Swindow_configuration_p, 1, 1, 0, | |
5c4d25a6 | 3204 | "T if OBJECT is a window-configuration object.") |
413430c5 EN |
3205 | (object) |
3206 | Lisp_Object object; | |
7ab12479 | 3207 | { |
413430c5 | 3208 | if (WINDOW_CONFIGURATIONP (object)) |
7ab12479 JB |
3209 | return Qt; |
3210 | return Qnil; | |
3211 | } | |
3212 | ||
3213 | ||
d5b2799e RS |
3214 | DEFUN ("set-window-configuration", Fset_window_configuration, |
3215 | Sset_window_configuration, 1, 1, 0, | |
7ab12479 JB |
3216 | "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\ |
3217 | CONFIGURATION must be a value previously returned\n\ | |
3218 | by `current-window-configuration' (which see).") | |
2f83aebe JB |
3219 | (configuration) |
3220 | Lisp_Object configuration; | |
7ab12479 | 3221 | { |
7ab12479 JB |
3222 | register struct save_window_data *data; |
3223 | struct Lisp_Vector *saved_windows; | |
7ab12479 | 3224 | Lisp_Object new_current_buffer; |
fd482be5 | 3225 | Lisp_Object frame; |
44fa5b1e | 3226 | FRAME_PTR f; |
d2b35234 | 3227 | int old_point = -1; |
7ab12479 | 3228 | |
017b2bad | 3229 | while (!WINDOW_CONFIGURATIONP (configuration)) |
7ab12479 | 3230 | { |
2f83aebe JB |
3231 | configuration = wrong_type_argument (intern ("window-configuration-p"), |
3232 | configuration); | |
7ab12479 JB |
3233 | } |
3234 | ||
2f83aebe | 3235 | data = (struct save_window_data *) XVECTOR (configuration); |
7ab12479 JB |
3236 | saved_windows = XVECTOR (data->saved_windows); |
3237 | ||
7ab12479 | 3238 | new_current_buffer = data->current_buffer; |
265a9e55 | 3239 | if (NILP (XBUFFER (new_current_buffer)->name)) |
7ab12479 | 3240 | new_current_buffer = Qnil; |
d2b35234 RS |
3241 | else |
3242 | { | |
3243 | if (XBUFFER (new_current_buffer) == current_buffer) | |
3244 | old_point = PT; | |
3245 | } | |
7ab12479 | 3246 | |
fd482be5 JB |
3247 | frame = XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame; |
3248 | f = XFRAME (frame); | |
9ace597f | 3249 | |
fd482be5 JB |
3250 | /* If f is a dead frame, don't bother rebuilding its window tree. |
3251 | However, there is other stuff we should still try to do below. */ | |
3252 | if (FRAME_LIVE_P (f)) | |
7ab12479 | 3253 | { |
fd482be5 JB |
3254 | register struct window *w; |
3255 | register struct saved_window *p; | |
3256 | int k; | |
3257 | ||
3258 | /* If the frame has been resized since this window configuration was | |
3259 | made, we change the frame to the size specified in the | |
3260 | configuration, restore the configuration, and then resize it | |
3261 | back. We keep track of the prevailing height in these variables. */ | |
3262 | int previous_frame_height = FRAME_HEIGHT (f); | |
3263 | int previous_frame_width = FRAME_WIDTH (f); | |
8f6ea2e9 | 3264 | int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f); |
fd482be5 | 3265 | |
d2b35234 RS |
3266 | /* The mouse highlighting code could get screwed up |
3267 | if it runs during this. */ | |
3268 | BLOCK_INPUT; | |
3269 | ||
fd482be5 JB |
3270 | if (XFASTINT (data->frame_height) != previous_frame_height |
3271 | || XFASTINT (data->frame_width) != previous_frame_width) | |
3272 | change_frame_size (f, data->frame_height, data->frame_width, 0, 0); | |
e3678b64 | 3273 | #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS) |
8f6ea2e9 KH |
3274 | if (XFASTINT (data->frame_menu_bar_lines) |
3275 | != previous_frame_menu_bar_lines) | |
3276 | x_set_menu_bar_lines (f, data->frame_menu_bar_lines, 0); | |
217f2871 | 3277 | #endif |
fd482be5 | 3278 | |
596ae0cf RS |
3279 | if (! NILP (XWINDOW (selected_window)->buffer)) |
3280 | { | |
3281 | w = XWINDOW (selected_window); | |
3282 | set_marker_both (w->pointm, | |
3283 | w->buffer, | |
3284 | BUF_PT (XBUFFER (w->buffer)), | |
3285 | BUF_PT_BYTE (XBUFFER (w->buffer))); | |
3286 | } | |
3287 | ||
fd482be5 | 3288 | windows_or_buffers_changed++; |
29aeee73 | 3289 | FRAME_WINDOW_SIZES_CHANGED (f) = 1; |
fd482be5 | 3290 | |
756b6edc RS |
3291 | /* Temporarily avoid any problems with windows that are smaller |
3292 | than they are supposed to be. */ | |
3293 | window_min_height = 1; | |
3294 | window_min_width = 1; | |
3295 | ||
fd482be5 JB |
3296 | /* Kludge Alert! |
3297 | Mark all windows now on frame as "deleted". | |
3298 | Restoring the new configuration "undeletes" any that are in it. | |
37962e60 | 3299 | |
fd482be5 JB |
3300 | Save their current buffers in their height fields, since we may |
3301 | need it later, if a buffer saved in the configuration is now | |
3302 | dead. */ | |
3303 | delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f))); | |
3304 | ||
3305 | for (k = 0; k < saved_windows->size; k++) | |
3306 | { | |
3307 | p = SAVED_WINDOW_N (saved_windows, k); | |
3308 | w = XWINDOW (p->window); | |
3309 | w->next = Qnil; | |
7ab12479 | 3310 | |
fd482be5 JB |
3311 | if (!NILP (p->parent)) |
3312 | w->parent = SAVED_WINDOW_N (saved_windows, | |
3313 | XFASTINT (p->parent))->window; | |
3314 | else | |
3315 | w->parent = Qnil; | |
7ab12479 | 3316 | |
fd482be5 | 3317 | if (!NILP (p->prev)) |
7ab12479 | 3318 | { |
fd482be5 JB |
3319 | w->prev = SAVED_WINDOW_N (saved_windows, |
3320 | XFASTINT (p->prev))->window; | |
3321 | XWINDOW (w->prev)->next = p->window; | |
3322 | } | |
3323 | else | |
3324 | { | |
3325 | w->prev = Qnil; | |
3326 | if (!NILP (w->parent)) | |
3327 | { | |
3328 | if (EQ (p->width, XWINDOW (w->parent)->width)) | |
3329 | { | |
3330 | XWINDOW (w->parent)->vchild = p->window; | |
3331 | XWINDOW (w->parent)->hchild = Qnil; | |
3332 | } | |
3333 | else | |
3334 | { | |
3335 | XWINDOW (w->parent)->hchild = p->window; | |
3336 | XWINDOW (w->parent)->vchild = Qnil; | |
3337 | } | |
3338 | } | |
3339 | } | |
3340 | ||
3341 | /* If we squirreled away the buffer in the window's height, | |
3342 | restore it now. */ | |
017b2bad | 3343 | if (BUFFERP (w->height)) |
fd482be5 JB |
3344 | w->buffer = w->height; |
3345 | w->left = p->left; | |
3346 | w->top = p->top; | |
3347 | w->width = p->width; | |
3348 | w->height = p->height; | |
3349 | w->hscroll = p->hscroll; | |
3350 | w->display_table = p->display_table; | |
d834a2e9 | 3351 | XSETFASTINT (w->last_modified, 0); |
3cd21523 | 3352 | XSETFASTINT (w->last_overlay_modified, 0); |
fd482be5 JB |
3353 | |
3354 | /* Reinstall the saved buffer and pointers into it. */ | |
3355 | if (NILP (p->buffer)) | |
3356 | w->buffer = p->buffer; | |
3357 | else | |
3358 | { | |
3359 | if (!NILP (XBUFFER (p->buffer)->name)) | |
3360 | /* If saved buffer is alive, install it. */ | |
3361 | { | |
3362 | w->buffer = p->buffer; | |
3363 | w->start_at_line_beg = p->start_at_line_beg; | |
b73ea88e RS |
3364 | set_marker_restricted (w->start, p->start, w->buffer); |
3365 | set_marker_restricted (w->pointm, p->pointm, w->buffer); | |
fd482be5 | 3366 | Fset_marker (XBUFFER (w->buffer)->mark, |
b73ea88e | 3367 | p->mark, w->buffer); |
fd482be5 JB |
3368 | |
3369 | /* As documented in Fcurrent_window_configuration, don't | |
3370 | save the location of point in the buffer which was current | |
3371 | when the window configuration was recorded. */ | |
6b54027b RS |
3372 | if (!EQ (p->buffer, new_current_buffer) |
3373 | && XBUFFER (p->buffer) == current_buffer) | |
fd482be5 JB |
3374 | Fgoto_char (w->pointm); |
3375 | } | |
52a68e98 RS |
3376 | else if (NILP (w->buffer) || NILP (XBUFFER (w->buffer)->name)) |
3377 | /* Else unless window has a live buffer, get one. */ | |
7ab12479 | 3378 | { |
fd482be5 JB |
3379 | w->buffer = Fcdr (Fcar (Vbuffer_alist)); |
3380 | /* This will set the markers to beginning of visible | |
3381 | range. */ | |
3382 | set_marker_restricted (w->start, make_number (0), w->buffer); | |
3383 | set_marker_restricted (w->pointm, make_number (0),w->buffer); | |
3384 | w->start_at_line_beg = Qt; | |
7ab12479 JB |
3385 | } |
3386 | else | |
fd482be5 | 3387 | /* Keeping window's old buffer; make sure the markers |
52a68e98 | 3388 | are real. */ |
7ab12479 | 3389 | { |
fd482be5 JB |
3390 | /* Set window markers at start of visible range. */ |
3391 | if (XMARKER (w->start)->buffer == 0) | |
3392 | set_marker_restricted (w->start, make_number (0), | |
3393 | w->buffer); | |
3394 | if (XMARKER (w->pointm)->buffer == 0) | |
b73ea88e RS |
3395 | set_marker_restricted_both (w->pointm, w->buffer, |
3396 | BUF_PT (XBUFFER (w->buffer)), | |
3397 | BUF_PT_BYTE (XBUFFER (w->buffer))); | |
fd482be5 | 3398 | w->start_at_line_beg = Qt; |
7ab12479 JB |
3399 | } |
3400 | } | |
3401 | } | |
9ace597f | 3402 | |
fd482be5 JB |
3403 | FRAME_ROOT_WINDOW (f) = data->root_window; |
3404 | Fselect_window (data->current_window); | |
396a830c RS |
3405 | XBUFFER (XWINDOW (selected_window)->buffer)->last_selected_window |
3406 | = selected_window; | |
7ab12479 | 3407 | |
db269683 | 3408 | if (NILP (data->focus_frame) |
017b2bad | 3409 | || (FRAMEP (data->focus_frame) |
db269683 JB |
3410 | && FRAME_LIVE_P (XFRAME (data->focus_frame)))) |
3411 | Fredirect_frame_focus (frame, data->focus_frame); | |
7ab12479 | 3412 | |
fd482be5 JB |
3413 | #if 0 /* I don't understand why this is needed, and it causes problems |
3414 | when the frame's old selected window has been deleted. */ | |
e4e59717 | 3415 | if (f != selected_frame && FRAME_WINDOW_P (f)) |
9a7c6fc3 RS |
3416 | do_switch_frame (WINDOW_FRAME (XWINDOW (data->root_window)), |
3417 | Qnil, 0); | |
fd482be5 JB |
3418 | #endif |
3419 | ||
3420 | /* Set the screen height to the value it had before this function. */ | |
3421 | if (previous_frame_height != FRAME_HEIGHT (f) | |
3422 | || previous_frame_width != FRAME_WIDTH (f)) | |
3423 | change_frame_size (f, previous_frame_height, previous_frame_width, | |
3424 | 0, 0); | |
e3678b64 | 3425 | #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS) |
8f6ea2e9 KH |
3426 | if (previous_frame_menu_bar_lines != FRAME_MENU_BAR_LINES (f)) |
3427 | x_set_menu_bar_lines (f, previous_frame_menu_bar_lines, 0); | |
217f2871 | 3428 | #endif |
d2b35234 RS |
3429 | |
3430 | UNBLOCK_INPUT; | |
fd482be5 | 3431 | } |
bdc727bf | 3432 | |
756b6edc RS |
3433 | /* Restore the minimum heights recorded in the configuration. */ |
3434 | window_min_height = XINT (data->min_height); | |
3435 | window_min_width = XINT (data->min_width); | |
3436 | ||
bdc727bf | 3437 | /* Fselect_window will have made f the selected frame, so we |
d5b2799e | 3438 | reselect the proper frame here. Fhandle_switch_frame will change the |
bdc727bf JB |
3439 | selected window too, but that doesn't make the call to |
3440 | Fselect_window above totally superfluous; it still sets f's | |
3441 | selected window. */ | |
fd482be5 | 3442 | if (FRAME_LIVE_P (XFRAME (data->selected_frame))) |
9a7c6fc3 | 3443 | do_switch_frame (data->selected_frame, Qnil, 0); |
bdc727bf JB |
3444 | |
3445 | if (!NILP (new_current_buffer)) | |
d2b35234 RS |
3446 | { |
3447 | Fset_buffer (new_current_buffer); | |
3448 | ||
3449 | /* If the buffer that is current now is the same | |
3450 | that was current before setting the window configuration, | |
3451 | don't alter its PT. */ | |
3452 | if (old_point >= 0) | |
3453 | SET_PT (old_point); | |
3454 | } | |
bdc727bf | 3455 | |
7ab12479 | 3456 | Vminibuf_scroll_window = data->minibuf_scroll_window; |
543f5fb1 RS |
3457 | |
3458 | if (! NILP (Vwindow_configuration_change_hook) | |
3459 | && ! NILP (Vrun_hooks)) | |
3460 | call1 (Vrun_hooks, Qwindow_configuration_change_hook); | |
3461 | ||
7ab12479 JB |
3462 | return (Qnil); |
3463 | } | |
3464 | ||
44fa5b1e | 3465 | /* Mark all windows now on frame as deleted |
7ab12479 JB |
3466 | by setting their buffers to nil. */ |
3467 | ||
fd482be5 | 3468 | void |
7ab12479 JB |
3469 | delete_all_subwindows (w) |
3470 | register struct window *w; | |
3471 | { | |
265a9e55 | 3472 | if (!NILP (w->next)) |
7ab12479 | 3473 | delete_all_subwindows (XWINDOW (w->next)); |
265a9e55 | 3474 | if (!NILP (w->vchild)) |
7ab12479 | 3475 | delete_all_subwindows (XWINDOW (w->vchild)); |
265a9e55 | 3476 | if (!NILP (w->hchild)) |
7ab12479 | 3477 | delete_all_subwindows (XWINDOW (w->hchild)); |
605be8af JB |
3478 | |
3479 | w->height = w->buffer; /* See Fset_window_configuration for excuse. */ | |
3480 | ||
86e48436 RS |
3481 | if (!NILP (w->buffer)) |
3482 | unshow_buffer (w); | |
3483 | ||
605be8af JB |
3484 | /* We set all three of these fields to nil, to make sure that we can |
3485 | distinguish this dead window from any live window. Live leaf | |
3486 | windows will have buffer set, and combination windows will have | |
3487 | vchild or hchild set. */ | |
3488 | w->buffer = Qnil; | |
3489 | w->vchild = Qnil; | |
3490 | w->hchild = Qnil; | |
7ab12479 JB |
3491 | } |
3492 | \f | |
3493 | static int | |
3494 | count_windows (window) | |
3495 | register struct window *window; | |
3496 | { | |
3497 | register int count = 1; | |
265a9e55 | 3498 | if (!NILP (window->next)) |
7ab12479 | 3499 | count += count_windows (XWINDOW (window->next)); |
265a9e55 | 3500 | if (!NILP (window->vchild)) |
7ab12479 | 3501 | count += count_windows (XWINDOW (window->vchild)); |
265a9e55 | 3502 | if (!NILP (window->hchild)) |
7ab12479 JB |
3503 | count += count_windows (XWINDOW (window->hchild)); |
3504 | return count; | |
3505 | } | |
3506 | ||
3507 | static int | |
3508 | save_window_save (window, vector, i) | |
3509 | Lisp_Object window; | |
3510 | struct Lisp_Vector *vector; | |
3511 | int i; | |
3512 | { | |
3513 | register struct saved_window *p; | |
3514 | register struct window *w; | |
3515 | register Lisp_Object tem; | |
3516 | ||
265a9e55 | 3517 | for (;!NILP (window); window = w->next) |
7ab12479 JB |
3518 | { |
3519 | p = SAVED_WINDOW_N (vector, i); | |
3520 | w = XWINDOW (window); | |
3521 | ||
d834a2e9 | 3522 | XSETFASTINT (w->temslot, i++); |
7ab12479 JB |
3523 | p->window = window; |
3524 | p->buffer = w->buffer; | |
3525 | p->left = w->left; | |
3526 | p->top = w->top; | |
3527 | p->width = w->width; | |
3528 | p->height = w->height; | |
3529 | p->hscroll = w->hscroll; | |
3530 | p->display_table = w->display_table; | |
265a9e55 | 3531 | if (!NILP (w->buffer)) |
7ab12479 JB |
3532 | { |
3533 | /* Save w's value of point in the window configuration. | |
3534 | If w is the selected window, then get the value of point | |
3535 | from the buffer; pointm is garbage in the selected window. */ | |
3536 | if (EQ (window, selected_window)) | |
3537 | { | |
3538 | p->pointm = Fmake_marker (); | |
b73ea88e RS |
3539 | set_marker_both (p->pointm, w->buffer, |
3540 | BUF_PT (XBUFFER (w->buffer)), | |
3541 | BUF_PT_BYTE (XBUFFER (w->buffer))); | |
7ab12479 JB |
3542 | } |
3543 | else | |
eeb82665 | 3544 | p->pointm = Fcopy_marker (w->pointm, Qnil); |
7ab12479 | 3545 | |
eeb82665 | 3546 | p->start = Fcopy_marker (w->start, Qnil); |
7ab12479 JB |
3547 | p->start_at_line_beg = w->start_at_line_beg; |
3548 | ||
3549 | tem = XBUFFER (w->buffer)->mark; | |
eeb82665 | 3550 | p->mark = Fcopy_marker (tem, Qnil); |
7ab12479 JB |
3551 | } |
3552 | else | |
3553 | { | |
3554 | p->pointm = Qnil; | |
3555 | p->start = Qnil; | |
3556 | p->mark = Qnil; | |
3557 | p->start_at_line_beg = Qnil; | |
3558 | } | |
3559 | ||
265a9e55 | 3560 | if (NILP (w->parent)) |
7ab12479 JB |
3561 | p->parent = Qnil; |
3562 | else | |
3563 | p->parent = XWINDOW (w->parent)->temslot; | |
3564 | ||
265a9e55 | 3565 | if (NILP (w->prev)) |
7ab12479 JB |
3566 | p->prev = Qnil; |
3567 | else | |
3568 | p->prev = XWINDOW (w->prev)->temslot; | |
3569 | ||
265a9e55 | 3570 | if (!NILP (w->vchild)) |
7ab12479 | 3571 | i = save_window_save (w->vchild, vector, i); |
265a9e55 | 3572 | if (!NILP (w->hchild)) |
7ab12479 JB |
3573 | i = save_window_save (w->hchild, vector, i); |
3574 | } | |
3575 | ||
3576 | return i; | |
3577 | } | |
3578 | ||
a0d76c27 EN |
3579 | DEFUN ("current-window-configuration", Fcurrent_window_configuration, |
3580 | Scurrent_window_configuration, 0, 1, 0, | |
44fa5b1e JB |
3581 | "Return an object representing the current window configuration of FRAME.\n\ |
3582 | If FRAME is nil or omitted, use the selected frame.\n\ | |
7ab12479 JB |
3583 | This describes the number of windows, their sizes and current buffers,\n\ |
3584 | and for each displayed buffer, where display starts, and the positions of\n\ | |
3585 | point and mark. An exception is made for point in the current buffer:\n\ | |
bdc727bf JB |
3586 | its value is -not- saved.\n\ |
3587 | This also records the currently selected frame, and FRAME's focus\n\ | |
3588 | redirection (see `redirect-frame-focus').") | |
44fa5b1e JB |
3589 | (frame) |
3590 | Lisp_Object frame; | |
7ab12479 JB |
3591 | { |
3592 | register Lisp_Object tem; | |
3593 | register int n_windows; | |
3594 | register struct save_window_data *data; | |
da2792e0 | 3595 | register struct Lisp_Vector *vec; |
7ab12479 | 3596 | register int i; |
44fa5b1e | 3597 | FRAME_PTR f; |
43bad991 | 3598 | |
44fa5b1e JB |
3599 | if (NILP (frame)) |
3600 | f = selected_frame; | |
43bad991 JB |
3601 | else |
3602 | { | |
44fa5b1e JB |
3603 | CHECK_LIVE_FRAME (frame, 0); |
3604 | f = XFRAME (frame); | |
43bad991 | 3605 | } |
7ab12479 | 3606 | |
44fa5b1e | 3607 | n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f))); |
da2792e0 KH |
3608 | vec = allocate_vectorlike (VECSIZE (struct save_window_data)); |
3609 | for (i = 0; i < VECSIZE (struct save_window_data); i++) | |
3610 | vec->contents[i] = Qnil; | |
3611 | vec->size = VECSIZE (struct save_window_data); | |
3612 | data = (struct save_window_data *)vec; | |
3613 | ||
d834a2e9 KH |
3614 | XSETFASTINT (data->frame_width, FRAME_WIDTH (f)); |
3615 | XSETFASTINT (data->frame_height, FRAME_HEIGHT (f)); | |
3616 | XSETFASTINT (data->frame_menu_bar_lines, FRAME_MENU_BAR_LINES (f)); | |
74112613 | 3617 | XSETFRAME (data->selected_frame, selected_frame); |
44fa5b1e | 3618 | data->current_window = FRAME_SELECTED_WINDOW (f); |
74112613 | 3619 | XSETBUFFER (data->current_buffer, current_buffer); |
7ab12479 | 3620 | data->minibuf_scroll_window = Vminibuf_scroll_window; |
44fa5b1e | 3621 | data->root_window = FRAME_ROOT_WINDOW (f); |
bdc727bf | 3622 | data->focus_frame = FRAME_FOCUS_FRAME (f); |
74112613 KH |
3623 | XSETINT (data->min_height, window_min_height); |
3624 | XSETINT (data->min_width, window_min_width); | |
7ab12479 JB |
3625 | tem = Fmake_vector (make_number (n_windows), Qnil); |
3626 | data->saved_windows = tem; | |
3627 | for (i = 0; i < n_windows; i++) | |
3628 | XVECTOR (tem)->contents[i] | |
3629 | = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE), Qnil); | |
44fa5b1e | 3630 | save_window_save (FRAME_ROOT_WINDOW (f), |
7ab12479 | 3631 | XVECTOR (tem), 0); |
74112613 | 3632 | XSETWINDOW_CONFIGURATION (tem, data); |
7ab12479 JB |
3633 | return (tem); |
3634 | } | |
3635 | ||
3636 | DEFUN ("save-window-excursion", Fsave_window_excursion, Ssave_window_excursion, | |
3637 | 0, UNEVALLED, 0, | |
3638 | "Execute body, preserving window sizes and contents.\n\ | |
eb16ec06 RS |
3639 | Restore which buffer appears in which window, where display starts,\n\ |
3640 | and the value of point and mark for each window.\n\ | |
3641 | Also restore which buffer is current.\n\ | |
3642 | But do not preserve point in the current buffer.\n\ | |
7ab12479 JB |
3643 | Does not restore the value of point in current buffer.") |
3644 | (args) | |
3645 | Lisp_Object args; | |
3646 | { | |
3647 | register Lisp_Object val; | |
3648 | register int count = specpdl_ptr - specpdl; | |
3649 | ||
3650 | record_unwind_protect (Fset_window_configuration, | |
43bad991 | 3651 | Fcurrent_window_configuration (Qnil)); |
7ab12479 JB |
3652 | val = Fprogn (args); |
3653 | return unbind_to (count, val); | |
3654 | } | |
3655 | \f | |
3656 | init_window_once () | |
3657 | { | |
44fa5b1e | 3658 | selected_frame = make_terminal_frame (); |
bc6c324f | 3659 | XSETFRAME (Vterminal_frame, selected_frame); |
44fa5b1e JB |
3660 | minibuf_window = selected_frame->minibuffer_window; |
3661 | selected_window = selected_frame->selected_window; | |
3662 | last_nonminibuf_frame = selected_frame; | |
5b03d3c0 RS |
3663 | |
3664 | window_initialized = 1; | |
7ab12479 JB |
3665 | } |
3666 | ||
3667 | syms_of_window () | |
3668 | { | |
543f5fb1 RS |
3669 | staticpro (&Qwindow_configuration_change_hook); |
3670 | Qwindow_configuration_change_hook | |
3671 | = intern ("window-configuration-change-hook"); | |
3672 | ||
7ab12479 JB |
3673 | Qwindowp = intern ("windowp"); |
3674 | staticpro (&Qwindowp); | |
3675 | ||
806b4d9b JB |
3676 | Qwindow_live_p = intern ("window-live-p"); |
3677 | staticpro (&Qwindow_live_p); | |
605be8af | 3678 | |
2cccc823 | 3679 | Qtemp_buffer_show_hook = intern ("temp-buffer-show-hook"); |
a58ec57d RS |
3680 | staticpro (&Qtemp_buffer_show_hook); |
3681 | ||
7ab12479 JB |
3682 | DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function, |
3683 | "Non-nil means call as function to display a help buffer.\n\ | |
c3ef6b1d | 3684 | The function is called with one argument, the buffer to be displayed.\n\ |
f52cca03 RS |
3685 | Used by `with-output-to-temp-buffer'.\n\ |
3686 | If this function is used, then it must do the entire job of showing\n\ | |
3687 | the buffer; `temp-buffer-show-hook' is not run unless this function runs it."); | |
7ab12479 JB |
3688 | Vtemp_buffer_show_function = Qnil; |
3689 | ||
3690 | DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function, | |
3691 | "If non-nil, function to call to handle `display-buffer'.\n\ | |
3692 | It will receive two args, the buffer and a flag which if non-nil means\n\ | |
3693 | that the currently selected window is not acceptable.\n\ | |
3694 | Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\ | |
3695 | work using this function."); | |
3696 | Vdisplay_buffer_function = Qnil; | |
3697 | ||
7ab12479 JB |
3698 | DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window, |
3699 | "Non-nil means it is the window that C-M-v in minibuffer should scroll."); | |
3700 | Vminibuf_scroll_window = Qnil; | |
3701 | ||
3702 | DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer, | |
3703 | "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window."); | |
3704 | Vother_window_scroll_buffer = Qnil; | |
3705 | ||
44fa5b1e | 3706 | DEFVAR_BOOL ("pop-up-frames", &pop_up_frames, |
700f75a4 | 3707 | "*Non-nil means `display-buffer' should make a separate frame."); |
44fa5b1e | 3708 | pop_up_frames = 0; |
7ab12479 | 3709 | |
44fa5b1e | 3710 | DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function, |
a90712c2 | 3711 | "Function to call to handle automatic new frame creation.\n\ |
44fa5b1e | 3712 | It is called with no arguments and should return a newly created frame.\n\ |
7ab12479 | 3713 | \n\ |
44fa5b1e JB |
3714 | A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\ |
3715 | where `pop-up-frame-alist' would hold the default frame parameters."); | |
3716 | Vpop_up_frame_function = Qnil; | |
7ab12479 | 3717 | |
a90712c2 RS |
3718 | DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names, |
3719 | "*List of buffer names that should have their own special frames.\n\ | |
3720 | Displaying a buffer whose name is in this list makes a special frame for it\n\ | |
524580a4 | 3721 | using `special-display-function'. See also `special-display-regexps'.\n\ |
3548e138 | 3722 | \n\ |
524580a4 RS |
3723 | An element of the list can be a list instead of just a string.\n\ |
3724 | There are two ways to use a list as an element:\n\ | |
3725 | (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)\n\ | |
3726 | In the first case, FRAME-PARAMETERS are used to create the frame.\n\ | |
3727 | In the latter case, FUNCTION is called with BUFFER as the first argument,\n\ | |
3728 | followed by OTHER-ARGS--it can display BUFFER in any way it likes.\n\ | |
4caa7448 RS |
3729 | All this is done by the function found in `special-display-function'.\n\ |
3730 | \n\ | |
3731 | If this variable appears \"not to work\", because you add a name to it\n\ | |
3732 | but that buffer still appears in the selected window, look at the\n\ | |
3733 | values of `same-window-buffer-names' and `same-window-regexps'.\n\ | |
3734 | Those variables take precedence over this one."); | |
a90712c2 RS |
3735 | Vspecial_display_buffer_names = Qnil; |
3736 | ||
3737 | DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps, | |
3738 | "*List of regexps saying which buffers should have their own special frames.\n\ | |
3739 | If a buffer name matches one of these regexps, it gets its own frame.\n\ | |
3740 | Displaying a buffer whose name is in this list makes a special frame for it\n\ | |
0a952b57 | 3741 | using `special-display-function'.\n\ |
3548e138 | 3742 | \n\ |
524580a4 RS |
3743 | An element of the list can be a list instead of just a string.\n\ |
3744 | There are two ways to use a list as an element:\n\ | |
3745 | (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)\n\ | |
3746 | In the first case, FRAME-PARAMETERS are used to create the frame.\n\ | |
3747 | In the latter case, FUNCTION is called with the buffer as first argument,\n\ | |
3748 | followed by OTHER-ARGS--it can display the buffer in any way it likes.\n\ | |
4caa7448 RS |
3749 | All this is done by the function found in `special-display-function'.\n\ |
3750 | \n\ | |
3751 | If this variable appears \"not to work\", because you add a regexp to it\n\ | |
3752 | but the matching buffers still appear in the selected window, look at the\n\ | |
3753 | values of `same-window-buffer-names' and `same-window-regexps'.\n\ | |
3754 | Those variables take precedence over this one."); | |
a90712c2 RS |
3755 | Vspecial_display_regexps = Qnil; |
3756 | ||
3757 | DEFVAR_LISP ("special-display-function", &Vspecial_display_function, | |
3758 | "Function to call to make a new frame for a special buffer.\n\ | |
0a952b57 RS |
3759 | It is called with two arguments, the buffer and optional buffer specific\n\ |
3760 | data, and should return a window displaying that buffer.\n\ | |
a90712c2 | 3761 | The default value makes a separate frame for the buffer,\n\ |
bdd3a802 | 3762 | using `special-display-frame-alist' to specify the frame parameters.\n\ |
a90712c2 RS |
3763 | \n\ |
3764 | A buffer is special if its is listed in `special-display-buffer-names'\n\ | |
3765 | or matches a regexp in `special-display-regexps'."); | |
3766 | Vspecial_display_function = Qnil; | |
3767 | ||
855d8627 RS |
3768 | DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names, |
3769 | "*List of buffer names that should appear in the selected window.\n\ | |
3770 | Displaying one of these buffers using `display-buffer' or `pop-to-buffer'\n\ | |
3771 | switches to it in the selected window, rather than making it appear\n\ | |
2e5ce1a0 | 3772 | in some other window.\n\ |
855d8627 RS |
3773 | \n\ |
3774 | An element of the list can be a cons cell instead of just a string.\n\ | |
3775 | Then the car must be a string, which specifies the buffer name.\n\ | |
3776 | This is for compatibility with `special-display-buffer-names';\n\ | |
3777 | the cdr of the cons cell is ignored.\n\ | |
3778 | \n\ | |
3779 | See also `same-window-regexps'."); | |
3780 | Vsame_window_buffer_names = Qnil; | |
3781 | ||
3782 | DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps, | |
3783 | "*List of regexps saying which buffers should appear in the selected window.\n\ | |
3784 | If a buffer name matches one of these regexps, then displaying it\n\ | |
3785 | using `display-buffer' or `pop-to-buffer' switches to it\n\ | |
3786 | in the selected window, rather than making it appear in some other window.\n\ | |
3787 | \n\ | |
3788 | An element of the list can be a cons cell instead of just a string.\n\ | |
3789 | Then the car must be a string, which specifies the buffer name.\n\ | |
3790 | This is for compatibility with `special-display-buffer-names';\n\ | |
3791 | the cdr of the cons cell is ignored.\n\ | |
3792 | \n\ | |
3793 | See also `same-window-buffer-names'."); | |
3794 | Vsame_window_regexps = Qnil; | |
3795 | ||
7ab12479 JB |
3796 | DEFVAR_BOOL ("pop-up-windows", &pop_up_windows, |
3797 | "*Non-nil means display-buffer should make new windows."); | |
3798 | pop_up_windows = 1; | |
3799 | ||
3800 | DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines, | |
3801 | "*Number of lines of continuity when scrolling by screenfuls."); | |
3802 | next_screen_context_lines = 2; | |
3803 | ||
3804 | DEFVAR_INT ("split-height-threshold", &split_height_threshold, | |
3805 | "*display-buffer would prefer to split the largest window if this large.\n\ | |
3806 | If there is only one window, it is split regardless of this value."); | |
3807 | split_height_threshold = 500; | |
3808 | ||
3809 | DEFVAR_INT ("window-min-height", &window_min_height, | |
3810 | "*Delete any window less than this tall (including its mode line)."); | |
3811 | window_min_height = 4; | |
3812 | ||
3813 | DEFVAR_INT ("window-min-width", &window_min_width, | |
3814 | "*Delete any window less than this wide."); | |
3815 | window_min_width = 10; | |
3816 | ||
9317a85d RS |
3817 | DEFVAR_BOOL ("scroll-preserve-screen-position", |
3818 | &scroll_preserve_screen_position, | |
3819 | "*Nonzero means scroll commands move point to keep its screen line unchanged."); | |
3820 | scroll_preserve_screen_position = 0; | |
3821 | ||
543f5fb1 RS |
3822 | DEFVAR_LISP ("window-configuration-change-hook", |
3823 | &Vwindow_configuration_change_hook, | |
3824 | "Functions to call when window configuration changes.\n\ | |
e3e041eb | 3825 | The selected frame is the one whose configuration has changed."); |
543f5fb1 RS |
3826 | Vwindow_configuration_change_hook = Qnil; |
3827 | ||
7ab12479 JB |
3828 | defsubr (&Sselected_window); |
3829 | defsubr (&Sminibuffer_window); | |
3830 | defsubr (&Swindow_minibuffer_p); | |
3831 | defsubr (&Swindowp); | |
806b4d9b | 3832 | defsubr (&Swindow_live_p); |
7ab12479 JB |
3833 | defsubr (&Spos_visible_in_window_p); |
3834 | defsubr (&Swindow_buffer); | |
3835 | defsubr (&Swindow_height); | |
3836 | defsubr (&Swindow_width); | |
3837 | defsubr (&Swindow_hscroll); | |
3838 | defsubr (&Sset_window_hscroll); | |
190eb263 RS |
3839 | defsubr (&Swindow_redisplay_end_trigger); |
3840 | defsubr (&Sset_window_redisplay_end_trigger); | |
7ab12479 | 3841 | defsubr (&Swindow_edges); |
d5783c40 JB |
3842 | defsubr (&Scoordinates_in_window_p); |
3843 | defsubr (&Swindow_at); | |
7ab12479 JB |
3844 | defsubr (&Swindow_point); |
3845 | defsubr (&Swindow_start); | |
3846 | defsubr (&Swindow_end); | |
3847 | defsubr (&Sset_window_point); | |
3848 | defsubr (&Sset_window_start); | |
3849 | defsubr (&Swindow_dedicated_p); | |
d207b766 | 3850 | defsubr (&Sset_window_dedicated_p); |
7ab12479 JB |
3851 | defsubr (&Swindow_display_table); |
3852 | defsubr (&Sset_window_display_table); | |
3853 | defsubr (&Snext_window); | |
3854 | defsubr (&Sprevious_window); | |
3855 | defsubr (&Sother_window); | |
3856 | defsubr (&Sget_lru_window); | |
3857 | defsubr (&Sget_largest_window); | |
3858 | defsubr (&Sget_buffer_window); | |
3859 | defsubr (&Sdelete_other_windows); | |
3860 | defsubr (&Sdelete_windows_on); | |
3861 | defsubr (&Sreplace_buffer_in_windows); | |
3862 | defsubr (&Sdelete_window); | |
3863 | defsubr (&Sset_window_buffer); | |
3864 | defsubr (&Sselect_window); | |
4628f7a4 EN |
3865 | defsubr (&Sspecial_display_p); |
3866 | defsubr (&Ssame_window_p); | |
7ab12479 JB |
3867 | defsubr (&Sdisplay_buffer); |
3868 | defsubr (&Ssplit_window); | |
3869 | defsubr (&Senlarge_window); | |
3870 | defsubr (&Sshrink_window); | |
3871 | defsubr (&Sscroll_up); | |
3872 | defsubr (&Sscroll_down); | |
3873 | defsubr (&Sscroll_left); | |
3874 | defsubr (&Sscroll_right); | |
ccd0664b | 3875 | defsubr (&Sother_window_for_scrolling); |
7ab12479 JB |
3876 | defsubr (&Sscroll_other_window); |
3877 | defsubr (&Srecenter); | |
3878 | defsubr (&Smove_to_window_line); | |
3879 | defsubr (&Swindow_configuration_p); | |
3880 | defsubr (&Sset_window_configuration); | |
3881 | defsubr (&Scurrent_window_configuration); | |
3882 | defsubr (&Ssave_window_excursion); | |
3883 | } | |
3884 | ||
3885 | keys_of_window () | |
3886 | { | |
3887 | initial_define_key (control_x_map, '1', "delete-other-windows"); | |
3888 | initial_define_key (control_x_map, '2', "split-window"); | |
3889 | initial_define_key (control_x_map, '0', "delete-window"); | |
3890 | initial_define_key (control_x_map, 'o', "other-window"); | |
3891 | initial_define_key (control_x_map, '^', "enlarge-window"); | |
3892 | initial_define_key (control_x_map, '<', "scroll-left"); | |
3893 | initial_define_key (control_x_map, '>', "scroll-right"); | |
3894 | ||
3895 | initial_define_key (global_map, Ctl ('V'), "scroll-up"); | |
3896 | initial_define_key (meta_map, Ctl ('V'), "scroll-other-window"); | |
3897 | initial_define_key (meta_map, 'v', "scroll-down"); | |
3898 | ||
3899 | initial_define_key (global_map, Ctl('L'), "recenter"); | |
3900 | initial_define_key (meta_map, 'r', "move-to-window-line"); | |
3901 | } |