*** empty log message ***
[emacs.git] / src / window.c
blobcdddc0da82e3bf5e1d167ad4cf88dcf2b9d22f40
1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
4 2001, 2002, 2003, 2004, 2005 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 line and page scrolling on tall lines (with images)
128 does partial scrolling by modifying window-vscroll. */
130 int auto_window_vscroll_p;
132 /* Non-zero means to use mode-line-inactive face in all windows but the
133 selected-window and the minibuffer-scroll-window when the
134 minibuffer is active. */
135 int mode_line_in_non_selected_windows;
137 /* If a window gets smaller than either of these, it is removed. */
139 EMACS_INT window_min_height;
140 EMACS_INT window_min_width;
142 /* Nonzero implies Fdisplay_buffer should create windows. */
144 int pop_up_windows;
146 /* Nonzero implies make new frames for Fdisplay_buffer. */
148 int pop_up_frames;
150 /* Nonzero means reuse existing frames for displaying buffers. */
152 int display_buffer_reuse_frames;
154 /* Non-nil means use this function instead of default */
156 Lisp_Object Vpop_up_frame_function;
158 /* Function to call to handle Fdisplay_buffer. */
160 Lisp_Object Vdisplay_buffer_function;
162 /* Non-nil means that Fdisplay_buffer should even the heights of windows. */
164 Lisp_Object Veven_window_heights;
166 /* List of buffer *names* for buffers that should have their own frames. */
168 Lisp_Object Vspecial_display_buffer_names;
170 /* List of regexps for buffer names that should have their own frames. */
172 Lisp_Object Vspecial_display_regexps;
174 /* Function to pop up a special frame. */
176 Lisp_Object Vspecial_display_function;
178 /* List of buffer *names* for buffers to appear in selected window. */
180 Lisp_Object Vsame_window_buffer_names;
182 /* List of regexps for buffer names to appear in selected window. */
184 Lisp_Object Vsame_window_regexps;
186 /* Hook run at end of temp_output_buffer_show. */
188 Lisp_Object Qtemp_buffer_show_hook;
190 /* Fdisplay_buffer always splits the largest window
191 if that window is more than this high. */
193 EMACS_INT split_height_threshold;
195 /* Number of lines of continuity in scrolling by screenfuls. */
197 EMACS_INT next_screen_context_lines;
199 /* Incremented for each window created. */
201 static int sequence_number;
203 /* Nonzero after init_window_once has finished. */
205 static int window_initialized;
207 /* Hook to run when window config changes. */
209 Lisp_Object Qwindow_configuration_change_hook;
210 Lisp_Object Vwindow_configuration_change_hook;
212 /* Non-nil means scroll commands try to put point
213 at the same screen height as previously. */
215 Lisp_Object Vscroll_preserve_screen_position;
217 #if 0 /* This isn't used anywhere. */
218 /* Nonzero means we can split a frame even if it is "unsplittable". */
219 static int inhibit_frame_unsplittable;
220 #endif /* 0 */
222 extern EMACS_INT scroll_margin;
224 extern Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
226 DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0,
227 doc: /* Returns t if OBJECT is a window. */)
228 (object)
229 Lisp_Object object;
231 return WINDOWP (object) ? Qt : Qnil;
234 DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0,
235 doc: /* Returns t if OBJECT is a window which is currently visible. */)
236 (object)
237 Lisp_Object object;
239 return WINDOW_LIVE_P (object) ? Qt : Qnil;
242 Lisp_Object
243 make_window ()
245 Lisp_Object val;
246 register struct window *p;
248 p = allocate_window ();
249 ++sequence_number;
250 XSETFASTINT (p->sequence_number, sequence_number);
251 XSETFASTINT (p->left_col, 0);
252 XSETFASTINT (p->top_line, 0);
253 XSETFASTINT (p->total_lines, 0);
254 XSETFASTINT (p->total_cols, 0);
255 XSETFASTINT (p->hscroll, 0);
256 XSETFASTINT (p->min_hscroll, 0);
257 p->orig_top_line = p->orig_total_lines = Qnil;
258 p->start = Fmake_marker ();
259 p->pointm = Fmake_marker ();
260 XSETFASTINT (p->use_time, 0);
261 p->frame = Qnil;
262 p->display_table = Qnil;
263 p->dedicated = Qnil;
264 p->pseudo_window_p = 0;
265 bzero (&p->cursor, sizeof (p->cursor));
266 bzero (&p->last_cursor, sizeof (p->last_cursor));
267 bzero (&p->phys_cursor, sizeof (p->phys_cursor));
268 p->desired_matrix = p->current_matrix = 0;
269 p->nrows_scale_factor = p->ncols_scale_factor = 1;
270 p->phys_cursor_type = -1;
271 p->phys_cursor_width = -1;
272 p->must_be_updated_p = 0;
273 XSETFASTINT (p->window_end_vpos, 0);
274 XSETFASTINT (p->window_end_pos, 0);
275 p->window_end_valid = Qnil;
276 p->vscroll = 0;
277 XSETWINDOW (val, p);
278 XSETFASTINT (p->last_point, 0);
279 p->frozen_window_start_p = 0;
280 p->height_fixed_p = 0;
281 p->last_cursor_off_p = p->cursor_off_p = 0;
282 p->left_margin_cols = Qnil;
283 p->right_margin_cols = Qnil;
284 p->left_fringe_width = Qnil;
285 p->right_fringe_width = Qnil;
286 p->fringes_outside_margins = Qnil;
287 p->scroll_bar_width = Qnil;
288 p->vertical_scroll_bar_type = Qt;
290 Vwindow_list = Qnil;
291 return val;
294 DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0,
295 doc: /* Return the window that the cursor now appears in and commands apply to. */)
298 return selected_window;
301 DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0,
302 doc: /* Return the window used now for minibuffers.
303 If the optional argument FRAME is specified, return the minibuffer window
304 used by that frame. */)
305 (frame)
306 Lisp_Object frame;
308 if (NILP (frame))
309 frame = selected_frame;
310 CHECK_LIVE_FRAME (frame);
311 return FRAME_MINIBUF_WINDOW (XFRAME (frame));
314 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, Swindow_minibuffer_p, 0, 1, 0,
315 doc: /* Returns non-nil if WINDOW is a minibuffer window.
316 WINDOW defaults to the selected window. */)
317 (window)
318 Lisp_Object window;
320 struct window *w = decode_window (window);
321 return MINI_WINDOW_P (w) ? Qt : Qnil;
325 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p,
326 Spos_visible_in_window_p, 0, 3, 0,
327 doc: /* Return non-nil if position POS is currently on the frame in WINDOW.
328 Return nil if that position is scrolled vertically out of view.
329 If a character is only partially visible, nil is returned, unless the
330 optional argument PARTIALLY is non-nil.
331 If POS is only out of view because of horizontal scrolling, return non-nil.
332 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
334 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
335 return value is a list (X Y PARTIAL) where X and Y are the pixel coordinates
336 relative to the top left corner of the window. PARTIAL is nil if the character
337 after POS is fully visible; otherwise it is a cons (RTOP . RBOT) where RTOP
338 and RBOT are the number of pixels invisible at the top and bottom of the row. */)
339 (pos, window, partially)
340 Lisp_Object pos, window, partially;
342 register struct window *w;
343 register int posint;
344 register struct buffer *buf;
345 struct text_pos top;
346 Lisp_Object in_window = Qnil;
347 int rtop, rbot, fully_p = 1;
348 int x, y;
350 w = decode_window (window);
351 buf = XBUFFER (w->buffer);
352 SET_TEXT_POS_FROM_MARKER (top, w->start);
354 if (!NILP (pos))
356 CHECK_NUMBER_COERCE_MARKER (pos);
357 posint = XINT (pos);
359 else if (w == XWINDOW (selected_window))
360 posint = PT;
361 else
362 posint = XMARKER (w->pointm)->charpos;
364 /* If position is above window start or outside buffer boundaries,
365 or if window start is out of range, position is not visible. */
366 if (posint >= CHARPOS (top)
367 && posint <= BUF_ZV (buf)
368 && CHARPOS (top) >= BUF_BEGV (buf)
369 && CHARPOS (top) <= BUF_ZV (buf)
370 && pos_visible_p (w, posint, &x, &y, &rtop, &rbot, NILP (partially))
371 && (fully_p = !rtop && !rbot, (!NILP (partially) || fully_p)))
372 in_window = Qt;
374 if (!NILP (in_window) && !NILP (partially))
375 in_window = Fcons (make_number (x),
376 Fcons (make_number (y),
377 Fcons ((fully_p ? Qnil
378 : Fcons (make_number (rtop),
379 make_number (rbot))),
380 Qnil)));
381 return in_window;
385 static struct window *
386 decode_window (window)
387 register Lisp_Object window;
389 if (NILP (window))
390 return XWINDOW (selected_window);
392 CHECK_LIVE_WINDOW (window);
393 return XWINDOW (window);
396 static struct window *
397 decode_any_window (window)
398 register Lisp_Object window;
400 if (NILP (window))
401 return XWINDOW (selected_window);
403 CHECK_WINDOW (window);
404 return XWINDOW (window);
407 DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0,
408 doc: /* Return the buffer that WINDOW is displaying.
409 WINDOW defaults to the selected window. */)
410 (window)
411 Lisp_Object window;
413 return decode_window (window)->buffer;
416 DEFUN ("window-height", Fwindow_height, Swindow_height, 0, 1, 0,
417 doc: /* Return the number of lines in WINDOW (including its mode line). */)
418 (window)
419 Lisp_Object window;
421 return decode_any_window (window)->total_lines;
424 DEFUN ("window-width", Fwindow_width, Swindow_width, 0, 1, 0,
425 doc: /* Return the number of display columns in WINDOW.
426 This is the width that is usable columns available for text in WINDOW.
427 If you want to find out how many columns WINDOW takes up,
428 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
429 (window)
430 Lisp_Object window;
432 return make_number (window_box_text_cols (decode_any_window (window)));
435 DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0,
436 doc: /* Return the number of columns by which WINDOW is scrolled from left margin. */)
437 (window)
438 Lisp_Object window;
440 return decode_window (window)->hscroll;
443 DEFUN ("set-window-hscroll", Fset_window_hscroll, Sset_window_hscroll, 2, 2, 0,
444 doc: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
445 Return NCOL. NCOL should be zero or positive.
447 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
448 window so that the location of point becomes invisible. */)
449 (window, ncol)
450 Lisp_Object window, ncol;
452 struct window *w = decode_window (window);
453 int hscroll;
455 CHECK_NUMBER (ncol);
456 hscroll = max (0, XINT (ncol));
458 /* Prevent redisplay shortcuts when changing the hscroll. */
459 if (XINT (w->hscroll) != hscroll)
460 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
462 w->hscroll = make_number (hscroll);
463 return ncol;
466 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger,
467 Swindow_redisplay_end_trigger, 0, 1, 0,
468 doc: /* Return WINDOW's redisplay end trigger value.
469 See `set-window-redisplay-end-trigger' for more information. */)
470 (window)
471 Lisp_Object window;
473 return decode_window (window)->redisplay_end_trigger;
476 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger,
477 Sset_window_redisplay_end_trigger, 2, 2, 0,
478 doc: /* Set WINDOW's redisplay end trigger value to VALUE.
479 VALUE should be a buffer position (typically a marker) or nil.
480 If it is a buffer position, then if redisplay in WINDOW reaches a position
481 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
482 with two arguments: WINDOW, and the end trigger value.
483 Afterwards the end-trigger value is reset to nil. */)
484 (window, value)
485 register Lisp_Object window, value;
487 register struct window *w;
489 w = decode_window (window);
490 w->redisplay_end_trigger = value;
491 return value;
494 DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0,
495 doc: /* Return a list of the edge coordinates of WINDOW.
496 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
497 RIGHT is one more than the rightmost column occupied by WINDOW,
498 and BOTTOM is one more than the bottommost row occupied by WINDOW.
499 The edges include the space used by the window's scroll bar,
500 display margins, fringes, header line, and mode line, if it has them.
501 To get the edges of the actual text area, use `window-inside-edges'. */)
502 (window)
503 Lisp_Object window;
505 register struct window *w = decode_any_window (window);
507 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w)),
508 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w)),
509 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w)),
510 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w)),
511 Qnil))));
514 DEFUN ("window-pixel-edges", Fwindow_pixel_edges, Swindow_pixel_edges, 0, 1, 0,
515 doc: /* Return a list of the edge pixel coordinates of WINDOW.
516 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
517 RIGHT is one more than the rightmost x position occupied by WINDOW,
518 and BOTTOM is one more than the bottommost y position occupied by WINDOW.
519 The pixel edges include the space used by the window's scroll bar,
520 display margins, fringes, header line, and mode line, if it has them.
521 To get the edges of the actual text area, use `window-inside-pixel-edges'. */)
522 (window)
523 Lisp_Object window;
525 register struct window *w = decode_any_window (window);
527 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w)),
528 Fcons (make_number (WINDOW_TOP_EDGE_Y (w)),
529 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w)),
530 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w)),
531 Qnil))));
534 DEFUN ("window-inside-edges", Fwindow_inside_edges, Swindow_inside_edges, 0, 1, 0,
535 doc: /* Return a list of the edge coordinates of WINDOW.
536 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
537 RIGHT is one more than the rightmost column used by text in WINDOW,
538 and BOTTOM is one more than the bottommost row used by text in WINDOW.
539 The inside edges do not include the space used by the window's scroll bar,
540 display margins, fringes, header line, and/or mode line. */)
541 (window)
542 Lisp_Object window;
544 register struct window *w = decode_any_window (window);
546 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w)
547 + WINDOW_LEFT_MARGIN_COLS (w)
548 + WINDOW_LEFT_FRINGE_COLS (w)),
549 make_number (WINDOW_TOP_EDGE_LINE (w)
550 + WINDOW_HEADER_LINE_LINES (w)),
551 make_number (WINDOW_RIGHT_EDGE_COL (w)
552 - WINDOW_RIGHT_MARGIN_COLS (w)
553 - WINDOW_RIGHT_FRINGE_COLS (w)),
554 make_number (WINDOW_BOTTOM_EDGE_LINE (w)
555 - WINDOW_MODE_LINE_LINES (w)));
558 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges, Swindow_inside_pixel_edges, 0, 1, 0,
559 doc: /* Return a list of the edge pixel coordinates of WINDOW.
560 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
561 RIGHT is one more than the rightmost x position used by text in WINDOW,
562 and BOTTOM is one more than the bottommost y position used by text in WINDOW.
563 The inside edges do not include the space used by the window's scroll bar,
564 display margins, fringes, header line, and/or mode line. */)
565 (window)
566 Lisp_Object window;
568 register struct window *w = decode_any_window (window);
570 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w)
571 + WINDOW_LEFT_MARGIN_WIDTH (w)
572 + WINDOW_LEFT_FRINGE_WIDTH (w)),
573 make_number (WINDOW_TOP_EDGE_Y (w)
574 + WINDOW_HEADER_LINE_HEIGHT (w)),
575 make_number (WINDOW_RIGHT_EDGE_X (w)
576 - WINDOW_RIGHT_MARGIN_WIDTH (w)
577 - WINDOW_RIGHT_FRINGE_WIDTH (w)),
578 make_number (WINDOW_BOTTOM_EDGE_Y (w)
579 - WINDOW_MODE_LINE_HEIGHT (w)));
582 /* Test if the character at column *X, row *Y is within window W.
583 If it is not, return ON_NOTHING;
584 if it is in the window's text area,
585 set *x and *y to its location relative to the upper left corner
586 of the window, and
587 return ON_TEXT;
588 if it is on the window's modeline, return ON_MODE_LINE;
589 if it is on the border between the window and its right sibling,
590 return ON_VERTICAL_BORDER.
591 if it is on a scroll bar,
592 return ON_SCROLL_BAR.
593 if it is on the window's top line, return ON_HEADER_LINE;
594 if it is in left or right fringe of the window,
595 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y
596 to window-relative coordinates;
597 if it is in the marginal area to the left/right of the window,
598 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y
599 to window-relative coordinates.
601 X and Y are frame relative pixel coordinates. */
603 static enum window_part
604 coordinates_in_window (w, x, y)
605 register struct window *w;
606 register int *x, *y;
608 struct frame *f = XFRAME (WINDOW_FRAME (w));
609 int left_x, right_x, top_y, bottom_y;
610 enum window_part part;
611 int ux = FRAME_COLUMN_WIDTH (f);
612 int x0 = WINDOW_LEFT_EDGE_X (w);
613 int x1 = WINDOW_RIGHT_EDGE_X (w);
614 /* The width of the area where the vertical line can be dragged.
615 (Between mode lines for instance. */
616 int grabbable_width = ux;
617 int lmargin_width, rmargin_width, text_left, text_right;
619 /* In what's below, we subtract 1 when computing right_x because we
620 want the rightmost pixel, which is given by left_pixel+width-1. */
621 if (w->pseudo_window_p)
623 left_x = 0;
624 right_x = WINDOW_TOTAL_WIDTH (w) - 1;
625 top_y = WINDOW_TOP_EDGE_Y (w);
626 bottom_y = WINDOW_BOTTOM_EDGE_Y (w);
628 else
630 left_x = WINDOW_BOX_LEFT_EDGE_X (w);
631 right_x = WINDOW_BOX_RIGHT_EDGE_X (w) - 1;
632 top_y = WINDOW_TOP_EDGE_Y (w);
633 bottom_y = WINDOW_BOTTOM_EDGE_Y (w);
636 /* Outside any interesting row? */
637 if (*y < top_y || *y >= bottom_y)
638 return ON_NOTHING;
640 /* On the mode line or header line? If it's near the start of
641 the mode or header line of window that's has a horizontal
642 sibling, say it's on the vertical line. That's to be able
643 to resize windows horizontally in case we're using toolkit
644 scroll bars. */
646 if (WINDOW_WANTS_MODELINE_P (w)
647 && *y >= bottom_y - CURRENT_MODE_LINE_HEIGHT (w))
649 part = ON_MODE_LINE;
651 header_vertical_border_check:
652 /* We're somewhere on the mode line. We consider the place
653 between mode lines of horizontally adjacent mode lines
654 as the vertical border. If scroll bars on the left,
655 return the right window. */
656 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)
657 || WINDOW_RIGHTMOST_P (w))
659 if (!WINDOW_LEFTMOST_P (w) && abs (*x - x0) < grabbable_width)
660 return ON_VERTICAL_BORDER;
662 else
664 if (abs (*x - x1) < grabbable_width)
665 return ON_VERTICAL_BORDER;
668 if (*x < x0 || *x >= x1)
669 return ON_NOTHING;
671 /* Convert X and Y to window relative coordinates.
672 Mode line starts at left edge of window. */
673 *x -= x0;
674 *y -= top_y;
675 return part;
678 if (WINDOW_WANTS_HEADER_LINE_P (w)
679 && *y < top_y + CURRENT_HEADER_LINE_HEIGHT (w))
681 part = ON_HEADER_LINE;
682 goto header_vertical_border_check;
685 if (*x < x0 || *x >= x1)
686 return ON_NOTHING;
688 /* Outside any interesting column? */
689 if (*x < left_x || *x > right_x)
690 return ON_SCROLL_BAR;
692 lmargin_width = window_box_width (w, LEFT_MARGIN_AREA);
693 rmargin_width = window_box_width (w, RIGHT_MARGIN_AREA);
695 text_left = window_box_left (w, TEXT_AREA);
696 text_right = text_left + window_box_width (w, TEXT_AREA);
698 if (FRAME_WINDOW_P (f))
700 if (!w->pseudo_window_p
701 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w)
702 && !WINDOW_RIGHTMOST_P (w)
703 && (abs (*x - right_x) < grabbable_width))
704 return ON_VERTICAL_BORDER;
706 else
708 /* Need to say "*x > right_x" rather than >=, since on character
709 terminals, the vertical line's x coordinate is right_x. */
710 if (!w->pseudo_window_p
711 && !WINDOW_RIGHTMOST_P (w)
712 && *x > right_x - ux)
714 /* On the border on the right side of the window? Assume that
715 this area begins at RIGHT_X minus a canonical char width. */
716 return ON_VERTICAL_BORDER;
720 if (*x < text_left)
722 if (lmargin_width > 0
723 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
724 ? (*x >= left_x + WINDOW_LEFT_FRINGE_WIDTH (w))
725 : (*x < left_x + lmargin_width)))
727 *x -= left_x;
728 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
729 *x -= WINDOW_LEFT_FRINGE_WIDTH (w);
730 *y -= top_y;
731 return ON_LEFT_MARGIN;
734 /* Convert X and Y to window-relative pixel coordinates. */
735 *x -= left_x;
736 *y -= top_y;
737 return ON_LEFT_FRINGE;
740 if (*x >= text_right)
742 if (rmargin_width > 0
743 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
744 ? (*x < right_x - WINDOW_RIGHT_FRINGE_WIDTH (w))
745 : (*x >= right_x - rmargin_width)))
747 *x -= right_x;
748 if (!WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
749 *x -= WINDOW_RIGHT_FRINGE_WIDTH (w);
750 *y -= top_y;
751 return ON_RIGHT_MARGIN;
754 /* Convert X and Y to window-relative pixel coordinates. */
755 *x -= left_x + WINDOW_LEFT_FRINGE_WIDTH (w);
756 *y -= top_y;
757 return ON_RIGHT_FRINGE;
760 /* Everything special ruled out - must be on text area */
761 *x -= left_x + WINDOW_LEFT_FRINGE_WIDTH (w);
762 *y -= top_y;
763 return ON_TEXT;
767 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
768 Scoordinates_in_window_p, 2, 2, 0,
769 doc: /* Return non-nil if COORDINATES are in WINDOW.
770 COORDINATES is a cons of the form (X . Y), X and Y being distances
771 measured in characters from the upper-left corner of the frame.
772 \(0 . 0) denotes the character in the upper left corner of the
773 frame.
774 If COORDINATES are in the text portion of WINDOW,
775 the coordinates relative to the window are returned.
776 If they are in the mode line of WINDOW, `mode-line' is returned.
777 If they are in the top mode line of WINDOW, `header-line' is returned.
778 If they are in the left fringe of WINDOW, `left-fringe' is returned.
779 If they are in the right fringe of WINDOW, `right-fringe' is returned.
780 If they are on the border between WINDOW and its right sibling,
781 `vertical-line' is returned.
782 If they are in the windows's left or right marginal areas, `left-margin'\n\
783 or `right-margin' is returned. */)
784 (coordinates, window)
785 register Lisp_Object coordinates, window;
787 struct window *w;
788 struct frame *f;
789 int x, y;
790 Lisp_Object lx, ly;
792 CHECK_WINDOW (window);
793 w = XWINDOW (window);
794 f = XFRAME (w->frame);
795 CHECK_CONS (coordinates);
796 lx = Fcar (coordinates);
797 ly = Fcdr (coordinates);
798 CHECK_NUMBER_OR_FLOAT (lx);
799 CHECK_NUMBER_OR_FLOAT (ly);
800 x = FRAME_PIXEL_X_FROM_CANON_X (f, lx) + FRAME_INTERNAL_BORDER_WIDTH (f);
801 y = FRAME_PIXEL_Y_FROM_CANON_Y (f, ly) + FRAME_INTERNAL_BORDER_WIDTH (f);
803 switch (coordinates_in_window (w, &x, &y))
805 case ON_NOTHING:
806 return Qnil;
808 case ON_TEXT:
809 /* X and Y are now window relative pixel coordinates. Convert
810 them to canonical char units before returning them. */
811 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f, x),
812 FRAME_CANON_Y_FROM_PIXEL_Y (f, y));
814 case ON_MODE_LINE:
815 return Qmode_line;
817 case ON_VERTICAL_BORDER:
818 return Qvertical_line;
820 case ON_HEADER_LINE:
821 return Qheader_line;
823 case ON_LEFT_FRINGE:
824 return Qleft_fringe;
826 case ON_RIGHT_FRINGE:
827 return Qright_fringe;
829 case ON_LEFT_MARGIN:
830 return Qleft_margin;
832 case ON_RIGHT_MARGIN:
833 return Qright_margin;
835 case ON_SCROLL_BAR:
836 /* Historically we are supposed to return nil in this case. */
837 return Qnil;
839 default:
840 abort ();
845 /* Callback for foreach_window, used in window_from_coordinates.
846 Check if window W contains coordinates specified by USER_DATA which
847 is actually a pointer to a struct check_window_data CW.
849 Check if window W contains coordinates *CW->x and *CW->y. If it
850 does, return W in *CW->window, as Lisp_Object, and return in
851 *CW->part the part of the window under coordinates *X,*Y. Return
852 zero from this function to stop iterating over windows. */
854 struct check_window_data
856 Lisp_Object *window;
857 int *x, *y;
858 enum window_part *part;
861 static int
862 check_window_containing (w, user_data)
863 struct window *w;
864 void *user_data;
866 struct check_window_data *cw = (struct check_window_data *) user_data;
867 enum window_part found;
868 int continue_p = 1;
870 found = coordinates_in_window (w, cw->x, cw->y);
871 if (found != ON_NOTHING)
873 *cw->part = found;
874 XSETWINDOW (*cw->window, w);
875 continue_p = 0;
878 return continue_p;
882 /* Find the window containing frame-relative pixel position X/Y and
883 return it as a Lisp_Object.
885 If X, Y is on one of the window's special `window_part' elements,
886 set *PART to the id of that element, and return X and Y converted
887 to window relative coordinates in WX and WY.
889 If there is no window under X, Y return nil and leave *PART
890 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
892 This function was previously implemented with a loop cycling over
893 windows with Fnext_window, and starting with the frame's selected
894 window. It turned out that this doesn't work with an
895 implementation of next_window using Vwindow_list, because
896 FRAME_SELECTED_WINDOW (F) is not always contained in the window
897 tree of F when this function is called asynchronously from
898 note_mouse_highlight. The original loop didn't terminate in this
899 case. */
901 Lisp_Object
902 window_from_coordinates (f, x, y, part, wx, wy, tool_bar_p)
903 struct frame *f;
904 int x, y;
905 enum window_part *part;
906 int *wx, *wy;
907 int tool_bar_p;
909 Lisp_Object window;
910 struct check_window_data cw;
911 enum window_part dummy;
913 if (part == 0)
914 part = &dummy;
916 window = Qnil;
917 cw.window = &window, cw.x = &x, cw.y = &y; cw.part = part;
918 foreach_window (f, check_window_containing, &cw);
920 /* If not found above, see if it's in the tool bar window, if a tool
921 bar exists. */
922 if (NILP (window)
923 && tool_bar_p
924 && WINDOWP (f->tool_bar_window)
925 && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window)) > 0
926 && (coordinates_in_window (XWINDOW (f->tool_bar_window), &x, &y)
927 != ON_NOTHING))
929 *part = ON_TEXT;
930 window = f->tool_bar_window;
933 if (wx) *wx = x;
934 if (wy) *wy = y;
936 return window;
939 DEFUN ("window-at", Fwindow_at, Swindow_at, 2, 3, 0,
940 doc: /* Return window containing coordinates X and Y on FRAME.
941 If omitted, FRAME defaults to the currently selected frame.
942 The top left corner of the frame is considered to be row 0,
943 column 0. */)
944 (x, y, frame)
945 Lisp_Object x, y, frame;
947 struct frame *f;
949 if (NILP (frame))
950 frame = selected_frame;
951 CHECK_LIVE_FRAME (frame);
952 f = XFRAME (frame);
954 /* Check that arguments are integers or floats. */
955 CHECK_NUMBER_OR_FLOAT (x);
956 CHECK_NUMBER_OR_FLOAT (y);
958 return window_from_coordinates (f,
959 (FRAME_PIXEL_X_FROM_CANON_X (f, x)
960 + FRAME_INTERNAL_BORDER_WIDTH (f)),
961 (FRAME_PIXEL_Y_FROM_CANON_Y (f, y)
962 + FRAME_INTERNAL_BORDER_WIDTH (f)),
963 0, 0, 0, 0);
966 DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0,
967 doc: /* Return current value of point in WINDOW.
968 For a nonselected window, this is the value point would have
969 if that window were selected.
971 Note that, when WINDOW is the selected window and its buffer
972 is also currently selected, the value returned is the same as (point).
973 It would be more strictly correct to return the `top-level' value
974 of point, outside of any save-excursion forms.
975 But that is hard to define. */)
976 (window)
977 Lisp_Object window;
979 register struct window *w = decode_window (window);
981 if (w == XWINDOW (selected_window)
982 && current_buffer == XBUFFER (w->buffer))
983 return Fpoint ();
984 return Fmarker_position (w->pointm);
987 DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0,
988 doc: /* Return position at which display currently starts in WINDOW.
989 This is updated by redisplay or by calling `set-window-start'. */)
990 (window)
991 Lisp_Object window;
993 return Fmarker_position (decode_window (window)->start);
996 /* This is text temporarily removed from the doc string below.
998 This function returns nil if the position is not currently known.
999 That happens when redisplay is preempted and doesn't finish.
1000 If in that case you want to compute where the end of the window would
1001 have been if redisplay had finished, do this:
1002 (save-excursion
1003 (goto-char (window-start window))
1004 (vertical-motion (1- (window-height window)) window)
1005 (point))") */
1007 DEFUN ("window-end", Fwindow_end, Swindow_end, 0, 2, 0,
1008 doc: /* Return position at which display currently ends in WINDOW.
1009 This is updated by redisplay, when it runs to completion.
1010 Simply changing the buffer text or setting `window-start'
1011 does not update this value.
1012 Return nil if there is no recorded value. \(This can happen if the
1013 last redisplay of WINDOW was preempted, and did not finish.)
1014 If UPDATE is non-nil, compute the up-to-date position
1015 if it isn't already recorded. */)
1016 (window, update)
1017 Lisp_Object window, update;
1019 Lisp_Object value;
1020 struct window *w = decode_window (window);
1021 Lisp_Object buf;
1023 buf = w->buffer;
1024 CHECK_BUFFER (buf);
1026 #if 0 /* This change broke some things. We should make it later. */
1027 /* If we don't know the end position, return nil.
1028 The user can compute it with vertical-motion if he wants to.
1029 It would be nicer to do it automatically,
1030 but that's so slow that it would probably bother people. */
1031 if (NILP (w->window_end_valid))
1032 return Qnil;
1033 #endif
1035 if (! NILP (update)
1036 && ! (! NILP (w->window_end_valid)
1037 && XFASTINT (w->last_modified) >= MODIFF))
1039 struct text_pos startp;
1040 struct it it;
1041 struct buffer *old_buffer = NULL, *b = XBUFFER (buf);
1043 /* In case W->start is out of the range, use something
1044 reasonable. This situation occurred when loading a file with
1045 `-l' containing a call to `rmail' with subsequent other
1046 commands. At the end, W->start happened to be BEG, while
1047 rmail had already narrowed the buffer. */
1048 if (XMARKER (w->start)->charpos < BEGV)
1049 SET_TEXT_POS (startp, BEGV, BEGV_BYTE);
1050 else if (XMARKER (w->start)->charpos > ZV)
1051 SET_TEXT_POS (startp, ZV, ZV_BYTE);
1052 else
1053 SET_TEXT_POS_FROM_MARKER (startp, w->start);
1055 /* Cannot use Fvertical_motion because that function doesn't
1056 cope with variable-height lines. */
1057 if (b != current_buffer)
1059 old_buffer = current_buffer;
1060 set_buffer_internal (b);
1063 start_display (&it, w, startp);
1064 move_it_vertically (&it, window_box_height (w));
1065 if (it.current_y < it.last_visible_y)
1066 move_it_past_eol (&it);
1067 value = make_number (IT_CHARPOS (it));
1069 if (old_buffer)
1070 set_buffer_internal (old_buffer);
1072 else
1073 XSETINT (value, BUF_Z (XBUFFER (buf)) - XFASTINT (w->window_end_pos));
1075 return value;
1078 DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0,
1079 doc: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1080 Return POS. */)
1081 (window, pos)
1082 Lisp_Object window, pos;
1084 register struct window *w = decode_window (window);
1086 CHECK_NUMBER_COERCE_MARKER (pos);
1087 if (w == XWINDOW (selected_window)
1088 && XBUFFER (w->buffer) == current_buffer)
1089 Fgoto_char (pos);
1090 else
1091 set_marker_restricted (w->pointm, pos, w->buffer);
1093 /* We have to make sure that redisplay updates the window to show
1094 the new value of point. */
1095 if (!EQ (window, selected_window))
1096 ++windows_or_buffers_changed;
1098 return pos;
1101 DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0,
1102 doc: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1103 Return POS.
1104 Optional third arg NOFORCE non-nil inhibits next redisplay
1105 from overriding motion of point in order to display at this exact start. */)
1106 (window, pos, noforce)
1107 Lisp_Object window, pos, noforce;
1109 register struct window *w = decode_window (window);
1111 CHECK_NUMBER_COERCE_MARKER (pos);
1112 set_marker_restricted (w->start, pos, w->buffer);
1113 /* this is not right, but much easier than doing what is right. */
1114 w->start_at_line_beg = Qnil;
1115 if (NILP (noforce))
1116 w->force_start = Qt;
1117 w->update_mode_line = Qt;
1118 XSETFASTINT (w->last_modified, 0);
1119 XSETFASTINT (w->last_overlay_modified, 0);
1120 if (!EQ (window, selected_window))
1121 windows_or_buffers_changed++;
1123 return pos;
1126 DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p,
1127 1, 1, 0,
1128 doc: /* Return WINDOW's dedicated object, usually t or nil.
1129 See also `set-window-dedicated-p'. */)
1130 (window)
1131 Lisp_Object window;
1133 return decode_window (window)->dedicated;
1136 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p,
1137 Sset_window_dedicated_p, 2, 2, 0,
1138 doc: /* Control whether WINDOW is dedicated to the buffer it displays.
1139 If it is dedicated, Emacs will not automatically change
1140 which buffer appears in it.
1141 The second argument is the new value for the dedication flag;
1142 non-nil means yes. */)
1143 (window, arg)
1144 Lisp_Object window, arg;
1146 register struct window *w = decode_window (window);
1148 w->dedicated = arg;
1150 return w->dedicated;
1153 DEFUN ("window-display-table", Fwindow_display_table, Swindow_display_table,
1154 0, 1, 0,
1155 doc: /* Return the display-table that WINDOW is using. */)
1156 (window)
1157 Lisp_Object window;
1159 return decode_window (window)->display_table;
1162 /* Get the display table for use on window W. This is either W's
1163 display table or W's buffer's display table. Ignore the specified
1164 tables if they are not valid; if no valid table is specified,
1165 return 0. */
1167 struct Lisp_Char_Table *
1168 window_display_table (w)
1169 struct window *w;
1171 struct Lisp_Char_Table *dp = NULL;
1173 if (DISP_TABLE_P (w->display_table))
1174 dp = XCHAR_TABLE (w->display_table);
1175 else if (BUFFERP (w->buffer))
1177 struct buffer *b = XBUFFER (w->buffer);
1179 if (DISP_TABLE_P (b->display_table))
1180 dp = XCHAR_TABLE (b->display_table);
1181 else if (DISP_TABLE_P (Vstandard_display_table))
1182 dp = XCHAR_TABLE (Vstandard_display_table);
1185 return dp;
1188 DEFUN ("set-window-display-table", Fset_window_display_table, Sset_window_display_table, 2, 2, 0,
1189 doc: /* Set WINDOW's display-table to TABLE. */)
1190 (window, table)
1191 register Lisp_Object window, table;
1193 register struct window *w;
1195 w = decode_window (window);
1196 w->display_table = table;
1197 return table;
1200 /* Record info on buffer window w is displaying
1201 when it is about to cease to display that buffer. */
1202 static void
1203 unshow_buffer (w)
1204 register struct window *w;
1206 Lisp_Object buf;
1207 struct buffer *b;
1209 buf = w->buffer;
1210 b = XBUFFER (buf);
1211 if (b != XMARKER (w->pointm)->buffer)
1212 abort ();
1214 #if 0
1215 if (w == XWINDOW (selected_window)
1216 || ! EQ (buf, XWINDOW (selected_window)->buffer))
1217 /* Do this except when the selected window's buffer
1218 is being removed from some other window. */
1219 #endif
1220 /* last_window_start records the start position that this buffer
1221 had in the last window to be disconnected from it.
1222 Now that this statement is unconditional,
1223 it is possible for the buffer to be displayed in the
1224 selected window, while last_window_start reflects another
1225 window which was recently showing the same buffer.
1226 Some people might say that might be a good thing. Let's see. */
1227 b->last_window_start = marker_position (w->start);
1229 /* Point in the selected window's buffer
1230 is actually stored in that buffer, and the window's pointm isn't used.
1231 So don't clobber point in that buffer. */
1232 if (! EQ (buf, XWINDOW (selected_window)->buffer)
1233 /* This line helps to fix Horsley's testbug.el bug. */
1234 && !(WINDOWP (b->last_selected_window)
1235 && w != XWINDOW (b->last_selected_window)
1236 && EQ (buf, XWINDOW (b->last_selected_window)->buffer)))
1237 temp_set_point_both (b,
1238 clip_to_bounds (BUF_BEGV (b),
1239 XMARKER (w->pointm)->charpos,
1240 BUF_ZV (b)),
1241 clip_to_bounds (BUF_BEGV_BYTE (b),
1242 marker_byte_position (w->pointm),
1243 BUF_ZV_BYTE (b)));
1245 if (WINDOWP (b->last_selected_window)
1246 && w == XWINDOW (b->last_selected_window))
1247 b->last_selected_window = Qnil;
1250 /* Put replacement into the window structure in place of old. */
1251 static void
1252 replace_window (old, replacement)
1253 Lisp_Object old, replacement;
1255 register Lisp_Object tem;
1256 register struct window *o = XWINDOW (old), *p = XWINDOW (replacement);
1258 /* If OLD is its frame's root_window, then replacement is the new
1259 root_window for that frame. */
1261 if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame))))
1262 FRAME_ROOT_WINDOW (XFRAME (o->frame)) = replacement;
1264 p->left_col = o->left_col;
1265 p->top_line = o->top_line;
1266 p->total_cols = o->total_cols;
1267 p->total_lines = o->total_lines;
1268 p->desired_matrix = p->current_matrix = 0;
1269 p->vscroll = 0;
1270 bzero (&p->cursor, sizeof (p->cursor));
1271 bzero (&p->last_cursor, sizeof (p->last_cursor));
1272 bzero (&p->phys_cursor, sizeof (p->phys_cursor));
1273 p->phys_cursor_type = -1;
1274 p->phys_cursor_width = -1;
1275 p->must_be_updated_p = 0;
1276 p->pseudo_window_p = 0;
1277 XSETFASTINT (p->window_end_vpos, 0);
1278 XSETFASTINT (p->window_end_pos, 0);
1279 p->window_end_valid = Qnil;
1280 p->frozen_window_start_p = 0;
1281 p->orig_top_line = p->orig_total_lines = Qnil;
1283 p->next = tem = o->next;
1284 if (!NILP (tem))
1285 XWINDOW (tem)->prev = replacement;
1287 p->prev = tem = o->prev;
1288 if (!NILP (tem))
1289 XWINDOW (tem)->next = replacement;
1291 p->parent = tem = o->parent;
1292 if (!NILP (tem))
1294 if (EQ (XWINDOW (tem)->vchild, old))
1295 XWINDOW (tem)->vchild = replacement;
1296 if (EQ (XWINDOW (tem)->hchild, old))
1297 XWINDOW (tem)->hchild = replacement;
1300 /*** Here, if replacement is a vertical combination
1301 and so is its new parent, we should make replacement's
1302 children be children of that parent instead. ***/
1305 DEFUN ("delete-window", Fdelete_window, Sdelete_window, 0, 1, "",
1306 doc: /* Remove WINDOW from the display. Default is selected window. */)
1307 (window)
1308 register Lisp_Object window;
1310 delete_window (window);
1312 if (! NILP (Vwindow_configuration_change_hook)
1313 && ! NILP (Vrun_hooks))
1314 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
1316 return Qnil;
1319 void
1320 delete_window (window)
1321 register Lisp_Object window;
1323 register Lisp_Object tem, parent, sib;
1324 register struct window *p;
1325 register struct window *par;
1326 struct frame *f;
1328 /* Because this function is called by other C code on non-leaf
1329 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1330 so we can't decode_window here. */
1331 if (NILP (window))
1332 window = selected_window;
1333 else
1334 CHECK_WINDOW (window);
1335 p = XWINDOW (window);
1337 /* It's okay to delete an already-deleted window. */
1338 if (NILP (p->buffer)
1339 && NILP (p->hchild)
1340 && NILP (p->vchild))
1341 return;
1343 parent = p->parent;
1344 if (NILP (parent))
1345 error ("Attempt to delete minibuffer or sole ordinary window");
1346 par = XWINDOW (parent);
1348 windows_or_buffers_changed++;
1349 Vwindow_list = Qnil;
1350 f = XFRAME (WINDOW_FRAME (p));
1351 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
1353 /* Are we trying to delete any frame's selected window? */
1355 Lisp_Object swindow, pwindow;
1357 /* See if the frame's selected window is either WINDOW
1358 or any subwindow of it, by finding all that window's parents
1359 and comparing each one with WINDOW. */
1360 swindow = FRAME_SELECTED_WINDOW (f);
1362 while (1)
1364 pwindow = swindow;
1365 while (!NILP (pwindow))
1367 if (EQ (window, pwindow))
1368 break;
1369 pwindow = XWINDOW (pwindow)->parent;
1372 /* If the window being deleted is not a parent of SWINDOW,
1373 then SWINDOW is ok as the new selected window. */
1374 if (!EQ (window, pwindow))
1375 break;
1376 /* Otherwise, try another window for SWINDOW. */
1377 swindow = Fnext_window (swindow, Qlambda, Qnil);;
1379 /* If we get back to the frame's selected window,
1380 it means there was no acceptable alternative,
1381 so we cannot delete. */
1382 if (EQ (swindow, FRAME_SELECTED_WINDOW (f)))
1383 error ("Cannot delete window");
1386 /* If we need to change SWINDOW, do it. */
1387 if (! EQ (swindow, FRAME_SELECTED_WINDOW (f)))
1389 /* If we're about to delete the selected window on the
1390 selected frame, then we should use Fselect_window to select
1391 the new window. On the other hand, if we're about to
1392 delete the selected window on any other frame, we shouldn't do
1393 anything but set the frame's selected_window slot. */
1394 if (EQ (FRAME_SELECTED_WINDOW (f), selected_window))
1395 Fselect_window (swindow, Qnil);
1396 else
1397 FRAME_SELECTED_WINDOW (f) = swindow;
1401 tem = p->buffer;
1402 /* tem is null for dummy parent windows
1403 (which have inferiors but not any contents themselves) */
1404 if (!NILP (tem))
1406 unshow_buffer (p);
1407 unchain_marker (XMARKER (p->pointm));
1408 unchain_marker (XMARKER (p->start));
1411 /* Free window glyph matrices. It is sure that they are allocated
1412 again when ADJUST_GLYPHS is called. Block input so that expose
1413 events and other events that access glyph matrices are not
1414 processed while we are changing them. */
1415 BLOCK_INPUT;
1416 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f)));
1418 tem = p->next;
1419 if (!NILP (tem))
1420 XWINDOW (tem)->prev = p->prev;
1422 tem = p->prev;
1423 if (!NILP (tem))
1424 XWINDOW (tem)->next = p->next;
1426 if (EQ (window, par->hchild))
1427 par->hchild = p->next;
1428 if (EQ (window, par->vchild))
1429 par->vchild = p->next;
1431 /* Find one of our siblings to give our space to. */
1432 sib = p->prev;
1433 if (NILP (sib))
1435 /* If p gives its space to its next sibling, that sibling needs
1436 to have its top/left side pulled back to where p's is.
1437 set_window_{height,width} will re-position the sibling's
1438 children. */
1439 sib = p->next;
1440 XWINDOW (sib)->top_line = p->top_line;
1441 XWINDOW (sib)->left_col = p->left_col;
1444 /* Stretch that sibling. */
1445 if (!NILP (par->vchild))
1446 set_window_height (sib,
1447 XFASTINT (XWINDOW (sib)->total_lines) + XFASTINT (p->total_lines),
1449 if (!NILP (par->hchild))
1450 set_window_width (sib,
1451 XFASTINT (XWINDOW (sib)->total_cols) + XFASTINT (p->total_cols),
1454 /* If parent now has only one child,
1455 put the child into the parent's place. */
1456 tem = par->hchild;
1457 if (NILP (tem))
1458 tem = par->vchild;
1459 if (NILP (XWINDOW (tem)->next))
1460 replace_window (parent, tem);
1462 /* Since we may be deleting combination windows, we must make sure that
1463 not only p but all its children have been marked as deleted. */
1464 if (! NILP (p->hchild))
1465 delete_all_subwindows (XWINDOW (p->hchild));
1466 else if (! NILP (p->vchild))
1467 delete_all_subwindows (XWINDOW (p->vchild));
1469 /* Mark this window as deleted. */
1470 p->buffer = p->hchild = p->vchild = Qnil;
1472 /* Adjust glyph matrices. */
1473 adjust_glyphs (f);
1474 UNBLOCK_INPUT;
1479 /***********************************************************************
1480 Window List
1481 ***********************************************************************/
1483 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1484 pointer. This is a callback function for foreach_window, used in
1485 function window_list. */
1487 static int
1488 add_window_to_list (w, user_data)
1489 struct window *w;
1490 void *user_data;
1492 Lisp_Object *list = (Lisp_Object *) user_data;
1493 Lisp_Object window;
1494 XSETWINDOW (window, w);
1495 *list = Fcons (window, *list);
1496 return 1;
1500 /* Return a list of all windows, for use by next_window. If
1501 Vwindow_list is a list, return that list. Otherwise, build a new
1502 list, cache it in Vwindow_list, and return that. */
1504 static Lisp_Object
1505 window_list ()
1507 if (!CONSP (Vwindow_list))
1509 Lisp_Object tail;
1511 Vwindow_list = Qnil;
1512 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1514 Lisp_Object args[2];
1516 /* We are visiting windows in canonical order, and add
1517 new windows at the front of args[1], which means we
1518 have to reverse this list at the end. */
1519 args[1] = Qnil;
1520 foreach_window (XFRAME (XCAR (tail)), add_window_to_list, &args[1]);
1521 args[0] = Vwindow_list;
1522 args[1] = Fnreverse (args[1]);
1523 Vwindow_list = Fnconc (2, args);
1527 return Vwindow_list;
1531 /* Value is non-zero if WINDOW satisfies the constraints given by
1532 OWINDOW, MINIBUF and ALL_FRAMES.
1534 MINIBUF t means WINDOW may be minibuffer windows.
1535 `lambda' means WINDOW may not be a minibuffer window.
1536 a window means a specific minibuffer window
1538 ALL_FRAMES t means search all frames,
1539 nil means search just current frame,
1540 `visible' means search just visible frames,
1541 0 means search visible and iconified frames,
1542 a window means search the frame that window belongs to,
1543 a frame means consider windows on that frame, only. */
1545 static int
1546 candidate_window_p (window, owindow, minibuf, all_frames)
1547 Lisp_Object window, owindow, minibuf, all_frames;
1549 struct window *w = XWINDOW (window);
1550 struct frame *f = XFRAME (w->frame);
1551 int candidate_p = 1;
1553 if (!BUFFERP (w->buffer))
1554 candidate_p = 0;
1555 else if (MINI_WINDOW_P (w)
1556 && (EQ (minibuf, Qlambda)
1557 || (WINDOWP (minibuf) && !EQ (minibuf, window))))
1559 /* If MINIBUF is `lambda' don't consider any mini-windows.
1560 If it is a window, consider only that one. */
1561 candidate_p = 0;
1563 else if (EQ (all_frames, Qt))
1564 candidate_p = 1;
1565 else if (NILP (all_frames))
1567 xassert (WINDOWP (owindow));
1568 candidate_p = EQ (w->frame, XWINDOW (owindow)->frame);
1570 else if (EQ (all_frames, Qvisible))
1572 FRAME_SAMPLE_VISIBILITY (f);
1573 candidate_p = FRAME_VISIBLE_P (f);
1575 else if (INTEGERP (all_frames) && XINT (all_frames) == 0)
1577 FRAME_SAMPLE_VISIBILITY (f);
1578 candidate_p = FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f);
1580 else if (WINDOWP (all_frames))
1581 candidate_p = (EQ (FRAME_MINIBUF_WINDOW (f), all_frames)
1582 || EQ (XWINDOW (all_frames)->frame, w->frame)
1583 || EQ (XWINDOW (all_frames)->frame, FRAME_FOCUS_FRAME (f)));
1584 else if (FRAMEP (all_frames))
1585 candidate_p = EQ (all_frames, w->frame);
1587 return candidate_p;
1591 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1592 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1593 ALL_FRAMES. */
1595 static void
1596 decode_next_window_args (window, minibuf, all_frames)
1597 Lisp_Object *window, *minibuf, *all_frames;
1599 if (NILP (*window))
1600 *window = selected_window;
1601 else
1602 CHECK_LIVE_WINDOW (*window);
1604 /* MINIBUF nil may or may not include minibuffers. Decide if it
1605 does. */
1606 if (NILP (*minibuf))
1607 *minibuf = minibuf_level ? minibuf_window : Qlambda;
1608 else if (!EQ (*minibuf, Qt))
1609 *minibuf = Qlambda;
1611 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1612 => count none of them, or a specific minibuffer window (the
1613 active one) to count. */
1615 /* ALL_FRAMES nil doesn't specify which frames to include. */
1616 if (NILP (*all_frames))
1617 *all_frames = (!EQ (*minibuf, Qlambda)
1618 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window)->frame))
1619 : Qnil);
1620 else if (EQ (*all_frames, Qvisible))
1622 else if (EQ (*all_frames, make_number (0)))
1624 else if (FRAMEP (*all_frames))
1626 else if (!EQ (*all_frames, Qt))
1627 *all_frames = Qnil;
1629 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1630 search just current frame, `visible' meaning search just visible
1631 frames, 0 meaning search visible and iconified frames, or a
1632 window, meaning search the frame that window belongs to, or a
1633 frame, meaning consider windows on that frame, only. */
1637 /* Return the next or previous window of WINDOW in canonical ordering
1638 of windows. NEXT_P non-zero means return the next window. See the
1639 documentation string of next-window for the meaning of MINIBUF and
1640 ALL_FRAMES. */
1642 static Lisp_Object
1643 next_window (window, minibuf, all_frames, next_p)
1644 Lisp_Object window, minibuf, all_frames;
1645 int next_p;
1647 decode_next_window_args (&window, &minibuf, &all_frames);
1649 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1650 return the first window on the frame. */
1651 if (FRAMEP (all_frames)
1652 && !EQ (all_frames, XWINDOW (window)->frame))
1653 return Fframe_first_window (all_frames);
1655 if (next_p)
1657 Lisp_Object list;
1659 /* Find WINDOW in the list of all windows. */
1660 list = Fmemq (window, window_list ());
1662 /* Scan forward from WINDOW to the end of the window list. */
1663 if (CONSP (list))
1664 for (list = XCDR (list); CONSP (list); list = XCDR (list))
1665 if (candidate_window_p (XCAR (list), window, minibuf, all_frames))
1666 break;
1668 /* Scan from the start of the window list up to WINDOW. */
1669 if (!CONSP (list))
1670 for (list = Vwindow_list;
1671 CONSP (list) && !EQ (XCAR (list), window);
1672 list = XCDR (list))
1673 if (candidate_window_p (XCAR (list), window, minibuf, all_frames))
1674 break;
1676 if (CONSP (list))
1677 window = XCAR (list);
1679 else
1681 Lisp_Object candidate, list;
1683 /* Scan through the list of windows for candidates. If there are
1684 candidate windows in front of WINDOW, the last one of these
1685 is the one we want. If there are candidates following WINDOW
1686 in the list, again the last one of these is the one we want. */
1687 candidate = Qnil;
1688 for (list = window_list (); CONSP (list); list = XCDR (list))
1690 if (EQ (XCAR (list), window))
1692 if (WINDOWP (candidate))
1693 break;
1695 else if (candidate_window_p (XCAR (list), window, minibuf,
1696 all_frames))
1697 candidate = XCAR (list);
1700 if (WINDOWP (candidate))
1701 window = candidate;
1704 return window;
1708 DEFUN ("next-window", Fnext_window, Snext_window, 0, 3, 0,
1709 doc: /* Return next window after WINDOW in canonical ordering of windows.
1710 If omitted, WINDOW defaults to the selected window.
1712 Optional second arg MINIBUF t means count the minibuffer window even
1713 if not active. MINIBUF nil or omitted means count the minibuffer iff
1714 it is active. MINIBUF neither t nor nil means not to count the
1715 minibuffer even if it is active.
1717 Several frames may share a single minibuffer; if the minibuffer
1718 counts, all windows on all frames that share that minibuffer count
1719 too. Therefore, `next-window' can be used to iterate through the
1720 set of windows even when the minibuffer is on another frame. If the
1721 minibuffer does not count, only windows from WINDOW's frame count.
1723 Optional third arg ALL-FRAMES t means include windows on all frames.
1724 ALL-FRAMES nil or omitted means cycle within the frames as specified
1725 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1726 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1727 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1728 Anything else means restrict to WINDOW's frame.
1730 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1731 `next-window' to iterate through the entire cycle of acceptable
1732 windows, eventually ending up back at the window you started with.
1733 `previous-window' traverses the same cycle, in the reverse order. */)
1734 (window, minibuf, all_frames)
1735 Lisp_Object window, minibuf, all_frames;
1737 return next_window (window, minibuf, all_frames, 1);
1741 DEFUN ("previous-window", Fprevious_window, Sprevious_window, 0, 3, 0,
1742 doc: /* Return the window preceding WINDOW in canonical ordering of windows.
1743 If omitted, WINDOW defaults to the selected window.
1745 Optional second arg MINIBUF t means count the minibuffer window even
1746 if not active. MINIBUF nil or omitted means count the minibuffer iff
1747 it is active. MINIBUF neither t nor nil means not to count the
1748 minibuffer even if it is active.
1750 Several frames may share a single minibuffer; if the minibuffer
1751 counts, all windows on all frames that share that minibuffer count
1752 too. Therefore, `previous-window' can be used to iterate through
1753 the set of windows even when the minibuffer is on another frame. If
1754 the minibuffer does not count, only windows from WINDOW's frame count
1756 Optional third arg ALL-FRAMES t means include windows on all frames.
1757 ALL-FRAMES nil or omitted means cycle within the frames as specified
1758 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1759 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1760 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1761 Anything else means restrict to WINDOW's frame.
1763 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1764 `previous-window' to iterate through the entire cycle of acceptable
1765 windows, eventually ending up back at the window you started with.
1766 `next-window' traverses the same cycle, in the reverse order. */)
1767 (window, minibuf, all_frames)
1768 Lisp_Object window, minibuf, all_frames;
1770 return next_window (window, minibuf, all_frames, 0);
1774 DEFUN ("other-window", Fother_window, Sother_window, 1, 2, "p",
1775 doc: /* Select the ARG'th different window on this frame.
1776 All windows on current frame are arranged in a cyclic order.
1777 This command selects the window ARG steps away in that order.
1778 A negative ARG moves in the opposite order. The optional second
1779 argument ALL_FRAMES has the same meaning as in `next-window', which see. */)
1780 (arg, all_frames)
1781 Lisp_Object arg, all_frames;
1783 Lisp_Object window;
1784 int i;
1786 CHECK_NUMBER (arg);
1787 window = selected_window;
1789 for (i = XINT (arg); i > 0; --i)
1790 window = Fnext_window (window, Qnil, all_frames);
1791 for (; i < 0; ++i)
1792 window = Fprevious_window (window, Qnil, all_frames);
1794 Fselect_window (window, Qnil);
1795 return Qnil;
1799 DEFUN ("window-list", Fwindow_list, Swindow_list, 0, 3, 0,
1800 doc: /* Return a list of windows on FRAME, starting with WINDOW.
1801 FRAME nil or omitted means use the selected frame.
1802 WINDOW nil or omitted means use the selected window.
1803 MINIBUF t means include the minibuffer window, even if it isn't active.
1804 MINIBUF nil or omitted means include the minibuffer window only
1805 if it's active.
1806 MINIBUF neither nil nor t means never include the minibuffer window. */)
1807 (frame, minibuf, window)
1808 Lisp_Object frame, minibuf, window;
1810 if (NILP (window))
1811 window = selected_window;
1812 if (NILP (frame))
1813 frame = selected_frame;
1815 if (!EQ (frame, XWINDOW (window)->frame))
1816 error ("Window is on a different frame");
1818 return window_list_1 (window, minibuf, frame);
1822 /* Return a list of windows in canonical ordering. Arguments are like
1823 for `next-window'. */
1825 static Lisp_Object
1826 window_list_1 (window, minibuf, all_frames)
1827 Lisp_Object window, minibuf, all_frames;
1829 Lisp_Object tail, list, rest;
1831 decode_next_window_args (&window, &minibuf, &all_frames);
1832 list = Qnil;
1834 for (tail = window_list (); CONSP (tail); tail = XCDR (tail))
1835 if (candidate_window_p (XCAR (tail), window, minibuf, all_frames))
1836 list = Fcons (XCAR (tail), list);
1838 /* Rotate the list to start with WINDOW. */
1839 list = Fnreverse (list);
1840 rest = Fmemq (window, list);
1841 if (!NILP (rest) && !EQ (rest, list))
1843 for (tail = list; !EQ (XCDR (tail), rest); tail = XCDR (tail))
1845 XSETCDR (tail, Qnil);
1846 list = nconc2 (rest, list);
1848 return list;
1853 /* Look at all windows, performing an operation specified by TYPE
1854 with argument OBJ.
1855 If FRAMES is Qt, look at all frames;
1856 Qnil, look at just the selected frame;
1857 Qvisible, look at visible frames;
1858 a frame, just look at windows on that frame.
1859 If MINI is non-zero, perform the operation on minibuffer windows too. */
1861 enum window_loop
1863 WINDOW_LOOP_UNUSED,
1864 GET_BUFFER_WINDOW, /* Arg is buffer */
1865 GET_LRU_WINDOW, /* Arg is t for full-width windows only */
1866 DELETE_OTHER_WINDOWS, /* Arg is window not to delete */
1867 DELETE_BUFFER_WINDOWS, /* Arg is buffer */
1868 GET_LARGEST_WINDOW,
1869 UNSHOW_BUFFER, /* Arg is buffer */
1870 REDISPLAY_BUFFER_WINDOWS, /* Arg is buffer */
1871 CHECK_ALL_WINDOWS
1874 static Lisp_Object
1875 window_loop (type, obj, mini, frames)
1876 enum window_loop type;
1877 Lisp_Object obj, frames;
1878 int mini;
1880 Lisp_Object window, windows, best_window, frame_arg;
1881 struct frame *f;
1882 struct gcpro gcpro1;
1884 /* If we're only looping through windows on a particular frame,
1885 frame points to that frame. If we're looping through windows
1886 on all frames, frame is 0. */
1887 if (FRAMEP (frames))
1888 f = XFRAME (frames);
1889 else if (NILP (frames))
1890 f = SELECTED_FRAME ();
1891 else
1892 f = NULL;
1894 if (f)
1895 frame_arg = Qlambda;
1896 else if (EQ (frames, make_number (0)))
1897 frame_arg = frames;
1898 else if (EQ (frames, Qvisible))
1899 frame_arg = frames;
1900 else
1901 frame_arg = Qt;
1903 /* frame_arg is Qlambda to stick to one frame,
1904 Qvisible to consider all visible frames,
1905 or Qt otherwise. */
1907 /* Pick a window to start with. */
1908 if (WINDOWP (obj))
1909 window = obj;
1910 else if (f)
1911 window = FRAME_SELECTED_WINDOW (f);
1912 else
1913 window = FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
1915 windows = window_list_1 (window, mini ? Qt : Qnil, frame_arg);
1916 GCPRO1 (windows);
1917 best_window = Qnil;
1919 for (; CONSP (windows); windows = CDR (windows))
1921 struct window *w;
1923 window = XCAR (windows);
1924 w = XWINDOW (window);
1926 /* Note that we do not pay attention here to whether the frame
1927 is visible, since Fwindow_list skips non-visible frames if
1928 that is desired, under the control of frame_arg. */
1929 if (!MINI_WINDOW_P (w)
1930 /* For UNSHOW_BUFFER, we must always consider all windows. */
1931 || type == UNSHOW_BUFFER
1932 || (mini && minibuf_level > 0))
1933 switch (type)
1935 case GET_BUFFER_WINDOW:
1936 if (EQ (w->buffer, obj)
1937 /* Don't find any minibuffer window
1938 except the one that is currently in use. */
1939 && (MINI_WINDOW_P (w)
1940 ? EQ (window, minibuf_window)
1941 : 1))
1943 if (NILP (best_window))
1944 best_window = window;
1945 else if (EQ (window, selected_window))
1946 /* For compatibility with 20.x, prefer to return
1947 selected-window. */
1948 best_window = window;
1950 break;
1952 case GET_LRU_WINDOW:
1953 /* t as arg means consider only full-width windows */
1954 if (!NILP (obj) && !WINDOW_FULL_WIDTH_P (w))
1955 break;
1956 /* Ignore dedicated windows and minibuffers. */
1957 if (MINI_WINDOW_P (w) || EQ (w->dedicated, Qt))
1958 break;
1959 if (NILP (best_window)
1960 || (XFASTINT (XWINDOW (best_window)->use_time)
1961 > XFASTINT (w->use_time)))
1962 best_window = window;
1963 break;
1965 case DELETE_OTHER_WINDOWS:
1966 if (!EQ (window, obj))
1967 Fdelete_window (window);
1968 break;
1970 case DELETE_BUFFER_WINDOWS:
1971 if (EQ (w->buffer, obj))
1973 struct frame *f = XFRAME (WINDOW_FRAME (w));
1975 /* If this window is dedicated, and in a frame of its own,
1976 kill the frame. */
1977 if (EQ (window, FRAME_ROOT_WINDOW (f))
1978 && !NILP (w->dedicated)
1979 && other_visible_frames (f))
1981 /* Skip the other windows on this frame.
1982 There might be one, the minibuffer! */
1983 while (CONSP (XCDR (windows))
1984 && EQ (XWINDOW (XCAR (windows))->frame,
1985 XWINDOW (XCAR (XCDR (windows)))->frame))
1986 windows = XCDR (windows);
1988 /* Now we can safely delete the frame. */
1989 Fdelete_frame (w->frame, Qnil);
1991 else if (NILP (w->parent))
1993 /* If we're deleting the buffer displayed in the
1994 only window on the frame, find a new buffer to
1995 display there. */
1996 Lisp_Object buffer;
1997 buffer = Fother_buffer (obj, Qnil, w->frame);
1998 Fset_window_buffer (window, buffer, Qnil);
1999 if (EQ (window, selected_window))
2000 Fset_buffer (w->buffer);
2002 else
2003 Fdelete_window (window);
2005 break;
2007 case GET_LARGEST_WINDOW:
2009 /* Ignore dedicated windows and minibuffers. */
2010 if (MINI_WINDOW_P (w) || EQ (w->dedicated, Qt))
2011 break;
2013 if (NILP (best_window))
2014 best_window = window;
2015 else
2017 struct window *b = XWINDOW (best_window);
2018 if (XFASTINT (w->total_lines) * XFASTINT (w->total_cols)
2019 > XFASTINT (b->total_lines) * XFASTINT (b->total_cols))
2020 best_window = window;
2023 break;
2025 case UNSHOW_BUFFER:
2026 if (EQ (w->buffer, obj))
2028 Lisp_Object buffer;
2029 struct frame *f = XFRAME (w->frame);
2031 /* Find another buffer to show in this window. */
2032 buffer = Fother_buffer (obj, Qnil, w->frame);
2034 /* If this window is dedicated, and in a frame of its own,
2035 kill the frame. */
2036 if (EQ (window, FRAME_ROOT_WINDOW (f))
2037 && !NILP (w->dedicated)
2038 && other_visible_frames (f))
2040 /* Skip the other windows on this frame.
2041 There might be one, the minibuffer! */
2042 while (CONSP (XCDR (windows))
2043 && EQ (XWINDOW (XCAR (windows))->frame,
2044 XWINDOW (XCAR (XCDR (windows)))->frame))
2045 windows = XCDR (windows);
2047 /* Now we can safely delete the frame. */
2048 Fdelete_frame (w->frame, Qnil);
2050 else if (!NILP (w->dedicated) && !NILP (w->parent))
2052 Lisp_Object window;
2053 XSETWINDOW (window, w);
2054 /* If this window is dedicated and not the only window
2055 in its frame, then kill it. */
2056 Fdelete_window (window);
2058 else
2060 /* Otherwise show a different buffer in the window. */
2061 w->dedicated = Qnil;
2062 Fset_window_buffer (window, buffer, Qnil);
2063 if (EQ (window, selected_window))
2064 Fset_buffer (w->buffer);
2067 break;
2069 case REDISPLAY_BUFFER_WINDOWS:
2070 if (EQ (w->buffer, obj))
2072 mark_window_display_accurate (window, 0);
2073 w->update_mode_line = Qt;
2074 XBUFFER (obj)->prevent_redisplay_optimizations_p = 1;
2075 ++update_mode_lines;
2076 best_window = window;
2078 break;
2080 /* Check for a window that has a killed buffer. */
2081 case CHECK_ALL_WINDOWS:
2082 if (! NILP (w->buffer)
2083 && NILP (XBUFFER (w->buffer)->name))
2084 abort ();
2085 break;
2087 case WINDOW_LOOP_UNUSED:
2088 break;
2092 UNGCPRO;
2093 return best_window;
2096 /* Used for debugging. Abort if any window has a dead buffer. */
2098 void
2099 check_all_windows ()
2101 window_loop (CHECK_ALL_WINDOWS, Qnil, 1, Qt);
2104 DEFUN ("get-lru-window", Fget_lru_window, Sget_lru_window, 0, 1, 0,
2105 doc: /* Return the window least recently selected or used for display.
2106 Return a full-width window if possible.
2107 A minibuffer window is never a candidate.
2108 A dedicated window is never a candidate, so if all windows are dedicated,
2109 the value is nil.
2110 If optional argument FRAME is `visible', search all visible frames.
2111 If FRAME is 0, search all visible and iconified frames.
2112 If FRAME is t, search all frames.
2113 If FRAME is nil, search only the selected frame.
2114 If FRAME is a frame, search only that frame. */)
2115 (frame)
2116 Lisp_Object frame;
2118 register Lisp_Object w;
2119 /* First try for a window that is full-width */
2120 w = window_loop (GET_LRU_WINDOW, Qt, 0, frame);
2121 if (!NILP (w) && !EQ (w, selected_window))
2122 return w;
2123 /* If none of them, try the rest */
2124 return window_loop (GET_LRU_WINDOW, Qnil, 0, frame);
2127 DEFUN ("get-largest-window", Fget_largest_window, Sget_largest_window, 0, 1, 0,
2128 doc: /* Return the largest window in area.
2129 A minibuffer window is never a candidate.
2130 A dedicated window is never a candidate, so if all windows are dedicated,
2131 the value is nil.
2132 If optional argument FRAME is `visible', search all visible frames.
2133 If FRAME is 0, search all visible and iconified frames.
2134 If FRAME is t, search all frames.
2135 If FRAME is nil, search only the selected frame.
2136 If FRAME is a frame, search only that frame. */)
2137 (frame)
2138 Lisp_Object frame;
2140 return window_loop (GET_LARGEST_WINDOW, Qnil, 0,
2141 frame);
2144 DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 1, 2, 0,
2145 doc: /* Return a window currently displaying BUFFER, or nil if none.
2146 BUFFER can be a buffer or a buffer name.
2147 If optional argument FRAME is `visible', search all visible frames.
2148 If optional argument FRAME is 0, search all visible and iconified frames.
2149 If FRAME is t, search all frames.
2150 If FRAME is nil, search only the selected frame.
2151 If FRAME is a frame, search only that frame. */)
2152 (buffer, frame)
2153 Lisp_Object buffer, frame;
2155 buffer = Fget_buffer (buffer);
2156 if (BUFFERP (buffer))
2157 return window_loop (GET_BUFFER_WINDOW, buffer, 1, frame);
2158 else
2159 return Qnil;
2162 DEFUN ("delete-other-windows", Fdelete_other_windows, Sdelete_other_windows,
2163 0, 1, "",
2164 doc: /* Make WINDOW (or the selected window) fill its frame.
2165 Only the frame WINDOW is on is affected.
2166 This function tries to reduce display jumps
2167 by keeping the text previously visible in WINDOW
2168 in the same place on the frame. Doing this depends on
2169 the value of (window-start WINDOW), so if calling this function
2170 in a program gives strange scrolling, make sure the window-start
2171 value is reasonable when this function is called. */)
2172 (window)
2173 Lisp_Object window;
2175 struct window *w;
2176 int startpos;
2177 int top, new_top;
2179 if (NILP (window))
2180 window = selected_window;
2181 else
2182 CHECK_LIVE_WINDOW (window);
2183 w = XWINDOW (window);
2185 startpos = marker_position (w->start);
2186 top = WINDOW_TOP_EDGE_LINE (w) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w)));
2188 if (MINI_WINDOW_P (w) && top > 0)
2189 error ("Can't expand minibuffer to full frame");
2191 window_loop (DELETE_OTHER_WINDOWS, window, 0, WINDOW_FRAME (w));
2193 /* Try to minimize scrolling, by setting the window start to the point
2194 will cause the text at the old window start to be at the same place
2195 on the frame. But don't try to do this if the window start is
2196 outside the visible portion (as might happen when the display is
2197 not current, due to typeahead). */
2198 new_top = WINDOW_TOP_EDGE_LINE (w) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w)));
2199 if (new_top != top
2200 && startpos >= BUF_BEGV (XBUFFER (w->buffer))
2201 && startpos <= BUF_ZV (XBUFFER (w->buffer)))
2203 struct position pos;
2204 struct buffer *obuf = current_buffer;
2206 Fset_buffer (w->buffer);
2207 /* This computation used to temporarily move point, but that can
2208 have unwanted side effects due to text properties. */
2209 pos = *vmotion (startpos, -top, w);
2211 set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos);
2212 w->window_end_valid = Qnil;
2213 w->start_at_line_beg = ((pos.bytepos == BEGV_BYTE
2214 || FETCH_BYTE (pos.bytepos - 1) == '\n') ? Qt
2215 : Qnil);
2216 /* We need to do this, so that the window-scroll-functions
2217 get called. */
2218 w->optional_new_start = Qt;
2220 set_buffer_internal (obuf);
2223 return Qnil;
2226 DEFUN ("delete-windows-on", Fdelete_windows_on, Sdelete_windows_on,
2227 1, 2, "bDelete windows on (buffer): ",
2228 doc: /* Delete all windows showing BUFFER.
2229 BUFFER must be a buffer or the name of an existing buffer.
2230 Optional second argument FRAME controls which frames are affected.
2231 If optional argument FRAME is `visible', search all visible frames.
2232 If FRAME is 0, search all visible and iconified frames.
2233 If FRAME is nil, search all frames.
2234 If FRAME is t, search only the selected frame.
2235 If FRAME is a frame, search only that frame. */)
2236 (buffer, frame)
2237 Lisp_Object buffer, frame;
2239 /* FRAME uses t and nil to mean the opposite of what window_loop
2240 expects. */
2241 if (NILP (frame))
2242 frame = Qt;
2243 else if (EQ (frame, Qt))
2244 frame = Qnil;
2246 if (!NILP (buffer))
2248 buffer = Fget_buffer (buffer);
2249 CHECK_BUFFER (buffer);
2250 window_loop (DELETE_BUFFER_WINDOWS, buffer, 0, frame);
2253 return Qnil;
2256 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows,
2257 Sreplace_buffer_in_windows,
2258 1, 1, "bReplace buffer in windows: ",
2259 doc: /* Replace BUFFER with some other buffer in all windows showing it.
2260 BUFFER may be a buffer or the name of an existing buffer. */)
2261 (buffer)
2262 Lisp_Object buffer;
2264 if (!NILP (buffer))
2266 buffer = Fget_buffer (buffer);
2267 CHECK_BUFFER (buffer);
2268 window_loop (UNSHOW_BUFFER, buffer, 0, Qt);
2270 return Qnil;
2273 /* Replace BUFFER with some other buffer in all windows
2274 of all frames, even those on other keyboards. */
2276 void
2277 replace_buffer_in_all_windows (buffer)
2278 Lisp_Object buffer;
2280 #ifdef MULTI_KBOARD
2281 Lisp_Object tail, frame;
2283 /* A single call to window_loop won't do the job
2284 because it only considers frames on the current keyboard.
2285 So loop manually over frames, and handle each one. */
2286 FOR_EACH_FRAME (tail, frame)
2287 window_loop (UNSHOW_BUFFER, buffer, 1, frame);
2288 #else
2289 window_loop (UNSHOW_BUFFER, buffer, 1, Qt);
2290 #endif
2293 /* Set the height of WINDOW and all its inferiors. */
2295 /* The smallest acceptable dimensions for a window. Anything smaller
2296 might crash Emacs. */
2298 #define MIN_SAFE_WINDOW_WIDTH (2)
2299 #define MIN_SAFE_WINDOW_HEIGHT (1)
2301 /* Make sure that window_min_height and window_min_width are
2302 not too small; if they are, set them to safe minima. */
2304 static void
2305 check_min_window_sizes ()
2307 /* Smaller values might permit a crash. */
2308 if (window_min_width < MIN_SAFE_WINDOW_WIDTH)
2309 window_min_width = MIN_SAFE_WINDOW_WIDTH;
2310 if (window_min_height < MIN_SAFE_WINDOW_HEIGHT)
2311 window_min_height = MIN_SAFE_WINDOW_HEIGHT;
2314 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2315 minimum allowable size. */
2317 void
2318 check_frame_size (frame, rows, cols)
2319 FRAME_PTR frame;
2320 int *rows, *cols;
2322 /* For height, we have to see:
2323 how many windows the frame has at minimum (one or two),
2324 and whether it has a menu bar or other special stuff at the top. */
2325 int min_height
2326 = ((FRAME_MINIBUF_ONLY_P (frame) || ! FRAME_HAS_MINIBUF_P (frame))
2327 ? MIN_SAFE_WINDOW_HEIGHT
2328 : 2 * MIN_SAFE_WINDOW_HEIGHT);
2330 if (FRAME_TOP_MARGIN (frame) > 0)
2331 min_height += FRAME_TOP_MARGIN (frame);
2333 if (*rows < min_height)
2334 *rows = min_height;
2335 if (*cols < MIN_SAFE_WINDOW_WIDTH)
2336 *cols = MIN_SAFE_WINDOW_WIDTH;
2340 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2341 check if W's width can be changed, otherwise check W's height.
2342 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2343 siblings, too. If none of the siblings is resizable, WINDOW isn't
2344 either. */
2346 static int
2347 window_fixed_size_p (w, width_p, check_siblings_p)
2348 struct window *w;
2349 int width_p, check_siblings_p;
2351 int fixed_p;
2352 struct window *c;
2354 if (!NILP (w->hchild))
2356 c = XWINDOW (w->hchild);
2358 if (width_p)
2360 /* A horiz. combination is fixed-width if all of if its
2361 children are. */
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;
2366 else
2368 /* A horiz. combination is fixed-height if one of if its
2369 children is. */
2370 while (c && !window_fixed_size_p (c, width_p, 0))
2371 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2372 fixed_p = c != NULL;
2375 else if (!NILP (w->vchild))
2377 c = XWINDOW (w->vchild);
2379 if (width_p)
2381 /* A vert. combination is fixed-width if one of if its
2382 children is. */
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;
2387 else
2389 /* A vert. combination is fixed-height if all of if its
2390 children are. */
2391 while (c && window_fixed_size_p (c, width_p, 0))
2392 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2393 fixed_p = c == NULL;
2396 else if (BUFFERP (w->buffer))
2398 if (w->height_fixed_p && !width_p)
2399 fixed_p = 1;
2400 else
2402 struct buffer *old = current_buffer;
2403 Lisp_Object val;
2405 current_buffer = XBUFFER (w->buffer);
2406 val = find_symbol_value (Qwindow_size_fixed);
2407 current_buffer = old;
2409 fixed_p = 0;
2410 if (!EQ (val, Qunbound))
2412 fixed_p = !NILP (val);
2414 if (fixed_p
2415 && ((EQ (val, Qheight) && width_p)
2416 || (EQ (val, Qwidth) && !width_p)))
2417 fixed_p = 0;
2421 /* Can't tell if this one is resizable without looking at
2422 siblings. If all siblings are fixed-size this one is too. */
2423 if (!fixed_p && check_siblings_p && WINDOWP (w->parent))
2425 Lisp_Object child;
2427 for (child = w->prev; !NILP (child); child = XWINDOW (child)->prev)
2428 if (!window_fixed_size_p (XWINDOW (child), width_p, 0))
2429 break;
2431 if (NILP (child))
2432 for (child = w->next; !NILP (child); child = XWINDOW (child)->next)
2433 if (!window_fixed_size_p (XWINDOW (child), width_p, 0))
2434 break;
2436 if (NILP (child))
2437 fixed_p = 1;
2440 else
2441 fixed_p = 1;
2443 return fixed_p;
2447 /* Return the minimum size of window W, not taking fixed-width windows
2448 into account. WIDTH_P non-zero means return the minimum width,
2449 otherwise return the minimum height. If W is a combination window,
2450 compute the minimum size from the minimum sizes of W's children. */
2452 static int
2453 window_min_size_1 (w, width_p)
2454 struct window *w;
2455 int width_p;
2457 struct window *c;
2458 int size;
2460 if (!NILP (w->hchild))
2462 c = XWINDOW (w->hchild);
2463 size = 0;
2465 if (width_p)
2467 /* The min width of a horizontal combination is
2468 the sum of the min widths of its children. */
2469 while (c)
2471 size += window_min_size_1 (c, width_p);
2472 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2475 else
2477 /* The min height a horizontal combination equals
2478 the maximum of all min height of its children. */
2479 while (c)
2481 int min_size = window_min_size_1 (c, width_p);
2482 size = max (min_size, size);
2483 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2487 else if (!NILP (w->vchild))
2489 c = XWINDOW (w->vchild);
2490 size = 0;
2492 if (width_p)
2494 /* The min width of a vertical combination is
2495 the maximum of the min widths of its children. */
2496 while (c)
2498 int min_size = window_min_size_1 (c, width_p);
2499 size = max (min_size, size);
2500 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2503 else
2505 /* The min height of a vertical combination equals
2506 the sum of the min height of its children. */
2507 while (c)
2509 size += window_min_size_1 (c, width_p);
2510 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2514 else
2516 if (width_p)
2517 size = window_min_width;
2518 else
2520 if (MINI_WINDOW_P (w)
2521 || (!WINDOW_WANTS_MODELINE_P (w)
2522 && !WINDOW_WANTS_HEADER_LINE_P (w)))
2523 size = 1;
2524 else
2525 size = window_min_height;
2529 return size;
2533 /* Return the minimum size of window W, taking fixed-size windows into
2534 account. WIDTH_P non-zero means return the minimum width,
2535 otherwise return the minimum height. IGNORE_FIXED_P non-zero means
2536 ignore if W is fixed-size. Set *FIXED to 1 if W is fixed-size
2537 unless FIXED is null. */
2539 static int
2540 window_min_size (w, width_p, ignore_fixed_p, fixed)
2541 struct window *w;
2542 int width_p, ignore_fixed_p, *fixed;
2544 int size, fixed_p;
2546 if (ignore_fixed_p)
2547 fixed_p = 0;
2548 else
2549 fixed_p = window_fixed_size_p (w, width_p, 1);
2551 if (fixed)
2552 *fixed = fixed_p;
2554 if (fixed_p)
2555 size = width_p ? XFASTINT (w->total_cols) : XFASTINT (w->total_lines);
2556 else
2557 size = window_min_size_1 (w, width_p);
2559 return size;
2563 /* Adjust the margins of window W if text area is too small.
2564 Return 1 if window width is ok after adjustment; 0 if window
2565 is still too narrow. */
2567 static int
2568 adjust_window_margins (w)
2569 struct window *w;
2571 int box_cols = (WINDOW_TOTAL_COLS (w)
2572 - WINDOW_FRINGE_COLS (w)
2573 - WINDOW_SCROLL_BAR_COLS (w));
2574 int margin_cols = (WINDOW_LEFT_MARGIN_COLS (w)
2575 + WINDOW_RIGHT_MARGIN_COLS (w));
2577 if (box_cols - margin_cols >= MIN_SAFE_WINDOW_WIDTH)
2578 return 1;
2580 if (margin_cols < 0 || box_cols < MIN_SAFE_WINDOW_WIDTH)
2581 return 0;
2583 /* Window's text area is too narrow, but reducing the window
2584 margins will fix that. */
2585 margin_cols = box_cols - MIN_SAFE_WINDOW_WIDTH;
2586 if (WINDOW_RIGHT_MARGIN_COLS (w) > 0)
2588 if (WINDOW_LEFT_MARGIN_COLS (w) > 0)
2589 w->left_margin_cols = w->right_margin_cols
2590 = make_number (margin_cols/2);
2591 else
2592 w->right_margin_cols = make_number (margin_cols);
2594 else
2595 w->left_margin_cols = make_number (margin_cols);
2596 return 1;
2599 /* Calculate new sizes for windows in the list FORWARD when the window size
2600 goes from TOTAL to SIZE. TOTAL must be greater than SIZE.
2601 The number of windows in FORWARD is NCHILDREN, and the number that
2602 can shrink is SHRINKABLE.
2603 The minimum size a window can have is MIN_SIZE.
2604 If we are shrinking fixed windows, RESIZE_FIXED_P is non-zero.
2605 If we are shrinking columns, WIDTH_P is non-zero, otherwise we are
2606 shrinking rows.
2608 This function returns an allocated array of new sizes that the caller
2609 must free. The size -1 means the window is fixed and RESIZE_FIXED_P
2610 is zero. Array index 0 refers to the first window in FORWARD, 1 to
2611 the second, and so on.
2613 This function tries to keep windows at least at the minimum size
2614 and resize other windows before it resizes any window to zero (i.e.
2615 delete that window).
2617 Windows are resized proportional to their size, so bigger windows
2618 shrink more than smaller windows. */
2619 static int *
2620 shrink_windows (total, size, nchildren, shrinkable,
2621 min_size, resize_fixed_p, forward, width_p)
2622 int total, size, nchildren, shrinkable, min_size;
2623 int resize_fixed_p, width_p;
2624 Lisp_Object forward;
2626 int available_resize = 0;
2627 int *new_sizes;
2628 struct window *c;
2629 Lisp_Object child;
2630 int smallest = total;
2631 int total_removed = 0;
2632 int total_shrink = total - size;
2633 int i;
2635 new_sizes = xmalloc (sizeof (*new_sizes) * nchildren);
2637 for (i = 0, child = forward; !NILP (child); child = c->next, ++i)
2639 int child_size;
2641 c = XWINDOW (child);
2642 child_size = width_p ? XINT (c->total_cols) : XINT (c->total_lines);
2644 if (! resize_fixed_p && window_fixed_size_p (c, width_p, 0))
2645 new_sizes[i] = -1;
2646 else
2648 new_sizes[i] = child_size;
2649 if (child_size > min_size)
2650 available_resize += child_size - min_size;
2653 /* We might need to shrink some windows to zero. Find the smallest
2654 windows and set them to 0 until we can fulfil the new size. */
2656 while (shrinkable > 1 && size + available_resize < total)
2658 for (i = 0; i < nchildren; ++i)
2659 if (new_sizes[i] > 0 && smallest > new_sizes[i])
2660 smallest = new_sizes[i];
2662 for (i = 0; i < nchildren; ++i)
2663 if (new_sizes[i] == smallest)
2665 /* Resize this window down to zero. */
2666 new_sizes[i] = 0;
2667 if (smallest > min_size)
2668 available_resize -= smallest - min_size;
2669 available_resize += smallest;
2670 --shrinkable;
2671 total_removed += smallest;
2673 /* We don't know what the smallest is now. */
2674 smallest = total;
2676 /* Out of for, just remove one window at the time and
2677 check again if we have enough space. */
2678 break;
2682 /* Now, calculate the new sizes. Try to shrink each window
2683 proportional to its size. */
2684 for (i = 0; i < nchildren; ++i)
2686 if (new_sizes[i] > min_size)
2688 int to_shrink = total_shrink*new_sizes[i]/total;
2689 if (new_sizes[i] - to_shrink < min_size)
2690 to_shrink = new_sizes[i] - min_size;
2691 new_sizes[i] -= to_shrink;
2692 total_removed += to_shrink;
2696 /* Any reminder due to rounding, we just subtract from windows
2697 that are left and still can be shrunk. */
2698 while (total_shrink > total_removed)
2700 int nonzero_sizes = 0;
2701 int nonzero_idx = -1;
2703 for (i = 0; i < nchildren; ++i)
2704 if (new_sizes[i] > 0)
2706 ++nonzero_sizes;
2707 nonzero_idx = i;
2710 for (i = 0; i < nchildren; ++i)
2711 if (new_sizes[i] > min_size)
2713 --new_sizes[i];
2714 ++total_removed;
2716 /* Out of for, just shrink one window at the time and
2717 check again if we have enough space. */
2718 break;
2722 /* Special case, only one window left. */
2723 if (nonzero_sizes == 1)
2724 break;
2727 /* Any surplus due to rounding, we add to windows that are left. */
2728 while (total_shrink < total_removed)
2730 for (i = 0; i < nchildren; ++i)
2732 if (new_sizes[i] != 0 && total_shrink < total_removed)
2734 ++new_sizes[i];
2735 --total_removed;
2736 break;
2741 return new_sizes;
2744 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
2745 WINDOW's width. Resize WINDOW's children, if any, so that they
2746 keep their proportionate size relative to WINDOW. Propagate
2747 WINDOW's top or left edge position to children. Delete windows
2748 that become too small unless NODELETE_P is non-zero.
2750 If NODELETE_P is 2, that means we do delete windows that are
2751 too small, even if they were too small before! */
2753 static void
2754 size_window (window, size, width_p, nodelete_p)
2755 Lisp_Object window;
2756 int size, width_p, nodelete_p;
2758 struct window *w = XWINDOW (window);
2759 struct window *c;
2760 Lisp_Object child, *forward, *sideward;
2761 int old_size, min_size, safe_min_size;
2763 /* We test nodelete_p != 2 and nodelete_p != 1 below, so it
2764 seems like it's too soon to do this here. ++KFS. */
2765 if (nodelete_p == 2)
2766 nodelete_p = 0;
2768 check_min_window_sizes ();
2769 size = max (0, size);
2771 /* If the window has been "too small" at one point,
2772 don't delete it for being "too small" in the future.
2773 Preserve it as long as that is at all possible. */
2774 if (width_p)
2776 old_size = WINDOW_TOTAL_COLS (w);
2777 min_size = window_min_width;
2778 /* Ensure that there is room for the scroll bar and fringes!
2779 We may reduce display margins though. */
2780 safe_min_size = (MIN_SAFE_WINDOW_WIDTH
2781 + WINDOW_FRINGE_COLS (w)
2782 + WINDOW_SCROLL_BAR_COLS (w));
2784 else
2786 old_size = XINT (w->total_lines);
2787 min_size = window_min_height;
2788 safe_min_size = MIN_SAFE_WINDOW_HEIGHT;
2791 if (old_size < min_size && nodelete_p != 2)
2792 w->too_small_ok = Qt;
2794 /* Maybe delete WINDOW if it's too small. */
2795 if (nodelete_p != 1 && !NILP (w->parent))
2797 if (!MINI_WINDOW_P (w) && !NILP (w->too_small_ok))
2798 min_size = width_p ? MIN_SAFE_WINDOW_WIDTH : MIN_SAFE_WINDOW_HEIGHT;
2799 if (min_size < safe_min_size)
2800 min_size = safe_min_size;
2801 if (size < min_size)
2803 delete_window (window);
2804 return;
2808 /* Set redisplay hints. */
2809 w->last_modified = make_number (0);
2810 w->last_overlay_modified = make_number (0);
2811 windows_or_buffers_changed++;
2812 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w->frame)) = 1;
2814 if (width_p)
2816 sideward = &w->vchild;
2817 forward = &w->hchild;
2818 w->total_cols = make_number (size);
2819 adjust_window_margins (w);
2821 else
2823 sideward = &w->hchild;
2824 forward = &w->vchild;
2825 w->total_lines = make_number (size);
2826 w->orig_total_lines = Qnil;
2829 if (!NILP (*sideward))
2831 for (child = *sideward; !NILP (child); child = c->next)
2833 c = XWINDOW (child);
2834 if (width_p)
2835 c->left_col = w->left_col;
2836 else
2837 c->top_line = w->top_line;
2838 size_window (child, size, width_p, nodelete_p);
2841 else if (!NILP (*forward))
2843 int fixed_size, each, extra, n;
2844 int resize_fixed_p, nfixed;
2845 int last_pos, first_pos, nchildren, total;
2846 int *new_sizes = NULL;
2848 /* Determine the fixed-size portion of the this window, and the
2849 number of child windows. */
2850 fixed_size = nchildren = nfixed = total = 0;
2851 for (child = *forward; !NILP (child); child = c->next, ++nchildren)
2853 int child_size;
2855 c = XWINDOW (child);
2856 child_size = width_p ? XINT (c->total_cols) : XINT (c->total_lines);
2857 total += child_size;
2859 if (window_fixed_size_p (c, width_p, 0))
2861 fixed_size += child_size;
2862 ++nfixed;
2866 /* If the new size is smaller than fixed_size, or if there
2867 aren't any resizable windows, allow resizing fixed-size
2868 windows. */
2869 resize_fixed_p = nfixed == nchildren || size < fixed_size;
2871 /* Compute how many lines/columns to add/remove to each child. The
2872 value of extra takes care of rounding errors. */
2873 n = resize_fixed_p ? nchildren : nchildren - nfixed;
2874 if (size < total && n > 1)
2875 new_sizes = shrink_windows (total, size, nchildren, n, min_size,
2876 resize_fixed_p, *forward, width_p);
2877 else
2879 each = (size - total) / n;
2880 extra = (size - total) - n * each;
2883 /* Compute new children heights and edge positions. */
2884 first_pos = width_p ? XINT (w->left_col) : XINT (w->top_line);
2885 last_pos = first_pos;
2886 for (n = 0, child = *forward; !NILP (child); child = c->next, ++n)
2888 int new_size, old_size;
2890 c = XWINDOW (child);
2891 old_size = width_p ? XFASTINT (c->total_cols) : XFASTINT (c->total_lines);
2892 new_size = old_size;
2894 /* The top or left edge position of this child equals the
2895 bottom or right edge of its predecessor. */
2896 if (width_p)
2897 c->left_col = make_number (last_pos);
2898 else
2899 c->top_line = make_number (last_pos);
2901 /* If this child can be resized, do it. */
2902 if (resize_fixed_p || !window_fixed_size_p (c, width_p, 0))
2904 new_size = new_sizes ? new_sizes[n] : old_size + each + extra;
2905 extra = 0;
2908 /* Set new height. Note that size_window also propagates
2909 edge positions to children, so it's not a no-op if we
2910 didn't change the child's size. */
2911 size_window (child, new_size, width_p, 1);
2913 /* Remember the bottom/right edge position of this child; it
2914 will be used to set the top/left edge of the next child. */
2915 last_pos += new_size;
2918 if (new_sizes) xfree (new_sizes);
2920 /* We should have covered the parent exactly with child windows. */
2921 xassert (size == last_pos - first_pos);
2923 /* Now delete any children that became too small. */
2924 if (!nodelete_p)
2925 for (child = *forward; !NILP (child); child = c->next)
2927 int child_size;
2928 c = XWINDOW (child);
2929 child_size = width_p ? XINT (c->total_cols) : XINT (c->total_lines);
2930 size_window (child, child_size, width_p, 2);
2935 /* Set WINDOW's height to HEIGHT, and recursively change the height of
2936 WINDOW's children. NODELETE non-zero means don't delete windows
2937 that become too small in the process. (The caller should check
2938 later and do so if appropriate.) */
2940 void
2941 set_window_height (window, height, nodelete)
2942 Lisp_Object window;
2943 int height;
2944 int nodelete;
2946 size_window (window, height, 0, nodelete);
2950 /* Set WINDOW's width to WIDTH, and recursively change the width of
2951 WINDOW's children. NODELETE non-zero means don't delete windows
2952 that become too small in the process. (The caller should check
2953 later and do so if appropriate.) */
2955 void
2956 set_window_width (window, width, nodelete)
2957 Lisp_Object window;
2958 int width;
2959 int nodelete;
2961 size_window (window, width, 1, nodelete);
2964 /* Change window heights in windows rooted in WINDOW by N lines. */
2966 void
2967 change_window_heights (window, n)
2968 Lisp_Object window;
2969 int n;
2971 struct window *w = XWINDOW (window);
2973 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
2974 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
2976 if (INTEGERP (w->orig_top_line))
2977 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
2978 if (INTEGERP (w->orig_total_lines))
2979 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
2981 /* Handle just the top child in a vertical split. */
2982 if (!NILP (w->vchild))
2983 change_window_heights (w->vchild, n);
2985 /* Adjust all children in a horizontal split. */
2986 for (window = w->hchild; !NILP (window); window = w->next)
2988 w = XWINDOW (window);
2989 change_window_heights (window, n);
2994 int window_select_count;
2996 Lisp_Object
2997 Fset_window_buffer_unwind (obuf)
2998 Lisp_Object obuf;
3000 Fset_buffer (obuf);
3001 return Qnil;
3004 EXFUN (Fset_window_fringes, 4);
3005 EXFUN (Fset_window_scroll_bars, 4);
3007 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
3008 means it's allowed to run hooks. See make_frame for a case where
3009 it's not allowed. KEEP_MARGINS_P non-zero means that the current
3010 margins, fringes, and scroll-bar settings of the window are not
3011 reset from the buffer's local settings. */
3013 void
3014 set_window_buffer (window, buffer, run_hooks_p, keep_margins_p)
3015 Lisp_Object window, buffer;
3016 int run_hooks_p, keep_margins_p;
3018 struct window *w = XWINDOW (window);
3019 struct buffer *b = XBUFFER (buffer);
3020 int count = SPECPDL_INDEX ();
3022 w->buffer = buffer;
3024 if (EQ (window, selected_window))
3025 b->last_selected_window = window;
3027 /* Let redisplay errors through. */
3028 b->display_error_modiff = 0;
3030 /* Update time stamps of buffer display. */
3031 if (INTEGERP (b->display_count))
3032 XSETINT (b->display_count, XINT (b->display_count) + 1);
3033 b->display_time = Fcurrent_time ();
3035 XSETFASTINT (w->window_end_pos, 0);
3036 XSETFASTINT (w->window_end_vpos, 0);
3037 bzero (&w->last_cursor, sizeof w->last_cursor);
3038 w->window_end_valid = Qnil;
3039 w->hscroll = w->min_hscroll = make_number (0);
3040 w->vscroll = 0;
3041 set_marker_both (w->pointm, buffer, BUF_PT (b), BUF_PT_BYTE (b));
3042 set_marker_restricted (w->start,
3043 make_number (b->last_window_start),
3044 buffer);
3045 w->start_at_line_beg = Qnil;
3046 w->force_start = Qnil;
3047 XSETFASTINT (w->last_modified, 0);
3048 XSETFASTINT (w->last_overlay_modified, 0);
3049 windows_or_buffers_changed++;
3051 /* We must select BUFFER for running the window-scroll-functions.
3052 If WINDOW is selected, switch permanently.
3053 Otherwise, switch but go back to the ambient buffer afterward. */
3054 if (EQ (window, selected_window))
3055 Fset_buffer (buffer);
3056 /* We can't check ! NILP (Vwindow_scroll_functions) here
3057 because that might itself be a local variable. */
3058 else if (window_initialized)
3060 record_unwind_protect (Fset_window_buffer_unwind, Fcurrent_buffer ());
3061 Fset_buffer (buffer);
3064 if (!keep_margins_p)
3066 /* Set left and right marginal area width etc. from buffer. */
3068 /* This may call adjust_window_margins three times, so
3069 temporarily disable window margins. */
3070 Lisp_Object save_left = w->left_margin_cols;
3071 Lisp_Object save_right = w->right_margin_cols;
3073 w->left_margin_cols = w->right_margin_cols = Qnil;
3075 Fset_window_fringes (window,
3076 b->left_fringe_width, b->right_fringe_width,
3077 b->fringes_outside_margins);
3079 Fset_window_scroll_bars (window,
3080 b->scroll_bar_width,
3081 b->vertical_scroll_bar_type, Qnil);
3083 w->left_margin_cols = save_left;
3084 w->right_margin_cols = save_right;
3086 Fset_window_margins (window,
3087 b->left_margin_cols, b->right_margin_cols);
3090 if (run_hooks_p)
3092 if (! NILP (Vwindow_scroll_functions))
3093 run_hook_with_args_2 (Qwindow_scroll_functions, window,
3094 Fmarker_position (w->start));
3096 if (! NILP (Vwindow_configuration_change_hook)
3097 && ! NILP (Vrun_hooks))
3098 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
3101 unbind_to (count, Qnil);
3105 DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 3, 0,
3106 doc: /* Make WINDOW display BUFFER as its contents.
3107 BUFFER can be a buffer or the name of an existing buffer.
3108 Optional third arg KEEP-MARGINS non-nil means that WINDOW's current
3109 display margins, fringe widths, and scroll bar settings are maintained;
3110 the default is to reset these from BUFFER's local settings or the frame
3111 defaults.
3113 This function runs the hook `window-scroll-functions'. */)
3114 (window, buffer, keep_margins)
3115 register Lisp_Object window, buffer, keep_margins;
3117 register Lisp_Object tem;
3118 register struct window *w = decode_window (window);
3120 XSETWINDOW (window, w);
3121 buffer = Fget_buffer (buffer);
3122 CHECK_BUFFER (buffer);
3124 if (NILP (XBUFFER (buffer)->name))
3125 error ("Attempt to display deleted buffer");
3127 tem = w->buffer;
3128 if (NILP (tem))
3129 error ("Window is deleted");
3130 else if (! EQ (tem, Qt)) /* w->buffer is t when the window
3131 is first being set up. */
3133 if (!NILP (w->dedicated) && !EQ (tem, buffer))
3134 error ("Window is dedicated to `%s'",
3135 SDATA (XBUFFER (tem)->name));
3137 unshow_buffer (w);
3140 set_window_buffer (window, buffer, 1, !NILP (keep_margins));
3141 return Qnil;
3144 /* Note that selected_window can be nil
3145 when this is called from Fset_window_configuration. */
3147 DEFUN ("select-window", Fselect_window, Sselect_window, 1, 2, 0,
3148 doc: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
3149 If WINDOW is not already selected, make WINDOW's buffer current
3150 and make WINDOW the frame's selected window. Return WINDOW.
3151 Optional second arg NORECORD non-nil means
3152 do not put this buffer at the front of the list of recently selected ones.
3154 Note that the main editor command loop
3155 selects the buffer of the selected window before each command. */)
3156 (window, norecord)
3157 register Lisp_Object window, norecord;
3159 register struct window *w;
3160 register struct window *ow;
3161 struct frame *sf;
3163 CHECK_LIVE_WINDOW (window);
3165 w = XWINDOW (window);
3166 w->frozen_window_start_p = 0;
3168 ++window_select_count;
3169 XSETFASTINT (w->use_time, window_select_count);
3170 if (EQ (window, selected_window))
3171 return window;
3173 /* Store the current buffer's actual point into the
3174 old selected window. It belongs to that window,
3175 and when the window is not selected, must be in the window. */
3176 if (!NILP (selected_window))
3178 ow = XWINDOW (selected_window);
3179 if (! NILP (ow->buffer))
3180 set_marker_both (ow->pointm, ow->buffer,
3181 BUF_PT (XBUFFER (ow->buffer)),
3182 BUF_PT_BYTE (XBUFFER (ow->buffer)));
3185 selected_window = window;
3186 sf = SELECTED_FRAME ();
3187 if (XFRAME (WINDOW_FRAME (w)) != sf)
3189 XFRAME (WINDOW_FRAME (w))->selected_window = window;
3190 /* Use this rather than Fhandle_switch_frame
3191 so that FRAME_FOCUS_FRAME is moved appropriately as we
3192 move around in the state where a minibuffer in a separate
3193 frame is active. */
3194 Fselect_frame (WINDOW_FRAME (w), Qnil);
3196 else
3197 sf->selected_window = window;
3199 if (NILP (norecord))
3200 record_buffer (w->buffer);
3201 Fset_buffer (w->buffer);
3203 XBUFFER (w->buffer)->last_selected_window = window;
3205 /* Go to the point recorded in the window.
3206 This is important when the buffer is in more
3207 than one window. It also matters when
3208 redisplay_window has altered point after scrolling,
3209 because it makes the change only in the window. */
3211 register int new_point = marker_position (w->pointm);
3212 if (new_point < BEGV)
3213 SET_PT (BEGV);
3214 else if (new_point > ZV)
3215 SET_PT (ZV);
3216 else
3217 SET_PT (new_point);
3220 windows_or_buffers_changed++;
3221 return window;
3224 static Lisp_Object
3225 select_window_norecord (window)
3226 Lisp_Object window;
3228 return Fselect_window (window, Qt);
3231 /* Deiconify the frame containing the window WINDOW,
3232 unless it is the selected frame;
3233 then return WINDOW.
3235 The reason for the exception for the selected frame
3236 is that it seems better not to change the selected frames visibility
3237 merely because of displaying a different buffer in it.
3238 The deiconification is useful when a buffer gets shown in
3239 another frame that you were not using lately. */
3241 static Lisp_Object
3242 display_buffer_1 (window)
3243 Lisp_Object window;
3245 Lisp_Object frame = XWINDOW (window)->frame;
3246 FRAME_PTR f = XFRAME (frame);
3248 FRAME_SAMPLE_VISIBILITY (f);
3250 if (EQ (frame, selected_frame))
3251 ; /* Assume the selected frame is already visible enough. */
3252 else if (minibuf_level > 0
3253 && MINI_WINDOW_P (XWINDOW (selected_window))
3254 && WINDOW_LIVE_P (minibuf_selected_window)
3255 && EQ (frame, WINDOW_FRAME (XWINDOW (minibuf_selected_window))))
3256 ; /* Assume the frame from which we invoked the minibuffer is visible. */
3257 else
3259 if (FRAME_ICONIFIED_P (f))
3260 Fmake_frame_visible (frame);
3261 else if (FRAME_VISIBLE_P (f))
3262 Fraise_frame (frame);
3265 return window;
3268 DEFUN ("special-display-p", Fspecial_display_p, Sspecial_display_p, 1, 1, 0,
3269 doc: /* Returns non-nil if a buffer named BUFFER-NAME gets a special frame.
3270 If the value is t, a frame would be created for that buffer
3271 using the default frame parameters. If the value is a list,
3272 it is a list of frame parameters that would be used
3273 to make a frame for that buffer.
3274 The variables `special-display-buffer-names'
3275 and `special-display-regexps' control this. */)
3276 (buffer_name)
3277 Lisp_Object buffer_name;
3279 Lisp_Object tem;
3281 CHECK_STRING (buffer_name);
3283 tem = Fmember (buffer_name, Vspecial_display_buffer_names);
3284 if (!NILP (tem))
3285 return Qt;
3287 tem = Fassoc (buffer_name, Vspecial_display_buffer_names);
3288 if (!NILP (tem))
3289 return XCDR (tem);
3291 for (tem = Vspecial_display_regexps; CONSP (tem); tem = XCDR (tem))
3293 Lisp_Object car = XCAR (tem);
3294 if (STRINGP (car)
3295 && fast_string_match (car, buffer_name) >= 0)
3296 return Qt;
3297 else if (CONSP (car)
3298 && STRINGP (XCAR (car))
3299 && fast_string_match (XCAR (car), buffer_name) >= 0)
3300 return XCDR (car);
3302 return Qnil;
3305 DEFUN ("same-window-p", Fsame_window_p, Ssame_window_p, 1, 1, 0,
3306 doc: /* Returns non-nil if a new buffer named BUFFER-NAME would use the same window.
3307 See `same-window-buffer-names' and `same-window-regexps'. */)
3308 (buffer_name)
3309 Lisp_Object buffer_name;
3311 Lisp_Object tem;
3313 CHECK_STRING (buffer_name);
3315 tem = Fmember (buffer_name, Vsame_window_buffer_names);
3316 if (!NILP (tem))
3317 return Qt;
3319 tem = Fassoc (buffer_name, Vsame_window_buffer_names);
3320 if (!NILP (tem))
3321 return Qt;
3323 for (tem = Vsame_window_regexps; CONSP (tem); tem = XCDR (tem))
3325 Lisp_Object car = XCAR (tem);
3326 if (STRINGP (car)
3327 && fast_string_match (car, buffer_name) >= 0)
3328 return Qt;
3329 else if (CONSP (car)
3330 && STRINGP (XCAR (car))
3331 && fast_string_match (XCAR (car), buffer_name) >= 0)
3332 return Qt;
3334 return Qnil;
3337 /* Use B so the default is (other-buffer). */
3338 DEFUN ("display-buffer", Fdisplay_buffer, Sdisplay_buffer, 1, 3,
3339 "BDisplay buffer: \nP",
3340 doc: /* Make BUFFER appear in some window but don't select it.
3341 BUFFER must be the name of an existing buffer, or, when called from Lisp,
3342 a buffer.
3343 If BUFFER is shown already in some window, just use that one,
3344 unless the window is the selected window and the optional second
3345 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).
3346 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
3347 Returns the window displaying BUFFER.
3348 If `display-buffer-reuse-frames' is non-nil, and another frame is currently
3349 displaying BUFFER, then simply raise that frame.
3351 The variables `special-display-buffer-names',
3352 `special-display-regexps', `same-window-buffer-names', and
3353 `same-window-regexps' customize how certain buffer names are handled.
3354 The latter two take effect only if NOT-THIS-WINDOW is t.
3356 If optional argument FRAME is `visible', search all visible frames.
3357 If FRAME is 0, search all visible and iconified frames.
3358 If FRAME is t, search all frames.
3359 If FRAME is a frame, search only that frame.
3360 If FRAME is nil, search only the selected frame
3361 (actually the last nonminibuffer frame),
3362 unless `pop-up-frames' or `display-buffer-reuse-frames' is non-nil,
3363 which means search visible and iconified frames.
3365 If a full-width window on a splittable frame is available to display
3366 the buffer, it may be split, subject to the value of the variable
3367 `split-height-threshold'.
3369 If `even-window-heights' is non-nil, window heights will be evened out
3370 if displaying the buffer causes two vertically adjacent windows to be
3371 displayed. */)
3372 (buffer, not_this_window, frame)
3373 register Lisp_Object buffer, not_this_window, frame;
3375 register Lisp_Object window, tem, swp;
3376 struct frame *f;
3378 swp = Qnil;
3379 buffer = Fget_buffer (buffer);
3380 CHECK_BUFFER (buffer);
3382 if (!NILP (Vdisplay_buffer_function))
3383 return call2 (Vdisplay_buffer_function, buffer, not_this_window);
3385 if (NILP (not_this_window)
3386 && XBUFFER (XWINDOW (selected_window)->buffer) == XBUFFER (buffer))
3387 return display_buffer_1 (selected_window);
3389 /* See if the user has specified this buffer should appear
3390 in the selected window. */
3391 if (NILP (not_this_window))
3393 swp = Fsame_window_p (XBUFFER (buffer)->name);
3394 if (!NILP (swp) && !no_switch_window (selected_window))
3396 Fswitch_to_buffer (buffer, Qnil);
3397 return display_buffer_1 (selected_window);
3401 /* If the user wants pop-up-frames or display-buffer-reuse-frames,
3402 look for a window showing BUFFER on any visible or iconified frame.
3403 Otherwise search only the current frame. */
3404 if (! NILP (frame))
3405 tem = frame;
3406 else if (pop_up_frames
3407 || display_buffer_reuse_frames
3408 || last_nonminibuf_frame == 0)
3409 XSETFASTINT (tem, 0);
3410 else
3411 XSETFRAME (tem, last_nonminibuf_frame);
3413 window = Fget_buffer_window (buffer, tem);
3414 if (!NILP (window)
3415 && (NILP (not_this_window) || !EQ (window, selected_window)))
3416 return display_buffer_1 (window);
3418 /* Certain buffer names get special handling. */
3419 if (!NILP (Vspecial_display_function) && NILP (swp))
3421 tem = Fspecial_display_p (XBUFFER (buffer)->name);
3422 if (EQ (tem, Qt))
3423 return call1 (Vspecial_display_function, buffer);
3424 if (CONSP (tem))
3425 return call2 (Vspecial_display_function, buffer, tem);
3428 /* If there are no frames open that have more than a minibuffer,
3429 we need to create a new frame. */
3430 if (pop_up_frames || last_nonminibuf_frame == 0)
3432 window = Fframe_selected_window (call0 (Vpop_up_frame_function));
3433 Fset_window_buffer (window, buffer, Qnil);
3434 return display_buffer_1 (window);
3437 f = SELECTED_FRAME ();
3438 if (pop_up_windows
3439 || FRAME_MINIBUF_ONLY_P (f)
3440 /* If the current frame is a special display frame,
3441 don't try to reuse its windows. */
3442 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (f))->dedicated))
3444 Lisp_Object frames;
3446 frames = Qnil;
3447 if (FRAME_MINIBUF_ONLY_P (f))
3448 XSETFRAME (frames, last_nonminibuf_frame);
3449 /* Don't try to create a window if we would get an error. */
3450 if (split_height_threshold < window_min_height << 1)
3451 split_height_threshold = window_min_height << 1;
3453 /* Note that both Fget_largest_window and Fget_lru_window
3454 ignore minibuffers and dedicated windows.
3455 This means they can return nil. */
3457 /* If the frame we would try to split cannot be split,
3458 try other frames. */
3459 if (FRAME_NO_SPLIT_P (NILP (frames) ? f : last_nonminibuf_frame))
3461 /* Try visible frames first. */
3462 window = Fget_largest_window (Qvisible);
3463 /* If that didn't work, try iconified frames. */
3464 if (NILP (window))
3465 window = Fget_largest_window (make_number (0));
3466 if (NILP (window))
3467 window = Fget_largest_window (Qt);
3469 else
3470 window = Fget_largest_window (frames);
3472 /* If we got a tall enough full-width window that can be split,
3473 split it. */
3474 if (!NILP (window)
3475 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame))
3476 && window_height (window) >= split_height_threshold
3477 && WINDOW_FULL_WIDTH_P (XWINDOW (window)))
3478 window = Fsplit_window (window, Qnil, Qnil);
3479 else
3481 Lisp_Object upper, lower, other;
3483 window = Fget_lru_window (frames);
3484 /* If the LRU window is selected, and big enough,
3485 and can be split, split it. */
3486 if (!NILP (window)
3487 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame))
3488 && (EQ (window, selected_window)
3489 || EQ (XWINDOW (window)->parent, Qnil))
3490 && window_height (window) >= window_min_height << 1)
3491 window = Fsplit_window (window, Qnil, Qnil);
3492 /* If Fget_lru_window returned nil, try other approaches. */
3494 /* Try visible frames first. */
3495 if (NILP (window))
3496 window = Fget_buffer_window (buffer, Qvisible);
3497 if (NILP (window))
3498 window = Fget_largest_window (Qvisible);
3499 /* If that didn't work, try iconified frames. */
3500 if (NILP (window))
3501 window = Fget_buffer_window (buffer, make_number (0));
3502 if (NILP (window))
3503 window = Fget_largest_window (make_number (0));
3504 /* Try invisible frames. */
3505 if (NILP (window))
3506 window = Fget_buffer_window (buffer, Qt);
3507 if (NILP (window))
3508 window = Fget_largest_window (Qt);
3509 /* As a last resort, make a new frame. */
3510 if (NILP (window))
3511 window = Fframe_selected_window (call0 (Vpop_up_frame_function));
3512 /* If window appears above or below another,
3513 even out their heights. */
3514 other = upper = lower = Qnil;
3515 if (!NILP (XWINDOW (window)->prev))
3516 other = upper = XWINDOW (window)->prev, lower = window;
3517 if (!NILP (XWINDOW (window)->next))
3518 other = lower = XWINDOW (window)->next, upper = window;
3519 if (!NILP (other)
3520 && !NILP (Veven_window_heights)
3521 /* Check that OTHER and WINDOW are vertically arrayed. */
3522 && !EQ (XWINDOW (other)->top_line, XWINDOW (window)->top_line)
3523 && (XFASTINT (XWINDOW (other)->total_lines)
3524 > XFASTINT (XWINDOW (window)->total_lines)))
3526 int total = (XFASTINT (XWINDOW (other)->total_lines)
3527 + XFASTINT (XWINDOW (window)->total_lines));
3528 enlarge_window (upper,
3529 total / 2 - XFASTINT (XWINDOW (upper)->total_lines),
3530 0, 0);
3534 else
3535 window = Fget_lru_window (Qnil);
3537 Fset_window_buffer (window, buffer, Qnil);
3538 return display_buffer_1 (window);
3542 DEFUN ("force-window-update", Fforce_window_update, Sforce_window_update,
3543 0, 1, 0,
3544 doc: /* Force redisplay of all windows.
3545 If optional arg OBJECT is a window, force redisplay of that window only.
3546 If OBJECT is a buffer or buffer name, force redisplay of all windows
3547 displaying that buffer. */)
3548 (object)
3549 Lisp_Object object;
3551 if (NILP (object))
3553 windows_or_buffers_changed++;
3554 update_mode_lines++;
3555 return Qt;
3558 if (WINDOWP (object))
3560 struct window *w = XWINDOW (object);
3561 mark_window_display_accurate (object, 0);
3562 w->update_mode_line = Qt;
3563 if (BUFFERP (w->buffer))
3564 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
3565 ++update_mode_lines;
3566 return Qt;
3569 if (STRINGP (object))
3570 object = Fget_buffer (object);
3571 if (BUFFERP (object) && !NILP (XBUFFER (object)->name))
3573 /* Walk all windows looking for buffer, and force update
3574 of each of those windows. */
3576 object = window_loop (REDISPLAY_BUFFER_WINDOWS, object, 0, Qvisible);
3577 return NILP (object) ? Qnil : Qt;
3580 /* If nothing suitable was found, just return.
3581 We could signal an error, but this feature will typically be used
3582 asynchronously in timers or process sentinels, so we don't. */
3583 return Qnil;
3587 void
3588 temp_output_buffer_show (buf)
3589 register Lisp_Object buf;
3591 register struct buffer *old = current_buffer;
3592 register Lisp_Object window;
3593 register struct window *w;
3595 XBUFFER (buf)->directory = current_buffer->directory;
3597 Fset_buffer (buf);
3598 BUF_SAVE_MODIFF (XBUFFER (buf)) = MODIFF;
3599 BEGV = BEG;
3600 ZV = Z;
3601 SET_PT (BEG);
3602 #if 0 /* rms: there should be no reason for this. */
3603 XBUFFER (buf)->prevent_redisplay_optimizations_p = 1;
3604 #endif
3605 set_buffer_internal (old);
3607 if (!EQ (Vtemp_buffer_show_function, Qnil))
3608 call1 (Vtemp_buffer_show_function, buf);
3609 else
3611 window = Fdisplay_buffer (buf, Qnil, Qnil);
3613 if (!EQ (XWINDOW (window)->frame, selected_frame))
3614 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
3615 Vminibuf_scroll_window = window;
3616 w = XWINDOW (window);
3617 XSETFASTINT (w->hscroll, 0);
3618 XSETFASTINT (w->min_hscroll, 0);
3619 set_marker_restricted_both (w->start, buf, BEG, BEG);
3620 set_marker_restricted_both (w->pointm, buf, BEG, BEG);
3622 /* Run temp-buffer-show-hook, with the chosen window selected
3623 and its buffer current. */
3625 if (!NILP (Vrun_hooks)
3626 && !NILP (Fboundp (Qtemp_buffer_show_hook))
3627 && !NILP (Fsymbol_value (Qtemp_buffer_show_hook)))
3629 int count = SPECPDL_INDEX ();
3630 Lisp_Object prev_window, prev_buffer;
3631 prev_window = selected_window;
3632 XSETBUFFER (prev_buffer, old);
3634 /* Select the window that was chosen, for running the hook.
3635 Note: Both Fselect_window and select_window_norecord may
3636 set-buffer to the buffer displayed in the window,
3637 so we need to save the current buffer. --stef */
3638 record_unwind_protect (Fset_buffer, prev_buffer);
3639 record_unwind_protect (select_window_norecord, prev_window);
3640 Fselect_window (window, Qt);
3641 Fset_buffer (w->buffer);
3642 call1 (Vrun_hooks, Qtemp_buffer_show_hook);
3643 unbind_to (count, Qnil);
3648 static void
3649 make_dummy_parent (window)
3650 Lisp_Object window;
3652 Lisp_Object new;
3653 register struct window *o, *p;
3654 int i;
3656 o = XWINDOW (window);
3657 p = allocate_window ();
3658 for (i = 0; i < VECSIZE (struct window); ++i)
3659 ((struct Lisp_Vector *) p)->contents[i]
3660 = ((struct Lisp_Vector *)o)->contents[i];
3661 XSETWINDOW (new, p);
3663 ++sequence_number;
3664 XSETFASTINT (p->sequence_number, sequence_number);
3666 /* Put new into window structure in place of window */
3667 replace_window (window, new);
3669 o->next = Qnil;
3670 o->prev = Qnil;
3671 o->vchild = Qnil;
3672 o->hchild = Qnil;
3673 o->parent = new;
3675 p->start = Qnil;
3676 p->pointm = Qnil;
3677 p->buffer = Qnil;
3680 DEFUN ("split-window", Fsplit_window, Ssplit_window, 0, 3, "",
3681 doc: /* Split WINDOW, putting SIZE lines in the first of the pair.
3682 WINDOW defaults to selected one and SIZE to half its size.
3683 If optional third arg HORFLAG is non-nil, split side by side
3684 and put SIZE columns in the first of the pair. In that case,
3685 SIZE includes that window's scroll bar, or the divider column to its right.
3686 Interactively, all arguments are nil.
3688 Returns the newly created window (which is the lower or rightmost one).
3689 The upper or leftmost window is the original one and remains selected.
3690 See Info node `(elisp)Splitting Windows' for more details and examples.*/)
3691 (window, size, horflag)
3692 Lisp_Object window, size, horflag;
3694 register Lisp_Object new;
3695 register struct window *o, *p;
3696 FRAME_PTR fo;
3697 register int size_int;
3699 if (NILP (window))
3700 window = selected_window;
3701 else
3702 CHECK_LIVE_WINDOW (window);
3704 o = XWINDOW (window);
3705 fo = XFRAME (WINDOW_FRAME (o));
3707 if (NILP (size))
3709 if (!NILP (horflag))
3710 /* Calculate the size of the left-hand window, by dividing
3711 the usable space in columns by two.
3712 We round up, since the left-hand window may include
3713 a dividing line, while the right-hand may not. */
3714 size_int = (XFASTINT (o->total_cols) + 1) >> 1;
3715 else
3716 size_int = XFASTINT (o->total_lines) >> 1;
3718 else
3720 CHECK_NUMBER (size);
3721 size_int = XINT (size);
3724 if (MINI_WINDOW_P (o))
3725 error ("Attempt to split minibuffer window");
3726 else if (window_fixed_size_p (o, !NILP (horflag), 0))
3727 error ("Attempt to split fixed-size window");
3729 check_min_window_sizes ();
3731 if (NILP (horflag))
3733 if (size_int < window_min_height)
3734 error ("Window height %d too small (after splitting)", size_int);
3735 if (size_int + window_min_height > XFASTINT (o->total_lines))
3736 error ("Window height %d too small (after splitting)",
3737 XFASTINT (o->total_lines) - size_int);
3738 if (NILP (o->parent)
3739 || NILP (XWINDOW (o->parent)->vchild))
3741 make_dummy_parent (window);
3742 new = o->parent;
3743 XWINDOW (new)->vchild = window;
3746 else
3748 if (size_int < window_min_width)
3749 error ("Window width %d too small (after splitting)", size_int);
3751 if (size_int + window_min_width > XFASTINT (o->total_cols))
3752 error ("Window width %d too small (after splitting)",
3753 XFASTINT (o->total_cols) - size_int);
3754 if (NILP (o->parent)
3755 || NILP (XWINDOW (o->parent)->hchild))
3757 make_dummy_parent (window);
3758 new = o->parent;
3759 XWINDOW (new)->hchild = window;
3763 /* Now we know that window's parent is a vertical combination
3764 if we are dividing vertically, or a horizontal combination
3765 if we are making side-by-side windows */
3767 windows_or_buffers_changed++;
3768 FRAME_WINDOW_SIZES_CHANGED (fo) = 1;
3769 new = make_window ();
3770 p = XWINDOW (new);
3772 p->frame = o->frame;
3773 p->next = o->next;
3774 if (!NILP (p->next))
3775 XWINDOW (p->next)->prev = new;
3776 p->prev = window;
3777 o->next = new;
3778 p->parent = o->parent;
3779 p->buffer = Qt;
3780 p->window_end_valid = Qnil;
3781 bzero (&p->last_cursor, sizeof p->last_cursor);
3783 /* Duplicate special geometry settings. */
3785 p->left_margin_cols = o->left_margin_cols;
3786 p->right_margin_cols = o->right_margin_cols;
3787 p->left_fringe_width = o->left_fringe_width;
3788 p->right_fringe_width = o->right_fringe_width;
3789 p->fringes_outside_margins = o->fringes_outside_margins;
3790 p->scroll_bar_width = o->scroll_bar_width;
3791 p->vertical_scroll_bar_type = o->vertical_scroll_bar_type;
3793 /* Apportion the available frame space among the two new windows */
3795 if (!NILP (horflag))
3797 p->total_lines = o->total_lines;
3798 p->top_line = o->top_line;
3799 XSETFASTINT (p->total_cols, XFASTINT (o->total_cols) - size_int);
3800 XSETFASTINT (o->total_cols, size_int);
3801 XSETFASTINT (p->left_col, XFASTINT (o->left_col) + size_int);
3802 adjust_window_margins (p);
3803 adjust_window_margins (o);
3805 else
3807 p->left_col = o->left_col;
3808 p->total_cols = o->total_cols;
3809 XSETFASTINT (p->total_lines, XFASTINT (o->total_lines) - size_int);
3810 XSETFASTINT (o->total_lines, size_int);
3811 XSETFASTINT (p->top_line, XFASTINT (o->top_line) + size_int);
3814 /* Adjust glyph matrices. */
3815 adjust_glyphs (fo);
3817 Fset_window_buffer (new, o->buffer, Qt);
3818 return new;
3821 DEFUN ("enlarge-window", Fenlarge_window, Senlarge_window, 1, 3, "p",
3822 doc: /* Make current window ARG lines bigger.
3823 From program, optional second arg non-nil means grow sideways ARG columns.
3824 Interactively, if an argument is not given, make the window one line bigger.
3826 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3827 of the siblings above or to the left of the selected window. Only
3828 siblings to the right or below are changed. */)
3829 (arg, side, preserve_before)
3830 register Lisp_Object arg, side, preserve_before;
3832 CHECK_NUMBER (arg);
3833 enlarge_window (selected_window, XINT (arg), !NILP (side),
3834 !NILP (preserve_before));
3836 if (! NILP (Vwindow_configuration_change_hook))
3837 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
3839 return Qnil;
3842 DEFUN ("shrink-window", Fshrink_window, Sshrink_window, 1, 3, "p",
3843 doc: /* Make current window ARG lines smaller.
3844 From program, optional second arg non-nil means shrink sideways arg columns.
3845 Interactively, if an argument is not given, make the window one line smaller.
3847 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3848 of the siblings above or to the left of the selected window. Only
3849 siblings to the right or below are changed. */)
3850 (arg, side, preserve_before)
3851 register Lisp_Object arg, side, preserve_before;
3853 CHECK_NUMBER (arg);
3854 enlarge_window (selected_window, -XINT (arg), !NILP (side),
3855 !NILP (preserve_before));
3857 if (! NILP (Vwindow_configuration_change_hook))
3858 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
3860 return Qnil;
3864 window_height (window)
3865 Lisp_Object window;
3867 register struct window *p = XWINDOW (window);
3868 return WINDOW_TOTAL_LINES (p);
3872 window_width (window)
3873 Lisp_Object window;
3875 register struct window *p = XWINDOW (window);
3876 return WINDOW_TOTAL_COLS (p);
3880 #define CURBEG(w) \
3881 *(widthflag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line))
3883 #define CURSIZE(w) \
3884 *(widthflag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines))
3887 /* Enlarge WINDOW by DELTA. WIDTHFLAG non-zero means
3888 increase its width. Siblings of the selected window are resized to
3889 fulfill the size request. If they become too small in the process,
3890 they will be deleted.
3892 If PRESERVE_BEFORE is nonzero, that means don't alter
3893 the siblings to the left or above WINDOW. */
3895 static void
3896 enlarge_window (window, delta, widthflag, preserve_before)
3897 Lisp_Object window;
3898 int delta, widthflag, preserve_before;
3900 Lisp_Object parent, next, prev;
3901 struct window *p;
3902 Lisp_Object *sizep;
3903 int maximum;
3904 int (*sizefun) P_ ((Lisp_Object))
3905 = widthflag ? window_width : window_height;
3906 void (*setsizefun) P_ ((Lisp_Object, int, int))
3907 = (widthflag ? set_window_width : set_window_height);
3909 /* Check values of window_min_width and window_min_height for
3910 validity. */
3911 check_min_window_sizes ();
3913 /* Give up if this window cannot be resized. */
3914 if (window_fixed_size_p (XWINDOW (window), widthflag, 1))
3915 error ("Window is not resizable");
3917 /* Find the parent of the selected window. */
3918 while (1)
3920 p = XWINDOW (window);
3921 parent = p->parent;
3923 if (NILP (parent))
3925 if (widthflag)
3926 error ("No other window to side of this one");
3927 break;
3930 if (widthflag
3931 ? !NILP (XWINDOW (parent)->hchild)
3932 : !NILP (XWINDOW (parent)->vchild))
3933 break;
3935 window = parent;
3938 sizep = &CURSIZE (window);
3941 register int maxdelta;
3943 /* Compute the maximum size increment this window can have. */
3945 if (preserve_before)
3947 if (!NILP (parent))
3949 maxdelta = (*sizefun) (parent) - XINT (*sizep);
3950 /* Subtract size of siblings before, since we can't take that. */
3951 maxdelta -= XINT (CURBEG (window)) - XINT (CURBEG (parent));
3953 else
3954 maxdelta = (!NILP (p->next) ? ((*sizefun) (p->next)
3955 - window_min_size (XWINDOW (p->next),
3956 widthflag, 0, 0))
3957 : (delta = 0));
3959 else
3960 maxdelta = (!NILP (parent) ? (*sizefun) (parent) - XINT (*sizep)
3961 /* This is a main window followed by a minibuffer. */
3962 : !NILP (p->next) ? ((*sizefun) (p->next)
3963 - window_min_size (XWINDOW (p->next),
3964 widthflag, 0, 0))
3965 /* This is a minibuffer following a main window. */
3966 : !NILP (p->prev) ? ((*sizefun) (p->prev)
3967 - window_min_size (XWINDOW (p->prev),
3968 widthflag, 0, 0))
3969 /* This is a frame with only one window, a minibuffer-only
3970 or a minibufferless frame. */
3971 : (delta = 0));
3973 if (delta > maxdelta)
3974 /* This case traps trying to make the minibuffer
3975 the full frame, or make the only window aside from the
3976 minibuffer the full frame. */
3977 delta = maxdelta;
3980 if (XINT (*sizep) + delta < window_min_size (XWINDOW (window), widthflag, 0, 0))
3982 delete_window (window);
3983 return;
3986 if (delta == 0)
3987 return;
3989 /* Find the total we can get from other siblings without deleting them. */
3990 maximum = 0;
3991 for (next = p->next; ! NILP (next); next = XWINDOW (next)->next)
3992 maximum += (*sizefun) (next) - window_min_size (XWINDOW (next),
3993 widthflag, 0, 0);
3994 if (! preserve_before)
3995 for (prev = p->prev; ! NILP (prev); prev = XWINDOW (prev)->prev)
3996 maximum += (*sizefun) (prev) - window_min_size (XWINDOW (prev),
3997 widthflag, 0, 0);
3999 /* If we can get it all from them without deleting them, do so. */
4000 if (delta <= maximum)
4002 Lisp_Object first_unaffected;
4003 Lisp_Object first_affected;
4004 int fixed_p;
4006 next = p->next;
4007 prev = p->prev;
4008 first_affected = window;
4009 /* Look at one sibling at a time,
4010 moving away from this window in both directions alternately,
4011 and take as much as we can get without deleting that sibling. */
4012 while (delta != 0
4013 && (!NILP (next) || (!preserve_before && !NILP (prev))))
4015 if (! NILP (next))
4017 int this_one = ((*sizefun) (next)
4018 - window_min_size (XWINDOW (next),
4019 widthflag, 0, &fixed_p));
4020 if (!fixed_p)
4022 if (this_one > delta)
4023 this_one = delta;
4025 (*setsizefun) (next, (*sizefun) (next) - this_one, 0);
4026 (*setsizefun) (window, XINT (*sizep) + this_one, 0);
4028 delta -= this_one;
4031 next = XWINDOW (next)->next;
4034 if (delta == 0)
4035 break;
4037 if (!preserve_before && ! NILP (prev))
4039 int this_one = ((*sizefun) (prev)
4040 - window_min_size (XWINDOW (prev),
4041 widthflag, 0, &fixed_p));
4042 if (!fixed_p)
4044 if (this_one > delta)
4045 this_one = delta;
4047 first_affected = prev;
4049 (*setsizefun) (prev, (*sizefun) (prev) - this_one, 0);
4050 (*setsizefun) (window, XINT (*sizep) + this_one, 0);
4052 delta -= this_one;
4055 prev = XWINDOW (prev)->prev;
4059 xassert (delta == 0);
4061 /* Now recalculate the edge positions of all the windows affected,
4062 based on the new sizes. */
4063 first_unaffected = next;
4064 prev = first_affected;
4065 for (next = XWINDOW (prev)->next; ! EQ (next, first_unaffected);
4066 prev = next, next = XWINDOW (next)->next)
4068 XSETINT (CURBEG (next), XINT (CURBEG (prev)) + (*sizefun) (prev));
4069 /* This does not change size of NEXT,
4070 but it propagates the new top edge to its children */
4071 (*setsizefun) (next, (*sizefun) (next), 0);
4074 else
4076 register int delta1;
4077 register int opht = (*sizefun) (parent);
4079 if (opht <= XINT (*sizep) + delta)
4081 /* If trying to grow this window to or beyond size of the parent,
4082 just delete all the sibling windows. */
4083 Lisp_Object start, tem, next;
4085 start = XWINDOW (parent)->vchild;
4086 if (NILP (start))
4087 start = XWINDOW (parent)->hchild;
4089 /* Delete any siblings that come after WINDOW. */
4090 tem = XWINDOW (window)->next;
4091 while (! NILP (tem))
4093 next = XWINDOW (tem)->next;
4094 delete_window (tem);
4095 tem = next;
4098 /* Delete any siblings that come after WINDOW.
4099 Note that if START is not WINDOW, then WINDOW still
4100 Fhas siblings, so WINDOW has not yet replaced its parent. */
4101 tem = start;
4102 while (! EQ (tem, window))
4104 next = XWINDOW (tem)->next;
4105 delete_window (tem);
4106 tem = next;
4109 else
4111 /* Otherwise, make delta1 just right so that if we add
4112 delta1 lines to this window and to the parent, and then
4113 shrink the parent back to its original size, the new
4114 proportional size of this window will increase by delta.
4116 The function size_window will compute the new height h'
4117 of the window from delta1 as:
4119 e = delta1/n
4120 x = delta1 - delta1/n * n for the 1st resizable child
4121 h' = h + e + x
4123 where n is the number of children that can be resized.
4124 We can ignore x by choosing a delta1 that is a multiple of
4125 n. We want the height of this window to come out as
4127 h' = h + delta
4129 So, delta1 must be
4131 h + e = h + delta
4132 delta1/n = delta
4133 delta1 = n * delta.
4135 The number of children n equals the number of resizable
4136 children of this window + 1 because we know window itself
4137 is resizable (otherwise we would have signalled an error. */
4139 struct window *w = XWINDOW (window);
4140 Lisp_Object s;
4141 int n = 1;
4143 for (s = w->next; !NILP (s); s = XWINDOW (s)->next)
4144 if (!window_fixed_size_p (XWINDOW (s), widthflag, 0))
4145 ++n;
4146 for (s = w->prev; !NILP (s); s = XWINDOW (s)->prev)
4147 if (!window_fixed_size_p (XWINDOW (s), widthflag, 0))
4148 ++n;
4150 delta1 = n * delta;
4152 /* Add delta1 lines or columns to this window, and to the parent,
4153 keeping things consistent while not affecting siblings. */
4154 XSETINT (CURSIZE (parent), opht + delta1);
4155 (*setsizefun) (window, XINT (*sizep) + delta1, 0);
4157 /* Squeeze out delta1 lines or columns from our parent,
4158 shriking this window and siblings proportionately.
4159 This brings parent back to correct size.
4160 Delta1 was calculated so this makes this window the desired size,
4161 taking it all out of the siblings. */
4162 (*setsizefun) (parent, opht, 0);
4167 XSETFASTINT (p->last_modified, 0);
4168 XSETFASTINT (p->last_overlay_modified, 0);
4170 /* Adjust glyph matrices. */
4171 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window))));
4174 #undef CURBEG
4175 #undef CURSIZE
4179 /***********************************************************************
4180 Resizing Mini-Windows
4181 ***********************************************************************/
4183 static void shrink_window_lowest_first P_ ((struct window *, int));
4185 enum save_restore_action
4187 CHECK_ORIG_SIZES,
4188 SAVE_ORIG_SIZES,
4189 RESTORE_ORIG_SIZES
4192 static int save_restore_orig_size P_ ((struct window *,
4193 enum save_restore_action));
4195 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
4196 from lowest windows first. */
4198 static void
4199 shrink_window_lowest_first (w, height)
4200 struct window *w;
4201 int height;
4203 struct window *c;
4204 Lisp_Object child;
4205 int old_height;
4207 xassert (!MINI_WINDOW_P (w));
4209 /* Set redisplay hints. */
4210 XSETFASTINT (w->last_modified, 0);
4211 XSETFASTINT (w->last_overlay_modified, 0);
4212 windows_or_buffers_changed++;
4213 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w))) = 1;
4215 old_height = XFASTINT (w->total_lines);
4216 XSETFASTINT (w->total_lines, height);
4218 if (!NILP (w->hchild))
4220 for (child = w->hchild; !NILP (child); child = c->next)
4222 c = XWINDOW (child);
4223 c->top_line = w->top_line;
4224 shrink_window_lowest_first (c, height);
4227 else if (!NILP (w->vchild))
4229 Lisp_Object last_child;
4230 int delta = old_height - height;
4231 int last_top;
4233 last_child = Qnil;
4235 /* Find the last child. We are taking space from lowest windows
4236 first, so we iterate over children from the last child
4237 backwards. */
4238 for (child = w->vchild; !NILP (child); child = XWINDOW (child)->next)
4239 last_child = child;
4241 /* Assign new heights. We leave only MIN_SAFE_WINDOW_HEIGHT. */
4242 for (child = last_child; delta && !NILP (child); child = c->prev)
4244 int this_one;
4246 c = XWINDOW (child);
4247 this_one = XFASTINT (c->total_lines) - MIN_SAFE_WINDOW_HEIGHT;
4249 if (this_one > delta)
4250 this_one = delta;
4252 shrink_window_lowest_first (c, XFASTINT (c->total_lines) - this_one);
4253 delta -= this_one;
4256 /* Compute new positions. */
4257 last_top = XINT (w->top_line);
4258 for (child = w->vchild; !NILP (child); child = c->next)
4260 c = XWINDOW (child);
4261 c->top_line = make_number (last_top);
4262 shrink_window_lowest_first (c, XFASTINT (c->total_lines));
4263 last_top += XFASTINT (c->total_lines);
4269 /* Save, restore, or check positions and sizes in the window tree
4270 rooted at W. ACTION says what to do.
4272 If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and
4273 orig_total_lines members are valid for all windows in the window
4274 tree. Value is non-zero if they are valid.
4276 If ACTION is SAVE_ORIG_SIZES, save members top and height in
4277 orig_top_line and orig_total_lines for all windows in the tree.
4279 If ACTION is RESTORE_ORIG_SIZES, restore top and height from values
4280 stored in orig_top_line and orig_total_lines for all windows. */
4282 static int
4283 save_restore_orig_size (w, action)
4284 struct window *w;
4285 enum save_restore_action action;
4287 int success_p = 1;
4289 while (w)
4291 if (!NILP (w->hchild))
4293 if (!save_restore_orig_size (XWINDOW (w->hchild), action))
4294 success_p = 0;
4296 else if (!NILP (w->vchild))
4298 if (!save_restore_orig_size (XWINDOW (w->vchild), action))
4299 success_p = 0;
4302 switch (action)
4304 case CHECK_ORIG_SIZES:
4305 if (!INTEGERP (w->orig_top_line) || !INTEGERP (w->orig_total_lines))
4306 return 0;
4307 break;
4309 case SAVE_ORIG_SIZES:
4310 w->orig_top_line = w->top_line;
4311 w->orig_total_lines = w->total_lines;
4312 XSETFASTINT (w->last_modified, 0);
4313 XSETFASTINT (w->last_overlay_modified, 0);
4314 break;
4316 case RESTORE_ORIG_SIZES:
4317 xassert (INTEGERP (w->orig_top_line) && INTEGERP (w->orig_total_lines));
4318 w->top_line = w->orig_top_line;
4319 w->total_lines = w->orig_total_lines;
4320 w->orig_total_lines = w->orig_top_line = Qnil;
4321 XSETFASTINT (w->last_modified, 0);
4322 XSETFASTINT (w->last_overlay_modified, 0);
4323 break;
4325 default:
4326 abort ();
4329 w = NILP (w->next) ? NULL : XWINDOW (w->next);
4332 return success_p;
4336 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
4337 without deleting other windows. */
4339 void
4340 grow_mini_window (w, delta)
4341 struct window *w;
4342 int delta;
4344 struct frame *f = XFRAME (w->frame);
4345 struct window *root;
4347 xassert (MINI_WINDOW_P (w));
4348 xassert (delta >= 0);
4350 /* Check values of window_min_width and window_min_height for
4351 validity. */
4352 check_min_window_sizes ();
4354 /* Compute how much we can enlarge the mini-window without deleting
4355 other windows. */
4356 root = XWINDOW (FRAME_ROOT_WINDOW (f));
4357 if (delta)
4359 int min_height = window_min_size (root, 0, 0, 0);
4360 if (XFASTINT (root->total_lines) - delta < min_height)
4361 /* Note that the root window may already be smaller than
4362 min_height. */
4363 delta = max (0, XFASTINT (root->total_lines) - min_height);
4366 if (delta)
4368 /* Save original window sizes and positions, if not already done. */
4369 if (!save_restore_orig_size (root, CHECK_ORIG_SIZES))
4370 save_restore_orig_size (root, SAVE_ORIG_SIZES);
4372 /* Shrink other windows. */
4373 shrink_window_lowest_first (root, XFASTINT (root->total_lines) - delta);
4375 /* Grow the mini-window. */
4376 w->top_line = make_number (XFASTINT (root->top_line) + XFASTINT (root->total_lines));
4377 w->total_lines = make_number (XFASTINT (w->total_lines) + delta);
4378 XSETFASTINT (w->last_modified, 0);
4379 XSETFASTINT (w->last_overlay_modified, 0);
4381 adjust_glyphs (f);
4386 /* Shrink mini-window W. If there is recorded info about window sizes
4387 before a call to grow_mini_window, restore recorded window sizes.
4388 Otherwise, if the mini-window is higher than 1 line, resize it to 1
4389 line. */
4391 void
4392 shrink_mini_window (w)
4393 struct window *w;
4395 struct frame *f = XFRAME (w->frame);
4396 struct window *root = XWINDOW (FRAME_ROOT_WINDOW (f));
4398 if (save_restore_orig_size (root, CHECK_ORIG_SIZES))
4400 save_restore_orig_size (root, RESTORE_ORIG_SIZES);
4401 adjust_glyphs (f);
4402 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
4403 windows_or_buffers_changed = 1;
4405 else if (XFASTINT (w->total_lines) > 1)
4407 /* Distribute the additional lines of the mini-window
4408 among the other windows. */
4409 Lisp_Object window;
4410 XSETWINDOW (window, w);
4411 enlarge_window (window, 1 - XFASTINT (w->total_lines), 0, 0);
4417 /* Mark window cursors off for all windows in the window tree rooted
4418 at W by setting their phys_cursor_on_p flag to zero. Called from
4419 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4420 the frame are cleared. */
4422 void
4423 mark_window_cursors_off (w)
4424 struct window *w;
4426 while (w)
4428 if (!NILP (w->hchild))
4429 mark_window_cursors_off (XWINDOW (w->hchild));
4430 else if (!NILP (w->vchild))
4431 mark_window_cursors_off (XWINDOW (w->vchild));
4432 else
4433 w->phys_cursor_on_p = 0;
4435 w = NILP (w->next) ? 0 : XWINDOW (w->next);
4440 /* Return number of lines of text (not counting mode lines) in W. */
4443 window_internal_height (w)
4444 struct window *w;
4446 int ht = XFASTINT (w->total_lines);
4448 if (!MINI_WINDOW_P (w))
4450 if (!NILP (w->parent)
4451 || !NILP (w->vchild)
4452 || !NILP (w->hchild)
4453 || !NILP (w->next)
4454 || !NILP (w->prev)
4455 || WINDOW_WANTS_MODELINE_P (w))
4456 --ht;
4458 if (WINDOW_WANTS_HEADER_LINE_P (w))
4459 --ht;
4462 return ht;
4466 /* Return the number of columns in W.
4467 Don't count columns occupied by scroll bars or the vertical bar
4468 separating W from the sibling to its right. */
4471 window_box_text_cols (w)
4472 struct window *w;
4474 struct frame *f = XFRAME (WINDOW_FRAME (w));
4475 int width = XINT (w->total_cols);
4477 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
4478 /* Scroll bars occupy a few columns. */
4479 width -= WINDOW_CONFIG_SCROLL_BAR_COLS (w);
4480 else if (!FRAME_WINDOW_P (f)
4481 && !WINDOW_RIGHTMOST_P (w) && !WINDOW_FULL_WIDTH_P (w))
4482 /* The column of `|' characters separating side-by-side windows
4483 occupies one column only. */
4484 width -= 1;
4486 if (FRAME_WINDOW_P (f))
4487 /* On window-systems, fringes and display margins cannot be
4488 used for normal text. */
4489 width -= (WINDOW_FRINGE_COLS (w)
4490 + WINDOW_LEFT_MARGIN_COLS (w)
4491 + WINDOW_RIGHT_MARGIN_COLS (w));
4493 return width;
4497 /************************************************************************
4498 Window Scrolling
4499 ***********************************************************************/
4501 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4502 N screen-fulls, which is defined as the height of the window minus
4503 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4504 instead. Negative values of N mean scroll down. NOERROR non-zero
4505 means don't signal an error if we try to move over BEGV or ZV,
4506 respectively. */
4508 static void
4509 window_scroll (window, n, whole, noerror)
4510 Lisp_Object window;
4511 int n;
4512 int whole;
4513 int noerror;
4515 immediate_quit = 1;
4517 /* If we must, use the pixel-based version which is much slower than
4518 the line-based one but can handle varying line heights. */
4519 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window)->frame)))
4520 window_scroll_pixel_based (window, n, whole, noerror);
4521 else
4522 window_scroll_line_based (window, n, whole, noerror);
4524 immediate_quit = 0;
4528 /* Implementation of window_scroll that works based on pixel line
4529 heights. See the comment of window_scroll for parameter
4530 descriptions. */
4532 static void
4533 window_scroll_pixel_based (window, n, whole, noerror)
4534 Lisp_Object window;
4535 int n;
4536 int whole;
4537 int noerror;
4539 struct it it;
4540 struct window *w = XWINDOW (window);
4541 struct text_pos start;
4542 Lisp_Object tem;
4543 int this_scroll_margin;
4544 int preserve_y;
4545 /* True if we fiddled the window vscroll field without really scrolling. */
4546 int vscrolled = 0;
4548 SET_TEXT_POS_FROM_MARKER (start, w->start);
4550 /* If PT is not visible in WINDOW, move back one half of
4551 the screen. Allow PT to be partially visible, otherwise
4552 something like (scroll-down 1) with PT in the line before
4553 the partially visible one would recenter. */
4554 tem = Fpos_visible_in_window_p (make_number (PT), window, Qt);
4555 if (NILP (tem))
4557 /* Move backward half the height of the window. Performance note:
4558 vmotion used here is about 10% faster, but would give wrong
4559 results for variable height lines. */
4560 init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID);
4561 it.current_y = it.last_visible_y;
4562 move_it_vertically_backward (&it, window_box_height (w) / 2);
4564 /* The function move_iterator_vertically may move over more than
4565 the specified y-distance. If it->w is small, e.g. a
4566 mini-buffer window, we may end up in front of the window's
4567 display area. This is the case when Start displaying at the
4568 start of the line containing PT in this case. */
4569 if (it.current_y <= 0)
4571 init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID);
4572 move_it_vertically_backward (&it, 0);
4573 it.current_y = 0;
4576 start = it.current.pos;
4578 else if (auto_window_vscroll_p)
4580 if (tem = XCAR (XCDR (XCDR (tem))), CONSP (tem))
4582 int px;
4583 int dy = WINDOW_FRAME_LINE_HEIGHT (w);
4584 if (whole)
4585 dy = max ((window_box_height (w)
4586 - next_screen_context_lines * dy),
4587 dy);
4588 dy *= n;
4590 if (n < 0 && (px = XINT (XCAR (tem))) > 0)
4592 px = max (0, -w->vscroll - min (px, -dy));
4593 Fset_window_vscroll (window, make_number (px), Qt);
4594 return;
4596 if (n > 0 && (px = XINT (XCDR (tem))) > 0)
4598 px = max (0, -w->vscroll + min (px, dy));
4599 Fset_window_vscroll (window, make_number (px), Qt);
4600 return;
4603 Fset_window_vscroll (window, make_number (0), Qt);
4606 /* If scroll_preserve_screen_position is non-nil, we try to set
4607 point in the same window line as it is now, so get that line. */
4608 if (!NILP (Vscroll_preserve_screen_position))
4610 start_display (&it, w, start);
4611 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
4612 preserve_y = it.current_y;
4614 else
4615 preserve_y = -1;
4617 /* Move iterator it from start the specified distance forward or
4618 backward. The result is the new window start. */
4619 start_display (&it, w, start);
4620 if (whole)
4622 int start_pos = IT_CHARPOS (it);
4623 int dy = WINDOW_FRAME_LINE_HEIGHT (w);
4624 dy = max ((window_box_height (w)
4625 - next_screen_context_lines * dy),
4626 dy) * n;
4628 /* Note that move_it_vertically always moves the iterator to the
4629 start of a line. So, if the last line doesn't have a newline,
4630 we would end up at the start of the line ending at ZV. */
4631 if (dy <= 0)
4633 move_it_vertically_backward (&it, -dy);
4634 /* Ensure we actually does move, e.g. in case we are currently
4635 looking at an image that is taller that the window height. */
4636 while (start_pos == IT_CHARPOS (it)
4637 && start_pos > BEGV)
4638 move_it_by_lines (&it, -1, 1);
4640 else if (dy > 0)
4642 move_it_to (&it, ZV, -1, it.current_y + dy, -1,
4643 MOVE_TO_POS | MOVE_TO_Y);
4644 /* Ensure we actually does move, e.g. in case we are currently
4645 looking at an image that is taller that the window height. */
4646 while (start_pos == IT_CHARPOS (it)
4647 && start_pos < ZV)
4648 move_it_by_lines (&it, 1, 1);
4651 else
4652 move_it_by_lines (&it, n, 1);
4654 /* We failed if we find ZV is already on the screen (scrolling up,
4655 means there's nothing past the end), or if we can't start any
4656 earlier (scrolling down, means there's nothing past the top). */
4657 if ((n > 0 && IT_CHARPOS (it) == ZV)
4658 || (n < 0 && IT_CHARPOS (it) == CHARPOS (start)))
4660 if (IT_CHARPOS (it) == ZV)
4662 if (it.current_y < it.last_visible_y
4663 && (it.current_y + it.max_ascent + it.max_descent
4664 >= it.last_visible_y))
4666 /* The last line was only partially visible, make it fully
4667 visible. */
4668 w->vscroll = (it.last_visible_y
4669 - it.current_y + it.max_ascent + it.max_descent);
4670 adjust_glyphs (it.f);
4672 else if (noerror)
4673 return;
4674 else
4675 Fsignal (Qend_of_buffer, Qnil);
4677 else
4679 if (w->vscroll != 0)
4680 /* The first line was only partially visible, make it fully
4681 visible. */
4682 w->vscroll = 0;
4683 else if (noerror)
4684 return;
4685 else
4686 Fsignal (Qbeginning_of_buffer, Qnil);
4689 /* If control gets here, then we vscrolled. */
4691 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
4693 /* Don't try to change the window start below. */
4694 vscrolled = 1;
4697 if (! vscrolled)
4699 int pos = IT_CHARPOS (it);
4700 int bytepos;
4702 /* If in the middle of a multi-glyph character move forward to
4703 the next character. */
4704 if (in_display_vector_p (&it))
4706 ++pos;
4707 move_it_to (&it, pos, -1, -1, -1, MOVE_TO_POS);
4710 /* Set the window start, and set up the window for redisplay. */
4711 set_marker_restricted (w->start, make_number (pos),
4712 w->buffer);
4713 bytepos = XMARKER (w->start)->bytepos;
4714 w->start_at_line_beg = ((pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n')
4715 ? Qt : Qnil);
4716 w->update_mode_line = Qt;
4717 XSETFASTINT (w->last_modified, 0);
4718 XSETFASTINT (w->last_overlay_modified, 0);
4719 /* Set force_start so that redisplay_window will run the
4720 window-scroll-functions. */
4721 w->force_start = Qt;
4724 /* The rest of this function uses current_y in a nonstandard way,
4725 not including the height of the header line if any. */
4726 it.current_y = it.vpos = 0;
4728 /* Move PT out of scroll margins.
4729 This code wants current_y to be zero at the window start position
4730 even if there is a header line. */
4731 this_scroll_margin = max (0, scroll_margin);
4732 this_scroll_margin = min (this_scroll_margin, XFASTINT (w->total_lines) / 4);
4733 this_scroll_margin *= FRAME_LINE_HEIGHT (it.f);
4735 if (n > 0)
4737 /* We moved the window start towards ZV, so PT may be now
4738 in the scroll margin at the top. */
4739 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
4740 if (IT_CHARPOS (it) == PT && it.current_y >= this_scroll_margin)
4741 /* We found PT at a legitimate height. Leave it alone. */
4743 else if (preserve_y >= 0)
4745 /* If we have a header line, take account of it.
4746 This is necessary because we set it.current_y to 0, above. */
4747 if (WINDOW_WANTS_HEADER_LINE_P (w))
4748 preserve_y -= CURRENT_HEADER_LINE_HEIGHT (w);
4750 move_it_to (&it, -1, -1, preserve_y, -1, MOVE_TO_Y);
4751 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4753 else
4755 while (it.current_y < this_scroll_margin)
4757 int prev = it.current_y;
4758 move_it_by_lines (&it, 1, 1);
4759 if (prev == it.current_y)
4760 break;
4762 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4765 else if (n < 0)
4767 int charpos, bytepos;
4768 int partial_p;
4770 /* Save our position, for the preserve_y case. */
4771 charpos = IT_CHARPOS (it);
4772 bytepos = IT_BYTEPOS (it);
4774 /* We moved the window start towards BEGV, so PT may be now
4775 in the scroll margin at the bottom. */
4776 move_it_to (&it, PT, -1,
4777 it.last_visible_y - this_scroll_margin - 1, -1,
4778 MOVE_TO_POS | MOVE_TO_Y);
4780 /* Save our position, in case it's correct. */
4781 charpos = IT_CHARPOS (it);
4782 bytepos = IT_BYTEPOS (it);
4784 /* See if point is on a partially visible line at the end. */
4785 if (it.what == IT_EOB)
4786 partial_p = it.current_y + it.ascent + it.descent > it.last_visible_y;
4787 else
4789 move_it_by_lines (&it, 1, 1);
4790 partial_p = it.current_y > it.last_visible_y;
4793 if (charpos == PT && !partial_p)
4794 /* We found PT before we found the display margin, so PT is ok. */
4796 else if (preserve_y >= 0)
4798 SET_TEXT_POS_FROM_MARKER (start, w->start);
4799 start_display (&it, w, start);
4800 #if 0 /* It's wrong to subtract this here
4801 because we called start_display again
4802 and did not alter it.current_y this time. */
4804 /* If we have a header line, take account of it. */
4805 if (WINDOW_WANTS_HEADER_LINE_P (w))
4806 preserve_y -= CURRENT_HEADER_LINE_HEIGHT (w);
4807 #endif
4809 move_it_to (&it, -1, -1, preserve_y, -1, MOVE_TO_Y);
4810 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4812 else
4814 if (partial_p)
4815 /* The last line was only partially visible, so back up two
4816 lines to make sure we're on a fully visible line. */
4818 move_it_by_lines (&it, -2, 0);
4819 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4821 else
4822 /* No, the position we saved is OK, so use it. */
4823 SET_PT_BOTH (charpos, bytepos);
4829 /* Implementation of window_scroll that works based on screen lines.
4830 See the comment of window_scroll for parameter descriptions. */
4832 static void
4833 window_scroll_line_based (window, n, whole, noerror)
4834 Lisp_Object window;
4835 int n;
4836 int whole;
4837 int noerror;
4839 register struct window *w = XWINDOW (window);
4840 register int opoint = PT, opoint_byte = PT_BYTE;
4841 register int pos, pos_byte;
4842 register int ht = window_internal_height (w);
4843 register Lisp_Object tem;
4844 int lose;
4845 Lisp_Object bolp;
4846 int startpos;
4847 struct position posit;
4848 int original_vpos;
4850 /* If scrolling screen-fulls, compute the number of lines to
4851 scroll from the window's height. */
4852 if (whole)
4853 n *= max (1, ht - next_screen_context_lines);
4855 startpos = marker_position (w->start);
4857 posit = *compute_motion (startpos, 0, 0, 0,
4858 PT, ht, 0,
4859 -1, XINT (w->hscroll),
4860 0, w);
4861 original_vpos = posit.vpos;
4863 XSETFASTINT (tem, PT);
4864 tem = Fpos_visible_in_window_p (tem, window, Qnil);
4866 if (NILP (tem))
4868 Fvertical_motion (make_number (- (ht / 2)), window);
4869 startpos = PT;
4872 SET_PT (startpos);
4873 lose = n < 0 && PT == BEGV;
4874 Fvertical_motion (make_number (n), window);
4875 pos = PT;
4876 pos_byte = PT_BYTE;
4877 bolp = Fbolp ();
4878 SET_PT_BOTH (opoint, opoint_byte);
4880 if (lose)
4882 if (noerror)
4883 return;
4884 else
4885 Fsignal (Qbeginning_of_buffer, Qnil);
4888 if (pos < ZV)
4890 int this_scroll_margin = scroll_margin;
4892 /* Don't use a scroll margin that is negative or too large. */
4893 if (this_scroll_margin < 0)
4894 this_scroll_margin = 0;
4896 if (XINT (w->total_lines) < 4 * scroll_margin)
4897 this_scroll_margin = XINT (w->total_lines) / 4;
4899 set_marker_restricted_both (w->start, w->buffer, pos, pos_byte);
4900 w->start_at_line_beg = bolp;
4901 w->update_mode_line = Qt;
4902 XSETFASTINT (w->last_modified, 0);
4903 XSETFASTINT (w->last_overlay_modified, 0);
4904 /* Set force_start so that redisplay_window will run
4905 the window-scroll-functions. */
4906 w->force_start = Qt;
4908 if (whole && !NILP (Vscroll_preserve_screen_position))
4910 SET_PT_BOTH (pos, pos_byte);
4911 Fvertical_motion (make_number (original_vpos), window);
4913 /* If we scrolled forward, put point enough lines down
4914 that it is outside the scroll margin. */
4915 else if (n > 0)
4917 int top_margin;
4919 if (this_scroll_margin > 0)
4921 SET_PT_BOTH (pos, pos_byte);
4922 Fvertical_motion (make_number (this_scroll_margin), window);
4923 top_margin = PT;
4925 else
4926 top_margin = pos;
4928 if (top_margin <= opoint)
4929 SET_PT_BOTH (opoint, opoint_byte);
4930 else if (!NILP (Vscroll_preserve_screen_position))
4932 SET_PT_BOTH (pos, pos_byte);
4933 Fvertical_motion (make_number (original_vpos), window);
4935 else
4936 SET_PT (top_margin);
4938 else if (n < 0)
4940 int bottom_margin;
4942 /* If we scrolled backward, put point near the end of the window
4943 but not within the scroll margin. */
4944 SET_PT_BOTH (pos, pos_byte);
4945 tem = Fvertical_motion (make_number (ht - this_scroll_margin), window);
4946 if (XFASTINT (tem) == ht - this_scroll_margin)
4947 bottom_margin = PT;
4948 else
4949 bottom_margin = PT + 1;
4951 if (bottom_margin > opoint)
4952 SET_PT_BOTH (opoint, opoint_byte);
4953 else
4955 if (!NILP (Vscroll_preserve_screen_position))
4957 SET_PT_BOTH (pos, pos_byte);
4958 Fvertical_motion (make_number (original_vpos), window);
4960 else
4961 Fvertical_motion (make_number (-1), window);
4965 else
4967 if (noerror)
4968 return;
4969 else
4970 Fsignal (Qend_of_buffer, Qnil);
4975 /* Scroll selected_window up or down. If N is nil, scroll a
4976 screen-full which is defined as the height of the window minus
4977 next_screen_context_lines. If N is the symbol `-', scroll.
4978 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4979 up. This is the guts of Fscroll_up and Fscroll_down. */
4981 static void
4982 scroll_command (n, direction)
4983 Lisp_Object n;
4984 int direction;
4986 int count = SPECPDL_INDEX ();
4988 xassert (abs (direction) == 1);
4990 /* If selected window's buffer isn't current, make it current for
4991 the moment. But don't screw up if window_scroll gets an error. */
4992 if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
4994 record_unwind_protect (save_excursion_restore, save_excursion_save ());
4995 Fset_buffer (XWINDOW (selected_window)->buffer);
4997 /* Make redisplay consider other windows than just selected_window. */
4998 ++windows_or_buffers_changed;
5001 if (NILP (n))
5002 window_scroll (selected_window, direction, 1, 0);
5003 else if (EQ (n, Qminus))
5004 window_scroll (selected_window, -direction, 1, 0);
5005 else
5007 n = Fprefix_numeric_value (n);
5008 window_scroll (selected_window, XINT (n) * direction, 0, 0);
5011 unbind_to (count, Qnil);
5014 DEFUN ("scroll-up", Fscroll_up, Sscroll_up, 0, 1, "P",
5015 doc: /* Scroll text of current window upward ARG lines.
5016 If ARG is omitted or nil, scroll upward by a near full screen.
5017 A near full screen is `next-screen-context-lines' less than a full screen.
5018 Negative ARG means scroll downward.
5019 If ARG is the atom `-', scroll downward by nearly full screen.
5020 When calling from a program, supply as argument a number, nil, or `-'. */)
5021 (arg)
5022 Lisp_Object arg;
5024 scroll_command (arg, 1);
5025 return Qnil;
5028 DEFUN ("scroll-down", Fscroll_down, Sscroll_down, 0, 1, "P",
5029 doc: /* Scroll text of current window down ARG lines.
5030 If ARG is omitted or nil, scroll down by a near full screen.
5031 A near full screen is `next-screen-context-lines' less than a full screen.
5032 Negative ARG means scroll upward.
5033 If ARG is the atom `-', scroll upward by nearly full screen.
5034 When calling from a program, supply as argument a number, nil, or `-'. */)
5035 (arg)
5036 Lisp_Object arg;
5038 scroll_command (arg, -1);
5039 return Qnil;
5042 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling, Sother_window_for_scrolling, 0, 0, 0,
5043 doc: /* Return the other window for \"other window scroll\" commands.
5044 If `other-window-scroll-buffer' is non-nil, a window
5045 showing that buffer is used.
5046 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5047 specifies the window. This takes precedence over
5048 `other-window-scroll-buffer'. */)
5051 Lisp_Object window;
5053 if (MINI_WINDOW_P (XWINDOW (selected_window))
5054 && !NILP (Vminibuf_scroll_window))
5055 window = Vminibuf_scroll_window;
5056 /* If buffer is specified, scroll that buffer. */
5057 else if (!NILP (Vother_window_scroll_buffer))
5059 window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil);
5060 if (NILP (window))
5061 window = Fdisplay_buffer (Vother_window_scroll_buffer, Qt, Qnil);
5063 else
5065 /* Nothing specified; look for a neighboring window on the same
5066 frame. */
5067 window = Fnext_window (selected_window, Qnil, Qnil);
5069 if (EQ (window, selected_window))
5070 /* That didn't get us anywhere; look for a window on another
5071 visible frame. */
5073 window = Fnext_window (window, Qnil, Qt);
5074 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window))))
5075 && ! EQ (window, selected_window));
5078 CHECK_LIVE_WINDOW (window);
5080 if (EQ (window, selected_window))
5081 error ("There is no other window");
5083 return window;
5086 DEFUN ("scroll-other-window", Fscroll_other_window, Sscroll_other_window, 0, 1, "P",
5087 doc: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5088 A near full screen is `next-screen-context-lines' less than a full screen.
5089 The next window is the one below the current one; or the one at the top
5090 if the current one is at the bottom. Negative ARG means scroll downward.
5091 If ARG is the atom `-', scroll downward by nearly full screen.
5092 When calling from a program, supply as argument a number, nil, or `-'.
5094 If `other-window-scroll-buffer' is non-nil, scroll the window
5095 showing that buffer, popping the buffer up if necessary.
5096 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5097 specifies the window to scroll. This takes precedence over
5098 `other-window-scroll-buffer'. */)
5099 (arg)
5100 Lisp_Object arg;
5102 Lisp_Object window;
5103 struct window *w;
5104 int count = SPECPDL_INDEX ();
5106 window = Fother_window_for_scrolling ();
5107 w = XWINDOW (window);
5109 /* Don't screw up if window_scroll gets an error. */
5110 record_unwind_protect (save_excursion_restore, save_excursion_save ());
5111 ++windows_or_buffers_changed;
5113 Fset_buffer (w->buffer);
5114 SET_PT (marker_position (w->pointm));
5116 if (NILP (arg))
5117 window_scroll (window, 1, 1, 1);
5118 else if (EQ (arg, Qminus))
5119 window_scroll (window, -1, 1, 1);
5120 else
5122 if (CONSP (arg))
5123 arg = Fcar (arg);
5124 CHECK_NUMBER (arg);
5125 window_scroll (window, XINT (arg), 0, 1);
5128 set_marker_both (w->pointm, Qnil, PT, PT_BYTE);
5129 unbind_to (count, Qnil);
5131 return Qnil;
5134 DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 2, "P\np",
5135 doc: /* Scroll selected window display ARG columns left.
5136 Default for ARG is window width minus 2.
5137 Value is the total amount of leftward horizontal scrolling in
5138 effect after the change.
5139 If SET_MINIMUM is non-nil, the new scroll amount becomes the
5140 lower bound for automatic scrolling, i.e. automatic scrolling
5141 will not scroll a window to a column less than the value returned
5142 by this function. This happens in an interactive call. */)
5143 (arg, set_minimum)
5144 register Lisp_Object arg, set_minimum;
5146 Lisp_Object result;
5147 int hscroll;
5148 struct window *w = XWINDOW (selected_window);
5150 if (NILP (arg))
5151 XSETFASTINT (arg, window_box_text_cols (w) - 2);
5152 else
5153 arg = Fprefix_numeric_value (arg);
5155 hscroll = XINT (w->hscroll) + XINT (arg);
5156 result = Fset_window_hscroll (selected_window, make_number (hscroll));
5158 if (!NILP (set_minimum))
5159 w->min_hscroll = w->hscroll;
5161 return result;
5164 DEFUN ("scroll-right", Fscroll_right, Sscroll_right, 0, 2, "P\np",
5165 doc: /* Scroll selected window display ARG columns right.
5166 Default for ARG is window width minus 2.
5167 Value is the total amount of leftward horizontal scrolling in
5168 effect after the change.
5169 If SET_MINIMUM is non-nil, the new scroll amount becomes the
5170 lower bound for automatic scrolling, i.e. automatic scrolling
5171 will not scroll a window to a column less than the value returned
5172 by this function. This happens in an interactive call. */)
5173 (arg, set_minimum)
5174 register Lisp_Object arg, set_minimum;
5176 Lisp_Object result;
5177 int hscroll;
5178 struct window *w = XWINDOW (selected_window);
5180 if (NILP (arg))
5181 XSETFASTINT (arg, window_box_text_cols (w) - 2);
5182 else
5183 arg = Fprefix_numeric_value (arg);
5185 hscroll = XINT (w->hscroll) - XINT (arg);
5186 result = Fset_window_hscroll (selected_window, make_number (hscroll));
5188 if (!NILP (set_minimum))
5189 w->min_hscroll = w->hscroll;
5191 return result;
5194 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window, Sminibuffer_selected_window, 0, 0, 0,
5195 doc: /* Return the window which was selected when entering the minibuffer.
5196 Returns nil, if current window is not a minibuffer window. */)
5199 if (minibuf_level > 0
5200 && MINI_WINDOW_P (XWINDOW (selected_window))
5201 && WINDOW_LIVE_P (minibuf_selected_window))
5202 return minibuf_selected_window;
5204 return Qnil;
5207 /* Value is the number of lines actually displayed in window W,
5208 as opposed to its height. */
5210 static int
5211 displayed_window_lines (w)
5212 struct window *w;
5214 struct it it;
5215 struct text_pos start;
5216 int height = window_box_height (w);
5217 struct buffer *old_buffer;
5218 int bottom_y;
5220 if (XBUFFER (w->buffer) != current_buffer)
5222 old_buffer = current_buffer;
5223 set_buffer_internal (XBUFFER (w->buffer));
5225 else
5226 old_buffer = NULL;
5228 /* In case W->start is out of the accessible range, do something
5229 reasonable. This happens in Info mode when Info-scroll-down
5230 calls (recenter -1) while W->start is 1. */
5231 if (XMARKER (w->start)->charpos < BEGV)
5232 SET_TEXT_POS (start, BEGV, BEGV_BYTE);
5233 else if (XMARKER (w->start)->charpos > ZV)
5234 SET_TEXT_POS (start, ZV, ZV_BYTE);
5235 else
5236 SET_TEXT_POS_FROM_MARKER (start, w->start);
5238 start_display (&it, w, start);
5239 move_it_vertically (&it, height);
5240 bottom_y = line_bottom_y (&it);
5242 /* rms: On a non-window display,
5243 the value of it.vpos at the bottom of the screen
5244 seems to be 1 larger than window_box_height (w).
5245 This kludge fixes a bug whereby (move-to-window-line -1)
5246 when ZV is on the last screen line
5247 moves to the previous screen line instead of the last one. */
5248 if (! FRAME_WINDOW_P (XFRAME (w->frame)))
5249 height++;
5251 /* Add in empty lines at the bottom of the window. */
5252 if (bottom_y < height)
5254 int uy = FRAME_LINE_HEIGHT (it.f);
5255 it.vpos += (height - bottom_y + uy - 1) / uy;
5258 if (old_buffer)
5259 set_buffer_internal (old_buffer);
5261 return it.vpos;
5265 DEFUN ("recenter", Frecenter, Srecenter, 0, 1, "P",
5266 doc: /* Center point in window and redisplay frame.
5267 With prefix argument ARG, recenter putting point on screen line ARG
5268 relative to the current window. If ARG is negative, it counts up from the
5269 bottom of the window. (ARG should be less than the height of the window.)
5271 If ARG is omitted or nil, erase the entire frame and then
5272 redraw with point in the center of the current window.
5273 Just C-u as prefix means put point in the center of the window
5274 and redisplay normally--don't erase and redraw the frame. */)
5275 (arg)
5276 register Lisp_Object arg;
5278 struct window *w = XWINDOW (selected_window);
5279 struct buffer *buf = XBUFFER (w->buffer);
5280 struct buffer *obuf = current_buffer;
5281 int center_p = 0;
5282 int charpos, bytepos;
5284 /* If redisplay is suppressed due to an error, try again. */
5285 obuf->display_error_modiff = 0;
5287 if (NILP (arg))
5289 int i;
5291 /* Invalidate pixel data calculated for all compositions. */
5292 for (i = 0; i < n_compositions; i++)
5293 composition_table[i]->font = NULL;
5295 Fredraw_frame (w->frame);
5296 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w)));
5297 center_p = 1;
5299 else if (CONSP (arg)) /* Just C-u. */
5300 center_p = 1;
5301 else
5303 arg = Fprefix_numeric_value (arg);
5304 CHECK_NUMBER (arg);
5307 set_buffer_internal (buf);
5309 /* Handle centering on a graphical frame specially. Such frames can
5310 have variable-height lines and centering point on the basis of
5311 line counts would lead to strange effects. */
5312 if (FRAME_WINDOW_P (XFRAME (w->frame)))
5314 if (center_p)
5316 struct it it;
5317 struct text_pos pt;
5319 SET_TEXT_POS (pt, PT, PT_BYTE);
5320 start_display (&it, w, pt);
5321 move_it_vertically_backward (&it, window_box_height (w) / 2);
5322 charpos = IT_CHARPOS (it);
5323 bytepos = IT_BYTEPOS (it);
5325 else if (XINT (arg) < 0)
5327 struct it it;
5328 struct text_pos pt;
5329 int nlines = - XINT (arg);
5330 int extra_line_spacing;
5331 int h = window_box_height (w);
5333 SET_TEXT_POS (pt, PT, PT_BYTE);
5334 start_display (&it, w, pt);
5336 /* Be sure we have the exact height of the full line containing PT. */
5337 move_it_by_lines (&it, 0, 1);
5339 /* The amount of pixels we have to move back is the window
5340 height minus what's displayed in the line containing PT,
5341 and the lines below. */
5342 it.current_y = 0;
5343 it.vpos = 0;
5344 move_it_by_lines (&it, nlines, 1);
5346 if (it.vpos == nlines)
5347 h -= it.current_y;
5348 else
5350 /* Last line has no newline */
5351 h -= line_bottom_y (&it);
5352 it.vpos++;
5355 /* Don't reserve space for extra line spacing of last line. */
5356 extra_line_spacing = it.max_extra_line_spacing;
5358 /* If we can't move down NLINES lines because we hit
5359 the end of the buffer, count in some empty lines. */
5360 if (it.vpos < nlines)
5362 nlines -= it.vpos;
5363 extra_line_spacing = it.extra_line_spacing;
5364 h -= nlines * (FRAME_LINE_HEIGHT (it.f) + extra_line_spacing);
5366 if (h <= 0)
5367 return Qnil;
5369 /* Now find the new top line (starting position) of the window. */
5370 start_display (&it, w, pt);
5371 it.current_y = 0;
5372 move_it_vertically_backward (&it, h);
5374 /* If extra line spacing is present, we may move too far
5375 back. This causes the last line to be only partially
5376 visible (which triggers redisplay to recenter that line
5377 in the middle), so move forward.
5378 But ignore extra line spacing on last line, as it is not
5379 considered to be part of the visible height of the line.
5381 h += extra_line_spacing;
5382 while (-it.current_y > h)
5383 move_it_by_lines (&it, 1, 1);
5385 charpos = IT_CHARPOS (it);
5386 bytepos = IT_BYTEPOS (it);
5388 else
5390 struct position pos;
5391 pos = *vmotion (PT, - XINT (arg), w);
5392 charpos = pos.bufpos;
5393 bytepos = pos.bytepos;
5396 else
5398 struct position pos;
5399 int ht = window_internal_height (w);
5401 if (center_p)
5402 arg = make_number (ht / 2);
5403 else if (XINT (arg) < 0)
5404 arg = make_number (XINT (arg) + ht);
5406 pos = *vmotion (PT, - XINT (arg), w);
5407 charpos = pos.bufpos;
5408 bytepos = pos.bytepos;
5411 /* Set the new window start. */
5412 set_marker_both (w->start, w->buffer, charpos, bytepos);
5413 w->window_end_valid = Qnil;
5415 w->optional_new_start = Qt;
5417 if (bytepos == BEGV_BYTE || FETCH_BYTE (bytepos - 1) == '\n')
5418 w->start_at_line_beg = Qt;
5419 else
5420 w->start_at_line_beg = Qnil;
5422 set_buffer_internal (obuf);
5423 return Qnil;
5427 DEFUN ("window-text-height", Fwindow_text_height, Swindow_text_height,
5428 0, 1, 0,
5429 doc: /* Return the height in lines of the text display area of WINDOW.
5430 This doesn't include the mode-line (or header-line if any) or any
5431 partial-height lines in the text display area. */)
5432 (window)
5433 Lisp_Object window;
5435 struct window *w = decode_window (window);
5436 int pixel_height = window_box_height (w);
5437 int line_height = pixel_height / FRAME_LINE_HEIGHT (XFRAME (w->frame));
5438 return make_number (line_height);
5443 DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line,
5444 1, 1, "P",
5445 doc: /* Position point relative to window.
5446 With no argument, position point at center of window.
5447 An argument specifies vertical position within the window;
5448 zero means top of window, negative means relative to bottom of window. */)
5449 (arg)
5450 Lisp_Object arg;
5452 struct window *w = XWINDOW (selected_window);
5453 int lines, start;
5454 Lisp_Object window;
5456 window = selected_window;
5457 start = marker_position (w->start);
5458 if (start < BEGV || start > ZV)
5460 int height = window_internal_height (w);
5461 Fvertical_motion (make_number (- (height / 2)), window);
5462 set_marker_both (w->start, w->buffer, PT, PT_BYTE);
5463 w->start_at_line_beg = Fbolp ();
5464 w->force_start = Qt;
5466 else
5467 Fgoto_char (w->start);
5469 lines = displayed_window_lines (w);
5470 if (NILP (arg))
5471 XSETFASTINT (arg, lines / 2);
5472 else
5474 arg = Fprefix_numeric_value (arg);
5475 if (XINT (arg) < 0)
5476 XSETINT (arg, XINT (arg) + lines);
5479 /* Skip past a partially visible first line. */
5480 if (w->vscroll)
5481 XSETINT (arg, XINT (arg) + 1);
5483 return Fvertical_motion (arg, window);
5488 /***********************************************************************
5489 Window Configuration
5490 ***********************************************************************/
5492 struct save_window_data
5494 EMACS_INT size_from_Lisp_Vector_struct;
5495 struct Lisp_Vector *next_from_Lisp_Vector_struct;
5496 Lisp_Object frame_cols, frame_lines, frame_menu_bar_lines;
5497 Lisp_Object frame_tool_bar_lines;
5498 Lisp_Object selected_frame;
5499 Lisp_Object current_window;
5500 Lisp_Object current_buffer;
5501 Lisp_Object minibuf_scroll_window;
5502 Lisp_Object minibuf_selected_window;
5503 Lisp_Object root_window;
5504 Lisp_Object focus_frame;
5505 /* Record the values of window-min-width and window-min-height
5506 so that window sizes remain consistent with them. */
5507 Lisp_Object min_width, min_height;
5508 /* A vector, each of whose elements is a struct saved_window
5509 for one window. */
5510 Lisp_Object saved_windows;
5513 /* This is saved as a Lisp_Vector */
5514 struct saved_window
5516 /* these first two must agree with struct Lisp_Vector in lisp.h */
5517 EMACS_INT size_from_Lisp_Vector_struct;
5518 struct Lisp_Vector *next_from_Lisp_Vector_struct;
5520 Lisp_Object window;
5521 Lisp_Object buffer, start, pointm, mark;
5522 Lisp_Object left_col, top_line, total_cols, total_lines;
5523 Lisp_Object hscroll, min_hscroll;
5524 Lisp_Object parent, prev;
5525 Lisp_Object start_at_line_beg;
5526 Lisp_Object display_table;
5527 Lisp_Object orig_top_line, orig_total_lines;
5528 Lisp_Object left_margin_cols, right_margin_cols;
5529 Lisp_Object left_fringe_width, right_fringe_width, fringes_outside_margins;
5530 Lisp_Object scroll_bar_width, vertical_scroll_bar_type;
5533 #define SAVED_WINDOW_VECTOR_SIZE 24 /* Arg to Fmake_vector */
5535 #define SAVED_WINDOW_N(swv,n) \
5536 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5538 DEFUN ("window-configuration-p", Fwindow_configuration_p, Swindow_configuration_p, 1, 1, 0,
5539 doc: /* Return t if OBJECT is a window-configuration object. */)
5540 (object)
5541 Lisp_Object object;
5543 if (WINDOW_CONFIGURATIONP (object))
5544 return Qt;
5545 return Qnil;
5548 DEFUN ("window-configuration-frame", Fwindow_configuration_frame, Swindow_configuration_frame, 1, 1, 0,
5549 doc: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5550 (config)
5551 Lisp_Object config;
5553 register struct save_window_data *data;
5554 struct Lisp_Vector *saved_windows;
5556 if (! WINDOW_CONFIGURATIONP (config))
5557 wrong_type_argument (Qwindow_configuration_p, config);
5559 data = (struct save_window_data *) XVECTOR (config);
5560 saved_windows = XVECTOR (data->saved_windows);
5561 return XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame;
5564 DEFUN ("set-window-configuration", Fset_window_configuration,
5565 Sset_window_configuration, 1, 1, 0,
5566 doc: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5567 CONFIGURATION must be a value previously returned
5568 by `current-window-configuration' (which see).
5569 If CONFIGURATION was made from a frame that is now deleted,
5570 only frame-independent values can be restored. In this case,
5571 the return value is nil. Otherwise the value is t. */)
5572 (configuration)
5573 Lisp_Object configuration;
5575 register struct save_window_data *data;
5576 struct Lisp_Vector *saved_windows;
5577 Lisp_Object new_current_buffer;
5578 Lisp_Object frame;
5579 FRAME_PTR f;
5580 int old_point = -1;
5582 while (!WINDOW_CONFIGURATIONP (configuration))
5583 wrong_type_argument (Qwindow_configuration_p, configuration);
5585 data = (struct save_window_data *) XVECTOR (configuration);
5586 saved_windows = XVECTOR (data->saved_windows);
5588 new_current_buffer = data->current_buffer;
5589 if (NILP (XBUFFER (new_current_buffer)->name))
5590 new_current_buffer = Qnil;
5591 else
5593 if (XBUFFER (new_current_buffer) == current_buffer)
5594 old_point = PT;
5595 else
5596 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
5597 point in new_current_buffer as of the last time this buffer was
5598 used. This can be non-deterministic since it can be changed by
5599 things like jit-lock by mere temporary selection of some random
5600 window that happens to show this buffer.
5601 So if possible we want this arbitrary choice of "which point" to
5602 be the one from the to-be-selected-window so as to prevent this
5603 window's cursor from being copied from another window. */
5604 if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer)
5605 /* If current_window = selected_window, its point is in BUF_PT. */
5606 && !EQ (selected_window, data->current_window))
5607 old_point = XMARKER (XWINDOW (data->current_window)->pointm)->charpos;
5608 else
5609 old_point = BUF_PT (XBUFFER (new_current_buffer));
5612 frame = XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame;
5613 f = XFRAME (frame);
5615 /* If f is a dead frame, don't bother rebuilding its window tree.
5616 However, there is other stuff we should still try to do below. */
5617 if (FRAME_LIVE_P (f))
5619 register struct window *w;
5620 register struct saved_window *p;
5621 struct window *root_window;
5622 struct window **leaf_windows;
5623 int n_leaf_windows;
5624 int k, i, n;
5626 /* If the frame has been resized since this window configuration was
5627 made, we change the frame to the size specified in the
5628 configuration, restore the configuration, and then resize it
5629 back. We keep track of the prevailing height in these variables. */
5630 int previous_frame_lines = FRAME_LINES (f);
5631 int previous_frame_cols = FRAME_COLS (f);
5632 int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
5633 int previous_frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f);
5635 /* The mouse highlighting code could get screwed up
5636 if it runs during this. */
5637 BLOCK_INPUT;
5639 if (XFASTINT (data->frame_lines) != previous_frame_lines
5640 || XFASTINT (data->frame_cols) != previous_frame_cols)
5641 change_frame_size (f, XFASTINT (data->frame_lines),
5642 XFASTINT (data->frame_cols), 0, 0, 0);
5643 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5644 if (XFASTINT (data->frame_menu_bar_lines)
5645 != previous_frame_menu_bar_lines)
5646 x_set_menu_bar_lines (f, data->frame_menu_bar_lines, make_number (0));
5647 #ifdef HAVE_WINDOW_SYSTEM
5648 if (XFASTINT (data->frame_tool_bar_lines)
5649 != previous_frame_tool_bar_lines)
5650 x_set_tool_bar_lines (f, data->frame_tool_bar_lines, make_number (0));
5651 #endif
5652 #endif
5654 /* "Swap out" point from the selected window's buffer
5655 into the window itself. (Normally the pointm of the selected
5656 window holds garbage.) We do this now, before
5657 restoring the window contents, and prevent it from
5658 being done later on when we select a new window. */
5659 if (! NILP (XWINDOW (selected_window)->buffer))
5661 w = XWINDOW (selected_window);
5662 set_marker_both (w->pointm,
5663 w->buffer,
5664 BUF_PT (XBUFFER (w->buffer)),
5665 BUF_PT_BYTE (XBUFFER (w->buffer)));
5668 windows_or_buffers_changed++;
5669 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
5671 /* Problem: Freeing all matrices and later allocating them again
5672 is a serious redisplay flickering problem. What we would
5673 really like to do is to free only those matrices not reused
5674 below. */
5675 root_window = XWINDOW (FRAME_ROOT_WINDOW (f));
5676 leaf_windows
5677 = (struct window **) alloca (count_windows (root_window)
5678 * sizeof (struct window *));
5679 n_leaf_windows = get_leaf_windows (root_window, leaf_windows, 0);
5681 /* Temporarily avoid any problems with windows that are smaller
5682 than they are supposed to be. */
5683 window_min_height = 1;
5684 window_min_width = 1;
5686 /* Kludge Alert!
5687 Mark all windows now on frame as "deleted".
5688 Restoring the new configuration "undeletes" any that are in it.
5690 Save their current buffers in their height fields, since we may
5691 need it later, if a buffer saved in the configuration is now
5692 dead. */
5693 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f)));
5695 for (k = 0; k < saved_windows->size; k++)
5697 p = SAVED_WINDOW_N (saved_windows, k);
5698 w = XWINDOW (p->window);
5699 w->next = Qnil;
5701 if (!NILP (p->parent))
5702 w->parent = SAVED_WINDOW_N (saved_windows,
5703 XFASTINT (p->parent))->window;
5704 else
5705 w->parent = Qnil;
5707 if (!NILP (p->prev))
5709 w->prev = SAVED_WINDOW_N (saved_windows,
5710 XFASTINT (p->prev))->window;
5711 XWINDOW (w->prev)->next = p->window;
5713 else
5715 w->prev = Qnil;
5716 if (!NILP (w->parent))
5718 if (EQ (p->total_cols, XWINDOW (w->parent)->total_cols))
5720 XWINDOW (w->parent)->vchild = p->window;
5721 XWINDOW (w->parent)->hchild = Qnil;
5723 else
5725 XWINDOW (w->parent)->hchild = p->window;
5726 XWINDOW (w->parent)->vchild = Qnil;
5731 /* If we squirreled away the buffer in the window's height,
5732 restore it now. */
5733 if (BUFFERP (w->total_lines))
5734 w->buffer = w->total_lines;
5735 w->left_col = p->left_col;
5736 w->top_line = p->top_line;
5737 w->total_cols = p->total_cols;
5738 w->total_lines = p->total_lines;
5739 w->hscroll = p->hscroll;
5740 w->min_hscroll = p->min_hscroll;
5741 w->display_table = p->display_table;
5742 w->orig_top_line = p->orig_top_line;
5743 w->orig_total_lines = p->orig_total_lines;
5744 w->left_margin_cols = p->left_margin_cols;
5745 w->right_margin_cols = p->right_margin_cols;
5746 w->left_fringe_width = p->left_fringe_width;
5747 w->right_fringe_width = p->right_fringe_width;
5748 w->fringes_outside_margins = p->fringes_outside_margins;
5749 w->scroll_bar_width = p->scroll_bar_width;
5750 w->vertical_scroll_bar_type = p->vertical_scroll_bar_type;
5751 XSETFASTINT (w->last_modified, 0);
5752 XSETFASTINT (w->last_overlay_modified, 0);
5754 /* Reinstall the saved buffer and pointers into it. */
5755 if (NILP (p->buffer))
5756 w->buffer = p->buffer;
5757 else
5759 if (!NILP (XBUFFER (p->buffer)->name))
5760 /* If saved buffer is alive, install it. */
5762 w->buffer = p->buffer;
5763 w->start_at_line_beg = p->start_at_line_beg;
5764 set_marker_restricted (w->start, p->start, w->buffer);
5765 set_marker_restricted (w->pointm, p->pointm, w->buffer);
5766 Fset_marker (XBUFFER (w->buffer)->mark,
5767 p->mark, w->buffer);
5769 /* As documented in Fcurrent_window_configuration, don't
5770 restore the location of point in the buffer which was
5771 current when the window configuration was recorded. */
5772 if (!EQ (p->buffer, new_current_buffer)
5773 && XBUFFER (p->buffer) == current_buffer)
5774 Fgoto_char (w->pointm);
5776 else if (NILP (w->buffer) || NILP (XBUFFER (w->buffer)->name))
5777 /* Else unless window has a live buffer, get one. */
5779 w->buffer = Fcdr (Fcar (Vbuffer_alist));
5780 /* This will set the markers to beginning of visible
5781 range. */
5782 set_marker_restricted (w->start, make_number (0), w->buffer);
5783 set_marker_restricted (w->pointm, make_number (0),w->buffer);
5784 w->start_at_line_beg = Qt;
5786 else
5787 /* Keeping window's old buffer; make sure the markers
5788 are real. */
5790 /* Set window markers at start of visible range. */
5791 if (XMARKER (w->start)->buffer == 0)
5792 set_marker_restricted (w->start, make_number (0),
5793 w->buffer);
5794 if (XMARKER (w->pointm)->buffer == 0)
5795 set_marker_restricted_both (w->pointm, w->buffer,
5796 BUF_PT (XBUFFER (w->buffer)),
5797 BUF_PT_BYTE (XBUFFER (w->buffer)));
5798 w->start_at_line_beg = Qt;
5803 FRAME_ROOT_WINDOW (f) = data->root_window;
5804 /* Prevent "swapping out point" in the old selected window
5805 using the buffer that has been restored into it.
5806 We already swapped out point that from that window's old buffer. */
5807 selected_window = Qnil;
5809 /* Arrange *not* to restore point in the buffer that was
5810 current when the window configuration was saved. */
5811 if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer))
5812 set_marker_restricted (XWINDOW (data->current_window)->pointm,
5813 make_number (old_point),
5814 XWINDOW (data->current_window)->buffer);
5816 Fselect_window (data->current_window, Qnil);
5817 XBUFFER (XWINDOW (selected_window)->buffer)->last_selected_window
5818 = selected_window;
5820 if (NILP (data->focus_frame)
5821 || (FRAMEP (data->focus_frame)
5822 && FRAME_LIVE_P (XFRAME (data->focus_frame))))
5823 Fredirect_frame_focus (frame, data->focus_frame);
5825 #if 0 /* I don't understand why this is needed, and it causes problems
5826 when the frame's old selected window has been deleted. */
5827 if (f != selected_frame && FRAME_WINDOW_P (f))
5828 do_switch_frame (WINDOW_FRAME (XWINDOW (data->root_window)),
5829 0, 0);
5830 #endif
5832 /* Set the screen height to the value it had before this function. */
5833 if (previous_frame_lines != FRAME_LINES (f)
5834 || previous_frame_cols != FRAME_COLS (f))
5835 change_frame_size (f, previous_frame_lines, previous_frame_cols,
5836 0, 0, 0);
5837 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5838 if (previous_frame_menu_bar_lines != FRAME_MENU_BAR_LINES (f))
5839 x_set_menu_bar_lines (f, make_number (previous_frame_menu_bar_lines),
5840 make_number (0));
5841 #ifdef HAVE_WINDOW_SYSTEM
5842 if (previous_frame_tool_bar_lines != FRAME_TOOL_BAR_LINES (f))
5843 x_set_tool_bar_lines (f, make_number (previous_frame_tool_bar_lines),
5844 make_number (0));
5845 #endif
5846 #endif
5848 /* Now, free glyph matrices in windows that were not reused. */
5849 for (i = n = 0; i < n_leaf_windows; ++i)
5851 if (NILP (leaf_windows[i]->buffer))
5853 /* Assert it's not reused as a combination. */
5854 xassert (NILP (leaf_windows[i]->hchild)
5855 && NILP (leaf_windows[i]->vchild));
5856 free_window_matrices (leaf_windows[i]);
5858 else if (EQ (leaf_windows[i]->buffer, new_current_buffer))
5859 ++n;
5862 adjust_glyphs (f);
5864 UNBLOCK_INPUT;
5866 /* Fselect_window will have made f the selected frame, so we
5867 reselect the proper frame here. Fhandle_switch_frame will change the
5868 selected window too, but that doesn't make the call to
5869 Fselect_window above totally superfluous; it still sets f's
5870 selected window. */
5871 if (FRAME_LIVE_P (XFRAME (data->selected_frame)))
5872 do_switch_frame (data->selected_frame, 0, 0);
5874 if (! NILP (Vwindow_configuration_change_hook)
5875 && ! NILP (Vrun_hooks))
5876 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
5879 if (!NILP (new_current_buffer))
5880 Fset_buffer (new_current_buffer);
5882 /* Restore the minimum heights recorded in the configuration. */
5883 window_min_height = XINT (data->min_height);
5884 window_min_width = XINT (data->min_width);
5886 Vminibuf_scroll_window = data->minibuf_scroll_window;
5887 minibuf_selected_window = data->minibuf_selected_window;
5889 return (FRAME_LIVE_P (f) ? Qt : Qnil);
5892 /* Mark all windows now on frame as deleted
5893 by setting their buffers to nil. */
5895 void
5896 delete_all_subwindows (w)
5897 register struct window *w;
5899 if (!NILP (w->next))
5900 delete_all_subwindows (XWINDOW (w->next));
5901 if (!NILP (w->vchild))
5902 delete_all_subwindows (XWINDOW (w->vchild));
5903 if (!NILP (w->hchild))
5904 delete_all_subwindows (XWINDOW (w->hchild));
5906 w->total_lines = w->buffer; /* See Fset_window_configuration for excuse. */
5908 if (!NILP (w->buffer))
5909 unshow_buffer (w);
5911 /* We set all three of these fields to nil, to make sure that we can
5912 distinguish this dead window from any live window. Live leaf
5913 windows will have buffer set, and combination windows will have
5914 vchild or hchild set. */
5915 w->buffer = Qnil;
5916 w->vchild = Qnil;
5917 w->hchild = Qnil;
5919 Vwindow_list = Qnil;
5922 static int
5923 count_windows (window)
5924 register struct window *window;
5926 register int count = 1;
5927 if (!NILP (window->next))
5928 count += count_windows (XWINDOW (window->next));
5929 if (!NILP (window->vchild))
5930 count += count_windows (XWINDOW (window->vchild));
5931 if (!NILP (window->hchild))
5932 count += count_windows (XWINDOW (window->hchild));
5933 return count;
5937 /* Fill vector FLAT with leaf windows under W, starting at index I.
5938 Value is last index + 1. */
5940 static int
5941 get_leaf_windows (w, flat, i)
5942 struct window *w;
5943 struct window **flat;
5944 int i;
5946 while (w)
5948 if (!NILP (w->hchild))
5949 i = get_leaf_windows (XWINDOW (w->hchild), flat, i);
5950 else if (!NILP (w->vchild))
5951 i = get_leaf_windows (XWINDOW (w->vchild), flat, i);
5952 else
5953 flat[i++] = w;
5955 w = NILP (w->next) ? 0 : XWINDOW (w->next);
5958 return i;
5962 /* Return a pointer to the glyph W's physical cursor is on. Value is
5963 null if W's current matrix is invalid, so that no meaningfull glyph
5964 can be returned. */
5966 struct glyph *
5967 get_phys_cursor_glyph (w)
5968 struct window *w;
5970 struct glyph_row *row;
5971 struct glyph *glyph;
5973 if (w->phys_cursor.vpos >= 0
5974 && w->phys_cursor.vpos < w->current_matrix->nrows
5975 && (row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos),
5976 row->enabled_p)
5977 && row->used[TEXT_AREA] > w->phys_cursor.hpos)
5978 glyph = row->glyphs[TEXT_AREA] + w->phys_cursor.hpos;
5979 else
5980 glyph = NULL;
5982 return glyph;
5986 static int
5987 save_window_save (window, vector, i)
5988 Lisp_Object window;
5989 struct Lisp_Vector *vector;
5990 int i;
5992 register struct saved_window *p;
5993 register struct window *w;
5994 register Lisp_Object tem;
5996 for (;!NILP (window); window = w->next)
5998 p = SAVED_WINDOW_N (vector, i);
5999 w = XWINDOW (window);
6001 XSETFASTINT (w->temslot, i); i++;
6002 p->window = window;
6003 p->buffer = w->buffer;
6004 p->left_col = w->left_col;
6005 p->top_line = w->top_line;
6006 p->total_cols = w->total_cols;
6007 p->total_lines = w->total_lines;
6008 p->hscroll = w->hscroll;
6009 p->min_hscroll = w->min_hscroll;
6010 p->display_table = w->display_table;
6011 p->orig_top_line = w->orig_top_line;
6012 p->orig_total_lines = w->orig_total_lines;
6013 p->left_margin_cols = w->left_margin_cols;
6014 p->right_margin_cols = w->right_margin_cols;
6015 p->left_fringe_width = w->left_fringe_width;
6016 p->right_fringe_width = w->right_fringe_width;
6017 p->fringes_outside_margins = w->fringes_outside_margins;
6018 p->scroll_bar_width = w->scroll_bar_width;
6019 p->vertical_scroll_bar_type = w->vertical_scroll_bar_type;
6020 if (!NILP (w->buffer))
6022 /* Save w's value of point in the window configuration.
6023 If w is the selected window, then get the value of point
6024 from the buffer; pointm is garbage in the selected window. */
6025 if (EQ (window, selected_window))
6027 p->pointm = Fmake_marker ();
6028 set_marker_both (p->pointm, w->buffer,
6029 BUF_PT (XBUFFER (w->buffer)),
6030 BUF_PT_BYTE (XBUFFER (w->buffer)));
6032 else
6033 p->pointm = Fcopy_marker (w->pointm, Qnil);
6035 p->start = Fcopy_marker (w->start, Qnil);
6036 p->start_at_line_beg = w->start_at_line_beg;
6038 tem = XBUFFER (w->buffer)->mark;
6039 p->mark = Fcopy_marker (tem, Qnil);
6041 else
6043 p->pointm = Qnil;
6044 p->start = Qnil;
6045 p->mark = Qnil;
6046 p->start_at_line_beg = Qnil;
6049 if (NILP (w->parent))
6050 p->parent = Qnil;
6051 else
6052 p->parent = XWINDOW (w->parent)->temslot;
6054 if (NILP (w->prev))
6055 p->prev = Qnil;
6056 else
6057 p->prev = XWINDOW (w->prev)->temslot;
6059 if (!NILP (w->vchild))
6060 i = save_window_save (w->vchild, vector, i);
6061 if (!NILP (w->hchild))
6062 i = save_window_save (w->hchild, vector, i);
6065 return i;
6068 DEFUN ("current-window-configuration", Fcurrent_window_configuration,
6069 Scurrent_window_configuration, 0, 1, 0,
6070 doc: /* Return an object representing the current window configuration of FRAME.
6071 If FRAME is nil or omitted, use the selected frame.
6072 This describes the number of windows, their sizes and current buffers,
6073 and for each displayed buffer, where display starts, and the positions of
6074 point and mark. An exception is made for point in the current buffer:
6075 its value is -not- saved.
6076 This also records the currently selected frame, and FRAME's focus
6077 redirection (see `redirect-frame-focus'). */)
6078 (frame)
6079 Lisp_Object frame;
6081 register Lisp_Object tem;
6082 register int n_windows;
6083 register struct save_window_data *data;
6084 register struct Lisp_Vector *vec;
6085 register int i;
6086 FRAME_PTR f;
6088 if (NILP (frame))
6089 frame = selected_frame;
6090 CHECK_LIVE_FRAME (frame);
6091 f = XFRAME (frame);
6093 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
6094 vec = allocate_other_vector (VECSIZE (struct save_window_data));
6095 data = (struct save_window_data *)vec;
6097 XSETFASTINT (data->frame_cols, FRAME_COLS (f));
6098 XSETFASTINT (data->frame_lines, FRAME_LINES (f));
6099 XSETFASTINT (data->frame_menu_bar_lines, FRAME_MENU_BAR_LINES (f));
6100 XSETFASTINT (data->frame_tool_bar_lines, FRAME_TOOL_BAR_LINES (f));
6101 data->selected_frame = selected_frame;
6102 data->current_window = FRAME_SELECTED_WINDOW (f);
6103 XSETBUFFER (data->current_buffer, current_buffer);
6104 data->minibuf_scroll_window = minibuf_level > 0 ? Vminibuf_scroll_window : Qnil;
6105 data->minibuf_selected_window = minibuf_level > 0 ? minibuf_selected_window : Qnil;
6106 data->root_window = FRAME_ROOT_WINDOW (f);
6107 data->focus_frame = FRAME_FOCUS_FRAME (f);
6108 XSETINT (data->min_height, window_min_height);
6109 XSETINT (data->min_width, window_min_width);
6110 tem = Fmake_vector (make_number (n_windows), Qnil);
6111 data->saved_windows = tem;
6112 for (i = 0; i < n_windows; i++)
6113 XVECTOR (tem)->contents[i]
6114 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE), Qnil);
6115 save_window_save (FRAME_ROOT_WINDOW (f), XVECTOR (tem), 0);
6116 XSETWINDOW_CONFIGURATION (tem, data);
6117 return (tem);
6120 DEFUN ("save-window-excursion", Fsave_window_excursion, Ssave_window_excursion,
6121 0, UNEVALLED, 0,
6122 doc: /* Execute BODY, preserving window sizes and contents.
6123 Return the value of the last form in BODY.
6124 Restore which buffer appears in which window, where display starts,
6125 and the value of point and mark for each window.
6126 Also restore the choice of selected window.
6127 Also restore which buffer is current.
6128 Does not restore the value of point in current buffer.
6129 usage: (save-window-excursion BODY ...) */)
6130 (args)
6131 Lisp_Object args;
6133 register Lisp_Object val;
6134 register int count = SPECPDL_INDEX ();
6136 record_unwind_protect (Fset_window_configuration,
6137 Fcurrent_window_configuration (Qnil));
6138 val = Fprogn (args);
6139 return unbind_to (count, val);
6143 /***********************************************************************
6144 Marginal Areas
6145 ***********************************************************************/
6147 DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins,
6148 2, 3, 0,
6149 doc: /* Set width of marginal areas of window WINDOW.
6150 If WINDOW is nil, set margins of the currently selected window.
6151 Second arg LEFT-WIDTH specifies the number of character cells to
6152 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6153 does the same for the right marginal area. A nil width parameter
6154 means no margin. */)
6155 (window, left, right)
6156 Lisp_Object window, left, right;
6158 struct window *w = decode_window (window);
6160 /* Translate negative or zero widths to nil.
6161 Margins that are too wide have to be checked elsewhere. */
6163 if (!NILP (left))
6165 CHECK_NUMBER (left);
6166 if (XINT (left) <= 0)
6167 left = Qnil;
6170 if (!NILP (right))
6172 CHECK_NUMBER (right);
6173 if (XINT (right) <= 0)
6174 right = Qnil;
6177 if (!EQ (w->left_margin_cols, left)
6178 || !EQ (w->right_margin_cols, right))
6180 w->left_margin_cols = left;
6181 w->right_margin_cols = right;
6183 adjust_window_margins (w);
6185 ++windows_or_buffers_changed;
6186 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6189 return Qnil;
6193 DEFUN ("window-margins", Fwindow_margins, Swindow_margins,
6194 0, 1, 0,
6195 doc: /* Get width of marginal areas of window WINDOW.
6196 If WINDOW is omitted or nil, use the currently selected window.
6197 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6198 If a marginal area does not exist, its width will be returned
6199 as nil. */)
6200 (window)
6201 Lisp_Object window;
6203 struct window *w = decode_window (window);
6204 return Fcons (w->left_margin_cols, w->right_margin_cols);
6209 /***********************************************************************
6210 Fringes
6211 ***********************************************************************/
6213 DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes,
6214 2, 4, 0,
6215 doc: /* Set the fringe widths of window WINDOW.
6216 If WINDOW is nil, set the fringe widths of the currently selected
6217 window.
6218 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6219 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6220 fringe width. If a fringe width arg is nil, that means to use the
6221 frame's default fringe width. Default fringe widths can be set with
6222 the command `set-fringe-style'.
6223 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6224 outside of the display margins. By default, fringes are drawn between
6225 display marginal areas and the text area. */)
6226 (window, left, right, outside_margins)
6227 Lisp_Object window, left, right, outside_margins;
6229 struct window *w = decode_window (window);
6231 if (!NILP (left))
6232 CHECK_NATNUM (left);
6233 if (!NILP (right))
6234 CHECK_NATNUM (right);
6236 if (!EQ (w->left_fringe_width, left)
6237 || !EQ (w->right_fringe_width, right)
6238 || !EQ (w->fringes_outside_margins, outside_margins))
6240 w->left_fringe_width = left;
6241 w->right_fringe_width = right;
6242 w->fringes_outside_margins = outside_margins;
6244 adjust_window_margins (w);
6246 clear_glyph_matrix (w->current_matrix);
6247 w->window_end_valid = Qnil;
6249 ++windows_or_buffers_changed;
6250 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6253 return Qnil;
6257 DEFUN ("window-fringes", Fwindow_fringes, Swindow_fringes,
6258 0, 1, 0,
6259 doc: /* Get width of fringes of window WINDOW.
6260 If WINDOW is omitted or nil, use the currently selected window.
6261 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6262 (window)
6263 Lisp_Object window;
6265 struct window *w = decode_window (window);
6266 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w)),
6267 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w)),
6268 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) ?
6269 Qt : Qnil), Qnil)));
6274 /***********************************************************************
6275 Scroll bars
6276 ***********************************************************************/
6278 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars, Sset_window_scroll_bars,
6279 2, 4, 0,
6280 doc: /* Set width and type of scroll bars of window WINDOW.
6281 If window is nil, set scroll bars of the currently selected window.
6282 Second parameter WIDTH specifies the pixel width for the scroll bar;
6283 this is automatically adjusted to a multiple of the frame column width.
6284 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6285 bar: left, right, or nil.
6286 If WIDTH is nil, use the frame's scroll-bar width.
6287 If TYPE is t, use the frame's scroll-bar type. */)
6288 (window, width, vertical_type, horizontal_type)
6289 Lisp_Object window, width, vertical_type, horizontal_type;
6291 struct window *w = decode_window (window);
6293 if (!NILP (width))
6295 CHECK_NATNUM (width);
6297 if (XINT (width) == 0)
6298 vertical_type = Qnil;
6301 if (!(EQ (vertical_type, Qnil)
6302 || EQ (vertical_type, Qleft)
6303 || EQ (vertical_type, Qright)
6304 || EQ (vertical_type, Qt)))
6305 error ("Invalid type of vertical scroll bar");
6307 if (!EQ (w->scroll_bar_width, width)
6308 || !EQ (w->vertical_scroll_bar_type, vertical_type))
6310 w->scroll_bar_width = width;
6311 w->vertical_scroll_bar_type = vertical_type;
6313 adjust_window_margins (w);
6315 clear_glyph_matrix (w->current_matrix);
6316 w->window_end_valid = Qnil;
6318 ++windows_or_buffers_changed;
6319 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6322 return Qnil;
6326 DEFUN ("window-scroll-bars", Fwindow_scroll_bars, Swindow_scroll_bars,
6327 0, 1, 0,
6328 doc: /* Get width and type of scroll bars of window WINDOW.
6329 If WINDOW is omitted or nil, use the currently selected window.
6330 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6331 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6332 value. */)
6333 (window)
6334 Lisp_Object window;
6336 struct window *w = decode_window (window);
6337 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
6338 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
6339 : WINDOW_SCROLL_BAR_AREA_WIDTH (w))),
6340 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w)),
6341 Fcons (w->vertical_scroll_bar_type,
6342 Fcons (Qnil, Qnil))));
6347 /***********************************************************************
6348 Smooth scrolling
6349 ***********************************************************************/
6351 DEFUN ("window-vscroll", Fwindow_vscroll, Swindow_vscroll, 0, 2, 0,
6352 doc: /* Return the amount by which WINDOW is scrolled vertically.
6353 Use the selected window if WINDOW is nil or omitted.
6354 Normally, value is a multiple of the canonical character height of WINDOW;
6355 optional second arg PIXELS_P means value is measured in pixels. */)
6356 (window, pixels_p)
6357 Lisp_Object window, pixels_p;
6359 Lisp_Object result;
6360 struct frame *f;
6361 struct window *w;
6363 if (NILP (window))
6364 window = selected_window;
6365 else
6366 CHECK_WINDOW (window);
6367 w = XWINDOW (window);
6368 f = XFRAME (w->frame);
6370 if (FRAME_WINDOW_P (f))
6371 result = (NILP (pixels_p)
6372 ? FRAME_CANON_Y_FROM_PIXEL_Y (f, -w->vscroll)
6373 : make_number (-w->vscroll));
6374 else
6375 result = make_number (0);
6376 return result;
6380 DEFUN ("set-window-vscroll", Fset_window_vscroll, Sset_window_vscroll,
6381 2, 3, 0,
6382 doc: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6383 WINDOW nil means use the selected window. Normally, VSCROLL is a
6384 non-negative multiple of the canonical character height of WINDOW;
6385 optional third arg PIXELS_P non-nil means that VSCROLL is in pixels.
6386 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6387 corresponds to an integral number of pixels. The return value is the
6388 result of this rounding.
6389 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6390 (window, vscroll, pixels_p)
6391 Lisp_Object window, vscroll, pixels_p;
6393 struct window *w;
6394 struct frame *f;
6396 if (NILP (window))
6397 window = selected_window;
6398 else
6399 CHECK_WINDOW (window);
6400 CHECK_NUMBER_OR_FLOAT (vscroll);
6402 w = XWINDOW (window);
6403 f = XFRAME (w->frame);
6405 if (FRAME_WINDOW_P (f))
6407 int old_dy = w->vscroll;
6409 w->vscroll = - (NILP (pixels_p)
6410 ? FRAME_LINE_HEIGHT (f) * XFLOATINT (vscroll)
6411 : XFLOATINT (vscroll));
6412 w->vscroll = min (w->vscroll, 0);
6414 if (w->vscroll != old_dy)
6416 /* Adjust glyph matrix of the frame if the virtual display
6417 area becomes larger than before. */
6418 if (w->vscroll < 0 && w->vscroll < old_dy)
6419 adjust_glyphs (f);
6421 /* Prevent redisplay shortcuts. */
6422 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
6426 return Fwindow_vscroll (window, pixels_p);
6430 /* Call FN for all leaf windows on frame F. FN is called with the
6431 first argument being a pointer to the leaf window, and with
6432 additional argument USER_DATA. Stops when FN returns 0. */
6434 void
6435 foreach_window (f, fn, user_data)
6436 struct frame *f;
6437 int (* fn) P_ ((struct window *, void *));
6438 void *user_data;
6440 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f)), fn, user_data);
6444 /* Helper function for foreach_window. Call FN for all leaf windows
6445 reachable from W. FN is called with the first argument being a
6446 pointer to the leaf window, and with additional argument USER_DATA.
6447 Stop when FN returns 0. Value is 0 if stopped by FN. */
6449 static int
6450 foreach_window_1 (w, fn, user_data)
6451 struct window *w;
6452 int (* fn) P_ ((struct window *, void *));
6453 void *user_data;
6455 int cont;
6457 for (cont = 1; w && cont;)
6459 if (!NILP (w->hchild))
6460 cont = foreach_window_1 (XWINDOW (w->hchild), fn, user_data);
6461 else if (!NILP (w->vchild))
6462 cont = foreach_window_1 (XWINDOW (w->vchild), fn, user_data);
6463 else
6464 cont = fn (w, user_data);
6466 w = NILP (w->next) ? 0 : XWINDOW (w->next);
6469 return cont;
6473 /* Freeze or unfreeze the window start of W unless it is a
6474 mini-window or the selected window. FREEZE_P non-null means freeze
6475 the window start. */
6477 static int
6478 freeze_window_start (w, freeze_p)
6479 struct window *w;
6480 void *freeze_p;
6482 if (w == XWINDOW (selected_window)
6483 || MINI_WINDOW_P (w)
6484 || (MINI_WINDOW_P (XWINDOW (selected_window))
6485 && ! NILP (Vminibuf_scroll_window)
6486 && w == XWINDOW (Vminibuf_scroll_window)))
6487 freeze_p = NULL;
6489 w->frozen_window_start_p = freeze_p != NULL;
6490 return 1;
6494 /* Freeze or unfreeze the window starts of all leaf windows on frame
6495 F, except the selected window and a mini-window. FREEZE_P non-zero
6496 means freeze the window start. */
6498 void
6499 freeze_window_starts (f, freeze_p)
6500 struct frame *f;
6501 int freeze_p;
6503 foreach_window (f, freeze_window_start, (void *) (freeze_p ? f : 0));
6507 /***********************************************************************
6508 Initialization
6509 ***********************************************************************/
6511 /* Return 1 if window configurations C1 and C2
6512 describe the same state of affairs. This is used by Fequal. */
6515 compare_window_configurations (c1, c2, ignore_positions)
6516 Lisp_Object c1, c2;
6517 int ignore_positions;
6519 register struct save_window_data *d1, *d2;
6520 struct Lisp_Vector *sw1, *sw2;
6521 int i;
6523 if (!WINDOW_CONFIGURATIONP (c1))
6524 wrong_type_argument (Qwindow_configuration_p, c1);
6525 if (!WINDOW_CONFIGURATIONP (c2))
6526 wrong_type_argument (Qwindow_configuration_p, c2);
6528 d1 = (struct save_window_data *) XVECTOR (c1);
6529 d2 = (struct save_window_data *) XVECTOR (c2);
6530 sw1 = XVECTOR (d1->saved_windows);
6531 sw2 = XVECTOR (d2->saved_windows);
6533 if (! EQ (d1->frame_cols, d2->frame_cols))
6534 return 0;
6535 if (! EQ (d1->frame_lines, d2->frame_lines))
6536 return 0;
6537 if (! EQ (d1->frame_menu_bar_lines, d2->frame_menu_bar_lines))
6538 return 0;
6539 if (! EQ (d1->selected_frame, d2->selected_frame))
6540 return 0;
6541 /* Don't compare the current_window field directly.
6542 Instead see w1_is_current and w2_is_current, below. */
6543 if (! EQ (d1->current_buffer, d2->current_buffer))
6544 return 0;
6545 if (! ignore_positions)
6547 if (! EQ (d1->minibuf_scroll_window, d2->minibuf_scroll_window))
6548 return 0;
6549 if (! EQ (d1->minibuf_selected_window, d2->minibuf_selected_window))
6550 return 0;
6552 /* Don't compare the root_window field.
6553 We don't require the two configurations
6554 to use the same window object,
6555 and the two root windows must be equivalent
6556 if everything else compares equal. */
6557 if (! EQ (d1->focus_frame, d2->focus_frame))
6558 return 0;
6559 if (! EQ (d1->min_width, d2->min_width))
6560 return 0;
6561 if (! EQ (d1->min_height, d2->min_height))
6562 return 0;
6564 /* Verify that the two confis have the same number of windows. */
6565 if (sw1->size != sw2->size)
6566 return 0;
6568 for (i = 0; i < sw1->size; i++)
6570 struct saved_window *p1, *p2;
6571 int w1_is_current, w2_is_current;
6573 p1 = SAVED_WINDOW_N (sw1, i);
6574 p2 = SAVED_WINDOW_N (sw2, i);
6576 /* Verify that the current windows in the two
6577 configurations correspond to each other. */
6578 w1_is_current = EQ (d1->current_window, p1->window);
6579 w2_is_current = EQ (d2->current_window, p2->window);
6581 if (w1_is_current != w2_is_current)
6582 return 0;
6584 /* Verify that the corresponding windows do match. */
6585 if (! EQ (p1->buffer, p2->buffer))
6586 return 0;
6587 if (! EQ (p1->left_col, p2->left_col))
6588 return 0;
6589 if (! EQ (p1->top_line, p2->top_line))
6590 return 0;
6591 if (! EQ (p1->total_cols, p2->total_cols))
6592 return 0;
6593 if (! EQ (p1->total_lines, p2->total_lines))
6594 return 0;
6595 if (! EQ (p1->display_table, p2->display_table))
6596 return 0;
6597 if (! EQ (p1->parent, p2->parent))
6598 return 0;
6599 if (! EQ (p1->prev, p2->prev))
6600 return 0;
6601 if (! ignore_positions)
6603 if (! EQ (p1->hscroll, p2->hscroll))
6604 return 0;
6605 if (!EQ (p1->min_hscroll, p2->min_hscroll))
6606 return 0;
6607 if (! EQ (p1->start_at_line_beg, p2->start_at_line_beg))
6608 return 0;
6609 if (NILP (Fequal (p1->start, p2->start)))
6610 return 0;
6611 if (NILP (Fequal (p1->pointm, p2->pointm)))
6612 return 0;
6613 if (NILP (Fequal (p1->mark, p2->mark)))
6614 return 0;
6616 if (! EQ (p1->left_margin_cols, p2->left_margin_cols))
6617 return 0;
6618 if (! EQ (p1->right_margin_cols, p2->right_margin_cols))
6619 return 0;
6620 if (! EQ (p1->left_fringe_width, p2->left_fringe_width))
6621 return 0;
6622 if (! EQ (p1->right_fringe_width, p2->right_fringe_width))
6623 return 0;
6624 if (! EQ (p1->fringes_outside_margins, p2->fringes_outside_margins))
6625 return 0;
6626 if (! EQ (p1->scroll_bar_width, p2->scroll_bar_width))
6627 return 0;
6628 if (! EQ (p1->vertical_scroll_bar_type, p2->vertical_scroll_bar_type))
6629 return 0;
6632 return 1;
6635 DEFUN ("compare-window-configurations", Fcompare_window_configurations,
6636 Scompare_window_configurations, 2, 2, 0,
6637 doc: /* Compare two window configurations as regards the structure of windows.
6638 This function ignores details such as the values of point and mark
6639 and scrolling positions. */)
6640 (x, y)
6641 Lisp_Object x, y;
6643 if (compare_window_configurations (x, y, 1))
6644 return Qt;
6645 return Qnil;
6648 void
6649 init_window_once ()
6651 struct frame *f = make_terminal_frame ();
6652 XSETFRAME (selected_frame, f);
6653 Vterminal_frame = selected_frame;
6654 minibuf_window = f->minibuffer_window;
6655 selected_window = f->selected_window;
6656 last_nonminibuf_frame = f;
6658 window_initialized = 1;
6661 void
6662 init_window ()
6664 Vwindow_list = Qnil;
6667 void
6668 syms_of_window ()
6670 Qwindow_size_fixed = intern ("window-size-fixed");
6671 staticpro (&Qwindow_size_fixed);
6673 staticpro (&Qwindow_configuration_change_hook);
6674 Qwindow_configuration_change_hook
6675 = intern ("window-configuration-change-hook");
6677 Qwindowp = intern ("windowp");
6678 staticpro (&Qwindowp);
6680 Qwindow_configuration_p = intern ("window-configuration-p");
6681 staticpro (&Qwindow_configuration_p);
6683 Qwindow_live_p = intern ("window-live-p");
6684 staticpro (&Qwindow_live_p);
6686 Qtemp_buffer_show_hook = intern ("temp-buffer-show-hook");
6687 staticpro (&Qtemp_buffer_show_hook);
6689 staticpro (&Vwindow_list);
6691 minibuf_selected_window = Qnil;
6692 staticpro (&minibuf_selected_window);
6694 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function,
6695 doc: /* Non-nil means call as function to display a help buffer.
6696 The function is called with one argument, the buffer to be displayed.
6697 Used by `with-output-to-temp-buffer'.
6698 If this function is used, then it must do the entire job of showing
6699 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6700 Vtemp_buffer_show_function = Qnil;
6702 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function,
6703 doc: /* If non-nil, function to call to handle `display-buffer'.
6704 It will receive two args, the buffer and a flag which if non-nil means
6705 that the currently selected window is not acceptable.
6706 It should choose or create a window, display the specified buffer in it,
6707 and return the window.
6708 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'
6709 work using this function. */);
6710 Vdisplay_buffer_function = Qnil;
6712 DEFVAR_LISP ("even-window-heights", &Veven_window_heights,
6713 doc: /* *If non-nil, `display-buffer' should even the window heights.
6714 If nil, `display-buffer' will leave the window configuration alone. */);
6715 Veven_window_heights = Qt;
6717 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window,
6718 doc: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6719 Vminibuf_scroll_window = Qnil;
6721 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows,
6722 doc: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6723 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6724 is displayed in the `mode-line' face. */);
6725 mode_line_in_non_selected_windows = 1;
6727 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer,
6728 doc: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6729 Vother_window_scroll_buffer = Qnil;
6731 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames,
6732 doc: /* *Non-nil means `display-buffer' should make a separate frame. */);
6733 pop_up_frames = 0;
6735 DEFVAR_BOOL ("auto-window-vscroll", &auto_window_vscroll_p,
6736 doc: /* *Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
6737 auto_window_vscroll_p = 1;
6739 DEFVAR_BOOL ("display-buffer-reuse-frames", &display_buffer_reuse_frames,
6740 doc: /* *Non-nil means `display-buffer' should reuse frames.
6741 If the buffer in question is already displayed in a frame, raise that frame. */);
6742 display_buffer_reuse_frames = 0;
6744 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function,
6745 doc: /* Function to call to handle automatic new frame creation.
6746 It is called with no arguments and should return a newly created frame.
6748 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'
6749 where `pop-up-frame-alist' would hold the default frame parameters. */);
6750 Vpop_up_frame_function = Qnil;
6752 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names,
6753 doc: /* *List of buffer names that should have their own special frames.
6754 Displaying a buffer whose name is in this list makes a special frame for it
6755 using `special-display-function'. See also `special-display-regexps'.
6757 An element of the list can be a list instead of just a string.
6758 There are two ways to use a list as an element:
6759 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)
6760 In the first case, the FRAME-PARAMETERS are pairs of the form
6761 \(PARAMETER . VALUE); these parameter values are used to create the frame.
6762 In the second case, FUNCTION is called with BUFFER as the first argument,
6763 followed by the OTHER-ARGS--it can display BUFFER in any way it likes.
6764 All this is done by the function found in `special-display-function'.
6766 If the specified frame parameters include (same-buffer . t), the
6767 buffer is displayed in the currently selected window. Otherwise, if
6768 they include (same-frame . t), the buffer is displayed in a new window
6769 in the currently selected frame.
6771 If this variable appears \"not to work\", because you add a name to it
6772 but that buffer still appears in the selected window, look at the
6773 values of `same-window-buffer-names' and `same-window-regexps'.
6774 Those variables take precedence over this one. */);
6775 Vspecial_display_buffer_names = Qnil;
6777 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps,
6778 doc: /* *List of regexps saying which buffers should have their own special frames.
6779 If a buffer name matches one of these regexps, it gets its own frame.
6780 Displaying a buffer whose name is in this list makes a special frame for it
6781 using `special-display-function'.
6783 An element of the list can be a list instead of just a string.
6784 There are two ways to use a list as an element:
6785 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)
6786 In the first case, the FRAME-PARAMETERS are pairs of the form
6787 \(PARAMETER . VALUE); these parameter values are used to create the frame.
6788 In the second case, FUNCTION is called with BUFFER as the first argument,
6789 followed by the OTHER-ARGS--it can display the buffer in any way it likes.
6790 All this is done by the function found in `special-display-function'.
6792 If the specified frame parameters include (same-buffer . t), the
6793 buffer is displayed in the currently selected window. Otherwise, if
6794 they include (same-frame . t), the buffer is displayed in a new window
6795 in the currently selected frame.
6797 If this variable appears \"not to work\", because you add a regexp to it
6798 but the matching buffers still appear in the selected window, look at the
6799 values of `same-window-buffer-names' and `same-window-regexps'.
6800 Those variables take precedence over this one. */);
6801 Vspecial_display_regexps = Qnil;
6803 DEFVAR_LISP ("special-display-function", &Vspecial_display_function,
6804 doc: /* Function to call to make a new frame for a special buffer.
6805 It is called with two arguments, the buffer and optional buffer specific
6806 data, and should return a window displaying that buffer.
6807 The default value normally makes a separate frame for the buffer,
6808 using `special-display-frame-alist' to specify the frame parameters.
6809 But if the buffer specific data includes (same-buffer . t) then the
6810 buffer is displayed in the current selected window.
6811 Otherwise if it includes (same-frame . t) then the buffer is displayed in
6812 a new window in the currently selected frame.
6814 A buffer is special if it is listed in `special-display-buffer-names'
6815 or matches a regexp in `special-display-regexps'. */);
6816 Vspecial_display_function = Qnil;
6818 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names,
6819 doc: /* *List of buffer names that should appear in the selected window.
6820 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'
6821 switches to it in the selected window, rather than making it appear
6822 in some other window.
6824 An element of the list can be a cons cell instead of just a string.
6825 Then the car must be a string, which specifies the buffer name.
6826 This is for compatibility with `special-display-buffer-names';
6827 the cdr of the cons cell is ignored.
6829 See also `same-window-regexps'. */);
6830 Vsame_window_buffer_names = Qnil;
6832 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps,
6833 doc: /* *List of regexps saying which buffers should appear in the selected window.
6834 If a buffer name matches one of these regexps, then displaying it
6835 using `display-buffer' or `pop-to-buffer' switches to it
6836 in the selected window, rather than making it appear in some other window.
6838 An element of the list can be a cons cell instead of just a string.
6839 Then the car must be a string, which specifies the buffer name.
6840 This is for compatibility with `special-display-buffer-names';
6841 the cdr of the cons cell is ignored.
6843 See also `same-window-buffer-names'. */);
6844 Vsame_window_regexps = Qnil;
6846 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows,
6847 doc: /* *Non-nil means display-buffer should make new windows. */);
6848 pop_up_windows = 1;
6850 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines,
6851 doc: /* *Number of lines of continuity when scrolling by screenfuls. */);
6852 next_screen_context_lines = 2;
6854 DEFVAR_INT ("split-height-threshold", &split_height_threshold,
6855 doc: /* *A window must be at least this tall to be eligible for splitting by `display-buffer'.
6856 If there is only one window, it is split regardless of this value. */);
6857 split_height_threshold = 500;
6859 DEFVAR_INT ("window-min-height", &window_min_height,
6860 doc: /* *Delete any window less than this tall (including its mode line). */);
6861 window_min_height = 4;
6863 DEFVAR_INT ("window-min-width", &window_min_width,
6864 doc: /* *Delete any window less than this wide. */);
6865 window_min_width = 10;
6867 DEFVAR_LISP ("scroll-preserve-screen-position",
6868 &Vscroll_preserve_screen_position,
6869 doc: /* *Non-nil means scroll commands move point to keep its screen line unchanged.
6870 This is only when it is impossible to keep point fixed and still
6871 scroll as specified. */);
6872 Vscroll_preserve_screen_position = Qnil;
6874 DEFVAR_LISP ("window-configuration-change-hook",
6875 &Vwindow_configuration_change_hook,
6876 doc: /* Functions to call when window configuration changes.
6877 The selected frame is the one whose configuration has changed. */);
6878 Vwindow_configuration_change_hook = Qnil;
6880 DEFVAR_BOOL ("window-size-fixed", &window_size_fixed,
6881 doc: /* Non-nil in a buffer means windows displaying the buffer are fixed-size.
6882 If the value is`height', then only the window's height is fixed.
6883 If the value is `width', then only the window's width is fixed.
6884 Any other non-nil value fixes both the width and the height.
6885 Emacs won't change the size of any window displaying that buffer,
6886 unless you explicitly change the size, or Emacs has no other choice. */);
6887 Fmake_variable_buffer_local (Qwindow_size_fixed);
6888 window_size_fixed = 0;
6890 defsubr (&Sselected_window);
6891 defsubr (&Sminibuffer_window);
6892 defsubr (&Swindow_minibuffer_p);
6893 defsubr (&Swindowp);
6894 defsubr (&Swindow_live_p);
6895 defsubr (&Spos_visible_in_window_p);
6896 defsubr (&Swindow_buffer);
6897 defsubr (&Swindow_height);
6898 defsubr (&Swindow_width);
6899 defsubr (&Swindow_hscroll);
6900 defsubr (&Sset_window_hscroll);
6901 defsubr (&Swindow_redisplay_end_trigger);
6902 defsubr (&Sset_window_redisplay_end_trigger);
6903 defsubr (&Swindow_edges);
6904 defsubr (&Swindow_pixel_edges);
6905 defsubr (&Swindow_inside_edges);
6906 defsubr (&Swindow_inside_pixel_edges);
6907 defsubr (&Scoordinates_in_window_p);
6908 defsubr (&Swindow_at);
6909 defsubr (&Swindow_point);
6910 defsubr (&Swindow_start);
6911 defsubr (&Swindow_end);
6912 defsubr (&Sset_window_point);
6913 defsubr (&Sset_window_start);
6914 defsubr (&Swindow_dedicated_p);
6915 defsubr (&Sset_window_dedicated_p);
6916 defsubr (&Swindow_display_table);
6917 defsubr (&Sset_window_display_table);
6918 defsubr (&Snext_window);
6919 defsubr (&Sprevious_window);
6920 defsubr (&Sother_window);
6921 defsubr (&Sget_lru_window);
6922 defsubr (&Sget_largest_window);
6923 defsubr (&Sget_buffer_window);
6924 defsubr (&Sdelete_other_windows);
6925 defsubr (&Sdelete_windows_on);
6926 defsubr (&Sreplace_buffer_in_windows);
6927 defsubr (&Sdelete_window);
6928 defsubr (&Sset_window_buffer);
6929 defsubr (&Sselect_window);
6930 defsubr (&Sspecial_display_p);
6931 defsubr (&Ssame_window_p);
6932 defsubr (&Sdisplay_buffer);
6933 defsubr (&Sforce_window_update);
6934 defsubr (&Ssplit_window);
6935 defsubr (&Senlarge_window);
6936 defsubr (&Sshrink_window);
6937 defsubr (&Sscroll_up);
6938 defsubr (&Sscroll_down);
6939 defsubr (&Sscroll_left);
6940 defsubr (&Sscroll_right);
6941 defsubr (&Sother_window_for_scrolling);
6942 defsubr (&Sscroll_other_window);
6943 defsubr (&Sminibuffer_selected_window);
6944 defsubr (&Srecenter);
6945 defsubr (&Swindow_text_height);
6946 defsubr (&Smove_to_window_line);
6947 defsubr (&Swindow_configuration_p);
6948 defsubr (&Swindow_configuration_frame);
6949 defsubr (&Sset_window_configuration);
6950 defsubr (&Scurrent_window_configuration);
6951 defsubr (&Ssave_window_excursion);
6952 defsubr (&Sset_window_margins);
6953 defsubr (&Swindow_margins);
6954 defsubr (&Sset_window_fringes);
6955 defsubr (&Swindow_fringes);
6956 defsubr (&Sset_window_scroll_bars);
6957 defsubr (&Swindow_scroll_bars);
6958 defsubr (&Swindow_vscroll);
6959 defsubr (&Sset_window_vscroll);
6960 defsubr (&Scompare_window_configurations);
6961 defsubr (&Swindow_list);
6964 void
6965 keys_of_window ()
6967 initial_define_key (control_x_map, '1', "delete-other-windows");
6968 initial_define_key (control_x_map, '2', "split-window");
6969 initial_define_key (control_x_map, '0', "delete-window");
6970 initial_define_key (control_x_map, 'o', "other-window");
6971 initial_define_key (control_x_map, '^', "enlarge-window");
6972 initial_define_key (control_x_map, '<', "scroll-left");
6973 initial_define_key (control_x_map, '>', "scroll-right");
6975 initial_define_key (global_map, Ctl ('V'), "scroll-up");
6976 initial_define_key (meta_map, Ctl ('V'), "scroll-other-window");
6977 initial_define_key (meta_map, 'v', "scroll-down");
6979 initial_define_key (global_map, Ctl('L'), "recenter");
6980 initial_define_key (meta_map, 'r', "move-to-window-line");
6983 /* arch-tag: 90a9c576-0590-48f1-a5f1-6c96a0452d9f
6984 (do not change this comment) */