1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985, 86, 87, 93, 94, 95, 96 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. */
33 Lisp_Object Qwindowp
, Qwindow_live_p
;
35 Lisp_Object
Fnext_window (), Fdelete_window (), Fselect_window ();
36 Lisp_Object
Fset_window_buffer (), Fsplit_window (), Frecenter ();
38 void delete_all_subwindows ();
39 static struct window
*decode_window();
41 /* This is the window in which the terminal's cursor should
42 be left when nothing is being done with it. This must
43 always be a leaf window, and its buffer is selected by
44 the top level editing loop at the end of each command.
46 This value is always the same as
47 FRAME_SELECTED_WINDOW (selected_frame). */
49 Lisp_Object selected_window
;
51 /* The minibuffer window of the selected frame.
52 Note that you cannot test for minibufferness of an arbitrary window
53 by comparing against this; but you can test for minibufferness of
54 the selected window. */
55 Lisp_Object minibuf_window
;
57 /* Non-nil means it is the window for C-M-v to scroll
58 when the minibuffer is selected. */
59 Lisp_Object Vminibuf_scroll_window
;
61 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
62 Lisp_Object Vother_window_scroll_buffer
;
64 /* Non-nil means it's function to call to display temp buffers. */
65 Lisp_Object Vtemp_buffer_show_function
;
67 /* If a window gets smaller than either of these, it is removed. */
68 int window_min_height
;
71 /* Nonzero implies Fdisplay_buffer should create windows. */
74 /* Nonzero implies make new frames for Fdisplay_buffer. */
77 /* Non-nil means use this function instead of default */
78 Lisp_Object Vpop_up_frame_function
;
80 /* Function to call to handle Fdisplay_buffer. */
81 Lisp_Object Vdisplay_buffer_function
;
83 /* List of buffer *names* for buffers that should have their own frames. */
84 Lisp_Object Vspecial_display_buffer_names
;
86 /* List of regexps for buffer names that should have their own frames. */
87 Lisp_Object Vspecial_display_regexps
;
89 /* Function to pop up a special frame. */
90 Lisp_Object Vspecial_display_function
;
92 /* List of buffer *names* for buffers to appear in selected window. */
93 Lisp_Object Vsame_window_buffer_names
;
95 /* List of regexps for buffer names to appear in selected window. */
96 Lisp_Object Vsame_window_regexps
;
98 /* Hook run at end of temp_output_buffer_show. */
99 Lisp_Object Qtemp_buffer_show_hook
;
101 /* Fdisplay_buffer always splits the largest window
102 if that window is more than this high. */
103 int split_height_threshold
;
105 /* Number of lines of continuity in scrolling by screenfuls. */
106 int next_screen_context_lines
;
108 /* Incremented for each window created. */
109 static int sequence_number
;
111 /* Nonzero after init_window_once has finished. */
112 static int window_initialized
;
114 /* Hook to run when window config changes. */
115 Lisp_Object Qwindow_configuration_change_hook
;
116 Lisp_Object Vwindow_configuration_change_hook
;
118 /* Nonzero means scroll commands try to put point
119 at the same screen height as previously. */
120 static int scroll_preserve_screen_position
;
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. */
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
;
716 if (XBUFFER (buf
) != XMARKER (w
->pointm
)->buffer
)
719 if (w
== XWINDOW (XBUFFER (buf
)->last_selected_window
))
720 XBUFFER (buf
)->last_selected_window
= Qnil
;
723 if (w
== XWINDOW (selected_window
)
724 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
725 /* Do this except when the selected window's buffer
726 is being removed from some other window. */
728 /* last_window_start records the start position that this buffer
729 had in the last window to be disconnected from it.
730 Now that this statement is unconditional,
731 it is possible for the buffer to be displayed in the
732 selected window, while last_window_start reflects another
733 window which was recently showing the same buffer.
734 Some people might say that might be a good thing. Let's see. */
735 XBUFFER (buf
)->last_window_start
= marker_position (w
->start
);
737 /* Point in the selected window's buffer
738 is actually stored in that buffer, and the window's pointm isn't used.
739 So don't clobber point in that buffer. */
740 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
))
741 BUF_PT (XBUFFER (buf
))
742 = clip_to_bounds (BUF_BEGV (XBUFFER (buf
)),
743 marker_position (w
->pointm
),
744 BUF_ZV (XBUFFER (buf
)));
747 /* Put replacement into the window structure in place of old. */
749 replace_window (old
, replacement
)
750 Lisp_Object old
, replacement
;
752 register Lisp_Object tem
;
753 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
755 /* If OLD is its frame's root_window, then replacement is the new
756 root_window for that frame. */
758 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
759 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
764 p
->height
= o
->height
;
766 p
->next
= tem
= o
->next
;
768 XWINDOW (tem
)->prev
= replacement
;
770 p
->prev
= tem
= o
->prev
;
772 XWINDOW (tem
)->next
= replacement
;
774 p
->parent
= tem
= o
->parent
;
777 if (EQ (XWINDOW (tem
)->vchild
, old
))
778 XWINDOW (tem
)->vchild
= replacement
;
779 if (EQ (XWINDOW (tem
)->hchild
, old
))
780 XWINDOW (tem
)->hchild
= replacement
;
783 /*** Here, if replacement is a vertical combination
784 and so is its new parent, we should make replacement's
785 children be children of that parent instead. ***/
788 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
789 "Remove WINDOW from the display. Default is selected window.")
791 register Lisp_Object window
;
793 delete_window (window
);
795 if (! NILP (Vwindow_configuration_change_hook
)
796 && ! NILP (Vrun_hooks
))
797 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
802 delete_window (window
)
803 register Lisp_Object window
;
805 register Lisp_Object tem
, parent
, sib
;
806 register struct window
*p
;
807 register struct window
*par
;
809 /* Because this function is called by other C code on non-leaf
810 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
811 so we can't decode_window here. */
813 window
= selected_window
;
815 CHECK_WINDOW (window
, 0);
816 p
= XWINDOW (window
);
818 /* It's okay to delete an already-deleted window. */
826 error ("Attempt to delete minibuffer or sole ordinary window");
827 par
= XWINDOW (parent
);
829 windows_or_buffers_changed
++;
830 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (p
))) = 1;
832 /* Are we trying to delete any frame's selected window? */
834 Lisp_Object frame
, pwindow
;
836 /* See if the frame's selected window is either WINDOW
837 or any subwindow of it, by finding all that window's parents
838 and comparing each one with WINDOW. */
839 frame
= WINDOW_FRAME (XWINDOW (window
));
840 pwindow
= FRAME_SELECTED_WINDOW (XFRAME (frame
));
842 while (!NILP (pwindow
))
844 if (EQ (window
, pwindow
))
846 pwindow
= XWINDOW (pwindow
)->parent
;
849 if (EQ (window
, pwindow
))
851 Lisp_Object alternative
;
852 alternative
= Fnext_window (window
, Qlambda
, Qnil
);
854 /* If we're about to delete the selected window on the
855 selected frame, then we should use Fselect_window to select
856 the new window. On the other hand, if we're about to
857 delete the selected window on any other frame, we shouldn't do
858 anything but set the frame's selected_window slot. */
859 if (EQ (window
, selected_window
))
860 Fselect_window (alternative
);
862 FRAME_SELECTED_WINDOW (XFRAME (frame
)) = alternative
;
867 /* tem is null for dummy parent windows
868 (which have inferiors but not any contents themselves) */
872 unchain_marker (p
->pointm
);
873 unchain_marker (p
->start
);
878 XWINDOW (tem
)->prev
= p
->prev
;
882 XWINDOW (tem
)->next
= p
->next
;
884 if (EQ (window
, par
->hchild
))
885 par
->hchild
= p
->next
;
886 if (EQ (window
, par
->vchild
))
887 par
->vchild
= p
->next
;
889 /* Find one of our siblings to give our space to. */
893 /* If p gives its space to its next sibling, that sibling needs
894 to have its top/left side pulled back to where p's is.
895 set_window_{height,width} will re-position the sibling's
898 XWINDOW (sib
)->top
= p
->top
;
899 XWINDOW (sib
)->left
= p
->left
;
902 /* Stretch that sibling. */
903 if (!NILP (par
->vchild
))
904 set_window_height (sib
,
905 XFASTINT (XWINDOW (sib
)->height
) + XFASTINT (p
->height
),
907 if (!NILP (par
->hchild
))
908 set_window_width (sib
,
909 XFASTINT (XWINDOW (sib
)->width
) + XFASTINT (p
->width
),
912 /* If parent now has only one child,
913 put the child into the parent's place. */
917 if (NILP (XWINDOW (tem
)->next
))
918 replace_window (parent
, tem
);
920 /* Since we may be deleting combination windows, we must make sure that
921 not only p but all its children have been marked as deleted. */
922 if (! NILP (p
->hchild
))
923 delete_all_subwindows (XWINDOW (p
->hchild
));
924 else if (! NILP (p
->vchild
))
925 delete_all_subwindows (XWINDOW (p
->vchild
));
927 /* Mark this window as deleted. */
928 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
932 extern Lisp_Object
next_frame (), prev_frame ();
934 /* This comment supplies the doc string for `next-window',
935 for make-docfile to see. We cannot put this in the real DEFUN
936 due to limits in the Unix cpp.
938 DEFUN ("next-window", Ffoo, Sfoo, 0, 3, 0,
939 "Return next window after WINDOW in canonical ordering of windows.\n\
940 If omitted, WINDOW defaults to the selected window.\n\
942 Optional second arg MINIBUF t means count the minibuffer window even\n\
943 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
944 it is active. MINIBUF neither t nor nil means not to count the\n\
945 minibuffer even if it is active.\n\
947 Several frames may share a single minibuffer; if the minibuffer\n\
948 counts, all windows on all frames that share that minibuffer count\n\
949 too. Therefore, `next-window' can be used to iterate through the\n\
950 set of windows even when the minibuffer is on another frame. If the\n\
951 minibuffer does not count, only windows from WINDOW's frame count.\n\
953 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
954 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
955 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
956 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
957 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
958 Anything else means restrict to WINDOW's frame.\n\
960 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
961 `next-window' to iterate through the entire cycle of acceptable\n\
962 windows, eventually ending up back at the window you started with.\n\
963 `previous-window' traverses the same cycle, in the reverse order.")
964 (window, minibuf, all_frames) */
966 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
968 (window
, minibuf
, all_frames
)
969 register Lisp_Object window
, minibuf
, all_frames
;
971 register Lisp_Object tem
;
972 Lisp_Object start_window
;
975 window
= selected_window
;
977 CHECK_LIVE_WINDOW (window
, 0);
979 start_window
= window
;
981 /* minibuf == nil may or may not include minibuffers.
982 Decide if it does. */
984 minibuf
= (minibuf_level
? minibuf_window
: Qlambda
);
985 else if (! EQ (minibuf
, Qt
))
987 /* Now minibuf can be t => count all minibuffer windows,
988 lambda => count none of them,
989 or a specific minibuffer window (the active one) to count. */
991 /* all_frames == nil doesn't specify which frames to include. */
992 if (NILP (all_frames
))
993 all_frames
= (! EQ (minibuf
, Qlambda
)
994 ? (FRAME_MINIBUF_WINDOW
997 (XWINDOW (window
)))))
999 else if (EQ (all_frames
, Qvisible
))
1001 else if (XFASTINT (all_frames
) == 0)
1003 else if (FRAMEP (all_frames
) && ! EQ (all_frames
, Fwindow_frame (window
)))
1004 /* If all_frames is a frame and window arg isn't on that frame, just
1005 return the first window on the frame. */
1006 return Fframe_first_window (all_frames
);
1007 else if (! EQ (all_frames
, Qt
))
1009 /* Now all_frames is t meaning search all frames,
1010 nil meaning search just current frame,
1011 visible meaning search just visible frames,
1012 0 meaning search visible and iconified frames,
1013 or a window, meaning search the frame that window belongs to. */
1015 /* Do this loop at least once, to get the next window, and perhaps
1016 again, if we hit the minibuffer and that is not acceptable. */
1019 /* Find a window that actually has a next one. This loop
1020 climbs up the tree. */
1021 while (tem
= XWINDOW (window
)->next
, NILP (tem
))
1022 if (tem
= XWINDOW (window
)->parent
, !NILP (tem
))
1026 /* We've reached the end of this frame.
1027 Which other frames are acceptable? */
1028 tem
= WINDOW_FRAME (XWINDOW (window
));
1029 if (! NILP (all_frames
))
1034 tem
= next_frame (tem
, all_frames
);
1035 /* In the case where the minibuffer is active,
1036 and we include its frame as well as the selected one,
1037 next_frame may get stuck in that frame.
1038 If that happens, go back to the selected frame
1039 so we can complete the cycle. */
1041 XSETFRAME (tem
, selected_frame
);
1043 tem
= FRAME_ROOT_WINDOW (XFRAME (tem
));
1050 /* If we're in a combination window, find its first child and
1051 recurse on that. Otherwise, we've found the window we want. */
1054 if (!NILP (XWINDOW (window
)->hchild
))
1055 window
= XWINDOW (window
)->hchild
;
1056 else if (!NILP (XWINDOW (window
)->vchild
))
1057 window
= XWINDOW (window
)->vchild
;
1061 /* Which windows are acceptable?
1062 Exit the loop and accept this window if
1063 this isn't a minibuffer window,
1064 or we're accepting all minibuffer windows,
1065 or this is the active minibuffer and we are accepting that one, or
1066 we've come all the way around and we're back at the original window. */
1067 while (MINI_WINDOW_P (XWINDOW (window
))
1068 && ! EQ (minibuf
, Qt
)
1069 && ! EQ (minibuf
, window
)
1070 && ! EQ (window
, start_window
));
1075 /* This comment supplies the doc string for `previous-window',
1076 for make-docfile to see. We cannot put this in the real DEFUN
1077 due to limits in the Unix cpp.
1079 DEFUN ("previous-window", Ffoo, Sfoo, 0, 3, 0,
1080 "Return the window preceding WINDOW in canonical ordering of windows.\n\
1081 If omitted, WINDOW defaults to the selected window.\n\
1083 Optional second arg MINIBUF t means count the minibuffer window even\n\
1084 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1085 it is active. MINIBUF neither t nor nil means not to count the\n\
1086 minibuffer even if it is active.\n\
1088 Several frames may share a single minibuffer; if the minibuffer\n\
1089 counts, all windows on all frames that share that minibuffer count\n\
1090 too. Therefore, `previous-window' can be used to iterate through\n\
1091 the set of windows even when the minibuffer is on another frame. If\n\
1092 the minibuffer does not count, only windows from WINDOW's frame count\n\
1094 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1095 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1096 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1097 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1098 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1099 Anything else means restrict to WINDOW's frame.\n\
1101 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1102 `previous-window' to iterate through the entire cycle of acceptable\n\
1103 windows, eventually ending up back at the window you started with.\n\
1104 `next-window' traverses the same cycle, in the reverse order.")
1105 (window, minibuf, all_frames) */
1108 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1110 (window
, minibuf
, all_frames
)
1111 register Lisp_Object window
, minibuf
, all_frames
;
1113 register Lisp_Object tem
;
1114 Lisp_Object start_window
;
1117 window
= selected_window
;
1119 CHECK_LIVE_WINDOW (window
, 0);
1121 start_window
= window
;
1123 /* minibuf == nil may or may not include minibuffers.
1124 Decide if it does. */
1126 minibuf
= (minibuf_level
? minibuf_window
: Qlambda
);
1127 else if (! EQ (minibuf
, Qt
))
1129 /* Now minibuf can be t => count all minibuffer windows,
1130 lambda => count none of them,
1131 or a specific minibuffer window (the active one) to count. */
1133 /* all_frames == nil doesn't specify which frames to include.
1134 Decide which frames it includes. */
1135 if (NILP (all_frames
))
1136 all_frames
= (! EQ (minibuf
, Qlambda
)
1137 ? (FRAME_MINIBUF_WINDOW
1140 (XWINDOW (window
)))))
1142 else if (EQ (all_frames
, Qvisible
))
1144 else if (XFASTINT (all_frames
) == 0)
1146 else if (FRAMEP (all_frames
) && ! EQ (all_frames
, Fwindow_frame (window
)))
1147 /* If all_frames is a frame and window arg isn't on that frame, just
1148 return the first window on the frame. */
1149 return Fframe_first_window (all_frames
);
1150 else if (! EQ (all_frames
, Qt
))
1152 /* Now all_frames is t meaning search all frames,
1153 nil meaning search just current frame,
1154 visible meaning search just visible frames,
1155 0 meaning search visible and iconified frames,
1156 or a window, meaning search the frame that window belongs to. */
1158 /* Do this loop at least once, to get the previous window, and perhaps
1159 again, if we hit the minibuffer and that is not acceptable. */
1162 /* Find a window that actually has a previous one. This loop
1163 climbs up the tree. */
1164 while (tem
= XWINDOW (window
)->prev
, NILP (tem
))
1165 if (tem
= XWINDOW (window
)->parent
, !NILP (tem
))
1169 /* We have found the top window on the frame.
1170 Which frames are acceptable? */
1171 tem
= WINDOW_FRAME (XWINDOW (window
));
1172 if (! NILP (all_frames
))
1173 /* It's actually important that we use prev_frame here,
1174 rather than next_frame. All the windows acceptable
1175 according to the given parameters should form a ring;
1176 Fnext_window and Fprevious_window should go back and
1177 forth around the ring. If we use next_frame here,
1178 then Fnext_window and Fprevious_window take different
1179 paths through the set of acceptable windows.
1180 window_loop assumes that these `ring' requirement are
1186 tem
= prev_frame (tem
, all_frames
);
1187 /* In the case where the minibuffer is active,
1188 and we include its frame as well as the selected one,
1189 next_frame may get stuck in that frame.
1190 If that happens, go back to the selected frame
1191 so we can complete the cycle. */
1193 XSETFRAME (tem
, selected_frame
);
1195 /* If this frame has a minibuffer, find that window first,
1196 because it is conceptually the last window in that frame. */
1197 if (FRAME_HAS_MINIBUF_P (XFRAME (tem
)))
1198 tem
= FRAME_MINIBUF_WINDOW (XFRAME (tem
));
1200 tem
= FRAME_ROOT_WINDOW (XFRAME (tem
));
1206 /* If we're in a combination window, find its last child and
1207 recurse on that. Otherwise, we've found the window we want. */
1210 if (!NILP (XWINDOW (window
)->hchild
))
1211 window
= XWINDOW (window
)->hchild
;
1212 else if (!NILP (XWINDOW (window
)->vchild
))
1213 window
= XWINDOW (window
)->vchild
;
1215 while (tem
= XWINDOW (window
)->next
, !NILP (tem
))
1219 /* Which windows are acceptable?
1220 Exit the loop and accept this window if
1221 this isn't a minibuffer window,
1222 or we're accepting all minibuffer windows,
1223 or this is the active minibuffer and we are accepting that one, or
1224 we've come all the way around and we're back at the original window. */
1225 while (MINI_WINDOW_P (XWINDOW (window
))
1226 && ! EQ (minibuf
, Qt
)
1227 && ! EQ (minibuf
, window
)
1228 && ! EQ (window
, start_window
));
1233 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1234 "Select the ARG'th different window on this frame.\n\
1235 All windows on current frame are arranged in a cyclic order.\n\
1236 This command selects the window ARG steps away in that order.\n\
1237 A negative ARG moves in the opposite order. If the optional second\n\
1238 argument ALL_FRAMES is non-nil, cycle through all frames.")
1240 register Lisp_Object arg
, all_frames
;
1243 register Lisp_Object w
;
1245 CHECK_NUMBER (arg
, 0);
1246 w
= selected_window
;
1251 w
= Fnext_window (w
, Qnil
, all_frames
);
1256 w
= Fprevious_window (w
, Qnil
, all_frames
);
1263 /* Look at all windows, performing an operation specified by TYPE
1265 If FRAMES is Qt, look at all frames;
1266 Qnil, look at just the selected frame;
1267 Qvisible, look at visible frames;
1268 a frame, just look at windows on that frame.
1269 If MINI is non-zero, perform the operation on minibuffer windows too.
1275 GET_BUFFER_WINDOW
, /* Arg is buffer */
1276 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1277 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1278 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1280 UNSHOW_BUFFER
/* Arg is buffer */
1284 window_loop (type
, obj
, mini
, frames
)
1285 enum window_loop type
;
1286 register Lisp_Object obj
, frames
;
1289 register Lisp_Object w
;
1290 register Lisp_Object best_window
;
1291 register Lisp_Object next_window
;
1292 register Lisp_Object last_window
;
1294 Lisp_Object frame_arg
;
1297 /* If we're only looping through windows on a particular frame,
1298 frame points to that frame. If we're looping through windows
1299 on all frames, frame is 0. */
1300 if (FRAMEP (frames
))
1301 frame
= XFRAME (frames
);
1302 else if (NILP (frames
))
1303 frame
= selected_frame
;
1307 frame_arg
= Qlambda
;
1308 else if (XFASTINT (frames
) == 0)
1310 else if (EQ (frames
, Qvisible
))
1313 /* frame_arg is Qlambda to stick to one frame,
1314 Qvisible to consider all visible frames,
1317 /* Pick a window to start with. */
1321 w
= FRAME_SELECTED_WINDOW (frame
);
1323 w
= FRAME_SELECTED_WINDOW (selected_frame
);
1325 /* Figure out the last window we're going to mess with. Since
1326 Fnext_window, given the same options, is guaranteed to go in a
1327 ring, we can just use Fprevious_window to find the last one.
1329 We can't just wait until we hit the first window again, because
1330 it might be deleted. */
1332 last_window
= Fprevious_window (w
, mini
? Qt
: Qnil
, frame_arg
);
1337 FRAME_PTR w_frame
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1339 /* Pick the next window now, since some operations will delete
1340 the current window. */
1341 next_window
= Fnext_window (w
, mini
? Qt
: Qnil
, frame_arg
);
1343 /* Note that we do not pay attention here to whether
1344 the frame is visible, since Fnext_window skips non-visible frames
1345 if that is desired, under the control of frame_arg. */
1346 if (! MINI_WINDOW_P (XWINDOW (w
))
1347 || (mini
&& minibuf_level
> 0))
1350 case GET_BUFFER_WINDOW
:
1351 if (XBUFFER (XWINDOW (w
)->buffer
) == XBUFFER (obj
)
1352 /* Don't find any minibuffer window
1353 except the one that is currently in use. */
1354 && (MINI_WINDOW_P (XWINDOW (w
))
1355 ? EQ (w
, minibuf_window
) : 1))
1359 case GET_LRU_WINDOW
:
1360 /* t as arg means consider only full-width windows */
1361 if (!NILP (obj
) && !WINDOW_FULL_WIDTH_P (XWINDOW (w
)))
1363 /* Ignore dedicated windows and minibuffers. */
1364 if (MINI_WINDOW_P (XWINDOW (w
))
1365 || !NILP (XWINDOW (w
)->dedicated
))
1367 if (NILP (best_window
)
1368 || (XFASTINT (XWINDOW (best_window
)->use_time
)
1369 > XFASTINT (XWINDOW (w
)->use_time
)))
1373 case DELETE_OTHER_WINDOWS
:
1374 if (XWINDOW (w
) != XWINDOW (obj
))
1378 case DELETE_BUFFER_WINDOWS
:
1379 if (EQ (XWINDOW (w
)->buffer
, obj
))
1381 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1383 /* If this window is dedicated, and in a frame of its own,
1385 if (EQ (w
, FRAME_ROOT_WINDOW (f
))
1386 && !NILP (XWINDOW (w
)->dedicated
)
1387 && other_visible_frames (f
))
1389 /* Skip the other windows on this frame.
1390 There might be one, the minibuffer! */
1391 if (! EQ (w
, last_window
))
1392 while (f
== XFRAME (WINDOW_FRAME (XWINDOW (next_window
))))
1394 /* As we go, check for the end of the loop.
1395 We mustn't start going around a second time. */
1396 if (EQ (next_window
, last_window
))
1401 next_window
= Fnext_window (next_window
,
1405 /* Now we can safely delete the frame. */
1406 Fdelete_frame (WINDOW_FRAME (XWINDOW (w
)), Qnil
);
1409 /* If we're deleting the buffer displayed in the only window
1410 on the frame, find a new buffer to display there. */
1411 if (NILP (XWINDOW (w
)->parent
))
1413 Lisp_Object new_buffer
;
1414 new_buffer
= Fother_buffer (obj
, Qnil
);
1415 if (NILP (new_buffer
))
1417 = Fget_buffer_create (build_string ("*scratch*"));
1418 Fset_window_buffer (w
, new_buffer
);
1419 if (EQ (w
, selected_window
))
1420 Fset_buffer (XWINDOW (w
)->buffer
);
1427 case GET_LARGEST_WINDOW
:
1428 /* Ignore dedicated windows and minibuffers. */
1429 if (MINI_WINDOW_P (XWINDOW (w
))
1430 || !NILP (XWINDOW (w
)->dedicated
))
1433 struct window
*best_window_ptr
= XWINDOW (best_window
);
1434 struct window
*w_ptr
= XWINDOW (w
);
1435 if (NILP (best_window
)
1436 || (XFASTINT (w_ptr
->height
) * XFASTINT (w_ptr
->width
)
1437 > (XFASTINT (best_window_ptr
->height
)
1438 * XFASTINT (best_window_ptr
->width
))))
1444 if (EQ (XWINDOW (w
)->buffer
, obj
))
1446 /* Find another buffer to show in this window. */
1447 Lisp_Object another_buffer
;
1448 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1449 another_buffer
= Fother_buffer (obj
, Qnil
);
1450 if (NILP (another_buffer
))
1452 = Fget_buffer_create (build_string ("*scratch*"));
1453 /* If this window is dedicated, and in a frame of its own,
1455 if (EQ (w
, FRAME_ROOT_WINDOW (f
))
1456 && !NILP (XWINDOW (w
)->dedicated
)
1457 && other_visible_frames (f
))
1459 /* Skip the other windows on this frame.
1460 There might be one, the minibuffer! */
1461 if (! EQ (w
, last_window
))
1462 while (f
== XFRAME (WINDOW_FRAME (XWINDOW (next_window
))))
1464 /* As we go, check for the end of the loop.
1465 We mustn't start going around a second time. */
1466 if (EQ (next_window
, last_window
))
1471 next_window
= Fnext_window (next_window
,
1475 /* Now we can safely delete the frame. */
1476 Fdelete_frame (WINDOW_FRAME (XWINDOW (w
)), Qnil
);
1480 /* Otherwise show a different buffer in the window. */
1481 XWINDOW (w
)->dedicated
= Qnil
;
1482 Fset_window_buffer (w
, another_buffer
);
1483 if (EQ (w
, selected_window
))
1484 Fset_buffer (XWINDOW (w
)->buffer
);
1490 if (EQ (w
, last_window
))
1499 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 1, 0,
1500 "Return the window least recently selected or used for display.\n\
1501 If optional argument FRAME is `visible', search all visible frames.\n\
1502 If FRAME is 0, search all visible and iconified frames.\n\
1503 If FRAME is t, search all frames.\n\
1504 If FRAME is nil, search only the selected frame.\n\
1505 If FRAME is a frame, search only that frame.")
1509 register Lisp_Object w
;
1510 /* First try for a window that is full-width */
1511 w
= window_loop (GET_LRU_WINDOW
, Qt
, 0, frame
);
1512 if (!NILP (w
) && !EQ (w
, selected_window
))
1514 /* If none of them, try the rest */
1515 return window_loop (GET_LRU_WINDOW
, Qnil
, 0, frame
);
1518 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 1, 0,
1519 "Return the largest window in area.\n\
1520 If optional argument FRAME is `visible', search all visible frames.\n\
1521 If FRAME is 0, search all visible and iconified frames.\n\
1522 If FRAME is t, search all frames.\n\
1523 If FRAME is nil, search only the selected frame.\n\
1524 If FRAME is a frame, search only that frame.")
1528 return window_loop (GET_LARGEST_WINDOW
, Qnil
, 0,
1532 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
1533 "Return a window currently displaying BUFFER, or nil if none.\n\
1534 If optional argument FRAME is `visible', search all visible frames.\n\
1535 If optional argument FRAME is 0, search all visible and iconified frames.\n\
1536 If FRAME is t, search all frames.\n\
1537 If FRAME is nil, search only the selected frame.\n\
1538 If FRAME is a frame, search only that frame.")
1540 Lisp_Object buffer
, frame
;
1542 buffer
= Fget_buffer (buffer
);
1543 if (BUFFERP (buffer
))
1544 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
1549 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
1551 "Make WINDOW (or the selected window) fill its frame.\n\
1552 Only the frame WINDOW is on is affected.\n\
1553 This function tries to reduce display jumps\n\
1554 by keeping the text previously visible in WINDOW\n\
1555 in the same place on the frame. Doing this depends on\n\
1556 the value of (window-start WINDOW), so if calling this function\n\
1557 in a program gives strange scrolling, make sure the window-start\n\
1558 value is reasonable when this function is called.")
1567 window
= selected_window
;
1569 CHECK_LIVE_WINDOW (window
, 0);
1571 w
= XWINDOW (window
);
1573 startpos
= marker_position (w
->start
);
1574 top
= XFASTINT (w
->top
) - FRAME_MENU_BAR_LINES (XFRAME (WINDOW_FRAME (w
)));
1576 if (MINI_WINDOW_P (w
) && top
> 0)
1577 error ("Can't expand minibuffer to full frame");
1579 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
1581 /* Try to minimize scrolling, by setting the window start to the point
1582 will cause the text at the old window start to be at the same place
1583 on the frame. But don't try to do this if the window start is
1584 outside the visible portion (as might happen when the display is
1585 not current, due to typeahead). */
1586 if (startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
1587 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
1589 struct position pos
;
1590 struct buffer
*obuf
= current_buffer
;
1592 Fset_buffer (w
->buffer
);
1593 /* This computation used to temporarily move point, but that can
1594 have unwanted side effects due to text properties. */
1595 pos
= *vmotion (startpos
, -top
, w
);
1597 Fset_marker (w
->start
, make_number (pos
.bufpos
), w
->buffer
);
1598 w
->start_at_line_beg
= ((pos
.bufpos
== BEGV
1599 || FETCH_BYTE (pos
.bufpos
- 1) == '\n') ? Qt
1601 /* We need to do this, so that the window-scroll-functions
1603 w
->optional_new_start
= Qt
;
1605 set_buffer_internal (obuf
);
1610 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
1611 1, 2, "bDelete windows on (buffer): ",
1612 "Delete all windows showing BUFFER.\n\
1613 Optional second argument FRAME controls which frames are affected.\n\
1614 If nil or omitted, delete all windows showing BUFFER in any frame.\n\
1615 If t, delete only windows showing BUFFER in the selected frame.\n\
1616 If `visible', delete all windows showing BUFFER in any visible frame.\n\
1617 If a frame, delete only windows showing BUFFER in that frame.")
1619 Lisp_Object buffer
, frame
;
1621 /* FRAME uses t and nil to mean the opposite of what window_loop
1623 if (! FRAMEP (frame
))
1624 frame
= NILP (frame
) ? Qt
: Qnil
;
1628 buffer
= Fget_buffer (buffer
);
1629 CHECK_BUFFER (buffer
, 0);
1630 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
1635 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
1636 Sreplace_buffer_in_windows
,
1637 1, 1, "bReplace buffer in windows: ",
1638 "Replace BUFFER with some other buffer in all windows showing it.")
1644 buffer
= Fget_buffer (buffer
);
1645 CHECK_BUFFER (buffer
, 0);
1646 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
1651 /* Replace BUFFER with some other buffer in all windows
1652 of all frames, even those on other keyboards. */
1655 replace_buffer_in_all_windows (buffer
)
1659 Lisp_Object tail
, frame
;
1661 /* A single call to window_loop won't do the job
1662 because it only considers frames on the current keyboard.
1663 So loop manually over frames, and handle each one. */
1664 FOR_EACH_FRAME (tail
, frame
)
1665 window_loop (UNSHOW_BUFFER
, buffer
, 0, frame
);
1667 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
1671 /* Set the height of WINDOW and all its inferiors. */
1673 /* The smallest acceptable dimensions for a window. Anything smaller
1674 might crash Emacs. */
1675 #define MIN_SAFE_WINDOW_WIDTH (2)
1676 #define MIN_SAFE_WINDOW_HEIGHT (2)
1678 /* Make sure that window_min_height and window_min_width are
1679 not too small; if they are, set them to safe minima. */
1682 check_min_window_sizes ()
1684 /* Smaller values might permit a crash. */
1685 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
1686 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
1687 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
1688 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
1691 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
1692 minimum allowable size. */
1694 check_frame_size (frame
, rows
, cols
)
1698 /* For height, we have to see:
1699 whether the frame has a minibuffer,
1700 whether it wants a mode line, and
1701 whether it has a menu bar. */
1703 (FRAME_MINIBUF_ONLY_P (frame
) ? MIN_SAFE_WINDOW_HEIGHT
- 1
1704 : (! FRAME_HAS_MINIBUF_P (frame
)) ? MIN_SAFE_WINDOW_HEIGHT
1705 : 2 * MIN_SAFE_WINDOW_HEIGHT
- 1);
1706 if (FRAME_MENU_BAR_LINES (frame
) > 0)
1707 min_height
+= FRAME_MENU_BAR_LINES (frame
);
1709 if (*rows
< min_height
)
1711 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
1712 *cols
= MIN_SAFE_WINDOW_WIDTH
;
1715 /* Normally the window is deleted if it gets too small.
1716 nodelete nonzero means do not do this.
1717 (The caller should check later and do so if appropriate) */
1719 set_window_height (window
, height
, nodelete
)
1724 register struct window
*w
= XWINDOW (window
);
1725 register struct window
*c
;
1726 int oheight
= XFASTINT (w
->height
);
1727 int top
, pos
, lastbot
, opos
, lastobot
;
1730 check_min_window_sizes ();
1733 && ! NILP (w
->parent
)
1734 && height
< window_min_height
)
1736 delete_window (window
);
1740 XSETFASTINT (w
->last_modified
, 0);
1741 XSETFASTINT (w
->last_overlay_modified
, 0);
1742 windows_or_buffers_changed
++;
1743 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
1745 XSETFASTINT (w
->height
, height
);
1746 if (!NILP (w
->hchild
))
1748 for (child
= w
->hchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1750 XWINDOW (child
)->top
= w
->top
;
1751 set_window_height (child
, height
, nodelete
);
1754 else if (!NILP (w
->vchild
))
1756 lastbot
= top
= XFASTINT (w
->top
);
1758 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
1760 c
= XWINDOW (child
);
1762 opos
= lastobot
+ XFASTINT (c
->height
);
1764 XSETFASTINT (c
->top
, lastbot
);
1766 pos
= (((opos
* height
) << 1) + oheight
) / (oheight
<< 1);
1768 /* Avoid confusion: inhibit deletion of child if becomes too small */
1769 set_window_height (child
, pos
+ top
- lastbot
, 1);
1771 /* Now advance child to next window,
1772 and set lastbot if child was not just deleted. */
1773 lastbot
= pos
+ top
;
1776 /* Now delete any children that became too small. */
1778 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1780 set_window_height (child
, XINT (XWINDOW (child
)->height
), 0);
1785 /* Recursively set width of WINDOW and its inferiors. */
1787 set_window_width (window
, width
, nodelete
)
1792 register struct window
*w
= XWINDOW (window
);
1793 register struct window
*c
;
1794 int owidth
= XFASTINT (w
->width
);
1795 int left
, pos
, lastright
, opos
, lastoright
;
1798 if (!nodelete
&& width
< window_min_width
&& !NILP (w
->parent
))
1800 delete_window (window
);
1804 XSETFASTINT (w
->last_modified
, 0);
1805 XSETFASTINT (w
->last_overlay_modified
, 0);
1806 windows_or_buffers_changed
++;
1807 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
1809 XSETFASTINT (w
->width
, width
);
1810 if (!NILP (w
->vchild
))
1812 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1814 XWINDOW (child
)->left
= w
->left
;
1815 set_window_width (child
, width
, nodelete
);
1818 else if (!NILP (w
->hchild
))
1820 lastright
= left
= XFASTINT (w
->left
);
1822 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
1824 c
= XWINDOW (child
);
1826 opos
= lastoright
+ XFASTINT (c
->width
);
1828 XSETFASTINT (c
->left
, lastright
);
1830 pos
= (((opos
* width
) << 1) + owidth
) / (owidth
<< 1);
1832 /* Inhibit deletion for becoming too small */
1833 set_window_width (child
, pos
+ left
- lastright
, 1);
1835 /* Now advance child to next window,
1836 and set lastright if child was not just deleted. */
1837 lastright
= pos
+ left
, lastoright
= opos
;
1839 /* Delete children that became too small */
1841 for (child
= w
->hchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1843 set_window_width (child
, XINT (XWINDOW (child
)->width
), 0);
1848 int window_select_count
;
1851 Fset_window_buffer_unwind (obuf
)
1858 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 2, 0,
1859 "Make WINDOW display BUFFER as its contents.\n\
1860 BUFFER can be a buffer or buffer name.")
1862 register Lisp_Object window
, buffer
;
1864 register Lisp_Object tem
;
1865 register struct window
*w
= decode_window (window
);
1866 int count
= specpdl_ptr
- specpdl
;
1868 buffer
= Fget_buffer (buffer
);
1869 CHECK_BUFFER (buffer
, 1);
1871 if (NILP (XBUFFER (buffer
)->name
))
1872 error ("Attempt to display deleted buffer");
1876 error ("Window is deleted");
1877 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
1878 is first being set up. */
1880 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
1881 error ("Window is dedicated to `%s'",
1882 XSTRING (XBUFFER (tem
)->name
)->data
);
1889 if (EQ (window
, selected_window
))
1890 XBUFFER (w
->buffer
)->last_selected_window
= window
;
1891 if (INTEGERP (XBUFFER (buffer
)->display_count
))
1892 XSETINT (XBUFFER (buffer
)->display_count
,
1893 XINT (XBUFFER (buffer
)->display_count
) + 1);
1895 XSETFASTINT (w
->window_end_pos
, 0);
1896 w
->window_end_valid
= Qnil
;
1897 XSETFASTINT (w
->hscroll
, 0);
1898 Fset_marker (w
->pointm
,
1899 make_number (BUF_PT (XBUFFER (buffer
))),
1901 set_marker_restricted (w
->start
,
1902 make_number (XBUFFER (buffer
)->last_window_start
),
1904 w
->start_at_line_beg
= Qnil
;
1905 w
->force_start
= Qnil
;
1906 XSETFASTINT (w
->last_modified
, 0);
1907 XSETFASTINT (w
->last_overlay_modified
, 0);
1908 windows_or_buffers_changed
++;
1910 /* We must select BUFFER for running the window-scroll-functions.
1911 If WINDOW is selected, switch permanently.
1912 Otherwise, switch but go back to the ambient buffer afterward. */
1913 if (EQ (window
, selected_window
))
1914 Fset_buffer (buffer
);
1915 /* We can't check ! NILP (Vwindow_scroll_functions) here
1916 because that might itself be a local variable. */
1917 else if (window_initialized
)
1919 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
1920 Fset_buffer (buffer
);
1923 if (! NILP (Vwindow_scroll_functions
))
1924 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1925 Fmarker_position (w
->start
));
1927 if (! NILP (Vwindow_configuration_change_hook
)
1928 && ! NILP (Vrun_hooks
))
1929 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
1931 unbind_to (count
, Qnil
);
1936 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 1, 0,
1937 "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\
1938 The main editor command loop selects the buffer of the selected window\n\
1939 before each command.")
1941 register Lisp_Object window
;
1943 register struct window
*w
;
1944 register struct window
*ow
= XWINDOW (selected_window
);
1946 CHECK_LIVE_WINDOW (window
, 0);
1948 w
= XWINDOW (window
);
1950 if (NILP (w
->buffer
))
1951 error ("Trying to select deleted window or non-leaf window");
1953 XSETFASTINT (w
->use_time
, ++window_select_count
);
1954 if (EQ (window
, selected_window
))
1957 Fset_marker (ow
->pointm
, make_number (BUF_PT (XBUFFER (ow
->buffer
))),
1960 selected_window
= window
;
1961 if (XFRAME (WINDOW_FRAME (w
)) != selected_frame
)
1963 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
1964 /* Use this rather than Fhandle_switch_frame
1965 so that FRAME_FOCUS_FRAME is moved appropriately as we
1966 move around in the state where a minibuffer in a separate
1968 Fselect_frame (WINDOW_FRAME (w
), Qnil
);
1971 selected_frame
->selected_window
= window
;
1973 record_buffer (w
->buffer
);
1974 Fset_buffer (w
->buffer
);
1976 XBUFFER (w
->buffer
)->last_selected_window
= window
;
1978 /* Go to the point recorded in the window.
1979 This is important when the buffer is in more
1980 than one window. It also matters when
1981 redisplay_window has altered point after scrolling,
1982 because it makes the change only in the window. */
1984 register int new_point
= marker_position (w
->pointm
);
1985 if (new_point
< BEGV
)
1987 else if (new_point
> ZV
)
1993 windows_or_buffers_changed
++;
1997 /* Deiconify the frame containing the window WINDOW,
1998 unless it is the selected frame;
2001 The reason for the exception for the selected frame
2002 is that it seems better not to change the selected frames visibility
2003 merely because of displaying a different buffer in it.
2004 The deiconification is useful when a buffer gets shown in
2005 another frame that you were not using lately. */
2008 display_buffer_1 (window
)
2011 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
2012 FRAME_SAMPLE_VISIBILITY (f
);
2013 if (f
!= selected_frame
)
2015 if (FRAME_ICONIFIED_P (f
))
2016 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
2017 else if (FRAME_VISIBLE_P (f
))
2018 Fraise_frame (WINDOW_FRAME (XWINDOW (window
)));
2023 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
2024 "Returns non-nil if a buffer named BUFFER-NAME would be created specially.\n\
2025 The value is actually t if the frame should be called with default frame\n\
2026 parameters, and a list of frame parameters if they were specified.\n\
2027 See `special-display-buffer-names', and `special-display-regexps'.")
2029 Lisp_Object buffer_name
;
2033 CHECK_STRING (buffer_name
, 1);
2035 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
2039 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
2043 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2045 Lisp_Object car
= XCAR (tem
);
2047 && fast_string_match (car
, buffer_name
) >= 0)
2049 else if (CONSP (car
)
2050 && STRINGP (XCAR (car
))
2051 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2057 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
2058 "Returns non-nil if a new buffer named BUFFER-NAME would use the same window.\n\
2059 See `same-window-buffer-names' and `same-window-regexps'.")
2061 Lisp_Object buffer_name
;
2065 CHECK_STRING (buffer_name
, 1);
2067 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
2071 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
2075 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2077 Lisp_Object car
= XCAR (tem
);
2079 && fast_string_match (car
, buffer_name
) >= 0)
2081 else if (CONSP (car
)
2082 && STRINGP (XCAR (car
))
2083 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2089 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 2,
2090 "bDisplay buffer: \nP",
2091 "Make BUFFER appear in some window but don't select it.\n\
2092 BUFFER can be a buffer or a buffer name.\n\
2093 If BUFFER is shown already in some window, just use that one,\n\
2094 unless the window is the selected window and the optional second\n\
2095 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).\n\
2096 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.\n\
2097 Returns the window displaying BUFFER.\n\
2099 The variables `special-display-buffer-names', `special-display-regexps',\n\
2100 `same-window-buffer-names', and `same-window-regexps' customize how certain\n\
2101 buffer names are handled.")
2102 (buffer
, not_this_window
)
2103 register Lisp_Object buffer
, not_this_window
;
2105 register Lisp_Object window
, tem
;
2107 buffer
= Fget_buffer (buffer
);
2108 CHECK_BUFFER (buffer
, 0);
2110 if (!NILP (Vdisplay_buffer_function
))
2111 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
2113 if (NILP (not_this_window
)
2114 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
2115 return display_buffer_1 (selected_window
);
2117 /* See if the user has specified this buffer should appear
2118 in the selected window. */
2119 if (NILP (not_this_window
))
2121 tem
= Fsame_window_p (XBUFFER (buffer
)->name
);
2124 Fswitch_to_buffer (buffer
, Qnil
);
2125 return display_buffer_1 (selected_window
);
2129 /* If pop_up_frames,
2130 look for a window showing BUFFER on any visible or iconified frame.
2131 Otherwise search only the current frame. */
2132 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2133 XSETFASTINT (tem
, 0);
2135 XSETFRAME (tem
, last_nonminibuf_frame
);
2136 window
= Fget_buffer_window (buffer
, tem
);
2138 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
2140 return display_buffer_1 (window
);
2143 /* Certain buffer names get special handling. */
2144 if (!NILP (Vspecial_display_function
))
2146 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
2148 return call1 (Vspecial_display_function
, buffer
);
2150 return call2 (Vspecial_display_function
, buffer
, tem
);
2153 /* If there are no frames open that have more than a minibuffer,
2154 we need to create a new frame. */
2155 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2157 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2158 Fset_window_buffer (window
, buffer
);
2159 return display_buffer_1 (window
);
2163 || FRAME_MINIBUF_ONLY_P (selected_frame
)
2164 /* If the current frame is a special display frame,
2165 don't try to reuse its windows. */
2166 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (selected_frame
))->dedicated
)
2172 if (FRAME_MINIBUF_ONLY_P (selected_frame
))
2173 XSETFRAME (frames
, last_nonminibuf_frame
);
2174 /* Don't try to create a window if would get an error */
2175 if (split_height_threshold
< window_min_height
<< 1)
2176 split_height_threshold
= window_min_height
<< 1;
2178 /* Note that both Fget_largest_window and Fget_lru_window
2179 ignore minibuffers and dedicated windows.
2180 This means they can return nil. */
2182 /* If the frame we would try to split cannot be split,
2183 try other frames. */
2184 if (FRAME_NO_SPLIT_P (NILP (frames
) ? selected_frame
2185 : last_nonminibuf_frame
))
2187 /* Try visible frames first. */
2188 window
= Fget_largest_window (Qvisible
);
2189 /* If that didn't work, try iconified frames. */
2191 window
= Fget_largest_window (make_number (0));
2193 window
= Fget_largest_window (Qt
);
2196 window
= Fget_largest_window (frames
);
2198 /* If we got a tall enough full-width window that can be split,
2201 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2202 && window_height (window
) >= split_height_threshold
2203 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
2204 window
= Fsplit_window (window
, Qnil
, Qnil
);
2207 Lisp_Object upper
, lower
, other
;
2209 window
= Fget_lru_window (frames
);
2210 /* If the LRU window is selected, and big enough,
2211 and can be split, split it. */
2213 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2214 && (EQ (window
, selected_window
)
2215 || EQ (XWINDOW (window
)->parent
, Qnil
))
2216 && window_height (window
) >= window_min_height
<< 1)
2217 window
= Fsplit_window (window
, Qnil
, Qnil
);
2218 /* If Fget_lru_window returned nil, try other approaches. */
2219 /* Try visible frames first. */
2221 window
= Fget_largest_window (Qvisible
);
2222 /* If that didn't work, try iconified frames. */
2224 window
= Fget_largest_window (make_number (0));
2225 /* Try invisible frames. */
2227 window
= Fget_largest_window (Qt
);
2228 /* As a last resort, make a new frame. */
2230 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2231 /* If window appears above or below another,
2232 even out their heights. */
2233 other
= upper
= lower
= Qnil
;
2234 if (!NILP (XWINDOW (window
)->prev
))
2235 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
2236 if (!NILP (XWINDOW (window
)->next
))
2237 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
2239 /* Check that OTHER and WINDOW are vertically arrayed. */
2240 && !EQ (XWINDOW (other
)->top
, XWINDOW (window
)->top
)
2241 && (XFASTINT (XWINDOW (other
)->height
)
2242 > XFASTINT (XWINDOW (window
)->height
)))
2244 int total
= (XFASTINT (XWINDOW (other
)->height
)
2245 + XFASTINT (XWINDOW (window
)->height
));
2246 Lisp_Object old_selected_window
;
2247 old_selected_window
= selected_window
;
2249 selected_window
= upper
;
2250 change_window_height ((total
/ 2
2251 - XFASTINT (XWINDOW (upper
)->height
)),
2253 selected_window
= old_selected_window
;
2258 window
= Fget_lru_window (Qnil
);
2260 Fset_window_buffer (window
, buffer
);
2261 return display_buffer_1 (window
);
2265 temp_output_buffer_show (buf
)
2266 register Lisp_Object buf
;
2268 register struct buffer
*old
= current_buffer
;
2269 register Lisp_Object window
;
2270 register struct window
*w
;
2273 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
2277 XBUFFER (buf
)->clip_changed
= 1;
2278 set_buffer_internal (old
);
2280 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
2281 call1 (Vtemp_buffer_show_function
, buf
);
2284 window
= Fdisplay_buffer (buf
, Qnil
);
2286 if (XFRAME (XWINDOW (window
)->frame
) != selected_frame
)
2287 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
2288 Vminibuf_scroll_window
= window
;
2289 w
= XWINDOW (window
);
2290 XSETFASTINT (w
->hscroll
, 0);
2291 set_marker_restricted (w
->start
, make_number (1), buf
);
2292 set_marker_restricted (w
->pointm
, make_number (1), buf
);
2294 /* Run temp-buffer-show-hook, with the chosen window selected. */
2295 if (!NILP (Vrun_hooks
))
2298 tem
= Fboundp (Qtemp_buffer_show_hook
);
2301 tem
= Fsymbol_value (Qtemp_buffer_show_hook
);
2304 int count
= specpdl_ptr
- specpdl
;
2306 /* Select the window that was chosen, for running the hook. */
2307 record_unwind_protect (Fset_window_configuration
,
2308 Fcurrent_window_configuration (Qnil
));
2310 Fselect_window (window
);
2311 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
2312 unbind_to (count
, Qnil
);
2320 make_dummy_parent (window
)
2324 register struct window
*o
, *p
;
2325 register struct Lisp_Vector
*vec
;
2328 o
= XWINDOW (window
);
2329 vec
= allocate_vectorlike ((EMACS_INT
)VECSIZE (struct window
));
2330 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
2331 vec
->contents
[i
] = ((struct Lisp_Vector
*)o
)->contents
[i
];
2332 vec
->size
= VECSIZE (struct window
);
2333 p
= (struct window
*)vec
;
2334 XSETWINDOW (new, p
);
2336 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
2338 /* Put new into window structure in place of window */
2339 replace_window (window
, new);
2352 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
2353 "Split WINDOW, putting SIZE lines in the first of the pair.\n\
2354 WINDOW defaults to selected one and SIZE to half its size.\n\
2355 If optional third arg HORFLAG is non-nil, split side by side\n\
2356 and put SIZE columns in the first of the pair.")
2357 (window
, size
, horflag
)
2358 Lisp_Object window
, size
, horflag
;
2360 register Lisp_Object
new;
2361 register struct window
*o
, *p
;
2363 register int size_int
;
2366 window
= selected_window
;
2368 CHECK_LIVE_WINDOW (window
, 0);
2370 o
= XWINDOW (window
);
2371 fo
= XFRAME (WINDOW_FRAME (o
));
2375 if (!NILP (horflag
))
2376 /* Calculate the size of the left-hand window, by dividing
2377 the usable space in columns by two. */
2378 size_int
= XFASTINT (o
->width
) >> 1;
2380 size_int
= XFASTINT (o
->height
) >> 1;
2384 CHECK_NUMBER (size
, 1);
2385 size_int
= XINT (size
);
2388 if (MINI_WINDOW_P (o
))
2389 error ("Attempt to split minibuffer window");
2390 else if (FRAME_NO_SPLIT_P (fo
))
2391 error ("Attempt to split unsplittable frame");
2393 check_min_window_sizes ();
2397 if (size_int
< window_min_height
)
2398 error ("Window height %d too small (after splitting)", size_int
);
2399 if (size_int
+ window_min_height
> XFASTINT (o
->height
))
2400 error ("Window height %d too small (after splitting)",
2401 XFASTINT (o
->height
) - size_int
);
2402 if (NILP (o
->parent
)
2403 || NILP (XWINDOW (o
->parent
)->vchild
))
2405 make_dummy_parent (window
);
2407 XWINDOW (new)->vchild
= window
;
2412 if (size_int
< window_min_width
)
2413 error ("Window width %d too small (after splitting)", size_int
);
2415 if (size_int
+ window_min_width
> XFASTINT (o
->width
))
2416 error ("Window width %d too small (after splitting)",
2417 XFASTINT (o
->width
) - size_int
);
2418 if (NILP (o
->parent
)
2419 || NILP (XWINDOW (o
->parent
)->hchild
))
2421 make_dummy_parent (window
);
2423 XWINDOW (new)->hchild
= window
;
2427 /* Now we know that window's parent is a vertical combination
2428 if we are dividing vertically, or a horizontal combination
2429 if we are making side-by-side windows */
2431 windows_or_buffers_changed
++;
2432 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
2433 new = make_window ();
2436 p
->frame
= o
->frame
;
2438 if (!NILP (p
->next
))
2439 XWINDOW (p
->next
)->prev
= new;
2442 p
->parent
= o
->parent
;
2445 /* Apportion the available frame space among the two new windows */
2447 if (!NILP (horflag
))
2449 p
->height
= o
->height
;
2451 XSETFASTINT (p
->width
, XFASTINT (o
->width
) - size_int
);
2452 XSETFASTINT (o
->width
, size_int
);
2453 XSETFASTINT (p
->left
, XFASTINT (o
->left
) + size_int
);
2458 p
->width
= o
->width
;
2459 XSETFASTINT (p
->height
, XFASTINT (o
->height
) - size_int
);
2460 XSETFASTINT (o
->height
, size_int
);
2461 XSETFASTINT (p
->top
, XFASTINT (o
->top
) + size_int
);
2464 Fset_window_buffer (new, o
->buffer
);
2469 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
2470 "Make current window ARG lines bigger.\n\
2471 From program, optional second arg non-nil means grow sideways ARG columns.")
2473 register Lisp_Object arg
, side
;
2475 CHECK_NUMBER (arg
, 0);
2476 change_window_height (XINT (arg
), !NILP (side
));
2478 if (! NILP (Vwindow_configuration_change_hook
))
2479 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2484 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
2485 "Make current window ARG lines smaller.\n\
2486 From program, optional second arg non-nil means shrink sideways arg columns.")
2488 register Lisp_Object arg
, side
;
2490 CHECK_NUMBER (arg
, 0);
2491 change_window_height (-XINT (arg
), !NILP (side
));
2493 if (! NILP (Vwindow_configuration_change_hook
))
2494 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2500 window_height (window
)
2503 register struct window
*p
= XWINDOW (window
);
2504 return XFASTINT (p
->height
);
2508 window_width (window
)
2511 register struct window
*p
= XWINDOW (window
);
2512 return XFASTINT (p
->width
);
2515 #define MINSIZE(w) \
2517 ? window_min_width \
2518 : (MINI_WINDOW_P (XWINDOW (w)) ? 1 : window_min_height))
2521 *(widthflag ? (int *) &(XWINDOW (w)->left) : (int *) &(XWINDOW (w)->top))
2523 #define CURSIZE(w) \
2524 *(widthflag ? (int *) &(XWINDOW (w)->width) : (int *) &(XWINDOW (w)->height))
2526 /* Unlike set_window_height, this function
2527 also changes the heights of the siblings so as to
2528 keep everything consistent. */
2530 change_window_height (delta
, widthflag
)
2534 register Lisp_Object parent
;
2536 register struct window
*p
;
2538 int (*sizefun
) () = widthflag
? window_width
: window_height
;
2539 register int (*setsizefun
) () = (widthflag
2541 : set_window_height
);
2543 Lisp_Object next
, prev
;
2545 check_min_window_sizes ();
2547 window
= selected_window
;
2550 p
= XWINDOW (window
);
2555 error ("No other window to side of this one");
2558 if (widthflag
? !NILP (XWINDOW (parent
)->hchild
)
2559 : !NILP (XWINDOW (parent
)->vchild
))
2564 sizep
= &CURSIZE (window
);
2567 register int maxdelta
;
2569 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - *sizep
2570 : !NILP (p
->next
) ? (*sizefun
) (p
->next
) - MINSIZE (p
->next
)
2571 : !NILP (p
->prev
) ? (*sizefun
) (p
->prev
) - MINSIZE (p
->prev
)
2572 /* This is a frame with only one window, a minibuffer-only
2573 or a minibufferless frame. */
2576 if (delta
> maxdelta
)
2577 /* This case traps trying to make the minibuffer
2578 the full frame, or make the only window aside from the
2579 minibuffer the full frame. */
2583 if (*sizep
+ delta
< MINSIZE (window
))
2585 delete_window (window
);
2592 /* Find the total we can get from other siblings. */
2594 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
2595 maximum
+= (*sizefun
) (next
) - MINSIZE (next
);
2596 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
2597 maximum
+= (*sizefun
) (prev
) - MINSIZE (prev
);
2599 /* If we can get it all from them, do so. */
2600 if (delta
< maximum
)
2602 Lisp_Object first_unaffected
;
2603 Lisp_Object first_affected
;
2607 first_affected
= window
;
2608 /* Look at one sibling at a time,
2609 moving away from this window in both directions alternately,
2610 and take as much as we can get without deleting that sibling. */
2617 int this_one
= (*sizefun
) (next
) - MINSIZE (next
);
2618 if (this_one
> delta
)
2621 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
2622 (*setsizefun
) (window
, *sizep
+ this_one
, 0);
2625 next
= XWINDOW (next
)->next
;
2631 int this_one
= (*sizefun
) (prev
) - MINSIZE (prev
);
2632 if (this_one
> delta
)
2635 first_affected
= prev
;
2637 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
2638 (*setsizefun
) (window
, *sizep
+ this_one
, 0);
2641 prev
= XWINDOW (prev
)->prev
;
2645 /* Now recalculate the edge positions of all the windows affected,
2646 based on the new sizes. */
2647 first_unaffected
= next
;
2648 prev
= first_affected
;
2649 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
2650 prev
= next
, next
= XWINDOW (next
)->next
)
2652 CURBEG (next
) = CURBEG (prev
) + (*sizefun
) (prev
);
2653 /* This does not change size of NEXT,
2654 but it propagates the new top edge to its children */
2655 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
2660 register int delta1
;
2661 register int opht
= (*sizefun
) (parent
);
2663 /* If trying to grow this window to or beyond size of the parent,
2664 make delta1 so big that, on shrinking back down,
2665 all the siblings end up with less than one line and are deleted. */
2666 if (opht
<= *sizep
+ delta
)
2667 delta1
= opht
* opht
* 2;
2668 /* Otherwise, make delta1 just right so that if we add delta1
2669 lines to this window and to the parent, and then shrink
2670 the parent back to its original size, the new proportional
2671 size of this window will increase by delta. */
2673 delta1
= (delta
* opht
* 100) / ((opht
- *sizep
- delta
) * 100);
2675 /* Add delta1 lines or columns to this window, and to the parent,
2676 keeping things consistent while not affecting siblings. */
2677 CURSIZE (parent
) = opht
+ delta1
;
2678 (*setsizefun
) (window
, *sizep
+ delta1
, 0);
2680 /* Squeeze out delta1 lines or columns from our parent,
2681 shriking this window and siblings proportionately.
2682 This brings parent back to correct size.
2683 Delta1 was calculated so this makes this window the desired size,
2684 taking it all out of the siblings. */
2685 (*setsizefun
) (parent
, opht
, 0);
2688 XSETFASTINT (p
->last_modified
, 0);
2689 XSETFASTINT (p
->last_overlay_modified
, 0);
2696 /* Return number of lines of text (not counting mode line) in W. */
2699 window_internal_height (w
)
2702 int ht
= XFASTINT (w
->height
);
2704 if (MINI_WINDOW_P (w
))
2707 if (!NILP (w
->parent
) || !NILP (w
->vchild
) || !NILP (w
->hchild
)
2708 || !NILP (w
->next
) || !NILP (w
->prev
)
2709 || FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (w
))))
2716 /* Return the number of columns in W.
2717 Don't count columns occupied by scroll bars or the vertical bar
2718 separating W from the sibling to its right. */
2720 window_internal_width (w
)
2723 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2724 int width
= XINT (w
->width
);
2726 /* Scroll bars occupy a few columns. */
2727 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2728 return width
- FRAME_SCROLL_BAR_COLS (f
);
2730 /* The column of `|' characters separating side-by-side windows
2731 occupies one column only. */
2732 if (!WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
2739 /* Scroll contents of window WINDOW up N lines.
2740 If WHOLE is nonzero, it means scroll N screenfuls instead. */
2743 window_scroll (window
, n
, whole
, noerror
)
2749 register struct window
*w
= XWINDOW (window
);
2750 register int opoint
= PT
;
2752 register int ht
= window_internal_height (w
);
2753 register Lisp_Object tem
;
2755 Lisp_Object bolp
, nmoved
;
2757 struct position posit
;
2760 startpos
= marker_position (w
->start
);
2762 posit
= *compute_motion (startpos
, 0, 0, 0,
2764 window_internal_width (w
), XINT (w
->hscroll
),
2766 original_vpos
= posit
.vpos
;
2768 XSETFASTINT (tem
, PT
);
2769 tem
= Fpos_visible_in_window_p (tem
, window
);
2773 Fvertical_motion (make_number (- (ht
/ 2)), window
);
2778 lose
= n
< 0 && PT
== BEGV
;
2779 Fvertical_motion (make_number (n
), window
);
2789 Fsignal (Qbeginning_of_buffer
, Qnil
);
2794 int this_scroll_margin
= scroll_margin
;
2796 /* Don't use a scroll margin that is negative or too large. */
2797 if (this_scroll_margin
< 0)
2798 this_scroll_margin
= 0;
2800 if (XINT (w
->height
) < 4 * scroll_margin
)
2801 this_scroll_margin
= XINT (w
->height
) / 4;
2803 set_marker_restricted (w
->start
, make_number (pos
), w
->buffer
);
2804 w
->start_at_line_beg
= bolp
;
2805 w
->update_mode_line
= Qt
;
2806 XSETFASTINT (w
->last_modified
, 0);
2807 XSETFASTINT (w
->last_overlay_modified
, 0);
2808 /* Set force_start so that redisplay_window will run
2809 the window-scroll-functions. */
2810 w
->force_start
= Qt
;
2812 if (whole
&& scroll_preserve_screen_position
)
2815 Fvertical_motion (make_number (original_vpos
), window
);
2817 /* If we scrolled forward, put point enough lines down
2818 that it is outside the scroll margin. */
2823 if (this_scroll_margin
> 0)
2826 Fvertical_motion (make_number (this_scroll_margin
), window
);
2832 if (top_margin
<= opoint
)
2834 else if (scroll_preserve_screen_position
)
2837 Fvertical_motion (make_number (original_vpos
), window
);
2846 /* If we scrolled backward, put point near the end of the window
2847 but not within the scroll margin. */
2849 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
2850 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
2853 bottom_margin
= PT
+ 1;
2855 if (bottom_margin
> opoint
)
2859 if (scroll_preserve_screen_position
)
2862 Fvertical_motion (make_number (original_vpos
), window
);
2865 Fvertical_motion (make_number (-1), window
);
2874 Fsignal (Qend_of_buffer
, Qnil
);
2878 /* This is the guts of Fscroll_up and Fscroll_down. */
2881 scroll_command (n
, direction
)
2882 register Lisp_Object n
;
2885 register int defalt
;
2886 int count
= specpdl_ptr
- specpdl
;
2888 /* If selected window's buffer isn't current, make it current for the moment.
2889 But don't screw up if window_scroll gets an error. */
2890 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
2892 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
2893 Fset_buffer (XWINDOW (selected_window
)->buffer
);
2896 defalt
= (window_internal_height (XWINDOW (selected_window
))
2897 - next_screen_context_lines
);
2898 defalt
= direction
* (defalt
< 1 ? 1 : defalt
);
2901 window_scroll (selected_window
, defalt
, 1, 0);
2902 else if (EQ (n
, Qminus
))
2903 window_scroll (selected_window
, - defalt
, 1, 0);
2906 n
= Fprefix_numeric_value (n
);
2907 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
2910 unbind_to (count
, Qnil
);
2913 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
2914 "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\
2915 A near full screen is `next-screen-context-lines' less than a full screen.\n\
2916 Negative ARG means scroll downward.\n\
2917 When calling from a program, supply a number as argument or nil.")
2921 scroll_command (arg
, 1);
2925 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
2926 "Scroll text of current window downward ARG lines; or near full screen if no ARG.\n\
2927 A near full screen is `next-screen-context-lines' less than a full screen.\n\
2928 Negative ARG means scroll upward.\n\
2929 When calling from a program, supply a number as argument or nil.")
2933 scroll_command (arg
, -1);
2937 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
2938 "Return the other window for \"other window scroll\" commands.\n\
2939 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
2940 specifies the window.\n\
2941 If `other-window-scroll-buffer' is non-nil, a window\n\
2942 showing that buffer is used.")
2947 if (MINI_WINDOW_P (XWINDOW (selected_window
))
2948 && !NILP (Vminibuf_scroll_window
))
2949 window
= Vminibuf_scroll_window
;
2950 /* If buffer is specified, scroll that buffer. */
2951 else if (!NILP (Vother_window_scroll_buffer
))
2953 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
2955 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
);
2959 /* Nothing specified; look for a neighboring window on the same
2961 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
2963 if (EQ (window
, selected_window
))
2964 /* That didn't get us anywhere; look for a window on another
2967 window
= Fnext_window (window
, Qnil
, Qt
);
2968 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
2969 && ! EQ (window
, selected_window
));
2972 CHECK_LIVE_WINDOW (window
, 0);
2974 if (EQ (window
, selected_window
))
2975 error ("There is no other window");
2980 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
2981 "Scroll next window upward ARG lines; or near full screen if no ARG.\n\
2982 The next window is the one below the current one; or the one at the top\n\
2983 if the current one is at the bottom. Negative ARG means scroll downward.\n\
2984 When calling from a program, supply a number as argument or nil.\n\
2986 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
2987 specifies the window to scroll.\n\
2988 If `other-window-scroll-buffer' is non-nil, scroll the window\n\
2989 showing that buffer, popping the buffer up if necessary.")
2991 register Lisp_Object arg
;
2993 register Lisp_Object window
;
2994 register int defalt
;
2995 register struct window
*w
;
2996 register int count
= specpdl_ptr
- specpdl
;
2998 window
= Fother_window_for_scrolling ();
3000 w
= XWINDOW (window
);
3001 defalt
= window_internal_height (w
) - next_screen_context_lines
;
3002 if (defalt
< 1) defalt
= 1;
3004 /* Don't screw up if window_scroll gets an error. */
3005 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
3007 Fset_buffer (w
->buffer
);
3008 SET_PT (marker_position (w
->pointm
));
3011 window_scroll (window
, defalt
, 1, 1);
3012 else if (EQ (arg
, Qminus
))
3013 window_scroll (window
, -defalt
, 1, 1);
3018 CHECK_NUMBER (arg
, 0);
3019 window_scroll (window
, XINT (arg
), 0, 1);
3022 Fset_marker (w
->pointm
, make_number (PT
), Qnil
);
3023 unbind_to (count
, Qnil
);
3028 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 1, "P",
3029 "Scroll selected window display ARG columns left.\n\
3030 Default for ARG is window width minus 2.")
3032 register Lisp_Object arg
;
3036 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
3038 arg
= Fprefix_numeric_value (arg
);
3041 Fset_window_hscroll (selected_window
,
3042 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
3046 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 1, "P",
3047 "Scroll selected window display ARG columns right.\n\
3048 Default for ARG is window width minus 2.")
3050 register Lisp_Object arg
;
3053 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
3055 arg
= Fprefix_numeric_value (arg
);
3058 Fset_window_hscroll (selected_window
,
3059 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
3063 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
3064 "Center point in window and redisplay frame. With ARG, put point on line ARG.\n\
3065 The desired position of point is always relative to the current window.\n\
3066 Just C-u as prefix means put point in the center of the window.\n\
3067 If ARG is omitted or nil, erases the entire frame and then\n\
3068 redraws with point in the center of the current window.")
3070 register Lisp_Object arg
;
3072 register struct window
*w
= XWINDOW (selected_window
);
3073 register int ht
= window_internal_height (w
);
3074 struct position pos
;
3078 extern int frame_garbaged
;
3080 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
3081 XSETFASTINT (arg
, ht
/ 2);
3083 else if (CONSP (arg
)) /* Just C-u. */
3085 XSETFASTINT (arg
, ht
/ 2);
3089 arg
= Fprefix_numeric_value (arg
);
3090 CHECK_NUMBER (arg
, 0);
3094 XSETINT (arg
, XINT (arg
) + ht
);
3096 pos
= *vmotion (PT
, - XINT (arg
), w
);
3098 Fset_marker (w
->start
, make_number (pos
.bufpos
), w
->buffer
);
3099 w
->start_at_line_beg
= ((pos
.bufpos
== BEGV
3100 || FETCH_BYTE (pos
.bufpos
- 1) == '\n')
3102 w
->force_start
= Qt
;
3107 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
3109 "Position point relative to window.\n\
3110 With no argument, position point at center of window.\n\
3111 An argument specifies frame line; zero means top of window,\n\
3112 negative means relative to bottom of window.")
3114 register Lisp_Object arg
;
3116 register struct window
*w
= XWINDOW (selected_window
);
3117 register int height
= window_internal_height (w
);
3122 XSETFASTINT (arg
, height
/ 2);
3125 arg
= Fprefix_numeric_value (arg
);
3127 XSETINT (arg
, XINT (arg
) + height
);
3130 start
= marker_position (w
->start
);
3131 XSETWINDOW (window
, w
);
3132 if (start
< BEGV
|| start
> ZV
)
3134 Fvertical_motion (make_number (- (height
/ 2)), window
);
3135 Fset_marker (w
->start
, make_number (PT
), w
->buffer
);
3136 w
->start_at_line_beg
= Fbolp ();
3137 w
->force_start
= Qt
;
3142 return Fvertical_motion (arg
, window
);
3145 struct save_window_data
3147 EMACS_INT size_from_Lisp_Vector_struct
;
3148 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
3149 Lisp_Object frame_width
, frame_height
, frame_menu_bar_lines
;
3150 Lisp_Object selected_frame
;
3151 Lisp_Object current_window
;
3152 Lisp_Object current_buffer
;
3153 Lisp_Object minibuf_scroll_window
;
3154 Lisp_Object root_window
;
3155 Lisp_Object focus_frame
;
3156 /* Record the values of window-min-width and window-min-height
3157 so that window sizes remain consistent with them. */
3158 Lisp_Object min_width
, min_height
;
3159 /* A vector, interpreted as a struct saved_window */
3160 Lisp_Object saved_windows
;
3163 /* This is saved as a Lisp_Vector */
3166 /* these first two must agree with struct Lisp_Vector in lisp.h */
3167 EMACS_INT size_from_Lisp_Vector_struct
;
3168 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
3171 Lisp_Object buffer
, start
, pointm
, mark
;
3172 Lisp_Object left
, top
, width
, height
, hscroll
;
3173 Lisp_Object parent
, prev
;
3174 Lisp_Object start_at_line_beg
;
3175 Lisp_Object display_table
;
3177 #define SAVED_WINDOW_VECTOR_SIZE 14 /* Arg to Fmake_vector */
3179 #define SAVED_WINDOW_N(swv,n) \
3180 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
3182 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
3183 "T if OBJECT is a window-configuration object.")
3187 if (WINDOW_CONFIGURATIONP (object
))
3193 DEFUN ("set-window-configuration", Fset_window_configuration
,
3194 Sset_window_configuration
, 1, 1, 0,
3195 "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\
3196 CONFIGURATION must be a value previously returned\n\
3197 by `current-window-configuration' (which see).")
3199 Lisp_Object configuration
;
3201 register struct save_window_data
*data
;
3202 struct Lisp_Vector
*saved_windows
;
3203 Lisp_Object new_current_buffer
;
3207 while (!WINDOW_CONFIGURATIONP (configuration
))
3209 configuration
= wrong_type_argument (intern ("window-configuration-p"),
3213 data
= (struct save_window_data
*) XVECTOR (configuration
);
3214 saved_windows
= XVECTOR (data
->saved_windows
);
3216 new_current_buffer
= data
->current_buffer
;
3217 if (NILP (XBUFFER (new_current_buffer
)->name
))
3218 new_current_buffer
= Qnil
;
3220 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
3223 /* If f is a dead frame, don't bother rebuilding its window tree.
3224 However, there is other stuff we should still try to do below. */
3225 if (FRAME_LIVE_P (f
))
3227 register struct window
*w
;
3228 register struct saved_window
*p
;
3231 /* If the frame has been resized since this window configuration was
3232 made, we change the frame to the size specified in the
3233 configuration, restore the configuration, and then resize it
3234 back. We keep track of the prevailing height in these variables. */
3235 int previous_frame_height
= FRAME_HEIGHT (f
);
3236 int previous_frame_width
= FRAME_WIDTH (f
);
3237 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
3239 if (XFASTINT (data
->frame_height
) != previous_frame_height
3240 || XFASTINT (data
->frame_width
) != previous_frame_width
)
3241 change_frame_size (f
, data
->frame_height
, data
->frame_width
, 0, 0);
3242 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
3243 if (XFASTINT (data
->frame_menu_bar_lines
)
3244 != previous_frame_menu_bar_lines
)
3245 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, 0);
3248 windows_or_buffers_changed
++;
3249 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3251 /* Temporarily avoid any problems with windows that are smaller
3252 than they are supposed to be. */
3253 window_min_height
= 1;
3254 window_min_width
= 1;
3257 Mark all windows now on frame as "deleted".
3258 Restoring the new configuration "undeletes" any that are in it.
3260 Save their current buffers in their height fields, since we may
3261 need it later, if a buffer saved in the configuration is now
3263 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3265 for (k
= 0; k
< saved_windows
->size
; k
++)
3267 p
= SAVED_WINDOW_N (saved_windows
, k
);
3268 w
= XWINDOW (p
->window
);
3271 if (!NILP (p
->parent
))
3272 w
->parent
= SAVED_WINDOW_N (saved_windows
,
3273 XFASTINT (p
->parent
))->window
;
3277 if (!NILP (p
->prev
))
3279 w
->prev
= SAVED_WINDOW_N (saved_windows
,
3280 XFASTINT (p
->prev
))->window
;
3281 XWINDOW (w
->prev
)->next
= p
->window
;
3286 if (!NILP (w
->parent
))
3288 if (EQ (p
->width
, XWINDOW (w
->parent
)->width
))
3290 XWINDOW (w
->parent
)->vchild
= p
->window
;
3291 XWINDOW (w
->parent
)->hchild
= Qnil
;
3295 XWINDOW (w
->parent
)->hchild
= p
->window
;
3296 XWINDOW (w
->parent
)->vchild
= Qnil
;
3301 /* If we squirreled away the buffer in the window's height,
3303 if (BUFFERP (w
->height
))
3304 w
->buffer
= w
->height
;
3307 w
->width
= p
->width
;
3308 w
->height
= p
->height
;
3309 w
->hscroll
= p
->hscroll
;
3310 w
->display_table
= p
->display_table
;
3311 XSETFASTINT (w
->last_modified
, 0);
3312 XSETFASTINT (w
->last_overlay_modified
, 0);
3314 /* Reinstall the saved buffer and pointers into it. */
3315 if (NILP (p
->buffer
))
3316 w
->buffer
= p
->buffer
;
3319 if (!NILP (XBUFFER (p
->buffer
)->name
))
3320 /* If saved buffer is alive, install it. */
3322 w
->buffer
= p
->buffer
;
3323 w
->start_at_line_beg
= p
->start_at_line_beg
;
3324 set_marker_restricted (w
->start
,
3325 Fmarker_position (p
->start
),
3327 set_marker_restricted (w
->pointm
,
3328 Fmarker_position (p
->pointm
),
3330 Fset_marker (XBUFFER (w
->buffer
)->mark
,
3331 Fmarker_position (p
->mark
), w
->buffer
);
3333 /* As documented in Fcurrent_window_configuration, don't
3334 save the location of point in the buffer which was current
3335 when the window configuration was recorded. */
3336 if (!EQ (p
->buffer
, new_current_buffer
)
3337 && XBUFFER (p
->buffer
) == current_buffer
)
3338 Fgoto_char (w
->pointm
);
3340 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
3341 /* Else unless window has a live buffer, get one. */
3343 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
3344 /* This will set the markers to beginning of visible
3346 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
3347 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
3348 w
->start_at_line_beg
= Qt
;
3351 /* Keeping window's old buffer; make sure the markers
3354 /* Set window markers at start of visible range. */
3355 if (XMARKER (w
->start
)->buffer
== 0)
3356 set_marker_restricted (w
->start
, make_number (0),
3358 if (XMARKER (w
->pointm
)->buffer
== 0)
3359 set_marker_restricted (w
->pointm
,
3361 (BUF_PT (XBUFFER (w
->buffer
)))),
3363 w
->start_at_line_beg
= Qt
;
3368 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
3369 Fselect_window (data
->current_window
);
3371 if (NILP (data
->focus_frame
)
3372 || (FRAMEP (data
->focus_frame
)
3373 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
3374 Fredirect_frame_focus (frame
, data
->focus_frame
);
3376 #if 0 /* I don't understand why this is needed, and it causes problems
3377 when the frame's old selected window has been deleted. */
3378 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
3379 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
3383 /* Set the screen height to the value it had before this function. */
3384 if (previous_frame_height
!= FRAME_HEIGHT (f
)
3385 || previous_frame_width
!= FRAME_WIDTH (f
))
3386 change_frame_size (f
, previous_frame_height
, previous_frame_width
,
3388 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
3389 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
3390 x_set_menu_bar_lines (f
, previous_frame_menu_bar_lines
, 0);
3394 /* Restore the minimum heights recorded in the configuration. */
3395 window_min_height
= XINT (data
->min_height
);
3396 window_min_width
= XINT (data
->min_width
);
3398 /* Fselect_window will have made f the selected frame, so we
3399 reselect the proper frame here. Fhandle_switch_frame will change the
3400 selected window too, but that doesn't make the call to
3401 Fselect_window above totally superfluous; it still sets f's
3403 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
3404 do_switch_frame (data
->selected_frame
, Qnil
, 0);
3406 if (!NILP (new_current_buffer
))
3407 Fset_buffer (new_current_buffer
);
3409 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
3411 if (! NILP (Vwindow_configuration_change_hook
)
3412 && ! NILP (Vrun_hooks
))
3413 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3418 /* Mark all windows now on frame as deleted
3419 by setting their buffers to nil. */
3422 delete_all_subwindows (w
)
3423 register struct window
*w
;
3425 if (!NILP (w
->next
))
3426 delete_all_subwindows (XWINDOW (w
->next
));
3427 if (!NILP (w
->vchild
))
3428 delete_all_subwindows (XWINDOW (w
->vchild
));
3429 if (!NILP (w
->hchild
))
3430 delete_all_subwindows (XWINDOW (w
->hchild
));
3432 w
->height
= w
->buffer
; /* See Fset_window_configuration for excuse. */
3434 if (!NILP (w
->buffer
))
3437 /* We set all three of these fields to nil, to make sure that we can
3438 distinguish this dead window from any live window. Live leaf
3439 windows will have buffer set, and combination windows will have
3440 vchild or hchild set. */
3447 count_windows (window
)
3448 register struct window
*window
;
3450 register int count
= 1;
3451 if (!NILP (window
->next
))
3452 count
+= count_windows (XWINDOW (window
->next
));
3453 if (!NILP (window
->vchild
))
3454 count
+= count_windows (XWINDOW (window
->vchild
));
3455 if (!NILP (window
->hchild
))
3456 count
+= count_windows (XWINDOW (window
->hchild
));
3461 save_window_save (window
, vector
, i
)
3463 struct Lisp_Vector
*vector
;
3466 register struct saved_window
*p
;
3467 register struct window
*w
;
3468 register Lisp_Object tem
;
3470 for (;!NILP (window
); window
= w
->next
)
3472 p
= SAVED_WINDOW_N (vector
, i
);
3473 w
= XWINDOW (window
);
3475 XSETFASTINT (w
->temslot
, i
++);
3477 p
->buffer
= w
->buffer
;
3480 p
->width
= w
->width
;
3481 p
->height
= w
->height
;
3482 p
->hscroll
= w
->hscroll
;
3483 p
->display_table
= w
->display_table
;
3484 if (!NILP (w
->buffer
))
3486 /* Save w's value of point in the window configuration.
3487 If w is the selected window, then get the value of point
3488 from the buffer; pointm is garbage in the selected window. */
3489 if (EQ (window
, selected_window
))
3491 p
->pointm
= Fmake_marker ();
3492 Fset_marker (p
->pointm
, BUF_PT (XBUFFER (w
->buffer
)),
3496 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
3498 p
->start
= Fcopy_marker (w
->start
, Qnil
);
3499 p
->start_at_line_beg
= w
->start_at_line_beg
;
3501 tem
= XBUFFER (w
->buffer
)->mark
;
3502 p
->mark
= Fcopy_marker (tem
, Qnil
);
3509 p
->start_at_line_beg
= Qnil
;
3512 if (NILP (w
->parent
))
3515 p
->parent
= XWINDOW (w
->parent
)->temslot
;
3520 p
->prev
= XWINDOW (w
->prev
)->temslot
;
3522 if (!NILP (w
->vchild
))
3523 i
= save_window_save (w
->vchild
, vector
, i
);
3524 if (!NILP (w
->hchild
))
3525 i
= save_window_save (w
->hchild
, vector
, i
);
3531 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
3532 Scurrent_window_configuration
, 0, 1, 0,
3533 "Return an object representing the current window configuration of FRAME.\n\
3534 If FRAME is nil or omitted, use the selected frame.\n\
3535 This describes the number of windows, their sizes and current buffers,\n\
3536 and for each displayed buffer, where display starts, and the positions of\n\
3537 point and mark. An exception is made for point in the current buffer:\n\
3538 its value is -not- saved.\n\
3539 This also records the currently selected frame, and FRAME's focus\n\
3540 redirection (see `redirect-frame-focus').")
3544 register Lisp_Object tem
;
3545 register int n_windows
;
3546 register struct save_window_data
*data
;
3547 register struct Lisp_Vector
*vec
;
3555 CHECK_LIVE_FRAME (frame
, 0);
3559 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3560 vec
= allocate_vectorlike (VECSIZE (struct save_window_data
));
3561 for (i
= 0; i
< VECSIZE (struct save_window_data
); i
++)
3562 vec
->contents
[i
] = Qnil
;
3563 vec
->size
= VECSIZE (struct save_window_data
);
3564 data
= (struct save_window_data
*)vec
;
3566 XSETFASTINT (data
->frame_width
, FRAME_WIDTH (f
));
3567 XSETFASTINT (data
->frame_height
, FRAME_HEIGHT (f
));
3568 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
3569 XSETFRAME (data
->selected_frame
, selected_frame
);
3570 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
3571 XSETBUFFER (data
->current_buffer
, current_buffer
);
3572 data
->minibuf_scroll_window
= Vminibuf_scroll_window
;
3573 data
->root_window
= FRAME_ROOT_WINDOW (f
);
3574 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
3575 XSETINT (data
->min_height
, window_min_height
);
3576 XSETINT (data
->min_width
, window_min_width
);
3577 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
3578 data
->saved_windows
= tem
;
3579 for (i
= 0; i
< n_windows
; i
++)
3580 XVECTOR (tem
)->contents
[i
]
3581 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
3582 save_window_save (FRAME_ROOT_WINDOW (f
),
3584 XSETWINDOW_CONFIGURATION (tem
, data
);
3588 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
3590 "Execute body, preserving window sizes and contents.\n\
3591 Restore which buffer appears in which window, where display starts,\n\
3592 and the value of point and mark for each window.\n\
3593 Also restore which buffer is current.\n\
3594 But do not preserve point in the current buffer.\n\
3595 Does not restore the value of point in current buffer.")
3599 register Lisp_Object val
;
3600 register int count
= specpdl_ptr
- specpdl
;
3602 record_unwind_protect (Fset_window_configuration
,
3603 Fcurrent_window_configuration (Qnil
));
3604 val
= Fprogn (args
);
3605 return unbind_to (count
, val
);
3610 selected_frame
= make_terminal_frame ();
3611 XSETFRAME (Vterminal_frame
, selected_frame
);
3612 minibuf_window
= selected_frame
->minibuffer_window
;
3613 selected_window
= selected_frame
->selected_window
;
3614 last_nonminibuf_frame
= selected_frame
;
3616 window_initialized
= 1;
3621 staticpro (&Qwindow_configuration_change_hook
);
3622 Qwindow_configuration_change_hook
3623 = intern ("window-configuration-change-hook");
3625 Qwindowp
= intern ("windowp");
3626 staticpro (&Qwindowp
);
3628 Qwindow_live_p
= intern ("window-live-p");
3629 staticpro (&Qwindow_live_p
);
3631 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
3632 staticpro (&Qtemp_buffer_show_hook
);
3634 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
3635 "Non-nil means call as function to display a help buffer.\n\
3636 The function is called with one argument, the buffer to be displayed.\n\
3637 Used by `with-output-to-temp-buffer'.\n\
3638 If this function is used, then it must do the entire job of showing\n\
3639 the buffer; `temp-buffer-show-hook' is not run unless this function runs it.");
3640 Vtemp_buffer_show_function
= Qnil
;
3642 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
3643 "If non-nil, function to call to handle `display-buffer'.\n\
3644 It will receive two args, the buffer and a flag which if non-nil means\n\
3645 that the currently selected window is not acceptable.\n\
3646 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\
3647 work using this function.");
3648 Vdisplay_buffer_function
= Qnil
;
3650 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
3651 "Non-nil means it is the window that C-M-v in minibuffer should scroll.");
3652 Vminibuf_scroll_window
= Qnil
;
3654 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
3655 "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.");
3656 Vother_window_scroll_buffer
= Qnil
;
3658 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
3659 "*Non-nil means `display-buffer' should make a separate frame.");
3662 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
3663 "Function to call to handle automatic new frame creation.\n\
3664 It is called with no arguments and should return a newly created frame.\n\
3666 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\
3667 where `pop-up-frame-alist' would hold the default frame parameters.");
3668 Vpop_up_frame_function
= Qnil
;
3670 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
3671 "*List of buffer names that should have their own special frames.\n\
3672 Displaying a buffer whose name is in this list makes a special frame for it\n\
3673 using `special-display-function'. See also `special-display-regexps'.\n\
3675 An element of the list can be a list instead of just a string.\n\
3676 There are two ways to use a list as an element:\n\
3677 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)\n\
3678 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
3679 In the latter case, FUNCTION is called with BUFFER as the first argument,\n\
3680 followed by OTHER-ARGS--it can display BUFFER in any way it likes.\n\
3681 All this is done by the function found in `special-display-function'.");
3682 Vspecial_display_buffer_names
= Qnil
;
3684 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
3685 "*List of regexps saying which buffers should have their own special frames.\n\
3686 If a buffer name matches one of these regexps, it gets its own frame.\n\
3687 Displaying a buffer whose name is in this list makes a special frame for it\n\
3688 using `special-display-function'.\n\
3690 An element of the list can be a list instead of just a string.\n\
3691 There are two ways to use a list as an element:\n\
3692 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)\n\
3693 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
3694 In the latter case, FUNCTION is called with the buffer as first argument,\n\
3695 followed by OTHER-ARGS--it can display the buffer in any way it likes.\n\
3696 All this is done by the function found in `special-display-function'.");
3697 Vspecial_display_regexps
= Qnil
;
3699 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
3700 "Function to call to make a new frame for a special buffer.\n\
3701 It is called with two arguments, the buffer and optional buffer specific\n\
3702 data, and should return a window displaying that buffer.\n\
3703 The default value makes a separate frame for the buffer,\n\
3704 using `special-display-frame-alist' to specify the frame parameters.\n\
3706 A buffer is special if its is listed in `special-display-buffer-names'\n\
3707 or matches a regexp in `special-display-regexps'.");
3708 Vspecial_display_function
= Qnil
;
3710 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
3711 "*List of buffer names that should appear in the selected window.\n\
3712 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'\n\
3713 switches to it in the selected window, rather than making it appear\n\
3714 in some other window.\n\
3716 An element of the list can be a cons cell instead of just a string.\n\
3717 Then the car must be a string, which specifies the buffer name.\n\
3718 This is for compatibility with `special-display-buffer-names';\n\
3719 the cdr of the cons cell is ignored.\n\
3721 See also `same-window-regexps'.");
3722 Vsame_window_buffer_names
= Qnil
;
3724 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
3725 "*List of regexps saying which buffers should appear in the selected window.\n\
3726 If a buffer name matches one of these regexps, then displaying it\n\
3727 using `display-buffer' or `pop-to-buffer' switches to it\n\
3728 in the selected window, rather than making it appear in some other window.\n\
3730 An element of the list can be a cons cell instead of just a string.\n\
3731 Then the car must be a string, which specifies the buffer name.\n\
3732 This is for compatibility with `special-display-buffer-names';\n\
3733 the cdr of the cons cell is ignored.\n\
3735 See also `same-window-buffer-names'.");
3736 Vsame_window_regexps
= Qnil
;
3738 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
3739 "*Non-nil means display-buffer should make new windows.");
3742 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
3743 "*Number of lines of continuity when scrolling by screenfuls.");
3744 next_screen_context_lines
= 2;
3746 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
3747 "*display-buffer would prefer to split the largest window if this large.\n\
3748 If there is only one window, it is split regardless of this value.");
3749 split_height_threshold
= 500;
3751 DEFVAR_INT ("window-min-height", &window_min_height
,
3752 "*Delete any window less than this tall (including its mode line).");
3753 window_min_height
= 4;
3755 DEFVAR_INT ("window-min-width", &window_min_width
,
3756 "*Delete any window less than this wide.");
3757 window_min_width
= 10;
3759 DEFVAR_BOOL ("scroll-preserve-screen-position",
3760 &scroll_preserve_screen_position
,
3761 "*Nonzero means scroll commands move point to keep its screen line unchanged.");
3762 scroll_preserve_screen_position
= 0;
3764 DEFVAR_LISP ("window-configuration-change-hook",
3765 &Vwindow_configuration_change_hook
,
3766 "Functions to call when window configuration changes.\n\
3767 The selected frae is the one whose configuration has changed.");
3768 Vwindow_configuration_change_hook
= Qnil
;
3770 defsubr (&Sselected_window
);
3771 defsubr (&Sminibuffer_window
);
3772 defsubr (&Swindow_minibuffer_p
);
3773 defsubr (&Swindowp
);
3774 defsubr (&Swindow_live_p
);
3775 defsubr (&Spos_visible_in_window_p
);
3776 defsubr (&Swindow_buffer
);
3777 defsubr (&Swindow_height
);
3778 defsubr (&Swindow_width
);
3779 defsubr (&Swindow_hscroll
);
3780 defsubr (&Sset_window_hscroll
);
3781 defsubr (&Swindow_redisplay_end_trigger
);
3782 defsubr (&Sset_window_redisplay_end_trigger
);
3783 defsubr (&Swindow_edges
);
3784 defsubr (&Scoordinates_in_window_p
);
3785 defsubr (&Swindow_at
);
3786 defsubr (&Swindow_point
);
3787 defsubr (&Swindow_start
);
3788 defsubr (&Swindow_end
);
3789 defsubr (&Sset_window_point
);
3790 defsubr (&Sset_window_start
);
3791 defsubr (&Swindow_dedicated_p
);
3792 defsubr (&Sset_window_dedicated_p
);
3793 defsubr (&Swindow_display_table
);
3794 defsubr (&Sset_window_display_table
);
3795 defsubr (&Snext_window
);
3796 defsubr (&Sprevious_window
);
3797 defsubr (&Sother_window
);
3798 defsubr (&Sget_lru_window
);
3799 defsubr (&Sget_largest_window
);
3800 defsubr (&Sget_buffer_window
);
3801 defsubr (&Sdelete_other_windows
);
3802 defsubr (&Sdelete_windows_on
);
3803 defsubr (&Sreplace_buffer_in_windows
);
3804 defsubr (&Sdelete_window
);
3805 defsubr (&Sset_window_buffer
);
3806 defsubr (&Sselect_window
);
3807 defsubr (&Sspecial_display_p
);
3808 defsubr (&Ssame_window_p
);
3809 defsubr (&Sdisplay_buffer
);
3810 defsubr (&Ssplit_window
);
3811 defsubr (&Senlarge_window
);
3812 defsubr (&Sshrink_window
);
3813 defsubr (&Sscroll_up
);
3814 defsubr (&Sscroll_down
);
3815 defsubr (&Sscroll_left
);
3816 defsubr (&Sscroll_right
);
3817 defsubr (&Sother_window_for_scrolling
);
3818 defsubr (&Sscroll_other_window
);
3819 defsubr (&Srecenter
);
3820 defsubr (&Smove_to_window_line
);
3821 defsubr (&Swindow_configuration_p
);
3822 defsubr (&Sset_window_configuration
);
3823 defsubr (&Scurrent_window_configuration
);
3824 defsubr (&Ssave_window_excursion
);
3829 initial_define_key (control_x_map
, '1', "delete-other-windows");
3830 initial_define_key (control_x_map
, '2', "split-window");
3831 initial_define_key (control_x_map
, '0', "delete-window");
3832 initial_define_key (control_x_map
, 'o', "other-window");
3833 initial_define_key (control_x_map
, '^', "enlarge-window");
3834 initial_define_key (control_x_map
, '<', "scroll-left");
3835 initial_define_key (control_x_map
, '>', "scroll-right");
3837 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
3838 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
3839 initial_define_key (meta_map
, 'v', "scroll-down");
3841 initial_define_key (global_map
, Ctl('L'), "recenter");
3842 initial_define_key (meta_map
, 'r', "move-to-window-line");