Update copyright. Update commentary to mention rx syntax support.
[emacs.git] / src / window.c
blob735bd99fd556a1311343a3db2dfe527ed72918b9
1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985,86,87, 1993,94,95,96,97,98, 2000,01,02,03,04
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 #include <config.h>
24 #include "lisp.h"
25 #include "buffer.h"
26 #include "keyboard.h"
27 #include "keymap.h"
28 #include "frame.h"
29 #include "window.h"
30 #include "commands.h"
31 #include "indent.h"
32 #include "termchar.h"
33 #include "disptab.h"
34 #include "dispextern.h"
35 #include "blockinput.h"
36 #include "intervals.h"
38 #ifdef HAVE_X_WINDOWS
39 #include "xterm.h"
40 #endif /* HAVE_X_WINDOWS */
41 #ifdef WINDOWSNT
42 #include "w32term.h"
43 #endif
44 #ifdef MSDOS
45 #include "msdos.h"
46 #endif
47 #ifdef MAC_OS
48 #include "macterm.h"
49 #endif
52 Lisp_Object Qwindowp, Qwindow_live_p, Qwindow_configuration_p;
53 Lisp_Object Qwindow_size_fixed;
54 extern Lisp_Object Qleft_margin, Qright_margin;
56 static int displayed_window_lines P_ ((struct window *));
57 static struct window *decode_window P_ ((Lisp_Object));
58 static int count_windows P_ ((struct window *));
59 static int get_leaf_windows P_ ((struct window *, struct window **, int));
60 static void window_scroll P_ ((Lisp_Object, int, int, int));
61 static void window_scroll_pixel_based P_ ((Lisp_Object, int, int, int));
62 static void window_scroll_line_based P_ ((Lisp_Object, int, int, int));
63 static int window_min_size_1 P_ ((struct window *, int));
64 static int window_min_size P_ ((struct window *, int, int, int *));
65 static void size_window P_ ((Lisp_Object, int, int, int));
66 static int freeze_window_start P_ ((struct window *, void *));
67 static int window_fixed_size_p P_ ((struct window *, int, int));
68 static void enlarge_window P_ ((Lisp_Object, int, int, int));
69 static Lisp_Object window_list P_ ((void));
70 static int add_window_to_list P_ ((struct window *, void *));
71 static int candidate_window_p P_ ((Lisp_Object, Lisp_Object, Lisp_Object,
72 Lisp_Object));
73 static Lisp_Object next_window P_ ((Lisp_Object, Lisp_Object,
74 Lisp_Object, int));
75 static void decode_next_window_args P_ ((Lisp_Object *, Lisp_Object *,
76 Lisp_Object *));
77 static int foreach_window_1 P_ ((struct window *,
78 int (* fn) (struct window *, void *),
79 void *));
80 static Lisp_Object window_list_1 P_ ((Lisp_Object, Lisp_Object, Lisp_Object));
82 /* The value of `window-size-fixed'. */
84 int window_size_fixed;
86 /* This is the window in which the terminal's cursor should
87 be left when nothing is being done with it. This must
88 always be a leaf window, and its buffer is selected by
89 the top level editing loop at the end of each command.
91 This value is always the same as
92 FRAME_SELECTED_WINDOW (selected_frame). */
94 Lisp_Object selected_window;
96 /* A list of all windows for use by next_window and Fwindow_list.
97 Functions creating or deleting windows should invalidate this cache
98 by setting it to nil. */
100 Lisp_Object Vwindow_list;
102 /* The mini-buffer window of the selected frame.
103 Note that you cannot test for mini-bufferness of an arbitrary window
104 by comparing against this; but you can test for mini-bufferness of
105 the selected window. */
107 Lisp_Object minibuf_window;
109 /* Non-nil means it is the window whose mode line should be
110 shown as the selected window when the minibuffer is selected. */
112 Lisp_Object minibuf_selected_window;
114 /* Non-nil means it is the window for C-M-v to scroll
115 when the mini-buffer is selected. */
117 Lisp_Object Vminibuf_scroll_window;
119 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
121 Lisp_Object Vother_window_scroll_buffer;
123 /* Non-nil means it's function to call to display temp buffers. */
125 Lisp_Object Vtemp_buffer_show_function;
127 /* Non-zero means to use mode-line-inactive face in all windows but the
128 selected-window and the minibuffer-scroll-window when the
129 minibuffer is active. */
130 int mode_line_in_non_selected_windows;
132 /* If a window gets smaller than either of these, it is removed. */
134 EMACS_INT window_min_height;
135 EMACS_INT window_min_width;
137 /* Nonzero implies Fdisplay_buffer should create windows. */
139 int pop_up_windows;
141 /* Nonzero implies make new frames for Fdisplay_buffer. */
143 int pop_up_frames;
145 /* Nonzero means reuse existing frames for displaying buffers. */
147 int display_buffer_reuse_frames;
149 /* Non-nil means use this function instead of default */
151 Lisp_Object Vpop_up_frame_function;
153 /* Function to call to handle Fdisplay_buffer. */
155 Lisp_Object Vdisplay_buffer_function;
157 /* Non-nil means that Fdisplay_buffer should even the heights of windows. */
159 Lisp_Object Veven_window_heights;
161 /* List of buffer *names* for buffers that should have their own frames. */
163 Lisp_Object Vspecial_display_buffer_names;
165 /* List of regexps for buffer names that should have their own frames. */
167 Lisp_Object Vspecial_display_regexps;
169 /* Function to pop up a special frame. */
171 Lisp_Object Vspecial_display_function;
173 /* List of buffer *names* for buffers to appear in selected window. */
175 Lisp_Object Vsame_window_buffer_names;
177 /* List of regexps for buffer names to appear in selected window. */
179 Lisp_Object Vsame_window_regexps;
181 /* Hook run at end of temp_output_buffer_show. */
183 Lisp_Object Qtemp_buffer_show_hook;
185 /* Fdisplay_buffer always splits the largest window
186 if that window is more than this high. */
188 EMACS_INT split_height_threshold;
190 /* Number of lines of continuity in scrolling by screenfuls. */
192 EMACS_INT next_screen_context_lines;
194 /* Incremented for each window created. */
196 static int sequence_number;
198 /* Nonzero after init_window_once has finished. */
200 static int window_initialized;
202 /* Hook to run when window config changes. */
204 Lisp_Object Qwindow_configuration_change_hook;
205 Lisp_Object Vwindow_configuration_change_hook;
207 /* Non-nil means scroll commands try to put point
208 at the same screen height as previously. */
210 Lisp_Object Vscroll_preserve_screen_position;
212 #if 0 /* This isn't used anywhere. */
213 /* Nonzero means we can split a frame even if it is "unsplittable". */
214 static int inhibit_frame_unsplittable;
215 #endif /* 0 */
217 extern EMACS_INT scroll_margin;
219 extern Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
221 DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0,
222 doc: /* Returns t if OBJECT is a window. */)
223 (object)
224 Lisp_Object object;
226 return WINDOWP (object) ? Qt : Qnil;
229 DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0,
230 doc: /* Returns t if OBJECT is a window which is currently visible. */)
231 (object)
232 Lisp_Object object;
234 return WINDOW_LIVE_P (object) ? Qt : Qnil;
237 Lisp_Object
238 make_window ()
240 Lisp_Object val;
241 register struct window *p;
243 p = allocate_window ();
244 ++sequence_number;
245 XSETFASTINT (p->sequence_number, sequence_number);
246 XSETFASTINT (p->left_col, 0);
247 XSETFASTINT (p->top_line, 0);
248 XSETFASTINT (p->total_lines, 0);
249 XSETFASTINT (p->total_cols, 0);
250 XSETFASTINT (p->hscroll, 0);
251 XSETFASTINT (p->min_hscroll, 0);
252 p->orig_top_line = p->orig_total_lines = Qnil;
253 p->start = Fmake_marker ();
254 p->pointm = Fmake_marker ();
255 XSETFASTINT (p->use_time, 0);
256 p->frame = Qnil;
257 p->display_table = Qnil;
258 p->dedicated = Qnil;
259 p->pseudo_window_p = 0;
260 bzero (&p->cursor, sizeof (p->cursor));
261 bzero (&p->last_cursor, sizeof (p->last_cursor));
262 bzero (&p->phys_cursor, sizeof (p->phys_cursor));
263 p->desired_matrix = p->current_matrix = 0;
264 p->nrows_scale_factor = p->ncols_scale_factor = 1;
265 p->phys_cursor_type = -1;
266 p->phys_cursor_width = -1;
267 p->must_be_updated_p = 0;
268 XSETFASTINT (p->window_end_vpos, 0);
269 XSETFASTINT (p->window_end_pos, 0);
270 p->window_end_valid = Qnil;
271 p->vscroll = 0;
272 XSETWINDOW (val, p);
273 XSETFASTINT (p->last_point, 0);
274 p->frozen_window_start_p = 0;
275 p->height_fixed_p = 0;
276 p->last_cursor_off_p = p->cursor_off_p = 0;
277 p->left_margin_cols = Qnil;
278 p->right_margin_cols = Qnil;
279 p->left_fringe_width = Qnil;
280 p->right_fringe_width = Qnil;
281 p->fringes_outside_margins = Qnil;
282 p->scroll_bar_width = Qnil;
283 p->vertical_scroll_bar_type = Qt;
284 p->overlay_arrow_bitmap = 0;
286 Vwindow_list = Qnil;
287 return val;
290 DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0,
291 doc: /* Return the window that the cursor now appears in and commands apply to. */)
294 return selected_window;
297 DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0,
298 doc: /* Return the window used now for minibuffers.
299 If the optional argument FRAME is specified, return the minibuffer window
300 used by that frame. */)
301 (frame)
302 Lisp_Object frame;
304 if (NILP (frame))
305 frame = selected_frame;
306 CHECK_LIVE_FRAME (frame);
307 return FRAME_MINIBUF_WINDOW (XFRAME (frame));
310 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, Swindow_minibuffer_p, 0, 1, 0,
311 doc: /* Returns non-nil if WINDOW is a minibuffer window.
312 WINDOW defaults to the selected window. */)
313 (window)
314 Lisp_Object window;
316 struct window *w = decode_window (window);
317 return MINI_WINDOW_P (w) ? Qt : Qnil;
321 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p,
322 Spos_visible_in_window_p, 0, 3, 0,
323 doc: /* Return non-nil if position POS is currently on the frame in WINDOW.
324 Return nil if that position is scrolled vertically out of view.
325 If a character is only partially visible, nil is returned, unless the
326 optional argument PARTIALLY is non-nil.
327 If POS is only out of view because of horizontal scrolling, return non-nil.
328 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
330 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
331 return value is a list (X Y FULLY) where X and Y are the pixel coordinates
332 relative to the top left corner of the window, and FULLY is t if the
333 character after POS is fully visible and nil otherwise. */)
334 (pos, window, partially)
335 Lisp_Object pos, window, partially;
337 register struct window *w;
338 register int posint;
339 register struct buffer *buf;
340 struct text_pos top;
341 Lisp_Object in_window = Qnil;
342 int fully_p = 1;
343 int x, y;
345 w = decode_window (window);
346 buf = XBUFFER (w->buffer);
347 SET_TEXT_POS_FROM_MARKER (top, w->start);
349 if (!NILP (pos))
351 CHECK_NUMBER_COERCE_MARKER (pos);
352 posint = XINT (pos);
354 else if (w == XWINDOW (selected_window))
355 posint = PT;
356 else
357 posint = XMARKER (w->pointm)->charpos;
359 /* If position is above window start or outside buffer boundaries,
360 or if window start is out of range, position is not visible. */
361 if (posint >= CHARPOS (top)
362 && posint <= BUF_ZV (buf)
363 && CHARPOS (top) >= BUF_BEGV (buf)
364 && CHARPOS (top) <= BUF_ZV (buf)
365 && pos_visible_p (w, posint, &fully_p, &x, &y, NILP (partially))
366 && (!NILP (partially) || fully_p))
367 in_window = Qt;
369 if (!NILP (in_window) && !NILP (partially))
370 in_window = Fcons (make_number (x),
371 Fcons (make_number (y),
372 Fcons (fully_p ? Qt : Qnil, Qnil)));
373 return in_window;
377 static struct window *
378 decode_window (window)
379 register Lisp_Object window;
381 if (NILP (window))
382 return XWINDOW (selected_window);
384 CHECK_LIVE_WINDOW (window);
385 return XWINDOW (window);
388 static struct window *
389 decode_any_window (window)
390 register Lisp_Object window;
392 if (NILP (window))
393 return XWINDOW (selected_window);
395 CHECK_WINDOW (window);
396 return XWINDOW (window);
399 DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0,
400 doc: /* Return the buffer that WINDOW is displaying.
401 WINDOW defaults to the selected window. */)
402 (window)
403 Lisp_Object window;
405 return decode_window (window)->buffer;
408 DEFUN ("window-height", Fwindow_height, Swindow_height, 0, 1, 0,
409 doc: /* Return the number of lines in WINDOW (including its mode line). */)
410 (window)
411 Lisp_Object window;
413 return decode_any_window (window)->total_lines;
416 DEFUN ("window-width", Fwindow_width, Swindow_width, 0, 1, 0,
417 doc: /* Return the number of display columns in WINDOW.
418 This is the width that is usable columns available for text in WINDOW.
419 If you want to find out how many columns WINDOW takes up,
420 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
421 (window)
422 Lisp_Object window;
424 return make_number (window_box_text_cols (decode_any_window (window)));
427 DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0,
428 doc: /* Return the number of columns by which WINDOW is scrolled from left margin. */)
429 (window)
430 Lisp_Object window;
432 return decode_window (window)->hscroll;
435 DEFUN ("set-window-hscroll", Fset_window_hscroll, Sset_window_hscroll, 2, 2, 0,
436 doc: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
437 Return NCOL. NCOL should be zero or positive.
439 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
440 window so that the location of point becomes invisible. */)
441 (window, ncol)
442 Lisp_Object window, ncol;
444 struct window *w = decode_window (window);
445 int hscroll;
447 CHECK_NUMBER (ncol);
448 hscroll = max (0, XINT (ncol));
450 /* Prevent redisplay shortcuts when changing the hscroll. */
451 if (XINT (w->hscroll) != hscroll)
452 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
454 w->hscroll = make_number (hscroll);
455 return ncol;
458 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger,
459 Swindow_redisplay_end_trigger, 0, 1, 0,
460 doc: /* Return WINDOW's redisplay end trigger value.
461 See `set-window-redisplay-end-trigger' for more information. */)
462 (window)
463 Lisp_Object window;
465 return decode_window (window)->redisplay_end_trigger;
468 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger,
469 Sset_window_redisplay_end_trigger, 2, 2, 0,
470 doc: /* Set WINDOW's redisplay end trigger value to VALUE.
471 VALUE should be a buffer position (typically a marker) or nil.
472 If it is a buffer position, then if redisplay in WINDOW reaches a position
473 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
474 with two arguments: WINDOW, and the end trigger value.
475 Afterwards the end-trigger value is reset to nil. */)
476 (window, value)
477 register Lisp_Object window, value;
479 register struct window *w;
481 w = decode_window (window);
482 w->redisplay_end_trigger = value;
483 return value;
486 DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0,
487 doc: /* Return a list of the edge coordinates of WINDOW.
488 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
489 RIGHT is one more than the rightmost column occupied by WINDOW,
490 and BOTTOM is one more than the bottommost row occupied by WINDOW.
491 The edges include the space used by the window's scroll bar,
492 display margins, fringes, header line, and mode line, if it has them.
493 To get the edges of the actual text area, use `window-inside-edges'. */)
494 (window)
495 Lisp_Object window;
497 register struct window *w = decode_any_window (window);
499 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w)),
500 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w)),
501 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w)),
502 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w)),
503 Qnil))));
506 DEFUN ("window-pixel-edges", Fwindow_pixel_edges, Swindow_pixel_edges, 0, 1, 0,
507 doc: /* Return a list of the edge pixel coordinates of WINDOW.
508 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
509 RIGHT is one more than the rightmost x position occupied by WINDOW,
510 and BOTTOM is one more than the bottommost y position occupied by WINDOW.
511 The pixel edges include the space used by the window's scroll bar,
512 display margins, fringes, header line, and mode line, if it has them.
513 To get the edges of the actual text area, use `window-inside-pixel-edges'. */)
514 (window)
515 Lisp_Object window;
517 register struct window *w = decode_any_window (window);
519 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w)),
520 Fcons (make_number (WINDOW_TOP_EDGE_Y (w)),
521 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w)),
522 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w)),
523 Qnil))));
526 DEFUN ("window-inside-edges", Fwindow_inside_edges, Swindow_inside_edges, 0, 1, 0,
527 doc: /* Return a list of the edge coordinates of WINDOW.
528 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
529 RIGHT is one more than the rightmost column used by text in WINDOW,
530 and BOTTOM is one more than the bottommost row used by text in WINDOW.
531 The inside edges do not include the space used by the window's scroll bar,
532 display margins, fringes, header line, and/or mode line. */)
533 (window)
534 Lisp_Object window;
536 register struct window *w = decode_any_window (window);
538 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w)
539 + WINDOW_LEFT_MARGIN_COLS (w)
540 + WINDOW_LEFT_FRINGE_COLS (w)),
541 make_number (WINDOW_TOP_EDGE_LINE (w)
542 + WINDOW_HEADER_LINE_LINES (w)),
543 make_number (WINDOW_RIGHT_EDGE_COL (w)
544 - WINDOW_RIGHT_MARGIN_COLS (w)
545 - WINDOW_RIGHT_FRINGE_COLS (w)),
546 make_number (WINDOW_BOTTOM_EDGE_LINE (w)
547 - WINDOW_MODE_LINE_LINES (w)));
550 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges, Swindow_inside_pixel_edges, 0, 1, 0,
551 doc: /* Return a list of the edge pixel coordinates of WINDOW.
552 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
553 RIGHT is one more than the rightmost x position used by text in WINDOW,
554 and BOTTOM is one more than the bottommost y position used by text in WINDOW.
555 The inside edges do not include the space used by the window's scroll bar,
556 display margins, fringes, header line, and/or mode line. */)
557 (window)
558 Lisp_Object window;
560 register struct window *w = decode_any_window (window);
562 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w)
563 + WINDOW_LEFT_MARGIN_WIDTH (w)
564 + WINDOW_LEFT_FRINGE_WIDTH (w)),
565 make_number (WINDOW_TOP_EDGE_Y (w)
566 + WINDOW_HEADER_LINE_HEIGHT (w)),
567 make_number (WINDOW_RIGHT_EDGE_X (w)
568 - WINDOW_RIGHT_MARGIN_WIDTH (w)
569 - WINDOW_RIGHT_FRINGE_WIDTH (w)),
570 make_number (WINDOW_BOTTOM_EDGE_Y (w)
571 - WINDOW_MODE_LINE_HEIGHT (w)));
574 /* Test if the character at column *X, row *Y is within window W.
575 If it is not, return ON_NOTHING;
576 if it is in the window's text area,
577 set *x and *y to its location relative to the upper left corner
578 of the window, and
579 return ON_TEXT;
580 if it is on the window's modeline, return ON_MODE_LINE;
581 if it is on the border between the window and its right sibling,
582 return ON_VERTICAL_BORDER.
583 if it is on a scroll bar,
584 return ON_SCROLL_BAR.
585 if it is on the window's top line, return ON_HEADER_LINE;
586 if it is in left or right fringe of the window,
587 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y
588 to window-relative coordinates;
589 if it is in the marginal area to the left/right of the window,
590 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y
591 to window-relative coordinates.
593 X and Y are frame relative pixel coordinates. */
595 static enum window_part
596 coordinates_in_window (w, x, y)
597 register struct window *w;
598 register int *x, *y;
600 struct frame *f = XFRAME (WINDOW_FRAME (w));
601 int left_x, right_x, top_y, bottom_y;
602 enum window_part part;
603 int ux = FRAME_COLUMN_WIDTH (f);
604 int x0 = WINDOW_LEFT_EDGE_X (w);
605 int x1 = WINDOW_RIGHT_EDGE_X (w);
606 /* The width of the area where the vertical line can be dragged.
607 (Between mode lines for instance. */
608 int grabbable_width = ux;
609 int lmargin_width, rmargin_width, text_left, text_right;
611 /* In what's below, we subtract 1 when computing right_x because we
612 want the rightmost pixel, which is given by left_pixel+width-1. */
613 if (w->pseudo_window_p)
615 left_x = 0;
616 right_x = WINDOW_TOTAL_WIDTH (w) - 1;
617 top_y = WINDOW_TOP_EDGE_Y (w);
618 bottom_y = WINDOW_BOTTOM_EDGE_Y (w);
620 else
622 left_x = WINDOW_BOX_LEFT_EDGE_X (w);
623 right_x = WINDOW_BOX_RIGHT_EDGE_X (w) - 1;
624 top_y = WINDOW_TOP_EDGE_Y (w);
625 bottom_y = WINDOW_BOTTOM_EDGE_Y (w);
628 /* Outside any interesting row? */
629 if (*y < top_y || *y >= bottom_y)
630 return ON_NOTHING;
632 /* On the mode line or header line? If it's near the start of
633 the mode or header line of window that's has a horizontal
634 sibling, say it's on the vertical line. That's to be able
635 to resize windows horizontally in case we're using toolkit
636 scroll bars. */
638 if (WINDOW_WANTS_MODELINE_P (w)
639 && *y >= bottom_y - CURRENT_MODE_LINE_HEIGHT (w))
641 part = ON_MODE_LINE;
643 header_vertical_border_check:
644 /* We're somewhere on the mode line. We consider the place
645 between mode lines of horizontally adjacent mode lines
646 as the vertical border. If scroll bars on the left,
647 return the right window. */
648 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)
649 || WINDOW_RIGHTMOST_P (w))
651 if (!WINDOW_LEFTMOST_P (w) && abs (*x - x0) < grabbable_width)
652 return ON_VERTICAL_BORDER;
654 else
656 if (abs (*x - x1) < grabbable_width)
657 return ON_VERTICAL_BORDER;
660 if (*x < x0 || *x >= x1)
661 return ON_NOTHING;
663 /* Convert X and Y to window relative coordinates.
664 Mode line starts at left edge of window. */
665 *x -= x0;
666 *y -= top_y;
667 return part;
670 if (WINDOW_WANTS_HEADER_LINE_P (w)
671 && *y < top_y + CURRENT_HEADER_LINE_HEIGHT (w))
673 part = ON_HEADER_LINE;
674 goto header_vertical_border_check;
677 if (*x < x0 || *x >= x1)
678 return ON_NOTHING;
680 /* Outside any interesting column? */
681 if (*x < left_x || *x > right_x)
682 return ON_SCROLL_BAR;
684 lmargin_width = window_box_width (w, LEFT_MARGIN_AREA);
685 rmargin_width = window_box_width (w, RIGHT_MARGIN_AREA);
687 text_left = window_box_left (w, TEXT_AREA);
688 text_right = text_left + window_box_width (w, TEXT_AREA);
690 if (FRAME_WINDOW_P (f))
692 if (!w->pseudo_window_p
693 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w)
694 && !WINDOW_RIGHTMOST_P (w)
695 && (abs (*x - right_x) < grabbable_width))
696 return ON_VERTICAL_BORDER;
698 else
700 /* Need to say "*x > right_x" rather than >=, since on character
701 terminals, the vertical line's x coordinate is right_x. */
702 if (!w->pseudo_window_p
703 && !WINDOW_RIGHTMOST_P (w)
704 && *x > right_x - ux)
706 /* On the border on the right side of the window? Assume that
707 this area begins at RIGHT_X minus a canonical char width. */
708 return ON_VERTICAL_BORDER;
712 if (*x < text_left)
714 if (lmargin_width > 0
715 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
716 ? (*x >= left_x + WINDOW_LEFT_FRINGE_WIDTH (w))
717 : (*x < left_x + lmargin_width)))
719 *x -= left_x;
720 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
721 *x -= WINDOW_LEFT_FRINGE_WIDTH (w);
722 *y -= top_y;
723 return ON_LEFT_MARGIN;
726 /* Convert X and Y to window-relative pixel coordinates. */
727 *x -= left_x;
728 *y -= top_y;
729 return ON_LEFT_FRINGE;
732 if (*x >= text_right)
734 if (rmargin_width > 0
735 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
736 ? (*x < right_x - WINDOW_RIGHT_FRINGE_WIDTH (w))
737 : (*x >= right_x - rmargin_width)))
739 *x -= right_x;
740 if (!WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
741 *x -= WINDOW_RIGHT_FRINGE_WIDTH (w);
742 *y -= top_y;
743 return ON_RIGHT_MARGIN;
746 /* Convert X and Y to window-relative pixel coordinates. */
747 *x -= left_x + WINDOW_LEFT_FRINGE_WIDTH (w);
748 *y -= top_y;
749 return ON_RIGHT_FRINGE;
752 /* Everything special ruled out - must be on text area */
753 *x -= left_x + WINDOW_LEFT_FRINGE_WIDTH (w);
754 *y -= top_y;
755 return ON_TEXT;
759 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
760 Scoordinates_in_window_p, 2, 2, 0,
761 doc: /* Return non-nil if COORDINATES are in WINDOW.
762 COORDINATES is a cons of the form (X . Y), X and Y being distances
763 measured in characters from the upper-left corner of the frame.
764 \(0 . 0) denotes the character in the upper left corner of the
765 frame.
766 If COORDINATES are in the text portion of WINDOW,
767 the coordinates relative to the window are returned.
768 If they are in the mode line of WINDOW, `mode-line' is returned.
769 If they are in the top mode line of WINDOW, `header-line' is returned.
770 If they are in the left fringe of WINDOW, `left-fringe' is returned.
771 If they are in the right fringe of WINDOW, `right-fringe' is returned.
772 If they are on the border between WINDOW and its right sibling,
773 `vertical-line' is returned.
774 If they are in the windows's left or right marginal areas, `left-margin'\n\
775 or `right-margin' is returned. */)
776 (coordinates, window)
777 register Lisp_Object coordinates, window;
779 struct window *w;
780 struct frame *f;
781 int x, y;
782 Lisp_Object lx, ly;
784 CHECK_WINDOW (window);
785 w = XWINDOW (window);
786 f = XFRAME (w->frame);
787 CHECK_CONS (coordinates);
788 lx = Fcar (coordinates);
789 ly = Fcdr (coordinates);
790 CHECK_NUMBER_OR_FLOAT (lx);
791 CHECK_NUMBER_OR_FLOAT (ly);
792 x = FRAME_PIXEL_X_FROM_CANON_X (f, lx) + FRAME_INTERNAL_BORDER_WIDTH (f);
793 y = FRAME_PIXEL_Y_FROM_CANON_Y (f, ly) + FRAME_INTERNAL_BORDER_WIDTH (f);
795 switch (coordinates_in_window (w, &x, &y))
797 case ON_NOTHING:
798 return Qnil;
800 case ON_TEXT:
801 /* X and Y are now window relative pixel coordinates. Convert
802 them to canonical char units before returning them. */
803 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f, x),
804 FRAME_CANON_Y_FROM_PIXEL_Y (f, y));
806 case ON_MODE_LINE:
807 return Qmode_line;
809 case ON_VERTICAL_BORDER:
810 return Qvertical_line;
812 case ON_HEADER_LINE:
813 return Qheader_line;
815 case ON_LEFT_FRINGE:
816 return Qleft_fringe;
818 case ON_RIGHT_FRINGE:
819 return Qright_fringe;
821 case ON_LEFT_MARGIN:
822 return Qleft_margin;
824 case ON_RIGHT_MARGIN:
825 return Qright_margin;
827 case ON_SCROLL_BAR:
828 /* Historically we are supposed to return nil in this case. */
829 return Qnil;
831 default:
832 abort ();
837 /* Callback for foreach_window, used in window_from_coordinates.
838 Check if window W contains coordinates specified by USER_DATA which
839 is actually a pointer to a struct check_window_data CW.
841 Check if window W contains coordinates *CW->x and *CW->y. If it
842 does, return W in *CW->window, as Lisp_Object, and return in
843 *CW->part the part of the window under coordinates *X,*Y. Return
844 zero from this function to stop iterating over windows. */
846 struct check_window_data
848 Lisp_Object *window;
849 int *x, *y;
850 enum window_part *part;
853 static int
854 check_window_containing (w, user_data)
855 struct window *w;
856 void *user_data;
858 struct check_window_data *cw = (struct check_window_data *) user_data;
859 enum window_part found;
860 int continue_p = 1;
862 found = coordinates_in_window (w, cw->x, cw->y);
863 if (found != ON_NOTHING)
865 *cw->part = found;
866 XSETWINDOW (*cw->window, w);
867 continue_p = 0;
870 return continue_p;
874 /* Find the window containing frame-relative pixel position X/Y and
875 return it as a Lisp_Object.
877 If X, Y is on one of the window's special `window_part' elements,
878 set *PART to the id of that element, and return X and Y converted
879 to window relative coordinates in WX and WY.
881 If there is no window under X, Y return nil and leave *PART
882 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
884 This function was previously implemented with a loop cycling over
885 windows with Fnext_window, and starting with the frame's selected
886 window. It turned out that this doesn't work with an
887 implementation of next_window using Vwindow_list, because
888 FRAME_SELECTED_WINDOW (F) is not always contained in the window
889 tree of F when this function is called asynchronously from
890 note_mouse_highlight. The original loop didn't terminate in this
891 case. */
893 Lisp_Object
894 window_from_coordinates (f, x, y, part, wx, wy, tool_bar_p)
895 struct frame *f;
896 int x, y;
897 enum window_part *part;
898 int *wx, *wy;
899 int tool_bar_p;
901 Lisp_Object window;
902 struct check_window_data cw;
903 enum window_part dummy;
905 if (part == 0)
906 part = &dummy;
908 window = Qnil;
909 cw.window = &window, cw.x = &x, cw.y = &y; cw.part = part;
910 foreach_window (f, check_window_containing, &cw);
912 /* If not found above, see if it's in the tool bar window, if a tool
913 bar exists. */
914 if (NILP (window)
915 && tool_bar_p
916 && WINDOWP (f->tool_bar_window)
917 && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window)) > 0
918 && (coordinates_in_window (XWINDOW (f->tool_bar_window), &x, &y)
919 != ON_NOTHING))
921 *part = ON_TEXT;
922 window = f->tool_bar_window;
925 if (wx) *wx = x;
926 if (wy) *wy = y;
928 return window;
931 DEFUN ("window-at", Fwindow_at, Swindow_at, 2, 3, 0,
932 doc: /* Return window containing coordinates X and Y on FRAME.
933 If omitted, FRAME defaults to the currently selected frame.
934 The top left corner of the frame is considered to be row 0,
935 column 0. */)
936 (x, y, frame)
937 Lisp_Object x, y, frame;
939 struct frame *f;
941 if (NILP (frame))
942 frame = selected_frame;
943 CHECK_LIVE_FRAME (frame);
944 f = XFRAME (frame);
946 /* Check that arguments are integers or floats. */
947 CHECK_NUMBER_OR_FLOAT (x);
948 CHECK_NUMBER_OR_FLOAT (y);
950 return window_from_coordinates (f,
951 (FRAME_PIXEL_X_FROM_CANON_X (f, x)
952 + FRAME_INTERNAL_BORDER_WIDTH (f)),
953 (FRAME_PIXEL_Y_FROM_CANON_Y (f, y)
954 + FRAME_INTERNAL_BORDER_WIDTH (f)),
955 0, 0, 0, 0);
958 DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0,
959 doc: /* Return current value of point in WINDOW.
960 For a nonselected window, this is the value point would have
961 if that window were selected.
963 Note that, when WINDOW is the selected window and its buffer
964 is also currently selected, the value returned is the same as (point).
965 It would be more strictly correct to return the `top-level' value
966 of point, outside of any save-excursion forms.
967 But that is hard to define. */)
968 (window)
969 Lisp_Object window;
971 register struct window *w = decode_window (window);
973 if (w == XWINDOW (selected_window)
974 && current_buffer == XBUFFER (w->buffer))
975 return Fpoint ();
976 return Fmarker_position (w->pointm);
979 DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0,
980 doc: /* Return position at which display currently starts in WINDOW.
981 This is updated by redisplay or by calling `set-window-start'. */)
982 (window)
983 Lisp_Object window;
985 return Fmarker_position (decode_window (window)->start);
988 /* This is text temporarily removed from the doc string below.
990 This function returns nil if the position is not currently known.
991 That happens when redisplay is preempted and doesn't finish.
992 If in that case you want to compute where the end of the window would
993 have been if redisplay had finished, do this:
994 (save-excursion
995 (goto-char (window-start window))
996 (vertical-motion (1- (window-height window)) window)
997 (point))") */
999 DEFUN ("window-end", Fwindow_end, Swindow_end, 0, 2, 0,
1000 doc: /* Return position at which display currently ends in WINDOW.
1001 This is updated by redisplay, when it runs to completion.
1002 Simply changing the buffer text or setting `window-start'
1003 does not update this value.
1004 Return nil if there is no recorded value. \(This can happen if the
1005 last redisplay of WINDOW was preempted, and did not finish.)
1006 If UPDATE is non-nil, compute the up-to-date position
1007 if it isn't already recorded. */)
1008 (window, update)
1009 Lisp_Object window, update;
1011 Lisp_Object value;
1012 struct window *w = decode_window (window);
1013 Lisp_Object buf;
1015 buf = w->buffer;
1016 CHECK_BUFFER (buf);
1018 #if 0 /* This change broke some things. We should make it later. */
1019 /* If we don't know the end position, return nil.
1020 The user can compute it with vertical-motion if he wants to.
1021 It would be nicer to do it automatically,
1022 but that's so slow that it would probably bother people. */
1023 if (NILP (w->window_end_valid))
1024 return Qnil;
1025 #endif
1027 if (! NILP (update)
1028 && ! (! NILP (w->window_end_valid)
1029 && XFASTINT (w->last_modified) >= MODIFF))
1031 struct text_pos startp;
1032 struct it it;
1033 struct buffer *old_buffer = NULL, *b = XBUFFER (buf);
1035 /* In case W->start is out of the range, use something
1036 reasonable. This situation occurred when loading a file with
1037 `-l' containing a call to `rmail' with subsequent other
1038 commands. At the end, W->start happened to be BEG, while
1039 rmail had already narrowed the buffer. */
1040 if (XMARKER (w->start)->charpos < BEGV)
1041 SET_TEXT_POS (startp, BEGV, BEGV_BYTE);
1042 else if (XMARKER (w->start)->charpos > ZV)
1043 SET_TEXT_POS (startp, ZV, ZV_BYTE);
1044 else
1045 SET_TEXT_POS_FROM_MARKER (startp, w->start);
1047 /* Cannot use Fvertical_motion because that function doesn't
1048 cope with variable-height lines. */
1049 if (b != current_buffer)
1051 old_buffer = current_buffer;
1052 set_buffer_internal (b);
1055 start_display (&it, w, startp);
1056 move_it_vertically (&it, window_box_height (w));
1057 if (it.current_y < it.last_visible_y)
1058 move_it_past_eol (&it);
1059 value = make_number (IT_CHARPOS (it));
1061 if (old_buffer)
1062 set_buffer_internal (old_buffer);
1064 else
1065 XSETINT (value, BUF_Z (XBUFFER (buf)) - XFASTINT (w->window_end_pos));
1067 return value;
1070 DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0,
1071 doc: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1072 Return POS. */)
1073 (window, pos)
1074 Lisp_Object window, pos;
1076 register struct window *w = decode_window (window);
1078 CHECK_NUMBER_COERCE_MARKER (pos);
1079 if (w == XWINDOW (selected_window)
1080 && XBUFFER (w->buffer) == current_buffer)
1081 Fgoto_char (pos);
1082 else
1083 set_marker_restricted (w->pointm, pos, w->buffer);
1085 /* We have to make sure that redisplay updates the window to show
1086 the new value of point. */
1087 if (!EQ (window, selected_window))
1088 ++windows_or_buffers_changed;
1090 return pos;
1093 DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0,
1094 doc: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1095 Return POS.
1096 Optional third arg NOFORCE non-nil inhibits next redisplay
1097 from overriding motion of point in order to display at this exact start. */)
1098 (window, pos, noforce)
1099 Lisp_Object window, pos, noforce;
1101 register struct window *w = decode_window (window);
1103 CHECK_NUMBER_COERCE_MARKER (pos);
1104 set_marker_restricted (w->start, pos, w->buffer);
1105 /* this is not right, but much easier than doing what is right. */
1106 w->start_at_line_beg = Qnil;
1107 if (NILP (noforce))
1108 w->force_start = Qt;
1109 w->update_mode_line = Qt;
1110 XSETFASTINT (w->last_modified, 0);
1111 XSETFASTINT (w->last_overlay_modified, 0);
1112 if (!EQ (window, selected_window))
1113 windows_or_buffers_changed++;
1115 return pos;
1118 DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p,
1119 1, 1, 0,
1120 doc: /* Return WINDOW's dedicated object, usually t or nil.
1121 See also `set-window-dedicated-p'. */)
1122 (window)
1123 Lisp_Object window;
1125 return decode_window (window)->dedicated;
1128 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p,
1129 Sset_window_dedicated_p, 2, 2, 0,
1130 doc: /* Control whether WINDOW is dedicated to the buffer it displays.
1131 If it is dedicated, Emacs will not automatically change
1132 which buffer appears in it.
1133 The second argument is the new value for the dedication flag;
1134 non-nil means yes. */)
1135 (window, arg)
1136 Lisp_Object window, arg;
1138 register struct window *w = decode_window (window);
1140 w->dedicated = arg;
1142 return w->dedicated;
1145 DEFUN ("window-display-table", Fwindow_display_table, Swindow_display_table,
1146 0, 1, 0,
1147 doc: /* Return the display-table that WINDOW is using. */)
1148 (window)
1149 Lisp_Object window;
1151 return decode_window (window)->display_table;
1154 /* Get the display table for use on window W. This is either W's
1155 display table or W's buffer's display table. Ignore the specified
1156 tables if they are not valid; if no valid table is specified,
1157 return 0. */
1159 struct Lisp_Char_Table *
1160 window_display_table (w)
1161 struct window *w;
1163 struct Lisp_Char_Table *dp = NULL;
1165 if (DISP_TABLE_P (w->display_table))
1166 dp = XCHAR_TABLE (w->display_table);
1167 else if (BUFFERP (w->buffer))
1169 struct buffer *b = XBUFFER (w->buffer);
1171 if (DISP_TABLE_P (b->display_table))
1172 dp = XCHAR_TABLE (b->display_table);
1173 else if (DISP_TABLE_P (Vstandard_display_table))
1174 dp = XCHAR_TABLE (Vstandard_display_table);
1177 return dp;
1180 DEFUN ("set-window-display-table", Fset_window_display_table, Sset_window_display_table, 2, 2, 0,
1181 doc: /* Set WINDOW's display-table to TABLE. */)
1182 (window, table)
1183 register Lisp_Object window, table;
1185 register struct window *w;
1187 w = decode_window (window);
1188 w->display_table = table;
1189 return table;
1192 /* Record info on buffer window w is displaying
1193 when it is about to cease to display that buffer. */
1194 static void
1195 unshow_buffer (w)
1196 register struct window *w;
1198 Lisp_Object buf;
1199 struct buffer *b;
1201 buf = w->buffer;
1202 b = XBUFFER (buf);
1203 if (b != XMARKER (w->pointm)->buffer)
1204 abort ();
1206 #if 0
1207 if (w == XWINDOW (selected_window)
1208 || ! EQ (buf, XWINDOW (selected_window)->buffer))
1209 /* Do this except when the selected window's buffer
1210 is being removed from some other window. */
1211 #endif
1212 /* last_window_start records the start position that this buffer
1213 had in the last window to be disconnected from it.
1214 Now that this statement is unconditional,
1215 it is possible for the buffer to be displayed in the
1216 selected window, while last_window_start reflects another
1217 window which was recently showing the same buffer.
1218 Some people might say that might be a good thing. Let's see. */
1219 b->last_window_start = marker_position (w->start);
1221 /* Point in the selected window's buffer
1222 is actually stored in that buffer, and the window's pointm isn't used.
1223 So don't clobber point in that buffer. */
1224 if (! EQ (buf, XWINDOW (selected_window)->buffer)
1225 /* This line helps to fix Horsley's testbug.el bug. */
1226 && !(WINDOWP (b->last_selected_window)
1227 && w != XWINDOW (b->last_selected_window)
1228 && EQ (buf, XWINDOW (b->last_selected_window)->buffer)))
1229 temp_set_point_both (b,
1230 clip_to_bounds (BUF_BEGV (b),
1231 XMARKER (w->pointm)->charpos,
1232 BUF_ZV (b)),
1233 clip_to_bounds (BUF_BEGV_BYTE (b),
1234 marker_byte_position (w->pointm),
1235 BUF_ZV_BYTE (b)));
1237 if (WINDOWP (b->last_selected_window)
1238 && w == XWINDOW (b->last_selected_window))
1239 b->last_selected_window = Qnil;
1242 /* Put replacement into the window structure in place of old. */
1243 static void
1244 replace_window (old, replacement)
1245 Lisp_Object old, replacement;
1247 register Lisp_Object tem;
1248 register struct window *o = XWINDOW (old), *p = XWINDOW (replacement);
1250 /* If OLD is its frame's root_window, then replacement is the new
1251 root_window for that frame. */
1253 if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame))))
1254 FRAME_ROOT_WINDOW (XFRAME (o->frame)) = replacement;
1256 p->left_col = o->left_col;
1257 p->top_line = o->top_line;
1258 p->total_cols = o->total_cols;
1259 p->total_lines = o->total_lines;
1260 p->desired_matrix = p->current_matrix = 0;
1261 p->vscroll = 0;
1262 bzero (&p->cursor, sizeof (p->cursor));
1263 bzero (&p->last_cursor, sizeof (p->last_cursor));
1264 bzero (&p->phys_cursor, sizeof (p->phys_cursor));
1265 p->phys_cursor_type = -1;
1266 p->phys_cursor_width = -1;
1267 p->must_be_updated_p = 0;
1268 p->pseudo_window_p = 0;
1269 XSETFASTINT (p->window_end_vpos, 0);
1270 XSETFASTINT (p->window_end_pos, 0);
1271 p->window_end_valid = Qnil;
1272 p->frozen_window_start_p = 0;
1273 p->orig_top_line = p->orig_total_lines = Qnil;
1275 p->next = tem = o->next;
1276 if (!NILP (tem))
1277 XWINDOW (tem)->prev = replacement;
1279 p->prev = tem = o->prev;
1280 if (!NILP (tem))
1281 XWINDOW (tem)->next = replacement;
1283 p->parent = tem = o->parent;
1284 if (!NILP (tem))
1286 if (EQ (XWINDOW (tem)->vchild, old))
1287 XWINDOW (tem)->vchild = replacement;
1288 if (EQ (XWINDOW (tem)->hchild, old))
1289 XWINDOW (tem)->hchild = replacement;
1292 /*** Here, if replacement is a vertical combination
1293 and so is its new parent, we should make replacement's
1294 children be children of that parent instead. ***/
1297 DEFUN ("delete-window", Fdelete_window, Sdelete_window, 0, 1, "",
1298 doc: /* Remove WINDOW from the display. Default is selected window. */)
1299 (window)
1300 register Lisp_Object window;
1302 delete_window (window);
1304 if (! NILP (Vwindow_configuration_change_hook)
1305 && ! NILP (Vrun_hooks))
1306 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
1308 return Qnil;
1311 void
1312 delete_window (window)
1313 register Lisp_Object window;
1315 register Lisp_Object tem, parent, sib;
1316 register struct window *p;
1317 register struct window *par;
1318 struct frame *f;
1320 /* Because this function is called by other C code on non-leaf
1321 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1322 so we can't decode_window here. */
1323 if (NILP (window))
1324 window = selected_window;
1325 else
1326 CHECK_WINDOW (window);
1327 p = XWINDOW (window);
1329 /* It's okay to delete an already-deleted window. */
1330 if (NILP (p->buffer)
1331 && NILP (p->hchild)
1332 && NILP (p->vchild))
1333 return;
1335 parent = p->parent;
1336 if (NILP (parent))
1337 error ("Attempt to delete minibuffer or sole ordinary window");
1338 par = XWINDOW (parent);
1340 windows_or_buffers_changed++;
1341 Vwindow_list = Qnil;
1342 f = XFRAME (WINDOW_FRAME (p));
1343 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
1345 /* Are we trying to delete any frame's selected window? */
1347 Lisp_Object swindow, pwindow;
1349 /* See if the frame's selected window is either WINDOW
1350 or any subwindow of it, by finding all that window's parents
1351 and comparing each one with WINDOW. */
1352 swindow = FRAME_SELECTED_WINDOW (f);
1354 while (1)
1356 pwindow = swindow;
1357 while (!NILP (pwindow))
1359 if (EQ (window, pwindow))
1360 break;
1361 pwindow = XWINDOW (pwindow)->parent;
1364 /* If the window being deleted is not a parent of SWINDOW,
1365 then SWINDOW is ok as the new selected window. */
1366 if (!EQ (window, pwindow))
1367 break;
1368 /* Otherwise, try another window for SWINDOW. */
1369 swindow = Fnext_window (swindow, Qlambda, Qnil);;
1371 /* If we get back to the frame's selected window,
1372 it means there was no acceptable alternative,
1373 so we cannot delete. */
1374 if (EQ (swindow, FRAME_SELECTED_WINDOW (f)))
1375 error ("Cannot delete window");
1378 /* If we need to change SWINDOW, do it. */
1379 if (! EQ (swindow, FRAME_SELECTED_WINDOW (f)))
1381 /* If we're about to delete the selected window on the
1382 selected frame, then we should use Fselect_window to select
1383 the new window. On the other hand, if we're about to
1384 delete the selected window on any other frame, we shouldn't do
1385 anything but set the frame's selected_window slot. */
1386 if (EQ (FRAME_SELECTED_WINDOW (f), selected_window))
1387 Fselect_window (swindow, Qnil);
1388 else
1389 FRAME_SELECTED_WINDOW (f) = swindow;
1393 tem = p->buffer;
1394 /* tem is null for dummy parent windows
1395 (which have inferiors but not any contents themselves) */
1396 if (!NILP (tem))
1398 unshow_buffer (p);
1399 unchain_marker (XMARKER (p->pointm));
1400 unchain_marker (XMARKER (p->start));
1403 /* Free window glyph matrices. It is sure that they are allocated
1404 again when ADJUST_GLYPHS is called. Block input so that expose
1405 events and other events that access glyph matrices are not
1406 processed while we are changing them. */
1407 BLOCK_INPUT;
1408 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f)));
1410 tem = p->next;
1411 if (!NILP (tem))
1412 XWINDOW (tem)->prev = p->prev;
1414 tem = p->prev;
1415 if (!NILP (tem))
1416 XWINDOW (tem)->next = p->next;
1418 if (EQ (window, par->hchild))
1419 par->hchild = p->next;
1420 if (EQ (window, par->vchild))
1421 par->vchild = p->next;
1423 /* Find one of our siblings to give our space to. */
1424 sib = p->prev;
1425 if (NILP (sib))
1427 /* If p gives its space to its next sibling, that sibling needs
1428 to have its top/left side pulled back to where p's is.
1429 set_window_{height,width} will re-position the sibling's
1430 children. */
1431 sib = p->next;
1432 XWINDOW (sib)->top_line = p->top_line;
1433 XWINDOW (sib)->left_col = p->left_col;
1436 /* Stretch that sibling. */
1437 if (!NILP (par->vchild))
1438 set_window_height (sib,
1439 XFASTINT (XWINDOW (sib)->total_lines) + XFASTINT (p->total_lines),
1441 if (!NILP (par->hchild))
1442 set_window_width (sib,
1443 XFASTINT (XWINDOW (sib)->total_cols) + XFASTINT (p->total_cols),
1446 /* If parent now has only one child,
1447 put the child into the parent's place. */
1448 tem = par->hchild;
1449 if (NILP (tem))
1450 tem = par->vchild;
1451 if (NILP (XWINDOW (tem)->next))
1452 replace_window (parent, tem);
1454 /* Since we may be deleting combination windows, we must make sure that
1455 not only p but all its children have been marked as deleted. */
1456 if (! NILP (p->hchild))
1457 delete_all_subwindows (XWINDOW (p->hchild));
1458 else if (! NILP (p->vchild))
1459 delete_all_subwindows (XWINDOW (p->vchild));
1461 /* Mark this window as deleted. */
1462 p->buffer = p->hchild = p->vchild = Qnil;
1464 /* Adjust glyph matrices. */
1465 adjust_glyphs (f);
1466 UNBLOCK_INPUT;
1471 /***********************************************************************
1472 Window List
1473 ***********************************************************************/
1475 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1476 pointer. This is a callback function for foreach_window, used in
1477 function window_list. */
1479 static int
1480 add_window_to_list (w, user_data)
1481 struct window *w;
1482 void *user_data;
1484 Lisp_Object *list = (Lisp_Object *) user_data;
1485 Lisp_Object window;
1486 XSETWINDOW (window, w);
1487 *list = Fcons (window, *list);
1488 return 1;
1492 /* Return a list of all windows, for use by next_window. If
1493 Vwindow_list is a list, return that list. Otherwise, build a new
1494 list, cache it in Vwindow_list, and return that. */
1496 static Lisp_Object
1497 window_list ()
1499 if (!CONSP (Vwindow_list))
1501 Lisp_Object tail;
1503 Vwindow_list = Qnil;
1504 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1506 Lisp_Object args[2];
1508 /* We are visiting windows in canonical order, and add
1509 new windows at the front of args[1], which means we
1510 have to reverse this list at the end. */
1511 args[1] = Qnil;
1512 foreach_window (XFRAME (XCAR (tail)), add_window_to_list, &args[1]);
1513 args[0] = Vwindow_list;
1514 args[1] = Fnreverse (args[1]);
1515 Vwindow_list = Fnconc (2, args);
1519 return Vwindow_list;
1523 /* Value is non-zero if WINDOW satisfies the constraints given by
1524 OWINDOW, MINIBUF and ALL_FRAMES.
1526 MINIBUF t means WINDOW may be minibuffer windows.
1527 `lambda' means WINDOW may not be a minibuffer window.
1528 a window means a specific minibuffer window
1530 ALL_FRAMES t means search all frames,
1531 nil means search just current frame,
1532 `visible' means search just visible frames,
1533 0 means search visible and iconified frames,
1534 a window means search the frame that window belongs to,
1535 a frame means consider windows on that frame, only. */
1537 static int
1538 candidate_window_p (window, owindow, minibuf, all_frames)
1539 Lisp_Object window, owindow, minibuf, all_frames;
1541 struct window *w = XWINDOW (window);
1542 struct frame *f = XFRAME (w->frame);
1543 int candidate_p = 1;
1545 if (!BUFFERP (w->buffer))
1546 candidate_p = 0;
1547 else if (MINI_WINDOW_P (w)
1548 && (EQ (minibuf, Qlambda)
1549 || (WINDOWP (minibuf) && !EQ (minibuf, window))))
1551 /* If MINIBUF is `lambda' don't consider any mini-windows.
1552 If it is a window, consider only that one. */
1553 candidate_p = 0;
1555 else if (EQ (all_frames, Qt))
1556 candidate_p = 1;
1557 else if (NILP (all_frames))
1559 xassert (WINDOWP (owindow));
1560 candidate_p = EQ (w->frame, XWINDOW (owindow)->frame);
1562 else if (EQ (all_frames, Qvisible))
1564 FRAME_SAMPLE_VISIBILITY (f);
1565 candidate_p = FRAME_VISIBLE_P (f);
1567 else if (INTEGERP (all_frames) && XINT (all_frames) == 0)
1569 FRAME_SAMPLE_VISIBILITY (f);
1570 candidate_p = FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f);
1572 else if (WINDOWP (all_frames))
1573 candidate_p = (EQ (FRAME_MINIBUF_WINDOW (f), all_frames)
1574 || EQ (XWINDOW (all_frames)->frame, w->frame)
1575 || EQ (XWINDOW (all_frames)->frame, FRAME_FOCUS_FRAME (f)));
1576 else if (FRAMEP (all_frames))
1577 candidate_p = EQ (all_frames, w->frame);
1579 return candidate_p;
1583 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1584 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1585 ALL_FRAMES. */
1587 static void
1588 decode_next_window_args (window, minibuf, all_frames)
1589 Lisp_Object *window, *minibuf, *all_frames;
1591 if (NILP (*window))
1592 *window = selected_window;
1593 else
1594 CHECK_LIVE_WINDOW (*window);
1596 /* MINIBUF nil may or may not include minibuffers. Decide if it
1597 does. */
1598 if (NILP (*minibuf))
1599 *minibuf = minibuf_level ? minibuf_window : Qlambda;
1600 else if (!EQ (*minibuf, Qt))
1601 *minibuf = Qlambda;
1603 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1604 => count none of them, or a specific minibuffer window (the
1605 active one) to count. */
1607 /* ALL_FRAMES nil doesn't specify which frames to include. */
1608 if (NILP (*all_frames))
1609 *all_frames = (!EQ (*minibuf, Qlambda)
1610 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window)->frame))
1611 : Qnil);
1612 else if (EQ (*all_frames, Qvisible))
1614 else if (EQ (*all_frames, make_number (0)))
1616 else if (FRAMEP (*all_frames))
1618 else if (!EQ (*all_frames, Qt))
1619 *all_frames = Qnil;
1621 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1622 search just current frame, `visible' meaning search just visible
1623 frames, 0 meaning search visible and iconified frames, or a
1624 window, meaning search the frame that window belongs to, or a
1625 frame, meaning consider windows on that frame, only. */
1629 /* Return the next or previous window of WINDOW in canonical ordering
1630 of windows. NEXT_P non-zero means return the next window. See the
1631 documentation string of next-window for the meaning of MINIBUF and
1632 ALL_FRAMES. */
1634 static Lisp_Object
1635 next_window (window, minibuf, all_frames, next_p)
1636 Lisp_Object window, minibuf, all_frames;
1637 int next_p;
1639 decode_next_window_args (&window, &minibuf, &all_frames);
1641 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1642 return the first window on the frame. */
1643 if (FRAMEP (all_frames)
1644 && !EQ (all_frames, XWINDOW (window)->frame))
1645 return Fframe_first_window (all_frames);
1647 if (next_p)
1649 Lisp_Object list;
1651 /* Find WINDOW in the list of all windows. */
1652 list = Fmemq (window, window_list ());
1654 /* Scan forward from WINDOW to the end of the window list. */
1655 if (CONSP (list))
1656 for (list = XCDR (list); CONSP (list); list = XCDR (list))
1657 if (candidate_window_p (XCAR (list), window, minibuf, all_frames))
1658 break;
1660 /* Scan from the start of the window list up to WINDOW. */
1661 if (!CONSP (list))
1662 for (list = Vwindow_list;
1663 CONSP (list) && !EQ (XCAR (list), window);
1664 list = XCDR (list))
1665 if (candidate_window_p (XCAR (list), window, minibuf, all_frames))
1666 break;
1668 if (CONSP (list))
1669 window = XCAR (list);
1671 else
1673 Lisp_Object candidate, list;
1675 /* Scan through the list of windows for candidates. If there are
1676 candidate windows in front of WINDOW, the last one of these
1677 is the one we want. If there are candidates following WINDOW
1678 in the list, again the last one of these is the one we want. */
1679 candidate = Qnil;
1680 for (list = window_list (); CONSP (list); list = XCDR (list))
1682 if (EQ (XCAR (list), window))
1684 if (WINDOWP (candidate))
1685 break;
1687 else if (candidate_window_p (XCAR (list), window, minibuf,
1688 all_frames))
1689 candidate = XCAR (list);
1692 if (WINDOWP (candidate))
1693 window = candidate;
1696 return window;
1700 DEFUN ("next-window", Fnext_window, Snext_window, 0, 3, 0,
1701 doc: /* Return next window after WINDOW in canonical ordering of windows.
1702 If omitted, WINDOW defaults to the selected window.
1704 Optional second arg MINIBUF t means count the minibuffer window even
1705 if not active. MINIBUF nil or omitted means count the minibuffer iff
1706 it is active. MINIBUF neither t nor nil means not to count the
1707 minibuffer even if it is active.
1709 Several frames may share a single minibuffer; if the minibuffer
1710 counts, all windows on all frames that share that minibuffer count
1711 too. Therefore, `next-window' can be used to iterate through the
1712 set of windows even when the minibuffer is on another frame. If the
1713 minibuffer does not count, only windows from WINDOW's frame count.
1715 Optional third arg ALL-FRAMES t means include windows on all frames.
1716 ALL-FRAMES nil or omitted means cycle within the frames as specified
1717 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1718 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1719 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1720 Anything else means restrict to WINDOW's frame.
1722 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1723 `next-window' to iterate through the entire cycle of acceptable
1724 windows, eventually ending up back at the window you started with.
1725 `previous-window' traverses the same cycle, in the reverse order. */)
1726 (window, minibuf, all_frames)
1727 Lisp_Object window, minibuf, all_frames;
1729 return next_window (window, minibuf, all_frames, 1);
1733 DEFUN ("previous-window", Fprevious_window, Sprevious_window, 0, 3, 0,
1734 doc: /* Return the window preceding WINDOW in canonical ordering of windows.
1735 If omitted, WINDOW defaults to the selected window.
1737 Optional second arg MINIBUF t means count the minibuffer window even
1738 if not active. MINIBUF nil or omitted means count the minibuffer iff
1739 it is active. MINIBUF neither t nor nil means not to count the
1740 minibuffer even if it is active.
1742 Several frames may share a single minibuffer; if the minibuffer
1743 counts, all windows on all frames that share that minibuffer count
1744 too. Therefore, `previous-window' can be used to iterate through
1745 the set of windows even when the minibuffer is on another frame. If
1746 the minibuffer does not count, only windows from WINDOW's frame count
1748 Optional third arg ALL-FRAMES t means include windows on all frames.
1749 ALL-FRAMES nil or omitted means cycle within the frames as specified
1750 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1751 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1752 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1753 Anything else means restrict to WINDOW's frame.
1755 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1756 `previous-window' to iterate through the entire cycle of acceptable
1757 windows, eventually ending up back at the window you started with.
1758 `next-window' traverses the same cycle, in the reverse order. */)
1759 (window, minibuf, all_frames)
1760 Lisp_Object window, minibuf, all_frames;
1762 return next_window (window, minibuf, all_frames, 0);
1766 DEFUN ("other-window", Fother_window, Sother_window, 1, 2, "p",
1767 doc: /* Select the ARG'th different window on this frame.
1768 All windows on current frame are arranged in a cyclic order.
1769 This command selects the window ARG steps away in that order.
1770 A negative ARG moves in the opposite order. The optional second
1771 argument ALL_FRAMES has the same meaning as in `next-window', which see. */)
1772 (arg, all_frames)
1773 Lisp_Object arg, all_frames;
1775 Lisp_Object window;
1776 int i;
1778 CHECK_NUMBER (arg);
1779 window = selected_window;
1781 for (i = XINT (arg); i > 0; --i)
1782 window = Fnext_window (window, Qnil, all_frames);
1783 for (; i < 0; ++i)
1784 window = Fprevious_window (window, Qnil, all_frames);
1786 Fselect_window (window, Qnil);
1787 return Qnil;
1791 DEFUN ("window-list", Fwindow_list, Swindow_list, 0, 3, 0,
1792 doc: /* Return a list of windows on FRAME, starting with WINDOW.
1793 FRAME nil or omitted means use the selected frame.
1794 WINDOW nil or omitted means use the selected window.
1795 MINIBUF t means include the minibuffer window, even if it isn't active.
1796 MINIBUF nil or omitted means include the minibuffer window only
1797 if it's active.
1798 MINIBUF neither nil nor t means never include the minibuffer window. */)
1799 (frame, minibuf, window)
1800 Lisp_Object frame, minibuf, window;
1802 if (NILP (window))
1803 window = selected_window;
1804 if (NILP (frame))
1805 frame = selected_frame;
1807 if (!EQ (frame, XWINDOW (window)->frame))
1808 error ("Window is on a different frame");
1810 return window_list_1 (window, minibuf, frame);
1814 /* Return a list of windows in canonical ordering. Arguments are like
1815 for `next-window'. */
1817 static Lisp_Object
1818 window_list_1 (window, minibuf, all_frames)
1819 Lisp_Object window, minibuf, all_frames;
1821 Lisp_Object tail, list, rest;
1823 decode_next_window_args (&window, &minibuf, &all_frames);
1824 list = Qnil;
1826 for (tail = window_list (); CONSP (tail); tail = XCDR (tail))
1827 if (candidate_window_p (XCAR (tail), window, minibuf, all_frames))
1828 list = Fcons (XCAR (tail), list);
1830 /* Rotate the list to start with WINDOW. */
1831 list = Fnreverse (list);
1832 rest = Fmemq (window, list);
1833 if (!NILP (rest) && !EQ (rest, list))
1835 for (tail = list; !EQ (XCDR (tail), rest); tail = XCDR (tail))
1837 XSETCDR (tail, Qnil);
1838 list = nconc2 (rest, list);
1840 return list;
1845 /* Look at all windows, performing an operation specified by TYPE
1846 with argument OBJ.
1847 If FRAMES is Qt, look at all frames;
1848 Qnil, look at just the selected frame;
1849 Qvisible, look at visible frames;
1850 a frame, just look at windows on that frame.
1851 If MINI is non-zero, perform the operation on minibuffer windows too. */
1853 enum window_loop
1855 WINDOW_LOOP_UNUSED,
1856 GET_BUFFER_WINDOW, /* Arg is buffer */
1857 GET_LRU_WINDOW, /* Arg is t for full-width windows only */
1858 DELETE_OTHER_WINDOWS, /* Arg is window not to delete */
1859 DELETE_BUFFER_WINDOWS, /* Arg is buffer */
1860 GET_LARGEST_WINDOW,
1861 UNSHOW_BUFFER, /* Arg is buffer */
1862 REDISPLAY_BUFFER_WINDOWS, /* Arg is buffer */
1863 CHECK_ALL_WINDOWS
1866 static Lisp_Object
1867 window_loop (type, obj, mini, frames)
1868 enum window_loop type;
1869 Lisp_Object obj, frames;
1870 int mini;
1872 Lisp_Object window, windows, best_window, frame_arg;
1873 struct frame *f;
1874 struct gcpro gcpro1;
1876 /* If we're only looping through windows on a particular frame,
1877 frame points to that frame. If we're looping through windows
1878 on all frames, frame is 0. */
1879 if (FRAMEP (frames))
1880 f = XFRAME (frames);
1881 else if (NILP (frames))
1882 f = SELECTED_FRAME ();
1883 else
1884 f = NULL;
1886 if (f)
1887 frame_arg = Qlambda;
1888 else if (EQ (frames, make_number (0)))
1889 frame_arg = frames;
1890 else if (EQ (frames, Qvisible))
1891 frame_arg = frames;
1892 else
1893 frame_arg = Qt;
1895 /* frame_arg is Qlambda to stick to one frame,
1896 Qvisible to consider all visible frames,
1897 or Qt otherwise. */
1899 /* Pick a window to start with. */
1900 if (WINDOWP (obj))
1901 window = obj;
1902 else if (f)
1903 window = FRAME_SELECTED_WINDOW (f);
1904 else
1905 window = FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
1907 windows = window_list_1 (window, mini ? Qt : Qnil, frame_arg);
1908 GCPRO1 (windows);
1909 best_window = Qnil;
1911 for (; CONSP (windows); windows = CDR (windows))
1913 struct window *w;
1915 window = XCAR (windows);
1916 w = XWINDOW (window);
1918 /* Note that we do not pay attention here to whether the frame
1919 is visible, since Fwindow_list skips non-visible frames if
1920 that is desired, under the control of frame_arg. */
1921 if (!MINI_WINDOW_P (w)
1922 /* For UNSHOW_BUFFER, we must always consider all windows. */
1923 || type == UNSHOW_BUFFER
1924 || (mini && minibuf_level > 0))
1925 switch (type)
1927 case GET_BUFFER_WINDOW:
1928 if (EQ (w->buffer, obj)
1929 /* Don't find any minibuffer window
1930 except the one that is currently in use. */
1931 && (MINI_WINDOW_P (w)
1932 ? EQ (window, minibuf_window)
1933 : 1))
1935 if (NILP (best_window))
1936 best_window = window;
1937 else if (EQ (window, selected_window))
1938 /* For compatibility with 20.x, prefer to return
1939 selected-window. */
1940 best_window = window;
1942 break;
1944 case GET_LRU_WINDOW:
1945 /* t as arg means consider only full-width windows */
1946 if (!NILP (obj) && !WINDOW_FULL_WIDTH_P (w))
1947 break;
1948 /* Ignore dedicated windows and minibuffers. */
1949 if (MINI_WINDOW_P (w) || EQ (w->dedicated, Qt))
1950 break;
1951 if (NILP (best_window)
1952 || (XFASTINT (XWINDOW (best_window)->use_time)
1953 > XFASTINT (w->use_time)))
1954 best_window = window;
1955 break;
1957 case DELETE_OTHER_WINDOWS:
1958 if (!EQ (window, obj))
1959 Fdelete_window (window);
1960 break;
1962 case DELETE_BUFFER_WINDOWS:
1963 if (EQ (w->buffer, obj))
1965 struct frame *f = XFRAME (WINDOW_FRAME (w));
1967 /* If this window is dedicated, and in a frame of its own,
1968 kill the frame. */
1969 if (EQ (window, FRAME_ROOT_WINDOW (f))
1970 && !NILP (w->dedicated)
1971 && other_visible_frames (f))
1973 /* Skip the other windows on this frame.
1974 There might be one, the minibuffer! */
1975 while (CONSP (XCDR (windows))
1976 && EQ (XWINDOW (XCAR (windows))->frame,
1977 XWINDOW (XCAR (XCDR (windows)))->frame))
1978 windows = XCDR (windows);
1980 /* Now we can safely delete the frame. */
1981 Fdelete_frame (w->frame, Qnil);
1983 else if (NILP (w->parent))
1985 /* If we're deleting the buffer displayed in the
1986 only window on the frame, find a new buffer to
1987 display there. */
1988 Lisp_Object buffer;
1989 buffer = Fother_buffer (obj, Qnil, w->frame);
1990 Fset_window_buffer (window, buffer, Qnil);
1991 if (EQ (window, selected_window))
1992 Fset_buffer (w->buffer);
1994 else
1995 Fdelete_window (window);
1997 break;
1999 case GET_LARGEST_WINDOW:
2001 /* Ignore dedicated windows and minibuffers. */
2002 if (MINI_WINDOW_P (w) || EQ (w->dedicated, Qt))
2003 break;
2005 if (NILP (best_window))
2006 best_window = window;
2007 else
2009 struct window *b = XWINDOW (best_window);
2010 if (XFASTINT (w->total_lines) * XFASTINT (w->total_cols)
2011 > XFASTINT (b->total_lines) * XFASTINT (b->total_cols))
2012 best_window = window;
2015 break;
2017 case UNSHOW_BUFFER:
2018 if (EQ (w->buffer, obj))
2020 Lisp_Object buffer;
2021 struct frame *f = XFRAME (w->frame);
2023 /* Find another buffer to show in this window. */
2024 buffer = Fother_buffer (obj, Qnil, w->frame);
2026 /* If this window is dedicated, and in a frame of its own,
2027 kill the frame. */
2028 if (EQ (window, FRAME_ROOT_WINDOW (f))
2029 && !NILP (w->dedicated)
2030 && other_visible_frames (f))
2032 /* Skip the other windows on this frame.
2033 There might be one, the minibuffer! */
2034 while (CONSP (XCDR (windows))
2035 && EQ (XWINDOW (XCAR (windows))->frame,
2036 XWINDOW (XCAR (XCDR (windows)))->frame))
2037 windows = XCDR (windows);
2039 /* Now we can safely delete the frame. */
2040 Fdelete_frame (w->frame, Qnil);
2042 else if (!NILP (w->dedicated) && !NILP (w->parent))
2044 Lisp_Object window;
2045 XSETWINDOW (window, w);
2046 /* If this window is dedicated and not the only window
2047 in its frame, then kill it. */
2048 Fdelete_window (window);
2050 else
2052 /* Otherwise show a different buffer in the window. */
2053 w->dedicated = Qnil;
2054 Fset_window_buffer (window, buffer, Qnil);
2055 if (EQ (window, selected_window))
2056 Fset_buffer (w->buffer);
2059 break;
2061 case REDISPLAY_BUFFER_WINDOWS:
2062 if (EQ (w->buffer, obj))
2064 mark_window_display_accurate (window, 0);
2065 w->update_mode_line = Qt;
2066 XBUFFER (obj)->prevent_redisplay_optimizations_p = 1;
2067 ++update_mode_lines;
2068 best_window = window;
2070 break;
2072 /* Check for a window that has a killed buffer. */
2073 case CHECK_ALL_WINDOWS:
2074 if (! NILP (w->buffer)
2075 && NILP (XBUFFER (w->buffer)->name))
2076 abort ();
2077 break;
2079 case WINDOW_LOOP_UNUSED:
2080 break;
2084 UNGCPRO;
2085 return best_window;
2088 /* Used for debugging. Abort if any window has a dead buffer. */
2090 void
2091 check_all_windows ()
2093 window_loop (CHECK_ALL_WINDOWS, Qnil, 1, Qt);
2096 DEFUN ("get-lru-window", Fget_lru_window, Sget_lru_window, 0, 1, 0,
2097 doc: /* Return the window least recently selected or used for display.
2098 Return a full-width window if possible.
2099 A minibuffer window is never a candidate.
2100 A dedicated window is never a candidate, so if all windows are dedicated,
2101 the value is nil.
2102 If optional argument FRAME is `visible', search all visible frames.
2103 If FRAME is 0, search all visible and iconified frames.
2104 If FRAME is t, search all frames.
2105 If FRAME is nil, search only the selected frame.
2106 If FRAME is a frame, search only that frame. */)
2107 (frame)
2108 Lisp_Object frame;
2110 register Lisp_Object w;
2111 /* First try for a window that is full-width */
2112 w = window_loop (GET_LRU_WINDOW, Qt, 0, frame);
2113 if (!NILP (w) && !EQ (w, selected_window))
2114 return w;
2115 /* If none of them, try the rest */
2116 return window_loop (GET_LRU_WINDOW, Qnil, 0, frame);
2119 DEFUN ("get-largest-window", Fget_largest_window, Sget_largest_window, 0, 1, 0,
2120 doc: /* Return the largest window in area.
2121 A minibuffer window is never a candidate.
2122 A dedicated window is never a candidate, so if all windows are dedicated,
2123 the value is nil.
2124 If optional argument FRAME is `visible', search all visible frames.
2125 If FRAME is 0, search all visible and iconified frames.
2126 If FRAME is t, search all frames.
2127 If FRAME is nil, search only the selected frame.
2128 If FRAME is a frame, search only that frame. */)
2129 (frame)
2130 Lisp_Object frame;
2132 return window_loop (GET_LARGEST_WINDOW, Qnil, 0,
2133 frame);
2136 DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 1, 2, 0,
2137 doc: /* Return a window currently displaying BUFFER, or nil if none.
2138 BUFFER can be a buffer or a buffer name.
2139 If optional argument FRAME is `visible', search all visible frames.
2140 If optional argument FRAME is 0, search all visible and iconified frames.
2141 If FRAME is t, search all frames.
2142 If FRAME is nil, search only the selected frame.
2143 If FRAME is a frame, search only that frame. */)
2144 (buffer, frame)
2145 Lisp_Object buffer, frame;
2147 buffer = Fget_buffer (buffer);
2148 if (BUFFERP (buffer))
2149 return window_loop (GET_BUFFER_WINDOW, buffer, 1, frame);
2150 else
2151 return Qnil;
2154 DEFUN ("delete-other-windows", Fdelete_other_windows, Sdelete_other_windows,
2155 0, 1, "",
2156 doc: /* Make WINDOW (or the selected window) fill its frame.
2157 Only the frame WINDOW is on is affected.
2158 This function tries to reduce display jumps
2159 by keeping the text previously visible in WINDOW
2160 in the same place on the frame. Doing this depends on
2161 the value of (window-start WINDOW), so if calling this function
2162 in a program gives strange scrolling, make sure the window-start
2163 value is reasonable when this function is called. */)
2164 (window)
2165 Lisp_Object window;
2167 struct window *w;
2168 int startpos;
2169 int top, new_top;
2171 if (NILP (window))
2172 window = selected_window;
2173 else
2174 CHECK_LIVE_WINDOW (window);
2175 w = XWINDOW (window);
2177 startpos = marker_position (w->start);
2178 top = WINDOW_TOP_EDGE_LINE (w) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w)));
2180 if (MINI_WINDOW_P (w) && top > 0)
2181 error ("Can't expand minibuffer to full frame");
2183 window_loop (DELETE_OTHER_WINDOWS, window, 0, WINDOW_FRAME (w));
2185 /* Try to minimize scrolling, by setting the window start to the point
2186 will cause the text at the old window start to be at the same place
2187 on the frame. But don't try to do this if the window start is
2188 outside the visible portion (as might happen when the display is
2189 not current, due to typeahead). */
2190 new_top = WINDOW_TOP_EDGE_LINE (w) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w)));
2191 if (new_top != top
2192 && startpos >= BUF_BEGV (XBUFFER (w->buffer))
2193 && startpos <= BUF_ZV (XBUFFER (w->buffer)))
2195 struct position pos;
2196 struct buffer *obuf = current_buffer;
2198 Fset_buffer (w->buffer);
2199 /* This computation used to temporarily move point, but that can
2200 have unwanted side effects due to text properties. */
2201 pos = *vmotion (startpos, -top, w);
2203 set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos);
2204 w->window_end_valid = Qnil;
2205 w->start_at_line_beg = ((pos.bytepos == BEGV_BYTE
2206 || FETCH_BYTE (pos.bytepos - 1) == '\n') ? Qt
2207 : Qnil);
2208 /* We need to do this, so that the window-scroll-functions
2209 get called. */
2210 w->optional_new_start = Qt;
2212 set_buffer_internal (obuf);
2215 return Qnil;
2218 DEFUN ("delete-windows-on", Fdelete_windows_on, Sdelete_windows_on,
2219 1, 2, "bDelete windows on (buffer): ",
2220 doc: /* Delete all windows showing BUFFER.
2221 BUFFER must be a buffer or the name of an existing buffer.
2222 Optional second argument FRAME controls which frames are affected.
2223 If optional argument FRAME is `visible', search all visible frames.
2224 If FRAME is 0, search all visible and iconified frames.
2225 If FRAME is nil, search all frames.
2226 If FRAME is t, search only the selected frame.
2227 If FRAME is a frame, search only that frame. */)
2228 (buffer, frame)
2229 Lisp_Object buffer, frame;
2231 /* FRAME uses t and nil to mean the opposite of what window_loop
2232 expects. */
2233 if (NILP (frame))
2234 frame = Qt;
2235 else if (EQ (frame, Qt))
2236 frame = Qnil;
2238 if (!NILP (buffer))
2240 buffer = Fget_buffer (buffer);
2241 CHECK_BUFFER (buffer);
2242 window_loop (DELETE_BUFFER_WINDOWS, buffer, 0, frame);
2245 return Qnil;
2248 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows,
2249 Sreplace_buffer_in_windows,
2250 1, 1, "bReplace buffer in windows: ",
2251 doc: /* Replace BUFFER with some other buffer in all windows showing it.
2252 BUFFER may be a buffer or the name of an existing buffer. */)
2253 (buffer)
2254 Lisp_Object buffer;
2256 if (!NILP (buffer))
2258 buffer = Fget_buffer (buffer);
2259 CHECK_BUFFER (buffer);
2260 window_loop (UNSHOW_BUFFER, buffer, 0, Qt);
2262 return Qnil;
2265 /* Replace BUFFER with some other buffer in all windows
2266 of all frames, even those on other keyboards. */
2268 void
2269 replace_buffer_in_all_windows (buffer)
2270 Lisp_Object buffer;
2272 #ifdef MULTI_KBOARD
2273 Lisp_Object tail, frame;
2275 /* A single call to window_loop won't do the job
2276 because it only considers frames on the current keyboard.
2277 So loop manually over frames, and handle each one. */
2278 FOR_EACH_FRAME (tail, frame)
2279 window_loop (UNSHOW_BUFFER, buffer, 1, frame);
2280 #else
2281 window_loop (UNSHOW_BUFFER, buffer, 1, Qt);
2282 #endif
2285 /* Set the height of WINDOW and all its inferiors. */
2287 /* The smallest acceptable dimensions for a window. Anything smaller
2288 might crash Emacs. */
2290 #define MIN_SAFE_WINDOW_WIDTH (2)
2291 #define MIN_SAFE_WINDOW_HEIGHT (1)
2293 /* Make sure that window_min_height and window_min_width are
2294 not too small; if they are, set them to safe minima. */
2296 static void
2297 check_min_window_sizes ()
2299 /* Smaller values might permit a crash. */
2300 if (window_min_width < MIN_SAFE_WINDOW_WIDTH)
2301 window_min_width = MIN_SAFE_WINDOW_WIDTH;
2302 if (window_min_height < MIN_SAFE_WINDOW_HEIGHT)
2303 window_min_height = MIN_SAFE_WINDOW_HEIGHT;
2306 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2307 minimum allowable size. */
2309 void
2310 check_frame_size (frame, rows, cols)
2311 FRAME_PTR frame;
2312 int *rows, *cols;
2314 /* For height, we have to see:
2315 how many windows the frame has at minimum (one or two),
2316 and whether it has a menu bar or other special stuff at the top. */
2317 int min_height
2318 = ((FRAME_MINIBUF_ONLY_P (frame) || ! FRAME_HAS_MINIBUF_P (frame))
2319 ? MIN_SAFE_WINDOW_HEIGHT
2320 : 2 * MIN_SAFE_WINDOW_HEIGHT);
2322 if (FRAME_TOP_MARGIN (frame) > 0)
2323 min_height += FRAME_TOP_MARGIN (frame);
2325 if (*rows < min_height)
2326 *rows = min_height;
2327 if (*cols < MIN_SAFE_WINDOW_WIDTH)
2328 *cols = MIN_SAFE_WINDOW_WIDTH;
2332 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2333 check if W's width can be changed, otherwise check W's height.
2334 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2335 siblings, too. If none of the siblings is resizable, WINDOW isn't
2336 either. */
2338 static int
2339 window_fixed_size_p (w, width_p, check_siblings_p)
2340 struct window *w;
2341 int width_p, check_siblings_p;
2343 int fixed_p;
2344 struct window *c;
2346 if (!NILP (w->hchild))
2348 c = XWINDOW (w->hchild);
2350 if (width_p)
2352 /* A horiz. combination is fixed-width if all of if its
2353 children are. */
2354 while (c && window_fixed_size_p (c, width_p, 0))
2355 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2356 fixed_p = c == NULL;
2358 else
2360 /* A horiz. combination is fixed-height if one of if its
2361 children is. */
2362 while (c && !window_fixed_size_p (c, width_p, 0))
2363 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2364 fixed_p = c != NULL;
2367 else if (!NILP (w->vchild))
2369 c = XWINDOW (w->vchild);
2371 if (width_p)
2373 /* A vert. combination is fixed-width if one of if its
2374 children is. */
2375 while (c && !window_fixed_size_p (c, width_p, 0))
2376 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2377 fixed_p = c != NULL;
2379 else
2381 /* A vert. combination is fixed-height if all of if its
2382 children are. */
2383 while (c && window_fixed_size_p (c, width_p, 0))
2384 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2385 fixed_p = c == NULL;
2388 else if (BUFFERP (w->buffer))
2390 if (w->height_fixed_p && !width_p)
2391 fixed_p = 1;
2392 else
2394 struct buffer *old = current_buffer;
2395 Lisp_Object val;
2397 current_buffer = XBUFFER (w->buffer);
2398 val = find_symbol_value (Qwindow_size_fixed);
2399 current_buffer = old;
2401 fixed_p = 0;
2402 if (!EQ (val, Qunbound))
2404 fixed_p = !NILP (val);
2406 if (fixed_p
2407 && ((EQ (val, Qheight) && width_p)
2408 || (EQ (val, Qwidth) && !width_p)))
2409 fixed_p = 0;
2413 /* Can't tell if this one is resizable without looking at
2414 siblings. If all siblings are fixed-size this one is too. */
2415 if (!fixed_p && check_siblings_p && WINDOWP (w->parent))
2417 Lisp_Object child;
2419 for (child = w->prev; !NILP (child); child = XWINDOW (child)->prev)
2420 if (!window_fixed_size_p (XWINDOW (child), width_p, 0))
2421 break;
2423 if (NILP (child))
2424 for (child = w->next; !NILP (child); child = XWINDOW (child)->next)
2425 if (!window_fixed_size_p (XWINDOW (child), width_p, 0))
2426 break;
2428 if (NILP (child))
2429 fixed_p = 1;
2432 else
2433 fixed_p = 1;
2435 return fixed_p;
2439 /* Return the minimum size of window W, not taking fixed-width windows
2440 into account. WIDTH_P non-zero means return the minimum width,
2441 otherwise return the minimum height. If W is a combination window,
2442 compute the minimum size from the minimum sizes of W's children. */
2444 static int
2445 window_min_size_1 (w, width_p)
2446 struct window *w;
2447 int width_p;
2449 struct window *c;
2450 int size;
2452 if (!NILP (w->hchild))
2454 c = XWINDOW (w->hchild);
2455 size = 0;
2457 if (width_p)
2459 /* The min width of a horizontal combination is
2460 the sum of the min widths of its children. */
2461 while (c)
2463 size += window_min_size_1 (c, width_p);
2464 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2467 else
2469 /* The min height a horizontal combination equals
2470 the maximum of all min height of its children. */
2471 while (c)
2473 int min_size = window_min_size_1 (c, width_p);
2474 size = max (min_size, size);
2475 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2479 else if (!NILP (w->vchild))
2481 c = XWINDOW (w->vchild);
2482 size = 0;
2484 if (width_p)
2486 /* The min width of a vertical combination is
2487 the maximum of the min widths of its children. */
2488 while (c)
2490 int min_size = window_min_size_1 (c, width_p);
2491 size = max (min_size, size);
2492 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2495 else
2497 /* The min height of a vertical combination equals
2498 the sum of the min height of its children. */
2499 while (c)
2501 size += window_min_size_1 (c, width_p);
2502 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2506 else
2508 if (width_p)
2509 size = window_min_width;
2510 else
2512 if (MINI_WINDOW_P (w)
2513 || (!WINDOW_WANTS_MODELINE_P (w)
2514 && !WINDOW_WANTS_HEADER_LINE_P (w)))
2515 size = 1;
2516 else
2517 size = window_min_height;
2521 return size;
2525 /* Return the minimum size of window W, taking fixed-size windows into
2526 account. WIDTH_P non-zero means return the minimum width,
2527 otherwise return the minimum height. IGNORE_FIXED_P non-zero means
2528 ignore if W is fixed-size. Set *FIXED to 1 if W is fixed-size
2529 unless FIXED is null. */
2531 static int
2532 window_min_size (w, width_p, ignore_fixed_p, fixed)
2533 struct window *w;
2534 int width_p, ignore_fixed_p, *fixed;
2536 int size, fixed_p;
2538 if (ignore_fixed_p)
2539 fixed_p = 0;
2540 else
2541 fixed_p = window_fixed_size_p (w, width_p, 1);
2543 if (fixed)
2544 *fixed = fixed_p;
2546 if (fixed_p)
2547 size = width_p ? XFASTINT (w->total_cols) : XFASTINT (w->total_lines);
2548 else
2549 size = window_min_size_1 (w, width_p);
2551 return size;
2555 /* Adjust the margins of window W if text area is too small.
2556 Return 1 if window width is ok after adjustment; 0 if window
2557 is still too narrow. */
2559 static int
2560 adjust_window_margins (w)
2561 struct window *w;
2563 int box_cols = (WINDOW_TOTAL_COLS (w)
2564 - WINDOW_FRINGE_COLS (w)
2565 - WINDOW_SCROLL_BAR_COLS (w));
2566 int margin_cols = (WINDOW_LEFT_MARGIN_COLS (w)
2567 + WINDOW_RIGHT_MARGIN_COLS (w));
2569 if (box_cols - margin_cols >= MIN_SAFE_WINDOW_WIDTH)
2570 return 1;
2572 if (margin_cols < 0 || box_cols < MIN_SAFE_WINDOW_WIDTH)
2573 return 0;
2575 /* Window's text area is too narrow, but reducing the window
2576 margins will fix that. */
2577 margin_cols = box_cols - MIN_SAFE_WINDOW_WIDTH;
2578 if (WINDOW_RIGHT_MARGIN_COLS (w) > 0)
2580 if (WINDOW_LEFT_MARGIN_COLS (w) > 0)
2581 w->left_margin_cols = w->right_margin_cols
2582 = make_number (margin_cols/2);
2583 else
2584 w->right_margin_cols = make_number (margin_cols);
2586 else
2587 w->left_margin_cols = make_number (margin_cols);
2588 return 1;
2591 /* Calculate new sizes for windows in the list FORWARD when the window size
2592 goes from TOTAL to SIZE. TOTAL must be greater than SIZE.
2593 The number of windows in FORWARD is NCHILDREN, and the number that
2594 can shrink is SHRINKABLE.
2595 The minimum size a window can have is MIN_SIZE.
2596 If we are shrinking fixed windows, RESIZE_FIXED_P is non-zero.
2597 If we are shrinking columns, WIDTH_P is non-zero, otherwise we are
2598 shrinking rows.
2600 This function returns an allocated array of new sizes that the caller
2601 must free. The size -1 means the window is fixed and RESIZE_FIXED_P
2602 is zero. Array index 0 refers to the first window in FORWARD, 1 to
2603 the second, and so on.
2605 This function tries to keep windows at least at the minimum size
2606 and resize other windows before it resizes any window to zero (i.e.
2607 delete that window).
2609 Windows are resized proportional to their size, so bigger windows
2610 shrink more than smaller windows. */
2611 static int *
2612 shrink_windows (total, size, nchildren, shrinkable,
2613 min_size, resize_fixed_p, forward, width_p)
2614 int total, size, nchildren, shrinkable, min_size;
2615 int resize_fixed_p, width_p;
2616 Lisp_Object forward;
2618 int available_resize = 0;
2619 int *new_sizes;
2620 struct window *c;
2621 Lisp_Object child;
2622 int smallest = total;
2623 int total_removed = 0;
2624 int total_shrink = total - size;
2625 int i;
2627 new_sizes = xmalloc (sizeof (*new_sizes) * nchildren);
2629 for (i = 0, child = forward; !NILP (child); child = c->next, ++i)
2631 int child_size;
2633 c = XWINDOW (child);
2634 child_size = width_p ? XINT (c->total_cols) : XINT (c->total_lines);
2636 if (! resize_fixed_p && window_fixed_size_p (c, width_p, 0))
2637 new_sizes[i] = -1;
2638 else
2640 new_sizes[i] = child_size;
2641 if (child_size > min_size)
2642 available_resize += child_size - min_size;
2645 /* We might need to shrink some windows to zero. Find the smallest
2646 windows and set them to 0 until we can fulfil the new size. */
2648 while (shrinkable > 1 && size + available_resize < total)
2650 for (i = 0; i < nchildren; ++i)
2651 if (new_sizes[i] > 0 && smallest > new_sizes[i])
2652 smallest = new_sizes[i];
2654 for (i = 0; i < nchildren; ++i)
2655 if (new_sizes[i] == smallest)
2657 /* Resize this window down to zero. */
2658 new_sizes[i] = 0;
2659 if (smallest > min_size)
2660 available_resize -= smallest - min_size;
2661 available_resize += smallest;
2662 --shrinkable;
2663 total_removed += smallest;
2665 /* We don't know what the smallest is now. */
2666 smallest = total;
2668 /* Out of for, just remove one window at the time and
2669 check again if we have enough space. */
2670 break;
2674 /* Now, calculate the new sizes. Try to shrink each window
2675 proportional to its size. */
2676 for (i = 0; i < nchildren; ++i)
2678 if (new_sizes[i] > min_size)
2680 int to_shrink = total_shrink*new_sizes[i]/total;
2681 if (new_sizes[i] - to_shrink < min_size)
2682 to_shrink = new_sizes[i] - min_size;
2683 new_sizes[i] -= to_shrink;
2684 total_removed += to_shrink;
2688 /* Any reminder due to rounding, we just subtract from windows
2689 that are left and still can be shrunk. */
2690 while (total_shrink > total_removed)
2692 int nonzero_sizes = 0;
2693 int nonzero_idx = -1;
2695 for (i = 0; i < nchildren; ++i)
2696 if (new_sizes[i] > 0)
2698 ++nonzero_sizes;
2699 nonzero_idx = i;
2702 for (i = 0; i < nchildren; ++i)
2703 if (new_sizes[i] > min_size)
2705 --new_sizes[i];
2706 ++total_removed;
2708 /* Out of for, just shrink one window at the time and
2709 check again if we have enough space. */
2710 break;
2714 /* Special case, only one window left. */
2715 if (nonzero_sizes == 1)
2716 break;
2719 /* Any surplus due to rounding, we add to windows that are left. */
2720 while (total_shrink < total_removed)
2722 for (i = 0; i < nchildren; ++i)
2724 if (new_sizes[i] != 0 && total_shrink < total_removed)
2726 ++new_sizes[i];
2727 --total_removed;
2728 break;
2733 return new_sizes;
2736 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
2737 WINDOW's width. Resize WINDOW's children, if any, so that they
2738 keep their proportionate size relative to WINDOW. Propagate
2739 WINDOW's top or left edge position to children. Delete windows
2740 that become too small unless NODELETE_P is non-zero.
2742 If NODELETE_P is 2, that means we do delete windows that are
2743 too small, even if they were too small before! */
2745 static void
2746 size_window (window, size, width_p, nodelete_p)
2747 Lisp_Object window;
2748 int size, width_p, nodelete_p;
2750 struct window *w = XWINDOW (window);
2751 struct window *c;
2752 Lisp_Object child, *forward, *sideward;
2753 int old_size, min_size, safe_min_size;
2755 /* We test nodelete_p != 2 and nodelete_p != 1 below, so it
2756 seems like it's too soon to do this here. ++KFS. */
2757 if (nodelete_p == 2)
2758 nodelete_p = 0;
2760 check_min_window_sizes ();
2761 size = max (0, size);
2763 /* If the window has been "too small" at one point,
2764 don't delete it for being "too small" in the future.
2765 Preserve it as long as that is at all possible. */
2766 if (width_p)
2768 old_size = WINDOW_TOTAL_COLS (w);
2769 min_size = window_min_width;
2770 /* Ensure that there is room for the scroll bar and fringes!
2771 We may reduce display margins though. */
2772 safe_min_size = (MIN_SAFE_WINDOW_WIDTH
2773 + WINDOW_FRINGE_COLS (w)
2774 + WINDOW_SCROLL_BAR_COLS (w));
2776 else
2778 old_size = XINT (w->total_lines);
2779 min_size = window_min_height;
2780 safe_min_size = MIN_SAFE_WINDOW_HEIGHT;
2783 if (old_size < min_size && nodelete_p != 2)
2784 w->too_small_ok = Qt;
2786 /* Maybe delete WINDOW if it's too small. */
2787 if (nodelete_p != 1 && !NILP (w->parent))
2789 if (!MINI_WINDOW_P (w) && !NILP (w->too_small_ok))
2790 min_size = width_p ? MIN_SAFE_WINDOW_WIDTH : MIN_SAFE_WINDOW_HEIGHT;
2791 if (min_size < safe_min_size)
2792 min_size = safe_min_size;
2793 if (size < min_size)
2795 delete_window (window);
2796 return;
2800 /* Set redisplay hints. */
2801 w->last_modified = make_number (0);
2802 w->last_overlay_modified = make_number (0);
2803 windows_or_buffers_changed++;
2804 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w->frame)) = 1;
2806 if (width_p)
2808 sideward = &w->vchild;
2809 forward = &w->hchild;
2810 w->total_cols = make_number (size);
2811 adjust_window_margins (w);
2813 else
2815 sideward = &w->hchild;
2816 forward = &w->vchild;
2817 w->total_lines = make_number (size);
2818 w->orig_total_lines = Qnil;
2821 if (!NILP (*sideward))
2823 for (child = *sideward; !NILP (child); child = c->next)
2825 c = XWINDOW (child);
2826 if (width_p)
2827 c->left_col = w->left_col;
2828 else
2829 c->top_line = w->top_line;
2830 size_window (child, size, width_p, nodelete_p);
2833 else if (!NILP (*forward))
2835 int fixed_size, each, extra, n;
2836 int resize_fixed_p, nfixed;
2837 int last_pos, first_pos, nchildren, total;
2838 int *new_sizes = NULL;
2840 /* Determine the fixed-size portion of the this window, and the
2841 number of child windows. */
2842 fixed_size = nchildren = nfixed = total = 0;
2843 for (child = *forward; !NILP (child); child = c->next, ++nchildren)
2845 int child_size;
2847 c = XWINDOW (child);
2848 child_size = width_p ? XINT (c->total_cols) : XINT (c->total_lines);
2849 total += child_size;
2851 if (window_fixed_size_p (c, width_p, 0))
2853 fixed_size += child_size;
2854 ++nfixed;
2858 /* If the new size is smaller than fixed_size, or if there
2859 aren't any resizable windows, allow resizing fixed-size
2860 windows. */
2861 resize_fixed_p = nfixed == nchildren || size < fixed_size;
2863 /* Compute how many lines/columns to add/remove to each child. The
2864 value of extra takes care of rounding errors. */
2865 n = resize_fixed_p ? nchildren : nchildren - nfixed;
2866 if (size < total && n > 1)
2867 new_sizes = shrink_windows (total, size, nchildren, n, min_size,
2868 resize_fixed_p, *forward, width_p);
2869 else
2871 each = (size - total) / n;
2872 extra = (size - total) - n * each;
2875 /* Compute new children heights and edge positions. */
2876 first_pos = width_p ? XINT (w->left_col) : XINT (w->top_line);
2877 last_pos = first_pos;
2878 for (n = 0, child = *forward; !NILP (child); child = c->next, ++n)
2880 int new_size, old_size;
2882 c = XWINDOW (child);
2883 old_size = width_p ? XFASTINT (c->total_cols) : XFASTINT (c->total_lines);
2884 new_size = old_size;
2886 /* The top or left edge position of this child equals the
2887 bottom or right edge of its predecessor. */
2888 if (width_p)
2889 c->left_col = make_number (last_pos);
2890 else
2891 c->top_line = make_number (last_pos);
2893 /* If this child can be resized, do it. */
2894 if (resize_fixed_p || !window_fixed_size_p (c, width_p, 0))
2896 new_size = new_sizes ? new_sizes[n] : old_size + each + extra;
2897 extra = 0;
2900 /* Set new height. Note that size_window also propagates
2901 edge positions to children, so it's not a no-op if we
2902 didn't change the child's size. */
2903 size_window (child, new_size, width_p, 1);
2905 /* Remember the bottom/right edge position of this child; it
2906 will be used to set the top/left edge of the next child. */
2907 last_pos += new_size;
2910 if (new_sizes) xfree (new_sizes);
2912 /* We should have covered the parent exactly with child windows. */
2913 xassert (size == last_pos - first_pos);
2915 /* Now delete any children that became too small. */
2916 if (!nodelete_p)
2917 for (child = *forward; !NILP (child); child = c->next)
2919 int child_size;
2920 c = XWINDOW (child);
2921 child_size = width_p ? XINT (c->total_cols) : XINT (c->total_lines);
2922 size_window (child, child_size, width_p, 2);
2927 /* Set WINDOW's height to HEIGHT, and recursively change the height of
2928 WINDOW's children. NODELETE non-zero means don't delete windows
2929 that become too small in the process. (The caller should check
2930 later and do so if appropriate.) */
2932 void
2933 set_window_height (window, height, nodelete)
2934 Lisp_Object window;
2935 int height;
2936 int nodelete;
2938 size_window (window, height, 0, nodelete);
2942 /* Set WINDOW's width to WIDTH, and recursively change the width of
2943 WINDOW's children. NODELETE non-zero means don't delete windows
2944 that become too small in the process. (The caller should check
2945 later and do so if appropriate.) */
2947 void
2948 set_window_width (window, width, nodelete)
2949 Lisp_Object window;
2950 int width;
2951 int nodelete;
2953 size_window (window, width, 1, nodelete);
2956 /* Change window heights in windows rooted in WINDOW by N lines. */
2958 void
2959 change_window_heights (window, n)
2960 Lisp_Object window;
2961 int n;
2963 struct window *w = XWINDOW (window);
2965 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
2966 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
2968 if (INTEGERP (w->orig_top_line))
2969 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
2970 if (INTEGERP (w->orig_total_lines))
2971 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
2973 /* Handle just the top child in a vertical split. */
2974 if (!NILP (w->vchild))
2975 change_window_heights (w->vchild, n);
2977 /* Adjust all children in a horizontal split. */
2978 for (window = w->hchild; !NILP (window); window = w->next)
2980 w = XWINDOW (window);
2981 change_window_heights (window, n);
2986 int window_select_count;
2988 Lisp_Object
2989 Fset_window_buffer_unwind (obuf)
2990 Lisp_Object obuf;
2992 Fset_buffer (obuf);
2993 return Qnil;
2996 EXFUN (Fset_window_fringes, 4);
2997 EXFUN (Fset_window_scroll_bars, 4);
2999 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
3000 means it's allowed to run hooks. See make_frame for a case where
3001 it's not allowed. KEEP_MARGINS_P non-zero means that the current
3002 margins, fringes, and scroll-bar settings of the window are not
3003 reset from the buffer's local settings. */
3005 void
3006 set_window_buffer (window, buffer, run_hooks_p, keep_margins_p)
3007 Lisp_Object window, buffer;
3008 int run_hooks_p, keep_margins_p;
3010 struct window *w = XWINDOW (window);
3011 struct buffer *b = XBUFFER (buffer);
3012 int count = SPECPDL_INDEX ();
3014 w->buffer = buffer;
3016 if (EQ (window, selected_window))
3017 b->last_selected_window = window;
3019 /* Let redisplay errors through. */
3020 b->display_error_modiff = 0;
3022 /* Update time stamps of buffer display. */
3023 if (INTEGERP (b->display_count))
3024 XSETINT (b->display_count, XINT (b->display_count) + 1);
3025 b->display_time = Fcurrent_time ();
3027 XSETFASTINT (w->window_end_pos, 0);
3028 XSETFASTINT (w->window_end_vpos, 0);
3029 bzero (&w->last_cursor, sizeof w->last_cursor);
3030 w->window_end_valid = Qnil;
3031 w->hscroll = w->min_hscroll = make_number (0);
3032 w->vscroll = 0;
3033 set_marker_both (w->pointm, buffer, BUF_PT (b), BUF_PT_BYTE (b));
3034 set_marker_restricted (w->start,
3035 make_number (b->last_window_start),
3036 buffer);
3037 w->start_at_line_beg = Qnil;
3038 w->force_start = Qnil;
3039 XSETFASTINT (w->last_modified, 0);
3040 XSETFASTINT (w->last_overlay_modified, 0);
3041 windows_or_buffers_changed++;
3043 /* We must select BUFFER for running the window-scroll-functions.
3044 If WINDOW is selected, switch permanently.
3045 Otherwise, switch but go back to the ambient buffer afterward. */
3046 if (EQ (window, selected_window))
3047 Fset_buffer (buffer);
3048 /* We can't check ! NILP (Vwindow_scroll_functions) here
3049 because that might itself be a local variable. */
3050 else if (window_initialized)
3052 record_unwind_protect (Fset_window_buffer_unwind, Fcurrent_buffer ());
3053 Fset_buffer (buffer);
3056 if (!keep_margins_p)
3058 /* Set left and right marginal area width etc. from buffer. */
3060 /* This may call adjust_window_margins three times, so
3061 temporarily disable window margins. */
3062 Lisp_Object save_left = w->left_margin_cols;
3063 Lisp_Object save_right = w->right_margin_cols;
3065 w->left_margin_cols = w->right_margin_cols = Qnil;
3067 Fset_window_fringes (window,
3068 b->left_fringe_width, b->right_fringe_width,
3069 b->fringes_outside_margins);
3071 Fset_window_scroll_bars (window,
3072 b->scroll_bar_width,
3073 b->vertical_scroll_bar_type, Qnil);
3075 w->left_margin_cols = save_left;
3076 w->right_margin_cols = save_right;
3078 Fset_window_margins (window,
3079 b->left_margin_cols, b->right_margin_cols);
3082 if (run_hooks_p)
3084 if (! NILP (Vwindow_scroll_functions))
3085 run_hook_with_args_2 (Qwindow_scroll_functions, window,
3086 Fmarker_position (w->start));
3088 if (! NILP (Vwindow_configuration_change_hook)
3089 && ! NILP (Vrun_hooks))
3090 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
3093 unbind_to (count, Qnil);
3097 DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 3, 0,
3098 doc: /* Make WINDOW display BUFFER as its contents.
3099 BUFFER can be a buffer or the name of an existing buffer.
3100 Optional third arg KEEP-MARGINS non-nil means that WINDOW's current
3101 display margins, fringe widths, and scroll bar settings are maintained;
3102 the default is to reset these from BUFFER's local settings or the frame
3103 defaults.
3105 This function runs the hook `window-scroll-functions'. */)
3106 (window, buffer, keep_margins)
3107 register Lisp_Object window, buffer, keep_margins;
3109 register Lisp_Object tem;
3110 register struct window *w = decode_window (window);
3112 XSETWINDOW (window, w);
3113 buffer = Fget_buffer (buffer);
3114 CHECK_BUFFER (buffer);
3116 if (NILP (XBUFFER (buffer)->name))
3117 error ("Attempt to display deleted buffer");
3119 tem = w->buffer;
3120 if (NILP (tem))
3121 error ("Window is deleted");
3122 else if (! EQ (tem, Qt)) /* w->buffer is t when the window
3123 is first being set up. */
3125 if (!NILP (w->dedicated) && !EQ (tem, buffer))
3126 error ("Window is dedicated to `%s'",
3127 SDATA (XBUFFER (tem)->name));
3129 unshow_buffer (w);
3132 set_window_buffer (window, buffer, 1, !NILP (keep_margins));
3133 return Qnil;
3136 /* Note that selected_window can be nil
3137 when this is called from Fset_window_configuration. */
3139 DEFUN ("select-window", Fselect_window, Sselect_window, 1, 2, 0,
3140 doc: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
3141 If WINDOW is not already selected, make WINDOW's buffer current
3142 and make WINDOW the frame's selected window. Return WINDOW.
3143 Optional second arg NORECORD non-nil means
3144 do not put this buffer at the front of the list of recently selected ones.
3146 Note that the main editor command loop
3147 selects the buffer of the selected window before each command. */)
3148 (window, norecord)
3149 register Lisp_Object window, norecord;
3151 register struct window *w;
3152 register struct window *ow;
3153 struct frame *sf;
3155 CHECK_LIVE_WINDOW (window);
3157 w = XWINDOW (window);
3158 w->frozen_window_start_p = 0;
3160 ++window_select_count;
3161 XSETFASTINT (w->use_time, window_select_count);
3162 if (EQ (window, selected_window))
3163 return window;
3165 if (!NILP (selected_window))
3167 ow = XWINDOW (selected_window);
3168 if (! NILP (ow->buffer))
3169 set_marker_both (ow->pointm, ow->buffer,
3170 BUF_PT (XBUFFER (ow->buffer)),
3171 BUF_PT_BYTE (XBUFFER (ow->buffer)));
3174 selected_window = window;
3175 sf = SELECTED_FRAME ();
3176 if (XFRAME (WINDOW_FRAME (w)) != sf)
3178 XFRAME (WINDOW_FRAME (w))->selected_window = window;
3179 /* Use this rather than Fhandle_switch_frame
3180 so that FRAME_FOCUS_FRAME is moved appropriately as we
3181 move around in the state where a minibuffer in a separate
3182 frame is active. */
3183 Fselect_frame (WINDOW_FRAME (w), Qnil);
3185 else
3186 sf->selected_window = window;
3188 if (NILP (norecord))
3189 record_buffer (w->buffer);
3190 Fset_buffer (w->buffer);
3192 XBUFFER (w->buffer)->last_selected_window = window;
3194 /* Go to the point recorded in the window.
3195 This is important when the buffer is in more
3196 than one window. It also matters when
3197 redisplay_window has altered point after scrolling,
3198 because it makes the change only in the window. */
3200 register int new_point = marker_position (w->pointm);
3201 if (new_point < BEGV)
3202 SET_PT (BEGV);
3203 else if (new_point > ZV)
3204 SET_PT (ZV);
3205 else
3206 SET_PT (new_point);
3209 windows_or_buffers_changed++;
3210 return window;
3213 static Lisp_Object
3214 select_window_norecord (window)
3215 Lisp_Object window;
3217 return Fselect_window (window, Qt);
3220 /* Deiconify the frame containing the window WINDOW,
3221 unless it is the selected frame;
3222 then return WINDOW.
3224 The reason for the exception for the selected frame
3225 is that it seems better not to change the selected frames visibility
3226 merely because of displaying a different buffer in it.
3227 The deiconification is useful when a buffer gets shown in
3228 another frame that you were not using lately. */
3230 static Lisp_Object
3231 display_buffer_1 (window)
3232 Lisp_Object window;
3234 Lisp_Object frame = XWINDOW (window)->frame;
3235 FRAME_PTR f = XFRAME (frame);
3237 FRAME_SAMPLE_VISIBILITY (f);
3239 if (EQ (frame, selected_frame))
3240 ; /* Assume the selected frame is already visible enough. */
3241 else if (minibuf_level > 0
3242 && MINI_WINDOW_P (XWINDOW (selected_window))
3243 && WINDOW_LIVE_P (minibuf_selected_window)
3244 && EQ (frame, WINDOW_FRAME (XWINDOW (minibuf_selected_window))))
3245 ; /* Assume the frame from which we invoked the minibuffer is visible. */
3246 else
3248 if (FRAME_ICONIFIED_P (f))
3249 Fmake_frame_visible (frame);
3250 else if (FRAME_VISIBLE_P (f))
3251 Fraise_frame (frame);
3254 return window;
3257 DEFUN ("special-display-p", Fspecial_display_p, Sspecial_display_p, 1, 1, 0,
3258 doc: /* Returns non-nil if a buffer named BUFFER-NAME gets a special frame.
3259 If the value is t, a frame would be created for that buffer
3260 using the default frame parameters. If the value is a list,
3261 it is a list of frame parameters that would be used
3262 to make a frame for that buffer.
3263 The variables `special-display-buffer-names'
3264 and `special-display-regexps' control this. */)
3265 (buffer_name)
3266 Lisp_Object buffer_name;
3268 Lisp_Object tem;
3270 CHECK_STRING (buffer_name);
3272 tem = Fmember (buffer_name, Vspecial_display_buffer_names);
3273 if (!NILP (tem))
3274 return Qt;
3276 tem = Fassoc (buffer_name, Vspecial_display_buffer_names);
3277 if (!NILP (tem))
3278 return XCDR (tem);
3280 for (tem = Vspecial_display_regexps; CONSP (tem); tem = XCDR (tem))
3282 Lisp_Object car = XCAR (tem);
3283 if (STRINGP (car)
3284 && fast_string_match (car, buffer_name) >= 0)
3285 return Qt;
3286 else if (CONSP (car)
3287 && STRINGP (XCAR (car))
3288 && fast_string_match (XCAR (car), buffer_name) >= 0)
3289 return XCDR (car);
3291 return Qnil;
3294 DEFUN ("same-window-p", Fsame_window_p, Ssame_window_p, 1, 1, 0,
3295 doc: /* Returns non-nil if a new buffer named BUFFER-NAME would use the same window.
3296 See `same-window-buffer-names' and `same-window-regexps'. */)
3297 (buffer_name)
3298 Lisp_Object buffer_name;
3300 Lisp_Object tem;
3302 CHECK_STRING (buffer_name);
3304 tem = Fmember (buffer_name, Vsame_window_buffer_names);
3305 if (!NILP (tem))
3306 return Qt;
3308 tem = Fassoc (buffer_name, Vsame_window_buffer_names);
3309 if (!NILP (tem))
3310 return Qt;
3312 for (tem = Vsame_window_regexps; CONSP (tem); tem = XCDR (tem))
3314 Lisp_Object car = XCAR (tem);
3315 if (STRINGP (car)
3316 && fast_string_match (car, buffer_name) >= 0)
3317 return Qt;
3318 else if (CONSP (car)
3319 && STRINGP (XCAR (car))
3320 && fast_string_match (XCAR (car), buffer_name) >= 0)
3321 return Qt;
3323 return Qnil;
3326 /* Use B so the default is (other-buffer). */
3327 DEFUN ("display-buffer", Fdisplay_buffer, Sdisplay_buffer, 1, 3,
3328 "BDisplay buffer: \nP",
3329 doc: /* Make BUFFER appear in some window but don't select it.
3330 BUFFER must be the name of an existing buffer, or, when called from Lisp,
3331 a buffer.
3332 If BUFFER is shown already in some window, just use that one,
3333 unless the window is the selected window and the optional second
3334 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).
3335 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
3336 Returns the window displaying BUFFER.
3337 If `display-buffer-reuse-frames' is non-nil, and another frame is currently
3338 displaying BUFFER, then simply raise that frame.
3340 The variables `special-display-buffer-names',
3341 `special-display-regexps', `same-window-buffer-names', and
3342 `same-window-regexps' customize how certain buffer names are handled.
3343 The latter two take effect only if NOT-THIS-WINDOW is t.
3345 If optional argument FRAME is `visible', search all visible frames.
3346 If FRAME is 0, search all visible and iconified frames.
3347 If FRAME is t, search all frames.
3348 If FRAME is a frame, search only that frame.
3349 If FRAME is nil, search only the selected frame
3350 (actually the last nonminibuffer frame),
3351 unless `pop-up-frames' or `display-buffer-reuse-frames' is non-nil,
3352 which means search visible and iconified frames.
3354 If a full-width window on a splittable frame is available to display
3355 the buffer, it may be split, subject to the value of the variable
3356 `split-height-threshold'.
3358 If `even-window-heights' is non-nil, window heights will be evened out
3359 if displaying the buffer causes two vertically adjacent windows to be
3360 displayed. */)
3361 (buffer, not_this_window, frame)
3362 register Lisp_Object buffer, not_this_window, frame;
3364 register Lisp_Object window, tem, swp;
3365 struct frame *f;
3367 swp = Qnil;
3368 buffer = Fget_buffer (buffer);
3369 CHECK_BUFFER (buffer);
3371 if (!NILP (Vdisplay_buffer_function))
3372 return call2 (Vdisplay_buffer_function, buffer, not_this_window);
3374 if (NILP (not_this_window)
3375 && XBUFFER (XWINDOW (selected_window)->buffer) == XBUFFER (buffer))
3376 return display_buffer_1 (selected_window);
3378 /* See if the user has specified this buffer should appear
3379 in the selected window. */
3380 if (NILP (not_this_window))
3382 swp = Fsame_window_p (XBUFFER (buffer)->name);
3383 if (!NILP (swp) && !no_switch_window (selected_window))
3385 Fswitch_to_buffer (buffer, Qnil);
3386 return display_buffer_1 (selected_window);
3390 /* If the user wants pop-up-frames or display-buffer-reuse-frames,
3391 look for a window showing BUFFER on any visible or iconified frame.
3392 Otherwise search only the current frame. */
3393 if (! NILP (frame))
3394 tem = frame;
3395 else if (pop_up_frames
3396 || display_buffer_reuse_frames
3397 || last_nonminibuf_frame == 0)
3398 XSETFASTINT (tem, 0);
3399 else
3400 XSETFRAME (tem, last_nonminibuf_frame);
3402 window = Fget_buffer_window (buffer, tem);
3403 if (!NILP (window)
3404 && (NILP (not_this_window) || !EQ (window, selected_window)))
3405 return display_buffer_1 (window);
3407 /* Certain buffer names get special handling. */
3408 if (!NILP (Vspecial_display_function) && NILP (swp))
3410 tem = Fspecial_display_p (XBUFFER (buffer)->name);
3411 if (EQ (tem, Qt))
3412 return call1 (Vspecial_display_function, buffer);
3413 if (CONSP (tem))
3414 return call2 (Vspecial_display_function, buffer, tem);
3417 /* If there are no frames open that have more than a minibuffer,
3418 we need to create a new frame. */
3419 if (pop_up_frames || last_nonminibuf_frame == 0)
3421 window = Fframe_selected_window (call0 (Vpop_up_frame_function));
3422 Fset_window_buffer (window, buffer, Qnil);
3423 return display_buffer_1 (window);
3426 f = SELECTED_FRAME ();
3427 if (pop_up_windows
3428 || FRAME_MINIBUF_ONLY_P (f)
3429 /* If the current frame is a special display frame,
3430 don't try to reuse its windows. */
3431 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (f))->dedicated))
3433 Lisp_Object frames;
3435 frames = Qnil;
3436 if (FRAME_MINIBUF_ONLY_P (f))
3437 XSETFRAME (frames, last_nonminibuf_frame);
3438 /* Don't try to create a window if we would get an error. */
3439 if (split_height_threshold < window_min_height << 1)
3440 split_height_threshold = window_min_height << 1;
3442 /* Note that both Fget_largest_window and Fget_lru_window
3443 ignore minibuffers and dedicated windows.
3444 This means they can return nil. */
3446 /* If the frame we would try to split cannot be split,
3447 try other frames. */
3448 if (FRAME_NO_SPLIT_P (NILP (frames) ? f : last_nonminibuf_frame))
3450 /* Try visible frames first. */
3451 window = Fget_largest_window (Qvisible);
3452 /* If that didn't work, try iconified frames. */
3453 if (NILP (window))
3454 window = Fget_largest_window (make_number (0));
3455 if (NILP (window))
3456 window = Fget_largest_window (Qt);
3458 else
3459 window = Fget_largest_window (frames);
3461 /* If we got a tall enough full-width window that can be split,
3462 split it. */
3463 if (!NILP (window)
3464 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame))
3465 && window_height (window) >= split_height_threshold
3466 && WINDOW_FULL_WIDTH_P (XWINDOW (window)))
3467 window = Fsplit_window (window, Qnil, Qnil);
3468 else
3470 Lisp_Object upper, lower, other;
3472 window = Fget_lru_window (frames);
3473 /* If the LRU window is selected, and big enough,
3474 and can be split, split it. */
3475 if (!NILP (window)
3476 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame))
3477 && (EQ (window, selected_window)
3478 || EQ (XWINDOW (window)->parent, Qnil))
3479 && window_height (window) >= window_min_height << 1)
3480 window = Fsplit_window (window, Qnil, Qnil);
3481 /* If Fget_lru_window returned nil, try other approaches. */
3483 /* Try visible frames first. */
3484 if (NILP (window))
3485 window = Fget_buffer_window (buffer, Qvisible);
3486 if (NILP (window))
3487 window = Fget_largest_window (Qvisible);
3488 /* If that didn't work, try iconified frames. */
3489 if (NILP (window))
3490 window = Fget_buffer_window (buffer, make_number (0));
3491 if (NILP (window))
3492 window = Fget_largest_window (make_number (0));
3493 /* Try invisible frames. */
3494 if (NILP (window))
3495 window = Fget_buffer_window (buffer, Qt);
3496 if (NILP (window))
3497 window = Fget_largest_window (Qt);
3498 /* As a last resort, make a new frame. */
3499 if (NILP (window))
3500 window = Fframe_selected_window (call0 (Vpop_up_frame_function));
3501 /* If window appears above or below another,
3502 even out their heights. */
3503 other = upper = lower = Qnil;
3504 if (!NILP (XWINDOW (window)->prev))
3505 other = upper = XWINDOW (window)->prev, lower = window;
3506 if (!NILP (XWINDOW (window)->next))
3507 other = lower = XWINDOW (window)->next, upper = window;
3508 if (!NILP (other)
3509 && !NILP (Veven_window_heights)
3510 /* Check that OTHER and WINDOW are vertically arrayed. */
3511 && !EQ (XWINDOW (other)->top_line, XWINDOW (window)->top_line)
3512 && (XFASTINT (XWINDOW (other)->total_lines)
3513 > XFASTINT (XWINDOW (window)->total_lines)))
3515 int total = (XFASTINT (XWINDOW (other)->total_lines)
3516 + XFASTINT (XWINDOW (window)->total_lines));
3517 enlarge_window (upper,
3518 total / 2 - XFASTINT (XWINDOW (upper)->total_lines),
3519 0, 0);
3523 else
3524 window = Fget_lru_window (Qnil);
3526 Fset_window_buffer (window, buffer, Qnil);
3527 return display_buffer_1 (window);
3531 DEFUN ("force-window-update", Fforce_window_update, Sforce_window_update,
3532 0, 1, 0,
3533 doc: /* Force redisplay of all windows.
3534 If optional arg OBJECT is a window, force redisplay of that window only.
3535 If OBJECT is a buffer or buffer name, force redisplay of all windows
3536 displaying that buffer. */)
3537 (object)
3538 Lisp_Object object;
3540 if (NILP (object))
3542 windows_or_buffers_changed++;
3543 update_mode_lines++;
3544 return Qt;
3547 if (WINDOWP (object))
3549 struct window *w = XWINDOW (object);
3550 mark_window_display_accurate (object, 0);
3551 w->update_mode_line = Qt;
3552 if (BUFFERP (w->buffer))
3553 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
3554 ++update_mode_lines;
3555 return Qt;
3558 if (STRINGP (object))
3559 object = Fget_buffer (object);
3560 if (BUFFERP (object) && !NILP (XBUFFER (object)->name))
3562 /* Walk all windows looking for buffer, and force update
3563 of each of those windows. */
3565 object = window_loop (REDISPLAY_BUFFER_WINDOWS, object, 0, Qvisible);
3566 return NILP (object) ? Qnil : Qt;
3569 /* If nothing suitable was found, just return.
3570 We could signal an error, but this feature will typically be used
3571 asynchronously in timers or process sentinels, so we don't. */
3572 return Qnil;
3576 void
3577 temp_output_buffer_show (buf)
3578 register Lisp_Object buf;
3580 register struct buffer *old = current_buffer;
3581 register Lisp_Object window;
3582 register struct window *w;
3584 XBUFFER (buf)->directory = current_buffer->directory;
3586 Fset_buffer (buf);
3587 BUF_SAVE_MODIFF (XBUFFER (buf)) = MODIFF;
3588 BEGV = BEG;
3589 ZV = Z;
3590 SET_PT (BEG);
3591 #if 0 /* rms: there should be no reason for this. */
3592 XBUFFER (buf)->prevent_redisplay_optimizations_p = 1;
3593 #endif
3594 set_buffer_internal (old);
3596 if (!EQ (Vtemp_buffer_show_function, Qnil))
3597 call1 (Vtemp_buffer_show_function, buf);
3598 else
3600 window = Fdisplay_buffer (buf, Qnil, Qnil);
3602 if (!EQ (XWINDOW (window)->frame, selected_frame))
3603 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
3604 Vminibuf_scroll_window = window;
3605 w = XWINDOW (window);
3606 XSETFASTINT (w->hscroll, 0);
3607 XSETFASTINT (w->min_hscroll, 0);
3608 set_marker_restricted_both (w->start, buf, BEG, BEG);
3609 set_marker_restricted_both (w->pointm, buf, BEG, BEG);
3611 /* Run temp-buffer-show-hook, with the chosen window selected
3612 and its buffer current. */
3614 if (!NILP (Vrun_hooks)
3615 && !NILP (Fboundp (Qtemp_buffer_show_hook))
3616 && !NILP (Fsymbol_value (Qtemp_buffer_show_hook)))
3618 int count = SPECPDL_INDEX ();
3619 Lisp_Object prev_window, prev_buffer;
3620 prev_window = selected_window;
3621 XSETBUFFER (prev_buffer, old);
3623 /* Select the window that was chosen, for running the hook.
3624 Note: Both Fselect_window and select_window_norecord may
3625 set-buffer to the buffer displayed in the window,
3626 so we need to save the current buffer. --stef */
3627 record_unwind_protect (Fset_buffer, prev_buffer);
3628 record_unwind_protect (select_window_norecord, prev_window);
3629 Fselect_window (window, Qt);
3630 Fset_buffer (w->buffer);
3631 call1 (Vrun_hooks, Qtemp_buffer_show_hook);
3632 unbind_to (count, Qnil);
3637 static void
3638 make_dummy_parent (window)
3639 Lisp_Object window;
3641 Lisp_Object new;
3642 register struct window *o, *p;
3643 int i;
3645 o = XWINDOW (window);
3646 p = allocate_window ();
3647 for (i = 0; i < VECSIZE (struct window); ++i)
3648 ((struct Lisp_Vector *) p)->contents[i]
3649 = ((struct Lisp_Vector *)o)->contents[i];
3650 XSETWINDOW (new, p);
3652 ++sequence_number;
3653 XSETFASTINT (p->sequence_number, sequence_number);
3655 /* Put new into window structure in place of window */
3656 replace_window (window, new);
3658 o->next = Qnil;
3659 o->prev = Qnil;
3660 o->vchild = Qnil;
3661 o->hchild = Qnil;
3662 o->parent = new;
3664 p->start = Qnil;
3665 p->pointm = Qnil;
3666 p->buffer = Qnil;
3669 DEFUN ("split-window", Fsplit_window, Ssplit_window, 0, 3, "",
3670 doc: /* Split WINDOW, putting SIZE lines in the first of the pair.
3671 WINDOW defaults to selected one and SIZE to half its size.
3672 If optional third arg HORFLAG is non-nil, split side by side
3673 and put SIZE columns in the first of the pair. In that case,
3674 SIZE includes that window's scroll bar, or the divider column to its right.
3675 Interactively, all arguments are nil.
3677 Returns the newly created window (which is the lower or rightmost one).
3678 The upper or leftmost window is the original one and remains selected.
3679 See Info node `(elisp)Splitting Windows' for more details and examples.*/)
3680 (window, size, horflag)
3681 Lisp_Object window, size, horflag;
3683 register Lisp_Object new;
3684 register struct window *o, *p;
3685 FRAME_PTR fo;
3686 register int size_int;
3688 if (NILP (window))
3689 window = selected_window;
3690 else
3691 CHECK_LIVE_WINDOW (window);
3693 o = XWINDOW (window);
3694 fo = XFRAME (WINDOW_FRAME (o));
3696 if (NILP (size))
3698 if (!NILP (horflag))
3699 /* Calculate the size of the left-hand window, by dividing
3700 the usable space in columns by two.
3701 We round up, since the left-hand window may include
3702 a dividing line, while the right-hand may not. */
3703 size_int = (XFASTINT (o->total_cols) + 1) >> 1;
3704 else
3705 size_int = XFASTINT (o->total_lines) >> 1;
3707 else
3709 CHECK_NUMBER (size);
3710 size_int = XINT (size);
3713 if (MINI_WINDOW_P (o))
3714 error ("Attempt to split minibuffer window");
3715 else if (window_fixed_size_p (o, !NILP (horflag), 0))
3716 error ("Attempt to split fixed-size window");
3718 check_min_window_sizes ();
3720 if (NILP (horflag))
3722 if (size_int < window_min_height)
3723 error ("Window height %d too small (after splitting)", size_int);
3724 if (size_int + window_min_height > XFASTINT (o->total_lines))
3725 error ("Window height %d too small (after splitting)",
3726 XFASTINT (o->total_lines) - size_int);
3727 if (NILP (o->parent)
3728 || NILP (XWINDOW (o->parent)->vchild))
3730 make_dummy_parent (window);
3731 new = o->parent;
3732 XWINDOW (new)->vchild = window;
3735 else
3737 if (size_int < window_min_width)
3738 error ("Window width %d too small (after splitting)", size_int);
3740 if (size_int + window_min_width > XFASTINT (o->total_cols))
3741 error ("Window width %d too small (after splitting)",
3742 XFASTINT (o->total_cols) - size_int);
3743 if (NILP (o->parent)
3744 || NILP (XWINDOW (o->parent)->hchild))
3746 make_dummy_parent (window);
3747 new = o->parent;
3748 XWINDOW (new)->hchild = window;
3752 /* Now we know that window's parent is a vertical combination
3753 if we are dividing vertically, or a horizontal combination
3754 if we are making side-by-side windows */
3756 windows_or_buffers_changed++;
3757 FRAME_WINDOW_SIZES_CHANGED (fo) = 1;
3758 new = make_window ();
3759 p = XWINDOW (new);
3761 p->frame = o->frame;
3762 p->next = o->next;
3763 if (!NILP (p->next))
3764 XWINDOW (p->next)->prev = new;
3765 p->prev = window;
3766 o->next = new;
3767 p->parent = o->parent;
3768 p->buffer = Qt;
3769 p->window_end_valid = Qnil;
3770 bzero (&p->last_cursor, sizeof p->last_cursor);
3772 /* Duplicate special geometry settings. */
3774 p->left_margin_cols = o->left_margin_cols;
3775 p->right_margin_cols = o->right_margin_cols;
3776 p->left_fringe_width = o->left_fringe_width;
3777 p->right_fringe_width = o->right_fringe_width;
3778 p->fringes_outside_margins = o->fringes_outside_margins;
3779 p->scroll_bar_width = o->scroll_bar_width;
3780 p->vertical_scroll_bar_type = o->vertical_scroll_bar_type;
3782 /* Apportion the available frame space among the two new windows */
3784 if (!NILP (horflag))
3786 p->total_lines = o->total_lines;
3787 p->top_line = o->top_line;
3788 XSETFASTINT (p->total_cols, XFASTINT (o->total_cols) - size_int);
3789 XSETFASTINT (o->total_cols, size_int);
3790 XSETFASTINT (p->left_col, XFASTINT (o->left_col) + size_int);
3791 adjust_window_margins (p);
3792 adjust_window_margins (o);
3794 else
3796 p->left_col = o->left_col;
3797 p->total_cols = o->total_cols;
3798 XSETFASTINT (p->total_lines, XFASTINT (o->total_lines) - size_int);
3799 XSETFASTINT (o->total_lines, size_int);
3800 XSETFASTINT (p->top_line, XFASTINT (o->top_line) + size_int);
3803 /* Adjust glyph matrices. */
3804 adjust_glyphs (fo);
3806 Fset_window_buffer (new, o->buffer, Qt);
3807 return new;
3810 DEFUN ("enlarge-window", Fenlarge_window, Senlarge_window, 1, 3, "p",
3811 doc: /* Make current window ARG lines bigger.
3812 From program, optional second arg non-nil means grow sideways ARG columns.
3813 Interactively, if an argument is not given, make the window one line bigger.
3815 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3816 of the siblings above or to the left of the selected window. Only
3817 siblings to the right or below are changed. */)
3818 (arg, side, preserve_before)
3819 register Lisp_Object arg, side, preserve_before;
3821 CHECK_NUMBER (arg);
3822 enlarge_window (selected_window, XINT (arg), !NILP (side),
3823 !NILP (preserve_before));
3825 if (! NILP (Vwindow_configuration_change_hook))
3826 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
3828 return Qnil;
3831 DEFUN ("shrink-window", Fshrink_window, Sshrink_window, 1, 3, "p",
3832 doc: /* Make current window ARG lines smaller.
3833 From program, optional second arg non-nil means shrink sideways arg columns.
3834 Interactively, if an argument is not given, make the window one line smaller.
3836 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3837 of the siblings above or to the left of the selected window. Only
3838 siblings to the right or below are changed. */)
3839 (arg, side, preserve_before)
3840 register Lisp_Object arg, side, preserve_before;
3842 CHECK_NUMBER (arg);
3843 enlarge_window (selected_window, -XINT (arg), !NILP (side),
3844 !NILP (preserve_before));
3846 if (! NILP (Vwindow_configuration_change_hook))
3847 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
3849 return Qnil;
3853 window_height (window)
3854 Lisp_Object window;
3856 register struct window *p = XWINDOW (window);
3857 return WINDOW_TOTAL_LINES (p);
3861 window_width (window)
3862 Lisp_Object window;
3864 register struct window *p = XWINDOW (window);
3865 return WINDOW_TOTAL_COLS (p);
3869 #define CURBEG(w) \
3870 *(widthflag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line))
3872 #define CURSIZE(w) \
3873 *(widthflag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines))
3876 /* Enlarge WINDOW by DELTA. WIDTHFLAG non-zero means
3877 increase its width. Siblings of the selected window are resized to
3878 fulfill the size request. If they become too small in the process,
3879 they will be deleted.
3881 If PRESERVE_BEFORE is nonzero, that means don't alter
3882 the siblings to the left or above WINDOW. */
3884 static void
3885 enlarge_window (window, delta, widthflag, preserve_before)
3886 Lisp_Object window;
3887 int delta, widthflag, preserve_before;
3889 Lisp_Object parent, next, prev;
3890 struct window *p;
3891 Lisp_Object *sizep;
3892 int maximum;
3893 int (*sizefun) P_ ((Lisp_Object))
3894 = widthflag ? window_width : window_height;
3895 void (*setsizefun) P_ ((Lisp_Object, int, int))
3896 = (widthflag ? set_window_width : set_window_height);
3898 /* Check values of window_min_width and window_min_height for
3899 validity. */
3900 check_min_window_sizes ();
3902 /* Give up if this window cannot be resized. */
3903 if (window_fixed_size_p (XWINDOW (window), widthflag, 1))
3904 error ("Window is not resizable");
3906 /* Find the parent of the selected window. */
3907 while (1)
3909 p = XWINDOW (window);
3910 parent = p->parent;
3912 if (NILP (parent))
3914 if (widthflag)
3915 error ("No other window to side of this one");
3916 break;
3919 if (widthflag
3920 ? !NILP (XWINDOW (parent)->hchild)
3921 : !NILP (XWINDOW (parent)->vchild))
3922 break;
3924 window = parent;
3927 sizep = &CURSIZE (window);
3930 register int maxdelta;
3932 /* Compute the maximum size increment this window can have. */
3934 if (preserve_before)
3936 if (!NILP (parent))
3938 maxdelta = (*sizefun) (parent) - XINT (*sizep);
3939 /* Subtract size of siblings before, since we can't take that. */
3940 maxdelta -= XINT (CURBEG (window)) - XINT (CURBEG (parent));
3942 else
3943 maxdelta = (!NILP (p->next) ? ((*sizefun) (p->next)
3944 - window_min_size (XWINDOW (p->next),
3945 widthflag, 0, 0))
3946 : (delta = 0));
3948 else
3949 maxdelta = (!NILP (parent) ? (*sizefun) (parent) - XINT (*sizep)
3950 /* This is a main window followed by a minibuffer. */
3951 : !NILP (p->next) ? ((*sizefun) (p->next)
3952 - window_min_size (XWINDOW (p->next),
3953 widthflag, 0, 0))
3954 /* This is a minibuffer following a main window. */
3955 : !NILP (p->prev) ? ((*sizefun) (p->prev)
3956 - window_min_size (XWINDOW (p->prev),
3957 widthflag, 0, 0))
3958 /* This is a frame with only one window, a minibuffer-only
3959 or a minibufferless frame. */
3960 : (delta = 0));
3962 if (delta > maxdelta)
3963 /* This case traps trying to make the minibuffer
3964 the full frame, or make the only window aside from the
3965 minibuffer the full frame. */
3966 delta = maxdelta;
3969 if (XINT (*sizep) + delta < window_min_size (XWINDOW (window), widthflag, 0, 0))
3971 delete_window (window);
3972 return;
3975 if (delta == 0)
3976 return;
3978 /* Find the total we can get from other siblings without deleting them. */
3979 maximum = 0;
3980 for (next = p->next; ! NILP (next); next = XWINDOW (next)->next)
3981 maximum += (*sizefun) (next) - window_min_size (XWINDOW (next),
3982 widthflag, 0, 0);
3983 if (! preserve_before)
3984 for (prev = p->prev; ! NILP (prev); prev = XWINDOW (prev)->prev)
3985 maximum += (*sizefun) (prev) - window_min_size (XWINDOW (prev),
3986 widthflag, 0, 0);
3988 /* If we can get it all from them without deleting them, do so. */
3989 if (delta <= maximum)
3991 Lisp_Object first_unaffected;
3992 Lisp_Object first_affected;
3993 int fixed_p;
3995 next = p->next;
3996 prev = p->prev;
3997 first_affected = window;
3998 /* Look at one sibling at a time,
3999 moving away from this window in both directions alternately,
4000 and take as much as we can get without deleting that sibling. */
4001 while (delta != 0
4002 && (!NILP (next) || (!preserve_before && !NILP (prev))))
4004 if (! NILP (next))
4006 int this_one = ((*sizefun) (next)
4007 - window_min_size (XWINDOW (next),
4008 widthflag, 0, &fixed_p));
4009 if (!fixed_p)
4011 if (this_one > delta)
4012 this_one = delta;
4014 (*setsizefun) (next, (*sizefun) (next) - this_one, 0);
4015 (*setsizefun) (window, XINT (*sizep) + this_one, 0);
4017 delta -= this_one;
4020 next = XWINDOW (next)->next;
4023 if (delta == 0)
4024 break;
4026 if (!preserve_before && ! NILP (prev))
4028 int this_one = ((*sizefun) (prev)
4029 - window_min_size (XWINDOW (prev),
4030 widthflag, 0, &fixed_p));
4031 if (!fixed_p)
4033 if (this_one > delta)
4034 this_one = delta;
4036 first_affected = prev;
4038 (*setsizefun) (prev, (*sizefun) (prev) - this_one, 0);
4039 (*setsizefun) (window, XINT (*sizep) + this_one, 0);
4041 delta -= this_one;
4044 prev = XWINDOW (prev)->prev;
4048 xassert (delta == 0);
4050 /* Now recalculate the edge positions of all the windows affected,
4051 based on the new sizes. */
4052 first_unaffected = next;
4053 prev = first_affected;
4054 for (next = XWINDOW (prev)->next; ! EQ (next, first_unaffected);
4055 prev = next, next = XWINDOW (next)->next)
4057 XSETINT (CURBEG (next), XINT (CURBEG (prev)) + (*sizefun) (prev));
4058 /* This does not change size of NEXT,
4059 but it propagates the new top edge to its children */
4060 (*setsizefun) (next, (*sizefun) (next), 0);
4063 else
4065 register int delta1;
4066 register int opht = (*sizefun) (parent);
4068 if (opht <= XINT (*sizep) + delta)
4070 /* If trying to grow this window to or beyond size of the parent,
4071 just delete all the sibling windows. */
4072 Lisp_Object start, tem, next;
4074 start = XWINDOW (parent)->vchild;
4075 if (NILP (start))
4076 start = XWINDOW (parent)->hchild;
4078 /* Delete any siblings that come after WINDOW. */
4079 tem = XWINDOW (window)->next;
4080 while (! NILP (tem))
4082 next = XWINDOW (tem)->next;
4083 delete_window (tem);
4084 tem = next;
4087 /* Delete any siblings that come after WINDOW.
4088 Note that if START is not WINDOW, then WINDOW still
4089 Fhas siblings, so WINDOW has not yet replaced its parent. */
4090 tem = start;
4091 while (! EQ (tem, window))
4093 next = XWINDOW (tem)->next;
4094 delete_window (tem);
4095 tem = next;
4098 else
4100 /* Otherwise, make delta1 just right so that if we add
4101 delta1 lines to this window and to the parent, and then
4102 shrink the parent back to its original size, the new
4103 proportional size of this window will increase by delta.
4105 The function size_window will compute the new height h'
4106 of the window from delta1 as:
4108 e = delta1/n
4109 x = delta1 - delta1/n * n for the 1st resizable child
4110 h' = h + e + x
4112 where n is the number of children that can be resized.
4113 We can ignore x by choosing a delta1 that is a multiple of
4114 n. We want the height of this window to come out as
4116 h' = h + delta
4118 So, delta1 must be
4120 h + e = h + delta
4121 delta1/n = delta
4122 delta1 = n * delta.
4124 The number of children n equals the number of resizable
4125 children of this window + 1 because we know window itself
4126 is resizable (otherwise we would have signalled an error. */
4128 struct window *w = XWINDOW (window);
4129 Lisp_Object s;
4130 int n = 1;
4132 for (s = w->next; !NILP (s); s = XWINDOW (s)->next)
4133 if (!window_fixed_size_p (XWINDOW (s), widthflag, 0))
4134 ++n;
4135 for (s = w->prev; !NILP (s); s = XWINDOW (s)->prev)
4136 if (!window_fixed_size_p (XWINDOW (s), widthflag, 0))
4137 ++n;
4139 delta1 = n * delta;
4141 /* Add delta1 lines or columns to this window, and to the parent,
4142 keeping things consistent while not affecting siblings. */
4143 XSETINT (CURSIZE (parent), opht + delta1);
4144 (*setsizefun) (window, XINT (*sizep) + delta1, 0);
4146 /* Squeeze out delta1 lines or columns from our parent,
4147 shriking this window and siblings proportionately.
4148 This brings parent back to correct size.
4149 Delta1 was calculated so this makes this window the desired size,
4150 taking it all out of the siblings. */
4151 (*setsizefun) (parent, opht, 0);
4156 XSETFASTINT (p->last_modified, 0);
4157 XSETFASTINT (p->last_overlay_modified, 0);
4159 /* Adjust glyph matrices. */
4160 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window))));
4163 #undef CURBEG
4164 #undef CURSIZE
4168 /***********************************************************************
4169 Resizing Mini-Windows
4170 ***********************************************************************/
4172 static void shrink_window_lowest_first P_ ((struct window *, int));
4174 enum save_restore_action
4176 CHECK_ORIG_SIZES,
4177 SAVE_ORIG_SIZES,
4178 RESTORE_ORIG_SIZES
4181 static int save_restore_orig_size P_ ((struct window *,
4182 enum save_restore_action));
4184 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
4185 from lowest windows first. */
4187 static void
4188 shrink_window_lowest_first (w, height)
4189 struct window *w;
4190 int height;
4192 struct window *c;
4193 Lisp_Object child;
4194 int old_height;
4196 xassert (!MINI_WINDOW_P (w));
4198 /* Set redisplay hints. */
4199 XSETFASTINT (w->last_modified, 0);
4200 XSETFASTINT (w->last_overlay_modified, 0);
4201 windows_or_buffers_changed++;
4202 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w))) = 1;
4204 old_height = XFASTINT (w->total_lines);
4205 XSETFASTINT (w->total_lines, height);
4207 if (!NILP (w->hchild))
4209 for (child = w->hchild; !NILP (child); child = c->next)
4211 c = XWINDOW (child);
4212 c->top_line = w->top_line;
4213 shrink_window_lowest_first (c, height);
4216 else if (!NILP (w->vchild))
4218 Lisp_Object last_child;
4219 int delta = old_height - height;
4220 int last_top;
4222 last_child = Qnil;
4224 /* Find the last child. We are taking space from lowest windows
4225 first, so we iterate over children from the last child
4226 backwards. */
4227 for (child = w->vchild; !NILP (child); child = XWINDOW (child)->next)
4228 last_child = child;
4230 /* Assign new heights. We leave only MIN_SAFE_WINDOW_HEIGHT. */
4231 for (child = last_child; delta && !NILP (child); child = c->prev)
4233 int this_one;
4235 c = XWINDOW (child);
4236 this_one = XFASTINT (c->total_lines) - MIN_SAFE_WINDOW_HEIGHT;
4238 if (this_one > delta)
4239 this_one = delta;
4241 shrink_window_lowest_first (c, XFASTINT (c->total_lines) - this_one);
4242 delta -= this_one;
4245 /* Compute new positions. */
4246 last_top = XINT (w->top_line);
4247 for (child = w->vchild; !NILP (child); child = c->next)
4249 c = XWINDOW (child);
4250 c->top_line = make_number (last_top);
4251 shrink_window_lowest_first (c, XFASTINT (c->total_lines));
4252 last_top += XFASTINT (c->total_lines);
4258 /* Save, restore, or check positions and sizes in the window tree
4259 rooted at W. ACTION says what to do.
4261 If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and
4262 orig_total_lines members are valid for all windows in the window
4263 tree. Value is non-zero if they are valid.
4265 If ACTION is SAVE_ORIG_SIZES, save members top and height in
4266 orig_top_line and orig_total_lines for all windows in the tree.
4268 If ACTION is RESTORE_ORIG_SIZES, restore top and height from values
4269 stored in orig_top_line and orig_total_lines for all windows. */
4271 static int
4272 save_restore_orig_size (w, action)
4273 struct window *w;
4274 enum save_restore_action action;
4276 int success_p = 1;
4278 while (w)
4280 if (!NILP (w->hchild))
4282 if (!save_restore_orig_size (XWINDOW (w->hchild), action))
4283 success_p = 0;
4285 else if (!NILP (w->vchild))
4287 if (!save_restore_orig_size (XWINDOW (w->vchild), action))
4288 success_p = 0;
4291 switch (action)
4293 case CHECK_ORIG_SIZES:
4294 if (!INTEGERP (w->orig_top_line) || !INTEGERP (w->orig_total_lines))
4295 return 0;
4296 break;
4298 case SAVE_ORIG_SIZES:
4299 w->orig_top_line = w->top_line;
4300 w->orig_total_lines = w->total_lines;
4301 XSETFASTINT (w->last_modified, 0);
4302 XSETFASTINT (w->last_overlay_modified, 0);
4303 break;
4305 case RESTORE_ORIG_SIZES:
4306 xassert (INTEGERP (w->orig_top_line) && INTEGERP (w->orig_total_lines));
4307 w->top_line = w->orig_top_line;
4308 w->total_lines = w->orig_total_lines;
4309 w->orig_total_lines = w->orig_top_line = Qnil;
4310 XSETFASTINT (w->last_modified, 0);
4311 XSETFASTINT (w->last_overlay_modified, 0);
4312 break;
4314 default:
4315 abort ();
4318 w = NILP (w->next) ? NULL : XWINDOW (w->next);
4321 return success_p;
4325 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
4326 without deleting other windows. */
4328 void
4329 grow_mini_window (w, delta)
4330 struct window *w;
4331 int delta;
4333 struct frame *f = XFRAME (w->frame);
4334 struct window *root;
4336 xassert (MINI_WINDOW_P (w));
4337 xassert (delta >= 0);
4339 /* Check values of window_min_width and window_min_height for
4340 validity. */
4341 check_min_window_sizes ();
4343 /* Compute how much we can enlarge the mini-window without deleting
4344 other windows. */
4345 root = XWINDOW (FRAME_ROOT_WINDOW (f));
4346 if (delta)
4348 int min_height = window_min_size (root, 0, 0, 0);
4349 if (XFASTINT (root->total_lines) - delta < min_height)
4350 /* Note that the root window may already be smaller than
4351 min_height. */
4352 delta = max (0, XFASTINT (root->total_lines) - min_height);
4355 if (delta)
4357 /* Save original window sizes and positions, if not already done. */
4358 if (!save_restore_orig_size (root, CHECK_ORIG_SIZES))
4359 save_restore_orig_size (root, SAVE_ORIG_SIZES);
4361 /* Shrink other windows. */
4362 shrink_window_lowest_first (root, XFASTINT (root->total_lines) - delta);
4364 /* Grow the mini-window. */
4365 w->top_line = make_number (XFASTINT (root->top_line) + XFASTINT (root->total_lines));
4366 w->total_lines = make_number (XFASTINT (w->total_lines) + delta);
4367 XSETFASTINT (w->last_modified, 0);
4368 XSETFASTINT (w->last_overlay_modified, 0);
4370 adjust_glyphs (f);
4375 /* Shrink mini-window W. If there is recorded info about window sizes
4376 before a call to grow_mini_window, restore recorded window sizes.
4377 Otherwise, if the mini-window is higher than 1 line, resize it to 1
4378 line. */
4380 void
4381 shrink_mini_window (w)
4382 struct window *w;
4384 struct frame *f = XFRAME (w->frame);
4385 struct window *root = XWINDOW (FRAME_ROOT_WINDOW (f));
4387 if (save_restore_orig_size (root, CHECK_ORIG_SIZES))
4389 save_restore_orig_size (root, RESTORE_ORIG_SIZES);
4390 adjust_glyphs (f);
4391 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
4392 windows_or_buffers_changed = 1;
4394 else if (XFASTINT (w->total_lines) > 1)
4396 /* Distribute the additional lines of the mini-window
4397 among the other windows. */
4398 Lisp_Object window;
4399 XSETWINDOW (window, w);
4400 enlarge_window (window, 1 - XFASTINT (w->total_lines), 0, 0);
4406 /* Mark window cursors off for all windows in the window tree rooted
4407 at W by setting their phys_cursor_on_p flag to zero. Called from
4408 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4409 the frame are cleared. */
4411 void
4412 mark_window_cursors_off (w)
4413 struct window *w;
4415 while (w)
4417 if (!NILP (w->hchild))
4418 mark_window_cursors_off (XWINDOW (w->hchild));
4419 else if (!NILP (w->vchild))
4420 mark_window_cursors_off (XWINDOW (w->vchild));
4421 else
4422 w->phys_cursor_on_p = 0;
4424 w = NILP (w->next) ? 0 : XWINDOW (w->next);
4429 /* Return number of lines of text (not counting mode lines) in W. */
4432 window_internal_height (w)
4433 struct window *w;
4435 int ht = XFASTINT (w->total_lines);
4437 if (!MINI_WINDOW_P (w))
4439 if (!NILP (w->parent)
4440 || !NILP (w->vchild)
4441 || !NILP (w->hchild)
4442 || !NILP (w->next)
4443 || !NILP (w->prev)
4444 || WINDOW_WANTS_MODELINE_P (w))
4445 --ht;
4447 if (WINDOW_WANTS_HEADER_LINE_P (w))
4448 --ht;
4451 return ht;
4455 /* Return the number of columns in W.
4456 Don't count columns occupied by scroll bars or the vertical bar
4457 separating W from the sibling to its right. */
4460 window_box_text_cols (w)
4461 struct window *w;
4463 struct frame *f = XFRAME (WINDOW_FRAME (w));
4464 int width = XINT (w->total_cols);
4466 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
4467 /* Scroll bars occupy a few columns. */
4468 width -= WINDOW_CONFIG_SCROLL_BAR_COLS (w);
4469 else if (!FRAME_WINDOW_P (f)
4470 && !WINDOW_RIGHTMOST_P (w) && !WINDOW_FULL_WIDTH_P (w))
4471 /* The column of `|' characters separating side-by-side windows
4472 occupies one column only. */
4473 width -= 1;
4475 if (FRAME_WINDOW_P (f))
4476 /* On window-systems, fringes and display margins cannot be
4477 used for normal text. */
4478 width -= (WINDOW_FRINGE_COLS (w)
4479 + WINDOW_LEFT_MARGIN_COLS (w)
4480 + WINDOW_RIGHT_MARGIN_COLS (w));
4482 return width;
4486 /************************************************************************
4487 Window Scrolling
4488 ***********************************************************************/
4490 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4491 N screen-fulls, which is defined as the height of the window minus
4492 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4493 instead. Negative values of N mean scroll down. NOERROR non-zero
4494 means don't signal an error if we try to move over BEGV or ZV,
4495 respectively. */
4497 static void
4498 window_scroll (window, n, whole, noerror)
4499 Lisp_Object window;
4500 int n;
4501 int whole;
4502 int noerror;
4504 immediate_quit = 1;
4506 /* If we must, use the pixel-based version which is much slower than
4507 the line-based one but can handle varying line heights. */
4508 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window)->frame)))
4509 window_scroll_pixel_based (window, n, whole, noerror);
4510 else
4511 window_scroll_line_based (window, n, whole, noerror);
4513 immediate_quit = 0;
4517 /* Implementation of window_scroll that works based on pixel line
4518 heights. See the comment of window_scroll for parameter
4519 descriptions. */
4521 static void
4522 window_scroll_pixel_based (window, n, whole, noerror)
4523 Lisp_Object window;
4524 int n;
4525 int whole;
4526 int noerror;
4528 struct it it;
4529 struct window *w = XWINDOW (window);
4530 struct text_pos start;
4531 Lisp_Object tem;
4532 int this_scroll_margin;
4533 int preserve_y;
4534 /* True if we fiddled the window vscroll field without really scrolling. */
4535 int vscrolled = 0;
4537 SET_TEXT_POS_FROM_MARKER (start, w->start);
4539 /* If PT is not visible in WINDOW, move back one half of
4540 the screen. Allow PT to be partially visible, otherwise
4541 something like (scroll-down 1) with PT in the line before
4542 the partially visible one would recenter. */
4543 tem = Fpos_visible_in_window_p (make_number (PT), window, Qt);
4544 if (NILP (tem))
4546 /* Move backward half the height of the window. Performance note:
4547 vmotion used here is about 10% faster, but would give wrong
4548 results for variable height lines. */
4549 init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID);
4550 it.current_y = it.last_visible_y;
4551 move_it_vertically_backward (&it, window_box_height (w) / 2);
4553 /* The function move_iterator_vertically may move over more than
4554 the specified y-distance. If it->w is small, e.g. a
4555 mini-buffer window, we may end up in front of the window's
4556 display area. This is the case when Start displaying at the
4557 start of the line containing PT in this case. */
4558 if (it.current_y <= 0)
4560 init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID);
4561 move_it_vertically_backward (&it, 0);
4562 it.current_y = 0;
4565 start = it.current.pos;
4568 /* If scroll_preserve_screen_position is non-nil, we try to set
4569 point in the same window line as it is now, so get that line. */
4570 if (!NILP (Vscroll_preserve_screen_position))
4572 start_display (&it, w, start);
4573 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
4574 preserve_y = it.current_y;
4576 else
4577 preserve_y = -1;
4579 /* Move iterator it from start the specified distance forward or
4580 backward. The result is the new window start. */
4581 start_display (&it, w, start);
4582 if (whole)
4584 int screen_full = (window_box_height (w)
4585 - next_screen_context_lines * FRAME_LINE_HEIGHT (it.f));
4586 int dy = n * screen_full;
4588 /* Note that move_it_vertically always moves the iterator to the
4589 start of a line. So, if the last line doesn't have a newline,
4590 we would end up at the start of the line ending at ZV. */
4591 if (dy <= 0)
4592 move_it_vertically_backward (&it, -dy);
4593 else if (dy > 0)
4594 move_it_to (&it, ZV, -1, it.current_y + dy, -1,
4595 MOVE_TO_POS | MOVE_TO_Y);
4597 else
4598 move_it_by_lines (&it, n, 1);
4600 /* We failed if we find ZV is already on the screen (scrolling up,
4601 means there's nothing past the end), or if we can't start any
4602 earlier (scrolling down, means there's nothing past the top). */
4603 if ((n > 0 && IT_CHARPOS (it) == ZV)
4604 || (n < 0 && IT_CHARPOS (it) == CHARPOS (start)))
4606 if (IT_CHARPOS (it) == ZV)
4608 if (it.current_y < it.last_visible_y
4609 && (it.current_y + it.max_ascent + it.max_descent
4610 >= it.last_visible_y))
4612 /* The last line was only partially visible, make it fully
4613 visible. */
4614 w->vscroll = (it.last_visible_y
4615 - it.current_y + it.max_ascent + it.max_descent);
4616 adjust_glyphs (it.f);
4618 else if (noerror)
4619 return;
4620 else
4621 Fsignal (Qend_of_buffer, Qnil);
4623 else
4625 if (w->vscroll != 0)
4626 /* The first line was only partially visible, make it fully
4627 visible. */
4628 w->vscroll = 0;
4629 else if (noerror)
4630 return;
4631 else
4632 Fsignal (Qbeginning_of_buffer, Qnil);
4635 /* If control gets here, then we vscrolled. */
4637 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
4639 /* Don't try to change the window start below. */
4640 vscrolled = 1;
4643 if (! vscrolled)
4645 int pos = IT_CHARPOS (it);
4646 int bytepos;
4648 /* If in the middle of a multi-glyph character move forward to
4649 the next character. */
4650 if (in_display_vector_p (&it))
4652 ++pos;
4653 move_it_to (&it, pos, -1, -1, -1, MOVE_TO_POS);
4656 /* Set the window start, and set up the window for redisplay. */
4657 set_marker_restricted (w->start, make_number (pos),
4658 w->buffer);
4659 bytepos = XMARKER (w->start)->bytepos;
4660 w->start_at_line_beg = ((pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n')
4661 ? Qt : Qnil);
4662 w->update_mode_line = Qt;
4663 XSETFASTINT (w->last_modified, 0);
4664 XSETFASTINT (w->last_overlay_modified, 0);
4665 /* Set force_start so that redisplay_window will run the
4666 window-scroll-functions. */
4667 w->force_start = Qt;
4670 /* The rest of this function uses current_y in a nonstandard way,
4671 not including the height of the header line if any. */
4672 it.current_y = it.vpos = 0;
4674 /* Move PT out of scroll margins.
4675 This code wants current_y to be zero at the window start position
4676 even if there is a header line. */
4677 this_scroll_margin = max (0, scroll_margin);
4678 this_scroll_margin = min (this_scroll_margin, XFASTINT (w->total_lines) / 4);
4679 this_scroll_margin *= FRAME_LINE_HEIGHT (it.f);
4681 if (n > 0)
4683 /* We moved the window start towards ZV, so PT may be now
4684 in the scroll margin at the top. */
4685 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
4686 if (IT_CHARPOS (it) == PT && it.current_y >= this_scroll_margin)
4687 /* We found PT at a legitimate height. Leave it alone. */
4689 else if (preserve_y >= 0)
4691 /* If we have a header line, take account of it.
4692 This is necessary because we set it.current_y to 0, above. */
4693 if (WINDOW_WANTS_HEADER_LINE_P (w))
4694 preserve_y -= CURRENT_HEADER_LINE_HEIGHT (w);
4696 move_it_to (&it, -1, -1, preserve_y, -1, MOVE_TO_Y);
4697 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4699 else
4701 while (it.current_y < this_scroll_margin)
4703 int prev = it.current_y;
4704 move_it_by_lines (&it, 1, 1);
4705 if (prev == it.current_y)
4706 break;
4708 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4711 else if (n < 0)
4713 int charpos, bytepos;
4715 /* Save our position, for the preserve_y case. */
4716 charpos = IT_CHARPOS (it);
4717 bytepos = IT_BYTEPOS (it);
4719 /* We moved the window start towards BEGV, so PT may be now
4720 in the scroll margin at the bottom. */
4721 move_it_to (&it, PT, -1,
4722 it.last_visible_y - this_scroll_margin - 1, -1,
4723 MOVE_TO_POS | MOVE_TO_Y);
4725 if (IT_CHARPOS (it) == PT)
4726 /* We found PT before we found the display margin, so PT is ok. */
4728 else if (preserve_y >= 0)
4730 SET_TEXT_POS_FROM_MARKER (start, w->start);
4731 start_display (&it, w, start);
4732 #if 0 /* It's wrong to subtract this here
4733 because we called start_display again
4734 and did not alter it.current_y this time. */
4736 /* If we have a header line, take account of it. */
4737 if (WINDOW_WANTS_HEADER_LINE_P (w))
4738 preserve_y -= CURRENT_HEADER_LINE_HEIGHT (w);
4739 #endif
4741 move_it_to (&it, -1, -1, preserve_y, -1, MOVE_TO_Y);
4742 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4744 else
4746 /* Save our position, in case it's correct. */
4747 charpos = IT_CHARPOS (it);
4748 bytepos = IT_BYTEPOS (it);
4750 /* See if point is on a partially visible line at the end. */
4751 move_it_by_lines (&it, 1, 1);
4753 if (it.current_y > it.last_visible_y)
4754 /* The last line was only partially visible, so back up two
4755 lines to make sure we're on a fully visible line. */
4757 move_it_by_lines (&it, -2, 0);
4758 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4760 else
4761 /* No, the position we saved is OK, so use it. */
4762 SET_PT_BOTH (charpos, bytepos);
4768 /* Implementation of window_scroll that works based on screen lines.
4769 See the comment of window_scroll for parameter descriptions. */
4771 static void
4772 window_scroll_line_based (window, n, whole, noerror)
4773 Lisp_Object window;
4774 int n;
4775 int whole;
4776 int noerror;
4778 register struct window *w = XWINDOW (window);
4779 register int opoint = PT, opoint_byte = PT_BYTE;
4780 register int pos, pos_byte;
4781 register int ht = window_internal_height (w);
4782 register Lisp_Object tem;
4783 int lose;
4784 Lisp_Object bolp;
4785 int startpos;
4786 struct position posit;
4787 int original_vpos;
4789 /* If scrolling screen-fulls, compute the number of lines to
4790 scroll from the window's height. */
4791 if (whole)
4792 n *= max (1, ht - next_screen_context_lines);
4794 startpos = marker_position (w->start);
4796 posit = *compute_motion (startpos, 0, 0, 0,
4797 PT, ht, 0,
4798 -1, XINT (w->hscroll),
4799 0, w);
4800 original_vpos = posit.vpos;
4802 XSETFASTINT (tem, PT);
4803 tem = Fpos_visible_in_window_p (tem, window, Qnil);
4805 if (NILP (tem))
4807 Fvertical_motion (make_number (- (ht / 2)), window);
4808 startpos = PT;
4811 SET_PT (startpos);
4812 lose = n < 0 && PT == BEGV;
4813 Fvertical_motion (make_number (n), window);
4814 pos = PT;
4815 pos_byte = PT_BYTE;
4816 bolp = Fbolp ();
4817 SET_PT_BOTH (opoint, opoint_byte);
4819 if (lose)
4821 if (noerror)
4822 return;
4823 else
4824 Fsignal (Qbeginning_of_buffer, Qnil);
4827 if (pos < ZV)
4829 int this_scroll_margin = scroll_margin;
4831 /* Don't use a scroll margin that is negative or too large. */
4832 if (this_scroll_margin < 0)
4833 this_scroll_margin = 0;
4835 if (XINT (w->total_lines) < 4 * scroll_margin)
4836 this_scroll_margin = XINT (w->total_lines) / 4;
4838 set_marker_restricted_both (w->start, w->buffer, pos, pos_byte);
4839 w->start_at_line_beg = bolp;
4840 w->update_mode_line = Qt;
4841 XSETFASTINT (w->last_modified, 0);
4842 XSETFASTINT (w->last_overlay_modified, 0);
4843 /* Set force_start so that redisplay_window will run
4844 the window-scroll-functions. */
4845 w->force_start = Qt;
4847 if (whole && !NILP (Vscroll_preserve_screen_position))
4849 SET_PT_BOTH (pos, pos_byte);
4850 Fvertical_motion (make_number (original_vpos), window);
4852 /* If we scrolled forward, put point enough lines down
4853 that it is outside the scroll margin. */
4854 else if (n > 0)
4856 int top_margin;
4858 if (this_scroll_margin > 0)
4860 SET_PT_BOTH (pos, pos_byte);
4861 Fvertical_motion (make_number (this_scroll_margin), window);
4862 top_margin = PT;
4864 else
4865 top_margin = pos;
4867 if (top_margin <= opoint)
4868 SET_PT_BOTH (opoint, opoint_byte);
4869 else if (!NILP (Vscroll_preserve_screen_position))
4871 SET_PT_BOTH (pos, pos_byte);
4872 Fvertical_motion (make_number (original_vpos), window);
4874 else
4875 SET_PT (top_margin);
4877 else if (n < 0)
4879 int bottom_margin;
4881 /* If we scrolled backward, put point near the end of the window
4882 but not within the scroll margin. */
4883 SET_PT_BOTH (pos, pos_byte);
4884 tem = Fvertical_motion (make_number (ht - this_scroll_margin), window);
4885 if (XFASTINT (tem) == ht - this_scroll_margin)
4886 bottom_margin = PT;
4887 else
4888 bottom_margin = PT + 1;
4890 if (bottom_margin > opoint)
4891 SET_PT_BOTH (opoint, opoint_byte);
4892 else
4894 if (!NILP (Vscroll_preserve_screen_position))
4896 SET_PT_BOTH (pos, pos_byte);
4897 Fvertical_motion (make_number (original_vpos), window);
4899 else
4900 Fvertical_motion (make_number (-1), window);
4904 else
4906 if (noerror)
4907 return;
4908 else
4909 Fsignal (Qend_of_buffer, Qnil);
4914 /* Scroll selected_window up or down. If N is nil, scroll a
4915 screen-full which is defined as the height of the window minus
4916 next_screen_context_lines. If N is the symbol `-', scroll.
4917 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4918 up. This is the guts of Fscroll_up and Fscroll_down. */
4920 static void
4921 scroll_command (n, direction)
4922 Lisp_Object n;
4923 int direction;
4925 int count = SPECPDL_INDEX ();
4927 xassert (abs (direction) == 1);
4929 /* If selected window's buffer isn't current, make it current for
4930 the moment. But don't screw up if window_scroll gets an error. */
4931 if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
4933 record_unwind_protect (save_excursion_restore, save_excursion_save ());
4934 Fset_buffer (XWINDOW (selected_window)->buffer);
4936 /* Make redisplay consider other windows than just selected_window. */
4937 ++windows_or_buffers_changed;
4940 if (NILP (n))
4941 window_scroll (selected_window, direction, 1, 0);
4942 else if (EQ (n, Qminus))
4943 window_scroll (selected_window, -direction, 1, 0);
4944 else
4946 n = Fprefix_numeric_value (n);
4947 window_scroll (selected_window, XINT (n) * direction, 0, 0);
4950 unbind_to (count, Qnil);
4953 DEFUN ("scroll-up", Fscroll_up, Sscroll_up, 0, 1, "P",
4954 doc: /* Scroll text of current window upward ARG lines.
4955 If ARG is omitted or nil, scroll upward by a near full screen.
4956 A near full screen is `next-screen-context-lines' less than a full screen.
4957 Negative ARG means scroll downward.
4958 If ARG is the atom `-', scroll downward by nearly full screen.
4959 When calling from a program, supply as argument a number, nil, or `-'. */)
4960 (arg)
4961 Lisp_Object arg;
4963 scroll_command (arg, 1);
4964 return Qnil;
4967 DEFUN ("scroll-down", Fscroll_down, Sscroll_down, 0, 1, "P",
4968 doc: /* Scroll text of current window down ARG lines.
4969 If ARG is omitted or nil, scroll down by a near full screen.
4970 A near full screen is `next-screen-context-lines' less than a full screen.
4971 Negative ARG means scroll upward.
4972 If ARG is the atom `-', scroll upward by nearly full screen.
4973 When calling from a program, supply as argument a number, nil, or `-'. */)
4974 (arg)
4975 Lisp_Object arg;
4977 scroll_command (arg, -1);
4978 return Qnil;
4981 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling, Sother_window_for_scrolling, 0, 0, 0,
4982 doc: /* Return the other window for \"other window scroll\" commands.
4983 If `other-window-scroll-buffer' is non-nil, a window
4984 showing that buffer is used.
4985 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4986 specifies the window. This takes precedence over
4987 `other-window-scroll-buffer'. */)
4990 Lisp_Object window;
4992 if (MINI_WINDOW_P (XWINDOW (selected_window))
4993 && !NILP (Vminibuf_scroll_window))
4994 window = Vminibuf_scroll_window;
4995 /* If buffer is specified, scroll that buffer. */
4996 else if (!NILP (Vother_window_scroll_buffer))
4998 window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil);
4999 if (NILP (window))
5000 window = Fdisplay_buffer (Vother_window_scroll_buffer, Qt, Qnil);
5002 else
5004 /* Nothing specified; look for a neighboring window on the same
5005 frame. */
5006 window = Fnext_window (selected_window, Qnil, Qnil);
5008 if (EQ (window, selected_window))
5009 /* That didn't get us anywhere; look for a window on another
5010 visible frame. */
5012 window = Fnext_window (window, Qnil, Qt);
5013 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window))))
5014 && ! EQ (window, selected_window));
5017 CHECK_LIVE_WINDOW (window);
5019 if (EQ (window, selected_window))
5020 error ("There is no other window");
5022 return window;
5025 DEFUN ("scroll-other-window", Fscroll_other_window, Sscroll_other_window, 0, 1, "P",
5026 doc: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5027 A near full screen is `next-screen-context-lines' less than a full screen.
5028 The next window is the one below the current one; or the one at the top
5029 if the current one is at the bottom. Negative ARG means scroll downward.
5030 If ARG is the atom `-', scroll downward by nearly full screen.
5031 When calling from a program, supply as argument a number, nil, or `-'.
5033 If `other-window-scroll-buffer' is non-nil, scroll the window
5034 showing that buffer, popping the buffer up if necessary.
5035 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5036 specifies the window to scroll. This takes precedence over
5037 `other-window-scroll-buffer'. */)
5038 (arg)
5039 Lisp_Object arg;
5041 Lisp_Object window;
5042 struct window *w;
5043 int count = SPECPDL_INDEX ();
5045 window = Fother_window_for_scrolling ();
5046 w = XWINDOW (window);
5048 /* Don't screw up if window_scroll gets an error. */
5049 record_unwind_protect (save_excursion_restore, save_excursion_save ());
5050 ++windows_or_buffers_changed;
5052 Fset_buffer (w->buffer);
5053 SET_PT (marker_position (w->pointm));
5055 if (NILP (arg))
5056 window_scroll (window, 1, 1, 1);
5057 else if (EQ (arg, Qminus))
5058 window_scroll (window, -1, 1, 1);
5059 else
5061 if (CONSP (arg))
5062 arg = Fcar (arg);
5063 CHECK_NUMBER (arg);
5064 window_scroll (window, XINT (arg), 0, 1);
5067 set_marker_both (w->pointm, Qnil, PT, PT_BYTE);
5068 unbind_to (count, Qnil);
5070 return Qnil;
5073 DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 2, "P\np",
5074 doc: /* Scroll selected window display ARG columns left.
5075 Default for ARG is window width minus 2.
5076 Value is the total amount of leftward horizontal scrolling in
5077 effect after the change.
5078 If SET_MINIMUM is non-nil, the new scroll amount becomes the
5079 lower bound for automatic scrolling, i.e. automatic scrolling
5080 will not scroll a window to a column less than the value returned
5081 by this function. This happens in an interactive call. */)
5082 (arg, set_minimum)
5083 register Lisp_Object arg, set_minimum;
5085 Lisp_Object result;
5086 int hscroll;
5087 struct window *w = XWINDOW (selected_window);
5089 if (NILP (arg))
5090 XSETFASTINT (arg, window_box_text_cols (w) - 2);
5091 else
5092 arg = Fprefix_numeric_value (arg);
5094 hscroll = XINT (w->hscroll) + XINT (arg);
5095 result = Fset_window_hscroll (selected_window, make_number (hscroll));
5097 if (!NILP (set_minimum))
5098 w->min_hscroll = w->hscroll;
5100 return result;
5103 DEFUN ("scroll-right", Fscroll_right, Sscroll_right, 0, 2, "P\np",
5104 doc: /* Scroll selected window display ARG columns right.
5105 Default for ARG is window width minus 2.
5106 Value is the total amount of leftward horizontal scrolling in
5107 effect after the change.
5108 If SET_MINIMUM is non-nil, the new scroll amount becomes the
5109 lower bound for automatic scrolling, i.e. automatic scrolling
5110 will not scroll a window to a column less than the value returned
5111 by this function. This happens in an interactive call. */)
5112 (arg, set_minimum)
5113 register Lisp_Object arg, set_minimum;
5115 Lisp_Object result;
5116 int hscroll;
5117 struct window *w = XWINDOW (selected_window);
5119 if (NILP (arg))
5120 XSETFASTINT (arg, window_box_text_cols (w) - 2);
5121 else
5122 arg = Fprefix_numeric_value (arg);
5124 hscroll = XINT (w->hscroll) - XINT (arg);
5125 result = Fset_window_hscroll (selected_window, make_number (hscroll));
5127 if (!NILP (set_minimum))
5128 w->min_hscroll = w->hscroll;
5130 return result;
5133 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window, Sminibuffer_selected_window, 0, 0, 0,
5134 doc: /* Return the window which was selected when entering the minibuffer.
5135 Returns nil, if current window is not a minibuffer window. */)
5138 if (minibuf_level > 0
5139 && MINI_WINDOW_P (XWINDOW (selected_window))
5140 && WINDOW_LIVE_P (minibuf_selected_window))
5141 return minibuf_selected_window;
5143 return Qnil;
5146 /* Value is the number of lines actually displayed in window W,
5147 as opposed to its height. */
5149 static int
5150 displayed_window_lines (w)
5151 struct window *w;
5153 struct it it;
5154 struct text_pos start;
5155 int height = window_box_height (w);
5156 struct buffer *old_buffer;
5157 int bottom_y;
5159 if (XBUFFER (w->buffer) != current_buffer)
5161 old_buffer = current_buffer;
5162 set_buffer_internal (XBUFFER (w->buffer));
5164 else
5165 old_buffer = NULL;
5167 /* In case W->start is out of the accessible range, do something
5168 reasonable. This happens in Info mode when Info-scroll-down
5169 calls (recenter -1) while W->start is 1. */
5170 if (XMARKER (w->start)->charpos < BEGV)
5171 SET_TEXT_POS (start, BEGV, BEGV_BYTE);
5172 else if (XMARKER (w->start)->charpos > ZV)
5173 SET_TEXT_POS (start, ZV, ZV_BYTE);
5174 else
5175 SET_TEXT_POS_FROM_MARKER (start, w->start);
5177 start_display (&it, w, start);
5178 move_it_vertically (&it, height);
5179 bottom_y = line_bottom_y (&it);
5181 /* rms: On a non-window display,
5182 the value of it.vpos at the bottom of the screen
5183 seems to be 1 larger than window_box_height (w).
5184 This kludge fixes a bug whereby (move-to-window-line -1)
5185 when ZV is on the last screen line
5186 moves to the previous screen line instead of the last one. */
5187 if (! FRAME_WINDOW_P (XFRAME (w->frame)))
5188 height++;
5190 /* Add in empty lines at the bottom of the window. */
5191 if (bottom_y < height)
5193 int uy = FRAME_LINE_HEIGHT (it.f);
5194 it.vpos += (height - bottom_y + uy - 1) / uy;
5197 if (old_buffer)
5198 set_buffer_internal (old_buffer);
5200 return it.vpos;
5204 DEFUN ("recenter", Frecenter, Srecenter, 0, 1, "P",
5205 doc: /* Center point in window and redisplay frame.
5206 With prefix argument ARG, recenter putting point on screen line ARG
5207 relative to the current window. If ARG is negative, it counts up from the
5208 bottom of the window. (ARG should be less than the height of the window.)
5210 If ARG is omitted or nil, erase the entire frame and then
5211 redraw with point in the center of the current window.
5212 Just C-u as prefix means put point in the center of the window
5213 and redisplay normally--don't erase and redraw the frame. */)
5214 (arg)
5215 register Lisp_Object arg;
5217 struct window *w = XWINDOW (selected_window);
5218 struct buffer *buf = XBUFFER (w->buffer);
5219 struct buffer *obuf = current_buffer;
5220 int center_p = 0;
5221 int charpos, bytepos;
5223 /* If redisplay is suppressed due to an error, try again. */
5224 obuf->display_error_modiff = 0;
5226 if (NILP (arg))
5228 int i;
5230 /* Invalidate pixel data calculated for all compositions. */
5231 for (i = 0; i < n_compositions; i++)
5232 composition_table[i]->font = NULL;
5234 Fredraw_frame (w->frame);
5235 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w)));
5236 center_p = 1;
5238 else if (CONSP (arg)) /* Just C-u. */
5239 center_p = 1;
5240 else
5242 arg = Fprefix_numeric_value (arg);
5243 CHECK_NUMBER (arg);
5246 set_buffer_internal (buf);
5248 /* Handle centering on a graphical frame specially. Such frames can
5249 have variable-height lines and centering point on the basis of
5250 line counts would lead to strange effects. */
5251 if (FRAME_WINDOW_P (XFRAME (w->frame)))
5253 if (center_p)
5255 struct it it;
5256 struct text_pos pt;
5258 SET_TEXT_POS (pt, PT, PT_BYTE);
5259 start_display (&it, w, pt);
5260 move_it_vertically_backward (&it, window_box_height (w) / 2);
5261 charpos = IT_CHARPOS (it);
5262 bytepos = IT_BYTEPOS (it);
5264 else if (XINT (arg) < 0)
5266 struct it it;
5267 struct text_pos pt;
5268 int nlines = - XINT (arg);
5269 int extra_line_spacing;
5270 int h = window_box_height (w);
5272 SET_TEXT_POS (pt, PT, PT_BYTE);
5273 start_display (&it, w, pt);
5275 /* Be sure we have the exact height of the full line containing PT. */
5276 move_it_by_lines (&it, 0, 1);
5278 /* The amount of pixels we have to move back is the window
5279 height minus what's displayed in the line containing PT,
5280 and the lines below. */
5281 it.current_y = 0;
5282 it.vpos = 0;
5283 move_it_by_lines (&it, nlines, 1);
5285 if (it.vpos == nlines)
5286 h -= it.current_y;
5287 else
5289 /* Last line has no newline */
5290 h -= line_bottom_y (&it);
5291 it.vpos++;
5294 /* Don't reserve space for extra line spacing of last line. */
5295 extra_line_spacing = it.max_extra_line_spacing;
5297 /* If we can't move down NLINES lines because we hit
5298 the end of the buffer, count in some empty lines. */
5299 if (it.vpos < nlines)
5301 nlines -= it.vpos;
5302 extra_line_spacing = it.extra_line_spacing;
5303 h -= nlines * (FRAME_LINE_HEIGHT (it.f) + extra_line_spacing);
5305 if (h <= 0)
5306 return Qnil;
5308 /* Now find the new top line (starting position) of the window. */
5309 start_display (&it, w, pt);
5310 it.current_y = 0;
5311 move_it_vertically_backward (&it, h);
5313 /* If extra line spacing is present, we may move too far
5314 back. This causes the last line to be only partially
5315 visible (which triggers redisplay to recenter that line
5316 in the middle), so move forward.
5317 But ignore extra line spacing on last line, as it is not
5318 considered to be part of the visible height of the line.
5320 h += extra_line_spacing;
5321 while (-it.current_y > h)
5322 move_it_by_lines (&it, 1, 1);
5324 charpos = IT_CHARPOS (it);
5325 bytepos = IT_BYTEPOS (it);
5327 else
5329 struct position pos;
5330 pos = *vmotion (PT, - XINT (arg), w);
5331 charpos = pos.bufpos;
5332 bytepos = pos.bytepos;
5335 else
5337 struct position pos;
5338 int ht = window_internal_height (w);
5340 if (center_p)
5341 arg = make_number (ht / 2);
5342 else if (XINT (arg) < 0)
5343 arg = make_number (XINT (arg) + ht);
5345 pos = *vmotion (PT, - XINT (arg), w);
5346 charpos = pos.bufpos;
5347 bytepos = pos.bytepos;
5350 /* Set the new window start. */
5351 set_marker_both (w->start, w->buffer, charpos, bytepos);
5352 w->window_end_valid = Qnil;
5354 w->optional_new_start = Qt;
5356 if (bytepos == BEGV_BYTE || FETCH_BYTE (bytepos - 1) == '\n')
5357 w->start_at_line_beg = Qt;
5358 else
5359 w->start_at_line_beg = Qnil;
5361 set_buffer_internal (obuf);
5362 return Qnil;
5366 DEFUN ("window-text-height", Fwindow_text_height, Swindow_text_height,
5367 0, 1, 0,
5368 doc: /* Return the height in lines of the text display area of WINDOW.
5369 This doesn't include the mode-line (or header-line if any) or any
5370 partial-height lines in the text display area. */)
5371 (window)
5372 Lisp_Object window;
5374 struct window *w = decode_window (window);
5375 int pixel_height = window_box_height (w);
5376 int line_height = pixel_height / FRAME_LINE_HEIGHT (XFRAME (w->frame));
5377 return make_number (line_height);
5382 DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line,
5383 1, 1, "P",
5384 doc: /* Position point relative to window.
5385 With no argument, position point at center of window.
5386 An argument specifies vertical position within the window;
5387 zero means top of window, negative means relative to bottom of window. */)
5388 (arg)
5389 Lisp_Object arg;
5391 struct window *w = XWINDOW (selected_window);
5392 int lines, start;
5393 Lisp_Object window;
5395 window = selected_window;
5396 start = marker_position (w->start);
5397 if (start < BEGV || start > ZV)
5399 int height = window_internal_height (w);
5400 Fvertical_motion (make_number (- (height / 2)), window);
5401 set_marker_both (w->start, w->buffer, PT, PT_BYTE);
5402 w->start_at_line_beg = Fbolp ();
5403 w->force_start = Qt;
5405 else
5406 Fgoto_char (w->start);
5408 lines = displayed_window_lines (w);
5409 if (NILP (arg))
5410 XSETFASTINT (arg, lines / 2);
5411 else
5413 arg = Fprefix_numeric_value (arg);
5414 if (XINT (arg) < 0)
5415 XSETINT (arg, XINT (arg) + lines);
5418 /* Skip past a partially visible first line. */
5419 if (w->vscroll)
5420 XSETINT (arg, XINT (arg) + 1);
5422 return Fvertical_motion (arg, window);
5427 /***********************************************************************
5428 Window Configuration
5429 ***********************************************************************/
5431 struct save_window_data
5433 EMACS_INT size_from_Lisp_Vector_struct;
5434 struct Lisp_Vector *next_from_Lisp_Vector_struct;
5435 Lisp_Object frame_cols, frame_lines, frame_menu_bar_lines;
5436 Lisp_Object frame_tool_bar_lines;
5437 Lisp_Object selected_frame;
5438 Lisp_Object current_window;
5439 Lisp_Object current_buffer;
5440 Lisp_Object minibuf_scroll_window;
5441 Lisp_Object minibuf_selected_window;
5442 Lisp_Object root_window;
5443 Lisp_Object focus_frame;
5444 /* Record the values of window-min-width and window-min-height
5445 so that window sizes remain consistent with them. */
5446 Lisp_Object min_width, min_height;
5447 /* A vector, each of whose elements is a struct saved_window
5448 for one window. */
5449 Lisp_Object saved_windows;
5452 /* This is saved as a Lisp_Vector */
5453 struct saved_window
5455 /* these first two must agree with struct Lisp_Vector in lisp.h */
5456 EMACS_INT size_from_Lisp_Vector_struct;
5457 struct Lisp_Vector *next_from_Lisp_Vector_struct;
5459 Lisp_Object window;
5460 Lisp_Object buffer, start, pointm, mark;
5461 Lisp_Object left_col, top_line, total_cols, total_lines;
5462 Lisp_Object hscroll, min_hscroll;
5463 Lisp_Object parent, prev;
5464 Lisp_Object start_at_line_beg;
5465 Lisp_Object display_table;
5466 Lisp_Object orig_top_line, orig_total_lines;
5467 Lisp_Object left_margin_cols, right_margin_cols;
5468 Lisp_Object left_fringe_width, right_fringe_width, fringes_outside_margins;
5469 Lisp_Object scroll_bar_width, vertical_scroll_bar_type;
5472 #define SAVED_WINDOW_VECTOR_SIZE 24 /* Arg to Fmake_vector */
5474 #define SAVED_WINDOW_N(swv,n) \
5475 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5477 DEFUN ("window-configuration-p", Fwindow_configuration_p, Swindow_configuration_p, 1, 1, 0,
5478 doc: /* Return t if OBJECT is a window-configuration object. */)
5479 (object)
5480 Lisp_Object object;
5482 if (WINDOW_CONFIGURATIONP (object))
5483 return Qt;
5484 return Qnil;
5487 DEFUN ("window-configuration-frame", Fwindow_configuration_frame, Swindow_configuration_frame, 1, 1, 0,
5488 doc: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5489 (config)
5490 Lisp_Object config;
5492 register struct save_window_data *data;
5493 struct Lisp_Vector *saved_windows;
5495 if (! WINDOW_CONFIGURATIONP (config))
5496 wrong_type_argument (Qwindow_configuration_p, config);
5498 data = (struct save_window_data *) XVECTOR (config);
5499 saved_windows = XVECTOR (data->saved_windows);
5500 return XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame;
5503 DEFUN ("set-window-configuration", Fset_window_configuration,
5504 Sset_window_configuration, 1, 1, 0,
5505 doc: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5506 CONFIGURATION must be a value previously returned
5507 by `current-window-configuration' (which see).
5508 If CONFIGURATION was made from a frame that is now deleted,
5509 only frame-independent values can be restored. In this case,
5510 the return value is nil. Otherwise the value is t. */)
5511 (configuration)
5512 Lisp_Object configuration;
5514 register struct save_window_data *data;
5515 struct Lisp_Vector *saved_windows;
5516 Lisp_Object new_current_buffer;
5517 Lisp_Object frame;
5518 FRAME_PTR f;
5519 int old_point = -1;
5521 while (!WINDOW_CONFIGURATIONP (configuration))
5522 wrong_type_argument (Qwindow_configuration_p, configuration);
5524 data = (struct save_window_data *) XVECTOR (configuration);
5525 saved_windows = XVECTOR (data->saved_windows);
5527 new_current_buffer = data->current_buffer;
5528 if (NILP (XBUFFER (new_current_buffer)->name))
5529 new_current_buffer = Qnil;
5530 else
5532 if (XBUFFER (new_current_buffer) == current_buffer)
5533 old_point = PT;
5534 else
5535 old_point = BUF_PT (XBUFFER (new_current_buffer));
5538 frame = XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame;
5539 f = XFRAME (frame);
5541 /* If f is a dead frame, don't bother rebuilding its window tree.
5542 However, there is other stuff we should still try to do below. */
5543 if (FRAME_LIVE_P (f))
5545 register struct window *w;
5546 register struct saved_window *p;
5547 struct window *root_window;
5548 struct window **leaf_windows;
5549 int n_leaf_windows;
5550 int k, i, n;
5552 /* If the frame has been resized since this window configuration was
5553 made, we change the frame to the size specified in the
5554 configuration, restore the configuration, and then resize it
5555 back. We keep track of the prevailing height in these variables. */
5556 int previous_frame_lines = FRAME_LINES (f);
5557 int previous_frame_cols = FRAME_COLS (f);
5558 int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
5559 int previous_frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f);
5561 /* The mouse highlighting code could get screwed up
5562 if it runs during this. */
5563 BLOCK_INPUT;
5565 if (XFASTINT (data->frame_lines) != previous_frame_lines
5566 || XFASTINT (data->frame_cols) != previous_frame_cols)
5567 change_frame_size (f, XFASTINT (data->frame_lines),
5568 XFASTINT (data->frame_cols), 0, 0, 0);
5569 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5570 if (XFASTINT (data->frame_menu_bar_lines)
5571 != previous_frame_menu_bar_lines)
5572 x_set_menu_bar_lines (f, data->frame_menu_bar_lines, make_number (0));
5573 #ifdef HAVE_WINDOW_SYSTEM
5574 if (XFASTINT (data->frame_tool_bar_lines)
5575 != previous_frame_tool_bar_lines)
5576 x_set_tool_bar_lines (f, data->frame_tool_bar_lines, make_number (0));
5577 #endif
5578 #endif
5580 /* "Swap out" point from the selected window
5581 into its buffer. We do this now, before
5582 restoring the window contents, and prevent it from
5583 being done later on when we select a new window. */
5584 if (! NILP (XWINDOW (selected_window)->buffer))
5586 w = XWINDOW (selected_window);
5587 set_marker_both (w->pointm,
5588 w->buffer,
5589 BUF_PT (XBUFFER (w->buffer)),
5590 BUF_PT_BYTE (XBUFFER (w->buffer)));
5593 windows_or_buffers_changed++;
5594 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
5596 /* Problem: Freeing all matrices and later allocating them again
5597 is a serious redisplay flickering problem. What we would
5598 really like to do is to free only those matrices not reused
5599 below. */
5600 root_window = XWINDOW (FRAME_ROOT_WINDOW (f));
5601 leaf_windows
5602 = (struct window **) alloca (count_windows (root_window)
5603 * sizeof (struct window *));
5604 n_leaf_windows = get_leaf_windows (root_window, leaf_windows, 0);
5606 /* Temporarily avoid any problems with windows that are smaller
5607 than they are supposed to be. */
5608 window_min_height = 1;
5609 window_min_width = 1;
5611 /* Kludge Alert!
5612 Mark all windows now on frame as "deleted".
5613 Restoring the new configuration "undeletes" any that are in it.
5615 Save their current buffers in their height fields, since we may
5616 need it later, if a buffer saved in the configuration is now
5617 dead. */
5618 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f)));
5620 for (k = 0; k < saved_windows->size; k++)
5622 p = SAVED_WINDOW_N (saved_windows, k);
5623 w = XWINDOW (p->window);
5624 w->next = Qnil;
5626 if (!NILP (p->parent))
5627 w->parent = SAVED_WINDOW_N (saved_windows,
5628 XFASTINT (p->parent))->window;
5629 else
5630 w->parent = Qnil;
5632 if (!NILP (p->prev))
5634 w->prev = SAVED_WINDOW_N (saved_windows,
5635 XFASTINT (p->prev))->window;
5636 XWINDOW (w->prev)->next = p->window;
5638 else
5640 w->prev = Qnil;
5641 if (!NILP (w->parent))
5643 if (EQ (p->total_cols, XWINDOW (w->parent)->total_cols))
5645 XWINDOW (w->parent)->vchild = p->window;
5646 XWINDOW (w->parent)->hchild = Qnil;
5648 else
5650 XWINDOW (w->parent)->hchild = p->window;
5651 XWINDOW (w->parent)->vchild = Qnil;
5656 /* If we squirreled away the buffer in the window's height,
5657 restore it now. */
5658 if (BUFFERP (w->total_lines))
5659 w->buffer = w->total_lines;
5660 w->left_col = p->left_col;
5661 w->top_line = p->top_line;
5662 w->total_cols = p->total_cols;
5663 w->total_lines = p->total_lines;
5664 w->hscroll = p->hscroll;
5665 w->min_hscroll = p->min_hscroll;
5666 w->display_table = p->display_table;
5667 w->orig_top_line = p->orig_top_line;
5668 w->orig_total_lines = p->orig_total_lines;
5669 w->left_margin_cols = p->left_margin_cols;
5670 w->right_margin_cols = p->right_margin_cols;
5671 w->left_fringe_width = p->left_fringe_width;
5672 w->right_fringe_width = p->right_fringe_width;
5673 w->fringes_outside_margins = p->fringes_outside_margins;
5674 w->scroll_bar_width = p->scroll_bar_width;
5675 w->vertical_scroll_bar_type = p->vertical_scroll_bar_type;
5676 XSETFASTINT (w->last_modified, 0);
5677 XSETFASTINT (w->last_overlay_modified, 0);
5679 /* Reinstall the saved buffer and pointers into it. */
5680 if (NILP (p->buffer))
5681 w->buffer = p->buffer;
5682 else
5684 if (!NILP (XBUFFER (p->buffer)->name))
5685 /* If saved buffer is alive, install it. */
5687 w->buffer = p->buffer;
5688 w->start_at_line_beg = p->start_at_line_beg;
5689 set_marker_restricted (w->start, p->start, w->buffer);
5690 set_marker_restricted (w->pointm, p->pointm, w->buffer);
5691 Fset_marker (XBUFFER (w->buffer)->mark,
5692 p->mark, w->buffer);
5694 /* As documented in Fcurrent_window_configuration, don't
5695 restore the location of point in the buffer which was
5696 current when the window configuration was recorded. */
5697 if (!EQ (p->buffer, new_current_buffer)
5698 && XBUFFER (p->buffer) == current_buffer)
5699 Fgoto_char (w->pointm);
5701 else if (NILP (w->buffer) || NILP (XBUFFER (w->buffer)->name))
5702 /* Else unless window has a live buffer, get one. */
5704 w->buffer = Fcdr (Fcar (Vbuffer_alist));
5705 /* This will set the markers to beginning of visible
5706 range. */
5707 set_marker_restricted (w->start, make_number (0), w->buffer);
5708 set_marker_restricted (w->pointm, make_number (0),w->buffer);
5709 w->start_at_line_beg = Qt;
5711 else
5712 /* Keeping window's old buffer; make sure the markers
5713 are real. */
5715 /* Set window markers at start of visible range. */
5716 if (XMARKER (w->start)->buffer == 0)
5717 set_marker_restricted (w->start, make_number (0),
5718 w->buffer);
5719 if (XMARKER (w->pointm)->buffer == 0)
5720 set_marker_restricted_both (w->pointm, w->buffer,
5721 BUF_PT (XBUFFER (w->buffer)),
5722 BUF_PT_BYTE (XBUFFER (w->buffer)));
5723 w->start_at_line_beg = Qt;
5728 FRAME_ROOT_WINDOW (f) = data->root_window;
5729 /* Prevent "swapping out point" in the old selected window
5730 using the buffer that has been restored into it.
5731 Use the point value from the beginning of this function
5732 since unshow_buffer (called from delete_all_subwindows)
5733 could have altered it. */
5734 selected_window = Qnil;
5735 if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer))
5736 set_marker_restricted (XWINDOW (data->current_window)->pointm,
5737 make_number (old_point),
5738 XWINDOW (data->current_window)->buffer);
5740 Fselect_window (data->current_window, Qnil);
5741 XBUFFER (XWINDOW (selected_window)->buffer)->last_selected_window
5742 = selected_window;
5744 if (NILP (data->focus_frame)
5745 || (FRAMEP (data->focus_frame)
5746 && FRAME_LIVE_P (XFRAME (data->focus_frame))))
5747 Fredirect_frame_focus (frame, data->focus_frame);
5749 #if 0 /* I don't understand why this is needed, and it causes problems
5750 when the frame's old selected window has been deleted. */
5751 if (f != selected_frame && FRAME_WINDOW_P (f))
5752 do_switch_frame (WINDOW_FRAME (XWINDOW (data->root_window)),
5753 0, 0);
5754 #endif
5756 /* Set the screen height to the value it had before this function. */
5757 if (previous_frame_lines != FRAME_LINES (f)
5758 || previous_frame_cols != FRAME_COLS (f))
5759 change_frame_size (f, previous_frame_lines, previous_frame_cols,
5760 0, 0, 0);
5761 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5762 if (previous_frame_menu_bar_lines != FRAME_MENU_BAR_LINES (f))
5763 x_set_menu_bar_lines (f, make_number (previous_frame_menu_bar_lines),
5764 make_number (0));
5765 #ifdef HAVE_WINDOW_SYSTEM
5766 if (previous_frame_tool_bar_lines != FRAME_TOOL_BAR_LINES (f))
5767 x_set_tool_bar_lines (f, make_number (previous_frame_tool_bar_lines),
5768 make_number (0));
5769 #endif
5770 #endif
5772 /* Now, free glyph matrices in windows that were not reused. */
5773 for (i = n = 0; i < n_leaf_windows; ++i)
5775 if (NILP (leaf_windows[i]->buffer))
5777 /* Assert it's not reused as a combination. */
5778 xassert (NILP (leaf_windows[i]->hchild)
5779 && NILP (leaf_windows[i]->vchild));
5780 free_window_matrices (leaf_windows[i]);
5782 else if (EQ (leaf_windows[i]->buffer, new_current_buffer))
5783 ++n;
5786 adjust_glyphs (f);
5788 UNBLOCK_INPUT;
5790 /* Fselect_window will have made f the selected frame, so we
5791 reselect the proper frame here. Fhandle_switch_frame will change the
5792 selected window too, but that doesn't make the call to
5793 Fselect_window above totally superfluous; it still sets f's
5794 selected window. */
5795 if (FRAME_LIVE_P (XFRAME (data->selected_frame)))
5796 do_switch_frame (data->selected_frame, 0, 0);
5798 if (! NILP (Vwindow_configuration_change_hook)
5799 && ! NILP (Vrun_hooks))
5800 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
5803 if (!NILP (new_current_buffer))
5804 Fset_buffer (new_current_buffer);
5806 /* Restore the minimum heights recorded in the configuration. */
5807 window_min_height = XINT (data->min_height);
5808 window_min_width = XINT (data->min_width);
5810 Vminibuf_scroll_window = data->minibuf_scroll_window;
5811 minibuf_selected_window = data->minibuf_selected_window;
5813 return (FRAME_LIVE_P (f) ? Qt : Qnil);
5816 /* Mark all windows now on frame as deleted
5817 by setting their buffers to nil. */
5819 void
5820 delete_all_subwindows (w)
5821 register struct window *w;
5823 if (!NILP (w->next))
5824 delete_all_subwindows (XWINDOW (w->next));
5825 if (!NILP (w->vchild))
5826 delete_all_subwindows (XWINDOW (w->vchild));
5827 if (!NILP (w->hchild))
5828 delete_all_subwindows (XWINDOW (w->hchild));
5830 w->total_lines = w->buffer; /* See Fset_window_configuration for excuse. */
5832 if (!NILP (w->buffer))
5833 unshow_buffer (w);
5835 /* We set all three of these fields to nil, to make sure that we can
5836 distinguish this dead window from any live window. Live leaf
5837 windows will have buffer set, and combination windows will have
5838 vchild or hchild set. */
5839 w->buffer = Qnil;
5840 w->vchild = Qnil;
5841 w->hchild = Qnil;
5843 Vwindow_list = Qnil;
5846 static int
5847 count_windows (window)
5848 register struct window *window;
5850 register int count = 1;
5851 if (!NILP (window->next))
5852 count += count_windows (XWINDOW (window->next));
5853 if (!NILP (window->vchild))
5854 count += count_windows (XWINDOW (window->vchild));
5855 if (!NILP (window->hchild))
5856 count += count_windows (XWINDOW (window->hchild));
5857 return count;
5861 /* Fill vector FLAT with leaf windows under W, starting at index I.
5862 Value is last index + 1. */
5864 static int
5865 get_leaf_windows (w, flat, i)
5866 struct window *w;
5867 struct window **flat;
5868 int i;
5870 while (w)
5872 if (!NILP (w->hchild))
5873 i = get_leaf_windows (XWINDOW (w->hchild), flat, i);
5874 else if (!NILP (w->vchild))
5875 i = get_leaf_windows (XWINDOW (w->vchild), flat, i);
5876 else
5877 flat[i++] = w;
5879 w = NILP (w->next) ? 0 : XWINDOW (w->next);
5882 return i;
5886 /* Return a pointer to the glyph W's physical cursor is on. Value is
5887 null if W's current matrix is invalid, so that no meaningfull glyph
5888 can be returned. */
5890 struct glyph *
5891 get_phys_cursor_glyph (w)
5892 struct window *w;
5894 struct glyph_row *row;
5895 struct glyph *glyph;
5897 if (w->phys_cursor.vpos >= 0
5898 && w->phys_cursor.vpos < w->current_matrix->nrows
5899 && (row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos),
5900 row->enabled_p)
5901 && row->used[TEXT_AREA] > w->phys_cursor.hpos)
5902 glyph = row->glyphs[TEXT_AREA] + w->phys_cursor.hpos;
5903 else
5904 glyph = NULL;
5906 return glyph;
5910 static int
5911 save_window_save (window, vector, i)
5912 Lisp_Object window;
5913 struct Lisp_Vector *vector;
5914 int i;
5916 register struct saved_window *p;
5917 register struct window *w;
5918 register Lisp_Object tem;
5920 for (;!NILP (window); window = w->next)
5922 p = SAVED_WINDOW_N (vector, i);
5923 w = XWINDOW (window);
5925 XSETFASTINT (w->temslot, i); i++;
5926 p->window = window;
5927 p->buffer = w->buffer;
5928 p->left_col = w->left_col;
5929 p->top_line = w->top_line;
5930 p->total_cols = w->total_cols;
5931 p->total_lines = w->total_lines;
5932 p->hscroll = w->hscroll;
5933 p->min_hscroll = w->min_hscroll;
5934 p->display_table = w->display_table;
5935 p->orig_top_line = w->orig_top_line;
5936 p->orig_total_lines = w->orig_total_lines;
5937 p->left_margin_cols = w->left_margin_cols;
5938 p->right_margin_cols = w->right_margin_cols;
5939 p->left_fringe_width = w->left_fringe_width;
5940 p->right_fringe_width = w->right_fringe_width;
5941 p->fringes_outside_margins = w->fringes_outside_margins;
5942 p->scroll_bar_width = w->scroll_bar_width;
5943 p->vertical_scroll_bar_type = w->vertical_scroll_bar_type;
5944 if (!NILP (w->buffer))
5946 /* Save w's value of point in the window configuration.
5947 If w is the selected window, then get the value of point
5948 from the buffer; pointm is garbage in the selected window. */
5949 if (EQ (window, selected_window))
5951 p->pointm = Fmake_marker ();
5952 set_marker_both (p->pointm, w->buffer,
5953 BUF_PT (XBUFFER (w->buffer)),
5954 BUF_PT_BYTE (XBUFFER (w->buffer)));
5956 else
5957 p->pointm = Fcopy_marker (w->pointm, Qnil);
5959 p->start = Fcopy_marker (w->start, Qnil);
5960 p->start_at_line_beg = w->start_at_line_beg;
5962 tem = XBUFFER (w->buffer)->mark;
5963 p->mark = Fcopy_marker (tem, Qnil);
5965 else
5967 p->pointm = Qnil;
5968 p->start = Qnil;
5969 p->mark = Qnil;
5970 p->start_at_line_beg = Qnil;
5973 if (NILP (w->parent))
5974 p->parent = Qnil;
5975 else
5976 p->parent = XWINDOW (w->parent)->temslot;
5978 if (NILP (w->prev))
5979 p->prev = Qnil;
5980 else
5981 p->prev = XWINDOW (w->prev)->temslot;
5983 if (!NILP (w->vchild))
5984 i = save_window_save (w->vchild, vector, i);
5985 if (!NILP (w->hchild))
5986 i = save_window_save (w->hchild, vector, i);
5989 return i;
5992 DEFUN ("current-window-configuration", Fcurrent_window_configuration,
5993 Scurrent_window_configuration, 0, 1, 0,
5994 doc: /* Return an object representing the current window configuration of FRAME.
5995 If FRAME is nil or omitted, use the selected frame.
5996 This describes the number of windows, their sizes and current buffers,
5997 and for each displayed buffer, where display starts, and the positions of
5998 point and mark. An exception is made for point in the current buffer:
5999 its value is -not- saved.
6000 This also records the currently selected frame, and FRAME's focus
6001 redirection (see `redirect-frame-focus'). */)
6002 (frame)
6003 Lisp_Object frame;
6005 register Lisp_Object tem;
6006 register int n_windows;
6007 register struct save_window_data *data;
6008 register struct Lisp_Vector *vec;
6009 register int i;
6010 FRAME_PTR f;
6012 if (NILP (frame))
6013 frame = selected_frame;
6014 CHECK_LIVE_FRAME (frame);
6015 f = XFRAME (frame);
6017 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
6018 vec = allocate_other_vector (VECSIZE (struct save_window_data));
6019 data = (struct save_window_data *)vec;
6021 XSETFASTINT (data->frame_cols, FRAME_COLS (f));
6022 XSETFASTINT (data->frame_lines, FRAME_LINES (f));
6023 XSETFASTINT (data->frame_menu_bar_lines, FRAME_MENU_BAR_LINES (f));
6024 XSETFASTINT (data->frame_tool_bar_lines, FRAME_TOOL_BAR_LINES (f));
6025 data->selected_frame = selected_frame;
6026 data->current_window = FRAME_SELECTED_WINDOW (f);
6027 XSETBUFFER (data->current_buffer, current_buffer);
6028 data->minibuf_scroll_window = minibuf_level > 0 ? Vminibuf_scroll_window : Qnil;
6029 data->minibuf_selected_window = minibuf_level > 0 ? minibuf_selected_window : Qnil;
6030 data->root_window = FRAME_ROOT_WINDOW (f);
6031 data->focus_frame = FRAME_FOCUS_FRAME (f);
6032 XSETINT (data->min_height, window_min_height);
6033 XSETINT (data->min_width, window_min_width);
6034 tem = Fmake_vector (make_number (n_windows), Qnil);
6035 data->saved_windows = tem;
6036 for (i = 0; i < n_windows; i++)
6037 XVECTOR (tem)->contents[i]
6038 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE), Qnil);
6039 save_window_save (FRAME_ROOT_WINDOW (f), XVECTOR (tem), 0);
6040 XSETWINDOW_CONFIGURATION (tem, data);
6041 return (tem);
6044 DEFUN ("save-window-excursion", Fsave_window_excursion, Ssave_window_excursion,
6045 0, UNEVALLED, 0,
6046 doc: /* Execute BODY, preserving window sizes and contents.
6047 Return the value of the last form in BODY.
6048 Restore which buffer appears in which window, where display starts,
6049 and the value of point and mark for each window.
6050 Also restore the choice of selected window.
6051 Also restore which buffer is current.
6052 Does not restore the value of point in current buffer.
6053 usage: (save-window-excursion BODY ...) */)
6054 (args)
6055 Lisp_Object args;
6057 register Lisp_Object val;
6058 register int count = SPECPDL_INDEX ();
6060 record_unwind_protect (Fset_window_configuration,
6061 Fcurrent_window_configuration (Qnil));
6062 val = Fprogn (args);
6063 return unbind_to (count, val);
6067 /***********************************************************************
6068 Marginal Areas
6069 ***********************************************************************/
6071 DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins,
6072 2, 3, 0,
6073 doc: /* Set width of marginal areas of window WINDOW.
6074 If WINDOW is nil, set margins of the currently selected window.
6075 Second arg LEFT-WIDTH specifies the number of character cells to
6076 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6077 does the same for the right marginal area. A nil width parameter
6078 means no margin. */)
6079 (window, left, right)
6080 Lisp_Object window, left, right;
6082 struct window *w = decode_window (window);
6084 /* Translate negative or zero widths to nil.
6085 Margins that are too wide have to be checked elsewhere. */
6087 if (!NILP (left))
6089 CHECK_NUMBER (left);
6090 if (XINT (left) <= 0)
6091 left = Qnil;
6094 if (!NILP (right))
6096 CHECK_NUMBER (right);
6097 if (XINT (right) <= 0)
6098 right = Qnil;
6101 if (!EQ (w->left_margin_cols, left)
6102 || !EQ (w->right_margin_cols, right))
6104 w->left_margin_cols = left;
6105 w->right_margin_cols = right;
6107 adjust_window_margins (w);
6109 ++windows_or_buffers_changed;
6110 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6113 return Qnil;
6117 DEFUN ("window-margins", Fwindow_margins, Swindow_margins,
6118 0, 1, 0,
6119 doc: /* Get width of marginal areas of window WINDOW.
6120 If WINDOW is omitted or nil, use the currently selected window.
6121 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6122 If a marginal area does not exist, its width will be returned
6123 as nil. */)
6124 (window)
6125 Lisp_Object window;
6127 struct window *w = decode_window (window);
6128 return Fcons (w->left_margin_cols, w->right_margin_cols);
6133 /***********************************************************************
6134 Fringes
6135 ***********************************************************************/
6137 DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes,
6138 2, 4, 0,
6139 doc: /* Set the fringe widths of window WINDOW.
6140 If WINDOW is nil, set the fringe widths of the currently selected
6141 window.
6142 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6143 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6144 fringe width. If a fringe width arg is nil, that means to use the
6145 frame's default fringe width. Default fringe widths can be set with
6146 the command `set-fringe-style'.
6147 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6148 outside of the display margins. By default, fringes are drawn between
6149 display marginal areas and the text area. */)
6150 (window, left, right, outside_margins)
6151 Lisp_Object window, left, right, outside_margins;
6153 struct window *w = decode_window (window);
6155 if (!NILP (left))
6156 CHECK_NATNUM (left);
6157 if (!NILP (right))
6158 CHECK_NATNUM (right);
6160 if (!EQ (w->left_fringe_width, left)
6161 || !EQ (w->right_fringe_width, right)
6162 || !EQ (w->fringes_outside_margins, outside_margins))
6164 w->left_fringe_width = left;
6165 w->right_fringe_width = right;
6166 w->fringes_outside_margins = outside_margins;
6168 adjust_window_margins (w);
6170 clear_glyph_matrix (w->current_matrix);
6171 w->window_end_valid = Qnil;
6173 ++windows_or_buffers_changed;
6174 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6177 return Qnil;
6181 DEFUN ("window-fringes", Fwindow_fringes, Swindow_fringes,
6182 0, 1, 0,
6183 doc: /* Get width of fringes of window WINDOW.
6184 If WINDOW is omitted or nil, use the currently selected window.
6185 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6186 (window)
6187 Lisp_Object window;
6189 struct window *w = decode_window (window);
6190 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w)),
6191 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w)),
6192 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) ?
6193 Qt : Qnil), Qnil)));
6198 /***********************************************************************
6199 Scroll bars
6200 ***********************************************************************/
6202 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars, Sset_window_scroll_bars,
6203 2, 4, 0,
6204 doc: /* Set width and type of scroll bars of window WINDOW.
6205 If window is nil, set scroll bars of the currently selected window.
6206 Second parameter WIDTH specifies the pixel width for the scroll bar;
6207 this is automatically adjusted to a multiple of the frame column width.
6208 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6209 bar: left, right, or nil.
6210 If WIDTH is nil, use the frame's scroll-bar width.
6211 If TYPE is t, use the frame's scroll-bar type. */)
6212 (window, width, vertical_type, horizontal_type)
6213 Lisp_Object window, width, vertical_type, horizontal_type;
6215 struct window *w = decode_window (window);
6217 if (!NILP (width))
6219 CHECK_NATNUM (width);
6221 if (XINT (width) == 0)
6222 vertical_type = Qnil;
6225 if (!(EQ (vertical_type, Qnil)
6226 || EQ (vertical_type, Qleft)
6227 || EQ (vertical_type, Qright)
6228 || EQ (vertical_type, Qt)))
6229 error ("Invalid type of vertical scroll bar");
6231 if (!EQ (w->scroll_bar_width, width)
6232 || !EQ (w->vertical_scroll_bar_type, vertical_type))
6234 w->scroll_bar_width = width;
6235 w->vertical_scroll_bar_type = vertical_type;
6237 adjust_window_margins (w);
6239 clear_glyph_matrix (w->current_matrix);
6240 w->window_end_valid = Qnil;
6242 ++windows_or_buffers_changed;
6243 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6246 return Qnil;
6250 DEFUN ("window-scroll-bars", Fwindow_scroll_bars, Swindow_scroll_bars,
6251 0, 1, 0,
6252 doc: /* Get width and type of scroll bars of window WINDOW.
6253 If WINDOW is omitted or nil, use the currently selected window.
6254 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6255 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6256 value. */)
6257 (window)
6258 Lisp_Object window;
6260 struct window *w = decode_window (window);
6261 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
6262 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
6263 : WINDOW_SCROLL_BAR_AREA_WIDTH (w))),
6264 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w)),
6265 Fcons (w->vertical_scroll_bar_type,
6266 Fcons (Qnil, Qnil))));
6271 /***********************************************************************
6272 Smooth scrolling
6273 ***********************************************************************/
6275 DEFUN ("window-vscroll", Fwindow_vscroll, Swindow_vscroll, 0, 2, 0,
6276 doc: /* Return the amount by which WINDOW is scrolled vertically.
6277 Use the selected window if WINDOW is nil or omitted.
6278 Normally, value is a multiple of the canonical character height of WINDOW;
6279 optional second arg PIXELS_P means value is measured in pixels. */)
6280 (window, pixels_p)
6281 Lisp_Object window, pixels_p;
6283 Lisp_Object result;
6284 struct frame *f;
6285 struct window *w;
6287 if (NILP (window))
6288 window = selected_window;
6289 else
6290 CHECK_WINDOW (window);
6291 w = XWINDOW (window);
6292 f = XFRAME (w->frame);
6294 if (FRAME_WINDOW_P (f))
6295 result = (NILP (pixels_p)
6296 ? FRAME_CANON_Y_FROM_PIXEL_Y (f, -w->vscroll)
6297 : make_number (-w->vscroll));
6298 else
6299 result = make_number (0);
6300 return result;
6304 DEFUN ("set-window-vscroll", Fset_window_vscroll, Sset_window_vscroll,
6305 2, 3, 0,
6306 doc: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6307 WINDOW nil means use the selected window. Normally, VSCROLL is a
6308 non-negative multiple of the canonical character height of WINDOW;
6309 optional third arg PIXELS_P non-nil means that VSCROLL is in pixels.
6310 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6311 corresponds to an integral number of pixels. The return value is the
6312 result of this rounding.
6313 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6314 (window, vscroll, pixels_p)
6315 Lisp_Object window, vscroll, pixels_p;
6317 struct window *w;
6318 struct frame *f;
6320 if (NILP (window))
6321 window = selected_window;
6322 else
6323 CHECK_WINDOW (window);
6324 CHECK_NUMBER_OR_FLOAT (vscroll);
6326 w = XWINDOW (window);
6327 f = XFRAME (w->frame);
6329 if (FRAME_WINDOW_P (f))
6331 int old_dy = w->vscroll;
6333 w->vscroll = - (NILP (pixels_p)
6334 ? FRAME_LINE_HEIGHT (f) * XFLOATINT (vscroll)
6335 : XFLOATINT (vscroll));
6336 w->vscroll = min (w->vscroll, 0);
6338 /* Adjust glyph matrix of the frame if the virtual display
6339 area becomes larger than before. */
6340 if (w->vscroll < 0 && w->vscroll < old_dy)
6341 adjust_glyphs (f);
6343 /* Prevent redisplay shortcuts. */
6344 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
6347 return Fwindow_vscroll (window, pixels_p);
6351 /* Call FN for all leaf windows on frame F. FN is called with the
6352 first argument being a pointer to the leaf window, and with
6353 additional argument USER_DATA. Stops when FN returns 0. */
6355 void
6356 foreach_window (f, fn, user_data)
6357 struct frame *f;
6358 int (* fn) P_ ((struct window *, void *));
6359 void *user_data;
6361 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f)), fn, user_data);
6365 /* Helper function for foreach_window. Call FN for all leaf windows
6366 reachable from W. FN is called with the first argument being a
6367 pointer to the leaf window, and with additional argument USER_DATA.
6368 Stop when FN returns 0. Value is 0 if stopped by FN. */
6370 static int
6371 foreach_window_1 (w, fn, user_data)
6372 struct window *w;
6373 int (* fn) P_ ((struct window *, void *));
6374 void *user_data;
6376 int cont;
6378 for (cont = 1; w && cont;)
6380 if (!NILP (w->hchild))
6381 cont = foreach_window_1 (XWINDOW (w->hchild), fn, user_data);
6382 else if (!NILP (w->vchild))
6383 cont = foreach_window_1 (XWINDOW (w->vchild), fn, user_data);
6384 else
6385 cont = fn (w, user_data);
6387 w = NILP (w->next) ? 0 : XWINDOW (w->next);
6390 return cont;
6394 /* Freeze or unfreeze the window start of W unless it is a
6395 mini-window or the selected window. FREEZE_P non-null means freeze
6396 the window start. */
6398 static int
6399 freeze_window_start (w, freeze_p)
6400 struct window *w;
6401 void *freeze_p;
6403 if (w == XWINDOW (selected_window)
6404 || MINI_WINDOW_P (w)
6405 || (MINI_WINDOW_P (XWINDOW (selected_window))
6406 && ! NILP (Vminibuf_scroll_window)
6407 && w == XWINDOW (Vminibuf_scroll_window)))
6408 freeze_p = NULL;
6410 w->frozen_window_start_p = freeze_p != NULL;
6411 return 1;
6415 /* Freeze or unfreeze the window starts of all leaf windows on frame
6416 F, except the selected window and a mini-window. FREEZE_P non-zero
6417 means freeze the window start. */
6419 void
6420 freeze_window_starts (f, freeze_p)
6421 struct frame *f;
6422 int freeze_p;
6424 foreach_window (f, freeze_window_start, (void *) (freeze_p ? f : 0));
6428 /***********************************************************************
6429 Initialization
6430 ***********************************************************************/
6432 /* Return 1 if window configurations C1 and C2
6433 describe the same state of affairs. This is used by Fequal. */
6436 compare_window_configurations (c1, c2, ignore_positions)
6437 Lisp_Object c1, c2;
6438 int ignore_positions;
6440 register struct save_window_data *d1, *d2;
6441 struct Lisp_Vector *sw1, *sw2;
6442 int i;
6444 if (!WINDOW_CONFIGURATIONP (c1))
6445 wrong_type_argument (Qwindow_configuration_p, c1);
6446 if (!WINDOW_CONFIGURATIONP (c2))
6447 wrong_type_argument (Qwindow_configuration_p, c2);
6449 d1 = (struct save_window_data *) XVECTOR (c1);
6450 d2 = (struct save_window_data *) XVECTOR (c2);
6451 sw1 = XVECTOR (d1->saved_windows);
6452 sw2 = XVECTOR (d2->saved_windows);
6454 if (! EQ (d1->frame_cols, d2->frame_cols))
6455 return 0;
6456 if (! EQ (d1->frame_lines, d2->frame_lines))
6457 return 0;
6458 if (! EQ (d1->frame_menu_bar_lines, d2->frame_menu_bar_lines))
6459 return 0;
6460 if (! EQ (d1->selected_frame, d2->selected_frame))
6461 return 0;
6462 /* Don't compare the current_window field directly.
6463 Instead see w1_is_current and w2_is_current, below. */
6464 if (! EQ (d1->current_buffer, d2->current_buffer))
6465 return 0;
6466 if (! ignore_positions)
6468 if (! EQ (d1->minibuf_scroll_window, d2->minibuf_scroll_window))
6469 return 0;
6470 if (! EQ (d1->minibuf_selected_window, d2->minibuf_selected_window))
6471 return 0;
6473 /* Don't compare the root_window field.
6474 We don't require the two configurations
6475 to use the same window object,
6476 and the two root windows must be equivalent
6477 if everything else compares equal. */
6478 if (! EQ (d1->focus_frame, d2->focus_frame))
6479 return 0;
6480 if (! EQ (d1->min_width, d2->min_width))
6481 return 0;
6482 if (! EQ (d1->min_height, d2->min_height))
6483 return 0;
6485 /* Verify that the two confis have the same number of windows. */
6486 if (sw1->size != sw2->size)
6487 return 0;
6489 for (i = 0; i < sw1->size; i++)
6491 struct saved_window *p1, *p2;
6492 int w1_is_current, w2_is_current;
6494 p1 = SAVED_WINDOW_N (sw1, i);
6495 p2 = SAVED_WINDOW_N (sw2, i);
6497 /* Verify that the current windows in the two
6498 configurations correspond to each other. */
6499 w1_is_current = EQ (d1->current_window, p1->window);
6500 w2_is_current = EQ (d2->current_window, p2->window);
6502 if (w1_is_current != w2_is_current)
6503 return 0;
6505 /* Verify that the corresponding windows do match. */
6506 if (! EQ (p1->buffer, p2->buffer))
6507 return 0;
6508 if (! EQ (p1->left_col, p2->left_col))
6509 return 0;
6510 if (! EQ (p1->top_line, p2->top_line))
6511 return 0;
6512 if (! EQ (p1->total_cols, p2->total_cols))
6513 return 0;
6514 if (! EQ (p1->total_lines, p2->total_lines))
6515 return 0;
6516 if (! EQ (p1->display_table, p2->display_table))
6517 return 0;
6518 if (! EQ (p1->parent, p2->parent))
6519 return 0;
6520 if (! EQ (p1->prev, p2->prev))
6521 return 0;
6522 if (! ignore_positions)
6524 if (! EQ (p1->hscroll, p2->hscroll))
6525 return 0;
6526 if (!EQ (p1->min_hscroll, p2->min_hscroll))
6527 return 0;
6528 if (! EQ (p1->start_at_line_beg, p2->start_at_line_beg))
6529 return 0;
6530 if (NILP (Fequal (p1->start, p2->start)))
6531 return 0;
6532 if (NILP (Fequal (p1->pointm, p2->pointm)))
6533 return 0;
6534 if (NILP (Fequal (p1->mark, p2->mark)))
6535 return 0;
6537 if (! EQ (p1->left_margin_cols, p2->left_margin_cols))
6538 return 0;
6539 if (! EQ (p1->right_margin_cols, p2->right_margin_cols))
6540 return 0;
6541 if (! EQ (p1->left_fringe_width, p2->left_fringe_width))
6542 return 0;
6543 if (! EQ (p1->right_fringe_width, p2->right_fringe_width))
6544 return 0;
6545 if (! EQ (p1->fringes_outside_margins, p2->fringes_outside_margins))
6546 return 0;
6547 if (! EQ (p1->scroll_bar_width, p2->scroll_bar_width))
6548 return 0;
6549 if (! EQ (p1->vertical_scroll_bar_type, p2->vertical_scroll_bar_type))
6550 return 0;
6553 return 1;
6556 DEFUN ("compare-window-configurations", Fcompare_window_configurations,
6557 Scompare_window_configurations, 2, 2, 0,
6558 doc: /* Compare two window configurations as regards the structure of windows.
6559 This function ignores details such as the values of point and mark
6560 and scrolling positions. */)
6561 (x, y)
6562 Lisp_Object x, y;
6564 if (compare_window_configurations (x, y, 1))
6565 return Qt;
6566 return Qnil;
6569 void
6570 init_window_once ()
6572 struct frame *f = make_terminal_frame ();
6573 XSETFRAME (selected_frame, f);
6574 Vterminal_frame = selected_frame;
6575 minibuf_window = f->minibuffer_window;
6576 selected_window = f->selected_window;
6577 last_nonminibuf_frame = f;
6579 window_initialized = 1;
6582 void
6583 init_window ()
6585 Vwindow_list = Qnil;
6588 void
6589 syms_of_window ()
6591 Qwindow_size_fixed = intern ("window-size-fixed");
6592 staticpro (&Qwindow_size_fixed);
6594 staticpro (&Qwindow_configuration_change_hook);
6595 Qwindow_configuration_change_hook
6596 = intern ("window-configuration-change-hook");
6598 Qwindowp = intern ("windowp");
6599 staticpro (&Qwindowp);
6601 Qwindow_configuration_p = intern ("window-configuration-p");
6602 staticpro (&Qwindow_configuration_p);
6604 Qwindow_live_p = intern ("window-live-p");
6605 staticpro (&Qwindow_live_p);
6607 Qtemp_buffer_show_hook = intern ("temp-buffer-show-hook");
6608 staticpro (&Qtemp_buffer_show_hook);
6610 staticpro (&Vwindow_list);
6612 minibuf_selected_window = Qnil;
6613 staticpro (&minibuf_selected_window);
6615 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function,
6616 doc: /* Non-nil means call as function to display a help buffer.
6617 The function is called with one argument, the buffer to be displayed.
6618 Used by `with-output-to-temp-buffer'.
6619 If this function is used, then it must do the entire job of showing
6620 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6621 Vtemp_buffer_show_function = Qnil;
6623 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function,
6624 doc: /* If non-nil, function to call to handle `display-buffer'.
6625 It will receive two args, the buffer and a flag which if non-nil means
6626 that the currently selected window is not acceptable.
6627 It should choose or create a window, display the specified buffer in it,
6628 and return the window.
6629 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'
6630 work using this function. */);
6631 Vdisplay_buffer_function = Qnil;
6633 DEFVAR_LISP ("even-window-heights", &Veven_window_heights,
6634 doc: /* *If non-nil, `display-buffer' should even the window heights.
6635 If nil, `display-buffer' will leave the window configuration alone. */);
6636 Veven_window_heights = Qt;
6638 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window,
6639 doc: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6640 Vminibuf_scroll_window = Qnil;
6642 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows,
6643 doc: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6644 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6645 is displayed in the `mode-line' face. */);
6646 mode_line_in_non_selected_windows = 1;
6648 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer,
6649 doc: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6650 Vother_window_scroll_buffer = Qnil;
6652 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames,
6653 doc: /* *Non-nil means `display-buffer' should make a separate frame. */);
6654 pop_up_frames = 0;
6656 DEFVAR_BOOL ("display-buffer-reuse-frames", &display_buffer_reuse_frames,
6657 doc: /* *Non-nil means `display-buffer' should reuse frames.
6658 If the buffer in question is already displayed in a frame, raise that frame. */);
6659 display_buffer_reuse_frames = 0;
6661 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function,
6662 doc: /* Function to call to handle automatic new frame creation.
6663 It is called with no arguments and should return a newly created frame.
6665 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'
6666 where `pop-up-frame-alist' would hold the default frame parameters. */);
6667 Vpop_up_frame_function = Qnil;
6669 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names,
6670 doc: /* *List of buffer names that should have their own special frames.
6671 Displaying a buffer whose name is in this list makes a special frame for it
6672 using `special-display-function'. See also `special-display-regexps'.
6674 An element of the list can be a list instead of just a string.
6675 There are two ways to use a list as an element:
6676 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)
6677 In the first case, the FRAME-PARAMETERS are pairs of the form
6678 \(PARAMETER . VALUE); these parameter values are used to create the frame.
6679 In the second case, FUNCTION is called with BUFFER as the first argument,
6680 followed by the OTHER-ARGS--it can display BUFFER in any way it likes.
6681 All this is done by the function found in `special-display-function'.
6683 If the specified frame parameters include (same-buffer . t), the
6684 buffer is displayed in the currently selected window. Otherwise, if
6685 they include (same-frame . t), the buffer is displayed in a new window
6686 in the currently selected frame.
6688 If this variable appears \"not to work\", because you add a name to it
6689 but that buffer still appears in the selected window, look at the
6690 values of `same-window-buffer-names' and `same-window-regexps'.
6691 Those variables take precedence over this one. */);
6692 Vspecial_display_buffer_names = Qnil;
6694 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps,
6695 doc: /* *List of regexps saying which buffers should have their own special frames.
6696 If a buffer name matches one of these regexps, it gets its own frame.
6697 Displaying a buffer whose name is in this list makes a special frame for it
6698 using `special-display-function'.
6700 An element of the list can be a list instead of just a string.
6701 There are two ways to use a list as an element:
6702 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)
6703 In the first case, the FRAME-PARAMETERS are pairs of the form
6704 \(PARAMETER . VALUE); these parameter values are used to create the frame.
6705 In the second case, FUNCTION is called with BUFFER as the first argument,
6706 followed by the OTHER-ARGS--it can display the buffer in any way it likes.
6707 All this is done by the function found in `special-display-function'.
6709 If the specified frame parameters include (same-buffer . t), the
6710 buffer is displayed in the currently selected window. Otherwise, if
6711 they include (same-frame . t), the buffer is displayed in a new window
6712 in the currently selected frame.
6714 If this variable appears \"not to work\", because you add a regexp to it
6715 but the matching buffers still appear in the selected window, look at the
6716 values of `same-window-buffer-names' and `same-window-regexps'.
6717 Those variables take precedence over this one. */);
6718 Vspecial_display_regexps = Qnil;
6720 DEFVAR_LISP ("special-display-function", &Vspecial_display_function,
6721 doc: /* Function to call to make a new frame for a special buffer.
6722 It is called with two arguments, the buffer and optional buffer specific
6723 data, and should return a window displaying that buffer.
6724 The default value normally makes a separate frame for the buffer,
6725 using `special-display-frame-alist' to specify the frame parameters.
6726 But if the buffer specific data includes (same-buffer . t) then the
6727 buffer is displayed in the current selected window.
6728 Otherwise if it includes (same-frame . t) then the buffer is displayed in
6729 a new window in the currently selected frame.
6731 A buffer is special if it is listed in `special-display-buffer-names'
6732 or matches a regexp in `special-display-regexps'. */);
6733 Vspecial_display_function = Qnil;
6735 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names,
6736 doc: /* *List of buffer names that should appear in the selected window.
6737 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'
6738 switches to it in the selected window, rather than making it appear
6739 in some other window.
6741 An element of the list can be a cons cell instead of just a string.
6742 Then the car must be a string, which specifies the buffer name.
6743 This is for compatibility with `special-display-buffer-names';
6744 the cdr of the cons cell is ignored.
6746 See also `same-window-regexps'. */);
6747 Vsame_window_buffer_names = Qnil;
6749 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps,
6750 doc: /* *List of regexps saying which buffers should appear in the selected window.
6751 If a buffer name matches one of these regexps, then displaying it
6752 using `display-buffer' or `pop-to-buffer' switches to it
6753 in the selected window, rather than making it appear in some other window.
6755 An element of the list can be a cons cell instead of just a string.
6756 Then the car must be a string, which specifies the buffer name.
6757 This is for compatibility with `special-display-buffer-names';
6758 the cdr of the cons cell is ignored.
6760 See also `same-window-buffer-names'. */);
6761 Vsame_window_regexps = Qnil;
6763 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows,
6764 doc: /* *Non-nil means display-buffer should make new windows. */);
6765 pop_up_windows = 1;
6767 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines,
6768 doc: /* *Number of lines of continuity when scrolling by screenfuls. */);
6769 next_screen_context_lines = 2;
6771 DEFVAR_INT ("split-height-threshold", &split_height_threshold,
6772 doc: /* *A window must be at least this tall to be eligible for splitting by `display-buffer'.
6773 If there is only one window, it is split regardless of this value. */);
6774 split_height_threshold = 500;
6776 DEFVAR_INT ("window-min-height", &window_min_height,
6777 doc: /* *Delete any window less than this tall (including its mode line). */);
6778 window_min_height = 4;
6780 DEFVAR_INT ("window-min-width", &window_min_width,
6781 doc: /* *Delete any window less than this wide. */);
6782 window_min_width = 10;
6784 DEFVAR_LISP ("scroll-preserve-screen-position",
6785 &Vscroll_preserve_screen_position,
6786 doc: /* *Non-nil means scroll commands move point to keep its screen line unchanged.
6787 This is only when it is impossible to keep point fixed and still
6788 scroll as specified. */);
6789 Vscroll_preserve_screen_position = Qnil;
6791 DEFVAR_LISP ("window-configuration-change-hook",
6792 &Vwindow_configuration_change_hook,
6793 doc: /* Functions to call when window configuration changes.
6794 The selected frame is the one whose configuration has changed. */);
6795 Vwindow_configuration_change_hook = Qnil;
6797 DEFVAR_BOOL ("window-size-fixed", &window_size_fixed,
6798 doc: /* Non-nil in a buffer means windows displaying the buffer are fixed-size.
6799 If the value is`height', then only the window's height is fixed.
6800 If the value is `width', then only the window's width is fixed.
6801 Any other non-nil value fixes both the width and the height.
6802 Emacs won't change the size of any window displaying that buffer,
6803 unless you explicitly change the size, or Emacs has no other choice. */);
6804 Fmake_variable_buffer_local (Qwindow_size_fixed);
6805 window_size_fixed = 0;
6807 defsubr (&Sselected_window);
6808 defsubr (&Sminibuffer_window);
6809 defsubr (&Swindow_minibuffer_p);
6810 defsubr (&Swindowp);
6811 defsubr (&Swindow_live_p);
6812 defsubr (&Spos_visible_in_window_p);
6813 defsubr (&Swindow_buffer);
6814 defsubr (&Swindow_height);
6815 defsubr (&Swindow_width);
6816 defsubr (&Swindow_hscroll);
6817 defsubr (&Sset_window_hscroll);
6818 defsubr (&Swindow_redisplay_end_trigger);
6819 defsubr (&Sset_window_redisplay_end_trigger);
6820 defsubr (&Swindow_edges);
6821 defsubr (&Swindow_pixel_edges);
6822 defsubr (&Swindow_inside_edges);
6823 defsubr (&Swindow_inside_pixel_edges);
6824 defsubr (&Scoordinates_in_window_p);
6825 defsubr (&Swindow_at);
6826 defsubr (&Swindow_point);
6827 defsubr (&Swindow_start);
6828 defsubr (&Swindow_end);
6829 defsubr (&Sset_window_point);
6830 defsubr (&Sset_window_start);
6831 defsubr (&Swindow_dedicated_p);
6832 defsubr (&Sset_window_dedicated_p);
6833 defsubr (&Swindow_display_table);
6834 defsubr (&Sset_window_display_table);
6835 defsubr (&Snext_window);
6836 defsubr (&Sprevious_window);
6837 defsubr (&Sother_window);
6838 defsubr (&Sget_lru_window);
6839 defsubr (&Sget_largest_window);
6840 defsubr (&Sget_buffer_window);
6841 defsubr (&Sdelete_other_windows);
6842 defsubr (&Sdelete_windows_on);
6843 defsubr (&Sreplace_buffer_in_windows);
6844 defsubr (&Sdelete_window);
6845 defsubr (&Sset_window_buffer);
6846 defsubr (&Sselect_window);
6847 defsubr (&Sspecial_display_p);
6848 defsubr (&Ssame_window_p);
6849 defsubr (&Sdisplay_buffer);
6850 defsubr (&Sforce_window_update);
6851 defsubr (&Ssplit_window);
6852 defsubr (&Senlarge_window);
6853 defsubr (&Sshrink_window);
6854 defsubr (&Sscroll_up);
6855 defsubr (&Sscroll_down);
6856 defsubr (&Sscroll_left);
6857 defsubr (&Sscroll_right);
6858 defsubr (&Sother_window_for_scrolling);
6859 defsubr (&Sscroll_other_window);
6860 defsubr (&Sminibuffer_selected_window);
6861 defsubr (&Srecenter);
6862 defsubr (&Swindow_text_height);
6863 defsubr (&Smove_to_window_line);
6864 defsubr (&Swindow_configuration_p);
6865 defsubr (&Swindow_configuration_frame);
6866 defsubr (&Sset_window_configuration);
6867 defsubr (&Scurrent_window_configuration);
6868 defsubr (&Ssave_window_excursion);
6869 defsubr (&Sset_window_margins);
6870 defsubr (&Swindow_margins);
6871 defsubr (&Sset_window_fringes);
6872 defsubr (&Swindow_fringes);
6873 defsubr (&Sset_window_scroll_bars);
6874 defsubr (&Swindow_scroll_bars);
6875 defsubr (&Swindow_vscroll);
6876 defsubr (&Sset_window_vscroll);
6877 defsubr (&Scompare_window_configurations);
6878 defsubr (&Swindow_list);
6881 void
6882 keys_of_window ()
6884 initial_define_key (control_x_map, '1', "delete-other-windows");
6885 initial_define_key (control_x_map, '2', "split-window");
6886 initial_define_key (control_x_map, '0', "delete-window");
6887 initial_define_key (control_x_map, 'o', "other-window");
6888 initial_define_key (control_x_map, '^', "enlarge-window");
6889 initial_define_key (control_x_map, '<', "scroll-left");
6890 initial_define_key (control_x_map, '>', "scroll-right");
6892 initial_define_key (global_map, Ctl ('V'), "scroll-up");
6893 initial_define_key (meta_map, Ctl ('V'), "scroll-other-window");
6894 initial_define_key (meta_map, 'v', "scroll-down");
6896 initial_define_key (global_map, Ctl('L'), "recenter");
6897 initial_define_key (meta_map, 'r', "move-to-window-line");
6900 /* arch-tag: 90a9c576-0590-48f1-a5f1-6c96a0452d9f
6901 (do not change this comment) */