1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985,86,87,93,94,95,96,97,1998,2000, 2001, 2002, 2003
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
34 #include "dispextern.h"
35 #include "blockinput.h"
36 #include "intervals.h"
40 #endif /* HAVE_X_WINDOWS */
52 Lisp_Object Qwindowp
, Qwindow_live_p
, Qwindow_configuration_p
;
53 Lisp_Object Qwindow_size_fixed
;
54 extern Lisp_Object Qleft_margin
, Qright_margin
;
56 static int displayed_window_lines
P_ ((struct window
*));
57 static struct window
*decode_window
P_ ((Lisp_Object
));
58 static int count_windows
P_ ((struct window
*));
59 static int get_leaf_windows
P_ ((struct window
*, struct window
**, int));
60 static void window_scroll
P_ ((Lisp_Object
, int, int, int));
61 static void window_scroll_pixel_based
P_ ((Lisp_Object
, int, int, int));
62 static void window_scroll_line_based
P_ ((Lisp_Object
, int, int, int));
63 static int window_min_size_1
P_ ((struct window
*, int));
64 static int window_min_size
P_ ((struct window
*, int, int, int *));
65 static void size_window
P_ ((Lisp_Object
, int, int, int));
66 static int freeze_window_start
P_ ((struct window
*, void *));
67 static int window_fixed_size_p
P_ ((struct window
*, int, int));
68 static void enlarge_window
P_ ((Lisp_Object
, int, int, int));
69 static Lisp_Object window_list
P_ ((void));
70 static int add_window_to_list
P_ ((struct window
*, void *));
71 static int candidate_window_p
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
73 static Lisp_Object next_window
P_ ((Lisp_Object
, Lisp_Object
,
75 static void decode_next_window_args
P_ ((Lisp_Object
*, Lisp_Object
*,
77 static int foreach_window_1
P_ ((struct window
*,
78 int (* fn
) (struct window
*, void *),
80 static Lisp_Object window_list_1
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
82 /* The value of `window-size-fixed'. */
84 int window_size_fixed
;
86 /* This is the window in which the terminal's cursor should
87 be left when nothing is being done with it. This must
88 always be a leaf window, and its buffer is selected by
89 the top level editing loop at the end of each command.
91 This value is always the same as
92 FRAME_SELECTED_WINDOW (selected_frame). */
94 Lisp_Object selected_window
;
96 /* A list of all windows for use by next_window and Fwindow_list.
97 Functions creating or deleting windows should invalidate this cache
98 by setting it to nil. */
100 Lisp_Object Vwindow_list
;
102 /* The mini-buffer window of the selected frame.
103 Note that you cannot test for mini-bufferness of an arbitrary window
104 by comparing against this; but you can test for mini-bufferness of
105 the selected window. */
107 Lisp_Object minibuf_window
;
109 /* Non-nil means it is the window whose mode line should be
110 shown as the selected window when the minibuffer is selected. */
112 Lisp_Object minibuf_selected_window
;
114 /* Non-nil means it is the window for C-M-v to scroll
115 when the mini-buffer is selected. */
117 Lisp_Object Vminibuf_scroll_window
;
119 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
121 Lisp_Object Vother_window_scroll_buffer
;
123 /* Non-nil means it's function to call to display temp buffers. */
125 Lisp_Object Vtemp_buffer_show_function
;
127 /* Non-zero means to use mode-line-inactive face in all windows but the
128 selected-window and the minibuffer-scroll-window when the
129 minibuffer is active. */
130 int mode_line_in_non_selected_windows
;
132 /* If a window gets smaller than either of these, it is removed. */
134 EMACS_INT window_min_height
;
135 EMACS_INT window_min_width
;
137 /* Nonzero implies Fdisplay_buffer should create windows. */
141 /* Nonzero implies make new frames for Fdisplay_buffer. */
145 /* Nonzero means reuse existing frames for displaying buffers. */
147 int display_buffer_reuse_frames
;
149 /* Non-nil means use this function instead of default */
151 Lisp_Object Vpop_up_frame_function
;
153 /* Function to call to handle Fdisplay_buffer. */
155 Lisp_Object Vdisplay_buffer_function
;
157 /* Non-nil means that Fdisplay_buffer should even the heights of windows. */
159 Lisp_Object Veven_window_heights
;
161 /* List of buffer *names* for buffers that should have their own frames. */
163 Lisp_Object Vspecial_display_buffer_names
;
165 /* List of regexps for buffer names that should have their own frames. */
167 Lisp_Object Vspecial_display_regexps
;
169 /* Function to pop up a special frame. */
171 Lisp_Object Vspecial_display_function
;
173 /* List of buffer *names* for buffers to appear in selected window. */
175 Lisp_Object Vsame_window_buffer_names
;
177 /* List of regexps for buffer names to appear in selected window. */
179 Lisp_Object Vsame_window_regexps
;
181 /* Hook run at end of temp_output_buffer_show. */
183 Lisp_Object Qtemp_buffer_show_hook
;
185 /* Fdisplay_buffer always splits the largest window
186 if that window is more than this high. */
188 EMACS_INT split_height_threshold
;
190 /* Number of lines of continuity in scrolling by screenfuls. */
192 EMACS_INT next_screen_context_lines
;
194 /* Incremented for each window created. */
196 static int sequence_number
;
198 /* Nonzero after init_window_once has finished. */
200 static int window_initialized
;
202 /* Hook to run when window config changes. */
204 Lisp_Object Qwindow_configuration_change_hook
;
205 Lisp_Object Vwindow_configuration_change_hook
;
207 /* Nonzero means scroll commands try to put point
208 at the same screen height as previously. */
210 Lisp_Object Vscroll_preserve_screen_position
;
212 #if 0 /* This isn't used anywhere. */
213 /* Nonzero means we can split a frame even if it is "unsplittable". */
214 static int inhibit_frame_unsplittable
;
217 extern EMACS_INT scroll_margin
;
219 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
221 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
222 doc
: /* Returns t if OBJECT is a window. */)
226 return WINDOWP (object
) ? Qt
: Qnil
;
229 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
230 doc
: /* Returns t if OBJECT is a window which is currently visible. */)
234 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
241 register struct window
*p
;
243 p
= allocate_window ();
244 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
245 XSETFASTINT (p
->left_col
, 0);
246 XSETFASTINT (p
->top_line
, 0);
247 XSETFASTINT (p
->total_lines
, 0);
248 XSETFASTINT (p
->total_cols
, 0);
249 XSETFASTINT (p
->hscroll
, 0);
250 XSETFASTINT (p
->min_hscroll
, 0);
251 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
252 p
->start
= Fmake_marker ();
253 p
->pointm
= Fmake_marker ();
254 XSETFASTINT (p
->use_time
, 0);
256 p
->display_table
= Qnil
;
258 p
->pseudo_window_p
= 0;
259 bzero (&p
->cursor
, sizeof (p
->cursor
));
260 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
261 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
262 p
->desired_matrix
= p
->current_matrix
= 0;
263 p
->phys_cursor_type
= -1;
264 p
->phys_cursor_width
= -1;
265 p
->must_be_updated_p
= 0;
266 XSETFASTINT (p
->window_end_vpos
, 0);
267 XSETFASTINT (p
->window_end_pos
, 0);
268 p
->window_end_valid
= Qnil
;
271 XSETFASTINT (p
->last_point
, 0);
272 p
->frozen_window_start_p
= 0;
273 p
->height_fixed_p
= 0;
274 p
->last_cursor_off_p
= p
->cursor_off_p
= 0;
275 p
->left_margin_cols
= Qnil
;
276 p
->right_margin_cols
= Qnil
;
277 p
->left_fringe_width
= Qnil
;
278 p
->right_fringe_width
= Qnil
;
279 p
->fringes_outside_margins
= Qnil
;
280 p
->scroll_bar_width
= Qnil
;
281 p
->vertical_scroll_bar_type
= Qt
;
287 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
288 doc
: /* Return the window that the cursor now appears in and commands apply to. */)
291 return selected_window
;
294 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
295 doc
: /* Return the window used now for minibuffers.
296 If the optional argument FRAME is specified, return the minibuffer window
297 used by that frame. */)
302 frame
= selected_frame
;
303 CHECK_LIVE_FRAME (frame
);
304 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
307 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
308 doc
: /* Returns non-nil if WINDOW is a minibuffer window. */)
312 struct window
*w
= decode_window (window
);
313 return MINI_WINDOW_P (w
) ? Qt
: Qnil
;
317 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
318 Spos_visible_in_window_p
, 0, 3, 0,
319 doc
: /* Return t if position POS is currently on the frame in WINDOW.
320 Return nil if that position is scrolled vertically out of view.
321 If a character is only partially visible, nil is returned, unless the
322 optional argument PARTIALLY is non-nil.
323 POS defaults to point in WINDOW; WINDOW defaults to the selected window. */)
324 (pos
, window
, partially
)
325 Lisp_Object pos
, window
, partially
;
327 register struct window
*w
;
329 register struct buffer
*buf
;
331 Lisp_Object in_window
;
334 w
= decode_window (window
);
335 buf
= XBUFFER (w
->buffer
);
336 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
340 CHECK_NUMBER_COERCE_MARKER (pos
);
343 else if (w
== XWINDOW (selected_window
))
346 posint
= XMARKER (w
->pointm
)->charpos
;
348 /* If position is above window start, it's not visible. */
349 if (posint
< CHARPOS (top
))
351 else if (XFASTINT (w
->last_modified
) >= BUF_MODIFF (buf
)
352 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (buf
)
353 && posint
< BUF_Z (buf
) - XFASTINT (w
->window_end_pos
))
355 /* If frame is up-to-date, and POSINT is < window end pos, use
356 that info. This doesn't work for POSINT == end pos, because
357 the window end pos is actually the position _after_ the last
358 char in the window. */
359 if (NILP (partially
))
361 pos_visible_p (w
, posint
, &fully_p
, NILP (partially
));
362 in_window
= fully_p
? Qt
: Qnil
;
367 else if (posint
> BUF_ZV (buf
))
369 else if (CHARPOS (top
) < BUF_BEGV (buf
) || CHARPOS (top
) > BUF_ZV (buf
))
370 /* If window start is out of range, do something reasonable. */
374 if (pos_visible_p (w
, posint
, &fully_p
, NILP (partially
)))
375 in_window
= !NILP (partially
) || fully_p
? Qt
: Qnil
;
384 static struct window
*
385 decode_window (window
)
386 register Lisp_Object window
;
389 return XWINDOW (selected_window
);
391 CHECK_LIVE_WINDOW (window
);
392 return XWINDOW (window
);
395 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
396 doc
: /* Return the buffer that WINDOW is displaying. */)
400 return decode_window (window
)->buffer
;
403 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
404 doc
: /* Return the number of lines in WINDOW (including its mode line). */)
408 return decode_window (window
)->total_lines
;
411 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
412 doc
: /* Return the number of display columns in WINDOW.
413 This is the width that is usable columns available for text in WINDOW.
414 If you want to find out how many columns WINDOW takes up,
415 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
419 return make_number (window_box_text_cols (decode_window (window
)));
422 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
423 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin. */)
427 return decode_window (window
)->hscroll
;
430 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
431 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
432 NCOL should be zero or positive.
434 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
435 window so that the location of point becomes invisible. */)
437 Lisp_Object window
, ncol
;
439 struct window
*w
= decode_window (window
);
443 hscroll
= max (0, XINT (ncol
));
445 /* Prevent redisplay shortcuts when changing the hscroll. */
446 if (XINT (w
->hscroll
) != hscroll
)
447 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
449 w
->hscroll
= make_number (hscroll
);
453 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
454 Swindow_redisplay_end_trigger
, 0, 1, 0,
455 doc
: /* Return WINDOW's redisplay end trigger value.
456 See `set-window-redisplay-end-trigger' for more information. */)
460 return decode_window (window
)->redisplay_end_trigger
;
463 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
464 Sset_window_redisplay_end_trigger
, 2, 2, 0,
465 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
466 VALUE should be a buffer position (typically a marker) or nil.
467 If it is a buffer position, then if redisplay in WINDOW reaches a position
468 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
469 with two arguments: WINDOW, and the end trigger value.
470 Afterwards the end-trigger value is reset to nil. */)
472 register Lisp_Object window
, value
;
474 register struct window
*w
;
476 w
= decode_window (window
);
477 w
->redisplay_end_trigger
= value
;
481 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
482 doc
: /* Return a list of the edge coordinates of WINDOW.
483 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
484 RIGHT is one more than the rightmost column occupied by WINDOW,
485 and BOTTOM is one more than the bottommost row occupied by WINDOW.
486 The edges include the space used by the window's scroll bar,
487 display margins, fringes, header line, and mode line, if it has them.
488 To get the edges of the actual text area, use `window-inside-edges'. */)
492 register struct window
*w
= decode_window (window
);
494 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w
)),
495 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w
)),
496 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w
)),
497 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w
)),
501 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
502 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
503 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
504 RIGHT is one more than the rightmost x position occupied by WINDOW,
505 and BOTTOM is one more than the bottommost y position occupied by WINDOW.
506 The pixel edges include the space used by the window's scroll bar,
507 display margins, fringes, header line, and mode line, if it has them.
508 To get the edges of the actual text area, use `window-inside-pixel-edges'. */)
512 register struct window
*w
= decode_window (window
);
514 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
)),
515 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
)),
516 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
)),
517 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
)),
521 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
522 doc
: /* Return a list of the edge coordinates of WINDOW.
523 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
524 RIGHT is one more than the rightmost column used by text in WINDOW,
525 and BOTTOM is one more than the bottommost row used by text in WINDOW.
526 The inside edges do not include the space used by the window's scroll bar,
527 display margins, fringes, header line, and/or mode line. */)
531 register struct window
*w
= decode_window (window
);
533 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w
)
534 + WINDOW_LEFT_MARGIN_COLS (w
)
535 + WINDOW_LEFT_FRINGE_COLS (w
)),
536 make_number (WINDOW_TOP_EDGE_LINE (w
)
537 + WINDOW_HEADER_LINE_LINES (w
)),
538 make_number (WINDOW_RIGHT_EDGE_COL (w
)
539 - WINDOW_RIGHT_MARGIN_COLS (w
)
540 - WINDOW_RIGHT_FRINGE_COLS (w
)),
541 make_number (WINDOW_BOTTOM_EDGE_LINE (w
)
542 - WINDOW_MODE_LINE_LINES (w
)));
545 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
546 doc
: /* Return a list of the edge coordinates of WINDOW.
547 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
548 RIGHT is one more than the rightmost x position used by text in WINDOW,
549 and BOTTOM is one more than the bottommost y position used by text in WINDOW.
550 The inside edges do not include the space used by the window's scroll bar,
551 display margins, fringes, header line, and/or mode line. */)
555 register struct window
*w
= decode_window (window
);
557 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
558 + WINDOW_LEFT_MARGIN_WIDTH (w
)
559 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
560 make_number (WINDOW_TOP_EDGE_Y (w
)
561 + WINDOW_HEADER_LINE_HEIGHT (w
)),
562 make_number (WINDOW_RIGHT_EDGE_X (w
)
563 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
564 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
565 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
566 - WINDOW_MODE_LINE_HEIGHT (w
)));
569 /* Test if the character at column *X, row *Y is within window W.
570 If it is not, return ON_NOTHING;
571 if it is in the window's text area,
572 set *x and *y to its location relative to the upper left corner
575 if it is on the window's modeline, return ON_MODE_LINE;
576 if it is on the border between the window and its right sibling,
577 return ON_VERTICAL_BORDER.
578 if it is on the window's top line, return ON_HEADER_LINE;
579 if it is in left or right fringe of the window,
580 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y
581 to window-relative coordinates;
582 if it is in the marginal area to the left/right of the window,
583 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y
584 to window-relative coordinates.
586 X and Y are frame relative pixel coordinates. */
588 static enum window_part
589 coordinates_in_window (w
, x
, y
)
590 register struct window
*w
;
593 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
594 int left_x
, right_x
, top_y
, bottom_y
;
595 enum window_part part
;
596 int ux
= FRAME_COLUMN_WIDTH (f
);
597 int x0
= WINDOW_LEFT_EDGE_X (w
);
598 int x1
= WINDOW_RIGHT_EDGE_X (w
);
599 /* The width of the area where the vertical line can be dragged.
600 (Between mode lines for instance. */
601 int grabbable_width
= ux
;
602 int lmargin_width
, rmargin_width
, text_left
, text_right
;
604 if (*x
< x0
|| *x
>= x1
)
607 /* In what's below, we subtract 1 when computing right_x because we
608 want the rightmost pixel, which is given by left_pixel+width-1. */
609 if (w
->pseudo_window_p
)
612 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
613 top_y
= WINDOW_TOP_EDGE_Y (w
);
614 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
618 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
619 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
620 top_y
= WINDOW_TOP_EDGE_Y (w
);
621 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
624 /* Outside any interesting row? */
625 if (*y
< top_y
|| *y
>= bottom_y
)
628 /* On the mode line or header line? If it's near the start of
629 the mode or header line of window that's has a horizontal
630 sibling, say it's on the vertical line. That's to be able
631 to resize windows horizontally in case we're using toolkit
634 if (WINDOW_WANTS_MODELINE_P (w
)
635 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
)
640 header_vertical_border_check
:
641 /* We're somewhere on the mode line. We consider the place
642 between mode lines of horizontally adjacent mode lines
643 as the vertical border. If scroll bars on the left,
644 return the right window. */
645 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
646 || WINDOW_RIGHTMOST_P (w
))
648 if (!WINDOW_LEFTMOST_P (w
) && abs (*x
- x0
) < grabbable_width
)
649 return ON_VERTICAL_BORDER
;
653 if (abs (*x
- x1
) < grabbable_width
)
654 return ON_VERTICAL_BORDER
;
660 if (WINDOW_WANTS_HEADER_LINE_P (w
)
662 && *y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
))
664 part
= ON_HEADER_LINE
;
665 goto header_vertical_border_check
;
668 /* Outside any interesting column? */
669 if (*x
< left_x
|| *x
> right_x
)
672 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
673 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
675 text_left
= window_box_left (w
, TEXT_AREA
);
676 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
678 if (FRAME_WINDOW_P (f
))
680 if (!w
->pseudo_window_p
681 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
682 && !WINDOW_RIGHTMOST_P (w
)
683 && (abs (*x
- right_x
) < grabbable_width
))
684 return ON_VERTICAL_BORDER
;
688 /* Need to say "*x > right_x" rather than >=, since on character
689 terminals, the vertical line's x coordinate is right_x. */
690 if (!w
->pseudo_window_p
691 && !WINDOW_RIGHTMOST_P (w
)
692 && *x
> right_x
- ux
)
694 /* On the border on the right side of the window? Assume that
695 this area begins at RIGHT_X minus a canonical char width. */
696 return ON_VERTICAL_BORDER
;
702 if (lmargin_width
> 0
703 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
704 ? (*x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
705 : (*x
< left_x
+ lmargin_width
)))
706 return ON_LEFT_MARGIN
;
708 /* Convert X and Y to window-relative pixel coordinates. */
711 return ON_LEFT_FRINGE
;
714 if (*x
>= text_right
)
716 if (rmargin_width
> 0
717 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
718 ? (*x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
719 : (*x
>= right_x
- rmargin_width
)))
720 return ON_RIGHT_MARGIN
;
722 /* Convert X and Y to window-relative pixel coordinates. */
723 *x
-= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
);
725 return ON_RIGHT_FRINGE
;
728 /* Everything special ruled out - must be on text area */
729 *x
-= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
);
735 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
736 Scoordinates_in_window_p
, 2, 2, 0,
737 doc
: /* Return non-nil if COORDINATES are in WINDOW.
738 COORDINATES is a cons of the form (X . Y), X and Y being distances
739 measured in characters from the upper-left corner of the frame.
740 \(0 . 0) denotes the character in the upper left corner of the
742 If COORDINATES are in the text portion of WINDOW,
743 the coordinates relative to the window are returned.
744 If they are in the mode line of WINDOW, `mode-line' is returned.
745 If they are in the top mode line of WINDOW, `header-line' is returned.
746 If they are in the left fringe of WINDOW, `left-fringe' is returned.
747 If they are in the right fringe of WINDOW, `right-fringe' is returned.
748 If they are on the border between WINDOW and its right sibling,
749 `vertical-line' is returned.
750 If they are in the windows's left or right marginal areas, `left-margin'\n\
751 or `right-margin' is returned. */)
752 (coordinates
, window
)
753 register Lisp_Object coordinates
, window
;
760 CHECK_LIVE_WINDOW (window
);
761 w
= XWINDOW (window
);
762 f
= XFRAME (w
->frame
);
763 CHECK_CONS (coordinates
);
764 lx
= Fcar (coordinates
);
765 ly
= Fcdr (coordinates
);
766 CHECK_NUMBER_OR_FLOAT (lx
);
767 CHECK_NUMBER_OR_FLOAT (ly
);
768 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
);
769 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
);
771 switch (coordinates_in_window (w
, &x
, &y
))
777 /* X and Y are now window relative pixel coordinates. Convert
778 them to canonical char units before returning them. */
779 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
780 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
785 case ON_VERTICAL_BORDER
:
786 return Qvertical_line
;
794 case ON_RIGHT_FRINGE
:
795 return Qright_fringe
;
800 case ON_RIGHT_MARGIN
:
801 return Qright_margin
;
809 /* Callback for foreach_window, used in window_from_coordinates.
810 Check if window W contains coordinates specified by USER_DATA which
811 is actually a pointer to a struct check_window_data CW.
813 Check if window W contains coordinates *CW->x and *CW->y. If it
814 does, return W in *CW->window, as Lisp_Object, and return in
815 *CW->part the part of the window under coordinates *X,*Y. Return
816 zero from this function to stop iterating over windows. */
818 struct check_window_data
822 enum window_part
*part
;
826 check_window_containing (w
, user_data
)
830 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
831 enum window_part found
;
834 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
835 if (found
!= ON_NOTHING
)
838 XSETWINDOW (*cw
->window
, w
);
846 /* Find the window containing frame-relative pixel position X/Y and
847 return it as a Lisp_Object.
849 If X, Y is on one of the window's special `window_part' elements,
850 set *PART to the id of that element, and return X and Y converted
851 to window relative coordinates in WX and WY.
853 If there is no window under X, Y return nil and leave *PART
854 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
856 This function was previously implemented with a loop cycling over
857 windows with Fnext_window, and starting with the frame's selected
858 window. It turned out that this doesn't work with an
859 implementation of next_window using Vwindow_list, because
860 FRAME_SELECTED_WINDOW (F) is not always contained in the window
861 tree of F when this function is called asynchronously from
862 note_mouse_highlight. The original loop didn't terminate in this
866 window_from_coordinates (f
, x
, y
, part
, wx
, wy
, tool_bar_p
)
869 enum window_part
*part
;
874 struct check_window_data cw
;
875 enum window_part dummy
;
881 cw
.window
= &window
, cw
.x
= &x
, cw
.y
= &y
; cw
.part
= part
;
882 foreach_window (f
, check_window_containing
, &cw
);
884 /* If not found above, see if it's in the tool bar window, if a tool
888 && WINDOWP (f
->tool_bar_window
)
889 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
890 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), &x
, &y
)
894 window
= f
->tool_bar_window
;
903 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
904 doc
: /* Return window containing coordinates X and Y on FRAME.
905 If omitted, FRAME defaults to the currently selected frame.
906 The top left corner of the frame is considered to be row 0,
909 Lisp_Object x
, y
, frame
;
914 frame
= selected_frame
;
915 CHECK_LIVE_FRAME (frame
);
918 /* Check that arguments are integers or floats. */
919 CHECK_NUMBER_OR_FLOAT (x
);
920 CHECK_NUMBER_OR_FLOAT (y
);
922 return window_from_coordinates (f
,
923 FRAME_PIXEL_X_FROM_CANON_X (f
, x
),
924 FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
),
928 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
929 doc
: /* Return current value of point in WINDOW.
930 For a nonselected window, this is the value point would have
931 if that window were selected.
933 Note that, when WINDOW is the selected window and its buffer
934 is also currently selected, the value returned is the same as (point).
935 It would be more strictly correct to return the `top-level' value
936 of point, outside of any save-excursion forms.
937 But that is hard to define. */)
941 register struct window
*w
= decode_window (window
);
943 if (w
== XWINDOW (selected_window
)
944 && current_buffer
== XBUFFER (w
->buffer
))
946 return Fmarker_position (w
->pointm
);
949 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
950 doc
: /* Return position at which display currently starts in WINDOW.
951 This is updated by redisplay or by calling `set-window-start'. */)
955 return Fmarker_position (decode_window (window
)->start
);
958 /* This is text temporarily removed from the doc string below.
960 This function returns nil if the position is not currently known.
961 That happens when redisplay is preempted and doesn't finish.
962 If in that case you want to compute where the end of the window would
963 have been if redisplay had finished, do this:
965 (goto-char (window-start window))
966 (vertical-motion (1- (window-height window)) window)
969 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
970 doc
: /* Return position at which display currently ends in WINDOW.
971 This is updated by redisplay, when it runs to completion.
972 Simply changing the buffer text or setting `window-start'
973 does not update this value.
974 If UPDATE is non-nil, compute the up-to-date position
975 if it isn't already recorded. */)
977 Lisp_Object window
, update
;
980 struct window
*w
= decode_window (window
);
986 #if 0 /* This change broke some things. We should make it later. */
987 /* If we don't know the end position, return nil.
988 The user can compute it with vertical-motion if he wants to.
989 It would be nicer to do it automatically,
990 but that's so slow that it would probably bother people. */
991 if (NILP (w
->window_end_valid
))
996 && ! (! NILP (w
->window_end_valid
)
997 && XFASTINT (w
->last_modified
) >= MODIFF
))
999 struct text_pos startp
;
1001 struct buffer
*old_buffer
= NULL
, *b
= XBUFFER (buf
);
1003 /* In case W->start is out of the range, use something
1004 reasonable. This situation occurred when loading a file with
1005 `-l' containing a call to `rmail' with subsequent other
1006 commands. At the end, W->start happened to be BEG, while
1007 rmail had already narrowed the buffer. */
1008 if (XMARKER (w
->start
)->charpos
< BEGV
)
1009 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1010 else if (XMARKER (w
->start
)->charpos
> ZV
)
1011 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1013 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1015 /* Cannot use Fvertical_motion because that function doesn't
1016 cope with variable-height lines. */
1017 if (b
!= current_buffer
)
1019 old_buffer
= current_buffer
;
1020 set_buffer_internal (b
);
1023 start_display (&it
, w
, startp
);
1024 move_it_vertically (&it
, window_box_height (w
));
1025 if (it
.current_y
< it
.last_visible_y
)
1026 move_it_past_eol (&it
);
1027 value
= make_number (IT_CHARPOS (it
));
1030 set_buffer_internal (old_buffer
);
1033 XSETINT (value
, BUF_Z (XBUFFER (buf
)) - XFASTINT (w
->window_end_pos
));
1038 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1039 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer. */)
1041 Lisp_Object window
, pos
;
1043 register struct window
*w
= decode_window (window
);
1045 CHECK_NUMBER_COERCE_MARKER (pos
);
1046 if (w
== XWINDOW (selected_window
)
1047 && XBUFFER (w
->buffer
) == current_buffer
)
1050 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1052 /* We have to make sure that redisplay updates the window to show
1053 the new value of point. */
1054 if (!EQ (window
, selected_window
))
1055 ++windows_or_buffers_changed
;
1060 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1061 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1062 Optional third arg NOFORCE non-nil inhibits next redisplay
1063 from overriding motion of point in order to display at this exact start. */)
1064 (window
, pos
, noforce
)
1065 Lisp_Object window
, pos
, noforce
;
1067 register struct window
*w
= decode_window (window
);
1069 CHECK_NUMBER_COERCE_MARKER (pos
);
1070 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1071 /* this is not right, but much easier than doing what is right. */
1072 w
->start_at_line_beg
= Qnil
;
1074 w
->force_start
= Qt
;
1075 w
->update_mode_line
= Qt
;
1076 XSETFASTINT (w
->last_modified
, 0);
1077 XSETFASTINT (w
->last_overlay_modified
, 0);
1078 if (!EQ (window
, selected_window
))
1079 windows_or_buffers_changed
++;
1084 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1086 doc
: /* Return WINDOW's dedicated object, usually t or nil.
1087 See also `set-window-dedicated-p'. */)
1091 return decode_window (window
)->dedicated
;
1094 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1095 Sset_window_dedicated_p
, 2, 2, 0,
1096 doc
: /* Control whether WINDOW is dedicated to the buffer it displays.
1097 If it is dedicated, Emacs will not automatically change
1098 which buffer appears in it.
1099 The second argument is the new value for the dedication flag;
1100 non-nil means yes. */)
1102 Lisp_Object window
, arg
;
1104 register struct window
*w
= decode_window (window
);
1107 w
->dedicated
= Qnil
;
1111 return w
->dedicated
;
1114 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1116 doc
: /* Return the display-table that WINDOW is using. */)
1120 return decode_window (window
)->display_table
;
1123 /* Get the display table for use on window W. This is either W's
1124 display table or W's buffer's display table. Ignore the specified
1125 tables if they are not valid; if no valid table is specified,
1128 struct Lisp_Char_Table
*
1129 window_display_table (w
)
1132 struct Lisp_Char_Table
*dp
= NULL
;
1134 if (DISP_TABLE_P (w
->display_table
))
1135 dp
= XCHAR_TABLE (w
->display_table
);
1136 else if (BUFFERP (w
->buffer
))
1138 struct buffer
*b
= XBUFFER (w
->buffer
);
1140 if (DISP_TABLE_P (b
->display_table
))
1141 dp
= XCHAR_TABLE (b
->display_table
);
1142 else if (DISP_TABLE_P (Vstandard_display_table
))
1143 dp
= XCHAR_TABLE (Vstandard_display_table
);
1149 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1150 doc
: /* Set WINDOW's display-table to TABLE. */)
1152 register Lisp_Object window
, table
;
1154 register struct window
*w
;
1156 w
= decode_window (window
);
1157 w
->display_table
= table
;
1161 /* Record info on buffer window w is displaying
1162 when it is about to cease to display that buffer. */
1165 register struct window
*w
;
1172 if (b
!= XMARKER (w
->pointm
)->buffer
)
1176 if (w
== XWINDOW (selected_window
)
1177 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1178 /* Do this except when the selected window's buffer
1179 is being removed from some other window. */
1181 /* last_window_start records the start position that this buffer
1182 had in the last window to be disconnected from it.
1183 Now that this statement is unconditional,
1184 it is possible for the buffer to be displayed in the
1185 selected window, while last_window_start reflects another
1186 window which was recently showing the same buffer.
1187 Some people might say that might be a good thing. Let's see. */
1188 b
->last_window_start
= marker_position (w
->start
);
1190 /* Point in the selected window's buffer
1191 is actually stored in that buffer, and the window's pointm isn't used.
1192 So don't clobber point in that buffer. */
1193 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1194 /* This line helps to fix Horsley's testbug.el bug. */
1195 && !(WINDOWP (b
->last_selected_window
)
1196 && w
!= XWINDOW (b
->last_selected_window
)
1197 && EQ (buf
, XWINDOW (b
->last_selected_window
)->buffer
)))
1198 temp_set_point_both (b
,
1199 clip_to_bounds (BUF_BEGV (b
),
1200 XMARKER (w
->pointm
)->charpos
,
1202 clip_to_bounds (BUF_BEGV_BYTE (b
),
1203 marker_byte_position (w
->pointm
),
1206 if (WINDOWP (b
->last_selected_window
)
1207 && w
== XWINDOW (b
->last_selected_window
))
1208 b
->last_selected_window
= Qnil
;
1211 /* Put replacement into the window structure in place of old. */
1213 replace_window (old
, replacement
)
1214 Lisp_Object old
, replacement
;
1216 register Lisp_Object tem
;
1217 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
1219 /* If OLD is its frame's root_window, then replacement is the new
1220 root_window for that frame. */
1222 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1223 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
1225 p
->left_col
= o
->left_col
;
1226 p
->top_line
= o
->top_line
;
1227 p
->total_cols
= o
->total_cols
;
1228 p
->total_lines
= o
->total_lines
;
1229 p
->desired_matrix
= p
->current_matrix
= 0;
1231 bzero (&p
->cursor
, sizeof (p
->cursor
));
1232 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
1233 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
1234 p
->phys_cursor_type
= -1;
1235 p
->phys_cursor_width
= -1;
1236 p
->must_be_updated_p
= 0;
1237 p
->pseudo_window_p
= 0;
1238 XSETFASTINT (p
->window_end_vpos
, 0);
1239 XSETFASTINT (p
->window_end_pos
, 0);
1240 p
->window_end_valid
= Qnil
;
1241 p
->frozen_window_start_p
= 0;
1242 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
1244 p
->next
= tem
= o
->next
;
1246 XWINDOW (tem
)->prev
= replacement
;
1248 p
->prev
= tem
= o
->prev
;
1250 XWINDOW (tem
)->next
= replacement
;
1252 p
->parent
= tem
= o
->parent
;
1255 if (EQ (XWINDOW (tem
)->vchild
, old
))
1256 XWINDOW (tem
)->vchild
= replacement
;
1257 if (EQ (XWINDOW (tem
)->hchild
, old
))
1258 XWINDOW (tem
)->hchild
= replacement
;
1261 /*** Here, if replacement is a vertical combination
1262 and so is its new parent, we should make replacement's
1263 children be children of that parent instead. ***/
1266 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
1267 doc
: /* Remove WINDOW from the display. Default is selected window. */)
1269 register Lisp_Object window
;
1271 delete_window (window
);
1273 if (! NILP (Vwindow_configuration_change_hook
)
1274 && ! NILP (Vrun_hooks
))
1275 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
1281 delete_window (window
)
1282 register Lisp_Object window
;
1284 register Lisp_Object tem
, parent
, sib
;
1285 register struct window
*p
;
1286 register struct window
*par
;
1289 /* Because this function is called by other C code on non-leaf
1290 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1291 so we can't decode_window here. */
1293 window
= selected_window
;
1295 CHECK_WINDOW (window
);
1296 p
= XWINDOW (window
);
1298 /* It's okay to delete an already-deleted window. */
1299 if (NILP (p
->buffer
)
1301 && NILP (p
->vchild
))
1306 error ("Attempt to delete minibuffer or sole ordinary window");
1307 par
= XWINDOW (parent
);
1309 windows_or_buffers_changed
++;
1310 Vwindow_list
= Qnil
;
1311 f
= XFRAME (WINDOW_FRAME (p
));
1312 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
1314 /* Are we trying to delete any frame's selected window? */
1316 Lisp_Object swindow
, pwindow
;
1318 /* See if the frame's selected window is either WINDOW
1319 or any subwindow of it, by finding all that window's parents
1320 and comparing each one with WINDOW. */
1321 swindow
= FRAME_SELECTED_WINDOW (f
);
1326 while (!NILP (pwindow
))
1328 if (EQ (window
, pwindow
))
1330 pwindow
= XWINDOW (pwindow
)->parent
;
1333 /* If the window being deleted is not a parent of SWINDOW,
1334 then SWINDOW is ok as the new selected window. */
1335 if (!EQ (window
, pwindow
))
1337 /* Otherwise, try another window for SWINDOW. */
1338 swindow
= Fnext_window (swindow
, Qlambda
, Qnil
);;
1340 /* If we get back to the frame's selected window,
1341 it means there was no acceptable alternative,
1342 so we cannot delete. */
1343 if (EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1344 error ("Cannot delete window");
1347 /* If we need to change SWINDOW, do it. */
1348 if (! EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1350 /* If we're about to delete the selected window on the
1351 selected frame, then we should use Fselect_window to select
1352 the new window. On the other hand, if we're about to
1353 delete the selected window on any other frame, we shouldn't do
1354 anything but set the frame's selected_window slot. */
1355 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
1356 Fselect_window (swindow
, Qnil
);
1358 FRAME_SELECTED_WINDOW (f
) = swindow
;
1363 /* tem is null for dummy parent windows
1364 (which have inferiors but not any contents themselves) */
1368 unchain_marker (p
->pointm
);
1369 unchain_marker (p
->start
);
1372 /* Free window glyph matrices. It is sure that they are allocated
1373 again when ADJUST_GLYPHS is called. Block input so that expose
1374 events and other events that access glyph matrices are not
1375 processed while we are changing them. */
1377 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)));
1381 XWINDOW (tem
)->prev
= p
->prev
;
1385 XWINDOW (tem
)->next
= p
->next
;
1387 if (EQ (window
, par
->hchild
))
1388 par
->hchild
= p
->next
;
1389 if (EQ (window
, par
->vchild
))
1390 par
->vchild
= p
->next
;
1392 /* Find one of our siblings to give our space to. */
1396 /* If p gives its space to its next sibling, that sibling needs
1397 to have its top/left side pulled back to where p's is.
1398 set_window_{height,width} will re-position the sibling's
1401 XWINDOW (sib
)->top_line
= p
->top_line
;
1402 XWINDOW (sib
)->left_col
= p
->left_col
;
1405 /* Stretch that sibling. */
1406 if (!NILP (par
->vchild
))
1407 set_window_height (sib
,
1408 XFASTINT (XWINDOW (sib
)->total_lines
) + XFASTINT (p
->total_lines
),
1410 if (!NILP (par
->hchild
))
1411 set_window_width (sib
,
1412 XFASTINT (XWINDOW (sib
)->total_cols
) + XFASTINT (p
->total_cols
),
1415 /* If parent now has only one child,
1416 put the child into the parent's place. */
1420 if (NILP (XWINDOW (tem
)->next
))
1421 replace_window (parent
, tem
);
1423 /* Since we may be deleting combination windows, we must make sure that
1424 not only p but all its children have been marked as deleted. */
1425 if (! NILP (p
->hchild
))
1426 delete_all_subwindows (XWINDOW (p
->hchild
));
1427 else if (! NILP (p
->vchild
))
1428 delete_all_subwindows (XWINDOW (p
->vchild
));
1430 /* Mark this window as deleted. */
1431 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1433 /* Adjust glyph matrices. */
1440 /***********************************************************************
1442 ***********************************************************************/
1444 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1445 pointer. This is a callback function for foreach_window, used in
1446 function window_list. */
1449 add_window_to_list (w
, user_data
)
1453 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1455 XSETWINDOW (window
, w
);
1456 *list
= Fcons (window
, *list
);
1461 /* Return a list of all windows, for use by next_window. If
1462 Vwindow_list is a list, return that list. Otherwise, build a new
1463 list, cache it in Vwindow_list, and return that. */
1468 if (!CONSP (Vwindow_list
))
1472 Vwindow_list
= Qnil
;
1473 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1475 Lisp_Object args
[2];
1477 /* We are visiting windows in canonical order, and add
1478 new windows at the front of args[1], which means we
1479 have to reverse this list at the end. */
1481 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1482 args
[0] = Vwindow_list
;
1483 args
[1] = Fnreverse (args
[1]);
1484 Vwindow_list
= Fnconc (2, args
);
1488 return Vwindow_list
;
1492 /* Value is non-zero if WINDOW satisfies the constraints given by
1493 OWINDOW, MINIBUF and ALL_FRAMES.
1495 MINIBUF t means WINDOW may be minibuffer windows.
1496 `lambda' means WINDOW may not be a minibuffer window.
1497 a window means a specific minibuffer window
1499 ALL_FRAMES t means search all frames,
1500 nil means search just current frame,
1501 `visible' means search just visible frames,
1502 0 means search visible and iconified frames,
1503 a window means search the frame that window belongs to,
1504 a frame means consider windows on that frame, only. */
1507 candidate_window_p (window
, owindow
, minibuf
, all_frames
)
1508 Lisp_Object window
, owindow
, minibuf
, all_frames
;
1510 struct window
*w
= XWINDOW (window
);
1511 struct frame
*f
= XFRAME (w
->frame
);
1512 int candidate_p
= 1;
1514 if (!BUFFERP (w
->buffer
))
1516 else if (MINI_WINDOW_P (w
)
1517 && (EQ (minibuf
, Qlambda
)
1518 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
1520 /* If MINIBUF is `lambda' don't consider any mini-windows.
1521 If it is a window, consider only that one. */
1524 else if (EQ (all_frames
, Qt
))
1526 else if (NILP (all_frames
))
1528 xassert (WINDOWP (owindow
));
1529 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
1531 else if (EQ (all_frames
, Qvisible
))
1533 FRAME_SAMPLE_VISIBILITY (f
);
1534 candidate_p
= FRAME_VISIBLE_P (f
);
1536 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
1538 FRAME_SAMPLE_VISIBILITY (f
);
1539 candidate_p
= FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
);
1541 else if (WINDOWP (all_frames
))
1542 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
1543 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
1544 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
1545 else if (FRAMEP (all_frames
))
1546 candidate_p
= EQ (all_frames
, w
->frame
);
1552 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1553 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1557 decode_next_window_args (window
, minibuf
, all_frames
)
1558 Lisp_Object
*window
, *minibuf
, *all_frames
;
1561 *window
= selected_window
;
1563 CHECK_LIVE_WINDOW (*window
);
1565 /* MINIBUF nil may or may not include minibuffers. Decide if it
1567 if (NILP (*minibuf
))
1568 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
1569 else if (!EQ (*minibuf
, Qt
))
1572 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1573 => count none of them, or a specific minibuffer window (the
1574 active one) to count. */
1576 /* ALL_FRAMES nil doesn't specify which frames to include. */
1577 if (NILP (*all_frames
))
1578 *all_frames
= (!EQ (*minibuf
, Qlambda
)
1579 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
1581 else if (EQ (*all_frames
, Qvisible
))
1583 else if (XFASTINT (*all_frames
) == 0)
1585 else if (FRAMEP (*all_frames
))
1587 else if (!EQ (*all_frames
, Qt
))
1590 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1591 search just current frame, `visible' meaning search just visible
1592 frames, 0 meaning search visible and iconified frames, or a
1593 window, meaning search the frame that window belongs to, or a
1594 frame, meaning consider windows on that frame, only. */
1598 /* Return the next or previous window of WINDOW in canonical ordering
1599 of windows. NEXT_P non-zero means return the next window. See the
1600 documentation string of next-window for the meaning of MINIBUF and
1604 next_window (window
, minibuf
, all_frames
, next_p
)
1605 Lisp_Object window
, minibuf
, all_frames
;
1608 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1610 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1611 return the first window on the frame. */
1612 if (FRAMEP (all_frames
)
1613 && !EQ (all_frames
, XWINDOW (window
)->frame
))
1614 return Fframe_first_window (all_frames
);
1620 /* Find WINDOW in the list of all windows. */
1621 list
= Fmemq (window
, window_list ());
1623 /* Scan forward from WINDOW to the end of the window list. */
1625 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
1626 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1629 /* Scan from the start of the window list up to WINDOW. */
1631 for (list
= Vwindow_list
;
1632 CONSP (list
) && !EQ (XCAR (list
), window
);
1634 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1638 window
= XCAR (list
);
1642 Lisp_Object candidate
, list
;
1644 /* Scan through the list of windows for candidates. If there are
1645 candidate windows in front of WINDOW, the last one of these
1646 is the one we want. If there are candidates following WINDOW
1647 in the list, again the last one of these is the one we want. */
1649 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
1651 if (EQ (XCAR (list
), window
))
1653 if (WINDOWP (candidate
))
1656 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
1658 candidate
= XCAR (list
);
1661 if (WINDOWP (candidate
))
1669 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
1670 doc
: /* Return next window after WINDOW in canonical ordering of windows.
1671 If omitted, WINDOW defaults to the selected window.
1673 Optional second arg MINIBUF t means count the minibuffer window even
1674 if not active. MINIBUF nil or omitted means count the minibuffer iff
1675 it is active. MINIBUF neither t nor nil means not to count the
1676 minibuffer even if it is active.
1678 Several frames may share a single minibuffer; if the minibuffer
1679 counts, all windows on all frames that share that minibuffer count
1680 too. Therefore, `next-window' can be used to iterate through the
1681 set of windows even when the minibuffer is on another frame. If the
1682 minibuffer does not count, only windows from WINDOW's frame count.
1684 Optional third arg ALL-FRAMES t means include windows on all frames.
1685 ALL-FRAMES nil or omitted means cycle within the frames as specified
1686 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1687 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1688 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1689 Anything else means restrict to WINDOW's frame.
1691 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1692 `next-window' to iterate through the entire cycle of acceptable
1693 windows, eventually ending up back at the window you started with.
1694 `previous-window' traverses the same cycle, in the reverse order. */)
1695 (window
, minibuf
, all_frames
)
1696 Lisp_Object window
, minibuf
, all_frames
;
1698 return next_window (window
, minibuf
, all_frames
, 1);
1702 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1703 doc
: /* Return the window preceding WINDOW in canonical ordering of windows.
1704 If omitted, WINDOW defaults to the selected window.
1706 Optional second arg MINIBUF t means count the minibuffer window even
1707 if not active. MINIBUF nil or omitted means count the minibuffer iff
1708 it is active. MINIBUF neither t nor nil means not to count the
1709 minibuffer even if it is active.
1711 Several frames may share a single minibuffer; if the minibuffer
1712 counts, all windows on all frames that share that minibuffer count
1713 too. Therefore, `previous-window' can be used to iterate through
1714 the set of windows even when the minibuffer is on another frame. If
1715 the minibuffer does not count, only windows from WINDOW's frame count
1717 Optional third arg ALL-FRAMES t means include windows on all frames.
1718 ALL-FRAMES nil or omitted means cycle within the frames as specified
1719 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1720 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1721 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1722 Anything else means restrict to WINDOW's frame.
1724 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1725 `previous-window' to iterate through the entire cycle of acceptable
1726 windows, eventually ending up back at the window you started with.
1727 `next-window' traverses the same cycle, in the reverse order. */)
1728 (window
, minibuf
, all_frames
)
1729 Lisp_Object window
, minibuf
, all_frames
;
1731 return next_window (window
, minibuf
, all_frames
, 0);
1735 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1736 doc
: /* Select the ARG'th different window on this frame.
1737 All windows on current frame are arranged in a cyclic order.
1738 This command selects the window ARG steps away in that order.
1739 A negative ARG moves in the opposite order. If the optional second
1740 argument ALL_FRAMES is non-nil, cycle through all frames. */)
1742 Lisp_Object arg
, all_frames
;
1748 window
= selected_window
;
1750 for (i
= XINT (arg
); i
> 0; --i
)
1751 window
= Fnext_window (window
, Qnil
, all_frames
);
1753 window
= Fprevious_window (window
, Qnil
, all_frames
);
1755 Fselect_window (window
, Qnil
);
1760 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
1761 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
1762 FRAME nil or omitted means use the selected frame.
1763 WINDOW nil or omitted means use the selected window.
1764 MINIBUF t means include the minibuffer window, even if it isn't active.
1765 MINIBUF nil or omitted means include the minibuffer window only
1767 MINIBUF neither nil nor t means never include the minibuffer window. */)
1768 (frame
, minibuf
, window
)
1769 Lisp_Object frame
, minibuf
, window
;
1772 window
= selected_window
;
1774 frame
= selected_frame
;
1776 if (!EQ (frame
, XWINDOW (window
)->frame
))
1777 error ("Window is on a different frame");
1779 return window_list_1 (window
, minibuf
, frame
);
1783 /* Return a list of windows in canonical ordering. Arguments are like
1784 for `next-window'. */
1787 window_list_1 (window
, minibuf
, all_frames
)
1788 Lisp_Object window
, minibuf
, all_frames
;
1790 Lisp_Object tail
, list
;
1792 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1795 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
1796 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
1797 list
= Fcons (XCAR (tail
), list
);
1799 return Fnreverse (list
);
1804 /* Look at all windows, performing an operation specified by TYPE
1806 If FRAMES is Qt, look at all frames;
1807 Qnil, look at just the selected frame;
1808 Qvisible, look at visible frames;
1809 a frame, just look at windows on that frame.
1810 If MINI is non-zero, perform the operation on minibuffer windows too. */
1815 GET_BUFFER_WINDOW
, /* Arg is buffer */
1816 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1817 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1818 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1820 UNSHOW_BUFFER
, /* Arg is buffer */
1825 window_loop (type
, obj
, mini
, frames
)
1826 enum window_loop type
;
1827 Lisp_Object obj
, frames
;
1830 Lisp_Object window
, windows
, best_window
, frame_arg
;
1832 struct gcpro gcpro1
;
1834 /* If we're only looping through windows on a particular frame,
1835 frame points to that frame. If we're looping through windows
1836 on all frames, frame is 0. */
1837 if (FRAMEP (frames
))
1838 f
= XFRAME (frames
);
1839 else if (NILP (frames
))
1840 f
= SELECTED_FRAME ();
1845 frame_arg
= Qlambda
;
1846 else if (XFASTINT (frames
) == 0)
1848 else if (EQ (frames
, Qvisible
))
1853 /* frame_arg is Qlambda to stick to one frame,
1854 Qvisible to consider all visible frames,
1857 /* Pick a window to start with. */
1861 window
= FRAME_SELECTED_WINDOW (f
);
1863 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
1865 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
1869 for (; CONSP (windows
); windows
= CDR (windows
))
1873 window
= XCAR (windows
);
1874 w
= XWINDOW (window
);
1876 /* Note that we do not pay attention here to whether the frame
1877 is visible, since Fwindow_list skips non-visible frames if
1878 that is desired, under the control of frame_arg. */
1879 if (!MINI_WINDOW_P (w
)
1880 /* For UNSHOW_BUFFER, we must always consider all windows. */
1881 || type
== UNSHOW_BUFFER
1882 || (mini
&& minibuf_level
> 0))
1885 case GET_BUFFER_WINDOW
:
1886 if (EQ (w
->buffer
, obj
)
1887 /* Don't find any minibuffer window
1888 except the one that is currently in use. */
1889 && (MINI_WINDOW_P (w
)
1890 ? EQ (window
, minibuf_window
)
1893 if (NILP (best_window
))
1894 best_window
= window
;
1895 else if (EQ (window
, selected_window
))
1896 /* For compatibility with 20.x, prefer to return
1898 best_window
= window
;
1902 case GET_LRU_WINDOW
:
1903 /* t as arg means consider only full-width windows */
1904 if (!NILP (obj
) && !WINDOW_FULL_WIDTH_P (w
))
1906 /* Ignore dedicated windows and minibuffers. */
1907 if (MINI_WINDOW_P (w
) || EQ (w
->dedicated
, Qt
))
1909 if (NILP (best_window
)
1910 || (XFASTINT (XWINDOW (best_window
)->use_time
)
1911 > XFASTINT (w
->use_time
)))
1912 best_window
= window
;
1915 case DELETE_OTHER_WINDOWS
:
1916 if (!EQ (window
, obj
))
1917 Fdelete_window (window
);
1920 case DELETE_BUFFER_WINDOWS
:
1921 if (EQ (w
->buffer
, obj
))
1923 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1925 /* If this window is dedicated, and in a frame of its own,
1927 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
1928 && !NILP (w
->dedicated
)
1929 && other_visible_frames (f
))
1931 /* Skip the other windows on this frame.
1932 There might be one, the minibuffer! */
1933 while (CONSP (XCDR (windows
))
1934 && EQ (XWINDOW (XCAR (windows
))->frame
,
1935 XWINDOW (XCAR (XCDR (windows
)))->frame
))
1936 windows
= XCDR (windows
);
1938 /* Now we can safely delete the frame. */
1939 Fdelete_frame (w
->frame
, Qnil
);
1941 else if (NILP (w
->parent
))
1943 /* If we're deleting the buffer displayed in the
1944 only window on the frame, find a new buffer to
1947 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
1948 Fset_window_buffer (window
, buffer
, Qnil
);
1949 if (EQ (window
, selected_window
))
1950 Fset_buffer (w
->buffer
);
1953 Fdelete_window (window
);
1957 case GET_LARGEST_WINDOW
:
1959 /* Ignore dedicated windows and minibuffers. */
1960 if (MINI_WINDOW_P (w
) || EQ (w
->dedicated
, Qt
))
1963 if (NILP (best_window
))
1964 best_window
= window
;
1967 struct window
*b
= XWINDOW (best_window
);
1968 if (XFASTINT (w
->total_lines
) * XFASTINT (w
->total_cols
)
1969 > XFASTINT (b
->total_lines
) * XFASTINT (b
->total_cols
))
1970 best_window
= window
;
1976 if (EQ (w
->buffer
, obj
))
1979 struct frame
*f
= XFRAME (w
->frame
);
1981 /* Find another buffer to show in this window. */
1982 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
1984 /* If this window is dedicated, and in a frame of its own,
1986 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
1987 && !NILP (w
->dedicated
)
1988 && other_visible_frames (f
))
1990 /* Skip the other windows on this frame.
1991 There might be one, the minibuffer! */
1992 while (CONSP (XCDR (windows
))
1993 && EQ (XWINDOW (XCAR (windows
))->frame
,
1994 XWINDOW (XCAR (XCDR (windows
)))->frame
))
1995 windows
= XCDR (windows
);
1997 /* Now we can safely delete the frame. */
1998 Fdelete_frame (w
->frame
, Qnil
);
2000 else if (!NILP (w
->dedicated
) && !NILP (w
->parent
))
2003 XSETWINDOW (window
, w
);
2004 /* If this window is dedicated and not the only window
2005 in its frame, then kill it. */
2006 Fdelete_window (window
);
2010 /* Otherwise show a different buffer in the window. */
2011 w
->dedicated
= Qnil
;
2012 Fset_window_buffer (window
, buffer
, Qnil
);
2013 if (EQ (window
, selected_window
))
2014 Fset_buffer (w
->buffer
);
2019 /* Check for a window that has a killed buffer. */
2020 case CHECK_ALL_WINDOWS
:
2021 if (! NILP (w
->buffer
)
2022 && NILP (XBUFFER (w
->buffer
)->name
))
2026 case WINDOW_LOOP_UNUSED
:
2035 /* Used for debugging. Abort if any window has a dead buffer. */
2038 check_all_windows ()
2040 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2043 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 1, 0,
2044 doc
: /* Return the window least recently selected or used for display.
2045 If optional argument FRAME is `visible', search all visible frames.
2046 If FRAME is 0, search all visible and iconified frames.
2047 If FRAME is t, search all frames.
2048 If FRAME is nil, search only the selected frame.
2049 If FRAME is a frame, search only that frame. */)
2053 register Lisp_Object w
;
2054 /* First try for a window that is full-width */
2055 w
= window_loop (GET_LRU_WINDOW
, Qt
, 0, frame
);
2056 if (!NILP (w
) && !EQ (w
, selected_window
))
2058 /* If none of them, try the rest */
2059 return window_loop (GET_LRU_WINDOW
, Qnil
, 0, frame
);
2062 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 1, 0,
2063 doc
: /* Return the largest window in area.
2064 If optional argument FRAME is `visible', search all visible frames.
2065 If FRAME is 0, search all visible and iconified frames.
2066 If FRAME is t, search all frames.
2067 If FRAME is nil, search only the selected frame.
2068 If FRAME is a frame, search only that frame. */)
2072 return window_loop (GET_LARGEST_WINDOW
, Qnil
, 0,
2076 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
2077 doc
: /* Return a window currently displaying BUFFER, or nil if none.
2078 If optional argument FRAME is `visible', search all visible frames.
2079 If optional argument FRAME is 0, search all visible and iconified frames.
2080 If FRAME is t, search all frames.
2081 If FRAME is nil, search only the selected frame.
2082 If FRAME is a frame, search only that frame. */)
2084 Lisp_Object buffer
, frame
;
2086 buffer
= Fget_buffer (buffer
);
2087 if (BUFFERP (buffer
))
2088 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
2093 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
2095 doc
: /* Make WINDOW (or the selected window) fill its frame.
2096 Only the frame WINDOW is on is affected.
2097 This function tries to reduce display jumps
2098 by keeping the text previously visible in WINDOW
2099 in the same place on the frame. Doing this depends on
2100 the value of (window-start WINDOW), so if calling this function
2101 in a program gives strange scrolling, make sure the window-start
2102 value is reasonable when this function is called. */)
2111 window
= selected_window
;
2113 CHECK_LIVE_WINDOW (window
);
2114 w
= XWINDOW (window
);
2116 startpos
= marker_position (w
->start
);
2117 top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2119 if (MINI_WINDOW_P (w
) && top
> 0)
2120 error ("Can't expand minibuffer to full frame");
2122 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
2124 /* Try to minimize scrolling, by setting the window start to the point
2125 will cause the text at the old window start to be at the same place
2126 on the frame. But don't try to do this if the window start is
2127 outside the visible portion (as might happen when the display is
2128 not current, due to typeahead). */
2129 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2131 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2132 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2134 struct position pos
;
2135 struct buffer
*obuf
= current_buffer
;
2137 Fset_buffer (w
->buffer
);
2138 /* This computation used to temporarily move point, but that can
2139 have unwanted side effects due to text properties. */
2140 pos
= *vmotion (startpos
, -top
, w
);
2142 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2143 w
->window_end_valid
= Qnil
;
2144 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
2145 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
2147 /* We need to do this, so that the window-scroll-functions
2149 w
->optional_new_start
= Qt
;
2151 set_buffer_internal (obuf
);
2157 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
2158 1, 2, "bDelete windows on (buffer): ",
2159 doc
: /* Delete all windows showing BUFFER.
2160 Optional second argument FRAME controls which frames are affected.
2161 If optional argument FRAME is `visible', search all visible frames.
2162 If FRAME is 0, search all visible and iconified frames.
2163 If FRAME is nil, search all frames.
2164 If FRAME is t, search only the selected frame.
2165 If FRAME is a frame, search only that frame. */)
2167 Lisp_Object buffer
, frame
;
2169 /* FRAME uses t and nil to mean the opposite of what window_loop
2173 else if (EQ (frame
, Qt
))
2178 buffer
= Fget_buffer (buffer
);
2179 CHECK_BUFFER (buffer
);
2180 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
2186 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
2187 Sreplace_buffer_in_windows
,
2188 1, 1, "bReplace buffer in windows: ",
2189 doc
: /* Replace BUFFER with some other buffer in all windows showing it. */)
2195 buffer
= Fget_buffer (buffer
);
2196 CHECK_BUFFER (buffer
);
2197 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
2202 /* Replace BUFFER with some other buffer in all windows
2203 of all frames, even those on other keyboards. */
2206 replace_buffer_in_all_windows (buffer
)
2210 Lisp_Object tail
, frame
;
2212 /* A single call to window_loop won't do the job
2213 because it only considers frames on the current keyboard.
2214 So loop manually over frames, and handle each one. */
2215 FOR_EACH_FRAME (tail
, frame
)
2216 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
2218 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
2222 /* Set the height of WINDOW and all its inferiors. */
2224 /* The smallest acceptable dimensions for a window. Anything smaller
2225 might crash Emacs. */
2227 #define MIN_SAFE_WINDOW_WIDTH (2)
2228 #define MIN_SAFE_WINDOW_HEIGHT (1)
2230 /* Make sure that window_min_height and window_min_width are
2231 not too small; if they are, set them to safe minima. */
2234 check_min_window_sizes ()
2236 /* Smaller values might permit a crash. */
2237 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
2238 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
2239 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
2240 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
2243 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2244 minimum allowable size. */
2247 check_frame_size (frame
, rows
, cols
)
2251 /* For height, we have to see:
2252 how many windows the frame has at minimum (one or two),
2253 and whether it has a menu bar or other special stuff at the top. */
2255 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
2256 ? MIN_SAFE_WINDOW_HEIGHT
2257 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
2259 if (FRAME_TOP_MARGIN (frame
) > 0)
2260 min_height
+= FRAME_TOP_MARGIN (frame
);
2262 if (*rows
< min_height
)
2264 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2265 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2269 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2270 check if W's width can be changed, otherwise check W's height.
2271 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2272 siblings, too. If none of the siblings is resizable, WINDOW isn't
2276 window_fixed_size_p (w
, width_p
, check_siblings_p
)
2278 int width_p
, check_siblings_p
;
2283 if (!NILP (w
->hchild
))
2285 c
= XWINDOW (w
->hchild
);
2289 /* A horiz. combination is fixed-width if all of if its
2291 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2292 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2293 fixed_p
= c
== NULL
;
2297 /* A horiz. combination is fixed-height if one of if its
2299 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2300 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2301 fixed_p
= c
!= NULL
;
2304 else if (!NILP (w
->vchild
))
2306 c
= XWINDOW (w
->vchild
);
2310 /* A vert. combination is fixed-width if one of if its
2312 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2313 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2314 fixed_p
= c
!= NULL
;
2318 /* A vert. combination is fixed-height if all of if its
2320 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2321 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2322 fixed_p
= c
== NULL
;
2325 else if (BUFFERP (w
->buffer
))
2327 if (w
->height_fixed_p
&& !width_p
)
2331 struct buffer
*old
= current_buffer
;
2334 current_buffer
= XBUFFER (w
->buffer
);
2335 val
= find_symbol_value (Qwindow_size_fixed
);
2336 current_buffer
= old
;
2339 if (!EQ (val
, Qunbound
))
2341 fixed_p
= !NILP (val
);
2344 && ((EQ (val
, Qheight
) && width_p
)
2345 || (EQ (val
, Qwidth
) && !width_p
)))
2350 /* Can't tell if this one is resizable without looking at
2351 siblings. If all siblings are fixed-size this one is too. */
2352 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
2356 for (child
= w
->prev
; !NILP (child
); child
= XWINDOW (child
)->prev
)
2357 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2361 for (child
= w
->next
; !NILP (child
); child
= XWINDOW (child
)->next
)
2362 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2376 /* Return the minimum size of window W, not taking fixed-width windows
2377 into account. WIDTH_P non-zero means return the minimum width,
2378 otherwise return the minimum height. If W is a combination window,
2379 compute the minimum size from the minimum sizes of W's children. */
2382 window_min_size_1 (w
, width_p
)
2389 if (!NILP (w
->hchild
))
2391 c
= XWINDOW (w
->hchild
);
2396 /* The min width of a horizontal combination is
2397 the sum of the min widths of its children. */
2400 size
+= window_min_size_1 (c
, width_p
);
2401 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2406 /* The min height a horizontal combination equals
2407 the maximum of all min height of its children. */
2410 int min_size
= window_min_size_1 (c
, width_p
);
2411 size
= max (min_size
, size
);
2412 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2416 else if (!NILP (w
->vchild
))
2418 c
= XWINDOW (w
->vchild
);
2423 /* The min width of a vertical combination is
2424 the maximum of the min widths of its children. */
2427 int min_size
= window_min_size_1 (c
, width_p
);
2428 size
= max (min_size
, size
);
2429 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2434 /* The min height of a vertical combination equals
2435 the sum of the min height of its children. */
2438 size
+= window_min_size_1 (c
, width_p
);
2439 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2446 size
= window_min_width
;
2449 if (MINI_WINDOW_P (w
)
2450 || (!WINDOW_WANTS_MODELINE_P (w
)
2451 && !WINDOW_WANTS_HEADER_LINE_P (w
)))
2454 size
= window_min_height
;
2462 /* Return the minimum size of window W, taking fixed-size windows into
2463 account. WIDTH_P non-zero means return the minimum width,
2464 otherwise return the minimum height. IGNORE_FIXED_P non-zero means
2465 ignore if W is fixed-size. Set *FIXED to 1 if W is fixed-size
2466 unless FIXED is null. */
2469 window_min_size (w
, width_p
, ignore_fixed_p
, fixed
)
2471 int width_p
, ignore_fixed_p
, *fixed
;
2478 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
2484 size
= width_p
? XFASTINT (w
->total_cols
) : XFASTINT (w
->total_lines
);
2486 size
= window_min_size_1 (w
, width_p
);
2492 /* Adjust the margins of window W if text area is too small.
2493 Return 1 if window width is ok after adjustment; 0 if window
2494 is still too narrow. */
2497 adjust_window_margins (w
)
2500 int box_cols
= (WINDOW_TOTAL_COLS (w
)
2501 - WINDOW_FRINGE_COLS (w
)
2502 - WINDOW_SCROLL_BAR_COLS (w
));
2503 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
2504 + WINDOW_RIGHT_MARGIN_COLS (w
));
2506 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
2509 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
2512 /* Window's text area is too narrow, but reducing the window
2513 margins will fix that. */
2514 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
2515 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
2517 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
2518 w
->left_margin_cols
= w
->right_margin_cols
2519 = make_number (margin_cols
/2);
2521 w
->right_margin_cols
= make_number (margin_cols
);
2524 w
->left_margin_cols
= make_number (margin_cols
);
2529 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
2530 WINDOW's width. Resize WINDOW's children, if any, so that they
2531 keep their proportionate size relative to WINDOW. Propagate
2532 WINDOW's top or left edge position to children. Delete windows
2533 that become too small unless NODELETE_P is non-zero.
2535 If NODELETE_P is 2, that means we do delete windows that are
2536 too small, even if they were too small before! */
2539 size_window (window
, size
, width_p
, nodelete_p
)
2541 int size
, width_p
, nodelete_p
;
2543 struct window
*w
= XWINDOW (window
);
2545 Lisp_Object child
, *forward
, *sideward
;
2546 int old_size
, min_size
, safe_min_size
;
2548 /* We test nodelete_p != 2 and nodelete_p != 1 below, so it
2549 seems like it's too soon to do this here. ++KFS. */
2550 if (nodelete_p
== 2)
2553 check_min_window_sizes ();
2554 size
= max (0, size
);
2556 /* If the window has been "too small" at one point,
2557 don't delete it for being "too small" in the future.
2558 Preserve it as long as that is at all possible. */
2561 old_size
= WINDOW_TOTAL_COLS (w
);
2562 min_size
= window_min_width
;
2563 /* Ensure that there is room for the scroll bar and fringes!
2564 We may reduce display margins though. */
2565 safe_min_size
= (MIN_SAFE_WINDOW_WIDTH
2566 + WINDOW_FRINGE_COLS (w
)
2567 + WINDOW_SCROLL_BAR_COLS (w
));
2571 old_size
= XINT (w
->total_lines
);
2572 min_size
= window_min_height
;
2573 safe_min_size
= MIN_SAFE_WINDOW_HEIGHT
;
2576 if (old_size
< min_size
&& nodelete_p
!= 2)
2577 w
->too_small_ok
= Qt
;
2579 /* Maybe delete WINDOW if it's too small. */
2580 if (nodelete_p
!= 1 && !NILP (w
->parent
))
2582 if (!MINI_WINDOW_P (w
) && !NILP (w
->too_small_ok
))
2583 min_size
= width_p
? MIN_SAFE_WINDOW_WIDTH
: MIN_SAFE_WINDOW_HEIGHT
;
2584 if (min_size
< safe_min_size
)
2585 min_size
= safe_min_size
;
2586 if (size
< min_size
)
2588 delete_window (window
);
2593 /* Set redisplay hints. */
2594 w
->last_modified
= make_number (0);
2595 w
->last_overlay_modified
= make_number (0);
2596 windows_or_buffers_changed
++;
2597 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w
->frame
)) = 1;
2601 sideward
= &w
->vchild
;
2602 forward
= &w
->hchild
;
2603 w
->total_cols
= make_number (size
);
2604 adjust_window_margins (w
);
2608 sideward
= &w
->hchild
;
2609 forward
= &w
->vchild
;
2610 w
->total_lines
= make_number (size
);
2611 w
->orig_total_lines
= Qnil
;
2614 if (!NILP (*sideward
))
2616 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
2618 c
= XWINDOW (child
);
2620 c
->left_col
= w
->left_col
;
2622 c
->top_line
= w
->top_line
;
2623 size_window (child
, size
, width_p
, nodelete_p
);
2626 else if (!NILP (*forward
))
2628 int fixed_size
, each
, extra
, n
;
2629 int resize_fixed_p
, nfixed
;
2630 int last_pos
, first_pos
, nchildren
, total
;
2632 /* Determine the fixed-size portion of the this window, and the
2633 number of child windows. */
2634 fixed_size
= nchildren
= nfixed
= total
= 0;
2635 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
2639 c
= XWINDOW (child
);
2640 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2641 total
+= child_size
;
2643 if (window_fixed_size_p (c
, width_p
, 0))
2645 fixed_size
+= child_size
;
2650 /* If the new size is smaller than fixed_size, or if there
2651 aren't any resizable windows, allow resizing fixed-size
2653 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
2655 /* Compute how many lines/columns to add to each child. The
2656 value of extra takes care of rounding errors. */
2657 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
2658 each
= (size
- total
) / n
;
2659 extra
= (size
- total
) - n
* each
;
2661 /* Compute new children heights and edge positions. */
2662 first_pos
= width_p
? XINT (w
->left_col
) : XINT (w
->top_line
);
2663 last_pos
= first_pos
;
2664 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2666 int new_size
, old_size
;
2668 c
= XWINDOW (child
);
2669 old_size
= width_p
? XFASTINT (c
->total_cols
) : XFASTINT (c
->total_lines
);
2670 new_size
= old_size
;
2672 /* The top or left edge position of this child equals the
2673 bottom or right edge of its predecessor. */
2675 c
->left_col
= make_number (last_pos
);
2677 c
->top_line
= make_number (last_pos
);
2679 /* If this child can be resized, do it. */
2680 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
2682 new_size
= old_size
+ each
+ extra
;
2686 /* Set new height. Note that size_window also propagates
2687 edge positions to children, so it's not a no-op if we
2688 didn't change the child's size. */
2689 size_window (child
, new_size
, width_p
, 1);
2691 /* Remember the bottom/right edge position of this child; it
2692 will be used to set the top/left edge of the next child. */
2693 last_pos
+= new_size
;
2696 /* We should have covered the parent exactly with child windows. */
2697 xassert (size
== last_pos
- first_pos
);
2699 /* Now delete any children that became too small. */
2701 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2704 c
= XWINDOW (child
);
2705 child_size
= width_p
? XINT (c
->total_cols
) : XINT (c
->total_lines
);
2706 size_window (child
, child_size
, width_p
, 2);
2711 /* Set WINDOW's height to HEIGHT, and recursively change the height of
2712 WINDOW's children. NODELETE non-zero means don't delete windows
2713 that become too small in the process. (The caller should check
2714 later and do so if appropriate.) */
2717 set_window_height (window
, height
, nodelete
)
2722 size_window (window
, height
, 0, nodelete
);
2726 /* Set WINDOW's width to WIDTH, and recursively change the width of
2727 WINDOW's children. NODELETE non-zero means don't delete windows
2728 that become too small in the process. (The caller should check
2729 later and do so if appropriate.) */
2732 set_window_width (window
, width
, nodelete
)
2737 size_window (window
, width
, 1, nodelete
);
2740 /* Change window heights in windows rooted in WINDOW by N lines. */
2743 change_window_heights (window
, n
)
2747 struct window
*w
= XWINDOW (window
);
2749 XSETFASTINT (w
->top_line
, XFASTINT (w
->top_line
) + n
);
2750 XSETFASTINT (w
->total_lines
, XFASTINT (w
->total_lines
) - n
);
2752 if (INTEGERP (w
->orig_top_line
))
2753 XSETFASTINT (w
->orig_top_line
, XFASTINT (w
->orig_top_line
) + n
);
2754 if (INTEGERP (w
->orig_total_lines
))
2755 XSETFASTINT (w
->orig_total_lines
, XFASTINT (w
->orig_total_lines
) - n
);
2757 /* Handle just the top child in a vertical split. */
2758 if (!NILP (w
->vchild
))
2759 change_window_heights (w
->vchild
, n
);
2761 /* Adjust all children in a horizontal split. */
2762 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
2764 w
= XWINDOW (window
);
2765 change_window_heights (window
, n
);
2770 int window_select_count
;
2773 Fset_window_buffer_unwind (obuf
)
2780 EXFUN (Fset_window_fringes
, 4);
2781 EXFUN (Fset_window_scroll_bars
, 4);
2783 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
2784 means it's allowed to run hooks. See make_frame for a case where
2785 it's not allowed. KEEP_MARGINS_P non-zero means that the current
2786 margins, fringes, and scroll-bar settings of the window are not
2787 reset from the buffer's local settings. */
2790 set_window_buffer (window
, buffer
, run_hooks_p
, keep_margins_p
)
2791 Lisp_Object window
, buffer
;
2792 int run_hooks_p
, keep_margins_p
;
2794 struct window
*w
= XWINDOW (window
);
2795 struct buffer
*b
= XBUFFER (buffer
);
2796 int count
= SPECPDL_INDEX ();
2800 if (EQ (window
, selected_window
))
2801 b
->last_selected_window
= window
;
2803 /* Update time stamps of buffer display. */
2804 if (INTEGERP (b
->display_count
))
2805 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
2806 b
->display_time
= Fcurrent_time ();
2808 XSETFASTINT (w
->window_end_pos
, 0);
2809 XSETFASTINT (w
->window_end_vpos
, 0);
2810 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
2811 w
->window_end_valid
= Qnil
;
2812 w
->hscroll
= w
->min_hscroll
= make_number (0);
2814 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
2815 set_marker_restricted (w
->start
,
2816 make_number (b
->last_window_start
),
2818 w
->start_at_line_beg
= Qnil
;
2819 w
->force_start
= Qnil
;
2820 XSETFASTINT (w
->last_modified
, 0);
2821 XSETFASTINT (w
->last_overlay_modified
, 0);
2822 windows_or_buffers_changed
++;
2824 /* We must select BUFFER for running the window-scroll-functions.
2825 If WINDOW is selected, switch permanently.
2826 Otherwise, switch but go back to the ambient buffer afterward. */
2827 if (EQ (window
, selected_window
))
2828 Fset_buffer (buffer
);
2829 /* We can't check ! NILP (Vwindow_scroll_functions) here
2830 because that might itself be a local variable. */
2831 else if (window_initialized
)
2833 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
2834 Fset_buffer (buffer
);
2837 if (!keep_margins_p
)
2839 /* Set left and right marginal area width etc. from buffer. */
2841 /* This may call adjust_window_margins three times, so
2842 temporarily disable window margins. */
2843 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
2845 Fset_window_fringes (window
,
2846 b
->left_fringe_width
, b
->right_fringe_width
,
2847 b
->fringes_outside_margins
);
2849 Fset_window_scroll_bars (window
,
2850 b
->scroll_bar_width
,
2851 b
->vertical_scroll_bar_type
, Qnil
);
2853 Fset_window_margins (window
,
2854 b
->left_margin_cols
, b
->right_margin_cols
);
2859 if (! NILP (Vwindow_scroll_functions
))
2860 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2861 Fmarker_position (w
->start
));
2863 if (! NILP (Vwindow_configuration_change_hook
)
2864 && ! NILP (Vrun_hooks
))
2865 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2868 unbind_to (count
, Qnil
);
2872 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
2873 doc
: /* Make WINDOW display BUFFER as its contents.
2874 BUFFER can be a buffer or buffer name.
2875 Optional third arg KEEP_MARGINS non-nil means that WINDOW's current
2876 display margins, fringe widths, and scroll bar settings are maintained;
2877 the default is to reset these from BUFFER's local settings or the frame
2879 (window
, buffer
, keep_margins
)
2880 register Lisp_Object window
, buffer
, keep_margins
;
2882 register Lisp_Object tem
;
2883 register struct window
*w
= decode_window (window
);
2885 XSETWINDOW (window
, w
);
2886 buffer
= Fget_buffer (buffer
);
2887 CHECK_BUFFER (buffer
);
2889 if (NILP (XBUFFER (buffer
)->name
))
2890 error ("Attempt to display deleted buffer");
2894 error ("Window is deleted");
2895 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
2896 is first being set up. */
2898 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
2899 error ("Window is dedicated to `%s'",
2900 SDATA (XBUFFER (tem
)->name
));
2905 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
2909 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
2910 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
2911 If WINDOW is not already selected, also make WINDOW's buffer current.
2912 Also make WINDOW the frame's selected window.
2913 Optional second arg NORECORD non-nil means
2914 do not put this buffer at the front of the list of recently selected ones.
2916 Note that the main editor command loop
2917 selects the buffer of the selected window before each command. */)
2919 register Lisp_Object window
, norecord
;
2921 register struct window
*w
;
2922 register struct window
*ow
;
2925 CHECK_LIVE_WINDOW (window
);
2927 w
= XWINDOW (window
);
2928 w
->frozen_window_start_p
= 0;
2930 XSETFASTINT (w
->use_time
, ++window_select_count
);
2931 if (EQ (window
, selected_window
))
2934 if (!NILP (selected_window
))
2936 ow
= XWINDOW (selected_window
);
2937 if (! NILP (ow
->buffer
))
2938 set_marker_both (ow
->pointm
, ow
->buffer
,
2939 BUF_PT (XBUFFER (ow
->buffer
)),
2940 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
2943 selected_window
= window
;
2944 sf
= SELECTED_FRAME ();
2945 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
2947 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
2948 /* Use this rather than Fhandle_switch_frame
2949 so that FRAME_FOCUS_FRAME is moved appropriately as we
2950 move around in the state where a minibuffer in a separate
2952 Fselect_frame (WINDOW_FRAME (w
), Qnil
);
2955 sf
->selected_window
= window
;
2957 if (NILP (norecord
))
2958 record_buffer (w
->buffer
);
2959 Fset_buffer (w
->buffer
);
2961 XBUFFER (w
->buffer
)->last_selected_window
= window
;
2963 /* Go to the point recorded in the window.
2964 This is important when the buffer is in more
2965 than one window. It also matters when
2966 redisplay_window has altered point after scrolling,
2967 because it makes the change only in the window. */
2969 register int new_point
= marker_position (w
->pointm
);
2970 if (new_point
< BEGV
)
2972 else if (new_point
> ZV
)
2978 windows_or_buffers_changed
++;
2983 select_window_norecord (window
)
2986 return Fselect_window (window
, Qt
);
2989 /* Deiconify the frame containing the window WINDOW,
2990 unless it is the selected frame;
2993 The reason for the exception for the selected frame
2994 is that it seems better not to change the selected frames visibility
2995 merely because of displaying a different buffer in it.
2996 The deiconification is useful when a buffer gets shown in
2997 another frame that you were not using lately. */
3000 display_buffer_1 (window
)
3003 Lisp_Object frame
= XWINDOW (window
)->frame
;
3004 FRAME_PTR f
= XFRAME (frame
);
3006 FRAME_SAMPLE_VISIBILITY (f
);
3008 if (!EQ (frame
, selected_frame
))
3010 if (FRAME_ICONIFIED_P (f
))
3011 Fmake_frame_visible (frame
);
3012 else if (FRAME_VISIBLE_P (f
))
3013 Fraise_frame (frame
);
3019 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
3020 doc
: /* Returns non-nil if a buffer named BUFFER-NAME would be created specially.
3021 The value is actually t if the frame should be called with default frame
3022 parameters, and a list of frame parameters if they were specified.
3023 See `special-display-buffer-names', and `special-display-regexps'. */)
3025 Lisp_Object buffer_name
;
3029 CHECK_STRING (buffer_name
);
3031 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
3035 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
3039 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
3041 Lisp_Object car
= XCAR (tem
);
3043 && fast_string_match (car
, buffer_name
) >= 0)
3045 else if (CONSP (car
)
3046 && STRINGP (XCAR (car
))
3047 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
3053 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
3054 doc
: /* Returns non-nil if a new buffer named BUFFER-NAME would use the same window.
3055 See `same-window-buffer-names' and `same-window-regexps'. */)
3057 Lisp_Object buffer_name
;
3061 CHECK_STRING (buffer_name
);
3063 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
3067 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
3071 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
3073 Lisp_Object car
= XCAR (tem
);
3075 && fast_string_match (car
, buffer_name
) >= 0)
3077 else if (CONSP (car
)
3078 && STRINGP (XCAR (car
))
3079 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
3085 /* Use B so the default is (other-buffer). */
3086 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
3087 "BDisplay buffer: \nP",
3088 doc
: /* Make BUFFER appear in some window but don't select it.
3089 BUFFER can be a buffer or a buffer name.
3090 If BUFFER is shown already in some window, just use that one,
3091 unless the window is the selected window and the optional second
3092 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).
3093 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
3094 Returns the window displaying BUFFER.
3095 If `display-buffer-reuse-frames' is non-nil, and another frame is currently
3096 displaying BUFFER, then simply raise that frame.
3098 The variables `special-display-buffer-names', `special-display-regexps',
3099 `same-window-buffer-names', and `same-window-regexps' customize how certain
3100 buffer names are handled.
3102 If optional argument FRAME is `visible', search all visible frames.
3103 If FRAME is 0, search all visible and iconified frames.
3104 If FRAME is t, search all frames.
3105 If FRAME is a frame, search only that frame.
3106 If FRAME is nil, search only the selected frame
3107 (actually the last nonminibuffer frame),
3108 unless `pop-up-frames' or `display-buffer-reuse-frames' is non-nil,
3109 which means search visible and iconified frames.
3111 If `even-window-heights' is non-nil, window heights will be evened out
3112 if displaying the buffer causes two vertically adjacent windows to be
3114 (buffer
, not_this_window
, frame
)
3115 register Lisp_Object buffer
, not_this_window
, frame
;
3117 register Lisp_Object window
, tem
, swp
;
3121 buffer
= Fget_buffer (buffer
);
3122 CHECK_BUFFER (buffer
);
3124 if (!NILP (Vdisplay_buffer_function
))
3125 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
3127 if (NILP (not_this_window
)
3128 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
3129 return display_buffer_1 (selected_window
);
3131 /* See if the user has specified this buffer should appear
3132 in the selected window. */
3133 if (NILP (not_this_window
))
3135 swp
= Fsame_window_p (XBUFFER (buffer
)->name
);
3136 if (!NILP (swp
) && !no_switch_window (selected_window
))
3138 Fswitch_to_buffer (buffer
, Qnil
);
3139 return display_buffer_1 (selected_window
);
3143 /* If the user wants pop-up-frames or display-buffer-reuse-frames,
3144 look for a window showing BUFFER on any visible or iconified frame.
3145 Otherwise search only the current frame. */
3148 else if (pop_up_frames
3149 || display_buffer_reuse_frames
3150 || last_nonminibuf_frame
== 0)
3151 XSETFASTINT (tem
, 0);
3153 XSETFRAME (tem
, last_nonminibuf_frame
);
3155 window
= Fget_buffer_window (buffer
, tem
);
3157 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
3158 return display_buffer_1 (window
);
3160 /* Certain buffer names get special handling. */
3161 if (!NILP (Vspecial_display_function
) && NILP (swp
))
3163 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
3165 return call1 (Vspecial_display_function
, buffer
);
3167 return call2 (Vspecial_display_function
, buffer
, tem
);
3170 /* If there are no frames open that have more than a minibuffer,
3171 we need to create a new frame. */
3172 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
3174 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3175 Fset_window_buffer (window
, buffer
, Qnil
);
3176 return display_buffer_1 (window
);
3179 f
= SELECTED_FRAME ();
3181 || FRAME_MINIBUF_ONLY_P (f
)
3182 /* If the current frame is a special display frame,
3183 don't try to reuse its windows. */
3184 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (f
))->dedicated
))
3189 if (FRAME_MINIBUF_ONLY_P (f
))
3190 XSETFRAME (frames
, last_nonminibuf_frame
);
3191 /* Don't try to create a window if we would get an error. */
3192 if (split_height_threshold
< window_min_height
<< 1)
3193 split_height_threshold
= window_min_height
<< 1;
3195 /* Note that both Fget_largest_window and Fget_lru_window
3196 ignore minibuffers and dedicated windows.
3197 This means they can return nil. */
3199 /* If the frame we would try to split cannot be split,
3200 try other frames. */
3201 if (FRAME_NO_SPLIT_P (NILP (frames
) ? f
: last_nonminibuf_frame
))
3203 /* Try visible frames first. */
3204 window
= Fget_largest_window (Qvisible
);
3205 /* If that didn't work, try iconified frames. */
3207 window
= Fget_largest_window (make_number (0));
3209 window
= Fget_largest_window (Qt
);
3212 window
= Fget_largest_window (frames
);
3214 /* If we got a tall enough full-width window that can be split,
3217 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3218 && window_height (window
) >= split_height_threshold
3219 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
3220 window
= Fsplit_window (window
, Qnil
, Qnil
);
3223 Lisp_Object upper
, lower
, other
;
3225 window
= Fget_lru_window (frames
);
3226 /* If the LRU window is selected, and big enough,
3227 and can be split, split it. */
3229 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3230 && (EQ (window
, selected_window
)
3231 || EQ (XWINDOW (window
)->parent
, Qnil
))
3232 && window_height (window
) >= window_min_height
<< 1)
3233 window
= Fsplit_window (window
, Qnil
, Qnil
);
3234 /* If Fget_lru_window returned nil, try other approaches. */
3236 /* Try visible frames first. */
3238 window
= Fget_buffer_window (buffer
, Qvisible
);
3240 window
= Fget_largest_window (Qvisible
);
3241 /* If that didn't work, try iconified frames. */
3243 window
= Fget_buffer_window (buffer
, make_number (0));
3245 window
= Fget_largest_window (make_number (0));
3246 /* Try invisible frames. */
3248 window
= Fget_buffer_window (buffer
, Qt
);
3250 window
= Fget_largest_window (Qt
);
3251 /* As a last resort, make a new frame. */
3253 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3254 /* If window appears above or below another,
3255 even out their heights. */
3256 other
= upper
= lower
= Qnil
;
3257 if (!NILP (XWINDOW (window
)->prev
))
3258 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
3259 if (!NILP (XWINDOW (window
)->next
))
3260 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
3262 && !NILP (Veven_window_heights
)
3263 /* Check that OTHER and WINDOW are vertically arrayed. */
3264 && !EQ (XWINDOW (other
)->top_line
, XWINDOW (window
)->top_line
)
3265 && (XFASTINT (XWINDOW (other
)->total_lines
)
3266 > XFASTINT (XWINDOW (window
)->total_lines
)))
3268 int total
= (XFASTINT (XWINDOW (other
)->total_lines
)
3269 + XFASTINT (XWINDOW (window
)->total_lines
));
3270 enlarge_window (upper
,
3271 total
/ 2 - XFASTINT (XWINDOW (upper
)->total_lines
),
3277 window
= Fget_lru_window (Qnil
);
3279 Fset_window_buffer (window
, buffer
, Qnil
);
3280 return display_buffer_1 (window
);
3284 temp_output_buffer_show (buf
)
3285 register Lisp_Object buf
;
3287 register struct buffer
*old
= current_buffer
;
3288 register Lisp_Object window
;
3289 register struct window
*w
;
3291 XBUFFER (buf
)->directory
= current_buffer
->directory
;
3294 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3298 #if 0 /* rms: there should be no reason for this. */
3299 XBUFFER (buf
)->prevent_redisplay_optimizations_p
= 1;
3301 set_buffer_internal (old
);
3303 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
3304 call1 (Vtemp_buffer_show_function
, buf
);
3307 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
3309 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3310 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3311 Vminibuf_scroll_window
= window
;
3312 w
= XWINDOW (window
);
3313 XSETFASTINT (w
->hscroll
, 0);
3314 XSETFASTINT (w
->min_hscroll
, 0);
3315 set_marker_restricted_both (w
->start
, buf
, 1, 1);
3316 set_marker_restricted_both (w
->pointm
, buf
, 1, 1);
3318 /* Run temp-buffer-show-hook, with the chosen window selected
3319 and its buffer current. */
3320 if (!NILP (Vrun_hooks
))
3323 tem
= Fboundp (Qtemp_buffer_show_hook
);
3326 tem
= Fsymbol_value (Qtemp_buffer_show_hook
);
3329 int count
= SPECPDL_INDEX ();
3330 Lisp_Object prev_window
, prev_buffer
;
3331 prev_window
= selected_window
;
3332 XSETBUFFER (prev_buffer
, old
);
3334 /* Select the window that was chosen, for running the hook.
3335 Note: Both Fselect_window and select_window_norecord may
3336 set-buffer to the buffer displayed in the window,
3337 so we need to save the current buffer. --stef */
3338 record_unwind_protect (Fset_buffer
, prev_buffer
);
3339 record_unwind_protect (select_window_norecord
, prev_window
);
3340 Fselect_window (window
, Qt
);
3341 Fset_buffer (w
->buffer
);
3342 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
3343 unbind_to (count
, Qnil
);
3351 make_dummy_parent (window
)
3355 register struct window
*o
, *p
;
3358 o
= XWINDOW (window
);
3359 p
= allocate_window ();
3360 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
3361 ((struct Lisp_Vector
*) p
)->contents
[i
]
3362 = ((struct Lisp_Vector
*)o
)->contents
[i
];
3363 XSETWINDOW (new, p
);
3365 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
3367 /* Put new into window structure in place of window */
3368 replace_window (window
, new);
3381 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
3382 doc
: /* Split WINDOW, putting SIZE lines in the first of the pair.
3383 WINDOW defaults to selected one and SIZE to half its size.
3384 If optional third arg HORFLAG is non-nil, split side by side
3385 and put SIZE columns in the first of the pair. In that case,
3386 SIZE includes that window's scroll bar, or the divider column to its right. */)
3387 (window
, size
, horflag
)
3388 Lisp_Object window
, size
, horflag
;
3390 register Lisp_Object
new;
3391 register struct window
*o
, *p
;
3393 register int size_int
;
3396 window
= selected_window
;
3398 CHECK_LIVE_WINDOW (window
);
3400 o
= XWINDOW (window
);
3401 fo
= XFRAME (WINDOW_FRAME (o
));
3405 if (!NILP (horflag
))
3406 /* Calculate the size of the left-hand window, by dividing
3407 the usable space in columns by two.
3408 We round up, since the left-hand window may include
3409 a dividing line, while the right-hand may not. */
3410 size_int
= (XFASTINT (o
->total_cols
) + 1) >> 1;
3412 size_int
= XFASTINT (o
->total_lines
) >> 1;
3416 CHECK_NUMBER (size
);
3417 size_int
= XINT (size
);
3420 if (MINI_WINDOW_P (o
))
3421 error ("Attempt to split minibuffer window");
3422 else if (window_fixed_size_p (o
, !NILP (horflag
), 0))
3423 error ("Attempt to split fixed-size window");
3425 check_min_window_sizes ();
3429 if (size_int
< window_min_height
)
3430 error ("Window height %d too small (after splitting)", size_int
);
3431 if (size_int
+ window_min_height
> XFASTINT (o
->total_lines
))
3432 error ("Window height %d too small (after splitting)",
3433 XFASTINT (o
->total_lines
) - size_int
);
3434 if (NILP (o
->parent
)
3435 || NILP (XWINDOW (o
->parent
)->vchild
))
3437 make_dummy_parent (window
);
3439 XWINDOW (new)->vchild
= window
;
3444 if (size_int
< window_min_width
)
3445 error ("Window width %d too small (after splitting)", size_int
);
3447 if (size_int
+ window_min_width
> XFASTINT (o
->total_cols
))
3448 error ("Window width %d too small (after splitting)",
3449 XFASTINT (o
->total_cols
) - size_int
);
3450 if (NILP (o
->parent
)
3451 || NILP (XWINDOW (o
->parent
)->hchild
))
3453 make_dummy_parent (window
);
3455 XWINDOW (new)->hchild
= window
;
3459 /* Now we know that window's parent is a vertical combination
3460 if we are dividing vertically, or a horizontal combination
3461 if we are making side-by-side windows */
3463 windows_or_buffers_changed
++;
3464 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
3465 new = make_window ();
3468 p
->frame
= o
->frame
;
3470 if (!NILP (p
->next
))
3471 XWINDOW (p
->next
)->prev
= new;
3474 p
->parent
= o
->parent
;
3476 p
->window_end_valid
= Qnil
;
3477 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
3479 /* Duplicate special geometry settings. */
3481 p
->left_margin_cols
= o
->left_margin_cols
;
3482 p
->right_margin_cols
= o
->right_margin_cols
;
3483 p
->left_fringe_width
= o
->left_fringe_width
;
3484 p
->right_fringe_width
= o
->right_fringe_width
;
3485 p
->fringes_outside_margins
= o
->fringes_outside_margins
;
3486 p
->scroll_bar_width
= o
->scroll_bar_width
;
3487 p
->vertical_scroll_bar_type
= o
->vertical_scroll_bar_type
;
3489 /* Apportion the available frame space among the two new windows */
3491 if (!NILP (horflag
))
3493 p
->total_lines
= o
->total_lines
;
3494 p
->top_line
= o
->top_line
;
3495 XSETFASTINT (p
->total_cols
, XFASTINT (o
->total_cols
) - size_int
);
3496 XSETFASTINT (o
->total_cols
, size_int
);
3497 XSETFASTINT (p
->left_col
, XFASTINT (o
->left_col
) + size_int
);
3498 adjust_window_margins (p
);
3499 adjust_window_margins (o
);
3503 p
->left_col
= o
->left_col
;
3504 p
->total_cols
= o
->total_cols
;
3505 XSETFASTINT (p
->total_lines
, XFASTINT (o
->total_lines
) - size_int
);
3506 XSETFASTINT (o
->total_lines
, size_int
);
3507 XSETFASTINT (p
->top_line
, XFASTINT (o
->top_line
) + size_int
);
3510 /* Adjust glyph matrices. */
3513 Fset_window_buffer (new, o
->buffer
, Qt
);
3517 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 3, "p",
3518 doc
: /* Make current window ARG lines bigger.
3519 From program, optional second arg non-nil means grow sideways ARG columns.
3520 Interactively, if an argument is not given, make the window one line bigger.
3522 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3523 of the siblings above or to the left of the selected window. Only
3524 siblings to the right or below are changed. */)
3525 (arg
, side
, preserve_before
)
3526 register Lisp_Object arg
, side
, preserve_before
;
3529 enlarge_window (selected_window
, XINT (arg
), !NILP (side
),
3530 !NILP (preserve_before
));
3532 if (! NILP (Vwindow_configuration_change_hook
))
3533 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3538 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 3, "p",
3539 doc
: /* Make current window ARG lines smaller.
3540 From program, optional second arg non-nil means shrink sideways arg columns.
3541 Interactively, if an argument is not given, make the window one line smaller.
3543 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3544 of the siblings above or to the left of the selected window. Only
3545 siblings to the right or below are changed. */)
3546 (arg
, side
, preserve_before
)
3547 register Lisp_Object arg
, side
, preserve_before
;
3550 enlarge_window (selected_window
, -XINT (arg
), !NILP (side
),
3551 !NILP (preserve_before
));
3553 if (! NILP (Vwindow_configuration_change_hook
))
3554 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3560 window_height (window
)
3563 register struct window
*p
= XWINDOW (window
);
3564 return WINDOW_TOTAL_LINES (p
);
3568 window_width (window
)
3571 register struct window
*p
= XWINDOW (window
);
3572 return WINDOW_TOTAL_COLS (p
);
3577 *(widthflag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line))
3579 #define CURSIZE(w) \
3580 *(widthflag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines))
3583 /* Enlarge WINDOW by DELTA. WIDTHFLAG non-zero means
3584 increase its width. Siblings of the selected window are resized to
3585 fulfill the size request. If they become too small in the process,
3586 they will be deleted.
3588 If PRESERVE_BEFORE is nonzero, that means don't alter
3589 the siblings to the left or above WINDOW. */
3592 enlarge_window (window
, delta
, widthflag
, preserve_before
)
3594 int delta
, widthflag
, preserve_before
;
3596 Lisp_Object parent
, next
, prev
;
3600 int (*sizefun
) P_ ((Lisp_Object
))
3601 = widthflag
? window_width
: window_height
;
3602 void (*setsizefun
) P_ ((Lisp_Object
, int, int))
3603 = (widthflag
? set_window_width
: set_window_height
);
3605 /* Check values of window_min_width and window_min_height for
3607 check_min_window_sizes ();
3609 /* Give up if this window cannot be resized. */
3610 if (window_fixed_size_p (XWINDOW (window
), widthflag
, 1))
3611 error ("Window is not resizable");
3613 /* Find the parent of the selected window. */
3616 p
= XWINDOW (window
);
3622 error ("No other window to side of this one");
3627 ? !NILP (XWINDOW (parent
)->hchild
)
3628 : !NILP (XWINDOW (parent
)->vchild
))
3634 sizep
= &CURSIZE (window
);
3637 register int maxdelta
;
3639 /* Compute the maximum size increment this window can have. */
3641 if (preserve_before
)
3645 maxdelta
= (*sizefun
) (parent
) - XINT (*sizep
);
3646 /* Subtract size of siblings before, since we can't take that. */
3647 maxdelta
-= XINT (CURBEG (window
)) - XINT (CURBEG (parent
));
3650 maxdelta
= (!NILP (p
->next
) ? ((*sizefun
) (p
->next
)
3651 - window_min_size (XWINDOW (p
->next
),
3656 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - XINT (*sizep
)
3657 /* This is a main window followed by a minibuffer. */
3658 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
3659 - window_min_size (XWINDOW (p
->next
),
3661 /* This is a minibuffer following a main window. */
3662 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
3663 - window_min_size (XWINDOW (p
->prev
),
3665 /* This is a frame with only one window, a minibuffer-only
3666 or a minibufferless frame. */
3669 if (delta
> maxdelta
)
3670 /* This case traps trying to make the minibuffer
3671 the full frame, or make the only window aside from the
3672 minibuffer the full frame. */
3676 if (XINT (*sizep
) + delta
< window_min_size (XWINDOW (window
), widthflag
, 0, 0))
3678 delete_window (window
);
3685 /* Find the total we can get from other siblings without deleting them. */
3687 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
3688 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
3690 if (! preserve_before
)
3691 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
3692 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
3695 /* If we can get it all from them without deleting them, do so. */
3696 if (delta
<= maximum
)
3698 Lisp_Object first_unaffected
;
3699 Lisp_Object first_affected
;
3704 first_affected
= window
;
3705 /* Look at one sibling at a time,
3706 moving away from this window in both directions alternately,
3707 and take as much as we can get without deleting that sibling. */
3709 && (!NILP (next
) || (!preserve_before
&& !NILP (prev
))))
3713 int this_one
= ((*sizefun
) (next
)
3714 - window_min_size (XWINDOW (next
),
3715 widthflag
, 0, &fixed_p
));
3718 if (this_one
> delta
)
3721 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
3722 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
3727 next
= XWINDOW (next
)->next
;
3733 if (!preserve_before
&& ! NILP (prev
))
3735 int this_one
= ((*sizefun
) (prev
)
3736 - window_min_size (XWINDOW (prev
),
3737 widthflag
, 0, &fixed_p
));
3740 if (this_one
> delta
)
3743 first_affected
= prev
;
3745 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
3746 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
3751 prev
= XWINDOW (prev
)->prev
;
3755 xassert (delta
== 0);
3757 /* Now recalculate the edge positions of all the windows affected,
3758 based on the new sizes. */
3759 first_unaffected
= next
;
3760 prev
= first_affected
;
3761 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
3762 prev
= next
, next
= XWINDOW (next
)->next
)
3764 XSETINT (CURBEG (next
), XINT (CURBEG (prev
)) + (*sizefun
) (prev
));
3765 /* This does not change size of NEXT,
3766 but it propagates the new top edge to its children */
3767 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
3772 register int delta1
;
3773 register int opht
= (*sizefun
) (parent
);
3775 if (opht
<= XINT (*sizep
) + delta
)
3777 /* If trying to grow this window to or beyond size of the parent,
3778 just delete all the sibling windows. */
3779 Lisp_Object start
, tem
, next
;
3781 start
= XWINDOW (parent
)->vchild
;
3783 start
= XWINDOW (parent
)->hchild
;
3785 /* Delete any siblings that come after WINDOW. */
3786 tem
= XWINDOW (window
)->next
;
3787 while (! NILP (tem
))
3789 next
= XWINDOW (tem
)->next
;
3790 delete_window (tem
);
3794 /* Delete any siblings that come after WINDOW.
3795 Note that if START is not WINDOW, then WINDOW still
3796 Fhas siblings, so WINDOW has not yet replaced its parent. */
3798 while (! EQ (tem
, window
))
3800 next
= XWINDOW (tem
)->next
;
3801 delete_window (tem
);
3807 /* Otherwise, make delta1 just right so that if we add
3808 delta1 lines to this window and to the parent, and then
3809 shrink the parent back to its original size, the new
3810 proportional size of this window will increase by delta.
3812 The function size_window will compute the new height h'
3813 of the window from delta1 as:
3816 x = delta1 - delta1/n * n for the 1st resizable child
3819 where n is the number of children that can be resized.
3820 We can ignore x by choosing a delta1 that is a multiple of
3821 n. We want the height of this window to come out as
3831 The number of children n equals the number of resizable
3832 children of this window + 1 because we know window itself
3833 is resizable (otherwise we would have signalled an error. */
3835 struct window
*w
= XWINDOW (window
);
3839 for (s
= w
->next
; !NILP (s
); s
= XWINDOW (s
)->next
)
3840 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
3842 for (s
= w
->prev
; !NILP (s
); s
= XWINDOW (s
)->prev
)
3843 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
3848 /* Add delta1 lines or columns to this window, and to the parent,
3849 keeping things consistent while not affecting siblings. */
3850 XSETINT (CURSIZE (parent
), opht
+ delta1
);
3851 (*setsizefun
) (window
, XINT (*sizep
) + delta1
, 0);
3853 /* Squeeze out delta1 lines or columns from our parent,
3854 shriking this window and siblings proportionately.
3855 This brings parent back to correct size.
3856 Delta1 was calculated so this makes this window the desired size,
3857 taking it all out of the siblings. */
3858 (*setsizefun
) (parent
, opht
, 0);
3863 XSETFASTINT (p
->last_modified
, 0);
3864 XSETFASTINT (p
->last_overlay_modified
, 0);
3866 /* Adjust glyph matrices. */
3867 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
3875 /***********************************************************************
3876 Resizing Mini-Windows
3877 ***********************************************************************/
3879 static void shrink_window_lowest_first
P_ ((struct window
*, int));
3881 enum save_restore_action
3888 static int save_restore_orig_size
P_ ((struct window
*,
3889 enum save_restore_action
));
3891 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
3892 from lowest windows first. */
3895 shrink_window_lowest_first (w
, height
)
3903 xassert (!MINI_WINDOW_P (w
));
3905 /* Set redisplay hints. */
3906 XSETFASTINT (w
->last_modified
, 0);
3907 XSETFASTINT (w
->last_overlay_modified
, 0);
3908 windows_or_buffers_changed
++;
3909 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
3911 old_height
= XFASTINT (w
->total_lines
);
3912 XSETFASTINT (w
->total_lines
, height
);
3914 if (!NILP (w
->hchild
))
3916 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
3918 c
= XWINDOW (child
);
3919 c
->top_line
= w
->top_line
;
3920 shrink_window_lowest_first (c
, height
);
3923 else if (!NILP (w
->vchild
))
3925 Lisp_Object last_child
;
3926 int delta
= old_height
- height
;
3931 /* Find the last child. We are taking space from lowest windows
3932 first, so we iterate over children from the last child
3934 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
3937 /* Assign new heights. We leave only MIN_SAFE_WINDOW_HEIGHT. */
3938 for (child
= last_child
; delta
&& !NILP (child
); child
= c
->prev
)
3942 c
= XWINDOW (child
);
3943 this_one
= XFASTINT (c
->total_lines
) - MIN_SAFE_WINDOW_HEIGHT
;
3945 if (this_one
> delta
)
3948 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
) - this_one
);
3952 /* Compute new positions. */
3953 last_top
= XINT (w
->top_line
);
3954 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
3956 c
= XWINDOW (child
);
3957 c
->top_line
= make_number (last_top
);
3958 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
));
3959 last_top
+= XFASTINT (c
->total_lines
);
3965 /* Save, restore, or check positions and sizes in the window tree
3966 rooted at W. ACTION says what to do.
3968 If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and
3969 orig_total_lines members are valid for all windows in the window
3970 tree. Value is non-zero if they are valid.
3972 If ACTION is SAVE_ORIG_SIZES, save members top and height in
3973 orig_top_line and orig_total_lines for all windows in the tree.
3975 If ACTION is RESTORE_ORIG_SIZES, restore top and height from values
3976 stored in orig_top_line and orig_total_lines for all windows. */
3979 save_restore_orig_size (w
, action
)
3981 enum save_restore_action action
;
3987 if (!NILP (w
->hchild
))
3989 if (!save_restore_orig_size (XWINDOW (w
->hchild
), action
))
3992 else if (!NILP (w
->vchild
))
3994 if (!save_restore_orig_size (XWINDOW (w
->vchild
), action
))
4000 case CHECK_ORIG_SIZES
:
4001 if (!INTEGERP (w
->orig_top_line
) || !INTEGERP (w
->orig_total_lines
))
4005 case SAVE_ORIG_SIZES
:
4006 w
->orig_top_line
= w
->top_line
;
4007 w
->orig_total_lines
= w
->total_lines
;
4008 XSETFASTINT (w
->last_modified
, 0);
4009 XSETFASTINT (w
->last_overlay_modified
, 0);
4012 case RESTORE_ORIG_SIZES
:
4013 xassert (INTEGERP (w
->orig_top_line
) && INTEGERP (w
->orig_total_lines
));
4014 w
->top_line
= w
->orig_top_line
;
4015 w
->total_lines
= w
->orig_total_lines
;
4016 w
->orig_total_lines
= w
->orig_top_line
= Qnil
;
4017 XSETFASTINT (w
->last_modified
, 0);
4018 XSETFASTINT (w
->last_overlay_modified
, 0);
4025 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
4032 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
4033 without deleting other windows. */
4036 grow_mini_window (w
, delta
)
4040 struct frame
*f
= XFRAME (w
->frame
);
4041 struct window
*root
;
4043 xassert (MINI_WINDOW_P (w
));
4044 xassert (delta
>= 0);
4046 /* Check values of window_min_width and window_min_height for
4048 check_min_window_sizes ();
4050 /* Compute how much we can enlarge the mini-window without deleting
4052 root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4055 int min_height
= window_min_size (root
, 0, 0, 0);
4056 if (XFASTINT (root
->total_lines
) - delta
< min_height
)
4057 /* Note that the root window may already be smaller than
4059 delta
= max (0, XFASTINT (root
->total_lines
) - min_height
);
4064 /* Save original window sizes and positions, if not already done. */
4065 if (!save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4066 save_restore_orig_size (root
, SAVE_ORIG_SIZES
);
4068 /* Shrink other windows. */
4069 shrink_window_lowest_first (root
, XFASTINT (root
->total_lines
) - delta
);
4071 /* Grow the mini-window. */
4072 w
->top_line
= make_number (XFASTINT (root
->top_line
) + XFASTINT (root
->total_lines
));
4073 w
->total_lines
= make_number (XFASTINT (w
->total_lines
) + delta
);
4074 XSETFASTINT (w
->last_modified
, 0);
4075 XSETFASTINT (w
->last_overlay_modified
, 0);
4082 /* Shrink mini-window W. If there is recorded info about window sizes
4083 before a call to grow_mini_window, restore recorded window sizes.
4084 Otherwise, if the mini-window is higher than 1 line, resize it to 1
4088 shrink_mini_window (w
)
4091 struct frame
*f
= XFRAME (w
->frame
);
4092 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4094 if (save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4096 save_restore_orig_size (root
, RESTORE_ORIG_SIZES
);
4098 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4099 windows_or_buffers_changed
= 1;
4101 else if (XFASTINT (w
->total_lines
) > 1)
4103 /* Distribute the additional lines of the mini-window
4104 among the other windows. */
4106 XSETWINDOW (window
, w
);
4107 enlarge_window (window
, 1 - XFASTINT (w
->total_lines
), 0, 0);
4113 /* Mark window cursors off for all windows in the window tree rooted
4114 at W by setting their phys_cursor_on_p flag to zero. Called from
4115 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4116 the frame are cleared. */
4119 mark_window_cursors_off (w
)
4124 if (!NILP (w
->hchild
))
4125 mark_window_cursors_off (XWINDOW (w
->hchild
));
4126 else if (!NILP (w
->vchild
))
4127 mark_window_cursors_off (XWINDOW (w
->vchild
));
4129 w
->phys_cursor_on_p
= 0;
4131 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4136 /* Return number of lines of text (not counting mode lines) in W. */
4139 window_internal_height (w
)
4142 int ht
= XFASTINT (w
->total_lines
);
4144 if (!MINI_WINDOW_P (w
))
4146 if (!NILP (w
->parent
)
4147 || !NILP (w
->vchild
)
4148 || !NILP (w
->hchild
)
4151 || WINDOW_WANTS_MODELINE_P (w
))
4154 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4162 /* Return the number of columns in W.
4163 Don't count columns occupied by scroll bars or the vertical bar
4164 separating W from the sibling to its right. */
4167 window_box_text_cols (w
)
4170 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4171 int width
= XINT (w
->total_cols
);
4173 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
4174 /* Scroll bars occupy a few columns. */
4175 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
4176 else if (!FRAME_WINDOW_P (f
)
4177 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
4178 /* The column of `|' characters separating side-by-side windows
4179 occupies one column only. */
4182 if (FRAME_WINDOW_P (f
))
4183 /* On window-systems, fringes and display margins cannot be
4184 used for normal text. */
4185 width
-= (WINDOW_FRINGE_COLS (w
)
4186 + WINDOW_LEFT_MARGIN_COLS (w
)
4187 + WINDOW_RIGHT_MARGIN_COLS (w
));
4193 /************************************************************************
4195 ***********************************************************************/
4197 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4198 N screen-fulls, which is defined as the height of the window minus
4199 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4200 instead. Negative values of N mean scroll down. NOERROR non-zero
4201 means don't signal an error if we try to move over BEGV or ZV,
4205 window_scroll (window
, n
, whole
, noerror
)
4213 /* If we must, use the pixel-based version which is much slower than
4214 the line-based one but can handle varying line heights. */
4215 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4216 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4218 window_scroll_line_based (window
, n
, whole
, noerror
);
4224 /* Implementation of window_scroll that works based on pixel line
4225 heights. See the comment of window_scroll for parameter
4229 window_scroll_pixel_based (window
, n
, whole
, noerror
)
4236 struct window
*w
= XWINDOW (window
);
4237 struct text_pos start
;
4239 int this_scroll_margin
;
4241 /* True if we fiddled the window vscroll field without really scrolling. */
4244 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4246 /* If PT is not visible in WINDOW, move back one half of
4247 the screen. Allow PT to be partially visible, otherwise
4248 something like (scroll-down 1) with PT in the line before
4249 the partially visible one would recenter. */
4250 tem
= Fpos_visible_in_window_p (make_number (PT
), window
, Qt
);
4253 /* Move backward half the height of the window. Performance note:
4254 vmotion used here is about 10% faster, but would give wrong
4255 results for variable height lines. */
4256 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4257 it
.current_y
= it
.last_visible_y
;
4258 move_it_vertically (&it
, - window_box_height (w
) / 2);
4260 /* The function move_iterator_vertically may move over more than
4261 the specified y-distance. If it->w is small, e.g. a
4262 mini-buffer window, we may end up in front of the window's
4263 display area. This is the case when Start displaying at the
4264 start of the line containing PT in this case. */
4265 if (it
.current_y
<= 0)
4267 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4268 move_it_vertically (&it
, 0);
4272 start
= it
.current
.pos
;
4275 /* If scroll_preserve_screen_position is non-zero, we try to set
4276 point in the same window line as it is now, so get that line. */
4277 if (!NILP (Vscroll_preserve_screen_position
))
4279 start_display (&it
, w
, start
);
4280 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4281 preserve_y
= it
.current_y
;
4286 /* Move iterator it from start the specified distance forward or
4287 backward. The result is the new window start. */
4288 start_display (&it
, w
, start
);
4291 int screen_full
= (window_box_height (w
)
4292 - next_screen_context_lines
* FRAME_LINE_HEIGHT (it
.f
));
4293 int dy
= n
* screen_full
;
4295 /* Note that move_it_vertically always moves the iterator to the
4296 start of a line. So, if the last line doesn't have a newline,
4297 we would end up at the start of the line ending at ZV. */
4299 move_it_vertically_backward (&it
, -dy
);
4301 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4302 MOVE_TO_POS
| MOVE_TO_Y
);
4305 move_it_by_lines (&it
, n
, 1);
4307 /* We failed if we find ZV is already on the screen (scrolling up,
4308 means there's nothing past the end), or if we can't start any
4309 earlier (scrolling down, means there's nothing past the top). */
4310 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4311 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4313 if (IT_CHARPOS (it
) == ZV
)
4315 if (it
.current_y
< it
.last_visible_y
4316 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4317 >= it
.last_visible_y
))
4319 /* The last line was only partially visible, make it fully
4321 w
->vscroll
= (it
.last_visible_y
4322 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4323 adjust_glyphs (it
.f
);
4328 Fsignal (Qend_of_buffer
, Qnil
);
4332 if (w
->vscroll
!= 0)
4333 /* The first line was only partially visible, make it fully
4339 Fsignal (Qbeginning_of_buffer
, Qnil
);
4342 /* If control gets here, then we vscrolled. */
4344 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
4346 /* Don't try to change the window start below. */
4352 int pos
= IT_CHARPOS (it
);
4355 /* If in the middle of a multi-glyph character move forward to
4356 the next character. */
4357 if (in_display_vector_p (&it
))
4360 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
4363 /* Set the window start, and set up the window for redisplay. */
4364 set_marker_restricted (w
->start
, make_number (pos
),
4366 bytepos
= XMARKER (w
->start
)->bytepos
;
4367 w
->start_at_line_beg
= ((pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n')
4369 w
->update_mode_line
= Qt
;
4370 XSETFASTINT (w
->last_modified
, 0);
4371 XSETFASTINT (w
->last_overlay_modified
, 0);
4372 /* Set force_start so that redisplay_window will run the
4373 window-scroll-functions. */
4374 w
->force_start
= Qt
;
4377 it
.current_y
= it
.vpos
= 0;
4379 /* Preserve the screen position if we must. */
4380 if (preserve_y
>= 0)
4382 move_it_to (&it
, -1, -1, preserve_y
, -1, MOVE_TO_Y
);
4383 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4387 /* Move PT out of scroll margins. */
4388 this_scroll_margin
= max (0, scroll_margin
);
4389 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->total_lines
) / 4);
4390 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
4394 /* We moved the window start towards ZV, so PT may be now
4395 in the scroll margin at the top. */
4396 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4397 while (it
.current_y
< this_scroll_margin
)
4399 int prev
= it
.current_y
;
4400 move_it_by_lines (&it
, 1, 1);
4401 if (prev
== it
.current_y
)
4404 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4408 int charpos
, bytepos
;
4410 /* We moved the window start towards BEGV, so PT may be now
4411 in the scroll margin at the bottom. */
4412 move_it_to (&it
, PT
, -1,
4413 it
.last_visible_y
- this_scroll_margin
- 1, -1,
4414 MOVE_TO_POS
| MOVE_TO_Y
);
4416 /* Save our position, in case it's correct. */
4417 charpos
= IT_CHARPOS (it
);
4418 bytepos
= IT_BYTEPOS (it
);
4420 /* See if point is on a partially visible line at the end. */
4421 move_it_by_lines (&it
, 1, 1);
4422 if (it
.current_y
> it
.last_visible_y
)
4423 /* The last line was only partially visible, so back up two
4424 lines to make sure we're on a fully visible line. */
4426 move_it_by_lines (&it
, -2, 0);
4427 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4430 /* No, the position we saved is OK, so use it. */
4431 SET_PT_BOTH (charpos
, bytepos
);
4437 /* Implementation of window_scroll that works based on screen lines.
4438 See the comment of window_scroll for parameter descriptions. */
4441 window_scroll_line_based (window
, n
, whole
, noerror
)
4447 register struct window
*w
= XWINDOW (window
);
4448 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
4449 register int pos
, pos_byte
;
4450 register int ht
= window_internal_height (w
);
4451 register Lisp_Object tem
;
4455 struct position posit
;
4458 /* If scrolling screen-fulls, compute the number of lines to
4459 scroll from the window's height. */
4461 n
*= max (1, ht
- next_screen_context_lines
);
4463 startpos
= marker_position (w
->start
);
4465 posit
= *compute_motion (startpos
, 0, 0, 0,
4467 window_box_text_cols (w
), XINT (w
->hscroll
),
4469 original_vpos
= posit
.vpos
;
4471 XSETFASTINT (tem
, PT
);
4472 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
4476 Fvertical_motion (make_number (- (ht
/ 2)), window
);
4481 lose
= n
< 0 && PT
== BEGV
;
4482 Fvertical_motion (make_number (n
), window
);
4486 SET_PT_BOTH (opoint
, opoint_byte
);
4493 Fsignal (Qbeginning_of_buffer
, Qnil
);
4498 int this_scroll_margin
= scroll_margin
;
4500 /* Don't use a scroll margin that is negative or too large. */
4501 if (this_scroll_margin
< 0)
4502 this_scroll_margin
= 0;
4504 if (XINT (w
->total_lines
) < 4 * scroll_margin
)
4505 this_scroll_margin
= XINT (w
->total_lines
) / 4;
4507 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
4508 w
->start_at_line_beg
= bolp
;
4509 w
->update_mode_line
= Qt
;
4510 XSETFASTINT (w
->last_modified
, 0);
4511 XSETFASTINT (w
->last_overlay_modified
, 0);
4512 /* Set force_start so that redisplay_window will run
4513 the window-scroll-functions. */
4514 w
->force_start
= Qt
;
4516 if (whole
&& !NILP (Vscroll_preserve_screen_position
))
4518 SET_PT_BOTH (pos
, pos_byte
);
4519 Fvertical_motion (make_number (original_vpos
), window
);
4521 /* If we scrolled forward, put point enough lines down
4522 that it is outside the scroll margin. */
4527 if (this_scroll_margin
> 0)
4529 SET_PT_BOTH (pos
, pos_byte
);
4530 Fvertical_motion (make_number (this_scroll_margin
), window
);
4536 if (top_margin
<= opoint
)
4537 SET_PT_BOTH (opoint
, opoint_byte
);
4538 else if (!NILP (Vscroll_preserve_screen_position
))
4540 SET_PT_BOTH (pos
, pos_byte
);
4541 Fvertical_motion (make_number (original_vpos
), window
);
4544 SET_PT (top_margin
);
4550 /* If we scrolled backward, put point near the end of the window
4551 but not within the scroll margin. */
4552 SET_PT_BOTH (pos
, pos_byte
);
4553 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
4554 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
4557 bottom_margin
= PT
+ 1;
4559 if (bottom_margin
> opoint
)
4560 SET_PT_BOTH (opoint
, opoint_byte
);
4563 if (!NILP (Vscroll_preserve_screen_position
))
4565 SET_PT_BOTH (pos
, pos_byte
);
4566 Fvertical_motion (make_number (original_vpos
), window
);
4569 Fvertical_motion (make_number (-1), window
);
4578 Fsignal (Qend_of_buffer
, Qnil
);
4583 /* Scroll selected_window up or down. If N is nil, scroll a
4584 screen-full which is defined as the height of the window minus
4585 next_screen_context_lines. If N is the symbol `-', scroll.
4586 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4587 up. This is the guts of Fscroll_up and Fscroll_down. */
4590 scroll_command (n
, direction
)
4594 int count
= SPECPDL_INDEX ();
4596 xassert (abs (direction
) == 1);
4598 /* If selected window's buffer isn't current, make it current for
4599 the moment. But don't screw up if window_scroll gets an error. */
4600 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
4602 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4603 Fset_buffer (XWINDOW (selected_window
)->buffer
);
4605 /* Make redisplay consider other windows than just selected_window. */
4606 ++windows_or_buffers_changed
;
4610 window_scroll (selected_window
, direction
, 1, 0);
4611 else if (EQ (n
, Qminus
))
4612 window_scroll (selected_window
, -direction
, 1, 0);
4615 n
= Fprefix_numeric_value (n
);
4616 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
4619 unbind_to (count
, Qnil
);
4622 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
4623 doc
: /* Scroll text of current window upward ARG lines; or near full screen if no ARG.
4624 A near full screen is `next-screen-context-lines' less than a full screen.
4625 Negative ARG means scroll downward.
4626 If ARG is the atom `-', scroll downward by nearly full screen.
4627 When calling from a program, supply as argument a number, nil, or `-'. */)
4631 scroll_command (arg
, 1);
4635 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
4636 doc
: /* Scroll text of current window down ARG lines; or near full screen if no ARG.
4637 A near full screen is `next-screen-context-lines' less than a full screen.
4638 Negative ARG means scroll upward.
4639 If ARG is the atom `-', scroll upward by nearly full screen.
4640 When calling from a program, supply as argument a number, nil, or `-'. */)
4644 scroll_command (arg
, -1);
4648 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
4649 doc
: /* Return the other window for \"other window scroll\" commands.
4650 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4651 specifies the window.
4652 If `other-window-scroll-buffer' is non-nil, a window
4653 showing that buffer is used. */)
4658 if (MINI_WINDOW_P (XWINDOW (selected_window
))
4659 && !NILP (Vminibuf_scroll_window
))
4660 window
= Vminibuf_scroll_window
;
4661 /* If buffer is specified, scroll that buffer. */
4662 else if (!NILP (Vother_window_scroll_buffer
))
4664 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
4666 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
4670 /* Nothing specified; look for a neighboring window on the same
4672 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
4674 if (EQ (window
, selected_window
))
4675 /* That didn't get us anywhere; look for a window on another
4678 window
= Fnext_window (window
, Qnil
, Qt
);
4679 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
4680 && ! EQ (window
, selected_window
));
4683 CHECK_LIVE_WINDOW (window
);
4685 if (EQ (window
, selected_window
))
4686 error ("There is no other window");
4691 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
4692 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
4693 A near full screen is `next-screen-context-lines' less than a full screen.
4694 The next window is the one below the current one; or the one at the top
4695 if the current one is at the bottom. Negative ARG means scroll downward.
4696 If ARG is the atom `-', scroll downward by nearly full screen.
4697 When calling from a program, supply as argument a number, nil, or `-'.
4699 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4700 specifies the window to scroll.
4701 If `other-window-scroll-buffer' is non-nil, scroll the window
4702 showing that buffer, popping the buffer up if necessary. */)
4708 int count
= SPECPDL_INDEX ();
4710 window
= Fother_window_for_scrolling ();
4711 w
= XWINDOW (window
);
4713 /* Don't screw up if window_scroll gets an error. */
4714 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4715 ++windows_or_buffers_changed
;
4717 Fset_buffer (w
->buffer
);
4718 SET_PT (marker_position (w
->pointm
));
4721 window_scroll (window
, 1, 1, 1);
4722 else if (EQ (arg
, Qminus
))
4723 window_scroll (window
, -1, 1, 1);
4729 window_scroll (window
, XINT (arg
), 0, 1);
4732 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
4733 unbind_to (count
, Qnil
);
4738 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 1, "P",
4739 doc
: /* Scroll selected window display ARG columns left.
4740 Default for ARG is window width minus 2.
4741 Value is the total amount of leftward horizontal scrolling in
4742 effect after the change.
4743 If `automatic-hscrolling' is non-nil, the argument ARG modifies
4744 a lower bound for automatic scrolling, i.e. automatic scrolling
4745 will not scroll a window to a column less than the value returned
4746 by this function. */)
4748 register Lisp_Object arg
;
4752 struct window
*w
= XWINDOW (selected_window
);
4755 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
4757 arg
= Fprefix_numeric_value (arg
);
4759 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
4760 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
4762 if (interactive_p (0))
4763 w
->min_hscroll
= w
->hscroll
;
4768 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 1, "P",
4769 doc
: /* Scroll selected window display ARG columns right.
4770 Default for ARG is window width minus 2.
4771 Value is the total amount of leftward horizontal scrolling in
4772 effect after the change.
4773 If `automatic-hscrolling' is non-nil, the argument ARG modifies
4774 a lower bound for automatic scrolling, i.e. automatic scrolling
4775 will not scroll a window to a column less than the value returned
4776 by this function. */)
4778 register Lisp_Object arg
;
4782 struct window
*w
= XWINDOW (selected_window
);
4785 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
4787 arg
= Fprefix_numeric_value (arg
);
4789 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
4790 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
4792 if (interactive_p (0))
4793 w
->min_hscroll
= w
->hscroll
;
4798 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
4799 doc
: /* Return the window which was selected when entering the minibuffer.
4800 Returns nil, if current window is not a minibuffer window. */)
4803 if (minibuf_level
> 0
4804 && MINI_WINDOW_P (XWINDOW (selected_window
))
4805 && !NILP (minibuf_selected_window
)
4806 && WINDOW_LIVE_P (minibuf_selected_window
))
4807 return minibuf_selected_window
;
4812 /* Value is the number of lines actually displayed in window W,
4813 as opposed to its height. */
4816 displayed_window_lines (w
)
4820 struct text_pos start
;
4821 int height
= window_box_height (w
);
4822 struct buffer
*old_buffer
;
4825 if (XBUFFER (w
->buffer
) != current_buffer
)
4827 old_buffer
= current_buffer
;
4828 set_buffer_internal (XBUFFER (w
->buffer
));
4833 /* In case W->start is out of the accessible range, do something
4834 reasonable. This happens in Info mode when Info-scroll-down
4835 calls (recenter -1) while W->start is 1. */
4836 if (XMARKER (w
->start
)->charpos
< BEGV
)
4837 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4838 else if (XMARKER (w
->start
)->charpos
> ZV
)
4839 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
4841 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4843 start_display (&it
, w
, start
);
4844 move_it_vertically (&it
, height
);
4845 bottom_y
= line_bottom_y (&it
);
4847 /* rms: On a non-window display,
4848 the value of it.vpos at the bottom of the screen
4849 seems to be 1 larger than window_box_height (w).
4850 This kludge fixes a bug whereby (move-to-window-line -1)
4851 when ZV is on the last screen line
4852 moves to the previous screen line instead of the last one. */
4853 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
4856 /* Add in empty lines at the bottom of the window. */
4857 if (bottom_y
< height
)
4859 int uy
= FRAME_LINE_HEIGHT (it
.f
);
4860 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
4864 set_buffer_internal (old_buffer
);
4870 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
4871 doc
: /* Center point in window and redisplay frame.
4872 With prefix argument ARG, recenter putting point on screen line ARG
4873 relative to the current window. If ARG is negative, it counts up from the
4874 bottom of the window. (ARG should be less than the height of the window.)
4876 If ARG is omitted or nil, erase the entire frame and then
4877 redraw with point in the center of the current window.
4878 Just C-u as prefix means put point in the center of the window
4879 and redisplay normally--don't erase and redraw the frame. */)
4881 register Lisp_Object arg
;
4883 struct window
*w
= XWINDOW (selected_window
);
4884 struct buffer
*buf
= XBUFFER (w
->buffer
);
4885 struct buffer
*obuf
= current_buffer
;
4887 int charpos
, bytepos
;
4889 /* If redisplay is suppressed due to an error, try again. */
4890 obuf
->display_error_modiff
= 0;
4896 /* Invalidate pixel data calculated for all compositions. */
4897 for (i
= 0; i
< n_compositions
; i
++)
4898 composition_table
[i
]->font
= NULL
;
4900 Fredraw_frame (w
->frame
);
4901 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
4904 else if (CONSP (arg
)) /* Just C-u. */
4908 arg
= Fprefix_numeric_value (arg
);
4912 set_buffer_internal (buf
);
4914 /* Handle centering on a graphical frame specially. Such frames can
4915 have variable-height lines and centering point on the basis of
4916 line counts would lead to strange effects. */
4917 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
4924 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
4925 start_display (&it
, w
, pt
);
4926 move_it_vertically (&it
, - window_box_height (w
) / 2);
4927 charpos
= IT_CHARPOS (it
);
4928 bytepos
= IT_BYTEPOS (it
);
4930 else if (XINT (arg
) < 0)
4934 int y0
, y1
, h
, nlines
;
4936 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
4937 start_display (&it
, w
, pt
);
4940 /* The amount of pixels we have to move back is the window
4941 height minus what's displayed in the line containing PT,
4942 and the lines below. */
4943 nlines
= - XINT (arg
) - 1;
4944 move_it_by_lines (&it
, nlines
, 1);
4946 y1
= line_bottom_y (&it
);
4948 /* If we can't move down NLINES lines because we hit
4949 the end of the buffer, count in some empty lines. */
4950 if (it
.vpos
< nlines
)
4951 y1
+= (nlines
- it
.vpos
) * FRAME_LINE_HEIGHT (it
.f
);
4953 h
= window_box_height (w
) - (y1
- y0
);
4955 start_display (&it
, w
, pt
);
4956 move_it_vertically (&it
, - h
);
4957 charpos
= IT_CHARPOS (it
);
4958 bytepos
= IT_BYTEPOS (it
);
4962 struct position pos
;
4963 pos
= *vmotion (PT
, - XINT (arg
), w
);
4964 charpos
= pos
.bufpos
;
4965 bytepos
= pos
.bytepos
;
4970 struct position pos
;
4971 int ht
= window_internal_height (w
);
4974 arg
= make_number (ht
/ 2);
4975 else if (XINT (arg
) < 0)
4976 arg
= make_number (XINT (arg
) + ht
);
4978 pos
= *vmotion (PT
, - XINT (arg
), w
);
4979 charpos
= pos
.bufpos
;
4980 bytepos
= pos
.bytepos
;
4983 /* Set the new window start. */
4984 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
4985 w
->window_end_valid
= Qnil
;
4987 w
->optional_new_start
= Qt
;
4989 if (bytepos
== BEGV_BYTE
|| FETCH_BYTE (bytepos
- 1) == '\n')
4990 w
->start_at_line_beg
= Qt
;
4992 w
->start_at_line_beg
= Qnil
;
4994 set_buffer_internal (obuf
);
4999 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5001 doc
: /* Return the height in lines of the text display area of WINDOW.
5002 This doesn't include the mode-line (or header-line if any) or any
5003 partial-height lines in the text display area. */)
5007 struct window
*w
= decode_window (window
);
5008 int pixel_height
= window_box_height (w
);
5009 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5010 return make_number (line_height
);
5015 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5017 doc
: /* Position point relative to window.
5018 With no argument, position point at center of window.
5019 An argument specifies vertical position within the window;
5020 zero means top of window, negative means relative to bottom of window. */)
5024 struct window
*w
= XWINDOW (selected_window
);
5028 window
= selected_window
;
5029 start
= marker_position (w
->start
);
5030 if (start
< BEGV
|| start
> ZV
)
5032 int height
= window_internal_height (w
);
5033 Fvertical_motion (make_number (- (height
/ 2)), window
);
5034 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
5035 w
->start_at_line_beg
= Fbolp ();
5036 w
->force_start
= Qt
;
5039 Fgoto_char (w
->start
);
5041 lines
= displayed_window_lines (w
);
5043 XSETFASTINT (arg
, lines
/ 2);
5046 arg
= Fprefix_numeric_value (arg
);
5048 XSETINT (arg
, XINT (arg
) + lines
);
5051 /* Skip past a partially visible first line. */
5053 XSETINT (arg
, XINT (arg
) + 1);
5055 return Fvertical_motion (arg
, window
);
5060 /***********************************************************************
5061 Window Configuration
5062 ***********************************************************************/
5064 struct save_window_data
5066 EMACS_INT size_from_Lisp_Vector_struct
;
5067 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5068 Lisp_Object frame_cols
, frame_lines
, frame_menu_bar_lines
;
5069 Lisp_Object frame_tool_bar_lines
;
5070 Lisp_Object selected_frame
;
5071 Lisp_Object current_window
;
5072 Lisp_Object current_buffer
;
5073 Lisp_Object minibuf_scroll_window
;
5074 Lisp_Object minibuf_selected_window
;
5075 Lisp_Object root_window
;
5076 Lisp_Object focus_frame
;
5077 /* Record the values of window-min-width and window-min-height
5078 so that window sizes remain consistent with them. */
5079 Lisp_Object min_width
, min_height
;
5080 /* A vector, each of whose elements is a struct saved_window
5082 Lisp_Object saved_windows
;
5085 /* This is saved as a Lisp_Vector */
5088 /* these first two must agree with struct Lisp_Vector in lisp.h */
5089 EMACS_INT size_from_Lisp_Vector_struct
;
5090 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5093 Lisp_Object buffer
, start
, pointm
, mark
;
5094 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5095 Lisp_Object hscroll
, min_hscroll
;
5096 Lisp_Object parent
, prev
;
5097 Lisp_Object start_at_line_beg
;
5098 Lisp_Object display_table
;
5099 Lisp_Object orig_top_line
, orig_total_lines
;
5100 Lisp_Object left_margin_cols
, right_margin_cols
;
5101 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
5102 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
;
5105 #define SAVED_WINDOW_VECTOR_SIZE 24 /* Arg to Fmake_vector */
5107 #define SAVED_WINDOW_N(swv,n) \
5108 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5110 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
5111 doc
: /* Return t if OBJECT is a window-configuration object. */)
5115 if (WINDOW_CONFIGURATIONP (object
))
5120 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
5121 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5125 register struct save_window_data
*data
;
5126 struct Lisp_Vector
*saved_windows
;
5128 if (! WINDOW_CONFIGURATIONP (config
))
5129 wrong_type_argument (Qwindow_configuration_p
, config
);
5131 data
= (struct save_window_data
*) XVECTOR (config
);
5132 saved_windows
= XVECTOR (data
->saved_windows
);
5133 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5136 DEFUN ("set-window-configuration", Fset_window_configuration
,
5137 Sset_window_configuration
, 1, 1, 0,
5138 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5139 CONFIGURATION must be a value previously returned
5140 by `current-window-configuration' (which see).
5141 If CONFIGURATION was made from a frame that is now deleted,
5142 only frame-independent values can be restored. In this case,
5143 the return value is nil. Otherwise the value is t. */)
5145 Lisp_Object configuration
;
5147 register struct save_window_data
*data
;
5148 struct Lisp_Vector
*saved_windows
;
5149 Lisp_Object new_current_buffer
;
5154 while (!WINDOW_CONFIGURATIONP (configuration
))
5155 wrong_type_argument (Qwindow_configuration_p
, configuration
);
5157 data
= (struct save_window_data
*) XVECTOR (configuration
);
5158 saved_windows
= XVECTOR (data
->saved_windows
);
5160 new_current_buffer
= data
->current_buffer
;
5161 if (NILP (XBUFFER (new_current_buffer
)->name
))
5162 new_current_buffer
= Qnil
;
5165 if (XBUFFER (new_current_buffer
) == current_buffer
)
5168 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
5171 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5174 /* If f is a dead frame, don't bother rebuilding its window tree.
5175 However, there is other stuff we should still try to do below. */
5176 if (FRAME_LIVE_P (f
))
5178 register struct window
*w
;
5179 register struct saved_window
*p
;
5180 struct window
*root_window
;
5181 struct window
**leaf_windows
;
5185 /* If the frame has been resized since this window configuration was
5186 made, we change the frame to the size specified in the
5187 configuration, restore the configuration, and then resize it
5188 back. We keep track of the prevailing height in these variables. */
5189 int previous_frame_lines
= FRAME_LINES (f
);
5190 int previous_frame_cols
= FRAME_COLS (f
);
5191 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
5192 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
5194 /* The mouse highlighting code could get screwed up
5195 if it runs during this. */
5198 if (XFASTINT (data
->frame_lines
) != previous_frame_lines
5199 || XFASTINT (data
->frame_cols
) != previous_frame_cols
)
5200 change_frame_size (f
, XFASTINT (data
->frame_lines
),
5201 XFASTINT (data
->frame_cols
), 0, 0, 0);
5202 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5203 if (XFASTINT (data
->frame_menu_bar_lines
)
5204 != previous_frame_menu_bar_lines
)
5205 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, make_number (0));
5206 #ifdef HAVE_WINDOW_SYSTEM
5207 if (XFASTINT (data
->frame_tool_bar_lines
)
5208 != previous_frame_tool_bar_lines
)
5209 x_set_tool_bar_lines (f
, data
->frame_tool_bar_lines
, make_number (0));
5213 /* "Swap out" point from the selected window
5214 into its buffer. We do this now, before
5215 restoring the window contents, and prevent it from
5216 being done later on when we select a new window. */
5217 if (! NILP (XWINDOW (selected_window
)->buffer
))
5219 w
= XWINDOW (selected_window
);
5220 set_marker_both (w
->pointm
,
5222 BUF_PT (XBUFFER (w
->buffer
)),
5223 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5226 windows_or_buffers_changed
++;
5227 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
5229 /* Problem: Freeing all matrices and later allocating them again
5230 is a serious redisplay flickering problem. What we would
5231 really like to do is to free only those matrices not reused
5233 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5235 = (struct window
**) alloca (count_windows (root_window
)
5236 * sizeof (struct window
*));
5237 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
5239 /* Temporarily avoid any problems with windows that are smaller
5240 than they are supposed to be. */
5241 window_min_height
= 1;
5242 window_min_width
= 1;
5245 Mark all windows now on frame as "deleted".
5246 Restoring the new configuration "undeletes" any that are in it.
5248 Save their current buffers in their height fields, since we may
5249 need it later, if a buffer saved in the configuration is now
5251 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5253 for (k
= 0; k
< saved_windows
->size
; k
++)
5255 p
= SAVED_WINDOW_N (saved_windows
, k
);
5256 w
= XWINDOW (p
->window
);
5259 if (!NILP (p
->parent
))
5260 w
->parent
= SAVED_WINDOW_N (saved_windows
,
5261 XFASTINT (p
->parent
))->window
;
5265 if (!NILP (p
->prev
))
5267 w
->prev
= SAVED_WINDOW_N (saved_windows
,
5268 XFASTINT (p
->prev
))->window
;
5269 XWINDOW (w
->prev
)->next
= p
->window
;
5274 if (!NILP (w
->parent
))
5276 if (EQ (p
->total_cols
, XWINDOW (w
->parent
)->total_cols
))
5278 XWINDOW (w
->parent
)->vchild
= p
->window
;
5279 XWINDOW (w
->parent
)->hchild
= Qnil
;
5283 XWINDOW (w
->parent
)->hchild
= p
->window
;
5284 XWINDOW (w
->parent
)->vchild
= Qnil
;
5289 /* If we squirreled away the buffer in the window's height,
5291 if (BUFFERP (w
->total_lines
))
5292 w
->buffer
= w
->total_lines
;
5293 w
->left_col
= p
->left_col
;
5294 w
->top_line
= p
->top_line
;
5295 w
->total_cols
= p
->total_cols
;
5296 w
->total_lines
= p
->total_lines
;
5297 w
->hscroll
= p
->hscroll
;
5298 w
->min_hscroll
= p
->min_hscroll
;
5299 w
->display_table
= p
->display_table
;
5300 w
->orig_top_line
= p
->orig_top_line
;
5301 w
->orig_total_lines
= p
->orig_total_lines
;
5302 w
->left_margin_cols
= p
->left_margin_cols
;
5303 w
->right_margin_cols
= p
->right_margin_cols
;
5304 w
->left_fringe_width
= p
->left_fringe_width
;
5305 w
->right_fringe_width
= p
->right_fringe_width
;
5306 w
->fringes_outside_margins
= p
->fringes_outside_margins
;
5307 w
->scroll_bar_width
= p
->scroll_bar_width
;
5308 w
->vertical_scroll_bar_type
= p
->vertical_scroll_bar_type
;
5309 XSETFASTINT (w
->last_modified
, 0);
5310 XSETFASTINT (w
->last_overlay_modified
, 0);
5312 /* Reinstall the saved buffer and pointers into it. */
5313 if (NILP (p
->buffer
))
5314 w
->buffer
= p
->buffer
;
5317 if (!NILP (XBUFFER (p
->buffer
)->name
))
5318 /* If saved buffer is alive, install it. */
5320 w
->buffer
= p
->buffer
;
5321 w
->start_at_line_beg
= p
->start_at_line_beg
;
5322 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
5323 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
5324 Fset_marker (XBUFFER (w
->buffer
)->mark
,
5325 p
->mark
, w
->buffer
);
5327 /* As documented in Fcurrent_window_configuration, don't
5328 restore the location of point in the buffer which was
5329 current when the window configuration was recorded. */
5330 if (!EQ (p
->buffer
, new_current_buffer
)
5331 && XBUFFER (p
->buffer
) == current_buffer
)
5332 Fgoto_char (w
->pointm
);
5334 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
5335 /* Else unless window has a live buffer, get one. */
5337 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
5338 /* This will set the markers to beginning of visible
5340 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
5341 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
5342 w
->start_at_line_beg
= Qt
;
5345 /* Keeping window's old buffer; make sure the markers
5348 /* Set window markers at start of visible range. */
5349 if (XMARKER (w
->start
)->buffer
== 0)
5350 set_marker_restricted (w
->start
, make_number (0),
5352 if (XMARKER (w
->pointm
)->buffer
== 0)
5353 set_marker_restricted_both (w
->pointm
, w
->buffer
,
5354 BUF_PT (XBUFFER (w
->buffer
)),
5355 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5356 w
->start_at_line_beg
= Qt
;
5361 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
5362 /* Prevent "swapping out point" in the old selected window
5363 using the buffer that has been restored into it.
5364 Use the point value from the beginning of this function
5365 since unshow_buffer (called from delete_all_subwindows)
5366 could have altered it. */
5367 selected_window
= Qnil
;
5368 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
5369 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
5370 make_number (old_point
),
5371 XWINDOW (data
->current_window
)->buffer
);
5373 Fselect_window (data
->current_window
, Qnil
);
5374 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
5377 if (NILP (data
->focus_frame
)
5378 || (FRAMEP (data
->focus_frame
)
5379 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
5380 Fredirect_frame_focus (frame
, data
->focus_frame
);
5382 #if 0 /* I don't understand why this is needed, and it causes problems
5383 when the frame's old selected window has been deleted. */
5384 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
5385 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
5389 /* Set the screen height to the value it had before this function. */
5390 if (previous_frame_lines
!= FRAME_LINES (f
)
5391 || previous_frame_cols
!= FRAME_COLS (f
))
5392 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
5394 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5395 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
5396 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
5398 #ifdef HAVE_WINDOW_SYSTEM
5399 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
5400 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
5405 /* Now, free glyph matrices in windows that were not reused. */
5406 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
5408 if (NILP (leaf_windows
[i
]->buffer
))
5410 /* Assert it's not reused as a combination. */
5411 xassert (NILP (leaf_windows
[i
]->hchild
)
5412 && NILP (leaf_windows
[i
]->vchild
));
5413 free_window_matrices (leaf_windows
[i
]);
5415 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
5423 /* Fselect_window will have made f the selected frame, so we
5424 reselect the proper frame here. Fhandle_switch_frame will change the
5425 selected window too, but that doesn't make the call to
5426 Fselect_window above totally superfluous; it still sets f's
5428 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
5429 do_switch_frame (data
->selected_frame
, 0, 0);
5431 if (! NILP (Vwindow_configuration_change_hook
)
5432 && ! NILP (Vrun_hooks
))
5433 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
5436 if (!NILP (new_current_buffer
))
5437 Fset_buffer (new_current_buffer
);
5439 /* Restore the minimum heights recorded in the configuration. */
5440 window_min_height
= XINT (data
->min_height
);
5441 window_min_width
= XINT (data
->min_width
);
5443 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
5444 minibuf_selected_window
= data
->minibuf_selected_window
;
5446 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
5449 /* Mark all windows now on frame as deleted
5450 by setting their buffers to nil. */
5453 delete_all_subwindows (w
)
5454 register struct window
*w
;
5456 if (!NILP (w
->next
))
5457 delete_all_subwindows (XWINDOW (w
->next
));
5458 if (!NILP (w
->vchild
))
5459 delete_all_subwindows (XWINDOW (w
->vchild
));
5460 if (!NILP (w
->hchild
))
5461 delete_all_subwindows (XWINDOW (w
->hchild
));
5463 w
->total_lines
= w
->buffer
; /* See Fset_window_configuration for excuse. */
5465 if (!NILP (w
->buffer
))
5468 /* We set all three of these fields to nil, to make sure that we can
5469 distinguish this dead window from any live window. Live leaf
5470 windows will have buffer set, and combination windows will have
5471 vchild or hchild set. */
5476 Vwindow_list
= Qnil
;
5480 count_windows (window
)
5481 register struct window
*window
;
5483 register int count
= 1;
5484 if (!NILP (window
->next
))
5485 count
+= count_windows (XWINDOW (window
->next
));
5486 if (!NILP (window
->vchild
))
5487 count
+= count_windows (XWINDOW (window
->vchild
));
5488 if (!NILP (window
->hchild
))
5489 count
+= count_windows (XWINDOW (window
->hchild
));
5494 /* Fill vector FLAT with leaf windows under W, starting at index I.
5495 Value is last index + 1. */
5498 get_leaf_windows (w
, flat
, i
)
5500 struct window
**flat
;
5505 if (!NILP (w
->hchild
))
5506 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
5507 else if (!NILP (w
->vchild
))
5508 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
5512 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5519 /* Return a pointer to the glyph W's physical cursor is on. Value is
5520 null if W's current matrix is invalid, so that no meaningfull glyph
5524 get_phys_cursor_glyph (w
)
5527 struct glyph_row
*row
;
5528 struct glyph
*glyph
;
5530 if (w
->phys_cursor
.vpos
>= 0
5531 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
5532 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
5534 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
5535 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
5544 save_window_save (window
, vector
, i
)
5546 struct Lisp_Vector
*vector
;
5549 register struct saved_window
*p
;
5550 register struct window
*w
;
5551 register Lisp_Object tem
;
5553 for (;!NILP (window
); window
= w
->next
)
5555 p
= SAVED_WINDOW_N (vector
, i
);
5556 w
= XWINDOW (window
);
5558 XSETFASTINT (w
->temslot
, i
++);
5560 p
->buffer
= w
->buffer
;
5561 p
->left_col
= w
->left_col
;
5562 p
->top_line
= w
->top_line
;
5563 p
->total_cols
= w
->total_cols
;
5564 p
->total_lines
= w
->total_lines
;
5565 p
->hscroll
= w
->hscroll
;
5566 p
->min_hscroll
= w
->min_hscroll
;
5567 p
->display_table
= w
->display_table
;
5568 p
->orig_top_line
= w
->orig_top_line
;
5569 p
->orig_total_lines
= w
->orig_total_lines
;
5570 p
->left_margin_cols
= w
->left_margin_cols
;
5571 p
->right_margin_cols
= w
->right_margin_cols
;
5572 p
->left_fringe_width
= w
->left_fringe_width
;
5573 p
->right_fringe_width
= w
->right_fringe_width
;
5574 p
->fringes_outside_margins
= w
->fringes_outside_margins
;
5575 p
->scroll_bar_width
= w
->scroll_bar_width
;
5576 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
5577 if (!NILP (w
->buffer
))
5579 /* Save w's value of point in the window configuration.
5580 If w is the selected window, then get the value of point
5581 from the buffer; pointm is garbage in the selected window. */
5582 if (EQ (window
, selected_window
))
5584 p
->pointm
= Fmake_marker ();
5585 set_marker_both (p
->pointm
, w
->buffer
,
5586 BUF_PT (XBUFFER (w
->buffer
)),
5587 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5590 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
5592 p
->start
= Fcopy_marker (w
->start
, Qnil
);
5593 p
->start_at_line_beg
= w
->start_at_line_beg
;
5595 tem
= XBUFFER (w
->buffer
)->mark
;
5596 p
->mark
= Fcopy_marker (tem
, Qnil
);
5603 p
->start_at_line_beg
= Qnil
;
5606 if (NILP (w
->parent
))
5609 p
->parent
= XWINDOW (w
->parent
)->temslot
;
5614 p
->prev
= XWINDOW (w
->prev
)->temslot
;
5616 if (!NILP (w
->vchild
))
5617 i
= save_window_save (w
->vchild
, vector
, i
);
5618 if (!NILP (w
->hchild
))
5619 i
= save_window_save (w
->hchild
, vector
, i
);
5625 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
5626 Scurrent_window_configuration
, 0, 1, 0,
5627 doc
: /* Return an object representing the current window configuration of FRAME.
5628 If FRAME is nil or omitted, use the selected frame.
5629 This describes the number of windows, their sizes and current buffers,
5630 and for each displayed buffer, where display starts, and the positions of
5631 point and mark. An exception is made for point in the current buffer:
5632 its value is -not- saved.
5633 This also records the currently selected frame, and FRAME's focus
5634 redirection (see `redirect-frame-focus'). */)
5638 register Lisp_Object tem
;
5639 register int n_windows
;
5640 register struct save_window_data
*data
;
5641 register struct Lisp_Vector
*vec
;
5646 frame
= selected_frame
;
5647 CHECK_LIVE_FRAME (frame
);
5650 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5651 vec
= allocate_other_vector (VECSIZE (struct save_window_data
));
5652 data
= (struct save_window_data
*)vec
;
5654 XSETFASTINT (data
->frame_cols
, FRAME_COLS (f
));
5655 XSETFASTINT (data
->frame_lines
, FRAME_LINES (f
));
5656 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
5657 XSETFASTINT (data
->frame_tool_bar_lines
, FRAME_TOOL_BAR_LINES (f
));
5658 data
->selected_frame
= selected_frame
;
5659 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
5660 XSETBUFFER (data
->current_buffer
, current_buffer
);
5661 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
5662 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
5663 data
->root_window
= FRAME_ROOT_WINDOW (f
);
5664 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
5665 XSETINT (data
->min_height
, window_min_height
);
5666 XSETINT (data
->min_width
, window_min_width
);
5667 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
5668 data
->saved_windows
= tem
;
5669 for (i
= 0; i
< n_windows
; i
++)
5670 XVECTOR (tem
)->contents
[i
]
5671 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
5672 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
5673 XSETWINDOW_CONFIGURATION (tem
, data
);
5677 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
5679 doc
: /* Execute body, preserving window sizes and contents.
5680 Restore which buffer appears in which window, where display starts,
5681 and the value of point and mark for each window.
5682 Also restore the choice of selected window.
5683 Also restore which buffer is current.
5684 Does not restore the value of point in current buffer.
5685 usage: (save-window-excursion BODY ...) */)
5689 register Lisp_Object val
;
5690 register int count
= SPECPDL_INDEX ();
5692 record_unwind_protect (Fset_window_configuration
,
5693 Fcurrent_window_configuration (Qnil
));
5694 val
= Fprogn (args
);
5695 return unbind_to (count
, val
);
5699 /***********************************************************************
5701 ***********************************************************************/
5703 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
5705 doc
: /* Set width of marginal areas of window WINDOW.
5706 If window is nil, set margins of the currently selected window.
5707 First parameter LEFT-WIDTH specifies the number of character
5708 cells to reserve for the left marginal area. Second parameter
5709 RIGHT-WIDTH does the same for the right marginal area.
5710 A nil width parameter means no margin. */)
5711 (window
, left
, right
)
5712 Lisp_Object window
, left
, right
;
5714 struct window
*w
= decode_window (window
);
5716 /* TODO: It doesn't make sense to use FLOATs here, since
5717 the rest of the code assumes they are integers.
5718 So don't allow floats! ++KFS */
5721 CHECK_NUMBER_OR_FLOAT (left
);
5723 CHECK_NUMBER_OR_FLOAT (right
);
5725 /* Check widths < 0 and translate a zero width to nil.
5726 Margins that are too wide have to be checked elsewhere. */
5727 if ((INTEGERP (left
) && XINT (left
) < 0)
5728 || (FLOATP (left
) && XFLOAT_DATA (left
) <= 0))
5729 XSETFASTINT (left
, 0);
5730 if (INTEGERP (left
) && XFASTINT (left
) == 0)
5733 if ((INTEGERP (right
) && XINT (right
) < 0)
5734 || (FLOATP (right
) && XFLOAT_DATA (right
) <= 0))
5735 XSETFASTINT (right
, 0);
5736 if (INTEGERP (right
) && XFASTINT (right
) == 0)
5739 if (!EQ (w
->left_margin_cols
, left
)
5740 || !EQ (w
->right_margin_cols
, right
))
5742 w
->left_margin_cols
= left
;
5743 w
->right_margin_cols
= right
;
5745 adjust_window_margins (w
);
5747 ++windows_or_buffers_changed
;
5748 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
5755 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
5757 doc
: /* Get width of marginal areas of window WINDOW.
5758 If WINDOW is omitted or nil, use the currently selected window.
5759 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
5760 If a marginal area does not exist, its width will be returned
5765 struct window
*w
= decode_window (window
);
5766 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
5771 /***********************************************************************
5773 ***********************************************************************/
5775 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
5777 doc
: /* Set width of fringes of window WINDOW.
5779 If window is nil, set fringes of the currently selected window.
5780 Second parameter LEFT-WIDTH specifies the number of pixels to reserve
5781 for the left fringe. Third parameter RIGHT-WIDTH does the same for
5782 the right fringe. Fourth parameter OUTSIDE-MARGINS non-nil specifies
5783 that fringes are drawn outside of the display margins; by default, fringes
5784 are drawn between display marginal areas and the text area.
5785 A nil width parameter means to use the frame's corresponding fringe width. */)
5786 (window
, left
, right
, outside_margins
)
5787 Lisp_Object window
, left
, right
, outside_margins
;
5789 struct window
*w
= decode_window (window
);
5792 CHECK_NUMBER (left
);
5794 CHECK_NUMBER (right
);
5796 if (!EQ (w
->left_fringe_width
, left
)
5797 || !EQ (w
->right_fringe_width
, right
)
5798 || !EQ (w
->fringes_outside_margins
, outside_margins
))
5800 w
->left_fringe_width
= left
;
5801 w
->right_fringe_width
= right
;
5802 w
->fringes_outside_margins
= outside_margins
;
5804 adjust_window_margins (w
);
5806 clear_glyph_matrix (w
->current_matrix
);
5807 w
->window_end_valid
= Qnil
;
5809 ++windows_or_buffers_changed
;
5810 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
5817 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
5819 doc
: /* Get width of fringes of window WINDOW.
5820 If WINDOW is omitted or nil, use the currently selected window.
5821 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS).
5822 If a window specific fringe width is not set, its width will be returned
5827 struct window
*w
= decode_window (window
);
5828 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
5829 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
5830 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
) ?
5831 Qt
: Qnil
), Qnil
)));
5836 /***********************************************************************
5838 ***********************************************************************/
5840 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
, Sset_window_scroll_bars
,
5842 doc
: /* Set width and type of scroll bars of window WINDOW.
5843 If window is nil, set scroll bars of the currently selected window.
5844 Second parameter WIDTH specifies the pixel width for the scroll bar;
5845 this is automatically adjusted to a multiple of the frame column width.
5846 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
5847 bar: left, right, or nil.
5848 A width of nil and type of t means to use the frame's corresponding value. */)
5849 (window
, width
, vertical_type
, horizontal_type
)
5850 Lisp_Object window
, width
, vertical_type
, horizontal_type
;
5852 struct window
*w
= decode_window (window
);
5855 CHECK_NUMBER (width
);
5857 if (XINT (width
) == 0)
5858 vertical_type
= Qnil
;
5860 if (!EQ (w
->scroll_bar_width
, width
)
5861 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
5863 w
->scroll_bar_width
= width
;
5864 w
->vertical_scroll_bar_type
= vertical_type
;
5866 adjust_window_margins (w
);
5868 clear_glyph_matrix (w
->current_matrix
);
5869 w
->window_end_valid
= Qnil
;
5871 ++windows_or_buffers_changed
;
5872 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
5879 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
5881 doc
: /* Get width and type of scroll bars of window WINDOW.
5882 If WINDOW is omitted or nil, use the currently selected window.
5883 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE). */)
5887 struct window
*w
= decode_window (window
);
5888 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
5889 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
5890 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
5891 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
5892 Fcons (w
->vertical_scroll_bar_type
,
5893 Fcons (Qnil
, Qnil
))));
5898 /***********************************************************************
5900 ***********************************************************************/
5902 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 1, 0,
5903 doc
: /* Return the amount by which WINDOW is scrolled vertically.
5904 Use the selected window if WINDOW is nil or omitted.
5905 Value is a multiple of the canonical character height of WINDOW. */)
5914 window
= selected_window
;
5916 CHECK_WINDOW (window
);
5917 w
= XWINDOW (window
);
5918 f
= XFRAME (w
->frame
);
5920 if (FRAME_WINDOW_P (f
))
5921 result
= FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
);
5923 result
= make_number (0);
5928 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
5930 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
5931 WINDOW nil means use the selected window. VSCROLL is a non-negative
5932 multiple of the canonical character height of WINDOW. */)
5934 Lisp_Object window
, vscroll
;
5940 window
= selected_window
;
5942 CHECK_WINDOW (window
);
5943 CHECK_NUMBER_OR_FLOAT (vscroll
);
5945 w
= XWINDOW (window
);
5946 f
= XFRAME (w
->frame
);
5948 if (FRAME_WINDOW_P (f
))
5950 int old_dy
= w
->vscroll
;
5952 w
->vscroll
= - FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
);
5953 w
->vscroll
= min (w
->vscroll
, 0);
5955 /* Adjust glyph matrix of the frame if the virtual display
5956 area becomes larger than before. */
5957 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
5960 /* Prevent redisplay shortcuts. */
5961 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
5964 return Fwindow_vscroll (window
);
5968 /* Call FN for all leaf windows on frame F. FN is called with the
5969 first argument being a pointer to the leaf window, and with
5970 additional argument USER_DATA. Stops when FN returns 0. */
5973 foreach_window (f
, fn
, user_data
)
5975 int (* fn
) P_ ((struct window
*, void *));
5978 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
5982 /* Helper function for foreach_window. Call FN for all leaf windows
5983 reachable from W. FN is called with the first argument being a
5984 pointer to the leaf window, and with additional argument USER_DATA.
5985 Stop when FN returns 0. Value is 0 if stopped by FN. */
5988 foreach_window_1 (w
, fn
, user_data
)
5990 int (* fn
) P_ ((struct window
*, void *));
5995 for (cont
= 1; w
&& cont
;)
5997 if (!NILP (w
->hchild
))
5998 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
5999 else if (!NILP (w
->vchild
))
6000 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
6002 cont
= fn (w
, user_data
);
6004 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6011 /* Freeze or unfreeze the window start of W unless it is a
6012 mini-window or the selected window. FREEZE_P non-null means freeze
6013 the window start. */
6016 freeze_window_start (w
, freeze_p
)
6020 if (w
== XWINDOW (selected_window
)
6021 || MINI_WINDOW_P (w
)
6022 || (MINI_WINDOW_P (XWINDOW (selected_window
))
6023 && ! NILP (Vminibuf_scroll_window
)
6024 && w
== XWINDOW (Vminibuf_scroll_window
)))
6027 w
->frozen_window_start_p
= freeze_p
!= NULL
;
6032 /* Freeze or unfreeze the window starts of all leaf windows on frame
6033 F, except the selected window and a mini-window. FREEZE_P non-zero
6034 means freeze the window start. */
6037 freeze_window_starts (f
, freeze_p
)
6041 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
6045 /***********************************************************************
6047 ***********************************************************************/
6049 /* Return 1 if window configurations C1 and C2
6050 describe the same state of affairs. This is used by Fequal. */
6053 compare_window_configurations (c1
, c2
, ignore_positions
)
6055 int ignore_positions
;
6057 register struct save_window_data
*d1
, *d2
;
6058 struct Lisp_Vector
*sw1
, *sw2
;
6061 if (!WINDOW_CONFIGURATIONP (c1
))
6062 wrong_type_argument (Qwindow_configuration_p
, c1
);
6063 if (!WINDOW_CONFIGURATIONP (c2
))
6064 wrong_type_argument (Qwindow_configuration_p
, c2
);
6066 d1
= (struct save_window_data
*) XVECTOR (c1
);
6067 d2
= (struct save_window_data
*) XVECTOR (c2
);
6068 sw1
= XVECTOR (d1
->saved_windows
);
6069 sw2
= XVECTOR (d2
->saved_windows
);
6071 if (! EQ (d1
->frame_cols
, d2
->frame_cols
))
6073 if (! EQ (d1
->frame_lines
, d2
->frame_lines
))
6075 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
6077 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
6079 /* Don't compare the current_window field directly.
6080 Instead see w1_is_current and w2_is_current, below. */
6081 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
6083 if (! ignore_positions
)
6085 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
6087 if (! EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
))
6090 /* Don't compare the root_window field.
6091 We don't require the two configurations
6092 to use the same window object,
6093 and the two root windows must be equivalent
6094 if everything else compares equal. */
6095 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
6097 if (! EQ (d1
->min_width
, d2
->min_width
))
6099 if (! EQ (d1
->min_height
, d2
->min_height
))
6102 /* Verify that the two confis have the same number of windows. */
6103 if (sw1
->size
!= sw2
->size
)
6106 for (i
= 0; i
< sw1
->size
; i
++)
6108 struct saved_window
*p1
, *p2
;
6109 int w1_is_current
, w2_is_current
;
6111 p1
= SAVED_WINDOW_N (sw1
, i
);
6112 p2
= SAVED_WINDOW_N (sw2
, i
);
6114 /* Verify that the current windows in the two
6115 configurations correspond to each other. */
6116 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
6117 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
6119 if (w1_is_current
!= w2_is_current
)
6122 /* Verify that the corresponding windows do match. */
6123 if (! EQ (p1
->buffer
, p2
->buffer
))
6125 if (! EQ (p1
->left_col
, p2
->left_col
))
6127 if (! EQ (p1
->top_line
, p2
->top_line
))
6129 if (! EQ (p1
->total_cols
, p2
->total_cols
))
6131 if (! EQ (p1
->total_lines
, p2
->total_lines
))
6133 if (! EQ (p1
->display_table
, p2
->display_table
))
6135 if (! EQ (p1
->parent
, p2
->parent
))
6137 if (! EQ (p1
->prev
, p2
->prev
))
6139 if (! ignore_positions
)
6141 if (! EQ (p1
->hscroll
, p2
->hscroll
))
6143 if (!EQ (p1
->min_hscroll
, p2
->min_hscroll
))
6145 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
6147 if (NILP (Fequal (p1
->start
, p2
->start
)))
6149 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
6151 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
6154 if (! EQ (p1
->left_margin_cols
, p2
->left_margin_cols
))
6156 if (! EQ (p1
->right_margin_cols
, p2
->right_margin_cols
))
6158 if (! EQ (p1
->left_fringe_width
, p2
->left_fringe_width
))
6160 if (! EQ (p1
->right_fringe_width
, p2
->right_fringe_width
))
6162 if (! EQ (p1
->fringes_outside_margins
, p2
->fringes_outside_margins
))
6164 if (! EQ (p1
->scroll_bar_width
, p2
->scroll_bar_width
))
6166 if (! EQ (p1
->vertical_scroll_bar_type
, p2
->vertical_scroll_bar_type
))
6173 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
6174 Scompare_window_configurations
, 2, 2, 0,
6175 doc
: /* Compare two window configurations as regards the structure of windows.
6176 This function ignores details such as the values of point and mark
6177 and scrolling positions. */)
6181 if (compare_window_configurations (x
, y
, 1))
6189 struct frame
*f
= make_terminal_frame ();
6190 XSETFRAME (selected_frame
, f
);
6191 Vterminal_frame
= selected_frame
;
6192 minibuf_window
= f
->minibuffer_window
;
6193 selected_window
= f
->selected_window
;
6194 last_nonminibuf_frame
= f
;
6196 window_initialized
= 1;
6202 Vwindow_list
= Qnil
;
6208 Qwindow_size_fixed
= intern ("window-size-fixed");
6209 staticpro (&Qwindow_size_fixed
);
6211 staticpro (&Qwindow_configuration_change_hook
);
6212 Qwindow_configuration_change_hook
6213 = intern ("window-configuration-change-hook");
6215 Qwindowp
= intern ("windowp");
6216 staticpro (&Qwindowp
);
6218 Qwindow_configuration_p
= intern ("window-configuration-p");
6219 staticpro (&Qwindow_configuration_p
);
6221 Qwindow_live_p
= intern ("window-live-p");
6222 staticpro (&Qwindow_live_p
);
6224 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
6225 staticpro (&Qtemp_buffer_show_hook
);
6227 staticpro (&Vwindow_list
);
6229 minibuf_selected_window
= Qnil
;
6230 staticpro (&minibuf_selected_window
);
6232 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
6233 doc
: /* Non-nil means call as function to display a help buffer.
6234 The function is called with one argument, the buffer to be displayed.
6235 Used by `with-output-to-temp-buffer'.
6236 If this function is used, then it must do the entire job of showing
6237 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6238 Vtemp_buffer_show_function
= Qnil
;
6240 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
6241 doc
: /* If non-nil, function to call to handle `display-buffer'.
6242 It will receive two args, the buffer and a flag which if non-nil means
6243 that the currently selected window is not acceptable.
6244 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'
6245 work using this function. */);
6246 Vdisplay_buffer_function
= Qnil
;
6248 DEFVAR_LISP ("even-window-heights", &Veven_window_heights
,
6249 doc
: /* *If non-nil, `display-buffer' should even the window heights.
6250 If nil, `display-buffer' will leave the window configuration alone. */);
6251 Veven_window_heights
= Qt
;
6253 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
6254 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6255 Vminibuf_scroll_window
= Qnil
;
6257 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows
,
6258 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6259 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6260 is displayed in the `mode-line' face. */);
6261 mode_line_in_non_selected_windows
= 1;
6263 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
6264 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6265 Vother_window_scroll_buffer
= Qnil
;
6267 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
6268 doc
: /* *Non-nil means `display-buffer' should make a separate frame. */);
6271 DEFVAR_BOOL ("display-buffer-reuse-frames", &display_buffer_reuse_frames
,
6272 doc
: /* *Non-nil means `display-buffer' should reuse frames.
6273 If the buffer in question is already displayed in a frame, raise that frame. */);
6274 display_buffer_reuse_frames
= 0;
6276 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
6277 doc
: /* Function to call to handle automatic new frame creation.
6278 It is called with no arguments and should return a newly created frame.
6280 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'
6281 where `pop-up-frame-alist' would hold the default frame parameters. */);
6282 Vpop_up_frame_function
= Qnil
;
6284 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
6285 doc
: /* *List of buffer names that should have their own special frames.
6286 Displaying a buffer whose name is in this list makes a special frame for it
6287 using `special-display-function'. See also `special-display-regexps'.
6289 An element of the list can be a list instead of just a string.
6290 There are two ways to use a list as an element:
6291 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)
6292 In the first case, FRAME-PARAMETERS are used to create the frame.
6293 In the latter case, FUNCTION is called with BUFFER as the first argument,
6294 followed by OTHER-ARGS--it can display BUFFER in any way it likes.
6295 All this is done by the function found in `special-display-function'.
6297 If this variable appears \"not to work\", because you add a name to it
6298 but that buffer still appears in the selected window, look at the
6299 values of `same-window-buffer-names' and `same-window-regexps'.
6300 Those variables take precedence over this one. */);
6301 Vspecial_display_buffer_names
= Qnil
;
6303 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
6304 doc
: /* *List of regexps saying which buffers should have their own special frames.
6305 If a buffer name matches one of these regexps, it gets its own frame.
6306 Displaying a buffer whose name is in this list makes a special frame for it
6307 using `special-display-function'.
6309 An element of the list can be a list instead of just a string.
6310 There are two ways to use a list as an element:
6311 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)
6312 In the first case, FRAME-PARAMETERS are used to create the frame.
6313 In the latter case, FUNCTION is called with the buffer as first argument,
6314 followed by OTHER-ARGS--it can display the buffer in any way it likes.
6315 All this is done by the function found in `special-display-function'.
6317 If this variable appears \"not to work\", because you add a regexp to it
6318 but the matching buffers still appear in the selected window, look at the
6319 values of `same-window-buffer-names' and `same-window-regexps'.
6320 Those variables take precedence over this one. */);
6321 Vspecial_display_regexps
= Qnil
;
6323 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
6324 doc
: /* Function to call to make a new frame for a special buffer.
6325 It is called with two arguments, the buffer and optional buffer specific
6326 data, and should return a window displaying that buffer.
6327 The default value normally makes a separate frame for the buffer,
6328 using `special-display-frame-alist' to specify the frame parameters.
6329 But if the buffer specific data includes (same-buffer . t) then the
6330 buffer is displayed in the current selected window.
6331 Otherwise if it includes (same-frame . t) then the buffer is displayed in
6332 a new window in the currently selected frame.
6334 A buffer is special if it is listed in `special-display-buffer-names'
6335 or matches a regexp in `special-display-regexps'. */);
6336 Vspecial_display_function
= Qnil
;
6338 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
6339 doc
: /* *List of buffer names that should appear in the selected window.
6340 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'
6341 switches to it in the selected window, rather than making it appear
6342 in some other window.
6344 An element of the list can be a cons cell instead of just a string.
6345 Then the car must be a string, which specifies the buffer name.
6346 This is for compatibility with `special-display-buffer-names';
6347 the cdr of the cons cell is ignored.
6349 See also `same-window-regexps'. */);
6350 Vsame_window_buffer_names
= Qnil
;
6352 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
6353 doc
: /* *List of regexps saying which buffers should appear in the selected window.
6354 If a buffer name matches one of these regexps, then displaying it
6355 using `display-buffer' or `pop-to-buffer' switches to it
6356 in the selected window, rather than making it appear in some other window.
6358 An element of the list can be a cons cell instead of just a string.
6359 Then the car must be a string, which specifies the buffer name.
6360 This is for compatibility with `special-display-buffer-names';
6361 the cdr of the cons cell is ignored.
6363 See also `same-window-buffer-names'. */);
6364 Vsame_window_regexps
= Qnil
;
6366 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
6367 doc
: /* *Non-nil means display-buffer should make new windows. */);
6370 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
6371 doc
: /* *Number of lines of continuity when scrolling by screenfuls. */);
6372 next_screen_context_lines
= 2;
6374 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
6375 doc
: /* *display-buffer would prefer to split the largest window if this large.
6376 If there is only one window, it is split regardless of this value. */);
6377 split_height_threshold
= 500;
6379 DEFVAR_INT ("window-min-height", &window_min_height
,
6380 doc
: /* *Delete any window less than this tall (including its mode line). */);
6381 window_min_height
= 4;
6383 DEFVAR_INT ("window-min-width", &window_min_width
,
6384 doc
: /* *Delete any window less than this wide. */);
6385 window_min_width
= 10;
6387 DEFVAR_LISP ("scroll-preserve-screen-position",
6388 &Vscroll_preserve_screen_position
,
6389 doc
: /* *Non-nil means scroll commands move point to keep its screen line unchanged. */);
6390 Vscroll_preserve_screen_position
= Qnil
;
6392 DEFVAR_LISP ("window-configuration-change-hook",
6393 &Vwindow_configuration_change_hook
,
6394 doc
: /* Functions to call when window configuration changes.
6395 The selected frame is the one whose configuration has changed. */);
6396 Vwindow_configuration_change_hook
= Qnil
;
6398 DEFVAR_BOOL ("window-size-fixed", &window_size_fixed
,
6399 doc
: /* Non-nil in a buffer means windows displaying the buffer are fixed-size.
6400 Emacs won't change the size of any window displaying that buffer,
6401 unless you explicitly change the size, or Emacs has no other choice.
6402 This variable automatically becomes buffer-local when set. */);
6403 Fmake_variable_buffer_local (Qwindow_size_fixed
);
6404 window_size_fixed
= 0;
6406 defsubr (&Sselected_window
);
6407 defsubr (&Sminibuffer_window
);
6408 defsubr (&Swindow_minibuffer_p
);
6409 defsubr (&Swindowp
);
6410 defsubr (&Swindow_live_p
);
6411 defsubr (&Spos_visible_in_window_p
);
6412 defsubr (&Swindow_buffer
);
6413 defsubr (&Swindow_height
);
6414 defsubr (&Swindow_width
);
6415 defsubr (&Swindow_hscroll
);
6416 defsubr (&Sset_window_hscroll
);
6417 defsubr (&Swindow_redisplay_end_trigger
);
6418 defsubr (&Sset_window_redisplay_end_trigger
);
6419 defsubr (&Swindow_edges
);
6420 defsubr (&Swindow_pixel_edges
);
6421 defsubr (&Swindow_inside_edges
);
6422 defsubr (&Swindow_inside_pixel_edges
);
6423 defsubr (&Scoordinates_in_window_p
);
6424 defsubr (&Swindow_at
);
6425 defsubr (&Swindow_point
);
6426 defsubr (&Swindow_start
);
6427 defsubr (&Swindow_end
);
6428 defsubr (&Sset_window_point
);
6429 defsubr (&Sset_window_start
);
6430 defsubr (&Swindow_dedicated_p
);
6431 defsubr (&Sset_window_dedicated_p
);
6432 defsubr (&Swindow_display_table
);
6433 defsubr (&Sset_window_display_table
);
6434 defsubr (&Snext_window
);
6435 defsubr (&Sprevious_window
);
6436 defsubr (&Sother_window
);
6437 defsubr (&Sget_lru_window
);
6438 defsubr (&Sget_largest_window
);
6439 defsubr (&Sget_buffer_window
);
6440 defsubr (&Sdelete_other_windows
);
6441 defsubr (&Sdelete_windows_on
);
6442 defsubr (&Sreplace_buffer_in_windows
);
6443 defsubr (&Sdelete_window
);
6444 defsubr (&Sset_window_buffer
);
6445 defsubr (&Sselect_window
);
6446 defsubr (&Sspecial_display_p
);
6447 defsubr (&Ssame_window_p
);
6448 defsubr (&Sdisplay_buffer
);
6449 defsubr (&Ssplit_window
);
6450 defsubr (&Senlarge_window
);
6451 defsubr (&Sshrink_window
);
6452 defsubr (&Sscroll_up
);
6453 defsubr (&Sscroll_down
);
6454 defsubr (&Sscroll_left
);
6455 defsubr (&Sscroll_right
);
6456 defsubr (&Sother_window_for_scrolling
);
6457 defsubr (&Sscroll_other_window
);
6458 defsubr (&Sminibuffer_selected_window
);
6459 defsubr (&Srecenter
);
6460 defsubr (&Swindow_text_height
);
6461 defsubr (&Smove_to_window_line
);
6462 defsubr (&Swindow_configuration_p
);
6463 defsubr (&Swindow_configuration_frame
);
6464 defsubr (&Sset_window_configuration
);
6465 defsubr (&Scurrent_window_configuration
);
6466 defsubr (&Ssave_window_excursion
);
6467 defsubr (&Sset_window_margins
);
6468 defsubr (&Swindow_margins
);
6469 defsubr (&Sset_window_fringes
);
6470 defsubr (&Swindow_fringes
);
6471 defsubr (&Sset_window_scroll_bars
);
6472 defsubr (&Swindow_scroll_bars
);
6473 defsubr (&Swindow_vscroll
);
6474 defsubr (&Sset_window_vscroll
);
6475 defsubr (&Scompare_window_configurations
);
6476 defsubr (&Swindow_list
);
6482 initial_define_key (control_x_map
, '1', "delete-other-windows");
6483 initial_define_key (control_x_map
, '2', "split-window");
6484 initial_define_key (control_x_map
, '0', "delete-window");
6485 initial_define_key (control_x_map
, 'o', "other-window");
6486 initial_define_key (control_x_map
, '^', "enlarge-window");
6487 initial_define_key (control_x_map
, '<', "scroll-left");
6488 initial_define_key (control_x_map
, '>', "scroll-right");
6490 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
6491 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
6492 initial_define_key (meta_map
, 'v', "scroll-down");
6494 initial_define_key (global_map
, Ctl('L'), "recenter");
6495 initial_define_key (meta_map
, 'r', "move-to-window-line");