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
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/>. */
35 #include "dispextern.h"
36 #include "blockinput.h"
37 #include "intervals.h"
38 #include "termhooks.h" /* For FRAME_TERMINAL. */
42 #endif /* HAVE_X_WINDOWS */
54 Lisp_Object Qwindowp
, Qwindow_live_p
, Qwindow_configuration_p
;
55 Lisp_Object Qdisplay_buffer
;
56 Lisp_Object Qscroll_up
, Qscroll_down
;
57 Lisp_Object Qwindow_size_fixed
;
59 extern Lisp_Object Qleft_margin
, Qright_margin
;
61 static int displayed_window_lines
P_ ((struct window
*));
62 static struct window
*decode_window
P_ ((Lisp_Object
));
63 static int count_windows
P_ ((struct window
*));
64 static int get_leaf_windows
P_ ((struct window
*, struct window
**, int));
65 static void window_scroll
P_ ((Lisp_Object
, int, int, int));
66 static void window_scroll_pixel_based
P_ ((Lisp_Object
, int, int, int));
67 static void window_scroll_line_based
P_ ((Lisp_Object
, int, int, int));
68 static int window_min_size_1
P_ ((struct window
*, int, int));
69 static int window_min_size_2
P_ ((struct window
*, int, int));
70 static int window_min_size
P_ ((struct window
*, int, int, int, int *));
71 static void size_window
P_ ((Lisp_Object
, int, int, int, int, int));
72 static int freeze_window_start
P_ ((struct window
*, void *));
73 static int window_fixed_size_p
P_ ((struct window
*, int, int));
74 static void enlarge_window
P_ ((Lisp_Object
, int, int));
75 static Lisp_Object window_list
P_ ((void));
76 static int add_window_to_list
P_ ((struct window
*, void *));
77 static int candidate_window_p
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
79 static Lisp_Object next_window
P_ ((Lisp_Object
, Lisp_Object
,
81 static void decode_next_window_args
P_ ((Lisp_Object
*, Lisp_Object
*,
83 static int foreach_window_1
P_ ((struct window
*,
84 int (* fn
) (struct window
*, void *),
86 static Lisp_Object window_list_1
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
88 /* This is the window in which the terminal's cursor should
89 be left when nothing is being done with it. This must
90 always be a leaf window, and its buffer is selected by
91 the top level editing loop at the end of each command.
93 This value is always the same as
94 FRAME_SELECTED_WINDOW (selected_frame). */
96 Lisp_Object selected_window
;
98 /* A list of all windows for use by next_window and Fwindow_list.
99 Functions creating or deleting windows should invalidate this cache
100 by setting it to nil. */
102 Lisp_Object Vwindow_list
;
104 /* The mini-buffer window of the selected frame.
105 Note that you cannot test for mini-bufferness of an arbitrary window
106 by comparing against this; but you can test for mini-bufferness of
107 the selected window. */
109 Lisp_Object minibuf_window
;
111 /* Non-nil means it is the window whose mode line should be
112 shown as the selected window when the minibuffer is selected. */
114 Lisp_Object minibuf_selected_window
;
116 /* Non-nil means it is the window for C-M-v to scroll
117 when the mini-buffer is selected. */
119 Lisp_Object Vminibuf_scroll_window
;
121 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
123 Lisp_Object Vother_window_scroll_buffer
;
125 /* Non-nil means it's function to call to display temp buffers. */
127 Lisp_Object Vtemp_buffer_show_function
;
129 /* Non-zero means line and page scrolling on tall lines (with images)
130 does partial scrolling by modifying window-vscroll. */
132 int auto_window_vscroll_p
;
134 /* Non-zero means to use mode-line-inactive face in all windows but the
135 selected-window and the minibuffer-scroll-window when the
136 minibuffer is active. */
137 int mode_line_in_non_selected_windows
;
139 /* If a window gets smaller than either of these, it is removed. */
141 EMACS_INT window_min_height
;
142 EMACS_INT window_min_width
;
144 /* Hook run at end of temp_output_buffer_show. */
146 Lisp_Object Qtemp_buffer_show_hook
;
148 /* Number of lines of continuity in scrolling by screenfuls. */
150 EMACS_INT next_screen_context_lines
;
152 /* Incremented for each window created. */
154 static int sequence_number
;
156 /* Nonzero after init_window_once has finished. */
158 static int window_initialized
;
160 /* Hook to run when window config changes. */
162 static Lisp_Object Qwindow_configuration_change_hook
;
163 static Lisp_Object Vwindow_configuration_change_hook
;
165 /* Non-nil means scroll commands try to put point
166 at the same screen height as previously. */
168 Lisp_Object Vscroll_preserve_screen_position
;
170 /* Non-nil means that text is inserted before window's markers. */
172 Lisp_Object Vwindow_point_insertion_type
;
174 /* Incremented by 1 whenever a window is deleted. */
176 int window_deletion_count
;
178 /* Used by the function window_scroll_pixel_based */
180 static int window_scroll_pixel_based_preserve_x
;
181 static int window_scroll_pixel_based_preserve_y
;
183 /* Same for window_scroll_line_based. */
185 static int window_scroll_preserve_hpos
;
186 static int window_scroll_preserve_vpos
;
188 #if 0 /* This isn't used anywhere. */
189 /* Nonzero means we can split a frame even if it is "unsplittable". */
190 static int inhibit_frame_unsplittable
;
193 extern EMACS_INT scroll_margin
;
195 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
197 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
198 doc
: /* Return t if OBJECT is a window. */)
202 return WINDOWP (object
) ? Qt
: Qnil
;
205 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
206 doc
: /* Return t if OBJECT is a window which is currently visible. */)
210 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
217 register struct window
*p
;
219 p
= allocate_window ();
221 XSETFASTINT (p
->sequence_number
, sequence_number
);
222 XSETFASTINT (p
->left_col
, 0);
223 XSETFASTINT (p
->top_line
, 0);
224 XSETFASTINT (p
->total_lines
, 0);
225 XSETFASTINT (p
->total_cols
, 0);
226 XSETFASTINT (p
->hscroll
, 0);
227 XSETFASTINT (p
->min_hscroll
, 0);
228 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
229 p
->start
= Fmake_marker ();
230 p
->pointm
= Fmake_marker ();
231 XSETFASTINT (p
->use_time
, 0);
233 p
->display_table
= Qnil
;
235 p
->window_parameters
= Qnil
;
236 p
->pseudo_window_p
= 0;
237 bzero (&p
->cursor
, sizeof (p
->cursor
));
238 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
239 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
240 p
->desired_matrix
= p
->current_matrix
= 0;
241 p
->nrows_scale_factor
= p
->ncols_scale_factor
= 1;
242 p
->phys_cursor_type
= -1;
243 p
->phys_cursor_width
= -1;
244 p
->must_be_updated_p
= 0;
245 XSETFASTINT (p
->window_end_vpos
, 0);
246 XSETFASTINT (p
->window_end_pos
, 0);
247 p
->window_end_valid
= Qnil
;
250 XSETFASTINT (p
->last_point
, 0);
251 p
->frozen_window_start_p
= 0;
252 p
->last_cursor_off_p
= p
->cursor_off_p
= 0;
253 p
->left_margin_cols
= Qnil
;
254 p
->right_margin_cols
= Qnil
;
255 p
->left_fringe_width
= Qnil
;
256 p
->right_fringe_width
= Qnil
;
257 p
->fringes_outside_margins
= Qnil
;
258 p
->scroll_bar_width
= Qnil
;
259 p
->vertical_scroll_bar_type
= Qt
;
260 p
->resize_proportionally
= Qnil
;
266 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
267 doc
: /* Return the window that the cursor now appears in and commands apply to. */)
270 return selected_window
;
273 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
274 doc
: /* Return the window used now for minibuffers.
275 If the optional argument FRAME is specified, return the minibuffer window
276 used by that frame. */)
281 frame
= selected_frame
;
282 CHECK_LIVE_FRAME (frame
);
283 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
286 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
287 doc
: /* Return non-nil if WINDOW is a minibuffer window.
288 WINDOW defaults to the selected window. */)
292 struct window
*w
= decode_window (window
);
293 return MINI_WINDOW_P (w
) ? Qt
: Qnil
;
297 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
298 Spos_visible_in_window_p
, 0, 3, 0,
299 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
300 Return nil if that position is scrolled vertically out of view.
301 If a character is only partially visible, nil is returned, unless the
302 optional argument PARTIALLY is non-nil.
303 If POS is only out of view because of horizontal scrolling, return non-nil.
304 If POS is t, it specifies the position of the last visible glyph in WINDOW.
305 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
307 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
308 return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
309 where X and Y are the pixel coordinates relative to the top left corner
310 of the window. The remaining elements are omitted if the character after
311 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
312 off-window at the top and bottom of the row, ROWH is the height of the
313 display row, and VPOS is the row number (0-based) containing POS. */)
314 (pos
, window
, partially
)
315 Lisp_Object pos
, window
, partially
;
317 register struct window
*w
;
319 register struct buffer
*buf
;
321 Lisp_Object in_window
= Qnil
;
322 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
325 w
= decode_window (window
);
326 buf
= XBUFFER (w
->buffer
);
327 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
331 else if (!NILP (pos
))
333 CHECK_NUMBER_COERCE_MARKER (pos
);
336 else if (w
== XWINDOW (selected_window
))
339 posint
= XMARKER (w
->pointm
)->charpos
;
341 /* If position is above window start or outside buffer boundaries,
342 or if window start is out of range, position is not visible. */
344 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
345 && CHARPOS (top
) >= BUF_BEGV (buf
)
346 && CHARPOS (top
) <= BUF_ZV (buf
)
347 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
348 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
351 if (!NILP (in_window
) && !NILP (partially
))
353 Lisp_Object part
= Qnil
;
355 part
= list4 (make_number (rtop
), make_number (rbot
),
356 make_number (rowh
), make_number (vpos
));
357 in_window
= Fcons (make_number (x
),
358 Fcons (make_number (y
), part
));
364 DEFUN ("window-line-height", Fwindow_line_height
,
365 Swindow_line_height
, 0, 2, 0,
366 doc
: /* Return height in pixels of text line LINE in window WINDOW.
367 If WINDOW is nil or omitted, use selected window.
369 Return height of current line if LINE is omitted or nil. Return height of
370 header or mode line if LINE is `header-line' and `mode-line'.
371 Otherwise, LINE is a text line number starting from 0. A negative number
372 counts from the end of the window.
374 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
375 in pixels of the visible part of the line, VPOS and YPOS are the
376 vertical position in lines and pixels of the line, relative to the top
377 of the first text line, and OFFBOT is the number of off-window pixels at
378 the bottom of the text line. If there are off-window pixels at the top
379 of the (first) text line, YPOS is negative.
381 Return nil if window display is not up-to-date. In that case, use
382 `pos-visible-in-window-p' to obtain the information. */)
384 Lisp_Object line
, window
;
386 register struct window
*w
;
387 register struct buffer
*b
;
388 struct glyph_row
*row
, *end_row
;
389 int max_y
, crop
, i
, n
;
391 w
= decode_window (window
);
394 || w
->pseudo_window_p
)
397 CHECK_BUFFER (w
->buffer
);
398 b
= XBUFFER (w
->buffer
);
400 /* Fail if current matrix is not up-to-date. */
401 if (NILP (w
->window_end_valid
)
402 || current_buffer
->clip_changed
403 || current_buffer
->prevent_redisplay_optimizations_p
404 || XFASTINT (w
->last_modified
) < BUF_MODIFF (b
)
405 || XFASTINT (w
->last_overlay_modified
) < BUF_OVERLAY_MODIFF (b
))
411 if (i
< 0 || i
>= w
->current_matrix
->nrows
412 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
414 max_y
= window_text_bottom_y (w
);
418 if (EQ (line
, Qheader_line
))
420 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
422 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
425 return list4 (make_number (row
->height
),
426 make_number (0), make_number (0),
430 if (EQ (line
, Qmode_line
))
432 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
435 return list4 (make_number (row
->height
),
436 make_number (0), /* not accurate */
437 make_number (WINDOW_HEADER_LINE_HEIGHT (w
)
438 + window_text_bottom_y (w
)),
445 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
446 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
447 max_y
= window_text_bottom_y (w
);
450 while ((n
< 0 || i
< n
)
451 && row
<= end_row
&& row
->enabled_p
452 && row
->y
+ row
->height
< max_y
)
455 if (row
> end_row
|| !row
->enabled_p
)
467 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
468 return list4 (make_number (row
->height
+ min (0, row
->y
) - crop
),
470 make_number (row
->y
),
476 static struct window
*
477 decode_window (window
)
478 register Lisp_Object window
;
481 return XWINDOW (selected_window
);
483 CHECK_LIVE_WINDOW (window
);
484 return XWINDOW (window
);
487 static struct window
*
488 decode_any_window (window
)
489 register Lisp_Object window
;
492 return XWINDOW (selected_window
);
494 CHECK_WINDOW (window
);
495 return XWINDOW (window
);
498 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
499 doc
: /* Return the buffer that WINDOW is displaying.
500 WINDOW defaults to the selected window. */)
504 return decode_window (window
)->buffer
;
507 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
508 doc
: /* Return the number of lines in WINDOW.
509 WINDOW defaults to the selected window.
511 The return value includes WINDOW's mode line and header line, if any. */)
515 return decode_any_window (window
)->total_lines
;
518 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
519 doc
: /* Return the number of display columns in WINDOW.
520 WINDOW defaults to the selected window.
522 Note: The return value is the number of columns available for text in
523 WINDOW. If you want to find out how many columns WINDOW takes up, use
524 (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
528 return make_number (window_box_text_cols (decode_any_window (window
)));
531 DEFUN ("window-full-width-p", Fwindow_full_width_p
, Swindow_full_width_p
, 0, 1, 0,
532 doc
: /* Return t if WINDOW is as wide as its frame.
533 WINDOW defaults to the selected window. */)
537 return WINDOW_FULL_WIDTH_P (decode_any_window (window
)) ? Qt
: Qnil
;
540 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
541 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
542 WINDOW defaults to the selected window. */)
546 return decode_window (window
)->hscroll
;
549 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
550 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
551 Return NCOL. NCOL should be zero or positive.
553 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
554 window so that the location of point moves off-window. */)
556 Lisp_Object window
, ncol
;
558 struct window
*w
= decode_window (window
);
562 hscroll
= max (0, XINT (ncol
));
564 /* Prevent redisplay shortcuts when changing the hscroll. */
565 if (XINT (w
->hscroll
) != hscroll
)
566 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
568 w
->hscroll
= make_number (hscroll
);
572 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
573 Swindow_redisplay_end_trigger
, 0, 1, 0,
574 doc
: /* Return WINDOW's redisplay end trigger value.
575 WINDOW defaults to the selected window.
576 See `set-window-redisplay-end-trigger' for more information. */)
580 return decode_window (window
)->redisplay_end_trigger
;
583 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
584 Sset_window_redisplay_end_trigger
, 2, 2, 0,
585 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
586 VALUE should be a buffer position (typically a marker) or nil.
587 If it is a buffer position, then if redisplay in WINDOW reaches a position
588 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
589 with two arguments: WINDOW, and the end trigger value.
590 Afterwards the end-trigger value is reset to nil. */)
592 register Lisp_Object window
, value
;
594 register struct window
*w
;
596 w
= decode_window (window
);
597 w
->redisplay_end_trigger
= value
;
601 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
602 doc
: /* Return a list of the edge coordinates of WINDOW.
603 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
604 RIGHT is one more than the rightmost column occupied by WINDOW,
605 and BOTTOM is one more than the bottommost row occupied by WINDOW.
606 The edges include the space used by the window's scroll bar,
607 display margins, fringes, header line, and mode line, if it has them.
608 To get the edges of the actual text area, use `window-inside-edges'. */)
612 register struct window
*w
= decode_any_window (window
);
614 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w
)),
615 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w
)),
616 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w
)),
617 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w
)),
621 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
622 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
623 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
624 RIGHT is one more than the rightmost x position occupied by WINDOW,
625 and BOTTOM is one more than the bottommost y position occupied by WINDOW.
626 The pixel edges include the space used by the window's scroll bar,
627 display margins, fringes, header line, and mode line, if it has them.
628 To get the edges of the actual text area, use `window-inside-pixel-edges'. */)
632 register struct window
*w
= decode_any_window (window
);
634 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
)),
635 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
)),
636 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
)),
637 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
)),
641 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
642 doc
: /* Return a list of the edge coordinates of WINDOW.
643 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
644 RIGHT is one more than the rightmost column used by text in WINDOW,
645 and BOTTOM is one more than the bottommost row used by text in WINDOW.
646 The inside edges do not include the space used by the window's scroll bar,
647 display margins, fringes, header line, and/or mode line. */)
651 register struct window
*w
= decode_any_window (window
);
653 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w
)
654 + WINDOW_LEFT_MARGIN_COLS (w
)
655 + WINDOW_LEFT_FRINGE_COLS (w
)),
656 make_number (WINDOW_TOP_EDGE_LINE (w
)
657 + WINDOW_HEADER_LINE_LINES (w
)),
658 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w
)
659 - WINDOW_RIGHT_MARGIN_COLS (w
)
660 - WINDOW_RIGHT_FRINGE_COLS (w
)),
661 make_number (WINDOW_BOTTOM_EDGE_LINE (w
)
662 - WINDOW_MODE_LINE_LINES (w
)));
665 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
666 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
667 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
668 RIGHT is one more than the rightmost x position used by text in WINDOW,
669 and BOTTOM is one more than the bottommost y position used by text in WINDOW.
670 The inside edges do not include the space used by the window's scroll bar,
671 display margins, fringes, header line, and/or mode line. */)
675 register struct window
*w
= decode_any_window (window
);
677 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
678 + WINDOW_LEFT_MARGIN_WIDTH (w
)
679 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
680 make_number (WINDOW_TOP_EDGE_Y (w
)
681 + WINDOW_HEADER_LINE_HEIGHT (w
)),
682 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
683 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
684 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
685 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
686 - WINDOW_MODE_LINE_HEIGHT (w
)));
689 /* Test if the character at column *X, row *Y is within window W.
690 If it is not, return ON_NOTHING;
691 if it is in the window's text area,
692 set *x and *y to its location relative to the upper left corner
695 if it is on the window's modeline, return ON_MODE_LINE;
696 if it is on the border between the window and its right sibling,
697 return ON_VERTICAL_BORDER.
698 if it is on a scroll bar,
699 return ON_SCROLL_BAR.
700 if it is on the window's top line, return ON_HEADER_LINE;
701 if it is in left or right fringe of the window,
702 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y
703 to window-relative coordinates;
704 if it is in the marginal area to the left/right of the window,
705 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y
706 to window-relative coordinates.
708 X and Y are frame relative pixel coordinates. */
710 static enum window_part
711 coordinates_in_window (w
, x
, y
)
712 register struct window
*w
;
715 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
716 int left_x
, right_x
, top_y
, bottom_y
;
717 enum window_part part
;
718 int ux
= FRAME_COLUMN_WIDTH (f
);
719 int x0
= WINDOW_LEFT_EDGE_X (w
);
720 int x1
= WINDOW_RIGHT_EDGE_X (w
);
721 /* The width of the area where the vertical line can be dragged.
722 (Between mode lines for instance. */
723 int grabbable_width
= ux
;
724 int lmargin_width
, rmargin_width
, text_left
, text_right
;
726 /* In what's below, we subtract 1 when computing right_x because we
727 want the rightmost pixel, which is given by left_pixel+width-1. */
728 if (w
->pseudo_window_p
)
731 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
732 top_y
= WINDOW_TOP_EDGE_Y (w
);
733 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
737 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
738 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
739 top_y
= WINDOW_TOP_EDGE_Y (w
);
740 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
743 /* Outside any interesting row? */
744 if (*y
< top_y
|| *y
>= bottom_y
)
747 /* On the mode line or header line? If it's near the start of
748 the mode or header line of window that's has a horizontal
749 sibling, say it's on the vertical line. That's to be able
750 to resize windows horizontally in case we're using toolkit
753 if (WINDOW_WANTS_MODELINE_P (w
)
754 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
758 header_vertical_border_check
:
759 /* We're somewhere on the mode line. We consider the place
760 between mode lines of horizontally adjacent mode lines
761 as the vertical border. If scroll bars on the left,
762 return the right window. */
763 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
764 || WINDOW_RIGHTMOST_P (w
))
766 if (!WINDOW_LEFTMOST_P (w
) && eabs (*x
- x0
) < grabbable_width
)
768 /* Convert X and Y to window relative coordinates.
769 Vertical border is at the left edge of window. */
770 *x
= max (0, *x
- x0
);
772 return ON_VERTICAL_BORDER
;
777 if (eabs (*x
- x1
) < grabbable_width
)
779 /* Convert X and Y to window relative coordinates.
780 Vertical border is at the right edge of window. */
781 *x
= min (x1
, *x
) - x0
;
783 return ON_VERTICAL_BORDER
;
787 if (*x
< x0
|| *x
>= x1
)
790 /* Convert X and Y to window relative coordinates.
791 Mode line starts at left edge of window. */
797 if (WINDOW_WANTS_HEADER_LINE_P (w
)
798 && *y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
))
800 part
= ON_HEADER_LINE
;
801 goto header_vertical_border_check
;
804 if (*x
< x0
|| *x
>= x1
)
807 /* Outside any interesting column? */
808 if (*x
< left_x
|| *x
> right_x
)
811 return ON_SCROLL_BAR
;
814 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
815 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
817 text_left
= window_box_left (w
, TEXT_AREA
);
818 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
820 if (FRAME_WINDOW_P (f
))
822 if (!w
->pseudo_window_p
823 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
824 && !WINDOW_RIGHTMOST_P (w
)
825 && (eabs (*x
- right_x
) < grabbable_width
))
827 /* Convert X and Y to window relative coordinates.
828 Vertical border is at the right edge of window. */
829 *x
= min (right_x
, *x
) - left_x
;
831 return ON_VERTICAL_BORDER
;
836 /* Need to say "*x > right_x" rather than >=, since on character
837 terminals, the vertical line's x coordinate is right_x. */
838 if (!w
->pseudo_window_p
839 && !WINDOW_RIGHTMOST_P (w
)
840 && *x
> right_x
- ux
)
842 /* On the border on the right side of the window? Assume that
843 this area begins at RIGHT_X minus a canonical char width. */
844 *x
= min (right_x
, *x
) - left_x
;
846 return ON_VERTICAL_BORDER
;
852 if (lmargin_width
> 0
853 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
854 ? (*x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
855 : (*x
< left_x
+ lmargin_width
)))
858 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
859 *x
-= WINDOW_LEFT_FRINGE_WIDTH (w
);
861 return ON_LEFT_MARGIN
;
864 /* Convert X and Y to window-relative pixel coordinates. */
867 return ON_LEFT_FRINGE
;
870 if (*x
>= text_right
)
872 if (rmargin_width
> 0
873 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
874 ? (*x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
875 : (*x
>= right_x
- rmargin_width
)))
877 *x
-= right_x
- rmargin_width
;
878 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
879 *x
+= WINDOW_RIGHT_FRINGE_WIDTH (w
);
881 return ON_RIGHT_MARGIN
;
884 /* Convert X and Y to window-relative pixel coordinates. */
885 *x
-= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
);
887 return ON_RIGHT_FRINGE
;
890 /* Everything special ruled out - must be on text area */
897 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
898 Scoordinates_in_window_p
, 2, 2, 0,
899 doc
: /* Return non-nil if COORDINATES are in WINDOW.
900 COORDINATES is a cons of the form (X . Y), X and Y being distances
901 measured in characters from the upper-left corner of the frame.
902 \(0 . 0) denotes the character in the upper left corner of the
904 If COORDINATES are in the text portion of WINDOW,
905 the coordinates relative to the window are returned.
906 If they are in the mode line of WINDOW, `mode-line' is returned.
907 If they are in the top mode line of WINDOW, `header-line' is returned.
908 If they are in the left fringe of WINDOW, `left-fringe' is returned.
909 If they are in the right fringe of WINDOW, `right-fringe' is returned.
910 If they are on the border between WINDOW and its right sibling,
911 `vertical-line' is returned.
912 If they are in the windows's left or right marginal areas, `left-margin'\n\
913 or `right-margin' is returned. */)
914 (coordinates
, window
)
915 register Lisp_Object coordinates
, window
;
922 CHECK_WINDOW (window
);
923 w
= XWINDOW (window
);
924 f
= XFRAME (w
->frame
);
925 CHECK_CONS (coordinates
);
926 lx
= Fcar (coordinates
);
927 ly
= Fcdr (coordinates
);
928 CHECK_NUMBER_OR_FLOAT (lx
);
929 CHECK_NUMBER_OR_FLOAT (ly
);
930 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
931 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
933 switch (coordinates_in_window (w
, &x
, &y
))
939 /* X and Y are now window relative pixel coordinates. Convert
940 them to canonical char units before returning them. */
941 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
942 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
947 case ON_VERTICAL_BORDER
:
948 return Qvertical_line
;
956 case ON_RIGHT_FRINGE
:
957 return Qright_fringe
;
962 case ON_RIGHT_MARGIN
:
963 return Qright_margin
;
966 /* Historically we are supposed to return nil in this case. */
975 /* Callback for foreach_window, used in window_from_coordinates.
976 Check if window W contains coordinates specified by USER_DATA which
977 is actually a pointer to a struct check_window_data CW.
979 Check if window W contains coordinates *CW->x and *CW->y. If it
980 does, return W in *CW->window, as Lisp_Object, and return in
981 *CW->part the part of the window under coordinates *X,*Y. Return
982 zero from this function to stop iterating over windows. */
984 struct check_window_data
988 enum window_part
*part
;
992 check_window_containing (w
, user_data
)
996 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
997 enum window_part found
;
1000 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1001 if (found
!= ON_NOTHING
)
1004 XSETWINDOW (*cw
->window
, w
);
1012 /* Find the window containing frame-relative pixel position X/Y and
1013 return it as a Lisp_Object.
1015 If X, Y is on one of the window's special `window_part' elements,
1016 set *PART to the id of that element, and return X and Y converted
1017 to window relative coordinates in WX and WY.
1019 If there is no window under X, Y return nil and leave *PART
1020 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1022 This function was previously implemented with a loop cycling over
1023 windows with Fnext_window, and starting with the frame's selected
1024 window. It turned out that this doesn't work with an
1025 implementation of next_window using Vwindow_list, because
1026 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1027 tree of F when this function is called asynchronously from
1028 note_mouse_highlight. The original loop didn't terminate in this
1032 window_from_coordinates (f
, x
, y
, part
, wx
, wy
, tool_bar_p
)
1035 enum window_part
*part
;
1040 struct check_window_data cw
;
1041 enum window_part dummy
;
1047 cw
.window
= &window
, cw
.x
= &x
, cw
.y
= &y
; cw
.part
= part
;
1048 foreach_window (f
, check_window_containing
, &cw
);
1050 /* If not found above, see if it's in the tool bar window, if a tool
1054 && WINDOWP (f
->tool_bar_window
)
1055 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1056 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), &x
, &y
)
1060 window
= f
->tool_bar_window
;
1069 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1070 doc
: /* Return window containing coordinates X and Y on FRAME.
1071 If omitted, FRAME defaults to the currently selected frame.
1072 The top left corner of the frame is considered to be row 0,
1075 Lisp_Object x
, y
, frame
;
1080 frame
= selected_frame
;
1081 CHECK_LIVE_FRAME (frame
);
1084 /* Check that arguments are integers or floats. */
1085 CHECK_NUMBER_OR_FLOAT (x
);
1086 CHECK_NUMBER_OR_FLOAT (y
);
1088 return window_from_coordinates (f
,
1089 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1090 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1091 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1092 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1096 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1097 doc
: /* Return current value of point in WINDOW.
1098 WINDOW defaults to the selected window.
1100 For a nonselected window, this is the value point would have
1101 if that window were selected.
1103 Note that, when WINDOW is the selected window and its buffer
1104 is also currently selected, the value returned is the same as (point).
1105 It would be more strictly correct to return the `top-level' value
1106 of point, outside of any save-excursion forms.
1107 But that is hard to define. */)
1111 register struct window
*w
= decode_window (window
);
1113 if (w
== XWINDOW (selected_window
)
1114 && current_buffer
== XBUFFER (w
->buffer
))
1116 return Fmarker_position (w
->pointm
);
1119 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1120 doc
: /* Return position at which display currently starts in WINDOW.
1121 WINDOW defaults to the selected window.
1122 This is updated by redisplay or by calling `set-window-start'. */)
1126 return Fmarker_position (decode_window (window
)->start
);
1129 /* This is text temporarily removed from the doc string below.
1131 This function returns nil if the position is not currently known.
1132 That happens when redisplay is preempted and doesn't finish.
1133 If in that case you want to compute where the end of the window would
1134 have been if redisplay had finished, do this:
1136 (goto-char (window-start window))
1137 (vertical-motion (1- (window-height window)) window)
1140 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1141 doc
: /* Return position at which display currently ends in WINDOW.
1142 WINDOW defaults to the selected window.
1143 This is updated by redisplay, when it runs to completion.
1144 Simply changing the buffer text or setting `window-start'
1145 does not update this value.
1146 Return nil if there is no recorded value. \(This can happen if the
1147 last redisplay of WINDOW was preempted, and did not finish.)
1148 If UPDATE is non-nil, compute the up-to-date position
1149 if it isn't already recorded. */)
1151 Lisp_Object window
, update
;
1154 struct window
*w
= decode_window (window
);
1162 #if 0 /* This change broke some things. We should make it later. */
1163 /* If we don't know the end position, return nil.
1164 The user can compute it with vertical-motion if he wants to.
1165 It would be nicer to do it automatically,
1166 but that's so slow that it would probably bother people. */
1167 if (NILP (w
->window_end_valid
))
1172 && ! (! NILP (w
->window_end_valid
)
1173 && XFASTINT (w
->last_modified
) >= BUF_MODIFF (b
)
1174 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (b
))
1177 struct text_pos startp
;
1179 struct buffer
*old_buffer
= NULL
;
1181 /* Cannot use Fvertical_motion because that function doesn't
1182 cope with variable-height lines. */
1183 if (b
!= current_buffer
)
1185 old_buffer
= current_buffer
;
1186 set_buffer_internal (b
);
1189 /* In case W->start is out of the range, use something
1190 reasonable. This situation occurred when loading a file with
1191 `-l' containing a call to `rmail' with subsequent other
1192 commands. At the end, W->start happened to be BEG, while
1193 rmail had already narrowed the buffer. */
1194 if (XMARKER (w
->start
)->charpos
< BEGV
)
1195 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1196 else if (XMARKER (w
->start
)->charpos
> ZV
)
1197 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1199 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1201 start_display (&it
, w
, startp
);
1202 move_it_vertically (&it
, window_box_height (w
));
1203 if (it
.current_y
< it
.last_visible_y
)
1204 move_it_past_eol (&it
);
1205 value
= make_number (IT_CHARPOS (it
));
1208 set_buffer_internal (old_buffer
);
1211 XSETINT (value
, BUF_Z (b
) - XFASTINT (w
->window_end_pos
));
1216 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1217 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1220 Lisp_Object window
, pos
;
1222 register struct window
*w
= decode_window (window
);
1224 CHECK_NUMBER_COERCE_MARKER (pos
);
1225 if (w
== XWINDOW (selected_window
)
1226 && XBUFFER (w
->buffer
) == current_buffer
)
1229 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1231 /* We have to make sure that redisplay updates the window to show
1232 the new value of point. */
1233 if (!EQ (window
, selected_window
))
1234 ++windows_or_buffers_changed
;
1239 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1240 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1241 WINDOW defaults to the selected window. Return POS.
1242 Optional third arg NOFORCE non-nil inhibits next redisplay from
1243 overriding motion of point in order to display at this exact start. */)
1244 (window
, pos
, noforce
)
1245 Lisp_Object window
, pos
, noforce
;
1247 register struct window
*w
= decode_window (window
);
1249 CHECK_NUMBER_COERCE_MARKER (pos
);
1250 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1251 /* this is not right, but much easier than doing what is right. */
1252 w
->start_at_line_beg
= Qnil
;
1254 w
->force_start
= Qt
;
1255 w
->update_mode_line
= Qt
;
1256 XSETFASTINT (w
->last_modified
, 0);
1257 XSETFASTINT (w
->last_overlay_modified
, 0);
1258 if (!EQ (window
, selected_window
))
1259 windows_or_buffers_changed
++;
1265 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1267 doc
: /* Return non-nil when WINDOW is dedicated to its buffer.
1268 More precisely, return the value assigned by the last call of
1269 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1270 never called with WINDOW as its argument, or the value set by that
1271 function was internally reset since its last call. WINDOW defaults to
1272 the selected window.
1274 When a window is dedicated to its buffer, `display-buffer' will refrain
1275 from displaying another buffer in it. `get-lru-window' and
1276 `get-largest-window' treat dedicated windows specially.
1277 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1278 `kill-buffer' can delete a dedicated window and the containing frame.
1280 Functions like `set-window-buffer' may change the buffer displayed by a
1281 window, unless that window is "strongly" dedicated to its buffer, that
1282 is the value returned by `window-dedicated-p' is t. */)
1286 return decode_window (window
)->dedicated
;
1289 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1290 Sset_window_dedicated_p
, 2, 2, 0,
1291 doc
: /* Mark WINDOW as dedicated according to FLAG.
1292 WINDOW defaults to the selected window. FLAG non-nil means mark WINDOW
1293 as dedicated to its buffer. FLAG nil means mark WINDOW as non-dedicated.
1296 When a window is dedicated to its buffer, `display-buffer' will refrain
1297 from displaying another buffer in it. `get-lru-window' and
1298 `get-largest-window' treat dedicated windows specially.
1299 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1300 `kill-buffer' can delete a dedicated window and the containing
1303 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
1304 its buffer. Functions like `set-window-buffer' may change the buffer
1305 displayed by a window, unless that window is strongly dedicated to its
1306 buffer. If and when `set-window-buffer' displays another buffer in a
1307 window, it also makes sure that the window is not marked as dedicated. */)
1309 Lisp_Object window
, flag
;
1311 register struct window
*w
= decode_window (window
);
1313 w
->dedicated
= flag
;
1314 return w
->dedicated
;
1318 DEFUN ("window-parameters", Fwindow_parameters
, Swindow_parameters
,
1320 doc
: /* Return the parameters of WINDOW and their values.
1321 WINDOW defaults to the selected window. The return value is a list of
1322 elements of the form (PARAMETER . VALUE). */)
1326 return Fcopy_alist (decode_window (window
)->window_parameters
);
1329 DEFUN ("window-parameter", Fwindow_parameter
, Swindow_parameter
,
1331 doc
: /* Return WINDOW's value for PARAMETER.
1332 WINDOW defaults to the selected window. */)
1334 Lisp_Object window
, parameter
;
1338 result
= Fassq (parameter
, decode_window (window
)->window_parameters
);
1339 return CDR_SAFE (result
);
1342 DEFUN ("set-window-parameter", Fset_window_parameter
,
1343 Sset_window_parameter
, 3, 3, 0,
1344 doc
: /* Set WINDOW's value of PARAMETER to VALUE.
1345 WINDOW defaults to the selected window. Return VALUE. */)
1346 (window
, parameter
, value
)
1347 Lisp_Object window
, parameter
, value
;
1349 register struct window
*w
= decode_window (window
);
1350 Lisp_Object old_alist_elt
;
1352 old_alist_elt
= Fassq (parameter
, w
->window_parameters
);
1353 if (NILP (old_alist_elt
))
1354 w
->window_parameters
= Fcons (Fcons (parameter
, value
), w
->window_parameters
);
1356 Fsetcdr (old_alist_elt
, value
);
1361 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1363 doc
: /* Return the display-table that WINDOW is using.
1364 WINDOW defaults to the selected window. */)
1368 return decode_window (window
)->display_table
;
1371 /* Get the display table for use on window W. This is either W's
1372 display table or W's buffer's display table. Ignore the specified
1373 tables if they are not valid; if no valid table is specified,
1376 struct Lisp_Char_Table
*
1377 window_display_table (w
)
1380 struct Lisp_Char_Table
*dp
= NULL
;
1382 if (DISP_TABLE_P (w
->display_table
))
1383 dp
= XCHAR_TABLE (w
->display_table
);
1384 else if (BUFFERP (w
->buffer
))
1386 struct buffer
*b
= XBUFFER (w
->buffer
);
1388 if (DISP_TABLE_P (b
->display_table
))
1389 dp
= XCHAR_TABLE (b
->display_table
);
1390 else if (DISP_TABLE_P (Vstandard_display_table
))
1391 dp
= XCHAR_TABLE (Vstandard_display_table
);
1397 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1398 doc
: /* Set WINDOW's display-table to TABLE. */)
1400 register Lisp_Object window
, table
;
1402 register struct window
*w
;
1404 w
= decode_window (window
);
1405 w
->display_table
= table
;
1409 /* Record info on buffer window w is displaying
1410 when it is about to cease to display that buffer. */
1413 register struct window
*w
;
1420 if (b
!= XMARKER (w
->pointm
)->buffer
)
1424 if (w
== XWINDOW (selected_window
)
1425 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1426 /* Do this except when the selected window's buffer
1427 is being removed from some other window. */
1429 /* last_window_start records the start position that this buffer
1430 had in the last window to be disconnected from it.
1431 Now that this statement is unconditional,
1432 it is possible for the buffer to be displayed in the
1433 selected window, while last_window_start reflects another
1434 window which was recently showing the same buffer.
1435 Some people might say that might be a good thing. Let's see. */
1436 b
->last_window_start
= marker_position (w
->start
);
1438 /* Point in the selected window's buffer
1439 is actually stored in that buffer, and the window's pointm isn't used.
1440 So don't clobber point in that buffer. */
1441 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1442 /* This line helps to fix Horsley's testbug.el bug. */
1443 && !(WINDOWP (b
->last_selected_window
)
1444 && w
!= XWINDOW (b
->last_selected_window
)
1445 && EQ (buf
, XWINDOW (b
->last_selected_window
)->buffer
)))
1446 temp_set_point_both (b
,
1447 clip_to_bounds (BUF_BEGV (b
),
1448 XMARKER (w
->pointm
)->charpos
,
1450 clip_to_bounds (BUF_BEGV_BYTE (b
),
1451 marker_byte_position (w
->pointm
),
1454 if (WINDOWP (b
->last_selected_window
)
1455 && w
== XWINDOW (b
->last_selected_window
))
1456 b
->last_selected_window
= Qnil
;
1459 /* Put replacement into the window structure in place of old. */
1461 replace_window (old
, replacement
)
1462 Lisp_Object old
, replacement
;
1464 register Lisp_Object tem
;
1465 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
1467 /* If OLD is its frame's root_window, then replacement is the new
1468 root_window for that frame. */
1470 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1471 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
1473 p
->left_col
= o
->left_col
;
1474 p
->top_line
= o
->top_line
;
1475 p
->total_cols
= o
->total_cols
;
1476 p
->total_lines
= o
->total_lines
;
1477 p
->desired_matrix
= p
->current_matrix
= 0;
1479 bzero (&p
->cursor
, sizeof (p
->cursor
));
1480 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
1481 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
1482 p
->phys_cursor_type
= -1;
1483 p
->phys_cursor_width
= -1;
1484 p
->must_be_updated_p
= 0;
1485 p
->pseudo_window_p
= 0;
1486 XSETFASTINT (p
->window_end_vpos
, 0);
1487 XSETFASTINT (p
->window_end_pos
, 0);
1488 p
->window_end_valid
= Qnil
;
1489 p
->frozen_window_start_p
= 0;
1490 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
1492 p
->next
= tem
= o
->next
;
1494 XWINDOW (tem
)->prev
= replacement
;
1496 p
->prev
= tem
= o
->prev
;
1498 XWINDOW (tem
)->next
= replacement
;
1500 p
->parent
= tem
= o
->parent
;
1503 if (EQ (XWINDOW (tem
)->vchild
, old
))
1504 XWINDOW (tem
)->vchild
= replacement
;
1505 if (EQ (XWINDOW (tem
)->hchild
, old
))
1506 XWINDOW (tem
)->hchild
= replacement
;
1509 /*** Here, if replacement is a vertical combination
1510 and so is its new parent, we should make replacement's
1511 children be children of that parent instead. ***/
1514 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
1515 doc
: /* Remove WINDOW from its frame.
1516 WINDOW defaults to the selected window. Return nil.
1517 Signal an error when WINDOW is the only window on its frame. */)
1519 register Lisp_Object window
;
1523 window
= selected_window
;
1524 f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
1525 delete_window (window
);
1527 run_window_configuration_change_hook (f
);
1533 delete_window (window
)
1534 register Lisp_Object window
;
1536 register Lisp_Object tem
, parent
, sib
;
1537 register struct window
*p
;
1538 register struct window
*par
;
1541 /* Because this function is called by other C code on non-leaf
1542 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1543 so we can't decode_window here. */
1544 CHECK_WINDOW (window
);
1545 p
= XWINDOW (window
);
1547 /* It's a no-op to delete an already-deleted window. */
1548 if (NILP (p
->buffer
)
1550 && NILP (p
->vchild
))
1555 error ("Attempt to delete minibuffer or sole ordinary window");
1556 par
= XWINDOW (parent
);
1558 windows_or_buffers_changed
++;
1559 Vwindow_list
= Qnil
;
1560 f
= XFRAME (WINDOW_FRAME (p
));
1561 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
1563 /* Are we trying to delete any frame's selected window? */
1565 Lisp_Object swindow
, pwindow
;
1567 /* See if the frame's selected window is either WINDOW
1568 or any subwindow of it, by finding all that window's parents
1569 and comparing each one with WINDOW. */
1570 swindow
= FRAME_SELECTED_WINDOW (f
);
1575 while (!NILP (pwindow
))
1577 if (EQ (window
, pwindow
))
1579 pwindow
= XWINDOW (pwindow
)->parent
;
1582 /* If the window being deleted is not a parent of SWINDOW,
1583 then SWINDOW is ok as the new selected window. */
1584 if (!EQ (window
, pwindow
))
1586 /* Otherwise, try another window for SWINDOW. */
1587 swindow
= Fnext_window (swindow
, Qlambda
, Qnil
);
1589 /* If we get back to the frame's selected window,
1590 it means there was no acceptable alternative,
1591 so we cannot delete. */
1592 if (EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1593 error ("Cannot delete window");
1596 /* If we need to change SWINDOW, do it. */
1597 if (! EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1599 /* If we're about to delete the selected window on the
1600 selected frame, then we should use Fselect_window to select
1601 the new window. On the other hand, if we're about to
1602 delete the selected window on any other frame, we shouldn't do
1603 anything but set the frame's selected_window slot. */
1604 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
1605 Fselect_window (swindow
, Qnil
);
1607 FRAME_SELECTED_WINDOW (f
) = swindow
;
1611 /* Now we know we can delete this one. */
1612 window_deletion_count
++;
1615 /* tem is null for dummy parent windows
1616 (which have inferiors but not any contents themselves) */
1620 unchain_marker (XMARKER (p
->pointm
));
1621 unchain_marker (XMARKER (p
->start
));
1624 /* Free window glyph matrices. It is sure that they are allocated
1625 again when ADJUST_GLYPHS is called. Block input so that expose
1626 events and other events that access glyph matrices are not
1627 processed while we are changing them. */
1629 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)));
1633 XWINDOW (tem
)->prev
= p
->prev
;
1637 XWINDOW (tem
)->next
= p
->next
;
1639 if (EQ (window
, par
->hchild
))
1640 par
->hchild
= p
->next
;
1641 if (EQ (window
, par
->vchild
))
1642 par
->vchild
= p
->next
;
1644 /* Find one of our siblings to give our space to. */
1648 /* If p gives its space to its next sibling, that sibling needs
1649 to have its top/left side pulled back to where p's is.
1650 set_window_{height,width} will re-position the sibling's
1653 XWINDOW (sib
)->top_line
= p
->top_line
;
1654 XWINDOW (sib
)->left_col
= p
->left_col
;
1657 /* Stretch that sibling. */
1658 if (!NILP (par
->vchild
))
1659 set_window_height (sib
,
1660 XFASTINT (XWINDOW (sib
)->total_lines
) + XFASTINT (p
->total_lines
),
1662 if (!NILP (par
->hchild
))
1663 set_window_width (sib
,
1664 XFASTINT (XWINDOW (sib
)->total_cols
) + XFASTINT (p
->total_cols
),
1667 /* If parent now has only one child,
1668 put the child into the parent's place. */
1672 if (NILP (XWINDOW (tem
)->next
)) {
1673 replace_window (parent
, tem
);
1674 par
= XWINDOW (tem
);
1677 /* Since we may be deleting combination windows, we must make sure that
1678 not only p but all its children have been marked as deleted. */
1679 if (! NILP (p
->hchild
))
1680 delete_all_subwindows (XWINDOW (p
->hchild
));
1681 else if (! NILP (p
->vchild
))
1682 delete_all_subwindows (XWINDOW (p
->vchild
));
1684 /* Mark this window as deleted. */
1685 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1687 if (! NILP (par
->parent
))
1688 par
= XWINDOW (par
->parent
);
1690 /* Check if we have a v/hchild with a v/hchild. In that case remove
1693 if (! NILP (par
->vchild
) && ! NILP (XWINDOW (par
->vchild
)->vchild
))
1695 p
= XWINDOW (par
->vchild
);
1696 par
->vchild
= p
->vchild
;
1699 else if (! NILP (par
->hchild
) && ! NILP (XWINDOW (par
->hchild
)->hchild
))
1701 p
= XWINDOW (par
->hchild
);
1702 par
->hchild
= p
->hchild
;
1710 while (! NILP (tem
)) {
1711 XWINDOW (tem
)->parent
= p
->parent
;
1712 if (NILP (XWINDOW (tem
)->next
))
1714 tem
= XWINDOW (tem
)->next
;
1717 /* The next of the v/hchild we are removing is now the next of the
1718 last child for the v/hchild:
1719 Before v/hchild -> v/hchild -> next1 -> next2
1722 After: v/hchild -> next1 -> next2 -> next3
1724 XWINDOW (tem
)->next
= p
->next
;
1725 if (! NILP (p
->next
))
1726 XWINDOW (p
->next
)->prev
= tem
;
1728 p
->next
= p
->prev
= p
->vchild
= p
->hchild
= p
->buffer
= Qnil
;
1732 /* Adjust glyph matrices. */
1739 /***********************************************************************
1741 ***********************************************************************/
1743 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1744 pointer. This is a callback function for foreach_window, used in
1745 function window_list. */
1748 add_window_to_list (w
, user_data
)
1752 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1754 XSETWINDOW (window
, w
);
1755 *list
= Fcons (window
, *list
);
1760 /* Return a list of all windows, for use by next_window. If
1761 Vwindow_list is a list, return that list. Otherwise, build a new
1762 list, cache it in Vwindow_list, and return that. */
1767 if (!CONSP (Vwindow_list
))
1771 Vwindow_list
= Qnil
;
1772 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1774 Lisp_Object args
[2];
1776 /* We are visiting windows in canonical order, and add
1777 new windows at the front of args[1], which means we
1778 have to reverse this list at the end. */
1780 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1781 args
[0] = Vwindow_list
;
1782 args
[1] = Fnreverse (args
[1]);
1783 Vwindow_list
= Fnconc (2, args
);
1787 return Vwindow_list
;
1791 /* Value is non-zero if WINDOW satisfies the constraints given by
1792 OWINDOW, MINIBUF and ALL_FRAMES.
1794 MINIBUF t means WINDOW may be minibuffer windows.
1795 `lambda' means WINDOW may not be a minibuffer window.
1796 a window means a specific minibuffer window
1798 ALL_FRAMES t means search all frames,
1799 nil means search just current frame,
1800 `visible' means search just visible frames,
1801 0 means search visible and iconified frames,
1802 a window means search the frame that window belongs to,
1803 a frame means consider windows on that frame, only. */
1806 candidate_window_p (window
, owindow
, minibuf
, all_frames
)
1807 Lisp_Object window
, owindow
, minibuf
, all_frames
;
1809 struct window
*w
= XWINDOW (window
);
1810 struct frame
*f
= XFRAME (w
->frame
);
1811 int candidate_p
= 1;
1813 if (!BUFFERP (w
->buffer
))
1815 else if (MINI_WINDOW_P (w
)
1816 && (EQ (minibuf
, Qlambda
)
1817 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
1819 /* If MINIBUF is `lambda' don't consider any mini-windows.
1820 If it is a window, consider only that one. */
1823 else if (EQ (all_frames
, Qt
))
1825 else if (NILP (all_frames
))
1827 xassert (WINDOWP (owindow
));
1828 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
1830 else if (EQ (all_frames
, Qvisible
))
1832 FRAME_SAMPLE_VISIBILITY (f
);
1833 candidate_p
= FRAME_VISIBLE_P (f
)
1834 && (FRAME_TERMINAL (XFRAME (w
->frame
))
1835 == FRAME_TERMINAL (XFRAME (selected_frame
)));
1838 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
1840 FRAME_SAMPLE_VISIBILITY (f
);
1841 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
1842 #ifdef HAVE_X_WINDOWS
1843 /* Yuck!! If we've just created the frame and the
1844 window-manager requested the user to place it
1845 manually, the window may still not be considered
1846 `visible'. I'd argue it should be at least
1847 something like `iconified', but don't know how to do
1849 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
1850 && !f
->output_data
.x
->has_been_visible
)
1853 && (FRAME_TERMINAL (XFRAME (w
->frame
))
1854 == FRAME_TERMINAL (XFRAME (selected_frame
)));
1856 else if (WINDOWP (all_frames
))
1857 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
1858 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
1859 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
1860 else if (FRAMEP (all_frames
))
1861 candidate_p
= EQ (all_frames
, w
->frame
);
1867 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1868 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1872 decode_next_window_args (window
, minibuf
, all_frames
)
1873 Lisp_Object
*window
, *minibuf
, *all_frames
;
1876 *window
= selected_window
;
1878 CHECK_LIVE_WINDOW (*window
);
1880 /* MINIBUF nil may or may not include minibuffers. Decide if it
1882 if (NILP (*minibuf
))
1883 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
1884 else if (!EQ (*minibuf
, Qt
))
1887 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1888 => count none of them, or a specific minibuffer window (the
1889 active one) to count. */
1891 /* ALL_FRAMES nil doesn't specify which frames to include. */
1892 if (NILP (*all_frames
))
1893 *all_frames
= (!EQ (*minibuf
, Qlambda
)
1894 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
1896 else if (EQ (*all_frames
, Qvisible
))
1898 else if (EQ (*all_frames
, make_number (0)))
1900 else if (FRAMEP (*all_frames
))
1902 else if (!EQ (*all_frames
, Qt
))
1905 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1906 search just current frame, `visible' meaning search just visible
1907 frames, 0 meaning search visible and iconified frames, or a
1908 window, meaning search the frame that window belongs to, or a
1909 frame, meaning consider windows on that frame, only. */
1913 /* Return the next or previous window of WINDOW in cyclic ordering
1914 of windows. NEXT_P non-zero means return the next window. See the
1915 documentation string of next-window for the meaning of MINIBUF and
1919 next_window (window
, minibuf
, all_frames
, next_p
)
1920 Lisp_Object window
, minibuf
, all_frames
;
1923 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1925 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1926 return the first window on the frame. */
1927 if (FRAMEP (all_frames
)
1928 && !EQ (all_frames
, XWINDOW (window
)->frame
))
1929 return Fframe_first_window (all_frames
);
1935 /* Find WINDOW in the list of all windows. */
1936 list
= Fmemq (window
, window_list ());
1938 /* Scan forward from WINDOW to the end of the window list. */
1940 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
1941 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1944 /* Scan from the start of the window list up to WINDOW. */
1946 for (list
= Vwindow_list
;
1947 CONSP (list
) && !EQ (XCAR (list
), window
);
1949 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1953 window
= XCAR (list
);
1957 Lisp_Object candidate
, list
;
1959 /* Scan through the list of windows for candidates. If there are
1960 candidate windows in front of WINDOW, the last one of these
1961 is the one we want. If there are candidates following WINDOW
1962 in the list, again the last one of these is the one we want. */
1964 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
1966 if (EQ (XCAR (list
), window
))
1968 if (WINDOWP (candidate
))
1971 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
1973 candidate
= XCAR (list
);
1976 if (WINDOWP (candidate
))
1984 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
1985 doc
: /* Return window following WINDOW in cyclic ordering of windows.
1986 WINDOW defaults to the selected window. The optional arguments
1987 MINIBUF and ALL-FRAMES specify the set of windows to consider.
1989 MINIBUF t means consider the minibuffer window even if the
1990 minibuffer is not active. MINIBUF nil or omitted means consider
1991 the minibuffer window only if the minibuffer is active. Any
1992 other value means do not consider the minibuffer window even if
1993 the minibuffer is active.
1995 Several frames may share a single minibuffer; if the minibuffer
1996 is active, all windows on all frames that share that minibuffer
1997 are considered too. Therefore, if you are using a separate
1998 minibuffer frame and the minibuffer is active and MINIBUF says it
1999 counts, `next-window' considers the windows in the frame from
2000 which you entered the minibuffer, as well as the minibuffer
2003 ALL-FRAMES nil or omitted means consider all windows on WINDOW's
2004 frame, plus the minibuffer window if specified by the MINIBUF
2005 argument, see above. If the minibuffer counts, consider all
2006 windows on all frames that share that minibuffer too.
2007 ALL-FRAMES t means consider all windows on all existing frames.
2008 ALL-FRAMES `visible' means consider all windows on all visible
2010 ALL-FRAMES 0 means consider all windows on all visible and
2012 ALL-FRAMES a frame means consider all windows on that frame only.
2013 Anything else means consider all windows on WINDOW's frame and no
2016 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2017 `next-window' to iterate through the entire cycle of acceptable
2018 windows, eventually ending up back at the window you started with.
2019 `previous-window' traverses the same cycle, in the reverse order. */)
2020 (window
, minibuf
, all_frames
)
2021 Lisp_Object window
, minibuf
, all_frames
;
2023 return next_window (window
, minibuf
, all_frames
, 1);
2027 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
2028 doc
: /* Return window preceding WINDOW in cyclic ordering of windows.
2029 WINDOW defaults to the selected window. The optional arguments
2030 MINIBUF and ALL-FRAMES specify the set of windows to consider.
2031 For the precise meaning of these arguments see `next-window'.
2033 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2034 use `previous-window' to iterate through the entire cycle of
2035 acceptable windows, eventually ending up back at the window you
2036 started with. `next-window' traverses the same cycle, in the
2038 (window
, minibuf
, all_frames
)
2039 Lisp_Object window
, minibuf
, all_frames
;
2041 return next_window (window
, minibuf
, all_frames
, 0);
2045 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
2046 doc
: /* Select another window in cyclic ordering of windows.
2047 COUNT specifies the number of windows to skip, starting with the
2048 selected window, before making the selection. If COUNT is
2049 positive, skip COUNT windows forwards. If COUNT is negative,
2050 skip -COUNT windows backwards. COUNT zero means do not skip any
2051 window, so select the selected window. In an interactive call,
2052 COUNT is the numeric prefix argument. Return nil.
2054 This function uses `next-window' for finding the window to select.
2055 The argument ALL-FRAMES has the same meaning as in `next-window',
2056 but the MINIBUF argument of `next-window' is always effectively
2059 Lisp_Object count
, all_frames
;
2064 CHECK_NUMBER (count
);
2065 window
= selected_window
;
2067 for (i
= XINT (count
); i
> 0; --i
)
2068 window
= Fnext_window (window
, Qnil
, all_frames
);
2070 window
= Fprevious_window (window
, Qnil
, all_frames
);
2072 Fselect_window (window
, Qnil
);
2077 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2078 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2079 FRAME nil or omitted means use the selected frame.
2080 WINDOW nil or omitted means use the selected window.
2081 MINIBUF t means include the minibuffer window, even if it isn't active.
2082 MINIBUF nil or omitted means include the minibuffer window only
2084 MINIBUF neither nil nor t means never include the minibuffer window. */)
2085 (frame
, minibuf
, window
)
2086 Lisp_Object frame
, minibuf
, window
;
2089 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2090 CHECK_WINDOW (window
);
2092 frame
= selected_frame
;
2094 if (!EQ (frame
, XWINDOW (window
)->frame
))
2095 error ("Window is on a different frame");
2097 return window_list_1 (window
, minibuf
, frame
);
2101 /* Return a list of windows in cyclic ordering. Arguments are like
2102 for `next-window'. */
2105 window_list_1 (window
, minibuf
, all_frames
)
2106 Lisp_Object window
, minibuf
, all_frames
;
2108 Lisp_Object tail
, list
, rest
;
2110 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2113 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2114 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2115 list
= Fcons (XCAR (tail
), list
);
2117 /* Rotate the list to start with WINDOW. */
2118 list
= Fnreverse (list
);
2119 rest
= Fmemq (window
, list
);
2120 if (!NILP (rest
) && !EQ (rest
, list
))
2122 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2124 XSETCDR (tail
, Qnil
);
2125 list
= nconc2 (rest
, list
);
2132 /* Look at all windows, performing an operation specified by TYPE
2134 If FRAMES is Qt, look at all frames;
2135 Qnil, look at just the selected frame;
2136 Qvisible, look at visible frames;
2137 a frame, just look at windows on that frame.
2138 If MINI is non-zero, perform the operation on minibuffer windows too. */
2143 GET_BUFFER_WINDOW
, /* Arg is buffer */
2144 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
2145 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
2146 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
2148 UNSHOW_BUFFER
, /* Arg is buffer */
2149 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2154 window_loop (type
, obj
, mini
, frames
)
2155 enum window_loop type
;
2156 Lisp_Object obj
, frames
;
2159 Lisp_Object window
, windows
, best_window
, frame_arg
;
2161 struct gcpro gcpro1
;
2163 /* If we're only looping through windows on a particular frame,
2164 frame points to that frame. If we're looping through windows
2165 on all frames, frame is 0. */
2166 if (FRAMEP (frames
))
2167 f
= XFRAME (frames
);
2168 else if (NILP (frames
))
2169 f
= SELECTED_FRAME ();
2174 frame_arg
= Qlambda
;
2175 else if (EQ (frames
, make_number (0)))
2177 else if (EQ (frames
, Qvisible
))
2182 /* frame_arg is Qlambda to stick to one frame,
2183 Qvisible to consider all visible frames,
2186 /* Pick a window to start with. */
2190 window
= FRAME_SELECTED_WINDOW (f
);
2192 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2194 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2198 for (; CONSP (windows
); windows
= XCDR (windows
))
2202 window
= XCAR (windows
);
2203 w
= XWINDOW (window
);
2205 /* Note that we do not pay attention here to whether the frame
2206 is visible, since Fwindow_list skips non-visible frames if
2207 that is desired, under the control of frame_arg. */
2208 if (!MINI_WINDOW_P (w
)
2209 /* For UNSHOW_BUFFER, we must always consider all windows. */
2210 || type
== UNSHOW_BUFFER
2211 || (mini
&& minibuf_level
> 0))
2214 case GET_BUFFER_WINDOW
:
2215 if (EQ (w
->buffer
, obj
)
2216 /* Don't find any minibuffer window
2217 except the one that is currently in use. */
2218 && (MINI_WINDOW_P (w
)
2219 ? EQ (window
, minibuf_window
)
2222 if (NILP (best_window
))
2223 best_window
= window
;
2224 else if (EQ (window
, selected_window
))
2225 /* Prefer to return selected-window. */
2226 RETURN_UNGCPRO (window
);
2227 else if (EQ (Fwindow_frame (window
), selected_frame
))
2228 /* Prefer windows on the current frame. */
2229 best_window
= window
;
2233 case GET_LRU_WINDOW
:
2234 /* `obj' is an integer encoding a bitvector.
2235 `obj & 1' means consider only full-width windows.
2236 `obj & 2' means consider also dedicated windows. */
2237 if (((XINT (obj
) & 1) && !WINDOW_FULL_WIDTH_P (w
))
2238 || (!(XINT (obj
) & 2) && !NILP (w
->dedicated
))
2239 /* Minibuffer windows are always ignored. */
2240 || MINI_WINDOW_P (w
))
2242 if (NILP (best_window
)
2243 || (XFASTINT (XWINDOW (best_window
)->use_time
)
2244 > XFASTINT (w
->use_time
)))
2245 best_window
= window
;
2248 case DELETE_OTHER_WINDOWS
:
2249 if (!EQ (window
, obj
))
2250 Fdelete_window (window
);
2253 case DELETE_BUFFER_WINDOWS
:
2254 if (EQ (w
->buffer
, obj
))
2256 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2258 /* If this window is dedicated, and in a frame of its own,
2260 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
2261 && !NILP (w
->dedicated
)
2262 && other_visible_frames (f
))
2264 /* Skip the other windows on this frame.
2265 There might be one, the minibuffer! */
2266 while (CONSP (XCDR (windows
))
2267 && EQ (XWINDOW (XCAR (windows
))->frame
,
2268 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2269 windows
= XCDR (windows
);
2271 /* Now we can safely delete the frame. */
2272 Fdelete_frame (w
->frame
, Qnil
);
2274 else if (NILP (w
->parent
))
2276 /* If we're deleting the buffer displayed in the
2277 only window on the frame, find a new buffer to
2280 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2281 /* Reset dedicated state of window. */
2282 w
->dedicated
= Qnil
;
2283 Fset_window_buffer (window
, buffer
, Qnil
);
2284 if (EQ (window
, selected_window
))
2285 Fset_buffer (w
->buffer
);
2288 Fdelete_window (window
);
2292 case GET_LARGEST_WINDOW
:
2293 { /* nil `obj' means to ignore dedicated windows. */
2294 /* Ignore dedicated windows and minibuffers. */
2295 if (MINI_WINDOW_P (w
) || (NILP (obj
) && !NILP (w
->dedicated
)))
2298 if (NILP (best_window
))
2299 best_window
= window
;
2302 struct window
*b
= XWINDOW (best_window
);
2303 if (XFASTINT (w
->total_lines
) * XFASTINT (w
->total_cols
)
2304 > XFASTINT (b
->total_lines
) * XFASTINT (b
->total_cols
))
2305 best_window
= window
;
2311 if (EQ (w
->buffer
, obj
))
2314 struct frame
*f
= XFRAME (w
->frame
);
2316 /* Find another buffer to show in this window. */
2317 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2319 /* If this window is dedicated, and in a frame of its own,
2321 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
2322 && !NILP (w
->dedicated
)
2323 && other_visible_frames (f
))
2325 /* Skip the other windows on this frame.
2326 There might be one, the minibuffer! */
2327 while (CONSP (XCDR (windows
))
2328 && EQ (XWINDOW (XCAR (windows
))->frame
,
2329 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2330 windows
= XCDR (windows
);
2332 /* Now we can safely delete the frame. */
2333 Fdelete_frame (w
->frame
, Qnil
);
2335 else if (!NILP (w
->dedicated
) && !NILP (w
->parent
))
2338 XSETWINDOW (window
, w
);
2339 /* If this window is dedicated and not the only window
2340 in its frame, then kill it. */
2341 Fdelete_window (window
);
2345 /* Otherwise show a different buffer in the window. */
2346 w
->dedicated
= Qnil
;
2347 Fset_window_buffer (window
, buffer
, Qnil
);
2348 if (EQ (window
, selected_window
))
2349 Fset_buffer (w
->buffer
);
2354 case REDISPLAY_BUFFER_WINDOWS
:
2355 if (EQ (w
->buffer
, obj
))
2357 mark_window_display_accurate (window
, 0);
2358 w
->update_mode_line
= Qt
;
2359 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2360 ++update_mode_lines
;
2361 best_window
= window
;
2365 /* Check for a window that has a killed buffer. */
2366 case CHECK_ALL_WINDOWS
:
2367 if (! NILP (w
->buffer
)
2368 && NILP (XBUFFER (w
->buffer
)->name
))
2372 case WINDOW_LOOP_UNUSED
:
2381 /* Used for debugging. Abort if any window has a dead buffer. */
2384 check_all_windows ()
2386 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2389 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 2, 0,
2390 doc
: /* Return the window least recently selected or used for display.
2391 \(LRU means Least Recently Used.)
2393 Return a full-width window if possible.
2394 A minibuffer window is never a candidate.
2395 A dedicated window is never a candidate, unless DEDICATED is non-nil,
2396 so if all windows are dedicated, the value is nil.
2397 If optional argument FRAME is `visible', search all visible frames.
2398 If FRAME is 0, search all visible and iconified frames.
2399 If FRAME is t, search all frames.
2400 If FRAME is nil, search only the selected frame.
2401 If FRAME is a frame, search only that frame. */)
2403 Lisp_Object frame
, dedicated
;
2405 register Lisp_Object w
;
2406 /* First try for a window that is full-width */
2407 w
= window_loop (GET_LRU_WINDOW
,
2408 NILP (dedicated
) ? make_number (1) : make_number (3),
2410 if (!NILP (w
) && !EQ (w
, selected_window
))
2412 /* If none of them, try the rest */
2413 return window_loop (GET_LRU_WINDOW
,
2414 NILP (dedicated
) ? make_number (0) : make_number (2),
2418 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 2, 0,
2419 doc
: /* Return the largest window in area.
2420 A minibuffer window is never a candidate.
2421 A dedicated window is never a candidate unless DEDICATED is non-nil,
2422 so if all windows are dedicated, the value is nil.
2423 If optional argument FRAME is `visible', search all visible frames.
2424 If FRAME is 0, search all visible and iconified frames.
2425 If FRAME is t, search all frames.
2426 If FRAME is nil, search only the selected frame.
2427 If FRAME is a frame, search only that frame. */)
2429 Lisp_Object frame
, dedicated
;
2431 return window_loop (GET_LARGEST_WINDOW
, dedicated
, 0,
2435 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 0, 2, 0,
2436 doc
: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2437 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to the
2439 If optional argument FRAME is `visible', search all visible frames.
2440 If optional argument FRAME is 0, search all visible and iconified frames.
2441 If FRAME is t, search all frames.
2442 If FRAME is nil, search only the selected frame.
2443 If FRAME is a frame, search only that frame. */)
2444 (buffer_or_name
, frame
)
2445 Lisp_Object buffer_or_name
, frame
;
2449 if (NILP (buffer_or_name
))
2450 buffer
= Fcurrent_buffer ();
2452 buffer
= Fget_buffer (buffer_or_name
);
2454 if (BUFFERP (buffer
))
2455 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
2460 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
2462 doc
: /* Make WINDOW (or the selected window) fill its frame.
2463 Only the frame WINDOW is on is affected.
2464 This function tries to reduce display jumps by keeping the text
2465 previously visible in WINDOW in the same place on the frame. Doing this
2466 depends on the value of (window-start WINDOW), so if calling this
2467 function in a program gives strange scrolling, make sure the
2468 window-start value is reasonable when this function is called. */)
2477 window
= selected_window
;
2479 CHECK_LIVE_WINDOW (window
);
2480 w
= XWINDOW (window
);
2482 startpos
= marker_position (w
->start
);
2483 top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2485 if (MINI_WINDOW_P (w
) && top
> 0)
2486 error ("Can't expand minibuffer to full frame");
2488 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
2490 /* Try to minimize scrolling, by setting the window start to the point
2491 will cause the text at the old window start to be at the same place
2492 on the frame. But don't try to do this if the window start is
2493 outside the visible portion (as might happen when the display is
2494 not current, due to typeahead). */
2495 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2497 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2498 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2500 struct position pos
;
2501 struct buffer
*obuf
= current_buffer
;
2503 Fset_buffer (w
->buffer
);
2504 /* This computation used to temporarily move point, but that can
2505 have unwanted side effects due to text properties. */
2506 pos
= *vmotion (startpos
, -top
, w
);
2508 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2509 w
->window_end_valid
= Qnil
;
2510 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
2511 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
2513 /* We need to do this, so that the window-scroll-functions
2515 w
->optional_new_start
= Qt
;
2517 set_buffer_internal (obuf
);
2523 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
2524 0, 2, "bDelete windows on (buffer): ",
2525 doc
: /* Delete all windows showing BUFFER-OR-NAME.
2526 BUFFER-OR-NAME may be a buffer or the name of an existing buffer and
2527 defaults to the current buffer.
2529 Optional second argument FRAME controls which frames are affected.
2530 If optional argument FRAME is `visible', search all visible frames.
2531 If FRAME is 0, search all visible and iconified frames.
2532 If FRAME is nil, search all frames.
2533 If FRAME is t, search only the selected frame.
2534 If FRAME is a frame, search only that frame.
2535 When a window showing BUFFER-OR-NAME is dedicated and the only window of
2536 its frame, that frame is deleted when there are other frames left. */)
2537 (buffer_or_name
, frame
)
2538 Lisp_Object buffer_or_name
, frame
;
2542 /* FRAME uses t and nil to mean the opposite of what window_loop
2546 else if (EQ (frame
, Qt
))
2549 if (NILP (buffer_or_name
))
2550 buffer
= Fcurrent_buffer ();
2553 buffer
= Fget_buffer (buffer_or_name
);
2554 CHECK_BUFFER (buffer
);
2557 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
2562 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
2563 Sreplace_buffer_in_windows
,
2564 0, 1, "bReplace buffer in windows: ",
2565 doc
: /* Replace BUFFER-OR-NAME with some other buffer in all windows showing it.
2566 BUFFER-OR-NAME may be a buffer or the name of an existing buffer and
2567 defaults to the current buffer.
2569 When a window showing BUFFER-OR-NAME is dedicated that window is
2570 deleted. If that window is the only window on its frame, that frame is
2571 deleted too when there are other frames left. If there are no other
2572 frames left, some other buffer is displayed in that window. */)
2574 Lisp_Object buffer_or_name
;
2578 if (NILP (buffer_or_name
))
2579 buffer
= Fcurrent_buffer ();
2582 buffer
= Fget_buffer (buffer_or_name
);
2583 CHECK_BUFFER (buffer
);
2586 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
2591 /* Replace BUFFER with some other buffer in all windows
2592 of all frames, even those on other keyboards. */
2595 replace_buffer_in_all_windows (buffer
)
2598 Lisp_Object tail
, frame
;
2600 /* A single call to window_loop won't do the job
2601 because it only considers frames on the current keyboard.
2602 So loop manually over frames, and handle each one. */
2603 FOR_EACH_FRAME (tail
, frame
)
2604 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
2607 /* Set the height of WINDOW and all its inferiors. */
2609 /* The smallest acceptable dimensions for a window. Anything smaller
2610 might crash Emacs. */
2612 #define MIN_SAFE_WINDOW_WIDTH (2)
2613 #define MIN_SAFE_WINDOW_HEIGHT (1)
2615 /* For wp non-zero the total number of columns of window w. Otherwise
2616 the total number of lines of w. */
2618 #define WINDOW_TOTAL_SIZE(w, wp) \
2619 (wp ? WINDOW_TOTAL_COLS (w) : WINDOW_TOTAL_LINES (w))
2621 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2622 minimum allowable size. */
2625 check_frame_size (frame
, rows
, cols
)
2629 /* For height, we have to see:
2630 how many windows the frame has at minimum (one or two),
2631 and whether it has a menu bar or other special stuff at the top. */
2633 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
2634 ? MIN_SAFE_WINDOW_HEIGHT
2635 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
2637 if (FRAME_TOP_MARGIN (frame
) > 0)
2638 min_height
+= FRAME_TOP_MARGIN (frame
);
2640 if (*rows
< min_height
)
2642 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2643 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2646 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2647 check if W's width can be changed, otherwise check W's height.
2648 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2649 siblings, too. If none of the siblings is resizable, WINDOW isn't
2653 window_fixed_size_p (w
, width_p
, check_siblings_p
)
2655 int width_p
, check_siblings_p
;
2660 if (!NILP (w
->hchild
))
2662 c
= XWINDOW (w
->hchild
);
2666 /* A horizontal combination is fixed-width if all of if its
2668 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2669 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2670 fixed_p
= c
== NULL
;
2674 /* A horizontal combination is fixed-height if one of if its
2676 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2677 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2678 fixed_p
= c
!= NULL
;
2681 else if (!NILP (w
->vchild
))
2683 c
= XWINDOW (w
->vchild
);
2687 /* A vertical combination is fixed-width if one of if its
2689 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2690 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2691 fixed_p
= c
!= NULL
;
2695 /* A vertical combination is fixed-height if all of if its
2697 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2698 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2699 fixed_p
= c
== NULL
;
2702 else if (BUFFERP (w
->buffer
))
2704 struct buffer
*old
= current_buffer
;
2707 current_buffer
= XBUFFER (w
->buffer
);
2708 val
= find_symbol_value (Qwindow_size_fixed
);
2709 current_buffer
= old
;
2712 if (!EQ (val
, Qunbound
))
2714 fixed_p
= !NILP (val
);
2717 && ((EQ (val
, Qheight
) && width_p
)
2718 || (EQ (val
, Qwidth
) && !width_p
)))
2722 /* Can't tell if this one is resizable without looking at
2723 siblings. If all siblings are fixed-size this one is too. */
2724 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
2728 for (child
= w
->prev
; WINDOWP (child
); child
= XWINDOW (child
)->prev
)
2729 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2733 for (child
= w
->next
; WINDOWP (child
); child
= XWINDOW (child
)->next
)
2734 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2747 /* Return minimum size of leaf window W. WIDTH_P non-zero means return
2748 the minimum width of W, WIDTH_P zero means return the minimum height
2749 of W. SAFE_P non-zero means ignore window-min-height|width but just
2750 return values that won't crash Emacs and don't hide components like
2751 fringes, scrollbars, or modelines. If WIDTH_P is zero and W is the
2752 minibuffer window, always return 1. */
2755 window_min_size_2 (w
, width_p
, safe_p
)
2757 int width_p
, safe_p
;
2759 /* We should consider buffer-local values of window_min_height and
2760 window_min_width here. */
2763 int safe_size
= (MIN_SAFE_WINDOW_WIDTH
2764 + WINDOW_FRINGE_COLS (w
)
2765 + WINDOW_SCROLL_BAR_COLS (w
));
2767 return safe_p
? safe_size
: max (window_min_width
, safe_size
);
2769 else if (MINI_WINDOW_P (w
))
2773 int safe_size
= (MIN_SAFE_WINDOW_HEIGHT
2774 + ((BUFFERP (w
->buffer
)
2775 && !NILP (XBUFFER (w
->buffer
)->mode_line_format
))
2778 return safe_p
? safe_size
: max (window_min_height
, safe_size
);
2782 /* Return minimum size of window W, not taking fixed-width windows into
2783 account. WIDTH_P non-zero means return the minimum width, otherwise
2784 return the minimum height. SAFE_P non-zero means ignore
2785 window-min-height|width but just return values that won't crash Emacs
2786 and don't hide components like fringes, scrollbars, or modelines. If
2787 W is a combination window, compute the minimum size from the minimum
2788 sizes of W's children. */
2791 window_min_size_1 (w
, width_p
, safe_p
)
2793 int width_p
, safe_p
;
2798 if (!NILP (w
->hchild
))
2800 /* W is a horizontal combination. */
2801 c
= XWINDOW (w
->hchild
);
2806 /* The minimum width of a horizontal combination is the sum of
2807 the minimum widths of its children. */
2810 size
+= window_min_size_1 (c
, 1, safe_p
);
2811 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2816 /* The minimum height of a horizontal combination is the
2817 maximum of the minimum heights of its children. */
2820 size
= max (window_min_size_1 (c
, 0, safe_p
), size
);
2821 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2825 else if (!NILP (w
->vchild
))
2827 /* W is a vertical combination. */
2828 c
= XWINDOW (w
->vchild
);
2833 /* The minimum width of a vertical combination is the maximum
2834 of the minimum widths of its children. */
2837 size
= max (window_min_size_1 (c
, 1, safe_p
), size
);
2838 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2843 /* The minimum height of a vertical combination is the sum of
2844 the minimum height of its children. */
2847 size
+= window_min_size_1 (c
, 0, safe_p
);
2848 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2853 /* W is a leaf window. */
2854 size
= window_min_size_2 (w
, width_p
, safe_p
);
2859 /* Return the minimum size of window W, taking fixed-size windows into
2860 account. WIDTH_P non-zero means return the minimum width, otherwise
2861 return the minimum height. SAFE_P non-zero means ignore
2862 window-min-height|width but just return values that won't crash Emacs
2863 and don't hide components like fringes, scrollbars, or modelines.
2864 IGNORE_FIXED_P non-zero means ignore if W is fixed-size. Set *FIXED
2865 to 1 if W is fixed-size unless FIXED is null. */
2868 window_min_size (w
, width_p
, safe_p
, ignore_fixed_p
, fixed
)
2870 int width_p
, safe_p
, ignore_fixed_p
, *fixed
;
2877 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
2883 size
= WINDOW_TOTAL_SIZE (w
, width_p
);
2885 size
= window_min_size_1 (w
, width_p
, safe_p
);
2891 /* Adjust the margins of window W if text area is too small.
2892 Return 1 if window width is ok after adjustment; 0 if window
2893 is still too narrow. */
2896 adjust_window_margins (w
)
2899 int box_cols
= (WINDOW_TOTAL_COLS (w
)
2900 - WINDOW_FRINGE_COLS (w
)
2901 - WINDOW_SCROLL_BAR_COLS (w
));
2902 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
2903 + WINDOW_RIGHT_MARGIN_COLS (w
));
2905 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
2908 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
2911 /* Window's text area is too narrow, but reducing the window
2912 margins will fix that. */
2913 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
2914 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
2916 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
2917 w
->left_margin_cols
= w
->right_margin_cols
2918 = make_number (margin_cols
/2);
2920 w
->right_margin_cols
= make_number (margin_cols
);
2923 w
->left_margin_cols
= make_number (margin_cols
);
2927 /* Calculate new sizes for windows in the list FORWARD when their
2928 compound size goes from TOTAL to SIZE. TOTAL must be greater than
2929 SIZE. The number of windows in FORWARD is NCHILDREN, and the number
2930 that can shrink is SHRINKABLE. Fixed-size windows may be shrunk if
2931 and only if RESIZE_FIXED_P is non-zero. WIDTH_P non-zero means
2932 shrink columns, otherwise shrink lines.
2934 SAFE_P zero means windows may be sized down to window-min-height
2935 lines (window-min-window columns for WIDTH_P non-zero). SAFE_P
2936 non-zero means windows may be sized down to their minimum safe sizes
2937 taking into account the space needed to display modelines, fringes,
2940 This function returns an allocated array of new sizes that the caller
2941 must free. A size -1 means the window is fixed and RESIZE_FIXED_P is
2942 zero. A size zero means the window shall be deleted. Array index 0
2943 refers to the first window in FORWARD, 1 to the second, and so on.
2945 This function resizes windows proportionally to their size. It also
2946 tries to preserve smaller windows by resizing larger windows before
2947 resizing any window to zero. If resize_proportionally is non-nil for
2948 a specific window, it will attempt to strictly resize that window
2949 proportionally, even at the expense of deleting smaller windows. */
2951 shrink_windows (total
, size
, nchildren
, shrinkable
, resize_fixed_p
,
2952 forward
, width_p
, safe_p
)
2953 int total
, size
, nchildren
, shrinkable
;
2954 int resize_fixed_p
, width_p
, safe_p
;
2955 Lisp_Object forward
;
2957 int available_resize
= 0;
2958 int *new_sizes
, *min_sizes
;
2961 int smallest
= total
;
2962 int total_removed
= 0;
2963 int total_shrink
= total
- size
;
2966 new_sizes
= xmalloc (sizeof (*new_sizes
) * nchildren
);
2967 min_sizes
= xmalloc (sizeof (*min_sizes
) * nchildren
);
2969 for (i
= 0, child
= forward
; !NILP (child
); child
= c
->next
, ++i
)
2973 c
= XWINDOW (child
);
2974 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
2976 if (!resize_fixed_p
&& window_fixed_size_p (c
, width_p
, 0))
2980 new_sizes
[i
] = child_size
;
2981 min_sizes
[i
] = window_min_size_1 (c
, width_p
, safe_p
);
2982 if (child_size
> min_sizes
[i
]
2983 && NILP (c
->resize_proportionally
))
2984 available_resize
+= child_size
- min_sizes
[i
];
2987 /* We might need to shrink some windows to zero. Find the smallest
2988 windows and set them to 0 until we can fulfil the new size. */
2990 while (shrinkable
> 1 && size
+ available_resize
< total
)
2992 for (i
= 0; i
< nchildren
; ++i
)
2993 if (new_sizes
[i
] > 0 && smallest
> new_sizes
[i
])
2994 smallest
= new_sizes
[i
];
2996 for (i
= 0; i
< nchildren
; ++i
)
2997 if (new_sizes
[i
] == smallest
)
2999 /* Resize this window down to zero. */
3001 if (smallest
> min_sizes
[i
])
3002 available_resize
-= smallest
- min_sizes
[i
];
3003 available_resize
+= smallest
;
3005 total_removed
+= smallest
;
3007 /* We don't know what the smallest is now. */
3010 /* Out of for, just remove one window at the time and
3011 check again if we have enough space. */
3016 /* Now, calculate the new sizes. Try to shrink each window
3017 proportional to its size. */
3018 for (i
= 0; i
< nchildren
; ++i
)
3020 if (new_sizes
[i
] > min_sizes
[i
])
3022 int to_shrink
= total_shrink
* new_sizes
[i
] / total
;
3024 if (new_sizes
[i
] - to_shrink
< min_sizes
[i
])
3025 to_shrink
= new_sizes
[i
] - min_sizes
[i
];
3026 new_sizes
[i
] -= to_shrink
;
3027 total_removed
+= to_shrink
;
3031 /* Any reminder due to rounding, we just subtract from windows
3032 that are left and still can be shrunk. */
3033 while (total_shrink
> total_removed
)
3035 int nonzero_sizes
= 0;
3036 int nonzero_idx
= -1;
3038 for (i
= 0; i
< nchildren
; ++i
)
3039 if (new_sizes
[i
] > 0)
3045 for (i
= 0; i
< nchildren
; ++i
)
3046 if (new_sizes
[i
] > min_sizes
[i
])
3051 /* Out of for, just shrink one window at the time and
3052 check again if we have enough space. */
3056 /* Special case, only one window left. */
3057 if (nonzero_sizes
== 1)
3061 /* Any surplus due to rounding, we add to windows that are left. */
3062 while (total_shrink
< total_removed
)
3064 for (i
= 0; i
< nchildren
; ++i
)
3066 if (new_sizes
[i
] != 0 && total_shrink
< total_removed
)
3080 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
3081 WINDOW's width. Resize WINDOW's children, if any, so that they keep
3082 their proportionate size relative to WINDOW.
3084 If FIRST_ONLY is 1, change only the first of WINDOW's children when
3085 they are in series. If LAST_ONLY is 1, change only the last of
3086 WINDOW's children when they are in series.
3088 Propagate WINDOW's top or left edge position to children. Delete
3089 windows that become too small unless NODELETE_P is 1. When
3090 NODELETE_P equals 2 do not honor settings for window-min-height and
3091 window-min-width when resizing windows but use safe defaults instead.
3092 This should give better behavior when resizing frames. */
3095 size_window (window
, size
, width_p
, nodelete_p
, first_only
, last_only
)
3097 int size
, width_p
, nodelete_p
;
3098 int first_only
, last_only
;
3100 struct window
*w
= XWINDOW (window
);
3102 Lisp_Object child
, *forward
, *sideward
;
3103 int old_size
= WINDOW_TOTAL_SIZE (w
, width_p
);
3105 size
= max (0, size
);
3107 /* Delete WINDOW if it's too small. */
3108 if (nodelete_p
!= 1 && !NILP (w
->parent
)
3109 && size
< window_min_size_1 (w
, width_p
, nodelete_p
== 2))
3111 delete_window (window
);
3115 /* Set redisplay hints. */
3116 w
->last_modified
= make_number (0);
3117 w
->last_overlay_modified
= make_number (0);
3118 windows_or_buffers_changed
++;
3119 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w
->frame
)) = 1;
3123 sideward
= &w
->vchild
;
3124 forward
= &w
->hchild
;
3125 w
->total_cols
= make_number (size
);
3126 adjust_window_margins (w
);
3130 sideward
= &w
->hchild
;
3131 forward
= &w
->vchild
;
3132 w
->total_lines
= make_number (size
);
3133 w
->orig_total_lines
= Qnil
;
3136 if (!NILP (*sideward
))
3138 /* We have a chain of parallel siblings whose size should all change. */
3139 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
3141 c
= XWINDOW (child
);
3143 c
->left_col
= w
->left_col
;
3145 c
->top_line
= w
->top_line
;
3146 size_window (child
, size
, width_p
, nodelete_p
,
3147 first_only
, last_only
);
3150 else if (!NILP (*forward
) && last_only
)
3152 /* Change the last in a series of siblings. */
3153 Lisp_Object last_child
;
3156 for (child
= *forward
; !NILP (child
); child
= c
->next
)
3158 c
= XWINDOW (child
);
3162 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3163 size_window (last_child
, size
- old_size
+ child_size
,
3164 width_p
, nodelete_p
, first_only
, last_only
);
3166 else if (!NILP (*forward
) && first_only
)
3168 /* Change the first in a series of siblings. */
3172 c
= XWINDOW (child
);
3175 c
->left_col
= w
->left_col
;
3177 c
->top_line
= w
->top_line
;
3179 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3180 size_window (child
, size
- old_size
+ child_size
,
3181 width_p
, nodelete_p
, first_only
, last_only
);
3183 else if (!NILP (*forward
))
3185 int fixed_size
, each
, extra
, n
;
3186 int resize_fixed_p
, nfixed
;
3187 int last_pos
, first_pos
, nchildren
, total
;
3188 int *new_sizes
= NULL
;
3190 /* Determine the fixed-size portion of this window, and the
3191 number of child windows. */
3192 fixed_size
= nchildren
= nfixed
= total
= 0;
3193 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
3197 c
= XWINDOW (child
);
3198 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3199 total
+= child_size
;
3201 if (window_fixed_size_p (c
, width_p
, 0))
3203 fixed_size
+= child_size
;
3208 /* If the new size is smaller than fixed_size, or if there
3209 aren't any resizable windows, allow resizing fixed-size
3211 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
3213 /* Compute how many lines/columns to add/remove to each child. The
3214 value of extra takes care of rounding errors. */
3215 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
3216 if (size
< total
&& n
> 1)
3217 new_sizes
= shrink_windows (total
, size
, nchildren
, n
,
3218 resize_fixed_p
, *forward
, width_p
,
3222 each
= (size
- total
) / n
;
3223 extra
= (size
- total
) - n
* each
;
3226 /* Compute new children heights and edge positions. */
3227 first_pos
= width_p
? XINT (w
->left_col
) : XINT (w
->top_line
);
3228 last_pos
= first_pos
;
3229 for (n
= 0, child
= *forward
; !NILP (child
); child
= c
->next
, ++n
)
3231 int new_size
, old_size
;
3233 c
= XWINDOW (child
);
3234 old_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3235 new_size
= old_size
;
3237 /* The top or left edge position of this child equals the
3238 bottom or right edge of its predecessor. */
3240 c
->left_col
= make_number (last_pos
);
3242 c
->top_line
= make_number (last_pos
);
3244 /* If this child can be resized, do it. */
3245 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
3247 new_size
= new_sizes
? new_sizes
[n
] : old_size
+ each
+ extra
;
3251 /* Set new size. Note that size_window also propagates
3252 edge positions to children, so it's not a no-op if we
3253 didn't change the child's size. */
3254 size_window (child
, new_size
, width_p
, 1, first_only
, last_only
);
3256 /* Remember the bottom/right edge position of this child; it
3257 will be used to set the top/left edge of the next child. */
3258 last_pos
+= new_size
;
3263 /* We should have covered the parent exactly with child windows. */
3264 xassert (size
== last_pos
- first_pos
);
3266 /* Now delete any children that became too small. */
3267 if (nodelete_p
!= 1)
3268 for (child
= *forward
; !NILP (child
); child
= c
->next
)
3272 c
= XWINDOW (child
);
3273 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3274 size_window (child
, child_size
, width_p
, nodelete_p
,
3275 first_only
, last_only
);
3280 /* Set WINDOW's height to HEIGHT, and recursively change the height of
3281 WINDOW's children. NODELETE zero means windows that have become
3282 smaller than window-min-height in the process may be deleted.
3283 NODELETE 1 means never delete windows that become too small in the
3284 process. (The caller should check later and do so if appropriate.)
3285 NODELETE 2 means delete only windows that have become too small to be
3286 displayed correctly. */
3289 set_window_height (window
, height
, nodelete
)
3294 size_window (window
, height
, 0, nodelete
, 0, 0);
3297 /* Set WINDOW's width to WIDTH, and recursively change the width of
3298 WINDOW's children. NODELETE zero means windows that have become
3299 smaller than window-min-width in the process may be deleted.
3300 NODELETE 1 means never delete windows that become too small in the
3301 process. (The caller should check later and do so if appropriate.)
3302 NODELETE 2 means delete only windows that have become too small to be
3303 displayed correctly. */
3306 set_window_width (window
, width
, nodelete
)
3311 size_window (window
, width
, 1, nodelete
, 0, 0);
3314 /* Change window heights in windows rooted in WINDOW by N lines. */
3317 change_window_heights (window
, n
)
3321 struct window
*w
= XWINDOW (window
);
3323 XSETFASTINT (w
->top_line
, XFASTINT (w
->top_line
) + n
);
3324 XSETFASTINT (w
->total_lines
, XFASTINT (w
->total_lines
) - n
);
3326 if (INTEGERP (w
->orig_top_line
))
3327 XSETFASTINT (w
->orig_top_line
, XFASTINT (w
->orig_top_line
) + n
);
3328 if (INTEGERP (w
->orig_total_lines
))
3329 XSETFASTINT (w
->orig_total_lines
, XFASTINT (w
->orig_total_lines
) - n
);
3331 /* Handle just the top child in a vertical split. */
3332 if (!NILP (w
->vchild
))
3333 change_window_heights (w
->vchild
, n
);
3335 /* Adjust all children in a horizontal split. */
3336 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
3338 w
= XWINDOW (window
);
3339 change_window_heights (window
, n
);
3344 int window_select_count
;
3346 EXFUN (Fset_window_fringes
, 4);
3347 EXFUN (Fset_window_scroll_bars
, 4);
3350 run_funs (Lisp_Object funs
)
3352 for (; CONSP (funs
); funs
= XCDR (funs
))
3353 if (!EQ (XCAR (funs
), Qt
))
3354 call0 (XCAR (funs
));
3357 static Lisp_Object
select_window_norecord (Lisp_Object window
);
3358 static Lisp_Object
select_frame_norecord (Lisp_Object frame
);
3361 run_window_configuration_change_hook (struct frame
*f
)
3363 int count
= SPECPDL_INDEX ();
3364 Lisp_Object frame
, global_wcch
3365 = Fdefault_value (Qwindow_configuration_change_hook
);
3366 XSETFRAME (frame
, f
);
3368 if (NILP (Vrun_hooks
))
3371 if (SELECTED_FRAME () != f
)
3373 record_unwind_protect (select_frame_norecord
, Fselected_frame ());
3374 Fselect_frame (frame
, Qt
);
3377 /* Use the right buffer. Matters when running the local hooks. */
3378 if (current_buffer
!= XBUFFER (Fwindow_buffer (Qnil
)))
3380 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
3381 Fset_buffer (Fwindow_buffer (Qnil
));
3384 /* Look for buffer-local values. */
3386 Lisp_Object windows
= Fwindow_list (frame
, Qlambda
, Qnil
);
3387 for (; CONSP (windows
); windows
= XCDR (windows
))
3389 Lisp_Object window
= XCAR (windows
);
3390 Lisp_Object buffer
= Fwindow_buffer (window
);
3391 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook
,
3394 int count
= SPECPDL_INDEX ();
3395 record_unwind_protect (select_window_norecord
, Fselected_window ());
3396 select_window_norecord (window
);
3397 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook
,
3399 unbind_to (count
, Qnil
);
3404 run_funs (global_wcch
);
3405 unbind_to (count
, Qnil
);
3408 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
3409 means it's allowed to run hooks. See make_frame for a case where
3410 it's not allowed. KEEP_MARGINS_P non-zero means that the current
3411 margins, fringes, and scroll-bar settings of the window are not
3412 reset from the buffer's local settings. */
3415 set_window_buffer (window
, buffer
, run_hooks_p
, keep_margins_p
)
3416 Lisp_Object window
, buffer
;
3417 int run_hooks_p
, keep_margins_p
;
3419 struct window
*w
= XWINDOW (window
);
3420 struct buffer
*b
= XBUFFER (buffer
);
3421 int count
= SPECPDL_INDEX ();
3422 int samebuf
= EQ (buffer
, w
->buffer
);
3426 if (EQ (window
, selected_window
))
3427 b
->last_selected_window
= window
;
3429 /* Let redisplay errors through. */
3430 b
->display_error_modiff
= 0;
3432 /* Update time stamps of buffer display. */
3433 if (INTEGERP (b
->display_count
))
3434 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
3435 b
->display_time
= Fcurrent_time ();
3437 XSETFASTINT (w
->window_end_pos
, 0);
3438 XSETFASTINT (w
->window_end_vpos
, 0);
3439 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
3440 w
->window_end_valid
= Qnil
;
3441 if (!(keep_margins_p
&& samebuf
))
3442 { /* If we're not actually changing the buffer, don't reset hscroll and
3443 vscroll. This case happens for example when called from
3444 change_frame_size_1, where we use a dummy call to
3445 Fset_window_buffer on the frame's selected window (and no other)
3446 just in order to run window-configuration-change-hook.
3447 Resetting hscroll and vscroll here is problematic for things like
3448 image-mode and doc-view-mode since it resets the image's position
3449 whenever we resize the frame. */
3450 w
->hscroll
= w
->min_hscroll
= make_number (0);
3452 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3453 set_marker_restricted (w
->start
,
3454 make_number (b
->last_window_start
),
3456 w
->start_at_line_beg
= Qnil
;
3457 w
->force_start
= Qnil
;
3458 XSETFASTINT (w
->last_modified
, 0);
3459 XSETFASTINT (w
->last_overlay_modified
, 0);
3461 /* Maybe we could move this into the `if' but it's not obviously safe and
3462 I doubt it's worth the trouble. */
3463 windows_or_buffers_changed
++;
3465 /* We must select BUFFER for running the window-scroll-functions. */
3466 /* We can't check ! NILP (Vwindow_scroll_functions) here
3467 because that might itself be a local variable. */
3468 if (window_initialized
)
3470 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
3471 Fset_buffer (buffer
);
3474 XMARKER (w
->pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3476 if (!keep_margins_p
)
3478 /* Set left and right marginal area width etc. from buffer. */
3480 /* This may call adjust_window_margins three times, so
3481 temporarily disable window margins. */
3482 Lisp_Object save_left
= w
->left_margin_cols
;
3483 Lisp_Object save_right
= w
->right_margin_cols
;
3485 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
3487 Fset_window_fringes (window
,
3488 b
->left_fringe_width
, b
->right_fringe_width
,
3489 b
->fringes_outside_margins
);
3491 Fset_window_scroll_bars (window
,
3492 b
->scroll_bar_width
,
3493 b
->vertical_scroll_bar_type
, Qnil
);
3495 w
->left_margin_cols
= save_left
;
3496 w
->right_margin_cols
= save_right
;
3498 Fset_window_margins (window
,
3499 b
->left_margin_cols
, b
->right_margin_cols
);
3504 if (! NILP (Vwindow_scroll_functions
))
3505 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3506 Fmarker_position (w
->start
));
3507 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w
)));
3510 unbind_to (count
, Qnil
);
3514 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3515 doc
: /* Make WINDOW display BUFFER-OR-NAME as its contents.
3516 WINDOW defaults to the selected window. BUFFER-OR-NAME must be a buffer
3517 or the name of an existing buffer. Optional third argument KEEP-MARGINS
3518 non-nil means that WINDOW's current display margins, fringe widths, and
3519 scroll bar settings are preserved; the default is to reset these from
3520 the local settings for BUFFER-OR-NAME or the frame defaults. Return nil.
3522 This function throws an error when WINDOW is strongly dedicated to its
3523 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3524 already display BUFFER-OR-NAME.
3526 This function runs `window-scroll-functions' before running
3527 `window-configuration-change-hook'. */)
3528 (window
, buffer_or_name
, keep_margins
)
3529 register Lisp_Object window
, buffer_or_name
, keep_margins
;
3531 register Lisp_Object tem
, buffer
;
3532 register struct window
*w
= decode_window (window
);
3534 XSETWINDOW (window
, w
);
3535 buffer
= Fget_buffer (buffer_or_name
);
3536 CHECK_BUFFER (buffer
);
3537 if (NILP (XBUFFER (buffer
)->name
))
3538 error ("Attempt to display deleted buffer");
3542 error ("Window is deleted");
3543 else if (!EQ (tem
, Qt
))
3544 /* w->buffer is t when the window is first being set up. */
3546 if (!EQ (tem
, buffer
))
3547 if (EQ (w
->dedicated
, Qt
))
3548 error ("Window is dedicated to `%s'", SDATA (XBUFFER (tem
)->name
));
3550 w
->dedicated
= Qnil
;
3555 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3559 /* Note that selected_window can be nil when this is called from
3560 Fset_window_configuration. */
3562 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
3563 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
3564 If WINDOW is not already selected, make WINDOW's buffer current
3565 and make WINDOW the frame's selected window. Return WINDOW.
3566 Optional second arg NORECORD non-nil means do not put this buffer
3567 at the front of the list of recently selected ones and do not
3568 make this window the most recently selected one.
3570 Note that the main editor command loop selects the buffer of the
3571 selected window before each command. */)
3573 register Lisp_Object window
, norecord
;
3575 register struct window
*w
;
3576 register struct window
*ow
;
3579 CHECK_LIVE_WINDOW (window
);
3581 w
= XWINDOW (window
);
3582 w
->frozen_window_start_p
= 0;
3584 if (NILP (norecord
))
3586 ++window_select_count
;
3587 XSETFASTINT (w
->use_time
, window_select_count
);
3590 if (EQ (window
, selected_window
))
3593 sf
= SELECTED_FRAME ();
3594 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
3596 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
3597 /* Use this rather than Fhandle_switch_frame
3598 so that FRAME_FOCUS_FRAME is moved appropriately as we
3599 move around in the state where a minibuffer in a separate
3601 Fselect_frame (WINDOW_FRAME (w
), norecord
);
3602 /* Fselect_frame called us back so we've done all the work already. */
3603 eassert (EQ (window
, selected_window
));
3607 sf
->selected_window
= window
;
3609 /* Store the current buffer's actual point into the
3610 old selected window. It belongs to that window,
3611 and when the window is not selected, must be in the window. */
3612 if (!NILP (selected_window
))
3614 ow
= XWINDOW (selected_window
);
3615 if (! NILP (ow
->buffer
))
3616 set_marker_both (ow
->pointm
, ow
->buffer
,
3617 BUF_PT (XBUFFER (ow
->buffer
)),
3618 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
3621 selected_window
= window
;
3623 if (NILP (norecord
))
3624 record_buffer (w
->buffer
);
3625 Fset_buffer (w
->buffer
);
3627 XBUFFER (w
->buffer
)->last_selected_window
= window
;
3629 /* Go to the point recorded in the window.
3630 This is important when the buffer is in more
3631 than one window. It also matters when
3632 redisplay_window has altered point after scrolling,
3633 because it makes the change only in the window. */
3635 register int new_point
= marker_position (w
->pointm
);
3636 if (new_point
< BEGV
)
3638 else if (new_point
> ZV
)
3644 windows_or_buffers_changed
++;
3649 select_window_norecord (window
)
3652 return WINDOW_LIVE_P (window
)
3653 ? Fselect_window (window
, Qt
) : selected_window
;
3657 select_frame_norecord (frame
)
3660 return FRAME_LIVE_P (XFRAME (frame
))
3661 ? Fselect_frame (frame
, Qt
) : selected_frame
;
3665 display_buffer (buffer
, not_this_window_p
, override_frame
)
3666 Lisp_Object buffer
, not_this_window_p
, override_frame
;
3668 return call3 (Qdisplay_buffer
, buffer
, not_this_window_p
, override_frame
);
3671 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3673 doc
: /* Force all windows to be updated on next redisplay.
3674 If optional arg OBJECT is a window, force redisplay of that window only.
3675 If OBJECT is a buffer or buffer name, force redisplay of all windows
3676 displaying that buffer. */)
3682 windows_or_buffers_changed
++;
3683 update_mode_lines
++;
3687 if (WINDOWP (object
))
3689 struct window
*w
= XWINDOW (object
);
3690 mark_window_display_accurate (object
, 0);
3691 w
->update_mode_line
= Qt
;
3692 if (BUFFERP (w
->buffer
))
3693 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
3694 ++update_mode_lines
;
3698 if (STRINGP (object
))
3699 object
= Fget_buffer (object
);
3700 if (BUFFERP (object
) && !NILP (XBUFFER (object
)->name
))
3702 /* Walk all windows looking for buffer, and force update
3703 of each of those windows. */
3705 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3706 return NILP (object
) ? Qnil
: Qt
;
3709 /* If nothing suitable was found, just return.
3710 We could signal an error, but this feature will typically be used
3711 asynchronously in timers or process sentinels, so we don't. */
3717 temp_output_buffer_show (buf
)
3718 register Lisp_Object buf
;
3720 register struct buffer
*old
= current_buffer
;
3721 register Lisp_Object window
;
3722 register struct window
*w
;
3724 XBUFFER (buf
)->directory
= current_buffer
->directory
;
3727 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3731 #if 0 /* rms: there should be no reason for this. */
3732 XBUFFER (buf
)->prevent_redisplay_optimizations_p
= 1;
3734 set_buffer_internal (old
);
3736 if (!NILP (Vtemp_buffer_show_function
))
3737 call1 (Vtemp_buffer_show_function
, buf
);
3740 window
= display_buffer (buf
, Qnil
, Qnil
);
3742 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3743 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3744 Vminibuf_scroll_window
= window
;
3745 w
= XWINDOW (window
);
3746 XSETFASTINT (w
->hscroll
, 0);
3747 XSETFASTINT (w
->min_hscroll
, 0);
3748 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3749 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3751 /* Run temp-buffer-show-hook, with the chosen window selected
3752 and its buffer current. */
3754 if (!NILP (Vrun_hooks
)
3755 && !NILP (Fboundp (Qtemp_buffer_show_hook
))
3756 && !NILP (Fsymbol_value (Qtemp_buffer_show_hook
)))
3758 int count
= SPECPDL_INDEX ();
3759 Lisp_Object prev_window
, prev_buffer
;
3760 prev_window
= selected_window
;
3761 XSETBUFFER (prev_buffer
, old
);
3763 /* Select the window that was chosen, for running the hook.
3764 Note: Both Fselect_window and select_window_norecord may
3765 set-buffer to the buffer displayed in the window,
3766 so we need to save the current buffer. --stef */
3767 record_unwind_protect (Fset_buffer
, prev_buffer
);
3768 record_unwind_protect (select_window_norecord
, prev_window
);
3769 Fselect_window (window
, Qt
);
3770 Fset_buffer (w
->buffer
);
3771 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
3772 unbind_to (count
, Qnil
);
3778 make_dummy_parent (window
)
3782 register struct window
*o
, *p
;
3785 o
= XWINDOW (window
);
3786 p
= allocate_window ();
3787 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
3788 ((struct Lisp_Vector
*) p
)->contents
[i
]
3789 = ((struct Lisp_Vector
*)o
)->contents
[i
];
3790 XSETWINDOW (new, p
);
3793 XSETFASTINT (p
->sequence_number
, sequence_number
);
3795 /* Put new into window structure in place of window */
3796 replace_window (window
, new);
3809 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
3810 doc
: /* Split WINDOW, putting SIZE lines in the first of the pair.
3811 WINDOW defaults to selected one and SIZE to half its size.
3812 If optional third arg HORIZONTAL is non-nil, split side by side and put
3813 SIZE columns in the first of the pair. In that case, SIZE includes that
3814 window's scroll bar, or the divider column to its right.
3815 Interactively, all arguments are nil.
3816 Returns the newly created window (which is the lower or rightmost one).
3817 The upper or leftmost window is the original one, and remains selected
3818 if it was selected before.
3820 See Info node `(elisp)Splitting Windows' for more details and examples. */)
3821 (window
, size
, horizontal
)
3822 Lisp_Object window
, size
, horizontal
;
3824 register Lisp_Object
new;
3825 register struct window
*o
, *p
;
3827 register int size_int
;
3830 window
= selected_window
;
3832 CHECK_LIVE_WINDOW (window
);
3834 o
= XWINDOW (window
);
3835 fo
= XFRAME (WINDOW_FRAME (o
));
3839 if (!NILP (horizontal
))
3840 /* Calculate the size of the left-hand window, by dividing
3841 the usable space in columns by two.
3842 We round up, since the left-hand window may include
3843 a dividing line, while the right-hand may not. */
3844 size_int
= (XFASTINT (o
->total_cols
) + 1) >> 1;
3846 size_int
= XFASTINT (o
->total_lines
) >> 1;
3850 CHECK_NUMBER (size
);
3851 size_int
= XINT (size
);
3854 if (MINI_WINDOW_P (o
))
3855 error ("Attempt to split minibuffer window");
3856 else if (window_fixed_size_p (o
, !NILP (horizontal
), 0))
3857 error ("Attempt to split fixed-size window");
3859 if (NILP (horizontal
))
3861 int window_safe_height
= window_min_size_2 (o
, 0, 0);
3863 if (size_int
< window_safe_height
)
3864 error ("Window height %d too small (after splitting)", size_int
);
3865 if (size_int
+ window_safe_height
> XFASTINT (o
->total_lines
))
3866 error ("Window height %d too small (after splitting)",
3867 XFASTINT (o
->total_lines
) - size_int
);
3868 if (NILP (o
->parent
)
3869 || NILP (XWINDOW (o
->parent
)->vchild
))
3871 make_dummy_parent (window
);
3873 XWINDOW (new)->vchild
= window
;
3878 int window_safe_width
= window_min_size_2 (o
, 1, 0);
3880 if (size_int
< window_safe_width
)
3881 error ("Window width %d too small (after splitting)", size_int
);
3882 if (size_int
+ window_safe_width
> XFASTINT (o
->total_cols
))
3883 error ("Window width %d too small (after splitting)",
3884 XFASTINT (o
->total_cols
) - size_int
);
3885 if (NILP (o
->parent
)
3886 || NILP (XWINDOW (o
->parent
)->hchild
))
3888 make_dummy_parent (window
);
3890 XWINDOW (new)->hchild
= window
;
3894 /* Now we know that window's parent is a vertical combination
3895 if we are dividing vertically, or a horizontal combination
3896 if we are making side-by-side windows */
3898 windows_or_buffers_changed
++;
3899 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
3900 new = make_window ();
3903 p
->frame
= o
->frame
;
3905 if (!NILP (p
->next
))
3906 XWINDOW (p
->next
)->prev
= new;
3909 p
->parent
= o
->parent
;
3911 p
->window_end_valid
= Qnil
;
3912 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
3914 /* Duplicate special geometry settings. */
3916 p
->left_margin_cols
= o
->left_margin_cols
;
3917 p
->right_margin_cols
= o
->right_margin_cols
;
3918 p
->left_fringe_width
= o
->left_fringe_width
;
3919 p
->right_fringe_width
= o
->right_fringe_width
;
3920 p
->fringes_outside_margins
= o
->fringes_outside_margins
;
3921 p
->scroll_bar_width
= o
->scroll_bar_width
;
3922 p
->vertical_scroll_bar_type
= o
->vertical_scroll_bar_type
;
3924 /* Apportion the available frame space among the two new windows */
3926 if (!NILP (horizontal
))
3928 p
->total_lines
= o
->total_lines
;
3929 p
->top_line
= o
->top_line
;
3930 XSETFASTINT (p
->total_cols
, XFASTINT (o
->total_cols
) - size_int
);
3931 XSETFASTINT (o
->total_cols
, size_int
);
3932 XSETFASTINT (p
->left_col
, XFASTINT (o
->left_col
) + size_int
);
3933 adjust_window_margins (p
);
3934 adjust_window_margins (o
);
3938 p
->left_col
= o
->left_col
;
3939 p
->total_cols
= o
->total_cols
;
3940 XSETFASTINT (p
->total_lines
, XFASTINT (o
->total_lines
) - size_int
);
3941 XSETFASTINT (o
->total_lines
, size_int
);
3942 XSETFASTINT (p
->top_line
, XFASTINT (o
->top_line
) + size_int
);
3945 /* Adjust glyph matrices. */
3948 Fset_window_buffer (new, o
->buffer
, Qt
);
3952 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
3953 doc
: /* Make selected window SIZE lines taller.
3954 Interactively, if no argument is given, make the selected window one
3955 line taller. If optional argument HORIZONTAL is non-nil, make selected
3956 window wider by SIZE columns. If SIZE is negative, shrink the window by
3957 -SIZE lines or columns. Return nil.
3959 This function can delete windows if they get too small. The size of
3960 fixed size windows is not altered by this function. */)
3962 Lisp_Object size
, horizontal
;
3964 CHECK_NUMBER (size
);
3965 enlarge_window (selected_window
, XINT (size
), !NILP (horizontal
));
3967 run_window_configuration_change_hook (SELECTED_FRAME ());
3972 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
3973 doc
: /* Make selected window SIZE lines smaller.
3974 Interactively, if no argument is given, make the selected window one
3975 line smaller. If optional argument HORIZONTAL is non-nil, make the
3976 window narrower by SIZE columns. If SIZE is negative, enlarge selected
3977 window by -SIZE lines or columns. Return nil.
3979 This function can delete windows if they get too small. The size of
3980 fixed size windows is not altered by this function. */)
3982 Lisp_Object size
, horizontal
;
3984 CHECK_NUMBER (size
);
3985 enlarge_window (selected_window
, -XINT (size
), !NILP (horizontal
));
3987 run_window_configuration_change_hook (SELECTED_FRAME ());
3993 window_height (window
)
3996 register struct window
*p
= XWINDOW (window
);
3997 return WINDOW_TOTAL_LINES (p
);
4001 window_width (window
)
4004 register struct window
*p
= XWINDOW (window
);
4005 return WINDOW_TOTAL_COLS (p
);
4010 *(horiz_flag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line))
4012 #define CURSIZE(w) \
4013 *(horiz_flag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines))
4016 /* Enlarge WINDOW by DELTA. HORIZ_FLAG nonzero means enlarge it
4017 horizontally; zero means do it vertically.
4019 Siblings of the selected window are resized to fulfill the size
4020 request. If they become too small in the process, they may be
4024 enlarge_window (window
, delta
, horiz_flag
)
4026 int delta
, horiz_flag
;
4028 Lisp_Object parent
, next
, prev
;
4032 int (*sizefun
) P_ ((Lisp_Object
))
4033 = horiz_flag
? window_width
: window_height
;
4034 void (*setsizefun
) P_ ((Lisp_Object
, int, int))
4035 = (horiz_flag
? set_window_width
: set_window_height
);
4037 /* Give up if this window cannot be resized. */
4038 if (window_fixed_size_p (XWINDOW (window
), horiz_flag
, 1))
4039 error ("Window is not resizable");
4041 /* Find the parent of the selected window. */
4044 p
= XWINDOW (window
);
4050 error ("No other window to side of this one");
4055 ? !NILP (XWINDOW (parent
)->hchild
)
4056 : !NILP (XWINDOW (parent
)->vchild
))
4062 sizep
= &CURSIZE (window
);
4065 register int maxdelta
;
4067 /* Compute the maximum size increment this window can have. */
4069 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - XINT (*sizep
)
4070 /* This is a main window followed by a minibuffer. */
4071 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
4072 - window_min_size (XWINDOW (p
->next
),
4073 horiz_flag
, 0, 0, 0))
4074 /* This is a minibuffer following a main window. */
4075 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
4076 - window_min_size (XWINDOW (p
->prev
),
4077 horiz_flag
, 0, 0, 0))
4078 /* This is a frame with only one window, a minibuffer-only
4079 or a minibufferless frame. */
4082 if (delta
> maxdelta
)
4083 /* This case traps trying to make the minibuffer
4084 the full frame, or make the only window aside from the
4085 minibuffer the full frame. */
4089 if (XINT (*sizep
) + delta
< window_min_size (XWINDOW (window
),
4090 horiz_flag
, 0, 0, 0))
4092 delete_window (window
);
4099 /* Find the total we can get from other siblings without deleting them. */
4101 for (next
= p
->next
; WINDOWP (next
); next
= XWINDOW (next
)->next
)
4102 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
4103 horiz_flag
, 0, 0, 0);
4104 for (prev
= p
->prev
; WINDOWP (prev
); prev
= XWINDOW (prev
)->prev
)
4105 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
4106 horiz_flag
, 0, 0, 0);
4108 /* If we can get it all from them without deleting them, do so. */
4109 if (delta
<= maximum
)
4111 Lisp_Object first_unaffected
;
4112 Lisp_Object first_affected
;
4117 first_affected
= window
;
4118 /* Look at one sibling at a time,
4119 moving away from this window in both directions alternately,
4120 and take as much as we can get without deleting that sibling. */
4122 && (!NILP (next
) || !NILP (prev
)))
4126 int this_one
= ((*sizefun
) (next
)
4127 - window_min_size (XWINDOW (next
), horiz_flag
,
4131 if (this_one
> delta
)
4134 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
4135 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4140 next
= XWINDOW (next
)->next
;
4148 int this_one
= ((*sizefun
) (prev
)
4149 - window_min_size (XWINDOW (prev
), horiz_flag
,
4153 if (this_one
> delta
)
4156 first_affected
= prev
;
4158 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
4159 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4164 prev
= XWINDOW (prev
)->prev
;
4168 xassert (delta
== 0);
4170 /* Now recalculate the edge positions of all the windows affected,
4171 based on the new sizes. */
4172 first_unaffected
= next
;
4173 prev
= first_affected
;
4174 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
4175 prev
= next
, next
= XWINDOW (next
)->next
)
4177 XSETINT (CURBEG (next
), XINT (CURBEG (prev
)) + (*sizefun
) (prev
));
4178 /* This does not change size of NEXT,
4179 but it propagates the new top edge to its children */
4180 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
4185 register int delta1
;
4186 register int opht
= (*sizefun
) (parent
);
4188 if (opht
<= XINT (*sizep
) + delta
)
4190 /* If trying to grow this window to or beyond size of the parent,
4191 just delete all the sibling windows. */
4192 Lisp_Object start
, tem
, next
;
4194 start
= XWINDOW (parent
)->vchild
;
4196 start
= XWINDOW (parent
)->hchild
;
4198 /* Delete any siblings that come after WINDOW. */
4199 tem
= XWINDOW (window
)->next
;
4200 while (! NILP (tem
))
4202 next
= XWINDOW (tem
)->next
;
4203 delete_window (tem
);
4207 /* Delete any siblings that come after WINDOW.
4208 Note that if START is not WINDOW, then WINDOW still
4209 has siblings, so WINDOW has not yet replaced its parent. */
4211 while (! EQ (tem
, window
))
4213 next
= XWINDOW (tem
)->next
;
4214 delete_window (tem
);
4220 /* Otherwise, make delta1 just right so that if we add
4221 delta1 lines to this window and to the parent, and then
4222 shrink the parent back to its original size, the new
4223 proportional size of this window will increase by delta.
4225 The function size_window will compute the new height h'
4226 of the window from delta1 as:
4229 x = delta1 - delta1/n * n for the 1st resizable child
4232 where n is the number of children that can be resized.
4233 We can ignore x by choosing a delta1 that is a multiple of
4234 n. We want the height of this window to come out as
4244 The number of children n equals the number of resizable
4245 children of this window + 1 because we know window itself
4246 is resizable (otherwise we would have signaled an error).
4248 This reasoning is not correct when other windows become too
4249 small and shrink_windows refuses to delete them. Below we
4250 use resize_proportionally to work around this problem. */
4252 struct window
*w
= XWINDOW (window
);
4256 for (s
= w
->next
; WINDOWP (s
); s
= XWINDOW (s
)->next
)
4257 if (!window_fixed_size_p (XWINDOW (s
), horiz_flag
, 0))
4259 for (s
= w
->prev
; WINDOWP (s
); s
= XWINDOW (s
)->prev
)
4260 if (!window_fixed_size_p (XWINDOW (s
), horiz_flag
, 0))
4265 /* Add delta1 lines or columns to this window, and to the parent,
4266 keeping things consistent while not affecting siblings. */
4267 XSETINT (CURSIZE (parent
), opht
+ delta1
);
4268 (*setsizefun
) (window
, XINT (*sizep
) + delta1
, 0);
4270 /* Squeeze out delta1 lines or columns from our parent,
4271 shrinking this window and siblings proportionately. This
4272 brings parent back to correct size. Delta1 was calculated
4273 so this makes this window the desired size, taking it all
4274 out of the siblings.
4276 Temporarily set resize_proportionally to Qt to assure that,
4277 if necessary, shrink_windows deletes smaller windows rather
4278 than shrink this window. */
4279 w
->resize_proportionally
= Qt
;
4280 (*setsizefun
) (parent
, opht
, 0);
4281 w
->resize_proportionally
= Qnil
;
4285 XSETFASTINT (p
->last_modified
, 0);
4286 XSETFASTINT (p
->last_overlay_modified
, 0);
4288 /* Adjust glyph matrices. */
4289 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4293 /* Adjust the size of WINDOW by DELTA, moving only its trailing edge.
4294 HORIZ_FLAG nonzero means adjust the width, moving the right edge.
4295 zero means adjust the height, moving the bottom edge.
4297 Following siblings of the selected window are resized to fulfill
4298 the size request. If they become too small in the process, they
4299 are not deleted; instead, we signal an error. */
4302 adjust_window_trailing_edge (window
, delta
, horiz_flag
)
4304 int delta
, horiz_flag
;
4306 Lisp_Object parent
, child
;
4308 Lisp_Object old_config
= Fcurrent_window_configuration (Qnil
);
4309 int delcount
= window_deletion_count
;
4311 CHECK_WINDOW (window
);
4313 /* Give up if this window cannot be resized. */
4314 if (window_fixed_size_p (XWINDOW (window
), horiz_flag
, 1))
4315 error ("Window is not resizable");
4319 Lisp_Object first_parallel
= Qnil
;
4323 /* This happens if WINDOW on the previous iteration was
4324 at top level of the window tree. */
4325 Fset_window_configuration (old_config
);
4326 error ("Specified window edge is fixed");
4329 p
= XWINDOW (window
);
4332 /* See if this level has windows in parallel in the specified
4333 direction. If so, set FIRST_PARALLEL to the first one. */
4336 if (! NILP (parent
) && !NILP (XWINDOW (parent
)->vchild
))
4337 first_parallel
= XWINDOW (parent
)->vchild
;
4338 else if (NILP (parent
) && !NILP (p
->next
))
4340 /* Handle the vertical chain of main window and minibuffer
4341 which has no parent. */
4342 first_parallel
= window
;
4343 while (! NILP (XWINDOW (first_parallel
)->prev
))
4344 first_parallel
= XWINDOW (first_parallel
)->prev
;
4349 if (! NILP (parent
) && !NILP (XWINDOW (parent
)->hchild
))
4350 first_parallel
= XWINDOW (parent
)->hchild
;
4353 /* If this level's succession is in the desired dimension,
4354 and this window is the last one, and there is no higher level,
4355 its trailing edge is fixed. */
4356 if (NILP (XWINDOW (window
)->next
) && NILP (first_parallel
)
4359 Fset_window_configuration (old_config
);
4360 error ("Specified window edge is fixed");
4363 /* Don't make this window too small. */
4364 if (XINT (CURSIZE (window
)) + delta
4365 < window_min_size_2 (XWINDOW (window
), horiz_flag
, 0))
4367 Fset_window_configuration (old_config
);
4368 error ("Cannot adjust window size as specified");
4371 /* Clear out some redisplay caches. */
4372 XSETFASTINT (p
->last_modified
, 0);
4373 XSETFASTINT (p
->last_overlay_modified
, 0);
4375 /* Adjust this window's edge. */
4376 XSETINT (CURSIZE (window
),
4377 XINT (CURSIZE (window
)) + delta
);
4379 /* If this window has following siblings in the desired dimension,
4380 make them smaller, and exit the loop.
4382 (If we reach the top of the tree and can never do this,
4383 we will fail and report an error, above.) */
4384 if (NILP (first_parallel
))
4386 if (!NILP (p
->next
))
4388 /* This may happen for the minibuffer. In that case
4389 the window_deletion_count check below does not work. */
4390 if (XINT (CURSIZE (p
->next
)) - delta
<= 0)
4392 Fset_window_configuration (old_config
);
4393 error ("Cannot adjust window size as specified");
4396 XSETINT (CURBEG (p
->next
),
4397 XINT (CURBEG (p
->next
)) + delta
);
4398 size_window (p
->next
, XINT (CURSIZE (p
->next
)) - delta
,
4399 horiz_flag
, 0, 1, 0);
4404 /* Here we have a chain of parallel siblings, in the other dimension.
4405 Change the size of the other siblings. */
4406 for (child
= first_parallel
;
4408 child
= XWINDOW (child
)->next
)
4409 if (! EQ (child
, window
))
4410 size_window (child
, XINT (CURSIZE (child
)) + delta
,
4411 horiz_flag
, 0, 0, 1);
4416 /* If we made a window so small it got deleted,
4417 we failed. Report failure. */
4418 if (delcount
!= window_deletion_count
)
4420 Fset_window_configuration (old_config
);
4421 error ("Cannot adjust window size as specified");
4424 /* Adjust glyph matrices. */
4425 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4431 DEFUN ("adjust-window-trailing-edge", Fadjust_window_trailing_edge
,
4432 Sadjust_window_trailing_edge
, 3, 3, 0,
4433 doc
: /* Adjust the bottom or right edge of WINDOW by DELTA.
4434 If HORIZONTAL is non-nil, that means adjust the width, moving the right edge.
4435 Otherwise, adjust the height, moving the bottom edge.
4437 Following siblings of the selected window are resized to fulfill
4438 the size request. If they become too small in the process, they
4439 are not deleted; instead, we signal an error. */)
4440 (window
, delta
, horizontal
)
4441 Lisp_Object window
, delta
, horizontal
;
4443 CHECK_NUMBER (delta
);
4445 window
= selected_window
;
4446 adjust_window_trailing_edge (window
, XINT (delta
), !NILP (horizontal
));
4448 run_window_configuration_change_hook
4449 (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4456 /***********************************************************************
4457 Resizing Mini-Windows
4458 ***********************************************************************/
4460 static void shrink_window_lowest_first
P_ ((struct window
*, int));
4462 enum save_restore_action
4469 static int save_restore_orig_size
P_ ((struct window
*,
4470 enum save_restore_action
));
4472 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
4473 from lowest windows first. */
4476 shrink_window_lowest_first (w
, height
)
4484 xassert (!MINI_WINDOW_P (w
));
4486 /* Set redisplay hints. */
4487 XSETFASTINT (w
->last_modified
, 0);
4488 XSETFASTINT (w
->last_overlay_modified
, 0);
4489 windows_or_buffers_changed
++;
4490 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
4492 old_height
= XFASTINT (w
->total_lines
);
4493 XSETFASTINT (w
->total_lines
, height
);
4495 if (!NILP (w
->hchild
))
4497 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
4499 c
= XWINDOW (child
);
4500 c
->top_line
= w
->top_line
;
4501 shrink_window_lowest_first (c
, height
);
4504 else if (!NILP (w
->vchild
))
4506 Lisp_Object last_child
;
4507 int delta
= old_height
- height
;
4512 /* Find the last child. We are taking space from lowest windows
4513 first, so we iterate over children from the last child
4515 for (child
= w
->vchild
; WINDOWP (child
); child
= XWINDOW (child
)->next
)
4518 /* Size children down to their safe heights. */
4519 for (child
= last_child
; delta
&& !NILP (child
); child
= c
->prev
)
4523 c
= XWINDOW (child
);
4524 this_one
= XFASTINT (c
->total_lines
) - window_min_size_1 (c
, 0, 1);
4526 if (this_one
> delta
)
4529 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
) - this_one
);
4533 /* Compute new positions. */
4534 last_top
= XINT (w
->top_line
);
4535 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
4537 c
= XWINDOW (child
);
4538 c
->top_line
= make_number (last_top
);
4539 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
));
4540 last_top
+= XFASTINT (c
->total_lines
);
4546 /* Save, restore, or check positions and sizes in the window tree
4547 rooted at W. ACTION says what to do.
4549 If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and
4550 orig_total_lines members are valid for all windows in the window
4551 tree. Value is non-zero if they are valid.
4553 If ACTION is SAVE_ORIG_SIZES, save members top and height in
4554 orig_top_line and orig_total_lines for all windows in the tree.
4556 If ACTION is RESTORE_ORIG_SIZES, restore top and height from values
4557 stored in orig_top_line and orig_total_lines for all windows. */
4560 save_restore_orig_size (w
, action
)
4562 enum save_restore_action action
;
4568 if (!NILP (w
->hchild
))
4570 if (!save_restore_orig_size (XWINDOW (w
->hchild
), action
))
4573 else if (!NILP (w
->vchild
))
4575 if (!save_restore_orig_size (XWINDOW (w
->vchild
), action
))
4581 case CHECK_ORIG_SIZES
:
4582 if (!INTEGERP (w
->orig_top_line
) || !INTEGERP (w
->orig_total_lines
))
4586 case SAVE_ORIG_SIZES
:
4587 w
->orig_top_line
= w
->top_line
;
4588 w
->orig_total_lines
= w
->total_lines
;
4589 XSETFASTINT (w
->last_modified
, 0);
4590 XSETFASTINT (w
->last_overlay_modified
, 0);
4593 case RESTORE_ORIG_SIZES
:
4594 xassert (INTEGERP (w
->orig_top_line
) && INTEGERP (w
->orig_total_lines
));
4595 w
->top_line
= w
->orig_top_line
;
4596 w
->total_lines
= w
->orig_total_lines
;
4597 w
->orig_total_lines
= w
->orig_top_line
= Qnil
;
4598 XSETFASTINT (w
->last_modified
, 0);
4599 XSETFASTINT (w
->last_overlay_modified
, 0);
4606 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
4613 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
4614 without deleting other windows. */
4617 grow_mini_window (w
, delta
)
4621 struct frame
*f
= XFRAME (w
->frame
);
4622 struct window
*root
;
4624 xassert (MINI_WINDOW_P (w
));
4625 xassert (delta
>= 0);
4627 /* Compute how much we can enlarge the mini-window without deleting
4629 root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4632 int min_height
= window_min_size (root
, 0, 0, 0, 0);
4633 if (XFASTINT (root
->total_lines
) - delta
< min_height
)
4634 /* Note that the root window may already be smaller than
4636 delta
= max (0, XFASTINT (root
->total_lines
) - min_height
);
4641 /* Save original window sizes and positions, if not already done. */
4642 if (!save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4643 save_restore_orig_size (root
, SAVE_ORIG_SIZES
);
4645 /* Shrink other windows. */
4646 shrink_window_lowest_first (root
, XFASTINT (root
->total_lines
) - delta
);
4648 /* Grow the mini-window. */
4649 w
->top_line
= make_number (XFASTINT (root
->top_line
) + XFASTINT (root
->total_lines
));
4650 w
->total_lines
= make_number (XFASTINT (w
->total_lines
) + delta
);
4651 XSETFASTINT (w
->last_modified
, 0);
4652 XSETFASTINT (w
->last_overlay_modified
, 0);
4659 /* Shrink mini-window W. If there is recorded info about window sizes
4660 before a call to grow_mini_window, restore recorded window sizes.
4661 Otherwise, if the mini-window is higher than 1 line, resize it to 1
4665 shrink_mini_window (w
)
4668 struct frame
*f
= XFRAME (w
->frame
);
4669 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4671 if (save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4673 save_restore_orig_size (root
, RESTORE_ORIG_SIZES
);
4675 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4676 windows_or_buffers_changed
= 1;
4678 else if (XFASTINT (w
->total_lines
) > 1)
4680 /* Distribute the additional lines of the mini-window
4681 among the other windows. */
4683 XSETWINDOW (window
, w
);
4684 enlarge_window (window
, 1 - XFASTINT (w
->total_lines
), 0);
4690 /* Mark window cursors off for all windows in the window tree rooted
4691 at W by setting their phys_cursor_on_p flag to zero. Called from
4692 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4693 the frame are cleared. */
4696 mark_window_cursors_off (w
)
4701 if (!NILP (w
->hchild
))
4702 mark_window_cursors_off (XWINDOW (w
->hchild
));
4703 else if (!NILP (w
->vchild
))
4704 mark_window_cursors_off (XWINDOW (w
->vchild
));
4706 w
->phys_cursor_on_p
= 0;
4708 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4713 /* Return number of lines of text (not counting mode lines) in W. */
4716 window_internal_height (w
)
4719 int ht
= XFASTINT (w
->total_lines
);
4721 if (!MINI_WINDOW_P (w
))
4723 if (!NILP (w
->parent
)
4724 || !NILP (w
->vchild
)
4725 || !NILP (w
->hchild
)
4728 || WINDOW_WANTS_MODELINE_P (w
))
4731 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4739 /* Return the number of columns in W.
4740 Don't count columns occupied by scroll bars or the vertical bar
4741 separating W from the sibling to its right. */
4744 window_box_text_cols (w
)
4747 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4748 int width
= XINT (w
->total_cols
);
4750 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
4751 /* Scroll bars occupy a few columns. */
4752 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
4753 else if (!FRAME_WINDOW_P (f
)
4754 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
4755 /* The column of `|' characters separating side-by-side windows
4756 occupies one column only. */
4759 if (FRAME_WINDOW_P (f
))
4760 /* On window-systems, fringes and display margins cannot be
4761 used for normal text. */
4762 width
-= (WINDOW_FRINGE_COLS (w
)
4763 + WINDOW_LEFT_MARGIN_COLS (w
)
4764 + WINDOW_RIGHT_MARGIN_COLS (w
));
4770 /************************************************************************
4772 ***********************************************************************/
4774 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4775 N screen-fulls, which is defined as the height of the window minus
4776 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4777 instead. Negative values of N mean scroll down. NOERROR non-zero
4778 means don't signal an error if we try to move over BEGV or ZV,
4782 window_scroll (window
, n
, whole
, noerror
)
4790 /* If we must, use the pixel-based version which is much slower than
4791 the line-based one but can handle varying line heights. */
4792 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4793 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4795 window_scroll_line_based (window
, n
, whole
, noerror
);
4801 /* Implementation of window_scroll that works based on pixel line
4802 heights. See the comment of window_scroll for parameter
4806 window_scroll_pixel_based (window
, n
, whole
, noerror
)
4813 struct window
*w
= XWINDOW (window
);
4814 struct text_pos start
;
4815 int this_scroll_margin
;
4816 /* True if we fiddled the window vscroll field without really scrolling. */
4818 int x
, y
, rtop
, rbot
, rowh
, vpos
;
4820 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4822 /* If PT is not visible in WINDOW, move back one half of
4823 the screen. Allow PT to be partially visible, otherwise
4824 something like (scroll-down 1) with PT in the line before
4825 the partially visible one would recenter. */
4827 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
4829 /* Move backward half the height of the window. Performance note:
4830 vmotion used here is about 10% faster, but would give wrong
4831 results for variable height lines. */
4832 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4833 it
.current_y
= it
.last_visible_y
;
4834 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4836 /* The function move_iterator_vertically may move over more than
4837 the specified y-distance. If it->w is small, e.g. a
4838 mini-buffer window, we may end up in front of the window's
4839 display area. This is the case when Start displaying at the
4840 start of the line containing PT in this case. */
4841 if (it
.current_y
<= 0)
4843 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4844 move_it_vertically_backward (&it
, 0);
4848 start
= it
.current
.pos
;
4850 else if (auto_window_vscroll_p
)
4852 if (rtop
|| rbot
) /* partially visible */
4855 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4857 dy
= max ((window_box_height (w
)
4858 - next_screen_context_lines
* dy
),
4864 /* Only vscroll backwards if already vscrolled forwards. */
4865 if (w
->vscroll
< 0 && rtop
> 0)
4867 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
4868 Fset_window_vscroll (window
, make_number (px
), Qt
);
4874 /* Do vscroll if already vscrolled or only display line. */
4875 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
4877 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
4878 Fset_window_vscroll (window
, make_number (px
), Qt
);
4882 /* Maybe modify window start instead of scrolling. */
4883 if (rbot
> 0 || w
->vscroll
< 0)
4887 Fset_window_vscroll (window
, make_number (0), Qt
);
4888 /* If there are other text lines above the current row,
4889 move window start to current row. Else to next row. */
4891 spos
= XINT (Fline_beginning_position (Qnil
));
4893 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
4894 set_marker_restricted (w
->start
, make_number (spos
),
4896 w
->start_at_line_beg
= Qt
;
4897 w
->update_mode_line
= Qt
;
4898 XSETFASTINT (w
->last_modified
, 0);
4899 XSETFASTINT (w
->last_overlay_modified
, 0);
4900 /* Set force_start so that redisplay_window will run the
4901 window-scroll-functions. */
4902 w
->force_start
= Qt
;
4907 /* Cancel previous vscroll. */
4908 Fset_window_vscroll (window
, make_number (0), Qt
);
4911 /* If scroll_preserve_screen_position is non-nil, we try to set
4912 point in the same window line as it is now, so get that line. */
4913 if (!NILP (Vscroll_preserve_screen_position
))
4915 /* We preserve the goal pixel coordinate across consecutive
4916 calls to scroll-up or scroll-down. This avoids the
4917 possibility of point becoming "stuck" on a tall line when
4918 scrolling by one line. */
4919 if (window_scroll_pixel_based_preserve_y
< 0
4920 || (!EQ (current_kboard
->Vlast_command
, Qscroll_up
)
4921 && !EQ (current_kboard
->Vlast_command
, Qscroll_down
)))
4923 start_display (&it
, w
, start
);
4924 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4925 window_scroll_pixel_based_preserve_y
= it
.current_y
;
4926 window_scroll_pixel_based_preserve_x
= it
.current_x
;
4930 window_scroll_pixel_based_preserve_y
4931 = window_scroll_pixel_based_preserve_x
= -1;
4933 /* Move iterator it from start the specified distance forward or
4934 backward. The result is the new window start. */
4935 start_display (&it
, w
, start
);
4938 int start_pos
= IT_CHARPOS (it
);
4939 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4940 dy
= max ((window_box_height (w
)
4941 - next_screen_context_lines
* dy
),
4944 /* Note that move_it_vertically always moves the iterator to the
4945 start of a line. So, if the last line doesn't have a newline,
4946 we would end up at the start of the line ending at ZV. */
4949 move_it_vertically_backward (&it
, -dy
);
4950 /* Ensure we actually do move, e.g. in case we are currently
4951 looking at an image that is taller that the window height. */
4952 while (start_pos
== IT_CHARPOS (it
)
4953 && start_pos
> BEGV
)
4954 move_it_by_lines (&it
, -1, 1);
4958 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4959 MOVE_TO_POS
| MOVE_TO_Y
);
4960 /* Ensure we actually do move, e.g. in case we are currently
4961 looking at an image that is taller that the window height. */
4962 while (start_pos
== IT_CHARPOS (it
)
4964 move_it_by_lines (&it
, 1, 1);
4968 move_it_by_lines (&it
, n
, 1);
4970 /* We failed if we find ZV is already on the screen (scrolling up,
4971 means there's nothing past the end), or if we can't start any
4972 earlier (scrolling down, means there's nothing past the top). */
4973 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4974 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4976 if (IT_CHARPOS (it
) == ZV
)
4978 if (it
.current_y
< it
.last_visible_y
4979 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4980 > it
.last_visible_y
))
4982 /* The last line was only partially visible, make it fully
4984 w
->vscroll
= (it
.last_visible_y
4985 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4986 adjust_glyphs (it
.f
);
4990 else if (n
< 0) /* could happen with empty buffers */
4991 xsignal0 (Qbeginning_of_buffer
);
4993 xsignal0 (Qend_of_buffer
);
4997 if (w
->vscroll
!= 0)
4998 /* The first line was only partially visible, make it fully
5004 xsignal0 (Qbeginning_of_buffer
);
5007 /* If control gets here, then we vscrolled. */
5009 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
5011 /* Don't try to change the window start below. */
5017 int pos
= IT_CHARPOS (it
);
5020 /* If in the middle of a multi-glyph character move forward to
5021 the next character. */
5022 if (in_display_vector_p (&it
))
5025 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
5028 /* Set the window start, and set up the window for redisplay. */
5029 set_marker_restricted (w
->start
, make_number (pos
),
5031 bytepos
= XMARKER (w
->start
)->bytepos
;
5032 w
->start_at_line_beg
= ((pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n')
5034 w
->update_mode_line
= Qt
;
5035 XSETFASTINT (w
->last_modified
, 0);
5036 XSETFASTINT (w
->last_overlay_modified
, 0);
5037 /* Set force_start so that redisplay_window will run the
5038 window-scroll-functions. */
5039 w
->force_start
= Qt
;
5042 /* The rest of this function uses current_y in a nonstandard way,
5043 not including the height of the header line if any. */
5044 it
.current_y
= it
.vpos
= 0;
5046 /* Move PT out of scroll margins.
5047 This code wants current_y to be zero at the window start position
5048 even if there is a header line. */
5049 this_scroll_margin
= max (0, scroll_margin
);
5050 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->total_lines
) / 4);
5051 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
5055 /* We moved the window start towards ZV, so PT may be now
5056 in the scroll margin at the top. */
5057 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5058 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
5059 && (NILP (Vscroll_preserve_screen_position
)
5060 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5061 /* We found PT at a legitimate height. Leave it alone. */
5063 else if (window_scroll_pixel_based_preserve_y
>= 0)
5065 /* If we have a header line, take account of it.
5066 This is necessary because we set it.current_y to 0, above. */
5067 move_it_to (&it
, -1,
5068 window_scroll_pixel_based_preserve_x
,
5069 window_scroll_pixel_based_preserve_y
5070 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
5071 -1, MOVE_TO_Y
| MOVE_TO_X
);
5072 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5076 while (it
.current_y
< this_scroll_margin
)
5078 int prev
= it
.current_y
;
5079 move_it_by_lines (&it
, 1, 1);
5080 if (prev
== it
.current_y
)
5083 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5088 int charpos
, bytepos
;
5091 /* Save our position, for the
5092 window_scroll_pixel_based_preserve_y case. */
5093 charpos
= IT_CHARPOS (it
);
5094 bytepos
= IT_BYTEPOS (it
);
5096 /* We moved the window start towards BEGV, so PT may be now
5097 in the scroll margin at the bottom. */
5098 move_it_to (&it
, PT
, -1,
5099 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
5100 - this_scroll_margin
- 1),
5102 MOVE_TO_POS
| MOVE_TO_Y
);
5104 /* Save our position, in case it's correct. */
5105 charpos
= IT_CHARPOS (it
);
5106 bytepos
= IT_BYTEPOS (it
);
5108 /* See if point is on a partially visible line at the end. */
5109 if (it
.what
== IT_EOB
)
5110 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
5113 move_it_by_lines (&it
, 1, 1);
5114 partial_p
= it
.current_y
> it
.last_visible_y
;
5117 if (charpos
== PT
&& !partial_p
5118 && (NILP (Vscroll_preserve_screen_position
)
5119 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5120 /* We found PT before we found the display margin, so PT is ok. */
5122 else if (window_scroll_pixel_based_preserve_y
>= 0)
5124 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5125 start_display (&it
, w
, start
);
5126 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
5127 here because we called start_display again and did not
5128 alter it.current_y this time. */
5129 move_it_to (&it
, -1, window_scroll_pixel_based_preserve_x
,
5130 window_scroll_pixel_based_preserve_y
, -1,
5131 MOVE_TO_Y
| MOVE_TO_X
);
5132 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5137 /* The last line was only partially visible, so back up two
5138 lines to make sure we're on a fully visible line. */
5140 move_it_by_lines (&it
, -2, 0);
5141 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5144 /* No, the position we saved is OK, so use it. */
5145 SET_PT_BOTH (charpos
, bytepos
);
5151 /* Implementation of window_scroll that works based on screen lines.
5152 See the comment of window_scroll for parameter descriptions. */
5155 window_scroll_line_based (window
, n
, whole
, noerror
)
5161 register struct window
*w
= XWINDOW (window
);
5162 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
5163 register int pos
, pos_byte
;
5164 register int ht
= window_internal_height (w
);
5165 register Lisp_Object tem
;
5169 Lisp_Object original_pos
= Qnil
;
5171 /* If scrolling screen-fulls, compute the number of lines to
5172 scroll from the window's height. */
5174 n
*= max (1, ht
- next_screen_context_lines
);
5176 startpos
= marker_position (w
->start
);
5178 if (!NILP (Vscroll_preserve_screen_position
))
5180 if (window_scroll_preserve_vpos
<= 0
5181 || (!EQ (current_kboard
->Vlast_command
, Qscroll_up
)
5182 && !EQ (current_kboard
->Vlast_command
, Qscroll_down
)))
5184 struct position posit
5185 = *compute_motion (startpos
, 0, 0, 0,
5187 -1, XINT (w
->hscroll
),
5189 window_scroll_preserve_vpos
= posit
.vpos
;
5190 window_scroll_preserve_hpos
= posit
.hpos
+ XINT (w
->hscroll
);
5193 original_pos
= Fcons (make_number (window_scroll_preserve_hpos
),
5194 make_number (window_scroll_preserve_vpos
));
5197 XSETFASTINT (tem
, PT
);
5198 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
5202 Fvertical_motion (make_number (- (ht
/ 2)), window
);
5207 lose
= n
< 0 && PT
== BEGV
;
5208 Fvertical_motion (make_number (n
), window
);
5212 SET_PT_BOTH (opoint
, opoint_byte
);
5219 xsignal0 (Qbeginning_of_buffer
);
5224 int this_scroll_margin
= scroll_margin
;
5226 /* Don't use a scroll margin that is negative or too large. */
5227 if (this_scroll_margin
< 0)
5228 this_scroll_margin
= 0;
5230 if (XINT (w
->total_lines
) < 4 * scroll_margin
)
5231 this_scroll_margin
= XINT (w
->total_lines
) / 4;
5233 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
5234 w
->start_at_line_beg
= bolp
;
5235 w
->update_mode_line
= Qt
;
5236 XSETFASTINT (w
->last_modified
, 0);
5237 XSETFASTINT (w
->last_overlay_modified
, 0);
5238 /* Set force_start so that redisplay_window will run
5239 the window-scroll-functions. */
5240 w
->force_start
= Qt
;
5242 if (!NILP (Vscroll_preserve_screen_position
)
5243 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
5245 SET_PT_BOTH (pos
, pos_byte
);
5246 Fvertical_motion (original_pos
, window
);
5248 /* If we scrolled forward, put point enough lines down
5249 that it is outside the scroll margin. */
5254 if (this_scroll_margin
> 0)
5256 SET_PT_BOTH (pos
, pos_byte
);
5257 Fvertical_motion (make_number (this_scroll_margin
), window
);
5263 if (top_margin
<= opoint
)
5264 SET_PT_BOTH (opoint
, opoint_byte
);
5265 else if (!NILP (Vscroll_preserve_screen_position
))
5267 SET_PT_BOTH (pos
, pos_byte
);
5268 Fvertical_motion (original_pos
, window
);
5271 SET_PT (top_margin
);
5277 /* If we scrolled backward, put point near the end of the window
5278 but not within the scroll margin. */
5279 SET_PT_BOTH (pos
, pos_byte
);
5280 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
5281 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
5284 bottom_margin
= PT
+ 1;
5286 if (bottom_margin
> opoint
)
5287 SET_PT_BOTH (opoint
, opoint_byte
);
5290 if (!NILP (Vscroll_preserve_screen_position
))
5292 SET_PT_BOTH (pos
, pos_byte
);
5293 Fvertical_motion (original_pos
, window
);
5296 Fvertical_motion (make_number (-1), window
);
5305 xsignal0 (Qend_of_buffer
);
5310 /* Scroll selected_window up or down. If N is nil, scroll a
5311 screen-full which is defined as the height of the window minus
5312 next_screen_context_lines. If N is the symbol `-', scroll.
5313 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
5314 up. This is the guts of Fscroll_up and Fscroll_down. */
5317 scroll_command (n
, direction
)
5321 int count
= SPECPDL_INDEX ();
5323 xassert (eabs (direction
) == 1);
5325 /* If selected window's buffer isn't current, make it current for
5326 the moment. But don't screw up if window_scroll gets an error. */
5327 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
5329 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5330 Fset_buffer (XWINDOW (selected_window
)->buffer
);
5332 /* Make redisplay consider other windows than just selected_window. */
5333 ++windows_or_buffers_changed
;
5337 window_scroll (selected_window
, direction
, 1, 0);
5338 else if (EQ (n
, Qminus
))
5339 window_scroll (selected_window
, -direction
, 1, 0);
5342 n
= Fprefix_numeric_value (n
);
5343 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
5346 unbind_to (count
, Qnil
);
5349 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "^P",
5350 doc
: /* Scroll text of selected window upward ARG lines.
5351 If ARG is omitted or nil, scroll upward by a near full screen.
5352 A near full screen is `next-screen-context-lines' less than a full screen.
5353 Negative ARG means scroll downward.
5354 If ARG is the atom `-', scroll downward by nearly full screen.
5355 When calling from a program, supply as argument a number, nil, or `-'. */)
5359 scroll_command (arg
, 1);
5363 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "^P",
5364 doc
: /* Scroll text of selected window down ARG lines.
5365 If ARG is omitted or nil, scroll down by a near full screen.
5366 A near full screen is `next-screen-context-lines' less than a full screen.
5367 Negative ARG means scroll upward.
5368 If ARG is the atom `-', scroll upward by nearly full screen.
5369 When calling from a program, supply as argument a number, nil, or `-'. */)
5373 scroll_command (arg
, -1);
5377 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
5378 doc
: /* Return the other window for \"other window scroll\" commands.
5379 If `other-window-scroll-buffer' is non-nil, a window
5380 showing that buffer is used.
5381 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5382 specifies the window. This takes precedence over
5383 `other-window-scroll-buffer'. */)
5388 if (MINI_WINDOW_P (XWINDOW (selected_window
))
5389 && !NILP (Vminibuf_scroll_window
))
5390 window
= Vminibuf_scroll_window
;
5391 /* If buffer is specified, scroll that buffer. */
5392 else if (!NILP (Vother_window_scroll_buffer
))
5394 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
5396 window
= display_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
5400 /* Nothing specified; look for a neighboring window on the same
5402 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
5404 if (EQ (window
, selected_window
))
5405 /* That didn't get us anywhere; look for a window on another
5408 window
= Fnext_window (window
, Qnil
, Qt
);
5409 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
5410 && ! EQ (window
, selected_window
));
5413 CHECK_LIVE_WINDOW (window
);
5415 if (EQ (window
, selected_window
))
5416 error ("There is no other window");
5421 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
5422 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5423 A near full screen is `next-screen-context-lines' less than a full screen.
5424 The next window is the one below the current one; or the one at the top
5425 if the current one is at the bottom. Negative ARG means scroll downward.
5426 If ARG is the atom `-', scroll downward by nearly full screen.
5427 When calling from a program, supply as argument a number, nil, or `-'.
5429 If `other-window-scroll-buffer' is non-nil, scroll the window
5430 showing that buffer, popping the buffer up if necessary.
5431 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5432 specifies the window to scroll. This takes precedence over
5433 `other-window-scroll-buffer'. */)
5439 int count
= SPECPDL_INDEX ();
5441 window
= Fother_window_for_scrolling ();
5442 w
= XWINDOW (window
);
5444 /* Don't screw up if window_scroll gets an error. */
5445 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5446 ++windows_or_buffers_changed
;
5448 Fset_buffer (w
->buffer
);
5449 SET_PT (marker_position (w
->pointm
));
5452 window_scroll (window
, 1, 1, 1);
5453 else if (EQ (arg
, Qminus
))
5454 window_scroll (window
, -1, 1, 1);
5460 window_scroll (window
, XINT (arg
), 0, 1);
5463 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5464 unbind_to (count
, Qnil
);
5469 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "^P\np",
5470 doc
: /* Scroll selected window display ARG columns left.
5471 Default for ARG is window width minus 2.
5472 Value is the total amount of leftward horizontal scrolling in
5473 effect after the change.
5474 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5475 lower bound for automatic scrolling, i.e. automatic scrolling
5476 will not scroll a window to a column less than the value returned
5477 by this function. This happens in an interactive call. */)
5479 register Lisp_Object arg
, set_minimum
;
5483 struct window
*w
= XWINDOW (selected_window
);
5486 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5488 arg
= Fprefix_numeric_value (arg
);
5490 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
5491 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5493 if (!NILP (set_minimum
))
5494 w
->min_hscroll
= w
->hscroll
;
5499 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "^P\np",
5500 doc
: /* Scroll selected window display ARG columns right.
5501 Default for ARG is window width minus 2.
5502 Value is the total amount of leftward horizontal scrolling in
5503 effect after the change.
5504 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5505 lower bound for automatic scrolling, i.e. automatic scrolling
5506 will not scroll a window to a column less than the value returned
5507 by this function. This happens in an interactive call. */)
5509 register Lisp_Object arg
, set_minimum
;
5513 struct window
*w
= XWINDOW (selected_window
);
5516 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5518 arg
= Fprefix_numeric_value (arg
);
5520 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
5521 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5523 if (!NILP (set_minimum
))
5524 w
->min_hscroll
= w
->hscroll
;
5529 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5530 doc
: /* Return the window which was selected when entering the minibuffer.
5531 Returns nil, if selected window is not a minibuffer window. */)
5534 if (minibuf_level
> 0
5535 && MINI_WINDOW_P (XWINDOW (selected_window
))
5536 && WINDOW_LIVE_P (minibuf_selected_window
))
5537 return minibuf_selected_window
;
5542 /* Value is the number of lines actually displayed in window W,
5543 as opposed to its height. */
5546 displayed_window_lines (w
)
5550 struct text_pos start
;
5551 int height
= window_box_height (w
);
5552 struct buffer
*old_buffer
;
5555 if (XBUFFER (w
->buffer
) != current_buffer
)
5557 old_buffer
= current_buffer
;
5558 set_buffer_internal (XBUFFER (w
->buffer
));
5563 /* In case W->start is out of the accessible range, do something
5564 reasonable. This happens in Info mode when Info-scroll-down
5565 calls (recenter -1) while W->start is 1. */
5566 if (XMARKER (w
->start
)->charpos
< BEGV
)
5567 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5568 else if (XMARKER (w
->start
)->charpos
> ZV
)
5569 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
5571 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5573 start_display (&it
, w
, start
);
5574 move_it_vertically (&it
, height
);
5575 bottom_y
= line_bottom_y (&it
);
5577 /* rms: On a non-window display,
5578 the value of it.vpos at the bottom of the screen
5579 seems to be 1 larger than window_box_height (w).
5580 This kludge fixes a bug whereby (move-to-window-line -1)
5581 when ZV is on the last screen line
5582 moves to the previous screen line instead of the last one. */
5583 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5586 /* Add in empty lines at the bottom of the window. */
5587 if (bottom_y
< height
)
5589 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5590 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5594 set_buffer_internal (old_buffer
);
5600 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5601 doc
: /* Center point in selected window and redisplay frame.
5602 With prefix argument ARG, recenter putting point on screen line ARG
5603 relative to the selected window. If ARG is negative, it counts up from the
5604 bottom of the window. (ARG should be less than the height of the window.)
5606 If ARG is omitted or nil, erase the entire frame and then redraw with point
5607 in the center of the selected window. If `auto-resize-tool-bars' is set to
5608 `grow-only', this resets the tool-bar's height to the minimum height needed.
5610 Just C-u as prefix means put point in the center of the window
5611 and redisplay normally--don't erase and redraw the frame. */)
5613 register Lisp_Object arg
;
5615 struct window
*w
= XWINDOW (selected_window
);
5616 struct buffer
*buf
= XBUFFER (w
->buffer
);
5617 struct buffer
*obuf
= current_buffer
;
5619 int charpos
, bytepos
;
5621 int this_scroll_margin
;
5623 /* If redisplay is suppressed due to an error, try again. */
5624 obuf
->display_error_modiff
= 0;
5630 /* Invalidate pixel data calculated for all compositions. */
5631 for (i
= 0; i
< n_compositions
; i
++)
5632 composition_table
[i
]->font
= NULL
;
5634 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5636 Fredraw_frame (WINDOW_FRAME (w
));
5637 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5640 else if (CONSP (arg
)) /* Just C-u. */
5644 arg
= Fprefix_numeric_value (arg
);
5649 set_buffer_internal (buf
);
5651 /* Do this after making BUF current
5652 in case scroll_margin is buffer-local. */
5653 this_scroll_margin
= max (0, scroll_margin
);
5654 this_scroll_margin
= min (this_scroll_margin
,
5655 XFASTINT (w
->total_lines
) / 4);
5657 /* Handle centering on a graphical frame specially. Such frames can
5658 have variable-height lines and centering point on the basis of
5659 line counts would lead to strange effects. */
5660 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5667 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5668 start_display (&it
, w
, pt
);
5669 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5670 charpos
= IT_CHARPOS (it
);
5671 bytepos
= IT_BYTEPOS (it
);
5678 int extra_line_spacing
;
5679 int h
= window_box_height (w
);
5681 iarg
= - max (-iarg
, this_scroll_margin
);
5683 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5684 start_display (&it
, w
, pt
);
5686 /* Be sure we have the exact height of the full line containing PT. */
5687 move_it_by_lines (&it
, 0, 1);
5689 /* The amount of pixels we have to move back is the window
5690 height minus what's displayed in the line containing PT,
5691 and the lines below. */
5694 move_it_by_lines (&it
, nlines
, 1);
5696 if (it
.vpos
== nlines
)
5700 /* Last line has no newline */
5701 h
-= line_bottom_y (&it
);
5705 /* Don't reserve space for extra line spacing of last line. */
5706 extra_line_spacing
= it
.max_extra_line_spacing
;
5708 /* If we can't move down NLINES lines because we hit
5709 the end of the buffer, count in some empty lines. */
5710 if (it
.vpos
< nlines
)
5713 extra_line_spacing
= it
.extra_line_spacing
;
5714 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5719 /* Now find the new top line (starting position) of the window. */
5720 start_display (&it
, w
, pt
);
5722 move_it_vertically_backward (&it
, h
);
5724 /* If extra line spacing is present, we may move too far
5725 back. This causes the last line to be only partially
5726 visible (which triggers redisplay to recenter that line
5727 in the middle), so move forward.
5728 But ignore extra line spacing on last line, as it is not
5729 considered to be part of the visible height of the line.
5731 h
+= extra_line_spacing
;
5732 while (-it
.current_y
> h
)
5733 move_it_by_lines (&it
, 1, 1);
5735 charpos
= IT_CHARPOS (it
);
5736 bytepos
= IT_BYTEPOS (it
);
5740 struct position pos
;
5742 iarg
= max (iarg
, this_scroll_margin
);
5744 pos
= *vmotion (PT
, -iarg
, w
);
5745 charpos
= pos
.bufpos
;
5746 bytepos
= pos
.bytepos
;
5751 struct position pos
;
5752 int ht
= window_internal_height (w
);
5759 /* Don't let it get into the margin at either top or bottom. */
5760 iarg
= max (iarg
, this_scroll_margin
);
5761 iarg
= min (iarg
, ht
- this_scroll_margin
- 1);
5763 pos
= *vmotion (PT
, - iarg
, w
);
5764 charpos
= pos
.bufpos
;
5765 bytepos
= pos
.bytepos
;
5768 /* Set the new window start. */
5769 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
5770 w
->window_end_valid
= Qnil
;
5772 w
->optional_new_start
= Qt
;
5774 if (bytepos
== BEGV_BYTE
|| FETCH_BYTE (bytepos
- 1) == '\n')
5775 w
->start_at_line_beg
= Qt
;
5777 w
->start_at_line_beg
= Qnil
;
5779 set_buffer_internal (obuf
);
5784 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5786 doc
: /* Return the height in lines of the text display area of WINDOW.
5787 WINDOW defaults to the selected window.
5789 The return value does neither include the mode line or header line, if
5790 any, nor any partial-height lines in the text display area. */)
5794 struct window
*w
= decode_window (window
);
5795 int pixel_height
= window_box_height (w
);
5796 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5797 return make_number (line_height
);
5802 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5804 doc
: /* Position point relative to window.
5805 With no argument, position point at center of window.
5806 An argument specifies vertical position within the window;
5807 zero means top of window, negative means relative to bottom of window. */)
5811 struct window
*w
= XWINDOW (selected_window
);
5815 int this_scroll_margin
;
5818 window
= selected_window
;
5819 start
= marker_position (w
->start
);
5820 if (start
< BEGV
|| start
> ZV
)
5822 int height
= window_internal_height (w
);
5823 Fvertical_motion (make_number (- (height
/ 2)), window
);
5824 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
5825 w
->start_at_line_beg
= Fbolp ();
5826 w
->force_start
= Qt
;
5829 Fgoto_char (w
->start
);
5831 lines
= displayed_window_lines (w
);
5834 this_scroll_margin
= max (0, scroll_margin
);
5835 this_scroll_margin
= min (this_scroll_margin
, lines
/ 4);
5839 XSETFASTINT (arg
, lines
/ 2);
5842 int iarg
= XINT (Fprefix_numeric_value (arg
));
5845 iarg
= iarg
+ lines
;
5847 #if 0 /* This code would prevent move-to-window-line from moving point
5848 to a place inside the scroll margins (which would cause the
5849 next redisplay to scroll). I wrote this code, but then concluded
5850 it is probably better not to install it. However, it is here
5851 inside #if 0 so as not to lose it. -- rms. */
5853 /* Don't let it get into the margin at either top or bottom. */
5854 iarg
= max (iarg
, this_scroll_margin
);
5855 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
5858 arg
= make_number (iarg
);
5861 /* Skip past a partially visible first line. */
5863 XSETINT (arg
, XINT (arg
) + 1);
5865 return Fvertical_motion (arg
, window
);
5870 /***********************************************************************
5871 Window Configuration
5872 ***********************************************************************/
5874 struct save_window_data
5877 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5878 Lisp_Object selected_frame
;
5879 Lisp_Object current_window
;
5880 Lisp_Object current_buffer
;
5881 Lisp_Object minibuf_scroll_window
;
5882 Lisp_Object minibuf_selected_window
;
5883 Lisp_Object root_window
;
5884 Lisp_Object focus_frame
;
5885 /* A vector, each of whose elements is a struct saved_window
5887 Lisp_Object saved_windows
;
5889 /* All fields above are traced by the GC.
5890 From `fame-cols' down, the fields are ignored by the GC. */
5892 int frame_cols
, frame_lines
, frame_menu_bar_lines
;
5893 int frame_tool_bar_lines
;
5896 /* This is saved as a Lisp_Vector */
5899 /* these first two must agree with struct Lisp_Vector in lisp.h */
5901 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5904 Lisp_Object buffer
, start
, pointm
, mark
;
5905 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5906 Lisp_Object hscroll
, min_hscroll
;
5907 Lisp_Object parent
, prev
;
5908 Lisp_Object start_at_line_beg
;
5909 Lisp_Object display_table
;
5910 Lisp_Object orig_top_line
, orig_total_lines
;
5911 Lisp_Object left_margin_cols
, right_margin_cols
;
5912 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
5913 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
;
5914 Lisp_Object dedicated
, resize_proportionally
;
5917 #define SAVED_WINDOW_N(swv,n) \
5918 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5920 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
5921 doc
: /* Return t if OBJECT is a window-configuration object. */)
5925 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
5928 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
5929 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5933 register struct save_window_data
*data
;
5934 struct Lisp_Vector
*saved_windows
;
5936 CHECK_WINDOW_CONFIGURATION (config
);
5938 data
= (struct save_window_data
*) XVECTOR (config
);
5939 saved_windows
= XVECTOR (data
->saved_windows
);
5940 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5943 DEFUN ("set-window-configuration", Fset_window_configuration
,
5944 Sset_window_configuration
, 1, 1, 0,
5945 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5946 CONFIGURATION must be a value previously returned
5947 by `current-window-configuration' (which see).
5948 If CONFIGURATION was made from a frame that is now deleted,
5949 only frame-independent values can be restored. In this case,
5950 the return value is nil. Otherwise the value is t. */)
5952 Lisp_Object configuration
;
5954 register struct save_window_data
*data
;
5955 struct Lisp_Vector
*saved_windows
;
5956 Lisp_Object new_current_buffer
;
5961 CHECK_WINDOW_CONFIGURATION (configuration
);
5963 data
= (struct save_window_data
*) XVECTOR (configuration
);
5964 saved_windows
= XVECTOR (data
->saved_windows
);
5966 new_current_buffer
= data
->current_buffer
;
5967 if (NILP (XBUFFER (new_current_buffer
)->name
))
5968 new_current_buffer
= Qnil
;
5971 if (XBUFFER (new_current_buffer
) == current_buffer
)
5972 /* The code further down "preserves point" by saving here PT in
5973 old_point and then setting it later back into PT. When the
5974 current-selected-window and the final-selected-window both show
5975 the current buffer, this suffers from the problem that the
5976 current PT is the window-point of the current-selected-window,
5977 while the final PT is the point of the final-selected-window, so
5978 this copy from one PT to the other would end up moving the
5979 window-point of the final-selected-window to the window-point of
5980 the current-selected-window. So we have to be careful which
5981 point of the current-buffer we copy into old_point. */
5982 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
5983 && WINDOWP (selected_window
)
5984 && EQ (XWINDOW (selected_window
)->buffer
, new_current_buffer
)
5985 && !EQ (selected_window
, data
->current_window
))
5986 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
5990 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
5991 point in new_current_buffer as of the last time this buffer was
5992 used. This can be non-deterministic since it can be changed by
5993 things like jit-lock by mere temporary selection of some random
5994 window that happens to show this buffer.
5995 So if possible we want this arbitrary choice of "which point" to
5996 be the one from the to-be-selected-window so as to prevent this
5997 window's cursor from being copied from another window. */
5998 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
5999 /* If current_window = selected_window, its point is in BUF_PT. */
6000 && !EQ (selected_window
, data
->current_window
))
6001 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
6003 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
6006 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6009 /* If f is a dead frame, don't bother rebuilding its window tree.
6010 However, there is other stuff we should still try to do below. */
6011 if (FRAME_LIVE_P (f
))
6013 register struct window
*w
;
6014 register struct saved_window
*p
;
6015 struct window
*root_window
;
6016 struct window
**leaf_windows
;
6020 /* If the frame has been resized since this window configuration was
6021 made, we change the frame to the size specified in the
6022 configuration, restore the configuration, and then resize it
6023 back. We keep track of the prevailing height in these variables. */
6024 int previous_frame_lines
= FRAME_LINES (f
);
6025 int previous_frame_cols
= FRAME_COLS (f
);
6026 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6027 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6029 /* The mouse highlighting code could get screwed up
6030 if it runs during this. */
6033 if (data
->frame_lines
!= previous_frame_lines
6034 || data
->frame_cols
!= previous_frame_cols
)
6035 change_frame_size (f
, data
->frame_lines
,
6036 data
->frame_cols
, 0, 0, 0);
6037 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
6038 if (data
->frame_menu_bar_lines
6039 != previous_frame_menu_bar_lines
)
6040 x_set_menu_bar_lines (f
, make_number (data
->frame_menu_bar_lines
),
6042 #ifdef HAVE_WINDOW_SYSTEM
6043 if (data
->frame_tool_bar_lines
6044 != previous_frame_tool_bar_lines
)
6045 x_set_tool_bar_lines (f
, make_number (data
->frame_tool_bar_lines
),
6050 /* "Swap out" point from the selected window's buffer
6051 into the window itself. (Normally the pointm of the selected
6052 window holds garbage.) We do this now, before
6053 restoring the window contents, and prevent it from
6054 being done later on when we select a new window. */
6055 if (! NILP (XWINDOW (selected_window
)->buffer
))
6057 w
= XWINDOW (selected_window
);
6058 set_marker_both (w
->pointm
,
6060 BUF_PT (XBUFFER (w
->buffer
)),
6061 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6064 windows_or_buffers_changed
++;
6065 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
6067 /* Problem: Freeing all matrices and later allocating them again
6068 is a serious redisplay flickering problem. What we would
6069 really like to do is to free only those matrices not reused
6071 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6073 = (struct window
**) alloca (count_windows (root_window
)
6074 * sizeof (struct window
*));
6075 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
6078 Mark all windows now on frame as "deleted".
6079 Restoring the new configuration "undeletes" any that are in it.
6081 Save their current buffers in their height fields, since we may
6082 need it later, if a buffer saved in the configuration is now
6084 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6086 for (k
= 0; k
< saved_windows
->size
; k
++)
6088 p
= SAVED_WINDOW_N (saved_windows
, k
);
6089 w
= XWINDOW (p
->window
);
6092 if (!NILP (p
->parent
))
6093 w
->parent
= SAVED_WINDOW_N (saved_windows
,
6094 XFASTINT (p
->parent
))->window
;
6098 if (!NILP (p
->prev
))
6100 w
->prev
= SAVED_WINDOW_N (saved_windows
,
6101 XFASTINT (p
->prev
))->window
;
6102 XWINDOW (w
->prev
)->next
= p
->window
;
6107 if (!NILP (w
->parent
))
6109 if (EQ (p
->total_cols
, XWINDOW (w
->parent
)->total_cols
))
6111 XWINDOW (w
->parent
)->vchild
= p
->window
;
6112 XWINDOW (w
->parent
)->hchild
= Qnil
;
6116 XWINDOW (w
->parent
)->hchild
= p
->window
;
6117 XWINDOW (w
->parent
)->vchild
= Qnil
;
6122 /* If we squirreled away the buffer in the window's height,
6124 if (BUFFERP (w
->total_lines
))
6125 w
->buffer
= w
->total_lines
;
6126 w
->left_col
= p
->left_col
;
6127 w
->top_line
= p
->top_line
;
6128 w
->total_cols
= p
->total_cols
;
6129 w
->total_lines
= p
->total_lines
;
6130 w
->hscroll
= p
->hscroll
;
6131 w
->min_hscroll
= p
->min_hscroll
;
6132 w
->display_table
= p
->display_table
;
6133 w
->orig_top_line
= p
->orig_top_line
;
6134 w
->orig_total_lines
= p
->orig_total_lines
;
6135 w
->left_margin_cols
= p
->left_margin_cols
;
6136 w
->right_margin_cols
= p
->right_margin_cols
;
6137 w
->left_fringe_width
= p
->left_fringe_width
;
6138 w
->right_fringe_width
= p
->right_fringe_width
;
6139 w
->fringes_outside_margins
= p
->fringes_outside_margins
;
6140 w
->scroll_bar_width
= p
->scroll_bar_width
;
6141 w
->vertical_scroll_bar_type
= p
->vertical_scroll_bar_type
;
6142 w
->dedicated
= p
->dedicated
;
6143 w
->resize_proportionally
= p
->resize_proportionally
;
6144 XSETFASTINT (w
->last_modified
, 0);
6145 XSETFASTINT (w
->last_overlay_modified
, 0);
6147 /* Reinstall the saved buffer and pointers into it. */
6148 if (NILP (p
->buffer
))
6149 w
->buffer
= p
->buffer
;
6152 if (!NILP (XBUFFER (p
->buffer
)->name
))
6153 /* If saved buffer is alive, install it. */
6155 w
->buffer
= p
->buffer
;
6156 w
->start_at_line_beg
= p
->start_at_line_beg
;
6157 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
6158 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
6159 Fset_marker (XBUFFER (w
->buffer
)->mark
,
6160 p
->mark
, w
->buffer
);
6162 /* As documented in Fcurrent_window_configuration, don't
6163 restore the location of point in the buffer which was
6164 current when the window configuration was recorded. */
6165 if (!EQ (p
->buffer
, new_current_buffer
)
6166 && XBUFFER (p
->buffer
) == current_buffer
)
6167 Fgoto_char (w
->pointm
);
6169 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
6170 /* Else unless window has a live buffer, get one. */
6172 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
6173 /* This will set the markers to beginning of visible
6175 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
6176 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
6177 w
->start_at_line_beg
= Qt
;
6180 /* Keeping window's old buffer; make sure the markers
6183 /* Set window markers at start of visible range. */
6184 if (XMARKER (w
->start
)->buffer
== 0)
6185 set_marker_restricted (w
->start
, make_number (0),
6187 if (XMARKER (w
->pointm
)->buffer
== 0)
6188 set_marker_restricted_both (w
->pointm
, w
->buffer
,
6189 BUF_PT (XBUFFER (w
->buffer
)),
6190 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6191 w
->start_at_line_beg
= Qt
;
6196 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
6197 /* Prevent "swapping out point" in the old selected window
6198 using the buffer that has been restored into it.
6199 We already swapped out point that from that window's old buffer. */
6200 selected_window
= Qnil
;
6202 /* Arrange *not* to restore point in the buffer that was
6203 current when the window configuration was saved. */
6204 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
6205 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
6206 make_number (old_point
),
6207 XWINDOW (data
->current_window
)->buffer
);
6209 Fselect_window (data
->current_window
, Qnil
);
6210 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
6213 if (NILP (data
->focus_frame
)
6214 || (FRAMEP (data
->focus_frame
)
6215 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
6216 Fredirect_frame_focus (frame
, data
->focus_frame
);
6218 #if 0 /* I don't understand why this is needed, and it causes problems
6219 when the frame's old selected window has been deleted. */
6220 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
6221 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
6225 /* Set the screen height to the value it had before this function. */
6226 if (previous_frame_lines
!= FRAME_LINES (f
)
6227 || previous_frame_cols
!= FRAME_COLS (f
))
6228 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
6230 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
6231 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
6232 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
6234 #ifdef HAVE_WINDOW_SYSTEM
6235 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
6236 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
6241 /* Now, free glyph matrices in windows that were not reused. */
6242 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
6244 if (NILP (leaf_windows
[i
]->buffer
))
6246 /* Assert it's not reused as a combination. */
6247 xassert (NILP (leaf_windows
[i
]->hchild
)
6248 && NILP (leaf_windows
[i
]->vchild
));
6249 free_window_matrices (leaf_windows
[i
]);
6251 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
6259 /* Fselect_window will have made f the selected frame, so we
6260 reselect the proper frame here. Fhandle_switch_frame will change the
6261 selected window too, but that doesn't make the call to
6262 Fselect_window above totally superfluous; it still sets f's
6264 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
6265 do_switch_frame (data
->selected_frame
, 0, 0, Qnil
);
6267 run_window_configuration_change_hook (f
);
6270 if (!NILP (new_current_buffer
))
6271 Fset_buffer (new_current_buffer
);
6273 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
6274 minibuf_selected_window
= data
->minibuf_selected_window
;
6276 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
6279 /* Mark all windows now on frame as deleted
6280 by setting their buffers to nil. */
6283 delete_all_subwindows (w
)
6284 register struct window
*w
;
6286 if (!NILP (w
->next
))
6287 delete_all_subwindows (XWINDOW (w
->next
));
6288 if (!NILP (w
->vchild
))
6289 delete_all_subwindows (XWINDOW (w
->vchild
));
6290 if (!NILP (w
->hchild
))
6291 delete_all_subwindows (XWINDOW (w
->hchild
));
6293 w
->total_lines
= w
->buffer
; /* See Fset_window_configuration for excuse. */
6295 if (!NILP (w
->buffer
))
6298 /* We set all three of these fields to nil, to make sure that we can
6299 distinguish this dead window from any live window. Live leaf
6300 windows will have buffer set, and combination windows will have
6301 vchild or hchild set. */
6306 Vwindow_list
= Qnil
;
6310 count_windows (window
)
6311 register struct window
*window
;
6313 register int count
= 1;
6314 if (!NILP (window
->next
))
6315 count
+= count_windows (XWINDOW (window
->next
));
6316 if (!NILP (window
->vchild
))
6317 count
+= count_windows (XWINDOW (window
->vchild
));
6318 if (!NILP (window
->hchild
))
6319 count
+= count_windows (XWINDOW (window
->hchild
));
6324 /* Fill vector FLAT with leaf windows under W, starting at index I.
6325 Value is last index + 1. */
6328 get_leaf_windows (w
, flat
, i
)
6330 struct window
**flat
;
6335 if (!NILP (w
->hchild
))
6336 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
6337 else if (!NILP (w
->vchild
))
6338 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
6342 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6349 /* Return a pointer to the glyph W's physical cursor is on. Value is
6350 null if W's current matrix is invalid, so that no meaningfull glyph
6354 get_phys_cursor_glyph (w
)
6357 struct glyph_row
*row
;
6358 struct glyph
*glyph
;
6360 if (w
->phys_cursor
.vpos
>= 0
6361 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
6362 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
6364 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
6365 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
6374 save_window_save (window
, vector
, i
)
6376 struct Lisp_Vector
*vector
;
6379 register struct saved_window
*p
;
6380 register struct window
*w
;
6381 register Lisp_Object tem
;
6383 for (;!NILP (window
); window
= w
->next
)
6385 p
= SAVED_WINDOW_N (vector
, i
);
6386 w
= XWINDOW (window
);
6388 XSETFASTINT (w
->temslot
, i
); i
++;
6390 p
->buffer
= w
->buffer
;
6391 p
->left_col
= w
->left_col
;
6392 p
->top_line
= w
->top_line
;
6393 p
->total_cols
= w
->total_cols
;
6394 p
->total_lines
= w
->total_lines
;
6395 p
->hscroll
= w
->hscroll
;
6396 p
->min_hscroll
= w
->min_hscroll
;
6397 p
->display_table
= w
->display_table
;
6398 p
->orig_top_line
= w
->orig_top_line
;
6399 p
->orig_total_lines
= w
->orig_total_lines
;
6400 p
->left_margin_cols
= w
->left_margin_cols
;
6401 p
->right_margin_cols
= w
->right_margin_cols
;
6402 p
->left_fringe_width
= w
->left_fringe_width
;
6403 p
->right_fringe_width
= w
->right_fringe_width
;
6404 p
->fringes_outside_margins
= w
->fringes_outside_margins
;
6405 p
->scroll_bar_width
= w
->scroll_bar_width
;
6406 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
6407 p
->dedicated
= w
->dedicated
;
6408 p
->resize_proportionally
= w
->resize_proportionally
;
6409 if (!NILP (w
->buffer
))
6411 /* Save w's value of point in the window configuration.
6412 If w is the selected window, then get the value of point
6413 from the buffer; pointm is garbage in the selected window. */
6414 if (EQ (window
, selected_window
))
6416 p
->pointm
= Fmake_marker ();
6417 set_marker_both (p
->pointm
, w
->buffer
,
6418 BUF_PT (XBUFFER (w
->buffer
)),
6419 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6422 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
6424 p
->start
= Fcopy_marker (w
->start
, Qnil
);
6425 p
->start_at_line_beg
= w
->start_at_line_beg
;
6427 tem
= XBUFFER (w
->buffer
)->mark
;
6428 p
->mark
= Fcopy_marker (tem
, Qnil
);
6435 p
->start_at_line_beg
= Qnil
;
6438 if (NILP (w
->parent
))
6441 p
->parent
= XWINDOW (w
->parent
)->temslot
;
6446 p
->prev
= XWINDOW (w
->prev
)->temslot
;
6448 if (!NILP (w
->vchild
))
6449 i
= save_window_save (w
->vchild
, vector
, i
);
6450 if (!NILP (w
->hchild
))
6451 i
= save_window_save (w
->hchild
, vector
, i
);
6457 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
6458 Scurrent_window_configuration
, 0, 1, 0,
6459 doc
: /* Return an object representing the current window configuration of FRAME.
6460 If FRAME is nil or omitted, use the selected frame.
6461 This describes the number of windows, their sizes and current buffers,
6462 and for each displayed buffer, where display starts, and the positions of
6463 point and mark. An exception is made for point in the current buffer:
6464 its value is -not- saved.
6465 This also records the currently selected frame, and FRAME's focus
6466 redirection (see `redirect-frame-focus'). */)
6470 register Lisp_Object tem
;
6471 register int n_windows
;
6472 register struct save_window_data
*data
;
6477 frame
= selected_frame
;
6478 CHECK_LIVE_FRAME (frame
);
6481 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6482 data
= ALLOCATE_PSEUDOVECTOR (struct save_window_data
, frame_cols
,
6483 PVEC_WINDOW_CONFIGURATION
);
6485 data
->frame_cols
= FRAME_COLS (f
);
6486 data
->frame_lines
= FRAME_LINES (f
);
6487 data
->frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6488 data
->frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6489 data
->selected_frame
= selected_frame
;
6490 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6491 XSETBUFFER (data
->current_buffer
, current_buffer
);
6492 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6493 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6494 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6495 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6496 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
6497 data
->saved_windows
= tem
;
6498 for (i
= 0; i
< n_windows
; i
++)
6499 XVECTOR (tem
)->contents
[i
]
6500 = Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
);
6501 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6502 XSETWINDOW_CONFIGURATION (tem
, data
);
6506 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
6508 doc
: /* Execute BODY, preserving window sizes and contents.
6509 Return the value of the last form in BODY.
6510 Restore which buffer appears in which window, where display starts,
6511 and the value of point and mark for each window.
6512 Also restore the choice of selected window.
6513 Also restore which buffer is current.
6514 Does not restore the value of point in current buffer.
6515 usage: (save-window-excursion BODY...) */)
6519 register Lisp_Object val
;
6520 register int count
= SPECPDL_INDEX ();
6522 record_unwind_protect (Fset_window_configuration
,
6523 Fcurrent_window_configuration (Qnil
));
6524 val
= Fprogn (args
);
6525 return unbind_to (count
, val
);
6530 /***********************************************************************
6532 ***********************************************************************/
6538 Lisp_Object tail
= Qnil
;
6539 Lisp_Object result
= Qnil
;
6546 if (!NILP (w
->hchild
))
6547 wn
= Fcons (Qnil
, Fcons (Fwindow_edges (wn
),
6548 window_tree (XWINDOW (w
->hchild
))));
6549 else if (!NILP (w
->vchild
))
6550 wn
= Fcons (Qt
, Fcons (Fwindow_edges (wn
),
6551 window_tree (XWINDOW (w
->vchild
))));
6555 result
= tail
= Fcons (wn
, Qnil
);
6559 XSETCDR (tail
, Fcons (wn
, Qnil
));
6563 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6571 DEFUN ("window-tree", Fwindow_tree
, Swindow_tree
,
6573 doc
: /* Return the window tree for frame FRAME.
6575 The return value is a list of the form (ROOT MINI), where ROOT
6576 represents the window tree of the frame's root window, and MINI
6577 is the frame's minibuffer window.
6579 If the root window is not split, ROOT is the root window itself.
6580 Otherwise, ROOT is a list (DIR EDGES W1 W2 ...) where DIR is nil for a
6581 horizontal split, and t for a vertical split, EDGES gives the combined
6582 size and position of the subwindows in the split, and the rest of the
6583 elements are the subwindows in the split. Each of the subwindows may
6584 again be a window or a list representing a window split, and so on.
6585 EDGES is a list \(LEFT TOP RIGHT BOTTOM) as returned by `window-edges'.
6587 If FRAME is nil or omitted, return information on the currently
6595 frame
= selected_frame
;
6597 CHECK_FRAME (frame
);
6600 if (!FRAME_LIVE_P (f
))
6603 return window_tree (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6607 /***********************************************************************
6609 ***********************************************************************/
6611 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6613 doc
: /* Set width of marginal areas of window WINDOW.
6614 If WINDOW is nil, set margins of the currently selected window.
6615 Second arg LEFT-WIDTH specifies the number of character cells to
6616 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6617 does the same for the right marginal area. A nil width parameter
6618 means no margin. */)
6619 (window
, left_width
, right_width
)
6620 Lisp_Object window
, left_width
, right_width
;
6622 struct window
*w
= decode_window (window
);
6624 /* Translate negative or zero widths to nil.
6625 Margins that are too wide have to be checked elsewhere. */
6627 if (!NILP (left_width
))
6629 CHECK_NUMBER (left_width
);
6630 if (XINT (left_width
) <= 0)
6634 if (!NILP (right_width
))
6636 CHECK_NUMBER (right_width
);
6637 if (XINT (right_width
) <= 0)
6641 if (!EQ (w
->left_margin_cols
, left_width
)
6642 || !EQ (w
->right_margin_cols
, right_width
))
6644 w
->left_margin_cols
= left_width
;
6645 w
->right_margin_cols
= right_width
;
6647 adjust_window_margins (w
);
6649 ++windows_or_buffers_changed
;
6650 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6657 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6659 doc
: /* Get width of marginal areas of window WINDOW.
6660 If WINDOW is omitted or nil, use the currently selected window.
6661 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6662 If a marginal area does not exist, its width will be returned
6667 struct window
*w
= decode_window (window
);
6668 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
6673 /***********************************************************************
6675 ***********************************************************************/
6677 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6679 doc
: /* Set the fringe widths of window WINDOW.
6680 If WINDOW is nil, set the fringe widths of the currently selected
6682 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6683 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6684 fringe width. If a fringe width arg is nil, that means to use the
6685 frame's default fringe width. Default fringe widths can be set with
6686 the command `set-fringe-style'.
6687 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6688 outside of the display margins. By default, fringes are drawn between
6689 display marginal areas and the text area. */)
6690 (window
, left_width
, right_width
, outside_margins
)
6691 Lisp_Object window
, left_width
, right_width
, outside_margins
;
6693 struct window
*w
= decode_window (window
);
6695 if (!NILP (left_width
))
6696 CHECK_NATNUM (left_width
);
6697 if (!NILP (right_width
))
6698 CHECK_NATNUM (right_width
);
6700 /* Do nothing on a tty. */
6701 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6702 && (!EQ (w
->left_fringe_width
, left_width
)
6703 || !EQ (w
->right_fringe_width
, right_width
)
6704 || !EQ (w
->fringes_outside_margins
, outside_margins
)))
6706 w
->left_fringe_width
= left_width
;
6707 w
->right_fringe_width
= right_width
;
6708 w
->fringes_outside_margins
= outside_margins
;
6710 adjust_window_margins (w
);
6712 clear_glyph_matrix (w
->current_matrix
);
6713 w
->window_end_valid
= Qnil
;
6715 ++windows_or_buffers_changed
;
6716 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6723 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6725 doc
: /* Get width of fringes of window WINDOW.
6726 If WINDOW is omitted or nil, use the currently selected window.
6727 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6731 struct window
*w
= decode_window (window
);
6733 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6734 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6735 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
6736 ? Qt
: Qnil
), Qnil
)));
6741 /***********************************************************************
6743 ***********************************************************************/
6745 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
, Sset_window_scroll_bars
,
6747 doc
: /* Set width and type of scroll bars of window WINDOW.
6748 If window is nil, set scroll bars of the currently selected window.
6749 Second parameter WIDTH specifies the pixel width for the scroll bar;
6750 this is automatically adjusted to a multiple of the frame column width.
6751 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6752 bar: left, right, or nil.
6753 If WIDTH is nil, use the frame's scroll-bar width.
6754 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6755 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6756 (window
, width
, vertical_type
, horizontal_type
)
6757 Lisp_Object window
, width
, vertical_type
, horizontal_type
;
6759 struct window
*w
= decode_window (window
);
6763 CHECK_NATNUM (width
);
6765 if (XINT (width
) == 0)
6766 vertical_type
= Qnil
;
6769 if (!(NILP (vertical_type
)
6770 || EQ (vertical_type
, Qleft
)
6771 || EQ (vertical_type
, Qright
)
6772 || EQ (vertical_type
, Qt
)))
6773 error ("Invalid type of vertical scroll bar");
6775 if (!EQ (w
->scroll_bar_width
, width
)
6776 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6778 w
->scroll_bar_width
= width
;
6779 w
->vertical_scroll_bar_type
= vertical_type
;
6781 adjust_window_margins (w
);
6783 clear_glyph_matrix (w
->current_matrix
);
6784 w
->window_end_valid
= Qnil
;
6786 ++windows_or_buffers_changed
;
6787 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6794 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6796 doc
: /* Get width and type of scroll bars of window WINDOW.
6797 If WINDOW is omitted or nil, use the currently selected window.
6798 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6799 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6804 struct window
*w
= decode_window (window
);
6805 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6806 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6807 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6808 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6809 Fcons (w
->vertical_scroll_bar_type
,
6810 Fcons (Qnil
, Qnil
))));
6815 /***********************************************************************
6817 ***********************************************************************/
6819 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6820 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6821 Use the selected window if WINDOW is nil or omitted.
6822 Normally, value is a multiple of the canonical character height of WINDOW;
6823 optional second arg PIXELS-P means value is measured in pixels. */)
6825 Lisp_Object window
, pixels_p
;
6832 window
= selected_window
;
6834 CHECK_WINDOW (window
);
6835 w
= XWINDOW (window
);
6836 f
= XFRAME (w
->frame
);
6838 if (FRAME_WINDOW_P (f
))
6839 result
= (NILP (pixels_p
)
6840 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6841 : make_number (-w
->vscroll
));
6843 result
= make_number (0);
6848 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6850 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6851 WINDOW nil means use the selected window. Normally, VSCROLL is a
6852 non-negative multiple of the canonical character height of WINDOW;
6853 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
6854 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6855 corresponds to an integral number of pixels. The return value is the
6856 result of this rounding.
6857 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6858 (window
, vscroll
, pixels_p
)
6859 Lisp_Object window
, vscroll
, pixels_p
;
6865 window
= selected_window
;
6867 CHECK_WINDOW (window
);
6868 CHECK_NUMBER_OR_FLOAT (vscroll
);
6870 w
= XWINDOW (window
);
6871 f
= XFRAME (w
->frame
);
6873 if (FRAME_WINDOW_P (f
))
6875 int old_dy
= w
->vscroll
;
6877 w
->vscroll
= - (NILP (pixels_p
)
6878 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
6879 : XFLOATINT (vscroll
));
6880 w
->vscroll
= min (w
->vscroll
, 0);
6882 if (w
->vscroll
!= old_dy
)
6884 /* Adjust glyph matrix of the frame if the virtual display
6885 area becomes larger than before. */
6886 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
6889 /* Prevent redisplay shortcuts. */
6890 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
6894 return Fwindow_vscroll (window
, pixels_p
);
6898 /* Call FN for all leaf windows on frame F. FN is called with the
6899 first argument being a pointer to the leaf window, and with
6900 additional argument USER_DATA. Stops when FN returns 0. */
6903 foreach_window (f
, fn
, user_data
)
6905 int (* fn
) P_ ((struct window
*, void *));
6908 /* Fdelete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
6909 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
6910 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
6914 /* Helper function for foreach_window. Call FN for all leaf windows
6915 reachable from W. FN is called with the first argument being a
6916 pointer to the leaf window, and with additional argument USER_DATA.
6917 Stop when FN returns 0. Value is 0 if stopped by FN. */
6920 foreach_window_1 (w
, fn
, user_data
)
6922 int (* fn
) P_ ((struct window
*, void *));
6927 for (cont
= 1; w
&& cont
;)
6929 if (!NILP (w
->hchild
))
6930 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
6931 else if (!NILP (w
->vchild
))
6932 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
6934 cont
= fn (w
, user_data
);
6936 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6943 /* Freeze or unfreeze the window start of W unless it is a
6944 mini-window or the selected window. FREEZE_P non-null means freeze
6945 the window start. */
6948 freeze_window_start (w
, freeze_p
)
6952 if (MINI_WINDOW_P (w
)
6953 || (WINDOWP (selected_window
) /* Can be nil in corner cases. */
6954 && (w
== XWINDOW (selected_window
)
6955 || (MINI_WINDOW_P (XWINDOW (selected_window
))
6956 && ! NILP (Vminibuf_scroll_window
)
6957 && w
== XWINDOW (Vminibuf_scroll_window
)))))
6960 w
->frozen_window_start_p
= freeze_p
!= NULL
;
6965 /* Freeze or unfreeze the window starts of all leaf windows on frame
6966 F, except the selected window and a mini-window. FREEZE_P non-zero
6967 means freeze the window start. */
6970 freeze_window_starts (f
, freeze_p
)
6974 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
6978 /***********************************************************************
6980 ***********************************************************************/
6982 /* Return 1 if window configurations C1 and C2
6983 describe the same state of affairs. This is used by Fequal. */
6986 compare_window_configurations (c1
, c2
, ignore_positions
)
6988 int ignore_positions
;
6990 register struct save_window_data
*d1
, *d2
;
6991 struct Lisp_Vector
*sw1
, *sw2
;
6994 CHECK_WINDOW_CONFIGURATION (c1
);
6995 CHECK_WINDOW_CONFIGURATION (c2
);
6997 d1
= (struct save_window_data
*) XVECTOR (c1
);
6998 d2
= (struct save_window_data
*) XVECTOR (c2
);
6999 sw1
= XVECTOR (d1
->saved_windows
);
7000 sw2
= XVECTOR (d2
->saved_windows
);
7002 if (d1
->frame_cols
!= d2
->frame_cols
)
7004 if (d1
->frame_lines
!= d2
->frame_lines
)
7006 if (d1
->frame_menu_bar_lines
!= d2
->frame_menu_bar_lines
)
7008 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
7010 /* Don't compare the current_window field directly.
7011 Instead see w1_is_current and w2_is_current, below. */
7012 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
7014 if (! ignore_positions
)
7016 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
7018 if (! EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
))
7021 /* Don't compare the root_window field.
7022 We don't require the two configurations
7023 to use the same window object,
7024 and the two root windows must be equivalent
7025 if everything else compares equal. */
7026 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
7029 /* Verify that the two confis have the same number of windows. */
7030 if (sw1
->size
!= sw2
->size
)
7033 for (i
= 0; i
< sw1
->size
; i
++)
7035 struct saved_window
*p1
, *p2
;
7036 int w1_is_current
, w2_is_current
;
7038 p1
= SAVED_WINDOW_N (sw1
, i
);
7039 p2
= SAVED_WINDOW_N (sw2
, i
);
7041 /* Verify that the current windows in the two
7042 configurations correspond to each other. */
7043 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
7044 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
7046 if (w1_is_current
!= w2_is_current
)
7049 /* Verify that the corresponding windows do match. */
7050 if (! EQ (p1
->buffer
, p2
->buffer
))
7052 if (! EQ (p1
->left_col
, p2
->left_col
))
7054 if (! EQ (p1
->top_line
, p2
->top_line
))
7056 if (! EQ (p1
->total_cols
, p2
->total_cols
))
7058 if (! EQ (p1
->total_lines
, p2
->total_lines
))
7060 if (! EQ (p1
->display_table
, p2
->display_table
))
7062 if (! EQ (p1
->parent
, p2
->parent
))
7064 if (! EQ (p1
->prev
, p2
->prev
))
7066 if (! ignore_positions
)
7068 if (! EQ (p1
->hscroll
, p2
->hscroll
))
7070 if (!EQ (p1
->min_hscroll
, p2
->min_hscroll
))
7072 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
7074 if (NILP (Fequal (p1
->start
, p2
->start
)))
7076 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
7078 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
7081 if (! EQ (p1
->left_margin_cols
, p2
->left_margin_cols
))
7083 if (! EQ (p1
->right_margin_cols
, p2
->right_margin_cols
))
7085 if (! EQ (p1
->left_fringe_width
, p2
->left_fringe_width
))
7087 if (! EQ (p1
->right_fringe_width
, p2
->right_fringe_width
))
7089 if (! EQ (p1
->fringes_outside_margins
, p2
->fringes_outside_margins
))
7091 if (! EQ (p1
->scroll_bar_width
, p2
->scroll_bar_width
))
7093 if (! EQ (p1
->vertical_scroll_bar_type
, p2
->vertical_scroll_bar_type
))
7100 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
7101 Scompare_window_configurations
, 2, 2, 0,
7102 doc
: /* Compare two window configurations as regards the structure of windows.
7103 This function ignores details such as the values of point and mark
7104 and scrolling positions. */)
7108 if (compare_window_configurations (x
, y
, 1))
7116 struct frame
*f
= make_initial_frame ();
7117 XSETFRAME (selected_frame
, f
);
7118 Vterminal_frame
= selected_frame
;
7119 minibuf_window
= f
->minibuffer_window
;
7120 selected_window
= f
->selected_window
;
7121 last_nonminibuf_frame
= f
;
7123 window_initialized
= 1;
7129 Vwindow_list
= Qnil
;
7135 Qscroll_up
= intern ("scroll-up");
7136 staticpro (&Qscroll_up
);
7138 Qscroll_down
= intern ("scroll-down");
7139 staticpro (&Qscroll_down
);
7141 Qwindow_size_fixed
= intern ("window-size-fixed");
7142 staticpro (&Qwindow_size_fixed
);
7143 Fset (Qwindow_size_fixed
, Qnil
);
7145 staticpro (&Qwindow_configuration_change_hook
);
7146 Qwindow_configuration_change_hook
7147 = intern ("window-configuration-change-hook");
7149 Qwindowp
= intern ("windowp");
7150 staticpro (&Qwindowp
);
7152 Qwindow_configuration_p
= intern ("window-configuration-p");
7153 staticpro (&Qwindow_configuration_p
);
7155 Qwindow_live_p
= intern ("window-live-p");
7156 staticpro (&Qwindow_live_p
);
7158 Qdisplay_buffer
= intern ("display-buffer");
7159 staticpro (&Qdisplay_buffer
);
7161 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
7162 staticpro (&Qtemp_buffer_show_hook
);
7164 staticpro (&Vwindow_list
);
7166 minibuf_selected_window
= Qnil
;
7167 staticpro (&minibuf_selected_window
);
7169 window_scroll_pixel_based_preserve_x
= -1;
7170 window_scroll_pixel_based_preserve_y
= -1;
7171 window_scroll_preserve_hpos
= -1;
7172 window_scroll_preserve_vpos
= -1;
7174 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
7175 doc
: /* Non-nil means call as function to display a help buffer.
7176 The function is called with one argument, the buffer to be displayed.
7177 Used by `with-output-to-temp-buffer'.
7178 If this function is used, then it must do the entire job of showing
7179 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
7180 Vtemp_buffer_show_function
= Qnil
;
7182 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
7183 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
7184 Vminibuf_scroll_window
= Qnil
;
7186 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows
,
7187 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
7188 If the minibuffer is active, the `minibuffer-scroll-window' mode line
7189 is displayed in the `mode-line' face. */);
7190 mode_line_in_non_selected_windows
= 1;
7192 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
7193 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
7194 Vother_window_scroll_buffer
= Qnil
;
7196 DEFVAR_BOOL ("auto-window-vscroll", &auto_window_vscroll_p
,
7197 doc
: /* *Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
7198 auto_window_vscroll_p
= 1;
7200 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
7201 doc
: /* *Number of lines of continuity when scrolling by screenfuls. */);
7202 next_screen_context_lines
= 2;
7204 DEFVAR_INT ("window-min-height", &window_min_height
,
7205 doc
: /* Allow deleting windows less than this tall.
7206 The value is measured in line units. If a window wants a modeline it
7207 is counted as one line.
7209 Emacs honors settings of this variable when enlarging or shrinking
7210 windows vertically. A value less than 1 is invalid. */);
7211 window_min_height
= 4;
7213 DEFVAR_INT ("window-min-width", &window_min_width
,
7214 doc
: /* Allow deleting windows less than this wide.
7215 The value is measured in characters and includes any fringes or
7218 Emacs honors settings of this variable when enlarging or shrinking
7219 windows horizontally. A value less than 2 is invalid. */);
7220 window_min_width
= 10;
7222 DEFVAR_LISP ("scroll-preserve-screen-position",
7223 &Vscroll_preserve_screen_position
,
7224 doc
: /* *Controls if scroll commands move point to keep its screen position unchanged.
7225 A value of nil means point does not keep its screen position except
7226 at the scroll margin or window boundary respectively.
7227 A value of t means point keeps its screen position if the scroll
7228 command moved it vertically out of the window, e.g. when scrolling
7230 Any other value means point always keeps its screen position. */);
7231 Vscroll_preserve_screen_position
= Qnil
;
7233 DEFVAR_LISP ("window-point-insertion-type", &Vwindow_point_insertion_type
,
7234 doc
: /* Type of marker to use for `window-point'. */);
7235 Vwindow_point_insertion_type
= Qnil
;
7237 DEFVAR_LISP ("window-configuration-change-hook",
7238 &Vwindow_configuration_change_hook
,
7239 doc
: /* Functions to call when window configuration changes.
7240 The buffer-local part is run once per window, with the relevant window
7241 selected; while the global part is run only once for the modified frame,
7242 with the relevant frame selected. */);
7243 Vwindow_configuration_change_hook
= Qnil
;
7245 defsubr (&Sselected_window
);
7246 defsubr (&Sminibuffer_window
);
7247 defsubr (&Swindow_minibuffer_p
);
7248 defsubr (&Swindowp
);
7249 defsubr (&Swindow_live_p
);
7250 defsubr (&Spos_visible_in_window_p
);
7251 defsubr (&Swindow_line_height
);
7252 defsubr (&Swindow_buffer
);
7253 defsubr (&Swindow_height
);
7254 defsubr (&Swindow_width
);
7255 defsubr (&Swindow_full_width_p
);
7256 defsubr (&Swindow_hscroll
);
7257 defsubr (&Sset_window_hscroll
);
7258 defsubr (&Swindow_redisplay_end_trigger
);
7259 defsubr (&Sset_window_redisplay_end_trigger
);
7260 defsubr (&Swindow_edges
);
7261 defsubr (&Swindow_pixel_edges
);
7262 defsubr (&Swindow_inside_edges
);
7263 defsubr (&Swindow_inside_pixel_edges
);
7264 defsubr (&Scoordinates_in_window_p
);
7265 defsubr (&Swindow_at
);
7266 defsubr (&Swindow_point
);
7267 defsubr (&Swindow_start
);
7268 defsubr (&Swindow_end
);
7269 defsubr (&Sset_window_point
);
7270 defsubr (&Sset_window_start
);
7271 defsubr (&Swindow_dedicated_p
);
7272 defsubr (&Sset_window_dedicated_p
);
7273 defsubr (&Swindow_display_table
);
7274 defsubr (&Sset_window_display_table
);
7275 defsubr (&Snext_window
);
7276 defsubr (&Sprevious_window
);
7277 defsubr (&Sother_window
);
7278 defsubr (&Sget_lru_window
);
7279 defsubr (&Sget_largest_window
);
7280 defsubr (&Sget_buffer_window
);
7281 defsubr (&Sdelete_other_windows
);
7282 defsubr (&Sdelete_windows_on
);
7283 defsubr (&Sreplace_buffer_in_windows
);
7284 defsubr (&Sdelete_window
);
7285 defsubr (&Sset_window_buffer
);
7286 defsubr (&Sselect_window
);
7287 defsubr (&Sforce_window_update
);
7288 defsubr (&Ssplit_window
);
7289 defsubr (&Senlarge_window
);
7290 defsubr (&Sshrink_window
);
7291 defsubr (&Sadjust_window_trailing_edge
);
7292 defsubr (&Sscroll_up
);
7293 defsubr (&Sscroll_down
);
7294 defsubr (&Sscroll_left
);
7295 defsubr (&Sscroll_right
);
7296 defsubr (&Sother_window_for_scrolling
);
7297 defsubr (&Sscroll_other_window
);
7298 defsubr (&Sminibuffer_selected_window
);
7299 defsubr (&Srecenter
);
7300 defsubr (&Swindow_text_height
);
7301 defsubr (&Smove_to_window_line
);
7302 defsubr (&Swindow_configuration_p
);
7303 defsubr (&Swindow_configuration_frame
);
7304 defsubr (&Sset_window_configuration
);
7305 defsubr (&Scurrent_window_configuration
);
7306 defsubr (&Ssave_window_excursion
);
7307 defsubr (&Swindow_tree
);
7308 defsubr (&Sset_window_margins
);
7309 defsubr (&Swindow_margins
);
7310 defsubr (&Sset_window_fringes
);
7311 defsubr (&Swindow_fringes
);
7312 defsubr (&Sset_window_scroll_bars
);
7313 defsubr (&Swindow_scroll_bars
);
7314 defsubr (&Swindow_vscroll
);
7315 defsubr (&Sset_window_vscroll
);
7316 defsubr (&Scompare_window_configurations
);
7317 defsubr (&Swindow_list
);
7318 defsubr (&Swindow_parameters
);
7319 defsubr (&Swindow_parameter
);
7320 defsubr (&Sset_window_parameter
);
7327 initial_define_key (control_x_map
, '1', "delete-other-windows");
7328 initial_define_key (control_x_map
, '2', "split-window");
7329 initial_define_key (control_x_map
, '0', "delete-window");
7330 initial_define_key (control_x_map
, 'o', "other-window");
7331 initial_define_key (control_x_map
, '^', "enlarge-window");
7332 initial_define_key (control_x_map
, '<', "scroll-left");
7333 initial_define_key (control_x_map
, '>', "scroll-right");
7335 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
7336 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
7337 initial_define_key (meta_map
, 'v', "scroll-down");
7339 initial_define_key (global_map
, Ctl('L'), "recenter");
7340 initial_define_key (meta_map
, 'r', "move-to-window-line");
7343 /* arch-tag: 90a9c576-0590-48f1-a5f1-6c96a0452d9f
7344 (do not change this comment) */