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, 2006, 2007 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 3, or (at your option)
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., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
36 #include "dispextern.h"
37 #include "blockinput.h"
38 #include "intervals.h"
39 #include "termhooks.h" /* For FRAME_TERMINAL. */
43 #endif /* HAVE_X_WINDOWS */
55 Lisp_Object Qwindowp
, Qwindow_live_p
, Qwindow_configuration_p
;
56 Lisp_Object Qscroll_up
, Qscroll_down
;
57 Lisp_Object Qwindow_size_fixed
;
58 extern Lisp_Object Qleft_margin
, Qright_margin
;
60 static int displayed_window_lines
P_ ((struct window
*));
61 static struct window
*decode_window
P_ ((Lisp_Object
));
62 static int count_windows
P_ ((struct window
*));
63 static int get_leaf_windows
P_ ((struct window
*, struct window
**, int));
64 static void window_scroll
P_ ((Lisp_Object
, int, int, int));
65 static void window_scroll_pixel_based
P_ ((Lisp_Object
, int, int, int));
66 static void window_scroll_line_based
P_ ((Lisp_Object
, int, int, int));
67 static int window_min_size_1
P_ ((struct window
*, int));
68 static int window_min_size_2
P_ ((struct window
*, int));
69 static int window_min_size
P_ ((struct window
*, int, int, int *));
70 static void size_window
P_ ((Lisp_Object
, int, int, int, int, int));
71 static int freeze_window_start
P_ ((struct window
*, void *));
72 static int window_fixed_size_p
P_ ((struct window
*, int, int));
73 static void enlarge_window
P_ ((Lisp_Object
, int, int));
74 static Lisp_Object window_list
P_ ((void));
75 static int add_window_to_list
P_ ((struct window
*, void *));
76 static int candidate_window_p
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
78 static Lisp_Object next_window
P_ ((Lisp_Object
, Lisp_Object
,
80 static void decode_next_window_args
P_ ((Lisp_Object
*, Lisp_Object
*,
82 static int foreach_window_1
P_ ((struct window
*,
83 int (* fn
) (struct window
*, void *),
85 static Lisp_Object window_list_1
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
87 /* This is the window in which the terminal's cursor should
88 be left when nothing is being done with it. This must
89 always be a leaf window, and its buffer is selected by
90 the top level editing loop at the end of each command.
92 This value is always the same as
93 FRAME_SELECTED_WINDOW (selected_frame). */
95 Lisp_Object selected_window
;
97 /* A list of all windows for use by next_window and Fwindow_list.
98 Functions creating or deleting windows should invalidate this cache
99 by setting it to nil. */
101 Lisp_Object Vwindow_list
;
103 /* The mini-buffer window of the selected frame.
104 Note that you cannot test for mini-bufferness of an arbitrary window
105 by comparing against this; but you can test for mini-bufferness of
106 the selected window. */
108 Lisp_Object minibuf_window
;
110 /* Non-nil means it is the window whose mode line should be
111 shown as the selected window when the minibuffer is selected. */
113 Lisp_Object minibuf_selected_window
;
115 /* Non-nil means it is the window for C-M-v to scroll
116 when the mini-buffer is selected. */
118 Lisp_Object Vminibuf_scroll_window
;
120 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
122 Lisp_Object Vother_window_scroll_buffer
;
124 /* Non-nil means it's function to call to display temp buffers. */
126 Lisp_Object Vtemp_buffer_show_function
;
128 /* Non-zero means line and page scrolling on tall lines (with images)
129 does partial scrolling by modifying window-vscroll. */
131 int auto_window_vscroll_p
;
133 /* Non-zero means to use mode-line-inactive face in all windows but the
134 selected-window and the minibuffer-scroll-window when the
135 minibuffer is active. */
136 int mode_line_in_non_selected_windows
;
138 /* If a window gets smaller than either of these, it is removed. */
140 EMACS_INT window_min_height
;
141 EMACS_INT window_min_width
;
143 /* Nonzero implies Fdisplay_buffer should create windows. */
147 /* Nonzero implies make new frames for Fdisplay_buffer. */
151 /* Nonzero means reuse existing frames for displaying buffers. */
153 int display_buffer_reuse_frames
;
155 /* Non-nil means use this function instead of default */
157 Lisp_Object Vpop_up_frame_function
;
159 /* Function to call to handle Fdisplay_buffer. */
161 Lisp_Object Vdisplay_buffer_function
;
163 /* Non-nil means that Fdisplay_buffer should even the heights of windows. */
165 Lisp_Object Veven_window_heights
;
167 /* List of buffer *names* for buffers that should have their own frames. */
169 Lisp_Object Vspecial_display_buffer_names
;
171 /* List of regexps for buffer names that should have their own frames. */
173 Lisp_Object Vspecial_display_regexps
;
175 /* Function to pop up a special frame. */
177 Lisp_Object Vspecial_display_function
;
179 /* List of buffer *names* for buffers to appear in selected window. */
181 Lisp_Object Vsame_window_buffer_names
;
183 /* List of regexps for buffer names to appear in selected window. */
185 Lisp_Object Vsame_window_regexps
;
187 /* Hook run at end of temp_output_buffer_show. */
189 Lisp_Object Qtemp_buffer_show_hook
;
191 /* Fdisplay_buffer always splits the largest window
192 if that window is more than this high. */
194 EMACS_INT split_height_threshold
;
196 /* How to split windows (horizontally/vertically/hybrid). */
198 Lisp_Object Vsplit_window_preferred_function
;
200 /* Number of lines of continuity in scrolling by screenfuls. */
202 EMACS_INT next_screen_context_lines
;
204 /* Incremented for each window created. */
206 static int sequence_number
;
208 /* Nonzero after init_window_once has finished. */
210 static int window_initialized
;
212 /* Hook to run when window config changes. */
214 Lisp_Object Qwindow_configuration_change_hook
;
215 Lisp_Object Vwindow_configuration_change_hook
;
217 /* Non-nil means scroll commands try to put point
218 at the same screen height as previously. */
220 Lisp_Object Vscroll_preserve_screen_position
;
222 /* Incremented by 1 whenever a window is deleted. */
224 int window_deletion_count
;
226 /* Used by the function window_scroll_pixel_based */
228 static int window_scroll_pixel_based_preserve_y
;
230 #if 0 /* This isn't used anywhere. */
231 /* Nonzero means we can split a frame even if it is "unsplittable". */
232 static int inhibit_frame_unsplittable
;
235 extern EMACS_INT scroll_margin
;
237 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
239 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
240 doc
: /* Returns t if OBJECT is a window. */)
244 return WINDOWP (object
) ? Qt
: Qnil
;
247 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
248 doc
: /* Returns t if OBJECT is a window which is currently visible. */)
252 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
259 register struct window
*p
;
261 p
= allocate_window ();
263 XSETFASTINT (p
->sequence_number
, sequence_number
);
264 XSETFASTINT (p
->left_col
, 0);
265 XSETFASTINT (p
->top_line
, 0);
266 XSETFASTINT (p
->total_lines
, 0);
267 XSETFASTINT (p
->total_cols
, 0);
268 XSETFASTINT (p
->hscroll
, 0);
269 XSETFASTINT (p
->min_hscroll
, 0);
270 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
271 p
->start
= Fmake_marker ();
272 p
->pointm
= Fmake_marker ();
273 XSETFASTINT (p
->use_time
, 0);
275 p
->display_table
= Qnil
;
277 p
->pseudo_window_p
= 0;
278 bzero (&p
->cursor
, sizeof (p
->cursor
));
279 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
280 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
281 p
->desired_matrix
= p
->current_matrix
= 0;
282 p
->nrows_scale_factor
= p
->ncols_scale_factor
= 1;
283 p
->phys_cursor_type
= -1;
284 p
->phys_cursor_width
= -1;
285 p
->must_be_updated_p
= 0;
286 XSETFASTINT (p
->window_end_vpos
, 0);
287 XSETFASTINT (p
->window_end_pos
, 0);
288 p
->window_end_valid
= Qnil
;
291 XSETFASTINT (p
->last_point
, 0);
292 p
->frozen_window_start_p
= 0;
293 p
->last_cursor_off_p
= p
->cursor_off_p
= 0;
294 p
->left_margin_cols
= Qnil
;
295 p
->right_margin_cols
= Qnil
;
296 p
->left_fringe_width
= Qnil
;
297 p
->right_fringe_width
= Qnil
;
298 p
->fringes_outside_margins
= Qnil
;
299 p
->scroll_bar_width
= Qnil
;
300 p
->vertical_scroll_bar_type
= Qt
;
306 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
307 doc
: /* Return the window that the cursor now appears in and commands apply to. */)
310 return selected_window
;
313 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
314 doc
: /* Return the window used now for minibuffers.
315 If the optional argument FRAME is specified, return the minibuffer window
316 used by that frame. */)
321 frame
= selected_frame
;
322 CHECK_LIVE_FRAME (frame
);
323 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
326 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
327 doc
: /* Returns non-nil if WINDOW is a minibuffer window.
328 WINDOW defaults to the selected window. */)
332 struct window
*w
= decode_window (window
);
333 return MINI_WINDOW_P (w
) ? Qt
: Qnil
;
337 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
338 Spos_visible_in_window_p
, 0, 3, 0,
339 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
340 Return nil if that position is scrolled vertically out of view.
341 If a character is only partially visible, nil is returned, unless the
342 optional argument PARTIALLY is non-nil.
343 If POS is only out of view because of horizontal scrolling, return non-nil.
344 If POS is t, it specifies the position of the last visible glyph in WINDOW.
345 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
347 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
348 return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
349 where X and Y are the pixel coordinates relative to the top left corner
350 of the window. The remaining elements are omitted if the character after
351 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
352 off-window at the top and bottom of the row, ROWH is the height of the
353 display row, and VPOS is the row number (0-based) containing POS. */)
354 (pos
, window
, partially
)
355 Lisp_Object pos
, window
, partially
;
357 register struct window
*w
;
359 register struct buffer
*buf
;
361 Lisp_Object in_window
= Qnil
;
362 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
365 w
= decode_window (window
);
366 buf
= XBUFFER (w
->buffer
);
367 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
371 else if (!NILP (pos
))
373 CHECK_NUMBER_COERCE_MARKER (pos
);
376 else if (w
== XWINDOW (selected_window
))
379 posint
= XMARKER (w
->pointm
)->charpos
;
381 /* If position is above window start or outside buffer boundaries,
382 or if window start is out of range, position is not visible. */
384 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
385 && CHARPOS (top
) >= BUF_BEGV (buf
)
386 && CHARPOS (top
) <= BUF_ZV (buf
)
387 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
388 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
391 if (!NILP (in_window
) && !NILP (partially
))
393 Lisp_Object part
= Qnil
;
395 part
= list4 (make_number (rtop
), make_number (rbot
),
396 make_number (rowh
), make_number (vpos
));
397 in_window
= Fcons (make_number (x
),
398 Fcons (make_number (y
), part
));
404 DEFUN ("window-line-height", Fwindow_line_height
,
405 Swindow_line_height
, 0, 2, 0,
406 doc
: /* Return height in pixels of text line LINE in window WINDOW.
407 If WINDOW is nil or omitted, use selected window.
409 Return height of current line if LINE is omitted or nil. Return height of
410 header or mode line if LINE is `header-line' and `mode-line'.
411 Otherwise, LINE is a text line number starting from 0. A negative number
412 counts from the end of the window.
414 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
415 in pixels of the visible part of the line, VPOS and YPOS are the
416 vertical position in lines and pixels of the line, relative to the top
417 of the first text line, and OFFBOT is the number of off-window pixels at
418 the bottom of the text line. If there are off-window pixels at the top
419 of the (first) text line, YPOS is negative.
421 Return nil if window display is not up-to-date. In that case, use
422 `pos-visible-in-window-p' to obtain the information. */)
424 Lisp_Object line
, window
;
426 register struct window
*w
;
427 register struct buffer
*b
;
428 struct glyph_row
*row
, *end_row
;
429 int max_y
, crop
, i
, n
;
431 w
= decode_window (window
);
434 || w
->pseudo_window_p
)
437 CHECK_BUFFER (w
->buffer
);
438 b
= XBUFFER (w
->buffer
);
440 /* Fail if current matrix is not up-to-date. */
441 if (NILP (w
->window_end_valid
)
442 || current_buffer
->clip_changed
443 || current_buffer
->prevent_redisplay_optimizations_p
444 || XFASTINT (w
->last_modified
) < BUF_MODIFF (b
)
445 || XFASTINT (w
->last_overlay_modified
) < BUF_OVERLAY_MODIFF (b
))
451 if (i
< 0 || i
>= w
->current_matrix
->nrows
452 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
454 max_y
= window_text_bottom_y (w
);
458 if (EQ (line
, Qheader_line
))
460 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
462 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
465 return list4 (make_number (row
->height
),
466 make_number (0), make_number (0),
470 if (EQ (line
, Qmode_line
))
472 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
475 return list4 (make_number (row
->height
),
476 make_number (0), /* not accurate */
477 make_number (WINDOW_HEADER_LINE_HEIGHT (w
)
478 + window_text_bottom_y (w
)),
485 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
486 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
487 max_y
= window_text_bottom_y (w
);
490 while ((n
< 0 || i
< n
)
491 && row
<= end_row
&& row
->enabled_p
492 && row
->y
+ row
->height
< max_y
)
495 if (row
> end_row
|| !row
->enabled_p
)
507 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
508 return list4 (make_number (row
->height
+ min (0, row
->y
) - crop
),
510 make_number (row
->y
),
516 static struct window
*
517 decode_window (window
)
518 register Lisp_Object window
;
521 return XWINDOW (selected_window
);
523 CHECK_LIVE_WINDOW (window
);
524 return XWINDOW (window
);
527 static struct window
*
528 decode_any_window (window
)
529 register Lisp_Object window
;
532 return XWINDOW (selected_window
);
534 CHECK_WINDOW (window
);
535 return XWINDOW (window
);
538 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
539 doc
: /* Return the buffer that WINDOW is displaying.
540 WINDOW defaults to the selected window. */)
544 return decode_window (window
)->buffer
;
547 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
548 doc
: /* Return the number of lines in WINDOW (including its mode line).
549 WINDOW defaults to the selected window. */)
553 return decode_any_window (window
)->total_lines
;
556 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
557 doc
: /* Return the number of display columns in WINDOW.
558 This is the width that is usable columns available for text in WINDOW.
559 If you want to find out how many columns WINDOW takes up,
560 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
564 return make_number (window_box_text_cols (decode_any_window (window
)));
567 DEFUN ("window-full-width-p", Fwindow_full_width_p
, Swindow_full_width_p
, 0, 1, 0,
568 doc
: /* Return t if WINDOW is as wide as its frame.
569 WINDOW defaults to the selected window. */)
573 return WINDOW_FULL_WIDTH_P (decode_any_window (window
)) ? Qt
: Qnil
;
576 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
577 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
578 WINDOW defaults to the selected window. */)
582 return decode_window (window
)->hscroll
;
585 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
586 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
587 Return NCOL. NCOL should be zero or positive.
589 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
590 window so that the location of point moves off-window. */)
592 Lisp_Object window
, ncol
;
594 struct window
*w
= decode_window (window
);
598 hscroll
= max (0, XINT (ncol
));
600 /* Prevent redisplay shortcuts when changing the hscroll. */
601 if (XINT (w
->hscroll
) != hscroll
)
602 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
604 w
->hscroll
= make_number (hscroll
);
608 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
609 Swindow_redisplay_end_trigger
, 0, 1, 0,
610 doc
: /* Return WINDOW's redisplay end trigger value.
611 WINDOW defaults to the selected window.
612 See `set-window-redisplay-end-trigger' for more information. */)
616 return decode_window (window
)->redisplay_end_trigger
;
619 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
620 Sset_window_redisplay_end_trigger
, 2, 2, 0,
621 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
622 VALUE should be a buffer position (typically a marker) or nil.
623 If it is a buffer position, then if redisplay in WINDOW reaches a position
624 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
625 with two arguments: WINDOW, and the end trigger value.
626 Afterwards the end-trigger value is reset to nil. */)
628 register Lisp_Object window
, value
;
630 register struct window
*w
;
632 w
= decode_window (window
);
633 w
->redisplay_end_trigger
= value
;
637 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
638 doc
: /* Return a list of the edge coordinates of WINDOW.
639 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
640 RIGHT is one more than the rightmost column occupied by WINDOW,
641 and BOTTOM is one more than the bottommost row occupied by WINDOW.
642 The edges include the space used by the window's scroll bar,
643 display margins, fringes, header line, and mode line, if it has them.
644 To get the edges of the actual text area, use `window-inside-edges'. */)
648 register struct window
*w
= decode_any_window (window
);
650 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w
)),
651 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w
)),
652 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w
)),
653 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w
)),
657 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
658 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
659 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
660 RIGHT is one more than the rightmost x position occupied by WINDOW,
661 and BOTTOM is one more than the bottommost y position occupied by WINDOW.
662 The pixel edges include the space used by the window's scroll bar,
663 display margins, fringes, header line, and mode line, if it has them.
664 To get the edges of the actual text area, use `window-inside-pixel-edges'. */)
668 register struct window
*w
= decode_any_window (window
);
670 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
)),
671 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
)),
672 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
)),
673 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
)),
677 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
678 doc
: /* Return a list of the edge coordinates of WINDOW.
679 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
680 RIGHT is one more than the rightmost column used by text in WINDOW,
681 and BOTTOM is one more than the bottommost row used by text in WINDOW.
682 The inside edges do not include the space used by the window's scroll bar,
683 display margins, fringes, header line, and/or mode line. */)
687 register struct window
*w
= decode_any_window (window
);
689 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w
)
690 + WINDOW_LEFT_MARGIN_COLS (w
)
691 + WINDOW_LEFT_FRINGE_COLS (w
)),
692 make_number (WINDOW_TOP_EDGE_LINE (w
)
693 + WINDOW_HEADER_LINE_LINES (w
)),
694 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w
)
695 - WINDOW_RIGHT_MARGIN_COLS (w
)
696 - WINDOW_RIGHT_FRINGE_COLS (w
)),
697 make_number (WINDOW_BOTTOM_EDGE_LINE (w
)
698 - WINDOW_MODE_LINE_LINES (w
)));
701 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
702 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
703 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
704 RIGHT is one more than the rightmost x position used by text in WINDOW,
705 and BOTTOM is one more than the bottommost y position used by text in WINDOW.
706 The inside edges do not include the space used by the window's scroll bar,
707 display margins, fringes, header line, and/or mode line. */)
711 register struct window
*w
= decode_any_window (window
);
713 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
714 + WINDOW_LEFT_MARGIN_WIDTH (w
)
715 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
716 make_number (WINDOW_TOP_EDGE_Y (w
)
717 + WINDOW_HEADER_LINE_HEIGHT (w
)),
718 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
719 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
720 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
721 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
722 - WINDOW_MODE_LINE_HEIGHT (w
)));
725 /* Test if the character at column *X, row *Y is within window W.
726 If it is not, return ON_NOTHING;
727 if it is in the window's text area,
728 set *x and *y to its location relative to the upper left corner
731 if it is on the window's modeline, return ON_MODE_LINE;
732 if it is on the border between the window and its right sibling,
733 return ON_VERTICAL_BORDER.
734 if it is on a scroll bar,
735 return ON_SCROLL_BAR.
736 if it is on the window's top line, return ON_HEADER_LINE;
737 if it is in left or right fringe of the window,
738 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y
739 to window-relative coordinates;
740 if it is in the marginal area to the left/right of the window,
741 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y
742 to window-relative coordinates.
744 X and Y are frame relative pixel coordinates. */
746 static enum window_part
747 coordinates_in_window (w
, x
, y
)
748 register struct window
*w
;
751 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
752 int left_x
, right_x
, top_y
, bottom_y
;
753 enum window_part part
;
754 int ux
= FRAME_COLUMN_WIDTH (f
);
755 int x0
= WINDOW_LEFT_EDGE_X (w
);
756 int x1
= WINDOW_RIGHT_EDGE_X (w
);
757 /* The width of the area where the vertical line can be dragged.
758 (Between mode lines for instance. */
759 int grabbable_width
= ux
;
760 int lmargin_width
, rmargin_width
, text_left
, text_right
;
762 /* In what's below, we subtract 1 when computing right_x because we
763 want the rightmost pixel, which is given by left_pixel+width-1. */
764 if (w
->pseudo_window_p
)
767 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
768 top_y
= WINDOW_TOP_EDGE_Y (w
);
769 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
773 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
774 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
775 top_y
= WINDOW_TOP_EDGE_Y (w
);
776 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
779 /* Outside any interesting row? */
780 if (*y
< top_y
|| *y
>= bottom_y
)
783 /* On the mode line or header line? If it's near the start of
784 the mode or header line of window that's has a horizontal
785 sibling, say it's on the vertical line. That's to be able
786 to resize windows horizontally in case we're using toolkit
789 if (WINDOW_WANTS_MODELINE_P (w
)
790 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
794 header_vertical_border_check
:
795 /* We're somewhere on the mode line. We consider the place
796 between mode lines of horizontally adjacent mode lines
797 as the vertical border. If scroll bars on the left,
798 return the right window. */
799 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
800 || WINDOW_RIGHTMOST_P (w
))
802 if (!WINDOW_LEFTMOST_P (w
) && abs (*x
- x0
) < grabbable_width
)
804 /* Convert X and Y to window relative coordinates.
805 Vertical border is at the left edge of window. */
806 *x
= max (0, *x
- x0
);
808 return ON_VERTICAL_BORDER
;
813 if (abs (*x
- x1
) < grabbable_width
)
815 /* Convert X and Y to window relative coordinates.
816 Vertical border is at the right edge of window. */
817 *x
= min (x1
, *x
) - x0
;
819 return ON_VERTICAL_BORDER
;
823 if (*x
< x0
|| *x
>= x1
)
826 /* Convert X and Y to window relative coordinates.
827 Mode line starts at left edge of window. */
833 if (WINDOW_WANTS_HEADER_LINE_P (w
)
834 && *y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
))
836 part
= ON_HEADER_LINE
;
837 goto header_vertical_border_check
;
840 if (*x
< x0
|| *x
>= x1
)
843 /* Outside any interesting column? */
844 if (*x
< left_x
|| *x
> right_x
)
847 return ON_SCROLL_BAR
;
850 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
851 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
853 text_left
= window_box_left (w
, TEXT_AREA
);
854 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
856 if (FRAME_WINDOW_P (f
))
858 if (!w
->pseudo_window_p
859 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
860 && !WINDOW_RIGHTMOST_P (w
)
861 && (abs (*x
- right_x
) < grabbable_width
))
863 /* Convert X and Y to window relative coordinates.
864 Vertical border is at the right edge of window. */
865 *x
= min (right_x
, *x
) - left_x
;
867 return ON_VERTICAL_BORDER
;
872 /* Need to say "*x > right_x" rather than >=, since on character
873 terminals, the vertical line's x coordinate is right_x. */
874 if (!w
->pseudo_window_p
875 && !WINDOW_RIGHTMOST_P (w
)
876 && *x
> right_x
- ux
)
878 /* On the border on the right side of the window? Assume that
879 this area begins at RIGHT_X minus a canonical char width. */
880 *x
= min (right_x
, *x
) - left_x
;
882 return ON_VERTICAL_BORDER
;
888 if (lmargin_width
> 0
889 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
890 ? (*x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
891 : (*x
< left_x
+ lmargin_width
)))
894 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
895 *x
-= WINDOW_LEFT_FRINGE_WIDTH (w
);
897 return ON_LEFT_MARGIN
;
900 /* Convert X and Y to window-relative pixel coordinates. */
903 return ON_LEFT_FRINGE
;
906 if (*x
>= text_right
)
908 if (rmargin_width
> 0
909 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
910 ? (*x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
911 : (*x
>= right_x
- rmargin_width
)))
913 *x
-= right_x
- rmargin_width
;
914 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
915 *x
+= WINDOW_RIGHT_FRINGE_WIDTH (w
);
917 return ON_RIGHT_MARGIN
;
920 /* Convert X and Y to window-relative pixel coordinates. */
921 *x
-= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
);
923 return ON_RIGHT_FRINGE
;
926 /* Everything special ruled out - must be on text area */
933 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
934 Scoordinates_in_window_p
, 2, 2, 0,
935 doc
: /* Return non-nil if COORDINATES are in WINDOW.
936 COORDINATES is a cons of the form (X . Y), X and Y being distances
937 measured in characters from the upper-left corner of the frame.
938 \(0 . 0) denotes the character in the upper left corner of the
940 If COORDINATES are in the text portion of WINDOW,
941 the coordinates relative to the window are returned.
942 If they are in the mode line of WINDOW, `mode-line' is returned.
943 If they are in the top mode line of WINDOW, `header-line' is returned.
944 If they are in the left fringe of WINDOW, `left-fringe' is returned.
945 If they are in the right fringe of WINDOW, `right-fringe' is returned.
946 If they are on the border between WINDOW and its right sibling,
947 `vertical-line' is returned.
948 If they are in the windows's left or right marginal areas, `left-margin'\n\
949 or `right-margin' is returned. */)
950 (coordinates
, window
)
951 register Lisp_Object coordinates
, window
;
958 CHECK_WINDOW (window
);
959 w
= XWINDOW (window
);
960 f
= XFRAME (w
->frame
);
961 CHECK_CONS (coordinates
);
962 lx
= Fcar (coordinates
);
963 ly
= Fcdr (coordinates
);
964 CHECK_NUMBER_OR_FLOAT (lx
);
965 CHECK_NUMBER_OR_FLOAT (ly
);
966 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
967 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
969 switch (coordinates_in_window (w
, &x
, &y
))
975 /* X and Y are now window relative pixel coordinates. Convert
976 them to canonical char units before returning them. */
977 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
978 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
983 case ON_VERTICAL_BORDER
:
984 return Qvertical_line
;
992 case ON_RIGHT_FRINGE
:
993 return Qright_fringe
;
998 case ON_RIGHT_MARGIN
:
999 return Qright_margin
;
1002 /* Historically we are supposed to return nil in this case. */
1011 /* Callback for foreach_window, used in window_from_coordinates.
1012 Check if window W contains coordinates specified by USER_DATA which
1013 is actually a pointer to a struct check_window_data CW.
1015 Check if window W contains coordinates *CW->x and *CW->y. If it
1016 does, return W in *CW->window, as Lisp_Object, and return in
1017 *CW->part the part of the window under coordinates *X,*Y. Return
1018 zero from this function to stop iterating over windows. */
1020 struct check_window_data
1022 Lisp_Object
*window
;
1024 enum window_part
*part
;
1028 check_window_containing (w
, user_data
)
1032 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
1033 enum window_part found
;
1036 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1037 if (found
!= ON_NOTHING
)
1040 XSETWINDOW (*cw
->window
, w
);
1048 /* Find the window containing frame-relative pixel position X/Y and
1049 return it as a Lisp_Object.
1051 If X, Y is on one of the window's special `window_part' elements,
1052 set *PART to the id of that element, and return X and Y converted
1053 to window relative coordinates in WX and WY.
1055 If there is no window under X, Y return nil and leave *PART
1056 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1058 This function was previously implemented with a loop cycling over
1059 windows with Fnext_window, and starting with the frame's selected
1060 window. It turned out that this doesn't work with an
1061 implementation of next_window using Vwindow_list, because
1062 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1063 tree of F when this function is called asynchronously from
1064 note_mouse_highlight. The original loop didn't terminate in this
1068 window_from_coordinates (f
, x
, y
, part
, wx
, wy
, tool_bar_p
)
1071 enum window_part
*part
;
1076 struct check_window_data cw
;
1077 enum window_part dummy
;
1083 cw
.window
= &window
, cw
.x
= &x
, cw
.y
= &y
; cw
.part
= part
;
1084 foreach_window (f
, check_window_containing
, &cw
);
1086 /* If not found above, see if it's in the tool bar window, if a tool
1090 && WINDOWP (f
->tool_bar_window
)
1091 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1092 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), &x
, &y
)
1096 window
= f
->tool_bar_window
;
1105 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1106 doc
: /* Return window containing coordinates X and Y on FRAME.
1107 If omitted, FRAME defaults to the currently selected frame.
1108 The top left corner of the frame is considered to be row 0,
1111 Lisp_Object x
, y
, frame
;
1116 frame
= selected_frame
;
1117 CHECK_LIVE_FRAME (frame
);
1120 /* Check that arguments are integers or floats. */
1121 CHECK_NUMBER_OR_FLOAT (x
);
1122 CHECK_NUMBER_OR_FLOAT (y
);
1124 return window_from_coordinates (f
,
1125 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1126 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1127 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1128 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1132 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1133 doc
: /* Return current value of point in WINDOW.
1134 WINDOW defaults to the selected window.
1136 For a nonselected window, this is the value point would have
1137 if that window were selected.
1139 Note that, when WINDOW is the selected window and its buffer
1140 is also currently selected, the value returned is the same as (point).
1141 It would be more strictly correct to return the `top-level' value
1142 of point, outside of any save-excursion forms.
1143 But that is hard to define. */)
1147 register struct window
*w
= decode_window (window
);
1149 if (w
== XWINDOW (selected_window
)
1150 && current_buffer
== XBUFFER (w
->buffer
))
1152 return Fmarker_position (w
->pointm
);
1155 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1156 doc
: /* Return position at which display currently starts in WINDOW.
1157 WINDOW defaults to the selected window.
1158 This is updated by redisplay or by calling `set-window-start'. */)
1162 return Fmarker_position (decode_window (window
)->start
);
1165 /* This is text temporarily removed from the doc string below.
1167 This function returns nil if the position is not currently known.
1168 That happens when redisplay is preempted and doesn't finish.
1169 If in that case you want to compute where the end of the window would
1170 have been if redisplay had finished, do this:
1172 (goto-char (window-start window))
1173 (vertical-motion (1- (window-height window)) window)
1176 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1177 doc
: /* Return position at which display currently ends in WINDOW.
1178 WINDOW defaults to the selected window.
1179 This is updated by redisplay, when it runs to completion.
1180 Simply changing the buffer text or setting `window-start'
1181 does not update this value.
1182 Return nil if there is no recorded value. \(This can happen if the
1183 last redisplay of WINDOW was preempted, and did not finish.)
1184 If UPDATE is non-nil, compute the up-to-date position
1185 if it isn't already recorded. */)
1187 Lisp_Object window
, update
;
1190 struct window
*w
= decode_window (window
);
1198 #if 0 /* This change broke some things. We should make it later. */
1199 /* If we don't know the end position, return nil.
1200 The user can compute it with vertical-motion if he wants to.
1201 It would be nicer to do it automatically,
1202 but that's so slow that it would probably bother people. */
1203 if (NILP (w
->window_end_valid
))
1208 && ! (! NILP (w
->window_end_valid
)
1209 && XFASTINT (w
->last_modified
) >= BUF_MODIFF (b
)
1210 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (b
))
1213 struct text_pos startp
;
1215 struct buffer
*old_buffer
= NULL
;
1217 /* Cannot use Fvertical_motion because that function doesn't
1218 cope with variable-height lines. */
1219 if (b
!= current_buffer
)
1221 old_buffer
= current_buffer
;
1222 set_buffer_internal (b
);
1225 /* In case W->start is out of the range, use something
1226 reasonable. This situation occurred when loading a file with
1227 `-l' containing a call to `rmail' with subsequent other
1228 commands. At the end, W->start happened to be BEG, while
1229 rmail had already narrowed the buffer. */
1230 if (XMARKER (w
->start
)->charpos
< BEGV
)
1231 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1232 else if (XMARKER (w
->start
)->charpos
> ZV
)
1233 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1235 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1237 start_display (&it
, w
, startp
);
1238 move_it_vertically (&it
, window_box_height (w
));
1239 if (it
.current_y
< it
.last_visible_y
)
1240 move_it_past_eol (&it
);
1241 value
= make_number (IT_CHARPOS (it
));
1244 set_buffer_internal (old_buffer
);
1247 XSETINT (value
, BUF_Z (b
) - XFASTINT (w
->window_end_pos
));
1252 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1253 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1256 Lisp_Object window
, pos
;
1258 register struct window
*w
= decode_window (window
);
1260 CHECK_NUMBER_COERCE_MARKER (pos
);
1261 if (w
== XWINDOW (selected_window
)
1262 && XBUFFER (w
->buffer
) == current_buffer
)
1265 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1267 /* We have to make sure that redisplay updates the window to show
1268 the new value of point. */
1269 if (!EQ (window
, selected_window
))
1270 ++windows_or_buffers_changed
;
1275 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1276 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1278 Optional third arg NOFORCE non-nil inhibits next redisplay
1279 from overriding motion of point in order to display at this exact start. */)
1280 (window
, pos
, noforce
)
1281 Lisp_Object window
, pos
, noforce
;
1283 register struct window
*w
= decode_window (window
);
1285 CHECK_NUMBER_COERCE_MARKER (pos
);
1286 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1287 /* this is not right, but much easier than doing what is right. */
1288 w
->start_at_line_beg
= Qnil
;
1290 w
->force_start
= Qt
;
1291 w
->update_mode_line
= Qt
;
1292 XSETFASTINT (w
->last_modified
, 0);
1293 XSETFASTINT (w
->last_overlay_modified
, 0);
1294 if (!EQ (window
, selected_window
))
1295 windows_or_buffers_changed
++;
1300 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1302 doc
: /* Return WINDOW's dedicated object, usually t or nil.
1303 See also `set-window-dedicated-p'. */)
1307 return decode_window (window
)->dedicated
;
1310 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1311 Sset_window_dedicated_p
, 2, 2, 0,
1312 doc
: /* Control whether WINDOW is dedicated to the buffer it displays.
1313 If it is dedicated, Emacs will not automatically change
1314 which buffer appears in it.
1315 The second argument is the new value for the dedication flag;
1316 non-nil means yes. */)
1318 Lisp_Object window
, arg
;
1320 register struct window
*w
= decode_window (window
);
1324 return w
->dedicated
;
1327 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1329 doc
: /* Return the display-table that WINDOW is using.
1330 WINDOW defaults to the selected window. */)
1334 return decode_window (window
)->display_table
;
1337 /* Get the display table for use on window W. This is either W's
1338 display table or W's buffer's display table. Ignore the specified
1339 tables if they are not valid; if no valid table is specified,
1342 struct Lisp_Char_Table
*
1343 window_display_table (w
)
1346 struct Lisp_Char_Table
*dp
= NULL
;
1348 if (DISP_TABLE_P (w
->display_table
))
1349 dp
= XCHAR_TABLE (w
->display_table
);
1350 else if (BUFFERP (w
->buffer
))
1352 struct buffer
*b
= XBUFFER (w
->buffer
);
1354 if (DISP_TABLE_P (b
->display_table
))
1355 dp
= XCHAR_TABLE (b
->display_table
);
1356 else if (DISP_TABLE_P (Vstandard_display_table
))
1357 dp
= XCHAR_TABLE (Vstandard_display_table
);
1363 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1364 doc
: /* Set WINDOW's display-table to TABLE. */)
1366 register Lisp_Object window
, table
;
1368 register struct window
*w
;
1370 w
= decode_window (window
);
1371 w
->display_table
= table
;
1375 /* Record info on buffer window w is displaying
1376 when it is about to cease to display that buffer. */
1379 register struct window
*w
;
1386 if (b
!= XMARKER (w
->pointm
)->buffer
)
1390 if (w
== XWINDOW (selected_window
)
1391 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1392 /* Do this except when the selected window's buffer
1393 is being removed from some other window. */
1395 /* last_window_start records the start position that this buffer
1396 had in the last window to be disconnected from it.
1397 Now that this statement is unconditional,
1398 it is possible for the buffer to be displayed in the
1399 selected window, while last_window_start reflects another
1400 window which was recently showing the same buffer.
1401 Some people might say that might be a good thing. Let's see. */
1402 b
->last_window_start
= marker_position (w
->start
);
1404 /* Point in the selected window's buffer
1405 is actually stored in that buffer, and the window's pointm isn't used.
1406 So don't clobber point in that buffer. */
1407 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1408 /* This line helps to fix Horsley's testbug.el bug. */
1409 && !(WINDOWP (b
->last_selected_window
)
1410 && w
!= XWINDOW (b
->last_selected_window
)
1411 && EQ (buf
, XWINDOW (b
->last_selected_window
)->buffer
)))
1412 temp_set_point_both (b
,
1413 clip_to_bounds (BUF_BEGV (b
),
1414 XMARKER (w
->pointm
)->charpos
,
1416 clip_to_bounds (BUF_BEGV_BYTE (b
),
1417 marker_byte_position (w
->pointm
),
1420 if (WINDOWP (b
->last_selected_window
)
1421 && w
== XWINDOW (b
->last_selected_window
))
1422 b
->last_selected_window
= Qnil
;
1425 /* Put replacement into the window structure in place of old. */
1427 replace_window (old
, replacement
)
1428 Lisp_Object old
, replacement
;
1430 register Lisp_Object tem
;
1431 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
1433 /* If OLD is its frame's root_window, then replacement is the new
1434 root_window for that frame. */
1436 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1437 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
1439 p
->left_col
= o
->left_col
;
1440 p
->top_line
= o
->top_line
;
1441 p
->total_cols
= o
->total_cols
;
1442 p
->total_lines
= o
->total_lines
;
1443 p
->desired_matrix
= p
->current_matrix
= 0;
1445 bzero (&p
->cursor
, sizeof (p
->cursor
));
1446 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
1447 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
1448 p
->phys_cursor_type
= -1;
1449 p
->phys_cursor_width
= -1;
1450 p
->must_be_updated_p
= 0;
1451 p
->pseudo_window_p
= 0;
1452 XSETFASTINT (p
->window_end_vpos
, 0);
1453 XSETFASTINT (p
->window_end_pos
, 0);
1454 p
->window_end_valid
= Qnil
;
1455 p
->frozen_window_start_p
= 0;
1456 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
1458 p
->next
= tem
= o
->next
;
1460 XWINDOW (tem
)->prev
= replacement
;
1462 p
->prev
= tem
= o
->prev
;
1464 XWINDOW (tem
)->next
= replacement
;
1466 p
->parent
= tem
= o
->parent
;
1469 if (EQ (XWINDOW (tem
)->vchild
, old
))
1470 XWINDOW (tem
)->vchild
= replacement
;
1471 if (EQ (XWINDOW (tem
)->hchild
, old
))
1472 XWINDOW (tem
)->hchild
= replacement
;
1475 /*** Here, if replacement is a vertical combination
1476 and so is its new parent, we should make replacement's
1477 children be children of that parent instead. ***/
1480 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
1481 doc
: /* Remove WINDOW from the display. Default is selected window. */)
1483 register Lisp_Object window
;
1485 delete_window (window
);
1487 if (! NILP (Vwindow_configuration_change_hook
)
1488 && ! NILP (Vrun_hooks
))
1489 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
1495 delete_window (window
)
1496 register Lisp_Object window
;
1498 register Lisp_Object tem
, parent
, sib
;
1499 register struct window
*p
;
1500 register struct window
*par
;
1503 /* Because this function is called by other C code on non-leaf
1504 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1505 so we can't decode_window here. */
1507 window
= selected_window
;
1509 CHECK_WINDOW (window
);
1510 p
= XWINDOW (window
);
1512 /* It's a no-op to delete an already-deleted window. */
1513 if (NILP (p
->buffer
)
1515 && NILP (p
->vchild
))
1520 error ("Attempt to delete minibuffer or sole ordinary window");
1521 par
= XWINDOW (parent
);
1523 windows_or_buffers_changed
++;
1524 Vwindow_list
= Qnil
;
1525 f
= XFRAME (WINDOW_FRAME (p
));
1526 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
1528 /* Are we trying to delete any frame's selected window? */
1530 Lisp_Object swindow
, pwindow
;
1532 /* See if the frame's selected window is either WINDOW
1533 or any subwindow of it, by finding all that window's parents
1534 and comparing each one with WINDOW. */
1535 swindow
= FRAME_SELECTED_WINDOW (f
);
1540 while (!NILP (pwindow
))
1542 if (EQ (window
, pwindow
))
1544 pwindow
= XWINDOW (pwindow
)->parent
;
1547 /* If the window being deleted is not a parent of SWINDOW,
1548 then SWINDOW is ok as the new selected window. */
1549 if (!EQ (window
, pwindow
))
1551 /* Otherwise, try another window for SWINDOW. */
1552 swindow
= Fnext_window (swindow
, Qlambda
, Qnil
);
1554 /* If we get back to the frame's selected window,
1555 it means there was no acceptable alternative,
1556 so we cannot delete. */
1557 if (EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1558 error ("Cannot delete window");
1561 /* If we need to change SWINDOW, do it. */
1562 if (! EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1564 /* If we're about to delete the selected window on the
1565 selected frame, then we should use Fselect_window to select
1566 the new window. On the other hand, if we're about to
1567 delete the selected window on any other frame, we shouldn't do
1568 anything but set the frame's selected_window slot. */
1569 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
1570 Fselect_window (swindow
, Qnil
);
1572 FRAME_SELECTED_WINDOW (f
) = swindow
;
1576 /* Now we know we can delete this one. */
1577 window_deletion_count
++;
1580 /* tem is null for dummy parent windows
1581 (which have inferiors but not any contents themselves) */
1585 unchain_marker (XMARKER (p
->pointm
));
1586 unchain_marker (XMARKER (p
->start
));
1589 /* Free window glyph matrices. It is sure that they are allocated
1590 again when ADJUST_GLYPHS is called. Block input so that expose
1591 events and other events that access glyph matrices are not
1592 processed while we are changing them. */
1594 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)));
1598 XWINDOW (tem
)->prev
= p
->prev
;
1602 XWINDOW (tem
)->next
= p
->next
;
1604 if (EQ (window
, par
->hchild
))
1605 par
->hchild
= p
->next
;
1606 if (EQ (window
, par
->vchild
))
1607 par
->vchild
= p
->next
;
1609 /* Find one of our siblings to give our space to. */
1613 /* If p gives its space to its next sibling, that sibling needs
1614 to have its top/left side pulled back to where p's is.
1615 set_window_{height,width} will re-position the sibling's
1618 XWINDOW (sib
)->top_line
= p
->top_line
;
1619 XWINDOW (sib
)->left_col
= p
->left_col
;
1622 /* Stretch that sibling. */
1623 if (!NILP (par
->vchild
))
1624 set_window_height (sib
,
1625 XFASTINT (XWINDOW (sib
)->total_lines
) + XFASTINT (p
->total_lines
),
1627 if (!NILP (par
->hchild
))
1628 set_window_width (sib
,
1629 XFASTINT (XWINDOW (sib
)->total_cols
) + XFASTINT (p
->total_cols
),
1632 /* If parent now has only one child,
1633 put the child into the parent's place. */
1637 if (NILP (XWINDOW (tem
)->next
)) {
1638 replace_window (parent
, tem
);
1639 par
= XWINDOW (tem
);
1642 /* Since we may be deleting combination windows, we must make sure that
1643 not only p but all its children have been marked as deleted. */
1644 if (! NILP (p
->hchild
))
1645 delete_all_subwindows (XWINDOW (p
->hchild
));
1646 else if (! NILP (p
->vchild
))
1647 delete_all_subwindows (XWINDOW (p
->vchild
));
1649 /* Mark this window as deleted. */
1650 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1652 if (! NILP (par
->parent
))
1653 par
= XWINDOW (par
->parent
);
1655 /* Check if we have a v/hchild with a v/hchild. In that case remove
1658 if (! NILP (par
->vchild
) && ! NILP (XWINDOW (par
->vchild
)->vchild
))
1660 p
= XWINDOW (par
->vchild
);
1661 par
->vchild
= p
->vchild
;
1664 else if (! NILP (par
->hchild
) && ! NILP (XWINDOW (par
->hchild
)->hchild
))
1666 p
= XWINDOW (par
->hchild
);
1667 par
->hchild
= p
->hchild
;
1675 while (! NILP (tem
)) {
1676 XWINDOW (tem
)->parent
= p
->parent
;
1677 if (NILP (XWINDOW (tem
)->next
))
1679 tem
= XWINDOW (tem
)->next
;
1682 /* The next of the v/hchild we are removing is now the next of the
1683 last child for the v/hchild:
1684 Before v/hchild -> v/hchild -> next1 -> next2
1687 After: v/hchild -> next1 -> next2 -> next3
1689 XWINDOW (tem
)->next
= p
->next
;
1690 if (! NILP (p
->next
))
1691 XWINDOW (p
->next
)->prev
= tem
;
1693 p
->next
= p
->prev
= p
->vchild
= p
->hchild
= p
->buffer
= Qnil
;
1697 /* Adjust glyph matrices. */
1704 /***********************************************************************
1706 ***********************************************************************/
1708 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1709 pointer. This is a callback function for foreach_window, used in
1710 function window_list. */
1713 add_window_to_list (w
, user_data
)
1717 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1719 XSETWINDOW (window
, w
);
1720 *list
= Fcons (window
, *list
);
1725 /* Return a list of all windows, for use by next_window. If
1726 Vwindow_list is a list, return that list. Otherwise, build a new
1727 list, cache it in Vwindow_list, and return that. */
1732 if (!CONSP (Vwindow_list
))
1736 Vwindow_list
= Qnil
;
1737 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1739 Lisp_Object args
[2];
1741 /* We are visiting windows in canonical order, and add
1742 new windows at the front of args[1], which means we
1743 have to reverse this list at the end. */
1745 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1746 args
[0] = Vwindow_list
;
1747 args
[1] = Fnreverse (args
[1]);
1748 Vwindow_list
= Fnconc (2, args
);
1752 return Vwindow_list
;
1756 /* Value is non-zero if WINDOW satisfies the constraints given by
1757 OWINDOW, MINIBUF and ALL_FRAMES.
1759 MINIBUF t means WINDOW may be minibuffer windows.
1760 `lambda' means WINDOW may not be a minibuffer window.
1761 a window means a specific minibuffer window
1763 ALL_FRAMES t means search all frames,
1764 nil means search just current frame,
1765 `visible' means search just visible frames,
1766 0 means search visible and iconified frames,
1767 a window means search the frame that window belongs to,
1768 a frame means consider windows on that frame, only. */
1771 candidate_window_p (window
, owindow
, minibuf
, all_frames
)
1772 Lisp_Object window
, owindow
, minibuf
, all_frames
;
1774 struct window
*w
= XWINDOW (window
);
1775 struct frame
*f
= XFRAME (w
->frame
);
1776 int candidate_p
= 1;
1778 if (!BUFFERP (w
->buffer
))
1780 else if (MINI_WINDOW_P (w
)
1781 && (EQ (minibuf
, Qlambda
)
1782 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
1784 /* If MINIBUF is `lambda' don't consider any mini-windows.
1785 If it is a window, consider only that one. */
1788 else if (EQ (all_frames
, Qt
))
1790 else if (NILP (all_frames
))
1792 xassert (WINDOWP (owindow
));
1793 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
1795 else if (EQ (all_frames
, Qvisible
))
1797 FRAME_SAMPLE_VISIBILITY (f
);
1798 candidate_p
= FRAME_VISIBLE_P (f
)
1799 && (FRAME_TERMINAL (XFRAME (w
->frame
))
1800 == FRAME_TERMINAL (XFRAME (selected_frame
)));
1803 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
1805 FRAME_SAMPLE_VISIBILITY (f
);
1806 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
1807 #ifdef HAVE_X_WINDOWS
1808 /* Yuck!! If we've just created the frame and the
1809 window-manager requested the user to place it
1810 manually, the window may still not be considered
1811 `visible'. I'd argue it should be at least
1812 something like `iconified', but don't know how to do
1814 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
1815 && !f
->output_data
.x
->has_been_visible
)
1818 && (FRAME_TERMINAL (XFRAME (w
->frame
))
1819 == FRAME_TERMINAL (XFRAME (selected_frame
)));
1821 else if (WINDOWP (all_frames
))
1822 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
1823 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
1824 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
1825 else if (FRAMEP (all_frames
))
1826 candidate_p
= EQ (all_frames
, w
->frame
);
1832 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1833 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1837 decode_next_window_args (window
, minibuf
, all_frames
)
1838 Lisp_Object
*window
, *minibuf
, *all_frames
;
1841 *window
= selected_window
;
1843 CHECK_LIVE_WINDOW (*window
);
1845 /* MINIBUF nil may or may not include minibuffers. Decide if it
1847 if (NILP (*minibuf
))
1848 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
1849 else if (!EQ (*minibuf
, Qt
))
1852 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1853 => count none of them, or a specific minibuffer window (the
1854 active one) to count. */
1856 /* ALL_FRAMES nil doesn't specify which frames to include. */
1857 if (NILP (*all_frames
))
1858 *all_frames
= (!EQ (*minibuf
, Qlambda
)
1859 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
1861 else if (EQ (*all_frames
, Qvisible
))
1863 else if (EQ (*all_frames
, make_number (0)))
1865 else if (FRAMEP (*all_frames
))
1867 else if (!EQ (*all_frames
, Qt
))
1870 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1871 search just current frame, `visible' meaning search just visible
1872 frames, 0 meaning search visible and iconified frames, or a
1873 window, meaning search the frame that window belongs to, or a
1874 frame, meaning consider windows on that frame, only. */
1878 /* Return the next or previous window of WINDOW in canonical ordering
1879 of windows. NEXT_P non-zero means return the next window. See the
1880 documentation string of next-window for the meaning of MINIBUF and
1884 next_window (window
, minibuf
, all_frames
, next_p
)
1885 Lisp_Object window
, minibuf
, all_frames
;
1888 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1890 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1891 return the first window on the frame. */
1892 if (FRAMEP (all_frames
)
1893 && !EQ (all_frames
, XWINDOW (window
)->frame
))
1894 return Fframe_first_window (all_frames
);
1900 /* Find WINDOW in the list of all windows. */
1901 list
= Fmemq (window
, window_list ());
1903 /* Scan forward from WINDOW to the end of the window list. */
1905 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
1906 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1909 /* Scan from the start of the window list up to WINDOW. */
1911 for (list
= Vwindow_list
;
1912 CONSP (list
) && !EQ (XCAR (list
), window
);
1914 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1918 window
= XCAR (list
);
1922 Lisp_Object candidate
, list
;
1924 /* Scan through the list of windows for candidates. If there are
1925 candidate windows in front of WINDOW, the last one of these
1926 is the one we want. If there are candidates following WINDOW
1927 in the list, again the last one of these is the one we want. */
1929 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
1931 if (EQ (XCAR (list
), window
))
1933 if (WINDOWP (candidate
))
1936 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
1938 candidate
= XCAR (list
);
1941 if (WINDOWP (candidate
))
1949 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
1950 doc
: /* Return next window after WINDOW in canonical ordering of windows.
1951 If omitted, WINDOW defaults to the selected window.
1953 Optional second arg MINIBUF t means count the minibuffer window even
1954 if not active. MINIBUF nil or omitted means count the minibuffer iff
1955 it is active. MINIBUF neither t nor nil means not to count the
1956 minibuffer even if it is active.
1958 Several frames may share a single minibuffer; if the minibuffer
1959 counts, all windows on all frames that share that minibuffer count
1960 too. Therefore, `next-window' can be used to iterate through the
1961 set of windows even when the minibuffer is on another frame. If the
1962 minibuffer does not count, only windows from WINDOW's frame count.
1964 Optional third arg ALL-FRAMES t means include windows on all frames.
1965 ALL-FRAMES nil or omitted means cycle within the frames as specified
1966 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1967 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1968 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1969 Anything else means restrict to WINDOW's frame.
1971 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1972 `next-window' to iterate through the entire cycle of acceptable
1973 windows, eventually ending up back at the window you started with.
1974 `previous-window' traverses the same cycle, in the reverse order. */)
1975 (window
, minibuf
, all_frames
)
1976 Lisp_Object window
, minibuf
, all_frames
;
1978 return next_window (window
, minibuf
, all_frames
, 1);
1982 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1983 doc
: /* Return the window preceding WINDOW in canonical ordering of windows.
1984 If omitted, WINDOW defaults to the selected window.
1986 Optional second arg MINIBUF t means count the minibuffer window even
1987 if not active. MINIBUF nil or omitted means count the minibuffer iff
1988 it is active. MINIBUF neither t nor nil means not to count the
1989 minibuffer even if it is active.
1991 Several frames may share a single minibuffer; if the minibuffer
1992 counts, all windows on all frames that share that minibuffer count
1993 too. Therefore, `previous-window' can be used to iterate through
1994 the set of windows even when the minibuffer is on another frame. If
1995 the minibuffer does not count, only windows from WINDOW's frame count
1997 Optional third arg ALL-FRAMES t means include windows on all frames.
1998 ALL-FRAMES nil or omitted means cycle within the frames as specified
1999 above. ALL-FRAMES = `visible' means include windows on all visible frames.
2000 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
2001 If ALL-FRAMES is a frame, restrict search to windows on that frame.
2002 Anything else means restrict to WINDOW's frame.
2004 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2005 `previous-window' to iterate through the entire cycle of acceptable
2006 windows, eventually ending up back at the window you started with.
2007 `next-window' traverses the same cycle, in the reverse order. */)
2008 (window
, minibuf
, all_frames
)
2009 Lisp_Object window
, minibuf
, all_frames
;
2011 return next_window (window
, minibuf
, all_frames
, 0);
2015 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
2016 doc
: /* Select the ARG'th different window on this frame.
2017 All windows on current frame are arranged in a cyclic order.
2018 This command selects the window ARG steps away in that order.
2019 A negative ARG moves in the opposite order. The optional second
2020 argument ALL-FRAMES has the same meaning as in `next-window', which see. */)
2022 Lisp_Object arg
, all_frames
;
2028 window
= selected_window
;
2030 for (i
= XINT (arg
); i
> 0; --i
)
2031 window
= Fnext_window (window
, Qnil
, all_frames
);
2033 window
= Fprevious_window (window
, Qnil
, all_frames
);
2035 Fselect_window (window
, Qnil
);
2040 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2041 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2042 FRAME nil or omitted means use the selected frame.
2043 WINDOW nil or omitted means use the selected window.
2044 MINIBUF t means include the minibuffer window, even if it isn't active.
2045 MINIBUF nil or omitted means include the minibuffer window only
2047 MINIBUF neither nil nor t means never include the minibuffer window. */)
2048 (frame
, minibuf
, window
)
2049 Lisp_Object frame
, minibuf
, window
;
2052 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2053 CHECK_WINDOW (window
);
2055 frame
= selected_frame
;
2057 if (!EQ (frame
, XWINDOW (window
)->frame
))
2058 error ("Window is on a different frame");
2060 return window_list_1 (window
, minibuf
, frame
);
2064 /* Return a list of windows in canonical ordering. Arguments are like
2065 for `next-window'. */
2068 window_list_1 (window
, minibuf
, all_frames
)
2069 Lisp_Object window
, minibuf
, all_frames
;
2071 Lisp_Object tail
, list
, rest
;
2073 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2076 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2077 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2078 list
= Fcons (XCAR (tail
), list
);
2080 /* Rotate the list to start with WINDOW. */
2081 list
= Fnreverse (list
);
2082 rest
= Fmemq (window
, list
);
2083 if (!NILP (rest
) && !EQ (rest
, list
))
2085 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2087 XSETCDR (tail
, Qnil
);
2088 list
= nconc2 (rest
, list
);
2095 /* Look at all windows, performing an operation specified by TYPE
2097 If FRAMES is Qt, look at all frames;
2098 Qnil, look at just the selected frame;
2099 Qvisible, look at visible frames;
2100 a frame, just look at windows on that frame.
2101 If MINI is non-zero, perform the operation on minibuffer windows too. */
2106 GET_BUFFER_WINDOW
, /* Arg is buffer */
2107 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
2108 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
2109 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
2111 UNSHOW_BUFFER
, /* Arg is buffer */
2112 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2117 window_loop (type
, obj
, mini
, frames
)
2118 enum window_loop type
;
2119 Lisp_Object obj
, frames
;
2122 Lisp_Object window
, windows
, best_window
, frame_arg
;
2124 struct gcpro gcpro1
;
2126 /* If we're only looping through windows on a particular frame,
2127 frame points to that frame. If we're looping through windows
2128 on all frames, frame is 0. */
2129 if (FRAMEP (frames
))
2130 f
= XFRAME (frames
);
2131 else if (NILP (frames
))
2132 f
= SELECTED_FRAME ();
2137 frame_arg
= Qlambda
;
2138 else if (EQ (frames
, make_number (0)))
2140 else if (EQ (frames
, Qvisible
))
2145 /* frame_arg is Qlambda to stick to one frame,
2146 Qvisible to consider all visible frames,
2149 /* Pick a window to start with. */
2153 window
= FRAME_SELECTED_WINDOW (f
);
2155 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2157 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2161 for (; CONSP (windows
); windows
= XCDR (windows
))
2165 window
= XCAR (windows
);
2166 w
= XWINDOW (window
);
2168 /* Note that we do not pay attention here to whether the frame
2169 is visible, since Fwindow_list skips non-visible frames if
2170 that is desired, under the control of frame_arg. */
2171 if (!MINI_WINDOW_P (w
)
2172 /* For UNSHOW_BUFFER, we must always consider all windows. */
2173 || type
== UNSHOW_BUFFER
2174 || (mini
&& minibuf_level
> 0))
2177 case GET_BUFFER_WINDOW
:
2178 if (EQ (w
->buffer
, obj
)
2179 /* Don't find any minibuffer window
2180 except the one that is currently in use. */
2181 && (MINI_WINDOW_P (w
)
2182 ? EQ (window
, minibuf_window
)
2185 if (NILP (best_window
))
2186 best_window
= window
;
2187 else if (EQ (window
, selected_window
))
2188 /* Prefer to return selected-window. */
2189 RETURN_UNGCPRO (window
);
2190 else if (EQ (Fwindow_frame (window
), selected_frame
))
2191 /* Prefer windows on the current frame. */
2192 best_window
= window
;
2196 case GET_LRU_WINDOW
:
2197 /* `obj' is an integer encoding a bitvector.
2198 `obj & 1' means consider only full-width windows.
2199 `obj & 2' means consider also dedicated windows. */
2200 if (((XINT (obj
) & 1) && !WINDOW_FULL_WIDTH_P (w
))
2201 || (!(XINT (obj
) & 2) && !NILP (w
->dedicated
))
2202 /* Minibuffer windows are always ignored. */
2203 || MINI_WINDOW_P (w
))
2205 if (NILP (best_window
)
2206 || (XFASTINT (XWINDOW (best_window
)->use_time
)
2207 > XFASTINT (w
->use_time
)))
2208 best_window
= window
;
2211 case DELETE_OTHER_WINDOWS
:
2212 if (!EQ (window
, obj
))
2213 Fdelete_window (window
);
2216 case DELETE_BUFFER_WINDOWS
:
2217 if (EQ (w
->buffer
, obj
))
2219 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2221 /* If this window is dedicated, and in a frame of its own,
2223 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
2224 && !NILP (w
->dedicated
)
2225 && other_visible_frames (f
))
2227 /* Skip the other windows on this frame.
2228 There might be one, the minibuffer! */
2229 while (CONSP (XCDR (windows
))
2230 && EQ (XWINDOW (XCAR (windows
))->frame
,
2231 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2232 windows
= XCDR (windows
);
2234 /* Now we can safely delete the frame. */
2235 Fdelete_frame (w
->frame
, Qnil
);
2237 else if (NILP (w
->parent
))
2239 /* If we're deleting the buffer displayed in the
2240 only window on the frame, find a new buffer to
2243 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2244 Fset_window_buffer (window
, buffer
, Qnil
);
2245 if (EQ (window
, selected_window
))
2246 Fset_buffer (w
->buffer
);
2249 Fdelete_window (window
);
2253 case GET_LARGEST_WINDOW
:
2254 { /* nil `obj' means to ignore dedicated windows. */
2255 /* Ignore dedicated windows and minibuffers. */
2256 if (MINI_WINDOW_P (w
) || (NILP (obj
) && !NILP (w
->dedicated
)))
2259 if (NILP (best_window
))
2260 best_window
= window
;
2263 struct window
*b
= XWINDOW (best_window
);
2264 if (XFASTINT (w
->total_lines
) * XFASTINT (w
->total_cols
)
2265 > XFASTINT (b
->total_lines
) * XFASTINT (b
->total_cols
))
2266 best_window
= window
;
2272 if (EQ (w
->buffer
, obj
))
2275 struct frame
*f
= XFRAME (w
->frame
);
2277 /* Find another buffer to show in this window. */
2278 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2280 /* If this window is dedicated, and in a frame of its own,
2282 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
2283 && !NILP (w
->dedicated
)
2284 && other_visible_frames (f
))
2286 /* Skip the other windows on this frame.
2287 There might be one, the minibuffer! */
2288 while (CONSP (XCDR (windows
))
2289 && EQ (XWINDOW (XCAR (windows
))->frame
,
2290 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2291 windows
= XCDR (windows
);
2293 /* Now we can safely delete the frame. */
2294 Fdelete_frame (w
->frame
, Qnil
);
2296 else if (!NILP (w
->dedicated
) && !NILP (w
->parent
))
2299 XSETWINDOW (window
, w
);
2300 /* If this window is dedicated and not the only window
2301 in its frame, then kill it. */
2302 Fdelete_window (window
);
2306 /* Otherwise show a different buffer in the window. */
2307 w
->dedicated
= Qnil
;
2308 Fset_window_buffer (window
, buffer
, Qnil
);
2309 if (EQ (window
, selected_window
))
2310 Fset_buffer (w
->buffer
);
2315 case REDISPLAY_BUFFER_WINDOWS
:
2316 if (EQ (w
->buffer
, obj
))
2318 mark_window_display_accurate (window
, 0);
2319 w
->update_mode_line
= Qt
;
2320 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2321 ++update_mode_lines
;
2322 best_window
= window
;
2326 /* Check for a window that has a killed buffer. */
2327 case CHECK_ALL_WINDOWS
:
2328 if (! NILP (w
->buffer
)
2329 && NILP (XBUFFER (w
->buffer
)->name
))
2333 case WINDOW_LOOP_UNUSED
:
2342 /* Used for debugging. Abort if any window has a dead buffer. */
2345 check_all_windows ()
2347 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2350 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 2, 0,
2351 doc
: /* Return the window least recently selected or used for display.
2352 \(LRU means Least Recently Used.)
2354 Return a full-width window if possible.
2355 A minibuffer window is never a candidate.
2356 A dedicated window is never a candidate, unless DEDICATED is non-nil,
2357 so if all windows are dedicated, the value is nil.
2358 If optional argument FRAME is `visible', search all visible frames.
2359 If FRAME is 0, search all visible and iconified frames.
2360 If FRAME is t, search all frames.
2361 If FRAME is nil, search only the selected frame.
2362 If FRAME is a frame, search only that frame. */)
2364 Lisp_Object frame
, dedicated
;
2366 register Lisp_Object w
;
2367 /* First try for a window that is full-width */
2368 w
= window_loop (GET_LRU_WINDOW
,
2369 NILP (dedicated
) ? make_number (1) : make_number (3),
2371 if (!NILP (w
) && !EQ (w
, selected_window
))
2373 /* If none of them, try the rest */
2374 return window_loop (GET_LRU_WINDOW
,
2375 NILP (dedicated
) ? make_number (0) : make_number (2),
2379 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 2, 0,
2380 doc
: /* Return the largest window in area.
2381 A minibuffer window is never a candidate.
2382 A dedicated window is never a candidate unless DEDICATED is non-nil,
2383 so if all windows are dedicated, the value is nil.
2384 If optional argument FRAME is `visible', search all visible frames.
2385 If FRAME is 0, search all visible and iconified frames.
2386 If FRAME is t, search all frames.
2387 If FRAME is nil, search only the selected frame.
2388 If FRAME is a frame, search only that frame. */)
2390 Lisp_Object frame
, dedicated
;
2392 return window_loop (GET_LARGEST_WINDOW
, dedicated
, 0,
2396 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
2397 doc
: /* Return a window currently displaying BUFFER, or nil if none.
2398 BUFFER can be a buffer or a buffer name.
2399 If optional argument FRAME is `visible', search all visible frames.
2400 If optional argument FRAME is 0, search all visible and iconified frames.
2401 If FRAME is t, search all frames.
2402 If FRAME is nil, search only the selected frame.
2403 If FRAME is a frame, search only that frame. */)
2405 Lisp_Object buffer
, frame
;
2407 buffer
= Fget_buffer (buffer
);
2408 if (BUFFERP (buffer
))
2409 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
2414 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
2416 doc
: /* Make WINDOW (or the selected window) fill its frame.
2417 Only the frame WINDOW is on is affected.
2418 This function tries to reduce display jumps
2419 by keeping the text previously visible in WINDOW
2420 in the same place on the frame. Doing this depends on
2421 the value of (window-start WINDOW), so if calling this function
2422 in a program gives strange scrolling, make sure the window-start
2423 value is reasonable when this function is called. */)
2432 window
= selected_window
;
2434 CHECK_LIVE_WINDOW (window
);
2435 w
= XWINDOW (window
);
2437 startpos
= marker_position (w
->start
);
2438 top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2440 if (MINI_WINDOW_P (w
) && top
> 0)
2441 error ("Can't expand minibuffer to full frame");
2443 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
2445 /* Try to minimize scrolling, by setting the window start to the point
2446 will cause the text at the old window start to be at the same place
2447 on the frame. But don't try to do this if the window start is
2448 outside the visible portion (as might happen when the display is
2449 not current, due to typeahead). */
2450 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2452 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2453 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2455 struct position pos
;
2456 struct buffer
*obuf
= current_buffer
;
2458 Fset_buffer (w
->buffer
);
2459 /* This computation used to temporarily move point, but that can
2460 have unwanted side effects due to text properties. */
2461 pos
= *vmotion (startpos
, -top
, w
);
2463 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2464 w
->window_end_valid
= Qnil
;
2465 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
2466 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
2468 /* We need to do this, so that the window-scroll-functions
2470 w
->optional_new_start
= Qt
;
2472 set_buffer_internal (obuf
);
2478 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
2479 1, 2, "bDelete windows on (buffer): ",
2480 doc
: /* Delete all windows showing BUFFER.
2481 BUFFER must be a buffer or the name of an existing buffer.
2482 Optional second argument FRAME controls which frames are affected.
2483 If optional argument FRAME is `visible', search all visible frames.
2484 If FRAME is 0, search all visible and iconified frames.
2485 If FRAME is nil, search all frames.
2486 If FRAME is t, search only the selected frame.
2487 If FRAME is a frame, search only that frame. */)
2489 Lisp_Object buffer
, frame
;
2491 /* FRAME uses t and nil to mean the opposite of what window_loop
2495 else if (EQ (frame
, Qt
))
2500 buffer
= Fget_buffer (buffer
);
2501 CHECK_BUFFER (buffer
);
2502 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
2508 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
2509 Sreplace_buffer_in_windows
,
2510 1, 1, "bReplace buffer in windows: ",
2511 doc
: /* Replace BUFFER with some other buffer in all windows showing it.
2512 BUFFER may be a buffer or the name of an existing buffer. */)
2518 buffer
= Fget_buffer (buffer
);
2519 CHECK_BUFFER (buffer
);
2520 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
2525 /* Replace BUFFER with some other buffer in all windows
2526 of all frames, even those on other keyboards. */
2529 replace_buffer_in_all_windows (buffer
)
2533 Lisp_Object tail
, frame
;
2535 /* A single call to window_loop won't do the job
2536 because it only considers frames on the current keyboard.
2537 So loop manually over frames, and handle each one. */
2538 FOR_EACH_FRAME (tail
, frame
)
2539 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
2541 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
2545 /* Set the height of WINDOW and all its inferiors. */
2547 /* The smallest acceptable dimensions for a window. Anything smaller
2548 might crash Emacs. */
2550 #define MIN_SAFE_WINDOW_WIDTH (2)
2551 #define MIN_SAFE_WINDOW_HEIGHT (1)
2553 /* Make sure that window_min_height and window_min_width are
2554 not too small; if they are, set them to safe minima. */
2557 check_min_window_sizes ()
2559 /* Smaller values might permit a crash. */
2560 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
2561 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
2562 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
2563 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
2566 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2567 minimum allowable size. */
2570 check_frame_size (frame
, rows
, cols
)
2574 /* For height, we have to see:
2575 how many windows the frame has at minimum (one or two),
2576 and whether it has a menu bar or other special stuff at the top. */
2578 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
2579 ? MIN_SAFE_WINDOW_HEIGHT
2580 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
2582 if (FRAME_TOP_MARGIN (frame
) > 0)
2583 min_height
+= FRAME_TOP_MARGIN (frame
);
2585 if (*rows
< min_height
)
2587 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2588 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2591 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2592 check if W's width can be changed, otherwise check W's height.
2593 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2594 siblings, too. If none of the siblings is resizable, WINDOW isn't
2598 window_fixed_size_p (w
, width_p
, check_siblings_p
)
2600 int width_p
, check_siblings_p
;
2605 if (!NILP (w
->hchild
))
2607 c
= XWINDOW (w
->hchild
);
2611 /* A horiz. combination is fixed-width if all of if its
2613 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2614 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2615 fixed_p
= c
== NULL
;
2619 /* A horiz. combination is fixed-height if one of if its
2621 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2622 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2623 fixed_p
= c
!= NULL
;
2626 else if (!NILP (w
->vchild
))
2628 c
= XWINDOW (w
->vchild
);
2632 /* A vert. combination is fixed-width if one of if its
2634 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2635 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2636 fixed_p
= c
!= NULL
;
2640 /* A vert. combination is fixed-height if all of if its
2642 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2643 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2644 fixed_p
= c
== NULL
;
2647 else if (BUFFERP (w
->buffer
))
2649 struct buffer
*old
= current_buffer
;
2652 current_buffer
= XBUFFER (w
->buffer
);
2653 val
= find_symbol_value (Qwindow_size_fixed
);
2654 current_buffer
= old
;
2657 if (!EQ (val
, Qunbound
))
2659 fixed_p
= !NILP (val
);
2662 && ((EQ (val
, Qheight
) && width_p
)
2663 || (EQ (val
, Qwidth
) && !width_p
)))
2667 /* Can't tell if this one is resizable without looking at
2668 siblings. If all siblings are fixed-size this one is too. */
2669 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
2673 for (child
= w
->prev
; !NILP (child
); child
= XWINDOW (child
)->prev
)
2674 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2678 for (child
= w
->next
; !NILP (child
); child
= XWINDOW (child
)->next
)
2679 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2692 /* Return the minimum size for leaf window W. WIDTH_P non-zero means
2693 take into account fringes and the scrollbar of W. WIDTH_P zero
2694 means take into account mode-line and header-line of W. Return 1
2695 for the minibuffer. */
2698 window_min_size_2 (w
, width_p
)
2705 size
= max (window_min_width
,
2706 (MIN_SAFE_WINDOW_WIDTH
2707 + WINDOW_FRINGE_COLS (w
)
2708 + WINDOW_SCROLL_BAR_COLS (w
)));
2709 else if (MINI_WINDOW_P (w
))
2712 size
= max (window_min_height
,
2713 (MIN_SAFE_WINDOW_HEIGHT
2714 + (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)
2715 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 )));
2720 /* Return the minimum size of window W, not taking fixed-width windows
2721 into account. WIDTH_P non-zero means return the minimum width,
2722 otherwise return the minimum height. If W is a combination window,
2723 compute the minimum size from the minimum sizes of W's children. */
2726 window_min_size_1 (w
, width_p
)
2733 if (!NILP (w
->hchild
))
2735 c
= XWINDOW (w
->hchild
);
2740 /* The min width of a horizontal combination is
2741 the sum of the min widths of its children. */
2744 size
+= window_min_size_1 (c
, width_p
);
2745 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2750 /* The min height a horizontal combination equals
2751 the maximum of all min height of its children. */
2754 int min_size
= window_min_size_1 (c
, width_p
);
2755 size
= max (min_size
, size
);
2756 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2760 else if (!NILP (w
->vchild
))
2762 c
= XWINDOW (w
->vchild
);
2767 /* The min width of a vertical combination is
2768 the maximum of the min widths of its children. */
2771 int min_size
= window_min_size_1 (c
, width_p
);
2772 size
= max (min_size
, size
);
2773 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2778 /* The min height of a vertical combination equals
2779 the sum of the min height of its children. */
2782 size
+= window_min_size_1 (c
, width_p
);
2783 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2788 size
= window_min_size_2 (w
, width_p
);
2794 /* Return the minimum size of window W, taking fixed-size windows into
2795 account. WIDTH_P non-zero means return the minimum width,
2796 otherwise return the minimum height. IGNORE_FIXED_P non-zero means
2797 ignore if W is fixed-size. Set *FIXED to 1 if W is fixed-size
2798 unless FIXED is null. */
2801 window_min_size (w
, width_p
, ignore_fixed_p
, fixed
)
2803 int width_p
, ignore_fixed_p
, *fixed
;
2810 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
2816 size
= width_p
? XFASTINT (w
->total_cols
) : XFASTINT (w
->total_lines
);
2818 size
= window_min_size_1 (w
, width_p
);
2824 /* Adjust the margins of window W if text area is too small.
2825 Return 1 if window width is ok after adjustment; 0 if window
2826 is still too narrow. */
2829 adjust_window_margins (w
)
2832 int box_cols
= (WINDOW_TOTAL_COLS (w
)
2833 - WINDOW_FRINGE_COLS (w
)
2834 - WINDOW_SCROLL_BAR_COLS (w
));
2835 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
2836 + WINDOW_RIGHT_MARGIN_COLS (w
));
2838 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
2841 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
2844 /* Window's text area is too narrow, but reducing the window
2845 margins will fix that. */
2846 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
2847 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
2849 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
2850 w
->left_margin_cols
= w
->right_margin_cols
2851 = make_number (margin_cols
/2);
2853 w
->right_margin_cols
= make_number (margin_cols
);
2856 w
->left_margin_cols
= make_number (margin_cols
);
2860 /* Calculate new sizes for windows in the list FORWARD when the window size
2861 goes from TOTAL to SIZE. TOTAL must be greater than SIZE.
2862 The number of windows in FORWARD is NCHILDREN, and the number that
2863 can shrink is SHRINKABLE.
2864 The minimum size a window can have is MIN_SIZE.
2865 If we are shrinking fixed windows, RESIZE_FIXED_P is non-zero.
2866 If we are shrinking columns, WIDTH_P is non-zero, otherwise we are
2869 This function returns an allocated array of new sizes that the caller
2870 must free. The size -1 means the window is fixed and RESIZE_FIXED_P
2871 is zero. Array index 0 refers to the first window in FORWARD, 1 to
2872 the second, and so on.
2874 This function tries to keep windows at least at the minimum size
2875 and resize other windows before it resizes any window to zero (i.e.
2876 delete that window).
2878 Windows are resized proportional to their size, so bigger windows
2879 shrink more than smaller windows. */
2881 shrink_windows (total
, size
, nchildren
, shrinkable
,
2882 min_size
, resize_fixed_p
, forward
, width_p
)
2883 int total
, size
, nchildren
, shrinkable
, min_size
;
2884 int resize_fixed_p
, width_p
;
2885 Lisp_Object forward
;
2887 int available_resize
= 0;
2891 int smallest
= total
;
2892 int total_removed
= 0;
2893 int total_shrink
= total
- size
;
2896 new_sizes
= xmalloc (sizeof (*new_sizes
) * nchildren
);
2898 for (i
= 0, child
= forward
; !NILP (child
); child
= c
->next
, ++i
)
2902 c
= XWINDOW (child
);
2903 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2905 if (! resize_fixed_p
&& window_fixed_size_p (c
, width_p
, 0))
2909 new_sizes
[i
] = child_size
;
2910 if (child_size
> min_size
)
2911 available_resize
+= child_size
- min_size
;
2914 /* We might need to shrink some windows to zero. Find the smallest
2915 windows and set them to 0 until we can fulfil the new size. */
2917 while (shrinkable
> 1 && size
+ available_resize
< total
)
2919 for (i
= 0; i
< nchildren
; ++i
)
2920 if (new_sizes
[i
] > 0 && smallest
> new_sizes
[i
])
2921 smallest
= new_sizes
[i
];
2923 for (i
= 0; i
< nchildren
; ++i
)
2924 if (new_sizes
[i
] == smallest
)
2926 /* Resize this window down to zero. */
2928 if (smallest
> min_size
)
2929 available_resize
-= smallest
- min_size
;
2930 available_resize
+= smallest
;
2932 total_removed
+= smallest
;
2934 /* We don't know what the smallest is now. */
2937 /* Out of for, just remove one window at the time and
2938 check again if we have enough space. */
2943 /* Now, calculate the new sizes. Try to shrink each window
2944 proportional to its size. */
2945 for (i
= 0; i
< nchildren
; ++i
)
2947 if (new_sizes
[i
] > min_size
)
2949 int to_shrink
= total_shrink
*new_sizes
[i
]/total
;
2950 if (new_sizes
[i
] - to_shrink
< min_size
)
2951 to_shrink
= new_sizes
[i
] - min_size
;
2952 new_sizes
[i
] -= to_shrink
;
2953 total_removed
+= to_shrink
;
2957 /* Any reminder due to rounding, we just subtract from windows
2958 that are left and still can be shrunk. */
2959 while (total_shrink
> total_removed
)
2961 int nonzero_sizes
= 0;
2962 int nonzero_idx
= -1;
2964 for (i
= 0; i
< nchildren
; ++i
)
2965 if (new_sizes
[i
] > 0)
2971 for (i
= 0; i
< nchildren
; ++i
)
2972 if (new_sizes
[i
] > min_size
)
2977 /* Out of for, just shrink one window at the time and
2978 check again if we have enough space. */
2983 /* Special case, only one window left. */
2984 if (nonzero_sizes
== 1)
2988 /* Any surplus due to rounding, we add to windows that are left. */
2989 while (total_shrink
< total_removed
)
2991 for (i
= 0; i
< nchildren
; ++i
)
2993 if (new_sizes
[i
] != 0 && total_shrink
< total_removed
)
3005 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
3006 WINDOW's width. Resize WINDOW's children, if any, so that they
3007 keep their proportionate size relative to WINDOW.
3009 If FIRST_ONLY is 1, change only the first of WINDOW's children when
3010 they are in series. If LAST_ONLY is 1, change only the last of
3011 WINDOW's children when they are in series.
3013 Propagate WINDOW's top or left edge position to children. Delete
3014 windows that become too small unless NODELETE_P is non-zero.
3016 If NODELETE_P is 2, that means we do delete windows that are
3017 too small, even if they were too small before! */
3020 size_window (window
, size
, width_p
, nodelete_p
, first_only
, last_only
)
3022 int size
, width_p
, nodelete_p
;
3023 int first_only
, last_only
;
3025 struct window
*w
= XWINDOW (window
);
3027 Lisp_Object child
, *forward
, *sideward
;
3028 int old_size
, min_size
, safe_min_size
;
3030 check_min_window_sizes ();
3031 size
= max (0, size
);
3033 /* If the window has been "too small" at one point,
3034 don't delete it for being "too small" in the future.
3035 Preserve it as long as that is at all possible. */
3038 old_size
= WINDOW_TOTAL_COLS (w
);
3039 min_size
= window_min_width
;
3040 safe_min_size
= window_min_size_2 (w
, 1);
3044 old_size
= XINT (w
->total_lines
);
3045 min_size
= window_min_height
;
3046 safe_min_size
= window_min_size_2 (w
, 0);
3049 if (old_size
< min_size
&& nodelete_p
!= 2)
3050 w
->too_small_ok
= Qt
;
3052 /* Move the following test here since otherwise the
3053 preceding test doesn't make sense. martin. */
3054 if (nodelete_p
== 2)
3057 /* Maybe delete WINDOW if it's too small. */
3058 if (nodelete_p
!= 1 && !NILP (w
->parent
))
3060 if (!MINI_WINDOW_P (w
) && !NILP (w
->too_small_ok
))
3061 min_size
= width_p
? MIN_SAFE_WINDOW_WIDTH
: MIN_SAFE_WINDOW_HEIGHT
;
3062 if (min_size
< safe_min_size
)
3063 min_size
= safe_min_size
;
3064 if (size
< min_size
)
3066 delete_window (window
);
3071 /* Set redisplay hints. */
3072 w
->last_modified
= make_number (0);
3073 w
->last_overlay_modified
= make_number (0);
3074 windows_or_buffers_changed
++;
3075 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w
->frame
)) = 1;
3079 sideward
= &w
->vchild
;
3080 forward
= &w
->hchild
;
3081 w
->total_cols
= make_number (size
);
3082 adjust_window_margins (w
);
3086 sideward
= &w
->hchild
;
3087 forward
= &w
->vchild
;
3088 w
->total_lines
= make_number (size
);
3089 w
->orig_total_lines
= Qnil
;
3092 if (!NILP (*sideward
))
3094 /* We have a chain of parallel siblings whose size should all change. */
3095 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
3097 c
= XWINDOW (child
);
3099 c
->left_col
= w
->left_col
;
3101 c
->top_line
= w
->top_line
;
3102 size_window (child
, size
, width_p
, nodelete_p
,
3103 first_only
, last_only
);
3106 else if (!NILP (*forward
) && last_only
)
3108 /* Change the last in a series of siblings. */
3109 Lisp_Object last_child
;
3112 for (child
= *forward
; !NILP (child
); child
= c
->next
)
3114 c
= XWINDOW (child
);
3118 child_size
= XINT (width_p
? c
->total_cols
: c
->total_lines
);
3119 size_window (last_child
,
3120 size
- old_size
+ child_size
,
3121 width_p
, nodelete_p
, first_only
, last_only
);
3123 else if (!NILP (*forward
) && first_only
)
3125 /* Change the first in a series of siblings. */
3129 c
= XWINDOW (child
);
3132 c
->left_col
= w
->left_col
;
3134 c
->top_line
= w
->top_line
;
3136 child_size
= XINT (width_p
? c
->total_cols
: c
->total_lines
);
3138 size
- old_size
+ child_size
,
3139 width_p
, nodelete_p
, first_only
, last_only
);
3141 else if (!NILP (*forward
))
3143 int fixed_size
, each
, extra
, n
;
3144 int resize_fixed_p
, nfixed
;
3145 int last_pos
, first_pos
, nchildren
, total
;
3146 int *new_sizes
= NULL
;
3148 /* Determine the fixed-size portion of this window, and the
3149 number of child windows. */
3150 fixed_size
= nchildren
= nfixed
= total
= 0;
3151 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
3155 c
= XWINDOW (child
);
3156 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
3157 total
+= child_size
;
3159 if (window_fixed_size_p (c
, width_p
, 0))
3161 fixed_size
+= child_size
;
3166 /* If the new size is smaller than fixed_size, or if there
3167 aren't any resizable windows, allow resizing fixed-size
3169 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
3171 /* Compute how many lines/columns to add/remove to each child. The
3172 value of extra takes care of rounding errors. */
3173 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
3174 if (size
< total
&& n
> 1)
3175 new_sizes
= shrink_windows (total
, size
, nchildren
, n
, min_size
,
3176 resize_fixed_p
, *forward
, width_p
);
3179 each
= (size
- total
) / n
;
3180 extra
= (size
- total
) - n
* each
;
3183 /* Compute new children heights and edge positions. */
3184 first_pos
= width_p
? XINT (w
->left_col
) : XINT (w
->top_line
);
3185 last_pos
= first_pos
;
3186 for (n
= 0, child
= *forward
; !NILP (child
); child
= c
->next
, ++n
)
3188 int new_size
, old_size
;
3190 c
= XWINDOW (child
);
3191 old_size
= width_p
? XFASTINT (c
->total_cols
) : XFASTINT (c
->total_lines
);
3192 new_size
= old_size
;
3194 /* The top or left edge position of this child equals the
3195 bottom or right edge of its predecessor. */
3197 c
->left_col
= make_number (last_pos
);
3199 c
->top_line
= make_number (last_pos
);
3201 /* If this child can be resized, do it. */
3202 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
3204 new_size
= new_sizes
? new_sizes
[n
] : old_size
+ each
+ extra
;
3208 /* Set new height. Note that size_window also propagates
3209 edge positions to children, so it's not a no-op if we
3210 didn't change the child's size. */
3211 size_window (child
, new_size
, width_p
, 1, first_only
, last_only
);
3213 /* Remember the bottom/right edge position of this child; it
3214 will be used to set the top/left edge of the next child. */
3215 last_pos
+= new_size
;
3218 if (new_sizes
) xfree (new_sizes
);
3220 /* We should have covered the parent exactly with child windows. */
3221 xassert (size
== last_pos
- first_pos
);
3223 /* Now delete any children that became too small. */
3225 for (child
= *forward
; !NILP (child
); child
= c
->next
)
3228 c
= XWINDOW (child
);
3229 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
3230 size_window (child
, child_size
, width_p
, 2, first_only
, last_only
);
3235 /* Set WINDOW's height to HEIGHT, and recursively change the height of
3236 WINDOW's children. NODELETE non-zero means don't delete windows
3237 that become too small in the process. (The caller should check
3238 later and do so if appropriate.) */
3241 set_window_height (window
, height
, nodelete
)
3246 size_window (window
, height
, 0, nodelete
, 0, 0);
3250 /* Set WINDOW's width to WIDTH, and recursively change the width of
3251 WINDOW's children. NODELETE non-zero means don't delete windows
3252 that become too small in the process. (The caller should check
3253 later and do so if appropriate.) */
3256 set_window_width (window
, width
, nodelete
)
3261 size_window (window
, width
, 1, nodelete
, 0, 0);
3264 /* Change window heights in windows rooted in WINDOW by N lines. */
3267 change_window_heights (window
, n
)
3271 struct window
*w
= XWINDOW (window
);
3273 XSETFASTINT (w
->top_line
, XFASTINT (w
->top_line
) + n
);
3274 XSETFASTINT (w
->total_lines
, XFASTINT (w
->total_lines
) - n
);
3276 if (INTEGERP (w
->orig_top_line
))
3277 XSETFASTINT (w
->orig_top_line
, XFASTINT (w
->orig_top_line
) + n
);
3278 if (INTEGERP (w
->orig_total_lines
))
3279 XSETFASTINT (w
->orig_total_lines
, XFASTINT (w
->orig_total_lines
) - n
);
3281 /* Handle just the top child in a vertical split. */
3282 if (!NILP (w
->vchild
))
3283 change_window_heights (w
->vchild
, n
);
3285 /* Adjust all children in a horizontal split. */
3286 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
3288 w
= XWINDOW (window
);
3289 change_window_heights (window
, n
);
3294 int window_select_count
;
3297 Fset_window_buffer_unwind (obuf
)
3304 EXFUN (Fset_window_fringes
, 4);
3305 EXFUN (Fset_window_scroll_bars
, 4);
3307 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
3308 means it's allowed to run hooks. See make_frame for a case where
3309 it's not allowed. KEEP_MARGINS_P non-zero means that the current
3310 margins, fringes, and scroll-bar settings of the window are not
3311 reset from the buffer's local settings. */
3314 set_window_buffer (window
, buffer
, run_hooks_p
, keep_margins_p
)
3315 Lisp_Object window
, buffer
;
3316 int run_hooks_p
, keep_margins_p
;
3318 struct window
*w
= XWINDOW (window
);
3319 struct buffer
*b
= XBUFFER (buffer
);
3320 int count
= SPECPDL_INDEX ();
3324 if (EQ (window
, selected_window
))
3325 b
->last_selected_window
= window
;
3327 /* Let redisplay errors through. */
3328 b
->display_error_modiff
= 0;
3330 /* Update time stamps of buffer display. */
3331 if (INTEGERP (b
->display_count
))
3332 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
3333 b
->display_time
= Fcurrent_time ();
3335 XSETFASTINT (w
->window_end_pos
, 0);
3336 XSETFASTINT (w
->window_end_vpos
, 0);
3337 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
3338 w
->window_end_valid
= Qnil
;
3339 w
->hscroll
= w
->min_hscroll
= make_number (0);
3341 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3342 set_marker_restricted (w
->start
,
3343 make_number (b
->last_window_start
),
3345 w
->start_at_line_beg
= Qnil
;
3346 w
->force_start
= Qnil
;
3347 XSETFASTINT (w
->last_modified
, 0);
3348 XSETFASTINT (w
->last_overlay_modified
, 0);
3349 windows_or_buffers_changed
++;
3351 /* We must select BUFFER for running the window-scroll-functions.
3352 If WINDOW is selected, switch permanently.
3353 Otherwise, switch but go back to the ambient buffer afterward. */
3354 if (EQ (window
, selected_window
))
3355 Fset_buffer (buffer
);
3356 /* We can't check ! NILP (Vwindow_scroll_functions) here
3357 because that might itself be a local variable. */
3358 else if (window_initialized
)
3360 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
3361 Fset_buffer (buffer
);
3364 if (!keep_margins_p
)
3366 /* Set left and right marginal area width etc. from buffer. */
3368 /* This may call adjust_window_margins three times, so
3369 temporarily disable window margins. */
3370 Lisp_Object save_left
= w
->left_margin_cols
;
3371 Lisp_Object save_right
= w
->right_margin_cols
;
3373 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
3375 Fset_window_fringes (window
,
3376 b
->left_fringe_width
, b
->right_fringe_width
,
3377 b
->fringes_outside_margins
);
3379 Fset_window_scroll_bars (window
,
3380 b
->scroll_bar_width
,
3381 b
->vertical_scroll_bar_type
, Qnil
);
3383 w
->left_margin_cols
= save_left
;
3384 w
->right_margin_cols
= save_right
;
3386 Fset_window_margins (window
,
3387 b
->left_margin_cols
, b
->right_margin_cols
);
3392 if (! NILP (Vwindow_scroll_functions
))
3393 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3394 Fmarker_position (w
->start
));
3396 if (! NILP (Vwindow_configuration_change_hook
)
3397 && ! NILP (Vrun_hooks
))
3398 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3401 unbind_to (count
, Qnil
);
3405 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3406 doc
: /* Make WINDOW display BUFFER as its contents.
3407 BUFFER can be a buffer or the name of an existing buffer.
3408 Optional third arg KEEP-MARGINS non-nil means that WINDOW's current
3409 display margins, fringe widths, and scroll bar settings are maintained;
3410 the default is to reset these from BUFFER's local settings or the frame
3413 This function runs the hook `window-scroll-functions'. */)
3414 (window
, buffer
, keep_margins
)
3415 register Lisp_Object window
, buffer
, keep_margins
;
3417 register Lisp_Object tem
;
3418 register struct window
*w
= decode_window (window
);
3420 XSETWINDOW (window
, w
);
3421 buffer
= Fget_buffer (buffer
);
3422 CHECK_BUFFER (buffer
);
3424 if (NILP (XBUFFER (buffer
)->name
))
3425 error ("Attempt to display deleted buffer");
3429 error ("Window is deleted");
3430 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
3431 is first being set up. */
3433 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
3434 error ("Window is dedicated to `%s'",
3435 SDATA (XBUFFER (tem
)->name
));
3440 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3444 /* Note that selected_window can be nil
3445 when this is called from Fset_window_configuration. */
3447 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
3448 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
3449 If WINDOW is not already selected, make WINDOW's buffer current
3450 and make WINDOW the frame's selected window. Return WINDOW.
3451 Optional second arg NORECORD non-nil means
3452 do not put this buffer at the front of the list of recently selected ones.
3454 Note that the main editor command loop
3455 selects the buffer of the selected window before each command. */)
3457 register Lisp_Object window
, norecord
;
3459 register struct window
*w
;
3460 register struct window
*ow
;
3463 CHECK_LIVE_WINDOW (window
);
3465 w
= XWINDOW (window
);
3466 w
->frozen_window_start_p
= 0;
3468 ++window_select_count
;
3469 XSETFASTINT (w
->use_time
, window_select_count
);
3470 if (EQ (window
, selected_window
))
3473 sf
= SELECTED_FRAME ();
3474 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
3476 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
3477 /* Use this rather than Fhandle_switch_frame
3478 so that FRAME_FOCUS_FRAME is moved appropriately as we
3479 move around in the state where a minibuffer in a separate
3481 Fselect_frame (WINDOW_FRAME (w
));
3482 /* Fselect_frame called us back so we've done all the work already. */
3483 eassert (EQ (window
, selected_window
));
3487 sf
->selected_window
= window
;
3489 /* Store the current buffer's actual point into the
3490 old selected window. It belongs to that window,
3491 and when the window is not selected, must be in the window. */
3492 if (!NILP (selected_window
))
3494 ow
= XWINDOW (selected_window
);
3495 if (! NILP (ow
->buffer
))
3496 set_marker_both (ow
->pointm
, ow
->buffer
,
3497 BUF_PT (XBUFFER (ow
->buffer
)),
3498 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
3501 selected_window
= window
;
3503 if (NILP (norecord
))
3504 record_buffer (w
->buffer
);
3505 Fset_buffer (w
->buffer
);
3507 XBUFFER (w
->buffer
)->last_selected_window
= window
;
3509 /* Go to the point recorded in the window.
3510 This is important when the buffer is in more
3511 than one window. It also matters when
3512 redisplay_window has altered point after scrolling,
3513 because it makes the change only in the window. */
3515 register int new_point
= marker_position (w
->pointm
);
3516 if (new_point
< BEGV
)
3518 else if (new_point
> ZV
)
3524 windows_or_buffers_changed
++;
3529 select_window_norecord (window
)
3532 return Fselect_window (window
, Qt
);
3535 /* Deiconify the frame containing the window WINDOW,
3536 unless it is the selected frame;
3539 The reason for the exception for the selected frame
3540 is that it seems better not to change the selected frames visibility
3541 merely because of displaying a different buffer in it.
3542 The deiconification is useful when a buffer gets shown in
3543 another frame that you were not using lately. */
3546 display_buffer_1 (window
)
3549 Lisp_Object frame
= XWINDOW (window
)->frame
;
3550 FRAME_PTR f
= XFRAME (frame
);
3552 FRAME_SAMPLE_VISIBILITY (f
);
3554 if (EQ (frame
, selected_frame
))
3555 ; /* Assume the selected frame is already visible enough. */
3556 else if (minibuf_level
> 0
3557 && MINI_WINDOW_P (XWINDOW (selected_window
))
3558 && WINDOW_LIVE_P (minibuf_selected_window
)
3559 && EQ (frame
, WINDOW_FRAME (XWINDOW (minibuf_selected_window
))))
3560 ; /* Assume the frame from which we invoked the minibuffer is visible. */
3563 if (FRAME_ICONIFIED_P (f
))
3564 Fmake_frame_visible (frame
);
3565 else if (FRAME_VISIBLE_P (f
))
3566 Fraise_frame (frame
);
3572 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
3573 doc
: /* Returns non-nil if a buffer named BUFFER-NAME gets a special frame.
3574 If the value is t, `display-buffer' or `pop-to-buffer' would create a
3575 special frame for that buffer using the default frame parameters.
3577 If the value is a list, it is a list of frame parameters that would be used
3578 to make a frame for that buffer.
3579 The variables `special-display-buffer-names'
3580 and `special-display-regexps' control this. */)
3582 Lisp_Object buffer_name
;
3586 CHECK_STRING (buffer_name
);
3588 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
3592 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
3596 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
3598 Lisp_Object car
= XCAR (tem
);
3600 && fast_string_match (car
, buffer_name
) >= 0)
3602 else if (CONSP (car
)
3603 && STRINGP (XCAR (car
))
3604 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
3610 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
3611 doc
: /* Returns non-nil if a buffer named BUFFER-NAME would use the same window.
3612 More precisely, if `display-buffer' or `pop-to-buffer' would display
3613 that buffer in the selected window rather than (as usual) in some other window.
3614 See `same-window-buffer-names' and `same-window-regexps'. */)
3616 Lisp_Object buffer_name
;
3620 CHECK_STRING (buffer_name
);
3622 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
3626 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
3630 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
3632 Lisp_Object car
= XCAR (tem
);
3634 && fast_string_match (car
, buffer_name
) >= 0)
3636 else if (CONSP (car
)
3637 && STRINGP (XCAR (car
))
3638 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
3644 /* Use B so the default is (other-buffer). */
3645 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
3646 "BDisplay buffer: \nP",
3647 doc
: /* Make BUFFER appear in some window but don't select it.
3648 BUFFER must be the name of an existing buffer, or, when called from Lisp,
3650 If BUFFER is shown already in some window, just use that one,
3651 unless the window is the selected window and the optional second
3652 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).
3653 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
3654 Returns the window displaying BUFFER.
3655 If `display-buffer-reuse-frames' is non-nil, and another frame is currently
3656 displaying BUFFER, then simply raise that frame.
3658 The variables `special-display-buffer-names',
3659 `special-display-regexps', `same-window-buffer-names', and
3660 `same-window-regexps' customize how certain buffer names are handled.
3661 The latter two take effect only if NOT-THIS-WINDOW is nil.
3663 If optional argument FRAME is `visible', check all visible frames
3664 for a window to use.
3665 If FRAME is 0, check all visible and iconified frames.
3666 If FRAME is t, check all frames.
3667 If FRAME is a frame, check only that frame.
3668 If FRAME is nil, check only the selected frame
3669 (actually the last nonminibuffer frame),
3670 unless `pop-up-frames' or `display-buffer-reuse-frames' is non-nil,
3671 which means search visible and iconified frames.
3673 If a full-width window on a splittable frame is available to display
3674 the buffer, it may be split, subject to the value of the variable
3675 `split-height-threshold'.
3677 If `even-window-heights' is non-nil, window heights will be evened out
3678 if displaying the buffer causes two vertically adjacent windows to be
3680 (buffer
, not_this_window
, frame
)
3681 Lisp_Object buffer
, not_this_window
, frame
;
3683 register Lisp_Object window
, tem
, swp
;
3687 buffer
= Fget_buffer (buffer
);
3688 CHECK_BUFFER (buffer
);
3690 if (!NILP (Vdisplay_buffer_function
))
3691 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
3693 if (NILP (not_this_window
)
3694 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
3695 return display_buffer_1 (selected_window
);
3697 /* See if the user has specified this buffer should appear
3698 in the selected window. */
3699 if (NILP (not_this_window
))
3701 swp
= Fsame_window_p (XBUFFER (buffer
)->name
);
3702 if (!NILP (swp
) && !no_switch_window (selected_window
))
3704 Fswitch_to_buffer (buffer
, Qnil
);
3705 return display_buffer_1 (selected_window
);
3709 /* If the user wants pop-up-frames or display-buffer-reuse-frames,
3710 look for a window showing BUFFER on any visible or iconified frame.
3711 Otherwise search only the current frame. */
3714 else if (pop_up_frames
3715 || display_buffer_reuse_frames
3716 || last_nonminibuf_frame
== 0)
3717 XSETFASTINT (tem
, 0);
3719 XSETFRAME (tem
, last_nonminibuf_frame
);
3721 window
= Fget_buffer_window (buffer
, tem
);
3723 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
3724 return display_buffer_1 (window
);
3726 /* Certain buffer names get special handling. */
3727 if (!NILP (Vspecial_display_function
) && NILP (swp
))
3729 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
3731 return call1 (Vspecial_display_function
, buffer
);
3733 return call2 (Vspecial_display_function
, buffer
, tem
);
3736 /* If there are no frames open that have more than a minibuffer,
3737 we need to create a new frame. */
3738 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
3740 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3741 Fset_window_buffer (window
, buffer
, Qnil
);
3742 return display_buffer_1 (window
);
3745 f
= SELECTED_FRAME ();
3747 || FRAME_MINIBUF_ONLY_P (f
)
3748 /* If the current frame is a special display frame,
3749 don't try to reuse its windows. */
3750 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (f
))->dedicated
))
3753 struct gcpro gcpro1
;
3757 if (FRAME_MINIBUF_ONLY_P (f
))
3758 XSETFRAME (frames
, last_nonminibuf_frame
);
3760 /* Note that both Fget_largest_window and Fget_lru_window
3761 ignore minibuffers and dedicated windows.
3762 This means they can return nil. */
3764 /* If the frame we would try to split cannot be split,
3765 try other frames. */
3766 if (FRAME_NO_SPLIT_P (NILP (frames
) ? f
: last_nonminibuf_frame
))
3768 /* Try visible frames first. */
3769 window
= Fget_largest_window (Qvisible
, Qt
);
3770 /* If that didn't work, try iconified frames. */
3772 window
= Fget_largest_window (make_number (0), Qt
);
3773 #if 0 /* Don't try windows on other displays. */
3775 window
= Fget_largest_window (Qt
, Qt
);
3779 window
= Fget_largest_window (frames
, Qt
);
3781 /* If the largest window is tall enough, full-width, and either eligible
3782 for splitting or the only window, split it. */
3784 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3785 && WINDOW_FULL_WIDTH_P (XWINDOW (window
))
3786 && (window_height (window
) >= split_height_threshold
3787 || (NILP (XWINDOW (window
)->parent
)))
3788 && (window_height (window
)
3789 >= (2 * window_min_size_2 (XWINDOW (window
), 0))))
3790 window
= call1 (Vsplit_window_preferred_function
, window
);
3793 Lisp_Object upper
, lower
, other
;
3795 window
= Fget_lru_window (frames
, Qt
);
3796 /* If the LRU window is tall enough, and either eligible for
3797 splitting and selected or the only window, split it. */
3799 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3800 && ((EQ (window
, selected_window
)
3801 && window_height (window
) >= split_height_threshold
)
3802 || (NILP (XWINDOW (window
)->parent
)))
3803 && (window_height (window
)
3804 >= (2 * window_min_size_2 (XWINDOW (window
), 0))))
3805 window
= call1 (Vsplit_window_preferred_function
, window
);
3807 window
= Fget_lru_window (frames
, Qnil
);
3808 /* If Fget_lru_window returned nil, try other approaches. */
3810 /* Try visible frames first. */
3812 window
= Fget_buffer_window (buffer
, Qvisible
);
3814 window
= Fget_largest_window (Qvisible
, Qnil
);
3815 /* If that didn't work, try iconified frames. */
3817 window
= Fget_buffer_window (buffer
, make_number (0));
3819 window
= Fget_largest_window (make_number (0), Qnil
);
3821 #if 0 /* Don't try frames on other displays. */
3823 window
= Fget_buffer_window (buffer
, Qt
);
3825 window
= Fget_largest_window (Qt
, Qnil
);
3827 /* As a last resort, make a new frame. */
3829 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3830 /* If window appears above or below another,
3831 even out their heights. */
3832 other
= upper
= lower
= Qnil
;
3833 if (!NILP (XWINDOW (window
)->prev
))
3834 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
3835 if (!NILP (XWINDOW (window
)->next
))
3836 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
3838 && !NILP (Veven_window_heights
)
3839 /* Check that OTHER and WINDOW are vertically arrayed. */
3840 && !EQ (XWINDOW (other
)->top_line
, XWINDOW (window
)->top_line
)
3841 && (XFASTINT (XWINDOW (other
)->total_lines
)
3842 > XFASTINT (XWINDOW (window
)->total_lines
)))
3844 int total
= (XFASTINT (XWINDOW (other
)->total_lines
)
3845 + XFASTINT (XWINDOW (window
)->total_lines
));
3846 enlarge_window (upper
,
3847 total
/ 2 - XFASTINT (XWINDOW (upper
)->total_lines
),
3854 window
= Fget_lru_window (Qnil
, Qnil
);
3856 Fset_window_buffer (window
, buffer
, Qnil
);
3857 return display_buffer_1 (window
);
3861 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3863 doc
: /* Force all windows to be updated on next redisplay.
3864 If optional arg OBJECT is a window, force redisplay of that window only.
3865 If OBJECT is a buffer or buffer name, force redisplay of all windows
3866 displaying that buffer. */)
3872 windows_or_buffers_changed
++;
3873 update_mode_lines
++;
3877 if (WINDOWP (object
))
3879 struct window
*w
= XWINDOW (object
);
3880 mark_window_display_accurate (object
, 0);
3881 w
->update_mode_line
= Qt
;
3882 if (BUFFERP (w
->buffer
))
3883 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
3884 ++update_mode_lines
;
3888 if (STRINGP (object
))
3889 object
= Fget_buffer (object
);
3890 if (BUFFERP (object
) && !NILP (XBUFFER (object
)->name
))
3892 /* Walk all windows looking for buffer, and force update
3893 of each of those windows. */
3895 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3896 return NILP (object
) ? Qnil
: Qt
;
3899 /* If nothing suitable was found, just return.
3900 We could signal an error, but this feature will typically be used
3901 asynchronously in timers or process sentinels, so we don't. */
3907 temp_output_buffer_show (buf
)
3908 register Lisp_Object buf
;
3910 register struct buffer
*old
= current_buffer
;
3911 register Lisp_Object window
;
3912 register struct window
*w
;
3914 XBUFFER (buf
)->directory
= current_buffer
->directory
;
3917 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3921 #if 0 /* rms: there should be no reason for this. */
3922 XBUFFER (buf
)->prevent_redisplay_optimizations_p
= 1;
3924 set_buffer_internal (old
);
3926 if (!NILP (Vtemp_buffer_show_function
))
3927 call1 (Vtemp_buffer_show_function
, buf
);
3930 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
3932 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3933 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3934 Vminibuf_scroll_window
= window
;
3935 w
= XWINDOW (window
);
3936 XSETFASTINT (w
->hscroll
, 0);
3937 XSETFASTINT (w
->min_hscroll
, 0);
3938 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3939 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3941 /* Run temp-buffer-show-hook, with the chosen window selected
3942 and its buffer current. */
3944 if (!NILP (Vrun_hooks
)
3945 && !NILP (Fboundp (Qtemp_buffer_show_hook
))
3946 && !NILP (Fsymbol_value (Qtemp_buffer_show_hook
)))
3948 int count
= SPECPDL_INDEX ();
3949 Lisp_Object prev_window
, prev_buffer
;
3950 prev_window
= selected_window
;
3951 XSETBUFFER (prev_buffer
, old
);
3953 /* Select the window that was chosen, for running the hook.
3954 Note: Both Fselect_window and select_window_norecord may
3955 set-buffer to the buffer displayed in the window,
3956 so we need to save the current buffer. --stef */
3957 record_unwind_protect (Fset_buffer
, prev_buffer
);
3958 record_unwind_protect (select_window_norecord
, prev_window
);
3959 Fselect_window (window
, Qt
);
3960 Fset_buffer (w
->buffer
);
3961 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
3962 unbind_to (count
, Qnil
);
3968 make_dummy_parent (window
)
3972 register struct window
*o
, *p
;
3975 o
= XWINDOW (window
);
3976 p
= allocate_window ();
3977 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
3978 ((struct Lisp_Vector
*) p
)->contents
[i
]
3979 = ((struct Lisp_Vector
*)o
)->contents
[i
];
3980 XSETWINDOW (new, p
);
3983 XSETFASTINT (p
->sequence_number
, sequence_number
);
3985 /* Put new into window structure in place of window */
3986 replace_window (window
, new);
3999 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
4000 doc
: /* Split WINDOW, putting SIZE lines in the first of the pair.
4001 WINDOW defaults to selected one and SIZE to half its size.
4002 If optional third arg HORFLAG is non-nil, split side by side
4003 and put SIZE columns in the first of the pair. In that case,
4004 SIZE includes that window's scroll bar, or the divider column to its right.
4005 Interactively, all arguments are nil.
4007 Returns the newly created window (which is the lower or rightmost one).
4008 The upper or leftmost window is the original one, and remains selected
4009 if it was selected before.
4011 See Info node `(elisp)Splitting Windows' for more details and examples.*/)
4012 (window
, size
, horflag
)
4013 Lisp_Object window
, size
, horflag
;
4015 register Lisp_Object
new;
4016 register struct window
*o
, *p
;
4018 register int size_int
;
4021 window
= selected_window
;
4023 CHECK_LIVE_WINDOW (window
);
4025 o
= XWINDOW (window
);
4026 fo
= XFRAME (WINDOW_FRAME (o
));
4030 if (!NILP (horflag
))
4031 /* Calculate the size of the left-hand window, by dividing
4032 the usable space in columns by two.
4033 We round up, since the left-hand window may include
4034 a dividing line, while the right-hand may not. */
4035 size_int
= (XFASTINT (o
->total_cols
) + 1) >> 1;
4037 size_int
= XFASTINT (o
->total_lines
) >> 1;
4041 CHECK_NUMBER (size
);
4042 size_int
= XINT (size
);
4045 if (MINI_WINDOW_P (o
))
4046 error ("Attempt to split minibuffer window");
4047 else if (window_fixed_size_p (o
, !NILP (horflag
), 0))
4048 error ("Attempt to split fixed-size window");
4050 check_min_window_sizes ();
4054 int window_safe_height
= window_min_size_2 (o
, 0);
4056 if (size_int
< window_safe_height
)
4057 error ("Window height %d too small (after splitting)", size_int
);
4058 if (size_int
+ window_safe_height
> XFASTINT (o
->total_lines
))
4059 error ("Window height %d too small (after splitting)",
4060 XFASTINT (o
->total_lines
) - size_int
);
4061 if (NILP (o
->parent
)
4062 || NILP (XWINDOW (o
->parent
)->vchild
))
4064 make_dummy_parent (window
);
4066 XWINDOW (new)->vchild
= window
;
4071 int window_safe_width
= window_min_size_2 (o
, 1);
4073 if (size_int
< window_safe_width
)
4074 error ("Window width %d too small (after splitting)", size_int
);
4075 if (size_int
+ window_safe_width
> XFASTINT (o
->total_cols
))
4076 error ("Window width %d too small (after splitting)",
4077 XFASTINT (o
->total_cols
) - size_int
);
4078 if (NILP (o
->parent
)
4079 || NILP (XWINDOW (o
->parent
)->hchild
))
4081 make_dummy_parent (window
);
4083 XWINDOW (new)->hchild
= window
;
4087 /* Now we know that window's parent is a vertical combination
4088 if we are dividing vertically, or a horizontal combination
4089 if we are making side-by-side windows */
4091 windows_or_buffers_changed
++;
4092 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
4093 new = make_window ();
4096 p
->frame
= o
->frame
;
4098 if (!NILP (p
->next
))
4099 XWINDOW (p
->next
)->prev
= new;
4102 p
->parent
= o
->parent
;
4104 p
->window_end_valid
= Qnil
;
4105 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
4107 /* Duplicate special geometry settings. */
4109 p
->left_margin_cols
= o
->left_margin_cols
;
4110 p
->right_margin_cols
= o
->right_margin_cols
;
4111 p
->left_fringe_width
= o
->left_fringe_width
;
4112 p
->right_fringe_width
= o
->right_fringe_width
;
4113 p
->fringes_outside_margins
= o
->fringes_outside_margins
;
4114 p
->scroll_bar_width
= o
->scroll_bar_width
;
4115 p
->vertical_scroll_bar_type
= o
->vertical_scroll_bar_type
;
4117 /* Apportion the available frame space among the two new windows */
4119 if (!NILP (horflag
))
4121 p
->total_lines
= o
->total_lines
;
4122 p
->top_line
= o
->top_line
;
4123 XSETFASTINT (p
->total_cols
, XFASTINT (o
->total_cols
) - size_int
);
4124 XSETFASTINT (o
->total_cols
, size_int
);
4125 XSETFASTINT (p
->left_col
, XFASTINT (o
->left_col
) + size_int
);
4126 adjust_window_margins (p
);
4127 adjust_window_margins (o
);
4131 p
->left_col
= o
->left_col
;
4132 p
->total_cols
= o
->total_cols
;
4133 XSETFASTINT (p
->total_lines
, XFASTINT (o
->total_lines
) - size_int
);
4134 XSETFASTINT (o
->total_lines
, size_int
);
4135 XSETFASTINT (p
->top_line
, XFASTINT (o
->top_line
) + size_int
);
4138 /* Adjust glyph matrices. */
4141 Fset_window_buffer (new, o
->buffer
, Qt
);
4145 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
4146 doc
: /* Make current window ARG lines bigger.
4147 From program, optional second arg non-nil means grow sideways ARG columns.
4148 Interactively, if an argument is not given, make the window one line bigger.
4149 If HORIZONTAL is non-nil, enlarge horizontally instead of vertically.
4150 This function can delete windows, even the second window, if they get
4153 Lisp_Object arg
, horizontal
;
4156 enlarge_window (selected_window
, XINT (arg
), !NILP (horizontal
));
4158 if (! NILP (Vwindow_configuration_change_hook
))
4159 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
4164 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
4165 doc
: /* Make current window ARG lines smaller.
4166 From program, optional second arg non-nil means shrink sideways arg columns.
4167 Interactively, if an argument is not given, make the window one line smaller.
4168 Only siblings to the right or below are changed. */)
4170 Lisp_Object arg
, side
;
4173 enlarge_window (selected_window
, -XINT (arg
), !NILP (side
));
4175 if (! NILP (Vwindow_configuration_change_hook
))
4176 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
4182 window_height (window
)
4185 register struct window
*p
= XWINDOW (window
);
4186 return WINDOW_TOTAL_LINES (p
);
4190 window_width (window
)
4193 register struct window
*p
= XWINDOW (window
);
4194 return WINDOW_TOTAL_COLS (p
);
4199 *(horiz_flag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line))
4201 #define CURSIZE(w) \
4202 *(horiz_flag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines))
4205 /* Enlarge WINDOW by DELTA.
4206 HORIZ_FLAG nonzero means enlarge it horizontally;
4207 zero means do it vertically.
4209 Siblings of the selected window are resized to fulfill the size
4210 request. If they become too small in the process, they will be
4214 enlarge_window (window
, delta
, horiz_flag
)
4216 int delta
, horiz_flag
;
4218 Lisp_Object parent
, next
, prev
;
4222 int (*sizefun
) P_ ((Lisp_Object
))
4223 = horiz_flag
? window_width
: window_height
;
4224 void (*setsizefun
) P_ ((Lisp_Object
, int, int))
4225 = (horiz_flag
? set_window_width
: set_window_height
);
4227 /* Check values of window_min_width and window_min_height for
4229 check_min_window_sizes ();
4231 /* Give up if this window cannot be resized. */
4232 if (window_fixed_size_p (XWINDOW (window
), horiz_flag
, 1))
4233 error ("Window is not resizable");
4235 /* Find the parent of the selected window. */
4238 p
= XWINDOW (window
);
4244 error ("No other window to side of this one");
4249 ? !NILP (XWINDOW (parent
)->hchild
)
4250 : !NILP (XWINDOW (parent
)->vchild
))
4256 sizep
= &CURSIZE (window
);
4259 register int maxdelta
;
4261 /* Compute the maximum size increment this window can have. */
4263 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - XINT (*sizep
)
4264 /* This is a main window followed by a minibuffer. */
4265 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
4266 - window_min_size (XWINDOW (p
->next
),
4268 /* This is a minibuffer following a main window. */
4269 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
4270 - window_min_size (XWINDOW (p
->prev
),
4272 /* This is a frame with only one window, a minibuffer-only
4273 or a minibufferless frame. */
4276 if (delta
> maxdelta
)
4277 /* This case traps trying to make the minibuffer
4278 the full frame, or make the only window aside from the
4279 minibuffer the full frame. */
4283 if (XINT (*sizep
) + delta
< window_min_size (XWINDOW (window
), horiz_flag
, 0, 0))
4285 delete_window (window
);
4292 /* Find the total we can get from other siblings without deleting them. */
4294 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
4295 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
4297 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
4298 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
4301 /* If we can get it all from them without deleting them, do so. */
4302 if (delta
<= maximum
)
4304 Lisp_Object first_unaffected
;
4305 Lisp_Object first_affected
;
4310 first_affected
= window
;
4311 /* Look at one sibling at a time,
4312 moving away from this window in both directions alternately,
4313 and take as much as we can get without deleting that sibling. */
4315 && (!NILP (next
) || !NILP (prev
)))
4319 int this_one
= ((*sizefun
) (next
)
4320 - window_min_size (XWINDOW (next
),
4321 horiz_flag
, 0, &fixed_p
));
4324 if (this_one
> delta
)
4327 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
4328 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4333 next
= XWINDOW (next
)->next
;
4341 int this_one
= ((*sizefun
) (prev
)
4342 - window_min_size (XWINDOW (prev
),
4343 horiz_flag
, 0, &fixed_p
));
4346 if (this_one
> delta
)
4349 first_affected
= prev
;
4351 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
4352 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4357 prev
= XWINDOW (prev
)->prev
;
4361 xassert (delta
== 0);
4363 /* Now recalculate the edge positions of all the windows affected,
4364 based on the new sizes. */
4365 first_unaffected
= next
;
4366 prev
= first_affected
;
4367 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
4368 prev
= next
, next
= XWINDOW (next
)->next
)
4370 XSETINT (CURBEG (next
), XINT (CURBEG (prev
)) + (*sizefun
) (prev
));
4371 /* This does not change size of NEXT,
4372 but it propagates the new top edge to its children */
4373 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
4378 register int delta1
;
4379 register int opht
= (*sizefun
) (parent
);
4381 if (opht
<= XINT (*sizep
) + delta
)
4383 /* If trying to grow this window to or beyond size of the parent,
4384 just delete all the sibling windows. */
4385 Lisp_Object start
, tem
, next
;
4387 start
= XWINDOW (parent
)->vchild
;
4389 start
= XWINDOW (parent
)->hchild
;
4391 /* Delete any siblings that come after WINDOW. */
4392 tem
= XWINDOW (window
)->next
;
4393 while (! NILP (tem
))
4395 next
= XWINDOW (tem
)->next
;
4396 delete_window (tem
);
4400 /* Delete any siblings that come after WINDOW.
4401 Note that if START is not WINDOW, then WINDOW still
4402 Fhas siblings, so WINDOW has not yet replaced its parent. */
4404 while (! EQ (tem
, window
))
4406 next
= XWINDOW (tem
)->next
;
4407 delete_window (tem
);
4413 /* Otherwise, make delta1 just right so that if we add
4414 delta1 lines to this window and to the parent, and then
4415 shrink the parent back to its original size, the new
4416 proportional size of this window will increase by delta.
4418 The function size_window will compute the new height h'
4419 of the window from delta1 as:
4422 x = delta1 - delta1/n * n for the 1st resizable child
4425 where n is the number of children that can be resized.
4426 We can ignore x by choosing a delta1 that is a multiple of
4427 n. We want the height of this window to come out as
4437 The number of children n equals the number of resizable
4438 children of this window + 1 because we know window itself
4439 is resizable (otherwise we would have signalled an error). */
4441 struct window
*w
= XWINDOW (window
);
4445 for (s
= w
->next
; !NILP (s
); s
= XWINDOW (s
)->next
)
4446 if (!window_fixed_size_p (XWINDOW (s
), horiz_flag
, 0))
4448 for (s
= w
->prev
; !NILP (s
); s
= XWINDOW (s
)->prev
)
4449 if (!window_fixed_size_p (XWINDOW (s
), horiz_flag
, 0))
4454 /* Add delta1 lines or columns to this window, and to the parent,
4455 keeping things consistent while not affecting siblings. */
4456 XSETINT (CURSIZE (parent
), opht
+ delta1
);
4457 (*setsizefun
) (window
, XINT (*sizep
) + delta1
, 0);
4459 /* Squeeze out delta1 lines or columns from our parent,
4460 shriking this window and siblings proportionately.
4461 This brings parent back to correct size.
4462 Delta1 was calculated so this makes this window the desired size,
4463 taking it all out of the siblings. */
4464 (*setsizefun
) (parent
, opht
, 0);
4469 XSETFASTINT (p
->last_modified
, 0);
4470 XSETFASTINT (p
->last_overlay_modified
, 0);
4472 /* Adjust glyph matrices. */
4473 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4477 /* Adjust the size of WINDOW by DELTA, moving only its trailing edge.
4478 HORIZ_FLAG nonzero means adjust the width, moving the right edge.
4479 zero means adjust the height, moving the bottom edge.
4481 Following siblings of the selected window are resized to fulfill
4482 the size request. If they become too small in the process, they
4483 are not deleted; instead, we signal an error. */
4486 adjust_window_trailing_edge (window
, delta
, horiz_flag
)
4488 int delta
, horiz_flag
;
4490 Lisp_Object parent
, child
;
4492 Lisp_Object old_config
= Fcurrent_window_configuration (Qnil
);
4493 int delcount
= window_deletion_count
;
4495 /* Check values of window_min_width and window_min_height for
4497 check_min_window_sizes ();
4500 window
= Fselected_window ();
4502 CHECK_WINDOW (window
);
4504 /* Give up if this window cannot be resized. */
4505 if (window_fixed_size_p (XWINDOW (window
), horiz_flag
, 1))
4506 error ("Window is not resizable");
4510 Lisp_Object first_parallel
= Qnil
;
4514 /* This happens if WINDOW on the previous iteration was
4515 at top level of the window tree. */
4516 Fset_window_configuration (old_config
);
4517 error ("Specified window edge is fixed");
4520 p
= XWINDOW (window
);
4523 /* See if this level has windows in parallel in the specified
4524 direction. If so, set FIRST_PARALLEL to the first one. */
4527 if (! NILP (parent
) && !NILP (XWINDOW (parent
)->vchild
))
4528 first_parallel
= XWINDOW (parent
)->vchild
;
4529 else if (NILP (parent
) && !NILP (p
->next
))
4531 /* Handle the vertical chain of main window and minibuffer
4532 which has no parent. */
4533 first_parallel
= window
;
4534 while (! NILP (XWINDOW (first_parallel
)->prev
))
4535 first_parallel
= XWINDOW (first_parallel
)->prev
;
4540 if (! NILP (parent
) && !NILP (XWINDOW (parent
)->hchild
))
4541 first_parallel
= XWINDOW (parent
)->hchild
;
4544 /* If this level's succession is in the desired dimension,
4545 and this window is the last one, and there is no higher level,
4546 its trailing edge is fixed. */
4547 if (NILP (XWINDOW (window
)->next
) && NILP (first_parallel
)
4550 Fset_window_configuration (old_config
);
4551 error ("Specified window edge is fixed");
4554 /* Don't make this window too small. */
4555 if (XINT (CURSIZE (window
)) + delta
4556 < window_min_size_2 (XWINDOW (window
), horiz_flag
))
4558 Fset_window_configuration (old_config
);
4559 error ("Cannot adjust window size as specified");
4562 /* Clear out some redisplay caches. */
4563 XSETFASTINT (p
->last_modified
, 0);
4564 XSETFASTINT (p
->last_overlay_modified
, 0);
4566 /* Adjust this window's edge. */
4567 XSETINT (CURSIZE (window
),
4568 XINT (CURSIZE (window
)) + delta
);
4570 /* If this window has following siblings in the desired dimension,
4571 make them smaller, and exit the loop.
4573 (If we reach the top of the tree and can never do this,
4574 we will fail and report an error, above.) */
4575 if (NILP (first_parallel
))
4577 if (!NILP (p
->next
))
4579 /* This may happen for the minibuffer. In that case
4580 the window_deletion_count check below does not work. */
4581 if (XINT (CURSIZE (p
->next
)) - delta
<= 0)
4583 Fset_window_configuration (old_config
);
4584 error ("Cannot adjust window size as specified");
4587 XSETINT (CURBEG (p
->next
),
4588 XINT (CURBEG (p
->next
)) + delta
);
4589 size_window (p
->next
, XINT (CURSIZE (p
->next
)) - delta
,
4590 horiz_flag
, 0, 1, 0);
4595 /* Here we have a chain of parallel siblings, in the other dimension.
4596 Change the size of the other siblings. */
4597 for (child
= first_parallel
;
4599 child
= XWINDOW (child
)->next
)
4600 if (! EQ (child
, window
))
4601 size_window (child
, XINT (CURSIZE (child
)) + delta
,
4602 horiz_flag
, 0, 0, 1);
4607 /* If we made a window so small it got deleted,
4608 we failed. Report failure. */
4609 if (delcount
!= window_deletion_count
)
4611 Fset_window_configuration (old_config
);
4612 error ("Cannot adjust window size as specified");
4615 /* Adjust glyph matrices. */
4616 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4622 DEFUN ("adjust-window-trailing-edge", Fadjust_window_trailing_edge
,
4623 Sadjust_window_trailing_edge
, 3, 3, 0,
4624 doc
: /* Adjust the bottom or right edge of WINDOW by DELTA.
4625 If HORIZONTAL is non-nil, that means adjust the width, moving the right edge.
4626 Otherwise, adjust the height, moving the bottom edge.
4628 Following siblings of the selected window are resized to fulfill
4629 the size request. If they become too small in the process, they
4630 are not deleted; instead, we signal an error. */)
4631 (window
, delta
, horizontal
)
4632 Lisp_Object window
, delta
, horizontal
;
4634 CHECK_NUMBER (delta
);
4635 adjust_window_trailing_edge (window
, XINT (delta
), !NILP (horizontal
));
4637 if (! NILP (Vwindow_configuration_change_hook
))
4638 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
4645 /***********************************************************************
4646 Resizing Mini-Windows
4647 ***********************************************************************/
4649 static void shrink_window_lowest_first
P_ ((struct window
*, int));
4651 enum save_restore_action
4658 static int save_restore_orig_size
P_ ((struct window
*,
4659 enum save_restore_action
));
4661 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
4662 from lowest windows first. */
4665 shrink_window_lowest_first (w
, height
)
4673 xassert (!MINI_WINDOW_P (w
));
4675 /* Set redisplay hints. */
4676 XSETFASTINT (w
->last_modified
, 0);
4677 XSETFASTINT (w
->last_overlay_modified
, 0);
4678 windows_or_buffers_changed
++;
4679 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
4681 old_height
= XFASTINT (w
->total_lines
);
4682 XSETFASTINT (w
->total_lines
, height
);
4684 if (!NILP (w
->hchild
))
4686 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
4688 c
= XWINDOW (child
);
4689 c
->top_line
= w
->top_line
;
4690 shrink_window_lowest_first (c
, height
);
4693 else if (!NILP (w
->vchild
))
4695 Lisp_Object last_child
;
4696 int delta
= old_height
- height
;
4701 /* Find the last child. We are taking space from lowest windows
4702 first, so we iterate over children from the last child
4704 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
4707 /* Assign new heights. We leave only MIN_SAFE_WINDOW_HEIGHT. */
4708 for (child
= last_child
; delta
&& !NILP (child
); child
= c
->prev
)
4712 c
= XWINDOW (child
);
4713 this_one
= XFASTINT (c
->total_lines
) - MIN_SAFE_WINDOW_HEIGHT
;
4715 if (this_one
> delta
)
4718 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
) - this_one
);
4722 /* Compute new positions. */
4723 last_top
= XINT (w
->top_line
);
4724 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
4726 c
= XWINDOW (child
);
4727 c
->top_line
= make_number (last_top
);
4728 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
));
4729 last_top
+= XFASTINT (c
->total_lines
);
4735 /* Save, restore, or check positions and sizes in the window tree
4736 rooted at W. ACTION says what to do.
4738 If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and
4739 orig_total_lines members are valid for all windows in the window
4740 tree. Value is non-zero if they are valid.
4742 If ACTION is SAVE_ORIG_SIZES, save members top and height in
4743 orig_top_line and orig_total_lines for all windows in the tree.
4745 If ACTION is RESTORE_ORIG_SIZES, restore top and height from values
4746 stored in orig_top_line and orig_total_lines for all windows. */
4749 save_restore_orig_size (w
, action
)
4751 enum save_restore_action action
;
4757 if (!NILP (w
->hchild
))
4759 if (!save_restore_orig_size (XWINDOW (w
->hchild
), action
))
4762 else if (!NILP (w
->vchild
))
4764 if (!save_restore_orig_size (XWINDOW (w
->vchild
), action
))
4770 case CHECK_ORIG_SIZES
:
4771 if (!INTEGERP (w
->orig_top_line
) || !INTEGERP (w
->orig_total_lines
))
4775 case SAVE_ORIG_SIZES
:
4776 w
->orig_top_line
= w
->top_line
;
4777 w
->orig_total_lines
= w
->total_lines
;
4778 XSETFASTINT (w
->last_modified
, 0);
4779 XSETFASTINT (w
->last_overlay_modified
, 0);
4782 case RESTORE_ORIG_SIZES
:
4783 xassert (INTEGERP (w
->orig_top_line
) && INTEGERP (w
->orig_total_lines
));
4784 w
->top_line
= w
->orig_top_line
;
4785 w
->total_lines
= w
->orig_total_lines
;
4786 w
->orig_total_lines
= w
->orig_top_line
= Qnil
;
4787 XSETFASTINT (w
->last_modified
, 0);
4788 XSETFASTINT (w
->last_overlay_modified
, 0);
4795 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
4802 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
4803 without deleting other windows. */
4806 grow_mini_window (w
, delta
)
4810 struct frame
*f
= XFRAME (w
->frame
);
4811 struct window
*root
;
4813 xassert (MINI_WINDOW_P (w
));
4814 xassert (delta
>= 0);
4816 /* Check values of window_min_width and window_min_height for
4818 check_min_window_sizes ();
4820 /* Compute how much we can enlarge the mini-window without deleting
4822 root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4825 int min_height
= window_min_size (root
, 0, 0, 0);
4826 if (XFASTINT (root
->total_lines
) - delta
< min_height
)
4827 /* Note that the root window may already be smaller than
4829 delta
= max (0, XFASTINT (root
->total_lines
) - min_height
);
4834 /* Save original window sizes and positions, if not already done. */
4835 if (!save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4836 save_restore_orig_size (root
, SAVE_ORIG_SIZES
);
4838 /* Shrink other windows. */
4839 shrink_window_lowest_first (root
, XFASTINT (root
->total_lines
) - delta
);
4841 /* Grow the mini-window. */
4842 w
->top_line
= make_number (XFASTINT (root
->top_line
) + XFASTINT (root
->total_lines
));
4843 w
->total_lines
= make_number (XFASTINT (w
->total_lines
) + delta
);
4844 XSETFASTINT (w
->last_modified
, 0);
4845 XSETFASTINT (w
->last_overlay_modified
, 0);
4852 /* Shrink mini-window W. If there is recorded info about window sizes
4853 before a call to grow_mini_window, restore recorded window sizes.
4854 Otherwise, if the mini-window is higher than 1 line, resize it to 1
4858 shrink_mini_window (w
)
4861 struct frame
*f
= XFRAME (w
->frame
);
4862 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4864 if (save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4866 save_restore_orig_size (root
, RESTORE_ORIG_SIZES
);
4868 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4869 windows_or_buffers_changed
= 1;
4871 else if (XFASTINT (w
->total_lines
) > 1)
4873 /* Distribute the additional lines of the mini-window
4874 among the other windows. */
4876 XSETWINDOW (window
, w
);
4877 enlarge_window (window
, 1 - XFASTINT (w
->total_lines
), 0);
4883 /* Mark window cursors off for all windows in the window tree rooted
4884 at W by setting their phys_cursor_on_p flag to zero. Called from
4885 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4886 the frame are cleared. */
4889 mark_window_cursors_off (w
)
4894 if (!NILP (w
->hchild
))
4895 mark_window_cursors_off (XWINDOW (w
->hchild
));
4896 else if (!NILP (w
->vchild
))
4897 mark_window_cursors_off (XWINDOW (w
->vchild
));
4899 w
->phys_cursor_on_p
= 0;
4901 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4906 /* Return number of lines of text (not counting mode lines) in W. */
4909 window_internal_height (w
)
4912 int ht
= XFASTINT (w
->total_lines
);
4914 if (!MINI_WINDOW_P (w
))
4916 if (!NILP (w
->parent
)
4917 || !NILP (w
->vchild
)
4918 || !NILP (w
->hchild
)
4921 || WINDOW_WANTS_MODELINE_P (w
))
4924 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4932 /* Return the number of columns in W.
4933 Don't count columns occupied by scroll bars or the vertical bar
4934 separating W from the sibling to its right. */
4937 window_box_text_cols (w
)
4940 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4941 int width
= XINT (w
->total_cols
);
4943 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
4944 /* Scroll bars occupy a few columns. */
4945 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
4946 else if (!FRAME_WINDOW_P (f
)
4947 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
4948 /* The column of `|' characters separating side-by-side windows
4949 occupies one column only. */
4952 if (FRAME_WINDOW_P (f
))
4953 /* On window-systems, fringes and display margins cannot be
4954 used for normal text. */
4955 width
-= (WINDOW_FRINGE_COLS (w
)
4956 + WINDOW_LEFT_MARGIN_COLS (w
)
4957 + WINDOW_RIGHT_MARGIN_COLS (w
));
4963 /************************************************************************
4965 ***********************************************************************/
4967 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4968 N screen-fulls, which is defined as the height of the window minus
4969 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4970 instead. Negative values of N mean scroll down. NOERROR non-zero
4971 means don't signal an error if we try to move over BEGV or ZV,
4975 window_scroll (window
, n
, whole
, noerror
)
4983 /* If we must, use the pixel-based version which is much slower than
4984 the line-based one but can handle varying line heights. */
4985 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4986 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4988 window_scroll_line_based (window
, n
, whole
, noerror
);
4994 /* Implementation of window_scroll that works based on pixel line
4995 heights. See the comment of window_scroll for parameter
4999 window_scroll_pixel_based (window
, n
, whole
, noerror
)
5006 struct window
*w
= XWINDOW (window
);
5007 struct text_pos start
;
5008 int this_scroll_margin
;
5009 /* True if we fiddled the window vscroll field without really scrolling. */
5011 int x
, y
, rtop
, rbot
, rowh
, vpos
;
5013 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5015 /* If PT is not visible in WINDOW, move back one half of
5016 the screen. Allow PT to be partially visible, otherwise
5017 something like (scroll-down 1) with PT in the line before
5018 the partially visible one would recenter. */
5020 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
5022 /* Move backward half the height of the window. Performance note:
5023 vmotion used here is about 10% faster, but would give wrong
5024 results for variable height lines. */
5025 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
5026 it
.current_y
= it
.last_visible_y
;
5027 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5029 /* The function move_iterator_vertically may move over more than
5030 the specified y-distance. If it->w is small, e.g. a
5031 mini-buffer window, we may end up in front of the window's
5032 display area. This is the case when Start displaying at the
5033 start of the line containing PT in this case. */
5034 if (it
.current_y
<= 0)
5036 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
5037 move_it_vertically_backward (&it
, 0);
5041 start
= it
.current
.pos
;
5043 else if (auto_window_vscroll_p
)
5045 if (rtop
|| rbot
) /* partially visible */
5048 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
5050 dy
= max ((window_box_height (w
)
5051 - next_screen_context_lines
* dy
),
5057 /* Only vscroll backwards if already vscrolled forwards. */
5058 if (w
->vscroll
< 0 && rtop
> 0)
5060 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
5061 Fset_window_vscroll (window
, make_number (px
), Qt
);
5067 /* Do vscroll if already vscrolled or only display line. */
5068 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
5070 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
5071 Fset_window_vscroll (window
, make_number (px
), Qt
);
5075 /* Maybe modify window start instead of scrolling. */
5076 if (rbot
> 0 || w
->vscroll
< 0)
5080 Fset_window_vscroll (window
, make_number (0), Qt
);
5081 /* If there are other text lines above the current row,
5082 move window start to current row. Else to next row. */
5084 spos
= XINT (Fline_beginning_position (Qnil
));
5086 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
5087 set_marker_restricted (w
->start
, make_number (spos
),
5089 w
->start_at_line_beg
= Qt
;
5090 w
->update_mode_line
= Qt
;
5091 XSETFASTINT (w
->last_modified
, 0);
5092 XSETFASTINT (w
->last_overlay_modified
, 0);
5093 /* Set force_start so that redisplay_window will run the
5094 window-scroll-functions. */
5095 w
->force_start
= Qt
;
5100 /* Cancel previous vscroll. */
5101 Fset_window_vscroll (window
, make_number (0), Qt
);
5104 /* If scroll_preserve_screen_position is non-nil, we try to set
5105 point in the same window line as it is now, so get that line. */
5106 if (!NILP (Vscroll_preserve_screen_position
))
5108 /* We preserve the goal pixel coordinate across consecutive
5109 calls to scroll-up or scroll-down. This avoids the
5110 possibility of point becoming "stuck" on a tall line when
5111 scrolling by one line. */
5112 if (window_scroll_pixel_based_preserve_y
< 0
5113 || (!EQ (current_kboard
->Vlast_command
, Qscroll_up
)
5114 && !EQ (current_kboard
->Vlast_command
, Qscroll_down
)))
5116 start_display (&it
, w
, start
);
5117 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5118 window_scroll_pixel_based_preserve_y
= it
.current_y
;
5122 window_scroll_pixel_based_preserve_y
= -1;
5124 /* Move iterator it from start the specified distance forward or
5125 backward. The result is the new window start. */
5126 start_display (&it
, w
, start
);
5129 int start_pos
= IT_CHARPOS (it
);
5130 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
5131 dy
= max ((window_box_height (w
)
5132 - next_screen_context_lines
* dy
),
5135 /* Note that move_it_vertically always moves the iterator to the
5136 start of a line. So, if the last line doesn't have a newline,
5137 we would end up at the start of the line ending at ZV. */
5140 move_it_vertically_backward (&it
, -dy
);
5141 /* Ensure we actually do move, e.g. in case we are currently
5142 looking at an image that is taller that the window height. */
5143 while (start_pos
== IT_CHARPOS (it
)
5144 && start_pos
> BEGV
)
5145 move_it_by_lines (&it
, -1, 1);
5149 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
5150 MOVE_TO_POS
| MOVE_TO_Y
);
5151 /* Ensure we actually do move, e.g. in case we are currently
5152 looking at an image that is taller that the window height. */
5153 while (start_pos
== IT_CHARPOS (it
)
5155 move_it_by_lines (&it
, 1, 1);
5159 move_it_by_lines (&it
, n
, 1);
5161 /* We failed if we find ZV is already on the screen (scrolling up,
5162 means there's nothing past the end), or if we can't start any
5163 earlier (scrolling down, means there's nothing past the top). */
5164 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
5165 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
5167 if (IT_CHARPOS (it
) == ZV
)
5169 if (it
.current_y
< it
.last_visible_y
5170 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
5171 > it
.last_visible_y
))
5173 /* The last line was only partially visible, make it fully
5175 w
->vscroll
= (it
.last_visible_y
5176 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
5177 adjust_glyphs (it
.f
);
5181 else if (n
< 0) /* could happen with empty buffers */
5182 xsignal0 (Qbeginning_of_buffer
);
5184 xsignal0 (Qend_of_buffer
);
5188 if (w
->vscroll
!= 0)
5189 /* The first line was only partially visible, make it fully
5195 xsignal0 (Qbeginning_of_buffer
);
5198 /* If control gets here, then we vscrolled. */
5200 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
5202 /* Don't try to change the window start below. */
5208 int pos
= IT_CHARPOS (it
);
5211 /* If in the middle of a multi-glyph character move forward to
5212 the next character. */
5213 if (in_display_vector_p (&it
))
5216 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
5219 /* Set the window start, and set up the window for redisplay. */
5220 set_marker_restricted (w
->start
, make_number (pos
),
5222 bytepos
= XMARKER (w
->start
)->bytepos
;
5223 w
->start_at_line_beg
= ((pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n')
5225 w
->update_mode_line
= Qt
;
5226 XSETFASTINT (w
->last_modified
, 0);
5227 XSETFASTINT (w
->last_overlay_modified
, 0);
5228 /* Set force_start so that redisplay_window will run the
5229 window-scroll-functions. */
5230 w
->force_start
= Qt
;
5233 /* The rest of this function uses current_y in a nonstandard way,
5234 not including the height of the header line if any. */
5235 it
.current_y
= it
.vpos
= 0;
5237 /* Move PT out of scroll margins.
5238 This code wants current_y to be zero at the window start position
5239 even if there is a header line. */
5240 this_scroll_margin
= max (0, scroll_margin
);
5241 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->total_lines
) / 4);
5242 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
5246 /* We moved the window start towards ZV, so PT may be now
5247 in the scroll margin at the top. */
5248 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5249 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
5250 && (NILP (Vscroll_preserve_screen_position
)
5251 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5252 /* We found PT at a legitimate height. Leave it alone. */
5254 else if (window_scroll_pixel_based_preserve_y
>= 0)
5256 /* If we have a header line, take account of it.
5257 This is necessary because we set it.current_y to 0, above. */
5258 move_it_to (&it
, -1, -1,
5259 window_scroll_pixel_based_preserve_y
5260 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
5262 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5266 while (it
.current_y
< this_scroll_margin
)
5268 int prev
= it
.current_y
;
5269 move_it_by_lines (&it
, 1, 1);
5270 if (prev
== it
.current_y
)
5273 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5278 int charpos
, bytepos
;
5281 /* Save our position, for the
5282 window_scroll_pixel_based_preserve_y case. */
5283 charpos
= IT_CHARPOS (it
);
5284 bytepos
= IT_BYTEPOS (it
);
5286 /* We moved the window start towards BEGV, so PT may be now
5287 in the scroll margin at the bottom. */
5288 move_it_to (&it
, PT
, -1,
5289 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
5290 - this_scroll_margin
- 1),
5292 MOVE_TO_POS
| MOVE_TO_Y
);
5294 /* Save our position, in case it's correct. */
5295 charpos
= IT_CHARPOS (it
);
5296 bytepos
= IT_BYTEPOS (it
);
5298 /* See if point is on a partially visible line at the end. */
5299 if (it
.what
== IT_EOB
)
5300 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
5303 move_it_by_lines (&it
, 1, 1);
5304 partial_p
= it
.current_y
> it
.last_visible_y
;
5307 if (charpos
== PT
&& !partial_p
5308 && (NILP (Vscroll_preserve_screen_position
)
5309 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5310 /* We found PT before we found the display margin, so PT is ok. */
5312 else if (window_scroll_pixel_based_preserve_y
>= 0)
5314 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5315 start_display (&it
, w
, start
);
5316 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
5317 here because we called start_display again and did not
5318 alter it.current_y this time. */
5319 move_it_to (&it
, -1, -1, window_scroll_pixel_based_preserve_y
, -1,
5321 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5326 /* The last line was only partially visible, so back up two
5327 lines to make sure we're on a fully visible line. */
5329 move_it_by_lines (&it
, -2, 0);
5330 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5333 /* No, the position we saved is OK, so use it. */
5334 SET_PT_BOTH (charpos
, bytepos
);
5340 /* Implementation of window_scroll that works based on screen lines.
5341 See the comment of window_scroll for parameter descriptions. */
5344 window_scroll_line_based (window
, n
, whole
, noerror
)
5350 register struct window
*w
= XWINDOW (window
);
5351 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
5352 register int pos
, pos_byte
;
5353 register int ht
= window_internal_height (w
);
5354 register Lisp_Object tem
;
5358 struct position posit
;
5361 /* If scrolling screen-fulls, compute the number of lines to
5362 scroll from the window's height. */
5364 n
*= max (1, ht
- next_screen_context_lines
);
5366 startpos
= marker_position (w
->start
);
5368 posit
= *compute_motion (startpos
, 0, 0, 0,
5370 -1, XINT (w
->hscroll
),
5372 original_vpos
= posit
.vpos
;
5374 XSETFASTINT (tem
, PT
);
5375 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
5379 Fvertical_motion (make_number (- (ht
/ 2)), window
);
5384 lose
= n
< 0 && PT
== BEGV
;
5385 Fvertical_motion (make_number (n
), window
);
5389 SET_PT_BOTH (opoint
, opoint_byte
);
5396 xsignal0 (Qbeginning_of_buffer
);
5401 int this_scroll_margin
= scroll_margin
;
5403 /* Don't use a scroll margin that is negative or too large. */
5404 if (this_scroll_margin
< 0)
5405 this_scroll_margin
= 0;
5407 if (XINT (w
->total_lines
) < 4 * scroll_margin
)
5408 this_scroll_margin
= XINT (w
->total_lines
) / 4;
5410 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
5411 w
->start_at_line_beg
= bolp
;
5412 w
->update_mode_line
= Qt
;
5413 XSETFASTINT (w
->last_modified
, 0);
5414 XSETFASTINT (w
->last_overlay_modified
, 0);
5415 /* Set force_start so that redisplay_window will run
5416 the window-scroll-functions. */
5417 w
->force_start
= Qt
;
5419 if (!NILP (Vscroll_preserve_screen_position
)
5420 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
5422 SET_PT_BOTH (pos
, pos_byte
);
5423 Fvertical_motion (make_number (original_vpos
), window
);
5425 /* If we scrolled forward, put point enough lines down
5426 that it is outside the scroll margin. */
5431 if (this_scroll_margin
> 0)
5433 SET_PT_BOTH (pos
, pos_byte
);
5434 Fvertical_motion (make_number (this_scroll_margin
), window
);
5440 if (top_margin
<= opoint
)
5441 SET_PT_BOTH (opoint
, opoint_byte
);
5442 else if (!NILP (Vscroll_preserve_screen_position
))
5444 SET_PT_BOTH (pos
, pos_byte
);
5445 Fvertical_motion (make_number (original_vpos
), window
);
5448 SET_PT (top_margin
);
5454 /* If we scrolled backward, put point near the end of the window
5455 but not within the scroll margin. */
5456 SET_PT_BOTH (pos
, pos_byte
);
5457 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
5458 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
5461 bottom_margin
= PT
+ 1;
5463 if (bottom_margin
> opoint
)
5464 SET_PT_BOTH (opoint
, opoint_byte
);
5467 if (!NILP (Vscroll_preserve_screen_position
))
5469 SET_PT_BOTH (pos
, pos_byte
);
5470 Fvertical_motion (make_number (original_vpos
), window
);
5473 Fvertical_motion (make_number (-1), window
);
5482 xsignal0 (Qend_of_buffer
);
5487 /* Scroll selected_window up or down. If N is nil, scroll a
5488 screen-full which is defined as the height of the window minus
5489 next_screen_context_lines. If N is the symbol `-', scroll.
5490 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
5491 up. This is the guts of Fscroll_up and Fscroll_down. */
5494 scroll_command (n
, direction
)
5498 int count
= SPECPDL_INDEX ();
5500 xassert (abs (direction
) == 1);
5502 /* If selected window's buffer isn't current, make it current for
5503 the moment. But don't screw up if window_scroll gets an error. */
5504 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
5506 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5507 Fset_buffer (XWINDOW (selected_window
)->buffer
);
5509 /* Make redisplay consider other windows than just selected_window. */
5510 ++windows_or_buffers_changed
;
5514 window_scroll (selected_window
, direction
, 1, 0);
5515 else if (EQ (n
, Qminus
))
5516 window_scroll (selected_window
, -direction
, 1, 0);
5519 n
= Fprefix_numeric_value (n
);
5520 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
5523 unbind_to (count
, Qnil
);
5526 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
5527 doc
: /* Scroll text of current window upward ARG lines.
5528 If ARG is omitted or nil, scroll upward by a near full screen.
5529 A near full screen is `next-screen-context-lines' less than a full screen.
5530 Negative ARG means scroll downward.
5531 If ARG is the atom `-', scroll downward by nearly full screen.
5532 When calling from a program, supply as argument a number, nil, or `-'. */)
5536 scroll_command (arg
, 1);
5540 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
5541 doc
: /* Scroll text of current window down ARG lines.
5542 If ARG is omitted or nil, scroll down by a near full screen.
5543 A near full screen is `next-screen-context-lines' less than a full screen.
5544 Negative ARG means scroll upward.
5545 If ARG is the atom `-', scroll upward by nearly full screen.
5546 When calling from a program, supply as argument a number, nil, or `-'. */)
5550 scroll_command (arg
, -1);
5554 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
5555 doc
: /* Return the other window for \"other window scroll\" commands.
5556 If `other-window-scroll-buffer' is non-nil, a window
5557 showing that buffer is used.
5558 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5559 specifies the window. This takes precedence over
5560 `other-window-scroll-buffer'. */)
5565 if (MINI_WINDOW_P (XWINDOW (selected_window
))
5566 && !NILP (Vminibuf_scroll_window
))
5567 window
= Vminibuf_scroll_window
;
5568 /* If buffer is specified, scroll that buffer. */
5569 else if (!NILP (Vother_window_scroll_buffer
))
5571 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
5573 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
5577 /* Nothing specified; look for a neighboring window on the same
5579 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
5581 if (EQ (window
, selected_window
))
5582 /* That didn't get us anywhere; look for a window on another
5585 window
= Fnext_window (window
, Qnil
, Qt
);
5586 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
5587 && ! EQ (window
, selected_window
));
5590 CHECK_LIVE_WINDOW (window
);
5592 if (EQ (window
, selected_window
))
5593 error ("There is no other window");
5598 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
5599 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5600 A near full screen is `next-screen-context-lines' less than a full screen.
5601 The next window is the one below the current one; or the one at the top
5602 if the current one is at the bottom. Negative ARG means scroll downward.
5603 If ARG is the atom `-', scroll downward by nearly full screen.
5604 When calling from a program, supply as argument a number, nil, or `-'.
5606 If `other-window-scroll-buffer' is non-nil, scroll the window
5607 showing that buffer, popping the buffer up if necessary.
5608 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5609 specifies the window to scroll. This takes precedence over
5610 `other-window-scroll-buffer'. */)
5616 int count
= SPECPDL_INDEX ();
5618 window
= Fother_window_for_scrolling ();
5619 w
= XWINDOW (window
);
5621 /* Don't screw up if window_scroll gets an error. */
5622 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5623 ++windows_or_buffers_changed
;
5625 Fset_buffer (w
->buffer
);
5626 SET_PT (marker_position (w
->pointm
));
5629 window_scroll (window
, 1, 1, 1);
5630 else if (EQ (arg
, Qminus
))
5631 window_scroll (window
, -1, 1, 1);
5637 window_scroll (window
, XINT (arg
), 0, 1);
5640 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5641 unbind_to (count
, Qnil
);
5646 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "P\np",
5647 doc
: /* Scroll selected window display ARG columns left.
5648 Default for ARG is window width minus 2.
5649 Value is the total amount of leftward horizontal scrolling in
5650 effect after the change.
5651 If SET_MINIMUM is non-nil, the new scroll amount becomes the
5652 lower bound for automatic scrolling, i.e. automatic scrolling
5653 will not scroll a window to a column less than the value returned
5654 by this function. This happens in an interactive call. */)
5656 register Lisp_Object arg
, set_minimum
;
5660 struct window
*w
= XWINDOW (selected_window
);
5663 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5665 arg
= Fprefix_numeric_value (arg
);
5667 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
5668 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5670 if (!NILP (set_minimum
))
5671 w
->min_hscroll
= w
->hscroll
;
5676 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "P\np",
5677 doc
: /* Scroll selected window display ARG columns right.
5678 Default for ARG is window width minus 2.
5679 Value is the total amount of leftward horizontal scrolling in
5680 effect after the change.
5681 If SET_MINIMUM is non-nil, the new scroll amount becomes the
5682 lower bound for automatic scrolling, i.e. automatic scrolling
5683 will not scroll a window to a column less than the value returned
5684 by this function. This happens in an interactive call. */)
5686 register Lisp_Object arg
, set_minimum
;
5690 struct window
*w
= XWINDOW (selected_window
);
5693 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5695 arg
= Fprefix_numeric_value (arg
);
5697 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
5698 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5700 if (!NILP (set_minimum
))
5701 w
->min_hscroll
= w
->hscroll
;
5706 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5707 doc
: /* Return the window which was selected when entering the minibuffer.
5708 Returns nil, if current window is not a minibuffer window. */)
5711 if (minibuf_level
> 0
5712 && MINI_WINDOW_P (XWINDOW (selected_window
))
5713 && WINDOW_LIVE_P (minibuf_selected_window
))
5714 return minibuf_selected_window
;
5719 /* Value is the number of lines actually displayed in window W,
5720 as opposed to its height. */
5723 displayed_window_lines (w
)
5727 struct text_pos start
;
5728 int height
= window_box_height (w
);
5729 struct buffer
*old_buffer
;
5732 if (XBUFFER (w
->buffer
) != current_buffer
)
5734 old_buffer
= current_buffer
;
5735 set_buffer_internal (XBUFFER (w
->buffer
));
5740 /* In case W->start is out of the accessible range, do something
5741 reasonable. This happens in Info mode when Info-scroll-down
5742 calls (recenter -1) while W->start is 1. */
5743 if (XMARKER (w
->start
)->charpos
< BEGV
)
5744 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5745 else if (XMARKER (w
->start
)->charpos
> ZV
)
5746 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
5748 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5750 start_display (&it
, w
, start
);
5751 move_it_vertically (&it
, height
);
5752 bottom_y
= line_bottom_y (&it
);
5754 /* rms: On a non-window display,
5755 the value of it.vpos at the bottom of the screen
5756 seems to be 1 larger than window_box_height (w).
5757 This kludge fixes a bug whereby (move-to-window-line -1)
5758 when ZV is on the last screen line
5759 moves to the previous screen line instead of the last one. */
5760 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5763 /* Add in empty lines at the bottom of the window. */
5764 if (bottom_y
< height
)
5766 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5767 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5771 set_buffer_internal (old_buffer
);
5777 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5778 doc
: /* Center point in window and redisplay frame.
5779 With prefix argument ARG, recenter putting point on screen line ARG
5780 relative to the current window. If ARG is negative, it counts up from the
5781 bottom of the window. (ARG should be less than the height of the window.)
5783 If ARG is omitted or nil, erase the entire frame and then redraw with point
5784 in the center of the current window. If `auto-resize-tool-bars' is set to
5785 `grow-only', this resets the tool-bar's height to the minimum height needed.
5787 Just C-u as prefix means put point in the center of the window
5788 and redisplay normally--don't erase and redraw the frame. */)
5790 register Lisp_Object arg
;
5792 struct window
*w
= XWINDOW (selected_window
);
5793 struct buffer
*buf
= XBUFFER (w
->buffer
);
5794 struct buffer
*obuf
= current_buffer
;
5796 int charpos
, bytepos
;
5798 int this_scroll_margin
;
5800 /* If redisplay is suppressed due to an error, try again. */
5801 obuf
->display_error_modiff
= 0;
5807 /* Invalidate pixel data calculated for all compositions. */
5808 for (i
= 0; i
< n_compositions
; i
++)
5809 composition_table
[i
]->font
= NULL
;
5811 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5813 Fredraw_frame (WINDOW_FRAME (w
));
5814 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5817 else if (CONSP (arg
)) /* Just C-u. */
5821 arg
= Fprefix_numeric_value (arg
);
5826 set_buffer_internal (buf
);
5828 /* Do this after making BUF current
5829 in case scroll_margin is buffer-local. */
5830 this_scroll_margin
= max (0, scroll_margin
);
5831 this_scroll_margin
= min (this_scroll_margin
,
5832 XFASTINT (w
->total_lines
) / 4);
5834 /* Handle centering on a graphical frame specially. Such frames can
5835 have variable-height lines and centering point on the basis of
5836 line counts would lead to strange effects. */
5837 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5844 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5845 start_display (&it
, w
, pt
);
5846 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5847 charpos
= IT_CHARPOS (it
);
5848 bytepos
= IT_BYTEPOS (it
);
5855 int extra_line_spacing
;
5856 int h
= window_box_height (w
);
5858 iarg
= - max (-iarg
, this_scroll_margin
);
5860 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5861 start_display (&it
, w
, pt
);
5863 /* Be sure we have the exact height of the full line containing PT. */
5864 move_it_by_lines (&it
, 0, 1);
5866 /* The amount of pixels we have to move back is the window
5867 height minus what's displayed in the line containing PT,
5868 and the lines below. */
5871 move_it_by_lines (&it
, nlines
, 1);
5873 if (it
.vpos
== nlines
)
5877 /* Last line has no newline */
5878 h
-= line_bottom_y (&it
);
5882 /* Don't reserve space for extra line spacing of last line. */
5883 extra_line_spacing
= it
.max_extra_line_spacing
;
5885 /* If we can't move down NLINES lines because we hit
5886 the end of the buffer, count in some empty lines. */
5887 if (it
.vpos
< nlines
)
5890 extra_line_spacing
= it
.extra_line_spacing
;
5891 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5896 /* Now find the new top line (starting position) of the window. */
5897 start_display (&it
, w
, pt
);
5899 move_it_vertically_backward (&it
, h
);
5901 /* If extra line spacing is present, we may move too far
5902 back. This causes the last line to be only partially
5903 visible (which triggers redisplay to recenter that line
5904 in the middle), so move forward.
5905 But ignore extra line spacing on last line, as it is not
5906 considered to be part of the visible height of the line.
5908 h
+= extra_line_spacing
;
5909 while (-it
.current_y
> h
)
5910 move_it_by_lines (&it
, 1, 1);
5912 charpos
= IT_CHARPOS (it
);
5913 bytepos
= IT_BYTEPOS (it
);
5917 struct position pos
;
5919 iarg
= max (iarg
, this_scroll_margin
);
5921 pos
= *vmotion (PT
, -iarg
, w
);
5922 charpos
= pos
.bufpos
;
5923 bytepos
= pos
.bytepos
;
5928 struct position pos
;
5929 int ht
= window_internal_height (w
);
5936 /* Don't let it get into the margin at either top or bottom. */
5937 iarg
= max (iarg
, this_scroll_margin
);
5938 iarg
= min (iarg
, ht
- this_scroll_margin
- 1);
5940 pos
= *vmotion (PT
, - iarg
, w
);
5941 charpos
= pos
.bufpos
;
5942 bytepos
= pos
.bytepos
;
5945 /* Set the new window start. */
5946 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
5947 w
->window_end_valid
= Qnil
;
5949 w
->optional_new_start
= Qt
;
5951 if (bytepos
== BEGV_BYTE
|| FETCH_BYTE (bytepos
- 1) == '\n')
5952 w
->start_at_line_beg
= Qt
;
5954 w
->start_at_line_beg
= Qnil
;
5956 set_buffer_internal (obuf
);
5961 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5963 doc
: /* Return the height in lines of the text display area of WINDOW.
5964 WINDOW defaults to the selected window.
5965 This doesn't include the mode-line (or header-line if any) or any
5966 partial-height lines in the text display area. */)
5970 struct window
*w
= decode_window (window
);
5971 int pixel_height
= window_box_height (w
);
5972 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5973 return make_number (line_height
);
5978 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5980 doc
: /* Position point relative to window.
5981 With no argument, position point at center of window.
5982 An argument specifies vertical position within the window;
5983 zero means top of window, negative means relative to bottom of window. */)
5987 struct window
*w
= XWINDOW (selected_window
);
5991 int this_scroll_margin
;
5994 window
= selected_window
;
5995 start
= marker_position (w
->start
);
5996 if (start
< BEGV
|| start
> ZV
)
5998 int height
= window_internal_height (w
);
5999 Fvertical_motion (make_number (- (height
/ 2)), window
);
6000 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
6001 w
->start_at_line_beg
= Fbolp ();
6002 w
->force_start
= Qt
;
6005 Fgoto_char (w
->start
);
6007 lines
= displayed_window_lines (w
);
6010 this_scroll_margin
= max (0, scroll_margin
);
6011 this_scroll_margin
= min (this_scroll_margin
, lines
/ 4);
6015 XSETFASTINT (arg
, lines
/ 2);
6018 int iarg
= XINT (Fprefix_numeric_value (arg
));
6021 iarg
= iarg
+ lines
;
6023 #if 0 /* This code would prevent move-to-window-line from moving point
6024 to a place inside the scroll margins (which would cause the
6025 next redisplay to scroll). I wrote this code, but then concluded
6026 it is probably better not to install it. However, it is here
6027 inside #if 0 so as not to lose it. -- rms. */
6029 /* Don't let it get into the margin at either top or bottom. */
6030 iarg
= max (iarg
, this_scroll_margin
);
6031 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
6034 arg
= make_number (iarg
);
6037 /* Skip past a partially visible first line. */
6039 XSETINT (arg
, XINT (arg
) + 1);
6041 return Fvertical_motion (arg
, window
);
6046 /***********************************************************************
6047 Window Configuration
6048 ***********************************************************************/
6050 struct save_window_data
6053 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
6054 Lisp_Object frame_cols
, frame_lines
, frame_menu_bar_lines
;
6055 Lisp_Object frame_tool_bar_lines
;
6056 Lisp_Object selected_frame
;
6057 Lisp_Object current_window
;
6058 Lisp_Object current_buffer
;
6059 Lisp_Object minibuf_scroll_window
;
6060 Lisp_Object minibuf_selected_window
;
6061 Lisp_Object root_window
;
6062 Lisp_Object focus_frame
;
6063 /* Record the values of window-min-width and window-min-height
6064 so that window sizes remain consistent with them. */
6065 Lisp_Object min_width
, min_height
;
6066 /* A vector, each of whose elements is a struct saved_window
6068 Lisp_Object saved_windows
;
6071 /* This is saved as a Lisp_Vector */
6074 /* these first two must agree with struct Lisp_Vector in lisp.h */
6076 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
6079 Lisp_Object buffer
, start
, pointm
, mark
;
6080 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
6081 Lisp_Object hscroll
, min_hscroll
;
6082 Lisp_Object parent
, prev
;
6083 Lisp_Object start_at_line_beg
;
6084 Lisp_Object display_table
;
6085 Lisp_Object orig_top_line
, orig_total_lines
;
6086 Lisp_Object left_margin_cols
, right_margin_cols
;
6087 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
6088 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
;
6089 Lisp_Object dedicated
;
6092 #define SAVED_WINDOW_N(swv,n) \
6093 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
6095 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
6096 doc
: /* Return t if OBJECT is a window-configuration object. */)
6100 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
6103 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
6104 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
6108 register struct save_window_data
*data
;
6109 struct Lisp_Vector
*saved_windows
;
6111 CHECK_WINDOW_CONFIGURATION (config
);
6113 data
= (struct save_window_data
*) XVECTOR (config
);
6114 saved_windows
= XVECTOR (data
->saved_windows
);
6115 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6118 DEFUN ("set-window-configuration", Fset_window_configuration
,
6119 Sset_window_configuration
, 1, 1, 0,
6120 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
6121 CONFIGURATION must be a value previously returned
6122 by `current-window-configuration' (which see).
6123 If CONFIGURATION was made from a frame that is now deleted,
6124 only frame-independent values can be restored. In this case,
6125 the return value is nil. Otherwise the value is t. */)
6127 Lisp_Object configuration
;
6129 register struct save_window_data
*data
;
6130 struct Lisp_Vector
*saved_windows
;
6131 Lisp_Object new_current_buffer
;
6136 CHECK_WINDOW_CONFIGURATION (configuration
);
6138 data
= (struct save_window_data
*) XVECTOR (configuration
);
6139 saved_windows
= XVECTOR (data
->saved_windows
);
6141 new_current_buffer
= data
->current_buffer
;
6142 if (NILP (XBUFFER (new_current_buffer
)->name
))
6143 new_current_buffer
= Qnil
;
6146 if (XBUFFER (new_current_buffer
) == current_buffer
)
6147 /* The code further down "preserves point" by saving here PT in
6148 old_point and then setting it later back into PT. When the
6149 current-selected-window and the final-selected-window both show
6150 the current buffer, this suffers from the problem that the
6151 current PT is the window-point of the current-selected-window,
6152 while the final PT is the point of the final-selected-window, so
6153 this copy from one PT to the other would end up moving the
6154 window-point of the final-selected-window to the window-point of
6155 the current-selected-window. So we have to be careful which
6156 point of the current-buffer we copy into old_point. */
6157 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
6158 && WINDOWP (selected_window
)
6159 && EQ (XWINDOW (selected_window
)->buffer
, new_current_buffer
)
6160 && !EQ (selected_window
, data
->current_window
))
6161 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
6165 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
6166 point in new_current_buffer as of the last time this buffer was
6167 used. This can be non-deterministic since it can be changed by
6168 things like jit-lock by mere temporary selection of some random
6169 window that happens to show this buffer.
6170 So if possible we want this arbitrary choice of "which point" to
6171 be the one from the to-be-selected-window so as to prevent this
6172 window's cursor from being copied from another window. */
6173 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
6174 /* If current_window = selected_window, its point is in BUF_PT. */
6175 && !EQ (selected_window
, data
->current_window
))
6176 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
6178 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
6181 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6184 /* If f is a dead frame, don't bother rebuilding its window tree.
6185 However, there is other stuff we should still try to do below. */
6186 if (FRAME_LIVE_P (f
))
6188 register struct window
*w
;
6189 register struct saved_window
*p
;
6190 struct window
*root_window
;
6191 struct window
**leaf_windows
;
6195 /* If the frame has been resized since this window configuration was
6196 made, we change the frame to the size specified in the
6197 configuration, restore the configuration, and then resize it
6198 back. We keep track of the prevailing height in these variables. */
6199 int previous_frame_lines
= FRAME_LINES (f
);
6200 int previous_frame_cols
= FRAME_COLS (f
);
6201 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6202 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6204 /* The mouse highlighting code could get screwed up
6205 if it runs during this. */
6208 if (XFASTINT (data
->frame_lines
) != previous_frame_lines
6209 || XFASTINT (data
->frame_cols
) != previous_frame_cols
)
6210 change_frame_size (f
, XFASTINT (data
->frame_lines
),
6211 XFASTINT (data
->frame_cols
), 0, 0, 0);
6212 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
6213 if (XFASTINT (data
->frame_menu_bar_lines
)
6214 != previous_frame_menu_bar_lines
)
6215 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, make_number (0));
6216 #ifdef HAVE_WINDOW_SYSTEM
6217 if (XFASTINT (data
->frame_tool_bar_lines
)
6218 != previous_frame_tool_bar_lines
)
6219 x_set_tool_bar_lines (f
, data
->frame_tool_bar_lines
, make_number (0));
6223 /* "Swap out" point from the selected window's buffer
6224 into the window itself. (Normally the pointm of the selected
6225 window holds garbage.) We do this now, before
6226 restoring the window contents, and prevent it from
6227 being done later on when we select a new window. */
6228 if (! NILP (XWINDOW (selected_window
)->buffer
))
6230 w
= XWINDOW (selected_window
);
6231 set_marker_both (w
->pointm
,
6233 BUF_PT (XBUFFER (w
->buffer
)),
6234 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6237 windows_or_buffers_changed
++;
6238 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
6240 /* Problem: Freeing all matrices and later allocating them again
6241 is a serious redisplay flickering problem. What we would
6242 really like to do is to free only those matrices not reused
6244 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6246 = (struct window
**) alloca (count_windows (root_window
)
6247 * sizeof (struct window
*));
6248 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
6250 /* Temporarily avoid any problems with windows that are smaller
6251 than they are supposed to be. */
6252 window_min_height
= 1;
6253 window_min_width
= 1;
6256 Mark all windows now on frame as "deleted".
6257 Restoring the new configuration "undeletes" any that are in it.
6259 Save their current buffers in their height fields, since we may
6260 need it later, if a buffer saved in the configuration is now
6262 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6264 for (k
= 0; k
< saved_windows
->size
; k
++)
6266 p
= SAVED_WINDOW_N (saved_windows
, k
);
6267 w
= XWINDOW (p
->window
);
6270 if (!NILP (p
->parent
))
6271 w
->parent
= SAVED_WINDOW_N (saved_windows
,
6272 XFASTINT (p
->parent
))->window
;
6276 if (!NILP (p
->prev
))
6278 w
->prev
= SAVED_WINDOW_N (saved_windows
,
6279 XFASTINT (p
->prev
))->window
;
6280 XWINDOW (w
->prev
)->next
= p
->window
;
6285 if (!NILP (w
->parent
))
6287 if (EQ (p
->total_cols
, XWINDOW (w
->parent
)->total_cols
))
6289 XWINDOW (w
->parent
)->vchild
= p
->window
;
6290 XWINDOW (w
->parent
)->hchild
= Qnil
;
6294 XWINDOW (w
->parent
)->hchild
= p
->window
;
6295 XWINDOW (w
->parent
)->vchild
= Qnil
;
6300 /* If we squirreled away the buffer in the window's height,
6302 if (BUFFERP (w
->total_lines
))
6303 w
->buffer
= w
->total_lines
;
6304 w
->left_col
= p
->left_col
;
6305 w
->top_line
= p
->top_line
;
6306 w
->total_cols
= p
->total_cols
;
6307 w
->total_lines
= p
->total_lines
;
6308 w
->hscroll
= p
->hscroll
;
6309 w
->min_hscroll
= p
->min_hscroll
;
6310 w
->display_table
= p
->display_table
;
6311 w
->orig_top_line
= p
->orig_top_line
;
6312 w
->orig_total_lines
= p
->orig_total_lines
;
6313 w
->left_margin_cols
= p
->left_margin_cols
;
6314 w
->right_margin_cols
= p
->right_margin_cols
;
6315 w
->left_fringe_width
= p
->left_fringe_width
;
6316 w
->right_fringe_width
= p
->right_fringe_width
;
6317 w
->fringes_outside_margins
= p
->fringes_outside_margins
;
6318 w
->scroll_bar_width
= p
->scroll_bar_width
;
6319 w
->vertical_scroll_bar_type
= p
->vertical_scroll_bar_type
;
6320 w
->dedicated
= p
->dedicated
;
6321 XSETFASTINT (w
->last_modified
, 0);
6322 XSETFASTINT (w
->last_overlay_modified
, 0);
6324 /* Reinstall the saved buffer and pointers into it. */
6325 if (NILP (p
->buffer
))
6326 w
->buffer
= p
->buffer
;
6329 if (!NILP (XBUFFER (p
->buffer
)->name
))
6330 /* If saved buffer is alive, install it. */
6332 w
->buffer
= p
->buffer
;
6333 w
->start_at_line_beg
= p
->start_at_line_beg
;
6334 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
6335 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
6336 Fset_marker (XBUFFER (w
->buffer
)->mark
,
6337 p
->mark
, w
->buffer
);
6339 /* As documented in Fcurrent_window_configuration, don't
6340 restore the location of point in the buffer which was
6341 current when the window configuration was recorded. */
6342 if (!EQ (p
->buffer
, new_current_buffer
)
6343 && XBUFFER (p
->buffer
) == current_buffer
)
6344 Fgoto_char (w
->pointm
);
6346 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
6347 /* Else unless window has a live buffer, get one. */
6349 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
6350 /* This will set the markers to beginning of visible
6352 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
6353 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
6354 w
->start_at_line_beg
= Qt
;
6357 /* Keeping window's old buffer; make sure the markers
6360 /* Set window markers at start of visible range. */
6361 if (XMARKER (w
->start
)->buffer
== 0)
6362 set_marker_restricted (w
->start
, make_number (0),
6364 if (XMARKER (w
->pointm
)->buffer
== 0)
6365 set_marker_restricted_both (w
->pointm
, w
->buffer
,
6366 BUF_PT (XBUFFER (w
->buffer
)),
6367 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6368 w
->start_at_line_beg
= Qt
;
6373 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
6374 /* Prevent "swapping out point" in the old selected window
6375 using the buffer that has been restored into it.
6376 We already swapped out point that from that window's old buffer. */
6377 selected_window
= Qnil
;
6379 /* Arrange *not* to restore point in the buffer that was
6380 current when the window configuration was saved. */
6381 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
6382 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
6383 make_number (old_point
),
6384 XWINDOW (data
->current_window
)->buffer
);
6386 Fselect_window (data
->current_window
, Qnil
);
6387 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
6390 if (NILP (data
->focus_frame
)
6391 || (FRAMEP (data
->focus_frame
)
6392 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
6393 Fredirect_frame_focus (frame
, data
->focus_frame
);
6395 #if 0 /* I don't understand why this is needed, and it causes problems
6396 when the frame's old selected window has been deleted. */
6397 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
6398 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
6402 /* Set the screen height to the value it had before this function. */
6403 if (previous_frame_lines
!= FRAME_LINES (f
)
6404 || previous_frame_cols
!= FRAME_COLS (f
))
6405 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
6407 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
6408 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
6409 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
6411 #ifdef HAVE_WINDOW_SYSTEM
6412 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
6413 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
6418 /* Now, free glyph matrices in windows that were not reused. */
6419 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
6421 if (NILP (leaf_windows
[i
]->buffer
))
6423 /* Assert it's not reused as a combination. */
6424 xassert (NILP (leaf_windows
[i
]->hchild
)
6425 && NILP (leaf_windows
[i
]->vchild
));
6426 free_window_matrices (leaf_windows
[i
]);
6428 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
6436 /* Fselect_window will have made f the selected frame, so we
6437 reselect the proper frame here. Fhandle_switch_frame will change the
6438 selected window too, but that doesn't make the call to
6439 Fselect_window above totally superfluous; it still sets f's
6441 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
6442 do_switch_frame (data
->selected_frame
, 0, 0);
6444 if (! NILP (Vwindow_configuration_change_hook
)
6445 && ! NILP (Vrun_hooks
))
6446 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
6449 if (!NILP (new_current_buffer
))
6450 Fset_buffer (new_current_buffer
);
6452 /* Restore the minimum heights recorded in the configuration. */
6453 window_min_height
= XINT (data
->min_height
);
6454 window_min_width
= XINT (data
->min_width
);
6456 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
6457 minibuf_selected_window
= data
->minibuf_selected_window
;
6459 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
6462 /* Mark all windows now on frame as deleted
6463 by setting their buffers to nil. */
6466 delete_all_subwindows (w
)
6467 register struct window
*w
;
6469 if (!NILP (w
->next
))
6470 delete_all_subwindows (XWINDOW (w
->next
));
6471 if (!NILP (w
->vchild
))
6472 delete_all_subwindows (XWINDOW (w
->vchild
));
6473 if (!NILP (w
->hchild
))
6474 delete_all_subwindows (XWINDOW (w
->hchild
));
6476 w
->total_lines
= w
->buffer
; /* See Fset_window_configuration for excuse. */
6478 if (!NILP (w
->buffer
))
6481 /* We set all three of these fields to nil, to make sure that we can
6482 distinguish this dead window from any live window. Live leaf
6483 windows will have buffer set, and combination windows will have
6484 vchild or hchild set. */
6489 Vwindow_list
= Qnil
;
6493 count_windows (window
)
6494 register struct window
*window
;
6496 register int count
= 1;
6497 if (!NILP (window
->next
))
6498 count
+= count_windows (XWINDOW (window
->next
));
6499 if (!NILP (window
->vchild
))
6500 count
+= count_windows (XWINDOW (window
->vchild
));
6501 if (!NILP (window
->hchild
))
6502 count
+= count_windows (XWINDOW (window
->hchild
));
6507 /* Fill vector FLAT with leaf windows under W, starting at index I.
6508 Value is last index + 1. */
6511 get_leaf_windows (w
, flat
, i
)
6513 struct window
**flat
;
6518 if (!NILP (w
->hchild
))
6519 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
6520 else if (!NILP (w
->vchild
))
6521 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
6525 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6532 /* Return a pointer to the glyph W's physical cursor is on. Value is
6533 null if W's current matrix is invalid, so that no meaningfull glyph
6537 get_phys_cursor_glyph (w
)
6540 struct glyph_row
*row
;
6541 struct glyph
*glyph
;
6543 if (w
->phys_cursor
.vpos
>= 0
6544 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
6545 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
6547 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
6548 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
6557 save_window_save (window
, vector
, i
)
6559 struct Lisp_Vector
*vector
;
6562 register struct saved_window
*p
;
6563 register struct window
*w
;
6564 register Lisp_Object tem
;
6566 for (;!NILP (window
); window
= w
->next
)
6568 p
= SAVED_WINDOW_N (vector
, i
);
6569 w
= XWINDOW (window
);
6571 XSETFASTINT (w
->temslot
, i
); i
++;
6573 p
->buffer
= w
->buffer
;
6574 p
->left_col
= w
->left_col
;
6575 p
->top_line
= w
->top_line
;
6576 p
->total_cols
= w
->total_cols
;
6577 p
->total_lines
= w
->total_lines
;
6578 p
->hscroll
= w
->hscroll
;
6579 p
->min_hscroll
= w
->min_hscroll
;
6580 p
->display_table
= w
->display_table
;
6581 p
->orig_top_line
= w
->orig_top_line
;
6582 p
->orig_total_lines
= w
->orig_total_lines
;
6583 p
->left_margin_cols
= w
->left_margin_cols
;
6584 p
->right_margin_cols
= w
->right_margin_cols
;
6585 p
->left_fringe_width
= w
->left_fringe_width
;
6586 p
->right_fringe_width
= w
->right_fringe_width
;
6587 p
->fringes_outside_margins
= w
->fringes_outside_margins
;
6588 p
->scroll_bar_width
= w
->scroll_bar_width
;
6589 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
6590 p
->dedicated
= w
->dedicated
;
6591 if (!NILP (w
->buffer
))
6593 /* Save w's value of point in the window configuration.
6594 If w is the selected window, then get the value of point
6595 from the buffer; pointm is garbage in the selected window. */
6596 if (EQ (window
, selected_window
))
6598 p
->pointm
= Fmake_marker ();
6599 set_marker_both (p
->pointm
, w
->buffer
,
6600 BUF_PT (XBUFFER (w
->buffer
)),
6601 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6604 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
6606 p
->start
= Fcopy_marker (w
->start
, Qnil
);
6607 p
->start_at_line_beg
= w
->start_at_line_beg
;
6609 tem
= XBUFFER (w
->buffer
)->mark
;
6610 p
->mark
= Fcopy_marker (tem
, Qnil
);
6617 p
->start_at_line_beg
= Qnil
;
6620 if (NILP (w
->parent
))
6623 p
->parent
= XWINDOW (w
->parent
)->temslot
;
6628 p
->prev
= XWINDOW (w
->prev
)->temslot
;
6630 if (!NILP (w
->vchild
))
6631 i
= save_window_save (w
->vchild
, vector
, i
);
6632 if (!NILP (w
->hchild
))
6633 i
= save_window_save (w
->hchild
, vector
, i
);
6639 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
6640 Scurrent_window_configuration
, 0, 1, 0,
6641 doc
: /* Return an object representing the current window configuration of FRAME.
6642 If FRAME is nil or omitted, use the selected frame.
6643 This describes the number of windows, their sizes and current buffers,
6644 and for each displayed buffer, where display starts, and the positions of
6645 point and mark. An exception is made for point in the current buffer:
6646 its value is -not- saved.
6647 This also records the currently selected frame, and FRAME's focus
6648 redirection (see `redirect-frame-focus'). */)
6652 register Lisp_Object tem
;
6653 register int n_windows
;
6654 register struct save_window_data
*data
;
6655 register struct Lisp_Vector
*vec
;
6660 frame
= selected_frame
;
6661 CHECK_LIVE_FRAME (frame
);
6664 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6665 vec
= allocate_other_vector (VECSIZE (struct save_window_data
));
6666 XSETPVECTYPE (vec
, PVEC_WINDOW_CONFIGURATION
);
6667 data
= (struct save_window_data
*)vec
;
6669 XSETFASTINT (data
->frame_cols
, FRAME_COLS (f
));
6670 XSETFASTINT (data
->frame_lines
, FRAME_LINES (f
));
6671 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
6672 XSETFASTINT (data
->frame_tool_bar_lines
, FRAME_TOOL_BAR_LINES (f
));
6673 data
->selected_frame
= selected_frame
;
6674 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6675 XSETBUFFER (data
->current_buffer
, current_buffer
);
6676 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6677 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6678 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6679 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6680 XSETINT (data
->min_height
, window_min_height
);
6681 XSETINT (data
->min_width
, window_min_width
);
6682 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
6683 data
->saved_windows
= tem
;
6684 for (i
= 0; i
< n_windows
; i
++)
6685 XVECTOR (tem
)->contents
[i
]
6686 = Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
);
6687 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6688 XSETWINDOW_CONFIGURATION (tem
, data
);
6692 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
6694 doc
: /* Execute BODY, preserving window sizes and contents.
6695 Return the value of the last form in BODY.
6696 Restore which buffer appears in which window, where display starts,
6697 and the value of point and mark for each window.
6698 Also restore the choice of selected window.
6699 Also restore which buffer is current.
6700 Does not restore the value of point in current buffer.
6701 usage: (save-window-excursion BODY...) */)
6705 register Lisp_Object val
;
6706 register int count
= SPECPDL_INDEX ();
6708 record_unwind_protect (Fset_window_configuration
,
6709 Fcurrent_window_configuration (Qnil
));
6710 val
= Fprogn (args
);
6711 return unbind_to (count
, val
);
6716 /***********************************************************************
6718 ***********************************************************************/
6724 Lisp_Object tail
= Qnil
;
6725 Lisp_Object result
= Qnil
;
6732 if (!NILP (w
->hchild
))
6733 wn
= Fcons (Qnil
, Fcons (Fwindow_edges (wn
),
6734 window_tree (XWINDOW (w
->hchild
))));
6735 else if (!NILP (w
->vchild
))
6736 wn
= Fcons (Qt
, Fcons (Fwindow_edges (wn
),
6737 window_tree (XWINDOW (w
->vchild
))));
6741 result
= tail
= Fcons (wn
, Qnil
);
6745 XSETCDR (tail
, Fcons (wn
, Qnil
));
6749 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6757 DEFUN ("window-tree", Fwindow_tree
, Swindow_tree
,
6759 doc
: /* Return the window tree for frame FRAME.
6761 The return value is a list of the form (ROOT MINI), where ROOT
6762 represents the window tree of the frame's root window, and MINI
6763 is the frame's minibuffer window.
6765 If the root window is not split, ROOT is the root window itself.
6766 Otherwise, ROOT is a list (DIR EDGES W1 W2 ...) where DIR is nil for a
6767 horizontal split, and t for a vertical split, EDGES gives the combined
6768 size and position of the subwindows in the split, and the rest of the
6769 elements are the subwindows in the split. Each of the subwindows may
6770 again be a window or a list representing a window split, and so on.
6771 EDGES is a list \(LEFT TOP RIGHT BOTTOM) as returned by `window-edges'.
6773 If FRAME is nil or omitted, return information on the currently
6781 frame
= selected_frame
;
6783 CHECK_FRAME (frame
);
6786 if (!FRAME_LIVE_P (f
))
6789 return window_tree (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6793 /***********************************************************************
6795 ***********************************************************************/
6797 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6799 doc
: /* Set width of marginal areas of window WINDOW.
6800 If WINDOW is nil, set margins of the currently selected window.
6801 Second arg LEFT-WIDTH specifies the number of character cells to
6802 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6803 does the same for the right marginal area. A nil width parameter
6804 means no margin. */)
6805 (window
, left_width
, right_width
)
6806 Lisp_Object window
, left_width
, right_width
;
6808 struct window
*w
= decode_window (window
);
6810 /* Translate negative or zero widths to nil.
6811 Margins that are too wide have to be checked elsewhere. */
6813 if (!NILP (left_width
))
6815 CHECK_NUMBER (left_width
);
6816 if (XINT (left_width
) <= 0)
6820 if (!NILP (right_width
))
6822 CHECK_NUMBER (right_width
);
6823 if (XINT (right_width
) <= 0)
6827 if (!EQ (w
->left_margin_cols
, left_width
)
6828 || !EQ (w
->right_margin_cols
, right_width
))
6830 w
->left_margin_cols
= left_width
;
6831 w
->right_margin_cols
= right_width
;
6833 adjust_window_margins (w
);
6835 ++windows_or_buffers_changed
;
6836 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6843 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6845 doc
: /* Get width of marginal areas of window WINDOW.
6846 If WINDOW is omitted or nil, use the currently selected window.
6847 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6848 If a marginal area does not exist, its width will be returned
6853 struct window
*w
= decode_window (window
);
6854 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
6859 /***********************************************************************
6861 ***********************************************************************/
6863 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6865 doc
: /* Set the fringe widths of window WINDOW.
6866 If WINDOW is nil, set the fringe widths of the currently selected
6868 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6869 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6870 fringe width. If a fringe width arg is nil, that means to use the
6871 frame's default fringe width. Default fringe widths can be set with
6872 the command `set-fringe-style'.
6873 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6874 outside of the display margins. By default, fringes are drawn between
6875 display marginal areas and the text area. */)
6876 (window
, left_width
, right_width
, outside_margins
)
6877 Lisp_Object window
, left_width
, right_width
, outside_margins
;
6879 struct window
*w
= decode_window (window
);
6881 if (!NILP (left_width
))
6882 CHECK_NATNUM (left_width
);
6883 if (!NILP (right_width
))
6884 CHECK_NATNUM (right_width
);
6886 /* Do nothing on a tty. */
6887 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6888 && (!EQ (w
->left_fringe_width
, left_width
)
6889 || !EQ (w
->right_fringe_width
, right_width
)
6890 || !EQ (w
->fringes_outside_margins
, outside_margins
)))
6892 w
->left_fringe_width
= left_width
;
6893 w
->right_fringe_width
= right_width
;
6894 w
->fringes_outside_margins
= outside_margins
;
6896 adjust_window_margins (w
);
6898 clear_glyph_matrix (w
->current_matrix
);
6899 w
->window_end_valid
= Qnil
;
6901 ++windows_or_buffers_changed
;
6902 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6909 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6911 doc
: /* Get width of fringes of window WINDOW.
6912 If WINDOW is omitted or nil, use the currently selected window.
6913 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6917 struct window
*w
= decode_window (window
);
6919 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6920 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6921 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
6922 ? Qt
: Qnil
), Qnil
)));
6927 /***********************************************************************
6929 ***********************************************************************/
6931 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
, Sset_window_scroll_bars
,
6933 doc
: /* Set width and type of scroll bars of window WINDOW.
6934 If window is nil, set scroll bars of the currently selected window.
6935 Second parameter WIDTH specifies the pixel width for the scroll bar;
6936 this is automatically adjusted to a multiple of the frame column width.
6937 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6938 bar: left, right, or nil.
6939 If WIDTH is nil, use the frame's scroll-bar width.
6940 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6941 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6942 (window
, width
, vertical_type
, horizontal_type
)
6943 Lisp_Object window
, width
, vertical_type
, horizontal_type
;
6945 struct window
*w
= decode_window (window
);
6949 CHECK_NATNUM (width
);
6951 if (XINT (width
) == 0)
6952 vertical_type
= Qnil
;
6955 if (!(NILP (vertical_type
)
6956 || EQ (vertical_type
, Qleft
)
6957 || EQ (vertical_type
, Qright
)
6958 || EQ (vertical_type
, Qt
)))
6959 error ("Invalid type of vertical scroll bar");
6961 if (!EQ (w
->scroll_bar_width
, width
)
6962 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6964 w
->scroll_bar_width
= width
;
6965 w
->vertical_scroll_bar_type
= vertical_type
;
6967 adjust_window_margins (w
);
6969 clear_glyph_matrix (w
->current_matrix
);
6970 w
->window_end_valid
= Qnil
;
6972 ++windows_or_buffers_changed
;
6973 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6980 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6982 doc
: /* Get width and type of scroll bars of window WINDOW.
6983 If WINDOW is omitted or nil, use the currently selected window.
6984 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6985 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6990 struct window
*w
= decode_window (window
);
6991 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6992 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6993 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6994 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6995 Fcons (w
->vertical_scroll_bar_type
,
6996 Fcons (Qnil
, Qnil
))));
7001 /***********************************************************************
7003 ***********************************************************************/
7005 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
7006 doc
: /* Return the amount by which WINDOW is scrolled vertically.
7007 Use the selected window if WINDOW is nil or omitted.
7008 Normally, value is a multiple of the canonical character height of WINDOW;
7009 optional second arg PIXELS-P means value is measured in pixels. */)
7011 Lisp_Object window
, pixels_p
;
7018 window
= selected_window
;
7020 CHECK_WINDOW (window
);
7021 w
= XWINDOW (window
);
7022 f
= XFRAME (w
->frame
);
7024 if (FRAME_WINDOW_P (f
))
7025 result
= (NILP (pixels_p
)
7026 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
7027 : make_number (-w
->vscroll
));
7029 result
= make_number (0);
7034 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
7036 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
7037 WINDOW nil means use the selected window. Normally, VSCROLL is a
7038 non-negative multiple of the canonical character height of WINDOW;
7039 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
7040 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
7041 corresponds to an integral number of pixels. The return value is the
7042 result of this rounding.
7043 If PIXELS-P is non-nil, the return value is VSCROLL. */)
7044 (window
, vscroll
, pixels_p
)
7045 Lisp_Object window
, vscroll
, pixels_p
;
7051 window
= selected_window
;
7053 CHECK_WINDOW (window
);
7054 CHECK_NUMBER_OR_FLOAT (vscroll
);
7056 w
= XWINDOW (window
);
7057 f
= XFRAME (w
->frame
);
7059 if (FRAME_WINDOW_P (f
))
7061 int old_dy
= w
->vscroll
;
7063 w
->vscroll
= - (NILP (pixels_p
)
7064 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
7065 : XFLOATINT (vscroll
));
7066 w
->vscroll
= min (w
->vscroll
, 0);
7068 if (w
->vscroll
!= old_dy
)
7070 /* Adjust glyph matrix of the frame if the virtual display
7071 area becomes larger than before. */
7072 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
7075 /* Prevent redisplay shortcuts. */
7076 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
7080 return Fwindow_vscroll (window
, pixels_p
);
7084 /* Call FN for all leaf windows on frame F. FN is called with the
7085 first argument being a pointer to the leaf window, and with
7086 additional argument USER_DATA. Stops when FN returns 0. */
7089 foreach_window (f
, fn
, user_data
)
7091 int (* fn
) P_ ((struct window
*, void *));
7094 /* Fdelete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
7095 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
7096 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
7100 /* Helper function for foreach_window. Call FN for all leaf windows
7101 reachable from W. FN is called with the first argument being a
7102 pointer to the leaf window, and with additional argument USER_DATA.
7103 Stop when FN returns 0. Value is 0 if stopped by FN. */
7106 foreach_window_1 (w
, fn
, user_data
)
7108 int (* fn
) P_ ((struct window
*, void *));
7113 for (cont
= 1; w
&& cont
;)
7115 if (!NILP (w
->hchild
))
7116 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
7117 else if (!NILP (w
->vchild
))
7118 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
7120 cont
= fn (w
, user_data
);
7122 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
7129 /* Freeze or unfreeze the window start of W unless it is a
7130 mini-window or the selected window. FREEZE_P non-null means freeze
7131 the window start. */
7134 freeze_window_start (w
, freeze_p
)
7138 if (MINI_WINDOW_P (w
)
7139 || (WINDOWP (selected_window
) /* Can be nil in corner cases. */
7140 && (w
== XWINDOW (selected_window
)
7141 || (MINI_WINDOW_P (XWINDOW (selected_window
))
7142 && ! NILP (Vminibuf_scroll_window
)
7143 && w
== XWINDOW (Vminibuf_scroll_window
)))))
7146 w
->frozen_window_start_p
= freeze_p
!= NULL
;
7151 /* Freeze or unfreeze the window starts of all leaf windows on frame
7152 F, except the selected window and a mini-window. FREEZE_P non-zero
7153 means freeze the window start. */
7156 freeze_window_starts (f
, freeze_p
)
7160 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
7164 /***********************************************************************
7166 ***********************************************************************/
7168 /* Return 1 if window configurations C1 and C2
7169 describe the same state of affairs. This is used by Fequal. */
7172 compare_window_configurations (c1
, c2
, ignore_positions
)
7174 int ignore_positions
;
7176 register struct save_window_data
*d1
, *d2
;
7177 struct Lisp_Vector
*sw1
, *sw2
;
7180 CHECK_WINDOW_CONFIGURATION (c1
);
7181 CHECK_WINDOW_CONFIGURATION (c2
);
7183 d1
= (struct save_window_data
*) XVECTOR (c1
);
7184 d2
= (struct save_window_data
*) XVECTOR (c2
);
7185 sw1
= XVECTOR (d1
->saved_windows
);
7186 sw2
= XVECTOR (d2
->saved_windows
);
7188 if (! EQ (d1
->frame_cols
, d2
->frame_cols
))
7190 if (! EQ (d1
->frame_lines
, d2
->frame_lines
))
7192 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
7194 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
7196 /* Don't compare the current_window field directly.
7197 Instead see w1_is_current and w2_is_current, below. */
7198 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
7200 if (! ignore_positions
)
7202 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
7204 if (! EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
))
7207 /* Don't compare the root_window field.
7208 We don't require the two configurations
7209 to use the same window object,
7210 and the two root windows must be equivalent
7211 if everything else compares equal. */
7212 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
7214 if (! EQ (d1
->min_width
, d2
->min_width
))
7216 if (! EQ (d1
->min_height
, d2
->min_height
))
7219 /* Verify that the two confis have the same number of windows. */
7220 if (sw1
->size
!= sw2
->size
)
7223 for (i
= 0; i
< sw1
->size
; i
++)
7225 struct saved_window
*p1
, *p2
;
7226 int w1_is_current
, w2_is_current
;
7228 p1
= SAVED_WINDOW_N (sw1
, i
);
7229 p2
= SAVED_WINDOW_N (sw2
, i
);
7231 /* Verify that the current windows in the two
7232 configurations correspond to each other. */
7233 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
7234 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
7236 if (w1_is_current
!= w2_is_current
)
7239 /* Verify that the corresponding windows do match. */
7240 if (! EQ (p1
->buffer
, p2
->buffer
))
7242 if (! EQ (p1
->left_col
, p2
->left_col
))
7244 if (! EQ (p1
->top_line
, p2
->top_line
))
7246 if (! EQ (p1
->total_cols
, p2
->total_cols
))
7248 if (! EQ (p1
->total_lines
, p2
->total_lines
))
7250 if (! EQ (p1
->display_table
, p2
->display_table
))
7252 if (! EQ (p1
->parent
, p2
->parent
))
7254 if (! EQ (p1
->prev
, p2
->prev
))
7256 if (! ignore_positions
)
7258 if (! EQ (p1
->hscroll
, p2
->hscroll
))
7260 if (!EQ (p1
->min_hscroll
, p2
->min_hscroll
))
7262 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
7264 if (NILP (Fequal (p1
->start
, p2
->start
)))
7266 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
7268 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
7271 if (! EQ (p1
->left_margin_cols
, p2
->left_margin_cols
))
7273 if (! EQ (p1
->right_margin_cols
, p2
->right_margin_cols
))
7275 if (! EQ (p1
->left_fringe_width
, p2
->left_fringe_width
))
7277 if (! EQ (p1
->right_fringe_width
, p2
->right_fringe_width
))
7279 if (! EQ (p1
->fringes_outside_margins
, p2
->fringes_outside_margins
))
7281 if (! EQ (p1
->scroll_bar_width
, p2
->scroll_bar_width
))
7283 if (! EQ (p1
->vertical_scroll_bar_type
, p2
->vertical_scroll_bar_type
))
7290 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
7291 Scompare_window_configurations
, 2, 2, 0,
7292 doc
: /* Compare two window configurations as regards the structure of windows.
7293 This function ignores details such as the values of point and mark
7294 and scrolling positions. */)
7298 if (compare_window_configurations (x
, y
, 1))
7306 struct frame
*f
= make_initial_frame ();
7307 XSETFRAME (selected_frame
, f
);
7308 Vterminal_frame
= selected_frame
;
7309 minibuf_window
= f
->minibuffer_window
;
7310 selected_window
= f
->selected_window
;
7311 last_nonminibuf_frame
= f
;
7313 window_initialized
= 1;
7319 Vwindow_list
= Qnil
;
7325 Qscroll_up
= intern ("scroll-up");
7326 staticpro (&Qscroll_up
);
7328 Qscroll_down
= intern ("scroll-down");
7329 staticpro (&Qscroll_down
);
7331 Qwindow_size_fixed
= intern ("window-size-fixed");
7332 staticpro (&Qwindow_size_fixed
);
7333 Fset (Qwindow_size_fixed
, Qnil
);
7335 staticpro (&Qwindow_configuration_change_hook
);
7336 Qwindow_configuration_change_hook
7337 = intern ("window-configuration-change-hook");
7339 Qwindowp
= intern ("windowp");
7340 staticpro (&Qwindowp
);
7342 Qwindow_configuration_p
= intern ("window-configuration-p");
7343 staticpro (&Qwindow_configuration_p
);
7345 Qwindow_live_p
= intern ("window-live-p");
7346 staticpro (&Qwindow_live_p
);
7348 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
7349 staticpro (&Qtemp_buffer_show_hook
);
7351 staticpro (&Vwindow_list
);
7353 minibuf_selected_window
= Qnil
;
7354 staticpro (&minibuf_selected_window
);
7356 window_scroll_pixel_based_preserve_y
= -1;
7358 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
7359 doc
: /* Non-nil means call as function to display a help buffer.
7360 The function is called with one argument, the buffer to be displayed.
7361 Used by `with-output-to-temp-buffer'.
7362 If this function is used, then it must do the entire job of showing
7363 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
7364 Vtemp_buffer_show_function
= Qnil
;
7366 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
7367 doc
: /* If non-nil, function to call to handle `display-buffer'.
7368 It will receive two args, the buffer and a flag which if non-nil means
7369 that the currently selected window is not acceptable.
7370 It should choose or create a window, display the specified buffer in it,
7371 and return the window.
7372 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'
7373 work using this function. */);
7374 Vdisplay_buffer_function
= Qnil
;
7376 DEFVAR_LISP ("even-window-heights", &Veven_window_heights
,
7377 doc
: /* *If non-nil, `display-buffer' should even the window heights.
7378 If nil, `display-buffer' will leave the window configuration alone. */);
7379 Veven_window_heights
= Qt
;
7381 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
7382 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
7383 Vminibuf_scroll_window
= Qnil
;
7385 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows
,
7386 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
7387 If the minibuffer is active, the `minibuffer-scroll-window' mode line
7388 is displayed in the `mode-line' face. */);
7389 mode_line_in_non_selected_windows
= 1;
7391 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
7392 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
7393 Vother_window_scroll_buffer
= Qnil
;
7395 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
7396 doc
: /* *Non-nil means `display-buffer' should make a separate frame. */);
7399 DEFVAR_BOOL ("auto-window-vscroll", &auto_window_vscroll_p
,
7400 doc
: /* *Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
7401 auto_window_vscroll_p
= 1;
7403 DEFVAR_BOOL ("display-buffer-reuse-frames", &display_buffer_reuse_frames
,
7404 doc
: /* *Non-nil means `display-buffer' should reuse frames.
7405 If the buffer in question is already displayed in a frame, raise that frame. */);
7406 display_buffer_reuse_frames
= 0;
7408 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
7409 doc
: /* Function to call to handle automatic new frame creation.
7410 It is called with no arguments and should return a newly created frame.
7412 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'
7413 where `pop-up-frame-alist' would hold the default frame parameters. */);
7414 Vpop_up_frame_function
= Qnil
;
7416 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
7417 doc
: /* *List of buffer names that should have their own special frames.
7418 Displaying a buffer with `display-buffer' or `pop-to-buffer',
7419 if its name is in this list, makes a special frame for it
7420 using `special-display-function'. See also `special-display-regexps'.
7422 An element of the list can be a list instead of just a string.
7423 There are two ways to use a list as an element:
7424 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)
7425 In the first case, the FRAME-PARAMETERS are pairs of the form
7426 \(PARAMETER . VALUE); these parameter values are used to create the frame.
7427 In the second case, FUNCTION is called with BUFFER as the first argument,
7428 followed by the OTHER-ARGS--it can display BUFFER in any way it likes.
7429 All this is done by the function found in `special-display-function'.
7431 If the specified frame parameters include (same-buffer . t), the
7432 buffer is displayed in the currently selected window. Otherwise, if
7433 they include (same-frame . t), the buffer is displayed in a new window
7434 in the currently selected frame.
7436 If this variable appears \"not to work\", because you add a name to it
7437 but that buffer still appears in the selected window, look at the
7438 values of `same-window-buffer-names' and `same-window-regexps'.
7439 Those variables take precedence over this one. */);
7440 Vspecial_display_buffer_names
= Qnil
;
7442 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
7443 doc
: /* *List of regexps saying which buffers should have their own special frames.
7444 When displaying a buffer with `display-buffer' or `pop-to-buffer',
7445 if any regexp in this list matches the buffer name, it makes a
7446 special frame for the buffer by calling `special-display-function'.
7448 An element of the list can be a list instead of just a string.
7449 There are two ways to use a list as an element:
7450 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)
7451 In the first case, the FRAME-PARAMETERS are pairs of the form
7452 \(PARAMETER . VALUE); these parameter values are used to create the frame.
7453 In the second case, FUNCTION is called with BUFFER as the first argument,
7454 followed by the OTHER-ARGS--it can display the buffer in any way it likes.
7455 All this is done by the function found in `special-display-function'.
7457 If the specified frame parameters include (same-buffer . t), the
7458 buffer is displayed in the currently selected window. Otherwise, if
7459 they include (same-frame . t), the buffer is displayed in a new window
7460 in the currently selected frame.
7462 If this variable appears \"not to work\", because you add a regexp to it
7463 but the matching buffers still appear in the selected window, look at the
7464 values of `same-window-buffer-names' and `same-window-regexps'.
7465 Those variables take precedence over this one. */);
7466 Vspecial_display_regexps
= Qnil
;
7468 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
7469 doc
: /* Function to call to make a new frame for a special buffer.
7470 It is called with two arguments, the buffer and optional buffer specific
7471 data, and should return a window displaying that buffer.
7472 The default value normally makes a separate frame for the buffer,
7473 using `special-display-frame-alist' to specify the frame parameters.
7474 But if the buffer specific data includes (same-buffer . t) then the
7475 buffer is displayed in the current selected window.
7476 Otherwise if it includes (same-frame . t) then the buffer is displayed in
7477 a new window in the currently selected frame.
7479 A buffer is special if it is listed in `special-display-buffer-names'
7480 or matches a regexp in `special-display-regexps'. */);
7481 Vspecial_display_function
= Qnil
;
7483 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
7484 doc
: /* *List of buffer names that should appear in the selected window.
7485 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'
7486 switches to it in the selected window, rather than making it appear
7487 in some other window.
7489 An element of the list can be a cons cell instead of just a string.
7490 Then the car must be a string, which specifies the buffer name.
7491 This is for compatibility with `special-display-buffer-names';
7492 the cdr of the cons cell is ignored.
7494 See also `same-window-regexps'. */);
7495 Vsame_window_buffer_names
= Qnil
;
7497 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
7498 doc
: /* *List of regexps saying which buffers should appear in the selected window.
7499 If a buffer name matches one of these regexps, then displaying it
7500 using `display-buffer' or `pop-to-buffer' switches to it
7501 in the selected window, rather than making it appear in some other window.
7503 An element of the list can be a cons cell instead of just a string.
7504 Then the car must be a string, which specifies the buffer name.
7505 This is for compatibility with `special-display-buffer-names';
7506 the cdr of the cons cell is ignored.
7508 See also `same-window-buffer-names'. */);
7509 Vsame_window_regexps
= Qnil
;
7511 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
7512 doc
: /* *Non-nil means display-buffer should make new windows. */);
7515 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
7516 doc
: /* *Number of lines of continuity when scrolling by screenfuls. */);
7517 next_screen_context_lines
= 2;
7519 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
7520 doc
: /* *A window must be at least this tall to be eligible for splitting
7521 by `display-buffer'. The value is in line units.
7522 If there is only one window, it is split regardless of this value. */);
7523 split_height_threshold
= 500;
7525 DEFVAR_LISP ("split-window-preferred-function",
7526 &Vsplit_window_preferred_function
,
7527 doc
: /* Function to use to split a window.
7528 This is used by `display-buffer' to allow the user to choose whether
7529 to split windows horizontally or vertically or some mix of the two.
7530 It is called with a window as single argument and should split it in two
7531 and return the new window. */);
7532 Vsplit_window_preferred_function
= intern ("split-window");
7534 DEFVAR_INT ("window-min-height", &window_min_height
,
7535 doc
: /* *Delete any window less than this tall (including its mode line).
7536 The value is in line units. */);
7537 window_min_height
= 4;
7539 DEFVAR_INT ("window-min-width", &window_min_width
,
7540 doc
: /* *Delete any window less than this wide (measured in characters). */);
7541 window_min_width
= 10;
7543 DEFVAR_LISP ("scroll-preserve-screen-position",
7544 &Vscroll_preserve_screen_position
,
7545 doc
: /* *Controls if scroll commands move point to keep its screen line unchanged.
7546 A value of nil means point does not keep its screen position except
7547 at the scroll margin or window boundary respectively.
7548 A value of t means point keeps its screen position if the scroll
7549 command moved it vertically out of the window, e.g. when scrolling
7551 Any other value means point always keeps its screen position. */);
7552 Vscroll_preserve_screen_position
= Qnil
;
7554 DEFVAR_LISP ("window-configuration-change-hook",
7555 &Vwindow_configuration_change_hook
,
7556 doc
: /* Functions to call when window configuration changes.
7557 The selected frame is the one whose configuration has changed. */);
7558 Vwindow_configuration_change_hook
= Qnil
;
7560 defsubr (&Sselected_window
);
7561 defsubr (&Sminibuffer_window
);
7562 defsubr (&Swindow_minibuffer_p
);
7563 defsubr (&Swindowp
);
7564 defsubr (&Swindow_live_p
);
7565 defsubr (&Spos_visible_in_window_p
);
7566 defsubr (&Swindow_line_height
);
7567 defsubr (&Swindow_buffer
);
7568 defsubr (&Swindow_height
);
7569 defsubr (&Swindow_width
);
7570 defsubr (&Swindow_full_width_p
);
7571 defsubr (&Swindow_hscroll
);
7572 defsubr (&Sset_window_hscroll
);
7573 defsubr (&Swindow_redisplay_end_trigger
);
7574 defsubr (&Sset_window_redisplay_end_trigger
);
7575 defsubr (&Swindow_edges
);
7576 defsubr (&Swindow_pixel_edges
);
7577 defsubr (&Swindow_inside_edges
);
7578 defsubr (&Swindow_inside_pixel_edges
);
7579 defsubr (&Scoordinates_in_window_p
);
7580 defsubr (&Swindow_at
);
7581 defsubr (&Swindow_point
);
7582 defsubr (&Swindow_start
);
7583 defsubr (&Swindow_end
);
7584 defsubr (&Sset_window_point
);
7585 defsubr (&Sset_window_start
);
7586 defsubr (&Swindow_dedicated_p
);
7587 defsubr (&Sset_window_dedicated_p
);
7588 defsubr (&Swindow_display_table
);
7589 defsubr (&Sset_window_display_table
);
7590 defsubr (&Snext_window
);
7591 defsubr (&Sprevious_window
);
7592 defsubr (&Sother_window
);
7593 defsubr (&Sget_lru_window
);
7594 defsubr (&Sget_largest_window
);
7595 defsubr (&Sget_buffer_window
);
7596 defsubr (&Sdelete_other_windows
);
7597 defsubr (&Sdelete_windows_on
);
7598 defsubr (&Sreplace_buffer_in_windows
);
7599 defsubr (&Sdelete_window
);
7600 defsubr (&Sset_window_buffer
);
7601 defsubr (&Sselect_window
);
7602 defsubr (&Sspecial_display_p
);
7603 defsubr (&Ssame_window_p
);
7604 defsubr (&Sdisplay_buffer
);
7605 defsubr (&Sforce_window_update
);
7606 defsubr (&Ssplit_window
);
7607 defsubr (&Senlarge_window
);
7608 defsubr (&Sshrink_window
);
7609 defsubr (&Sadjust_window_trailing_edge
);
7610 defsubr (&Sscroll_up
);
7611 defsubr (&Sscroll_down
);
7612 defsubr (&Sscroll_left
);
7613 defsubr (&Sscroll_right
);
7614 defsubr (&Sother_window_for_scrolling
);
7615 defsubr (&Sscroll_other_window
);
7616 defsubr (&Sminibuffer_selected_window
);
7617 defsubr (&Srecenter
);
7618 defsubr (&Swindow_text_height
);
7619 defsubr (&Smove_to_window_line
);
7620 defsubr (&Swindow_configuration_p
);
7621 defsubr (&Swindow_configuration_frame
);
7622 defsubr (&Sset_window_configuration
);
7623 defsubr (&Scurrent_window_configuration
);
7624 defsubr (&Ssave_window_excursion
);
7625 defsubr (&Swindow_tree
);
7626 defsubr (&Sset_window_margins
);
7627 defsubr (&Swindow_margins
);
7628 defsubr (&Sset_window_fringes
);
7629 defsubr (&Swindow_fringes
);
7630 defsubr (&Sset_window_scroll_bars
);
7631 defsubr (&Swindow_scroll_bars
);
7632 defsubr (&Swindow_vscroll
);
7633 defsubr (&Sset_window_vscroll
);
7634 defsubr (&Scompare_window_configurations
);
7635 defsubr (&Swindow_list
);
7641 initial_define_key (control_x_map
, '1', "delete-other-windows");
7642 initial_define_key (control_x_map
, '2', "split-window");
7643 initial_define_key (control_x_map
, '0', "delete-window");
7644 initial_define_key (control_x_map
, 'o', "other-window");
7645 initial_define_key (control_x_map
, '^', "enlarge-window");
7646 initial_define_key (control_x_map
, '<', "scroll-left");
7647 initial_define_key (control_x_map
, '>', "scroll-right");
7649 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
7650 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
7651 initial_define_key (meta_map
, 'v', "scroll-down");
7653 initial_define_key (global_map
, Ctl('L'), "recenter");
7654 initial_define_key (meta_map
, 'r', "move-to-window-line");
7657 /* arch-tag: 90a9c576-0590-48f1-a5f1-6c96a0452d9f
7658 (do not change this comment) */