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. */
33 #include "dispextern.h"
34 #include "blockinput.h"
35 #include "intervals.h"
39 #endif /* HAVE_X_WINDOWS */
51 #define max(a, b) ((a) < (b) ? (b) : (a))
54 /* Values returned from coordinates_in_window. */
68 Lisp_Object Qwindowp
, Qwindow_live_p
, Qwindow_configuration_p
;
69 Lisp_Object Qwindow_size_fixed
, Qleft_fringe
, Qright_fringe
;
70 extern Lisp_Object Qheight
, Qwidth
;
72 static int displayed_window_lines
P_ ((struct window
*));
73 static struct window
*decode_window
P_ ((Lisp_Object
));
74 static Lisp_Object select_window_1
P_ ((Lisp_Object
, int));
75 static int count_windows
P_ ((struct window
*));
76 static int get_leaf_windows
P_ ((struct window
*, struct window
**, int));
77 static void window_scroll
P_ ((Lisp_Object
, int, int, int));
78 static void window_scroll_pixel_based
P_ ((Lisp_Object
, int, int, int));
79 static void window_scroll_line_based
P_ ((Lisp_Object
, int, int, int));
80 static int window_min_size_1
P_ ((struct window
*, int));
81 static int window_min_size
P_ ((struct window
*, int, int, int *));
82 static void size_window
P_ ((Lisp_Object
, int, int, int));
83 static int freeze_window_start
P_ ((struct window
*, void *));
84 static int window_fixed_size_p
P_ ((struct window
*, int, int));
85 static void enlarge_window
P_ ((Lisp_Object
, int, int));
86 static Lisp_Object window_list
P_ ((void));
87 static int add_window_to_list
P_ ((struct window
*, void *));
88 static int candidate_window_p
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
90 static Lisp_Object next_window
P_ ((Lisp_Object
, Lisp_Object
,
92 static void decode_next_window_args
P_ ((Lisp_Object
*, Lisp_Object
*,
94 static int foreach_window_1
P_ ((struct window
*,
95 int (* fn
) (struct window
*, void *),
97 static Lisp_Object window_list_1
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
99 /* The value of `window-size-fixed'. */
101 int window_size_fixed
;
103 /* This is the window in which the terminal's cursor should
104 be left when nothing is being done with it. This must
105 always be a leaf window, and its buffer is selected by
106 the top level editing loop at the end of each command.
108 This value is always the same as
109 FRAME_SELECTED_WINDOW (selected_frame). */
111 Lisp_Object selected_window
;
113 /* A list of all windows for use by next_window and Fwindow_list.
114 Functions creating or deleting windows should invalidate this cache
115 by setting it to nil. */
117 Lisp_Object Vwindow_list
;
119 /* The mini-buffer window of the selected frame.
120 Note that you cannot test for mini-bufferness of an arbitrary window
121 by comparing against this; but you can test for mini-bufferness of
122 the selected window. */
124 Lisp_Object minibuf_window
;
126 /* Non-nil means it is the window for C-M-v to scroll
127 when the mini-buffer is selected. */
129 Lisp_Object Vminibuf_scroll_window
;
131 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
133 Lisp_Object Vother_window_scroll_buffer
;
135 /* Non-nil means it's function to call to display temp buffers. */
137 Lisp_Object Vtemp_buffer_show_function
;
139 /* If a window gets smaller than either of these, it is removed. */
141 int window_min_height
;
142 int window_min_width
;
144 /* Nonzero implies Fdisplay_buffer should create windows. */
148 /* Nonzero implies make new frames for Fdisplay_buffer. */
152 /* Nonzero means reuse existing frames for displaying buffers. */
154 int display_buffer_reuse_frames
;
156 /* Non-nil means use this function instead of default */
158 Lisp_Object Vpop_up_frame_function
;
160 /* Function to call to handle Fdisplay_buffer. */
162 Lisp_Object Vdisplay_buffer_function
;
164 /* Non-nil means that Fdisplay_buffer should even the heights of windows. */
166 Lisp_Object Veven_window_heights
;
168 /* List of buffer *names* for buffers that should have their own frames. */
170 Lisp_Object Vspecial_display_buffer_names
;
172 /* List of regexps for buffer names that should have their own frames. */
174 Lisp_Object Vspecial_display_regexps
;
176 /* Function to pop up a special frame. */
178 Lisp_Object Vspecial_display_function
;
180 /* List of buffer *names* for buffers to appear in selected window. */
182 Lisp_Object Vsame_window_buffer_names
;
184 /* List of regexps for buffer names to appear in selected window. */
186 Lisp_Object Vsame_window_regexps
;
188 /* Hook run at end of temp_output_buffer_show. */
190 Lisp_Object Qtemp_buffer_show_hook
;
192 /* Fdisplay_buffer always splits the largest window
193 if that window is more than this high. */
195 int split_height_threshold
;
197 /* Number of lines of continuity in scrolling by screenfuls. */
199 int next_screen_context_lines
;
201 /* Incremented for each window created. */
203 static int sequence_number
;
205 /* Nonzero after init_window_once has finished. */
207 static int window_initialized
;
209 /* Hook to run when window config changes. */
211 Lisp_Object Qwindow_configuration_change_hook
;
212 Lisp_Object Vwindow_configuration_change_hook
;
214 /* Nonzero means scroll commands try to put point
215 at the same screen height as previously. */
217 Lisp_Object Vscroll_preserve_screen_position
;
219 #if 0 /* This isn't used anywhere. */
220 /* Nonzero means we can split a frame even if it is "unsplittable". */
221 static int inhibit_frame_unsplittable
;
224 #define min(a, b) ((a) < (b) ? (a) : (b))
226 extern int scroll_margin
;
228 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
230 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
231 "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 "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 "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 "Return the window used now for minibuffers.\n\
295 If the optional argument FRAME is specified, return the minibuffer window\n\
296 used by that frame.")
301 frame
= selected_frame
;
302 CHECK_LIVE_FRAME (frame
, 0);
303 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
306 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
307 "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 "Return t if position POS is currently on the frame in WINDOW.\n\
319 Return nil if that position is scrolled vertically out of view.\n\
320 If a character is only partially visible, nil is returned, unless the\n\
321 optional argument PARTIALLY is non-nil.\n\
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
, 0);
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
, 0);
391 return XWINDOW (window
);
394 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
395 "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 "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 "Return the number of display columns in WINDOW.\n\
412 This is the width that is usable columns available for text in WINDOW.\n\
413 If you want to find out how many columns WINDOW takes up,\n\
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 "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 "Set number of columns WINDOW is scrolled from left margin to NCOL.\n\
431 NCOL should be zero or positive.\n\
433 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the\n\
434 window so that the location of point is not visible.")
436 Lisp_Object window
, ncol
;
438 struct window
*w
= decode_window (window
);
441 CHECK_NUMBER (ncol
, 1);
442 hscroll
= max (0, XINT (ncol
));
444 /* Prevent redisplay shortcuts when changing the hscroll. */
445 if (XINT (w
->hscroll
) != hscroll
)
446 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
448 w
->hscroll
= make_number (hscroll
);
452 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
453 Swindow_redisplay_end_trigger
, 0, 1, 0,
454 "Return WINDOW's redisplay end trigger value.\n\
455 See `set-window-redisplay-end-trigger' for more information.")
459 return decode_window (window
)->redisplay_end_trigger
;
462 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
463 Sset_window_redisplay_end_trigger
, 2, 2, 0,
464 "Set WINDOW's redisplay end trigger value to VALUE.\n\
465 VALUE should be a buffer position (typically a marker) or nil.\n\
466 If it is a buffer position, then if redisplay in WINDOW reaches a position\n\
467 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called\n\
468 with two arguments: WINDOW, and the end trigger value.\n\
469 Afterwards the end-trigger value is reset to nil.")
471 register Lisp_Object window
, value
;
473 register struct window
*w
;
475 w
= decode_window (window
);
476 w
->redisplay_end_trigger
= value
;
480 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
481 "Return a list of the edge coordinates of WINDOW.\n\
482 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.\n\
483 RIGHT is one more than the rightmost column used by WINDOW,\n\
484 and BOTTOM is one more than the bottommost row used by WINDOW\n\
489 register struct window
*w
= decode_window (window
);
491 return Fcons (w
->left
, Fcons (w
->top
,
492 Fcons (make_number (WINDOW_RIGHT_EDGE (w
)),
493 Fcons (make_number (XFASTINT (w
->top
)
494 + XFASTINT (w
->height
)),
498 /* Test if the character at column *X, row *Y is within window W.
499 If it is not, return 0;
500 if it is in the window's text area,
501 set *x and *y to its location relative to the upper left corner
504 if it is on the window's modeline, return 2;
505 if it is on the border between the window and its right sibling,
507 if it is on the window's top line, return 4;
508 if it is in the bitmap area to the left/right of the window,
509 return 5 or 6, and convert *X and *Y to window-relative corrdinates.
511 X and Y are frame relative pixel coordinates. */
513 static enum window_part
514 coordinates_in_window (w
, x
, y
)
515 register struct window
*w
;
518 /* Let's make this a global enum later, instead of using numbers
520 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
521 int left_x
, right_x
, top_y
, bottom_y
;
522 int flags_area_width
= FRAME_LEFT_FLAGS_AREA_WIDTH (f
);
523 enum window_part part
;
524 int ux
= CANON_X_UNIT (f
), uy
= CANON_Y_UNIT (f
);
525 int x0
= XFASTINT (w
->left
) * ux
;
526 int x1
= x0
+ XFASTINT (w
->width
) * ux
;
527 /* The width of the area where the vertical line can be dragged.
528 (Between mode lines for instance. */
529 int grabbable_width
= ux
;
531 if (*x
< x0
|| *x
>= x1
)
534 /* In what's below, we subtract 1 when computing right_x because we
535 want the rightmost pixel, which is given by left_pixel+width-1. */
536 if (w
->pseudo_window_p
)
539 right_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
) - 1;
540 top_y
= WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
);
541 bottom_y
= WINDOW_DISPLAY_BOTTOM_EDGE_PIXEL_Y (w
);
545 left_x
= (WINDOW_DISPLAY_LEFT_EDGE_PIXEL_X (w
)
546 - FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
));
547 right_x
= WINDOW_DISPLAY_RIGHT_EDGE_PIXEL_X (w
) - 1;
548 top_y
= (WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
)
549 - FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
));
550 bottom_y
= WINDOW_DISPLAY_BOTTOM_EDGE_PIXEL_Y (w
);
553 /* On the mode line or header line? If it's near the start of
554 the mode or header line of window that's has a horizontal
555 sibling, say it's on the vertical line. That's to be able
556 to resize windows horizontally in case we're using toolkit
559 if (WINDOW_WANTS_MODELINE_P (w
)
560 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
)
563 /* We're somewhere on the mode line. We consider the place
564 between mode lines of horizontally adjacent mode lines
565 as the vertical border. If scroll bars on the left,
566 return the right window. */
569 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
571 if (abs (*x
- x0
) < grabbable_width
)
572 part
= ON_VERTICAL_BORDER
;
574 else if (!WINDOW_RIGHTMOST_P (w
) && abs (*x
- x1
) < grabbable_width
)
575 part
= ON_VERTICAL_BORDER
;
577 else if (WINDOW_WANTS_HEADER_LINE_P (w
)
578 && *y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
)
581 part
= ON_HEADER_LINE
;
583 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
585 if (abs (*x
- x0
) < grabbable_width
)
586 part
= ON_VERTICAL_BORDER
;
588 else if (!WINDOW_RIGHTMOST_P (w
) && abs (*x
- x1
) < grabbable_width
)
589 part
= ON_VERTICAL_BORDER
;
591 /* Outside anything interesting? */
596 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * ux
)
599 + FRAME_RIGHT_SCROLL_BAR_WIDTH (f
) * ux
))
603 else if (FRAME_WINDOW_P (f
))
605 if (!w
->pseudo_window_p
606 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
607 && !WINDOW_RIGHTMOST_P (w
)
608 && (abs (*x
- right_x
- flags_area_width
) < grabbable_width
))
610 part
= ON_VERTICAL_BORDER
;
612 else if (*x
< left_x
|| *x
> right_x
)
614 /* Other lines than the mode line don't include flags areas and
615 scroll bars on the left. */
617 /* Convert X and Y to window-relative pixel coordinates. */
620 part
= *x
< left_x
? ON_LEFT_FRINGE
: ON_RIGHT_FRINGE
;
631 /* Need to say "*x > right_x" rather than >=, since on character
632 terminals, the vertical line's x coordinate is right_x. */
633 if (*x
< left_x
|| *x
> right_x
)
635 /* Other lines than the mode line don't include flags areas and
636 scroll bars on the left. */
638 /* Convert X and Y to window-relative pixel coordinates. */
641 part
= *x
< left_x
? ON_LEFT_FRINGE
: ON_RIGHT_FRINGE
;
643 /* Here, too, "*x > right_x" is because of character terminals. */
644 else if (!w
->pseudo_window_p
645 && !WINDOW_RIGHTMOST_P (w
)
646 && *x
> right_x
- ux
)
648 /* On the border on the right side of the window? Assume that
649 this area begins at RIGHT_X minus a canonical char width. */
650 part
= ON_VERTICAL_BORDER
;
654 /* Convert X and Y to window-relative pixel coordinates. */
665 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
666 Scoordinates_in_window_p
, 2, 2, 0,
667 "Return non-nil if COORDINATES are in WINDOW.\n\
668 COORDINATES is a cons of the form (X . Y), X and Y being distances\n\
669 measured in characters from the upper-left corner of the frame.\n\
670 \(0 . 0) denotes the character in the upper left corner of the\n\
672 If COORDINATES are in the text portion of WINDOW,\n\
673 the coordinates relative to the window are returned.\n\
674 If they are in the mode line of WINDOW, `mode-line' is returned.\n\
675 If they are in the top mode line of WINDOW, `header-line' is returned.\n\
676 If they are in the fringe to the left of the window,\n\
677 `left-fringe' is returned, if they are in the area on the right of\n\
678 the window, `right-fringe' is returned.\n\
679 If they are on the border between WINDOW and its right sibling,\n\
680 `vertical-line' is returned.")
681 (coordinates
, window
)
682 register Lisp_Object coordinates
, window
;
689 CHECK_LIVE_WINDOW (window
, 0);
690 w
= XWINDOW (window
);
691 f
= XFRAME (w
->frame
);
692 CHECK_CONS (coordinates
, 1);
693 lx
= Fcar (coordinates
);
694 ly
= Fcdr (coordinates
);
695 CHECK_NUMBER_OR_FLOAT (lx
, 1);
696 CHECK_NUMBER_OR_FLOAT (ly
, 1);
697 x
= PIXEL_X_FROM_CANON_X (f
, lx
);
698 y
= PIXEL_Y_FROM_CANON_Y (f
, ly
);
700 switch (coordinates_in_window (w
, &x
, &y
))
706 /* X and Y are now window relative pixel coordinates. Convert
707 them to canonical char units before returning them. */
708 return Fcons (CANON_X_FROM_PIXEL_X (f
, x
),
709 CANON_Y_FROM_PIXEL_Y (f
, y
));
714 case ON_VERTICAL_BORDER
:
715 return Qvertical_line
;
723 case ON_RIGHT_FRINGE
:
724 return Qright_fringe
;
732 /* Callback for foreach_window, used in window_from_coordinates.
733 Check if window W contains coordinates specified by USER_DATA which
734 is actually a pointer to a struct check_window_data CW.
736 Check if window W contains coordinates *CW->x and *CW->y. If it
737 does, return W in *CW->window, as Lisp_Object, and return in
738 *CW->part the part of the window under coordinates *X,*Y. Return
739 zero from this function to stop iterating over windows. */
741 struct check_window_data
748 check_window_containing (w
, user_data
)
752 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
753 enum window_part found
;
756 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
757 if (found
!= ON_NOTHING
)
759 *cw
->part
= found
- 1;
760 XSETWINDOW (*cw
->window
, w
);
768 /* Find the window containing frame-relative pixel position X/Y and
769 return it as a Lisp_Object. If X, Y is on the window's modeline,
770 set *PART to 1; if it is on the separating line between the window
771 and its right sibling, set it to 2; otherwise set it to 0. If
772 there is no window under X, Y return nil and leave *PART
773 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
775 This function was previously implemented with a loop cycling over
776 windows with Fnext_window, and starting with the frame's selected
777 window. It turned out that this doesn't work with an
778 implementation of next_window using Vwindow_list, because
779 FRAME_SELECTED_WINDOW (F) is not always contained in the window
780 tree of F when this function is called asynchronously from
781 note_mouse_highlight. The original loop didn't terminate in this
785 window_from_coordinates (f
, x
, y
, part
, tool_bar_p
)
792 struct check_window_data cw
;
795 cw
.window
= &window
, cw
.x
= &x
, cw
.y
= &y
; cw
.part
= part
;
796 foreach_window (f
, check_window_containing
, &cw
);
798 /* If not found above, see if it's in the tool bar window, if a tool
802 && WINDOWP (f
->tool_bar_window
)
803 && XINT (XWINDOW (f
->tool_bar_window
)->height
) > 0
804 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), &x
, &y
)
808 window
= f
->tool_bar_window
;
814 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
815 "Return window containing coordinates X and Y on FRAME.\n\
816 If omitted, FRAME defaults to the currently selected frame.\n\
817 The top left corner of the frame is considered to be row 0,\n\
820 Lisp_Object x
, y
, frame
;
826 frame
= selected_frame
;
827 CHECK_LIVE_FRAME (frame
, 2);
830 /* Check that arguments are integers or floats. */
831 CHECK_NUMBER_OR_FLOAT (x
, 0);
832 CHECK_NUMBER_OR_FLOAT (y
, 1);
834 return window_from_coordinates (f
,
835 PIXEL_X_FROM_CANON_X (f
, x
),
836 PIXEL_Y_FROM_CANON_Y (f
, y
),
840 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
841 "Return current value of point in WINDOW.\n\
842 For a nonselected window, this is the value point would have\n\
843 if that window were selected.\n\
845 Note that, when WINDOW is the selected window and its buffer\n\
846 is also currently selected, the value returned is the same as (point).\n\
847 It would be more strictly correct to return the `top-level' value\n\
848 of point, outside of any save-excursion forms.\n\
849 But that is hard to define.")
853 register struct window
*w
= decode_window (window
);
855 if (w
== XWINDOW (selected_window
)
856 && current_buffer
== XBUFFER (w
->buffer
))
858 return Fmarker_position (w
->pointm
);
861 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
862 "Return position at which display currently starts in WINDOW.\n\
863 This is updated by redisplay or by calling `set-window-start'.")
867 return Fmarker_position (decode_window (window
)->start
);
870 /* This is text temporarily removed from the doc string below.
872 This function returns nil if the position is not currently known.\n\
873 That happens when redisplay is preempted and doesn't finish.\n\
874 If in that case you want to compute where the end of the window would\n\
875 have been if redisplay had finished, do this:\n\
877 (goto-char (window-start window))\n\
878 (vertical-motion (1- (window-height window)) window)\n\
881 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
882 "Return position at which display currently ends in WINDOW.\n\
883 This is updated by redisplay, when it runs to completion.\n\
884 Simply changing the buffer text or setting `window-start'\n\
885 does not update this value.\n\
886 If UPDATE is non-nil, compute the up-to-date position\n\
887 if it isn't already recorded.")
889 Lisp_Object window
, update
;
892 struct window
*w
= decode_window (window
);
896 CHECK_BUFFER (buf
, 0);
898 #if 0 /* This change broke some things. We should make it later. */
899 /* If we don't know the end position, return nil.
900 The user can compute it with vertical-motion if he wants to.
901 It would be nicer to do it automatically,
902 but that's so slow that it would probably bother people. */
903 if (NILP (w
->window_end_valid
))
908 && ! (! NILP (w
->window_end_valid
)
909 && XFASTINT (w
->last_modified
) >= MODIFF
))
911 struct text_pos startp
;
913 struct buffer
*old_buffer
= NULL
, *b
= XBUFFER (buf
);
915 /* In case W->start is out of the range, use something
916 reasonable. This situation occured when loading a file with
917 `-l' containing a call to `rmail' with subsequent other
918 commands. At the end, W->start happened to be BEG, while
919 rmail had already narrowed the buffer. */
920 if (XMARKER (w
->start
)->charpos
< BEGV
)
921 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
922 else if (XMARKER (w
->start
)->charpos
> ZV
)
923 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
925 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
927 /* Cannot use Fvertical_motion because that function doesn't
928 cope with variable-height lines. */
929 if (b
!= current_buffer
)
931 old_buffer
= current_buffer
;
932 set_buffer_internal (b
);
935 start_display (&it
, w
, startp
);
936 move_it_vertically (&it
, window_box_height (w
));
937 if (it
.current_y
< it
.last_visible_y
)
938 move_it_past_eol (&it
);
939 value
= make_number (IT_CHARPOS (it
));
942 set_buffer_internal (old_buffer
);
945 XSETINT (value
, BUF_Z (XBUFFER (buf
)) - XFASTINT (w
->window_end_pos
));
950 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
951 "Make point value in WINDOW be at position POS in WINDOW's buffer.")
953 Lisp_Object window
, pos
;
955 register struct window
*w
= decode_window (window
);
957 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
958 if (w
== XWINDOW (selected_window
)
959 && XBUFFER (w
->buffer
) == current_buffer
)
962 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
964 /* We have to make sure that redisplay updates the window to show
965 the new value of point. */
966 if (!EQ (window
, selected_window
))
967 ++windows_or_buffers_changed
;
972 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
973 "Make display in WINDOW start at position POS in WINDOW's buffer.\n\
974 Optional third arg NOFORCE non-nil inhibits next redisplay\n\
975 from overriding motion of point in order to display at this exact start.")
976 (window
, pos
, noforce
)
977 Lisp_Object window
, pos
, noforce
;
979 register struct window
*w
= decode_window (window
);
981 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
982 set_marker_restricted (w
->start
, pos
, w
->buffer
);
983 /* this is not right, but much easier than doing what is right. */
984 w
->start_at_line_beg
= Qnil
;
987 w
->update_mode_line
= Qt
;
988 XSETFASTINT (w
->last_modified
, 0);
989 XSETFASTINT (w
->last_overlay_modified
, 0);
990 if (!EQ (window
, selected_window
))
991 windows_or_buffers_changed
++;
996 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
998 "Return WINDOW's dedicated object, usually t or nil.\n\
999 See also `set-window-dedicated-p'.")
1003 return decode_window (window
)->dedicated
;
1006 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1007 Sset_window_dedicated_p
, 2, 2, 0,
1008 "Control whether WINDOW is dedicated to the buffer it displays.\n\
1009 If it is dedicated, Emacs will not automatically change\n\
1010 which buffer appears in it.\n\
1011 The second argument is the new value for the dedication flag;\n\
1012 non-nil means yes.")
1014 Lisp_Object window
, arg
;
1016 register struct window
*w
= decode_window (window
);
1019 w
->dedicated
= Qnil
;
1023 return w
->dedicated
;
1026 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1028 "Return the display-table that WINDOW is using.")
1032 return decode_window (window
)->display_table
;
1035 /* Get the display table for use on window W. This is either W's
1036 display table or W's buffer's display table. Ignore the specified
1037 tables if they are not valid; if no valid table is specified,
1040 struct Lisp_Char_Table
*
1041 window_display_table (w
)
1044 struct Lisp_Char_Table
*dp
= NULL
;
1046 if (DISP_TABLE_P (w
->display_table
))
1047 dp
= XCHAR_TABLE (w
->display_table
);
1048 else if (BUFFERP (w
->buffer
))
1050 struct buffer
*b
= XBUFFER (w
->buffer
);
1052 if (DISP_TABLE_P (b
->display_table
))
1053 dp
= XCHAR_TABLE (b
->display_table
);
1054 else if (DISP_TABLE_P (Vstandard_display_table
))
1055 dp
= XCHAR_TABLE (Vstandard_display_table
);
1061 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1062 "Set WINDOW's display-table to TABLE.")
1064 register Lisp_Object window
, table
;
1066 register struct window
*w
;
1068 w
= decode_window (window
);
1069 w
->display_table
= table
;
1073 /* Record info on buffer window w is displaying
1074 when it is about to cease to display that buffer. */
1077 register struct window
*w
;
1084 if (b
!= XMARKER (w
->pointm
)->buffer
)
1088 if (w
== XWINDOW (selected_window
)
1089 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1090 /* Do this except when the selected window's buffer
1091 is being removed from some other window. */
1093 /* last_window_start records the start position that this buffer
1094 had in the last window to be disconnected from it.
1095 Now that this statement is unconditional,
1096 it is possible for the buffer to be displayed in the
1097 selected window, while last_window_start reflects another
1098 window which was recently showing the same buffer.
1099 Some people might say that might be a good thing. Let's see. */
1100 b
->last_window_start
= marker_position (w
->start
);
1102 /* Point in the selected window's buffer
1103 is actually stored in that buffer, and the window's pointm isn't used.
1104 So don't clobber point in that buffer. */
1105 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1106 /* This line helps to fix Horsley's testbug.el bug. */
1107 && !(WINDOWP (b
->last_selected_window
)
1108 && w
!= XWINDOW (b
->last_selected_window
)
1109 && EQ (buf
, XWINDOW (b
->last_selected_window
)->buffer
)))
1110 temp_set_point_both (b
,
1111 clip_to_bounds (BUF_BEGV (b
),
1112 XMARKER (w
->pointm
)->charpos
,
1114 clip_to_bounds (BUF_BEGV_BYTE (b
),
1115 marker_byte_position (w
->pointm
),
1118 if (WINDOWP (b
->last_selected_window
)
1119 && w
== XWINDOW (b
->last_selected_window
))
1120 b
->last_selected_window
= Qnil
;
1123 /* Put replacement into the window structure in place of old. */
1125 replace_window (old
, replacement
)
1126 Lisp_Object old
, replacement
;
1128 register Lisp_Object tem
;
1129 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
1131 /* If OLD is its frame's root_window, then replacement is the new
1132 root_window for that frame. */
1134 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1135 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
1139 p
->width
= o
->width
;
1140 p
->height
= o
->height
;
1141 p
->desired_matrix
= p
->current_matrix
= 0;
1143 bzero (&p
->cursor
, sizeof (p
->cursor
));
1144 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
1145 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
1146 p
->phys_cursor_type
= -1;
1147 p
->must_be_updated_p
= 0;
1148 p
->pseudo_window_p
= 0;
1149 XSETFASTINT (p
->window_end_vpos
, 0);
1150 XSETFASTINT (p
->window_end_pos
, 0);
1151 p
->window_end_valid
= Qnil
;
1152 p
->frozen_window_start_p
= 0;
1153 p
->orig_top
= p
->orig_height
= Qnil
;
1155 p
->next
= tem
= o
->next
;
1157 XWINDOW (tem
)->prev
= replacement
;
1159 p
->prev
= tem
= o
->prev
;
1161 XWINDOW (tem
)->next
= replacement
;
1163 p
->parent
= tem
= o
->parent
;
1166 if (EQ (XWINDOW (tem
)->vchild
, old
))
1167 XWINDOW (tem
)->vchild
= replacement
;
1168 if (EQ (XWINDOW (tem
)->hchild
, old
))
1169 XWINDOW (tem
)->hchild
= replacement
;
1172 /*** Here, if replacement is a vertical combination
1173 and so is its new parent, we should make replacement's
1174 children be children of that parent instead. ***/
1177 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
1178 "Remove WINDOW from the display. Default is selected window.")
1180 register Lisp_Object window
;
1182 delete_window (window
);
1184 if (! NILP (Vwindow_configuration_change_hook
)
1185 && ! NILP (Vrun_hooks
))
1186 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
1192 delete_window (window
)
1193 register Lisp_Object window
;
1195 register Lisp_Object tem
, parent
, sib
;
1196 register struct window
*p
;
1197 register struct window
*par
;
1200 /* Because this function is called by other C code on non-leaf
1201 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1202 so we can't decode_window here. */
1204 window
= selected_window
;
1206 CHECK_WINDOW (window
, 0);
1207 p
= XWINDOW (window
);
1209 /* It's okay to delete an already-deleted window. */
1210 if (NILP (p
->buffer
)
1212 && NILP (p
->vchild
))
1217 error ("Attempt to delete minibuffer or sole ordinary window");
1218 par
= XWINDOW (parent
);
1220 windows_or_buffers_changed
++;
1221 Vwindow_list
= Qnil
;
1222 f
= XFRAME (WINDOW_FRAME (p
));
1223 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
1225 /* Are we trying to delete any frame's selected window? */
1227 Lisp_Object pwindow
;
1229 /* See if the frame's selected window is either WINDOW
1230 or any subwindow of it, by finding all that window's parents
1231 and comparing each one with WINDOW. */
1232 pwindow
= FRAME_SELECTED_WINDOW (f
);
1234 while (!NILP (pwindow
))
1236 if (EQ (window
, pwindow
))
1238 pwindow
= XWINDOW (pwindow
)->parent
;
1241 if (EQ (window
, pwindow
))
1243 Lisp_Object alternative
;
1244 alternative
= Fnext_window (window
, Qlambda
, Qnil
);
1246 /* If we're about to delete the selected window on the
1247 selected frame, then we should use Fselect_window to select
1248 the new window. On the other hand, if we're about to
1249 delete the selected window on any other frame, we shouldn't do
1250 anything but set the frame's selected_window slot. */
1251 if (EQ (window
, selected_window
))
1252 Fselect_window (alternative
);
1254 FRAME_SELECTED_WINDOW (f
) = alternative
;
1259 /* tem is null for dummy parent windows
1260 (which have inferiors but not any contents themselves) */
1264 unchain_marker (p
->pointm
);
1265 unchain_marker (p
->start
);
1268 /* Free window glyph matrices. It is sure that they are allocated
1269 again when ADJUST_GLYPHS is called. Block input so that expose
1270 events and other events that access glyph matrices are not
1271 processed while we are changing them. */
1273 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)));
1277 XWINDOW (tem
)->prev
= p
->prev
;
1281 XWINDOW (tem
)->next
= p
->next
;
1283 if (EQ (window
, par
->hchild
))
1284 par
->hchild
= p
->next
;
1285 if (EQ (window
, par
->vchild
))
1286 par
->vchild
= p
->next
;
1288 /* Find one of our siblings to give our space to. */
1292 /* If p gives its space to its next sibling, that sibling needs
1293 to have its top/left side pulled back to where p's is.
1294 set_window_{height,width} will re-position the sibling's
1297 XWINDOW (sib
)->top
= p
->top
;
1298 XWINDOW (sib
)->left
= p
->left
;
1301 /* Stretch that sibling. */
1302 if (!NILP (par
->vchild
))
1303 set_window_height (sib
,
1304 XFASTINT (XWINDOW (sib
)->height
) + XFASTINT (p
->height
),
1306 if (!NILP (par
->hchild
))
1307 set_window_width (sib
,
1308 XFASTINT (XWINDOW (sib
)->width
) + XFASTINT (p
->width
),
1311 /* If parent now has only one child,
1312 put the child into the parent's place. */
1316 if (NILP (XWINDOW (tem
)->next
))
1317 replace_window (parent
, tem
);
1319 /* Since we may be deleting combination windows, we must make sure that
1320 not only p but all its children have been marked as deleted. */
1321 if (! NILP (p
->hchild
))
1322 delete_all_subwindows (XWINDOW (p
->hchild
));
1323 else if (! NILP (p
->vchild
))
1324 delete_all_subwindows (XWINDOW (p
->vchild
));
1326 /* Mark this window as deleted. */
1327 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1329 /* Adjust glyph matrices. */
1336 /***********************************************************************
1338 ***********************************************************************/
1340 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1341 pointer. This is a callback function for foreach_window, used in
1342 function window_list. */
1345 add_window_to_list (w
, user_data
)
1349 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1351 XSETWINDOW (window
, w
);
1352 *list
= Fcons (window
, *list
);
1357 /* Return a list of all windows, for use by next_window. If
1358 Vwindow_list is a list, return that list. Otherwise, build a new
1359 list, cache it in Vwindow_list, and return that. */
1364 if (!CONSP (Vwindow_list
))
1368 Vwindow_list
= Qnil
;
1369 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1371 Lisp_Object args
[2];
1373 /* We are visiting windows in canonical order, and add
1374 new windows at the front of args[1], which means we
1375 have to reverse this list at the end. */
1377 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1378 args
[0] = Vwindow_list
;
1379 args
[1] = Fnreverse (args
[1]);
1380 Vwindow_list
= Fnconc (2, args
);
1384 return Vwindow_list
;
1388 /* Value is non-zero if WINDOW satisfies the constraints given by
1389 OWINDOW, MINIBUF and ALL_FRAMES.
1391 MINIBUF t means WINDOW may be minibuffer windows.
1392 `lambda' means WINDOW may not be a minibuffer window.
1393 a window means a specific minibuffer window
1395 ALL_FRAMES t means search all frames,
1396 nil means search just current frame,
1397 `visible' means search just visible frames,
1398 0 means search visible and iconified frames,
1399 a window means search the frame that window belongs to,
1400 a frame means consider windows on that frame, only. */
1403 candidate_window_p (window
, owindow
, minibuf
, all_frames
)
1404 Lisp_Object window
, owindow
, minibuf
, all_frames
;
1406 struct window
*w
= XWINDOW (window
);
1407 struct frame
*f
= XFRAME (w
->frame
);
1408 int candidate_p
= 1;
1410 if (!BUFFERP (w
->buffer
))
1412 else if (MINI_WINDOW_P (w
)
1413 && (EQ (minibuf
, Qlambda
)
1414 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
1416 /* If MINIBUF is `lambda' don't consider any mini-windows.
1417 If it is a window, consider only that one. */
1420 else if (EQ (all_frames
, Qt
))
1422 else if (NILP (all_frames
))
1424 xassert (WINDOWP (owindow
));
1425 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
1427 else if (EQ (all_frames
, Qvisible
))
1429 FRAME_SAMPLE_VISIBILITY (f
);
1430 candidate_p
= FRAME_VISIBLE_P (f
);
1432 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
1434 FRAME_SAMPLE_VISIBILITY (f
);
1435 candidate_p
= FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
);
1437 else if (WINDOWP (all_frames
))
1438 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
1439 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
1440 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
1441 else if (FRAMEP (all_frames
))
1442 candidate_p
= EQ (all_frames
, w
->frame
);
1448 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1449 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1453 decode_next_window_args (window
, minibuf
, all_frames
)
1454 Lisp_Object
*window
, *minibuf
, *all_frames
;
1457 *window
= selected_window
;
1459 CHECK_LIVE_WINDOW (*window
, 0);
1461 /* MINIBUF nil may or may not include minibuffers. Decide if it
1463 if (NILP (*minibuf
))
1464 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
1465 else if (!EQ (*minibuf
, Qt
))
1468 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1469 => count none of them, or a specific minibuffer window (the
1470 active one) to count. */
1472 /* ALL_FRAMES nil doesn't specify which frames to include. */
1473 if (NILP (*all_frames
))
1474 *all_frames
= (!EQ (*minibuf
, Qlambda
)
1475 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
1477 else if (EQ (*all_frames
, Qvisible
))
1479 else if (XFASTINT (*all_frames
) == 0)
1481 else if (FRAMEP (*all_frames
))
1483 else if (!EQ (*all_frames
, Qt
))
1486 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1487 search just current frame, `visible' meaning search just visible
1488 frames, 0 meaning search visible and iconified frames, or a
1489 window, meaning search the frame that window belongs to, or a
1490 frame, meaning consider windows on that frame, only. */
1494 /* Return the next or previous window of WINDOW in canonical ordering
1495 of windows. NEXT_P non-zero means return the next window. See the
1496 documentation string of next-window for the meaning of MINIBUF and
1500 next_window (window
, minibuf
, all_frames
, next_p
)
1501 Lisp_Object window
, minibuf
, all_frames
;
1504 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1506 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1507 return the first window on the frame. */
1508 if (FRAMEP (all_frames
)
1509 && !EQ (all_frames
, XWINDOW (window
)->frame
))
1510 return Fframe_first_window (all_frames
);
1516 /* Find WINDOW in the list of all windows. */
1517 list
= Fmemq (window
, window_list ());
1519 /* Scan forward from WINDOW to the end of the window list. */
1521 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
1522 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1525 /* Scan from the start of the window list up to WINDOW. */
1527 for (list
= Vwindow_list
;
1528 CONSP (list
) && !EQ (XCAR (list
), window
);
1530 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1534 window
= XCAR (list
);
1538 Lisp_Object candidate
, list
;
1540 /* Scan through the list of windows for candidates. If there are
1541 candidate windows in front of WINDOW, the last one of these
1542 is the one we want. If there are candidates following WINDOW
1543 in the list, again the last one of these is the one we want. */
1545 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
1547 if (EQ (XCAR (list
), window
))
1549 if (WINDOWP (candidate
))
1552 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
1554 candidate
= XCAR (list
);
1557 if (WINDOWP (candidate
))
1565 /* This comment supplies the doc string for `next-window',
1566 for make-docfile to see. We cannot put this in the real DEFUN
1567 due to limits in the Unix cpp.
1569 DEFUN ("next-window", Ffoo, Sfoo, 0, 3, 0,
1570 "Return next window after WINDOW in canonical ordering of windows.\n\
1571 If omitted, WINDOW defaults to the selected window.\n\
1573 Optional second arg MINIBUF t means count the minibuffer window even\n\
1574 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1575 it is active. MINIBUF neither t nor nil means not to count the\n\
1576 minibuffer even if it is active.\n\
1578 Several frames may share a single minibuffer; if the minibuffer\n\
1579 counts, all windows on all frames that share that minibuffer count\n\
1580 too. Therefore, `next-window' can be used to iterate through the\n\
1581 set of windows even when the minibuffer is on another frame. If the\n\
1582 minibuffer does not count, only windows from WINDOW's frame count.\n\
1584 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1585 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1586 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1587 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1588 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1589 Anything else means restrict to WINDOW's frame.\n\
1591 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1592 `next-window' to iterate through the entire cycle of acceptable\n\
1593 windows, eventually ending up back at the window you started with.\n\
1594 `previous-window' traverses the same cycle, in the reverse order.")
1595 (window, minibuf, all_frames) */
1597 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
1599 (window
, minibuf
, all_frames
)
1600 Lisp_Object window
, minibuf
, all_frames
;
1602 return next_window (window
, minibuf
, all_frames
, 1);
1606 /* This comment supplies the doc string for `previous-window',
1607 for make-docfile to see. We cannot put this in the real DEFUN
1608 due to limits in the Unix cpp.
1610 DEFUN ("previous-window", Ffoo, Sfoo, 0, 3, 0,
1611 "Return the window preceding WINDOW in canonical ordering of windows.\n\
1612 If omitted, WINDOW defaults to the selected window.\n\
1614 Optional second arg MINIBUF t means count the minibuffer window even\n\
1615 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1616 it is active. MINIBUF neither t nor nil means not to count the\n\
1617 minibuffer even if it is active.\n\
1619 Several frames may share a single minibuffer; if the minibuffer\n\
1620 counts, all windows on all frames that share that minibuffer count\n\
1621 too. Therefore, `previous-window' can be used to iterate through\n\
1622 the set of windows even when the minibuffer is on another frame. If\n\
1623 the minibuffer does not count, only windows from WINDOW's frame count\n\
1625 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1626 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1627 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1628 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1629 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1630 Anything else means restrict to WINDOW's frame.\n\
1632 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1633 `previous-window' to iterate through the entire cycle of acceptable\n\
1634 windows, eventually ending up back at the window you started with.\n\
1635 `next-window' traverses the same cycle, in the reverse order.")
1636 (window, minibuf, all_frames) */
1639 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1641 (window
, minibuf
, all_frames
)
1642 Lisp_Object window
, minibuf
, all_frames
;
1644 return next_window (window
, minibuf
, all_frames
, 0);
1648 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1649 "Select the ARG'th different window on this frame.\n\
1650 All windows on current frame are arranged in a cyclic order.\n\
1651 This command selects the window ARG steps away in that order.\n\
1652 A negative ARG moves in the opposite order. If the optional second\n\
1653 argument ALL_FRAMES is non-nil, cycle through all frames.")
1655 Lisp_Object arg
, all_frames
;
1660 CHECK_NUMBER (arg
, 0);
1661 window
= selected_window
;
1663 for (i
= XINT (arg
); i
> 0; --i
)
1664 window
= Fnext_window (window
, Qnil
, all_frames
);
1666 window
= Fprevious_window (window
, Qnil
, all_frames
);
1668 Fselect_window (window
);
1673 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
1674 "Return a list of windows on FRAME, starting with WINDOW.\n\
1675 FRAME nil or omitted means use the selected frame.\n\
1676 WINDOW nil or omitted means use the selected window.\n\
1677 MINIBUF t means include the minibuffer window, even if it isn't active.\n\
1678 MINIBUF nil or omitted means include the minibuffer window only\n\
1680 MINIBUF neither nil nor t means never include the minibuffer window.")
1681 (frame
, minibuf
, window
)
1682 Lisp_Object frame
, minibuf
, window
;
1685 window
= selected_window
;
1687 frame
= selected_frame
;
1689 if (!EQ (frame
, XWINDOW (window
)->frame
))
1690 error ("Window is on a different frame");
1692 return window_list_1 (window
, minibuf
, frame
);
1696 /* Return a list of windows in canonical ordering. Arguments are like
1697 for `next-window'. */
1700 window_list_1 (window
, minibuf
, all_frames
)
1701 Lisp_Object window
, minibuf
, all_frames
;
1703 Lisp_Object tail
, list
;
1705 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1708 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
1709 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
1710 list
= Fcons (XCAR (tail
), list
);
1712 return Fnreverse (list
);
1717 /* Look at all windows, performing an operation specified by TYPE
1719 If FRAMES is Qt, look at all frames;
1720 Qnil, look at just the selected frame;
1721 Qvisible, look at visible frames;
1722 a frame, just look at windows on that frame.
1723 If MINI is non-zero, perform the operation on minibuffer windows too. */
1728 GET_BUFFER_WINDOW
, /* Arg is buffer */
1729 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1730 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1731 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1733 UNSHOW_BUFFER
, /* Arg is buffer */
1738 window_loop (type
, obj
, mini
, frames
)
1739 enum window_loop type
;
1740 Lisp_Object obj
, frames
;
1743 Lisp_Object window
, windows
, best_window
, frame_arg
;
1745 struct gcpro gcpro1
;
1747 /* If we're only looping through windows on a particular frame,
1748 frame points to that frame. If we're looping through windows
1749 on all frames, frame is 0. */
1750 if (FRAMEP (frames
))
1751 f
= XFRAME (frames
);
1752 else if (NILP (frames
))
1753 f
= SELECTED_FRAME ();
1758 frame_arg
= Qlambda
;
1759 else if (XFASTINT (frames
) == 0)
1761 else if (EQ (frames
, Qvisible
))
1766 /* frame_arg is Qlambda to stick to one frame,
1767 Qvisible to consider all visible frames,
1770 /* Pick a window to start with. */
1774 window
= FRAME_SELECTED_WINDOW (f
);
1776 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
1778 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
1782 for (; CONSP (windows
); windows
= CDR (windows
))
1786 window
= XCAR (windows
);
1787 w
= XWINDOW (window
);
1789 /* Note that we do not pay attention here to whether the frame
1790 is visible, since Fwindow_list skips non-visible frames if
1791 that is desired, under the control of frame_arg. */
1792 if (!MINI_WINDOW_P (w
)
1793 /* For UNSHOW_BUFFER, we must always consider all windows. */
1794 || type
== UNSHOW_BUFFER
1795 || (mini
&& minibuf_level
> 0))
1798 case GET_BUFFER_WINDOW
:
1799 if (EQ (w
->buffer
, obj
)
1800 /* Don't find any minibuffer window
1801 except the one that is currently in use. */
1802 && (MINI_WINDOW_P (w
)
1803 ? EQ (window
, minibuf_window
)
1806 if (NILP (best_window
))
1807 best_window
= window
;
1808 else if (EQ (window
, selected_window
))
1809 /* For compatibility with 20.x, prefer to return
1811 best_window
= window
;
1815 case GET_LRU_WINDOW
:
1816 /* t as arg means consider only full-width windows */
1817 if (!NILP (obj
) && !WINDOW_FULL_WIDTH_P (w
))
1819 /* Ignore dedicated windows and minibuffers. */
1820 if (MINI_WINDOW_P (w
) || !NILP (w
->dedicated
))
1822 if (NILP (best_window
)
1823 || (XFASTINT (XWINDOW (best_window
)->use_time
)
1824 > XFASTINT (w
->use_time
)))
1825 best_window
= window
;
1828 case DELETE_OTHER_WINDOWS
:
1829 if (!EQ (window
, obj
))
1830 Fdelete_window (window
);
1833 case DELETE_BUFFER_WINDOWS
:
1834 if (EQ (w
->buffer
, obj
))
1836 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1838 /* If this window is dedicated, and in a frame of its own,
1840 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
1841 && !NILP (w
->dedicated
)
1842 && other_visible_frames (f
))
1844 /* Skip the other windows on this frame.
1845 There might be one, the minibuffer! */
1846 while (CONSP (XCDR (windows
))
1847 && EQ (XWINDOW (XCAR (windows
))->frame
,
1848 XWINDOW (XCAR (XCDR (windows
)))->frame
))
1849 windows
= XCDR (windows
);
1851 /* Now we can safely delete the frame. */
1852 Fdelete_frame (w
->frame
, Qnil
);
1854 else if (NILP (w
->parent
))
1856 /* If we're deleting the buffer displayed in the
1857 only window on the frame, find a new buffer to
1860 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
1862 buffer
= Fget_buffer_create (build_string ("*scratch*"));
1863 Fset_window_buffer (window
, buffer
);
1864 if (EQ (window
, selected_window
))
1865 Fset_buffer (w
->buffer
);
1868 Fdelete_window (window
);
1872 case GET_LARGEST_WINDOW
:
1874 /* Ignore dedicated windows and minibuffers. */
1875 if (MINI_WINDOW_P (w
) || !NILP (w
->dedicated
))
1878 if (NILP (best_window
))
1879 best_window
= window
;
1882 struct window
*b
= XWINDOW (best_window
);
1883 if (XFASTINT (w
->height
) * XFASTINT (w
->width
)
1884 > XFASTINT (b
->height
) * XFASTINT (b
->width
))
1885 best_window
= window
;
1891 if (EQ (w
->buffer
, obj
))
1894 struct frame
*f
= XFRAME (w
->frame
);
1896 /* Find another buffer to show in this window. */
1897 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
1899 buffer
= Fget_buffer_create (build_string ("*scratch*"));
1901 /* If this window is dedicated, and in a frame of its own,
1903 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
1904 && !NILP (w
->dedicated
)
1905 && other_visible_frames (f
))
1907 /* Skip the other windows on this frame.
1908 There might be one, the minibuffer! */
1909 while (CONSP (XCDR (windows
))
1910 && EQ (XWINDOW (XCAR (windows
))->frame
,
1911 XWINDOW (XCAR (XCDR (windows
)))->frame
))
1912 windows
= XCDR (windows
);
1914 /* Now we can safely delete the frame. */
1915 Fdelete_frame (w
->frame
, Qnil
);
1919 /* Otherwise show a different buffer in the window. */
1920 w
->dedicated
= Qnil
;
1921 Fset_window_buffer (window
, buffer
);
1922 if (EQ (window
, selected_window
))
1923 Fset_buffer (w
->buffer
);
1928 /* Check for a window that has a killed buffer. */
1929 case CHECK_ALL_WINDOWS
:
1930 if (! NILP (w
->buffer
)
1931 && NILP (XBUFFER (w
->buffer
)->name
))
1935 case WINDOW_LOOP_UNUSED
:
1944 /* Used for debugging. Abort if any window has a dead buffer. */
1947 check_all_windows ()
1949 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
1952 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 1, 0,
1953 "Return the window least recently selected or used for display.\n\
1954 If optional argument FRAME is `visible', search all visible frames.\n\
1955 If FRAME is 0, search all visible and iconified frames.\n\
1956 If FRAME is t, search all frames.\n\
1957 If FRAME is nil, search only the selected frame.\n\
1958 If FRAME is a frame, search only that frame.")
1962 register Lisp_Object w
;
1963 /* First try for a window that is full-width */
1964 w
= window_loop (GET_LRU_WINDOW
, Qt
, 0, frame
);
1965 if (!NILP (w
) && !EQ (w
, selected_window
))
1967 /* If none of them, try the rest */
1968 return window_loop (GET_LRU_WINDOW
, Qnil
, 0, frame
);
1971 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 1, 0,
1972 "Return the largest window in area.\n\
1973 If optional argument FRAME is `visible', search all visible frames.\n\
1974 If FRAME is 0, search all visible and iconified frames.\n\
1975 If FRAME is t, search all frames.\n\
1976 If FRAME is nil, search only the selected frame.\n\
1977 If FRAME is a frame, search only that frame.")
1981 return window_loop (GET_LARGEST_WINDOW
, Qnil
, 0,
1985 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
1986 "Return a window currently displaying BUFFER, or nil if none.\n\
1987 If optional argument FRAME is `visible', search all visible frames.\n\
1988 If optional argument FRAME is 0, search all visible and iconified frames.\n\
1989 If FRAME is t, search all frames.\n\
1990 If FRAME is nil, search only the selected frame.\n\
1991 If FRAME is a frame, search only that frame.")
1993 Lisp_Object buffer
, frame
;
1995 buffer
= Fget_buffer (buffer
);
1996 if (BUFFERP (buffer
))
1997 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
2002 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
2004 "Make WINDOW (or the selected window) fill its frame.\n\
2005 Only the frame WINDOW is on is affected.\n\
2006 This function tries to reduce display jumps\n\
2007 by keeping the text previously visible in WINDOW\n\
2008 in the same place on the frame. Doing this depends on\n\
2009 the value of (window-start WINDOW), so if calling this function\n\
2010 in a program gives strange scrolling, make sure the window-start\n\
2011 value is reasonable when this function is called.")
2020 window
= selected_window
;
2022 CHECK_LIVE_WINDOW (window
, 0);
2023 w
= XWINDOW (window
);
2025 startpos
= marker_position (w
->start
);
2026 top
= XFASTINT (w
->top
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2028 if (MINI_WINDOW_P (w
) && top
> 0)
2029 error ("Can't expand minibuffer to full frame");
2031 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
2033 /* Try to minimize scrolling, by setting the window start to the point
2034 will cause the text at the old window start to be at the same place
2035 on the frame. But don't try to do this if the window start is
2036 outside the visible portion (as might happen when the display is
2037 not current, due to typeahead). */
2038 new_top
= XFASTINT (w
->top
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2040 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2041 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2043 struct position pos
;
2044 struct buffer
*obuf
= current_buffer
;
2046 Fset_buffer (w
->buffer
);
2047 /* This computation used to temporarily move point, but that can
2048 have unwanted side effects due to text properties. */
2049 pos
= *vmotion (startpos
, -top
, w
);
2051 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2052 w
->window_end_valid
= Qnil
;
2053 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
2054 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
2056 /* We need to do this, so that the window-scroll-functions
2058 w
->optional_new_start
= Qt
;
2060 set_buffer_internal (obuf
);
2066 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
2067 1, 2, "bDelete windows on (buffer): ",
2068 "Delete all windows showing BUFFER.\n\
2069 Optional second argument FRAME controls which frames are affected.\n\
2070 If optional argument FRAME is `visible', search all visible frames.\n\
2071 If FRAME is 0, search all visible and iconified frames.\n\
2072 If FRAME is nil, search all frames.\n\
2073 If FRAME is t, search only the selected frame.\n\
2074 If FRAME is a frame, search only that frame.")
2076 Lisp_Object buffer
, frame
;
2078 /* FRAME uses t and nil to mean the opposite of what window_loop
2082 else if (EQ (frame
, Qt
))
2087 buffer
= Fget_buffer (buffer
);
2088 CHECK_BUFFER (buffer
, 0);
2089 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
2095 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
2096 Sreplace_buffer_in_windows
,
2097 1, 1, "bReplace buffer in windows: ",
2098 "Replace BUFFER with some other buffer in all windows showing it.")
2104 buffer
= Fget_buffer (buffer
);
2105 CHECK_BUFFER (buffer
, 0);
2106 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
2111 /* Replace BUFFER with some other buffer in all windows
2112 of all frames, even those on other keyboards. */
2115 replace_buffer_in_all_windows (buffer
)
2119 Lisp_Object tail
, frame
;
2121 /* A single call to window_loop won't do the job
2122 because it only considers frames on the current keyboard.
2123 So loop manually over frames, and handle each one. */
2124 FOR_EACH_FRAME (tail
, frame
)
2125 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
2127 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
2131 /* Set the height of WINDOW and all its inferiors. */
2133 /* The smallest acceptable dimensions for a window. Anything smaller
2134 might crash Emacs. */
2136 #define MIN_SAFE_WINDOW_WIDTH (2)
2137 #define MIN_SAFE_WINDOW_HEIGHT (2)
2139 /* Make sure that window_min_height and window_min_width are
2140 not too small; if they are, set them to safe minima. */
2143 check_min_window_sizes ()
2145 /* Smaller values might permit a crash. */
2146 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
2147 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
2148 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
2149 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
2152 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2153 minimum allowable size. */
2156 check_frame_size (frame
, rows
, cols
)
2160 /* For height, we have to see:
2161 whether the frame has a minibuffer,
2162 whether it wants a mode line, and
2163 whether it has a menu bar. */
2165 (FRAME_MINIBUF_ONLY_P (frame
) ? MIN_SAFE_WINDOW_HEIGHT
- 1
2166 : (! FRAME_HAS_MINIBUF_P (frame
)) ? MIN_SAFE_WINDOW_HEIGHT
2167 : 2 * MIN_SAFE_WINDOW_HEIGHT
- 1);
2169 if (FRAME_TOP_MARGIN (frame
) > 0)
2170 min_height
+= FRAME_TOP_MARGIN (frame
);
2172 if (*rows
< min_height
)
2174 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2175 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2179 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2180 check if W's width can be changed, otherwise check W's height.
2181 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2182 siblings, too. If none of the siblings is resizable, WINDOW isn't
2186 window_fixed_size_p (w
, width_p
, check_siblings_p
)
2188 int width_p
, check_siblings_p
;
2193 if (!NILP (w
->hchild
))
2195 c
= XWINDOW (w
->hchild
);
2199 /* A horiz. combination is fixed-width if all of if its
2201 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2202 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2203 fixed_p
= c
== NULL
;
2207 /* A horiz. combination is fixed-height if one of if its
2209 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2210 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2211 fixed_p
= c
!= NULL
;
2214 else if (!NILP (w
->vchild
))
2216 c
= XWINDOW (w
->vchild
);
2220 /* A vert. combination is fixed-width if one of if its
2222 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2223 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2224 fixed_p
= c
!= NULL
;
2228 /* A vert. combination is fixed-height if all of if its
2230 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2231 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2232 fixed_p
= c
== NULL
;
2235 else if (BUFFERP (w
->buffer
))
2237 if (w
->height_fixed_p
&& !width_p
)
2241 struct buffer
*old
= current_buffer
;
2244 current_buffer
= XBUFFER (w
->buffer
);
2245 val
= find_symbol_value (Qwindow_size_fixed
);
2246 current_buffer
= old
;
2249 if (!EQ (val
, Qunbound
))
2251 fixed_p
= !NILP (val
);
2254 && ((EQ (val
, Qheight
) && width_p
)
2255 || (EQ (val
, Qwidth
) && !width_p
)))
2260 /* Can't tell if this one is resizable without looking at
2261 siblings. If all siblings are fixed-size this one is too. */
2262 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
2266 for (child
= w
->prev
; !NILP (child
); child
= XWINDOW (child
)->prev
)
2267 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2271 for (child
= w
->next
; !NILP (child
); child
= XWINDOW (child
)->next
)
2272 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2286 /* Return the minimum size of window W, not taking fixed-width windows
2287 into account. WIDTH_P non-zero means return the minimum width,
2288 otherwise return the minimum height. If W is a combination window,
2289 compute the minimum size from the minimum sizes of W's children. */
2292 window_min_size_1 (w
, width_p
)
2299 if (!NILP (w
->hchild
))
2301 c
= XWINDOW (w
->hchild
);
2306 /* The min width of a horizontal combination is
2307 the sum of the min widths of its children. */
2310 size
+= window_min_size_1 (c
, width_p
);
2311 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2316 /* The min height a horizontal combination equals
2317 the maximum of all min height of its children. */
2320 int min_size
= window_min_size_1 (c
, width_p
);
2321 size
= max (min_size
, size
);
2322 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2326 else if (!NILP (w
->vchild
))
2328 c
= XWINDOW (w
->vchild
);
2333 /* The min width of a vertical combination is
2334 the maximum of the min widths of its children. */
2337 int min_size
= window_min_size_1 (c
, width_p
);
2338 size
= max (min_size
, size
);
2339 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2344 /* The min height of a vertical combination equals
2345 the sum of the min height of its children. */
2348 size
+= window_min_size_1 (c
, width_p
);
2349 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2356 size
= window_min_width
;
2359 if (MINI_WINDOW_P (w
)
2360 || (!WINDOW_WANTS_MODELINE_P (w
)
2361 && !WINDOW_WANTS_HEADER_LINE_P (w
)))
2364 size
= window_min_height
;
2372 /* Return the minimum size of window W, taking fixed-size windows into
2373 account. WIDTH_P non-zero means return the minimum width,
2374 otherwise return the minimum height. IGNORE_FIXED_P non-zero means
2375 ignore if W is fixed-size. Set *FIXED to 1 if W is fixed-size
2376 unless FIXED is null. */
2379 window_min_size (w
, width_p
, ignore_fixed_p
, fixed
)
2381 int width_p
, ignore_fixed_p
, *fixed
;
2388 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
2394 size
= width_p
? XFASTINT (w
->width
) : XFASTINT (w
->height
);
2396 size
= window_min_size_1 (w
, width_p
);
2402 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
2403 WINDOW's width. Resize WINDOW's children, if any, so that they
2404 keep their proportionate size relative to WINDOW. Propagate
2405 WINDOW's top or left edge position to children. Delete windows
2406 that become too small unless NODELETE_P is non-zero. */
2409 size_window (window
, size
, width_p
, nodelete_p
)
2411 int size
, width_p
, nodelete_p
;
2413 struct window
*w
= XWINDOW (window
);
2415 Lisp_Object child
, *forward
, *sideward
;
2416 int old_size
, min_size
;
2418 check_min_window_sizes ();
2419 size
= max (0, size
);
2421 /* If the window has been "too small" at one point,
2422 don't delete it for being "too small" in the future.
2423 Preserve it as long as that is at all possible. */
2426 old_size
= XINT (w
->width
);
2427 min_size
= window_min_width
;
2431 old_size
= XINT (w
->height
);
2432 min_size
= window_min_height
;
2435 if (old_size
< min_size
)
2436 w
->too_small_ok
= Qt
;
2438 /* Maybe delete WINDOW if it's too small. */
2439 if (!nodelete_p
&& !NILP (w
->parent
))
2441 if (!MINI_WINDOW_P (w
) && !NILP (w
->too_small_ok
))
2442 min_size
= width_p
? MIN_SAFE_WINDOW_WIDTH
: MIN_SAFE_WINDOW_HEIGHT
;
2444 min_size
= width_p
? window_min_width
: window_min_height
;
2446 if (size
< min_size
)
2448 delete_window (window
);
2453 /* Set redisplay hints. */
2454 w
->last_modified
= make_number (0);
2455 w
->last_overlay_modified
= make_number (0);
2456 windows_or_buffers_changed
++;
2457 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w
->frame
)) = 1;
2461 sideward
= &w
->vchild
;
2462 forward
= &w
->hchild
;
2463 w
->width
= make_number (size
);
2467 sideward
= &w
->hchild
;
2468 forward
= &w
->vchild
;
2469 w
->height
= make_number (size
);
2470 w
->orig_height
= Qnil
;
2473 if (!NILP (*sideward
))
2475 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
2477 c
= XWINDOW (child
);
2482 size_window (child
, size
, width_p
, nodelete_p
);
2485 else if (!NILP (*forward
))
2487 int fixed_size
, each
, extra
, n
;
2488 int resize_fixed_p
, nfixed
;
2489 int last_pos
, first_pos
, nchildren
, total
;
2491 /* Determine the fixed-size portion of the this window, and the
2492 number of child windows. */
2493 fixed_size
= nchildren
= nfixed
= total
= 0;
2494 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
2498 c
= XWINDOW (child
);
2499 child_size
= width_p
? XINT (c
->width
) : XINT (c
->height
);
2500 total
+= child_size
;
2502 if (window_fixed_size_p (c
, width_p
, 0))
2504 fixed_size
+= child_size
;
2509 /* If the new size is smaller than fixed_size, or if there
2510 aren't any resizable windows, allow resizing fixed-size
2512 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
2514 /* Compute how many lines/columns to add to each child. The
2515 value of extra takes care of rounding errors. */
2516 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
2517 each
= (size
- total
) / n
;
2518 extra
= (size
- total
) - n
* each
;
2520 /* Compute new children heights and edge positions. */
2521 first_pos
= width_p
? XINT (w
->left
) : XINT (w
->top
);
2522 last_pos
= first_pos
;
2523 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2525 int new_size
, old_size
;
2527 c
= XWINDOW (child
);
2528 old_size
= width_p
? XFASTINT (c
->width
) : XFASTINT (c
->height
);
2529 new_size
= old_size
;
2531 /* The top or left edge position of this child equals the
2532 bottom or right edge of its predecessor. */
2534 c
->left
= make_number (last_pos
);
2536 c
->top
= make_number (last_pos
);
2538 /* If this child can be resized, do it. */
2539 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
2541 new_size
= old_size
+ each
+ extra
;
2545 /* Set new height. Note that size_window also propagates
2546 edge positions to children, so it's not a no-op if we
2547 didn't change the child's size. */
2548 size_window (child
, new_size
, width_p
, 1);
2550 /* Remember the bottom/right edge position of this child; it
2551 will be used to set the top/left edge of the next child. */
2552 last_pos
+= new_size
;
2555 /* We should have covered the parent exactly with child windows. */
2556 xassert (size
== last_pos
- first_pos
);
2558 /* Now delete any children that became too small. */
2560 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2563 c
= XWINDOW (child
);
2564 child_size
= width_p
? XINT (c
->width
) : XINT (c
->height
);
2565 size_window (child
, child_size
, width_p
, 0);
2570 /* Set WINDOW's height to HEIGHT, and recursively change the height of
2571 WINDOW's children. NODELETE non-zero means don't delete windows
2572 that become too small in the process. (The caller should check
2573 later and do so if appropriate.) */
2576 set_window_height (window
, height
, nodelete
)
2581 size_window (window
, height
, 0, nodelete
);
2585 /* Set WINDOW's width to WIDTH, and recursively change the width of
2586 WINDOW's children. NODELETE non-zero means don't delete windows
2587 that become too small in the process. (The caller should check
2588 later and do so if appropriate.) */
2591 set_window_width (window
, width
, nodelete
)
2596 size_window (window
, width
, 1, nodelete
);
2600 int window_select_count
;
2603 Fset_window_buffer_unwind (obuf
)
2611 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
2612 means it's allowed to run hooks. See make_frame for a case where
2613 it's not allowed. */
2616 set_window_buffer (window
, buffer
, run_hooks_p
)
2617 Lisp_Object window
, buffer
;
2620 struct window
*w
= XWINDOW (window
);
2621 struct buffer
*b
= XBUFFER (buffer
);
2622 int count
= specpdl_ptr
- specpdl
;
2626 if (EQ (window
, selected_window
))
2627 b
->last_selected_window
= window
;
2629 /* Update time stamps of buffer display. */
2630 if (INTEGERP (b
->display_count
))
2631 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
2632 b
->display_time
= Fcurrent_time ();
2634 XSETFASTINT (w
->window_end_pos
, 0);
2635 XSETFASTINT (w
->window_end_vpos
, 0);
2636 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
2637 w
->window_end_valid
= Qnil
;
2638 w
->hscroll
= w
->min_hscroll
= make_number (0);
2640 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
2641 set_marker_restricted (w
->start
,
2642 make_number (b
->last_window_start
),
2644 w
->start_at_line_beg
= Qnil
;
2645 w
->force_start
= Qnil
;
2646 XSETFASTINT (w
->last_modified
, 0);
2647 XSETFASTINT (w
->last_overlay_modified
, 0);
2648 windows_or_buffers_changed
++;
2650 /* We must select BUFFER for running the window-scroll-functions.
2651 If WINDOW is selected, switch permanently.
2652 Otherwise, switch but go back to the ambient buffer afterward. */
2653 if (EQ (window
, selected_window
))
2654 Fset_buffer (buffer
);
2655 /* We can't check ! NILP (Vwindow_scroll_functions) here
2656 because that might itself be a local variable. */
2657 else if (window_initialized
)
2659 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
2660 Fset_buffer (buffer
);
2663 /* Set left and right marginal area width from buffer. */
2664 Fset_window_margins (window
, b
->left_margin_width
, b
->right_margin_width
);
2668 if (! NILP (Vwindow_scroll_functions
))
2669 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2670 Fmarker_position (w
->start
));
2672 if (! NILP (Vwindow_configuration_change_hook
)
2673 && ! NILP (Vrun_hooks
))
2674 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2677 unbind_to (count
, Qnil
);
2681 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 2, 0,
2682 "Make WINDOW display BUFFER as its contents.\n\
2683 BUFFER can be a buffer or buffer name.")
2685 register Lisp_Object window
, buffer
;
2687 register Lisp_Object tem
;
2688 register struct window
*w
= decode_window (window
);
2690 XSETWINDOW (window
, w
);
2691 buffer
= Fget_buffer (buffer
);
2692 CHECK_BUFFER (buffer
, 1);
2694 if (NILP (XBUFFER (buffer
)->name
))
2695 error ("Attempt to display deleted buffer");
2699 error ("Window is deleted");
2700 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
2701 is first being set up. */
2703 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
2704 error ("Window is dedicated to `%s'",
2705 XSTRING (XBUFFER (tem
)->name
)->data
);
2710 set_window_buffer (window
, buffer
, 1);
2714 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 1, 0,
2715 "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\
2716 If WINDOW is not already selected, also make WINDOW's buffer current.\n\
2717 Note that the main editor command loop\n\
2718 selects the buffer of the selected window before each command.")
2720 register Lisp_Object window
;
2722 return select_window_1 (window
, 1);
2725 /* Note that selected_window can be nil
2726 when this is called from Fset_window_configuration. */
2729 select_window_1 (window
, recordflag
)
2730 register Lisp_Object window
;
2733 register struct window
*w
;
2734 register struct window
*ow
;
2737 CHECK_LIVE_WINDOW (window
, 0);
2739 w
= XWINDOW (window
);
2740 w
->frozen_window_start_p
= 0;
2742 XSETFASTINT (w
->use_time
, ++window_select_count
);
2743 if (EQ (window
, selected_window
))
2746 if (!NILP (selected_window
))
2748 ow
= XWINDOW (selected_window
);
2749 if (! NILP (ow
->buffer
))
2750 set_marker_both (ow
->pointm
, ow
->buffer
,
2751 BUF_PT (XBUFFER (ow
->buffer
)),
2752 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
2755 selected_window
= window
;
2756 sf
= SELECTED_FRAME ();
2757 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
2759 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
2760 /* Use this rather than Fhandle_switch_frame
2761 so that FRAME_FOCUS_FRAME is moved appropriately as we
2762 move around in the state where a minibuffer in a separate
2764 Fselect_frame (WINDOW_FRAME (w
), Qnil
);
2767 sf
->selected_window
= window
;
2770 record_buffer (w
->buffer
);
2771 Fset_buffer (w
->buffer
);
2773 XBUFFER (w
->buffer
)->last_selected_window
= window
;
2775 /* Go to the point recorded in the window.
2776 This is important when the buffer is in more
2777 than one window. It also matters when
2778 redisplay_window has altered point after scrolling,
2779 because it makes the change only in the window. */
2781 register int new_point
= marker_position (w
->pointm
);
2782 if (new_point
< BEGV
)
2784 else if (new_point
> ZV
)
2790 windows_or_buffers_changed
++;
2794 /* Deiconify the frame containing the window WINDOW,
2795 unless it is the selected frame;
2798 The reason for the exception for the selected frame
2799 is that it seems better not to change the selected frames visibility
2800 merely because of displaying a different buffer in it.
2801 The deiconification is useful when a buffer gets shown in
2802 another frame that you were not using lately. */
2805 display_buffer_1 (window
)
2808 Lisp_Object frame
= XWINDOW (window
)->frame
;
2809 FRAME_PTR f
= XFRAME (frame
);
2811 FRAME_SAMPLE_VISIBILITY (f
);
2813 if (!EQ (frame
, selected_frame
))
2815 if (FRAME_ICONIFIED_P (f
))
2816 Fmake_frame_visible (frame
);
2817 else if (FRAME_VISIBLE_P (f
))
2818 Fraise_frame (frame
);
2824 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
2825 "Returns non-nil if a buffer named BUFFER-NAME would be created specially.\n\
2826 The value is actually t if the frame should be called with default frame\n\
2827 parameters, and a list of frame parameters if they were specified.\n\
2828 See `special-display-buffer-names', and `special-display-regexps'.")
2830 Lisp_Object buffer_name
;
2834 CHECK_STRING (buffer_name
, 1);
2836 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
2840 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
2844 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2846 Lisp_Object car
= XCAR (tem
);
2848 && fast_string_match (car
, buffer_name
) >= 0)
2850 else if (CONSP (car
)
2851 && STRINGP (XCAR (car
))
2852 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2858 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
2859 "Returns non-nil if a new buffer named BUFFER-NAME would use the same window.\n\
2860 See `same-window-buffer-names' and `same-window-regexps'.")
2862 Lisp_Object buffer_name
;
2866 CHECK_STRING (buffer_name
, 1);
2868 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
2872 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
2876 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2878 Lisp_Object car
= XCAR (tem
);
2880 && fast_string_match (car
, buffer_name
) >= 0)
2882 else if (CONSP (car
)
2883 && STRINGP (XCAR (car
))
2884 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2890 /* Use B so the default is (other-buffer). */
2891 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
2892 "BDisplay buffer: \nP",
2893 "Make BUFFER appear in some window but don't select it.\n\
2894 BUFFER can be a buffer or a buffer name.\n\
2895 If BUFFER is shown already in some window, just use that one,\n\
2896 unless the window is the selected window and the optional second\n\
2897 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).\n\
2898 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.\n\
2899 Returns the window displaying BUFFER.\n\
2900 If `display-reuse-frames' is non-nil, and another frame is currently\n\
2901 displaying BUFFER, then simply raise that frame.\n\
2903 The variables `special-display-buffer-names', `special-display-regexps',\n\
2904 `same-window-buffer-names', and `same-window-regexps' customize how certain\n\
2905 buffer names are handled.\n\
2907 If optional argument FRAME is `visible', search all visible frames.\n\
2908 If FRAME is 0, search all visible and iconified frames.\n\
2909 If FRAME is t, search all frames.\n\
2910 If FRAME is a frame, search only that frame.\n\
2911 If FRAME is nil, search only the selected frame\n\
2912 (actually the last nonminibuffer frame),\n\
2913 unless `pop-up-frames' or `display-buffer-reuse-frames' is non-nil,\n\
2914 which means search visible and iconified frames.\n\
2916 If `even-window-heights' is non-nil, window heights will be evened out\n\
2917 if displaying the buffer causes two vertically adjacent windows to be\n\
2919 (buffer
, not_this_window
, frame
)
2920 register Lisp_Object buffer
, not_this_window
, frame
;
2922 register Lisp_Object window
, tem
, swp
;
2926 buffer
= Fget_buffer (buffer
);
2927 CHECK_BUFFER (buffer
, 0);
2929 if (!NILP (Vdisplay_buffer_function
))
2930 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
2932 if (NILP (not_this_window
)
2933 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
2934 return display_buffer_1 (selected_window
);
2936 /* See if the user has specified this buffer should appear
2937 in the selected window. */
2938 if (NILP (not_this_window
))
2940 swp
= Fsame_window_p (XBUFFER (buffer
)->name
);
2941 if (!NILP (swp
) && !no_switch_window (selected_window
))
2943 Fswitch_to_buffer (buffer
, Qnil
);
2944 return display_buffer_1 (selected_window
);
2948 /* If the user wants pop-up-frames or display-reuse-frames, then
2949 look for a window showing BUFFER on any visible or iconified frame.
2950 Otherwise search only the current frame. */
2953 else if (pop_up_frames
2954 || display_buffer_reuse_frames
2955 || last_nonminibuf_frame
== 0)
2956 XSETFASTINT (tem
, 0);
2958 XSETFRAME (tem
, last_nonminibuf_frame
);
2960 window
= Fget_buffer_window (buffer
, tem
);
2962 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
2963 return display_buffer_1 (window
);
2965 /* Certain buffer names get special handling. */
2966 if (!NILP (Vspecial_display_function
) && NILP (swp
))
2968 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
2970 return call1 (Vspecial_display_function
, buffer
);
2972 return call2 (Vspecial_display_function
, buffer
, tem
);
2975 /* If there are no frames open that have more than a minibuffer,
2976 we need to create a new frame. */
2977 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2979 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2980 Fset_window_buffer (window
, buffer
);
2981 return display_buffer_1 (window
);
2984 f
= SELECTED_FRAME ();
2986 || FRAME_MINIBUF_ONLY_P (f
)
2987 /* If the current frame is a special display frame,
2988 don't try to reuse its windows. */
2989 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (f
))->dedicated
))
2994 if (FRAME_MINIBUF_ONLY_P (f
))
2995 XSETFRAME (frames
, last_nonminibuf_frame
);
2996 /* Don't try to create a window if would get an error */
2997 if (split_height_threshold
< window_min_height
<< 1)
2998 split_height_threshold
= window_min_height
<< 1;
3000 /* Note that both Fget_largest_window and Fget_lru_window
3001 ignore minibuffers and dedicated windows.
3002 This means they can return nil. */
3004 /* If the frame we would try to split cannot be split,
3005 try other frames. */
3006 if (FRAME_NO_SPLIT_P (NILP (frames
) ? f
: last_nonminibuf_frame
))
3008 /* Try visible frames first. */
3009 window
= Fget_largest_window (Qvisible
);
3010 /* If that didn't work, try iconified frames. */
3012 window
= Fget_largest_window (make_number (0));
3014 window
= Fget_largest_window (Qt
);
3017 window
= Fget_largest_window (frames
);
3019 /* If we got a tall enough full-width window that can be split,
3022 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3023 && window_height (window
) >= split_height_threshold
3024 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
3025 window
= Fsplit_window (window
, Qnil
, Qnil
);
3028 Lisp_Object upper
, lower
, other
;
3030 window
= Fget_lru_window (frames
);
3031 /* If the LRU window is selected, and big enough,
3032 and can be split, split it. */
3034 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
3035 && (EQ (window
, selected_window
)
3036 || EQ (XWINDOW (window
)->parent
, Qnil
))
3037 && window_height (window
) >= window_min_height
<< 1)
3038 window
= Fsplit_window (window
, Qnil
, Qnil
);
3039 /* If Fget_lru_window returned nil, try other approaches. */
3041 /* Try visible frames first. */
3043 window
= Fget_buffer_window (buffer
, Qvisible
);
3045 window
= Fget_largest_window (Qvisible
);
3046 /* If that didn't work, try iconified frames. */
3048 window
= Fget_buffer_window (buffer
, make_number (0));
3050 window
= Fget_largest_window (make_number (0));
3051 /* Try invisible frames. */
3053 window
= Fget_buffer_window (buffer
, Qt
);
3055 window
= Fget_largest_window (Qt
);
3056 /* As a last resort, make a new frame. */
3058 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
3059 /* If window appears above or below another,
3060 even out their heights. */
3061 other
= upper
= lower
= Qnil
;
3062 if (!NILP (XWINDOW (window
)->prev
))
3063 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
3064 if (!NILP (XWINDOW (window
)->next
))
3065 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
3067 && !NILP (Veven_window_heights
)
3068 /* Check that OTHER and WINDOW are vertically arrayed. */
3069 && !EQ (XWINDOW (other
)->top
, XWINDOW (window
)->top
)
3070 && (XFASTINT (XWINDOW (other
)->height
)
3071 > XFASTINT (XWINDOW (window
)->height
)))
3073 int total
= (XFASTINT (XWINDOW (other
)->height
)
3074 + XFASTINT (XWINDOW (window
)->height
));
3075 enlarge_window (upper
,
3076 total
/ 2 - XFASTINT (XWINDOW (upper
)->height
),
3082 window
= Fget_lru_window (Qnil
);
3084 Fset_window_buffer (window
, buffer
);
3085 return display_buffer_1 (window
);
3089 temp_output_buffer_show (buf
)
3090 register Lisp_Object buf
;
3092 register struct buffer
*old
= current_buffer
;
3093 register Lisp_Object window
;
3094 register struct window
*w
;
3096 XBUFFER (buf
)->directory
= current_buffer
->directory
;
3099 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3103 XBUFFER (buf
)->prevent_redisplay_optimizations_p
= 1;
3104 set_buffer_internal (old
);
3106 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
3107 call1 (Vtemp_buffer_show_function
, buf
);
3110 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
3112 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3113 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3114 Vminibuf_scroll_window
= window
;
3115 w
= XWINDOW (window
);
3116 XSETFASTINT (w
->hscroll
, 0);
3117 XSETFASTINT (w
->min_hscroll
, 0);
3118 set_marker_restricted_both (w
->start
, buf
, 1, 1);
3119 set_marker_restricted_both (w
->pointm
, buf
, 1, 1);
3121 /* Run temp-buffer-show-hook, with the chosen window selected
3122 and it sbuffer current. */
3123 if (!NILP (Vrun_hooks
))
3126 tem
= Fboundp (Qtemp_buffer_show_hook
);
3129 tem
= Fsymbol_value (Qtemp_buffer_show_hook
);
3132 int count
= specpdl_ptr
- specpdl
;
3133 Lisp_Object prev_window
;
3134 prev_window
= selected_window
;
3136 /* Select the window that was chosen, for running the hook. */
3137 record_unwind_protect (Fselect_window
, prev_window
);
3138 select_window_1 (window
, 0);
3139 Fset_buffer (w
->buffer
);
3140 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
3141 select_window_1 (prev_window
, 0);
3142 unbind_to (count
, Qnil
);
3150 make_dummy_parent (window
)
3154 register struct window
*o
, *p
;
3157 o
= XWINDOW (window
);
3158 p
= allocate_window ();
3159 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
3160 ((struct Lisp_Vector
*) p
)->contents
[i
]
3161 = ((struct Lisp_Vector
*)o
)->contents
[i
];
3162 XSETWINDOW (new, p
);
3164 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
3166 /* Put new into window structure in place of window */
3167 replace_window (window
, new);
3180 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
3181 "Split WINDOW, putting SIZE lines in the first of the pair.\n\
3182 WINDOW defaults to selected one and SIZE to half its size.\n\
3183 If optional third arg HORFLAG is non-nil, split side by side\n\
3184 and put SIZE columns in the first of the pair. In that case,\n\
3185 SIZE includes that window's scroll bar, or the divider column to its right.")
3186 (window
, size
, horflag
)
3187 Lisp_Object window
, size
, horflag
;
3189 register Lisp_Object
new;
3190 register struct window
*o
, *p
;
3192 register int size_int
;
3195 window
= selected_window
;
3197 CHECK_LIVE_WINDOW (window
, 0);
3199 o
= XWINDOW (window
);
3200 fo
= XFRAME (WINDOW_FRAME (o
));
3204 if (!NILP (horflag
))
3205 /* Calculate the size of the left-hand window, by dividing
3206 the usable space in columns by two.
3207 We round up, since the left-hand window may include
3208 a dividing line, while the right-hand may not. */
3209 size_int
= (XFASTINT (o
->width
) + 1) >> 1;
3211 size_int
= XFASTINT (o
->height
) >> 1;
3215 CHECK_NUMBER (size
, 1);
3216 size_int
= XINT (size
);
3219 if (MINI_WINDOW_P (o
))
3220 error ("Attempt to split minibuffer window");
3221 else if (window_fixed_size_p (o
, !NILP (horflag
), 0))
3222 error ("Attempt to split fixed-size window");
3224 check_min_window_sizes ();
3228 if (size_int
< window_min_height
)
3229 error ("Window height %d too small (after splitting)", size_int
);
3230 if (size_int
+ window_min_height
> XFASTINT (o
->height
))
3231 error ("Window height %d too small (after splitting)",
3232 XFASTINT (o
->height
) - size_int
);
3233 if (NILP (o
->parent
)
3234 || NILP (XWINDOW (o
->parent
)->vchild
))
3236 make_dummy_parent (window
);
3238 XWINDOW (new)->vchild
= window
;
3243 if (size_int
< window_min_width
)
3244 error ("Window width %d too small (after splitting)", size_int
);
3246 if (size_int
+ window_min_width
> XFASTINT (o
->width
))
3247 error ("Window width %d too small (after splitting)",
3248 XFASTINT (o
->width
) - size_int
);
3249 if (NILP (o
->parent
)
3250 || NILP (XWINDOW (o
->parent
)->hchild
))
3252 make_dummy_parent (window
);
3254 XWINDOW (new)->hchild
= window
;
3258 /* Now we know that window's parent is a vertical combination
3259 if we are dividing vertically, or a horizontal combination
3260 if we are making side-by-side windows */
3262 windows_or_buffers_changed
++;
3263 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
3264 new = make_window ();
3267 p
->frame
= o
->frame
;
3269 if (!NILP (p
->next
))
3270 XWINDOW (p
->next
)->prev
= new;
3273 p
->parent
= o
->parent
;
3275 p
->window_end_valid
= Qnil
;
3276 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
3278 /* Apportion the available frame space among the two new windows */
3280 if (!NILP (horflag
))
3282 p
->height
= o
->height
;
3284 XSETFASTINT (p
->width
, XFASTINT (o
->width
) - size_int
);
3285 XSETFASTINT (o
->width
, size_int
);
3286 XSETFASTINT (p
->left
, XFASTINT (o
->left
) + size_int
);
3291 p
->width
= o
->width
;
3292 XSETFASTINT (p
->height
, XFASTINT (o
->height
) - size_int
);
3293 XSETFASTINT (o
->height
, size_int
);
3294 XSETFASTINT (p
->top
, XFASTINT (o
->top
) + size_int
);
3297 /* Adjust glyph matrices. */
3299 Fset_window_buffer (new, o
->buffer
);
3303 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
3304 "Make current window ARG lines bigger.\n\
3305 From program, optional second arg non-nil means grow sideways ARG columns.\n\
3306 Interactively, if an argument is not given, make the window one line bigger.")
3308 register Lisp_Object arg
, side
;
3310 CHECK_NUMBER (arg
, 0);
3311 enlarge_window (selected_window
, XINT (arg
), !NILP (side
));
3313 if (! NILP (Vwindow_configuration_change_hook
))
3314 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3319 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
3320 "Make current window ARG lines smaller.\n\
3321 From program, optional second arg non-nil means shrink sideways arg columns.\n\
3322 Interactively, if an argument is not given, make the window one line smaller.")
3324 register Lisp_Object arg
, side
;
3326 CHECK_NUMBER (arg
, 0);
3327 enlarge_window (selected_window
, -XINT (arg
), !NILP (side
));
3329 if (! NILP (Vwindow_configuration_change_hook
))
3330 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3336 window_height (window
)
3339 register struct window
*p
= XWINDOW (window
);
3340 return XFASTINT (p
->height
);
3344 window_width (window
)
3347 register struct window
*p
= XWINDOW (window
);
3348 return XFASTINT (p
->width
);
3353 *(widthflag ? &(XWINDOW (w)->left) : &(XWINDOW (w)->top))
3355 #define CURSIZE(w) \
3356 *(widthflag ? &(XWINDOW (w)->width) : &(XWINDOW (w)->height))
3359 /* Enlarge selected_window by DELTA. WIDTHFLAG non-zero means
3360 increase its width. Siblings of the selected window are resized to
3361 fullfil the size request. If they become too small in the process,
3362 they will be deleted. */
3365 enlarge_window (window
, delta
, widthflag
)
3367 int delta
, widthflag
;
3369 Lisp_Object parent
, next
, prev
;
3373 int (*sizefun
) P_ ((Lisp_Object
))
3374 = widthflag
? window_width
: window_height
;
3375 void (*setsizefun
) P_ ((Lisp_Object
, int, int))
3376 = (widthflag
? set_window_width
: set_window_height
);
3378 /* Check values of window_min_width and window_min_height for
3380 check_min_window_sizes ();
3382 /* Give up if this window cannot be resized. */
3383 if (window_fixed_size_p (XWINDOW (window
), widthflag
, 1))
3384 error ("Window is not resizable");
3386 /* Find the parent of the selected window. */
3389 p
= XWINDOW (window
);
3395 error ("No other window to side of this one");
3400 ? !NILP (XWINDOW (parent
)->hchild
)
3401 : !NILP (XWINDOW (parent
)->vchild
))
3407 sizep
= &CURSIZE (window
);
3410 register int maxdelta
;
3412 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - XINT (*sizep
)
3413 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
3414 - window_min_size (XWINDOW (p
->next
),
3416 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
3417 - window_min_size (XWINDOW (p
->prev
),
3419 /* This is a frame with only one window, a minibuffer-only
3420 or a minibufferless frame. */
3423 if (delta
> maxdelta
)
3424 /* This case traps trying to make the minibuffer
3425 the full frame, or make the only window aside from the
3426 minibuffer the full frame. */
3430 if (XINT (*sizep
) + delta
< window_min_size (XWINDOW (window
), widthflag
, 0, 0))
3432 delete_window (window
);
3439 /* Find the total we can get from other siblings. */
3441 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
3442 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
3444 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
3445 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
3448 /* If we can get it all from them, do so. */
3449 if (delta
<= maximum
)
3451 Lisp_Object first_unaffected
;
3452 Lisp_Object first_affected
;
3457 first_affected
= window
;
3458 /* Look at one sibling at a time,
3459 moving away from this window in both directions alternately,
3460 and take as much as we can get without deleting that sibling. */
3461 while (delta
!= 0 && (!NILP (next
) || !NILP (prev
)))
3465 int this_one
= ((*sizefun
) (next
)
3466 - window_min_size (XWINDOW (next
),
3467 widthflag
, 0, &fixed_p
));
3470 if (this_one
> delta
)
3473 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
3474 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
3479 next
= XWINDOW (next
)->next
;
3487 int this_one
= ((*sizefun
) (prev
)
3488 - window_min_size (XWINDOW (prev
),
3489 widthflag
, 0, &fixed_p
));
3492 if (this_one
> delta
)
3495 first_affected
= prev
;
3497 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
3498 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
3503 prev
= XWINDOW (prev
)->prev
;
3507 xassert (delta
== 0);
3509 /* Now recalculate the edge positions of all the windows affected,
3510 based on the new sizes. */
3511 first_unaffected
= next
;
3512 prev
= first_affected
;
3513 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
3514 prev
= next
, next
= XWINDOW (next
)->next
)
3516 XSETINT (CURBEG (next
), XINT (CURBEG (prev
)) + (*sizefun
) (prev
));
3517 /* This does not change size of NEXT,
3518 but it propagates the new top edge to its children */
3519 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
3524 register int delta1
;
3525 register int opht
= (*sizefun
) (parent
);
3527 if (opht
<= XINT (*sizep
) + delta
)
3529 /* If trying to grow this window to or beyond size of the parent,
3530 just delete all the sibling windows. */
3531 Lisp_Object start
, tem
, next
;
3533 start
= XWINDOW (parent
)->vchild
;
3535 start
= XWINDOW (parent
)->hchild
;
3537 /* Delete any siblings that come after WINDOW. */
3538 tem
= XWINDOW (window
)->next
;
3539 while (! NILP (tem
))
3541 next
= XWINDOW (tem
)->next
;
3542 delete_window (tem
);
3546 /* Delete any siblings that come after WINDOW.
3547 Note that if START is not WINDOW, then WINDOW still
3548 Fhas siblings, so WINDOW has not yet replaced its parent. */
3550 while (! EQ (tem
, window
))
3552 next
= XWINDOW (tem
)->next
;
3553 delete_window (tem
);
3559 /* Otherwise, make delta1 just right so that if we add
3560 delta1 lines to this window and to the parent, and then
3561 shrink the parent back to its original size, the new
3562 proportional size of this window will increase by delta.
3564 The function size_window will compute the new height h'
3565 of the window from delta1 as:
3568 x = delta1 - delta1/n * n for the 1st resizable child
3571 where n is the number of children that can be resized.
3572 We can ignore x by choosing a delta1 that is a multiple of
3573 n. We want the height of this window to come out as
3583 The number of children n rquals the number of resizable
3584 children of this window + 1 because we know window itself
3585 is resizable (otherwise we would have signalled an error. */
3587 struct window
*w
= XWINDOW (window
);
3591 for (s
= w
->next
; !NILP (s
); s
= XWINDOW (s
)->next
)
3592 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
3594 for (s
= w
->prev
; !NILP (s
); s
= XWINDOW (s
)->prev
)
3595 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
3600 /* Add delta1 lines or columns to this window, and to the parent,
3601 keeping things consistent while not affecting siblings. */
3602 XSETINT (CURSIZE (parent
), opht
+ delta1
);
3603 (*setsizefun
) (window
, XINT (*sizep
) + delta1
, 0);
3605 /* Squeeze out delta1 lines or columns from our parent,
3606 shriking this window and siblings proportionately.
3607 This brings parent back to correct size.
3608 Delta1 was calculated so this makes this window the desired size,
3609 taking it all out of the siblings. */
3610 (*setsizefun
) (parent
, opht
, 0);
3615 XSETFASTINT (p
->last_modified
, 0);
3616 XSETFASTINT (p
->last_overlay_modified
, 0);
3618 /* Adjust glyph matrices. */
3619 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
3627 /***********************************************************************
3628 Resizing Mini-Windows
3629 ***********************************************************************/
3631 static void shrink_window_lowest_first
P_ ((struct window
*, int));
3633 enum save_restore_action
3640 static int save_restore_orig_size
P_ ((struct window
*,
3641 enum save_restore_action
));
3643 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
3644 from lowest windows first. */
3647 shrink_window_lowest_first (w
, height
)
3655 xassert (!MINI_WINDOW_P (w
));
3657 /* Set redisplay hints. */
3658 XSETFASTINT (w
->last_modified
, 0);
3659 XSETFASTINT (w
->last_overlay_modified
, 0);
3660 windows_or_buffers_changed
++;
3661 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
3663 old_height
= XFASTINT (w
->height
);
3664 XSETFASTINT (w
->height
, height
);
3666 if (!NILP (w
->hchild
))
3668 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
3670 c
= XWINDOW (child
);
3672 shrink_window_lowest_first (c
, height
);
3675 else if (!NILP (w
->vchild
))
3677 Lisp_Object last_child
;
3678 int delta
= old_height
- height
;
3683 /* Find the last child. We are taking space from lowest windows
3684 first, so we iterate over children from the last child
3686 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
3689 /* Assign new heights. We leave only MIN_SAFE_WINDOW_HEIGHT. */
3690 for (child
= last_child
; delta
&& !NILP (child
); child
= c
->prev
)
3694 c
= XWINDOW (child
);
3695 this_one
= XFASTINT (c
->height
) - MIN_SAFE_WINDOW_HEIGHT
;
3697 if (this_one
> delta
)
3700 shrink_window_lowest_first (c
, XFASTINT (c
->height
) - this_one
);
3704 /* Compute new positions. */
3705 last_top
= XINT (w
->top
);
3706 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
3708 c
= XWINDOW (child
);
3709 c
->top
= make_number (last_top
);
3710 shrink_window_lowest_first (c
, XFASTINT (c
->height
));
3711 last_top
+= XFASTINT (c
->height
);
3717 /* Save, restore, or check positions and sizes in the window tree
3718 rooted at W. ACTION says what to do.
3720 If ACTION is CHECK_ORIG_SIZES, check if orig_top and orig_height
3721 members are valid for all windows in the window tree. Value is
3722 non-zero if they are valid.
3724 If ACTION is SAVE_ORIG_SIZES, save members top and height in
3725 orig_top and orig_height for all windows in the tree.
3727 If ACTION is RESTORE_ORIG_SIZES, restore top and height from
3728 values stored in orig_top and orig_height for all windows. */
3731 save_restore_orig_size (w
, action
)
3733 enum save_restore_action action
;
3739 if (!NILP (w
->hchild
))
3741 if (!save_restore_orig_size (XWINDOW (w
->hchild
), action
))
3744 else if (!NILP (w
->vchild
))
3746 if (!save_restore_orig_size (XWINDOW (w
->vchild
), action
))
3752 case CHECK_ORIG_SIZES
:
3753 if (!INTEGERP (w
->orig_top
) || !INTEGERP (w
->orig_height
))
3757 case SAVE_ORIG_SIZES
:
3758 w
->orig_top
= w
->top
;
3759 w
->orig_height
= w
->height
;
3760 XSETFASTINT (w
->last_modified
, 0);
3761 XSETFASTINT (w
->last_overlay_modified
, 0);
3764 case RESTORE_ORIG_SIZES
:
3765 xassert (INTEGERP (w
->orig_top
) && INTEGERP (w
->orig_height
));
3766 w
->top
= w
->orig_top
;
3767 w
->height
= w
->orig_height
;
3768 w
->orig_height
= w
->orig_top
= Qnil
;
3769 XSETFASTINT (w
->last_modified
, 0);
3770 XSETFASTINT (w
->last_overlay_modified
, 0);
3777 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
3784 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
3785 without deleting other windows. */
3788 grow_mini_window (w
, delta
)
3792 struct frame
*f
= XFRAME (w
->frame
);
3793 struct window
*root
;
3795 xassert (MINI_WINDOW_P (w
));
3796 xassert (delta
>= 0);
3798 /* Check values of window_min_width and window_min_height for
3800 check_min_window_sizes ();
3802 /* Compute how much we can enlarge the mini-window without deleting
3804 root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3807 int min_height
= window_min_size (root
, 0, 0, 0);
3808 if (XFASTINT (root
->height
) - delta
< min_height
)
3809 /* Note that the roor window may already be smaller than
3811 delta
= max (0, XFASTINT (root
->height
) - min_height
);
3816 /* Save original window sizes and positions, if not already done. */
3817 if (!save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
3818 save_restore_orig_size (root
, SAVE_ORIG_SIZES
);
3820 /* Shrink other windows. */
3821 shrink_window_lowest_first (root
, XFASTINT (root
->height
) - delta
);
3823 /* Grow the mini-window. */
3824 w
->top
= make_number (XFASTINT (root
->top
) + XFASTINT (root
->height
));
3825 w
->height
= make_number (XFASTINT (w
->height
) + delta
);
3826 XSETFASTINT (w
->last_modified
, 0);
3827 XSETFASTINT (w
->last_overlay_modified
, 0);
3834 /* Shrink mini-window W. If there is recorded info about window sizes
3835 before a call to grow_mini_window, restore recorded window sizes.
3836 Otherwise, if the mini-window is higher than 1 line, resize it to 1
3840 shrink_mini_window (w
)
3843 struct frame
*f
= XFRAME (w
->frame
);
3844 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3846 if (save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
3848 save_restore_orig_size (root
, RESTORE_ORIG_SIZES
);
3850 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3851 windows_or_buffers_changed
= 1;
3853 else if (XFASTINT (w
->height
) > 1)
3855 /* Distribute the additional lines of the mini-window
3856 among the other windows. */
3858 XSETWINDOW (window
, w
);
3859 enlarge_window (window
, 1 - XFASTINT (w
->height
), 0);
3865 /* Mark window cursors off for all windows in the window tree rooted
3866 at W by setting their phys_cursor_on_p flag to zero. Called from
3867 xterm.c, e.g. when a frame is cleared and thereby all cursors on
3868 the frame are cleared. */
3871 mark_window_cursors_off (w
)
3876 if (!NILP (w
->hchild
))
3877 mark_window_cursors_off (XWINDOW (w
->hchild
));
3878 else if (!NILP (w
->vchild
))
3879 mark_window_cursors_off (XWINDOW (w
->vchild
));
3881 w
->phys_cursor_on_p
= 0;
3883 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3888 /* Return number of lines of text (not counting mode lines) in W. */
3891 window_internal_height (w
)
3894 int ht
= XFASTINT (w
->height
);
3896 if (!MINI_WINDOW_P (w
))
3898 if (!NILP (w
->parent
)
3899 || !NILP (w
->vchild
)
3900 || !NILP (w
->hchild
)
3903 || WINDOW_WANTS_MODELINE_P (w
))
3906 if (WINDOW_WANTS_HEADER_LINE_P (w
))
3914 /* Return the number of columns in W.
3915 Don't count columns occupied by scroll bars or the vertical bar
3916 separating W from the sibling to its right. */
3919 window_internal_width (w
)
3922 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3923 int width
= XINT (w
->width
);
3925 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3926 /* Scroll bars occupy a few columns. */
3927 width
-= FRAME_SCROLL_BAR_COLS (f
);
3928 else if (!WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
3929 /* The column of `|' characters separating side-by-side windows
3930 occupies one column only. */
3933 /* On window-systems, areas to the left and right of the window
3934 are used to display bitmaps there. */
3935 if (FRAME_WINDOW_P (f
))
3936 width
-= FRAME_FLAGS_AREA_COLS (f
);
3942 /************************************************************************
3944 ***********************************************************************/
3946 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
3947 N screen-fulls, which is defined as the height of the window minus
3948 next_screen_context_lines. If WHOLE is zero, scroll up N lines
3949 instead. Negative values of N mean scroll down. NOERROR non-zero
3950 means don't signal an error if we try to move over BEGV or ZV,
3954 window_scroll (window
, n
, whole
, noerror
)
3960 /* If we must, use the pixel-based version which is much slower than
3961 the line-based one but can handle varying line heights. */
3962 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
3963 window_scroll_pixel_based (window
, n
, whole
, noerror
);
3965 window_scroll_line_based (window
, n
, whole
, noerror
);
3969 /* Implementation of window_scroll that works based on pixel line
3970 heights. See the comment of window_scroll for parameter
3974 window_scroll_pixel_based (window
, n
, whole
, noerror
)
3981 struct window
*w
= XWINDOW (window
);
3982 struct text_pos start
;
3984 int this_scroll_margin
;
3986 /* True if we fiddled the window vscroll field without really scrolling. */
3989 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
3991 /* If PT is not visible in WINDOW, move back one half of
3992 the screen. Allow PT to be partially visible, otherwise
3993 something like (scroll-down 1) with PT in the line before
3994 the partially visible one would recenter. */
3995 tem
= Fpos_visible_in_window_p (make_number (PT
), window
, Qt
);
3998 /* Move backward half the height of the window. Performance note:
3999 vmotion used here is about 10% faster, but would give wrong
4000 results for variable height lines. */
4001 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4002 it
.current_y
= it
.last_visible_y
;
4003 move_it_vertically (&it
, - window_box_height (w
) / 2);
4005 /* The function move_iterator_vertically may move over more than
4006 the specified y-distance. If it->w is small, e.g. a
4007 mini-buffer window, we may end up in front of the window's
4008 display area. This is the case when Start displaying at the
4009 start of the line containing PT in this case. */
4010 if (it
.current_y
<= 0)
4012 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4013 move_it_vertically (&it
, 0);
4017 start
= it
.current
.pos
;
4020 /* If scroll_preserve_screen_position is non-zero, we try to set
4021 point in the same window line as it is now, so get that line. */
4022 if (!NILP (Vscroll_preserve_screen_position
))
4024 start_display (&it
, w
, start
);
4025 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4026 preserve_y
= it
.current_y
;
4031 /* Move iterator it from start the specified distance forward or
4032 backward. The result is the new window start. */
4033 start_display (&it
, w
, start
);
4036 int screen_full
= (window_box_height (w
)
4037 - next_screen_context_lines
* CANON_Y_UNIT (it
.f
));
4038 int dy
= n
* screen_full
;
4040 /* Note that move_it_vertically always moves the iterator to the
4041 start of a line. So, if the last line doesn't have a newline,
4042 we would end up at the start of the line ending at ZV. */
4044 move_it_vertically_backward (&it
, -dy
);
4046 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4047 MOVE_TO_POS
| MOVE_TO_Y
);
4050 move_it_by_lines (&it
, n
, 1);
4052 /* End if we end up at ZV or BEGV. */
4053 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4054 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4056 if (IT_CHARPOS (it
) == ZV
)
4058 if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4059 > it
.last_visible_y
)
4061 /* The last line was only partially visible, make it fully
4063 w
->vscroll
= (it
.last_visible_y
4064 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4065 adjust_glyphs (it
.f
);
4070 Fsignal (Qend_of_buffer
, Qnil
);
4074 if (w
->vscroll
!= 0)
4075 /* The first line was only partially visible, make it fully
4081 Fsignal (Qbeginning_of_buffer
, Qnil
);
4084 /* If control gets here, then we vscrolled. */
4086 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
4088 /* Don't try to change the window start below. */
4094 /* Set the window start, and set up the window for redisplay. */
4095 set_marker_restricted (w
->start
, make_number (IT_CHARPOS (it
)),
4097 w
->start_at_line_beg
= Fbolp ();
4098 w
->update_mode_line
= Qt
;
4099 XSETFASTINT (w
->last_modified
, 0);
4100 XSETFASTINT (w
->last_overlay_modified
, 0);
4101 /* Set force_start so that redisplay_window will run the
4102 window-scroll-functions. */
4103 w
->force_start
= Qt
;
4106 it
.current_y
= it
.vpos
= 0;
4108 /* Preserve the screen position if we must. */
4109 if (preserve_y
>= 0)
4111 move_it_to (&it
, -1, -1, preserve_y
, -1, MOVE_TO_Y
);
4112 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4116 /* Move PT out of scroll margins. */
4117 this_scroll_margin
= max (0, scroll_margin
);
4118 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
4119 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
4123 /* We moved the window start towards ZV, so PT may be now
4124 in the scroll margin at the top. */
4125 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4126 while (it
.current_y
< this_scroll_margin
)
4127 move_it_by_lines (&it
, 1, 1);
4128 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4132 int charpos
, bytepos
;
4134 /* We moved the window start towards BEGV, so PT may be now
4135 in the scroll margin at the bottom. */
4136 move_it_to (&it
, PT
, -1,
4137 it
.last_visible_y
- this_scroll_margin
- 1, -1,
4138 MOVE_TO_POS
| MOVE_TO_Y
);
4140 /* Save our position, in case it's correct. */
4141 charpos
= IT_CHARPOS (it
);
4142 bytepos
= IT_BYTEPOS (it
);
4144 /* See if point is on a partially visible line at the end. */
4145 move_it_by_lines (&it
, 1, 1);
4146 if (it
.current_y
> it
.last_visible_y
)
4147 /* The last line was only partially visible, so back up two
4148 lines to make sure we're on a fully visible line. */
4150 move_it_by_lines (&it
, -2, 0);
4151 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4154 /* No, the position we saved is OK, so use it. */
4155 SET_PT_BOTH (charpos
, bytepos
);
4161 /* Implementation of window_scroll that works based on screen lines.
4162 See the comment of window_scroll for parameter descriptions. */
4165 window_scroll_line_based (window
, n
, whole
, noerror
)
4171 register struct window
*w
= XWINDOW (window
);
4172 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
4173 register int pos
, pos_byte
;
4174 register int ht
= window_internal_height (w
);
4175 register Lisp_Object tem
;
4179 struct position posit
;
4182 /* If scrolling screen-fulls, compute the number of lines to
4183 scroll from the window's height. */
4185 n
*= max (1, ht
- next_screen_context_lines
);
4187 startpos
= marker_position (w
->start
);
4189 posit
= *compute_motion (startpos
, 0, 0, 0,
4191 window_internal_width (w
), XINT (w
->hscroll
),
4193 original_vpos
= posit
.vpos
;
4195 XSETFASTINT (tem
, PT
);
4196 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
4200 Fvertical_motion (make_number (- (ht
/ 2)), window
);
4205 lose
= n
< 0 && PT
== BEGV
;
4206 Fvertical_motion (make_number (n
), window
);
4210 SET_PT_BOTH (opoint
, opoint_byte
);
4217 Fsignal (Qbeginning_of_buffer
, Qnil
);
4222 int this_scroll_margin
= scroll_margin
;
4224 /* Don't use a scroll margin that is negative or too large. */
4225 if (this_scroll_margin
< 0)
4226 this_scroll_margin
= 0;
4228 if (XINT (w
->height
) < 4 * scroll_margin
)
4229 this_scroll_margin
= XINT (w
->height
) / 4;
4231 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
4232 w
->start_at_line_beg
= bolp
;
4233 w
->update_mode_line
= Qt
;
4234 XSETFASTINT (w
->last_modified
, 0);
4235 XSETFASTINT (w
->last_overlay_modified
, 0);
4236 /* Set force_start so that redisplay_window will run
4237 the window-scroll-functions. */
4238 w
->force_start
= Qt
;
4240 if (whole
&& !NILP (Vscroll_preserve_screen_position
))
4242 SET_PT_BOTH (pos
, pos_byte
);
4243 Fvertical_motion (make_number (original_vpos
), window
);
4245 /* If we scrolled forward, put point enough lines down
4246 that it is outside the scroll margin. */
4251 if (this_scroll_margin
> 0)
4253 SET_PT_BOTH (pos
, pos_byte
);
4254 Fvertical_motion (make_number (this_scroll_margin
), window
);
4260 if (top_margin
<= opoint
)
4261 SET_PT_BOTH (opoint
, opoint_byte
);
4262 else if (!NILP (Vscroll_preserve_screen_position
))
4264 SET_PT_BOTH (pos
, pos_byte
);
4265 Fvertical_motion (make_number (original_vpos
), window
);
4268 SET_PT (top_margin
);
4274 /* If we scrolled backward, put point near the end of the window
4275 but not within the scroll margin. */
4276 SET_PT_BOTH (pos
, pos_byte
);
4277 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
4278 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
4281 bottom_margin
= PT
+ 1;
4283 if (bottom_margin
> opoint
)
4284 SET_PT_BOTH (opoint
, opoint_byte
);
4287 if (!NILP (Vscroll_preserve_screen_position
))
4289 SET_PT_BOTH (pos
, pos_byte
);
4290 Fvertical_motion (make_number (original_vpos
), window
);
4293 Fvertical_motion (make_number (-1), window
);
4302 Fsignal (Qend_of_buffer
, Qnil
);
4307 /* Scroll selected_window up or down. If N is nil, scroll a
4308 screen-full which is defined as the height of the window minus
4309 next_screen_context_lines. If N is the symbol `-', scroll.
4310 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4311 up. This is the guts of Fscroll_up and Fscroll_down. */
4314 scroll_command (n
, direction
)
4318 int count
= BINDING_STACK_SIZE ();
4320 xassert (abs (direction
) == 1);
4322 /* If selected window's buffer isn't current, make it current for
4323 the moment. But don't screw up if window_scroll gets an error. */
4324 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
4326 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4327 Fset_buffer (XWINDOW (selected_window
)->buffer
);
4329 /* Make redisplay consider other windows than just selected_window. */
4330 ++windows_or_buffers_changed
;
4334 window_scroll (selected_window
, direction
, 1, 0);
4335 else if (EQ (n
, Qminus
))
4336 window_scroll (selected_window
, -direction
, 1, 0);
4339 n
= Fprefix_numeric_value (n
);
4340 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
4343 unbind_to (count
, Qnil
);
4346 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
4347 "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\
4348 A near full screen is `next-screen-context-lines' less than a full screen.\n\
4349 Negative ARG means scroll downward.\n\
4350 If ARG is the atom `-', scroll downward by nearly full screen.\n\
4351 When calling from a program, supply as argument a number, nil, or `-'.")
4355 scroll_command (arg
, 1);
4359 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
4360 "Scroll text of current window down ARG lines; or near full screen if no ARG.\n\
4361 A near full screen is `next-screen-context-lines' less than a full screen.\n\
4362 Negative ARG means scroll upward.\n\
4363 If ARG is the atom `-', scroll upward by nearly full screen.\n\
4364 When calling from a program, supply as argument a number, nil, or `-'.")
4368 scroll_command (arg
, -1);
4372 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
4373 "Return the other window for \"other window scroll\" commands.\n\
4374 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
4375 specifies the window.\n\
4376 If `other-window-scroll-buffer' is non-nil, a window\n\
4377 showing that buffer is used.")
4382 if (MINI_WINDOW_P (XWINDOW (selected_window
))
4383 && !NILP (Vminibuf_scroll_window
))
4384 window
= Vminibuf_scroll_window
;
4385 /* If buffer is specified, scroll that buffer. */
4386 else if (!NILP (Vother_window_scroll_buffer
))
4388 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
4390 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
4394 /* Nothing specified; look for a neighboring window on the same
4396 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
4398 if (EQ (window
, selected_window
))
4399 /* That didn't get us anywhere; look for a window on another
4402 window
= Fnext_window (window
, Qnil
, Qt
);
4403 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
4404 && ! EQ (window
, selected_window
));
4407 CHECK_LIVE_WINDOW (window
, 0);
4409 if (EQ (window
, selected_window
))
4410 error ("There is no other window");
4415 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
4416 "Scroll next window upward ARG lines; or near full screen if no ARG.\n\
4417 A near full screen is `next-screen-context-lines' less than a full screen.\n\
4418 The next window is the one below the current one; or the one at the top\n\
4419 if the current one is at the bottom. Negative ARG means scroll downward.\n\
4420 If ARG is the atom `-', scroll downward by nearly full screen.\n\
4421 When calling from a program, supply as argument a number, nil, or `-'.\n\
4423 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
4424 specifies the window to scroll.\n\
4425 If `other-window-scroll-buffer' is non-nil, scroll the window\n\
4426 showing that buffer, popping the buffer up if necessary.")
4432 int count
= BINDING_STACK_SIZE ();
4434 window
= Fother_window_for_scrolling ();
4435 w
= XWINDOW (window
);
4437 /* Don't screw up if window_scroll gets an error. */
4438 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4439 ++windows_or_buffers_changed
;
4441 Fset_buffer (w
->buffer
);
4442 SET_PT (marker_position (w
->pointm
));
4445 window_scroll (window
, 1, 1, 1);
4446 else if (EQ (arg
, Qminus
))
4447 window_scroll (window
, -1, 1, 1);
4452 CHECK_NUMBER (arg
, 0);
4453 window_scroll (window
, XINT (arg
), 0, 1);
4456 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
4457 unbind_to (count
, Qnil
);
4462 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 1, "P",
4463 "Scroll selected window display ARG columns left.\n\
4464 Default for ARG is window width minus 2.\n\
4465 Value is the total amount of leftward horizontal scrolling in\n\
4466 effect after the change.\n\
4467 If `automatic-hscrolling' is non-nil, the argument ARG modifies\n\
4468 a lower bound for automatic scrolling, i.e. automatic scrolling\n\
4469 will not scroll a window to a column less than the value returned\n\
4472 register Lisp_Object arg
;
4476 struct window
*w
= XWINDOW (selected_window
);
4479 XSETFASTINT (arg
, window_internal_width (w
) - 2);
4481 arg
= Fprefix_numeric_value (arg
);
4483 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
4484 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
4486 if (interactive_p (0))
4487 w
->min_hscroll
= w
->hscroll
;
4492 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 1, "P",
4493 "Scroll selected window display ARG columns right.\n\
4494 Default for ARG is window width minus 2.\n\
4495 Value is the total amount of leftward horizontal scrolling in\n\
4496 effect after the change.\n\
4497 If `automatic-hscrolling' is non-nil, the argument ARG modifies\n\
4498 a lower bound for automatic scrolling, i.e. automatic scrolling\n\
4499 will not scroll a window to a column less than the value returned\n\
4502 register Lisp_Object arg
;
4506 struct window
*w
= XWINDOW (selected_window
);
4509 XSETFASTINT (arg
, window_internal_width (w
) - 2);
4511 arg
= Fprefix_numeric_value (arg
);
4513 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
4514 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
4516 if (interactive_p (0))
4517 w
->min_hscroll
= w
->hscroll
;
4522 /* Value is the number of lines actually displayed in window W,
4523 as opposed to its height. */
4526 displayed_window_lines (w
)
4530 struct text_pos start
;
4531 int height
= window_box_height (w
);
4532 struct buffer
*old_buffer
;
4535 if (XBUFFER (w
->buffer
) != current_buffer
)
4537 old_buffer
= current_buffer
;
4538 set_buffer_internal (XBUFFER (w
->buffer
));
4543 /* In case W->start is out of the accessible range, do something
4544 reasonable. This happens in Info mode when Info-scroll-down
4545 calls (recenter -1) while W->start is 1. */
4546 if (XMARKER (w
->start
)->charpos
< BEGV
)
4547 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4548 else if (XMARKER (w
->start
)->charpos
> ZV
)
4549 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
4551 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4553 start_display (&it
, w
, start
);
4554 move_it_vertically (&it
, height
);
4555 bottom_y
= line_bottom_y (&it
);
4557 /* Add in empty lines at the bottom of the window. */
4558 if (bottom_y
< height
)
4560 int uy
= CANON_Y_UNIT (it
.f
);
4561 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
4565 set_buffer_internal (old_buffer
);
4571 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
4572 "Center point in window and redisplay frame.\n\
4573 With prefix argument ARG, recenter putting point on screen line ARG\n\
4574 relative to the current window. If ARG is negative, it counts up from the\n\
4575 bottom of the window. (ARG should be less than the height of the window.)\n\
4577 If ARG is omitted or nil, erase the entire frame and then\n\
4578 redraw with point in the center of the current window.\n\
4579 Just C-u as prefix means put point in the center of the window\n\
4580 and redisplay normally--don't erase and redraw the frame.")
4582 register Lisp_Object arg
;
4584 struct window
*w
= XWINDOW (selected_window
);
4585 struct buffer
*buf
= XBUFFER (w
->buffer
);
4586 struct buffer
*obuf
= current_buffer
;
4588 int charpos
, bytepos
;
4594 /* Invalidate pixel data calculated for all compositions. */
4595 for (i
= 0; i
< n_compositions
; i
++)
4596 composition_table
[i
]->font
= NULL
;
4598 Fredraw_frame (w
->frame
);
4599 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
4602 else if (CONSP (arg
)) /* Just C-u. */
4606 arg
= Fprefix_numeric_value (arg
);
4607 CHECK_NUMBER (arg
, 0);
4610 set_buffer_internal (buf
);
4612 /* Handle centering on a graphical frame specially. Such frames can
4613 have variable-height lines and centering point on the basis of
4614 line counts would lead to strange effects. */
4615 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
4622 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
4623 start_display (&it
, w
, pt
);
4624 move_it_vertically (&it
, - window_box_height (w
) / 2);
4625 charpos
= IT_CHARPOS (it
);
4626 bytepos
= IT_BYTEPOS (it
);
4628 else if (XINT (arg
) < 0)
4632 int y0
, y1
, h
, nlines
;
4634 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
4635 start_display (&it
, w
, pt
);
4638 /* The amount of pixels we have to move back is the window
4639 height minus what's displayed in the line containing PT,
4640 and the lines below. */
4641 nlines
= - XINT (arg
) - 1;
4642 move_it_by_lines (&it
, nlines
, 1);
4644 y1
= line_bottom_y (&it
);
4646 /* If we can't move down NLINES lines because we hit
4647 the end of the buffer, count in some empty lines. */
4648 if (it
.vpos
< nlines
)
4649 y1
+= (nlines
- it
.vpos
) * CANON_Y_UNIT (it
.f
);
4651 h
= window_box_height (w
) - (y1
- y0
);
4653 start_display (&it
, w
, pt
);
4654 move_it_vertically (&it
, - h
);
4655 charpos
= IT_CHARPOS (it
);
4656 bytepos
= IT_BYTEPOS (it
);
4660 struct position pos
;
4661 pos
= *vmotion (PT
, - XINT (arg
), w
);
4662 charpos
= pos
.bufpos
;
4663 bytepos
= pos
.bytepos
;
4668 struct position pos
;
4669 int ht
= window_internal_height (w
);
4672 arg
= make_number (ht
/ 2);
4673 else if (XINT (arg
) < 0)
4674 arg
= make_number (XINT (arg
) + ht
);
4676 pos
= *vmotion (PT
, - XINT (arg
), w
);
4677 charpos
= pos
.bufpos
;
4678 bytepos
= pos
.bytepos
;
4681 /* Set the new window start. */
4682 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
4683 w
->window_end_valid
= Qnil
;
4684 w
->force_start
= Qt
;
4685 if (bytepos
== BEGV_BYTE
|| FETCH_BYTE (bytepos
- 1) == '\n')
4686 w
->start_at_line_beg
= Qt
;
4688 w
->start_at_line_beg
= Qnil
;
4690 set_buffer_internal (obuf
);
4695 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
4697 "Return the height in lines of the text display area of WINDOW.\n\
4698 This doesn't include the mode-line (or header-line if any) or any\n\
4699 partial-height lines in the text display area.")
4703 struct window
*w
= decode_window (window
);
4704 int pixel_height
= window_box_height (w
);
4705 int line_height
= pixel_height
/ CANON_Y_UNIT (XFRAME (w
->frame
));
4706 return make_number (line_height
);
4711 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
4713 "Position point relative to window.\n\
4714 With no argument, position point at center of window.\n\
4715 An argument specifies vertical position within the window;\n\
4716 zero means top of window, negative means relative to bottom of window.")
4720 struct window
*w
= XWINDOW (selected_window
);
4724 window
= selected_window
;
4725 start
= marker_position (w
->start
);
4726 if (start
< BEGV
|| start
> ZV
)
4728 int height
= window_internal_height (w
);
4729 Fvertical_motion (make_number (- (height
/ 2)), window
);
4730 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
4731 w
->start_at_line_beg
= Fbolp ();
4732 w
->force_start
= Qt
;
4735 Fgoto_char (w
->start
);
4737 lines
= displayed_window_lines (w
);
4739 XSETFASTINT (arg
, lines
/ 2);
4742 arg
= Fprefix_numeric_value (arg
);
4744 XSETINT (arg
, XINT (arg
) + lines
);
4747 /* Skip past a partially visible first line. */
4749 XSETINT (arg
, XINT (arg
) + 1);
4751 return Fvertical_motion (arg
, window
);
4756 /***********************************************************************
4757 Window Configuration
4758 ***********************************************************************/
4760 struct save_window_data
4762 EMACS_INT size_from_Lisp_Vector_struct
;
4763 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
4764 Lisp_Object frame_width
, frame_height
, frame_menu_bar_lines
;
4765 Lisp_Object frame_tool_bar_lines
;
4766 Lisp_Object selected_frame
;
4767 Lisp_Object current_window
;
4768 Lisp_Object current_buffer
;
4769 Lisp_Object minibuf_scroll_window
;
4770 Lisp_Object root_window
;
4771 Lisp_Object focus_frame
;
4772 /* Record the values of window-min-width and window-min-height
4773 so that window sizes remain consistent with them. */
4774 Lisp_Object min_width
, min_height
;
4775 /* A vector, each of whose elements is a struct saved_window
4777 Lisp_Object saved_windows
;
4780 /* This is saved as a Lisp_Vector */
4783 /* these first two must agree with struct Lisp_Vector in lisp.h */
4784 EMACS_INT size_from_Lisp_Vector_struct
;
4785 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
4788 Lisp_Object buffer
, start
, pointm
, mark
;
4789 Lisp_Object left
, top
, width
, height
, hscroll
, min_hscroll
;
4790 Lisp_Object parent
, prev
;
4791 Lisp_Object start_at_line_beg
;
4792 Lisp_Object display_table
;
4793 Lisp_Object orig_top
, orig_height
;
4796 #define SAVED_WINDOW_VECTOR_SIZE 17 /* Arg to Fmake_vector */
4798 #define SAVED_WINDOW_N(swv,n) \
4799 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
4801 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
4802 "Return t if OBJECT is a window-configuration object.")
4806 if (WINDOW_CONFIGURATIONP (object
))
4811 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
4812 "Return the frame that CONFIG, a window-configuration object, is about.")
4816 register struct save_window_data
*data
;
4817 struct Lisp_Vector
*saved_windows
;
4819 if (! WINDOW_CONFIGURATIONP (config
))
4820 wrong_type_argument (Qwindow_configuration_p
, config
);
4822 data
= (struct save_window_data
*) XVECTOR (config
);
4823 saved_windows
= XVECTOR (data
->saved_windows
);
4824 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
4827 DEFUN ("set-window-configuration", Fset_window_configuration
,
4828 Sset_window_configuration
, 1, 1, 0,
4829 "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\
4830 CONFIGURATION must be a value previously returned\n\
4831 by `current-window-configuration' (which see).\n\
4832 If CONFIGURATION was made from a frame that is now deleted,\n\
4833 only frame-independent values can be restored. In this case,\n\
4834 the return value is nil. Otherwise the value is t.")
4836 Lisp_Object configuration
;
4838 register struct save_window_data
*data
;
4839 struct Lisp_Vector
*saved_windows
;
4840 Lisp_Object new_current_buffer
;
4845 while (!WINDOW_CONFIGURATIONP (configuration
))
4846 wrong_type_argument (Qwindow_configuration_p
, configuration
);
4848 data
= (struct save_window_data
*) XVECTOR (configuration
);
4849 saved_windows
= XVECTOR (data
->saved_windows
);
4851 new_current_buffer
= data
->current_buffer
;
4852 if (NILP (XBUFFER (new_current_buffer
)->name
))
4853 new_current_buffer
= Qnil
;
4856 if (XBUFFER (new_current_buffer
) == current_buffer
)
4860 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
4863 /* If f is a dead frame, don't bother rebuilding its window tree.
4864 However, there is other stuff we should still try to do below. */
4865 if (FRAME_LIVE_P (f
))
4867 register struct window
*w
;
4868 register struct saved_window
*p
;
4869 struct window
*root_window
;
4870 struct window
**leaf_windows
;
4874 /* If the frame has been resized since this window configuration was
4875 made, we change the frame to the size specified in the
4876 configuration, restore the configuration, and then resize it
4877 back. We keep track of the prevailing height in these variables. */
4878 int previous_frame_height
= FRAME_HEIGHT (f
);
4879 int previous_frame_width
= FRAME_WIDTH (f
);
4880 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
4881 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
4883 /* The mouse highlighting code could get screwed up
4884 if it runs during this. */
4887 if (XFASTINT (data
->frame_height
) != previous_frame_height
4888 || XFASTINT (data
->frame_width
) != previous_frame_width
)
4889 change_frame_size (f
, XFASTINT (data
->frame_height
),
4890 XFASTINT (data
->frame_width
), 0, 0, 0);
4891 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
4892 if (XFASTINT (data
->frame_menu_bar_lines
)
4893 != previous_frame_menu_bar_lines
)
4894 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, make_number (0));
4895 #ifdef HAVE_WINDOW_SYSTEM
4896 if (XFASTINT (data
->frame_tool_bar_lines
)
4897 != previous_frame_tool_bar_lines
)
4898 x_set_tool_bar_lines (f
, data
->frame_tool_bar_lines
, make_number (0));
4902 /* "Swap out" point from the selected window
4903 into its buffer. We do this now, before
4904 restoring the window contents, and prevent it from
4905 being done later on when we select a new window. */
4906 if (! NILP (XWINDOW (selected_window
)->buffer
))
4908 w
= XWINDOW (selected_window
);
4909 set_marker_both (w
->pointm
,
4911 BUF_PT (XBUFFER (w
->buffer
)),
4912 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
4915 windows_or_buffers_changed
++;
4916 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4918 /* Problem: Freeing all matrices and later allocating them again
4919 is a serious redisplay flickering problem. What we would
4920 really like to do is to free only those matrices not reused
4922 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4924 = (struct window
**) alloca (count_windows (root_window
)
4925 * sizeof (struct window
*));
4926 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
4928 /* Temporarily avoid any problems with windows that are smaller
4929 than they are supposed to be. */
4930 window_min_height
= 1;
4931 window_min_width
= 1;
4934 Mark all windows now on frame as "deleted".
4935 Restoring the new configuration "undeletes" any that are in it.
4937 Save their current buffers in their height fields, since we may
4938 need it later, if a buffer saved in the configuration is now
4940 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4942 for (k
= 0; k
< saved_windows
->size
; k
++)
4944 p
= SAVED_WINDOW_N (saved_windows
, k
);
4945 w
= XWINDOW (p
->window
);
4948 if (!NILP (p
->parent
))
4949 w
->parent
= SAVED_WINDOW_N (saved_windows
,
4950 XFASTINT (p
->parent
))->window
;
4954 if (!NILP (p
->prev
))
4956 w
->prev
= SAVED_WINDOW_N (saved_windows
,
4957 XFASTINT (p
->prev
))->window
;
4958 XWINDOW (w
->prev
)->next
= p
->window
;
4963 if (!NILP (w
->parent
))
4965 if (EQ (p
->width
, XWINDOW (w
->parent
)->width
))
4967 XWINDOW (w
->parent
)->vchild
= p
->window
;
4968 XWINDOW (w
->parent
)->hchild
= Qnil
;
4972 XWINDOW (w
->parent
)->hchild
= p
->window
;
4973 XWINDOW (w
->parent
)->vchild
= Qnil
;
4978 /* If we squirreled away the buffer in the window's height,
4980 if (BUFFERP (w
->height
))
4981 w
->buffer
= w
->height
;
4984 w
->width
= p
->width
;
4985 w
->height
= p
->height
;
4986 w
->hscroll
= p
->hscroll
;
4987 w
->min_hscroll
= p
->min_hscroll
;
4988 w
->display_table
= p
->display_table
;
4989 w
->orig_top
= p
->orig_top
;
4990 w
->orig_height
= p
->orig_height
;
4991 XSETFASTINT (w
->last_modified
, 0);
4992 XSETFASTINT (w
->last_overlay_modified
, 0);
4994 /* Reinstall the saved buffer and pointers into it. */
4995 if (NILP (p
->buffer
))
4996 w
->buffer
= p
->buffer
;
4999 if (!NILP (XBUFFER (p
->buffer
)->name
))
5000 /* If saved buffer is alive, install it. */
5002 w
->buffer
= p
->buffer
;
5003 w
->start_at_line_beg
= p
->start_at_line_beg
;
5004 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
5005 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
5006 Fset_marker (XBUFFER (w
->buffer
)->mark
,
5007 p
->mark
, w
->buffer
);
5009 /* As documented in Fcurrent_window_configuration, don't
5010 save the location of point in the buffer which was current
5011 when the window configuration was recorded. */
5012 if (!EQ (p
->buffer
, new_current_buffer
)
5013 && XBUFFER (p
->buffer
) == current_buffer
)
5014 Fgoto_char (w
->pointm
);
5016 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
5017 /* Else unless window has a live buffer, get one. */
5019 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
5020 /* This will set the markers to beginning of visible
5022 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
5023 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
5024 w
->start_at_line_beg
= Qt
;
5027 /* Keeping window's old buffer; make sure the markers
5030 /* Set window markers at start of visible range. */
5031 if (XMARKER (w
->start
)->buffer
== 0)
5032 set_marker_restricted (w
->start
, make_number (0),
5034 if (XMARKER (w
->pointm
)->buffer
== 0)
5035 set_marker_restricted_both (w
->pointm
, w
->buffer
,
5036 BUF_PT (XBUFFER (w
->buffer
)),
5037 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5038 w
->start_at_line_beg
= Qt
;
5043 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
5044 /* Prevent "swapping out point" in the old selected window
5045 using the buffer that has been restored into it.
5046 That swapping out has already been done,
5047 near the beginning of this function. */
5048 selected_window
= Qnil
;
5049 Fselect_window (data
->current_window
);
5050 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
5053 if (NILP (data
->focus_frame
)
5054 || (FRAMEP (data
->focus_frame
)
5055 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
5056 Fredirect_frame_focus (frame
, data
->focus_frame
);
5058 #if 0 /* I don't understand why this is needed, and it causes problems
5059 when the frame's old selected window has been deleted. */
5060 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
5061 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
5065 /* Set the screen height to the value it had before this function. */
5066 if (previous_frame_height
!= FRAME_HEIGHT (f
)
5067 || previous_frame_width
!= FRAME_WIDTH (f
))
5068 change_frame_size (f
, previous_frame_height
, previous_frame_width
,
5070 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5071 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
5072 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
5074 #ifdef HAVE_WINDOW_SYSTEM
5075 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
5076 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
5081 /* Now, free glyph matrices in windows that were not reused. */
5082 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
5084 if (NILP (leaf_windows
[i
]->buffer
))
5086 /* Assert it's not reused as a combination. */
5087 xassert (NILP (leaf_windows
[i
]->hchild
)
5088 && NILP (leaf_windows
[i
]->vchild
));
5089 free_window_matrices (leaf_windows
[i
]);
5091 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
5095 /* If more than one window shows the new and old current buffer,
5096 don't try to preserve point in that buffer. */
5097 if (old_point
> 0 && n
> 1)
5104 /* Fselect_window will have made f the selected frame, so we
5105 reselect the proper frame here. Fhandle_switch_frame will change the
5106 selected window too, but that doesn't make the call to
5107 Fselect_window above totally superfluous; it still sets f's
5109 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
5110 do_switch_frame (data
->selected_frame
, 0, 0);
5112 if (! NILP (Vwindow_configuration_change_hook
)
5113 && ! NILP (Vrun_hooks
))
5114 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
5117 if (!NILP (new_current_buffer
))
5119 Fset_buffer (new_current_buffer
);
5121 /* If the buffer that is current now is the same
5122 that was current before setting the window configuration,
5123 don't alter its PT. */
5128 /* Restore the minimum heights recorded in the configuration. */
5129 window_min_height
= XINT (data
->min_height
);
5130 window_min_width
= XINT (data
->min_width
);
5132 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
5134 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
5137 /* Mark all windows now on frame as deleted
5138 by setting their buffers to nil. */
5141 delete_all_subwindows (w
)
5142 register struct window
*w
;
5144 if (!NILP (w
->next
))
5145 delete_all_subwindows (XWINDOW (w
->next
));
5146 if (!NILP (w
->vchild
))
5147 delete_all_subwindows (XWINDOW (w
->vchild
));
5148 if (!NILP (w
->hchild
))
5149 delete_all_subwindows (XWINDOW (w
->hchild
));
5151 w
->height
= w
->buffer
; /* See Fset_window_configuration for excuse. */
5153 if (!NILP (w
->buffer
))
5156 /* We set all three of these fields to nil, to make sure that we can
5157 distinguish this dead window from any live window. Live leaf
5158 windows will have buffer set, and combination windows will have
5159 vchild or hchild set. */
5164 Vwindow_list
= Qnil
;
5168 count_windows (window
)
5169 register struct window
*window
;
5171 register int count
= 1;
5172 if (!NILP (window
->next
))
5173 count
+= count_windows (XWINDOW (window
->next
));
5174 if (!NILP (window
->vchild
))
5175 count
+= count_windows (XWINDOW (window
->vchild
));
5176 if (!NILP (window
->hchild
))
5177 count
+= count_windows (XWINDOW (window
->hchild
));
5182 /* Fill vector FLAT with leaf windows under W, starting at index I.
5183 Value is last index + 1. */
5186 get_leaf_windows (w
, flat
, i
)
5188 struct window
**flat
;
5193 if (!NILP (w
->hchild
))
5194 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
5195 else if (!NILP (w
->vchild
))
5196 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
5200 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5207 /* Return a pointer to the glyph W's physical cursor is on. Value is
5208 null if W's current matrix is invalid, so that no meaningfull glyph
5212 get_phys_cursor_glyph (w
)
5215 struct glyph_row
*row
;
5216 struct glyph
*glyph
;
5218 if (w
->phys_cursor
.vpos
>= 0
5219 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
5220 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
5222 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
5223 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
5232 save_window_save (window
, vector
, i
)
5234 struct Lisp_Vector
*vector
;
5237 register struct saved_window
*p
;
5238 register struct window
*w
;
5239 register Lisp_Object tem
;
5241 for (;!NILP (window
); window
= w
->next
)
5243 p
= SAVED_WINDOW_N (vector
, i
);
5244 w
= XWINDOW (window
);
5246 XSETFASTINT (w
->temslot
, i
++);
5248 p
->buffer
= w
->buffer
;
5251 p
->width
= w
->width
;
5252 p
->height
= w
->height
;
5253 p
->hscroll
= w
->hscroll
;
5254 p
->min_hscroll
= w
->min_hscroll
;
5255 p
->display_table
= w
->display_table
;
5256 p
->orig_top
= w
->orig_top
;
5257 p
->orig_height
= w
->orig_height
;
5258 if (!NILP (w
->buffer
))
5260 /* Save w's value of point in the window configuration.
5261 If w is the selected window, then get the value of point
5262 from the buffer; pointm is garbage in the selected window. */
5263 if (EQ (window
, selected_window
))
5265 p
->pointm
= Fmake_marker ();
5266 set_marker_both (p
->pointm
, w
->buffer
,
5267 BUF_PT (XBUFFER (w
->buffer
)),
5268 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5271 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
5273 p
->start
= Fcopy_marker (w
->start
, Qnil
);
5274 p
->start_at_line_beg
= w
->start_at_line_beg
;
5276 tem
= XBUFFER (w
->buffer
)->mark
;
5277 p
->mark
= Fcopy_marker (tem
, Qnil
);
5284 p
->start_at_line_beg
= Qnil
;
5287 if (NILP (w
->parent
))
5290 p
->parent
= XWINDOW (w
->parent
)->temslot
;
5295 p
->prev
= XWINDOW (w
->prev
)->temslot
;
5297 if (!NILP (w
->vchild
))
5298 i
= save_window_save (w
->vchild
, vector
, i
);
5299 if (!NILP (w
->hchild
))
5300 i
= save_window_save (w
->hchild
, vector
, i
);
5306 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
5307 Scurrent_window_configuration
, 0, 1, 0,
5308 "Return an object representing the current window configuration of FRAME.\n\
5309 If FRAME is nil or omitted, use the selected frame.\n\
5310 This describes the number of windows, their sizes and current buffers,\n\
5311 and for each displayed buffer, where display starts, and the positions of\n\
5312 point and mark. An exception is made for point in the current buffer:\n\
5313 its value is -not- saved.\n\
5314 This also records the currently selected frame, and FRAME's focus\n\
5315 redirection (see `redirect-frame-focus').")
5319 register Lisp_Object tem
;
5320 register int n_windows
;
5321 register struct save_window_data
*data
;
5322 register struct Lisp_Vector
*vec
;
5327 frame
= selected_frame
;
5328 CHECK_LIVE_FRAME (frame
, 0);
5331 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5332 vec
= allocate_other_vector (VECSIZE (struct save_window_data
));
5333 data
= (struct save_window_data
*)vec
;
5335 XSETFASTINT (data
->frame_width
, FRAME_WIDTH (f
));
5336 XSETFASTINT (data
->frame_height
, FRAME_HEIGHT (f
));
5337 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
5338 XSETFASTINT (data
->frame_tool_bar_lines
, FRAME_TOOL_BAR_LINES (f
));
5339 data
->selected_frame
= selected_frame
;
5340 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
5341 XSETBUFFER (data
->current_buffer
, current_buffer
);
5342 data
->minibuf_scroll_window
= Vminibuf_scroll_window
;
5343 data
->root_window
= FRAME_ROOT_WINDOW (f
);
5344 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
5345 XSETINT (data
->min_height
, window_min_height
);
5346 XSETINT (data
->min_width
, window_min_width
);
5347 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
5348 data
->saved_windows
= tem
;
5349 for (i
= 0; i
< n_windows
; i
++)
5350 XVECTOR (tem
)->contents
[i
]
5351 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
5352 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
5353 XSETWINDOW_CONFIGURATION (tem
, data
);
5357 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
5359 "Execute body, preserving window sizes and contents.\n\
5360 Restore which buffer appears in which window, where display starts,\n\
5361 and the value of point and mark for each window.\n\
5362 Also restore the choice of selected window.\n\
5363 Also restore which buffer is current.\n\
5364 Does not restore the value of point in current buffer.")
5368 register Lisp_Object val
;
5369 register int count
= specpdl_ptr
- specpdl
;
5371 record_unwind_protect (Fset_window_configuration
,
5372 Fcurrent_window_configuration (Qnil
));
5373 val
= Fprogn (args
);
5374 return unbind_to (count
, val
);
5378 /***********************************************************************
5380 ***********************************************************************/
5382 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
5384 "Set width of marginal areas of window WINDOW.\n\
5385 If window is nil, set margins of the currently selected window.\n\
5386 First parameter LEFT-WIDTH specifies the number of character\n\
5387 cells to reserve for the left marginal area. Second parameter\n\
5388 RIGHT-WIDTH does the same for the right marginal area.\n\
5389 A nil width parameter means no margin.")
5390 (window
, left
, right
)
5391 Lisp_Object window
, left
, right
;
5393 struct window
*w
= decode_window (window
);
5396 CHECK_NUMBER_OR_FLOAT (left
, 1);
5398 CHECK_NUMBER_OR_FLOAT (right
, 2);
5400 /* Check widths < 0 and translate a zero width to nil.
5401 Margins that are too wide have to be checked elsewhere. */
5402 if ((INTEGERP (left
) && XINT (left
) < 0)
5403 || (FLOATP (left
) && XFLOAT_DATA (left
) <= 0))
5404 XSETFASTINT (left
, 0);
5405 if (INTEGERP (left
) && XFASTINT (left
) == 0)
5408 if ((INTEGERP (right
) && XINT (right
) < 0)
5409 || (FLOATP (right
) && XFLOAT_DATA (right
) <= 0))
5410 XSETFASTINT (right
, 0);
5411 if (INTEGERP (right
) && XFASTINT (right
) == 0)
5414 w
->left_margin_width
= left
;
5415 w
->right_margin_width
= right
;
5417 ++windows_or_buffers_changed
;
5418 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
5423 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
5425 "Get width of marginal areas of window WINDOW.\n\
5426 If WINDOW is omitted or nil, use the currently selected window.\n\
5427 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).\n\
5428 If a marginal area does not exist, its width will be returned\n\
5433 struct window
*w
= decode_window (window
);
5434 return Fcons (w
->left_margin_width
, w
->right_margin_width
);
5439 /***********************************************************************
5441 ***********************************************************************/
5443 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 1, 0,
5444 "Return the amount by which WINDOW is scrolled vertically.\n\
5445 Use the selected window if WINDOW is nil or omitted.\n\
5446 Value is a multiple of the canonical character height of WINDOW.")
5455 window
= selected_window
;
5457 CHECK_WINDOW (window
, 0);
5458 w
= XWINDOW (window
);
5459 f
= XFRAME (w
->frame
);
5461 if (FRAME_WINDOW_P (f
))
5462 result
= CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
);
5464 result
= make_number (0);
5469 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
5471 "Set amount by which WINDOW should be scrolled vertically to VSCROLL.\n\
5472 WINDOW nil means use the selected window. VSCROLL is a non-negative\n\
5473 multiple of the canonical character height of WINDOW.")
5475 Lisp_Object window
, vscroll
;
5481 window
= selected_window
;
5483 CHECK_WINDOW (window
, 0);
5484 CHECK_NUMBER_OR_FLOAT (vscroll
, 1);
5486 w
= XWINDOW (window
);
5487 f
= XFRAME (w
->frame
);
5489 if (FRAME_WINDOW_P (f
))
5491 int old_dy
= w
->vscroll
;
5493 w
->vscroll
= - CANON_Y_UNIT (f
) * XFLOATINT (vscroll
);
5494 w
->vscroll
= min (w
->vscroll
, 0);
5496 /* Adjust glyph matrix of the frame if the virtual display
5497 area becomes larger than before. */
5498 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
5501 /* Prevent redisplay shortcuts. */
5502 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
5505 return Fwindow_vscroll (window
);
5509 /* Call FN for all leaf windows on frame F. FN is called with the
5510 first argument being a pointer to the leaf window, and with
5511 additional argument USER_DATA. Stops when FN returns 0. */
5514 foreach_window (f
, fn
, user_data
)
5516 int (* fn
) P_ ((struct window
*, void *));
5519 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
5523 /* Helper function for foreach_window. Call FN for all leaf windows
5524 reachable from W. FN is called with the first argument being a
5525 pointer to the leaf window, and with additional argument USER_DATA.
5526 Stop when FN returns 0. Value is 0 if stopped by FN. */
5529 foreach_window_1 (w
, fn
, user_data
)
5531 int (* fn
) P_ ((struct window
*, void *));
5536 for (cont
= 1; w
&& cont
;)
5538 if (!NILP (w
->hchild
))
5539 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
5540 else if (!NILP (w
->vchild
))
5541 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
5543 cont
= fn (w
, user_data
);
5545 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5552 /* Freeze or unfreeze the window start of W if unless it is a
5553 mini-window or the selected window. FREEZE_P non-null means freeze
5554 the window start. */
5557 freeze_window_start (w
, freeze_p
)
5561 if (w
== XWINDOW (selected_window
)
5562 || MINI_WINDOW_P (w
)
5563 || (MINI_WINDOW_P (XWINDOW (selected_window
))
5564 && ! NILP (Vminibuf_scroll_window
)
5565 && w
== XWINDOW (Vminibuf_scroll_window
)))
5568 w
->frozen_window_start_p
= freeze_p
!= NULL
;
5573 /* Freeze or unfreeze the window starts of all leaf windows on frame
5574 F, except the selected window and a mini-window. FREEZE_P non-zero
5575 means freeze the window start. */
5578 freeze_window_starts (f
, freeze_p
)
5582 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
5586 /***********************************************************************
5588 ***********************************************************************/
5590 /* Return 1 if window configurations C1 and C2
5591 describe the same state of affairs. This is used by Fequal. */
5594 compare_window_configurations (c1
, c2
, ignore_positions
)
5596 int ignore_positions
;
5598 register struct save_window_data
*d1
, *d2
;
5599 struct Lisp_Vector
*sw1
, *sw2
;
5602 if (!WINDOW_CONFIGURATIONP (c1
))
5603 wrong_type_argument (Qwindow_configuration_p
, c1
);
5604 if (!WINDOW_CONFIGURATIONP (c2
))
5605 wrong_type_argument (Qwindow_configuration_p
, c2
);
5607 d1
= (struct save_window_data
*) XVECTOR (c1
);
5608 d2
= (struct save_window_data
*) XVECTOR (c2
);
5609 sw1
= XVECTOR (d1
->saved_windows
);
5610 sw2
= XVECTOR (d2
->saved_windows
);
5612 if (! EQ (d1
->frame_width
, d2
->frame_width
))
5614 if (! EQ (d1
->frame_height
, d2
->frame_height
))
5616 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
5618 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
5620 /* Don't compare the current_window field directly.
5621 Instead see w1_is_current and w2_is_current, below. */
5622 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
5624 if (! ignore_positions
)
5625 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
5627 /* Don't compare the root_window field.
5628 We don't require the two configurations
5629 to use the same window object,
5630 and the two root windows must be equivalent
5631 if everything else compares equal. */
5632 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
5634 if (! EQ (d1
->min_width
, d2
->min_width
))
5636 if (! EQ (d1
->min_height
, d2
->min_height
))
5639 /* Verify that the two confis have the same number of windows. */
5640 if (sw1
->size
!= sw2
->size
)
5643 for (i
= 0; i
< sw1
->size
; i
++)
5645 struct saved_window
*p1
, *p2
;
5646 int w1_is_current
, w2_is_current
;
5648 p1
= SAVED_WINDOW_N (sw1
, i
);
5649 p2
= SAVED_WINDOW_N (sw2
, i
);
5651 /* Verify that the current windows in the two
5652 configurations correspond to each other. */
5653 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
5654 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
5656 if (w1_is_current
!= w2_is_current
)
5659 /* Verify that the corresponding windows do match. */
5660 if (! EQ (p1
->buffer
, p2
->buffer
))
5662 if (! EQ (p1
->left
, p2
->left
))
5664 if (! EQ (p1
->top
, p2
->top
))
5666 if (! EQ (p1
->width
, p2
->width
))
5668 if (! EQ (p1
->height
, p2
->height
))
5670 if (! EQ (p1
->display_table
, p2
->display_table
))
5672 if (! EQ (p1
->parent
, p2
->parent
))
5674 if (! EQ (p1
->prev
, p2
->prev
))
5676 if (! ignore_positions
)
5678 if (! EQ (p1
->hscroll
, p2
->hscroll
))
5680 if (!EQ (p1
->min_hscroll
, p2
->min_hscroll
))
5682 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
5684 if (NILP (Fequal (p1
->start
, p2
->start
)))
5686 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
5688 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
5696 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
5697 Scompare_window_configurations
, 2, 2, 0,
5698 "Compare two window configurations as regards the structure of windows.\n\
5699 This function ignores details such as the values of point and mark\n\
5700 and scrolling positions.")
5704 if (compare_window_configurations (x
, y
, 1))
5712 struct frame
*f
= make_terminal_frame ();
5713 XSETFRAME (selected_frame
, f
);
5714 Vterminal_frame
= selected_frame
;
5715 minibuf_window
= f
->minibuffer_window
;
5716 selected_window
= f
->selected_window
;
5717 last_nonminibuf_frame
= f
;
5719 window_initialized
= 1;
5725 Vwindow_list
= Qnil
;
5731 Qleft_fringe
= intern ("left-fringe");
5732 staticpro (&Qleft_fringe
);
5733 Qright_fringe
= intern ("right-fringe");
5734 staticpro (&Qright_fringe
);
5736 Qwindow_size_fixed
= intern ("window-size-fixed");
5737 staticpro (&Qwindow_size_fixed
);
5739 staticpro (&Qwindow_configuration_change_hook
);
5740 Qwindow_configuration_change_hook
5741 = intern ("window-configuration-change-hook");
5743 Qwindowp
= intern ("windowp");
5744 staticpro (&Qwindowp
);
5746 Qwindow_configuration_p
= intern ("window-configuration-p");
5747 staticpro (&Qwindow_configuration_p
);
5749 Qwindow_live_p
= intern ("window-live-p");
5750 staticpro (&Qwindow_live_p
);
5752 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
5753 staticpro (&Qtemp_buffer_show_hook
);
5755 staticpro (&Vwindow_list
);
5757 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
5758 "Non-nil means call as function to display a help buffer.\n\
5759 The function is called with one argument, the buffer to be displayed.\n\
5760 Used by `with-output-to-temp-buffer'.\n\
5761 If this function is used, then it must do the entire job of showing\n\
5762 the buffer; `temp-buffer-show-hook' is not run unless this function runs it.");
5763 Vtemp_buffer_show_function
= Qnil
;
5765 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
5766 "If non-nil, function to call to handle `display-buffer'.\n\
5767 It will receive two args, the buffer and a flag which if non-nil means\n\
5768 that the currently selected window is not acceptable.\n\
5769 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\
5770 work using this function.");
5771 Vdisplay_buffer_function
= Qnil
;
5773 DEFVAR_LISP ("even-window-heights", &Veven_window_heights
,
5774 "*If non-nil, `display-buffer' should even the window heights.\n\
5775 If nil, `display-buffer' will leave the window configuration alone.");
5776 Veven_window_heights
= Qt
;
5778 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
5779 "Non-nil means it is the window that C-M-v in minibuffer should scroll.");
5780 Vminibuf_scroll_window
= Qnil
;
5782 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
5783 "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.");
5784 Vother_window_scroll_buffer
= Qnil
;
5786 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
5787 "*Non-nil means `display-buffer' should make a separate frame.");
5790 DEFVAR_BOOL ("display-buffer-reuse-frames", &display_buffer_reuse_frames
,
5791 "*Non-nil means `display-buffer' should reuse frames.\n\
5792 If the buffer in question is already displayed in a frame, raise that frame.");
5793 display_buffer_reuse_frames
= 0;
5795 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
5796 "Function to call to handle automatic new frame creation.\n\
5797 It is called with no arguments and should return a newly created frame.\n\
5799 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\
5800 where `pop-up-frame-alist' would hold the default frame parameters.");
5801 Vpop_up_frame_function
= Qnil
;
5803 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
5804 "*List of buffer names that should have their own special frames.\n\
5805 Displaying a buffer whose name is in this list makes a special frame for it\n\
5806 using `special-display-function'. See also `special-display-regexps'.\n\
5808 An element of the list can be a list instead of just a string.\n\
5809 There are two ways to use a list as an element:\n\
5810 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)\n\
5811 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
5812 In the latter case, FUNCTION is called with BUFFER as the first argument,\n\
5813 followed by OTHER-ARGS--it can display BUFFER in any way it likes.\n\
5814 All this is done by the function found in `special-display-function'.\n\
5816 If this variable appears \"not to work\", because you add a name to it\n\
5817 but that buffer still appears in the selected window, look at the\n\
5818 values of `same-window-buffer-names' and `same-window-regexps'.\n\
5819 Those variables take precedence over this one.");
5820 Vspecial_display_buffer_names
= Qnil
;
5822 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
5823 "*List of regexps saying which buffers should have their own special frames.\n\
5824 If a buffer name matches one of these regexps, it gets its own frame.\n\
5825 Displaying a buffer whose name is in this list makes a special frame for it\n\
5826 using `special-display-function'.\n\
5828 An element of the list can be a list instead of just a string.\n\
5829 There are two ways to use a list as an element:\n\
5830 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)\n\
5831 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
5832 In the latter case, FUNCTION is called with the buffer as first argument,\n\
5833 followed by OTHER-ARGS--it can display the buffer in any way it likes.\n\
5834 All this is done by the function found in `special-display-function'.\n\
5836 If this variable appears \"not to work\", because you add a regexp to it\n\
5837 but the matching buffers still appear in the selected window, look at the\n\
5838 values of `same-window-buffer-names' and `same-window-regexps'.\n\
5839 Those variables take precedence over this one.");
5840 Vspecial_display_regexps
= Qnil
;
5842 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
5843 "Function to call to make a new frame for a special buffer.\n\
5844 It is called with two arguments, the buffer and optional buffer specific\n\
5845 data, and should return a window displaying that buffer.\n\
5846 The default value makes a separate frame for the buffer,\n\
5847 using `special-display-frame-alist' to specify the frame parameters.\n\
5849 A buffer is special if its is listed in `special-display-buffer-names'\n\
5850 or matches a regexp in `special-display-regexps'.");
5851 Vspecial_display_function
= Qnil
;
5853 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
5854 "*List of buffer names that should appear in the selected window.\n\
5855 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'\n\
5856 switches to it in the selected window, rather than making it appear\n\
5857 in some other window.\n\
5859 An element of the list can be a cons cell instead of just a string.\n\
5860 Then the car must be a string, which specifies the buffer name.\n\
5861 This is for compatibility with `special-display-buffer-names';\n\
5862 the cdr of the cons cell is ignored.\n\
5864 See also `same-window-regexps'.");
5865 Vsame_window_buffer_names
= Qnil
;
5867 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
5868 "*List of regexps saying which buffers should appear in the selected window.\n\
5869 If a buffer name matches one of these regexps, then displaying it\n\
5870 using `display-buffer' or `pop-to-buffer' switches to it\n\
5871 in the selected window, rather than making it appear in some other window.\n\
5873 An element of the list can be a cons cell instead of just a string.\n\
5874 Then the car must be a string, which specifies the buffer name.\n\
5875 This is for compatibility with `special-display-buffer-names';\n\
5876 the cdr of the cons cell is ignored.\n\
5878 See also `same-window-buffer-names'.");
5879 Vsame_window_regexps
= Qnil
;
5881 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
5882 "*Non-nil means display-buffer should make new windows.");
5885 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
5886 "*Number of lines of continuity when scrolling by screenfuls.");
5887 next_screen_context_lines
= 2;
5889 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
5890 "*display-buffer would prefer to split the largest window if this large.\n\
5891 If there is only one window, it is split regardless of this value.");
5892 split_height_threshold
= 500;
5894 DEFVAR_INT ("window-min-height", &window_min_height
,
5895 "*Delete any window less than this tall (including its mode line).");
5896 window_min_height
= 4;
5898 DEFVAR_INT ("window-min-width", &window_min_width
,
5899 "*Delete any window less than this wide.");
5900 window_min_width
= 10;
5902 DEFVAR_LISP ("scroll-preserve-screen-position",
5903 &Vscroll_preserve_screen_position
,
5904 "*Non-nil means scroll commands move point to keep its screen line unchanged.");
5905 Vscroll_preserve_screen_position
= Qnil
;
5907 DEFVAR_LISP ("window-configuration-change-hook",
5908 &Vwindow_configuration_change_hook
,
5909 "Functions to call when window configuration changes.\n\
5910 The selected frame is the one whose configuration has changed.");
5911 Vwindow_configuration_change_hook
= Qnil
;
5913 DEFVAR_BOOL ("window-size-fixed", &window_size_fixed
,
5914 "Non-nil in a buffer means windows displaying the buffer are fixed-size.\n\
5915 Emacs won't change the size of any window displaying that buffer,\n\
5916 unless you explicitly change the size, or Emacs has no other choice.\n\
5917 This variable automatically becomes buffer-local when set.");
5918 Fmake_variable_buffer_local (Qwindow_size_fixed
);
5919 window_size_fixed
= 0;
5921 defsubr (&Sselected_window
);
5922 defsubr (&Sminibuffer_window
);
5923 defsubr (&Swindow_minibuffer_p
);
5924 defsubr (&Swindowp
);
5925 defsubr (&Swindow_live_p
);
5926 defsubr (&Spos_visible_in_window_p
);
5927 defsubr (&Swindow_buffer
);
5928 defsubr (&Swindow_height
);
5929 defsubr (&Swindow_width
);
5930 defsubr (&Swindow_hscroll
);
5931 defsubr (&Sset_window_hscroll
);
5932 defsubr (&Swindow_redisplay_end_trigger
);
5933 defsubr (&Sset_window_redisplay_end_trigger
);
5934 defsubr (&Swindow_edges
);
5935 defsubr (&Scoordinates_in_window_p
);
5936 defsubr (&Swindow_at
);
5937 defsubr (&Swindow_point
);
5938 defsubr (&Swindow_start
);
5939 defsubr (&Swindow_end
);
5940 defsubr (&Sset_window_point
);
5941 defsubr (&Sset_window_start
);
5942 defsubr (&Swindow_dedicated_p
);
5943 defsubr (&Sset_window_dedicated_p
);
5944 defsubr (&Swindow_display_table
);
5945 defsubr (&Sset_window_display_table
);
5946 defsubr (&Snext_window
);
5947 defsubr (&Sprevious_window
);
5948 defsubr (&Sother_window
);
5949 defsubr (&Sget_lru_window
);
5950 defsubr (&Sget_largest_window
);
5951 defsubr (&Sget_buffer_window
);
5952 defsubr (&Sdelete_other_windows
);
5953 defsubr (&Sdelete_windows_on
);
5954 defsubr (&Sreplace_buffer_in_windows
);
5955 defsubr (&Sdelete_window
);
5956 defsubr (&Sset_window_buffer
);
5957 defsubr (&Sselect_window
);
5958 defsubr (&Sspecial_display_p
);
5959 defsubr (&Ssame_window_p
);
5960 defsubr (&Sdisplay_buffer
);
5961 defsubr (&Ssplit_window
);
5962 defsubr (&Senlarge_window
);
5963 defsubr (&Sshrink_window
);
5964 defsubr (&Sscroll_up
);
5965 defsubr (&Sscroll_down
);
5966 defsubr (&Sscroll_left
);
5967 defsubr (&Sscroll_right
);
5968 defsubr (&Sother_window_for_scrolling
);
5969 defsubr (&Sscroll_other_window
);
5970 defsubr (&Srecenter
);
5971 defsubr (&Swindow_text_height
);
5972 defsubr (&Smove_to_window_line
);
5973 defsubr (&Swindow_configuration_p
);
5974 defsubr (&Swindow_configuration_frame
);
5975 defsubr (&Sset_window_configuration
);
5976 defsubr (&Scurrent_window_configuration
);
5977 defsubr (&Ssave_window_excursion
);
5978 defsubr (&Sset_window_margins
);
5979 defsubr (&Swindow_margins
);
5980 defsubr (&Swindow_vscroll
);
5981 defsubr (&Sset_window_vscroll
);
5982 defsubr (&Scompare_window_configurations
);
5983 defsubr (&Swindow_list
);
5989 initial_define_key (control_x_map
, '1', "delete-other-windows");
5990 initial_define_key (control_x_map
, '2', "split-window");
5991 initial_define_key (control_x_map
, '0', "delete-window");
5992 initial_define_key (control_x_map
, 'o', "other-window");
5993 initial_define_key (control_x_map
, '^', "enlarge-window");
5994 initial_define_key (control_x_map
, '<', "scroll-left");
5995 initial_define_key (control_x_map
, '>', "scroll-right");
5997 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
5998 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
5999 initial_define_key (meta_map
, 'v', "scroll-down");
6001 initial_define_key (global_map
, Ctl('L'), "recenter");
6002 initial_define_key (meta_map
, 'r', "move-to-window-line");