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 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. */
36 #include "dispextern.h"
37 #include "blockinput.h"
38 #include "intervals.h"
42 #endif /* HAVE_X_WINDOWS */
54 Lisp_Object Qwindowp
, Qwindow_live_p
, Qwindow_configuration_p
;
55 Lisp_Object Qwindow_size_fixed
;
56 extern Lisp_Object Qleft_margin
, Qright_margin
;
58 static int displayed_window_lines
P_ ((struct window
*));
59 static struct window
*decode_window
P_ ((Lisp_Object
));
60 static int count_windows
P_ ((struct window
*));
61 static int get_leaf_windows
P_ ((struct window
*, struct window
**, int));
62 static void window_scroll
P_ ((Lisp_Object
, int, int, int));
63 static void window_scroll_pixel_based
P_ ((Lisp_Object
, int, int, int));
64 static void window_scroll_line_based
P_ ((Lisp_Object
, int, int, int));
65 static int window_min_size_1
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));
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 #if 0 /* This isn't used anywhere. */
220 /* Nonzero means we can split a frame even if it is "unsplittable". */
221 static int inhibit_frame_unsplittable
;
224 extern EMACS_INT scroll_margin
;
226 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
228 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
229 doc
: /* Returns t if OBJECT is a window. */)
233 return WINDOWP (object
) ? Qt
: Qnil
;
236 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
237 doc
: /* Returns t if OBJECT is a window which is currently visible. */)
241 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
248 register struct window
*p
;
250 p
= allocate_window ();
252 XSETFASTINT (p
->sequence_number
, sequence_number
);
253 XSETFASTINT (p
->left_col
, 0);
254 XSETFASTINT (p
->top_line
, 0);
255 XSETFASTINT (p
->total_lines
, 0);
256 XSETFASTINT (p
->total_cols
, 0);
257 XSETFASTINT (p
->hscroll
, 0);
258 XSETFASTINT (p
->min_hscroll
, 0);
259 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
260 p
->start
= Fmake_marker ();
261 p
->pointm
= Fmake_marker ();
262 XSETFASTINT (p
->use_time
, 0);
264 p
->display_table
= Qnil
;
266 p
->pseudo_window_p
= 0;
267 bzero (&p
->cursor
, sizeof (p
->cursor
));
268 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
269 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
270 p
->desired_matrix
= p
->current_matrix
= 0;
271 p
->nrows_scale_factor
= p
->ncols_scale_factor
= 1;
272 p
->phys_cursor_type
= -1;
273 p
->phys_cursor_width
= -1;
274 p
->must_be_updated_p
= 0;
275 XSETFASTINT (p
->window_end_vpos
, 0);
276 XSETFASTINT (p
->window_end_pos
, 0);
277 p
->window_end_valid
= Qnil
;
280 XSETFASTINT (p
->last_point
, 0);
281 p
->frozen_window_start_p
= 0;
282 p
->last_cursor_off_p
= p
->cursor_off_p
= 0;
283 p
->left_margin_cols
= Qnil
;
284 p
->right_margin_cols
= Qnil
;
285 p
->left_fringe_width
= Qnil
;
286 p
->right_fringe_width
= Qnil
;
287 p
->fringes_outside_margins
= Qnil
;
288 p
->scroll_bar_width
= Qnil
;
289 p
->vertical_scroll_bar_type
= Qt
;
295 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
296 doc
: /* Return the window that the cursor now appears in and commands apply to. */)
299 return selected_window
;
302 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
303 doc
: /* Return the window used now for minibuffers.
304 If the optional argument FRAME is specified, return the minibuffer window
305 used by that frame. */)
310 frame
= selected_frame
;
311 CHECK_LIVE_FRAME (frame
);
312 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
315 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
316 doc
: /* Returns non-nil if WINDOW is a minibuffer window.
317 WINDOW defaults to the selected window. */)
321 struct window
*w
= decode_window (window
);
322 return MINI_WINDOW_P (w
) ? Qt
: Qnil
;
326 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
327 Spos_visible_in_window_p
, 0, 3, 0,
328 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
329 Return nil if that position is scrolled vertically out of view.
330 If a character is only partially visible, nil is returned, unless the
331 optional argument PARTIALLY is non-nil.
332 If POS is only out of view because of horizontal scrolling, return non-nil.
333 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
335 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
336 return value is a list (X Y PARTIAL) where X and Y are the pixel coordinates
337 relative to the top left corner of the window. PARTIAL is nil if the character
338 after POS is fully visible; otherwise it is a cons (RTOP . RBOT) where RTOP
339 and RBOT are the number of pixels invisible at the top and bottom of the row. */)
340 (pos
, window
, partially
)
341 Lisp_Object pos
, window
, partially
;
343 register struct window
*w
;
345 register struct buffer
*buf
;
347 Lisp_Object in_window
= Qnil
;
348 int rtop
, rbot
, fully_p
= 1;
351 w
= decode_window (window
);
352 buf
= XBUFFER (w
->buffer
);
353 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
357 CHECK_NUMBER_COERCE_MARKER (pos
);
360 else if (w
== XWINDOW (selected_window
))
363 posint
= XMARKER (w
->pointm
)->charpos
;
365 /* If position is above window start or outside buffer boundaries,
366 or if window start is out of range, position is not visible. */
367 if (posint
>= CHARPOS (top
)
368 && posint
<= BUF_ZV (buf
)
369 && CHARPOS (top
) >= BUF_BEGV (buf
)
370 && CHARPOS (top
) <= BUF_ZV (buf
)
371 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, NILP (partially
))
372 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
375 if (!NILP (in_window
) && !NILP (partially
))
376 in_window
= Fcons (make_number (x
),
377 Fcons (make_number (y
),
378 Fcons ((fully_p
? Qnil
379 : Fcons (make_number (rtop
),
380 make_number (rbot
))),
386 static struct window
*
387 decode_window (window
)
388 register Lisp_Object window
;
391 return XWINDOW (selected_window
);
393 CHECK_LIVE_WINDOW (window
);
394 return XWINDOW (window
);
397 static struct window
*
398 decode_any_window (window
)
399 register Lisp_Object window
;
402 return XWINDOW (selected_window
);
404 CHECK_WINDOW (window
);
405 return XWINDOW (window
);
408 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
409 doc
: /* Return the buffer that WINDOW is displaying.
410 WINDOW defaults to the selected window. */)
414 return decode_window (window
)->buffer
;
417 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
418 doc
: /* Return the number of lines in WINDOW (including its mode line). */)
422 return decode_any_window (window
)->total_lines
;
425 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
426 doc
: /* Return the number of display columns in WINDOW.
427 This is the width that is usable columns available for text in WINDOW.
428 If you want to find out how many columns WINDOW takes up,
429 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
433 return make_number (window_box_text_cols (decode_any_window (window
)));
436 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
437 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin. */)
441 return decode_window (window
)->hscroll
;
444 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
445 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
446 Return NCOL. NCOL should be zero or positive.
448 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
449 window so that the location of point becomes invisible. */)
451 Lisp_Object window
, ncol
;
453 struct window
*w
= decode_window (window
);
457 hscroll
= max (0, XINT (ncol
));
459 /* Prevent redisplay shortcuts when changing the hscroll. */
460 if (XINT (w
->hscroll
) != hscroll
)
461 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
463 w
->hscroll
= make_number (hscroll
);
467 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
468 Swindow_redisplay_end_trigger
, 0, 1, 0,
469 doc
: /* Return WINDOW's redisplay end trigger value.
470 See `set-window-redisplay-end-trigger' for more information. */)
474 return decode_window (window
)->redisplay_end_trigger
;
477 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
478 Sset_window_redisplay_end_trigger
, 2, 2, 0,
479 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
480 VALUE should be a buffer position (typically a marker) or nil.
481 If it is a buffer position, then if redisplay in WINDOW reaches a position
482 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
483 with two arguments: WINDOW, and the end trigger value.
484 Afterwards the end-trigger value is reset to nil. */)
486 register Lisp_Object window
, value
;
488 register struct window
*w
;
490 w
= decode_window (window
);
491 w
->redisplay_end_trigger
= value
;
495 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
496 doc
: /* Return a list of the edge coordinates of WINDOW.
497 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
498 RIGHT is one more than the rightmost column occupied by WINDOW,
499 and BOTTOM is one more than the bottommost row occupied by WINDOW.
500 The edges include the space used by the window's scroll bar,
501 display margins, fringes, header line, and mode line, if it has them.
502 To get the edges of the actual text area, use `window-inside-edges'. */)
506 register struct window
*w
= decode_any_window (window
);
508 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w
)),
509 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w
)),
510 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w
)),
511 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w
)),
515 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
516 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
517 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
518 RIGHT is one more than the rightmost x position occupied by WINDOW,
519 and BOTTOM is one more than the bottommost y position occupied by WINDOW.
520 The pixel edges include the space used by the window's scroll bar,
521 display margins, fringes, header line, and mode line, if it has them.
522 To get the edges of the actual text area, use `window-inside-pixel-edges'. */)
526 register struct window
*w
= decode_any_window (window
);
528 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
)),
529 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
)),
530 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
)),
531 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
)),
535 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
536 doc
: /* Return a list of the edge coordinates of WINDOW.
537 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
538 RIGHT is one more than the rightmost column used by text in WINDOW,
539 and BOTTOM is one more than the bottommost row used by text in WINDOW.
540 The inside edges do not include the space used by the window's scroll bar,
541 display margins, fringes, header line, and/or mode line. */)
545 register struct window
*w
= decode_any_window (window
);
547 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w
)
548 + WINDOW_LEFT_MARGIN_COLS (w
)
549 + WINDOW_LEFT_FRINGE_COLS (w
)),
550 make_number (WINDOW_TOP_EDGE_LINE (w
)
551 + WINDOW_HEADER_LINE_LINES (w
)),
552 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w
)
553 - WINDOW_RIGHT_MARGIN_COLS (w
)
554 - WINDOW_RIGHT_FRINGE_COLS (w
)),
555 make_number (WINDOW_BOTTOM_EDGE_LINE (w
)
556 - WINDOW_MODE_LINE_LINES (w
)));
559 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
560 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
561 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
562 RIGHT is one more than the rightmost x position used by text in WINDOW,
563 and BOTTOM is one more than the bottommost y position used by text in WINDOW.
564 The inside edges do not include the space used by the window's scroll bar,
565 display margins, fringes, header line, and/or mode line. */)
569 register struct window
*w
= decode_any_window (window
);
571 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
572 + WINDOW_LEFT_MARGIN_WIDTH (w
)
573 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
574 make_number (WINDOW_TOP_EDGE_Y (w
)
575 + WINDOW_HEADER_LINE_HEIGHT (w
)),
576 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
577 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
578 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
579 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
580 - WINDOW_MODE_LINE_HEIGHT (w
)));
583 /* Test if the character at column *X, row *Y is within window W.
584 If it is not, return ON_NOTHING;
585 if it is in the window's text area,
586 set *x and *y to its location relative to the upper left corner
589 if it is on the window's modeline, return ON_MODE_LINE;
590 if it is on the border between the window and its right sibling,
591 return ON_VERTICAL_BORDER.
592 if it is on a scroll bar,
593 return ON_SCROLL_BAR.
594 if it is on the window's top line, return ON_HEADER_LINE;
595 if it is in left or right fringe of the window,
596 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y
597 to window-relative coordinates;
598 if it is in the marginal area to the left/right of the window,
599 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y
600 to window-relative coordinates.
602 X and Y are frame relative pixel coordinates. */
604 static enum window_part
605 coordinates_in_window (w
, x
, y
)
606 register struct window
*w
;
609 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
610 int left_x
, right_x
, top_y
, bottom_y
;
611 enum window_part part
;
612 int ux
= FRAME_COLUMN_WIDTH (f
);
613 int x0
= WINDOW_LEFT_EDGE_X (w
);
614 int x1
= WINDOW_RIGHT_EDGE_X (w
);
615 /* The width of the area where the vertical line can be dragged.
616 (Between mode lines for instance. */
617 int grabbable_width
= ux
;
618 int lmargin_width
, rmargin_width
, text_left
, text_right
;
620 /* In what's below, we subtract 1 when computing right_x because we
621 want the rightmost pixel, which is given by left_pixel+width-1. */
622 if (w
->pseudo_window_p
)
625 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
626 top_y
= WINDOW_TOP_EDGE_Y (w
);
627 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
631 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
632 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
633 top_y
= WINDOW_TOP_EDGE_Y (w
);
634 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
637 /* Outside any interesting row? */
638 if (*y
< top_y
|| *y
>= bottom_y
)
641 /* On the mode line or header line? If it's near the start of
642 the mode or header line of window that's has a horizontal
643 sibling, say it's on the vertical line. That's to be able
644 to resize windows horizontally in case we're using toolkit
647 if (WINDOW_WANTS_MODELINE_P (w
)
648 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
652 header_vertical_border_check
:
653 /* We're somewhere on the mode line. We consider the place
654 between mode lines of horizontally adjacent mode lines
655 as the vertical border. If scroll bars on the left,
656 return the right window. */
657 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
658 || WINDOW_RIGHTMOST_P (w
))
660 if (!WINDOW_LEFTMOST_P (w
) && abs (*x
- x0
) < grabbable_width
)
661 return ON_VERTICAL_BORDER
;
665 if (abs (*x
- x1
) < grabbable_width
)
666 return ON_VERTICAL_BORDER
;
669 if (*x
< x0
|| *x
>= x1
)
672 /* Convert X and Y to window relative coordinates.
673 Mode line starts at left edge of window. */
679 if (WINDOW_WANTS_HEADER_LINE_P (w
)
680 && *y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
))
682 part
= ON_HEADER_LINE
;
683 goto header_vertical_border_check
;
686 if (*x
< x0
|| *x
>= x1
)
689 /* Outside any interesting column? */
690 if (*x
< left_x
|| *x
> right_x
)
693 return ON_SCROLL_BAR
;
696 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
697 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
699 text_left
= window_box_left (w
, TEXT_AREA
);
700 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
702 if (FRAME_WINDOW_P (f
))
704 if (!w
->pseudo_window_p
705 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
706 && !WINDOW_RIGHTMOST_P (w
)
707 && (abs (*x
- right_x
) < grabbable_width
))
708 return ON_VERTICAL_BORDER
;
712 /* Need to say "*x > right_x" rather than >=, since on character
713 terminals, the vertical line's x coordinate is right_x. */
714 if (!w
->pseudo_window_p
715 && !WINDOW_RIGHTMOST_P (w
)
716 && *x
> right_x
- ux
)
718 /* On the border on the right side of the window? Assume that
719 this area begins at RIGHT_X minus a canonical char width. */
720 return ON_VERTICAL_BORDER
;
726 if (lmargin_width
> 0
727 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
728 ? (*x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
729 : (*x
< left_x
+ lmargin_width
)))
732 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
733 *x
-= WINDOW_LEFT_FRINGE_WIDTH (w
);
735 return ON_LEFT_MARGIN
;
738 /* Convert X and Y to window-relative pixel coordinates. */
741 return ON_LEFT_FRINGE
;
744 if (*x
>= text_right
)
746 if (rmargin_width
> 0
747 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
748 ? (*x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
749 : (*x
>= right_x
- rmargin_width
)))
751 *x
-= right_x
- rmargin_width
;
752 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
753 *x
+= WINDOW_RIGHT_FRINGE_WIDTH (w
);
755 return ON_RIGHT_MARGIN
;
758 /* Convert X and Y to window-relative pixel coordinates. */
759 *x
-= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
);
761 return ON_RIGHT_FRINGE
;
764 /* Everything special ruled out - must be on text area */
771 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
772 Scoordinates_in_window_p
, 2, 2, 0,
773 doc
: /* Return non-nil if COORDINATES are in WINDOW.
774 COORDINATES is a cons of the form (X . Y), X and Y being distances
775 measured in characters from the upper-left corner of the frame.
776 \(0 . 0) denotes the character in the upper left corner of the
778 If COORDINATES are in the text portion of WINDOW,
779 the coordinates relative to the window are returned.
780 If they are in the mode line of WINDOW, `mode-line' is returned.
781 If they are in the top mode line of WINDOW, `header-line' is returned.
782 If they are in the left fringe of WINDOW, `left-fringe' is returned.
783 If they are in the right fringe of WINDOW, `right-fringe' is returned.
784 If they are on the border between WINDOW and its right sibling,
785 `vertical-line' is returned.
786 If they are in the windows's left or right marginal areas, `left-margin'\n\
787 or `right-margin' is returned. */)
788 (coordinates
, window
)
789 register Lisp_Object coordinates
, window
;
796 CHECK_WINDOW (window
);
797 w
= XWINDOW (window
);
798 f
= XFRAME (w
->frame
);
799 CHECK_CONS (coordinates
);
800 lx
= Fcar (coordinates
);
801 ly
= Fcdr (coordinates
);
802 CHECK_NUMBER_OR_FLOAT (lx
);
803 CHECK_NUMBER_OR_FLOAT (ly
);
804 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
805 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
807 switch (coordinates_in_window (w
, &x
, &y
))
813 /* X and Y are now window relative pixel coordinates. Convert
814 them to canonical char units before returning them. */
815 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
816 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
821 case ON_VERTICAL_BORDER
:
822 return Qvertical_line
;
830 case ON_RIGHT_FRINGE
:
831 return Qright_fringe
;
836 case ON_RIGHT_MARGIN
:
837 return Qright_margin
;
840 /* Historically we are supposed to return nil in this case. */
849 /* Callback for foreach_window, used in window_from_coordinates.
850 Check if window W contains coordinates specified by USER_DATA which
851 is actually a pointer to a struct check_window_data CW.
853 Check if window W contains coordinates *CW->x and *CW->y. If it
854 does, return W in *CW->window, as Lisp_Object, and return in
855 *CW->part the part of the window under coordinates *X,*Y. Return
856 zero from this function to stop iterating over windows. */
858 struct check_window_data
862 enum window_part
*part
;
866 check_window_containing (w
, user_data
)
870 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
871 enum window_part found
;
874 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
875 if (found
!= ON_NOTHING
)
878 XSETWINDOW (*cw
->window
, w
);
886 /* Find the window containing frame-relative pixel position X/Y and
887 return it as a Lisp_Object.
889 If X, Y is on one of the window's special `window_part' elements,
890 set *PART to the id of that element, and return X and Y converted
891 to window relative coordinates in WX and WY.
893 If there is no window under X, Y return nil and leave *PART
894 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
896 This function was previously implemented with a loop cycling over
897 windows with Fnext_window, and starting with the frame's selected
898 window. It turned out that this doesn't work with an
899 implementation of next_window using Vwindow_list, because
900 FRAME_SELECTED_WINDOW (F) is not always contained in the window
901 tree of F when this function is called asynchronously from
902 note_mouse_highlight. The original loop didn't terminate in this
906 window_from_coordinates (f
, x
, y
, part
, wx
, wy
, tool_bar_p
)
909 enum window_part
*part
;
914 struct check_window_data cw
;
915 enum window_part dummy
;
921 cw
.window
= &window
, cw
.x
= &x
, cw
.y
= &y
; cw
.part
= part
;
922 foreach_window (f
, check_window_containing
, &cw
);
924 /* If not found above, see if it's in the tool bar window, if a tool
928 && WINDOWP (f
->tool_bar_window
)
929 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
930 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), &x
, &y
)
934 window
= f
->tool_bar_window
;
943 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
944 doc
: /* Return window containing coordinates X and Y on FRAME.
945 If omitted, FRAME defaults to the currently selected frame.
946 The top left corner of the frame is considered to be row 0,
949 Lisp_Object x
, y
, frame
;
954 frame
= selected_frame
;
955 CHECK_LIVE_FRAME (frame
);
958 /* Check that arguments are integers or floats. */
959 CHECK_NUMBER_OR_FLOAT (x
);
960 CHECK_NUMBER_OR_FLOAT (y
);
962 return window_from_coordinates (f
,
963 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
964 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
965 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
966 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
970 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
971 doc
: /* Return current value of point in WINDOW.
972 For a nonselected window, this is the value point would have
973 if that window were selected.
975 Note that, when WINDOW is the selected window and its buffer
976 is also currently selected, the value returned is the same as (point).
977 It would be more strictly correct to return the `top-level' value
978 of point, outside of any save-excursion forms.
979 But that is hard to define. */)
983 register struct window
*w
= decode_window (window
);
985 if (w
== XWINDOW (selected_window
)
986 && current_buffer
== XBUFFER (w
->buffer
))
988 return Fmarker_position (w
->pointm
);
991 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
992 doc
: /* Return position at which display currently starts in WINDOW.
993 This is updated by redisplay or by calling `set-window-start'. */)
997 return Fmarker_position (decode_window (window
)->start
);
1000 /* This is text temporarily removed from the doc string below.
1002 This function returns nil if the position is not currently known.
1003 That happens when redisplay is preempted and doesn't finish.
1004 If in that case you want to compute where the end of the window would
1005 have been if redisplay had finished, do this:
1007 (goto-char (window-start window))
1008 (vertical-motion (1- (window-height window)) window)
1011 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1012 doc
: /* Return position at which display currently ends in WINDOW.
1013 This is updated by redisplay, when it runs to completion.
1014 Simply changing the buffer text or setting `window-start'
1015 does not update this value.
1016 Return nil if there is no recorded value. \(This can happen if the
1017 last redisplay of WINDOW was preempted, and did not finish.)
1018 If UPDATE is non-nil, compute the up-to-date position
1019 if it isn't already recorded. */)
1021 Lisp_Object window
, update
;
1024 struct window
*w
= decode_window (window
);
1030 #if 0 /* This change broke some things. We should make it later. */
1031 /* If we don't know the end position, return nil.
1032 The user can compute it with vertical-motion if he wants to.
1033 It would be nicer to do it automatically,
1034 but that's so slow that it would probably bother people. */
1035 if (NILP (w
->window_end_valid
))
1040 && ! (! NILP (w
->window_end_valid
)
1041 && XFASTINT (w
->last_modified
) >= MODIFF
)
1044 struct text_pos startp
;
1046 struct buffer
*old_buffer
= NULL
, *b
= XBUFFER (buf
);
1048 /* In case W->start is out of the range, use something
1049 reasonable. This situation occurred when loading a file with
1050 `-l' containing a call to `rmail' with subsequent other
1051 commands. At the end, W->start happened to be BEG, while
1052 rmail had already narrowed the buffer. */
1053 if (XMARKER (w
->start
)->charpos
< BEGV
)
1054 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1055 else if (XMARKER (w
->start
)->charpos
> ZV
)
1056 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1058 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1060 /* Cannot use Fvertical_motion because that function doesn't
1061 cope with variable-height lines. */
1062 if (b
!= current_buffer
)
1064 old_buffer
= current_buffer
;
1065 set_buffer_internal (b
);
1068 start_display (&it
, w
, startp
);
1069 move_it_vertically (&it
, window_box_height (w
));
1070 if (it
.current_y
< it
.last_visible_y
)
1071 move_it_past_eol (&it
);
1072 value
= make_number (IT_CHARPOS (it
));
1075 set_buffer_internal (old_buffer
);
1078 XSETINT (value
, BUF_Z (XBUFFER (buf
)) - XFASTINT (w
->window_end_pos
));
1083 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1084 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1087 Lisp_Object window
, pos
;
1089 register struct window
*w
= decode_window (window
);
1091 CHECK_NUMBER_COERCE_MARKER (pos
);
1092 if (w
== XWINDOW (selected_window
)
1093 && XBUFFER (w
->buffer
) == current_buffer
)
1096 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1098 /* We have to make sure that redisplay updates the window to show
1099 the new value of point. */
1100 if (!EQ (window
, selected_window
))
1101 ++windows_or_buffers_changed
;
1106 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1107 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1109 Optional third arg NOFORCE non-nil inhibits next redisplay
1110 from overriding motion of point in order to display at this exact start. */)
1111 (window
, pos
, noforce
)
1112 Lisp_Object window
, pos
, noforce
;
1114 register struct window
*w
= decode_window (window
);
1116 CHECK_NUMBER_COERCE_MARKER (pos
);
1117 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1118 /* this is not right, but much easier than doing what is right. */
1119 w
->start_at_line_beg
= Qnil
;
1121 w
->force_start
= Qt
;
1122 w
->update_mode_line
= Qt
;
1123 XSETFASTINT (w
->last_modified
, 0);
1124 XSETFASTINT (w
->last_overlay_modified
, 0);
1125 if (!EQ (window
, selected_window
))
1126 windows_or_buffers_changed
++;
1131 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1133 doc
: /* Return WINDOW's dedicated object, usually t or nil.
1134 See also `set-window-dedicated-p'. */)
1138 return decode_window (window
)->dedicated
;
1141 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1142 Sset_window_dedicated_p
, 2, 2, 0,
1143 doc
: /* Control whether WINDOW is dedicated to the buffer it displays.
1144 If it is dedicated, Emacs will not automatically change
1145 which buffer appears in it.
1146 The second argument is the new value for the dedication flag;
1147 non-nil means yes. */)
1149 Lisp_Object window
, arg
;
1151 register struct window
*w
= decode_window (window
);
1155 return w
->dedicated
;
1158 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1160 doc
: /* Return the display-table that WINDOW is using. */)
1164 return decode_window (window
)->display_table
;
1167 /* Get the display table for use on window W. This is either W's
1168 display table or W's buffer's display table. Ignore the specified
1169 tables if they are not valid; if no valid table is specified,
1172 struct Lisp_Char_Table
*
1173 window_display_table (w
)
1176 struct Lisp_Char_Table
*dp
= NULL
;
1178 if (DISP_TABLE_P (w
->display_table
))
1179 dp
= XCHAR_TABLE (w
->display_table
);
1180 else if (BUFFERP (w
->buffer
))
1182 struct buffer
*b
= XBUFFER (w
->buffer
);
1184 if (DISP_TABLE_P (b
->display_table
))
1185 dp
= XCHAR_TABLE (b
->display_table
);
1186 else if (DISP_TABLE_P (Vstandard_display_table
))
1187 dp
= XCHAR_TABLE (Vstandard_display_table
);
1193 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1194 doc
: /* Set WINDOW's display-table to TABLE. */)
1196 register Lisp_Object window
, table
;
1198 register struct window
*w
;
1200 w
= decode_window (window
);
1201 w
->display_table
= table
;
1205 /* Record info on buffer window w is displaying
1206 when it is about to cease to display that buffer. */
1209 register struct window
*w
;
1216 if (b
!= XMARKER (w
->pointm
)->buffer
)
1220 if (w
== XWINDOW (selected_window
)
1221 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1222 /* Do this except when the selected window's buffer
1223 is being removed from some other window. */
1225 /* last_window_start records the start position that this buffer
1226 had in the last window to be disconnected from it.
1227 Now that this statement is unconditional,
1228 it is possible for the buffer to be displayed in the
1229 selected window, while last_window_start reflects another
1230 window which was recently showing the same buffer.
1231 Some people might say that might be a good thing. Let's see. */
1232 b
->last_window_start
= marker_position (w
->start
);
1234 /* Point in the selected window's buffer
1235 is actually stored in that buffer, and the window's pointm isn't used.
1236 So don't clobber point in that buffer. */
1237 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1238 /* This line helps to fix Horsley's testbug.el bug. */
1239 && !(WINDOWP (b
->last_selected_window
)
1240 && w
!= XWINDOW (b
->last_selected_window
)
1241 && EQ (buf
, XWINDOW (b
->last_selected_window
)->buffer
)))
1242 temp_set_point_both (b
,
1243 clip_to_bounds (BUF_BEGV (b
),
1244 XMARKER (w
->pointm
)->charpos
,
1246 clip_to_bounds (BUF_BEGV_BYTE (b
),
1247 marker_byte_position (w
->pointm
),
1250 if (WINDOWP (b
->last_selected_window
)
1251 && w
== XWINDOW (b
->last_selected_window
))
1252 b
->last_selected_window
= Qnil
;
1255 /* Put replacement into the window structure in place of old. */
1257 replace_window (old
, replacement
)
1258 Lisp_Object old
, replacement
;
1260 register Lisp_Object tem
;
1261 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
1263 /* If OLD is its frame's root_window, then replacement is the new
1264 root_window for that frame. */
1266 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1267 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
1269 p
->left_col
= o
->left_col
;
1270 p
->top_line
= o
->top_line
;
1271 p
->total_cols
= o
->total_cols
;
1272 p
->total_lines
= o
->total_lines
;
1273 p
->desired_matrix
= p
->current_matrix
= 0;
1275 bzero (&p
->cursor
, sizeof (p
->cursor
));
1276 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
1277 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
1278 p
->phys_cursor_type
= -1;
1279 p
->phys_cursor_width
= -1;
1280 p
->must_be_updated_p
= 0;
1281 p
->pseudo_window_p
= 0;
1282 XSETFASTINT (p
->window_end_vpos
, 0);
1283 XSETFASTINT (p
->window_end_pos
, 0);
1284 p
->window_end_valid
= Qnil
;
1285 p
->frozen_window_start_p
= 0;
1286 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
1288 p
->next
= tem
= o
->next
;
1290 XWINDOW (tem
)->prev
= replacement
;
1292 p
->prev
= tem
= o
->prev
;
1294 XWINDOW (tem
)->next
= replacement
;
1296 p
->parent
= tem
= o
->parent
;
1299 if (EQ (XWINDOW (tem
)->vchild
, old
))
1300 XWINDOW (tem
)->vchild
= replacement
;
1301 if (EQ (XWINDOW (tem
)->hchild
, old
))
1302 XWINDOW (tem
)->hchild
= replacement
;
1305 /*** Here, if replacement is a vertical combination
1306 and so is its new parent, we should make replacement's
1307 children be children of that parent instead. ***/
1310 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
1311 doc
: /* Remove WINDOW from the display. Default is selected window. */)
1313 register Lisp_Object window
;
1315 delete_window (window
);
1317 if (! NILP (Vwindow_configuration_change_hook
)
1318 && ! NILP (Vrun_hooks
))
1319 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
1325 delete_window (window
)
1326 register Lisp_Object window
;
1328 register Lisp_Object tem
, parent
, sib
;
1329 register struct window
*p
;
1330 register struct window
*par
;
1333 /* Because this function is called by other C code on non-leaf
1334 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1335 so we can't decode_window here. */
1337 window
= selected_window
;
1339 CHECK_WINDOW (window
);
1340 p
= XWINDOW (window
);
1342 /* It's a no-op to delete an already-deleted window. */
1343 if (NILP (p
->buffer
)
1345 && NILP (p
->vchild
))
1350 error ("Attempt to delete minibuffer or sole ordinary window");
1351 par
= XWINDOW (parent
);
1353 windows_or_buffers_changed
++;
1354 Vwindow_list
= Qnil
;
1355 f
= XFRAME (WINDOW_FRAME (p
));
1356 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
1358 /* Are we trying to delete any frame's selected window? */
1360 Lisp_Object swindow
, pwindow
;
1362 /* See if the frame's selected window is either WINDOW
1363 or any subwindow of it, by finding all that window's parents
1364 and comparing each one with WINDOW. */
1365 swindow
= FRAME_SELECTED_WINDOW (f
);
1370 while (!NILP (pwindow
))
1372 if (EQ (window
, pwindow
))
1374 pwindow
= XWINDOW (pwindow
)->parent
;
1377 /* If the window being deleted is not a parent of SWINDOW,
1378 then SWINDOW is ok as the new selected window. */
1379 if (!EQ (window
, pwindow
))
1381 /* Otherwise, try another window for SWINDOW. */
1382 swindow
= Fnext_window (swindow
, Qlambda
, Qnil
);;
1384 /* If we get back to the frame's selected window,
1385 it means there was no acceptable alternative,
1386 so we cannot delete. */
1387 if (EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1388 error ("Cannot delete window");
1391 /* If we need to change SWINDOW, do it. */
1392 if (! EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1394 /* If we're about to delete the selected window on the
1395 selected frame, then we should use Fselect_window to select
1396 the new window. On the other hand, if we're about to
1397 delete the selected window on any other frame, we shouldn't do
1398 anything but set the frame's selected_window slot. */
1399 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
1400 Fselect_window (swindow
, Qnil
);
1402 FRAME_SELECTED_WINDOW (f
) = swindow
;
1406 /* Now we know we can delete this one. */
1407 window_deletion_count
++;
1410 /* tem is null for dummy parent windows
1411 (which have inferiors but not any contents themselves) */
1415 unchain_marker (XMARKER (p
->pointm
));
1416 unchain_marker (XMARKER (p
->start
));
1419 /* Free window glyph matrices. It is sure that they are allocated
1420 again when ADJUST_GLYPHS is called. Block input so that expose
1421 events and other events that access glyph matrices are not
1422 processed while we are changing them. */
1424 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)));
1428 XWINDOW (tem
)->prev
= p
->prev
;
1432 XWINDOW (tem
)->next
= p
->next
;
1434 if (EQ (window
, par
->hchild
))
1435 par
->hchild
= p
->next
;
1436 if (EQ (window
, par
->vchild
))
1437 par
->vchild
= p
->next
;
1439 /* Find one of our siblings to give our space to. */
1443 /* If p gives its space to its next sibling, that sibling needs
1444 to have its top/left side pulled back to where p's is.
1445 set_window_{height,width} will re-position the sibling's
1448 XWINDOW (sib
)->top_line
= p
->top_line
;
1449 XWINDOW (sib
)->left_col
= p
->left_col
;
1452 /* Stretch that sibling. */
1453 if (!NILP (par
->vchild
))
1454 set_window_height (sib
,
1455 XFASTINT (XWINDOW (sib
)->total_lines
) + XFASTINT (p
->total_lines
),
1457 if (!NILP (par
->hchild
))
1458 set_window_width (sib
,
1459 XFASTINT (XWINDOW (sib
)->total_cols
) + XFASTINT (p
->total_cols
),
1462 /* If parent now has only one child,
1463 put the child into the parent's place. */
1467 if (NILP (XWINDOW (tem
)->next
)) {
1468 replace_window (parent
, tem
);
1469 par
= XWINDOW (tem
);
1472 /* Since we may be deleting combination windows, we must make sure that
1473 not only p but all its children have been marked as deleted. */
1474 if (! NILP (p
->hchild
))
1475 delete_all_subwindows (XWINDOW (p
->hchild
));
1476 else if (! NILP (p
->vchild
))
1477 delete_all_subwindows (XWINDOW (p
->vchild
));
1479 /* Mark this window as deleted. */
1480 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1482 if (! NILP (par
->parent
))
1483 par
= XWINDOW (par
->parent
);
1485 /* Check if we have a v/hchild with a v/hchild. In that case remove
1488 if (! NILP (par
->vchild
) && ! NILP (XWINDOW (par
->vchild
)->vchild
))
1490 p
= XWINDOW (par
->vchild
);
1491 par
->vchild
= p
->vchild
;
1494 else if (! NILP (par
->hchild
) && ! NILP (XWINDOW (par
->hchild
)->hchild
))
1496 p
= XWINDOW (par
->hchild
);
1497 par
->hchild
= p
->hchild
;
1505 while (! NILP (tem
)) {
1506 XWINDOW (tem
)->parent
= p
->parent
;
1507 if (NILP (XWINDOW (tem
)->next
))
1509 tem
= XWINDOW (tem
)->next
;
1512 /* The next of the v/hchild we are removing is now the next of the
1513 last child for the v/hchild:
1514 Before v/hchild -> v/hchild -> next1 -> next2
1517 After: v/hchild -> next1 -> next2 -> next3
1519 XWINDOW (tem
)->next
= p
->next
;
1520 if (! NILP (p
->next
))
1521 XWINDOW (p
->next
)->prev
= tem
;
1523 p
->next
= p
->prev
= p
->vchild
= p
->hchild
= p
->buffer
= Qnil
;
1527 /* Adjust glyph matrices. */
1534 /***********************************************************************
1536 ***********************************************************************/
1538 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1539 pointer. This is a callback function for foreach_window, used in
1540 function window_list. */
1543 add_window_to_list (w
, user_data
)
1547 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1549 XSETWINDOW (window
, w
);
1550 *list
= Fcons (window
, *list
);
1555 /* Return a list of all windows, for use by next_window. If
1556 Vwindow_list is a list, return that list. Otherwise, build a new
1557 list, cache it in Vwindow_list, and return that. */
1562 if (!CONSP (Vwindow_list
))
1566 Vwindow_list
= Qnil
;
1567 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1569 Lisp_Object args
[2];
1571 /* We are visiting windows in canonical order, and add
1572 new windows at the front of args[1], which means we
1573 have to reverse this list at the end. */
1575 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1576 args
[0] = Vwindow_list
;
1577 args
[1] = Fnreverse (args
[1]);
1578 Vwindow_list
= Fnconc (2, args
);
1582 return Vwindow_list
;
1586 /* Value is non-zero if WINDOW satisfies the constraints given by
1587 OWINDOW, MINIBUF and ALL_FRAMES.
1589 MINIBUF t means WINDOW may be minibuffer windows.
1590 `lambda' means WINDOW may not be a minibuffer window.
1591 a window means a specific minibuffer window
1593 ALL_FRAMES t means search all frames,
1594 nil means search just current frame,
1595 `visible' means search just visible frames,
1596 0 means search visible and iconified frames,
1597 a window means search the frame that window belongs to,
1598 a frame means consider windows on that frame, only. */
1601 candidate_window_p (window
, owindow
, minibuf
, all_frames
)
1602 Lisp_Object window
, owindow
, minibuf
, all_frames
;
1604 struct window
*w
= XWINDOW (window
);
1605 struct frame
*f
= XFRAME (w
->frame
);
1606 int candidate_p
= 1;
1608 if (!BUFFERP (w
->buffer
))
1610 else if (MINI_WINDOW_P (w
)
1611 && (EQ (minibuf
, Qlambda
)
1612 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
1614 /* If MINIBUF is `lambda' don't consider any mini-windows.
1615 If it is a window, consider only that one. */
1618 else if (EQ (all_frames
, Qt
))
1620 else if (NILP (all_frames
))
1622 xassert (WINDOWP (owindow
));
1623 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
1625 else if (EQ (all_frames
, Qvisible
))
1627 FRAME_SAMPLE_VISIBILITY (f
);
1628 candidate_p
= FRAME_VISIBLE_P (f
);
1630 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
1632 FRAME_SAMPLE_VISIBILITY (f
);
1633 candidate_p
= FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
);
1635 else if (WINDOWP (all_frames
))
1636 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
1637 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
1638 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
1639 else if (FRAMEP (all_frames
))
1640 candidate_p
= EQ (all_frames
, w
->frame
);
1646 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1647 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1651 decode_next_window_args (window
, minibuf
, all_frames
)
1652 Lisp_Object
*window
, *minibuf
, *all_frames
;
1655 *window
= selected_window
;
1657 CHECK_LIVE_WINDOW (*window
);
1659 /* MINIBUF nil may or may not include minibuffers. Decide if it
1661 if (NILP (*minibuf
))
1662 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
1663 else if (!EQ (*minibuf
, Qt
))
1666 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1667 => count none of them, or a specific minibuffer window (the
1668 active one) to count. */
1670 /* ALL_FRAMES nil doesn't specify which frames to include. */
1671 if (NILP (*all_frames
))
1672 *all_frames
= (!EQ (*minibuf
, Qlambda
)
1673 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
1675 else if (EQ (*all_frames
, Qvisible
))
1677 else if (EQ (*all_frames
, make_number (0)))
1679 else if (FRAMEP (*all_frames
))
1681 else if (!EQ (*all_frames
, Qt
))
1684 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1685 search just current frame, `visible' meaning search just visible
1686 frames, 0 meaning search visible and iconified frames, or a
1687 window, meaning search the frame that window belongs to, or a
1688 frame, meaning consider windows on that frame, only. */
1692 /* Return the next or previous window of WINDOW in canonical ordering
1693 of windows. NEXT_P non-zero means return the next window. See the
1694 documentation string of next-window for the meaning of MINIBUF and
1698 next_window (window
, minibuf
, all_frames
, next_p
)
1699 Lisp_Object window
, minibuf
, all_frames
;
1702 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1704 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1705 return the first window on the frame. */
1706 if (FRAMEP (all_frames
)
1707 && !EQ (all_frames
, XWINDOW (window
)->frame
))
1708 return Fframe_first_window (all_frames
);
1714 /* Find WINDOW in the list of all windows. */
1715 list
= Fmemq (window
, window_list ());
1717 /* Scan forward from WINDOW to the end of the window list. */
1719 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
1720 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1723 /* Scan from the start of the window list up to WINDOW. */
1725 for (list
= Vwindow_list
;
1726 CONSP (list
) && !EQ (XCAR (list
), window
);
1728 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1732 window
= XCAR (list
);
1736 Lisp_Object candidate
, list
;
1738 /* Scan through the list of windows for candidates. If there are
1739 candidate windows in front of WINDOW, the last one of these
1740 is the one we want. If there are candidates following WINDOW
1741 in the list, again the last one of these is the one we want. */
1743 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
1745 if (EQ (XCAR (list
), window
))
1747 if (WINDOWP (candidate
))
1750 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
1752 candidate
= XCAR (list
);
1755 if (WINDOWP (candidate
))
1763 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
1764 doc
: /* Return next window after WINDOW in canonical ordering of windows.
1765 If omitted, WINDOW defaults to the selected window.
1767 Optional second arg MINIBUF t means count the minibuffer window even
1768 if not active. MINIBUF nil or omitted means count the minibuffer iff
1769 it is active. MINIBUF neither t nor nil means not to count the
1770 minibuffer even if it is active.
1772 Several frames may share a single minibuffer; if the minibuffer
1773 counts, all windows on all frames that share that minibuffer count
1774 too. Therefore, `next-window' can be used to iterate through the
1775 set of windows even when the minibuffer is on another frame. If the
1776 minibuffer does not count, only windows from WINDOW's frame count.
1778 Optional third arg ALL-FRAMES t means include windows on all frames.
1779 ALL-FRAMES nil or omitted means cycle within the frames as specified
1780 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1781 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1782 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1783 Anything else means restrict to WINDOW's frame.
1785 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1786 `next-window' to iterate through the entire cycle of acceptable
1787 windows, eventually ending up back at the window you started with.
1788 `previous-window' traverses the same cycle, in the reverse order. */)
1789 (window
, minibuf
, all_frames
)
1790 Lisp_Object window
, minibuf
, all_frames
;
1792 return next_window (window
, minibuf
, all_frames
, 1);
1796 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1797 doc
: /* Return the window preceding WINDOW in canonical ordering of windows.
1798 If omitted, WINDOW defaults to the selected window.
1800 Optional second arg MINIBUF t means count the minibuffer window even
1801 if not active. MINIBUF nil or omitted means count the minibuffer iff
1802 it is active. MINIBUF neither t nor nil means not to count the
1803 minibuffer even if it is active.
1805 Several frames may share a single minibuffer; if the minibuffer
1806 counts, all windows on all frames that share that minibuffer count
1807 too. Therefore, `previous-window' can be used to iterate through
1808 the set of windows even when the minibuffer is on another frame. If
1809 the minibuffer does not count, only windows from WINDOW's frame count
1811 Optional third arg ALL-FRAMES t means include windows on all frames.
1812 ALL-FRAMES nil or omitted means cycle within the frames as specified
1813 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1814 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1815 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1816 Anything else means restrict to WINDOW's frame.
1818 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1819 `previous-window' to iterate through the entire cycle of acceptable
1820 windows, eventually ending up back at the window you started with.
1821 `next-window' traverses the same cycle, in the reverse order. */)
1822 (window
, minibuf
, all_frames
)
1823 Lisp_Object window
, minibuf
, all_frames
;
1825 return next_window (window
, minibuf
, all_frames
, 0);
1829 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1830 doc
: /* Select the ARG'th different window on this frame.
1831 All windows on current frame are arranged in a cyclic order.
1832 This command selects the window ARG steps away in that order.
1833 A negative ARG moves in the opposite order. The optional second
1834 argument ALL-FRAMES has the same meaning as in `next-window', which see. */)
1836 Lisp_Object arg
, all_frames
;
1842 window
= selected_window
;
1844 for (i
= XINT (arg
); i
> 0; --i
)
1845 window
= Fnext_window (window
, Qnil
, all_frames
);
1847 window
= Fprevious_window (window
, Qnil
, all_frames
);
1849 Fselect_window (window
, Qnil
);
1854 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
1855 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
1856 FRAME nil or omitted means use the selected frame.
1857 WINDOW nil or omitted means use the selected window.
1858 MINIBUF t means include the minibuffer window, even if it isn't active.
1859 MINIBUF nil or omitted means include the minibuffer window only
1861 MINIBUF neither nil nor t means never include the minibuffer window. */)
1862 (frame
, minibuf
, window
)
1863 Lisp_Object frame
, minibuf
, window
;
1866 window
= selected_window
;
1868 frame
= selected_frame
;
1870 if (!EQ (frame
, XWINDOW (window
)->frame
))
1871 error ("Window is on a different frame");
1873 return window_list_1 (window
, minibuf
, frame
);
1877 /* Return a list of windows in canonical ordering. Arguments are like
1878 for `next-window'. */
1881 window_list_1 (window
, minibuf
, all_frames
)
1882 Lisp_Object window
, minibuf
, all_frames
;
1884 Lisp_Object tail
, list
, rest
;
1886 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1889 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
1890 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
1891 list
= Fcons (XCAR (tail
), list
);
1893 /* Rotate the list to start with WINDOW. */
1894 list
= Fnreverse (list
);
1895 rest
= Fmemq (window
, list
);
1896 if (!NILP (rest
) && !EQ (rest
, list
))
1898 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
1900 XSETCDR (tail
, Qnil
);
1901 list
= nconc2 (rest
, list
);
1908 /* Look at all windows, performing an operation specified by TYPE
1910 If FRAMES is Qt, look at all frames;
1911 Qnil, look at just the selected frame;
1912 Qvisible, look at visible frames;
1913 a frame, just look at windows on that frame.
1914 If MINI is non-zero, perform the operation on minibuffer windows too. */
1919 GET_BUFFER_WINDOW
, /* Arg is buffer */
1920 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1921 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1922 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1924 UNSHOW_BUFFER
, /* Arg is buffer */
1925 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
1930 window_loop (type
, obj
, mini
, frames
)
1931 enum window_loop type
;
1932 Lisp_Object obj
, frames
;
1935 Lisp_Object window
, windows
, best_window
, frame_arg
;
1937 struct gcpro gcpro1
;
1939 /* If we're only looping through windows on a particular frame,
1940 frame points to that frame. If we're looping through windows
1941 on all frames, frame is 0. */
1942 if (FRAMEP (frames
))
1943 f
= XFRAME (frames
);
1944 else if (NILP (frames
))
1945 f
= SELECTED_FRAME ();
1950 frame_arg
= Qlambda
;
1951 else if (EQ (frames
, make_number (0)))
1953 else if (EQ (frames
, Qvisible
))
1958 /* frame_arg is Qlambda to stick to one frame,
1959 Qvisible to consider all visible frames,
1962 /* Pick a window to start with. */
1966 window
= FRAME_SELECTED_WINDOW (f
);
1968 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
1970 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
1974 for (; CONSP (windows
); windows
= XCDR (windows
))
1978 window
= XCAR (windows
);
1979 w
= XWINDOW (window
);
1981 /* Note that we do not pay attention here to whether the frame
1982 is visible, since Fwindow_list skips non-visible frames if
1983 that is desired, under the control of frame_arg. */
1984 if (!MINI_WINDOW_P (w
)
1985 /* For UNSHOW_BUFFER, we must always consider all windows. */
1986 || type
== UNSHOW_BUFFER
1987 || (mini
&& minibuf_level
> 0))
1990 case GET_BUFFER_WINDOW
:
1991 if (EQ (w
->buffer
, obj
)
1992 /* Don't find any minibuffer window
1993 except the one that is currently in use. */
1994 && (MINI_WINDOW_P (w
)
1995 ? EQ (window
, minibuf_window
)
1998 if (NILP (best_window
))
1999 best_window
= window
;
2000 else if (EQ (window
, selected_window
))
2001 /* For compatibility with 20.x, prefer to return
2003 best_window
= window
;
2007 case GET_LRU_WINDOW
:
2008 /* `obj' is an integer encoding a bitvector.
2009 `obj & 1' means consider only full-width windows.
2010 `obj & 2' means consider also dedicated windows. */
2011 if (((XINT (obj
) & 1) && !WINDOW_FULL_WIDTH_P (w
))
2012 || (!(XINT (obj
) & 2) && EQ (w
->dedicated
, Qt
))
2013 /* Minibuffer windows are always ignored. */
2014 || MINI_WINDOW_P (w
))
2016 if (NILP (best_window
)
2017 || (XFASTINT (XWINDOW (best_window
)->use_time
)
2018 > XFASTINT (w
->use_time
)))
2019 best_window
= window
;
2022 case DELETE_OTHER_WINDOWS
:
2023 if (!EQ (window
, obj
))
2024 Fdelete_window (window
);
2027 case DELETE_BUFFER_WINDOWS
:
2028 if (EQ (w
->buffer
, obj
))
2030 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2032 /* If this window is dedicated, and in a frame of its own,
2034 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
2035 && !NILP (w
->dedicated
)
2036 && other_visible_frames (f
))
2038 /* Skip the other windows on this frame.
2039 There might be one, the minibuffer! */
2040 while (CONSP (XCDR (windows
))
2041 && EQ (XWINDOW (XCAR (windows
))->frame
,
2042 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2043 windows
= XCDR (windows
);
2045 /* Now we can safely delete the frame. */
2046 Fdelete_frame (w
->frame
, Qnil
);
2048 else if (NILP (w
->parent
))
2050 /* If we're deleting the buffer displayed in the
2051 only window on the frame, find a new buffer to
2054 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2055 Fset_window_buffer (window
, buffer
, Qnil
);
2056 if (EQ (window
, selected_window
))
2057 Fset_buffer (w
->buffer
);
2060 Fdelete_window (window
);
2064 case GET_LARGEST_WINDOW
:
2065 { /* nil `obj' means to ignore dedicated windows. */
2066 /* Ignore dedicated windows and minibuffers. */
2067 if (MINI_WINDOW_P (w
) || (NILP (obj
) && EQ (w
->dedicated
, Qt
)))
2070 if (NILP (best_window
))
2071 best_window
= window
;
2074 struct window
*b
= XWINDOW (best_window
);
2075 if (XFASTINT (w
->total_lines
) * XFASTINT (w
->total_cols
)
2076 > XFASTINT (b
->total_lines
) * XFASTINT (b
->total_cols
))
2077 best_window
= window
;
2083 if (EQ (w
->buffer
, obj
))
2086 struct frame
*f
= XFRAME (w
->frame
);
2088 /* Find another buffer to show in this window. */
2089 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2091 /* If this window is dedicated, and in a frame of its own,
2093 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
2094 && !NILP (w
->dedicated
)
2095 && other_visible_frames (f
))
2097 /* Skip the other windows on this frame.
2098 There might be one, the minibuffer! */
2099 while (CONSP (XCDR (windows
))
2100 && EQ (XWINDOW (XCAR (windows
))->frame
,
2101 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2102 windows
= XCDR (windows
);
2104 /* Now we can safely delete the frame. */
2105 Fdelete_frame (w
->frame
, Qnil
);
2107 else if (!NILP (w
->dedicated
) && !NILP (w
->parent
))
2110 XSETWINDOW (window
, w
);
2111 /* If this window is dedicated and not the only window
2112 in its frame, then kill it. */
2113 Fdelete_window (window
);
2117 /* Otherwise show a different buffer in the window. */
2118 w
->dedicated
= Qnil
;
2119 Fset_window_buffer (window
, buffer
, Qnil
);
2120 if (EQ (window
, selected_window
))
2121 Fset_buffer (w
->buffer
);
2126 case REDISPLAY_BUFFER_WINDOWS
:
2127 if (EQ (w
->buffer
, obj
))
2129 mark_window_display_accurate (window
, 0);
2130 w
->update_mode_line
= Qt
;
2131 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2132 ++update_mode_lines
;
2133 best_window
= window
;
2137 /* Check for a window that has a killed buffer. */
2138 case CHECK_ALL_WINDOWS
:
2139 if (! NILP (w
->buffer
)
2140 && NILP (XBUFFER (w
->buffer
)->name
))
2144 case WINDOW_LOOP_UNUSED
:
2153 /* Used for debugging. Abort if any window has a dead buffer. */
2156 check_all_windows ()
2158 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2161 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 2, 0,
2162 doc
: /* Return the window least recently selected or used for display.
2163 Return a full-width window if possible.
2164 A minibuffer window is never a candidate.
2165 A dedicated window is never a candidate, unless DEDICATED is non-nil,
2166 so if all windows are dedicated, the value is nil.
2167 If optional argument FRAME is `visible', search all visible frames.
2168 If FRAME is 0, search all visible and iconified frames.
2169 If FRAME is t, search all frames.
2170 If FRAME is nil, search only the selected frame.
2171 If FRAME is a frame, search only that frame. */)
2173 Lisp_Object frame
, dedicated
;
2175 register Lisp_Object w
;
2176 /* First try for a window that is full-width */
2177 w
= window_loop (GET_LRU_WINDOW
,
2178 NILP (dedicated
) ? make_number (1) : make_number (3),
2180 if (!NILP (w
) && !EQ (w
, selected_window
))
2182 /* If none of them, try the rest */
2183 return window_loop (GET_LRU_WINDOW
,
2184 NILP (dedicated
) ? make_number (0) : make_number (2),
2188 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 2, 0,
2189 doc
: /* Return the largest window in area.
2190 A minibuffer window is never a candidate.
2191 A dedicated window is never a candidate unless DEDICATED is non-nil,
2192 so if all windows are dedicated, the value is nil.
2193 If optional argument FRAME is `visible', search all visible frames.
2194 If FRAME is 0, search all visible and iconified frames.
2195 If FRAME is t, search all frames.
2196 If FRAME is nil, search only the selected frame.
2197 If FRAME is a frame, search only that frame. */)
2199 Lisp_Object frame
, dedicated
;
2201 return window_loop (GET_LARGEST_WINDOW
, dedicated
, 0,
2205 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
2206 doc
: /* Return a window currently displaying BUFFER, or nil if none.
2207 BUFFER can be a buffer or a buffer name.
2208 If optional argument FRAME is `visible', search all visible frames.
2209 If optional argument FRAME is 0, search all visible and iconified frames.
2210 If FRAME is t, search all frames.
2211 If FRAME is nil, search only the selected frame.
2212 If FRAME is a frame, search only that frame. */)
2214 Lisp_Object buffer
, frame
;
2216 buffer
= Fget_buffer (buffer
);
2217 if (BUFFERP (buffer
))
2218 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
2223 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
2225 doc
: /* Make WINDOW (or the selected window) fill its frame.
2226 Only the frame WINDOW is on is affected.
2227 This function tries to reduce display jumps
2228 by keeping the text previously visible in WINDOW
2229 in the same place on the frame. Doing this depends on
2230 the value of (window-start WINDOW), so if calling this function
2231 in a program gives strange scrolling, make sure the window-start
2232 value is reasonable when this function is called. */)
2241 window
= selected_window
;
2243 CHECK_LIVE_WINDOW (window
);
2244 w
= XWINDOW (window
);
2246 startpos
= marker_position (w
->start
);
2247 top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2249 if (MINI_WINDOW_P (w
) && top
> 0)
2250 error ("Can't expand minibuffer to full frame");
2252 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
2254 /* Try to minimize scrolling, by setting the window start to the point
2255 will cause the text at the old window start to be at the same place
2256 on the frame. But don't try to do this if the window start is
2257 outside the visible portion (as might happen when the display is
2258 not current, due to typeahead). */
2259 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2261 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2262 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2264 struct position pos
;
2265 struct buffer
*obuf
= current_buffer
;
2267 Fset_buffer (w
->buffer
);
2268 /* This computation used to temporarily move point, but that can
2269 have unwanted side effects due to text properties. */
2270 pos
= *vmotion (startpos
, -top
, w
);
2272 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2273 w
->window_end_valid
= Qnil
;
2274 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
2275 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
2277 /* We need to do this, so that the window-scroll-functions
2279 w
->optional_new_start
= Qt
;
2281 set_buffer_internal (obuf
);
2287 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
2288 1, 2, "bDelete windows on (buffer): ",
2289 doc
: /* Delete all windows showing BUFFER.
2290 BUFFER must be a buffer or the name of an existing buffer.
2291 Optional second argument FRAME controls which frames are affected.
2292 If optional argument FRAME is `visible', search all visible frames.
2293 If FRAME is 0, search all visible and iconified frames.
2294 If FRAME is nil, search all frames.
2295 If FRAME is t, search only the selected frame.
2296 If FRAME is a frame, search only that frame. */)
2298 Lisp_Object buffer
, frame
;
2300 /* FRAME uses t and nil to mean the opposite of what window_loop
2304 else if (EQ (frame
, Qt
))
2309 buffer
= Fget_buffer (buffer
);
2310 CHECK_BUFFER (buffer
);
2311 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
2317 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
2318 Sreplace_buffer_in_windows
,
2319 1, 1, "bReplace buffer in windows: ",
2320 doc
: /* Replace BUFFER with some other buffer in all windows showing it.
2321 BUFFER may be a buffer or the name of an existing buffer. */)
2327 buffer
= Fget_buffer (buffer
);
2328 CHECK_BUFFER (buffer
);
2329 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
2334 /* Replace BUFFER with some other buffer in all windows
2335 of all frames, even those on other keyboards. */
2338 replace_buffer_in_all_windows (buffer
)
2342 Lisp_Object tail
, frame
;
2344 /* A single call to window_loop won't do the job
2345 because it only considers frames on the current keyboard.
2346 So loop manually over frames, and handle each one. */
2347 FOR_EACH_FRAME (tail
, frame
)
2348 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
2350 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
2354 /* Set the height of WINDOW and all its inferiors. */
2356 /* The smallest acceptable dimensions for a window. Anything smaller
2357 might crash Emacs. */
2359 #define MIN_SAFE_WINDOW_WIDTH (2)
2360 #define MIN_SAFE_WINDOW_HEIGHT (1)
2362 /* Make sure that window_min_height and window_min_width are
2363 not too small; if they are, set them to safe minima. */
2366 check_min_window_sizes ()
2368 /* Smaller values might permit a crash. */
2369 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
2370 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
2371 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
2372 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
2375 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2376 minimum allowable size. */
2379 check_frame_size (frame
, rows
, cols
)
2383 /* For height, we have to see:
2384 how many windows the frame has at minimum (one or two),
2385 and whether it has a menu bar or other special stuff at the top. */
2387 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
2388 ? MIN_SAFE_WINDOW_HEIGHT
2389 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
2391 if (FRAME_TOP_MARGIN (frame
) > 0)
2392 min_height
+= FRAME_TOP_MARGIN (frame
);
2394 if (*rows
< min_height
)
2396 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2397 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2401 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2402 check if W's width can be changed, otherwise check W's height.
2403 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2404 siblings, too. If none of the siblings is resizable, WINDOW isn't
2408 window_fixed_size_p (w
, width_p
, check_siblings_p
)
2410 int width_p
, check_siblings_p
;
2415 if (!NILP (w
->hchild
))
2417 c
= XWINDOW (w
->hchild
);
2421 /* A horiz. combination is fixed-width if all of if its
2423 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2424 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2425 fixed_p
= c
== NULL
;
2429 /* A horiz. combination is fixed-height if one of if its
2431 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2432 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2433 fixed_p
= c
!= NULL
;
2436 else if (!NILP (w
->vchild
))
2438 c
= XWINDOW (w
->vchild
);
2442 /* A vert. combination is fixed-width if one of if its
2444 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2445 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2446 fixed_p
= c
!= NULL
;
2450 /* A vert. combination is fixed-height if all of if its
2452 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2453 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2454 fixed_p
= c
== NULL
;
2457 else if (BUFFERP (w
->buffer
))
2459 struct buffer
*old
= current_buffer
;
2462 current_buffer
= XBUFFER (w
->buffer
);
2463 val
= find_symbol_value (Qwindow_size_fixed
);
2464 current_buffer
= old
;
2467 if (!EQ (val
, Qunbound
))
2469 fixed_p
= !NILP (val
);
2472 && ((EQ (val
, Qheight
) && width_p
)
2473 || (EQ (val
, Qwidth
) && !width_p
)))
2477 /* Can't tell if this one is resizable without looking at
2478 siblings. If all siblings are fixed-size this one is too. */
2479 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
2483 for (child
= w
->prev
; !NILP (child
); child
= XWINDOW (child
)->prev
)
2484 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2488 for (child
= w
->next
; !NILP (child
); child
= XWINDOW (child
)->next
)
2489 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2503 /* Return the minimum size of window W, not taking fixed-width windows
2504 into account. WIDTH_P non-zero means return the minimum width,
2505 otherwise return the minimum height. If W is a combination window,
2506 compute the minimum size from the minimum sizes of W's children. */
2509 window_min_size_1 (w
, width_p
)
2516 if (!NILP (w
->hchild
))
2518 c
= XWINDOW (w
->hchild
);
2523 /* The min width of a horizontal combination is
2524 the sum of the min widths of its children. */
2527 size
+= window_min_size_1 (c
, width_p
);
2528 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2533 /* The min height a horizontal combination equals
2534 the maximum of all min height of its children. */
2537 int min_size
= window_min_size_1 (c
, width_p
);
2538 size
= max (min_size
, size
);
2539 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2543 else if (!NILP (w
->vchild
))
2545 c
= XWINDOW (w
->vchild
);
2550 /* The min width of a vertical combination is
2551 the maximum of the min widths of its children. */
2554 int min_size
= window_min_size_1 (c
, width_p
);
2555 size
= max (min_size
, size
);
2556 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2561 /* The min height of a vertical combination equals
2562 the sum of the min height of its children. */
2565 size
+= window_min_size_1 (c
, width_p
);
2566 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2573 size
= window_min_width
;
2576 if (MINI_WINDOW_P (w
)
2577 || (!WINDOW_WANTS_MODELINE_P (w
)
2578 && !WINDOW_WANTS_HEADER_LINE_P (w
)))
2581 size
= window_min_height
;
2589 /* Return the minimum size of window W, taking fixed-size windows into
2590 account. WIDTH_P non-zero means return the minimum width,
2591 otherwise return the minimum height. IGNORE_FIXED_P non-zero means
2592 ignore if W is fixed-size. Set *FIXED to 1 if W is fixed-size
2593 unless FIXED is null. */
2596 window_min_size (w
, width_p
, ignore_fixed_p
, fixed
)
2598 int width_p
, ignore_fixed_p
, *fixed
;
2605 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
2611 size
= width_p
? XFASTINT (w
->total_cols
) : XFASTINT (w
->total_lines
);
2613 size
= window_min_size_1 (w
, width_p
);
2619 /* Adjust the margins of window W if text area is too small.
2620 Return 1 if window width is ok after adjustment; 0 if window
2621 is still too narrow. */
2624 adjust_window_margins (w
)
2627 int box_cols
= (WINDOW_TOTAL_COLS (w
)
2628 - WINDOW_FRINGE_COLS (w
)
2629 - WINDOW_SCROLL_BAR_COLS (w
));
2630 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
2631 + WINDOW_RIGHT_MARGIN_COLS (w
));
2633 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
2636 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
2639 /* Window's text area is too narrow, but reducing the window
2640 margins will fix that. */
2641 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
2642 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
2644 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
2645 w
->left_margin_cols
= w
->right_margin_cols
2646 = make_number (margin_cols
/2);
2648 w
->right_margin_cols
= make_number (margin_cols
);
2651 w
->left_margin_cols
= make_number (margin_cols
);
2655 /* Calculate new sizes for windows in the list FORWARD when the window size
2656 goes from TOTAL to SIZE. TOTAL must be greater than SIZE.
2657 The number of windows in FORWARD is NCHILDREN, and the number that
2658 can shrink is SHRINKABLE.
2659 The minimum size a window can have is MIN_SIZE.
2660 If we are shrinking fixed windows, RESIZE_FIXED_P is non-zero.
2661 If we are shrinking columns, WIDTH_P is non-zero, otherwise we are
2664 This function returns an allocated array of new sizes that the caller
2665 must free. The size -1 means the window is fixed and RESIZE_FIXED_P
2666 is zero. Array index 0 refers to the first window in FORWARD, 1 to
2667 the second, and so on.
2669 This function tries to keep windows at least at the minimum size
2670 and resize other windows before it resizes any window to zero (i.e.
2671 delete that window).
2673 Windows are resized proportional to their size, so bigger windows
2674 shrink more than smaller windows. */
2676 shrink_windows (total
, size
, nchildren
, shrinkable
,
2677 min_size
, resize_fixed_p
, forward
, width_p
)
2678 int total
, size
, nchildren
, shrinkable
, min_size
;
2679 int resize_fixed_p
, width_p
;
2680 Lisp_Object forward
;
2682 int available_resize
= 0;
2686 int smallest
= total
;
2687 int total_removed
= 0;
2688 int total_shrink
= total
- size
;
2691 new_sizes
= xmalloc (sizeof (*new_sizes
) * nchildren
);
2693 for (i
= 0, child
= forward
; !NILP (child
); child
= c
->next
, ++i
)
2697 c
= XWINDOW (child
);
2698 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2700 if (! resize_fixed_p
&& window_fixed_size_p (c
, width_p
, 0))
2704 new_sizes
[i
] = child_size
;
2705 if (child_size
> min_size
)
2706 available_resize
+= child_size
- min_size
;
2709 /* We might need to shrink some windows to zero. Find the smallest
2710 windows and set them to 0 until we can fulfil the new size. */
2712 while (shrinkable
> 1 && size
+ available_resize
< total
)
2714 for (i
= 0; i
< nchildren
; ++i
)
2715 if (new_sizes
[i
] > 0 && smallest
> new_sizes
[i
])
2716 smallest
= new_sizes
[i
];
2718 for (i
= 0; i
< nchildren
; ++i
)
2719 if (new_sizes
[i
] == smallest
)
2721 /* Resize this window down to zero. */
2723 if (smallest
> min_size
)
2724 available_resize
-= smallest
- min_size
;
2725 available_resize
+= smallest
;
2727 total_removed
+= smallest
;
2729 /* We don't know what the smallest is now. */
2732 /* Out of for, just remove one window at the time and
2733 check again if we have enough space. */
2738 /* Now, calculate the new sizes. Try to shrink each window
2739 proportional to its size. */
2740 for (i
= 0; i
< nchildren
; ++i
)
2742 if (new_sizes
[i
] > min_size
)
2744 int to_shrink
= total_shrink
*new_sizes
[i
]/total
;
2745 if (new_sizes
[i
] - to_shrink
< min_size
)
2746 to_shrink
= new_sizes
[i
] - min_size
;
2747 new_sizes
[i
] -= to_shrink
;
2748 total_removed
+= to_shrink
;
2752 /* Any reminder due to rounding, we just subtract from windows
2753 that are left and still can be shrunk. */
2754 while (total_shrink
> total_removed
)
2756 int nonzero_sizes
= 0;
2757 int nonzero_idx
= -1;
2759 for (i
= 0; i
< nchildren
; ++i
)
2760 if (new_sizes
[i
] > 0)
2766 for (i
= 0; i
< nchildren
; ++i
)
2767 if (new_sizes
[i
] > min_size
)
2772 /* Out of for, just shrink one window at the time and
2773 check again if we have enough space. */
2778 /* Special case, only one window left. */
2779 if (nonzero_sizes
== 1)
2783 /* Any surplus due to rounding, we add to windows that are left. */
2784 while (total_shrink
< total_removed
)
2786 for (i
= 0; i
< nchildren
; ++i
)
2788 if (new_sizes
[i
] != 0 && total_shrink
< total_removed
)
2800 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
2801 WINDOW's width. Resize WINDOW's children, if any, so that they
2802 keep their proportionate size relative to WINDOW. Propagate
2803 WINDOW's top or left edge position to children. Delete windows
2804 that become too small unless NODELETE_P is non-zero.
2806 If NODELETE_P is 2, that means we do delete windows that are
2807 too small, even if they were too small before! */
2810 size_window (window
, size
, width_p
, nodelete_p
)
2812 int size
, width_p
, nodelete_p
;
2814 struct window
*w
= XWINDOW (window
);
2816 Lisp_Object child
, *forward
, *sideward
;
2817 int old_size
, min_size
, safe_min_size
;
2819 /* We test nodelete_p != 2 and nodelete_p != 1 below, so it
2820 seems like it's too soon to do this here. ++KFS. */
2821 if (nodelete_p
== 2)
2824 check_min_window_sizes ();
2825 size
= max (0, size
);
2827 /* If the window has been "too small" at one point,
2828 don't delete it for being "too small" in the future.
2829 Preserve it as long as that is at all possible. */
2832 old_size
= WINDOW_TOTAL_COLS (w
);
2833 min_size
= window_min_width
;
2834 /* Ensure that there is room for the scroll bar and fringes!
2835 We may reduce display margins though. */
2836 safe_min_size
= (MIN_SAFE_WINDOW_WIDTH
2837 + WINDOW_FRINGE_COLS (w
)
2838 + WINDOW_SCROLL_BAR_COLS (w
));
2842 old_size
= XINT (w
->total_lines
);
2843 min_size
= window_min_height
;
2844 safe_min_size
= MIN_SAFE_WINDOW_HEIGHT
;
2847 if (old_size
< min_size
&& nodelete_p
!= 2)
2848 w
->too_small_ok
= Qt
;
2850 /* Maybe delete WINDOW if it's too small. */
2851 if (nodelete_p
!= 1 && !NILP (w
->parent
))
2853 if (!MINI_WINDOW_P (w
) && !NILP (w
->too_small_ok
))
2854 min_size
= width_p
? MIN_SAFE_WINDOW_WIDTH
: MIN_SAFE_WINDOW_HEIGHT
;
2855 if (min_size
< safe_min_size
)
2856 min_size
= safe_min_size
;
2857 if (size
< min_size
)
2859 delete_window (window
);
2864 /* Set redisplay hints. */
2865 w
->last_modified
= make_number (0);
2866 w
->last_overlay_modified
= make_number (0);
2867 windows_or_buffers_changed
++;
2868 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w
->frame
)) = 1;
2872 sideward
= &w
->vchild
;
2873 forward
= &w
->hchild
;
2874 w
->total_cols
= make_number (size
);
2875 adjust_window_margins (w
);
2879 sideward
= &w
->hchild
;
2880 forward
= &w
->vchild
;
2881 w
->total_lines
= make_number (size
);
2882 w
->orig_total_lines
= Qnil
;
2885 if (!NILP (*sideward
))
2887 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
2889 c
= XWINDOW (child
);
2891 c
->left_col
= w
->left_col
;
2893 c
->top_line
= w
->top_line
;
2894 size_window (child
, size
, width_p
, nodelete_p
);
2897 else if (!NILP (*forward
))
2899 int fixed_size
, each
, extra
, n
;
2900 int resize_fixed_p
, nfixed
;
2901 int last_pos
, first_pos
, nchildren
, total
;
2902 int *new_sizes
= NULL
;
2904 /* Determine the fixed-size portion of the this window, and the
2905 number of child windows. */
2906 fixed_size
= nchildren
= nfixed
= total
= 0;
2907 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
2911 c
= XWINDOW (child
);
2912 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2913 total
+= child_size
;
2915 if (window_fixed_size_p (c
, width_p
, 0))
2917 fixed_size
+= child_size
;
2922 /* If the new size is smaller than fixed_size, or if there
2923 aren't any resizable windows, allow resizing fixed-size
2925 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
2927 /* Compute how many lines/columns to add/remove to each child. The
2928 value of extra takes care of rounding errors. */
2929 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
2930 if (size
< total
&& n
> 1)
2931 new_sizes
= shrink_windows (total
, size
, nchildren
, n
, min_size
,
2932 resize_fixed_p
, *forward
, width_p
);
2935 each
= (size
- total
) / n
;
2936 extra
= (size
- total
) - n
* each
;
2939 /* Compute new children heights and edge positions. */
2940 first_pos
= width_p
? XINT (w
->left_col
) : XINT (w
->top_line
);
2941 last_pos
= first_pos
;
2942 for (n
= 0, child
= *forward
; !NILP (child
); child
= c
->next
, ++n
)
2944 int new_size
, old_size
;
2946 c
= XWINDOW (child
);
2947 old_size
= width_p
? XFASTINT (c
->total_cols
) : XFASTINT (c
->total_lines
);
2948 new_size
= old_size
;
2950 /* The top or left edge position of this child equals the
2951 bottom or right edge of its predecessor. */
2953 c
->left_col
= make_number (last_pos
);
2955 c
->top_line
= make_number (last_pos
);
2957 /* If this child can be resized, do it. */
2958 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
2960 new_size
= new_sizes
? new_sizes
[n
] : old_size
+ each
+ extra
;
2964 /* Set new height. Note that size_window also propagates
2965 edge positions to children, so it's not a no-op if we
2966 didn't change the child's size. */
2967 size_window (child
, new_size
, width_p
, 1);
2969 /* Remember the bottom/right edge position of this child; it
2970 will be used to set the top/left edge of the next child. */
2971 last_pos
+= new_size
;
2974 if (new_sizes
) xfree (new_sizes
);
2976 /* We should have covered the parent exactly with child windows. */
2977 xassert (size
== last_pos
- first_pos
);
2979 /* Now delete any children that became too small. */
2981 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2984 c
= XWINDOW (child
);
2985 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2986 size_window (child
, child_size
, width_p
, 2);
2991 /* Set WINDOW's height to HEIGHT, and recursively change the height of
2992 WINDOW's children. NODELETE non-zero means don't delete windows
2993 that become too small in the process. (The caller should check
2994 later and do so if appropriate.) */
2997 set_window_height (window
, height
, nodelete
)
3002 size_window (window
, height
, 0, nodelete
);
3006 /* Set WINDOW's width to WIDTH, and recursively change the width of
3007 WINDOW's children. NODELETE non-zero means don't delete windows
3008 that become too small in the process. (The caller should check
3009 later and do so if appropriate.) */
3012 set_window_width (window
, width
, nodelete
)
3017 size_window (window
, width
, 1, nodelete
);
3020 /* Change window heights in windows rooted in WINDOW by N lines. */
3023 change_window_heights (window
, n
)
3027 struct window
*w
= XWINDOW (window
);
3029 XSETFASTINT (w
->top_line
, XFASTINT (w
->top_line
) + n
);
3030 XSETFASTINT (w
->total_lines
, XFASTINT (w
->total_lines
) - n
);
3032 if (INTEGERP (w
->orig_top_line
))
3033 XSETFASTINT (w
->orig_top_line
, XFASTINT (w
->orig_top_line
) + n
);
3034 if (INTEGERP (w
->orig_total_lines
))
3035 XSETFASTINT (w
->orig_total_lines
, XFASTINT (w
->orig_total_lines
) - n
);
3037 /* Handle just the top child in a vertical split. */
3038 if (!NILP (w
->vchild
))
3039 change_window_heights (w
->vchild
, n
);
3041 /* Adjust all children in a horizontal split. */
3042 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
3044 w
= XWINDOW (window
);
3045 change_window_heights (window
, n
);
3050 int window_select_count
;
3053 Fset_window_buffer_unwind (obuf
)
3060 EXFUN (Fset_window_fringes
, 4);
3061 EXFUN (Fset_window_scroll_bars
, 4);
3063 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
3064 means it's allowed to run hooks. See make_frame for a case where
3065 it's not allowed. KEEP_MARGINS_P non-zero means that the current
3066 margins, fringes, and scroll-bar settings of the window are not
3067 reset from the buffer's local settings. */
3070 set_window_buffer (window
, buffer
, run_hooks_p
, keep_margins_p
)
3071 Lisp_Object window
, buffer
;
3072 int run_hooks_p
, keep_margins_p
;
3074 struct window
*w
= XWINDOW (window
);
3075 struct buffer
*b
= XBUFFER (buffer
);
3076 int count
= SPECPDL_INDEX ();
3080 if (EQ (window
, selected_window
))
3081 b
->last_selected_window
= window
;
3083 /* Let redisplay errors through. */
3084 b
->display_error_modiff
= 0;
3086 /* Update time stamps of buffer display. */
3087 if (INTEGERP (b
->display_count
))
3088 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
3089 b
->display_time
= Fcurrent_time ();
3091 XSETFASTINT (w
->window_end_pos
, 0);
3092 XSETFASTINT (w
->window_end_vpos
, 0);
3093 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
3094 w
->window_end_valid
= Qnil
;
3095 w
->hscroll
= w
->min_hscroll
= make_number (0);
3097 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3098 set_marker_restricted (w
->start
,
3099 make_number (b
->last_window_start
),
3101 w
->start_at_line_beg
= Qnil
;
3102 w
->force_start
= Qnil
;
3103 XSETFASTINT (w
->last_modified
, 0);
3104 XSETFASTINT (w
->last_overlay_modified
, 0);
3105 windows_or_buffers_changed
++;
3107 /* We must select BUFFER for running the window-scroll-functions.
3108 If WINDOW is selected, switch permanently.
3109 Otherwise, switch but go back to the ambient buffer afterward. */
3110 if (EQ (window
, selected_window
))
3111 Fset_buffer (buffer
);
3112 /* We can't check ! NILP (Vwindow_scroll_functions) here
3113 because that might itself be a local variable. */
3114 else if (window_initialized
)
3116 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
3117 Fset_buffer (buffer
);
3120 if (!keep_margins_p
)
3122 /* Set left and right marginal area width etc. from buffer. */
3124 /* This may call adjust_window_margins three times, so
3125 temporarily disable window margins. */
3126 Lisp_Object save_left
= w
->left_margin_cols
;
3127 Lisp_Object save_right
= w
->right_margin_cols
;
3129 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
3131 Fset_window_fringes (window
,
3132 b
->left_fringe_width
, b
->right_fringe_width
,
3133 b
->fringes_outside_margins
);
3135 Fset_window_scroll_bars (window
,
3136 b
->scroll_bar_width
,
3137 b
->vertical_scroll_bar_type
, Qnil
);
3139 w
->left_margin_cols
= save_left
;
3140 w
->right_margin_cols
= save_right
;
3142 Fset_window_margins (window
,
3143 b
->left_margin_cols
, b
->right_margin_cols
);
3148 if (! NILP (Vwindow_scroll_functions
))
3149 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3150 Fmarker_position (w
->start
));
3152 if (! NILP (Vwindow_configuration_change_hook
)
3153 && ! NILP (Vrun_hooks
))
3154 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3157 unbind_to (count
, Qnil
);
3161 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3162 doc
: /* Make WINDOW display BUFFER as its contents.
3163 BUFFER can be a buffer or the name of an existing buffer.
3164 Optional third arg KEEP-MARGINS non-nil means that WINDOW's current
3165 display margins, fringe widths, and scroll bar settings are maintained;
3166 the default is to reset these from BUFFER's local settings or the frame
3169 This function runs the hook `window-scroll-functions'. */)
3170 (window
, buffer
, keep_margins
)
3171 register Lisp_Object window
, buffer
, keep_margins
;
3173 register Lisp_Object tem
;
3174 register struct window
*w
= decode_window (window
);
3176 XSETWINDOW (window
, w
);
3177 buffer
= Fget_buffer (buffer
);
3178 CHECK_BUFFER (buffer
);
3180 if (NILP (XBUFFER (buffer
)->name
))
3181 error ("Attempt to display deleted buffer");
3185 error ("Window is deleted");
3186 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
3187 is first being set up. */
3189 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
3190 error ("Window is dedicated to `%s'",
3191 SDATA (XBUFFER (tem
)->name
));
3196 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3200 /* Note that selected_window can be nil
3201 when this is called from Fset_window_configuration. */
3203 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
3204 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
3205 If WINDOW is not already selected, make WINDOW's buffer current
3206 and make WINDOW the frame's selected window. Return WINDOW.
3207 Optional second arg NORECORD non-nil means
3208 do not put this buffer at the front of the list of recently selected ones.
3210 Note that the main editor command loop
3211 selects the buffer of the selected window before each command. */)
3213 register Lisp_Object window
, norecord
;
3215 register struct window
*w
;
3216 register struct window
*ow
;
3219 CHECK_LIVE_WINDOW (window
);
3221 w
= XWINDOW (window
);
3222 w
->frozen_window_start_p
= 0;
3224 ++window_select_count
;
3225 XSETFASTINT (w
->use_time
, window_select_count
);
3226 if (EQ (window
, selected_window
))
3229 /* Store the current buffer's actual point into the
3230 old selected window. It belongs to that window,
3231 and when the window is not selected, must be in the window. */
3232 if (!NILP (selected_window
))
3234 ow
= XWINDOW (selected_window
);
3235 if (! NILP (ow
->buffer
))
3236 set_marker_both (ow
->pointm
, ow
->buffer
,
3237 BUF_PT (XBUFFER (ow
->buffer
)),
3238 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
3241 selected_window
= window
;
3242 sf
= SELECTED_FRAME ();
3243 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
3245 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
3246 /* Use this rather than Fhandle_switch_frame
3247 so that FRAME_FOCUS_FRAME is moved appropriately as we
3248 move around in the state where a minibuffer in a separate
3250 Fselect_frame (WINDOW_FRAME (w
));
3253 sf
->selected_window
= window
;
3255 if (NILP (norecord
))
3256 record_buffer (w
->buffer
);
3257 Fset_buffer (w
->buffer
);
3259 XBUFFER (w
->buffer
)->last_selected_window
= window
;
3261 /* Go to the point recorded in the window.
3262 This is important when the buffer is in more
3263 than one window. It also matters when
3264 redisplay_window has altered point after scrolling,
3265 because it makes the change only in the window. */
3267 register int new_point
= marker_position (w
->pointm
);
3268 if (new_point
< BEGV
)
3270 else if (new_point
> ZV
)
3276 windows_or_buffers_changed
++;
3281 select_window_norecord (window
)
3284 return Fselect_window (window
, Qt
);
3287 /* Deiconify the frame containing the window WINDOW,
3288 unless it is the selected frame;
3291 The reason for the exception for the selected frame
3292 is that it seems better not to change the selected frames visibility
3293 merely because of displaying a different buffer in it.
3294 The deiconification is useful when a buffer gets shown in
3295 another frame that you were not using lately. */
3298 display_buffer_1 (window
)
3301 Lisp_Object frame
= XWINDOW (window
)->frame
;
3302 FRAME_PTR f
= XFRAME (frame
);
3304 FRAME_SAMPLE_VISIBILITY (f
);
3306 if (EQ (frame
, selected_frame
))
3307 ; /* Assume the selected frame is already visible enough. */
3308 else if (minibuf_level
> 0
3309 && MINI_WINDOW_P (XWINDOW (selected_window
))
3310 && WINDOW_LIVE_P (minibuf_selected_window
)
3311 && EQ (frame
, WINDOW_FRAME (XWINDOW (minibuf_selected_window
))))
3312 ; /* Assume the frame from which we invoked the minibuffer is visible. */
3315 if (FRAME_ICONIFIED_P (f
))
3316 Fmake_frame_visible (frame
);
3317 else if (FRAME_VISIBLE_P (f
))
3318 Fraise_frame (frame
);
3324 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
3325 doc
: /* Returns non-nil if a buffer named BUFFER-NAME gets a special frame.
3326 If the value is t, `display-buffer' or `pop-to-buffer' would create a
3327 special frame for that buffer using the default frame parameters.
3329 If the value is a list, it is a list of frame parameters that would be used
3330 to make a frame for that buffer.
3331 The variables `special-display-buffer-names'
3332 and `special-display-regexps' control this. */)
3334 Lisp_Object buffer_name
;
3338 CHECK_STRING (buffer_name
);
3340 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
3344 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
3348 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
3350 Lisp_Object car
= XCAR (tem
);
3352 && fast_string_match (car
, buffer_name
) >= 0)
3354 else if (CONSP (car
)
3355 && STRINGP (XCAR (car
))
3356 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
3362 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
3363 doc
: /* Returns non-nil if a buffer named BUFFER-NAME would use the same window.
3364 More precisely, if `display-buffer' or `pop-to-buffer' would display
3365 that buffer in the selected window rather than (as usual) in some other window.
3366 See `same-window-buffer-names' and `same-window-regexps'. */)
3368 Lisp_Object buffer_name
;
3372 CHECK_STRING (buffer_name
);
3374 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
3378 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
3382 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
3384 Lisp_Object car
= XCAR (tem
);
3386 && fast_string_match (car
, buffer_name
) >= 0)
3388 else if (CONSP (car
)
3389 && STRINGP (XCAR (car
))
3390 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
3396 /* Use B so the default is (other-buffer). */
3397 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
3398 "BDisplay buffer: \nP",
3399 doc
: /* Make BUFFER appear in some window but don't select it.
3400 BUFFER must be the name of an existing buffer, or, when called from Lisp,
3402 If BUFFER is shown already in some window, just use that one,
3403 unless the window is the selected window and the optional second
3404 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).
3405 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
3406 Returns the window displaying BUFFER.
3407 If `display-buffer-reuse-frames' is non-nil, and another frame is currently
3408 displaying BUFFER, then simply raise that frame.
3410 The variables `special-display-buffer-names',
3411 `special-display-regexps', `same-window-buffer-names', and
3412 `same-window-regexps' customize how certain buffer names are handled.
3413 The latter two take effect only if NOT-THIS-WINDOW is t.
3415 If optional argument FRAME is `visible', search all visible frames.
3416 If FRAME is 0, search all visible and iconified frames.
3417 If FRAME is t, search all frames.
3418 If FRAME is a frame, search only that frame.
3419 If FRAME is nil, search only the selected frame
3420 (actually the last nonminibuffer frame),
3421 unless `pop-up-frames' or `display-buffer-reuse-frames' is non-nil,
3422 which means search visible and iconified frames.
3424 If a full-width window on a splittable frame is available to display
3425 the buffer, it may be split, subject to the value of the variable
3426 `split-height-threshold'.
3428 If `even-window-heights' is non-nil, window heights will be evened out
3429 if displaying the buffer causes two vertically adjacent windows to be
3431 (buffer
, not_this_window
, frame
)
3432 register Lisp_Object buffer
, not_this_window
, frame
;
3434 register Lisp_Object window
, tem
, swp
;
3438 buffer
= Fget_buffer (buffer
);
3439 CHECK_BUFFER (buffer
);
3441 if (!NILP (Vdisplay_buffer_function
))
3442 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
3444 if (NILP (not_this_window
)
3445 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
3446 return display_buffer_1 (selected_window
);
3448 /* See if the user has specified this buffer should appear
3449 in the selected window. */
3450 if (NILP (not_this_window
))
3452 swp
= Fsame_window_p (XBUFFER (buffer
)->name
);
3453 if (!NILP (swp
) && !no_switch_window (selected_window
))
3455 Fswitch_to_buffer (buffer
, Qnil
);
3456 return display_buffer_1 (selected_window
);
3460 /* If the user wants pop-up-frames or display-buffer-reuse-frames,
3461 look for a window showing BUFFER on any visible or iconified frame.
3462 Otherwise search only the current frame. */
3465 else if (pop_up_frames
3466 || display_buffer_reuse_frames
3467 || last_nonminibuf_frame
== 0)
3468 XSETFASTINT (tem
, 0);
3470 XSETFRAME (tem
, last_nonminibuf_frame
);
3472 window
= Fget_buffer_window (buffer
, tem
);
3474 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
3475 return display_buffer_1 (window
);
3477 /* Certain buffer names get special handling. */
3478 if (!NILP (Vspecial_display_function
) && NILP (swp
))
3480 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
3482 return call1 (Vspecial_display_function
, buffer
);
3484 return call2 (Vspecial_display_function
, buffer
, tem
);
3487 /* If there are no frames open that have more than a minibuffer,
3488 we need to create a new frame. */
3489 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
3491 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3492 Fset_window_buffer (window
, buffer
, Qnil
);
3493 return display_buffer_1 (window
);
3496 f
= SELECTED_FRAME ();
3498 || FRAME_MINIBUF_ONLY_P (f
)
3499 /* If the current frame is a special display frame,
3500 don't try to reuse its windows. */
3501 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (f
))->dedicated
))
3506 if (FRAME_MINIBUF_ONLY_P (f
))
3507 XSETFRAME (frames
, last_nonminibuf_frame
);
3508 /* Don't try to create a window if we would get an error. */
3509 if (split_height_threshold
< window_min_height
<< 1)
3510 split_height_threshold
= window_min_height
<< 1;
3512 /* Note that both Fget_largest_window and Fget_lru_window
3513 ignore minibuffers and dedicated windows.
3514 This means they can return nil. */
3516 /* If the frame we would try to split cannot be split,
3517 try other frames. */
3518 if (FRAME_NO_SPLIT_P (NILP (frames
) ? f
: last_nonminibuf_frame
))
3520 /* Try visible frames first. */
3521 window
= Fget_largest_window (Qvisible
, Qt
);
3522 /* If that didn't work, try iconified frames. */
3524 window
= Fget_largest_window (make_number (0), Qt
);
3525 #if 0 /* Don't try windows on other displays. */
3527 window
= Fget_largest_window (Qt
, Qt
);
3531 window
= Fget_largest_window (frames
, Qt
);
3533 /* If we got a tall enough full-width window that can be split,
3536 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3537 && window_height (window
) >= split_height_threshold
3538 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
3539 window
= Fsplit_window (window
, Qnil
, Qnil
);
3542 Lisp_Object upper
, lower
, other
;
3544 window
= Fget_lru_window (frames
, Qt
);
3545 /* If the LRU window is selected, and big enough,
3546 and can be split, split it. */
3548 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3549 && (EQ (window
, selected_window
)
3550 || EQ (XWINDOW (window
)->parent
, Qnil
))
3551 && window_height (window
) >= window_min_height
<< 1)
3552 window
= Fsplit_window (window
, Qnil
, Qnil
);
3554 window
= Fget_lru_window (frames
, Qnil
);
3555 /* If Fget_lru_window returned nil, try other approaches. */
3557 /* Try visible frames first. */
3559 window
= Fget_buffer_window (buffer
, Qvisible
);
3561 window
= Fget_largest_window (Qvisible
, Qnil
);
3562 /* If that didn't work, try iconified frames. */
3564 window
= Fget_buffer_window (buffer
, make_number (0));
3566 window
= Fget_largest_window (make_number (0), Qnil
);
3568 #if 0 /* Don't try frames on other displays. */
3570 window
= Fget_buffer_window (buffer
, Qt
);
3572 window
= Fget_largest_window (Qt
, Qnil
);
3574 /* As a last resort, make a new frame. */
3576 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3577 /* If window appears above or below another,
3578 even out their heights. */
3579 other
= upper
= lower
= Qnil
;
3580 if (!NILP (XWINDOW (window
)->prev
))
3581 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
3582 if (!NILP (XWINDOW (window
)->next
))
3583 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
3585 && !NILP (Veven_window_heights
)
3586 /* Check that OTHER and WINDOW are vertically arrayed. */
3587 && !EQ (XWINDOW (other
)->top_line
, XWINDOW (window
)->top_line
)
3588 && (XFASTINT (XWINDOW (other
)->total_lines
)
3589 > XFASTINT (XWINDOW (window
)->total_lines
)))
3591 int total
= (XFASTINT (XWINDOW (other
)->total_lines
)
3592 + XFASTINT (XWINDOW (window
)->total_lines
));
3593 enlarge_window (upper
,
3594 total
/ 2 - XFASTINT (XWINDOW (upper
)->total_lines
),
3600 window
= Fget_lru_window (Qnil
, Qnil
);
3602 Fset_window_buffer (window
, buffer
, Qnil
);
3603 return display_buffer_1 (window
);
3607 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3609 doc
: /* Force redisplay of all windows.
3610 If optional arg OBJECT is a window, force redisplay of that window only.
3611 If OBJECT is a buffer or buffer name, force redisplay of all windows
3612 displaying that buffer. */)
3618 windows_or_buffers_changed
++;
3619 update_mode_lines
++;
3623 if (WINDOWP (object
))
3625 struct window
*w
= XWINDOW (object
);
3626 mark_window_display_accurate (object
, 0);
3627 w
->update_mode_line
= Qt
;
3628 if (BUFFERP (w
->buffer
))
3629 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
3630 ++update_mode_lines
;
3634 if (STRINGP (object
))
3635 object
= Fget_buffer (object
);
3636 if (BUFFERP (object
) && !NILP (XBUFFER (object
)->name
))
3638 /* Walk all windows looking for buffer, and force update
3639 of each of those windows. */
3641 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3642 return NILP (object
) ? Qnil
: Qt
;
3645 /* If nothing suitable was found, just return.
3646 We could signal an error, but this feature will typically be used
3647 asynchronously in timers or process sentinels, so we don't. */
3653 temp_output_buffer_show (buf
)
3654 register Lisp_Object buf
;
3656 register struct buffer
*old
= current_buffer
;
3657 register Lisp_Object window
;
3658 register struct window
*w
;
3660 XBUFFER (buf
)->directory
= current_buffer
->directory
;
3663 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3667 #if 0 /* rms: there should be no reason for this. */
3668 XBUFFER (buf
)->prevent_redisplay_optimizations_p
= 1;
3670 set_buffer_internal (old
);
3672 if (!NILP (Vtemp_buffer_show_function
))
3673 call1 (Vtemp_buffer_show_function
, buf
);
3676 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
3678 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3679 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3680 Vminibuf_scroll_window
= window
;
3681 w
= XWINDOW (window
);
3682 XSETFASTINT (w
->hscroll
, 0);
3683 XSETFASTINT (w
->min_hscroll
, 0);
3684 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3685 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3687 /* Run temp-buffer-show-hook, with the chosen window selected
3688 and its buffer current. */
3690 if (!NILP (Vrun_hooks
)
3691 && !NILP (Fboundp (Qtemp_buffer_show_hook
))
3692 && !NILP (Fsymbol_value (Qtemp_buffer_show_hook
)))
3694 int count
= SPECPDL_INDEX ();
3695 Lisp_Object prev_window
, prev_buffer
;
3696 prev_window
= selected_window
;
3697 XSETBUFFER (prev_buffer
, old
);
3699 /* Select the window that was chosen, for running the hook.
3700 Note: Both Fselect_window and select_window_norecord may
3701 set-buffer to the buffer displayed in the window,
3702 so we need to save the current buffer. --stef */
3703 record_unwind_protect (Fset_buffer
, prev_buffer
);
3704 record_unwind_protect (select_window_norecord
, prev_window
);
3705 Fselect_window (window
, Qt
);
3706 Fset_buffer (w
->buffer
);
3707 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
3708 unbind_to (count
, Qnil
);
3714 make_dummy_parent (window
)
3718 register struct window
*o
, *p
;
3721 o
= XWINDOW (window
);
3722 p
= allocate_window ();
3723 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
3724 ((struct Lisp_Vector
*) p
)->contents
[i
]
3725 = ((struct Lisp_Vector
*)o
)->contents
[i
];
3726 XSETWINDOW (new, p
);
3729 XSETFASTINT (p
->sequence_number
, sequence_number
);
3731 /* Put new into window structure in place of window */
3732 replace_window (window
, new);
3745 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
3746 doc
: /* Split WINDOW, putting SIZE lines in the first of the pair.
3747 WINDOW defaults to selected one and SIZE to half its size.
3748 If optional third arg HORFLAG is non-nil, split side by side
3749 and put SIZE columns in the first of the pair. In that case,
3750 SIZE includes that window's scroll bar, or the divider column to its right.
3751 Interactively, all arguments are nil.
3753 Returns the newly created window (which is the lower or rightmost one).
3754 The upper or leftmost window is the original one and remains selected.
3755 See Info node `(elisp)Splitting Windows' for more details and examples.*/)
3756 (window
, size
, horflag
)
3757 Lisp_Object window
, size
, horflag
;
3759 register Lisp_Object
new;
3760 register struct window
*o
, *p
;
3762 register int size_int
;
3765 window
= selected_window
;
3767 CHECK_LIVE_WINDOW (window
);
3769 o
= XWINDOW (window
);
3770 fo
= XFRAME (WINDOW_FRAME (o
));
3774 if (!NILP (horflag
))
3775 /* Calculate the size of the left-hand window, by dividing
3776 the usable space in columns by two.
3777 We round up, since the left-hand window may include
3778 a dividing line, while the right-hand may not. */
3779 size_int
= (XFASTINT (o
->total_cols
) + 1) >> 1;
3781 size_int
= XFASTINT (o
->total_lines
) >> 1;
3785 CHECK_NUMBER (size
);
3786 size_int
= XINT (size
);
3789 if (MINI_WINDOW_P (o
))
3790 error ("Attempt to split minibuffer window");
3791 else if (window_fixed_size_p (o
, !NILP (horflag
), 0))
3792 error ("Attempt to split fixed-size window");
3794 check_min_window_sizes ();
3798 if (size_int
< window_min_height
)
3799 error ("Window height %d too small (after splitting)", size_int
);
3800 if (size_int
+ window_min_height
> XFASTINT (o
->total_lines
))
3801 error ("Window height %d too small (after splitting)",
3802 XFASTINT (o
->total_lines
) - size_int
);
3803 if (NILP (o
->parent
)
3804 || NILP (XWINDOW (o
->parent
)->vchild
))
3806 make_dummy_parent (window
);
3808 XWINDOW (new)->vchild
= window
;
3813 if (size_int
< window_min_width
)
3814 error ("Window width %d too small (after splitting)", size_int
);
3816 if (size_int
+ window_min_width
> XFASTINT (o
->total_cols
))
3817 error ("Window width %d too small (after splitting)",
3818 XFASTINT (o
->total_cols
) - size_int
);
3819 if (NILP (o
->parent
)
3820 || NILP (XWINDOW (o
->parent
)->hchild
))
3822 make_dummy_parent (window
);
3824 XWINDOW (new)->hchild
= window
;
3828 /* Now we know that window's parent is a vertical combination
3829 if we are dividing vertically, or a horizontal combination
3830 if we are making side-by-side windows */
3832 windows_or_buffers_changed
++;
3833 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
3834 new = make_window ();
3837 p
->frame
= o
->frame
;
3839 if (!NILP (p
->next
))
3840 XWINDOW (p
->next
)->prev
= new;
3843 p
->parent
= o
->parent
;
3845 p
->window_end_valid
= Qnil
;
3846 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
3848 /* Duplicate special geometry settings. */
3850 p
->left_margin_cols
= o
->left_margin_cols
;
3851 p
->right_margin_cols
= o
->right_margin_cols
;
3852 p
->left_fringe_width
= o
->left_fringe_width
;
3853 p
->right_fringe_width
= o
->right_fringe_width
;
3854 p
->fringes_outside_margins
= o
->fringes_outside_margins
;
3855 p
->scroll_bar_width
= o
->scroll_bar_width
;
3856 p
->vertical_scroll_bar_type
= o
->vertical_scroll_bar_type
;
3858 /* Apportion the available frame space among the two new windows */
3860 if (!NILP (horflag
))
3862 p
->total_lines
= o
->total_lines
;
3863 p
->top_line
= o
->top_line
;
3864 XSETFASTINT (p
->total_cols
, XFASTINT (o
->total_cols
) - size_int
);
3865 XSETFASTINT (o
->total_cols
, size_int
);
3866 XSETFASTINT (p
->left_col
, XFASTINT (o
->left_col
) + size_int
);
3867 adjust_window_margins (p
);
3868 adjust_window_margins (o
);
3872 p
->left_col
= o
->left_col
;
3873 p
->total_cols
= o
->total_cols
;
3874 XSETFASTINT (p
->total_lines
, XFASTINT (o
->total_lines
) - size_int
);
3875 XSETFASTINT (o
->total_lines
, size_int
);
3876 XSETFASTINT (p
->top_line
, XFASTINT (o
->top_line
) + size_int
);
3879 /* Adjust glyph matrices. */
3882 Fset_window_buffer (new, o
->buffer
, Qt
);
3886 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
3887 doc
: /* Make current window ARG lines bigger.
3888 From program, optional second arg non-nil means grow sideways ARG columns.
3889 Interactively, if an argument is not given, make the window one line bigger.
3890 If HORIZONTAL is non-nil, enlarge horizontally instead of vertically.
3891 This function can delete windows, even the second window, if they get
3894 Lisp_Object arg
, horizontal
;
3897 enlarge_window (selected_window
, XINT (arg
), !NILP (horizontal
));
3899 if (! NILP (Vwindow_configuration_change_hook
))
3900 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3905 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
3906 doc
: /* Make current window ARG lines smaller.
3907 From program, optional second arg non-nil means shrink sideways arg columns.
3908 Interactively, if an argument is not given, make the window one line smaller. Only
3909 siblings to the right or below are changed. */)
3911 Lisp_Object arg
, side
;
3914 enlarge_window (selected_window
, -XINT (arg
), !NILP (side
));
3916 if (! NILP (Vwindow_configuration_change_hook
))
3917 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3923 window_height (window
)
3926 register struct window
*p
= XWINDOW (window
);
3927 return WINDOW_TOTAL_LINES (p
);
3931 window_width (window
)
3934 register struct window
*p
= XWINDOW (window
);
3935 return WINDOW_TOTAL_COLS (p
);
3940 *(horiz_flag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line))
3942 #define CURSIZE(w) \
3943 *(horiz_flag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines))
3946 /* Enlarge WINDOW by DELTA.
3947 HORIZ_FLAG nonzero means enlarge it horizontally;
3948 zero means do it vertically.
3950 Siblings of the selected window are resized to fulfill the size
3951 request. If they become too small in the process, they will be
3955 enlarge_window (window
, delta
, horiz_flag
)
3957 int delta
, horiz_flag
;
3959 Lisp_Object parent
, next
, prev
;
3963 int (*sizefun
) P_ ((Lisp_Object
))
3964 = horiz_flag
? window_width
: window_height
;
3965 void (*setsizefun
) P_ ((Lisp_Object
, int, int))
3966 = (horiz_flag
? set_window_width
: set_window_height
);
3968 /* Check values of window_min_width and window_min_height for
3970 check_min_window_sizes ();
3972 /* Give up if this window cannot be resized. */
3973 if (window_fixed_size_p (XWINDOW (window
), horiz_flag
, 1))
3974 error ("Window is not resizable");
3976 /* Find the parent of the selected window. */
3979 p
= XWINDOW (window
);
3985 error ("No other window to side of this one");
3990 ? !NILP (XWINDOW (parent
)->hchild
)
3991 : !NILP (XWINDOW (parent
)->vchild
))
3997 sizep
= &CURSIZE (window
);
4000 register int maxdelta
;
4002 /* Compute the maximum size increment this window can have. */
4004 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - XINT (*sizep
)
4005 /* This is a main window followed by a minibuffer. */
4006 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
4007 - window_min_size (XWINDOW (p
->next
),
4009 /* This is a minibuffer following a main window. */
4010 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
4011 - window_min_size (XWINDOW (p
->prev
),
4013 /* This is a frame with only one window, a minibuffer-only
4014 or a minibufferless frame. */
4017 if (delta
> maxdelta
)
4018 /* This case traps trying to make the minibuffer
4019 the full frame, or make the only window aside from the
4020 minibuffer the full frame. */
4024 if (XINT (*sizep
) + delta
< window_min_size (XWINDOW (window
), horiz_flag
, 0, 0))
4026 delete_window (window
);
4033 /* Find the total we can get from other siblings without deleting them. */
4035 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
4036 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
4038 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
4039 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
4042 /* If we can get it all from them without deleting them, do so. */
4043 if (delta
<= maximum
)
4045 Lisp_Object first_unaffected
;
4046 Lisp_Object first_affected
;
4051 first_affected
= window
;
4052 /* Look at one sibling at a time,
4053 moving away from this window in both directions alternately,
4054 and take as much as we can get without deleting that sibling. */
4056 && (!NILP (next
) || !NILP (prev
)))
4060 int this_one
= ((*sizefun
) (next
)
4061 - window_min_size (XWINDOW (next
),
4062 horiz_flag
, 0, &fixed_p
));
4065 if (this_one
> delta
)
4068 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
4069 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4074 next
= XWINDOW (next
)->next
;
4082 int this_one
= ((*sizefun
) (prev
)
4083 - window_min_size (XWINDOW (prev
),
4084 horiz_flag
, 0, &fixed_p
));
4087 if (this_one
> delta
)
4090 first_affected
= prev
;
4092 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
4093 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4098 prev
= XWINDOW (prev
)->prev
;
4102 xassert (delta
== 0);
4104 /* Now recalculate the edge positions of all the windows affected,
4105 based on the new sizes. */
4106 first_unaffected
= next
;
4107 prev
= first_affected
;
4108 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
4109 prev
= next
, next
= XWINDOW (next
)->next
)
4111 XSETINT (CURBEG (next
), XINT (CURBEG (prev
)) + (*sizefun
) (prev
));
4112 /* This does not change size of NEXT,
4113 but it propagates the new top edge to its children */
4114 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
4119 register int delta1
;
4120 register int opht
= (*sizefun
) (parent
);
4122 if (opht
<= XINT (*sizep
) + delta
)
4124 /* If trying to grow this window to or beyond size of the parent,
4125 just delete all the sibling windows. */
4126 Lisp_Object start
, tem
, next
;
4128 start
= XWINDOW (parent
)->vchild
;
4130 start
= XWINDOW (parent
)->hchild
;
4132 /* Delete any siblings that come after WINDOW. */
4133 tem
= XWINDOW (window
)->next
;
4134 while (! NILP (tem
))
4136 next
= XWINDOW (tem
)->next
;
4137 delete_window (tem
);
4141 /* Delete any siblings that come after WINDOW.
4142 Note that if START is not WINDOW, then WINDOW still
4143 Fhas siblings, so WINDOW has not yet replaced its parent. */
4145 while (! EQ (tem
, window
))
4147 next
= XWINDOW (tem
)->next
;
4148 delete_window (tem
);
4154 /* Otherwise, make delta1 just right so that if we add
4155 delta1 lines to this window and to the parent, and then
4156 shrink the parent back to its original size, the new
4157 proportional size of this window will increase by delta.
4159 The function size_window will compute the new height h'
4160 of the window from delta1 as:
4163 x = delta1 - delta1/n * n for the 1st resizable child
4166 where n is the number of children that can be resized.
4167 We can ignore x by choosing a delta1 that is a multiple of
4168 n. We want the height of this window to come out as
4178 The number of children n equals the number of resizable
4179 children of this window + 1 because we know window itself
4180 is resizable (otherwise we would have signalled an error). */
4182 struct window
*w
= XWINDOW (window
);
4186 for (s
= w
->next
; !NILP (s
); s
= XWINDOW (s
)->next
)
4187 if (!window_fixed_size_p (XWINDOW (s
), horiz_flag
, 0))
4189 for (s
= w
->prev
; !NILP (s
); s
= XWINDOW (s
)->prev
)
4190 if (!window_fixed_size_p (XWINDOW (s
), horiz_flag
, 0))
4195 /* Add delta1 lines or columns to this window, and to the parent,
4196 keeping things consistent while not affecting siblings. */
4197 XSETINT (CURSIZE (parent
), opht
+ delta1
);
4198 (*setsizefun
) (window
, XINT (*sizep
) + delta1
, 0);
4200 /* Squeeze out delta1 lines or columns from our parent,
4201 shriking this window and siblings proportionately.
4202 This brings parent back to correct size.
4203 Delta1 was calculated so this makes this window the desired size,
4204 taking it all out of the siblings. */
4205 (*setsizefun
) (parent
, opht
, 0);
4210 XSETFASTINT (p
->last_modified
, 0);
4211 XSETFASTINT (p
->last_overlay_modified
, 0);
4213 /* Adjust glyph matrices. */
4214 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4218 /* Adjust the size of WINDOW by DELTA, moving only its trailing edge.
4219 HORIZ_FLAG nonzero means adjust the width, moving the right edge.
4220 zero means adjust the height, moving the bottom edge.
4222 Following siblings of the selected window are resized to fulfill
4223 the size request. If they become too small in the process, they
4224 are not deleted; instead, we signal an error. */
4227 adjust_window_trailing_edge (window
, delta
, horiz_flag
)
4229 int delta
, horiz_flag
;
4231 Lisp_Object parent
, child
;
4233 Lisp_Object old_config
= Fcurrent_window_configuration (Qnil
);
4234 int delcount
= window_deletion_count
;
4236 /* Check values of window_min_width and window_min_height for
4238 check_min_window_sizes ();
4241 window
= Fselected_window ();
4243 CHECK_WINDOW (window
);
4245 /* Give up if this window cannot be resized. */
4246 if (window_fixed_size_p (XWINDOW (window
), horiz_flag
, 1))
4247 error ("Window is not resizable");
4251 p
= XWINDOW (window
);
4254 /* Make sure there is a following window. */
4257 : NILP (XWINDOW (window
)->next
)))
4259 Fset_window_configuration (old_config
);
4260 error ("No other window following this one");
4263 /* Don't make this window too small. */
4264 if (XINT (CURSIZE (window
)) + delta
4265 < (horiz_flag
? window_min_width
: window_min_height
))
4267 Fset_window_configuration (old_config
);
4268 error ("Cannot adjust window size as specified");
4271 /* Clear out some redisplay caches. */
4272 XSETFASTINT (p
->last_modified
, 0);
4273 XSETFASTINT (p
->last_overlay_modified
, 0);
4275 /* Adjust this window's edge. */
4276 XSETINT (CURSIZE (window
),
4277 XINT (CURSIZE (window
)) + delta
);
4279 /* If this window has following siblings in the desired dimension,
4281 (If we reach the top of the tree and can never do this,
4282 we will fail and report an error, above.) */
4284 ? !NILP (XWINDOW (parent
)->hchild
)
4285 : !NILP (XWINDOW (parent
)->vchild
))
4287 if (!NILP (XWINDOW (window
)->next
))
4289 /* This may happen for the minibuffer. In that case
4290 the window_deletion_count check below does not work. */
4291 if (XINT (CURSIZE (p
->next
)) - delta
<= 0)
4293 Fset_window_configuration (old_config
);
4294 error ("Cannot adjust window size as specified");
4297 XSETINT (CURBEG (p
->next
),
4298 XINT (CURBEG (p
->next
)) + delta
);
4299 size_window (p
->next
, XINT (CURSIZE (p
->next
)) - delta
,
4305 /* Here we have a chain of parallel siblings, in the other dimension.
4306 Change the size of the other siblings. */
4307 for (child
= (horiz_flag
4308 ? XWINDOW (parent
)->vchild
4309 : XWINDOW (parent
)->hchild
);
4311 child
= XWINDOW (child
)->next
)
4312 if (! EQ (child
, window
))
4313 size_window (child
, XINT (CURSIZE (child
)) + delta
,
4319 /* If we made a window so small it got deleted,
4320 we failed. Report failure. */
4321 if (delcount
!= window_deletion_count
)
4323 Fset_window_configuration (old_config
);
4324 error ("Cannot adjust window size as specified");
4327 /* Adjust glyph matrices. */
4328 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4334 DEFUN ("adjust-window-trailing-edge", Fadjust_window_trailing_edge
,
4335 Sadjust_window_trailing_edge
, 3, 3, 0,
4336 doc
: /* Adjust the bottom or right edge of WINDOW by DELTA.
4337 If HORIZONTAL is non-nil, that means adjust the width, moving the right edge.
4338 Otherwise, adjust the height, moving the bottom edge.
4340 Following siblings of the selected window are resized to fulfill
4341 the size request. If they become too small in the process, they
4342 are not deleted; instead, we signal an error. */)
4343 (window
, delta
, horizontal
)
4344 Lisp_Object window
, delta
, horizontal
;
4346 CHECK_NUMBER (delta
);
4347 adjust_window_trailing_edge (window
, XINT (delta
), !NILP (horizontal
));
4349 if (! NILP (Vwindow_configuration_change_hook
))
4350 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
4357 /***********************************************************************
4358 Resizing Mini-Windows
4359 ***********************************************************************/
4361 static void shrink_window_lowest_first
P_ ((struct window
*, int));
4363 enum save_restore_action
4370 static int save_restore_orig_size
P_ ((struct window
*,
4371 enum save_restore_action
));
4373 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
4374 from lowest windows first. */
4377 shrink_window_lowest_first (w
, height
)
4385 xassert (!MINI_WINDOW_P (w
));
4387 /* Set redisplay hints. */
4388 XSETFASTINT (w
->last_modified
, 0);
4389 XSETFASTINT (w
->last_overlay_modified
, 0);
4390 windows_or_buffers_changed
++;
4391 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
4393 old_height
= XFASTINT (w
->total_lines
);
4394 XSETFASTINT (w
->total_lines
, height
);
4396 if (!NILP (w
->hchild
))
4398 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
4400 c
= XWINDOW (child
);
4401 c
->top_line
= w
->top_line
;
4402 shrink_window_lowest_first (c
, height
);
4405 else if (!NILP (w
->vchild
))
4407 Lisp_Object last_child
;
4408 int delta
= old_height
- height
;
4413 /* Find the last child. We are taking space from lowest windows
4414 first, so we iterate over children from the last child
4416 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
4419 /* Assign new heights. We leave only MIN_SAFE_WINDOW_HEIGHT. */
4420 for (child
= last_child
; delta
&& !NILP (child
); child
= c
->prev
)
4424 c
= XWINDOW (child
);
4425 this_one
= XFASTINT (c
->total_lines
) - MIN_SAFE_WINDOW_HEIGHT
;
4427 if (this_one
> delta
)
4430 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
) - this_one
);
4434 /* Compute new positions. */
4435 last_top
= XINT (w
->top_line
);
4436 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
4438 c
= XWINDOW (child
);
4439 c
->top_line
= make_number (last_top
);
4440 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
));
4441 last_top
+= XFASTINT (c
->total_lines
);
4447 /* Save, restore, or check positions and sizes in the window tree
4448 rooted at W. ACTION says what to do.
4450 If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and
4451 orig_total_lines members are valid for all windows in the window
4452 tree. Value is non-zero if they are valid.
4454 If ACTION is SAVE_ORIG_SIZES, save members top and height in
4455 orig_top_line and orig_total_lines for all windows in the tree.
4457 If ACTION is RESTORE_ORIG_SIZES, restore top and height from values
4458 stored in orig_top_line and orig_total_lines for all windows. */
4461 save_restore_orig_size (w
, action
)
4463 enum save_restore_action action
;
4469 if (!NILP (w
->hchild
))
4471 if (!save_restore_orig_size (XWINDOW (w
->hchild
), action
))
4474 else if (!NILP (w
->vchild
))
4476 if (!save_restore_orig_size (XWINDOW (w
->vchild
), action
))
4482 case CHECK_ORIG_SIZES
:
4483 if (!INTEGERP (w
->orig_top_line
) || !INTEGERP (w
->orig_total_lines
))
4487 case SAVE_ORIG_SIZES
:
4488 w
->orig_top_line
= w
->top_line
;
4489 w
->orig_total_lines
= w
->total_lines
;
4490 XSETFASTINT (w
->last_modified
, 0);
4491 XSETFASTINT (w
->last_overlay_modified
, 0);
4494 case RESTORE_ORIG_SIZES
:
4495 xassert (INTEGERP (w
->orig_top_line
) && INTEGERP (w
->orig_total_lines
));
4496 w
->top_line
= w
->orig_top_line
;
4497 w
->total_lines
= w
->orig_total_lines
;
4498 w
->orig_total_lines
= w
->orig_top_line
= Qnil
;
4499 XSETFASTINT (w
->last_modified
, 0);
4500 XSETFASTINT (w
->last_overlay_modified
, 0);
4507 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
4514 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
4515 without deleting other windows. */
4518 grow_mini_window (w
, delta
)
4522 struct frame
*f
= XFRAME (w
->frame
);
4523 struct window
*root
;
4525 xassert (MINI_WINDOW_P (w
));
4526 xassert (delta
>= 0);
4528 /* Check values of window_min_width and window_min_height for
4530 check_min_window_sizes ();
4532 /* Compute how much we can enlarge the mini-window without deleting
4534 root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4537 int min_height
= window_min_size (root
, 0, 0, 0);
4538 if (XFASTINT (root
->total_lines
) - delta
< min_height
)
4539 /* Note that the root window may already be smaller than
4541 delta
= max (0, XFASTINT (root
->total_lines
) - min_height
);
4546 /* Save original window sizes and positions, if not already done. */
4547 if (!save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4548 save_restore_orig_size (root
, SAVE_ORIG_SIZES
);
4550 /* Shrink other windows. */
4551 shrink_window_lowest_first (root
, XFASTINT (root
->total_lines
) - delta
);
4553 /* Grow the mini-window. */
4554 w
->top_line
= make_number (XFASTINT (root
->top_line
) + XFASTINT (root
->total_lines
));
4555 w
->total_lines
= make_number (XFASTINT (w
->total_lines
) + delta
);
4556 XSETFASTINT (w
->last_modified
, 0);
4557 XSETFASTINT (w
->last_overlay_modified
, 0);
4564 /* Shrink mini-window W. If there is recorded info about window sizes
4565 before a call to grow_mini_window, restore recorded window sizes.
4566 Otherwise, if the mini-window is higher than 1 line, resize it to 1
4570 shrink_mini_window (w
)
4573 struct frame
*f
= XFRAME (w
->frame
);
4574 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4576 if (save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4578 save_restore_orig_size (root
, RESTORE_ORIG_SIZES
);
4580 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4581 windows_or_buffers_changed
= 1;
4583 else if (XFASTINT (w
->total_lines
) > 1)
4585 /* Distribute the additional lines of the mini-window
4586 among the other windows. */
4588 XSETWINDOW (window
, w
);
4589 enlarge_window (window
, 1 - XFASTINT (w
->total_lines
), 0);
4595 /* Mark window cursors off for all windows in the window tree rooted
4596 at W by setting their phys_cursor_on_p flag to zero. Called from
4597 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4598 the frame are cleared. */
4601 mark_window_cursors_off (w
)
4606 if (!NILP (w
->hchild
))
4607 mark_window_cursors_off (XWINDOW (w
->hchild
));
4608 else if (!NILP (w
->vchild
))
4609 mark_window_cursors_off (XWINDOW (w
->vchild
));
4611 w
->phys_cursor_on_p
= 0;
4613 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4618 /* Return number of lines of text (not counting mode lines) in W. */
4621 window_internal_height (w
)
4624 int ht
= XFASTINT (w
->total_lines
);
4626 if (!MINI_WINDOW_P (w
))
4628 if (!NILP (w
->parent
)
4629 || !NILP (w
->vchild
)
4630 || !NILP (w
->hchild
)
4633 || WINDOW_WANTS_MODELINE_P (w
))
4636 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4644 /* Return the number of columns in W.
4645 Don't count columns occupied by scroll bars or the vertical bar
4646 separating W from the sibling to its right. */
4649 window_box_text_cols (w
)
4652 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4653 int width
= XINT (w
->total_cols
);
4655 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
4656 /* Scroll bars occupy a few columns. */
4657 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
4658 else if (!FRAME_WINDOW_P (f
)
4659 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
4660 /* The column of `|' characters separating side-by-side windows
4661 occupies one column only. */
4664 if (FRAME_WINDOW_P (f
))
4665 /* On window-systems, fringes and display margins cannot be
4666 used for normal text. */
4667 width
-= (WINDOW_FRINGE_COLS (w
)
4668 + WINDOW_LEFT_MARGIN_COLS (w
)
4669 + WINDOW_RIGHT_MARGIN_COLS (w
));
4675 /************************************************************************
4677 ***********************************************************************/
4679 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4680 N screen-fulls, which is defined as the height of the window minus
4681 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4682 instead. Negative values of N mean scroll down. NOERROR non-zero
4683 means don't signal an error if we try to move over BEGV or ZV,
4687 window_scroll (window
, n
, whole
, noerror
)
4695 /* If we must, use the pixel-based version which is much slower than
4696 the line-based one but can handle varying line heights. */
4697 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4698 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4700 window_scroll_line_based (window
, n
, whole
, noerror
);
4706 /* Implementation of window_scroll that works based on pixel line
4707 heights. See the comment of window_scroll for parameter
4711 window_scroll_pixel_based (window
, n
, whole
, noerror
)
4718 struct window
*w
= XWINDOW (window
);
4719 struct text_pos start
;
4721 int this_scroll_margin
;
4723 /* True if we fiddled the window vscroll field without really scrolling. */
4726 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4728 /* If PT is not visible in WINDOW, move back one half of
4729 the screen. Allow PT to be partially visible, otherwise
4730 something like (scroll-down 1) with PT in the line before
4731 the partially visible one would recenter. */
4732 tem
= Fpos_visible_in_window_p (make_number (PT
), window
, Qt
);
4735 /* Move backward half the height of the window. Performance note:
4736 vmotion used here is about 10% faster, but would give wrong
4737 results for variable height lines. */
4738 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4739 it
.current_y
= it
.last_visible_y
;
4740 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4742 /* The function move_iterator_vertically may move over more than
4743 the specified y-distance. If it->w is small, e.g. a
4744 mini-buffer window, we may end up in front of the window's
4745 display area. This is the case when Start displaying at the
4746 start of the line containing PT in this case. */
4747 if (it
.current_y
<= 0)
4749 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4750 move_it_vertically_backward (&it
, 0);
4754 start
= it
.current
.pos
;
4756 else if (auto_window_vscroll_p
)
4758 if (tem
= XCAR (XCDR (XCDR (tem
))), CONSP (tem
))
4761 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4763 dy
= max ((window_box_height (w
)
4764 - next_screen_context_lines
* dy
),
4768 if (n
< 0 && (px
= XINT (XCAR (tem
))) > 0)
4770 px
= max (0, -w
->vscroll
- min (px
, -dy
));
4771 Fset_window_vscroll (window
, make_number (px
), Qt
);
4774 if (n
> 0 && (px
= XINT (XCDR (tem
))) > 0)
4776 px
= max (0, -w
->vscroll
+ min (px
, dy
));
4777 Fset_window_vscroll (window
, make_number (px
), Qt
);
4781 Fset_window_vscroll (window
, make_number (0), Qt
);
4784 /* If scroll_preserve_screen_position is non-nil, we try to set
4785 point in the same window line as it is now, so get that line. */
4786 if (!NILP (Vscroll_preserve_screen_position
))
4788 start_display (&it
, w
, start
);
4789 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4790 preserve_y
= it
.current_y
;
4795 /* Move iterator it from start the specified distance forward or
4796 backward. The result is the new window start. */
4797 start_display (&it
, w
, start
);
4800 int start_pos
= IT_CHARPOS (it
);
4801 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4802 dy
= max ((window_box_height (w
)
4803 - next_screen_context_lines
* dy
),
4806 /* Note that move_it_vertically always moves the iterator to the
4807 start of a line. So, if the last line doesn't have a newline,
4808 we would end up at the start of the line ending at ZV. */
4811 move_it_vertically_backward (&it
, -dy
);
4812 /* Ensure we actually does move, e.g. in case we are currently
4813 looking at an image that is taller that the window height. */
4814 while (start_pos
== IT_CHARPOS (it
)
4815 && start_pos
> BEGV
)
4816 move_it_by_lines (&it
, -1, 1);
4820 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4821 MOVE_TO_POS
| MOVE_TO_Y
);
4822 /* Ensure we actually does move, e.g. in case we are currently
4823 looking at an image that is taller that the window height. */
4824 while (start_pos
== IT_CHARPOS (it
)
4826 move_it_by_lines (&it
, 1, 1);
4830 move_it_by_lines (&it
, n
, 1);
4832 /* We failed if we find ZV is already on the screen (scrolling up,
4833 means there's nothing past the end), or if we can't start any
4834 earlier (scrolling down, means there's nothing past the top). */
4835 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4836 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4838 if (IT_CHARPOS (it
) == ZV
)
4840 if (it
.current_y
< it
.last_visible_y
4841 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4842 >= it
.last_visible_y
))
4844 /* The last line was only partially visible, make it fully
4846 w
->vscroll
= (it
.last_visible_y
4847 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4848 adjust_glyphs (it
.f
);
4853 Fsignal (Qend_of_buffer
, Qnil
);
4857 if (w
->vscroll
!= 0)
4858 /* The first line was only partially visible, make it fully
4864 Fsignal (Qbeginning_of_buffer
, Qnil
);
4867 /* If control gets here, then we vscrolled. */
4869 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
4871 /* Don't try to change the window start below. */
4877 int pos
= IT_CHARPOS (it
);
4880 /* If in the middle of a multi-glyph character move forward to
4881 the next character. */
4882 if (in_display_vector_p (&it
))
4885 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
4888 /* Set the window start, and set up the window for redisplay. */
4889 set_marker_restricted (w
->start
, make_number (pos
),
4891 bytepos
= XMARKER (w
->start
)->bytepos
;
4892 w
->start_at_line_beg
= ((pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n')
4894 w
->update_mode_line
= Qt
;
4895 XSETFASTINT (w
->last_modified
, 0);
4896 XSETFASTINT (w
->last_overlay_modified
, 0);
4897 /* Set force_start so that redisplay_window will run the
4898 window-scroll-functions. */
4899 w
->force_start
= Qt
;
4902 /* The rest of this function uses current_y in a nonstandard way,
4903 not including the height of the header line if any. */
4904 it
.current_y
= it
.vpos
= 0;
4906 /* Move PT out of scroll margins.
4907 This code wants current_y to be zero at the window start position
4908 even if there is a header line. */
4909 this_scroll_margin
= max (0, scroll_margin
);
4910 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->total_lines
) / 4);
4911 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
4915 /* We moved the window start towards ZV, so PT may be now
4916 in the scroll margin at the top. */
4917 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4918 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
4919 && (NILP (Vscroll_preserve_screen_position
)
4920 || EQ (Vscroll_preserve_screen_position
, Qt
)))
4921 /* We found PT at a legitimate height. Leave it alone. */
4923 else if (preserve_y
>= 0)
4925 /* If we have a header line, take account of it.
4926 This is necessary because we set it.current_y to 0, above. */
4927 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4928 preserve_y
-= CURRENT_HEADER_LINE_HEIGHT (w
);
4930 move_it_to (&it
, -1, -1, preserve_y
, -1, MOVE_TO_Y
);
4931 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4935 while (it
.current_y
< this_scroll_margin
)
4937 int prev
= it
.current_y
;
4938 move_it_by_lines (&it
, 1, 1);
4939 if (prev
== it
.current_y
)
4942 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4947 int charpos
, bytepos
;
4950 /* Save our position, for the preserve_y case. */
4951 charpos
= IT_CHARPOS (it
);
4952 bytepos
= IT_BYTEPOS (it
);
4954 /* We moved the window start towards BEGV, so PT may be now
4955 in the scroll margin at the bottom. */
4956 move_it_to (&it
, PT
, -1,
4957 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
4958 - this_scroll_margin
- 1),
4960 MOVE_TO_POS
| MOVE_TO_Y
);
4962 /* Save our position, in case it's correct. */
4963 charpos
= IT_CHARPOS (it
);
4964 bytepos
= IT_BYTEPOS (it
);
4966 /* See if point is on a partially visible line at the end. */
4967 if (it
.what
== IT_EOB
)
4968 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
4971 move_it_by_lines (&it
, 1, 1);
4972 partial_p
= it
.current_y
> it
.last_visible_y
;
4975 if (charpos
== PT
&& !partial_p
4976 && (NILP (Vscroll_preserve_screen_position
)
4977 || EQ (Vscroll_preserve_screen_position
, Qt
)))
4978 /* We found PT before we found the display margin, so PT is ok. */
4980 else if (preserve_y
>= 0)
4982 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4983 start_display (&it
, w
, start
);
4984 #if 0 /* It's wrong to subtract this here
4985 because we called start_display again
4986 and did not alter it.current_y this time. */
4988 /* If we have a header line, take account of it. */
4989 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4990 preserve_y
-= CURRENT_HEADER_LINE_HEIGHT (w
);
4993 move_it_to (&it
, -1, -1, preserve_y
, -1, MOVE_TO_Y
);
4994 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4999 /* The last line was only partially visible, so back up two
5000 lines to make sure we're on a fully visible line. */
5002 move_it_by_lines (&it
, -2, 0);
5003 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5006 /* No, the position we saved is OK, so use it. */
5007 SET_PT_BOTH (charpos
, bytepos
);
5013 /* Implementation of window_scroll that works based on screen lines.
5014 See the comment of window_scroll for parameter descriptions. */
5017 window_scroll_line_based (window
, n
, whole
, noerror
)
5023 register struct window
*w
= XWINDOW (window
);
5024 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
5025 register int pos
, pos_byte
;
5026 register int ht
= window_internal_height (w
);
5027 register Lisp_Object tem
;
5031 struct position posit
;
5034 /* If scrolling screen-fulls, compute the number of lines to
5035 scroll from the window's height. */
5037 n
*= max (1, ht
- next_screen_context_lines
);
5039 startpos
= marker_position (w
->start
);
5041 posit
= *compute_motion (startpos
, 0, 0, 0,
5043 -1, XINT (w
->hscroll
),
5045 original_vpos
= posit
.vpos
;
5047 XSETFASTINT (tem
, PT
);
5048 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
5052 Fvertical_motion (make_number (- (ht
/ 2)), window
);
5057 lose
= n
< 0 && PT
== BEGV
;
5058 Fvertical_motion (make_number (n
), window
);
5062 SET_PT_BOTH (opoint
, opoint_byte
);
5069 Fsignal (Qbeginning_of_buffer
, Qnil
);
5074 int this_scroll_margin
= scroll_margin
;
5076 /* Don't use a scroll margin that is negative or too large. */
5077 if (this_scroll_margin
< 0)
5078 this_scroll_margin
= 0;
5080 if (XINT (w
->total_lines
) < 4 * scroll_margin
)
5081 this_scroll_margin
= XINT (w
->total_lines
) / 4;
5083 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
5084 w
->start_at_line_beg
= bolp
;
5085 w
->update_mode_line
= Qt
;
5086 XSETFASTINT (w
->last_modified
, 0);
5087 XSETFASTINT (w
->last_overlay_modified
, 0);
5088 /* Set force_start so that redisplay_window will run
5089 the window-scroll-functions. */
5090 w
->force_start
= Qt
;
5092 if (!NILP (Vscroll_preserve_screen_position
)
5093 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
5095 SET_PT_BOTH (pos
, pos_byte
);
5096 Fvertical_motion (make_number (original_vpos
), window
);
5098 /* If we scrolled forward, put point enough lines down
5099 that it is outside the scroll margin. */
5104 if (this_scroll_margin
> 0)
5106 SET_PT_BOTH (pos
, pos_byte
);
5107 Fvertical_motion (make_number (this_scroll_margin
), window
);
5113 if (top_margin
<= opoint
)
5114 SET_PT_BOTH (opoint
, opoint_byte
);
5115 else if (!NILP (Vscroll_preserve_screen_position
))
5117 SET_PT_BOTH (pos
, pos_byte
);
5118 Fvertical_motion (make_number (original_vpos
), window
);
5121 SET_PT (top_margin
);
5127 /* If we scrolled backward, put point near the end of the window
5128 but not within the scroll margin. */
5129 SET_PT_BOTH (pos
, pos_byte
);
5130 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
5131 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
5134 bottom_margin
= PT
+ 1;
5136 if (bottom_margin
> opoint
)
5137 SET_PT_BOTH (opoint
, opoint_byte
);
5140 if (!NILP (Vscroll_preserve_screen_position
))
5142 SET_PT_BOTH (pos
, pos_byte
);
5143 Fvertical_motion (make_number (original_vpos
), window
);
5146 Fvertical_motion (make_number (-1), window
);
5155 Fsignal (Qend_of_buffer
, Qnil
);
5160 /* Scroll selected_window up or down. If N is nil, scroll a
5161 screen-full which is defined as the height of the window minus
5162 next_screen_context_lines. If N is the symbol `-', scroll.
5163 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
5164 up. This is the guts of Fscroll_up and Fscroll_down. */
5167 scroll_command (n
, direction
)
5171 int count
= SPECPDL_INDEX ();
5173 xassert (abs (direction
) == 1);
5175 /* If selected window's buffer isn't current, make it current for
5176 the moment. But don't screw up if window_scroll gets an error. */
5177 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
5179 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5180 Fset_buffer (XWINDOW (selected_window
)->buffer
);
5182 /* Make redisplay consider other windows than just selected_window. */
5183 ++windows_or_buffers_changed
;
5187 window_scroll (selected_window
, direction
, 1, 0);
5188 else if (EQ (n
, Qminus
))
5189 window_scroll (selected_window
, -direction
, 1, 0);
5192 n
= Fprefix_numeric_value (n
);
5193 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
5196 unbind_to (count
, Qnil
);
5199 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
5200 doc
: /* Scroll text of current window upward ARG lines.
5201 If ARG is omitted or nil, scroll upward by a near full screen.
5202 A near full screen is `next-screen-context-lines' less than a full screen.
5203 Negative ARG means scroll downward.
5204 If ARG is the atom `-', scroll downward by nearly full screen.
5205 When calling from a program, supply as argument a number, nil, or `-'. */)
5209 scroll_command (arg
, 1);
5213 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
5214 doc
: /* Scroll text of current window down ARG lines.
5215 If ARG is omitted or nil, scroll down by a near full screen.
5216 A near full screen is `next-screen-context-lines' less than a full screen.
5217 Negative ARG means scroll upward.
5218 If ARG is the atom `-', scroll upward by nearly full screen.
5219 When calling from a program, supply as argument a number, nil, or `-'. */)
5223 scroll_command (arg
, -1);
5227 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
5228 doc
: /* Return the other window for \"other window scroll\" commands.
5229 If `other-window-scroll-buffer' is non-nil, a window
5230 showing that buffer is used.
5231 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5232 specifies the window. This takes precedence over
5233 `other-window-scroll-buffer'. */)
5238 if (MINI_WINDOW_P (XWINDOW (selected_window
))
5239 && !NILP (Vminibuf_scroll_window
))
5240 window
= Vminibuf_scroll_window
;
5241 /* If buffer is specified, scroll that buffer. */
5242 else if (!NILP (Vother_window_scroll_buffer
))
5244 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
5246 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
5250 /* Nothing specified; look for a neighboring window on the same
5252 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
5254 if (EQ (window
, selected_window
))
5255 /* That didn't get us anywhere; look for a window on another
5258 window
= Fnext_window (window
, Qnil
, Qt
);
5259 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
5260 && ! EQ (window
, selected_window
));
5263 CHECK_LIVE_WINDOW (window
);
5265 if (EQ (window
, selected_window
))
5266 error ("There is no other window");
5271 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
5272 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5273 A near full screen is `next-screen-context-lines' less than a full screen.
5274 The next window is the one below the current one; or the one at the top
5275 if the current one is at the bottom. Negative ARG means scroll downward.
5276 If ARG is the atom `-', scroll downward by nearly full screen.
5277 When calling from a program, supply as argument a number, nil, or `-'.
5279 If `other-window-scroll-buffer' is non-nil, scroll the window
5280 showing that buffer, popping the buffer up if necessary.
5281 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5282 specifies the window to scroll. This takes precedence over
5283 `other-window-scroll-buffer'. */)
5289 int count
= SPECPDL_INDEX ();
5291 window
= Fother_window_for_scrolling ();
5292 w
= XWINDOW (window
);
5294 /* Don't screw up if window_scroll gets an error. */
5295 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5296 ++windows_or_buffers_changed
;
5298 Fset_buffer (w
->buffer
);
5299 SET_PT (marker_position (w
->pointm
));
5302 window_scroll (window
, 1, 1, 1);
5303 else if (EQ (arg
, Qminus
))
5304 window_scroll (window
, -1, 1, 1);
5310 window_scroll (window
, XINT (arg
), 0, 1);
5313 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5314 unbind_to (count
, Qnil
);
5319 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "P\np",
5320 doc
: /* Scroll selected window display ARG columns left.
5321 Default for ARG is window width minus 2.
5322 Value is the total amount of leftward horizontal scrolling in
5323 effect after the change.
5324 If SET_MINIMUM is non-nil, the new scroll amount becomes the
5325 lower bound for automatic scrolling, i.e. automatic scrolling
5326 will not scroll a window to a column less than the value returned
5327 by this function. This happens in an interactive call. */)
5329 register Lisp_Object arg
, set_minimum
;
5333 struct window
*w
= XWINDOW (selected_window
);
5336 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5338 arg
= Fprefix_numeric_value (arg
);
5340 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
5341 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5343 if (!NILP (set_minimum
))
5344 w
->min_hscroll
= w
->hscroll
;
5349 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "P\np",
5350 doc
: /* Scroll selected window display ARG columns right.
5351 Default for ARG is window width minus 2.
5352 Value is the total amount of leftward horizontal scrolling in
5353 effect after the change.
5354 If SET_MINIMUM is non-nil, the new scroll amount becomes the
5355 lower bound for automatic scrolling, i.e. automatic scrolling
5356 will not scroll a window to a column less than the value returned
5357 by this function. This happens in an interactive call. */)
5359 register Lisp_Object arg
, set_minimum
;
5363 struct window
*w
= XWINDOW (selected_window
);
5366 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5368 arg
= Fprefix_numeric_value (arg
);
5370 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
5371 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5373 if (!NILP (set_minimum
))
5374 w
->min_hscroll
= w
->hscroll
;
5379 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5380 doc
: /* Return the window which was selected when entering the minibuffer.
5381 Returns nil, if current window is not a minibuffer window. */)
5384 if (minibuf_level
> 0
5385 && MINI_WINDOW_P (XWINDOW (selected_window
))
5386 && WINDOW_LIVE_P (minibuf_selected_window
))
5387 return minibuf_selected_window
;
5392 /* Value is the number of lines actually displayed in window W,
5393 as opposed to its height. */
5396 displayed_window_lines (w
)
5400 struct text_pos start
;
5401 int height
= window_box_height (w
);
5402 struct buffer
*old_buffer
;
5405 if (XBUFFER (w
->buffer
) != current_buffer
)
5407 old_buffer
= current_buffer
;
5408 set_buffer_internal (XBUFFER (w
->buffer
));
5413 /* In case W->start is out of the accessible range, do something
5414 reasonable. This happens in Info mode when Info-scroll-down
5415 calls (recenter -1) while W->start is 1. */
5416 if (XMARKER (w
->start
)->charpos
< BEGV
)
5417 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5418 else if (XMARKER (w
->start
)->charpos
> ZV
)
5419 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
5421 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5423 start_display (&it
, w
, start
);
5424 move_it_vertically (&it
, height
);
5425 bottom_y
= line_bottom_y (&it
);
5427 /* rms: On a non-window display,
5428 the value of it.vpos at the bottom of the screen
5429 seems to be 1 larger than window_box_height (w).
5430 This kludge fixes a bug whereby (move-to-window-line -1)
5431 when ZV is on the last screen line
5432 moves to the previous screen line instead of the last one. */
5433 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5436 /* Add in empty lines at the bottom of the window. */
5437 if (bottom_y
< height
)
5439 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5440 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5444 set_buffer_internal (old_buffer
);
5450 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5451 doc
: /* Center point in window and redisplay frame.
5452 With prefix argument ARG, recenter putting point on screen line ARG
5453 relative to the current window. If ARG is negative, it counts up from the
5454 bottom of the window. (ARG should be less than the height of the window.)
5456 If ARG is omitted or nil, erase the entire frame and then
5457 redraw with point in the center of the current window.
5458 Just C-u as prefix means put point in the center of the window
5459 and redisplay normally--don't erase and redraw the frame. */)
5461 register Lisp_Object arg
;
5463 struct window
*w
= XWINDOW (selected_window
);
5464 struct buffer
*buf
= XBUFFER (w
->buffer
);
5465 struct buffer
*obuf
= current_buffer
;
5467 int charpos
, bytepos
;
5469 int this_scroll_margin
;
5471 /* If redisplay is suppressed due to an error, try again. */
5472 obuf
->display_error_modiff
= 0;
5478 /* Invalidate pixel data calculated for all compositions. */
5479 for (i
= 0; i
< n_compositions
; i
++)
5480 composition_table
[i
]->font
= NULL
;
5482 Fredraw_frame (w
->frame
);
5483 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
5486 else if (CONSP (arg
)) /* Just C-u. */
5490 arg
= Fprefix_numeric_value (arg
);
5495 set_buffer_internal (buf
);
5497 /* Do this after making BUF current
5498 in case scroll_margin is buffer-local. */
5499 this_scroll_margin
= max (0, scroll_margin
);
5500 this_scroll_margin
= min (this_scroll_margin
,
5501 XFASTINT (w
->total_lines
) / 4);
5503 /* Handle centering on a graphical frame specially. Such frames can
5504 have variable-height lines and centering point on the basis of
5505 line counts would lead to strange effects. */
5506 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5513 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5514 start_display (&it
, w
, pt
);
5515 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5516 charpos
= IT_CHARPOS (it
);
5517 bytepos
= IT_BYTEPOS (it
);
5524 int extra_line_spacing
;
5525 int h
= window_box_height (w
);
5527 iarg
= - max (-iarg
, this_scroll_margin
);
5529 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5530 start_display (&it
, w
, pt
);
5532 /* Be sure we have the exact height of the full line containing PT. */
5533 move_it_by_lines (&it
, 0, 1);
5535 /* The amount of pixels we have to move back is the window
5536 height minus what's displayed in the line containing PT,
5537 and the lines below. */
5540 move_it_by_lines (&it
, nlines
, 1);
5542 if (it
.vpos
== nlines
)
5546 /* Last line has no newline */
5547 h
-= line_bottom_y (&it
);
5551 /* Don't reserve space for extra line spacing of last line. */
5552 extra_line_spacing
= it
.max_extra_line_spacing
;
5554 /* If we can't move down NLINES lines because we hit
5555 the end of the buffer, count in some empty lines. */
5556 if (it
.vpos
< nlines
)
5559 extra_line_spacing
= it
.extra_line_spacing
;
5560 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5565 /* Now find the new top line (starting position) of the window. */
5566 start_display (&it
, w
, pt
);
5568 move_it_vertically_backward (&it
, h
);
5570 /* If extra line spacing is present, we may move too far
5571 back. This causes the last line to be only partially
5572 visible (which triggers redisplay to recenter that line
5573 in the middle), so move forward.
5574 But ignore extra line spacing on last line, as it is not
5575 considered to be part of the visible height of the line.
5577 h
+= extra_line_spacing
;
5578 while (-it
.current_y
> h
)
5579 move_it_by_lines (&it
, 1, 1);
5581 charpos
= IT_CHARPOS (it
);
5582 bytepos
= IT_BYTEPOS (it
);
5586 struct position pos
;
5588 iarg
= max (iarg
, this_scroll_margin
);
5590 pos
= *vmotion (PT
, -iarg
, w
);
5591 charpos
= pos
.bufpos
;
5592 bytepos
= pos
.bytepos
;
5597 struct position pos
;
5598 int ht
= window_internal_height (w
);
5605 /* Don't let it get into the margin at either top or bottom. */
5606 iarg
= max (iarg
, this_scroll_margin
);
5607 iarg
= min (iarg
, ht
- this_scroll_margin
- 1);
5609 pos
= *vmotion (PT
, - iarg
, w
);
5610 charpos
= pos
.bufpos
;
5611 bytepos
= pos
.bytepos
;
5614 /* Set the new window start. */
5615 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
5616 w
->window_end_valid
= Qnil
;
5618 w
->optional_new_start
= Qt
;
5620 if (bytepos
== BEGV_BYTE
|| FETCH_BYTE (bytepos
- 1) == '\n')
5621 w
->start_at_line_beg
= Qt
;
5623 w
->start_at_line_beg
= Qnil
;
5625 set_buffer_internal (obuf
);
5630 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5632 doc
: /* Return the height in lines of the text display area of WINDOW.
5633 This doesn't include the mode-line (or header-line if any) or any
5634 partial-height lines in the text display area. */)
5638 struct window
*w
= decode_window (window
);
5639 int pixel_height
= window_box_height (w
);
5640 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5641 return make_number (line_height
);
5646 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5648 doc
: /* Position point relative to window.
5649 With no argument, position point at center of window.
5650 An argument specifies vertical position within the window;
5651 zero means top of window, negative means relative to bottom of window. */)
5655 struct window
*w
= XWINDOW (selected_window
);
5659 int this_scroll_margin
;
5662 window
= selected_window
;
5663 start
= marker_position (w
->start
);
5664 if (start
< BEGV
|| start
> ZV
)
5666 int height
= window_internal_height (w
);
5667 Fvertical_motion (make_number (- (height
/ 2)), window
);
5668 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
5669 w
->start_at_line_beg
= Fbolp ();
5670 w
->force_start
= Qt
;
5673 Fgoto_char (w
->start
);
5675 lines
= displayed_window_lines (w
);
5678 this_scroll_margin
= max (0, scroll_margin
);
5679 this_scroll_margin
= min (this_scroll_margin
, lines
/ 4);
5683 XSETFASTINT (arg
, lines
/ 2);
5686 int iarg
= XINT (Fprefix_numeric_value (arg
));
5689 iarg
= iarg
+ lines
;
5691 #if 0 /* This code would prevent move-to-window-line from moving point
5692 to a place inside the scroll margins (which would cause the
5693 next redisplay to scroll). I wrote this code, but then concluded
5694 it is probably better not to install it. However, it is here
5695 inside #if 0 so as not to lose it. -- rms. */
5697 /* Don't let it get into the margin at either top or bottom. */
5698 iarg
= max (iarg
, this_scroll_margin
);
5699 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
5702 arg
= make_number (iarg
);
5705 /* Skip past a partially visible first line. */
5707 XSETINT (arg
, XINT (arg
) + 1);
5709 return Fvertical_motion (arg
, window
);
5714 /***********************************************************************
5715 Window Configuration
5716 ***********************************************************************/
5718 struct save_window_data
5720 EMACS_INT size_from_Lisp_Vector_struct
;
5721 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5722 Lisp_Object frame_cols
, frame_lines
, frame_menu_bar_lines
;
5723 Lisp_Object frame_tool_bar_lines
;
5724 Lisp_Object selected_frame
;
5725 Lisp_Object current_window
;
5726 Lisp_Object current_buffer
;
5727 Lisp_Object minibuf_scroll_window
;
5728 Lisp_Object minibuf_selected_window
;
5729 Lisp_Object root_window
;
5730 Lisp_Object focus_frame
;
5731 /* Record the values of window-min-width and window-min-height
5732 so that window sizes remain consistent with them. */
5733 Lisp_Object min_width
, min_height
;
5734 /* A vector, each of whose elements is a struct saved_window
5736 Lisp_Object saved_windows
;
5739 /* This is saved as a Lisp_Vector */
5742 /* these first two must agree with struct Lisp_Vector in lisp.h */
5743 EMACS_INT size_from_Lisp_Vector_struct
;
5744 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5747 Lisp_Object buffer
, start
, pointm
, mark
;
5748 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5749 Lisp_Object hscroll
, min_hscroll
;
5750 Lisp_Object parent
, prev
;
5751 Lisp_Object start_at_line_beg
;
5752 Lisp_Object display_table
;
5753 Lisp_Object orig_top_line
, orig_total_lines
;
5754 Lisp_Object left_margin_cols
, right_margin_cols
;
5755 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
5756 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
;
5759 #define SAVED_WINDOW_N(swv,n) \
5760 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5762 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
5763 doc
: /* Return t if OBJECT is a window-configuration object. */)
5767 if (WINDOW_CONFIGURATIONP (object
))
5772 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
5773 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5777 register struct save_window_data
*data
;
5778 struct Lisp_Vector
*saved_windows
;
5780 if (! WINDOW_CONFIGURATIONP (config
))
5781 wrong_type_argument (Qwindow_configuration_p
, config
);
5783 data
= (struct save_window_data
*) XVECTOR (config
);
5784 saved_windows
= XVECTOR (data
->saved_windows
);
5785 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5788 DEFUN ("set-window-configuration", Fset_window_configuration
,
5789 Sset_window_configuration
, 1, 1, 0,
5790 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5791 CONFIGURATION must be a value previously returned
5792 by `current-window-configuration' (which see).
5793 If CONFIGURATION was made from a frame that is now deleted,
5794 only frame-independent values can be restored. In this case,
5795 the return value is nil. Otherwise the value is t. */)
5797 Lisp_Object configuration
;
5799 register struct save_window_data
*data
;
5800 struct Lisp_Vector
*saved_windows
;
5801 Lisp_Object new_current_buffer
;
5806 while (!WINDOW_CONFIGURATIONP (configuration
))
5807 wrong_type_argument (Qwindow_configuration_p
, configuration
);
5809 data
= (struct save_window_data
*) XVECTOR (configuration
);
5810 saved_windows
= XVECTOR (data
->saved_windows
);
5812 new_current_buffer
= data
->current_buffer
;
5813 if (NILP (XBUFFER (new_current_buffer
)->name
))
5814 new_current_buffer
= Qnil
;
5817 if (XBUFFER (new_current_buffer
) == current_buffer
)
5818 /* The code further down "preserves point" by saving here PT in
5819 old_point and then setting it later back into PT. When the
5820 current-selected-window and the final-selected-window both show
5821 the current buffer, this suffers from the problem that the
5822 current PT is the window-point of the current-selected-window,
5823 while the final PT is the point of the final-selected-window, so
5824 this copy from one PT to the other would end up moving the
5825 window-point of the final-selected-window to the window-point of
5826 the current-selected-window. So we have to be careful which
5827 point of the current-buffer we copy into old_point. */
5828 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
5829 && WINDOWP (selected_window
)
5830 && EQ (XWINDOW (selected_window
)->buffer
, new_current_buffer
)
5831 && !EQ (selected_window
, data
->current_window
))
5832 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
5836 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
5837 point in new_current_buffer as of the last time this buffer was
5838 used. This can be non-deterministic since it can be changed by
5839 things like jit-lock by mere temporary selection of some random
5840 window that happens to show this buffer.
5841 So if possible we want this arbitrary choice of "which point" to
5842 be the one from the to-be-selected-window so as to prevent this
5843 window's cursor from being copied from another window. */
5844 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
5845 /* If current_window = selected_window, its point is in BUF_PT. */
5846 && !EQ (selected_window
, data
->current_window
))
5847 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
5849 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
5852 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5855 /* If f is a dead frame, don't bother rebuilding its window tree.
5856 However, there is other stuff we should still try to do below. */
5857 if (FRAME_LIVE_P (f
))
5859 register struct window
*w
;
5860 register struct saved_window
*p
;
5861 struct window
*root_window
;
5862 struct window
**leaf_windows
;
5866 /* If the frame has been resized since this window configuration was
5867 made, we change the frame to the size specified in the
5868 configuration, restore the configuration, and then resize it
5869 back. We keep track of the prevailing height in these variables. */
5870 int previous_frame_lines
= FRAME_LINES (f
);
5871 int previous_frame_cols
= FRAME_COLS (f
);
5872 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
5873 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
5875 /* The mouse highlighting code could get screwed up
5876 if it runs during this. */
5879 if (XFASTINT (data
->frame_lines
) != previous_frame_lines
5880 || XFASTINT (data
->frame_cols
) != previous_frame_cols
)
5881 change_frame_size (f
, XFASTINT (data
->frame_lines
),
5882 XFASTINT (data
->frame_cols
), 0, 0, 0);
5883 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5884 if (XFASTINT (data
->frame_menu_bar_lines
)
5885 != previous_frame_menu_bar_lines
)
5886 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, make_number (0));
5887 #ifdef HAVE_WINDOW_SYSTEM
5888 if (XFASTINT (data
->frame_tool_bar_lines
)
5889 != previous_frame_tool_bar_lines
)
5890 x_set_tool_bar_lines (f
, data
->frame_tool_bar_lines
, make_number (0));
5894 /* "Swap out" point from the selected window's buffer
5895 into the window itself. (Normally the pointm of the selected
5896 window holds garbage.) We do this now, before
5897 restoring the window contents, and prevent it from
5898 being done later on when we select a new window. */
5899 if (! NILP (XWINDOW (selected_window
)->buffer
))
5901 w
= XWINDOW (selected_window
);
5902 set_marker_both (w
->pointm
,
5904 BUF_PT (XBUFFER (w
->buffer
)),
5905 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5908 windows_or_buffers_changed
++;
5909 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
5911 /* Problem: Freeing all matrices and later allocating them again
5912 is a serious redisplay flickering problem. What we would
5913 really like to do is to free only those matrices not reused
5915 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5917 = (struct window
**) alloca (count_windows (root_window
)
5918 * sizeof (struct window
*));
5919 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
5921 /* Temporarily avoid any problems with windows that are smaller
5922 than they are supposed to be. */
5923 window_min_height
= 1;
5924 window_min_width
= 1;
5927 Mark all windows now on frame as "deleted".
5928 Restoring the new configuration "undeletes" any that are in it.
5930 Save their current buffers in their height fields, since we may
5931 need it later, if a buffer saved in the configuration is now
5933 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5935 for (k
= 0; k
< saved_windows
->size
; k
++)
5937 p
= SAVED_WINDOW_N (saved_windows
, k
);
5938 w
= XWINDOW (p
->window
);
5941 if (!NILP (p
->parent
))
5942 w
->parent
= SAVED_WINDOW_N (saved_windows
,
5943 XFASTINT (p
->parent
))->window
;
5947 if (!NILP (p
->prev
))
5949 w
->prev
= SAVED_WINDOW_N (saved_windows
,
5950 XFASTINT (p
->prev
))->window
;
5951 XWINDOW (w
->prev
)->next
= p
->window
;
5956 if (!NILP (w
->parent
))
5958 if (EQ (p
->total_cols
, XWINDOW (w
->parent
)->total_cols
))
5960 XWINDOW (w
->parent
)->vchild
= p
->window
;
5961 XWINDOW (w
->parent
)->hchild
= Qnil
;
5965 XWINDOW (w
->parent
)->hchild
= p
->window
;
5966 XWINDOW (w
->parent
)->vchild
= Qnil
;
5971 /* If we squirreled away the buffer in the window's height,
5973 if (BUFFERP (w
->total_lines
))
5974 w
->buffer
= w
->total_lines
;
5975 w
->left_col
= p
->left_col
;
5976 w
->top_line
= p
->top_line
;
5977 w
->total_cols
= p
->total_cols
;
5978 w
->total_lines
= p
->total_lines
;
5979 w
->hscroll
= p
->hscroll
;
5980 w
->min_hscroll
= p
->min_hscroll
;
5981 w
->display_table
= p
->display_table
;
5982 w
->orig_top_line
= p
->orig_top_line
;
5983 w
->orig_total_lines
= p
->orig_total_lines
;
5984 w
->left_margin_cols
= p
->left_margin_cols
;
5985 w
->right_margin_cols
= p
->right_margin_cols
;
5986 w
->left_fringe_width
= p
->left_fringe_width
;
5987 w
->right_fringe_width
= p
->right_fringe_width
;
5988 w
->fringes_outside_margins
= p
->fringes_outside_margins
;
5989 w
->scroll_bar_width
= p
->scroll_bar_width
;
5990 w
->vertical_scroll_bar_type
= p
->vertical_scroll_bar_type
;
5991 XSETFASTINT (w
->last_modified
, 0);
5992 XSETFASTINT (w
->last_overlay_modified
, 0);
5994 /* Reinstall the saved buffer and pointers into it. */
5995 if (NILP (p
->buffer
))
5996 w
->buffer
= p
->buffer
;
5999 if (!NILP (XBUFFER (p
->buffer
)->name
))
6000 /* If saved buffer is alive, install it. */
6002 w
->buffer
= p
->buffer
;
6003 w
->start_at_line_beg
= p
->start_at_line_beg
;
6004 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
6005 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
6006 Fset_marker (XBUFFER (w
->buffer
)->mark
,
6007 p
->mark
, w
->buffer
);
6009 /* As documented in Fcurrent_window_configuration, don't
6010 restore the location of point in the buffer which was
6011 current when the window configuration was recorded. */
6012 if (!EQ (p
->buffer
, new_current_buffer
)
6013 && XBUFFER (p
->buffer
) == current_buffer
)
6014 Fgoto_char (w
->pointm
);
6016 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
6017 /* Else unless window has a live buffer, get one. */
6019 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
6020 /* This will set the markers to beginning of visible
6022 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
6023 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
6024 w
->start_at_line_beg
= Qt
;
6027 /* Keeping window's old buffer; make sure the markers
6030 /* Set window markers at start of visible range. */
6031 if (XMARKER (w
->start
)->buffer
== 0)
6032 set_marker_restricted (w
->start
, make_number (0),
6034 if (XMARKER (w
->pointm
)->buffer
== 0)
6035 set_marker_restricted_both (w
->pointm
, w
->buffer
,
6036 BUF_PT (XBUFFER (w
->buffer
)),
6037 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6038 w
->start_at_line_beg
= Qt
;
6043 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
6044 /* Prevent "swapping out point" in the old selected window
6045 using the buffer that has been restored into it.
6046 We already swapped out point that from that window's old buffer. */
6047 selected_window
= Qnil
;
6049 /* Arrange *not* to restore point in the buffer that was
6050 current when the window configuration was saved. */
6051 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
6052 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
6053 make_number (old_point
),
6054 XWINDOW (data
->current_window
)->buffer
);
6056 Fselect_window (data
->current_window
, Qnil
);
6057 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
6060 if (NILP (data
->focus_frame
)
6061 || (FRAMEP (data
->focus_frame
)
6062 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
6063 Fredirect_frame_focus (frame
, data
->focus_frame
);
6065 #if 0 /* I don't understand why this is needed, and it causes problems
6066 when the frame's old selected window has been deleted. */
6067 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
6068 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
6072 /* Set the screen height to the value it had before this function. */
6073 if (previous_frame_lines
!= FRAME_LINES (f
)
6074 || previous_frame_cols
!= FRAME_COLS (f
))
6075 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
6077 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
6078 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
6079 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
6081 #ifdef HAVE_WINDOW_SYSTEM
6082 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
6083 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
6088 /* Now, free glyph matrices in windows that were not reused. */
6089 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
6091 if (NILP (leaf_windows
[i
]->buffer
))
6093 /* Assert it's not reused as a combination. */
6094 xassert (NILP (leaf_windows
[i
]->hchild
)
6095 && NILP (leaf_windows
[i
]->vchild
));
6096 free_window_matrices (leaf_windows
[i
]);
6098 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
6106 /* Fselect_window will have made f the selected frame, so we
6107 reselect the proper frame here. Fhandle_switch_frame will change the
6108 selected window too, but that doesn't make the call to
6109 Fselect_window above totally superfluous; it still sets f's
6111 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
6112 do_switch_frame (data
->selected_frame
, 0, 0);
6114 if (! NILP (Vwindow_configuration_change_hook
)
6115 && ! NILP (Vrun_hooks
))
6116 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
6119 if (!NILP (new_current_buffer
))
6120 Fset_buffer (new_current_buffer
);
6122 /* Restore the minimum heights recorded in the configuration. */
6123 window_min_height
= XINT (data
->min_height
);
6124 window_min_width
= XINT (data
->min_width
);
6126 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
6127 minibuf_selected_window
= data
->minibuf_selected_window
;
6129 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
6132 /* Mark all windows now on frame as deleted
6133 by setting their buffers to nil. */
6136 delete_all_subwindows (w
)
6137 register struct window
*w
;
6139 if (!NILP (w
->next
))
6140 delete_all_subwindows (XWINDOW (w
->next
));
6141 if (!NILP (w
->vchild
))
6142 delete_all_subwindows (XWINDOW (w
->vchild
));
6143 if (!NILP (w
->hchild
))
6144 delete_all_subwindows (XWINDOW (w
->hchild
));
6146 w
->total_lines
= w
->buffer
; /* See Fset_window_configuration for excuse. */
6148 if (!NILP (w
->buffer
))
6151 /* We set all three of these fields to nil, to make sure that we can
6152 distinguish this dead window from any live window. Live leaf
6153 windows will have buffer set, and combination windows will have
6154 vchild or hchild set. */
6159 Vwindow_list
= Qnil
;
6163 count_windows (window
)
6164 register struct window
*window
;
6166 register int count
= 1;
6167 if (!NILP (window
->next
))
6168 count
+= count_windows (XWINDOW (window
->next
));
6169 if (!NILP (window
->vchild
))
6170 count
+= count_windows (XWINDOW (window
->vchild
));
6171 if (!NILP (window
->hchild
))
6172 count
+= count_windows (XWINDOW (window
->hchild
));
6177 /* Fill vector FLAT with leaf windows under W, starting at index I.
6178 Value is last index + 1. */
6181 get_leaf_windows (w
, flat
, i
)
6183 struct window
**flat
;
6188 if (!NILP (w
->hchild
))
6189 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
6190 else if (!NILP (w
->vchild
))
6191 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
6195 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6202 /* Return a pointer to the glyph W's physical cursor is on. Value is
6203 null if W's current matrix is invalid, so that no meaningfull glyph
6207 get_phys_cursor_glyph (w
)
6210 struct glyph_row
*row
;
6211 struct glyph
*glyph
;
6213 if (w
->phys_cursor
.vpos
>= 0
6214 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
6215 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
6217 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
6218 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
6227 save_window_save (window
, vector
, i
)
6229 struct Lisp_Vector
*vector
;
6232 register struct saved_window
*p
;
6233 register struct window
*w
;
6234 register Lisp_Object tem
;
6236 for (;!NILP (window
); window
= w
->next
)
6238 p
= SAVED_WINDOW_N (vector
, i
);
6239 w
= XWINDOW (window
);
6241 XSETFASTINT (w
->temslot
, i
); i
++;
6243 p
->buffer
= w
->buffer
;
6244 p
->left_col
= w
->left_col
;
6245 p
->top_line
= w
->top_line
;
6246 p
->total_cols
= w
->total_cols
;
6247 p
->total_lines
= w
->total_lines
;
6248 p
->hscroll
= w
->hscroll
;
6249 p
->min_hscroll
= w
->min_hscroll
;
6250 p
->display_table
= w
->display_table
;
6251 p
->orig_top_line
= w
->orig_top_line
;
6252 p
->orig_total_lines
= w
->orig_total_lines
;
6253 p
->left_margin_cols
= w
->left_margin_cols
;
6254 p
->right_margin_cols
= w
->right_margin_cols
;
6255 p
->left_fringe_width
= w
->left_fringe_width
;
6256 p
->right_fringe_width
= w
->right_fringe_width
;
6257 p
->fringes_outside_margins
= w
->fringes_outside_margins
;
6258 p
->scroll_bar_width
= w
->scroll_bar_width
;
6259 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
6260 if (!NILP (w
->buffer
))
6262 /* Save w's value of point in the window configuration.
6263 If w is the selected window, then get the value of point
6264 from the buffer; pointm is garbage in the selected window. */
6265 if (EQ (window
, selected_window
))
6267 p
->pointm
= Fmake_marker ();
6268 set_marker_both (p
->pointm
, w
->buffer
,
6269 BUF_PT (XBUFFER (w
->buffer
)),
6270 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6273 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
6275 p
->start
= Fcopy_marker (w
->start
, Qnil
);
6276 p
->start_at_line_beg
= w
->start_at_line_beg
;
6278 tem
= XBUFFER (w
->buffer
)->mark
;
6279 p
->mark
= Fcopy_marker (tem
, Qnil
);
6286 p
->start_at_line_beg
= Qnil
;
6289 if (NILP (w
->parent
))
6292 p
->parent
= XWINDOW (w
->parent
)->temslot
;
6297 p
->prev
= XWINDOW (w
->prev
)->temslot
;
6299 if (!NILP (w
->vchild
))
6300 i
= save_window_save (w
->vchild
, vector
, i
);
6301 if (!NILP (w
->hchild
))
6302 i
= save_window_save (w
->hchild
, vector
, i
);
6308 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
6309 Scurrent_window_configuration
, 0, 1, 0,
6310 doc
: /* Return an object representing the current window configuration of FRAME.
6311 If FRAME is nil or omitted, use the selected frame.
6312 This describes the number of windows, their sizes and current buffers,
6313 and for each displayed buffer, where display starts, and the positions of
6314 point and mark. An exception is made for point in the current buffer:
6315 its value is -not- saved.
6316 This also records the currently selected frame, and FRAME's focus
6317 redirection (see `redirect-frame-focus'). */)
6321 register Lisp_Object tem
;
6322 register int n_windows
;
6323 register struct save_window_data
*data
;
6324 register struct Lisp_Vector
*vec
;
6329 frame
= selected_frame
;
6330 CHECK_LIVE_FRAME (frame
);
6333 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6334 vec
= allocate_other_vector (VECSIZE (struct save_window_data
));
6335 data
= (struct save_window_data
*)vec
;
6337 XSETFASTINT (data
->frame_cols
, FRAME_COLS (f
));
6338 XSETFASTINT (data
->frame_lines
, FRAME_LINES (f
));
6339 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
6340 XSETFASTINT (data
->frame_tool_bar_lines
, FRAME_TOOL_BAR_LINES (f
));
6341 data
->selected_frame
= selected_frame
;
6342 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6343 XSETBUFFER (data
->current_buffer
, current_buffer
);
6344 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6345 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6346 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6347 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6348 XSETINT (data
->min_height
, window_min_height
);
6349 XSETINT (data
->min_width
, window_min_width
);
6350 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
6351 data
->saved_windows
= tem
;
6352 for (i
= 0; i
< n_windows
; i
++)
6353 XVECTOR (tem
)->contents
[i
]
6354 = Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
);
6355 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6356 XSETWINDOW_CONFIGURATION (tem
, data
);
6360 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
6362 doc
: /* Execute BODY, preserving window sizes and contents.
6363 Return the value of the last form in BODY.
6364 Restore which buffer appears in which window, where display starts,
6365 and the value of point and mark for each window.
6366 Also restore the choice of selected window.
6367 Also restore which buffer is current.
6368 Does not restore the value of point in current buffer.
6369 usage: (save-window-excursion BODY ...) */)
6373 register Lisp_Object val
;
6374 register int count
= SPECPDL_INDEX ();
6376 record_unwind_protect (Fset_window_configuration
,
6377 Fcurrent_window_configuration (Qnil
));
6378 val
= Fprogn (args
);
6379 return unbind_to (count
, val
);
6384 /***********************************************************************
6386 ***********************************************************************/
6392 Lisp_Object tail
= Qnil
;
6393 Lisp_Object result
= Qnil
;
6400 if (!NILP (w
->hchild
))
6401 wn
= Fcons (Qnil
, Fcons (Fwindow_edges (wn
),
6402 window_tree (XWINDOW (w
->hchild
))));
6403 else if (!NILP (w
->vchild
))
6404 wn
= Fcons (Qt
, Fcons (Fwindow_edges (wn
),
6405 window_tree (XWINDOW (w
->vchild
))));
6409 result
= tail
= Fcons (wn
, Qnil
);
6413 XSETCDR (tail
, Fcons (wn
, Qnil
));
6417 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6425 DEFUN ("window-tree", Fwindow_tree
, Swindow_tree
,
6427 doc
: /* Return the window tree for frame FRAME.
6429 The return value is a list of the form (ROOT MINI), where ROOT
6430 represents the window tree of the frame's root window, and MINI
6431 is the frame's minibuffer window.
6433 If the root window is not split, ROOT is the root window itself.
6434 Otherwise, ROOT is a list (DIR EDGES W1 W2 ...) where DIR is nil for a
6435 horizontal split, and t for a vertical split, EDGES gives the combined
6436 size and position of the subwindows in the split, and the rest of the
6437 elements are the subwindows in the split. Each of the subwindows may
6438 again be a window or a list representing a window split, and so on.
6439 EDGES is a list \(LEFT TOP RIGHT BOTTOM) as returned by `window-edges'.
6441 If FRAME is nil or omitted, return information on the currently
6449 frame
= selected_frame
;
6451 CHECK_FRAME (frame
);
6454 if (!FRAME_LIVE_P (f
))
6457 return window_tree (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6461 /***********************************************************************
6463 ***********************************************************************/
6465 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6467 doc
: /* Set width of marginal areas of window WINDOW.
6468 If WINDOW is nil, set margins of the currently selected window.
6469 Second arg LEFT-WIDTH specifies the number of character cells to
6470 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6471 does the same for the right marginal area. A nil width parameter
6472 means no margin. */)
6473 (window
, left_width
, right_width
)
6474 Lisp_Object window
, left_width
, right_width
;
6476 struct window
*w
= decode_window (window
);
6478 /* Translate negative or zero widths to nil.
6479 Margins that are too wide have to be checked elsewhere. */
6481 if (!NILP (left_width
))
6483 CHECK_NUMBER (left_width
);
6484 if (XINT (left_width
) <= 0)
6488 if (!NILP (right_width
))
6490 CHECK_NUMBER (right_width
);
6491 if (XINT (right_width
) <= 0)
6495 if (!EQ (w
->left_margin_cols
, left_width
)
6496 || !EQ (w
->right_margin_cols
, right_width
))
6498 w
->left_margin_cols
= left_width
;
6499 w
->right_margin_cols
= right_width
;
6501 adjust_window_margins (w
);
6503 ++windows_or_buffers_changed
;
6504 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6511 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6513 doc
: /* Get width of marginal areas of window WINDOW.
6514 If WINDOW is omitted or nil, use the currently selected window.
6515 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6516 If a marginal area does not exist, its width will be returned
6521 struct window
*w
= decode_window (window
);
6522 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
6527 /***********************************************************************
6529 ***********************************************************************/
6531 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6533 doc
: /* Set the fringe widths of window WINDOW.
6534 If WINDOW is nil, set the fringe widths of the currently selected
6536 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6537 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6538 fringe width. If a fringe width arg is nil, that means to use the
6539 frame's default fringe width. Default fringe widths can be set with
6540 the command `set-fringe-style'.
6541 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6542 outside of the display margins. By default, fringes are drawn between
6543 display marginal areas and the text area. */)
6544 (window
, left_width
, right_width
, outside_margins
)
6545 Lisp_Object window
, left_width
, right_width
, outside_margins
;
6547 struct window
*w
= decode_window (window
);
6549 if (!NILP (left_width
))
6550 CHECK_NATNUM (left_width
);
6551 if (!NILP (right_width
))
6552 CHECK_NATNUM (right_width
);
6554 if (!EQ (w
->left_fringe_width
, left_width
)
6555 || !EQ (w
->right_fringe_width
, right_width
)
6556 || !EQ (w
->fringes_outside_margins
, outside_margins
))
6558 w
->left_fringe_width
= left_width
;
6559 w
->right_fringe_width
= right_width
;
6560 w
->fringes_outside_margins
= outside_margins
;
6562 adjust_window_margins (w
);
6564 clear_glyph_matrix (w
->current_matrix
);
6565 w
->window_end_valid
= Qnil
;
6567 ++windows_or_buffers_changed
;
6568 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6575 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6577 doc
: /* Get width of fringes of window WINDOW.
6578 If WINDOW is omitted or nil, use the currently selected window.
6579 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6583 struct window
*w
= decode_window (window
);
6584 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6585 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6586 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
) ?
6587 Qt
: Qnil
), Qnil
)));
6592 /***********************************************************************
6594 ***********************************************************************/
6596 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
, Sset_window_scroll_bars
,
6598 doc
: /* Set width and type of scroll bars of window WINDOW.
6599 If window is nil, set scroll bars of the currently selected window.
6600 Second parameter WIDTH specifies the pixel width for the scroll bar;
6601 this is automatically adjusted to a multiple of the frame column width.
6602 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6603 bar: left, right, or nil.
6604 If WIDTH is nil, use the frame's scroll-bar width.
6605 If TYPE is t, use the frame's scroll-bar type. */)
6606 (window
, width
, vertical_type
, horizontal_type
)
6607 Lisp_Object window
, width
, vertical_type
, horizontal_type
;
6609 struct window
*w
= decode_window (window
);
6613 CHECK_NATNUM (width
);
6615 if (XINT (width
) == 0)
6616 vertical_type
= Qnil
;
6619 if (!(EQ (vertical_type
, Qnil
)
6620 || EQ (vertical_type
, Qleft
)
6621 || EQ (vertical_type
, Qright
)
6622 || EQ (vertical_type
, Qt
)))
6623 error ("Invalid type of vertical scroll bar");
6625 if (!EQ (w
->scroll_bar_width
, width
)
6626 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6628 w
->scroll_bar_width
= width
;
6629 w
->vertical_scroll_bar_type
= vertical_type
;
6631 adjust_window_margins (w
);
6633 clear_glyph_matrix (w
->current_matrix
);
6634 w
->window_end_valid
= Qnil
;
6636 ++windows_or_buffers_changed
;
6637 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6644 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6646 doc
: /* Get width and type of scroll bars of window WINDOW.
6647 If WINDOW is omitted or nil, use the currently selected window.
6648 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6649 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6654 struct window
*w
= decode_window (window
);
6655 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6656 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6657 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6658 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6659 Fcons (w
->vertical_scroll_bar_type
,
6660 Fcons (Qnil
, Qnil
))));
6665 /***********************************************************************
6667 ***********************************************************************/
6669 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6670 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6671 Use the selected window if WINDOW is nil or omitted.
6672 Normally, value is a multiple of the canonical character height of WINDOW;
6673 optional second arg PIXELS-P means value is measured in pixels. */)
6675 Lisp_Object window
, pixels_p
;
6682 window
= selected_window
;
6684 CHECK_WINDOW (window
);
6685 w
= XWINDOW (window
);
6686 f
= XFRAME (w
->frame
);
6688 if (FRAME_WINDOW_P (f
))
6689 result
= (NILP (pixels_p
)
6690 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6691 : make_number (-w
->vscroll
));
6693 result
= make_number (0);
6698 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6700 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6701 WINDOW nil means use the selected window. Normally, VSCROLL is a
6702 non-negative multiple of the canonical character height of WINDOW;
6703 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
6704 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6705 corresponds to an integral number of pixels. The return value is the
6706 result of this rounding.
6707 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6708 (window
, vscroll
, pixels_p
)
6709 Lisp_Object window
, vscroll
, pixels_p
;
6715 window
= selected_window
;
6717 CHECK_WINDOW (window
);
6718 CHECK_NUMBER_OR_FLOAT (vscroll
);
6720 w
= XWINDOW (window
);
6721 f
= XFRAME (w
->frame
);
6723 if (FRAME_WINDOW_P (f
))
6725 int old_dy
= w
->vscroll
;
6727 w
->vscroll
= - (NILP (pixels_p
)
6728 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
6729 : XFLOATINT (vscroll
));
6730 w
->vscroll
= min (w
->vscroll
, 0);
6732 if (w
->vscroll
!= old_dy
)
6734 /* Adjust glyph matrix of the frame if the virtual display
6735 area becomes larger than before. */
6736 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
6739 /* Prevent redisplay shortcuts. */
6740 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
6744 return Fwindow_vscroll (window
, pixels_p
);
6748 /* Call FN for all leaf windows on frame F. FN is called with the
6749 first argument being a pointer to the leaf window, and with
6750 additional argument USER_DATA. Stops when FN returns 0. */
6753 foreach_window (f
, fn
, user_data
)
6755 int (* fn
) P_ ((struct window
*, void *));
6758 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
6762 /* Helper function for foreach_window. Call FN for all leaf windows
6763 reachable from W. FN is called with the first argument being a
6764 pointer to the leaf window, and with additional argument USER_DATA.
6765 Stop when FN returns 0. Value is 0 if stopped by FN. */
6768 foreach_window_1 (w
, fn
, user_data
)
6770 int (* fn
) P_ ((struct window
*, void *));
6775 for (cont
= 1; w
&& cont
;)
6777 if (!NILP (w
->hchild
))
6778 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
6779 else if (!NILP (w
->vchild
))
6780 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
6782 cont
= fn (w
, user_data
);
6784 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6791 /* Freeze or unfreeze the window start of W unless it is a
6792 mini-window or the selected window. FREEZE_P non-null means freeze
6793 the window start. */
6796 freeze_window_start (w
, freeze_p
)
6800 if (w
== XWINDOW (selected_window
)
6801 || MINI_WINDOW_P (w
)
6802 || (MINI_WINDOW_P (XWINDOW (selected_window
))
6803 && ! NILP (Vminibuf_scroll_window
)
6804 && w
== XWINDOW (Vminibuf_scroll_window
)))
6807 w
->frozen_window_start_p
= freeze_p
!= NULL
;
6812 /* Freeze or unfreeze the window starts of all leaf windows on frame
6813 F, except the selected window and a mini-window. FREEZE_P non-zero
6814 means freeze the window start. */
6817 freeze_window_starts (f
, freeze_p
)
6821 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
6825 /***********************************************************************
6827 ***********************************************************************/
6829 /* Return 1 if window configurations C1 and C2
6830 describe the same state of affairs. This is used by Fequal. */
6833 compare_window_configurations (c1
, c2
, ignore_positions
)
6835 int ignore_positions
;
6837 register struct save_window_data
*d1
, *d2
;
6838 struct Lisp_Vector
*sw1
, *sw2
;
6841 if (!WINDOW_CONFIGURATIONP (c1
))
6842 wrong_type_argument (Qwindow_configuration_p
, c1
);
6843 if (!WINDOW_CONFIGURATIONP (c2
))
6844 wrong_type_argument (Qwindow_configuration_p
, c2
);
6846 d1
= (struct save_window_data
*) XVECTOR (c1
);
6847 d2
= (struct save_window_data
*) XVECTOR (c2
);
6848 sw1
= XVECTOR (d1
->saved_windows
);
6849 sw2
= XVECTOR (d2
->saved_windows
);
6851 if (! EQ (d1
->frame_cols
, d2
->frame_cols
))
6853 if (! EQ (d1
->frame_lines
, d2
->frame_lines
))
6855 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
6857 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
6859 /* Don't compare the current_window field directly.
6860 Instead see w1_is_current and w2_is_current, below. */
6861 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
6863 if (! ignore_positions
)
6865 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
6867 if (! EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
))
6870 /* Don't compare the root_window field.
6871 We don't require the two configurations
6872 to use the same window object,
6873 and the two root windows must be equivalent
6874 if everything else compares equal. */
6875 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
6877 if (! EQ (d1
->min_width
, d2
->min_width
))
6879 if (! EQ (d1
->min_height
, d2
->min_height
))
6882 /* Verify that the two confis have the same number of windows. */
6883 if (sw1
->size
!= sw2
->size
)
6886 for (i
= 0; i
< sw1
->size
; i
++)
6888 struct saved_window
*p1
, *p2
;
6889 int w1_is_current
, w2_is_current
;
6891 p1
= SAVED_WINDOW_N (sw1
, i
);
6892 p2
= SAVED_WINDOW_N (sw2
, i
);
6894 /* Verify that the current windows in the two
6895 configurations correspond to each other. */
6896 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
6897 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
6899 if (w1_is_current
!= w2_is_current
)
6902 /* Verify that the corresponding windows do match. */
6903 if (! EQ (p1
->buffer
, p2
->buffer
))
6905 if (! EQ (p1
->left_col
, p2
->left_col
))
6907 if (! EQ (p1
->top_line
, p2
->top_line
))
6909 if (! EQ (p1
->total_cols
, p2
->total_cols
))
6911 if (! EQ (p1
->total_lines
, p2
->total_lines
))
6913 if (! EQ (p1
->display_table
, p2
->display_table
))
6915 if (! EQ (p1
->parent
, p2
->parent
))
6917 if (! EQ (p1
->prev
, p2
->prev
))
6919 if (! ignore_positions
)
6921 if (! EQ (p1
->hscroll
, p2
->hscroll
))
6923 if (!EQ (p1
->min_hscroll
, p2
->min_hscroll
))
6925 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
6927 if (NILP (Fequal (p1
->start
, p2
->start
)))
6929 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
6931 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
6934 if (! EQ (p1
->left_margin_cols
, p2
->left_margin_cols
))
6936 if (! EQ (p1
->right_margin_cols
, p2
->right_margin_cols
))
6938 if (! EQ (p1
->left_fringe_width
, p2
->left_fringe_width
))
6940 if (! EQ (p1
->right_fringe_width
, p2
->right_fringe_width
))
6942 if (! EQ (p1
->fringes_outside_margins
, p2
->fringes_outside_margins
))
6944 if (! EQ (p1
->scroll_bar_width
, p2
->scroll_bar_width
))
6946 if (! EQ (p1
->vertical_scroll_bar_type
, p2
->vertical_scroll_bar_type
))
6953 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
6954 Scompare_window_configurations
, 2, 2, 0,
6955 doc
: /* Compare two window configurations as regards the structure of windows.
6956 This function ignores details such as the values of point and mark
6957 and scrolling positions. */)
6961 if (compare_window_configurations (x
, y
, 1))
6969 struct frame
*f
= make_initial_frame ();
6970 XSETFRAME (selected_frame
, f
);
6971 Vterminal_frame
= selected_frame
;
6972 minibuf_window
= f
->minibuffer_window
;
6973 selected_window
= f
->selected_window
;
6974 last_nonminibuf_frame
= f
;
6976 window_initialized
= 1;
6982 Vwindow_list
= Qnil
;
6988 Qwindow_size_fixed
= intern ("window-size-fixed");
6989 staticpro (&Qwindow_size_fixed
);
6990 Fset (Qwindow_size_fixed
, Qnil
);
6992 staticpro (&Qwindow_configuration_change_hook
);
6993 Qwindow_configuration_change_hook
6994 = intern ("window-configuration-change-hook");
6996 Qwindowp
= intern ("windowp");
6997 staticpro (&Qwindowp
);
6999 Qwindow_configuration_p
= intern ("window-configuration-p");
7000 staticpro (&Qwindow_configuration_p
);
7002 Qwindow_live_p
= intern ("window-live-p");
7003 staticpro (&Qwindow_live_p
);
7005 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
7006 staticpro (&Qtemp_buffer_show_hook
);
7008 staticpro (&Vwindow_list
);
7010 minibuf_selected_window
= Qnil
;
7011 staticpro (&minibuf_selected_window
);
7013 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
7014 doc
: /* Non-nil means call as function to display a help buffer.
7015 The function is called with one argument, the buffer to be displayed.
7016 Used by `with-output-to-temp-buffer'.
7017 If this function is used, then it must do the entire job of showing
7018 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
7019 Vtemp_buffer_show_function
= Qnil
;
7021 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
7022 doc
: /* If non-nil, function to call to handle `display-buffer'.
7023 It will receive two args, the buffer and a flag which if non-nil means
7024 that the currently selected window is not acceptable.
7025 It should choose or create a window, display the specified buffer in it,
7026 and return the window.
7027 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'
7028 work using this function. */);
7029 Vdisplay_buffer_function
= Qnil
;
7031 DEFVAR_LISP ("even-window-heights", &Veven_window_heights
,
7032 doc
: /* *If non-nil, `display-buffer' should even the window heights.
7033 If nil, `display-buffer' will leave the window configuration alone. */);
7034 Veven_window_heights
= Qt
;
7036 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
7037 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
7038 Vminibuf_scroll_window
= Qnil
;
7040 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows
,
7041 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
7042 If the minibuffer is active, the `minibuffer-scroll-window' mode line
7043 is displayed in the `mode-line' face. */);
7044 mode_line_in_non_selected_windows
= 1;
7046 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
7047 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
7048 Vother_window_scroll_buffer
= Qnil
;
7050 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
7051 doc
: /* *Non-nil means `display-buffer' should make a separate frame. */);
7054 DEFVAR_BOOL ("auto-window-vscroll", &auto_window_vscroll_p
,
7055 doc
: /* *Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
7056 auto_window_vscroll_p
= 1;
7058 DEFVAR_BOOL ("display-buffer-reuse-frames", &display_buffer_reuse_frames
,
7059 doc
: /* *Non-nil means `display-buffer' should reuse frames.
7060 If the buffer in question is already displayed in a frame, raise that frame. */);
7061 display_buffer_reuse_frames
= 0;
7063 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
7064 doc
: /* Function to call to handle automatic new frame creation.
7065 It is called with no arguments and should return a newly created frame.
7067 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'
7068 where `pop-up-frame-alist' would hold the default frame parameters. */);
7069 Vpop_up_frame_function
= Qnil
;
7071 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
7072 doc
: /* *List of buffer names that should have their own special frames.
7073 Displaying a buffer with `display-buffer' or `pop-to-buffer',
7074 if its name is in this list, makes a special frame for it
7075 using `special-display-function'. See also `special-display-regexps'.
7077 An element of the list can be a list instead of just a string.
7078 There are two ways to use a list as an element:
7079 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)
7080 In the first case, the FRAME-PARAMETERS are pairs of the form
7081 \(PARAMETER . VALUE); these parameter values are used to create the frame.
7082 In the second case, FUNCTION is called with BUFFER as the first argument,
7083 followed by the OTHER-ARGS--it can display BUFFER in any way it likes.
7084 All this is done by the function found in `special-display-function'.
7086 If the specified frame parameters include (same-buffer . t), the
7087 buffer is displayed in the currently selected window. Otherwise, if
7088 they include (same-frame . t), the buffer is displayed in a new window
7089 in the currently selected frame.
7091 If this variable appears \"not to work\", because you add a name to it
7092 but that buffer still appears in the selected window, look at the
7093 values of `same-window-buffer-names' and `same-window-regexps'.
7094 Those variables take precedence over this one. */);
7095 Vspecial_display_buffer_names
= Qnil
;
7097 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
7098 doc
: /* *List of regexps saying which buffers should have their own special frames.
7099 When displaying a buffer with `display-buffer' or `pop-to-buffer',
7100 if any regexp in this list matches the buffer name, it makes a
7101 special frame for the buffer by calling `special-display-function'.
7103 An element of the list can be a list instead of just a string.
7104 There are two ways to use a list as an element:
7105 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)
7106 In the first case, the FRAME-PARAMETERS are pairs of the form
7107 \(PARAMETER . VALUE); these parameter values are used to create the frame.
7108 In the second case, FUNCTION is called with BUFFER as the first argument,
7109 followed by the OTHER-ARGS--it can display the buffer in any way it likes.
7110 All this is done by the function found in `special-display-function'.
7112 If the specified frame parameters include (same-buffer . t), the
7113 buffer is displayed in the currently selected window. Otherwise, if
7114 they include (same-frame . t), the buffer is displayed in a new window
7115 in the currently selected frame.
7117 If this variable appears \"not to work\", because you add a regexp to it
7118 but the matching buffers still appear in the selected window, look at the
7119 values of `same-window-buffer-names' and `same-window-regexps'.
7120 Those variables take precedence over this one. */);
7121 Vspecial_display_regexps
= Qnil
;
7123 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
7124 doc
: /* Function to call to make a new frame for a special buffer.
7125 It is called with two arguments, the buffer and optional buffer specific
7126 data, and should return a window displaying that buffer.
7127 The default value normally makes a separate frame for the buffer,
7128 using `special-display-frame-alist' to specify the frame parameters.
7129 But if the buffer specific data includes (same-buffer . t) then the
7130 buffer is displayed in the current selected window.
7131 Otherwise if it includes (same-frame . t) then the buffer is displayed in
7132 a new window in the currently selected frame.
7134 A buffer is special if it is listed in `special-display-buffer-names'
7135 or matches a regexp in `special-display-regexps'. */);
7136 Vspecial_display_function
= Qnil
;
7138 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
7139 doc
: /* *List of buffer names that should appear in the selected window.
7140 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'
7141 switches to it in the selected window, rather than making it appear
7142 in some other window.
7144 An element of the list can be a cons cell instead of just a string.
7145 Then the car must be a string, which specifies the buffer name.
7146 This is for compatibility with `special-display-buffer-names';
7147 the cdr of the cons cell is ignored.
7149 See also `same-window-regexps'. */);
7150 Vsame_window_buffer_names
= Qnil
;
7152 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
7153 doc
: /* *List of regexps saying which buffers should appear in the selected window.
7154 If a buffer name matches one of these regexps, then displaying it
7155 using `display-buffer' or `pop-to-buffer' switches to it
7156 in the selected window, rather than making it appear in some other window.
7158 An element of the list can be a cons cell instead of just a string.
7159 Then the car must be a string, which specifies the buffer name.
7160 This is for compatibility with `special-display-buffer-names';
7161 the cdr of the cons cell is ignored.
7163 See also `same-window-buffer-names'. */);
7164 Vsame_window_regexps
= Qnil
;
7166 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
7167 doc
: /* *Non-nil means display-buffer should make new windows. */);
7170 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
7171 doc
: /* *Number of lines of continuity when scrolling by screenfuls. */);
7172 next_screen_context_lines
= 2;
7174 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
7175 doc
: /* *A window must be at least this tall to be eligible for splitting by `display-buffer'.
7176 If there is only one window, it is split regardless of this value. */);
7177 split_height_threshold
= 500;
7179 DEFVAR_INT ("window-min-height", &window_min_height
,
7180 doc
: /* *Delete any window less than this tall (including its mode line). */);
7181 window_min_height
= 4;
7183 DEFVAR_INT ("window-min-width", &window_min_width
,
7184 doc
: /* *Delete any window less than this wide. */);
7185 window_min_width
= 10;
7187 DEFVAR_LISP ("scroll-preserve-screen-position",
7188 &Vscroll_preserve_screen_position
,
7189 doc
: /* *Controls if scroll commands move point to keep its screen line unchanged.
7190 A value of nil means point does not keep its screen position except
7191 at the scroll margin or window boundary respectively.
7192 A value of t means point keeps its screen position if the scroll
7193 command moved it vertically out of the window, e.g. when scrolling
7195 Any other value means point always keeps its screen position. */);
7196 Vscroll_preserve_screen_position
= Qnil
;
7198 DEFVAR_LISP ("window-configuration-change-hook",
7199 &Vwindow_configuration_change_hook
,
7200 doc
: /* Functions to call when window configuration changes.
7201 The selected frame is the one whose configuration has changed. */);
7202 Vwindow_configuration_change_hook
= Qnil
;
7204 defsubr (&Sselected_window
);
7205 defsubr (&Sminibuffer_window
);
7206 defsubr (&Swindow_minibuffer_p
);
7207 defsubr (&Swindowp
);
7208 defsubr (&Swindow_live_p
);
7209 defsubr (&Spos_visible_in_window_p
);
7210 defsubr (&Swindow_buffer
);
7211 defsubr (&Swindow_height
);
7212 defsubr (&Swindow_width
);
7213 defsubr (&Swindow_hscroll
);
7214 defsubr (&Sset_window_hscroll
);
7215 defsubr (&Swindow_redisplay_end_trigger
);
7216 defsubr (&Sset_window_redisplay_end_trigger
);
7217 defsubr (&Swindow_edges
);
7218 defsubr (&Swindow_pixel_edges
);
7219 defsubr (&Swindow_inside_edges
);
7220 defsubr (&Swindow_inside_pixel_edges
);
7221 defsubr (&Scoordinates_in_window_p
);
7222 defsubr (&Swindow_at
);
7223 defsubr (&Swindow_point
);
7224 defsubr (&Swindow_start
);
7225 defsubr (&Swindow_end
);
7226 defsubr (&Sset_window_point
);
7227 defsubr (&Sset_window_start
);
7228 defsubr (&Swindow_dedicated_p
);
7229 defsubr (&Sset_window_dedicated_p
);
7230 defsubr (&Swindow_display_table
);
7231 defsubr (&Sset_window_display_table
);
7232 defsubr (&Snext_window
);
7233 defsubr (&Sprevious_window
);
7234 defsubr (&Sother_window
);
7235 defsubr (&Sget_lru_window
);
7236 defsubr (&Sget_largest_window
);
7237 defsubr (&Sget_buffer_window
);
7238 defsubr (&Sdelete_other_windows
);
7239 defsubr (&Sdelete_windows_on
);
7240 defsubr (&Sreplace_buffer_in_windows
);
7241 defsubr (&Sdelete_window
);
7242 defsubr (&Sset_window_buffer
);
7243 defsubr (&Sselect_window
);
7244 defsubr (&Sspecial_display_p
);
7245 defsubr (&Ssame_window_p
);
7246 defsubr (&Sdisplay_buffer
);
7247 defsubr (&Sforce_window_update
);
7248 defsubr (&Ssplit_window
);
7249 defsubr (&Senlarge_window
);
7250 defsubr (&Sshrink_window
);
7251 defsubr (&Sadjust_window_trailing_edge
);
7252 defsubr (&Sscroll_up
);
7253 defsubr (&Sscroll_down
);
7254 defsubr (&Sscroll_left
);
7255 defsubr (&Sscroll_right
);
7256 defsubr (&Sother_window_for_scrolling
);
7257 defsubr (&Sscroll_other_window
);
7258 defsubr (&Sminibuffer_selected_window
);
7259 defsubr (&Srecenter
);
7260 defsubr (&Swindow_text_height
);
7261 defsubr (&Smove_to_window_line
);
7262 defsubr (&Swindow_configuration_p
);
7263 defsubr (&Swindow_configuration_frame
);
7264 defsubr (&Sset_window_configuration
);
7265 defsubr (&Scurrent_window_configuration
);
7266 defsubr (&Ssave_window_excursion
);
7267 defsubr (&Swindow_tree
);
7268 defsubr (&Sset_window_margins
);
7269 defsubr (&Swindow_margins
);
7270 defsubr (&Sset_window_fringes
);
7271 defsubr (&Swindow_fringes
);
7272 defsubr (&Sset_window_scroll_bars
);
7273 defsubr (&Swindow_scroll_bars
);
7274 defsubr (&Swindow_vscroll
);
7275 defsubr (&Sset_window_vscroll
);
7276 defsubr (&Scompare_window_configurations
);
7277 defsubr (&Swindow_list
);
7283 initial_define_key (control_x_map
, '1', "delete-other-windows");
7284 initial_define_key (control_x_map
, '2', "split-window");
7285 initial_define_key (control_x_map
, '0', "delete-window");
7286 initial_define_key (control_x_map
, 'o', "other-window");
7287 initial_define_key (control_x_map
, '^', "enlarge-window");
7288 initial_define_key (control_x_map
, '<', "scroll-left");
7289 initial_define_key (control_x_map
, '>', "scroll-right");
7291 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
7292 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
7293 initial_define_key (meta_map
, 'v', "scroll-down");
7295 initial_define_key (global_map
, Ctl('L'), "recenter");
7296 initial_define_key (meta_map
, 'r', "move-to-window-line");
7299 /* arch-tag: 90a9c576-0590-48f1-a5f1-6c96a0452d9f
7300 (do not change this comment) */