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 2, 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. */
34 #include "dispextern.h"
35 #include "blockinput.h"
36 #include "intervals.h"
40 #endif /* HAVE_X_WINDOWS */
52 Lisp_Object Qwindowp
, Qwindow_live_p
, Qwindow_configuration_p
;
53 Lisp_Object Qscroll_up
, Qscroll_down
;
54 Lisp_Object Qwindow_size_fixed
;
55 extern Lisp_Object Qleft_margin
, Qright_margin
;
57 static int displayed_window_lines
P_ ((struct window
*));
58 static struct window
*decode_window
P_ ((Lisp_Object
));
59 static int count_windows
P_ ((struct window
*));
60 static int get_leaf_windows
P_ ((struct window
*, struct window
**, int));
61 static void window_scroll
P_ ((Lisp_Object
, int, int, int));
62 static void window_scroll_pixel_based
P_ ((Lisp_Object
, int, int, int));
63 static void window_scroll_line_based
P_ ((Lisp_Object
, int, int, int));
64 static int window_min_size_1
P_ ((struct window
*, int));
65 static int window_min_size_2
P_ ((struct window
*, int));
66 static int window_min_size
P_ ((struct window
*, int, int, int *));
67 static void size_window
P_ ((Lisp_Object
, int, int, int, int, int));
68 static int freeze_window_start
P_ ((struct window
*, void *));
69 static int window_fixed_size_p
P_ ((struct window
*, int, int));
70 static void enlarge_window
P_ ((Lisp_Object
, int, int));
71 static Lisp_Object window_list
P_ ((void));
72 static int add_window_to_list
P_ ((struct window
*, void *));
73 static int candidate_window_p
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
75 static Lisp_Object next_window
P_ ((Lisp_Object
, Lisp_Object
,
77 static void decode_next_window_args
P_ ((Lisp_Object
*, Lisp_Object
*,
79 static int foreach_window_1
P_ ((struct window
*,
80 int (* fn
) (struct window
*, void *),
82 static Lisp_Object window_list_1
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
84 /* This is the window in which the terminal's cursor should
85 be left when nothing is being done with it. This must
86 always be a leaf window, and its buffer is selected by
87 the top level editing loop at the end of each command.
89 This value is always the same as
90 FRAME_SELECTED_WINDOW (selected_frame). */
92 Lisp_Object selected_window
;
94 /* A list of all windows for use by next_window and Fwindow_list.
95 Functions creating or deleting windows should invalidate this cache
96 by setting it to nil. */
98 Lisp_Object Vwindow_list
;
100 /* The mini-buffer window of the selected frame.
101 Note that you cannot test for mini-bufferness of an arbitrary window
102 by comparing against this; but you can test for mini-bufferness of
103 the selected window. */
105 Lisp_Object minibuf_window
;
107 /* Non-nil means it is the window whose mode line should be
108 shown as the selected window when the minibuffer is selected. */
110 Lisp_Object minibuf_selected_window
;
112 /* Non-nil means it is the window for C-M-v to scroll
113 when the mini-buffer is selected. */
115 Lisp_Object Vminibuf_scroll_window
;
117 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
119 Lisp_Object Vother_window_scroll_buffer
;
121 /* Non-nil means it's function to call to display temp buffers. */
123 Lisp_Object Vtemp_buffer_show_function
;
125 /* Non-zero means line and page scrolling on tall lines (with images)
126 does partial scrolling by modifying window-vscroll. */
128 int auto_window_vscroll_p
;
130 /* Non-zero means to use mode-line-inactive face in all windows but the
131 selected-window and the minibuffer-scroll-window when the
132 minibuffer is active. */
133 int mode_line_in_non_selected_windows
;
135 /* If a window gets smaller than either of these, it is removed. */
137 EMACS_INT window_min_height
;
138 EMACS_INT window_min_width
;
140 /* Nonzero implies Fdisplay_buffer should create windows. */
144 /* Nonzero implies make new frames for Fdisplay_buffer. */
148 /* Nonzero means reuse existing frames for displaying buffers. */
150 int display_buffer_reuse_frames
;
152 /* Non-nil means use this function instead of default */
154 Lisp_Object Vpop_up_frame_function
;
156 /* Function to call to handle Fdisplay_buffer. */
158 Lisp_Object Vdisplay_buffer_function
;
160 /* Non-nil means that Fdisplay_buffer should even the heights of windows. */
162 Lisp_Object Veven_window_heights
;
164 /* List of buffer *names* for buffers that should have their own frames. */
166 Lisp_Object Vspecial_display_buffer_names
;
168 /* List of regexps for buffer names that should have their own frames. */
170 Lisp_Object Vspecial_display_regexps
;
172 /* Function to pop up a special frame. */
174 Lisp_Object Vspecial_display_function
;
176 /* List of buffer *names* for buffers to appear in selected window. */
178 Lisp_Object Vsame_window_buffer_names
;
180 /* List of regexps for buffer names to appear in selected window. */
182 Lisp_Object Vsame_window_regexps
;
184 /* Hook run at end of temp_output_buffer_show. */
186 Lisp_Object Qtemp_buffer_show_hook
;
188 /* Fdisplay_buffer always splits the largest window
189 if that window is more than this high. */
191 EMACS_INT split_height_threshold
;
193 /* Number of lines of continuity in scrolling by screenfuls. */
195 EMACS_INT next_screen_context_lines
;
197 /* Incremented for each window created. */
199 static int sequence_number
;
201 /* Nonzero after init_window_once has finished. */
203 static int window_initialized
;
205 /* Hook to run when window config changes. */
207 Lisp_Object Qwindow_configuration_change_hook
;
208 Lisp_Object Vwindow_configuration_change_hook
;
210 /* Non-nil means scroll commands try to put point
211 at the same screen height as previously. */
213 Lisp_Object Vscroll_preserve_screen_position
;
215 /* Incremented by 1 whenever a window is deleted. */
217 int window_deletion_count
;
219 /* Used by the function window_scroll_pixel_based */
221 static int window_scroll_pixel_based_preserve_y
;
223 #if 0 /* This isn't used anywhere. */
224 /* Nonzero means we can split a frame even if it is "unsplittable". */
225 static int inhibit_frame_unsplittable
;
228 extern EMACS_INT scroll_margin
;
230 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
232 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
233 doc
: /* Returns t if OBJECT is a window. */)
237 return WINDOWP (object
) ? Qt
: Qnil
;
240 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
241 doc
: /* Returns t if OBJECT is a window which is currently visible. */)
245 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
252 register struct window
*p
;
254 p
= allocate_window ();
256 XSETFASTINT (p
->sequence_number
, sequence_number
);
257 XSETFASTINT (p
->left_col
, 0);
258 XSETFASTINT (p
->top_line
, 0);
259 XSETFASTINT (p
->total_lines
, 0);
260 XSETFASTINT (p
->total_cols
, 0);
261 XSETFASTINT (p
->hscroll
, 0);
262 XSETFASTINT (p
->min_hscroll
, 0);
263 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
264 p
->start
= Fmake_marker ();
265 p
->pointm
= Fmake_marker ();
266 XSETFASTINT (p
->use_time
, 0);
268 p
->display_table
= Qnil
;
270 p
->pseudo_window_p
= 0;
271 bzero (&p
->cursor
, sizeof (p
->cursor
));
272 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
273 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
274 p
->desired_matrix
= p
->current_matrix
= 0;
275 p
->nrows_scale_factor
= p
->ncols_scale_factor
= 1;
276 p
->phys_cursor_type
= -1;
277 p
->phys_cursor_width
= -1;
278 p
->must_be_updated_p
= 0;
279 XSETFASTINT (p
->window_end_vpos
, 0);
280 XSETFASTINT (p
->window_end_pos
, 0);
281 p
->window_end_valid
= Qnil
;
284 XSETFASTINT (p
->last_point
, 0);
285 p
->frozen_window_start_p
= 0;
286 p
->last_cursor_off_p
= p
->cursor_off_p
= 0;
287 p
->left_margin_cols
= Qnil
;
288 p
->right_margin_cols
= Qnil
;
289 p
->left_fringe_width
= Qnil
;
290 p
->right_fringe_width
= Qnil
;
291 p
->fringes_outside_margins
= Qnil
;
292 p
->scroll_bar_width
= Qnil
;
293 p
->vertical_scroll_bar_type
= Qt
;
299 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
300 doc
: /* Return the window that the cursor now appears in and commands apply to. */)
303 return selected_window
;
306 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
307 doc
: /* Return the window used now for minibuffers.
308 If the optional argument FRAME is specified, return the minibuffer window
309 used by that frame. */)
314 frame
= selected_frame
;
315 CHECK_LIVE_FRAME (frame
);
316 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
319 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
320 doc
: /* Returns non-nil if WINDOW is a minibuffer window.
321 WINDOW defaults to the selected window. */)
325 struct window
*w
= decode_window (window
);
326 return MINI_WINDOW_P (w
) ? Qt
: Qnil
;
330 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
331 Spos_visible_in_window_p
, 0, 3, 0,
332 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
333 Return nil if that position is scrolled vertically out of view.
334 If a character is only partially visible, nil is returned, unless the
335 optional argument PARTIALLY is non-nil.
336 If POS is only out of view because of horizontal scrolling, return non-nil.
337 If POS is t, it specifies the position of the last visible glyph in WINDOW.
338 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
340 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
341 return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
342 where X and Y are the pixel coordinates relative to the top left corner
343 of the window. The remaining elements are omitted if the character after
344 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
345 off-window at the top and bottom of the row, ROWH is the height of the
346 display row, and VPOS is the row number (0-based) containing POS. */)
347 (pos
, window
, partially
)
348 Lisp_Object pos
, window
, partially
;
350 register struct window
*w
;
352 register struct buffer
*buf
;
354 Lisp_Object in_window
= Qnil
;
355 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
358 w
= decode_window (window
);
359 buf
= XBUFFER (w
->buffer
);
360 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
364 else if (!NILP (pos
))
366 CHECK_NUMBER_COERCE_MARKER (pos
);
369 else if (w
== XWINDOW (selected_window
))
372 posint
= XMARKER (w
->pointm
)->charpos
;
374 /* If position is above window start or outside buffer boundaries,
375 or if window start is out of range, position is not visible. */
377 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
378 && CHARPOS (top
) >= BUF_BEGV (buf
)
379 && CHARPOS (top
) <= BUF_ZV (buf
)
380 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
381 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
384 if (!NILP (in_window
) && !NILP (partially
))
386 Lisp_Object part
= Qnil
;
388 part
= list4 (make_number (rtop
), make_number (rbot
),
389 make_number (rowh
), make_number (vpos
));
390 in_window
= Fcons (make_number (x
),
391 Fcons (make_number (y
), part
));
397 DEFUN ("window-line-height", Fwindow_line_height
,
398 Swindow_line_height
, 0, 2, 0,
399 doc
: /* Return height in pixels of text line LINE in window WINDOW.
400 If WINDOW is nil or omitted, use selected window.
402 Return height of current line if LINE is omitted or nil. Return height of
403 header or mode line if LINE is `header-line' and `mode-line'.
404 Otherwise, LINE is a text line number starting from 0. A negative number
405 counts from the end of the window.
407 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
408 in pixels of the visible part of the line, VPOS and YPOS are the
409 vertical position in lines and pixels of the line, relative to the top
410 of the first text line, and OFFBOT is the number of off-window pixels at
411 the bottom of the text line. If there are off-window pixels at the top
412 of the (first) text line, YPOS is negative.
414 Return nil if window display is not up-to-date. In that case, use
415 `pos-visible-in-window-p' to obtain the information. */)
417 Lisp_Object line
, window
;
419 register struct window
*w
;
420 register struct buffer
*b
;
421 struct glyph_row
*row
, *end_row
;
422 int max_y
, crop
, i
, n
;
424 w
= decode_window (window
);
427 || w
->pseudo_window_p
)
430 CHECK_BUFFER (w
->buffer
);
431 b
= XBUFFER (w
->buffer
);
433 /* Fail if current matrix is not up-to-date. */
434 if (NILP (w
->window_end_valid
)
435 || current_buffer
->clip_changed
436 || current_buffer
->prevent_redisplay_optimizations_p
437 || XFASTINT (w
->last_modified
) < BUF_MODIFF (b
)
438 || XFASTINT (w
->last_overlay_modified
) < BUF_OVERLAY_MODIFF (b
))
444 if (i
< 0 || i
>= w
->current_matrix
->nrows
445 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
447 max_y
= window_text_bottom_y (w
);
451 if (EQ (line
, Qheader_line
))
453 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
455 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
458 return list4 (make_number (row
->height
),
459 make_number (0), make_number (0),
463 if (EQ (line
, Qmode_line
))
465 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
468 return list4 (make_number (row
->height
),
469 make_number (0), /* not accurate */
470 make_number (WINDOW_HEADER_LINE_HEIGHT (w
)
471 + window_text_bottom_y (w
)),
478 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
479 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
480 max_y
= window_text_bottom_y (w
);
483 while ((n
< 0 || i
< n
)
484 && row
<= end_row
&& row
->enabled_p
485 && row
->y
+ row
->height
< max_y
)
488 if (row
> end_row
|| !row
->enabled_p
)
500 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
501 return list4 (make_number (row
->height
+ min (0, row
->y
) - crop
),
503 make_number (row
->y
),
509 static struct window
*
510 decode_window (window
)
511 register Lisp_Object window
;
514 return XWINDOW (selected_window
);
516 CHECK_LIVE_WINDOW (window
);
517 return XWINDOW (window
);
520 static struct window
*
521 decode_any_window (window
)
522 register Lisp_Object window
;
525 return XWINDOW (selected_window
);
527 CHECK_WINDOW (window
);
528 return XWINDOW (window
);
531 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
532 doc
: /* Return the buffer that WINDOW is displaying.
533 WINDOW defaults to the selected window. */)
537 return decode_window (window
)->buffer
;
540 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
541 doc
: /* Return the number of lines in WINDOW (including its mode line).
542 WINDOW defaults to the selected window. */)
546 return decode_any_window (window
)->total_lines
;
549 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
550 doc
: /* Return the number of display columns in WINDOW.
551 This is the width that is usable columns available for text in WINDOW.
552 If you want to find out how many columns WINDOW takes up,
553 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
557 return make_number (window_box_text_cols (decode_any_window (window
)));
560 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
561 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
562 WINDOW defaults to the selected window. */)
566 return decode_window (window
)->hscroll
;
569 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
570 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
571 Return NCOL. NCOL should be zero or positive.
573 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
574 window so that the location of point moves off-window. */)
576 Lisp_Object window
, ncol
;
578 struct window
*w
= decode_window (window
);
582 hscroll
= max (0, XINT (ncol
));
584 /* Prevent redisplay shortcuts when changing the hscroll. */
585 if (XINT (w
->hscroll
) != hscroll
)
586 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
588 w
->hscroll
= make_number (hscroll
);
592 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
593 Swindow_redisplay_end_trigger
, 0, 1, 0,
594 doc
: /* Return WINDOW's redisplay end trigger value.
595 WINDOW defaults to the selected window.
596 See `set-window-redisplay-end-trigger' for more information. */)
600 return decode_window (window
)->redisplay_end_trigger
;
603 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
604 Sset_window_redisplay_end_trigger
, 2, 2, 0,
605 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
606 VALUE should be a buffer position (typically a marker) or nil.
607 If it is a buffer position, then if redisplay in WINDOW reaches a position
608 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
609 with two arguments: WINDOW, and the end trigger value.
610 Afterwards the end-trigger value is reset to nil. */)
612 register Lisp_Object window
, value
;
614 register struct window
*w
;
616 w
= decode_window (window
);
617 w
->redisplay_end_trigger
= value
;
621 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
622 doc
: /* Return a list of the edge coordinates of WINDOW.
623 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
624 RIGHT is one more than the rightmost column occupied by WINDOW,
625 and BOTTOM is one more than the bottommost row occupied by WINDOW.
626 The edges include the space used by the window's scroll bar,
627 display margins, fringes, header line, and mode line, if it has them.
628 To get the edges of the actual text area, use `window-inside-edges'. */)
632 register struct window
*w
= decode_any_window (window
);
634 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w
)),
635 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w
)),
636 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w
)),
637 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w
)),
641 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
642 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
643 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
644 RIGHT is one more than the rightmost x position occupied by WINDOW,
645 and BOTTOM is one more than the bottommost y position occupied by WINDOW.
646 The pixel edges include the space used by the window's scroll bar,
647 display margins, fringes, header line, and mode line, if it has them.
648 To get the edges of the actual text area, use `window-inside-pixel-edges'. */)
652 register struct window
*w
= decode_any_window (window
);
654 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
)),
655 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
)),
656 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
)),
657 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
)),
661 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
662 doc
: /* Return a list of the edge coordinates of WINDOW.
663 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
664 RIGHT is one more than the rightmost column used by text in WINDOW,
665 and BOTTOM is one more than the bottommost row used by text in WINDOW.
666 The inside edges do not include the space used by the window's scroll bar,
667 display margins, fringes, header line, and/or mode line. */)
671 register struct window
*w
= decode_any_window (window
);
673 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w
)
674 + WINDOW_LEFT_MARGIN_COLS (w
)
675 + WINDOW_LEFT_FRINGE_COLS (w
)),
676 make_number (WINDOW_TOP_EDGE_LINE (w
)
677 + WINDOW_HEADER_LINE_LINES (w
)),
678 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w
)
679 - WINDOW_RIGHT_MARGIN_COLS (w
)
680 - WINDOW_RIGHT_FRINGE_COLS (w
)),
681 make_number (WINDOW_BOTTOM_EDGE_LINE (w
)
682 - WINDOW_MODE_LINE_LINES (w
)));
685 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
686 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
687 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
688 RIGHT is one more than the rightmost x position used by text in WINDOW,
689 and BOTTOM is one more than the bottommost y position used by text in WINDOW.
690 The inside edges do not include the space used by the window's scroll bar,
691 display margins, fringes, header line, and/or mode line. */)
695 register struct window
*w
= decode_any_window (window
);
697 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
698 + WINDOW_LEFT_MARGIN_WIDTH (w
)
699 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
700 make_number (WINDOW_TOP_EDGE_Y (w
)
701 + WINDOW_HEADER_LINE_HEIGHT (w
)),
702 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
703 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
704 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
705 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
706 - WINDOW_MODE_LINE_HEIGHT (w
)));
709 /* Test if the character at column *X, row *Y is within window W.
710 If it is not, return ON_NOTHING;
711 if it is in the window's text area,
712 set *x and *y to its location relative to the upper left corner
715 if it is on the window's modeline, return ON_MODE_LINE;
716 if it is on the border between the window and its right sibling,
717 return ON_VERTICAL_BORDER.
718 if it is on a scroll bar,
719 return ON_SCROLL_BAR.
720 if it is on the window's top line, return ON_HEADER_LINE;
721 if it is in left or right fringe of the window,
722 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y
723 to window-relative coordinates;
724 if it is in the marginal area to the left/right of the window,
725 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y
726 to window-relative coordinates.
728 X and Y are frame relative pixel coordinates. */
730 static enum window_part
731 coordinates_in_window (w
, x
, y
)
732 register struct window
*w
;
735 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
736 int left_x
, right_x
, top_y
, bottom_y
;
737 enum window_part part
;
738 int ux
= FRAME_COLUMN_WIDTH (f
);
739 int x0
= WINDOW_LEFT_EDGE_X (w
);
740 int x1
= WINDOW_RIGHT_EDGE_X (w
);
741 /* The width of the area where the vertical line can be dragged.
742 (Between mode lines for instance. */
743 int grabbable_width
= ux
;
744 int lmargin_width
, rmargin_width
, text_left
, text_right
;
746 /* In what's below, we subtract 1 when computing right_x because we
747 want the rightmost pixel, which is given by left_pixel+width-1. */
748 if (w
->pseudo_window_p
)
751 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
752 top_y
= WINDOW_TOP_EDGE_Y (w
);
753 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
757 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
758 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
759 top_y
= WINDOW_TOP_EDGE_Y (w
);
760 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
763 /* Outside any interesting row? */
764 if (*y
< top_y
|| *y
>= bottom_y
)
767 /* On the mode line or header line? If it's near the start of
768 the mode or header line of window that's has a horizontal
769 sibling, say it's on the vertical line. That's to be able
770 to resize windows horizontally in case we're using toolkit
773 if (WINDOW_WANTS_MODELINE_P (w
)
774 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
778 header_vertical_border_check
:
779 /* We're somewhere on the mode line. We consider the place
780 between mode lines of horizontally adjacent mode lines
781 as the vertical border. If scroll bars on the left,
782 return the right window. */
783 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
784 || WINDOW_RIGHTMOST_P (w
))
786 if (!WINDOW_LEFTMOST_P (w
) && abs (*x
- x0
) < grabbable_width
)
788 /* Convert X and Y to window relative coordinates.
789 Vertical border is at the left edge of window. */
790 *x
= max (0, *x
- x0
);
792 return ON_VERTICAL_BORDER
;
797 if (abs (*x
- x1
) < grabbable_width
)
799 /* Convert X and Y to window relative coordinates.
800 Vertical border is at the right edge of window. */
801 *x
= min (x1
, *x
) - x0
;
803 return ON_VERTICAL_BORDER
;
807 if (*x
< x0
|| *x
>= x1
)
810 /* Convert X and Y to window relative coordinates.
811 Mode line starts at left edge of window. */
817 if (WINDOW_WANTS_HEADER_LINE_P (w
)
818 && *y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
))
820 part
= ON_HEADER_LINE
;
821 goto header_vertical_border_check
;
824 if (*x
< x0
|| *x
>= x1
)
827 /* Outside any interesting column? */
828 if (*x
< left_x
|| *x
> right_x
)
831 return ON_SCROLL_BAR
;
834 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
835 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
837 text_left
= window_box_left (w
, TEXT_AREA
);
838 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
840 if (FRAME_WINDOW_P (f
))
842 if (!w
->pseudo_window_p
843 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
844 && !WINDOW_RIGHTMOST_P (w
)
845 && (abs (*x
- right_x
) < grabbable_width
))
847 /* Convert X and Y to window relative coordinates.
848 Vertical border is at the right edge of window. */
849 *x
= min (right_x
, *x
) - left_x
;
851 return ON_VERTICAL_BORDER
;
856 /* Need to say "*x > right_x" rather than >=, since on character
857 terminals, the vertical line's x coordinate is right_x. */
858 if (!w
->pseudo_window_p
859 && !WINDOW_RIGHTMOST_P (w
)
860 && *x
> right_x
- ux
)
862 /* On the border on the right side of the window? Assume that
863 this area begins at RIGHT_X minus a canonical char width. */
864 *x
= min (right_x
, *x
) - left_x
;
866 return ON_VERTICAL_BORDER
;
872 if (lmargin_width
> 0
873 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
874 ? (*x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
875 : (*x
< left_x
+ lmargin_width
)))
878 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
879 *x
-= WINDOW_LEFT_FRINGE_WIDTH (w
);
881 return ON_LEFT_MARGIN
;
884 /* Convert X and Y to window-relative pixel coordinates. */
887 return ON_LEFT_FRINGE
;
890 if (*x
>= text_right
)
892 if (rmargin_width
> 0
893 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
894 ? (*x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
895 : (*x
>= right_x
- rmargin_width
)))
897 *x
-= right_x
- rmargin_width
;
898 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
899 *x
+= WINDOW_RIGHT_FRINGE_WIDTH (w
);
901 return ON_RIGHT_MARGIN
;
904 /* Convert X and Y to window-relative pixel coordinates. */
905 *x
-= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
);
907 return ON_RIGHT_FRINGE
;
910 /* Everything special ruled out - must be on text area */
917 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
918 Scoordinates_in_window_p
, 2, 2, 0,
919 doc
: /* Return non-nil if COORDINATES are in WINDOW.
920 COORDINATES is a cons of the form (X . Y), X and Y being distances
921 measured in characters from the upper-left corner of the frame.
922 \(0 . 0) denotes the character in the upper left corner of the
924 If COORDINATES are in the text portion of WINDOW,
925 the coordinates relative to the window are returned.
926 If they are in the mode line of WINDOW, `mode-line' is returned.
927 If they are in the top mode line of WINDOW, `header-line' is returned.
928 If they are in the left fringe of WINDOW, `left-fringe' is returned.
929 If they are in the right fringe of WINDOW, `right-fringe' is returned.
930 If they are on the border between WINDOW and its right sibling,
931 `vertical-line' is returned.
932 If they are in the windows's left or right marginal areas, `left-margin'\n\
933 or `right-margin' is returned. */)
934 (coordinates
, window
)
935 register Lisp_Object coordinates
, window
;
942 CHECK_WINDOW (window
);
943 w
= XWINDOW (window
);
944 f
= XFRAME (w
->frame
);
945 CHECK_CONS (coordinates
);
946 lx
= Fcar (coordinates
);
947 ly
= Fcdr (coordinates
);
948 CHECK_NUMBER_OR_FLOAT (lx
);
949 CHECK_NUMBER_OR_FLOAT (ly
);
950 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
951 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
953 switch (coordinates_in_window (w
, &x
, &y
))
959 /* X and Y are now window relative pixel coordinates. Convert
960 them to canonical char units before returning them. */
961 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
962 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
967 case ON_VERTICAL_BORDER
:
968 return Qvertical_line
;
976 case ON_RIGHT_FRINGE
:
977 return Qright_fringe
;
982 case ON_RIGHT_MARGIN
:
983 return Qright_margin
;
986 /* Historically we are supposed to return nil in this case. */
995 /* Callback for foreach_window, used in window_from_coordinates.
996 Check if window W contains coordinates specified by USER_DATA which
997 is actually a pointer to a struct check_window_data CW.
999 Check if window W contains coordinates *CW->x and *CW->y. If it
1000 does, return W in *CW->window, as Lisp_Object, and return in
1001 *CW->part the part of the window under coordinates *X,*Y. Return
1002 zero from this function to stop iterating over windows. */
1004 struct check_window_data
1006 Lisp_Object
*window
;
1008 enum window_part
*part
;
1012 check_window_containing (w
, user_data
)
1016 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
1017 enum window_part found
;
1020 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1021 if (found
!= ON_NOTHING
)
1024 XSETWINDOW (*cw
->window
, w
);
1032 /* Find the window containing frame-relative pixel position X/Y and
1033 return it as a Lisp_Object.
1035 If X, Y is on one of the window's special `window_part' elements,
1036 set *PART to the id of that element, and return X and Y converted
1037 to window relative coordinates in WX and WY.
1039 If there is no window under X, Y return nil and leave *PART
1040 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1042 This function was previously implemented with a loop cycling over
1043 windows with Fnext_window, and starting with the frame's selected
1044 window. It turned out that this doesn't work with an
1045 implementation of next_window using Vwindow_list, because
1046 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1047 tree of F when this function is called asynchronously from
1048 note_mouse_highlight. The original loop didn't terminate in this
1052 window_from_coordinates (f
, x
, y
, part
, wx
, wy
, tool_bar_p
)
1055 enum window_part
*part
;
1060 struct check_window_data cw
;
1061 enum window_part dummy
;
1067 cw
.window
= &window
, cw
.x
= &x
, cw
.y
= &y
; cw
.part
= part
;
1068 foreach_window (f
, check_window_containing
, &cw
);
1070 /* If not found above, see if it's in the tool bar window, if a tool
1074 && WINDOWP (f
->tool_bar_window
)
1075 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1076 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), &x
, &y
)
1080 window
= f
->tool_bar_window
;
1089 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1090 doc
: /* Return window containing coordinates X and Y on FRAME.
1091 If omitted, FRAME defaults to the currently selected frame.
1092 The top left corner of the frame is considered to be row 0,
1095 Lisp_Object x
, y
, frame
;
1100 frame
= selected_frame
;
1101 CHECK_LIVE_FRAME (frame
);
1104 /* Check that arguments are integers or floats. */
1105 CHECK_NUMBER_OR_FLOAT (x
);
1106 CHECK_NUMBER_OR_FLOAT (y
);
1108 return window_from_coordinates (f
,
1109 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1110 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1111 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1112 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1116 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1117 doc
: /* Return current value of point in WINDOW.
1118 WINDOW defaults to the selected window.
1120 For a nonselected window, this is the value point would have
1121 if that window were selected.
1123 Note that, when WINDOW is the selected window and its buffer
1124 is also currently selected, the value returned is the same as (point).
1125 It would be more strictly correct to return the `top-level' value
1126 of point, outside of any save-excursion forms.
1127 But that is hard to define. */)
1131 register struct window
*w
= decode_window (window
);
1133 if (w
== XWINDOW (selected_window
)
1134 && current_buffer
== XBUFFER (w
->buffer
))
1136 return Fmarker_position (w
->pointm
);
1139 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1140 doc
: /* Return position at which display currently starts in WINDOW.
1141 WINDOW defaults to the selected window.
1142 This is updated by redisplay or by calling `set-window-start'. */)
1146 return Fmarker_position (decode_window (window
)->start
);
1149 /* This is text temporarily removed from the doc string below.
1151 This function returns nil if the position is not currently known.
1152 That happens when redisplay is preempted and doesn't finish.
1153 If in that case you want to compute where the end of the window would
1154 have been if redisplay had finished, do this:
1156 (goto-char (window-start window))
1157 (vertical-motion (1- (window-height window)) window)
1160 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1161 doc
: /* Return position at which display currently ends in WINDOW.
1162 WINDOW defaults to the selected window.
1163 This is updated by redisplay, when it runs to completion.
1164 Simply changing the buffer text or setting `window-start'
1165 does not update this value.
1166 Return nil if there is no recorded value. \(This can happen if the
1167 last redisplay of WINDOW was preempted, and did not finish.)
1168 If UPDATE is non-nil, compute the up-to-date position
1169 if it isn't already recorded. */)
1171 Lisp_Object window
, update
;
1174 struct window
*w
= decode_window (window
);
1182 #if 0 /* This change broke some things. We should make it later. */
1183 /* If we don't know the end position, return nil.
1184 The user can compute it with vertical-motion if he wants to.
1185 It would be nicer to do it automatically,
1186 but that's so slow that it would probably bother people. */
1187 if (NILP (w
->window_end_valid
))
1192 && ! (! NILP (w
->window_end_valid
)
1193 && XFASTINT (w
->last_modified
) >= BUF_MODIFF (b
)
1194 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (b
))
1197 struct text_pos startp
;
1199 struct buffer
*old_buffer
= NULL
;
1201 /* Cannot use Fvertical_motion because that function doesn't
1202 cope with variable-height lines. */
1203 if (b
!= current_buffer
)
1205 old_buffer
= current_buffer
;
1206 set_buffer_internal (b
);
1209 /* In case W->start is out of the range, use something
1210 reasonable. This situation occurred when loading a file with
1211 `-l' containing a call to `rmail' with subsequent other
1212 commands. At the end, W->start happened to be BEG, while
1213 rmail had already narrowed the buffer. */
1214 if (XMARKER (w
->start
)->charpos
< BEGV
)
1215 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1216 else if (XMARKER (w
->start
)->charpos
> ZV
)
1217 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1219 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1221 start_display (&it
, w
, startp
);
1222 move_it_vertically (&it
, window_box_height (w
));
1223 if (it
.current_y
< it
.last_visible_y
)
1224 move_it_past_eol (&it
);
1225 value
= make_number (IT_CHARPOS (it
));
1228 set_buffer_internal (old_buffer
);
1231 XSETINT (value
, BUF_Z (b
) - XFASTINT (w
->window_end_pos
));
1236 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1237 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1240 Lisp_Object window
, pos
;
1242 register struct window
*w
= decode_window (window
);
1244 CHECK_NUMBER_COERCE_MARKER (pos
);
1245 if (w
== XWINDOW (selected_window
)
1246 && XBUFFER (w
->buffer
) == current_buffer
)
1249 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1251 /* We have to make sure that redisplay updates the window to show
1252 the new value of point. */
1253 if (!EQ (window
, selected_window
))
1254 ++windows_or_buffers_changed
;
1259 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1260 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1262 Optional third arg NOFORCE non-nil inhibits next redisplay
1263 from overriding motion of point in order to display at this exact start. */)
1264 (window
, pos
, noforce
)
1265 Lisp_Object window
, pos
, noforce
;
1267 register struct window
*w
= decode_window (window
);
1269 CHECK_NUMBER_COERCE_MARKER (pos
);
1270 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1271 /* this is not right, but much easier than doing what is right. */
1272 w
->start_at_line_beg
= Qnil
;
1274 w
->force_start
= Qt
;
1275 w
->update_mode_line
= Qt
;
1276 XSETFASTINT (w
->last_modified
, 0);
1277 XSETFASTINT (w
->last_overlay_modified
, 0);
1278 if (!EQ (window
, selected_window
))
1279 windows_or_buffers_changed
++;
1284 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1286 doc
: /* Return WINDOW's dedicated object, usually t or nil.
1287 See also `set-window-dedicated-p'. */)
1291 return decode_window (window
)->dedicated
;
1294 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1295 Sset_window_dedicated_p
, 2, 2, 0,
1296 doc
: /* Control whether WINDOW is dedicated to the buffer it displays.
1297 If it is dedicated, Emacs will not automatically change
1298 which buffer appears in it.
1299 The second argument is the new value for the dedication flag;
1300 non-nil means yes. */)
1302 Lisp_Object window
, arg
;
1304 register struct window
*w
= decode_window (window
);
1308 return w
->dedicated
;
1311 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1313 doc
: /* Return the display-table that WINDOW is using.
1314 WINDOW defaults to the selected window. */)
1318 return decode_window (window
)->display_table
;
1321 /* Get the display table for use on window W. This is either W's
1322 display table or W's buffer's display table. Ignore the specified
1323 tables if they are not valid; if no valid table is specified,
1326 struct Lisp_Char_Table
*
1327 window_display_table (w
)
1330 struct Lisp_Char_Table
*dp
= NULL
;
1332 if (DISP_TABLE_P (w
->display_table
))
1333 dp
= XCHAR_TABLE (w
->display_table
);
1334 else if (BUFFERP (w
->buffer
))
1336 struct buffer
*b
= XBUFFER (w
->buffer
);
1338 if (DISP_TABLE_P (b
->display_table
))
1339 dp
= XCHAR_TABLE (b
->display_table
);
1340 else if (DISP_TABLE_P (Vstandard_display_table
))
1341 dp
= XCHAR_TABLE (Vstandard_display_table
);
1347 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1348 doc
: /* Set WINDOW's display-table to TABLE. */)
1350 register Lisp_Object window
, table
;
1352 register struct window
*w
;
1354 w
= decode_window (window
);
1355 w
->display_table
= table
;
1359 /* Record info on buffer window w is displaying
1360 when it is about to cease to display that buffer. */
1363 register struct window
*w
;
1370 if (b
!= XMARKER (w
->pointm
)->buffer
)
1374 if (w
== XWINDOW (selected_window
)
1375 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1376 /* Do this except when the selected window's buffer
1377 is being removed from some other window. */
1379 /* last_window_start records the start position that this buffer
1380 had in the last window to be disconnected from it.
1381 Now that this statement is unconditional,
1382 it is possible for the buffer to be displayed in the
1383 selected window, while last_window_start reflects another
1384 window which was recently showing the same buffer.
1385 Some people might say that might be a good thing. Let's see. */
1386 b
->last_window_start
= marker_position (w
->start
);
1388 /* Point in the selected window's buffer
1389 is actually stored in that buffer, and the window's pointm isn't used.
1390 So don't clobber point in that buffer. */
1391 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1392 /* This line helps to fix Horsley's testbug.el bug. */
1393 && !(WINDOWP (b
->last_selected_window
)
1394 && w
!= XWINDOW (b
->last_selected_window
)
1395 && EQ (buf
, XWINDOW (b
->last_selected_window
)->buffer
)))
1396 temp_set_point_both (b
,
1397 clip_to_bounds (BUF_BEGV (b
),
1398 XMARKER (w
->pointm
)->charpos
,
1400 clip_to_bounds (BUF_BEGV_BYTE (b
),
1401 marker_byte_position (w
->pointm
),
1404 if (WINDOWP (b
->last_selected_window
)
1405 && w
== XWINDOW (b
->last_selected_window
))
1406 b
->last_selected_window
= Qnil
;
1409 /* Put replacement into the window structure in place of old. */
1411 replace_window (old
, replacement
)
1412 Lisp_Object old
, replacement
;
1414 register Lisp_Object tem
;
1415 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
1417 /* If OLD is its frame's root_window, then replacement is the new
1418 root_window for that frame. */
1420 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1421 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
1423 p
->left_col
= o
->left_col
;
1424 p
->top_line
= o
->top_line
;
1425 p
->total_cols
= o
->total_cols
;
1426 p
->total_lines
= o
->total_lines
;
1427 p
->desired_matrix
= p
->current_matrix
= 0;
1429 bzero (&p
->cursor
, sizeof (p
->cursor
));
1430 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
1431 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
1432 p
->phys_cursor_type
= -1;
1433 p
->phys_cursor_width
= -1;
1434 p
->must_be_updated_p
= 0;
1435 p
->pseudo_window_p
= 0;
1436 XSETFASTINT (p
->window_end_vpos
, 0);
1437 XSETFASTINT (p
->window_end_pos
, 0);
1438 p
->window_end_valid
= Qnil
;
1439 p
->frozen_window_start_p
= 0;
1440 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
1442 p
->next
= tem
= o
->next
;
1444 XWINDOW (tem
)->prev
= replacement
;
1446 p
->prev
= tem
= o
->prev
;
1448 XWINDOW (tem
)->next
= replacement
;
1450 p
->parent
= tem
= o
->parent
;
1453 if (EQ (XWINDOW (tem
)->vchild
, old
))
1454 XWINDOW (tem
)->vchild
= replacement
;
1455 if (EQ (XWINDOW (tem
)->hchild
, old
))
1456 XWINDOW (tem
)->hchild
= replacement
;
1459 /*** Here, if replacement is a vertical combination
1460 and so is its new parent, we should make replacement's
1461 children be children of that parent instead. ***/
1464 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
1465 doc
: /* Remove WINDOW from the display. Default is selected window. */)
1467 register Lisp_Object window
;
1469 delete_window (window
);
1471 if (! NILP (Vwindow_configuration_change_hook
)
1472 && ! NILP (Vrun_hooks
))
1473 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
1479 delete_window (window
)
1480 register Lisp_Object window
;
1482 register Lisp_Object tem
, parent
, sib
;
1483 register struct window
*p
;
1484 register struct window
*par
;
1487 /* Because this function is called by other C code on non-leaf
1488 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1489 so we can't decode_window here. */
1491 window
= selected_window
;
1493 CHECK_WINDOW (window
);
1494 p
= XWINDOW (window
);
1496 /* It's a no-op to delete an already-deleted window. */
1497 if (NILP (p
->buffer
)
1499 && NILP (p
->vchild
))
1504 error ("Attempt to delete minibuffer or sole ordinary window");
1505 par
= XWINDOW (parent
);
1507 windows_or_buffers_changed
++;
1508 Vwindow_list
= Qnil
;
1509 f
= XFRAME (WINDOW_FRAME (p
));
1510 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
1512 /* Are we trying to delete any frame's selected window? */
1514 Lisp_Object swindow
, pwindow
;
1516 /* See if the frame's selected window is either WINDOW
1517 or any subwindow of it, by finding all that window's parents
1518 and comparing each one with WINDOW. */
1519 swindow
= FRAME_SELECTED_WINDOW (f
);
1524 while (!NILP (pwindow
))
1526 if (EQ (window
, pwindow
))
1528 pwindow
= XWINDOW (pwindow
)->parent
;
1531 /* If the window being deleted is not a parent of SWINDOW,
1532 then SWINDOW is ok as the new selected window. */
1533 if (!EQ (window
, pwindow
))
1535 /* Otherwise, try another window for SWINDOW. */
1536 swindow
= Fnext_window (swindow
, Qlambda
, Qnil
);
1538 /* If we get back to the frame's selected window,
1539 it means there was no acceptable alternative,
1540 so we cannot delete. */
1541 if (EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1542 error ("Cannot delete window");
1545 /* If we need to change SWINDOW, do it. */
1546 if (! EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1548 /* If we're about to delete the selected window on the
1549 selected frame, then we should use Fselect_window to select
1550 the new window. On the other hand, if we're about to
1551 delete the selected window on any other frame, we shouldn't do
1552 anything but set the frame's selected_window slot. */
1553 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
1554 Fselect_window (swindow
, Qnil
);
1556 FRAME_SELECTED_WINDOW (f
) = swindow
;
1560 /* Now we know we can delete this one. */
1561 window_deletion_count
++;
1564 /* tem is null for dummy parent windows
1565 (which have inferiors but not any contents themselves) */
1569 unchain_marker (XMARKER (p
->pointm
));
1570 unchain_marker (XMARKER (p
->start
));
1573 /* Free window glyph matrices. It is sure that they are allocated
1574 again when ADJUST_GLYPHS is called. Block input so that expose
1575 events and other events that access glyph matrices are not
1576 processed while we are changing them. */
1578 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)));
1582 XWINDOW (tem
)->prev
= p
->prev
;
1586 XWINDOW (tem
)->next
= p
->next
;
1588 if (EQ (window
, par
->hchild
))
1589 par
->hchild
= p
->next
;
1590 if (EQ (window
, par
->vchild
))
1591 par
->vchild
= p
->next
;
1593 /* Find one of our siblings to give our space to. */
1597 /* If p gives its space to its next sibling, that sibling needs
1598 to have its top/left side pulled back to where p's is.
1599 set_window_{height,width} will re-position the sibling's
1602 XWINDOW (sib
)->top_line
= p
->top_line
;
1603 XWINDOW (sib
)->left_col
= p
->left_col
;
1606 /* Stretch that sibling. */
1607 if (!NILP (par
->vchild
))
1608 set_window_height (sib
,
1609 XFASTINT (XWINDOW (sib
)->total_lines
) + XFASTINT (p
->total_lines
),
1611 if (!NILP (par
->hchild
))
1612 set_window_width (sib
,
1613 XFASTINT (XWINDOW (sib
)->total_cols
) + XFASTINT (p
->total_cols
),
1616 /* If parent now has only one child,
1617 put the child into the parent's place. */
1621 if (NILP (XWINDOW (tem
)->next
)) {
1622 replace_window (parent
, tem
);
1623 par
= XWINDOW (tem
);
1626 /* Since we may be deleting combination windows, we must make sure that
1627 not only p but all its children have been marked as deleted. */
1628 if (! NILP (p
->hchild
))
1629 delete_all_subwindows (XWINDOW (p
->hchild
));
1630 else if (! NILP (p
->vchild
))
1631 delete_all_subwindows (XWINDOW (p
->vchild
));
1633 /* Mark this window as deleted. */
1634 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1636 if (! NILP (par
->parent
))
1637 par
= XWINDOW (par
->parent
);
1639 /* Check if we have a v/hchild with a v/hchild. In that case remove
1642 if (! NILP (par
->vchild
) && ! NILP (XWINDOW (par
->vchild
)->vchild
))
1644 p
= XWINDOW (par
->vchild
);
1645 par
->vchild
= p
->vchild
;
1648 else if (! NILP (par
->hchild
) && ! NILP (XWINDOW (par
->hchild
)->hchild
))
1650 p
= XWINDOW (par
->hchild
);
1651 par
->hchild
= p
->hchild
;
1659 while (! NILP (tem
)) {
1660 XWINDOW (tem
)->parent
= p
->parent
;
1661 if (NILP (XWINDOW (tem
)->next
))
1663 tem
= XWINDOW (tem
)->next
;
1666 /* The next of the v/hchild we are removing is now the next of the
1667 last child for the v/hchild:
1668 Before v/hchild -> v/hchild -> next1 -> next2
1671 After: v/hchild -> next1 -> next2 -> next3
1673 XWINDOW (tem
)->next
= p
->next
;
1674 if (! NILP (p
->next
))
1675 XWINDOW (p
->next
)->prev
= tem
;
1677 p
->next
= p
->prev
= p
->vchild
= p
->hchild
= p
->buffer
= Qnil
;
1681 /* Adjust glyph matrices. */
1688 /***********************************************************************
1690 ***********************************************************************/
1692 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1693 pointer. This is a callback function for foreach_window, used in
1694 function window_list. */
1697 add_window_to_list (w
, user_data
)
1701 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1703 XSETWINDOW (window
, w
);
1704 *list
= Fcons (window
, *list
);
1709 /* Return a list of all windows, for use by next_window. If
1710 Vwindow_list is a list, return that list. Otherwise, build a new
1711 list, cache it in Vwindow_list, and return that. */
1716 if (!CONSP (Vwindow_list
))
1720 Vwindow_list
= Qnil
;
1721 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1723 Lisp_Object args
[2];
1725 /* We are visiting windows in canonical order, and add
1726 new windows at the front of args[1], which means we
1727 have to reverse this list at the end. */
1729 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1730 args
[0] = Vwindow_list
;
1731 args
[1] = Fnreverse (args
[1]);
1732 Vwindow_list
= Fnconc (2, args
);
1736 return Vwindow_list
;
1740 /* Value is non-zero if WINDOW satisfies the constraints given by
1741 OWINDOW, MINIBUF and ALL_FRAMES.
1743 MINIBUF t means WINDOW may be minibuffer windows.
1744 `lambda' means WINDOW may not be a minibuffer window.
1745 a window means a specific minibuffer window
1747 ALL_FRAMES t means search all frames,
1748 nil means search just current frame,
1749 `visible' means search just visible frames,
1750 0 means search visible and iconified frames,
1751 a window means search the frame that window belongs to,
1752 a frame means consider windows on that frame, only. */
1755 candidate_window_p (window
, owindow
, minibuf
, all_frames
)
1756 Lisp_Object window
, owindow
, minibuf
, all_frames
;
1758 struct window
*w
= XWINDOW (window
);
1759 struct frame
*f
= XFRAME (w
->frame
);
1760 int candidate_p
= 1;
1762 if (!BUFFERP (w
->buffer
))
1764 else if (MINI_WINDOW_P (w
)
1765 && (EQ (minibuf
, Qlambda
)
1766 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
1768 /* If MINIBUF is `lambda' don't consider any mini-windows.
1769 If it is a window, consider only that one. */
1772 else if (EQ (all_frames
, Qt
))
1774 else if (NILP (all_frames
))
1776 xassert (WINDOWP (owindow
));
1777 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
1779 else if (EQ (all_frames
, Qvisible
))
1781 FRAME_SAMPLE_VISIBILITY (f
);
1782 candidate_p
= FRAME_VISIBLE_P (f
);
1784 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
1786 FRAME_SAMPLE_VISIBILITY (f
);
1787 candidate_p
= FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
);
1789 else if (WINDOWP (all_frames
))
1790 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
1791 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
1792 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
1793 else if (FRAMEP (all_frames
))
1794 candidate_p
= EQ (all_frames
, w
->frame
);
1800 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1801 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1805 decode_next_window_args (window
, minibuf
, all_frames
)
1806 Lisp_Object
*window
, *minibuf
, *all_frames
;
1809 *window
= selected_window
;
1811 CHECK_LIVE_WINDOW (*window
);
1813 /* MINIBUF nil may or may not include minibuffers. Decide if it
1815 if (NILP (*minibuf
))
1816 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
1817 else if (!EQ (*minibuf
, Qt
))
1820 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1821 => count none of them, or a specific minibuffer window (the
1822 active one) to count. */
1824 /* ALL_FRAMES nil doesn't specify which frames to include. */
1825 if (NILP (*all_frames
))
1826 *all_frames
= (!EQ (*minibuf
, Qlambda
)
1827 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
1829 else if (EQ (*all_frames
, Qvisible
))
1831 else if (EQ (*all_frames
, make_number (0)))
1833 else if (FRAMEP (*all_frames
))
1835 else if (!EQ (*all_frames
, Qt
))
1838 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1839 search just current frame, `visible' meaning search just visible
1840 frames, 0 meaning search visible and iconified frames, or a
1841 window, meaning search the frame that window belongs to, or a
1842 frame, meaning consider windows on that frame, only. */
1846 /* Return the next or previous window of WINDOW in canonical ordering
1847 of windows. NEXT_P non-zero means return the next window. See the
1848 documentation string of next-window for the meaning of MINIBUF and
1852 next_window (window
, minibuf
, all_frames
, next_p
)
1853 Lisp_Object window
, minibuf
, all_frames
;
1856 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1858 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1859 return the first window on the frame. */
1860 if (FRAMEP (all_frames
)
1861 && !EQ (all_frames
, XWINDOW (window
)->frame
))
1862 return Fframe_first_window (all_frames
);
1868 /* Find WINDOW in the list of all windows. */
1869 list
= Fmemq (window
, window_list ());
1871 /* Scan forward from WINDOW to the end of the window list. */
1873 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
1874 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1877 /* Scan from the start of the window list up to WINDOW. */
1879 for (list
= Vwindow_list
;
1880 CONSP (list
) && !EQ (XCAR (list
), window
);
1882 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1886 window
= XCAR (list
);
1890 Lisp_Object candidate
, list
;
1892 /* Scan through the list of windows for candidates. If there are
1893 candidate windows in front of WINDOW, the last one of these
1894 is the one we want. If there are candidates following WINDOW
1895 in the list, again the last one of these is the one we want. */
1897 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
1899 if (EQ (XCAR (list
), window
))
1901 if (WINDOWP (candidate
))
1904 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
1906 candidate
= XCAR (list
);
1909 if (WINDOWP (candidate
))
1917 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
1918 doc
: /* Return next window after WINDOW in canonical ordering of windows.
1919 If omitted, WINDOW defaults to the selected window.
1921 Optional second arg MINIBUF t means count the minibuffer window even
1922 if not active. MINIBUF nil or omitted means count the minibuffer iff
1923 it is active. MINIBUF neither t nor nil means not to count the
1924 minibuffer even if it is active.
1926 Several frames may share a single minibuffer; if the minibuffer
1927 counts, all windows on all frames that share that minibuffer count
1928 too. Therefore, `next-window' can be used to iterate through the
1929 set of windows even when the minibuffer is on another frame. If the
1930 minibuffer does not count, only windows from WINDOW's frame count.
1932 Optional third arg ALL-FRAMES t means include windows on all frames.
1933 ALL-FRAMES nil or omitted means cycle within the frames as specified
1934 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1935 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1936 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1937 Anything else means restrict to WINDOW's frame.
1939 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1940 `next-window' to iterate through the entire cycle of acceptable
1941 windows, eventually ending up back at the window you started with.
1942 `previous-window' traverses the same cycle, in the reverse order. */)
1943 (window
, minibuf
, all_frames
)
1944 Lisp_Object window
, minibuf
, all_frames
;
1946 return next_window (window
, minibuf
, all_frames
, 1);
1950 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1951 doc
: /* Return the window preceding WINDOW in canonical ordering of windows.
1952 If omitted, WINDOW defaults to the selected window.
1954 Optional second arg MINIBUF t means count the minibuffer window even
1955 if not active. MINIBUF nil or omitted means count the minibuffer iff
1956 it is active. MINIBUF neither t nor nil means not to count the
1957 minibuffer even if it is active.
1959 Several frames may share a single minibuffer; if the minibuffer
1960 counts, all windows on all frames that share that minibuffer count
1961 too. Therefore, `previous-window' can be used to iterate through
1962 the set of windows even when the minibuffer is on another frame. If
1963 the minibuffer does not count, only windows from WINDOW's frame count
1965 Optional third arg ALL-FRAMES t means include windows on all frames.
1966 ALL-FRAMES nil or omitted means cycle within the frames as specified
1967 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1968 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1969 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1970 Anything else means restrict to WINDOW's frame.
1972 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1973 `previous-window' to iterate through the entire cycle of acceptable
1974 windows, eventually ending up back at the window you started with.
1975 `next-window' traverses the same cycle, in the reverse order. */)
1976 (window
, minibuf
, all_frames
)
1977 Lisp_Object window
, minibuf
, all_frames
;
1979 return next_window (window
, minibuf
, all_frames
, 0);
1983 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1984 doc
: /* Select the ARG'th different window on this frame.
1985 All windows on current frame are arranged in a cyclic order.
1986 This command selects the window ARG steps away in that order.
1987 A negative ARG moves in the opposite order. The optional second
1988 argument ALL-FRAMES has the same meaning as in `next-window', which see. */)
1990 Lisp_Object arg
, all_frames
;
1996 window
= selected_window
;
1998 for (i
= XINT (arg
); i
> 0; --i
)
1999 window
= Fnext_window (window
, Qnil
, all_frames
);
2001 window
= Fprevious_window (window
, Qnil
, all_frames
);
2003 Fselect_window (window
, Qnil
);
2008 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2009 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2010 FRAME nil or omitted means use the selected frame.
2011 WINDOW nil or omitted means use the selected window.
2012 MINIBUF t means include the minibuffer window, even if it isn't active.
2013 MINIBUF nil or omitted means include the minibuffer window only
2015 MINIBUF neither nil nor t means never include the minibuffer window. */)
2016 (frame
, minibuf
, window
)
2017 Lisp_Object frame
, minibuf
, window
;
2020 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2021 CHECK_WINDOW (window
);
2023 frame
= selected_frame
;
2025 if (!EQ (frame
, XWINDOW (window
)->frame
))
2026 error ("Window is on a different frame");
2028 return window_list_1 (window
, minibuf
, frame
);
2032 /* Return a list of windows in canonical ordering. Arguments are like
2033 for `next-window'. */
2036 window_list_1 (window
, minibuf
, all_frames
)
2037 Lisp_Object window
, minibuf
, all_frames
;
2039 Lisp_Object tail
, list
, rest
;
2041 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2044 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2045 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2046 list
= Fcons (XCAR (tail
), list
);
2048 /* Rotate the list to start with WINDOW. */
2049 list
= Fnreverse (list
);
2050 rest
= Fmemq (window
, list
);
2051 if (!NILP (rest
) && !EQ (rest
, list
))
2053 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2055 XSETCDR (tail
, Qnil
);
2056 list
= nconc2 (rest
, list
);
2063 /* Look at all windows, performing an operation specified by TYPE
2065 If FRAMES is Qt, look at all frames;
2066 Qnil, look at just the selected frame;
2067 Qvisible, look at visible frames;
2068 a frame, just look at windows on that frame.
2069 If MINI is non-zero, perform the operation on minibuffer windows too. */
2074 GET_BUFFER_WINDOW
, /* Arg is buffer */
2075 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
2076 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
2077 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
2079 UNSHOW_BUFFER
, /* Arg is buffer */
2080 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2085 window_loop (type
, obj
, mini
, frames
)
2086 enum window_loop type
;
2087 Lisp_Object obj
, frames
;
2090 Lisp_Object window
, windows
, best_window
, frame_arg
;
2092 struct gcpro gcpro1
;
2094 /* If we're only looping through windows on a particular frame,
2095 frame points to that frame. If we're looping through windows
2096 on all frames, frame is 0. */
2097 if (FRAMEP (frames
))
2098 f
= XFRAME (frames
);
2099 else if (NILP (frames
))
2100 f
= SELECTED_FRAME ();
2105 frame_arg
= Qlambda
;
2106 else if (EQ (frames
, make_number (0)))
2108 else if (EQ (frames
, Qvisible
))
2113 /* frame_arg is Qlambda to stick to one frame,
2114 Qvisible to consider all visible frames,
2117 /* Pick a window to start with. */
2121 window
= FRAME_SELECTED_WINDOW (f
);
2123 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2125 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2129 for (; CONSP (windows
); windows
= XCDR (windows
))
2133 window
= XCAR (windows
);
2134 w
= XWINDOW (window
);
2136 /* Note that we do not pay attention here to whether the frame
2137 is visible, since Fwindow_list skips non-visible frames if
2138 that is desired, under the control of frame_arg. */
2139 if (!MINI_WINDOW_P (w
)
2140 /* For UNSHOW_BUFFER, we must always consider all windows. */
2141 || type
== UNSHOW_BUFFER
2142 || (mini
&& minibuf_level
> 0))
2145 case GET_BUFFER_WINDOW
:
2146 if (EQ (w
->buffer
, obj
)
2147 /* Don't find any minibuffer window
2148 except the one that is currently in use. */
2149 && (MINI_WINDOW_P (w
)
2150 ? EQ (window
, minibuf_window
)
2153 if (NILP (best_window
))
2154 best_window
= window
;
2155 else if (EQ (window
, selected_window
))
2156 /* For compatibility with 20.x, prefer to return
2158 best_window
= window
;
2162 case GET_LRU_WINDOW
:
2163 /* `obj' is an integer encoding a bitvector.
2164 `obj & 1' means consider only full-width windows.
2165 `obj & 2' means consider also dedicated windows. */
2166 if (((XINT (obj
) & 1) && !WINDOW_FULL_WIDTH_P (w
))
2167 || (!(XINT (obj
) & 2) && !NILP (w
->dedicated
))
2168 /* Minibuffer windows are always ignored. */
2169 || MINI_WINDOW_P (w
))
2171 if (NILP (best_window
)
2172 || (XFASTINT (XWINDOW (best_window
)->use_time
)
2173 > XFASTINT (w
->use_time
)))
2174 best_window
= window
;
2177 case DELETE_OTHER_WINDOWS
:
2178 if (!EQ (window
, obj
))
2179 Fdelete_window (window
);
2182 case DELETE_BUFFER_WINDOWS
:
2183 if (EQ (w
->buffer
, obj
))
2185 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2187 /* If this window is dedicated, and in a frame of its own,
2189 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
2190 && !NILP (w
->dedicated
)
2191 && other_visible_frames (f
))
2193 /* Skip the other windows on this frame.
2194 There might be one, the minibuffer! */
2195 while (CONSP (XCDR (windows
))
2196 && EQ (XWINDOW (XCAR (windows
))->frame
,
2197 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2198 windows
= XCDR (windows
);
2200 /* Now we can safely delete the frame. */
2201 Fdelete_frame (w
->frame
, Qnil
);
2203 else if (NILP (w
->parent
))
2205 /* If we're deleting the buffer displayed in the
2206 only window on the frame, find a new buffer to
2209 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2210 Fset_window_buffer (window
, buffer
, Qnil
);
2211 if (EQ (window
, selected_window
))
2212 Fset_buffer (w
->buffer
);
2215 Fdelete_window (window
);
2219 case GET_LARGEST_WINDOW
:
2220 { /* nil `obj' means to ignore dedicated windows. */
2221 /* Ignore dedicated windows and minibuffers. */
2222 if (MINI_WINDOW_P (w
) || (NILP (obj
) && !NILP (w
->dedicated
)))
2225 if (NILP (best_window
))
2226 best_window
= window
;
2229 struct window
*b
= XWINDOW (best_window
);
2230 if (XFASTINT (w
->total_lines
) * XFASTINT (w
->total_cols
)
2231 > XFASTINT (b
->total_lines
) * XFASTINT (b
->total_cols
))
2232 best_window
= window
;
2238 if (EQ (w
->buffer
, obj
))
2241 struct frame
*f
= XFRAME (w
->frame
);
2243 /* Find another buffer to show in this window. */
2244 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2246 /* If this window is dedicated, and in a frame of its own,
2248 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
2249 && !NILP (w
->dedicated
)
2250 && other_visible_frames (f
))
2252 /* Skip the other windows on this frame.
2253 There might be one, the minibuffer! */
2254 while (CONSP (XCDR (windows
))
2255 && EQ (XWINDOW (XCAR (windows
))->frame
,
2256 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2257 windows
= XCDR (windows
);
2259 /* Now we can safely delete the frame. */
2260 Fdelete_frame (w
->frame
, Qnil
);
2262 else if (!NILP (w
->dedicated
) && !NILP (w
->parent
))
2265 XSETWINDOW (window
, w
);
2266 /* If this window is dedicated and not the only window
2267 in its frame, then kill it. */
2268 Fdelete_window (window
);
2272 /* Otherwise show a different buffer in the window. */
2273 w
->dedicated
= Qnil
;
2274 Fset_window_buffer (window
, buffer
, Qnil
);
2275 if (EQ (window
, selected_window
))
2276 Fset_buffer (w
->buffer
);
2281 case REDISPLAY_BUFFER_WINDOWS
:
2282 if (EQ (w
->buffer
, obj
))
2284 mark_window_display_accurate (window
, 0);
2285 w
->update_mode_line
= Qt
;
2286 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2287 ++update_mode_lines
;
2288 best_window
= window
;
2292 /* Check for a window that has a killed buffer. */
2293 case CHECK_ALL_WINDOWS
:
2294 if (! NILP (w
->buffer
)
2295 && NILP (XBUFFER (w
->buffer
)->name
))
2299 case WINDOW_LOOP_UNUSED
:
2308 /* Used for debugging. Abort if any window has a dead buffer. */
2311 check_all_windows ()
2313 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2316 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 2, 0,
2317 doc
: /* Return the window least recently selected or used for display.
2318 \(LRU means Least Recently Used.)
2320 Return a full-width window if possible.
2321 A minibuffer window is never a candidate.
2322 A dedicated window is never a candidate, unless DEDICATED is non-nil,
2323 so if all windows are dedicated, the value is nil.
2324 If optional argument FRAME is `visible', search all visible frames.
2325 If FRAME is 0, search all visible and iconified frames.
2326 If FRAME is t, search all frames.
2327 If FRAME is nil, search only the selected frame.
2328 If FRAME is a frame, search only that frame. */)
2330 Lisp_Object frame
, dedicated
;
2332 register Lisp_Object w
;
2333 /* First try for a window that is full-width */
2334 w
= window_loop (GET_LRU_WINDOW
,
2335 NILP (dedicated
) ? make_number (1) : make_number (3),
2337 if (!NILP (w
) && !EQ (w
, selected_window
))
2339 /* If none of them, try the rest */
2340 return window_loop (GET_LRU_WINDOW
,
2341 NILP (dedicated
) ? make_number (0) : make_number (2),
2345 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 2, 0,
2346 doc
: /* Return the largest window in area.
2347 A minibuffer window is never a candidate.
2348 A dedicated window is never a candidate unless DEDICATED is non-nil,
2349 so if all windows are dedicated, the value is nil.
2350 If optional argument FRAME is `visible', search all visible frames.
2351 If FRAME is 0, search all visible and iconified frames.
2352 If FRAME is t, search all frames.
2353 If FRAME is nil, search only the selected frame.
2354 If FRAME is a frame, search only that frame. */)
2356 Lisp_Object frame
, dedicated
;
2358 return window_loop (GET_LARGEST_WINDOW
, dedicated
, 0,
2362 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
2363 doc
: /* Return a window currently displaying BUFFER, or nil if none.
2364 BUFFER can be a buffer or a buffer name.
2365 If optional argument FRAME is `visible', search all visible frames.
2366 If optional argument FRAME is 0, search all visible and iconified frames.
2367 If FRAME is t, search all frames.
2368 If FRAME is nil, search only the selected frame.
2369 If FRAME is a frame, search only that frame. */)
2371 Lisp_Object buffer
, frame
;
2373 buffer
= Fget_buffer (buffer
);
2374 if (BUFFERP (buffer
))
2375 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
2380 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
2382 doc
: /* Make WINDOW (or the selected window) fill its frame.
2383 Only the frame WINDOW is on is affected.
2384 This function tries to reduce display jumps
2385 by keeping the text previously visible in WINDOW
2386 in the same place on the frame. Doing this depends on
2387 the value of (window-start WINDOW), so if calling this function
2388 in a program gives strange scrolling, make sure the window-start
2389 value is reasonable when this function is called. */)
2398 window
= selected_window
;
2400 CHECK_LIVE_WINDOW (window
);
2401 w
= XWINDOW (window
);
2403 startpos
= marker_position (w
->start
);
2404 top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2406 if (MINI_WINDOW_P (w
) && top
> 0)
2407 error ("Can't expand minibuffer to full frame");
2409 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
2411 /* Try to minimize scrolling, by setting the window start to the point
2412 will cause the text at the old window start to be at the same place
2413 on the frame. But don't try to do this if the window start is
2414 outside the visible portion (as might happen when the display is
2415 not current, due to typeahead). */
2416 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2418 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2419 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2421 struct position pos
;
2422 struct buffer
*obuf
= current_buffer
;
2424 Fset_buffer (w
->buffer
);
2425 /* This computation used to temporarily move point, but that can
2426 have unwanted side effects due to text properties. */
2427 pos
= *vmotion (startpos
, -top
, w
);
2429 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2430 w
->window_end_valid
= Qnil
;
2431 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
2432 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
2434 /* We need to do this, so that the window-scroll-functions
2436 w
->optional_new_start
= Qt
;
2438 set_buffer_internal (obuf
);
2444 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
2445 1, 2, "bDelete windows on (buffer): ",
2446 doc
: /* Delete all windows showing BUFFER.
2447 BUFFER must be a buffer or the name of an existing buffer.
2448 Optional second argument FRAME controls which frames are affected.
2449 If optional argument FRAME is `visible', search all visible frames.
2450 If FRAME is 0, search all visible and iconified frames.
2451 If FRAME is nil, search all frames.
2452 If FRAME is t, search only the selected frame.
2453 If FRAME is a frame, search only that frame. */)
2455 Lisp_Object buffer
, frame
;
2457 /* FRAME uses t and nil to mean the opposite of what window_loop
2461 else if (EQ (frame
, Qt
))
2466 buffer
= Fget_buffer (buffer
);
2467 CHECK_BUFFER (buffer
);
2468 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
2474 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
2475 Sreplace_buffer_in_windows
,
2476 1, 1, "bReplace buffer in windows: ",
2477 doc
: /* Replace BUFFER with some other buffer in all windows showing it.
2478 BUFFER may be a buffer or the name of an existing buffer. */)
2484 buffer
= Fget_buffer (buffer
);
2485 CHECK_BUFFER (buffer
);
2486 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
2491 /* Replace BUFFER with some other buffer in all windows
2492 of all frames, even those on other keyboards. */
2495 replace_buffer_in_all_windows (buffer
)
2499 Lisp_Object tail
, frame
;
2501 /* A single call to window_loop won't do the job
2502 because it only considers frames on the current keyboard.
2503 So loop manually over frames, and handle each one. */
2504 FOR_EACH_FRAME (tail
, frame
)
2505 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
2507 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
2511 /* Set the height of WINDOW and all its inferiors. */
2513 /* The smallest acceptable dimensions for a window. Anything smaller
2514 might crash Emacs. */
2516 #define MIN_SAFE_WINDOW_WIDTH (2)
2517 #define MIN_SAFE_WINDOW_HEIGHT (1)
2519 /* Make sure that window_min_height and window_min_width are
2520 not too small; if they are, set them to safe minima. */
2523 check_min_window_sizes ()
2525 /* Smaller values might permit a crash. */
2526 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
2527 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
2528 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
2529 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
2532 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2533 minimum allowable size. */
2536 check_frame_size (frame
, rows
, cols
)
2540 /* For height, we have to see:
2541 how many windows the frame has at minimum (one or two),
2542 and whether it has a menu bar or other special stuff at the top. */
2544 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
2545 ? MIN_SAFE_WINDOW_HEIGHT
2546 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
2548 if (FRAME_TOP_MARGIN (frame
) > 0)
2549 min_height
+= FRAME_TOP_MARGIN (frame
);
2551 if (*rows
< min_height
)
2553 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2554 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2557 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2558 check if W's width can be changed, otherwise check W's height.
2559 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2560 siblings, too. If none of the siblings is resizable, WINDOW isn't
2564 window_fixed_size_p (w
, width_p
, check_siblings_p
)
2566 int width_p
, check_siblings_p
;
2571 if (!NILP (w
->hchild
))
2573 c
= XWINDOW (w
->hchild
);
2577 /* A horiz. combination is fixed-width if all of if its
2579 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2580 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2581 fixed_p
= c
== NULL
;
2585 /* A horiz. combination is fixed-height if one of if its
2587 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2588 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2589 fixed_p
= c
!= NULL
;
2592 else if (!NILP (w
->vchild
))
2594 c
= XWINDOW (w
->vchild
);
2598 /* A vert. combination is fixed-width if one of if its
2600 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2601 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2602 fixed_p
= c
!= NULL
;
2606 /* A vert. combination is fixed-height if all of if its
2608 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2609 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2610 fixed_p
= c
== NULL
;
2613 else if (BUFFERP (w
->buffer
))
2615 struct buffer
*old
= current_buffer
;
2618 current_buffer
= XBUFFER (w
->buffer
);
2619 val
= find_symbol_value (Qwindow_size_fixed
);
2620 current_buffer
= old
;
2623 if (!EQ (val
, Qunbound
))
2625 fixed_p
= !NILP (val
);
2628 && ((EQ (val
, Qheight
) && width_p
)
2629 || (EQ (val
, Qwidth
) && !width_p
)))
2633 /* Can't tell if this one is resizable without looking at
2634 siblings. If all siblings are fixed-size this one is too. */
2635 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
2639 for (child
= w
->prev
; !NILP (child
); child
= XWINDOW (child
)->prev
)
2640 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2644 for (child
= w
->next
; !NILP (child
); child
= XWINDOW (child
)->next
)
2645 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2658 /* Return the minimum size for leaf window W. WIDTH_P non-zero means
2659 take into account fringes and the scrollbar of W. WIDTH_P zero
2660 means take into account mode-line and header-line of W. Return 1
2661 for the minibuffer. */
2664 window_min_size_2 (w
, width_p
)
2671 size
= max (window_min_width
,
2672 (MIN_SAFE_WINDOW_WIDTH
2673 + WINDOW_FRINGE_COLS (w
)
2674 + WINDOW_SCROLL_BAR_COLS (w
)));
2675 else if (MINI_WINDOW_P (w
))
2678 size
= max (window_min_height
,
2679 (MIN_SAFE_WINDOW_HEIGHT
2680 + (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)
2681 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 )));
2686 /* Return the minimum size of window W, not taking fixed-width windows
2687 into account. WIDTH_P non-zero means return the minimum width,
2688 otherwise return the minimum height. If W is a combination window,
2689 compute the minimum size from the minimum sizes of W's children. */
2692 window_min_size_1 (w
, width_p
)
2699 if (!NILP (w
->hchild
))
2701 c
= XWINDOW (w
->hchild
);
2706 /* The min width of a horizontal combination is
2707 the sum of the min widths of its children. */
2710 size
+= window_min_size_1 (c
, width_p
);
2711 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2716 /* The min height a horizontal combination equals
2717 the maximum of all min height of its children. */
2720 int min_size
= window_min_size_1 (c
, width_p
);
2721 size
= max (min_size
, size
);
2722 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2726 else if (!NILP (w
->vchild
))
2728 c
= XWINDOW (w
->vchild
);
2733 /* The min width of a vertical combination is
2734 the maximum of the min widths of its children. */
2737 int min_size
= window_min_size_1 (c
, width_p
);
2738 size
= max (min_size
, size
);
2739 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2744 /* The min height of a vertical combination equals
2745 the sum of the min height of its children. */
2748 size
+= window_min_size_1 (c
, width_p
);
2749 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2754 size
= window_min_size_2 (w
, width_p
);
2760 /* Return the minimum size of window W, taking fixed-size windows into
2761 account. WIDTH_P non-zero means return the minimum width,
2762 otherwise return the minimum height. IGNORE_FIXED_P non-zero means
2763 ignore if W is fixed-size. Set *FIXED to 1 if W is fixed-size
2764 unless FIXED is null. */
2767 window_min_size (w
, width_p
, ignore_fixed_p
, fixed
)
2769 int width_p
, ignore_fixed_p
, *fixed
;
2776 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
2782 size
= width_p
? XFASTINT (w
->total_cols
) : XFASTINT (w
->total_lines
);
2784 size
= window_min_size_1 (w
, width_p
);
2790 /* Adjust the margins of window W if text area is too small.
2791 Return 1 if window width is ok after adjustment; 0 if window
2792 is still too narrow. */
2795 adjust_window_margins (w
)
2798 int box_cols
= (WINDOW_TOTAL_COLS (w
)
2799 - WINDOW_FRINGE_COLS (w
)
2800 - WINDOW_SCROLL_BAR_COLS (w
));
2801 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
2802 + WINDOW_RIGHT_MARGIN_COLS (w
));
2804 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
2807 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
2810 /* Window's text area is too narrow, but reducing the window
2811 margins will fix that. */
2812 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
2813 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
2815 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
2816 w
->left_margin_cols
= w
->right_margin_cols
2817 = make_number (margin_cols
/2);
2819 w
->right_margin_cols
= make_number (margin_cols
);
2822 w
->left_margin_cols
= make_number (margin_cols
);
2826 /* Calculate new sizes for windows in the list FORWARD when the window size
2827 goes from TOTAL to SIZE. TOTAL must be greater than SIZE.
2828 The number of windows in FORWARD is NCHILDREN, and the number that
2829 can shrink is SHRINKABLE.
2830 The minimum size a window can have is MIN_SIZE.
2831 If we are shrinking fixed windows, RESIZE_FIXED_P is non-zero.
2832 If we are shrinking columns, WIDTH_P is non-zero, otherwise we are
2835 This function returns an allocated array of new sizes that the caller
2836 must free. The size -1 means the window is fixed and RESIZE_FIXED_P
2837 is zero. Array index 0 refers to the first window in FORWARD, 1 to
2838 the second, and so on.
2840 This function tries to keep windows at least at the minimum size
2841 and resize other windows before it resizes any window to zero (i.e.
2842 delete that window).
2844 Windows are resized proportional to their size, so bigger windows
2845 shrink more than smaller windows. */
2847 shrink_windows (total
, size
, nchildren
, shrinkable
,
2848 min_size
, resize_fixed_p
, forward
, width_p
)
2849 int total
, size
, nchildren
, shrinkable
, min_size
;
2850 int resize_fixed_p
, width_p
;
2851 Lisp_Object forward
;
2853 int available_resize
= 0;
2857 int smallest
= total
;
2858 int total_removed
= 0;
2859 int total_shrink
= total
- size
;
2862 new_sizes
= xmalloc (sizeof (*new_sizes
) * nchildren
);
2864 for (i
= 0, child
= forward
; !NILP (child
); child
= c
->next
, ++i
)
2868 c
= XWINDOW (child
);
2869 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2871 if (! resize_fixed_p
&& window_fixed_size_p (c
, width_p
, 0))
2875 new_sizes
[i
] = child_size
;
2876 if (child_size
> min_size
)
2877 available_resize
+= child_size
- min_size
;
2880 /* We might need to shrink some windows to zero. Find the smallest
2881 windows and set them to 0 until we can fulfil the new size. */
2883 while (shrinkable
> 1 && size
+ available_resize
< total
)
2885 for (i
= 0; i
< nchildren
; ++i
)
2886 if (new_sizes
[i
] > 0 && smallest
> new_sizes
[i
])
2887 smallest
= new_sizes
[i
];
2889 for (i
= 0; i
< nchildren
; ++i
)
2890 if (new_sizes
[i
] == smallest
)
2892 /* Resize this window down to zero. */
2894 if (smallest
> min_size
)
2895 available_resize
-= smallest
- min_size
;
2896 available_resize
+= smallest
;
2898 total_removed
+= smallest
;
2900 /* We don't know what the smallest is now. */
2903 /* Out of for, just remove one window at the time and
2904 check again if we have enough space. */
2909 /* Now, calculate the new sizes. Try to shrink each window
2910 proportional to its size. */
2911 for (i
= 0; i
< nchildren
; ++i
)
2913 if (new_sizes
[i
] > min_size
)
2915 int to_shrink
= total_shrink
*new_sizes
[i
]/total
;
2916 if (new_sizes
[i
] - to_shrink
< min_size
)
2917 to_shrink
= new_sizes
[i
] - min_size
;
2918 new_sizes
[i
] -= to_shrink
;
2919 total_removed
+= to_shrink
;
2923 /* Any reminder due to rounding, we just subtract from windows
2924 that are left and still can be shrunk. */
2925 while (total_shrink
> total_removed
)
2927 int nonzero_sizes
= 0;
2928 int nonzero_idx
= -1;
2930 for (i
= 0; i
< nchildren
; ++i
)
2931 if (new_sizes
[i
] > 0)
2937 for (i
= 0; i
< nchildren
; ++i
)
2938 if (new_sizes
[i
] > min_size
)
2943 /* Out of for, just shrink one window at the time and
2944 check again if we have enough space. */
2949 /* Special case, only one window left. */
2950 if (nonzero_sizes
== 1)
2954 /* Any surplus due to rounding, we add to windows that are left. */
2955 while (total_shrink
< total_removed
)
2957 for (i
= 0; i
< nchildren
; ++i
)
2959 if (new_sizes
[i
] != 0 && total_shrink
< total_removed
)
2971 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
2972 WINDOW's width. Resize WINDOW's children, if any, so that they
2973 keep their proportionate size relative to WINDOW.
2975 If FIRST_ONLY is 1, change only the first of WINDOW's children when
2976 they are in series. If LAST_ONLY is 1, change only the last of
2977 WINDOW's children when they are in series.
2979 Propagate WINDOW's top or left edge position to children. Delete
2980 windows that become too small unless NODELETE_P is non-zero.
2982 If NODELETE_P is 2, that means we do delete windows that are
2983 too small, even if they were too small before! */
2986 size_window (window
, size
, width_p
, nodelete_p
, first_only
, last_only
)
2988 int size
, width_p
, nodelete_p
;
2989 int first_only
, last_only
;
2991 struct window
*w
= XWINDOW (window
);
2993 Lisp_Object child
, *forward
, *sideward
;
2994 int old_size
, min_size
, safe_min_size
;
2996 check_min_window_sizes ();
2997 size
= max (0, size
);
2999 /* If the window has been "too small" at one point,
3000 don't delete it for being "too small" in the future.
3001 Preserve it as long as that is at all possible. */
3004 old_size
= WINDOW_TOTAL_COLS (w
);
3005 min_size
= window_min_width
;
3006 safe_min_size
= window_min_size_2 (w
, 1);
3010 old_size
= XINT (w
->total_lines
);
3011 min_size
= window_min_height
;
3012 safe_min_size
= window_min_size_2 (w
, 0);
3015 if (old_size
< min_size
&& nodelete_p
!= 2)
3016 w
->too_small_ok
= Qt
;
3018 /* Move the following test here since otherwise the
3019 preceding test doesn't make sense. martin. */
3020 if (nodelete_p
== 2)
3023 /* Maybe delete WINDOW if it's too small. */
3024 if (nodelete_p
!= 1 && !NILP (w
->parent
))
3026 if (!MINI_WINDOW_P (w
) && !NILP (w
->too_small_ok
))
3027 min_size
= width_p
? MIN_SAFE_WINDOW_WIDTH
: MIN_SAFE_WINDOW_HEIGHT
;
3028 if (min_size
< safe_min_size
)
3029 min_size
= safe_min_size
;
3030 if (size
< min_size
)
3032 delete_window (window
);
3037 /* Set redisplay hints. */
3038 w
->last_modified
= make_number (0);
3039 w
->last_overlay_modified
= make_number (0);
3040 windows_or_buffers_changed
++;
3041 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w
->frame
)) = 1;
3045 sideward
= &w
->vchild
;
3046 forward
= &w
->hchild
;
3047 w
->total_cols
= make_number (size
);
3048 adjust_window_margins (w
);
3052 sideward
= &w
->hchild
;
3053 forward
= &w
->vchild
;
3054 w
->total_lines
= make_number (size
);
3055 w
->orig_total_lines
= Qnil
;
3058 if (!NILP (*sideward
))
3060 /* We have a chain of parallel siblings whose size should all change. */
3061 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
3063 c
= XWINDOW (child
);
3065 c
->left_col
= w
->left_col
;
3067 c
->top_line
= w
->top_line
;
3068 size_window (child
, size
, width_p
, nodelete_p
,
3069 first_only
, last_only
);
3072 else if (!NILP (*forward
) && last_only
)
3074 /* Change the last in a series of siblings. */
3075 Lisp_Object last_child
;
3078 for (child
= *forward
; !NILP (child
); child
= c
->next
)
3080 c
= XWINDOW (child
);
3084 child_size
= XINT (width_p
? c
->total_cols
: c
->total_lines
);
3085 size_window (last_child
,
3086 size
- old_size
+ child_size
,
3087 width_p
, nodelete_p
, first_only
, last_only
);
3089 else if (!NILP (*forward
) && first_only
)
3091 /* Change the first in a series of siblings. */
3095 c
= XWINDOW (child
);
3098 c
->left_col
= w
->left_col
;
3100 c
->top_line
= w
->top_line
;
3102 child_size
= XINT (width_p
? c
->total_cols
: c
->total_lines
);
3104 size
- old_size
+ child_size
,
3105 width_p
, nodelete_p
, first_only
, last_only
);
3107 else if (!NILP (*forward
))
3109 int fixed_size
, each
, extra
, n
;
3110 int resize_fixed_p
, nfixed
;
3111 int last_pos
, first_pos
, nchildren
, total
;
3112 int *new_sizes
= NULL
;
3114 /* Determine the fixed-size portion of this window, and the
3115 number of child windows. */
3116 fixed_size
= nchildren
= nfixed
= total
= 0;
3117 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
3121 c
= XWINDOW (child
);
3122 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
3123 total
+= child_size
;
3125 if (window_fixed_size_p (c
, width_p
, 0))
3127 fixed_size
+= child_size
;
3132 /* If the new size is smaller than fixed_size, or if there
3133 aren't any resizable windows, allow resizing fixed-size
3135 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
3137 /* Compute how many lines/columns to add/remove to each child. The
3138 value of extra takes care of rounding errors. */
3139 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
3140 if (size
< total
&& n
> 1)
3141 new_sizes
= shrink_windows (total
, size
, nchildren
, n
, min_size
,
3142 resize_fixed_p
, *forward
, width_p
);
3145 each
= (size
- total
) / n
;
3146 extra
= (size
- total
) - n
* each
;
3149 /* Compute new children heights and edge positions. */
3150 first_pos
= width_p
? XINT (w
->left_col
) : XINT (w
->top_line
);
3151 last_pos
= first_pos
;
3152 for (n
= 0, child
= *forward
; !NILP (child
); child
= c
->next
, ++n
)
3154 int new_size
, old_size
;
3156 c
= XWINDOW (child
);
3157 old_size
= width_p
? XFASTINT (c
->total_cols
) : XFASTINT (c
->total_lines
);
3158 new_size
= old_size
;
3160 /* The top or left edge position of this child equals the
3161 bottom or right edge of its predecessor. */
3163 c
->left_col
= make_number (last_pos
);
3165 c
->top_line
= make_number (last_pos
);
3167 /* If this child can be resized, do it. */
3168 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
3170 new_size
= new_sizes
? new_sizes
[n
] : old_size
+ each
+ extra
;
3174 /* Set new height. Note that size_window also propagates
3175 edge positions to children, so it's not a no-op if we
3176 didn't change the child's size. */
3177 size_window (child
, new_size
, width_p
, 1, first_only
, last_only
);
3179 /* Remember the bottom/right edge position of this child; it
3180 will be used to set the top/left edge of the next child. */
3181 last_pos
+= new_size
;
3184 if (new_sizes
) xfree (new_sizes
);
3186 /* We should have covered the parent exactly with child windows. */
3187 xassert (size
== last_pos
- first_pos
);
3189 /* Now delete any children that became too small. */
3191 for (child
= *forward
; !NILP (child
); child
= c
->next
)
3194 c
= XWINDOW (child
);
3195 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
3196 size_window (child
, child_size
, width_p
, 2, first_only
, last_only
);
3201 /* Set WINDOW's height to HEIGHT, and recursively change the height of
3202 WINDOW's children. NODELETE non-zero means don't delete windows
3203 that become too small in the process. (The caller should check
3204 later and do so if appropriate.) */
3207 set_window_height (window
, height
, nodelete
)
3212 size_window (window
, height
, 0, nodelete
, 0, 0);
3216 /* Set WINDOW's width to WIDTH, and recursively change the width of
3217 WINDOW's children. NODELETE non-zero means don't delete windows
3218 that become too small in the process. (The caller should check
3219 later and do so if appropriate.) */
3222 set_window_width (window
, width
, nodelete
)
3227 size_window (window
, width
, 1, nodelete
, 0, 0);
3230 /* Change window heights in windows rooted in WINDOW by N lines. */
3233 change_window_heights (window
, n
)
3237 struct window
*w
= XWINDOW (window
);
3239 XSETFASTINT (w
->top_line
, XFASTINT (w
->top_line
) + n
);
3240 XSETFASTINT (w
->total_lines
, XFASTINT (w
->total_lines
) - n
);
3242 if (INTEGERP (w
->orig_top_line
))
3243 XSETFASTINT (w
->orig_top_line
, XFASTINT (w
->orig_top_line
) + n
);
3244 if (INTEGERP (w
->orig_total_lines
))
3245 XSETFASTINT (w
->orig_total_lines
, XFASTINT (w
->orig_total_lines
) - n
);
3247 /* Handle just the top child in a vertical split. */
3248 if (!NILP (w
->vchild
))
3249 change_window_heights (w
->vchild
, n
);
3251 /* Adjust all children in a horizontal split. */
3252 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
3254 w
= XWINDOW (window
);
3255 change_window_heights (window
, n
);
3260 int window_select_count
;
3263 Fset_window_buffer_unwind (obuf
)
3270 EXFUN (Fset_window_fringes
, 4);
3271 EXFUN (Fset_window_scroll_bars
, 4);
3273 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
3274 means it's allowed to run hooks. See make_frame for a case where
3275 it's not allowed. KEEP_MARGINS_P non-zero means that the current
3276 margins, fringes, and scroll-bar settings of the window are not
3277 reset from the buffer's local settings. */
3280 set_window_buffer (window
, buffer
, run_hooks_p
, keep_margins_p
)
3281 Lisp_Object window
, buffer
;
3282 int run_hooks_p
, keep_margins_p
;
3284 struct window
*w
= XWINDOW (window
);
3285 struct buffer
*b
= XBUFFER (buffer
);
3286 int count
= SPECPDL_INDEX ();
3290 if (EQ (window
, selected_window
))
3291 b
->last_selected_window
= window
;
3293 /* Let redisplay errors through. */
3294 b
->display_error_modiff
= 0;
3296 /* Update time stamps of buffer display. */
3297 if (INTEGERP (b
->display_count
))
3298 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
3299 b
->display_time
= Fcurrent_time ();
3301 XSETFASTINT (w
->window_end_pos
, 0);
3302 XSETFASTINT (w
->window_end_vpos
, 0);
3303 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
3304 w
->window_end_valid
= Qnil
;
3305 w
->hscroll
= w
->min_hscroll
= make_number (0);
3307 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3308 set_marker_restricted (w
->start
,
3309 make_number (b
->last_window_start
),
3311 w
->start_at_line_beg
= Qnil
;
3312 w
->force_start
= Qnil
;
3313 XSETFASTINT (w
->last_modified
, 0);
3314 XSETFASTINT (w
->last_overlay_modified
, 0);
3315 windows_or_buffers_changed
++;
3317 /* We must select BUFFER for running the window-scroll-functions.
3318 If WINDOW is selected, switch permanently.
3319 Otherwise, switch but go back to the ambient buffer afterward. */
3320 if (EQ (window
, selected_window
))
3321 Fset_buffer (buffer
);
3322 /* We can't check ! NILP (Vwindow_scroll_functions) here
3323 because that might itself be a local variable. */
3324 else if (window_initialized
)
3326 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
3327 Fset_buffer (buffer
);
3330 if (!keep_margins_p
)
3332 /* Set left and right marginal area width etc. from buffer. */
3334 /* This may call adjust_window_margins three times, so
3335 temporarily disable window margins. */
3336 Lisp_Object save_left
= w
->left_margin_cols
;
3337 Lisp_Object save_right
= w
->right_margin_cols
;
3339 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
3341 Fset_window_fringes (window
,
3342 b
->left_fringe_width
, b
->right_fringe_width
,
3343 b
->fringes_outside_margins
);
3345 Fset_window_scroll_bars (window
,
3346 b
->scroll_bar_width
,
3347 b
->vertical_scroll_bar_type
, Qnil
);
3349 w
->left_margin_cols
= save_left
;
3350 w
->right_margin_cols
= save_right
;
3352 Fset_window_margins (window
,
3353 b
->left_margin_cols
, b
->right_margin_cols
);
3358 if (! NILP (Vwindow_scroll_functions
))
3359 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3360 Fmarker_position (w
->start
));
3362 if (! NILP (Vwindow_configuration_change_hook
)
3363 && ! NILP (Vrun_hooks
))
3364 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3367 unbind_to (count
, Qnil
);
3371 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3372 doc
: /* Make WINDOW display BUFFER as its contents.
3373 BUFFER can be a buffer or the name of an existing buffer.
3374 Optional third arg KEEP-MARGINS non-nil means that WINDOW's current
3375 display margins, fringe widths, and scroll bar settings are maintained;
3376 the default is to reset these from BUFFER's local settings or the frame
3379 This function runs the hook `window-scroll-functions'. */)
3380 (window
, buffer
, keep_margins
)
3381 register Lisp_Object window
, buffer
, keep_margins
;
3383 register Lisp_Object tem
;
3384 register struct window
*w
= decode_window (window
);
3386 XSETWINDOW (window
, w
);
3387 buffer
= Fget_buffer (buffer
);
3388 CHECK_BUFFER (buffer
);
3390 if (NILP (XBUFFER (buffer
)->name
))
3391 error ("Attempt to display deleted buffer");
3395 error ("Window is deleted");
3396 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
3397 is first being set up. */
3399 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
3400 error ("Window is dedicated to `%s'",
3401 SDATA (XBUFFER (tem
)->name
));
3406 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3410 /* Note that selected_window can be nil
3411 when this is called from Fset_window_configuration. */
3413 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
3414 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
3415 If WINDOW is not already selected, make WINDOW's buffer current
3416 and make WINDOW the frame's selected window. Return WINDOW.
3417 Optional second arg NORECORD non-nil means
3418 do not put this buffer at the front of the list of recently selected ones.
3420 Note that the main editor command loop
3421 selects the buffer of the selected window before each command. */)
3423 register Lisp_Object window
, norecord
;
3425 register struct window
*w
;
3426 register struct window
*ow
;
3429 CHECK_LIVE_WINDOW (window
);
3431 w
= XWINDOW (window
);
3432 w
->frozen_window_start_p
= 0;
3434 ++window_select_count
;
3435 XSETFASTINT (w
->use_time
, window_select_count
);
3436 if (EQ (window
, selected_window
))
3439 /* Store the current buffer's actual point into the
3440 old selected window. It belongs to that window,
3441 and when the window is not selected, must be in the window. */
3442 if (!NILP (selected_window
))
3444 ow
= XWINDOW (selected_window
);
3445 if (! NILP (ow
->buffer
))
3446 set_marker_both (ow
->pointm
, ow
->buffer
,
3447 BUF_PT (XBUFFER (ow
->buffer
)),
3448 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
3451 selected_window
= window
;
3452 sf
= SELECTED_FRAME ();
3453 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
3455 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
3456 /* Use this rather than Fhandle_switch_frame
3457 so that FRAME_FOCUS_FRAME is moved appropriately as we
3458 move around in the state where a minibuffer in a separate
3460 Fselect_frame (WINDOW_FRAME (w
));
3463 sf
->selected_window
= window
;
3465 if (NILP (norecord
))
3466 record_buffer (w
->buffer
);
3467 Fset_buffer (w
->buffer
);
3469 XBUFFER (w
->buffer
)->last_selected_window
= window
;
3471 /* Go to the point recorded in the window.
3472 This is important when the buffer is in more
3473 than one window. It also matters when
3474 redisplay_window has altered point after scrolling,
3475 because it makes the change only in the window. */
3477 register int new_point
= marker_position (w
->pointm
);
3478 if (new_point
< BEGV
)
3480 else if (new_point
> ZV
)
3486 windows_or_buffers_changed
++;
3491 select_window_norecord (window
)
3494 return Fselect_window (window
, Qt
);
3497 /* Deiconify the frame containing the window WINDOW,
3498 unless it is the selected frame;
3501 The reason for the exception for the selected frame
3502 is that it seems better not to change the selected frames visibility
3503 merely because of displaying a different buffer in it.
3504 The deiconification is useful when a buffer gets shown in
3505 another frame that you were not using lately. */
3508 display_buffer_1 (window
)
3511 Lisp_Object frame
= XWINDOW (window
)->frame
;
3512 FRAME_PTR f
= XFRAME (frame
);
3514 FRAME_SAMPLE_VISIBILITY (f
);
3516 if (EQ (frame
, selected_frame
))
3517 ; /* Assume the selected frame is already visible enough. */
3518 else if (minibuf_level
> 0
3519 && MINI_WINDOW_P (XWINDOW (selected_window
))
3520 && WINDOW_LIVE_P (minibuf_selected_window
)
3521 && EQ (frame
, WINDOW_FRAME (XWINDOW (minibuf_selected_window
))))
3522 ; /* Assume the frame from which we invoked the minibuffer is visible. */
3525 if (FRAME_ICONIFIED_P (f
))
3526 Fmake_frame_visible (frame
);
3527 else if (FRAME_VISIBLE_P (f
))
3528 Fraise_frame (frame
);
3534 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
3535 doc
: /* Returns non-nil if a buffer named BUFFER-NAME gets a special frame.
3536 If the value is t, `display-buffer' or `pop-to-buffer' would create a
3537 special frame for that buffer using the default frame parameters.
3539 If the value is a list, it is a list of frame parameters that would be used
3540 to make a frame for that buffer.
3541 The variables `special-display-buffer-names'
3542 and `special-display-regexps' control this. */)
3544 Lisp_Object buffer_name
;
3548 CHECK_STRING (buffer_name
);
3550 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
3554 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
3558 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
3560 Lisp_Object car
= XCAR (tem
);
3562 && fast_string_match (car
, buffer_name
) >= 0)
3564 else if (CONSP (car
)
3565 && STRINGP (XCAR (car
))
3566 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
3572 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
3573 doc
: /* Returns non-nil if a buffer named BUFFER-NAME would use the same window.
3574 More precisely, if `display-buffer' or `pop-to-buffer' would display
3575 that buffer in the selected window rather than (as usual) in some other window.
3576 See `same-window-buffer-names' and `same-window-regexps'. */)
3578 Lisp_Object buffer_name
;
3582 CHECK_STRING (buffer_name
);
3584 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
3588 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
3592 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
3594 Lisp_Object car
= XCAR (tem
);
3596 && fast_string_match (car
, buffer_name
) >= 0)
3598 else if (CONSP (car
)
3599 && STRINGP (XCAR (car
))
3600 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
3606 /* Use B so the default is (other-buffer). */
3607 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
3608 "BDisplay buffer: \nP",
3609 doc
: /* Make BUFFER appear in some window but don't select it.
3610 BUFFER must be the name of an existing buffer, or, when called from Lisp,
3612 If BUFFER is shown already in some window, just use that one,
3613 unless the window is the selected window and the optional second
3614 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).
3615 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
3616 Returns the window displaying BUFFER.
3617 If `display-buffer-reuse-frames' is non-nil, and another frame is currently
3618 displaying BUFFER, then simply raise that frame.
3620 The variables `special-display-buffer-names',
3621 `special-display-regexps', `same-window-buffer-names', and
3622 `same-window-regexps' customize how certain buffer names are handled.
3623 The latter two take effect only if NOT-THIS-WINDOW is nil.
3625 If optional argument FRAME is `visible', check all visible frames
3626 for a window to use.
3627 If FRAME is 0, check all visible and iconified frames.
3628 If FRAME is t, check all frames.
3629 If FRAME is a frame, check only that frame.
3630 If FRAME is nil, check only the selected frame
3631 (actually the last nonminibuffer frame),
3632 unless `pop-up-frames' or `display-buffer-reuse-frames' is non-nil,
3633 which means search visible and iconified frames.
3635 If a full-width window on a splittable frame is available to display
3636 the buffer, it may be split, subject to the value of the variable
3637 `split-height-threshold'.
3639 If `even-window-heights' is non-nil, window heights will be evened out
3640 if displaying the buffer causes two vertically adjacent windows to be
3642 (buffer
, not_this_window
, frame
)
3643 register Lisp_Object buffer
, not_this_window
, frame
;
3645 register Lisp_Object window
, tem
, swp
;
3649 buffer
= Fget_buffer (buffer
);
3650 CHECK_BUFFER (buffer
);
3652 if (!NILP (Vdisplay_buffer_function
))
3653 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
3655 if (NILP (not_this_window
)
3656 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
3657 return display_buffer_1 (selected_window
);
3659 /* See if the user has specified this buffer should appear
3660 in the selected window. */
3661 if (NILP (not_this_window
))
3663 swp
= Fsame_window_p (XBUFFER (buffer
)->name
);
3664 if (!NILP (swp
) && !no_switch_window (selected_window
))
3666 Fswitch_to_buffer (buffer
, Qnil
);
3667 return display_buffer_1 (selected_window
);
3671 /* If the user wants pop-up-frames or display-buffer-reuse-frames,
3672 look for a window showing BUFFER on any visible or iconified frame.
3673 Otherwise search only the current frame. */
3676 else if (pop_up_frames
3677 || display_buffer_reuse_frames
3678 || last_nonminibuf_frame
== 0)
3679 XSETFASTINT (tem
, 0);
3681 XSETFRAME (tem
, last_nonminibuf_frame
);
3683 window
= Fget_buffer_window (buffer
, tem
);
3685 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
3686 return display_buffer_1 (window
);
3688 /* Certain buffer names get special handling. */
3689 if (!NILP (Vspecial_display_function
) && NILP (swp
))
3691 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
3693 return call1 (Vspecial_display_function
, buffer
);
3695 return call2 (Vspecial_display_function
, buffer
, tem
);
3698 /* If there are no frames open that have more than a minibuffer,
3699 we need to create a new frame. */
3700 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
3702 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3703 Fset_window_buffer (window
, buffer
, Qnil
);
3704 return display_buffer_1 (window
);
3707 f
= SELECTED_FRAME ();
3709 || FRAME_MINIBUF_ONLY_P (f
)
3710 /* If the current frame is a special display frame,
3711 don't try to reuse its windows. */
3712 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (f
))->dedicated
))
3717 if (FRAME_MINIBUF_ONLY_P (f
))
3718 XSETFRAME (frames
, last_nonminibuf_frame
);
3720 /* Note that both Fget_largest_window and Fget_lru_window
3721 ignore minibuffers and dedicated windows.
3722 This means they can return nil. */
3724 /* If the frame we would try to split cannot be split,
3725 try other frames. */
3726 if (FRAME_NO_SPLIT_P (NILP (frames
) ? f
: last_nonminibuf_frame
))
3728 /* Try visible frames first. */
3729 window
= Fget_largest_window (Qvisible
, Qt
);
3730 /* If that didn't work, try iconified frames. */
3732 window
= Fget_largest_window (make_number (0), Qt
);
3733 #if 0 /* Don't try windows on other displays. */
3735 window
= Fget_largest_window (Qt
, Qt
);
3739 window
= Fget_largest_window (frames
, Qt
);
3741 /* If the largest window is tall enough, full-width, and either eligible
3742 for splitting or the only window, split it. */
3744 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3745 && WINDOW_FULL_WIDTH_P (XWINDOW (window
))
3746 && (window_height (window
) >= split_height_threshold
3747 || (NILP (XWINDOW (window
)->parent
)))
3748 && (window_height (window
)
3749 >= (2 * window_min_size_2 (XWINDOW (window
), 0))))
3750 window
= Fsplit_window (window
, Qnil
, Qnil
);
3753 Lisp_Object upper
, other
;
3755 window
= Fget_lru_window (frames
, Qt
);
3756 /* If the LRU window is tall enough, and either eligible for splitting
3757 and selected or the only window, split it. */
3759 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3760 && ((EQ (window
, selected_window
)
3761 && window_height (window
) >= split_height_threshold
)
3762 || (NILP (XWINDOW (window
)->parent
)))
3763 && (window_height (window
)
3764 >= (2 * window_min_size_2 (XWINDOW (window
), 0))))
3765 window
= Fsplit_window (window
, Qnil
, Qnil
);
3767 window
= Fget_lru_window (frames
, Qnil
);
3768 /* If Fget_lru_window returned nil, try other approaches. */
3770 /* Try visible frames first. */
3772 window
= Fget_buffer_window (buffer
, Qvisible
);
3774 window
= Fget_largest_window (Qvisible
, Qnil
);
3775 /* If that didn't work, try iconified frames. */
3777 window
= Fget_buffer_window (buffer
, make_number (0));
3779 window
= Fget_largest_window (make_number (0), Qnil
);
3781 #if 0 /* Don't try frames on other displays. */
3783 window
= Fget_buffer_window (buffer
, Qt
);
3785 window
= Fget_largest_window (Qt
, Qnil
);
3787 /* As a last resort, make a new frame. */
3789 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3790 /* If window appears above or below another,
3791 even out their heights. */
3792 other
= upper
= Qnil
;
3793 if (!NILP (XWINDOW (window
)->prev
))
3794 other
= upper
= XWINDOW (window
)->prev
;
3795 if (!NILP (XWINDOW (window
)->next
))
3796 other
= XWINDOW (window
)->next
, upper
= window
;
3798 && !NILP (Veven_window_heights
)
3799 /* Check that OTHER and WINDOW are vertically arrayed. */
3800 && !EQ (XWINDOW (other
)->top_line
, XWINDOW (window
)->top_line
)
3801 && (XFASTINT (XWINDOW (other
)->total_lines
)
3802 > XFASTINT (XWINDOW (window
)->total_lines
)))
3804 int total
= (XFASTINT (XWINDOW (other
)->total_lines
)
3805 + XFASTINT (XWINDOW (window
)->total_lines
));
3806 enlarge_window (upper
,
3807 total
/ 2 - XFASTINT (XWINDOW (upper
)->total_lines
),
3813 window
= Fget_lru_window (Qnil
, Qnil
);
3815 Fset_window_buffer (window
, buffer
, Qnil
);
3816 return display_buffer_1 (window
);
3820 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3822 doc
: /* Force all windows to be updated on next redisplay.
3823 If optional arg OBJECT is a window, force redisplay of that window only.
3824 If OBJECT is a buffer or buffer name, force redisplay of all windows
3825 displaying that buffer. */)
3831 windows_or_buffers_changed
++;
3832 update_mode_lines
++;
3836 if (WINDOWP (object
))
3838 struct window
*w
= XWINDOW (object
);
3839 mark_window_display_accurate (object
, 0);
3840 w
->update_mode_line
= Qt
;
3841 if (BUFFERP (w
->buffer
))
3842 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
3843 ++update_mode_lines
;
3847 if (STRINGP (object
))
3848 object
= Fget_buffer (object
);
3849 if (BUFFERP (object
) && !NILP (XBUFFER (object
)->name
))
3851 /* Walk all windows looking for buffer, and force update
3852 of each of those windows. */
3854 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3855 return NILP (object
) ? Qnil
: Qt
;
3858 /* If nothing suitable was found, just return.
3859 We could signal an error, but this feature will typically be used
3860 asynchronously in timers or process sentinels, so we don't. */
3866 temp_output_buffer_show (buf
)
3867 register Lisp_Object buf
;
3869 register struct buffer
*old
= current_buffer
;
3870 register Lisp_Object window
;
3871 register struct window
*w
;
3873 XBUFFER (buf
)->directory
= current_buffer
->directory
;
3876 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3880 #if 0 /* rms: there should be no reason for this. */
3881 XBUFFER (buf
)->prevent_redisplay_optimizations_p
= 1;
3883 set_buffer_internal (old
);
3885 if (!NILP (Vtemp_buffer_show_function
))
3886 call1 (Vtemp_buffer_show_function
, buf
);
3889 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
3891 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3892 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3893 Vminibuf_scroll_window
= window
;
3894 w
= XWINDOW (window
);
3895 XSETFASTINT (w
->hscroll
, 0);
3896 XSETFASTINT (w
->min_hscroll
, 0);
3897 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3898 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3900 /* Run temp-buffer-show-hook, with the chosen window selected
3901 and its buffer current. */
3903 if (!NILP (Vrun_hooks
)
3904 && !NILP (Fboundp (Qtemp_buffer_show_hook
))
3905 && !NILP (Fsymbol_value (Qtemp_buffer_show_hook
)))
3907 int count
= SPECPDL_INDEX ();
3908 Lisp_Object prev_window
, prev_buffer
;
3909 prev_window
= selected_window
;
3910 XSETBUFFER (prev_buffer
, old
);
3912 /* Select the window that was chosen, for running the hook.
3913 Note: Both Fselect_window and select_window_norecord may
3914 set-buffer to the buffer displayed in the window,
3915 so we need to save the current buffer. --stef */
3916 record_unwind_protect (Fset_buffer
, prev_buffer
);
3917 record_unwind_protect (select_window_norecord
, prev_window
);
3918 Fselect_window (window
, Qt
);
3919 Fset_buffer (w
->buffer
);
3920 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
3921 unbind_to (count
, Qnil
);
3927 make_dummy_parent (window
)
3931 register struct window
*o
, *p
;
3934 o
= XWINDOW (window
);
3935 p
= allocate_window ();
3936 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
3937 ((struct Lisp_Vector
*) p
)->contents
[i
]
3938 = ((struct Lisp_Vector
*)o
)->contents
[i
];
3939 XSETWINDOW (new, p
);
3942 XSETFASTINT (p
->sequence_number
, sequence_number
);
3944 /* Put new into window structure in place of window */
3945 replace_window (window
, new);
3958 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
3959 doc
: /* Split WINDOW, putting SIZE lines in the first of the pair.
3960 WINDOW defaults to selected one and SIZE to half its size.
3961 If optional third arg HORFLAG is non-nil, split side by side
3962 and put SIZE columns in the first of the pair. In that case,
3963 SIZE includes that window's scroll bar, or the divider column to its right.
3964 Interactively, all arguments are nil.
3966 Returns the newly created window (which is the lower or rightmost one).
3967 The upper or leftmost window is the original one, and remains selected
3968 if it was selected before.
3970 See Info node `(elisp)Splitting Windows' for more details and examples.*/)
3971 (window
, size
, horflag
)
3972 Lisp_Object window
, size
, horflag
;
3974 register Lisp_Object
new;
3975 register struct window
*o
, *p
;
3977 register int size_int
;
3980 window
= selected_window
;
3982 CHECK_LIVE_WINDOW (window
);
3984 o
= XWINDOW (window
);
3985 fo
= XFRAME (WINDOW_FRAME (o
));
3989 if (!NILP (horflag
))
3990 /* Calculate the size of the left-hand window, by dividing
3991 the usable space in columns by two.
3992 We round up, since the left-hand window may include
3993 a dividing line, while the right-hand may not. */
3994 size_int
= (XFASTINT (o
->total_cols
) + 1) >> 1;
3996 size_int
= XFASTINT (o
->total_lines
) >> 1;
4000 CHECK_NUMBER (size
);
4001 size_int
= XINT (size
);
4004 if (MINI_WINDOW_P (o
))
4005 error ("Attempt to split minibuffer window");
4006 else if (window_fixed_size_p (o
, !NILP (horflag
), 0))
4007 error ("Attempt to split fixed-size window");
4009 check_min_window_sizes ();
4013 int window_safe_height
= window_min_size_2 (o
, 0);
4015 if (size_int
< window_safe_height
)
4016 error ("Window height %d too small (after splitting)", size_int
);
4017 if (size_int
+ window_safe_height
> XFASTINT (o
->total_lines
))
4018 error ("Window height %d too small (after splitting)",
4019 XFASTINT (o
->total_lines
) - size_int
);
4020 if (NILP (o
->parent
)
4021 || NILP (XWINDOW (o
->parent
)->vchild
))
4023 make_dummy_parent (window
);
4025 XWINDOW (new)->vchild
= window
;
4030 int window_safe_width
= window_min_size_2 (o
, 1);
4032 if (size_int
< window_safe_width
)
4033 error ("Window width %d too small (after splitting)", size_int
);
4034 if (size_int
+ window_safe_width
> XFASTINT (o
->total_cols
))
4035 error ("Window width %d too small (after splitting)",
4036 XFASTINT (o
->total_cols
) - size_int
);
4037 if (NILP (o
->parent
)
4038 || NILP (XWINDOW (o
->parent
)->hchild
))
4040 make_dummy_parent (window
);
4042 XWINDOW (new)->hchild
= window
;
4046 /* Now we know that window's parent is a vertical combination
4047 if we are dividing vertically, or a horizontal combination
4048 if we are making side-by-side windows */
4050 windows_or_buffers_changed
++;
4051 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
4052 new = make_window ();
4055 p
->frame
= o
->frame
;
4057 if (!NILP (p
->next
))
4058 XWINDOW (p
->next
)->prev
= new;
4061 p
->parent
= o
->parent
;
4063 p
->window_end_valid
= Qnil
;
4064 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
4066 /* Duplicate special geometry settings. */
4068 p
->left_margin_cols
= o
->left_margin_cols
;
4069 p
->right_margin_cols
= o
->right_margin_cols
;
4070 p
->left_fringe_width
= o
->left_fringe_width
;
4071 p
->right_fringe_width
= o
->right_fringe_width
;
4072 p
->fringes_outside_margins
= o
->fringes_outside_margins
;
4073 p
->scroll_bar_width
= o
->scroll_bar_width
;
4074 p
->vertical_scroll_bar_type
= o
->vertical_scroll_bar_type
;
4076 /* Apportion the available frame space among the two new windows */
4078 if (!NILP (horflag
))
4080 p
->total_lines
= o
->total_lines
;
4081 p
->top_line
= o
->top_line
;
4082 XSETFASTINT (p
->total_cols
, XFASTINT (o
->total_cols
) - size_int
);
4083 XSETFASTINT (o
->total_cols
, size_int
);
4084 XSETFASTINT (p
->left_col
, XFASTINT (o
->left_col
) + size_int
);
4085 adjust_window_margins (p
);
4086 adjust_window_margins (o
);
4090 p
->left_col
= o
->left_col
;
4091 p
->total_cols
= o
->total_cols
;
4092 XSETFASTINT (p
->total_lines
, XFASTINT (o
->total_lines
) - size_int
);
4093 XSETFASTINT (o
->total_lines
, size_int
);
4094 XSETFASTINT (p
->top_line
, XFASTINT (o
->top_line
) + size_int
);
4097 /* Adjust glyph matrices. */
4100 Fset_window_buffer (new, o
->buffer
, Qt
);
4104 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
4105 doc
: /* Make current window ARG lines bigger.
4106 From program, optional second arg non-nil means grow sideways ARG columns.
4107 Interactively, if an argument is not given, make the window one line bigger.
4108 If HORIZONTAL is non-nil, enlarge horizontally instead of vertically.
4109 This function can delete windows, even the second window, if they get
4112 Lisp_Object arg
, horizontal
;
4115 enlarge_window (selected_window
, XINT (arg
), !NILP (horizontal
));
4117 if (! NILP (Vwindow_configuration_change_hook
))
4118 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
4123 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
4124 doc
: /* Make current window ARG lines smaller.
4125 From program, optional second arg non-nil means shrink sideways arg columns.
4126 Interactively, if an argument is not given, make the window one line smaller.
4127 Only siblings to the right or below are changed. */)
4129 Lisp_Object arg
, side
;
4132 enlarge_window (selected_window
, -XINT (arg
), !NILP (side
));
4134 if (! NILP (Vwindow_configuration_change_hook
))
4135 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
4141 window_height (window
)
4144 register struct window
*p
= XWINDOW (window
);
4145 return WINDOW_TOTAL_LINES (p
);
4149 window_width (window
)
4152 register struct window
*p
= XWINDOW (window
);
4153 return WINDOW_TOTAL_COLS (p
);
4158 *(horiz_flag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line))
4160 #define CURSIZE(w) \
4161 *(horiz_flag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines))
4164 /* Enlarge WINDOW by DELTA.
4165 HORIZ_FLAG nonzero means enlarge it horizontally;
4166 zero means do it vertically.
4168 Siblings of the selected window are resized to fulfill the size
4169 request. If they become too small in the process, they will be
4173 enlarge_window (window
, delta
, horiz_flag
)
4175 int delta
, horiz_flag
;
4177 Lisp_Object parent
, next
, prev
;
4181 int (*sizefun
) P_ ((Lisp_Object
))
4182 = horiz_flag
? window_width
: window_height
;
4183 void (*setsizefun
) P_ ((Lisp_Object
, int, int))
4184 = (horiz_flag
? set_window_width
: set_window_height
);
4186 /* Check values of window_min_width and window_min_height for
4188 check_min_window_sizes ();
4190 /* Give up if this window cannot be resized. */
4191 if (window_fixed_size_p (XWINDOW (window
), horiz_flag
, 1))
4192 error ("Window is not resizable");
4194 /* Find the parent of the selected window. */
4197 p
= XWINDOW (window
);
4203 error ("No other window to side of this one");
4208 ? !NILP (XWINDOW (parent
)->hchild
)
4209 : !NILP (XWINDOW (parent
)->vchild
))
4215 sizep
= &CURSIZE (window
);
4218 register int maxdelta
;
4220 /* Compute the maximum size increment this window can have. */
4222 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - XINT (*sizep
)
4223 /* This is a main window followed by a minibuffer. */
4224 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
4225 - window_min_size (XWINDOW (p
->next
),
4227 /* This is a minibuffer following a main window. */
4228 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
4229 - window_min_size (XWINDOW (p
->prev
),
4231 /* This is a frame with only one window, a minibuffer-only
4232 or a minibufferless frame. */
4235 if (delta
> maxdelta
)
4236 /* This case traps trying to make the minibuffer
4237 the full frame, or make the only window aside from the
4238 minibuffer the full frame. */
4242 if (XINT (*sizep
) + delta
< window_min_size (XWINDOW (window
), horiz_flag
, 0, 0))
4244 delete_window (window
);
4251 /* Find the total we can get from other siblings without deleting them. */
4253 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
4254 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
4256 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
4257 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
4260 /* If we can get it all from them without deleting them, do so. */
4261 if (delta
<= maximum
)
4263 Lisp_Object first_unaffected
;
4264 Lisp_Object first_affected
;
4269 first_affected
= window
;
4270 /* Look at one sibling at a time,
4271 moving away from this window in both directions alternately,
4272 and take as much as we can get without deleting that sibling. */
4274 && (!NILP (next
) || !NILP (prev
)))
4278 int this_one
= ((*sizefun
) (next
)
4279 - window_min_size (XWINDOW (next
),
4280 horiz_flag
, 0, &fixed_p
));
4283 if (this_one
> delta
)
4286 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
4287 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4292 next
= XWINDOW (next
)->next
;
4300 int this_one
= ((*sizefun
) (prev
)
4301 - window_min_size (XWINDOW (prev
),
4302 horiz_flag
, 0, &fixed_p
));
4305 if (this_one
> delta
)
4308 first_affected
= prev
;
4310 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
4311 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4316 prev
= XWINDOW (prev
)->prev
;
4320 xassert (delta
== 0);
4322 /* Now recalculate the edge positions of all the windows affected,
4323 based on the new sizes. */
4324 first_unaffected
= next
;
4325 prev
= first_affected
;
4326 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
4327 prev
= next
, next
= XWINDOW (next
)->next
)
4329 XSETINT (CURBEG (next
), XINT (CURBEG (prev
)) + (*sizefun
) (prev
));
4330 /* This does not change size of NEXT,
4331 but it propagates the new top edge to its children */
4332 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
4337 register int delta1
;
4338 register int opht
= (*sizefun
) (parent
);
4340 if (opht
<= XINT (*sizep
) + delta
)
4342 /* If trying to grow this window to or beyond size of the parent,
4343 just delete all the sibling windows. */
4344 Lisp_Object start
, tem
, next
;
4346 start
= XWINDOW (parent
)->vchild
;
4348 start
= XWINDOW (parent
)->hchild
;
4350 /* Delete any siblings that come after WINDOW. */
4351 tem
= XWINDOW (window
)->next
;
4352 while (! NILP (tem
))
4354 next
= XWINDOW (tem
)->next
;
4355 delete_window (tem
);
4359 /* Delete any siblings that come after WINDOW.
4360 Note that if START is not WINDOW, then WINDOW still
4361 Fhas siblings, so WINDOW has not yet replaced its parent. */
4363 while (! EQ (tem
, window
))
4365 next
= XWINDOW (tem
)->next
;
4366 delete_window (tem
);
4372 /* Otherwise, make delta1 just right so that if we add
4373 delta1 lines to this window and to the parent, and then
4374 shrink the parent back to its original size, the new
4375 proportional size of this window will increase by delta.
4377 The function size_window will compute the new height h'
4378 of the window from delta1 as:
4381 x = delta1 - delta1/n * n for the 1st resizable child
4384 where n is the number of children that can be resized.
4385 We can ignore x by choosing a delta1 that is a multiple of
4386 n. We want the height of this window to come out as
4396 The number of children n equals the number of resizable
4397 children of this window + 1 because we know window itself
4398 is resizable (otherwise we would have signalled an error). */
4400 struct window
*w
= XWINDOW (window
);
4404 for (s
= w
->next
; !NILP (s
); s
= XWINDOW (s
)->next
)
4405 if (!window_fixed_size_p (XWINDOW (s
), horiz_flag
, 0))
4407 for (s
= w
->prev
; !NILP (s
); s
= XWINDOW (s
)->prev
)
4408 if (!window_fixed_size_p (XWINDOW (s
), horiz_flag
, 0))
4413 /* Add delta1 lines or columns to this window, and to the parent,
4414 keeping things consistent while not affecting siblings. */
4415 XSETINT (CURSIZE (parent
), opht
+ delta1
);
4416 (*setsizefun
) (window
, XINT (*sizep
) + delta1
, 0);
4418 /* Squeeze out delta1 lines or columns from our parent,
4419 shriking this window and siblings proportionately.
4420 This brings parent back to correct size.
4421 Delta1 was calculated so this makes this window the desired size,
4422 taking it all out of the siblings. */
4423 (*setsizefun
) (parent
, opht
, 0);
4428 XSETFASTINT (p
->last_modified
, 0);
4429 XSETFASTINT (p
->last_overlay_modified
, 0);
4431 /* Adjust glyph matrices. */
4432 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4436 /* Adjust the size of WINDOW by DELTA, moving only its trailing edge.
4437 HORIZ_FLAG nonzero means adjust the width, moving the right edge.
4438 zero means adjust the height, moving the bottom edge.
4440 Following siblings of the selected window are resized to fulfill
4441 the size request. If they become too small in the process, they
4442 are not deleted; instead, we signal an error. */
4445 adjust_window_trailing_edge (window
, delta
, horiz_flag
)
4447 int delta
, horiz_flag
;
4449 Lisp_Object parent
, child
;
4451 Lisp_Object old_config
= Fcurrent_window_configuration (Qnil
);
4452 int delcount
= window_deletion_count
;
4454 /* Check values of window_min_width and window_min_height for
4456 check_min_window_sizes ();
4459 window
= Fselected_window ();
4461 CHECK_WINDOW (window
);
4463 /* Give up if this window cannot be resized. */
4464 if (window_fixed_size_p (XWINDOW (window
), horiz_flag
, 1))
4465 error ("Window is not resizable");
4469 Lisp_Object first_parallel
= Qnil
;
4473 /* This happens if WINDOW on the previous iteration was
4474 at top level of the window tree. */
4475 Fset_window_configuration (old_config
);
4476 error ("Specified window edge is fixed");
4479 p
= XWINDOW (window
);
4482 /* See if this level has windows in parallel in the specified
4483 direction. If so, set FIRST_PARALLEL to the first one. */
4486 if (! NILP (parent
) && !NILP (XWINDOW (parent
)->vchild
))
4487 first_parallel
= XWINDOW (parent
)->vchild
;
4488 else if (NILP (parent
) && !NILP (p
->next
))
4490 /* Handle the vertical chain of main window and minibuffer
4491 which has no parent. */
4492 first_parallel
= window
;
4493 while (! NILP (XWINDOW (first_parallel
)->prev
))
4494 first_parallel
= XWINDOW (first_parallel
)->prev
;
4499 if (! NILP (parent
) && !NILP (XWINDOW (parent
)->hchild
))
4500 first_parallel
= XWINDOW (parent
)->hchild
;
4503 /* If this level's succession is in the desired dimension,
4504 and this window is the last one, and there is no higher level,
4505 its trailing edge is fixed. */
4506 if (NILP (XWINDOW (window
)->next
) && NILP (first_parallel
)
4509 Fset_window_configuration (old_config
);
4510 error ("Specified window edge is fixed");
4513 /* Don't make this window too small. */
4514 if (XINT (CURSIZE (window
)) + delta
4515 < window_min_size_2 (XWINDOW (window
), horiz_flag
))
4517 Fset_window_configuration (old_config
);
4518 error ("Cannot adjust window size as specified");
4521 /* Clear out some redisplay caches. */
4522 XSETFASTINT (p
->last_modified
, 0);
4523 XSETFASTINT (p
->last_overlay_modified
, 0);
4525 /* Adjust this window's edge. */
4526 XSETINT (CURSIZE (window
),
4527 XINT (CURSIZE (window
)) + delta
);
4529 /* If this window has following siblings in the desired dimension,
4530 make them smaller, and exit the loop.
4532 (If we reach the top of the tree and can never do this,
4533 we will fail and report an error, above.) */
4534 if (NILP (first_parallel
))
4536 if (!NILP (p
->next
))
4538 /* This may happen for the minibuffer. In that case
4539 the window_deletion_count check below does not work. */
4540 if (XINT (CURSIZE (p
->next
)) - delta
<= 0)
4542 Fset_window_configuration (old_config
);
4543 error ("Cannot adjust window size as specified");
4546 XSETINT (CURBEG (p
->next
),
4547 XINT (CURBEG (p
->next
)) + delta
);
4548 size_window (p
->next
, XINT (CURSIZE (p
->next
)) - delta
,
4549 horiz_flag
, 0, 1, 0);
4554 /* Here we have a chain of parallel siblings, in the other dimension.
4555 Change the size of the other siblings. */
4556 for (child
= first_parallel
;
4558 child
= XWINDOW (child
)->next
)
4559 if (! EQ (child
, window
))
4560 size_window (child
, XINT (CURSIZE (child
)) + delta
,
4561 horiz_flag
, 0, 0, 1);
4566 /* If we made a window so small it got deleted,
4567 we failed. Report failure. */
4568 if (delcount
!= window_deletion_count
)
4570 Fset_window_configuration (old_config
);
4571 error ("Cannot adjust window size as specified");
4574 /* Adjust glyph matrices. */
4575 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4581 DEFUN ("adjust-window-trailing-edge", Fadjust_window_trailing_edge
,
4582 Sadjust_window_trailing_edge
, 3, 3, 0,
4583 doc
: /* Adjust the bottom or right edge of WINDOW by DELTA.
4584 If HORIZONTAL is non-nil, that means adjust the width, moving the right edge.
4585 Otherwise, adjust the height, moving the bottom edge.
4587 Following siblings of the selected window are resized to fulfill
4588 the size request. If they become too small in the process, they
4589 are not deleted; instead, we signal an error. */)
4590 (window
, delta
, horizontal
)
4591 Lisp_Object window
, delta
, horizontal
;
4593 CHECK_NUMBER (delta
);
4594 adjust_window_trailing_edge (window
, XINT (delta
), !NILP (horizontal
));
4596 if (! NILP (Vwindow_configuration_change_hook
))
4597 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
4604 /***********************************************************************
4605 Resizing Mini-Windows
4606 ***********************************************************************/
4608 static void shrink_window_lowest_first
P_ ((struct window
*, int));
4610 enum save_restore_action
4617 static int save_restore_orig_size
P_ ((struct window
*,
4618 enum save_restore_action
));
4620 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
4621 from lowest windows first. */
4624 shrink_window_lowest_first (w
, height
)
4632 xassert (!MINI_WINDOW_P (w
));
4634 /* Set redisplay hints. */
4635 XSETFASTINT (w
->last_modified
, 0);
4636 XSETFASTINT (w
->last_overlay_modified
, 0);
4637 windows_or_buffers_changed
++;
4638 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
4640 old_height
= XFASTINT (w
->total_lines
);
4641 XSETFASTINT (w
->total_lines
, height
);
4643 if (!NILP (w
->hchild
))
4645 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
4647 c
= XWINDOW (child
);
4648 c
->top_line
= w
->top_line
;
4649 shrink_window_lowest_first (c
, height
);
4652 else if (!NILP (w
->vchild
))
4654 Lisp_Object last_child
;
4655 int delta
= old_height
- height
;
4660 /* Find the last child. We are taking space from lowest windows
4661 first, so we iterate over children from the last child
4663 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
4666 /* Assign new heights. We leave only MIN_SAFE_WINDOW_HEIGHT. */
4667 for (child
= last_child
; delta
&& !NILP (child
); child
= c
->prev
)
4671 c
= XWINDOW (child
);
4672 this_one
= XFASTINT (c
->total_lines
) - MIN_SAFE_WINDOW_HEIGHT
;
4674 if (this_one
> delta
)
4677 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
) - this_one
);
4681 /* Compute new positions. */
4682 last_top
= XINT (w
->top_line
);
4683 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
4685 c
= XWINDOW (child
);
4686 c
->top_line
= make_number (last_top
);
4687 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
));
4688 last_top
+= XFASTINT (c
->total_lines
);
4694 /* Save, restore, or check positions and sizes in the window tree
4695 rooted at W. ACTION says what to do.
4697 If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and
4698 orig_total_lines members are valid for all windows in the window
4699 tree. Value is non-zero if they are valid.
4701 If ACTION is SAVE_ORIG_SIZES, save members top and height in
4702 orig_top_line and orig_total_lines for all windows in the tree.
4704 If ACTION is RESTORE_ORIG_SIZES, restore top and height from values
4705 stored in orig_top_line and orig_total_lines for all windows. */
4708 save_restore_orig_size (w
, action
)
4710 enum save_restore_action action
;
4716 if (!NILP (w
->hchild
))
4718 if (!save_restore_orig_size (XWINDOW (w
->hchild
), action
))
4721 else if (!NILP (w
->vchild
))
4723 if (!save_restore_orig_size (XWINDOW (w
->vchild
), action
))
4729 case CHECK_ORIG_SIZES
:
4730 if (!INTEGERP (w
->orig_top_line
) || !INTEGERP (w
->orig_total_lines
))
4734 case SAVE_ORIG_SIZES
:
4735 w
->orig_top_line
= w
->top_line
;
4736 w
->orig_total_lines
= w
->total_lines
;
4737 XSETFASTINT (w
->last_modified
, 0);
4738 XSETFASTINT (w
->last_overlay_modified
, 0);
4741 case RESTORE_ORIG_SIZES
:
4742 xassert (INTEGERP (w
->orig_top_line
) && INTEGERP (w
->orig_total_lines
));
4743 w
->top_line
= w
->orig_top_line
;
4744 w
->total_lines
= w
->orig_total_lines
;
4745 w
->orig_total_lines
= w
->orig_top_line
= Qnil
;
4746 XSETFASTINT (w
->last_modified
, 0);
4747 XSETFASTINT (w
->last_overlay_modified
, 0);
4754 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
4761 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
4762 without deleting other windows. */
4765 grow_mini_window (w
, delta
)
4769 struct frame
*f
= XFRAME (w
->frame
);
4770 struct window
*root
;
4772 xassert (MINI_WINDOW_P (w
));
4773 xassert (delta
>= 0);
4775 /* Check values of window_min_width and window_min_height for
4777 check_min_window_sizes ();
4779 /* Compute how much we can enlarge the mini-window without deleting
4781 root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4784 int min_height
= window_min_size (root
, 0, 0, 0);
4785 if (XFASTINT (root
->total_lines
) - delta
< min_height
)
4786 /* Note that the root window may already be smaller than
4788 delta
= max (0, XFASTINT (root
->total_lines
) - min_height
);
4793 /* Save original window sizes and positions, if not already done. */
4794 if (!save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4795 save_restore_orig_size (root
, SAVE_ORIG_SIZES
);
4797 /* Shrink other windows. */
4798 shrink_window_lowest_first (root
, XFASTINT (root
->total_lines
) - delta
);
4800 /* Grow the mini-window. */
4801 w
->top_line
= make_number (XFASTINT (root
->top_line
) + XFASTINT (root
->total_lines
));
4802 w
->total_lines
= make_number (XFASTINT (w
->total_lines
) + delta
);
4803 XSETFASTINT (w
->last_modified
, 0);
4804 XSETFASTINT (w
->last_overlay_modified
, 0);
4811 /* Shrink mini-window W. If there is recorded info about window sizes
4812 before a call to grow_mini_window, restore recorded window sizes.
4813 Otherwise, if the mini-window is higher than 1 line, resize it to 1
4817 shrink_mini_window (w
)
4820 struct frame
*f
= XFRAME (w
->frame
);
4821 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4823 if (save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4825 save_restore_orig_size (root
, RESTORE_ORIG_SIZES
);
4827 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4828 windows_or_buffers_changed
= 1;
4830 else if (XFASTINT (w
->total_lines
) > 1)
4832 /* Distribute the additional lines of the mini-window
4833 among the other windows. */
4835 XSETWINDOW (window
, w
);
4836 enlarge_window (window
, 1 - XFASTINT (w
->total_lines
), 0);
4842 /* Mark window cursors off for all windows in the window tree rooted
4843 at W by setting their phys_cursor_on_p flag to zero. Called from
4844 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4845 the frame are cleared. */
4848 mark_window_cursors_off (w
)
4853 if (!NILP (w
->hchild
))
4854 mark_window_cursors_off (XWINDOW (w
->hchild
));
4855 else if (!NILP (w
->vchild
))
4856 mark_window_cursors_off (XWINDOW (w
->vchild
));
4858 w
->phys_cursor_on_p
= 0;
4860 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4865 /* Return number of lines of text (not counting mode lines) in W. */
4868 window_internal_height (w
)
4871 int ht
= XFASTINT (w
->total_lines
);
4873 if (!MINI_WINDOW_P (w
))
4875 if (!NILP (w
->parent
)
4876 || !NILP (w
->vchild
)
4877 || !NILP (w
->hchild
)
4880 || WINDOW_WANTS_MODELINE_P (w
))
4883 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4891 /* Return the number of columns in W.
4892 Don't count columns occupied by scroll bars or the vertical bar
4893 separating W from the sibling to its right. */
4896 window_box_text_cols (w
)
4899 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4900 int width
= XINT (w
->total_cols
);
4902 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
4903 /* Scroll bars occupy a few columns. */
4904 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
4905 else if (!FRAME_WINDOW_P (f
)
4906 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
4907 /* The column of `|' characters separating side-by-side windows
4908 occupies one column only. */
4911 if (FRAME_WINDOW_P (f
))
4912 /* On window-systems, fringes and display margins cannot be
4913 used for normal text. */
4914 width
-= (WINDOW_FRINGE_COLS (w
)
4915 + WINDOW_LEFT_MARGIN_COLS (w
)
4916 + WINDOW_RIGHT_MARGIN_COLS (w
));
4922 /************************************************************************
4924 ***********************************************************************/
4926 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4927 N screen-fulls, which is defined as the height of the window minus
4928 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4929 instead. Negative values of N mean scroll down. NOERROR non-zero
4930 means don't signal an error if we try to move over BEGV or ZV,
4934 window_scroll (window
, n
, whole
, noerror
)
4942 /* If we must, use the pixel-based version which is much slower than
4943 the line-based one but can handle varying line heights. */
4944 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4945 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4947 window_scroll_line_based (window
, n
, whole
, noerror
);
4953 /* Implementation of window_scroll that works based on pixel line
4954 heights. See the comment of window_scroll for parameter
4958 window_scroll_pixel_based (window
, n
, whole
, noerror
)
4965 struct window
*w
= XWINDOW (window
);
4966 struct text_pos start
;
4967 int this_scroll_margin
;
4968 /* True if we fiddled the window vscroll field without really scrolling. */
4970 int x
, y
, rtop
, rbot
, rowh
, vpos
;
4972 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4974 /* If PT is not visible in WINDOW, move back one half of
4975 the screen. Allow PT to be partially visible, otherwise
4976 something like (scroll-down 1) with PT in the line before
4977 the partially visible one would recenter. */
4979 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
4981 /* Move backward half the height of the window. Performance note:
4982 vmotion used here is about 10% faster, but would give wrong
4983 results for variable height lines. */
4984 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4985 it
.current_y
= it
.last_visible_y
;
4986 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4988 /* The function move_iterator_vertically may move over more than
4989 the specified y-distance. If it->w is small, e.g. a
4990 mini-buffer window, we may end up in front of the window's
4991 display area. This is the case when Start displaying at the
4992 start of the line containing PT in this case. */
4993 if (it
.current_y
<= 0)
4995 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4996 move_it_vertically_backward (&it
, 0);
5000 start
= it
.current
.pos
;
5002 else if (auto_window_vscroll_p
)
5004 if (rtop
|| rbot
) /* partially visible */
5007 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
5009 dy
= max ((window_box_height (w
)
5010 - next_screen_context_lines
* dy
),
5016 /* Only vscroll backwards if already vscrolled forwards. */
5017 if (w
->vscroll
< 0 && rtop
> 0)
5019 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
5020 Fset_window_vscroll (window
, make_number (px
), Qt
);
5026 /* Do vscroll if already vscrolled or only display line. */
5027 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
5029 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
5030 Fset_window_vscroll (window
, make_number (px
), Qt
);
5034 /* Maybe modify window start instead of scrolling. */
5035 if (rbot
> 0 || w
->vscroll
< 0)
5039 Fset_window_vscroll (window
, make_number (0), Qt
);
5040 /* If there are other text lines above the current row,
5041 move window start to current row. Else to next row. */
5043 spos
= XINT (Fline_beginning_position (Qnil
));
5045 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
5046 set_marker_restricted (w
->start
, make_number (spos
),
5048 w
->start_at_line_beg
= Qt
;
5049 w
->update_mode_line
= Qt
;
5050 XSETFASTINT (w
->last_modified
, 0);
5051 XSETFASTINT (w
->last_overlay_modified
, 0);
5052 /* Set force_start so that redisplay_window will run the
5053 window-scroll-functions. */
5054 w
->force_start
= Qt
;
5059 /* Cancel previous vscroll. */
5060 Fset_window_vscroll (window
, make_number (0), Qt
);
5063 /* If scroll_preserve_screen_position is non-nil, we try to set
5064 point in the same window line as it is now, so get that line. */
5065 if (!NILP (Vscroll_preserve_screen_position
))
5067 /* We preserve the goal pixel coordinate across consecutive
5068 calls to scroll-up or scroll-down. This avoids the
5069 possibility of point becoming "stuck" on a tall line when
5070 scrolling by one line. */
5071 if (window_scroll_pixel_based_preserve_y
< 0
5072 || (!EQ (current_kboard
->Vlast_command
, Qscroll_up
)
5073 && !EQ (current_kboard
->Vlast_command
, Qscroll_down
)))
5075 start_display (&it
, w
, start
);
5076 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5077 window_scroll_pixel_based_preserve_y
= it
.current_y
;
5081 window_scroll_pixel_based_preserve_y
= -1;
5083 /* Move iterator it from start the specified distance forward or
5084 backward. The result is the new window start. */
5085 start_display (&it
, w
, start
);
5088 int start_pos
= IT_CHARPOS (it
);
5089 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
5090 dy
= max ((window_box_height (w
)
5091 - next_screen_context_lines
* dy
),
5094 /* Note that move_it_vertically always moves the iterator to the
5095 start of a line. So, if the last line doesn't have a newline,
5096 we would end up at the start of the line ending at ZV. */
5099 move_it_vertically_backward (&it
, -dy
);
5100 /* Ensure we actually do move, e.g. in case we are currently
5101 looking at an image that is taller that the window height. */
5102 while (start_pos
== IT_CHARPOS (it
)
5103 && start_pos
> BEGV
)
5104 move_it_by_lines (&it
, -1, 1);
5108 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
5109 MOVE_TO_POS
| MOVE_TO_Y
);
5110 /* Ensure we actually do move, e.g. in case we are currently
5111 looking at an image that is taller that the window height. */
5112 while (start_pos
== IT_CHARPOS (it
)
5114 move_it_by_lines (&it
, 1, 1);
5118 move_it_by_lines (&it
, n
, 1);
5120 /* We failed if we find ZV is already on the screen (scrolling up,
5121 means there's nothing past the end), or if we can't start any
5122 earlier (scrolling down, means there's nothing past the top). */
5123 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
5124 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
5126 if (IT_CHARPOS (it
) == ZV
)
5128 if (it
.current_y
< it
.last_visible_y
5129 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
5130 > it
.last_visible_y
))
5132 /* The last line was only partially visible, make it fully
5134 w
->vscroll
= (it
.last_visible_y
5135 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
5136 adjust_glyphs (it
.f
);
5140 else if (n
< 0) /* could happen with empty buffers */
5141 xsignal0 (Qbeginning_of_buffer
);
5143 xsignal0 (Qend_of_buffer
);
5147 if (w
->vscroll
!= 0)
5148 /* The first line was only partially visible, make it fully
5154 xsignal0 (Qbeginning_of_buffer
);
5157 /* If control gets here, then we vscrolled. */
5159 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
5161 /* Don't try to change the window start below. */
5167 int pos
= IT_CHARPOS (it
);
5170 /* If in the middle of a multi-glyph character move forward to
5171 the next character. */
5172 if (in_display_vector_p (&it
))
5175 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
5178 /* Set the window start, and set up the window for redisplay. */
5179 set_marker_restricted (w
->start
, make_number (pos
),
5181 bytepos
= XMARKER (w
->start
)->bytepos
;
5182 w
->start_at_line_beg
= ((pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n')
5184 w
->update_mode_line
= Qt
;
5185 XSETFASTINT (w
->last_modified
, 0);
5186 XSETFASTINT (w
->last_overlay_modified
, 0);
5187 /* Set force_start so that redisplay_window will run the
5188 window-scroll-functions. */
5189 w
->force_start
= Qt
;
5192 /* The rest of this function uses current_y in a nonstandard way,
5193 not including the height of the header line if any. */
5194 it
.current_y
= it
.vpos
= 0;
5196 /* Move PT out of scroll margins.
5197 This code wants current_y to be zero at the window start position
5198 even if there is a header line. */
5199 this_scroll_margin
= max (0, scroll_margin
);
5200 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->total_lines
) / 4);
5201 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
5205 /* We moved the window start towards ZV, so PT may be now
5206 in the scroll margin at the top. */
5207 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5208 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
5209 && (NILP (Vscroll_preserve_screen_position
)
5210 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5211 /* We found PT at a legitimate height. Leave it alone. */
5213 else if (window_scroll_pixel_based_preserve_y
>= 0)
5215 /* If we have a header line, take account of it.
5216 This is necessary because we set it.current_y to 0, above. */
5217 move_it_to (&it
, -1, -1,
5218 window_scroll_pixel_based_preserve_y
5219 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
5221 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5225 while (it
.current_y
< this_scroll_margin
)
5227 int prev
= it
.current_y
;
5228 move_it_by_lines (&it
, 1, 1);
5229 if (prev
== it
.current_y
)
5232 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5237 int charpos
, bytepos
;
5240 /* Save our position, for the
5241 window_scroll_pixel_based_preserve_y case. */
5242 charpos
= IT_CHARPOS (it
);
5243 bytepos
= IT_BYTEPOS (it
);
5245 /* We moved the window start towards BEGV, so PT may be now
5246 in the scroll margin at the bottom. */
5247 move_it_to (&it
, PT
, -1,
5248 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
5249 - this_scroll_margin
- 1),
5251 MOVE_TO_POS
| MOVE_TO_Y
);
5253 /* Save our position, in case it's correct. */
5254 charpos
= IT_CHARPOS (it
);
5255 bytepos
= IT_BYTEPOS (it
);
5257 /* See if point is on a partially visible line at the end. */
5258 if (it
.what
== IT_EOB
)
5259 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
5262 move_it_by_lines (&it
, 1, 1);
5263 partial_p
= it
.current_y
> it
.last_visible_y
;
5266 if (charpos
== PT
&& !partial_p
5267 && (NILP (Vscroll_preserve_screen_position
)
5268 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5269 /* We found PT before we found the display margin, so PT is ok. */
5271 else if (window_scroll_pixel_based_preserve_y
>= 0)
5273 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5274 start_display (&it
, w
, start
);
5275 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
5276 here because we called start_display again and did not
5277 alter it.current_y this time. */
5278 move_it_to (&it
, -1, -1, window_scroll_pixel_based_preserve_y
, -1,
5280 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5285 /* The last line was only partially visible, so back up two
5286 lines to make sure we're on a fully visible line. */
5288 move_it_by_lines (&it
, -2, 0);
5289 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5292 /* No, the position we saved is OK, so use it. */
5293 SET_PT_BOTH (charpos
, bytepos
);
5299 /* Implementation of window_scroll that works based on screen lines.
5300 See the comment of window_scroll for parameter descriptions. */
5303 window_scroll_line_based (window
, n
, whole
, noerror
)
5309 register struct window
*w
= XWINDOW (window
);
5310 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
5311 register int pos
, pos_byte
;
5312 register int ht
= window_internal_height (w
);
5313 register Lisp_Object tem
;
5317 struct position posit
;
5320 /* If scrolling screen-fulls, compute the number of lines to
5321 scroll from the window's height. */
5323 n
*= max (1, ht
- next_screen_context_lines
);
5325 startpos
= marker_position (w
->start
);
5327 posit
= *compute_motion (startpos
, 0, 0, 0,
5329 -1, XINT (w
->hscroll
),
5331 original_vpos
= posit
.vpos
;
5333 XSETFASTINT (tem
, PT
);
5334 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
5338 Fvertical_motion (make_number (- (ht
/ 2)), window
);
5343 lose
= n
< 0 && PT
== BEGV
;
5344 Fvertical_motion (make_number (n
), window
);
5348 SET_PT_BOTH (opoint
, opoint_byte
);
5355 xsignal0 (Qbeginning_of_buffer
);
5360 int this_scroll_margin
= scroll_margin
;
5362 /* Don't use a scroll margin that is negative or too large. */
5363 if (this_scroll_margin
< 0)
5364 this_scroll_margin
= 0;
5366 if (XINT (w
->total_lines
) < 4 * scroll_margin
)
5367 this_scroll_margin
= XINT (w
->total_lines
) / 4;
5369 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
5370 w
->start_at_line_beg
= bolp
;
5371 w
->update_mode_line
= Qt
;
5372 XSETFASTINT (w
->last_modified
, 0);
5373 XSETFASTINT (w
->last_overlay_modified
, 0);
5374 /* Set force_start so that redisplay_window will run
5375 the window-scroll-functions. */
5376 w
->force_start
= Qt
;
5378 if (!NILP (Vscroll_preserve_screen_position
)
5379 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
5381 SET_PT_BOTH (pos
, pos_byte
);
5382 Fvertical_motion (make_number (original_vpos
), window
);
5384 /* If we scrolled forward, put point enough lines down
5385 that it is outside the scroll margin. */
5390 if (this_scroll_margin
> 0)
5392 SET_PT_BOTH (pos
, pos_byte
);
5393 Fvertical_motion (make_number (this_scroll_margin
), window
);
5399 if (top_margin
<= opoint
)
5400 SET_PT_BOTH (opoint
, opoint_byte
);
5401 else if (!NILP (Vscroll_preserve_screen_position
))
5403 SET_PT_BOTH (pos
, pos_byte
);
5404 Fvertical_motion (make_number (original_vpos
), window
);
5407 SET_PT (top_margin
);
5413 /* If we scrolled backward, put point near the end of the window
5414 but not within the scroll margin. */
5415 SET_PT_BOTH (pos
, pos_byte
);
5416 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
5417 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
5420 bottom_margin
= PT
+ 1;
5422 if (bottom_margin
> opoint
)
5423 SET_PT_BOTH (opoint
, opoint_byte
);
5426 if (!NILP (Vscroll_preserve_screen_position
))
5428 SET_PT_BOTH (pos
, pos_byte
);
5429 Fvertical_motion (make_number (original_vpos
), window
);
5432 Fvertical_motion (make_number (-1), window
);
5441 xsignal0 (Qend_of_buffer
);
5446 /* Scroll selected_window up or down. If N is nil, scroll a
5447 screen-full which is defined as the height of the window minus
5448 next_screen_context_lines. If N is the symbol `-', scroll.
5449 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
5450 up. This is the guts of Fscroll_up and Fscroll_down. */
5453 scroll_command (n
, direction
)
5457 int count
= SPECPDL_INDEX ();
5459 xassert (abs (direction
) == 1);
5461 /* If selected window's buffer isn't current, make it current for
5462 the moment. But don't screw up if window_scroll gets an error. */
5463 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
5465 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5466 Fset_buffer (XWINDOW (selected_window
)->buffer
);
5468 /* Make redisplay consider other windows than just selected_window. */
5469 ++windows_or_buffers_changed
;
5473 window_scroll (selected_window
, direction
, 1, 0);
5474 else if (EQ (n
, Qminus
))
5475 window_scroll (selected_window
, -direction
, 1, 0);
5478 n
= Fprefix_numeric_value (n
);
5479 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
5482 unbind_to (count
, Qnil
);
5485 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
5486 doc
: /* Scroll text of current window upward ARG lines.
5487 If ARG is omitted or nil, scroll upward by a near full screen.
5488 A near full screen is `next-screen-context-lines' less than a full screen.
5489 Negative ARG means scroll downward.
5490 If ARG is the atom `-', scroll downward by nearly full screen.
5491 When calling from a program, supply as argument a number, nil, or `-'. */)
5495 scroll_command (arg
, 1);
5499 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
5500 doc
: /* Scroll text of current window down ARG lines.
5501 If ARG is omitted or nil, scroll down by a near full screen.
5502 A near full screen is `next-screen-context-lines' less than a full screen.
5503 Negative ARG means scroll upward.
5504 If ARG is the atom `-', scroll upward by nearly full screen.
5505 When calling from a program, supply as argument a number, nil, or `-'. */)
5509 scroll_command (arg
, -1);
5513 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
5514 doc
: /* Return the other window for \"other window scroll\" commands.
5515 If `other-window-scroll-buffer' is non-nil, a window
5516 showing that buffer is used.
5517 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5518 specifies the window. This takes precedence over
5519 `other-window-scroll-buffer'. */)
5524 if (MINI_WINDOW_P (XWINDOW (selected_window
))
5525 && !NILP (Vminibuf_scroll_window
))
5526 window
= Vminibuf_scroll_window
;
5527 /* If buffer is specified, scroll that buffer. */
5528 else if (!NILP (Vother_window_scroll_buffer
))
5530 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
5532 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
5536 /* Nothing specified; look for a neighboring window on the same
5538 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
5540 if (EQ (window
, selected_window
))
5541 /* That didn't get us anywhere; look for a window on another
5544 window
= Fnext_window (window
, Qnil
, Qt
);
5545 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
5546 && ! EQ (window
, selected_window
));
5549 CHECK_LIVE_WINDOW (window
);
5551 if (EQ (window
, selected_window
))
5552 error ("There is no other window");
5557 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
5558 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5559 A near full screen is `next-screen-context-lines' less than a full screen.
5560 The next window is the one below the current one; or the one at the top
5561 if the current one is at the bottom. Negative ARG means scroll downward.
5562 If ARG is the atom `-', scroll downward by nearly full screen.
5563 When calling from a program, supply as argument a number, nil, or `-'.
5565 If `other-window-scroll-buffer' is non-nil, scroll the window
5566 showing that buffer, popping the buffer up if necessary.
5567 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5568 specifies the window to scroll. This takes precedence over
5569 `other-window-scroll-buffer'. */)
5575 int count
= SPECPDL_INDEX ();
5577 window
= Fother_window_for_scrolling ();
5578 w
= XWINDOW (window
);
5580 /* Don't screw up if window_scroll gets an error. */
5581 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5582 ++windows_or_buffers_changed
;
5584 Fset_buffer (w
->buffer
);
5585 SET_PT (marker_position (w
->pointm
));
5588 window_scroll (window
, 1, 1, 1);
5589 else if (EQ (arg
, Qminus
))
5590 window_scroll (window
, -1, 1, 1);
5596 window_scroll (window
, XINT (arg
), 0, 1);
5599 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5600 unbind_to (count
, Qnil
);
5605 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "P\np",
5606 doc
: /* Scroll selected window display ARG columns left.
5607 Default for ARG is window width minus 2.
5608 Value is the total amount of leftward horizontal scrolling in
5609 effect after the change.
5610 If SET_MINIMUM is non-nil, the new scroll amount becomes the
5611 lower bound for automatic scrolling, i.e. automatic scrolling
5612 will not scroll a window to a column less than the value returned
5613 by this function. This happens in an interactive call. */)
5615 register Lisp_Object arg
, set_minimum
;
5619 struct window
*w
= XWINDOW (selected_window
);
5622 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5624 arg
= Fprefix_numeric_value (arg
);
5626 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
5627 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5629 if (!NILP (set_minimum
))
5630 w
->min_hscroll
= w
->hscroll
;
5635 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "P\np",
5636 doc
: /* Scroll selected window display ARG columns right.
5637 Default for ARG is window width minus 2.
5638 Value is the total amount of leftward horizontal scrolling in
5639 effect after the change.
5640 If SET_MINIMUM is non-nil, the new scroll amount becomes the
5641 lower bound for automatic scrolling, i.e. automatic scrolling
5642 will not scroll a window to a column less than the value returned
5643 by this function. This happens in an interactive call. */)
5645 register Lisp_Object arg
, set_minimum
;
5649 struct window
*w
= XWINDOW (selected_window
);
5652 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5654 arg
= Fprefix_numeric_value (arg
);
5656 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
5657 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5659 if (!NILP (set_minimum
))
5660 w
->min_hscroll
= w
->hscroll
;
5665 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5666 doc
: /* Return the window which was selected when entering the minibuffer.
5667 Returns nil, if current window is not a minibuffer window. */)
5670 if (minibuf_level
> 0
5671 && MINI_WINDOW_P (XWINDOW (selected_window
))
5672 && WINDOW_LIVE_P (minibuf_selected_window
))
5673 return minibuf_selected_window
;
5678 /* Value is the number of lines actually displayed in window W,
5679 as opposed to its height. */
5682 displayed_window_lines (w
)
5686 struct text_pos start
;
5687 int height
= window_box_height (w
);
5688 struct buffer
*old_buffer
;
5691 if (XBUFFER (w
->buffer
) != current_buffer
)
5693 old_buffer
= current_buffer
;
5694 set_buffer_internal (XBUFFER (w
->buffer
));
5699 /* In case W->start is out of the accessible range, do something
5700 reasonable. This happens in Info mode when Info-scroll-down
5701 calls (recenter -1) while W->start is 1. */
5702 if (XMARKER (w
->start
)->charpos
< BEGV
)
5703 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5704 else if (XMARKER (w
->start
)->charpos
> ZV
)
5705 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
5707 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5709 start_display (&it
, w
, start
);
5710 move_it_vertically (&it
, height
);
5711 bottom_y
= line_bottom_y (&it
);
5713 /* rms: On a non-window display,
5714 the value of it.vpos at the bottom of the screen
5715 seems to be 1 larger than window_box_height (w).
5716 This kludge fixes a bug whereby (move-to-window-line -1)
5717 when ZV is on the last screen line
5718 moves to the previous screen line instead of the last one. */
5719 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5722 /* Add in empty lines at the bottom of the window. */
5723 if (bottom_y
< height
)
5725 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5726 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5730 set_buffer_internal (old_buffer
);
5736 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5737 doc
: /* Center point in window and redisplay frame.
5738 With prefix argument ARG, recenter putting point on screen line ARG
5739 relative to the current window. If ARG is negative, it counts up from the
5740 bottom of the window. (ARG should be less than the height of the window.)
5742 If ARG is omitted or nil, erase the entire frame and then redraw with point
5743 in the center of the current window. If `auto-resize-tool-bars' is set to
5744 `grow-only', this resets the tool-bar's height to the minimum height needed.
5746 Just C-u as prefix means put point in the center of the window
5747 and redisplay normally--don't erase and redraw the frame. */)
5749 register Lisp_Object arg
;
5751 struct window
*w
= XWINDOW (selected_window
);
5752 struct buffer
*buf
= XBUFFER (w
->buffer
);
5753 struct buffer
*obuf
= current_buffer
;
5755 int charpos
, bytepos
;
5757 int this_scroll_margin
;
5759 /* If redisplay is suppressed due to an error, try again. */
5760 obuf
->display_error_modiff
= 0;
5766 /* Invalidate pixel data calculated for all compositions. */
5767 for (i
= 0; i
< n_compositions
; i
++)
5768 composition_table
[i
]->font
= NULL
;
5770 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5772 Fredraw_frame (WINDOW_FRAME (w
));
5773 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5776 else if (CONSP (arg
)) /* Just C-u. */
5780 arg
= Fprefix_numeric_value (arg
);
5785 set_buffer_internal (buf
);
5787 /* Do this after making BUF current
5788 in case scroll_margin is buffer-local. */
5789 this_scroll_margin
= max (0, scroll_margin
);
5790 this_scroll_margin
= min (this_scroll_margin
,
5791 XFASTINT (w
->total_lines
) / 4);
5793 /* Handle centering on a graphical frame specially. Such frames can
5794 have variable-height lines and centering point on the basis of
5795 line counts would lead to strange effects. */
5796 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5803 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5804 start_display (&it
, w
, pt
);
5805 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5806 charpos
= IT_CHARPOS (it
);
5807 bytepos
= IT_BYTEPOS (it
);
5814 int extra_line_spacing
;
5815 int h
= window_box_height (w
);
5817 iarg
= - max (-iarg
, this_scroll_margin
);
5819 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5820 start_display (&it
, w
, pt
);
5822 /* Be sure we have the exact height of the full line containing PT. */
5823 move_it_by_lines (&it
, 0, 1);
5825 /* The amount of pixels we have to move back is the window
5826 height minus what's displayed in the line containing PT,
5827 and the lines below. */
5830 move_it_by_lines (&it
, nlines
, 1);
5832 if (it
.vpos
== nlines
)
5836 /* Last line has no newline */
5837 h
-= line_bottom_y (&it
);
5841 /* Don't reserve space for extra line spacing of last line. */
5842 extra_line_spacing
= it
.max_extra_line_spacing
;
5844 /* If we can't move down NLINES lines because we hit
5845 the end of the buffer, count in some empty lines. */
5846 if (it
.vpos
< nlines
)
5849 extra_line_spacing
= it
.extra_line_spacing
;
5850 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5855 /* Now find the new top line (starting position) of the window. */
5856 start_display (&it
, w
, pt
);
5858 move_it_vertically_backward (&it
, h
);
5860 /* If extra line spacing is present, we may move too far
5861 back. This causes the last line to be only partially
5862 visible (which triggers redisplay to recenter that line
5863 in the middle), so move forward.
5864 But ignore extra line spacing on last line, as it is not
5865 considered to be part of the visible height of the line.
5867 h
+= extra_line_spacing
;
5868 while (-it
.current_y
> h
)
5869 move_it_by_lines (&it
, 1, 1);
5871 charpos
= IT_CHARPOS (it
);
5872 bytepos
= IT_BYTEPOS (it
);
5876 struct position pos
;
5878 iarg
= max (iarg
, this_scroll_margin
);
5880 pos
= *vmotion (PT
, -iarg
, w
);
5881 charpos
= pos
.bufpos
;
5882 bytepos
= pos
.bytepos
;
5887 struct position pos
;
5888 int ht
= window_internal_height (w
);
5895 /* Don't let it get into the margin at either top or bottom. */
5896 iarg
= max (iarg
, this_scroll_margin
);
5897 iarg
= min (iarg
, ht
- this_scroll_margin
- 1);
5899 pos
= *vmotion (PT
, - iarg
, w
);
5900 charpos
= pos
.bufpos
;
5901 bytepos
= pos
.bytepos
;
5904 /* Set the new window start. */
5905 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
5906 w
->window_end_valid
= Qnil
;
5908 w
->optional_new_start
= Qt
;
5910 if (bytepos
== BEGV_BYTE
|| FETCH_BYTE (bytepos
- 1) == '\n')
5911 w
->start_at_line_beg
= Qt
;
5913 w
->start_at_line_beg
= Qnil
;
5915 set_buffer_internal (obuf
);
5920 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5922 doc
: /* Return the height in lines of the text display area of WINDOW.
5923 WINDOW defaults to the selected window.
5924 This doesn't include the mode-line (or header-line if any) or any
5925 partial-height lines in the text display area. */)
5929 struct window
*w
= decode_window (window
);
5930 int pixel_height
= window_box_height (w
);
5931 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5932 return make_number (line_height
);
5937 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5939 doc
: /* Position point relative to window.
5940 With no argument, position point at center of window.
5941 An argument specifies vertical position within the window;
5942 zero means top of window, negative means relative to bottom of window. */)
5946 struct window
*w
= XWINDOW (selected_window
);
5950 int this_scroll_margin
;
5953 window
= selected_window
;
5954 start
= marker_position (w
->start
);
5955 if (start
< BEGV
|| start
> ZV
)
5957 int height
= window_internal_height (w
);
5958 Fvertical_motion (make_number (- (height
/ 2)), window
);
5959 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
5960 w
->start_at_line_beg
= Fbolp ();
5961 w
->force_start
= Qt
;
5964 Fgoto_char (w
->start
);
5966 lines
= displayed_window_lines (w
);
5969 this_scroll_margin
= max (0, scroll_margin
);
5970 this_scroll_margin
= min (this_scroll_margin
, lines
/ 4);
5974 XSETFASTINT (arg
, lines
/ 2);
5977 int iarg
= XINT (Fprefix_numeric_value (arg
));
5980 iarg
= iarg
+ lines
;
5982 #if 0 /* This code would prevent move-to-window-line from moving point
5983 to a place inside the scroll margins (which would cause the
5984 next redisplay to scroll). I wrote this code, but then concluded
5985 it is probably better not to install it. However, it is here
5986 inside #if 0 so as not to lose it. -- rms. */
5988 /* Don't let it get into the margin at either top or bottom. */
5989 iarg
= max (iarg
, this_scroll_margin
);
5990 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
5993 arg
= make_number (iarg
);
5996 /* Skip past a partially visible first line. */
5998 XSETINT (arg
, XINT (arg
) + 1);
6000 return Fvertical_motion (arg
, window
);
6005 /***********************************************************************
6006 Window Configuration
6007 ***********************************************************************/
6009 struct save_window_data
6011 EMACS_INT size_from_Lisp_Vector_struct
;
6012 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
6013 Lisp_Object frame_cols
, frame_lines
, frame_menu_bar_lines
;
6014 Lisp_Object frame_tool_bar_lines
;
6015 Lisp_Object selected_frame
;
6016 Lisp_Object current_window
;
6017 Lisp_Object current_buffer
;
6018 Lisp_Object minibuf_scroll_window
;
6019 Lisp_Object minibuf_selected_window
;
6020 Lisp_Object root_window
;
6021 Lisp_Object focus_frame
;
6022 /* Record the values of window-min-width and window-min-height
6023 so that window sizes remain consistent with them. */
6024 Lisp_Object min_width
, min_height
;
6025 /* A vector, each of whose elements is a struct saved_window
6027 Lisp_Object saved_windows
;
6030 /* This is saved as a Lisp_Vector */
6033 /* these first two must agree with struct Lisp_Vector in lisp.h */
6034 EMACS_INT size_from_Lisp_Vector_struct
;
6035 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
6038 Lisp_Object buffer
, start
, pointm
, mark
;
6039 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
6040 Lisp_Object hscroll
, min_hscroll
;
6041 Lisp_Object parent
, prev
;
6042 Lisp_Object start_at_line_beg
;
6043 Lisp_Object display_table
;
6044 Lisp_Object orig_top_line
, orig_total_lines
;
6045 Lisp_Object left_margin_cols
, right_margin_cols
;
6046 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
6047 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
;
6048 Lisp_Object dedicated
;
6051 #define SAVED_WINDOW_N(swv,n) \
6052 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
6054 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
6055 doc
: /* Return t if OBJECT is a window-configuration object. */)
6059 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
6062 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
6063 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
6067 register struct save_window_data
*data
;
6068 struct Lisp_Vector
*saved_windows
;
6070 CHECK_WINDOW_CONFIGURATION (config
);
6072 data
= (struct save_window_data
*) XVECTOR (config
);
6073 saved_windows
= XVECTOR (data
->saved_windows
);
6074 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6077 DEFUN ("set-window-configuration", Fset_window_configuration
,
6078 Sset_window_configuration
, 1, 1, 0,
6079 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
6080 CONFIGURATION must be a value previously returned
6081 by `current-window-configuration' (which see).
6082 If CONFIGURATION was made from a frame that is now deleted,
6083 only frame-independent values can be restored. In this case,
6084 the return value is nil. Otherwise the value is t. */)
6086 Lisp_Object configuration
;
6088 register struct save_window_data
*data
;
6089 struct Lisp_Vector
*saved_windows
;
6090 Lisp_Object new_current_buffer
;
6095 CHECK_WINDOW_CONFIGURATION (configuration
);
6097 data
= (struct save_window_data
*) XVECTOR (configuration
);
6098 saved_windows
= XVECTOR (data
->saved_windows
);
6100 new_current_buffer
= data
->current_buffer
;
6101 if (NILP (XBUFFER (new_current_buffer
)->name
))
6102 new_current_buffer
= Qnil
;
6105 if (XBUFFER (new_current_buffer
) == current_buffer
)
6106 /* The code further down "preserves point" by saving here PT in
6107 old_point and then setting it later back into PT. When the
6108 current-selected-window and the final-selected-window both show
6109 the current buffer, this suffers from the problem that the
6110 current PT is the window-point of the current-selected-window,
6111 while the final PT is the point of the final-selected-window, so
6112 this copy from one PT to the other would end up moving the
6113 window-point of the final-selected-window to the window-point of
6114 the current-selected-window. So we have to be careful which
6115 point of the current-buffer we copy into old_point. */
6116 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
6117 && WINDOWP (selected_window
)
6118 && EQ (XWINDOW (selected_window
)->buffer
, new_current_buffer
)
6119 && !EQ (selected_window
, data
->current_window
))
6120 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
6124 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
6125 point in new_current_buffer as of the last time this buffer was
6126 used. This can be non-deterministic since it can be changed by
6127 things like jit-lock by mere temporary selection of some random
6128 window that happens to show this buffer.
6129 So if possible we want this arbitrary choice of "which point" to
6130 be the one from the to-be-selected-window so as to prevent this
6131 window's cursor from being copied from another window. */
6132 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
6133 /* If current_window = selected_window, its point is in BUF_PT. */
6134 && !EQ (selected_window
, data
->current_window
))
6135 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
6137 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
6140 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6143 /* If f is a dead frame, don't bother rebuilding its window tree.
6144 However, there is other stuff we should still try to do below. */
6145 if (FRAME_LIVE_P (f
))
6147 register struct window
*w
;
6148 register struct saved_window
*p
;
6149 struct window
*root_window
;
6150 struct window
**leaf_windows
;
6154 /* If the frame has been resized since this window configuration was
6155 made, we change the frame to the size specified in the
6156 configuration, restore the configuration, and then resize it
6157 back. We keep track of the prevailing height in these variables. */
6158 int previous_frame_lines
= FRAME_LINES (f
);
6159 int previous_frame_cols
= FRAME_COLS (f
);
6160 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6161 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6163 /* The mouse highlighting code could get screwed up
6164 if it runs during this. */
6167 if (XFASTINT (data
->frame_lines
) != previous_frame_lines
6168 || XFASTINT (data
->frame_cols
) != previous_frame_cols
)
6169 change_frame_size (f
, XFASTINT (data
->frame_lines
),
6170 XFASTINT (data
->frame_cols
), 0, 0, 0);
6171 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
6172 if (XFASTINT (data
->frame_menu_bar_lines
)
6173 != previous_frame_menu_bar_lines
)
6174 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, make_number (0));
6175 #ifdef HAVE_WINDOW_SYSTEM
6176 if (XFASTINT (data
->frame_tool_bar_lines
)
6177 != previous_frame_tool_bar_lines
)
6178 x_set_tool_bar_lines (f
, data
->frame_tool_bar_lines
, make_number (0));
6182 /* "Swap out" point from the selected window's buffer
6183 into the window itself. (Normally the pointm of the selected
6184 window holds garbage.) We do this now, before
6185 restoring the window contents, and prevent it from
6186 being done later on when we select a new window. */
6187 if (! NILP (XWINDOW (selected_window
)->buffer
))
6189 w
= XWINDOW (selected_window
);
6190 set_marker_both (w
->pointm
,
6192 BUF_PT (XBUFFER (w
->buffer
)),
6193 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6196 windows_or_buffers_changed
++;
6197 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
6199 /* Problem: Freeing all matrices and later allocating them again
6200 is a serious redisplay flickering problem. What we would
6201 really like to do is to free only those matrices not reused
6203 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6205 = (struct window
**) alloca (count_windows (root_window
)
6206 * sizeof (struct window
*));
6207 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
6209 /* Temporarily avoid any problems with windows that are smaller
6210 than they are supposed to be. */
6211 window_min_height
= 1;
6212 window_min_width
= 1;
6215 Mark all windows now on frame as "deleted".
6216 Restoring the new configuration "undeletes" any that are in it.
6218 Save their current buffers in their height fields, since we may
6219 need it later, if a buffer saved in the configuration is now
6221 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6223 for (k
= 0; k
< saved_windows
->size
; k
++)
6225 p
= SAVED_WINDOW_N (saved_windows
, k
);
6226 w
= XWINDOW (p
->window
);
6229 if (!NILP (p
->parent
))
6230 w
->parent
= SAVED_WINDOW_N (saved_windows
,
6231 XFASTINT (p
->parent
))->window
;
6235 if (!NILP (p
->prev
))
6237 w
->prev
= SAVED_WINDOW_N (saved_windows
,
6238 XFASTINT (p
->prev
))->window
;
6239 XWINDOW (w
->prev
)->next
= p
->window
;
6244 if (!NILP (w
->parent
))
6246 if (EQ (p
->total_cols
, XWINDOW (w
->parent
)->total_cols
))
6248 XWINDOW (w
->parent
)->vchild
= p
->window
;
6249 XWINDOW (w
->parent
)->hchild
= Qnil
;
6253 XWINDOW (w
->parent
)->hchild
= p
->window
;
6254 XWINDOW (w
->parent
)->vchild
= Qnil
;
6259 /* If we squirreled away the buffer in the window's height,
6261 if (BUFFERP (w
->total_lines
))
6262 w
->buffer
= w
->total_lines
;
6263 w
->left_col
= p
->left_col
;
6264 w
->top_line
= p
->top_line
;
6265 w
->total_cols
= p
->total_cols
;
6266 w
->total_lines
= p
->total_lines
;
6267 w
->hscroll
= p
->hscroll
;
6268 w
->min_hscroll
= p
->min_hscroll
;
6269 w
->display_table
= p
->display_table
;
6270 w
->orig_top_line
= p
->orig_top_line
;
6271 w
->orig_total_lines
= p
->orig_total_lines
;
6272 w
->left_margin_cols
= p
->left_margin_cols
;
6273 w
->right_margin_cols
= p
->right_margin_cols
;
6274 w
->left_fringe_width
= p
->left_fringe_width
;
6275 w
->right_fringe_width
= p
->right_fringe_width
;
6276 w
->fringes_outside_margins
= p
->fringes_outside_margins
;
6277 w
->scroll_bar_width
= p
->scroll_bar_width
;
6278 w
->vertical_scroll_bar_type
= p
->vertical_scroll_bar_type
;
6279 w
->dedicated
= p
->dedicated
;
6280 XSETFASTINT (w
->last_modified
, 0);
6281 XSETFASTINT (w
->last_overlay_modified
, 0);
6283 /* Reinstall the saved buffer and pointers into it. */
6284 if (NILP (p
->buffer
))
6285 w
->buffer
= p
->buffer
;
6288 if (!NILP (XBUFFER (p
->buffer
)->name
))
6289 /* If saved buffer is alive, install it. */
6291 w
->buffer
= p
->buffer
;
6292 w
->start_at_line_beg
= p
->start_at_line_beg
;
6293 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
6294 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
6295 Fset_marker (XBUFFER (w
->buffer
)->mark
,
6296 p
->mark
, w
->buffer
);
6298 /* As documented in Fcurrent_window_configuration, don't
6299 restore the location of point in the buffer which was
6300 current when the window configuration was recorded. */
6301 if (!EQ (p
->buffer
, new_current_buffer
)
6302 && XBUFFER (p
->buffer
) == current_buffer
)
6303 Fgoto_char (w
->pointm
);
6305 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
6306 /* Else unless window has a live buffer, get one. */
6308 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
6309 /* This will set the markers to beginning of visible
6311 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
6312 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
6313 w
->start_at_line_beg
= Qt
;
6316 /* Keeping window's old buffer; make sure the markers
6319 /* Set window markers at start of visible range. */
6320 if (XMARKER (w
->start
)->buffer
== 0)
6321 set_marker_restricted (w
->start
, make_number (0),
6323 if (XMARKER (w
->pointm
)->buffer
== 0)
6324 set_marker_restricted_both (w
->pointm
, w
->buffer
,
6325 BUF_PT (XBUFFER (w
->buffer
)),
6326 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6327 w
->start_at_line_beg
= Qt
;
6332 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
6333 /* Prevent "swapping out point" in the old selected window
6334 using the buffer that has been restored into it.
6335 We already swapped out point that from that window's old buffer. */
6336 selected_window
= Qnil
;
6338 /* Arrange *not* to restore point in the buffer that was
6339 current when the window configuration was saved. */
6340 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
6341 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
6342 make_number (old_point
),
6343 XWINDOW (data
->current_window
)->buffer
);
6345 Fselect_window (data
->current_window
, Qnil
);
6346 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
6349 if (NILP (data
->focus_frame
)
6350 || (FRAMEP (data
->focus_frame
)
6351 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
6352 Fredirect_frame_focus (frame
, data
->focus_frame
);
6354 #if 0 /* I don't understand why this is needed, and it causes problems
6355 when the frame's old selected window has been deleted. */
6356 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
6357 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
6361 /* Set the screen height to the value it had before this function. */
6362 if (previous_frame_lines
!= FRAME_LINES (f
)
6363 || previous_frame_cols
!= FRAME_COLS (f
))
6364 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
6366 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
6367 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
6368 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
6370 #ifdef HAVE_WINDOW_SYSTEM
6371 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
6372 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
6377 /* Now, free glyph matrices in windows that were not reused. */
6378 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
6380 if (NILP (leaf_windows
[i
]->buffer
))
6382 /* Assert it's not reused as a combination. */
6383 xassert (NILP (leaf_windows
[i
]->hchild
)
6384 && NILP (leaf_windows
[i
]->vchild
));
6385 free_window_matrices (leaf_windows
[i
]);
6387 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
6395 /* Fselect_window will have made f the selected frame, so we
6396 reselect the proper frame here. Fhandle_switch_frame will change the
6397 selected window too, but that doesn't make the call to
6398 Fselect_window above totally superfluous; it still sets f's
6400 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
6401 do_switch_frame (data
->selected_frame
, 0, 0);
6403 if (! NILP (Vwindow_configuration_change_hook
)
6404 && ! NILP (Vrun_hooks
))
6405 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
6408 if (!NILP (new_current_buffer
))
6409 Fset_buffer (new_current_buffer
);
6411 /* Restore the minimum heights recorded in the configuration. */
6412 window_min_height
= XINT (data
->min_height
);
6413 window_min_width
= XINT (data
->min_width
);
6415 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
6416 minibuf_selected_window
= data
->minibuf_selected_window
;
6418 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
6421 /* Mark all windows now on frame as deleted
6422 by setting their buffers to nil. */
6425 delete_all_subwindows (w
)
6426 register struct window
*w
;
6428 if (!NILP (w
->next
))
6429 delete_all_subwindows (XWINDOW (w
->next
));
6430 if (!NILP (w
->vchild
))
6431 delete_all_subwindows (XWINDOW (w
->vchild
));
6432 if (!NILP (w
->hchild
))
6433 delete_all_subwindows (XWINDOW (w
->hchild
));
6435 w
->total_lines
= w
->buffer
; /* See Fset_window_configuration for excuse. */
6437 if (!NILP (w
->buffer
))
6440 /* We set all three of these fields to nil, to make sure that we can
6441 distinguish this dead window from any live window. Live leaf
6442 windows will have buffer set, and combination windows will have
6443 vchild or hchild set. */
6448 Vwindow_list
= Qnil
;
6452 count_windows (window
)
6453 register struct window
*window
;
6455 register int count
= 1;
6456 if (!NILP (window
->next
))
6457 count
+= count_windows (XWINDOW (window
->next
));
6458 if (!NILP (window
->vchild
))
6459 count
+= count_windows (XWINDOW (window
->vchild
));
6460 if (!NILP (window
->hchild
))
6461 count
+= count_windows (XWINDOW (window
->hchild
));
6466 /* Fill vector FLAT with leaf windows under W, starting at index I.
6467 Value is last index + 1. */
6470 get_leaf_windows (w
, flat
, i
)
6472 struct window
**flat
;
6477 if (!NILP (w
->hchild
))
6478 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
6479 else if (!NILP (w
->vchild
))
6480 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
6484 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6491 /* Return a pointer to the glyph W's physical cursor is on. Value is
6492 null if W's current matrix is invalid, so that no meaningfull glyph
6496 get_phys_cursor_glyph (w
)
6499 struct glyph_row
*row
;
6500 struct glyph
*glyph
;
6502 if (w
->phys_cursor
.vpos
>= 0
6503 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
6504 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
6506 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
6507 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
6516 save_window_save (window
, vector
, i
)
6518 struct Lisp_Vector
*vector
;
6521 register struct saved_window
*p
;
6522 register struct window
*w
;
6523 register Lisp_Object tem
;
6525 for (;!NILP (window
); window
= w
->next
)
6527 p
= SAVED_WINDOW_N (vector
, i
);
6528 w
= XWINDOW (window
);
6530 XSETFASTINT (w
->temslot
, i
); i
++;
6532 p
->buffer
= w
->buffer
;
6533 p
->left_col
= w
->left_col
;
6534 p
->top_line
= w
->top_line
;
6535 p
->total_cols
= w
->total_cols
;
6536 p
->total_lines
= w
->total_lines
;
6537 p
->hscroll
= w
->hscroll
;
6538 p
->min_hscroll
= w
->min_hscroll
;
6539 p
->display_table
= w
->display_table
;
6540 p
->orig_top_line
= w
->orig_top_line
;
6541 p
->orig_total_lines
= w
->orig_total_lines
;
6542 p
->left_margin_cols
= w
->left_margin_cols
;
6543 p
->right_margin_cols
= w
->right_margin_cols
;
6544 p
->left_fringe_width
= w
->left_fringe_width
;
6545 p
->right_fringe_width
= w
->right_fringe_width
;
6546 p
->fringes_outside_margins
= w
->fringes_outside_margins
;
6547 p
->scroll_bar_width
= w
->scroll_bar_width
;
6548 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
6549 p
->dedicated
= w
->dedicated
;
6550 if (!NILP (w
->buffer
))
6552 /* Save w's value of point in the window configuration.
6553 If w is the selected window, then get the value of point
6554 from the buffer; pointm is garbage in the selected window. */
6555 if (EQ (window
, selected_window
))
6557 p
->pointm
= Fmake_marker ();
6558 set_marker_both (p
->pointm
, w
->buffer
,
6559 BUF_PT (XBUFFER (w
->buffer
)),
6560 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6563 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
6565 p
->start
= Fcopy_marker (w
->start
, Qnil
);
6566 p
->start_at_line_beg
= w
->start_at_line_beg
;
6568 tem
= XBUFFER (w
->buffer
)->mark
;
6569 p
->mark
= Fcopy_marker (tem
, Qnil
);
6576 p
->start_at_line_beg
= Qnil
;
6579 if (NILP (w
->parent
))
6582 p
->parent
= XWINDOW (w
->parent
)->temslot
;
6587 p
->prev
= XWINDOW (w
->prev
)->temslot
;
6589 if (!NILP (w
->vchild
))
6590 i
= save_window_save (w
->vchild
, vector
, i
);
6591 if (!NILP (w
->hchild
))
6592 i
= save_window_save (w
->hchild
, vector
, i
);
6598 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
6599 Scurrent_window_configuration
, 0, 1, 0,
6600 doc
: /* Return an object representing the current window configuration of FRAME.
6601 If FRAME is nil or omitted, use the selected frame.
6602 This describes the number of windows, their sizes and current buffers,
6603 and for each displayed buffer, where display starts, and the positions of
6604 point and mark. An exception is made for point in the current buffer:
6605 its value is -not- saved.
6606 This also records the currently selected frame, and FRAME's focus
6607 redirection (see `redirect-frame-focus'). */)
6611 register Lisp_Object tem
;
6612 register int n_windows
;
6613 register struct save_window_data
*data
;
6614 register struct Lisp_Vector
*vec
;
6619 frame
= selected_frame
;
6620 CHECK_LIVE_FRAME (frame
);
6623 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6624 vec
= allocate_other_vector (VECSIZE (struct save_window_data
));
6625 data
= (struct save_window_data
*)vec
;
6627 XSETFASTINT (data
->frame_cols
, FRAME_COLS (f
));
6628 XSETFASTINT (data
->frame_lines
, FRAME_LINES (f
));
6629 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
6630 XSETFASTINT (data
->frame_tool_bar_lines
, FRAME_TOOL_BAR_LINES (f
));
6631 data
->selected_frame
= selected_frame
;
6632 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6633 XSETBUFFER (data
->current_buffer
, current_buffer
);
6634 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6635 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6636 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6637 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6638 XSETINT (data
->min_height
, window_min_height
);
6639 XSETINT (data
->min_width
, window_min_width
);
6640 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
6641 data
->saved_windows
= tem
;
6642 for (i
= 0; i
< n_windows
; i
++)
6643 XVECTOR (tem
)->contents
[i
]
6644 = Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
);
6645 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6646 XSETWINDOW_CONFIGURATION (tem
, data
);
6650 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
6652 doc
: /* Execute BODY, preserving window sizes and contents.
6653 Return the value of the last form in BODY.
6654 Restore which buffer appears in which window, where display starts,
6655 and the value of point and mark for each window.
6656 Also restore the choice of selected window.
6657 Also restore which buffer is current.
6658 Does not restore the value of point in current buffer.
6659 usage: (save-window-excursion BODY...) */)
6663 register Lisp_Object val
;
6664 register int count
= SPECPDL_INDEX ();
6666 record_unwind_protect (Fset_window_configuration
,
6667 Fcurrent_window_configuration (Qnil
));
6668 val
= Fprogn (args
);
6669 return unbind_to (count
, val
);
6674 /***********************************************************************
6676 ***********************************************************************/
6682 Lisp_Object tail
= Qnil
;
6683 Lisp_Object result
= Qnil
;
6690 if (!NILP (w
->hchild
))
6691 wn
= Fcons (Qnil
, Fcons (Fwindow_edges (wn
),
6692 window_tree (XWINDOW (w
->hchild
))));
6693 else if (!NILP (w
->vchild
))
6694 wn
= Fcons (Qt
, Fcons (Fwindow_edges (wn
),
6695 window_tree (XWINDOW (w
->vchild
))));
6699 result
= tail
= Fcons (wn
, Qnil
);
6703 XSETCDR (tail
, Fcons (wn
, Qnil
));
6707 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6715 DEFUN ("window-tree", Fwindow_tree
, Swindow_tree
,
6717 doc
: /* Return the window tree for frame FRAME.
6719 The return value is a list of the form (ROOT MINI), where ROOT
6720 represents the window tree of the frame's root window, and MINI
6721 is the frame's minibuffer window.
6723 If the root window is not split, ROOT is the root window itself.
6724 Otherwise, ROOT is a list (DIR EDGES W1 W2 ...) where DIR is nil for a
6725 horizontal split, and t for a vertical split, EDGES gives the combined
6726 size and position of the subwindows in the split, and the rest of the
6727 elements are the subwindows in the split. Each of the subwindows may
6728 again be a window or a list representing a window split, and so on.
6729 EDGES is a list \(LEFT TOP RIGHT BOTTOM) as returned by `window-edges'.
6731 If FRAME is nil or omitted, return information on the currently
6739 frame
= selected_frame
;
6741 CHECK_FRAME (frame
);
6744 if (!FRAME_LIVE_P (f
))
6747 return window_tree (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6751 /***********************************************************************
6753 ***********************************************************************/
6755 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6757 doc
: /* Set width of marginal areas of window WINDOW.
6758 If WINDOW is nil, set margins of the currently selected window.
6759 Second arg LEFT-WIDTH specifies the number of character cells to
6760 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6761 does the same for the right marginal area. A nil width parameter
6762 means no margin. */)
6763 (window
, left_width
, right_width
)
6764 Lisp_Object window
, left_width
, right_width
;
6766 struct window
*w
= decode_window (window
);
6768 /* Translate negative or zero widths to nil.
6769 Margins that are too wide have to be checked elsewhere. */
6771 if (!NILP (left_width
))
6773 CHECK_NUMBER (left_width
);
6774 if (XINT (left_width
) <= 0)
6778 if (!NILP (right_width
))
6780 CHECK_NUMBER (right_width
);
6781 if (XINT (right_width
) <= 0)
6785 if (!EQ (w
->left_margin_cols
, left_width
)
6786 || !EQ (w
->right_margin_cols
, right_width
))
6788 w
->left_margin_cols
= left_width
;
6789 w
->right_margin_cols
= right_width
;
6791 adjust_window_margins (w
);
6793 ++windows_or_buffers_changed
;
6794 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6801 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6803 doc
: /* Get width of marginal areas of window WINDOW.
6804 If WINDOW is omitted or nil, use the currently selected window.
6805 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6806 If a marginal area does not exist, its width will be returned
6811 struct window
*w
= decode_window (window
);
6812 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
6817 /***********************************************************************
6819 ***********************************************************************/
6821 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6823 doc
: /* Set the fringe widths of window WINDOW.
6824 If WINDOW is nil, set the fringe widths of the currently selected
6826 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6827 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6828 fringe width. If a fringe width arg is nil, that means to use the
6829 frame's default fringe width. Default fringe widths can be set with
6830 the command `set-fringe-style'.
6831 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6832 outside of the display margins. By default, fringes are drawn between
6833 display marginal areas and the text area. */)
6834 (window
, left_width
, right_width
, outside_margins
)
6835 Lisp_Object window
, left_width
, right_width
, outside_margins
;
6837 struct window
*w
= decode_window (window
);
6839 if (!NILP (left_width
))
6840 CHECK_NATNUM (left_width
);
6841 if (!NILP (right_width
))
6842 CHECK_NATNUM (right_width
);
6844 /* Do nothing on a tty. */
6845 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6846 && (!EQ (w
->left_fringe_width
, left_width
)
6847 || !EQ (w
->right_fringe_width
, right_width
)
6848 || !EQ (w
->fringes_outside_margins
, outside_margins
)))
6850 w
->left_fringe_width
= left_width
;
6851 w
->right_fringe_width
= right_width
;
6852 w
->fringes_outside_margins
= outside_margins
;
6854 adjust_window_margins (w
);
6856 clear_glyph_matrix (w
->current_matrix
);
6857 w
->window_end_valid
= Qnil
;
6859 ++windows_or_buffers_changed
;
6860 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6867 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6869 doc
: /* Get width of fringes of window WINDOW.
6870 If WINDOW is omitted or nil, use the currently selected window.
6871 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6875 struct window
*w
= decode_window (window
);
6877 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6878 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6879 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
6880 ? Qt
: Qnil
), Qnil
)));
6885 /***********************************************************************
6887 ***********************************************************************/
6889 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
, Sset_window_scroll_bars
,
6891 doc
: /* Set width and type of scroll bars of window WINDOW.
6892 If window is nil, set scroll bars of the currently selected window.
6893 Second parameter WIDTH specifies the pixel width for the scroll bar;
6894 this is automatically adjusted to a multiple of the frame column width.
6895 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6896 bar: left, right, or nil.
6897 If WIDTH is nil, use the frame's scroll-bar width.
6898 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6899 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6900 (window
, width
, vertical_type
, horizontal_type
)
6901 Lisp_Object window
, width
, vertical_type
, horizontal_type
;
6903 struct window
*w
= decode_window (window
);
6907 CHECK_NATNUM (width
);
6909 if (XINT (width
) == 0)
6910 vertical_type
= Qnil
;
6913 if (!(NILP (vertical_type
)
6914 || EQ (vertical_type
, Qleft
)
6915 || EQ (vertical_type
, Qright
)
6916 || EQ (vertical_type
, Qt
)))
6917 error ("Invalid type of vertical scroll bar");
6919 if (!EQ (w
->scroll_bar_width
, width
)
6920 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6922 w
->scroll_bar_width
= width
;
6923 w
->vertical_scroll_bar_type
= vertical_type
;
6925 adjust_window_margins (w
);
6927 clear_glyph_matrix (w
->current_matrix
);
6928 w
->window_end_valid
= Qnil
;
6930 ++windows_or_buffers_changed
;
6931 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6938 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6940 doc
: /* Get width and type of scroll bars of window WINDOW.
6941 If WINDOW is omitted or nil, use the currently selected window.
6942 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6943 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6948 struct window
*w
= decode_window (window
);
6949 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6950 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6951 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6952 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6953 Fcons (w
->vertical_scroll_bar_type
,
6954 Fcons (Qnil
, Qnil
))));
6959 /***********************************************************************
6961 ***********************************************************************/
6963 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6964 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6965 Use the selected window if WINDOW is nil or omitted.
6966 Normally, value is a multiple of the canonical character height of WINDOW;
6967 optional second arg PIXELS-P means value is measured in pixels. */)
6969 Lisp_Object window
, pixels_p
;
6976 window
= selected_window
;
6978 CHECK_WINDOW (window
);
6979 w
= XWINDOW (window
);
6980 f
= XFRAME (w
->frame
);
6982 if (FRAME_WINDOW_P (f
))
6983 result
= (NILP (pixels_p
)
6984 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6985 : make_number (-w
->vscroll
));
6987 result
= make_number (0);
6992 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6994 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6995 WINDOW nil means use the selected window. Normally, VSCROLL is a
6996 non-negative multiple of the canonical character height of WINDOW;
6997 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
6998 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6999 corresponds to an integral number of pixels. The return value is the
7000 result of this rounding.
7001 If PIXELS-P is non-nil, the return value is VSCROLL. */)
7002 (window
, vscroll
, pixels_p
)
7003 Lisp_Object window
, vscroll
, pixels_p
;
7009 window
= selected_window
;
7011 CHECK_WINDOW (window
);
7012 CHECK_NUMBER_OR_FLOAT (vscroll
);
7014 w
= XWINDOW (window
);
7015 f
= XFRAME (w
->frame
);
7017 if (FRAME_WINDOW_P (f
))
7019 int old_dy
= w
->vscroll
;
7021 w
->vscroll
= - (NILP (pixels_p
)
7022 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
7023 : XFLOATINT (vscroll
));
7024 w
->vscroll
= min (w
->vscroll
, 0);
7026 if (w
->vscroll
!= old_dy
)
7028 /* Adjust glyph matrix of the frame if the virtual display
7029 area becomes larger than before. */
7030 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
7033 /* Prevent redisplay shortcuts. */
7034 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
7038 return Fwindow_vscroll (window
, pixels_p
);
7042 /* Call FN for all leaf windows on frame F. FN is called with the
7043 first argument being a pointer to the leaf window, and with
7044 additional argument USER_DATA. Stops when FN returns 0. */
7047 foreach_window (f
, fn
, user_data
)
7049 int (* fn
) P_ ((struct window
*, void *));
7052 /* Fdelete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
7053 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
7054 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
7058 /* Helper function for foreach_window. Call FN for all leaf windows
7059 reachable from W. FN is called with the first argument being a
7060 pointer to the leaf window, and with additional argument USER_DATA.
7061 Stop when FN returns 0. Value is 0 if stopped by FN. */
7064 foreach_window_1 (w
, fn
, user_data
)
7066 int (* fn
) P_ ((struct window
*, void *));
7071 for (cont
= 1; w
&& cont
;)
7073 if (!NILP (w
->hchild
))
7074 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
7075 else if (!NILP (w
->vchild
))
7076 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
7078 cont
= fn (w
, user_data
);
7080 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
7087 /* Freeze or unfreeze the window start of W unless it is a
7088 mini-window or the selected window. FREEZE_P non-null means freeze
7089 the window start. */
7092 freeze_window_start (w
, freeze_p
)
7096 if (w
== XWINDOW (selected_window
)
7097 || MINI_WINDOW_P (w
)
7098 || (MINI_WINDOW_P (XWINDOW (selected_window
))
7099 && ! NILP (Vminibuf_scroll_window
)
7100 && w
== XWINDOW (Vminibuf_scroll_window
)))
7103 w
->frozen_window_start_p
= freeze_p
!= NULL
;
7108 /* Freeze or unfreeze the window starts of all leaf windows on frame
7109 F, except the selected window and a mini-window. FREEZE_P non-zero
7110 means freeze the window start. */
7113 freeze_window_starts (f
, freeze_p
)
7117 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
7121 /***********************************************************************
7123 ***********************************************************************/
7125 /* Return 1 if window configurations C1 and C2
7126 describe the same state of affairs. This is used by Fequal. */
7129 compare_window_configurations (c1
, c2
, ignore_positions
)
7131 int ignore_positions
;
7133 register struct save_window_data
*d1
, *d2
;
7134 struct Lisp_Vector
*sw1
, *sw2
;
7137 CHECK_WINDOW_CONFIGURATION (c1
);
7138 CHECK_WINDOW_CONFIGURATION (c2
);
7140 d1
= (struct save_window_data
*) XVECTOR (c1
);
7141 d2
= (struct save_window_data
*) XVECTOR (c2
);
7142 sw1
= XVECTOR (d1
->saved_windows
);
7143 sw2
= XVECTOR (d2
->saved_windows
);
7145 if (! EQ (d1
->frame_cols
, d2
->frame_cols
))
7147 if (! EQ (d1
->frame_lines
, d2
->frame_lines
))
7149 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
7151 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
7153 /* Don't compare the current_window field directly.
7154 Instead see w1_is_current and w2_is_current, below. */
7155 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
7157 if (! ignore_positions
)
7159 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
7161 if (! EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
))
7164 /* Don't compare the root_window field.
7165 We don't require the two configurations
7166 to use the same window object,
7167 and the two root windows must be equivalent
7168 if everything else compares equal. */
7169 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
7171 if (! EQ (d1
->min_width
, d2
->min_width
))
7173 if (! EQ (d1
->min_height
, d2
->min_height
))
7176 /* Verify that the two confis have the same number of windows. */
7177 if (sw1
->size
!= sw2
->size
)
7180 for (i
= 0; i
< sw1
->size
; i
++)
7182 struct saved_window
*p1
, *p2
;
7183 int w1_is_current
, w2_is_current
;
7185 p1
= SAVED_WINDOW_N (sw1
, i
);
7186 p2
= SAVED_WINDOW_N (sw2
, i
);
7188 /* Verify that the current windows in the two
7189 configurations correspond to each other. */
7190 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
7191 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
7193 if (w1_is_current
!= w2_is_current
)
7196 /* Verify that the corresponding windows do match. */
7197 if (! EQ (p1
->buffer
, p2
->buffer
))
7199 if (! EQ (p1
->left_col
, p2
->left_col
))
7201 if (! EQ (p1
->top_line
, p2
->top_line
))
7203 if (! EQ (p1
->total_cols
, p2
->total_cols
))
7205 if (! EQ (p1
->total_lines
, p2
->total_lines
))
7207 if (! EQ (p1
->display_table
, p2
->display_table
))
7209 if (! EQ (p1
->parent
, p2
->parent
))
7211 if (! EQ (p1
->prev
, p2
->prev
))
7213 if (! ignore_positions
)
7215 if (! EQ (p1
->hscroll
, p2
->hscroll
))
7217 if (!EQ (p1
->min_hscroll
, p2
->min_hscroll
))
7219 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
7221 if (NILP (Fequal (p1
->start
, p2
->start
)))
7223 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
7225 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
7228 if (! EQ (p1
->left_margin_cols
, p2
->left_margin_cols
))
7230 if (! EQ (p1
->right_margin_cols
, p2
->right_margin_cols
))
7232 if (! EQ (p1
->left_fringe_width
, p2
->left_fringe_width
))
7234 if (! EQ (p1
->right_fringe_width
, p2
->right_fringe_width
))
7236 if (! EQ (p1
->fringes_outside_margins
, p2
->fringes_outside_margins
))
7238 if (! EQ (p1
->scroll_bar_width
, p2
->scroll_bar_width
))
7240 if (! EQ (p1
->vertical_scroll_bar_type
, p2
->vertical_scroll_bar_type
))
7247 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
7248 Scompare_window_configurations
, 2, 2, 0,
7249 doc
: /* Compare two window configurations as regards the structure of windows.
7250 This function ignores details such as the values of point and mark
7251 and scrolling positions. */)
7255 if (compare_window_configurations (x
, y
, 1))
7263 struct frame
*f
= make_terminal_frame ();
7264 XSETFRAME (selected_frame
, f
);
7265 Vterminal_frame
= selected_frame
;
7266 minibuf_window
= f
->minibuffer_window
;
7267 selected_window
= f
->selected_window
;
7268 last_nonminibuf_frame
= f
;
7270 window_initialized
= 1;
7276 Vwindow_list
= Qnil
;
7282 Qscroll_up
= intern ("scroll-up");
7283 staticpro (&Qscroll_up
);
7285 Qscroll_down
= intern ("scroll-down");
7286 staticpro (&Qscroll_down
);
7288 Qwindow_size_fixed
= intern ("window-size-fixed");
7289 staticpro (&Qwindow_size_fixed
);
7290 Fset (Qwindow_size_fixed
, Qnil
);
7292 staticpro (&Qwindow_configuration_change_hook
);
7293 Qwindow_configuration_change_hook
7294 = intern ("window-configuration-change-hook");
7296 Qwindowp
= intern ("windowp");
7297 staticpro (&Qwindowp
);
7299 Qwindow_configuration_p
= intern ("window-configuration-p");
7300 staticpro (&Qwindow_configuration_p
);
7302 Qwindow_live_p
= intern ("window-live-p");
7303 staticpro (&Qwindow_live_p
);
7305 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
7306 staticpro (&Qtemp_buffer_show_hook
);
7308 staticpro (&Vwindow_list
);
7310 minibuf_selected_window
= Qnil
;
7311 staticpro (&minibuf_selected_window
);
7313 window_scroll_pixel_based_preserve_y
= -1;
7315 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
7316 doc
: /* Non-nil means call as function to display a help buffer.
7317 The function is called with one argument, the buffer to be displayed.
7318 Used by `with-output-to-temp-buffer'.
7319 If this function is used, then it must do the entire job of showing
7320 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
7321 Vtemp_buffer_show_function
= Qnil
;
7323 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
7324 doc
: /* If non-nil, function to call to handle `display-buffer'.
7325 It will receive two args, the buffer and a flag which if non-nil means
7326 that the currently selected window is not acceptable.
7327 It should choose or create a window, display the specified buffer in it,
7328 and return the window.
7329 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'
7330 work using this function. */);
7331 Vdisplay_buffer_function
= Qnil
;
7333 DEFVAR_LISP ("even-window-heights", &Veven_window_heights
,
7334 doc
: /* *If non-nil, `display-buffer' should even the window heights.
7335 If nil, `display-buffer' will leave the window configuration alone. */);
7336 Veven_window_heights
= Qt
;
7338 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
7339 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
7340 Vminibuf_scroll_window
= Qnil
;
7342 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows
,
7343 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
7344 If the minibuffer is active, the `minibuffer-scroll-window' mode line
7345 is displayed in the `mode-line' face. */);
7346 mode_line_in_non_selected_windows
= 1;
7348 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
7349 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
7350 Vother_window_scroll_buffer
= Qnil
;
7352 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
7353 doc
: /* *Non-nil means `display-buffer' should make a separate frame. */);
7356 DEFVAR_BOOL ("auto-window-vscroll", &auto_window_vscroll_p
,
7357 doc
: /* *Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
7358 auto_window_vscroll_p
= 1;
7360 DEFVAR_BOOL ("display-buffer-reuse-frames", &display_buffer_reuse_frames
,
7361 doc
: /* *Non-nil means `display-buffer' should reuse frames.
7362 If the buffer in question is already displayed in a frame, raise that frame. */);
7363 display_buffer_reuse_frames
= 0;
7365 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
7366 doc
: /* Function to call to handle automatic new frame creation.
7367 It is called with no arguments and should return a newly created frame.
7369 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'
7370 where `pop-up-frame-alist' would hold the default frame parameters. */);
7371 Vpop_up_frame_function
= Qnil
;
7373 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
7374 doc
: /* *List of buffer names that should have their own special frames.
7375 Displaying a buffer with `display-buffer' or `pop-to-buffer',
7376 if its name is in this list, makes a special frame for it
7377 using `special-display-function'. See also `special-display-regexps'.
7379 An element of the list can be a list instead of just a string.
7380 There are two ways to use a list as an element:
7381 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)
7382 In the first case, the FRAME-PARAMETERS are pairs of the form
7383 \(PARAMETER . VALUE); these parameter values are used to create the frame.
7384 In the second case, FUNCTION is called with BUFFER as the first argument,
7385 followed by the OTHER-ARGS--it can display BUFFER in any way it likes.
7386 All this is done by the function found in `special-display-function'.
7388 If the specified frame parameters include (same-buffer . t), the
7389 buffer is displayed in the currently selected window. Otherwise, if
7390 they include (same-frame . t), the buffer is displayed in a new window
7391 in the currently selected frame.
7393 If this variable appears \"not to work\", because you add a name to it
7394 but that buffer still appears in the selected window, look at the
7395 values of `same-window-buffer-names' and `same-window-regexps'.
7396 Those variables take precedence over this one. */);
7397 Vspecial_display_buffer_names
= Qnil
;
7399 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
7400 doc
: /* *List of regexps saying which buffers should have their own special frames.
7401 When displaying a buffer with `display-buffer' or `pop-to-buffer',
7402 if any regexp in this list matches the buffer name, it makes a
7403 special frame for the buffer by calling `special-display-function'.
7405 An element of the list can be a list instead of just a string.
7406 There are two ways to use a list as an element:
7407 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)
7408 In the first case, the FRAME-PARAMETERS are pairs of the form
7409 \(PARAMETER . VALUE); these parameter values are used to create the frame.
7410 In the second case, FUNCTION is called with BUFFER as the first argument,
7411 followed by the OTHER-ARGS--it can display the buffer in any way it likes.
7412 All this is done by the function found in `special-display-function'.
7414 If the specified frame parameters include (same-buffer . t), the
7415 buffer is displayed in the currently selected window. Otherwise, if
7416 they include (same-frame . t), the buffer is displayed in a new window
7417 in the currently selected frame.
7419 If this variable appears \"not to work\", because you add a regexp to it
7420 but the matching buffers still appear in the selected window, look at the
7421 values of `same-window-buffer-names' and `same-window-regexps'.
7422 Those variables take precedence over this one. */);
7423 Vspecial_display_regexps
= Qnil
;
7425 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
7426 doc
: /* Function to call to make a new frame for a special buffer.
7427 It is called with two arguments, the buffer and optional buffer specific
7428 data, and should return a window displaying that buffer.
7429 The default value normally makes a separate frame for the buffer,
7430 using `special-display-frame-alist' to specify the frame parameters.
7431 But if the buffer specific data includes (same-buffer . t) then the
7432 buffer is displayed in the current selected window.
7433 Otherwise if it includes (same-frame . t) then the buffer is displayed in
7434 a new window in the currently selected frame.
7436 A buffer is special if it is listed in `special-display-buffer-names'
7437 or matches a regexp in `special-display-regexps'. */);
7438 Vspecial_display_function
= Qnil
;
7440 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
7441 doc
: /* *List of buffer names that should appear in the selected window.
7442 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'
7443 switches to it in the selected window, rather than making it appear
7444 in some other window.
7446 An element of the list can be a cons cell instead of just a string.
7447 Then the car must be a string, which specifies the buffer name.
7448 This is for compatibility with `special-display-buffer-names';
7449 the cdr of the cons cell is ignored.
7451 See also `same-window-regexps'. */);
7452 Vsame_window_buffer_names
= Qnil
;
7454 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
7455 doc
: /* *List of regexps saying which buffers should appear in the selected window.
7456 If a buffer name matches one of these regexps, then displaying it
7457 using `display-buffer' or `pop-to-buffer' switches to it
7458 in the selected window, rather than making it appear in some other window.
7460 An element of the list can be a cons cell instead of just a string.
7461 Then the car must be a string, which specifies the buffer name.
7462 This is for compatibility with `special-display-buffer-names';
7463 the cdr of the cons cell is ignored.
7465 See also `same-window-buffer-names'. */);
7466 Vsame_window_regexps
= Qnil
;
7468 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
7469 doc
: /* *Non-nil means display-buffer should make new windows. */);
7472 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
7473 doc
: /* *Number of lines of continuity when scrolling by screenfuls. */);
7474 next_screen_context_lines
= 2;
7476 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
7477 doc
: /* *A window must be at least this tall to be eligible for splitting
7478 by `display-buffer'. The value is in line units.
7479 If there is only one window, it is split regardless of this value. */);
7480 split_height_threshold
= 500;
7482 DEFVAR_INT ("window-min-height", &window_min_height
,
7483 doc
: /* *Delete any window less than this tall (including its mode line).
7484 The value is in line units. */);
7485 window_min_height
= 4;
7487 DEFVAR_INT ("window-min-width", &window_min_width
,
7488 doc
: /* *Delete any window less than this wide (measured in characters). */);
7489 window_min_width
= 10;
7491 DEFVAR_LISP ("scroll-preserve-screen-position",
7492 &Vscroll_preserve_screen_position
,
7493 doc
: /* *Controls if scroll commands move point to keep its screen line unchanged.
7494 A value of nil means point does not keep its screen position except
7495 at the scroll margin or window boundary respectively.
7496 A value of t means point keeps its screen position if the scroll
7497 command moved it vertically out of the window, e.g. when scrolling
7499 Any other value means point always keeps its screen position. */);
7500 Vscroll_preserve_screen_position
= Qnil
;
7502 DEFVAR_LISP ("window-configuration-change-hook",
7503 &Vwindow_configuration_change_hook
,
7504 doc
: /* Functions to call when window configuration changes.
7505 The selected frame is the one whose configuration has changed. */);
7506 Vwindow_configuration_change_hook
= Qnil
;
7508 defsubr (&Sselected_window
);
7509 defsubr (&Sminibuffer_window
);
7510 defsubr (&Swindow_minibuffer_p
);
7511 defsubr (&Swindowp
);
7512 defsubr (&Swindow_live_p
);
7513 defsubr (&Spos_visible_in_window_p
);
7514 defsubr (&Swindow_line_height
);
7515 defsubr (&Swindow_buffer
);
7516 defsubr (&Swindow_height
);
7517 defsubr (&Swindow_width
);
7518 defsubr (&Swindow_hscroll
);
7519 defsubr (&Sset_window_hscroll
);
7520 defsubr (&Swindow_redisplay_end_trigger
);
7521 defsubr (&Sset_window_redisplay_end_trigger
);
7522 defsubr (&Swindow_edges
);
7523 defsubr (&Swindow_pixel_edges
);
7524 defsubr (&Swindow_inside_edges
);
7525 defsubr (&Swindow_inside_pixel_edges
);
7526 defsubr (&Scoordinates_in_window_p
);
7527 defsubr (&Swindow_at
);
7528 defsubr (&Swindow_point
);
7529 defsubr (&Swindow_start
);
7530 defsubr (&Swindow_end
);
7531 defsubr (&Sset_window_point
);
7532 defsubr (&Sset_window_start
);
7533 defsubr (&Swindow_dedicated_p
);
7534 defsubr (&Sset_window_dedicated_p
);
7535 defsubr (&Swindow_display_table
);
7536 defsubr (&Sset_window_display_table
);
7537 defsubr (&Snext_window
);
7538 defsubr (&Sprevious_window
);
7539 defsubr (&Sother_window
);
7540 defsubr (&Sget_lru_window
);
7541 defsubr (&Sget_largest_window
);
7542 defsubr (&Sget_buffer_window
);
7543 defsubr (&Sdelete_other_windows
);
7544 defsubr (&Sdelete_windows_on
);
7545 defsubr (&Sreplace_buffer_in_windows
);
7546 defsubr (&Sdelete_window
);
7547 defsubr (&Sset_window_buffer
);
7548 defsubr (&Sselect_window
);
7549 defsubr (&Sspecial_display_p
);
7550 defsubr (&Ssame_window_p
);
7551 defsubr (&Sdisplay_buffer
);
7552 defsubr (&Sforce_window_update
);
7553 defsubr (&Ssplit_window
);
7554 defsubr (&Senlarge_window
);
7555 defsubr (&Sshrink_window
);
7556 defsubr (&Sadjust_window_trailing_edge
);
7557 defsubr (&Sscroll_up
);
7558 defsubr (&Sscroll_down
);
7559 defsubr (&Sscroll_left
);
7560 defsubr (&Sscroll_right
);
7561 defsubr (&Sother_window_for_scrolling
);
7562 defsubr (&Sscroll_other_window
);
7563 defsubr (&Sminibuffer_selected_window
);
7564 defsubr (&Srecenter
);
7565 defsubr (&Swindow_text_height
);
7566 defsubr (&Smove_to_window_line
);
7567 defsubr (&Swindow_configuration_p
);
7568 defsubr (&Swindow_configuration_frame
);
7569 defsubr (&Sset_window_configuration
);
7570 defsubr (&Scurrent_window_configuration
);
7571 defsubr (&Ssave_window_excursion
);
7572 defsubr (&Swindow_tree
);
7573 defsubr (&Sset_window_margins
);
7574 defsubr (&Swindow_margins
);
7575 defsubr (&Sset_window_fringes
);
7576 defsubr (&Swindow_fringes
);
7577 defsubr (&Sset_window_scroll_bars
);
7578 defsubr (&Swindow_scroll_bars
);
7579 defsubr (&Swindow_vscroll
);
7580 defsubr (&Sset_window_vscroll
);
7581 defsubr (&Scompare_window_configurations
);
7582 defsubr (&Swindow_list
);
7588 initial_define_key (control_x_map
, '1', "delete-other-windows");
7589 initial_define_key (control_x_map
, '2', "split-window");
7590 initial_define_key (control_x_map
, '0', "delete-window");
7591 initial_define_key (control_x_map
, 'o', "other-window");
7592 initial_define_key (control_x_map
, '^', "enlarge-window");
7593 initial_define_key (control_x_map
, '<', "scroll-left");
7594 initial_define_key (control_x_map
, '>', "scroll-right");
7596 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
7597 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
7598 initial_define_key (meta_map
, 'v', "scroll-down");
7600 initial_define_key (global_map
, Ctl('L'), "recenter");
7601 initial_define_key (meta_map
, 'r', "move-to-window-line");
7604 /* arch-tag: 90a9c576-0590-48f1-a5f1-6c96a0452d9f
7605 (do not change this comment) */