1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
4 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 This file is part of GNU Emacs.
9 GNU Emacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 GNU Emacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
36 #include "dispextern.h"
37 #include "blockinput.h"
38 #include "intervals.h"
39 #include "termhooks.h" /* For FRAME_TERMINAL. */
43 #endif /* HAVE_X_WINDOWS */
55 Lisp_Object Qwindowp
, Qwindow_live_p
, Qwindow_configuration_p
;
56 Lisp_Object Qdisplay_buffer
;
57 Lisp_Object Qscroll_up
, Qscroll_down
;
58 Lisp_Object Qwindow_size_fixed
;
60 extern Lisp_Object Qleft_margin
, Qright_margin
;
62 static int displayed_window_lines
P_ ((struct window
*));
63 static struct window
*decode_window
P_ ((Lisp_Object
));
64 static int count_windows
P_ ((struct window
*));
65 static int get_leaf_windows
P_ ((struct window
*, struct window
**, int));
66 static void window_scroll
P_ ((Lisp_Object
, int, int, int));
67 static void window_scroll_pixel_based
P_ ((Lisp_Object
, int, int, int));
68 static void window_scroll_line_based
P_ ((Lisp_Object
, int, int, int));
69 static int window_min_size_1
P_ ((struct window
*, int, int));
70 static int window_min_size_2
P_ ((struct window
*, int, int));
71 static int window_min_size
P_ ((struct window
*, int, int, int, int *));
72 static void size_window
P_ ((Lisp_Object
, int, int, int, int, int));
73 static int freeze_window_start
P_ ((struct window
*, void *));
74 static int window_fixed_size_p
P_ ((struct window
*, int, int));
75 static void enlarge_window
P_ ((Lisp_Object
, int, int));
76 static Lisp_Object window_list
P_ ((void));
77 static int add_window_to_list
P_ ((struct window
*, void *));
78 static int candidate_window_p
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
80 static Lisp_Object next_window
P_ ((Lisp_Object
, Lisp_Object
,
82 static void decode_next_window_args
P_ ((Lisp_Object
*, Lisp_Object
*,
84 static int foreach_window_1
P_ ((struct window
*,
85 int (* fn
) (struct window
*, void *),
87 static Lisp_Object window_list_1
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
89 /* This is the window in which the terminal's cursor should
90 be left when nothing is being done with it. This must
91 always be a leaf window, and its buffer is selected by
92 the top level editing loop at the end of each command.
94 This value is always the same as
95 FRAME_SELECTED_WINDOW (selected_frame). */
97 Lisp_Object selected_window
;
99 /* A list of all windows for use by next_window and Fwindow_list.
100 Functions creating or deleting windows should invalidate this cache
101 by setting it to nil. */
103 Lisp_Object Vwindow_list
;
105 /* The mini-buffer window of the selected frame.
106 Note that you cannot test for mini-bufferness of an arbitrary window
107 by comparing against this; but you can test for mini-bufferness of
108 the selected window. */
110 Lisp_Object minibuf_window
;
112 /* Non-nil means it is the window whose mode line should be
113 shown as the selected window when the minibuffer is selected. */
115 Lisp_Object minibuf_selected_window
;
117 /* Non-nil means it is the window for C-M-v to scroll
118 when the mini-buffer is selected. */
120 Lisp_Object Vminibuf_scroll_window
;
122 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
124 Lisp_Object Vother_window_scroll_buffer
;
126 /* Non-nil means it's function to call to display temp buffers. */
128 Lisp_Object Vtemp_buffer_show_function
;
130 /* Non-zero means line and page scrolling on tall lines (with images)
131 does partial scrolling by modifying window-vscroll. */
133 int auto_window_vscroll_p
;
135 /* Non-zero means to use mode-line-inactive face in all windows but the
136 selected-window and the minibuffer-scroll-window when the
137 minibuffer is active. */
138 int mode_line_in_non_selected_windows
;
140 /* If a window gets smaller than either of these, it is removed. */
142 EMACS_INT window_min_height
;
143 EMACS_INT window_min_width
;
145 /* Hook run at end of temp_output_buffer_show. */
147 Lisp_Object Qtemp_buffer_show_hook
;
149 /* Number of lines of continuity in scrolling by screenfuls. */
151 EMACS_INT next_screen_context_lines
;
153 /* Incremented for each window created. */
155 static int sequence_number
;
157 /* Nonzero after init_window_once has finished. */
159 static int window_initialized
;
161 /* Hook to run when window config changes. */
163 static Lisp_Object Qwindow_configuration_change_hook
;
164 static Lisp_Object Vwindow_configuration_change_hook
;
166 /* Non-nil means scroll commands try to put point
167 at the same screen height as previously. */
169 Lisp_Object Vscroll_preserve_screen_position
;
171 /* List of commands affected by `Vscroll_preserve_screen_position'. */
173 Lisp_Object Vscroll_preserve_screen_position_commands
;
175 /* Non-nil means that text is inserted before window's markers. */
177 Lisp_Object Vwindow_point_insertion_type
;
179 /* Incremented by 1 whenever a window is deleted. */
181 int window_deletion_count
;
183 /* Used by the function window_scroll_pixel_based */
185 static int window_scroll_pixel_based_preserve_x
;
186 static int window_scroll_pixel_based_preserve_y
;
188 /* Same for window_scroll_line_based. */
190 static int window_scroll_preserve_hpos
;
191 static int window_scroll_preserve_vpos
;
193 #if 0 /* This isn't used anywhere. */
194 /* Nonzero means we can split a frame even if it is "unsplittable". */
195 static int inhibit_frame_unsplittable
;
198 extern EMACS_INT scroll_margin
;
200 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
202 /* If non-nil, then the `recenter' command with a nil argument
203 the entire frame to be redrawn; the special value `tty' causes the
204 frame to be redrawn only if it is a tty frame. */
206 static Lisp_Object Vrecenter_redisplay
;
207 extern Lisp_Object Qtty
;
210 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
211 doc
: /* Return t if OBJECT is a window. */)
215 return WINDOWP (object
) ? Qt
: Qnil
;
218 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
219 doc
: /* Return t if OBJECT is a window which is currently visible. */)
223 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
230 register struct window
*p
;
232 p
= allocate_window ();
234 XSETFASTINT (p
->sequence_number
, sequence_number
);
235 XSETFASTINT (p
->left_col
, 0);
236 XSETFASTINT (p
->top_line
, 0);
237 XSETFASTINT (p
->total_lines
, 0);
238 XSETFASTINT (p
->total_cols
, 0);
239 XSETFASTINT (p
->hscroll
, 0);
240 XSETFASTINT (p
->min_hscroll
, 0);
241 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
242 p
->start
= Fmake_marker ();
243 p
->pointm
= Fmake_marker ();
244 XSETFASTINT (p
->use_time
, 0);
246 p
->display_table
= Qnil
;
248 p
->window_parameters
= Qnil
;
249 p
->pseudo_window_p
= 0;
250 bzero (&p
->cursor
, sizeof (p
->cursor
));
251 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
252 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
253 p
->desired_matrix
= p
->current_matrix
= 0;
254 p
->nrows_scale_factor
= p
->ncols_scale_factor
= 1;
255 p
->phys_cursor_type
= -1;
256 p
->phys_cursor_width
= -1;
257 p
->must_be_updated_p
= 0;
258 XSETFASTINT (p
->window_end_vpos
, 0);
259 XSETFASTINT (p
->window_end_pos
, 0);
260 p
->window_end_valid
= Qnil
;
263 XSETFASTINT (p
->last_point
, 0);
264 p
->frozen_window_start_p
= 0;
265 p
->last_cursor_off_p
= p
->cursor_off_p
= 0;
266 p
->left_margin_cols
= Qnil
;
267 p
->right_margin_cols
= Qnil
;
268 p
->left_fringe_width
= Qnil
;
269 p
->right_fringe_width
= Qnil
;
270 p
->fringes_outside_margins
= Qnil
;
271 p
->scroll_bar_width
= Qnil
;
272 p
->vertical_scroll_bar_type
= Qt
;
273 p
->resize_proportionally
= Qnil
;
279 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
280 doc
: /* Return the window that the cursor now appears in and commands apply to. */)
283 return selected_window
;
286 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
287 doc
: /* Return the window used now for minibuffers.
288 If the optional argument FRAME is specified, return the minibuffer window
289 used by that frame. */)
294 frame
= selected_frame
;
295 CHECK_LIVE_FRAME (frame
);
296 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
299 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
300 doc
: /* Return non-nil if WINDOW is a minibuffer window.
301 WINDOW defaults to the selected window. */)
305 struct window
*w
= decode_window (window
);
306 return MINI_WINDOW_P (w
) ? Qt
: Qnil
;
310 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
311 Spos_visible_in_window_p
, 0, 3, 0,
312 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
313 Return nil if that position is scrolled vertically out of view.
314 If a character is only partially visible, nil is returned, unless the
315 optional argument PARTIALLY is non-nil.
316 If POS is only out of view because of horizontal scrolling, return non-nil.
317 If POS is t, it specifies the position of the last visible glyph in WINDOW.
318 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
320 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
321 return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
322 where X and Y are the pixel coordinates relative to the top left corner
323 of the window. The remaining elements are omitted if the character after
324 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
325 off-window at the top and bottom of the row, ROWH is the height of the
326 display row, and VPOS is the row number (0-based) containing POS. */)
327 (pos
, window
, partially
)
328 Lisp_Object pos
, window
, partially
;
330 register struct window
*w
;
332 register struct buffer
*buf
;
334 Lisp_Object in_window
= Qnil
;
335 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
338 w
= decode_window (window
);
339 buf
= XBUFFER (w
->buffer
);
340 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
344 else if (!NILP (pos
))
346 CHECK_NUMBER_COERCE_MARKER (pos
);
349 else if (w
== XWINDOW (selected_window
))
352 posint
= XMARKER (w
->pointm
)->charpos
;
354 /* If position is above window start or outside buffer boundaries,
355 or if window start is out of range, position is not visible. */
357 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
358 && CHARPOS (top
) >= BUF_BEGV (buf
)
359 && CHARPOS (top
) <= BUF_ZV (buf
)
360 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
361 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
364 if (!NILP (in_window
) && !NILP (partially
))
366 Lisp_Object part
= Qnil
;
368 part
= list4 (make_number (rtop
), make_number (rbot
),
369 make_number (rowh
), make_number (vpos
));
370 in_window
= Fcons (make_number (x
),
371 Fcons (make_number (y
), part
));
377 DEFUN ("window-line-height", Fwindow_line_height
,
378 Swindow_line_height
, 0, 2, 0,
379 doc
: /* Return height in pixels of text line LINE in window WINDOW.
380 If WINDOW is nil or omitted, use selected window.
382 Return height of current line if LINE is omitted or nil. Return height of
383 header or mode line if LINE is `header-line' and `mode-line'.
384 Otherwise, LINE is a text line number starting from 0. A negative number
385 counts from the end of the window.
387 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
388 in pixels of the visible part of the line, VPOS and YPOS are the
389 vertical position in lines and pixels of the line, relative to the top
390 of the first text line, and OFFBOT is the number of off-window pixels at
391 the bottom of the text line. If there are off-window pixels at the top
392 of the (first) text line, YPOS is negative.
394 Return nil if window display is not up-to-date. In that case, use
395 `pos-visible-in-window-p' to obtain the information. */)
397 Lisp_Object line
, window
;
399 register struct window
*w
;
400 register struct buffer
*b
;
401 struct glyph_row
*row
, *end_row
;
402 int max_y
, crop
, i
, n
;
404 w
= decode_window (window
);
407 || w
->pseudo_window_p
)
410 CHECK_BUFFER (w
->buffer
);
411 b
= XBUFFER (w
->buffer
);
413 /* Fail if current matrix is not up-to-date. */
414 if (NILP (w
->window_end_valid
)
415 || current_buffer
->clip_changed
416 || current_buffer
->prevent_redisplay_optimizations_p
417 || XFASTINT (w
->last_modified
) < BUF_MODIFF (b
)
418 || XFASTINT (w
->last_overlay_modified
) < BUF_OVERLAY_MODIFF (b
))
424 if (i
< 0 || i
>= w
->current_matrix
->nrows
425 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
427 max_y
= window_text_bottom_y (w
);
431 if (EQ (line
, Qheader_line
))
433 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
435 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
438 return list4 (make_number (row
->height
),
439 make_number (0), make_number (0),
443 if (EQ (line
, Qmode_line
))
445 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
448 return list4 (make_number (row
->height
),
449 make_number (0), /* not accurate */
450 make_number (WINDOW_HEADER_LINE_HEIGHT (w
)
451 + window_text_bottom_y (w
)),
458 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
459 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
460 max_y
= window_text_bottom_y (w
);
463 while ((n
< 0 || i
< n
)
464 && row
<= end_row
&& row
->enabled_p
465 && row
->y
+ row
->height
< max_y
)
468 if (row
> end_row
|| !row
->enabled_p
)
480 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
481 return list4 (make_number (row
->height
+ min (0, row
->y
) - crop
),
483 make_number (row
->y
),
489 static struct window
*
490 decode_window (window
)
491 register Lisp_Object window
;
494 return XWINDOW (selected_window
);
496 CHECK_LIVE_WINDOW (window
);
497 return XWINDOW (window
);
500 static struct window
*
501 decode_any_window (window
)
502 register Lisp_Object window
;
505 return XWINDOW (selected_window
);
507 CHECK_WINDOW (window
);
508 return XWINDOW (window
);
511 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
512 doc
: /* Return the buffer that WINDOW is displaying.
513 WINDOW defaults to the selected window. */)
517 return decode_window (window
)->buffer
;
520 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
521 doc
: /* Return the number of lines in WINDOW.
522 WINDOW defaults to the selected window.
524 The return value includes WINDOW's mode line and header line, if any. */)
528 return decode_any_window (window
)->total_lines
;
531 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
532 doc
: /* Return the number of display columns in WINDOW.
533 WINDOW defaults to the selected window.
535 Note: The return value is the number of columns available for text in
536 WINDOW. If you want to find out how many columns WINDOW takes up, use
537 (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
541 return make_number (window_box_text_cols (decode_any_window (window
)));
544 DEFUN ("window-full-width-p", Fwindow_full_width_p
, Swindow_full_width_p
, 0, 1, 0,
545 doc
: /* Return t if WINDOW is as wide as its frame.
546 WINDOW defaults to the selected window. */)
550 return WINDOW_FULL_WIDTH_P (decode_any_window (window
)) ? Qt
: Qnil
;
553 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
554 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
555 WINDOW defaults to the selected window. */)
559 return decode_window (window
)->hscroll
;
562 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
563 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
564 Return NCOL. NCOL should be zero or positive.
566 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
567 window so that the location of point moves off-window. */)
569 Lisp_Object window
, ncol
;
571 struct window
*w
= decode_window (window
);
575 hscroll
= max (0, XINT (ncol
));
577 /* Prevent redisplay shortcuts when changing the hscroll. */
578 if (XINT (w
->hscroll
) != hscroll
)
579 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
581 w
->hscroll
= make_number (hscroll
);
585 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
586 Swindow_redisplay_end_trigger
, 0, 1, 0,
587 doc
: /* Return WINDOW's redisplay end trigger value.
588 WINDOW defaults to the selected window.
589 See `set-window-redisplay-end-trigger' for more information. */)
593 return decode_window (window
)->redisplay_end_trigger
;
596 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
597 Sset_window_redisplay_end_trigger
, 2, 2, 0,
598 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
599 VALUE should be a buffer position (typically a marker) or nil.
600 If it is a buffer position, then if redisplay in WINDOW reaches a position
601 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
602 with two arguments: WINDOW, and the end trigger value.
603 Afterwards the end-trigger value is reset to nil. */)
605 register Lisp_Object window
, value
;
607 register struct window
*w
;
609 w
= decode_window (window
);
610 w
->redisplay_end_trigger
= value
;
614 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
615 doc
: /* Return a list of the edge coordinates of WINDOW.
616 The list has the form (LEFT TOP RIGHT BOTTOM).
617 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
618 all relative to 0, 0 at top left corner of frame.
620 RIGHT is one more than the rightmost column occupied by WINDOW.
621 BOTTOM is one more than the bottommost row occupied by WINDOW.
622 The edges include the space used by WINDOW's scroll bar, display
623 margins, fringes, header line, and/or mode line. For the edges of
624 just the text area, use `window-inside-edges'. */)
628 register struct window
*w
= decode_any_window (window
);
630 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w
)),
631 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w
)),
632 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w
)),
633 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w
)),
637 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
638 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
639 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
640 the top left corner of the frame.
642 RIGHT is one more than the rightmost x position occupied by WINDOW.
643 BOTTOM is one more than the bottommost y position occupied by WINDOW.
644 The pixel edges include the space used by WINDOW's scroll bar, display
645 margins, fringes, header line, and/or mode line. For the pixel edges
646 of just the text area, use `window-inside-pixel-edges'. */)
650 register struct window
*w
= decode_any_window (window
);
652 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
)),
653 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
)),
654 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
)),
655 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
)),
659 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
660 doc
: /* Return a list of the edge coordinates of WINDOW.
661 The list has the form (LEFT TOP RIGHT BOTTOM).
662 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
663 all relative to 0, 0 at top left corner of frame.
665 RIGHT is one more than the rightmost column of WINDOW's text area.
666 BOTTOM is one more than the bottommost row of WINDOW's text area.
667 The inside edges do not include the space used by the WINDOW's scroll
668 bar, display margins, fringes, header line, and/or mode line. */)
672 register struct window
*w
= decode_any_window (window
);
674 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w
)
675 + WINDOW_LEFT_MARGIN_COLS (w
)
676 + WINDOW_LEFT_FRINGE_COLS (w
)),
677 make_number (WINDOW_TOP_EDGE_LINE (w
)
678 + WINDOW_HEADER_LINE_LINES (w
)),
679 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w
)
680 - WINDOW_RIGHT_MARGIN_COLS (w
)
681 - WINDOW_RIGHT_FRINGE_COLS (w
)),
682 make_number (WINDOW_BOTTOM_EDGE_LINE (w
)
683 - WINDOW_MODE_LINE_LINES (w
)));
686 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
687 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
688 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
689 the top left corner of the frame.
691 RIGHT is one more than the rightmost x position of WINDOW's text area.
692 BOTTOM is one more than the bottommost y position of WINDOW's text area.
693 The inside edges do not include the space used by WINDOW's scroll bar,
694 display margins, fringes, header line, and/or mode line. */)
698 register struct window
*w
= decode_any_window (window
);
700 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
701 + WINDOW_LEFT_MARGIN_WIDTH (w
)
702 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
703 make_number (WINDOW_TOP_EDGE_Y (w
)
704 + WINDOW_HEADER_LINE_HEIGHT (w
)),
705 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
706 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
707 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
708 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
709 - WINDOW_MODE_LINE_HEIGHT (w
)));
712 /* Test if the character at column *X, row *Y is within window W.
713 If it is not, return ON_NOTHING;
714 if it is in the window's text area,
715 set *x and *y to its location relative to the upper left corner
718 if it is on the window's modeline, return ON_MODE_LINE;
719 if it is on the border between the window and its right sibling,
720 return ON_VERTICAL_BORDER.
721 if it is on a scroll bar,
722 return ON_SCROLL_BAR.
723 if it is on the window's top line, return ON_HEADER_LINE;
724 if it is in left or right fringe of the window,
725 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y
726 to window-relative coordinates;
727 if it is in the marginal area to the left/right of the window,
728 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y
729 to window-relative coordinates.
731 X and Y are frame relative pixel coordinates. */
733 static enum window_part
734 coordinates_in_window (w
, x
, y
)
735 register struct window
*w
;
738 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
739 int left_x
, right_x
, top_y
, bottom_y
;
740 enum window_part part
;
741 int ux
= FRAME_COLUMN_WIDTH (f
);
742 int x0
= WINDOW_LEFT_EDGE_X (w
);
743 int x1
= WINDOW_RIGHT_EDGE_X (w
);
744 /* The width of the area where the vertical line can be dragged.
745 (Between mode lines for instance. */
746 int grabbable_width
= ux
;
747 int lmargin_width
, rmargin_width
, text_left
, text_right
;
749 /* In what's below, we subtract 1 when computing right_x because we
750 want the rightmost pixel, which is given by left_pixel+width-1. */
751 if (w
->pseudo_window_p
)
754 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
755 top_y
= WINDOW_TOP_EDGE_Y (w
);
756 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
760 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
761 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
762 top_y
= WINDOW_TOP_EDGE_Y (w
);
763 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
766 /* Outside any interesting row? */
767 if (*y
< top_y
|| *y
>= bottom_y
)
770 /* On the mode line or header line? If it's near the start of
771 the mode or header line of window that's has a horizontal
772 sibling, say it's on the vertical line. That's to be able
773 to resize windows horizontally in case we're using toolkit
776 if (WINDOW_WANTS_MODELINE_P (w
)
777 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
781 header_vertical_border_check
:
782 /* We're somewhere on the mode line. We consider the place
783 between mode lines of horizontally adjacent mode lines
784 as the vertical border. If scroll bars on the left,
785 return the right window. */
786 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
787 || WINDOW_RIGHTMOST_P (w
))
789 if (!WINDOW_LEFTMOST_P (w
) && eabs (*x
- x0
) < grabbable_width
)
791 /* Convert X and Y to window relative coordinates.
792 Vertical border is at the left edge of window. */
793 *x
= max (0, *x
- x0
);
795 return ON_VERTICAL_BORDER
;
800 /* Make sure we're not at the rightmost position of a
801 mode-/header-line and there's yet another window on
802 the right. (Bug#1372) */
803 if ((WINDOW_RIGHTMOST_P (w
) || *x
< x1
)
804 && eabs (*x
- x1
) < grabbable_width
)
806 /* Convert X and Y to window relative coordinates.
807 Vertical border is at the right edge of window. */
808 *x
= min (x1
, *x
) - x0
;
810 return ON_VERTICAL_BORDER
;
814 if (*x
< x0
|| *x
>= x1
)
817 /* Convert X and Y to window relative coordinates.
818 Mode line starts at left edge of window. */
824 if (WINDOW_WANTS_HEADER_LINE_P (w
)
825 && *y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
))
827 part
= ON_HEADER_LINE
;
828 goto header_vertical_border_check
;
831 if (*x
< x0
|| *x
>= x1
)
834 /* Outside any interesting column? */
835 if (*x
< left_x
|| *x
> right_x
)
838 return ON_SCROLL_BAR
;
841 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
842 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
844 text_left
= window_box_left (w
, TEXT_AREA
);
845 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
847 if (FRAME_WINDOW_P (f
))
849 if (!w
->pseudo_window_p
850 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
851 && !WINDOW_RIGHTMOST_P (w
)
852 && (eabs (*x
- right_x
) < grabbable_width
))
854 /* Convert X and Y to window relative coordinates.
855 Vertical border is at the right edge of window. */
856 *x
= min (right_x
, *x
) - left_x
;
858 return ON_VERTICAL_BORDER
;
863 /* Need to say "*x > right_x" rather than >=, since on character
864 terminals, the vertical line's x coordinate is right_x. */
865 if (!w
->pseudo_window_p
866 && !WINDOW_RIGHTMOST_P (w
)
867 && *x
> right_x
- ux
)
869 /* On the border on the right side of the window? Assume that
870 this area begins at RIGHT_X minus a canonical char width. */
871 *x
= min (right_x
, *x
) - left_x
;
873 return ON_VERTICAL_BORDER
;
879 if (lmargin_width
> 0
880 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
881 ? (*x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
882 : (*x
< left_x
+ lmargin_width
)))
885 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
886 *x
-= WINDOW_LEFT_FRINGE_WIDTH (w
);
888 return ON_LEFT_MARGIN
;
891 /* Convert X and Y to window-relative pixel coordinates. */
894 return ON_LEFT_FRINGE
;
897 if (*x
>= text_right
)
899 if (rmargin_width
> 0
900 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
901 ? (*x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
902 : (*x
>= right_x
- rmargin_width
)))
904 *x
-= right_x
- rmargin_width
;
905 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
906 *x
+= WINDOW_RIGHT_FRINGE_WIDTH (w
);
908 return ON_RIGHT_MARGIN
;
911 /* Convert X and Y to window-relative pixel coordinates. */
912 *x
-= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
);
914 return ON_RIGHT_FRINGE
;
917 /* Everything special ruled out - must be on text area */
924 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
925 Scoordinates_in_window_p
, 2, 2, 0,
926 doc
: /* Return non-nil if COORDINATES are in WINDOW.
927 COORDINATES is a cons of the form (X . Y), X and Y being distances
928 measured in characters from the upper-left corner of the frame.
929 \(0 . 0) denotes the character in the upper left corner of the
931 If COORDINATES are in the text portion of WINDOW,
932 the coordinates relative to the window are returned.
933 If they are in the mode line of WINDOW, `mode-line' is returned.
934 If they are in the top mode line of WINDOW, `header-line' is returned.
935 If they are in the left fringe of WINDOW, `left-fringe' is returned.
936 If they are in the right fringe of WINDOW, `right-fringe' is returned.
937 If they are on the border between WINDOW and its right sibling,
938 `vertical-line' is returned.
939 If they are in the windows's left or right marginal areas, `left-margin'\n\
940 or `right-margin' is returned. */)
941 (coordinates
, window
)
942 register Lisp_Object coordinates
, window
;
949 CHECK_WINDOW (window
);
950 w
= XWINDOW (window
);
951 f
= XFRAME (w
->frame
);
952 CHECK_CONS (coordinates
);
953 lx
= Fcar (coordinates
);
954 ly
= Fcdr (coordinates
);
955 CHECK_NUMBER_OR_FLOAT (lx
);
956 CHECK_NUMBER_OR_FLOAT (ly
);
957 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
958 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
960 switch (coordinates_in_window (w
, &x
, &y
))
966 /* X and Y are now window relative pixel coordinates. Convert
967 them to canonical char units before returning them. */
968 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
969 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
974 case ON_VERTICAL_BORDER
:
975 return Qvertical_line
;
983 case ON_RIGHT_FRINGE
:
984 return Qright_fringe
;
989 case ON_RIGHT_MARGIN
:
990 return Qright_margin
;
993 /* Historically we are supposed to return nil in this case. */
1002 /* Callback for foreach_window, used in window_from_coordinates.
1003 Check if window W contains coordinates specified by USER_DATA which
1004 is actually a pointer to a struct check_window_data CW.
1006 Check if window W contains coordinates *CW->x and *CW->y. If it
1007 does, return W in *CW->window, as Lisp_Object, and return in
1008 *CW->part the part of the window under coordinates *X,*Y. Return
1009 zero from this function to stop iterating over windows. */
1011 struct check_window_data
1013 Lisp_Object
*window
;
1015 enum window_part
*part
;
1019 check_window_containing (w
, user_data
)
1023 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
1024 enum window_part found
;
1027 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1028 if (found
!= ON_NOTHING
)
1031 XSETWINDOW (*cw
->window
, w
);
1039 /* Find the window containing frame-relative pixel position X/Y and
1040 return it as a Lisp_Object.
1042 If X, Y is on one of the window's special `window_part' elements,
1043 set *PART to the id of that element, and return X and Y converted
1044 to window relative coordinates in WX and WY.
1046 If there is no window under X, Y return nil and leave *PART
1047 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1049 This function was previously implemented with a loop cycling over
1050 windows with Fnext_window, and starting with the frame's selected
1051 window. It turned out that this doesn't work with an
1052 implementation of next_window using Vwindow_list, because
1053 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1054 tree of F when this function is called asynchronously from
1055 note_mouse_highlight. The original loop didn't terminate in this
1059 window_from_coordinates (f
, x
, y
, part
, wx
, wy
, tool_bar_p
)
1062 enum window_part
*part
;
1067 struct check_window_data cw
;
1068 enum window_part dummy
;
1074 cw
.window
= &window
, cw
.x
= &x
, cw
.y
= &y
; cw
.part
= part
;
1075 foreach_window (f
, check_window_containing
, &cw
);
1077 /* If not found above, see if it's in the tool bar window, if a tool
1081 && WINDOWP (f
->tool_bar_window
)
1082 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1083 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), &x
, &y
)
1087 window
= f
->tool_bar_window
;
1096 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1097 doc
: /* Return window containing coordinates X and Y on FRAME.
1098 If omitted, FRAME defaults to the currently selected frame.
1099 The top left corner of the frame is considered to be row 0,
1102 Lisp_Object x
, y
, frame
;
1107 frame
= selected_frame
;
1108 CHECK_LIVE_FRAME (frame
);
1111 /* Check that arguments are integers or floats. */
1112 CHECK_NUMBER_OR_FLOAT (x
);
1113 CHECK_NUMBER_OR_FLOAT (y
);
1115 return window_from_coordinates (f
,
1116 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1117 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1118 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1119 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1123 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1124 doc
: /* Return current value of point in WINDOW.
1125 WINDOW defaults to the selected window.
1127 For a nonselected window, this is the value point would have
1128 if that window were selected.
1130 Note that, when WINDOW is the selected window and its buffer
1131 is also currently selected, the value returned is the same as (point).
1132 It would be more strictly correct to return the `top-level' value
1133 of point, outside of any save-excursion forms.
1134 But that is hard to define. */)
1138 register struct window
*w
= decode_window (window
);
1140 if (w
== XWINDOW (selected_window
)
1141 && current_buffer
== XBUFFER (w
->buffer
))
1143 return Fmarker_position (w
->pointm
);
1146 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1147 doc
: /* Return position at which display currently starts in WINDOW.
1148 WINDOW defaults to the selected window.
1149 This is updated by redisplay or by calling `set-window-start'. */)
1153 return Fmarker_position (decode_window (window
)->start
);
1156 /* This is text temporarily removed from the doc string below.
1158 This function returns nil if the position is not currently known.
1159 That happens when redisplay is preempted and doesn't finish.
1160 If in that case you want to compute where the end of the window would
1161 have been if redisplay had finished, do this:
1163 (goto-char (window-start window))
1164 (vertical-motion (1- (window-height window)) window)
1167 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1168 doc
: /* Return position at which display currently ends in WINDOW.
1169 WINDOW defaults to the selected window.
1170 This is updated by redisplay, when it runs to completion.
1171 Simply changing the buffer text or setting `window-start'
1172 does not update this value.
1173 Return nil if there is no recorded value. \(This can happen if the
1174 last redisplay of WINDOW was preempted, and did not finish.)
1175 If UPDATE is non-nil, compute the up-to-date position
1176 if it isn't already recorded. */)
1178 Lisp_Object window
, update
;
1181 struct window
*w
= decode_window (window
);
1189 #if 0 /* This change broke some things. We should make it later. */
1190 /* If we don't know the end position, return nil.
1191 The user can compute it with vertical-motion if he wants to.
1192 It would be nicer to do it automatically,
1193 but that's so slow that it would probably bother people. */
1194 if (NILP (w
->window_end_valid
))
1199 && ! (! NILP (w
->window_end_valid
)
1200 && XFASTINT (w
->last_modified
) >= BUF_MODIFF (b
)
1201 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (b
))
1204 struct text_pos startp
;
1206 struct buffer
*old_buffer
= NULL
;
1208 /* Cannot use Fvertical_motion because that function doesn't
1209 cope with variable-height lines. */
1210 if (b
!= current_buffer
)
1212 old_buffer
= current_buffer
;
1213 set_buffer_internal (b
);
1216 /* In case W->start is out of the range, use something
1217 reasonable. This situation occurred when loading a file with
1218 `-l' containing a call to `rmail' with subsequent other
1219 commands. At the end, W->start happened to be BEG, while
1220 rmail had already narrowed the buffer. */
1221 if (XMARKER (w
->start
)->charpos
< BEGV
)
1222 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1223 else if (XMARKER (w
->start
)->charpos
> ZV
)
1224 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1226 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1228 start_display (&it
, w
, startp
);
1229 move_it_vertically (&it
, window_box_height (w
));
1230 if (it
.current_y
< it
.last_visible_y
)
1231 move_it_past_eol (&it
);
1232 value
= make_number (IT_CHARPOS (it
));
1235 set_buffer_internal (old_buffer
);
1238 XSETINT (value
, BUF_Z (b
) - XFASTINT (w
->window_end_pos
));
1243 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1244 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1247 Lisp_Object window
, pos
;
1249 register struct window
*w
= decode_window (window
);
1251 CHECK_NUMBER_COERCE_MARKER (pos
);
1252 if (w
== XWINDOW (selected_window
)
1253 && XBUFFER (w
->buffer
) == current_buffer
)
1256 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1258 /* We have to make sure that redisplay updates the window to show
1259 the new value of point. */
1260 if (!EQ (window
, selected_window
))
1261 ++windows_or_buffers_changed
;
1266 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1267 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1268 WINDOW defaults to the selected window. Return POS.
1269 Optional third arg NOFORCE non-nil inhibits next redisplay from
1270 overriding motion of point in order to display at this exact start. */)
1271 (window
, pos
, noforce
)
1272 Lisp_Object window
, pos
, noforce
;
1274 register struct window
*w
= decode_window (window
);
1276 CHECK_NUMBER_COERCE_MARKER (pos
);
1277 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1278 /* this is not right, but much easier than doing what is right. */
1279 w
->start_at_line_beg
= Qnil
;
1281 w
->force_start
= Qt
;
1282 w
->update_mode_line
= Qt
;
1283 XSETFASTINT (w
->last_modified
, 0);
1284 XSETFASTINT (w
->last_overlay_modified
, 0);
1285 if (!EQ (window
, selected_window
))
1286 windows_or_buffers_changed
++;
1292 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1294 doc
: /* Return non-nil when WINDOW is dedicated to its buffer.
1295 More precisely, return the value assigned by the last call of
1296 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1297 never called with WINDOW as its argument, or the value set by that
1298 function was internally reset since its last call. WINDOW defaults to
1299 the selected window.
1301 When a window is dedicated to its buffer, `display-buffer' will refrain
1302 from displaying another buffer in it. `get-lru-window' and
1303 `get-largest-window' treat dedicated windows specially.
1304 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1305 `kill-buffer' can delete a dedicated window and the containing frame.
1307 Functions like `set-window-buffer' may change the buffer displayed by a
1308 window, unless that window is "strongly" dedicated to its buffer, that
1309 is the value returned by `window-dedicated-p' is t. */)
1313 return decode_window (window
)->dedicated
;
1316 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1317 Sset_window_dedicated_p
, 2, 2, 0,
1318 doc
: /* Mark WINDOW as dedicated according to FLAG.
1319 WINDOW defaults to the selected window. FLAG non-nil means mark WINDOW
1320 as dedicated to its buffer. FLAG nil means mark WINDOW as non-dedicated.
1323 When a window is dedicated to its buffer, `display-buffer' will refrain
1324 from displaying another buffer in it. `get-lru-window' and
1325 `get-largest-window' treat dedicated windows specially.
1326 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1327 `kill-buffer' can delete a dedicated window and the containing
1330 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
1331 its buffer. Functions like `set-window-buffer' may change the buffer
1332 displayed by a window, unless that window is strongly dedicated to its
1333 buffer. If and when `set-window-buffer' displays another buffer in a
1334 window, it also makes sure that the window is not marked as dedicated. */)
1336 Lisp_Object window
, flag
;
1338 register struct window
*w
= decode_window (window
);
1340 w
->dedicated
= flag
;
1341 return w
->dedicated
;
1345 DEFUN ("window-parameters", Fwindow_parameters
, Swindow_parameters
,
1347 doc
: /* Return the parameters of WINDOW and their values.
1348 WINDOW defaults to the selected window. The return value is a list of
1349 elements of the form (PARAMETER . VALUE). */)
1353 return Fcopy_alist (decode_window (window
)->window_parameters
);
1356 DEFUN ("window-parameter", Fwindow_parameter
, Swindow_parameter
,
1358 doc
: /* Return WINDOW's value for PARAMETER.
1359 WINDOW defaults to the selected window. */)
1361 Lisp_Object window
, parameter
;
1365 result
= Fassq (parameter
, decode_window (window
)->window_parameters
);
1366 return CDR_SAFE (result
);
1369 DEFUN ("set-window-parameter", Fset_window_parameter
,
1370 Sset_window_parameter
, 3, 3, 0,
1371 doc
: /* Set WINDOW's value of PARAMETER to VALUE.
1372 WINDOW defaults to the selected window. Return VALUE. */)
1373 (window
, parameter
, value
)
1374 Lisp_Object window
, parameter
, value
;
1376 register struct window
*w
= decode_window (window
);
1377 Lisp_Object old_alist_elt
;
1379 old_alist_elt
= Fassq (parameter
, w
->window_parameters
);
1380 if (NILP (old_alist_elt
))
1381 w
->window_parameters
= Fcons (Fcons (parameter
, value
), w
->window_parameters
);
1383 Fsetcdr (old_alist_elt
, value
);
1388 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1390 doc
: /* Return the display-table that WINDOW is using.
1391 WINDOW defaults to the selected window. */)
1395 return decode_window (window
)->display_table
;
1398 /* Get the display table for use on window W. This is either W's
1399 display table or W's buffer's display table. Ignore the specified
1400 tables if they are not valid; if no valid table is specified,
1403 struct Lisp_Char_Table
*
1404 window_display_table (w
)
1407 struct Lisp_Char_Table
*dp
= NULL
;
1409 if (DISP_TABLE_P (w
->display_table
))
1410 dp
= XCHAR_TABLE (w
->display_table
);
1411 else if (BUFFERP (w
->buffer
))
1413 struct buffer
*b
= XBUFFER (w
->buffer
);
1415 if (DISP_TABLE_P (b
->display_table
))
1416 dp
= XCHAR_TABLE (b
->display_table
);
1417 else if (DISP_TABLE_P (Vstandard_display_table
))
1418 dp
= XCHAR_TABLE (Vstandard_display_table
);
1424 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1425 doc
: /* Set WINDOW's display-table to TABLE. */)
1427 register Lisp_Object window
, table
;
1429 register struct window
*w
;
1431 w
= decode_window (window
);
1432 w
->display_table
= table
;
1436 /* Record info on buffer window w is displaying
1437 when it is about to cease to display that buffer. */
1440 register struct window
*w
;
1447 if (b
!= XMARKER (w
->pointm
)->buffer
)
1451 if (w
== XWINDOW (selected_window
)
1452 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1453 /* Do this except when the selected window's buffer
1454 is being removed from some other window. */
1456 /* last_window_start records the start position that this buffer
1457 had in the last window to be disconnected from it.
1458 Now that this statement is unconditional,
1459 it is possible for the buffer to be displayed in the
1460 selected window, while last_window_start reflects another
1461 window which was recently showing the same buffer.
1462 Some people might say that might be a good thing. Let's see. */
1463 b
->last_window_start
= marker_position (w
->start
);
1465 /* Point in the selected window's buffer
1466 is actually stored in that buffer, and the window's pointm isn't used.
1467 So don't clobber point in that buffer. */
1468 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1469 /* This line helps to fix Horsley's testbug.el bug. */
1470 && !(WINDOWP (b
->last_selected_window
)
1471 && w
!= XWINDOW (b
->last_selected_window
)
1472 && EQ (buf
, XWINDOW (b
->last_selected_window
)->buffer
)))
1473 temp_set_point_both (b
,
1474 clip_to_bounds (BUF_BEGV (b
),
1475 XMARKER (w
->pointm
)->charpos
,
1477 clip_to_bounds (BUF_BEGV_BYTE (b
),
1478 marker_byte_position (w
->pointm
),
1481 if (WINDOWP (b
->last_selected_window
)
1482 && w
== XWINDOW (b
->last_selected_window
))
1483 b
->last_selected_window
= Qnil
;
1486 /* Put replacement into the window structure in place of old. */
1488 replace_window (old
, replacement
)
1489 Lisp_Object old
, replacement
;
1491 register Lisp_Object tem
;
1492 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
1494 /* If OLD is its frame's root_window, then replacement is the new
1495 root_window for that frame. */
1497 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1498 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
1500 p
->left_col
= o
->left_col
;
1501 p
->top_line
= o
->top_line
;
1502 p
->total_cols
= o
->total_cols
;
1503 p
->total_lines
= o
->total_lines
;
1504 p
->desired_matrix
= p
->current_matrix
= 0;
1506 bzero (&p
->cursor
, sizeof (p
->cursor
));
1507 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
1508 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
1509 p
->phys_cursor_type
= -1;
1510 p
->phys_cursor_width
= -1;
1511 p
->must_be_updated_p
= 0;
1512 p
->pseudo_window_p
= 0;
1513 XSETFASTINT (p
->window_end_vpos
, 0);
1514 XSETFASTINT (p
->window_end_pos
, 0);
1515 p
->window_end_valid
= Qnil
;
1516 p
->frozen_window_start_p
= 0;
1517 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
1519 p
->next
= tem
= o
->next
;
1521 XWINDOW (tem
)->prev
= replacement
;
1523 p
->prev
= tem
= o
->prev
;
1525 XWINDOW (tem
)->next
= replacement
;
1527 p
->parent
= tem
= o
->parent
;
1530 if (EQ (XWINDOW (tem
)->vchild
, old
))
1531 XWINDOW (tem
)->vchild
= replacement
;
1532 if (EQ (XWINDOW (tem
)->hchild
, old
))
1533 XWINDOW (tem
)->hchild
= replacement
;
1536 /*** Here, if replacement is a vertical combination
1537 and so is its new parent, we should make replacement's
1538 children be children of that parent instead. ***/
1541 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
1542 doc
: /* Remove WINDOW from its frame.
1543 WINDOW defaults to the selected window. Return nil.
1544 Signal an error when WINDOW is the only window on its frame. */)
1546 register Lisp_Object window
;
1550 window
= selected_window
;
1552 CHECK_LIVE_WINDOW (window
);
1554 f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
1555 delete_window (window
);
1557 run_window_configuration_change_hook (f
);
1563 delete_window (window
)
1564 register Lisp_Object window
;
1566 register Lisp_Object tem
, parent
, sib
;
1567 register struct window
*p
;
1568 register struct window
*par
;
1571 /* Because this function is called by other C code on non-leaf
1572 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1573 so we can't decode_window here. */
1574 CHECK_WINDOW (window
);
1575 p
= XWINDOW (window
);
1577 /* It's a no-op to delete an already-deleted window. */
1578 if (NILP (p
->buffer
)
1580 && NILP (p
->vchild
))
1585 error ("Attempt to delete minibuffer or sole ordinary window");
1586 par
= XWINDOW (parent
);
1588 windows_or_buffers_changed
++;
1589 Vwindow_list
= Qnil
;
1590 f
= XFRAME (WINDOW_FRAME (p
));
1591 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
1593 /* Are we trying to delete any frame's selected window? */
1595 Lisp_Object swindow
, pwindow
;
1597 /* See if the frame's selected window is either WINDOW
1598 or any subwindow of it, by finding all that window's parents
1599 and comparing each one with WINDOW. */
1600 swindow
= FRAME_SELECTED_WINDOW (f
);
1605 while (!NILP (pwindow
))
1607 if (EQ (window
, pwindow
))
1609 pwindow
= XWINDOW (pwindow
)->parent
;
1612 /* If the window being deleted is not a parent of SWINDOW,
1613 then SWINDOW is ok as the new selected window. */
1614 if (!EQ (window
, pwindow
))
1616 /* Otherwise, try another window for SWINDOW. */
1617 swindow
= Fnext_window (swindow
, Qlambda
, Qnil
);
1619 /* If we get back to the frame's selected window,
1620 it means there was no acceptable alternative,
1621 so we cannot delete. */
1622 if (EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1623 error ("Cannot delete window");
1626 /* If we need to change SWINDOW, do it. */
1627 if (! EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1629 /* If we're about to delete the selected window on the
1630 selected frame, then we should use Fselect_window to select
1631 the new window. On the other hand, if we're about to
1632 delete the selected window on any other frame, we shouldn't do
1633 anything but set the frame's selected_window slot. */
1634 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
1635 Fselect_window (swindow
, Qnil
);
1637 FRAME_SELECTED_WINDOW (f
) = swindow
;
1641 /* Now we know we can delete this one. */
1642 window_deletion_count
++;
1645 /* tem is null for dummy parent windows
1646 (which have inferiors but not any contents themselves) */
1650 unchain_marker (XMARKER (p
->pointm
));
1651 unchain_marker (XMARKER (p
->start
));
1654 /* Free window glyph matrices. It is sure that they are allocated
1655 again when ADJUST_GLYPHS is called. Block input so that expose
1656 events and other events that access glyph matrices are not
1657 processed while we are changing them. */
1659 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)));
1663 XWINDOW (tem
)->prev
= p
->prev
;
1667 XWINDOW (tem
)->next
= p
->next
;
1669 if (EQ (window
, par
->hchild
))
1670 par
->hchild
= p
->next
;
1671 if (EQ (window
, par
->vchild
))
1672 par
->vchild
= p
->next
;
1674 /* Find one of our siblings to give our space to. */
1678 /* If p gives its space to its next sibling, that sibling needs
1679 to have its top/left side pulled back to where p's is.
1680 set_window_{height,width} will re-position the sibling's
1683 XWINDOW (sib
)->top_line
= p
->top_line
;
1684 XWINDOW (sib
)->left_col
= p
->left_col
;
1687 /* Stretch that sibling. */
1688 if (!NILP (par
->vchild
))
1689 set_window_height (sib
,
1690 XFASTINT (XWINDOW (sib
)->total_lines
) + XFASTINT (p
->total_lines
),
1692 if (!NILP (par
->hchild
))
1693 set_window_width (sib
,
1694 XFASTINT (XWINDOW (sib
)->total_cols
) + XFASTINT (p
->total_cols
),
1697 /* If parent now has only one child,
1698 put the child into the parent's place. */
1702 if (NILP (XWINDOW (tem
)->next
)) {
1703 replace_window (parent
, tem
);
1704 par
= XWINDOW (tem
);
1707 /* Since we may be deleting combination windows, we must make sure that
1708 not only p but all its children have been marked as deleted. */
1709 if (! NILP (p
->hchild
))
1710 delete_all_subwindows (XWINDOW (p
->hchild
));
1711 else if (! NILP (p
->vchild
))
1712 delete_all_subwindows (XWINDOW (p
->vchild
));
1714 /* Mark this window as deleted. */
1715 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1717 if (! NILP (par
->parent
))
1718 par
= XWINDOW (par
->parent
);
1720 /* Check if we have a v/hchild with a v/hchild. In that case remove
1723 if (! NILP (par
->vchild
) && ! NILP (XWINDOW (par
->vchild
)->vchild
))
1725 p
= XWINDOW (par
->vchild
);
1726 par
->vchild
= p
->vchild
;
1729 else if (! NILP (par
->hchild
) && ! NILP (XWINDOW (par
->hchild
)->hchild
))
1731 p
= XWINDOW (par
->hchild
);
1732 par
->hchild
= p
->hchild
;
1740 while (! NILP (tem
)) {
1741 XWINDOW (tem
)->parent
= p
->parent
;
1742 if (NILP (XWINDOW (tem
)->next
))
1744 tem
= XWINDOW (tem
)->next
;
1747 /* The next of the v/hchild we are removing is now the next of the
1748 last child for the v/hchild:
1749 Before v/hchild -> v/hchild -> next1 -> next2
1752 After: v/hchild -> next1 -> next2 -> next3
1754 XWINDOW (tem
)->next
= p
->next
;
1755 if (! NILP (p
->next
))
1756 XWINDOW (p
->next
)->prev
= tem
;
1758 p
->next
= p
->prev
= p
->vchild
= p
->hchild
= p
->buffer
= Qnil
;
1762 /* Adjust glyph matrices. */
1769 /***********************************************************************
1771 ***********************************************************************/
1773 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1774 pointer. This is a callback function for foreach_window, used in
1775 function window_list. */
1778 add_window_to_list (w
, user_data
)
1782 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1784 XSETWINDOW (window
, w
);
1785 *list
= Fcons (window
, *list
);
1790 /* Return a list of all windows, for use by next_window. If
1791 Vwindow_list is a list, return that list. Otherwise, build a new
1792 list, cache it in Vwindow_list, and return that. */
1797 if (!CONSP (Vwindow_list
))
1801 Vwindow_list
= Qnil
;
1802 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1804 Lisp_Object args
[2];
1806 /* We are visiting windows in canonical order, and add
1807 new windows at the front of args[1], which means we
1808 have to reverse this list at the end. */
1810 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1811 args
[0] = Vwindow_list
;
1812 args
[1] = Fnreverse (args
[1]);
1813 Vwindow_list
= Fnconc (2, args
);
1817 return Vwindow_list
;
1821 /* Value is non-zero if WINDOW satisfies the constraints given by
1822 OWINDOW, MINIBUF and ALL_FRAMES.
1824 MINIBUF t means WINDOW may be minibuffer windows.
1825 `lambda' means WINDOW may not be a minibuffer window.
1826 a window means a specific minibuffer window
1828 ALL_FRAMES t means search all frames,
1829 nil means search just current frame,
1830 `visible' means search just visible frames,
1831 0 means search visible and iconified frames,
1832 a window means search the frame that window belongs to,
1833 a frame means consider windows on that frame, only. */
1836 candidate_window_p (window
, owindow
, minibuf
, all_frames
)
1837 Lisp_Object window
, owindow
, minibuf
, all_frames
;
1839 struct window
*w
= XWINDOW (window
);
1840 struct frame
*f
= XFRAME (w
->frame
);
1841 int candidate_p
= 1;
1843 if (!BUFFERP (w
->buffer
))
1845 else if (MINI_WINDOW_P (w
)
1846 && (EQ (minibuf
, Qlambda
)
1847 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
1849 /* If MINIBUF is `lambda' don't consider any mini-windows.
1850 If it is a window, consider only that one. */
1853 else if (EQ (all_frames
, Qt
))
1855 else if (NILP (all_frames
))
1857 xassert (WINDOWP (owindow
));
1858 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
1860 else if (EQ (all_frames
, Qvisible
))
1862 FRAME_SAMPLE_VISIBILITY (f
);
1863 candidate_p
= FRAME_VISIBLE_P (f
)
1864 && (FRAME_TERMINAL (XFRAME (w
->frame
))
1865 == FRAME_TERMINAL (XFRAME (selected_frame
)));
1868 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
1870 FRAME_SAMPLE_VISIBILITY (f
);
1871 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
1872 #ifdef HAVE_X_WINDOWS
1873 /* Yuck!! If we've just created the frame and the
1874 window-manager requested the user to place it
1875 manually, the window may still not be considered
1876 `visible'. I'd argue it should be at least
1877 something like `iconified', but don't know how to do
1879 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
1880 && !f
->output_data
.x
->has_been_visible
)
1883 && (FRAME_TERMINAL (XFRAME (w
->frame
))
1884 == FRAME_TERMINAL (XFRAME (selected_frame
)));
1886 else if (WINDOWP (all_frames
))
1887 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
1888 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
1889 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
1890 else if (FRAMEP (all_frames
))
1891 candidate_p
= EQ (all_frames
, w
->frame
);
1897 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1898 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1902 decode_next_window_args (window
, minibuf
, all_frames
)
1903 Lisp_Object
*window
, *minibuf
, *all_frames
;
1906 *window
= selected_window
;
1908 CHECK_LIVE_WINDOW (*window
);
1910 /* MINIBUF nil may or may not include minibuffers. Decide if it
1912 if (NILP (*minibuf
))
1913 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
1914 else if (!EQ (*minibuf
, Qt
))
1917 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1918 => count none of them, or a specific minibuffer window (the
1919 active one) to count. */
1921 /* ALL_FRAMES nil doesn't specify which frames to include. */
1922 if (NILP (*all_frames
))
1923 *all_frames
= (!EQ (*minibuf
, Qlambda
)
1924 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
1926 else if (EQ (*all_frames
, Qvisible
))
1928 else if (EQ (*all_frames
, make_number (0)))
1930 else if (FRAMEP (*all_frames
))
1932 else if (!EQ (*all_frames
, Qt
))
1935 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1936 search just current frame, `visible' meaning search just visible
1937 frames, 0 meaning search visible and iconified frames, or a
1938 window, meaning search the frame that window belongs to, or a
1939 frame, meaning consider windows on that frame, only. */
1943 /* Return the next or previous window of WINDOW in cyclic ordering
1944 of windows. NEXT_P non-zero means return the next window. See the
1945 documentation string of next-window for the meaning of MINIBUF and
1949 next_window (window
, minibuf
, all_frames
, next_p
)
1950 Lisp_Object window
, minibuf
, all_frames
;
1953 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1955 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1956 return the first window on the frame. */
1957 if (FRAMEP (all_frames
)
1958 && !EQ (all_frames
, XWINDOW (window
)->frame
))
1959 return Fframe_first_window (all_frames
);
1965 /* Find WINDOW in the list of all windows. */
1966 list
= Fmemq (window
, window_list ());
1968 /* Scan forward from WINDOW to the end of the window list. */
1970 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
1971 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1974 /* Scan from the start of the window list up to WINDOW. */
1976 for (list
= Vwindow_list
;
1977 CONSP (list
) && !EQ (XCAR (list
), window
);
1979 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1983 window
= XCAR (list
);
1987 Lisp_Object candidate
, list
;
1989 /* Scan through the list of windows for candidates. If there are
1990 candidate windows in front of WINDOW, the last one of these
1991 is the one we want. If there are candidates following WINDOW
1992 in the list, again the last one of these is the one we want. */
1994 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
1996 if (EQ (XCAR (list
), window
))
1998 if (WINDOWP (candidate
))
2001 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
2003 candidate
= XCAR (list
);
2006 if (WINDOWP (candidate
))
2014 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
2015 doc
: /* Return window following WINDOW in cyclic ordering of windows.
2016 WINDOW defaults to the selected window. The optional arguments
2017 MINIBUF and ALL-FRAMES specify the set of windows to consider.
2019 MINIBUF t means consider the minibuffer window even if the
2020 minibuffer is not active. MINIBUF nil or omitted means consider
2021 the minibuffer window only if the minibuffer is active. Any
2022 other value means do not consider the minibuffer window even if
2023 the minibuffer is active.
2025 Several frames may share a single minibuffer; if the minibuffer
2026 is active, all windows on all frames that share that minibuffer
2027 are considered too. Therefore, if you are using a separate
2028 minibuffer frame and the minibuffer is active and MINIBUF says it
2029 counts, `next-window' considers the windows in the frame from
2030 which you entered the minibuffer, as well as the minibuffer
2033 ALL-FRAMES nil or omitted means consider all windows on WINDOW's
2034 frame, plus the minibuffer window if specified by the MINIBUF
2035 argument, see above. If the minibuffer counts, consider all
2036 windows on all frames that share that minibuffer too.
2037 ALL-FRAMES t means consider all windows on all existing frames.
2038 ALL-FRAMES `visible' means consider all windows on all visible
2040 ALL-FRAMES 0 means consider all windows on all visible and
2042 ALL-FRAMES a frame means consider all windows on that frame only.
2043 Anything else means consider all windows on WINDOW's frame and no
2046 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2047 `next-window' to iterate through the entire cycle of acceptable
2048 windows, eventually ending up back at the window you started with.
2049 `previous-window' traverses the same cycle, in the reverse order. */)
2050 (window
, minibuf
, all_frames
)
2051 Lisp_Object window
, minibuf
, all_frames
;
2053 return next_window (window
, minibuf
, all_frames
, 1);
2057 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
2058 doc
: /* Return window preceding WINDOW in cyclic ordering of windows.
2059 WINDOW defaults to the selected window. The optional arguments
2060 MINIBUF and ALL-FRAMES specify the set of windows to consider.
2061 For the precise meaning of these arguments see `next-window'.
2063 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2064 use `previous-window' to iterate through the entire cycle of
2065 acceptable windows, eventually ending up back at the window you
2066 started with. `next-window' traverses the same cycle, in the
2068 (window
, minibuf
, all_frames
)
2069 Lisp_Object window
, minibuf
, all_frames
;
2071 return next_window (window
, minibuf
, all_frames
, 0);
2075 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
2076 doc
: /* Select another window in cyclic ordering of windows.
2077 COUNT specifies the number of windows to skip, starting with the
2078 selected window, before making the selection. If COUNT is
2079 positive, skip COUNT windows forwards. If COUNT is negative,
2080 skip -COUNT windows backwards. COUNT zero means do not skip any
2081 window, so select the selected window. In an interactive call,
2082 COUNT is the numeric prefix argument. Return nil.
2084 This function uses `next-window' for finding the window to select.
2085 The argument ALL-FRAMES has the same meaning as in `next-window',
2086 but the MINIBUF argument of `next-window' is always effectively
2089 Lisp_Object count
, all_frames
;
2094 CHECK_NUMBER (count
);
2095 window
= selected_window
;
2097 for (i
= XINT (count
); i
> 0; --i
)
2098 window
= Fnext_window (window
, Qnil
, all_frames
);
2100 window
= Fprevious_window (window
, Qnil
, all_frames
);
2102 Fselect_window (window
, Qnil
);
2107 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2108 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2109 FRAME nil or omitted means use the selected frame.
2110 WINDOW nil or omitted means use the selected window.
2111 MINIBUF t means include the minibuffer window, even if it isn't active.
2112 MINIBUF nil or omitted means include the minibuffer window only
2114 MINIBUF neither nil nor t means never include the minibuffer window. */)
2115 (frame
, minibuf
, window
)
2116 Lisp_Object frame
, minibuf
, window
;
2119 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2120 CHECK_WINDOW (window
);
2122 frame
= selected_frame
;
2124 if (!EQ (frame
, XWINDOW (window
)->frame
))
2125 error ("Window is on a different frame");
2127 return window_list_1 (window
, minibuf
, frame
);
2131 /* Return a list of windows in cyclic ordering. Arguments are like
2132 for `next-window'. */
2135 window_list_1 (window
, minibuf
, all_frames
)
2136 Lisp_Object window
, minibuf
, all_frames
;
2138 Lisp_Object tail
, list
, rest
;
2140 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2143 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2144 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2145 list
= Fcons (XCAR (tail
), list
);
2147 /* Rotate the list to start with WINDOW. */
2148 list
= Fnreverse (list
);
2149 rest
= Fmemq (window
, list
);
2150 if (!NILP (rest
) && !EQ (rest
, list
))
2152 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2154 XSETCDR (tail
, Qnil
);
2155 list
= nconc2 (rest
, list
);
2162 /* Look at all windows, performing an operation specified by TYPE
2164 If FRAMES is Qt, look at all frames;
2165 Qnil, look at just the selected frame;
2166 Qvisible, look at visible frames;
2167 a frame, just look at windows on that frame.
2168 If MINI is non-zero, perform the operation on minibuffer windows too. */
2173 GET_BUFFER_WINDOW
, /* Arg is buffer */
2174 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
2175 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
2176 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
2178 UNSHOW_BUFFER
, /* Arg is buffer */
2179 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2184 window_loop (type
, obj
, mini
, frames
)
2185 enum window_loop type
;
2186 Lisp_Object obj
, frames
;
2189 Lisp_Object window
, windows
, best_window
, frame_arg
;
2191 struct gcpro gcpro1
;
2193 /* If we're only looping through windows on a particular frame,
2194 frame points to that frame. If we're looping through windows
2195 on all frames, frame is 0. */
2196 if (FRAMEP (frames
))
2197 f
= XFRAME (frames
);
2198 else if (NILP (frames
))
2199 f
= SELECTED_FRAME ();
2204 frame_arg
= Qlambda
;
2205 else if (EQ (frames
, make_number (0)))
2207 else if (EQ (frames
, Qvisible
))
2212 /* frame_arg is Qlambda to stick to one frame,
2213 Qvisible to consider all visible frames,
2216 /* Pick a window to start with. */
2220 window
= FRAME_SELECTED_WINDOW (f
);
2222 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2224 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2228 for (; CONSP (windows
); windows
= XCDR (windows
))
2232 window
= XCAR (windows
);
2233 w
= XWINDOW (window
);
2235 /* Note that we do not pay attention here to whether the frame
2236 is visible, since Fwindow_list skips non-visible frames if
2237 that is desired, under the control of frame_arg. */
2238 if (!MINI_WINDOW_P (w
)
2239 /* For UNSHOW_BUFFER, we must always consider all windows. */
2240 || type
== UNSHOW_BUFFER
2241 || (mini
&& minibuf_level
> 0))
2244 case GET_BUFFER_WINDOW
:
2245 if (EQ (w
->buffer
, obj
)
2246 /* Don't find any minibuffer window
2247 except the one that is currently in use. */
2248 && (MINI_WINDOW_P (w
)
2249 ? EQ (window
, minibuf_window
)
2252 if (NILP (best_window
))
2253 best_window
= window
;
2254 else if (EQ (window
, selected_window
))
2255 /* Prefer to return selected-window. */
2256 RETURN_UNGCPRO (window
);
2257 else if (EQ (Fwindow_frame (window
), selected_frame
))
2258 /* Prefer windows on the current frame. */
2259 best_window
= window
;
2263 case GET_LRU_WINDOW
:
2264 /* `obj' is an integer encoding a bitvector.
2265 `obj & 1' means consider only full-width windows.
2266 `obj & 2' means consider also dedicated windows. */
2267 if (((XINT (obj
) & 1) && !WINDOW_FULL_WIDTH_P (w
))
2268 || (!(XINT (obj
) & 2) && !NILP (w
->dedicated
))
2269 /* Minibuffer windows are always ignored. */
2270 || MINI_WINDOW_P (w
))
2272 if (NILP (best_window
)
2273 || (XFASTINT (XWINDOW (best_window
)->use_time
)
2274 > XFASTINT (w
->use_time
)))
2275 best_window
= window
;
2278 case DELETE_OTHER_WINDOWS
:
2279 if (!EQ (window
, obj
))
2280 Fdelete_window (window
);
2283 case DELETE_BUFFER_WINDOWS
:
2284 if (EQ (w
->buffer
, obj
))
2286 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2288 /* If this window is dedicated, and in a frame of its own,
2290 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
2291 && !NILP (w
->dedicated
)
2292 && other_visible_frames (f
))
2294 /* Skip the other windows on this frame.
2295 There might be one, the minibuffer! */
2296 while (CONSP (XCDR (windows
))
2297 && EQ (XWINDOW (XCAR (windows
))->frame
,
2298 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2299 windows
= XCDR (windows
);
2301 /* Now we can safely delete the frame. */
2302 delete_frame (w
->frame
, Qnil
);
2304 else if (NILP (w
->parent
))
2306 /* If we're deleting the buffer displayed in the
2307 only window on the frame, find a new buffer to
2310 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2311 /* Reset dedicated state of window. */
2312 w
->dedicated
= Qnil
;
2313 Fset_window_buffer (window
, buffer
, Qnil
);
2314 if (EQ (window
, selected_window
))
2315 Fset_buffer (w
->buffer
);
2318 Fdelete_window (window
);
2322 case GET_LARGEST_WINDOW
:
2323 { /* nil `obj' means to ignore dedicated windows. */
2324 /* Ignore dedicated windows and minibuffers. */
2325 if (MINI_WINDOW_P (w
) || (NILP (obj
) && !NILP (w
->dedicated
)))
2328 if (NILP (best_window
))
2329 best_window
= window
;
2332 struct window
*b
= XWINDOW (best_window
);
2333 if (XFASTINT (w
->total_lines
) * XFASTINT (w
->total_cols
)
2334 > XFASTINT (b
->total_lines
) * XFASTINT (b
->total_cols
))
2335 best_window
= window
;
2341 if (EQ (w
->buffer
, obj
))
2344 struct frame
*f
= XFRAME (w
->frame
);
2346 /* Find another buffer to show in this window. */
2347 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2349 /* If this window is dedicated, and in a frame of its own,
2351 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
2352 && !NILP (w
->dedicated
)
2353 && other_visible_frames (f
))
2355 /* Skip the other windows on this frame.
2356 There might be one, the minibuffer! */
2357 while (CONSP (XCDR (windows
))
2358 && EQ (XWINDOW (XCAR (windows
))->frame
,
2359 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2360 windows
= XCDR (windows
);
2362 /* Now we can safely delete the frame. */
2363 delete_frame (w
->frame
, Qnil
);
2365 else if (!NILP (w
->dedicated
) && !NILP (w
->parent
))
2368 XSETWINDOW (window
, w
);
2369 /* If this window is dedicated and not the only window
2370 in its frame, then kill it. */
2371 Fdelete_window (window
);
2375 /* Otherwise show a different buffer in the window. */
2376 w
->dedicated
= Qnil
;
2377 Fset_window_buffer (window
, buffer
, Qnil
);
2378 if (EQ (window
, selected_window
))
2379 Fset_buffer (w
->buffer
);
2384 case REDISPLAY_BUFFER_WINDOWS
:
2385 if (EQ (w
->buffer
, obj
))
2387 mark_window_display_accurate (window
, 0);
2388 w
->update_mode_line
= Qt
;
2389 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2390 ++update_mode_lines
;
2391 best_window
= window
;
2395 /* Check for a window that has a killed buffer. */
2396 case CHECK_ALL_WINDOWS
:
2397 if (! NILP (w
->buffer
)
2398 && NILP (XBUFFER (w
->buffer
)->name
))
2402 case WINDOW_LOOP_UNUSED
:
2411 /* Used for debugging. Abort if any window has a dead buffer. */
2414 check_all_windows ()
2416 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2419 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 2, 0,
2420 doc
: /* Return the window least recently selected or used for display.
2421 \(LRU means Least Recently Used.)
2423 Return a full-width window if possible.
2424 A minibuffer window is never a candidate.
2425 A dedicated window is never a candidate, unless DEDICATED is non-nil,
2426 so if all windows are dedicated, the value is nil.
2427 If optional argument FRAME is `visible', search all visible frames.
2428 If FRAME is 0, search all visible and iconified frames.
2429 If FRAME is t, search all frames.
2430 If FRAME is nil, search only the selected frame.
2431 If FRAME is a frame, search only that frame. */)
2433 Lisp_Object frame
, dedicated
;
2435 register Lisp_Object w
;
2436 /* First try for a window that is full-width */
2437 w
= window_loop (GET_LRU_WINDOW
,
2438 NILP (dedicated
) ? make_number (1) : make_number (3),
2440 if (!NILP (w
) && !EQ (w
, selected_window
))
2442 /* If none of them, try the rest */
2443 return window_loop (GET_LRU_WINDOW
,
2444 NILP (dedicated
) ? make_number (0) : make_number (2),
2448 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 2, 0,
2449 doc
: /* Return the largest window in area.
2450 A minibuffer window is never a candidate.
2451 A dedicated window is never a candidate unless DEDICATED is non-nil,
2452 so if all windows are dedicated, the value is nil.
2453 If optional argument FRAME is `visible', search all visible frames.
2454 If FRAME is 0, search all visible and iconified frames.
2455 If FRAME is t, search all frames.
2456 If FRAME is nil, search only the selected frame.
2457 If FRAME is a frame, search only that frame. */)
2459 Lisp_Object frame
, dedicated
;
2461 return window_loop (GET_LARGEST_WINDOW
, dedicated
, 0,
2465 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 0, 2, 0,
2466 doc
: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2467 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to the
2469 If optional argument FRAME is `visible', search all visible frames.
2470 If optional argument FRAME is 0, search all visible and iconified frames.
2471 If FRAME is t, search all frames.
2472 If FRAME is nil, search only the selected frame.
2473 If FRAME is a frame, search only that frame. */)
2474 (buffer_or_name
, frame
)
2475 Lisp_Object buffer_or_name
, frame
;
2479 if (NILP (buffer_or_name
))
2480 buffer
= Fcurrent_buffer ();
2482 buffer
= Fget_buffer (buffer_or_name
);
2484 if (BUFFERP (buffer
))
2485 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
2490 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
2492 doc
: /* Make WINDOW (or the selected window) fill its frame.
2493 Only the frame WINDOW is on is affected.
2494 This function tries to reduce display jumps by keeping the text
2495 previously visible in WINDOW in the same place on the frame. Doing this
2496 depends on the value of (window-start WINDOW), so if calling this
2497 function in a program gives strange scrolling, make sure the
2498 window-start value is reasonable when this function is called. */)
2507 window
= selected_window
;
2509 CHECK_LIVE_WINDOW (window
);
2510 w
= XWINDOW (window
);
2512 startpos
= marker_position (w
->start
);
2513 top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2515 if (MINI_WINDOW_P (w
) && top
> 0)
2516 error ("Can't expand minibuffer to full frame");
2518 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
2520 /* Try to minimize scrolling, by setting the window start to the point
2521 will cause the text at the old window start to be at the same place
2522 on the frame. But don't try to do this if the window start is
2523 outside the visible portion (as might happen when the display is
2524 not current, due to typeahead). */
2525 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2527 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2528 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2530 struct position pos
;
2531 struct buffer
*obuf
= current_buffer
;
2533 Fset_buffer (w
->buffer
);
2534 /* This computation used to temporarily move point, but that can
2535 have unwanted side effects due to text properties. */
2536 pos
= *vmotion (startpos
, -top
, w
);
2538 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2539 w
->window_end_valid
= Qnil
;
2540 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
2541 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
2543 /* We need to do this, so that the window-scroll-functions
2545 w
->optional_new_start
= Qt
;
2547 set_buffer_internal (obuf
);
2553 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
2554 0, 2, "bDelete windows on (buffer): ",
2555 doc
: /* Delete all windows showing BUFFER-OR-NAME.
2556 BUFFER-OR-NAME may be a buffer or the name of an existing buffer and
2557 defaults to the current buffer.
2559 Optional second argument FRAME controls which frames are affected.
2560 If optional argument FRAME is `visible', search all visible frames.
2561 If FRAME is 0, search all visible and iconified frames.
2562 If FRAME is nil, search all frames.
2563 If FRAME is t, search only the selected frame.
2564 If FRAME is a frame, search only that frame.
2565 When a window showing BUFFER-OR-NAME is dedicated and the only window of
2566 its frame, that frame is deleted when there are other frames left. */)
2567 (buffer_or_name
, frame
)
2568 Lisp_Object buffer_or_name
, frame
;
2572 /* FRAME uses t and nil to mean the opposite of what window_loop
2576 else if (EQ (frame
, Qt
))
2579 if (NILP (buffer_or_name
))
2580 buffer
= Fcurrent_buffer ();
2583 buffer
= Fget_buffer (buffer_or_name
);
2584 CHECK_BUFFER (buffer
);
2587 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
2592 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
2593 Sreplace_buffer_in_windows
,
2594 0, 1, "bReplace buffer in windows: ",
2595 doc
: /* Replace BUFFER-OR-NAME with some other buffer in all windows showing it.
2596 BUFFER-OR-NAME may be a buffer or the name of an existing buffer and
2597 defaults to the current buffer.
2599 When a window showing BUFFER-OR-NAME is dedicated that window is
2600 deleted. If that window is the only window on its frame, that frame is
2601 deleted too when there are other frames left. If there are no other
2602 frames left, some other buffer is displayed in that window. */)
2604 Lisp_Object buffer_or_name
;
2608 if (NILP (buffer_or_name
))
2609 buffer
= Fcurrent_buffer ();
2612 buffer
= Fget_buffer (buffer_or_name
);
2613 CHECK_BUFFER (buffer
);
2616 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
2621 /* Replace BUFFER with some other buffer in all windows
2622 of all frames, even those on other keyboards. */
2625 replace_buffer_in_all_windows (buffer
)
2628 Lisp_Object tail
, frame
;
2630 /* A single call to window_loop won't do the job
2631 because it only considers frames on the current keyboard.
2632 So loop manually over frames, and handle each one. */
2633 FOR_EACH_FRAME (tail
, frame
)
2634 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
2637 /* Set the height of WINDOW and all its inferiors. */
2639 /* The smallest acceptable dimensions for a window. Anything smaller
2640 might crash Emacs. */
2642 #define MIN_SAFE_WINDOW_WIDTH (2)
2643 #define MIN_SAFE_WINDOW_HEIGHT (1)
2645 /* For wp non-zero the total number of columns of window w. Otherwise
2646 the total number of lines of w. */
2648 #define WINDOW_TOTAL_SIZE(w, wp) \
2649 (wp ? WINDOW_TOTAL_COLS (w) : WINDOW_TOTAL_LINES (w))
2651 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2652 minimum allowable size. */
2655 check_frame_size (frame
, rows
, cols
)
2659 /* For height, we have to see:
2660 how many windows the frame has at minimum (one or two),
2661 and whether it has a menu bar or other special stuff at the top. */
2663 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
2664 ? MIN_SAFE_WINDOW_HEIGHT
2665 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
2667 if (FRAME_TOP_MARGIN (frame
) > 0)
2668 min_height
+= FRAME_TOP_MARGIN (frame
);
2670 if (*rows
< min_height
)
2672 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2673 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2676 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2677 check if W's width can be changed, otherwise check W's height.
2678 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2679 siblings, too. If none of the siblings is resizable, WINDOW isn't
2683 window_fixed_size_p (w
, width_p
, check_siblings_p
)
2685 int width_p
, check_siblings_p
;
2690 if (!NILP (w
->hchild
))
2692 c
= XWINDOW (w
->hchild
);
2696 /* A horizontal combination is fixed-width if all of if its
2698 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2699 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2700 fixed_p
= c
== NULL
;
2704 /* A horizontal combination is fixed-height if one of if its
2706 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2707 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2708 fixed_p
= c
!= NULL
;
2711 else if (!NILP (w
->vchild
))
2713 c
= XWINDOW (w
->vchild
);
2717 /* A vertical combination is fixed-width if one of if its
2719 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2720 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2721 fixed_p
= c
!= NULL
;
2725 /* A vertical combination is fixed-height if all of if its
2727 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2728 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2729 fixed_p
= c
== NULL
;
2732 else if (BUFFERP (w
->buffer
))
2734 struct buffer
*old
= current_buffer
;
2737 current_buffer
= XBUFFER (w
->buffer
);
2738 val
= find_symbol_value (Qwindow_size_fixed
);
2739 current_buffer
= old
;
2742 if (!EQ (val
, Qunbound
))
2744 fixed_p
= !NILP (val
);
2747 && ((EQ (val
, Qheight
) && width_p
)
2748 || (EQ (val
, Qwidth
) && !width_p
)))
2752 /* Can't tell if this one is resizable without looking at
2753 siblings. If all siblings are fixed-size this one is too. */
2754 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
2758 for (child
= w
->prev
; WINDOWP (child
); child
= XWINDOW (child
)->prev
)
2759 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2763 for (child
= w
->next
; WINDOWP (child
); child
= XWINDOW (child
)->next
)
2764 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2777 /* Return minimum size of leaf window W. WIDTH_P non-zero means return
2778 the minimum width of W, WIDTH_P zero means return the minimum height
2779 of W. SAFE_P non-zero means ignore window-min-height|width but just
2780 return values that won't crash Emacs and don't hide components like
2781 fringes, scrollbars, or modelines. If WIDTH_P is zero and W is the
2782 minibuffer window, always return 1. */
2785 window_min_size_2 (w
, width_p
, safe_p
)
2787 int width_p
, safe_p
;
2789 /* We should consider buffer-local values of window_min_height and
2790 window_min_width here. */
2793 int safe_size
= (MIN_SAFE_WINDOW_WIDTH
2794 + WINDOW_FRINGE_COLS (w
)
2795 + WINDOW_SCROLL_BAR_COLS (w
));
2797 return safe_p
? safe_size
: max (window_min_width
, safe_size
);
2799 else if (MINI_WINDOW_P (w
))
2803 int safe_size
= (MIN_SAFE_WINDOW_HEIGHT
2804 + ((BUFFERP (w
->buffer
)
2805 && !NILP (XBUFFER (w
->buffer
)->mode_line_format
))
2808 return safe_p
? safe_size
: max (window_min_height
, safe_size
);
2812 /* Return minimum size of window W, not taking fixed-width windows into
2813 account. WIDTH_P non-zero means return the minimum width, otherwise
2814 return the minimum height. SAFE_P non-zero means ignore
2815 window-min-height|width but just return values that won't crash Emacs
2816 and don't hide components like fringes, scrollbars, or modelines. If
2817 W is a combination window, compute the minimum size from the minimum
2818 sizes of W's children. */
2821 window_min_size_1 (w
, width_p
, safe_p
)
2823 int width_p
, safe_p
;
2828 if (!NILP (w
->hchild
))
2830 /* W is a horizontal combination. */
2831 c
= XWINDOW (w
->hchild
);
2836 /* The minimum width of a horizontal combination is the sum of
2837 the minimum widths of its children. */
2840 size
+= window_min_size_1 (c
, 1, safe_p
);
2841 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2846 /* The minimum height of a horizontal combination is the
2847 maximum of the minimum heights of its children. */
2850 size
= max (window_min_size_1 (c
, 0, safe_p
), size
);
2851 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2855 else if (!NILP (w
->vchild
))
2857 /* W is a vertical combination. */
2858 c
= XWINDOW (w
->vchild
);
2863 /* The minimum width of a vertical combination is the maximum
2864 of the minimum widths of its children. */
2867 size
= max (window_min_size_1 (c
, 1, safe_p
), size
);
2868 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2873 /* The minimum height of a vertical combination is the sum of
2874 the minimum height of its children. */
2877 size
+= window_min_size_1 (c
, 0, safe_p
);
2878 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2883 /* W is a leaf window. */
2884 size
= window_min_size_2 (w
, width_p
, safe_p
);
2889 /* Return the minimum size of window W, taking fixed-size windows into
2890 account. WIDTH_P non-zero means return the minimum width, otherwise
2891 return the minimum height. SAFE_P non-zero means ignore
2892 window-min-height|width but just return values that won't crash Emacs
2893 and don't hide components like fringes, scrollbars, or modelines.
2894 IGNORE_FIXED_P non-zero means ignore if W is fixed-size. Set *FIXED
2895 to 1 if W is fixed-size unless FIXED is null. */
2898 window_min_size (w
, width_p
, safe_p
, ignore_fixed_p
, fixed
)
2900 int width_p
, safe_p
, ignore_fixed_p
, *fixed
;
2907 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
2913 size
= WINDOW_TOTAL_SIZE (w
, width_p
);
2915 size
= window_min_size_1 (w
, width_p
, safe_p
);
2921 /* Adjust the margins of window W if text area is too small.
2922 Return 1 if window width is ok after adjustment; 0 if window
2923 is still too narrow. */
2926 adjust_window_margins (w
)
2929 int box_cols
= (WINDOW_TOTAL_COLS (w
)
2930 - WINDOW_FRINGE_COLS (w
)
2931 - WINDOW_SCROLL_BAR_COLS (w
));
2932 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
2933 + WINDOW_RIGHT_MARGIN_COLS (w
));
2935 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
2938 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
2941 /* Window's text area is too narrow, but reducing the window
2942 margins will fix that. */
2943 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
2944 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
2946 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
2947 w
->left_margin_cols
= w
->right_margin_cols
2948 = make_number (margin_cols
/2);
2950 w
->right_margin_cols
= make_number (margin_cols
);
2953 w
->left_margin_cols
= make_number (margin_cols
);
2957 /* Calculate new sizes for windows in the list FORWARD when their
2958 compound size goes from TOTAL to SIZE. TOTAL must be greater than
2959 SIZE. The number of windows in FORWARD is NCHILDREN, and the number
2960 that can shrink is SHRINKABLE. Fixed-size windows may be shrunk if
2961 and only if RESIZE_FIXED_P is non-zero. WIDTH_P non-zero means
2962 shrink columns, otherwise shrink lines.
2964 SAFE_P zero means windows may be sized down to window-min-height
2965 lines (window-min-window columns for WIDTH_P non-zero). SAFE_P
2966 non-zero means windows may be sized down to their minimum safe sizes
2967 taking into account the space needed to display modelines, fringes,
2970 This function returns an allocated array of new sizes that the caller
2971 must free. A size -1 means the window is fixed and RESIZE_FIXED_P is
2972 zero. A size zero means the window shall be deleted. Array index 0
2973 refers to the first window in FORWARD, 1 to the second, and so on.
2975 This function resizes windows proportionally to their size. It also
2976 tries to preserve smaller windows by resizing larger windows before
2977 resizing any window to zero. If resize_proportionally is non-nil for
2978 a specific window, it will attempt to strictly resize that window
2979 proportionally, even at the expense of deleting smaller windows. */
2981 shrink_windows (total
, size
, nchildren
, shrinkable
, resize_fixed_p
,
2982 forward
, width_p
, safe_p
)
2983 int total
, size
, nchildren
, shrinkable
;
2984 int resize_fixed_p
, width_p
, safe_p
;
2985 Lisp_Object forward
;
2987 int available_resize
= 0;
2988 int *new_sizes
, *min_sizes
;
2991 int smallest
= total
;
2992 int total_removed
= 0;
2993 int total_shrink
= total
- size
;
2996 new_sizes
= xmalloc (sizeof (*new_sizes
) * nchildren
);
2997 min_sizes
= xmalloc (sizeof (*min_sizes
) * nchildren
);
2999 for (i
= 0, child
= forward
; !NILP (child
); child
= c
->next
, ++i
)
3003 c
= XWINDOW (child
);
3004 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3006 if (!resize_fixed_p
&& window_fixed_size_p (c
, width_p
, 0))
3010 new_sizes
[i
] = child_size
;
3011 min_sizes
[i
] = window_min_size_1 (c
, width_p
, safe_p
);
3012 if (child_size
> min_sizes
[i
]
3013 && NILP (c
->resize_proportionally
))
3014 available_resize
+= child_size
- min_sizes
[i
];
3017 /* We might need to shrink some windows to zero. Find the smallest
3018 windows and set them to 0 until we can fulfil the new size. */
3020 while (shrinkable
> 1 && size
+ available_resize
< total
)
3022 for (i
= 0; i
< nchildren
; ++i
)
3023 if (new_sizes
[i
] > 0 && smallest
> new_sizes
[i
])
3024 smallest
= new_sizes
[i
];
3026 for (i
= 0; i
< nchildren
; ++i
)
3027 if (new_sizes
[i
] == smallest
)
3029 /* Resize this window down to zero. */
3031 if (smallest
> min_sizes
[i
])
3032 available_resize
-= smallest
- min_sizes
[i
];
3033 available_resize
+= smallest
;
3035 total_removed
+= smallest
;
3037 /* We don't know what the smallest is now. */
3040 /* Out of for, just remove one window at the time and
3041 check again if we have enough space. */
3046 /* Now, calculate the new sizes. Try to shrink each window
3047 proportional to its size. */
3048 for (i
= 0; i
< nchildren
; ++i
)
3050 if (new_sizes
[i
] > min_sizes
[i
])
3052 int to_shrink
= total_shrink
* new_sizes
[i
] / total
;
3054 if (new_sizes
[i
] - to_shrink
< min_sizes
[i
])
3055 to_shrink
= new_sizes
[i
] - min_sizes
[i
];
3056 new_sizes
[i
] -= to_shrink
;
3057 total_removed
+= to_shrink
;
3061 /* Any reminder due to rounding, we just subtract from windows
3062 that are left and still can be shrunk. */
3063 while (total_shrink
> total_removed
)
3065 int nonzero_sizes
= 0;
3066 int nonzero_idx
= -1;
3068 for (i
= 0; i
< nchildren
; ++i
)
3069 if (new_sizes
[i
] > 0)
3075 for (i
= 0; i
< nchildren
; ++i
)
3076 if (new_sizes
[i
] > min_sizes
[i
])
3081 /* Out of for, just shrink one window at the time and
3082 check again if we have enough space. */
3086 /* Special case, only one window left. */
3087 if (nonzero_sizes
== 1)
3091 /* Any surplus due to rounding, we add to windows that are left. */
3092 while (total_shrink
< total_removed
)
3094 for (i
= 0; i
< nchildren
; ++i
)
3096 if (new_sizes
[i
] != 0 && total_shrink
< total_removed
)
3110 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
3111 WINDOW's width. Resize WINDOW's children, if any, so that they keep
3112 their proportionate size relative to WINDOW.
3114 If FIRST_ONLY is 1, change only the first of WINDOW's children when
3115 they are in series. If LAST_ONLY is 1, change only the last of
3116 WINDOW's children when they are in series.
3118 Propagate WINDOW's top or left edge position to children. Delete
3119 windows that become too small unless NODELETE_P is 1. When
3120 NODELETE_P equals 2 do not honor settings for window-min-height and
3121 window-min-width when resizing windows but use safe defaults instead.
3122 This should give better behavior when resizing frames. */
3125 size_window (window
, size
, width_p
, nodelete_p
, first_only
, last_only
)
3127 int size
, width_p
, nodelete_p
;
3128 int first_only
, last_only
;
3130 struct window
*w
= XWINDOW (window
);
3132 Lisp_Object child
, *forward
, *sideward
;
3133 int old_size
= WINDOW_TOTAL_SIZE (w
, width_p
);
3135 size
= max (0, size
);
3137 /* Delete WINDOW if it's too small. */
3138 if (nodelete_p
!= 1 && !NILP (w
->parent
)
3139 && size
< window_min_size_1 (w
, width_p
, nodelete_p
== 2))
3141 delete_window (window
);
3145 /* Set redisplay hints. */
3146 w
->last_modified
= make_number (0);
3147 w
->last_overlay_modified
= make_number (0);
3148 windows_or_buffers_changed
++;
3149 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w
->frame
)) = 1;
3153 sideward
= &w
->vchild
;
3154 forward
= &w
->hchild
;
3155 w
->total_cols
= make_number (size
);
3156 adjust_window_margins (w
);
3160 sideward
= &w
->hchild
;
3161 forward
= &w
->vchild
;
3162 w
->total_lines
= make_number (size
);
3163 w
->orig_total_lines
= Qnil
;
3166 if (!NILP (*sideward
))
3168 /* We have a chain of parallel siblings whose size should all change. */
3169 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
3171 c
= XWINDOW (child
);
3173 c
->left_col
= w
->left_col
;
3175 c
->top_line
= w
->top_line
;
3176 size_window (child
, size
, width_p
, nodelete_p
,
3177 first_only
, last_only
);
3180 else if (!NILP (*forward
) && last_only
)
3182 /* Change the last in a series of siblings. */
3183 Lisp_Object last_child
;
3186 for (child
= *forward
; !NILP (child
); child
= c
->next
)
3188 c
= XWINDOW (child
);
3192 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3193 size_window (last_child
, size
- old_size
+ child_size
,
3194 width_p
, nodelete_p
, first_only
, last_only
);
3196 else if (!NILP (*forward
) && first_only
)
3198 /* Change the first in a series of siblings. */
3202 c
= XWINDOW (child
);
3205 c
->left_col
= w
->left_col
;
3207 c
->top_line
= w
->top_line
;
3209 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3210 size_window (child
, size
- old_size
+ child_size
,
3211 width_p
, nodelete_p
, first_only
, last_only
);
3213 else if (!NILP (*forward
))
3215 int fixed_size
, each
, extra
, n
;
3216 int resize_fixed_p
, nfixed
;
3217 int last_pos
, first_pos
, nchildren
, total
;
3218 int *new_sizes
= NULL
;
3220 /* Determine the fixed-size portion of this window, and the
3221 number of child windows. */
3222 fixed_size
= nchildren
= nfixed
= total
= 0;
3223 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
3227 c
= XWINDOW (child
);
3228 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3229 total
+= child_size
;
3231 if (window_fixed_size_p (c
, width_p
, 0))
3233 fixed_size
+= child_size
;
3238 /* If the new size is smaller than fixed_size, or if there
3239 aren't any resizable windows, allow resizing fixed-size
3241 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
3243 /* Compute how many lines/columns to add/remove to each child. The
3244 value of extra takes care of rounding errors. */
3245 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
3246 if (size
< total
&& n
> 1)
3247 new_sizes
= shrink_windows (total
, size
, nchildren
, n
,
3248 resize_fixed_p
, *forward
, width_p
,
3252 each
= (size
- total
) / n
;
3253 extra
= (size
- total
) - n
* each
;
3256 /* Compute new children heights and edge positions. */
3257 first_pos
= width_p
? XINT (w
->left_col
) : XINT (w
->top_line
);
3258 last_pos
= first_pos
;
3259 for (n
= 0, child
= *forward
; !NILP (child
); child
= c
->next
, ++n
)
3261 int new_size
, old_size
;
3263 c
= XWINDOW (child
);
3264 old_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3265 new_size
= old_size
;
3267 /* The top or left edge position of this child equals the
3268 bottom or right edge of its predecessor. */
3270 c
->left_col
= make_number (last_pos
);
3272 c
->top_line
= make_number (last_pos
);
3274 /* If this child can be resized, do it. */
3275 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
3277 new_size
= new_sizes
? new_sizes
[n
] : old_size
+ each
+ extra
;
3281 /* Set new size. Note that size_window also propagates
3282 edge positions to children, so it's not a no-op if we
3283 didn't change the child's size. */
3284 size_window (child
, new_size
, width_p
, 1, first_only
, last_only
);
3286 /* Remember the bottom/right edge position of this child; it
3287 will be used to set the top/left edge of the next child. */
3288 last_pos
+= new_size
;
3293 /* We should have covered the parent exactly with child windows. */
3294 xassert (size
== last_pos
- first_pos
);
3296 /* Now delete any children that became too small. */
3297 if (nodelete_p
!= 1)
3298 for (child
= *forward
; !NILP (child
); child
= c
->next
)
3302 c
= XWINDOW (child
);
3303 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3304 size_window (child
, child_size
, width_p
, nodelete_p
,
3305 first_only
, last_only
);
3310 /* Set WINDOW's height to HEIGHT, and recursively change the height of
3311 WINDOW's children. NODELETE zero means windows that have become
3312 smaller than window-min-height in the process may be deleted.
3313 NODELETE 1 means never delete windows that become too small in the
3314 process. (The caller should check later and do so if appropriate.)
3315 NODELETE 2 means delete only windows that have become too small to be
3316 displayed correctly. */
3319 set_window_height (window
, height
, nodelete
)
3324 size_window (window
, height
, 0, nodelete
, 0, 0);
3327 /* Set WINDOW's width to WIDTH, and recursively change the width of
3328 WINDOW's children. NODELETE zero means windows that have become
3329 smaller than window-min-width in the process may be deleted.
3330 NODELETE 1 means never delete windows that become too small in the
3331 process. (The caller should check later and do so if appropriate.)
3332 NODELETE 2 means delete only windows that have become too small to be
3333 displayed correctly. */
3336 set_window_width (window
, width
, nodelete
)
3341 size_window (window
, width
, 1, nodelete
, 0, 0);
3344 /* Change window heights in windows rooted in WINDOW by N lines. */
3347 change_window_heights (window
, n
)
3351 struct window
*w
= XWINDOW (window
);
3353 XSETFASTINT (w
->top_line
, XFASTINT (w
->top_line
) + n
);
3354 XSETFASTINT (w
->total_lines
, XFASTINT (w
->total_lines
) - n
);
3356 if (INTEGERP (w
->orig_top_line
))
3357 XSETFASTINT (w
->orig_top_line
, XFASTINT (w
->orig_top_line
) + n
);
3358 if (INTEGERP (w
->orig_total_lines
))
3359 XSETFASTINT (w
->orig_total_lines
, XFASTINT (w
->orig_total_lines
) - n
);
3361 /* Handle just the top child in a vertical split. */
3362 if (!NILP (w
->vchild
))
3363 change_window_heights (w
->vchild
, n
);
3365 /* Adjust all children in a horizontal split. */
3366 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
3368 w
= XWINDOW (window
);
3369 change_window_heights (window
, n
);
3374 int window_select_count
;
3376 EXFUN (Fset_window_fringes
, 4);
3377 EXFUN (Fset_window_scroll_bars
, 4);
3380 run_funs (Lisp_Object funs
)
3382 for (; CONSP (funs
); funs
= XCDR (funs
))
3383 if (!EQ (XCAR (funs
), Qt
))
3384 call0 (XCAR (funs
));
3387 static Lisp_Object
select_window_norecord (Lisp_Object window
);
3388 static Lisp_Object
select_frame_norecord (Lisp_Object frame
);
3391 run_window_configuration_change_hook (struct frame
*f
)
3393 int count
= SPECPDL_INDEX ();
3394 Lisp_Object frame
, global_wcch
3395 = Fdefault_value (Qwindow_configuration_change_hook
);
3396 XSETFRAME (frame
, f
);
3398 if (NILP (Vrun_hooks
))
3401 if (SELECTED_FRAME () != f
)
3403 record_unwind_protect (select_frame_norecord
, Fselected_frame ());
3404 Fselect_frame (frame
, Qt
);
3407 /* Use the right buffer. Matters when running the local hooks. */
3408 if (current_buffer
!= XBUFFER (Fwindow_buffer (Qnil
)))
3410 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
3411 Fset_buffer (Fwindow_buffer (Qnil
));
3414 /* Look for buffer-local values. */
3416 Lisp_Object windows
= Fwindow_list (frame
, Qlambda
, Qnil
);
3417 for (; CONSP (windows
); windows
= XCDR (windows
))
3419 Lisp_Object window
= XCAR (windows
);
3420 Lisp_Object buffer
= Fwindow_buffer (window
);
3421 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook
,
3424 int count
= SPECPDL_INDEX ();
3425 record_unwind_protect (select_window_norecord
, Fselected_window ());
3426 select_window_norecord (window
);
3427 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook
,
3429 unbind_to (count
, Qnil
);
3434 run_funs (global_wcch
);
3435 unbind_to (count
, Qnil
);
3438 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
3439 means it's allowed to run hooks. See make_frame for a case where
3440 it's not allowed. KEEP_MARGINS_P non-zero means that the current
3441 margins, fringes, and scroll-bar settings of the window are not
3442 reset from the buffer's local settings. */
3445 set_window_buffer (window
, buffer
, run_hooks_p
, keep_margins_p
)
3446 Lisp_Object window
, buffer
;
3447 int run_hooks_p
, keep_margins_p
;
3449 struct window
*w
= XWINDOW (window
);
3450 struct buffer
*b
= XBUFFER (buffer
);
3451 int count
= SPECPDL_INDEX ();
3452 int samebuf
= EQ (buffer
, w
->buffer
);
3456 if (EQ (window
, selected_window
))
3457 b
->last_selected_window
= window
;
3459 /* Let redisplay errors through. */
3460 b
->display_error_modiff
= 0;
3462 /* Update time stamps of buffer display. */
3463 if (INTEGERP (b
->display_count
))
3464 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
3465 b
->display_time
= Fcurrent_time ();
3467 XSETFASTINT (w
->window_end_pos
, 0);
3468 XSETFASTINT (w
->window_end_vpos
, 0);
3469 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
3470 w
->window_end_valid
= Qnil
;
3471 if (!(keep_margins_p
&& samebuf
))
3472 { /* If we're not actually changing the buffer, don't reset hscroll and
3473 vscroll. This case happens for example when called from
3474 change_frame_size_1, where we use a dummy call to
3475 Fset_window_buffer on the frame's selected window (and no other)
3476 just in order to run window-configuration-change-hook.
3477 Resetting hscroll and vscroll here is problematic for things like
3478 image-mode and doc-view-mode since it resets the image's position
3479 whenever we resize the frame. */
3480 w
->hscroll
= w
->min_hscroll
= make_number (0);
3482 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3483 set_marker_restricted (w
->start
,
3484 make_number (b
->last_window_start
),
3486 w
->start_at_line_beg
= Qnil
;
3487 w
->force_start
= Qnil
;
3488 XSETFASTINT (w
->last_modified
, 0);
3489 XSETFASTINT (w
->last_overlay_modified
, 0);
3491 /* Maybe we could move this into the `if' but it's not obviously safe and
3492 I doubt it's worth the trouble. */
3493 windows_or_buffers_changed
++;
3495 /* We must select BUFFER for running the window-scroll-functions. */
3496 /* We can't check ! NILP (Vwindow_scroll_functions) here
3497 because that might itself be a local variable. */
3498 if (window_initialized
)
3500 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
3501 Fset_buffer (buffer
);
3504 XMARKER (w
->pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3506 if (!keep_margins_p
)
3508 /* Set left and right marginal area width etc. from buffer. */
3510 /* This may call adjust_window_margins three times, so
3511 temporarily disable window margins. */
3512 Lisp_Object save_left
= w
->left_margin_cols
;
3513 Lisp_Object save_right
= w
->right_margin_cols
;
3515 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
3517 Fset_window_fringes (window
,
3518 b
->left_fringe_width
, b
->right_fringe_width
,
3519 b
->fringes_outside_margins
);
3521 Fset_window_scroll_bars (window
,
3522 b
->scroll_bar_width
,
3523 b
->vertical_scroll_bar_type
, Qnil
);
3525 w
->left_margin_cols
= save_left
;
3526 w
->right_margin_cols
= save_right
;
3528 Fset_window_margins (window
,
3529 b
->left_margin_cols
, b
->right_margin_cols
);
3534 if (! NILP (Vwindow_scroll_functions
))
3535 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3536 Fmarker_position (w
->start
));
3537 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w
)));
3540 unbind_to (count
, Qnil
);
3544 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3545 doc
: /* Make WINDOW display BUFFER-OR-NAME as its contents.
3546 WINDOW defaults to the selected window. BUFFER-OR-NAME must be a buffer
3547 or the name of an existing buffer. Optional third argument KEEP-MARGINS
3548 non-nil means that WINDOW's current display margins, fringe widths, and
3549 scroll bar settings are preserved; the default is to reset these from
3550 the local settings for BUFFER-OR-NAME or the frame defaults. Return nil.
3552 This function throws an error when WINDOW is strongly dedicated to its
3553 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3554 already display BUFFER-OR-NAME.
3556 This function runs `window-scroll-functions' before running
3557 `window-configuration-change-hook'. */)
3558 (window
, buffer_or_name
, keep_margins
)
3559 register Lisp_Object window
, buffer_or_name
, keep_margins
;
3561 register Lisp_Object tem
, buffer
;
3562 register struct window
*w
= decode_window (window
);
3564 XSETWINDOW (window
, w
);
3565 buffer
= Fget_buffer (buffer_or_name
);
3566 CHECK_BUFFER (buffer
);
3567 if (NILP (XBUFFER (buffer
)->name
))
3568 error ("Attempt to display deleted buffer");
3572 error ("Window is deleted");
3573 else if (!EQ (tem
, Qt
))
3574 /* w->buffer is t when the window is first being set up. */
3576 if (!EQ (tem
, buffer
))
3577 if (EQ (w
->dedicated
, Qt
))
3578 error ("Window is dedicated to `%s'", SDATA (XBUFFER (tem
)->name
));
3580 w
->dedicated
= Qnil
;
3585 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3589 /* Note that selected_window can be nil when this is called from
3590 Fset_window_configuration. */
3592 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
3593 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
3594 If WINDOW is not already selected, make WINDOW's buffer current
3595 and make WINDOW the frame's selected window. Return WINDOW.
3596 Optional second arg NORECORD non-nil means do not put this buffer
3597 at the front of the list of recently selected ones and do not
3598 make this window the most recently selected one.
3600 Note that the main editor command loop selects the buffer of the
3601 selected window before each command. */)
3603 register Lisp_Object window
, norecord
;
3605 register struct window
*w
;
3606 register struct window
*ow
;
3609 CHECK_LIVE_WINDOW (window
);
3611 w
= XWINDOW (window
);
3612 w
->frozen_window_start_p
= 0;
3614 if (NILP (norecord
))
3616 ++window_select_count
;
3617 XSETFASTINT (w
->use_time
, window_select_count
);
3620 if (EQ (window
, selected_window
))
3623 sf
= SELECTED_FRAME ();
3624 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
3626 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
3627 /* Use this rather than Fhandle_switch_frame
3628 so that FRAME_FOCUS_FRAME is moved appropriately as we
3629 move around in the state where a minibuffer in a separate
3631 Fselect_frame (WINDOW_FRAME (w
), norecord
);
3632 /* Fselect_frame called us back so we've done all the work already. */
3633 eassert (EQ (window
, selected_window
));
3637 sf
->selected_window
= window
;
3639 /* Store the current buffer's actual point into the
3640 old selected window. It belongs to that window,
3641 and when the window is not selected, must be in the window. */
3642 if (!NILP (selected_window
))
3644 ow
= XWINDOW (selected_window
);
3645 if (! NILP (ow
->buffer
))
3646 set_marker_both (ow
->pointm
, ow
->buffer
,
3647 BUF_PT (XBUFFER (ow
->buffer
)),
3648 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
3651 selected_window
= window
;
3653 if (NILP (norecord
))
3654 record_buffer (w
->buffer
);
3655 Fset_buffer (w
->buffer
);
3657 XBUFFER (w
->buffer
)->last_selected_window
= window
;
3659 /* Go to the point recorded in the window.
3660 This is important when the buffer is in more
3661 than one window. It also matters when
3662 redisplay_window has altered point after scrolling,
3663 because it makes the change only in the window. */
3665 register int new_point
= marker_position (w
->pointm
);
3666 if (new_point
< BEGV
)
3668 else if (new_point
> ZV
)
3674 windows_or_buffers_changed
++;
3679 select_window_norecord (window
)
3682 return WINDOW_LIVE_P (window
)
3683 ? Fselect_window (window
, Qt
) : selected_window
;
3687 select_frame_norecord (frame
)
3690 return FRAME_LIVE_P (XFRAME (frame
))
3691 ? Fselect_frame (frame
, Qt
) : selected_frame
;
3695 display_buffer (buffer
, not_this_window_p
, override_frame
)
3696 Lisp_Object buffer
, not_this_window_p
, override_frame
;
3698 return call3 (Qdisplay_buffer
, buffer
, not_this_window_p
, override_frame
);
3701 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3703 doc
: /* Force all windows to be updated on next redisplay.
3704 If optional arg OBJECT is a window, force redisplay of that window only.
3705 If OBJECT is a buffer or buffer name, force redisplay of all windows
3706 displaying that buffer. */)
3712 windows_or_buffers_changed
++;
3713 update_mode_lines
++;
3717 if (WINDOWP (object
))
3719 struct window
*w
= XWINDOW (object
);
3720 mark_window_display_accurate (object
, 0);
3721 w
->update_mode_line
= Qt
;
3722 if (BUFFERP (w
->buffer
))
3723 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
3724 ++update_mode_lines
;
3728 if (STRINGP (object
))
3729 object
= Fget_buffer (object
);
3730 if (BUFFERP (object
) && !NILP (XBUFFER (object
)->name
))
3732 /* Walk all windows looking for buffer, and force update
3733 of each of those windows. */
3735 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3736 return NILP (object
) ? Qnil
: Qt
;
3739 /* If nothing suitable was found, just return.
3740 We could signal an error, but this feature will typically be used
3741 asynchronously in timers or process sentinels, so we don't. */
3747 temp_output_buffer_show (buf
)
3748 register Lisp_Object buf
;
3750 register struct buffer
*old
= current_buffer
;
3751 register Lisp_Object window
;
3752 register struct window
*w
;
3754 XBUFFER (buf
)->directory
= current_buffer
->directory
;
3757 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3761 #if 0 /* rms: there should be no reason for this. */
3762 XBUFFER (buf
)->prevent_redisplay_optimizations_p
= 1;
3764 set_buffer_internal (old
);
3766 if (!NILP (Vtemp_buffer_show_function
))
3767 call1 (Vtemp_buffer_show_function
, buf
);
3770 window
= display_buffer (buf
, Qnil
, Qnil
);
3772 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3773 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3774 Vminibuf_scroll_window
= window
;
3775 w
= XWINDOW (window
);
3776 XSETFASTINT (w
->hscroll
, 0);
3777 XSETFASTINT (w
->min_hscroll
, 0);
3778 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3779 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3781 /* Run temp-buffer-show-hook, with the chosen window selected
3782 and its buffer current. */
3784 if (!NILP (Vrun_hooks
)
3785 && !NILP (Fboundp (Qtemp_buffer_show_hook
))
3786 && !NILP (Fsymbol_value (Qtemp_buffer_show_hook
)))
3788 int count
= SPECPDL_INDEX ();
3789 Lisp_Object prev_window
, prev_buffer
;
3790 prev_window
= selected_window
;
3791 XSETBUFFER (prev_buffer
, old
);
3793 /* Select the window that was chosen, for running the hook.
3794 Note: Both Fselect_window and select_window_norecord may
3795 set-buffer to the buffer displayed in the window,
3796 so we need to save the current buffer. --stef */
3797 record_unwind_protect (Fset_buffer
, prev_buffer
);
3798 record_unwind_protect (select_window_norecord
, prev_window
);
3799 Fselect_window (window
, Qt
);
3800 Fset_buffer (w
->buffer
);
3801 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
3802 unbind_to (count
, Qnil
);
3808 make_dummy_parent (window
)
3812 register struct window
*o
, *p
;
3815 o
= XWINDOW (window
);
3816 p
= allocate_window ();
3817 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
3818 ((struct Lisp_Vector
*) p
)->contents
[i
]
3819 = ((struct Lisp_Vector
*)o
)->contents
[i
];
3820 XSETWINDOW (new, p
);
3823 XSETFASTINT (p
->sequence_number
, sequence_number
);
3825 /* Put new into window structure in place of window */
3826 replace_window (window
, new);
3839 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
3840 doc
: /* Split WINDOW, putting SIZE lines in the first of the pair.
3841 WINDOW defaults to selected one and SIZE to half its size.
3842 If optional third arg HORIZONTAL is non-nil, split side by side and put
3843 SIZE columns in the first of the pair. In that case, SIZE includes that
3844 window's scroll bar, or the divider column to its right.
3845 Interactively, all arguments are nil.
3846 Returns the newly created window (which is the lower or rightmost one).
3847 The upper or leftmost window is the original one, and remains selected
3848 if it was selected before.
3850 See Info node `(elisp)Splitting Windows' for more details and examples. */)
3851 (window
, size
, horizontal
)
3852 Lisp_Object window
, size
, horizontal
;
3854 register Lisp_Object
new;
3855 register struct window
*o
, *p
;
3857 register int size_int
;
3860 window
= selected_window
;
3862 CHECK_LIVE_WINDOW (window
);
3864 o
= XWINDOW (window
);
3865 fo
= XFRAME (WINDOW_FRAME (o
));
3869 if (!NILP (horizontal
))
3870 /* Calculate the size of the left-hand window, by dividing
3871 the usable space in columns by two.
3872 We round up, since the left-hand window may include
3873 a dividing line, while the right-hand may not. */
3874 size_int
= (XFASTINT (o
->total_cols
) + 1) >> 1;
3876 size_int
= XFASTINT (o
->total_lines
) >> 1;
3880 CHECK_NUMBER (size
);
3881 size_int
= XINT (size
);
3884 if (MINI_WINDOW_P (o
))
3885 error ("Attempt to split minibuffer window");
3886 else if (window_fixed_size_p (o
, !NILP (horizontal
), 0))
3887 error ("Attempt to split fixed-size window");
3889 if (NILP (horizontal
))
3891 int window_safe_height
= window_min_size_2 (o
, 0, 0);
3893 if (size_int
< window_safe_height
)
3894 error ("Window height %d too small (after splitting)", size_int
);
3895 if (size_int
+ window_safe_height
> XFASTINT (o
->total_lines
))
3896 error ("Window height %d too small (after splitting)",
3897 XFASTINT (o
->total_lines
) - size_int
);
3898 if (NILP (o
->parent
)
3899 || NILP (XWINDOW (o
->parent
)->vchild
))
3901 make_dummy_parent (window
);
3903 XWINDOW (new)->vchild
= window
;
3908 int window_safe_width
= window_min_size_2 (o
, 1, 0);
3910 if (size_int
< window_safe_width
)
3911 error ("Window width %d too small (after splitting)", size_int
);
3912 if (size_int
+ window_safe_width
> XFASTINT (o
->total_cols
))
3913 error ("Window width %d too small (after splitting)",
3914 XFASTINT (o
->total_cols
) - size_int
);
3915 if (NILP (o
->parent
)
3916 || NILP (XWINDOW (o
->parent
)->hchild
))
3918 make_dummy_parent (window
);
3920 XWINDOW (new)->hchild
= window
;
3924 /* Now we know that window's parent is a vertical combination
3925 if we are dividing vertically, or a horizontal combination
3926 if we are making side-by-side windows */
3928 windows_or_buffers_changed
++;
3929 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
3930 new = make_window ();
3933 p
->frame
= o
->frame
;
3935 if (!NILP (p
->next
))
3936 XWINDOW (p
->next
)->prev
= new;
3939 p
->parent
= o
->parent
;
3941 p
->window_end_valid
= Qnil
;
3942 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
3944 /* Duplicate special geometry settings. */
3946 p
->left_margin_cols
= o
->left_margin_cols
;
3947 p
->right_margin_cols
= o
->right_margin_cols
;
3948 p
->left_fringe_width
= o
->left_fringe_width
;
3949 p
->right_fringe_width
= o
->right_fringe_width
;
3950 p
->fringes_outside_margins
= o
->fringes_outside_margins
;
3951 p
->scroll_bar_width
= o
->scroll_bar_width
;
3952 p
->vertical_scroll_bar_type
= o
->vertical_scroll_bar_type
;
3954 /* Apportion the available frame space among the two new windows */
3956 if (!NILP (horizontal
))
3958 p
->total_lines
= o
->total_lines
;
3959 p
->top_line
= o
->top_line
;
3960 XSETFASTINT (p
->total_cols
, XFASTINT (o
->total_cols
) - size_int
);
3961 XSETFASTINT (o
->total_cols
, size_int
);
3962 XSETFASTINT (p
->left_col
, XFASTINT (o
->left_col
) + size_int
);
3963 adjust_window_margins (p
);
3964 adjust_window_margins (o
);
3968 p
->left_col
= o
->left_col
;
3969 p
->total_cols
= o
->total_cols
;
3970 XSETFASTINT (p
->total_lines
, XFASTINT (o
->total_lines
) - size_int
);
3971 XSETFASTINT (o
->total_lines
, size_int
);
3972 XSETFASTINT (p
->top_line
, XFASTINT (o
->top_line
) + size_int
);
3975 /* Adjust glyph matrices. */
3978 Fset_window_buffer (new, o
->buffer
, Qt
);
3982 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
3983 doc
: /* Make selected window SIZE lines taller.
3984 Interactively, if no argument is given, make the selected window one
3985 line taller. If optional argument HORIZONTAL is non-nil, make selected
3986 window wider by SIZE columns. If SIZE is negative, shrink the window by
3987 -SIZE lines or columns. Return nil.
3989 This function can delete windows if they get too small. The size of
3990 fixed size windows is not altered by this function. */)
3992 Lisp_Object size
, horizontal
;
3994 CHECK_NUMBER (size
);
3995 enlarge_window (selected_window
, XINT (size
), !NILP (horizontal
));
3997 run_window_configuration_change_hook (SELECTED_FRAME ());
4002 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
4003 doc
: /* Make selected window SIZE lines smaller.
4004 Interactively, if no argument is given, make the selected window one
4005 line smaller. If optional argument HORIZONTAL is non-nil, make the
4006 window narrower by SIZE columns. If SIZE is negative, enlarge selected
4007 window by -SIZE lines or columns. Return nil.
4009 This function can delete windows if they get too small. The size of
4010 fixed size windows is not altered by this function. */)
4012 Lisp_Object size
, horizontal
;
4014 CHECK_NUMBER (size
);
4015 enlarge_window (selected_window
, -XINT (size
), !NILP (horizontal
));
4017 run_window_configuration_change_hook (SELECTED_FRAME ());
4023 window_height (window
)
4026 register struct window
*p
= XWINDOW (window
);
4027 return WINDOW_TOTAL_LINES (p
);
4031 window_width (window
)
4034 register struct window
*p
= XWINDOW (window
);
4035 return WINDOW_TOTAL_COLS (p
);
4040 *(horiz_flag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line))
4042 #define CURSIZE(w) \
4043 *(horiz_flag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines))
4046 /* Enlarge WINDOW by DELTA. HORIZ_FLAG nonzero means enlarge it
4047 horizontally; zero means do it vertically.
4049 Siblings of the selected window are resized to fulfill the size
4050 request. If they become too small in the process, they may be
4054 enlarge_window (window
, delta
, horiz_flag
)
4056 int delta
, horiz_flag
;
4058 Lisp_Object parent
, next
, prev
;
4062 int (*sizefun
) P_ ((Lisp_Object
))
4063 = horiz_flag
? window_width
: window_height
;
4064 void (*setsizefun
) P_ ((Lisp_Object
, int, int))
4065 = (horiz_flag
? set_window_width
: set_window_height
);
4067 /* Give up if this window cannot be resized. */
4068 if (window_fixed_size_p (XWINDOW (window
), horiz_flag
, 1))
4069 error ("Window is not resizable");
4071 /* Find the parent of the selected window. */
4074 p
= XWINDOW (window
);
4080 error ("No other window to side of this one");
4085 ? !NILP (XWINDOW (parent
)->hchild
)
4086 : !NILP (XWINDOW (parent
)->vchild
))
4092 sizep
= &CURSIZE (window
);
4095 register int maxdelta
;
4097 /* Compute the maximum size increment this window can have. */
4099 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - XINT (*sizep
)
4100 /* This is a main window followed by a minibuffer. */
4101 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
4102 - window_min_size (XWINDOW (p
->next
),
4103 horiz_flag
, 0, 0, 0))
4104 /* This is a minibuffer following a main window. */
4105 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
4106 - window_min_size (XWINDOW (p
->prev
),
4107 horiz_flag
, 0, 0, 0))
4108 /* This is a frame with only one window, a minibuffer-only
4109 or a minibufferless frame. */
4112 if (delta
> maxdelta
)
4113 /* This case traps trying to make the minibuffer
4114 the full frame, or make the only window aside from the
4115 minibuffer the full frame. */
4119 if (XINT (*sizep
) + delta
< window_min_size (XWINDOW (window
),
4120 horiz_flag
, 0, 0, 0))
4122 delete_window (window
);
4129 /* Find the total we can get from other siblings without deleting them. */
4131 for (next
= p
->next
; WINDOWP (next
); next
= XWINDOW (next
)->next
)
4132 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
4133 horiz_flag
, 0, 0, 0);
4134 for (prev
= p
->prev
; WINDOWP (prev
); prev
= XWINDOW (prev
)->prev
)
4135 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
4136 horiz_flag
, 0, 0, 0);
4138 /* If we can get it all from them without deleting them, do so. */
4139 if (delta
<= maximum
)
4141 Lisp_Object first_unaffected
;
4142 Lisp_Object first_affected
;
4147 first_affected
= window
;
4148 /* Look at one sibling at a time,
4149 moving away from this window in both directions alternately,
4150 and take as much as we can get without deleting that sibling. */
4152 && (!NILP (next
) || !NILP (prev
)))
4156 int this_one
= ((*sizefun
) (next
)
4157 - window_min_size (XWINDOW (next
), horiz_flag
,
4161 if (this_one
> delta
)
4164 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
4165 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4170 next
= XWINDOW (next
)->next
;
4178 int this_one
= ((*sizefun
) (prev
)
4179 - window_min_size (XWINDOW (prev
), horiz_flag
,
4183 if (this_one
> delta
)
4186 first_affected
= prev
;
4188 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
4189 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4194 prev
= XWINDOW (prev
)->prev
;
4198 xassert (delta
== 0);
4200 /* Now recalculate the edge positions of all the windows affected,
4201 based on the new sizes. */
4202 first_unaffected
= next
;
4203 prev
= first_affected
;
4204 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
4205 prev
= next
, next
= XWINDOW (next
)->next
)
4207 XSETINT (CURBEG (next
), XINT (CURBEG (prev
)) + (*sizefun
) (prev
));
4208 /* This does not change size of NEXT,
4209 but it propagates the new top edge to its children */
4210 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
4215 register int delta1
;
4216 register int opht
= (*sizefun
) (parent
);
4218 if (opht
<= XINT (*sizep
) + delta
)
4220 /* If trying to grow this window to or beyond size of the parent,
4221 just delete all the sibling windows. */
4222 Lisp_Object start
, tem
, next
;
4224 start
= XWINDOW (parent
)->vchild
;
4226 start
= XWINDOW (parent
)->hchild
;
4228 /* Delete any siblings that come after WINDOW. */
4229 tem
= XWINDOW (window
)->next
;
4230 while (! NILP (tem
))
4232 next
= XWINDOW (tem
)->next
;
4233 delete_window (tem
);
4237 /* Delete any siblings that come after WINDOW.
4238 Note that if START is not WINDOW, then WINDOW still
4239 has siblings, so WINDOW has not yet replaced its parent. */
4241 while (! EQ (tem
, window
))
4243 next
= XWINDOW (tem
)->next
;
4244 delete_window (tem
);
4250 /* Otherwise, make delta1 just right so that if we add
4251 delta1 lines to this window and to the parent, and then
4252 shrink the parent back to its original size, the new
4253 proportional size of this window will increase by delta.
4255 The function size_window will compute the new height h'
4256 of the window from delta1 as:
4259 x = delta1 - delta1/n * n for the 1st resizable child
4262 where n is the number of children that can be resized.
4263 We can ignore x by choosing a delta1 that is a multiple of
4264 n. We want the height of this window to come out as
4274 The number of children n equals the number of resizable
4275 children of this window + 1 because we know window itself
4276 is resizable (otherwise we would have signaled an error).
4278 This reasoning is not correct when other windows become too
4279 small and shrink_windows refuses to delete them. Below we
4280 use resize_proportionally to work around this problem. */
4282 struct window
*w
= XWINDOW (window
);
4286 for (s
= w
->next
; WINDOWP (s
); s
= XWINDOW (s
)->next
)
4287 if (!window_fixed_size_p (XWINDOW (s
), horiz_flag
, 0))
4289 for (s
= w
->prev
; WINDOWP (s
); s
= XWINDOW (s
)->prev
)
4290 if (!window_fixed_size_p (XWINDOW (s
), horiz_flag
, 0))
4295 /* Add delta1 lines or columns to this window, and to the parent,
4296 keeping things consistent while not affecting siblings. */
4297 XSETINT (CURSIZE (parent
), opht
+ delta1
);
4298 (*setsizefun
) (window
, XINT (*sizep
) + delta1
, 0);
4300 /* Squeeze out delta1 lines or columns from our parent,
4301 shrinking this window and siblings proportionately. This
4302 brings parent back to correct size. Delta1 was calculated
4303 so this makes this window the desired size, taking it all
4304 out of the siblings.
4306 Temporarily set resize_proportionally to Qt to assure that,
4307 if necessary, shrink_windows deletes smaller windows rather
4308 than shrink this window. */
4309 w
->resize_proportionally
= Qt
;
4310 (*setsizefun
) (parent
, opht
, 0);
4311 w
->resize_proportionally
= Qnil
;
4315 XSETFASTINT (p
->last_modified
, 0);
4316 XSETFASTINT (p
->last_overlay_modified
, 0);
4318 /* Adjust glyph matrices. */
4319 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4323 /* Adjust the size of WINDOW by DELTA, moving only its trailing edge.
4324 HORIZ_FLAG nonzero means adjust the width, moving the right edge.
4325 zero means adjust the height, moving the bottom edge.
4327 Following siblings of the selected window are resized to fulfill
4328 the size request. If they become too small in the process, they
4329 are not deleted; instead, we signal an error. */
4332 adjust_window_trailing_edge (window
, delta
, horiz_flag
)
4334 int delta
, horiz_flag
;
4336 Lisp_Object parent
, child
;
4338 Lisp_Object old_config
= Fcurrent_window_configuration (Qnil
);
4339 int delcount
= window_deletion_count
;
4341 CHECK_WINDOW (window
);
4343 /* Give up if this window cannot be resized. */
4344 if (window_fixed_size_p (XWINDOW (window
), horiz_flag
, 1))
4345 error ("Window is not resizable");
4349 Lisp_Object first_parallel
= Qnil
;
4353 /* This happens if WINDOW on the previous iteration was
4354 at top level of the window tree. */
4355 Fset_window_configuration (old_config
);
4356 error ("Specified window edge is fixed");
4359 p
= XWINDOW (window
);
4362 /* See if this level has windows in parallel in the specified
4363 direction. If so, set FIRST_PARALLEL to the first one. */
4366 if (! NILP (parent
) && !NILP (XWINDOW (parent
)->vchild
))
4367 first_parallel
= XWINDOW (parent
)->vchild
;
4368 else if (NILP (parent
) && !NILP (p
->next
))
4370 /* Handle the vertical chain of main window and minibuffer
4371 which has no parent. */
4372 first_parallel
= window
;
4373 while (! NILP (XWINDOW (first_parallel
)->prev
))
4374 first_parallel
= XWINDOW (first_parallel
)->prev
;
4379 if (! NILP (parent
) && !NILP (XWINDOW (parent
)->hchild
))
4380 first_parallel
= XWINDOW (parent
)->hchild
;
4383 /* If this level's succession is in the desired dimension,
4384 and this window is the last one, and there is no higher level,
4385 its trailing edge is fixed. */
4386 if (NILP (XWINDOW (window
)->next
) && NILP (first_parallel
)
4389 Fset_window_configuration (old_config
);
4390 error ("Specified window edge is fixed");
4393 /* Don't make this window too small. */
4394 if (XINT (CURSIZE (window
)) + delta
4395 < window_min_size_2 (XWINDOW (window
), horiz_flag
, 0))
4397 Fset_window_configuration (old_config
);
4398 error ("Cannot adjust window size as specified");
4401 /* Clear out some redisplay caches. */
4402 XSETFASTINT (p
->last_modified
, 0);
4403 XSETFASTINT (p
->last_overlay_modified
, 0);
4405 /* Adjust this window's edge. */
4406 XSETINT (CURSIZE (window
),
4407 XINT (CURSIZE (window
)) + delta
);
4409 /* If this window has following siblings in the desired dimension,
4410 make them smaller, and exit the loop.
4412 (If we reach the top of the tree and can never do this,
4413 we will fail and report an error, above.) */
4414 if (NILP (first_parallel
))
4416 if (!NILP (p
->next
))
4418 /* This may happen for the minibuffer. In that case
4419 the window_deletion_count check below does not work. */
4420 if (XINT (CURSIZE (p
->next
)) - delta
<= 0)
4422 Fset_window_configuration (old_config
);
4423 error ("Cannot adjust window size as specified");
4426 XSETINT (CURBEG (p
->next
),
4427 XINT (CURBEG (p
->next
)) + delta
);
4428 size_window (p
->next
, XINT (CURSIZE (p
->next
)) - delta
,
4429 horiz_flag
, 0, 1, 0);
4434 /* Here we have a chain of parallel siblings, in the other dimension.
4435 Change the size of the other siblings. */
4436 for (child
= first_parallel
;
4438 child
= XWINDOW (child
)->next
)
4439 if (! EQ (child
, window
))
4440 size_window (child
, XINT (CURSIZE (child
)) + delta
,
4441 horiz_flag
, 0, 0, 1);
4446 /* If we made a window so small it got deleted,
4447 we failed. Report failure. */
4448 if (delcount
!= window_deletion_count
)
4450 Fset_window_configuration (old_config
);
4451 error ("Cannot adjust window size as specified");
4454 /* Adjust glyph matrices. */
4455 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4461 DEFUN ("adjust-window-trailing-edge", Fadjust_window_trailing_edge
,
4462 Sadjust_window_trailing_edge
, 3, 3, 0,
4463 doc
: /* Adjust the bottom or right edge of WINDOW by DELTA.
4464 If HORIZONTAL is non-nil, that means adjust the width, moving the right edge.
4465 Otherwise, adjust the height, moving the bottom edge.
4467 Following siblings of the selected window are resized to fulfill
4468 the size request. If they become too small in the process, they
4469 are not deleted; instead, we signal an error. */)
4470 (window
, delta
, horizontal
)
4471 Lisp_Object window
, delta
, horizontal
;
4473 CHECK_NUMBER (delta
);
4475 window
= selected_window
;
4476 adjust_window_trailing_edge (window
, XINT (delta
), !NILP (horizontal
));
4478 run_window_configuration_change_hook
4479 (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4486 /***********************************************************************
4487 Resizing Mini-Windows
4488 ***********************************************************************/
4490 static void shrink_window_lowest_first
P_ ((struct window
*, int));
4492 enum save_restore_action
4499 static int save_restore_orig_size
P_ ((struct window
*,
4500 enum save_restore_action
));
4502 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
4503 from lowest windows first. */
4506 shrink_window_lowest_first (w
, height
)
4514 xassert (!MINI_WINDOW_P (w
));
4516 /* Set redisplay hints. */
4517 XSETFASTINT (w
->last_modified
, 0);
4518 XSETFASTINT (w
->last_overlay_modified
, 0);
4519 windows_or_buffers_changed
++;
4520 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
4522 old_height
= XFASTINT (w
->total_lines
);
4523 XSETFASTINT (w
->total_lines
, height
);
4525 if (!NILP (w
->hchild
))
4527 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
4529 c
= XWINDOW (child
);
4530 c
->top_line
= w
->top_line
;
4531 shrink_window_lowest_first (c
, height
);
4534 else if (!NILP (w
->vchild
))
4536 Lisp_Object last_child
;
4537 int delta
= old_height
- height
;
4542 /* Find the last child. We are taking space from lowest windows
4543 first, so we iterate over children from the last child
4545 for (child
= w
->vchild
; WINDOWP (child
); child
= XWINDOW (child
)->next
)
4548 /* Size children down to their safe heights. */
4549 for (child
= last_child
; delta
&& !NILP (child
); child
= c
->prev
)
4553 c
= XWINDOW (child
);
4554 this_one
= XFASTINT (c
->total_lines
) - window_min_size_1 (c
, 0, 1);
4556 if (this_one
> delta
)
4559 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
) - this_one
);
4563 /* Compute new positions. */
4564 last_top
= XINT (w
->top_line
);
4565 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
4567 c
= XWINDOW (child
);
4568 c
->top_line
= make_number (last_top
);
4569 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
));
4570 last_top
+= XFASTINT (c
->total_lines
);
4576 /* Save, restore, or check positions and sizes in the window tree
4577 rooted at W. ACTION says what to do.
4579 If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and
4580 orig_total_lines members are valid for all windows in the window
4581 tree. Value is non-zero if they are valid.
4583 If ACTION is SAVE_ORIG_SIZES, save members top and height in
4584 orig_top_line and orig_total_lines for all windows in the tree.
4586 If ACTION is RESTORE_ORIG_SIZES, restore top and height from values
4587 stored in orig_top_line and orig_total_lines for all windows. */
4590 save_restore_orig_size (w
, action
)
4592 enum save_restore_action action
;
4598 if (!NILP (w
->hchild
))
4600 if (!save_restore_orig_size (XWINDOW (w
->hchild
), action
))
4603 else if (!NILP (w
->vchild
))
4605 if (!save_restore_orig_size (XWINDOW (w
->vchild
), action
))
4611 case CHECK_ORIG_SIZES
:
4612 if (!INTEGERP (w
->orig_top_line
) || !INTEGERP (w
->orig_total_lines
))
4616 case SAVE_ORIG_SIZES
:
4617 w
->orig_top_line
= w
->top_line
;
4618 w
->orig_total_lines
= w
->total_lines
;
4619 XSETFASTINT (w
->last_modified
, 0);
4620 XSETFASTINT (w
->last_overlay_modified
, 0);
4623 case RESTORE_ORIG_SIZES
:
4624 xassert (INTEGERP (w
->orig_top_line
) && INTEGERP (w
->orig_total_lines
));
4625 w
->top_line
= w
->orig_top_line
;
4626 w
->total_lines
= w
->orig_total_lines
;
4627 w
->orig_total_lines
= w
->orig_top_line
= Qnil
;
4628 XSETFASTINT (w
->last_modified
, 0);
4629 XSETFASTINT (w
->last_overlay_modified
, 0);
4636 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
4643 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
4644 without deleting other windows. */
4647 grow_mini_window (w
, delta
)
4651 struct frame
*f
= XFRAME (w
->frame
);
4652 struct window
*root
;
4654 xassert (MINI_WINDOW_P (w
));
4655 /* Commenting out the following assertion goes against the stated interface
4656 of the function, but it currently does not seem to do anything useful.
4657 See discussion of this issue in the thread for bug#4534.
4658 xassert (delta >= 0); */
4660 /* Compute how much we can enlarge the mini-window without deleting
4662 root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4665 int min_height
= window_min_size (root
, 0, 0, 0, 0);
4666 if (XFASTINT (root
->total_lines
) - delta
< min_height
)
4667 /* Note that the root window may already be smaller than
4669 delta
= max (0, XFASTINT (root
->total_lines
) - min_height
);
4674 /* Save original window sizes and positions, if not already done. */
4675 if (!save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4676 save_restore_orig_size (root
, SAVE_ORIG_SIZES
);
4678 /* Shrink other windows. */
4679 shrink_window_lowest_first (root
, XFASTINT (root
->total_lines
) - delta
);
4681 /* Grow the mini-window. */
4682 w
->top_line
= make_number (XFASTINT (root
->top_line
) + XFASTINT (root
->total_lines
));
4683 w
->total_lines
= make_number (XFASTINT (w
->total_lines
) + delta
);
4684 XSETFASTINT (w
->last_modified
, 0);
4685 XSETFASTINT (w
->last_overlay_modified
, 0);
4692 /* Shrink mini-window W. If there is recorded info about window sizes
4693 before a call to grow_mini_window, restore recorded window sizes.
4694 Otherwise, if the mini-window is higher than 1 line, resize it to 1
4698 shrink_mini_window (w
)
4701 struct frame
*f
= XFRAME (w
->frame
);
4702 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4704 if (save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4706 save_restore_orig_size (root
, RESTORE_ORIG_SIZES
);
4708 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4709 windows_or_buffers_changed
= 1;
4711 else if (XFASTINT (w
->total_lines
) > 1)
4713 /* Distribute the additional lines of the mini-window
4714 among the other windows. */
4716 XSETWINDOW (window
, w
);
4717 enlarge_window (window
, 1 - XFASTINT (w
->total_lines
), 0);
4723 /* Mark window cursors off for all windows in the window tree rooted
4724 at W by setting their phys_cursor_on_p flag to zero. Called from
4725 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4726 the frame are cleared. */
4729 mark_window_cursors_off (w
)
4734 if (!NILP (w
->hchild
))
4735 mark_window_cursors_off (XWINDOW (w
->hchild
));
4736 else if (!NILP (w
->vchild
))
4737 mark_window_cursors_off (XWINDOW (w
->vchild
));
4739 w
->phys_cursor_on_p
= 0;
4741 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4746 /* Return number of lines of text (not counting mode lines) in W. */
4749 window_internal_height (w
)
4752 int ht
= XFASTINT (w
->total_lines
);
4754 if (!MINI_WINDOW_P (w
))
4756 if (!NILP (w
->parent
)
4757 || !NILP (w
->vchild
)
4758 || !NILP (w
->hchild
)
4761 || WINDOW_WANTS_MODELINE_P (w
))
4764 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4772 /* Return the number of columns in W.
4773 Don't count columns occupied by scroll bars or the vertical bar
4774 separating W from the sibling to its right. */
4777 window_box_text_cols (w
)
4780 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4781 int width
= XINT (w
->total_cols
);
4783 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
4784 /* Scroll bars occupy a few columns. */
4785 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
4786 else if (!FRAME_WINDOW_P (f
)
4787 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
4788 /* The column of `|' characters separating side-by-side windows
4789 occupies one column only. */
4792 if (FRAME_WINDOW_P (f
))
4793 /* On window-systems, fringes and display margins cannot be
4794 used for normal text. */
4795 width
-= (WINDOW_FRINGE_COLS (w
)
4796 + WINDOW_LEFT_MARGIN_COLS (w
)
4797 + WINDOW_RIGHT_MARGIN_COLS (w
));
4803 /************************************************************************
4805 ***********************************************************************/
4807 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4808 N screen-fulls, which is defined as the height of the window minus
4809 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4810 instead. Negative values of N mean scroll down. NOERROR non-zero
4811 means don't signal an error if we try to move over BEGV or ZV,
4815 window_scroll (window
, n
, whole
, noerror
)
4823 /* If we must, use the pixel-based version which is much slower than
4824 the line-based one but can handle varying line heights. */
4825 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4826 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4828 window_scroll_line_based (window
, n
, whole
, noerror
);
4834 /* Implementation of window_scroll that works based on pixel line
4835 heights. See the comment of window_scroll for parameter
4839 window_scroll_pixel_based (window
, n
, whole
, noerror
)
4846 struct window
*w
= XWINDOW (window
);
4847 struct text_pos start
;
4848 int this_scroll_margin
;
4849 /* True if we fiddled the window vscroll field without really scrolling. */
4851 int x
, y
, rtop
, rbot
, rowh
, vpos
;
4853 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4855 /* If PT is not visible in WINDOW, move back one half of
4856 the screen. Allow PT to be partially visible, otherwise
4857 something like (scroll-down 1) with PT in the line before
4858 the partially visible one would recenter. */
4860 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
4862 /* Move backward half the height of the window. Performance note:
4863 vmotion used here is about 10% faster, but would give wrong
4864 results for variable height lines. */
4865 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4866 it
.current_y
= it
.last_visible_y
;
4867 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4869 /* The function move_iterator_vertically may move over more than
4870 the specified y-distance. If it->w is small, e.g. a
4871 mini-buffer window, we may end up in front of the window's
4872 display area. This is the case when Start displaying at the
4873 start of the line containing PT in this case. */
4874 if (it
.current_y
<= 0)
4876 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4877 move_it_vertically_backward (&it
, 0);
4881 start
= it
.current
.pos
;
4883 else if (auto_window_vscroll_p
)
4885 if (rtop
|| rbot
) /* partially visible */
4888 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4890 dy
= max ((window_box_height (w
)
4891 - next_screen_context_lines
* dy
),
4897 /* Only vscroll backwards if already vscrolled forwards. */
4898 if (w
->vscroll
< 0 && rtop
> 0)
4900 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
4901 Fset_window_vscroll (window
, make_number (px
), Qt
);
4907 /* Do vscroll if already vscrolled or only display line. */
4908 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
4910 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
4911 Fset_window_vscroll (window
, make_number (px
), Qt
);
4915 /* Maybe modify window start instead of scrolling. */
4916 if (rbot
> 0 || w
->vscroll
< 0)
4920 Fset_window_vscroll (window
, make_number (0), Qt
);
4921 /* If there are other text lines above the current row,
4922 move window start to current row. Else to next row. */
4924 spos
= XINT (Fline_beginning_position (Qnil
));
4926 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
4927 set_marker_restricted (w
->start
, make_number (spos
),
4929 w
->start_at_line_beg
= Qt
;
4930 w
->update_mode_line
= Qt
;
4931 XSETFASTINT (w
->last_modified
, 0);
4932 XSETFASTINT (w
->last_overlay_modified
, 0);
4933 /* Set force_start so that redisplay_window will run the
4934 window-scroll-functions. */
4935 w
->force_start
= Qt
;
4940 /* Cancel previous vscroll. */
4941 Fset_window_vscroll (window
, make_number (0), Qt
);
4944 /* If scroll_preserve_screen_position is non-nil, we try to set
4945 point in the same window line as it is now, so get that line. */
4946 if (!NILP (Vscroll_preserve_screen_position
))
4948 /* We preserve the goal pixel coordinate across consecutive
4949 calls to scroll-up or scroll-down. This avoids the
4950 possibility of point becoming "stuck" on a tall line when
4951 scrolling by one line. */
4952 if (window_scroll_pixel_based_preserve_y
< 0
4953 || NILP (Fmemq (current_kboard
->Vlast_command
,
4954 Vscroll_preserve_screen_position_commands
)))
4956 start_display (&it
, w
, start
);
4957 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4958 window_scroll_pixel_based_preserve_y
= it
.current_y
;
4959 window_scroll_pixel_based_preserve_x
= it
.current_x
;
4963 window_scroll_pixel_based_preserve_y
4964 = window_scroll_pixel_based_preserve_x
= -1;
4966 /* Move iterator it from start the specified distance forward or
4967 backward. The result is the new window start. */
4968 start_display (&it
, w
, start
);
4971 int start_pos
= IT_CHARPOS (it
);
4972 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4973 dy
= max ((window_box_height (w
)
4974 - next_screen_context_lines
* dy
),
4977 /* Note that move_it_vertically always moves the iterator to the
4978 start of a line. So, if the last line doesn't have a newline,
4979 we would end up at the start of the line ending at ZV. */
4982 move_it_vertically_backward (&it
, -dy
);
4983 /* Ensure we actually do move, e.g. in case we are currently
4984 looking at an image that is taller that the window height. */
4985 while (start_pos
== IT_CHARPOS (it
)
4986 && start_pos
> BEGV
)
4987 move_it_by_lines (&it
, -1, 1);
4991 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4992 MOVE_TO_POS
| MOVE_TO_Y
);
4993 /* Ensure we actually do move, e.g. in case we are currently
4994 looking at an image that is taller that the window height. */
4995 while (start_pos
== IT_CHARPOS (it
)
4997 move_it_by_lines (&it
, 1, 1);
5001 move_it_by_lines (&it
, n
, 1);
5003 /* We failed if we find ZV is already on the screen (scrolling up,
5004 means there's nothing past the end), or if we can't start any
5005 earlier (scrolling down, means there's nothing past the top). */
5006 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
5007 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
5009 if (IT_CHARPOS (it
) == ZV
)
5011 if (it
.current_y
< it
.last_visible_y
5012 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
5013 > it
.last_visible_y
))
5015 /* The last line was only partially visible, make it fully
5017 w
->vscroll
= (it
.last_visible_y
5018 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
5019 adjust_glyphs (it
.f
);
5023 else if (n
< 0) /* could happen with empty buffers */
5024 xsignal0 (Qbeginning_of_buffer
);
5026 xsignal0 (Qend_of_buffer
);
5030 if (w
->vscroll
!= 0)
5031 /* The first line was only partially visible, make it fully
5037 xsignal0 (Qbeginning_of_buffer
);
5040 /* If control gets here, then we vscrolled. */
5042 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
5044 /* Don't try to change the window start below. */
5050 int pos
= IT_CHARPOS (it
);
5053 /* If in the middle of a multi-glyph character move forward to
5054 the next character. */
5055 if (in_display_vector_p (&it
))
5058 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
5061 /* Set the window start, and set up the window for redisplay. */
5062 set_marker_restricted (w
->start
, make_number (pos
),
5064 bytepos
= XMARKER (w
->start
)->bytepos
;
5065 w
->start_at_line_beg
= ((pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n')
5067 w
->update_mode_line
= Qt
;
5068 XSETFASTINT (w
->last_modified
, 0);
5069 XSETFASTINT (w
->last_overlay_modified
, 0);
5070 /* Set force_start so that redisplay_window will run the
5071 window-scroll-functions. */
5072 w
->force_start
= Qt
;
5075 /* The rest of this function uses current_y in a nonstandard way,
5076 not including the height of the header line if any. */
5077 it
.current_y
= it
.vpos
= 0;
5079 /* Move PT out of scroll margins.
5080 This code wants current_y to be zero at the window start position
5081 even if there is a header line. */
5082 this_scroll_margin
= max (0, scroll_margin
);
5083 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->total_lines
) / 4);
5084 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
5088 /* We moved the window start towards ZV, so PT may be now
5089 in the scroll margin at the top. */
5090 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5091 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
5092 && (NILP (Vscroll_preserve_screen_position
)
5093 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5094 /* We found PT at a legitimate height. Leave it alone. */
5096 else if (window_scroll_pixel_based_preserve_y
>= 0)
5098 /* If we have a header line, take account of it.
5099 This is necessary because we set it.current_y to 0, above. */
5100 move_it_to (&it
, -1,
5101 window_scroll_pixel_based_preserve_x
,
5102 window_scroll_pixel_based_preserve_y
5103 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
5104 -1, MOVE_TO_Y
| MOVE_TO_X
);
5105 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5109 while (it
.current_y
< this_scroll_margin
)
5111 int prev
= it
.current_y
;
5112 move_it_by_lines (&it
, 1, 1);
5113 if (prev
== it
.current_y
)
5116 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5121 int charpos
, bytepos
;
5124 /* Save our position, for the
5125 window_scroll_pixel_based_preserve_y case. */
5126 charpos
= IT_CHARPOS (it
);
5127 bytepos
= IT_BYTEPOS (it
);
5129 /* We moved the window start towards BEGV, so PT may be now
5130 in the scroll margin at the bottom. */
5131 move_it_to (&it
, PT
, -1,
5132 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
5133 - this_scroll_margin
- 1),
5135 MOVE_TO_POS
| MOVE_TO_Y
);
5137 /* Save our position, in case it's correct. */
5138 charpos
= IT_CHARPOS (it
);
5139 bytepos
= IT_BYTEPOS (it
);
5141 /* See if point is on a partially visible line at the end. */
5142 if (it
.what
== IT_EOB
)
5143 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
5146 move_it_by_lines (&it
, 1, 1);
5147 partial_p
= it
.current_y
> it
.last_visible_y
;
5150 if (charpos
== PT
&& !partial_p
5151 && (NILP (Vscroll_preserve_screen_position
)
5152 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5153 /* We found PT before we found the display margin, so PT is ok. */
5155 else if (window_scroll_pixel_based_preserve_y
>= 0)
5157 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5158 start_display (&it
, w
, start
);
5159 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
5160 here because we called start_display again and did not
5161 alter it.current_y this time. */
5162 move_it_to (&it
, -1, window_scroll_pixel_based_preserve_x
,
5163 window_scroll_pixel_based_preserve_y
, -1,
5164 MOVE_TO_Y
| MOVE_TO_X
);
5165 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5170 /* The last line was only partially visible, so back up two
5171 lines to make sure we're on a fully visible line. */
5173 move_it_by_lines (&it
, -2, 0);
5174 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5177 /* No, the position we saved is OK, so use it. */
5178 SET_PT_BOTH (charpos
, bytepos
);
5184 /* Implementation of window_scroll that works based on screen lines.
5185 See the comment of window_scroll for parameter descriptions. */
5188 window_scroll_line_based (window
, n
, whole
, noerror
)
5194 register struct window
*w
= XWINDOW (window
);
5195 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
5196 register int pos
, pos_byte
;
5197 register int ht
= window_internal_height (w
);
5198 register Lisp_Object tem
;
5202 Lisp_Object original_pos
= Qnil
;
5204 /* If scrolling screen-fulls, compute the number of lines to
5205 scroll from the window's height. */
5207 n
*= max (1, ht
- next_screen_context_lines
);
5209 startpos
= marker_position (w
->start
);
5211 if (!NILP (Vscroll_preserve_screen_position
))
5213 if (window_scroll_preserve_vpos
<= 0
5214 || NILP (Fmemq (current_kboard
->Vlast_command
,
5215 Vscroll_preserve_screen_position_commands
)))
5217 struct position posit
5218 = *compute_motion (startpos
, 0, 0, 0,
5220 -1, XINT (w
->hscroll
),
5222 window_scroll_preserve_vpos
= posit
.vpos
;
5223 window_scroll_preserve_hpos
= posit
.hpos
+ XINT (w
->hscroll
);
5226 original_pos
= Fcons (make_number (window_scroll_preserve_hpos
),
5227 make_number (window_scroll_preserve_vpos
));
5230 XSETFASTINT (tem
, PT
);
5231 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
5235 Fvertical_motion (make_number (- (ht
/ 2)), window
);
5240 lose
= n
< 0 && PT
== BEGV
;
5241 Fvertical_motion (make_number (n
), window
);
5245 SET_PT_BOTH (opoint
, opoint_byte
);
5252 xsignal0 (Qbeginning_of_buffer
);
5257 int this_scroll_margin
= scroll_margin
;
5259 /* Don't use a scroll margin that is negative or too large. */
5260 if (this_scroll_margin
< 0)
5261 this_scroll_margin
= 0;
5263 if (XINT (w
->total_lines
) < 4 * scroll_margin
)
5264 this_scroll_margin
= XINT (w
->total_lines
) / 4;
5266 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
5267 w
->start_at_line_beg
= bolp
;
5268 w
->update_mode_line
= Qt
;
5269 XSETFASTINT (w
->last_modified
, 0);
5270 XSETFASTINT (w
->last_overlay_modified
, 0);
5271 /* Set force_start so that redisplay_window will run
5272 the window-scroll-functions. */
5273 w
->force_start
= Qt
;
5275 if (!NILP (Vscroll_preserve_screen_position
)
5276 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
5278 SET_PT_BOTH (pos
, pos_byte
);
5279 Fvertical_motion (original_pos
, window
);
5281 /* If we scrolled forward, put point enough lines down
5282 that it is outside the scroll margin. */
5287 if (this_scroll_margin
> 0)
5289 SET_PT_BOTH (pos
, pos_byte
);
5290 Fvertical_motion (make_number (this_scroll_margin
), window
);
5296 if (top_margin
<= opoint
)
5297 SET_PT_BOTH (opoint
, opoint_byte
);
5298 else if (!NILP (Vscroll_preserve_screen_position
))
5300 SET_PT_BOTH (pos
, pos_byte
);
5301 Fvertical_motion (original_pos
, window
);
5304 SET_PT (top_margin
);
5310 /* If we scrolled backward, put point near the end of the window
5311 but not within the scroll margin. */
5312 SET_PT_BOTH (pos
, pos_byte
);
5313 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
5314 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
5317 bottom_margin
= PT
+ 1;
5319 if (bottom_margin
> opoint
)
5320 SET_PT_BOTH (opoint
, opoint_byte
);
5323 if (!NILP (Vscroll_preserve_screen_position
))
5325 SET_PT_BOTH (pos
, pos_byte
);
5326 Fvertical_motion (original_pos
, window
);
5329 Fvertical_motion (make_number (-1), window
);
5338 xsignal0 (Qend_of_buffer
);
5343 /* Scroll selected_window up or down. If N is nil, scroll a
5344 screen-full which is defined as the height of the window minus
5345 next_screen_context_lines. If N is the symbol `-', scroll.
5346 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
5347 up. This is the guts of Fscroll_up and Fscroll_down. */
5350 scroll_command (n
, direction
)
5354 int count
= SPECPDL_INDEX ();
5356 xassert (eabs (direction
) == 1);
5358 /* If selected window's buffer isn't current, make it current for
5359 the moment. But don't screw up if window_scroll gets an error. */
5360 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
5362 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5363 Fset_buffer (XWINDOW (selected_window
)->buffer
);
5365 /* Make redisplay consider other windows than just selected_window. */
5366 ++windows_or_buffers_changed
;
5370 window_scroll (selected_window
, direction
, 1, 0);
5371 else if (EQ (n
, Qminus
))
5372 window_scroll (selected_window
, -direction
, 1, 0);
5375 n
= Fprefix_numeric_value (n
);
5376 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
5379 unbind_to (count
, Qnil
);
5382 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "^P",
5383 doc
: /* Scroll text of selected window upward ARG lines.
5384 If ARG is omitted or nil, scroll upward by a near full screen.
5385 A near full screen is `next-screen-context-lines' less than a full screen.
5386 Negative ARG means scroll downward.
5387 If ARG is the atom `-', scroll downward by nearly full screen.
5388 When calling from a program, supply as argument a number, nil, or `-'. */)
5392 scroll_command (arg
, 1);
5396 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "^P",
5397 doc
: /* Scroll text of selected window down ARG lines.
5398 If ARG is omitted or nil, scroll down by a near full screen.
5399 A near full screen is `next-screen-context-lines' less than a full screen.
5400 Negative ARG means scroll upward.
5401 If ARG is the atom `-', scroll upward by nearly full screen.
5402 When calling from a program, supply as argument a number, nil, or `-'. */)
5406 scroll_command (arg
, -1);
5410 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
5411 doc
: /* Return the other window for \"other window scroll\" commands.
5412 If `other-window-scroll-buffer' is non-nil, a window
5413 showing that buffer is used.
5414 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5415 specifies the window. This takes precedence over
5416 `other-window-scroll-buffer'. */)
5421 if (MINI_WINDOW_P (XWINDOW (selected_window
))
5422 && !NILP (Vminibuf_scroll_window
))
5423 window
= Vminibuf_scroll_window
;
5424 /* If buffer is specified, scroll that buffer. */
5425 else if (!NILP (Vother_window_scroll_buffer
))
5427 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
5429 window
= display_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
5433 /* Nothing specified; look for a neighboring window on the same
5435 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
5437 if (EQ (window
, selected_window
))
5438 /* That didn't get us anywhere; look for a window on another
5441 window
= Fnext_window (window
, Qnil
, Qt
);
5442 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
5443 && ! EQ (window
, selected_window
));
5446 CHECK_LIVE_WINDOW (window
);
5448 if (EQ (window
, selected_window
))
5449 error ("There is no other window");
5454 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
5455 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5456 A near full screen is `next-screen-context-lines' less than a full screen.
5457 The next window is the one below the current one; or the one at the top
5458 if the current one is at the bottom. Negative ARG means scroll downward.
5459 If ARG is the atom `-', scroll downward by nearly full screen.
5460 When calling from a program, supply as argument a number, nil, or `-'.
5462 If `other-window-scroll-buffer' is non-nil, scroll the window
5463 showing that buffer, popping the buffer up if necessary.
5464 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5465 specifies the window to scroll. This takes precedence over
5466 `other-window-scroll-buffer'. */)
5472 int count
= SPECPDL_INDEX ();
5474 window
= Fother_window_for_scrolling ();
5475 w
= XWINDOW (window
);
5477 /* Don't screw up if window_scroll gets an error. */
5478 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5479 ++windows_or_buffers_changed
;
5481 Fset_buffer (w
->buffer
);
5482 SET_PT (marker_position (w
->pointm
));
5485 window_scroll (window
, 1, 1, 1);
5486 else if (EQ (arg
, Qminus
))
5487 window_scroll (window
, -1, 1, 1);
5493 window_scroll (window
, XINT (arg
), 0, 1);
5496 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5497 unbind_to (count
, Qnil
);
5502 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "^P\np",
5503 doc
: /* Scroll selected window display ARG columns left.
5504 Default for ARG is window width minus 2.
5505 Value is the total amount of leftward horizontal scrolling in
5506 effect after the change.
5507 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5508 lower bound for automatic scrolling, i.e. automatic scrolling
5509 will not scroll a window to a column less than the value returned
5510 by this function. This happens in an interactive call. */)
5512 register Lisp_Object arg
, set_minimum
;
5516 struct window
*w
= XWINDOW (selected_window
);
5519 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5521 arg
= Fprefix_numeric_value (arg
);
5523 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
5524 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5526 if (!NILP (set_minimum
))
5527 w
->min_hscroll
= w
->hscroll
;
5532 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "^P\np",
5533 doc
: /* Scroll selected window display ARG columns right.
5534 Default for ARG is window width minus 2.
5535 Value is the total amount of leftward horizontal scrolling in
5536 effect after the change.
5537 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5538 lower bound for automatic scrolling, i.e. automatic scrolling
5539 will not scroll a window to a column less than the value returned
5540 by this function. This happens in an interactive call. */)
5542 register Lisp_Object arg
, set_minimum
;
5546 struct window
*w
= XWINDOW (selected_window
);
5549 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5551 arg
= Fprefix_numeric_value (arg
);
5553 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
5554 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5556 if (!NILP (set_minimum
))
5557 w
->min_hscroll
= w
->hscroll
;
5562 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5563 doc
: /* Return the window which was selected when entering the minibuffer.
5564 Returns nil, if selected window is not a minibuffer window. */)
5567 if (minibuf_level
> 0
5568 && MINI_WINDOW_P (XWINDOW (selected_window
))
5569 && WINDOW_LIVE_P (minibuf_selected_window
))
5570 return minibuf_selected_window
;
5575 /* Value is the number of lines actually displayed in window W,
5576 as opposed to its height. */
5579 displayed_window_lines (w
)
5583 struct text_pos start
;
5584 int height
= window_box_height (w
);
5585 struct buffer
*old_buffer
;
5588 if (XBUFFER (w
->buffer
) != current_buffer
)
5590 old_buffer
= current_buffer
;
5591 set_buffer_internal (XBUFFER (w
->buffer
));
5596 /* In case W->start is out of the accessible range, do something
5597 reasonable. This happens in Info mode when Info-scroll-down
5598 calls (recenter -1) while W->start is 1. */
5599 if (XMARKER (w
->start
)->charpos
< BEGV
)
5600 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5601 else if (XMARKER (w
->start
)->charpos
> ZV
)
5602 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
5604 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5606 start_display (&it
, w
, start
);
5607 move_it_vertically (&it
, height
);
5608 bottom_y
= line_bottom_y (&it
);
5610 /* rms: On a non-window display,
5611 the value of it.vpos at the bottom of the screen
5612 seems to be 1 larger than window_box_height (w).
5613 This kludge fixes a bug whereby (move-to-window-line -1)
5614 when ZV is on the last screen line
5615 moves to the previous screen line instead of the last one. */
5616 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5619 /* Add in empty lines at the bottom of the window. */
5620 if (bottom_y
< height
)
5622 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5623 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5627 set_buffer_internal (old_buffer
);
5633 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5634 doc
: /* Center point in selected window and maybe redisplay frame.
5635 With prefix argument ARG, recenter putting point on screen line ARG
5636 relative to the selected window. If ARG is negative, it counts up from the
5637 bottom of the window. (ARG should be less than the height of the window.)
5639 If ARG is omitted or nil, then recenter with point on the middle line of
5640 the selected window; if the variable `recenter-redisplay' is non-nil,
5641 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5642 is set to `grow-only', this resets the tool-bar's height to the minimum
5643 height needed); if `recenter-redisplay' has the special value `tty',
5644 then only tty frame are redrawn.
5646 Just C-u as prefix means put point in the center of the window
5647 and redisplay normally--don't erase and redraw the frame. */)
5649 register Lisp_Object arg
;
5651 struct window
*w
= XWINDOW (selected_window
);
5652 struct buffer
*buf
= XBUFFER (w
->buffer
);
5653 struct buffer
*obuf
= current_buffer
;
5655 int charpos
, bytepos
;
5657 int this_scroll_margin
;
5659 /* If redisplay is suppressed due to an error, try again. */
5660 obuf
->display_error_modiff
= 0;
5664 if (!NILP (Vrecenter_redisplay
)
5665 && (!EQ (Vrecenter_redisplay
, Qtty
)
5666 || !NILP (Ftty_type (selected_frame
))))
5670 /* Invalidate pixel data calculated for all compositions. */
5671 for (i
= 0; i
< n_compositions
; i
++)
5672 composition_table
[i
]->font
= NULL
;
5674 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5676 Fredraw_frame (WINDOW_FRAME (w
));
5677 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5682 else if (CONSP (arg
)) /* Just C-u. */
5686 arg
= Fprefix_numeric_value (arg
);
5691 set_buffer_internal (buf
);
5693 /* Do this after making BUF current
5694 in case scroll_margin is buffer-local. */
5695 this_scroll_margin
= max (0, scroll_margin
);
5696 this_scroll_margin
= min (this_scroll_margin
,
5697 XFASTINT (w
->total_lines
) / 4);
5699 /* Handle centering on a graphical frame specially. Such frames can
5700 have variable-height lines and centering point on the basis of
5701 line counts would lead to strange effects. */
5702 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5709 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5710 start_display (&it
, w
, pt
);
5711 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5712 charpos
= IT_CHARPOS (it
);
5713 bytepos
= IT_BYTEPOS (it
);
5720 int extra_line_spacing
;
5721 int h
= window_box_height (w
);
5723 iarg
= - max (-iarg
, this_scroll_margin
);
5725 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5726 start_display (&it
, w
, pt
);
5728 /* Be sure we have the exact height of the full line containing PT. */
5729 move_it_by_lines (&it
, 0, 1);
5731 /* The amount of pixels we have to move back is the window
5732 height minus what's displayed in the line containing PT,
5733 and the lines below. */
5736 move_it_by_lines (&it
, nlines
, 1);
5738 if (it
.vpos
== nlines
)
5742 /* Last line has no newline */
5743 h
-= line_bottom_y (&it
);
5747 /* Don't reserve space for extra line spacing of last line. */
5748 extra_line_spacing
= it
.max_extra_line_spacing
;
5750 /* If we can't move down NLINES lines because we hit
5751 the end of the buffer, count in some empty lines. */
5752 if (it
.vpos
< nlines
)
5755 extra_line_spacing
= it
.extra_line_spacing
;
5756 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5761 /* Now find the new top line (starting position) of the window. */
5762 start_display (&it
, w
, pt
);
5764 move_it_vertically_backward (&it
, h
);
5766 /* If extra line spacing is present, we may move too far
5767 back. This causes the last line to be only partially
5768 visible (which triggers redisplay to recenter that line
5769 in the middle), so move forward.
5770 But ignore extra line spacing on last line, as it is not
5771 considered to be part of the visible height of the line.
5773 h
+= extra_line_spacing
;
5774 while (-it
.current_y
> h
)
5775 move_it_by_lines (&it
, 1, 1);
5777 charpos
= IT_CHARPOS (it
);
5778 bytepos
= IT_BYTEPOS (it
);
5782 struct position pos
;
5784 iarg
= max (iarg
, this_scroll_margin
);
5786 pos
= *vmotion (PT
, -iarg
, w
);
5787 charpos
= pos
.bufpos
;
5788 bytepos
= pos
.bytepos
;
5793 struct position pos
;
5794 int ht
= window_internal_height (w
);
5801 /* Don't let it get into the margin at either top or bottom. */
5802 iarg
= max (iarg
, this_scroll_margin
);
5803 iarg
= min (iarg
, ht
- this_scroll_margin
- 1);
5805 pos
= *vmotion (PT
, - iarg
, w
);
5806 charpos
= pos
.bufpos
;
5807 bytepos
= pos
.bytepos
;
5810 /* Set the new window start. */
5811 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
5812 w
->window_end_valid
= Qnil
;
5814 w
->optional_new_start
= Qt
;
5816 if (bytepos
== BEGV_BYTE
|| FETCH_BYTE (bytepos
- 1) == '\n')
5817 w
->start_at_line_beg
= Qt
;
5819 w
->start_at_line_beg
= Qnil
;
5821 set_buffer_internal (obuf
);
5826 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5828 doc
: /* Return the height in lines of the text display area of WINDOW.
5829 WINDOW defaults to the selected window.
5831 The return value does not include the mode line, any header line, nor
5832 any partial-height lines in the text display area. */)
5836 struct window
*w
= decode_window (window
);
5837 int pixel_height
= window_box_height (w
);
5838 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5839 return make_number (line_height
);
5844 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5846 doc
: /* Position point relative to window.
5847 With no argument, position point at center of window.
5848 An argument specifies vertical position within the window;
5849 zero means top of window, negative means relative to bottom of window. */)
5853 struct window
*w
= XWINDOW (selected_window
);
5857 int this_scroll_margin
;
5860 window
= selected_window
;
5861 start
= marker_position (w
->start
);
5862 if (start
< BEGV
|| start
> ZV
)
5864 int height
= window_internal_height (w
);
5865 Fvertical_motion (make_number (- (height
/ 2)), window
);
5866 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
5867 w
->start_at_line_beg
= Fbolp ();
5868 w
->force_start
= Qt
;
5871 Fgoto_char (w
->start
);
5873 lines
= displayed_window_lines (w
);
5876 this_scroll_margin
= max (0, scroll_margin
);
5877 this_scroll_margin
= min (this_scroll_margin
, lines
/ 4);
5881 XSETFASTINT (arg
, lines
/ 2);
5884 int iarg
= XINT (Fprefix_numeric_value (arg
));
5887 iarg
= iarg
+ lines
;
5889 #if 0 /* This code would prevent move-to-window-line from moving point
5890 to a place inside the scroll margins (which would cause the
5891 next redisplay to scroll). I wrote this code, but then concluded
5892 it is probably better not to install it. However, it is here
5893 inside #if 0 so as not to lose it. -- rms. */
5895 /* Don't let it get into the margin at either top or bottom. */
5896 iarg
= max (iarg
, this_scroll_margin
);
5897 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
5900 arg
= make_number (iarg
);
5903 /* Skip past a partially visible first line. */
5905 XSETINT (arg
, XINT (arg
) + 1);
5907 return Fvertical_motion (arg
, window
);
5912 /***********************************************************************
5913 Window Configuration
5914 ***********************************************************************/
5916 struct save_window_data
5919 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5920 Lisp_Object selected_frame
;
5921 Lisp_Object current_window
;
5922 Lisp_Object current_buffer
;
5923 Lisp_Object minibuf_scroll_window
;
5924 Lisp_Object minibuf_selected_window
;
5925 Lisp_Object root_window
;
5926 Lisp_Object focus_frame
;
5927 /* A vector, each of whose elements is a struct saved_window
5929 Lisp_Object saved_windows
;
5931 /* All fields above are traced by the GC.
5932 From `fame-cols' down, the fields are ignored by the GC. */
5934 int frame_cols
, frame_lines
, frame_menu_bar_lines
;
5935 int frame_tool_bar_lines
;
5938 /* This is saved as a Lisp_Vector */
5941 /* these first two must agree with struct Lisp_Vector in lisp.h */
5943 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5946 Lisp_Object buffer
, start
, pointm
, mark
;
5947 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5948 Lisp_Object hscroll
, min_hscroll
;
5949 Lisp_Object parent
, prev
;
5950 Lisp_Object start_at_line_beg
;
5951 Lisp_Object display_table
;
5952 Lisp_Object orig_top_line
, orig_total_lines
;
5953 Lisp_Object left_margin_cols
, right_margin_cols
;
5954 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
5955 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
;
5956 Lisp_Object dedicated
, resize_proportionally
;
5959 #define SAVED_WINDOW_N(swv,n) \
5960 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5962 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
5963 doc
: /* Return t if OBJECT is a window-configuration object. */)
5967 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
5970 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
5971 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5975 register struct save_window_data
*data
;
5976 struct Lisp_Vector
*saved_windows
;
5978 CHECK_WINDOW_CONFIGURATION (config
);
5980 data
= (struct save_window_data
*) XVECTOR (config
);
5981 saved_windows
= XVECTOR (data
->saved_windows
);
5982 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5985 DEFUN ("set-window-configuration", Fset_window_configuration
,
5986 Sset_window_configuration
, 1, 1, 0,
5987 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5988 CONFIGURATION must be a value previously returned
5989 by `current-window-configuration' (which see).
5990 If CONFIGURATION was made from a frame that is now deleted,
5991 only frame-independent values can be restored. In this case,
5992 the return value is nil. Otherwise the value is t. */)
5994 Lisp_Object configuration
;
5996 register struct save_window_data
*data
;
5997 struct Lisp_Vector
*saved_windows
;
5998 Lisp_Object new_current_buffer
;
6003 CHECK_WINDOW_CONFIGURATION (configuration
);
6005 data
= (struct save_window_data
*) XVECTOR (configuration
);
6006 saved_windows
= XVECTOR (data
->saved_windows
);
6008 new_current_buffer
= data
->current_buffer
;
6009 if (NILP (XBUFFER (new_current_buffer
)->name
))
6010 new_current_buffer
= Qnil
;
6013 if (XBUFFER (new_current_buffer
) == current_buffer
)
6014 /* The code further down "preserves point" by saving here PT in
6015 old_point and then setting it later back into PT. When the
6016 current-selected-window and the final-selected-window both show
6017 the current buffer, this suffers from the problem that the
6018 current PT is the window-point of the current-selected-window,
6019 while the final PT is the point of the final-selected-window, so
6020 this copy from one PT to the other would end up moving the
6021 window-point of the final-selected-window to the window-point of
6022 the current-selected-window. So we have to be careful which
6023 point of the current-buffer we copy into old_point. */
6024 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
6025 && WINDOWP (selected_window
)
6026 && EQ (XWINDOW (selected_window
)->buffer
, new_current_buffer
)
6027 && !EQ (selected_window
, data
->current_window
))
6028 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
6032 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
6033 point in new_current_buffer as of the last time this buffer was
6034 used. This can be non-deterministic since it can be changed by
6035 things like jit-lock by mere temporary selection of some random
6036 window that happens to show this buffer.
6037 So if possible we want this arbitrary choice of "which point" to
6038 be the one from the to-be-selected-window so as to prevent this
6039 window's cursor from being copied from another window. */
6040 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
6041 /* If current_window = selected_window, its point is in BUF_PT. */
6042 && !EQ (selected_window
, data
->current_window
))
6043 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
6045 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
6048 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6051 /* If f is a dead frame, don't bother rebuilding its window tree.
6052 However, there is other stuff we should still try to do below. */
6053 if (FRAME_LIVE_P (f
))
6055 register struct window
*w
;
6056 register struct saved_window
*p
;
6057 struct window
*root_window
;
6058 struct window
**leaf_windows
;
6062 /* If the frame has been resized since this window configuration was
6063 made, we change the frame to the size specified in the
6064 configuration, restore the configuration, and then resize it
6065 back. We keep track of the prevailing height in these variables. */
6066 int previous_frame_lines
= FRAME_LINES (f
);
6067 int previous_frame_cols
= FRAME_COLS (f
);
6068 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6069 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6071 /* The mouse highlighting code could get screwed up
6072 if it runs during this. */
6075 if (data
->frame_lines
!= previous_frame_lines
6076 || data
->frame_cols
!= previous_frame_cols
)
6077 change_frame_size (f
, data
->frame_lines
,
6078 data
->frame_cols
, 0, 0, 0);
6079 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
6080 if (data
->frame_menu_bar_lines
6081 != previous_frame_menu_bar_lines
)
6082 x_set_menu_bar_lines (f
, make_number (data
->frame_menu_bar_lines
),
6084 #ifdef HAVE_WINDOW_SYSTEM
6085 if (data
->frame_tool_bar_lines
6086 != previous_frame_tool_bar_lines
)
6087 x_set_tool_bar_lines (f
, make_number (data
->frame_tool_bar_lines
),
6092 /* "Swap out" point from the selected window's buffer
6093 into the window itself. (Normally the pointm of the selected
6094 window holds garbage.) We do this now, before
6095 restoring the window contents, and prevent it from
6096 being done later on when we select a new window. */
6097 if (! NILP (XWINDOW (selected_window
)->buffer
))
6099 w
= XWINDOW (selected_window
);
6100 set_marker_both (w
->pointm
,
6102 BUF_PT (XBUFFER (w
->buffer
)),
6103 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6106 windows_or_buffers_changed
++;
6107 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
6109 /* Problem: Freeing all matrices and later allocating them again
6110 is a serious redisplay flickering problem. What we would
6111 really like to do is to free only those matrices not reused
6113 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6115 = (struct window
**) alloca (count_windows (root_window
)
6116 * sizeof (struct window
*));
6117 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
6120 Mark all windows now on frame as "deleted".
6121 Restoring the new configuration "undeletes" any that are in it.
6123 Save their current buffers in their height fields, since we may
6124 need it later, if a buffer saved in the configuration is now
6126 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6128 for (k
= 0; k
< saved_windows
->size
; k
++)
6130 p
= SAVED_WINDOW_N (saved_windows
, k
);
6131 w
= XWINDOW (p
->window
);
6134 if (!NILP (p
->parent
))
6135 w
->parent
= SAVED_WINDOW_N (saved_windows
,
6136 XFASTINT (p
->parent
))->window
;
6140 if (!NILP (p
->prev
))
6142 w
->prev
= SAVED_WINDOW_N (saved_windows
,
6143 XFASTINT (p
->prev
))->window
;
6144 XWINDOW (w
->prev
)->next
= p
->window
;
6149 if (!NILP (w
->parent
))
6151 if (EQ (p
->total_cols
, XWINDOW (w
->parent
)->total_cols
))
6153 XWINDOW (w
->parent
)->vchild
= p
->window
;
6154 XWINDOW (w
->parent
)->hchild
= Qnil
;
6158 XWINDOW (w
->parent
)->hchild
= p
->window
;
6159 XWINDOW (w
->parent
)->vchild
= Qnil
;
6164 /* If we squirreled away the buffer in the window's height,
6166 if (BUFFERP (w
->total_lines
))
6167 w
->buffer
= w
->total_lines
;
6168 w
->left_col
= p
->left_col
;
6169 w
->top_line
= p
->top_line
;
6170 w
->total_cols
= p
->total_cols
;
6171 w
->total_lines
= p
->total_lines
;
6172 w
->hscroll
= p
->hscroll
;
6173 w
->min_hscroll
= p
->min_hscroll
;
6174 w
->display_table
= p
->display_table
;
6175 w
->orig_top_line
= p
->orig_top_line
;
6176 w
->orig_total_lines
= p
->orig_total_lines
;
6177 w
->left_margin_cols
= p
->left_margin_cols
;
6178 w
->right_margin_cols
= p
->right_margin_cols
;
6179 w
->left_fringe_width
= p
->left_fringe_width
;
6180 w
->right_fringe_width
= p
->right_fringe_width
;
6181 w
->fringes_outside_margins
= p
->fringes_outside_margins
;
6182 w
->scroll_bar_width
= p
->scroll_bar_width
;
6183 w
->vertical_scroll_bar_type
= p
->vertical_scroll_bar_type
;
6184 w
->dedicated
= p
->dedicated
;
6185 w
->resize_proportionally
= p
->resize_proportionally
;
6186 XSETFASTINT (w
->last_modified
, 0);
6187 XSETFASTINT (w
->last_overlay_modified
, 0);
6189 /* Reinstall the saved buffer and pointers into it. */
6190 if (NILP (p
->buffer
))
6191 w
->buffer
= p
->buffer
;
6194 if (!NILP (XBUFFER (p
->buffer
)->name
))
6195 /* If saved buffer is alive, install it. */
6197 w
->buffer
= p
->buffer
;
6198 w
->start_at_line_beg
= p
->start_at_line_beg
;
6199 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
6200 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
6201 Fset_marker (XBUFFER (w
->buffer
)->mark
,
6202 p
->mark
, w
->buffer
);
6204 /* As documented in Fcurrent_window_configuration, don't
6205 restore the location of point in the buffer which was
6206 current when the window configuration was recorded. */
6207 if (!EQ (p
->buffer
, new_current_buffer
)
6208 && XBUFFER (p
->buffer
) == current_buffer
)
6209 Fgoto_char (w
->pointm
);
6211 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
6212 /* Else unless window has a live buffer, get one. */
6214 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
6215 /* This will set the markers to beginning of visible
6217 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
6218 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
6219 w
->start_at_line_beg
= Qt
;
6222 /* Keeping window's old buffer; make sure the markers
6225 /* Set window markers at start of visible range. */
6226 if (XMARKER (w
->start
)->buffer
== 0)
6227 set_marker_restricted (w
->start
, make_number (0),
6229 if (XMARKER (w
->pointm
)->buffer
== 0)
6230 set_marker_restricted_both (w
->pointm
, w
->buffer
,
6231 BUF_PT (XBUFFER (w
->buffer
)),
6232 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6233 w
->start_at_line_beg
= Qt
;
6238 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
6239 /* Prevent "swapping out point" in the old selected window
6240 using the buffer that has been restored into it.
6241 We already swapped out point that from that window's old buffer. */
6242 selected_window
= Qnil
;
6244 /* Arrange *not* to restore point in the buffer that was
6245 current when the window configuration was saved. */
6246 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
6247 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
6248 make_number (old_point
),
6249 XWINDOW (data
->current_window
)->buffer
);
6251 Fselect_window (data
->current_window
, Qnil
);
6252 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
6255 if (NILP (data
->focus_frame
)
6256 || (FRAMEP (data
->focus_frame
)
6257 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
6258 Fredirect_frame_focus (frame
, data
->focus_frame
);
6260 #if 0 /* I don't understand why this is needed, and it causes problems
6261 when the frame's old selected window has been deleted. */
6262 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
6263 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
6267 /* Set the screen height to the value it had before this function. */
6268 if (previous_frame_lines
!= FRAME_LINES (f
)
6269 || previous_frame_cols
!= FRAME_COLS (f
))
6270 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
6272 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
6273 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
6274 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
6276 #ifdef HAVE_WINDOW_SYSTEM
6277 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
6278 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
6283 /* Now, free glyph matrices in windows that were not reused. */
6284 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
6286 if (NILP (leaf_windows
[i
]->buffer
))
6288 /* Assert it's not reused as a combination. */
6289 xassert (NILP (leaf_windows
[i
]->hchild
)
6290 && NILP (leaf_windows
[i
]->vchild
));
6291 free_window_matrices (leaf_windows
[i
]);
6293 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
6301 /* Fselect_window will have made f the selected frame, so we
6302 reselect the proper frame here. Fhandle_switch_frame will change the
6303 selected window too, but that doesn't make the call to
6304 Fselect_window above totally superfluous; it still sets f's
6306 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
6307 do_switch_frame (data
->selected_frame
, 0, 0, Qnil
);
6309 run_window_configuration_change_hook (f
);
6312 if (!NILP (new_current_buffer
))
6313 Fset_buffer (new_current_buffer
);
6315 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
6316 minibuf_selected_window
= data
->minibuf_selected_window
;
6318 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
6321 /* Mark all windows now on frame as deleted
6322 by setting their buffers to nil. */
6325 delete_all_subwindows (w
)
6326 register struct window
*w
;
6328 if (!NILP (w
->next
))
6329 delete_all_subwindows (XWINDOW (w
->next
));
6330 if (!NILP (w
->vchild
))
6331 delete_all_subwindows (XWINDOW (w
->vchild
));
6332 if (!NILP (w
->hchild
))
6333 delete_all_subwindows (XWINDOW (w
->hchild
));
6335 w
->total_lines
= w
->buffer
; /* See Fset_window_configuration for excuse. */
6337 if (!NILP (w
->buffer
))
6340 /* We set all three of these fields to nil, to make sure that we can
6341 distinguish this dead window from any live window. Live leaf
6342 windows will have buffer set, and combination windows will have
6343 vchild or hchild set. */
6348 Vwindow_list
= Qnil
;
6352 count_windows (window
)
6353 register struct window
*window
;
6355 register int count
= 1;
6356 if (!NILP (window
->next
))
6357 count
+= count_windows (XWINDOW (window
->next
));
6358 if (!NILP (window
->vchild
))
6359 count
+= count_windows (XWINDOW (window
->vchild
));
6360 if (!NILP (window
->hchild
))
6361 count
+= count_windows (XWINDOW (window
->hchild
));
6366 /* Fill vector FLAT with leaf windows under W, starting at index I.
6367 Value is last index + 1. */
6370 get_leaf_windows (w
, flat
, i
)
6372 struct window
**flat
;
6377 if (!NILP (w
->hchild
))
6378 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
6379 else if (!NILP (w
->vchild
))
6380 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
6384 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6391 /* Return a pointer to the glyph W's physical cursor is on. Value is
6392 null if W's current matrix is invalid, so that no meaningfull glyph
6396 get_phys_cursor_glyph (w
)
6399 struct glyph_row
*row
;
6400 struct glyph
*glyph
;
6402 if (w
->phys_cursor
.vpos
>= 0
6403 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
6404 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
6406 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
6407 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
6416 save_window_save (window
, vector
, i
)
6418 struct Lisp_Vector
*vector
;
6421 register struct saved_window
*p
;
6422 register struct window
*w
;
6423 register Lisp_Object tem
;
6425 for (;!NILP (window
); window
= w
->next
)
6427 p
= SAVED_WINDOW_N (vector
, i
);
6428 w
= XWINDOW (window
);
6430 XSETFASTINT (w
->temslot
, i
); i
++;
6432 p
->buffer
= w
->buffer
;
6433 p
->left_col
= w
->left_col
;
6434 p
->top_line
= w
->top_line
;
6435 p
->total_cols
= w
->total_cols
;
6436 p
->total_lines
= w
->total_lines
;
6437 p
->hscroll
= w
->hscroll
;
6438 p
->min_hscroll
= w
->min_hscroll
;
6439 p
->display_table
= w
->display_table
;
6440 p
->orig_top_line
= w
->orig_top_line
;
6441 p
->orig_total_lines
= w
->orig_total_lines
;
6442 p
->left_margin_cols
= w
->left_margin_cols
;
6443 p
->right_margin_cols
= w
->right_margin_cols
;
6444 p
->left_fringe_width
= w
->left_fringe_width
;
6445 p
->right_fringe_width
= w
->right_fringe_width
;
6446 p
->fringes_outside_margins
= w
->fringes_outside_margins
;
6447 p
->scroll_bar_width
= w
->scroll_bar_width
;
6448 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
6449 p
->dedicated
= w
->dedicated
;
6450 p
->resize_proportionally
= w
->resize_proportionally
;
6451 if (!NILP (w
->buffer
))
6453 /* Save w's value of point in the window configuration.
6454 If w is the selected window, then get the value of point
6455 from the buffer; pointm is garbage in the selected window. */
6456 if (EQ (window
, selected_window
))
6458 p
->pointm
= Fmake_marker ();
6459 set_marker_both (p
->pointm
, w
->buffer
,
6460 BUF_PT (XBUFFER (w
->buffer
)),
6461 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6464 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
6466 p
->start
= Fcopy_marker (w
->start
, Qnil
);
6467 p
->start_at_line_beg
= w
->start_at_line_beg
;
6469 tem
= XBUFFER (w
->buffer
)->mark
;
6470 p
->mark
= Fcopy_marker (tem
, Qnil
);
6477 p
->start_at_line_beg
= Qnil
;
6480 if (NILP (w
->parent
))
6483 p
->parent
= XWINDOW (w
->parent
)->temslot
;
6488 p
->prev
= XWINDOW (w
->prev
)->temslot
;
6490 if (!NILP (w
->vchild
))
6491 i
= save_window_save (w
->vchild
, vector
, i
);
6492 if (!NILP (w
->hchild
))
6493 i
= save_window_save (w
->hchild
, vector
, i
);
6499 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
6500 Scurrent_window_configuration
, 0, 1, 0,
6501 doc
: /* Return an object representing the current window configuration of FRAME.
6502 If FRAME is nil or omitted, use the selected frame.
6503 This describes the number of windows, their sizes and current buffers,
6504 and for each displayed buffer, where display starts, and the positions of
6505 point and mark. An exception is made for point in the current buffer:
6506 its value is -not- saved.
6507 This also records the currently selected frame, and FRAME's focus
6508 redirection (see `redirect-frame-focus'). */)
6512 register Lisp_Object tem
;
6513 register int n_windows
;
6514 register struct save_window_data
*data
;
6519 frame
= selected_frame
;
6520 CHECK_LIVE_FRAME (frame
);
6523 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6524 data
= ALLOCATE_PSEUDOVECTOR (struct save_window_data
, frame_cols
,
6525 PVEC_WINDOW_CONFIGURATION
);
6527 data
->frame_cols
= FRAME_COLS (f
);
6528 data
->frame_lines
= FRAME_LINES (f
);
6529 data
->frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6530 data
->frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6531 data
->selected_frame
= selected_frame
;
6532 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6533 XSETBUFFER (data
->current_buffer
, current_buffer
);
6534 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6535 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6536 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6537 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6538 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
6539 data
->saved_windows
= tem
;
6540 for (i
= 0; i
< n_windows
; i
++)
6541 XVECTOR (tem
)->contents
[i
]
6542 = Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
);
6543 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6544 XSETWINDOW_CONFIGURATION (tem
, data
);
6548 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
6550 doc
: /* Execute BODY, preserving window sizes and contents.
6551 Return the value of the last form in BODY.
6552 Restore which buffer appears in which window, where display starts,
6553 and the value of point and mark for each window.
6554 Also restore the choice of selected window.
6555 Also restore which buffer is current.
6556 Does not restore the value of point in current buffer.
6557 usage: (save-window-excursion BODY...) */)
6561 register Lisp_Object val
;
6562 register int count
= SPECPDL_INDEX ();
6564 record_unwind_protect (Fset_window_configuration
,
6565 Fcurrent_window_configuration (Qnil
));
6566 val
= Fprogn (args
);
6567 return unbind_to (count
, val
);
6572 /***********************************************************************
6574 ***********************************************************************/
6580 Lisp_Object tail
= Qnil
;
6581 Lisp_Object result
= Qnil
;
6588 if (!NILP (w
->hchild
))
6589 wn
= Fcons (Qnil
, Fcons (Fwindow_edges (wn
),
6590 window_tree (XWINDOW (w
->hchild
))));
6591 else if (!NILP (w
->vchild
))
6592 wn
= Fcons (Qt
, Fcons (Fwindow_edges (wn
),
6593 window_tree (XWINDOW (w
->vchild
))));
6597 result
= tail
= Fcons (wn
, Qnil
);
6601 XSETCDR (tail
, Fcons (wn
, Qnil
));
6605 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6613 DEFUN ("window-tree", Fwindow_tree
, Swindow_tree
,
6615 doc
: /* Return the window tree for frame FRAME.
6617 The return value is a list of the form (ROOT MINI), where ROOT
6618 represents the window tree of the frame's root window, and MINI
6619 is the frame's minibuffer window.
6621 If the root window is not split, ROOT is the root window itself.
6622 Otherwise, ROOT is a list (DIR EDGES W1 W2 ...) where DIR is nil for a
6623 horizontal split, and t for a vertical split, EDGES gives the combined
6624 size and position of the subwindows in the split, and the rest of the
6625 elements are the subwindows in the split. Each of the subwindows may
6626 again be a window or a list representing a window split, and so on.
6627 EDGES is a list \(LEFT TOP RIGHT BOTTOM) as returned by `window-edges'.
6629 If FRAME is nil or omitted, return information on the currently
6637 frame
= selected_frame
;
6639 CHECK_FRAME (frame
);
6642 if (!FRAME_LIVE_P (f
))
6645 return window_tree (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6649 /***********************************************************************
6651 ***********************************************************************/
6653 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6655 doc
: /* Set width of marginal areas of window WINDOW.
6656 If WINDOW is nil, set margins of the currently selected window.
6657 Second arg LEFT-WIDTH specifies the number of character cells to
6658 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6659 does the same for the right marginal area. A nil width parameter
6660 means no margin. */)
6661 (window
, left_width
, right_width
)
6662 Lisp_Object window
, left_width
, right_width
;
6664 struct window
*w
= decode_window (window
);
6666 /* Translate negative or zero widths to nil.
6667 Margins that are too wide have to be checked elsewhere. */
6669 if (!NILP (left_width
))
6671 CHECK_NUMBER (left_width
);
6672 if (XINT (left_width
) <= 0)
6676 if (!NILP (right_width
))
6678 CHECK_NUMBER (right_width
);
6679 if (XINT (right_width
) <= 0)
6683 if (!EQ (w
->left_margin_cols
, left_width
)
6684 || !EQ (w
->right_margin_cols
, right_width
))
6686 w
->left_margin_cols
= left_width
;
6687 w
->right_margin_cols
= right_width
;
6689 adjust_window_margins (w
);
6691 ++windows_or_buffers_changed
;
6692 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6699 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6701 doc
: /* Get width of marginal areas of window WINDOW.
6702 If WINDOW is omitted or nil, use the currently selected window.
6703 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6704 If a marginal area does not exist, its width will be returned
6709 struct window
*w
= decode_window (window
);
6710 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
6715 /***********************************************************************
6717 ***********************************************************************/
6719 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6721 doc
: /* Set the fringe widths of window WINDOW.
6722 If WINDOW is nil, set the fringe widths of the currently selected
6724 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6725 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6726 fringe width. If a fringe width arg is nil, that means to use the
6727 frame's default fringe width. Default fringe widths can be set with
6728 the command `set-fringe-style'.
6729 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6730 outside of the display margins. By default, fringes are drawn between
6731 display marginal areas and the text area. */)
6732 (window
, left_width
, right_width
, outside_margins
)
6733 Lisp_Object window
, left_width
, right_width
, outside_margins
;
6735 struct window
*w
= decode_window (window
);
6737 if (!NILP (left_width
))
6738 CHECK_NATNUM (left_width
);
6739 if (!NILP (right_width
))
6740 CHECK_NATNUM (right_width
);
6742 /* Do nothing on a tty. */
6743 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6744 && (!EQ (w
->left_fringe_width
, left_width
)
6745 || !EQ (w
->right_fringe_width
, right_width
)
6746 || !EQ (w
->fringes_outside_margins
, outside_margins
)))
6748 w
->left_fringe_width
= left_width
;
6749 w
->right_fringe_width
= right_width
;
6750 w
->fringes_outside_margins
= outside_margins
;
6752 adjust_window_margins (w
);
6754 clear_glyph_matrix (w
->current_matrix
);
6755 w
->window_end_valid
= Qnil
;
6757 ++windows_or_buffers_changed
;
6758 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6765 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6767 doc
: /* Get width of fringes of window WINDOW.
6768 If WINDOW is omitted or nil, use the currently selected window.
6769 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6773 struct window
*w
= decode_window (window
);
6775 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6776 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6777 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
6778 ? Qt
: Qnil
), Qnil
)));
6783 /***********************************************************************
6785 ***********************************************************************/
6787 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
, Sset_window_scroll_bars
,
6789 doc
: /* Set width and type of scroll bars of window WINDOW.
6790 If window is nil, set scroll bars of the currently selected window.
6791 Second parameter WIDTH specifies the pixel width for the scroll bar;
6792 this is automatically adjusted to a multiple of the frame column width.
6793 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6794 bar: left, right, or nil.
6795 If WIDTH is nil, use the frame's scroll-bar width.
6796 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6797 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6798 (window
, width
, vertical_type
, horizontal_type
)
6799 Lisp_Object window
, width
, vertical_type
, horizontal_type
;
6801 struct window
*w
= decode_window (window
);
6805 CHECK_NATNUM (width
);
6807 if (XINT (width
) == 0)
6808 vertical_type
= Qnil
;
6811 if (!(NILP (vertical_type
)
6812 || EQ (vertical_type
, Qleft
)
6813 || EQ (vertical_type
, Qright
)
6814 || EQ (vertical_type
, Qt
)))
6815 error ("Invalid type of vertical scroll bar");
6817 if (!EQ (w
->scroll_bar_width
, width
)
6818 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6820 w
->scroll_bar_width
= width
;
6821 w
->vertical_scroll_bar_type
= vertical_type
;
6823 adjust_window_margins (w
);
6825 clear_glyph_matrix (w
->current_matrix
);
6826 w
->window_end_valid
= Qnil
;
6828 ++windows_or_buffers_changed
;
6829 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6836 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6838 doc
: /* Get width and type of scroll bars of window WINDOW.
6839 If WINDOW is omitted or nil, use the currently selected window.
6840 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6841 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6846 struct window
*w
= decode_window (window
);
6847 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6848 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6849 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6850 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6851 Fcons (w
->vertical_scroll_bar_type
,
6852 Fcons (Qnil
, Qnil
))));
6857 /***********************************************************************
6859 ***********************************************************************/
6861 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6862 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6863 Use the selected window if WINDOW is nil or omitted.
6864 Normally, value is a multiple of the canonical character height of WINDOW;
6865 optional second arg PIXELS-P means value is measured in pixels. */)
6867 Lisp_Object window
, pixels_p
;
6874 window
= selected_window
;
6876 CHECK_WINDOW (window
);
6877 w
= XWINDOW (window
);
6878 f
= XFRAME (w
->frame
);
6880 if (FRAME_WINDOW_P (f
))
6881 result
= (NILP (pixels_p
)
6882 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6883 : make_number (-w
->vscroll
));
6885 result
= make_number (0);
6890 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6892 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6893 WINDOW nil means use the selected window. Normally, VSCROLL is a
6894 non-negative multiple of the canonical character height of WINDOW;
6895 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
6896 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6897 corresponds to an integral number of pixels. The return value is the
6898 result of this rounding.
6899 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6900 (window
, vscroll
, pixels_p
)
6901 Lisp_Object window
, vscroll
, pixels_p
;
6907 window
= selected_window
;
6909 CHECK_WINDOW (window
);
6910 CHECK_NUMBER_OR_FLOAT (vscroll
);
6912 w
= XWINDOW (window
);
6913 f
= XFRAME (w
->frame
);
6915 if (FRAME_WINDOW_P (f
))
6917 int old_dy
= w
->vscroll
;
6919 w
->vscroll
= - (NILP (pixels_p
)
6920 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
6921 : XFLOATINT (vscroll
));
6922 w
->vscroll
= min (w
->vscroll
, 0);
6924 if (w
->vscroll
!= old_dy
)
6926 /* Adjust glyph matrix of the frame if the virtual display
6927 area becomes larger than before. */
6928 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
6931 /* Prevent redisplay shortcuts. */
6932 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
6936 return Fwindow_vscroll (window
, pixels_p
);
6940 /* Call FN for all leaf windows on frame F. FN is called with the
6941 first argument being a pointer to the leaf window, and with
6942 additional argument USER_DATA. Stops when FN returns 0. */
6945 foreach_window (f
, fn
, user_data
)
6947 int (* fn
) P_ ((struct window
*, void *));
6950 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
6951 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
6952 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
6956 /* Helper function for foreach_window. Call FN for all leaf windows
6957 reachable from W. FN is called with the first argument being a
6958 pointer to the leaf window, and with additional argument USER_DATA.
6959 Stop when FN returns 0. Value is 0 if stopped by FN. */
6962 foreach_window_1 (w
, fn
, user_data
)
6964 int (* fn
) P_ ((struct window
*, void *));
6969 for (cont
= 1; w
&& cont
;)
6971 if (!NILP (w
->hchild
))
6972 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
6973 else if (!NILP (w
->vchild
))
6974 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
6976 cont
= fn (w
, user_data
);
6978 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6985 /* Freeze or unfreeze the window start of W unless it is a
6986 mini-window or the selected window. FREEZE_P non-null means freeze
6987 the window start. */
6990 freeze_window_start (w
, freeze_p
)
6994 if (MINI_WINDOW_P (w
)
6995 || (WINDOWP (selected_window
) /* Can be nil in corner cases. */
6996 && (w
== XWINDOW (selected_window
)
6997 || (MINI_WINDOW_P (XWINDOW (selected_window
))
6998 && ! NILP (Vminibuf_scroll_window
)
6999 && w
== XWINDOW (Vminibuf_scroll_window
)))))
7002 w
->frozen_window_start_p
= freeze_p
!= NULL
;
7007 /* Freeze or unfreeze the window starts of all leaf windows on frame
7008 F, except the selected window and a mini-window. FREEZE_P non-zero
7009 means freeze the window start. */
7012 freeze_window_starts (f
, freeze_p
)
7016 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
7020 /***********************************************************************
7022 ***********************************************************************/
7024 /* Return 1 if window configurations C1 and C2
7025 describe the same state of affairs. This is used by Fequal. */
7028 compare_window_configurations (c1
, c2
, ignore_positions
)
7030 int ignore_positions
;
7032 register struct save_window_data
*d1
, *d2
;
7033 struct Lisp_Vector
*sw1
, *sw2
;
7036 CHECK_WINDOW_CONFIGURATION (c1
);
7037 CHECK_WINDOW_CONFIGURATION (c2
);
7039 d1
= (struct save_window_data
*) XVECTOR (c1
);
7040 d2
= (struct save_window_data
*) XVECTOR (c2
);
7041 sw1
= XVECTOR (d1
->saved_windows
);
7042 sw2
= XVECTOR (d2
->saved_windows
);
7044 if (d1
->frame_cols
!= d2
->frame_cols
)
7046 if (d1
->frame_lines
!= d2
->frame_lines
)
7048 if (d1
->frame_menu_bar_lines
!= d2
->frame_menu_bar_lines
)
7050 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
7052 /* Don't compare the current_window field directly.
7053 Instead see w1_is_current and w2_is_current, below. */
7054 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
7056 if (! ignore_positions
)
7058 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
7060 if (! EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
))
7063 /* Don't compare the root_window field.
7064 We don't require the two configurations
7065 to use the same window object,
7066 and the two root windows must be equivalent
7067 if everything else compares equal. */
7068 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
7071 /* Verify that the two confis have the same number of windows. */
7072 if (sw1
->size
!= sw2
->size
)
7075 for (i
= 0; i
< sw1
->size
; i
++)
7077 struct saved_window
*p1
, *p2
;
7078 int w1_is_current
, w2_is_current
;
7080 p1
= SAVED_WINDOW_N (sw1
, i
);
7081 p2
= SAVED_WINDOW_N (sw2
, i
);
7083 /* Verify that the current windows in the two
7084 configurations correspond to each other. */
7085 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
7086 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
7088 if (w1_is_current
!= w2_is_current
)
7091 /* Verify that the corresponding windows do match. */
7092 if (! EQ (p1
->buffer
, p2
->buffer
))
7094 if (! EQ (p1
->left_col
, p2
->left_col
))
7096 if (! EQ (p1
->top_line
, p2
->top_line
))
7098 if (! EQ (p1
->total_cols
, p2
->total_cols
))
7100 if (! EQ (p1
->total_lines
, p2
->total_lines
))
7102 if (! EQ (p1
->display_table
, p2
->display_table
))
7104 if (! EQ (p1
->parent
, p2
->parent
))
7106 if (! EQ (p1
->prev
, p2
->prev
))
7108 if (! ignore_positions
)
7110 if (! EQ (p1
->hscroll
, p2
->hscroll
))
7112 if (!EQ (p1
->min_hscroll
, p2
->min_hscroll
))
7114 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
7116 if (NILP (Fequal (p1
->start
, p2
->start
)))
7118 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
7120 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
7123 if (! EQ (p1
->left_margin_cols
, p2
->left_margin_cols
))
7125 if (! EQ (p1
->right_margin_cols
, p2
->right_margin_cols
))
7127 if (! EQ (p1
->left_fringe_width
, p2
->left_fringe_width
))
7129 if (! EQ (p1
->right_fringe_width
, p2
->right_fringe_width
))
7131 if (! EQ (p1
->fringes_outside_margins
, p2
->fringes_outside_margins
))
7133 if (! EQ (p1
->scroll_bar_width
, p2
->scroll_bar_width
))
7135 if (! EQ (p1
->vertical_scroll_bar_type
, p2
->vertical_scroll_bar_type
))
7142 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
7143 Scompare_window_configurations
, 2, 2, 0,
7144 doc
: /* Compare two window configurations as regards the structure of windows.
7145 This function ignores details such as the values of point and mark
7146 and scrolling positions. */)
7150 if (compare_window_configurations (x
, y
, 1))
7158 struct frame
*f
= make_initial_frame ();
7159 XSETFRAME (selected_frame
, f
);
7160 Vterminal_frame
= selected_frame
;
7161 minibuf_window
= f
->minibuffer_window
;
7162 selected_window
= f
->selected_window
;
7163 last_nonminibuf_frame
= f
;
7165 window_initialized
= 1;
7171 Vwindow_list
= Qnil
;
7177 Qscroll_up
= intern_c_string ("scroll-up");
7178 staticpro (&Qscroll_up
);
7180 Qscroll_down
= intern_c_string ("scroll-down");
7181 staticpro (&Qscroll_down
);
7183 Qwindow_size_fixed
= intern_c_string ("window-size-fixed");
7184 staticpro (&Qwindow_size_fixed
);
7185 Fset (Qwindow_size_fixed
, Qnil
);
7187 staticpro (&Qwindow_configuration_change_hook
);
7188 Qwindow_configuration_change_hook
7189 = intern_c_string ("window-configuration-change-hook");
7191 Qwindowp
= intern_c_string ("windowp");
7192 staticpro (&Qwindowp
);
7194 Qwindow_configuration_p
= intern_c_string ("window-configuration-p");
7195 staticpro (&Qwindow_configuration_p
);
7197 Qwindow_live_p
= intern_c_string ("window-live-p");
7198 staticpro (&Qwindow_live_p
);
7200 Qdisplay_buffer
= intern_c_string ("display-buffer");
7201 staticpro (&Qdisplay_buffer
);
7203 Qtemp_buffer_show_hook
= intern_c_string ("temp-buffer-show-hook");
7204 staticpro (&Qtemp_buffer_show_hook
);
7206 staticpro (&Vwindow_list
);
7208 minibuf_selected_window
= Qnil
;
7209 staticpro (&minibuf_selected_window
);
7211 window_scroll_pixel_based_preserve_x
= -1;
7212 window_scroll_pixel_based_preserve_y
= -1;
7213 window_scroll_preserve_hpos
= -1;
7214 window_scroll_preserve_vpos
= -1;
7216 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
7217 doc
: /* Non-nil means call as function to display a help buffer.
7218 The function is called with one argument, the buffer to be displayed.
7219 Used by `with-output-to-temp-buffer'.
7220 If this function is used, then it must do the entire job of showing
7221 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
7222 Vtemp_buffer_show_function
= Qnil
;
7224 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
7225 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
7226 Vminibuf_scroll_window
= Qnil
;
7228 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows
,
7229 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
7230 If the minibuffer is active, the `minibuffer-scroll-window' mode line
7231 is displayed in the `mode-line' face. */);
7232 mode_line_in_non_selected_windows
= 1;
7234 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
7235 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
7236 Vother_window_scroll_buffer
= Qnil
;
7238 DEFVAR_BOOL ("auto-window-vscroll", &auto_window_vscroll_p
,
7239 doc
: /* *Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
7240 auto_window_vscroll_p
= 1;
7242 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
7243 doc
: /* *Number of lines of continuity when scrolling by screenfuls. */);
7244 next_screen_context_lines
= 2;
7246 DEFVAR_INT ("window-min-height", &window_min_height
,
7247 doc
: /* Allow deleting windows less than this tall.
7248 The value is measured in line units. If a window wants a modeline it
7249 is counted as one line.
7251 Emacs honors settings of this variable when enlarging or shrinking
7252 windows vertically. A value less than 1 is invalid. */);
7253 window_min_height
= 4;
7255 DEFVAR_INT ("window-min-width", &window_min_width
,
7256 doc
: /* Allow deleting windows less than this wide.
7257 The value is measured in characters and includes any fringes or
7260 Emacs honors settings of this variable when enlarging or shrinking
7261 windows horizontally. A value less than 2 is invalid. */);
7262 window_min_width
= 10;
7264 DEFVAR_LISP ("scroll-preserve-screen-position",
7265 &Vscroll_preserve_screen_position
,
7266 doc
: /* *Controls if scroll commands move point to keep its screen position unchanged.
7267 A value of nil means point does not keep its screen position except
7268 at the scroll margin or window boundary respectively.
7269 A value of t means point keeps its screen position if the scroll
7270 command moved it vertically out of the window, e.g. when scrolling
7272 Any other value means point always keeps its screen position.
7273 Scroll commands are defined by the variable
7274 `scroll-preserve-screen-position-commands'. */);
7275 Vscroll_preserve_screen_position
= Qnil
;
7277 DEFVAR_LISP ("scroll-preserve-screen-position-commands",
7278 &Vscroll_preserve_screen_position_commands
,
7279 doc
: /* A list of commands whose scrolling should keep screen position unchanged.
7280 This list defines the names of scroll commands affected by the variable
7281 `scroll-preserve-screen-position'. */);
7282 Vscroll_preserve_screen_position_commands
=
7283 Fcons (Qscroll_down
, Fcons (Qscroll_up
, Qnil
));
7285 DEFVAR_LISP ("window-point-insertion-type", &Vwindow_point_insertion_type
,
7286 doc
: /* Type of marker to use for `window-point'. */);
7287 Vwindow_point_insertion_type
= Qnil
;
7289 DEFVAR_LISP ("window-configuration-change-hook",
7290 &Vwindow_configuration_change_hook
,
7291 doc
: /* Functions to call when window configuration changes.
7292 The buffer-local part is run once per window, with the relevant window
7293 selected; while the global part is run only once for the modified frame,
7294 with the relevant frame selected. */);
7295 Vwindow_configuration_change_hook
= Qnil
;
7297 DEFVAR_LISP ("recenter-redisplay", &Vrecenter_redisplay
,
7298 doc
: /* If non-nil, then the `recenter' command with a nil argument
7299 the entire frame to be redrawn; the special value `tty' causes the
7300 frame to be redrawn only if it is a tty frame. */);
7301 Vrecenter_redisplay
= Qtty
;
7304 defsubr (&Sselected_window
);
7305 defsubr (&Sminibuffer_window
);
7306 defsubr (&Swindow_minibuffer_p
);
7307 defsubr (&Swindowp
);
7308 defsubr (&Swindow_live_p
);
7309 defsubr (&Spos_visible_in_window_p
);
7310 defsubr (&Swindow_line_height
);
7311 defsubr (&Swindow_buffer
);
7312 defsubr (&Swindow_height
);
7313 defsubr (&Swindow_width
);
7314 defsubr (&Swindow_full_width_p
);
7315 defsubr (&Swindow_hscroll
);
7316 defsubr (&Sset_window_hscroll
);
7317 defsubr (&Swindow_redisplay_end_trigger
);
7318 defsubr (&Sset_window_redisplay_end_trigger
);
7319 defsubr (&Swindow_edges
);
7320 defsubr (&Swindow_pixel_edges
);
7321 defsubr (&Swindow_inside_edges
);
7322 defsubr (&Swindow_inside_pixel_edges
);
7323 defsubr (&Scoordinates_in_window_p
);
7324 defsubr (&Swindow_at
);
7325 defsubr (&Swindow_point
);
7326 defsubr (&Swindow_start
);
7327 defsubr (&Swindow_end
);
7328 defsubr (&Sset_window_point
);
7329 defsubr (&Sset_window_start
);
7330 defsubr (&Swindow_dedicated_p
);
7331 defsubr (&Sset_window_dedicated_p
);
7332 defsubr (&Swindow_display_table
);
7333 defsubr (&Sset_window_display_table
);
7334 defsubr (&Snext_window
);
7335 defsubr (&Sprevious_window
);
7336 defsubr (&Sother_window
);
7337 defsubr (&Sget_lru_window
);
7338 defsubr (&Sget_largest_window
);
7339 defsubr (&Sget_buffer_window
);
7340 defsubr (&Sdelete_other_windows
);
7341 defsubr (&Sdelete_windows_on
);
7342 defsubr (&Sreplace_buffer_in_windows
);
7343 defsubr (&Sdelete_window
);
7344 defsubr (&Sset_window_buffer
);
7345 defsubr (&Sselect_window
);
7346 defsubr (&Sforce_window_update
);
7347 defsubr (&Ssplit_window
);
7348 defsubr (&Senlarge_window
);
7349 defsubr (&Sshrink_window
);
7350 defsubr (&Sadjust_window_trailing_edge
);
7351 defsubr (&Sscroll_up
);
7352 defsubr (&Sscroll_down
);
7353 defsubr (&Sscroll_left
);
7354 defsubr (&Sscroll_right
);
7355 defsubr (&Sother_window_for_scrolling
);
7356 defsubr (&Sscroll_other_window
);
7357 defsubr (&Sminibuffer_selected_window
);
7358 defsubr (&Srecenter
);
7359 defsubr (&Swindow_text_height
);
7360 defsubr (&Smove_to_window_line
);
7361 defsubr (&Swindow_configuration_p
);
7362 defsubr (&Swindow_configuration_frame
);
7363 defsubr (&Sset_window_configuration
);
7364 defsubr (&Scurrent_window_configuration
);
7365 defsubr (&Ssave_window_excursion
);
7366 defsubr (&Swindow_tree
);
7367 defsubr (&Sset_window_margins
);
7368 defsubr (&Swindow_margins
);
7369 defsubr (&Sset_window_fringes
);
7370 defsubr (&Swindow_fringes
);
7371 defsubr (&Sset_window_scroll_bars
);
7372 defsubr (&Swindow_scroll_bars
);
7373 defsubr (&Swindow_vscroll
);
7374 defsubr (&Sset_window_vscroll
);
7375 defsubr (&Scompare_window_configurations
);
7376 defsubr (&Swindow_list
);
7377 defsubr (&Swindow_parameters
);
7378 defsubr (&Swindow_parameter
);
7379 defsubr (&Sset_window_parameter
);
7386 initial_define_key (control_x_map
, '1', "delete-other-windows");
7387 initial_define_key (control_x_map
, '2', "split-window");
7388 initial_define_key (control_x_map
, '0', "delete-window");
7389 initial_define_key (control_x_map
, 'o', "other-window");
7390 initial_define_key (control_x_map
, '^', "enlarge-window");
7391 initial_define_key (control_x_map
, '<', "scroll-left");
7392 initial_define_key (control_x_map
, '>', "scroll-right");
7394 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
7395 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
7396 initial_define_key (meta_map
, 'v', "scroll-down");
7399 /* arch-tag: 90a9c576-0590-48f1-a5f1-6c96a0452d9f
7400 (do not change this comment) */