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 line and page scrolling on tall lines (with images)
128 does partial scrolling by modifying window-vscroll. */
130 int auto_window_vscroll_p
;
132 /* Non-zero means to use mode-line-inactive face in all windows but the
133 selected-window and the minibuffer-scroll-window when the
134 minibuffer is active. */
135 int mode_line_in_non_selected_windows
;
137 /* If a window gets smaller than either of these, it is removed. */
139 EMACS_INT window_min_height
;
140 EMACS_INT window_min_width
;
142 /* Nonzero implies Fdisplay_buffer should create windows. */
146 /* Nonzero implies make new frames for Fdisplay_buffer. */
150 /* Nonzero means reuse existing frames for displaying buffers. */
152 int display_buffer_reuse_frames
;
154 /* Non-nil means use this function instead of default */
156 Lisp_Object Vpop_up_frame_function
;
158 /* Function to call to handle Fdisplay_buffer. */
160 Lisp_Object Vdisplay_buffer_function
;
162 /* Non-nil means that Fdisplay_buffer should even the heights of windows. */
164 Lisp_Object Veven_window_heights
;
166 /* List of buffer *names* for buffers that should have their own frames. */
168 Lisp_Object Vspecial_display_buffer_names
;
170 /* List of regexps for buffer names that should have their own frames. */
172 Lisp_Object Vspecial_display_regexps
;
174 /* Function to pop up a special frame. */
176 Lisp_Object Vspecial_display_function
;
178 /* List of buffer *names* for buffers to appear in selected window. */
180 Lisp_Object Vsame_window_buffer_names
;
182 /* List of regexps for buffer names to appear in selected window. */
184 Lisp_Object Vsame_window_regexps
;
186 /* Hook run at end of temp_output_buffer_show. */
188 Lisp_Object Qtemp_buffer_show_hook
;
190 /* Fdisplay_buffer always splits the largest window
191 if that window is more than this high. */
193 EMACS_INT split_height_threshold
;
195 /* Number of lines of continuity in scrolling by screenfuls. */
197 EMACS_INT next_screen_context_lines
;
199 /* Incremented for each window created. */
201 static int sequence_number
;
203 /* Nonzero after init_window_once has finished. */
205 static int window_initialized
;
207 /* Hook to run when window config changes. */
209 Lisp_Object Qwindow_configuration_change_hook
;
210 Lisp_Object Vwindow_configuration_change_hook
;
212 /* Non-nil means scroll commands try to put point
213 at the same screen height as previously. */
215 Lisp_Object Vscroll_preserve_screen_position
;
217 #if 0 /* This isn't used anywhere. */
218 /* Nonzero means we can split a frame even if it is "unsplittable". */
219 static int inhibit_frame_unsplittable
;
222 extern EMACS_INT scroll_margin
;
224 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
226 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
227 doc
: /* Returns t if OBJECT is a window. */)
231 return WINDOWP (object
) ? Qt
: Qnil
;
234 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
235 doc
: /* Returns t if OBJECT is a window which is currently visible. */)
239 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
246 register struct window
*p
;
248 p
= allocate_window ();
250 XSETFASTINT (p
->sequence_number
, sequence_number
);
251 XSETFASTINT (p
->left_col
, 0);
252 XSETFASTINT (p
->top_line
, 0);
253 XSETFASTINT (p
->total_lines
, 0);
254 XSETFASTINT (p
->total_cols
, 0);
255 XSETFASTINT (p
->hscroll
, 0);
256 XSETFASTINT (p
->min_hscroll
, 0);
257 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
258 p
->start
= Fmake_marker ();
259 p
->pointm
= Fmake_marker ();
260 XSETFASTINT (p
->use_time
, 0);
262 p
->display_table
= Qnil
;
264 p
->pseudo_window_p
= 0;
265 bzero (&p
->cursor
, sizeof (p
->cursor
));
266 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
267 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
268 p
->desired_matrix
= p
->current_matrix
= 0;
269 p
->nrows_scale_factor
= p
->ncols_scale_factor
= 1;
270 p
->phys_cursor_type
= -1;
271 p
->phys_cursor_width
= -1;
272 p
->must_be_updated_p
= 0;
273 XSETFASTINT (p
->window_end_vpos
, 0);
274 XSETFASTINT (p
->window_end_pos
, 0);
275 p
->window_end_valid
= Qnil
;
278 XSETFASTINT (p
->last_point
, 0);
279 p
->frozen_window_start_p
= 0;
280 p
->height_fixed_p
= 0;
281 p
->last_cursor_off_p
= p
->cursor_off_p
= 0;
282 p
->left_margin_cols
= Qnil
;
283 p
->right_margin_cols
= Qnil
;
284 p
->left_fringe_width
= Qnil
;
285 p
->right_fringe_width
= Qnil
;
286 p
->fringes_outside_margins
= Qnil
;
287 p
->scroll_bar_width
= Qnil
;
288 p
->vertical_scroll_bar_type
= Qt
;
289 p
->overlay_arrow_bitmap
= 0;
295 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
296 doc
: /* Return the window that the cursor now appears in and commands apply to. */)
299 return selected_window
;
302 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
303 doc
: /* Return the window used now for minibuffers.
304 If the optional argument FRAME is specified, return the minibuffer window
305 used by that frame. */)
310 frame
= selected_frame
;
311 CHECK_LIVE_FRAME (frame
);
312 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
315 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
316 doc
: /* Returns non-nil if WINDOW is a minibuffer window.
317 WINDOW defaults to the selected window. */)
321 struct window
*w
= decode_window (window
);
322 return MINI_WINDOW_P (w
) ? Qt
: Qnil
;
326 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
327 Spos_visible_in_window_p
, 0, 3, 0,
328 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
329 Return nil if that position is scrolled vertically out of view.
330 If a character is only partially visible, nil is returned, unless the
331 optional argument PARTIALLY is non-nil.
332 If POS is only out of view because of horizontal scrolling, return non-nil.
333 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
335 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
336 return value is a list (X Y FULLY [RTOP RBOT]) where X and Y are the pixel
337 coordinates relative to the top left corner of the window, and FULLY is t if the
338 character after POS is fully visible and nil otherwise. If FULLY is nil,
339 RTOP and RBOT are the number of pixels invisible at the top and bottom row
341 (pos
, window
, partially
)
342 Lisp_Object pos
, window
, partially
;
344 register struct window
*w
;
346 register struct buffer
*buf
;
348 Lisp_Object in_window
= Qnil
;
349 int rtop
, rbot
, fully_p
= 1;
352 w
= decode_window (window
);
353 buf
= XBUFFER (w
->buffer
);
354 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
358 CHECK_NUMBER_COERCE_MARKER (pos
);
361 else if (w
== XWINDOW (selected_window
))
364 posint
= XMARKER (w
->pointm
)->charpos
;
366 /* If position is above window start or outside buffer boundaries,
367 or if window start is out of range, position is not visible. */
368 if (posint
>= CHARPOS (top
)
369 && posint
<= BUF_ZV (buf
)
370 && CHARPOS (top
) >= BUF_BEGV (buf
)
371 && CHARPOS (top
) <= BUF_ZV (buf
)
372 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, NILP (partially
))
373 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
376 if (!NILP (in_window
) && !NILP (partially
))
377 in_window
= Fcons (make_number (x
),
378 Fcons (make_number (y
),
379 Fcons (fully_p
? Qt
: Qnil
,
382 : Fcons (make_number (rtop
),
383 Fcons (make_number (rbot
),
389 static struct window
*
390 decode_window (window
)
391 register Lisp_Object window
;
394 return XWINDOW (selected_window
);
396 CHECK_LIVE_WINDOW (window
);
397 return XWINDOW (window
);
400 static struct window
*
401 decode_any_window (window
)
402 register Lisp_Object window
;
405 return XWINDOW (selected_window
);
407 CHECK_WINDOW (window
);
408 return XWINDOW (window
);
411 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
412 doc
: /* Return the buffer that WINDOW is displaying.
413 WINDOW defaults to the selected window. */)
417 return decode_window (window
)->buffer
;
420 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
421 doc
: /* Return the number of lines in WINDOW (including its mode line). */)
425 return decode_any_window (window
)->total_lines
;
428 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
429 doc
: /* Return the number of display columns in WINDOW.
430 This is the width that is usable columns available for text in WINDOW.
431 If you want to find out how many columns WINDOW takes up,
432 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
436 return make_number (window_box_text_cols (decode_any_window (window
)));
439 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
440 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin. */)
444 return decode_window (window
)->hscroll
;
447 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
448 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
449 Return NCOL. NCOL should be zero or positive.
451 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
452 window so that the location of point becomes invisible. */)
454 Lisp_Object window
, ncol
;
456 struct window
*w
= decode_window (window
);
460 hscroll
= max (0, XINT (ncol
));
462 /* Prevent redisplay shortcuts when changing the hscroll. */
463 if (XINT (w
->hscroll
) != hscroll
)
464 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
466 w
->hscroll
= make_number (hscroll
);
470 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
471 Swindow_redisplay_end_trigger
, 0, 1, 0,
472 doc
: /* Return WINDOW's redisplay end trigger value.
473 See `set-window-redisplay-end-trigger' for more information. */)
477 return decode_window (window
)->redisplay_end_trigger
;
480 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
481 Sset_window_redisplay_end_trigger
, 2, 2, 0,
482 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
483 VALUE should be a buffer position (typically a marker) or nil.
484 If it is a buffer position, then if redisplay in WINDOW reaches a position
485 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
486 with two arguments: WINDOW, and the end trigger value.
487 Afterwards the end-trigger value is reset to nil. */)
489 register Lisp_Object window
, value
;
491 register struct window
*w
;
493 w
= decode_window (window
);
494 w
->redisplay_end_trigger
= value
;
498 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
499 doc
: /* Return a list of the edge coordinates of WINDOW.
500 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
501 RIGHT is one more than the rightmost column occupied by WINDOW,
502 and BOTTOM is one more than the bottommost row occupied by WINDOW.
503 The edges include the space used by the window's scroll bar,
504 display margins, fringes, header line, and mode line, if it has them.
505 To get the edges of the actual text area, use `window-inside-edges'. */)
509 register struct window
*w
= decode_any_window (window
);
511 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w
)),
512 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w
)),
513 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w
)),
514 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w
)),
518 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
519 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
520 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
521 RIGHT is one more than the rightmost x position occupied by WINDOW,
522 and BOTTOM is one more than the bottommost y position occupied by WINDOW.
523 The pixel edges include the space used by the window's scroll bar,
524 display margins, fringes, header line, and mode line, if it has them.
525 To get the edges of the actual text area, use `window-inside-pixel-edges'. */)
529 register struct window
*w
= decode_any_window (window
);
531 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
)),
532 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
)),
533 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
)),
534 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
)),
538 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
539 doc
: /* Return a list of the edge coordinates of WINDOW.
540 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
541 RIGHT is one more than the rightmost column used by text in WINDOW,
542 and BOTTOM is one more than the bottommost row used by text in WINDOW.
543 The inside edges do not include the space used by the window's scroll bar,
544 display margins, fringes, header line, and/or mode line. */)
548 register struct window
*w
= decode_any_window (window
);
550 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w
)
551 + WINDOW_LEFT_MARGIN_COLS (w
)
552 + WINDOW_LEFT_FRINGE_COLS (w
)),
553 make_number (WINDOW_TOP_EDGE_LINE (w
)
554 + WINDOW_HEADER_LINE_LINES (w
)),
555 make_number (WINDOW_RIGHT_EDGE_COL (w
)
556 - WINDOW_RIGHT_MARGIN_COLS (w
)
557 - WINDOW_RIGHT_FRINGE_COLS (w
)),
558 make_number (WINDOW_BOTTOM_EDGE_LINE (w
)
559 - WINDOW_MODE_LINE_LINES (w
)));
562 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
563 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
564 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
565 RIGHT is one more than the rightmost x position used by text in WINDOW,
566 and BOTTOM is one more than the bottommost y position used by text in WINDOW.
567 The inside edges do not include the space used by the window's scroll bar,
568 display margins, fringes, header line, and/or mode line. */)
572 register struct window
*w
= decode_any_window (window
);
574 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
575 + WINDOW_LEFT_MARGIN_WIDTH (w
)
576 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
577 make_number (WINDOW_TOP_EDGE_Y (w
)
578 + WINDOW_HEADER_LINE_HEIGHT (w
)),
579 make_number (WINDOW_RIGHT_EDGE_X (w
)
580 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
581 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
582 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
583 - WINDOW_MODE_LINE_HEIGHT (w
)));
586 /* Test if the character at column *X, row *Y is within window W.
587 If it is not, return ON_NOTHING;
588 if it is in the window's text area,
589 set *x and *y to its location relative to the upper left corner
592 if it is on the window's modeline, return ON_MODE_LINE;
593 if it is on the border between the window and its right sibling,
594 return ON_VERTICAL_BORDER.
595 if it is on a scroll bar,
596 return ON_SCROLL_BAR.
597 if it is on the window's top line, return ON_HEADER_LINE;
598 if it is in left or right fringe of the window,
599 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y
600 to window-relative coordinates;
601 if it is in the marginal area to the left/right of the window,
602 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y
603 to window-relative coordinates.
605 X and Y are frame relative pixel coordinates. */
607 static enum window_part
608 coordinates_in_window (w
, x
, y
)
609 register struct window
*w
;
612 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
613 int left_x
, right_x
, top_y
, bottom_y
;
614 enum window_part part
;
615 int ux
= FRAME_COLUMN_WIDTH (f
);
616 int x0
= WINDOW_LEFT_EDGE_X (w
);
617 int x1
= WINDOW_RIGHT_EDGE_X (w
);
618 /* The width of the area where the vertical line can be dragged.
619 (Between mode lines for instance. */
620 int grabbable_width
= ux
;
621 int lmargin_width
, rmargin_width
, text_left
, text_right
;
623 /* In what's below, we subtract 1 when computing right_x because we
624 want the rightmost pixel, which is given by left_pixel+width-1. */
625 if (w
->pseudo_window_p
)
628 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
629 top_y
= WINDOW_TOP_EDGE_Y (w
);
630 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
634 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
635 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
636 top_y
= WINDOW_TOP_EDGE_Y (w
);
637 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
640 /* Outside any interesting row? */
641 if (*y
< top_y
|| *y
>= bottom_y
)
644 /* On the mode line or header line? If it's near the start of
645 the mode or header line of window that's has a horizontal
646 sibling, say it's on the vertical line. That's to be able
647 to resize windows horizontally in case we're using toolkit
650 if (WINDOW_WANTS_MODELINE_P (w
)
651 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
655 header_vertical_border_check
:
656 /* We're somewhere on the mode line. We consider the place
657 between mode lines of horizontally adjacent mode lines
658 as the vertical border. If scroll bars on the left,
659 return the right window. */
660 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
661 || WINDOW_RIGHTMOST_P (w
))
663 if (!WINDOW_LEFTMOST_P (w
) && abs (*x
- x0
) < grabbable_width
)
664 return ON_VERTICAL_BORDER
;
668 if (abs (*x
- x1
) < grabbable_width
)
669 return ON_VERTICAL_BORDER
;
672 if (*x
< x0
|| *x
>= x1
)
675 /* Convert X and Y to window relative coordinates.
676 Mode line starts at left edge of window. */
682 if (WINDOW_WANTS_HEADER_LINE_P (w
)
683 && *y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
))
685 part
= ON_HEADER_LINE
;
686 goto header_vertical_border_check
;
689 if (*x
< x0
|| *x
>= x1
)
692 /* Outside any interesting column? */
693 if (*x
< left_x
|| *x
> right_x
)
694 return ON_SCROLL_BAR
;
696 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
697 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
699 text_left
= window_box_left (w
, TEXT_AREA
);
700 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
702 if (FRAME_WINDOW_P (f
))
704 if (!w
->pseudo_window_p
705 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
706 && !WINDOW_RIGHTMOST_P (w
)
707 && (abs (*x
- right_x
) < grabbable_width
))
708 return ON_VERTICAL_BORDER
;
712 /* Need to say "*x > right_x" rather than >=, since on character
713 terminals, the vertical line's x coordinate is right_x. */
714 if (!w
->pseudo_window_p
715 && !WINDOW_RIGHTMOST_P (w
)
716 && *x
> right_x
- ux
)
718 /* On the border on the right side of the window? Assume that
719 this area begins at RIGHT_X minus a canonical char width. */
720 return ON_VERTICAL_BORDER
;
726 if (lmargin_width
> 0
727 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
728 ? (*x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
729 : (*x
< left_x
+ lmargin_width
)))
732 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
733 *x
-= WINDOW_LEFT_FRINGE_WIDTH (w
);
735 return ON_LEFT_MARGIN
;
738 /* Convert X and Y to window-relative pixel coordinates. */
741 return ON_LEFT_FRINGE
;
744 if (*x
>= text_right
)
746 if (rmargin_width
> 0
747 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
748 ? (*x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
749 : (*x
>= right_x
- rmargin_width
)))
752 if (!WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
753 *x
-= WINDOW_RIGHT_FRINGE_WIDTH (w
);
755 return ON_RIGHT_MARGIN
;
758 /* Convert X and Y to window-relative pixel coordinates. */
759 *x
-= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
);
761 return ON_RIGHT_FRINGE
;
764 /* Everything special ruled out - must be on text area */
765 *x
-= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
);
771 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
772 Scoordinates_in_window_p
, 2, 2, 0,
773 doc
: /* Return non-nil if COORDINATES are in WINDOW.
774 COORDINATES is a cons of the form (X . Y), X and Y being distances
775 measured in characters from the upper-left corner of the frame.
776 \(0 . 0) denotes the character in the upper left corner of the
778 If COORDINATES are in the text portion of WINDOW,
779 the coordinates relative to the window are returned.
780 If they are in the mode line of WINDOW, `mode-line' is returned.
781 If they are in the top mode line of WINDOW, `header-line' is returned.
782 If they are in the left fringe of WINDOW, `left-fringe' is returned.
783 If they are in the right fringe of WINDOW, `right-fringe' is returned.
784 If they are on the border between WINDOW and its right sibling,
785 `vertical-line' is returned.
786 If they are in the windows's left or right marginal areas, `left-margin'\n\
787 or `right-margin' is returned. */)
788 (coordinates
, window
)
789 register Lisp_Object coordinates
, window
;
796 CHECK_WINDOW (window
);
797 w
= XWINDOW (window
);
798 f
= XFRAME (w
->frame
);
799 CHECK_CONS (coordinates
);
800 lx
= Fcar (coordinates
);
801 ly
= Fcdr (coordinates
);
802 CHECK_NUMBER_OR_FLOAT (lx
);
803 CHECK_NUMBER_OR_FLOAT (ly
);
804 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
805 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
807 switch (coordinates_in_window (w
, &x
, &y
))
813 /* X and Y are now window relative pixel coordinates. Convert
814 them to canonical char units before returning them. */
815 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
816 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
821 case ON_VERTICAL_BORDER
:
822 return Qvertical_line
;
830 case ON_RIGHT_FRINGE
:
831 return Qright_fringe
;
836 case ON_RIGHT_MARGIN
:
837 return Qright_margin
;
840 /* Historically we are supposed to return nil in this case. */
849 /* Callback for foreach_window, used in window_from_coordinates.
850 Check if window W contains coordinates specified by USER_DATA which
851 is actually a pointer to a struct check_window_data CW.
853 Check if window W contains coordinates *CW->x and *CW->y. If it
854 does, return W in *CW->window, as Lisp_Object, and return in
855 *CW->part the part of the window under coordinates *X,*Y. Return
856 zero from this function to stop iterating over windows. */
858 struct check_window_data
862 enum window_part
*part
;
866 check_window_containing (w
, user_data
)
870 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
871 enum window_part found
;
874 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
875 if (found
!= ON_NOTHING
)
878 XSETWINDOW (*cw
->window
, w
);
886 /* Find the window containing frame-relative pixel position X/Y and
887 return it as a Lisp_Object.
889 If X, Y is on one of the window's special `window_part' elements,
890 set *PART to the id of that element, and return X and Y converted
891 to window relative coordinates in WX and WY.
893 If there is no window under X, Y return nil and leave *PART
894 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
896 This function was previously implemented with a loop cycling over
897 windows with Fnext_window, and starting with the frame's selected
898 window. It turned out that this doesn't work with an
899 implementation of next_window using Vwindow_list, because
900 FRAME_SELECTED_WINDOW (F) is not always contained in the window
901 tree of F when this function is called asynchronously from
902 note_mouse_highlight. The original loop didn't terminate in this
906 window_from_coordinates (f
, x
, y
, part
, wx
, wy
, tool_bar_p
)
909 enum window_part
*part
;
914 struct check_window_data cw
;
915 enum window_part dummy
;
921 cw
.window
= &window
, cw
.x
= &x
, cw
.y
= &y
; cw
.part
= part
;
922 foreach_window (f
, check_window_containing
, &cw
);
924 /* If not found above, see if it's in the tool bar window, if a tool
928 && WINDOWP (f
->tool_bar_window
)
929 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
930 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), &x
, &y
)
934 window
= f
->tool_bar_window
;
943 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
944 doc
: /* Return window containing coordinates X and Y on FRAME.
945 If omitted, FRAME defaults to the currently selected frame.
946 The top left corner of the frame is considered to be row 0,
949 Lisp_Object x
, y
, frame
;
954 frame
= selected_frame
;
955 CHECK_LIVE_FRAME (frame
);
958 /* Check that arguments are integers or floats. */
959 CHECK_NUMBER_OR_FLOAT (x
);
960 CHECK_NUMBER_OR_FLOAT (y
);
962 return window_from_coordinates (f
,
963 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
964 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
965 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
966 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
970 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
971 doc
: /* Return current value of point in WINDOW.
972 For a nonselected window, this is the value point would have
973 if that window were selected.
975 Note that, when WINDOW is the selected window and its buffer
976 is also currently selected, the value returned is the same as (point).
977 It would be more strictly correct to return the `top-level' value
978 of point, outside of any save-excursion forms.
979 But that is hard to define. */)
983 register struct window
*w
= decode_window (window
);
985 if (w
== XWINDOW (selected_window
)
986 && current_buffer
== XBUFFER (w
->buffer
))
988 return Fmarker_position (w
->pointm
);
991 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
992 doc
: /* Return position at which display currently starts in WINDOW.
993 This is updated by redisplay or by calling `set-window-start'. */)
997 return Fmarker_position (decode_window (window
)->start
);
1000 /* This is text temporarily removed from the doc string below.
1002 This function returns nil if the position is not currently known.
1003 That happens when redisplay is preempted and doesn't finish.
1004 If in that case you want to compute where the end of the window would
1005 have been if redisplay had finished, do this:
1007 (goto-char (window-start window))
1008 (vertical-motion (1- (window-height window)) window)
1011 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1012 doc
: /* Return position at which display currently ends in WINDOW.
1013 This is updated by redisplay, when it runs to completion.
1014 Simply changing the buffer text or setting `window-start'
1015 does not update this value.
1016 Return nil if there is no recorded value. \(This can happen if the
1017 last redisplay of WINDOW was preempted, and did not finish.)
1018 If UPDATE is non-nil, compute the up-to-date position
1019 if it isn't already recorded. */)
1021 Lisp_Object window
, update
;
1024 struct window
*w
= decode_window (window
);
1030 #if 0 /* This change broke some things. We should make it later. */
1031 /* If we don't know the end position, return nil.
1032 The user can compute it with vertical-motion if he wants to.
1033 It would be nicer to do it automatically,
1034 but that's so slow that it would probably bother people. */
1035 if (NILP (w
->window_end_valid
))
1040 && ! (! NILP (w
->window_end_valid
)
1041 && XFASTINT (w
->last_modified
) >= MODIFF
))
1043 struct text_pos startp
;
1045 struct buffer
*old_buffer
= NULL
, *b
= XBUFFER (buf
);
1047 /* In case W->start is out of the range, use something
1048 reasonable. This situation occurred when loading a file with
1049 `-l' containing a call to `rmail' with subsequent other
1050 commands. At the end, W->start happened to be BEG, while
1051 rmail had already narrowed the buffer. */
1052 if (XMARKER (w
->start
)->charpos
< BEGV
)
1053 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1054 else if (XMARKER (w
->start
)->charpos
> ZV
)
1055 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1057 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1059 /* Cannot use Fvertical_motion because that function doesn't
1060 cope with variable-height lines. */
1061 if (b
!= current_buffer
)
1063 old_buffer
= current_buffer
;
1064 set_buffer_internal (b
);
1067 start_display (&it
, w
, startp
);
1068 move_it_vertically (&it
, window_box_height (w
));
1069 if (it
.current_y
< it
.last_visible_y
)
1070 move_it_past_eol (&it
);
1071 value
= make_number (IT_CHARPOS (it
));
1074 set_buffer_internal (old_buffer
);
1077 XSETINT (value
, BUF_Z (XBUFFER (buf
)) - XFASTINT (w
->window_end_pos
));
1082 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1083 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1086 Lisp_Object window
, pos
;
1088 register struct window
*w
= decode_window (window
);
1090 CHECK_NUMBER_COERCE_MARKER (pos
);
1091 if (w
== XWINDOW (selected_window
)
1092 && XBUFFER (w
->buffer
) == current_buffer
)
1095 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1097 /* We have to make sure that redisplay updates the window to show
1098 the new value of point. */
1099 if (!EQ (window
, selected_window
))
1100 ++windows_or_buffers_changed
;
1105 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1106 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1108 Optional third arg NOFORCE non-nil inhibits next redisplay
1109 from overriding motion of point in order to display at this exact start. */)
1110 (window
, pos
, noforce
)
1111 Lisp_Object window
, pos
, noforce
;
1113 register struct window
*w
= decode_window (window
);
1115 CHECK_NUMBER_COERCE_MARKER (pos
);
1116 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1117 /* this is not right, but much easier than doing what is right. */
1118 w
->start_at_line_beg
= Qnil
;
1120 w
->force_start
= Qt
;
1121 w
->update_mode_line
= Qt
;
1122 XSETFASTINT (w
->last_modified
, 0);
1123 XSETFASTINT (w
->last_overlay_modified
, 0);
1124 if (!EQ (window
, selected_window
))
1125 windows_or_buffers_changed
++;
1130 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1132 doc
: /* Return WINDOW's dedicated object, usually t or nil.
1133 See also `set-window-dedicated-p'. */)
1137 return decode_window (window
)->dedicated
;
1140 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1141 Sset_window_dedicated_p
, 2, 2, 0,
1142 doc
: /* Control whether WINDOW is dedicated to the buffer it displays.
1143 If it is dedicated, Emacs will not automatically change
1144 which buffer appears in it.
1145 The second argument is the new value for the dedication flag;
1146 non-nil means yes. */)
1148 Lisp_Object window
, arg
;
1150 register struct window
*w
= decode_window (window
);
1154 return w
->dedicated
;
1157 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1159 doc
: /* Return the display-table that WINDOW is using. */)
1163 return decode_window (window
)->display_table
;
1166 /* Get the display table for use on window W. This is either W's
1167 display table or W's buffer's display table. Ignore the specified
1168 tables if they are not valid; if no valid table is specified,
1171 struct Lisp_Char_Table
*
1172 window_display_table (w
)
1175 struct Lisp_Char_Table
*dp
= NULL
;
1177 if (DISP_TABLE_P (w
->display_table
))
1178 dp
= XCHAR_TABLE (w
->display_table
);
1179 else if (BUFFERP (w
->buffer
))
1181 struct buffer
*b
= XBUFFER (w
->buffer
);
1183 if (DISP_TABLE_P (b
->display_table
))
1184 dp
= XCHAR_TABLE (b
->display_table
);
1185 else if (DISP_TABLE_P (Vstandard_display_table
))
1186 dp
= XCHAR_TABLE (Vstandard_display_table
);
1192 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1193 doc
: /* Set WINDOW's display-table to TABLE. */)
1195 register Lisp_Object window
, table
;
1197 register struct window
*w
;
1199 w
= decode_window (window
);
1200 w
->display_table
= table
;
1204 /* Record info on buffer window w is displaying
1205 when it is about to cease to display that buffer. */
1208 register struct window
*w
;
1215 if (b
!= XMARKER (w
->pointm
)->buffer
)
1219 if (w
== XWINDOW (selected_window
)
1220 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1221 /* Do this except when the selected window's buffer
1222 is being removed from some other window. */
1224 /* last_window_start records the start position that this buffer
1225 had in the last window to be disconnected from it.
1226 Now that this statement is unconditional,
1227 it is possible for the buffer to be displayed in the
1228 selected window, while last_window_start reflects another
1229 window which was recently showing the same buffer.
1230 Some people might say that might be a good thing. Let's see. */
1231 b
->last_window_start
= marker_position (w
->start
);
1233 /* Point in the selected window's buffer
1234 is actually stored in that buffer, and the window's pointm isn't used.
1235 So don't clobber point in that buffer. */
1236 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1237 /* This line helps to fix Horsley's testbug.el bug. */
1238 && !(WINDOWP (b
->last_selected_window
)
1239 && w
!= XWINDOW (b
->last_selected_window
)
1240 && EQ (buf
, XWINDOW (b
->last_selected_window
)->buffer
)))
1241 temp_set_point_both (b
,
1242 clip_to_bounds (BUF_BEGV (b
),
1243 XMARKER (w
->pointm
)->charpos
,
1245 clip_to_bounds (BUF_BEGV_BYTE (b
),
1246 marker_byte_position (w
->pointm
),
1249 if (WINDOWP (b
->last_selected_window
)
1250 && w
== XWINDOW (b
->last_selected_window
))
1251 b
->last_selected_window
= Qnil
;
1254 /* Put replacement into the window structure in place of old. */
1256 replace_window (old
, replacement
)
1257 Lisp_Object old
, replacement
;
1259 register Lisp_Object tem
;
1260 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
1262 /* If OLD is its frame's root_window, then replacement is the new
1263 root_window for that frame. */
1265 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1266 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
1268 p
->left_col
= o
->left_col
;
1269 p
->top_line
= o
->top_line
;
1270 p
->total_cols
= o
->total_cols
;
1271 p
->total_lines
= o
->total_lines
;
1272 p
->desired_matrix
= p
->current_matrix
= 0;
1274 bzero (&p
->cursor
, sizeof (p
->cursor
));
1275 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
1276 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
1277 p
->phys_cursor_type
= -1;
1278 p
->phys_cursor_width
= -1;
1279 p
->must_be_updated_p
= 0;
1280 p
->pseudo_window_p
= 0;
1281 XSETFASTINT (p
->window_end_vpos
, 0);
1282 XSETFASTINT (p
->window_end_pos
, 0);
1283 p
->window_end_valid
= Qnil
;
1284 p
->frozen_window_start_p
= 0;
1285 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
1287 p
->next
= tem
= o
->next
;
1289 XWINDOW (tem
)->prev
= replacement
;
1291 p
->prev
= tem
= o
->prev
;
1293 XWINDOW (tem
)->next
= replacement
;
1295 p
->parent
= tem
= o
->parent
;
1298 if (EQ (XWINDOW (tem
)->vchild
, old
))
1299 XWINDOW (tem
)->vchild
= replacement
;
1300 if (EQ (XWINDOW (tem
)->hchild
, old
))
1301 XWINDOW (tem
)->hchild
= replacement
;
1304 /*** Here, if replacement is a vertical combination
1305 and so is its new parent, we should make replacement's
1306 children be children of that parent instead. ***/
1309 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
1310 doc
: /* Remove WINDOW from the display. Default is selected window. */)
1312 register Lisp_Object window
;
1314 delete_window (window
);
1316 if (! NILP (Vwindow_configuration_change_hook
)
1317 && ! NILP (Vrun_hooks
))
1318 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
1324 delete_window (window
)
1325 register Lisp_Object window
;
1327 register Lisp_Object tem
, parent
, sib
;
1328 register struct window
*p
;
1329 register struct window
*par
;
1332 /* Because this function is called by other C code on non-leaf
1333 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1334 so we can't decode_window here. */
1336 window
= selected_window
;
1338 CHECK_WINDOW (window
);
1339 p
= XWINDOW (window
);
1341 /* It's okay to delete an already-deleted window. */
1342 if (NILP (p
->buffer
)
1344 && NILP (p
->vchild
))
1349 error ("Attempt to delete minibuffer or sole ordinary window");
1350 par
= XWINDOW (parent
);
1352 windows_or_buffers_changed
++;
1353 Vwindow_list
= Qnil
;
1354 f
= XFRAME (WINDOW_FRAME (p
));
1355 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
1357 /* Are we trying to delete any frame's selected window? */
1359 Lisp_Object swindow
, pwindow
;
1361 /* See if the frame's selected window is either WINDOW
1362 or any subwindow of it, by finding all that window's parents
1363 and comparing each one with WINDOW. */
1364 swindow
= FRAME_SELECTED_WINDOW (f
);
1369 while (!NILP (pwindow
))
1371 if (EQ (window
, pwindow
))
1373 pwindow
= XWINDOW (pwindow
)->parent
;
1376 /* If the window being deleted is not a parent of SWINDOW,
1377 then SWINDOW is ok as the new selected window. */
1378 if (!EQ (window
, pwindow
))
1380 /* Otherwise, try another window for SWINDOW. */
1381 swindow
= Fnext_window (swindow
, Qlambda
, Qnil
);;
1383 /* If we get back to the frame's selected window,
1384 it means there was no acceptable alternative,
1385 so we cannot delete. */
1386 if (EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1387 error ("Cannot delete window");
1390 /* If we need to change SWINDOW, do it. */
1391 if (! EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1393 /* If we're about to delete the selected window on the
1394 selected frame, then we should use Fselect_window to select
1395 the new window. On the other hand, if we're about to
1396 delete the selected window on any other frame, we shouldn't do
1397 anything but set the frame's selected_window slot. */
1398 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
1399 Fselect_window (swindow
, Qnil
);
1401 FRAME_SELECTED_WINDOW (f
) = swindow
;
1406 /* tem is null for dummy parent windows
1407 (which have inferiors but not any contents themselves) */
1411 unchain_marker (XMARKER (p
->pointm
));
1412 unchain_marker (XMARKER (p
->start
));
1415 /* Free window glyph matrices. It is sure that they are allocated
1416 again when ADJUST_GLYPHS is called. Block input so that expose
1417 events and other events that access glyph matrices are not
1418 processed while we are changing them. */
1420 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)));
1424 XWINDOW (tem
)->prev
= p
->prev
;
1428 XWINDOW (tem
)->next
= p
->next
;
1430 if (EQ (window
, par
->hchild
))
1431 par
->hchild
= p
->next
;
1432 if (EQ (window
, par
->vchild
))
1433 par
->vchild
= p
->next
;
1435 /* Find one of our siblings to give our space to. */
1439 /* If p gives its space to its next sibling, that sibling needs
1440 to have its top/left side pulled back to where p's is.
1441 set_window_{height,width} will re-position the sibling's
1444 XWINDOW (sib
)->top_line
= p
->top_line
;
1445 XWINDOW (sib
)->left_col
= p
->left_col
;
1448 /* Stretch that sibling. */
1449 if (!NILP (par
->vchild
))
1450 set_window_height (sib
,
1451 XFASTINT (XWINDOW (sib
)->total_lines
) + XFASTINT (p
->total_lines
),
1453 if (!NILP (par
->hchild
))
1454 set_window_width (sib
,
1455 XFASTINT (XWINDOW (sib
)->total_cols
) + XFASTINT (p
->total_cols
),
1458 /* If parent now has only one child,
1459 put the child into the parent's place. */
1463 if (NILP (XWINDOW (tem
)->next
))
1464 replace_window (parent
, tem
);
1466 /* Since we may be deleting combination windows, we must make sure that
1467 not only p but all its children have been marked as deleted. */
1468 if (! NILP (p
->hchild
))
1469 delete_all_subwindows (XWINDOW (p
->hchild
));
1470 else if (! NILP (p
->vchild
))
1471 delete_all_subwindows (XWINDOW (p
->vchild
));
1473 /* Mark this window as deleted. */
1474 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1476 /* Adjust glyph matrices. */
1483 /***********************************************************************
1485 ***********************************************************************/
1487 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1488 pointer. This is a callback function for foreach_window, used in
1489 function window_list. */
1492 add_window_to_list (w
, user_data
)
1496 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1498 XSETWINDOW (window
, w
);
1499 *list
= Fcons (window
, *list
);
1504 /* Return a list of all windows, for use by next_window. If
1505 Vwindow_list is a list, return that list. Otherwise, build a new
1506 list, cache it in Vwindow_list, and return that. */
1511 if (!CONSP (Vwindow_list
))
1515 Vwindow_list
= Qnil
;
1516 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1518 Lisp_Object args
[2];
1520 /* We are visiting windows in canonical order, and add
1521 new windows at the front of args[1], which means we
1522 have to reverse this list at the end. */
1524 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1525 args
[0] = Vwindow_list
;
1526 args
[1] = Fnreverse (args
[1]);
1527 Vwindow_list
= Fnconc (2, args
);
1531 return Vwindow_list
;
1535 /* Value is non-zero if WINDOW satisfies the constraints given by
1536 OWINDOW, MINIBUF and ALL_FRAMES.
1538 MINIBUF t means WINDOW may be minibuffer windows.
1539 `lambda' means WINDOW may not be a minibuffer window.
1540 a window means a specific minibuffer window
1542 ALL_FRAMES t means search all frames,
1543 nil means search just current frame,
1544 `visible' means search just visible frames,
1545 0 means search visible and iconified frames,
1546 a window means search the frame that window belongs to,
1547 a frame means consider windows on that frame, only. */
1550 candidate_window_p (window
, owindow
, minibuf
, all_frames
)
1551 Lisp_Object window
, owindow
, minibuf
, all_frames
;
1553 struct window
*w
= XWINDOW (window
);
1554 struct frame
*f
= XFRAME (w
->frame
);
1555 int candidate_p
= 1;
1557 if (!BUFFERP (w
->buffer
))
1559 else if (MINI_WINDOW_P (w
)
1560 && (EQ (minibuf
, Qlambda
)
1561 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
1563 /* If MINIBUF is `lambda' don't consider any mini-windows.
1564 If it is a window, consider only that one. */
1567 else if (EQ (all_frames
, Qt
))
1569 else if (NILP (all_frames
))
1571 xassert (WINDOWP (owindow
));
1572 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
1574 else if (EQ (all_frames
, Qvisible
))
1576 FRAME_SAMPLE_VISIBILITY (f
);
1577 candidate_p
= FRAME_VISIBLE_P (f
);
1579 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
1581 FRAME_SAMPLE_VISIBILITY (f
);
1582 candidate_p
= FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
);
1584 else if (WINDOWP (all_frames
))
1585 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
1586 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
1587 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
1588 else if (FRAMEP (all_frames
))
1589 candidate_p
= EQ (all_frames
, w
->frame
);
1595 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1596 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1600 decode_next_window_args (window
, minibuf
, all_frames
)
1601 Lisp_Object
*window
, *minibuf
, *all_frames
;
1604 *window
= selected_window
;
1606 CHECK_LIVE_WINDOW (*window
);
1608 /* MINIBUF nil may or may not include minibuffers. Decide if it
1610 if (NILP (*minibuf
))
1611 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
1612 else if (!EQ (*minibuf
, Qt
))
1615 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1616 => count none of them, or a specific minibuffer window (the
1617 active one) to count. */
1619 /* ALL_FRAMES nil doesn't specify which frames to include. */
1620 if (NILP (*all_frames
))
1621 *all_frames
= (!EQ (*minibuf
, Qlambda
)
1622 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
1624 else if (EQ (*all_frames
, Qvisible
))
1626 else if (EQ (*all_frames
, make_number (0)))
1628 else if (FRAMEP (*all_frames
))
1630 else if (!EQ (*all_frames
, Qt
))
1633 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1634 search just current frame, `visible' meaning search just visible
1635 frames, 0 meaning search visible and iconified frames, or a
1636 window, meaning search the frame that window belongs to, or a
1637 frame, meaning consider windows on that frame, only. */
1641 /* Return the next or previous window of WINDOW in canonical ordering
1642 of windows. NEXT_P non-zero means return the next window. See the
1643 documentation string of next-window for the meaning of MINIBUF and
1647 next_window (window
, minibuf
, all_frames
, next_p
)
1648 Lisp_Object window
, minibuf
, all_frames
;
1651 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1653 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1654 return the first window on the frame. */
1655 if (FRAMEP (all_frames
)
1656 && !EQ (all_frames
, XWINDOW (window
)->frame
))
1657 return Fframe_first_window (all_frames
);
1663 /* Find WINDOW in the list of all windows. */
1664 list
= Fmemq (window
, window_list ());
1666 /* Scan forward from WINDOW to the end of the window list. */
1668 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
1669 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1672 /* Scan from the start of the window list up to WINDOW. */
1674 for (list
= Vwindow_list
;
1675 CONSP (list
) && !EQ (XCAR (list
), window
);
1677 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1681 window
= XCAR (list
);
1685 Lisp_Object candidate
, list
;
1687 /* Scan through the list of windows for candidates. If there are
1688 candidate windows in front of WINDOW, the last one of these
1689 is the one we want. If there are candidates following WINDOW
1690 in the list, again the last one of these is the one we want. */
1692 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
1694 if (EQ (XCAR (list
), window
))
1696 if (WINDOWP (candidate
))
1699 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
1701 candidate
= XCAR (list
);
1704 if (WINDOWP (candidate
))
1712 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
1713 doc
: /* Return next window after WINDOW in canonical ordering of windows.
1714 If omitted, WINDOW defaults to the selected window.
1716 Optional second arg MINIBUF t means count the minibuffer window even
1717 if not active. MINIBUF nil or omitted means count the minibuffer iff
1718 it is active. MINIBUF neither t nor nil means not to count the
1719 minibuffer even if it is active.
1721 Several frames may share a single minibuffer; if the minibuffer
1722 counts, all windows on all frames that share that minibuffer count
1723 too. Therefore, `next-window' can be used to iterate through the
1724 set of windows even when the minibuffer is on another frame. If the
1725 minibuffer does not count, only windows from WINDOW's frame count.
1727 Optional third arg ALL-FRAMES t means include windows on all frames.
1728 ALL-FRAMES nil or omitted means cycle within the frames as specified
1729 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1730 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1731 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1732 Anything else means restrict to WINDOW's frame.
1734 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1735 `next-window' to iterate through the entire cycle of acceptable
1736 windows, eventually ending up back at the window you started with.
1737 `previous-window' traverses the same cycle, in the reverse order. */)
1738 (window
, minibuf
, all_frames
)
1739 Lisp_Object window
, minibuf
, all_frames
;
1741 return next_window (window
, minibuf
, all_frames
, 1);
1745 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1746 doc
: /* Return the window preceding WINDOW in canonical ordering of windows.
1747 If omitted, WINDOW defaults to the selected window.
1749 Optional second arg MINIBUF t means count the minibuffer window even
1750 if not active. MINIBUF nil or omitted means count the minibuffer iff
1751 it is active. MINIBUF neither t nor nil means not to count the
1752 minibuffer even if it is active.
1754 Several frames may share a single minibuffer; if the minibuffer
1755 counts, all windows on all frames that share that minibuffer count
1756 too. Therefore, `previous-window' can be used to iterate through
1757 the set of windows even when the minibuffer is on another frame. If
1758 the minibuffer does not count, only windows from WINDOW's frame count
1760 Optional third arg ALL-FRAMES t means include windows on all frames.
1761 ALL-FRAMES nil or omitted means cycle within the frames as specified
1762 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1763 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1764 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1765 Anything else means restrict to WINDOW's frame.
1767 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1768 `previous-window' to iterate through the entire cycle of acceptable
1769 windows, eventually ending up back at the window you started with.
1770 `next-window' traverses the same cycle, in the reverse order. */)
1771 (window
, minibuf
, all_frames
)
1772 Lisp_Object window
, minibuf
, all_frames
;
1774 return next_window (window
, minibuf
, all_frames
, 0);
1778 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1779 doc
: /* Select the ARG'th different window on this frame.
1780 All windows on current frame are arranged in a cyclic order.
1781 This command selects the window ARG steps away in that order.
1782 A negative ARG moves in the opposite order. The optional second
1783 argument ALL_FRAMES has the same meaning as in `next-window', which see. */)
1785 Lisp_Object arg
, all_frames
;
1791 window
= selected_window
;
1793 for (i
= XINT (arg
); i
> 0; --i
)
1794 window
= Fnext_window (window
, Qnil
, all_frames
);
1796 window
= Fprevious_window (window
, Qnil
, all_frames
);
1798 Fselect_window (window
, Qnil
);
1803 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
1804 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
1805 FRAME nil or omitted means use the selected frame.
1806 WINDOW nil or omitted means use the selected window.
1807 MINIBUF t means include the minibuffer window, even if it isn't active.
1808 MINIBUF nil or omitted means include the minibuffer window only
1810 MINIBUF neither nil nor t means never include the minibuffer window. */)
1811 (frame
, minibuf
, window
)
1812 Lisp_Object frame
, minibuf
, window
;
1815 window
= selected_window
;
1817 frame
= selected_frame
;
1819 if (!EQ (frame
, XWINDOW (window
)->frame
))
1820 error ("Window is on a different frame");
1822 return window_list_1 (window
, minibuf
, frame
);
1826 /* Return a list of windows in canonical ordering. Arguments are like
1827 for `next-window'. */
1830 window_list_1 (window
, minibuf
, all_frames
)
1831 Lisp_Object window
, minibuf
, all_frames
;
1833 Lisp_Object tail
, list
, rest
;
1835 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1838 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
1839 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
1840 list
= Fcons (XCAR (tail
), list
);
1842 /* Rotate the list to start with WINDOW. */
1843 list
= Fnreverse (list
);
1844 rest
= Fmemq (window
, list
);
1845 if (!NILP (rest
) && !EQ (rest
, list
))
1847 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
1849 XSETCDR (tail
, Qnil
);
1850 list
= nconc2 (rest
, list
);
1857 /* Look at all windows, performing an operation specified by TYPE
1859 If FRAMES is Qt, look at all frames;
1860 Qnil, look at just the selected frame;
1861 Qvisible, look at visible frames;
1862 a frame, just look at windows on that frame.
1863 If MINI is non-zero, perform the operation on minibuffer windows too. */
1868 GET_BUFFER_WINDOW
, /* Arg is buffer */
1869 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1870 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1871 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1873 UNSHOW_BUFFER
, /* Arg is buffer */
1874 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
1879 window_loop (type
, obj
, mini
, frames
)
1880 enum window_loop type
;
1881 Lisp_Object obj
, frames
;
1884 Lisp_Object window
, windows
, best_window
, frame_arg
;
1886 struct gcpro gcpro1
;
1888 /* If we're only looping through windows on a particular frame,
1889 frame points to that frame. If we're looping through windows
1890 on all frames, frame is 0. */
1891 if (FRAMEP (frames
))
1892 f
= XFRAME (frames
);
1893 else if (NILP (frames
))
1894 f
= SELECTED_FRAME ();
1899 frame_arg
= Qlambda
;
1900 else if (EQ (frames
, make_number (0)))
1902 else if (EQ (frames
, Qvisible
))
1907 /* frame_arg is Qlambda to stick to one frame,
1908 Qvisible to consider all visible frames,
1911 /* Pick a window to start with. */
1915 window
= FRAME_SELECTED_WINDOW (f
);
1917 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
1919 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
1923 for (; CONSP (windows
); windows
= CDR (windows
))
1927 window
= XCAR (windows
);
1928 w
= XWINDOW (window
);
1930 /* Note that we do not pay attention here to whether the frame
1931 is visible, since Fwindow_list skips non-visible frames if
1932 that is desired, under the control of frame_arg. */
1933 if (!MINI_WINDOW_P (w
)
1934 /* For UNSHOW_BUFFER, we must always consider all windows. */
1935 || type
== UNSHOW_BUFFER
1936 || (mini
&& minibuf_level
> 0))
1939 case GET_BUFFER_WINDOW
:
1940 if (EQ (w
->buffer
, obj
)
1941 /* Don't find any minibuffer window
1942 except the one that is currently in use. */
1943 && (MINI_WINDOW_P (w
)
1944 ? EQ (window
, minibuf_window
)
1947 if (NILP (best_window
))
1948 best_window
= window
;
1949 else if (EQ (window
, selected_window
))
1950 /* For compatibility with 20.x, prefer to return
1952 best_window
= window
;
1956 case GET_LRU_WINDOW
:
1957 /* t as arg means consider only full-width windows */
1958 if (!NILP (obj
) && !WINDOW_FULL_WIDTH_P (w
))
1960 /* Ignore dedicated windows and minibuffers. */
1961 if (MINI_WINDOW_P (w
) || EQ (w
->dedicated
, Qt
))
1963 if (NILP (best_window
)
1964 || (XFASTINT (XWINDOW (best_window
)->use_time
)
1965 > XFASTINT (w
->use_time
)))
1966 best_window
= window
;
1969 case DELETE_OTHER_WINDOWS
:
1970 if (!EQ (window
, obj
))
1971 Fdelete_window (window
);
1974 case DELETE_BUFFER_WINDOWS
:
1975 if (EQ (w
->buffer
, obj
))
1977 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1979 /* If this window is dedicated, and in a frame of its own,
1981 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
1982 && !NILP (w
->dedicated
)
1983 && other_visible_frames (f
))
1985 /* Skip the other windows on this frame.
1986 There might be one, the minibuffer! */
1987 while (CONSP (XCDR (windows
))
1988 && EQ (XWINDOW (XCAR (windows
))->frame
,
1989 XWINDOW (XCAR (XCDR (windows
)))->frame
))
1990 windows
= XCDR (windows
);
1992 /* Now we can safely delete the frame. */
1993 Fdelete_frame (w
->frame
, Qnil
);
1995 else if (NILP (w
->parent
))
1997 /* If we're deleting the buffer displayed in the
1998 only window on the frame, find a new buffer to
2001 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2002 Fset_window_buffer (window
, buffer
, Qnil
);
2003 if (EQ (window
, selected_window
))
2004 Fset_buffer (w
->buffer
);
2007 Fdelete_window (window
);
2011 case GET_LARGEST_WINDOW
:
2013 /* Ignore dedicated windows and minibuffers. */
2014 if (MINI_WINDOW_P (w
) || EQ (w
->dedicated
, Qt
))
2017 if (NILP (best_window
))
2018 best_window
= window
;
2021 struct window
*b
= XWINDOW (best_window
);
2022 if (XFASTINT (w
->total_lines
) * XFASTINT (w
->total_cols
)
2023 > XFASTINT (b
->total_lines
) * XFASTINT (b
->total_cols
))
2024 best_window
= window
;
2030 if (EQ (w
->buffer
, obj
))
2033 struct frame
*f
= XFRAME (w
->frame
);
2035 /* Find another buffer to show in this window. */
2036 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2038 /* If this window is dedicated, and in a frame of its own,
2040 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
2041 && !NILP (w
->dedicated
)
2042 && other_visible_frames (f
))
2044 /* Skip the other windows on this frame.
2045 There might be one, the minibuffer! */
2046 while (CONSP (XCDR (windows
))
2047 && EQ (XWINDOW (XCAR (windows
))->frame
,
2048 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2049 windows
= XCDR (windows
);
2051 /* Now we can safely delete the frame. */
2052 Fdelete_frame (w
->frame
, Qnil
);
2054 else if (!NILP (w
->dedicated
) && !NILP (w
->parent
))
2057 XSETWINDOW (window
, w
);
2058 /* If this window is dedicated and not the only window
2059 in its frame, then kill it. */
2060 Fdelete_window (window
);
2064 /* Otherwise show a different buffer in the window. */
2065 w
->dedicated
= Qnil
;
2066 Fset_window_buffer (window
, buffer
, Qnil
);
2067 if (EQ (window
, selected_window
))
2068 Fset_buffer (w
->buffer
);
2073 case REDISPLAY_BUFFER_WINDOWS
:
2074 if (EQ (w
->buffer
, obj
))
2076 mark_window_display_accurate (window
, 0);
2077 w
->update_mode_line
= Qt
;
2078 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2079 ++update_mode_lines
;
2080 best_window
= window
;
2084 /* Check for a window that has a killed buffer. */
2085 case CHECK_ALL_WINDOWS
:
2086 if (! NILP (w
->buffer
)
2087 && NILP (XBUFFER (w
->buffer
)->name
))
2091 case WINDOW_LOOP_UNUSED
:
2100 /* Used for debugging. Abort if any window has a dead buffer. */
2103 check_all_windows ()
2105 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2108 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 1, 0,
2109 doc
: /* Return the window least recently selected or used for display.
2110 Return a full-width window if possible.
2111 A minibuffer window is never a candidate.
2112 A dedicated window is never a candidate, so if all windows are dedicated,
2114 If optional argument FRAME is `visible', search all visible frames.
2115 If FRAME is 0, search all visible and iconified frames.
2116 If FRAME is t, search all frames.
2117 If FRAME is nil, search only the selected frame.
2118 If FRAME is a frame, search only that frame. */)
2122 register Lisp_Object w
;
2123 /* First try for a window that is full-width */
2124 w
= window_loop (GET_LRU_WINDOW
, Qt
, 0, frame
);
2125 if (!NILP (w
) && !EQ (w
, selected_window
))
2127 /* If none of them, try the rest */
2128 return window_loop (GET_LRU_WINDOW
, Qnil
, 0, frame
);
2131 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 1, 0,
2132 doc
: /* Return the largest window in area.
2133 A minibuffer window is never a candidate.
2134 A dedicated window is never a candidate, so if all windows are dedicated,
2136 If optional argument FRAME is `visible', search all visible frames.
2137 If FRAME is 0, search all visible and iconified frames.
2138 If FRAME is t, search all frames.
2139 If FRAME is nil, search only the selected frame.
2140 If FRAME is a frame, search only that frame. */)
2144 return window_loop (GET_LARGEST_WINDOW
, Qnil
, 0,
2148 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
2149 doc
: /* Return a window currently displaying BUFFER, or nil if none.
2150 BUFFER can be a buffer or a buffer name.
2151 If optional argument FRAME is `visible', search all visible frames.
2152 If optional argument FRAME is 0, search all visible and iconified frames.
2153 If FRAME is t, search all frames.
2154 If FRAME is nil, search only the selected frame.
2155 If FRAME is a frame, search only that frame. */)
2157 Lisp_Object buffer
, frame
;
2159 buffer
= Fget_buffer (buffer
);
2160 if (BUFFERP (buffer
))
2161 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
2166 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
2168 doc
: /* Make WINDOW (or the selected window) fill its frame.
2169 Only the frame WINDOW is on is affected.
2170 This function tries to reduce display jumps
2171 by keeping the text previously visible in WINDOW
2172 in the same place on the frame. Doing this depends on
2173 the value of (window-start WINDOW), so if calling this function
2174 in a program gives strange scrolling, make sure the window-start
2175 value is reasonable when this function is called. */)
2184 window
= selected_window
;
2186 CHECK_LIVE_WINDOW (window
);
2187 w
= XWINDOW (window
);
2189 startpos
= marker_position (w
->start
);
2190 top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2192 if (MINI_WINDOW_P (w
) && top
> 0)
2193 error ("Can't expand minibuffer to full frame");
2195 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
2197 /* Try to minimize scrolling, by setting the window start to the point
2198 will cause the text at the old window start to be at the same place
2199 on the frame. But don't try to do this if the window start is
2200 outside the visible portion (as might happen when the display is
2201 not current, due to typeahead). */
2202 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2204 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2205 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2207 struct position pos
;
2208 struct buffer
*obuf
= current_buffer
;
2210 Fset_buffer (w
->buffer
);
2211 /* This computation used to temporarily move point, but that can
2212 have unwanted side effects due to text properties. */
2213 pos
= *vmotion (startpos
, -top
, w
);
2215 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2216 w
->window_end_valid
= Qnil
;
2217 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
2218 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
2220 /* We need to do this, so that the window-scroll-functions
2222 w
->optional_new_start
= Qt
;
2224 set_buffer_internal (obuf
);
2230 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
2231 1, 2, "bDelete windows on (buffer): ",
2232 doc
: /* Delete all windows showing BUFFER.
2233 BUFFER must be a buffer or the name of an existing buffer.
2234 Optional second argument FRAME controls which frames are affected.
2235 If optional argument FRAME is `visible', search all visible frames.
2236 If FRAME is 0, search all visible and iconified frames.
2237 If FRAME is nil, search all frames.
2238 If FRAME is t, search only the selected frame.
2239 If FRAME is a frame, search only that frame. */)
2241 Lisp_Object buffer
, frame
;
2243 /* FRAME uses t and nil to mean the opposite of what window_loop
2247 else if (EQ (frame
, Qt
))
2252 buffer
= Fget_buffer (buffer
);
2253 CHECK_BUFFER (buffer
);
2254 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
2260 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
2261 Sreplace_buffer_in_windows
,
2262 1, 1, "bReplace buffer in windows: ",
2263 doc
: /* Replace BUFFER with some other buffer in all windows showing it.
2264 BUFFER may be a buffer or the name of an existing buffer. */)
2270 buffer
= Fget_buffer (buffer
);
2271 CHECK_BUFFER (buffer
);
2272 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
2277 /* Replace BUFFER with some other buffer in all windows
2278 of all frames, even those on other keyboards. */
2281 replace_buffer_in_all_windows (buffer
)
2285 Lisp_Object tail
, frame
;
2287 /* A single call to window_loop won't do the job
2288 because it only considers frames on the current keyboard.
2289 So loop manually over frames, and handle each one. */
2290 FOR_EACH_FRAME (tail
, frame
)
2291 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
2293 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
2297 /* Set the height of WINDOW and all its inferiors. */
2299 /* The smallest acceptable dimensions for a window. Anything smaller
2300 might crash Emacs. */
2302 #define MIN_SAFE_WINDOW_WIDTH (2)
2303 #define MIN_SAFE_WINDOW_HEIGHT (1)
2305 /* Make sure that window_min_height and window_min_width are
2306 not too small; if they are, set them to safe minima. */
2309 check_min_window_sizes ()
2311 /* Smaller values might permit a crash. */
2312 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
2313 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
2314 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
2315 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
2318 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2319 minimum allowable size. */
2322 check_frame_size (frame
, rows
, cols
)
2326 /* For height, we have to see:
2327 how many windows the frame has at minimum (one or two),
2328 and whether it has a menu bar or other special stuff at the top. */
2330 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
2331 ? MIN_SAFE_WINDOW_HEIGHT
2332 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
2334 if (FRAME_TOP_MARGIN (frame
) > 0)
2335 min_height
+= FRAME_TOP_MARGIN (frame
);
2337 if (*rows
< min_height
)
2339 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2340 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2344 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2345 check if W's width can be changed, otherwise check W's height.
2346 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2347 siblings, too. If none of the siblings is resizable, WINDOW isn't
2351 window_fixed_size_p (w
, width_p
, check_siblings_p
)
2353 int width_p
, check_siblings_p
;
2358 if (!NILP (w
->hchild
))
2360 c
= XWINDOW (w
->hchild
);
2364 /* A horiz. combination is fixed-width if all of if its
2366 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2367 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2368 fixed_p
= c
== NULL
;
2372 /* A horiz. combination is fixed-height if one of if its
2374 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2375 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2376 fixed_p
= c
!= NULL
;
2379 else if (!NILP (w
->vchild
))
2381 c
= XWINDOW (w
->vchild
);
2385 /* A vert. combination is fixed-width if one of if its
2387 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2388 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2389 fixed_p
= c
!= NULL
;
2393 /* A vert. combination is fixed-height if all of if its
2395 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2396 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2397 fixed_p
= c
== NULL
;
2400 else if (BUFFERP (w
->buffer
))
2402 if (w
->height_fixed_p
&& !width_p
)
2406 struct buffer
*old
= current_buffer
;
2409 current_buffer
= XBUFFER (w
->buffer
);
2410 val
= find_symbol_value (Qwindow_size_fixed
);
2411 current_buffer
= old
;
2414 if (!EQ (val
, Qunbound
))
2416 fixed_p
= !NILP (val
);
2419 && ((EQ (val
, Qheight
) && width_p
)
2420 || (EQ (val
, Qwidth
) && !width_p
)))
2425 /* Can't tell if this one is resizable without looking at
2426 siblings. If all siblings are fixed-size this one is too. */
2427 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
2431 for (child
= w
->prev
; !NILP (child
); child
= XWINDOW (child
)->prev
)
2432 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2436 for (child
= w
->next
; !NILP (child
); child
= XWINDOW (child
)->next
)
2437 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2451 /* Return the minimum size of window W, not taking fixed-width windows
2452 into account. WIDTH_P non-zero means return the minimum width,
2453 otherwise return the minimum height. If W is a combination window,
2454 compute the minimum size from the minimum sizes of W's children. */
2457 window_min_size_1 (w
, width_p
)
2464 if (!NILP (w
->hchild
))
2466 c
= XWINDOW (w
->hchild
);
2471 /* The min width of a horizontal combination is
2472 the sum of the min widths of its children. */
2475 size
+= window_min_size_1 (c
, width_p
);
2476 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2481 /* The min height a horizontal combination equals
2482 the maximum of all min height of its children. */
2485 int min_size
= window_min_size_1 (c
, width_p
);
2486 size
= max (min_size
, size
);
2487 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2491 else if (!NILP (w
->vchild
))
2493 c
= XWINDOW (w
->vchild
);
2498 /* The min width of a vertical combination is
2499 the maximum of the min widths of its children. */
2502 int min_size
= window_min_size_1 (c
, width_p
);
2503 size
= max (min_size
, size
);
2504 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2509 /* The min height of a vertical combination equals
2510 the sum of the min height of its children. */
2513 size
+= window_min_size_1 (c
, width_p
);
2514 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2521 size
= window_min_width
;
2524 if (MINI_WINDOW_P (w
)
2525 || (!WINDOW_WANTS_MODELINE_P (w
)
2526 && !WINDOW_WANTS_HEADER_LINE_P (w
)))
2529 size
= window_min_height
;
2537 /* Return the minimum size of window W, taking fixed-size windows into
2538 account. WIDTH_P non-zero means return the minimum width,
2539 otherwise return the minimum height. IGNORE_FIXED_P non-zero means
2540 ignore if W is fixed-size. Set *FIXED to 1 if W is fixed-size
2541 unless FIXED is null. */
2544 window_min_size (w
, width_p
, ignore_fixed_p
, fixed
)
2546 int width_p
, ignore_fixed_p
, *fixed
;
2553 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
2559 size
= width_p
? XFASTINT (w
->total_cols
) : XFASTINT (w
->total_lines
);
2561 size
= window_min_size_1 (w
, width_p
);
2567 /* Adjust the margins of window W if text area is too small.
2568 Return 1 if window width is ok after adjustment; 0 if window
2569 is still too narrow. */
2572 adjust_window_margins (w
)
2575 int box_cols
= (WINDOW_TOTAL_COLS (w
)
2576 - WINDOW_FRINGE_COLS (w
)
2577 - WINDOW_SCROLL_BAR_COLS (w
));
2578 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
2579 + WINDOW_RIGHT_MARGIN_COLS (w
));
2581 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
2584 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
2587 /* Window's text area is too narrow, but reducing the window
2588 margins will fix that. */
2589 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
2590 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
2592 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
2593 w
->left_margin_cols
= w
->right_margin_cols
2594 = make_number (margin_cols
/2);
2596 w
->right_margin_cols
= make_number (margin_cols
);
2599 w
->left_margin_cols
= make_number (margin_cols
);
2603 /* Calculate new sizes for windows in the list FORWARD when the window size
2604 goes from TOTAL to SIZE. TOTAL must be greater than SIZE.
2605 The number of windows in FORWARD is NCHILDREN, and the number that
2606 can shrink is SHRINKABLE.
2607 The minimum size a window can have is MIN_SIZE.
2608 If we are shrinking fixed windows, RESIZE_FIXED_P is non-zero.
2609 If we are shrinking columns, WIDTH_P is non-zero, otherwise we are
2612 This function returns an allocated array of new sizes that the caller
2613 must free. The size -1 means the window is fixed and RESIZE_FIXED_P
2614 is zero. Array index 0 refers to the first window in FORWARD, 1 to
2615 the second, and so on.
2617 This function tries to keep windows at least at the minimum size
2618 and resize other windows before it resizes any window to zero (i.e.
2619 delete that window).
2621 Windows are resized proportional to their size, so bigger windows
2622 shrink more than smaller windows. */
2624 shrink_windows (total
, size
, nchildren
, shrinkable
,
2625 min_size
, resize_fixed_p
, forward
, width_p
)
2626 int total
, size
, nchildren
, shrinkable
, min_size
;
2627 int resize_fixed_p
, width_p
;
2628 Lisp_Object forward
;
2630 int available_resize
= 0;
2634 int smallest
= total
;
2635 int total_removed
= 0;
2636 int total_shrink
= total
- size
;
2639 new_sizes
= xmalloc (sizeof (*new_sizes
) * nchildren
);
2641 for (i
= 0, child
= forward
; !NILP (child
); child
= c
->next
, ++i
)
2645 c
= XWINDOW (child
);
2646 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2648 if (! resize_fixed_p
&& window_fixed_size_p (c
, width_p
, 0))
2652 new_sizes
[i
] = child_size
;
2653 if (child_size
> min_size
)
2654 available_resize
+= child_size
- min_size
;
2657 /* We might need to shrink some windows to zero. Find the smallest
2658 windows and set them to 0 until we can fulfil the new size. */
2660 while (shrinkable
> 1 && size
+ available_resize
< total
)
2662 for (i
= 0; i
< nchildren
; ++i
)
2663 if (new_sizes
[i
] > 0 && smallest
> new_sizes
[i
])
2664 smallest
= new_sizes
[i
];
2666 for (i
= 0; i
< nchildren
; ++i
)
2667 if (new_sizes
[i
] == smallest
)
2669 /* Resize this window down to zero. */
2671 if (smallest
> min_size
)
2672 available_resize
-= smallest
- min_size
;
2673 available_resize
+= smallest
;
2675 total_removed
+= smallest
;
2677 /* We don't know what the smallest is now. */
2680 /* Out of for, just remove one window at the time and
2681 check again if we have enough space. */
2686 /* Now, calculate the new sizes. Try to shrink each window
2687 proportional to its size. */
2688 for (i
= 0; i
< nchildren
; ++i
)
2690 if (new_sizes
[i
] > min_size
)
2692 int to_shrink
= total_shrink
*new_sizes
[i
]/total
;
2693 if (new_sizes
[i
] - to_shrink
< min_size
)
2694 to_shrink
= new_sizes
[i
] - min_size
;
2695 new_sizes
[i
] -= to_shrink
;
2696 total_removed
+= to_shrink
;
2700 /* Any reminder due to rounding, we just subtract from windows
2701 that are left and still can be shrunk. */
2702 while (total_shrink
> total_removed
)
2704 int nonzero_sizes
= 0;
2705 int nonzero_idx
= -1;
2707 for (i
= 0; i
< nchildren
; ++i
)
2708 if (new_sizes
[i
] > 0)
2714 for (i
= 0; i
< nchildren
; ++i
)
2715 if (new_sizes
[i
] > min_size
)
2720 /* Out of for, just shrink one window at the time and
2721 check again if we have enough space. */
2726 /* Special case, only one window left. */
2727 if (nonzero_sizes
== 1)
2731 /* Any surplus due to rounding, we add to windows that are left. */
2732 while (total_shrink
< total_removed
)
2734 for (i
= 0; i
< nchildren
; ++i
)
2736 if (new_sizes
[i
] != 0 && total_shrink
< total_removed
)
2748 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
2749 WINDOW's width. Resize WINDOW's children, if any, so that they
2750 keep their proportionate size relative to WINDOW. Propagate
2751 WINDOW's top or left edge position to children. Delete windows
2752 that become too small unless NODELETE_P is non-zero.
2754 If NODELETE_P is 2, that means we do delete windows that are
2755 too small, even if they were too small before! */
2758 size_window (window
, size
, width_p
, nodelete_p
)
2760 int size
, width_p
, nodelete_p
;
2762 struct window
*w
= XWINDOW (window
);
2764 Lisp_Object child
, *forward
, *sideward
;
2765 int old_size
, min_size
, safe_min_size
;
2767 /* We test nodelete_p != 2 and nodelete_p != 1 below, so it
2768 seems like it's too soon to do this here. ++KFS. */
2769 if (nodelete_p
== 2)
2772 check_min_window_sizes ();
2773 size
= max (0, size
);
2775 /* If the window has been "too small" at one point,
2776 don't delete it for being "too small" in the future.
2777 Preserve it as long as that is at all possible. */
2780 old_size
= WINDOW_TOTAL_COLS (w
);
2781 min_size
= window_min_width
;
2782 /* Ensure that there is room for the scroll bar and fringes!
2783 We may reduce display margins though. */
2784 safe_min_size
= (MIN_SAFE_WINDOW_WIDTH
2785 + WINDOW_FRINGE_COLS (w
)
2786 + WINDOW_SCROLL_BAR_COLS (w
));
2790 old_size
= XINT (w
->total_lines
);
2791 min_size
= window_min_height
;
2792 safe_min_size
= MIN_SAFE_WINDOW_HEIGHT
;
2795 if (old_size
< min_size
&& nodelete_p
!= 2)
2796 w
->too_small_ok
= Qt
;
2798 /* Maybe delete WINDOW if it's too small. */
2799 if (nodelete_p
!= 1 && !NILP (w
->parent
))
2801 if (!MINI_WINDOW_P (w
) && !NILP (w
->too_small_ok
))
2802 min_size
= width_p
? MIN_SAFE_WINDOW_WIDTH
: MIN_SAFE_WINDOW_HEIGHT
;
2803 if (min_size
< safe_min_size
)
2804 min_size
= safe_min_size
;
2805 if (size
< min_size
)
2807 delete_window (window
);
2812 /* Set redisplay hints. */
2813 w
->last_modified
= make_number (0);
2814 w
->last_overlay_modified
= make_number (0);
2815 windows_or_buffers_changed
++;
2816 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w
->frame
)) = 1;
2820 sideward
= &w
->vchild
;
2821 forward
= &w
->hchild
;
2822 w
->total_cols
= make_number (size
);
2823 adjust_window_margins (w
);
2827 sideward
= &w
->hchild
;
2828 forward
= &w
->vchild
;
2829 w
->total_lines
= make_number (size
);
2830 w
->orig_total_lines
= Qnil
;
2833 if (!NILP (*sideward
))
2835 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
2837 c
= XWINDOW (child
);
2839 c
->left_col
= w
->left_col
;
2841 c
->top_line
= w
->top_line
;
2842 size_window (child
, size
, width_p
, nodelete_p
);
2845 else if (!NILP (*forward
))
2847 int fixed_size
, each
, extra
, n
;
2848 int resize_fixed_p
, nfixed
;
2849 int last_pos
, first_pos
, nchildren
, total
;
2850 int *new_sizes
= NULL
;
2852 /* Determine the fixed-size portion of the this window, and the
2853 number of child windows. */
2854 fixed_size
= nchildren
= nfixed
= total
= 0;
2855 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
2859 c
= XWINDOW (child
);
2860 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2861 total
+= child_size
;
2863 if (window_fixed_size_p (c
, width_p
, 0))
2865 fixed_size
+= child_size
;
2870 /* If the new size is smaller than fixed_size, or if there
2871 aren't any resizable windows, allow resizing fixed-size
2873 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
2875 /* Compute how many lines/columns to add/remove to each child. The
2876 value of extra takes care of rounding errors. */
2877 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
2878 if (size
< total
&& n
> 1)
2879 new_sizes
= shrink_windows (total
, size
, nchildren
, n
, min_size
,
2880 resize_fixed_p
, *forward
, width_p
);
2883 each
= (size
- total
) / n
;
2884 extra
= (size
- total
) - n
* each
;
2887 /* Compute new children heights and edge positions. */
2888 first_pos
= width_p
? XINT (w
->left_col
) : XINT (w
->top_line
);
2889 last_pos
= first_pos
;
2890 for (n
= 0, child
= *forward
; !NILP (child
); child
= c
->next
, ++n
)
2892 int new_size
, old_size
;
2894 c
= XWINDOW (child
);
2895 old_size
= width_p
? XFASTINT (c
->total_cols
) : XFASTINT (c
->total_lines
);
2896 new_size
= old_size
;
2898 /* The top or left edge position of this child equals the
2899 bottom or right edge of its predecessor. */
2901 c
->left_col
= make_number (last_pos
);
2903 c
->top_line
= make_number (last_pos
);
2905 /* If this child can be resized, do it. */
2906 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
2908 new_size
= new_sizes
? new_sizes
[n
] : old_size
+ each
+ extra
;
2912 /* Set new height. Note that size_window also propagates
2913 edge positions to children, so it's not a no-op if we
2914 didn't change the child's size. */
2915 size_window (child
, new_size
, width_p
, 1);
2917 /* Remember the bottom/right edge position of this child; it
2918 will be used to set the top/left edge of the next child. */
2919 last_pos
+= new_size
;
2922 if (new_sizes
) xfree (new_sizes
);
2924 /* We should have covered the parent exactly with child windows. */
2925 xassert (size
== last_pos
- first_pos
);
2927 /* Now delete any children that became too small. */
2929 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2932 c
= XWINDOW (child
);
2933 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2934 size_window (child
, child_size
, width_p
, 2);
2939 /* Set WINDOW's height to HEIGHT, and recursively change the height of
2940 WINDOW's children. NODELETE non-zero means don't delete windows
2941 that become too small in the process. (The caller should check
2942 later and do so if appropriate.) */
2945 set_window_height (window
, height
, nodelete
)
2950 size_window (window
, height
, 0, nodelete
);
2954 /* Set WINDOW's width to WIDTH, and recursively change the width of
2955 WINDOW's children. NODELETE non-zero means don't delete windows
2956 that become too small in the process. (The caller should check
2957 later and do so if appropriate.) */
2960 set_window_width (window
, width
, nodelete
)
2965 size_window (window
, width
, 1, nodelete
);
2968 /* Change window heights in windows rooted in WINDOW by N lines. */
2971 change_window_heights (window
, n
)
2975 struct window
*w
= XWINDOW (window
);
2977 XSETFASTINT (w
->top_line
, XFASTINT (w
->top_line
) + n
);
2978 XSETFASTINT (w
->total_lines
, XFASTINT (w
->total_lines
) - n
);
2980 if (INTEGERP (w
->orig_top_line
))
2981 XSETFASTINT (w
->orig_top_line
, XFASTINT (w
->orig_top_line
) + n
);
2982 if (INTEGERP (w
->orig_total_lines
))
2983 XSETFASTINT (w
->orig_total_lines
, XFASTINT (w
->orig_total_lines
) - n
);
2985 /* Handle just the top child in a vertical split. */
2986 if (!NILP (w
->vchild
))
2987 change_window_heights (w
->vchild
, n
);
2989 /* Adjust all children in a horizontal split. */
2990 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
2992 w
= XWINDOW (window
);
2993 change_window_heights (window
, n
);
2998 int window_select_count
;
3001 Fset_window_buffer_unwind (obuf
)
3008 EXFUN (Fset_window_fringes
, 4);
3009 EXFUN (Fset_window_scroll_bars
, 4);
3011 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
3012 means it's allowed to run hooks. See make_frame for a case where
3013 it's not allowed. KEEP_MARGINS_P non-zero means that the current
3014 margins, fringes, and scroll-bar settings of the window are not
3015 reset from the buffer's local settings. */
3018 set_window_buffer (window
, buffer
, run_hooks_p
, keep_margins_p
)
3019 Lisp_Object window
, buffer
;
3020 int run_hooks_p
, keep_margins_p
;
3022 struct window
*w
= XWINDOW (window
);
3023 struct buffer
*b
= XBUFFER (buffer
);
3024 int count
= SPECPDL_INDEX ();
3028 if (EQ (window
, selected_window
))
3029 b
->last_selected_window
= window
;
3031 /* Let redisplay errors through. */
3032 b
->display_error_modiff
= 0;
3034 /* Update time stamps of buffer display. */
3035 if (INTEGERP (b
->display_count
))
3036 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
3037 b
->display_time
= Fcurrent_time ();
3039 XSETFASTINT (w
->window_end_pos
, 0);
3040 XSETFASTINT (w
->window_end_vpos
, 0);
3041 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
3042 w
->window_end_valid
= Qnil
;
3043 w
->hscroll
= w
->min_hscroll
= make_number (0);
3045 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3046 set_marker_restricted (w
->start
,
3047 make_number (b
->last_window_start
),
3049 w
->start_at_line_beg
= Qnil
;
3050 w
->force_start
= Qnil
;
3051 XSETFASTINT (w
->last_modified
, 0);
3052 XSETFASTINT (w
->last_overlay_modified
, 0);
3053 windows_or_buffers_changed
++;
3055 /* We must select BUFFER for running the window-scroll-functions.
3056 If WINDOW is selected, switch permanently.
3057 Otherwise, switch but go back to the ambient buffer afterward. */
3058 if (EQ (window
, selected_window
))
3059 Fset_buffer (buffer
);
3060 /* We can't check ! NILP (Vwindow_scroll_functions) here
3061 because that might itself be a local variable. */
3062 else if (window_initialized
)
3064 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
3065 Fset_buffer (buffer
);
3068 if (!keep_margins_p
)
3070 /* Set left and right marginal area width etc. from buffer. */
3072 /* This may call adjust_window_margins three times, so
3073 temporarily disable window margins. */
3074 Lisp_Object save_left
= w
->left_margin_cols
;
3075 Lisp_Object save_right
= w
->right_margin_cols
;
3077 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
3079 Fset_window_fringes (window
,
3080 b
->left_fringe_width
, b
->right_fringe_width
,
3081 b
->fringes_outside_margins
);
3083 Fset_window_scroll_bars (window
,
3084 b
->scroll_bar_width
,
3085 b
->vertical_scroll_bar_type
, Qnil
);
3087 w
->left_margin_cols
= save_left
;
3088 w
->right_margin_cols
= save_right
;
3090 Fset_window_margins (window
,
3091 b
->left_margin_cols
, b
->right_margin_cols
);
3096 if (! NILP (Vwindow_scroll_functions
))
3097 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3098 Fmarker_position (w
->start
));
3100 if (! NILP (Vwindow_configuration_change_hook
)
3101 && ! NILP (Vrun_hooks
))
3102 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3105 unbind_to (count
, Qnil
);
3109 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3110 doc
: /* Make WINDOW display BUFFER as its contents.
3111 BUFFER can be a buffer or the name of an existing buffer.
3112 Optional third arg KEEP-MARGINS non-nil means that WINDOW's current
3113 display margins, fringe widths, and scroll bar settings are maintained;
3114 the default is to reset these from BUFFER's local settings or the frame
3117 This function runs the hook `window-scroll-functions'. */)
3118 (window
, buffer
, keep_margins
)
3119 register Lisp_Object window
, buffer
, keep_margins
;
3121 register Lisp_Object tem
;
3122 register struct window
*w
= decode_window (window
);
3124 XSETWINDOW (window
, w
);
3125 buffer
= Fget_buffer (buffer
);
3126 CHECK_BUFFER (buffer
);
3128 if (NILP (XBUFFER (buffer
)->name
))
3129 error ("Attempt to display deleted buffer");
3133 error ("Window is deleted");
3134 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
3135 is first being set up. */
3137 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
3138 error ("Window is dedicated to `%s'",
3139 SDATA (XBUFFER (tem
)->name
));
3144 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3148 /* Note that selected_window can be nil
3149 when this is called from Fset_window_configuration. */
3151 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
3152 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
3153 If WINDOW is not already selected, make WINDOW's buffer current
3154 and make WINDOW the frame's selected window. Return WINDOW.
3155 Optional second arg NORECORD non-nil means
3156 do not put this buffer at the front of the list of recently selected ones.
3158 Note that the main editor command loop
3159 selects the buffer of the selected window before each command. */)
3161 register Lisp_Object window
, norecord
;
3163 register struct window
*w
;
3164 register struct window
*ow
;
3167 CHECK_LIVE_WINDOW (window
);
3169 w
= XWINDOW (window
);
3170 w
->frozen_window_start_p
= 0;
3172 ++window_select_count
;
3173 XSETFASTINT (w
->use_time
, window_select_count
);
3174 if (EQ (window
, selected_window
))
3177 if (!NILP (selected_window
))
3179 ow
= XWINDOW (selected_window
);
3180 if (! NILP (ow
->buffer
))
3181 set_marker_both (ow
->pointm
, ow
->buffer
,
3182 BUF_PT (XBUFFER (ow
->buffer
)),
3183 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
3186 selected_window
= window
;
3187 sf
= SELECTED_FRAME ();
3188 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
3190 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
3191 /* Use this rather than Fhandle_switch_frame
3192 so that FRAME_FOCUS_FRAME is moved appropriately as we
3193 move around in the state where a minibuffer in a separate
3195 Fselect_frame (WINDOW_FRAME (w
), Qnil
);
3198 sf
->selected_window
= window
;
3200 if (NILP (norecord
))
3201 record_buffer (w
->buffer
);
3202 Fset_buffer (w
->buffer
);
3204 XBUFFER (w
->buffer
)->last_selected_window
= window
;
3206 /* Go to the point recorded in the window.
3207 This is important when the buffer is in more
3208 than one window. It also matters when
3209 redisplay_window has altered point after scrolling,
3210 because it makes the change only in the window. */
3212 register int new_point
= marker_position (w
->pointm
);
3213 if (new_point
< BEGV
)
3215 else if (new_point
> ZV
)
3221 windows_or_buffers_changed
++;
3226 select_window_norecord (window
)
3229 return Fselect_window (window
, Qt
);
3232 /* Deiconify the frame containing the window WINDOW,
3233 unless it is the selected frame;
3236 The reason for the exception for the selected frame
3237 is that it seems better not to change the selected frames visibility
3238 merely because of displaying a different buffer in it.
3239 The deiconification is useful when a buffer gets shown in
3240 another frame that you were not using lately. */
3243 display_buffer_1 (window
)
3246 Lisp_Object frame
= XWINDOW (window
)->frame
;
3247 FRAME_PTR f
= XFRAME (frame
);
3249 FRAME_SAMPLE_VISIBILITY (f
);
3251 if (EQ (frame
, selected_frame
))
3252 ; /* Assume the selected frame is already visible enough. */
3253 else if (minibuf_level
> 0
3254 && MINI_WINDOW_P (XWINDOW (selected_window
))
3255 && WINDOW_LIVE_P (minibuf_selected_window
)
3256 && EQ (frame
, WINDOW_FRAME (XWINDOW (minibuf_selected_window
))))
3257 ; /* Assume the frame from which we invoked the minibuffer is visible. */
3260 if (FRAME_ICONIFIED_P (f
))
3261 Fmake_frame_visible (frame
);
3262 else if (FRAME_VISIBLE_P (f
))
3263 Fraise_frame (frame
);
3269 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
3270 doc
: /* Returns non-nil if a buffer named BUFFER-NAME gets a special frame.
3271 If the value is t, a frame would be created for that buffer
3272 using the default frame parameters. If the value is a list,
3273 it is a list of frame parameters that would be used
3274 to make a frame for that buffer.
3275 The variables `special-display-buffer-names'
3276 and `special-display-regexps' control this. */)
3278 Lisp_Object buffer_name
;
3282 CHECK_STRING (buffer_name
);
3284 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
3288 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
3292 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
3294 Lisp_Object car
= XCAR (tem
);
3296 && fast_string_match (car
, buffer_name
) >= 0)
3298 else if (CONSP (car
)
3299 && STRINGP (XCAR (car
))
3300 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
3306 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
3307 doc
: /* Returns non-nil if a new buffer named BUFFER-NAME would use the same window.
3308 See `same-window-buffer-names' and `same-window-regexps'. */)
3310 Lisp_Object buffer_name
;
3314 CHECK_STRING (buffer_name
);
3316 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
3320 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
3324 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
3326 Lisp_Object car
= XCAR (tem
);
3328 && fast_string_match (car
, buffer_name
) >= 0)
3330 else if (CONSP (car
)
3331 && STRINGP (XCAR (car
))
3332 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
3338 /* Use B so the default is (other-buffer). */
3339 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
3340 "BDisplay buffer: \nP",
3341 doc
: /* Make BUFFER appear in some window but don't select it.
3342 BUFFER must be the name of an existing buffer, or, when called from Lisp,
3344 If BUFFER is shown already in some window, just use that one,
3345 unless the window is the selected window and the optional second
3346 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).
3347 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
3348 Returns the window displaying BUFFER.
3349 If `display-buffer-reuse-frames' is non-nil, and another frame is currently
3350 displaying BUFFER, then simply raise that frame.
3352 The variables `special-display-buffer-names',
3353 `special-display-regexps', `same-window-buffer-names', and
3354 `same-window-regexps' customize how certain buffer names are handled.
3355 The latter two take effect only if NOT-THIS-WINDOW is t.
3357 If optional argument FRAME is `visible', search all visible frames.
3358 If FRAME is 0, search all visible and iconified frames.
3359 If FRAME is t, search all frames.
3360 If FRAME is a frame, search only that frame.
3361 If FRAME is nil, search only the selected frame
3362 (actually the last nonminibuffer frame),
3363 unless `pop-up-frames' or `display-buffer-reuse-frames' is non-nil,
3364 which means search visible and iconified frames.
3366 If a full-width window on a splittable frame is available to display
3367 the buffer, it may be split, subject to the value of the variable
3368 `split-height-threshold'.
3370 If `even-window-heights' is non-nil, window heights will be evened out
3371 if displaying the buffer causes two vertically adjacent windows to be
3373 (buffer
, not_this_window
, frame
)
3374 register Lisp_Object buffer
, not_this_window
, frame
;
3376 register Lisp_Object window
, tem
, swp
;
3380 buffer
= Fget_buffer (buffer
);
3381 CHECK_BUFFER (buffer
);
3383 if (!NILP (Vdisplay_buffer_function
))
3384 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
3386 if (NILP (not_this_window
)
3387 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
3388 return display_buffer_1 (selected_window
);
3390 /* See if the user has specified this buffer should appear
3391 in the selected window. */
3392 if (NILP (not_this_window
))
3394 swp
= Fsame_window_p (XBUFFER (buffer
)->name
);
3395 if (!NILP (swp
) && !no_switch_window (selected_window
))
3397 Fswitch_to_buffer (buffer
, Qnil
);
3398 return display_buffer_1 (selected_window
);
3402 /* If the user wants pop-up-frames or display-buffer-reuse-frames,
3403 look for a window showing BUFFER on any visible or iconified frame.
3404 Otherwise search only the current frame. */
3407 else if (pop_up_frames
3408 || display_buffer_reuse_frames
3409 || last_nonminibuf_frame
== 0)
3410 XSETFASTINT (tem
, 0);
3412 XSETFRAME (tem
, last_nonminibuf_frame
);
3414 window
= Fget_buffer_window (buffer
, tem
);
3416 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
3417 return display_buffer_1 (window
);
3419 /* Certain buffer names get special handling. */
3420 if (!NILP (Vspecial_display_function
) && NILP (swp
))
3422 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
3424 return call1 (Vspecial_display_function
, buffer
);
3426 return call2 (Vspecial_display_function
, buffer
, tem
);
3429 /* If there are no frames open that have more than a minibuffer,
3430 we need to create a new frame. */
3431 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
3433 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3434 Fset_window_buffer (window
, buffer
, Qnil
);
3435 return display_buffer_1 (window
);
3438 f
= SELECTED_FRAME ();
3440 || FRAME_MINIBUF_ONLY_P (f
)
3441 /* If the current frame is a special display frame,
3442 don't try to reuse its windows. */
3443 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (f
))->dedicated
))
3448 if (FRAME_MINIBUF_ONLY_P (f
))
3449 XSETFRAME (frames
, last_nonminibuf_frame
);
3450 /* Don't try to create a window if we would get an error. */
3451 if (split_height_threshold
< window_min_height
<< 1)
3452 split_height_threshold
= window_min_height
<< 1;
3454 /* Note that both Fget_largest_window and Fget_lru_window
3455 ignore minibuffers and dedicated windows.
3456 This means they can return nil. */
3458 /* If the frame we would try to split cannot be split,
3459 try other frames. */
3460 if (FRAME_NO_SPLIT_P (NILP (frames
) ? f
: last_nonminibuf_frame
))
3462 /* Try visible frames first. */
3463 window
= Fget_largest_window (Qvisible
);
3464 /* If that didn't work, try iconified frames. */
3466 window
= Fget_largest_window (make_number (0));
3468 window
= Fget_largest_window (Qt
);
3471 window
= Fget_largest_window (frames
);
3473 /* If we got a tall enough full-width window that can be split,
3476 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3477 && window_height (window
) >= split_height_threshold
3478 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
3479 window
= Fsplit_window (window
, Qnil
, Qnil
);
3482 Lisp_Object upper
, lower
, other
;
3484 window
= Fget_lru_window (frames
);
3485 /* If the LRU window is selected, and big enough,
3486 and can be split, split it. */
3488 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3489 && (EQ (window
, selected_window
)
3490 || EQ (XWINDOW (window
)->parent
, Qnil
))
3491 && window_height (window
) >= window_min_height
<< 1)
3492 window
= Fsplit_window (window
, Qnil
, Qnil
);
3493 /* If Fget_lru_window returned nil, try other approaches. */
3495 /* Try visible frames first. */
3497 window
= Fget_buffer_window (buffer
, Qvisible
);
3499 window
= Fget_largest_window (Qvisible
);
3500 /* If that didn't work, try iconified frames. */
3502 window
= Fget_buffer_window (buffer
, make_number (0));
3504 window
= Fget_largest_window (make_number (0));
3505 /* Try invisible frames. */
3507 window
= Fget_buffer_window (buffer
, Qt
);
3509 window
= Fget_largest_window (Qt
);
3510 /* As a last resort, make a new frame. */
3512 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3513 /* If window appears above or below another,
3514 even out their heights. */
3515 other
= upper
= lower
= Qnil
;
3516 if (!NILP (XWINDOW (window
)->prev
))
3517 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
3518 if (!NILP (XWINDOW (window
)->next
))
3519 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
3521 && !NILP (Veven_window_heights
)
3522 /* Check that OTHER and WINDOW are vertically arrayed. */
3523 && !EQ (XWINDOW (other
)->top_line
, XWINDOW (window
)->top_line
)
3524 && (XFASTINT (XWINDOW (other
)->total_lines
)
3525 > XFASTINT (XWINDOW (window
)->total_lines
)))
3527 int total
= (XFASTINT (XWINDOW (other
)->total_lines
)
3528 + XFASTINT (XWINDOW (window
)->total_lines
));
3529 enlarge_window (upper
,
3530 total
/ 2 - XFASTINT (XWINDOW (upper
)->total_lines
),
3536 window
= Fget_lru_window (Qnil
);
3538 Fset_window_buffer (window
, buffer
, Qnil
);
3539 return display_buffer_1 (window
);
3543 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3545 doc
: /* Force redisplay of all windows.
3546 If optional arg OBJECT is a window, force redisplay of that window only.
3547 If OBJECT is a buffer or buffer name, force redisplay of all windows
3548 displaying that buffer. */)
3554 windows_or_buffers_changed
++;
3555 update_mode_lines
++;
3559 if (WINDOWP (object
))
3561 struct window
*w
= XWINDOW (object
);
3562 mark_window_display_accurate (object
, 0);
3563 w
->update_mode_line
= Qt
;
3564 if (BUFFERP (w
->buffer
))
3565 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
3566 ++update_mode_lines
;
3570 if (STRINGP (object
))
3571 object
= Fget_buffer (object
);
3572 if (BUFFERP (object
) && !NILP (XBUFFER (object
)->name
))
3574 /* Walk all windows looking for buffer, and force update
3575 of each of those windows. */
3577 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3578 return NILP (object
) ? Qnil
: Qt
;
3581 /* If nothing suitable was found, just return.
3582 We could signal an error, but this feature will typically be used
3583 asynchronously in timers or process sentinels, so we don't. */
3589 temp_output_buffer_show (buf
)
3590 register Lisp_Object buf
;
3592 register struct buffer
*old
= current_buffer
;
3593 register Lisp_Object window
;
3594 register struct window
*w
;
3596 XBUFFER (buf
)->directory
= current_buffer
->directory
;
3599 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3603 #if 0 /* rms: there should be no reason for this. */
3604 XBUFFER (buf
)->prevent_redisplay_optimizations_p
= 1;
3606 set_buffer_internal (old
);
3608 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
3609 call1 (Vtemp_buffer_show_function
, buf
);
3612 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
3614 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3615 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3616 Vminibuf_scroll_window
= window
;
3617 w
= XWINDOW (window
);
3618 XSETFASTINT (w
->hscroll
, 0);
3619 XSETFASTINT (w
->min_hscroll
, 0);
3620 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3621 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3623 /* Run temp-buffer-show-hook, with the chosen window selected
3624 and its buffer current. */
3626 if (!NILP (Vrun_hooks
)
3627 && !NILP (Fboundp (Qtemp_buffer_show_hook
))
3628 && !NILP (Fsymbol_value (Qtemp_buffer_show_hook
)))
3630 int count
= SPECPDL_INDEX ();
3631 Lisp_Object prev_window
, prev_buffer
;
3632 prev_window
= selected_window
;
3633 XSETBUFFER (prev_buffer
, old
);
3635 /* Select the window that was chosen, for running the hook.
3636 Note: Both Fselect_window and select_window_norecord may
3637 set-buffer to the buffer displayed in the window,
3638 so we need to save the current buffer. --stef */
3639 record_unwind_protect (Fset_buffer
, prev_buffer
);
3640 record_unwind_protect (select_window_norecord
, prev_window
);
3641 Fselect_window (window
, Qt
);
3642 Fset_buffer (w
->buffer
);
3643 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
3644 unbind_to (count
, Qnil
);
3650 make_dummy_parent (window
)
3654 register struct window
*o
, *p
;
3657 o
= XWINDOW (window
);
3658 p
= allocate_window ();
3659 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
3660 ((struct Lisp_Vector
*) p
)->contents
[i
]
3661 = ((struct Lisp_Vector
*)o
)->contents
[i
];
3662 XSETWINDOW (new, p
);
3665 XSETFASTINT (p
->sequence_number
, sequence_number
);
3667 /* Put new into window structure in place of window */
3668 replace_window (window
, new);
3681 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
3682 doc
: /* Split WINDOW, putting SIZE lines in the first of the pair.
3683 WINDOW defaults to selected one and SIZE to half its size.
3684 If optional third arg HORFLAG is non-nil, split side by side
3685 and put SIZE columns in the first of the pair. In that case,
3686 SIZE includes that window's scroll bar, or the divider column to its right.
3687 Interactively, all arguments are nil.
3689 Returns the newly created window (which is the lower or rightmost one).
3690 The upper or leftmost window is the original one and remains selected.
3691 See Info node `(elisp)Splitting Windows' for more details and examples.*/)
3692 (window
, size
, horflag
)
3693 Lisp_Object window
, size
, horflag
;
3695 register Lisp_Object
new;
3696 register struct window
*o
, *p
;
3698 register int size_int
;
3701 window
= selected_window
;
3703 CHECK_LIVE_WINDOW (window
);
3705 o
= XWINDOW (window
);
3706 fo
= XFRAME (WINDOW_FRAME (o
));
3710 if (!NILP (horflag
))
3711 /* Calculate the size of the left-hand window, by dividing
3712 the usable space in columns by two.
3713 We round up, since the left-hand window may include
3714 a dividing line, while the right-hand may not. */
3715 size_int
= (XFASTINT (o
->total_cols
) + 1) >> 1;
3717 size_int
= XFASTINT (o
->total_lines
) >> 1;
3721 CHECK_NUMBER (size
);
3722 size_int
= XINT (size
);
3725 if (MINI_WINDOW_P (o
))
3726 error ("Attempt to split minibuffer window");
3727 else if (window_fixed_size_p (o
, !NILP (horflag
), 0))
3728 error ("Attempt to split fixed-size window");
3730 check_min_window_sizes ();
3734 if (size_int
< window_min_height
)
3735 error ("Window height %d too small (after splitting)", size_int
);
3736 if (size_int
+ window_min_height
> XFASTINT (o
->total_lines
))
3737 error ("Window height %d too small (after splitting)",
3738 XFASTINT (o
->total_lines
) - size_int
);
3739 if (NILP (o
->parent
)
3740 || NILP (XWINDOW (o
->parent
)->vchild
))
3742 make_dummy_parent (window
);
3744 XWINDOW (new)->vchild
= window
;
3749 if (size_int
< window_min_width
)
3750 error ("Window width %d too small (after splitting)", size_int
);
3752 if (size_int
+ window_min_width
> XFASTINT (o
->total_cols
))
3753 error ("Window width %d too small (after splitting)",
3754 XFASTINT (o
->total_cols
) - size_int
);
3755 if (NILP (o
->parent
)
3756 || NILP (XWINDOW (o
->parent
)->hchild
))
3758 make_dummy_parent (window
);
3760 XWINDOW (new)->hchild
= window
;
3764 /* Now we know that window's parent is a vertical combination
3765 if we are dividing vertically, or a horizontal combination
3766 if we are making side-by-side windows */
3768 windows_or_buffers_changed
++;
3769 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
3770 new = make_window ();
3773 p
->frame
= o
->frame
;
3775 if (!NILP (p
->next
))
3776 XWINDOW (p
->next
)->prev
= new;
3779 p
->parent
= o
->parent
;
3781 p
->window_end_valid
= Qnil
;
3782 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
3784 /* Duplicate special geometry settings. */
3786 p
->left_margin_cols
= o
->left_margin_cols
;
3787 p
->right_margin_cols
= o
->right_margin_cols
;
3788 p
->left_fringe_width
= o
->left_fringe_width
;
3789 p
->right_fringe_width
= o
->right_fringe_width
;
3790 p
->fringes_outside_margins
= o
->fringes_outside_margins
;
3791 p
->scroll_bar_width
= o
->scroll_bar_width
;
3792 p
->vertical_scroll_bar_type
= o
->vertical_scroll_bar_type
;
3794 /* Apportion the available frame space among the two new windows */
3796 if (!NILP (horflag
))
3798 p
->total_lines
= o
->total_lines
;
3799 p
->top_line
= o
->top_line
;
3800 XSETFASTINT (p
->total_cols
, XFASTINT (o
->total_cols
) - size_int
);
3801 XSETFASTINT (o
->total_cols
, size_int
);
3802 XSETFASTINT (p
->left_col
, XFASTINT (o
->left_col
) + size_int
);
3803 adjust_window_margins (p
);
3804 adjust_window_margins (o
);
3808 p
->left_col
= o
->left_col
;
3809 p
->total_cols
= o
->total_cols
;
3810 XSETFASTINT (p
->total_lines
, XFASTINT (o
->total_lines
) - size_int
);
3811 XSETFASTINT (o
->total_lines
, size_int
);
3812 XSETFASTINT (p
->top_line
, XFASTINT (o
->top_line
) + size_int
);
3815 /* Adjust glyph matrices. */
3818 Fset_window_buffer (new, o
->buffer
, Qt
);
3822 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 3, "p",
3823 doc
: /* Make current window ARG lines bigger.
3824 From program, optional second arg non-nil means grow sideways ARG columns.
3825 Interactively, if an argument is not given, make the window one line bigger.
3827 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3828 of the siblings above or to the left of the selected window. Only
3829 siblings to the right or below are changed. */)
3830 (arg
, side
, preserve_before
)
3831 register Lisp_Object arg
, side
, preserve_before
;
3834 enlarge_window (selected_window
, XINT (arg
), !NILP (side
),
3835 !NILP (preserve_before
));
3837 if (! NILP (Vwindow_configuration_change_hook
))
3838 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3843 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 3, "p",
3844 doc
: /* Make current window ARG lines smaller.
3845 From program, optional second arg non-nil means shrink sideways arg columns.
3846 Interactively, if an argument is not given, make the window one line smaller.
3848 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3849 of the siblings above or to the left of the selected window. Only
3850 siblings to the right or below are changed. */)
3851 (arg
, side
, preserve_before
)
3852 register Lisp_Object arg
, side
, preserve_before
;
3855 enlarge_window (selected_window
, -XINT (arg
), !NILP (side
),
3856 !NILP (preserve_before
));
3858 if (! NILP (Vwindow_configuration_change_hook
))
3859 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3865 window_height (window
)
3868 register struct window
*p
= XWINDOW (window
);
3869 return WINDOW_TOTAL_LINES (p
);
3873 window_width (window
)
3876 register struct window
*p
= XWINDOW (window
);
3877 return WINDOW_TOTAL_COLS (p
);
3882 *(widthflag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line))
3884 #define CURSIZE(w) \
3885 *(widthflag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines))
3888 /* Enlarge WINDOW by DELTA. WIDTHFLAG non-zero means
3889 increase its width. Siblings of the selected window are resized to
3890 fulfill the size request. If they become too small in the process,
3891 they will be deleted.
3893 If PRESERVE_BEFORE is nonzero, that means don't alter
3894 the siblings to the left or above WINDOW. */
3897 enlarge_window (window
, delta
, widthflag
, preserve_before
)
3899 int delta
, widthflag
, preserve_before
;
3901 Lisp_Object parent
, next
, prev
;
3905 int (*sizefun
) P_ ((Lisp_Object
))
3906 = widthflag
? window_width
: window_height
;
3907 void (*setsizefun
) P_ ((Lisp_Object
, int, int))
3908 = (widthflag
? set_window_width
: set_window_height
);
3910 /* Check values of window_min_width and window_min_height for
3912 check_min_window_sizes ();
3914 /* Give up if this window cannot be resized. */
3915 if (window_fixed_size_p (XWINDOW (window
), widthflag
, 1))
3916 error ("Window is not resizable");
3918 /* Find the parent of the selected window. */
3921 p
= XWINDOW (window
);
3927 error ("No other window to side of this one");
3932 ? !NILP (XWINDOW (parent
)->hchild
)
3933 : !NILP (XWINDOW (parent
)->vchild
))
3939 sizep
= &CURSIZE (window
);
3942 register int maxdelta
;
3944 /* Compute the maximum size increment this window can have. */
3946 if (preserve_before
)
3950 maxdelta
= (*sizefun
) (parent
) - XINT (*sizep
);
3951 /* Subtract size of siblings before, since we can't take that. */
3952 maxdelta
-= XINT (CURBEG (window
)) - XINT (CURBEG (parent
));
3955 maxdelta
= (!NILP (p
->next
) ? ((*sizefun
) (p
->next
)
3956 - window_min_size (XWINDOW (p
->next
),
3961 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - XINT (*sizep
)
3962 /* This is a main window followed by a minibuffer. */
3963 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
3964 - window_min_size (XWINDOW (p
->next
),
3966 /* This is a minibuffer following a main window. */
3967 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
3968 - window_min_size (XWINDOW (p
->prev
),
3970 /* This is a frame with only one window, a minibuffer-only
3971 or a minibufferless frame. */
3974 if (delta
> maxdelta
)
3975 /* This case traps trying to make the minibuffer
3976 the full frame, or make the only window aside from the
3977 minibuffer the full frame. */
3981 if (XINT (*sizep
) + delta
< window_min_size (XWINDOW (window
), widthflag
, 0, 0))
3983 delete_window (window
);
3990 /* Find the total we can get from other siblings without deleting them. */
3992 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
3993 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
3995 if (! preserve_before
)
3996 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
3997 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
4000 /* If we can get it all from them without deleting them, do so. */
4001 if (delta
<= maximum
)
4003 Lisp_Object first_unaffected
;
4004 Lisp_Object first_affected
;
4009 first_affected
= window
;
4010 /* Look at one sibling at a time,
4011 moving away from this window in both directions alternately,
4012 and take as much as we can get without deleting that sibling. */
4014 && (!NILP (next
) || (!preserve_before
&& !NILP (prev
))))
4018 int this_one
= ((*sizefun
) (next
)
4019 - window_min_size (XWINDOW (next
),
4020 widthflag
, 0, &fixed_p
));
4023 if (this_one
> delta
)
4026 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
4027 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4032 next
= XWINDOW (next
)->next
;
4038 if (!preserve_before
&& ! NILP (prev
))
4040 int this_one
= ((*sizefun
) (prev
)
4041 - window_min_size (XWINDOW (prev
),
4042 widthflag
, 0, &fixed_p
));
4045 if (this_one
> delta
)
4048 first_affected
= prev
;
4050 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
4051 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4056 prev
= XWINDOW (prev
)->prev
;
4060 xassert (delta
== 0);
4062 /* Now recalculate the edge positions of all the windows affected,
4063 based on the new sizes. */
4064 first_unaffected
= next
;
4065 prev
= first_affected
;
4066 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
4067 prev
= next
, next
= XWINDOW (next
)->next
)
4069 XSETINT (CURBEG (next
), XINT (CURBEG (prev
)) + (*sizefun
) (prev
));
4070 /* This does not change size of NEXT,
4071 but it propagates the new top edge to its children */
4072 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
4077 register int delta1
;
4078 register int opht
= (*sizefun
) (parent
);
4080 if (opht
<= XINT (*sizep
) + delta
)
4082 /* If trying to grow this window to or beyond size of the parent,
4083 just delete all the sibling windows. */
4084 Lisp_Object start
, tem
, next
;
4086 start
= XWINDOW (parent
)->vchild
;
4088 start
= XWINDOW (parent
)->hchild
;
4090 /* Delete any siblings that come after WINDOW. */
4091 tem
= XWINDOW (window
)->next
;
4092 while (! NILP (tem
))
4094 next
= XWINDOW (tem
)->next
;
4095 delete_window (tem
);
4099 /* Delete any siblings that come after WINDOW.
4100 Note that if START is not WINDOW, then WINDOW still
4101 Fhas siblings, so WINDOW has not yet replaced its parent. */
4103 while (! EQ (tem
, window
))
4105 next
= XWINDOW (tem
)->next
;
4106 delete_window (tem
);
4112 /* Otherwise, make delta1 just right so that if we add
4113 delta1 lines to this window and to the parent, and then
4114 shrink the parent back to its original size, the new
4115 proportional size of this window will increase by delta.
4117 The function size_window will compute the new height h'
4118 of the window from delta1 as:
4121 x = delta1 - delta1/n * n for the 1st resizable child
4124 where n is the number of children that can be resized.
4125 We can ignore x by choosing a delta1 that is a multiple of
4126 n. We want the height of this window to come out as
4136 The number of children n equals the number of resizable
4137 children of this window + 1 because we know window itself
4138 is resizable (otherwise we would have signalled an error. */
4140 struct window
*w
= XWINDOW (window
);
4144 for (s
= w
->next
; !NILP (s
); s
= XWINDOW (s
)->next
)
4145 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
4147 for (s
= w
->prev
; !NILP (s
); s
= XWINDOW (s
)->prev
)
4148 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
4153 /* Add delta1 lines or columns to this window, and to the parent,
4154 keeping things consistent while not affecting siblings. */
4155 XSETINT (CURSIZE (parent
), opht
+ delta1
);
4156 (*setsizefun
) (window
, XINT (*sizep
) + delta1
, 0);
4158 /* Squeeze out delta1 lines or columns from our parent,
4159 shriking this window and siblings proportionately.
4160 This brings parent back to correct size.
4161 Delta1 was calculated so this makes this window the desired size,
4162 taking it all out of the siblings. */
4163 (*setsizefun
) (parent
, opht
, 0);
4168 XSETFASTINT (p
->last_modified
, 0);
4169 XSETFASTINT (p
->last_overlay_modified
, 0);
4171 /* Adjust glyph matrices. */
4172 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4180 /***********************************************************************
4181 Resizing Mini-Windows
4182 ***********************************************************************/
4184 static void shrink_window_lowest_first
P_ ((struct window
*, int));
4186 enum save_restore_action
4193 static int save_restore_orig_size
P_ ((struct window
*,
4194 enum save_restore_action
));
4196 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
4197 from lowest windows first. */
4200 shrink_window_lowest_first (w
, height
)
4208 xassert (!MINI_WINDOW_P (w
));
4210 /* Set redisplay hints. */
4211 XSETFASTINT (w
->last_modified
, 0);
4212 XSETFASTINT (w
->last_overlay_modified
, 0);
4213 windows_or_buffers_changed
++;
4214 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
4216 old_height
= XFASTINT (w
->total_lines
);
4217 XSETFASTINT (w
->total_lines
, height
);
4219 if (!NILP (w
->hchild
))
4221 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
4223 c
= XWINDOW (child
);
4224 c
->top_line
= w
->top_line
;
4225 shrink_window_lowest_first (c
, height
);
4228 else if (!NILP (w
->vchild
))
4230 Lisp_Object last_child
;
4231 int delta
= old_height
- height
;
4236 /* Find the last child. We are taking space from lowest windows
4237 first, so we iterate over children from the last child
4239 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
4242 /* Assign new heights. We leave only MIN_SAFE_WINDOW_HEIGHT. */
4243 for (child
= last_child
; delta
&& !NILP (child
); child
= c
->prev
)
4247 c
= XWINDOW (child
);
4248 this_one
= XFASTINT (c
->total_lines
) - MIN_SAFE_WINDOW_HEIGHT
;
4250 if (this_one
> delta
)
4253 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
) - this_one
);
4257 /* Compute new positions. */
4258 last_top
= XINT (w
->top_line
);
4259 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
4261 c
= XWINDOW (child
);
4262 c
->top_line
= make_number (last_top
);
4263 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
));
4264 last_top
+= XFASTINT (c
->total_lines
);
4270 /* Save, restore, or check positions and sizes in the window tree
4271 rooted at W. ACTION says what to do.
4273 If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and
4274 orig_total_lines members are valid for all windows in the window
4275 tree. Value is non-zero if they are valid.
4277 If ACTION is SAVE_ORIG_SIZES, save members top and height in
4278 orig_top_line and orig_total_lines for all windows in the tree.
4280 If ACTION is RESTORE_ORIG_SIZES, restore top and height from values
4281 stored in orig_top_line and orig_total_lines for all windows. */
4284 save_restore_orig_size (w
, action
)
4286 enum save_restore_action action
;
4292 if (!NILP (w
->hchild
))
4294 if (!save_restore_orig_size (XWINDOW (w
->hchild
), action
))
4297 else if (!NILP (w
->vchild
))
4299 if (!save_restore_orig_size (XWINDOW (w
->vchild
), action
))
4305 case CHECK_ORIG_SIZES
:
4306 if (!INTEGERP (w
->orig_top_line
) || !INTEGERP (w
->orig_total_lines
))
4310 case SAVE_ORIG_SIZES
:
4311 w
->orig_top_line
= w
->top_line
;
4312 w
->orig_total_lines
= w
->total_lines
;
4313 XSETFASTINT (w
->last_modified
, 0);
4314 XSETFASTINT (w
->last_overlay_modified
, 0);
4317 case RESTORE_ORIG_SIZES
:
4318 xassert (INTEGERP (w
->orig_top_line
) && INTEGERP (w
->orig_total_lines
));
4319 w
->top_line
= w
->orig_top_line
;
4320 w
->total_lines
= w
->orig_total_lines
;
4321 w
->orig_total_lines
= w
->orig_top_line
= Qnil
;
4322 XSETFASTINT (w
->last_modified
, 0);
4323 XSETFASTINT (w
->last_overlay_modified
, 0);
4330 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
4337 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
4338 without deleting other windows. */
4341 grow_mini_window (w
, delta
)
4345 struct frame
*f
= XFRAME (w
->frame
);
4346 struct window
*root
;
4348 xassert (MINI_WINDOW_P (w
));
4349 xassert (delta
>= 0);
4351 /* Check values of window_min_width and window_min_height for
4353 check_min_window_sizes ();
4355 /* Compute how much we can enlarge the mini-window without deleting
4357 root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4360 int min_height
= window_min_size (root
, 0, 0, 0);
4361 if (XFASTINT (root
->total_lines
) - delta
< min_height
)
4362 /* Note that the root window may already be smaller than
4364 delta
= max (0, XFASTINT (root
->total_lines
) - min_height
);
4369 /* Save original window sizes and positions, if not already done. */
4370 if (!save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4371 save_restore_orig_size (root
, SAVE_ORIG_SIZES
);
4373 /* Shrink other windows. */
4374 shrink_window_lowest_first (root
, XFASTINT (root
->total_lines
) - delta
);
4376 /* Grow the mini-window. */
4377 w
->top_line
= make_number (XFASTINT (root
->top_line
) + XFASTINT (root
->total_lines
));
4378 w
->total_lines
= make_number (XFASTINT (w
->total_lines
) + delta
);
4379 XSETFASTINT (w
->last_modified
, 0);
4380 XSETFASTINT (w
->last_overlay_modified
, 0);
4387 /* Shrink mini-window W. If there is recorded info about window sizes
4388 before a call to grow_mini_window, restore recorded window sizes.
4389 Otherwise, if the mini-window is higher than 1 line, resize it to 1
4393 shrink_mini_window (w
)
4396 struct frame
*f
= XFRAME (w
->frame
);
4397 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4399 if (save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4401 save_restore_orig_size (root
, RESTORE_ORIG_SIZES
);
4403 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4404 windows_or_buffers_changed
= 1;
4406 else if (XFASTINT (w
->total_lines
) > 1)
4408 /* Distribute the additional lines of the mini-window
4409 among the other windows. */
4411 XSETWINDOW (window
, w
);
4412 enlarge_window (window
, 1 - XFASTINT (w
->total_lines
), 0, 0);
4418 /* Mark window cursors off for all windows in the window tree rooted
4419 at W by setting their phys_cursor_on_p flag to zero. Called from
4420 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4421 the frame are cleared. */
4424 mark_window_cursors_off (w
)
4429 if (!NILP (w
->hchild
))
4430 mark_window_cursors_off (XWINDOW (w
->hchild
));
4431 else if (!NILP (w
->vchild
))
4432 mark_window_cursors_off (XWINDOW (w
->vchild
));
4434 w
->phys_cursor_on_p
= 0;
4436 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4441 /* Return number of lines of text (not counting mode lines) in W. */
4444 window_internal_height (w
)
4447 int ht
= XFASTINT (w
->total_lines
);
4449 if (!MINI_WINDOW_P (w
))
4451 if (!NILP (w
->parent
)
4452 || !NILP (w
->vchild
)
4453 || !NILP (w
->hchild
)
4456 || WINDOW_WANTS_MODELINE_P (w
))
4459 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4467 /* Return the number of columns in W.
4468 Don't count columns occupied by scroll bars or the vertical bar
4469 separating W from the sibling to its right. */
4472 window_box_text_cols (w
)
4475 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4476 int width
= XINT (w
->total_cols
);
4478 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
4479 /* Scroll bars occupy a few columns. */
4480 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
4481 else if (!FRAME_WINDOW_P (f
)
4482 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
4483 /* The column of `|' characters separating side-by-side windows
4484 occupies one column only. */
4487 if (FRAME_WINDOW_P (f
))
4488 /* On window-systems, fringes and display margins cannot be
4489 used for normal text. */
4490 width
-= (WINDOW_FRINGE_COLS (w
)
4491 + WINDOW_LEFT_MARGIN_COLS (w
)
4492 + WINDOW_RIGHT_MARGIN_COLS (w
));
4498 /************************************************************************
4500 ***********************************************************************/
4502 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4503 N screen-fulls, which is defined as the height of the window minus
4504 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4505 instead. Negative values of N mean scroll down. NOERROR non-zero
4506 means don't signal an error if we try to move over BEGV or ZV,
4510 window_scroll (window
, n
, whole
, noerror
)
4518 /* If we must, use the pixel-based version which is much slower than
4519 the line-based one but can handle varying line heights. */
4520 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4521 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4523 window_scroll_line_based (window
, n
, whole
, noerror
);
4529 /* Implementation of window_scroll that works based on pixel line
4530 heights. See the comment of window_scroll for parameter
4534 window_scroll_pixel_based (window
, n
, whole
, noerror
)
4541 struct window
*w
= XWINDOW (window
);
4542 struct text_pos start
;
4544 int this_scroll_margin
;
4546 /* True if we fiddled the window vscroll field without really scrolling. */
4549 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4551 /* If PT is not visible in WINDOW, move back one half of
4552 the screen. Allow PT to be partially visible, otherwise
4553 something like (scroll-down 1) with PT in the line before
4554 the partially visible one would recenter. */
4555 tem
= Fpos_visible_in_window_p (make_number (PT
), window
, Qt
);
4558 /* Move backward half the height of the window. Performance note:
4559 vmotion used here is about 10% faster, but would give wrong
4560 results for variable height lines. */
4561 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4562 it
.current_y
= it
.last_visible_y
;
4563 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4565 /* The function move_iterator_vertically may move over more than
4566 the specified y-distance. If it->w is small, e.g. a
4567 mini-buffer window, we may end up in front of the window's
4568 display area. This is the case when Start displaying at the
4569 start of the line containing PT in this case. */
4570 if (it
.current_y
<= 0)
4572 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4573 move_it_vertically_backward (&it
, 0);
4577 start
= it
.current
.pos
;
4579 else if (auto_window_vscroll_p
)
4581 if (NILP (XCAR (XCDR (XCDR (tem
)))))
4584 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4586 dy
= window_box_height (w
) - next_screen_context_lines
* dy
;
4589 if (n
< 0 && (px
= XINT (Fnth (make_number (3), tem
))) > 0)
4591 px
= max (0, -w
->vscroll
- min (px
, -dy
));
4592 Fset_window_vscroll (window
, make_number (px
), Qt
);
4595 if (n
> 0 && (px
= XINT (Fnth (make_number (4), tem
))) > 0)
4597 px
= max (0, -w
->vscroll
+ min (px
, dy
));
4598 Fset_window_vscroll (window
, make_number (px
), Qt
);
4602 Fset_window_vscroll (window
, make_number (0), Qt
);
4605 /* If scroll_preserve_screen_position is non-nil, we try to set
4606 point in the same window line as it is now, so get that line. */
4607 if (!NILP (Vscroll_preserve_screen_position
))
4609 start_display (&it
, w
, start
);
4610 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4611 preserve_y
= it
.current_y
;
4616 /* Move iterator it from start the specified distance forward or
4617 backward. The result is the new window start. */
4618 start_display (&it
, w
, start
);
4621 int screen_full
= (window_box_height (w
)
4622 - next_screen_context_lines
* FRAME_LINE_HEIGHT (it
.f
));
4623 int dy
= n
* screen_full
;
4625 /* Note that move_it_vertically always moves the iterator to the
4626 start of a line. So, if the last line doesn't have a newline,
4627 we would end up at the start of the line ending at ZV. */
4629 move_it_vertically_backward (&it
, -dy
);
4631 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4632 MOVE_TO_POS
| MOVE_TO_Y
);
4635 move_it_by_lines (&it
, n
, 1);
4637 /* We failed if we find ZV is already on the screen (scrolling up,
4638 means there's nothing past the end), or if we can't start any
4639 earlier (scrolling down, means there's nothing past the top). */
4640 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4641 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4643 if (IT_CHARPOS (it
) == ZV
)
4645 if (it
.current_y
< it
.last_visible_y
4646 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4647 >= it
.last_visible_y
))
4649 /* The last line was only partially visible, make it fully
4651 w
->vscroll
= (it
.last_visible_y
4652 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4653 adjust_glyphs (it
.f
);
4658 Fsignal (Qend_of_buffer
, Qnil
);
4662 if (w
->vscroll
!= 0)
4663 /* The first line was only partially visible, make it fully
4669 Fsignal (Qbeginning_of_buffer
, Qnil
);
4672 /* If control gets here, then we vscrolled. */
4674 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
4676 /* Don't try to change the window start below. */
4682 int pos
= IT_CHARPOS (it
);
4685 /* If in the middle of a multi-glyph character move forward to
4686 the next character. */
4687 if (in_display_vector_p (&it
))
4690 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
4693 /* Set the window start, and set up the window for redisplay. */
4694 set_marker_restricted (w
->start
, make_number (pos
),
4696 bytepos
= XMARKER (w
->start
)->bytepos
;
4697 w
->start_at_line_beg
= ((pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n')
4699 w
->update_mode_line
= Qt
;
4700 XSETFASTINT (w
->last_modified
, 0);
4701 XSETFASTINT (w
->last_overlay_modified
, 0);
4702 /* Set force_start so that redisplay_window will run the
4703 window-scroll-functions. */
4704 w
->force_start
= Qt
;
4707 /* The rest of this function uses current_y in a nonstandard way,
4708 not including the height of the header line if any. */
4709 it
.current_y
= it
.vpos
= 0;
4711 /* Move PT out of scroll margins.
4712 This code wants current_y to be zero at the window start position
4713 even if there is a header line. */
4714 this_scroll_margin
= max (0, scroll_margin
);
4715 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->total_lines
) / 4);
4716 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
4720 /* We moved the window start towards ZV, so PT may be now
4721 in the scroll margin at the top. */
4722 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4723 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
)
4724 /* We found PT at a legitimate height. Leave it alone. */
4726 else if (preserve_y
>= 0)
4728 /* If we have a header line, take account of it.
4729 This is necessary because we set it.current_y to 0, above. */
4730 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4731 preserve_y
-= CURRENT_HEADER_LINE_HEIGHT (w
);
4733 move_it_to (&it
, -1, -1, preserve_y
, -1, MOVE_TO_Y
);
4734 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4738 while (it
.current_y
< this_scroll_margin
)
4740 int prev
= it
.current_y
;
4741 move_it_by_lines (&it
, 1, 1);
4742 if (prev
== it
.current_y
)
4745 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4750 int charpos
, bytepos
;
4752 /* Save our position, for the preserve_y case. */
4753 charpos
= IT_CHARPOS (it
);
4754 bytepos
= IT_BYTEPOS (it
);
4756 /* We moved the window start towards BEGV, so PT may be now
4757 in the scroll margin at the bottom. */
4758 move_it_to (&it
, PT
, -1,
4759 it
.last_visible_y
- this_scroll_margin
- 1, -1,
4760 MOVE_TO_POS
| MOVE_TO_Y
);
4762 if (IT_CHARPOS (it
) == PT
)
4763 /* We found PT before we found the display margin, so PT is ok. */
4765 else if (preserve_y
>= 0)
4767 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4768 start_display (&it
, w
, start
);
4769 #if 0 /* It's wrong to subtract this here
4770 because we called start_display again
4771 and did not alter it.current_y this time. */
4773 /* If we have a header line, take account of it. */
4774 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4775 preserve_y
-= CURRENT_HEADER_LINE_HEIGHT (w
);
4778 move_it_to (&it
, -1, -1, preserve_y
, -1, MOVE_TO_Y
);
4779 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4783 /* Save our position, in case it's correct. */
4784 charpos
= IT_CHARPOS (it
);
4785 bytepos
= IT_BYTEPOS (it
);
4787 /* See if point is on a partially visible line at the end. */
4788 move_it_by_lines (&it
, 1, 1);
4790 if (it
.current_y
> it
.last_visible_y
)
4791 /* The last line was only partially visible, so back up two
4792 lines to make sure we're on a fully visible line. */
4794 move_it_by_lines (&it
, -2, 0);
4795 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4798 /* No, the position we saved is OK, so use it. */
4799 SET_PT_BOTH (charpos
, bytepos
);
4805 /* Implementation of window_scroll that works based on screen lines.
4806 See the comment of window_scroll for parameter descriptions. */
4809 window_scroll_line_based (window
, n
, whole
, noerror
)
4815 register struct window
*w
= XWINDOW (window
);
4816 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
4817 register int pos
, pos_byte
;
4818 register int ht
= window_internal_height (w
);
4819 register Lisp_Object tem
;
4823 struct position posit
;
4826 /* If scrolling screen-fulls, compute the number of lines to
4827 scroll from the window's height. */
4829 n
*= max (1, ht
- next_screen_context_lines
);
4831 startpos
= marker_position (w
->start
);
4833 posit
= *compute_motion (startpos
, 0, 0, 0,
4835 -1, XINT (w
->hscroll
),
4837 original_vpos
= posit
.vpos
;
4839 XSETFASTINT (tem
, PT
);
4840 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
4844 Fvertical_motion (make_number (- (ht
/ 2)), window
);
4849 lose
= n
< 0 && PT
== BEGV
;
4850 Fvertical_motion (make_number (n
), window
);
4854 SET_PT_BOTH (opoint
, opoint_byte
);
4861 Fsignal (Qbeginning_of_buffer
, Qnil
);
4866 int this_scroll_margin
= scroll_margin
;
4868 /* Don't use a scroll margin that is negative or too large. */
4869 if (this_scroll_margin
< 0)
4870 this_scroll_margin
= 0;
4872 if (XINT (w
->total_lines
) < 4 * scroll_margin
)
4873 this_scroll_margin
= XINT (w
->total_lines
) / 4;
4875 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
4876 w
->start_at_line_beg
= bolp
;
4877 w
->update_mode_line
= Qt
;
4878 XSETFASTINT (w
->last_modified
, 0);
4879 XSETFASTINT (w
->last_overlay_modified
, 0);
4880 /* Set force_start so that redisplay_window will run
4881 the window-scroll-functions. */
4882 w
->force_start
= Qt
;
4884 if (whole
&& !NILP (Vscroll_preserve_screen_position
))
4886 SET_PT_BOTH (pos
, pos_byte
);
4887 Fvertical_motion (make_number (original_vpos
), window
);
4889 /* If we scrolled forward, put point enough lines down
4890 that it is outside the scroll margin. */
4895 if (this_scroll_margin
> 0)
4897 SET_PT_BOTH (pos
, pos_byte
);
4898 Fvertical_motion (make_number (this_scroll_margin
), window
);
4904 if (top_margin
<= opoint
)
4905 SET_PT_BOTH (opoint
, opoint_byte
);
4906 else if (!NILP (Vscroll_preserve_screen_position
))
4908 SET_PT_BOTH (pos
, pos_byte
);
4909 Fvertical_motion (make_number (original_vpos
), window
);
4912 SET_PT (top_margin
);
4918 /* If we scrolled backward, put point near the end of the window
4919 but not within the scroll margin. */
4920 SET_PT_BOTH (pos
, pos_byte
);
4921 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
4922 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
4925 bottom_margin
= PT
+ 1;
4927 if (bottom_margin
> opoint
)
4928 SET_PT_BOTH (opoint
, opoint_byte
);
4931 if (!NILP (Vscroll_preserve_screen_position
))
4933 SET_PT_BOTH (pos
, pos_byte
);
4934 Fvertical_motion (make_number (original_vpos
), window
);
4937 Fvertical_motion (make_number (-1), window
);
4946 Fsignal (Qend_of_buffer
, Qnil
);
4951 /* Scroll selected_window up or down. If N is nil, scroll a
4952 screen-full which is defined as the height of the window minus
4953 next_screen_context_lines. If N is the symbol `-', scroll.
4954 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4955 up. This is the guts of Fscroll_up and Fscroll_down. */
4958 scroll_command (n
, direction
)
4962 int count
= SPECPDL_INDEX ();
4964 xassert (abs (direction
) == 1);
4966 /* If selected window's buffer isn't current, make it current for
4967 the moment. But don't screw up if window_scroll gets an error. */
4968 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
4970 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4971 Fset_buffer (XWINDOW (selected_window
)->buffer
);
4973 /* Make redisplay consider other windows than just selected_window. */
4974 ++windows_or_buffers_changed
;
4978 window_scroll (selected_window
, direction
, 1, 0);
4979 else if (EQ (n
, Qminus
))
4980 window_scroll (selected_window
, -direction
, 1, 0);
4983 n
= Fprefix_numeric_value (n
);
4984 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
4987 unbind_to (count
, Qnil
);
4990 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
4991 doc
: /* Scroll text of current window upward ARG lines.
4992 If ARG is omitted or nil, scroll upward by a near full screen.
4993 A near full screen is `next-screen-context-lines' less than a full screen.
4994 Negative ARG means scroll downward.
4995 If ARG is the atom `-', scroll downward by nearly full screen.
4996 When calling from a program, supply as argument a number, nil, or `-'. */)
5000 scroll_command (arg
, 1);
5004 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
5005 doc
: /* Scroll text of current window down ARG lines.
5006 If ARG is omitted or nil, scroll down by a near full screen.
5007 A near full screen is `next-screen-context-lines' less than a full screen.
5008 Negative ARG means scroll upward.
5009 If ARG is the atom `-', scroll upward by nearly full screen.
5010 When calling from a program, supply as argument a number, nil, or `-'. */)
5014 scroll_command (arg
, -1);
5018 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
5019 doc
: /* Return the other window for \"other window scroll\" commands.
5020 If `other-window-scroll-buffer' is non-nil, a window
5021 showing that buffer is used.
5022 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5023 specifies the window. This takes precedence over
5024 `other-window-scroll-buffer'. */)
5029 if (MINI_WINDOW_P (XWINDOW (selected_window
))
5030 && !NILP (Vminibuf_scroll_window
))
5031 window
= Vminibuf_scroll_window
;
5032 /* If buffer is specified, scroll that buffer. */
5033 else if (!NILP (Vother_window_scroll_buffer
))
5035 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
5037 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
5041 /* Nothing specified; look for a neighboring window on the same
5043 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
5045 if (EQ (window
, selected_window
))
5046 /* That didn't get us anywhere; look for a window on another
5049 window
= Fnext_window (window
, Qnil
, Qt
);
5050 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
5051 && ! EQ (window
, selected_window
));
5054 CHECK_LIVE_WINDOW (window
);
5056 if (EQ (window
, selected_window
))
5057 error ("There is no other window");
5062 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
5063 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5064 A near full screen is `next-screen-context-lines' less than a full screen.
5065 The next window is the one below the current one; or the one at the top
5066 if the current one is at the bottom. Negative ARG means scroll downward.
5067 If ARG is the atom `-', scroll downward by nearly full screen.
5068 When calling from a program, supply as argument a number, nil, or `-'.
5070 If `other-window-scroll-buffer' is non-nil, scroll the window
5071 showing that buffer, popping the buffer up if necessary.
5072 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5073 specifies the window to scroll. This takes precedence over
5074 `other-window-scroll-buffer'. */)
5080 int count
= SPECPDL_INDEX ();
5082 window
= Fother_window_for_scrolling ();
5083 w
= XWINDOW (window
);
5085 /* Don't screw up if window_scroll gets an error. */
5086 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5087 ++windows_or_buffers_changed
;
5089 Fset_buffer (w
->buffer
);
5090 SET_PT (marker_position (w
->pointm
));
5093 window_scroll (window
, 1, 1, 1);
5094 else if (EQ (arg
, Qminus
))
5095 window_scroll (window
, -1, 1, 1);
5101 window_scroll (window
, XINT (arg
), 0, 1);
5104 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5105 unbind_to (count
, Qnil
);
5110 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "P\np",
5111 doc
: /* Scroll selected window display ARG columns left.
5112 Default for ARG is window width minus 2.
5113 Value is the total amount of leftward horizontal scrolling in
5114 effect after the change.
5115 If SET_MINIMUM is non-nil, the new scroll amount becomes the
5116 lower bound for automatic scrolling, i.e. automatic scrolling
5117 will not scroll a window to a column less than the value returned
5118 by this function. This happens in an interactive call. */)
5120 register Lisp_Object arg
, set_minimum
;
5124 struct window
*w
= XWINDOW (selected_window
);
5127 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5129 arg
= Fprefix_numeric_value (arg
);
5131 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
5132 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5134 if (!NILP (set_minimum
))
5135 w
->min_hscroll
= w
->hscroll
;
5140 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "P\np",
5141 doc
: /* Scroll selected window display ARG columns right.
5142 Default for ARG is window width minus 2.
5143 Value is the total amount of leftward horizontal scrolling in
5144 effect after the change.
5145 If SET_MINIMUM is non-nil, the new scroll amount becomes the
5146 lower bound for automatic scrolling, i.e. automatic scrolling
5147 will not scroll a window to a column less than the value returned
5148 by this function. This happens in an interactive call. */)
5150 register Lisp_Object arg
, set_minimum
;
5154 struct window
*w
= XWINDOW (selected_window
);
5157 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5159 arg
= Fprefix_numeric_value (arg
);
5161 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
5162 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5164 if (!NILP (set_minimum
))
5165 w
->min_hscroll
= w
->hscroll
;
5170 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5171 doc
: /* Return the window which was selected when entering the minibuffer.
5172 Returns nil, if current window is not a minibuffer window. */)
5175 if (minibuf_level
> 0
5176 && MINI_WINDOW_P (XWINDOW (selected_window
))
5177 && WINDOW_LIVE_P (minibuf_selected_window
))
5178 return minibuf_selected_window
;
5183 /* Value is the number of lines actually displayed in window W,
5184 as opposed to its height. */
5187 displayed_window_lines (w
)
5191 struct text_pos start
;
5192 int height
= window_box_height (w
);
5193 struct buffer
*old_buffer
;
5196 if (XBUFFER (w
->buffer
) != current_buffer
)
5198 old_buffer
= current_buffer
;
5199 set_buffer_internal (XBUFFER (w
->buffer
));
5204 /* In case W->start is out of the accessible range, do something
5205 reasonable. This happens in Info mode when Info-scroll-down
5206 calls (recenter -1) while W->start is 1. */
5207 if (XMARKER (w
->start
)->charpos
< BEGV
)
5208 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5209 else if (XMARKER (w
->start
)->charpos
> ZV
)
5210 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
5212 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5214 start_display (&it
, w
, start
);
5215 move_it_vertically (&it
, height
);
5216 bottom_y
= line_bottom_y (&it
);
5218 /* rms: On a non-window display,
5219 the value of it.vpos at the bottom of the screen
5220 seems to be 1 larger than window_box_height (w).
5221 This kludge fixes a bug whereby (move-to-window-line -1)
5222 when ZV is on the last screen line
5223 moves to the previous screen line instead of the last one. */
5224 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5227 /* Add in empty lines at the bottom of the window. */
5228 if (bottom_y
< height
)
5230 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5231 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5235 set_buffer_internal (old_buffer
);
5241 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5242 doc
: /* Center point in window and redisplay frame.
5243 With prefix argument ARG, recenter putting point on screen line ARG
5244 relative to the current window. If ARG is negative, it counts up from the
5245 bottom of the window. (ARG should be less than the height of the window.)
5247 If ARG is omitted or nil, erase the entire frame and then
5248 redraw with point in the center of the current window.
5249 Just C-u as prefix means put point in the center of the window
5250 and redisplay normally--don't erase and redraw the frame. */)
5252 register Lisp_Object arg
;
5254 struct window
*w
= XWINDOW (selected_window
);
5255 struct buffer
*buf
= XBUFFER (w
->buffer
);
5256 struct buffer
*obuf
= current_buffer
;
5258 int charpos
, bytepos
;
5260 /* If redisplay is suppressed due to an error, try again. */
5261 obuf
->display_error_modiff
= 0;
5267 /* Invalidate pixel data calculated for all compositions. */
5268 for (i
= 0; i
< n_compositions
; i
++)
5269 composition_table
[i
]->font
= NULL
;
5271 Fredraw_frame (w
->frame
);
5272 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
5275 else if (CONSP (arg
)) /* Just C-u. */
5279 arg
= Fprefix_numeric_value (arg
);
5283 set_buffer_internal (buf
);
5285 /* Handle centering on a graphical frame specially. Such frames can
5286 have variable-height lines and centering point on the basis of
5287 line counts would lead to strange effects. */
5288 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5295 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5296 start_display (&it
, w
, pt
);
5297 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5298 charpos
= IT_CHARPOS (it
);
5299 bytepos
= IT_BYTEPOS (it
);
5301 else if (XINT (arg
) < 0)
5305 int nlines
= - XINT (arg
);
5306 int extra_line_spacing
;
5307 int h
= window_box_height (w
);
5309 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5310 start_display (&it
, w
, pt
);
5312 /* Be sure we have the exact height of the full line containing PT. */
5313 move_it_by_lines (&it
, 0, 1);
5315 /* The amount of pixels we have to move back is the window
5316 height minus what's displayed in the line containing PT,
5317 and the lines below. */
5320 move_it_by_lines (&it
, nlines
, 1);
5322 if (it
.vpos
== nlines
)
5326 /* Last line has no newline */
5327 h
-= line_bottom_y (&it
);
5331 /* Don't reserve space for extra line spacing of last line. */
5332 extra_line_spacing
= it
.max_extra_line_spacing
;
5334 /* If we can't move down NLINES lines because we hit
5335 the end of the buffer, count in some empty lines. */
5336 if (it
.vpos
< nlines
)
5339 extra_line_spacing
= it
.extra_line_spacing
;
5340 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5345 /* Now find the new top line (starting position) of the window. */
5346 start_display (&it
, w
, pt
);
5348 move_it_vertically_backward (&it
, h
);
5350 /* If extra line spacing is present, we may move too far
5351 back. This causes the last line to be only partially
5352 visible (which triggers redisplay to recenter that line
5353 in the middle), so move forward.
5354 But ignore extra line spacing on last line, as it is not
5355 considered to be part of the visible height of the line.
5357 h
+= extra_line_spacing
;
5358 while (-it
.current_y
> h
)
5359 move_it_by_lines (&it
, 1, 1);
5361 charpos
= IT_CHARPOS (it
);
5362 bytepos
= IT_BYTEPOS (it
);
5366 struct position pos
;
5367 pos
= *vmotion (PT
, - XINT (arg
), w
);
5368 charpos
= pos
.bufpos
;
5369 bytepos
= pos
.bytepos
;
5374 struct position pos
;
5375 int ht
= window_internal_height (w
);
5378 arg
= make_number (ht
/ 2);
5379 else if (XINT (arg
) < 0)
5380 arg
= make_number (XINT (arg
) + ht
);
5382 pos
= *vmotion (PT
, - XINT (arg
), w
);
5383 charpos
= pos
.bufpos
;
5384 bytepos
= pos
.bytepos
;
5387 /* Set the new window start. */
5388 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
5389 w
->window_end_valid
= Qnil
;
5391 w
->optional_new_start
= Qt
;
5393 if (bytepos
== BEGV_BYTE
|| FETCH_BYTE (bytepos
- 1) == '\n')
5394 w
->start_at_line_beg
= Qt
;
5396 w
->start_at_line_beg
= Qnil
;
5398 set_buffer_internal (obuf
);
5403 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5405 doc
: /* Return the height in lines of the text display area of WINDOW.
5406 This doesn't include the mode-line (or header-line if any) or any
5407 partial-height lines in the text display area. */)
5411 struct window
*w
= decode_window (window
);
5412 int pixel_height
= window_box_height (w
);
5413 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5414 return make_number (line_height
);
5419 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5421 doc
: /* Position point relative to window.
5422 With no argument, position point at center of window.
5423 An argument specifies vertical position within the window;
5424 zero means top of window, negative means relative to bottom of window. */)
5428 struct window
*w
= XWINDOW (selected_window
);
5432 window
= selected_window
;
5433 start
= marker_position (w
->start
);
5434 if (start
< BEGV
|| start
> ZV
)
5436 int height
= window_internal_height (w
);
5437 Fvertical_motion (make_number (- (height
/ 2)), window
);
5438 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
5439 w
->start_at_line_beg
= Fbolp ();
5440 w
->force_start
= Qt
;
5443 Fgoto_char (w
->start
);
5445 lines
= displayed_window_lines (w
);
5447 XSETFASTINT (arg
, lines
/ 2);
5450 arg
= Fprefix_numeric_value (arg
);
5452 XSETINT (arg
, XINT (arg
) + lines
);
5455 /* Skip past a partially visible first line. */
5457 XSETINT (arg
, XINT (arg
) + 1);
5459 return Fvertical_motion (arg
, window
);
5464 /***********************************************************************
5465 Window Configuration
5466 ***********************************************************************/
5468 struct save_window_data
5470 EMACS_INT size_from_Lisp_Vector_struct
;
5471 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5472 Lisp_Object frame_cols
, frame_lines
, frame_menu_bar_lines
;
5473 Lisp_Object frame_tool_bar_lines
;
5474 Lisp_Object selected_frame
;
5475 Lisp_Object current_window
;
5476 Lisp_Object current_buffer
;
5477 Lisp_Object minibuf_scroll_window
;
5478 Lisp_Object minibuf_selected_window
;
5479 Lisp_Object root_window
;
5480 Lisp_Object focus_frame
;
5481 /* Record the values of window-min-width and window-min-height
5482 so that window sizes remain consistent with them. */
5483 Lisp_Object min_width
, min_height
;
5484 /* A vector, each of whose elements is a struct saved_window
5486 Lisp_Object saved_windows
;
5489 /* This is saved as a Lisp_Vector */
5492 /* these first two must agree with struct Lisp_Vector in lisp.h */
5493 EMACS_INT size_from_Lisp_Vector_struct
;
5494 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5497 Lisp_Object buffer
, start
, pointm
, mark
;
5498 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5499 Lisp_Object hscroll
, min_hscroll
;
5500 Lisp_Object parent
, prev
;
5501 Lisp_Object start_at_line_beg
;
5502 Lisp_Object display_table
;
5503 Lisp_Object orig_top_line
, orig_total_lines
;
5504 Lisp_Object left_margin_cols
, right_margin_cols
;
5505 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
5506 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
;
5509 #define SAVED_WINDOW_VECTOR_SIZE 24 /* Arg to Fmake_vector */
5511 #define SAVED_WINDOW_N(swv,n) \
5512 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5514 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
5515 doc
: /* Return t if OBJECT is a window-configuration object. */)
5519 if (WINDOW_CONFIGURATIONP (object
))
5524 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
5525 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5529 register struct save_window_data
*data
;
5530 struct Lisp_Vector
*saved_windows
;
5532 if (! WINDOW_CONFIGURATIONP (config
))
5533 wrong_type_argument (Qwindow_configuration_p
, config
);
5535 data
= (struct save_window_data
*) XVECTOR (config
);
5536 saved_windows
= XVECTOR (data
->saved_windows
);
5537 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5540 DEFUN ("set-window-configuration", Fset_window_configuration
,
5541 Sset_window_configuration
, 1, 1, 0,
5542 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5543 CONFIGURATION must be a value previously returned
5544 by `current-window-configuration' (which see).
5545 If CONFIGURATION was made from a frame that is now deleted,
5546 only frame-independent values can be restored. In this case,
5547 the return value is nil. Otherwise the value is t. */)
5549 Lisp_Object configuration
;
5551 register struct save_window_data
*data
;
5552 struct Lisp_Vector
*saved_windows
;
5553 Lisp_Object new_current_buffer
;
5558 while (!WINDOW_CONFIGURATIONP (configuration
))
5559 wrong_type_argument (Qwindow_configuration_p
, configuration
);
5561 data
= (struct save_window_data
*) XVECTOR (configuration
);
5562 saved_windows
= XVECTOR (data
->saved_windows
);
5564 new_current_buffer
= data
->current_buffer
;
5565 if (NILP (XBUFFER (new_current_buffer
)->name
))
5566 new_current_buffer
= Qnil
;
5569 if (XBUFFER (new_current_buffer
) == current_buffer
)
5572 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
5575 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5578 /* If f is a dead frame, don't bother rebuilding its window tree.
5579 However, there is other stuff we should still try to do below. */
5580 if (FRAME_LIVE_P (f
))
5582 register struct window
*w
;
5583 register struct saved_window
*p
;
5584 struct window
*root_window
;
5585 struct window
**leaf_windows
;
5589 /* If the frame has been resized since this window configuration was
5590 made, we change the frame to the size specified in the
5591 configuration, restore the configuration, and then resize it
5592 back. We keep track of the prevailing height in these variables. */
5593 int previous_frame_lines
= FRAME_LINES (f
);
5594 int previous_frame_cols
= FRAME_COLS (f
);
5595 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
5596 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
5598 /* The mouse highlighting code could get screwed up
5599 if it runs during this. */
5602 if (XFASTINT (data
->frame_lines
) != previous_frame_lines
5603 || XFASTINT (data
->frame_cols
) != previous_frame_cols
)
5604 change_frame_size (f
, XFASTINT (data
->frame_lines
),
5605 XFASTINT (data
->frame_cols
), 0, 0, 0);
5606 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5607 if (XFASTINT (data
->frame_menu_bar_lines
)
5608 != previous_frame_menu_bar_lines
)
5609 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, make_number (0));
5610 #ifdef HAVE_WINDOW_SYSTEM
5611 if (XFASTINT (data
->frame_tool_bar_lines
)
5612 != previous_frame_tool_bar_lines
)
5613 x_set_tool_bar_lines (f
, data
->frame_tool_bar_lines
, make_number (0));
5617 /* "Swap out" point from the selected window
5618 into its buffer. We do this now, before
5619 restoring the window contents, and prevent it from
5620 being done later on when we select a new window. */
5621 if (! NILP (XWINDOW (selected_window
)->buffer
))
5623 w
= XWINDOW (selected_window
);
5624 set_marker_both (w
->pointm
,
5626 BUF_PT (XBUFFER (w
->buffer
)),
5627 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5630 windows_or_buffers_changed
++;
5631 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
5633 /* Problem: Freeing all matrices and later allocating them again
5634 is a serious redisplay flickering problem. What we would
5635 really like to do is to free only those matrices not reused
5637 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5639 = (struct window
**) alloca (count_windows (root_window
)
5640 * sizeof (struct window
*));
5641 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
5643 /* Temporarily avoid any problems with windows that are smaller
5644 than they are supposed to be. */
5645 window_min_height
= 1;
5646 window_min_width
= 1;
5649 Mark all windows now on frame as "deleted".
5650 Restoring the new configuration "undeletes" any that are in it.
5652 Save their current buffers in their height fields, since we may
5653 need it later, if a buffer saved in the configuration is now
5655 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5657 for (k
= 0; k
< saved_windows
->size
; k
++)
5659 p
= SAVED_WINDOW_N (saved_windows
, k
);
5660 w
= XWINDOW (p
->window
);
5663 if (!NILP (p
->parent
))
5664 w
->parent
= SAVED_WINDOW_N (saved_windows
,
5665 XFASTINT (p
->parent
))->window
;
5669 if (!NILP (p
->prev
))
5671 w
->prev
= SAVED_WINDOW_N (saved_windows
,
5672 XFASTINT (p
->prev
))->window
;
5673 XWINDOW (w
->prev
)->next
= p
->window
;
5678 if (!NILP (w
->parent
))
5680 if (EQ (p
->total_cols
, XWINDOW (w
->parent
)->total_cols
))
5682 XWINDOW (w
->parent
)->vchild
= p
->window
;
5683 XWINDOW (w
->parent
)->hchild
= Qnil
;
5687 XWINDOW (w
->parent
)->hchild
= p
->window
;
5688 XWINDOW (w
->parent
)->vchild
= Qnil
;
5693 /* If we squirreled away the buffer in the window's height,
5695 if (BUFFERP (w
->total_lines
))
5696 w
->buffer
= w
->total_lines
;
5697 w
->left_col
= p
->left_col
;
5698 w
->top_line
= p
->top_line
;
5699 w
->total_cols
= p
->total_cols
;
5700 w
->total_lines
= p
->total_lines
;
5701 w
->hscroll
= p
->hscroll
;
5702 w
->min_hscroll
= p
->min_hscroll
;
5703 w
->display_table
= p
->display_table
;
5704 w
->orig_top_line
= p
->orig_top_line
;
5705 w
->orig_total_lines
= p
->orig_total_lines
;
5706 w
->left_margin_cols
= p
->left_margin_cols
;
5707 w
->right_margin_cols
= p
->right_margin_cols
;
5708 w
->left_fringe_width
= p
->left_fringe_width
;
5709 w
->right_fringe_width
= p
->right_fringe_width
;
5710 w
->fringes_outside_margins
= p
->fringes_outside_margins
;
5711 w
->scroll_bar_width
= p
->scroll_bar_width
;
5712 w
->vertical_scroll_bar_type
= p
->vertical_scroll_bar_type
;
5713 XSETFASTINT (w
->last_modified
, 0);
5714 XSETFASTINT (w
->last_overlay_modified
, 0);
5716 /* Reinstall the saved buffer and pointers into it. */
5717 if (NILP (p
->buffer
))
5718 w
->buffer
= p
->buffer
;
5721 if (!NILP (XBUFFER (p
->buffer
)->name
))
5722 /* If saved buffer is alive, install it. */
5724 w
->buffer
= p
->buffer
;
5725 w
->start_at_line_beg
= p
->start_at_line_beg
;
5726 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
5727 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
5728 Fset_marker (XBUFFER (w
->buffer
)->mark
,
5729 p
->mark
, w
->buffer
);
5731 /* As documented in Fcurrent_window_configuration, don't
5732 restore the location of point in the buffer which was
5733 current when the window configuration was recorded. */
5734 if (!EQ (p
->buffer
, new_current_buffer
)
5735 && XBUFFER (p
->buffer
) == current_buffer
)
5736 Fgoto_char (w
->pointm
);
5738 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
5739 /* Else unless window has a live buffer, get one. */
5741 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
5742 /* This will set the markers to beginning of visible
5744 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
5745 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
5746 w
->start_at_line_beg
= Qt
;
5749 /* Keeping window's old buffer; make sure the markers
5752 /* Set window markers at start of visible range. */
5753 if (XMARKER (w
->start
)->buffer
== 0)
5754 set_marker_restricted (w
->start
, make_number (0),
5756 if (XMARKER (w
->pointm
)->buffer
== 0)
5757 set_marker_restricted_both (w
->pointm
, w
->buffer
,
5758 BUF_PT (XBUFFER (w
->buffer
)),
5759 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5760 w
->start_at_line_beg
= Qt
;
5765 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
5766 /* Prevent "swapping out point" in the old selected window
5767 using the buffer that has been restored into it.
5768 Use the point value from the beginning of this function
5769 since unshow_buffer (called from delete_all_subwindows)
5770 could have altered it. */
5771 selected_window
= Qnil
;
5772 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
5773 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
5774 make_number (old_point
),
5775 XWINDOW (data
->current_window
)->buffer
);
5777 Fselect_window (data
->current_window
, Qnil
);
5778 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
5781 if (NILP (data
->focus_frame
)
5782 || (FRAMEP (data
->focus_frame
)
5783 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
5784 Fredirect_frame_focus (frame
, data
->focus_frame
);
5786 #if 0 /* I don't understand why this is needed, and it causes problems
5787 when the frame's old selected window has been deleted. */
5788 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
5789 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
5793 /* Set the screen height to the value it had before this function. */
5794 if (previous_frame_lines
!= FRAME_LINES (f
)
5795 || previous_frame_cols
!= FRAME_COLS (f
))
5796 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
5798 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5799 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
5800 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
5802 #ifdef HAVE_WINDOW_SYSTEM
5803 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
5804 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
5809 /* Now, free glyph matrices in windows that were not reused. */
5810 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
5812 if (NILP (leaf_windows
[i
]->buffer
))
5814 /* Assert it's not reused as a combination. */
5815 xassert (NILP (leaf_windows
[i
]->hchild
)
5816 && NILP (leaf_windows
[i
]->vchild
));
5817 free_window_matrices (leaf_windows
[i
]);
5819 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
5827 /* Fselect_window will have made f the selected frame, so we
5828 reselect the proper frame here. Fhandle_switch_frame will change the
5829 selected window too, but that doesn't make the call to
5830 Fselect_window above totally superfluous; it still sets f's
5832 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
5833 do_switch_frame (data
->selected_frame
, 0, 0);
5835 if (! NILP (Vwindow_configuration_change_hook
)
5836 && ! NILP (Vrun_hooks
))
5837 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
5840 if (!NILP (new_current_buffer
))
5841 Fset_buffer (new_current_buffer
);
5843 /* Restore the minimum heights recorded in the configuration. */
5844 window_min_height
= XINT (data
->min_height
);
5845 window_min_width
= XINT (data
->min_width
);
5847 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
5848 minibuf_selected_window
= data
->minibuf_selected_window
;
5850 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
5853 /* Mark all windows now on frame as deleted
5854 by setting their buffers to nil. */
5857 delete_all_subwindows (w
)
5858 register struct window
*w
;
5860 if (!NILP (w
->next
))
5861 delete_all_subwindows (XWINDOW (w
->next
));
5862 if (!NILP (w
->vchild
))
5863 delete_all_subwindows (XWINDOW (w
->vchild
));
5864 if (!NILP (w
->hchild
))
5865 delete_all_subwindows (XWINDOW (w
->hchild
));
5867 w
->total_lines
= w
->buffer
; /* See Fset_window_configuration for excuse. */
5869 if (!NILP (w
->buffer
))
5872 /* We set all three of these fields to nil, to make sure that we can
5873 distinguish this dead window from any live window. Live leaf
5874 windows will have buffer set, and combination windows will have
5875 vchild or hchild set. */
5880 Vwindow_list
= Qnil
;
5884 count_windows (window
)
5885 register struct window
*window
;
5887 register int count
= 1;
5888 if (!NILP (window
->next
))
5889 count
+= count_windows (XWINDOW (window
->next
));
5890 if (!NILP (window
->vchild
))
5891 count
+= count_windows (XWINDOW (window
->vchild
));
5892 if (!NILP (window
->hchild
))
5893 count
+= count_windows (XWINDOW (window
->hchild
));
5898 /* Fill vector FLAT with leaf windows under W, starting at index I.
5899 Value is last index + 1. */
5902 get_leaf_windows (w
, flat
, i
)
5904 struct window
**flat
;
5909 if (!NILP (w
->hchild
))
5910 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
5911 else if (!NILP (w
->vchild
))
5912 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
5916 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5923 /* Return a pointer to the glyph W's physical cursor is on. Value is
5924 null if W's current matrix is invalid, so that no meaningfull glyph
5928 get_phys_cursor_glyph (w
)
5931 struct glyph_row
*row
;
5932 struct glyph
*glyph
;
5934 if (w
->phys_cursor
.vpos
>= 0
5935 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
5936 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
5938 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
5939 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
5948 save_window_save (window
, vector
, i
)
5950 struct Lisp_Vector
*vector
;
5953 register struct saved_window
*p
;
5954 register struct window
*w
;
5955 register Lisp_Object tem
;
5957 for (;!NILP (window
); window
= w
->next
)
5959 p
= SAVED_WINDOW_N (vector
, i
);
5960 w
= XWINDOW (window
);
5962 XSETFASTINT (w
->temslot
, i
); i
++;
5964 p
->buffer
= w
->buffer
;
5965 p
->left_col
= w
->left_col
;
5966 p
->top_line
= w
->top_line
;
5967 p
->total_cols
= w
->total_cols
;
5968 p
->total_lines
= w
->total_lines
;
5969 p
->hscroll
= w
->hscroll
;
5970 p
->min_hscroll
= w
->min_hscroll
;
5971 p
->display_table
= w
->display_table
;
5972 p
->orig_top_line
= w
->orig_top_line
;
5973 p
->orig_total_lines
= w
->orig_total_lines
;
5974 p
->left_margin_cols
= w
->left_margin_cols
;
5975 p
->right_margin_cols
= w
->right_margin_cols
;
5976 p
->left_fringe_width
= w
->left_fringe_width
;
5977 p
->right_fringe_width
= w
->right_fringe_width
;
5978 p
->fringes_outside_margins
= w
->fringes_outside_margins
;
5979 p
->scroll_bar_width
= w
->scroll_bar_width
;
5980 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
5981 if (!NILP (w
->buffer
))
5983 /* Save w's value of point in the window configuration.
5984 If w is the selected window, then get the value of point
5985 from the buffer; pointm is garbage in the selected window. */
5986 if (EQ (window
, selected_window
))
5988 p
->pointm
= Fmake_marker ();
5989 set_marker_both (p
->pointm
, w
->buffer
,
5990 BUF_PT (XBUFFER (w
->buffer
)),
5991 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5994 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
5996 p
->start
= Fcopy_marker (w
->start
, Qnil
);
5997 p
->start_at_line_beg
= w
->start_at_line_beg
;
5999 tem
= XBUFFER (w
->buffer
)->mark
;
6000 p
->mark
= Fcopy_marker (tem
, Qnil
);
6007 p
->start_at_line_beg
= Qnil
;
6010 if (NILP (w
->parent
))
6013 p
->parent
= XWINDOW (w
->parent
)->temslot
;
6018 p
->prev
= XWINDOW (w
->prev
)->temslot
;
6020 if (!NILP (w
->vchild
))
6021 i
= save_window_save (w
->vchild
, vector
, i
);
6022 if (!NILP (w
->hchild
))
6023 i
= save_window_save (w
->hchild
, vector
, i
);
6029 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
6030 Scurrent_window_configuration
, 0, 1, 0,
6031 doc
: /* Return an object representing the current window configuration of FRAME.
6032 If FRAME is nil or omitted, use the selected frame.
6033 This describes the number of windows, their sizes and current buffers,
6034 and for each displayed buffer, where display starts, and the positions of
6035 point and mark. An exception is made for point in the current buffer:
6036 its value is -not- saved.
6037 This also records the currently selected frame, and FRAME's focus
6038 redirection (see `redirect-frame-focus'). */)
6042 register Lisp_Object tem
;
6043 register int n_windows
;
6044 register struct save_window_data
*data
;
6045 register struct Lisp_Vector
*vec
;
6050 frame
= selected_frame
;
6051 CHECK_LIVE_FRAME (frame
);
6054 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6055 vec
= allocate_other_vector (VECSIZE (struct save_window_data
));
6056 data
= (struct save_window_data
*)vec
;
6058 XSETFASTINT (data
->frame_cols
, FRAME_COLS (f
));
6059 XSETFASTINT (data
->frame_lines
, FRAME_LINES (f
));
6060 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
6061 XSETFASTINT (data
->frame_tool_bar_lines
, FRAME_TOOL_BAR_LINES (f
));
6062 data
->selected_frame
= selected_frame
;
6063 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6064 XSETBUFFER (data
->current_buffer
, current_buffer
);
6065 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6066 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6067 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6068 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6069 XSETINT (data
->min_height
, window_min_height
);
6070 XSETINT (data
->min_width
, window_min_width
);
6071 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
6072 data
->saved_windows
= tem
;
6073 for (i
= 0; i
< n_windows
; i
++)
6074 XVECTOR (tem
)->contents
[i
]
6075 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
6076 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6077 XSETWINDOW_CONFIGURATION (tem
, data
);
6081 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
6083 doc
: /* Execute BODY, preserving window sizes and contents.
6084 Return the value of the last form in BODY.
6085 Restore which buffer appears in which window, where display starts,
6086 and the value of point and mark for each window.
6087 Also restore the choice of selected window.
6088 Also restore which buffer is current.
6089 Does not restore the value of point in current buffer.
6090 usage: (save-window-excursion BODY ...) */)
6094 register Lisp_Object val
;
6095 register int count
= SPECPDL_INDEX ();
6097 record_unwind_protect (Fset_window_configuration
,
6098 Fcurrent_window_configuration (Qnil
));
6099 val
= Fprogn (args
);
6100 return unbind_to (count
, val
);
6104 /***********************************************************************
6106 ***********************************************************************/
6108 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6110 doc
: /* Set width of marginal areas of window WINDOW.
6111 If WINDOW is nil, set margins of the currently selected window.
6112 Second arg LEFT-WIDTH specifies the number of character cells to
6113 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6114 does the same for the right marginal area. A nil width parameter
6115 means no margin. */)
6116 (window
, left
, right
)
6117 Lisp_Object window
, left
, right
;
6119 struct window
*w
= decode_window (window
);
6121 /* Translate negative or zero widths to nil.
6122 Margins that are too wide have to be checked elsewhere. */
6126 CHECK_NUMBER (left
);
6127 if (XINT (left
) <= 0)
6133 CHECK_NUMBER (right
);
6134 if (XINT (right
) <= 0)
6138 if (!EQ (w
->left_margin_cols
, left
)
6139 || !EQ (w
->right_margin_cols
, right
))
6141 w
->left_margin_cols
= left
;
6142 w
->right_margin_cols
= right
;
6144 adjust_window_margins (w
);
6146 ++windows_or_buffers_changed
;
6147 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6154 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6156 doc
: /* Get width of marginal areas of window WINDOW.
6157 If WINDOW is omitted or nil, use the currently selected window.
6158 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6159 If a marginal area does not exist, its width will be returned
6164 struct window
*w
= decode_window (window
);
6165 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
6170 /***********************************************************************
6172 ***********************************************************************/
6174 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6176 doc
: /* Set the fringe widths of window WINDOW.
6177 If WINDOW is nil, set the fringe widths of the currently selected
6179 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6180 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6181 fringe width. If a fringe width arg is nil, that means to use the
6182 frame's default fringe width. Default fringe widths can be set with
6183 the command `set-fringe-style'.
6184 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6185 outside of the display margins. By default, fringes are drawn between
6186 display marginal areas and the text area. */)
6187 (window
, left
, right
, outside_margins
)
6188 Lisp_Object window
, left
, right
, outside_margins
;
6190 struct window
*w
= decode_window (window
);
6193 CHECK_NATNUM (left
);
6195 CHECK_NATNUM (right
);
6197 if (!EQ (w
->left_fringe_width
, left
)
6198 || !EQ (w
->right_fringe_width
, right
)
6199 || !EQ (w
->fringes_outside_margins
, outside_margins
))
6201 w
->left_fringe_width
= left
;
6202 w
->right_fringe_width
= right
;
6203 w
->fringes_outside_margins
= outside_margins
;
6205 adjust_window_margins (w
);
6207 clear_glyph_matrix (w
->current_matrix
);
6208 w
->window_end_valid
= Qnil
;
6210 ++windows_or_buffers_changed
;
6211 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6218 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6220 doc
: /* Get width of fringes of window WINDOW.
6221 If WINDOW is omitted or nil, use the currently selected window.
6222 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6226 struct window
*w
= decode_window (window
);
6227 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6228 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6229 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
) ?
6230 Qt
: Qnil
), Qnil
)));
6235 /***********************************************************************
6237 ***********************************************************************/
6239 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
, Sset_window_scroll_bars
,
6241 doc
: /* Set width and type of scroll bars of window WINDOW.
6242 If window is nil, set scroll bars of the currently selected window.
6243 Second parameter WIDTH specifies the pixel width for the scroll bar;
6244 this is automatically adjusted to a multiple of the frame column width.
6245 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6246 bar: left, right, or nil.
6247 If WIDTH is nil, use the frame's scroll-bar width.
6248 If TYPE is t, use the frame's scroll-bar type. */)
6249 (window
, width
, vertical_type
, horizontal_type
)
6250 Lisp_Object window
, width
, vertical_type
, horizontal_type
;
6252 struct window
*w
= decode_window (window
);
6256 CHECK_NATNUM (width
);
6258 if (XINT (width
) == 0)
6259 vertical_type
= Qnil
;
6262 if (!(EQ (vertical_type
, Qnil
)
6263 || EQ (vertical_type
, Qleft
)
6264 || EQ (vertical_type
, Qright
)
6265 || EQ (vertical_type
, Qt
)))
6266 error ("Invalid type of vertical scroll bar");
6268 if (!EQ (w
->scroll_bar_width
, width
)
6269 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6271 w
->scroll_bar_width
= width
;
6272 w
->vertical_scroll_bar_type
= vertical_type
;
6274 adjust_window_margins (w
);
6276 clear_glyph_matrix (w
->current_matrix
);
6277 w
->window_end_valid
= Qnil
;
6279 ++windows_or_buffers_changed
;
6280 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6287 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6289 doc
: /* Get width and type of scroll bars of window WINDOW.
6290 If WINDOW is omitted or nil, use the currently selected window.
6291 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6292 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6297 struct window
*w
= decode_window (window
);
6298 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6299 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6300 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6301 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6302 Fcons (w
->vertical_scroll_bar_type
,
6303 Fcons (Qnil
, Qnil
))));
6308 /***********************************************************************
6310 ***********************************************************************/
6312 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6313 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6314 Use the selected window if WINDOW is nil or omitted.
6315 Normally, value is a multiple of the canonical character height of WINDOW;
6316 optional second arg PIXELS_P means value is measured in pixels. */)
6318 Lisp_Object window
, pixels_p
;
6325 window
= selected_window
;
6327 CHECK_WINDOW (window
);
6328 w
= XWINDOW (window
);
6329 f
= XFRAME (w
->frame
);
6331 if (FRAME_WINDOW_P (f
))
6332 result
= (NILP (pixels_p
)
6333 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6334 : make_number (-w
->vscroll
));
6336 result
= make_number (0);
6341 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6343 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6344 WINDOW nil means use the selected window. Normally, VSCROLL is a
6345 non-negative multiple of the canonical character height of WINDOW;
6346 optional third arg PIXELS_P non-nil means that VSCROLL is in pixels.
6347 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6348 corresponds to an integral number of pixels. The return value is the
6349 result of this rounding.
6350 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6351 (window
, vscroll
, pixels_p
)
6352 Lisp_Object window
, vscroll
, pixels_p
;
6358 window
= selected_window
;
6360 CHECK_WINDOW (window
);
6361 CHECK_NUMBER_OR_FLOAT (vscroll
);
6363 w
= XWINDOW (window
);
6364 f
= XFRAME (w
->frame
);
6366 if (FRAME_WINDOW_P (f
))
6368 int old_dy
= w
->vscroll
;
6370 w
->vscroll
= - (NILP (pixels_p
)
6371 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
6372 : XFLOATINT (vscroll
));
6373 w
->vscroll
= min (w
->vscroll
, 0);
6375 if (w
->vscroll
!= old_dy
)
6377 /* Adjust glyph matrix of the frame if the virtual display
6378 area becomes larger than before. */
6379 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
6382 /* Prevent redisplay shortcuts. */
6383 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
6387 return Fwindow_vscroll (window
, pixels_p
);
6391 /* Call FN for all leaf windows on frame F. FN is called with the
6392 first argument being a pointer to the leaf window, and with
6393 additional argument USER_DATA. Stops when FN returns 0. */
6396 foreach_window (f
, fn
, user_data
)
6398 int (* fn
) P_ ((struct window
*, void *));
6401 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
6405 /* Helper function for foreach_window. Call FN for all leaf windows
6406 reachable from W. FN is called with the first argument being a
6407 pointer to the leaf window, and with additional argument USER_DATA.
6408 Stop when FN returns 0. Value is 0 if stopped by FN. */
6411 foreach_window_1 (w
, fn
, user_data
)
6413 int (* fn
) P_ ((struct window
*, void *));
6418 for (cont
= 1; w
&& cont
;)
6420 if (!NILP (w
->hchild
))
6421 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
6422 else if (!NILP (w
->vchild
))
6423 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
6425 cont
= fn (w
, user_data
);
6427 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6434 /* Freeze or unfreeze the window start of W unless it is a
6435 mini-window or the selected window. FREEZE_P non-null means freeze
6436 the window start. */
6439 freeze_window_start (w
, freeze_p
)
6443 if (w
== XWINDOW (selected_window
)
6444 || MINI_WINDOW_P (w
)
6445 || (MINI_WINDOW_P (XWINDOW (selected_window
))
6446 && ! NILP (Vminibuf_scroll_window
)
6447 && w
== XWINDOW (Vminibuf_scroll_window
)))
6450 w
->frozen_window_start_p
= freeze_p
!= NULL
;
6455 /* Freeze or unfreeze the window starts of all leaf windows on frame
6456 F, except the selected window and a mini-window. FREEZE_P non-zero
6457 means freeze the window start. */
6460 freeze_window_starts (f
, freeze_p
)
6464 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
6468 /***********************************************************************
6470 ***********************************************************************/
6472 /* Return 1 if window configurations C1 and C2
6473 describe the same state of affairs. This is used by Fequal. */
6476 compare_window_configurations (c1
, c2
, ignore_positions
)
6478 int ignore_positions
;
6480 register struct save_window_data
*d1
, *d2
;
6481 struct Lisp_Vector
*sw1
, *sw2
;
6484 if (!WINDOW_CONFIGURATIONP (c1
))
6485 wrong_type_argument (Qwindow_configuration_p
, c1
);
6486 if (!WINDOW_CONFIGURATIONP (c2
))
6487 wrong_type_argument (Qwindow_configuration_p
, c2
);
6489 d1
= (struct save_window_data
*) XVECTOR (c1
);
6490 d2
= (struct save_window_data
*) XVECTOR (c2
);
6491 sw1
= XVECTOR (d1
->saved_windows
);
6492 sw2
= XVECTOR (d2
->saved_windows
);
6494 if (! EQ (d1
->frame_cols
, d2
->frame_cols
))
6496 if (! EQ (d1
->frame_lines
, d2
->frame_lines
))
6498 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
6500 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
6502 /* Don't compare the current_window field directly.
6503 Instead see w1_is_current and w2_is_current, below. */
6504 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
6506 if (! ignore_positions
)
6508 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
6510 if (! EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
))
6513 /* Don't compare the root_window field.
6514 We don't require the two configurations
6515 to use the same window object,
6516 and the two root windows must be equivalent
6517 if everything else compares equal. */
6518 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
6520 if (! EQ (d1
->min_width
, d2
->min_width
))
6522 if (! EQ (d1
->min_height
, d2
->min_height
))
6525 /* Verify that the two confis have the same number of windows. */
6526 if (sw1
->size
!= sw2
->size
)
6529 for (i
= 0; i
< sw1
->size
; i
++)
6531 struct saved_window
*p1
, *p2
;
6532 int w1_is_current
, w2_is_current
;
6534 p1
= SAVED_WINDOW_N (sw1
, i
);
6535 p2
= SAVED_WINDOW_N (sw2
, i
);
6537 /* Verify that the current windows in the two
6538 configurations correspond to each other. */
6539 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
6540 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
6542 if (w1_is_current
!= w2_is_current
)
6545 /* Verify that the corresponding windows do match. */
6546 if (! EQ (p1
->buffer
, p2
->buffer
))
6548 if (! EQ (p1
->left_col
, p2
->left_col
))
6550 if (! EQ (p1
->top_line
, p2
->top_line
))
6552 if (! EQ (p1
->total_cols
, p2
->total_cols
))
6554 if (! EQ (p1
->total_lines
, p2
->total_lines
))
6556 if (! EQ (p1
->display_table
, p2
->display_table
))
6558 if (! EQ (p1
->parent
, p2
->parent
))
6560 if (! EQ (p1
->prev
, p2
->prev
))
6562 if (! ignore_positions
)
6564 if (! EQ (p1
->hscroll
, p2
->hscroll
))
6566 if (!EQ (p1
->min_hscroll
, p2
->min_hscroll
))
6568 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
6570 if (NILP (Fequal (p1
->start
, p2
->start
)))
6572 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
6574 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
6577 if (! EQ (p1
->left_margin_cols
, p2
->left_margin_cols
))
6579 if (! EQ (p1
->right_margin_cols
, p2
->right_margin_cols
))
6581 if (! EQ (p1
->left_fringe_width
, p2
->left_fringe_width
))
6583 if (! EQ (p1
->right_fringe_width
, p2
->right_fringe_width
))
6585 if (! EQ (p1
->fringes_outside_margins
, p2
->fringes_outside_margins
))
6587 if (! EQ (p1
->scroll_bar_width
, p2
->scroll_bar_width
))
6589 if (! EQ (p1
->vertical_scroll_bar_type
, p2
->vertical_scroll_bar_type
))
6596 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
6597 Scompare_window_configurations
, 2, 2, 0,
6598 doc
: /* Compare two window configurations as regards the structure of windows.
6599 This function ignores details such as the values of point and mark
6600 and scrolling positions. */)
6604 if (compare_window_configurations (x
, y
, 1))
6612 struct frame
*f
= make_terminal_frame ();
6613 XSETFRAME (selected_frame
, f
);
6614 Vterminal_frame
= selected_frame
;
6615 minibuf_window
= f
->minibuffer_window
;
6616 selected_window
= f
->selected_window
;
6617 last_nonminibuf_frame
= f
;
6619 window_initialized
= 1;
6625 Vwindow_list
= Qnil
;
6631 Qwindow_size_fixed
= intern ("window-size-fixed");
6632 staticpro (&Qwindow_size_fixed
);
6634 staticpro (&Qwindow_configuration_change_hook
);
6635 Qwindow_configuration_change_hook
6636 = intern ("window-configuration-change-hook");
6638 Qwindowp
= intern ("windowp");
6639 staticpro (&Qwindowp
);
6641 Qwindow_configuration_p
= intern ("window-configuration-p");
6642 staticpro (&Qwindow_configuration_p
);
6644 Qwindow_live_p
= intern ("window-live-p");
6645 staticpro (&Qwindow_live_p
);
6647 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
6648 staticpro (&Qtemp_buffer_show_hook
);
6650 staticpro (&Vwindow_list
);
6652 minibuf_selected_window
= Qnil
;
6653 staticpro (&minibuf_selected_window
);
6655 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
6656 doc
: /* Non-nil means call as function to display a help buffer.
6657 The function is called with one argument, the buffer to be displayed.
6658 Used by `with-output-to-temp-buffer'.
6659 If this function is used, then it must do the entire job of showing
6660 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6661 Vtemp_buffer_show_function
= Qnil
;
6663 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
6664 doc
: /* If non-nil, function to call to handle `display-buffer'.
6665 It will receive two args, the buffer and a flag which if non-nil means
6666 that the currently selected window is not acceptable.
6667 It should choose or create a window, display the specified buffer in it,
6668 and return the window.
6669 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'
6670 work using this function. */);
6671 Vdisplay_buffer_function
= Qnil
;
6673 DEFVAR_LISP ("even-window-heights", &Veven_window_heights
,
6674 doc
: /* *If non-nil, `display-buffer' should even the window heights.
6675 If nil, `display-buffer' will leave the window configuration alone. */);
6676 Veven_window_heights
= Qt
;
6678 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
6679 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6680 Vminibuf_scroll_window
= Qnil
;
6682 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows
,
6683 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6684 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6685 is displayed in the `mode-line' face. */);
6686 mode_line_in_non_selected_windows
= 1;
6688 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
6689 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6690 Vother_window_scroll_buffer
= Qnil
;
6692 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
6693 doc
: /* *Non-nil means `display-buffer' should make a separate frame. */);
6696 DEFVAR_BOOL ("auto-window-vscroll", &auto_window_vscroll_p
,
6697 doc
: /* *Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
6698 auto_window_vscroll_p
= 1;
6700 DEFVAR_BOOL ("display-buffer-reuse-frames", &display_buffer_reuse_frames
,
6701 doc
: /* *Non-nil means `display-buffer' should reuse frames.
6702 If the buffer in question is already displayed in a frame, raise that frame. */);
6703 display_buffer_reuse_frames
= 0;
6705 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
6706 doc
: /* Function to call to handle automatic new frame creation.
6707 It is called with no arguments and should return a newly created frame.
6709 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'
6710 where `pop-up-frame-alist' would hold the default frame parameters. */);
6711 Vpop_up_frame_function
= Qnil
;
6713 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
6714 doc
: /* *List of buffer names that should have their own special frames.
6715 Displaying a buffer whose name is in this list makes a special frame for it
6716 using `special-display-function'. See also `special-display-regexps'.
6718 An element of the list can be a list instead of just a string.
6719 There are two ways to use a list as an element:
6720 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)
6721 In the first case, the FRAME-PARAMETERS are pairs of the form
6722 \(PARAMETER . VALUE); these parameter values are used to create the frame.
6723 In the second case, FUNCTION is called with BUFFER as the first argument,
6724 followed by the OTHER-ARGS--it can display BUFFER in any way it likes.
6725 All this is done by the function found in `special-display-function'.
6727 If the specified frame parameters include (same-buffer . t), the
6728 buffer is displayed in the currently selected window. Otherwise, if
6729 they include (same-frame . t), the buffer is displayed in a new window
6730 in the currently selected frame.
6732 If this variable appears \"not to work\", because you add a name to it
6733 but that buffer still appears in the selected window, look at the
6734 values of `same-window-buffer-names' and `same-window-regexps'.
6735 Those variables take precedence over this one. */);
6736 Vspecial_display_buffer_names
= Qnil
;
6738 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
6739 doc
: /* *List of regexps saying which buffers should have their own special frames.
6740 If a buffer name matches one of these regexps, it gets its own frame.
6741 Displaying a buffer whose name is in this list makes a special frame for it
6742 using `special-display-function'.
6744 An element of the list can be a list instead of just a string.
6745 There are two ways to use a list as an element:
6746 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)
6747 In the first case, the FRAME-PARAMETERS are pairs of the form
6748 \(PARAMETER . VALUE); these parameter values are used to create the frame.
6749 In the second case, FUNCTION is called with BUFFER as the first argument,
6750 followed by the OTHER-ARGS--it can display the buffer in any way it likes.
6751 All this is done by the function found in `special-display-function'.
6753 If the specified frame parameters include (same-buffer . t), the
6754 buffer is displayed in the currently selected window. Otherwise, if
6755 they include (same-frame . t), the buffer is displayed in a new window
6756 in the currently selected frame.
6758 If this variable appears \"not to work\", because you add a regexp to it
6759 but the matching buffers still appear in the selected window, look at the
6760 values of `same-window-buffer-names' and `same-window-regexps'.
6761 Those variables take precedence over this one. */);
6762 Vspecial_display_regexps
= Qnil
;
6764 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
6765 doc
: /* Function to call to make a new frame for a special buffer.
6766 It is called with two arguments, the buffer and optional buffer specific
6767 data, and should return a window displaying that buffer.
6768 The default value normally makes a separate frame for the buffer,
6769 using `special-display-frame-alist' to specify the frame parameters.
6770 But if the buffer specific data includes (same-buffer . t) then the
6771 buffer is displayed in the current selected window.
6772 Otherwise if it includes (same-frame . t) then the buffer is displayed in
6773 a new window in the currently selected frame.
6775 A buffer is special if it is listed in `special-display-buffer-names'
6776 or matches a regexp in `special-display-regexps'. */);
6777 Vspecial_display_function
= Qnil
;
6779 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
6780 doc
: /* *List of buffer names that should appear in the selected window.
6781 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'
6782 switches to it in the selected window, rather than making it appear
6783 in some other window.
6785 An element of the list can be a cons cell instead of just a string.
6786 Then the car must be a string, which specifies the buffer name.
6787 This is for compatibility with `special-display-buffer-names';
6788 the cdr of the cons cell is ignored.
6790 See also `same-window-regexps'. */);
6791 Vsame_window_buffer_names
= Qnil
;
6793 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
6794 doc
: /* *List of regexps saying which buffers should appear in the selected window.
6795 If a buffer name matches one of these regexps, then displaying it
6796 using `display-buffer' or `pop-to-buffer' switches to it
6797 in the selected window, rather than making it appear in some other window.
6799 An element of the list can be a cons cell instead of just a string.
6800 Then the car must be a string, which specifies the buffer name.
6801 This is for compatibility with `special-display-buffer-names';
6802 the cdr of the cons cell is ignored.
6804 See also `same-window-buffer-names'. */);
6805 Vsame_window_regexps
= Qnil
;
6807 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
6808 doc
: /* *Non-nil means display-buffer should make new windows. */);
6811 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
6812 doc
: /* *Number of lines of continuity when scrolling by screenfuls. */);
6813 next_screen_context_lines
= 2;
6815 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
6816 doc
: /* *A window must be at least this tall to be eligible for splitting by `display-buffer'.
6817 If there is only one window, it is split regardless of this value. */);
6818 split_height_threshold
= 500;
6820 DEFVAR_INT ("window-min-height", &window_min_height
,
6821 doc
: /* *Delete any window less than this tall (including its mode line). */);
6822 window_min_height
= 4;
6824 DEFVAR_INT ("window-min-width", &window_min_width
,
6825 doc
: /* *Delete any window less than this wide. */);
6826 window_min_width
= 10;
6828 DEFVAR_LISP ("scroll-preserve-screen-position",
6829 &Vscroll_preserve_screen_position
,
6830 doc
: /* *Non-nil means scroll commands move point to keep its screen line unchanged.
6831 This is only when it is impossible to keep point fixed and still
6832 scroll as specified. */);
6833 Vscroll_preserve_screen_position
= Qnil
;
6835 DEFVAR_LISP ("window-configuration-change-hook",
6836 &Vwindow_configuration_change_hook
,
6837 doc
: /* Functions to call when window configuration changes.
6838 The selected frame is the one whose configuration has changed. */);
6839 Vwindow_configuration_change_hook
= Qnil
;
6841 DEFVAR_BOOL ("window-size-fixed", &window_size_fixed
,
6842 doc
: /* Non-nil in a buffer means windows displaying the buffer are fixed-size.
6843 If the value is`height', then only the window's height is fixed.
6844 If the value is `width', then only the window's width is fixed.
6845 Any other non-nil value fixes both the width and the height.
6846 Emacs won't change the size of any window displaying that buffer,
6847 unless you explicitly change the size, or Emacs has no other choice. */);
6848 Fmake_variable_buffer_local (Qwindow_size_fixed
);
6849 window_size_fixed
= 0;
6851 defsubr (&Sselected_window
);
6852 defsubr (&Sminibuffer_window
);
6853 defsubr (&Swindow_minibuffer_p
);
6854 defsubr (&Swindowp
);
6855 defsubr (&Swindow_live_p
);
6856 defsubr (&Spos_visible_in_window_p
);
6857 defsubr (&Swindow_buffer
);
6858 defsubr (&Swindow_height
);
6859 defsubr (&Swindow_width
);
6860 defsubr (&Swindow_hscroll
);
6861 defsubr (&Sset_window_hscroll
);
6862 defsubr (&Swindow_redisplay_end_trigger
);
6863 defsubr (&Sset_window_redisplay_end_trigger
);
6864 defsubr (&Swindow_edges
);
6865 defsubr (&Swindow_pixel_edges
);
6866 defsubr (&Swindow_inside_edges
);
6867 defsubr (&Swindow_inside_pixel_edges
);
6868 defsubr (&Scoordinates_in_window_p
);
6869 defsubr (&Swindow_at
);
6870 defsubr (&Swindow_point
);
6871 defsubr (&Swindow_start
);
6872 defsubr (&Swindow_end
);
6873 defsubr (&Sset_window_point
);
6874 defsubr (&Sset_window_start
);
6875 defsubr (&Swindow_dedicated_p
);
6876 defsubr (&Sset_window_dedicated_p
);
6877 defsubr (&Swindow_display_table
);
6878 defsubr (&Sset_window_display_table
);
6879 defsubr (&Snext_window
);
6880 defsubr (&Sprevious_window
);
6881 defsubr (&Sother_window
);
6882 defsubr (&Sget_lru_window
);
6883 defsubr (&Sget_largest_window
);
6884 defsubr (&Sget_buffer_window
);
6885 defsubr (&Sdelete_other_windows
);
6886 defsubr (&Sdelete_windows_on
);
6887 defsubr (&Sreplace_buffer_in_windows
);
6888 defsubr (&Sdelete_window
);
6889 defsubr (&Sset_window_buffer
);
6890 defsubr (&Sselect_window
);
6891 defsubr (&Sspecial_display_p
);
6892 defsubr (&Ssame_window_p
);
6893 defsubr (&Sdisplay_buffer
);
6894 defsubr (&Sforce_window_update
);
6895 defsubr (&Ssplit_window
);
6896 defsubr (&Senlarge_window
);
6897 defsubr (&Sshrink_window
);
6898 defsubr (&Sscroll_up
);
6899 defsubr (&Sscroll_down
);
6900 defsubr (&Sscroll_left
);
6901 defsubr (&Sscroll_right
);
6902 defsubr (&Sother_window_for_scrolling
);
6903 defsubr (&Sscroll_other_window
);
6904 defsubr (&Sminibuffer_selected_window
);
6905 defsubr (&Srecenter
);
6906 defsubr (&Swindow_text_height
);
6907 defsubr (&Smove_to_window_line
);
6908 defsubr (&Swindow_configuration_p
);
6909 defsubr (&Swindow_configuration_frame
);
6910 defsubr (&Sset_window_configuration
);
6911 defsubr (&Scurrent_window_configuration
);
6912 defsubr (&Ssave_window_excursion
);
6913 defsubr (&Sset_window_margins
);
6914 defsubr (&Swindow_margins
);
6915 defsubr (&Sset_window_fringes
);
6916 defsubr (&Swindow_fringes
);
6917 defsubr (&Sset_window_scroll_bars
);
6918 defsubr (&Swindow_scroll_bars
);
6919 defsubr (&Swindow_vscroll
);
6920 defsubr (&Sset_window_vscroll
);
6921 defsubr (&Scompare_window_configurations
);
6922 defsubr (&Swindow_list
);
6928 initial_define_key (control_x_map
, '1', "delete-other-windows");
6929 initial_define_key (control_x_map
, '2', "split-window");
6930 initial_define_key (control_x_map
, '0', "delete-window");
6931 initial_define_key (control_x_map
, 'o', "other-window");
6932 initial_define_key (control_x_map
, '^', "enlarge-window");
6933 initial_define_key (control_x_map
, '<', "scroll-left");
6934 initial_define_key (control_x_map
, '>', "scroll-right");
6936 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
6937 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
6938 initial_define_key (meta_map
, 'v', "scroll-down");
6940 initial_define_key (global_map
, Ctl('L'), "recenter");
6941 initial_define_key (meta_map
, 'r', "move-to-window-line");
6944 /* arch-tag: 90a9c576-0590-48f1-a5f1-6c96a0452d9f
6945 (do not change this comment) */