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
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))
55 Lisp_Object Qwindowp
, Qwindow_live_p
, Qwindow_configuration_p
;
56 Lisp_Object Qwindow_size_fixed
, Qleft_bitmap_area
, Qright_bitmap_area
;
57 extern Lisp_Object Qheight
, Qwidth
;
59 static struct window
*decode_window
P_ ((Lisp_Object
));
60 static Lisp_Object select_window_1
P_ ((Lisp_Object
, int));
61 static int count_windows
P_ ((struct window
*));
62 static int get_leaf_windows
P_ ((struct window
*, struct window
**, int));
63 static void window_scroll
P_ ((Lisp_Object
, int, int, int));
64 static void window_scroll_pixel_based
P_ ((Lisp_Object
, int, int, int));
65 static void window_scroll_line_based
P_ ((Lisp_Object
, int, int, int));
66 static int window_min_size_1
P_ ((struct window
*, int));
67 static int window_min_size
P_ ((struct window
*, int, int, int *));
68 static void size_window
P_ ((Lisp_Object
, int, int, int));
69 static int freeze_window_start
P_ ((struct window
*, void *));
70 static int window_fixed_size_p
P_ ((struct window
*, int, int));
71 static void enlarge_window
P_ ((Lisp_Object
, int, int));
72 static Lisp_Object window_list
P_ ((void));
73 static int add_window_to_list
P_ ((struct window
*, void *));
74 static int candidate_window_p
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
,
76 static Lisp_Object next_window
P_ ((Lisp_Object
, Lisp_Object
,
78 static void decode_next_window_args
P_ ((Lisp_Object
*, Lisp_Object
*,
80 static int foreach_window_1
P_ ((struct window
*,
81 int (* fn
) (struct window
*, void *),
83 static Lisp_Object window_list_1
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
85 /* This is the window in which the terminal's cursor should
86 be left when nothing is being done with it. This must
87 always be a leaf window, and its buffer is selected by
88 the top level editing loop at the end of each command.
90 This value is always the same as
91 FRAME_SELECTED_WINDOW (selected_frame). */
93 Lisp_Object selected_window
;
95 /* A list of all windows for use by next_window and Fwindow_list.
96 Functions creating or deleting windows should invalidate this cache
97 by setting it to nil. */
99 Lisp_Object Vwindow_list
;
101 /* The mini-buffer window of the selected frame.
102 Note that you cannot test for mini-bufferness of an arbitrary window
103 by comparing against this; but you can test for mini-bufferness of
104 the selected window. */
106 Lisp_Object minibuf_window
;
108 /* Non-nil means it is the window for C-M-v to scroll
109 when the mini-buffer is selected. */
111 Lisp_Object Vminibuf_scroll_window
;
113 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
115 Lisp_Object Vother_window_scroll_buffer
;
117 /* Non-nil means it's function to call to display temp buffers. */
119 Lisp_Object Vtemp_buffer_show_function
;
121 /* If a window gets smaller than either of these, it is removed. */
123 int window_min_height
;
124 int window_min_width
;
126 /* Nonzero implies Fdisplay_buffer should create windows. */
130 /* Nonzero implies make new frames for Fdisplay_buffer. */
134 /* Nonzero means reuse existing frames for displaying buffers. */
136 int display_buffer_reuse_frames
;
138 /* Non-nil means use this function instead of default */
140 Lisp_Object Vpop_up_frame_function
;
142 /* Function to call to handle Fdisplay_buffer. */
144 Lisp_Object Vdisplay_buffer_function
;
146 /* Non-nil means that Fdisplay_buffer should even the heights of windows. */
148 Lisp_Object Veven_window_heights
;
150 /* List of buffer *names* for buffers that should have their own frames. */
152 Lisp_Object Vspecial_display_buffer_names
;
154 /* List of regexps for buffer names that should have their own frames. */
156 Lisp_Object Vspecial_display_regexps
;
158 /* Function to pop up a special frame. */
160 Lisp_Object Vspecial_display_function
;
162 /* List of buffer *names* for buffers to appear in selected window. */
164 Lisp_Object Vsame_window_buffer_names
;
166 /* List of regexps for buffer names to appear in selected window. */
168 Lisp_Object Vsame_window_regexps
;
170 /* Hook run at end of temp_output_buffer_show. */
172 Lisp_Object Qtemp_buffer_show_hook
;
174 /* Fdisplay_buffer always splits the largest window
175 if that window is more than this high. */
177 int split_height_threshold
;
179 /* Number of lines of continuity in scrolling by screenfuls. */
181 int next_screen_context_lines
;
183 /* Incremented for each window created. */
185 static int sequence_number
;
187 /* Nonzero after init_window_once has finished. */
189 static int window_initialized
;
191 /* Hook to run when window config changes. */
193 Lisp_Object Qwindow_configuration_change_hook
;
194 Lisp_Object Vwindow_configuration_change_hook
;
196 /* Nonzero means scroll commands try to put point
197 at the same screen height as previously. */
199 Lisp_Object Vscroll_preserve_screen_position
;
201 #if 0 /* This isn't used anywhere. */
202 /* Nonzero means we can split a frame even if it is "unsplittable". */
203 static int inhibit_frame_unsplittable
;
206 #define min(a, b) ((a) < (b) ? (a) : (b))
208 extern int scroll_margin
;
210 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
212 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
213 "Returns t if OBJECT is a window.")
217 return WINDOWP (object
) ? Qt
: Qnil
;
220 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
221 "Returns t if OBJECT is a window which is currently visible.")
225 return (WINDOWP (object
) && ! NILP (XWINDOW (object
)->buffer
) ? Qt
: Qnil
);
232 register struct window
*p
;
233 register struct Lisp_Vector
*vec
;
236 vec
= allocate_vectorlike ((EMACS_INT
) VECSIZE (struct window
));
237 for (i
= 0; i
< VECSIZE (struct window
); i
++)
238 vec
->contents
[i
] = Qnil
;
239 vec
->size
= VECSIZE (struct window
);
240 p
= (struct window
*) vec
;
241 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
242 XSETFASTINT (p
->left
, 0);
243 XSETFASTINT (p
->top
, 0);
244 XSETFASTINT (p
->height
, 0);
245 XSETFASTINT (p
->width
, 0);
246 XSETFASTINT (p
->hscroll
, 0);
247 p
->orig_top
= p
->orig_height
= Qnil
;
248 p
->start
= Fmake_marker ();
249 p
->pointm
= Fmake_marker ();
250 XSETFASTINT (p
->use_time
, 0);
252 p
->display_table
= Qnil
;
254 p
->pseudo_window_p
= 0;
255 bzero (&p
->cursor
, sizeof (p
->cursor
));
256 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
257 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
258 p
->desired_matrix
= p
->current_matrix
= 0;
259 p
->phys_cursor_type
= -1;
260 p
->must_be_updated_p
= 0;
261 XSETFASTINT (p
->window_end_vpos
, 0);
262 XSETFASTINT (p
->window_end_pos
, 0);
263 p
->window_end_valid
= Qnil
;
266 XSETFASTINT (p
->last_point
, 0);
267 p
->frozen_window_start_p
= 0;
273 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
274 "Return the window that the cursor now appears in and commands apply to.")
277 return selected_window
;
280 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
281 "Return the window used now for minibuffers.\n\
282 If the optional argument FRAME is specified, return the minibuffer window\n\
283 used by that frame.")
288 frame
= selected_frame
;
289 CHECK_LIVE_FRAME (frame
, 0);
290 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
293 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
294 "Returns non-nil if WINDOW is a minibuffer window.")
298 struct window
*w
= decode_window (window
);
299 return MINI_WINDOW_P (w
) ? Qt
: Qnil
;
303 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
304 Spos_visible_in_window_p
, 0, 3, 0,
305 "Return t if position POS is currently on the frame in WINDOW.\n\
306 Return nil if that position is scrolled vertically out of view.\n\
307 If FULLY is non-nil, then only return t when POS is completely visible.\n\
308 POS defaults to point in WINDOW; WINDOW defaults to the selected window.")
310 Lisp_Object pos
, window
, fully
;
312 register struct window
*w
;
314 register struct buffer
*buf
;
316 Lisp_Object in_window
;
319 w
= decode_window (window
);
320 buf
= XBUFFER (w
->buffer
);
321 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
325 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
328 else if (w
== XWINDOW (selected_window
))
331 posint
= XMARKER (w
->pointm
)->charpos
;
333 /* If position is above window start, it's not visible. */
334 if (posint
< CHARPOS (top
))
336 else if (XFASTINT (w
->last_modified
) >= BUF_MODIFF (buf
)
337 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (buf
)
338 && posint
< BUF_Z (buf
) - XFASTINT (w
->window_end_pos
))
340 /* If frame is up-to-date, and POSINT is < window end pos, use
341 that info. This doesn't work for POSINT == end pos, because
342 the window end pos is actually the position _after_ the last
343 char in the window. */
346 pos_visible_p (w
, posint
, &fully_p
, !NILP (fully
));
347 in_window
= fully_p
? Qt
: Qnil
;
352 else if (posint
> BUF_ZV (buf
))
354 else if (CHARPOS (top
) < BUF_BEGV (buf
) || CHARPOS (top
) > BUF_ZV (buf
))
355 /* If window start is out of range, do something reasonable. */
359 if (pos_visible_p (w
, posint
, &fully_p
, !NILP (fully
)))
360 in_window
= NILP (fully
) || fully_p
? Qt
: Qnil
;
369 static struct window
*
370 decode_window (window
)
371 register Lisp_Object window
;
374 return XWINDOW (selected_window
);
376 CHECK_LIVE_WINDOW (window
, 0);
377 return XWINDOW (window
);
380 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
381 "Return the buffer that WINDOW is displaying.")
385 return decode_window (window
)->buffer
;
388 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
389 "Return the number of lines in WINDOW (including its mode line).")
393 return decode_window (window
)->height
;
396 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
397 "Return the number of display columns in WINDOW.\n\
398 This is the width that is usable columns available for text in WINDOW.\n\
399 If you want to find out how many columns WINDOW takes up,\n\
400 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))).")
404 return make_number (window_internal_width (decode_window (window
)));
407 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
408 "Return the number of columns by which WINDOW is scrolled from left margin.")
412 return decode_window (window
)->hscroll
;
415 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
416 "Set number of columns WINDOW is scrolled from left margin to NCOL.\n\
417 NCOL should be zero or positive.")
419 register Lisp_Object window
, ncol
;
421 register struct window
*w
;
423 CHECK_NUMBER (ncol
, 1);
424 if (XINT (ncol
) < 0) XSETFASTINT (ncol
, 0);
425 w
= decode_window (window
);
426 if (XINT (w
->hscroll
) != XINT (ncol
))
427 /* Prevent redisplay shortcuts */
428 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
433 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
434 Swindow_redisplay_end_trigger
, 0, 1, 0,
435 "Return WINDOW's redisplay end trigger value.\n\
436 See `set-window-redisplay-end-trigger' for more information.")
440 return decode_window (window
)->redisplay_end_trigger
;
443 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
444 Sset_window_redisplay_end_trigger
, 2, 2, 0,
445 "Set WINDOW's redisplay end trigger value to VALUE.\n\
446 VALUE should be a buffer position (typically a marker) or nil.\n\
447 If it is a buffer position, then if redisplay in WINDOW reaches a position\n\
448 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called\n\
449 with two arguments: WINDOW, and the end trigger value.\n\
450 Afterwards the end-trigger value is reset to nil.")
452 register Lisp_Object window
, value
;
454 register struct window
*w
;
456 w
= decode_window (window
);
457 w
->redisplay_end_trigger
= value
;
461 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
462 "Return a list of the edge coordinates of WINDOW.\n\
463 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.\n\
464 RIGHT is one more than the rightmost column used by WINDOW,\n\
465 and BOTTOM is one more than the bottommost row used by WINDOW\n\
470 register struct window
*w
= decode_window (window
);
472 return Fcons (w
->left
, Fcons (w
->top
,
473 Fcons (make_number (WINDOW_RIGHT_EDGE (w
)),
474 Fcons (make_number (XFASTINT (w
->top
)
475 + XFASTINT (w
->height
)),
479 /* Test if the character at column *X, row *Y is within window W.
480 If it is not, return 0;
481 if it is in the window's text area,
482 set *x and *y to its location relative to the upper left corner
485 if it is on the window's modeline, return 2;
486 if it is on the border between the window and its right sibling,
488 if it is on the window's top line, return 4;
489 if it is in the bitmap area to the left/right of the window,
490 return 5 or 6, and convert *X and *Y to window-relative corrdinates.
492 X and Y are frame relative pixel coordinates. */
495 coordinates_in_window (w
, x
, y
)
496 register struct window
*w
;
499 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
500 int left_x
, right_x
, top_y
, bottom_y
;
501 int flags_area_width
= FRAME_LEFT_FLAGS_AREA_WIDTH (f
);
503 /* Let's make this a global enum later, instead of using numbers
505 enum {ON_NOTHING
, ON_TEXT
, ON_MODE_LINE
, ON_VERTICAL_BORDER
,
506 ON_HEADER_LINE
, ON_LEFT_FRINGE
, ON_RIGHT_FRINGE
};
508 /* In what's below, we subtract 1 when computing right_x because we
509 want the rightmost pixel, which is given by left_pixel+width-1. */
510 if (w
->pseudo_window_p
)
513 right_x
= XFASTINT (w
->width
) * CANON_Y_UNIT (f
) - 1;
514 top_y
= WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
);
515 bottom_y
= WINDOW_DISPLAY_BOTTOM_EDGE_PIXEL_Y (w
);
519 left_x
= (WINDOW_DISPLAY_LEFT_EDGE_PIXEL_X (w
)
520 - FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
));
521 right_x
= WINDOW_DISPLAY_RIGHT_EDGE_PIXEL_X (w
) - 1;
522 top_y
= (WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
)
523 - FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
));
524 bottom_y
= WINDOW_DISPLAY_BOTTOM_EDGE_PIXEL_Y (w
);
527 /* On the mode line or header line? If it's near the start of
528 the mode or header line of window that's has a horizontal
529 sibling, say it's on the vertical line. That's to be able
530 to resize windows horizontally in case we're using toolkit
533 if (WINDOW_WANTS_MODELINE_P (w
)
535 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
537 if (!WINDOW_RIGHTMOST_P (w
)
538 && (abs (*x
- ((XFASTINT (w
->left
) + XFASTINT (w
->width
))
540 < CANON_X_UNIT (f
) / 2))
541 return ON_VERTICAL_BORDER
;
545 if (WINDOW_WANTS_HEADER_LINE_P (w
)
547 && *y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
))
549 if (!WINDOW_RIGHTMOST_P (w
)
550 && (abs (*x
- ((XFASTINT (w
->left
) + XFASTINT (w
->width
))
552 < CANON_X_UNIT (f
) / 2))
553 return ON_VERTICAL_BORDER
;
554 return ON_HEADER_LINE
;
557 /* Completely outside anything interesting? */
562 - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
)
564 || *x
> right_x
+ flags_area_width
)
567 if (FRAME_WINDOW_P (f
))
569 if (!w
->pseudo_window_p
570 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
571 && !WINDOW_RIGHTMOST_P (w
)
572 && (abs (*x
- right_x
- flags_area_width
) < CANON_X_UNIT (f
) / 2))
573 return ON_VERTICAL_BORDER
;
575 if (*x
< left_x
|| *x
> right_x
)
577 /* Other lines than the mode line don't include flags areas and
578 scroll bars on the left. */
580 /* Convert X and Y to window-relative pixel coordinates. */
583 return *x
< left_x
? ON_LEFT_FRINGE
: ON_RIGHT_FRINGE
;
588 /* Need to say "*x > right_x" rather than >=, since on character
589 terminals, the vertical line's x coordinate is right_x. */
590 if (*x
< left_x
|| *x
> right_x
)
592 /* Other lines than the mode line don't include flags areas and
593 scroll bars on the left. */
595 /* Convert X and Y to window-relative pixel coordinates. */
598 return *x
< left_x
? ON_LEFT_FRINGE
: ON_RIGHT_FRINGE
;
601 /* Here, too, "*x > right_x" is because of character terminals. */
602 if (!w
->pseudo_window_p
603 && !WINDOW_RIGHTMOST_P (w
)
604 && *x
> right_x
- CANON_X_UNIT (f
))
605 /* On the border on the right side of the window? Assume that
606 this area begins at RIGHT_X minus a canonical char width. */
607 return ON_VERTICAL_BORDER
;
610 /* Convert X and Y to window-relative pixel coordinates. */
616 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
617 Scoordinates_in_window_p
, 2, 2, 0,
618 "Return non-nil if COORDINATES are in WINDOW.\n\
619 COORDINATES is a cons of the form (X . Y), X and Y being distances\n\
620 measured in characters from the upper-left corner of the frame.\n\
621 (0 . 0) denotes the character in the upper left corner of the\n\
623 If COORDINATES are in the text portion of WINDOW,\n\
624 the coordinates relative to the window are returned.\n\
625 If they are in the mode line of WINDOW, `mode-line' is returned.\n\
626 If they are in the top mode line of WINDOW, `header-line' is returned.\n\
627 If they are in the bitmap-area to the left of the window,\n\
628 `left-bitmap-area' is returned, if they are in the area on the right of\n\
629 the window, `right-bitmap-area' is returned.\n\
630 If they are on the border between WINDOW and its right sibling,\n\
631 `vertical-line' is returned.")
632 (coordinates
, window
)
633 register Lisp_Object coordinates
, window
;
640 CHECK_LIVE_WINDOW (window
, 0);
641 w
= XWINDOW (window
);
642 f
= XFRAME (w
->frame
);
643 CHECK_CONS (coordinates
, 1);
644 lx
= Fcar (coordinates
);
645 ly
= Fcdr (coordinates
);
646 CHECK_NUMBER_OR_FLOAT (lx
, 1);
647 CHECK_NUMBER_OR_FLOAT (ly
, 1);
648 x
= PIXEL_X_FROM_CANON_X (f
, lx
);
649 y
= PIXEL_Y_FROM_CANON_Y (f
, ly
);
651 switch (coordinates_in_window (w
, &x
, &y
))
653 case 0: /* NOT in window at all. */
656 case 1: /* In text part of window. */
657 /* X and Y are now window relative pixel coordinates.
658 Convert them to canonical char units before returning
660 return Fcons (CANON_X_FROM_PIXEL_X (f
, x
),
661 CANON_Y_FROM_PIXEL_Y (f
, y
));
663 case 2: /* In mode line of window. */
666 case 3: /* On right border of window. */
667 return Qvertical_line
;
673 return Qleft_bitmap_area
;
676 return Qright_bitmap_area
;
684 /* Callback for foreach_window, used in window_from_coordinates.
685 Check if window W contains coordinates specified by USER_DATA which
686 is actually a pointer to a struct check_window_data CW.
688 Check if window W contains coordinates *CW->x and *CW->y. If it
689 does, return W in *CW->window, as Lisp_Object, and return in
690 *CW->part the part of the window under coordinates *X,*Y. Return
691 zero from this function to stop iterating over windows. */
693 struct check_window_data
700 check_window_containing (w
, user_data
)
704 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
707 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
710 *cw
->part
= found
- 1;
711 XSETWINDOW (*cw
->window
, w
);
718 /* Find the window containing frame-relative pixel position X/Y and
719 return it as a Lisp_Object. If X, Y is on the window's modeline,
720 set *PART to 1; if it is on the separating line between the window
721 and its right sibling, set it to 2; otherwise set it to 0. If
722 there is no window under X, Y return nil and leave *PART
723 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
725 This function was previously implemented with a loop cycling over
726 windows with Fnext_window, and starting with the frame's selected
727 window. It turned out that this doesn't work with an
728 implementation of next_window using Vwindow_list, because
729 FRAME_SELECTED_WINDOW (F) is not always contained in the window
730 tree of F when this function is called asynchronously from
731 note_mouse_highlight. The original loop didn't terminate in this
735 window_from_coordinates (f
, x
, y
, part
, tool_bar_p
)
742 struct check_window_data cw
;
745 cw
.window
= &window
, cw
.x
= &x
, cw
.y
= &y
; cw
.part
= part
;
746 foreach_window (f
, check_window_containing
, &cw
);
748 /* If not found above, see if it's in the tool bar window, if a tool
752 && WINDOWP (f
->tool_bar_window
)
753 && XINT (XWINDOW (f
->tool_bar_window
)->height
) > 0
754 && coordinates_in_window (XWINDOW (f
->tool_bar_window
), &x
, &y
))
757 window
= f
->tool_bar_window
;
763 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
764 "Return window containing coordinates X and Y on FRAME.\n\
765 If omitted, FRAME defaults to the currently selected frame.\n\
766 The top left corner of the frame is considered to be row 0,\n\
769 Lisp_Object x
, y
, frame
;
775 frame
= selected_frame
;
776 CHECK_LIVE_FRAME (frame
, 2);
779 /* Check that arguments are integers or floats. */
780 CHECK_NUMBER_OR_FLOAT (x
, 0);
781 CHECK_NUMBER_OR_FLOAT (y
, 1);
783 return window_from_coordinates (f
,
784 PIXEL_X_FROM_CANON_X (f
, x
),
785 PIXEL_Y_FROM_CANON_Y (f
, y
),
789 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
790 "Return current value of point in WINDOW.\n\
791 For a nonselected window, this is the value point would have\n\
792 if that window were selected.\n\
794 Note that, when WINDOW is the selected window and its buffer\n\
795 is also currently selected, the value returned is the same as (point).\n\
796 It would be more strictly correct to return the `top-level' value\n\
797 of point, outside of any save-excursion forms.\n\
798 But that is hard to define.")
802 register struct window
*w
= decode_window (window
);
804 if (w
== XWINDOW (selected_window
)
805 && current_buffer
== XBUFFER (w
->buffer
))
807 return Fmarker_position (w
->pointm
);
810 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
811 "Return position at which display currently starts in WINDOW.\n\
812 This is updated by redisplay or by calling `set-window-start'.")
816 return Fmarker_position (decode_window (window
)->start
);
819 /* This is text temporarily removed from the doc string below.
821 This function returns nil if the position is not currently known.\n\
822 That happens when redisplay is preempted and doesn't finish.\n\
823 If in that case you want to compute where the end of the window would\n\
824 have been if redisplay had finished, do this:\n\
826 (goto-char (window-start window))\n\
827 (vertical-motion (1- (window-height window)) window)\n\
830 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
831 "Return position at which display currently ends in WINDOW.\n\
832 This is updated by redisplay, when it runs to completion.\n\
833 Simply changing the buffer text or setting `window-start'\n\
834 does not update this value.\n\
835 If UP-TO-DATE is non-nil, compute the up-to-date position\n\
836 if it isn't already recorded.")
838 Lisp_Object window
, update
;
841 struct window
*w
= decode_window (window
);
845 CHECK_BUFFER (buf
, 0);
847 #if 0 /* This change broke some things. We should make it later. */
848 /* If we don't know the end position, return nil.
849 The user can compute it with vertical-motion if he wants to.
850 It would be nicer to do it automatically,
851 but that's so slow that it would probably bother people. */
852 if (NILP (w
->window_end_valid
))
857 && ! (! NILP (w
->window_end_valid
)
858 && XFASTINT (w
->last_modified
) >= MODIFF
))
860 struct text_pos startp
;
863 /* In case W->start is out of the range, use something
864 reasonable. This situation occured when loading a file with
865 `-l' containing a call to `rmail' with subsequent other
866 commands. At the end, W->start happened to be BEG, while
867 rmail had already narrowed the buffer. */
868 if (XMARKER (w
->start
)->charpos
< BEGV
)
869 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
870 else if (XMARKER (w
->start
)->charpos
> ZV
)
871 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
873 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
875 /* Cannot use Fvertical_motion because that function doesn't
876 cope with variable-height lines. */
877 start_display (&it
, w
, startp
);
878 move_it_vertically (&it
, window_box_height (w
));
879 value
= make_number (IT_CHARPOS (it
));
882 XSETINT (value
, BUF_Z (XBUFFER (buf
)) - XFASTINT (w
->window_end_pos
));
887 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
888 "Make point value in WINDOW be at position POS in WINDOW's buffer.")
890 Lisp_Object window
, pos
;
892 register struct window
*w
= decode_window (window
);
894 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
895 if (w
== XWINDOW (selected_window
)
896 && XBUFFER (w
->buffer
) == current_buffer
)
899 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
904 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
905 "Make display in WINDOW start at position POS in WINDOW's buffer.\n\
906 Optional third arg NOFORCE non-nil inhibits next redisplay\n\
907 from overriding motion of point in order to display at this exact start.")
908 (window
, pos
, noforce
)
909 Lisp_Object window
, pos
, noforce
;
911 register struct window
*w
= decode_window (window
);
913 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
914 set_marker_restricted (w
->start
, pos
, w
->buffer
);
915 /* this is not right, but much easier than doing what is right. */
916 w
->start_at_line_beg
= Qnil
;
919 w
->update_mode_line
= Qt
;
920 XSETFASTINT (w
->last_modified
, 0);
921 XSETFASTINT (w
->last_overlay_modified
, 0);
922 if (!EQ (window
, selected_window
))
923 windows_or_buffers_changed
++;
928 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
930 "Return WINDOW's dedicated object, usually t or nil.\n\
931 See also `set-window-dedicated-p'.")
935 return decode_window (window
)->dedicated
;
938 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
939 Sset_window_dedicated_p
, 2, 2, 0,
940 "Control whether WINDOW is dedicated to the buffer it displays.\n\
941 If it is dedicated, Emacs will not automatically change\n\
942 which buffer appears in it.\n\
943 The second argument is the new value for the dedication flag;\n\
946 Lisp_Object window
, arg
;
948 register struct window
*w
= decode_window (window
);
958 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
960 "Return the display-table that WINDOW is using.")
964 return decode_window (window
)->display_table
;
967 /* Get the display table for use on window W. This is either W's
968 display table or W's buffer's display table. Ignore the specified
969 tables if they are not valid; if no valid table is specified,
972 struct Lisp_Char_Table
*
973 window_display_table (w
)
976 struct Lisp_Char_Table
*dp
= NULL
;
978 if (DISP_TABLE_P (w
->display_table
))
979 dp
= XCHAR_TABLE (w
->display_table
);
980 else if (BUFFERP (w
->buffer
))
982 struct buffer
*b
= XBUFFER (w
->buffer
);
984 if (DISP_TABLE_P (b
->display_table
))
985 dp
= XCHAR_TABLE (b
->display_table
);
986 else if (DISP_TABLE_P (Vstandard_display_table
))
987 dp
= XCHAR_TABLE (Vstandard_display_table
);
993 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
994 "Set WINDOW's display-table to TABLE.")
996 register Lisp_Object window
, table
;
998 register struct window
*w
;
1000 w
= decode_window (window
);
1001 w
->display_table
= table
;
1005 /* Record info on buffer window w is displaying
1006 when it is about to cease to display that buffer. */
1009 register struct window
*w
;
1016 if (b
!= XMARKER (w
->pointm
)->buffer
)
1020 if (w
== XWINDOW (selected_window
)
1021 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1022 /* Do this except when the selected window's buffer
1023 is being removed from some other window. */
1025 /* last_window_start records the start position that this buffer
1026 had in the last window to be disconnected from it.
1027 Now that this statement is unconditional,
1028 it is possible for the buffer to be displayed in the
1029 selected window, while last_window_start reflects another
1030 window which was recently showing the same buffer.
1031 Some people might say that might be a good thing. Let's see. */
1032 b
->last_window_start
= marker_position (w
->start
);
1034 /* Point in the selected window's buffer
1035 is actually stored in that buffer, and the window's pointm isn't used.
1036 So don't clobber point in that buffer. */
1037 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1038 /* This line helps to fix Horsley's testbug.el bug. */
1039 && !(WINDOWP (b
->last_selected_window
)
1040 && w
!= XWINDOW (b
->last_selected_window
)
1041 && EQ (buf
, XWINDOW (b
->last_selected_window
)->buffer
)))
1042 temp_set_point_both (b
,
1043 clip_to_bounds (BUF_BEGV (b
),
1044 XMARKER (w
->pointm
)->charpos
,
1046 clip_to_bounds (BUF_BEGV_BYTE (b
),
1047 marker_byte_position (w
->pointm
),
1050 if (WINDOWP (b
->last_selected_window
)
1051 && w
== XWINDOW (b
->last_selected_window
))
1052 b
->last_selected_window
= Qnil
;
1055 /* Put replacement into the window structure in place of old. */
1057 replace_window (old
, replacement
)
1058 Lisp_Object old
, replacement
;
1060 register Lisp_Object tem
;
1061 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
1063 /* If OLD is its frame's root_window, then replacement is the new
1064 root_window for that frame. */
1066 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1067 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
1071 p
->width
= o
->width
;
1072 p
->height
= o
->height
;
1073 p
->desired_matrix
= p
->current_matrix
= 0;
1075 bzero (&p
->cursor
, sizeof (p
->cursor
));
1076 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
1077 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
1078 p
->phys_cursor_type
= -1;
1079 p
->must_be_updated_p
= 0;
1080 p
->pseudo_window_p
= 0;
1081 XSETFASTINT (p
->window_end_vpos
, 0);
1082 XSETFASTINT (p
->window_end_pos
, 0);
1083 p
->window_end_valid
= Qnil
;
1084 p
->frozen_window_start_p
= 0;
1085 p
->orig_top
= p
->orig_height
= Qnil
;
1087 p
->next
= tem
= o
->next
;
1089 XWINDOW (tem
)->prev
= replacement
;
1091 p
->prev
= tem
= o
->prev
;
1093 XWINDOW (tem
)->next
= replacement
;
1095 p
->parent
= tem
= o
->parent
;
1098 if (EQ (XWINDOW (tem
)->vchild
, old
))
1099 XWINDOW (tem
)->vchild
= replacement
;
1100 if (EQ (XWINDOW (tem
)->hchild
, old
))
1101 XWINDOW (tem
)->hchild
= replacement
;
1104 /*** Here, if replacement is a vertical combination
1105 and so is its new parent, we should make replacement's
1106 children be children of that parent instead. ***/
1109 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
1110 "Remove WINDOW from the display. Default is selected window.")
1112 register Lisp_Object window
;
1114 delete_window (window
);
1116 if (! NILP (Vwindow_configuration_change_hook
)
1117 && ! NILP (Vrun_hooks
))
1118 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
1124 delete_window (window
)
1125 register Lisp_Object window
;
1127 register Lisp_Object tem
, parent
, sib
;
1128 register struct window
*p
;
1129 register struct window
*par
;
1132 /* Because this function is called by other C code on non-leaf
1133 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1134 so we can't decode_window here. */
1136 window
= selected_window
;
1138 CHECK_WINDOW (window
, 0);
1139 p
= XWINDOW (window
);
1141 /* It's okay to delete an already-deleted window. */
1142 if (NILP (p
->buffer
)
1144 && NILP (p
->vchild
))
1149 error ("Attempt to delete minibuffer or sole ordinary window");
1150 par
= XWINDOW (parent
);
1152 windows_or_buffers_changed
++;
1153 Vwindow_list
= Qnil
;
1154 frame
= XFRAME (WINDOW_FRAME (p
));
1155 FRAME_WINDOW_SIZES_CHANGED (frame
) = 1;
1157 /* Are we trying to delete any frame's selected window? */
1159 Lisp_Object frame
, pwindow
;
1161 /* See if the frame's selected window is either WINDOW
1162 or any subwindow of it, by finding all that window's parents
1163 and comparing each one with WINDOW. */
1164 frame
= WINDOW_FRAME (XWINDOW (window
));
1165 pwindow
= FRAME_SELECTED_WINDOW (XFRAME (frame
));
1167 while (!NILP (pwindow
))
1169 if (EQ (window
, pwindow
))
1171 pwindow
= XWINDOW (pwindow
)->parent
;
1174 if (EQ (window
, pwindow
))
1176 Lisp_Object alternative
;
1177 alternative
= Fnext_window (window
, Qlambda
, Qnil
);
1179 /* If we're about to delete the selected window on the
1180 selected frame, then we should use Fselect_window to select
1181 the new window. On the other hand, if we're about to
1182 delete the selected window on any other frame, we shouldn't do
1183 anything but set the frame's selected_window slot. */
1184 if (EQ (window
, selected_window
))
1185 Fselect_window (alternative
);
1187 FRAME_SELECTED_WINDOW (XFRAME (frame
)) = alternative
;
1192 /* tem is null for dummy parent windows
1193 (which have inferiors but not any contents themselves) */
1197 unchain_marker (p
->pointm
);
1198 unchain_marker (p
->start
);
1201 /* Free window glyph matrices. It is sure that they are allocated
1202 again when ADJUST_GLYPHS is called. Block input so that expose
1203 events and other events that access glyph matrices are not
1204 processed while we are changing them. */
1206 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (frame
)));
1210 XWINDOW (tem
)->prev
= p
->prev
;
1214 XWINDOW (tem
)->next
= p
->next
;
1216 if (EQ (window
, par
->hchild
))
1217 par
->hchild
= p
->next
;
1218 if (EQ (window
, par
->vchild
))
1219 par
->vchild
= p
->next
;
1221 /* Find one of our siblings to give our space to. */
1225 /* If p gives its space to its next sibling, that sibling needs
1226 to have its top/left side pulled back to where p's is.
1227 set_window_{height,width} will re-position the sibling's
1230 XWINDOW (sib
)->top
= p
->top
;
1231 XWINDOW (sib
)->left
= p
->left
;
1234 /* Stretch that sibling. */
1235 if (!NILP (par
->vchild
))
1236 set_window_height (sib
,
1237 XFASTINT (XWINDOW (sib
)->height
) + XFASTINT (p
->height
),
1239 if (!NILP (par
->hchild
))
1240 set_window_width (sib
,
1241 XFASTINT (XWINDOW (sib
)->width
) + XFASTINT (p
->width
),
1244 /* If parent now has only one child,
1245 put the child into the parent's place. */
1249 if (NILP (XWINDOW (tem
)->next
))
1250 replace_window (parent
, tem
);
1252 /* Since we may be deleting combination windows, we must make sure that
1253 not only p but all its children have been marked as deleted. */
1254 if (! NILP (p
->hchild
))
1255 delete_all_subwindows (XWINDOW (p
->hchild
));
1256 else if (! NILP (p
->vchild
))
1257 delete_all_subwindows (XWINDOW (p
->vchild
));
1259 /* Mark this window as deleted. */
1260 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1262 /* Adjust glyph matrices. */
1263 adjust_glyphs (frame
);
1269 /***********************************************************************
1271 ***********************************************************************/
1273 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1274 pointer. This is a callback function for foreach_window, used in
1275 function window_list. */
1278 add_window_to_list (w
, user_data
)
1282 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1284 XSETWINDOW (window
, w
);
1285 *list
= Fcons (window
, *list
);
1290 /* Return a list of all windows, for use by next_window. If
1291 Vwindow_list is a list, return that list. Otherwise, build a new
1292 list, cache it in Vwindow_list, and return that. */
1297 if (!CONSP (Vwindow_list
))
1301 Vwindow_list
= Qnil
;
1302 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1304 Lisp_Object args
[2];
1306 /* We are visiting windows in canonical order, and add
1307 new windows at the front of args[1], which means we
1308 have to reverse this list at the end. */
1310 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1311 args
[0] = Vwindow_list
;
1312 args
[1] = Fnreverse (args
[1]);
1313 Vwindow_list
= Fnconc (2, args
);
1317 return Vwindow_list
;
1321 /* Value is non-zero if WINDOW satisfies the constraints given by
1322 OWINDOW, MINIBUF and ALL_FRAMES.
1324 MINIBUF t means WINDOW may be minibuffer windows.
1325 `lambda' means WINDOW may not be a minibuffer window.
1326 a window means a specific minibuffer window
1328 ALL_FRAMES t means search all frames,
1329 nil means search just current frame,
1330 `visible' means search just visible frames,
1331 0 means search visible and iconified frames,
1332 a window means search the frame that window belongs to,
1333 a frame means consider windows on that frame, only. */
1336 candidate_window_p (window
, owindow
, minibuf
, all_frames
)
1337 Lisp_Object window
, owindow
, minibuf
, all_frames
;
1339 struct window
*w
= XWINDOW (window
);
1340 struct frame
*f
= XFRAME (w
->frame
);
1341 int candidate_p
= 1;
1343 if (!BUFFERP (w
->buffer
))
1345 else if (MINI_WINDOW_P (w
)
1346 && (EQ (minibuf
, Qlambda
)
1347 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
1349 /* If MINIBUF is `lambda' don't consider any mini-windows.
1350 If it is a window, consider only that one. */
1353 else if (EQ (all_frames
, Qt
))
1355 else if (NILP (all_frames
))
1357 xassert (WINDOWP (owindow
));
1358 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
1360 else if (EQ (all_frames
, Qvisible
))
1362 FRAME_SAMPLE_VISIBILITY (f
);
1363 candidate_p
= FRAME_VISIBLE_P (f
);
1365 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
1367 FRAME_SAMPLE_VISIBILITY (f
);
1368 candidate_p
= FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
);
1370 else if (WINDOWP (all_frames
))
1371 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
1372 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
1373 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
1374 else if (FRAMEP (all_frames
))
1375 candidate_p
= EQ (all_frames
, w
->frame
);
1381 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1382 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1386 decode_next_window_args (window
, minibuf
, all_frames
)
1387 Lisp_Object
*window
, *minibuf
, *all_frames
;
1390 *window
= selected_window
;
1392 CHECK_LIVE_WINDOW (*window
, 0);
1394 /* MINIBUF nil may or may not include minibuffers. Decide if it
1396 if (NILP (*minibuf
))
1397 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
1398 else if (!EQ (*minibuf
, Qt
))
1401 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1402 => count none of them, or a specific minibuffer window (the
1403 active one) to count. */
1405 /* ALL_FRAMES nil doesn't specify which frames to include. */
1406 if (NILP (*all_frames
))
1407 *all_frames
= (!EQ (*minibuf
, Qlambda
)
1408 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
1410 else if (EQ (*all_frames
, Qvisible
))
1412 else if (XFASTINT (*all_frames
) == 0)
1414 else if (FRAMEP (*all_frames
))
1416 else if (!EQ (*all_frames
, Qt
))
1419 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1420 search just current frame, `visible' meaning search just visible
1421 frames, 0 meaning search visible and iconified frames, or a
1422 window, meaning search the frame that window belongs to, or a
1423 frame, meaning consider windows on that frame, only. */
1427 /* Return the next or previous window of WINDOW in canonical ordering
1428 of windows. NEXT_P non-zero means return the next window. See the
1429 documentation string of next-window for the meaning of MINIBUF and
1433 next_window (window
, minibuf
, all_frames
, next_p
)
1434 Lisp_Object window
, minibuf
, all_frames
;
1437 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1439 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1440 return the first window on the frame. */
1441 if (FRAMEP (all_frames
)
1442 && !EQ (all_frames
, XWINDOW (window
)->frame
))
1443 return Fframe_first_window (all_frames
);
1449 /* Find WINDOW in the list of all windows. */
1450 list
= Fmemq (window
, window_list ());
1452 /* Scan forward from WINDOW to the end of the window list. */
1454 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
1455 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1458 /* Scan from the start of the window list up to WINDOW. */
1460 for (list
= Vwindow_list
;
1461 CONSP (list
) && !EQ (XCAR (list
), window
);
1463 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
1467 window
= XCAR (list
);
1471 Lisp_Object candidate
, list
;
1473 /* Scan through the list of windows for candidates. If there are
1474 candidate windows in front of WINDOW, the last one of these
1475 is the one we want. If there are candidates following WINDOW
1476 in the list, again the last one of these is the one we want. */
1478 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
1480 if (EQ (XCAR (list
), window
))
1482 if (WINDOWP (candidate
))
1485 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
1487 candidate
= XCAR (list
);
1490 if (WINDOWP (candidate
))
1498 /* This comment supplies the doc string for `next-window',
1499 for make-docfile to see. We cannot put this in the real DEFUN
1500 due to limits in the Unix cpp.
1502 DEFUN ("next-window", Ffoo, Sfoo, 0, 3, 0,
1503 "Return next window after WINDOW in canonical ordering of windows.\n\
1504 If omitted, WINDOW defaults to the selected window.\n\
1506 Optional second arg MINIBUF t means count the minibuffer window even\n\
1507 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1508 it is active. MINIBUF neither t nor nil means not to count the\n\
1509 minibuffer even if it is active.\n\
1511 Several frames may share a single minibuffer; if the minibuffer\n\
1512 counts, all windows on all frames that share that minibuffer count\n\
1513 too. Therefore, `next-window' can be used to iterate through the\n\
1514 set of windows even when the minibuffer is on another frame. If the\n\
1515 minibuffer does not count, only windows from WINDOW's frame count.\n\
1517 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1518 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1519 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1520 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1521 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1522 Anything else means restrict to WINDOW's frame.\n\
1524 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1525 `next-window' to iterate through the entire cycle of acceptable\n\
1526 windows, eventually ending up back at the window you started with.\n\
1527 `previous-window' traverses the same cycle, in the reverse order.")
1528 (window, minibuf, all_frames) */
1530 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
1532 (window
, minibuf
, all_frames
)
1533 Lisp_Object window
, minibuf
, all_frames
;
1535 return next_window (window
, minibuf
, all_frames
, 1);
1539 /* This comment supplies the doc string for `previous-window',
1540 for make-docfile to see. We cannot put this in the real DEFUN
1541 due to limits in the Unix cpp.
1543 DEFUN ("previous-window", Ffoo, Sfoo, 0, 3, 0,
1544 "Return the window preceding WINDOW in canonical ordering of windows.\n\
1545 If omitted, WINDOW defaults to the selected window.\n\
1547 Optional second arg MINIBUF t means count the minibuffer window even\n\
1548 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1549 it is active. MINIBUF neither t nor nil means not to count the\n\
1550 minibuffer even if it is active.\n\
1552 Several frames may share a single minibuffer; if the minibuffer\n\
1553 counts, all windows on all frames that share that minibuffer count\n\
1554 too. Therefore, `previous-window' can be used to iterate through\n\
1555 the set of windows even when the minibuffer is on another frame. If\n\
1556 the minibuffer does not count, only windows from WINDOW's frame count\n\
1558 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1559 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1560 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1561 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1562 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1563 Anything else means restrict to WINDOW's frame.\n\
1565 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1566 `previous-window' to iterate through the entire cycle of acceptable\n\
1567 windows, eventually ending up back at the window you started with.\n\
1568 `next-window' traverses the same cycle, in the reverse order.")
1569 (window, minibuf, all_frames) */
1572 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1574 (window
, minibuf
, all_frames
)
1575 Lisp_Object window
, minibuf
, all_frames
;
1577 return next_window (window
, minibuf
, all_frames
, 0);
1581 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1582 "Select the ARG'th different window on this frame.\n\
1583 All windows on current frame are arranged in a cyclic order.\n\
1584 This command selects the window ARG steps away in that order.\n\
1585 A negative ARG moves in the opposite order. If the optional second\n\
1586 argument ALL_FRAMES is non-nil, cycle through all frames.")
1588 Lisp_Object arg
, all_frames
;
1593 CHECK_NUMBER (arg
, 0);
1594 window
= selected_window
;
1596 for (i
= XINT (arg
); i
> 0; --i
)
1597 window
= Fnext_window (window
, Qnil
, all_frames
);
1599 window
= Fprevious_window (window
, Qnil
, all_frames
);
1601 Fselect_window (window
);
1606 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
1607 "Return a list of windows on FRAME, starting with WINDOW.\n\
1608 FRAME nil or omitted means use the selected frame.\n\
1609 WINDOW nil or omitted means use the selected window.\n\
1610 MINIBUF t means include the minibuffer window, even if it isn't active.\n\
1611 MINIBUF nil or omitted means include the minibuffer window only\n\
1613 MINIBUF neither nil nor t means never include the minibuffer window.")
1614 (frame
, minibuf
, window
)
1615 Lisp_Object frame
, minibuf
, window
;
1620 window
= selected_window
;
1622 frame
= selected_frame
;
1624 if (!EQ (frame
, XWINDOW (window
)->frame
))
1625 error ("Window is on a different frame");
1627 return window_list_1 (window
, minibuf
, frame
);
1631 /* Return a list of windows in canonical ordering. Arguments are like
1632 for `next-window'. */
1635 window_list_1 (window
, minibuf
, all_frames
)
1636 Lisp_Object window
, minibuf
, all_frames
;
1638 Lisp_Object tail
, list
;
1640 decode_next_window_args (&window
, &minibuf
, &all_frames
);
1643 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
1644 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
1645 list
= Fcons (XCAR (tail
), list
);
1647 return Fnreverse (list
);
1652 /* Look at all windows, performing an operation specified by TYPE
1654 If FRAMES is Qt, look at all frames;
1655 Qnil, look at just the selected frame;
1656 Qvisible, look at visible frames;
1657 a frame, just look at windows on that frame.
1658 If MINI is non-zero, perform the operation on minibuffer windows too.
1664 GET_BUFFER_WINDOW
, /* Arg is buffer */
1665 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1666 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1667 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1669 UNSHOW_BUFFER
, /* Arg is buffer */
1674 window_loop (type
, obj
, mini
, frames
)
1675 enum window_loop type
;
1676 Lisp_Object obj
, frames
;
1679 Lisp_Object window
, windows
, best_window
, frame_arg
;
1681 struct gcpro gcpro1
;
1683 /* If we're only looping through windows on a particular frame,
1684 frame points to that frame. If we're looping through windows
1685 on all frames, frame is 0. */
1686 if (FRAMEP (frames
))
1687 f
= XFRAME (frames
);
1688 else if (NILP (frames
))
1689 f
= SELECTED_FRAME ();
1694 frame_arg
= Qlambda
;
1695 else if (XFASTINT (frames
) == 0)
1697 else if (EQ (frames
, Qvisible
))
1702 /* frame_arg is Qlambda to stick to one frame,
1703 Qvisible to consider all visible frames,
1706 /* Pick a window to start with. */
1710 window
= FRAME_SELECTED_WINDOW (f
);
1712 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
1714 /* Figure out the last window we're going to mess with. Since
1715 Fnext_window, given the same options, is guaranteed to go in a
1716 ring, we can just use Fprevious_window to find the last one.
1718 We can't just wait until we hit the first window again, because
1719 it might be deleted. */
1721 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
1725 for (; CONSP (windows
); windows
= CDR (windows
))
1729 window
= XCAR (windows
);
1730 w
= XWINDOW (window
);
1732 /* Note that we do not pay attention here to whether the frame
1733 is visible, since Fwindow_list skips non-visible frames if
1734 that is desired, under the control of frame_arg. */
1735 if (!MINI_WINDOW_P (w
)
1736 /* For UNSHOW_BUFFER, we must always consider all windows. */
1737 || type
== UNSHOW_BUFFER
1738 || (mini
&& minibuf_level
> 0))
1741 case GET_BUFFER_WINDOW
:
1742 if (EQ (w
->buffer
, obj
)
1743 /* Don't find any minibuffer window
1744 except the one that is currently in use. */
1745 && (MINI_WINDOW_P (w
)
1746 ? EQ (window
, minibuf_window
)
1754 case GET_LRU_WINDOW
:
1755 /* t as arg means consider only full-width windows */
1756 if (!NILP (obj
) && !WINDOW_FULL_WIDTH_P (w
))
1758 /* Ignore dedicated windows and minibuffers. */
1759 if (MINI_WINDOW_P (w
) || !NILP (w
->dedicated
))
1761 if (NILP (best_window
)
1762 || (XFASTINT (XWINDOW (best_window
)->use_time
)
1763 > XFASTINT (w
->use_time
)))
1764 best_window
= window
;
1767 case DELETE_OTHER_WINDOWS
:
1768 if (!EQ (window
, obj
))
1769 Fdelete_window (window
);
1772 case DELETE_BUFFER_WINDOWS
:
1773 if (EQ (w
->buffer
, obj
))
1775 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1777 /* If this window is dedicated, and in a frame of its own,
1779 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
1780 && !NILP (w
->dedicated
)
1781 && other_visible_frames (f
))
1783 /* Skip the other windows on this frame.
1784 There might be one, the minibuffer! */
1785 while (CONSP (XCDR (windows
))
1786 && EQ (XWINDOW (XCAR (windows
))->frame
,
1787 XWINDOW (XCAR (XCDR (windows
)))->frame
))
1788 windows
= XCDR (windows
);
1790 /* Now we can safely delete the frame. */
1791 Fdelete_frame (w
->frame
, Qnil
);
1793 else if (NILP (w
->parent
))
1795 /* If we're deleting the buffer displayed in the
1796 only window on the frame, find a new buffer to
1799 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
1801 buffer
= Fget_buffer_create (build_string ("*scratch*"));
1802 Fset_window_buffer (window
, buffer
);
1803 if (EQ (window
, selected_window
))
1804 Fset_buffer (w
->buffer
);
1807 Fdelete_window (window
);
1811 case GET_LARGEST_WINDOW
:
1813 /* Ignore dedicated windows and minibuffers. */
1814 if (MINI_WINDOW_P (w
) || !NILP (w
->dedicated
))
1817 if (NILP (best_window
))
1818 best_window
= window
;
1821 struct window
*b
= XWINDOW (best_window
);
1822 if (XFASTINT (w
->height
) * XFASTINT (w
->width
)
1823 > XFASTINT (b
->height
) * XFASTINT (b
->width
))
1824 best_window
= window
;
1830 if (EQ (w
->buffer
, obj
))
1833 struct frame
*f
= XFRAME (w
->frame
);
1835 /* Find another buffer to show in this window. */
1836 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
1838 buffer
= Fget_buffer_create (build_string ("*scratch*"));
1840 /* If this window is dedicated, and in a frame of its own,
1842 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
1843 && !NILP (w
->dedicated
)
1844 && other_visible_frames (f
))
1846 /* Skip the other windows on this frame.
1847 There might be one, the minibuffer! */
1848 while (CONSP (XCDR (windows
))
1849 && EQ (XWINDOW (XCAR (windows
))->frame
,
1850 XWINDOW (XCAR (XCDR (windows
)))->frame
))
1851 windows
= XCDR (windows
);
1853 /* Now we can safely delete the frame. */
1854 Fdelete_frame (w
->frame
, Qnil
);
1858 /* Otherwise show a different buffer in the window. */
1859 w
->dedicated
= Qnil
;
1860 Fset_window_buffer (window
, buffer
);
1861 if (EQ (window
, selected_window
))
1862 Fset_buffer (w
->buffer
);
1867 /* Check for a window that has a killed buffer. */
1868 case CHECK_ALL_WINDOWS
:
1869 if (! NILP (w
->buffer
)
1870 && NILP (XBUFFER (w
->buffer
)->name
))
1874 case WINDOW_LOOP_UNUSED
:
1883 /* Used for debugging. Abort if any window has a dead buffer. */
1886 check_all_windows ()
1888 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
1891 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 1, 0,
1892 "Return the window least recently selected or used for display.\n\
1893 If optional argument FRAME is `visible', search all visible frames.\n\
1894 If FRAME is 0, search all visible and iconified frames.\n\
1895 If FRAME is t, search all frames.\n\
1896 If FRAME is nil, search only the selected frame.\n\
1897 If FRAME is a frame, search only that frame.")
1901 register Lisp_Object w
;
1902 /* First try for a window that is full-width */
1903 w
= window_loop (GET_LRU_WINDOW
, Qt
, 0, frame
);
1904 if (!NILP (w
) && !EQ (w
, selected_window
))
1906 /* If none of them, try the rest */
1907 return window_loop (GET_LRU_WINDOW
, Qnil
, 0, frame
);
1910 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 1, 0,
1911 "Return the largest window in area.\n\
1912 If optional argument FRAME is `visible', search all visible frames.\n\
1913 If FRAME is 0, search all visible and iconified frames.\n\
1914 If FRAME is t, search all frames.\n\
1915 If FRAME is nil, search only the selected frame.\n\
1916 If FRAME is a frame, search only that frame.")
1920 return window_loop (GET_LARGEST_WINDOW
, Qnil
, 0,
1924 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
1925 "Return a window currently displaying BUFFER, or nil if none.\n\
1926 If optional argument FRAME is `visible', search all visible frames.\n\
1927 If optional argument FRAME is 0, search all visible and iconified frames.\n\
1928 If FRAME is t, search all frames.\n\
1929 If FRAME is nil, search only the selected frame.\n\
1930 If FRAME is a frame, search only that frame.")
1932 Lisp_Object buffer
, frame
;
1934 buffer
= Fget_buffer (buffer
);
1935 if (BUFFERP (buffer
))
1936 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
1941 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
1943 "Make WINDOW (or the selected window) fill its frame.\n\
1944 Only the frame WINDOW is on is affected.\n\
1945 This function tries to reduce display jumps\n\
1946 by keeping the text previously visible in WINDOW\n\
1947 in the same place on the frame. Doing this depends on\n\
1948 the value of (window-start WINDOW), so if calling this function\n\
1949 in a program gives strange scrolling, make sure the window-start\n\
1950 value is reasonable when this function is called.")
1959 window
= selected_window
;
1961 CHECK_LIVE_WINDOW (window
, 0);
1963 w
= XWINDOW (window
);
1965 startpos
= marker_position (w
->start
);
1966 top
= XFASTINT (w
->top
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
1968 if (MINI_WINDOW_P (w
) && top
> 0)
1969 error ("Can't expand minibuffer to full frame");
1971 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
1973 /* Try to minimize scrolling, by setting the window start to the point
1974 will cause the text at the old window start to be at the same place
1975 on the frame. But don't try to do this if the window start is
1976 outside the visible portion (as might happen when the display is
1977 not current, due to typeahead). */
1978 if (startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
1979 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
1981 struct position pos
;
1982 struct buffer
*obuf
= current_buffer
;
1984 Fset_buffer (w
->buffer
);
1985 /* This computation used to temporarily move point, but that can
1986 have unwanted side effects due to text properties. */
1987 pos
= *vmotion (startpos
, -top
, w
);
1989 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
1990 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
1991 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
1993 /* We need to do this, so that the window-scroll-functions
1995 w
->optional_new_start
= Qt
;
1997 set_buffer_internal (obuf
);
2003 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
2004 1, 2, "bDelete windows on (buffer): ",
2005 "Delete all windows showing BUFFER.\n\
2006 Optional second argument FRAME controls which frames are affected.\n\
2007 If optional argument FRAME is `visible', search all visible frames.\n\
2008 If FRAME is 0, search all visible and iconified frames.\n\
2009 If FRAME is nil, search all frames.\n\
2010 If FRAME is t, search only the selected frame.\n\
2011 If FRAME is a frame, search only that frame.")
2013 Lisp_Object buffer
, frame
;
2015 /* FRAME uses t and nil to mean the opposite of what window_loop
2019 else if (EQ (frame
, Qt
))
2024 buffer
= Fget_buffer (buffer
);
2025 CHECK_BUFFER (buffer
, 0);
2026 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
2032 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
2033 Sreplace_buffer_in_windows
,
2034 1, 1, "bReplace buffer in windows: ",
2035 "Replace BUFFER with some other buffer in all windows showing it.")
2041 buffer
= Fget_buffer (buffer
);
2042 CHECK_BUFFER (buffer
, 0);
2043 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
2048 /* Replace BUFFER with some other buffer in all windows
2049 of all frames, even those on other keyboards. */
2052 replace_buffer_in_all_windows (buffer
)
2056 Lisp_Object tail
, frame
;
2058 /* A single call to window_loop won't do the job
2059 because it only considers frames on the current keyboard.
2060 So loop manually over frames, and handle each one. */
2061 FOR_EACH_FRAME (tail
, frame
)
2062 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
2064 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
2068 /* Set the height of WINDOW and all its inferiors. */
2070 /* The smallest acceptable dimensions for a window. Anything smaller
2071 might crash Emacs. */
2073 #define MIN_SAFE_WINDOW_WIDTH (2)
2074 #define MIN_SAFE_WINDOW_HEIGHT (2)
2076 /* Make sure that window_min_height and window_min_width are
2077 not too small; if they are, set them to safe minima. */
2080 check_min_window_sizes ()
2082 /* Smaller values might permit a crash. */
2083 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
2084 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
2085 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
2086 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
2089 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2090 minimum allowable size. */
2093 check_frame_size (frame
, rows
, cols
)
2097 /* For height, we have to see:
2098 whether the frame has a minibuffer,
2099 whether it wants a mode line, and
2100 whether it has a menu bar. */
2102 (FRAME_MINIBUF_ONLY_P (frame
) ? MIN_SAFE_WINDOW_HEIGHT
- 1
2103 : (! FRAME_HAS_MINIBUF_P (frame
)) ? MIN_SAFE_WINDOW_HEIGHT
2104 : 2 * MIN_SAFE_WINDOW_HEIGHT
- 1);
2106 if (FRAME_TOP_MARGIN (frame
) > 0)
2107 min_height
+= FRAME_TOP_MARGIN (frame
);
2109 if (*rows
< min_height
)
2111 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2112 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2116 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2117 check if W's width can be changed, otherwise check W's height.
2118 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2119 siblings, too. If none of the siblings is resizable, WINDOW isn't
2123 window_fixed_size_p (w
, width_p
, check_siblings_p
)
2125 int width_p
, check_siblings_p
;
2130 if (!NILP (w
->hchild
))
2132 c
= XWINDOW (w
->hchild
);
2136 /* A horiz. combination is fixed-width if all of if its
2138 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2139 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2140 fixed_p
= c
== NULL
;
2144 /* A horiz. combination is fixed-height if one of if its
2146 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2147 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2148 fixed_p
= c
!= NULL
;
2151 else if (!NILP (w
->vchild
))
2153 c
= XWINDOW (w
->vchild
);
2157 /* A vert. combination is fixed-width if one of if its
2159 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2160 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2161 fixed_p
= c
!= NULL
;
2165 /* A vert. combination is fixed-height if all of if its
2167 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2168 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2169 fixed_p
= c
== NULL
;
2172 else if (BUFFERP (w
->buffer
))
2174 if (w
->height_fixed_p
&& !width_p
)
2178 struct buffer
*old
= current_buffer
;
2181 current_buffer
= XBUFFER (w
->buffer
);
2182 val
= find_symbol_value (Qwindow_size_fixed
);
2183 current_buffer
= old
;
2186 if (!EQ (val
, Qunbound
))
2188 fixed_p
= !NILP (val
);
2191 && ((EQ (val
, Qheight
) && width_p
)
2192 || (EQ (val
, Qwidth
) && !width_p
)))
2197 /* Can't tell if this one is resizable without looking at
2198 siblings. If all siblings are fixed-size this one is too. */
2199 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
2203 for (child
= w
->prev
; !NILP (child
); child
= XWINDOW (child
)->prev
)
2204 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2208 for (child
= w
->next
; !NILP (child
); child
= XWINDOW (child
)->next
)
2209 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2223 /* Return the minimum size of window W, not taking fixed-width windows
2224 into account. WIDTH_P non-zero means return the minimum width,
2225 otherwise return the minimum height. If W is a combination window,
2226 compute the minimum size from the minimum sizes of W's children. */
2229 window_min_size_1 (w
, width_p
)
2236 if (!NILP (w
->hchild
))
2238 c
= XWINDOW (w
->hchild
);
2243 /* The min width of a horizontal combination is
2244 the sum of the min widths of its children. */
2247 size
+= window_min_size_1 (c
, width_p
);
2248 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2253 /* The min height a horizontal combination equals
2254 the maximum of all min height of its children. */
2257 int min_size
= window_min_size_1 (c
, width_p
);
2258 size
= max (min_size
, size
);
2259 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2263 else if (!NILP (w
->vchild
))
2265 c
= XWINDOW (w
->vchild
);
2270 /* The min width of a vertical combination is
2271 the maximum of the min widths of its children. */
2274 int min_size
= window_min_size_1 (c
, width_p
);
2275 size
= max (min_size
, size
);
2276 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2281 /* The min height of a vertical combination equals
2282 the sum of the min height of its children. */
2285 size
+= window_min_size_1 (c
, width_p
);
2286 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2293 size
= window_min_width
;
2296 if (MINI_WINDOW_P (w
)
2297 || (!WINDOW_WANTS_MODELINE_P (w
)
2298 && !WINDOW_WANTS_HEADER_LINE_P (w
)))
2301 size
= window_min_height
;
2309 /* Return the minimum size of window W, taking fixed-size windows into
2310 account. WIDTH_P non-zero means return the minimum width,
2311 otherwise return the minimum height. IGNORE_FIXED_P non-zero means
2312 ignore if W is fixed-size. Set *FIXED to 1 if W is fixed-size
2313 unless FIXED is null. */
2316 window_min_size (w
, width_p
, ignore_fixed_p
, fixed
)
2318 int width_p
, ignore_fixed_p
, *fixed
;
2325 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
2331 size
= width_p
? XFASTINT (w
->width
) : XFASTINT (w
->height
);
2333 size
= window_min_size_1 (w
, width_p
);
2339 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
2340 WINDOW's width. Resize WINDOW's children, if any, so that they
2341 keep their proportionate size relative to WINDOW. Propagate
2342 WINDOW's top or left edge position to children. Delete windows
2343 that become too small unless NODELETE_P is non-zero. */
2346 size_window (window
, size
, width_p
, nodelete_p
)
2348 int size
, width_p
, nodelete_p
;
2350 struct window
*w
= XWINDOW (window
);
2352 Lisp_Object child
, *forward
, *sideward
;
2353 int old_size
, min_size
;
2355 check_min_window_sizes ();
2356 size
= max (0, size
);
2358 /* If the window has been "too small" at one point,
2359 don't delete it for being "too small" in the future.
2360 Preserve it as long as that is at all possible. */
2363 old_size
= XINT (w
->width
);
2364 min_size
= window_min_width
;
2368 old_size
= XINT (w
->height
);
2369 min_size
= window_min_height
;
2372 if (old_size
< window_min_width
)
2373 w
->too_small_ok
= Qt
;
2375 /* Maybe delete WINDOW if it's too small. */
2376 if (!nodelete_p
&& !NILP (w
->parent
))
2380 if (!MINI_WINDOW_P (w
) && !NILP (w
->too_small_ok
))
2381 min_size
= width_p
? MIN_SAFE_WINDOW_WIDTH
: MIN_SAFE_WINDOW_HEIGHT
;
2383 min_size
= width_p
? window_min_width
: window_min_height
;
2385 if (size
< min_size
)
2387 delete_window (window
);
2392 /* Set redisplay hints. */
2393 w
->last_modified
= make_number (0);
2394 w
->last_overlay_modified
= make_number (0);
2395 windows_or_buffers_changed
++;
2396 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w
->frame
)) = 1;
2400 sideward
= &w
->vchild
;
2401 forward
= &w
->hchild
;
2402 w
->width
= make_number (size
);
2406 sideward
= &w
->hchild
;
2407 forward
= &w
->vchild
;
2408 w
->height
= make_number (size
);
2411 if (!NILP (*sideward
))
2413 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
2415 c
= XWINDOW (child
);
2420 size_window (child
, size
, width_p
, nodelete_p
);
2423 else if (!NILP (*forward
))
2425 int fixed_size
, each
, extra
, n
;
2426 int resize_fixed_p
, nfixed
;
2427 int last_pos
, first_pos
, nchildren
, total
;
2429 /* Determine the fixed-size portion of the this window, and the
2430 number of child windows. */
2431 fixed_size
= nchildren
= nfixed
= total
= 0;
2432 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
2436 c
= XWINDOW (child
);
2437 child_size
= width_p
? XINT (c
->width
) : XINT (c
->height
);
2438 total
+= child_size
;
2440 if (window_fixed_size_p (c
, width_p
, 0))
2442 fixed_size
+= child_size
;
2447 /* If the new size is smaller than fixed_size, or if there
2448 aren't any resizable windows, allow resizing fixed-size
2450 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
2452 /* Compute how many lines/columns to add to each child. The
2453 value of extra takes care of rounding errors. */
2454 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
2455 each
= (size
- total
) / n
;
2456 extra
= (size
- total
) - n
* each
;
2458 /* Compute new children heights and edge positions. */
2459 first_pos
= width_p
? XINT (w
->left
) : XINT (w
->top
);
2460 last_pos
= first_pos
;
2461 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2463 int new_size
, old_size
;
2465 c
= XWINDOW (child
);
2466 old_size
= width_p
? XFASTINT (c
->width
) : XFASTINT (c
->height
);
2467 new_size
= old_size
;
2469 /* The top or left edge position of this child equals the
2470 bottom or right edge of its predecessor. */
2472 c
->left
= make_number (last_pos
);
2474 c
->top
= make_number (last_pos
);
2476 /* If this child can be resized, do it. */
2477 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
2479 new_size
= old_size
+ each
+ extra
;
2483 /* Set new height. Note that size_window also propagates
2484 edge positions to children, so it's not a no-op if we
2485 didn't change the child's size. */
2486 size_window (child
, new_size
, width_p
, 1);
2488 /* Remember the bottom/right edge position of this child; it
2489 will be used to set the top/left edge of the next child. */
2490 last_pos
+= new_size
;
2493 /* We should have covered the parent exactly with child windows. */
2494 xassert (size
== last_pos
- first_pos
);
2496 /* Now delete any children that became too small. */
2498 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2501 c
= XWINDOW (child
);
2502 child_size
= width_p
? XINT (c
->width
) : XINT (c
->height
);
2503 size_window (child
, child_size
, width_p
, 0);
2508 /* Set WINDOW's height to HEIGHT, and recursively change the height of
2509 WINDOW's children. NODELETE non-zero means don't delete windows
2510 that become too small in the process. (The caller should check
2511 later and do so if appropriate.) */
2514 set_window_height (window
, height
, nodelete
)
2519 size_window (window
, height
, 0, nodelete
);
2523 /* Set WINDOW's width to WIDTH, and recursively change the width of
2524 WINDOW's children. NODELETE non-zero means don't delete windows
2525 that become too small in the process. (The caller should check
2526 later and do so if appropriate.) */
2529 set_window_width (window
, width
, nodelete
)
2534 size_window (window
, width
, 1, nodelete
);
2538 int window_select_count
;
2541 Fset_window_buffer_unwind (obuf
)
2549 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
2550 means it's allowed to run hooks. See make_frame for a case where
2551 it's not allowed. */
2554 set_window_buffer (window
, buffer
, run_hooks_p
)
2555 Lisp_Object window
, buffer
;
2558 struct window
*w
= XWINDOW (window
);
2559 struct buffer
*b
= XBUFFER (buffer
);
2560 int count
= specpdl_ptr
- specpdl
;
2564 if (EQ (window
, selected_window
))
2565 b
->last_selected_window
= window
;
2567 /* Update time stamps of buffer display. */
2568 if (INTEGERP (b
->display_count
))
2569 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
2570 b
->display_time
= Fcurrent_time ();
2572 XSETFASTINT (w
->window_end_pos
, 0);
2573 XSETFASTINT (w
->window_end_vpos
, 0);
2574 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
2575 w
->window_end_valid
= Qnil
;
2576 XSETFASTINT (w
->hscroll
, 0);
2577 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
2578 set_marker_restricted (w
->start
,
2579 make_number (b
->last_window_start
),
2581 w
->start_at_line_beg
= Qnil
;
2582 w
->force_start
= Qnil
;
2583 XSETFASTINT (w
->last_modified
, 0);
2584 XSETFASTINT (w
->last_overlay_modified
, 0);
2585 windows_or_buffers_changed
++;
2587 /* We must select BUFFER for running the window-scroll-functions.
2588 If WINDOW is selected, switch permanently.
2589 Otherwise, switch but go back to the ambient buffer afterward. */
2590 if (EQ (window
, selected_window
))
2591 Fset_buffer (buffer
);
2592 /* We can't check ! NILP (Vwindow_scroll_functions) here
2593 because that might itself be a local variable. */
2594 else if (window_initialized
)
2596 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
2597 Fset_buffer (buffer
);
2600 /* Set left and right marginal area width from buffer. */
2601 Fset_window_margins (window
, b
->left_margin_width
, b
->right_margin_width
);
2605 if (! NILP (Vwindow_scroll_functions
))
2606 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2607 Fmarker_position (w
->start
));
2609 if (! NILP (Vwindow_configuration_change_hook
)
2610 && ! NILP (Vrun_hooks
))
2611 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2614 unbind_to (count
, Qnil
);
2618 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 2, 0,
2619 "Make WINDOW display BUFFER as its contents.\n\
2620 BUFFER can be a buffer or buffer name.")
2622 register Lisp_Object window
, buffer
;
2624 register Lisp_Object tem
;
2625 register struct window
*w
= decode_window (window
);
2627 XSETWINDOW (window
, w
);
2628 buffer
= Fget_buffer (buffer
);
2629 CHECK_BUFFER (buffer
, 1);
2631 if (NILP (XBUFFER (buffer
)->name
))
2632 error ("Attempt to display deleted buffer");
2636 error ("Window is deleted");
2637 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
2638 is first being set up. */
2640 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
2641 error ("Window is dedicated to `%s'",
2642 XSTRING (XBUFFER (tem
)->name
)->data
);
2647 set_window_buffer (window
, buffer
, 1);
2651 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 1, 0,
2652 "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\
2653 If WINDOW is not already selected, also make WINDOW's buffer current.\n\
2654 Note that the main editor command loop\n\
2655 selects the buffer of the selected window before each command.")
2657 register Lisp_Object window
;
2659 return select_window_1 (window
, 1);
2662 /* Note that selected_window can be nil
2663 when this is called from Fset_window_configuration. */
2666 select_window_1 (window
, recordflag
)
2667 register Lisp_Object window
;
2670 register struct window
*w
;
2671 register struct window
*ow
;
2674 CHECK_LIVE_WINDOW (window
, 0);
2676 w
= XWINDOW (window
);
2678 if (NILP (w
->buffer
))
2679 error ("Trying to select deleted window or non-leaf window");
2681 XSETFASTINT (w
->use_time
, ++window_select_count
);
2682 if (EQ (window
, selected_window
))
2685 if (!NILP (selected_window
))
2687 ow
= XWINDOW (selected_window
);
2688 if (! NILP (ow
->buffer
))
2689 set_marker_both (ow
->pointm
, ow
->buffer
,
2690 BUF_PT (XBUFFER (ow
->buffer
)),
2691 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
2694 selected_window
= window
;
2695 sf
= SELECTED_FRAME ();
2696 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
2698 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
2699 /* Use this rather than Fhandle_switch_frame
2700 so that FRAME_FOCUS_FRAME is moved appropriately as we
2701 move around in the state where a minibuffer in a separate
2703 Fselect_frame (WINDOW_FRAME (w
), Qnil
);
2706 sf
->selected_window
= window
;
2709 record_buffer (w
->buffer
);
2710 Fset_buffer (w
->buffer
);
2712 XBUFFER (w
->buffer
)->last_selected_window
= window
;
2714 /* Go to the point recorded in the window.
2715 This is important when the buffer is in more
2716 than one window. It also matters when
2717 redisplay_window has altered point after scrolling,
2718 because it makes the change only in the window. */
2720 register int new_point
= marker_position (w
->pointm
);
2721 if (new_point
< BEGV
)
2723 else if (new_point
> ZV
)
2729 windows_or_buffers_changed
++;
2733 /* Deiconify the frame containing the window WINDOW,
2734 unless it is the selected frame;
2737 The reason for the exception for the selected frame
2738 is that it seems better not to change the selected frames visibility
2739 merely because of displaying a different buffer in it.
2740 The deiconification is useful when a buffer gets shown in
2741 another frame that you were not using lately. */
2744 display_buffer_1 (window
)
2747 Lisp_Object frame
= XWINDOW (window
)->frame
;
2748 FRAME_PTR f
= XFRAME (frame
);
2750 FRAME_SAMPLE_VISIBILITY (f
);
2752 if (!EQ (frame
, selected_frame
))
2754 if (FRAME_ICONIFIED_P (f
))
2755 Fmake_frame_visible (frame
);
2756 else if (FRAME_VISIBLE_P (f
))
2757 Fraise_frame (frame
);
2763 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
2764 "Returns non-nil if a buffer named BUFFER-NAME would be created specially.\n\
2765 The value is actually t if the frame should be called with default frame\n\
2766 parameters, and a list of frame parameters if they were specified.\n\
2767 See `special-display-buffer-names', and `special-display-regexps'.")
2769 Lisp_Object buffer_name
;
2773 CHECK_STRING (buffer_name
, 1);
2775 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
2779 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
2783 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2785 Lisp_Object car
= XCAR (tem
);
2787 && fast_string_match (car
, buffer_name
) >= 0)
2789 else if (CONSP (car
)
2790 && STRINGP (XCAR (car
))
2791 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2797 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
2798 "Returns non-nil if a new buffer named BUFFER-NAME would use the same window.\n\
2799 See `same-window-buffer-names' and `same-window-regexps'.")
2801 Lisp_Object buffer_name
;
2805 CHECK_STRING (buffer_name
, 1);
2807 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
2811 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
2815 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2817 Lisp_Object car
= XCAR (tem
);
2819 && fast_string_match (car
, buffer_name
) >= 0)
2821 else if (CONSP (car
)
2822 && STRINGP (XCAR (car
))
2823 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2829 /* Use B so the default is (other-buffer). */
2830 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
2831 "BDisplay buffer: \nP",
2832 "Make BUFFER appear in some window but don't select it.\n\
2833 BUFFER can be a buffer or a buffer name.\n\
2834 If BUFFER is shown already in some window, just use that one,\n\
2835 unless the window is the selected window and the optional second\n\
2836 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).\n\
2837 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.\n\
2838 Returns the window displaying BUFFER.\n\
2839 If `display-reuse-frames' is non-nil, and another frame is currently\n\
2840 displaying BUFFER, then simply raise that frame.\n\
2842 The variables `special-display-buffer-names', `special-display-regexps',\n\
2843 `same-window-buffer-names', and `same-window-regexps' customize how certain\n\
2844 buffer names are handled.\n\
2846 If optional argument FRAME is `visible', search all visible frames.\n\
2847 If FRAME is 0, search all visible and iconified frames.\n\
2848 If FRAME is t, search all frames.\n\
2849 If FRAME is a frame, search only that frame.\n\
2850 If FRAME is nil, search only the selected frame\n\
2851 (actually the last nonminibuffer frame),\n\
2852 unless `pop-up-frames' or `display-buffer-reuse-frames' is non-nil,\n\
2853 which means search visible and iconified frames.\n\
2855 If `even-window-heights' is non-nil, window heights will be evened out\n\
2856 if displaying the buffer causes two vertically\ adjacent windows to be\n\
2858 (buffer
, not_this_window
, frame
)
2859 register Lisp_Object buffer
, not_this_window
, frame
;
2861 register Lisp_Object window
, tem
, swp
;
2865 buffer
= Fget_buffer (buffer
);
2866 CHECK_BUFFER (buffer
, 0);
2868 if (!NILP (Vdisplay_buffer_function
))
2869 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
2871 if (NILP (not_this_window
)
2872 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
2873 return display_buffer_1 (selected_window
);
2875 /* See if the user has specified this buffer should appear
2876 in the selected window. */
2877 if (NILP (not_this_window
))
2879 swp
= Fsame_window_p (XBUFFER (buffer
)->name
);
2880 if (!NILP (swp
) && !no_switch_window (selected_window
))
2882 Fswitch_to_buffer (buffer
, Qnil
);
2883 return display_buffer_1 (selected_window
);
2887 /* If the user wants pop-up-frames or display-reuse-frames, then
2888 look for a window showing BUFFER on any visible or iconified frame.
2889 Otherwise search only the current frame. */
2892 else if (pop_up_frames
2893 || display_buffer_reuse_frames
2894 || last_nonminibuf_frame
== 0)
2895 XSETFASTINT (tem
, 0);
2897 XSETFRAME (tem
, last_nonminibuf_frame
);
2899 window
= Fget_buffer_window (buffer
, tem
);
2901 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
2902 return display_buffer_1 (window
);
2904 /* Certain buffer names get special handling. */
2905 if (!NILP (Vspecial_display_function
) && NILP (swp
))
2907 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
2909 return call1 (Vspecial_display_function
, buffer
);
2911 return call2 (Vspecial_display_function
, buffer
, tem
);
2914 /* If there are no frames open that have more than a minibuffer,
2915 we need to create a new frame. */
2916 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2918 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2919 Fset_window_buffer (window
, buffer
);
2920 return display_buffer_1 (window
);
2923 f
= SELECTED_FRAME ();
2925 || FRAME_MINIBUF_ONLY_P (f
)
2926 /* If the current frame is a special display frame,
2927 don't try to reuse its windows. */
2928 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (f
))->dedicated
))
2933 if (FRAME_MINIBUF_ONLY_P (f
))
2934 XSETFRAME (frames
, last_nonminibuf_frame
);
2935 /* Don't try to create a window if would get an error */
2936 if (split_height_threshold
< window_min_height
<< 1)
2937 split_height_threshold
= window_min_height
<< 1;
2939 /* Note that both Fget_largest_window and Fget_lru_window
2940 ignore minibuffers and dedicated windows.
2941 This means they can return nil. */
2943 /* If the frame we would try to split cannot be split,
2944 try other frames. */
2945 if (FRAME_NO_SPLIT_P (NILP (frames
) ? f
: last_nonminibuf_frame
))
2947 /* Try visible frames first. */
2948 window
= Fget_largest_window (Qvisible
);
2949 /* If that didn't work, try iconified frames. */
2951 window
= Fget_largest_window (make_number (0));
2953 window
= Fget_largest_window (Qt
);
2956 window
= Fget_largest_window (frames
);
2958 /* If we got a tall enough full-width window that can be split,
2961 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2962 && window_height (window
) >= split_height_threshold
2963 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
2964 window
= Fsplit_window (window
, Qnil
, Qnil
);
2967 Lisp_Object upper
, lower
, other
;
2969 window
= Fget_lru_window (frames
);
2970 /* If the LRU window is selected, and big enough,
2971 and can be split, split it. */
2973 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2974 && (EQ (window
, selected_window
)
2975 || EQ (XWINDOW (window
)->parent
, Qnil
))
2976 && window_height (window
) >= window_min_height
<< 1)
2977 window
= Fsplit_window (window
, Qnil
, Qnil
);
2978 /* If Fget_lru_window returned nil, try other approaches. */
2980 /* Try visible frames first. */
2982 window
= Fget_buffer_window (buffer
, Qvisible
);
2984 window
= Fget_largest_window (Qvisible
);
2985 /* If that didn't work, try iconified frames. */
2987 window
= Fget_buffer_window (buffer
, make_number (0));
2989 window
= Fget_largest_window (make_number (0));
2990 /* Try invisible frames. */
2992 window
= Fget_buffer_window (buffer
, Qt
);
2994 window
= Fget_largest_window (Qt
);
2995 /* As a last resort, make a new frame. */
2997 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2998 /* If window appears above or below another,
2999 even out their heights. */
3000 other
= upper
= lower
= Qnil
;
3001 if (!NILP (XWINDOW (window
)->prev
))
3002 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
3003 if (!NILP (XWINDOW (window
)->next
))
3004 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
3006 && !NILP (Veven_window_heights
)
3007 /* Check that OTHER and WINDOW are vertically arrayed. */
3008 && !EQ (XWINDOW (other
)->top
, XWINDOW (window
)->top
)
3009 && (XFASTINT (XWINDOW (other
)->height
)
3010 > XFASTINT (XWINDOW (window
)->height
)))
3012 int total
= (XFASTINT (XWINDOW (other
)->height
)
3013 + XFASTINT (XWINDOW (window
)->height
));
3014 enlarge_window (upper
,
3015 total
/ 2 - XFASTINT (XWINDOW (upper
)->height
),
3021 window
= Fget_lru_window (Qnil
);
3023 Fset_window_buffer (window
, buffer
);
3024 return display_buffer_1 (window
);
3028 temp_output_buffer_show (buf
)
3029 register Lisp_Object buf
;
3031 register struct buffer
*old
= current_buffer
;
3032 register Lisp_Object window
;
3033 register struct window
*w
;
3035 XBUFFER (buf
)->directory
= current_buffer
->directory
;
3038 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3042 XBUFFER (buf
)->prevent_redisplay_optimizations_p
= 1;
3043 set_buffer_internal (old
);
3045 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
3046 call1 (Vtemp_buffer_show_function
, buf
);
3049 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
3051 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3052 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3053 Vminibuf_scroll_window
= window
;
3054 w
= XWINDOW (window
);
3055 XSETFASTINT (w
->hscroll
, 0);
3056 set_marker_restricted_both (w
->start
, buf
, 1, 1);
3057 set_marker_restricted_both (w
->pointm
, buf
, 1, 1);
3059 /* Run temp-buffer-show-hook, with the chosen window selected
3060 and it sbuffer current. */
3061 if (!NILP (Vrun_hooks
))
3064 tem
= Fboundp (Qtemp_buffer_show_hook
);
3067 tem
= Fsymbol_value (Qtemp_buffer_show_hook
);
3070 int count
= specpdl_ptr
- specpdl
;
3071 Lisp_Object prev_window
;
3072 prev_window
= selected_window
;
3074 /* Select the window that was chosen, for running the hook. */
3075 record_unwind_protect (Fselect_window
, prev_window
);
3076 select_window_1 (window
, 0);
3077 Fset_buffer (w
->buffer
);
3078 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
3079 select_window_1 (prev_window
, 0);
3080 unbind_to (count
, Qnil
);
3088 make_dummy_parent (window
)
3092 register struct window
*o
, *p
;
3093 register struct Lisp_Vector
*vec
;
3096 o
= XWINDOW (window
);
3097 vec
= allocate_vectorlike ((EMACS_INT
)VECSIZE (struct window
));
3098 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
3099 vec
->contents
[i
] = ((struct Lisp_Vector
*)o
)->contents
[i
];
3100 vec
->size
= VECSIZE (struct window
);
3101 p
= (struct window
*)vec
;
3102 XSETWINDOW (new, p
);
3104 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
3106 /* Put new into window structure in place of window */
3107 replace_window (window
, new);
3120 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
3121 "Split WINDOW, putting SIZE lines in the first of the pair.\n\
3122 WINDOW defaults to selected one and SIZE to half its size.\n\
3123 If optional third arg HORFLAG is non-nil, split side by side\n\
3124 and put SIZE columns in the first of the pair. In that case,\n\
3125 SIZE includes that window's scroll bar, or the divider column to its right.")
3126 (window
, size
, horflag
)
3127 Lisp_Object window
, size
, horflag
;
3129 register Lisp_Object
new;
3130 register struct window
*o
, *p
;
3132 register int size_int
;
3135 window
= selected_window
;
3137 CHECK_LIVE_WINDOW (window
, 0);
3139 o
= XWINDOW (window
);
3140 fo
= XFRAME (WINDOW_FRAME (o
));
3144 if (!NILP (horflag
))
3145 /* Calculate the size of the left-hand window, by dividing
3146 the usable space in columns by two.
3147 We round up, since the left-hand window may include
3148 a dividing line, while the right-hand may not. */
3149 size_int
= (XFASTINT (o
->width
) + 1) >> 1;
3151 size_int
= XFASTINT (o
->height
) >> 1;
3155 CHECK_NUMBER (size
, 1);
3156 size_int
= XINT (size
);
3159 if (MINI_WINDOW_P (o
))
3160 error ("Attempt to split minibuffer window");
3161 else if (window_fixed_size_p (o
, !NILP (horflag
), 0))
3162 error ("Attempt to split fixed-size window");
3164 check_min_window_sizes ();
3168 if (size_int
< window_min_height
)
3169 error ("Window height %d too small (after splitting)", size_int
);
3170 if (size_int
+ window_min_height
> XFASTINT (o
->height
))
3171 error ("Window height %d too small (after splitting)",
3172 XFASTINT (o
->height
) - size_int
);
3173 if (NILP (o
->parent
)
3174 || NILP (XWINDOW (o
->parent
)->vchild
))
3176 make_dummy_parent (window
);
3178 XWINDOW (new)->vchild
= window
;
3183 if (size_int
< window_min_width
)
3184 error ("Window width %d too small (after splitting)", size_int
);
3186 if (size_int
+ window_min_width
> XFASTINT (o
->width
))
3187 error ("Window width %d too small (after splitting)",
3188 XFASTINT (o
->width
) - size_int
);
3189 if (NILP (o
->parent
)
3190 || NILP (XWINDOW (o
->parent
)->hchild
))
3192 make_dummy_parent (window
);
3194 XWINDOW (new)->hchild
= window
;
3198 /* Now we know that window's parent is a vertical combination
3199 if we are dividing vertically, or a horizontal combination
3200 if we are making side-by-side windows */
3202 windows_or_buffers_changed
++;
3203 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
3204 new = make_window ();
3207 p
->frame
= o
->frame
;
3209 if (!NILP (p
->next
))
3210 XWINDOW (p
->next
)->prev
= new;
3213 p
->parent
= o
->parent
;
3215 p
->window_end_valid
= Qnil
;
3216 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
3218 /* Apportion the available frame space among the two new windows */
3220 if (!NILP (horflag
))
3222 p
->height
= o
->height
;
3224 XSETFASTINT (p
->width
, XFASTINT (o
->width
) - size_int
);
3225 XSETFASTINT (o
->width
, size_int
);
3226 XSETFASTINT (p
->left
, XFASTINT (o
->left
) + size_int
);
3231 p
->width
= o
->width
;
3232 XSETFASTINT (p
->height
, XFASTINT (o
->height
) - size_int
);
3233 XSETFASTINT (o
->height
, size_int
);
3234 XSETFASTINT (p
->top
, XFASTINT (o
->top
) + size_int
);
3237 /* Adjust glyph matrices. */
3239 Fset_window_buffer (new, o
->buffer
);
3243 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
3244 "Make current window ARG lines bigger.\n\
3245 From program, optional second arg non-nil means grow sideways ARG columns.")
3247 register Lisp_Object arg
, side
;
3249 CHECK_NUMBER (arg
, 0);
3250 enlarge_window (selected_window
, XINT (arg
), !NILP (side
));
3252 if (! NILP (Vwindow_configuration_change_hook
))
3253 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3258 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
3259 "Make current window ARG lines smaller.\n\
3260 From program, optional second arg non-nil means shrink sideways arg columns.")
3262 register Lisp_Object arg
, side
;
3264 CHECK_NUMBER (arg
, 0);
3265 enlarge_window (selected_window
, -XINT (arg
), !NILP (side
));
3267 if (! NILP (Vwindow_configuration_change_hook
))
3268 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3274 window_height (window
)
3277 register struct window
*p
= XWINDOW (window
);
3278 return XFASTINT (p
->height
);
3282 window_width (window
)
3285 register struct window
*p
= XWINDOW (window
);
3286 return XFASTINT (p
->width
);
3291 *(widthflag ? &(XWINDOW (w)->left) : &(XWINDOW (w)->top))
3293 #define CURSIZE(w) \
3294 *(widthflag ? &(XWINDOW (w)->width) : &(XWINDOW (w)->height))
3297 /* Enlarge selected_window by DELTA. WIDTHFLAG non-zero means
3298 increase its width. Siblings of the selected window are resized to
3299 fullfil the size request. If they become too small in the process,
3300 they will be deleted. */
3303 enlarge_window (window
, delta
, widthflag
)
3305 int delta
, widthflag
;
3307 Lisp_Object parent
, next
, prev
;
3311 int (*sizefun
) P_ ((Lisp_Object
))
3312 = widthflag
? window_width
: window_height
;
3313 void (*setsizefun
) P_ ((Lisp_Object
, int, int))
3314 = (widthflag
? set_window_width
: set_window_height
);
3316 /* Check values of window_min_width and window_min_height for
3318 check_min_window_sizes ();
3320 /* Give up if this window cannot be resized. */
3321 if (window_fixed_size_p (XWINDOW (window
), widthflag
, 1))
3322 error ("Window is not resizable");
3324 /* Find the parent of the selected window. */
3327 p
= XWINDOW (window
);
3333 error ("No other window to side of this one");
3338 ? !NILP (XWINDOW (parent
)->hchild
)
3339 : !NILP (XWINDOW (parent
)->vchild
))
3345 sizep
= &CURSIZE (window
);
3348 register int maxdelta
;
3350 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - XINT (*sizep
)
3351 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
3352 - window_min_size (XWINDOW (p
->next
),
3354 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
3355 - window_min_size (XWINDOW (p
->prev
),
3357 /* This is a frame with only one window, a minibuffer-only
3358 or a minibufferless frame. */
3361 if (delta
> maxdelta
)
3362 /* This case traps trying to make the minibuffer
3363 the full frame, or make the only window aside from the
3364 minibuffer the full frame. */
3368 if (XINT (*sizep
) + delta
< window_min_size (XWINDOW (window
), widthflag
, 0, 0))
3370 delete_window (window
);
3377 /* Find the total we can get from other siblings. */
3379 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
3380 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
3382 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
3383 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
3386 /* If we can get it all from them, do so. */
3387 if (delta
<= maximum
)
3389 Lisp_Object first_unaffected
;
3390 Lisp_Object first_affected
;
3395 first_affected
= window
;
3396 /* Look at one sibling at a time,
3397 moving away from this window in both directions alternately,
3398 and take as much as we can get without deleting that sibling. */
3399 while (delta
!= 0 && (!NILP (next
) || !NILP (prev
)))
3403 int this_one
= ((*sizefun
) (next
)
3404 - window_min_size (XWINDOW (next
),
3405 widthflag
, 0, &fixed_p
));
3408 if (this_one
> delta
)
3411 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
3412 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
3417 next
= XWINDOW (next
)->next
;
3425 int this_one
= ((*sizefun
) (prev
)
3426 - window_min_size (XWINDOW (prev
),
3427 widthflag
, 0, &fixed_p
));
3430 if (this_one
> delta
)
3433 first_affected
= prev
;
3435 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
3436 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
3441 prev
= XWINDOW (prev
)->prev
;
3445 xassert (delta
== 0);
3447 /* Now recalculate the edge positions of all the windows affected,
3448 based on the new sizes. */
3449 first_unaffected
= next
;
3450 prev
= first_affected
;
3451 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
3452 prev
= next
, next
= XWINDOW (next
)->next
)
3454 XSETINT (CURBEG (next
), XINT (CURBEG (prev
)) + (*sizefun
) (prev
));
3455 /* This does not change size of NEXT,
3456 but it propagates the new top edge to its children */
3457 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
3462 register int delta1
;
3463 register int opht
= (*sizefun
) (parent
);
3465 /* If trying to grow this window to or beyond size of the parent,
3466 make delta1 so big that, on shrinking back down,
3467 all the siblings end up with less than one line and are deleted. */
3468 if (opht
<= XINT (*sizep
) + delta
)
3469 delta1
= opht
* opht
* 2;
3472 /* Otherwise, make delta1 just right so that if we add
3473 delta1 lines to this window and to the parent, and then
3474 shrink the parent back to its original size, the new
3475 proportional size of this window will increase by delta.
3477 The function size_window will compute the new height h'
3478 of the window from delta1 as:
3481 x = delta1 - delta1/n * n for the 1st resizable child
3484 where n is the number of children that can be resized.
3485 We can ignore x by choosing a delta1 that is a multiple of
3486 n. We want the height of this window to come out as
3496 The number of children n rquals the number of resizable
3497 children of this window + 1 because we know window itself
3498 is resizable (otherwise we would have signalled an error. */
3500 struct window
*w
= XWINDOW (window
);
3504 for (s
= w
->next
; !NILP (s
); s
= XWINDOW (s
)->next
)
3505 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
3507 for (s
= w
->prev
; !NILP (s
); s
= XWINDOW (s
)->prev
)
3508 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
3514 /* Add delta1 lines or columns to this window, and to the parent,
3515 keeping things consistent while not affecting siblings. */
3516 XSETINT (CURSIZE (parent
), opht
+ delta1
);
3517 (*setsizefun
) (window
, XINT (*sizep
) + delta1
, 0);
3519 /* Squeeze out delta1 lines or columns from our parent,
3520 shriking this window and siblings proportionately.
3521 This brings parent back to correct size.
3522 Delta1 was calculated so this makes this window the desired size,
3523 taking it all out of the siblings. */
3524 (*setsizefun
) (parent
, opht
, 0);
3527 XSETFASTINT (p
->last_modified
, 0);
3528 XSETFASTINT (p
->last_overlay_modified
, 0);
3530 /* Adjust glyph matrices. */
3531 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
3539 /***********************************************************************
3540 Resizing Mini-Windows
3541 ***********************************************************************/
3543 static void shrink_window_lowest_first
P_ ((struct window
*, int));
3545 enum save_restore_action
3552 static int save_restore_orig_size
P_ ((struct window
*,
3553 enum save_restore_action
));
3555 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
3556 from lowest windows first. */
3559 shrink_window_lowest_first (w
, height
)
3567 xassert (!MINI_WINDOW_P (w
));
3569 /* Set redisplay hints. */
3570 XSETFASTINT (w
->last_modified
, 0);
3571 XSETFASTINT (w
->last_overlay_modified
, 0);
3572 windows_or_buffers_changed
++;
3573 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
3575 old_height
= XFASTINT (w
->height
);
3576 XSETFASTINT (w
->height
, height
);
3578 if (!NILP (w
->hchild
))
3580 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
3582 c
= XWINDOW (child
);
3584 shrink_window_lowest_first (c
, height
);
3587 else if (!NILP (w
->vchild
))
3589 Lisp_Object last_child
;
3590 int delta
= old_height
- height
;
3595 /* Find the last child. We are taking space from lowest windows
3596 first, so we iterate over children from the last child
3598 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
3601 /* Assign new heights. We leave only MIN_SAFE_WINDOW_HEIGHT. */
3602 for (child
= last_child
; delta
&& !NILP (child
); child
= c
->prev
)
3606 c
= XWINDOW (child
);
3607 this_one
= XFASTINT (c
->height
) - MIN_SAFE_WINDOW_HEIGHT
;
3609 if (this_one
> delta
)
3612 shrink_window_lowest_first (c
, XFASTINT (c
->height
) - this_one
);
3616 /* Compute new positions. */
3617 last_top
= XINT (w
->top
);
3618 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
3620 c
= XWINDOW (child
);
3621 c
->top
= make_number (last_top
);
3622 shrink_window_lowest_first (c
, XFASTINT (c
->height
));
3623 last_top
+= XFASTINT (c
->height
);
3629 /* Save, restore, or check positions and sizes in the window tree
3630 rooted at W. ACTION says what to do.
3632 If ACTION is CHECK_ORIG_SIZES, check if orig_top and orig_height
3633 members are valid for all windows in the window tree. Value is
3634 non-zero if they are valid.
3636 If ACTION is SAVE_ORIG_SIZES, save members top and height in
3637 orig_top and orig_height for all windows in the tree.
3639 If ACTION is RESTORE_ORIG_SIZES, restore top and height from
3640 values stored in orig_top and orig_height for all windows. */
3643 save_restore_orig_size (w
, action
)
3645 enum save_restore_action action
;
3651 if (!NILP (w
->hchild
))
3653 if (!save_restore_orig_size (XWINDOW (w
->hchild
), action
))
3656 else if (!NILP (w
->vchild
))
3658 if (!save_restore_orig_size (XWINDOW (w
->vchild
), action
))
3664 case CHECK_ORIG_SIZES
:
3665 if (!INTEGERP (w
->orig_top
) || !INTEGERP (w
->orig_height
))
3669 case SAVE_ORIG_SIZES
:
3670 w
->orig_top
= w
->top
;
3671 w
->orig_height
= w
->height
;
3672 XSETFASTINT (w
->last_modified
, 0);
3673 XSETFASTINT (w
->last_overlay_modified
, 0);
3676 case RESTORE_ORIG_SIZES
:
3677 xassert (INTEGERP (w
->orig_top
) && INTEGERP (w
->orig_height
));
3678 w
->top
= w
->orig_top
;
3679 w
->height
= w
->orig_height
;
3680 w
->orig_height
= w
->orig_top
= Qnil
;
3681 XSETFASTINT (w
->last_modified
, 0);
3682 XSETFASTINT (w
->last_overlay_modified
, 0);
3689 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
3696 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
3697 without deleting other windows. */
3700 grow_mini_window (w
, delta
)
3704 struct frame
*f
= XFRAME (w
->frame
);
3705 struct window
*root
;
3707 xassert (MINI_WINDOW_P (w
));
3708 xassert (delta
>= 0);
3710 /* Check values of window_min_width and window_min_height for
3712 check_min_window_sizes ();
3714 /* Compute how much we can enlarge the mini-window without deleting
3716 root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3719 int min_height
= window_min_size (root
, 0, 0, 0);
3720 if (XFASTINT (root
->height
) - delta
< min_height
)
3721 delta
= XFASTINT (root
->height
) - min_height
;
3726 /* Save original window sizes and positions, if not already done. */
3727 if (!save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
3728 save_restore_orig_size (root
, SAVE_ORIG_SIZES
);
3730 /* Shrink other windows. */
3731 shrink_window_lowest_first (root
, XFASTINT (root
->height
) - delta
);
3733 /* Grow the mini-window. */
3734 w
->top
= make_number (XFASTINT (root
->top
) + XFASTINT (root
->height
));
3735 w
->height
= make_number (XFASTINT (w
->height
) + delta
);
3736 XSETFASTINT (w
->last_modified
, 0);
3737 XSETFASTINT (w
->last_overlay_modified
, 0);
3744 /* Shrink mini-window W. If there is recorded info about window sizes
3745 before a call to grow_mini_window, restore recorded window sizes.
3746 Otherwise, if the mini-window is higher than 1 line, resize it to 1
3750 shrink_mini_window (w
)
3753 struct frame
*f
= XFRAME (w
->frame
);
3754 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3756 if (save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
3758 save_restore_orig_size (root
, RESTORE_ORIG_SIZES
);
3760 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3761 windows_or_buffers_changed
= 1;
3763 else if (XFASTINT (w
->height
) > 1)
3766 XSETWINDOW (window
, w
);
3767 enlarge_window (window
, 1 - XFASTINT (w
->height
), 0);
3773 /* Mark window cursors off for all windows in the window tree rooted
3774 at W by setting their phys_cursor_on_p flag to zero. Called from
3775 xterm.c, e.g. when a frame is cleared and thereby all cursors on
3776 the frame are cleared. */
3779 mark_window_cursors_off (w
)
3784 if (!NILP (w
->hchild
))
3785 mark_window_cursors_off (XWINDOW (w
->hchild
));
3786 else if (!NILP (w
->vchild
))
3787 mark_window_cursors_off (XWINDOW (w
->vchild
));
3789 w
->phys_cursor_on_p
= 0;
3791 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3796 /* Return number of lines of text (not counting mode line) in W. */
3799 window_internal_height (w
)
3802 int ht
= XFASTINT (w
->height
);
3804 if (MINI_WINDOW_P (w
))
3807 if (!NILP (w
->parent
) || !NILP (w
->vchild
) || !NILP (w
->hchild
)
3808 || !NILP (w
->next
) || !NILP (w
->prev
)
3809 || FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (w
))))
3816 /* Return the number of columns in W.
3817 Don't count columns occupied by scroll bars or the vertical bar
3818 separating W from the sibling to its right. */
3821 window_internal_width (w
)
3824 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3825 int width
= XINT (w
->width
);
3827 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3828 /* Scroll bars occupy a few columns. */
3829 width
-= FRAME_SCROLL_BAR_COLS (f
);
3830 else if (!WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
3831 /* The column of `|' characters separating side-by-side windows
3832 occupies one column only. */
3835 /* On window-systems, areas to the left and right of the window
3836 are used to display bitmaps there. */
3837 if (FRAME_WINDOW_P (f
))
3838 width
-= FRAME_FLAGS_AREA_COLS (f
);
3844 /************************************************************************
3846 ***********************************************************************/
3848 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
3849 one screen-full, which is defined as the height of the window minus
3850 next_screen_context_lines. If WHOLE is zero, scroll up N lines
3851 instead. Negative values of N mean scroll down. NOERROR non-zero
3852 means don't signal an error if we try to move over BEGV or ZV,
3856 window_scroll (window
, n
, whole
, noerror
)
3862 /* If we must, use the pixel-based version which is much slower than
3863 the line-based one but can handle varying line heights. */
3864 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
3865 window_scroll_pixel_based (window
, n
, whole
, noerror
);
3867 window_scroll_line_based (window
, n
, whole
, noerror
);
3871 /* Implementation of window_scroll that works based on pixel line
3872 heights. See the comment of window_scroll for parameter
3876 window_scroll_pixel_based (window
, n
, whole
, noerror
)
3883 struct window
*w
= XWINDOW (window
);
3884 struct text_pos start
;
3886 int this_scroll_margin
;
3889 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
3891 /* If PT is not visible in WINDOW, move back one half of
3893 XSETFASTINT (tem
, PT
);
3894 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
3897 /* Move backward half the height of the window. Performance note:
3898 vmotion used here is about 10% faster, but would give wrong
3899 results for variable height lines. */
3900 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
3901 it
.current_y
= it
.last_visible_y
;
3902 move_it_vertically (&it
, -it
.last_visible_y
/ 2);
3904 /* The function move_iterator_vertically may move over more than
3905 the specified y-distance. If it->w is small, e.g. a
3906 mini-buffer window, we may end up in front of the window's
3907 display area. This is the case when Start displaying at the
3908 start of the line containing PT in this case. */
3909 if (it
.current_y
<= 0)
3911 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
3912 move_it_vertically (&it
, 0);
3916 start
= it
.current
.pos
;
3919 /* If scroll_preserve_screen_position is non-zero, we try to set
3920 point in the same window line as it is now, so get that line. */
3921 if (!NILP (Vscroll_preserve_screen_position
))
3923 start_display (&it
, w
, start
);
3924 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
3925 preserve_y
= it
.current_y
;
3930 /* Move iterator it from start the specified distance forward or
3931 backward. The result is the new window start. */
3932 start_display (&it
, w
, start
);
3935 int screen_full
= (it
.last_visible_y
3936 - next_screen_context_lines
* CANON_Y_UNIT (it
.f
));
3937 int direction
= n
< 0 ? -1 : 1;
3938 move_it_vertically (&it
, direction
* screen_full
);
3941 move_it_by_lines (&it
, n
, 1);
3943 /* End if we end up at ZV or BEGV. */
3944 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
3945 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
3949 else if (IT_CHARPOS (it
) == ZV
)
3950 Fsignal (Qend_of_buffer
, Qnil
);
3952 Fsignal (Qbeginning_of_buffer
, Qnil
);
3955 /* Set the window start, and set up the window for redisplay. */
3956 set_marker_restricted (w
->start
, make_number (IT_CHARPOS (it
)), w
->buffer
);
3957 w
->start_at_line_beg
= Fbolp ();
3958 w
->update_mode_line
= Qt
;
3959 XSETFASTINT (w
->last_modified
, 0);
3960 XSETFASTINT (w
->last_overlay_modified
, 0);
3961 /* Set force_start so that redisplay_window will run the
3962 window-scroll-functions. */
3963 w
->force_start
= Qt
;
3965 it
.current_y
= it
.vpos
= 0;
3967 /* Preserve the screen position if we must. */
3968 if (preserve_y
>= 0)
3970 move_it_to (&it
, -1, -1, preserve_y
, -1, MOVE_TO_Y
);
3971 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
3975 /* Move PT out of scroll margins. */
3976 this_scroll_margin
= max (0, scroll_margin
);
3977 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
3978 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
3982 /* We moved the window start towards ZV, so PT may be now
3983 in the scroll margin at the top. */
3984 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
3985 while (it
.current_y
< this_scroll_margin
)
3986 move_it_by_lines (&it
, 1, 1);
3987 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
3991 /* We moved the window start towards BEGV, so PT may be now
3992 in the scroll margin at the bottom. */
3993 move_it_to (&it
, PT
, -1,
3994 it
.last_visible_y
- this_scroll_margin
- 1, -1,
3995 MOVE_TO_POS
| MOVE_TO_Y
);
3997 /* Don't put point on a partially visible line at the end. */
3998 if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
3999 > it
.last_visible_y
)
4000 move_it_by_lines (&it
, -1, 0);
4002 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4008 /* Implementation of window_scroll that works based on screen lines.
4009 See the comment of window_scroll for parameter descriptions. */
4012 window_scroll_line_based (window
, n
, whole
, noerror
)
4018 register struct window
*w
= XWINDOW (window
);
4019 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
4020 register int pos
, pos_byte
;
4021 register int ht
= window_internal_height (w
);
4022 register Lisp_Object tem
;
4026 struct position posit
;
4029 startpos
= marker_position (w
->start
);
4031 posit
= *compute_motion (startpos
, 0, 0, 0,
4033 window_internal_width (w
), XINT (w
->hscroll
),
4035 original_vpos
= posit
.vpos
;
4037 XSETFASTINT (tem
, PT
);
4038 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
4042 Fvertical_motion (make_number (- (ht
/ 2)), window
);
4047 lose
= n
< 0 && PT
== BEGV
;
4048 Fvertical_motion (make_number (n
), window
);
4052 SET_PT_BOTH (opoint
, opoint_byte
);
4059 Fsignal (Qbeginning_of_buffer
, Qnil
);
4064 int this_scroll_margin
= scroll_margin
;
4066 /* Don't use a scroll margin that is negative or too large. */
4067 if (this_scroll_margin
< 0)
4068 this_scroll_margin
= 0;
4070 if (XINT (w
->height
) < 4 * scroll_margin
)
4071 this_scroll_margin
= XINT (w
->height
) / 4;
4073 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
4074 w
->start_at_line_beg
= bolp
;
4075 w
->update_mode_line
= Qt
;
4076 XSETFASTINT (w
->last_modified
, 0);
4077 XSETFASTINT (w
->last_overlay_modified
, 0);
4078 /* Set force_start so that redisplay_window will run
4079 the window-scroll-functions. */
4080 w
->force_start
= Qt
;
4082 if (whole
&& !NILP (Vscroll_preserve_screen_position
))
4084 SET_PT_BOTH (pos
, pos_byte
);
4085 Fvertical_motion (make_number (original_vpos
), window
);
4087 /* If we scrolled forward, put point enough lines down
4088 that it is outside the scroll margin. */
4093 if (this_scroll_margin
> 0)
4095 SET_PT_BOTH (pos
, pos_byte
);
4096 Fvertical_motion (make_number (this_scroll_margin
), window
);
4102 if (top_margin
<= opoint
)
4103 SET_PT_BOTH (opoint
, opoint_byte
);
4104 else if (!NILP (Vscroll_preserve_screen_position
))
4106 SET_PT_BOTH (pos
, pos_byte
);
4107 Fvertical_motion (make_number (original_vpos
), window
);
4110 SET_PT (top_margin
);
4116 /* If we scrolled backward, put point near the end of the window
4117 but not within the scroll margin. */
4118 SET_PT_BOTH (pos
, pos_byte
);
4119 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
4120 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
4123 bottom_margin
= PT
+ 1;
4125 if (bottom_margin
> opoint
)
4126 SET_PT_BOTH (opoint
, opoint_byte
);
4129 if (!NILP (Vscroll_preserve_screen_position
))
4131 SET_PT_BOTH (pos
, pos_byte
);
4132 Fvertical_motion (make_number (original_vpos
), window
);
4135 Fvertical_motion (make_number (-1), window
);
4144 Fsignal (Qend_of_buffer
, Qnil
);
4149 /* Scroll selected_window up or down. If N is nil, scroll a
4150 screen-full which is defined as the height of the window minus
4151 next_screen_context_lines. If N is the symbol `-', scroll.
4152 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4153 up. This is the guts of Fscroll_up and Fscroll_down. */
4156 scroll_command (n
, direction
)
4160 register int defalt
;
4161 int count
= specpdl_ptr
- specpdl
;
4163 xassert (abs (direction
) == 1);
4165 /* If selected window's buffer isn't current, make it current for
4166 the moment. But don't screw up if window_scroll gets an error. */
4167 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
4169 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4170 Fset_buffer (XWINDOW (selected_window
)->buffer
);
4172 /* Make redisplay consider other windows than just selected_window. */
4173 ++windows_or_buffers_changed
;
4176 defalt
= (window_internal_height (XWINDOW (selected_window
))
4177 - next_screen_context_lines
);
4178 defalt
= direction
* (defalt
< 1 ? 1 : defalt
);
4181 window_scroll (selected_window
, defalt
, 1, 0);
4182 else if (EQ (n
, Qminus
))
4183 window_scroll (selected_window
, - defalt
, 1, 0);
4186 n
= Fprefix_numeric_value (n
);
4187 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
4190 unbind_to (count
, Qnil
);
4193 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
4194 "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\
4195 A near full screen is `next-screen-context-lines' less than a full screen.\n\
4196 Negative ARG means scroll downward.\n\
4197 If ARG is the atom `-', scroll downward by nearly full screen.\n\
4198 When calling from a program, supply as argument a number, nil, or `-'.")
4202 scroll_command (arg
, 1);
4206 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
4207 "Scroll text of current window down ARG lines; or near full screen if no ARG.\n\
4208 A near full screen is `next-screen-context-lines' less than a full screen.\n\
4209 Negative ARG means scroll upward.\n\
4210 If ARG is the atom `-', scroll upward by nearly full screen.\n\
4211 When calling from a program, supply as argument a number, nil, or `-'.")
4215 scroll_command (arg
, -1);
4219 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
4220 "Return the other window for \"other window scroll\" commands.\n\
4221 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
4222 specifies the window.\n\
4223 If `other-window-scroll-buffer' is non-nil, a window\n\
4224 showing that buffer is used.")
4229 if (MINI_WINDOW_P (XWINDOW (selected_window
))
4230 && !NILP (Vminibuf_scroll_window
))
4231 window
= Vminibuf_scroll_window
;
4232 /* If buffer is specified, scroll that buffer. */
4233 else if (!NILP (Vother_window_scroll_buffer
))
4235 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
4237 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
4241 /* Nothing specified; look for a neighboring window on the same
4243 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
4245 if (EQ (window
, selected_window
))
4246 /* That didn't get us anywhere; look for a window on another
4249 window
= Fnext_window (window
, Qnil
, Qt
);
4250 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
4251 && ! EQ (window
, selected_window
));
4254 CHECK_LIVE_WINDOW (window
, 0);
4256 if (EQ (window
, selected_window
))
4257 error ("There is no other window");
4262 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
4263 "Scroll next window upward ARG lines; or near full screen if no ARG.\n\
4264 A near full screen is `next-screen-context-lines' less than a full screen.\n\
4265 The next window is the one below the current one; or the one at the top\n\
4266 if the current one is at the bottom. Negative ARG means scroll downward.\n\
4267 If ARG is the atom `-', scroll downward by nearly full screen.\n\
4268 When calling from a program, supply as argument a number, nil, or `-'.\n\
4270 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
4271 specifies the window to scroll.\n\
4272 If `other-window-scroll-buffer' is non-nil, scroll the window\n\
4273 showing that buffer, popping the buffer up if necessary.")
4275 register Lisp_Object arg
;
4277 register Lisp_Object window
;
4278 register int defalt
;
4279 register struct window
*w
;
4280 register int count
= specpdl_ptr
- specpdl
;
4282 window
= Fother_window_for_scrolling ();
4284 w
= XWINDOW (window
);
4285 defalt
= window_internal_height (w
) - next_screen_context_lines
;
4286 if (defalt
< 1) defalt
= 1;
4288 /* Don't screw up if window_scroll gets an error. */
4289 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4290 ++windows_or_buffers_changed
;
4292 Fset_buffer (w
->buffer
);
4293 SET_PT (marker_position (w
->pointm
));
4296 window_scroll (window
, defalt
, 1, 1);
4297 else if (EQ (arg
, Qminus
))
4298 window_scroll (window
, -defalt
, 1, 1);
4303 CHECK_NUMBER (arg
, 0);
4304 window_scroll (window
, XINT (arg
), 0, 1);
4307 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
4308 unbind_to (count
, Qnil
);
4313 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 1, "P",
4314 "Scroll selected window display ARG columns left.\n\
4315 Default for ARG is window width minus 2.")
4317 register Lisp_Object arg
;
4321 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
4323 arg
= Fprefix_numeric_value (arg
);
4326 Fset_window_hscroll (selected_window
,
4327 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
4331 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 1, "P",
4332 "Scroll selected window display ARG columns right.\n\
4333 Default for ARG is window width minus 2.")
4335 register Lisp_Object arg
;
4338 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
4340 arg
= Fprefix_numeric_value (arg
);
4343 Fset_window_hscroll (selected_window
,
4344 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
4348 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
4349 "Center point in window and redisplay frame. With ARG, put point on line ARG.\n\
4350 The desired position of point is always relative to the current window.\n\
4351 Just C-u as prefix means put point in the center of the window.\n\
4352 If ARG is omitted or nil, erases the entire frame and then\n\
4353 redraws with point in the center of the current window.")
4355 register Lisp_Object arg
;
4357 register struct window
*w
= XWINDOW (selected_window
);
4358 register int ht
= window_internal_height (w
);
4359 struct position pos
;
4360 struct buffer
*buf
= XBUFFER (w
->buffer
);
4361 struct buffer
*obuf
= current_buffer
;
4365 extern int frame_garbaged
;
4368 /* Invalidate pixel data calculated for all compositions. */
4369 for (i
= 0; i
< n_compositions
; i
++)
4370 composition_table
[i
]->font
= NULL
;
4372 Fredraw_frame (w
->frame
);
4373 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
4374 XSETFASTINT (arg
, ht
/ 2);
4376 else if (CONSP (arg
)) /* Just C-u. */
4378 XSETFASTINT (arg
, ht
/ 2);
4382 arg
= Fprefix_numeric_value (arg
);
4383 CHECK_NUMBER (arg
, 0);
4387 XSETINT (arg
, XINT (arg
) + ht
);
4389 set_buffer_internal (buf
);
4390 pos
= *vmotion (PT
, - XINT (arg
), w
);
4392 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
4393 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
4394 || FETCH_BYTE (pos
.bytepos
- 1) == '\n')
4396 w
->force_start
= Qt
;
4397 set_buffer_internal (obuf
);
4403 /* Value is the number of lines actually displayed in window W,
4404 as opposed to its height. */
4407 displayed_window_lines (w
)
4411 struct text_pos start
;
4412 int height
= window_box_height (w
);
4413 struct buffer
*old_buffer
;
4416 if (XBUFFER (w
->buffer
) != current_buffer
)
4418 old_buffer
= current_buffer
;
4419 set_buffer_internal (XBUFFER (w
->buffer
));
4424 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4425 start_display (&it
, w
, start
);
4426 move_it_vertically (&it
, height
);
4429 set_buffer_internal (old_buffer
);
4431 /* Add in empty lines at the bottom of the window. */
4432 bottom_y
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
4433 if (bottom_y
< height
)
4435 struct frame
*f
= XFRAME (w
->frame
);
4436 int rest
= height
- bottom_y
;
4437 int lines
= (rest
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
4440 else if (it
.current_y
< height
&& bottom_y
> height
)
4441 /* Partially visible line at the bottom. */
4449 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
4451 "Position point relative to window.\n\
4452 With no argument, position point at center of window.\n\
4453 An argument specifies vertical position within the window;\n\
4454 zero means top of window, negative means relative to bottom of window.")
4458 struct window
*w
= XWINDOW (selected_window
);
4462 window
= selected_window
;
4463 start
= marker_position (w
->start
);
4464 if (start
< BEGV
|| start
> ZV
)
4466 int height
= window_internal_height (w
);
4467 Fvertical_motion (make_number (- (height
/ 2)), window
);
4468 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
4469 w
->start_at_line_beg
= Fbolp ();
4470 w
->force_start
= Qt
;
4473 Fgoto_char (w
->start
);
4475 lines
= displayed_window_lines (w
);
4477 XSETFASTINT (arg
, lines
/ 2);
4480 arg
= Fprefix_numeric_value (arg
);
4482 XSETINT (arg
, XINT (arg
) + lines
);
4485 return Fvertical_motion (arg
, window
);
4490 /***********************************************************************
4491 Window Configuration
4492 ***********************************************************************/
4494 struct save_window_data
4496 EMACS_INT size_from_Lisp_Vector_struct
;
4497 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
4498 Lisp_Object frame_width
, frame_height
, frame_menu_bar_lines
;
4499 Lisp_Object frame_tool_bar_lines
;
4500 Lisp_Object selected_frame
;
4501 Lisp_Object current_window
;
4502 Lisp_Object current_buffer
;
4503 Lisp_Object minibuf_scroll_window
;
4504 Lisp_Object root_window
;
4505 Lisp_Object focus_frame
;
4506 /* Record the values of window-min-width and window-min-height
4507 so that window sizes remain consistent with them. */
4508 Lisp_Object min_width
, min_height
;
4509 /* A vector, each of whose elements is a struct saved_window
4511 Lisp_Object saved_windows
;
4514 /* This is saved as a Lisp_Vector */
4517 /* these first two must agree with struct Lisp_Vector in lisp.h */
4518 EMACS_INT size_from_Lisp_Vector_struct
;
4519 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
4522 Lisp_Object buffer
, start
, pointm
, mark
;
4523 Lisp_Object left
, top
, width
, height
, hscroll
;
4524 Lisp_Object parent
, prev
;
4525 Lisp_Object start_at_line_beg
;
4526 Lisp_Object display_table
;
4527 Lisp_Object orig_top
, orig_height
;
4529 #define SAVED_WINDOW_VECTOR_SIZE 16 /* Arg to Fmake_vector */
4531 #define SAVED_WINDOW_N(swv,n) \
4532 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
4534 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
4535 "Return t if OBJECT is a window-configuration object.")
4539 if (WINDOW_CONFIGURATIONP (object
))
4544 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
4545 "Return the frame that CONFIG, a window-configuration object, is about.")
4549 register struct save_window_data
*data
;
4550 struct Lisp_Vector
*saved_windows
;
4552 if (! WINDOW_CONFIGURATIONP (config
))
4553 wrong_type_argument (Qwindow_configuration_p
, config
);
4555 data
= (struct save_window_data
*) XVECTOR (config
);
4556 saved_windows
= XVECTOR (data
->saved_windows
);
4557 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
4560 DEFUN ("set-window-configuration", Fset_window_configuration
,
4561 Sset_window_configuration
, 1, 1, 0,
4562 "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\
4563 CONFIGURATION must be a value previously returned\n\
4564 by `current-window-configuration' (which see).\n\
4565 If CONFIGURATION was made from a frame that is now deleted,\n\
4566 only frame-independent values can be restored. In this case,\n\
4567 the return value is nil. Otherwise the value is t.")
4569 Lisp_Object configuration
;
4571 register struct save_window_data
*data
;
4572 struct Lisp_Vector
*saved_windows
;
4573 Lisp_Object new_current_buffer
;
4578 while (!WINDOW_CONFIGURATIONP (configuration
))
4579 wrong_type_argument (Qwindow_configuration_p
, configuration
);
4581 data
= (struct save_window_data
*) XVECTOR (configuration
);
4582 saved_windows
= XVECTOR (data
->saved_windows
);
4584 new_current_buffer
= data
->current_buffer
;
4585 if (NILP (XBUFFER (new_current_buffer
)->name
))
4586 new_current_buffer
= Qnil
;
4589 if (XBUFFER (new_current_buffer
) == current_buffer
)
4593 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
4596 /* If f is a dead frame, don't bother rebuilding its window tree.
4597 However, there is other stuff we should still try to do below. */
4598 if (FRAME_LIVE_P (f
))
4600 register struct window
*w
;
4601 register struct saved_window
*p
;
4602 struct window
*root_window
;
4603 struct window
**leaf_windows
;
4607 /* If the frame has been resized since this window configuration was
4608 made, we change the frame to the size specified in the
4609 configuration, restore the configuration, and then resize it
4610 back. We keep track of the prevailing height in these variables. */
4611 int previous_frame_height
= FRAME_HEIGHT (f
);
4612 int previous_frame_width
= FRAME_WIDTH (f
);
4613 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
4614 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
4616 /* The mouse highlighting code could get screwed up
4617 if it runs during this. */
4620 if (XFASTINT (data
->frame_height
) != previous_frame_height
4621 || XFASTINT (data
->frame_width
) != previous_frame_width
)
4622 change_frame_size (f
, XFASTINT (data
->frame_height
),
4623 XFASTINT (data
->frame_width
), 0, 0, 0);
4624 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
4625 if (XFASTINT (data
->frame_menu_bar_lines
)
4626 != previous_frame_menu_bar_lines
)
4627 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, make_number (0));
4628 #ifdef HAVE_WINDOW_SYSTEM
4629 if (XFASTINT (data
->frame_tool_bar_lines
)
4630 != previous_frame_tool_bar_lines
)
4631 x_set_tool_bar_lines (f
, data
->frame_tool_bar_lines
, make_number (0));
4635 /* "Swap out" point from the selected window
4636 into its buffer. We do this now, before
4637 restoring the window contents, and prevent it from
4638 being done later on when we select a new window. */
4639 if (! NILP (XWINDOW (selected_window
)->buffer
))
4641 w
= XWINDOW (selected_window
);
4642 set_marker_both (w
->pointm
,
4644 BUF_PT (XBUFFER (w
->buffer
)),
4645 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
4648 windows_or_buffers_changed
++;
4649 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4651 /* Problem: Freeing all matrices and later allocating them again
4652 is a serious redisplay flickering problem. What we would
4653 really like to do is to free only those matrices not reused
4655 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4657 = (struct window
**) alloca (count_windows (root_window
)
4658 * sizeof (struct window
*));
4659 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
4661 /* Temporarily avoid any problems with windows that are smaller
4662 than they are supposed to be. */
4663 window_min_height
= 1;
4664 window_min_width
= 1;
4667 Mark all windows now on frame as "deleted".
4668 Restoring the new configuration "undeletes" any that are in it.
4670 Save their current buffers in their height fields, since we may
4671 need it later, if a buffer saved in the configuration is now
4673 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4675 for (k
= 0; k
< saved_windows
->size
; k
++)
4677 p
= SAVED_WINDOW_N (saved_windows
, k
);
4678 w
= XWINDOW (p
->window
);
4681 if (!NILP (p
->parent
))
4682 w
->parent
= SAVED_WINDOW_N (saved_windows
,
4683 XFASTINT (p
->parent
))->window
;
4687 if (!NILP (p
->prev
))
4689 w
->prev
= SAVED_WINDOW_N (saved_windows
,
4690 XFASTINT (p
->prev
))->window
;
4691 XWINDOW (w
->prev
)->next
= p
->window
;
4696 if (!NILP (w
->parent
))
4698 if (EQ (p
->width
, XWINDOW (w
->parent
)->width
))
4700 XWINDOW (w
->parent
)->vchild
= p
->window
;
4701 XWINDOW (w
->parent
)->hchild
= Qnil
;
4705 XWINDOW (w
->parent
)->hchild
= p
->window
;
4706 XWINDOW (w
->parent
)->vchild
= Qnil
;
4711 /* If we squirreled away the buffer in the window's height,
4713 if (BUFFERP (w
->height
))
4714 w
->buffer
= w
->height
;
4717 w
->width
= p
->width
;
4718 w
->height
= p
->height
;
4719 w
->hscroll
= p
->hscroll
;
4720 w
->display_table
= p
->display_table
;
4721 w
->orig_top
= p
->orig_top
;
4722 w
->orig_height
= p
->orig_height
;
4723 XSETFASTINT (w
->last_modified
, 0);
4724 XSETFASTINT (w
->last_overlay_modified
, 0);
4726 /* Reinstall the saved buffer and pointers into it. */
4727 if (NILP (p
->buffer
))
4728 w
->buffer
= p
->buffer
;
4731 if (!NILP (XBUFFER (p
->buffer
)->name
))
4732 /* If saved buffer is alive, install it. */
4734 w
->buffer
= p
->buffer
;
4735 w
->start_at_line_beg
= p
->start_at_line_beg
;
4736 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
4737 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
4738 Fset_marker (XBUFFER (w
->buffer
)->mark
,
4739 p
->mark
, w
->buffer
);
4741 /* As documented in Fcurrent_window_configuration, don't
4742 save the location of point in the buffer which was current
4743 when the window configuration was recorded. */
4744 if (!EQ (p
->buffer
, new_current_buffer
)
4745 && XBUFFER (p
->buffer
) == current_buffer
)
4746 Fgoto_char (w
->pointm
);
4748 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
4749 /* Else unless window has a live buffer, get one. */
4751 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
4752 /* This will set the markers to beginning of visible
4754 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
4755 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
4756 w
->start_at_line_beg
= Qt
;
4759 /* Keeping window's old buffer; make sure the markers
4762 /* Set window markers at start of visible range. */
4763 if (XMARKER (w
->start
)->buffer
== 0)
4764 set_marker_restricted (w
->start
, make_number (0),
4766 if (XMARKER (w
->pointm
)->buffer
== 0)
4767 set_marker_restricted_both (w
->pointm
, w
->buffer
,
4768 BUF_PT (XBUFFER (w
->buffer
)),
4769 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
4770 w
->start_at_line_beg
= Qt
;
4775 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
4776 /* Prevent "swapping out point" in the old selected window
4777 using the buffer that has been restored into it.
4778 That swapping out has already been done,
4779 near the beginning of this function. */
4780 selected_window
= Qnil
;
4781 Fselect_window (data
->current_window
);
4782 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
4785 if (NILP (data
->focus_frame
)
4786 || (FRAMEP (data
->focus_frame
)
4787 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
4788 Fredirect_frame_focus (frame
, data
->focus_frame
);
4790 #if 0 /* I don't understand why this is needed, and it causes problems
4791 when the frame's old selected window has been deleted. */
4792 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
4793 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
4797 /* Set the screen height to the value it had before this function. */
4798 if (previous_frame_height
!= FRAME_HEIGHT (f
)
4799 || previous_frame_width
!= FRAME_WIDTH (f
))
4800 change_frame_size (f
, previous_frame_height
, previous_frame_width
,
4802 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
4803 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
4804 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
4806 #ifdef HAVE_WINDOW_SYSTEM
4807 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
4808 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
4813 /* Now, free glyph matrices in windows that were not reused. */
4814 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
4816 if (NILP (leaf_windows
[i
]->buffer
))
4818 /* Assert it's not reused as a combination. */
4819 xassert (NILP (leaf_windows
[i
]->hchild
)
4820 && NILP (leaf_windows
[i
]->vchild
));
4821 free_window_matrices (leaf_windows
[i
]);
4822 SET_FRAME_GARBAGED (f
);
4824 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
4828 /* If more than one window shows the new and old current buffer,
4829 don't try to preserve point in that buffer. */
4830 if (old_point
> 0 && n
> 1)
4837 /* Fselect_window will have made f the selected frame, so we
4838 reselect the proper frame here. Fhandle_switch_frame will change the
4839 selected window too, but that doesn't make the call to
4840 Fselect_window above totally superfluous; it still sets f's
4842 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
4843 do_switch_frame (data
->selected_frame
, Qnil
, 0);
4845 if (! NILP (Vwindow_configuration_change_hook
)
4846 && ! NILP (Vrun_hooks
))
4847 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
4850 if (!NILP (new_current_buffer
))
4852 Fset_buffer (new_current_buffer
);
4854 /* If the buffer that is current now is the same
4855 that was current before setting the window configuration,
4856 don't alter its PT. */
4861 /* Restore the minimum heights recorded in the configuration. */
4862 window_min_height
= XINT (data
->min_height
);
4863 window_min_width
= XINT (data
->min_width
);
4865 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
4867 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
4870 /* Mark all windows now on frame as deleted
4871 by setting their buffers to nil. */
4874 delete_all_subwindows (w
)
4875 register struct window
*w
;
4877 if (!NILP (w
->next
))
4878 delete_all_subwindows (XWINDOW (w
->next
));
4879 if (!NILP (w
->vchild
))
4880 delete_all_subwindows (XWINDOW (w
->vchild
));
4881 if (!NILP (w
->hchild
))
4882 delete_all_subwindows (XWINDOW (w
->hchild
));
4884 w
->height
= w
->buffer
; /* See Fset_window_configuration for excuse. */
4886 if (!NILP (w
->buffer
))
4889 /* We set all three of these fields to nil, to make sure that we can
4890 distinguish this dead window from any live window. Live leaf
4891 windows will have buffer set, and combination windows will have
4892 vchild or hchild set. */
4897 Vwindow_list
= Qnil
;
4901 count_windows (window
)
4902 register struct window
*window
;
4904 register int count
= 1;
4905 if (!NILP (window
->next
))
4906 count
+= count_windows (XWINDOW (window
->next
));
4907 if (!NILP (window
->vchild
))
4908 count
+= count_windows (XWINDOW (window
->vchild
));
4909 if (!NILP (window
->hchild
))
4910 count
+= count_windows (XWINDOW (window
->hchild
));
4915 /* Fill vector FLAT with leaf windows under W, starting at index I.
4916 Value is last index + 1. */
4919 get_leaf_windows (w
, flat
, i
)
4921 struct window
**flat
;
4926 if (!NILP (w
->hchild
))
4927 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
4928 else if (!NILP (w
->vchild
))
4929 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
4933 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4940 /* Return a pointer to the glyph W's physical cursor is on. Value is
4941 null if W's current matrix is invalid, so that no meaningfull glyph
4945 get_phys_cursor_glyph (w
)
4948 struct glyph_row
*row
;
4949 struct glyph
*glyph
;
4951 if (w
->phys_cursor
.vpos
>= 0
4952 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
4953 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
4955 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
4956 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
4965 save_window_save (window
, vector
, i
)
4967 struct Lisp_Vector
*vector
;
4970 register struct saved_window
*p
;
4971 register struct window
*w
;
4972 register Lisp_Object tem
;
4974 for (;!NILP (window
); window
= w
->next
)
4976 p
= SAVED_WINDOW_N (vector
, i
);
4977 w
= XWINDOW (window
);
4979 XSETFASTINT (w
->temslot
, i
++);
4981 p
->buffer
= w
->buffer
;
4984 p
->width
= w
->width
;
4985 p
->height
= w
->height
;
4986 p
->hscroll
= w
->hscroll
;
4987 p
->display_table
= w
->display_table
;
4988 p
->orig_top
= w
->orig_top
;
4989 p
->orig_height
= w
->orig_height
;
4990 if (!NILP (w
->buffer
))
4992 /* Save w's value of point in the window configuration.
4993 If w is the selected window, then get the value of point
4994 from the buffer; pointm is garbage in the selected window. */
4995 if (EQ (window
, selected_window
))
4997 p
->pointm
= Fmake_marker ();
4998 set_marker_both (p
->pointm
, w
->buffer
,
4999 BUF_PT (XBUFFER (w
->buffer
)),
5000 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5003 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
5005 p
->start
= Fcopy_marker (w
->start
, Qnil
);
5006 p
->start_at_line_beg
= w
->start_at_line_beg
;
5008 tem
= XBUFFER (w
->buffer
)->mark
;
5009 p
->mark
= Fcopy_marker (tem
, Qnil
);
5016 p
->start_at_line_beg
= Qnil
;
5019 if (NILP (w
->parent
))
5022 p
->parent
= XWINDOW (w
->parent
)->temslot
;
5027 p
->prev
= XWINDOW (w
->prev
)->temslot
;
5029 if (!NILP (w
->vchild
))
5030 i
= save_window_save (w
->vchild
, vector
, i
);
5031 if (!NILP (w
->hchild
))
5032 i
= save_window_save (w
->hchild
, vector
, i
);
5038 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
5039 Scurrent_window_configuration
, 0, 1, 0,
5040 "Return an object representing the current window configuration of FRAME.\n\
5041 If FRAME is nil or omitted, use the selected frame.\n\
5042 This describes the number of windows, their sizes and current buffers,\n\
5043 and for each displayed buffer, where display starts, and the positions of\n\
5044 point and mark. An exception is made for point in the current buffer:\n\
5045 its value is -not- saved.\n\
5046 This also records the currently selected frame, and FRAME's focus\n\
5047 redirection (see `redirect-frame-focus').")
5051 register Lisp_Object tem
;
5052 register int n_windows
;
5053 register struct save_window_data
*data
;
5054 register struct Lisp_Vector
*vec
;
5059 frame
= selected_frame
;
5060 CHECK_LIVE_FRAME (frame
, 0);
5063 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5064 vec
= allocate_vectorlike (VECSIZE (struct save_window_data
));
5065 for (i
= 0; i
< VECSIZE (struct save_window_data
); i
++)
5066 vec
->contents
[i
] = Qnil
;
5067 vec
->size
= VECSIZE (struct save_window_data
);
5068 data
= (struct save_window_data
*)vec
;
5070 XSETFASTINT (data
->frame_width
, FRAME_WIDTH (f
));
5071 XSETFASTINT (data
->frame_height
, FRAME_HEIGHT (f
));
5072 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
5073 XSETFASTINT (data
->frame_tool_bar_lines
, FRAME_TOOL_BAR_LINES (f
));
5074 data
->selected_frame
= selected_frame
;
5075 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
5076 XSETBUFFER (data
->current_buffer
, current_buffer
);
5077 data
->minibuf_scroll_window
= Vminibuf_scroll_window
;
5078 data
->root_window
= FRAME_ROOT_WINDOW (f
);
5079 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
5080 XSETINT (data
->min_height
, window_min_height
);
5081 XSETINT (data
->min_width
, window_min_width
);
5082 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
5083 data
->saved_windows
= tem
;
5084 for (i
= 0; i
< n_windows
; i
++)
5085 XVECTOR (tem
)->contents
[i
]
5086 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
5087 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
5088 XSETWINDOW_CONFIGURATION (tem
, data
);
5092 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
5094 "Execute body, preserving window sizes and contents.\n\
5095 Restore which buffer appears in which window, where display starts,\n\
5096 and the value of point and mark for each window.\n\
5097 Also restore the choice of selected window.\n\
5098 Also restore which buffer is current.\n\
5099 Does not restore the value of point in current buffer.")
5103 register Lisp_Object val
;
5104 register int count
= specpdl_ptr
- specpdl
;
5106 record_unwind_protect (Fset_window_configuration
,
5107 Fcurrent_window_configuration (Qnil
));
5108 val
= Fprogn (args
);
5109 return unbind_to (count
, val
);
5113 /***********************************************************************
5115 ***********************************************************************/
5117 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
5119 "Set width of marginal areas of window WINDOW.\n\
5120 If window is nil, set margins of the currently selected window.\n\
5121 First parameter LEFT-WIDTH specifies the number of character\n\
5122 cells to reserve for the left marginal area. Second parameter\n\
5123 RIGHT-WIDTH does the same for the right marginal area.\n\
5124 A nil width parameter means no margin.")
5125 (window
, left
, right
)
5126 Lisp_Object window
, left
, right
;
5128 struct window
*w
= decode_window (window
);
5131 CHECK_NUMBER_OR_FLOAT (left
, 1);
5133 CHECK_NUMBER_OR_FLOAT (right
, 2);
5135 /* Check widths < 0 and translate a zero width to nil.
5136 Margins that are too wide have to be checked elsewhere. */
5137 if ((INTEGERP (left
) && XINT (left
) < 0)
5138 || (FLOATP (left
) && XFLOAT_DATA (left
) <= 0))
5139 XSETFASTINT (left
, 0);
5140 if (INTEGERP (left
) && XFASTINT (left
) == 0)
5143 if ((INTEGERP (right
) && XINT (right
) < 0)
5144 || (FLOATP (right
) && XFLOAT_DATA (right
) <= 0))
5145 XSETFASTINT (right
, 0);
5146 if (INTEGERP (right
) && XFASTINT (right
) == 0)
5149 w
->left_margin_width
= left
;
5150 w
->right_margin_width
= right
;
5152 ++windows_or_buffers_changed
;
5153 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
5158 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
5160 "Get width of marginal areas of window WINDOW.\n\
5161 If WINDOW is omitted or nil, use the currently selected window.\n\
5162 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).\n\
5163 If a marginal area does not exist, its width will be returned\n\
5168 struct window
*w
= decode_window (window
);
5169 return Fcons (w
->left_margin_width
, w
->right_margin_width
);
5174 /***********************************************************************
5176 ***********************************************************************/
5178 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 1, 0,
5179 "Return the amount by which WINDOW is scrolled vertically.\n\
5180 Use the selected window if WINDOW is nil or omitted.\n\
5181 Value is a multiple of the canonical character height of WINDOW.")
5190 window
= selected_window
;
5192 CHECK_WINDOW (window
, 0);
5193 w
= XWINDOW (window
);
5194 f
= XFRAME (w
->frame
);
5196 if (FRAME_WINDOW_P (f
))
5197 result
= CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
);
5199 result
= make_number (0);
5204 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
5206 "Set amount by which WINDOW should be scrolled vertically to VSCROLL.\n\
5207 WINDOW nil or omitted means use the selected window. VSCROLL is a\n\
5208 non-negative multiple of the canonical character height of WINDOW.")
5210 Lisp_Object window
, vscroll
;
5216 window
= selected_window
;
5218 CHECK_WINDOW (window
, 0);
5219 CHECK_NUMBER_OR_FLOAT (vscroll
, 1);
5221 w
= XWINDOW (window
);
5222 f
= XFRAME (w
->frame
);
5224 if (FRAME_WINDOW_P (f
))
5226 int old_dy
= w
->vscroll
;
5228 w
->vscroll
= - CANON_Y_UNIT (f
) * XFLOATINT (vscroll
);
5229 w
->vscroll
= min (w
->vscroll
, 0);
5231 /* Adjust glyph matrix of the frame if the virtual display
5232 area becomes larger than before. */
5233 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
5236 /* Prevent redisplay shortcuts. */
5237 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
5240 return Fwindow_vscroll (window
);
5244 /* Call FN for all leaf windows on frame F. FN is called with the
5245 first argument being a pointer to the leaf window, and with
5246 additional argument USER_DATA. Stops when FN returns 0. */
5249 foreach_window (f
, fn
, user_data
)
5251 int (* fn
) P_ ((struct window
*, void *));
5254 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
5258 /* Helper function for foreach_window. Call FN for all leaf windows
5259 reachable from W. FN is called with the first argument being a
5260 pointer to the leaf window, and with additional argument USER_DATA.
5261 Stop when FN returns 0. Value is 0 if stopped by FN. */
5264 foreach_window_1 (w
, fn
, user_data
)
5266 int (* fn
) P_ ((struct window
*, void *));
5271 for (cont
= 1; w
&& cont
;)
5273 if (!NILP (w
->hchild
))
5274 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
5275 else if (!NILP (w
->vchild
))
5276 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
5278 cont
= fn (w
, user_data
);
5280 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5287 /* Freeze or unfreeze the window start of W if unless it is a
5288 mini-window or the selected window. FREEZE_P non-null means freeze
5289 the window start. */
5292 freeze_window_start (w
, freeze_p
)
5296 if (w
== XWINDOW (selected_window
)
5297 || MINI_WINDOW_P (w
)
5298 || (MINI_WINDOW_P (XWINDOW (selected_window
))
5299 && ! NILP (Vminibuf_scroll_window
)
5300 && w
== XWINDOW (Vminibuf_scroll_window
)))
5303 w
->frozen_window_start_p
= freeze_p
!= NULL
;
5308 /* Freeze or unfreeze the window starts of all leaf windows on frame
5309 F, except the selected window and a mini-window. FREEZE_P non-zero
5310 means freeze the window start. */
5313 freeze_window_starts (f
, freeze_p
)
5317 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
5321 /***********************************************************************
5323 ***********************************************************************/
5325 /* Return 1 if window configurations C1 and C2
5326 describe the same state of affairs. This is used by Fequal. */
5329 compare_window_configurations (c1
, c2
, ignore_positions
)
5331 int ignore_positions
;
5333 register struct save_window_data
*d1
, *d2
;
5334 struct Lisp_Vector
*sw1
, *sw2
;
5337 if (!WINDOW_CONFIGURATIONP (c1
))
5338 wrong_type_argument (Qwindow_configuration_p
, c1
);
5339 if (!WINDOW_CONFIGURATIONP (c2
))
5340 wrong_type_argument (Qwindow_configuration_p
, c2
);
5342 d1
= (struct save_window_data
*) XVECTOR (c1
);
5343 d2
= (struct save_window_data
*) XVECTOR (c2
);
5344 sw1
= XVECTOR (d1
->saved_windows
);
5345 sw2
= XVECTOR (d2
->saved_windows
);
5347 if (! EQ (d1
->frame_width
, d2
->frame_width
))
5349 if (! EQ (d1
->frame_height
, d2
->frame_height
))
5351 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
5353 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
5355 /* Don't compare the current_window field directly.
5356 Instead see w1_is_current and w2_is_current, below. */
5357 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
5359 if (! ignore_positions
)
5360 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
5362 /* Don't compare the root_window field.
5363 We don't require the two configurations
5364 to use the same window object,
5365 and the two root windows must be equivalent
5366 if everything else compares equal. */
5367 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
5369 if (! EQ (d1
->min_width
, d2
->min_width
))
5371 if (! EQ (d1
->min_height
, d2
->min_height
))
5374 /* Verify that the two confis have the same number of windows. */
5375 if (sw1
->size
!= sw2
->size
)
5378 for (i
= 0; i
< sw1
->size
; i
++)
5380 struct saved_window
*p1
, *p2
;
5381 int w1_is_current
, w2_is_current
;
5383 p1
= SAVED_WINDOW_N (sw1
, i
);
5384 p2
= SAVED_WINDOW_N (sw2
, i
);
5386 /* Verify that the current windows in the two
5387 configurations correspond to each other. */
5388 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
5389 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
5391 if (w1_is_current
!= w2_is_current
)
5394 /* Verify that the corresponding windows do match. */
5395 if (! EQ (p1
->buffer
, p2
->buffer
))
5397 if (! EQ (p1
->left
, p2
->left
))
5399 if (! EQ (p1
->top
, p2
->top
))
5401 if (! EQ (p1
->width
, p2
->width
))
5403 if (! EQ (p1
->height
, p2
->height
))
5405 if (! EQ (p1
->display_table
, p2
->display_table
))
5407 if (! EQ (p1
->parent
, p2
->parent
))
5409 if (! EQ (p1
->prev
, p2
->prev
))
5411 if (! ignore_positions
)
5413 if (! EQ (p1
->hscroll
, p2
->hscroll
))
5415 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
5417 if (NILP (Fequal (p1
->start
, p2
->start
)))
5419 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
5421 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
5429 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
5430 Scompare_window_configurations
, 2, 2, 0,
5431 "Compare two window configurations as regards the structure of windows.\n\
5432 This function ignores details such as the values of point and mark\n\
5433 and scrolling positions.")
5437 if (compare_window_configurations (x
, y
, 1))
5445 struct frame
*f
= make_terminal_frame ();
5446 XSETFRAME (selected_frame
, f
);
5447 Vterminal_frame
= selected_frame
;
5448 minibuf_window
= f
->minibuffer_window
;
5449 selected_window
= f
->selected_window
;
5450 last_nonminibuf_frame
= f
;
5452 window_initialized
= 1;
5458 Vwindow_list
= Qnil
;
5464 Qleft_bitmap_area
= intern ("left-bitmap-area");
5465 staticpro (&Qleft_bitmap_area
);
5466 Qright_bitmap_area
= intern ("right-bitmap-area");
5467 staticpro (&Qright_bitmap_area
);
5469 Qwindow_size_fixed
= intern ("window-size-fixed");
5470 staticpro (&Qwindow_size_fixed
);
5472 staticpro (&Qwindow_configuration_change_hook
);
5473 Qwindow_configuration_change_hook
5474 = intern ("window-configuration-change-hook");
5476 Qwindowp
= intern ("windowp");
5477 staticpro (&Qwindowp
);
5479 Qwindow_configuration_p
= intern ("window-configuration-p");
5480 staticpro (&Qwindow_configuration_p
);
5482 Qwindow_live_p
= intern ("window-live-p");
5483 staticpro (&Qwindow_live_p
);
5485 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
5486 staticpro (&Qtemp_buffer_show_hook
);
5488 staticpro (&Vwindow_list
);
5490 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
5491 "Non-nil means call as function to display a help buffer.\n\
5492 The function is called with one argument, the buffer to be displayed.\n\
5493 Used by `with-output-to-temp-buffer'.\n\
5494 If this function is used, then it must do the entire job of showing\n\
5495 the buffer; `temp-buffer-show-hook' is not run unless this function runs it.");
5496 Vtemp_buffer_show_function
= Qnil
;
5498 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
5499 "If non-nil, function to call to handle `display-buffer'.\n\
5500 It will receive two args, the buffer and a flag which if non-nil means\n\
5501 that the currently selected window is not acceptable.\n\
5502 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\
5503 work using this function.");
5504 Vdisplay_buffer_function
= Qnil
;
5506 DEFVAR_LISP ("even-window-heights", &Veven_window_heights
,
5507 "*If non-nil, `display-buffer' should even the window heights.\n\
5508 If nil, `display-buffer' will leave the window configuration alone.");
5509 Veven_window_heights
= Qt
;
5511 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
5512 "Non-nil means it is the window that C-M-v in minibuffer should scroll.");
5513 Vminibuf_scroll_window
= Qnil
;
5515 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
5516 "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.");
5517 Vother_window_scroll_buffer
= Qnil
;
5519 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
5520 "*Non-nil means `display-buffer' should make a separate frame.");
5523 DEFVAR_BOOL ("display-buffer-reuse-frames", &display_buffer_reuse_frames
,
5524 "*Non-nil means `display-buffer' should reuse frames.\n\
5525 If the buffer in question is already displayed in a frame, raise that frame.");
5526 display_buffer_reuse_frames
= 0;
5528 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
5529 "Function to call to handle automatic new frame creation.\n\
5530 It is called with no arguments and should return a newly created frame.\n\
5532 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\
5533 where `pop-up-frame-alist' would hold the default frame parameters.");
5534 Vpop_up_frame_function
= Qnil
;
5536 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
5537 "*List of buffer names that should have their own special frames.\n\
5538 Displaying a buffer whose name is in this list makes a special frame for it\n\
5539 using `special-display-function'. See also `special-display-regexps'.\n\
5541 An element of the list can be a list instead of just a string.\n\
5542 There are two ways to use a list as an element:\n\
5543 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)\n\
5544 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
5545 In the latter case, FUNCTION is called with BUFFER as the first argument,\n\
5546 followed by OTHER-ARGS--it can display BUFFER in any way it likes.\n\
5547 All this is done by the function found in `special-display-function'.\n\
5549 If this variable appears \"not to work\", because you add a name to it\n\
5550 but that buffer still appears in the selected window, look at the\n\
5551 values of `same-window-buffer-names' and `same-window-regexps'.\n\
5552 Those variables take precedence over this one.");
5553 Vspecial_display_buffer_names
= Qnil
;
5555 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
5556 "*List of regexps saying which buffers should have their own special frames.\n\
5557 If a buffer name matches one of these regexps, it gets its own frame.\n\
5558 Displaying a buffer whose name is in this list makes a special frame for it\n\
5559 using `special-display-function'.\n\
5561 An element of the list can be a list instead of just a string.\n\
5562 There are two ways to use a list as an element:\n\
5563 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)\n\
5564 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
5565 In the latter case, FUNCTION is called with the buffer as first argument,\n\
5566 followed by OTHER-ARGS--it can display the buffer in any way it likes.\n\
5567 All this is done by the function found in `special-display-function'.\n\
5569 If this variable appears \"not to work\", because you add a regexp to it\n\
5570 but the matching buffers still appear in the selected window, look at the\n\
5571 values of `same-window-buffer-names' and `same-window-regexps'.\n\
5572 Those variables take precedence over this one.");
5573 Vspecial_display_regexps
= Qnil
;
5575 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
5576 "Function to call to make a new frame for a special buffer.\n\
5577 It is called with two arguments, the buffer and optional buffer specific\n\
5578 data, and should return a window displaying that buffer.\n\
5579 The default value makes a separate frame for the buffer,\n\
5580 using `special-display-frame-alist' to specify the frame parameters.\n\
5582 A buffer is special if its is listed in `special-display-buffer-names'\n\
5583 or matches a regexp in `special-display-regexps'.");
5584 Vspecial_display_function
= Qnil
;
5586 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
5587 "*List of buffer names that should appear in the selected window.\n\
5588 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'\n\
5589 switches to it in the selected window, rather than making it appear\n\
5590 in some other window.\n\
5592 An element of the list can be a cons cell instead of just a string.\n\
5593 Then the car must be a string, which specifies the buffer name.\n\
5594 This is for compatibility with `special-display-buffer-names';\n\
5595 the cdr of the cons cell is ignored.\n\
5597 See also `same-window-regexps'.");
5598 Vsame_window_buffer_names
= Qnil
;
5600 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
5601 "*List of regexps saying which buffers should appear in the selected window.\n\
5602 If a buffer name matches one of these regexps, then displaying it\n\
5603 using `display-buffer' or `pop-to-buffer' switches to it\n\
5604 in the selected window, rather than making it appear in some other window.\n\
5606 An element of the list can be a cons cell instead of just a string.\n\
5607 Then the car must be a string, which specifies the buffer name.\n\
5608 This is for compatibility with `special-display-buffer-names';\n\
5609 the cdr of the cons cell is ignored.\n\
5611 See also `same-window-buffer-names'.");
5612 Vsame_window_regexps
= Qnil
;
5614 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
5615 "*Non-nil means display-buffer should make new windows.");
5618 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
5619 "*Number of lines of continuity when scrolling by screenfuls.");
5620 next_screen_context_lines
= 2;
5622 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
5623 "*display-buffer would prefer to split the largest window if this large.\n\
5624 If there is only one window, it is split regardless of this value.");
5625 split_height_threshold
= 500;
5627 DEFVAR_INT ("window-min-height", &window_min_height
,
5628 "*Delete any window less than this tall (including its mode line).");
5629 window_min_height
= 4;
5631 DEFVAR_INT ("window-min-width", &window_min_width
,
5632 "*Delete any window less than this wide.");
5633 window_min_width
= 10;
5635 DEFVAR_LISP ("scroll-preserve-screen-position",
5636 &Vscroll_preserve_screen_position
,
5637 "*Nonzero means scroll commands move point to keep its screen line unchanged.");
5638 Vscroll_preserve_screen_position
= Qnil
;
5640 DEFVAR_LISP ("window-configuration-change-hook",
5641 &Vwindow_configuration_change_hook
,
5642 "Functions to call when window configuration changes.\n\
5643 The selected frame is the one whose configuration has changed.");
5644 Vwindow_configuration_change_hook
= Qnil
;
5646 defsubr (&Sselected_window
);
5647 defsubr (&Sminibuffer_window
);
5648 defsubr (&Swindow_minibuffer_p
);
5649 defsubr (&Swindowp
);
5650 defsubr (&Swindow_live_p
);
5651 defsubr (&Spos_visible_in_window_p
);
5652 defsubr (&Swindow_buffer
);
5653 defsubr (&Swindow_height
);
5654 defsubr (&Swindow_width
);
5655 defsubr (&Swindow_hscroll
);
5656 defsubr (&Sset_window_hscroll
);
5657 defsubr (&Swindow_redisplay_end_trigger
);
5658 defsubr (&Sset_window_redisplay_end_trigger
);
5659 defsubr (&Swindow_edges
);
5660 defsubr (&Scoordinates_in_window_p
);
5661 defsubr (&Swindow_at
);
5662 defsubr (&Swindow_point
);
5663 defsubr (&Swindow_start
);
5664 defsubr (&Swindow_end
);
5665 defsubr (&Sset_window_point
);
5666 defsubr (&Sset_window_start
);
5667 defsubr (&Swindow_dedicated_p
);
5668 defsubr (&Sset_window_dedicated_p
);
5669 defsubr (&Swindow_display_table
);
5670 defsubr (&Sset_window_display_table
);
5671 defsubr (&Snext_window
);
5672 defsubr (&Sprevious_window
);
5673 defsubr (&Sother_window
);
5674 defsubr (&Sget_lru_window
);
5675 defsubr (&Sget_largest_window
);
5676 defsubr (&Sget_buffer_window
);
5677 defsubr (&Sdelete_other_windows
);
5678 defsubr (&Sdelete_windows_on
);
5679 defsubr (&Sreplace_buffer_in_windows
);
5680 defsubr (&Sdelete_window
);
5681 defsubr (&Sset_window_buffer
);
5682 defsubr (&Sselect_window
);
5683 defsubr (&Sspecial_display_p
);
5684 defsubr (&Ssame_window_p
);
5685 defsubr (&Sdisplay_buffer
);
5686 defsubr (&Ssplit_window
);
5687 defsubr (&Senlarge_window
);
5688 defsubr (&Sshrink_window
);
5689 defsubr (&Sscroll_up
);
5690 defsubr (&Sscroll_down
);
5691 defsubr (&Sscroll_left
);
5692 defsubr (&Sscroll_right
);
5693 defsubr (&Sother_window_for_scrolling
);
5694 defsubr (&Sscroll_other_window
);
5695 defsubr (&Srecenter
);
5696 defsubr (&Smove_to_window_line
);
5697 defsubr (&Swindow_configuration_p
);
5698 defsubr (&Swindow_configuration_frame
);
5699 defsubr (&Sset_window_configuration
);
5700 defsubr (&Scurrent_window_configuration
);
5701 defsubr (&Ssave_window_excursion
);
5702 defsubr (&Sset_window_margins
);
5703 defsubr (&Swindow_margins
);
5704 defsubr (&Swindow_vscroll
);
5705 defsubr (&Sset_window_vscroll
);
5706 defsubr (&Scompare_window_configurations
);
5707 defsubr (&Swindow_list
);
5713 initial_define_key (control_x_map
, '1', "delete-other-windows");
5714 initial_define_key (control_x_map
, '2', "split-window");
5715 initial_define_key (control_x_map
, '0', "delete-window");
5716 initial_define_key (control_x_map
, 'o', "other-window");
5717 initial_define_key (control_x_map
, '^', "enlarge-window");
5718 initial_define_key (control_x_map
, '<', "scroll-left");
5719 initial_define_key (control_x_map
, '>', "scroll-right");
5721 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
5722 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
5723 initial_define_key (meta_map
, 'v', "scroll-down");
5725 initial_define_key (global_map
, Ctl('L'), "recenter");
5726 initial_define_key (meta_map
, 'r', "move-to-window-line");