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 /* Nonzero 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 ();
244 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
245 XSETFASTINT (p
->left_col
, 0);
246 XSETFASTINT (p
->top_line
, 0);
247 XSETFASTINT (p
->total_lines
, 0);
248 XSETFASTINT (p
->total_cols
, 0);
249 XSETFASTINT (p
->hscroll
, 0);
250 XSETFASTINT (p
->min_hscroll
, 0);
251 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
252 p
->start
= Fmake_marker ();
253 p
->pointm
= Fmake_marker ();
254 XSETFASTINT (p
->use_time
, 0);
256 p
->display_table
= Qnil
;
258 p
->pseudo_window_p
= 0;
259 bzero (&p
->cursor
, sizeof (p
->cursor
));
260 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
261 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
262 p
->desired_matrix
= p
->current_matrix
= 0;
263 p
->phys_cursor_type
= -1;
264 p
->phys_cursor_width
= -1;
265 p
->must_be_updated_p
= 0;
266 XSETFASTINT (p
->window_end_vpos
, 0);
267 XSETFASTINT (p
->window_end_pos
, 0);
268 p
->window_end_valid
= Qnil
;
271 XSETFASTINT (p
->last_point
, 0);
272 p
->frozen_window_start_p
= 0;
273 p
->height_fixed_p
= 0;
274 p
->last_cursor_off_p
= p
->cursor_off_p
= 0;
275 p
->left_margin_cols
= Qnil
;
276 p
->right_margin_cols
= Qnil
;
277 p
->left_fringe_width
= Qnil
;
278 p
->right_fringe_width
= Qnil
;
279 p
->fringes_outside_margins
= Qnil
;
280 p
->scroll_bar_width
= Qnil
;
281 p
->vertical_scroll_bar_type
= Qt
;
282 p
->overlay_arrow_bitmap
= 0;
288 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
289 doc
: /* Return the window that the cursor now appears in and commands apply to. */)
292 return selected_window
;
295 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
296 doc
: /* Return the window used now for minibuffers.
297 If the optional argument FRAME is specified, return the minibuffer window
298 used by that frame. */)
303 frame
= selected_frame
;
304 CHECK_LIVE_FRAME (frame
);
305 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
308 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
309 doc
: /* Returns non-nil if WINDOW is a minibuffer window.
310 WINDOW defaults to the selected window. */)
314 struct window
*w
= decode_window (window
);
315 return MINI_WINDOW_P (w
) ? Qt
: Qnil
;
319 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
320 Spos_visible_in_window_p
, 0, 3, 0,
321 doc
: /* Return t if position POS is currently on the frame in WINDOW.
322 Return nil if that position is scrolled vertically out of view.
323 If a character is only partially visible, nil is returned, unless the
324 optional argument PARTIALLY is non-nil.
325 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
327 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
328 return value is a list (X Y PARTIAL) where X and Y are the pixel relative
330 (pos
, window
, partially
)
331 Lisp_Object pos
, window
, partially
;
333 register struct window
*w
;
335 register struct buffer
*buf
;
337 Lisp_Object in_window
= Qnil
;
341 w
= decode_window (window
);
342 buf
= XBUFFER (w
->buffer
);
343 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
347 CHECK_NUMBER_COERCE_MARKER (pos
);
350 else if (w
== XWINDOW (selected_window
))
353 posint
= XMARKER (w
->pointm
)->charpos
;
355 /* If position is above window start or outside buffer boundaries,
356 or if window start is out of range, position is not visible. */
357 if (posint
>= CHARPOS (top
)
358 && posint
<= BUF_ZV (buf
)
359 && CHARPOS (top
) >= BUF_BEGV (buf
)
360 && CHARPOS (top
) <= BUF_ZV (buf
)
361 && pos_visible_p (w
, posint
, &fully_p
, &x
, &y
, NILP (partially
))
362 && (!NILP (partially
) || fully_p
))
365 if (!NILP (in_window
) && !NILP (partially
))
366 in_window
= Fcons (make_number (x
),
367 Fcons (make_number (y
),
368 Fcons (fully_p
? Qt
: Qnil
, Qnil
)));
373 static struct window
*
374 decode_window (window
)
375 register Lisp_Object window
;
378 return XWINDOW (selected_window
);
380 CHECK_LIVE_WINDOW (window
);
381 return XWINDOW (window
);
384 static struct window
*
385 decode_any_window (window
)
386 register Lisp_Object window
;
389 return XWINDOW (selected_window
);
391 CHECK_WINDOW (window
);
392 return XWINDOW (window
);
395 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
396 doc
: /* Return the buffer that WINDOW is displaying.
397 WINDOW defaults to the selected window. */)
401 return decode_window (window
)->buffer
;
404 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
405 doc
: /* Return the number of lines in WINDOW (including its mode line). */)
409 return decode_any_window (window
)->total_lines
;
412 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
413 doc
: /* Return the number of display columns in WINDOW.
414 This is the width that is usable columns available for text in WINDOW.
415 If you want to find out how many columns WINDOW takes up,
416 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
420 return make_number (window_box_text_cols (decode_any_window (window
)));
423 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
424 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin. */)
428 return decode_window (window
)->hscroll
;
431 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
432 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
433 NCOL should be zero or positive.
435 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
436 window so that the location of point becomes invisible. */)
438 Lisp_Object window
, ncol
;
440 struct window
*w
= decode_window (window
);
444 hscroll
= max (0, XINT (ncol
));
446 /* Prevent redisplay shortcuts when changing the hscroll. */
447 if (XINT (w
->hscroll
) != hscroll
)
448 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
450 w
->hscroll
= make_number (hscroll
);
454 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
455 Swindow_redisplay_end_trigger
, 0, 1, 0,
456 doc
: /* Return WINDOW's redisplay end trigger value.
457 See `set-window-redisplay-end-trigger' for more information. */)
461 return decode_window (window
)->redisplay_end_trigger
;
464 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
465 Sset_window_redisplay_end_trigger
, 2, 2, 0,
466 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
467 VALUE should be a buffer position (typically a marker) or nil.
468 If it is a buffer position, then if redisplay in WINDOW reaches a position
469 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
470 with two arguments: WINDOW, and the end trigger value.
471 Afterwards the end-trigger value is reset to nil. */)
473 register Lisp_Object window
, value
;
475 register struct window
*w
;
477 w
= decode_window (window
);
478 w
->redisplay_end_trigger
= value
;
482 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
483 doc
: /* Return a list of the edge coordinates of WINDOW.
484 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
485 RIGHT is one more than the rightmost column occupied by WINDOW,
486 and BOTTOM is one more than the bottommost row occupied by WINDOW.
487 The edges include the space used by the window's scroll bar,
488 display margins, fringes, header line, and mode line, if it has them.
489 To get the edges of the actual text area, use `window-inside-edges'. */)
493 register struct window
*w
= decode_any_window (window
);
495 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w
)),
496 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w
)),
497 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w
)),
498 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w
)),
502 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
503 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
504 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
505 RIGHT is one more than the rightmost x position occupied by WINDOW,
506 and BOTTOM is one more than the bottommost y position occupied by WINDOW.
507 The pixel edges include the space used by the window's scroll bar,
508 display margins, fringes, header line, and mode line, if it has them.
509 To get the edges of the actual text area, use `window-inside-pixel-edges'. */)
513 register struct window
*w
= decode_any_window (window
);
515 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
)),
516 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
)),
517 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
)),
518 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
)),
522 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
523 doc
: /* Return a list of the edge coordinates of WINDOW.
524 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
525 RIGHT is one more than the rightmost column used by text in WINDOW,
526 and BOTTOM is one more than the bottommost row used by text in WINDOW.
527 The inside edges do not include the space used by the window's scroll bar,
528 display margins, fringes, header line, and/or mode line. */)
532 register struct window
*w
= decode_any_window (window
);
534 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w
)
535 + WINDOW_LEFT_MARGIN_COLS (w
)
536 + WINDOW_LEFT_FRINGE_COLS (w
)),
537 make_number (WINDOW_TOP_EDGE_LINE (w
)
538 + WINDOW_HEADER_LINE_LINES (w
)),
539 make_number (WINDOW_RIGHT_EDGE_COL (w
)
540 - WINDOW_RIGHT_MARGIN_COLS (w
)
541 - WINDOW_RIGHT_FRINGE_COLS (w
)),
542 make_number (WINDOW_BOTTOM_EDGE_LINE (w
)
543 - WINDOW_MODE_LINE_LINES (w
)));
546 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
547 doc
: /* Return a list of the edge coordinates of WINDOW.
548 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
549 RIGHT is one more than the rightmost x position used by text in WINDOW,
550 and BOTTOM is one more than the bottommost y position used by text in WINDOW.
551 The inside edges do not include the space used by the window's scroll bar,
552 display margins, fringes, header line, and/or mode line. */)
556 register struct window
*w
= decode_any_window (window
);
558 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
559 + WINDOW_LEFT_MARGIN_WIDTH (w
)
560 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
561 make_number (WINDOW_TOP_EDGE_Y (w
)
562 + WINDOW_HEADER_LINE_HEIGHT (w
)),
563 make_number (WINDOW_RIGHT_EDGE_X (w
)
564 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
565 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
566 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
567 - WINDOW_MODE_LINE_HEIGHT (w
)));
570 /* Test if the character at column *X, row *Y is within window W.
571 If it is not, return ON_NOTHING;
572 if it is in the window's text area,
573 set *x and *y to its location relative to the upper left corner
576 if it is on the window's modeline, return ON_MODE_LINE;
577 if it is on the border between the window and its right sibling,
578 return ON_VERTICAL_BORDER.
579 if it is on the window's top line, return ON_HEADER_LINE;
580 if it is in left or right fringe of the window,
581 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y
582 to window-relative coordinates;
583 if it is in the marginal area to the left/right of the window,
584 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y
585 to window-relative coordinates.
587 X and Y are frame relative pixel coordinates. */
589 static enum window_part
590 coordinates_in_window (w
, x
, y
)
591 register struct window
*w
;
594 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
595 int left_x
, right_x
, top_y
, bottom_y
;
596 enum window_part part
;
597 int ux
= FRAME_COLUMN_WIDTH (f
);
598 int x0
= WINDOW_LEFT_EDGE_X (w
);
599 int x1
= WINDOW_RIGHT_EDGE_X (w
);
600 /* The width of the area where the vertical line can be dragged.
601 (Between mode lines for instance. */
602 int grabbable_width
= ux
;
603 int lmargin_width
, rmargin_width
, text_left
, text_right
;
605 if (*x
< x0
|| *x
>= x1
)
608 /* In what's below, we subtract 1 when computing right_x because we
609 want the rightmost pixel, which is given by left_pixel+width-1. */
610 if (w
->pseudo_window_p
)
613 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
614 top_y
= WINDOW_TOP_EDGE_Y (w
);
615 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
619 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
620 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
621 top_y
= WINDOW_TOP_EDGE_Y (w
);
622 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
625 /* Outside any interesting row? */
626 if (*y
< top_y
|| *y
>= bottom_y
)
629 /* On the mode line or header line? If it's near the start of
630 the mode or header line of window that's has a horizontal
631 sibling, say it's on the vertical line. That's to be able
632 to resize windows horizontally in case we're using toolkit
635 if (WINDOW_WANTS_MODELINE_P (w
)
636 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
640 header_vertical_border_check
:
641 /* We're somewhere on the mode line. We consider the place
642 between mode lines of horizontally adjacent mode lines
643 as the vertical border. If scroll bars on the left,
644 return the right window. */
645 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
646 || WINDOW_RIGHTMOST_P (w
))
648 if (!WINDOW_LEFTMOST_P (w
) && abs (*x
- x0
) < grabbable_width
)
649 return ON_VERTICAL_BORDER
;
653 if (abs (*x
- x1
) < grabbable_width
)
654 return ON_VERTICAL_BORDER
;
657 /* Convert X and Y to window relative coordinates.
658 Mode line starts at left edge of window. */
664 if (WINDOW_WANTS_HEADER_LINE_P (w
)
665 && *y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
))
667 part
= ON_HEADER_LINE
;
668 goto header_vertical_border_check
;
671 /* Outside any interesting column? */
672 if (*x
< left_x
|| *x
> right_x
)
673 return ON_VERTICAL_BORDER
;
675 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
676 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
678 text_left
= window_box_left (w
, TEXT_AREA
);
679 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
681 if (FRAME_WINDOW_P (f
))
683 if (!w
->pseudo_window_p
684 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
685 && !WINDOW_RIGHTMOST_P (w
)
686 && (abs (*x
- right_x
) < grabbable_width
))
687 return ON_VERTICAL_BORDER
;
691 /* Need to say "*x > right_x" rather than >=, since on character
692 terminals, the vertical line's x coordinate is right_x. */
693 if (!w
->pseudo_window_p
694 && !WINDOW_RIGHTMOST_P (w
)
695 && *x
> right_x
- ux
)
697 /* On the border on the right side of the window? Assume that
698 this area begins at RIGHT_X minus a canonical char width. */
699 return ON_VERTICAL_BORDER
;
705 if (lmargin_width
> 0
706 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
707 ? (*x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
708 : (*x
< left_x
+ lmargin_width
)))
711 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
712 *x
-= WINDOW_LEFT_FRINGE_WIDTH (w
);
714 return ON_LEFT_MARGIN
;
717 /* Convert X and Y to window-relative pixel coordinates. */
720 return ON_LEFT_FRINGE
;
723 if (*x
>= text_right
)
725 if (rmargin_width
> 0
726 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
727 ? (*x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
728 : (*x
>= right_x
- rmargin_width
)))
731 if (!WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
732 *x
-= WINDOW_RIGHT_FRINGE_WIDTH (w
);
734 return ON_RIGHT_MARGIN
;
737 /* Convert X and Y to window-relative pixel coordinates. */
738 *x
-= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
);
740 return ON_RIGHT_FRINGE
;
743 /* Everything special ruled out - must be on text area */
744 *x
-= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
);
750 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
751 Scoordinates_in_window_p
, 2, 2, 0,
752 doc
: /* Return non-nil if COORDINATES are in WINDOW.
753 COORDINATES is a cons of the form (X . Y), X and Y being distances
754 measured in characters from the upper-left corner of the frame.
755 \(0 . 0) denotes the character in the upper left corner of the
757 If COORDINATES are in the text portion of WINDOW,
758 the coordinates relative to the window are returned.
759 If they are in the mode line of WINDOW, `mode-line' is returned.
760 If they are in the top mode line of WINDOW, `header-line' is returned.
761 If they are in the left fringe of WINDOW, `left-fringe' is returned.
762 If they are in the right fringe of WINDOW, `right-fringe' is returned.
763 If they are on the border between WINDOW and its right sibling,
764 `vertical-line' is returned.
765 If they are in the windows's left or right marginal areas, `left-margin'\n\
766 or `right-margin' is returned. */)
767 (coordinates
, window
)
768 register Lisp_Object coordinates
, window
;
775 CHECK_WINDOW (window
);
776 w
= XWINDOW (window
);
777 f
= XFRAME (w
->frame
);
778 CHECK_CONS (coordinates
);
779 lx
= Fcar (coordinates
);
780 ly
= Fcdr (coordinates
);
781 CHECK_NUMBER_OR_FLOAT (lx
);
782 CHECK_NUMBER_OR_FLOAT (ly
);
783 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
);
784 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
);
786 switch (coordinates_in_window (w
, &x
, &y
))
792 /* X and Y are now window relative pixel coordinates. Convert
793 them to canonical char units before returning them. */
794 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
795 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
800 case ON_VERTICAL_BORDER
:
801 return Qvertical_line
;
809 case ON_RIGHT_FRINGE
:
810 return Qright_fringe
;
815 case ON_RIGHT_MARGIN
:
816 return Qright_margin
;
824 /* Callback for foreach_window, used in window_from_coordinates.
825 Check if window W contains coordinates specified by USER_DATA which
826 is actually a pointer to a struct check_window_data CW.
828 Check if window W contains coordinates *CW->x and *CW->y. If it
829 does, return W in *CW->window, as Lisp_Object, and return in
830 *CW->part the part of the window under coordinates *X,*Y. Return
831 zero from this function to stop iterating over windows. */
833 struct check_window_data
837 enum window_part
*part
;
841 check_window_containing (w
, user_data
)
845 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
846 enum window_part found
;
849 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
850 if (found
!= ON_NOTHING
)
853 XSETWINDOW (*cw
->window
, w
);
861 /* Find the window containing frame-relative pixel position X/Y and
862 return it as a Lisp_Object.
864 If X, Y is on one of the window's special `window_part' elements,
865 set *PART to the id of that element, and return X and Y converted
866 to window relative coordinates in WX and WY.
868 If there is no window under X, Y return nil and leave *PART
869 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
871 This function was previously implemented with a loop cycling over
872 windows with Fnext_window, and starting with the frame's selected
873 window. It turned out that this doesn't work with an
874 implementation of next_window using Vwindow_list, because
875 FRAME_SELECTED_WINDOW (F) is not always contained in the window
876 tree of F when this function is called asynchronously from
877 note_mouse_highlight. The original loop didn't terminate in this
881 window_from_coordinates (f
, x
, y
, part
, wx
, wy
, tool_bar_p
)
884 enum window_part
*part
;
889 struct check_window_data cw
;
890 enum window_part dummy
;
896 cw
.window
= &window
, cw
.x
= &x
, cw
.y
= &y
; cw
.part
= part
;
897 foreach_window (f
, check_window_containing
, &cw
);
899 /* If not found above, see if it's in the tool bar window, if a tool
903 && WINDOWP (f
->tool_bar_window
)
904 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
905 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), &x
, &y
)
909 window
= f
->tool_bar_window
;
918 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
919 doc
: /* Return window containing coordinates X and Y on FRAME.
920 If omitted, FRAME defaults to the currently selected frame.
921 The top left corner of the frame is considered to be row 0,
924 Lisp_Object x
, y
, frame
;
929 frame
= selected_frame
;
930 CHECK_LIVE_FRAME (frame
);
933 /* Check that arguments are integers or floats. */
934 CHECK_NUMBER_OR_FLOAT (x
);
935 CHECK_NUMBER_OR_FLOAT (y
);
937 return window_from_coordinates (f
,
938 FRAME_PIXEL_X_FROM_CANON_X (f
, x
),
939 FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
),
943 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
944 doc
: /* Return current value of point in WINDOW.
945 For a nonselected window, this is the value point would have
946 if that window were selected.
948 Note that, when WINDOW is the selected window and its buffer
949 is also currently selected, the value returned is the same as (point).
950 It would be more strictly correct to return the `top-level' value
951 of point, outside of any save-excursion forms.
952 But that is hard to define. */)
956 register struct window
*w
= decode_window (window
);
958 if (w
== XWINDOW (selected_window
)
959 && current_buffer
== XBUFFER (w
->buffer
))
961 return Fmarker_position (w
->pointm
);
964 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
965 doc
: /* Return position at which display currently starts in WINDOW.
966 This is updated by redisplay or by calling `set-window-start'. */)
970 return Fmarker_position (decode_window (window
)->start
);
973 /* This is text temporarily removed from the doc string below.
975 This function returns nil if the position is not currently known.
976 That happens when redisplay is preempted and doesn't finish.
977 If in that case you want to compute where the end of the window would
978 have been if redisplay had finished, do this:
980 (goto-char (window-start window))
981 (vertical-motion (1- (window-height window)) window)
984 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
985 doc
: /* Return position at which display currently ends in WINDOW.
986 This is updated by redisplay, when it runs to completion.
987 Simply changing the buffer text or setting `window-start'
988 does not update this value.
989 If UPDATE is non-nil, compute the up-to-date position
990 if it isn't already recorded. */)
992 Lisp_Object window
, update
;
995 struct window
*w
= decode_window (window
);
1001 #if 0 /* This change broke some things. We should make it later. */
1002 /* If we don't know the end position, return nil.
1003 The user can compute it with vertical-motion if he wants to.
1004 It would be nicer to do it automatically,
1005 but that's so slow that it would probably bother people. */
1006 if (NILP (w
->window_end_valid
))
1011 && ! (! NILP (w
->window_end_valid
)
1012 && XFASTINT (w
->last_modified
) >= MODIFF
))
1014 struct text_pos startp
;
1016 struct buffer
*old_buffer
= NULL
, *b
= XBUFFER (buf
);
1018 /* In case W->start is out of the range, use something
1019 reasonable. This situation occurred when loading a file with
1020 `-l' containing a call to `rmail' with subsequent other
1021 commands. At the end, W->start happened to be BEG, while
1022 rmail had already narrowed the buffer. */
1023 if (XMARKER (w
->start
)->charpos
< BEGV
)
1024 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1025 else if (XMARKER (w
->start
)->charpos
> ZV
)
1026 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1028 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1030 /* Cannot use Fvertical_motion because that function doesn't
1031 cope with variable-height lines. */
1032 if (b
!= current_buffer
)
1034 old_buffer
= current_buffer
;
1035 set_buffer_internal (b
);
1038 start_display (&it
, w
, startp
);
1039 move_it_vertically (&it
, window_box_height (w
));
1040 if (it
.current_y
< it
.last_visible_y
)
1041 move_it_past_eol (&it
);
1042 value
= make_number (IT_CHARPOS (it
));
1045 set_buffer_internal (old_buffer
);
1048 XSETINT (value
, BUF_Z (XBUFFER (buf
)) - XFASTINT (w
->window_end_pos
));
1053 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1054 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer. */)
1056 Lisp_Object window
, pos
;
1058 register struct window
*w
= decode_window (window
);
1060 CHECK_NUMBER_COERCE_MARKER (pos
);
1061 if (w
== XWINDOW (selected_window
)
1062 && XBUFFER (w
->buffer
) == current_buffer
)
1065 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1067 /* We have to make sure that redisplay updates the window to show
1068 the new value of point. */
1069 if (!EQ (window
, selected_window
))
1070 ++windows_or_buffers_changed
;
1075 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1076 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1077 Optional third arg NOFORCE non-nil inhibits next redisplay
1078 from overriding motion of point in order to display at this exact start. */)
1079 (window
, pos
, noforce
)
1080 Lisp_Object window
, pos
, noforce
;
1082 register struct window
*w
= decode_window (window
);
1084 CHECK_NUMBER_COERCE_MARKER (pos
);
1085 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1086 /* this is not right, but much easier than doing what is right. */
1087 w
->start_at_line_beg
= Qnil
;
1089 w
->force_start
= Qt
;
1090 w
->update_mode_line
= Qt
;
1091 XSETFASTINT (w
->last_modified
, 0);
1092 XSETFASTINT (w
->last_overlay_modified
, 0);
1093 if (!EQ (window
, selected_window
))
1094 windows_or_buffers_changed
++;
1099 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1101 doc
: /* Return WINDOW's dedicated object, usually t or nil.
1102 See also `set-window-dedicated-p'. */)
1106 return decode_window (window
)->dedicated
;
1109 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1110 Sset_window_dedicated_p
, 2, 2, 0,
1111 doc
: /* Control whether WINDOW is dedicated to the buffer it displays.
1112 If it is dedicated, Emacs will not automatically change
1113 which buffer appears in it.
1114 The second argument is the new value for the dedication flag;
1115 non-nil means yes. */)
1117 Lisp_Object window
, arg
;
1119 register struct window
*w
= decode_window (window
);
1123 return w
->dedicated
;
1126 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1128 doc
: /* Return the display-table that WINDOW is using. */)
1132 return decode_window (window
)->display_table
;
1135 /* Get the display table for use on window W. This is either W's
1136 display table or W's buffer's display table. Ignore the specified
1137 tables if they are not valid; if no valid table is specified,
1140 struct Lisp_Char_Table
*
1141 window_display_table (w
)
1144 struct Lisp_Char_Table
*dp
= NULL
;
1146 if (DISP_TABLE_P (w
->display_table
))
1147 dp
= XCHAR_TABLE (w
->display_table
);
1148 else if (BUFFERP (w
->buffer
))
1150 struct buffer
*b
= XBUFFER (w
->buffer
);
1152 if (DISP_TABLE_P (b
->display_table
))
1153 dp
= XCHAR_TABLE (b
->display_table
);
1154 else if (DISP_TABLE_P (Vstandard_display_table
))
1155 dp
= XCHAR_TABLE (Vstandard_display_table
);
1161 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1162 doc
: /* Set WINDOW's display-table to TABLE. */)
1164 register Lisp_Object window
, table
;
1166 register struct window
*w
;
1168 w
= decode_window (window
);
1169 w
->display_table
= table
;
1173 /* Record info on buffer window w is displaying
1174 when it is about to cease to display that buffer. */
1177 register struct window
*w
;
1184 if (b
!= XMARKER (w
->pointm
)->buffer
)
1188 if (w
== XWINDOW (selected_window
)
1189 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1190 /* Do this except when the selected window's buffer
1191 is being removed from some other window. */
1193 /* last_window_start records the start position that this buffer
1194 had in the last window to be disconnected from it.
1195 Now that this statement is unconditional,
1196 it is possible for the buffer to be displayed in the
1197 selected window, while last_window_start reflects another
1198 window which was recently showing the same buffer.
1199 Some people might say that might be a good thing. Let's see. */
1200 b
->last_window_start
= marker_position (w
->start
);
1202 /* Point in the selected window's buffer
1203 is actually stored in that buffer, and the window's pointm isn't used.
1204 So don't clobber point in that buffer. */
1205 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1206 /* This line helps to fix Horsley's testbug.el bug. */
1207 && !(WINDOWP (b
->last_selected_window
)
1208 && w
!= XWINDOW (b
->last_selected_window
)
1209 && EQ (buf
, XWINDOW (b
->last_selected_window
)->buffer
)))
1210 temp_set_point_both (b
,
1211 clip_to_bounds (BUF_BEGV (b
),
1212 XMARKER (w
->pointm
)->charpos
,
1214 clip_to_bounds (BUF_BEGV_BYTE (b
),
1215 marker_byte_position (w
->pointm
),
1218 if (WINDOWP (b
->last_selected_window
)
1219 && w
== XWINDOW (b
->last_selected_window
))
1220 b
->last_selected_window
= Qnil
;
1223 /* Put replacement into the window structure in place of old. */
1225 replace_window (old
, replacement
)
1226 Lisp_Object old
, replacement
;
1228 register Lisp_Object tem
;
1229 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
1231 /* If OLD is its frame's root_window, then replacement is the new
1232 root_window for that frame. */
1234 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1235 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
1237 p
->left_col
= o
->left_col
;
1238 p
->top_line
= o
->top_line
;
1239 p
->total_cols
= o
->total_cols
;
1240 p
->total_lines
= o
->total_lines
;
1241 p
->desired_matrix
= p
->current_matrix
= 0;
1243 bzero (&p
->cursor
, sizeof (p
->cursor
));
1244 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
1245 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
1246 p
->phys_cursor_type
= -1;
1247 p
->phys_cursor_width
= -1;
1248 p
->must_be_updated_p
= 0;
1249 p
->pseudo_window_p
= 0;
1250 XSETFASTINT (p
->window_end_vpos
, 0);
1251 XSETFASTINT (p
->window_end_pos
, 0);
1252 p
->window_end_valid
= Qnil
;
1253 p
->frozen_window_start_p
= 0;
1254 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
1256 p
->next
= tem
= o
->next
;
1258 XWINDOW (tem
)->prev
= replacement
;
1260 p
->prev
= tem
= o
->prev
;
1262 XWINDOW (tem
)->next
= replacement
;
1264 p
->parent
= tem
= o
->parent
;
1267 if (EQ (XWINDOW (tem
)->vchild
, old
))
1268 XWINDOW (tem
)->vchild
= replacement
;
1269 if (EQ (XWINDOW (tem
)->hchild
, old
))
1270 XWINDOW (tem
)->hchild
= replacement
;
1273 /*** Here, if replacement is a vertical combination
1274 and so is its new parent, we should make replacement's
1275 children be children of that parent instead. ***/
1278 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
1279 doc
: /* Remove WINDOW from the display. Default is selected window. */)
1281 register Lisp_Object window
;
1283 delete_window (window
);
1285 if (! NILP (Vwindow_configuration_change_hook
)
1286 && ! NILP (Vrun_hooks
))
1287 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
1293 delete_window (window
)
1294 register Lisp_Object window
;
1296 register Lisp_Object tem
, parent
, sib
;
1297 register struct window
*p
;
1298 register struct window
*par
;
1301 /* Because this function is called by other C code on non-leaf
1302 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1303 so we can't decode_window here. */
1305 window
= selected_window
;
1307 CHECK_WINDOW (window
);
1308 p
= XWINDOW (window
);
1310 /* It's okay to delete an already-deleted window. */
1311 if (NILP (p
->buffer
)
1313 && NILP (p
->vchild
))
1318 error ("Attempt to delete minibuffer or sole ordinary window");
1319 par
= XWINDOW (parent
);
1321 windows_or_buffers_changed
++;
1322 Vwindow_list
= Qnil
;
1323 f
= XFRAME (WINDOW_FRAME (p
));
1324 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
1326 /* Are we trying to delete any frame's selected window? */
1328 Lisp_Object swindow
, pwindow
;
1330 /* See if the frame's selected window is either WINDOW
1331 or any subwindow of it, by finding all that window's parents
1332 and comparing each one with WINDOW. */
1333 swindow
= FRAME_SELECTED_WINDOW (f
);
1338 while (!NILP (pwindow
))
1340 if (EQ (window
, pwindow
))
1342 pwindow
= XWINDOW (pwindow
)->parent
;
1345 /* If the window being deleted is not a parent of SWINDOW,
1346 then SWINDOW is ok as the new selected window. */
1347 if (!EQ (window
, pwindow
))
1349 /* Otherwise, try another window for SWINDOW. */
1350 swindow
= Fnext_window (swindow
, Qlambda
, Qnil
);;
1352 /* If we get back to the frame's selected window,
1353 it means there was no acceptable alternative,
1354 so we cannot delete. */
1355 if (EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1356 error ("Cannot delete window");
1359 /* If we need to change SWINDOW, do it. */
1360 if (! EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1362 /* If we're about to delete the selected window on the
1363 selected frame, then we should use Fselect_window to select
1364 the new window. On the other hand, if we're about to
1365 delete the selected window on any other frame, we shouldn't do
1366 anything but set the frame's selected_window slot. */
1367 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
1368 Fselect_window (swindow
, Qnil
);
1370 FRAME_SELECTED_WINDOW (f
) = swindow
;
1375 /* tem is null for dummy parent windows
1376 (which have inferiors but not any contents themselves) */
1380 unchain_marker (XMARKER (p
->pointm
));
1381 unchain_marker (XMARKER (p
->start
));
1384 /* Free window glyph matrices. It is sure that they are allocated
1385 again when ADJUST_GLYPHS is called. Block input so that expose
1386 events and other events that access glyph matrices are not
1387 processed while we are changing them. */
1389 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)));
1393 XWINDOW (tem
)->prev
= p
->prev
;
1397 XWINDOW (tem
)->next
= p
->next
;
1399 if (EQ (window
, par
->hchild
))
1400 par
->hchild
= p
->next
;
1401 if (EQ (window
, par
->vchild
))
1402 par
->vchild
= p
->next
;
1404 /* Find one of our siblings to give our space to. */
1408 /* If p gives its space to its next sibling, that sibling needs
1409 to have its top/left side pulled back to where p's is.
1410 set_window_{height,width} will re-position the sibling's
1413 XWINDOW (sib
)->top_line
= p
->top_line
;
1414 XWINDOW (sib
)->left_col
= p
->left_col
;
1417 /* Stretch that sibling. */
1418 if (!NILP (par
->vchild
))
1419 set_window_height (sib
,
1420 XFASTINT (XWINDOW (sib
)->total_lines
) + XFASTINT (p
->total_lines
),
1422 if (!NILP (par
->hchild
))
1423 set_window_width (sib
,
1424 XFASTINT (XWINDOW (sib
)->total_cols
) + XFASTINT (p
->total_cols
),
1427 /* If parent now has only one child,
1428 put the child into the parent's place. */
1432 if (NILP (XWINDOW (tem
)->next
))
1433 replace_window (parent
, tem
);
1435 /* Since we may be deleting combination windows, we must make sure that
1436 not only p but all its children have been marked as deleted. */
1437 if (! NILP (p
->hchild
))
1438 delete_all_subwindows (XWINDOW (p
->hchild
));
1439 else if (! NILP (p
->vchild
))
1440 delete_all_subwindows (XWINDOW (p
->vchild
));
1442 /* Mark this window as deleted. */
1443 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1445 /* Adjust glyph matrices. */
1452 /***********************************************************************
1454 ***********************************************************************/
1456 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1457 pointer. This is a callback function for foreach_window, used in
1458 function window_list. */
1461 add_window_to_list (w
, user_data
)
1465 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1467 XSETWINDOW (window
, w
);
1468 *list
= Fcons (window
, *list
);
1473 /* Return a list of all windows, for use by next_window. If
1474 Vwindow_list is a list, return that list. Otherwise, build a new
1475 list, cache it in Vwindow_list, and return that. */
1480 if (!CONSP (Vwindow_list
))
1484 Vwindow_list
= Qnil
;
1485 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1487 Lisp_Object args
[2];
1489 /* We are visiting windows in canonical order, and add
1490 new windows at the front of args[1], which means we
1491 have to reverse this list at the end. */
1493 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1494 args
[0] = Vwindow_list
;
1495 args
[1] = Fnreverse (args
[1]);
1496 Vwindow_list
= Fnconc (2, args
);
1500 return Vwindow_list
;
1504 /* Value is non-zero if WINDOW satisfies the constraints given by
1505 OWINDOW, MINIBUF and ALL_FRAMES.
1507 MINIBUF t means WINDOW may be minibuffer windows.
1508 `lambda' means WINDOW may not be a minibuffer window.
1509 a window means a specific minibuffer window
1511 ALL_FRAMES t means search all frames,
1512 nil means search just current frame,
1513 `visible' means search just visible frames,
1514 0 means search visible and iconified frames,
1515 a window means search the frame that window belongs to,
1516 a frame means consider windows on that frame, only. */
1519 candidate_window_p (window
, owindow
, minibuf
, all_frames
)
1520 Lisp_Object window
, owindow
, minibuf
, all_frames
;
1522 struct window
*w
= XWINDOW (window
);
1523 struct frame
*f
= XFRAME (w
->frame
);
1524 int candidate_p
= 1;
1526 if (!BUFFERP (w
->buffer
))
1528 else if (MINI_WINDOW_P (w
)
1529 && (EQ (minibuf
, Qlambda
)
1530 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
1532 /* If MINIBUF is `lambda' don't consider any mini-windows.
1533 If it is a window, consider only that one. */
1536 else if (EQ (all_frames
, Qt
))
1538 else if (NILP (all_frames
))
1540 xassert (WINDOWP (owindow
));
1541 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
1543 else if (EQ (all_frames
, Qvisible
))
1545 FRAME_SAMPLE_VISIBILITY (f
);
1546 candidate_p
= FRAME_VISIBLE_P (f
);
1548 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
1550 FRAME_SAMPLE_VISIBILITY (f
);
1551 candidate_p
= FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
);
1553 else if (WINDOWP (all_frames
))
1554 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
1555 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
1556 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
1557 else if (FRAMEP (all_frames
))
1558 candidate_p
= EQ (all_frames
, w
->frame
);
1564 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1565 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1569 decode_next_window_args (window
, minibuf
, all_frames
)
1570 Lisp_Object
*window
, *minibuf
, *all_frames
;
1573 *window
= selected_window
;
1575 CHECK_LIVE_WINDOW (*window
);
1577 /* MINIBUF nil may or may not include minibuffers. Decide if it
1579 if (NILP (*minibuf
))
1580 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
1581 else if (!EQ (*minibuf
, Qt
))
1584 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1585 => count none of them, or a specific minibuffer window (the
1586 active one) to count. */
1588 /* ALL_FRAMES nil doesn't specify which frames to include. */
1589 if (NILP (*all_frames
))
1590 *all_frames
= (!EQ (*minibuf
, Qlambda
)
1591 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
1593 else if (EQ (*all_frames
, Qvisible
))
1595 else if (XFASTINT (*all_frames
) == 0)
1597 else if (FRAMEP (*all_frames
))
1599 else if (!EQ (*all_frames
, Qt
))
1602 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1603 search just current frame, `visible' meaning search just visible
1604 frames, 0 meaning search visible and iconified frames, or a
1605 window, meaning search the frame that window belongs to, or a
1606 frame, meaning consider windows on that frame, only. */
1610 /* Return the next or previous window of WINDOW in canonical ordering
1611 of windows. NEXT_P non-zero means return the next window. See the
1612 documentation string of next-window for the meaning of MINIBUF and
1616 next_window (window
, minibuf
, all_frames
, next_p
)
1617 Lisp_Object window
, minibuf
, all_frames
;
1620 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1622 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1623 return the first window on the frame. */
1624 if (FRAMEP (all_frames
)
1625 && !EQ (all_frames
, XWINDOW (window
)->frame
))
1626 return Fframe_first_window (all_frames
);
1632 /* Find WINDOW in the list of all windows. */
1633 list
= Fmemq (window
, window_list ());
1635 /* Scan forward from WINDOW to the end of the window list. */
1637 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
1638 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1641 /* Scan from the start of the window list up to WINDOW. */
1643 for (list
= Vwindow_list
;
1644 CONSP (list
) && !EQ (XCAR (list
), window
);
1646 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1650 window
= XCAR (list
);
1654 Lisp_Object candidate
, list
;
1656 /* Scan through the list of windows for candidates. If there are
1657 candidate windows in front of WINDOW, the last one of these
1658 is the one we want. If there are candidates following WINDOW
1659 in the list, again the last one of these is the one we want. */
1661 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
1663 if (EQ (XCAR (list
), window
))
1665 if (WINDOWP (candidate
))
1668 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
1670 candidate
= XCAR (list
);
1673 if (WINDOWP (candidate
))
1681 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
1682 doc
: /* Return next window after WINDOW in canonical ordering of windows.
1683 If omitted, WINDOW defaults to the selected window.
1685 Optional second arg MINIBUF t means count the minibuffer window even
1686 if not active. MINIBUF nil or omitted means count the minibuffer iff
1687 it is active. MINIBUF neither t nor nil means not to count the
1688 minibuffer even if it is active.
1690 Several frames may share a single minibuffer; if the minibuffer
1691 counts, all windows on all frames that share that minibuffer count
1692 too. Therefore, `next-window' can be used to iterate through the
1693 set of windows even when the minibuffer is on another frame. If the
1694 minibuffer does not count, only windows from WINDOW's frame count.
1696 Optional third arg ALL-FRAMES t means include windows on all frames.
1697 ALL-FRAMES nil or omitted means cycle within the frames as specified
1698 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1699 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1700 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1701 Anything else means restrict to WINDOW's frame.
1703 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1704 `next-window' to iterate through the entire cycle of acceptable
1705 windows, eventually ending up back at the window you started with.
1706 `previous-window' traverses the same cycle, in the reverse order. */)
1707 (window
, minibuf
, all_frames
)
1708 Lisp_Object window
, minibuf
, all_frames
;
1710 return next_window (window
, minibuf
, all_frames
, 1);
1714 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1715 doc
: /* Return the window preceding WINDOW in canonical ordering of windows.
1716 If omitted, WINDOW defaults to the selected window.
1718 Optional second arg MINIBUF t means count the minibuffer window even
1719 if not active. MINIBUF nil or omitted means count the minibuffer iff
1720 it is active. MINIBUF neither t nor nil means not to count the
1721 minibuffer even if it is active.
1723 Several frames may share a single minibuffer; if the minibuffer
1724 counts, all windows on all frames that share that minibuffer count
1725 too. Therefore, `previous-window' can be used to iterate through
1726 the set of windows even when the minibuffer is on another frame. If
1727 the minibuffer does not count, only windows from WINDOW's frame count
1729 Optional third arg ALL-FRAMES t means include windows on all frames.
1730 ALL-FRAMES nil or omitted means cycle within the frames as specified
1731 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1732 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1733 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1734 Anything else means restrict to WINDOW's frame.
1736 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1737 `previous-window' to iterate through the entire cycle of acceptable
1738 windows, eventually ending up back at the window you started with.
1739 `next-window' traverses the same cycle, in the reverse order. */)
1740 (window
, minibuf
, all_frames
)
1741 Lisp_Object window
, minibuf
, all_frames
;
1743 return next_window (window
, minibuf
, all_frames
, 0);
1747 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1748 doc
: /* Select the ARG'th different window on this frame.
1749 All windows on current frame are arranged in a cyclic order.
1750 This command selects the window ARG steps away in that order.
1751 A negative ARG moves in the opposite order. The optional second
1752 argument ALL_FRAMES has the same meaning as in `next-window', which see. */)
1754 Lisp_Object arg
, all_frames
;
1760 window
= selected_window
;
1762 for (i
= XINT (arg
); i
> 0; --i
)
1763 window
= Fnext_window (window
, Qnil
, all_frames
);
1765 window
= Fprevious_window (window
, Qnil
, all_frames
);
1767 Fselect_window (window
, Qnil
);
1772 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
1773 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
1774 FRAME nil or omitted means use the selected frame.
1775 WINDOW nil or omitted means use the selected window.
1776 MINIBUF t means include the minibuffer window, even if it isn't active.
1777 MINIBUF nil or omitted means include the minibuffer window only
1779 MINIBUF neither nil nor t means never include the minibuffer window. */)
1780 (frame
, minibuf
, window
)
1781 Lisp_Object frame
, minibuf
, window
;
1784 window
= selected_window
;
1786 frame
= selected_frame
;
1788 if (!EQ (frame
, XWINDOW (window
)->frame
))
1789 error ("Window is on a different frame");
1791 return window_list_1 (window
, minibuf
, frame
);
1795 /* Return a list of windows in canonical ordering. Arguments are like
1796 for `next-window'. */
1799 window_list_1 (window
, minibuf
, all_frames
)
1800 Lisp_Object window
, minibuf
, all_frames
;
1802 Lisp_Object tail
, list
, rest
;
1804 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1807 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
1808 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
1809 list
= Fcons (XCAR (tail
), list
);
1811 /* Rotate the list to start with WINDOW. */
1812 list
= Fnreverse (list
);
1813 rest
= Fmemq (window
, list
);
1814 if (!NILP (rest
) && !EQ (rest
, list
))
1816 for (tail
= list
; XCDR (tail
) != rest
; tail
= XCDR (tail
))
1818 XSETCDR (tail
, Qnil
);
1819 list
= nconc2 (rest
, list
);
1826 /* Look at all windows, performing an operation specified by TYPE
1828 If FRAMES is Qt, look at all frames;
1829 Qnil, look at just the selected frame;
1830 Qvisible, look at visible frames;
1831 a frame, just look at windows on that frame.
1832 If MINI is non-zero, perform the operation on minibuffer windows too. */
1837 GET_BUFFER_WINDOW
, /* Arg is buffer */
1838 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1839 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1840 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1842 UNSHOW_BUFFER
, /* Arg is buffer */
1843 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
1848 window_loop (type
, obj
, mini
, frames
)
1849 enum window_loop type
;
1850 Lisp_Object obj
, frames
;
1853 Lisp_Object window
, windows
, best_window
, frame_arg
;
1855 struct gcpro gcpro1
;
1857 /* If we're only looping through windows on a particular frame,
1858 frame points to that frame. If we're looping through windows
1859 on all frames, frame is 0. */
1860 if (FRAMEP (frames
))
1861 f
= XFRAME (frames
);
1862 else if (NILP (frames
))
1863 f
= SELECTED_FRAME ();
1868 frame_arg
= Qlambda
;
1869 else if (XFASTINT (frames
) == 0)
1871 else if (EQ (frames
, Qvisible
))
1876 /* frame_arg is Qlambda to stick to one frame,
1877 Qvisible to consider all visible frames,
1880 /* Pick a window to start with. */
1884 window
= FRAME_SELECTED_WINDOW (f
);
1886 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
1888 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
1892 for (; CONSP (windows
); windows
= CDR (windows
))
1896 window
= XCAR (windows
);
1897 w
= XWINDOW (window
);
1899 /* Note that we do not pay attention here to whether the frame
1900 is visible, since Fwindow_list skips non-visible frames if
1901 that is desired, under the control of frame_arg. */
1902 if (!MINI_WINDOW_P (w
)
1903 /* For UNSHOW_BUFFER, we must always consider all windows. */
1904 || type
== UNSHOW_BUFFER
1905 || (mini
&& minibuf_level
> 0))
1908 case GET_BUFFER_WINDOW
:
1909 if (EQ (w
->buffer
, obj
)
1910 /* Don't find any minibuffer window
1911 except the one that is currently in use. */
1912 && (MINI_WINDOW_P (w
)
1913 ? EQ (window
, minibuf_window
)
1916 if (NILP (best_window
))
1917 best_window
= window
;
1918 else if (EQ (window
, selected_window
))
1919 /* For compatibility with 20.x, prefer to return
1921 best_window
= window
;
1925 case GET_LRU_WINDOW
:
1926 /* t as arg means consider only full-width windows */
1927 if (!NILP (obj
) && !WINDOW_FULL_WIDTH_P (w
))
1929 /* Ignore dedicated windows and minibuffers. */
1930 if (MINI_WINDOW_P (w
) || EQ (w
->dedicated
, Qt
))
1932 if (NILP (best_window
)
1933 || (XFASTINT (XWINDOW (best_window
)->use_time
)
1934 > XFASTINT (w
->use_time
)))
1935 best_window
= window
;
1938 case DELETE_OTHER_WINDOWS
:
1939 if (!EQ (window
, obj
))
1940 Fdelete_window (window
);
1943 case DELETE_BUFFER_WINDOWS
:
1944 if (EQ (w
->buffer
, obj
))
1946 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1948 /* If this window is dedicated, and in a frame of its own,
1950 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
1951 && !NILP (w
->dedicated
)
1952 && other_visible_frames (f
))
1954 /* Skip the other windows on this frame.
1955 There might be one, the minibuffer! */
1956 while (CONSP (XCDR (windows
))
1957 && EQ (XWINDOW (XCAR (windows
))->frame
,
1958 XWINDOW (XCAR (XCDR (windows
)))->frame
))
1959 windows
= XCDR (windows
);
1961 /* Now we can safely delete the frame. */
1962 Fdelete_frame (w
->frame
, Qnil
);
1964 else if (NILP (w
->parent
))
1966 /* If we're deleting the buffer displayed in the
1967 only window on the frame, find a new buffer to
1970 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
1971 Fset_window_buffer (window
, buffer
, Qnil
);
1972 if (EQ (window
, selected_window
))
1973 Fset_buffer (w
->buffer
);
1976 Fdelete_window (window
);
1980 case GET_LARGEST_WINDOW
:
1982 /* Ignore dedicated windows and minibuffers. */
1983 if (MINI_WINDOW_P (w
) || EQ (w
->dedicated
, Qt
))
1986 if (NILP (best_window
))
1987 best_window
= window
;
1990 struct window
*b
= XWINDOW (best_window
);
1991 if (XFASTINT (w
->total_lines
) * XFASTINT (w
->total_cols
)
1992 > XFASTINT (b
->total_lines
) * XFASTINT (b
->total_cols
))
1993 best_window
= window
;
1999 if (EQ (w
->buffer
, obj
))
2002 struct frame
*f
= XFRAME (w
->frame
);
2004 /* Find another buffer to show in this window. */
2005 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2007 /* If this window is dedicated, and in a frame of its own,
2009 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
2010 && !NILP (w
->dedicated
)
2011 && other_visible_frames (f
))
2013 /* Skip the other windows on this frame.
2014 There might be one, the minibuffer! */
2015 while (CONSP (XCDR (windows
))
2016 && EQ (XWINDOW (XCAR (windows
))->frame
,
2017 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2018 windows
= XCDR (windows
);
2020 /* Now we can safely delete the frame. */
2021 Fdelete_frame (w
->frame
, Qnil
);
2023 else if (!NILP (w
->dedicated
) && !NILP (w
->parent
))
2026 XSETWINDOW (window
, w
);
2027 /* If this window is dedicated and not the only window
2028 in its frame, then kill it. */
2029 Fdelete_window (window
);
2033 /* Otherwise show a different buffer in the window. */
2034 w
->dedicated
= Qnil
;
2035 Fset_window_buffer (window
, buffer
, Qnil
);
2036 if (EQ (window
, selected_window
))
2037 Fset_buffer (w
->buffer
);
2042 case REDISPLAY_BUFFER_WINDOWS
:
2043 if (EQ (w
->buffer
, obj
))
2045 mark_window_display_accurate (window
, 0);
2046 w
->update_mode_line
= Qt
;
2047 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2048 ++update_mode_lines
;
2049 best_window
= window
;
2053 /* Check for a window that has a killed buffer. */
2054 case CHECK_ALL_WINDOWS
:
2055 if (! NILP (w
->buffer
)
2056 && NILP (XBUFFER (w
->buffer
)->name
))
2060 case WINDOW_LOOP_UNUSED
:
2069 /* Used for debugging. Abort if any window has a dead buffer. */
2072 check_all_windows ()
2074 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2077 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 1, 0,
2078 doc
: /* Return the window least recently selected or used for display.
2079 Return a full-width window if possible.
2080 A minibuffer window is never a candidate.
2081 If optional argument FRAME is `visible', search all visible frames.
2082 If FRAME is 0, search all visible and iconified frames.
2083 If FRAME is t, search all frames.
2084 If FRAME is nil, search only the selected frame.
2085 If FRAME is a frame, search only that frame. */)
2089 register Lisp_Object w
;
2090 /* First try for a window that is full-width */
2091 w
= window_loop (GET_LRU_WINDOW
, Qt
, 0, frame
);
2092 if (!NILP (w
) && !EQ (w
, selected_window
))
2094 /* If none of them, try the rest */
2095 return window_loop (GET_LRU_WINDOW
, Qnil
, 0, frame
);
2098 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 1, 0,
2099 doc
: /* Return the largest window in area.
2100 A minibuffer window is never a candidate.
2101 If optional argument FRAME is `visible', search all visible frames.
2102 If FRAME is 0, search all visible and iconified frames.
2103 If FRAME is t, search all frames.
2104 If FRAME is nil, search only the selected frame.
2105 If FRAME is a frame, search only that frame. */)
2109 return window_loop (GET_LARGEST_WINDOW
, Qnil
, 0,
2113 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
2114 doc
: /* Return a window currently displaying BUFFER, or nil if none.
2115 BUFFER can be a buffer or a buffer name.
2116 If optional argument FRAME is `visible', search all visible frames.
2117 If optional argument FRAME is 0, search all visible and iconified frames.
2118 If FRAME is t, search all frames.
2119 If FRAME is nil, search only the selected frame.
2120 If FRAME is a frame, search only that frame. */)
2122 Lisp_Object buffer
, frame
;
2124 buffer
= Fget_buffer (buffer
);
2125 if (BUFFERP (buffer
))
2126 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
2131 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
2133 doc
: /* Make WINDOW (or the selected window) fill its frame.
2134 Only the frame WINDOW is on is affected.
2135 This function tries to reduce display jumps
2136 by keeping the text previously visible in WINDOW
2137 in the same place on the frame. Doing this depends on
2138 the value of (window-start WINDOW), so if calling this function
2139 in a program gives strange scrolling, make sure the window-start
2140 value is reasonable when this function is called. */)
2149 window
= selected_window
;
2151 CHECK_LIVE_WINDOW (window
);
2152 w
= XWINDOW (window
);
2154 startpos
= marker_position (w
->start
);
2155 top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2157 if (MINI_WINDOW_P (w
) && top
> 0)
2158 error ("Can't expand minibuffer to full frame");
2160 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
2162 /* Try to minimize scrolling, by setting the window start to the point
2163 will cause the text at the old window start to be at the same place
2164 on the frame. But don't try to do this if the window start is
2165 outside the visible portion (as might happen when the display is
2166 not current, due to typeahead). */
2167 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2169 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2170 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2172 struct position pos
;
2173 struct buffer
*obuf
= current_buffer
;
2175 Fset_buffer (w
->buffer
);
2176 /* This computation used to temporarily move point, but that can
2177 have unwanted side effects due to text properties. */
2178 pos
= *vmotion (startpos
, -top
, w
);
2180 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2181 w
->window_end_valid
= Qnil
;
2182 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
2183 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
2185 /* We need to do this, so that the window-scroll-functions
2187 w
->optional_new_start
= Qt
;
2189 set_buffer_internal (obuf
);
2195 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
2196 1, 2, "bDelete windows on (buffer): ",
2197 doc
: /* Delete all windows showing BUFFER.
2198 BUFFER must be a buffer or the name of an existing buffer.
2199 Optional second argument FRAME controls which frames are affected.
2200 If optional argument FRAME is `visible', search all visible frames.
2201 If FRAME is 0, search all visible and iconified frames.
2202 If FRAME is nil, search all frames.
2203 If FRAME is t, search only the selected frame.
2204 If FRAME is a frame, search only that frame. */)
2206 Lisp_Object buffer
, frame
;
2208 /* FRAME uses t and nil to mean the opposite of what window_loop
2212 else if (EQ (frame
, Qt
))
2217 buffer
= Fget_buffer (buffer
);
2218 CHECK_BUFFER (buffer
);
2219 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
2225 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
2226 Sreplace_buffer_in_windows
,
2227 1, 1, "bReplace buffer in windows: ",
2228 doc
: /* Replace BUFFER with some other buffer in all windows showing it.
2229 BUFFER may be a buffer or the name of an existing buffer. */)
2235 buffer
= Fget_buffer (buffer
);
2236 CHECK_BUFFER (buffer
);
2237 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
2242 /* Replace BUFFER with some other buffer in all windows
2243 of all frames, even those on other keyboards. */
2246 replace_buffer_in_all_windows (buffer
)
2250 Lisp_Object tail
, frame
;
2252 /* A single call to window_loop won't do the job
2253 because it only considers frames on the current keyboard.
2254 So loop manually over frames, and handle each one. */
2255 FOR_EACH_FRAME (tail
, frame
)
2256 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
2258 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
2262 /* Set the height of WINDOW and all its inferiors. */
2264 /* The smallest acceptable dimensions for a window. Anything smaller
2265 might crash Emacs. */
2267 #define MIN_SAFE_WINDOW_WIDTH (2)
2268 #define MIN_SAFE_WINDOW_HEIGHT (1)
2270 /* Make sure that window_min_height and window_min_width are
2271 not too small; if they are, set them to safe minima. */
2274 check_min_window_sizes ()
2276 /* Smaller values might permit a crash. */
2277 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
2278 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
2279 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
2280 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
2283 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2284 minimum allowable size. */
2287 check_frame_size (frame
, rows
, cols
)
2291 /* For height, we have to see:
2292 how many windows the frame has at minimum (one or two),
2293 and whether it has a menu bar or other special stuff at the top. */
2295 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
2296 ? MIN_SAFE_WINDOW_HEIGHT
2297 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
2299 if (FRAME_TOP_MARGIN (frame
) > 0)
2300 min_height
+= FRAME_TOP_MARGIN (frame
);
2302 if (*rows
< min_height
)
2304 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2305 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2309 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2310 check if W's width can be changed, otherwise check W's height.
2311 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2312 siblings, too. If none of the siblings is resizable, WINDOW isn't
2316 window_fixed_size_p (w
, width_p
, check_siblings_p
)
2318 int width_p
, check_siblings_p
;
2323 if (!NILP (w
->hchild
))
2325 c
= XWINDOW (w
->hchild
);
2329 /* A horiz. combination is fixed-width if all of if its
2331 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2332 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2333 fixed_p
= c
== NULL
;
2337 /* A horiz. combination is fixed-height if one of if its
2339 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2340 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2341 fixed_p
= c
!= NULL
;
2344 else if (!NILP (w
->vchild
))
2346 c
= XWINDOW (w
->vchild
);
2350 /* A vert. combination is fixed-width if one of if its
2352 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2353 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2354 fixed_p
= c
!= NULL
;
2358 /* A vert. combination is fixed-height if all of if its
2360 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2361 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2362 fixed_p
= c
== NULL
;
2365 else if (BUFFERP (w
->buffer
))
2367 if (w
->height_fixed_p
&& !width_p
)
2371 struct buffer
*old
= current_buffer
;
2374 current_buffer
= XBUFFER (w
->buffer
);
2375 val
= find_symbol_value (Qwindow_size_fixed
);
2376 current_buffer
= old
;
2379 if (!EQ (val
, Qunbound
))
2381 fixed_p
= !NILP (val
);
2384 && ((EQ (val
, Qheight
) && width_p
)
2385 || (EQ (val
, Qwidth
) && !width_p
)))
2390 /* Can't tell if this one is resizable without looking at
2391 siblings. If all siblings are fixed-size this one is too. */
2392 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
2396 for (child
= w
->prev
; !NILP (child
); child
= XWINDOW (child
)->prev
)
2397 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2401 for (child
= w
->next
; !NILP (child
); child
= XWINDOW (child
)->next
)
2402 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2416 /* Return the minimum size of window W, not taking fixed-width windows
2417 into account. WIDTH_P non-zero means return the minimum width,
2418 otherwise return the minimum height. If W is a combination window,
2419 compute the minimum size from the minimum sizes of W's children. */
2422 window_min_size_1 (w
, width_p
)
2429 if (!NILP (w
->hchild
))
2431 c
= XWINDOW (w
->hchild
);
2436 /* The min width of a horizontal combination is
2437 the sum of the min widths of its children. */
2440 size
+= window_min_size_1 (c
, width_p
);
2441 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2446 /* The min height a horizontal combination equals
2447 the maximum of all min height of its children. */
2450 int min_size
= window_min_size_1 (c
, width_p
);
2451 size
= max (min_size
, size
);
2452 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2456 else if (!NILP (w
->vchild
))
2458 c
= XWINDOW (w
->vchild
);
2463 /* The min width of a vertical combination is
2464 the maximum of the min widths of its children. */
2467 int min_size
= window_min_size_1 (c
, width_p
);
2468 size
= max (min_size
, size
);
2469 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2474 /* The min height of a vertical combination equals
2475 the sum of the min height of its children. */
2478 size
+= window_min_size_1 (c
, width_p
);
2479 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2486 size
= window_min_width
;
2489 if (MINI_WINDOW_P (w
)
2490 || (!WINDOW_WANTS_MODELINE_P (w
)
2491 && !WINDOW_WANTS_HEADER_LINE_P (w
)))
2494 size
= window_min_height
;
2502 /* Return the minimum size of window W, taking fixed-size windows into
2503 account. WIDTH_P non-zero means return the minimum width,
2504 otherwise return the minimum height. IGNORE_FIXED_P non-zero means
2505 ignore if W is fixed-size. Set *FIXED to 1 if W is fixed-size
2506 unless FIXED is null. */
2509 window_min_size (w
, width_p
, ignore_fixed_p
, fixed
)
2511 int width_p
, ignore_fixed_p
, *fixed
;
2518 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
2524 size
= width_p
? XFASTINT (w
->total_cols
) : XFASTINT (w
->total_lines
);
2526 size
= window_min_size_1 (w
, width_p
);
2532 /* Adjust the margins of window W if text area is too small.
2533 Return 1 if window width is ok after adjustment; 0 if window
2534 is still too narrow. */
2537 adjust_window_margins (w
)
2540 int box_cols
= (WINDOW_TOTAL_COLS (w
)
2541 - WINDOW_FRINGE_COLS (w
)
2542 - WINDOW_SCROLL_BAR_COLS (w
));
2543 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
2544 + WINDOW_RIGHT_MARGIN_COLS (w
));
2546 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
2549 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
2552 /* Window's text area is too narrow, but reducing the window
2553 margins will fix that. */
2554 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
2555 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
2557 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
2558 w
->left_margin_cols
= w
->right_margin_cols
2559 = make_number (margin_cols
/2);
2561 w
->right_margin_cols
= make_number (margin_cols
);
2564 w
->left_margin_cols
= make_number (margin_cols
);
2568 /* Calculate new sizes for windows in the list FORWARD when the window size
2569 goes from TOTAL to SIZE. TOTAL must be greater than SIZE.
2570 The number of windows in FORWARD is NCHILDREN, and the number that
2571 can shrink is SHRINKABLE.
2572 The minimum size a window can have is MIN_SIZE.
2573 If we are shrinking fixed windows, RESIZE_FIXED_P is non-zero.
2574 If we are shrinking columns, WIDTH_P is non-zero, otherwise we are
2577 This function returns an allocated array of new sizes that the caller
2578 must free. The size -1 means the window is fixed and RESIZE_FIXED_P
2579 is zero. Array index 0 refers to the first window in FORWARD, 1 to
2580 the second, and so on.
2582 This function tries to keep windows at least at the minimum size
2583 and resize other windows before it resizes any window to zero (i.e.
2584 delete that window).
2586 Windows are resized proportional to their size, so bigger windows
2587 shrink more than smaller windows. */
2589 shrink_windows (total
, size
, nchildren
, shrinkable
,
2590 min_size
, resize_fixed_p
, forward
, width_p
)
2591 int total
, size
, nchildren
, shrinkable
, min_size
;
2592 int resize_fixed_p
, width_p
;
2593 Lisp_Object forward
;
2595 int available_resize
= 0;
2599 int smallest
= total
;
2600 int total_removed
= 0;
2601 int total_shrink
= total
- size
;
2604 new_sizes
= xmalloc (sizeof (*new_sizes
) * nchildren
);
2606 for (i
= 0, child
= forward
; !NILP (child
); child
= c
->next
, ++i
)
2610 c
= XWINDOW (child
);
2611 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2613 if (! resize_fixed_p
&& window_fixed_size_p (c
, width_p
, 0))
2617 new_sizes
[i
] = child_size
;
2618 if (child_size
> min_size
)
2619 available_resize
+= child_size
- min_size
;
2622 /* We might need to shrink some windows to zero. Find the smallest
2623 windows and set them to 0 until we can fulfil the new size. */
2625 while (shrinkable
> 1 && size
+ available_resize
< total
)
2627 for (i
= 0; i
< nchildren
; ++i
)
2628 if (new_sizes
[i
] > 0 && smallest
> new_sizes
[i
])
2629 smallest
= new_sizes
[i
];
2631 for (i
= 0; i
< nchildren
; ++i
)
2632 if (new_sizes
[i
] == smallest
)
2634 /* Resize this window down to zero. */
2636 if (smallest
> min_size
)
2637 available_resize
-= smallest
- min_size
;
2638 available_resize
+= smallest
;
2640 total_removed
+= smallest
;
2642 /* Out of for, just remove one window at the time and
2643 check again if we have enough space. */
2648 /* Now, calculate the new sizes. Try to shrink each window
2649 proportional to its size. */
2650 for (i
= 0; i
< nchildren
; ++i
)
2652 if (new_sizes
[i
] > min_size
)
2654 int to_shrink
= total_shrink
*new_sizes
[i
]/total
;
2655 if (new_sizes
[i
] - to_shrink
< min_size
)
2656 to_shrink
= new_sizes
[i
] - min_size
;
2657 new_sizes
[i
] -= to_shrink
;
2658 total_removed
+= to_shrink
;
2662 /* Any reminder due to rounding, we just subtract from windows
2663 that are left and still can be shrunk. */
2664 while (total_shrink
> total_removed
)
2666 for (i
= 0; i
< nchildren
; ++i
)
2667 if (new_sizes
[i
] > min_size
)
2672 /* Out of for, just shrink one window at the time and
2673 check again if we have enough space. */
2681 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
2682 WINDOW's width. Resize WINDOW's children, if any, so that they
2683 keep their proportionate size relative to WINDOW. Propagate
2684 WINDOW's top or left edge position to children. Delete windows
2685 that become too small unless NODELETE_P is non-zero.
2687 If NODELETE_P is 2, that means we do delete windows that are
2688 too small, even if they were too small before! */
2691 size_window (window
, size
, width_p
, nodelete_p
)
2693 int size
, width_p
, nodelete_p
;
2695 struct window
*w
= XWINDOW (window
);
2697 Lisp_Object child
, *forward
, *sideward
;
2698 int old_size
, min_size
, safe_min_size
;
2700 /* We test nodelete_p != 2 and nodelete_p != 1 below, so it
2701 seems like it's too soon to do this here. ++KFS. */
2702 if (nodelete_p
== 2)
2705 check_min_window_sizes ();
2706 size
= max (0, size
);
2708 /* If the window has been "too small" at one point,
2709 don't delete it for being "too small" in the future.
2710 Preserve it as long as that is at all possible. */
2713 old_size
= WINDOW_TOTAL_COLS (w
);
2714 min_size
= window_min_width
;
2715 /* Ensure that there is room for the scroll bar and fringes!
2716 We may reduce display margins though. */
2717 safe_min_size
= (MIN_SAFE_WINDOW_WIDTH
2718 + WINDOW_FRINGE_COLS (w
)
2719 + WINDOW_SCROLL_BAR_COLS (w
));
2723 old_size
= XINT (w
->total_lines
);
2724 min_size
= window_min_height
;
2725 safe_min_size
= MIN_SAFE_WINDOW_HEIGHT
;
2728 if (old_size
< min_size
&& nodelete_p
!= 2)
2729 w
->too_small_ok
= Qt
;
2731 /* Maybe delete WINDOW if it's too small. */
2732 if (nodelete_p
!= 1 && !NILP (w
->parent
))
2734 if (!MINI_WINDOW_P (w
) && !NILP (w
->too_small_ok
))
2735 min_size
= width_p
? MIN_SAFE_WINDOW_WIDTH
: MIN_SAFE_WINDOW_HEIGHT
;
2736 if (min_size
< safe_min_size
)
2737 min_size
= safe_min_size
;
2738 if (size
< min_size
)
2740 delete_window (window
);
2745 /* Set redisplay hints. */
2746 w
->last_modified
= make_number (0);
2747 w
->last_overlay_modified
= make_number (0);
2748 windows_or_buffers_changed
++;
2749 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w
->frame
)) = 1;
2753 sideward
= &w
->vchild
;
2754 forward
= &w
->hchild
;
2755 w
->total_cols
= make_number (size
);
2756 adjust_window_margins (w
);
2760 sideward
= &w
->hchild
;
2761 forward
= &w
->vchild
;
2762 w
->total_lines
= make_number (size
);
2763 w
->orig_total_lines
= Qnil
;
2766 if (!NILP (*sideward
))
2768 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
2770 c
= XWINDOW (child
);
2772 c
->left_col
= w
->left_col
;
2774 c
->top_line
= w
->top_line
;
2775 size_window (child
, size
, width_p
, nodelete_p
);
2778 else if (!NILP (*forward
))
2780 int fixed_size
, each
, extra
, n
;
2781 int resize_fixed_p
, nfixed
;
2782 int last_pos
, first_pos
, nchildren
, total
;
2783 int *new_sizes
= NULL
;
2785 /* Determine the fixed-size portion of the this window, and the
2786 number of child windows. */
2787 fixed_size
= nchildren
= nfixed
= total
= 0;
2788 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
2792 c
= XWINDOW (child
);
2793 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2794 total
+= child_size
;
2796 if (window_fixed_size_p (c
, width_p
, 0))
2798 fixed_size
+= child_size
;
2803 /* If the new size is smaller than fixed_size, or if there
2804 aren't any resizable windows, allow resizing fixed-size
2806 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
2808 /* Compute how many lines/columns to add/remove to each child. The
2809 value of extra takes care of rounding errors. */
2810 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
2811 if (size
< total
&& n
> 1)
2812 new_sizes
= shrink_windows (total
, size
, nchildren
, n
, min_size
,
2813 resize_fixed_p
, *forward
, width_p
);
2816 each
= (size
- total
) / n
;
2817 extra
= (size
- total
) - n
* each
;
2820 /* Compute new children heights and edge positions. */
2821 first_pos
= width_p
? XINT (w
->left_col
) : XINT (w
->top_line
);
2822 last_pos
= first_pos
;
2823 for (n
= 0, child
= *forward
; !NILP (child
); child
= c
->next
, ++n
)
2825 int new_size
, old_size
;
2827 c
= XWINDOW (child
);
2828 old_size
= width_p
? XFASTINT (c
->total_cols
) : XFASTINT (c
->total_lines
);
2829 new_size
= old_size
;
2831 /* The top or left edge position of this child equals the
2832 bottom or right edge of its predecessor. */
2834 c
->left_col
= make_number (last_pos
);
2836 c
->top_line
= make_number (last_pos
);
2838 /* If this child can be resized, do it. */
2839 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
2841 new_size
= new_sizes
? new_sizes
[n
] : old_size
+ each
+ extra
;
2845 /* Set new height. Note that size_window also propagates
2846 edge positions to children, so it's not a no-op if we
2847 didn't change the child's size. */
2848 size_window (child
, new_size
, width_p
, 1);
2850 /* Remember the bottom/right edge position of this child; it
2851 will be used to set the top/left edge of the next child. */
2852 last_pos
+= new_size
;
2855 if (new_sizes
) xfree (new_sizes
);
2857 /* We should have covered the parent exactly with child windows. */
2858 xassert (size
== last_pos
- first_pos
);
2860 /* Now delete any children that became too small. */
2862 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2865 c
= XWINDOW (child
);
2866 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2867 size_window (child
, child_size
, width_p
, 2);
2872 /* Set WINDOW's height to HEIGHT, and recursively change the height of
2873 WINDOW's children. NODELETE non-zero means don't delete windows
2874 that become too small in the process. (The caller should check
2875 later and do so if appropriate.) */
2878 set_window_height (window
, height
, nodelete
)
2883 size_window (window
, height
, 0, nodelete
);
2887 /* Set WINDOW's width to WIDTH, and recursively change the width of
2888 WINDOW's children. NODELETE non-zero means don't delete windows
2889 that become too small in the process. (The caller should check
2890 later and do so if appropriate.) */
2893 set_window_width (window
, width
, nodelete
)
2898 size_window (window
, width
, 1, nodelete
);
2901 /* Change window heights in windows rooted in WINDOW by N lines. */
2904 change_window_heights (window
, n
)
2908 struct window
*w
= XWINDOW (window
);
2910 XSETFASTINT (w
->top_line
, XFASTINT (w
->top_line
) + n
);
2911 XSETFASTINT (w
->total_lines
, XFASTINT (w
->total_lines
) - n
);
2913 if (INTEGERP (w
->orig_top_line
))
2914 XSETFASTINT (w
->orig_top_line
, XFASTINT (w
->orig_top_line
) + n
);
2915 if (INTEGERP (w
->orig_total_lines
))
2916 XSETFASTINT (w
->orig_total_lines
, XFASTINT (w
->orig_total_lines
) - n
);
2918 /* Handle just the top child in a vertical split. */
2919 if (!NILP (w
->vchild
))
2920 change_window_heights (w
->vchild
, n
);
2922 /* Adjust all children in a horizontal split. */
2923 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
2925 w
= XWINDOW (window
);
2926 change_window_heights (window
, n
);
2931 int window_select_count
;
2934 Fset_window_buffer_unwind (obuf
)
2941 EXFUN (Fset_window_fringes
, 4);
2942 EXFUN (Fset_window_scroll_bars
, 4);
2944 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
2945 means it's allowed to run hooks. See make_frame for a case where
2946 it's not allowed. KEEP_MARGINS_P non-zero means that the current
2947 margins, fringes, and scroll-bar settings of the window are not
2948 reset from the buffer's local settings. */
2951 set_window_buffer (window
, buffer
, run_hooks_p
, keep_margins_p
)
2952 Lisp_Object window
, buffer
;
2953 int run_hooks_p
, keep_margins_p
;
2955 struct window
*w
= XWINDOW (window
);
2956 struct buffer
*b
= XBUFFER (buffer
);
2957 int count
= SPECPDL_INDEX ();
2961 if (EQ (window
, selected_window
))
2962 b
->last_selected_window
= window
;
2964 /* Update time stamps of buffer display. */
2965 if (INTEGERP (b
->display_count
))
2966 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
2967 b
->display_time
= Fcurrent_time ();
2969 XSETFASTINT (w
->window_end_pos
, 0);
2970 XSETFASTINT (w
->window_end_vpos
, 0);
2971 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
2972 w
->window_end_valid
= Qnil
;
2973 w
->hscroll
= w
->min_hscroll
= make_number (0);
2975 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
2976 set_marker_restricted (w
->start
,
2977 make_number (b
->last_window_start
),
2979 w
->start_at_line_beg
= Qnil
;
2980 w
->force_start
= Qnil
;
2981 XSETFASTINT (w
->last_modified
, 0);
2982 XSETFASTINT (w
->last_overlay_modified
, 0);
2983 windows_or_buffers_changed
++;
2985 /* We must select BUFFER for running the window-scroll-functions.
2986 If WINDOW is selected, switch permanently.
2987 Otherwise, switch but go back to the ambient buffer afterward. */
2988 if (EQ (window
, selected_window
))
2989 Fset_buffer (buffer
);
2990 /* We can't check ! NILP (Vwindow_scroll_functions) here
2991 because that might itself be a local variable. */
2992 else if (window_initialized
)
2994 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
2995 Fset_buffer (buffer
);
2998 if (!keep_margins_p
)
3000 /* Set left and right marginal area width etc. from buffer. */
3002 /* This may call adjust_window_margins three times, so
3003 temporarily disable window margins. */
3004 Lisp_Object save_left
= w
->left_margin_cols
;
3005 Lisp_Object save_right
= w
->right_margin_cols
;
3007 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
3009 Fset_window_fringes (window
,
3010 b
->left_fringe_width
, b
->right_fringe_width
,
3011 b
->fringes_outside_margins
);
3013 Fset_window_scroll_bars (window
,
3014 b
->scroll_bar_width
,
3015 b
->vertical_scroll_bar_type
, Qnil
);
3017 w
->left_margin_cols
= save_left
;
3018 w
->right_margin_cols
= save_right
;
3020 Fset_window_margins (window
,
3021 b
->left_margin_cols
, b
->right_margin_cols
);
3026 if (! NILP (Vwindow_scroll_functions
))
3027 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3028 Fmarker_position (w
->start
));
3030 if (! NILP (Vwindow_configuration_change_hook
)
3031 && ! NILP (Vrun_hooks
))
3032 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3035 unbind_to (count
, Qnil
);
3039 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3040 doc
: /* Make WINDOW display BUFFER as its contents.
3041 BUFFER can be a buffer or the name of an existing buffer.
3042 Optional third arg KEEP-MARGINS non-nil means that WINDOW's current
3043 display margins, fringe widths, and scroll bar settings are maintained;
3044 the default is to reset these from BUFFER's local settings or the frame
3046 (window
, buffer
, keep_margins
)
3047 register Lisp_Object window
, buffer
, keep_margins
;
3049 register Lisp_Object tem
;
3050 register struct window
*w
= decode_window (window
);
3052 XSETWINDOW (window
, w
);
3053 buffer
= Fget_buffer (buffer
);
3054 CHECK_BUFFER (buffer
);
3056 if (NILP (XBUFFER (buffer
)->name
))
3057 error ("Attempt to display deleted buffer");
3061 error ("Window is deleted");
3062 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
3063 is first being set up. */
3065 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
3066 error ("Window is dedicated to `%s'",
3067 SDATA (XBUFFER (tem
)->name
));
3072 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3076 /* Note that selected_window can be nil
3077 when this is called from Fset_window_configuration. */
3079 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
3080 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
3081 If WINDOW is not already selected, make WINDOW's buffer current
3082 and make WINDOW the frame's selected window. Return WINDOW.
3083 Optional second arg NORECORD non-nil means
3084 do not put this buffer at the front of the list of recently selected ones.
3086 Note that the main editor command loop
3087 selects the buffer of the selected window before each command. */)
3089 register Lisp_Object window
, norecord
;
3091 register struct window
*w
;
3092 register struct window
*ow
;
3095 CHECK_LIVE_WINDOW (window
);
3097 w
= XWINDOW (window
);
3098 w
->frozen_window_start_p
= 0;
3100 XSETFASTINT (w
->use_time
, ++window_select_count
);
3101 if (EQ (window
, selected_window
))
3104 if (!NILP (selected_window
))
3106 ow
= XWINDOW (selected_window
);
3107 if (! NILP (ow
->buffer
))
3108 set_marker_both (ow
->pointm
, ow
->buffer
,
3109 BUF_PT (XBUFFER (ow
->buffer
)),
3110 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
3113 selected_window
= window
;
3114 sf
= SELECTED_FRAME ();
3115 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
3117 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
3118 /* Use this rather than Fhandle_switch_frame
3119 so that FRAME_FOCUS_FRAME is moved appropriately as we
3120 move around in the state where a minibuffer in a separate
3122 Fselect_frame (WINDOW_FRAME (w
), Qnil
);
3125 sf
->selected_window
= window
;
3127 if (NILP (norecord
))
3128 record_buffer (w
->buffer
);
3129 Fset_buffer (w
->buffer
);
3131 XBUFFER (w
->buffer
)->last_selected_window
= window
;
3133 /* Go to the point recorded in the window.
3134 This is important when the buffer is in more
3135 than one window. It also matters when
3136 redisplay_window has altered point after scrolling,
3137 because it makes the change only in the window. */
3139 register int new_point
= marker_position (w
->pointm
);
3140 if (new_point
< BEGV
)
3142 else if (new_point
> ZV
)
3148 windows_or_buffers_changed
++;
3153 select_window_norecord (window
)
3156 return Fselect_window (window
, Qt
);
3159 /* Deiconify the frame containing the window WINDOW,
3160 unless it is the selected frame;
3163 The reason for the exception for the selected frame
3164 is that it seems better not to change the selected frames visibility
3165 merely because of displaying a different buffer in it.
3166 The deiconification is useful when a buffer gets shown in
3167 another frame that you were not using lately. */
3170 display_buffer_1 (window
)
3173 Lisp_Object frame
= XWINDOW (window
)->frame
;
3174 FRAME_PTR f
= XFRAME (frame
);
3176 FRAME_SAMPLE_VISIBILITY (f
);
3178 if (EQ (frame
, selected_frame
))
3179 ; /* Assume the selected frame is already visible enough. */
3180 else if (minibuf_level
> 0
3181 && MINI_WINDOW_P (XWINDOW (selected_window
))
3182 && WINDOW_LIVE_P (minibuf_selected_window
)
3183 && EQ (frame
, WINDOW_FRAME (XWINDOW (minibuf_selected_window
))))
3184 ; /* Assume the frame from which we invoked the minibuffer is visible. */
3187 if (FRAME_ICONIFIED_P (f
))
3188 Fmake_frame_visible (frame
);
3189 else if (FRAME_VISIBLE_P (f
))
3190 Fraise_frame (frame
);
3196 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
3197 doc
: /* Returns non-nil if a buffer named BUFFER-NAME would be created specially.
3198 The value is actually t if the frame should be called with default frame
3199 parameters, and a list of frame parameters if they were specified.
3200 See `special-display-buffer-names', and `special-display-regexps'. */)
3202 Lisp_Object buffer_name
;
3206 CHECK_STRING (buffer_name
);
3208 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
3212 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
3216 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
3218 Lisp_Object car
= XCAR (tem
);
3220 && fast_string_match (car
, buffer_name
) >= 0)
3222 else if (CONSP (car
)
3223 && STRINGP (XCAR (car
))
3224 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
3230 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
3231 doc
: /* Returns non-nil if a new buffer named BUFFER-NAME would use the same window.
3232 See `same-window-buffer-names' and `same-window-regexps'. */)
3234 Lisp_Object buffer_name
;
3238 CHECK_STRING (buffer_name
);
3240 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
3244 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
3248 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
3250 Lisp_Object car
= XCAR (tem
);
3252 && fast_string_match (car
, buffer_name
) >= 0)
3254 else if (CONSP (car
)
3255 && STRINGP (XCAR (car
))
3256 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
3262 /* Use B so the default is (other-buffer). */
3263 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
3264 "BDisplay buffer: \nP",
3265 doc
: /* Make BUFFER appear in some window but don't select it.
3266 BUFFER must be the name of an existing buffer, or, when called from Lisp,
3268 If BUFFER is shown already in some window, just use that one,
3269 unless the window is the selected window and the optional second
3270 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).
3271 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
3272 Returns the window displaying BUFFER.
3273 If `display-buffer-reuse-frames' is non-nil, and another frame is currently
3274 displaying BUFFER, then simply raise that frame.
3276 The variables `special-display-buffer-names',
3277 `special-display-regexps', `same-window-buffer-names', and
3278 `same-window-regexps' customize how certain buffer names are handled.
3279 The latter two take effect only if NOT-THIS-WINDOW is t.
3281 If optional argument FRAME is `visible', search all visible frames.
3282 If FRAME is 0, search all visible and iconified frames.
3283 If FRAME is t, search all frames.
3284 If FRAME is a frame, search only that frame.
3285 If FRAME is nil, search only the selected frame
3286 (actually the last nonminibuffer frame),
3287 unless `pop-up-frames' or `display-buffer-reuse-frames' is non-nil,
3288 which means search visible and iconified frames.
3290 If a full-width window on a splittable frame is available to display
3291 the buffer, it may be split, subject to the value of the variable
3292 `split-height-threshold'.
3294 If `even-window-heights' is non-nil, window heights will be evened out
3295 if displaying the buffer causes two vertically adjacent windows to be
3297 (buffer
, not_this_window
, frame
)
3298 register Lisp_Object buffer
, not_this_window
, frame
;
3300 register Lisp_Object window
, tem
, swp
;
3304 buffer
= Fget_buffer (buffer
);
3305 CHECK_BUFFER (buffer
);
3307 if (!NILP (Vdisplay_buffer_function
))
3308 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
3310 if (NILP (not_this_window
)
3311 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
3312 return display_buffer_1 (selected_window
);
3314 /* See if the user has specified this buffer should appear
3315 in the selected window. */
3316 if (NILP (not_this_window
))
3318 swp
= Fsame_window_p (XBUFFER (buffer
)->name
);
3319 if (!NILP (swp
) && !no_switch_window (selected_window
))
3321 Fswitch_to_buffer (buffer
, Qnil
);
3322 return display_buffer_1 (selected_window
);
3326 /* If the user wants pop-up-frames or display-buffer-reuse-frames,
3327 look for a window showing BUFFER on any visible or iconified frame.
3328 Otherwise search only the current frame. */
3331 else if (pop_up_frames
3332 || display_buffer_reuse_frames
3333 || last_nonminibuf_frame
== 0)
3334 XSETFASTINT (tem
, 0);
3336 XSETFRAME (tem
, last_nonminibuf_frame
);
3338 window
= Fget_buffer_window (buffer
, tem
);
3340 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
3341 return display_buffer_1 (window
);
3343 /* Certain buffer names get special handling. */
3344 if (!NILP (Vspecial_display_function
) && NILP (swp
))
3346 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
3348 return call1 (Vspecial_display_function
, buffer
);
3350 return call2 (Vspecial_display_function
, buffer
, tem
);
3353 /* If there are no frames open that have more than a minibuffer,
3354 we need to create a new frame. */
3355 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
3357 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3358 Fset_window_buffer (window
, buffer
, Qnil
);
3359 return display_buffer_1 (window
);
3362 f
= SELECTED_FRAME ();
3364 || FRAME_MINIBUF_ONLY_P (f
)
3365 /* If the current frame is a special display frame,
3366 don't try to reuse its windows. */
3367 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (f
))->dedicated
))
3372 if (FRAME_MINIBUF_ONLY_P (f
))
3373 XSETFRAME (frames
, last_nonminibuf_frame
);
3374 /* Don't try to create a window if we would get an error. */
3375 if (split_height_threshold
< window_min_height
<< 1)
3376 split_height_threshold
= window_min_height
<< 1;
3378 /* Note that both Fget_largest_window and Fget_lru_window
3379 ignore minibuffers and dedicated windows.
3380 This means they can return nil. */
3382 /* If the frame we would try to split cannot be split,
3383 try other frames. */
3384 if (FRAME_NO_SPLIT_P (NILP (frames
) ? f
: last_nonminibuf_frame
))
3386 /* Try visible frames first. */
3387 window
= Fget_largest_window (Qvisible
);
3388 /* If that didn't work, try iconified frames. */
3390 window
= Fget_largest_window (make_number (0));
3392 window
= Fget_largest_window (Qt
);
3395 window
= Fget_largest_window (frames
);
3397 /* If we got a tall enough full-width window that can be split,
3400 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3401 && window_height (window
) >= split_height_threshold
3402 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
3403 window
= Fsplit_window (window
, Qnil
, Qnil
);
3406 Lisp_Object upper
, lower
, other
;
3408 window
= Fget_lru_window (frames
);
3409 /* If the LRU window is selected, and big enough,
3410 and can be split, split it. */
3412 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3413 && (EQ (window
, selected_window
)
3414 || EQ (XWINDOW (window
)->parent
, Qnil
))
3415 && window_height (window
) >= window_min_height
<< 1)
3416 window
= Fsplit_window (window
, Qnil
, Qnil
);
3417 /* If Fget_lru_window returned nil, try other approaches. */
3419 /* Try visible frames first. */
3421 window
= Fget_buffer_window (buffer
, Qvisible
);
3423 window
= Fget_largest_window (Qvisible
);
3424 /* If that didn't work, try iconified frames. */
3426 window
= Fget_buffer_window (buffer
, make_number (0));
3428 window
= Fget_largest_window (make_number (0));
3429 /* Try invisible frames. */
3431 window
= Fget_buffer_window (buffer
, Qt
);
3433 window
= Fget_largest_window (Qt
);
3434 /* As a last resort, make a new frame. */
3436 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3437 /* If window appears above or below another,
3438 even out their heights. */
3439 other
= upper
= lower
= Qnil
;
3440 if (!NILP (XWINDOW (window
)->prev
))
3441 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
3442 if (!NILP (XWINDOW (window
)->next
))
3443 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
3445 && !NILP (Veven_window_heights
)
3446 /* Check that OTHER and WINDOW are vertically arrayed. */
3447 && !EQ (XWINDOW (other
)->top_line
, XWINDOW (window
)->top_line
)
3448 && (XFASTINT (XWINDOW (other
)->total_lines
)
3449 > XFASTINT (XWINDOW (window
)->total_lines
)))
3451 int total
= (XFASTINT (XWINDOW (other
)->total_lines
)
3452 + XFASTINT (XWINDOW (window
)->total_lines
));
3453 enlarge_window (upper
,
3454 total
/ 2 - XFASTINT (XWINDOW (upper
)->total_lines
),
3460 window
= Fget_lru_window (Qnil
);
3462 Fset_window_buffer (window
, buffer
, Qnil
);
3463 return display_buffer_1 (window
);
3467 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3469 doc
: /* Force redisplay of all windows.
3470 If optional arg OBJECT is a window, force redisplay of that window only.
3471 If OBJECT is a buffer or buffer name, force redisplay of all windows
3472 displaying that buffer. */)
3478 windows_or_buffers_changed
++;
3479 update_mode_lines
++;
3483 if (WINDOWP (object
))
3485 struct window
*w
= XWINDOW (object
);
3486 mark_window_display_accurate (object
, 0);
3487 w
->update_mode_line
= Qt
;
3488 if (BUFFERP (w
->buffer
))
3489 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
3490 ++update_mode_lines
;
3494 if (STRINGP (object
))
3495 object
= Fget_buffer (object
);
3496 if (BUFFERP (object
) && !NILP (XBUFFER (object
)->name
))
3498 /* Walk all windows looking for buffer, and force update
3499 of each of those windows. */
3501 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3502 return NILP (object
) ? Qnil
: Qt
;
3505 /* If nothing suitable was found, just return.
3506 We could signal an error, but this feature will typically be used
3507 asynchronously in timers or process sentinels, so we don't. */
3513 temp_output_buffer_show (buf
)
3514 register Lisp_Object buf
;
3516 register struct buffer
*old
= current_buffer
;
3517 register Lisp_Object window
;
3518 register struct window
*w
;
3520 XBUFFER (buf
)->directory
= current_buffer
->directory
;
3523 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3527 #if 0 /* rms: there should be no reason for this. */
3528 XBUFFER (buf
)->prevent_redisplay_optimizations_p
= 1;
3530 set_buffer_internal (old
);
3532 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
3533 call1 (Vtemp_buffer_show_function
, buf
);
3536 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
3538 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3539 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3540 Vminibuf_scroll_window
= window
;
3541 w
= XWINDOW (window
);
3542 XSETFASTINT (w
->hscroll
, 0);
3543 XSETFASTINT (w
->min_hscroll
, 0);
3544 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3545 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3547 /* Run temp-buffer-show-hook, with the chosen window selected
3548 and its buffer current. */
3550 if (!NILP (Vrun_hooks
)
3551 && !NILP (Fboundp (Qtemp_buffer_show_hook
))
3552 && !NILP (Fsymbol_value (Qtemp_buffer_show_hook
)))
3554 int count
= SPECPDL_INDEX ();
3555 Lisp_Object prev_window
, prev_buffer
;
3556 prev_window
= selected_window
;
3557 XSETBUFFER (prev_buffer
, old
);
3559 /* Select the window that was chosen, for running the hook.
3560 Note: Both Fselect_window and select_window_norecord may
3561 set-buffer to the buffer displayed in the window,
3562 so we need to save the current buffer. --stef */
3563 record_unwind_protect (Fset_buffer
, prev_buffer
);
3564 record_unwind_protect (select_window_norecord
, prev_window
);
3565 Fselect_window (window
, Qt
);
3566 Fset_buffer (w
->buffer
);
3567 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
3568 unbind_to (count
, Qnil
);
3574 make_dummy_parent (window
)
3578 register struct window
*o
, *p
;
3581 o
= XWINDOW (window
);
3582 p
= allocate_window ();
3583 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
3584 ((struct Lisp_Vector
*) p
)->contents
[i
]
3585 = ((struct Lisp_Vector
*)o
)->contents
[i
];
3586 XSETWINDOW (new, p
);
3588 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
3590 /* Put new into window structure in place of window */
3591 replace_window (window
, new);
3604 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
3605 doc
: /* Split WINDOW, putting SIZE lines in the first of the pair.
3606 WINDOW defaults to selected one and SIZE to half its size.
3607 If optional third arg HORFLAG is non-nil, split side by side
3608 and put SIZE columns in the first of the pair. In that case,
3609 SIZE includes that window's scroll bar, or the divider column to its right.
3610 Interactively, all arguments are nil.
3612 Returns the newly created window (which is the lower or rightmost one).
3613 The upper or leftmost window is the original one and remains selected.
3614 See Info node `(elisp)Splitting Windows' for more details and examples.*/)
3615 (window
, size
, horflag
)
3616 Lisp_Object window
, size
, horflag
;
3618 register Lisp_Object
new;
3619 register struct window
*o
, *p
;
3621 register int size_int
;
3624 window
= selected_window
;
3626 CHECK_LIVE_WINDOW (window
);
3628 o
= XWINDOW (window
);
3629 fo
= XFRAME (WINDOW_FRAME (o
));
3633 if (!NILP (horflag
))
3634 /* Calculate the size of the left-hand window, by dividing
3635 the usable space in columns by two.
3636 We round up, since the left-hand window may include
3637 a dividing line, while the right-hand may not. */
3638 size_int
= (XFASTINT (o
->total_cols
) + 1) >> 1;
3640 size_int
= XFASTINT (o
->total_lines
) >> 1;
3644 CHECK_NUMBER (size
);
3645 size_int
= XINT (size
);
3648 if (MINI_WINDOW_P (o
))
3649 error ("Attempt to split minibuffer window");
3650 else if (window_fixed_size_p (o
, !NILP (horflag
), 0))
3651 error ("Attempt to split fixed-size window");
3653 check_min_window_sizes ();
3657 if (size_int
< window_min_height
)
3658 error ("Window height %d too small (after splitting)", size_int
);
3659 if (size_int
+ window_min_height
> XFASTINT (o
->total_lines
))
3660 error ("Window height %d too small (after splitting)",
3661 XFASTINT (o
->total_lines
) - size_int
);
3662 if (NILP (o
->parent
)
3663 || NILP (XWINDOW (o
->parent
)->vchild
))
3665 make_dummy_parent (window
);
3667 XWINDOW (new)->vchild
= window
;
3672 if (size_int
< window_min_width
)
3673 error ("Window width %d too small (after splitting)", size_int
);
3675 if (size_int
+ window_min_width
> XFASTINT (o
->total_cols
))
3676 error ("Window width %d too small (after splitting)",
3677 XFASTINT (o
->total_cols
) - size_int
);
3678 if (NILP (o
->parent
)
3679 || NILP (XWINDOW (o
->parent
)->hchild
))
3681 make_dummy_parent (window
);
3683 XWINDOW (new)->hchild
= window
;
3687 /* Now we know that window's parent is a vertical combination
3688 if we are dividing vertically, or a horizontal combination
3689 if we are making side-by-side windows */
3691 windows_or_buffers_changed
++;
3692 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
3693 new = make_window ();
3696 p
->frame
= o
->frame
;
3698 if (!NILP (p
->next
))
3699 XWINDOW (p
->next
)->prev
= new;
3702 p
->parent
= o
->parent
;
3704 p
->window_end_valid
= Qnil
;
3705 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
3707 /* Duplicate special geometry settings. */
3709 p
->left_margin_cols
= o
->left_margin_cols
;
3710 p
->right_margin_cols
= o
->right_margin_cols
;
3711 p
->left_fringe_width
= o
->left_fringe_width
;
3712 p
->right_fringe_width
= o
->right_fringe_width
;
3713 p
->fringes_outside_margins
= o
->fringes_outside_margins
;
3714 p
->scroll_bar_width
= o
->scroll_bar_width
;
3715 p
->vertical_scroll_bar_type
= o
->vertical_scroll_bar_type
;
3717 /* Apportion the available frame space among the two new windows */
3719 if (!NILP (horflag
))
3721 p
->total_lines
= o
->total_lines
;
3722 p
->top_line
= o
->top_line
;
3723 XSETFASTINT (p
->total_cols
, XFASTINT (o
->total_cols
) - size_int
);
3724 XSETFASTINT (o
->total_cols
, size_int
);
3725 XSETFASTINT (p
->left_col
, XFASTINT (o
->left_col
) + size_int
);
3726 adjust_window_margins (p
);
3727 adjust_window_margins (o
);
3731 p
->left_col
= o
->left_col
;
3732 p
->total_cols
= o
->total_cols
;
3733 XSETFASTINT (p
->total_lines
, XFASTINT (o
->total_lines
) - size_int
);
3734 XSETFASTINT (o
->total_lines
, size_int
);
3735 XSETFASTINT (p
->top_line
, XFASTINT (o
->top_line
) + size_int
);
3738 /* Adjust glyph matrices. */
3741 Fset_window_buffer (new, o
->buffer
, Qt
);
3745 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 3, "p",
3746 doc
: /* Make current window ARG lines bigger.
3747 From program, optional second arg non-nil means grow sideways ARG columns.
3748 Interactively, if an argument is not given, make the window one line bigger.
3750 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3751 of the siblings above or to the left of the selected window. Only
3752 siblings to the right or below are changed. */)
3753 (arg
, side
, preserve_before
)
3754 register Lisp_Object arg
, side
, preserve_before
;
3757 enlarge_window (selected_window
, XINT (arg
), !NILP (side
),
3758 !NILP (preserve_before
));
3760 if (! NILP (Vwindow_configuration_change_hook
))
3761 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3766 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 3, "p",
3767 doc
: /* Make current window ARG lines smaller.
3768 From program, optional second arg non-nil means shrink sideways arg columns.
3769 Interactively, if an argument is not given, make the window one line smaller.
3771 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3772 of the siblings above or to the left of the selected window. Only
3773 siblings to the right or below are changed. */)
3774 (arg
, side
, preserve_before
)
3775 register Lisp_Object arg
, side
, preserve_before
;
3778 enlarge_window (selected_window
, -XINT (arg
), !NILP (side
),
3779 !NILP (preserve_before
));
3781 if (! NILP (Vwindow_configuration_change_hook
))
3782 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3788 window_height (window
)
3791 register struct window
*p
= XWINDOW (window
);
3792 return WINDOW_TOTAL_LINES (p
);
3796 window_width (window
)
3799 register struct window
*p
= XWINDOW (window
);
3800 return WINDOW_TOTAL_COLS (p
);
3805 *(widthflag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line))
3807 #define CURSIZE(w) \
3808 *(widthflag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines))
3811 /* Enlarge WINDOW by DELTA. WIDTHFLAG non-zero means
3812 increase its width. Siblings of the selected window are resized to
3813 fulfill the size request. If they become too small in the process,
3814 they will be deleted.
3816 If PRESERVE_BEFORE is nonzero, that means don't alter
3817 the siblings to the left or above WINDOW. */
3820 enlarge_window (window
, delta
, widthflag
, preserve_before
)
3822 int delta
, widthflag
, preserve_before
;
3824 Lisp_Object parent
, next
, prev
;
3828 int (*sizefun
) P_ ((Lisp_Object
))
3829 = widthflag
? window_width
: window_height
;
3830 void (*setsizefun
) P_ ((Lisp_Object
, int, int))
3831 = (widthflag
? set_window_width
: set_window_height
);
3833 /* Check values of window_min_width and window_min_height for
3835 check_min_window_sizes ();
3837 /* Give up if this window cannot be resized. */
3838 if (window_fixed_size_p (XWINDOW (window
), widthflag
, 1))
3839 error ("Window is not resizable");
3841 /* Find the parent of the selected window. */
3844 p
= XWINDOW (window
);
3850 error ("No other window to side of this one");
3855 ? !NILP (XWINDOW (parent
)->hchild
)
3856 : !NILP (XWINDOW (parent
)->vchild
))
3862 sizep
= &CURSIZE (window
);
3865 register int maxdelta
;
3867 /* Compute the maximum size increment this window can have. */
3869 if (preserve_before
)
3873 maxdelta
= (*sizefun
) (parent
) - XINT (*sizep
);
3874 /* Subtract size of siblings before, since we can't take that. */
3875 maxdelta
-= XINT (CURBEG (window
)) - XINT (CURBEG (parent
));
3878 maxdelta
= (!NILP (p
->next
) ? ((*sizefun
) (p
->next
)
3879 - window_min_size (XWINDOW (p
->next
),
3884 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - XINT (*sizep
)
3885 /* This is a main window followed by a minibuffer. */
3886 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
3887 - window_min_size (XWINDOW (p
->next
),
3889 /* This is a minibuffer following a main window. */
3890 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
3891 - window_min_size (XWINDOW (p
->prev
),
3893 /* This is a frame with only one window, a minibuffer-only
3894 or a minibufferless frame. */
3897 if (delta
> maxdelta
)
3898 /* This case traps trying to make the minibuffer
3899 the full frame, or make the only window aside from the
3900 minibuffer the full frame. */
3904 if (XINT (*sizep
) + delta
< window_min_size (XWINDOW (window
), widthflag
, 0, 0))
3906 delete_window (window
);
3913 /* Find the total we can get from other siblings without deleting them. */
3915 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
3916 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
3918 if (! preserve_before
)
3919 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
3920 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
3923 /* If we can get it all from them without deleting them, do so. */
3924 if (delta
<= maximum
)
3926 Lisp_Object first_unaffected
;
3927 Lisp_Object first_affected
;
3932 first_affected
= window
;
3933 /* Look at one sibling at a time,
3934 moving away from this window in both directions alternately,
3935 and take as much as we can get without deleting that sibling. */
3937 && (!NILP (next
) || (!preserve_before
&& !NILP (prev
))))
3941 int this_one
= ((*sizefun
) (next
)
3942 - window_min_size (XWINDOW (next
),
3943 widthflag
, 0, &fixed_p
));
3946 if (this_one
> delta
)
3949 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
3950 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
3955 next
= XWINDOW (next
)->next
;
3961 if (!preserve_before
&& ! NILP (prev
))
3963 int this_one
= ((*sizefun
) (prev
)
3964 - window_min_size (XWINDOW (prev
),
3965 widthflag
, 0, &fixed_p
));
3968 if (this_one
> delta
)
3971 first_affected
= prev
;
3973 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
3974 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
3979 prev
= XWINDOW (prev
)->prev
;
3983 xassert (delta
== 0);
3985 /* Now recalculate the edge positions of all the windows affected,
3986 based on the new sizes. */
3987 first_unaffected
= next
;
3988 prev
= first_affected
;
3989 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
3990 prev
= next
, next
= XWINDOW (next
)->next
)
3992 XSETINT (CURBEG (next
), XINT (CURBEG (prev
)) + (*sizefun
) (prev
));
3993 /* This does not change size of NEXT,
3994 but it propagates the new top edge to its children */
3995 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
4000 register int delta1
;
4001 register int opht
= (*sizefun
) (parent
);
4003 if (opht
<= XINT (*sizep
) + delta
)
4005 /* If trying to grow this window to or beyond size of the parent,
4006 just delete all the sibling windows. */
4007 Lisp_Object start
, tem
, next
;
4009 start
= XWINDOW (parent
)->vchild
;
4011 start
= XWINDOW (parent
)->hchild
;
4013 /* Delete any siblings that come after WINDOW. */
4014 tem
= XWINDOW (window
)->next
;
4015 while (! NILP (tem
))
4017 next
= XWINDOW (tem
)->next
;
4018 delete_window (tem
);
4022 /* Delete any siblings that come after WINDOW.
4023 Note that if START is not WINDOW, then WINDOW still
4024 Fhas siblings, so WINDOW has not yet replaced its parent. */
4026 while (! EQ (tem
, window
))
4028 next
= XWINDOW (tem
)->next
;
4029 delete_window (tem
);
4035 /* Otherwise, make delta1 just right so that if we add
4036 delta1 lines to this window and to the parent, and then
4037 shrink the parent back to its original size, the new
4038 proportional size of this window will increase by delta.
4040 The function size_window will compute the new height h'
4041 of the window from delta1 as:
4044 x = delta1 - delta1/n * n for the 1st resizable child
4047 where n is the number of children that can be resized.
4048 We can ignore x by choosing a delta1 that is a multiple of
4049 n. We want the height of this window to come out as
4059 The number of children n equals the number of resizable
4060 children of this window + 1 because we know window itself
4061 is resizable (otherwise we would have signalled an error. */
4063 struct window
*w
= XWINDOW (window
);
4067 for (s
= w
->next
; !NILP (s
); s
= XWINDOW (s
)->next
)
4068 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
4070 for (s
= w
->prev
; !NILP (s
); s
= XWINDOW (s
)->prev
)
4071 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
4076 /* Add delta1 lines or columns to this window, and to the parent,
4077 keeping things consistent while not affecting siblings. */
4078 XSETINT (CURSIZE (parent
), opht
+ delta1
);
4079 (*setsizefun
) (window
, XINT (*sizep
) + delta1
, 0);
4081 /* Squeeze out delta1 lines or columns from our parent,
4082 shriking this window and siblings proportionately.
4083 This brings parent back to correct size.
4084 Delta1 was calculated so this makes this window the desired size,
4085 taking it all out of the siblings. */
4086 (*setsizefun
) (parent
, opht
, 0);
4091 XSETFASTINT (p
->last_modified
, 0);
4092 XSETFASTINT (p
->last_overlay_modified
, 0);
4094 /* Adjust glyph matrices. */
4095 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4103 /***********************************************************************
4104 Resizing Mini-Windows
4105 ***********************************************************************/
4107 static void shrink_window_lowest_first
P_ ((struct window
*, int));
4109 enum save_restore_action
4116 static int save_restore_orig_size
P_ ((struct window
*,
4117 enum save_restore_action
));
4119 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
4120 from lowest windows first. */
4123 shrink_window_lowest_first (w
, height
)
4131 xassert (!MINI_WINDOW_P (w
));
4133 /* Set redisplay hints. */
4134 XSETFASTINT (w
->last_modified
, 0);
4135 XSETFASTINT (w
->last_overlay_modified
, 0);
4136 windows_or_buffers_changed
++;
4137 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
4139 old_height
= XFASTINT (w
->total_lines
);
4140 XSETFASTINT (w
->total_lines
, height
);
4142 if (!NILP (w
->hchild
))
4144 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
4146 c
= XWINDOW (child
);
4147 c
->top_line
= w
->top_line
;
4148 shrink_window_lowest_first (c
, height
);
4151 else if (!NILP (w
->vchild
))
4153 Lisp_Object last_child
;
4154 int delta
= old_height
- height
;
4159 /* Find the last child. We are taking space from lowest windows
4160 first, so we iterate over children from the last child
4162 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
4165 /* Assign new heights. We leave only MIN_SAFE_WINDOW_HEIGHT. */
4166 for (child
= last_child
; delta
&& !NILP (child
); child
= c
->prev
)
4170 c
= XWINDOW (child
);
4171 this_one
= XFASTINT (c
->total_lines
) - MIN_SAFE_WINDOW_HEIGHT
;
4173 if (this_one
> delta
)
4176 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
) - this_one
);
4180 /* Compute new positions. */
4181 last_top
= XINT (w
->top_line
);
4182 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
4184 c
= XWINDOW (child
);
4185 c
->top_line
= make_number (last_top
);
4186 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
));
4187 last_top
+= XFASTINT (c
->total_lines
);
4193 /* Save, restore, or check positions and sizes in the window tree
4194 rooted at W. ACTION says what to do.
4196 If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and
4197 orig_total_lines members are valid for all windows in the window
4198 tree. Value is non-zero if they are valid.
4200 If ACTION is SAVE_ORIG_SIZES, save members top and height in
4201 orig_top_line and orig_total_lines for all windows in the tree.
4203 If ACTION is RESTORE_ORIG_SIZES, restore top and height from values
4204 stored in orig_top_line and orig_total_lines for all windows. */
4207 save_restore_orig_size (w
, action
)
4209 enum save_restore_action action
;
4215 if (!NILP (w
->hchild
))
4217 if (!save_restore_orig_size (XWINDOW (w
->hchild
), action
))
4220 else if (!NILP (w
->vchild
))
4222 if (!save_restore_orig_size (XWINDOW (w
->vchild
), action
))
4228 case CHECK_ORIG_SIZES
:
4229 if (!INTEGERP (w
->orig_top_line
) || !INTEGERP (w
->orig_total_lines
))
4233 case SAVE_ORIG_SIZES
:
4234 w
->orig_top_line
= w
->top_line
;
4235 w
->orig_total_lines
= w
->total_lines
;
4236 XSETFASTINT (w
->last_modified
, 0);
4237 XSETFASTINT (w
->last_overlay_modified
, 0);
4240 case RESTORE_ORIG_SIZES
:
4241 xassert (INTEGERP (w
->orig_top_line
) && INTEGERP (w
->orig_total_lines
));
4242 w
->top_line
= w
->orig_top_line
;
4243 w
->total_lines
= w
->orig_total_lines
;
4244 w
->orig_total_lines
= w
->orig_top_line
= Qnil
;
4245 XSETFASTINT (w
->last_modified
, 0);
4246 XSETFASTINT (w
->last_overlay_modified
, 0);
4253 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
4260 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
4261 without deleting other windows. */
4264 grow_mini_window (w
, delta
)
4268 struct frame
*f
= XFRAME (w
->frame
);
4269 struct window
*root
;
4271 xassert (MINI_WINDOW_P (w
));
4272 xassert (delta
>= 0);
4274 /* Check values of window_min_width and window_min_height for
4276 check_min_window_sizes ();
4278 /* Compute how much we can enlarge the mini-window without deleting
4280 root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4283 int min_height
= window_min_size (root
, 0, 0, 0);
4284 if (XFASTINT (root
->total_lines
) - delta
< min_height
)
4285 /* Note that the root window may already be smaller than
4287 delta
= max (0, XFASTINT (root
->total_lines
) - min_height
);
4292 /* Save original window sizes and positions, if not already done. */
4293 if (!save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4294 save_restore_orig_size (root
, SAVE_ORIG_SIZES
);
4296 /* Shrink other windows. */
4297 shrink_window_lowest_first (root
, XFASTINT (root
->total_lines
) - delta
);
4299 /* Grow the mini-window. */
4300 w
->top_line
= make_number (XFASTINT (root
->top_line
) + XFASTINT (root
->total_lines
));
4301 w
->total_lines
= make_number (XFASTINT (w
->total_lines
) + delta
);
4302 XSETFASTINT (w
->last_modified
, 0);
4303 XSETFASTINT (w
->last_overlay_modified
, 0);
4310 /* Shrink mini-window W. If there is recorded info about window sizes
4311 before a call to grow_mini_window, restore recorded window sizes.
4312 Otherwise, if the mini-window is higher than 1 line, resize it to 1
4316 shrink_mini_window (w
)
4319 struct frame
*f
= XFRAME (w
->frame
);
4320 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4322 if (save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4324 save_restore_orig_size (root
, RESTORE_ORIG_SIZES
);
4326 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4327 windows_or_buffers_changed
= 1;
4329 else if (XFASTINT (w
->total_lines
) > 1)
4331 /* Distribute the additional lines of the mini-window
4332 among the other windows. */
4334 XSETWINDOW (window
, w
);
4335 enlarge_window (window
, 1 - XFASTINT (w
->total_lines
), 0, 0);
4341 /* Mark window cursors off for all windows in the window tree rooted
4342 at W by setting their phys_cursor_on_p flag to zero. Called from
4343 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4344 the frame are cleared. */
4347 mark_window_cursors_off (w
)
4352 if (!NILP (w
->hchild
))
4353 mark_window_cursors_off (XWINDOW (w
->hchild
));
4354 else if (!NILP (w
->vchild
))
4355 mark_window_cursors_off (XWINDOW (w
->vchild
));
4357 w
->phys_cursor_on_p
= 0;
4359 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4364 /* Return number of lines of text (not counting mode lines) in W. */
4367 window_internal_height (w
)
4370 int ht
= XFASTINT (w
->total_lines
);
4372 if (!MINI_WINDOW_P (w
))
4374 if (!NILP (w
->parent
)
4375 || !NILP (w
->vchild
)
4376 || !NILP (w
->hchild
)
4379 || WINDOW_WANTS_MODELINE_P (w
))
4382 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4390 /* Return the number of columns in W.
4391 Don't count columns occupied by scroll bars or the vertical bar
4392 separating W from the sibling to its right. */
4395 window_box_text_cols (w
)
4398 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4399 int width
= XINT (w
->total_cols
);
4401 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
4402 /* Scroll bars occupy a few columns. */
4403 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
4404 else if (!FRAME_WINDOW_P (f
)
4405 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
4406 /* The column of `|' characters separating side-by-side windows
4407 occupies one column only. */
4410 if (FRAME_WINDOW_P (f
))
4411 /* On window-systems, fringes and display margins cannot be
4412 used for normal text. */
4413 width
-= (WINDOW_FRINGE_COLS (w
)
4414 + WINDOW_LEFT_MARGIN_COLS (w
)
4415 + WINDOW_RIGHT_MARGIN_COLS (w
));
4421 /************************************************************************
4423 ***********************************************************************/
4425 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4426 N screen-fulls, which is defined as the height of the window minus
4427 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4428 instead. Negative values of N mean scroll down. NOERROR non-zero
4429 means don't signal an error if we try to move over BEGV or ZV,
4433 window_scroll (window
, n
, whole
, noerror
)
4441 /* If we must, use the pixel-based version which is much slower than
4442 the line-based one but can handle varying line heights. */
4443 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4444 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4446 window_scroll_line_based (window
, n
, whole
, noerror
);
4452 /* Implementation of window_scroll that works based on pixel line
4453 heights. See the comment of window_scroll for parameter
4457 window_scroll_pixel_based (window
, n
, whole
, noerror
)
4464 struct window
*w
= XWINDOW (window
);
4465 struct text_pos start
;
4467 int this_scroll_margin
;
4469 /* True if we fiddled the window vscroll field without really scrolling. */
4472 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4474 /* If PT is not visible in WINDOW, move back one half of
4475 the screen. Allow PT to be partially visible, otherwise
4476 something like (scroll-down 1) with PT in the line before
4477 the partially visible one would recenter. */
4478 tem
= Fpos_visible_in_window_p (make_number (PT
), window
, Qt
);
4481 /* Move backward half the height of the window. Performance note:
4482 vmotion used here is about 10% faster, but would give wrong
4483 results for variable height lines. */
4484 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4485 it
.current_y
= it
.last_visible_y
;
4486 move_it_vertically (&it
, - window_box_height (w
) / 2);
4488 /* The function move_iterator_vertically may move over more than
4489 the specified y-distance. If it->w is small, e.g. a
4490 mini-buffer window, we may end up in front of the window's
4491 display area. This is the case when Start displaying at the
4492 start of the line containing PT in this case. */
4493 if (it
.current_y
<= 0)
4495 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4496 move_it_vertically (&it
, 0);
4500 start
= it
.current
.pos
;
4503 /* If scroll_preserve_screen_position is non-zero, we try to set
4504 point in the same window line as it is now, so get that line. */
4505 if (!NILP (Vscroll_preserve_screen_position
))
4507 start_display (&it
, w
, start
);
4508 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4509 preserve_y
= it
.current_y
;
4514 /* Move iterator it from start the specified distance forward or
4515 backward. The result is the new window start. */
4516 start_display (&it
, w
, start
);
4519 int screen_full
= (window_box_height (w
)
4520 - next_screen_context_lines
* FRAME_LINE_HEIGHT (it
.f
));
4521 int dy
= n
* screen_full
;
4523 /* Note that move_it_vertically always moves the iterator to the
4524 start of a line. So, if the last line doesn't have a newline,
4525 we would end up at the start of the line ending at ZV. */
4527 move_it_vertically_backward (&it
, -dy
);
4529 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4530 MOVE_TO_POS
| MOVE_TO_Y
);
4533 move_it_by_lines (&it
, n
, 1);
4535 /* We failed if we find ZV is already on the screen (scrolling up,
4536 means there's nothing past the end), or if we can't start any
4537 earlier (scrolling down, means there's nothing past the top). */
4538 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4539 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4541 if (IT_CHARPOS (it
) == ZV
)
4543 if (it
.current_y
< it
.last_visible_y
4544 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4545 >= it
.last_visible_y
))
4547 /* The last line was only partially visible, make it fully
4549 w
->vscroll
= (it
.last_visible_y
4550 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4551 adjust_glyphs (it
.f
);
4556 Fsignal (Qend_of_buffer
, Qnil
);
4560 if (w
->vscroll
!= 0)
4561 /* The first line was only partially visible, make it fully
4567 Fsignal (Qbeginning_of_buffer
, Qnil
);
4570 /* If control gets here, then we vscrolled. */
4572 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
4574 /* Don't try to change the window start below. */
4580 int pos
= IT_CHARPOS (it
);
4583 /* If in the middle of a multi-glyph character move forward to
4584 the next character. */
4585 if (in_display_vector_p (&it
))
4588 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
4591 /* Set the window start, and set up the window for redisplay. */
4592 set_marker_restricted (w
->start
, make_number (pos
),
4594 bytepos
= XMARKER (w
->start
)->bytepos
;
4595 w
->start_at_line_beg
= ((pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n')
4597 w
->update_mode_line
= Qt
;
4598 XSETFASTINT (w
->last_modified
, 0);
4599 XSETFASTINT (w
->last_overlay_modified
, 0);
4600 /* Set force_start so that redisplay_window will run the
4601 window-scroll-functions. */
4602 w
->force_start
= Qt
;
4605 it
.current_y
= it
.vpos
= 0;
4607 /* Preserve the screen position if we must. */
4608 if (preserve_y
>= 0)
4610 move_it_to (&it
, -1, -1, preserve_y
, -1, MOVE_TO_Y
);
4611 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4615 /* Move PT out of scroll margins. */
4616 this_scroll_margin
= max (0, scroll_margin
);
4617 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->total_lines
) / 4);
4618 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
4622 /* We moved the window start towards ZV, so PT may be now
4623 in the scroll margin at the top. */
4624 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4625 while (it
.current_y
< this_scroll_margin
)
4627 int prev
= it
.current_y
;
4628 move_it_by_lines (&it
, 1, 1);
4629 if (prev
== it
.current_y
)
4632 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4636 int charpos
, bytepos
;
4638 /* We moved the window start towards BEGV, so PT may be now
4639 in the scroll margin at the bottom. */
4640 move_it_to (&it
, PT
, -1,
4641 it
.last_visible_y
- this_scroll_margin
- 1, -1,
4642 MOVE_TO_POS
| MOVE_TO_Y
);
4644 /* Save our position, in case it's correct. */
4645 charpos
= IT_CHARPOS (it
);
4646 bytepos
= IT_BYTEPOS (it
);
4648 /* See if point is on a partially visible line at the end. */
4649 move_it_by_lines (&it
, 1, 1);
4650 if (it
.current_y
> it
.last_visible_y
)
4651 /* The last line was only partially visible, so back up two
4652 lines to make sure we're on a fully visible line. */
4654 move_it_by_lines (&it
, -2, 0);
4655 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4658 /* No, the position we saved is OK, so use it. */
4659 SET_PT_BOTH (charpos
, bytepos
);
4665 /* Implementation of window_scroll that works based on screen lines.
4666 See the comment of window_scroll for parameter descriptions. */
4669 window_scroll_line_based (window
, n
, whole
, noerror
)
4675 register struct window
*w
= XWINDOW (window
);
4676 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
4677 register int pos
, pos_byte
;
4678 register int ht
= window_internal_height (w
);
4679 register Lisp_Object tem
;
4683 struct position posit
;
4686 /* If scrolling screen-fulls, compute the number of lines to
4687 scroll from the window's height. */
4689 n
*= max (1, ht
- next_screen_context_lines
);
4691 startpos
= marker_position (w
->start
);
4693 posit
= *compute_motion (startpos
, 0, 0, 0,
4695 window_box_text_cols (w
), XINT (w
->hscroll
),
4697 original_vpos
= posit
.vpos
;
4699 XSETFASTINT (tem
, PT
);
4700 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
4704 Fvertical_motion (make_number (- (ht
/ 2)), window
);
4709 lose
= n
< 0 && PT
== BEGV
;
4710 Fvertical_motion (make_number (n
), window
);
4714 SET_PT_BOTH (opoint
, opoint_byte
);
4721 Fsignal (Qbeginning_of_buffer
, Qnil
);
4726 int this_scroll_margin
= scroll_margin
;
4728 /* Don't use a scroll margin that is negative or too large. */
4729 if (this_scroll_margin
< 0)
4730 this_scroll_margin
= 0;
4732 if (XINT (w
->total_lines
) < 4 * scroll_margin
)
4733 this_scroll_margin
= XINT (w
->total_lines
) / 4;
4735 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
4736 w
->start_at_line_beg
= bolp
;
4737 w
->update_mode_line
= Qt
;
4738 XSETFASTINT (w
->last_modified
, 0);
4739 XSETFASTINT (w
->last_overlay_modified
, 0);
4740 /* Set force_start so that redisplay_window will run
4741 the window-scroll-functions. */
4742 w
->force_start
= Qt
;
4744 if (whole
&& !NILP (Vscroll_preserve_screen_position
))
4746 SET_PT_BOTH (pos
, pos_byte
);
4747 Fvertical_motion (make_number (original_vpos
), window
);
4749 /* If we scrolled forward, put point enough lines down
4750 that it is outside the scroll margin. */
4755 if (this_scroll_margin
> 0)
4757 SET_PT_BOTH (pos
, pos_byte
);
4758 Fvertical_motion (make_number (this_scroll_margin
), window
);
4764 if (top_margin
<= opoint
)
4765 SET_PT_BOTH (opoint
, opoint_byte
);
4766 else if (!NILP (Vscroll_preserve_screen_position
))
4768 SET_PT_BOTH (pos
, pos_byte
);
4769 Fvertical_motion (make_number (original_vpos
), window
);
4772 SET_PT (top_margin
);
4778 /* If we scrolled backward, put point near the end of the window
4779 but not within the scroll margin. */
4780 SET_PT_BOTH (pos
, pos_byte
);
4781 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
4782 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
4785 bottom_margin
= PT
+ 1;
4787 if (bottom_margin
> opoint
)
4788 SET_PT_BOTH (opoint
, opoint_byte
);
4791 if (!NILP (Vscroll_preserve_screen_position
))
4793 SET_PT_BOTH (pos
, pos_byte
);
4794 Fvertical_motion (make_number (original_vpos
), window
);
4797 Fvertical_motion (make_number (-1), window
);
4806 Fsignal (Qend_of_buffer
, Qnil
);
4811 /* Scroll selected_window up or down. If N is nil, scroll a
4812 screen-full which is defined as the height of the window minus
4813 next_screen_context_lines. If N is the symbol `-', scroll.
4814 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4815 up. This is the guts of Fscroll_up and Fscroll_down. */
4818 scroll_command (n
, direction
)
4822 int count
= SPECPDL_INDEX ();
4824 xassert (abs (direction
) == 1);
4826 /* If selected window's buffer isn't current, make it current for
4827 the moment. But don't screw up if window_scroll gets an error. */
4828 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
4830 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4831 Fset_buffer (XWINDOW (selected_window
)->buffer
);
4833 /* Make redisplay consider other windows than just selected_window. */
4834 ++windows_or_buffers_changed
;
4838 window_scroll (selected_window
, direction
, 1, 0);
4839 else if (EQ (n
, Qminus
))
4840 window_scroll (selected_window
, -direction
, 1, 0);
4843 n
= Fprefix_numeric_value (n
);
4844 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
4847 unbind_to (count
, Qnil
);
4850 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
4851 doc
: /* Scroll text of current window upward ARG lines; or near full screen if no ARG.
4852 A near full screen is `next-screen-context-lines' less than a full screen.
4853 Negative ARG means scroll downward.
4854 If ARG is the atom `-', scroll downward by nearly full screen.
4855 When calling from a program, supply as argument a number, nil, or `-'. */)
4859 scroll_command (arg
, 1);
4863 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
4864 doc
: /* Scroll text of current window down ARG lines; or near full screen if no ARG.
4865 A near full screen is `next-screen-context-lines' less than a full screen.
4866 Negative ARG means scroll upward.
4867 If ARG is the atom `-', scroll upward by nearly full screen.
4868 When calling from a program, supply as argument a number, nil, or `-'. */)
4872 scroll_command (arg
, -1);
4876 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
4877 doc
: /* Return the other window for \"other window scroll\" commands.
4878 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4879 specifies the window.
4880 If `other-window-scroll-buffer' is non-nil, a window
4881 showing that buffer is used. */)
4886 if (MINI_WINDOW_P (XWINDOW (selected_window
))
4887 && !NILP (Vminibuf_scroll_window
))
4888 window
= Vminibuf_scroll_window
;
4889 /* If buffer is specified, scroll that buffer. */
4890 else if (!NILP (Vother_window_scroll_buffer
))
4892 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
4894 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
4898 /* Nothing specified; look for a neighboring window on the same
4900 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
4902 if (EQ (window
, selected_window
))
4903 /* That didn't get us anywhere; look for a window on another
4906 window
= Fnext_window (window
, Qnil
, Qt
);
4907 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
4908 && ! EQ (window
, selected_window
));
4911 CHECK_LIVE_WINDOW (window
);
4913 if (EQ (window
, selected_window
))
4914 error ("There is no other window");
4919 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
4920 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
4921 A near full screen is `next-screen-context-lines' less than a full screen.
4922 The next window is the one below the current one; or the one at the top
4923 if the current one is at the bottom. Negative ARG means scroll downward.
4924 If ARG is the atom `-', scroll downward by nearly full screen.
4925 When calling from a program, supply as argument a number, nil, or `-'.
4927 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4928 specifies the window to scroll.
4929 If `other-window-scroll-buffer' is non-nil, scroll the window
4930 showing that buffer, popping the buffer up if necessary. */)
4936 int count
= SPECPDL_INDEX ();
4938 window
= Fother_window_for_scrolling ();
4939 w
= XWINDOW (window
);
4941 /* Don't screw up if window_scroll gets an error. */
4942 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4943 ++windows_or_buffers_changed
;
4945 Fset_buffer (w
->buffer
);
4946 SET_PT (marker_position (w
->pointm
));
4949 window_scroll (window
, 1, 1, 1);
4950 else if (EQ (arg
, Qminus
))
4951 window_scroll (window
, -1, 1, 1);
4957 window_scroll (window
, XINT (arg
), 0, 1);
4960 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
4961 unbind_to (count
, Qnil
);
4966 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 1, "P",
4967 doc
: /* Scroll selected window display ARG columns left.
4968 Default for ARG is window width minus 2.
4969 Value is the total amount of leftward horizontal scrolling in
4970 effect after the change.
4971 If `automatic-hscrolling' is non-nil, the argument ARG modifies
4972 a lower bound for automatic scrolling, i.e. automatic scrolling
4973 will not scroll a window to a column less than the value returned
4974 by this function. */)
4976 register Lisp_Object arg
;
4980 struct window
*w
= XWINDOW (selected_window
);
4983 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
4985 arg
= Fprefix_numeric_value (arg
);
4987 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
4988 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
4990 if (interactive_p (0))
4991 w
->min_hscroll
= w
->hscroll
;
4996 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 1, "P",
4997 doc
: /* Scroll selected window display ARG columns right.
4998 Default for ARG is window width minus 2.
4999 Value is the total amount of leftward horizontal scrolling in
5000 effect after the change.
5001 If `automatic-hscrolling' is non-nil, the argument ARG modifies
5002 a lower bound for automatic scrolling, i.e. automatic scrolling
5003 will not scroll a window to a column less than the value returned
5004 by this function. */)
5006 register Lisp_Object arg
;
5010 struct window
*w
= XWINDOW (selected_window
);
5013 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5015 arg
= Fprefix_numeric_value (arg
);
5017 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
5018 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5020 if (interactive_p (0))
5021 w
->min_hscroll
= w
->hscroll
;
5026 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5027 doc
: /* Return the window which was selected when entering the minibuffer.
5028 Returns nil, if current window is not a minibuffer window. */)
5031 if (minibuf_level
> 0
5032 && MINI_WINDOW_P (XWINDOW (selected_window
))
5033 && WINDOW_LIVE_P (minibuf_selected_window
))
5034 return minibuf_selected_window
;
5039 /* Value is the number of lines actually displayed in window W,
5040 as opposed to its height. */
5043 displayed_window_lines (w
)
5047 struct text_pos start
;
5048 int height
= window_box_height (w
);
5049 struct buffer
*old_buffer
;
5052 if (XBUFFER (w
->buffer
) != current_buffer
)
5054 old_buffer
= current_buffer
;
5055 set_buffer_internal (XBUFFER (w
->buffer
));
5060 /* In case W->start is out of the accessible range, do something
5061 reasonable. This happens in Info mode when Info-scroll-down
5062 calls (recenter -1) while W->start is 1. */
5063 if (XMARKER (w
->start
)->charpos
< BEGV
)
5064 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5065 else if (XMARKER (w
->start
)->charpos
> ZV
)
5066 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
5068 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5070 start_display (&it
, w
, start
);
5071 move_it_vertically (&it
, height
);
5072 bottom_y
= line_bottom_y (&it
);
5074 /* rms: On a non-window display,
5075 the value of it.vpos at the bottom of the screen
5076 seems to be 1 larger than window_box_height (w).
5077 This kludge fixes a bug whereby (move-to-window-line -1)
5078 when ZV is on the last screen line
5079 moves to the previous screen line instead of the last one. */
5080 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5083 /* Add in empty lines at the bottom of the window. */
5084 if (bottom_y
< height
)
5086 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5087 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5091 set_buffer_internal (old_buffer
);
5097 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5098 doc
: /* Center point in window and redisplay frame.
5099 With prefix argument ARG, recenter putting point on screen line ARG
5100 relative to the current window. If ARG is negative, it counts up from the
5101 bottom of the window. (ARG should be less than the height of the window.)
5103 If ARG is omitted or nil, erase the entire frame and then
5104 redraw with point in the center of the current window.
5105 Just C-u as prefix means put point in the center of the window
5106 and redisplay normally--don't erase and redraw the frame. */)
5108 register Lisp_Object arg
;
5110 struct window
*w
= XWINDOW (selected_window
);
5111 struct buffer
*buf
= XBUFFER (w
->buffer
);
5112 struct buffer
*obuf
= current_buffer
;
5114 int charpos
, bytepos
;
5116 /* If redisplay is suppressed due to an error, try again. */
5117 obuf
->display_error_modiff
= 0;
5123 /* Invalidate pixel data calculated for all compositions. */
5124 for (i
= 0; i
< n_compositions
; i
++)
5125 composition_table
[i
]->font
= NULL
;
5127 Fredraw_frame (w
->frame
);
5128 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
5131 else if (CONSP (arg
)) /* Just C-u. */
5135 arg
= Fprefix_numeric_value (arg
);
5139 set_buffer_internal (buf
);
5141 /* Handle centering on a graphical frame specially. Such frames can
5142 have variable-height lines and centering point on the basis of
5143 line counts would lead to strange effects. */
5144 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5151 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5152 start_display (&it
, w
, pt
);
5153 move_it_vertically (&it
, - window_box_height (w
) / 2);
5154 charpos
= IT_CHARPOS (it
);
5155 bytepos
= IT_BYTEPOS (it
);
5157 else if (XINT (arg
) < 0)
5161 int y0
, y1
, h
, nlines
;
5163 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5164 start_display (&it
, w
, pt
);
5167 /* The amount of pixels we have to move back is the window
5168 height minus what's displayed in the line containing PT,
5169 and the lines below. */
5170 nlines
= - XINT (arg
) - 1;
5171 move_it_by_lines (&it
, nlines
, 1);
5173 y1
= line_bottom_y (&it
);
5175 /* If we can't move down NLINES lines because we hit
5176 the end of the buffer, count in some empty lines. */
5177 if (it
.vpos
< nlines
)
5178 y1
+= (nlines
- it
.vpos
) * FRAME_LINE_HEIGHT (it
.f
);
5180 h
= window_box_height (w
) - (y1
- y0
);
5182 start_display (&it
, w
, pt
);
5183 move_it_vertically (&it
, - h
);
5184 charpos
= IT_CHARPOS (it
);
5185 bytepos
= IT_BYTEPOS (it
);
5189 struct position pos
;
5190 pos
= *vmotion (PT
, - XINT (arg
), w
);
5191 charpos
= pos
.bufpos
;
5192 bytepos
= pos
.bytepos
;
5197 struct position pos
;
5198 int ht
= window_internal_height (w
);
5201 arg
= make_number (ht
/ 2);
5202 else if (XINT (arg
) < 0)
5203 arg
= make_number (XINT (arg
) + ht
);
5205 pos
= *vmotion (PT
, - XINT (arg
), w
);
5206 charpos
= pos
.bufpos
;
5207 bytepos
= pos
.bytepos
;
5210 /* Set the new window start. */
5211 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
5212 w
->window_end_valid
= Qnil
;
5214 w
->optional_new_start
= Qt
;
5216 if (bytepos
== BEGV_BYTE
|| FETCH_BYTE (bytepos
- 1) == '\n')
5217 w
->start_at_line_beg
= Qt
;
5219 w
->start_at_line_beg
= Qnil
;
5221 set_buffer_internal (obuf
);
5226 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5228 doc
: /* Return the height in lines of the text display area of WINDOW.
5229 This doesn't include the mode-line (or header-line if any) or any
5230 partial-height lines in the text display area. */)
5234 struct window
*w
= decode_window (window
);
5235 int pixel_height
= window_box_height (w
);
5236 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5237 return make_number (line_height
);
5242 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5244 doc
: /* Position point relative to window.
5245 With no argument, position point at center of window.
5246 An argument specifies vertical position within the window;
5247 zero means top of window, negative means relative to bottom of window. */)
5251 struct window
*w
= XWINDOW (selected_window
);
5255 window
= selected_window
;
5256 start
= marker_position (w
->start
);
5257 if (start
< BEGV
|| start
> ZV
)
5259 int height
= window_internal_height (w
);
5260 Fvertical_motion (make_number (- (height
/ 2)), window
);
5261 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
5262 w
->start_at_line_beg
= Fbolp ();
5263 w
->force_start
= Qt
;
5266 Fgoto_char (w
->start
);
5268 lines
= displayed_window_lines (w
);
5270 XSETFASTINT (arg
, lines
/ 2);
5273 arg
= Fprefix_numeric_value (arg
);
5275 XSETINT (arg
, XINT (arg
) + lines
);
5278 /* Skip past a partially visible first line. */
5280 XSETINT (arg
, XINT (arg
) + 1);
5282 return Fvertical_motion (arg
, window
);
5287 /***********************************************************************
5288 Window Configuration
5289 ***********************************************************************/
5291 struct save_window_data
5293 EMACS_INT size_from_Lisp_Vector_struct
;
5294 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5295 Lisp_Object frame_cols
, frame_lines
, frame_menu_bar_lines
;
5296 Lisp_Object frame_tool_bar_lines
;
5297 Lisp_Object selected_frame
;
5298 Lisp_Object current_window
;
5299 Lisp_Object current_buffer
;
5300 Lisp_Object minibuf_scroll_window
;
5301 Lisp_Object minibuf_selected_window
;
5302 Lisp_Object root_window
;
5303 Lisp_Object focus_frame
;
5304 /* Record the values of window-min-width and window-min-height
5305 so that window sizes remain consistent with them. */
5306 Lisp_Object min_width
, min_height
;
5307 /* A vector, each of whose elements is a struct saved_window
5309 Lisp_Object saved_windows
;
5312 /* This is saved as a Lisp_Vector */
5315 /* these first two must agree with struct Lisp_Vector in lisp.h */
5316 EMACS_INT size_from_Lisp_Vector_struct
;
5317 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5320 Lisp_Object buffer
, start
, pointm
, mark
;
5321 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5322 Lisp_Object hscroll
, min_hscroll
;
5323 Lisp_Object parent
, prev
;
5324 Lisp_Object start_at_line_beg
;
5325 Lisp_Object display_table
;
5326 Lisp_Object orig_top_line
, orig_total_lines
;
5327 Lisp_Object left_margin_cols
, right_margin_cols
;
5328 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
5329 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
;
5332 #define SAVED_WINDOW_VECTOR_SIZE 24 /* Arg to Fmake_vector */
5334 #define SAVED_WINDOW_N(swv,n) \
5335 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5337 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
5338 doc
: /* Return t if OBJECT is a window-configuration object. */)
5342 if (WINDOW_CONFIGURATIONP (object
))
5347 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
5348 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5352 register struct save_window_data
*data
;
5353 struct Lisp_Vector
*saved_windows
;
5355 if (! WINDOW_CONFIGURATIONP (config
))
5356 wrong_type_argument (Qwindow_configuration_p
, config
);
5358 data
= (struct save_window_data
*) XVECTOR (config
);
5359 saved_windows
= XVECTOR (data
->saved_windows
);
5360 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5363 DEFUN ("set-window-configuration", Fset_window_configuration
,
5364 Sset_window_configuration
, 1, 1, 0,
5365 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5366 CONFIGURATION must be a value previously returned
5367 by `current-window-configuration' (which see).
5368 If CONFIGURATION was made from a frame that is now deleted,
5369 only frame-independent values can be restored. In this case,
5370 the return value is nil. Otherwise the value is t. */)
5372 Lisp_Object configuration
;
5374 register struct save_window_data
*data
;
5375 struct Lisp_Vector
*saved_windows
;
5376 Lisp_Object new_current_buffer
;
5381 while (!WINDOW_CONFIGURATIONP (configuration
))
5382 wrong_type_argument (Qwindow_configuration_p
, configuration
);
5384 data
= (struct save_window_data
*) XVECTOR (configuration
);
5385 saved_windows
= XVECTOR (data
->saved_windows
);
5387 new_current_buffer
= data
->current_buffer
;
5388 if (NILP (XBUFFER (new_current_buffer
)->name
))
5389 new_current_buffer
= Qnil
;
5392 if (XBUFFER (new_current_buffer
) == current_buffer
)
5395 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
5398 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5401 /* If f is a dead frame, don't bother rebuilding its window tree.
5402 However, there is other stuff we should still try to do below. */
5403 if (FRAME_LIVE_P (f
))
5405 register struct window
*w
;
5406 register struct saved_window
*p
;
5407 struct window
*root_window
;
5408 struct window
**leaf_windows
;
5412 /* If the frame has been resized since this window configuration was
5413 made, we change the frame to the size specified in the
5414 configuration, restore the configuration, and then resize it
5415 back. We keep track of the prevailing height in these variables. */
5416 int previous_frame_lines
= FRAME_LINES (f
);
5417 int previous_frame_cols
= FRAME_COLS (f
);
5418 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
5419 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
5421 /* The mouse highlighting code could get screwed up
5422 if it runs during this. */
5425 if (XFASTINT (data
->frame_lines
) != previous_frame_lines
5426 || XFASTINT (data
->frame_cols
) != previous_frame_cols
)
5427 change_frame_size (f
, XFASTINT (data
->frame_lines
),
5428 XFASTINT (data
->frame_cols
), 0, 0, 0);
5429 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5430 if (XFASTINT (data
->frame_menu_bar_lines
)
5431 != previous_frame_menu_bar_lines
)
5432 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, make_number (0));
5433 #ifdef HAVE_WINDOW_SYSTEM
5434 if (XFASTINT (data
->frame_tool_bar_lines
)
5435 != previous_frame_tool_bar_lines
)
5436 x_set_tool_bar_lines (f
, data
->frame_tool_bar_lines
, make_number (0));
5440 /* "Swap out" point from the selected window
5441 into its buffer. We do this now, before
5442 restoring the window contents, and prevent it from
5443 being done later on when we select a new window. */
5444 if (! NILP (XWINDOW (selected_window
)->buffer
))
5446 w
= XWINDOW (selected_window
);
5447 set_marker_both (w
->pointm
,
5449 BUF_PT (XBUFFER (w
->buffer
)),
5450 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5453 windows_or_buffers_changed
++;
5454 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
5456 /* Problem: Freeing all matrices and later allocating them again
5457 is a serious redisplay flickering problem. What we would
5458 really like to do is to free only those matrices not reused
5460 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5462 = (struct window
**) alloca (count_windows (root_window
)
5463 * sizeof (struct window
*));
5464 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
5466 /* Temporarily avoid any problems with windows that are smaller
5467 than they are supposed to be. */
5468 window_min_height
= 1;
5469 window_min_width
= 1;
5472 Mark all windows now on frame as "deleted".
5473 Restoring the new configuration "undeletes" any that are in it.
5475 Save their current buffers in their height fields, since we may
5476 need it later, if a buffer saved in the configuration is now
5478 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5480 for (k
= 0; k
< saved_windows
->size
; k
++)
5482 p
= SAVED_WINDOW_N (saved_windows
, k
);
5483 w
= XWINDOW (p
->window
);
5486 if (!NILP (p
->parent
))
5487 w
->parent
= SAVED_WINDOW_N (saved_windows
,
5488 XFASTINT (p
->parent
))->window
;
5492 if (!NILP (p
->prev
))
5494 w
->prev
= SAVED_WINDOW_N (saved_windows
,
5495 XFASTINT (p
->prev
))->window
;
5496 XWINDOW (w
->prev
)->next
= p
->window
;
5501 if (!NILP (w
->parent
))
5503 if (EQ (p
->total_cols
, XWINDOW (w
->parent
)->total_cols
))
5505 XWINDOW (w
->parent
)->vchild
= p
->window
;
5506 XWINDOW (w
->parent
)->hchild
= Qnil
;
5510 XWINDOW (w
->parent
)->hchild
= p
->window
;
5511 XWINDOW (w
->parent
)->vchild
= Qnil
;
5516 /* If we squirreled away the buffer in the window's height,
5518 if (BUFFERP (w
->total_lines
))
5519 w
->buffer
= w
->total_lines
;
5520 w
->left_col
= p
->left_col
;
5521 w
->top_line
= p
->top_line
;
5522 w
->total_cols
= p
->total_cols
;
5523 w
->total_lines
= p
->total_lines
;
5524 w
->hscroll
= p
->hscroll
;
5525 w
->min_hscroll
= p
->min_hscroll
;
5526 w
->display_table
= p
->display_table
;
5527 w
->orig_top_line
= p
->orig_top_line
;
5528 w
->orig_total_lines
= p
->orig_total_lines
;
5529 w
->left_margin_cols
= p
->left_margin_cols
;
5530 w
->right_margin_cols
= p
->right_margin_cols
;
5531 w
->left_fringe_width
= p
->left_fringe_width
;
5532 w
->right_fringe_width
= p
->right_fringe_width
;
5533 w
->fringes_outside_margins
= p
->fringes_outside_margins
;
5534 w
->scroll_bar_width
= p
->scroll_bar_width
;
5535 w
->vertical_scroll_bar_type
= p
->vertical_scroll_bar_type
;
5536 XSETFASTINT (w
->last_modified
, 0);
5537 XSETFASTINT (w
->last_overlay_modified
, 0);
5539 /* Reinstall the saved buffer and pointers into it. */
5540 if (NILP (p
->buffer
))
5541 w
->buffer
= p
->buffer
;
5544 if (!NILP (XBUFFER (p
->buffer
)->name
))
5545 /* If saved buffer is alive, install it. */
5547 w
->buffer
= p
->buffer
;
5548 w
->start_at_line_beg
= p
->start_at_line_beg
;
5549 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
5550 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
5551 Fset_marker (XBUFFER (w
->buffer
)->mark
,
5552 p
->mark
, w
->buffer
);
5554 /* As documented in Fcurrent_window_configuration, don't
5555 restore the location of point in the buffer which was
5556 current when the window configuration was recorded. */
5557 if (!EQ (p
->buffer
, new_current_buffer
)
5558 && XBUFFER (p
->buffer
) == current_buffer
)
5559 Fgoto_char (w
->pointm
);
5561 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
5562 /* Else unless window has a live buffer, get one. */
5564 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
5565 /* This will set the markers to beginning of visible
5567 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
5568 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
5569 w
->start_at_line_beg
= Qt
;
5572 /* Keeping window's old buffer; make sure the markers
5575 /* Set window markers at start of visible range. */
5576 if (XMARKER (w
->start
)->buffer
== 0)
5577 set_marker_restricted (w
->start
, make_number (0),
5579 if (XMARKER (w
->pointm
)->buffer
== 0)
5580 set_marker_restricted_both (w
->pointm
, w
->buffer
,
5581 BUF_PT (XBUFFER (w
->buffer
)),
5582 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5583 w
->start_at_line_beg
= Qt
;
5588 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
5589 /* Prevent "swapping out point" in the old selected window
5590 using the buffer that has been restored into it.
5591 Use the point value from the beginning of this function
5592 since unshow_buffer (called from delete_all_subwindows)
5593 could have altered it. */
5594 selected_window
= Qnil
;
5595 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
5596 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
5597 make_number (old_point
),
5598 XWINDOW (data
->current_window
)->buffer
);
5600 Fselect_window (data
->current_window
, Qnil
);
5601 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
5604 if (NILP (data
->focus_frame
)
5605 || (FRAMEP (data
->focus_frame
)
5606 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
5607 Fredirect_frame_focus (frame
, data
->focus_frame
);
5609 #if 0 /* I don't understand why this is needed, and it causes problems
5610 when the frame's old selected window has been deleted. */
5611 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
5612 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
5616 /* Set the screen height to the value it had before this function. */
5617 if (previous_frame_lines
!= FRAME_LINES (f
)
5618 || previous_frame_cols
!= FRAME_COLS (f
))
5619 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
5621 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5622 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
5623 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
5625 #ifdef HAVE_WINDOW_SYSTEM
5626 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
5627 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
5632 /* Now, free glyph matrices in windows that were not reused. */
5633 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
5635 if (NILP (leaf_windows
[i
]->buffer
))
5637 /* Assert it's not reused as a combination. */
5638 xassert (NILP (leaf_windows
[i
]->hchild
)
5639 && NILP (leaf_windows
[i
]->vchild
));
5640 free_window_matrices (leaf_windows
[i
]);
5642 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
5650 /* Fselect_window will have made f the selected frame, so we
5651 reselect the proper frame here. Fhandle_switch_frame will change the
5652 selected window too, but that doesn't make the call to
5653 Fselect_window above totally superfluous; it still sets f's
5655 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
5656 do_switch_frame (data
->selected_frame
, 0, 0);
5658 if (! NILP (Vwindow_configuration_change_hook
)
5659 && ! NILP (Vrun_hooks
))
5660 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
5663 if (!NILP (new_current_buffer
))
5664 Fset_buffer (new_current_buffer
);
5666 /* Restore the minimum heights recorded in the configuration. */
5667 window_min_height
= XINT (data
->min_height
);
5668 window_min_width
= XINT (data
->min_width
);
5670 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
5671 minibuf_selected_window
= data
->minibuf_selected_window
;
5673 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
5676 /* Mark all windows now on frame as deleted
5677 by setting their buffers to nil. */
5680 delete_all_subwindows (w
)
5681 register struct window
*w
;
5683 if (!NILP (w
->next
))
5684 delete_all_subwindows (XWINDOW (w
->next
));
5685 if (!NILP (w
->vchild
))
5686 delete_all_subwindows (XWINDOW (w
->vchild
));
5687 if (!NILP (w
->hchild
))
5688 delete_all_subwindows (XWINDOW (w
->hchild
));
5690 w
->total_lines
= w
->buffer
; /* See Fset_window_configuration for excuse. */
5692 if (!NILP (w
->buffer
))
5695 /* We set all three of these fields to nil, to make sure that we can
5696 distinguish this dead window from any live window. Live leaf
5697 windows will have buffer set, and combination windows will have
5698 vchild or hchild set. */
5703 Vwindow_list
= Qnil
;
5707 count_windows (window
)
5708 register struct window
*window
;
5710 register int count
= 1;
5711 if (!NILP (window
->next
))
5712 count
+= count_windows (XWINDOW (window
->next
));
5713 if (!NILP (window
->vchild
))
5714 count
+= count_windows (XWINDOW (window
->vchild
));
5715 if (!NILP (window
->hchild
))
5716 count
+= count_windows (XWINDOW (window
->hchild
));
5721 /* Fill vector FLAT with leaf windows under W, starting at index I.
5722 Value is last index + 1. */
5725 get_leaf_windows (w
, flat
, i
)
5727 struct window
**flat
;
5732 if (!NILP (w
->hchild
))
5733 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
5734 else if (!NILP (w
->vchild
))
5735 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
5739 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5746 /* Return a pointer to the glyph W's physical cursor is on. Value is
5747 null if W's current matrix is invalid, so that no meaningfull glyph
5751 get_phys_cursor_glyph (w
)
5754 struct glyph_row
*row
;
5755 struct glyph
*glyph
;
5757 if (w
->phys_cursor
.vpos
>= 0
5758 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
5759 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
5761 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
5762 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
5771 save_window_save (window
, vector
, i
)
5773 struct Lisp_Vector
*vector
;
5776 register struct saved_window
*p
;
5777 register struct window
*w
;
5778 register Lisp_Object tem
;
5780 for (;!NILP (window
); window
= w
->next
)
5782 p
= SAVED_WINDOW_N (vector
, i
);
5783 w
= XWINDOW (window
);
5785 XSETFASTINT (w
->temslot
, i
++);
5787 p
->buffer
= w
->buffer
;
5788 p
->left_col
= w
->left_col
;
5789 p
->top_line
= w
->top_line
;
5790 p
->total_cols
= w
->total_cols
;
5791 p
->total_lines
= w
->total_lines
;
5792 p
->hscroll
= w
->hscroll
;
5793 p
->min_hscroll
= w
->min_hscroll
;
5794 p
->display_table
= w
->display_table
;
5795 p
->orig_top_line
= w
->orig_top_line
;
5796 p
->orig_total_lines
= w
->orig_total_lines
;
5797 p
->left_margin_cols
= w
->left_margin_cols
;
5798 p
->right_margin_cols
= w
->right_margin_cols
;
5799 p
->left_fringe_width
= w
->left_fringe_width
;
5800 p
->right_fringe_width
= w
->right_fringe_width
;
5801 p
->fringes_outside_margins
= w
->fringes_outside_margins
;
5802 p
->scroll_bar_width
= w
->scroll_bar_width
;
5803 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
5804 if (!NILP (w
->buffer
))
5806 /* Save w's value of point in the window configuration.
5807 If w is the selected window, then get the value of point
5808 from the buffer; pointm is garbage in the selected window. */
5809 if (EQ (window
, selected_window
))
5811 p
->pointm
= Fmake_marker ();
5812 set_marker_both (p
->pointm
, w
->buffer
,
5813 BUF_PT (XBUFFER (w
->buffer
)),
5814 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5817 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
5819 p
->start
= Fcopy_marker (w
->start
, Qnil
);
5820 p
->start_at_line_beg
= w
->start_at_line_beg
;
5822 tem
= XBUFFER (w
->buffer
)->mark
;
5823 p
->mark
= Fcopy_marker (tem
, Qnil
);
5830 p
->start_at_line_beg
= Qnil
;
5833 if (NILP (w
->parent
))
5836 p
->parent
= XWINDOW (w
->parent
)->temslot
;
5841 p
->prev
= XWINDOW (w
->prev
)->temslot
;
5843 if (!NILP (w
->vchild
))
5844 i
= save_window_save (w
->vchild
, vector
, i
);
5845 if (!NILP (w
->hchild
))
5846 i
= save_window_save (w
->hchild
, vector
, i
);
5852 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
5853 Scurrent_window_configuration
, 0, 1, 0,
5854 doc
: /* Return an object representing the current window configuration of FRAME.
5855 If FRAME is nil or omitted, use the selected frame.
5856 This describes the number of windows, their sizes and current buffers,
5857 and for each displayed buffer, where display starts, and the positions of
5858 point and mark. An exception is made for point in the current buffer:
5859 its value is -not- saved.
5860 This also records the currently selected frame, and FRAME's focus
5861 redirection (see `redirect-frame-focus'). */)
5865 register Lisp_Object tem
;
5866 register int n_windows
;
5867 register struct save_window_data
*data
;
5868 register struct Lisp_Vector
*vec
;
5873 frame
= selected_frame
;
5874 CHECK_LIVE_FRAME (frame
);
5877 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5878 vec
= allocate_other_vector (VECSIZE (struct save_window_data
));
5879 data
= (struct save_window_data
*)vec
;
5881 XSETFASTINT (data
->frame_cols
, FRAME_COLS (f
));
5882 XSETFASTINT (data
->frame_lines
, FRAME_LINES (f
));
5883 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
5884 XSETFASTINT (data
->frame_tool_bar_lines
, FRAME_TOOL_BAR_LINES (f
));
5885 data
->selected_frame
= selected_frame
;
5886 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
5887 XSETBUFFER (data
->current_buffer
, current_buffer
);
5888 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
5889 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
5890 data
->root_window
= FRAME_ROOT_WINDOW (f
);
5891 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
5892 XSETINT (data
->min_height
, window_min_height
);
5893 XSETINT (data
->min_width
, window_min_width
);
5894 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
5895 data
->saved_windows
= tem
;
5896 for (i
= 0; i
< n_windows
; i
++)
5897 XVECTOR (tem
)->contents
[i
]
5898 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
5899 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
5900 XSETWINDOW_CONFIGURATION (tem
, data
);
5904 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
5906 doc
: /* Execute body, preserving window sizes and contents.
5907 Restore which buffer appears in which window, where display starts,
5908 and the value of point and mark for each window.
5909 Also restore the choice of selected window.
5910 Also restore which buffer is current.
5911 Does not restore the value of point in current buffer.
5912 usage: (save-window-excursion BODY ...) */)
5916 register Lisp_Object val
;
5917 register int count
= SPECPDL_INDEX ();
5919 record_unwind_protect (Fset_window_configuration
,
5920 Fcurrent_window_configuration (Qnil
));
5921 val
= Fprogn (args
);
5922 return unbind_to (count
, val
);
5926 /***********************************************************************
5928 ***********************************************************************/
5930 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
5932 doc
: /* Set width of marginal areas of window WINDOW.
5933 If WINDOW is nil, set margins of the currently selected window.
5934 Second arg LEFT-WIDTH specifies the number of character cells to
5935 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
5936 does the same for the right marginal area. A nil width parameter
5937 means no margin. */)
5938 (window
, left
, right
)
5939 Lisp_Object window
, left
, right
;
5941 struct window
*w
= decode_window (window
);
5943 /* Translate negative or zero widths to nil.
5944 Margins that are too wide have to be checked elsewhere. */
5948 CHECK_NUMBER (left
);
5949 if (XINT (left
) <= 0)
5955 CHECK_NUMBER (right
);
5956 if (XINT (right
) <= 0)
5960 if (!EQ (w
->left_margin_cols
, left
)
5961 || !EQ (w
->right_margin_cols
, right
))
5963 w
->left_margin_cols
= left
;
5964 w
->right_margin_cols
= right
;
5966 adjust_window_margins (w
);
5968 ++windows_or_buffers_changed
;
5969 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
5976 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
5978 doc
: /* Get width of marginal areas of window WINDOW.
5979 If WINDOW is omitted or nil, use the currently selected window.
5980 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
5981 If a marginal area does not exist, its width will be returned
5986 struct window
*w
= decode_window (window
);
5987 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
5992 /***********************************************************************
5994 ***********************************************************************/
5996 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
5998 doc
: /* Set the fringe widths of window WINDOW.
5999 If WINDOW is nil, set the fringe widths of the currently selected
6001 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6002 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6003 fringe width. If a fringe width arg is nil, that means to use the
6004 frame's default fringe width. Default fringe widths can be set with
6005 the command `set-fringe-style'.
6006 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6007 outside of the display margins. By default, fringes are drawn between
6008 display marginal areas and the text area. */)
6009 (window
, left
, right
, outside_margins
)
6010 Lisp_Object window
, left
, right
, outside_margins
;
6012 struct window
*w
= decode_window (window
);
6015 CHECK_NUMBER (left
);
6017 CHECK_NUMBER (right
);
6019 if (!EQ (w
->left_fringe_width
, left
)
6020 || !EQ (w
->right_fringe_width
, right
)
6021 || !EQ (w
->fringes_outside_margins
, outside_margins
))
6023 w
->left_fringe_width
= left
;
6024 w
->right_fringe_width
= right
;
6025 w
->fringes_outside_margins
= outside_margins
;
6027 adjust_window_margins (w
);
6029 clear_glyph_matrix (w
->current_matrix
);
6030 w
->window_end_valid
= Qnil
;
6032 ++windows_or_buffers_changed
;
6033 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6040 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6042 doc
: /* Get width of fringes of window WINDOW.
6043 If WINDOW is omitted or nil, use the currently selected window.
6044 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6048 struct window
*w
= decode_window (window
);
6049 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6050 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6051 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
) ?
6052 Qt
: Qnil
), Qnil
)));
6057 /***********************************************************************
6059 ***********************************************************************/
6061 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
, Sset_window_scroll_bars
,
6063 doc
: /* Set width and type of scroll bars of window WINDOW.
6064 If window is nil, set scroll bars of the currently selected window.
6065 Second parameter WIDTH specifies the pixel width for the scroll bar;
6066 this is automatically adjusted to a multiple of the frame column width.
6067 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6068 bar: left, right, or nil.
6069 If WIDTH is nil, use the frame's scroll-bar width.
6070 If TYPE is t, use the frame's scroll-bar type. */)
6071 (window
, width
, vertical_type
, horizontal_type
)
6072 Lisp_Object window
, width
, vertical_type
, horizontal_type
;
6074 struct window
*w
= decode_window (window
);
6077 CHECK_NUMBER (width
);
6079 if (XINT (width
) == 0)
6080 vertical_type
= Qnil
;
6082 if (!(EQ (vertical_type
, Qnil
)
6083 || EQ (vertical_type
, Qleft
)
6084 || EQ (vertical_type
, Qright
)
6085 || EQ (vertical_type
, Qt
)))
6086 error ("Invalid type of vertical scroll bar");
6088 if (!EQ (w
->scroll_bar_width
, width
)
6089 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6091 w
->scroll_bar_width
= width
;
6092 w
->vertical_scroll_bar_type
= vertical_type
;
6094 adjust_window_margins (w
);
6096 clear_glyph_matrix (w
->current_matrix
);
6097 w
->window_end_valid
= Qnil
;
6099 ++windows_or_buffers_changed
;
6100 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6107 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6109 doc
: /* Get width and type of scroll bars of window WINDOW.
6110 If WINDOW is omitted or nil, use the currently selected window.
6111 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6112 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6117 struct window
*w
= decode_window (window
);
6118 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6119 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6120 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6121 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6122 Fcons (w
->vertical_scroll_bar_type
,
6123 Fcons (Qnil
, Qnil
))));
6128 /***********************************************************************
6130 ***********************************************************************/
6132 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6133 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6134 Use the selected window if WINDOW is nil or omitted.
6135 Normally, value is a multiple of the canonical character height of WINDOW;
6136 optional second arg PIXELS_P means value is measured in pixels. */)
6138 Lisp_Object window
, pixels_p
;
6145 window
= selected_window
;
6147 CHECK_WINDOW (window
);
6148 w
= XWINDOW (window
);
6149 f
= XFRAME (w
->frame
);
6151 if (FRAME_WINDOW_P (f
))
6152 result
= (NILP (pixels_p
)
6153 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6154 : make_number (-w
->vscroll
));
6156 result
= make_number (0);
6161 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6163 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6164 WINDOW nil means use the selected window. Normally, VSCROLL is a
6165 non-negative multiple of the canonical character height of WINDOW;
6166 optional third arg PIXELS_P non-nil means that VSCROLL is in pixels. */)
6167 (window
, vscroll
, pixels_p
)
6168 Lisp_Object window
, vscroll
, pixels_p
;
6174 window
= selected_window
;
6176 CHECK_WINDOW (window
);
6177 CHECK_NUMBER_OR_FLOAT (vscroll
);
6179 w
= XWINDOW (window
);
6180 f
= XFRAME (w
->frame
);
6182 if (FRAME_WINDOW_P (f
))
6184 int old_dy
= w
->vscroll
;
6186 w
->vscroll
= - (NILP (pixels_p
)
6187 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
6188 : XFLOATINT (vscroll
));
6189 w
->vscroll
= min (w
->vscroll
, 0);
6191 /* Adjust glyph matrix of the frame if the virtual display
6192 area becomes larger than before. */
6193 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
6196 /* Prevent redisplay shortcuts. */
6197 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
6200 return Fwindow_vscroll (window
, pixels_p
);
6204 /* Call FN for all leaf windows on frame F. FN is called with the
6205 first argument being a pointer to the leaf window, and with
6206 additional argument USER_DATA. Stops when FN returns 0. */
6209 foreach_window (f
, fn
, user_data
)
6211 int (* fn
) P_ ((struct window
*, void *));
6214 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
6218 /* Helper function for foreach_window. Call FN for all leaf windows
6219 reachable from W. FN is called with the first argument being a
6220 pointer to the leaf window, and with additional argument USER_DATA.
6221 Stop when FN returns 0. Value is 0 if stopped by FN. */
6224 foreach_window_1 (w
, fn
, user_data
)
6226 int (* fn
) P_ ((struct window
*, void *));
6231 for (cont
= 1; w
&& cont
;)
6233 if (!NILP (w
->hchild
))
6234 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
6235 else if (!NILP (w
->vchild
))
6236 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
6238 cont
= fn (w
, user_data
);
6240 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6247 /* Freeze or unfreeze the window start of W unless it is a
6248 mini-window or the selected window. FREEZE_P non-null means freeze
6249 the window start. */
6252 freeze_window_start (w
, freeze_p
)
6256 if (w
== XWINDOW (selected_window
)
6257 || MINI_WINDOW_P (w
)
6258 || (MINI_WINDOW_P (XWINDOW (selected_window
))
6259 && ! NILP (Vminibuf_scroll_window
)
6260 && w
== XWINDOW (Vminibuf_scroll_window
)))
6263 w
->frozen_window_start_p
= freeze_p
!= NULL
;
6268 /* Freeze or unfreeze the window starts of all leaf windows on frame
6269 F, except the selected window and a mini-window. FREEZE_P non-zero
6270 means freeze the window start. */
6273 freeze_window_starts (f
, freeze_p
)
6277 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
6281 /***********************************************************************
6283 ***********************************************************************/
6285 /* Return 1 if window configurations C1 and C2
6286 describe the same state of affairs. This is used by Fequal. */
6289 compare_window_configurations (c1
, c2
, ignore_positions
)
6291 int ignore_positions
;
6293 register struct save_window_data
*d1
, *d2
;
6294 struct Lisp_Vector
*sw1
, *sw2
;
6297 if (!WINDOW_CONFIGURATIONP (c1
))
6298 wrong_type_argument (Qwindow_configuration_p
, c1
);
6299 if (!WINDOW_CONFIGURATIONP (c2
))
6300 wrong_type_argument (Qwindow_configuration_p
, c2
);
6302 d1
= (struct save_window_data
*) XVECTOR (c1
);
6303 d2
= (struct save_window_data
*) XVECTOR (c2
);
6304 sw1
= XVECTOR (d1
->saved_windows
);
6305 sw2
= XVECTOR (d2
->saved_windows
);
6307 if (! EQ (d1
->frame_cols
, d2
->frame_cols
))
6309 if (! EQ (d1
->frame_lines
, d2
->frame_lines
))
6311 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
6313 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
6315 /* Don't compare the current_window field directly.
6316 Instead see w1_is_current and w2_is_current, below. */
6317 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
6319 if (! ignore_positions
)
6321 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
6323 if (! EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
))
6326 /* Don't compare the root_window field.
6327 We don't require the two configurations
6328 to use the same window object,
6329 and the two root windows must be equivalent
6330 if everything else compares equal. */
6331 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
6333 if (! EQ (d1
->min_width
, d2
->min_width
))
6335 if (! EQ (d1
->min_height
, d2
->min_height
))
6338 /* Verify that the two confis have the same number of windows. */
6339 if (sw1
->size
!= sw2
->size
)
6342 for (i
= 0; i
< sw1
->size
; i
++)
6344 struct saved_window
*p1
, *p2
;
6345 int w1_is_current
, w2_is_current
;
6347 p1
= SAVED_WINDOW_N (sw1
, i
);
6348 p2
= SAVED_WINDOW_N (sw2
, i
);
6350 /* Verify that the current windows in the two
6351 configurations correspond to each other. */
6352 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
6353 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
6355 if (w1_is_current
!= w2_is_current
)
6358 /* Verify that the corresponding windows do match. */
6359 if (! EQ (p1
->buffer
, p2
->buffer
))
6361 if (! EQ (p1
->left_col
, p2
->left_col
))
6363 if (! EQ (p1
->top_line
, p2
->top_line
))
6365 if (! EQ (p1
->total_cols
, p2
->total_cols
))
6367 if (! EQ (p1
->total_lines
, p2
->total_lines
))
6369 if (! EQ (p1
->display_table
, p2
->display_table
))
6371 if (! EQ (p1
->parent
, p2
->parent
))
6373 if (! EQ (p1
->prev
, p2
->prev
))
6375 if (! ignore_positions
)
6377 if (! EQ (p1
->hscroll
, p2
->hscroll
))
6379 if (!EQ (p1
->min_hscroll
, p2
->min_hscroll
))
6381 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
6383 if (NILP (Fequal (p1
->start
, p2
->start
)))
6385 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
6387 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
6390 if (! EQ (p1
->left_margin_cols
, p2
->left_margin_cols
))
6392 if (! EQ (p1
->right_margin_cols
, p2
->right_margin_cols
))
6394 if (! EQ (p1
->left_fringe_width
, p2
->left_fringe_width
))
6396 if (! EQ (p1
->right_fringe_width
, p2
->right_fringe_width
))
6398 if (! EQ (p1
->fringes_outside_margins
, p2
->fringes_outside_margins
))
6400 if (! EQ (p1
->scroll_bar_width
, p2
->scroll_bar_width
))
6402 if (! EQ (p1
->vertical_scroll_bar_type
, p2
->vertical_scroll_bar_type
))
6409 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
6410 Scompare_window_configurations
, 2, 2, 0,
6411 doc
: /* Compare two window configurations as regards the structure of windows.
6412 This function ignores details such as the values of point and mark
6413 and scrolling positions. */)
6417 if (compare_window_configurations (x
, y
, 1))
6425 struct frame
*f
= make_terminal_frame ();
6426 XSETFRAME (selected_frame
, f
);
6427 Vterminal_frame
= selected_frame
;
6428 minibuf_window
= f
->minibuffer_window
;
6429 selected_window
= f
->selected_window
;
6430 last_nonminibuf_frame
= f
;
6432 window_initialized
= 1;
6438 Vwindow_list
= Qnil
;
6444 Qwindow_size_fixed
= intern ("window-size-fixed");
6445 staticpro (&Qwindow_size_fixed
);
6447 staticpro (&Qwindow_configuration_change_hook
);
6448 Qwindow_configuration_change_hook
6449 = intern ("window-configuration-change-hook");
6451 Qwindowp
= intern ("windowp");
6452 staticpro (&Qwindowp
);
6454 Qwindow_configuration_p
= intern ("window-configuration-p");
6455 staticpro (&Qwindow_configuration_p
);
6457 Qwindow_live_p
= intern ("window-live-p");
6458 staticpro (&Qwindow_live_p
);
6460 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
6461 staticpro (&Qtemp_buffer_show_hook
);
6463 staticpro (&Vwindow_list
);
6465 minibuf_selected_window
= Qnil
;
6466 staticpro (&minibuf_selected_window
);
6468 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
6469 doc
: /* Non-nil means call as function to display a help buffer.
6470 The function is called with one argument, the buffer to be displayed.
6471 Used by `with-output-to-temp-buffer'.
6472 If this function is used, then it must do the entire job of showing
6473 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6474 Vtemp_buffer_show_function
= Qnil
;
6476 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
6477 doc
: /* If non-nil, function to call to handle `display-buffer'.
6478 It will receive two args, the buffer and a flag which if non-nil means
6479 that the currently selected window is not acceptable.
6480 It should choose or create a window, display the specified buffer in it,
6481 and return the window.
6482 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'
6483 work using this function. */);
6484 Vdisplay_buffer_function
= Qnil
;
6486 DEFVAR_LISP ("even-window-heights", &Veven_window_heights
,
6487 doc
: /* *If non-nil, `display-buffer' should even the window heights.
6488 If nil, `display-buffer' will leave the window configuration alone. */);
6489 Veven_window_heights
= Qt
;
6491 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
6492 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6493 Vminibuf_scroll_window
= Qnil
;
6495 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows
,
6496 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6497 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6498 is displayed in the `mode-line' face. */);
6499 mode_line_in_non_selected_windows
= 1;
6501 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
6502 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6503 Vother_window_scroll_buffer
= Qnil
;
6505 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
6506 doc
: /* *Non-nil means `display-buffer' should make a separate frame. */);
6509 DEFVAR_BOOL ("display-buffer-reuse-frames", &display_buffer_reuse_frames
,
6510 doc
: /* *Non-nil means `display-buffer' should reuse frames.
6511 If the buffer in question is already displayed in a frame, raise that frame. */);
6512 display_buffer_reuse_frames
= 0;
6514 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
6515 doc
: /* Function to call to handle automatic new frame creation.
6516 It is called with no arguments and should return a newly created frame.
6518 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'
6519 where `pop-up-frame-alist' would hold the default frame parameters. */);
6520 Vpop_up_frame_function
= Qnil
;
6522 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
6523 doc
: /* *List of buffer names that should have their own special frames.
6524 Displaying a buffer whose name is in this list makes a special frame for it
6525 using `special-display-function'. See also `special-display-regexps'.
6527 An element of the list can be a list instead of just a string.
6528 There are two ways to use a list as an element:
6529 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)
6530 In the first case, the FRAME-PARAMETERS are pairs of the form
6531 \(PARAMETER . VALUE); these parameter values are used to create the frame.
6532 In the second case, FUNCTION is called with BUFFER as the first argument,
6533 followed by the OTHER-ARGS--it can display BUFFER in any way it likes.
6534 All this is done by the function found in `special-display-function'.
6536 If the specified frame parameters include (same-buffer . t), the
6537 buffer is displayed in the currently selected window. Otherwise, if
6538 they include (same-frame . t), the buffer is displayed in a new window
6539 in the currently selected frame.
6541 If this variable appears \"not to work\", because you add a name to it
6542 but that buffer still appears in the selected window, look at the
6543 values of `same-window-buffer-names' and `same-window-regexps'.
6544 Those variables take precedence over this one. */);
6545 Vspecial_display_buffer_names
= Qnil
;
6547 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
6548 doc
: /* *List of regexps saying which buffers should have their own special frames.
6549 If a buffer name matches one of these regexps, it gets its own frame.
6550 Displaying a buffer whose name is in this list makes a special frame for it
6551 using `special-display-function'.
6553 An element of the list can be a list instead of just a string.
6554 There are two ways to use a list as an element:
6555 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)
6556 In the first case, the FRAME-PARAMETERS are pairs of the form
6557 \(PARAMETER . VALUE); these parameter values are used to create the frame.
6558 In the second case, FUNCTION is called with BUFFER as the first argument,
6559 followed by the OTHER-ARGS--it can display the buffer in any way it likes.
6560 All this is done by the function found in `special-display-function'.
6562 If the specified frame parameters include (same-buffer . t), the
6563 buffer is displayed in the currently selected window. Otherwise, if
6564 they include (same-frame . t), the buffer is displayed in a new window
6565 in the currently selected frame.
6567 If this variable appears \"not to work\", because you add a regexp to it
6568 but the matching buffers still appear in the selected window, look at the
6569 values of `same-window-buffer-names' and `same-window-regexps'.
6570 Those variables take precedence over this one. */);
6571 Vspecial_display_regexps
= Qnil
;
6573 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
6574 doc
: /* Function to call to make a new frame for a special buffer.
6575 It is called with two arguments, the buffer and optional buffer specific
6576 data, and should return a window displaying that buffer.
6577 The default value normally makes a separate frame for the buffer,
6578 using `special-display-frame-alist' to specify the frame parameters.
6579 But if the buffer specific data includes (same-buffer . t) then the
6580 buffer is displayed in the current selected window.
6581 Otherwise if it includes (same-frame . t) then the buffer is displayed in
6582 a new window in the currently selected frame.
6584 A buffer is special if it is listed in `special-display-buffer-names'
6585 or matches a regexp in `special-display-regexps'. */);
6586 Vspecial_display_function
= Qnil
;
6588 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
6589 doc
: /* *List of buffer names that should appear in the selected window.
6590 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'
6591 switches to it in the selected window, rather than making it appear
6592 in some other window.
6594 An element of the list can be a cons cell instead of just a string.
6595 Then the car must be a string, which specifies the buffer name.
6596 This is for compatibility with `special-display-buffer-names';
6597 the cdr of the cons cell is ignored.
6599 See also `same-window-regexps'. */);
6600 Vsame_window_buffer_names
= Qnil
;
6602 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
6603 doc
: /* *List of regexps saying which buffers should appear in the selected window.
6604 If a buffer name matches one of these regexps, then displaying it
6605 using `display-buffer' or `pop-to-buffer' switches to it
6606 in the selected window, rather than making it appear in some other window.
6608 An element of the list can be a cons cell instead of just a string.
6609 Then the car must be a string, which specifies the buffer name.
6610 This is for compatibility with `special-display-buffer-names';
6611 the cdr of the cons cell is ignored.
6613 See also `same-window-buffer-names'. */);
6614 Vsame_window_regexps
= Qnil
;
6616 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
6617 doc
: /* *Non-nil means display-buffer should make new windows. */);
6620 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
6621 doc
: /* *Number of lines of continuity when scrolling by screenfuls. */);
6622 next_screen_context_lines
= 2;
6624 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
6625 doc
: /* *A window must be at least this tall to be eligible for splitting by `display-buffer'.
6626 If there is only one window, it is split regardless of this value. */);
6627 split_height_threshold
= 500;
6629 DEFVAR_INT ("window-min-height", &window_min_height
,
6630 doc
: /* *Delete any window less than this tall (including its mode line). */);
6631 window_min_height
= 4;
6633 DEFVAR_INT ("window-min-width", &window_min_width
,
6634 doc
: /* *Delete any window less than this wide. */);
6635 window_min_width
= 10;
6637 DEFVAR_LISP ("scroll-preserve-screen-position",
6638 &Vscroll_preserve_screen_position
,
6639 doc
: /* *Non-nil means scroll commands move point to keep its screen line unchanged. */);
6640 Vscroll_preserve_screen_position
= Qnil
;
6642 DEFVAR_LISP ("window-configuration-change-hook",
6643 &Vwindow_configuration_change_hook
,
6644 doc
: /* Functions to call when window configuration changes.
6645 The selected frame is the one whose configuration has changed. */);
6646 Vwindow_configuration_change_hook
= Qnil
;
6648 DEFVAR_BOOL ("window-size-fixed", &window_size_fixed
,
6649 doc
: /* Non-nil in a buffer means windows displaying the buffer are fixed-size.
6650 Emacs won't change the size of any window displaying that buffer,
6651 unless you explicitly change the size, or Emacs has no other choice.
6652 This variable automatically becomes buffer-local when set. */);
6653 Fmake_variable_buffer_local (Qwindow_size_fixed
);
6654 window_size_fixed
= 0;
6656 defsubr (&Sselected_window
);
6657 defsubr (&Sminibuffer_window
);
6658 defsubr (&Swindow_minibuffer_p
);
6659 defsubr (&Swindowp
);
6660 defsubr (&Swindow_live_p
);
6661 defsubr (&Spos_visible_in_window_p
);
6662 defsubr (&Swindow_buffer
);
6663 defsubr (&Swindow_height
);
6664 defsubr (&Swindow_width
);
6665 defsubr (&Swindow_hscroll
);
6666 defsubr (&Sset_window_hscroll
);
6667 defsubr (&Swindow_redisplay_end_trigger
);
6668 defsubr (&Sset_window_redisplay_end_trigger
);
6669 defsubr (&Swindow_edges
);
6670 defsubr (&Swindow_pixel_edges
);
6671 defsubr (&Swindow_inside_edges
);
6672 defsubr (&Swindow_inside_pixel_edges
);
6673 defsubr (&Scoordinates_in_window_p
);
6674 defsubr (&Swindow_at
);
6675 defsubr (&Swindow_point
);
6676 defsubr (&Swindow_start
);
6677 defsubr (&Swindow_end
);
6678 defsubr (&Sset_window_point
);
6679 defsubr (&Sset_window_start
);
6680 defsubr (&Swindow_dedicated_p
);
6681 defsubr (&Sset_window_dedicated_p
);
6682 defsubr (&Swindow_display_table
);
6683 defsubr (&Sset_window_display_table
);
6684 defsubr (&Snext_window
);
6685 defsubr (&Sprevious_window
);
6686 defsubr (&Sother_window
);
6687 defsubr (&Sget_lru_window
);
6688 defsubr (&Sget_largest_window
);
6689 defsubr (&Sget_buffer_window
);
6690 defsubr (&Sdelete_other_windows
);
6691 defsubr (&Sdelete_windows_on
);
6692 defsubr (&Sreplace_buffer_in_windows
);
6693 defsubr (&Sdelete_window
);
6694 defsubr (&Sset_window_buffer
);
6695 defsubr (&Sselect_window
);
6696 defsubr (&Sspecial_display_p
);
6697 defsubr (&Ssame_window_p
);
6698 defsubr (&Sdisplay_buffer
);
6699 defsubr (&Sforce_window_update
);
6700 defsubr (&Ssplit_window
);
6701 defsubr (&Senlarge_window
);
6702 defsubr (&Sshrink_window
);
6703 defsubr (&Sscroll_up
);
6704 defsubr (&Sscroll_down
);
6705 defsubr (&Sscroll_left
);
6706 defsubr (&Sscroll_right
);
6707 defsubr (&Sother_window_for_scrolling
);
6708 defsubr (&Sscroll_other_window
);
6709 defsubr (&Sminibuffer_selected_window
);
6710 defsubr (&Srecenter
);
6711 defsubr (&Swindow_text_height
);
6712 defsubr (&Smove_to_window_line
);
6713 defsubr (&Swindow_configuration_p
);
6714 defsubr (&Swindow_configuration_frame
);
6715 defsubr (&Sset_window_configuration
);
6716 defsubr (&Scurrent_window_configuration
);
6717 defsubr (&Ssave_window_excursion
);
6718 defsubr (&Sset_window_margins
);
6719 defsubr (&Swindow_margins
);
6720 defsubr (&Sset_window_fringes
);
6721 defsubr (&Swindow_fringes
);
6722 defsubr (&Sset_window_scroll_bars
);
6723 defsubr (&Swindow_scroll_bars
);
6724 defsubr (&Swindow_vscroll
);
6725 defsubr (&Sset_window_vscroll
);
6726 defsubr (&Scompare_window_configurations
);
6727 defsubr (&Swindow_list
);
6733 initial_define_key (control_x_map
, '1', "delete-other-windows");
6734 initial_define_key (control_x_map
, '2', "split-window");
6735 initial_define_key (control_x_map
, '0', "delete-window");
6736 initial_define_key (control_x_map
, 'o', "other-window");
6737 initial_define_key (control_x_map
, '^', "enlarge-window");
6738 initial_define_key (control_x_map
, '<', "scroll-left");
6739 initial_define_key (control_x_map
, '>', "scroll-right");
6741 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
6742 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
6743 initial_define_key (meta_map
, 'v', "scroll-down");
6745 initial_define_key (global_map
, Ctl('L'), "recenter");
6746 initial_define_key (meta_map
, 'r', "move-to-window-line");
6749 /* arch-tag: 90a9c576-0590-48f1-a5f1-6c96a0452d9f
6750 (do not change this comment) */