1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985,86,87, 1993,94,95,96,97,98, 2000,01,02,03,04
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
34 #include "dispextern.h"
35 #include "blockinput.h"
36 #include "intervals.h"
40 #endif /* HAVE_X_WINDOWS */
52 Lisp_Object Qwindowp
, Qwindow_live_p
, Qwindow_configuration_p
;
53 Lisp_Object Qwindow_size_fixed
;
54 extern Lisp_Object Qleft_margin
, Qright_margin
;
56 static int displayed_window_lines
P_ ((struct window
*));
57 static struct window
*decode_window
P_ ((Lisp_Object
));
58 static int count_windows
P_ ((struct window
*));
59 static int get_leaf_windows
P_ ((struct window
*, struct window
**, int));
60 static void window_scroll
P_ ((Lisp_Object
, int, int, int));
61 static void window_scroll_pixel_based
P_ ((Lisp_Object
, int, int, int));
62 static void window_scroll_line_based
P_ ((Lisp_Object
, int, int, int));
63 static int window_min_size_1
P_ ((struct window
*, int));
64 static int window_min_size
P_ ((struct window
*, int, int, int *));
65 static void size_window
P_ ((Lisp_Object
, int, int, int));
66 static int freeze_window_start
P_ ((struct window
*, void *));
67 static int window_fixed_size_p
P_ ((struct window
*, int, int));
68 static void enlarge_window
P_ ((Lisp_Object
, int, int, int));
69 static Lisp_Object window_list
P_ ((void));
70 static int add_window_to_list
P_ ((struct window
*, void *));
71 static int candidate_window_p
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
73 static Lisp_Object next_window
P_ ((Lisp_Object
, Lisp_Object
,
75 static void decode_next_window_args
P_ ((Lisp_Object
*, Lisp_Object
*,
77 static int foreach_window_1
P_ ((struct window
*,
78 int (* fn
) (struct window
*, void *),
80 static Lisp_Object window_list_1
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
82 /* The value of `window-size-fixed'. */
84 int window_size_fixed
;
86 /* This is the window in which the terminal's cursor should
87 be left when nothing is being done with it. This must
88 always be a leaf window, and its buffer is selected by
89 the top level editing loop at the end of each command.
91 This value is always the same as
92 FRAME_SELECTED_WINDOW (selected_frame). */
94 Lisp_Object selected_window
;
96 /* A list of all windows for use by next_window and Fwindow_list.
97 Functions creating or deleting windows should invalidate this cache
98 by setting it to nil. */
100 Lisp_Object Vwindow_list
;
102 /* The mini-buffer window of the selected frame.
103 Note that you cannot test for mini-bufferness of an arbitrary window
104 by comparing against this; but you can test for mini-bufferness of
105 the selected window. */
107 Lisp_Object minibuf_window
;
109 /* Non-nil means it is the window whose mode line should be
110 shown as the selected window when the minibuffer is selected. */
112 Lisp_Object minibuf_selected_window
;
114 /* Non-nil means it is the window for C-M-v to scroll
115 when the mini-buffer is selected. */
117 Lisp_Object Vminibuf_scroll_window
;
119 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
121 Lisp_Object Vother_window_scroll_buffer
;
123 /* Non-nil means it's function to call to display temp buffers. */
125 Lisp_Object Vtemp_buffer_show_function
;
127 /* Non-zero means to use mode-line-inactive face in all windows but the
128 selected-window and the minibuffer-scroll-window when the
129 minibuffer is active. */
130 int mode_line_in_non_selected_windows
;
132 /* If a window gets smaller than either of these, it is removed. */
134 EMACS_INT window_min_height
;
135 EMACS_INT window_min_width
;
137 /* Nonzero implies Fdisplay_buffer should create windows. */
141 /* Nonzero implies make new frames for Fdisplay_buffer. */
145 /* Nonzero means reuse existing frames for displaying buffers. */
147 int display_buffer_reuse_frames
;
149 /* Non-nil means use this function instead of default */
151 Lisp_Object Vpop_up_frame_function
;
153 /* Function to call to handle Fdisplay_buffer. */
155 Lisp_Object Vdisplay_buffer_function
;
157 /* Non-nil means that Fdisplay_buffer should even the heights of windows. */
159 Lisp_Object Veven_window_heights
;
161 /* List of buffer *names* for buffers that should have their own frames. */
163 Lisp_Object Vspecial_display_buffer_names
;
165 /* List of regexps for buffer names that should have their own frames. */
167 Lisp_Object Vspecial_display_regexps
;
169 /* Function to pop up a special frame. */
171 Lisp_Object Vspecial_display_function
;
173 /* List of buffer *names* for buffers to appear in selected window. */
175 Lisp_Object Vsame_window_buffer_names
;
177 /* List of regexps for buffer names to appear in selected window. */
179 Lisp_Object Vsame_window_regexps
;
181 /* Hook run at end of temp_output_buffer_show. */
183 Lisp_Object Qtemp_buffer_show_hook
;
185 /* Fdisplay_buffer always splits the largest window
186 if that window is more than this high. */
188 EMACS_INT split_height_threshold
;
190 /* Number of lines of continuity in scrolling by screenfuls. */
192 EMACS_INT next_screen_context_lines
;
194 /* Incremented for each window created. */
196 static int sequence_number
;
198 /* Nonzero after init_window_once has finished. */
200 static int window_initialized
;
202 /* Hook to run when window config changes. */
204 Lisp_Object Qwindow_configuration_change_hook
;
205 Lisp_Object Vwindow_configuration_change_hook
;
207 /* Non-nil means scroll commands try to put point
208 at the same screen height as previously. */
210 Lisp_Object Vscroll_preserve_screen_position
;
212 #if 0 /* This isn't used anywhere. */
213 /* Nonzero means we can split a frame even if it is "unsplittable". */
214 static int inhibit_frame_unsplittable
;
217 extern EMACS_INT scroll_margin
;
219 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
221 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
222 doc
: /* Returns t if OBJECT is a window. */)
226 return WINDOWP (object
) ? Qt
: Qnil
;
229 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
230 doc
: /* Returns t if OBJECT is a window which is currently visible. */)
234 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
241 register struct window
*p
;
243 p
= allocate_window ();
245 XSETFASTINT (p
->sequence_number
, sequence_number
);
246 XSETFASTINT (p
->left_col
, 0);
247 XSETFASTINT (p
->top_line
, 0);
248 XSETFASTINT (p
->total_lines
, 0);
249 XSETFASTINT (p
->total_cols
, 0);
250 XSETFASTINT (p
->hscroll
, 0);
251 XSETFASTINT (p
->min_hscroll
, 0);
252 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
253 p
->start
= Fmake_marker ();
254 p
->pointm
= Fmake_marker ();
255 XSETFASTINT (p
->use_time
, 0);
257 p
->display_table
= Qnil
;
259 p
->pseudo_window_p
= 0;
260 bzero (&p
->cursor
, sizeof (p
->cursor
));
261 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
262 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
263 p
->desired_matrix
= p
->current_matrix
= 0;
264 p
->nrows_scale_factor
= p
->ncols_scale_factor
= 1;
265 p
->phys_cursor_type
= -1;
266 p
->phys_cursor_width
= -1;
267 p
->must_be_updated_p
= 0;
268 XSETFASTINT (p
->window_end_vpos
, 0);
269 XSETFASTINT (p
->window_end_pos
, 0);
270 p
->window_end_valid
= Qnil
;
273 XSETFASTINT (p
->last_point
, 0);
274 p
->frozen_window_start_p
= 0;
275 p
->height_fixed_p
= 0;
276 p
->last_cursor_off_p
= p
->cursor_off_p
= 0;
277 p
->left_margin_cols
= Qnil
;
278 p
->right_margin_cols
= Qnil
;
279 p
->left_fringe_width
= Qnil
;
280 p
->right_fringe_width
= Qnil
;
281 p
->fringes_outside_margins
= Qnil
;
282 p
->scroll_bar_width
= Qnil
;
283 p
->vertical_scroll_bar_type
= Qt
;
284 p
->overlay_arrow_bitmap
= 0;
290 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
291 doc
: /* Return the window that the cursor now appears in and commands apply to. */)
294 return selected_window
;
297 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
298 doc
: /* Return the window used now for minibuffers.
299 If the optional argument FRAME is specified, return the minibuffer window
300 used by that frame. */)
305 frame
= selected_frame
;
306 CHECK_LIVE_FRAME (frame
);
307 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
310 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
311 doc
: /* Returns non-nil if WINDOW is a minibuffer window.
312 WINDOW defaults to the selected window. */)
316 struct window
*w
= decode_window (window
);
317 return MINI_WINDOW_P (w
) ? Qt
: Qnil
;
321 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
322 Spos_visible_in_window_p
, 0, 3, 0,
323 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
324 Return nil if that position is scrolled vertically out of view.
325 If a character is only partially visible, nil is returned, unless the
326 optional argument PARTIALLY is non-nil.
327 If POS is only out of view because of horizontal scrolling, return non-nil.
328 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
330 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
331 return value is a list (X Y FULLY) where X and Y are the pixel coordinates
332 relative to the top left corner of the window, and FULLY is t if the
333 character after POS is fully visible and nil otherwise. */)
334 (pos
, window
, partially
)
335 Lisp_Object pos
, window
, partially
;
337 register struct window
*w
;
339 register struct buffer
*buf
;
341 Lisp_Object in_window
= Qnil
;
345 w
= decode_window (window
);
346 buf
= XBUFFER (w
->buffer
);
347 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
351 CHECK_NUMBER_COERCE_MARKER (pos
);
354 else if (w
== XWINDOW (selected_window
))
357 posint
= XMARKER (w
->pointm
)->charpos
;
359 /* If position is above window start or outside buffer boundaries,
360 or if window start is out of range, position is not visible. */
361 if (posint
>= CHARPOS (top
)
362 && posint
<= BUF_ZV (buf
)
363 && CHARPOS (top
) >= BUF_BEGV (buf
)
364 && CHARPOS (top
) <= BUF_ZV (buf
)
365 && pos_visible_p (w
, posint
, &fully_p
, &x
, &y
, NILP (partially
))
366 && (!NILP (partially
) || fully_p
))
369 if (!NILP (in_window
) && !NILP (partially
))
370 in_window
= Fcons (make_number (x
),
371 Fcons (make_number (y
),
372 Fcons (fully_p
? Qt
: Qnil
, Qnil
)));
377 static struct window
*
378 decode_window (window
)
379 register Lisp_Object window
;
382 return XWINDOW (selected_window
);
384 CHECK_LIVE_WINDOW (window
);
385 return XWINDOW (window
);
388 static struct window
*
389 decode_any_window (window
)
390 register Lisp_Object window
;
393 return XWINDOW (selected_window
);
395 CHECK_WINDOW (window
);
396 return XWINDOW (window
);
399 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
400 doc
: /* Return the buffer that WINDOW is displaying.
401 WINDOW defaults to the selected window. */)
405 return decode_window (window
)->buffer
;
408 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
409 doc
: /* Return the number of lines in WINDOW (including its mode line). */)
413 return decode_any_window (window
)->total_lines
;
416 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
417 doc
: /* Return the number of display columns in WINDOW.
418 This is the width that is usable columns available for text in WINDOW.
419 If you want to find out how many columns WINDOW takes up,
420 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
424 return make_number (window_box_text_cols (decode_any_window (window
)));
427 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
428 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin. */)
432 return decode_window (window
)->hscroll
;
435 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
436 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
437 Return NCOL. NCOL should be zero or positive.
439 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
440 window so that the location of point becomes invisible. */)
442 Lisp_Object window
, ncol
;
444 struct window
*w
= decode_window (window
);
448 hscroll
= max (0, XINT (ncol
));
450 /* Prevent redisplay shortcuts when changing the hscroll. */
451 if (XINT (w
->hscroll
) != hscroll
)
452 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
454 w
->hscroll
= make_number (hscroll
);
458 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
459 Swindow_redisplay_end_trigger
, 0, 1, 0,
460 doc
: /* Return WINDOW's redisplay end trigger value.
461 See `set-window-redisplay-end-trigger' for more information. */)
465 return decode_window (window
)->redisplay_end_trigger
;
468 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
469 Sset_window_redisplay_end_trigger
, 2, 2, 0,
470 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
471 VALUE should be a buffer position (typically a marker) or nil.
472 If it is a buffer position, then if redisplay in WINDOW reaches a position
473 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
474 with two arguments: WINDOW, and the end trigger value.
475 Afterwards the end-trigger value is reset to nil. */)
477 register Lisp_Object window
, value
;
479 register struct window
*w
;
481 w
= decode_window (window
);
482 w
->redisplay_end_trigger
= value
;
486 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
487 doc
: /* Return a list of the edge coordinates of WINDOW.
488 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
489 RIGHT is one more than the rightmost column occupied by WINDOW,
490 and BOTTOM is one more than the bottommost row occupied by WINDOW.
491 The edges include the space used by the window's scroll bar,
492 display margins, fringes, header line, and mode line, if it has them.
493 To get the edges of the actual text area, use `window-inside-edges'. */)
497 register struct window
*w
= decode_any_window (window
);
499 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w
)),
500 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w
)),
501 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w
)),
502 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w
)),
506 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
507 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
508 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
509 RIGHT is one more than the rightmost x position occupied by WINDOW,
510 and BOTTOM is one more than the bottommost y position occupied by WINDOW.
511 The pixel edges include the space used by the window's scroll bar,
512 display margins, fringes, header line, and mode line, if it has them.
513 To get the edges of the actual text area, use `window-inside-pixel-edges'. */)
517 register struct window
*w
= decode_any_window (window
);
519 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
)),
520 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
)),
521 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
)),
522 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
)),
526 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
527 doc
: /* Return a list of the edge coordinates of WINDOW.
528 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
529 RIGHT is one more than the rightmost column used by text in WINDOW,
530 and BOTTOM is one more than the bottommost row used by text in WINDOW.
531 The inside edges do not include the space used by the window's scroll bar,
532 display margins, fringes, header line, and/or mode line. */)
536 register struct window
*w
= decode_any_window (window
);
538 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w
)
539 + WINDOW_LEFT_MARGIN_COLS (w
)
540 + WINDOW_LEFT_FRINGE_COLS (w
)),
541 make_number (WINDOW_TOP_EDGE_LINE (w
)
542 + WINDOW_HEADER_LINE_LINES (w
)),
543 make_number (WINDOW_RIGHT_EDGE_COL (w
)
544 - WINDOW_RIGHT_MARGIN_COLS (w
)
545 - WINDOW_RIGHT_FRINGE_COLS (w
)),
546 make_number (WINDOW_BOTTOM_EDGE_LINE (w
)
547 - WINDOW_MODE_LINE_LINES (w
)));
550 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
551 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
552 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
553 RIGHT is one more than the rightmost x position used by text in WINDOW,
554 and BOTTOM is one more than the bottommost y position used by text in WINDOW.
555 The inside edges do not include the space used by the window's scroll bar,
556 display margins, fringes, header line, and/or mode line. */)
560 register struct window
*w
= decode_any_window (window
);
562 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
563 + WINDOW_LEFT_MARGIN_WIDTH (w
)
564 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
565 make_number (WINDOW_TOP_EDGE_Y (w
)
566 + WINDOW_HEADER_LINE_HEIGHT (w
)),
567 make_number (WINDOW_RIGHT_EDGE_X (w
)
568 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
569 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
570 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
571 - WINDOW_MODE_LINE_HEIGHT (w
)));
574 /* Test if the character at column *X, row *Y is within window W.
575 If it is not, return ON_NOTHING;
576 if it is in the window's text area,
577 set *x and *y to its location relative to the upper left corner
580 if it is on the window's modeline, return ON_MODE_LINE;
581 if it is on the border between the window and its right sibling,
582 return ON_VERTICAL_BORDER.
583 if it is on a scroll bar,
584 return ON_SCROLL_BAR.
585 if it is on the window's top line, return ON_HEADER_LINE;
586 if it is in left or right fringe of the window,
587 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y
588 to window-relative coordinates;
589 if it is in the marginal area to the left/right of the window,
590 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y
591 to window-relative coordinates.
593 X and Y are frame relative pixel coordinates. */
595 static enum window_part
596 coordinates_in_window (w
, x
, y
)
597 register struct window
*w
;
600 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
601 int left_x
, right_x
, top_y
, bottom_y
;
602 enum window_part part
;
603 int ux
= FRAME_COLUMN_WIDTH (f
);
604 int x0
= WINDOW_LEFT_EDGE_X (w
);
605 int x1
= WINDOW_RIGHT_EDGE_X (w
);
606 /* The width of the area where the vertical line can be dragged.
607 (Between mode lines for instance. */
608 int grabbable_width
= ux
;
609 int lmargin_width
, rmargin_width
, text_left
, text_right
;
611 /* In what's below, we subtract 1 when computing right_x because we
612 want the rightmost pixel, which is given by left_pixel+width-1. */
613 if (w
->pseudo_window_p
)
616 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
617 top_y
= WINDOW_TOP_EDGE_Y (w
);
618 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
622 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
623 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
624 top_y
= WINDOW_TOP_EDGE_Y (w
);
625 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
628 /* Outside any interesting row? */
629 if (*y
< top_y
|| *y
>= bottom_y
)
632 /* On the mode line or header line? If it's near the start of
633 the mode or header line of window that's has a horizontal
634 sibling, say it's on the vertical line. That's to be able
635 to resize windows horizontally in case we're using toolkit
638 if (WINDOW_WANTS_MODELINE_P (w
)
639 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
643 header_vertical_border_check
:
644 /* We're somewhere on the mode line. We consider the place
645 between mode lines of horizontally adjacent mode lines
646 as the vertical border. If scroll bars on the left,
647 return the right window. */
648 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
649 || WINDOW_RIGHTMOST_P (w
))
651 if (!WINDOW_LEFTMOST_P (w
) && abs (*x
- x0
) < grabbable_width
)
652 return ON_VERTICAL_BORDER
;
656 if (abs (*x
- x1
) < grabbable_width
)
657 return ON_VERTICAL_BORDER
;
660 if (*x
< x0
|| *x
>= x1
)
663 /* Convert X and Y to window relative coordinates.
664 Mode line starts at left edge of window. */
670 if (WINDOW_WANTS_HEADER_LINE_P (w
)
671 && *y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
))
673 part
= ON_HEADER_LINE
;
674 goto header_vertical_border_check
;
677 if (*x
< x0
|| *x
>= x1
)
680 /* Outside any interesting column? */
681 if (*x
< left_x
|| *x
> right_x
)
682 return ON_SCROLL_BAR
;
684 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
685 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
687 text_left
= window_box_left (w
, TEXT_AREA
);
688 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
690 if (FRAME_WINDOW_P (f
))
692 if (!w
->pseudo_window_p
693 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
694 && !WINDOW_RIGHTMOST_P (w
)
695 && (abs (*x
- right_x
) < grabbable_width
))
696 return ON_VERTICAL_BORDER
;
700 /* Need to say "*x > right_x" rather than >=, since on character
701 terminals, the vertical line's x coordinate is right_x. */
702 if (!w
->pseudo_window_p
703 && !WINDOW_RIGHTMOST_P (w
)
704 && *x
> right_x
- ux
)
706 /* On the border on the right side of the window? Assume that
707 this area begins at RIGHT_X minus a canonical char width. */
708 return ON_VERTICAL_BORDER
;
714 if (lmargin_width
> 0
715 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
716 ? (*x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
717 : (*x
< left_x
+ lmargin_width
)))
720 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
721 *x
-= WINDOW_LEFT_FRINGE_WIDTH (w
);
723 return ON_LEFT_MARGIN
;
726 /* Convert X and Y to window-relative pixel coordinates. */
729 return ON_LEFT_FRINGE
;
732 if (*x
>= text_right
)
734 if (rmargin_width
> 0
735 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
736 ? (*x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
737 : (*x
>= right_x
- rmargin_width
)))
740 if (!WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
741 *x
-= WINDOW_RIGHT_FRINGE_WIDTH (w
);
743 return ON_RIGHT_MARGIN
;
746 /* Convert X and Y to window-relative pixel coordinates. */
747 *x
-= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
);
749 return ON_RIGHT_FRINGE
;
752 /* Everything special ruled out - must be on text area */
753 *x
-= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
);
759 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
760 Scoordinates_in_window_p
, 2, 2, 0,
761 doc
: /* Return non-nil if COORDINATES are in WINDOW.
762 COORDINATES is a cons of the form (X . Y), X and Y being distances
763 measured in characters from the upper-left corner of the frame.
764 \(0 . 0) denotes the character in the upper left corner of the
766 If COORDINATES are in the text portion of WINDOW,
767 the coordinates relative to the window are returned.
768 If they are in the mode line of WINDOW, `mode-line' is returned.
769 If they are in the top mode line of WINDOW, `header-line' is returned.
770 If they are in the left fringe of WINDOW, `left-fringe' is returned.
771 If they are in the right fringe of WINDOW, `right-fringe' is returned.
772 If they are on the border between WINDOW and its right sibling,
773 `vertical-line' is returned.
774 If they are in the windows's left or right marginal areas, `left-margin'\n\
775 or `right-margin' is returned. */)
776 (coordinates
, window
)
777 register Lisp_Object coordinates
, window
;
784 CHECK_WINDOW (window
);
785 w
= XWINDOW (window
);
786 f
= XFRAME (w
->frame
);
787 CHECK_CONS (coordinates
);
788 lx
= Fcar (coordinates
);
789 ly
= Fcdr (coordinates
);
790 CHECK_NUMBER_OR_FLOAT (lx
);
791 CHECK_NUMBER_OR_FLOAT (ly
);
792 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
793 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
795 switch (coordinates_in_window (w
, &x
, &y
))
801 /* X and Y are now window relative pixel coordinates. Convert
802 them to canonical char units before returning them. */
803 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
804 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
809 case ON_VERTICAL_BORDER
:
810 return Qvertical_line
;
818 case ON_RIGHT_FRINGE
:
819 return Qright_fringe
;
824 case ON_RIGHT_MARGIN
:
825 return Qright_margin
;
828 /* Historically we are supposed to return nil in this case. */
837 /* Callback for foreach_window, used in window_from_coordinates.
838 Check if window W contains coordinates specified by USER_DATA which
839 is actually a pointer to a struct check_window_data CW.
841 Check if window W contains coordinates *CW->x and *CW->y. If it
842 does, return W in *CW->window, as Lisp_Object, and return in
843 *CW->part the part of the window under coordinates *X,*Y. Return
844 zero from this function to stop iterating over windows. */
846 struct check_window_data
850 enum window_part
*part
;
854 check_window_containing (w
, user_data
)
858 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
859 enum window_part found
;
862 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
863 if (found
!= ON_NOTHING
)
866 XSETWINDOW (*cw
->window
, w
);
874 /* Find the window containing frame-relative pixel position X/Y and
875 return it as a Lisp_Object.
877 If X, Y is on one of the window's special `window_part' elements,
878 set *PART to the id of that element, and return X and Y converted
879 to window relative coordinates in WX and WY.
881 If there is no window under X, Y return nil and leave *PART
882 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
884 This function was previously implemented with a loop cycling over
885 windows with Fnext_window, and starting with the frame's selected
886 window. It turned out that this doesn't work with an
887 implementation of next_window using Vwindow_list, because
888 FRAME_SELECTED_WINDOW (F) is not always contained in the window
889 tree of F when this function is called asynchronously from
890 note_mouse_highlight. The original loop didn't terminate in this
894 window_from_coordinates (f
, x
, y
, part
, wx
, wy
, tool_bar_p
)
897 enum window_part
*part
;
902 struct check_window_data cw
;
903 enum window_part dummy
;
909 cw
.window
= &window
, cw
.x
= &x
, cw
.y
= &y
; cw
.part
= part
;
910 foreach_window (f
, check_window_containing
, &cw
);
912 /* If not found above, see if it's in the tool bar window, if a tool
916 && WINDOWP (f
->tool_bar_window
)
917 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
918 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), &x
, &y
)
922 window
= f
->tool_bar_window
;
931 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
932 doc
: /* Return window containing coordinates X and Y on FRAME.
933 If omitted, FRAME defaults to the currently selected frame.
934 The top left corner of the frame is considered to be row 0,
937 Lisp_Object x
, y
, frame
;
942 frame
= selected_frame
;
943 CHECK_LIVE_FRAME (frame
);
946 /* Check that arguments are integers or floats. */
947 CHECK_NUMBER_OR_FLOAT (x
);
948 CHECK_NUMBER_OR_FLOAT (y
);
950 return window_from_coordinates (f
,
951 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
952 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
953 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
954 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
958 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
959 doc
: /* Return current value of point in WINDOW.
960 For a nonselected window, this is the value point would have
961 if that window were selected.
963 Note that, when WINDOW is the selected window and its buffer
964 is also currently selected, the value returned is the same as (point).
965 It would be more strictly correct to return the `top-level' value
966 of point, outside of any save-excursion forms.
967 But that is hard to define. */)
971 register struct window
*w
= decode_window (window
);
973 if (w
== XWINDOW (selected_window
)
974 && current_buffer
== XBUFFER (w
->buffer
))
976 return Fmarker_position (w
->pointm
);
979 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
980 doc
: /* Return position at which display currently starts in WINDOW.
981 This is updated by redisplay or by calling `set-window-start'. */)
985 return Fmarker_position (decode_window (window
)->start
);
988 /* This is text temporarily removed from the doc string below.
990 This function returns nil if the position is not currently known.
991 That happens when redisplay is preempted and doesn't finish.
992 If in that case you want to compute where the end of the window would
993 have been if redisplay had finished, do this:
995 (goto-char (window-start window))
996 (vertical-motion (1- (window-height window)) window)
999 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1000 doc
: /* Return position at which display currently ends in WINDOW.
1001 This is updated by redisplay, when it runs to completion.
1002 Simply changing the buffer text or setting `window-start'
1003 does not update this value.
1004 Return nil if there is no recorded value. \(This can happen if the
1005 last redisplay of WINDOW was preempted, and did not finish.)
1006 If UPDATE is non-nil, compute the up-to-date position
1007 if it isn't already recorded. */)
1009 Lisp_Object window
, update
;
1012 struct window
*w
= decode_window (window
);
1018 #if 0 /* This change broke some things. We should make it later. */
1019 /* If we don't know the end position, return nil.
1020 The user can compute it with vertical-motion if he wants to.
1021 It would be nicer to do it automatically,
1022 but that's so slow that it would probably bother people. */
1023 if (NILP (w
->window_end_valid
))
1028 && ! (! NILP (w
->window_end_valid
)
1029 && XFASTINT (w
->last_modified
) >= MODIFF
))
1031 struct text_pos startp
;
1033 struct buffer
*old_buffer
= NULL
, *b
= XBUFFER (buf
);
1035 /* In case W->start is out of the range, use something
1036 reasonable. This situation occurred when loading a file with
1037 `-l' containing a call to `rmail' with subsequent other
1038 commands. At the end, W->start happened to be BEG, while
1039 rmail had already narrowed the buffer. */
1040 if (XMARKER (w
->start
)->charpos
< BEGV
)
1041 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1042 else if (XMARKER (w
->start
)->charpos
> ZV
)
1043 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1045 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1047 /* Cannot use Fvertical_motion because that function doesn't
1048 cope with variable-height lines. */
1049 if (b
!= current_buffer
)
1051 old_buffer
= current_buffer
;
1052 set_buffer_internal (b
);
1055 start_display (&it
, w
, startp
);
1056 move_it_vertically (&it
, window_box_height (w
));
1057 if (it
.current_y
< it
.last_visible_y
)
1058 move_it_past_eol (&it
);
1059 value
= make_number (IT_CHARPOS (it
));
1062 set_buffer_internal (old_buffer
);
1065 XSETINT (value
, BUF_Z (XBUFFER (buf
)) - XFASTINT (w
->window_end_pos
));
1070 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1071 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1074 Lisp_Object window
, pos
;
1076 register struct window
*w
= decode_window (window
);
1078 CHECK_NUMBER_COERCE_MARKER (pos
);
1079 if (w
== XWINDOW (selected_window
)
1080 && XBUFFER (w
->buffer
) == current_buffer
)
1083 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1085 /* We have to make sure that redisplay updates the window to show
1086 the new value of point. */
1087 if (!EQ (window
, selected_window
))
1088 ++windows_or_buffers_changed
;
1093 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1094 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1096 Optional third arg NOFORCE non-nil inhibits next redisplay
1097 from overriding motion of point in order to display at this exact start. */)
1098 (window
, pos
, noforce
)
1099 Lisp_Object window
, pos
, noforce
;
1101 register struct window
*w
= decode_window (window
);
1103 CHECK_NUMBER_COERCE_MARKER (pos
);
1104 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1105 /* this is not right, but much easier than doing what is right. */
1106 w
->start_at_line_beg
= Qnil
;
1108 w
->force_start
= Qt
;
1109 w
->update_mode_line
= Qt
;
1110 XSETFASTINT (w
->last_modified
, 0);
1111 XSETFASTINT (w
->last_overlay_modified
, 0);
1112 if (!EQ (window
, selected_window
))
1113 windows_or_buffers_changed
++;
1118 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1120 doc
: /* Return WINDOW's dedicated object, usually t or nil.
1121 See also `set-window-dedicated-p'. */)
1125 return decode_window (window
)->dedicated
;
1128 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1129 Sset_window_dedicated_p
, 2, 2, 0,
1130 doc
: /* Control whether WINDOW is dedicated to the buffer it displays.
1131 If it is dedicated, Emacs will not automatically change
1132 which buffer appears in it.
1133 The second argument is the new value for the dedication flag;
1134 non-nil means yes. */)
1136 Lisp_Object window
, arg
;
1138 register struct window
*w
= decode_window (window
);
1142 return w
->dedicated
;
1145 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1147 doc
: /* Return the display-table that WINDOW is using. */)
1151 return decode_window (window
)->display_table
;
1154 /* Get the display table for use on window W. This is either W's
1155 display table or W's buffer's display table. Ignore the specified
1156 tables if they are not valid; if no valid table is specified,
1159 struct Lisp_Char_Table
*
1160 window_display_table (w
)
1163 struct Lisp_Char_Table
*dp
= NULL
;
1165 if (DISP_TABLE_P (w
->display_table
))
1166 dp
= XCHAR_TABLE (w
->display_table
);
1167 else if (BUFFERP (w
->buffer
))
1169 struct buffer
*b
= XBUFFER (w
->buffer
);
1171 if (DISP_TABLE_P (b
->display_table
))
1172 dp
= XCHAR_TABLE (b
->display_table
);
1173 else if (DISP_TABLE_P (Vstandard_display_table
))
1174 dp
= XCHAR_TABLE (Vstandard_display_table
);
1180 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1181 doc
: /* Set WINDOW's display-table to TABLE. */)
1183 register Lisp_Object window
, table
;
1185 register struct window
*w
;
1187 w
= decode_window (window
);
1188 w
->display_table
= table
;
1192 /* Record info on buffer window w is displaying
1193 when it is about to cease to display that buffer. */
1196 register struct window
*w
;
1203 if (b
!= XMARKER (w
->pointm
)->buffer
)
1207 if (w
== XWINDOW (selected_window
)
1208 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1209 /* Do this except when the selected window's buffer
1210 is being removed from some other window. */
1212 /* last_window_start records the start position that this buffer
1213 had in the last window to be disconnected from it.
1214 Now that this statement is unconditional,
1215 it is possible for the buffer to be displayed in the
1216 selected window, while last_window_start reflects another
1217 window which was recently showing the same buffer.
1218 Some people might say that might be a good thing. Let's see. */
1219 b
->last_window_start
= marker_position (w
->start
);
1221 /* Point in the selected window's buffer
1222 is actually stored in that buffer, and the window's pointm isn't used.
1223 So don't clobber point in that buffer. */
1224 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1225 /* This line helps to fix Horsley's testbug.el bug. */
1226 && !(WINDOWP (b
->last_selected_window
)
1227 && w
!= XWINDOW (b
->last_selected_window
)
1228 && EQ (buf
, XWINDOW (b
->last_selected_window
)->buffer
)))
1229 temp_set_point_both (b
,
1230 clip_to_bounds (BUF_BEGV (b
),
1231 XMARKER (w
->pointm
)->charpos
,
1233 clip_to_bounds (BUF_BEGV_BYTE (b
),
1234 marker_byte_position (w
->pointm
),
1237 if (WINDOWP (b
->last_selected_window
)
1238 && w
== XWINDOW (b
->last_selected_window
))
1239 b
->last_selected_window
= Qnil
;
1242 /* Put replacement into the window structure in place of old. */
1244 replace_window (old
, replacement
)
1245 Lisp_Object old
, replacement
;
1247 register Lisp_Object tem
;
1248 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
1250 /* If OLD is its frame's root_window, then replacement is the new
1251 root_window for that frame. */
1253 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1254 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
1256 p
->left_col
= o
->left_col
;
1257 p
->top_line
= o
->top_line
;
1258 p
->total_cols
= o
->total_cols
;
1259 p
->total_lines
= o
->total_lines
;
1260 p
->desired_matrix
= p
->current_matrix
= 0;
1262 bzero (&p
->cursor
, sizeof (p
->cursor
));
1263 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
1264 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
1265 p
->phys_cursor_type
= -1;
1266 p
->phys_cursor_width
= -1;
1267 p
->must_be_updated_p
= 0;
1268 p
->pseudo_window_p
= 0;
1269 XSETFASTINT (p
->window_end_vpos
, 0);
1270 XSETFASTINT (p
->window_end_pos
, 0);
1271 p
->window_end_valid
= Qnil
;
1272 p
->frozen_window_start_p
= 0;
1273 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
1275 p
->next
= tem
= o
->next
;
1277 XWINDOW (tem
)->prev
= replacement
;
1279 p
->prev
= tem
= o
->prev
;
1281 XWINDOW (tem
)->next
= replacement
;
1283 p
->parent
= tem
= o
->parent
;
1286 if (EQ (XWINDOW (tem
)->vchild
, old
))
1287 XWINDOW (tem
)->vchild
= replacement
;
1288 if (EQ (XWINDOW (tem
)->hchild
, old
))
1289 XWINDOW (tem
)->hchild
= replacement
;
1292 /*** Here, if replacement is a vertical combination
1293 and so is its new parent, we should make replacement's
1294 children be children of that parent instead. ***/
1297 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
1298 doc
: /* Remove WINDOW from the display. Default is selected window. */)
1300 register Lisp_Object window
;
1302 delete_window (window
);
1304 if (! NILP (Vwindow_configuration_change_hook
)
1305 && ! NILP (Vrun_hooks
))
1306 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
1312 delete_window (window
)
1313 register Lisp_Object window
;
1315 register Lisp_Object tem
, parent
, sib
;
1316 register struct window
*p
;
1317 register struct window
*par
;
1320 /* Because this function is called by other C code on non-leaf
1321 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1322 so we can't decode_window here. */
1324 window
= selected_window
;
1326 CHECK_WINDOW (window
);
1327 p
= XWINDOW (window
);
1329 /* It's okay to delete an already-deleted window. */
1330 if (NILP (p
->buffer
)
1332 && NILP (p
->vchild
))
1337 error ("Attempt to delete minibuffer or sole ordinary window");
1338 par
= XWINDOW (parent
);
1340 windows_or_buffers_changed
++;
1341 Vwindow_list
= Qnil
;
1342 f
= XFRAME (WINDOW_FRAME (p
));
1343 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
1345 /* Are we trying to delete any frame's selected window? */
1347 Lisp_Object swindow
, pwindow
;
1349 /* See if the frame's selected window is either WINDOW
1350 or any subwindow of it, by finding all that window's parents
1351 and comparing each one with WINDOW. */
1352 swindow
= FRAME_SELECTED_WINDOW (f
);
1357 while (!NILP (pwindow
))
1359 if (EQ (window
, pwindow
))
1361 pwindow
= XWINDOW (pwindow
)->parent
;
1364 /* If the window being deleted is not a parent of SWINDOW,
1365 then SWINDOW is ok as the new selected window. */
1366 if (!EQ (window
, pwindow
))
1368 /* Otherwise, try another window for SWINDOW. */
1369 swindow
= Fnext_window (swindow
, Qlambda
, Qnil
);;
1371 /* If we get back to the frame's selected window,
1372 it means there was no acceptable alternative,
1373 so we cannot delete. */
1374 if (EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1375 error ("Cannot delete window");
1378 /* If we need to change SWINDOW, do it. */
1379 if (! EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1381 /* If we're about to delete the selected window on the
1382 selected frame, then we should use Fselect_window to select
1383 the new window. On the other hand, if we're about to
1384 delete the selected window on any other frame, we shouldn't do
1385 anything but set the frame's selected_window slot. */
1386 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
1387 Fselect_window (swindow
, Qnil
);
1389 FRAME_SELECTED_WINDOW (f
) = swindow
;
1394 /* tem is null for dummy parent windows
1395 (which have inferiors but not any contents themselves) */
1399 unchain_marker (XMARKER (p
->pointm
));
1400 unchain_marker (XMARKER (p
->start
));
1403 /* Free window glyph matrices. It is sure that they are allocated
1404 again when ADJUST_GLYPHS is called. Block input so that expose
1405 events and other events that access glyph matrices are not
1406 processed while we are changing them. */
1408 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)));
1412 XWINDOW (tem
)->prev
= p
->prev
;
1416 XWINDOW (tem
)->next
= p
->next
;
1418 if (EQ (window
, par
->hchild
))
1419 par
->hchild
= p
->next
;
1420 if (EQ (window
, par
->vchild
))
1421 par
->vchild
= p
->next
;
1423 /* Find one of our siblings to give our space to. */
1427 /* If p gives its space to its next sibling, that sibling needs
1428 to have its top/left side pulled back to where p's is.
1429 set_window_{height,width} will re-position the sibling's
1432 XWINDOW (sib
)->top_line
= p
->top_line
;
1433 XWINDOW (sib
)->left_col
= p
->left_col
;
1436 /* Stretch that sibling. */
1437 if (!NILP (par
->vchild
))
1438 set_window_height (sib
,
1439 XFASTINT (XWINDOW (sib
)->total_lines
) + XFASTINT (p
->total_lines
),
1441 if (!NILP (par
->hchild
))
1442 set_window_width (sib
,
1443 XFASTINT (XWINDOW (sib
)->total_cols
) + XFASTINT (p
->total_cols
),
1446 /* If parent now has only one child,
1447 put the child into the parent's place. */
1451 if (NILP (XWINDOW (tem
)->next
))
1452 replace_window (parent
, tem
);
1454 /* Since we may be deleting combination windows, we must make sure that
1455 not only p but all its children have been marked as deleted. */
1456 if (! NILP (p
->hchild
))
1457 delete_all_subwindows (XWINDOW (p
->hchild
));
1458 else if (! NILP (p
->vchild
))
1459 delete_all_subwindows (XWINDOW (p
->vchild
));
1461 /* Mark this window as deleted. */
1462 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1464 /* Adjust glyph matrices. */
1471 /***********************************************************************
1473 ***********************************************************************/
1475 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1476 pointer. This is a callback function for foreach_window, used in
1477 function window_list. */
1480 add_window_to_list (w
, user_data
)
1484 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1486 XSETWINDOW (window
, w
);
1487 *list
= Fcons (window
, *list
);
1492 /* Return a list of all windows, for use by next_window. If
1493 Vwindow_list is a list, return that list. Otherwise, build a new
1494 list, cache it in Vwindow_list, and return that. */
1499 if (!CONSP (Vwindow_list
))
1503 Vwindow_list
= Qnil
;
1504 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1506 Lisp_Object args
[2];
1508 /* We are visiting windows in canonical order, and add
1509 new windows at the front of args[1], which means we
1510 have to reverse this list at the end. */
1512 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1513 args
[0] = Vwindow_list
;
1514 args
[1] = Fnreverse (args
[1]);
1515 Vwindow_list
= Fnconc (2, args
);
1519 return Vwindow_list
;
1523 /* Value is non-zero if WINDOW satisfies the constraints given by
1524 OWINDOW, MINIBUF and ALL_FRAMES.
1526 MINIBUF t means WINDOW may be minibuffer windows.
1527 `lambda' means WINDOW may not be a minibuffer window.
1528 a window means a specific minibuffer window
1530 ALL_FRAMES t means search all frames,
1531 nil means search just current frame,
1532 `visible' means search just visible frames,
1533 0 means search visible and iconified frames,
1534 a window means search the frame that window belongs to,
1535 a frame means consider windows on that frame, only. */
1538 candidate_window_p (window
, owindow
, minibuf
, all_frames
)
1539 Lisp_Object window
, owindow
, minibuf
, all_frames
;
1541 struct window
*w
= XWINDOW (window
);
1542 struct frame
*f
= XFRAME (w
->frame
);
1543 int candidate_p
= 1;
1545 if (!BUFFERP (w
->buffer
))
1547 else if (MINI_WINDOW_P (w
)
1548 && (EQ (minibuf
, Qlambda
)
1549 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
1551 /* If MINIBUF is `lambda' don't consider any mini-windows.
1552 If it is a window, consider only that one. */
1555 else if (EQ (all_frames
, Qt
))
1557 else if (NILP (all_frames
))
1559 xassert (WINDOWP (owindow
));
1560 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
1562 else if (EQ (all_frames
, Qvisible
))
1564 FRAME_SAMPLE_VISIBILITY (f
);
1565 candidate_p
= FRAME_VISIBLE_P (f
);
1567 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
1569 FRAME_SAMPLE_VISIBILITY (f
);
1570 candidate_p
= FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
);
1572 else if (WINDOWP (all_frames
))
1573 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
1574 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
1575 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
1576 else if (FRAMEP (all_frames
))
1577 candidate_p
= EQ (all_frames
, w
->frame
);
1583 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1584 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1588 decode_next_window_args (window
, minibuf
, all_frames
)
1589 Lisp_Object
*window
, *minibuf
, *all_frames
;
1592 *window
= selected_window
;
1594 CHECK_LIVE_WINDOW (*window
);
1596 /* MINIBUF nil may or may not include minibuffers. Decide if it
1598 if (NILP (*minibuf
))
1599 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
1600 else if (!EQ (*minibuf
, Qt
))
1603 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1604 => count none of them, or a specific minibuffer window (the
1605 active one) to count. */
1607 /* ALL_FRAMES nil doesn't specify which frames to include. */
1608 if (NILP (*all_frames
))
1609 *all_frames
= (!EQ (*minibuf
, Qlambda
)
1610 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
1612 else if (EQ (*all_frames
, Qvisible
))
1614 else if (EQ (*all_frames
, make_number (0)))
1616 else if (FRAMEP (*all_frames
))
1618 else if (!EQ (*all_frames
, Qt
))
1621 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1622 search just current frame, `visible' meaning search just visible
1623 frames, 0 meaning search visible and iconified frames, or a
1624 window, meaning search the frame that window belongs to, or a
1625 frame, meaning consider windows on that frame, only. */
1629 /* Return the next or previous window of WINDOW in canonical ordering
1630 of windows. NEXT_P non-zero means return the next window. See the
1631 documentation string of next-window for the meaning of MINIBUF and
1635 next_window (window
, minibuf
, all_frames
, next_p
)
1636 Lisp_Object window
, minibuf
, all_frames
;
1639 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1641 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1642 return the first window on the frame. */
1643 if (FRAMEP (all_frames
)
1644 && !EQ (all_frames
, XWINDOW (window
)->frame
))
1645 return Fframe_first_window (all_frames
);
1651 /* Find WINDOW in the list of all windows. */
1652 list
= Fmemq (window
, window_list ());
1654 /* Scan forward from WINDOW to the end of the window list. */
1656 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
1657 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1660 /* Scan from the start of the window list up to WINDOW. */
1662 for (list
= Vwindow_list
;
1663 CONSP (list
) && !EQ (XCAR (list
), window
);
1665 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1669 window
= XCAR (list
);
1673 Lisp_Object candidate
, list
;
1675 /* Scan through the list of windows for candidates. If there are
1676 candidate windows in front of WINDOW, the last one of these
1677 is the one we want. If there are candidates following WINDOW
1678 in the list, again the last one of these is the one we want. */
1680 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
1682 if (EQ (XCAR (list
), window
))
1684 if (WINDOWP (candidate
))
1687 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
1689 candidate
= XCAR (list
);
1692 if (WINDOWP (candidate
))
1700 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
1701 doc
: /* Return next window after WINDOW in canonical ordering of windows.
1702 If omitted, WINDOW defaults to the selected window.
1704 Optional second arg MINIBUF t means count the minibuffer window even
1705 if not active. MINIBUF nil or omitted means count the minibuffer iff
1706 it is active. MINIBUF neither t nor nil means not to count the
1707 minibuffer even if it is active.
1709 Several frames may share a single minibuffer; if the minibuffer
1710 counts, all windows on all frames that share that minibuffer count
1711 too. Therefore, `next-window' can be used to iterate through the
1712 set of windows even when the minibuffer is on another frame. If the
1713 minibuffer does not count, only windows from WINDOW's frame count.
1715 Optional third arg ALL-FRAMES t means include windows on all frames.
1716 ALL-FRAMES nil or omitted means cycle within the frames as specified
1717 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1718 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1719 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1720 Anything else means restrict to WINDOW's frame.
1722 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1723 `next-window' to iterate through the entire cycle of acceptable
1724 windows, eventually ending up back at the window you started with.
1725 `previous-window' traverses the same cycle, in the reverse order. */)
1726 (window
, minibuf
, all_frames
)
1727 Lisp_Object window
, minibuf
, all_frames
;
1729 return next_window (window
, minibuf
, all_frames
, 1);
1733 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1734 doc
: /* Return the window preceding WINDOW in canonical ordering of windows.
1735 If omitted, WINDOW defaults to the selected window.
1737 Optional second arg MINIBUF t means count the minibuffer window even
1738 if not active. MINIBUF nil or omitted means count the minibuffer iff
1739 it is active. MINIBUF neither t nor nil means not to count the
1740 minibuffer even if it is active.
1742 Several frames may share a single minibuffer; if the minibuffer
1743 counts, all windows on all frames that share that minibuffer count
1744 too. Therefore, `previous-window' can be used to iterate through
1745 the set of windows even when the minibuffer is on another frame. If
1746 the minibuffer does not count, only windows from WINDOW's frame count
1748 Optional third arg ALL-FRAMES t means include windows on all frames.
1749 ALL-FRAMES nil or omitted means cycle within the frames as specified
1750 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1751 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1752 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1753 Anything else means restrict to WINDOW's frame.
1755 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1756 `previous-window' to iterate through the entire cycle of acceptable
1757 windows, eventually ending up back at the window you started with.
1758 `next-window' traverses the same cycle, in the reverse order. */)
1759 (window
, minibuf
, all_frames
)
1760 Lisp_Object window
, minibuf
, all_frames
;
1762 return next_window (window
, minibuf
, all_frames
, 0);
1766 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1767 doc
: /* Select the ARG'th different window on this frame.
1768 All windows on current frame are arranged in a cyclic order.
1769 This command selects the window ARG steps away in that order.
1770 A negative ARG moves in the opposite order. The optional second
1771 argument ALL_FRAMES has the same meaning as in `next-window', which see. */)
1773 Lisp_Object arg
, all_frames
;
1779 window
= selected_window
;
1781 for (i
= XINT (arg
); i
> 0; --i
)
1782 window
= Fnext_window (window
, Qnil
, all_frames
);
1784 window
= Fprevious_window (window
, Qnil
, all_frames
);
1786 Fselect_window (window
, Qnil
);
1791 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
1792 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
1793 FRAME nil or omitted means use the selected frame.
1794 WINDOW nil or omitted means use the selected window.
1795 MINIBUF t means include the minibuffer window, even if it isn't active.
1796 MINIBUF nil or omitted means include the minibuffer window only
1798 MINIBUF neither nil nor t means never include the minibuffer window. */)
1799 (frame
, minibuf
, window
)
1800 Lisp_Object frame
, minibuf
, window
;
1803 window
= selected_window
;
1805 frame
= selected_frame
;
1807 if (!EQ (frame
, XWINDOW (window
)->frame
))
1808 error ("Window is on a different frame");
1810 return window_list_1 (window
, minibuf
, frame
);
1814 /* Return a list of windows in canonical ordering. Arguments are like
1815 for `next-window'. */
1818 window_list_1 (window
, minibuf
, all_frames
)
1819 Lisp_Object window
, minibuf
, all_frames
;
1821 Lisp_Object tail
, list
, rest
;
1823 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1826 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
1827 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
1828 list
= Fcons (XCAR (tail
), list
);
1830 /* Rotate the list to start with WINDOW. */
1831 list
= Fnreverse (list
);
1832 rest
= Fmemq (window
, list
);
1833 if (!NILP (rest
) && !EQ (rest
, list
))
1835 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
1837 XSETCDR (tail
, Qnil
);
1838 list
= nconc2 (rest
, list
);
1845 /* Look at all windows, performing an operation specified by TYPE
1847 If FRAMES is Qt, look at all frames;
1848 Qnil, look at just the selected frame;
1849 Qvisible, look at visible frames;
1850 a frame, just look at windows on that frame.
1851 If MINI is non-zero, perform the operation on minibuffer windows too. */
1856 GET_BUFFER_WINDOW
, /* Arg is buffer */
1857 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1858 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1859 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1861 UNSHOW_BUFFER
, /* Arg is buffer */
1862 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
1867 window_loop (type
, obj
, mini
, frames
)
1868 enum window_loop type
;
1869 Lisp_Object obj
, frames
;
1872 Lisp_Object window
, windows
, best_window
, frame_arg
;
1874 struct gcpro gcpro1
;
1876 /* If we're only looping through windows on a particular frame,
1877 frame points to that frame. If we're looping through windows
1878 on all frames, frame is 0. */
1879 if (FRAMEP (frames
))
1880 f
= XFRAME (frames
);
1881 else if (NILP (frames
))
1882 f
= SELECTED_FRAME ();
1887 frame_arg
= Qlambda
;
1888 else if (EQ (frames
, make_number (0)))
1890 else if (EQ (frames
, Qvisible
))
1895 /* frame_arg is Qlambda to stick to one frame,
1896 Qvisible to consider all visible frames,
1899 /* Pick a window to start with. */
1903 window
= FRAME_SELECTED_WINDOW (f
);
1905 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
1907 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
1911 for (; CONSP (windows
); windows
= CDR (windows
))
1915 window
= XCAR (windows
);
1916 w
= XWINDOW (window
);
1918 /* Note that we do not pay attention here to whether the frame
1919 is visible, since Fwindow_list skips non-visible frames if
1920 that is desired, under the control of frame_arg. */
1921 if (!MINI_WINDOW_P (w
)
1922 /* For UNSHOW_BUFFER, we must always consider all windows. */
1923 || type
== UNSHOW_BUFFER
1924 || (mini
&& minibuf_level
> 0))
1927 case GET_BUFFER_WINDOW
:
1928 if (EQ (w
->buffer
, obj
)
1929 /* Don't find any minibuffer window
1930 except the one that is currently in use. */
1931 && (MINI_WINDOW_P (w
)
1932 ? EQ (window
, minibuf_window
)
1935 if (NILP (best_window
))
1936 best_window
= window
;
1937 else if (EQ (window
, selected_window
))
1938 /* For compatibility with 20.x, prefer to return
1940 best_window
= window
;
1944 case GET_LRU_WINDOW
:
1945 /* t as arg means consider only full-width windows */
1946 if (!NILP (obj
) && !WINDOW_FULL_WIDTH_P (w
))
1948 /* Ignore dedicated windows and minibuffers. */
1949 if (MINI_WINDOW_P (w
) || EQ (w
->dedicated
, Qt
))
1951 if (NILP (best_window
)
1952 || (XFASTINT (XWINDOW (best_window
)->use_time
)
1953 > XFASTINT (w
->use_time
)))
1954 best_window
= window
;
1957 case DELETE_OTHER_WINDOWS
:
1958 if (!EQ (window
, obj
))
1959 Fdelete_window (window
);
1962 case DELETE_BUFFER_WINDOWS
:
1963 if (EQ (w
->buffer
, obj
))
1965 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1967 /* If this window is dedicated, and in a frame of its own,
1969 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
1970 && !NILP (w
->dedicated
)
1971 && other_visible_frames (f
))
1973 /* Skip the other windows on this frame.
1974 There might be one, the minibuffer! */
1975 while (CONSP (XCDR (windows
))
1976 && EQ (XWINDOW (XCAR (windows
))->frame
,
1977 XWINDOW (XCAR (XCDR (windows
)))->frame
))
1978 windows
= XCDR (windows
);
1980 /* Now we can safely delete the frame. */
1981 Fdelete_frame (w
->frame
, Qnil
);
1983 else if (NILP (w
->parent
))
1985 /* If we're deleting the buffer displayed in the
1986 only window on the frame, find a new buffer to
1989 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
1990 Fset_window_buffer (window
, buffer
, Qnil
);
1991 if (EQ (window
, selected_window
))
1992 Fset_buffer (w
->buffer
);
1995 Fdelete_window (window
);
1999 case GET_LARGEST_WINDOW
:
2001 /* Ignore dedicated windows and minibuffers. */
2002 if (MINI_WINDOW_P (w
) || EQ (w
->dedicated
, Qt
))
2005 if (NILP (best_window
))
2006 best_window
= window
;
2009 struct window
*b
= XWINDOW (best_window
);
2010 if (XFASTINT (w
->total_lines
) * XFASTINT (w
->total_cols
)
2011 > XFASTINT (b
->total_lines
) * XFASTINT (b
->total_cols
))
2012 best_window
= window
;
2018 if (EQ (w
->buffer
, obj
))
2021 struct frame
*f
= XFRAME (w
->frame
);
2023 /* Find another buffer to show in this window. */
2024 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2026 /* If this window is dedicated, and in a frame of its own,
2028 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
2029 && !NILP (w
->dedicated
)
2030 && other_visible_frames (f
))
2032 /* Skip the other windows on this frame.
2033 There might be one, the minibuffer! */
2034 while (CONSP (XCDR (windows
))
2035 && EQ (XWINDOW (XCAR (windows
))->frame
,
2036 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2037 windows
= XCDR (windows
);
2039 /* Now we can safely delete the frame. */
2040 Fdelete_frame (w
->frame
, Qnil
);
2042 else if (!NILP (w
->dedicated
) && !NILP (w
->parent
))
2045 XSETWINDOW (window
, w
);
2046 /* If this window is dedicated and not the only window
2047 in its frame, then kill it. */
2048 Fdelete_window (window
);
2052 /* Otherwise show a different buffer in the window. */
2053 w
->dedicated
= Qnil
;
2054 Fset_window_buffer (window
, buffer
, Qnil
);
2055 if (EQ (window
, selected_window
))
2056 Fset_buffer (w
->buffer
);
2061 case REDISPLAY_BUFFER_WINDOWS
:
2062 if (EQ (w
->buffer
, obj
))
2064 mark_window_display_accurate (window
, 0);
2065 w
->update_mode_line
= Qt
;
2066 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2067 ++update_mode_lines
;
2068 best_window
= window
;
2072 /* Check for a window that has a killed buffer. */
2073 case CHECK_ALL_WINDOWS
:
2074 if (! NILP (w
->buffer
)
2075 && NILP (XBUFFER (w
->buffer
)->name
))
2079 case WINDOW_LOOP_UNUSED
:
2088 /* Used for debugging. Abort if any window has a dead buffer. */
2091 check_all_windows ()
2093 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2096 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 1, 0,
2097 doc
: /* Return the window least recently selected or used for display.
2098 Return a full-width window if possible.
2099 A minibuffer window is never a candidate.
2100 A dedicated window is never a candidate, so if all windows are dedicated,
2102 If optional argument FRAME is `visible', search all visible frames.
2103 If FRAME is 0, search all visible and iconified frames.
2104 If FRAME is t, search all frames.
2105 If FRAME is nil, search only the selected frame.
2106 If FRAME is a frame, search only that frame. */)
2110 register Lisp_Object w
;
2111 /* First try for a window that is full-width */
2112 w
= window_loop (GET_LRU_WINDOW
, Qt
, 0, frame
);
2113 if (!NILP (w
) && !EQ (w
, selected_window
))
2115 /* If none of them, try the rest */
2116 return window_loop (GET_LRU_WINDOW
, Qnil
, 0, frame
);
2119 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 1, 0,
2120 doc
: /* Return the largest window in area.
2121 A minibuffer window is never a candidate.
2122 A dedicated window is never a candidate, so if all windows are dedicated,
2124 If optional argument FRAME is `visible', search all visible frames.
2125 If FRAME is 0, search all visible and iconified frames.
2126 If FRAME is t, search all frames.
2127 If FRAME is nil, search only the selected frame.
2128 If FRAME is a frame, search only that frame. */)
2132 return window_loop (GET_LARGEST_WINDOW
, Qnil
, 0,
2136 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
2137 doc
: /* Return a window currently displaying BUFFER, or nil if none.
2138 BUFFER can be a buffer or a buffer name.
2139 If optional argument FRAME is `visible', search all visible frames.
2140 If optional argument FRAME is 0, search all visible and iconified frames.
2141 If FRAME is t, search all frames.
2142 If FRAME is nil, search only the selected frame.
2143 If FRAME is a frame, search only that frame. */)
2145 Lisp_Object buffer
, frame
;
2147 buffer
= Fget_buffer (buffer
);
2148 if (BUFFERP (buffer
))
2149 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
2154 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
2156 doc
: /* Make WINDOW (or the selected window) fill its frame.
2157 Only the frame WINDOW is on is affected.
2158 This function tries to reduce display jumps
2159 by keeping the text previously visible in WINDOW
2160 in the same place on the frame. Doing this depends on
2161 the value of (window-start WINDOW), so if calling this function
2162 in a program gives strange scrolling, make sure the window-start
2163 value is reasonable when this function is called. */)
2172 window
= selected_window
;
2174 CHECK_LIVE_WINDOW (window
);
2175 w
= XWINDOW (window
);
2177 startpos
= marker_position (w
->start
);
2178 top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2180 if (MINI_WINDOW_P (w
) && top
> 0)
2181 error ("Can't expand minibuffer to full frame");
2183 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
2185 /* Try to minimize scrolling, by setting the window start to the point
2186 will cause the text at the old window start to be at the same place
2187 on the frame. But don't try to do this if the window start is
2188 outside the visible portion (as might happen when the display is
2189 not current, due to typeahead). */
2190 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2192 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2193 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2195 struct position pos
;
2196 struct buffer
*obuf
= current_buffer
;
2198 Fset_buffer (w
->buffer
);
2199 /* This computation used to temporarily move point, but that can
2200 have unwanted side effects due to text properties. */
2201 pos
= *vmotion (startpos
, -top
, w
);
2203 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2204 w
->window_end_valid
= Qnil
;
2205 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
2206 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
2208 /* We need to do this, so that the window-scroll-functions
2210 w
->optional_new_start
= Qt
;
2212 set_buffer_internal (obuf
);
2218 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
2219 1, 2, "bDelete windows on (buffer): ",
2220 doc
: /* Delete all windows showing BUFFER.
2221 BUFFER must be a buffer or the name of an existing buffer.
2222 Optional second argument FRAME controls which frames are affected.
2223 If optional argument FRAME is `visible', search all visible frames.
2224 If FRAME is 0, search all visible and iconified frames.
2225 If FRAME is nil, search all frames.
2226 If FRAME is t, search only the selected frame.
2227 If FRAME is a frame, search only that frame. */)
2229 Lisp_Object buffer
, frame
;
2231 /* FRAME uses t and nil to mean the opposite of what window_loop
2235 else if (EQ (frame
, Qt
))
2240 buffer
= Fget_buffer (buffer
);
2241 CHECK_BUFFER (buffer
);
2242 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
2248 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
2249 Sreplace_buffer_in_windows
,
2250 1, 1, "bReplace buffer in windows: ",
2251 doc
: /* Replace BUFFER with some other buffer in all windows showing it.
2252 BUFFER may be a buffer or the name of an existing buffer. */)
2258 buffer
= Fget_buffer (buffer
);
2259 CHECK_BUFFER (buffer
);
2260 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
2265 /* Replace BUFFER with some other buffer in all windows
2266 of all frames, even those on other keyboards. */
2269 replace_buffer_in_all_windows (buffer
)
2273 Lisp_Object tail
, frame
;
2275 /* A single call to window_loop won't do the job
2276 because it only considers frames on the current keyboard.
2277 So loop manually over frames, and handle each one. */
2278 FOR_EACH_FRAME (tail
, frame
)
2279 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
2281 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
2285 /* Set the height of WINDOW and all its inferiors. */
2287 /* The smallest acceptable dimensions for a window. Anything smaller
2288 might crash Emacs. */
2290 #define MIN_SAFE_WINDOW_WIDTH (2)
2291 #define MIN_SAFE_WINDOW_HEIGHT (1)
2293 /* Make sure that window_min_height and window_min_width are
2294 not too small; if they are, set them to safe minima. */
2297 check_min_window_sizes ()
2299 /* Smaller values might permit a crash. */
2300 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
2301 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
2302 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
2303 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
2306 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2307 minimum allowable size. */
2310 check_frame_size (frame
, rows
, cols
)
2314 /* For height, we have to see:
2315 how many windows the frame has at minimum (one or two),
2316 and whether it has a menu bar or other special stuff at the top. */
2318 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
2319 ? MIN_SAFE_WINDOW_HEIGHT
2320 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
2322 if (FRAME_TOP_MARGIN (frame
) > 0)
2323 min_height
+= FRAME_TOP_MARGIN (frame
);
2325 if (*rows
< min_height
)
2327 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2328 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2332 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2333 check if W's width can be changed, otherwise check W's height.
2334 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2335 siblings, too. If none of the siblings is resizable, WINDOW isn't
2339 window_fixed_size_p (w
, width_p
, check_siblings_p
)
2341 int width_p
, check_siblings_p
;
2346 if (!NILP (w
->hchild
))
2348 c
= XWINDOW (w
->hchild
);
2352 /* A horiz. combination is fixed-width if all of if its
2354 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2355 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2356 fixed_p
= c
== NULL
;
2360 /* A horiz. combination is fixed-height if one of if its
2362 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2363 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2364 fixed_p
= c
!= NULL
;
2367 else if (!NILP (w
->vchild
))
2369 c
= XWINDOW (w
->vchild
);
2373 /* A vert. combination is fixed-width if one of if its
2375 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2376 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2377 fixed_p
= c
!= NULL
;
2381 /* A vert. combination is fixed-height if all of if its
2383 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2384 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2385 fixed_p
= c
== NULL
;
2388 else if (BUFFERP (w
->buffer
))
2390 if (w
->height_fixed_p
&& !width_p
)
2394 struct buffer
*old
= current_buffer
;
2397 current_buffer
= XBUFFER (w
->buffer
);
2398 val
= find_symbol_value (Qwindow_size_fixed
);
2399 current_buffer
= old
;
2402 if (!EQ (val
, Qunbound
))
2404 fixed_p
= !NILP (val
);
2407 && ((EQ (val
, Qheight
) && width_p
)
2408 || (EQ (val
, Qwidth
) && !width_p
)))
2413 /* Can't tell if this one is resizable without looking at
2414 siblings. If all siblings are fixed-size this one is too. */
2415 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
2419 for (child
= w
->prev
; !NILP (child
); child
= XWINDOW (child
)->prev
)
2420 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2424 for (child
= w
->next
; !NILP (child
); child
= XWINDOW (child
)->next
)
2425 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2439 /* Return the minimum size of window W, not taking fixed-width windows
2440 into account. WIDTH_P non-zero means return the minimum width,
2441 otherwise return the minimum height. If W is a combination window,
2442 compute the minimum size from the minimum sizes of W's children. */
2445 window_min_size_1 (w
, width_p
)
2452 if (!NILP (w
->hchild
))
2454 c
= XWINDOW (w
->hchild
);
2459 /* The min width of a horizontal combination is
2460 the sum of the min widths of its children. */
2463 size
+= window_min_size_1 (c
, width_p
);
2464 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2469 /* The min height a horizontal combination equals
2470 the maximum of all min height of its children. */
2473 int min_size
= window_min_size_1 (c
, width_p
);
2474 size
= max (min_size
, size
);
2475 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2479 else if (!NILP (w
->vchild
))
2481 c
= XWINDOW (w
->vchild
);
2486 /* The min width of a vertical combination is
2487 the maximum of the min widths of its children. */
2490 int min_size
= window_min_size_1 (c
, width_p
);
2491 size
= max (min_size
, size
);
2492 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2497 /* The min height of a vertical combination equals
2498 the sum of the min height of its children. */
2501 size
+= window_min_size_1 (c
, width_p
);
2502 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2509 size
= window_min_width
;
2512 if (MINI_WINDOW_P (w
)
2513 || (!WINDOW_WANTS_MODELINE_P (w
)
2514 && !WINDOW_WANTS_HEADER_LINE_P (w
)))
2517 size
= window_min_height
;
2525 /* Return the minimum size of window W, taking fixed-size windows into
2526 account. WIDTH_P non-zero means return the minimum width,
2527 otherwise return the minimum height. IGNORE_FIXED_P non-zero means
2528 ignore if W is fixed-size. Set *FIXED to 1 if W is fixed-size
2529 unless FIXED is null. */
2532 window_min_size (w
, width_p
, ignore_fixed_p
, fixed
)
2534 int width_p
, ignore_fixed_p
, *fixed
;
2541 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
2547 size
= width_p
? XFASTINT (w
->total_cols
) : XFASTINT (w
->total_lines
);
2549 size
= window_min_size_1 (w
, width_p
);
2555 /* Adjust the margins of window W if text area is too small.
2556 Return 1 if window width is ok after adjustment; 0 if window
2557 is still too narrow. */
2560 adjust_window_margins (w
)
2563 int box_cols
= (WINDOW_TOTAL_COLS (w
)
2564 - WINDOW_FRINGE_COLS (w
)
2565 - WINDOW_SCROLL_BAR_COLS (w
));
2566 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
2567 + WINDOW_RIGHT_MARGIN_COLS (w
));
2569 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
2572 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
2575 /* Window's text area is too narrow, but reducing the window
2576 margins will fix that. */
2577 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
2578 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
2580 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
2581 w
->left_margin_cols
= w
->right_margin_cols
2582 = make_number (margin_cols
/2);
2584 w
->right_margin_cols
= make_number (margin_cols
);
2587 w
->left_margin_cols
= make_number (margin_cols
);
2591 /* Calculate new sizes for windows in the list FORWARD when the window size
2592 goes from TOTAL to SIZE. TOTAL must be greater than SIZE.
2593 The number of windows in FORWARD is NCHILDREN, and the number that
2594 can shrink is SHRINKABLE.
2595 The minimum size a window can have is MIN_SIZE.
2596 If we are shrinking fixed windows, RESIZE_FIXED_P is non-zero.
2597 If we are shrinking columns, WIDTH_P is non-zero, otherwise we are
2600 This function returns an allocated array of new sizes that the caller
2601 must free. The size -1 means the window is fixed and RESIZE_FIXED_P
2602 is zero. Array index 0 refers to the first window in FORWARD, 1 to
2603 the second, and so on.
2605 This function tries to keep windows at least at the minimum size
2606 and resize other windows before it resizes any window to zero (i.e.
2607 delete that window).
2609 Windows are resized proportional to their size, so bigger windows
2610 shrink more than smaller windows. */
2612 shrink_windows (total
, size
, nchildren
, shrinkable
,
2613 min_size
, resize_fixed_p
, forward
, width_p
)
2614 int total
, size
, nchildren
, shrinkable
, min_size
;
2615 int resize_fixed_p
, width_p
;
2616 Lisp_Object forward
;
2618 int available_resize
= 0;
2622 int smallest
= total
;
2623 int total_removed
= 0;
2624 int total_shrink
= total
- size
;
2627 new_sizes
= xmalloc (sizeof (*new_sizes
) * nchildren
);
2629 for (i
= 0, child
= forward
; !NILP (child
); child
= c
->next
, ++i
)
2633 c
= XWINDOW (child
);
2634 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2636 if (! resize_fixed_p
&& window_fixed_size_p (c
, width_p
, 0))
2640 new_sizes
[i
] = child_size
;
2641 if (child_size
> min_size
)
2642 available_resize
+= child_size
- min_size
;
2645 /* We might need to shrink some windows to zero. Find the smallest
2646 windows and set them to 0 until we can fulfil the new size. */
2648 while (shrinkable
> 1 && size
+ available_resize
< total
)
2650 for (i
= 0; i
< nchildren
; ++i
)
2651 if (new_sizes
[i
] > 0 && smallest
> new_sizes
[i
])
2652 smallest
= new_sizes
[i
];
2654 for (i
= 0; i
< nchildren
; ++i
)
2655 if (new_sizes
[i
] == smallest
)
2657 /* Resize this window down to zero. */
2659 if (smallest
> min_size
)
2660 available_resize
-= smallest
- min_size
;
2661 available_resize
+= smallest
;
2663 total_removed
+= smallest
;
2665 /* We don't know what the smallest is now. */
2668 /* Out of for, just remove one window at the time and
2669 check again if we have enough space. */
2674 /* Now, calculate the new sizes. Try to shrink each window
2675 proportional to its size. */
2676 for (i
= 0; i
< nchildren
; ++i
)
2678 if (new_sizes
[i
] > min_size
)
2680 int to_shrink
= total_shrink
*new_sizes
[i
]/total
;
2681 if (new_sizes
[i
] - to_shrink
< min_size
)
2682 to_shrink
= new_sizes
[i
] - min_size
;
2683 new_sizes
[i
] -= to_shrink
;
2684 total_removed
+= to_shrink
;
2688 /* Any reminder due to rounding, we just subtract from windows
2689 that are left and still can be shrunk. */
2690 while (total_shrink
> total_removed
)
2692 int nonzero_sizes
= 0;
2693 int nonzero_idx
= -1;
2695 for (i
= 0; i
< nchildren
; ++i
)
2696 if (new_sizes
[i
] > 0)
2702 for (i
= 0; i
< nchildren
; ++i
)
2703 if (new_sizes
[i
] > min_size
)
2708 /* Out of for, just shrink one window at the time and
2709 check again if we have enough space. */
2714 /* Special case, only one window left. */
2715 if (nonzero_sizes
== 1)
2719 /* Any surplus due to rounding, we add to windows that are left. */
2720 while (total_shrink
< total_removed
)
2722 for (i
= 0; i
< nchildren
; ++i
)
2724 if (new_sizes
[i
] != 0 && total_shrink
< total_removed
)
2736 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
2737 WINDOW's width. Resize WINDOW's children, if any, so that they
2738 keep their proportionate size relative to WINDOW. Propagate
2739 WINDOW's top or left edge position to children. Delete windows
2740 that become too small unless NODELETE_P is non-zero.
2742 If NODELETE_P is 2, that means we do delete windows that are
2743 too small, even if they were too small before! */
2746 size_window (window
, size
, width_p
, nodelete_p
)
2748 int size
, width_p
, nodelete_p
;
2750 struct window
*w
= XWINDOW (window
);
2752 Lisp_Object child
, *forward
, *sideward
;
2753 int old_size
, min_size
, safe_min_size
;
2755 /* We test nodelete_p != 2 and nodelete_p != 1 below, so it
2756 seems like it's too soon to do this here. ++KFS. */
2757 if (nodelete_p
== 2)
2760 check_min_window_sizes ();
2761 size
= max (0, size
);
2763 /* If the window has been "too small" at one point,
2764 don't delete it for being "too small" in the future.
2765 Preserve it as long as that is at all possible. */
2768 old_size
= WINDOW_TOTAL_COLS (w
);
2769 min_size
= window_min_width
;
2770 /* Ensure that there is room for the scroll bar and fringes!
2771 We may reduce display margins though. */
2772 safe_min_size
= (MIN_SAFE_WINDOW_WIDTH
2773 + WINDOW_FRINGE_COLS (w
)
2774 + WINDOW_SCROLL_BAR_COLS (w
));
2778 old_size
= XINT (w
->total_lines
);
2779 min_size
= window_min_height
;
2780 safe_min_size
= MIN_SAFE_WINDOW_HEIGHT
;
2783 if (old_size
< min_size
&& nodelete_p
!= 2)
2784 w
->too_small_ok
= Qt
;
2786 /* Maybe delete WINDOW if it's too small. */
2787 if (nodelete_p
!= 1 && !NILP (w
->parent
))
2789 if (!MINI_WINDOW_P (w
) && !NILP (w
->too_small_ok
))
2790 min_size
= width_p
? MIN_SAFE_WINDOW_WIDTH
: MIN_SAFE_WINDOW_HEIGHT
;
2791 if (min_size
< safe_min_size
)
2792 min_size
= safe_min_size
;
2793 if (size
< min_size
)
2795 delete_window (window
);
2800 /* Set redisplay hints. */
2801 w
->last_modified
= make_number (0);
2802 w
->last_overlay_modified
= make_number (0);
2803 windows_or_buffers_changed
++;
2804 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w
->frame
)) = 1;
2808 sideward
= &w
->vchild
;
2809 forward
= &w
->hchild
;
2810 w
->total_cols
= make_number (size
);
2811 adjust_window_margins (w
);
2815 sideward
= &w
->hchild
;
2816 forward
= &w
->vchild
;
2817 w
->total_lines
= make_number (size
);
2818 w
->orig_total_lines
= Qnil
;
2821 if (!NILP (*sideward
))
2823 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
2825 c
= XWINDOW (child
);
2827 c
->left_col
= w
->left_col
;
2829 c
->top_line
= w
->top_line
;
2830 size_window (child
, size
, width_p
, nodelete_p
);
2833 else if (!NILP (*forward
))
2835 int fixed_size
, each
, extra
, n
;
2836 int resize_fixed_p
, nfixed
;
2837 int last_pos
, first_pos
, nchildren
, total
;
2838 int *new_sizes
= NULL
;
2840 /* Determine the fixed-size portion of the this window, and the
2841 number of child windows. */
2842 fixed_size
= nchildren
= nfixed
= total
= 0;
2843 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
2847 c
= XWINDOW (child
);
2848 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2849 total
+= child_size
;
2851 if (window_fixed_size_p (c
, width_p
, 0))
2853 fixed_size
+= child_size
;
2858 /* If the new size is smaller than fixed_size, or if there
2859 aren't any resizable windows, allow resizing fixed-size
2861 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
2863 /* Compute how many lines/columns to add/remove to each child. The
2864 value of extra takes care of rounding errors. */
2865 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
2866 if (size
< total
&& n
> 1)
2867 new_sizes
= shrink_windows (total
, size
, nchildren
, n
, min_size
,
2868 resize_fixed_p
, *forward
, width_p
);
2871 each
= (size
- total
) / n
;
2872 extra
= (size
- total
) - n
* each
;
2875 /* Compute new children heights and edge positions. */
2876 first_pos
= width_p
? XINT (w
->left_col
) : XINT (w
->top_line
);
2877 last_pos
= first_pos
;
2878 for (n
= 0, child
= *forward
; !NILP (child
); child
= c
->next
, ++n
)
2880 int new_size
, old_size
;
2882 c
= XWINDOW (child
);
2883 old_size
= width_p
? XFASTINT (c
->total_cols
) : XFASTINT (c
->total_lines
);
2884 new_size
= old_size
;
2886 /* The top or left edge position of this child equals the
2887 bottom or right edge of its predecessor. */
2889 c
->left_col
= make_number (last_pos
);
2891 c
->top_line
= make_number (last_pos
);
2893 /* If this child can be resized, do it. */
2894 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
2896 new_size
= new_sizes
? new_sizes
[n
] : old_size
+ each
+ extra
;
2900 /* Set new height. Note that size_window also propagates
2901 edge positions to children, so it's not a no-op if we
2902 didn't change the child's size. */
2903 size_window (child
, new_size
, width_p
, 1);
2905 /* Remember the bottom/right edge position of this child; it
2906 will be used to set the top/left edge of the next child. */
2907 last_pos
+= new_size
;
2910 if (new_sizes
) xfree (new_sizes
);
2912 /* We should have covered the parent exactly with child windows. */
2913 xassert (size
== last_pos
- first_pos
);
2915 /* Now delete any children that became too small. */
2917 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2920 c
= XWINDOW (child
);
2921 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2922 size_window (child
, child_size
, width_p
, 2);
2927 /* Set WINDOW's height to HEIGHT, and recursively change the height of
2928 WINDOW's children. NODELETE non-zero means don't delete windows
2929 that become too small in the process. (The caller should check
2930 later and do so if appropriate.) */
2933 set_window_height (window
, height
, nodelete
)
2938 size_window (window
, height
, 0, nodelete
);
2942 /* Set WINDOW's width to WIDTH, and recursively change the width of
2943 WINDOW's children. NODELETE non-zero means don't delete windows
2944 that become too small in the process. (The caller should check
2945 later and do so if appropriate.) */
2948 set_window_width (window
, width
, nodelete
)
2953 size_window (window
, width
, 1, nodelete
);
2956 /* Change window heights in windows rooted in WINDOW by N lines. */
2959 change_window_heights (window
, n
)
2963 struct window
*w
= XWINDOW (window
);
2965 XSETFASTINT (w
->top_line
, XFASTINT (w
->top_line
) + n
);
2966 XSETFASTINT (w
->total_lines
, XFASTINT (w
->total_lines
) - n
);
2968 if (INTEGERP (w
->orig_top_line
))
2969 XSETFASTINT (w
->orig_top_line
, XFASTINT (w
->orig_top_line
) + n
);
2970 if (INTEGERP (w
->orig_total_lines
))
2971 XSETFASTINT (w
->orig_total_lines
, XFASTINT (w
->orig_total_lines
) - n
);
2973 /* Handle just the top child in a vertical split. */
2974 if (!NILP (w
->vchild
))
2975 change_window_heights (w
->vchild
, n
);
2977 /* Adjust all children in a horizontal split. */
2978 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
2980 w
= XWINDOW (window
);
2981 change_window_heights (window
, n
);
2986 int window_select_count
;
2989 Fset_window_buffer_unwind (obuf
)
2996 EXFUN (Fset_window_fringes
, 4);
2997 EXFUN (Fset_window_scroll_bars
, 4);
2999 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
3000 means it's allowed to run hooks. See make_frame for a case where
3001 it's not allowed. KEEP_MARGINS_P non-zero means that the current
3002 margins, fringes, and scroll-bar settings of the window are not
3003 reset from the buffer's local settings. */
3006 set_window_buffer (window
, buffer
, run_hooks_p
, keep_margins_p
)
3007 Lisp_Object window
, buffer
;
3008 int run_hooks_p
, keep_margins_p
;
3010 struct window
*w
= XWINDOW (window
);
3011 struct buffer
*b
= XBUFFER (buffer
);
3012 int count
= SPECPDL_INDEX ();
3016 if (EQ (window
, selected_window
))
3017 b
->last_selected_window
= window
;
3019 /* Let redisplay errors through. */
3020 b
->display_error_modiff
= 0;
3022 /* Update time stamps of buffer display. */
3023 if (INTEGERP (b
->display_count
))
3024 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
3025 b
->display_time
= Fcurrent_time ();
3027 XSETFASTINT (w
->window_end_pos
, 0);
3028 XSETFASTINT (w
->window_end_vpos
, 0);
3029 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
3030 w
->window_end_valid
= Qnil
;
3031 w
->hscroll
= w
->min_hscroll
= make_number (0);
3033 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3034 set_marker_restricted (w
->start
,
3035 make_number (b
->last_window_start
),
3037 w
->start_at_line_beg
= Qnil
;
3038 w
->force_start
= Qnil
;
3039 XSETFASTINT (w
->last_modified
, 0);
3040 XSETFASTINT (w
->last_overlay_modified
, 0);
3041 windows_or_buffers_changed
++;
3043 /* We must select BUFFER for running the window-scroll-functions.
3044 If WINDOW is selected, switch permanently.
3045 Otherwise, switch but go back to the ambient buffer afterward. */
3046 if (EQ (window
, selected_window
))
3047 Fset_buffer (buffer
);
3048 /* We can't check ! NILP (Vwindow_scroll_functions) here
3049 because that might itself be a local variable. */
3050 else if (window_initialized
)
3052 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
3053 Fset_buffer (buffer
);
3056 if (!keep_margins_p
)
3058 /* Set left and right marginal area width etc. from buffer. */
3060 /* This may call adjust_window_margins three times, so
3061 temporarily disable window margins. */
3062 Lisp_Object save_left
= w
->left_margin_cols
;
3063 Lisp_Object save_right
= w
->right_margin_cols
;
3065 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
3067 Fset_window_fringes (window
,
3068 b
->left_fringe_width
, b
->right_fringe_width
,
3069 b
->fringes_outside_margins
);
3071 Fset_window_scroll_bars (window
,
3072 b
->scroll_bar_width
,
3073 b
->vertical_scroll_bar_type
, Qnil
);
3075 w
->left_margin_cols
= save_left
;
3076 w
->right_margin_cols
= save_right
;
3078 Fset_window_margins (window
,
3079 b
->left_margin_cols
, b
->right_margin_cols
);
3084 if (! NILP (Vwindow_scroll_functions
))
3085 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3086 Fmarker_position (w
->start
));
3088 if (! NILP (Vwindow_configuration_change_hook
)
3089 && ! NILP (Vrun_hooks
))
3090 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3093 unbind_to (count
, Qnil
);
3097 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3098 doc
: /* Make WINDOW display BUFFER as its contents.
3099 BUFFER can be a buffer or the name of an existing buffer.
3100 Optional third arg KEEP-MARGINS non-nil means that WINDOW's current
3101 display margins, fringe widths, and scroll bar settings are maintained;
3102 the default is to reset these from BUFFER's local settings or the frame
3105 This function runs the hook `window-scroll-functions'. */)
3106 (window
, buffer
, keep_margins
)
3107 register Lisp_Object window
, buffer
, keep_margins
;
3109 register Lisp_Object tem
;
3110 register struct window
*w
= decode_window (window
);
3112 XSETWINDOW (window
, w
);
3113 buffer
= Fget_buffer (buffer
);
3114 CHECK_BUFFER (buffer
);
3116 if (NILP (XBUFFER (buffer
)->name
))
3117 error ("Attempt to display deleted buffer");
3121 error ("Window is deleted");
3122 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
3123 is first being set up. */
3125 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
3126 error ("Window is dedicated to `%s'",
3127 SDATA (XBUFFER (tem
)->name
));
3132 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3136 /* Note that selected_window can be nil
3137 when this is called from Fset_window_configuration. */
3139 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
3140 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
3141 If WINDOW is not already selected, make WINDOW's buffer current
3142 and make WINDOW the frame's selected window. Return WINDOW.
3143 Optional second arg NORECORD non-nil means
3144 do not put this buffer at the front of the list of recently selected ones.
3146 Note that the main editor command loop
3147 selects the buffer of the selected window before each command. */)
3149 register Lisp_Object window
, norecord
;
3151 register struct window
*w
;
3152 register struct window
*ow
;
3155 CHECK_LIVE_WINDOW (window
);
3157 w
= XWINDOW (window
);
3158 w
->frozen_window_start_p
= 0;
3160 ++window_select_count
;
3161 XSETFASTINT (w
->use_time
, window_select_count
);
3162 if (EQ (window
, selected_window
))
3165 if (!NILP (selected_window
))
3167 ow
= XWINDOW (selected_window
);
3168 if (! NILP (ow
->buffer
))
3169 set_marker_both (ow
->pointm
, ow
->buffer
,
3170 BUF_PT (XBUFFER (ow
->buffer
)),
3171 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
3174 selected_window
= window
;
3175 sf
= SELECTED_FRAME ();
3176 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
3178 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
3179 /* Use this rather than Fhandle_switch_frame
3180 so that FRAME_FOCUS_FRAME is moved appropriately as we
3181 move around in the state where a minibuffer in a separate
3183 Fselect_frame (WINDOW_FRAME (w
), Qnil
);
3186 sf
->selected_window
= window
;
3188 if (NILP (norecord
))
3189 record_buffer (w
->buffer
);
3190 Fset_buffer (w
->buffer
);
3192 XBUFFER (w
->buffer
)->last_selected_window
= window
;
3194 /* Go to the point recorded in the window.
3195 This is important when the buffer is in more
3196 than one window. It also matters when
3197 redisplay_window has altered point after scrolling,
3198 because it makes the change only in the window. */
3200 register int new_point
= marker_position (w
->pointm
);
3201 if (new_point
< BEGV
)
3203 else if (new_point
> ZV
)
3209 windows_or_buffers_changed
++;
3214 select_window_norecord (window
)
3217 return Fselect_window (window
, Qt
);
3220 /* Deiconify the frame containing the window WINDOW,
3221 unless it is the selected frame;
3224 The reason for the exception for the selected frame
3225 is that it seems better not to change the selected frames visibility
3226 merely because of displaying a different buffer in it.
3227 The deiconification is useful when a buffer gets shown in
3228 another frame that you were not using lately. */
3231 display_buffer_1 (window
)
3234 Lisp_Object frame
= XWINDOW (window
)->frame
;
3235 FRAME_PTR f
= XFRAME (frame
);
3237 FRAME_SAMPLE_VISIBILITY (f
);
3239 if (EQ (frame
, selected_frame
))
3240 ; /* Assume the selected frame is already visible enough. */
3241 else if (minibuf_level
> 0
3242 && MINI_WINDOW_P (XWINDOW (selected_window
))
3243 && WINDOW_LIVE_P (minibuf_selected_window
)
3244 && EQ (frame
, WINDOW_FRAME (XWINDOW (minibuf_selected_window
))))
3245 ; /* Assume the frame from which we invoked the minibuffer is visible. */
3248 if (FRAME_ICONIFIED_P (f
))
3249 Fmake_frame_visible (frame
);
3250 else if (FRAME_VISIBLE_P (f
))
3251 Fraise_frame (frame
);
3257 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
3258 doc
: /* Returns non-nil if a buffer named BUFFER-NAME gets a special frame.
3259 If the value is t, a frame would be created for that buffer
3260 using the default frame parameters. If the value is a list,
3261 it is a list of frame parameters that would be used
3262 to make a frame for that buffer.
3263 The variables `special-display-buffer-names'
3264 and `special-display-regexps' control this. */)
3266 Lisp_Object buffer_name
;
3270 CHECK_STRING (buffer_name
);
3272 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
3276 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
3280 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
3282 Lisp_Object car
= XCAR (tem
);
3284 && fast_string_match (car
, buffer_name
) >= 0)
3286 else if (CONSP (car
)
3287 && STRINGP (XCAR (car
))
3288 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
3294 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
3295 doc
: /* Returns non-nil if a new buffer named BUFFER-NAME would use the same window.
3296 See `same-window-buffer-names' and `same-window-regexps'. */)
3298 Lisp_Object buffer_name
;
3302 CHECK_STRING (buffer_name
);
3304 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
3308 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
3312 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
3314 Lisp_Object car
= XCAR (tem
);
3316 && fast_string_match (car
, buffer_name
) >= 0)
3318 else if (CONSP (car
)
3319 && STRINGP (XCAR (car
))
3320 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
3326 /* Use B so the default is (other-buffer). */
3327 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
3328 "BDisplay buffer: \nP",
3329 doc
: /* Make BUFFER appear in some window but don't select it.
3330 BUFFER must be the name of an existing buffer, or, when called from Lisp,
3332 If BUFFER is shown already in some window, just use that one,
3333 unless the window is the selected window and the optional second
3334 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).
3335 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
3336 Returns the window displaying BUFFER.
3337 If `display-buffer-reuse-frames' is non-nil, and another frame is currently
3338 displaying BUFFER, then simply raise that frame.
3340 The variables `special-display-buffer-names',
3341 `special-display-regexps', `same-window-buffer-names', and
3342 `same-window-regexps' customize how certain buffer names are handled.
3343 The latter two take effect only if NOT-THIS-WINDOW is t.
3345 If optional argument FRAME is `visible', search all visible frames.
3346 If FRAME is 0, search all visible and iconified frames.
3347 If FRAME is t, search all frames.
3348 If FRAME is a frame, search only that frame.
3349 If FRAME is nil, search only the selected frame
3350 (actually the last nonminibuffer frame),
3351 unless `pop-up-frames' or `display-buffer-reuse-frames' is non-nil,
3352 which means search visible and iconified frames.
3354 If a full-width window on a splittable frame is available to display
3355 the buffer, it may be split, subject to the value of the variable
3356 `split-height-threshold'.
3358 If `even-window-heights' is non-nil, window heights will be evened out
3359 if displaying the buffer causes two vertically adjacent windows to be
3361 (buffer
, not_this_window
, frame
)
3362 register Lisp_Object buffer
, not_this_window
, frame
;
3364 register Lisp_Object window
, tem
, swp
;
3368 buffer
= Fget_buffer (buffer
);
3369 CHECK_BUFFER (buffer
);
3371 if (!NILP (Vdisplay_buffer_function
))
3372 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
3374 if (NILP (not_this_window
)
3375 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
3376 return display_buffer_1 (selected_window
);
3378 /* See if the user has specified this buffer should appear
3379 in the selected window. */
3380 if (NILP (not_this_window
))
3382 swp
= Fsame_window_p (XBUFFER (buffer
)->name
);
3383 if (!NILP (swp
) && !no_switch_window (selected_window
))
3385 Fswitch_to_buffer (buffer
, Qnil
);
3386 return display_buffer_1 (selected_window
);
3390 /* If the user wants pop-up-frames or display-buffer-reuse-frames,
3391 look for a window showing BUFFER on any visible or iconified frame.
3392 Otherwise search only the current frame. */
3395 else if (pop_up_frames
3396 || display_buffer_reuse_frames
3397 || last_nonminibuf_frame
== 0)
3398 XSETFASTINT (tem
, 0);
3400 XSETFRAME (tem
, last_nonminibuf_frame
);
3402 window
= Fget_buffer_window (buffer
, tem
);
3404 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
3405 return display_buffer_1 (window
);
3407 /* Certain buffer names get special handling. */
3408 if (!NILP (Vspecial_display_function
) && NILP (swp
))
3410 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
3412 return call1 (Vspecial_display_function
, buffer
);
3414 return call2 (Vspecial_display_function
, buffer
, tem
);
3417 /* If there are no frames open that have more than a minibuffer,
3418 we need to create a new frame. */
3419 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
3421 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3422 Fset_window_buffer (window
, buffer
, Qnil
);
3423 return display_buffer_1 (window
);
3426 f
= SELECTED_FRAME ();
3428 || FRAME_MINIBUF_ONLY_P (f
)
3429 /* If the current frame is a special display frame,
3430 don't try to reuse its windows. */
3431 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (f
))->dedicated
))
3436 if (FRAME_MINIBUF_ONLY_P (f
))
3437 XSETFRAME (frames
, last_nonminibuf_frame
);
3438 /* Don't try to create a window if we would get an error. */
3439 if (split_height_threshold
< window_min_height
<< 1)
3440 split_height_threshold
= window_min_height
<< 1;
3442 /* Note that both Fget_largest_window and Fget_lru_window
3443 ignore minibuffers and dedicated windows.
3444 This means they can return nil. */
3446 /* If the frame we would try to split cannot be split,
3447 try other frames. */
3448 if (FRAME_NO_SPLIT_P (NILP (frames
) ? f
: last_nonminibuf_frame
))
3450 /* Try visible frames first. */
3451 window
= Fget_largest_window (Qvisible
);
3452 /* If that didn't work, try iconified frames. */
3454 window
= Fget_largest_window (make_number (0));
3456 window
= Fget_largest_window (Qt
);
3459 window
= Fget_largest_window (frames
);
3461 /* If we got a tall enough full-width window that can be split,
3464 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3465 && window_height (window
) >= split_height_threshold
3466 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
3467 window
= Fsplit_window (window
, Qnil
, Qnil
);
3470 Lisp_Object upper
, lower
, other
;
3472 window
= Fget_lru_window (frames
);
3473 /* If the LRU window is selected, and big enough,
3474 and can be split, split it. */
3476 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3477 && (EQ (window
, selected_window
)
3478 || EQ (XWINDOW (window
)->parent
, Qnil
))
3479 && window_height (window
) >= window_min_height
<< 1)
3480 window
= Fsplit_window (window
, Qnil
, Qnil
);
3481 /* If Fget_lru_window returned nil, try other approaches. */
3483 /* Try visible frames first. */
3485 window
= Fget_buffer_window (buffer
, Qvisible
);
3487 window
= Fget_largest_window (Qvisible
);
3488 /* If that didn't work, try iconified frames. */
3490 window
= Fget_buffer_window (buffer
, make_number (0));
3492 window
= Fget_largest_window (make_number (0));
3493 /* Try invisible frames. */
3495 window
= Fget_buffer_window (buffer
, Qt
);
3497 window
= Fget_largest_window (Qt
);
3498 /* As a last resort, make a new frame. */
3500 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3501 /* If window appears above or below another,
3502 even out their heights. */
3503 other
= upper
= lower
= Qnil
;
3504 if (!NILP (XWINDOW (window
)->prev
))
3505 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
3506 if (!NILP (XWINDOW (window
)->next
))
3507 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
3509 && !NILP (Veven_window_heights
)
3510 /* Check that OTHER and WINDOW are vertically arrayed. */
3511 && !EQ (XWINDOW (other
)->top_line
, XWINDOW (window
)->top_line
)
3512 && (XFASTINT (XWINDOW (other
)->total_lines
)
3513 > XFASTINT (XWINDOW (window
)->total_lines
)))
3515 int total
= (XFASTINT (XWINDOW (other
)->total_lines
)
3516 + XFASTINT (XWINDOW (window
)->total_lines
));
3517 enlarge_window (upper
,
3518 total
/ 2 - XFASTINT (XWINDOW (upper
)->total_lines
),
3524 window
= Fget_lru_window (Qnil
);
3526 Fset_window_buffer (window
, buffer
, Qnil
);
3527 return display_buffer_1 (window
);
3531 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3533 doc
: /* Force redisplay of all windows.
3534 If optional arg OBJECT is a window, force redisplay of that window only.
3535 If OBJECT is a buffer or buffer name, force redisplay of all windows
3536 displaying that buffer. */)
3542 windows_or_buffers_changed
++;
3543 update_mode_lines
++;
3547 if (WINDOWP (object
))
3549 struct window
*w
= XWINDOW (object
);
3550 mark_window_display_accurate (object
, 0);
3551 w
->update_mode_line
= Qt
;
3552 if (BUFFERP (w
->buffer
))
3553 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
3554 ++update_mode_lines
;
3558 if (STRINGP (object
))
3559 object
= Fget_buffer (object
);
3560 if (BUFFERP (object
) && !NILP (XBUFFER (object
)->name
))
3562 /* Walk all windows looking for buffer, and force update
3563 of each of those windows. */
3565 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3566 return NILP (object
) ? Qnil
: Qt
;
3569 /* If nothing suitable was found, just return.
3570 We could signal an error, but this feature will typically be used
3571 asynchronously in timers or process sentinels, so we don't. */
3577 temp_output_buffer_show (buf
)
3578 register Lisp_Object buf
;
3580 register struct buffer
*old
= current_buffer
;
3581 register Lisp_Object window
;
3582 register struct window
*w
;
3584 XBUFFER (buf
)->directory
= current_buffer
->directory
;
3587 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3591 #if 0 /* rms: there should be no reason for this. */
3592 XBUFFER (buf
)->prevent_redisplay_optimizations_p
= 1;
3594 set_buffer_internal (old
);
3596 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
3597 call1 (Vtemp_buffer_show_function
, buf
);
3600 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
3602 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3603 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3604 Vminibuf_scroll_window
= window
;
3605 w
= XWINDOW (window
);
3606 XSETFASTINT (w
->hscroll
, 0);
3607 XSETFASTINT (w
->min_hscroll
, 0);
3608 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3609 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3611 /* Run temp-buffer-show-hook, with the chosen window selected
3612 and its buffer current. */
3614 if (!NILP (Vrun_hooks
)
3615 && !NILP (Fboundp (Qtemp_buffer_show_hook
))
3616 && !NILP (Fsymbol_value (Qtemp_buffer_show_hook
)))
3618 int count
= SPECPDL_INDEX ();
3619 Lisp_Object prev_window
, prev_buffer
;
3620 prev_window
= selected_window
;
3621 XSETBUFFER (prev_buffer
, old
);
3623 /* Select the window that was chosen, for running the hook.
3624 Note: Both Fselect_window and select_window_norecord may
3625 set-buffer to the buffer displayed in the window,
3626 so we need to save the current buffer. --stef */
3627 record_unwind_protect (Fset_buffer
, prev_buffer
);
3628 record_unwind_protect (select_window_norecord
, prev_window
);
3629 Fselect_window (window
, Qt
);
3630 Fset_buffer (w
->buffer
);
3631 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
3632 unbind_to (count
, Qnil
);
3638 make_dummy_parent (window
)
3642 register struct window
*o
, *p
;
3645 o
= XWINDOW (window
);
3646 p
= allocate_window ();
3647 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
3648 ((struct Lisp_Vector
*) p
)->contents
[i
]
3649 = ((struct Lisp_Vector
*)o
)->contents
[i
];
3650 XSETWINDOW (new, p
);
3653 XSETFASTINT (p
->sequence_number
, sequence_number
);
3655 /* Put new into window structure in place of window */
3656 replace_window (window
, new);
3669 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
3670 doc
: /* Split WINDOW, putting SIZE lines in the first of the pair.
3671 WINDOW defaults to selected one and SIZE to half its size.
3672 If optional third arg HORFLAG is non-nil, split side by side
3673 and put SIZE columns in the first of the pair. In that case,
3674 SIZE includes that window's scroll bar, or the divider column to its right.
3675 Interactively, all arguments are nil.
3677 Returns the newly created window (which is the lower or rightmost one).
3678 The upper or leftmost window is the original one and remains selected.
3679 See Info node `(elisp)Splitting Windows' for more details and examples.*/)
3680 (window
, size
, horflag
)
3681 Lisp_Object window
, size
, horflag
;
3683 register Lisp_Object
new;
3684 register struct window
*o
, *p
;
3686 register int size_int
;
3689 window
= selected_window
;
3691 CHECK_LIVE_WINDOW (window
);
3693 o
= XWINDOW (window
);
3694 fo
= XFRAME (WINDOW_FRAME (o
));
3698 if (!NILP (horflag
))
3699 /* Calculate the size of the left-hand window, by dividing
3700 the usable space in columns by two.
3701 We round up, since the left-hand window may include
3702 a dividing line, while the right-hand may not. */
3703 size_int
= (XFASTINT (o
->total_cols
) + 1) >> 1;
3705 size_int
= XFASTINT (o
->total_lines
) >> 1;
3709 CHECK_NUMBER (size
);
3710 size_int
= XINT (size
);
3713 if (MINI_WINDOW_P (o
))
3714 error ("Attempt to split minibuffer window");
3715 else if (window_fixed_size_p (o
, !NILP (horflag
), 0))
3716 error ("Attempt to split fixed-size window");
3718 check_min_window_sizes ();
3722 if (size_int
< window_min_height
)
3723 error ("Window height %d too small (after splitting)", size_int
);
3724 if (size_int
+ window_min_height
> XFASTINT (o
->total_lines
))
3725 error ("Window height %d too small (after splitting)",
3726 XFASTINT (o
->total_lines
) - size_int
);
3727 if (NILP (o
->parent
)
3728 || NILP (XWINDOW (o
->parent
)->vchild
))
3730 make_dummy_parent (window
);
3732 XWINDOW (new)->vchild
= window
;
3737 if (size_int
< window_min_width
)
3738 error ("Window width %d too small (after splitting)", size_int
);
3740 if (size_int
+ window_min_width
> XFASTINT (o
->total_cols
))
3741 error ("Window width %d too small (after splitting)",
3742 XFASTINT (o
->total_cols
) - size_int
);
3743 if (NILP (o
->parent
)
3744 || NILP (XWINDOW (o
->parent
)->hchild
))
3746 make_dummy_parent (window
);
3748 XWINDOW (new)->hchild
= window
;
3752 /* Now we know that window's parent is a vertical combination
3753 if we are dividing vertically, or a horizontal combination
3754 if we are making side-by-side windows */
3756 windows_or_buffers_changed
++;
3757 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
3758 new = make_window ();
3761 p
->frame
= o
->frame
;
3763 if (!NILP (p
->next
))
3764 XWINDOW (p
->next
)->prev
= new;
3767 p
->parent
= o
->parent
;
3769 p
->window_end_valid
= Qnil
;
3770 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
3772 /* Duplicate special geometry settings. */
3774 p
->left_margin_cols
= o
->left_margin_cols
;
3775 p
->right_margin_cols
= o
->right_margin_cols
;
3776 p
->left_fringe_width
= o
->left_fringe_width
;
3777 p
->right_fringe_width
= o
->right_fringe_width
;
3778 p
->fringes_outside_margins
= o
->fringes_outside_margins
;
3779 p
->scroll_bar_width
= o
->scroll_bar_width
;
3780 p
->vertical_scroll_bar_type
= o
->vertical_scroll_bar_type
;
3782 /* Apportion the available frame space among the two new windows */
3784 if (!NILP (horflag
))
3786 p
->total_lines
= o
->total_lines
;
3787 p
->top_line
= o
->top_line
;
3788 XSETFASTINT (p
->total_cols
, XFASTINT (o
->total_cols
) - size_int
);
3789 XSETFASTINT (o
->total_cols
, size_int
);
3790 XSETFASTINT (p
->left_col
, XFASTINT (o
->left_col
) + size_int
);
3791 adjust_window_margins (p
);
3792 adjust_window_margins (o
);
3796 p
->left_col
= o
->left_col
;
3797 p
->total_cols
= o
->total_cols
;
3798 XSETFASTINT (p
->total_lines
, XFASTINT (o
->total_lines
) - size_int
);
3799 XSETFASTINT (o
->total_lines
, size_int
);
3800 XSETFASTINT (p
->top_line
, XFASTINT (o
->top_line
) + size_int
);
3803 /* Adjust glyph matrices. */
3806 Fset_window_buffer (new, o
->buffer
, Qt
);
3810 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 3, "p",
3811 doc
: /* Make current window ARG lines bigger.
3812 From program, optional second arg non-nil means grow sideways ARG columns.
3813 Interactively, if an argument is not given, make the window one line bigger.
3815 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3816 of the siblings above or to the left of the selected window. Only
3817 siblings to the right or below are changed. */)
3818 (arg
, side
, preserve_before
)
3819 register Lisp_Object arg
, side
, preserve_before
;
3822 enlarge_window (selected_window
, XINT (arg
), !NILP (side
),
3823 !NILP (preserve_before
));
3825 if (! NILP (Vwindow_configuration_change_hook
))
3826 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3831 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 3, "p",
3832 doc
: /* Make current window ARG lines smaller.
3833 From program, optional second arg non-nil means shrink sideways arg columns.
3834 Interactively, if an argument is not given, make the window one line smaller.
3836 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3837 of the siblings above or to the left of the selected window. Only
3838 siblings to the right or below are changed. */)
3839 (arg
, side
, preserve_before
)
3840 register Lisp_Object arg
, side
, preserve_before
;
3843 enlarge_window (selected_window
, -XINT (arg
), !NILP (side
),
3844 !NILP (preserve_before
));
3846 if (! NILP (Vwindow_configuration_change_hook
))
3847 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3853 window_height (window
)
3856 register struct window
*p
= XWINDOW (window
);
3857 return WINDOW_TOTAL_LINES (p
);
3861 window_width (window
)
3864 register struct window
*p
= XWINDOW (window
);
3865 return WINDOW_TOTAL_COLS (p
);
3870 *(widthflag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line))
3872 #define CURSIZE(w) \
3873 *(widthflag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines))
3876 /* Enlarge WINDOW by DELTA. WIDTHFLAG non-zero means
3877 increase its width. Siblings of the selected window are resized to
3878 fulfill the size request. If they become too small in the process,
3879 they will be deleted.
3881 If PRESERVE_BEFORE is nonzero, that means don't alter
3882 the siblings to the left or above WINDOW. */
3885 enlarge_window (window
, delta
, widthflag
, preserve_before
)
3887 int delta
, widthflag
, preserve_before
;
3889 Lisp_Object parent
, next
, prev
;
3893 int (*sizefun
) P_ ((Lisp_Object
))
3894 = widthflag
? window_width
: window_height
;
3895 void (*setsizefun
) P_ ((Lisp_Object
, int, int))
3896 = (widthflag
? set_window_width
: set_window_height
);
3898 /* Check values of window_min_width and window_min_height for
3900 check_min_window_sizes ();
3902 /* Give up if this window cannot be resized. */
3903 if (window_fixed_size_p (XWINDOW (window
), widthflag
, 1))
3904 error ("Window is not resizable");
3906 /* Find the parent of the selected window. */
3909 p
= XWINDOW (window
);
3915 error ("No other window to side of this one");
3920 ? !NILP (XWINDOW (parent
)->hchild
)
3921 : !NILP (XWINDOW (parent
)->vchild
))
3927 sizep
= &CURSIZE (window
);
3930 register int maxdelta
;
3932 /* Compute the maximum size increment this window can have. */
3934 if (preserve_before
)
3938 maxdelta
= (*sizefun
) (parent
) - XINT (*sizep
);
3939 /* Subtract size of siblings before, since we can't take that. */
3940 maxdelta
-= XINT (CURBEG (window
)) - XINT (CURBEG (parent
));
3943 maxdelta
= (!NILP (p
->next
) ? ((*sizefun
) (p
->next
)
3944 - window_min_size (XWINDOW (p
->next
),
3949 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - XINT (*sizep
)
3950 /* This is a main window followed by a minibuffer. */
3951 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
3952 - window_min_size (XWINDOW (p
->next
),
3954 /* This is a minibuffer following a main window. */
3955 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
3956 - window_min_size (XWINDOW (p
->prev
),
3958 /* This is a frame with only one window, a minibuffer-only
3959 or a minibufferless frame. */
3962 if (delta
> maxdelta
)
3963 /* This case traps trying to make the minibuffer
3964 the full frame, or make the only window aside from the
3965 minibuffer the full frame. */
3969 if (XINT (*sizep
) + delta
< window_min_size (XWINDOW (window
), widthflag
, 0, 0))
3971 delete_window (window
);
3978 /* Find the total we can get from other siblings without deleting them. */
3980 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
3981 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
3983 if (! preserve_before
)
3984 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
3985 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
3988 /* If we can get it all from them without deleting them, do so. */
3989 if (delta
<= maximum
)
3991 Lisp_Object first_unaffected
;
3992 Lisp_Object first_affected
;
3997 first_affected
= window
;
3998 /* Look at one sibling at a time,
3999 moving away from this window in both directions alternately,
4000 and take as much as we can get without deleting that sibling. */
4002 && (!NILP (next
) || (!preserve_before
&& !NILP (prev
))))
4006 int this_one
= ((*sizefun
) (next
)
4007 - window_min_size (XWINDOW (next
),
4008 widthflag
, 0, &fixed_p
));
4011 if (this_one
> delta
)
4014 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
4015 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4020 next
= XWINDOW (next
)->next
;
4026 if (!preserve_before
&& ! NILP (prev
))
4028 int this_one
= ((*sizefun
) (prev
)
4029 - window_min_size (XWINDOW (prev
),
4030 widthflag
, 0, &fixed_p
));
4033 if (this_one
> delta
)
4036 first_affected
= prev
;
4038 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
4039 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4044 prev
= XWINDOW (prev
)->prev
;
4048 xassert (delta
== 0);
4050 /* Now recalculate the edge positions of all the windows affected,
4051 based on the new sizes. */
4052 first_unaffected
= next
;
4053 prev
= first_affected
;
4054 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
4055 prev
= next
, next
= XWINDOW (next
)->next
)
4057 XSETINT (CURBEG (next
), XINT (CURBEG (prev
)) + (*sizefun
) (prev
));
4058 /* This does not change size of NEXT,
4059 but it propagates the new top edge to its children */
4060 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
4065 register int delta1
;
4066 register int opht
= (*sizefun
) (parent
);
4068 if (opht
<= XINT (*sizep
) + delta
)
4070 /* If trying to grow this window to or beyond size of the parent,
4071 just delete all the sibling windows. */
4072 Lisp_Object start
, tem
, next
;
4074 start
= XWINDOW (parent
)->vchild
;
4076 start
= XWINDOW (parent
)->hchild
;
4078 /* Delete any siblings that come after WINDOW. */
4079 tem
= XWINDOW (window
)->next
;
4080 while (! NILP (tem
))
4082 next
= XWINDOW (tem
)->next
;
4083 delete_window (tem
);
4087 /* Delete any siblings that come after WINDOW.
4088 Note that if START is not WINDOW, then WINDOW still
4089 Fhas siblings, so WINDOW has not yet replaced its parent. */
4091 while (! EQ (tem
, window
))
4093 next
= XWINDOW (tem
)->next
;
4094 delete_window (tem
);
4100 /* Otherwise, make delta1 just right so that if we add
4101 delta1 lines to this window and to the parent, and then
4102 shrink the parent back to its original size, the new
4103 proportional size of this window will increase by delta.
4105 The function size_window will compute the new height h'
4106 of the window from delta1 as:
4109 x = delta1 - delta1/n * n for the 1st resizable child
4112 where n is the number of children that can be resized.
4113 We can ignore x by choosing a delta1 that is a multiple of
4114 n. We want the height of this window to come out as
4124 The number of children n equals the number of resizable
4125 children of this window + 1 because we know window itself
4126 is resizable (otherwise we would have signalled an error. */
4128 struct window
*w
= XWINDOW (window
);
4132 for (s
= w
->next
; !NILP (s
); s
= XWINDOW (s
)->next
)
4133 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
4135 for (s
= w
->prev
; !NILP (s
); s
= XWINDOW (s
)->prev
)
4136 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
4141 /* Add delta1 lines or columns to this window, and to the parent,
4142 keeping things consistent while not affecting siblings. */
4143 XSETINT (CURSIZE (parent
), opht
+ delta1
);
4144 (*setsizefun
) (window
, XINT (*sizep
) + delta1
, 0);
4146 /* Squeeze out delta1 lines or columns from our parent,
4147 shriking this window and siblings proportionately.
4148 This brings parent back to correct size.
4149 Delta1 was calculated so this makes this window the desired size,
4150 taking it all out of the siblings. */
4151 (*setsizefun
) (parent
, opht
, 0);
4156 XSETFASTINT (p
->last_modified
, 0);
4157 XSETFASTINT (p
->last_overlay_modified
, 0);
4159 /* Adjust glyph matrices. */
4160 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4168 /***********************************************************************
4169 Resizing Mini-Windows
4170 ***********************************************************************/
4172 static void shrink_window_lowest_first
P_ ((struct window
*, int));
4174 enum save_restore_action
4181 static int save_restore_orig_size
P_ ((struct window
*,
4182 enum save_restore_action
));
4184 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
4185 from lowest windows first. */
4188 shrink_window_lowest_first (w
, height
)
4196 xassert (!MINI_WINDOW_P (w
));
4198 /* Set redisplay hints. */
4199 XSETFASTINT (w
->last_modified
, 0);
4200 XSETFASTINT (w
->last_overlay_modified
, 0);
4201 windows_or_buffers_changed
++;
4202 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
4204 old_height
= XFASTINT (w
->total_lines
);
4205 XSETFASTINT (w
->total_lines
, height
);
4207 if (!NILP (w
->hchild
))
4209 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
4211 c
= XWINDOW (child
);
4212 c
->top_line
= w
->top_line
;
4213 shrink_window_lowest_first (c
, height
);
4216 else if (!NILP (w
->vchild
))
4218 Lisp_Object last_child
;
4219 int delta
= old_height
- height
;
4224 /* Find the last child. We are taking space from lowest windows
4225 first, so we iterate over children from the last child
4227 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
4230 /* Assign new heights. We leave only MIN_SAFE_WINDOW_HEIGHT. */
4231 for (child
= last_child
; delta
&& !NILP (child
); child
= c
->prev
)
4235 c
= XWINDOW (child
);
4236 this_one
= XFASTINT (c
->total_lines
) - MIN_SAFE_WINDOW_HEIGHT
;
4238 if (this_one
> delta
)
4241 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
) - this_one
);
4245 /* Compute new positions. */
4246 last_top
= XINT (w
->top_line
);
4247 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
4249 c
= XWINDOW (child
);
4250 c
->top_line
= make_number (last_top
);
4251 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
));
4252 last_top
+= XFASTINT (c
->total_lines
);
4258 /* Save, restore, or check positions and sizes in the window tree
4259 rooted at W. ACTION says what to do.
4261 If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and
4262 orig_total_lines members are valid for all windows in the window
4263 tree. Value is non-zero if they are valid.
4265 If ACTION is SAVE_ORIG_SIZES, save members top and height in
4266 orig_top_line and orig_total_lines for all windows in the tree.
4268 If ACTION is RESTORE_ORIG_SIZES, restore top and height from values
4269 stored in orig_top_line and orig_total_lines for all windows. */
4272 save_restore_orig_size (w
, action
)
4274 enum save_restore_action action
;
4280 if (!NILP (w
->hchild
))
4282 if (!save_restore_orig_size (XWINDOW (w
->hchild
), action
))
4285 else if (!NILP (w
->vchild
))
4287 if (!save_restore_orig_size (XWINDOW (w
->vchild
), action
))
4293 case CHECK_ORIG_SIZES
:
4294 if (!INTEGERP (w
->orig_top_line
) || !INTEGERP (w
->orig_total_lines
))
4298 case SAVE_ORIG_SIZES
:
4299 w
->orig_top_line
= w
->top_line
;
4300 w
->orig_total_lines
= w
->total_lines
;
4301 XSETFASTINT (w
->last_modified
, 0);
4302 XSETFASTINT (w
->last_overlay_modified
, 0);
4305 case RESTORE_ORIG_SIZES
:
4306 xassert (INTEGERP (w
->orig_top_line
) && INTEGERP (w
->orig_total_lines
));
4307 w
->top_line
= w
->orig_top_line
;
4308 w
->total_lines
= w
->orig_total_lines
;
4309 w
->orig_total_lines
= w
->orig_top_line
= Qnil
;
4310 XSETFASTINT (w
->last_modified
, 0);
4311 XSETFASTINT (w
->last_overlay_modified
, 0);
4318 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
4325 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
4326 without deleting other windows. */
4329 grow_mini_window (w
, delta
)
4333 struct frame
*f
= XFRAME (w
->frame
);
4334 struct window
*root
;
4336 xassert (MINI_WINDOW_P (w
));
4337 xassert (delta
>= 0);
4339 /* Check values of window_min_width and window_min_height for
4341 check_min_window_sizes ();
4343 /* Compute how much we can enlarge the mini-window without deleting
4345 root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4348 int min_height
= window_min_size (root
, 0, 0, 0);
4349 if (XFASTINT (root
->total_lines
) - delta
< min_height
)
4350 /* Note that the root window may already be smaller than
4352 delta
= max (0, XFASTINT (root
->total_lines
) - min_height
);
4357 /* Save original window sizes and positions, if not already done. */
4358 if (!save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4359 save_restore_orig_size (root
, SAVE_ORIG_SIZES
);
4361 /* Shrink other windows. */
4362 shrink_window_lowest_first (root
, XFASTINT (root
->total_lines
) - delta
);
4364 /* Grow the mini-window. */
4365 w
->top_line
= make_number (XFASTINT (root
->top_line
) + XFASTINT (root
->total_lines
));
4366 w
->total_lines
= make_number (XFASTINT (w
->total_lines
) + delta
);
4367 XSETFASTINT (w
->last_modified
, 0);
4368 XSETFASTINT (w
->last_overlay_modified
, 0);
4375 /* Shrink mini-window W. If there is recorded info about window sizes
4376 before a call to grow_mini_window, restore recorded window sizes.
4377 Otherwise, if the mini-window is higher than 1 line, resize it to 1
4381 shrink_mini_window (w
)
4384 struct frame
*f
= XFRAME (w
->frame
);
4385 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4387 if (save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4389 save_restore_orig_size (root
, RESTORE_ORIG_SIZES
);
4391 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4392 windows_or_buffers_changed
= 1;
4394 else if (XFASTINT (w
->total_lines
) > 1)
4396 /* Distribute the additional lines of the mini-window
4397 among the other windows. */
4399 XSETWINDOW (window
, w
);
4400 enlarge_window (window
, 1 - XFASTINT (w
->total_lines
), 0, 0);
4406 /* Mark window cursors off for all windows in the window tree rooted
4407 at W by setting their phys_cursor_on_p flag to zero. Called from
4408 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4409 the frame are cleared. */
4412 mark_window_cursors_off (w
)
4417 if (!NILP (w
->hchild
))
4418 mark_window_cursors_off (XWINDOW (w
->hchild
));
4419 else if (!NILP (w
->vchild
))
4420 mark_window_cursors_off (XWINDOW (w
->vchild
));
4422 w
->phys_cursor_on_p
= 0;
4424 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4429 /* Return number of lines of text (not counting mode lines) in W. */
4432 window_internal_height (w
)
4435 int ht
= XFASTINT (w
->total_lines
);
4437 if (!MINI_WINDOW_P (w
))
4439 if (!NILP (w
->parent
)
4440 || !NILP (w
->vchild
)
4441 || !NILP (w
->hchild
)
4444 || WINDOW_WANTS_MODELINE_P (w
))
4447 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4455 /* Return the number of columns in W.
4456 Don't count columns occupied by scroll bars or the vertical bar
4457 separating W from the sibling to its right. */
4460 window_box_text_cols (w
)
4463 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4464 int width
= XINT (w
->total_cols
);
4466 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
4467 /* Scroll bars occupy a few columns. */
4468 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
4469 else if (!FRAME_WINDOW_P (f
)
4470 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
4471 /* The column of `|' characters separating side-by-side windows
4472 occupies one column only. */
4475 if (FRAME_WINDOW_P (f
))
4476 /* On window-systems, fringes and display margins cannot be
4477 used for normal text. */
4478 width
-= (WINDOW_FRINGE_COLS (w
)
4479 + WINDOW_LEFT_MARGIN_COLS (w
)
4480 + WINDOW_RIGHT_MARGIN_COLS (w
));
4486 /************************************************************************
4488 ***********************************************************************/
4490 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4491 N screen-fulls, which is defined as the height of the window minus
4492 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4493 instead. Negative values of N mean scroll down. NOERROR non-zero
4494 means don't signal an error if we try to move over BEGV or ZV,
4498 window_scroll (window
, n
, whole
, noerror
)
4506 /* If we must, use the pixel-based version which is much slower than
4507 the line-based one but can handle varying line heights. */
4508 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4509 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4511 window_scroll_line_based (window
, n
, whole
, noerror
);
4517 /* Implementation of window_scroll that works based on pixel line
4518 heights. See the comment of window_scroll for parameter
4522 window_scroll_pixel_based (window
, n
, whole
, noerror
)
4529 struct window
*w
= XWINDOW (window
);
4530 struct text_pos start
;
4532 int this_scroll_margin
;
4534 /* True if we fiddled the window vscroll field without really scrolling. */
4537 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4539 /* If PT is not visible in WINDOW, move back one half of
4540 the screen. Allow PT to be partially visible, otherwise
4541 something like (scroll-down 1) with PT in the line before
4542 the partially visible one would recenter. */
4543 tem
= Fpos_visible_in_window_p (make_number (PT
), window
, Qt
);
4546 /* Move backward half the height of the window. Performance note:
4547 vmotion used here is about 10% faster, but would give wrong
4548 results for variable height lines. */
4549 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4550 it
.current_y
= it
.last_visible_y
;
4551 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4553 /* The function move_iterator_vertically may move over more than
4554 the specified y-distance. If it->w is small, e.g. a
4555 mini-buffer window, we may end up in front of the window's
4556 display area. This is the case when Start displaying at the
4557 start of the line containing PT in this case. */
4558 if (it
.current_y
<= 0)
4560 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4561 move_it_vertically_backward (&it
, 0);
4565 start
= it
.current
.pos
;
4568 /* If scroll_preserve_screen_position is non-nil, we try to set
4569 point in the same window line as it is now, so get that line. */
4570 if (!NILP (Vscroll_preserve_screen_position
))
4572 start_display (&it
, w
, start
);
4573 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4574 preserve_y
= it
.current_y
;
4579 /* Move iterator it from start the specified distance forward or
4580 backward. The result is the new window start. */
4581 start_display (&it
, w
, start
);
4584 int screen_full
= (window_box_height (w
)
4585 - next_screen_context_lines
* FRAME_LINE_HEIGHT (it
.f
));
4586 int dy
= n
* screen_full
;
4588 /* Note that move_it_vertically always moves the iterator to the
4589 start of a line. So, if the last line doesn't have a newline,
4590 we would end up at the start of the line ending at ZV. */
4592 move_it_vertically_backward (&it
, -dy
);
4594 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4595 MOVE_TO_POS
| MOVE_TO_Y
);
4598 move_it_by_lines (&it
, n
, 1);
4600 /* We failed if we find ZV is already on the screen (scrolling up,
4601 means there's nothing past the end), or if we can't start any
4602 earlier (scrolling down, means there's nothing past the top). */
4603 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4604 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4606 if (IT_CHARPOS (it
) == ZV
)
4608 if (it
.current_y
< it
.last_visible_y
4609 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4610 >= it
.last_visible_y
))
4612 /* The last line was only partially visible, make it fully
4614 w
->vscroll
= (it
.last_visible_y
4615 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4616 adjust_glyphs (it
.f
);
4621 Fsignal (Qend_of_buffer
, Qnil
);
4625 if (w
->vscroll
!= 0)
4626 /* The first line was only partially visible, make it fully
4632 Fsignal (Qbeginning_of_buffer
, Qnil
);
4635 /* If control gets here, then we vscrolled. */
4637 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
4639 /* Don't try to change the window start below. */
4645 int pos
= IT_CHARPOS (it
);
4648 /* If in the middle of a multi-glyph character move forward to
4649 the next character. */
4650 if (in_display_vector_p (&it
))
4653 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
4656 /* Set the window start, and set up the window for redisplay. */
4657 set_marker_restricted (w
->start
, make_number (pos
),
4659 bytepos
= XMARKER (w
->start
)->bytepos
;
4660 w
->start_at_line_beg
= ((pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n')
4662 w
->update_mode_line
= Qt
;
4663 XSETFASTINT (w
->last_modified
, 0);
4664 XSETFASTINT (w
->last_overlay_modified
, 0);
4665 /* Set force_start so that redisplay_window will run the
4666 window-scroll-functions. */
4667 w
->force_start
= Qt
;
4670 /* The rest of this function uses current_y in a nonstandard way,
4671 not including the height of the header line if any. */
4672 it
.current_y
= it
.vpos
= 0;
4674 /* Preserve the screen position if we should. */
4675 if (preserve_y
>= 0)
4677 /* If we have a header line, take account of it. */
4678 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4679 preserve_y
-= CURRENT_HEADER_LINE_HEIGHT (w
);
4681 move_it_to (&it
, -1, -1, preserve_y
, -1, MOVE_TO_Y
);
4682 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4686 /* Move PT out of scroll margins.
4687 This code wants current_y to be zero at the window start position
4688 even if there is a header line. */
4689 this_scroll_margin
= max (0, scroll_margin
);
4690 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->total_lines
) / 4);
4691 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
4695 /* We moved the window start towards ZV, so PT may be now
4696 in the scroll margin at the top. */
4697 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4698 while (it
.current_y
< this_scroll_margin
)
4700 int prev
= it
.current_y
;
4701 move_it_by_lines (&it
, 1, 1);
4702 if (prev
== it
.current_y
)
4705 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4709 int charpos
, bytepos
;
4711 /* We moved the window start towards BEGV, so PT may be now
4712 in the scroll margin at the bottom. */
4713 move_it_to (&it
, PT
, -1,
4714 it
.last_visible_y
- this_scroll_margin
- 1, -1,
4715 MOVE_TO_POS
| MOVE_TO_Y
);
4717 /* Save our position, in case it's correct. */
4718 charpos
= IT_CHARPOS (it
);
4719 bytepos
= IT_BYTEPOS (it
);
4721 /* See if point is on a partially visible line at the end. */
4722 move_it_by_lines (&it
, 1, 1);
4723 if (it
.current_y
> it
.last_visible_y
)
4724 /* The last line was only partially visible, so back up two
4725 lines to make sure we're on a fully visible line. */
4727 move_it_by_lines (&it
, -2, 0);
4728 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4731 /* No, the position we saved is OK, so use it. */
4732 SET_PT_BOTH (charpos
, bytepos
);
4738 /* Implementation of window_scroll that works based on screen lines.
4739 See the comment of window_scroll for parameter descriptions. */
4742 window_scroll_line_based (window
, n
, whole
, noerror
)
4748 register struct window
*w
= XWINDOW (window
);
4749 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
4750 register int pos
, pos_byte
;
4751 register int ht
= window_internal_height (w
);
4752 register Lisp_Object tem
;
4756 struct position posit
;
4759 /* If scrolling screen-fulls, compute the number of lines to
4760 scroll from the window's height. */
4762 n
*= max (1, ht
- next_screen_context_lines
);
4764 startpos
= marker_position (w
->start
);
4766 posit
= *compute_motion (startpos
, 0, 0, 0,
4768 -1, XINT (w
->hscroll
),
4770 original_vpos
= posit
.vpos
;
4772 XSETFASTINT (tem
, PT
);
4773 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
4777 Fvertical_motion (make_number (- (ht
/ 2)), window
);
4782 lose
= n
< 0 && PT
== BEGV
;
4783 Fvertical_motion (make_number (n
), window
);
4787 SET_PT_BOTH (opoint
, opoint_byte
);
4794 Fsignal (Qbeginning_of_buffer
, Qnil
);
4799 int this_scroll_margin
= scroll_margin
;
4801 /* Don't use a scroll margin that is negative or too large. */
4802 if (this_scroll_margin
< 0)
4803 this_scroll_margin
= 0;
4805 if (XINT (w
->total_lines
) < 4 * scroll_margin
)
4806 this_scroll_margin
= XINT (w
->total_lines
) / 4;
4808 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
4809 w
->start_at_line_beg
= bolp
;
4810 w
->update_mode_line
= Qt
;
4811 XSETFASTINT (w
->last_modified
, 0);
4812 XSETFASTINT (w
->last_overlay_modified
, 0);
4813 /* Set force_start so that redisplay_window will run
4814 the window-scroll-functions. */
4815 w
->force_start
= Qt
;
4817 if (whole
&& !NILP (Vscroll_preserve_screen_position
))
4819 SET_PT_BOTH (pos
, pos_byte
);
4820 Fvertical_motion (make_number (original_vpos
), window
);
4822 /* If we scrolled forward, put point enough lines down
4823 that it is outside the scroll margin. */
4828 if (this_scroll_margin
> 0)
4830 SET_PT_BOTH (pos
, pos_byte
);
4831 Fvertical_motion (make_number (this_scroll_margin
), window
);
4837 if (top_margin
<= opoint
)
4838 SET_PT_BOTH (opoint
, opoint_byte
);
4839 else if (!NILP (Vscroll_preserve_screen_position
))
4841 SET_PT_BOTH (pos
, pos_byte
);
4842 Fvertical_motion (make_number (original_vpos
), window
);
4845 SET_PT (top_margin
);
4851 /* If we scrolled backward, put point near the end of the window
4852 but not within the scroll margin. */
4853 SET_PT_BOTH (pos
, pos_byte
);
4854 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
4855 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
4858 bottom_margin
= PT
+ 1;
4860 if (bottom_margin
> opoint
)
4861 SET_PT_BOTH (opoint
, opoint_byte
);
4864 if (!NILP (Vscroll_preserve_screen_position
))
4866 SET_PT_BOTH (pos
, pos_byte
);
4867 Fvertical_motion (make_number (original_vpos
), window
);
4870 Fvertical_motion (make_number (-1), window
);
4879 Fsignal (Qend_of_buffer
, Qnil
);
4884 /* Scroll selected_window up or down. If N is nil, scroll a
4885 screen-full which is defined as the height of the window minus
4886 next_screen_context_lines. If N is the symbol `-', scroll.
4887 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4888 up. This is the guts of Fscroll_up and Fscroll_down. */
4891 scroll_command (n
, direction
)
4895 int count
= SPECPDL_INDEX ();
4897 xassert (abs (direction
) == 1);
4899 /* If selected window's buffer isn't current, make it current for
4900 the moment. But don't screw up if window_scroll gets an error. */
4901 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
4903 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4904 Fset_buffer (XWINDOW (selected_window
)->buffer
);
4906 /* Make redisplay consider other windows than just selected_window. */
4907 ++windows_or_buffers_changed
;
4911 window_scroll (selected_window
, direction
, 1, 0);
4912 else if (EQ (n
, Qminus
))
4913 window_scroll (selected_window
, -direction
, 1, 0);
4916 n
= Fprefix_numeric_value (n
);
4917 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
4920 unbind_to (count
, Qnil
);
4923 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
4924 doc
: /* Scroll text of current window upward ARG lines.
4925 If ARG is omitted or nil, scroll upward by a near full screen.
4926 A near full screen is `next-screen-context-lines' less than a full screen.
4927 Negative ARG means scroll downward.
4928 If ARG is the atom `-', scroll downward by nearly full screen.
4929 When calling from a program, supply as argument a number, nil, or `-'. */)
4933 scroll_command (arg
, 1);
4937 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
4938 doc
: /* Scroll text of current window down ARG lines.
4939 If ARG is omitted or nil, scroll down by a near full screen.
4940 A near full screen is `next-screen-context-lines' less than a full screen.
4941 Negative ARG means scroll upward.
4942 If ARG is the atom `-', scroll upward by nearly full screen.
4943 When calling from a program, supply as argument a number, nil, or `-'. */)
4947 scroll_command (arg
, -1);
4951 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
4952 doc
: /* Return the other window for \"other window scroll\" commands.
4953 If `other-window-scroll-buffer' is non-nil, a window
4954 showing that buffer is used.
4955 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4956 specifies the window. This takes precedence over
4957 `other-window-scroll-buffer'. */)
4962 if (MINI_WINDOW_P (XWINDOW (selected_window
))
4963 && !NILP (Vminibuf_scroll_window
))
4964 window
= Vminibuf_scroll_window
;
4965 /* If buffer is specified, scroll that buffer. */
4966 else if (!NILP (Vother_window_scroll_buffer
))
4968 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
4970 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
4974 /* Nothing specified; look for a neighboring window on the same
4976 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
4978 if (EQ (window
, selected_window
))
4979 /* That didn't get us anywhere; look for a window on another
4982 window
= Fnext_window (window
, Qnil
, Qt
);
4983 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
4984 && ! EQ (window
, selected_window
));
4987 CHECK_LIVE_WINDOW (window
);
4989 if (EQ (window
, selected_window
))
4990 error ("There is no other window");
4995 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
4996 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
4997 A near full screen is `next-screen-context-lines' less than a full screen.
4998 The next window is the one below the current one; or the one at the top
4999 if the current one is at the bottom. Negative ARG means scroll downward.
5000 If ARG is the atom `-', scroll downward by nearly full screen.
5001 When calling from a program, supply as argument a number, nil, or `-'.
5003 If `other-window-scroll-buffer' is non-nil, scroll the window
5004 showing that buffer, popping the buffer up if necessary.
5005 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5006 specifies the window to scroll. This takes precedence over
5007 `other-window-scroll-buffer'. */)
5013 int count
= SPECPDL_INDEX ();
5015 window
= Fother_window_for_scrolling ();
5016 w
= XWINDOW (window
);
5018 /* Don't screw up if window_scroll gets an error. */
5019 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5020 ++windows_or_buffers_changed
;
5022 Fset_buffer (w
->buffer
);
5023 SET_PT (marker_position (w
->pointm
));
5026 window_scroll (window
, 1, 1, 1);
5027 else if (EQ (arg
, Qminus
))
5028 window_scroll (window
, -1, 1, 1);
5034 window_scroll (window
, XINT (arg
), 0, 1);
5037 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5038 unbind_to (count
, Qnil
);
5043 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "P\np",
5044 doc
: /* Scroll selected window display ARG columns left.
5045 Default for ARG is window width minus 2.
5046 Value is the total amount of leftward horizontal scrolling in
5047 effect after the change.
5048 If SET_MINIMUM is non-nil, the new scroll amount becomes the
5049 lower bound for automatic scrolling, i.e. automatic scrolling
5050 will not scroll a window to a column less than the value returned
5051 by this function. This happens in an interactive call. */)
5053 register Lisp_Object arg
, set_minimum
;
5057 struct window
*w
= XWINDOW (selected_window
);
5060 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5062 arg
= Fprefix_numeric_value (arg
);
5064 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
5065 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5067 if (!NILP (set_minimum
))
5068 w
->min_hscroll
= w
->hscroll
;
5073 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "P\np",
5074 doc
: /* Scroll selected window display ARG columns right.
5075 Default for ARG is window width minus 2.
5076 Value is the total amount of leftward horizontal scrolling in
5077 effect after the change.
5078 If SET_MINIMUM is non-nil, the new scroll amount becomes the
5079 lower bound for automatic scrolling, i.e. automatic scrolling
5080 will not scroll a window to a column less than the value returned
5081 by this function. This happens in an interactive call. */)
5083 register Lisp_Object arg
, set_minimum
;
5087 struct window
*w
= XWINDOW (selected_window
);
5090 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5092 arg
= Fprefix_numeric_value (arg
);
5094 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
5095 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5097 if (!NILP (set_minimum
))
5098 w
->min_hscroll
= w
->hscroll
;
5103 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5104 doc
: /* Return the window which was selected when entering the minibuffer.
5105 Returns nil, if current window is not a minibuffer window. */)
5108 if (minibuf_level
> 0
5109 && MINI_WINDOW_P (XWINDOW (selected_window
))
5110 && WINDOW_LIVE_P (minibuf_selected_window
))
5111 return minibuf_selected_window
;
5116 /* Value is the number of lines actually displayed in window W,
5117 as opposed to its height. */
5120 displayed_window_lines (w
)
5124 struct text_pos start
;
5125 int height
= window_box_height (w
);
5126 struct buffer
*old_buffer
;
5129 if (XBUFFER (w
->buffer
) != current_buffer
)
5131 old_buffer
= current_buffer
;
5132 set_buffer_internal (XBUFFER (w
->buffer
));
5137 /* In case W->start is out of the accessible range, do something
5138 reasonable. This happens in Info mode when Info-scroll-down
5139 calls (recenter -1) while W->start is 1. */
5140 if (XMARKER (w
->start
)->charpos
< BEGV
)
5141 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5142 else if (XMARKER (w
->start
)->charpos
> ZV
)
5143 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
5145 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5147 start_display (&it
, w
, start
);
5148 move_it_vertically (&it
, height
);
5149 bottom_y
= line_bottom_y (&it
);
5151 /* rms: On a non-window display,
5152 the value of it.vpos at the bottom of the screen
5153 seems to be 1 larger than window_box_height (w).
5154 This kludge fixes a bug whereby (move-to-window-line -1)
5155 when ZV is on the last screen line
5156 moves to the previous screen line instead of the last one. */
5157 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5160 /* Add in empty lines at the bottom of the window. */
5161 if (bottom_y
< height
)
5163 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5164 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5168 set_buffer_internal (old_buffer
);
5174 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5175 doc
: /* Center point in window and redisplay frame.
5176 With prefix argument ARG, recenter putting point on screen line ARG
5177 relative to the current window. If ARG is negative, it counts up from the
5178 bottom of the window. (ARG should be less than the height of the window.)
5180 If ARG is omitted or nil, erase the entire frame and then
5181 redraw with point in the center of the current window.
5182 Just C-u as prefix means put point in the center of the window
5183 and redisplay normally--don't erase and redraw the frame. */)
5185 register Lisp_Object arg
;
5187 struct window
*w
= XWINDOW (selected_window
);
5188 struct buffer
*buf
= XBUFFER (w
->buffer
);
5189 struct buffer
*obuf
= current_buffer
;
5191 int charpos
, bytepos
;
5193 /* If redisplay is suppressed due to an error, try again. */
5194 obuf
->display_error_modiff
= 0;
5200 /* Invalidate pixel data calculated for all compositions. */
5201 for (i
= 0; i
< n_compositions
; i
++)
5202 composition_table
[i
]->font
= NULL
;
5204 Fredraw_frame (w
->frame
);
5205 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
5208 else if (CONSP (arg
)) /* Just C-u. */
5212 arg
= Fprefix_numeric_value (arg
);
5216 set_buffer_internal (buf
);
5218 /* Handle centering on a graphical frame specially. Such frames can
5219 have variable-height lines and centering point on the basis of
5220 line counts would lead to strange effects. */
5221 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5228 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5229 start_display (&it
, w
, pt
);
5230 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5231 charpos
= IT_CHARPOS (it
);
5232 bytepos
= IT_BYTEPOS (it
);
5234 else if (XINT (arg
) < 0)
5238 int nlines
= - XINT (arg
);
5239 int extra_line_spacing
;
5240 int h
= window_box_height (w
);
5242 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5243 start_display (&it
, w
, pt
);
5245 /* Be sure we have the exact height of the full line containing PT. */
5246 move_it_by_lines (&it
, 0, 1);
5248 /* The amount of pixels we have to move back is the window
5249 height minus what's displayed in the line containing PT,
5250 and the lines below. */
5253 move_it_by_lines (&it
, nlines
, 1);
5255 if (it
.vpos
== nlines
)
5259 /* Last line has no newline */
5260 h
-= line_bottom_y (&it
);
5264 /* Don't reserve space for extra line spacing of last line. */
5265 extra_line_spacing
= it
.max_extra_line_spacing
;
5267 /* If we can't move down NLINES lines because we hit
5268 the end of the buffer, count in some empty lines. */
5269 if (it
.vpos
< nlines
)
5272 extra_line_spacing
= it
.extra_line_spacing
;
5273 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5278 /* Now find the new top line (starting position) of the window. */
5279 start_display (&it
, w
, pt
);
5281 move_it_vertically_backward (&it
, h
);
5283 /* If extra line spacing is present, we may move too far
5284 back. This causes the last line to be only partially
5285 visible (which triggers redisplay to recenter that line
5286 in the middle), so move forward.
5287 But ignore extra line spacing on last line, as it is not
5288 considered to be part of the visible height of the line.
5290 h
+= extra_line_spacing
;
5291 while (-it
.current_y
> h
)
5292 move_it_by_lines (&it
, 1, 1);
5294 charpos
= IT_CHARPOS (it
);
5295 bytepos
= IT_BYTEPOS (it
);
5299 struct position pos
;
5300 pos
= *vmotion (PT
, - XINT (arg
), w
);
5301 charpos
= pos
.bufpos
;
5302 bytepos
= pos
.bytepos
;
5307 struct position pos
;
5308 int ht
= window_internal_height (w
);
5311 arg
= make_number (ht
/ 2);
5312 else if (XINT (arg
) < 0)
5313 arg
= make_number (XINT (arg
) + ht
);
5315 pos
= *vmotion (PT
, - XINT (arg
), w
);
5316 charpos
= pos
.bufpos
;
5317 bytepos
= pos
.bytepos
;
5320 /* Set the new window start. */
5321 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
5322 w
->window_end_valid
= Qnil
;
5324 w
->optional_new_start
= Qt
;
5326 if (bytepos
== BEGV_BYTE
|| FETCH_BYTE (bytepos
- 1) == '\n')
5327 w
->start_at_line_beg
= Qt
;
5329 w
->start_at_line_beg
= Qnil
;
5331 set_buffer_internal (obuf
);
5336 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5338 doc
: /* Return the height in lines of the text display area of WINDOW.
5339 This doesn't include the mode-line (or header-line if any) or any
5340 partial-height lines in the text display area. */)
5344 struct window
*w
= decode_window (window
);
5345 int pixel_height
= window_box_height (w
);
5346 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5347 return make_number (line_height
);
5352 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5354 doc
: /* Position point relative to window.
5355 With no argument, position point at center of window.
5356 An argument specifies vertical position within the window;
5357 zero means top of window, negative means relative to bottom of window. */)
5361 struct window
*w
= XWINDOW (selected_window
);
5365 window
= selected_window
;
5366 start
= marker_position (w
->start
);
5367 if (start
< BEGV
|| start
> ZV
)
5369 int height
= window_internal_height (w
);
5370 Fvertical_motion (make_number (- (height
/ 2)), window
);
5371 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
5372 w
->start_at_line_beg
= Fbolp ();
5373 w
->force_start
= Qt
;
5376 Fgoto_char (w
->start
);
5378 lines
= displayed_window_lines (w
);
5380 XSETFASTINT (arg
, lines
/ 2);
5383 arg
= Fprefix_numeric_value (arg
);
5385 XSETINT (arg
, XINT (arg
) + lines
);
5388 /* Skip past a partially visible first line. */
5390 XSETINT (arg
, XINT (arg
) + 1);
5392 return Fvertical_motion (arg
, window
);
5397 /***********************************************************************
5398 Window Configuration
5399 ***********************************************************************/
5401 struct save_window_data
5403 EMACS_INT size_from_Lisp_Vector_struct
;
5404 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5405 Lisp_Object frame_cols
, frame_lines
, frame_menu_bar_lines
;
5406 Lisp_Object frame_tool_bar_lines
;
5407 Lisp_Object selected_frame
;
5408 Lisp_Object current_window
;
5409 Lisp_Object current_buffer
;
5410 Lisp_Object minibuf_scroll_window
;
5411 Lisp_Object minibuf_selected_window
;
5412 Lisp_Object root_window
;
5413 Lisp_Object focus_frame
;
5414 /* Record the values of window-min-width and window-min-height
5415 so that window sizes remain consistent with them. */
5416 Lisp_Object min_width
, min_height
;
5417 /* A vector, each of whose elements is a struct saved_window
5419 Lisp_Object saved_windows
;
5422 /* This is saved as a Lisp_Vector */
5425 /* these first two must agree with struct Lisp_Vector in lisp.h */
5426 EMACS_INT size_from_Lisp_Vector_struct
;
5427 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5430 Lisp_Object buffer
, start
, pointm
, mark
;
5431 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5432 Lisp_Object hscroll
, min_hscroll
;
5433 Lisp_Object parent
, prev
;
5434 Lisp_Object start_at_line_beg
;
5435 Lisp_Object display_table
;
5436 Lisp_Object orig_top_line
, orig_total_lines
;
5437 Lisp_Object left_margin_cols
, right_margin_cols
;
5438 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
5439 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
;
5442 #define SAVED_WINDOW_VECTOR_SIZE 24 /* Arg to Fmake_vector */
5444 #define SAVED_WINDOW_N(swv,n) \
5445 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5447 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
5448 doc
: /* Return t if OBJECT is a window-configuration object. */)
5452 if (WINDOW_CONFIGURATIONP (object
))
5457 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
5458 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5462 register struct save_window_data
*data
;
5463 struct Lisp_Vector
*saved_windows
;
5465 if (! WINDOW_CONFIGURATIONP (config
))
5466 wrong_type_argument (Qwindow_configuration_p
, config
);
5468 data
= (struct save_window_data
*) XVECTOR (config
);
5469 saved_windows
= XVECTOR (data
->saved_windows
);
5470 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5473 DEFUN ("set-window-configuration", Fset_window_configuration
,
5474 Sset_window_configuration
, 1, 1, 0,
5475 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5476 CONFIGURATION must be a value previously returned
5477 by `current-window-configuration' (which see).
5478 If CONFIGURATION was made from a frame that is now deleted,
5479 only frame-independent values can be restored. In this case,
5480 the return value is nil. Otherwise the value is t. */)
5482 Lisp_Object configuration
;
5484 register struct save_window_data
*data
;
5485 struct Lisp_Vector
*saved_windows
;
5486 Lisp_Object new_current_buffer
;
5491 while (!WINDOW_CONFIGURATIONP (configuration
))
5492 wrong_type_argument (Qwindow_configuration_p
, configuration
);
5494 data
= (struct save_window_data
*) XVECTOR (configuration
);
5495 saved_windows
= XVECTOR (data
->saved_windows
);
5497 new_current_buffer
= data
->current_buffer
;
5498 if (NILP (XBUFFER (new_current_buffer
)->name
))
5499 new_current_buffer
= Qnil
;
5502 if (XBUFFER (new_current_buffer
) == current_buffer
)
5505 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
5508 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5511 /* If f is a dead frame, don't bother rebuilding its window tree.
5512 However, there is other stuff we should still try to do below. */
5513 if (FRAME_LIVE_P (f
))
5515 register struct window
*w
;
5516 register struct saved_window
*p
;
5517 struct window
*root_window
;
5518 struct window
**leaf_windows
;
5522 /* If the frame has been resized since this window configuration was
5523 made, we change the frame to the size specified in the
5524 configuration, restore the configuration, and then resize it
5525 back. We keep track of the prevailing height in these variables. */
5526 int previous_frame_lines
= FRAME_LINES (f
);
5527 int previous_frame_cols
= FRAME_COLS (f
);
5528 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
5529 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
5531 /* The mouse highlighting code could get screwed up
5532 if it runs during this. */
5535 if (XFASTINT (data
->frame_lines
) != previous_frame_lines
5536 || XFASTINT (data
->frame_cols
) != previous_frame_cols
)
5537 change_frame_size (f
, XFASTINT (data
->frame_lines
),
5538 XFASTINT (data
->frame_cols
), 0, 0, 0);
5539 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5540 if (XFASTINT (data
->frame_menu_bar_lines
)
5541 != previous_frame_menu_bar_lines
)
5542 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, make_number (0));
5543 #ifdef HAVE_WINDOW_SYSTEM
5544 if (XFASTINT (data
->frame_tool_bar_lines
)
5545 != previous_frame_tool_bar_lines
)
5546 x_set_tool_bar_lines (f
, data
->frame_tool_bar_lines
, make_number (0));
5550 /* "Swap out" point from the selected window
5551 into its buffer. We do this now, before
5552 restoring the window contents, and prevent it from
5553 being done later on when we select a new window. */
5554 if (! NILP (XWINDOW (selected_window
)->buffer
))
5556 w
= XWINDOW (selected_window
);
5557 set_marker_both (w
->pointm
,
5559 BUF_PT (XBUFFER (w
->buffer
)),
5560 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5563 windows_or_buffers_changed
++;
5564 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
5566 /* Problem: Freeing all matrices and later allocating them again
5567 is a serious redisplay flickering problem. What we would
5568 really like to do is to free only those matrices not reused
5570 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5572 = (struct window
**) alloca (count_windows (root_window
)
5573 * sizeof (struct window
*));
5574 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
5576 /* Temporarily avoid any problems with windows that are smaller
5577 than they are supposed to be. */
5578 window_min_height
= 1;
5579 window_min_width
= 1;
5582 Mark all windows now on frame as "deleted".
5583 Restoring the new configuration "undeletes" any that are in it.
5585 Save their current buffers in their height fields, since we may
5586 need it later, if a buffer saved in the configuration is now
5588 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5590 for (k
= 0; k
< saved_windows
->size
; k
++)
5592 p
= SAVED_WINDOW_N (saved_windows
, k
);
5593 w
= XWINDOW (p
->window
);
5596 if (!NILP (p
->parent
))
5597 w
->parent
= SAVED_WINDOW_N (saved_windows
,
5598 XFASTINT (p
->parent
))->window
;
5602 if (!NILP (p
->prev
))
5604 w
->prev
= SAVED_WINDOW_N (saved_windows
,
5605 XFASTINT (p
->prev
))->window
;
5606 XWINDOW (w
->prev
)->next
= p
->window
;
5611 if (!NILP (w
->parent
))
5613 if (EQ (p
->total_cols
, XWINDOW (w
->parent
)->total_cols
))
5615 XWINDOW (w
->parent
)->vchild
= p
->window
;
5616 XWINDOW (w
->parent
)->hchild
= Qnil
;
5620 XWINDOW (w
->parent
)->hchild
= p
->window
;
5621 XWINDOW (w
->parent
)->vchild
= Qnil
;
5626 /* If we squirreled away the buffer in the window's height,
5628 if (BUFFERP (w
->total_lines
))
5629 w
->buffer
= w
->total_lines
;
5630 w
->left_col
= p
->left_col
;
5631 w
->top_line
= p
->top_line
;
5632 w
->total_cols
= p
->total_cols
;
5633 w
->total_lines
= p
->total_lines
;
5634 w
->hscroll
= p
->hscroll
;
5635 w
->min_hscroll
= p
->min_hscroll
;
5636 w
->display_table
= p
->display_table
;
5637 w
->orig_top_line
= p
->orig_top_line
;
5638 w
->orig_total_lines
= p
->orig_total_lines
;
5639 w
->left_margin_cols
= p
->left_margin_cols
;
5640 w
->right_margin_cols
= p
->right_margin_cols
;
5641 w
->left_fringe_width
= p
->left_fringe_width
;
5642 w
->right_fringe_width
= p
->right_fringe_width
;
5643 w
->fringes_outside_margins
= p
->fringes_outside_margins
;
5644 w
->scroll_bar_width
= p
->scroll_bar_width
;
5645 w
->vertical_scroll_bar_type
= p
->vertical_scroll_bar_type
;
5646 XSETFASTINT (w
->last_modified
, 0);
5647 XSETFASTINT (w
->last_overlay_modified
, 0);
5649 /* Reinstall the saved buffer and pointers into it. */
5650 if (NILP (p
->buffer
))
5651 w
->buffer
= p
->buffer
;
5654 if (!NILP (XBUFFER (p
->buffer
)->name
))
5655 /* If saved buffer is alive, install it. */
5657 w
->buffer
= p
->buffer
;
5658 w
->start_at_line_beg
= p
->start_at_line_beg
;
5659 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
5660 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
5661 Fset_marker (XBUFFER (w
->buffer
)->mark
,
5662 p
->mark
, w
->buffer
);
5664 /* As documented in Fcurrent_window_configuration, don't
5665 restore the location of point in the buffer which was
5666 current when the window configuration was recorded. */
5667 if (!EQ (p
->buffer
, new_current_buffer
)
5668 && XBUFFER (p
->buffer
) == current_buffer
)
5669 Fgoto_char (w
->pointm
);
5671 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
5672 /* Else unless window has a live buffer, get one. */
5674 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
5675 /* This will set the markers to beginning of visible
5677 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
5678 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
5679 w
->start_at_line_beg
= Qt
;
5682 /* Keeping window's old buffer; make sure the markers
5685 /* Set window markers at start of visible range. */
5686 if (XMARKER (w
->start
)->buffer
== 0)
5687 set_marker_restricted (w
->start
, make_number (0),
5689 if (XMARKER (w
->pointm
)->buffer
== 0)
5690 set_marker_restricted_both (w
->pointm
, w
->buffer
,
5691 BUF_PT (XBUFFER (w
->buffer
)),
5692 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5693 w
->start_at_line_beg
= Qt
;
5698 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
5699 /* Prevent "swapping out point" in the old selected window
5700 using the buffer that has been restored into it.
5701 Use the point value from the beginning of this function
5702 since unshow_buffer (called from delete_all_subwindows)
5703 could have altered it. */
5704 selected_window
= Qnil
;
5705 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
5706 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
5707 make_number (old_point
),
5708 XWINDOW (data
->current_window
)->buffer
);
5710 Fselect_window (data
->current_window
, Qnil
);
5711 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
5714 if (NILP (data
->focus_frame
)
5715 || (FRAMEP (data
->focus_frame
)
5716 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
5717 Fredirect_frame_focus (frame
, data
->focus_frame
);
5719 #if 0 /* I don't understand why this is needed, and it causes problems
5720 when the frame's old selected window has been deleted. */
5721 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
5722 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
5726 /* Set the screen height to the value it had before this function. */
5727 if (previous_frame_lines
!= FRAME_LINES (f
)
5728 || previous_frame_cols
!= FRAME_COLS (f
))
5729 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
5731 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5732 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
5733 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
5735 #ifdef HAVE_WINDOW_SYSTEM
5736 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
5737 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
5742 /* Now, free glyph matrices in windows that were not reused. */
5743 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
5745 if (NILP (leaf_windows
[i
]->buffer
))
5747 /* Assert it's not reused as a combination. */
5748 xassert (NILP (leaf_windows
[i
]->hchild
)
5749 && NILP (leaf_windows
[i
]->vchild
));
5750 free_window_matrices (leaf_windows
[i
]);
5752 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
5760 /* Fselect_window will have made f the selected frame, so we
5761 reselect the proper frame here. Fhandle_switch_frame will change the
5762 selected window too, but that doesn't make the call to
5763 Fselect_window above totally superfluous; it still sets f's
5765 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
5766 do_switch_frame (data
->selected_frame
, 0, 0);
5768 if (! NILP (Vwindow_configuration_change_hook
)
5769 && ! NILP (Vrun_hooks
))
5770 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
5773 if (!NILP (new_current_buffer
))
5774 Fset_buffer (new_current_buffer
);
5776 /* Restore the minimum heights recorded in the configuration. */
5777 window_min_height
= XINT (data
->min_height
);
5778 window_min_width
= XINT (data
->min_width
);
5780 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
5781 minibuf_selected_window
= data
->minibuf_selected_window
;
5783 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
5786 /* Mark all windows now on frame as deleted
5787 by setting their buffers to nil. */
5790 delete_all_subwindows (w
)
5791 register struct window
*w
;
5793 if (!NILP (w
->next
))
5794 delete_all_subwindows (XWINDOW (w
->next
));
5795 if (!NILP (w
->vchild
))
5796 delete_all_subwindows (XWINDOW (w
->vchild
));
5797 if (!NILP (w
->hchild
))
5798 delete_all_subwindows (XWINDOW (w
->hchild
));
5800 w
->total_lines
= w
->buffer
; /* See Fset_window_configuration for excuse. */
5802 if (!NILP (w
->buffer
))
5805 /* We set all three of these fields to nil, to make sure that we can
5806 distinguish this dead window from any live window. Live leaf
5807 windows will have buffer set, and combination windows will have
5808 vchild or hchild set. */
5813 Vwindow_list
= Qnil
;
5817 count_windows (window
)
5818 register struct window
*window
;
5820 register int count
= 1;
5821 if (!NILP (window
->next
))
5822 count
+= count_windows (XWINDOW (window
->next
));
5823 if (!NILP (window
->vchild
))
5824 count
+= count_windows (XWINDOW (window
->vchild
));
5825 if (!NILP (window
->hchild
))
5826 count
+= count_windows (XWINDOW (window
->hchild
));
5831 /* Fill vector FLAT with leaf windows under W, starting at index I.
5832 Value is last index + 1. */
5835 get_leaf_windows (w
, flat
, i
)
5837 struct window
**flat
;
5842 if (!NILP (w
->hchild
))
5843 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
5844 else if (!NILP (w
->vchild
))
5845 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
5849 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5856 /* Return a pointer to the glyph W's physical cursor is on. Value is
5857 null if W's current matrix is invalid, so that no meaningfull glyph
5861 get_phys_cursor_glyph (w
)
5864 struct glyph_row
*row
;
5865 struct glyph
*glyph
;
5867 if (w
->phys_cursor
.vpos
>= 0
5868 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
5869 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
5871 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
5872 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
5881 save_window_save (window
, vector
, i
)
5883 struct Lisp_Vector
*vector
;
5886 register struct saved_window
*p
;
5887 register struct window
*w
;
5888 register Lisp_Object tem
;
5890 for (;!NILP (window
); window
= w
->next
)
5892 p
= SAVED_WINDOW_N (vector
, i
);
5893 w
= XWINDOW (window
);
5895 XSETFASTINT (w
->temslot
, i
); i
++;
5897 p
->buffer
= w
->buffer
;
5898 p
->left_col
= w
->left_col
;
5899 p
->top_line
= w
->top_line
;
5900 p
->total_cols
= w
->total_cols
;
5901 p
->total_lines
= w
->total_lines
;
5902 p
->hscroll
= w
->hscroll
;
5903 p
->min_hscroll
= w
->min_hscroll
;
5904 p
->display_table
= w
->display_table
;
5905 p
->orig_top_line
= w
->orig_top_line
;
5906 p
->orig_total_lines
= w
->orig_total_lines
;
5907 p
->left_margin_cols
= w
->left_margin_cols
;
5908 p
->right_margin_cols
= w
->right_margin_cols
;
5909 p
->left_fringe_width
= w
->left_fringe_width
;
5910 p
->right_fringe_width
= w
->right_fringe_width
;
5911 p
->fringes_outside_margins
= w
->fringes_outside_margins
;
5912 p
->scroll_bar_width
= w
->scroll_bar_width
;
5913 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
5914 if (!NILP (w
->buffer
))
5916 /* Save w's value of point in the window configuration.
5917 If w is the selected window, then get the value of point
5918 from the buffer; pointm is garbage in the selected window. */
5919 if (EQ (window
, selected_window
))
5921 p
->pointm
= Fmake_marker ();
5922 set_marker_both (p
->pointm
, w
->buffer
,
5923 BUF_PT (XBUFFER (w
->buffer
)),
5924 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5927 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
5929 p
->start
= Fcopy_marker (w
->start
, Qnil
);
5930 p
->start_at_line_beg
= w
->start_at_line_beg
;
5932 tem
= XBUFFER (w
->buffer
)->mark
;
5933 p
->mark
= Fcopy_marker (tem
, Qnil
);
5940 p
->start_at_line_beg
= Qnil
;
5943 if (NILP (w
->parent
))
5946 p
->parent
= XWINDOW (w
->parent
)->temslot
;
5951 p
->prev
= XWINDOW (w
->prev
)->temslot
;
5953 if (!NILP (w
->vchild
))
5954 i
= save_window_save (w
->vchild
, vector
, i
);
5955 if (!NILP (w
->hchild
))
5956 i
= save_window_save (w
->hchild
, vector
, i
);
5962 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
5963 Scurrent_window_configuration
, 0, 1, 0,
5964 doc
: /* Return an object representing the current window configuration of FRAME.
5965 If FRAME is nil or omitted, use the selected frame.
5966 This describes the number of windows, their sizes and current buffers,
5967 and for each displayed buffer, where display starts, and the positions of
5968 point and mark. An exception is made for point in the current buffer:
5969 its value is -not- saved.
5970 This also records the currently selected frame, and FRAME's focus
5971 redirection (see `redirect-frame-focus'). */)
5975 register Lisp_Object tem
;
5976 register int n_windows
;
5977 register struct save_window_data
*data
;
5978 register struct Lisp_Vector
*vec
;
5983 frame
= selected_frame
;
5984 CHECK_LIVE_FRAME (frame
);
5987 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5988 vec
= allocate_other_vector (VECSIZE (struct save_window_data
));
5989 data
= (struct save_window_data
*)vec
;
5991 XSETFASTINT (data
->frame_cols
, FRAME_COLS (f
));
5992 XSETFASTINT (data
->frame_lines
, FRAME_LINES (f
));
5993 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
5994 XSETFASTINT (data
->frame_tool_bar_lines
, FRAME_TOOL_BAR_LINES (f
));
5995 data
->selected_frame
= selected_frame
;
5996 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
5997 XSETBUFFER (data
->current_buffer
, current_buffer
);
5998 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
5999 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6000 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6001 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6002 XSETINT (data
->min_height
, window_min_height
);
6003 XSETINT (data
->min_width
, window_min_width
);
6004 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
6005 data
->saved_windows
= tem
;
6006 for (i
= 0; i
< n_windows
; i
++)
6007 XVECTOR (tem
)->contents
[i
]
6008 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
6009 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6010 XSETWINDOW_CONFIGURATION (tem
, data
);
6014 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
6016 doc
: /* Execute BODY, preserving window sizes and contents.
6017 Return the value of the last form in BODY.
6018 Restore which buffer appears in which window, where display starts,
6019 and the value of point and mark for each window.
6020 Also restore the choice of selected window.
6021 Also restore which buffer is current.
6022 Does not restore the value of point in current buffer.
6023 usage: (save-window-excursion BODY ...) */)
6027 register Lisp_Object val
;
6028 register int count
= SPECPDL_INDEX ();
6030 record_unwind_protect (Fset_window_configuration
,
6031 Fcurrent_window_configuration (Qnil
));
6032 val
= Fprogn (args
);
6033 return unbind_to (count
, val
);
6037 /***********************************************************************
6039 ***********************************************************************/
6041 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6043 doc
: /* Set width of marginal areas of window WINDOW.
6044 If WINDOW is nil, set margins of the currently selected window.
6045 Second arg LEFT-WIDTH specifies the number of character cells to
6046 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6047 does the same for the right marginal area. A nil width parameter
6048 means no margin. */)
6049 (window
, left
, right
)
6050 Lisp_Object window
, left
, right
;
6052 struct window
*w
= decode_window (window
);
6054 /* Translate negative or zero widths to nil.
6055 Margins that are too wide have to be checked elsewhere. */
6059 CHECK_NUMBER (left
);
6060 if (XINT (left
) <= 0)
6066 CHECK_NUMBER (right
);
6067 if (XINT (right
) <= 0)
6071 if (!EQ (w
->left_margin_cols
, left
)
6072 || !EQ (w
->right_margin_cols
, right
))
6074 w
->left_margin_cols
= left
;
6075 w
->right_margin_cols
= right
;
6077 adjust_window_margins (w
);
6079 ++windows_or_buffers_changed
;
6080 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6087 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6089 doc
: /* Get width of marginal areas of window WINDOW.
6090 If WINDOW is omitted or nil, use the currently selected window.
6091 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6092 If a marginal area does not exist, its width will be returned
6097 struct window
*w
= decode_window (window
);
6098 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
6103 /***********************************************************************
6105 ***********************************************************************/
6107 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6109 doc
: /* Set the fringe widths of window WINDOW.
6110 If WINDOW is nil, set the fringe widths of the currently selected
6112 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6113 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6114 fringe width. If a fringe width arg is nil, that means to use the
6115 frame's default fringe width. Default fringe widths can be set with
6116 the command `set-fringe-style'.
6117 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6118 outside of the display margins. By default, fringes are drawn between
6119 display marginal areas and the text area. */)
6120 (window
, left
, right
, outside_margins
)
6121 Lisp_Object window
, left
, right
, outside_margins
;
6123 struct window
*w
= decode_window (window
);
6126 CHECK_NATNUM (left
);
6128 CHECK_NATNUM (right
);
6130 if (!EQ (w
->left_fringe_width
, left
)
6131 || !EQ (w
->right_fringe_width
, right
)
6132 || !EQ (w
->fringes_outside_margins
, outside_margins
))
6134 w
->left_fringe_width
= left
;
6135 w
->right_fringe_width
= right
;
6136 w
->fringes_outside_margins
= outside_margins
;
6138 adjust_window_margins (w
);
6140 clear_glyph_matrix (w
->current_matrix
);
6141 w
->window_end_valid
= Qnil
;
6143 ++windows_or_buffers_changed
;
6144 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6151 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6153 doc
: /* Get width of fringes of window WINDOW.
6154 If WINDOW is omitted or nil, use the currently selected window.
6155 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6159 struct window
*w
= decode_window (window
);
6160 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6161 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6162 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
) ?
6163 Qt
: Qnil
), Qnil
)));
6168 /***********************************************************************
6170 ***********************************************************************/
6172 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
, Sset_window_scroll_bars
,
6174 doc
: /* Set width and type of scroll bars of window WINDOW.
6175 If window is nil, set scroll bars of the currently selected window.
6176 Second parameter WIDTH specifies the pixel width for the scroll bar;
6177 this is automatically adjusted to a multiple of the frame column width.
6178 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6179 bar: left, right, or nil.
6180 If WIDTH is nil, use the frame's scroll-bar width.
6181 If TYPE is t, use the frame's scroll-bar type. */)
6182 (window
, width
, vertical_type
, horizontal_type
)
6183 Lisp_Object window
, width
, vertical_type
, horizontal_type
;
6185 struct window
*w
= decode_window (window
);
6189 CHECK_NATNUM (width
);
6191 if (XINT (width
) == 0)
6192 vertical_type
= Qnil
;
6195 if (!(EQ (vertical_type
, Qnil
)
6196 || EQ (vertical_type
, Qleft
)
6197 || EQ (vertical_type
, Qright
)
6198 || EQ (vertical_type
, Qt
)))
6199 error ("Invalid type of vertical scroll bar");
6201 if (!EQ (w
->scroll_bar_width
, width
)
6202 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6204 w
->scroll_bar_width
= width
;
6205 w
->vertical_scroll_bar_type
= vertical_type
;
6207 adjust_window_margins (w
);
6209 clear_glyph_matrix (w
->current_matrix
);
6210 w
->window_end_valid
= Qnil
;
6212 ++windows_or_buffers_changed
;
6213 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6220 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6222 doc
: /* Get width and type of scroll bars of window WINDOW.
6223 If WINDOW is omitted or nil, use the currently selected window.
6224 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6225 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6230 struct window
*w
= decode_window (window
);
6231 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6232 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6233 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6234 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6235 Fcons (w
->vertical_scroll_bar_type
,
6236 Fcons (Qnil
, Qnil
))));
6241 /***********************************************************************
6243 ***********************************************************************/
6245 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6246 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6247 Use the selected window if WINDOW is nil or omitted.
6248 Normally, value is a multiple of the canonical character height of WINDOW;
6249 optional second arg PIXELS_P means value is measured in pixels. */)
6251 Lisp_Object window
, pixels_p
;
6258 window
= selected_window
;
6260 CHECK_WINDOW (window
);
6261 w
= XWINDOW (window
);
6262 f
= XFRAME (w
->frame
);
6264 if (FRAME_WINDOW_P (f
))
6265 result
= (NILP (pixels_p
)
6266 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6267 : make_number (-w
->vscroll
));
6269 result
= make_number (0);
6274 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6276 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6277 WINDOW nil means use the selected window. Normally, VSCROLL is a
6278 non-negative multiple of the canonical character height of WINDOW;
6279 optional third arg PIXELS_P non-nil means that VSCROLL is in pixels.
6280 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6281 corresponds to an integral number of pixels. The return value is the
6282 result of this rounding.
6283 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6284 (window
, vscroll
, pixels_p
)
6285 Lisp_Object window
, vscroll
, pixels_p
;
6291 window
= selected_window
;
6293 CHECK_WINDOW (window
);
6294 CHECK_NUMBER_OR_FLOAT (vscroll
);
6296 w
= XWINDOW (window
);
6297 f
= XFRAME (w
->frame
);
6299 if (FRAME_WINDOW_P (f
))
6301 int old_dy
= w
->vscroll
;
6303 w
->vscroll
= - (NILP (pixels_p
)
6304 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
6305 : XFLOATINT (vscroll
));
6306 w
->vscroll
= min (w
->vscroll
, 0);
6308 /* Adjust glyph matrix of the frame if the virtual display
6309 area becomes larger than before. */
6310 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
6313 /* Prevent redisplay shortcuts. */
6314 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
6317 return Fwindow_vscroll (window
, pixels_p
);
6321 /* Call FN for all leaf windows on frame F. FN is called with the
6322 first argument being a pointer to the leaf window, and with
6323 additional argument USER_DATA. Stops when FN returns 0. */
6326 foreach_window (f
, fn
, user_data
)
6328 int (* fn
) P_ ((struct window
*, void *));
6331 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
6335 /* Helper function for foreach_window. Call FN for all leaf windows
6336 reachable from W. FN is called with the first argument being a
6337 pointer to the leaf window, and with additional argument USER_DATA.
6338 Stop when FN returns 0. Value is 0 if stopped by FN. */
6341 foreach_window_1 (w
, fn
, user_data
)
6343 int (* fn
) P_ ((struct window
*, void *));
6348 for (cont
= 1; w
&& cont
;)
6350 if (!NILP (w
->hchild
))
6351 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
6352 else if (!NILP (w
->vchild
))
6353 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
6355 cont
= fn (w
, user_data
);
6357 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6364 /* Freeze or unfreeze the window start of W unless it is a
6365 mini-window or the selected window. FREEZE_P non-null means freeze
6366 the window start. */
6369 freeze_window_start (w
, freeze_p
)
6373 if (w
== XWINDOW (selected_window
)
6374 || MINI_WINDOW_P (w
)
6375 || (MINI_WINDOW_P (XWINDOW (selected_window
))
6376 && ! NILP (Vminibuf_scroll_window
)
6377 && w
== XWINDOW (Vminibuf_scroll_window
)))
6380 w
->frozen_window_start_p
= freeze_p
!= NULL
;
6385 /* Freeze or unfreeze the window starts of all leaf windows on frame
6386 F, except the selected window and a mini-window. FREEZE_P non-zero
6387 means freeze the window start. */
6390 freeze_window_starts (f
, freeze_p
)
6394 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
6398 /***********************************************************************
6400 ***********************************************************************/
6402 /* Return 1 if window configurations C1 and C2
6403 describe the same state of affairs. This is used by Fequal. */
6406 compare_window_configurations (c1
, c2
, ignore_positions
)
6408 int ignore_positions
;
6410 register struct save_window_data
*d1
, *d2
;
6411 struct Lisp_Vector
*sw1
, *sw2
;
6414 if (!WINDOW_CONFIGURATIONP (c1
))
6415 wrong_type_argument (Qwindow_configuration_p
, c1
);
6416 if (!WINDOW_CONFIGURATIONP (c2
))
6417 wrong_type_argument (Qwindow_configuration_p
, c2
);
6419 d1
= (struct save_window_data
*) XVECTOR (c1
);
6420 d2
= (struct save_window_data
*) XVECTOR (c2
);
6421 sw1
= XVECTOR (d1
->saved_windows
);
6422 sw2
= XVECTOR (d2
->saved_windows
);
6424 if (! EQ (d1
->frame_cols
, d2
->frame_cols
))
6426 if (! EQ (d1
->frame_lines
, d2
->frame_lines
))
6428 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
6430 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
6432 /* Don't compare the current_window field directly.
6433 Instead see w1_is_current and w2_is_current, below. */
6434 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
6436 if (! ignore_positions
)
6438 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
6440 if (! EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
))
6443 /* Don't compare the root_window field.
6444 We don't require the two configurations
6445 to use the same window object,
6446 and the two root windows must be equivalent
6447 if everything else compares equal. */
6448 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
6450 if (! EQ (d1
->min_width
, d2
->min_width
))
6452 if (! EQ (d1
->min_height
, d2
->min_height
))
6455 /* Verify that the two confis have the same number of windows. */
6456 if (sw1
->size
!= sw2
->size
)
6459 for (i
= 0; i
< sw1
->size
; i
++)
6461 struct saved_window
*p1
, *p2
;
6462 int w1_is_current
, w2_is_current
;
6464 p1
= SAVED_WINDOW_N (sw1
, i
);
6465 p2
= SAVED_WINDOW_N (sw2
, i
);
6467 /* Verify that the current windows in the two
6468 configurations correspond to each other. */
6469 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
6470 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
6472 if (w1_is_current
!= w2_is_current
)
6475 /* Verify that the corresponding windows do match. */
6476 if (! EQ (p1
->buffer
, p2
->buffer
))
6478 if (! EQ (p1
->left_col
, p2
->left_col
))
6480 if (! EQ (p1
->top_line
, p2
->top_line
))
6482 if (! EQ (p1
->total_cols
, p2
->total_cols
))
6484 if (! EQ (p1
->total_lines
, p2
->total_lines
))
6486 if (! EQ (p1
->display_table
, p2
->display_table
))
6488 if (! EQ (p1
->parent
, p2
->parent
))
6490 if (! EQ (p1
->prev
, p2
->prev
))
6492 if (! ignore_positions
)
6494 if (! EQ (p1
->hscroll
, p2
->hscroll
))
6496 if (!EQ (p1
->min_hscroll
, p2
->min_hscroll
))
6498 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
6500 if (NILP (Fequal (p1
->start
, p2
->start
)))
6502 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
6504 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
6507 if (! EQ (p1
->left_margin_cols
, p2
->left_margin_cols
))
6509 if (! EQ (p1
->right_margin_cols
, p2
->right_margin_cols
))
6511 if (! EQ (p1
->left_fringe_width
, p2
->left_fringe_width
))
6513 if (! EQ (p1
->right_fringe_width
, p2
->right_fringe_width
))
6515 if (! EQ (p1
->fringes_outside_margins
, p2
->fringes_outside_margins
))
6517 if (! EQ (p1
->scroll_bar_width
, p2
->scroll_bar_width
))
6519 if (! EQ (p1
->vertical_scroll_bar_type
, p2
->vertical_scroll_bar_type
))
6526 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
6527 Scompare_window_configurations
, 2, 2, 0,
6528 doc
: /* Compare two window configurations as regards the structure of windows.
6529 This function ignores details such as the values of point and mark
6530 and scrolling positions. */)
6534 if (compare_window_configurations (x
, y
, 1))
6542 struct frame
*f
= make_terminal_frame ();
6543 XSETFRAME (selected_frame
, f
);
6544 Vterminal_frame
= selected_frame
;
6545 minibuf_window
= f
->minibuffer_window
;
6546 selected_window
= f
->selected_window
;
6547 last_nonminibuf_frame
= f
;
6549 window_initialized
= 1;
6555 Vwindow_list
= Qnil
;
6561 Qwindow_size_fixed
= intern ("window-size-fixed");
6562 staticpro (&Qwindow_size_fixed
);
6564 staticpro (&Qwindow_configuration_change_hook
);
6565 Qwindow_configuration_change_hook
6566 = intern ("window-configuration-change-hook");
6568 Qwindowp
= intern ("windowp");
6569 staticpro (&Qwindowp
);
6571 Qwindow_configuration_p
= intern ("window-configuration-p");
6572 staticpro (&Qwindow_configuration_p
);
6574 Qwindow_live_p
= intern ("window-live-p");
6575 staticpro (&Qwindow_live_p
);
6577 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
6578 staticpro (&Qtemp_buffer_show_hook
);
6580 staticpro (&Vwindow_list
);
6582 minibuf_selected_window
= Qnil
;
6583 staticpro (&minibuf_selected_window
);
6585 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
6586 doc
: /* Non-nil means call as function to display a help buffer.
6587 The function is called with one argument, the buffer to be displayed.
6588 Used by `with-output-to-temp-buffer'.
6589 If this function is used, then it must do the entire job of showing
6590 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6591 Vtemp_buffer_show_function
= Qnil
;
6593 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
6594 doc
: /* If non-nil, function to call to handle `display-buffer'.
6595 It will receive two args, the buffer and a flag which if non-nil means
6596 that the currently selected window is not acceptable.
6597 It should choose or create a window, display the specified buffer in it,
6598 and return the window.
6599 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'
6600 work using this function. */);
6601 Vdisplay_buffer_function
= Qnil
;
6603 DEFVAR_LISP ("even-window-heights", &Veven_window_heights
,
6604 doc
: /* *If non-nil, `display-buffer' should even the window heights.
6605 If nil, `display-buffer' will leave the window configuration alone. */);
6606 Veven_window_heights
= Qt
;
6608 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
6609 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6610 Vminibuf_scroll_window
= Qnil
;
6612 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows
,
6613 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6614 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6615 is displayed in the `mode-line' face. */);
6616 mode_line_in_non_selected_windows
= 1;
6618 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
6619 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6620 Vother_window_scroll_buffer
= Qnil
;
6622 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
6623 doc
: /* *Non-nil means `display-buffer' should make a separate frame. */);
6626 DEFVAR_BOOL ("display-buffer-reuse-frames", &display_buffer_reuse_frames
,
6627 doc
: /* *Non-nil means `display-buffer' should reuse frames.
6628 If the buffer in question is already displayed in a frame, raise that frame. */);
6629 display_buffer_reuse_frames
= 0;
6631 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
6632 doc
: /* Function to call to handle automatic new frame creation.
6633 It is called with no arguments and should return a newly created frame.
6635 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'
6636 where `pop-up-frame-alist' would hold the default frame parameters. */);
6637 Vpop_up_frame_function
= Qnil
;
6639 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
6640 doc
: /* *List of buffer names that should have their own special frames.
6641 Displaying a buffer whose name is in this list makes a special frame for it
6642 using `special-display-function'. See also `special-display-regexps'.
6644 An element of the list can be a list instead of just a string.
6645 There are two ways to use a list as an element:
6646 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)
6647 In the first case, the FRAME-PARAMETERS are pairs of the form
6648 \(PARAMETER . VALUE); these parameter values are used to create the frame.
6649 In the second case, FUNCTION is called with BUFFER as the first argument,
6650 followed by the OTHER-ARGS--it can display BUFFER in any way it likes.
6651 All this is done by the function found in `special-display-function'.
6653 If the specified frame parameters include (same-buffer . t), the
6654 buffer is displayed in the currently selected window. Otherwise, if
6655 they include (same-frame . t), the buffer is displayed in a new window
6656 in the currently selected frame.
6658 If this variable appears \"not to work\", because you add a name to it
6659 but that buffer still appears in the selected window, look at the
6660 values of `same-window-buffer-names' and `same-window-regexps'.
6661 Those variables take precedence over this one. */);
6662 Vspecial_display_buffer_names
= Qnil
;
6664 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
6665 doc
: /* *List of regexps saying which buffers should have their own special frames.
6666 If a buffer name matches one of these regexps, it gets its own frame.
6667 Displaying a buffer whose name is in this list makes a special frame for it
6668 using `special-display-function'.
6670 An element of the list can be a list instead of just a string.
6671 There are two ways to use a list as an element:
6672 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)
6673 In the first case, the FRAME-PARAMETERS are pairs of the form
6674 \(PARAMETER . VALUE); these parameter values are used to create the frame.
6675 In the second case, FUNCTION is called with BUFFER as the first argument,
6676 followed by the OTHER-ARGS--it can display the buffer in any way it likes.
6677 All this is done by the function found in `special-display-function'.
6679 If the specified frame parameters include (same-buffer . t), the
6680 buffer is displayed in the currently selected window. Otherwise, if
6681 they include (same-frame . t), the buffer is displayed in a new window
6682 in the currently selected frame.
6684 If this variable appears \"not to work\", because you add a regexp to it
6685 but the matching buffers still appear in the selected window, look at the
6686 values of `same-window-buffer-names' and `same-window-regexps'.
6687 Those variables take precedence over this one. */);
6688 Vspecial_display_regexps
= Qnil
;
6690 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
6691 doc
: /* Function to call to make a new frame for a special buffer.
6692 It is called with two arguments, the buffer and optional buffer specific
6693 data, and should return a window displaying that buffer.
6694 The default value normally makes a separate frame for the buffer,
6695 using `special-display-frame-alist' to specify the frame parameters.
6696 But if the buffer specific data includes (same-buffer . t) then the
6697 buffer is displayed in the current selected window.
6698 Otherwise if it includes (same-frame . t) then the buffer is displayed in
6699 a new window in the currently selected frame.
6701 A buffer is special if it is listed in `special-display-buffer-names'
6702 or matches a regexp in `special-display-regexps'. */);
6703 Vspecial_display_function
= Qnil
;
6705 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
6706 doc
: /* *List of buffer names that should appear in the selected window.
6707 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'
6708 switches to it in the selected window, rather than making it appear
6709 in some other window.
6711 An element of the list can be a cons cell instead of just a string.
6712 Then the car must be a string, which specifies the buffer name.
6713 This is for compatibility with `special-display-buffer-names';
6714 the cdr of the cons cell is ignored.
6716 See also `same-window-regexps'. */);
6717 Vsame_window_buffer_names
= Qnil
;
6719 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
6720 doc
: /* *List of regexps saying which buffers should appear in the selected window.
6721 If a buffer name matches one of these regexps, then displaying it
6722 using `display-buffer' or `pop-to-buffer' switches to it
6723 in the selected window, rather than making it appear in some other window.
6725 An element of the list can be a cons cell instead of just a string.
6726 Then the car must be a string, which specifies the buffer name.
6727 This is for compatibility with `special-display-buffer-names';
6728 the cdr of the cons cell is ignored.
6730 See also `same-window-buffer-names'. */);
6731 Vsame_window_regexps
= Qnil
;
6733 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
6734 doc
: /* *Non-nil means display-buffer should make new windows. */);
6737 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
6738 doc
: /* *Number of lines of continuity when scrolling by screenfuls. */);
6739 next_screen_context_lines
= 2;
6741 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
6742 doc
: /* *A window must be at least this tall to be eligible for splitting by `display-buffer'.
6743 If there is only one window, it is split regardless of this value. */);
6744 split_height_threshold
= 500;
6746 DEFVAR_INT ("window-min-height", &window_min_height
,
6747 doc
: /* *Delete any window less than this tall (including its mode line). */);
6748 window_min_height
= 4;
6750 DEFVAR_INT ("window-min-width", &window_min_width
,
6751 doc
: /* *Delete any window less than this wide. */);
6752 window_min_width
= 10;
6754 DEFVAR_LISP ("scroll-preserve-screen-position",
6755 &Vscroll_preserve_screen_position
,
6756 doc
: /* *Non-nil means scroll commands move point to keep its screen line unchanged. */);
6757 Vscroll_preserve_screen_position
= Qnil
;
6759 DEFVAR_LISP ("window-configuration-change-hook",
6760 &Vwindow_configuration_change_hook
,
6761 doc
: /* Functions to call when window configuration changes.
6762 The selected frame is the one whose configuration has changed. */);
6763 Vwindow_configuration_change_hook
= Qnil
;
6765 DEFVAR_BOOL ("window-size-fixed", &window_size_fixed
,
6766 doc
: /* Non-nil in a buffer means windows displaying the buffer are fixed-size.
6767 If the value is`height', then only the window's height is fixed.
6768 If the value is `width', then only the window's width is fixed.
6769 Any other non-nil value fixes both the width and the height.
6770 Emacs won't change the size of any window displaying that buffer,
6771 unless you explicitly change the size, or Emacs has no other choice. */);
6772 Fmake_variable_buffer_local (Qwindow_size_fixed
);
6773 window_size_fixed
= 0;
6775 defsubr (&Sselected_window
);
6776 defsubr (&Sminibuffer_window
);
6777 defsubr (&Swindow_minibuffer_p
);
6778 defsubr (&Swindowp
);
6779 defsubr (&Swindow_live_p
);
6780 defsubr (&Spos_visible_in_window_p
);
6781 defsubr (&Swindow_buffer
);
6782 defsubr (&Swindow_height
);
6783 defsubr (&Swindow_width
);
6784 defsubr (&Swindow_hscroll
);
6785 defsubr (&Sset_window_hscroll
);
6786 defsubr (&Swindow_redisplay_end_trigger
);
6787 defsubr (&Sset_window_redisplay_end_trigger
);
6788 defsubr (&Swindow_edges
);
6789 defsubr (&Swindow_pixel_edges
);
6790 defsubr (&Swindow_inside_edges
);
6791 defsubr (&Swindow_inside_pixel_edges
);
6792 defsubr (&Scoordinates_in_window_p
);
6793 defsubr (&Swindow_at
);
6794 defsubr (&Swindow_point
);
6795 defsubr (&Swindow_start
);
6796 defsubr (&Swindow_end
);
6797 defsubr (&Sset_window_point
);
6798 defsubr (&Sset_window_start
);
6799 defsubr (&Swindow_dedicated_p
);
6800 defsubr (&Sset_window_dedicated_p
);
6801 defsubr (&Swindow_display_table
);
6802 defsubr (&Sset_window_display_table
);
6803 defsubr (&Snext_window
);
6804 defsubr (&Sprevious_window
);
6805 defsubr (&Sother_window
);
6806 defsubr (&Sget_lru_window
);
6807 defsubr (&Sget_largest_window
);
6808 defsubr (&Sget_buffer_window
);
6809 defsubr (&Sdelete_other_windows
);
6810 defsubr (&Sdelete_windows_on
);
6811 defsubr (&Sreplace_buffer_in_windows
);
6812 defsubr (&Sdelete_window
);
6813 defsubr (&Sset_window_buffer
);
6814 defsubr (&Sselect_window
);
6815 defsubr (&Sspecial_display_p
);
6816 defsubr (&Ssame_window_p
);
6817 defsubr (&Sdisplay_buffer
);
6818 defsubr (&Sforce_window_update
);
6819 defsubr (&Ssplit_window
);
6820 defsubr (&Senlarge_window
);
6821 defsubr (&Sshrink_window
);
6822 defsubr (&Sscroll_up
);
6823 defsubr (&Sscroll_down
);
6824 defsubr (&Sscroll_left
);
6825 defsubr (&Sscroll_right
);
6826 defsubr (&Sother_window_for_scrolling
);
6827 defsubr (&Sscroll_other_window
);
6828 defsubr (&Sminibuffer_selected_window
);
6829 defsubr (&Srecenter
);
6830 defsubr (&Swindow_text_height
);
6831 defsubr (&Smove_to_window_line
);
6832 defsubr (&Swindow_configuration_p
);
6833 defsubr (&Swindow_configuration_frame
);
6834 defsubr (&Sset_window_configuration
);
6835 defsubr (&Scurrent_window_configuration
);
6836 defsubr (&Ssave_window_excursion
);
6837 defsubr (&Sset_window_margins
);
6838 defsubr (&Swindow_margins
);
6839 defsubr (&Sset_window_fringes
);
6840 defsubr (&Swindow_fringes
);
6841 defsubr (&Sset_window_scroll_bars
);
6842 defsubr (&Swindow_scroll_bars
);
6843 defsubr (&Swindow_vscroll
);
6844 defsubr (&Sset_window_vscroll
);
6845 defsubr (&Scompare_window_configurations
);
6846 defsubr (&Swindow_list
);
6852 initial_define_key (control_x_map
, '1', "delete-other-windows");
6853 initial_define_key (control_x_map
, '2', "split-window");
6854 initial_define_key (control_x_map
, '0', "delete-window");
6855 initial_define_key (control_x_map
, 'o', "other-window");
6856 initial_define_key (control_x_map
, '^', "enlarge-window");
6857 initial_define_key (control_x_map
, '<', "scroll-left");
6858 initial_define_key (control_x_map
, '>', "scroll-right");
6860 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
6861 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
6862 initial_define_key (meta_map
, 'v', "scroll-down");
6864 initial_define_key (global_map
, Ctl('L'), "recenter");
6865 initial_define_key (meta_map
, 'r', "move-to-window-line");
6868 /* arch-tag: 90a9c576-0590-48f1-a5f1-6c96a0452d9f
6869 (do not change this comment) */