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 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
32 #include "blockinput.h"
34 Lisp_Object Qwindowp
, Qwindow_live_p
;
36 static struct window
*decode_window
P_ ((Lisp_Object
));
38 /* This is the window in which the terminal's cursor should
39 be left when nothing is being done with it. This must
40 always be a leaf window, and its buffer is selected by
41 the top level editing loop at the end of each command.
43 This value is always the same as
44 FRAME_SELECTED_WINDOW (selected_frame). */
46 Lisp_Object selected_window
;
48 /* The minibuffer window of the selected frame.
49 Note that you cannot test for minibufferness of an arbitrary window
50 by comparing against this; but you can test for minibufferness of
51 the selected window. */
52 Lisp_Object minibuf_window
;
54 /* Non-nil means it is the window for C-M-v to scroll
55 when the minibuffer is selected. */
56 Lisp_Object Vminibuf_scroll_window
;
58 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
59 Lisp_Object Vother_window_scroll_buffer
;
61 /* Non-nil means it's function to call to display temp buffers. */
62 Lisp_Object Vtemp_buffer_show_function
;
64 /* If a window gets smaller than either of these, it is removed. */
65 int window_min_height
;
68 /* Nonzero implies Fdisplay_buffer should create windows. */
71 /* Nonzero implies make new frames for Fdisplay_buffer. */
74 /* Non-nil means use this function instead of default */
75 Lisp_Object Vpop_up_frame_function
;
77 /* Function to call to handle Fdisplay_buffer. */
78 Lisp_Object Vdisplay_buffer_function
;
80 /* List of buffer *names* for buffers that should have their own frames. */
81 Lisp_Object Vspecial_display_buffer_names
;
83 /* List of regexps for buffer names that should have their own frames. */
84 Lisp_Object Vspecial_display_regexps
;
86 /* Function to pop up a special frame. */
87 Lisp_Object Vspecial_display_function
;
89 /* List of buffer *names* for buffers to appear in selected window. */
90 Lisp_Object Vsame_window_buffer_names
;
92 /* List of regexps for buffer names to appear in selected window. */
93 Lisp_Object Vsame_window_regexps
;
95 /* Hook run at end of temp_output_buffer_show. */
96 Lisp_Object Qtemp_buffer_show_hook
;
98 /* Fdisplay_buffer always splits the largest window
99 if that window is more than this high. */
100 int split_height_threshold
;
102 /* Number of lines of continuity in scrolling by screenfuls. */
103 int next_screen_context_lines
;
105 /* Incremented for each window created. */
106 static int sequence_number
;
108 /* Nonzero after init_window_once has finished. */
109 static int window_initialized
;
111 /* Hook to run when window config changes. */
112 Lisp_Object Qwindow_configuration_change_hook
;
113 Lisp_Object Vwindow_configuration_change_hook
;
115 /* Nonzero means scroll commands try to put point
116 at the same screen height as previously. */
117 static int scroll_preserve_screen_position
;
119 /* Nonzero means we can split a frame even if it is "unsplittable". */
120 static int inhibit_frame_unsplittable
;
122 #define min(a, b) ((a) < (b) ? (a) : (b))
124 extern int scroll_margin
;
126 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
128 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
129 "Returns t if OBJECT is a window.")
133 return WINDOWP (object
) ? Qt
: Qnil
;
136 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
137 "Returns t if OBJECT is a window which is currently visible.")
141 return (WINDOWP (object
) && ! NILP (XWINDOW (object
)->buffer
) ? Qt
: Qnil
);
148 register struct window
*p
;
149 register struct Lisp_Vector
*vec
;
152 vec
= allocate_vectorlike ((EMACS_INT
) VECSIZE (struct window
));
153 for (i
= 0; i
< VECSIZE (struct window
); i
++)
154 vec
->contents
[i
] = Qnil
;
155 vec
->size
= VECSIZE (struct window
);
156 p
= (struct window
*)vec
;
157 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
158 XSETFASTINT (p
->left
, 0);
159 XSETFASTINT (p
->top
, 0);
160 XSETFASTINT (p
->height
, 0);
161 XSETFASTINT (p
->width
, 0);
162 XSETFASTINT (p
->hscroll
, 0);
163 XSETFASTINT (p
->last_point_x
, 0);
164 XSETFASTINT (p
->last_point_y
, 0);
165 p
->start
= Fmake_marker ();
166 p
->pointm
= Fmake_marker ();
167 XSETFASTINT (p
->use_time
, 0);
169 p
->display_table
= Qnil
;
175 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
176 "Return the window that the cursor now appears in and commands apply to.")
179 return selected_window
;
182 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
183 "Return the window used now for minibuffers.\n\
184 If the optional argument FRAME is specified, return the minibuffer window\n\
185 used by that frame.")
190 XSETFRAME (frame
, selected_frame
);
192 CHECK_LIVE_FRAME (frame
, 0);
194 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
197 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
198 "Returns non-nil if WINDOW is a minibuffer window.")
202 struct window
*w
= decode_window (window
);
203 return (MINI_WINDOW_P (w
) ? Qt
: Qnil
);
206 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
207 Spos_visible_in_window_p
, 0, 2, 0,
208 "Return t if position POS is currently on the frame in WINDOW.\n\
209 Returns nil if that position is scrolled vertically out of view.\n\
210 POS defaults to point; WINDOW, to the selected window.")
212 Lisp_Object pos
, window
;
214 register struct window
*w
;
218 register struct buffer
*buf
;
219 struct position posval
;
226 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
230 w
= decode_window (window
);
231 top
= marker_position (w
->start
);
232 hscroll
= XINT (w
->hscroll
);
237 height
= XFASTINT (w
->height
) - ! MINI_WINDOW_P (w
);
239 buf
= XBUFFER (w
->buffer
);
240 if (XFASTINT (w
->last_modified
) >= BUF_MODIFF (buf
)
241 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (buf
))
243 /* If frame is up to date,
244 use the info recorded about how much text fit on it. */
245 if (posint
< BUF_Z (buf
) - XFASTINT (w
->window_end_pos
)
246 || (XFASTINT (w
->window_end_vpos
) < height
))
252 if (posint
> BUF_ZV (buf
))
255 /* w->start can be out of range. If it is, do something reasonable. */
256 if (top
< BUF_BEGV (buf
) || top
> BUF_ZV (buf
))
259 /* If that info is not correct, calculate afresh */
260 /* BUG FIX for the 7th arg (TOHPOS).
262 '0' is harmless, however, ' - (1 << (BITS_PER_SHORT - 1))' is
263 more appropriate here. In case of HSCROLL > 0, this can avoid
264 needless calculation done until (HPOS == 0).
266 We want to determine if the position POSINT is in HEIGHT or
267 not. We don't have to do calculation until (HPOS == 0). We
268 can stop it when VPOS goes beyond HEIGHT. */
269 posval
= *compute_motion (top
, 0, (hscroll
? 1 - hscroll
: 0), 0,
270 posint
, height
, - (1 << (BITS_PER_SHORT
- 1)),
271 window_internal_width (w
) - 1,
274 return posval
.vpos
< height
? Qt
: Qnil
;
278 static struct window
*
279 decode_window (window
)
280 register Lisp_Object window
;
283 return XWINDOW (selected_window
);
285 CHECK_LIVE_WINDOW (window
, 0);
286 return XWINDOW (window
);
289 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
290 "Return the buffer that WINDOW is displaying.")
294 return decode_window (window
)->buffer
;
297 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
298 "Return the number of lines in WINDOW (including its mode line).")
302 return decode_window (window
)->height
;
305 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
306 "Return the number of display columns in WINDOW.\n\
307 This is the width that is usable columns available for text in WINDOW.\n\
308 If you want to find out how many columns WINDOW takes up,\n\
309 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))).")
313 return make_number (window_internal_width (decode_window (window
)));
316 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
317 "Return the number of columns by which WINDOW is scrolled from left margin.")
321 return decode_window (window
)->hscroll
;
324 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
325 "Set number of columns WINDOW is scrolled from left margin to NCOL.\n\
326 NCOL should be zero or positive.")
328 register Lisp_Object window
, ncol
;
330 register struct window
*w
;
332 CHECK_NUMBER (ncol
, 1);
333 if (XINT (ncol
) < 0) XSETFASTINT (ncol
, 0);
334 w
= decode_window (window
);
335 if (XINT (w
->hscroll
) != XINT (ncol
))
336 XBUFFER (w
->buffer
)->clip_changed
= 1; /* Prevent redisplay shortcuts */
341 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
342 Swindow_redisplay_end_trigger
, 0, 1, 0,
343 "Return WINDOW's redisplay end trigger value.\n\
344 See `set-window-redisplay-end-trigger' for more information.")
348 return decode_window (window
)->redisplay_end_trigger
;
351 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
352 Sset_window_redisplay_end_trigger
, 2, 2, 0,
353 "Set WINDOW's redisplay end trigger value to VALUE.\n\
354 VALUE should be a buffer position (typically a marker) or nil.\n\
355 If it is a buffer position, then if redisplay in WINDOW reaches a position\n\
356 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called\n\
357 with two arguments: WINDOW, and the end trigger value.\n\
358 Afterwards the end-trigger value is reset to nil.")
360 register Lisp_Object window
, value
;
362 register struct window
*w
;
364 w
= decode_window (window
);
365 w
->redisplay_end_trigger
= value
;
369 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
370 "Return a list of the edge coordinates of WINDOW.\n\
371 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.\n\
372 RIGHT is one more than the rightmost column used by WINDOW,\n\
373 and BOTTOM is one more than the bottommost row used by WINDOW\n\
378 register struct window
*w
= decode_window (window
);
380 return Fcons (w
->left
, Fcons (w
->top
,
381 Fcons (make_number (WINDOW_RIGHT_EDGE (w
)),
382 Fcons (make_number (XFASTINT (w
->top
)
383 + XFASTINT (w
->height
)),
387 /* Test if the character at column *x, row *y is within window *w.
388 If it is not, return 0;
389 if it is in the window's text area,
390 set *x and *y to its location relative to the upper left corner
393 if it is on the window's modeline, return 2;
394 if it is on the border between the window and its right sibling,
397 coordinates_in_window (w
, x
, y
)
398 register struct window
*w
;
401 register int left
= XINT (w
->left
);
402 register int right_edge
= WINDOW_RIGHT_EDGE (w
);
403 register int left_margin
= WINDOW_LEFT_MARGIN (w
);
404 register int right_margin
= WINDOW_RIGHT_MARGIN (w
);
405 register int window_height
= XINT (w
->height
);
406 register int top
= XFASTINT (w
->top
);
408 if ( *x
< left
|| *x
>= right_edge
409 || *y
< top
|| *y
>= top
+ window_height
)
412 if (left_margin
!= left
&& *x
< left_margin
&& *x
>= left
)
415 if (right_margin
!= right_edge
&& *x
>= right_margin
&& *x
< right_edge
)
418 /* Is the character is the mode line? */
419 if (*y
== top
+ window_height
- 1
420 && ! MINI_WINDOW_P (w
))
423 *x
-= WINDOW_LEFT_MARGIN (w
);
428 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
429 Scoordinates_in_window_p
, 2, 2, 0,
430 "Return non-nil if COORDINATES are in WINDOW.\n\
431 COORDINATES is a cons of the form (X . Y), X and Y being distances\n\
432 measured in characters from the upper-left corner of the frame.\n\
433 (0 . 0) denotes the character in the upper left corner of the\n\
435 If COORDINATES are in the text portion of WINDOW,\n\
436 the coordinates relative to the window are returned.\n\
437 If they are in the mode line of WINDOW, `mode-line' is returned.\n\
438 If they are on the border between WINDOW and its right sibling,\n\
439 `vertical-line' is returned.")
440 (coordinates
, window
)
441 register Lisp_Object coordinates
, window
;
445 CHECK_LIVE_WINDOW (window
, 0);
446 CHECK_CONS (coordinates
, 1);
447 x
= XINT (Fcar (coordinates
));
448 y
= XINT (Fcdr (coordinates
));
450 switch (coordinates_in_window (XWINDOW (window
), &x
, &y
))
452 case 0: /* NOT in window at all. */
455 case 1: /* In text part of window. */
456 return Fcons (make_number (x
), make_number (y
));
458 case 2: /* In mode line of window. */
461 case 3: /* On right border of window. */
462 return Qvertical_line
;
469 /* Find the window containing column x, row y, and return it as a
470 Lisp_Object. If x, y is on the window's modeline, set *part
471 to 1; if it is on the separating line between the window and its
472 right sibling, set it to 2; otherwise set it to 0. If there is no
473 window under x, y return nil and leave *part unmodified. */
475 window_from_coordinates (frame
, x
, y
, part
)
480 register Lisp_Object tem
, first
;
482 tem
= first
= FRAME_SELECTED_WINDOW (frame
);
486 int found
= coordinates_in_window (XWINDOW (tem
), &x
, &y
);
494 tem
= Fnext_window (tem
, Qt
, Qlambda
);
496 while (! EQ (tem
, first
));
501 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
502 "Return window containing coordinates X and Y on FRAME.\n\
503 If omitted, FRAME defaults to the currently selected frame.\n\
504 The top left corner of the frame is considered to be row 0,\n\
507 Lisp_Object x
, y
, frame
;
512 XSETFRAME (frame
, selected_frame
);
514 CHECK_LIVE_FRAME (frame
, 2);
518 return window_from_coordinates (XFRAME (frame
),
523 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
524 "Return current value of point in WINDOW.\n\
525 For a nonselected window, this is the value point would have\n\
526 if that window were selected.\n\
528 Note that, when WINDOW is the selected window and its buffer\n\
529 is also currently selected, the value returned is the same as (point).\n\
530 It would be more strictly correct to return the `top-level' value\n\
531 of point, outside of any save-excursion forms.\n\
532 But that is hard to define.")
536 register struct window
*w
= decode_window (window
);
538 if (w
== XWINDOW (selected_window
)
539 && current_buffer
== XBUFFER (w
->buffer
))
541 return Fmarker_position (w
->pointm
);
544 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
545 "Return position at which display currently starts in WINDOW.\n\
546 This is updated by redisplay or by calling `set-window-start'.")
550 return Fmarker_position (decode_window (window
)->start
);
553 /* This is text temporarily removed from the doc string below.
555 This function returns nil if the position is not currently known.\n\
556 That happens when redisplay is preempted and doesn't finish.\n\
557 If in that case you want to compute where the end of the window would\n\
558 have been if redisplay had finished, do this:\n\
560 (goto-char (window-start window))\n\
561 (vertical-motion (1- (window-height window)) window)\n\
564 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
565 "Return position at which display currently ends in WINDOW.\n\
566 This is updated by redisplay, when it runs to completion.\n\
567 Simply changing the buffer text or setting `window-start'\n\
568 does not update this value.\n\
569 If UP-TO-DATE is non-nil, compute the up-to-date position\n\
570 if it isn't already recorded.")
572 Lisp_Object window
, update
;
575 struct window
*w
= decode_window (window
);
579 CHECK_BUFFER (buf
, 0);
581 #if 0 /* This change broke some things. We should make it later. */
582 /* If we don't know the end position, return nil.
583 The user can compute it with vertical-motion if he wants to.
584 It would be nicer to do it automatically,
585 but that's so slow that it would probably bother people. */
586 if (NILP (w
->window_end_valid
))
591 && ! (! NILP (w
->window_end_valid
)
592 && XFASTINT (w
->last_modified
) >= MODIFF
))
594 int opoint
= PT
, opoint_byte
= PT_BYTE
;
595 TEMP_SET_PT_BOTH (XMARKER (w
->start
)->charpos
,
596 XMARKER (w
->start
)->bytepos
);
597 Fvertical_motion (make_number (window_internal_height (w
)), Qnil
);
599 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
603 BUF_Z (XBUFFER (buf
)) - XFASTINT (w
->window_end_pos
));
608 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
609 "Make point value in WINDOW be at position POS in WINDOW's buffer.")
611 Lisp_Object window
, pos
;
613 register struct window
*w
= decode_window (window
);
615 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
616 if (w
== XWINDOW (selected_window
))
619 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
624 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
625 "Make display in WINDOW start at position POS in WINDOW's buffer.\n\
626 Optional third arg NOFORCE non-nil inhibits next redisplay\n\
627 from overriding motion of point in order to display at this exact start.")
628 (window
, pos
, noforce
)
629 Lisp_Object window
, pos
, noforce
;
631 register struct window
*w
= decode_window (window
);
633 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
634 set_marker_restricted (w
->start
, pos
, w
->buffer
);
635 /* this is not right, but much easier than doing what is right. */
636 w
->start_at_line_beg
= Qnil
;
639 w
->update_mode_line
= Qt
;
640 XSETFASTINT (w
->last_modified
, 0);
641 XSETFASTINT (w
->last_overlay_modified
, 0);
642 if (!EQ (window
, selected_window
))
643 windows_or_buffers_changed
++;
647 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
649 "Return WINDOW's dedicated object, usually t or nil.\n\
650 See also `set-window-dedicated-p'.")
654 return decode_window (window
)->dedicated
;
657 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
658 Sset_window_dedicated_p
, 2, 2, 0,
659 "Control whether WINDOW is dedicated to the buffer it displays.\n\
660 If it is dedicated, Emacs will not automatically change\n\
661 which buffer appears in it.\n\
662 The second argument is the new value for the dedication flag;\n\
665 Lisp_Object window
, arg
;
667 register struct window
*w
= decode_window (window
);
677 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
679 "Return the display-table that WINDOW is using.")
683 return decode_window (window
)->display_table
;
686 /* Get the display table for use currently on window W.
687 This is either W's display table or W's buffer's display table.
688 Ignore the specified tables if they are not valid;
689 if no valid table is specified, return 0. */
691 struct Lisp_Char_Table
*
692 window_display_table (w
)
696 tem
= w
->display_table
;
697 if (DISP_TABLE_P (tem
))
698 return XCHAR_TABLE (tem
);
699 if (NILP (w
->buffer
))
702 tem
= XBUFFER (w
->buffer
)->display_table
;
703 if (DISP_TABLE_P (tem
))
704 return XCHAR_TABLE (tem
);
705 tem
= Vstandard_display_table
;
706 if (DISP_TABLE_P (tem
))
707 return XCHAR_TABLE (tem
);
711 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
712 "Set WINDOW's display-table to TABLE.")
714 register Lisp_Object window
, table
;
716 register struct window
*w
;
717 register Lisp_Object z
; /* Return value. */
719 w
= decode_window (window
);
720 w
->display_table
= table
;
724 /* Record info on buffer window w is displaying
725 when it is about to cease to display that buffer. */
728 register struct window
*w
;
735 if (b
!= XMARKER (w
->pointm
)->buffer
)
738 if (w
== XWINDOW (b
->last_selected_window
))
739 b
->last_selected_window
= Qnil
;
742 if (w
== XWINDOW (selected_window
)
743 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
744 /* Do this except when the selected window's buffer
745 is being removed from some other window. */
747 /* last_window_start records the start position that this buffer
748 had in the last window to be disconnected from it.
749 Now that this statement is unconditional,
750 it is possible for the buffer to be displayed in the
751 selected window, while last_window_start reflects another
752 window which was recently showing the same buffer.
753 Some people might say that might be a good thing. Let's see. */
754 b
->last_window_start
= marker_position (w
->start
);
756 /* Point in the selected window's buffer
757 is actually stored in that buffer, and the window's pointm isn't used.
758 So don't clobber point in that buffer. */
759 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
))
760 temp_set_point_both (b
,
761 clip_to_bounds (BUF_BEGV (b
),
762 XMARKER (w
->pointm
)->charpos
,
764 clip_to_bounds (BUF_BEGV_BYTE (b
),
765 marker_byte_position (w
->pointm
),
769 /* Put replacement into the window structure in place of old. */
771 replace_window (old
, replacement
)
772 Lisp_Object old
, replacement
;
774 register Lisp_Object tem
;
775 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
777 /* If OLD is its frame's root_window, then replacement is the new
778 root_window for that frame. */
780 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
781 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
786 p
->height
= o
->height
;
788 p
->next
= tem
= o
->next
;
790 XWINDOW (tem
)->prev
= replacement
;
792 p
->prev
= tem
= o
->prev
;
794 XWINDOW (tem
)->next
= replacement
;
796 p
->parent
= tem
= o
->parent
;
799 if (EQ (XWINDOW (tem
)->vchild
, old
))
800 XWINDOW (tem
)->vchild
= replacement
;
801 if (EQ (XWINDOW (tem
)->hchild
, old
))
802 XWINDOW (tem
)->hchild
= replacement
;
805 /*** Here, if replacement is a vertical combination
806 and so is its new parent, we should make replacement's
807 children be children of that parent instead. ***/
810 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
811 "Remove WINDOW from the display. Default is selected window.")
813 register Lisp_Object window
;
815 delete_window (window
);
817 if (! NILP (Vwindow_configuration_change_hook
)
818 && ! NILP (Vrun_hooks
))
819 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
825 delete_window (window
)
826 register Lisp_Object window
;
828 register Lisp_Object tem
, parent
, sib
;
829 register struct window
*p
;
830 register struct window
*par
;
832 /* Because this function is called by other C code on non-leaf
833 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
834 so we can't decode_window here. */
836 window
= selected_window
;
838 CHECK_WINDOW (window
, 0);
839 p
= XWINDOW (window
);
841 /* It's okay to delete an already-deleted window. */
849 error ("Attempt to delete minibuffer or sole ordinary window");
850 par
= XWINDOW (parent
);
852 windows_or_buffers_changed
++;
853 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (p
))) = 1;
855 /* Are we trying to delete any frame's selected window? */
857 Lisp_Object frame
, pwindow
;
859 /* See if the frame's selected window is either WINDOW
860 or any subwindow of it, by finding all that window's parents
861 and comparing each one with WINDOW. */
862 frame
= WINDOW_FRAME (XWINDOW (window
));
863 pwindow
= FRAME_SELECTED_WINDOW (XFRAME (frame
));
865 while (!NILP (pwindow
))
867 if (EQ (window
, pwindow
))
869 pwindow
= XWINDOW (pwindow
)->parent
;
872 if (EQ (window
, pwindow
))
874 Lisp_Object alternative
;
875 alternative
= Fnext_window (window
, Qlambda
, Qnil
);
877 /* If we're about to delete the selected window on the
878 selected frame, then we should use Fselect_window to select
879 the new window. On the other hand, if we're about to
880 delete the selected window on any other frame, we shouldn't do
881 anything but set the frame's selected_window slot. */
882 if (EQ (window
, selected_window
))
883 Fselect_window (alternative
);
885 FRAME_SELECTED_WINDOW (XFRAME (frame
)) = alternative
;
890 /* tem is null for dummy parent windows
891 (which have inferiors but not any contents themselves) */
895 unchain_marker (p
->pointm
);
896 unchain_marker (p
->start
);
901 XWINDOW (tem
)->prev
= p
->prev
;
905 XWINDOW (tem
)->next
= p
->next
;
907 if (EQ (window
, par
->hchild
))
908 par
->hchild
= p
->next
;
909 if (EQ (window
, par
->vchild
))
910 par
->vchild
= p
->next
;
912 /* Find one of our siblings to give our space to. */
916 /* If p gives its space to its next sibling, that sibling needs
917 to have its top/left side pulled back to where p's is.
918 set_window_{height,width} will re-position the sibling's
921 XWINDOW (sib
)->top
= p
->top
;
922 XWINDOW (sib
)->left
= p
->left
;
925 /* Stretch that sibling. */
926 if (!NILP (par
->vchild
))
927 set_window_height (sib
,
928 XFASTINT (XWINDOW (sib
)->height
) + XFASTINT (p
->height
),
930 if (!NILP (par
->hchild
))
931 set_window_width (sib
,
932 XFASTINT (XWINDOW (sib
)->width
) + XFASTINT (p
->width
),
935 /* If parent now has only one child,
936 put the child into the parent's place. */
940 if (NILP (XWINDOW (tem
)->next
))
941 replace_window (parent
, tem
);
943 /* Since we may be deleting combination windows, we must make sure that
944 not only p but all its children have been marked as deleted. */
945 if (! NILP (p
->hchild
))
946 delete_all_subwindows (XWINDOW (p
->hchild
));
947 else if (! NILP (p
->vchild
))
948 delete_all_subwindows (XWINDOW (p
->vchild
));
950 /* Mark this window as deleted. */
951 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
955 extern Lisp_Object
next_frame (), prev_frame ();
957 /* This comment supplies the doc string for `next-window',
958 for make-docfile to see. We cannot put this in the real DEFUN
959 due to limits in the Unix cpp.
961 DEFUN ("next-window", Ffoo, Sfoo, 0, 3, 0,
962 "Return next window after WINDOW in canonical ordering of windows.\n\
963 If omitted, WINDOW defaults to the selected window.\n\
965 Optional second arg MINIBUF t means count the minibuffer window even\n\
966 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
967 it is active. MINIBUF neither t nor nil means not to count the\n\
968 minibuffer even if it is active.\n\
970 Several frames may share a single minibuffer; if the minibuffer\n\
971 counts, all windows on all frames that share that minibuffer count\n\
972 too. Therefore, `next-window' can be used to iterate through the\n\
973 set of windows even when the minibuffer is on another frame. If the\n\
974 minibuffer does not count, only windows from WINDOW's frame count.\n\
976 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
977 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
978 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
979 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
980 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
981 Anything else means restrict to WINDOW's frame.\n\
983 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
984 `next-window' to iterate through the entire cycle of acceptable\n\
985 windows, eventually ending up back at the window you started with.\n\
986 `previous-window' traverses the same cycle, in the reverse order.")
987 (window, minibuf, all_frames) */
989 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
991 (window
, minibuf
, all_frames
)
992 register Lisp_Object window
, minibuf
, all_frames
;
994 register Lisp_Object tem
;
995 Lisp_Object start_window
;
998 window
= selected_window
;
1000 CHECK_LIVE_WINDOW (window
, 0);
1002 start_window
= window
;
1004 /* minibuf == nil may or may not include minibuffers.
1005 Decide if it does. */
1007 minibuf
= (minibuf_level
? minibuf_window
: Qlambda
);
1008 else if (! EQ (minibuf
, Qt
))
1010 /* Now minibuf can be t => count all minibuffer windows,
1011 lambda => count none of them,
1012 or a specific minibuffer window (the active one) to count. */
1014 /* all_frames == nil doesn't specify which frames to include. */
1015 if (NILP (all_frames
))
1016 all_frames
= (! EQ (minibuf
, Qlambda
)
1017 ? (FRAME_MINIBUF_WINDOW
1020 (XWINDOW (window
)))))
1022 else if (EQ (all_frames
, Qvisible
))
1024 else if (XFASTINT (all_frames
) == 0)
1026 else if (FRAMEP (all_frames
) && ! EQ (all_frames
, Fwindow_frame (window
)))
1027 /* If all_frames is a frame and window arg isn't on that frame, just
1028 return the first window on the frame. */
1029 return Fframe_first_window (all_frames
);
1030 else if (! EQ (all_frames
, Qt
))
1032 /* Now all_frames is t meaning search all frames,
1033 nil meaning search just current frame,
1034 visible meaning search just visible frames,
1035 0 meaning search visible and iconified frames,
1036 or a window, meaning search the frame that window belongs to. */
1038 /* Do this loop at least once, to get the next window, and perhaps
1039 again, if we hit the minibuffer and that is not acceptable. */
1042 /* Find a window that actually has a next one. This loop
1043 climbs up the tree. */
1044 while (tem
= XWINDOW (window
)->next
, NILP (tem
))
1045 if (tem
= XWINDOW (window
)->parent
, !NILP (tem
))
1049 /* We've reached the end of this frame.
1050 Which other frames are acceptable? */
1051 tem
= WINDOW_FRAME (XWINDOW (window
));
1052 if (! NILP (all_frames
))
1057 tem
= next_frame (tem
, all_frames
);
1058 /* In the case where the minibuffer is active,
1059 and we include its frame as well as the selected one,
1060 next_frame may get stuck in that frame.
1061 If that happens, go back to the selected frame
1062 so we can complete the cycle. */
1064 XSETFRAME (tem
, selected_frame
);
1066 tem
= FRAME_ROOT_WINDOW (XFRAME (tem
));
1073 /* If we're in a combination window, find its first child and
1074 recurse on that. Otherwise, we've found the window we want. */
1077 if (!NILP (XWINDOW (window
)->hchild
))
1078 window
= XWINDOW (window
)->hchild
;
1079 else if (!NILP (XWINDOW (window
)->vchild
))
1080 window
= XWINDOW (window
)->vchild
;
1084 /* Which windows are acceptable?
1085 Exit the loop and accept this window if
1086 this isn't a minibuffer window,
1087 or we're accepting all minibuffer windows,
1088 or this is the active minibuffer and we are accepting that one, or
1089 we've come all the way around and we're back at the original window. */
1090 while (MINI_WINDOW_P (XWINDOW (window
))
1091 && ! EQ (minibuf
, Qt
)
1092 && ! EQ (minibuf
, window
)
1093 && ! EQ (window
, start_window
));
1098 /* This comment supplies the doc string for `previous-window',
1099 for make-docfile to see. We cannot put this in the real DEFUN
1100 due to limits in the Unix cpp.
1102 DEFUN ("previous-window", Ffoo, Sfoo, 0, 3, 0,
1103 "Return the window preceding WINDOW in canonical ordering of windows.\n\
1104 If omitted, WINDOW defaults to the selected window.\n\
1106 Optional second arg MINIBUF t means count the minibuffer window even\n\
1107 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1108 it is active. MINIBUF neither t nor nil means not to count the\n\
1109 minibuffer even if it is active.\n\
1111 Several frames may share a single minibuffer; if the minibuffer\n\
1112 counts, all windows on all frames that share that minibuffer count\n\
1113 too. Therefore, `previous-window' can be used to iterate through\n\
1114 the set of windows even when the minibuffer is on another frame. If\n\
1115 the minibuffer does not count, only windows from WINDOW's frame count\n\
1117 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1118 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1119 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1120 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1121 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1122 Anything else means restrict to WINDOW's frame.\n\
1124 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1125 `previous-window' to iterate through the entire cycle of acceptable\n\
1126 windows, eventually ending up back at the window you started with.\n\
1127 `next-window' traverses the same cycle, in the reverse order.")
1128 (window, minibuf, all_frames) */
1131 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1133 (window
, minibuf
, all_frames
)
1134 register Lisp_Object window
, minibuf
, all_frames
;
1136 register Lisp_Object tem
;
1137 Lisp_Object start_window
;
1140 window
= selected_window
;
1142 CHECK_LIVE_WINDOW (window
, 0);
1144 start_window
= window
;
1146 /* minibuf == nil may or may not include minibuffers.
1147 Decide if it does. */
1149 minibuf
= (minibuf_level
? minibuf_window
: Qlambda
);
1150 else if (! EQ (minibuf
, Qt
))
1152 /* Now minibuf can be t => count all minibuffer windows,
1153 lambda => count none of them,
1154 or a specific minibuffer window (the active one) to count. */
1156 /* all_frames == nil doesn't specify which frames to include.
1157 Decide which frames it includes. */
1158 if (NILP (all_frames
))
1159 all_frames
= (! EQ (minibuf
, Qlambda
)
1160 ? (FRAME_MINIBUF_WINDOW
1163 (XWINDOW (window
)))))
1165 else if (EQ (all_frames
, Qvisible
))
1167 else if (XFASTINT (all_frames
) == 0)
1169 else if (FRAMEP (all_frames
) && ! EQ (all_frames
, Fwindow_frame (window
)))
1170 /* If all_frames is a frame and window arg isn't on that frame, just
1171 return the first window on the frame. */
1172 return Fframe_first_window (all_frames
);
1173 else if (! EQ (all_frames
, Qt
))
1175 /* Now all_frames is t meaning search all frames,
1176 nil meaning search just current frame,
1177 visible meaning search just visible frames,
1178 0 meaning search visible and iconified frames,
1179 or a window, meaning search the frame that window belongs to. */
1181 /* Do this loop at least once, to get the previous window, and perhaps
1182 again, if we hit the minibuffer and that is not acceptable. */
1185 /* Find a window that actually has a previous one. This loop
1186 climbs up the tree. */
1187 while (tem
= XWINDOW (window
)->prev
, NILP (tem
))
1188 if (tem
= XWINDOW (window
)->parent
, !NILP (tem
))
1192 /* We have found the top window on the frame.
1193 Which frames are acceptable? */
1194 tem
= WINDOW_FRAME (XWINDOW (window
));
1195 if (! NILP (all_frames
))
1196 /* It's actually important that we use prev_frame here,
1197 rather than next_frame. All the windows acceptable
1198 according to the given parameters should form a ring;
1199 Fnext_window and Fprevious_window should go back and
1200 forth around the ring. If we use next_frame here,
1201 then Fnext_window and Fprevious_window take different
1202 paths through the set of acceptable windows.
1203 window_loop assumes that these `ring' requirement are
1209 tem
= prev_frame (tem
, all_frames
);
1210 /* In the case where the minibuffer is active,
1211 and we include its frame as well as the selected one,
1212 next_frame may get stuck in that frame.
1213 If that happens, go back to the selected frame
1214 so we can complete the cycle. */
1216 XSETFRAME (tem
, selected_frame
);
1218 /* If this frame has a minibuffer, find that window first,
1219 because it is conceptually the last window in that frame. */
1220 if (FRAME_HAS_MINIBUF_P (XFRAME (tem
)))
1221 tem
= FRAME_MINIBUF_WINDOW (XFRAME (tem
));
1223 tem
= FRAME_ROOT_WINDOW (XFRAME (tem
));
1229 /* If we're in a combination window, find its last child and
1230 recurse on that. Otherwise, we've found the window we want. */
1233 if (!NILP (XWINDOW (window
)->hchild
))
1234 window
= XWINDOW (window
)->hchild
;
1235 else if (!NILP (XWINDOW (window
)->vchild
))
1236 window
= XWINDOW (window
)->vchild
;
1238 while (tem
= XWINDOW (window
)->next
, !NILP (tem
))
1242 /* Which windows are acceptable?
1243 Exit the loop and accept this window if
1244 this isn't a minibuffer window,
1245 or we're accepting all minibuffer windows,
1246 or this is the active minibuffer and we are accepting that one, or
1247 we've come all the way around and we're back at the original window. */
1248 while (MINI_WINDOW_P (XWINDOW (window
))
1249 && ! EQ (minibuf
, Qt
)
1250 && ! EQ (minibuf
, window
)
1251 && ! EQ (window
, start_window
));
1256 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1257 "Select the ARG'th different window on this frame.\n\
1258 All windows on current frame are arranged in a cyclic order.\n\
1259 This command selects the window ARG steps away in that order.\n\
1260 A negative ARG moves in the opposite order. If the optional second\n\
1261 argument ALL_FRAMES is non-nil, cycle through all frames.")
1263 register Lisp_Object arg
, all_frames
;
1266 register Lisp_Object w
;
1268 CHECK_NUMBER (arg
, 0);
1269 w
= selected_window
;
1274 w
= Fnext_window (w
, Qnil
, all_frames
);
1279 w
= Fprevious_window (w
, Qnil
, all_frames
);
1286 /* Look at all windows, performing an operation specified by TYPE
1288 If FRAMES is Qt, look at all frames;
1289 Qnil, look at just the selected frame;
1290 Qvisible, look at visible frames;
1291 a frame, just look at windows on that frame.
1292 If MINI is non-zero, perform the operation on minibuffer windows too.
1298 GET_BUFFER_WINDOW
, /* Arg is buffer */
1299 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1300 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1301 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1303 UNSHOW_BUFFER
/* Arg is buffer */
1307 window_loop (type
, obj
, mini
, frames
)
1308 enum window_loop type
;
1309 register Lisp_Object obj
, frames
;
1312 register Lisp_Object w
;
1313 register Lisp_Object best_window
;
1314 register Lisp_Object next_window
;
1315 register Lisp_Object last_window
;
1317 Lisp_Object frame_arg
;
1320 /* If we're only looping through windows on a particular frame,
1321 frame points to that frame. If we're looping through windows
1322 on all frames, frame is 0. */
1323 if (FRAMEP (frames
))
1324 frame
= XFRAME (frames
);
1325 else if (NILP (frames
))
1326 frame
= selected_frame
;
1330 frame_arg
= Qlambda
;
1331 else if (XFASTINT (frames
) == 0)
1333 else if (EQ (frames
, Qvisible
))
1336 /* frame_arg is Qlambda to stick to one frame,
1337 Qvisible to consider all visible frames,
1340 /* Pick a window to start with. */
1344 w
= FRAME_SELECTED_WINDOW (frame
);
1346 w
= FRAME_SELECTED_WINDOW (selected_frame
);
1348 /* Figure out the last window we're going to mess with. Since
1349 Fnext_window, given the same options, is guaranteed to go in a
1350 ring, we can just use Fprevious_window to find the last one.
1352 We can't just wait until we hit the first window again, because
1353 it might be deleted. */
1355 last_window
= Fprevious_window (w
, mini
? Qt
: Qnil
, frame_arg
);
1360 FRAME_PTR w_frame
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1362 /* Pick the next window now, since some operations will delete
1363 the current window. */
1364 next_window
= Fnext_window (w
, mini
? Qt
: Qnil
, frame_arg
);
1366 /* Note that we do not pay attention here to whether
1367 the frame is visible, since Fnext_window skips non-visible frames
1368 if that is desired, under the control of frame_arg. */
1369 if (! MINI_WINDOW_P (XWINDOW (w
))
1370 || (mini
&& minibuf_level
> 0))
1373 case GET_BUFFER_WINDOW
:
1374 if (XBUFFER (XWINDOW (w
)->buffer
) == XBUFFER (obj
)
1375 /* Don't find any minibuffer window
1376 except the one that is currently in use. */
1377 && (MINI_WINDOW_P (XWINDOW (w
))
1378 ? EQ (w
, minibuf_window
) : 1))
1382 case GET_LRU_WINDOW
:
1383 /* t as arg means consider only full-width windows */
1384 if (!NILP (obj
) && !WINDOW_FULL_WIDTH_P (XWINDOW (w
)))
1386 /* Ignore dedicated windows and minibuffers. */
1387 if (MINI_WINDOW_P (XWINDOW (w
))
1388 || !NILP (XWINDOW (w
)->dedicated
))
1390 if (NILP (best_window
)
1391 || (XFASTINT (XWINDOW (best_window
)->use_time
)
1392 > XFASTINT (XWINDOW (w
)->use_time
)))
1396 case DELETE_OTHER_WINDOWS
:
1397 if (XWINDOW (w
) != XWINDOW (obj
))
1401 case DELETE_BUFFER_WINDOWS
:
1402 if (EQ (XWINDOW (w
)->buffer
, obj
))
1404 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1406 /* If this window is dedicated, and in a frame of its own,
1408 if (EQ (w
, FRAME_ROOT_WINDOW (f
))
1409 && !NILP (XWINDOW (w
)->dedicated
)
1410 && other_visible_frames (f
))
1412 /* Skip the other windows on this frame.
1413 There might be one, the minibuffer! */
1414 if (! EQ (w
, last_window
))
1415 while (f
== XFRAME (WINDOW_FRAME (XWINDOW (next_window
))))
1417 /* As we go, check for the end of the loop.
1418 We mustn't start going around a second time. */
1419 if (EQ (next_window
, last_window
))
1424 next_window
= Fnext_window (next_window
,
1428 /* Now we can safely delete the frame. */
1429 Fdelete_frame (WINDOW_FRAME (XWINDOW (w
)), Qnil
);
1432 /* If we're deleting the buffer displayed in the only window
1433 on the frame, find a new buffer to display there. */
1434 if (NILP (XWINDOW (w
)->parent
))
1436 Lisp_Object new_buffer
;
1437 new_buffer
= Fother_buffer (obj
, Qnil
);
1438 if (NILP (new_buffer
))
1440 = Fget_buffer_create (build_string ("*scratch*"));
1441 Fset_window_buffer (w
, new_buffer
);
1442 if (EQ (w
, selected_window
))
1443 Fset_buffer (XWINDOW (w
)->buffer
);
1450 case GET_LARGEST_WINDOW
:
1451 /* Ignore dedicated windows and minibuffers. */
1452 if (MINI_WINDOW_P (XWINDOW (w
))
1453 || !NILP (XWINDOW (w
)->dedicated
))
1456 struct window
*best_window_ptr
= XWINDOW (best_window
);
1457 struct window
*w_ptr
= XWINDOW (w
);
1458 if (NILP (best_window
)
1459 || (XFASTINT (w_ptr
->height
) * XFASTINT (w_ptr
->width
)
1460 > (XFASTINT (best_window_ptr
->height
)
1461 * XFASTINT (best_window_ptr
->width
))))
1467 if (EQ (XWINDOW (w
)->buffer
, obj
))
1469 /* Find another buffer to show in this window. */
1470 Lisp_Object another_buffer
;
1471 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1472 another_buffer
= Fother_buffer (obj
, Qnil
);
1473 if (NILP (another_buffer
))
1475 = Fget_buffer_create (build_string ("*scratch*"));
1476 /* If this window is dedicated, and in a frame of its own,
1478 if (EQ (w
, FRAME_ROOT_WINDOW (f
))
1479 && !NILP (XWINDOW (w
)->dedicated
)
1480 && other_visible_frames (f
))
1482 /* Skip the other windows on this frame.
1483 There might be one, the minibuffer! */
1484 if (! EQ (w
, last_window
))
1485 while (f
== XFRAME (WINDOW_FRAME (XWINDOW (next_window
))))
1487 /* As we go, check for the end of the loop.
1488 We mustn't start going around a second time. */
1489 if (EQ (next_window
, last_window
))
1494 next_window
= Fnext_window (next_window
,
1498 /* Now we can safely delete the frame. */
1499 Fdelete_frame (WINDOW_FRAME (XWINDOW (w
)), Qnil
);
1503 /* Otherwise show a different buffer in the window. */
1504 XWINDOW (w
)->dedicated
= Qnil
;
1505 Fset_window_buffer (w
, another_buffer
);
1506 if (EQ (w
, selected_window
))
1507 Fset_buffer (XWINDOW (w
)->buffer
);
1513 if (EQ (w
, last_window
))
1522 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 1, 0,
1523 "Return the window least recently selected or used for display.\n\
1524 If optional argument FRAME is `visible', search all visible frames.\n\
1525 If FRAME is 0, search all visible and iconified frames.\n\
1526 If FRAME is t, search all frames.\n\
1527 If FRAME is nil, search only the selected frame.\n\
1528 If FRAME is a frame, search only that frame.")
1532 register Lisp_Object w
;
1533 /* First try for a window that is full-width */
1534 w
= window_loop (GET_LRU_WINDOW
, Qt
, 0, frame
);
1535 if (!NILP (w
) && !EQ (w
, selected_window
))
1537 /* If none of them, try the rest */
1538 return window_loop (GET_LRU_WINDOW
, Qnil
, 0, frame
);
1541 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 1, 0,
1542 "Return the largest window in area.\n\
1543 If optional argument FRAME is `visible', search all visible frames.\n\
1544 If FRAME is 0, search all visible and iconified frames.\n\
1545 If FRAME is t, search all frames.\n\
1546 If FRAME is nil, search only the selected frame.\n\
1547 If FRAME is a frame, search only that frame.")
1551 return window_loop (GET_LARGEST_WINDOW
, Qnil
, 0,
1555 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
1556 "Return a window currently displaying BUFFER, or nil if none.\n\
1557 If optional argument FRAME is `visible', search all visible frames.\n\
1558 If optional argument FRAME is 0, search all visible and iconified frames.\n\
1559 If FRAME is t, search all frames.\n\
1560 If FRAME is nil, search only the selected frame.\n\
1561 If FRAME is a frame, search only that frame.")
1563 Lisp_Object buffer
, frame
;
1565 buffer
= Fget_buffer (buffer
);
1566 if (BUFFERP (buffer
))
1567 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
1572 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
1574 "Make WINDOW (or the selected window) fill its frame.\n\
1575 Only the frame WINDOW is on is affected.\n\
1576 This function tries to reduce display jumps\n\
1577 by keeping the text previously visible in WINDOW\n\
1578 in the same place on the frame. Doing this depends on\n\
1579 the value of (window-start WINDOW), so if calling this function\n\
1580 in a program gives strange scrolling, make sure the window-start\n\
1581 value is reasonable when this function is called.")
1590 window
= selected_window
;
1592 CHECK_LIVE_WINDOW (window
, 0);
1594 w
= XWINDOW (window
);
1596 startpos
= marker_position (w
->start
);
1597 top
= XFASTINT (w
->top
) - FRAME_MENU_BAR_LINES (XFRAME (WINDOW_FRAME (w
)));
1599 if (MINI_WINDOW_P (w
) && top
> 0)
1600 error ("Can't expand minibuffer to full frame");
1602 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
1604 /* Try to minimize scrolling, by setting the window start to the point
1605 will cause the text at the old window start to be at the same place
1606 on the frame. But don't try to do this if the window start is
1607 outside the visible portion (as might happen when the display is
1608 not current, due to typeahead). */
1609 if (startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
1610 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
1612 struct position pos
;
1613 struct buffer
*obuf
= current_buffer
;
1615 Fset_buffer (w
->buffer
);
1616 /* This computation used to temporarily move point, but that can
1617 have unwanted side effects due to text properties. */
1618 pos
= *vmotion (startpos
, -top
, w
);
1620 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
1621 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
1622 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
1624 /* We need to do this, so that the window-scroll-functions
1626 w
->optional_new_start
= Qt
;
1628 set_buffer_internal (obuf
);
1633 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
1634 1, 2, "bDelete windows on (buffer): ",
1635 "Delete all windows showing BUFFER.\n\
1636 Optional second argument FRAME controls which frames are affected.\n\
1637 If nil or omitted, delete all windows showing BUFFER in any frame.\n\
1638 If t, delete only windows showing BUFFER in the selected frame.\n\
1639 If `visible', delete all windows showing BUFFER in any visible frame.\n\
1640 If a frame, delete only windows showing BUFFER in that frame.")
1642 Lisp_Object buffer
, frame
;
1644 /* FRAME uses t and nil to mean the opposite of what window_loop
1646 if (! FRAMEP (frame
))
1647 frame
= NILP (frame
) ? Qt
: Qnil
;
1651 buffer
= Fget_buffer (buffer
);
1652 CHECK_BUFFER (buffer
, 0);
1653 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
1658 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
1659 Sreplace_buffer_in_windows
,
1660 1, 1, "bReplace buffer in windows: ",
1661 "Replace BUFFER with some other buffer in all windows showing it.")
1667 buffer
= Fget_buffer (buffer
);
1668 CHECK_BUFFER (buffer
, 0);
1669 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
1674 /* Replace BUFFER with some other buffer in all windows
1675 of all frames, even those on other keyboards. */
1678 replace_buffer_in_all_windows (buffer
)
1682 Lisp_Object tail
, frame
;
1684 /* A single call to window_loop won't do the job
1685 because it only considers frames on the current keyboard.
1686 So loop manually over frames, and handle each one. */
1687 FOR_EACH_FRAME (tail
, frame
)
1688 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
1690 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
1694 /* Set the height of WINDOW and all its inferiors. */
1696 /* The smallest acceptable dimensions for a window. Anything smaller
1697 might crash Emacs. */
1698 #define MIN_SAFE_WINDOW_WIDTH (2)
1699 #define MIN_SAFE_WINDOW_HEIGHT (2)
1701 /* Make sure that window_min_height and window_min_width are
1702 not too small; if they are, set them to safe minima. */
1705 check_min_window_sizes ()
1707 /* Smaller values might permit a crash. */
1708 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
1709 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
1710 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
1711 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
1714 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
1715 minimum allowable size. */
1717 check_frame_size (frame
, rows
, cols
)
1721 /* For height, we have to see:
1722 whether the frame has a minibuffer,
1723 whether it wants a mode line, and
1724 whether it has a menu bar. */
1726 (FRAME_MINIBUF_ONLY_P (frame
) ? MIN_SAFE_WINDOW_HEIGHT
- 1
1727 : (! FRAME_HAS_MINIBUF_P (frame
)) ? MIN_SAFE_WINDOW_HEIGHT
1728 : 2 * MIN_SAFE_WINDOW_HEIGHT
- 1);
1729 if (FRAME_MENU_BAR_LINES (frame
) > 0)
1730 min_height
+= FRAME_MENU_BAR_LINES (frame
);
1732 if (*rows
< min_height
)
1734 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
1735 *cols
= MIN_SAFE_WINDOW_WIDTH
;
1738 /* Normally the window is deleted if it gets too small.
1739 nodelete nonzero means do not do this.
1740 (The caller should check later and do so if appropriate) */
1743 set_window_height (window
, height
, nodelete
)
1748 register struct window
*w
= XWINDOW (window
);
1749 register struct window
*c
;
1750 int oheight
= XFASTINT (w
->height
);
1751 int top
, pos
, lastbot
, opos
, lastobot
;
1754 check_min_window_sizes ();
1757 && ! NILP (w
->parent
)
1758 && (MINI_WINDOW_P (w
)
1760 : height
< window_min_height
))
1762 delete_window (window
);
1766 XSETFASTINT (w
->last_modified
, 0);
1767 XSETFASTINT (w
->last_overlay_modified
, 0);
1768 windows_or_buffers_changed
++;
1769 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
1771 XSETFASTINT (w
->height
, height
);
1772 if (!NILP (w
->hchild
))
1774 for (child
= w
->hchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1776 XWINDOW (child
)->top
= w
->top
;
1777 set_window_height (child
, height
, nodelete
);
1780 else if (!NILP (w
->vchild
))
1782 lastbot
= top
= XFASTINT (w
->top
);
1784 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
1786 c
= XWINDOW (child
);
1788 opos
= lastobot
+ XFASTINT (c
->height
);
1790 XSETFASTINT (c
->top
, lastbot
);
1792 pos
= (((opos
* height
) << 1) + oheight
) / (oheight
<< 1);
1794 /* Avoid confusion: inhibit deletion of child if becomes too small */
1795 set_window_height (child
, pos
+ top
- lastbot
, 1);
1797 /* Now advance child to next window,
1798 and set lastbot if child was not just deleted. */
1799 lastbot
= pos
+ top
;
1802 /* Now delete any children that became too small. */
1804 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1806 set_window_height (child
, XINT (XWINDOW (child
)->height
), 0);
1811 /* Recursively set width of WINDOW and its inferiors. */
1814 set_window_width (window
, width
, nodelete
)
1819 register struct window
*w
= XWINDOW (window
);
1820 register struct window
*c
;
1821 int owidth
= XFASTINT (w
->width
);
1822 int left
, pos
, lastright
, opos
, lastoright
;
1825 if (!nodelete
&& width
< window_min_width
&& !NILP (w
->parent
))
1827 delete_window (window
);
1831 XSETFASTINT (w
->last_modified
, 0);
1832 XSETFASTINT (w
->last_overlay_modified
, 0);
1833 windows_or_buffers_changed
++;
1834 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
1836 XSETFASTINT (w
->width
, width
);
1837 if (!NILP (w
->vchild
))
1839 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1841 XWINDOW (child
)->left
= w
->left
;
1842 set_window_width (child
, width
, nodelete
);
1845 else if (!NILP (w
->hchild
))
1847 lastright
= left
= XFASTINT (w
->left
);
1849 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
1851 c
= XWINDOW (child
);
1853 opos
= lastoright
+ XFASTINT (c
->width
);
1855 XSETFASTINT (c
->left
, lastright
);
1857 pos
= (((opos
* width
) << 1) + owidth
) / (owidth
<< 1);
1859 /* Inhibit deletion for becoming too small */
1860 set_window_width (child
, pos
+ left
- lastright
, 1);
1862 /* Now advance child to next window,
1863 and set lastright if child was not just deleted. */
1864 lastright
= pos
+ left
, lastoright
= opos
;
1866 /* Delete children that became too small */
1868 for (child
= w
->hchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1870 set_window_width (child
, XINT (XWINDOW (child
)->width
), 0);
1875 int window_select_count
;
1878 Fset_window_buffer_unwind (obuf
)
1885 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 2, 0,
1886 "Make WINDOW display BUFFER as its contents.\n\
1887 BUFFER can be a buffer or buffer name.")
1889 register Lisp_Object window
, buffer
;
1891 register Lisp_Object tem
;
1892 register struct window
*w
= decode_window (window
);
1893 int count
= specpdl_ptr
- specpdl
;
1895 buffer
= Fget_buffer (buffer
);
1896 CHECK_BUFFER (buffer
, 1);
1898 if (NILP (XBUFFER (buffer
)->name
))
1899 error ("Attempt to display deleted buffer");
1903 error ("Window is deleted");
1904 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
1905 is first being set up. */
1907 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
1908 error ("Window is dedicated to `%s'",
1909 XSTRING (XBUFFER (tem
)->name
)->data
);
1916 if (EQ (window
, selected_window
))
1917 XBUFFER (w
->buffer
)->last_selected_window
= window
;
1918 if (INTEGERP (XBUFFER (buffer
)->display_count
))
1919 XSETINT (XBUFFER (buffer
)->display_count
,
1920 XINT (XBUFFER (buffer
)->display_count
) + 1);
1922 XSETFASTINT (w
->window_end_pos
, 0);
1923 w
->window_end_valid
= Qnil
;
1924 XSETFASTINT (w
->hscroll
, 0);
1925 set_marker_both (w
->pointm
, buffer
,
1926 BUF_PT (XBUFFER (buffer
)), BUF_PT_BYTE (XBUFFER (buffer
)));
1927 set_marker_restricted (w
->start
,
1928 make_number (XBUFFER (buffer
)->last_window_start
),
1930 w
->start_at_line_beg
= Qnil
;
1931 w
->force_start
= Qnil
;
1932 XSETFASTINT (w
->last_modified
, 0);
1933 XSETFASTINT (w
->last_overlay_modified
, 0);
1934 windows_or_buffers_changed
++;
1936 /* We must select BUFFER for running the window-scroll-functions.
1937 If WINDOW is selected, switch permanently.
1938 Otherwise, switch but go back to the ambient buffer afterward. */
1939 if (EQ (window
, selected_window
))
1940 Fset_buffer (buffer
);
1941 /* We can't check ! NILP (Vwindow_scroll_functions) here
1942 because that might itself be a local variable. */
1943 else if (window_initialized
)
1945 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
1946 Fset_buffer (buffer
);
1949 if (! NILP (Vwindow_scroll_functions
))
1950 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1951 Fmarker_position (w
->start
));
1953 if (! NILP (Vwindow_configuration_change_hook
)
1954 && ! NILP (Vrun_hooks
))
1955 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
1957 unbind_to (count
, Qnil
);
1962 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 1, 0,
1963 "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\
1964 The main editor command loop selects the buffer of the selected window\n\
1965 before each command.")
1967 register Lisp_Object window
;
1969 register struct window
*w
;
1970 register struct window
*ow
= XWINDOW (selected_window
);
1972 CHECK_LIVE_WINDOW (window
, 0);
1974 w
= XWINDOW (window
);
1976 if (NILP (w
->buffer
))
1977 error ("Trying to select deleted window or non-leaf window");
1979 XSETFASTINT (w
->use_time
, ++window_select_count
);
1980 if (EQ (window
, selected_window
))
1983 if (! NILP (ow
->buffer
))
1984 set_marker_both (ow
->pointm
, ow
->buffer
,
1985 BUF_PT (XBUFFER (ow
->buffer
)),
1986 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
1988 selected_window
= window
;
1989 if (XFRAME (WINDOW_FRAME (w
)) != selected_frame
)
1991 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
1992 /* Use this rather than Fhandle_switch_frame
1993 so that FRAME_FOCUS_FRAME is moved appropriately as we
1994 move around in the state where a minibuffer in a separate
1996 Fselect_frame (WINDOW_FRAME (w
), Qnil
);
1999 selected_frame
->selected_window
= window
;
2001 record_buffer (w
->buffer
);
2002 Fset_buffer (w
->buffer
);
2004 XBUFFER (w
->buffer
)->last_selected_window
= window
;
2006 /* Go to the point recorded in the window.
2007 This is important when the buffer is in more
2008 than one window. It also matters when
2009 redisplay_window has altered point after scrolling,
2010 because it makes the change only in the window. */
2012 register int new_point
= marker_position (w
->pointm
);
2013 if (new_point
< BEGV
)
2015 else if (new_point
> ZV
)
2021 windows_or_buffers_changed
++;
2025 /* Deiconify the frame containing the window WINDOW,
2026 unless it is the selected frame;
2029 The reason for the exception for the selected frame
2030 is that it seems better not to change the selected frames visibility
2031 merely because of displaying a different buffer in it.
2032 The deiconification is useful when a buffer gets shown in
2033 another frame that you were not using lately. */
2036 display_buffer_1 (window
)
2039 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
2040 FRAME_SAMPLE_VISIBILITY (f
);
2041 if (f
!= selected_frame
)
2043 if (FRAME_ICONIFIED_P (f
))
2044 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
2045 else if (FRAME_VISIBLE_P (f
))
2046 Fraise_frame (WINDOW_FRAME (XWINDOW (window
)));
2051 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
2052 "Returns non-nil if a buffer named BUFFER-NAME would be created specially.\n\
2053 The value is actually t if the frame should be called with default frame\n\
2054 parameters, and a list of frame parameters if they were specified.\n\
2055 See `special-display-buffer-names', and `special-display-regexps'.")
2057 Lisp_Object buffer_name
;
2061 CHECK_STRING (buffer_name
, 1);
2063 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
2067 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
2071 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2073 Lisp_Object car
= XCAR (tem
);
2075 && fast_string_match (car
, buffer_name
) >= 0)
2077 else if (CONSP (car
)
2078 && STRINGP (XCAR (car
))
2079 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2085 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
2086 "Returns non-nil if a new buffer named BUFFER-NAME would use the same window.\n\
2087 See `same-window-buffer-names' and `same-window-regexps'.")
2089 Lisp_Object buffer_name
;
2093 CHECK_STRING (buffer_name
, 1);
2095 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
2099 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
2103 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2105 Lisp_Object car
= XCAR (tem
);
2107 && fast_string_match (car
, buffer_name
) >= 0)
2109 else if (CONSP (car
)
2110 && STRINGP (XCAR (car
))
2111 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2117 /* Use B so the default is (other-buffer). */
2118 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
2119 "BDisplay buffer: \nP",
2120 "Make BUFFER appear in some window but don't select it.\n\
2121 BUFFER can be a buffer or a buffer name.\n\
2122 If BUFFER is shown already in some window, just use that one,\n\
2123 unless the window is the selected window and the optional second\n\
2124 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).\n\
2125 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.\n\
2126 Returns the window displaying BUFFER.\n\
2128 The variables `special-display-buffer-names', `special-display-regexps',\n\
2129 `same-window-buffer-names', and `same-window-regexps' customize how certain\n\
2130 buffer names are handled.\n\
2132 If optional argument FRAME is `visible', search all visible frames.\n\
2133 If FRAME is 0, search all visible and iconified frames.\n\
2134 If FRAME is t, search all frames.\n\
2135 If FRAME is a frame, search only that frame.\n\
2136 If FRAME is nil, search only the selected frame\n\
2137 (actually the last nonminibuffer frame),\n\
2138 unless `pop-up-frames' is non-nil,\n\
2139 which means search visible and iconified frames.")
2140 (buffer
, not_this_window
, frame
)
2141 register Lisp_Object buffer
, not_this_window
, frame
;
2143 register Lisp_Object window
, tem
;
2145 buffer
= Fget_buffer (buffer
);
2146 CHECK_BUFFER (buffer
, 0);
2148 if (!NILP (Vdisplay_buffer_function
))
2149 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
2151 if (NILP (not_this_window
)
2152 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
2153 return display_buffer_1 (selected_window
);
2155 /* See if the user has specified this buffer should appear
2156 in the selected window. */
2157 if (NILP (not_this_window
))
2159 tem
= Fsame_window_p (XBUFFER (buffer
)->name
);
2162 Fswitch_to_buffer (buffer
, Qnil
);
2163 return display_buffer_1 (selected_window
);
2167 /* If pop_up_frames,
2168 look for a window showing BUFFER on any visible or iconified frame.
2169 Otherwise search only the current frame. */
2172 else if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2173 XSETFASTINT (tem
, 0);
2175 XSETFRAME (tem
, last_nonminibuf_frame
);
2176 window
= Fget_buffer_window (buffer
, tem
);
2178 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
2180 return display_buffer_1 (window
);
2183 /* Certain buffer names get special handling. */
2184 if (!NILP (Vspecial_display_function
))
2186 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
2188 return call1 (Vspecial_display_function
, buffer
);
2190 return call2 (Vspecial_display_function
, buffer
, tem
);
2193 /* If there are no frames open that have more than a minibuffer,
2194 we need to create a new frame. */
2195 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2197 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2198 Fset_window_buffer (window
, buffer
);
2199 return display_buffer_1 (window
);
2203 || FRAME_MINIBUF_ONLY_P (selected_frame
)
2204 /* If the current frame is a special display frame,
2205 don't try to reuse its windows. */
2206 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (selected_frame
))->dedicated
)
2212 if (FRAME_MINIBUF_ONLY_P (selected_frame
))
2213 XSETFRAME (frames
, last_nonminibuf_frame
);
2214 /* Don't try to create a window if would get an error */
2215 if (split_height_threshold
< window_min_height
<< 1)
2216 split_height_threshold
= window_min_height
<< 1;
2218 /* Note that both Fget_largest_window and Fget_lru_window
2219 ignore minibuffers and dedicated windows.
2220 This means they can return nil. */
2222 /* If the frame we would try to split cannot be split,
2223 try other frames. */
2224 if (FRAME_NO_SPLIT_P (NILP (frames
) ? selected_frame
2225 : last_nonminibuf_frame
))
2227 /* Try visible frames first. */
2228 window
= Fget_largest_window (Qvisible
);
2229 /* If that didn't work, try iconified frames. */
2231 window
= Fget_largest_window (make_number (0));
2233 window
= Fget_largest_window (Qt
);
2236 window
= Fget_largest_window (frames
);
2238 /* If we got a tall enough full-width window that can be split,
2241 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2242 && window_height (window
) >= split_height_threshold
2243 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
2244 window
= Fsplit_window (window
, Qnil
, Qnil
);
2247 Lisp_Object upper
, lower
, other
;
2249 window
= Fget_lru_window (frames
);
2250 /* If the LRU window is selected, and big enough,
2251 and can be split, split it. */
2253 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2254 && (EQ (window
, selected_window
)
2255 || EQ (XWINDOW (window
)->parent
, Qnil
))
2256 && window_height (window
) >= window_min_height
<< 1)
2257 window
= Fsplit_window (window
, Qnil
, Qnil
);
2258 /* If Fget_lru_window returned nil, try other approaches. */
2260 /* Try visible frames first. */
2262 window
= Fget_buffer_window (buffer
, Qvisible
);
2264 window
= Fget_largest_window (Qvisible
);
2265 /* If that didn't work, try iconified frames. */
2267 window
= Fget_buffer_window (buffer
, make_number (0));
2269 window
= Fget_largest_window (make_number (0));
2270 /* Try invisible frames. */
2272 window
= Fget_buffer_window (buffer
, Qt
);
2274 window
= Fget_largest_window (Qt
);
2275 /* As a last resort, make a new frame. */
2277 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2278 /* If window appears above or below another,
2279 even out their heights. */
2280 other
= upper
= lower
= Qnil
;
2281 if (!NILP (XWINDOW (window
)->prev
))
2282 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
2283 if (!NILP (XWINDOW (window
)->next
))
2284 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
2286 /* Check that OTHER and WINDOW are vertically arrayed. */
2287 && !EQ (XWINDOW (other
)->top
, XWINDOW (window
)->top
)
2288 && (XFASTINT (XWINDOW (other
)->height
)
2289 > XFASTINT (XWINDOW (window
)->height
)))
2291 int total
= (XFASTINT (XWINDOW (other
)->height
)
2292 + XFASTINT (XWINDOW (window
)->height
));
2293 Lisp_Object old_selected_window
;
2294 old_selected_window
= selected_window
;
2296 selected_window
= upper
;
2297 change_window_height ((total
/ 2
2298 - XFASTINT (XWINDOW (upper
)->height
)),
2300 selected_window
= old_selected_window
;
2305 window
= Fget_lru_window (Qnil
);
2307 Fset_window_buffer (window
, buffer
);
2308 return display_buffer_1 (window
);
2312 temp_output_buffer_show (buf
)
2313 register Lisp_Object buf
;
2315 register struct buffer
*old
= current_buffer
;
2316 register Lisp_Object window
;
2317 register struct window
*w
;
2319 XBUFFER (buf
)->directory
= current_buffer
->directory
;
2322 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
2326 XBUFFER (buf
)->clip_changed
= 1;
2327 set_buffer_internal (old
);
2329 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
2330 call1 (Vtemp_buffer_show_function
, buf
);
2333 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
2335 if (XFRAME (XWINDOW (window
)->frame
) != selected_frame
)
2336 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
2337 Vminibuf_scroll_window
= window
;
2338 w
= XWINDOW (window
);
2339 XSETFASTINT (w
->hscroll
, 0);
2340 set_marker_restricted_both (w
->start
, buf
, 1, 1);
2341 set_marker_restricted_both (w
->pointm
, buf
, 1, 1);
2343 /* Run temp-buffer-show-hook, with the chosen window selected. */
2344 if (!NILP (Vrun_hooks
))
2347 tem
= Fboundp (Qtemp_buffer_show_hook
);
2350 tem
= Fsymbol_value (Qtemp_buffer_show_hook
);
2353 int count
= specpdl_ptr
- specpdl
;
2355 /* Select the window that was chosen, for running the hook. */
2356 record_unwind_protect (Fset_window_configuration
,
2357 Fcurrent_window_configuration (Qnil
));
2359 Fselect_window (window
);
2360 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
2361 unbind_to (count
, Qnil
);
2369 make_dummy_parent (window
)
2373 register struct window
*o
, *p
;
2374 register struct Lisp_Vector
*vec
;
2377 o
= XWINDOW (window
);
2378 vec
= allocate_vectorlike ((EMACS_INT
)VECSIZE (struct window
));
2379 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
2380 vec
->contents
[i
] = ((struct Lisp_Vector
*)o
)->contents
[i
];
2381 vec
->size
= VECSIZE (struct window
);
2382 p
= (struct window
*)vec
;
2383 XSETWINDOW (new, p
);
2385 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
2387 /* Put new into window structure in place of window */
2388 replace_window (window
, new);
2401 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
2402 "Split WINDOW, putting SIZE lines in the first of the pair.\n\
2403 WINDOW defaults to selected one and SIZE to half its size.\n\
2404 If optional third arg HORFLAG is non-nil, split side by side\n\
2405 and put SIZE columns in the first of the pair.")
2406 (window
, size
, horflag
)
2407 Lisp_Object window
, size
, horflag
;
2409 register Lisp_Object
new;
2410 register struct window
*o
, *p
;
2412 register int size_int
;
2415 window
= selected_window
;
2417 CHECK_LIVE_WINDOW (window
, 0);
2419 o
= XWINDOW (window
);
2420 fo
= XFRAME (WINDOW_FRAME (o
));
2424 if (!NILP (horflag
))
2425 /* Calculate the size of the left-hand window, by dividing
2426 the usable space in columns by two. */
2427 size_int
= XFASTINT (o
->width
) >> 1;
2429 size_int
= XFASTINT (o
->height
) >> 1;
2433 CHECK_NUMBER (size
, 1);
2434 size_int
= XINT (size
);
2437 if (MINI_WINDOW_P (o
))
2438 error ("Attempt to split minibuffer window");
2440 check_min_window_sizes ();
2444 if (size_int
< window_min_height
)
2445 error ("Window height %d too small (after splitting)", size_int
);
2446 if (size_int
+ window_min_height
> XFASTINT (o
->height
))
2447 error ("Window height %d too small (after splitting)",
2448 XFASTINT (o
->height
) - size_int
);
2449 if (NILP (o
->parent
)
2450 || NILP (XWINDOW (o
->parent
)->vchild
))
2452 make_dummy_parent (window
);
2454 XWINDOW (new)->vchild
= window
;
2459 if (size_int
< window_min_width
)
2460 error ("Window width %d too small (after splitting)", size_int
);
2462 if (size_int
+ window_min_width
> XFASTINT (o
->width
))
2463 error ("Window width %d too small (after splitting)",
2464 XFASTINT (o
->width
) - size_int
);
2465 if (NILP (o
->parent
)
2466 || NILP (XWINDOW (o
->parent
)->hchild
))
2468 make_dummy_parent (window
);
2470 XWINDOW (new)->hchild
= window
;
2474 /* Now we know that window's parent is a vertical combination
2475 if we are dividing vertically, or a horizontal combination
2476 if we are making side-by-side windows */
2478 windows_or_buffers_changed
++;
2479 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
2480 new = make_window ();
2483 p
->frame
= o
->frame
;
2485 if (!NILP (p
->next
))
2486 XWINDOW (p
->next
)->prev
= new;
2489 p
->parent
= o
->parent
;
2492 /* Apportion the available frame space among the two new windows */
2494 if (!NILP (horflag
))
2496 p
->height
= o
->height
;
2498 XSETFASTINT (p
->width
, XFASTINT (o
->width
) - size_int
);
2499 XSETFASTINT (o
->width
, size_int
);
2500 XSETFASTINT (p
->left
, XFASTINT (o
->left
) + size_int
);
2505 p
->width
= o
->width
;
2506 XSETFASTINT (p
->height
, XFASTINT (o
->height
) - size_int
);
2507 XSETFASTINT (o
->height
, size_int
);
2508 XSETFASTINT (p
->top
, XFASTINT (o
->top
) + size_int
);
2511 Fset_window_buffer (new, o
->buffer
);
2516 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
2517 "Make current window ARG lines bigger.\n\
2518 From program, optional second arg non-nil means grow sideways ARG columns.")
2520 register Lisp_Object arg
, side
;
2522 CHECK_NUMBER (arg
, 0);
2523 change_window_height (XINT (arg
), !NILP (side
));
2525 if (! NILP (Vwindow_configuration_change_hook
))
2526 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2531 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
2532 "Make current window ARG lines smaller.\n\
2533 From program, optional second arg non-nil means shrink sideways arg columns.")
2535 register Lisp_Object arg
, side
;
2537 CHECK_NUMBER (arg
, 0);
2538 change_window_height (-XINT (arg
), !NILP (side
));
2540 if (! NILP (Vwindow_configuration_change_hook
))
2541 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2547 window_height (window
)
2550 register struct window
*p
= XWINDOW (window
);
2551 return XFASTINT (p
->height
);
2555 window_width (window
)
2558 register struct window
*p
= XWINDOW (window
);
2559 return XFASTINT (p
->width
);
2562 #define MINSIZE(w) \
2564 ? window_min_width \
2565 : (MINI_WINDOW_P (XWINDOW (w)) ? 1 : window_min_height))
2568 *(widthflag ? (int *) &(XWINDOW (w)->left) : (int *) &(XWINDOW (w)->top))
2570 #define CURSIZE(w) \
2571 *(widthflag ? (int *) &(XWINDOW (w)->width) : (int *) &(XWINDOW (w)->height))
2573 /* Unlike set_window_height, this function
2574 also changes the heights of the siblings so as to
2575 keep everything consistent. */
2578 change_window_height (delta
, widthflag
)
2582 register Lisp_Object parent
;
2584 register struct window
*p
;
2586 int (*sizefun
) P_ ((Lisp_Object
))
2587 = widthflag
? window_width
: window_height
;
2588 register void (*setsizefun
) P_ ((Lisp_Object
, int, int))
2589 = (widthflag
? set_window_width
: set_window_height
);
2591 Lisp_Object next
, prev
;
2593 check_min_window_sizes ();
2595 window
= selected_window
;
2598 p
= XWINDOW (window
);
2603 error ("No other window to side of this one");
2606 if (widthflag
? !NILP (XWINDOW (parent
)->hchild
)
2607 : !NILP (XWINDOW (parent
)->vchild
))
2612 sizep
= &CURSIZE (window
);
2615 register int maxdelta
;
2617 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - *sizep
2618 : !NILP (p
->next
) ? (*sizefun
) (p
->next
) - MINSIZE (p
->next
)
2619 : !NILP (p
->prev
) ? (*sizefun
) (p
->prev
) - MINSIZE (p
->prev
)
2620 /* This is a frame with only one window, a minibuffer-only
2621 or a minibufferless frame. */
2624 if (delta
> maxdelta
)
2625 /* This case traps trying to make the minibuffer
2626 the full frame, or make the only window aside from the
2627 minibuffer the full frame. */
2631 if (*sizep
+ delta
< MINSIZE (window
))
2633 delete_window (window
);
2640 /* Find the total we can get from other siblings. */
2642 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
2643 maximum
+= (*sizefun
) (next
) - MINSIZE (next
);
2644 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
2645 maximum
+= (*sizefun
) (prev
) - MINSIZE (prev
);
2647 /* If we can get it all from them, do so. */
2648 if (delta
<= maximum
)
2650 Lisp_Object first_unaffected
;
2651 Lisp_Object first_affected
;
2655 first_affected
= window
;
2656 /* Look at one sibling at a time,
2657 moving away from this window in both directions alternately,
2658 and take as much as we can get without deleting that sibling. */
2665 int this_one
= (*sizefun
) (next
) - MINSIZE (next
);
2666 if (this_one
> delta
)
2669 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
2670 (*setsizefun
) (window
, *sizep
+ this_one
, 0);
2673 next
= XWINDOW (next
)->next
;
2679 int this_one
= (*sizefun
) (prev
) - MINSIZE (prev
);
2680 if (this_one
> delta
)
2683 first_affected
= prev
;
2685 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
2686 (*setsizefun
) (window
, *sizep
+ this_one
, 0);
2689 prev
= XWINDOW (prev
)->prev
;
2693 /* Now recalculate the edge positions of all the windows affected,
2694 based on the new sizes. */
2695 first_unaffected
= next
;
2696 prev
= first_affected
;
2697 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
2698 prev
= next
, next
= XWINDOW (next
)->next
)
2700 CURBEG (next
) = CURBEG (prev
) + (*sizefun
) (prev
);
2701 /* This does not change size of NEXT,
2702 but it propagates the new top edge to its children */
2703 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
2708 register int delta1
;
2709 register int opht
= (*sizefun
) (parent
);
2711 /* If trying to grow this window to or beyond size of the parent,
2712 make delta1 so big that, on shrinking back down,
2713 all the siblings end up with less than one line and are deleted. */
2714 if (opht
<= *sizep
+ delta
)
2715 delta1
= opht
* opht
* 2;
2716 /* Otherwise, make delta1 just right so that if we add delta1
2717 lines to this window and to the parent, and then shrink
2718 the parent back to its original size, the new proportional
2719 size of this window will increase by delta. */
2721 delta1
= (delta
* opht
* 100) / ((opht
- *sizep
- delta
) * 100);
2723 /* Add delta1 lines or columns to this window, and to the parent,
2724 keeping things consistent while not affecting siblings. */
2725 CURSIZE (parent
) = opht
+ delta1
;
2726 (*setsizefun
) (window
, *sizep
+ delta1
, 0);
2728 /* Squeeze out delta1 lines or columns from our parent,
2729 shriking this window and siblings proportionately.
2730 This brings parent back to correct size.
2731 Delta1 was calculated so this makes this window the desired size,
2732 taking it all out of the siblings. */
2733 (*setsizefun
) (parent
, opht
, 0);
2736 XSETFASTINT (p
->last_modified
, 0);
2737 XSETFASTINT (p
->last_overlay_modified
, 0);
2744 /* Return number of lines of text (not counting mode line) in W. */
2747 window_internal_height (w
)
2750 int ht
= XFASTINT (w
->height
);
2752 if (MINI_WINDOW_P (w
))
2755 if (!NILP (w
->parent
) || !NILP (w
->vchild
) || !NILP (w
->hchild
)
2756 || !NILP (w
->next
) || !NILP (w
->prev
)
2757 || FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (w
))))
2764 /* Return the number of columns in W.
2765 Don't count columns occupied by scroll bars or the vertical bar
2766 separating W from the sibling to its right. */
2768 window_internal_width (w
)
2771 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2772 int width
= XINT (w
->width
);
2774 /* Scroll bars occupy a few columns. */
2775 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2776 return width
- FRAME_SCROLL_BAR_COLS (f
);
2778 /* The column of `|' characters separating side-by-side windows
2779 occupies one column only. */
2780 if (!WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
2787 /* Scroll contents of window WINDOW up N lines.
2788 If WHOLE is nonzero, it means scroll N screenfuls instead. */
2791 window_scroll (window
, n
, whole
, noerror
)
2797 register struct window
*w
= XWINDOW (window
);
2798 register int opoint
= PT
;
2799 register int opoint_byte
= PT_BYTE
;
2800 register int pos
, pos_byte
;
2801 register int ht
= window_internal_height (w
);
2802 register Lisp_Object tem
;
2804 Lisp_Object bolp
, nmoved
;
2806 struct position posit
;
2809 startpos
= marker_position (w
->start
);
2811 posit
= *compute_motion (startpos
, 0, 0, 0,
2813 window_internal_width (w
), XINT (w
->hscroll
),
2815 original_vpos
= posit
.vpos
;
2817 XSETFASTINT (tem
, PT
);
2818 tem
= Fpos_visible_in_window_p (tem
, window
);
2822 Fvertical_motion (make_number (- (ht
/ 2)), window
);
2827 lose
= n
< 0 && PT
== BEGV
;
2828 Fvertical_motion (make_number (n
), window
);
2832 SET_PT_BOTH (opoint
, opoint_byte
);
2839 Fsignal (Qbeginning_of_buffer
, Qnil
);
2844 int this_scroll_margin
= scroll_margin
;
2846 /* Don't use a scroll margin that is negative or too large. */
2847 if (this_scroll_margin
< 0)
2848 this_scroll_margin
= 0;
2850 if (XINT (w
->height
) < 4 * scroll_margin
)
2851 this_scroll_margin
= XINT (w
->height
) / 4;
2853 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
2854 w
->start_at_line_beg
= bolp
;
2855 w
->update_mode_line
= Qt
;
2856 XSETFASTINT (w
->last_modified
, 0);
2857 XSETFASTINT (w
->last_overlay_modified
, 0);
2858 /* Set force_start so that redisplay_window will run
2859 the window-scroll-functions. */
2860 w
->force_start
= Qt
;
2862 if (whole
&& scroll_preserve_screen_position
)
2864 SET_PT_BOTH (pos
, pos_byte
);
2865 Fvertical_motion (make_number (original_vpos
), window
);
2867 /* If we scrolled forward, put point enough lines down
2868 that it is outside the scroll margin. */
2873 if (this_scroll_margin
> 0)
2875 SET_PT_BOTH (pos
, pos_byte
);
2876 Fvertical_motion (make_number (this_scroll_margin
), window
);
2882 if (top_margin
<= opoint
)
2883 SET_PT_BOTH (opoint
, opoint_byte
);
2884 else if (scroll_preserve_screen_position
)
2886 SET_PT_BOTH (pos
, pos_byte
);
2887 Fvertical_motion (make_number (original_vpos
), window
);
2890 SET_PT (top_margin
);
2896 /* If we scrolled backward, put point near the end of the window
2897 but not within the scroll margin. */
2898 SET_PT_BOTH (pos
, pos_byte
);
2899 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
2900 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
2903 bottom_margin
= PT
+ 1;
2905 if (bottom_margin
> opoint
)
2906 SET_PT_BOTH (opoint
, opoint_byte
);
2909 if (scroll_preserve_screen_position
)
2911 SET_PT_BOTH (pos
, pos_byte
);
2912 Fvertical_motion (make_number (original_vpos
), window
);
2915 Fvertical_motion (make_number (-1), window
);
2924 Fsignal (Qend_of_buffer
, Qnil
);
2928 /* This is the guts of Fscroll_up and Fscroll_down. */
2931 scroll_command (n
, direction
)
2932 register Lisp_Object n
;
2935 register int defalt
;
2936 int count
= specpdl_ptr
- specpdl
;
2938 /* If selected window's buffer isn't current, make it current for the moment.
2939 But don't screw up if window_scroll gets an error. */
2940 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
2942 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
2943 Fset_buffer (XWINDOW (selected_window
)->buffer
);
2946 defalt
= (window_internal_height (XWINDOW (selected_window
))
2947 - next_screen_context_lines
);
2948 defalt
= direction
* (defalt
< 1 ? 1 : defalt
);
2951 window_scroll (selected_window
, defalt
, 1, 0);
2952 else if (EQ (n
, Qminus
))
2953 window_scroll (selected_window
, - defalt
, 1, 0);
2956 n
= Fprefix_numeric_value (n
);
2957 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
2960 unbind_to (count
, Qnil
);
2963 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
2964 "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\
2965 A near full screen is `next-screen-context-lines' less than a full screen.\n\
2966 Negative ARG means scroll downward.\n\
2967 When calling from a program, supply a number as argument or nil.")
2971 scroll_command (arg
, 1);
2975 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
2976 "Scroll text of current window downward ARG lines; or near full screen if no ARG.\n\
2977 A near full screen is `next-screen-context-lines' less than a full screen.\n\
2978 Negative ARG means scroll upward.\n\
2979 When calling from a program, supply a number as argument or nil.")
2983 scroll_command (arg
, -1);
2987 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
2988 "Return the other window for \"other window scroll\" commands.\n\
2989 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
2990 specifies the window.\n\
2991 If `other-window-scroll-buffer' is non-nil, a window\n\
2992 showing that buffer is used.")
2997 if (MINI_WINDOW_P (XWINDOW (selected_window
))
2998 && !NILP (Vminibuf_scroll_window
))
2999 window
= Vminibuf_scroll_window
;
3000 /* If buffer is specified, scroll that buffer. */
3001 else if (!NILP (Vother_window_scroll_buffer
))
3003 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
3005 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
3009 /* Nothing specified; look for a neighboring window on the same
3011 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
3013 if (EQ (window
, selected_window
))
3014 /* That didn't get us anywhere; look for a window on another
3017 window
= Fnext_window (window
, Qnil
, Qt
);
3018 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
3019 && ! EQ (window
, selected_window
));
3022 CHECK_LIVE_WINDOW (window
, 0);
3024 if (EQ (window
, selected_window
))
3025 error ("There is no other window");
3030 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
3031 "Scroll next window upward ARG lines; or near full screen if no ARG.\n\
3032 The next window is the one below the current one; or the one at the top\n\
3033 if the current one is at the bottom. Negative ARG means scroll downward.\n\
3034 When calling from a program, supply a number as argument or nil.\n\
3036 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
3037 specifies the window to scroll.\n\
3038 If `other-window-scroll-buffer' is non-nil, scroll the window\n\
3039 showing that buffer, popping the buffer up if necessary.")
3041 register Lisp_Object arg
;
3043 register Lisp_Object window
;
3044 register int defalt
;
3045 register struct window
*w
;
3046 register int count
= specpdl_ptr
- specpdl
;
3048 window
= Fother_window_for_scrolling ();
3050 w
= XWINDOW (window
);
3051 defalt
= window_internal_height (w
) - next_screen_context_lines
;
3052 if (defalt
< 1) defalt
= 1;
3054 /* Don't screw up if window_scroll gets an error. */
3055 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
3057 Fset_buffer (w
->buffer
);
3058 SET_PT (marker_position (w
->pointm
));
3061 window_scroll (window
, defalt
, 1, 1);
3062 else if (EQ (arg
, Qminus
))
3063 window_scroll (window
, -defalt
, 1, 1);
3068 CHECK_NUMBER (arg
, 0);
3069 window_scroll (window
, XINT (arg
), 0, 1);
3072 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
3073 unbind_to (count
, Qnil
);
3078 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 1, "P",
3079 "Scroll selected window display ARG columns left.\n\
3080 Default for ARG is window width minus 2.")
3082 register Lisp_Object arg
;
3086 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
3088 arg
= Fprefix_numeric_value (arg
);
3091 Fset_window_hscroll (selected_window
,
3092 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
3096 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 1, "P",
3097 "Scroll selected window display ARG columns right.\n\
3098 Default for ARG is window width minus 2.")
3100 register Lisp_Object arg
;
3103 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
3105 arg
= Fprefix_numeric_value (arg
);
3108 Fset_window_hscroll (selected_window
,
3109 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
3113 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
3114 "Center point in window and redisplay frame. With ARG, put point on line ARG.\n\
3115 The desired position of point is always relative to the current window.\n\
3116 Just C-u as prefix means put point in the center of the window.\n\
3117 If ARG is omitted or nil, erases the entire frame and then\n\
3118 redraws with point in the center of the current window.")
3120 register Lisp_Object arg
;
3122 register struct window
*w
= XWINDOW (selected_window
);
3123 register int ht
= window_internal_height (w
);
3124 struct position pos
;
3125 struct buffer
*buf
= XBUFFER (w
->buffer
);
3126 struct buffer
*obuf
= current_buffer
;
3130 extern int frame_garbaged
;
3132 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
3133 XSETFASTINT (arg
, ht
/ 2);
3135 else if (CONSP (arg
)) /* Just C-u. */
3137 XSETFASTINT (arg
, ht
/ 2);
3141 arg
= Fprefix_numeric_value (arg
);
3142 CHECK_NUMBER (arg
, 0);
3146 XSETINT (arg
, XINT (arg
) + ht
);
3148 set_buffer_internal (buf
);
3149 pos
= *vmotion (PT
, - XINT (arg
), w
);
3151 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
3152 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
3153 || FETCH_BYTE (pos
.bytepos
- 1) == '\n')
3155 w
->force_start
= Qt
;
3156 set_buffer_internal (obuf
);
3161 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
3163 "Position point relative to window.\n\
3164 With no argument, position point at center of window.\n\
3165 An argument specifies frame line; zero means top of window,\n\
3166 negative means relative to bottom of window.")
3168 register Lisp_Object arg
;
3170 register struct window
*w
= XWINDOW (selected_window
);
3171 register int height
= window_internal_height (w
);
3176 XSETFASTINT (arg
, height
/ 2);
3179 arg
= Fprefix_numeric_value (arg
);
3181 XSETINT (arg
, XINT (arg
) + height
);
3184 start
= marker_position (w
->start
);
3185 XSETWINDOW (window
, w
);
3186 if (start
< BEGV
|| start
> ZV
)
3188 Fvertical_motion (make_number (- (height
/ 2)), window
);
3189 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
3190 w
->start_at_line_beg
= Fbolp ();
3191 w
->force_start
= Qt
;
3194 Fgoto_char (w
->start
);
3196 return Fvertical_motion (arg
, window
);
3199 struct save_window_data
3201 EMACS_INT size_from_Lisp_Vector_struct
;
3202 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
3203 Lisp_Object frame_width
, frame_height
, frame_menu_bar_lines
;
3204 Lisp_Object selected_frame
;
3205 Lisp_Object current_window
;
3206 Lisp_Object current_buffer
;
3207 Lisp_Object minibuf_scroll_window
;
3208 Lisp_Object root_window
;
3209 Lisp_Object focus_frame
;
3210 /* Record the values of window-min-width and window-min-height
3211 so that window sizes remain consistent with them. */
3212 Lisp_Object min_width
, min_height
;
3213 /* A vector, each of whose elements is a struct saved_window
3215 Lisp_Object saved_windows
;
3218 /* This is saved as a Lisp_Vector */
3221 /* these first two must agree with struct Lisp_Vector in lisp.h */
3222 EMACS_INT size_from_Lisp_Vector_struct
;
3223 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
3226 Lisp_Object buffer
, start
, pointm
, mark
;
3227 Lisp_Object left
, top
, width
, height
, hscroll
;
3228 Lisp_Object parent
, prev
;
3229 Lisp_Object start_at_line_beg
;
3230 Lisp_Object display_table
;
3232 #define SAVED_WINDOW_VECTOR_SIZE 14 /* Arg to Fmake_vector */
3234 #define SAVED_WINDOW_N(swv,n) \
3235 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
3237 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
3238 "Return t if OBJECT is a window-configuration object.")
3242 if (WINDOW_CONFIGURATIONP (object
))
3247 DEFUN ("set-window-configuration", Fset_window_configuration
,
3248 Sset_window_configuration
, 1, 1, 0,
3249 "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\
3250 CONFIGURATION must be a value previously returned\n\
3251 by `current-window-configuration' (which see).")
3253 Lisp_Object configuration
;
3255 register struct save_window_data
*data
;
3256 struct Lisp_Vector
*saved_windows
;
3257 Lisp_Object new_current_buffer
;
3262 while (!WINDOW_CONFIGURATIONP (configuration
))
3264 configuration
= wrong_type_argument (intern ("window-configuration-p"),
3268 data
= (struct save_window_data
*) XVECTOR (configuration
);
3269 saved_windows
= XVECTOR (data
->saved_windows
);
3271 new_current_buffer
= data
->current_buffer
;
3272 if (NILP (XBUFFER (new_current_buffer
)->name
))
3273 new_current_buffer
= Qnil
;
3276 if (XBUFFER (new_current_buffer
) == current_buffer
)
3281 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
3284 /* If f is a dead frame, don't bother rebuilding its window tree.
3285 However, there is other stuff we should still try to do below. */
3286 if (FRAME_LIVE_P (f
))
3288 register struct window
*w
;
3289 register struct saved_window
*p
;
3292 /* If the frame has been resized since this window configuration was
3293 made, we change the frame to the size specified in the
3294 configuration, restore the configuration, and then resize it
3295 back. We keep track of the prevailing height in these variables. */
3296 int previous_frame_height
= FRAME_HEIGHT (f
);
3297 int previous_frame_width
= FRAME_WIDTH (f
);
3298 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
3300 /* The mouse highlighting code could get screwed up
3301 if it runs during this. */
3304 if (XFASTINT (data
->frame_height
) != previous_frame_height
3305 || XFASTINT (data
->frame_width
) != previous_frame_width
)
3306 change_frame_size (f
, data
->frame_height
, data
->frame_width
, 0, 0);
3307 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
3308 if (XFASTINT (data
->frame_menu_bar_lines
)
3309 != previous_frame_menu_bar_lines
)
3310 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, 0);
3313 if (! NILP (XWINDOW (selected_window
)->buffer
))
3315 w
= XWINDOW (selected_window
);
3316 set_marker_both (w
->pointm
,
3318 BUF_PT (XBUFFER (w
->buffer
)),
3319 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
3322 windows_or_buffers_changed
++;
3323 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3325 /* Temporarily avoid any problems with windows that are smaller
3326 than they are supposed to be. */
3327 window_min_height
= 1;
3328 window_min_width
= 1;
3331 Mark all windows now on frame as "deleted".
3332 Restoring the new configuration "undeletes" any that are in it.
3334 Save their current buffers in their height fields, since we may
3335 need it later, if a buffer saved in the configuration is now
3337 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3339 for (k
= 0; k
< saved_windows
->size
; k
++)
3341 p
= SAVED_WINDOW_N (saved_windows
, k
);
3342 w
= XWINDOW (p
->window
);
3345 if (!NILP (p
->parent
))
3346 w
->parent
= SAVED_WINDOW_N (saved_windows
,
3347 XFASTINT (p
->parent
))->window
;
3351 if (!NILP (p
->prev
))
3353 w
->prev
= SAVED_WINDOW_N (saved_windows
,
3354 XFASTINT (p
->prev
))->window
;
3355 XWINDOW (w
->prev
)->next
= p
->window
;
3360 if (!NILP (w
->parent
))
3362 if (EQ (p
->width
, XWINDOW (w
->parent
)->width
))
3364 XWINDOW (w
->parent
)->vchild
= p
->window
;
3365 XWINDOW (w
->parent
)->hchild
= Qnil
;
3369 XWINDOW (w
->parent
)->hchild
= p
->window
;
3370 XWINDOW (w
->parent
)->vchild
= Qnil
;
3375 /* If we squirreled away the buffer in the window's height,
3377 if (BUFFERP (w
->height
))
3378 w
->buffer
= w
->height
;
3381 w
->width
= p
->width
;
3382 w
->height
= p
->height
;
3383 w
->hscroll
= p
->hscroll
;
3384 w
->display_table
= p
->display_table
;
3385 XSETFASTINT (w
->last_modified
, 0);
3386 XSETFASTINT (w
->last_overlay_modified
, 0);
3388 /* Reinstall the saved buffer and pointers into it. */
3389 if (NILP (p
->buffer
))
3390 w
->buffer
= p
->buffer
;
3393 if (!NILP (XBUFFER (p
->buffer
)->name
))
3394 /* If saved buffer is alive, install it. */
3396 w
->buffer
= p
->buffer
;
3397 w
->start_at_line_beg
= p
->start_at_line_beg
;
3398 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
3399 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
3400 Fset_marker (XBUFFER (w
->buffer
)->mark
,
3401 p
->mark
, w
->buffer
);
3403 /* As documented in Fcurrent_window_configuration, don't
3404 save the location of point in the buffer which was current
3405 when the window configuration was recorded. */
3406 if (!EQ (p
->buffer
, new_current_buffer
)
3407 && XBUFFER (p
->buffer
) == current_buffer
)
3408 Fgoto_char (w
->pointm
);
3410 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
3411 /* Else unless window has a live buffer, get one. */
3413 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
3414 /* This will set the markers to beginning of visible
3416 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
3417 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
3418 w
->start_at_line_beg
= Qt
;
3421 /* Keeping window's old buffer; make sure the markers
3424 /* Set window markers at start of visible range. */
3425 if (XMARKER (w
->start
)->buffer
== 0)
3426 set_marker_restricted (w
->start
, make_number (0),
3428 if (XMARKER (w
->pointm
)->buffer
== 0)
3429 set_marker_restricted_both (w
->pointm
, w
->buffer
,
3430 BUF_PT (XBUFFER (w
->buffer
)),
3431 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
3432 w
->start_at_line_beg
= Qt
;
3437 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
3438 Fselect_window (data
->current_window
);
3439 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
3442 if (NILP (data
->focus_frame
)
3443 || (FRAMEP (data
->focus_frame
)
3444 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
3445 Fredirect_frame_focus (frame
, data
->focus_frame
);
3447 #if 0 /* I don't understand why this is needed, and it causes problems
3448 when the frame's old selected window has been deleted. */
3449 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
3450 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
3454 /* Set the screen height to the value it had before this function. */
3455 if (previous_frame_height
!= FRAME_HEIGHT (f
)
3456 || previous_frame_width
!= FRAME_WIDTH (f
))
3457 change_frame_size (f
, previous_frame_height
, previous_frame_width
,
3459 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
3460 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
3461 x_set_menu_bar_lines (f
, previous_frame_menu_bar_lines
, 0);
3466 /* Fselect_window will have made f the selected frame, so we
3467 reselect the proper frame here. Fhandle_switch_frame will change the
3468 selected window too, but that doesn't make the call to
3469 Fselect_window above totally superfluous; it still sets f's
3471 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
3472 do_switch_frame (data
->selected_frame
, Qnil
, 0);
3474 if (! NILP (Vwindow_configuration_change_hook
)
3475 && ! NILP (Vrun_hooks
))
3476 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3479 if (!NILP (new_current_buffer
))
3481 Fset_buffer (new_current_buffer
);
3483 /* If the buffer that is current now is the same
3484 that was current before setting the window configuration,
3485 don't alter its PT. */
3490 /* Restore the minimum heights recorded in the configuration. */
3491 window_min_height
= XINT (data
->min_height
);
3492 window_min_width
= XINT (data
->min_width
);
3494 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
3499 /* Mark all windows now on frame as deleted
3500 by setting their buffers to nil. */
3503 delete_all_subwindows (w
)
3504 register struct window
*w
;
3506 if (!NILP (w
->next
))
3507 delete_all_subwindows (XWINDOW (w
->next
));
3508 if (!NILP (w
->vchild
))
3509 delete_all_subwindows (XWINDOW (w
->vchild
));
3510 if (!NILP (w
->hchild
))
3511 delete_all_subwindows (XWINDOW (w
->hchild
));
3513 w
->height
= w
->buffer
; /* See Fset_window_configuration for excuse. */
3515 if (!NILP (w
->buffer
))
3518 /* We set all three of these fields to nil, to make sure that we can
3519 distinguish this dead window from any live window. Live leaf
3520 windows will have buffer set, and combination windows will have
3521 vchild or hchild set. */
3528 count_windows (window
)
3529 register struct window
*window
;
3531 register int count
= 1;
3532 if (!NILP (window
->next
))
3533 count
+= count_windows (XWINDOW (window
->next
));
3534 if (!NILP (window
->vchild
))
3535 count
+= count_windows (XWINDOW (window
->vchild
));
3536 if (!NILP (window
->hchild
))
3537 count
+= count_windows (XWINDOW (window
->hchild
));
3542 save_window_save (window
, vector
, i
)
3544 struct Lisp_Vector
*vector
;
3547 register struct saved_window
*p
;
3548 register struct window
*w
;
3549 register Lisp_Object tem
;
3551 for (;!NILP (window
); window
= w
->next
)
3553 p
= SAVED_WINDOW_N (vector
, i
);
3554 w
= XWINDOW (window
);
3556 XSETFASTINT (w
->temslot
, i
++);
3558 p
->buffer
= w
->buffer
;
3561 p
->width
= w
->width
;
3562 p
->height
= w
->height
;
3563 p
->hscroll
= w
->hscroll
;
3564 p
->display_table
= w
->display_table
;
3565 if (!NILP (w
->buffer
))
3567 /* Save w's value of point in the window configuration.
3568 If w is the selected window, then get the value of point
3569 from the buffer; pointm is garbage in the selected window. */
3570 if (EQ (window
, selected_window
))
3572 p
->pointm
= Fmake_marker ();
3573 set_marker_both (p
->pointm
, w
->buffer
,
3574 BUF_PT (XBUFFER (w
->buffer
)),
3575 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
3578 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
3580 p
->start
= Fcopy_marker (w
->start
, Qnil
);
3581 p
->start_at_line_beg
= w
->start_at_line_beg
;
3583 tem
= XBUFFER (w
->buffer
)->mark
;
3584 p
->mark
= Fcopy_marker (tem
, Qnil
);
3591 p
->start_at_line_beg
= Qnil
;
3594 if (NILP (w
->parent
))
3597 p
->parent
= XWINDOW (w
->parent
)->temslot
;
3602 p
->prev
= XWINDOW (w
->prev
)->temslot
;
3604 if (!NILP (w
->vchild
))
3605 i
= save_window_save (w
->vchild
, vector
, i
);
3606 if (!NILP (w
->hchild
))
3607 i
= save_window_save (w
->hchild
, vector
, i
);
3613 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
3614 Scurrent_window_configuration
, 0, 1, 0,
3615 "Return an object representing the current window configuration of FRAME.\n\
3616 If FRAME is nil or omitted, use the selected frame.\n\
3617 This describes the number of windows, their sizes and current buffers,\n\
3618 and for each displayed buffer, where display starts, and the positions of\n\
3619 point and mark. An exception is made for point in the current buffer:\n\
3620 its value is -not- saved.\n\
3621 This also records the currently selected frame, and FRAME's focus\n\
3622 redirection (see `redirect-frame-focus').")
3626 register Lisp_Object tem
;
3627 register int n_windows
;
3628 register struct save_window_data
*data
;
3629 register struct Lisp_Vector
*vec
;
3637 CHECK_LIVE_FRAME (frame
, 0);
3641 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3642 vec
= allocate_vectorlike (VECSIZE (struct save_window_data
));
3643 for (i
= 0; i
< VECSIZE (struct save_window_data
); i
++)
3644 vec
->contents
[i
] = Qnil
;
3645 vec
->size
= VECSIZE (struct save_window_data
);
3646 data
= (struct save_window_data
*)vec
;
3648 XSETFASTINT (data
->frame_width
, FRAME_WIDTH (f
));
3649 XSETFASTINT (data
->frame_height
, FRAME_HEIGHT (f
));
3650 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
3651 XSETFRAME (data
->selected_frame
, selected_frame
);
3652 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
3653 XSETBUFFER (data
->current_buffer
, current_buffer
);
3654 data
->minibuf_scroll_window
= Vminibuf_scroll_window
;
3655 data
->root_window
= FRAME_ROOT_WINDOW (f
);
3656 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
3657 XSETINT (data
->min_height
, window_min_height
);
3658 XSETINT (data
->min_width
, window_min_width
);
3659 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
3660 data
->saved_windows
= tem
;
3661 for (i
= 0; i
< n_windows
; i
++)
3662 XVECTOR (tem
)->contents
[i
]
3663 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
3664 save_window_save (FRAME_ROOT_WINDOW (f
),
3666 XSETWINDOW_CONFIGURATION (tem
, data
);
3670 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
3672 "Execute body, preserving window sizes and contents.\n\
3673 Restore which buffer appears in which window, where display starts,\n\
3674 and the value of point and mark for each window.\n\
3675 Also restore which buffer is current.\n\
3676 But do not preserve point in the current buffer.\n\
3677 Does not restore the value of point in current buffer.")
3681 register Lisp_Object val
;
3682 register int count
= specpdl_ptr
- specpdl
;
3684 record_unwind_protect (Fset_window_configuration
,
3685 Fcurrent_window_configuration (Qnil
));
3686 val
= Fprogn (args
);
3687 return unbind_to (count
, val
);
3690 /* Return 1 if window configurations C1 and C2
3691 describe the same state of affairs. This is used by Fequal. */
3694 compare_window_configurations (c1
, c2
, ignore_positions
)
3696 int ignore_positions
;
3698 register struct save_window_data
*d1
, *d2
;
3699 struct Lisp_Vector
*sw1
, *sw2
;
3702 d1
= (struct save_window_data
*) XVECTOR (c1
);
3703 d2
= (struct save_window_data
*) XVECTOR (c2
);
3704 sw1
= XVECTOR (d1
->saved_windows
);
3705 sw2
= XVECTOR (d2
->saved_windows
);
3707 if (! EQ (d1
->frame_width
, d2
->frame_width
))
3709 if (! EQ (d1
->frame_height
, d2
->frame_height
))
3711 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
3713 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
3715 /* Don't compare the current_window field directly.
3716 Instead see w1_is_current and w2_is_current, below. */
3717 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
3719 if (! ignore_positions
)
3720 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
3722 /* Don't compare the root_window field.
3723 We don't require the two configurations
3724 to use the same window object,
3725 and the two root windows must be equivalent
3726 if everything else compares equal. */
3727 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
3729 if (! EQ (d1
->min_width
, d2
->min_width
))
3731 if (! EQ (d1
->min_height
, d2
->min_height
))
3734 /* Verify that the two confis have the same number of windows. */
3735 if (sw1
->size
!= sw2
->size
)
3738 for (i
= 0; i
< sw1
->size
; i
++)
3740 struct saved_window
*p1
, *p2
;
3741 int w1_is_current
, w2_is_current
;
3743 p1
= SAVED_WINDOW_N (sw1
, i
);
3744 p2
= SAVED_WINDOW_N (sw2
, i
);
3746 /* Verify that the current windows in the two
3747 configurations correspond to each other. */
3748 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
3749 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
3751 if (w1_is_current
!= w2_is_current
)
3754 /* Verify that the corresponding windows do match. */
3755 if (! EQ (p1
->buffer
, p2
->buffer
))
3757 if (! EQ (p1
->left
, p2
->left
))
3759 if (! EQ (p1
->top
, p2
->top
))
3761 if (! EQ (p1
->width
, p2
->width
))
3763 if (! EQ (p1
->height
, p2
->height
))
3765 if (! EQ (p1
->display_table
, p2
->display_table
))
3767 if (! EQ (p1
->parent
, p2
->parent
))
3769 if (! EQ (p1
->prev
, p2
->prev
))
3771 if (! ignore_positions
)
3773 if (! EQ (p1
->hscroll
, p2
->hscroll
))
3775 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
3777 if (NILP (Fequal (p1
->start
, p2
->start
)))
3779 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
3781 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
3789 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
3790 Scompare_window_configurations
, 2, 2, 0,
3791 "Compare two window configurations as regards the structure of windows.\n\
3792 This function ignores details such as the values of point and mark\n\
3793 and scrolling positions.")
3797 if (compare_window_configurations (x
, y
, 1))
3804 selected_frame
= make_terminal_frame ();
3805 XSETFRAME (Vterminal_frame
, selected_frame
);
3806 minibuf_window
= selected_frame
->minibuffer_window
;
3807 selected_window
= selected_frame
->selected_window
;
3808 last_nonminibuf_frame
= selected_frame
;
3810 window_initialized
= 1;
3815 staticpro (&Qwindow_configuration_change_hook
);
3816 Qwindow_configuration_change_hook
3817 = intern ("window-configuration-change-hook");
3819 Qwindowp
= intern ("windowp");
3820 staticpro (&Qwindowp
);
3822 Qwindow_live_p
= intern ("window-live-p");
3823 staticpro (&Qwindow_live_p
);
3825 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
3826 staticpro (&Qtemp_buffer_show_hook
);
3828 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
3829 "Non-nil means call as function to display a help buffer.\n\
3830 The function is called with one argument, the buffer to be displayed.\n\
3831 Used by `with-output-to-temp-buffer'.\n\
3832 If this function is used, then it must do the entire job of showing\n\
3833 the buffer; `temp-buffer-show-hook' is not run unless this function runs it.");
3834 Vtemp_buffer_show_function
= Qnil
;
3836 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
3837 "If non-nil, function to call to handle `display-buffer'.\n\
3838 It will receive two args, the buffer and a flag which if non-nil means\n\
3839 that the currently selected window is not acceptable.\n\
3840 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\
3841 work using this function.");
3842 Vdisplay_buffer_function
= Qnil
;
3844 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
3845 "Non-nil means it is the window that C-M-v in minibuffer should scroll.");
3846 Vminibuf_scroll_window
= Qnil
;
3848 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
3849 "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.");
3850 Vother_window_scroll_buffer
= Qnil
;
3852 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
3853 "*Non-nil means `display-buffer' should make a separate frame.");
3856 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
3857 "Function to call to handle automatic new frame creation.\n\
3858 It is called with no arguments and should return a newly created frame.\n\
3860 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\
3861 where `pop-up-frame-alist' would hold the default frame parameters.");
3862 Vpop_up_frame_function
= Qnil
;
3864 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
3865 "*List of buffer names that should have their own special frames.\n\
3866 Displaying a buffer whose name is in this list makes a special frame for it\n\
3867 using `special-display-function'. See also `special-display-regexps'.\n\
3869 An element of the list can be a list instead of just a string.\n\
3870 There are two ways to use a list as an element:\n\
3871 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)\n\
3872 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
3873 In the latter case, FUNCTION is called with BUFFER as the first argument,\n\
3874 followed by OTHER-ARGS--it can display BUFFER in any way it likes.\n\
3875 All this is done by the function found in `special-display-function'.\n\
3877 If this variable appears \"not to work\", because you add a name to it\n\
3878 but that buffer still appears in the selected window, look at the\n\
3879 values of `same-window-buffer-names' and `same-window-regexps'.\n\
3880 Those variables take precedence over this one.");
3881 Vspecial_display_buffer_names
= Qnil
;
3883 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
3884 "*List of regexps saying which buffers should have their own special frames.\n\
3885 If a buffer name matches one of these regexps, it gets its own frame.\n\
3886 Displaying a buffer whose name is in this list makes a special frame for it\n\
3887 using `special-display-function'.\n\
3889 An element of the list can be a list instead of just a string.\n\
3890 There are two ways to use a list as an element:\n\
3891 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)\n\
3892 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
3893 In the latter case, FUNCTION is called with the buffer as first argument,\n\
3894 followed by OTHER-ARGS--it can display the buffer in any way it likes.\n\
3895 All this is done by the function found in `special-display-function'.\n\
3897 If this variable appears \"not to work\", because you add a regexp to it\n\
3898 but the matching buffers still appear in the selected window, look at the\n\
3899 values of `same-window-buffer-names' and `same-window-regexps'.\n\
3900 Those variables take precedence over this one.");
3901 Vspecial_display_regexps
= Qnil
;
3903 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
3904 "Function to call to make a new frame for a special buffer.\n\
3905 It is called with two arguments, the buffer and optional buffer specific\n\
3906 data, and should return a window displaying that buffer.\n\
3907 The default value makes a separate frame for the buffer,\n\
3908 using `special-display-frame-alist' to specify the frame parameters.\n\
3910 A buffer is special if its is listed in `special-display-buffer-names'\n\
3911 or matches a regexp in `special-display-regexps'.");
3912 Vspecial_display_function
= Qnil
;
3914 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
3915 "*List of buffer names that should appear in the selected window.\n\
3916 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'\n\
3917 switches to it in the selected window, rather than making it appear\n\
3918 in some other window.\n\
3920 An element of the list can be a cons cell instead of just a string.\n\
3921 Then the car must be a string, which specifies the buffer name.\n\
3922 This is for compatibility with `special-display-buffer-names';\n\
3923 the cdr of the cons cell is ignored.\n\
3925 See also `same-window-regexps'.");
3926 Vsame_window_buffer_names
= Qnil
;
3928 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
3929 "*List of regexps saying which buffers should appear in the selected window.\n\
3930 If a buffer name matches one of these regexps, then displaying it\n\
3931 using `display-buffer' or `pop-to-buffer' switches to it\n\
3932 in the selected window, rather than making it appear in some other window.\n\
3934 An element of the list can be a cons cell instead of just a string.\n\
3935 Then the car must be a string, which specifies the buffer name.\n\
3936 This is for compatibility with `special-display-buffer-names';\n\
3937 the cdr of the cons cell is ignored.\n\
3939 See also `same-window-buffer-names'.");
3940 Vsame_window_regexps
= Qnil
;
3942 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
3943 "*Non-nil means display-buffer should make new windows.");
3946 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
3947 "*Number of lines of continuity when scrolling by screenfuls.");
3948 next_screen_context_lines
= 2;
3950 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
3951 "*display-buffer would prefer to split the largest window if this large.\n\
3952 If there is only one window, it is split regardless of this value.");
3953 split_height_threshold
= 500;
3955 DEFVAR_INT ("window-min-height", &window_min_height
,
3956 "*Delete any window less than this tall (including its mode line).");
3957 window_min_height
= 4;
3959 DEFVAR_INT ("window-min-width", &window_min_width
,
3960 "*Delete any window less than this wide.");
3961 window_min_width
= 10;
3963 DEFVAR_BOOL ("scroll-preserve-screen-position",
3964 &scroll_preserve_screen_position
,
3965 "*Nonzero means scroll commands move point to keep its screen line unchanged.");
3966 scroll_preserve_screen_position
= 0;
3968 DEFVAR_LISP ("window-configuration-change-hook",
3969 &Vwindow_configuration_change_hook
,
3970 "Functions to call when window configuration changes.\n\
3971 The selected frame is the one whose configuration has changed.");
3972 Vwindow_configuration_change_hook
= Qnil
;
3974 defsubr (&Sselected_window
);
3975 defsubr (&Sminibuffer_window
);
3976 defsubr (&Swindow_minibuffer_p
);
3977 defsubr (&Swindowp
);
3978 defsubr (&Swindow_live_p
);
3979 defsubr (&Spos_visible_in_window_p
);
3980 defsubr (&Swindow_buffer
);
3981 defsubr (&Swindow_height
);
3982 defsubr (&Swindow_width
);
3983 defsubr (&Swindow_hscroll
);
3984 defsubr (&Sset_window_hscroll
);
3985 defsubr (&Swindow_redisplay_end_trigger
);
3986 defsubr (&Sset_window_redisplay_end_trigger
);
3987 defsubr (&Swindow_edges
);
3988 defsubr (&Scoordinates_in_window_p
);
3989 defsubr (&Swindow_at
);
3990 defsubr (&Swindow_point
);
3991 defsubr (&Swindow_start
);
3992 defsubr (&Swindow_end
);
3993 defsubr (&Sset_window_point
);
3994 defsubr (&Sset_window_start
);
3995 defsubr (&Swindow_dedicated_p
);
3996 defsubr (&Sset_window_dedicated_p
);
3997 defsubr (&Swindow_display_table
);
3998 defsubr (&Sset_window_display_table
);
3999 defsubr (&Snext_window
);
4000 defsubr (&Sprevious_window
);
4001 defsubr (&Sother_window
);
4002 defsubr (&Sget_lru_window
);
4003 defsubr (&Sget_largest_window
);
4004 defsubr (&Sget_buffer_window
);
4005 defsubr (&Sdelete_other_windows
);
4006 defsubr (&Sdelete_windows_on
);
4007 defsubr (&Sreplace_buffer_in_windows
);
4008 defsubr (&Sdelete_window
);
4009 defsubr (&Sset_window_buffer
);
4010 defsubr (&Sselect_window
);
4011 defsubr (&Sspecial_display_p
);
4012 defsubr (&Ssame_window_p
);
4013 defsubr (&Sdisplay_buffer
);
4014 defsubr (&Ssplit_window
);
4015 defsubr (&Senlarge_window
);
4016 defsubr (&Sshrink_window
);
4017 defsubr (&Sscroll_up
);
4018 defsubr (&Sscroll_down
);
4019 defsubr (&Sscroll_left
);
4020 defsubr (&Sscroll_right
);
4021 defsubr (&Sother_window_for_scrolling
);
4022 defsubr (&Sscroll_other_window
);
4023 defsubr (&Srecenter
);
4024 defsubr (&Smove_to_window_line
);
4025 defsubr (&Swindow_configuration_p
);
4026 defsubr (&Sset_window_configuration
);
4027 defsubr (&Scurrent_window_configuration
);
4028 defsubr (&Ssave_window_excursion
);
4029 defsubr (&Scompare_window_configurations
);
4034 initial_define_key (control_x_map
, '1', "delete-other-windows");
4035 initial_define_key (control_x_map
, '2', "split-window");
4036 initial_define_key (control_x_map
, '0', "delete-window");
4037 initial_define_key (control_x_map
, 'o', "other-window");
4038 initial_define_key (control_x_map
, '^', "enlarge-window");
4039 initial_define_key (control_x_map
, '<', "scroll-left");
4040 initial_define_key (control_x_map
, '>', "scroll-right");
4042 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
4043 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
4044 initial_define_key (meta_map
, 'v', "scroll-down");
4046 initial_define_key (global_map
, Ctl('L'), "recenter");
4047 initial_define_key (meta_map
, 'r', "move-to-window-line");