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, 1, 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.")
573 struct window
*w
= decode_window (window
);
577 CHECK_BUFFER (buf
, 0);
579 #if 0 /* This change broke some things. We should make it later. */
580 /* If we don't know the end position, return nil.
581 The user can compute it with vertical-motion if he wants to.
582 It would be nicer to do it automatically,
583 but that's so slow that it would probably bother people. */
584 if (NILP (w
->window_end_valid
))
589 BUF_Z (XBUFFER (buf
)) - XFASTINT (w
->window_end_pos
));
594 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
595 "Make point value in WINDOW be at position POS in WINDOW's buffer.")
597 Lisp_Object window
, pos
;
599 register struct window
*w
= decode_window (window
);
601 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
602 if (w
== XWINDOW (selected_window
))
605 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
610 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
611 "Make display in WINDOW start at position POS in WINDOW's buffer.\n\
612 Optional third arg NOFORCE non-nil inhibits next redisplay\n\
613 from overriding motion of point in order to display at this exact start.")
614 (window
, pos
, noforce
)
615 Lisp_Object window
, pos
, noforce
;
617 register struct window
*w
= decode_window (window
);
619 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
620 set_marker_restricted (w
->start
, pos
, w
->buffer
);
621 /* this is not right, but much easier than doing what is right. */
622 w
->start_at_line_beg
= Qnil
;
625 w
->update_mode_line
= Qt
;
626 XSETFASTINT (w
->last_modified
, 0);
627 XSETFASTINT (w
->last_overlay_modified
, 0);
628 if (!EQ (window
, selected_window
))
629 windows_or_buffers_changed
++;
633 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
635 "Return WINDOW's dedicated object, usually t or nil.\n\
636 See also `set-window-dedicated-p'.")
640 return decode_window (window
)->dedicated
;
643 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
644 Sset_window_dedicated_p
, 2, 2, 0,
645 "Control whether WINDOW is dedicated to the buffer it displays.\n\
646 If it is dedicated, Emacs will not automatically change\n\
647 which buffer appears in it.\n\
648 The second argument is the new value for the dedication flag;\n\
651 Lisp_Object window
, arg
;
653 register struct window
*w
= decode_window (window
);
663 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
665 "Return the display-table that WINDOW is using.")
669 return decode_window (window
)->display_table
;
672 /* Get the display table for use currently on window W.
673 This is either W's display table or W's buffer's display table.
674 Ignore the specified tables if they are not valid;
675 if no valid table is specified, return 0. */
677 struct Lisp_Char_Table
*
678 window_display_table (w
)
682 tem
= w
->display_table
;
683 if (DISP_TABLE_P (tem
))
684 return XCHAR_TABLE (tem
);
685 tem
= XBUFFER (w
->buffer
)->display_table
;
686 if (DISP_TABLE_P (tem
))
687 return XCHAR_TABLE (tem
);
688 tem
= Vstandard_display_table
;
689 if (DISP_TABLE_P (tem
))
690 return XCHAR_TABLE (tem
);
694 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
695 "Set WINDOW's display-table to TABLE.")
697 register Lisp_Object window
, table
;
699 register struct window
*w
;
700 register Lisp_Object z
; /* Return value. */
702 w
= decode_window (window
);
703 w
->display_table
= table
;
707 /* Record info on buffer window w is displaying
708 when it is about to cease to display that buffer. */
711 register struct window
*w
;
718 if (b
!= XMARKER (w
->pointm
)->buffer
)
721 if (w
== XWINDOW (b
->last_selected_window
))
722 b
->last_selected_window
= Qnil
;
725 if (w
== XWINDOW (selected_window
)
726 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
727 /* Do this except when the selected window's buffer
728 is being removed from some other window. */
730 /* last_window_start records the start position that this buffer
731 had in the last window to be disconnected from it.
732 Now that this statement is unconditional,
733 it is possible for the buffer to be displayed in the
734 selected window, while last_window_start reflects another
735 window which was recently showing the same buffer.
736 Some people might say that might be a good thing. Let's see. */
737 b
->last_window_start
= marker_position (w
->start
);
739 /* Point in the selected window's buffer
740 is actually stored in that buffer, and the window's pointm isn't used.
741 So don't clobber point in that buffer. */
742 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
))
743 temp_set_point_both (b
,
744 clip_to_bounds (BUF_BEGV (b
),
745 XMARKER (w
->pointm
)->charpos
,
747 clip_to_bounds (BUF_BEGV_BYTE (b
),
748 marker_byte_position (w
->pointm
),
752 /* Put replacement into the window structure in place of old. */
754 replace_window (old
, replacement
)
755 Lisp_Object old
, replacement
;
757 register Lisp_Object tem
;
758 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
760 /* If OLD is its frame's root_window, then replacement is the new
761 root_window for that frame. */
763 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
764 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
769 p
->height
= o
->height
;
771 p
->next
= tem
= o
->next
;
773 XWINDOW (tem
)->prev
= replacement
;
775 p
->prev
= tem
= o
->prev
;
777 XWINDOW (tem
)->next
= replacement
;
779 p
->parent
= tem
= o
->parent
;
782 if (EQ (XWINDOW (tem
)->vchild
, old
))
783 XWINDOW (tem
)->vchild
= replacement
;
784 if (EQ (XWINDOW (tem
)->hchild
, old
))
785 XWINDOW (tem
)->hchild
= replacement
;
788 /*** Here, if replacement is a vertical combination
789 and so is its new parent, we should make replacement's
790 children be children of that parent instead. ***/
793 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
794 "Remove WINDOW from the display. Default is selected window.")
796 register Lisp_Object window
;
798 delete_window (window
);
800 if (! NILP (Vwindow_configuration_change_hook
)
801 && ! NILP (Vrun_hooks
))
802 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
808 delete_window (window
)
809 register Lisp_Object window
;
811 register Lisp_Object tem
, parent
, sib
;
812 register struct window
*p
;
813 register struct window
*par
;
815 /* Because this function is called by other C code on non-leaf
816 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
817 so we can't decode_window here. */
819 window
= selected_window
;
821 CHECK_WINDOW (window
, 0);
822 p
= XWINDOW (window
);
824 /* It's okay to delete an already-deleted window. */
832 error ("Attempt to delete minibuffer or sole ordinary window");
833 par
= XWINDOW (parent
);
835 windows_or_buffers_changed
++;
836 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (p
))) = 1;
838 /* Are we trying to delete any frame's selected window? */
840 Lisp_Object frame
, pwindow
;
842 /* See if the frame's selected window is either WINDOW
843 or any subwindow of it, by finding all that window's parents
844 and comparing each one with WINDOW. */
845 frame
= WINDOW_FRAME (XWINDOW (window
));
846 pwindow
= FRAME_SELECTED_WINDOW (XFRAME (frame
));
848 while (!NILP (pwindow
))
850 if (EQ (window
, pwindow
))
852 pwindow
= XWINDOW (pwindow
)->parent
;
855 if (EQ (window
, pwindow
))
857 Lisp_Object alternative
;
858 alternative
= Fnext_window (window
, Qlambda
, Qnil
);
860 /* If we're about to delete the selected window on the
861 selected frame, then we should use Fselect_window to select
862 the new window. On the other hand, if we're about to
863 delete the selected window on any other frame, we shouldn't do
864 anything but set the frame's selected_window slot. */
865 if (EQ (window
, selected_window
))
866 Fselect_window (alternative
);
868 FRAME_SELECTED_WINDOW (XFRAME (frame
)) = alternative
;
873 /* tem is null for dummy parent windows
874 (which have inferiors but not any contents themselves) */
878 unchain_marker (p
->pointm
);
879 unchain_marker (p
->start
);
884 XWINDOW (tem
)->prev
= p
->prev
;
888 XWINDOW (tem
)->next
= p
->next
;
890 if (EQ (window
, par
->hchild
))
891 par
->hchild
= p
->next
;
892 if (EQ (window
, par
->vchild
))
893 par
->vchild
= p
->next
;
895 /* Find one of our siblings to give our space to. */
899 /* If p gives its space to its next sibling, that sibling needs
900 to have its top/left side pulled back to where p's is.
901 set_window_{height,width} will re-position the sibling's
904 XWINDOW (sib
)->top
= p
->top
;
905 XWINDOW (sib
)->left
= p
->left
;
908 /* Stretch that sibling. */
909 if (!NILP (par
->vchild
))
910 set_window_height (sib
,
911 XFASTINT (XWINDOW (sib
)->height
) + XFASTINT (p
->height
),
913 if (!NILP (par
->hchild
))
914 set_window_width (sib
,
915 XFASTINT (XWINDOW (sib
)->width
) + XFASTINT (p
->width
),
918 /* If parent now has only one child,
919 put the child into the parent's place. */
923 if (NILP (XWINDOW (tem
)->next
))
924 replace_window (parent
, tem
);
926 /* Since we may be deleting combination windows, we must make sure that
927 not only p but all its children have been marked as deleted. */
928 if (! NILP (p
->hchild
))
929 delete_all_subwindows (XWINDOW (p
->hchild
));
930 else if (! NILP (p
->vchild
))
931 delete_all_subwindows (XWINDOW (p
->vchild
));
933 /* Mark this window as deleted. */
934 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
938 extern Lisp_Object
next_frame (), prev_frame ();
940 /* This comment supplies the doc string for `next-window',
941 for make-docfile to see. We cannot put this in the real DEFUN
942 due to limits in the Unix cpp.
944 DEFUN ("next-window", Ffoo, Sfoo, 0, 3, 0,
945 "Return next window after WINDOW in canonical ordering of windows.\n\
946 If omitted, WINDOW defaults to the selected window.\n\
948 Optional second arg MINIBUF t means count the minibuffer window even\n\
949 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
950 it is active. MINIBUF neither t nor nil means not to count the\n\
951 minibuffer even if it is active.\n\
953 Several frames may share a single minibuffer; if the minibuffer\n\
954 counts, all windows on all frames that share that minibuffer count\n\
955 too. Therefore, `next-window' can be used to iterate through the\n\
956 set of windows even when the minibuffer is on another frame. If the\n\
957 minibuffer does not count, only windows from WINDOW's frame count.\n\
959 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
960 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
961 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
962 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
963 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
964 Anything else means restrict to WINDOW's frame.\n\
966 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
967 `next-window' to iterate through the entire cycle of acceptable\n\
968 windows, eventually ending up back at the window you started with.\n\
969 `previous-window' traverses the same cycle, in the reverse order.")
970 (window, minibuf, all_frames) */
972 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
974 (window
, minibuf
, all_frames
)
975 register Lisp_Object window
, minibuf
, all_frames
;
977 register Lisp_Object tem
;
978 Lisp_Object start_window
;
981 window
= selected_window
;
983 CHECK_LIVE_WINDOW (window
, 0);
985 start_window
= window
;
987 /* minibuf == nil may or may not include minibuffers.
988 Decide if it does. */
990 minibuf
= (minibuf_level
? minibuf_window
: Qlambda
);
991 else if (! EQ (minibuf
, Qt
))
993 /* Now minibuf can be t => count all minibuffer windows,
994 lambda => count none of them,
995 or a specific minibuffer window (the active one) to count. */
997 /* all_frames == nil doesn't specify which frames to include. */
998 if (NILP (all_frames
))
999 all_frames
= (! EQ (minibuf
, Qlambda
)
1000 ? (FRAME_MINIBUF_WINDOW
1003 (XWINDOW (window
)))))
1005 else if (EQ (all_frames
, Qvisible
))
1007 else if (XFASTINT (all_frames
) == 0)
1009 else if (FRAMEP (all_frames
) && ! EQ (all_frames
, Fwindow_frame (window
)))
1010 /* If all_frames is a frame and window arg isn't on that frame, just
1011 return the first window on the frame. */
1012 return Fframe_first_window (all_frames
);
1013 else if (! EQ (all_frames
, Qt
))
1015 /* Now all_frames is t meaning search all frames,
1016 nil meaning search just current frame,
1017 visible meaning search just visible frames,
1018 0 meaning search visible and iconified frames,
1019 or a window, meaning search the frame that window belongs to. */
1021 /* Do this loop at least once, to get the next window, and perhaps
1022 again, if we hit the minibuffer and that is not acceptable. */
1025 /* Find a window that actually has a next one. This loop
1026 climbs up the tree. */
1027 while (tem
= XWINDOW (window
)->next
, NILP (tem
))
1028 if (tem
= XWINDOW (window
)->parent
, !NILP (tem
))
1032 /* We've reached the end of this frame.
1033 Which other frames are acceptable? */
1034 tem
= WINDOW_FRAME (XWINDOW (window
));
1035 if (! NILP (all_frames
))
1040 tem
= next_frame (tem
, all_frames
);
1041 /* In the case where the minibuffer is active,
1042 and we include its frame as well as the selected one,
1043 next_frame may get stuck in that frame.
1044 If that happens, go back to the selected frame
1045 so we can complete the cycle. */
1047 XSETFRAME (tem
, selected_frame
);
1049 tem
= FRAME_ROOT_WINDOW (XFRAME (tem
));
1056 /* If we're in a combination window, find its first child and
1057 recurse on that. Otherwise, we've found the window we want. */
1060 if (!NILP (XWINDOW (window
)->hchild
))
1061 window
= XWINDOW (window
)->hchild
;
1062 else if (!NILP (XWINDOW (window
)->vchild
))
1063 window
= XWINDOW (window
)->vchild
;
1067 /* Which windows are acceptable?
1068 Exit the loop and accept this window if
1069 this isn't a minibuffer window,
1070 or we're accepting all minibuffer windows,
1071 or this is the active minibuffer and we are accepting that one, or
1072 we've come all the way around and we're back at the original window. */
1073 while (MINI_WINDOW_P (XWINDOW (window
))
1074 && ! EQ (minibuf
, Qt
)
1075 && ! EQ (minibuf
, window
)
1076 && ! EQ (window
, start_window
));
1081 /* This comment supplies the doc string for `previous-window',
1082 for make-docfile to see. We cannot put this in the real DEFUN
1083 due to limits in the Unix cpp.
1085 DEFUN ("previous-window", Ffoo, Sfoo, 0, 3, 0,
1086 "Return the window preceding WINDOW in canonical ordering of windows.\n\
1087 If omitted, WINDOW defaults to the selected window.\n\
1089 Optional second arg MINIBUF t means count the minibuffer window even\n\
1090 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1091 it is active. MINIBUF neither t nor nil means not to count the\n\
1092 minibuffer even if it is active.\n\
1094 Several frames may share a single minibuffer; if the minibuffer\n\
1095 counts, all windows on all frames that share that minibuffer count\n\
1096 too. Therefore, `previous-window' can be used to iterate through\n\
1097 the set of windows even when the minibuffer is on another frame. If\n\
1098 the minibuffer does not count, only windows from WINDOW's frame count\n\
1100 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1101 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1102 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1103 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1104 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1105 Anything else means restrict to WINDOW's frame.\n\
1107 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1108 `previous-window' to iterate through the entire cycle of acceptable\n\
1109 windows, eventually ending up back at the window you started with.\n\
1110 `next-window' traverses the same cycle, in the reverse order.")
1111 (window, minibuf, all_frames) */
1114 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1116 (window
, minibuf
, all_frames
)
1117 register Lisp_Object window
, minibuf
, all_frames
;
1119 register Lisp_Object tem
;
1120 Lisp_Object start_window
;
1123 window
= selected_window
;
1125 CHECK_LIVE_WINDOW (window
, 0);
1127 start_window
= window
;
1129 /* minibuf == nil may or may not include minibuffers.
1130 Decide if it does. */
1132 minibuf
= (minibuf_level
? minibuf_window
: Qlambda
);
1133 else if (! EQ (minibuf
, Qt
))
1135 /* Now minibuf can be t => count all minibuffer windows,
1136 lambda => count none of them,
1137 or a specific minibuffer window (the active one) to count. */
1139 /* all_frames == nil doesn't specify which frames to include.
1140 Decide which frames it includes. */
1141 if (NILP (all_frames
))
1142 all_frames
= (! EQ (minibuf
, Qlambda
)
1143 ? (FRAME_MINIBUF_WINDOW
1146 (XWINDOW (window
)))))
1148 else if (EQ (all_frames
, Qvisible
))
1150 else if (XFASTINT (all_frames
) == 0)
1152 else if (FRAMEP (all_frames
) && ! EQ (all_frames
, Fwindow_frame (window
)))
1153 /* If all_frames is a frame and window arg isn't on that frame, just
1154 return the first window on the frame. */
1155 return Fframe_first_window (all_frames
);
1156 else if (! EQ (all_frames
, Qt
))
1158 /* Now all_frames is t meaning search all frames,
1159 nil meaning search just current frame,
1160 visible meaning search just visible frames,
1161 0 meaning search visible and iconified frames,
1162 or a window, meaning search the frame that window belongs to. */
1164 /* Do this loop at least once, to get the previous window, and perhaps
1165 again, if we hit the minibuffer and that is not acceptable. */
1168 /* Find a window that actually has a previous one. This loop
1169 climbs up the tree. */
1170 while (tem
= XWINDOW (window
)->prev
, NILP (tem
))
1171 if (tem
= XWINDOW (window
)->parent
, !NILP (tem
))
1175 /* We have found the top window on the frame.
1176 Which frames are acceptable? */
1177 tem
= WINDOW_FRAME (XWINDOW (window
));
1178 if (! NILP (all_frames
))
1179 /* It's actually important that we use prev_frame here,
1180 rather than next_frame. All the windows acceptable
1181 according to the given parameters should form a ring;
1182 Fnext_window and Fprevious_window should go back and
1183 forth around the ring. If we use next_frame here,
1184 then Fnext_window and Fprevious_window take different
1185 paths through the set of acceptable windows.
1186 window_loop assumes that these `ring' requirement are
1192 tem
= prev_frame (tem
, all_frames
);
1193 /* In the case where the minibuffer is active,
1194 and we include its frame as well as the selected one,
1195 next_frame may get stuck in that frame.
1196 If that happens, go back to the selected frame
1197 so we can complete the cycle. */
1199 XSETFRAME (tem
, selected_frame
);
1201 /* If this frame has a minibuffer, find that window first,
1202 because it is conceptually the last window in that frame. */
1203 if (FRAME_HAS_MINIBUF_P (XFRAME (tem
)))
1204 tem
= FRAME_MINIBUF_WINDOW (XFRAME (tem
));
1206 tem
= FRAME_ROOT_WINDOW (XFRAME (tem
));
1212 /* If we're in a combination window, find its last child and
1213 recurse on that. Otherwise, we've found the window we want. */
1216 if (!NILP (XWINDOW (window
)->hchild
))
1217 window
= XWINDOW (window
)->hchild
;
1218 else if (!NILP (XWINDOW (window
)->vchild
))
1219 window
= XWINDOW (window
)->vchild
;
1221 while (tem
= XWINDOW (window
)->next
, !NILP (tem
))
1225 /* Which windows are acceptable?
1226 Exit the loop and accept this window if
1227 this isn't a minibuffer window,
1228 or we're accepting all minibuffer windows,
1229 or this is the active minibuffer and we are accepting that one, or
1230 we've come all the way around and we're back at the original window. */
1231 while (MINI_WINDOW_P (XWINDOW (window
))
1232 && ! EQ (minibuf
, Qt
)
1233 && ! EQ (minibuf
, window
)
1234 && ! EQ (window
, start_window
));
1239 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1240 "Select the ARG'th different window on this frame.\n\
1241 All windows on current frame are arranged in a cyclic order.\n\
1242 This command selects the window ARG steps away in that order.\n\
1243 A negative ARG moves in the opposite order. If the optional second\n\
1244 argument ALL_FRAMES is non-nil, cycle through all frames.")
1246 register Lisp_Object arg
, all_frames
;
1249 register Lisp_Object w
;
1251 CHECK_NUMBER (arg
, 0);
1252 w
= selected_window
;
1257 w
= Fnext_window (w
, Qnil
, all_frames
);
1262 w
= Fprevious_window (w
, Qnil
, all_frames
);
1269 /* Look at all windows, performing an operation specified by TYPE
1271 If FRAMES is Qt, look at all frames;
1272 Qnil, look at just the selected frame;
1273 Qvisible, look at visible frames;
1274 a frame, just look at windows on that frame.
1275 If MINI is non-zero, perform the operation on minibuffer windows too.
1281 GET_BUFFER_WINDOW
, /* Arg is buffer */
1282 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1283 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1284 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1286 UNSHOW_BUFFER
/* Arg is buffer */
1290 window_loop (type
, obj
, mini
, frames
)
1291 enum window_loop type
;
1292 register Lisp_Object obj
, frames
;
1295 register Lisp_Object w
;
1296 register Lisp_Object best_window
;
1297 register Lisp_Object next_window
;
1298 register Lisp_Object last_window
;
1300 Lisp_Object frame_arg
;
1303 /* If we're only looping through windows on a particular frame,
1304 frame points to that frame. If we're looping through windows
1305 on all frames, frame is 0. */
1306 if (FRAMEP (frames
))
1307 frame
= XFRAME (frames
);
1308 else if (NILP (frames
))
1309 frame
= selected_frame
;
1313 frame_arg
= Qlambda
;
1314 else if (XFASTINT (frames
) == 0)
1316 else if (EQ (frames
, Qvisible
))
1319 /* frame_arg is Qlambda to stick to one frame,
1320 Qvisible to consider all visible frames,
1323 /* Pick a window to start with. */
1327 w
= FRAME_SELECTED_WINDOW (frame
);
1329 w
= FRAME_SELECTED_WINDOW (selected_frame
);
1331 /* Figure out the last window we're going to mess with. Since
1332 Fnext_window, given the same options, is guaranteed to go in a
1333 ring, we can just use Fprevious_window to find the last one.
1335 We can't just wait until we hit the first window again, because
1336 it might be deleted. */
1338 last_window
= Fprevious_window (w
, mini
? Qt
: Qnil
, frame_arg
);
1343 FRAME_PTR w_frame
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1345 /* Pick the next window now, since some operations will delete
1346 the current window. */
1347 next_window
= Fnext_window (w
, mini
? Qt
: Qnil
, frame_arg
);
1349 /* Note that we do not pay attention here to whether
1350 the frame is visible, since Fnext_window skips non-visible frames
1351 if that is desired, under the control of frame_arg. */
1352 if (! MINI_WINDOW_P (XWINDOW (w
))
1353 || (mini
&& minibuf_level
> 0))
1356 case GET_BUFFER_WINDOW
:
1357 if (XBUFFER (XWINDOW (w
)->buffer
) == XBUFFER (obj
)
1358 /* Don't find any minibuffer window
1359 except the one that is currently in use. */
1360 && (MINI_WINDOW_P (XWINDOW (w
))
1361 ? EQ (w
, minibuf_window
) : 1))
1365 case GET_LRU_WINDOW
:
1366 /* t as arg means consider only full-width windows */
1367 if (!NILP (obj
) && !WINDOW_FULL_WIDTH_P (XWINDOW (w
)))
1369 /* Ignore dedicated windows and minibuffers. */
1370 if (MINI_WINDOW_P (XWINDOW (w
))
1371 || !NILP (XWINDOW (w
)->dedicated
))
1373 if (NILP (best_window
)
1374 || (XFASTINT (XWINDOW (best_window
)->use_time
)
1375 > XFASTINT (XWINDOW (w
)->use_time
)))
1379 case DELETE_OTHER_WINDOWS
:
1380 if (XWINDOW (w
) != XWINDOW (obj
))
1384 case DELETE_BUFFER_WINDOWS
:
1385 if (EQ (XWINDOW (w
)->buffer
, obj
))
1387 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1389 /* If this window is dedicated, and in a frame of its own,
1391 if (EQ (w
, FRAME_ROOT_WINDOW (f
))
1392 && !NILP (XWINDOW (w
)->dedicated
)
1393 && other_visible_frames (f
))
1395 /* Skip the other windows on this frame.
1396 There might be one, the minibuffer! */
1397 if (! EQ (w
, last_window
))
1398 while (f
== XFRAME (WINDOW_FRAME (XWINDOW (next_window
))))
1400 /* As we go, check for the end of the loop.
1401 We mustn't start going around a second time. */
1402 if (EQ (next_window
, last_window
))
1407 next_window
= Fnext_window (next_window
,
1411 /* Now we can safely delete the frame. */
1412 Fdelete_frame (WINDOW_FRAME (XWINDOW (w
)), Qnil
);
1415 /* If we're deleting the buffer displayed in the only window
1416 on the frame, find a new buffer to display there. */
1417 if (NILP (XWINDOW (w
)->parent
))
1419 Lisp_Object new_buffer
;
1420 new_buffer
= Fother_buffer (obj
, Qnil
);
1421 if (NILP (new_buffer
))
1423 = Fget_buffer_create (build_string ("*scratch*"));
1424 Fset_window_buffer (w
, new_buffer
);
1425 if (EQ (w
, selected_window
))
1426 Fset_buffer (XWINDOW (w
)->buffer
);
1433 case GET_LARGEST_WINDOW
:
1434 /* Ignore dedicated windows and minibuffers. */
1435 if (MINI_WINDOW_P (XWINDOW (w
))
1436 || !NILP (XWINDOW (w
)->dedicated
))
1439 struct window
*best_window_ptr
= XWINDOW (best_window
);
1440 struct window
*w_ptr
= XWINDOW (w
);
1441 if (NILP (best_window
)
1442 || (XFASTINT (w_ptr
->height
) * XFASTINT (w_ptr
->width
)
1443 > (XFASTINT (best_window_ptr
->height
)
1444 * XFASTINT (best_window_ptr
->width
))))
1450 if (EQ (XWINDOW (w
)->buffer
, obj
))
1452 /* Find another buffer to show in this window. */
1453 Lisp_Object another_buffer
;
1454 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1455 another_buffer
= Fother_buffer (obj
, Qnil
);
1456 if (NILP (another_buffer
))
1458 = Fget_buffer_create (build_string ("*scratch*"));
1459 /* If this window is dedicated, and in a frame of its own,
1461 if (EQ (w
, FRAME_ROOT_WINDOW (f
))
1462 && !NILP (XWINDOW (w
)->dedicated
)
1463 && other_visible_frames (f
))
1465 /* Skip the other windows on this frame.
1466 There might be one, the minibuffer! */
1467 if (! EQ (w
, last_window
))
1468 while (f
== XFRAME (WINDOW_FRAME (XWINDOW (next_window
))))
1470 /* As we go, check for the end of the loop.
1471 We mustn't start going around a second time. */
1472 if (EQ (next_window
, last_window
))
1477 next_window
= Fnext_window (next_window
,
1481 /* Now we can safely delete the frame. */
1482 Fdelete_frame (WINDOW_FRAME (XWINDOW (w
)), Qnil
);
1486 /* Otherwise show a different buffer in the window. */
1487 XWINDOW (w
)->dedicated
= Qnil
;
1488 Fset_window_buffer (w
, another_buffer
);
1489 if (EQ (w
, selected_window
))
1490 Fset_buffer (XWINDOW (w
)->buffer
);
1496 if (EQ (w
, last_window
))
1505 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 1, 0,
1506 "Return the window least recently selected or used for display.\n\
1507 If optional argument FRAME is `visible', search all visible frames.\n\
1508 If FRAME is 0, search all visible and iconified frames.\n\
1509 If FRAME is t, search all frames.\n\
1510 If FRAME is nil, search only the selected frame.\n\
1511 If FRAME is a frame, search only that frame.")
1515 register Lisp_Object w
;
1516 /* First try for a window that is full-width */
1517 w
= window_loop (GET_LRU_WINDOW
, Qt
, 0, frame
);
1518 if (!NILP (w
) && !EQ (w
, selected_window
))
1520 /* If none of them, try the rest */
1521 return window_loop (GET_LRU_WINDOW
, Qnil
, 0, frame
);
1524 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 1, 0,
1525 "Return the largest window in area.\n\
1526 If optional argument FRAME is `visible', search all visible frames.\n\
1527 If FRAME is 0, search all visible and iconified frames.\n\
1528 If FRAME is t, search all frames.\n\
1529 If FRAME is nil, search only the selected frame.\n\
1530 If FRAME is a frame, search only that frame.")
1534 return window_loop (GET_LARGEST_WINDOW
, Qnil
, 0,
1538 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
1539 "Return a window currently displaying BUFFER, or nil if none.\n\
1540 If optional argument FRAME is `visible', search all visible frames.\n\
1541 If optional argument FRAME is 0, search all visible and iconified frames.\n\
1542 If FRAME is t, search all frames.\n\
1543 If FRAME is nil, search only the selected frame.\n\
1544 If FRAME is a frame, search only that frame.")
1546 Lisp_Object buffer
, frame
;
1548 buffer
= Fget_buffer (buffer
);
1549 if (BUFFERP (buffer
))
1550 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
1555 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
1557 "Make WINDOW (or the selected window) fill its frame.\n\
1558 Only the frame WINDOW is on is affected.\n\
1559 This function tries to reduce display jumps\n\
1560 by keeping the text previously visible in WINDOW\n\
1561 in the same place on the frame. Doing this depends on\n\
1562 the value of (window-start WINDOW), so if calling this function\n\
1563 in a program gives strange scrolling, make sure the window-start\n\
1564 value is reasonable when this function is called.")
1573 window
= selected_window
;
1575 CHECK_LIVE_WINDOW (window
, 0);
1577 w
= XWINDOW (window
);
1579 startpos
= marker_position (w
->start
);
1580 top
= XFASTINT (w
->top
) - FRAME_MENU_BAR_LINES (XFRAME (WINDOW_FRAME (w
)));
1582 if (MINI_WINDOW_P (w
) && top
> 0)
1583 error ("Can't expand minibuffer to full frame");
1585 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
1587 /* Try to minimize scrolling, by setting the window start to the point
1588 will cause the text at the old window start to be at the same place
1589 on the frame. But don't try to do this if the window start is
1590 outside the visible portion (as might happen when the display is
1591 not current, due to typeahead). */
1592 if (startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
1593 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
1595 struct position pos
;
1596 struct buffer
*obuf
= current_buffer
;
1598 Fset_buffer (w
->buffer
);
1599 /* This computation used to temporarily move point, but that can
1600 have unwanted side effects due to text properties. */
1601 pos
= *vmotion (startpos
, -top
, w
);
1603 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
1604 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
1605 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
1607 /* We need to do this, so that the window-scroll-functions
1609 w
->optional_new_start
= Qt
;
1611 set_buffer_internal (obuf
);
1616 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
1617 1, 2, "bDelete windows on (buffer): ",
1618 "Delete all windows showing BUFFER.\n\
1619 Optional second argument FRAME controls which frames are affected.\n\
1620 If nil or omitted, delete all windows showing BUFFER in any frame.\n\
1621 If t, delete only windows showing BUFFER in the selected frame.\n\
1622 If `visible', delete all windows showing BUFFER in any visible frame.\n\
1623 If a frame, delete only windows showing BUFFER in that frame.")
1625 Lisp_Object buffer
, frame
;
1627 /* FRAME uses t and nil to mean the opposite of what window_loop
1629 if (! FRAMEP (frame
))
1630 frame
= NILP (frame
) ? Qt
: Qnil
;
1634 buffer
= Fget_buffer (buffer
);
1635 CHECK_BUFFER (buffer
, 0);
1636 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
1641 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
1642 Sreplace_buffer_in_windows
,
1643 1, 1, "bReplace buffer in windows: ",
1644 "Replace BUFFER with some other buffer in all windows showing it.")
1650 buffer
= Fget_buffer (buffer
);
1651 CHECK_BUFFER (buffer
, 0);
1652 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
1657 /* Replace BUFFER with some other buffer in all windows
1658 of all frames, even those on other keyboards. */
1661 replace_buffer_in_all_windows (buffer
)
1665 Lisp_Object tail
, frame
;
1667 /* A single call to window_loop won't do the job
1668 because it only considers frames on the current keyboard.
1669 So loop manually over frames, and handle each one. */
1670 FOR_EACH_FRAME (tail
, frame
)
1671 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
1673 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
1677 /* Set the height of WINDOW and all its inferiors. */
1679 /* The smallest acceptable dimensions for a window. Anything smaller
1680 might crash Emacs. */
1681 #define MIN_SAFE_WINDOW_WIDTH (2)
1682 #define MIN_SAFE_WINDOW_HEIGHT (2)
1684 /* Make sure that window_min_height and window_min_width are
1685 not too small; if they are, set them to safe minima. */
1688 check_min_window_sizes ()
1690 /* Smaller values might permit a crash. */
1691 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
1692 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
1693 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
1694 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
1697 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
1698 minimum allowable size. */
1700 check_frame_size (frame
, rows
, cols
)
1704 /* For height, we have to see:
1705 whether the frame has a minibuffer,
1706 whether it wants a mode line, and
1707 whether it has a menu bar. */
1709 (FRAME_MINIBUF_ONLY_P (frame
) ? MIN_SAFE_WINDOW_HEIGHT
- 1
1710 : (! FRAME_HAS_MINIBUF_P (frame
)) ? MIN_SAFE_WINDOW_HEIGHT
1711 : 2 * MIN_SAFE_WINDOW_HEIGHT
- 1);
1712 if (FRAME_MENU_BAR_LINES (frame
) > 0)
1713 min_height
+= FRAME_MENU_BAR_LINES (frame
);
1715 if (*rows
< min_height
)
1717 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
1718 *cols
= MIN_SAFE_WINDOW_WIDTH
;
1721 /* Normally the window is deleted if it gets too small.
1722 nodelete nonzero means do not do this.
1723 (The caller should check later and do so if appropriate) */
1726 set_window_height (window
, height
, nodelete
)
1731 register struct window
*w
= XWINDOW (window
);
1732 register struct window
*c
;
1733 int oheight
= XFASTINT (w
->height
);
1734 int top
, pos
, lastbot
, opos
, lastobot
;
1737 check_min_window_sizes ();
1740 && ! NILP (w
->parent
)
1741 && (MINI_WINDOW_P (w
)
1743 : height
< window_min_height
))
1745 delete_window (window
);
1749 XSETFASTINT (w
->last_modified
, 0);
1750 XSETFASTINT (w
->last_overlay_modified
, 0);
1751 windows_or_buffers_changed
++;
1752 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
1754 XSETFASTINT (w
->height
, height
);
1755 if (!NILP (w
->hchild
))
1757 for (child
= w
->hchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1759 XWINDOW (child
)->top
= w
->top
;
1760 set_window_height (child
, height
, nodelete
);
1763 else if (!NILP (w
->vchild
))
1765 lastbot
= top
= XFASTINT (w
->top
);
1767 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
1769 c
= XWINDOW (child
);
1771 opos
= lastobot
+ XFASTINT (c
->height
);
1773 XSETFASTINT (c
->top
, lastbot
);
1775 pos
= (((opos
* height
) << 1) + oheight
) / (oheight
<< 1);
1777 /* Avoid confusion: inhibit deletion of child if becomes too small */
1778 set_window_height (child
, pos
+ top
- lastbot
, 1);
1780 /* Now advance child to next window,
1781 and set lastbot if child was not just deleted. */
1782 lastbot
= pos
+ top
;
1785 /* Now delete any children that became too small. */
1787 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1789 set_window_height (child
, XINT (XWINDOW (child
)->height
), 0);
1794 /* Recursively set width of WINDOW and its inferiors. */
1797 set_window_width (window
, width
, nodelete
)
1802 register struct window
*w
= XWINDOW (window
);
1803 register struct window
*c
;
1804 int owidth
= XFASTINT (w
->width
);
1805 int left
, pos
, lastright
, opos
, lastoright
;
1808 if (!nodelete
&& width
< window_min_width
&& !NILP (w
->parent
))
1810 delete_window (window
);
1814 XSETFASTINT (w
->last_modified
, 0);
1815 XSETFASTINT (w
->last_overlay_modified
, 0);
1816 windows_or_buffers_changed
++;
1817 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
1819 XSETFASTINT (w
->width
, width
);
1820 if (!NILP (w
->vchild
))
1822 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1824 XWINDOW (child
)->left
= w
->left
;
1825 set_window_width (child
, width
, nodelete
);
1828 else if (!NILP (w
->hchild
))
1830 lastright
= left
= XFASTINT (w
->left
);
1832 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
1834 c
= XWINDOW (child
);
1836 opos
= lastoright
+ XFASTINT (c
->width
);
1838 XSETFASTINT (c
->left
, lastright
);
1840 pos
= (((opos
* width
) << 1) + owidth
) / (owidth
<< 1);
1842 /* Inhibit deletion for becoming too small */
1843 set_window_width (child
, pos
+ left
- lastright
, 1);
1845 /* Now advance child to next window,
1846 and set lastright if child was not just deleted. */
1847 lastright
= pos
+ left
, lastoright
= opos
;
1849 /* Delete children that became too small */
1851 for (child
= w
->hchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1853 set_window_width (child
, XINT (XWINDOW (child
)->width
), 0);
1858 int window_select_count
;
1861 Fset_window_buffer_unwind (obuf
)
1868 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 2, 0,
1869 "Make WINDOW display BUFFER as its contents.\n\
1870 BUFFER can be a buffer or buffer name.")
1872 register Lisp_Object window
, buffer
;
1874 register Lisp_Object tem
;
1875 register struct window
*w
= decode_window (window
);
1876 int count
= specpdl_ptr
- specpdl
;
1878 buffer
= Fget_buffer (buffer
);
1879 CHECK_BUFFER (buffer
, 1);
1881 if (NILP (XBUFFER (buffer
)->name
))
1882 error ("Attempt to display deleted buffer");
1886 error ("Window is deleted");
1887 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
1888 is first being set up. */
1890 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
1891 error ("Window is dedicated to `%s'",
1892 XSTRING (XBUFFER (tem
)->name
)->data
);
1899 if (EQ (window
, selected_window
))
1900 XBUFFER (w
->buffer
)->last_selected_window
= window
;
1901 if (INTEGERP (XBUFFER (buffer
)->display_count
))
1902 XSETINT (XBUFFER (buffer
)->display_count
,
1903 XINT (XBUFFER (buffer
)->display_count
) + 1);
1905 XSETFASTINT (w
->window_end_pos
, 0);
1906 w
->window_end_valid
= Qnil
;
1907 XSETFASTINT (w
->hscroll
, 0);
1908 set_marker_both (w
->pointm
, buffer
,
1909 BUF_PT (XBUFFER (buffer
)), BUF_PT_BYTE (XBUFFER (buffer
)));
1910 set_marker_restricted (w
->start
,
1911 make_number (XBUFFER (buffer
)->last_window_start
),
1913 w
->start_at_line_beg
= Qnil
;
1914 w
->force_start
= Qnil
;
1915 XSETFASTINT (w
->last_modified
, 0);
1916 XSETFASTINT (w
->last_overlay_modified
, 0);
1917 windows_or_buffers_changed
++;
1919 /* We must select BUFFER for running the window-scroll-functions.
1920 If WINDOW is selected, switch permanently.
1921 Otherwise, switch but go back to the ambient buffer afterward. */
1922 if (EQ (window
, selected_window
))
1923 Fset_buffer (buffer
);
1924 /* We can't check ! NILP (Vwindow_scroll_functions) here
1925 because that might itself be a local variable. */
1926 else if (window_initialized
)
1928 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
1929 Fset_buffer (buffer
);
1932 if (! NILP (Vwindow_scroll_functions
))
1933 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1934 Fmarker_position (w
->start
));
1936 if (! NILP (Vwindow_configuration_change_hook
)
1937 && ! NILP (Vrun_hooks
))
1938 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
1940 unbind_to (count
, Qnil
);
1945 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 1, 0,
1946 "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\
1947 The main editor command loop selects the buffer of the selected window\n\
1948 before each command.")
1950 register Lisp_Object window
;
1952 register struct window
*w
;
1953 register struct window
*ow
= XWINDOW (selected_window
);
1955 CHECK_LIVE_WINDOW (window
, 0);
1957 w
= XWINDOW (window
);
1959 if (NILP (w
->buffer
))
1960 error ("Trying to select deleted window or non-leaf window");
1962 XSETFASTINT (w
->use_time
, ++window_select_count
);
1963 if (EQ (window
, selected_window
))
1966 if (! NILP (ow
->buffer
))
1967 set_marker_both (ow
->pointm
, ow
->buffer
,
1968 BUF_PT (XBUFFER (ow
->buffer
)),
1969 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
1971 selected_window
= window
;
1972 if (XFRAME (WINDOW_FRAME (w
)) != selected_frame
)
1974 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
1975 /* Use this rather than Fhandle_switch_frame
1976 so that FRAME_FOCUS_FRAME is moved appropriately as we
1977 move around in the state where a minibuffer in a separate
1979 Fselect_frame (WINDOW_FRAME (w
), Qnil
);
1982 selected_frame
->selected_window
= window
;
1984 record_buffer (w
->buffer
);
1985 Fset_buffer (w
->buffer
);
1987 XBUFFER (w
->buffer
)->last_selected_window
= window
;
1989 /* Go to the point recorded in the window.
1990 This is important when the buffer is in more
1991 than one window. It also matters when
1992 redisplay_window has altered point after scrolling,
1993 because it makes the change only in the window. */
1995 register int new_point
= marker_position (w
->pointm
);
1996 if (new_point
< BEGV
)
1998 else if (new_point
> ZV
)
2004 windows_or_buffers_changed
++;
2008 /* Deiconify the frame containing the window WINDOW,
2009 unless it is the selected frame;
2012 The reason for the exception for the selected frame
2013 is that it seems better not to change the selected frames visibility
2014 merely because of displaying a different buffer in it.
2015 The deiconification is useful when a buffer gets shown in
2016 another frame that you were not using lately. */
2019 display_buffer_1 (window
)
2022 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
2023 FRAME_SAMPLE_VISIBILITY (f
);
2024 if (f
!= selected_frame
)
2026 if (FRAME_ICONIFIED_P (f
))
2027 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
2028 else if (FRAME_VISIBLE_P (f
))
2029 Fraise_frame (WINDOW_FRAME (XWINDOW (window
)));
2034 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
2035 "Returns non-nil if a buffer named BUFFER-NAME would be created specially.\n\
2036 The value is actually t if the frame should be called with default frame\n\
2037 parameters, and a list of frame parameters if they were specified.\n\
2038 See `special-display-buffer-names', and `special-display-regexps'.")
2040 Lisp_Object buffer_name
;
2044 CHECK_STRING (buffer_name
, 1);
2046 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
2050 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
2054 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2056 Lisp_Object car
= XCAR (tem
);
2058 && fast_string_match (car
, buffer_name
) >= 0)
2060 else if (CONSP (car
)
2061 && STRINGP (XCAR (car
))
2062 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2068 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
2069 "Returns non-nil if a new buffer named BUFFER-NAME would use the same window.\n\
2070 See `same-window-buffer-names' and `same-window-regexps'.")
2072 Lisp_Object buffer_name
;
2076 CHECK_STRING (buffer_name
, 1);
2078 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
2082 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
2086 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2088 Lisp_Object car
= XCAR (tem
);
2090 && fast_string_match (car
, buffer_name
) >= 0)
2092 else if (CONSP (car
)
2093 && STRINGP (XCAR (car
))
2094 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2100 /* Use B so the default is (other-buffer). */
2101 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
2102 "BDisplay buffer: \nP",
2103 "Make BUFFER appear in some window but don't select it.\n\
2104 BUFFER can be a buffer or a buffer name.\n\
2105 If BUFFER is shown already in some window, just use that one,\n\
2106 unless the window is the selected window and the optional second\n\
2107 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).\n\
2108 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.\n\
2109 Returns the window displaying BUFFER.\n\
2111 The variables `special-display-buffer-names', `special-display-regexps',\n\
2112 `same-window-buffer-names', and `same-window-regexps' customize how certain\n\
2113 buffer names are handled.\n\
2115 If optional argument FRAME is `visible', search all visible frames.\n\
2116 If FRAME is 0, search all visible and iconified frames.\n\
2117 If FRAME is t, search all frames.\n\
2118 If FRAME is a frame, search only that frame.\n\
2119 If FRAME is nil, search only the selected frame\n\
2120 (actually the last nonminibuffer frame),\n\
2121 unless `pop-up-frames' is non-nil,\n\
2122 which means search visible and iconified frames.")
2123 (buffer
, not_this_window
, frame
)
2124 register Lisp_Object buffer
, not_this_window
, frame
;
2126 register Lisp_Object window
, tem
;
2128 buffer
= Fget_buffer (buffer
);
2129 CHECK_BUFFER (buffer
, 0);
2131 if (!NILP (Vdisplay_buffer_function
))
2132 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
2134 if (NILP (not_this_window
)
2135 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
2136 return display_buffer_1 (selected_window
);
2138 /* See if the user has specified this buffer should appear
2139 in the selected window. */
2140 if (NILP (not_this_window
))
2142 tem
= Fsame_window_p (XBUFFER (buffer
)->name
);
2145 Fswitch_to_buffer (buffer
, Qnil
);
2146 return display_buffer_1 (selected_window
);
2150 /* If pop_up_frames,
2151 look for a window showing BUFFER on any visible or iconified frame.
2152 Otherwise search only the current frame. */
2155 else if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2156 XSETFASTINT (tem
, 0);
2158 XSETFRAME (tem
, last_nonminibuf_frame
);
2159 window
= Fget_buffer_window (buffer
, tem
);
2161 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
2163 return display_buffer_1 (window
);
2166 /* Certain buffer names get special handling. */
2167 if (!NILP (Vspecial_display_function
))
2169 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
2171 return call1 (Vspecial_display_function
, buffer
);
2173 return call2 (Vspecial_display_function
, buffer
, tem
);
2176 /* If there are no frames open that have more than a minibuffer,
2177 we need to create a new frame. */
2178 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2180 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2181 Fset_window_buffer (window
, buffer
);
2182 return display_buffer_1 (window
);
2186 || FRAME_MINIBUF_ONLY_P (selected_frame
)
2187 /* If the current frame is a special display frame,
2188 don't try to reuse its windows. */
2189 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (selected_frame
))->dedicated
)
2195 if (FRAME_MINIBUF_ONLY_P (selected_frame
))
2196 XSETFRAME (frames
, last_nonminibuf_frame
);
2197 /* Don't try to create a window if would get an error */
2198 if (split_height_threshold
< window_min_height
<< 1)
2199 split_height_threshold
= window_min_height
<< 1;
2201 /* Note that both Fget_largest_window and Fget_lru_window
2202 ignore minibuffers and dedicated windows.
2203 This means they can return nil. */
2205 /* If the frame we would try to split cannot be split,
2206 try other frames. */
2207 if (FRAME_NO_SPLIT_P (NILP (frames
) ? selected_frame
2208 : last_nonminibuf_frame
))
2210 /* Try visible frames first. */
2211 window
= Fget_largest_window (Qvisible
);
2212 /* If that didn't work, try iconified frames. */
2214 window
= Fget_largest_window (make_number (0));
2216 window
= Fget_largest_window (Qt
);
2219 window
= Fget_largest_window (frames
);
2221 /* If we got a tall enough full-width window that can be split,
2224 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2225 && window_height (window
) >= split_height_threshold
2226 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
2227 window
= Fsplit_window (window
, Qnil
, Qnil
);
2230 Lisp_Object upper
, lower
, other
;
2232 window
= Fget_lru_window (frames
);
2233 /* If the LRU window is selected, and big enough,
2234 and can be split, split it. */
2236 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2237 && (EQ (window
, selected_window
)
2238 || EQ (XWINDOW (window
)->parent
, Qnil
))
2239 && window_height (window
) >= window_min_height
<< 1)
2240 window
= Fsplit_window (window
, Qnil
, Qnil
);
2241 /* If Fget_lru_window returned nil, try other approaches. */
2243 /* Try visible frames first. */
2245 window
= Fget_buffer_window (buffer
, Qvisible
);
2247 window
= Fget_largest_window (Qvisible
);
2248 /* If that didn't work, try iconified frames. */
2250 window
= Fget_buffer_window (buffer
, make_number (0));
2252 window
= Fget_largest_window (make_number (0));
2253 /* Try invisible frames. */
2255 window
= Fget_buffer_window (buffer
, Qt
);
2257 window
= Fget_largest_window (Qt
);
2258 /* As a last resort, make a new frame. */
2260 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2261 /* If window appears above or below another,
2262 even out their heights. */
2263 other
= upper
= lower
= Qnil
;
2264 if (!NILP (XWINDOW (window
)->prev
))
2265 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
2266 if (!NILP (XWINDOW (window
)->next
))
2267 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
2269 /* Check that OTHER and WINDOW are vertically arrayed. */
2270 && !EQ (XWINDOW (other
)->top
, XWINDOW (window
)->top
)
2271 && (XFASTINT (XWINDOW (other
)->height
)
2272 > XFASTINT (XWINDOW (window
)->height
)))
2274 int total
= (XFASTINT (XWINDOW (other
)->height
)
2275 + XFASTINT (XWINDOW (window
)->height
));
2276 Lisp_Object old_selected_window
;
2277 old_selected_window
= selected_window
;
2279 selected_window
= upper
;
2280 change_window_height ((total
/ 2
2281 - XFASTINT (XWINDOW (upper
)->height
)),
2283 selected_window
= old_selected_window
;
2288 window
= Fget_lru_window (Qnil
);
2290 Fset_window_buffer (window
, buffer
);
2291 return display_buffer_1 (window
);
2295 temp_output_buffer_show (buf
)
2296 register Lisp_Object buf
;
2298 register struct buffer
*old
= current_buffer
;
2299 register Lisp_Object window
;
2300 register struct window
*w
;
2302 XBUFFER (buf
)->directory
= current_buffer
->directory
;
2305 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
2309 XBUFFER (buf
)->clip_changed
= 1;
2310 set_buffer_internal (old
);
2312 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
2313 call1 (Vtemp_buffer_show_function
, buf
);
2316 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
2318 if (XFRAME (XWINDOW (window
)->frame
) != selected_frame
)
2319 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
2320 Vminibuf_scroll_window
= window
;
2321 w
= XWINDOW (window
);
2322 XSETFASTINT (w
->hscroll
, 0);
2323 set_marker_restricted_both (w
->start
, buf
, 1, 1);
2324 set_marker_restricted_both (w
->pointm
, buf
, 1, 1);
2326 /* Run temp-buffer-show-hook, with the chosen window selected. */
2327 if (!NILP (Vrun_hooks
))
2330 tem
= Fboundp (Qtemp_buffer_show_hook
);
2333 tem
= Fsymbol_value (Qtemp_buffer_show_hook
);
2336 int count
= specpdl_ptr
- specpdl
;
2338 /* Select the window that was chosen, for running the hook. */
2339 record_unwind_protect (Fset_window_configuration
,
2340 Fcurrent_window_configuration (Qnil
));
2342 Fselect_window (window
);
2343 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
2344 unbind_to (count
, Qnil
);
2352 make_dummy_parent (window
)
2356 register struct window
*o
, *p
;
2357 register struct Lisp_Vector
*vec
;
2360 o
= XWINDOW (window
);
2361 vec
= allocate_vectorlike ((EMACS_INT
)VECSIZE (struct window
));
2362 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
2363 vec
->contents
[i
] = ((struct Lisp_Vector
*)o
)->contents
[i
];
2364 vec
->size
= VECSIZE (struct window
);
2365 p
= (struct window
*)vec
;
2366 XSETWINDOW (new, p
);
2368 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
2370 /* Put new into window structure in place of window */
2371 replace_window (window
, new);
2384 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
2385 "Split WINDOW, putting SIZE lines in the first of the pair.\n\
2386 WINDOW defaults to selected one and SIZE to half its size.\n\
2387 If optional third arg HORFLAG is non-nil, split side by side\n\
2388 and put SIZE columns in the first of the pair.")
2389 (window
, size
, horflag
)
2390 Lisp_Object window
, size
, horflag
;
2392 register Lisp_Object
new;
2393 register struct window
*o
, *p
;
2395 register int size_int
;
2398 window
= selected_window
;
2400 CHECK_LIVE_WINDOW (window
, 0);
2402 o
= XWINDOW (window
);
2403 fo
= XFRAME (WINDOW_FRAME (o
));
2407 if (!NILP (horflag
))
2408 /* Calculate the size of the left-hand window, by dividing
2409 the usable space in columns by two. */
2410 size_int
= XFASTINT (o
->width
) >> 1;
2412 size_int
= XFASTINT (o
->height
) >> 1;
2416 CHECK_NUMBER (size
, 1);
2417 size_int
= XINT (size
);
2420 if (MINI_WINDOW_P (o
))
2421 error ("Attempt to split minibuffer window");
2423 check_min_window_sizes ();
2427 if (size_int
< window_min_height
)
2428 error ("Window height %d too small (after splitting)", size_int
);
2429 if (size_int
+ window_min_height
> XFASTINT (o
->height
))
2430 error ("Window height %d too small (after splitting)",
2431 XFASTINT (o
->height
) - size_int
);
2432 if (NILP (o
->parent
)
2433 || NILP (XWINDOW (o
->parent
)->vchild
))
2435 make_dummy_parent (window
);
2437 XWINDOW (new)->vchild
= window
;
2442 if (size_int
< window_min_width
)
2443 error ("Window width %d too small (after splitting)", size_int
);
2445 if (size_int
+ window_min_width
> XFASTINT (o
->width
))
2446 error ("Window width %d too small (after splitting)",
2447 XFASTINT (o
->width
) - size_int
);
2448 if (NILP (o
->parent
)
2449 || NILP (XWINDOW (o
->parent
)->hchild
))
2451 make_dummy_parent (window
);
2453 XWINDOW (new)->hchild
= window
;
2457 /* Now we know that window's parent is a vertical combination
2458 if we are dividing vertically, or a horizontal combination
2459 if we are making side-by-side windows */
2461 windows_or_buffers_changed
++;
2462 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
2463 new = make_window ();
2466 p
->frame
= o
->frame
;
2468 if (!NILP (p
->next
))
2469 XWINDOW (p
->next
)->prev
= new;
2472 p
->parent
= o
->parent
;
2475 /* Apportion the available frame space among the two new windows */
2477 if (!NILP (horflag
))
2479 p
->height
= o
->height
;
2481 XSETFASTINT (p
->width
, XFASTINT (o
->width
) - size_int
);
2482 XSETFASTINT (o
->width
, size_int
);
2483 XSETFASTINT (p
->left
, XFASTINT (o
->left
) + size_int
);
2488 p
->width
= o
->width
;
2489 XSETFASTINT (p
->height
, XFASTINT (o
->height
) - size_int
);
2490 XSETFASTINT (o
->height
, size_int
);
2491 XSETFASTINT (p
->top
, XFASTINT (o
->top
) + size_int
);
2494 Fset_window_buffer (new, o
->buffer
);
2499 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
2500 "Make current window ARG lines bigger.\n\
2501 From program, optional second arg non-nil means grow sideways ARG columns.")
2503 register Lisp_Object arg
, side
;
2505 CHECK_NUMBER (arg
, 0);
2506 change_window_height (XINT (arg
), !NILP (side
));
2508 if (! NILP (Vwindow_configuration_change_hook
))
2509 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2514 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
2515 "Make current window ARG lines smaller.\n\
2516 From program, optional second arg non-nil means shrink sideways arg columns.")
2518 register Lisp_Object arg
, side
;
2520 CHECK_NUMBER (arg
, 0);
2521 change_window_height (-XINT (arg
), !NILP (side
));
2523 if (! NILP (Vwindow_configuration_change_hook
))
2524 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2530 window_height (window
)
2533 register struct window
*p
= XWINDOW (window
);
2534 return XFASTINT (p
->height
);
2538 window_width (window
)
2541 register struct window
*p
= XWINDOW (window
);
2542 return XFASTINT (p
->width
);
2545 #define MINSIZE(w) \
2547 ? window_min_width \
2548 : (MINI_WINDOW_P (XWINDOW (w)) ? 1 : window_min_height))
2551 *(widthflag ? (int *) &(XWINDOW (w)->left) : (int *) &(XWINDOW (w)->top))
2553 #define CURSIZE(w) \
2554 *(widthflag ? (int *) &(XWINDOW (w)->width) : (int *) &(XWINDOW (w)->height))
2556 /* Unlike set_window_height, this function
2557 also changes the heights of the siblings so as to
2558 keep everything consistent. */
2561 change_window_height (delta
, widthflag
)
2565 register Lisp_Object parent
;
2567 register struct window
*p
;
2569 int (*sizefun
) P_ ((Lisp_Object
))
2570 = widthflag
? window_width
: window_height
;
2571 register void (*setsizefun
) P_ ((Lisp_Object
, int, int))
2572 = (widthflag
? set_window_width
: set_window_height
);
2574 Lisp_Object next
, prev
;
2576 check_min_window_sizes ();
2578 window
= selected_window
;
2581 p
= XWINDOW (window
);
2586 error ("No other window to side of this one");
2589 if (widthflag
? !NILP (XWINDOW (parent
)->hchild
)
2590 : !NILP (XWINDOW (parent
)->vchild
))
2595 sizep
= &CURSIZE (window
);
2598 register int maxdelta
;
2600 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - *sizep
2601 : !NILP (p
->next
) ? (*sizefun
) (p
->next
) - MINSIZE (p
->next
)
2602 : !NILP (p
->prev
) ? (*sizefun
) (p
->prev
) - MINSIZE (p
->prev
)
2603 /* This is a frame with only one window, a minibuffer-only
2604 or a minibufferless frame. */
2607 if (delta
> maxdelta
)
2608 /* This case traps trying to make the minibuffer
2609 the full frame, or make the only window aside from the
2610 minibuffer the full frame. */
2614 if (*sizep
+ delta
< MINSIZE (window
))
2616 delete_window (window
);
2623 /* Find the total we can get from other siblings. */
2625 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
2626 maximum
+= (*sizefun
) (next
) - MINSIZE (next
);
2627 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
2628 maximum
+= (*sizefun
) (prev
) - MINSIZE (prev
);
2630 /* If we can get it all from them, do so. */
2631 if (delta
<= maximum
)
2633 Lisp_Object first_unaffected
;
2634 Lisp_Object first_affected
;
2638 first_affected
= window
;
2639 /* Look at one sibling at a time,
2640 moving away from this window in both directions alternately,
2641 and take as much as we can get without deleting that sibling. */
2648 int this_one
= (*sizefun
) (next
) - MINSIZE (next
);
2649 if (this_one
> delta
)
2652 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
2653 (*setsizefun
) (window
, *sizep
+ this_one
, 0);
2656 next
= XWINDOW (next
)->next
;
2662 int this_one
= (*sizefun
) (prev
) - MINSIZE (prev
);
2663 if (this_one
> delta
)
2666 first_affected
= prev
;
2668 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
2669 (*setsizefun
) (window
, *sizep
+ this_one
, 0);
2672 prev
= XWINDOW (prev
)->prev
;
2676 /* Now recalculate the edge positions of all the windows affected,
2677 based on the new sizes. */
2678 first_unaffected
= next
;
2679 prev
= first_affected
;
2680 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
2681 prev
= next
, next
= XWINDOW (next
)->next
)
2683 CURBEG (next
) = CURBEG (prev
) + (*sizefun
) (prev
);
2684 /* This does not change size of NEXT,
2685 but it propagates the new top edge to its children */
2686 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
2691 register int delta1
;
2692 register int opht
= (*sizefun
) (parent
);
2694 /* If trying to grow this window to or beyond size of the parent,
2695 make delta1 so big that, on shrinking back down,
2696 all the siblings end up with less than one line and are deleted. */
2697 if (opht
<= *sizep
+ delta
)
2698 delta1
= opht
* opht
* 2;
2699 /* Otherwise, make delta1 just right so that if we add delta1
2700 lines to this window and to the parent, and then shrink
2701 the parent back to its original size, the new proportional
2702 size of this window will increase by delta. */
2704 delta1
= (delta
* opht
* 100) / ((opht
- *sizep
- delta
) * 100);
2706 /* Add delta1 lines or columns to this window, and to the parent,
2707 keeping things consistent while not affecting siblings. */
2708 CURSIZE (parent
) = opht
+ delta1
;
2709 (*setsizefun
) (window
, *sizep
+ delta1
, 0);
2711 /* Squeeze out delta1 lines or columns from our parent,
2712 shriking this window and siblings proportionately.
2713 This brings parent back to correct size.
2714 Delta1 was calculated so this makes this window the desired size,
2715 taking it all out of the siblings. */
2716 (*setsizefun
) (parent
, opht
, 0);
2719 XSETFASTINT (p
->last_modified
, 0);
2720 XSETFASTINT (p
->last_overlay_modified
, 0);
2727 /* Return number of lines of text (not counting mode line) in W. */
2730 window_internal_height (w
)
2733 int ht
= XFASTINT (w
->height
);
2735 if (MINI_WINDOW_P (w
))
2738 if (!NILP (w
->parent
) || !NILP (w
->vchild
) || !NILP (w
->hchild
)
2739 || !NILP (w
->next
) || !NILP (w
->prev
)
2740 || FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (w
))))
2747 /* Return the number of columns in W.
2748 Don't count columns occupied by scroll bars or the vertical bar
2749 separating W from the sibling to its right. */
2751 window_internal_width (w
)
2754 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2755 int width
= XINT (w
->width
);
2757 /* Scroll bars occupy a few columns. */
2758 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2759 return width
- FRAME_SCROLL_BAR_COLS (f
);
2761 /* The column of `|' characters separating side-by-side windows
2762 occupies one column only. */
2763 if (!WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
2770 /* Scroll contents of window WINDOW up N lines.
2771 If WHOLE is nonzero, it means scroll N screenfuls instead. */
2774 window_scroll (window
, n
, whole
, noerror
)
2780 register struct window
*w
= XWINDOW (window
);
2781 register int opoint
= PT
;
2782 register int opoint_byte
= PT_BYTE
;
2783 register int pos
, pos_byte
;
2784 register int ht
= window_internal_height (w
);
2785 register Lisp_Object tem
;
2787 Lisp_Object bolp
, nmoved
;
2789 struct position posit
;
2792 startpos
= marker_position (w
->start
);
2794 posit
= *compute_motion (startpos
, 0, 0, 0,
2796 window_internal_width (w
), XINT (w
->hscroll
),
2798 original_vpos
= posit
.vpos
;
2800 XSETFASTINT (tem
, PT
);
2801 tem
= Fpos_visible_in_window_p (tem
, window
);
2805 Fvertical_motion (make_number (- (ht
/ 2)), window
);
2810 lose
= n
< 0 && PT
== BEGV
;
2811 Fvertical_motion (make_number (n
), window
);
2815 SET_PT_BOTH (opoint
, opoint_byte
);
2822 Fsignal (Qbeginning_of_buffer
, Qnil
);
2827 int this_scroll_margin
= scroll_margin
;
2829 /* Don't use a scroll margin that is negative or too large. */
2830 if (this_scroll_margin
< 0)
2831 this_scroll_margin
= 0;
2833 if (XINT (w
->height
) < 4 * scroll_margin
)
2834 this_scroll_margin
= XINT (w
->height
) / 4;
2836 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
2837 w
->start_at_line_beg
= bolp
;
2838 w
->update_mode_line
= Qt
;
2839 XSETFASTINT (w
->last_modified
, 0);
2840 XSETFASTINT (w
->last_overlay_modified
, 0);
2841 /* Set force_start so that redisplay_window will run
2842 the window-scroll-functions. */
2843 w
->force_start
= Qt
;
2845 if (whole
&& scroll_preserve_screen_position
)
2847 SET_PT_BOTH (pos
, pos_byte
);
2848 Fvertical_motion (make_number (original_vpos
), window
);
2850 /* If we scrolled forward, put point enough lines down
2851 that it is outside the scroll margin. */
2856 if (this_scroll_margin
> 0)
2858 SET_PT_BOTH (pos
, pos_byte
);
2859 Fvertical_motion (make_number (this_scroll_margin
), window
);
2865 if (top_margin
<= opoint
)
2866 SET_PT_BOTH (opoint
, opoint_byte
);
2867 else if (scroll_preserve_screen_position
)
2869 SET_PT_BOTH (pos
, pos_byte
);
2870 Fvertical_motion (make_number (original_vpos
), window
);
2873 SET_PT (top_margin
);
2879 /* If we scrolled backward, put point near the end of the window
2880 but not within the scroll margin. */
2881 SET_PT_BOTH (pos
, pos_byte
);
2882 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
2883 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
2886 bottom_margin
= PT
+ 1;
2888 if (bottom_margin
> opoint
)
2889 SET_PT_BOTH (opoint
, opoint_byte
);
2892 if (scroll_preserve_screen_position
)
2894 SET_PT_BOTH (pos
, pos_byte
);
2895 Fvertical_motion (make_number (original_vpos
), window
);
2898 Fvertical_motion (make_number (-1), window
);
2907 Fsignal (Qend_of_buffer
, Qnil
);
2911 /* This is the guts of Fscroll_up and Fscroll_down. */
2914 scroll_command (n
, direction
)
2915 register Lisp_Object n
;
2918 register int defalt
;
2919 int count
= specpdl_ptr
- specpdl
;
2921 /* If selected window's buffer isn't current, make it current for the moment.
2922 But don't screw up if window_scroll gets an error. */
2923 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
2925 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
2926 Fset_buffer (XWINDOW (selected_window
)->buffer
);
2929 defalt
= (window_internal_height (XWINDOW (selected_window
))
2930 - next_screen_context_lines
);
2931 defalt
= direction
* (defalt
< 1 ? 1 : defalt
);
2934 window_scroll (selected_window
, defalt
, 1, 0);
2935 else if (EQ (n
, Qminus
))
2936 window_scroll (selected_window
, - defalt
, 1, 0);
2939 n
= Fprefix_numeric_value (n
);
2940 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
2943 unbind_to (count
, Qnil
);
2946 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
2947 "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\
2948 A near full screen is `next-screen-context-lines' less than a full screen.\n\
2949 Negative ARG means scroll downward.\n\
2950 When calling from a program, supply a number as argument or nil.")
2954 scroll_command (arg
, 1);
2958 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
2959 "Scroll text of current window downward ARG lines; or near full screen if no ARG.\n\
2960 A near full screen is `next-screen-context-lines' less than a full screen.\n\
2961 Negative ARG means scroll upward.\n\
2962 When calling from a program, supply a number as argument or nil.")
2966 scroll_command (arg
, -1);
2970 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
2971 "Return the other window for \"other window scroll\" commands.\n\
2972 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
2973 specifies the window.\n\
2974 If `other-window-scroll-buffer' is non-nil, a window\n\
2975 showing that buffer is used.")
2980 if (MINI_WINDOW_P (XWINDOW (selected_window
))
2981 && !NILP (Vminibuf_scroll_window
))
2982 window
= Vminibuf_scroll_window
;
2983 /* If buffer is specified, scroll that buffer. */
2984 else if (!NILP (Vother_window_scroll_buffer
))
2986 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
2988 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
2992 /* Nothing specified; look for a neighboring window on the same
2994 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
2996 if (EQ (window
, selected_window
))
2997 /* That didn't get us anywhere; look for a window on another
3000 window
= Fnext_window (window
, Qnil
, Qt
);
3001 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
3002 && ! EQ (window
, selected_window
));
3005 CHECK_LIVE_WINDOW (window
, 0);
3007 if (EQ (window
, selected_window
))
3008 error ("There is no other window");
3013 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
3014 "Scroll next window upward ARG lines; or near full screen if no ARG.\n\
3015 The next window is the one below the current one; or the one at the top\n\
3016 if the current one is at the bottom. Negative ARG means scroll downward.\n\
3017 When calling from a program, supply a number as argument or nil.\n\
3019 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
3020 specifies the window to scroll.\n\
3021 If `other-window-scroll-buffer' is non-nil, scroll the window\n\
3022 showing that buffer, popping the buffer up if necessary.")
3024 register Lisp_Object arg
;
3026 register Lisp_Object window
;
3027 register int defalt
;
3028 register struct window
*w
;
3029 register int count
= specpdl_ptr
- specpdl
;
3031 window
= Fother_window_for_scrolling ();
3033 w
= XWINDOW (window
);
3034 defalt
= window_internal_height (w
) - next_screen_context_lines
;
3035 if (defalt
< 1) defalt
= 1;
3037 /* Don't screw up if window_scroll gets an error. */
3038 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
3040 Fset_buffer (w
->buffer
);
3041 SET_PT (marker_position (w
->pointm
));
3044 window_scroll (window
, defalt
, 1, 1);
3045 else if (EQ (arg
, Qminus
))
3046 window_scroll (window
, -defalt
, 1, 1);
3051 CHECK_NUMBER (arg
, 0);
3052 window_scroll (window
, XINT (arg
), 0, 1);
3055 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
3056 unbind_to (count
, Qnil
);
3061 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 1, "P",
3062 "Scroll selected window display ARG columns left.\n\
3063 Default for ARG is window width minus 2.")
3065 register Lisp_Object arg
;
3069 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
3071 arg
= Fprefix_numeric_value (arg
);
3074 Fset_window_hscroll (selected_window
,
3075 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
3079 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 1, "P",
3080 "Scroll selected window display ARG columns right.\n\
3081 Default for ARG is window width minus 2.")
3083 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 ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
3097 "Center point in window and redisplay frame. With ARG, put point on line ARG.\n\
3098 The desired position of point is always relative to the current window.\n\
3099 Just C-u as prefix means put point in the center of the window.\n\
3100 If ARG is omitted or nil, erases the entire frame and then\n\
3101 redraws with point in the center of the current window.")
3103 register Lisp_Object arg
;
3105 register struct window
*w
= XWINDOW (selected_window
);
3106 register int ht
= window_internal_height (w
);
3107 struct position pos
;
3111 extern int frame_garbaged
;
3113 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
3114 XSETFASTINT (arg
, ht
/ 2);
3116 else if (CONSP (arg
)) /* Just C-u. */
3118 XSETFASTINT (arg
, ht
/ 2);
3122 arg
= Fprefix_numeric_value (arg
);
3123 CHECK_NUMBER (arg
, 0);
3127 XSETINT (arg
, XINT (arg
) + ht
);
3129 pos
= *vmotion (PT
, - XINT (arg
), w
);
3131 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
3132 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
3133 || FETCH_BYTE (pos
.bytepos
- 1) == '\n')
3135 w
->force_start
= Qt
;
3140 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
3142 "Position point relative to window.\n\
3143 With no argument, position point at center of window.\n\
3144 An argument specifies frame line; zero means top of window,\n\
3145 negative means relative to bottom of window.")
3147 register Lisp_Object arg
;
3149 register struct window
*w
= XWINDOW (selected_window
);
3150 register int height
= window_internal_height (w
);
3155 XSETFASTINT (arg
, height
/ 2);
3158 arg
= Fprefix_numeric_value (arg
);
3160 XSETINT (arg
, XINT (arg
) + height
);
3163 start
= marker_position (w
->start
);
3164 XSETWINDOW (window
, w
);
3165 if (start
< BEGV
|| start
> ZV
)
3167 Fvertical_motion (make_number (- (height
/ 2)), window
);
3168 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
3169 w
->start_at_line_beg
= Fbolp ();
3170 w
->force_start
= Qt
;
3173 Fgoto_char (w
->start
);
3175 return Fvertical_motion (arg
, window
);
3178 struct save_window_data
3180 EMACS_INT size_from_Lisp_Vector_struct
;
3181 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
3182 Lisp_Object frame_width
, frame_height
, frame_menu_bar_lines
;
3183 Lisp_Object selected_frame
;
3184 Lisp_Object current_window
;
3185 Lisp_Object current_buffer
;
3186 Lisp_Object minibuf_scroll_window
;
3187 Lisp_Object root_window
;
3188 Lisp_Object focus_frame
;
3189 /* Record the values of window-min-width and window-min-height
3190 so that window sizes remain consistent with them. */
3191 Lisp_Object min_width
, min_height
;
3192 /* A vector, each of whose elements is a struct saved_window
3194 Lisp_Object saved_windows
;
3197 /* This is saved as a Lisp_Vector */
3200 /* these first two must agree with struct Lisp_Vector in lisp.h */
3201 EMACS_INT size_from_Lisp_Vector_struct
;
3202 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
3205 Lisp_Object buffer
, start
, pointm
, mark
;
3206 Lisp_Object left
, top
, width
, height
, hscroll
;
3207 Lisp_Object parent
, prev
;
3208 Lisp_Object start_at_line_beg
;
3209 Lisp_Object display_table
;
3211 #define SAVED_WINDOW_VECTOR_SIZE 14 /* Arg to Fmake_vector */
3213 #define SAVED_WINDOW_N(swv,n) \
3214 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
3216 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
3217 "Return t if OBJECT is a window-configuration object.")
3221 if (WINDOW_CONFIGURATIONP (object
))
3226 DEFUN ("set-window-configuration", Fset_window_configuration
,
3227 Sset_window_configuration
, 1, 1, 0,
3228 "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\
3229 CONFIGURATION must be a value previously returned\n\
3230 by `current-window-configuration' (which see).")
3232 Lisp_Object configuration
;
3234 register struct save_window_data
*data
;
3235 struct Lisp_Vector
*saved_windows
;
3236 Lisp_Object new_current_buffer
;
3241 while (!WINDOW_CONFIGURATIONP (configuration
))
3243 configuration
= wrong_type_argument (intern ("window-configuration-p"),
3247 data
= (struct save_window_data
*) XVECTOR (configuration
);
3248 saved_windows
= XVECTOR (data
->saved_windows
);
3250 new_current_buffer
= data
->current_buffer
;
3251 if (NILP (XBUFFER (new_current_buffer
)->name
))
3252 new_current_buffer
= Qnil
;
3255 if (XBUFFER (new_current_buffer
) == current_buffer
)
3260 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
3263 /* If f is a dead frame, don't bother rebuilding its window tree.
3264 However, there is other stuff we should still try to do below. */
3265 if (FRAME_LIVE_P (f
))
3267 register struct window
*w
;
3268 register struct saved_window
*p
;
3271 /* If the frame has been resized since this window configuration was
3272 made, we change the frame to the size specified in the
3273 configuration, restore the configuration, and then resize it
3274 back. We keep track of the prevailing height in these variables. */
3275 int previous_frame_height
= FRAME_HEIGHT (f
);
3276 int previous_frame_width
= FRAME_WIDTH (f
);
3277 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
3279 /* The mouse highlighting code could get screwed up
3280 if it runs during this. */
3283 if (XFASTINT (data
->frame_height
) != previous_frame_height
3284 || XFASTINT (data
->frame_width
) != previous_frame_width
)
3285 change_frame_size (f
, data
->frame_height
, data
->frame_width
, 0, 0);
3286 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
3287 if (XFASTINT (data
->frame_menu_bar_lines
)
3288 != previous_frame_menu_bar_lines
)
3289 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, 0);
3292 if (! NILP (XWINDOW (selected_window
)->buffer
))
3294 w
= XWINDOW (selected_window
);
3295 set_marker_both (w
->pointm
,
3297 BUF_PT (XBUFFER (w
->buffer
)),
3298 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
3301 windows_or_buffers_changed
++;
3302 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3304 /* Temporarily avoid any problems with windows that are smaller
3305 than they are supposed to be. */
3306 window_min_height
= 1;
3307 window_min_width
= 1;
3310 Mark all windows now on frame as "deleted".
3311 Restoring the new configuration "undeletes" any that are in it.
3313 Save their current buffers in their height fields, since we may
3314 need it later, if a buffer saved in the configuration is now
3316 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3318 for (k
= 0; k
< saved_windows
->size
; k
++)
3320 p
= SAVED_WINDOW_N (saved_windows
, k
);
3321 w
= XWINDOW (p
->window
);
3324 if (!NILP (p
->parent
))
3325 w
->parent
= SAVED_WINDOW_N (saved_windows
,
3326 XFASTINT (p
->parent
))->window
;
3330 if (!NILP (p
->prev
))
3332 w
->prev
= SAVED_WINDOW_N (saved_windows
,
3333 XFASTINT (p
->prev
))->window
;
3334 XWINDOW (w
->prev
)->next
= p
->window
;
3339 if (!NILP (w
->parent
))
3341 if (EQ (p
->width
, XWINDOW (w
->parent
)->width
))
3343 XWINDOW (w
->parent
)->vchild
= p
->window
;
3344 XWINDOW (w
->parent
)->hchild
= Qnil
;
3348 XWINDOW (w
->parent
)->hchild
= p
->window
;
3349 XWINDOW (w
->parent
)->vchild
= Qnil
;
3354 /* If we squirreled away the buffer in the window's height,
3356 if (BUFFERP (w
->height
))
3357 w
->buffer
= w
->height
;
3360 w
->width
= p
->width
;
3361 w
->height
= p
->height
;
3362 w
->hscroll
= p
->hscroll
;
3363 w
->display_table
= p
->display_table
;
3364 XSETFASTINT (w
->last_modified
, 0);
3365 XSETFASTINT (w
->last_overlay_modified
, 0);
3367 /* Reinstall the saved buffer and pointers into it. */
3368 if (NILP (p
->buffer
))
3369 w
->buffer
= p
->buffer
;
3372 if (!NILP (XBUFFER (p
->buffer
)->name
))
3373 /* If saved buffer is alive, install it. */
3375 w
->buffer
= p
->buffer
;
3376 w
->start_at_line_beg
= p
->start_at_line_beg
;
3377 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
3378 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
3379 Fset_marker (XBUFFER (w
->buffer
)->mark
,
3380 p
->mark
, w
->buffer
);
3382 /* As documented in Fcurrent_window_configuration, don't
3383 save the location of point in the buffer which was current
3384 when the window configuration was recorded. */
3385 if (!EQ (p
->buffer
, new_current_buffer
)
3386 && XBUFFER (p
->buffer
) == current_buffer
)
3387 Fgoto_char (w
->pointm
);
3389 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
3390 /* Else unless window has a live buffer, get one. */
3392 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
3393 /* This will set the markers to beginning of visible
3395 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
3396 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
3397 w
->start_at_line_beg
= Qt
;
3400 /* Keeping window's old buffer; make sure the markers
3403 /* Set window markers at start of visible range. */
3404 if (XMARKER (w
->start
)->buffer
== 0)
3405 set_marker_restricted (w
->start
, make_number (0),
3407 if (XMARKER (w
->pointm
)->buffer
== 0)
3408 set_marker_restricted_both (w
->pointm
, w
->buffer
,
3409 BUF_PT (XBUFFER (w
->buffer
)),
3410 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
3411 w
->start_at_line_beg
= Qt
;
3416 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
3417 Fselect_window (data
->current_window
);
3418 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
3421 if (NILP (data
->focus_frame
)
3422 || (FRAMEP (data
->focus_frame
)
3423 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
3424 Fredirect_frame_focus (frame
, data
->focus_frame
);
3426 #if 0 /* I don't understand why this is needed, and it causes problems
3427 when the frame's old selected window has been deleted. */
3428 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
3429 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
3433 /* Set the screen height to the value it had before this function. */
3434 if (previous_frame_height
!= FRAME_HEIGHT (f
)
3435 || previous_frame_width
!= FRAME_WIDTH (f
))
3436 change_frame_size (f
, previous_frame_height
, previous_frame_width
,
3438 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
3439 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
3440 x_set_menu_bar_lines (f
, previous_frame_menu_bar_lines
, 0);
3446 /* Restore the minimum heights recorded in the configuration. */
3447 window_min_height
= XINT (data
->min_height
);
3448 window_min_width
= XINT (data
->min_width
);
3450 /* Fselect_window will have made f the selected frame, so we
3451 reselect the proper frame here. Fhandle_switch_frame will change the
3452 selected window too, but that doesn't make the call to
3453 Fselect_window above totally superfluous; it still sets f's
3455 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
3456 do_switch_frame (data
->selected_frame
, Qnil
, 0);
3458 if (!NILP (new_current_buffer
))
3460 Fset_buffer (new_current_buffer
);
3462 /* If the buffer that is current now is the same
3463 that was current before setting the window configuration,
3464 don't alter its PT. */
3469 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
3471 if (! NILP (Vwindow_configuration_change_hook
)
3472 && ! NILP (Vrun_hooks
))
3473 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3478 /* Mark all windows now on frame as deleted
3479 by setting their buffers to nil. */
3482 delete_all_subwindows (w
)
3483 register struct window
*w
;
3485 if (!NILP (w
->next
))
3486 delete_all_subwindows (XWINDOW (w
->next
));
3487 if (!NILP (w
->vchild
))
3488 delete_all_subwindows (XWINDOW (w
->vchild
));
3489 if (!NILP (w
->hchild
))
3490 delete_all_subwindows (XWINDOW (w
->hchild
));
3492 w
->height
= w
->buffer
; /* See Fset_window_configuration for excuse. */
3494 if (!NILP (w
->buffer
))
3497 /* We set all three of these fields to nil, to make sure that we can
3498 distinguish this dead window from any live window. Live leaf
3499 windows will have buffer set, and combination windows will have
3500 vchild or hchild set. */
3507 count_windows (window
)
3508 register struct window
*window
;
3510 register int count
= 1;
3511 if (!NILP (window
->next
))
3512 count
+= count_windows (XWINDOW (window
->next
));
3513 if (!NILP (window
->vchild
))
3514 count
+= count_windows (XWINDOW (window
->vchild
));
3515 if (!NILP (window
->hchild
))
3516 count
+= count_windows (XWINDOW (window
->hchild
));
3521 save_window_save (window
, vector
, i
)
3523 struct Lisp_Vector
*vector
;
3526 register struct saved_window
*p
;
3527 register struct window
*w
;
3528 register Lisp_Object tem
;
3530 for (;!NILP (window
); window
= w
->next
)
3532 p
= SAVED_WINDOW_N (vector
, i
);
3533 w
= XWINDOW (window
);
3535 XSETFASTINT (w
->temslot
, i
++);
3537 p
->buffer
= w
->buffer
;
3540 p
->width
= w
->width
;
3541 p
->height
= w
->height
;
3542 p
->hscroll
= w
->hscroll
;
3543 p
->display_table
= w
->display_table
;
3544 if (!NILP (w
->buffer
))
3546 /* Save w's value of point in the window configuration.
3547 If w is the selected window, then get the value of point
3548 from the buffer; pointm is garbage in the selected window. */
3549 if (EQ (window
, selected_window
))
3551 p
->pointm
= Fmake_marker ();
3552 set_marker_both (p
->pointm
, w
->buffer
,
3553 BUF_PT (XBUFFER (w
->buffer
)),
3554 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
3557 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
3559 p
->start
= Fcopy_marker (w
->start
, Qnil
);
3560 p
->start_at_line_beg
= w
->start_at_line_beg
;
3562 tem
= XBUFFER (w
->buffer
)->mark
;
3563 p
->mark
= Fcopy_marker (tem
, Qnil
);
3570 p
->start_at_line_beg
= Qnil
;
3573 if (NILP (w
->parent
))
3576 p
->parent
= XWINDOW (w
->parent
)->temslot
;
3581 p
->prev
= XWINDOW (w
->prev
)->temslot
;
3583 if (!NILP (w
->vchild
))
3584 i
= save_window_save (w
->vchild
, vector
, i
);
3585 if (!NILP (w
->hchild
))
3586 i
= save_window_save (w
->hchild
, vector
, i
);
3592 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
3593 Scurrent_window_configuration
, 0, 1, 0,
3594 "Return an object representing the current window configuration of FRAME.\n\
3595 If FRAME is nil or omitted, use the selected frame.\n\
3596 This describes the number of windows, their sizes and current buffers,\n\
3597 and for each displayed buffer, where display starts, and the positions of\n\
3598 point and mark. An exception is made for point in the current buffer:\n\
3599 its value is -not- saved.\n\
3600 This also records the currently selected frame, and FRAME's focus\n\
3601 redirection (see `redirect-frame-focus').")
3605 register Lisp_Object tem
;
3606 register int n_windows
;
3607 register struct save_window_data
*data
;
3608 register struct Lisp_Vector
*vec
;
3616 CHECK_LIVE_FRAME (frame
, 0);
3620 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3621 vec
= allocate_vectorlike (VECSIZE (struct save_window_data
));
3622 for (i
= 0; i
< VECSIZE (struct save_window_data
); i
++)
3623 vec
->contents
[i
] = Qnil
;
3624 vec
->size
= VECSIZE (struct save_window_data
);
3625 data
= (struct save_window_data
*)vec
;
3627 XSETFASTINT (data
->frame_width
, FRAME_WIDTH (f
));
3628 XSETFASTINT (data
->frame_height
, FRAME_HEIGHT (f
));
3629 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
3630 XSETFRAME (data
->selected_frame
, selected_frame
);
3631 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
3632 XSETBUFFER (data
->current_buffer
, current_buffer
);
3633 data
->minibuf_scroll_window
= Vminibuf_scroll_window
;
3634 data
->root_window
= FRAME_ROOT_WINDOW (f
);
3635 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
3636 XSETINT (data
->min_height
, window_min_height
);
3637 XSETINT (data
->min_width
, window_min_width
);
3638 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
3639 data
->saved_windows
= tem
;
3640 for (i
= 0; i
< n_windows
; i
++)
3641 XVECTOR (tem
)->contents
[i
]
3642 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
3643 save_window_save (FRAME_ROOT_WINDOW (f
),
3645 XSETWINDOW_CONFIGURATION (tem
, data
);
3649 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
3651 "Execute body, preserving window sizes and contents.\n\
3652 Restore which buffer appears in which window, where display starts,\n\
3653 and the value of point and mark for each window.\n\
3654 Also restore which buffer is current.\n\
3655 But do not preserve point in the current buffer.\n\
3656 Does not restore the value of point in current buffer.")
3660 register Lisp_Object val
;
3661 register int count
= specpdl_ptr
- specpdl
;
3663 record_unwind_protect (Fset_window_configuration
,
3664 Fcurrent_window_configuration (Qnil
));
3665 val
= Fprogn (args
);
3666 return unbind_to (count
, val
);
3669 /* Return 1 if window configurations C1 and C2
3670 describe the same state of affairs. This is used by Fequal. */
3673 compare_window_configurations (c1
, c2
)
3676 register struct save_window_data
*d1
, *d2
;
3677 struct Lisp_Vector
*sw1
, *sw2
;
3680 d1
= (struct save_window_data
*) XVECTOR (c1
);
3681 d2
= (struct save_window_data
*) XVECTOR (c2
);
3682 sw1
= XVECTOR (d1
->saved_windows
);
3683 sw2
= XVECTOR (d2
->saved_windows
);
3685 if (! EQ (d1
->frame_width
, d2
->frame_width
))
3687 if (! EQ (d1
->frame_height
, d2
->frame_height
))
3689 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
3691 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
3693 /* Don't compare the current_window field directly.
3694 Instead see w1_is_current and w2_is_current, below. */
3695 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
3697 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
3699 /* Don't compare the root_window field.
3700 We don't require the two configurations
3701 to use the same window object,
3702 and the two root windows must be equivalent
3703 if everything else compares equal. */
3704 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
3706 if (! EQ (d1
->min_width
, d2
->min_width
))
3708 if (! EQ (d1
->min_height
, d2
->min_height
))
3711 /* Verify that the two confis have the same number of windows. */
3712 if (sw1
->size
!= sw2
->size
)
3715 for (i
= 0; i
< sw1
->size
; i
++)
3717 struct saved_window
*p1
, *p2
;
3718 int w1_is_current
, w2_is_current
;
3720 p1
= SAVED_WINDOW_N (sw1
, i
);
3721 p2
= SAVED_WINDOW_N (sw2
, i
);
3723 /* Verify that the current windows in the two
3724 configurations correspond to each other. */
3725 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
3726 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
3728 if (w1_is_current
!= w2_is_current
)
3731 /* Verify that the corresponding windows do match. */
3732 if (! EQ (p1
->buffer
, p2
->buffer
))
3734 if (! EQ (p1
->left
, p2
->left
))
3736 if (! EQ (p1
->top
, p2
->top
))
3738 if (! EQ (p1
->width
, p2
->width
))
3740 if (! EQ (p1
->height
, p2
->height
))
3742 if (! EQ (p1
->hscroll
, p2
->hscroll
))
3744 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
3746 if (! EQ (p1
->display_table
, p2
->display_table
))
3748 if (! EQ (p1
->parent
, p2
->parent
))
3750 if (! EQ (p1
->prev
, p2
->prev
))
3752 if (NILP (Fequal (p1
->start
, p2
->start
)))
3754 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
3756 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
3765 selected_frame
= make_terminal_frame ();
3766 XSETFRAME (Vterminal_frame
, selected_frame
);
3767 minibuf_window
= selected_frame
->minibuffer_window
;
3768 selected_window
= selected_frame
->selected_window
;
3769 last_nonminibuf_frame
= selected_frame
;
3771 window_initialized
= 1;
3776 staticpro (&Qwindow_configuration_change_hook
);
3777 Qwindow_configuration_change_hook
3778 = intern ("window-configuration-change-hook");
3780 Qwindowp
= intern ("windowp");
3781 staticpro (&Qwindowp
);
3783 Qwindow_live_p
= intern ("window-live-p");
3784 staticpro (&Qwindow_live_p
);
3786 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
3787 staticpro (&Qtemp_buffer_show_hook
);
3789 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
3790 "Non-nil means call as function to display a help buffer.\n\
3791 The function is called with one argument, the buffer to be displayed.\n\
3792 Used by `with-output-to-temp-buffer'.\n\
3793 If this function is used, then it must do the entire job of showing\n\
3794 the buffer; `temp-buffer-show-hook' is not run unless this function runs it.");
3795 Vtemp_buffer_show_function
= Qnil
;
3797 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
3798 "If non-nil, function to call to handle `display-buffer'.\n\
3799 It will receive two args, the buffer and a flag which if non-nil means\n\
3800 that the currently selected window is not acceptable.\n\
3801 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\
3802 work using this function.");
3803 Vdisplay_buffer_function
= Qnil
;
3805 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
3806 "Non-nil means it is the window that C-M-v in minibuffer should scroll.");
3807 Vminibuf_scroll_window
= Qnil
;
3809 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
3810 "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.");
3811 Vother_window_scroll_buffer
= Qnil
;
3813 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
3814 "*Non-nil means `display-buffer' should make a separate frame.");
3817 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
3818 "Function to call to handle automatic new frame creation.\n\
3819 It is called with no arguments and should return a newly created frame.\n\
3821 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\
3822 where `pop-up-frame-alist' would hold the default frame parameters.");
3823 Vpop_up_frame_function
= Qnil
;
3825 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
3826 "*List of buffer names that should have their own special frames.\n\
3827 Displaying a buffer whose name is in this list makes a special frame for it\n\
3828 using `special-display-function'. See also `special-display-regexps'.\n\
3830 An element of the list can be a list instead of just a string.\n\
3831 There are two ways to use a list as an element:\n\
3832 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)\n\
3833 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
3834 In the latter case, FUNCTION is called with BUFFER as the first argument,\n\
3835 followed by OTHER-ARGS--it can display BUFFER in any way it likes.\n\
3836 All this is done by the function found in `special-display-function'.\n\
3838 If this variable appears \"not to work\", because you add a name to it\n\
3839 but that buffer still appears in the selected window, look at the\n\
3840 values of `same-window-buffer-names' and `same-window-regexps'.\n\
3841 Those variables take precedence over this one.");
3842 Vspecial_display_buffer_names
= Qnil
;
3844 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
3845 "*List of regexps saying which buffers should have their own special frames.\n\
3846 If a buffer name matches one of these regexps, it gets its own frame.\n\
3847 Displaying a buffer whose name is in this list makes a special frame for it\n\
3848 using `special-display-function'.\n\
3850 An element of the list can be a list instead of just a string.\n\
3851 There are two ways to use a list as an element:\n\
3852 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)\n\
3853 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
3854 In the latter case, FUNCTION is called with the buffer as first argument,\n\
3855 followed by OTHER-ARGS--it can display the buffer in any way it likes.\n\
3856 All this is done by the function found in `special-display-function'.\n\
3858 If this variable appears \"not to work\", because you add a regexp to it\n\
3859 but the matching buffers still appear in the selected window, look at the\n\
3860 values of `same-window-buffer-names' and `same-window-regexps'.\n\
3861 Those variables take precedence over this one.");
3862 Vspecial_display_regexps
= Qnil
;
3864 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
3865 "Function to call to make a new frame for a special buffer.\n\
3866 It is called with two arguments, the buffer and optional buffer specific\n\
3867 data, and should return a window displaying that buffer.\n\
3868 The default value makes a separate frame for the buffer,\n\
3869 using `special-display-frame-alist' to specify the frame parameters.\n\
3871 A buffer is special if its is listed in `special-display-buffer-names'\n\
3872 or matches a regexp in `special-display-regexps'.");
3873 Vspecial_display_function
= Qnil
;
3875 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
3876 "*List of buffer names that should appear in the selected window.\n\
3877 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'\n\
3878 switches to it in the selected window, rather than making it appear\n\
3879 in some other window.\n\
3881 An element of the list can be a cons cell instead of just a string.\n\
3882 Then the car must be a string, which specifies the buffer name.\n\
3883 This is for compatibility with `special-display-buffer-names';\n\
3884 the cdr of the cons cell is ignored.\n\
3886 See also `same-window-regexps'.");
3887 Vsame_window_buffer_names
= Qnil
;
3889 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
3890 "*List of regexps saying which buffers should appear in the selected window.\n\
3891 If a buffer name matches one of these regexps, then displaying it\n\
3892 using `display-buffer' or `pop-to-buffer' switches to it\n\
3893 in the selected window, rather than making it appear in some other window.\n\
3895 An element of the list can be a cons cell instead of just a string.\n\
3896 Then the car must be a string, which specifies the buffer name.\n\
3897 This is for compatibility with `special-display-buffer-names';\n\
3898 the cdr of the cons cell is ignored.\n\
3900 See also `same-window-buffer-names'.");
3901 Vsame_window_regexps
= Qnil
;
3903 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
3904 "*Non-nil means display-buffer should make new windows.");
3907 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
3908 "*Number of lines of continuity when scrolling by screenfuls.");
3909 next_screen_context_lines
= 2;
3911 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
3912 "*display-buffer would prefer to split the largest window if this large.\n\
3913 If there is only one window, it is split regardless of this value.");
3914 split_height_threshold
= 500;
3916 DEFVAR_INT ("window-min-height", &window_min_height
,
3917 "*Delete any window less than this tall (including its mode line).");
3918 window_min_height
= 4;
3920 DEFVAR_INT ("window-min-width", &window_min_width
,
3921 "*Delete any window less than this wide.");
3922 window_min_width
= 10;
3924 DEFVAR_BOOL ("scroll-preserve-screen-position",
3925 &scroll_preserve_screen_position
,
3926 "*Nonzero means scroll commands move point to keep its screen line unchanged.");
3927 scroll_preserve_screen_position
= 0;
3929 DEFVAR_LISP ("window-configuration-change-hook",
3930 &Vwindow_configuration_change_hook
,
3931 "Functions to call when window configuration changes.\n\
3932 The selected frame is the one whose configuration has changed.");
3933 Vwindow_configuration_change_hook
= Qnil
;
3935 defsubr (&Sselected_window
);
3936 defsubr (&Sminibuffer_window
);
3937 defsubr (&Swindow_minibuffer_p
);
3938 defsubr (&Swindowp
);
3939 defsubr (&Swindow_live_p
);
3940 defsubr (&Spos_visible_in_window_p
);
3941 defsubr (&Swindow_buffer
);
3942 defsubr (&Swindow_height
);
3943 defsubr (&Swindow_width
);
3944 defsubr (&Swindow_hscroll
);
3945 defsubr (&Sset_window_hscroll
);
3946 defsubr (&Swindow_redisplay_end_trigger
);
3947 defsubr (&Sset_window_redisplay_end_trigger
);
3948 defsubr (&Swindow_edges
);
3949 defsubr (&Scoordinates_in_window_p
);
3950 defsubr (&Swindow_at
);
3951 defsubr (&Swindow_point
);
3952 defsubr (&Swindow_start
);
3953 defsubr (&Swindow_end
);
3954 defsubr (&Sset_window_point
);
3955 defsubr (&Sset_window_start
);
3956 defsubr (&Swindow_dedicated_p
);
3957 defsubr (&Sset_window_dedicated_p
);
3958 defsubr (&Swindow_display_table
);
3959 defsubr (&Sset_window_display_table
);
3960 defsubr (&Snext_window
);
3961 defsubr (&Sprevious_window
);
3962 defsubr (&Sother_window
);
3963 defsubr (&Sget_lru_window
);
3964 defsubr (&Sget_largest_window
);
3965 defsubr (&Sget_buffer_window
);
3966 defsubr (&Sdelete_other_windows
);
3967 defsubr (&Sdelete_windows_on
);
3968 defsubr (&Sreplace_buffer_in_windows
);
3969 defsubr (&Sdelete_window
);
3970 defsubr (&Sset_window_buffer
);
3971 defsubr (&Sselect_window
);
3972 defsubr (&Sspecial_display_p
);
3973 defsubr (&Ssame_window_p
);
3974 defsubr (&Sdisplay_buffer
);
3975 defsubr (&Ssplit_window
);
3976 defsubr (&Senlarge_window
);
3977 defsubr (&Sshrink_window
);
3978 defsubr (&Sscroll_up
);
3979 defsubr (&Sscroll_down
);
3980 defsubr (&Sscroll_left
);
3981 defsubr (&Sscroll_right
);
3982 defsubr (&Sother_window_for_scrolling
);
3983 defsubr (&Sscroll_other_window
);
3984 defsubr (&Srecenter
);
3985 defsubr (&Smove_to_window_line
);
3986 defsubr (&Swindow_configuration_p
);
3987 defsubr (&Sset_window_configuration
);
3988 defsubr (&Scurrent_window_configuration
);
3989 defsubr (&Ssave_window_excursion
);
3994 initial_define_key (control_x_map
, '1', "delete-other-windows");
3995 initial_define_key (control_x_map
, '2', "split-window");
3996 initial_define_key (control_x_map
, '0', "delete-window");
3997 initial_define_key (control_x_map
, 'o', "other-window");
3998 initial_define_key (control_x_map
, '^', "enlarge-window");
3999 initial_define_key (control_x_map
, '<', "scroll-left");
4000 initial_define_key (control_x_map
, '>', "scroll-right");
4002 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
4003 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
4004 initial_define_key (meta_map
, 'v', "scroll-down");
4006 initial_define_key (global_map
, Ctl('L'), "recenter");
4007 initial_define_key (meta_map
, 'r', "move-to-window-line");