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
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 */
51 /* Values returned from coordinates_in_window. */
65 Lisp_Object Qwindowp
, Qwindow_live_p
, Qwindow_configuration_p
;
66 Lisp_Object Qwindow_size_fixed
;
67 extern Lisp_Object Qheight
, Qwidth
;
69 static int displayed_window_lines
P_ ((struct window
*));
70 static struct window
*decode_window
P_ ((Lisp_Object
));
71 static Lisp_Object select_window_1
P_ ((Lisp_Object
, int));
72 static int count_windows
P_ ((struct window
*));
73 static int get_leaf_windows
P_ ((struct window
*, struct window
**, int));
74 static void window_scroll
P_ ((Lisp_Object
, int, int, int));
75 static void window_scroll_pixel_based
P_ ((Lisp_Object
, int, int, int));
76 static void window_scroll_line_based
P_ ((Lisp_Object
, int, int, int));
77 static int window_min_size_1
P_ ((struct window
*, int));
78 static int window_min_size
P_ ((struct window
*, int, int, int *));
79 static void size_window
P_ ((Lisp_Object
, int, int, int));
80 static int freeze_window_start
P_ ((struct window
*, void *));
81 static int window_fixed_size_p
P_ ((struct window
*, int, int));
82 static void enlarge_window
P_ ((Lisp_Object
, int, int, int));
83 static Lisp_Object window_list
P_ ((void));
84 static int add_window_to_list
P_ ((struct window
*, void *));
85 static int candidate_window_p
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
87 static Lisp_Object next_window
P_ ((Lisp_Object
, Lisp_Object
,
89 static void decode_next_window_args
P_ ((Lisp_Object
*, Lisp_Object
*,
91 static int foreach_window_1
P_ ((struct window
*,
92 int (* fn
) (struct window
*, void *),
94 static Lisp_Object window_list_1
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
96 /* The value of `window-size-fixed'. */
98 int window_size_fixed
;
100 /* This is the window in which the terminal's cursor should
101 be left when nothing is being done with it. This must
102 always be a leaf window, and its buffer is selected by
103 the top level editing loop at the end of each command.
105 This value is always the same as
106 FRAME_SELECTED_WINDOW (selected_frame). */
108 Lisp_Object selected_window
;
110 /* A list of all windows for use by next_window and Fwindow_list.
111 Functions creating or deleting windows should invalidate this cache
112 by setting it to nil. */
114 Lisp_Object Vwindow_list
;
116 /* The mini-buffer window of the selected frame.
117 Note that you cannot test for mini-bufferness of an arbitrary window
118 by comparing against this; but you can test for mini-bufferness of
119 the selected window. */
121 Lisp_Object minibuf_window
;
123 /* Non-nil means it is the window for C-M-v to scroll
124 when the mini-buffer is selected. */
126 Lisp_Object Vminibuf_scroll_window
;
128 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
130 Lisp_Object Vother_window_scroll_buffer
;
132 /* Non-nil means it's function to call to display temp buffers. */
134 Lisp_Object Vtemp_buffer_show_function
;
136 /* Non-zero means to use mode-line-inactive face in all windows but the
137 selected-window and the minibuffer-scroll-window when the
138 minibuffer is active. */
139 int mode_line_in_non_selected_windows
;
141 /* If a window gets smaller than either of these, it is removed. */
143 int window_min_height
;
144 int window_min_width
;
146 /* Nonzero implies Fdisplay_buffer should create windows. */
150 /* Nonzero implies make new frames for Fdisplay_buffer. */
154 /* Nonzero means reuse existing frames for displaying buffers. */
156 int display_buffer_reuse_frames
;
158 /* Non-nil means use this function instead of default */
160 Lisp_Object Vpop_up_frame_function
;
162 /* Function to call to handle Fdisplay_buffer. */
164 Lisp_Object Vdisplay_buffer_function
;
166 /* Non-nil means that Fdisplay_buffer should even the heights of windows. */
168 Lisp_Object Veven_window_heights
;
170 /* List of buffer *names* for buffers that should have their own frames. */
172 Lisp_Object Vspecial_display_buffer_names
;
174 /* List of regexps for buffer names that should have their own frames. */
176 Lisp_Object Vspecial_display_regexps
;
178 /* Function to pop up a special frame. */
180 Lisp_Object Vspecial_display_function
;
182 /* List of buffer *names* for buffers to appear in selected window. */
184 Lisp_Object Vsame_window_buffer_names
;
186 /* List of regexps for buffer names to appear in selected window. */
188 Lisp_Object Vsame_window_regexps
;
190 /* Hook run at end of temp_output_buffer_show. */
192 Lisp_Object Qtemp_buffer_show_hook
;
194 /* Fdisplay_buffer always splits the largest window
195 if that window is more than this high. */
197 int split_height_threshold
;
199 /* Number of lines of continuity in scrolling by screenfuls. */
201 int next_screen_context_lines
;
203 /* Incremented for each window created. */
205 static int sequence_number
;
207 /* Nonzero after init_window_once has finished. */
209 static int window_initialized
;
211 /* Hook to run when window config changes. */
213 Lisp_Object Qwindow_configuration_change_hook
;
214 Lisp_Object Vwindow_configuration_change_hook
;
216 /* Nonzero means scroll commands try to put point
217 at the same screen height as previously. */
219 Lisp_Object Vscroll_preserve_screen_position
;
221 #if 0 /* This isn't used anywhere. */
222 /* Nonzero means we can split a frame even if it is "unsplittable". */
223 static int inhibit_frame_unsplittable
;
226 extern int scroll_margin
;
228 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
230 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
231 doc
: /* Returns t if OBJECT is a window. */)
235 return WINDOWP (object
) ? Qt
: Qnil
;
238 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
239 doc
: /* Returns t if OBJECT is a window which is currently visible. */)
243 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
250 register struct window
*p
;
252 p
= allocate_window ();
253 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
254 XSETFASTINT (p
->left
, 0);
255 XSETFASTINT (p
->top
, 0);
256 XSETFASTINT (p
->height
, 0);
257 XSETFASTINT (p
->width
, 0);
258 XSETFASTINT (p
->hscroll
, 0);
259 XSETFASTINT (p
->min_hscroll
, 0);
260 p
->orig_top
= p
->orig_height
= Qnil
;
261 p
->start
= Fmake_marker ();
262 p
->pointm
= Fmake_marker ();
263 XSETFASTINT (p
->use_time
, 0);
265 p
->display_table
= Qnil
;
267 p
->pseudo_window_p
= 0;
268 bzero (&p
->cursor
, sizeof (p
->cursor
));
269 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
270 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
271 p
->desired_matrix
= p
->current_matrix
= 0;
272 p
->phys_cursor_type
= -1;
273 p
->must_be_updated_p
= 0;
274 XSETFASTINT (p
->window_end_vpos
, 0);
275 XSETFASTINT (p
->window_end_pos
, 0);
276 p
->window_end_valid
= Qnil
;
279 XSETFASTINT (p
->last_point
, 0);
280 p
->frozen_window_start_p
= 0;
286 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
287 doc
: /* Return the window that the cursor now appears in and commands apply to. */)
290 return selected_window
;
293 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
294 doc
: /* Return the window used now for minibuffers.
295 If the optional argument FRAME is specified, return the minibuffer window
296 used by that frame. */)
301 frame
= selected_frame
;
302 CHECK_LIVE_FRAME (frame
);
303 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
306 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
307 doc
: /* Returns non-nil if WINDOW is a minibuffer window. */)
311 struct window
*w
= decode_window (window
);
312 return MINI_WINDOW_P (w
) ? Qt
: Qnil
;
316 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
317 Spos_visible_in_window_p
, 0, 3, 0,
318 doc
: /* Return t if position POS is currently on the frame in WINDOW.
319 Return nil if that position is scrolled vertically out of view.
320 If a character is only partially visible, nil is returned, unless the
321 optional argument PARTIALLY is non-nil.
322 POS defaults to point in WINDOW; WINDOW defaults to the selected window. */)
323 (pos
, window
, partially
)
324 Lisp_Object pos
, window
, partially
;
326 register struct window
*w
;
328 register struct buffer
*buf
;
330 Lisp_Object in_window
;
333 w
= decode_window (window
);
334 buf
= XBUFFER (w
->buffer
);
335 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
339 CHECK_NUMBER_COERCE_MARKER (pos
);
342 else if (w
== XWINDOW (selected_window
))
345 posint
= XMARKER (w
->pointm
)->charpos
;
347 /* If position is above window start, it's not visible. */
348 if (posint
< CHARPOS (top
))
350 else if (XFASTINT (w
->last_modified
) >= BUF_MODIFF (buf
)
351 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (buf
)
352 && posint
< BUF_Z (buf
) - XFASTINT (w
->window_end_pos
))
354 /* If frame is up-to-date, and POSINT is < window end pos, use
355 that info. This doesn't work for POSINT == end pos, because
356 the window end pos is actually the position _after_ the last
357 char in the window. */
358 if (NILP (partially
))
360 pos_visible_p (w
, posint
, &fully_p
, NILP (partially
));
361 in_window
= fully_p
? Qt
: Qnil
;
366 else if (posint
> BUF_ZV (buf
))
368 else if (CHARPOS (top
) < BUF_BEGV (buf
) || CHARPOS (top
) > BUF_ZV (buf
))
369 /* If window start is out of range, do something reasonable. */
373 if (pos_visible_p (w
, posint
, &fully_p
, NILP (partially
)))
374 in_window
= !NILP (partially
) || fully_p
? Qt
: Qnil
;
383 static struct window
*
384 decode_window (window
)
385 register Lisp_Object window
;
388 return XWINDOW (selected_window
);
390 CHECK_LIVE_WINDOW (window
);
391 return XWINDOW (window
);
394 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
395 doc
: /* Return the buffer that WINDOW is displaying. */)
399 return decode_window (window
)->buffer
;
402 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
403 doc
: /* Return the number of lines in WINDOW (including its mode line). */)
407 return decode_window (window
)->height
;
410 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
411 doc
: /* Return the number of display columns in WINDOW.
412 This is the width that is usable columns available for text in WINDOW.
413 If you want to find out how many columns WINDOW takes up,
414 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
418 return make_number (window_internal_width (decode_window (window
)));
421 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
422 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin. */)
426 return decode_window (window
)->hscroll
;
429 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
430 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
431 NCOL should be zero or positive. */)
433 Lisp_Object window
, ncol
;
435 struct window
*w
= decode_window (window
);
439 hscroll
= max (0, XINT (ncol
));
441 /* Prevent redisplay shortcuts when changing the hscroll. */
442 if (XINT (w
->hscroll
) != hscroll
)
443 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
445 w
->hscroll
= make_number (hscroll
);
449 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
450 Swindow_redisplay_end_trigger
, 0, 1, 0,
451 doc
: /* Return WINDOW's redisplay end trigger value.
452 See `set-window-redisplay-end-trigger' for more information. */)
456 return decode_window (window
)->redisplay_end_trigger
;
459 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
460 Sset_window_redisplay_end_trigger
, 2, 2, 0,
461 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
462 VALUE should be a buffer position (typically a marker) or nil.
463 If it is a buffer position, then if redisplay in WINDOW reaches a position
464 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
465 with two arguments: WINDOW, and the end trigger value.
466 Afterwards the end-trigger value is reset to nil. */)
468 register Lisp_Object window
, value
;
470 register struct window
*w
;
472 w
= decode_window (window
);
473 w
->redisplay_end_trigger
= value
;
477 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
478 doc
: /* Return a list of the edge coordinates of WINDOW.
479 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
480 RIGHT is one more than the rightmost column used by WINDOW,
481 and BOTTOM is one more than the bottommost row used by WINDOW
482 and its mode-line. */)
486 register struct window
*w
= decode_window (window
);
488 return Fcons (w
->left
, Fcons (w
->top
,
489 Fcons (make_number (WINDOW_RIGHT_EDGE (w
)),
490 Fcons (make_number (XFASTINT (w
->top
)
491 + XFASTINT (w
->height
)),
495 /* Test if the character at column *X, row *Y is within window W.
496 If it is not, return 0;
497 if it is in the window's text area,
498 set *x and *y to its location relative to the upper left corner
501 if it is on the window's modeline, return 2;
502 if it is on the border between the window and its right sibling,
504 if it is on the window's top line, return 4;
505 if it is in left or right fringe of the window,
506 return 5 or 6, and convert *X and *Y to window-relative corrdinates.
508 X and Y are frame relative pixel coordinates. */
510 static enum window_part
511 coordinates_in_window (w
, x
, y
)
512 register struct window
*w
;
515 /* Let's make this a global enum later, instead of using numbers
517 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
518 int left_x
, right_x
, top_y
, bottom_y
;
519 enum window_part part
;
520 int ux
= CANON_X_UNIT (f
);
521 int x0
= XFASTINT (w
->left
) * ux
;
522 int x1
= x0
+ XFASTINT (w
->width
) * ux
;
523 /* The width of the area where the vertical line can be dragged.
524 (Between mode lines for instance. */
525 int grabbable_width
= ux
;
527 if (*x
< x0
|| *x
>= x1
)
530 /* In what's below, we subtract 1 when computing right_x because we
531 want the rightmost pixel, which is given by left_pixel+width-1. */
532 if (w
->pseudo_window_p
)
535 right_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
) - 1;
536 top_y
= WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
);
537 bottom_y
= WINDOW_DISPLAY_BOTTOM_EDGE_PIXEL_Y (w
);
541 left_x
= (WINDOW_DISPLAY_LEFT_EDGE_PIXEL_X (w
)
542 - FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
));
543 right_x
= WINDOW_DISPLAY_RIGHT_EDGE_PIXEL_X (w
) - 1;
544 top_y
= (WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
)
545 - FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
));
546 bottom_y
= WINDOW_DISPLAY_BOTTOM_EDGE_PIXEL_Y (w
);
549 /* On the mode line or header line? If it's near the start of
550 the mode or header line of window that's has a horizontal
551 sibling, say it's on the vertical line. That's to be able
552 to resize windows horizontally in case we're using toolkit
555 if (WINDOW_WANTS_MODELINE_P (w
)
556 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
)
559 /* We're somewhere on the mode line. We consider the place
560 between mode lines of horizontally adjacent mode lines
561 as the vertical border. If scroll bars on the left,
562 return the right window. */
565 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
567 if (abs (*x
- x0
) < grabbable_width
)
568 part
= ON_VERTICAL_BORDER
;
570 else if (!WINDOW_RIGHTMOST_P (w
) && abs (*x
- x1
) < grabbable_width
)
571 part
= ON_VERTICAL_BORDER
;
573 else if (WINDOW_WANTS_HEADER_LINE_P (w
)
574 && *y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
)
577 part
= ON_HEADER_LINE
;
579 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
581 if (abs (*x
- x0
) < grabbable_width
)
582 part
= ON_VERTICAL_BORDER
;
584 else if (!WINDOW_RIGHTMOST_P (w
) && abs (*x
- x1
) < grabbable_width
)
585 part
= ON_VERTICAL_BORDER
;
587 /* Outside anything interesting? */
591 - FRAME_LEFT_FRINGE_WIDTH (f
)
592 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * ux
)
594 + FRAME_RIGHT_FRINGE_WIDTH (f
)
595 + FRAME_RIGHT_SCROLL_BAR_WIDTH (f
) * ux
))
599 else if (FRAME_WINDOW_P (f
))
601 if (!w
->pseudo_window_p
602 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
603 && !WINDOW_RIGHTMOST_P (w
)
604 && (abs (*x
- right_x
- FRAME_RIGHT_FRINGE_WIDTH (f
)) < grabbable_width
))
606 part
= ON_VERTICAL_BORDER
;
608 else if (*x
< left_x
|| *x
> right_x
)
610 /* Other lines than the mode line don't include fringes and
611 scroll bars on the left. */
613 /* Convert X and Y to window-relative pixel coordinates. */
616 part
= *x
< left_x
? ON_LEFT_FRINGE
: ON_RIGHT_FRINGE
;
627 /* Need to say "*x > right_x" rather than >=, since on character
628 terminals, the vertical line's x coordinate is right_x. */
629 if (*x
< left_x
|| *x
> right_x
)
631 /* Other lines than the mode line don't include fringes and
632 scroll bars on the left. */
634 /* Convert X and Y to window-relative pixel coordinates. */
637 part
= *x
< left_x
? ON_LEFT_FRINGE
: ON_RIGHT_FRINGE
;
639 /* Here, too, "*x > right_x" is because of character terminals. */
640 else if (!w
->pseudo_window_p
641 && !WINDOW_RIGHTMOST_P (w
)
642 && *x
> right_x
- ux
)
644 /* On the border on the right side of the window? Assume that
645 this area begins at RIGHT_X minus a canonical char width. */
646 part
= ON_VERTICAL_BORDER
;
650 /* Convert X and Y to window-relative pixel coordinates. */
661 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
662 Scoordinates_in_window_p
, 2, 2, 0,
663 doc
: /* Return non-nil if COORDINATES are in WINDOW.
664 COORDINATES is a cons of the form (X . Y), X and Y being distances
665 measured in characters from the upper-left corner of the frame.
666 \(0 . 0) denotes the character in the upper left corner of the
668 If COORDINATES are in the text portion of WINDOW,
669 the coordinates relative to the window are returned.
670 If they are in the mode line of WINDOW, `mode-line' is returned.
671 If they are in the top mode line of WINDOW, `header-line' is returned.
672 If they are in the left fringe of WINDOW, `left-fringe' is returned.
673 If they are in the right fringe of WINDOW, `right-fringe' is returned.
674 If they are on the border between WINDOW and its right sibling,
675 `vertical-line' is returned. */)
676 (coordinates
, window
)
677 register Lisp_Object coordinates
, window
;
684 CHECK_LIVE_WINDOW (window
);
685 w
= XWINDOW (window
);
686 f
= XFRAME (w
->frame
);
687 CHECK_CONS (coordinates
);
688 lx
= Fcar (coordinates
);
689 ly
= Fcdr (coordinates
);
690 CHECK_NUMBER_OR_FLOAT (lx
);
691 CHECK_NUMBER_OR_FLOAT (ly
);
692 x
= PIXEL_X_FROM_CANON_X (f
, lx
);
693 y
= PIXEL_Y_FROM_CANON_Y (f
, ly
);
695 switch (coordinates_in_window (w
, &x
, &y
))
701 /* X and Y are now window relative pixel coordinates. Convert
702 them to canonical char units before returning them. */
703 return Fcons (CANON_X_FROM_PIXEL_X (f
, x
),
704 CANON_Y_FROM_PIXEL_Y (f
, y
));
709 case ON_VERTICAL_BORDER
:
710 return Qvertical_line
;
718 case ON_RIGHT_FRINGE
:
719 return Qright_fringe
;
727 /* Callback for foreach_window, used in window_from_coordinates.
728 Check if window W contains coordinates specified by USER_DATA which
729 is actually a pointer to a struct check_window_data CW.
731 Check if window W contains coordinates *CW->x and *CW->y. If it
732 does, return W in *CW->window, as Lisp_Object, and return in
733 *CW->part the part of the window under coordinates *X,*Y. Return
734 zero from this function to stop iterating over windows. */
736 struct check_window_data
743 check_window_containing (w
, user_data
)
747 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
748 enum window_part found
;
751 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
752 if (found
!= ON_NOTHING
)
754 *cw
->part
= found
- 1;
755 XSETWINDOW (*cw
->window
, w
);
763 /* Find the window containing frame-relative pixel position X/Y and
764 return it as a Lisp_Object. If X, Y is on the window's modeline,
765 set *PART to 1; if it is on the separating line between the window
766 and its right sibling, set it to 2; otherwise set it to 0. If
767 there is no window under X, Y return nil and leave *PART
768 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
770 This function was previously implemented with a loop cycling over
771 windows with Fnext_window, and starting with the frame's selected
772 window. It turned out that this doesn't work with an
773 implementation of next_window using Vwindow_list, because
774 FRAME_SELECTED_WINDOW (F) is not always contained in the window
775 tree of F when this function is called asynchronously from
776 note_mouse_highlight. The original loop didn't terminate in this
780 window_from_coordinates (f
, x
, y
, part
, tool_bar_p
)
787 struct check_window_data cw
;
790 cw
.window
= &window
, cw
.x
= &x
, cw
.y
= &y
; cw
.part
= part
;
791 foreach_window (f
, check_window_containing
, &cw
);
793 /* If not found above, see if it's in the tool bar window, if a tool
797 && WINDOWP (f
->tool_bar_window
)
798 && XINT (XWINDOW (f
->tool_bar_window
)->height
) > 0
799 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), &x
, &y
)
803 window
= f
->tool_bar_window
;
809 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
810 doc
: /* Return window containing coordinates X and Y on FRAME.
811 If omitted, FRAME defaults to the currently selected frame.
812 The top left corner of the frame is considered to be row 0,
815 Lisp_Object x
, y
, frame
;
821 frame
= selected_frame
;
822 CHECK_LIVE_FRAME (frame
);
825 /* Check that arguments are integers or floats. */
826 CHECK_NUMBER_OR_FLOAT (x
);
827 CHECK_NUMBER_OR_FLOAT (y
);
829 return window_from_coordinates (f
,
830 PIXEL_X_FROM_CANON_X (f
, x
),
831 PIXEL_Y_FROM_CANON_Y (f
, y
),
835 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
836 doc
: /* Return current value of point in WINDOW.
837 For a nonselected window, this is the value point would have
838 if that window were selected.
840 Note that, when WINDOW is the selected window and its buffer
841 is also currently selected, the value returned is the same as (point).
842 It would be more strictly correct to return the `top-level' value
843 of point, outside of any save-excursion forms.
844 But that is hard to define. */)
848 register struct window
*w
= decode_window (window
);
850 if (w
== XWINDOW (selected_window
)
851 && current_buffer
== XBUFFER (w
->buffer
))
853 return Fmarker_position (w
->pointm
);
856 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
857 doc
: /* Return position at which display currently starts in WINDOW.
858 This is updated by redisplay or by calling `set-window-start'. */)
862 return Fmarker_position (decode_window (window
)->start
);
865 /* This is text temporarily removed from the doc string below.
867 This function returns nil if the position is not currently known.
868 That happens when redisplay is preempted and doesn't finish.
869 If in that case you want to compute where the end of the window would
870 have been if redisplay had finished, do this:
872 (goto-char (window-start window))
873 (vertical-motion (1- (window-height window)) window)
876 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
877 doc
: /* Return position at which display currently ends in WINDOW.
878 This is updated by redisplay, when it runs to completion.
879 Simply changing the buffer text or setting `window-start'
880 does not update this value.
881 If UPDATE is non-nil, compute the up-to-date position
882 if it isn't already recorded. */)
884 Lisp_Object window
, update
;
887 struct window
*w
= decode_window (window
);
893 #if 0 /* This change broke some things. We should make it later. */
894 /* If we don't know the end position, return nil.
895 The user can compute it with vertical-motion if he wants to.
896 It would be nicer to do it automatically,
897 but that's so slow that it would probably bother people. */
898 if (NILP (w
->window_end_valid
))
903 && ! (! NILP (w
->window_end_valid
)
904 && XFASTINT (w
->last_modified
) >= MODIFF
))
906 struct text_pos startp
;
908 struct buffer
*old_buffer
= NULL
, *b
= XBUFFER (buf
);
910 /* In case W->start is out of the range, use something
911 reasonable. This situation occured when loading a file with
912 `-l' containing a call to `rmail' with subsequent other
913 commands. At the end, W->start happened to be BEG, while
914 rmail had already narrowed the buffer. */
915 if (XMARKER (w
->start
)->charpos
< BEGV
)
916 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
917 else if (XMARKER (w
->start
)->charpos
> ZV
)
918 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
920 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
922 /* Cannot use Fvertical_motion because that function doesn't
923 cope with variable-height lines. */
924 if (b
!= current_buffer
)
926 old_buffer
= current_buffer
;
927 set_buffer_internal (b
);
930 start_display (&it
, w
, startp
);
931 move_it_vertically (&it
, window_box_height (w
));
932 if (it
.current_y
< it
.last_visible_y
)
933 move_it_past_eol (&it
);
934 value
= make_number (IT_CHARPOS (it
));
937 set_buffer_internal (old_buffer
);
940 XSETINT (value
, BUF_Z (XBUFFER (buf
)) - XFASTINT (w
->window_end_pos
));
945 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
946 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer. */)
948 Lisp_Object window
, pos
;
950 register struct window
*w
= decode_window (window
);
952 CHECK_NUMBER_COERCE_MARKER (pos
);
953 if (w
== XWINDOW (selected_window
)
954 && XBUFFER (w
->buffer
) == current_buffer
)
957 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
959 /* We have to make sure that redisplay updates the window to show
960 the new value of point. */
961 if (!EQ (window
, selected_window
))
962 ++windows_or_buffers_changed
;
967 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
968 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
969 Optional third arg NOFORCE non-nil inhibits next redisplay
970 from overriding motion of point in order to display at this exact start. */)
971 (window
, pos
, noforce
)
972 Lisp_Object window
, pos
, noforce
;
974 register struct window
*w
= decode_window (window
);
976 CHECK_NUMBER_COERCE_MARKER (pos
);
977 set_marker_restricted (w
->start
, pos
, w
->buffer
);
978 /* this is not right, but much easier than doing what is right. */
979 w
->start_at_line_beg
= Qnil
;
982 w
->update_mode_line
= Qt
;
983 XSETFASTINT (w
->last_modified
, 0);
984 XSETFASTINT (w
->last_overlay_modified
, 0);
985 if (!EQ (window
, selected_window
))
986 windows_or_buffers_changed
++;
991 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
993 doc
: /* Return WINDOW's dedicated object, usually t or nil.
994 See also `set-window-dedicated-p'. */)
998 return decode_window (window
)->dedicated
;
1001 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1002 Sset_window_dedicated_p
, 2, 2, 0,
1003 doc
: /* Control whether WINDOW is dedicated to the buffer it displays.
1004 If it is dedicated, Emacs will not automatically change
1005 which buffer appears in it.
1006 The second argument is the new value for the dedication flag;
1007 non-nil means yes. */)
1009 Lisp_Object window
, arg
;
1011 register struct window
*w
= decode_window (window
);
1014 w
->dedicated
= Qnil
;
1018 return w
->dedicated
;
1021 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1023 doc
: /* Return the display-table that WINDOW is using. */)
1027 return decode_window (window
)->display_table
;
1030 /* Get the display table for use on window W. This is either W's
1031 display table or W's buffer's display table. Ignore the specified
1032 tables if they are not valid; if no valid table is specified,
1035 struct Lisp_Char_Table
*
1036 window_display_table (w
)
1039 struct Lisp_Char_Table
*dp
= NULL
;
1041 if (DISP_TABLE_P (w
->display_table
))
1042 dp
= XCHAR_TABLE (w
->display_table
);
1043 else if (BUFFERP (w
->buffer
))
1045 struct buffer
*b
= XBUFFER (w
->buffer
);
1047 if (DISP_TABLE_P (b
->display_table
))
1048 dp
= XCHAR_TABLE (b
->display_table
);
1049 else if (DISP_TABLE_P (Vstandard_display_table
))
1050 dp
= XCHAR_TABLE (Vstandard_display_table
);
1056 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1057 doc
: /* Set WINDOW's display-table to TABLE. */)
1059 register Lisp_Object window
, table
;
1061 register struct window
*w
;
1063 w
= decode_window (window
);
1064 w
->display_table
= table
;
1068 /* Record info on buffer window w is displaying
1069 when it is about to cease to display that buffer. */
1072 register struct window
*w
;
1079 if (b
!= XMARKER (w
->pointm
)->buffer
)
1083 if (w
== XWINDOW (selected_window
)
1084 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1085 /* Do this except when the selected window's buffer
1086 is being removed from some other window. */
1088 /* last_window_start records the start position that this buffer
1089 had in the last window to be disconnected from it.
1090 Now that this statement is unconditional,
1091 it is possible for the buffer to be displayed in the
1092 selected window, while last_window_start reflects another
1093 window which was recently showing the same buffer.
1094 Some people might say that might be a good thing. Let's see. */
1095 b
->last_window_start
= marker_position (w
->start
);
1097 /* Point in the selected window's buffer
1098 is actually stored in that buffer, and the window's pointm isn't used.
1099 So don't clobber point in that buffer. */
1100 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1101 /* This line helps to fix Horsley's testbug.el bug. */
1102 && !(WINDOWP (b
->last_selected_window
)
1103 && w
!= XWINDOW (b
->last_selected_window
)
1104 && EQ (buf
, XWINDOW (b
->last_selected_window
)->buffer
)))
1105 temp_set_point_both (b
,
1106 clip_to_bounds (BUF_BEGV (b
),
1107 XMARKER (w
->pointm
)->charpos
,
1109 clip_to_bounds (BUF_BEGV_BYTE (b
),
1110 marker_byte_position (w
->pointm
),
1113 if (WINDOWP (b
->last_selected_window
)
1114 && w
== XWINDOW (b
->last_selected_window
))
1115 b
->last_selected_window
= Qnil
;
1118 /* Put replacement into the window structure in place of old. */
1120 replace_window (old
, replacement
)
1121 Lisp_Object old
, replacement
;
1123 register Lisp_Object tem
;
1124 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
1126 /* If OLD is its frame's root_window, then replacement is the new
1127 root_window for that frame. */
1129 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1130 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
1134 p
->width
= o
->width
;
1135 p
->height
= o
->height
;
1136 p
->desired_matrix
= p
->current_matrix
= 0;
1138 bzero (&p
->cursor
, sizeof (p
->cursor
));
1139 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
1140 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
1141 p
->phys_cursor_type
= -1;
1142 p
->must_be_updated_p
= 0;
1143 p
->pseudo_window_p
= 0;
1144 XSETFASTINT (p
->window_end_vpos
, 0);
1145 XSETFASTINT (p
->window_end_pos
, 0);
1146 p
->window_end_valid
= Qnil
;
1147 p
->frozen_window_start_p
= 0;
1148 p
->orig_top
= p
->orig_height
= Qnil
;
1150 p
->next
= tem
= o
->next
;
1152 XWINDOW (tem
)->prev
= replacement
;
1154 p
->prev
= tem
= o
->prev
;
1156 XWINDOW (tem
)->next
= replacement
;
1158 p
->parent
= tem
= o
->parent
;
1161 if (EQ (XWINDOW (tem
)->vchild
, old
))
1162 XWINDOW (tem
)->vchild
= replacement
;
1163 if (EQ (XWINDOW (tem
)->hchild
, old
))
1164 XWINDOW (tem
)->hchild
= replacement
;
1167 /*** Here, if replacement is a vertical combination
1168 and so is its new parent, we should make replacement's
1169 children be children of that parent instead. ***/
1172 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
1173 doc
: /* Remove WINDOW from the display. Default is selected window. */)
1175 register Lisp_Object window
;
1177 delete_window (window
);
1179 if (! NILP (Vwindow_configuration_change_hook
)
1180 && ! NILP (Vrun_hooks
))
1181 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
1187 delete_window (window
)
1188 register Lisp_Object window
;
1190 register Lisp_Object tem
, parent
, sib
;
1191 register struct window
*p
;
1192 register struct window
*par
;
1195 /* Because this function is called by other C code on non-leaf
1196 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1197 so we can't decode_window here. */
1199 window
= selected_window
;
1201 CHECK_WINDOW (window
);
1202 p
= XWINDOW (window
);
1204 /* It's okay to delete an already-deleted window. */
1205 if (NILP (p
->buffer
)
1207 && NILP (p
->vchild
))
1212 error ("Attempt to delete minibuffer or sole ordinary window");
1213 par
= XWINDOW (parent
);
1215 windows_or_buffers_changed
++;
1216 Vwindow_list
= Qnil
;
1217 f
= XFRAME (WINDOW_FRAME (p
));
1218 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
1220 /* Are we trying to delete any frame's selected window? */
1222 Lisp_Object swindow
, pwindow
;
1224 /* See if the frame's selected window is either WINDOW
1225 or any subwindow of it, by finding all that window's parents
1226 and comparing each one with WINDOW. */
1227 swindow
= FRAME_SELECTED_WINDOW (f
);
1232 while (!NILP (pwindow
))
1234 if (EQ (window
, pwindow
))
1236 pwindow
= XWINDOW (pwindow
)->parent
;
1239 /* If the window being deleted is not a parent of SWINDOW,
1240 then SWINDOW is ok as the new selected window. */
1241 if (!EQ (window
, pwindow
))
1243 /* Otherwise, try another window for SWINDOW. */
1244 swindow
= Fnext_window (swindow
, Qlambda
, Qnil
);;
1246 /* If we get back to the frame's selected window,
1247 it means there was no acceptable alternative,
1248 so we cannot delete. */
1249 if (EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1250 error ("Cannot delete window");
1253 /* If we need to change SWINDOW, do it. */
1254 if (! EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1256 /* If we're about to delete the selected window on the
1257 selected frame, then we should use Fselect_window to select
1258 the new window. On the other hand, if we're about to
1259 delete the selected window on any other frame, we shouldn't do
1260 anything but set the frame's selected_window slot. */
1261 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
1262 Fselect_window (swindow
);
1264 FRAME_SELECTED_WINDOW (f
) = swindow
;
1269 /* tem is null for dummy parent windows
1270 (which have inferiors but not any contents themselves) */
1274 unchain_marker (p
->pointm
);
1275 unchain_marker (p
->start
);
1278 /* Free window glyph matrices. It is sure that they are allocated
1279 again when ADJUST_GLYPHS is called. Block input so that expose
1280 events and other events that access glyph matrices are not
1281 processed while we are changing them. */
1283 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)));
1287 XWINDOW (tem
)->prev
= p
->prev
;
1291 XWINDOW (tem
)->next
= p
->next
;
1293 if (EQ (window
, par
->hchild
))
1294 par
->hchild
= p
->next
;
1295 if (EQ (window
, par
->vchild
))
1296 par
->vchild
= p
->next
;
1298 /* Find one of our siblings to give our space to. */
1302 /* If p gives its space to its next sibling, that sibling needs
1303 to have its top/left side pulled back to where p's is.
1304 set_window_{height,width} will re-position the sibling's
1307 XWINDOW (sib
)->top
= p
->top
;
1308 XWINDOW (sib
)->left
= p
->left
;
1311 /* Stretch that sibling. */
1312 if (!NILP (par
->vchild
))
1313 set_window_height (sib
,
1314 XFASTINT (XWINDOW (sib
)->height
) + XFASTINT (p
->height
),
1316 if (!NILP (par
->hchild
))
1317 set_window_width (sib
,
1318 XFASTINT (XWINDOW (sib
)->width
) + XFASTINT (p
->width
),
1321 /* If parent now has only one child,
1322 put the child into the parent's place. */
1326 if (NILP (XWINDOW (tem
)->next
))
1327 replace_window (parent
, tem
);
1329 /* Since we may be deleting combination windows, we must make sure that
1330 not only p but all its children have been marked as deleted. */
1331 if (! NILP (p
->hchild
))
1332 delete_all_subwindows (XWINDOW (p
->hchild
));
1333 else if (! NILP (p
->vchild
))
1334 delete_all_subwindows (XWINDOW (p
->vchild
));
1336 /* Mark this window as deleted. */
1337 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1339 /* Adjust glyph matrices. */
1346 /***********************************************************************
1348 ***********************************************************************/
1350 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1351 pointer. This is a callback function for foreach_window, used in
1352 function window_list. */
1355 add_window_to_list (w
, user_data
)
1359 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1361 XSETWINDOW (window
, w
);
1362 *list
= Fcons (window
, *list
);
1367 /* Return a list of all windows, for use by next_window. If
1368 Vwindow_list is a list, return that list. Otherwise, build a new
1369 list, cache it in Vwindow_list, and return that. */
1374 if (!CONSP (Vwindow_list
))
1378 Vwindow_list
= Qnil
;
1379 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1381 Lisp_Object args
[2];
1383 /* We are visiting windows in canonical order, and add
1384 new windows at the front of args[1], which means we
1385 have to reverse this list at the end. */
1387 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1388 args
[0] = Vwindow_list
;
1389 args
[1] = Fnreverse (args
[1]);
1390 Vwindow_list
= Fnconc (2, args
);
1394 return Vwindow_list
;
1398 /* Value is non-zero if WINDOW satisfies the constraints given by
1399 OWINDOW, MINIBUF and ALL_FRAMES.
1401 MINIBUF t means WINDOW may be minibuffer windows.
1402 `lambda' means WINDOW may not be a minibuffer window.
1403 a window means a specific minibuffer window
1405 ALL_FRAMES t means search all frames,
1406 nil means search just current frame,
1407 `visible' means search just visible frames,
1408 0 means search visible and iconified frames,
1409 a window means search the frame that window belongs to,
1410 a frame means consider windows on that frame, only. */
1413 candidate_window_p (window
, owindow
, minibuf
, all_frames
)
1414 Lisp_Object window
, owindow
, minibuf
, all_frames
;
1416 struct window
*w
= XWINDOW (window
);
1417 struct frame
*f
= XFRAME (w
->frame
);
1418 int candidate_p
= 1;
1420 if (!BUFFERP (w
->buffer
))
1422 else if (MINI_WINDOW_P (w
)
1423 && (EQ (minibuf
, Qlambda
)
1424 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
1426 /* If MINIBUF is `lambda' don't consider any mini-windows.
1427 If it is a window, consider only that one. */
1430 else if (EQ (all_frames
, Qt
))
1432 else if (NILP (all_frames
))
1434 xassert (WINDOWP (owindow
));
1435 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
1437 else if (EQ (all_frames
, Qvisible
))
1439 FRAME_SAMPLE_VISIBILITY (f
);
1440 candidate_p
= FRAME_VISIBLE_P (f
);
1442 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
1444 FRAME_SAMPLE_VISIBILITY (f
);
1445 candidate_p
= FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
);
1447 else if (WINDOWP (all_frames
))
1448 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
1449 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
1450 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
1451 else if (FRAMEP (all_frames
))
1452 candidate_p
= EQ (all_frames
, w
->frame
);
1458 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1459 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1463 decode_next_window_args (window
, minibuf
, all_frames
)
1464 Lisp_Object
*window
, *minibuf
, *all_frames
;
1467 *window
= selected_window
;
1469 CHECK_LIVE_WINDOW (*window
);
1471 /* MINIBUF nil may or may not include minibuffers. Decide if it
1473 if (NILP (*minibuf
))
1474 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
1475 else if (!EQ (*minibuf
, Qt
))
1478 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1479 => count none of them, or a specific minibuffer window (the
1480 active one) to count. */
1482 /* ALL_FRAMES nil doesn't specify which frames to include. */
1483 if (NILP (*all_frames
))
1484 *all_frames
= (!EQ (*minibuf
, Qlambda
)
1485 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
1487 else if (EQ (*all_frames
, Qvisible
))
1489 else if (XFASTINT (*all_frames
) == 0)
1491 else if (FRAMEP (*all_frames
))
1493 else if (!EQ (*all_frames
, Qt
))
1496 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1497 search just current frame, `visible' meaning search just visible
1498 frames, 0 meaning search visible and iconified frames, or a
1499 window, meaning search the frame that window belongs to, or a
1500 frame, meaning consider windows on that frame, only. */
1504 /* Return the next or previous window of WINDOW in canonical ordering
1505 of windows. NEXT_P non-zero means return the next window. See the
1506 documentation string of next-window for the meaning of MINIBUF and
1510 next_window (window
, minibuf
, all_frames
, next_p
)
1511 Lisp_Object window
, minibuf
, all_frames
;
1514 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1516 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1517 return the first window on the frame. */
1518 if (FRAMEP (all_frames
)
1519 && !EQ (all_frames
, XWINDOW (window
)->frame
))
1520 return Fframe_first_window (all_frames
);
1526 /* Find WINDOW in the list of all windows. */
1527 list
= Fmemq (window
, window_list ());
1529 /* Scan forward from WINDOW to the end of the window list. */
1531 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
1532 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1535 /* Scan from the start of the window list up to WINDOW. */
1537 for (list
= Vwindow_list
;
1538 CONSP (list
) && !EQ (XCAR (list
), window
);
1540 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1544 window
= XCAR (list
);
1548 Lisp_Object candidate
, list
;
1550 /* Scan through the list of windows for candidates. If there are
1551 candidate windows in front of WINDOW, the last one of these
1552 is the one we want. If there are candidates following WINDOW
1553 in the list, again the last one of these is the one we want. */
1555 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
1557 if (EQ (XCAR (list
), window
))
1559 if (WINDOWP (candidate
))
1562 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
1564 candidate
= XCAR (list
);
1567 if (WINDOWP (candidate
))
1575 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
1576 doc
: /* Return next window after WINDOW in canonical ordering of windows.
1577 If omitted, WINDOW defaults to the selected window.
1579 Optional second arg MINIBUF t means count the minibuffer window even
1580 if not active. MINIBUF nil or omitted means count the minibuffer iff
1581 it is active. MINIBUF neither t nor nil means not to count the
1582 minibuffer even if it is active.
1584 Several frames may share a single minibuffer; if the minibuffer
1585 counts, all windows on all frames that share that minibuffer count
1586 too. Therefore, `next-window' can be used to iterate through the
1587 set of windows even when the minibuffer is on another frame. If the
1588 minibuffer does not count, only windows from WINDOW's frame count.
1590 Optional third arg ALL-FRAMES t means include windows on all frames.
1591 ALL-FRAMES nil or omitted means cycle within the frames as specified
1592 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1593 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1594 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1595 Anything else means restrict to WINDOW's frame.
1597 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1598 `next-window' to iterate through the entire cycle of acceptable
1599 windows, eventually ending up back at the window you started with.
1600 `previous-window' traverses the same cycle, in the reverse order. */)
1601 (window
, minibuf
, all_frames
)
1602 Lisp_Object window
, minibuf
, all_frames
;
1604 return next_window (window
, minibuf
, all_frames
, 1);
1608 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1609 doc
: /* Return the window preceding WINDOW in canonical ordering of windows.
1610 If omitted, WINDOW defaults to the selected window.
1612 Optional second arg MINIBUF t means count the minibuffer window even
1613 if not active. MINIBUF nil or omitted means count the minibuffer iff
1614 it is active. MINIBUF neither t nor nil means not to count the
1615 minibuffer even if it is active.
1617 Several frames may share a single minibuffer; if the minibuffer
1618 counts, all windows on all frames that share that minibuffer count
1619 too. Therefore, `previous-window' can be used to iterate through
1620 the set of windows even when the minibuffer is on another frame. If
1621 the minibuffer does not count, only windows from WINDOW's frame count
1623 Optional third arg ALL-FRAMES t means include windows on all frames.
1624 ALL-FRAMES nil or omitted means cycle within the frames as specified
1625 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1626 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1627 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1628 Anything else means restrict to WINDOW's frame.
1630 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1631 `previous-window' to iterate through the entire cycle of acceptable
1632 windows, eventually ending up back at the window you started with.
1633 `next-window' traverses the same cycle, in the reverse order. */)
1634 (window
, minibuf
, all_frames
)
1635 Lisp_Object window
, minibuf
, all_frames
;
1637 return next_window (window
, minibuf
, all_frames
, 0);
1641 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1642 doc
: /* Select the ARG'th different window on this frame.
1643 All windows on current frame are arranged in a cyclic order.
1644 This command selects the window ARG steps away in that order.
1645 A negative ARG moves in the opposite order. If the optional second
1646 argument ALL_FRAMES is non-nil, cycle through all frames. */)
1648 Lisp_Object arg
, all_frames
;
1654 window
= selected_window
;
1656 for (i
= XINT (arg
); i
> 0; --i
)
1657 window
= Fnext_window (window
, Qnil
, all_frames
);
1659 window
= Fprevious_window (window
, Qnil
, all_frames
);
1661 Fselect_window (window
);
1666 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
1667 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
1668 FRAME nil or omitted means use the selected frame.
1669 WINDOW nil or omitted means use the selected window.
1670 MINIBUF t means include the minibuffer window, even if it isn't active.
1671 MINIBUF nil or omitted means include the minibuffer window only
1673 MINIBUF neither nil nor t means never include the minibuffer window. */)
1674 (frame
, minibuf
, window
)
1675 Lisp_Object frame
, minibuf
, window
;
1678 window
= selected_window
;
1680 frame
= selected_frame
;
1682 if (!EQ (frame
, XWINDOW (window
)->frame
))
1683 error ("Window is on a different frame");
1685 return window_list_1 (window
, minibuf
, frame
);
1689 /* Return a list of windows in canonical ordering. Arguments are like
1690 for `next-window'. */
1693 window_list_1 (window
, minibuf
, all_frames
)
1694 Lisp_Object window
, minibuf
, all_frames
;
1696 Lisp_Object tail
, list
;
1698 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1701 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
1702 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
1703 list
= Fcons (XCAR (tail
), list
);
1705 return Fnreverse (list
);
1710 /* Look at all windows, performing an operation specified by TYPE
1712 If FRAMES is Qt, look at all frames;
1713 Qnil, look at just the selected frame;
1714 Qvisible, look at visible frames;
1715 a frame, just look at windows on that frame.
1716 If MINI is non-zero, perform the operation on minibuffer windows too. */
1721 GET_BUFFER_WINDOW
, /* Arg is buffer */
1722 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1723 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1724 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1726 UNSHOW_BUFFER
, /* Arg is buffer */
1731 window_loop (type
, obj
, mini
, frames
)
1732 enum window_loop type
;
1733 Lisp_Object obj
, frames
;
1736 Lisp_Object window
, windows
, best_window
, frame_arg
;
1738 struct gcpro gcpro1
;
1740 /* If we're only looping through windows on a particular frame,
1741 frame points to that frame. If we're looping through windows
1742 on all frames, frame is 0. */
1743 if (FRAMEP (frames
))
1744 f
= XFRAME (frames
);
1745 else if (NILP (frames
))
1746 f
= SELECTED_FRAME ();
1751 frame_arg
= Qlambda
;
1752 else if (XFASTINT (frames
) == 0)
1754 else if (EQ (frames
, Qvisible
))
1759 /* frame_arg is Qlambda to stick to one frame,
1760 Qvisible to consider all visible frames,
1763 /* Pick a window to start with. */
1767 window
= FRAME_SELECTED_WINDOW (f
);
1769 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
1771 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
1775 for (; CONSP (windows
); windows
= CDR (windows
))
1779 window
= XCAR (windows
);
1780 w
= XWINDOW (window
);
1782 /* Note that we do not pay attention here to whether the frame
1783 is visible, since Fwindow_list skips non-visible frames if
1784 that is desired, under the control of frame_arg. */
1785 if (!MINI_WINDOW_P (w
)
1786 /* For UNSHOW_BUFFER, we must always consider all windows. */
1787 || type
== UNSHOW_BUFFER
1788 || (mini
&& minibuf_level
> 0))
1791 case GET_BUFFER_WINDOW
:
1792 if (EQ (w
->buffer
, obj
)
1793 /* Don't find any minibuffer window
1794 except the one that is currently in use. */
1795 && (MINI_WINDOW_P (w
)
1796 ? EQ (window
, minibuf_window
)
1799 if (NILP (best_window
))
1800 best_window
= window
;
1801 else if (EQ (window
, selected_window
))
1802 /* For compatibility with 20.x, prefer to return
1804 best_window
= window
;
1808 case GET_LRU_WINDOW
:
1809 /* t as arg means consider only full-width windows */
1810 if (!NILP (obj
) && !WINDOW_FULL_WIDTH_P (w
))
1812 /* Ignore dedicated windows and minibuffers. */
1813 if (MINI_WINDOW_P (w
) || !NILP (w
->dedicated
))
1815 if (NILP (best_window
)
1816 || (XFASTINT (XWINDOW (best_window
)->use_time
)
1817 > XFASTINT (w
->use_time
)))
1818 best_window
= window
;
1821 case DELETE_OTHER_WINDOWS
:
1822 if (!EQ (window
, obj
))
1823 Fdelete_window (window
);
1826 case DELETE_BUFFER_WINDOWS
:
1827 if (EQ (w
->buffer
, obj
))
1829 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1831 /* If this window is dedicated, and in a frame of its own,
1833 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
1834 && !NILP (w
->dedicated
)
1835 && other_visible_frames (f
))
1837 /* Skip the other windows on this frame.
1838 There might be one, the minibuffer! */
1839 while (CONSP (XCDR (windows
))
1840 && EQ (XWINDOW (XCAR (windows
))->frame
,
1841 XWINDOW (XCAR (XCDR (windows
)))->frame
))
1842 windows
= XCDR (windows
);
1844 /* Now we can safely delete the frame. */
1845 Fdelete_frame (w
->frame
, Qnil
);
1847 else if (NILP (w
->parent
))
1849 /* If we're deleting the buffer displayed in the
1850 only window on the frame, find a new buffer to
1853 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
1854 Fset_window_buffer (window
, buffer
);
1855 if (EQ (window
, selected_window
))
1856 Fset_buffer (w
->buffer
);
1859 Fdelete_window (window
);
1863 case GET_LARGEST_WINDOW
:
1865 /* Ignore dedicated windows and minibuffers. */
1866 if (MINI_WINDOW_P (w
) || !NILP (w
->dedicated
))
1869 if (NILP (best_window
))
1870 best_window
= window
;
1873 struct window
*b
= XWINDOW (best_window
);
1874 if (XFASTINT (w
->height
) * XFASTINT (w
->width
)
1875 > XFASTINT (b
->height
) * XFASTINT (b
->width
))
1876 best_window
= window
;
1882 if (EQ (w
->buffer
, obj
))
1885 struct frame
*f
= XFRAME (w
->frame
);
1887 /* Find another buffer to show in this window. */
1888 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
1890 /* If this window is dedicated, and in a frame of its own,
1892 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
1893 && !NILP (w
->dedicated
)
1894 && other_visible_frames (f
))
1896 /* Skip the other windows on this frame.
1897 There might be one, the minibuffer! */
1898 while (CONSP (XCDR (windows
))
1899 && EQ (XWINDOW (XCAR (windows
))->frame
,
1900 XWINDOW (XCAR (XCDR (windows
)))->frame
))
1901 windows
= XCDR (windows
);
1903 /* Now we can safely delete the frame. */
1904 Fdelete_frame (w
->frame
, Qnil
);
1908 /* Otherwise show a different buffer in the window. */
1909 w
->dedicated
= Qnil
;
1910 Fset_window_buffer (window
, buffer
);
1911 if (EQ (window
, selected_window
))
1912 Fset_buffer (w
->buffer
);
1917 /* Check for a window that has a killed buffer. */
1918 case CHECK_ALL_WINDOWS
:
1919 if (! NILP (w
->buffer
)
1920 && NILP (XBUFFER (w
->buffer
)->name
))
1924 case WINDOW_LOOP_UNUSED
:
1933 /* Used for debugging. Abort if any window has a dead buffer. */
1936 check_all_windows ()
1938 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
1941 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 1, 0,
1942 doc
: /* Return the window least recently selected or used for display.
1943 If optional argument FRAME is `visible', search all visible frames.
1944 If FRAME is 0, search all visible and iconified frames.
1945 If FRAME is t, search all frames.
1946 If FRAME is nil, search only the selected frame.
1947 If FRAME is a frame, search only that frame. */)
1951 register Lisp_Object w
;
1952 /* First try for a window that is full-width */
1953 w
= window_loop (GET_LRU_WINDOW
, Qt
, 0, frame
);
1954 if (!NILP (w
) && !EQ (w
, selected_window
))
1956 /* If none of them, try the rest */
1957 return window_loop (GET_LRU_WINDOW
, Qnil
, 0, frame
);
1960 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 1, 0,
1961 doc
: /* Return the largest window in area.
1962 If optional argument FRAME is `visible', search all visible frames.
1963 If FRAME is 0, search all visible and iconified frames.
1964 If FRAME is t, search all frames.
1965 If FRAME is nil, search only the selected frame.
1966 If FRAME is a frame, search only that frame. */)
1970 return window_loop (GET_LARGEST_WINDOW
, Qnil
, 0,
1974 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
1975 doc
: /* Return a window currently displaying BUFFER, or nil if none.
1976 If optional argument FRAME is `visible', search all visible frames.
1977 If optional argument FRAME is 0, search all visible and iconified frames.
1978 If FRAME is t, search all frames.
1979 If FRAME is nil, search only the selected frame.
1980 If FRAME is a frame, search only that frame. */)
1982 Lisp_Object buffer
, frame
;
1984 buffer
= Fget_buffer (buffer
);
1985 if (BUFFERP (buffer
))
1986 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
1991 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
1993 doc
: /* Make WINDOW (or the selected window) fill its frame.
1994 Only the frame WINDOW is on is affected.
1995 This function tries to reduce display jumps
1996 by keeping the text previously visible in WINDOW
1997 in the same place on the frame. Doing this depends on
1998 the value of (window-start WINDOW), so if calling this function
1999 in a program gives strange scrolling, make sure the window-start
2000 value is reasonable when this function is called. */)
2009 window
= selected_window
;
2011 CHECK_LIVE_WINDOW (window
);
2012 w
= XWINDOW (window
);
2014 startpos
= marker_position (w
->start
);
2015 top
= XFASTINT (w
->top
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2017 if (MINI_WINDOW_P (w
) && top
> 0)
2018 error ("Can't expand minibuffer to full frame");
2020 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
2022 /* Try to minimize scrolling, by setting the window start to the point
2023 will cause the text at the old window start to be at the same place
2024 on the frame. But don't try to do this if the window start is
2025 outside the visible portion (as might happen when the display is
2026 not current, due to typeahead). */
2027 new_top
= XFASTINT (w
->top
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2029 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2030 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2032 struct position pos
;
2033 struct buffer
*obuf
= current_buffer
;
2035 Fset_buffer (w
->buffer
);
2036 /* This computation used to temporarily move point, but that can
2037 have unwanted side effects due to text properties. */
2038 pos
= *vmotion (startpos
, -top
, w
);
2040 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2041 w
->window_end_valid
= Qnil
;
2042 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
2043 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
2045 /* We need to do this, so that the window-scroll-functions
2047 w
->optional_new_start
= Qt
;
2049 set_buffer_internal (obuf
);
2055 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
2056 1, 2, "bDelete windows on (buffer): ",
2057 doc
: /* Delete all windows showing BUFFER.
2058 Optional second argument FRAME controls which frames are affected.
2059 If optional argument FRAME is `visible', search all visible frames.
2060 If FRAME is 0, search all visible and iconified frames.
2061 If FRAME is nil, search all frames.
2062 If FRAME is t, search only the selected frame.
2063 If FRAME is a frame, search only that frame. */)
2065 Lisp_Object buffer
, frame
;
2067 /* FRAME uses t and nil to mean the opposite of what window_loop
2071 else if (EQ (frame
, Qt
))
2076 buffer
= Fget_buffer (buffer
);
2077 CHECK_BUFFER (buffer
);
2078 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
2084 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
2085 Sreplace_buffer_in_windows
,
2086 1, 1, "bReplace buffer in windows: ",
2087 doc
: /* Replace BUFFER with some other buffer in all windows showing it. */)
2093 buffer
= Fget_buffer (buffer
);
2094 CHECK_BUFFER (buffer
);
2095 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
2100 /* Replace BUFFER with some other buffer in all windows
2101 of all frames, even those on other keyboards. */
2104 replace_buffer_in_all_windows (buffer
)
2108 Lisp_Object tail
, frame
;
2110 /* A single call to window_loop won't do the job
2111 because it only considers frames on the current keyboard.
2112 So loop manually over frames, and handle each one. */
2113 FOR_EACH_FRAME (tail
, frame
)
2114 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
2116 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
2120 /* Set the height of WINDOW and all its inferiors. */
2122 /* The smallest acceptable dimensions for a window. Anything smaller
2123 might crash Emacs. */
2125 #define MIN_SAFE_WINDOW_WIDTH (2)
2126 #define MIN_SAFE_WINDOW_HEIGHT (1)
2128 /* Make sure that window_min_height and window_min_width are
2129 not too small; if they are, set them to safe minima. */
2132 check_min_window_sizes ()
2134 /* Smaller values might permit a crash. */
2135 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
2136 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
2137 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
2138 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
2141 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2142 minimum allowable size. */
2145 check_frame_size (frame
, rows
, cols
)
2149 /* For height, we have to see:
2150 how many windows the frame has at minimum (one or two),
2151 and whether it has a menu bar or other special stuff at the top. */
2153 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
2154 ? MIN_SAFE_WINDOW_HEIGHT
2155 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
2157 if (FRAME_TOP_MARGIN (frame
) > 0)
2158 min_height
+= FRAME_TOP_MARGIN (frame
);
2160 if (*rows
< min_height
)
2162 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2163 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2167 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2168 check if W's width can be changed, otherwise check W's height.
2169 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2170 siblings, too. If none of the siblings is resizable, WINDOW isn't
2174 window_fixed_size_p (w
, width_p
, check_siblings_p
)
2176 int width_p
, check_siblings_p
;
2181 if (!NILP (w
->hchild
))
2183 c
= XWINDOW (w
->hchild
);
2187 /* A horiz. combination is fixed-width if all of if its
2189 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2190 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2191 fixed_p
= c
== NULL
;
2195 /* A horiz. combination is fixed-height if one of if its
2197 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2198 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2199 fixed_p
= c
!= NULL
;
2202 else if (!NILP (w
->vchild
))
2204 c
= XWINDOW (w
->vchild
);
2208 /* A vert. combination is fixed-width if one of if its
2210 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2211 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2212 fixed_p
= c
!= NULL
;
2216 /* A vert. combination is fixed-height if all of if its
2218 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2219 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2220 fixed_p
= c
== NULL
;
2223 else if (BUFFERP (w
->buffer
))
2225 if (w
->height_fixed_p
&& !width_p
)
2229 struct buffer
*old
= current_buffer
;
2232 current_buffer
= XBUFFER (w
->buffer
);
2233 val
= find_symbol_value (Qwindow_size_fixed
);
2234 current_buffer
= old
;
2237 if (!EQ (val
, Qunbound
))
2239 fixed_p
= !NILP (val
);
2242 && ((EQ (val
, Qheight
) && width_p
)
2243 || (EQ (val
, Qwidth
) && !width_p
)))
2248 /* Can't tell if this one is resizable without looking at
2249 siblings. If all siblings are fixed-size this one is too. */
2250 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
2254 for (child
= w
->prev
; !NILP (child
); child
= XWINDOW (child
)->prev
)
2255 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2259 for (child
= w
->next
; !NILP (child
); child
= XWINDOW (child
)->next
)
2260 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2274 /* Return the minimum size of window W, not taking fixed-width windows
2275 into account. WIDTH_P non-zero means return the minimum width,
2276 otherwise return the minimum height. If W is a combination window,
2277 compute the minimum size from the minimum sizes of W's children. */
2280 window_min_size_1 (w
, width_p
)
2287 if (!NILP (w
->hchild
))
2289 c
= XWINDOW (w
->hchild
);
2294 /* The min width of a horizontal combination is
2295 the sum of the min widths of its children. */
2298 size
+= window_min_size_1 (c
, width_p
);
2299 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2304 /* The min height a horizontal combination equals
2305 the maximum of all min height of its children. */
2308 int min_size
= window_min_size_1 (c
, width_p
);
2309 size
= max (min_size
, size
);
2310 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2314 else if (!NILP (w
->vchild
))
2316 c
= XWINDOW (w
->vchild
);
2321 /* The min width of a vertical combination is
2322 the maximum of the min widths of its children. */
2325 int min_size
= window_min_size_1 (c
, width_p
);
2326 size
= max (min_size
, size
);
2327 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2332 /* The min height of a vertical combination equals
2333 the sum of the min height of its children. */
2336 size
+= window_min_size_1 (c
, width_p
);
2337 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2344 size
= window_min_width
;
2347 if (MINI_WINDOW_P (w
)
2348 || (!WINDOW_WANTS_MODELINE_P (w
)
2349 && !WINDOW_WANTS_HEADER_LINE_P (w
)))
2352 size
= window_min_height
;
2360 /* Return the minimum size of window W, taking fixed-size windows into
2361 account. WIDTH_P non-zero means return the minimum width,
2362 otherwise return the minimum height. IGNORE_FIXED_P non-zero means
2363 ignore if W is fixed-size. Set *FIXED to 1 if W is fixed-size
2364 unless FIXED is null. */
2367 window_min_size (w
, width_p
, ignore_fixed_p
, fixed
)
2369 int width_p
, ignore_fixed_p
, *fixed
;
2376 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
2382 size
= width_p
? XFASTINT (w
->width
) : XFASTINT (w
->height
);
2384 size
= window_min_size_1 (w
, width_p
);
2390 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
2391 WINDOW's width. Resize WINDOW's children, if any, so that they
2392 keep their proportionate size relative to WINDOW. Propagate
2393 WINDOW's top or left edge position to children. Delete windows
2394 that become too small unless NODELETE_P is non-zero.
2396 If NODELETE_P is 2, that means we do delete windows that are
2397 too small, even if they were too small before! */
2400 size_window (window
, size
, width_p
, nodelete_p
)
2402 int size
, width_p
, nodelete_p
;
2404 struct window
*w
= XWINDOW (window
);
2406 Lisp_Object child
, *forward
, *sideward
;
2407 int old_size
, min_size
;
2409 if (nodelete_p
== 2)
2412 check_min_window_sizes ();
2413 size
= max (0, size
);
2415 /* If the window has been "too small" at one point,
2416 don't delete it for being "too small" in the future.
2417 Preserve it as long as that is at all possible. */
2420 old_size
= XINT (w
->width
);
2421 min_size
= window_min_width
;
2425 old_size
= XINT (w
->height
);
2426 min_size
= window_min_height
;
2429 if (old_size
< min_size
&& nodelete_p
!= 2)
2430 w
->too_small_ok
= Qt
;
2432 /* Maybe delete WINDOW if it's too small. */
2433 if (nodelete_p
!= 1 && !NILP (w
->parent
))
2435 if (!MINI_WINDOW_P (w
) && !NILP (w
->too_small_ok
))
2436 min_size
= width_p
? MIN_SAFE_WINDOW_WIDTH
: MIN_SAFE_WINDOW_HEIGHT
;
2438 min_size
= width_p
? window_min_width
: window_min_height
;
2440 if (size
< min_size
)
2442 delete_window (window
);
2447 /* Set redisplay hints. */
2448 w
->last_modified
= make_number (0);
2449 w
->last_overlay_modified
= make_number (0);
2450 windows_or_buffers_changed
++;
2451 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w
->frame
)) = 1;
2455 sideward
= &w
->vchild
;
2456 forward
= &w
->hchild
;
2457 w
->width
= make_number (size
);
2461 sideward
= &w
->hchild
;
2462 forward
= &w
->vchild
;
2463 w
->height
= make_number (size
);
2464 w
->orig_height
= Qnil
;
2467 if (!NILP (*sideward
))
2469 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
2471 c
= XWINDOW (child
);
2476 size_window (child
, size
, width_p
, nodelete_p
);
2479 else if (!NILP (*forward
))
2481 int fixed_size
, each
, extra
, n
;
2482 int resize_fixed_p
, nfixed
;
2483 int last_pos
, first_pos
, nchildren
, total
;
2485 /* Determine the fixed-size portion of the this window, and the
2486 number of child windows. */
2487 fixed_size
= nchildren
= nfixed
= total
= 0;
2488 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
2492 c
= XWINDOW (child
);
2493 child_size
= width_p
? XINT (c
->width
) : XINT (c
->height
);
2494 total
+= child_size
;
2496 if (window_fixed_size_p (c
, width_p
, 0))
2498 fixed_size
+= child_size
;
2503 /* If the new size is smaller than fixed_size, or if there
2504 aren't any resizable windows, allow resizing fixed-size
2506 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
2508 /* Compute how many lines/columns to add to each child. The
2509 value of extra takes care of rounding errors. */
2510 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
2511 each
= (size
- total
) / n
;
2512 extra
= (size
- total
) - n
* each
;
2514 /* Compute new children heights and edge positions. */
2515 first_pos
= width_p
? XINT (w
->left
) : XINT (w
->top
);
2516 last_pos
= first_pos
;
2517 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2519 int new_size
, old_size
;
2521 c
= XWINDOW (child
);
2522 old_size
= width_p
? XFASTINT (c
->width
) : XFASTINT (c
->height
);
2523 new_size
= old_size
;
2525 /* The top or left edge position of this child equals the
2526 bottom or right edge of its predecessor. */
2528 c
->left
= make_number (last_pos
);
2530 c
->top
= make_number (last_pos
);
2532 /* If this child can be resized, do it. */
2533 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
2535 new_size
= old_size
+ each
+ extra
;
2539 /* Set new height. Note that size_window also propagates
2540 edge positions to children, so it's not a no-op if we
2541 didn't change the child's size. */
2542 size_window (child
, new_size
, width_p
, 1);
2544 /* Remember the bottom/right edge position of this child; it
2545 will be used to set the top/left edge of the next child. */
2546 last_pos
+= new_size
;
2549 /* We should have covered the parent exactly with child windows. */
2550 xassert (size
== last_pos
- first_pos
);
2552 /* Now delete any children that became too small. */
2554 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2557 c
= XWINDOW (child
);
2558 child_size
= width_p
? XINT (c
->width
) : XINT (c
->height
);
2559 size_window (child
, child_size
, width_p
, 2);
2564 /* Set WINDOW's height to HEIGHT, and recursively change the height of
2565 WINDOW's children. NODELETE non-zero means don't delete windows
2566 that become too small in the process. (The caller should check
2567 later and do so if appropriate.) */
2570 set_window_height (window
, height
, nodelete
)
2575 size_window (window
, height
, 0, nodelete
);
2579 /* Set WINDOW's width to WIDTH, and recursively change the width of
2580 WINDOW's children. NODELETE non-zero means don't delete windows
2581 that become too small in the process. (The caller should check
2582 later and do so if appropriate.) */
2585 set_window_width (window
, width
, nodelete
)
2590 size_window (window
, width
, 1, nodelete
);
2594 int window_select_count
;
2597 Fset_window_buffer_unwind (obuf
)
2605 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
2606 means it's allowed to run hooks. See make_frame for a case where
2607 it's not allowed. */
2610 set_window_buffer (window
, buffer
, run_hooks_p
)
2611 Lisp_Object window
, buffer
;
2614 struct window
*w
= XWINDOW (window
);
2615 struct buffer
*b
= XBUFFER (buffer
);
2616 int count
= specpdl_ptr
- specpdl
;
2620 if (EQ (window
, selected_window
))
2621 b
->last_selected_window
= window
;
2623 /* Update time stamps of buffer display. */
2624 if (INTEGERP (b
->display_count
))
2625 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
2626 b
->display_time
= Fcurrent_time ();
2628 XSETFASTINT (w
->window_end_pos
, 0);
2629 XSETFASTINT (w
->window_end_vpos
, 0);
2630 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
2631 w
->window_end_valid
= Qnil
;
2632 w
->hscroll
= w
->min_hscroll
= make_number (0);
2634 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
2635 set_marker_restricted (w
->start
,
2636 make_number (b
->last_window_start
),
2638 w
->start_at_line_beg
= Qnil
;
2639 w
->force_start
= Qnil
;
2640 XSETFASTINT (w
->last_modified
, 0);
2641 XSETFASTINT (w
->last_overlay_modified
, 0);
2642 windows_or_buffers_changed
++;
2644 /* We must select BUFFER for running the window-scroll-functions.
2645 If WINDOW is selected, switch permanently.
2646 Otherwise, switch but go back to the ambient buffer afterward. */
2647 if (EQ (window
, selected_window
))
2648 Fset_buffer (buffer
);
2649 /* We can't check ! NILP (Vwindow_scroll_functions) here
2650 because that might itself be a local variable. */
2651 else if (window_initialized
)
2653 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
2654 Fset_buffer (buffer
);
2657 /* Set left and right marginal area width from buffer. */
2658 Fset_window_margins (window
, b
->left_margin_width
, b
->right_margin_width
);
2662 if (! NILP (Vwindow_scroll_functions
))
2663 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2664 Fmarker_position (w
->start
));
2666 if (! NILP (Vwindow_configuration_change_hook
)
2667 && ! NILP (Vrun_hooks
))
2668 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2671 unbind_to (count
, Qnil
);
2675 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 2, 0,
2676 doc
: /* Make WINDOW display BUFFER as its contents.
2677 BUFFER can be a buffer or buffer name. */)
2679 register Lisp_Object window
, buffer
;
2681 register Lisp_Object tem
;
2682 register struct window
*w
= decode_window (window
);
2684 XSETWINDOW (window
, w
);
2685 buffer
= Fget_buffer (buffer
);
2686 CHECK_BUFFER (buffer
);
2688 if (NILP (XBUFFER (buffer
)->name
))
2689 error ("Attempt to display deleted buffer");
2693 error ("Window is deleted");
2694 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
2695 is first being set up. */
2697 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
2698 error ("Window is dedicated to `%s'",
2699 XSTRING (XBUFFER (tem
)->name
)->data
);
2704 set_window_buffer (window
, buffer
, 1);
2708 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 1, 0,
2709 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
2710 If WINDOW is not already selected, also make WINDOW's buffer current.
2711 Note that the main editor command loop
2712 selects the buffer of the selected window before each command. */)
2714 register Lisp_Object window
;
2716 return select_window_1 (window
, 1);
2719 /* Note that selected_window can be nil
2720 when this is called from Fset_window_configuration. */
2723 select_window_1 (window
, recordflag
)
2724 register Lisp_Object window
;
2727 register struct window
*w
;
2728 register struct window
*ow
;
2731 CHECK_LIVE_WINDOW (window
);
2733 w
= XWINDOW (window
);
2734 w
->frozen_window_start_p
= 0;
2736 XSETFASTINT (w
->use_time
, ++window_select_count
);
2737 if (EQ (window
, selected_window
))
2740 if (!NILP (selected_window
))
2742 ow
= XWINDOW (selected_window
);
2743 if (! NILP (ow
->buffer
))
2744 set_marker_both (ow
->pointm
, ow
->buffer
,
2745 BUF_PT (XBUFFER (ow
->buffer
)),
2746 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
2749 selected_window
= window
;
2750 sf
= SELECTED_FRAME ();
2751 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
2753 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
2754 /* Use this rather than Fhandle_switch_frame
2755 so that FRAME_FOCUS_FRAME is moved appropriately as we
2756 move around in the state where a minibuffer in a separate
2758 Fselect_frame (WINDOW_FRAME (w
), Qnil
);
2761 sf
->selected_window
= window
;
2764 record_buffer (w
->buffer
);
2765 Fset_buffer (w
->buffer
);
2767 XBUFFER (w
->buffer
)->last_selected_window
= window
;
2769 /* Go to the point recorded in the window.
2770 This is important when the buffer is in more
2771 than one window. It also matters when
2772 redisplay_window has altered point after scrolling,
2773 because it makes the change only in the window. */
2775 register int new_point
= marker_position (w
->pointm
);
2776 if (new_point
< BEGV
)
2778 else if (new_point
> ZV
)
2784 windows_or_buffers_changed
++;
2788 /* Deiconify the frame containing the window WINDOW,
2789 unless it is the selected frame;
2792 The reason for the exception for the selected frame
2793 is that it seems better not to change the selected frames visibility
2794 merely because of displaying a different buffer in it.
2795 The deiconification is useful when a buffer gets shown in
2796 another frame that you were not using lately. */
2799 display_buffer_1 (window
)
2802 Lisp_Object frame
= XWINDOW (window
)->frame
;
2803 FRAME_PTR f
= XFRAME (frame
);
2805 FRAME_SAMPLE_VISIBILITY (f
);
2807 if (!EQ (frame
, selected_frame
))
2809 if (FRAME_ICONIFIED_P (f
))
2810 Fmake_frame_visible (frame
);
2811 else if (FRAME_VISIBLE_P (f
))
2812 Fraise_frame (frame
);
2818 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
2819 doc
: /* Returns non-nil if a buffer named BUFFER-NAME would be created specially.
2820 The value is actually t if the frame should be called with default frame
2821 parameters, and a list of frame parameters if they were specified.
2822 See `special-display-buffer-names', and `special-display-regexps'. */)
2824 Lisp_Object buffer_name
;
2828 CHECK_STRING (buffer_name
);
2830 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
2834 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
2838 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2840 Lisp_Object car
= XCAR (tem
);
2842 && fast_string_match (car
, buffer_name
) >= 0)
2844 else if (CONSP (car
)
2845 && STRINGP (XCAR (car
))
2846 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2852 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
2853 doc
: /* Returns non-nil if a new buffer named BUFFER-NAME would use the same window.
2854 See `same-window-buffer-names' and `same-window-regexps'. */)
2856 Lisp_Object buffer_name
;
2860 CHECK_STRING (buffer_name
);
2862 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
2866 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
2870 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2872 Lisp_Object car
= XCAR (tem
);
2874 && fast_string_match (car
, buffer_name
) >= 0)
2876 else if (CONSP (car
)
2877 && STRINGP (XCAR (car
))
2878 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2884 /* Use B so the default is (other-buffer). */
2885 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
2886 "BDisplay buffer: \nP",
2887 doc
: /* Make BUFFER appear in some window but don't select it.
2888 BUFFER can be a buffer or a buffer name.
2889 If BUFFER is shown already in some window, just use that one,
2890 unless the window is the selected window and the optional second
2891 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).
2892 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
2893 Returns the window displaying BUFFER.
2894 If `display-reuse-frames' is non-nil, and another frame is currently
2895 displaying BUFFER, then simply raise that frame.
2897 The variables `special-display-buffer-names', `special-display-regexps',
2898 `same-window-buffer-names', and `same-window-regexps' customize how certain
2899 buffer names are handled.
2901 If optional argument FRAME is `visible', search all visible frames.
2902 If FRAME is 0, search all visible and iconified frames.
2903 If FRAME is t, search all frames.
2904 If FRAME is a frame, search only that frame.
2905 If FRAME is nil, search only the selected frame
2906 (actually the last nonminibuffer frame),
2907 unless `pop-up-frames' or `display-buffer-reuse-frames' is non-nil,
2908 which means search visible and iconified frames.
2910 If `even-window-heights' is non-nil, window heights will be evened out
2911 if displaying the buffer causes two vertically adjacent windows to be
2913 (buffer
, not_this_window
, frame
)
2914 register Lisp_Object buffer
, not_this_window
, frame
;
2916 register Lisp_Object window
, tem
, swp
;
2920 buffer
= Fget_buffer (buffer
);
2921 CHECK_BUFFER (buffer
);
2923 if (!NILP (Vdisplay_buffer_function
))
2924 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
2926 if (NILP (not_this_window
)
2927 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
2928 return display_buffer_1 (selected_window
);
2930 /* See if the user has specified this buffer should appear
2931 in the selected window. */
2932 if (NILP (not_this_window
))
2934 swp
= Fsame_window_p (XBUFFER (buffer
)->name
);
2935 if (!NILP (swp
) && !no_switch_window (selected_window
))
2937 Fswitch_to_buffer (buffer
, Qnil
);
2938 return display_buffer_1 (selected_window
);
2942 /* If the user wants pop-up-frames or display-reuse-frames, then
2943 look for a window showing BUFFER on any visible or iconified frame.
2944 Otherwise search only the current frame. */
2947 else if (pop_up_frames
2948 || display_buffer_reuse_frames
2949 || last_nonminibuf_frame
== 0)
2950 XSETFASTINT (tem
, 0);
2952 XSETFRAME (tem
, last_nonminibuf_frame
);
2954 window
= Fget_buffer_window (buffer
, tem
);
2956 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
2957 return display_buffer_1 (window
);
2959 /* Certain buffer names get special handling. */
2960 if (!NILP (Vspecial_display_function
) && NILP (swp
))
2962 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
2964 return call1 (Vspecial_display_function
, buffer
);
2966 return call2 (Vspecial_display_function
, buffer
, tem
);
2969 /* If there are no frames open that have more than a minibuffer,
2970 we need to create a new frame. */
2971 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2973 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2974 Fset_window_buffer (window
, buffer
);
2975 return display_buffer_1 (window
);
2978 f
= SELECTED_FRAME ();
2980 || FRAME_MINIBUF_ONLY_P (f
)
2981 /* If the current frame is a special display frame,
2982 don't try to reuse its windows. */
2983 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (f
))->dedicated
))
2988 if (FRAME_MINIBUF_ONLY_P (f
))
2989 XSETFRAME (frames
, last_nonminibuf_frame
);
2990 /* Don't try to create a window if would get an error */
2991 if (split_height_threshold
< window_min_height
<< 1)
2992 split_height_threshold
= window_min_height
<< 1;
2994 /* Note that both Fget_largest_window and Fget_lru_window
2995 ignore minibuffers and dedicated windows.
2996 This means they can return nil. */
2998 /* If the frame we would try to split cannot be split,
2999 try other frames. */
3000 if (FRAME_NO_SPLIT_P (NILP (frames
) ? f
: last_nonminibuf_frame
))
3002 /* Try visible frames first. */
3003 window
= Fget_largest_window (Qvisible
);
3004 /* If that didn't work, try iconified frames. */
3006 window
= Fget_largest_window (make_number (0));
3008 window
= Fget_largest_window (Qt
);
3011 window
= Fget_largest_window (frames
);
3013 /* If we got a tall enough full-width window that can be split,
3016 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3017 && window_height (window
) >= split_height_threshold
3018 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
3019 window
= Fsplit_window (window
, Qnil
, Qnil
);
3022 Lisp_Object upper
, lower
, other
;
3024 window
= Fget_lru_window (frames
);
3025 /* If the LRU window is selected, and big enough,
3026 and can be split, split it. */
3028 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3029 && (EQ (window
, selected_window
)
3030 || EQ (XWINDOW (window
)->parent
, Qnil
))
3031 && window_height (window
) >= window_min_height
<< 1)
3032 window
= Fsplit_window (window
, Qnil
, Qnil
);
3033 /* If Fget_lru_window returned nil, try other approaches. */
3035 /* Try visible frames first. */
3037 window
= Fget_buffer_window (buffer
, Qvisible
);
3039 window
= Fget_largest_window (Qvisible
);
3040 /* If that didn't work, try iconified frames. */
3042 window
= Fget_buffer_window (buffer
, make_number (0));
3044 window
= Fget_largest_window (make_number (0));
3045 /* Try invisible frames. */
3047 window
= Fget_buffer_window (buffer
, Qt
);
3049 window
= Fget_largest_window (Qt
);
3050 /* As a last resort, make a new frame. */
3052 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3053 /* If window appears above or below another,
3054 even out their heights. */
3055 other
= upper
= lower
= Qnil
;
3056 if (!NILP (XWINDOW (window
)->prev
))
3057 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
3058 if (!NILP (XWINDOW (window
)->next
))
3059 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
3061 && !NILP (Veven_window_heights
)
3062 /* Check that OTHER and WINDOW are vertically arrayed. */
3063 && !EQ (XWINDOW (other
)->top
, XWINDOW (window
)->top
)
3064 && (XFASTINT (XWINDOW (other
)->height
)
3065 > XFASTINT (XWINDOW (window
)->height
)))
3067 int total
= (XFASTINT (XWINDOW (other
)->height
)
3068 + XFASTINT (XWINDOW (window
)->height
));
3069 enlarge_window (upper
,
3070 total
/ 2 - XFASTINT (XWINDOW (upper
)->height
),
3076 window
= Fget_lru_window (Qnil
);
3078 Fset_window_buffer (window
, buffer
);
3079 return display_buffer_1 (window
);
3083 temp_output_buffer_show (buf
)
3084 register Lisp_Object buf
;
3086 register struct buffer
*old
= current_buffer
;
3087 register Lisp_Object window
;
3088 register struct window
*w
;
3090 XBUFFER (buf
)->directory
= current_buffer
->directory
;
3093 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3097 XBUFFER (buf
)->prevent_redisplay_optimizations_p
= 1;
3098 set_buffer_internal (old
);
3100 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
3101 call1 (Vtemp_buffer_show_function
, buf
);
3104 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
3106 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3107 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3108 Vminibuf_scroll_window
= window
;
3109 w
= XWINDOW (window
);
3110 XSETFASTINT (w
->hscroll
, 0);
3111 XSETFASTINT (w
->min_hscroll
, 0);
3112 set_marker_restricted_both (w
->start
, buf
, 1, 1);
3113 set_marker_restricted_both (w
->pointm
, buf
, 1, 1);
3115 /* Run temp-buffer-show-hook, with the chosen window selected
3116 and it sbuffer current. */
3117 if (!NILP (Vrun_hooks
))
3120 tem
= Fboundp (Qtemp_buffer_show_hook
);
3123 tem
= Fsymbol_value (Qtemp_buffer_show_hook
);
3126 int count
= specpdl_ptr
- specpdl
;
3127 Lisp_Object prev_window
;
3128 prev_window
= selected_window
;
3130 /* Select the window that was chosen, for running the hook. */
3131 record_unwind_protect (Fselect_window
, prev_window
);
3132 select_window_1 (window
, 0);
3133 Fset_buffer (w
->buffer
);
3134 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
3135 select_window_1 (prev_window
, 0);
3136 unbind_to (count
, Qnil
);
3144 make_dummy_parent (window
)
3148 register struct window
*o
, *p
;
3151 o
= XWINDOW (window
);
3152 p
= allocate_window ();
3153 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
3154 ((struct Lisp_Vector
*) p
)->contents
[i
]
3155 = ((struct Lisp_Vector
*)o
)->contents
[i
];
3156 XSETWINDOW (new, p
);
3158 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
3160 /* Put new into window structure in place of window */
3161 replace_window (window
, new);
3174 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
3175 doc
: /* Split WINDOW, putting SIZE lines in the first of the pair.
3176 WINDOW defaults to selected one and SIZE to half its size.
3177 If optional third arg HORFLAG is non-nil, split side by side
3178 and put SIZE columns in the first of the pair. In that case,
3179 SIZE includes that window's scroll bar, or the divider column to its right. */)
3180 (window
, size
, horflag
)
3181 Lisp_Object window
, size
, horflag
;
3183 register Lisp_Object
new;
3184 register struct window
*o
, *p
;
3186 register int size_int
;
3189 window
= selected_window
;
3191 CHECK_LIVE_WINDOW (window
);
3193 o
= XWINDOW (window
);
3194 fo
= XFRAME (WINDOW_FRAME (o
));
3198 if (!NILP (horflag
))
3199 /* Calculate the size of the left-hand window, by dividing
3200 the usable space in columns by two.
3201 We round up, since the left-hand window may include
3202 a dividing line, while the right-hand may not. */
3203 size_int
= (XFASTINT (o
->width
) + 1) >> 1;
3205 size_int
= XFASTINT (o
->height
) >> 1;
3209 CHECK_NUMBER (size
);
3210 size_int
= XINT (size
);
3213 if (MINI_WINDOW_P (o
))
3214 error ("Attempt to split minibuffer window");
3215 else if (window_fixed_size_p (o
, !NILP (horflag
), 0))
3216 error ("Attempt to split fixed-size window");
3218 check_min_window_sizes ();
3222 if (size_int
< window_min_height
)
3223 error ("Window height %d too small (after splitting)", size_int
);
3224 if (size_int
+ window_min_height
> XFASTINT (o
->height
))
3225 error ("Window height %d too small (after splitting)",
3226 XFASTINT (o
->height
) - size_int
);
3227 if (NILP (o
->parent
)
3228 || NILP (XWINDOW (o
->parent
)->vchild
))
3230 make_dummy_parent (window
);
3232 XWINDOW (new)->vchild
= window
;
3237 if (size_int
< window_min_width
)
3238 error ("Window width %d too small (after splitting)", size_int
);
3240 if (size_int
+ window_min_width
> XFASTINT (o
->width
))
3241 error ("Window width %d too small (after splitting)",
3242 XFASTINT (o
->width
) - size_int
);
3243 if (NILP (o
->parent
)
3244 || NILP (XWINDOW (o
->parent
)->hchild
))
3246 make_dummy_parent (window
);
3248 XWINDOW (new)->hchild
= window
;
3252 /* Now we know that window's parent is a vertical combination
3253 if we are dividing vertically, or a horizontal combination
3254 if we are making side-by-side windows */
3256 windows_or_buffers_changed
++;
3257 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
3258 new = make_window ();
3261 p
->frame
= o
->frame
;
3263 if (!NILP (p
->next
))
3264 XWINDOW (p
->next
)->prev
= new;
3267 p
->parent
= o
->parent
;
3269 p
->window_end_valid
= Qnil
;
3270 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
3272 /* Apportion the available frame space among the two new windows */
3274 if (!NILP (horflag
))
3276 p
->height
= o
->height
;
3278 XSETFASTINT (p
->width
, XFASTINT (o
->width
) - size_int
);
3279 XSETFASTINT (o
->width
, size_int
);
3280 XSETFASTINT (p
->left
, XFASTINT (o
->left
) + size_int
);
3285 p
->width
= o
->width
;
3286 XSETFASTINT (p
->height
, XFASTINT (o
->height
) - size_int
);
3287 XSETFASTINT (o
->height
, size_int
);
3288 XSETFASTINT (p
->top
, XFASTINT (o
->top
) + size_int
);
3291 /* Adjust glyph matrices. */
3293 Fset_window_buffer (new, o
->buffer
);
3297 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 3, "p",
3298 doc
: /* Make current window ARG lines bigger.
3299 From program, optional second arg non-nil means grow sideways ARG columns.
3300 Interactively, if an argument is not given, make the window one line bigger.
3302 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3303 of the siblings above or to the left of the selected window. Only
3304 siblings to the right or below are changed. */)
3305 (arg
, side
, preserve_before
)
3306 register Lisp_Object arg
, side
, preserve_before
;
3309 enlarge_window (selected_window
, XINT (arg
), !NILP (side
),
3310 !NILP (preserve_before
));
3312 if (! NILP (Vwindow_configuration_change_hook
))
3313 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3318 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
3319 doc
: /* Make current window ARG lines smaller.
3320 From program, optional second arg non-nil means shrink sideways arg columns.
3321 Interactively, if an argument is not given, make the window one line smaller. */)
3323 register Lisp_Object arg
, side
;
3326 enlarge_window (selected_window
, -XINT (arg
), !NILP (side
), 0);
3328 if (! NILP (Vwindow_configuration_change_hook
))
3329 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3335 window_height (window
)
3338 register struct window
*p
= XWINDOW (window
);
3339 return XFASTINT (p
->height
);
3343 window_width (window
)
3346 register struct window
*p
= XWINDOW (window
);
3347 return XFASTINT (p
->width
);
3352 *(widthflag ? &(XWINDOW (w)->left) : &(XWINDOW (w)->top))
3354 #define CURSIZE(w) \
3355 *(widthflag ? &(XWINDOW (w)->width) : &(XWINDOW (w)->height))
3358 /* Enlarge WINDOW by DELTA. WIDTHFLAG non-zero means
3359 increase its width. Siblings of the selected window are resized to
3360 fulfill the size request. If they become too small in the process,
3361 they will be deleted.
3363 If PRESERVE_BEFORE is nonzero, that means don't alter
3364 the siblings to the left or above WINDOW. */
3367 enlarge_window (window
, delta
, widthflag
, preserve_before
)
3369 int delta
, widthflag
, preserve_before
;
3371 Lisp_Object parent
, next
, prev
;
3375 int (*sizefun
) P_ ((Lisp_Object
))
3376 = widthflag
? window_width
: window_height
;
3377 void (*setsizefun
) P_ ((Lisp_Object
, int, int))
3378 = (widthflag
? set_window_width
: set_window_height
);
3380 /* Check values of window_min_width and window_min_height for
3382 check_min_window_sizes ();
3384 /* Give up if this window cannot be resized. */
3385 if (window_fixed_size_p (XWINDOW (window
), widthflag
, 1))
3386 error ("Window is not resizable");
3388 /* Find the parent of the selected window. */
3391 p
= XWINDOW (window
);
3397 error ("No other window to side of this one");
3402 ? !NILP (XWINDOW (parent
)->hchild
)
3403 : !NILP (XWINDOW (parent
)->vchild
))
3409 sizep
= &CURSIZE (window
);
3412 register int maxdelta
;
3414 /* Compute the maximum size increment this window can have. */
3416 if (preserve_before
)
3420 maxdelta
= (*sizefun
) (parent
) - XINT (*sizep
);
3421 /* Subtract size of siblings before, since we can't take that. */
3422 maxdelta
-= XINT (CURBEG (window
)) - XINT (CURBEG (parent
));
3425 maxdelta
= (!NILP (p
->next
) ? ((*sizefun
) (p
->next
)
3426 - window_min_size (XWINDOW (p
->next
),
3431 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - XINT (*sizep
)
3432 /* This is a main window followed by a minibuffer. */
3433 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
3434 - window_min_size (XWINDOW (p
->next
),
3436 /* This is a minibuffer following a main window. */
3437 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
3438 - window_min_size (XWINDOW (p
->prev
),
3440 /* This is a frame with only one window, a minibuffer-only
3441 or a minibufferless frame. */
3444 if (delta
> maxdelta
)
3445 /* This case traps trying to make the minibuffer
3446 the full frame, or make the only window aside from the
3447 minibuffer the full frame. */
3451 if (XINT (*sizep
) + delta
< window_min_size (XWINDOW (window
), widthflag
, 0, 0))
3453 delete_window (window
);
3460 /* Find the total we can get from other siblings without deleting them. */
3462 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
3463 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
3465 if (! preserve_before
)
3466 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
3467 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
3470 /* If we can get it all from them without deleting them, do so. */
3471 if (delta
<= maximum
)
3473 Lisp_Object first_unaffected
;
3474 Lisp_Object first_affected
;
3479 first_affected
= window
;
3480 /* Look at one sibling at a time,
3481 moving away from this window in both directions alternately,
3482 and take as much as we can get without deleting that sibling. */
3484 && (!NILP (next
) || (!preserve_before
&& !NILP (prev
))))
3488 int this_one
= ((*sizefun
) (next
)
3489 - window_min_size (XWINDOW (next
),
3490 widthflag
, 0, &fixed_p
));
3493 if (this_one
> delta
)
3496 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
3497 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
3502 next
= XWINDOW (next
)->next
;
3508 if (!preserve_before
&& ! NILP (prev
))
3510 int this_one
= ((*sizefun
) (prev
)
3511 - window_min_size (XWINDOW (prev
),
3512 widthflag
, 0, &fixed_p
));
3515 if (this_one
> delta
)
3518 first_affected
= prev
;
3520 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
3521 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
3526 prev
= XWINDOW (prev
)->prev
;
3530 xassert (delta
== 0);
3532 /* Now recalculate the edge positions of all the windows affected,
3533 based on the new sizes. */
3534 first_unaffected
= next
;
3535 prev
= first_affected
;
3536 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
3537 prev
= next
, next
= XWINDOW (next
)->next
)
3539 XSETINT (CURBEG (next
), XINT (CURBEG (prev
)) + (*sizefun
) (prev
));
3540 /* This does not change size of NEXT,
3541 but it propagates the new top edge to its children */
3542 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
3547 register int delta1
;
3548 register int opht
= (*sizefun
) (parent
);
3550 if (opht
<= XINT (*sizep
) + delta
)
3552 /* If trying to grow this window to or beyond size of the parent,
3553 just delete all the sibling windows. */
3554 Lisp_Object start
, tem
, next
;
3556 start
= XWINDOW (parent
)->vchild
;
3558 start
= XWINDOW (parent
)->hchild
;
3560 /* Delete any siblings that come after WINDOW. */
3561 tem
= XWINDOW (window
)->next
;
3562 while (! NILP (tem
))
3564 next
= XWINDOW (tem
)->next
;
3565 delete_window (tem
);
3569 /* Delete any siblings that come after WINDOW.
3570 Note that if START is not WINDOW, then WINDOW still
3571 Fhas siblings, so WINDOW has not yet replaced its parent. */
3573 while (! EQ (tem
, window
))
3575 next
= XWINDOW (tem
)->next
;
3576 delete_window (tem
);
3582 /* Otherwise, make delta1 just right so that if we add
3583 delta1 lines to this window and to the parent, and then
3584 shrink the parent back to its original size, the new
3585 proportional size of this window will increase by delta.
3587 The function size_window will compute the new height h'
3588 of the window from delta1 as:
3591 x = delta1 - delta1/n * n for the 1st resizable child
3594 where n is the number of children that can be resized.
3595 We can ignore x by choosing a delta1 that is a multiple of
3596 n. We want the height of this window to come out as
3606 The number of children n rquals the number of resizable
3607 children of this window + 1 because we know window itself
3608 is resizable (otherwise we would have signalled an error. */
3610 struct window
*w
= XWINDOW (window
);
3614 for (s
= w
->next
; !NILP (s
); s
= XWINDOW (s
)->next
)
3615 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
3617 for (s
= w
->prev
; !NILP (s
); s
= XWINDOW (s
)->prev
)
3618 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
3623 /* Add delta1 lines or columns to this window, and to the parent,
3624 keeping things consistent while not affecting siblings. */
3625 XSETINT (CURSIZE (parent
), opht
+ delta1
);
3626 (*setsizefun
) (window
, XINT (*sizep
) + delta1
, 0);
3628 /* Squeeze out delta1 lines or columns from our parent,
3629 shriking this window and siblings proportionately.
3630 This brings parent back to correct size.
3631 Delta1 was calculated so this makes this window the desired size,
3632 taking it all out of the siblings. */
3633 (*setsizefun
) (parent
, opht
, 0);
3638 XSETFASTINT (p
->last_modified
, 0);
3639 XSETFASTINT (p
->last_overlay_modified
, 0);
3641 /* Adjust glyph matrices. */
3642 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
3650 /***********************************************************************
3651 Resizing Mini-Windows
3652 ***********************************************************************/
3654 static void shrink_window_lowest_first
P_ ((struct window
*, int));
3656 enum save_restore_action
3663 static int save_restore_orig_size
P_ ((struct window
*,
3664 enum save_restore_action
));
3666 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
3667 from lowest windows first. */
3670 shrink_window_lowest_first (w
, height
)
3678 xassert (!MINI_WINDOW_P (w
));
3680 /* Set redisplay hints. */
3681 XSETFASTINT (w
->last_modified
, 0);
3682 XSETFASTINT (w
->last_overlay_modified
, 0);
3683 windows_or_buffers_changed
++;
3684 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
3686 old_height
= XFASTINT (w
->height
);
3687 XSETFASTINT (w
->height
, height
);
3689 if (!NILP (w
->hchild
))
3691 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
3693 c
= XWINDOW (child
);
3695 shrink_window_lowest_first (c
, height
);
3698 else if (!NILP (w
->vchild
))
3700 Lisp_Object last_child
;
3701 int delta
= old_height
- height
;
3706 /* Find the last child. We are taking space from lowest windows
3707 first, so we iterate over children from the last child
3709 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
3712 /* Assign new heights. We leave only MIN_SAFE_WINDOW_HEIGHT. */
3713 for (child
= last_child
; delta
&& !NILP (child
); child
= c
->prev
)
3717 c
= XWINDOW (child
);
3718 this_one
= XFASTINT (c
->height
) - MIN_SAFE_WINDOW_HEIGHT
;
3720 if (this_one
> delta
)
3723 shrink_window_lowest_first (c
, XFASTINT (c
->height
) - this_one
);
3727 /* Compute new positions. */
3728 last_top
= XINT (w
->top
);
3729 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
3731 c
= XWINDOW (child
);
3732 c
->top
= make_number (last_top
);
3733 shrink_window_lowest_first (c
, XFASTINT (c
->height
));
3734 last_top
+= XFASTINT (c
->height
);
3740 /* Save, restore, or check positions and sizes in the window tree
3741 rooted at W. ACTION says what to do.
3743 If ACTION is CHECK_ORIG_SIZES, check if orig_top and orig_height
3744 members are valid for all windows in the window tree. Value is
3745 non-zero if they are valid.
3747 If ACTION is SAVE_ORIG_SIZES, save members top and height in
3748 orig_top and orig_height for all windows in the tree.
3750 If ACTION is RESTORE_ORIG_SIZES, restore top and height from
3751 values stored in orig_top and orig_height for all windows. */
3754 save_restore_orig_size (w
, action
)
3756 enum save_restore_action action
;
3762 if (!NILP (w
->hchild
))
3764 if (!save_restore_orig_size (XWINDOW (w
->hchild
), action
))
3767 else if (!NILP (w
->vchild
))
3769 if (!save_restore_orig_size (XWINDOW (w
->vchild
), action
))
3775 case CHECK_ORIG_SIZES
:
3776 if (!INTEGERP (w
->orig_top
) || !INTEGERP (w
->orig_height
))
3780 case SAVE_ORIG_SIZES
:
3781 w
->orig_top
= w
->top
;
3782 w
->orig_height
= w
->height
;
3783 XSETFASTINT (w
->last_modified
, 0);
3784 XSETFASTINT (w
->last_overlay_modified
, 0);
3787 case RESTORE_ORIG_SIZES
:
3788 xassert (INTEGERP (w
->orig_top
) && INTEGERP (w
->orig_height
));
3789 w
->top
= w
->orig_top
;
3790 w
->height
= w
->orig_height
;
3791 w
->orig_height
= w
->orig_top
= Qnil
;
3792 XSETFASTINT (w
->last_modified
, 0);
3793 XSETFASTINT (w
->last_overlay_modified
, 0);
3800 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
3807 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
3808 without deleting other windows. */
3811 grow_mini_window (w
, delta
)
3815 struct frame
*f
= XFRAME (w
->frame
);
3816 struct window
*root
;
3818 xassert (MINI_WINDOW_P (w
));
3819 xassert (delta
>= 0);
3821 /* Check values of window_min_width and window_min_height for
3823 check_min_window_sizes ();
3825 /* Compute how much we can enlarge the mini-window without deleting
3827 root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3830 int min_height
= window_min_size (root
, 0, 0, 0);
3831 if (XFASTINT (root
->height
) - delta
< min_height
)
3832 /* Note that the root window may already be smaller than
3834 delta
= max (0, XFASTINT (root
->height
) - min_height
);
3839 /* Save original window sizes and positions, if not already done. */
3840 if (!save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
3841 save_restore_orig_size (root
, SAVE_ORIG_SIZES
);
3843 /* Shrink other windows. */
3844 shrink_window_lowest_first (root
, XFASTINT (root
->height
) - delta
);
3846 /* Grow the mini-window. */
3847 w
->top
= make_number (XFASTINT (root
->top
) + XFASTINT (root
->height
));
3848 w
->height
= make_number (XFASTINT (w
->height
) + delta
);
3849 XSETFASTINT (w
->last_modified
, 0);
3850 XSETFASTINT (w
->last_overlay_modified
, 0);
3857 /* Shrink mini-window W. If there is recorded info about window sizes
3858 before a call to grow_mini_window, restore recorded window sizes.
3859 Otherwise, if the mini-window is higher than 1 line, resize it to 1
3863 shrink_mini_window (w
)
3866 struct frame
*f
= XFRAME (w
->frame
);
3867 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3869 if (save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
3871 save_restore_orig_size (root
, RESTORE_ORIG_SIZES
);
3873 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3874 windows_or_buffers_changed
= 1;
3876 else if (XFASTINT (w
->height
) > 1)
3878 /* Distribute the additional lines of the mini-window
3879 among the other windows. */
3881 XSETWINDOW (window
, w
);
3882 enlarge_window (window
, 1 - XFASTINT (w
->height
), 0, 0);
3888 /* Mark window cursors off for all windows in the window tree rooted
3889 at W by setting their phys_cursor_on_p flag to zero. Called from
3890 xterm.c, e.g. when a frame is cleared and thereby all cursors on
3891 the frame are cleared. */
3894 mark_window_cursors_off (w
)
3899 if (!NILP (w
->hchild
))
3900 mark_window_cursors_off (XWINDOW (w
->hchild
));
3901 else if (!NILP (w
->vchild
))
3902 mark_window_cursors_off (XWINDOW (w
->vchild
));
3904 w
->phys_cursor_on_p
= 0;
3906 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3911 /* Return number of lines of text (not counting mode lines) in W. */
3914 window_internal_height (w
)
3917 int ht
= XFASTINT (w
->height
);
3919 if (!MINI_WINDOW_P (w
))
3921 if (!NILP (w
->parent
)
3922 || !NILP (w
->vchild
)
3923 || !NILP (w
->hchild
)
3926 || WINDOW_WANTS_MODELINE_P (w
))
3929 if (WINDOW_WANTS_HEADER_LINE_P (w
))
3937 /* Return the number of columns in W.
3938 Don't count columns occupied by scroll bars or the vertical bar
3939 separating W from the sibling to its right. */
3942 window_internal_width (w
)
3945 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3946 int width
= XINT (w
->width
);
3948 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3949 /* Scroll bars occupy a few columns. */
3950 width
-= FRAME_SCROLL_BAR_COLS (f
);
3951 else if (!WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
3952 /* The column of `|' characters separating side-by-side windows
3953 occupies one column only. */
3956 /* On window-systems, areas to the left and right of the window
3957 are used as fringes. */
3958 if (FRAME_WINDOW_P (f
))
3959 width
-= FRAME_FRINGE_COLS (f
);
3965 /************************************************************************
3967 ***********************************************************************/
3969 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
3970 N screen-fulls, which is defined as the height of the window minus
3971 next_screen_context_lines. If WHOLE is zero, scroll up N lines
3972 instead. Negative values of N mean scroll down. NOERROR non-zero
3973 means don't signal an error if we try to move over BEGV or ZV,
3977 window_scroll (window
, n
, whole
, noerror
)
3983 /* If we must, use the pixel-based version which is much slower than
3984 the line-based one but can handle varying line heights. */
3985 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
3986 window_scroll_pixel_based (window
, n
, whole
, noerror
);
3988 window_scroll_line_based (window
, n
, whole
, noerror
);
3992 /* Implementation of window_scroll that works based on pixel line
3993 heights. See the comment of window_scroll for parameter
3997 window_scroll_pixel_based (window
, n
, whole
, noerror
)
4004 struct window
*w
= XWINDOW (window
);
4005 struct text_pos start
;
4007 int this_scroll_margin
;
4009 /* True if we fiddled the window vscroll field without really scrolling. */
4012 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4014 /* If PT is not visible in WINDOW, move back one half of
4015 the screen. Allow PT to be partially visible, otherwise
4016 something like (scroll-down 1) with PT in the line before
4017 the partially visible one would recenter. */
4018 tem
= Fpos_visible_in_window_p (make_number (PT
), window
, Qt
);
4021 /* Move backward half the height of the window. Performance note:
4022 vmotion used here is about 10% faster, but would give wrong
4023 results for variable height lines. */
4024 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4025 it
.current_y
= it
.last_visible_y
;
4026 move_it_vertically (&it
, - window_box_height (w
) / 2);
4028 /* The function move_iterator_vertically may move over more than
4029 the specified y-distance. If it->w is small, e.g. a
4030 mini-buffer window, we may end up in front of the window's
4031 display area. This is the case when Start displaying at the
4032 start of the line containing PT in this case. */
4033 if (it
.current_y
<= 0)
4035 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4036 move_it_vertically (&it
, 0);
4040 start
= it
.current
.pos
;
4043 /* If scroll_preserve_screen_position is non-zero, we try to set
4044 point in the same window line as it is now, so get that line. */
4045 if (!NILP (Vscroll_preserve_screen_position
))
4047 start_display (&it
, w
, start
);
4048 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4049 preserve_y
= it
.current_y
;
4054 /* Move iterator it from start the specified distance forward or
4055 backward. The result is the new window start. */
4056 start_display (&it
, w
, start
);
4059 int screen_full
= (window_box_height (w
)
4060 - next_screen_context_lines
* CANON_Y_UNIT (it
.f
));
4061 int dy
= n
* screen_full
;
4063 /* Note that move_it_vertically always moves the iterator to the
4064 start of a line. So, if the last line doesn't have a newline,
4065 we would end up at the start of the line ending at ZV. */
4067 move_it_vertically_backward (&it
, -dy
);
4069 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4070 MOVE_TO_POS
| MOVE_TO_Y
);
4073 move_it_by_lines (&it
, n
, 1);
4075 /* End if we end up at ZV or BEGV. */
4076 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4077 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4079 if (IT_CHARPOS (it
) == ZV
)
4081 if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4082 > it
.last_visible_y
)
4084 /* The last line was only partially visible, make it fully
4086 w
->vscroll
= (it
.last_visible_y
4087 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4088 adjust_glyphs (it
.f
);
4093 Fsignal (Qend_of_buffer
, Qnil
);
4097 if (w
->vscroll
!= 0)
4098 /* The first line was only partially visible, make it fully
4104 Fsignal (Qbeginning_of_buffer
, Qnil
);
4107 /* If control gets here, then we vscrolled. */
4109 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
4111 /* Don't try to change the window start below. */
4117 /* Set the window start, and set up the window for redisplay. */
4118 set_marker_restricted (w
->start
, make_number (IT_CHARPOS (it
)),
4120 w
->start_at_line_beg
= Fbolp ();
4121 w
->update_mode_line
= Qt
;
4122 XSETFASTINT (w
->last_modified
, 0);
4123 XSETFASTINT (w
->last_overlay_modified
, 0);
4124 /* Set force_start so that redisplay_window will run the
4125 window-scroll-functions. */
4126 w
->force_start
= Qt
;
4129 it
.current_y
= it
.vpos
= 0;
4131 /* Preserve the screen position if we must. */
4132 if (preserve_y
>= 0)
4134 move_it_to (&it
, -1, -1, preserve_y
, -1, MOVE_TO_Y
);
4135 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4139 /* Move PT out of scroll margins. */
4140 this_scroll_margin
= max (0, scroll_margin
);
4141 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
4142 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
4146 /* We moved the window start towards ZV, so PT may be now
4147 in the scroll margin at the top. */
4148 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4149 while (it
.current_y
< this_scroll_margin
)
4150 move_it_by_lines (&it
, 1, 1);
4151 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4155 int charpos
, bytepos
;
4157 /* We moved the window start towards BEGV, so PT may be now
4158 in the scroll margin at the bottom. */
4159 move_it_to (&it
, PT
, -1,
4160 it
.last_visible_y
- this_scroll_margin
- 1, -1,
4161 MOVE_TO_POS
| MOVE_TO_Y
);
4163 /* Save our position, in case it's correct. */
4164 charpos
= IT_CHARPOS (it
);
4165 bytepos
= IT_BYTEPOS (it
);
4167 /* See if point is on a partially visible line at the end. */
4168 move_it_by_lines (&it
, 1, 1);
4169 if (it
.current_y
> it
.last_visible_y
)
4170 /* The last line was only partially visible, so back up two
4171 lines to make sure we're on a fully visible line. */
4173 move_it_by_lines (&it
, -2, 0);
4174 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4177 /* No, the position we saved is OK, so use it. */
4178 SET_PT_BOTH (charpos
, bytepos
);
4184 /* Implementation of window_scroll that works based on screen lines.
4185 See the comment of window_scroll for parameter descriptions. */
4188 window_scroll_line_based (window
, n
, whole
, noerror
)
4194 register struct window
*w
= XWINDOW (window
);
4195 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
4196 register int pos
, pos_byte
;
4197 register int ht
= window_internal_height (w
);
4198 register Lisp_Object tem
;
4202 struct position posit
;
4205 /* If scrolling screen-fulls, compute the number of lines to
4206 scroll from the window's height. */
4208 n
*= max (1, ht
- next_screen_context_lines
);
4210 startpos
= marker_position (w
->start
);
4212 posit
= *compute_motion (startpos
, 0, 0, 0,
4214 window_internal_width (w
), XINT (w
->hscroll
),
4216 original_vpos
= posit
.vpos
;
4218 XSETFASTINT (tem
, PT
);
4219 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
4223 Fvertical_motion (make_number (- (ht
/ 2)), window
);
4228 lose
= n
< 0 && PT
== BEGV
;
4229 Fvertical_motion (make_number (n
), window
);
4233 SET_PT_BOTH (opoint
, opoint_byte
);
4240 Fsignal (Qbeginning_of_buffer
, Qnil
);
4245 int this_scroll_margin
= scroll_margin
;
4247 /* Don't use a scroll margin that is negative or too large. */
4248 if (this_scroll_margin
< 0)
4249 this_scroll_margin
= 0;
4251 if (XINT (w
->height
) < 4 * scroll_margin
)
4252 this_scroll_margin
= XINT (w
->height
) / 4;
4254 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
4255 w
->start_at_line_beg
= bolp
;
4256 w
->update_mode_line
= Qt
;
4257 XSETFASTINT (w
->last_modified
, 0);
4258 XSETFASTINT (w
->last_overlay_modified
, 0);
4259 /* Set force_start so that redisplay_window will run
4260 the window-scroll-functions. */
4261 w
->force_start
= Qt
;
4263 if (whole
&& !NILP (Vscroll_preserve_screen_position
))
4265 SET_PT_BOTH (pos
, pos_byte
);
4266 Fvertical_motion (make_number (original_vpos
), window
);
4268 /* If we scrolled forward, put point enough lines down
4269 that it is outside the scroll margin. */
4274 if (this_scroll_margin
> 0)
4276 SET_PT_BOTH (pos
, pos_byte
);
4277 Fvertical_motion (make_number (this_scroll_margin
), window
);
4283 if (top_margin
<= opoint
)
4284 SET_PT_BOTH (opoint
, opoint_byte
);
4285 else if (!NILP (Vscroll_preserve_screen_position
))
4287 SET_PT_BOTH (pos
, pos_byte
);
4288 Fvertical_motion (make_number (original_vpos
), window
);
4291 SET_PT (top_margin
);
4297 /* If we scrolled backward, put point near the end of the window
4298 but not within the scroll margin. */
4299 SET_PT_BOTH (pos
, pos_byte
);
4300 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
4301 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
4304 bottom_margin
= PT
+ 1;
4306 if (bottom_margin
> opoint
)
4307 SET_PT_BOTH (opoint
, opoint_byte
);
4310 if (!NILP (Vscroll_preserve_screen_position
))
4312 SET_PT_BOTH (pos
, pos_byte
);
4313 Fvertical_motion (make_number (original_vpos
), window
);
4316 Fvertical_motion (make_number (-1), window
);
4325 Fsignal (Qend_of_buffer
, Qnil
);
4330 /* Scroll selected_window up or down. If N is nil, scroll a
4331 screen-full which is defined as the height of the window minus
4332 next_screen_context_lines. If N is the symbol `-', scroll.
4333 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4334 up. This is the guts of Fscroll_up and Fscroll_down. */
4337 scroll_command (n
, direction
)
4341 int count
= BINDING_STACK_SIZE ();
4343 xassert (abs (direction
) == 1);
4345 /* If selected window's buffer isn't current, make it current for
4346 the moment. But don't screw up if window_scroll gets an error. */
4347 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
4349 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4350 Fset_buffer (XWINDOW (selected_window
)->buffer
);
4352 /* Make redisplay consider other windows than just selected_window. */
4353 ++windows_or_buffers_changed
;
4357 window_scroll (selected_window
, direction
, 1, 0);
4358 else if (EQ (n
, Qminus
))
4359 window_scroll (selected_window
, -direction
, 1, 0);
4362 n
= Fprefix_numeric_value (n
);
4363 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
4366 unbind_to (count
, Qnil
);
4369 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
4370 doc
: /* Scroll text of current window upward ARG lines; or near full screen if no ARG.
4371 A near full screen is `next-screen-context-lines' less than a full screen.
4372 Negative ARG means scroll downward.
4373 If ARG is the atom `-', scroll downward by nearly full screen.
4374 When calling from a program, supply as argument a number, nil, or `-'. */)
4378 scroll_command (arg
, 1);
4382 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
4383 doc
: /* Scroll text of current window down ARG lines; or near full screen if no ARG.
4384 A near full screen is `next-screen-context-lines' less than a full screen.
4385 Negative ARG means scroll upward.
4386 If ARG is the atom `-', scroll upward by nearly full screen.
4387 When calling from a program, supply as argument a number, nil, or `-'. */)
4391 scroll_command (arg
, -1);
4395 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
4396 doc
: /* Return the other window for \"other window scroll\" commands.
4397 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4398 specifies the window.
4399 If `other-window-scroll-buffer' is non-nil, a window
4400 showing that buffer is used. */)
4405 if (MINI_WINDOW_P (XWINDOW (selected_window
))
4406 && !NILP (Vminibuf_scroll_window
))
4407 window
= Vminibuf_scroll_window
;
4408 /* If buffer is specified, scroll that buffer. */
4409 else if (!NILP (Vother_window_scroll_buffer
))
4411 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
4413 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
4417 /* Nothing specified; look for a neighboring window on the same
4419 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
4421 if (EQ (window
, selected_window
))
4422 /* That didn't get us anywhere; look for a window on another
4425 window
= Fnext_window (window
, Qnil
, Qt
);
4426 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
4427 && ! EQ (window
, selected_window
));
4430 CHECK_LIVE_WINDOW (window
);
4432 if (EQ (window
, selected_window
))
4433 error ("There is no other window");
4438 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
4439 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
4440 A near full screen is `next-screen-context-lines' less than a full screen.
4441 The next window is the one below the current one; or the one at the top
4442 if the current one is at the bottom. Negative ARG means scroll downward.
4443 If ARG is the atom `-', scroll downward by nearly full screen.
4444 When calling from a program, supply as argument a number, nil, or `-'.
4446 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4447 specifies the window to scroll.
4448 If `other-window-scroll-buffer' is non-nil, scroll the window
4449 showing that buffer, popping the buffer up if necessary. */)
4455 int count
= BINDING_STACK_SIZE ();
4457 window
= Fother_window_for_scrolling ();
4458 w
= XWINDOW (window
);
4460 /* Don't screw up if window_scroll gets an error. */
4461 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4462 ++windows_or_buffers_changed
;
4464 Fset_buffer (w
->buffer
);
4465 SET_PT (marker_position (w
->pointm
));
4468 window_scroll (window
, 1, 1, 1);
4469 else if (EQ (arg
, Qminus
))
4470 window_scroll (window
, -1, 1, 1);
4476 window_scroll (window
, XINT (arg
), 0, 1);
4479 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
4480 unbind_to (count
, Qnil
);
4485 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 1, "P",
4486 doc
: /* Scroll selected window display ARG columns left.
4487 Default for ARG is window width minus 2.
4488 Value is the total amount of leftward horizontal scrolling in
4489 effect after the change.
4490 If `automatic-hscrolling' is non-nil, the argument ARG modifies
4491 a lower bound for automatic scrolling, i.e. automatic scrolling
4492 will not scroll a window to a column less than the value returned
4493 by this function. */)
4495 register Lisp_Object arg
;
4499 struct window
*w
= XWINDOW (selected_window
);
4502 XSETFASTINT (arg
, window_internal_width (w
) - 2);
4504 arg
= Fprefix_numeric_value (arg
);
4506 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
4507 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
4509 if (interactive_p (0))
4510 w
->min_hscroll
= w
->hscroll
;
4515 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 1, "P",
4516 doc
: /* Scroll selected window display ARG columns right.
4517 Default for ARG is window width minus 2.
4518 Value is the total amount of leftward horizontal scrolling in
4519 effect after the change.
4520 If `automatic-hscrolling' is non-nil, the argument ARG modifies
4521 a lower bound for automatic scrolling, i.e. automatic scrolling
4522 will not scroll a window to a column less than the value returned
4523 by this function. */)
4525 register Lisp_Object arg
;
4529 struct window
*w
= XWINDOW (selected_window
);
4532 XSETFASTINT (arg
, window_internal_width (w
) - 2);
4534 arg
= Fprefix_numeric_value (arg
);
4536 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
4537 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
4539 if (interactive_p (0))
4540 w
->min_hscroll
= w
->hscroll
;
4545 /* Value is the number of lines actually displayed in window W,
4546 as opposed to its height. */
4549 displayed_window_lines (w
)
4553 struct text_pos start
;
4554 int height
= window_box_height (w
);
4555 struct buffer
*old_buffer
;
4558 if (XBUFFER (w
->buffer
) != current_buffer
)
4560 old_buffer
= current_buffer
;
4561 set_buffer_internal (XBUFFER (w
->buffer
));
4566 /* In case W->start is out of the accessible range, do something
4567 reasonable. This happens in Info mode when Info-scroll-down
4568 calls (recenter -1) while W->start is 1. */
4569 if (XMARKER (w
->start
)->charpos
< BEGV
)
4570 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4571 else if (XMARKER (w
->start
)->charpos
> ZV
)
4572 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
4574 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4576 start_display (&it
, w
, start
);
4577 move_it_vertically (&it
, height
);
4578 bottom_y
= line_bottom_y (&it
);
4580 /* Add in empty lines at the bottom of the window. */
4581 if (bottom_y
< height
)
4583 int uy
= CANON_Y_UNIT (it
.f
);
4584 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
4588 set_buffer_internal (old_buffer
);
4594 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
4595 doc
: /* Center point in window and redisplay frame.
4596 With prefix argument ARG, recenter putting point on screen line ARG
4597 relative to the current window. If ARG is negative, it counts up from the
4598 bottom of the window. (ARG should be less than the height of the window.)
4600 If ARG is omitted or nil, erase the entire frame and then
4601 redraw with point in the center of the current window.
4602 Just C-u as prefix means put point in the center of the window
4603 and redisplay normally--don't erase and redraw the frame. */)
4605 register Lisp_Object arg
;
4607 struct window
*w
= XWINDOW (selected_window
);
4608 struct buffer
*buf
= XBUFFER (w
->buffer
);
4609 struct buffer
*obuf
= current_buffer
;
4611 int charpos
, bytepos
;
4613 /* If redisplay is suppressed due to an error, try again. */
4614 obuf
->display_error_modiff
= 0;
4620 /* Invalidate pixel data calculated for all compositions. */
4621 for (i
= 0; i
< n_compositions
; i
++)
4622 composition_table
[i
]->font
= NULL
;
4624 Fredraw_frame (w
->frame
);
4625 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
4628 else if (CONSP (arg
)) /* Just C-u. */
4632 arg
= Fprefix_numeric_value (arg
);
4636 set_buffer_internal (buf
);
4638 /* Handle centering on a graphical frame specially. Such frames can
4639 have variable-height lines and centering point on the basis of
4640 line counts would lead to strange effects. */
4641 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
4648 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
4649 start_display (&it
, w
, pt
);
4650 move_it_vertically (&it
, - window_box_height (w
) / 2);
4651 charpos
= IT_CHARPOS (it
);
4652 bytepos
= IT_BYTEPOS (it
);
4654 else if (XINT (arg
) < 0)
4658 int y0
, y1
, h
, nlines
;
4660 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
4661 start_display (&it
, w
, pt
);
4664 /* The amount of pixels we have to move back is the window
4665 height minus what's displayed in the line containing PT,
4666 and the lines below. */
4667 nlines
= - XINT (arg
) - 1;
4668 move_it_by_lines (&it
, nlines
, 1);
4670 y1
= line_bottom_y (&it
);
4672 /* If we can't move down NLINES lines because we hit
4673 the end of the buffer, count in some empty lines. */
4674 if (it
.vpos
< nlines
)
4675 y1
+= (nlines
- it
.vpos
) * CANON_Y_UNIT (it
.f
);
4677 h
= window_box_height (w
) - (y1
- y0
);
4679 start_display (&it
, w
, pt
);
4680 move_it_vertically (&it
, - h
);
4681 charpos
= IT_CHARPOS (it
);
4682 bytepos
= IT_BYTEPOS (it
);
4686 struct position pos
;
4687 pos
= *vmotion (PT
, - XINT (arg
), w
);
4688 charpos
= pos
.bufpos
;
4689 bytepos
= pos
.bytepos
;
4694 struct position pos
;
4695 int ht
= window_internal_height (w
);
4698 arg
= make_number (ht
/ 2);
4699 else if (XINT (arg
) < 0)
4700 arg
= make_number (XINT (arg
) + ht
);
4702 pos
= *vmotion (PT
, - XINT (arg
), w
);
4703 charpos
= pos
.bufpos
;
4704 bytepos
= pos
.bytepos
;
4707 /* Set the new window start. */
4708 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
4709 w
->window_end_valid
= Qnil
;
4710 w
->force_start
= Qt
;
4711 if (bytepos
== BEGV_BYTE
|| FETCH_BYTE (bytepos
- 1) == '\n')
4712 w
->start_at_line_beg
= Qt
;
4714 w
->start_at_line_beg
= Qnil
;
4716 set_buffer_internal (obuf
);
4721 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
4723 doc
: /* Return the height in lines of the text display area of WINDOW.
4724 This doesn't include the mode-line (or header-line if any) or any
4725 partial-height lines in the text display area. */)
4729 struct window
*w
= decode_window (window
);
4730 int pixel_height
= window_box_height (w
);
4731 int line_height
= pixel_height
/ CANON_Y_UNIT (XFRAME (w
->frame
));
4732 return make_number (line_height
);
4737 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
4739 doc
: /* Position point relative to window.
4740 With no argument, position point at center of window.
4741 An argument specifies vertical position within the window;
4742 zero means top of window, negative means relative to bottom of window. */)
4746 struct window
*w
= XWINDOW (selected_window
);
4750 window
= selected_window
;
4751 start
= marker_position (w
->start
);
4752 if (start
< BEGV
|| start
> ZV
)
4754 int height
= window_internal_height (w
);
4755 Fvertical_motion (make_number (- (height
/ 2)), window
);
4756 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
4757 w
->start_at_line_beg
= Fbolp ();
4758 w
->force_start
= Qt
;
4761 Fgoto_char (w
->start
);
4763 lines
= displayed_window_lines (w
);
4765 XSETFASTINT (arg
, lines
/ 2);
4768 arg
= Fprefix_numeric_value (arg
);
4770 XSETINT (arg
, XINT (arg
) + lines
);
4773 /* Skip past a partially visible first line. */
4775 XSETINT (arg
, XINT (arg
) + 1);
4777 return Fvertical_motion (arg
, window
);
4782 /***********************************************************************
4783 Window Configuration
4784 ***********************************************************************/
4786 struct save_window_data
4788 EMACS_INT size_from_Lisp_Vector_struct
;
4789 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
4790 Lisp_Object frame_width
, frame_height
, frame_menu_bar_lines
;
4791 Lisp_Object frame_tool_bar_lines
;
4792 Lisp_Object selected_frame
;
4793 Lisp_Object current_window
;
4794 Lisp_Object current_buffer
;
4795 Lisp_Object minibuf_scroll_window
;
4796 Lisp_Object root_window
;
4797 Lisp_Object focus_frame
;
4798 /* Record the values of window-min-width and window-min-height
4799 so that window sizes remain consistent with them. */
4800 Lisp_Object min_width
, min_height
;
4801 /* A vector, each of whose elements is a struct saved_window
4803 Lisp_Object saved_windows
;
4806 /* This is saved as a Lisp_Vector */
4809 /* these first two must agree with struct Lisp_Vector in lisp.h */
4810 EMACS_INT size_from_Lisp_Vector_struct
;
4811 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
4814 Lisp_Object buffer
, start
, pointm
, mark
;
4815 Lisp_Object left
, top
, width
, height
, hscroll
, min_hscroll
;
4816 Lisp_Object parent
, prev
;
4817 Lisp_Object start_at_line_beg
;
4818 Lisp_Object display_table
;
4819 Lisp_Object orig_top
, orig_height
;
4822 #define SAVED_WINDOW_VECTOR_SIZE 17 /* Arg to Fmake_vector */
4824 #define SAVED_WINDOW_N(swv,n) \
4825 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
4827 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
4828 doc
: /* Return t if OBJECT is a window-configuration object. */)
4832 if (WINDOW_CONFIGURATIONP (object
))
4837 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
4838 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
4842 register struct save_window_data
*data
;
4843 struct Lisp_Vector
*saved_windows
;
4845 if (! WINDOW_CONFIGURATIONP (config
))
4846 wrong_type_argument (Qwindow_configuration_p
, config
);
4848 data
= (struct save_window_data
*) XVECTOR (config
);
4849 saved_windows
= XVECTOR (data
->saved_windows
);
4850 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
4853 DEFUN ("set-window-configuration", Fset_window_configuration
,
4854 Sset_window_configuration
, 1, 1, 0,
4855 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
4856 CONFIGURATION must be a value previously returned
4857 by `current-window-configuration' (which see).
4858 If CONFIGURATION was made from a frame that is now deleted,
4859 only frame-independent values can be restored. In this case,
4860 the return value is nil. Otherwise the value is t. */)
4862 Lisp_Object configuration
;
4864 register struct save_window_data
*data
;
4865 struct Lisp_Vector
*saved_windows
;
4866 Lisp_Object new_current_buffer
;
4871 while (!WINDOW_CONFIGURATIONP (configuration
))
4872 wrong_type_argument (Qwindow_configuration_p
, configuration
);
4874 data
= (struct save_window_data
*) XVECTOR (configuration
);
4875 saved_windows
= XVECTOR (data
->saved_windows
);
4877 new_current_buffer
= data
->current_buffer
;
4878 if (NILP (XBUFFER (new_current_buffer
)->name
))
4879 new_current_buffer
= Qnil
;
4882 if (XBUFFER (new_current_buffer
) == current_buffer
)
4886 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
4889 /* If f is a dead frame, don't bother rebuilding its window tree.
4890 However, there is other stuff we should still try to do below. */
4891 if (FRAME_LIVE_P (f
))
4893 register struct window
*w
;
4894 register struct saved_window
*p
;
4895 struct window
*root_window
;
4896 struct window
**leaf_windows
;
4900 /* If the frame has been resized since this window configuration was
4901 made, we change the frame to the size specified in the
4902 configuration, restore the configuration, and then resize it
4903 back. We keep track of the prevailing height in these variables. */
4904 int previous_frame_height
= FRAME_HEIGHT (f
);
4905 int previous_frame_width
= FRAME_WIDTH (f
);
4906 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
4907 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
4909 /* The mouse highlighting code could get screwed up
4910 if it runs during this. */
4913 if (XFASTINT (data
->frame_height
) != previous_frame_height
4914 || XFASTINT (data
->frame_width
) != previous_frame_width
)
4915 change_frame_size (f
, XFASTINT (data
->frame_height
),
4916 XFASTINT (data
->frame_width
), 0, 0, 0);
4917 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
4918 if (XFASTINT (data
->frame_menu_bar_lines
)
4919 != previous_frame_menu_bar_lines
)
4920 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, make_number (0));
4921 #ifdef HAVE_WINDOW_SYSTEM
4922 if (XFASTINT (data
->frame_tool_bar_lines
)
4923 != previous_frame_tool_bar_lines
)
4924 x_set_tool_bar_lines (f
, data
->frame_tool_bar_lines
, make_number (0));
4928 /* "Swap out" point from the selected window
4929 into its buffer. We do this now, before
4930 restoring the window contents, and prevent it from
4931 being done later on when we select a new window. */
4932 if (! NILP (XWINDOW (selected_window
)->buffer
))
4934 w
= XWINDOW (selected_window
);
4935 set_marker_both (w
->pointm
,
4937 BUF_PT (XBUFFER (w
->buffer
)),
4938 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
4941 windows_or_buffers_changed
++;
4942 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4944 /* Problem: Freeing all matrices and later allocating them again
4945 is a serious redisplay flickering problem. What we would
4946 really like to do is to free only those matrices not reused
4948 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4950 = (struct window
**) alloca (count_windows (root_window
)
4951 * sizeof (struct window
*));
4952 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
4954 /* Temporarily avoid any problems with windows that are smaller
4955 than they are supposed to be. */
4956 window_min_height
= 1;
4957 window_min_width
= 1;
4960 Mark all windows now on frame as "deleted".
4961 Restoring the new configuration "undeletes" any that are in it.
4963 Save their current buffers in their height fields, since we may
4964 need it later, if a buffer saved in the configuration is now
4966 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4968 for (k
= 0; k
< saved_windows
->size
; k
++)
4970 p
= SAVED_WINDOW_N (saved_windows
, k
);
4971 w
= XWINDOW (p
->window
);
4974 if (!NILP (p
->parent
))
4975 w
->parent
= SAVED_WINDOW_N (saved_windows
,
4976 XFASTINT (p
->parent
))->window
;
4980 if (!NILP (p
->prev
))
4982 w
->prev
= SAVED_WINDOW_N (saved_windows
,
4983 XFASTINT (p
->prev
))->window
;
4984 XWINDOW (w
->prev
)->next
= p
->window
;
4989 if (!NILP (w
->parent
))
4991 if (EQ (p
->width
, XWINDOW (w
->parent
)->width
))
4993 XWINDOW (w
->parent
)->vchild
= p
->window
;
4994 XWINDOW (w
->parent
)->hchild
= Qnil
;
4998 XWINDOW (w
->parent
)->hchild
= p
->window
;
4999 XWINDOW (w
->parent
)->vchild
= Qnil
;
5004 /* If we squirreled away the buffer in the window's height,
5006 if (BUFFERP (w
->height
))
5007 w
->buffer
= w
->height
;
5010 w
->width
= p
->width
;
5011 w
->height
= p
->height
;
5012 w
->hscroll
= p
->hscroll
;
5013 w
->min_hscroll
= p
->min_hscroll
;
5014 w
->display_table
= p
->display_table
;
5015 w
->orig_top
= p
->orig_top
;
5016 w
->orig_height
= p
->orig_height
;
5017 XSETFASTINT (w
->last_modified
, 0);
5018 XSETFASTINT (w
->last_overlay_modified
, 0);
5020 /* Reinstall the saved buffer and pointers into it. */
5021 if (NILP (p
->buffer
))
5022 w
->buffer
= p
->buffer
;
5025 if (!NILP (XBUFFER (p
->buffer
)->name
))
5026 /* If saved buffer is alive, install it. */
5028 w
->buffer
= p
->buffer
;
5029 w
->start_at_line_beg
= p
->start_at_line_beg
;
5030 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
5031 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
5032 Fset_marker (XBUFFER (w
->buffer
)->mark
,
5033 p
->mark
, w
->buffer
);
5035 /* As documented in Fcurrent_window_configuration, don't
5036 save the location of point in the buffer which was current
5037 when the window configuration was recorded. */
5038 if (!EQ (p
->buffer
, new_current_buffer
)
5039 && XBUFFER (p
->buffer
) == current_buffer
)
5040 Fgoto_char (w
->pointm
);
5042 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
5043 /* Else unless window has a live buffer, get one. */
5045 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
5046 /* This will set the markers to beginning of visible
5048 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
5049 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
5050 w
->start_at_line_beg
= Qt
;
5053 /* Keeping window's old buffer; make sure the markers
5056 /* Set window markers at start of visible range. */
5057 if (XMARKER (w
->start
)->buffer
== 0)
5058 set_marker_restricted (w
->start
, make_number (0),
5060 if (XMARKER (w
->pointm
)->buffer
== 0)
5061 set_marker_restricted_both (w
->pointm
, w
->buffer
,
5062 BUF_PT (XBUFFER (w
->buffer
)),
5063 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5064 w
->start_at_line_beg
= Qt
;
5069 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
5070 /* Prevent "swapping out point" in the old selected window
5071 using the buffer that has been restored into it.
5072 That swapping out has already been done,
5073 near the beginning of this function. */
5074 selected_window
= Qnil
;
5075 Fselect_window (data
->current_window
);
5076 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
5079 if (NILP (data
->focus_frame
)
5080 || (FRAMEP (data
->focus_frame
)
5081 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
5082 Fredirect_frame_focus (frame
, data
->focus_frame
);
5084 #if 0 /* I don't understand why this is needed, and it causes problems
5085 when the frame's old selected window has been deleted. */
5086 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
5087 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
5091 /* Set the screen height to the value it had before this function. */
5092 if (previous_frame_height
!= FRAME_HEIGHT (f
)
5093 || previous_frame_width
!= FRAME_WIDTH (f
))
5094 change_frame_size (f
, previous_frame_height
, previous_frame_width
,
5096 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5097 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
5098 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
5100 #ifdef HAVE_WINDOW_SYSTEM
5101 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
5102 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
5107 /* Now, free glyph matrices in windows that were not reused. */
5108 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
5110 if (NILP (leaf_windows
[i
]->buffer
))
5112 /* Assert it's not reused as a combination. */
5113 xassert (NILP (leaf_windows
[i
]->hchild
)
5114 && NILP (leaf_windows
[i
]->vchild
));
5115 free_window_matrices (leaf_windows
[i
]);
5117 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
5121 /* If more than one window shows the new and old current buffer,
5122 don't try to preserve point in that buffer. */
5123 if (old_point
> 0 && n
> 1)
5130 /* Fselect_window will have made f the selected frame, so we
5131 reselect the proper frame here. Fhandle_switch_frame will change the
5132 selected window too, but that doesn't make the call to
5133 Fselect_window above totally superfluous; it still sets f's
5135 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
5136 do_switch_frame (data
->selected_frame
, 0, 0);
5138 if (! NILP (Vwindow_configuration_change_hook
)
5139 && ! NILP (Vrun_hooks
))
5140 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
5143 if (!NILP (new_current_buffer
))
5145 Fset_buffer (new_current_buffer
);
5147 /* If the buffer that is current now is the same
5148 that was current before setting the window configuration,
5149 don't alter its PT. */
5154 /* Restore the minimum heights recorded in the configuration. */
5155 window_min_height
= XINT (data
->min_height
);
5156 window_min_width
= XINT (data
->min_width
);
5158 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
5160 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
5163 /* Mark all windows now on frame as deleted
5164 by setting their buffers to nil. */
5167 delete_all_subwindows (w
)
5168 register struct window
*w
;
5170 if (!NILP (w
->next
))
5171 delete_all_subwindows (XWINDOW (w
->next
));
5172 if (!NILP (w
->vchild
))
5173 delete_all_subwindows (XWINDOW (w
->vchild
));
5174 if (!NILP (w
->hchild
))
5175 delete_all_subwindows (XWINDOW (w
->hchild
));
5177 w
->height
= w
->buffer
; /* See Fset_window_configuration for excuse. */
5179 if (!NILP (w
->buffer
))
5182 /* We set all three of these fields to nil, to make sure that we can
5183 distinguish this dead window from any live window. Live leaf
5184 windows will have buffer set, and combination windows will have
5185 vchild or hchild set. */
5190 Vwindow_list
= Qnil
;
5194 count_windows (window
)
5195 register struct window
*window
;
5197 register int count
= 1;
5198 if (!NILP (window
->next
))
5199 count
+= count_windows (XWINDOW (window
->next
));
5200 if (!NILP (window
->vchild
))
5201 count
+= count_windows (XWINDOW (window
->vchild
));
5202 if (!NILP (window
->hchild
))
5203 count
+= count_windows (XWINDOW (window
->hchild
));
5208 /* Fill vector FLAT with leaf windows under W, starting at index I.
5209 Value is last index + 1. */
5212 get_leaf_windows (w
, flat
, i
)
5214 struct window
**flat
;
5219 if (!NILP (w
->hchild
))
5220 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
5221 else if (!NILP (w
->vchild
))
5222 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
5226 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5233 /* Return a pointer to the glyph W's physical cursor is on. Value is
5234 null if W's current matrix is invalid, so that no meaningfull glyph
5238 get_phys_cursor_glyph (w
)
5241 struct glyph_row
*row
;
5242 struct glyph
*glyph
;
5244 if (w
->phys_cursor
.vpos
>= 0
5245 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
5246 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
5248 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
5249 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
5258 save_window_save (window
, vector
, i
)
5260 struct Lisp_Vector
*vector
;
5263 register struct saved_window
*p
;
5264 register struct window
*w
;
5265 register Lisp_Object tem
;
5267 for (;!NILP (window
); window
= w
->next
)
5269 p
= SAVED_WINDOW_N (vector
, i
);
5270 w
= XWINDOW (window
);
5272 XSETFASTINT (w
->temslot
, i
++);
5274 p
->buffer
= w
->buffer
;
5277 p
->width
= w
->width
;
5278 p
->height
= w
->height
;
5279 p
->hscroll
= w
->hscroll
;
5280 p
->min_hscroll
= w
->min_hscroll
;
5281 p
->display_table
= w
->display_table
;
5282 p
->orig_top
= w
->orig_top
;
5283 p
->orig_height
= w
->orig_height
;
5284 if (!NILP (w
->buffer
))
5286 /* Save w's value of point in the window configuration.
5287 If w is the selected window, then get the value of point
5288 from the buffer; pointm is garbage in the selected window. */
5289 if (EQ (window
, selected_window
))
5291 p
->pointm
= Fmake_marker ();
5292 set_marker_both (p
->pointm
, w
->buffer
,
5293 BUF_PT (XBUFFER (w
->buffer
)),
5294 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5297 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
5299 p
->start
= Fcopy_marker (w
->start
, Qnil
);
5300 p
->start_at_line_beg
= w
->start_at_line_beg
;
5302 tem
= XBUFFER (w
->buffer
)->mark
;
5303 p
->mark
= Fcopy_marker (tem
, Qnil
);
5310 p
->start_at_line_beg
= Qnil
;
5313 if (NILP (w
->parent
))
5316 p
->parent
= XWINDOW (w
->parent
)->temslot
;
5321 p
->prev
= XWINDOW (w
->prev
)->temslot
;
5323 if (!NILP (w
->vchild
))
5324 i
= save_window_save (w
->vchild
, vector
, i
);
5325 if (!NILP (w
->hchild
))
5326 i
= save_window_save (w
->hchild
, vector
, i
);
5332 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
5333 Scurrent_window_configuration
, 0, 1, 0,
5334 doc
: /* Return an object representing the current window configuration of FRAME.
5335 If FRAME is nil or omitted, use the selected frame.
5336 This describes the number of windows, their sizes and current buffers,
5337 and for each displayed buffer, where display starts, and the positions of
5338 point and mark. An exception is made for point in the current buffer:
5339 its value is -not- saved.
5340 This also records the currently selected frame, and FRAME's focus
5341 redirection (see `redirect-frame-focus'). */)
5345 register Lisp_Object tem
;
5346 register int n_windows
;
5347 register struct save_window_data
*data
;
5348 register struct Lisp_Vector
*vec
;
5353 frame
= selected_frame
;
5354 CHECK_LIVE_FRAME (frame
);
5357 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5358 vec
= allocate_other_vector (VECSIZE (struct save_window_data
));
5359 data
= (struct save_window_data
*)vec
;
5361 XSETFASTINT (data
->frame_width
, FRAME_WIDTH (f
));
5362 XSETFASTINT (data
->frame_height
, FRAME_HEIGHT (f
));
5363 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
5364 XSETFASTINT (data
->frame_tool_bar_lines
, FRAME_TOOL_BAR_LINES (f
));
5365 data
->selected_frame
= selected_frame
;
5366 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
5367 XSETBUFFER (data
->current_buffer
, current_buffer
);
5368 data
->minibuf_scroll_window
= Vminibuf_scroll_window
;
5369 data
->root_window
= FRAME_ROOT_WINDOW (f
);
5370 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
5371 XSETINT (data
->min_height
, window_min_height
);
5372 XSETINT (data
->min_width
, window_min_width
);
5373 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
5374 data
->saved_windows
= tem
;
5375 for (i
= 0; i
< n_windows
; i
++)
5376 XVECTOR (tem
)->contents
[i
]
5377 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
5378 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
5379 XSETWINDOW_CONFIGURATION (tem
, data
);
5383 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
5385 doc
: /* Execute body, preserving window sizes and contents.
5386 Restore which buffer appears in which window, where display starts,
5387 and the value of point and mark for each window.
5388 Also restore the choice of selected window.
5389 Also restore which buffer is current.
5390 Does not restore the value of point in current buffer.
5391 usage: (save-window-excursion BODY ...) */)
5395 register Lisp_Object val
;
5396 register int count
= specpdl_ptr
- specpdl
;
5398 record_unwind_protect (Fset_window_configuration
,
5399 Fcurrent_window_configuration (Qnil
));
5400 val
= Fprogn (args
);
5401 return unbind_to (count
, val
);
5405 /***********************************************************************
5407 ***********************************************************************/
5409 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
5411 doc
: /* Set width of marginal areas of window WINDOW.
5412 If window is nil, set margins of the currently selected window.
5413 First parameter LEFT-WIDTH specifies the number of character
5414 cells to reserve for the left marginal area. Second parameter
5415 RIGHT-WIDTH does the same for the right marginal area.
5416 A nil width parameter means no margin. */)
5417 (window
, left
, right
)
5418 Lisp_Object window
, left
, right
;
5420 struct window
*w
= decode_window (window
);
5423 CHECK_NUMBER_OR_FLOAT (left
);
5425 CHECK_NUMBER_OR_FLOAT (right
);
5427 /* Check widths < 0 and translate a zero width to nil.
5428 Margins that are too wide have to be checked elsewhere. */
5429 if ((INTEGERP (left
) && XINT (left
) < 0)
5430 || (FLOATP (left
) && XFLOAT_DATA (left
) <= 0))
5431 XSETFASTINT (left
, 0);
5432 if (INTEGERP (left
) && XFASTINT (left
) == 0)
5435 if ((INTEGERP (right
) && XINT (right
) < 0)
5436 || (FLOATP (right
) && XFLOAT_DATA (right
) <= 0))
5437 XSETFASTINT (right
, 0);
5438 if (INTEGERP (right
) && XFASTINT (right
) == 0)
5441 w
->left_margin_width
= left
;
5442 w
->right_margin_width
= right
;
5444 ++windows_or_buffers_changed
;
5445 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
5450 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
5452 doc
: /* Get width of marginal areas of window WINDOW.
5453 If WINDOW is omitted or nil, use the currently selected window.
5454 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
5455 If a marginal area does not exist, its width will be returned
5460 struct window
*w
= decode_window (window
);
5461 return Fcons (w
->left_margin_width
, w
->right_margin_width
);
5466 /***********************************************************************
5468 ***********************************************************************/
5470 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 1, 0,
5471 doc
: /* Return the amount by which WINDOW is scrolled vertically.
5472 Use the selected window if WINDOW is nil or omitted.
5473 Value is a multiple of the canonical character height of WINDOW. */)
5482 window
= selected_window
;
5484 CHECK_WINDOW (window
);
5485 w
= XWINDOW (window
);
5486 f
= XFRAME (w
->frame
);
5488 if (FRAME_WINDOW_P (f
))
5489 result
= CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
);
5491 result
= make_number (0);
5496 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
5498 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
5499 WINDOW nil means use the selected window. VSCROLL is a non-negative
5500 multiple of the canonical character height of WINDOW. */)
5502 Lisp_Object window
, vscroll
;
5508 window
= selected_window
;
5510 CHECK_WINDOW (window
);
5511 CHECK_NUMBER_OR_FLOAT (vscroll
);
5513 w
= XWINDOW (window
);
5514 f
= XFRAME (w
->frame
);
5516 if (FRAME_WINDOW_P (f
))
5518 int old_dy
= w
->vscroll
;
5520 w
->vscroll
= - CANON_Y_UNIT (f
) * XFLOATINT (vscroll
);
5521 w
->vscroll
= min (w
->vscroll
, 0);
5523 /* Adjust glyph matrix of the frame if the virtual display
5524 area becomes larger than before. */
5525 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
5528 /* Prevent redisplay shortcuts. */
5529 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
5532 return Fwindow_vscroll (window
);
5536 /* Call FN for all leaf windows on frame F. FN is called with the
5537 first argument being a pointer to the leaf window, and with
5538 additional argument USER_DATA. Stops when FN returns 0. */
5541 foreach_window (f
, fn
, user_data
)
5543 int (* fn
) P_ ((struct window
*, void *));
5546 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
5550 /* Helper function for foreach_window. Call FN for all leaf windows
5551 reachable from W. FN is called with the first argument being a
5552 pointer to the leaf window, and with additional argument USER_DATA.
5553 Stop when FN returns 0. Value is 0 if stopped by FN. */
5556 foreach_window_1 (w
, fn
, user_data
)
5558 int (* fn
) P_ ((struct window
*, void *));
5563 for (cont
= 1; w
&& cont
;)
5565 if (!NILP (w
->hchild
))
5566 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
5567 else if (!NILP (w
->vchild
))
5568 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
5570 cont
= fn (w
, user_data
);
5572 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5579 /* Freeze or unfreeze the window start of W unless it is a
5580 mini-window or the selected window. FREEZE_P non-null means freeze
5581 the window start. */
5584 freeze_window_start (w
, freeze_p
)
5588 if (w
== XWINDOW (selected_window
)
5589 || MINI_WINDOW_P (w
)
5590 || (MINI_WINDOW_P (XWINDOW (selected_window
))
5591 && ! NILP (Vminibuf_scroll_window
)
5592 && w
== XWINDOW (Vminibuf_scroll_window
)))
5595 w
->frozen_window_start_p
= freeze_p
!= NULL
;
5600 /* Freeze or unfreeze the window starts of all leaf windows on frame
5601 F, except the selected window and a mini-window. FREEZE_P non-zero
5602 means freeze the window start. */
5605 freeze_window_starts (f
, freeze_p
)
5609 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
5613 /***********************************************************************
5615 ***********************************************************************/
5617 /* Return 1 if window configurations C1 and C2
5618 describe the same state of affairs. This is used by Fequal. */
5621 compare_window_configurations (c1
, c2
, ignore_positions
)
5623 int ignore_positions
;
5625 register struct save_window_data
*d1
, *d2
;
5626 struct Lisp_Vector
*sw1
, *sw2
;
5629 if (!WINDOW_CONFIGURATIONP (c1
))
5630 wrong_type_argument (Qwindow_configuration_p
, c1
);
5631 if (!WINDOW_CONFIGURATIONP (c2
))
5632 wrong_type_argument (Qwindow_configuration_p
, c2
);
5634 d1
= (struct save_window_data
*) XVECTOR (c1
);
5635 d2
= (struct save_window_data
*) XVECTOR (c2
);
5636 sw1
= XVECTOR (d1
->saved_windows
);
5637 sw2
= XVECTOR (d2
->saved_windows
);
5639 if (! EQ (d1
->frame_width
, d2
->frame_width
))
5641 if (! EQ (d1
->frame_height
, d2
->frame_height
))
5643 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
5645 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
5647 /* Don't compare the current_window field directly.
5648 Instead see w1_is_current and w2_is_current, below. */
5649 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
5651 if (! ignore_positions
)
5652 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
5654 /* Don't compare the root_window field.
5655 We don't require the two configurations
5656 to use the same window object,
5657 and the two root windows must be equivalent
5658 if everything else compares equal. */
5659 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
5661 if (! EQ (d1
->min_width
, d2
->min_width
))
5663 if (! EQ (d1
->min_height
, d2
->min_height
))
5666 /* Verify that the two confis have the same number of windows. */
5667 if (sw1
->size
!= sw2
->size
)
5670 for (i
= 0; i
< sw1
->size
; i
++)
5672 struct saved_window
*p1
, *p2
;
5673 int w1_is_current
, w2_is_current
;
5675 p1
= SAVED_WINDOW_N (sw1
, i
);
5676 p2
= SAVED_WINDOW_N (sw2
, i
);
5678 /* Verify that the current windows in the two
5679 configurations correspond to each other. */
5680 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
5681 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
5683 if (w1_is_current
!= w2_is_current
)
5686 /* Verify that the corresponding windows do match. */
5687 if (! EQ (p1
->buffer
, p2
->buffer
))
5689 if (! EQ (p1
->left
, p2
->left
))
5691 if (! EQ (p1
->top
, p2
->top
))
5693 if (! EQ (p1
->width
, p2
->width
))
5695 if (! EQ (p1
->height
, p2
->height
))
5697 if (! EQ (p1
->display_table
, p2
->display_table
))
5699 if (! EQ (p1
->parent
, p2
->parent
))
5701 if (! EQ (p1
->prev
, p2
->prev
))
5703 if (! ignore_positions
)
5705 if (! EQ (p1
->hscroll
, p2
->hscroll
))
5707 if (!EQ (p1
->min_hscroll
, p2
->min_hscroll
))
5709 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
5711 if (NILP (Fequal (p1
->start
, p2
->start
)))
5713 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
5715 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
5723 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
5724 Scompare_window_configurations
, 2, 2, 0,
5725 doc
: /* Compare two window configurations as regards the structure of windows.
5726 This function ignores details such as the values of point and mark
5727 and scrolling positions. */)
5731 if (compare_window_configurations (x
, y
, 1))
5739 struct frame
*f
= make_terminal_frame ();
5740 XSETFRAME (selected_frame
, f
);
5741 Vterminal_frame
= selected_frame
;
5742 minibuf_window
= f
->minibuffer_window
;
5743 selected_window
= f
->selected_window
;
5744 last_nonminibuf_frame
= f
;
5746 window_initialized
= 1;
5752 Vwindow_list
= Qnil
;
5758 Qwindow_size_fixed
= intern ("window-size-fixed");
5759 staticpro (&Qwindow_size_fixed
);
5761 staticpro (&Qwindow_configuration_change_hook
);
5762 Qwindow_configuration_change_hook
5763 = intern ("window-configuration-change-hook");
5765 Qwindowp
= intern ("windowp");
5766 staticpro (&Qwindowp
);
5768 Qwindow_configuration_p
= intern ("window-configuration-p");
5769 staticpro (&Qwindow_configuration_p
);
5771 Qwindow_live_p
= intern ("window-live-p");
5772 staticpro (&Qwindow_live_p
);
5774 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
5775 staticpro (&Qtemp_buffer_show_hook
);
5777 staticpro (&Vwindow_list
);
5779 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
5780 doc
: /* Non-nil means call as function to display a help buffer.
5781 The function is called with one argument, the buffer to be displayed.
5782 Used by `with-output-to-temp-buffer'.
5783 If this function is used, then it must do the entire job of showing
5784 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
5785 Vtemp_buffer_show_function
= Qnil
;
5787 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
5788 doc
: /* If non-nil, function to call to handle `display-buffer'.
5789 It will receive two args, the buffer and a flag which if non-nil means
5790 that the currently selected window is not acceptable.
5791 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'
5792 work using this function. */);
5793 Vdisplay_buffer_function
= Qnil
;
5795 DEFVAR_LISP ("even-window-heights", &Veven_window_heights
,
5796 doc
: /* *If non-nil, `display-buffer' should even the window heights.
5797 If nil, `display-buffer' will leave the window configuration alone. */);
5798 Veven_window_heights
= Qt
;
5800 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
5801 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
5802 Vminibuf_scroll_window
= Qnil
;
5804 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows
,
5805 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
5806 If the minibuffer is active, the `minibuffer-scroll-window' mode line
5807 is displayed in the `mode-line' face. */);
5808 mode_line_in_non_selected_windows
= 1;
5810 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
5811 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
5812 Vother_window_scroll_buffer
= Qnil
;
5814 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
5815 doc
: /* *Non-nil means `display-buffer' should make a separate frame. */);
5818 DEFVAR_BOOL ("display-buffer-reuse-frames", &display_buffer_reuse_frames
,
5819 doc
: /* *Non-nil means `display-buffer' should reuse frames.
5820 If the buffer in question is already displayed in a frame, raise that frame. */);
5821 display_buffer_reuse_frames
= 0;
5823 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
5824 doc
: /* Function to call to handle automatic new frame creation.
5825 It is called with no arguments and should return a newly created frame.
5827 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'
5828 where `pop-up-frame-alist' would hold the default frame parameters. */);
5829 Vpop_up_frame_function
= Qnil
;
5831 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
5832 doc
: /* *List of buffer names that should have their own special frames.
5833 Displaying a buffer whose name is in this list makes a special frame for it
5834 using `special-display-function'. See also `special-display-regexps'.
5836 An element of the list can be a list instead of just a string.
5837 There are two ways to use a list as an element:
5838 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)
5839 In the first case, FRAME-PARAMETERS are used to create the frame.
5840 In the latter case, FUNCTION is called with BUFFER as the first argument,
5841 followed by OTHER-ARGS--it can display BUFFER in any way it likes.
5842 All this is done by the function found in `special-display-function'.
5844 If this variable appears \"not to work\", because you add a name to it
5845 but that buffer still appears in the selected window, look at the
5846 values of `same-window-buffer-names' and `same-window-regexps'.
5847 Those variables take precedence over this one. */);
5848 Vspecial_display_buffer_names
= Qnil
;
5850 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
5851 doc
: /* *List of regexps saying which buffers should have their own special frames.
5852 If a buffer name matches one of these regexps, it gets its own frame.
5853 Displaying a buffer whose name is in this list makes a special frame for it
5854 using `special-display-function'.
5856 An element of the list can be a list instead of just a string.
5857 There are two ways to use a list as an element:
5858 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)
5859 In the first case, FRAME-PARAMETERS are used to create the frame.
5860 In the latter case, FUNCTION is called with the buffer as first argument,
5861 followed by OTHER-ARGS--it can display the buffer in any way it likes.
5862 All this is done by the function found in `special-display-function'.
5864 If this variable appears \"not to work\", because you add a regexp to it
5865 but the matching buffers still appear in the selected window, look at the
5866 values of `same-window-buffer-names' and `same-window-regexps'.
5867 Those variables take precedence over this one. */);
5868 Vspecial_display_regexps
= Qnil
;
5870 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
5871 doc
: /* Function to call to make a new frame for a special buffer.
5872 It is called with two arguments, the buffer and optional buffer specific
5873 data, and should return a window displaying that buffer.
5874 The default value makes a separate frame for the buffer,
5875 using `special-display-frame-alist' to specify the frame parameters.
5877 A buffer is special if its is listed in `special-display-buffer-names'
5878 or matches a regexp in `special-display-regexps'. */);
5879 Vspecial_display_function
= Qnil
;
5881 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
5882 doc
: /* *List of buffer names that should appear in the selected window.
5883 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'
5884 switches to it in the selected window, rather than making it appear
5885 in some other window.
5887 An element of the list can be a cons cell instead of just a string.
5888 Then the car must be a string, which specifies the buffer name.
5889 This is for compatibility with `special-display-buffer-names';
5890 the cdr of the cons cell is ignored.
5892 See also `same-window-regexps'. */);
5893 Vsame_window_buffer_names
= Qnil
;
5895 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
5896 doc
: /* *List of regexps saying which buffers should appear in the selected window.
5897 If a buffer name matches one of these regexps, then displaying it
5898 using `display-buffer' or `pop-to-buffer' switches to it
5899 in the selected window, rather than making it appear in some other window.
5901 An element of the list can be a cons cell instead of just a string.
5902 Then the car must be a string, which specifies the buffer name.
5903 This is for compatibility with `special-display-buffer-names';
5904 the cdr of the cons cell is ignored.
5906 See also `same-window-buffer-names'. */);
5907 Vsame_window_regexps
= Qnil
;
5909 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
5910 doc
: /* *Non-nil means display-buffer should make new windows. */);
5913 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
5914 doc
: /* *Number of lines of continuity when scrolling by screenfuls. */);
5915 next_screen_context_lines
= 2;
5917 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
5918 doc
: /* *display-buffer would prefer to split the largest window if this large.
5919 If there is only one window, it is split regardless of this value. */);
5920 split_height_threshold
= 500;
5922 DEFVAR_INT ("window-min-height", &window_min_height
,
5923 doc
: /* *Delete any window less than this tall (including its mode line). */);
5924 window_min_height
= 4;
5926 DEFVAR_INT ("window-min-width", &window_min_width
,
5927 doc
: /* *Delete any window less than this wide. */);
5928 window_min_width
= 10;
5930 DEFVAR_LISP ("scroll-preserve-screen-position",
5931 &Vscroll_preserve_screen_position
,
5932 doc
: /* *Non-nil means scroll commands move point to keep its screen line unchanged. */);
5933 Vscroll_preserve_screen_position
= Qnil
;
5935 DEFVAR_LISP ("window-configuration-change-hook",
5936 &Vwindow_configuration_change_hook
,
5937 doc
: /* Functions to call when window configuration changes.
5938 The selected frame is the one whose configuration has changed. */);
5939 Vwindow_configuration_change_hook
= Qnil
;
5941 DEFVAR_BOOL ("window-size-fixed", &window_size_fixed
,
5942 doc
: /* Non-nil in a buffer means windows displaying the buffer are fixed-size.
5943 Emacs won't change the size of any window displaying that buffer,
5944 unless you explicitly change the size, or Emacs has no other choice.
5945 This variable automatically becomes buffer-local when set. */);
5946 Fmake_variable_buffer_local (Qwindow_size_fixed
);
5947 window_size_fixed
= 0;
5949 defsubr (&Sselected_window
);
5950 defsubr (&Sminibuffer_window
);
5951 defsubr (&Swindow_minibuffer_p
);
5952 defsubr (&Swindowp
);
5953 defsubr (&Swindow_live_p
);
5954 defsubr (&Spos_visible_in_window_p
);
5955 defsubr (&Swindow_buffer
);
5956 defsubr (&Swindow_height
);
5957 defsubr (&Swindow_width
);
5958 defsubr (&Swindow_hscroll
);
5959 defsubr (&Sset_window_hscroll
);
5960 defsubr (&Swindow_redisplay_end_trigger
);
5961 defsubr (&Sset_window_redisplay_end_trigger
);
5962 defsubr (&Swindow_edges
);
5963 defsubr (&Scoordinates_in_window_p
);
5964 defsubr (&Swindow_at
);
5965 defsubr (&Swindow_point
);
5966 defsubr (&Swindow_start
);
5967 defsubr (&Swindow_end
);
5968 defsubr (&Sset_window_point
);
5969 defsubr (&Sset_window_start
);
5970 defsubr (&Swindow_dedicated_p
);
5971 defsubr (&Sset_window_dedicated_p
);
5972 defsubr (&Swindow_display_table
);
5973 defsubr (&Sset_window_display_table
);
5974 defsubr (&Snext_window
);
5975 defsubr (&Sprevious_window
);
5976 defsubr (&Sother_window
);
5977 defsubr (&Sget_lru_window
);
5978 defsubr (&Sget_largest_window
);
5979 defsubr (&Sget_buffer_window
);
5980 defsubr (&Sdelete_other_windows
);
5981 defsubr (&Sdelete_windows_on
);
5982 defsubr (&Sreplace_buffer_in_windows
);
5983 defsubr (&Sdelete_window
);
5984 defsubr (&Sset_window_buffer
);
5985 defsubr (&Sselect_window
);
5986 defsubr (&Sspecial_display_p
);
5987 defsubr (&Ssame_window_p
);
5988 defsubr (&Sdisplay_buffer
);
5989 defsubr (&Ssplit_window
);
5990 defsubr (&Senlarge_window
);
5991 defsubr (&Sshrink_window
);
5992 defsubr (&Sscroll_up
);
5993 defsubr (&Sscroll_down
);
5994 defsubr (&Sscroll_left
);
5995 defsubr (&Sscroll_right
);
5996 defsubr (&Sother_window_for_scrolling
);
5997 defsubr (&Sscroll_other_window
);
5998 defsubr (&Srecenter
);
5999 defsubr (&Swindow_text_height
);
6000 defsubr (&Smove_to_window_line
);
6001 defsubr (&Swindow_configuration_p
);
6002 defsubr (&Swindow_configuration_frame
);
6003 defsubr (&Sset_window_configuration
);
6004 defsubr (&Scurrent_window_configuration
);
6005 defsubr (&Ssave_window_excursion
);
6006 defsubr (&Sset_window_margins
);
6007 defsubr (&Swindow_margins
);
6008 defsubr (&Swindow_vscroll
);
6009 defsubr (&Sset_window_vscroll
);
6010 defsubr (&Scompare_window_configurations
);
6011 defsubr (&Swindow_list
);
6017 initial_define_key (control_x_map
, '1', "delete-other-windows");
6018 initial_define_key (control_x_map
, '2', "split-window");
6019 initial_define_key (control_x_map
, '0', "delete-window");
6020 initial_define_key (control_x_map
, 'o', "other-window");
6021 initial_define_key (control_x_map
, '^', "enlarge-window");
6022 initial_define_key (control_x_map
, '<', "scroll-left");
6023 initial_define_key (control_x_map
, '>', "scroll-right");
6025 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
6026 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
6027 initial_define_key (meta_map
, 'v', "scroll-down");
6029 initial_define_key (global_map
, Ctl('L'), "recenter");
6030 initial_define_key (meta_map
, 'r', "move-to-window-line");