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 #define min(a, b) ((a) < (b) ? (a) : (b))
116 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
118 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
119 "Returns t if OBJECT is a window.")
123 return WINDOWP (object
) ? Qt
: Qnil
;
126 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
127 "Returns t if OBJECT is a window which is currently visible.")
131 return (WINDOWP (object
) && ! NILP (XWINDOW (object
)->buffer
) ? Qt
: Qnil
);
138 register struct window
*p
;
139 register struct Lisp_Vector
*vec
;
142 vec
= allocate_vectorlike ((EMACS_INT
) VECSIZE (struct window
));
143 for (i
= 0; i
< VECSIZE (struct window
); i
++)
144 vec
->contents
[i
] = Qnil
;
145 vec
->size
= VECSIZE (struct window
);
146 p
= (struct window
*)vec
;
147 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
148 XSETFASTINT (p
->left
, 0);
149 XSETFASTINT (p
->top
, 0);
150 XSETFASTINT (p
->height
, 0);
151 XSETFASTINT (p
->width
, 0);
152 XSETFASTINT (p
->hscroll
, 0);
153 XSETFASTINT (p
->last_point_x
, 0);
154 XSETFASTINT (p
->last_point_y
, 0);
155 p
->start
= Fmake_marker ();
156 p
->pointm
= Fmake_marker ();
157 XSETFASTINT (p
->use_time
, 0);
159 p
->display_table
= Qnil
;
165 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
166 "Return the window that the cursor now appears in and commands apply to.")
169 return selected_window
;
172 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
173 "Return the window used now for minibuffers.\n\
174 If the optional argument FRAME is specified, return the minibuffer window\n\
175 used by that frame.")
180 XSETFRAME (frame
, selected_frame
);
182 CHECK_LIVE_FRAME (frame
, 0);
184 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
187 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
188 "Returns non-nil if WINDOW is a minibuffer window.")
192 struct window
*w
= decode_window (window
);
193 return (MINI_WINDOW_P (w
) ? Qt
: Qnil
);
196 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
197 Spos_visible_in_window_p
, 0, 2, 0,
198 "Return t if position POS is currently on the frame in WINDOW.\n\
199 Returns nil if that position is scrolled vertically out of view.\n\
200 POS defaults to point; WINDOW, to the selected window.")
202 Lisp_Object pos
, window
;
204 register struct window
*w
;
208 register struct buffer
*buf
;
209 struct position posval
;
216 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
220 w
= decode_window (window
);
221 top
= marker_position (w
->start
);
222 hscroll
= XINT (w
->hscroll
);
227 height
= XFASTINT (w
->height
) - ! MINI_WINDOW_P (w
);
229 buf
= XBUFFER (w
->buffer
);
230 if (XFASTINT (w
->last_modified
) >= BUF_MODIFF (buf
)
231 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (buf
))
233 /* If frame is up to date,
234 use the info recorded about how much text fit on it. */
235 if (posint
< BUF_Z (buf
) - XFASTINT (w
->window_end_pos
)
236 || (XFASTINT (w
->window_end_vpos
) < height
))
242 if (posint
> BUF_ZV (buf
))
245 /* w->start can be out of range. If it is, do something reasonable. */
246 if (top
< BUF_BEGV (buf
) || top
> BUF_ZV (buf
))
249 /* If that info is not correct, calculate afresh */
250 posval
= *compute_motion (top
, 0, (hscroll
? 1 - hscroll
: 0), 0,
252 window_internal_width (w
) - 1,
255 return posval
.vpos
< height
? Qt
: Qnil
;
259 static struct window
*
260 decode_window (window
)
261 register Lisp_Object window
;
264 return XWINDOW (selected_window
);
266 CHECK_LIVE_WINDOW (window
, 0);
267 return XWINDOW (window
);
270 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
271 "Return the buffer that WINDOW is displaying.")
275 return decode_window (window
)->buffer
;
278 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
279 "Return the number of lines in WINDOW (including its mode line).")
283 return decode_window (window
)->height
;
286 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
287 "Return the number of display columns in WINDOW.\n\
288 This is the width that is usable columns available for text in WINDOW.\n\
289 If you want to find out how many columns WINDOW takes up,\n\
290 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))).")
294 return make_number (window_internal_width (decode_window (window
)));
297 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
298 "Return the number of columns by which WINDOW is scrolled from left margin.")
302 return decode_window (window
)->hscroll
;
305 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
306 "Set number of columns WINDOW is scrolled from left margin to NCOL.\n\
307 NCOL should be zero or positive.")
309 register Lisp_Object window
, ncol
;
311 register struct window
*w
;
313 CHECK_NUMBER (ncol
, 1);
314 if (XINT (ncol
) < 0) XSETFASTINT (ncol
, 0);
315 w
= decode_window (window
);
316 if (XINT (w
->hscroll
) != XINT (ncol
))
317 XBUFFER (w
->buffer
)->clip_changed
= 1; /* Prevent redisplay shortcuts */
322 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
323 Swindow_redisplay_end_trigger
, 0, 1, 0,
324 "Return WINDOW's redisplay end trigger value.\n\
325 See `set-window-redisplay-end-trigger' for more information.")
329 return decode_window (window
)->redisplay_end_trigger
;
332 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
333 Sset_window_redisplay_end_trigger
, 2, 2, 0,
334 "Set WINDOW's redisplay end trigger value to VALUE.\n\
335 VALUE should be a buffer position (typically a marker) or nil.\n\
336 If it is a buffer position, then if redisplay in WINDOW reaches a position\n\
337 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called\n\
338 with two arguments: WINDOW, and the end trigger value.\n\
339 Afterwards the end-trigger value is reset to nil.")
341 register Lisp_Object window
, value
;
343 register struct window
*w
;
345 w
= decode_window (window
);
346 w
->redisplay_end_trigger
= value
;
350 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
351 "Return a list of the edge coordinates of WINDOW.\n\
352 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.\n\
353 RIGHT is one more than the rightmost column used by WINDOW,\n\
354 and BOTTOM is one more than the bottommost row used by WINDOW\n\
359 register struct window
*w
= decode_window (window
);
361 return Fcons (w
->left
, Fcons (w
->top
,
362 Fcons (make_number (WINDOW_RIGHT_EDGE (w
)),
363 Fcons (make_number (XFASTINT (w
->top
)
364 + XFASTINT (w
->height
)),
368 /* Test if the character at column *x, row *y is within window *w.
369 If it is not, return 0;
370 if it is in the window's text area,
371 set *x and *y to its location relative to the upper left corner
374 if it is on the window's modeline, return 2;
375 if it is on the border between the window and its right sibling,
378 coordinates_in_window (w
, x
, y
)
379 register struct window
*w
;
382 register int left
= XINT (w
->left
);
383 register int right_edge
= WINDOW_RIGHT_EDGE (w
);
384 register int left_margin
= WINDOW_LEFT_MARGIN (w
);
385 register int right_margin
= WINDOW_RIGHT_MARGIN (w
);
386 register int window_height
= XINT (w
->height
);
387 register int top
= XFASTINT (w
->top
);
389 if ( *x
< left
|| *x
>= right_edge
390 || *y
< top
|| *y
>= top
+ window_height
)
393 if (left_margin
!= left
&& *x
< left_margin
&& *x
>= left
)
396 if (right_margin
!= right_edge
&& *x
>= right_margin
&& *x
< right_edge
)
399 /* Is the character is the mode line? */
400 if (*y
== top
+ window_height
- 1
401 && ! MINI_WINDOW_P (w
))
404 *x
-= WINDOW_LEFT_MARGIN (w
);
409 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
410 Scoordinates_in_window_p
, 2, 2, 0,
411 "Return non-nil if COORDINATES are in WINDOW.\n\
412 COORDINATES is a cons of the form (X . Y), X and Y being distances\n\
413 measured in characters from the upper-left corner of the frame.\n\
414 (0 . 0) denotes the character in the upper left corner of the\n\
416 If COORDINATES are in the text portion of WINDOW,\n\
417 the coordinates relative to the window are returned.\n\
418 If they are in the mode line of WINDOW, `mode-line' is returned.\n\
419 If they are on the border between WINDOW and its right sibling,\n\
420 `vertical-line' is returned.")
421 (coordinates
, window
)
422 register Lisp_Object coordinates
, window
;
426 CHECK_LIVE_WINDOW (window
, 0);
427 CHECK_CONS (coordinates
, 1);
428 x
= XINT (Fcar (coordinates
));
429 y
= XINT (Fcdr (coordinates
));
431 switch (coordinates_in_window (XWINDOW (window
), &x
, &y
))
433 case 0: /* NOT in window at all. */
436 case 1: /* In text part of window. */
439 case 2: /* In mode line of window. */
442 case 3: /* On right border of window. */
443 return Qvertical_line
;
450 /* Find the window containing column x, row y, and return it as a
451 Lisp_Object. If x, y is on the window's modeline, set *part
452 to 1; if it is on the separating line between the window and its
453 right sibling, set it to 2; otherwise set it to 0. If there is no
454 window under x, y return nil and leave *part unmodified. */
456 window_from_coordinates (frame
, x
, y
, part
)
461 register Lisp_Object tem
, first
;
463 tem
= first
= FRAME_SELECTED_WINDOW (frame
);
467 int found
= coordinates_in_window (XWINDOW (tem
), &x
, &y
);
475 tem
= Fnext_window (tem
, Qt
, Qlambda
);
477 while (! EQ (tem
, first
));
482 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
483 "Return window containing coordinates X and Y on FRAME.\n\
484 If omitted, FRAME defaults to the currently selected frame.\n\
485 The top left corner of the frame is considered to be row 0,\n\
488 Lisp_Object x
, y
, frame
;
493 XSETFRAME (frame
, selected_frame
);
495 CHECK_LIVE_FRAME (frame
, 2);
499 return window_from_coordinates (XFRAME (frame
),
504 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
505 "Return current value of point in WINDOW.\n\
506 For a nonselected window, this is the value point would have\n\
507 if that window were selected.\n\
509 Note that, when WINDOW is the selected window and its buffer\n\
510 is also currently selected, the value returned is the same as (point).\n\
511 It would be more strictly correct to return the `top-level' value\n\
512 of point, outside of any save-excursion forms.\n\
513 But that is hard to define.")
517 register struct window
*w
= decode_window (window
);
519 if (w
== XWINDOW (selected_window
)
520 && current_buffer
== XBUFFER (w
->buffer
))
522 return Fmarker_position (w
->pointm
);
525 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
526 "Return position at which display currently starts in WINDOW.\n\
527 This is updated by redisplay or by calling `set-window-start'.")
531 return Fmarker_position (decode_window (window
)->start
);
534 /* This is text temporarily removed from the doc string below.
536 This function returns nil if the position is not currently known.\n\
537 That happens when redisplay is preempted and doesn't finish.\n\
538 If in that case you want to compute where the end of the window would\n\
539 have been if redisplay had finished, do this:\n\
541 (goto-char (window-start window))\n\
542 (vertical-motion (1- (window-height window)) window)\n\
545 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 1, 0,
546 "Return position at which display currently ends in WINDOW.\n\
547 This is updated by redisplay, when it runs to completion.\n\
548 Simply changing the buffer text or setting `window-start'\n\
549 does not update this value.")
554 struct window
*w
= decode_window (window
);
558 CHECK_BUFFER (buf
, 0);
560 #if 0 /* This change broke some things. We should make it later. */
561 /* If we don't know the end position, return nil.
562 The user can compute it with vertical-motion if he wants to.
563 It would be nicer to do it automatically,
564 but that's so slow that it would probably bother people. */
565 if (NILP (w
->window_end_valid
))
570 BUF_Z (XBUFFER (buf
)) - XFASTINT (w
->window_end_pos
));
575 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
576 "Make point value in WINDOW be at position POS in WINDOW's buffer.")
578 Lisp_Object window
, pos
;
580 register struct window
*w
= decode_window (window
);
582 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
583 if (w
== XWINDOW (selected_window
))
586 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
591 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
592 "Make display in WINDOW start at position POS in WINDOW's buffer.\n\
593 Optional third arg NOFORCE non-nil inhibits next redisplay\n\
594 from overriding motion of point in order to display at this exact start.")
595 (window
, pos
, noforce
)
596 Lisp_Object window
, pos
, noforce
;
598 register struct window
*w
= decode_window (window
);
600 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
601 set_marker_restricted (w
->start
, pos
, w
->buffer
);
602 /* this is not right, but much easier than doing what is right. */
603 w
->start_at_line_beg
= Qnil
;
606 w
->update_mode_line
= Qt
;
607 XSETFASTINT (w
->last_modified
, 0);
608 XSETFASTINT (w
->last_overlay_modified
, 0);
609 if (!EQ (window
, selected_window
))
610 windows_or_buffers_changed
++;
614 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
616 "Return WINDOW's dedicated object, usually t or nil.\n\
617 See also `set-window-dedicated-p'.")
621 return decode_window (window
)->dedicated
;
624 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
625 Sset_window_dedicated_p
, 2, 2, 0,
626 "Control whether WINDOW is dedicated to the buffer it displays.\n\
627 If it is dedicated, Emacs will not automatically change\n\
628 which buffer appears in it.\n\
629 The second argument is the new value for the dedication flag;\n\
632 Lisp_Object window
, arg
;
634 register struct window
*w
= decode_window (window
);
644 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
646 "Return the display-table that WINDOW is using.")
650 return decode_window (window
)->display_table
;
653 /* Get the display table for use currently on window W.
654 This is either W's display table or W's buffer's display table.
655 Ignore the specified tables if they are not valid;
656 if no valid table is specified, return 0. */
658 struct Lisp_Char_Table
*
659 window_display_table (w
)
663 tem
= w
->display_table
;
664 if (DISP_TABLE_P (tem
))
665 return XCHAR_TABLE (tem
);
666 tem
= XBUFFER (w
->buffer
)->display_table
;
667 if (DISP_TABLE_P (tem
))
668 return XCHAR_TABLE (tem
);
669 tem
= Vstandard_display_table
;
670 if (DISP_TABLE_P (tem
))
671 return XCHAR_TABLE (tem
);
675 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
676 "Set WINDOW's display-table to TABLE.")
678 register Lisp_Object window
, table
;
680 register struct window
*w
;
681 register Lisp_Object z
; /* Return value. */
683 w
= decode_window (window
);
684 w
->display_table
= table
;
688 /* Record info on buffer window w is displaying
689 when it is about to cease to display that buffer. */
692 register struct window
*w
;
697 if (XBUFFER (buf
) != XMARKER (w
->pointm
)->buffer
)
700 if (w
== XWINDOW (XBUFFER (buf
)->last_selected_window
))
701 XBUFFER (buf
)->last_selected_window
= Qnil
;
704 if (w
== XWINDOW (selected_window
)
705 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
706 /* Do this except when the selected window's buffer
707 is being removed from some other window. */
709 /* last_window_start records the start position that this buffer
710 had in the last window to be disconnected from it.
711 Now that this statement is unconditional,
712 it is possible for the buffer to be displayed in the
713 selected window, while last_window_start reflects another
714 window which was recently showing the same buffer.
715 Some people might say that might be a good thing. Let's see. */
716 XBUFFER (buf
)->last_window_start
= marker_position (w
->start
);
718 /* Point in the selected window's buffer
719 is actually stored in that buffer, and the window's pointm isn't used.
720 So don't clobber point in that buffer. */
721 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
))
722 BUF_PT (XBUFFER (buf
))
723 = clip_to_bounds (BUF_BEGV (XBUFFER (buf
)),
724 marker_position (w
->pointm
),
725 BUF_ZV (XBUFFER (buf
)));
728 /* Put replacement into the window structure in place of old. */
730 replace_window (old
, replacement
)
731 Lisp_Object old
, replacement
;
733 register Lisp_Object tem
;
734 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
736 /* If OLD is its frame's root_window, then replacement is the new
737 root_window for that frame. */
739 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
740 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
745 p
->height
= o
->height
;
747 p
->next
= tem
= o
->next
;
749 XWINDOW (tem
)->prev
= replacement
;
751 p
->prev
= tem
= o
->prev
;
753 XWINDOW (tem
)->next
= replacement
;
755 p
->parent
= tem
= o
->parent
;
758 if (EQ (XWINDOW (tem
)->vchild
, old
))
759 XWINDOW (tem
)->vchild
= replacement
;
760 if (EQ (XWINDOW (tem
)->hchild
, old
))
761 XWINDOW (tem
)->hchild
= replacement
;
764 /*** Here, if replacement is a vertical combination
765 and so is its new parent, we should make replacement's
766 children be children of that parent instead. ***/
769 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
770 "Remove WINDOW from the display. Default is selected window.")
772 register Lisp_Object window
;
774 register Lisp_Object tem
, parent
, sib
;
775 register struct window
*p
;
776 register struct window
*par
;
778 /* Because this function is called by other C code on non-leaf
779 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
780 so we can't decode_window here. */
782 window
= selected_window
;
784 CHECK_WINDOW (window
, 0);
785 p
= XWINDOW (window
);
787 /* It's okay to delete an already-deleted window. */
795 error ("Attempt to delete minibuffer or sole ordinary window");
796 par
= XWINDOW (parent
);
798 windows_or_buffers_changed
++;
799 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (p
))) = 1;
801 /* Are we trying to delete any frame's selected window? */
803 Lisp_Object frame
, pwindow
;
805 /* See if the frame's selected window is either WINDOW
806 or any subwindow of it, by finding all that window's parents
807 and comparing each one with WINDOW. */
808 frame
= WINDOW_FRAME (XWINDOW (window
));
809 pwindow
= FRAME_SELECTED_WINDOW (XFRAME (frame
));
811 while (!NILP (pwindow
))
813 if (EQ (window
, pwindow
))
815 pwindow
= XWINDOW (pwindow
)->parent
;
818 if (EQ (window
, pwindow
))
820 Lisp_Object alternative
;
821 alternative
= Fnext_window (window
, Qlambda
, Qnil
);
823 /* If we're about to delete the selected window on the
824 selected frame, then we should use Fselect_window to select
825 the new window. On the other hand, if we're about to
826 delete the selected window on any other frame, we shouldn't do
827 anything but set the frame's selected_window slot. */
828 if (EQ (window
, selected_window
))
829 Fselect_window (alternative
);
831 FRAME_SELECTED_WINDOW (XFRAME (frame
)) = alternative
;
836 /* tem is null for dummy parent windows
837 (which have inferiors but not any contents themselves) */
841 unchain_marker (p
->pointm
);
842 unchain_marker (p
->start
);
847 XWINDOW (tem
)->prev
= p
->prev
;
851 XWINDOW (tem
)->next
= p
->next
;
853 if (EQ (window
, par
->hchild
))
854 par
->hchild
= p
->next
;
855 if (EQ (window
, par
->vchild
))
856 par
->vchild
= p
->next
;
858 /* Find one of our siblings to give our space to. */
862 /* If p gives its space to its next sibling, that sibling needs
863 to have its top/left side pulled back to where p's is.
864 set_window_{height,width} will re-position the sibling's
867 XWINDOW (sib
)->top
= p
->top
;
868 XWINDOW (sib
)->left
= p
->left
;
871 /* Stretch that sibling. */
872 if (!NILP (par
->vchild
))
873 set_window_height (sib
,
874 XFASTINT (XWINDOW (sib
)->height
) + XFASTINT (p
->height
),
876 if (!NILP (par
->hchild
))
877 set_window_width (sib
,
878 XFASTINT (XWINDOW (sib
)->width
) + XFASTINT (p
->width
),
881 /* If parent now has only one child,
882 put the child into the parent's place. */
886 if (NILP (XWINDOW (tem
)->next
))
887 replace_window (parent
, tem
);
889 /* Since we may be deleting combination windows, we must make sure that
890 not only p but all its children have been marked as deleted. */
891 if (! NILP (p
->hchild
))
892 delete_all_subwindows (XWINDOW (p
->hchild
));
893 else if (! NILP (p
->vchild
))
894 delete_all_subwindows (XWINDOW (p
->vchild
));
896 /* Mark this window as deleted. */
897 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
903 extern Lisp_Object
next_frame (), prev_frame ();
905 /* This comment supplies the doc string for `next-window',
906 for make-docfile to see. We cannot put this in the real DEFUN
907 due to limits in the Unix cpp.
909 DEFUN ("next-window", Ffoo, Sfoo, 0, 3, 0,
910 "Return next window after WINDOW in canonical ordering of windows.\n\
911 If omitted, WINDOW defaults to the selected window.\n\
913 Optional second arg MINIBUF t means count the minibuffer window even\n\
914 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
915 it is active. MINIBUF neither t nor nil means not to count the\n\
916 minibuffer even if it is active.\n\
918 Several frames may share a single minibuffer; if the minibuffer\n\
919 counts, all windows on all frames that share that minibuffer count\n\
920 too. Therefore, `next-window' can be used to iterate through the\n\
921 set of windows even when the minibuffer is on another frame. If the\n\
922 minibuffer does not count, only windows from WINDOW's frame count.\n\
924 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
925 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
926 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
927 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
928 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
929 Anything else means restrict to WINDOW's frame.\n\
931 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
932 `next-window' to iterate through the entire cycle of acceptable\n\
933 windows, eventually ending up back at the window you started with.\n\
934 `previous-window' traverses the same cycle, in the reverse order.")
935 (window, minibuf, all_frames) */
937 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
939 (window
, minibuf
, all_frames
)
940 register Lisp_Object window
, minibuf
, all_frames
;
942 register Lisp_Object tem
;
943 Lisp_Object start_window
;
946 window
= selected_window
;
948 CHECK_LIVE_WINDOW (window
, 0);
950 start_window
= window
;
952 /* minibuf == nil may or may not include minibuffers.
953 Decide if it does. */
955 minibuf
= (minibuf_level
? minibuf_window
: Qlambda
);
956 else if (! EQ (minibuf
, Qt
))
958 /* Now minibuf can be t => count all minibuffer windows,
959 lambda => count none of them,
960 or a specific minibuffer window (the active one) to count. */
962 /* all_frames == nil doesn't specify which frames to include. */
963 if (NILP (all_frames
))
964 all_frames
= (! EQ (minibuf
, Qlambda
)
965 ? (FRAME_MINIBUF_WINDOW
968 (XWINDOW (window
)))))
970 else if (EQ (all_frames
, Qvisible
))
972 else if (XFASTINT (all_frames
) == 0)
974 else if (FRAMEP (all_frames
) && ! EQ (all_frames
, Fwindow_frame (window
)))
975 /* If all_frames is a frame and window arg isn't on that frame, just
976 return the first window on the frame. */
977 return Fframe_first_window (all_frames
);
978 else if (! EQ (all_frames
, Qt
))
980 /* Now all_frames is t meaning search all frames,
981 nil meaning search just current frame,
982 visible meaning search just visible frames,
983 0 meaning search visible and iconified frames,
984 or a window, meaning search the frame that window belongs to. */
986 /* Do this loop at least once, to get the next window, and perhaps
987 again, if we hit the minibuffer and that is not acceptable. */
990 /* Find a window that actually has a next one. This loop
991 climbs up the tree. */
992 while (tem
= XWINDOW (window
)->next
, NILP (tem
))
993 if (tem
= XWINDOW (window
)->parent
, !NILP (tem
))
997 /* We've reached the end of this frame.
998 Which other frames are acceptable? */
999 tem
= WINDOW_FRAME (XWINDOW (window
));
1000 if (! NILP (all_frames
))
1005 tem
= next_frame (tem
, all_frames
);
1006 /* In the case where the minibuffer is active,
1007 and we include its frame as well as the selected one,
1008 next_frame may get stuck in that frame.
1009 If that happens, go back to the selected frame
1010 so we can complete the cycle. */
1012 XSETFRAME (tem
, selected_frame
);
1014 tem
= FRAME_ROOT_WINDOW (XFRAME (tem
));
1021 /* If we're in a combination window, find its first child and
1022 recurse on that. Otherwise, we've found the window we want. */
1025 if (!NILP (XWINDOW (window
)->hchild
))
1026 window
= XWINDOW (window
)->hchild
;
1027 else if (!NILP (XWINDOW (window
)->vchild
))
1028 window
= XWINDOW (window
)->vchild
;
1032 /* Which windows are acceptable?
1033 Exit the loop and accept this window if
1034 this isn't a minibuffer window,
1035 or we're accepting all minibuffer windows,
1036 or this is the active minibuffer and we are accepting that one, or
1037 we've come all the way around and we're back at the original window. */
1038 while (MINI_WINDOW_P (XWINDOW (window
))
1039 && ! EQ (minibuf
, Qt
)
1040 && ! EQ (minibuf
, window
)
1041 && ! EQ (window
, start_window
));
1046 /* This comment supplies the doc string for `previous-window',
1047 for make-docfile to see. We cannot put this in the real DEFUN
1048 due to limits in the Unix cpp.
1050 DEFUN ("previous-window", Ffoo, Sfoo, 0, 3, 0,
1051 "Return the window preceding WINDOW in canonical ordering of windows.\n\
1052 If omitted, WINDOW defaults to the selected window.\n\
1054 Optional second arg MINIBUF t means count the minibuffer window even\n\
1055 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1056 it is active. MINIBUF neither t nor nil means not to count the\n\
1057 minibuffer even if it is active.\n\
1059 Several frames may share a single minibuffer; if the minibuffer\n\
1060 counts, all windows on all frames that share that minibuffer count\n\
1061 too. Therefore, `previous-window' can be used to iterate through\n\
1062 the set of windows even when the minibuffer is on another frame. If\n\
1063 the minibuffer does not count, only windows from WINDOW's frame count\n\
1065 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1066 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1067 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1068 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1069 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1070 Anything else means restrict to WINDOW's frame.\n\
1072 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1073 `previous-window' to iterate through the entire cycle of acceptable\n\
1074 windows, eventually ending up back at the window you started with.\n\
1075 `next-window' traverses the same cycle, in the reverse order.")
1076 (window, minibuf, all_frames) */
1079 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1081 (window
, minibuf
, all_frames
)
1082 register Lisp_Object window
, minibuf
, all_frames
;
1084 register Lisp_Object tem
;
1085 Lisp_Object start_window
;
1088 window
= selected_window
;
1090 CHECK_LIVE_WINDOW (window
, 0);
1092 start_window
= window
;
1094 /* minibuf == nil may or may not include minibuffers.
1095 Decide if it does. */
1097 minibuf
= (minibuf_level
? minibuf_window
: Qlambda
);
1098 else if (! EQ (minibuf
, Qt
))
1100 /* Now minibuf can be t => count all minibuffer windows,
1101 lambda => count none of them,
1102 or a specific minibuffer window (the active one) to count. */
1104 /* all_frames == nil doesn't specify which frames to include.
1105 Decide which frames it includes. */
1106 if (NILP (all_frames
))
1107 all_frames
= (! EQ (minibuf
, Qlambda
)
1108 ? (FRAME_MINIBUF_WINDOW
1111 (XWINDOW (window
)))))
1113 else if (EQ (all_frames
, Qvisible
))
1115 else if (XFASTINT (all_frames
) == 0)
1117 else if (FRAMEP (all_frames
) && ! EQ (all_frames
, Fwindow_frame (window
)))
1118 /* If all_frames is a frame and window arg isn't on that frame, just
1119 return the first window on the frame. */
1120 return Fframe_first_window (all_frames
);
1121 else if (! EQ (all_frames
, Qt
))
1123 /* Now all_frames is t meaning search all frames,
1124 nil meaning search just current frame,
1125 visible meaning search just visible frames,
1126 0 meaning search visible and iconified frames,
1127 or a window, meaning search the frame that window belongs to. */
1129 /* Do this loop at least once, to get the previous window, and perhaps
1130 again, if we hit the minibuffer and that is not acceptable. */
1133 /* Find a window that actually has a previous one. This loop
1134 climbs up the tree. */
1135 while (tem
= XWINDOW (window
)->prev
, NILP (tem
))
1136 if (tem
= XWINDOW (window
)->parent
, !NILP (tem
))
1140 /* We have found the top window on the frame.
1141 Which frames are acceptable? */
1142 tem
= WINDOW_FRAME (XWINDOW (window
));
1143 if (! NILP (all_frames
))
1144 /* It's actually important that we use prev_frame here,
1145 rather than next_frame. All the windows acceptable
1146 according to the given parameters should form a ring;
1147 Fnext_window and Fprevious_window should go back and
1148 forth around the ring. If we use next_frame here,
1149 then Fnext_window and Fprevious_window take different
1150 paths through the set of acceptable windows.
1151 window_loop assumes that these `ring' requirement are
1157 tem
= prev_frame (tem
, all_frames
);
1158 /* In the case where the minibuffer is active,
1159 and we include its frame as well as the selected one,
1160 next_frame may get stuck in that frame.
1161 If that happens, go back to the selected frame
1162 so we can complete the cycle. */
1164 XSETFRAME (tem
, selected_frame
);
1166 /* If this frame has a minibuffer, find that window first,
1167 because it is conceptually the last window in that frame. */
1168 if (FRAME_HAS_MINIBUF_P (XFRAME (tem
)))
1169 tem
= FRAME_MINIBUF_WINDOW (XFRAME (tem
));
1171 tem
= FRAME_ROOT_WINDOW (XFRAME (tem
));
1177 /* If we're in a combination window, find its last child and
1178 recurse on that. Otherwise, we've found the window we want. */
1181 if (!NILP (XWINDOW (window
)->hchild
))
1182 window
= XWINDOW (window
)->hchild
;
1183 else if (!NILP (XWINDOW (window
)->vchild
))
1184 window
= XWINDOW (window
)->vchild
;
1186 while (tem
= XWINDOW (window
)->next
, !NILP (tem
))
1190 /* Which windows are acceptable?
1191 Exit the loop and accept this window if
1192 this isn't a minibuffer window,
1193 or we're accepting all minibuffer windows,
1194 or this is the active minibuffer and we are accepting that one, or
1195 we've come all the way around and we're back at the original window. */
1196 while (MINI_WINDOW_P (XWINDOW (window
))
1197 && ! EQ (minibuf
, Qt
)
1198 && ! EQ (minibuf
, window
)
1199 && ! EQ (window
, start_window
));
1204 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1205 "Select the ARG'th different window on this frame.\n\
1206 All windows on current frame are arranged in a cyclic order.\n\
1207 This command selects the window ARG steps away in that order.\n\
1208 A negative ARG moves in the opposite order. If the optional second\n\
1209 argument ALL_FRAMES is non-nil, cycle through all frames.")
1211 register Lisp_Object arg
, all_frames
;
1214 register Lisp_Object w
;
1216 CHECK_NUMBER (arg
, 0);
1217 w
= selected_window
;
1222 w
= Fnext_window (w
, Qnil
, all_frames
);
1227 w
= Fprevious_window (w
, Qnil
, all_frames
);
1234 /* Look at all windows, performing an operation specified by TYPE
1236 If FRAMES is Qt, look at all frames;
1237 Qnil, look at just the selected frame;
1238 Qvisible, look at visible frames;
1239 a frame, just look at windows on that frame.
1240 If MINI is non-zero, perform the operation on minibuffer windows too.
1246 GET_BUFFER_WINDOW
, /* Arg is buffer */
1247 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1248 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1249 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1251 UNSHOW_BUFFER
/* Arg is buffer */
1255 window_loop (type
, obj
, mini
, frames
)
1256 enum window_loop type
;
1257 register Lisp_Object obj
, frames
;
1260 register Lisp_Object w
;
1261 register Lisp_Object best_window
;
1262 register Lisp_Object next_window
;
1263 register Lisp_Object last_window
;
1265 Lisp_Object frame_arg
;
1268 /* If we're only looping through windows on a particular frame,
1269 frame points to that frame. If we're looping through windows
1270 on all frames, frame is 0. */
1271 if (FRAMEP (frames
))
1272 frame
= XFRAME (frames
);
1273 else if (NILP (frames
))
1274 frame
= selected_frame
;
1278 frame_arg
= Qlambda
;
1279 else if (XFASTINT (frames
) == 0)
1281 else if (EQ (frames
, Qvisible
))
1284 /* frame_arg is Qlambda to stick to one frame,
1285 Qvisible to consider all visible frames,
1288 /* Pick a window to start with. */
1292 w
= FRAME_SELECTED_WINDOW (frame
);
1294 w
= FRAME_SELECTED_WINDOW (selected_frame
);
1296 /* Figure out the last window we're going to mess with. Since
1297 Fnext_window, given the same options, is guaranteed to go in a
1298 ring, we can just use Fprevious_window to find the last one.
1300 We can't just wait until we hit the first window again, because
1301 it might be deleted. */
1303 last_window
= Fprevious_window (w
, mini
? Qt
: Qnil
, frame_arg
);
1308 FRAME_PTR w_frame
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1310 /* Pick the next window now, since some operations will delete
1311 the current window. */
1312 next_window
= Fnext_window (w
, mini
? Qt
: Qnil
, frame_arg
);
1314 /* Note that we do not pay attention here to whether
1315 the frame is visible, since Fnext_window skips non-visible frames
1316 if that is desired, under the control of frame_arg. */
1317 if (! MINI_WINDOW_P (XWINDOW (w
))
1318 || (mini
&& minibuf_level
> 0))
1321 case GET_BUFFER_WINDOW
:
1322 if (XBUFFER (XWINDOW (w
)->buffer
) == XBUFFER (obj
)
1323 /* Don't find any minibuffer window
1324 except the one that is currently in use. */
1325 && (MINI_WINDOW_P (XWINDOW (w
))
1326 ? EQ (w
, minibuf_window
) : 1))
1330 case GET_LRU_WINDOW
:
1331 /* t as arg means consider only full-width windows */
1332 if (!NILP (obj
) && !WINDOW_FULL_WIDTH_P (XWINDOW (w
)))
1334 /* Ignore dedicated windows and minibuffers. */
1335 if (MINI_WINDOW_P (XWINDOW (w
))
1336 || !NILP (XWINDOW (w
)->dedicated
))
1338 if (NILP (best_window
)
1339 || (XFASTINT (XWINDOW (best_window
)->use_time
)
1340 > XFASTINT (XWINDOW (w
)->use_time
)))
1344 case DELETE_OTHER_WINDOWS
:
1345 if (XWINDOW (w
) != XWINDOW (obj
))
1349 case DELETE_BUFFER_WINDOWS
:
1350 if (EQ (XWINDOW (w
)->buffer
, obj
))
1352 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1354 /* If this window is dedicated, and in a frame of its own,
1356 if (EQ (w
, FRAME_ROOT_WINDOW (f
))
1357 && !NILP (XWINDOW (w
)->dedicated
)
1358 && other_visible_frames (f
))
1360 /* Skip the other windows on this frame.
1361 There might be one, the minibuffer! */
1362 if (! EQ (w
, last_window
))
1363 while (f
== XFRAME (WINDOW_FRAME (XWINDOW (next_window
))))
1365 /* As we go, check for the end of the loop.
1366 We mustn't start going around a second time. */
1367 if (EQ (next_window
, last_window
))
1372 next_window
= Fnext_window (next_window
,
1376 /* Now we can safely delete the frame. */
1377 Fdelete_frame (WINDOW_FRAME (XWINDOW (w
)), Qnil
);
1380 /* If we're deleting the buffer displayed in the only window
1381 on the frame, find a new buffer to display there. */
1382 if (NILP (XWINDOW (w
)->parent
))
1384 Lisp_Object new_buffer
;
1385 new_buffer
= Fother_buffer (obj
, Qnil
);
1386 if (NILP (new_buffer
))
1388 = Fget_buffer_create (build_string ("*scratch*"));
1389 Fset_window_buffer (w
, new_buffer
);
1390 if (EQ (w
, selected_window
))
1391 Fset_buffer (XWINDOW (w
)->buffer
);
1398 case GET_LARGEST_WINDOW
:
1399 /* Ignore dedicated windows and minibuffers. */
1400 if (MINI_WINDOW_P (XWINDOW (w
))
1401 || !NILP (XWINDOW (w
)->dedicated
))
1404 struct window
*best_window_ptr
= XWINDOW (best_window
);
1405 struct window
*w_ptr
= XWINDOW (w
);
1406 if (NILP (best_window
)
1407 || (XFASTINT (w_ptr
->height
) * XFASTINT (w_ptr
->width
)
1408 > (XFASTINT (best_window_ptr
->height
)
1409 * XFASTINT (best_window_ptr
->width
))))
1415 if (EQ (XWINDOW (w
)->buffer
, obj
))
1417 /* Find another buffer to show in this window. */
1418 Lisp_Object another_buffer
;
1419 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1420 another_buffer
= Fother_buffer (obj
, Qnil
);
1421 if (NILP (another_buffer
))
1423 = Fget_buffer_create (build_string ("*scratch*"));
1424 /* If this window is dedicated, and in a frame of its own,
1426 if (EQ (w
, FRAME_ROOT_WINDOW (f
))
1427 && !NILP (XWINDOW (w
)->dedicated
)
1428 && other_visible_frames (f
))
1430 /* Skip the other windows on this frame.
1431 There might be one, the minibuffer! */
1432 if (! EQ (w
, last_window
))
1433 while (f
== XFRAME (WINDOW_FRAME (XWINDOW (next_window
))))
1435 /* As we go, check for the end of the loop.
1436 We mustn't start going around a second time. */
1437 if (EQ (next_window
, last_window
))
1442 next_window
= Fnext_window (next_window
,
1446 /* Now we can safely delete the frame. */
1447 Fdelete_frame (WINDOW_FRAME (XWINDOW (w
)), Qnil
);
1451 /* Otherwise show a different buffer in the window. */
1452 XWINDOW (w
)->dedicated
= Qnil
;
1453 Fset_window_buffer (w
, another_buffer
);
1454 if (EQ (w
, selected_window
))
1455 Fset_buffer (XWINDOW (w
)->buffer
);
1461 if (EQ (w
, last_window
))
1470 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 1, 0,
1471 "Return the window least recently selected or used for display.\n\
1472 If optional argument FRAME is `visible', search all visible frames.\n\
1473 If FRAME is 0, search all visible and iconified frames.\n\
1474 If FRAME is t, search all frames.\n\
1475 If FRAME is nil, search only the selected frame.\n\
1476 If FRAME is a frame, search only that frame.")
1480 register Lisp_Object w
;
1481 /* First try for a window that is full-width */
1482 w
= window_loop (GET_LRU_WINDOW
, Qt
, 0, frame
);
1483 if (!NILP (w
) && !EQ (w
, selected_window
))
1485 /* If none of them, try the rest */
1486 return window_loop (GET_LRU_WINDOW
, Qnil
, 0, frame
);
1489 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 1, 0,
1490 "Return the largest window in area.\n\
1491 If optional argument FRAME is `visible', search all visible frames.\n\
1492 If FRAME is 0, search all visible and iconified frames.\n\
1493 If FRAME is t, search all frames.\n\
1494 If FRAME is nil, search only the selected frame.\n\
1495 If FRAME is a frame, search only that frame.")
1499 return window_loop (GET_LARGEST_WINDOW
, Qnil
, 0,
1503 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
1504 "Return a window currently displaying BUFFER, or nil if none.\n\
1505 If optional argument FRAME is `visible', search all visible frames.\n\
1506 If optional argument FRAME is 0, search all visible and iconified frames.\n\
1507 If FRAME is t, search all frames.\n\
1508 If FRAME is nil, search only the selected frame.\n\
1509 If FRAME is a frame, search only that frame.")
1511 Lisp_Object buffer
, frame
;
1513 buffer
= Fget_buffer (buffer
);
1514 if (BUFFERP (buffer
))
1515 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
1520 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
1522 "Make WINDOW (or the selected window) fill its frame.\n\
1523 Only the frame WINDOW is on is affected.\n\
1524 This function tries to reduce display jumps\n\
1525 by keeping the text previously visible in WINDOW\n\
1526 in the same place on the frame. Doing this depends on\n\
1527 the value of (window-start WINDOW), so if calling this function\n\
1528 in a program gives strange scrolling, make sure the window-start\n\
1529 value is reasonable when this function is called.")
1538 window
= selected_window
;
1540 CHECK_LIVE_WINDOW (window
, 0);
1542 w
= XWINDOW (window
);
1544 startpos
= marker_position (w
->start
);
1545 top
= XFASTINT (w
->top
) - FRAME_MENU_BAR_LINES (XFRAME (WINDOW_FRAME (w
)));
1547 if (MINI_WINDOW_P (w
) && top
> 0)
1548 error ("Can't expand minibuffer to full frame");
1550 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
1552 /* Try to minimize scrolling, by setting the window start to the point
1553 will cause the text at the old window start to be at the same place
1554 on the frame. But don't try to do this if the window start is
1555 outside the visible portion (as might happen when the display is
1556 not current, due to typeahead). */
1557 if (startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
1558 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
1560 struct position pos
;
1561 struct buffer
*obuf
= current_buffer
;
1563 Fset_buffer (w
->buffer
);
1564 /* This computation used to temporarily move point, but that can
1565 have unwanted side effects due to text properties. */
1566 pos
= *vmotion (startpos
, -top
, w
);
1567 Fset_marker (w
->start
, make_number (pos
.bufpos
), w
->buffer
);
1568 w
->start_at_line_beg
= ((pos
.bufpos
== BEGV
1569 || FETCH_CHAR (pos
.bufpos
- 1) == '\n') ? Qt
1571 /* We need to do this, so that the window-scroll-functions
1573 w
->force_start
= Qt
;
1575 set_buffer_internal (obuf
);
1580 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
1581 1, 2, "bDelete windows on (buffer): ",
1582 "Delete all windows showing BUFFER.\n\
1583 Optional second argument FRAME controls which frames are affected.\n\
1584 If nil or omitted, delete all windows showing BUFFER in any frame.\n\
1585 If t, delete only windows showing BUFFER in the selected frame.\n\
1586 If `visible', delete all windows showing BUFFER in any visible frame.\n\
1587 If a frame, delete only windows showing BUFFER in that frame.")
1589 Lisp_Object buffer
, frame
;
1591 /* FRAME uses t and nil to mean the opposite of what window_loop
1593 if (! FRAMEP (frame
))
1594 frame
= NILP (frame
) ? Qt
: Qnil
;
1598 buffer
= Fget_buffer (buffer
);
1599 CHECK_BUFFER (buffer
, 0);
1600 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
1605 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
1606 Sreplace_buffer_in_windows
,
1607 1, 1, "bReplace buffer in windows: ",
1608 "Replace BUFFER with some other buffer in all windows showing it.")
1614 buffer
= Fget_buffer (buffer
);
1615 CHECK_BUFFER (buffer
, 0);
1616 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
1621 /* Replace BUFFER with some other buffer in all windows
1622 of all frames, even those on other keyboards. */
1625 replace_buffer_in_all_windows (buffer
)
1629 Lisp_Object tail
, frame
;
1631 /* A single call to window_loop won't do the job
1632 because it only considers frames on the current keyboard.
1633 So loop manually over frames, and handle each one. */
1634 FOR_EACH_FRAME (tail
, frame
)
1635 window_loop (UNSHOW_BUFFER
, buffer
, 0, frame
);
1637 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
1641 /* Set the height of WINDOW and all its inferiors. */
1643 /* The smallest acceptable dimensions for a window. Anything smaller
1644 might crash Emacs. */
1645 #define MIN_SAFE_WINDOW_WIDTH (2)
1646 #define MIN_SAFE_WINDOW_HEIGHT (2)
1648 /* Make sure that window_min_height and window_min_width are
1649 not too small; if they are, set them to safe minima. */
1652 check_min_window_sizes ()
1654 /* Smaller values might permit a crash. */
1655 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
1656 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
1657 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
1658 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
1661 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
1662 minimum allowable size. */
1664 check_frame_size (frame
, rows
, cols
)
1668 /* For height, we have to see:
1669 whether the frame has a minibuffer,
1670 whether it wants a mode line, and
1671 whether it has a menu bar. */
1673 (FRAME_MINIBUF_ONLY_P (frame
) ? MIN_SAFE_WINDOW_HEIGHT
- 1
1674 : (! FRAME_HAS_MINIBUF_P (frame
)) ? MIN_SAFE_WINDOW_HEIGHT
1675 : 2 * MIN_SAFE_WINDOW_HEIGHT
- 1);
1676 if (FRAME_MENU_BAR_LINES (frame
) > 0)
1677 min_height
+= FRAME_MENU_BAR_LINES (frame
);
1679 if (*rows
< min_height
)
1681 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
1682 *cols
= MIN_SAFE_WINDOW_WIDTH
;
1685 /* Normally the window is deleted if it gets too small.
1686 nodelete nonzero means do not do this.
1687 (The caller should check later and do so if appropriate) */
1689 set_window_height (window
, height
, nodelete
)
1694 register struct window
*w
= XWINDOW (window
);
1695 register struct window
*c
;
1696 int oheight
= XFASTINT (w
->height
);
1697 int top
, pos
, lastbot
, opos
, lastobot
;
1700 check_min_window_sizes ();
1703 && ! NILP (w
->parent
)
1704 && height
< window_min_height
)
1706 Fdelete_window (window
);
1710 XSETFASTINT (w
->last_modified
, 0);
1711 XSETFASTINT (w
->last_overlay_modified
, 0);
1712 windows_or_buffers_changed
++;
1713 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
1715 XSETFASTINT (w
->height
, height
);
1716 if (!NILP (w
->hchild
))
1718 for (child
= w
->hchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1720 XWINDOW (child
)->top
= w
->top
;
1721 set_window_height (child
, height
, nodelete
);
1724 else if (!NILP (w
->vchild
))
1726 lastbot
= top
= XFASTINT (w
->top
);
1728 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
1730 c
= XWINDOW (child
);
1732 opos
= lastobot
+ XFASTINT (c
->height
);
1734 XSETFASTINT (c
->top
, lastbot
);
1736 pos
= (((opos
* height
) << 1) + oheight
) / (oheight
<< 1);
1738 /* Avoid confusion: inhibit deletion of child if becomes too small */
1739 set_window_height (child
, pos
+ top
- lastbot
, 1);
1741 /* Now advance child to next window,
1742 and set lastbot if child was not just deleted. */
1743 lastbot
= pos
+ top
;
1746 /* Now delete any children that became too small. */
1748 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1750 set_window_height (child
, XINT (XWINDOW (child
)->height
), 0);
1755 /* Recursively set width of WINDOW and its inferiors. */
1757 set_window_width (window
, width
, nodelete
)
1762 register struct window
*w
= XWINDOW (window
);
1763 register struct window
*c
;
1764 int owidth
= XFASTINT (w
->width
);
1765 int left
, pos
, lastright
, opos
, lastoright
;
1768 if (!nodelete
&& width
< window_min_width
&& !NILP (w
->parent
))
1770 Fdelete_window (window
);
1774 XSETFASTINT (w
->last_modified
, 0);
1775 XSETFASTINT (w
->last_overlay_modified
, 0);
1776 windows_or_buffers_changed
++;
1777 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
1779 XSETFASTINT (w
->width
, width
);
1780 if (!NILP (w
->vchild
))
1782 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1784 XWINDOW (child
)->left
= w
->left
;
1785 set_window_width (child
, width
, nodelete
);
1788 else if (!NILP (w
->hchild
))
1790 lastright
= left
= XFASTINT (w
->left
);
1792 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
1794 c
= XWINDOW (child
);
1796 opos
= lastoright
+ XFASTINT (c
->width
);
1798 XSETFASTINT (c
->left
, lastright
);
1800 pos
= (((opos
* width
) << 1) + owidth
) / (owidth
<< 1);
1802 /* Inhibit deletion for becoming too small */
1803 set_window_width (child
, pos
+ left
- lastright
, 1);
1805 /* Now advance child to next window,
1806 and set lastright if child was not just deleted. */
1807 lastright
= pos
+ left
, lastoright
= opos
;
1809 /* Delete children that became too small */
1811 for (child
= w
->hchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1813 set_window_width (child
, XINT (XWINDOW (child
)->width
), 0);
1818 int window_select_count
;
1821 Fset_window_buffer_unwind (obuf
)
1828 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 2, 0,
1829 "Make WINDOW display BUFFER as its contents.\n\
1830 BUFFER can be a buffer or buffer name.")
1832 register Lisp_Object window
, buffer
;
1834 register Lisp_Object tem
;
1835 register struct window
*w
= decode_window (window
);
1836 int count
= specpdl_ptr
- specpdl
;
1838 buffer
= Fget_buffer (buffer
);
1839 CHECK_BUFFER (buffer
, 1);
1841 if (NILP (XBUFFER (buffer
)->name
))
1842 error ("Attempt to display deleted buffer");
1846 error ("Window is deleted");
1847 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
1848 is first being set up. */
1850 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
1851 error ("Window is dedicated to `%s'",
1852 XSTRING (XBUFFER (tem
)->name
)->data
);
1859 if (EQ (window
, selected_window
))
1860 XBUFFER (w
->buffer
)->last_selected_window
= window
;
1862 XSETFASTINT (w
->window_end_pos
, 0);
1863 w
->window_end_valid
= Qnil
;
1864 XSETFASTINT (w
->hscroll
, 0);
1865 Fset_marker (w
->pointm
,
1866 make_number (BUF_PT (XBUFFER (buffer
))),
1868 set_marker_restricted (w
->start
,
1869 make_number (XBUFFER (buffer
)->last_window_start
),
1871 w
->start_at_line_beg
= Qnil
;
1872 w
->force_start
= Qnil
;
1873 XSETFASTINT (w
->last_modified
, 0);
1874 XSETFASTINT (w
->last_overlay_modified
, 0);
1875 windows_or_buffers_changed
++;
1877 /* We must select BUFFER for running the window-scroll-functions.
1878 If WINDOW is selected, switch permanently.
1879 Otherwise, switch but go back to the ambient buffer afterward. */
1880 if (EQ (window
, selected_window
))
1881 Fset_buffer (buffer
);
1882 /* We can't check ! NILP (Vwindow_scroll_functions) here
1883 because that might itself be a local variable. */
1884 else if (window_initialized
)
1886 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
1887 Fset_buffer (buffer
);
1890 if (! NILP (Vwindow_scroll_functions
))
1891 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
1892 Fmarker_position (w
->start
));
1894 unbind_to (count
, Qnil
);
1899 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 1, 0,
1900 "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\
1901 The main editor command loop selects the buffer of the selected window\n\
1902 before each command.")
1904 register Lisp_Object window
;
1906 register struct window
*w
;
1907 register struct window
*ow
= XWINDOW (selected_window
);
1909 CHECK_LIVE_WINDOW (window
, 0);
1911 w
= XWINDOW (window
);
1913 if (NILP (w
->buffer
))
1914 error ("Trying to select deleted window or non-leaf window");
1916 XSETFASTINT (w
->use_time
, ++window_select_count
);
1917 if (EQ (window
, selected_window
))
1920 Fset_marker (ow
->pointm
, make_number (BUF_PT (XBUFFER (ow
->buffer
))),
1923 selected_window
= window
;
1924 if (XFRAME (WINDOW_FRAME (w
)) != selected_frame
)
1926 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
1927 /* Use this rather than Fhandle_switch_frame
1928 so that FRAME_FOCUS_FRAME is moved appropriately as we
1929 move around in the state where a minibuffer in a separate
1931 Fselect_frame (WINDOW_FRAME (w
), Qnil
);
1934 selected_frame
->selected_window
= window
;
1936 record_buffer (w
->buffer
);
1937 Fset_buffer (w
->buffer
);
1939 XBUFFER (w
->buffer
)->last_selected_window
= window
;
1941 /* Go to the point recorded in the window.
1942 This is important when the buffer is in more
1943 than one window. It also matters when
1944 redisplay_window has altered point after scrolling,
1945 because it makes the change only in the window. */
1947 register int new_point
= marker_position (w
->pointm
);
1948 if (new_point
< BEGV
)
1950 else if (new_point
> ZV
)
1956 windows_or_buffers_changed
++;
1960 /* Deiconify the frame containing the window WINDOW,
1961 unless it is the selected frame;
1964 The reason for the exception for the selected frame
1965 is that it seems better not to change the selected frames visibility
1966 merely because of displaying a different buffer in it.
1967 The deiconification is useful when a buffer gets shown in
1968 another frame that you were not using lately. */
1971 display_buffer_1 (window
)
1974 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
1975 FRAME_SAMPLE_VISIBILITY (f
);
1976 if (f
!= selected_frame
)
1978 if (FRAME_ICONIFIED_P (f
))
1979 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
1980 else if (FRAME_VISIBLE_P (f
))
1981 Fraise_frame (WINDOW_FRAME (XWINDOW (window
)));
1986 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
1987 "Returns non-nil if a buffer named BUFFER-NAME would be created specially.
1988 The value is actually t if the frame should be called with default frame
1989 parameters, and a list of frame parameters if they were specified.
1990 See `special-display-buffer-names', and `special-display-regexps'.")
1992 Lisp_Object buffer_name
;
1996 CHECK_STRING (buffer_name
, 1);
1998 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
2002 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
2006 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2008 Lisp_Object car
= XCAR (tem
);
2010 && fast_string_match (car
, buffer_name
) >= 0)
2012 else if (CONSP (car
)
2013 && STRINGP (XCAR (car
))
2014 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2020 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
2021 "Returns non-nil if a new buffer named BUFFER-NAME would use the same window.
2022 See `same-window-buffer-names' and `same-window-regexps'.")
2024 Lisp_Object buffer_name
;
2028 CHECK_STRING (buffer_name
, 1);
2030 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
2034 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
2038 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2040 Lisp_Object car
= XCAR (tem
);
2042 && fast_string_match (car
, buffer_name
) >= 0)
2044 else if (CONSP (car
)
2045 && STRINGP (XCAR (car
))
2046 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2052 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 2,
2053 "bDisplay buffer: \nP",
2054 "Make BUFFER appear in some window but don't select it.\n\
2055 BUFFER can be a buffer or a buffer name.\n\
2056 If BUFFER is shown already in some window, just use that one,\n\
2057 unless the window is the selected window and the optional second\n\
2058 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).\n\
2059 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.\n\
2060 Returns the window displaying BUFFER.\n\
2062 The variables `special-display-buffer-names', `special-display-regexps',\n\
2063 `same-window-buffer-names', and `same-window-regexps' customize how certain\n\
2064 buffer names are handled.")
2065 (buffer
, not_this_window
)
2066 register Lisp_Object buffer
, not_this_window
;
2068 register Lisp_Object window
, tem
;
2070 buffer
= Fget_buffer (buffer
);
2071 CHECK_BUFFER (buffer
, 0);
2073 if (!NILP (Vdisplay_buffer_function
))
2074 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
2076 if (NILP (not_this_window
)
2077 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
2078 return display_buffer_1 (selected_window
);
2080 /* See if the user has specified this buffer should appear
2081 in the selected window. */
2082 if (NILP (not_this_window
))
2084 tem
= Fsame_window_p (XBUFFER (buffer
)->name
);
2087 Fswitch_to_buffer (buffer
, Qnil
);
2088 return display_buffer_1 (selected_window
);
2092 /* If pop_up_frames,
2093 look for a window showing BUFFER on any visible or iconified frame.
2094 Otherwise search only the current frame. */
2095 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2096 XSETFASTINT (tem
, 0);
2098 XSETFRAME (tem
, last_nonminibuf_frame
);
2099 window
= Fget_buffer_window (buffer
, tem
);
2101 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
2103 return display_buffer_1 (window
);
2106 /* Certain buffer names get special handling. */
2107 if (!NILP (Vspecial_display_function
))
2109 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
2111 return call1 (Vspecial_display_function
, buffer
);
2113 return call2 (Vspecial_display_function
, buffer
, tem
);
2116 /* If there are no frames open that have more than a minibuffer,
2117 we need to create a new frame. */
2118 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2120 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2121 Fset_window_buffer (window
, buffer
);
2122 return display_buffer_1 (window
);
2126 || FRAME_MINIBUF_ONLY_P (selected_frame
)
2127 /* If the current frame is a special display frame,
2128 don't try to reuse its windows. */
2129 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (selected_frame
))->dedicated
)
2135 if (FRAME_MINIBUF_ONLY_P (selected_frame
))
2136 XSETFRAME (frames
, last_nonminibuf_frame
);
2137 /* Don't try to create a window if would get an error */
2138 if (split_height_threshold
< window_min_height
<< 1)
2139 split_height_threshold
= window_min_height
<< 1;
2141 /* Note that both Fget_largest_window and Fget_lru_window
2142 ignore minibuffers and dedicated windows.
2143 This means they can return nil. */
2145 /* If the frame we would try to split cannot be split,
2146 try other frames. */
2147 if (FRAME_NO_SPLIT_P (NILP (frames
) ? selected_frame
2148 : last_nonminibuf_frame
))
2150 /* Try visible frames first. */
2151 window
= Fget_largest_window (Qvisible
);
2152 /* If that didn't work, try iconified frames. */
2154 window
= Fget_largest_window (make_number (0));
2156 window
= Fget_largest_window (Qt
);
2159 window
= Fget_largest_window (frames
);
2161 /* If we got a tall enough full-width window that can be split,
2164 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2165 && window_height (window
) >= split_height_threshold
2166 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
2167 window
= Fsplit_window (window
, Qnil
, Qnil
);
2170 Lisp_Object upper
, lower
, other
;
2172 window
= Fget_lru_window (frames
);
2173 /* If the LRU window is selected, and big enough,
2174 and can be split, split it. */
2176 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2177 && (EQ (window
, selected_window
)
2178 || EQ (XWINDOW (window
)->parent
, Qnil
))
2179 && window_height (window
) >= window_min_height
<< 1)
2180 window
= Fsplit_window (window
, Qnil
, Qnil
);
2181 /* If Fget_lru_window returned nil, try other approaches. */
2182 /* Try visible frames first. */
2184 window
= Fget_largest_window (Qvisible
);
2185 /* If that didn't work, try iconified frames. */
2187 window
= Fget_largest_window (make_number (0));
2188 /* Try invisible frames. */
2190 window
= Fget_largest_window (Qt
);
2191 /* As a last resort, make a new frame. */
2193 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2194 /* If window appears above or below another,
2195 even out their heights. */
2196 other
= upper
= lower
= Qnil
;
2197 if (!NILP (XWINDOW (window
)->prev
))
2198 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
2199 if (!NILP (XWINDOW (window
)->next
))
2200 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
2202 /* Check that OTHER and WINDOW are vertically arrayed. */
2203 && XWINDOW (other
)->top
!= XWINDOW (window
)->top
2204 && XWINDOW (other
)->height
> XWINDOW (window
)->height
)
2206 int total
= XWINDOW (other
)->height
+ XWINDOW (window
)->height
;
2207 Lisp_Object old_selected_window
;
2208 old_selected_window
= selected_window
;
2210 selected_window
= upper
;
2211 change_window_height (total
/ 2 - XWINDOW (upper
)->height
, 0);
2212 selected_window
= old_selected_window
;
2217 window
= Fget_lru_window (Qnil
);
2219 Fset_window_buffer (window
, buffer
);
2220 return display_buffer_1 (window
);
2224 temp_output_buffer_show (buf
)
2225 register Lisp_Object buf
;
2227 register struct buffer
*old
= current_buffer
;
2228 register Lisp_Object window
;
2229 register struct window
*w
;
2232 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
2236 XBUFFER (buf
)->clip_changed
= 1;
2237 set_buffer_internal (old
);
2239 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
2240 call1 (Vtemp_buffer_show_function
, buf
);
2243 window
= Fdisplay_buffer (buf
, Qnil
);
2245 if (XFRAME (XWINDOW (window
)->frame
) != selected_frame
)
2246 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
2247 Vminibuf_scroll_window
= window
;
2248 w
= XWINDOW (window
);
2249 XSETFASTINT (w
->hscroll
, 0);
2250 set_marker_restricted (w
->start
, make_number (1), buf
);
2251 set_marker_restricted (w
->pointm
, make_number (1), buf
);
2253 /* Run temp-buffer-show-hook, with the chosen window selected. */
2254 if (!NILP (Vrun_hooks
))
2257 tem
= Fboundp (Qtemp_buffer_show_hook
);
2260 tem
= Fsymbol_value (Qtemp_buffer_show_hook
);
2263 int count
= specpdl_ptr
- specpdl
;
2265 /* Select the window that was chosen, for running the hook. */
2266 record_unwind_protect (Fset_window_configuration
,
2267 Fcurrent_window_configuration (Qnil
));
2269 Fselect_window (window
);
2270 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
2271 unbind_to (count
, Qnil
);
2279 make_dummy_parent (window
)
2283 register struct window
*o
, *p
;
2284 register struct Lisp_Vector
*vec
;
2287 o
= XWINDOW (window
);
2288 vec
= allocate_vectorlike ((EMACS_INT
)VECSIZE (struct window
));
2289 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
2290 vec
->contents
[i
] = ((struct Lisp_Vector
*)o
)->contents
[i
];
2291 vec
->size
= VECSIZE (struct window
);
2292 p
= (struct window
*)vec
;
2293 XSETWINDOW (new, p
);
2295 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
2297 /* Put new into window structure in place of window */
2298 replace_window (window
, new);
2311 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
2312 "Split WINDOW, putting SIZE lines in the first of the pair.\n\
2313 WINDOW defaults to selected one and SIZE to half its size.\n\
2314 If optional third arg HORFLAG is non-nil, split side by side\n\
2315 and put SIZE columns in the first of the pair.")
2316 (window
, size
, horflag
)
2317 Lisp_Object window
, size
, horflag
;
2319 register Lisp_Object
new;
2320 register struct window
*o
, *p
;
2322 register int size_int
;
2325 window
= selected_window
;
2327 CHECK_LIVE_WINDOW (window
, 0);
2329 o
= XWINDOW (window
);
2330 fo
= XFRAME (WINDOW_FRAME (o
));
2334 if (!NILP (horflag
))
2335 /* Calculate the size of the left-hand window, by dividing
2336 the usable space in columns by two. */
2337 size_int
= XFASTINT (o
->width
) >> 1;
2339 size_int
= XFASTINT (o
->height
) >> 1;
2343 CHECK_NUMBER (size
, 1);
2344 size_int
= XINT (size
);
2347 if (MINI_WINDOW_P (o
))
2348 error ("Attempt to split minibuffer window");
2349 else if (FRAME_NO_SPLIT_P (fo
))
2350 error ("Attempt to split unsplittable frame");
2352 check_min_window_sizes ();
2356 if (size_int
< window_min_height
)
2357 error ("Window height %d too small (after splitting)", size_int
);
2358 if (size_int
+ window_min_height
> XFASTINT (o
->height
))
2359 error ("Window height %d too small (after splitting)",
2360 XFASTINT (o
->height
) - size_int
);
2361 if (NILP (o
->parent
)
2362 || NILP (XWINDOW (o
->parent
)->vchild
))
2364 make_dummy_parent (window
);
2366 XWINDOW (new)->vchild
= window
;
2371 if (size_int
< window_min_width
)
2372 error ("Window width %d too small (after splitting)", size_int
);
2374 if (size_int
+ window_min_width
> XFASTINT (o
->width
))
2375 error ("Window width %d too small (after splitting)",
2376 XFASTINT (o
->width
) - size_int
);
2377 if (NILP (o
->parent
)
2378 || NILP (XWINDOW (o
->parent
)->hchild
))
2380 make_dummy_parent (window
);
2382 XWINDOW (new)->hchild
= window
;
2386 /* Now we know that window's parent is a vertical combination
2387 if we are dividing vertically, or a horizontal combination
2388 if we are making side-by-side windows */
2390 windows_or_buffers_changed
++;
2391 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
2392 new = make_window ();
2395 p
->frame
= o
->frame
;
2397 if (!NILP (p
->next
))
2398 XWINDOW (p
->next
)->prev
= new;
2401 p
->parent
= o
->parent
;
2404 Fset_window_buffer (new, o
->buffer
);
2406 /* Apportion the available frame space among the two new windows */
2408 if (!NILP (horflag
))
2410 p
->height
= o
->height
;
2412 XSETFASTINT (p
->width
, XFASTINT (o
->width
) - size_int
);
2413 XSETFASTINT (o
->width
, size_int
);
2414 XSETFASTINT (p
->left
, XFASTINT (o
->left
) + size_int
);
2419 p
->width
= o
->width
;
2420 XSETFASTINT (p
->height
, XFASTINT (o
->height
) - size_int
);
2421 XSETFASTINT (o
->height
, size_int
);
2422 XSETFASTINT (p
->top
, XFASTINT (o
->top
) + size_int
);
2428 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
2429 "Make current window ARG lines bigger.\n\
2430 From program, optional second arg non-nil means grow sideways ARG columns.")
2432 register Lisp_Object arg
, side
;
2434 CHECK_NUMBER (arg
, 0);
2435 change_window_height (XINT (arg
), !NILP (side
));
2439 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
2440 "Make current window ARG lines smaller.\n\
2441 From program, optional second arg non-nil means shrink sideways arg columns.")
2443 register Lisp_Object arg
, side
;
2445 CHECK_NUMBER (arg
, 0);
2446 change_window_height (-XINT (arg
), !NILP (side
));
2451 window_height (window
)
2454 register struct window
*p
= XWINDOW (window
);
2455 return XFASTINT (p
->height
);
2459 window_width (window
)
2462 register struct window
*p
= XWINDOW (window
);
2463 return XFASTINT (p
->width
);
2466 #define MINSIZE(w) \
2468 ? window_min_width \
2469 : (MINI_WINDOW_P (XWINDOW (w)) ? 1 : window_min_height))
2472 *(widthflag ? (int *) &(XWINDOW (w)->left) : (int *) &(XWINDOW (w)->top))
2474 #define CURSIZE(w) \
2475 *(widthflag ? (int *) &(XWINDOW (w)->width) : (int *) &(XWINDOW (w)->height))
2477 /* Unlike set_window_height, this function
2478 also changes the heights of the siblings so as to
2479 keep everything consistent. */
2481 change_window_height (delta
, widthflag
)
2485 register Lisp_Object parent
;
2487 register struct window
*p
;
2489 int (*sizefun
) () = widthflag
? window_width
: window_height
;
2490 register int (*setsizefun
) () = (widthflag
2492 : set_window_height
);
2494 check_min_window_sizes ();
2496 window
= selected_window
;
2499 p
= XWINDOW (window
);
2504 error ("No other window to side of this one");
2507 if (widthflag
? !NILP (XWINDOW (parent
)->hchild
)
2508 : !NILP (XWINDOW (parent
)->vchild
))
2513 sizep
= &CURSIZE (window
);
2516 register int maxdelta
;
2518 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - *sizep
2519 : !NILP (p
->next
) ? (*sizefun
) (p
->next
) - MINSIZE (p
->next
)
2520 : !NILP (p
->prev
) ? (*sizefun
) (p
->prev
) - MINSIZE (p
->prev
)
2521 /* This is a frame with only one window, a minibuffer-only
2522 or a minibufferless frame. */
2525 if (delta
> maxdelta
)
2526 /* This case traps trying to make the minibuffer
2527 the full frame, or make the only window aside from the
2528 minibuffer the full frame. */
2532 if (*sizep
+ delta
< MINSIZE (window
))
2534 Fdelete_window (window
);
2542 && (*sizefun
) (p
->next
) - delta
>= MINSIZE (p
->next
))
2544 (*setsizefun
) (p
->next
, (*sizefun
) (p
->next
) - delta
, 0);
2545 (*setsizefun
) (window
, *sizep
+ delta
, 0);
2546 CURBEG (p
->next
) += delta
;
2547 /* This does not change size of p->next,
2548 but it propagates the new top edge to its children */
2549 (*setsizefun
) (p
->next
, (*sizefun
) (p
->next
), 0);
2551 else if (!NILP (p
->prev
)
2552 && (*sizefun
) (p
->prev
) - delta
>= MINSIZE (p
->prev
))
2554 (*setsizefun
) (p
->prev
, (*sizefun
) (p
->prev
) - delta
, 0);
2555 CURBEG (window
) -= delta
;
2556 (*setsizefun
) (window
, *sizep
+ delta
, 0);
2560 register int delta1
;
2561 register int opht
= (*sizefun
) (parent
);
2563 /* If trying to grow this window to or beyond size of the parent,
2564 make delta1 so big that, on shrinking back down,
2565 all the siblings end up with less than one line and are deleted. */
2566 if (opht
<= *sizep
+ delta
)
2567 delta1
= opht
* opht
* 2;
2568 /* Otherwise, make delta1 just right so that if we add delta1
2569 lines to this window and to the parent, and then shrink
2570 the parent back to its original size, the new proportional
2571 size of this window will increase by delta. */
2573 delta1
= (delta
* opht
* 100) / ((opht
- *sizep
- delta
) * 100);
2575 /* Add delta1 lines or columns to this window, and to the parent,
2576 keeping things consistent while not affecting siblings. */
2577 CURSIZE (parent
) = opht
+ delta1
;
2578 (*setsizefun
) (window
, *sizep
+ delta1
, 0);
2580 /* Squeeze out delta1 lines or columns from our parent,
2581 shriking this window and siblings proportionately.
2582 This brings parent back to correct size.
2583 Delta1 was calculated so this makes this window the desired size,
2584 taking it all out of the siblings. */
2585 (*setsizefun
) (parent
, opht
, 0);
2588 XSETFASTINT (p
->last_modified
, 0);
2589 XSETFASTINT (p
->last_overlay_modified
, 0);
2596 /* Return number of lines of text (not counting mode line) in W. */
2599 window_internal_height (w
)
2602 int ht
= XFASTINT (w
->height
);
2604 if (MINI_WINDOW_P (w
))
2607 if (!NILP (w
->parent
) || !NILP (w
->vchild
) || !NILP (w
->hchild
)
2608 || !NILP (w
->next
) || !NILP (w
->prev
)
2609 || FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (w
))))
2616 /* Return the number of columns in W.
2617 Don't count columns occupied by scroll bars or the vertical bar
2618 separating W from the sibling to its right. */
2620 window_internal_width (w
)
2623 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2624 int width
= XINT (w
->width
);
2626 /* Scroll bars occupy a few columns. */
2627 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2628 return width
- FRAME_SCROLL_BAR_COLS (f
);
2630 /* The column of `|' characters separating side-by-side windows
2631 occupies one column only. */
2632 if (!WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
2639 /* Scroll contents of window WINDOW up N lines. */
2642 window_scroll (window
, n
, noerror
)
2647 register struct window
*w
= XWINDOW (window
);
2648 register int opoint
= PT
;
2650 register int ht
= window_internal_height (w
);
2651 register Lisp_Object tem
;
2653 Lisp_Object bolp
, nmoved
;
2655 /* Always set force_start so that redisplay_window will run
2656 the window-scroll-functions. */
2657 w
->force_start
= Qt
;
2659 XSETFASTINT (tem
, PT
);
2660 tem
= Fpos_visible_in_window_p (tem
, window
);
2664 Fvertical_motion (make_number (- (ht
/ 2)), window
);
2665 XSETFASTINT (tem
, PT
);
2666 Fset_marker (w
->start
, tem
, w
->buffer
);
2669 SET_PT (marker_position (w
->start
));
2670 lose
= n
< 0 && PT
== BEGV
;
2671 Fvertical_motion (make_number (n
), window
);
2681 Fsignal (Qbeginning_of_buffer
, Qnil
);
2686 set_marker_restricted (w
->start
, make_number (pos
), w
->buffer
);
2687 w
->start_at_line_beg
= bolp
;
2688 w
->update_mode_line
= Qt
;
2689 XSETFASTINT (w
->last_modified
, 0);
2690 XSETFASTINT (w
->last_overlay_modified
, 0);
2696 tem
= Fvertical_motion (make_number (ht
), window
);
2697 if (PT
> opoint
|| XFASTINT (tem
) < ht
)
2700 Fvertical_motion (make_number (-1), window
);
2708 Fsignal (Qend_of_buffer
, Qnil
);
2712 /* This is the guts of Fscroll_up and Fscroll_down. */
2715 scroll_command (n
, direction
)
2716 register Lisp_Object n
;
2719 register int defalt
;
2720 int count
= specpdl_ptr
- specpdl
;
2722 /* If selected window's buffer isn't current, make it current for the moment.
2723 But don't screw up if window_scroll gets an error. */
2724 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
2726 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
2727 Fset_buffer (XWINDOW (selected_window
)->buffer
);
2730 defalt
= (window_internal_height (XWINDOW (selected_window
))
2731 - next_screen_context_lines
);
2732 defalt
= direction
* (defalt
< 1 ? 1 : defalt
);
2735 window_scroll (selected_window
, defalt
, 0);
2736 else if (EQ (n
, Qminus
))
2737 window_scroll (selected_window
, - defalt
, 0);
2740 n
= Fprefix_numeric_value (n
);
2741 window_scroll (selected_window
, XINT (n
) * direction
, 0);
2744 unbind_to (count
, Qnil
);
2747 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
2748 "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\
2749 A near full screen is `next-screen-context-lines' less than a full screen.\n\
2750 Negative ARG means scroll downward.\n\
2751 When calling from a program, supply a number as argument or nil.")
2755 scroll_command (arg
, 1);
2759 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
2760 "Scroll text of current window downward ARG lines; or near full screen if no ARG.\n\
2761 A near full screen is `next-screen-context-lines' less than a full screen.\n\
2762 Negative ARG means scroll upward.\n\
2763 When calling from a program, supply a number as argument or nil.")
2767 scroll_command (arg
, -1);
2771 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
2772 "Return the other window for \"other window scroll\" commands.\n\
2773 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
2774 specifies the window.\n\
2775 If `other-window-scroll-buffer' is non-nil, a window\n\
2776 showing that buffer is used.")
2781 if (MINI_WINDOW_P (XWINDOW (selected_window
))
2782 && !NILP (Vminibuf_scroll_window
))
2783 window
= Vminibuf_scroll_window
;
2784 /* If buffer is specified, scroll that buffer. */
2785 else if (!NILP (Vother_window_scroll_buffer
))
2787 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
2789 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
);
2793 /* Nothing specified; look for a neighboring window on the same
2795 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
2797 if (EQ (window
, selected_window
))
2798 /* That didn't get us anywhere; look for a window on another
2801 window
= Fnext_window (window
, Qnil
, Qt
);
2802 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
2803 && ! EQ (window
, selected_window
));
2806 CHECK_LIVE_WINDOW (window
, 0);
2808 if (EQ (window
, selected_window
))
2809 error ("There is no other window");
2814 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
2815 "Scroll next window upward ARG lines; or near full screen if no ARG.\n\
2816 The next window is the one below the current one; or the one at the top\n\
2817 if the current one is at the bottom. Negative ARG means scroll downward.\n\
2818 When calling from a program, supply a number as argument or nil.\n\
2820 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
2821 specifies the window to scroll.\n\
2822 If `other-window-scroll-buffer' is non-nil, scroll the window\n\
2823 showing that buffer, popping the buffer up if necessary.")
2825 register Lisp_Object arg
;
2827 register Lisp_Object window
;
2828 register int defalt
;
2829 register struct window
*w
;
2830 register int count
= specpdl_ptr
- specpdl
;
2832 window
= Fother_window_for_scrolling ();
2834 w
= XWINDOW (window
);
2835 defalt
= window_internal_height (w
) - next_screen_context_lines
;
2836 if (defalt
< 1) defalt
= 1;
2838 /* Don't screw up if window_scroll gets an error. */
2839 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
2841 Fset_buffer (w
->buffer
);
2842 SET_PT (marker_position (w
->pointm
));
2845 window_scroll (window
, defalt
, 1);
2846 else if (EQ (arg
, Qminus
))
2847 window_scroll (window
, -defalt
, 1);
2852 CHECK_NUMBER (arg
, 0);
2853 window_scroll (window
, XINT (arg
), 1);
2856 Fset_marker (w
->pointm
, make_number (PT
), Qnil
);
2857 unbind_to (count
, Qnil
);
2862 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 1, "P",
2863 "Scroll selected window display ARG columns left.\n\
2864 Default for ARG is window width minus 2.")
2866 register Lisp_Object arg
;
2870 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
2872 arg
= Fprefix_numeric_value (arg
);
2875 Fset_window_hscroll (selected_window
,
2876 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
2880 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 1, "P",
2881 "Scroll selected window display ARG columns right.\n\
2882 Default for ARG is window width minus 2.")
2884 register Lisp_Object arg
;
2887 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
2889 arg
= Fprefix_numeric_value (arg
);
2892 Fset_window_hscroll (selected_window
,
2893 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
2897 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
2898 "Center point in window and redisplay frame. With ARG, put point on line ARG.\n\
2899 The desired position of point is always relative to the current window.\n\
2900 Just C-u as prefix means put point in the center of the window.\n\
2901 If ARG is omitted or nil, erases the entire frame and then\n\
2902 redraws with point in the center of the current window.")
2904 register Lisp_Object arg
;
2906 register struct window
*w
= XWINDOW (selected_window
);
2907 register int ht
= window_internal_height (w
);
2908 struct position pos
;
2912 extern int frame_garbaged
;
2914 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
2915 XSETFASTINT (arg
, ht
/ 2);
2917 else if (CONSP (arg
)) /* Just C-u. */
2919 XSETFASTINT (arg
, ht
/ 2);
2923 arg
= Fprefix_numeric_value (arg
);
2924 CHECK_NUMBER (arg
, 0);
2928 XSETINT (arg
, XINT (arg
) + ht
);
2930 pos
= *vmotion (PT
, - XINT (arg
), w
);
2932 Fset_marker (w
->start
, make_number (pos
.bufpos
), w
->buffer
);
2933 w
->start_at_line_beg
= ((pos
.bufpos
== BEGV
2934 || FETCH_CHAR (pos
.bufpos
- 1) == '\n')
2936 w
->force_start
= Qt
;
2941 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
2943 "Position point relative to window.\n\
2944 With no argument, position point at center of window.\n\
2945 An argument specifies frame line; zero means top of window,\n\
2946 negative means relative to bottom of window.")
2948 register Lisp_Object arg
;
2950 register struct window
*w
= XWINDOW (selected_window
);
2951 register int height
= window_internal_height (w
);
2956 XSETFASTINT (arg
, height
/ 2);
2959 arg
= Fprefix_numeric_value (arg
);
2961 XSETINT (arg
, XINT (arg
) + height
);
2964 start
= marker_position (w
->start
);
2965 XSETWINDOW (window
, w
);
2966 if (start
< BEGV
|| start
> ZV
)
2968 Fvertical_motion (make_number (- (height
/ 2)), window
);
2969 Fset_marker (w
->start
, make_number (PT
), w
->buffer
);
2970 w
->start_at_line_beg
= Fbolp ();
2971 w
->force_start
= Qt
;
2976 return Fvertical_motion (arg
, window
);
2979 struct save_window_data
2981 EMACS_INT size_from_Lisp_Vector_struct
;
2982 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
2983 Lisp_Object frame_width
, frame_height
, frame_menu_bar_lines
;
2984 Lisp_Object selected_frame
;
2985 Lisp_Object current_window
;
2986 Lisp_Object current_buffer
;
2987 Lisp_Object minibuf_scroll_window
;
2988 Lisp_Object root_window
;
2989 Lisp_Object focus_frame
;
2990 /* Record the values of window-min-width and window-min-height
2991 so that window sizes remain consistent with them. */
2992 Lisp_Object min_width
, min_height
;
2993 /* A vector, interpreted as a struct saved_window */
2994 Lisp_Object saved_windows
;
2997 /* This is saved as a Lisp_Vector */
3000 /* these first two must agree with struct Lisp_Vector in lisp.h */
3001 EMACS_INT size_from_Lisp_Vector_struct
;
3002 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
3005 Lisp_Object buffer
, start
, pointm
, mark
;
3006 Lisp_Object left
, top
, width
, height
, hscroll
;
3007 Lisp_Object parent
, prev
;
3008 Lisp_Object start_at_line_beg
;
3009 Lisp_Object display_table
;
3011 #define SAVED_WINDOW_VECTOR_SIZE 14 /* Arg to Fmake_vector */
3013 #define SAVED_WINDOW_N(swv,n) \
3014 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
3016 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
3017 "T if OBJECT is a window-configuration object.")
3021 if (WINDOW_CONFIGURATIONP (object
))
3027 DEFUN ("set-window-configuration", Fset_window_configuration
,
3028 Sset_window_configuration
, 1, 1, 0,
3029 "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\
3030 CONFIGURATION must be a value previously returned\n\
3031 by `current-window-configuration' (which see).")
3033 Lisp_Object configuration
;
3035 register struct save_window_data
*data
;
3036 struct Lisp_Vector
*saved_windows
;
3037 Lisp_Object new_current_buffer
;
3041 while (!WINDOW_CONFIGURATIONP (configuration
))
3043 configuration
= wrong_type_argument (intern ("window-configuration-p"),
3047 data
= (struct save_window_data
*) XVECTOR (configuration
);
3048 saved_windows
= XVECTOR (data
->saved_windows
);
3050 new_current_buffer
= data
->current_buffer
;
3051 if (NILP (XBUFFER (new_current_buffer
)->name
))
3052 new_current_buffer
= Qnil
;
3054 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
3057 /* If f is a dead frame, don't bother rebuilding its window tree.
3058 However, there is other stuff we should still try to do below. */
3059 if (FRAME_LIVE_P (f
))
3061 register struct window
*w
;
3062 register struct saved_window
*p
;
3065 /* If the frame has been resized since this window configuration was
3066 made, we change the frame to the size specified in the
3067 configuration, restore the configuration, and then resize it
3068 back. We keep track of the prevailing height in these variables. */
3069 int previous_frame_height
= FRAME_HEIGHT (f
);
3070 int previous_frame_width
= FRAME_WIDTH (f
);
3071 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
3073 if (XFASTINT (data
->frame_height
) != previous_frame_height
3074 || XFASTINT (data
->frame_width
) != previous_frame_width
)
3075 change_frame_size (f
, data
->frame_height
, data
->frame_width
, 0, 0);
3076 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
3077 if (XFASTINT (data
->frame_menu_bar_lines
)
3078 != previous_frame_menu_bar_lines
)
3079 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, 0);
3082 windows_or_buffers_changed
++;
3083 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3085 /* Temporarily avoid any problems with windows that are smaller
3086 than they are supposed to be. */
3087 window_min_height
= 1;
3088 window_min_width
= 1;
3091 Mark all windows now on frame as "deleted".
3092 Restoring the new configuration "undeletes" any that are in it.
3094 Save their current buffers in their height fields, since we may
3095 need it later, if a buffer saved in the configuration is now
3097 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3099 for (k
= 0; k
< saved_windows
->size
; k
++)
3101 p
= SAVED_WINDOW_N (saved_windows
, k
);
3102 w
= XWINDOW (p
->window
);
3105 if (!NILP (p
->parent
))
3106 w
->parent
= SAVED_WINDOW_N (saved_windows
,
3107 XFASTINT (p
->parent
))->window
;
3111 if (!NILP (p
->prev
))
3113 w
->prev
= SAVED_WINDOW_N (saved_windows
,
3114 XFASTINT (p
->prev
))->window
;
3115 XWINDOW (w
->prev
)->next
= p
->window
;
3120 if (!NILP (w
->parent
))
3122 if (EQ (p
->width
, XWINDOW (w
->parent
)->width
))
3124 XWINDOW (w
->parent
)->vchild
= p
->window
;
3125 XWINDOW (w
->parent
)->hchild
= Qnil
;
3129 XWINDOW (w
->parent
)->hchild
= p
->window
;
3130 XWINDOW (w
->parent
)->vchild
= Qnil
;
3135 /* If we squirreled away the buffer in the window's height,
3137 if (BUFFERP (w
->height
))
3138 w
->buffer
= w
->height
;
3141 w
->width
= p
->width
;
3142 w
->height
= p
->height
;
3143 w
->hscroll
= p
->hscroll
;
3144 w
->display_table
= p
->display_table
;
3145 XSETFASTINT (w
->last_modified
, 0);
3146 XSETFASTINT (w
->last_overlay_modified
, 0);
3148 /* Reinstall the saved buffer and pointers into it. */
3149 if (NILP (p
->buffer
))
3150 w
->buffer
= p
->buffer
;
3153 if (!NILP (XBUFFER (p
->buffer
)->name
))
3154 /* If saved buffer is alive, install it. */
3156 w
->buffer
= p
->buffer
;
3157 w
->start_at_line_beg
= p
->start_at_line_beg
;
3158 set_marker_restricted (w
->start
,
3159 Fmarker_position (p
->start
),
3161 set_marker_restricted (w
->pointm
,
3162 Fmarker_position (p
->pointm
),
3164 Fset_marker (XBUFFER (w
->buffer
)->mark
,
3165 Fmarker_position (p
->mark
), w
->buffer
);
3167 /* As documented in Fcurrent_window_configuration, don't
3168 save the location of point in the buffer which was current
3169 when the window configuration was recorded. */
3170 if (!EQ (p
->buffer
, new_current_buffer
)
3171 && XBUFFER (p
->buffer
) == current_buffer
)
3172 Fgoto_char (w
->pointm
);
3174 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
3175 /* Else unless window has a live buffer, get one. */
3177 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
3178 /* This will set the markers to beginning of visible
3180 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
3181 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
3182 w
->start_at_line_beg
= Qt
;
3185 /* Keeping window's old buffer; make sure the markers
3188 /* Set window markers at start of visible range. */
3189 if (XMARKER (w
->start
)->buffer
== 0)
3190 set_marker_restricted (w
->start
, make_number (0),
3192 if (XMARKER (w
->pointm
)->buffer
== 0)
3193 set_marker_restricted (w
->pointm
,
3195 (BUF_PT (XBUFFER (w
->buffer
)))),
3197 w
->start_at_line_beg
= Qt
;
3202 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
3203 Fselect_window (data
->current_window
);
3205 if (NILP (data
->focus_frame
)
3206 || (FRAMEP (data
->focus_frame
)
3207 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
3208 Fredirect_frame_focus (frame
, data
->focus_frame
);
3210 #if 0 /* I don't understand why this is needed, and it causes problems
3211 when the frame's old selected window has been deleted. */
3212 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
3213 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
3217 /* Set the screen height to the value it had before this function. */
3218 if (previous_frame_height
!= FRAME_HEIGHT (f
)
3219 || previous_frame_width
!= FRAME_WIDTH (f
))
3220 change_frame_size (f
, previous_frame_height
, previous_frame_width
,
3222 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
3223 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
3224 x_set_menu_bar_lines (f
, previous_frame_menu_bar_lines
, 0);
3228 /* Restore the minimum heights recorded in the configuration. */
3229 window_min_height
= XINT (data
->min_height
);
3230 window_min_width
= XINT (data
->min_width
);
3232 /* Fselect_window will have made f the selected frame, so we
3233 reselect the proper frame here. Fhandle_switch_frame will change the
3234 selected window too, but that doesn't make the call to
3235 Fselect_window above totally superfluous; it still sets f's
3237 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
3238 do_switch_frame (data
->selected_frame
, Qnil
, 0);
3240 if (!NILP (new_current_buffer
))
3241 Fset_buffer (new_current_buffer
);
3243 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
3247 /* Mark all windows now on frame as deleted
3248 by setting their buffers to nil. */
3251 delete_all_subwindows (w
)
3252 register struct window
*w
;
3254 if (!NILP (w
->next
))
3255 delete_all_subwindows (XWINDOW (w
->next
));
3256 if (!NILP (w
->vchild
))
3257 delete_all_subwindows (XWINDOW (w
->vchild
));
3258 if (!NILP (w
->hchild
))
3259 delete_all_subwindows (XWINDOW (w
->hchild
));
3261 w
->height
= w
->buffer
; /* See Fset_window_configuration for excuse. */
3263 if (!NILP (w
->buffer
))
3266 /* We set all three of these fields to nil, to make sure that we can
3267 distinguish this dead window from any live window. Live leaf
3268 windows will have buffer set, and combination windows will have
3269 vchild or hchild set. */
3276 count_windows (window
)
3277 register struct window
*window
;
3279 register int count
= 1;
3280 if (!NILP (window
->next
))
3281 count
+= count_windows (XWINDOW (window
->next
));
3282 if (!NILP (window
->vchild
))
3283 count
+= count_windows (XWINDOW (window
->vchild
));
3284 if (!NILP (window
->hchild
))
3285 count
+= count_windows (XWINDOW (window
->hchild
));
3290 save_window_save (window
, vector
, i
)
3292 struct Lisp_Vector
*vector
;
3295 register struct saved_window
*p
;
3296 register struct window
*w
;
3297 register Lisp_Object tem
;
3299 for (;!NILP (window
); window
= w
->next
)
3301 p
= SAVED_WINDOW_N (vector
, i
);
3302 w
= XWINDOW (window
);
3304 XSETFASTINT (w
->temslot
, i
++);
3306 p
->buffer
= w
->buffer
;
3309 p
->width
= w
->width
;
3310 p
->height
= w
->height
;
3311 p
->hscroll
= w
->hscroll
;
3312 p
->display_table
= w
->display_table
;
3313 if (!NILP (w
->buffer
))
3315 /* Save w's value of point in the window configuration.
3316 If w is the selected window, then get the value of point
3317 from the buffer; pointm is garbage in the selected window. */
3318 if (EQ (window
, selected_window
))
3320 p
->pointm
= Fmake_marker ();
3321 Fset_marker (p
->pointm
, BUF_PT (XBUFFER (w
->buffer
)),
3325 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
3327 p
->start
= Fcopy_marker (w
->start
, Qnil
);
3328 p
->start_at_line_beg
= w
->start_at_line_beg
;
3330 tem
= XBUFFER (w
->buffer
)->mark
;
3331 p
->mark
= Fcopy_marker (tem
, Qnil
);
3338 p
->start_at_line_beg
= Qnil
;
3341 if (NILP (w
->parent
))
3344 p
->parent
= XWINDOW (w
->parent
)->temslot
;
3349 p
->prev
= XWINDOW (w
->prev
)->temslot
;
3351 if (!NILP (w
->vchild
))
3352 i
= save_window_save (w
->vchild
, vector
, i
);
3353 if (!NILP (w
->hchild
))
3354 i
= save_window_save (w
->hchild
, vector
, i
);
3360 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
3361 Scurrent_window_configuration
, 0, 1, 0,
3362 "Return an object representing the current window configuration of FRAME.\n\
3363 If FRAME is nil or omitted, use the selected frame.\n\
3364 This describes the number of windows, their sizes and current buffers,\n\
3365 and for each displayed buffer, where display starts, and the positions of\n\
3366 point and mark. An exception is made for point in the current buffer:\n\
3367 its value is -not- saved.\n\
3368 This also records the currently selected frame, and FRAME's focus\n\
3369 redirection (see `redirect-frame-focus').")
3373 register Lisp_Object tem
;
3374 register int n_windows
;
3375 register struct save_window_data
*data
;
3376 register struct Lisp_Vector
*vec
;
3384 CHECK_LIVE_FRAME (frame
, 0);
3388 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3389 vec
= allocate_vectorlike (VECSIZE (struct save_window_data
));
3390 for (i
= 0; i
< VECSIZE (struct save_window_data
); i
++)
3391 vec
->contents
[i
] = Qnil
;
3392 vec
->size
= VECSIZE (struct save_window_data
);
3393 data
= (struct save_window_data
*)vec
;
3395 XSETFASTINT (data
->frame_width
, FRAME_WIDTH (f
));
3396 XSETFASTINT (data
->frame_height
, FRAME_HEIGHT (f
));
3397 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
3398 XSETFRAME (data
->selected_frame
, selected_frame
);
3399 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
3400 XSETBUFFER (data
->current_buffer
, current_buffer
);
3401 data
->minibuf_scroll_window
= Vminibuf_scroll_window
;
3402 data
->root_window
= FRAME_ROOT_WINDOW (f
);
3403 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
3404 XSETINT (data
->min_height
, window_min_height
);
3405 XSETINT (data
->min_width
, window_min_width
);
3406 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
3407 data
->saved_windows
= tem
;
3408 for (i
= 0; i
< n_windows
; i
++)
3409 XVECTOR (tem
)->contents
[i
]
3410 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
3411 save_window_save (FRAME_ROOT_WINDOW (f
),
3413 XSETWINDOW_CONFIGURATION (tem
, data
);
3417 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
3419 "Execute body, preserving window sizes and contents.\n\
3420 Restore which buffer appears in which window, where display starts,\n\
3421 and the value of point and mark for each window.\n\
3422 Also restore which buffer is current.\n\
3423 But do not preserve point in the current buffer.\n\
3424 Does not restore the value of point in current buffer.")
3428 register Lisp_Object val
;
3429 register int count
= specpdl_ptr
- specpdl
;
3431 record_unwind_protect (Fset_window_configuration
,
3432 Fcurrent_window_configuration (Qnil
));
3433 val
= Fprogn (args
);
3434 return unbind_to (count
, val
);
3439 selected_frame
= make_terminal_frame ();
3440 XSETFRAME (Vterminal_frame
, selected_frame
);
3441 minibuf_window
= selected_frame
->minibuffer_window
;
3442 selected_window
= selected_frame
->selected_window
;
3443 last_nonminibuf_frame
= selected_frame
;
3445 window_initialized
= 1;
3450 Qwindowp
= intern ("windowp");
3451 staticpro (&Qwindowp
);
3453 Qwindow_live_p
= intern ("window-live-p");
3454 staticpro (&Qwindow_live_p
);
3456 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
3457 staticpro (&Qtemp_buffer_show_hook
);
3459 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
3460 "Non-nil means call as function to display a help buffer.\n\
3461 The function is called with one argument, the buffer to be displayed.\n\
3462 Used by `with-output-to-temp-buffer'.\n\
3463 If this function is used, then it must do the entire job of showing\n\
3464 the buffer; `temp-buffer-show-hook' is not run unless this function runs it.");
3465 Vtemp_buffer_show_function
= Qnil
;
3467 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
3468 "If non-nil, function to call to handle `display-buffer'.\n\
3469 It will receive two args, the buffer and a flag which if non-nil means\n\
3470 that the currently selected window is not acceptable.\n\
3471 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\
3472 work using this function.");
3473 Vdisplay_buffer_function
= Qnil
;
3475 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
3476 "Non-nil means it is the window that C-M-v in minibuffer should scroll.");
3477 Vminibuf_scroll_window
= Qnil
;
3479 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
3480 "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.");
3481 Vother_window_scroll_buffer
= Qnil
;
3483 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
3484 "*Non-nil means `display-buffer' should make a separate frame.");
3487 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
3488 "Function to call to handle automatic new frame creation.\n\
3489 It is called with no arguments and should return a newly created frame.\n\
3491 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\
3492 where `pop-up-frame-alist' would hold the default frame parameters.");
3493 Vpop_up_frame_function
= Qnil
;
3495 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
3496 "*List of buffer names that should have their own special frames.\n\
3497 Displaying a buffer whose name is in this list makes a special frame for it\n\
3498 using `special-display-function'. See also `special-display-regexps'.\n\
3500 An element of the list can be a list instead of just a string.\n\
3501 There are two ways to use a list as an element:\n\
3502 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)\n\
3503 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
3504 In the latter case, FUNCTION is called with BUFFER as the first argument,\n\
3505 followed by OTHER-ARGS--it can display BUFFER in any way it likes.\n\
3506 All this is done by the function found in `special-display-function'.");
3507 Vspecial_display_buffer_names
= Qnil
;
3509 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
3510 "*List of regexps saying which buffers should have their own special frames.\n\
3511 If a buffer name matches one of these regexps, it gets its own frame.\n\
3512 Displaying a buffer whose name is in this list makes a special frame for it\n\
3513 using `special-display-function'.\n\
3515 An element of the list can be a list instead of just a string.\n\
3516 There are two ways to use a list as an element:\n\
3517 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)\n\
3518 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
3519 In the latter case, FUNCTION is called with the buffer as first argument,\n\
3520 followed by OTHER-ARGS--it can display the buffer in any way it likes.\n\
3521 All this is done by the function found in `special-display-function'.");
3522 Vspecial_display_regexps
= Qnil
;
3524 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
3525 "Function to call to make a new frame for a special buffer.\n\
3526 It is called with two arguments, the buffer and optional buffer specific\n\
3527 data, and should return a window displaying that buffer.\n\
3528 The default value makes a separate frame for the buffer,\n\
3529 using `special-display-frame-alist' to specify the frame parameters.\n\
3531 A buffer is special if its is listed in `special-display-buffer-names'\n\
3532 or matches a regexp in `special-display-regexps'.");
3533 Vspecial_display_function
= Qnil
;
3535 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
3536 "*List of buffer names that should appear in the selected window.\n\
3537 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'\n\
3538 switches to it in the selected window, rather than making it appear\n\
3539 in some other window.\n\
3541 An element of the list can be a cons cell instead of just a string.\n\
3542 Then the car must be a string, which specifies the buffer name.\n\
3543 This is for compatibility with `special-display-buffer-names';\n\
3544 the cdr of the cons cell is ignored.\n\
3546 See also `same-window-regexps'.");
3547 Vsame_window_buffer_names
= Qnil
;
3549 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
3550 "*List of regexps saying which buffers should appear in the selected window.\n\
3551 If a buffer name matches one of these regexps, then displaying it\n\
3552 using `display-buffer' or `pop-to-buffer' switches to it\n\
3553 in the selected window, rather than making it appear in some other window.\n\
3555 An element of the list can be a cons cell instead of just a string.\n\
3556 Then the car must be a string, which specifies the buffer name.\n\
3557 This is for compatibility with `special-display-buffer-names';\n\
3558 the cdr of the cons cell is ignored.\n\
3560 See also `same-window-buffer-names'.");
3561 Vsame_window_regexps
= Qnil
;
3563 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
3564 "*Non-nil means display-buffer should make new windows.");
3567 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
3568 "*Number of lines of continuity when scrolling by screenfuls.");
3569 next_screen_context_lines
= 2;
3571 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
3572 "*display-buffer would prefer to split the largest window if this large.\n\
3573 If there is only one window, it is split regardless of this value.");
3574 split_height_threshold
= 500;
3576 DEFVAR_INT ("window-min-height", &window_min_height
,
3577 "*Delete any window less than this tall (including its mode line).");
3578 window_min_height
= 4;
3580 DEFVAR_INT ("window-min-width", &window_min_width
,
3581 "*Delete any window less than this wide.");
3582 window_min_width
= 10;
3584 defsubr (&Sselected_window
);
3585 defsubr (&Sminibuffer_window
);
3586 defsubr (&Swindow_minibuffer_p
);
3587 defsubr (&Swindowp
);
3588 defsubr (&Swindow_live_p
);
3589 defsubr (&Spos_visible_in_window_p
);
3590 defsubr (&Swindow_buffer
);
3591 defsubr (&Swindow_height
);
3592 defsubr (&Swindow_width
);
3593 defsubr (&Swindow_hscroll
);
3594 defsubr (&Sset_window_hscroll
);
3595 defsubr (&Swindow_redisplay_end_trigger
);
3596 defsubr (&Sset_window_redisplay_end_trigger
);
3597 defsubr (&Swindow_edges
);
3598 defsubr (&Scoordinates_in_window_p
);
3599 defsubr (&Swindow_at
);
3600 defsubr (&Swindow_point
);
3601 defsubr (&Swindow_start
);
3602 defsubr (&Swindow_end
);
3603 defsubr (&Sset_window_point
);
3604 defsubr (&Sset_window_start
);
3605 defsubr (&Swindow_dedicated_p
);
3606 defsubr (&Sset_window_dedicated_p
);
3607 defsubr (&Swindow_display_table
);
3608 defsubr (&Sset_window_display_table
);
3609 defsubr (&Snext_window
);
3610 defsubr (&Sprevious_window
);
3611 defsubr (&Sother_window
);
3612 defsubr (&Sget_lru_window
);
3613 defsubr (&Sget_largest_window
);
3614 defsubr (&Sget_buffer_window
);
3615 defsubr (&Sdelete_other_windows
);
3616 defsubr (&Sdelete_windows_on
);
3617 defsubr (&Sreplace_buffer_in_windows
);
3618 defsubr (&Sdelete_window
);
3619 defsubr (&Sset_window_buffer
);
3620 defsubr (&Sselect_window
);
3621 defsubr (&Sspecial_display_p
);
3622 defsubr (&Ssame_window_p
);
3623 defsubr (&Sdisplay_buffer
);
3624 defsubr (&Ssplit_window
);
3625 defsubr (&Senlarge_window
);
3626 defsubr (&Sshrink_window
);
3627 defsubr (&Sscroll_up
);
3628 defsubr (&Sscroll_down
);
3629 defsubr (&Sscroll_left
);
3630 defsubr (&Sscroll_right
);
3631 defsubr (&Sother_window_for_scrolling
);
3632 defsubr (&Sscroll_other_window
);
3633 defsubr (&Srecenter
);
3634 defsubr (&Smove_to_window_line
);
3635 defsubr (&Swindow_configuration_p
);
3636 defsubr (&Sset_window_configuration
);
3637 defsubr (&Scurrent_window_configuration
);
3638 defsubr (&Ssave_window_excursion
);
3643 initial_define_key (control_x_map
, '1', "delete-other-windows");
3644 initial_define_key (control_x_map
, '2', "split-window");
3645 initial_define_key (control_x_map
, '0', "delete-window");
3646 initial_define_key (control_x_map
, 'o', "other-window");
3647 initial_define_key (control_x_map
, '^', "enlarge-window");
3648 initial_define_key (control_x_map
, '<', "scroll-left");
3649 initial_define_key (control_x_map
, '>', "scroll-right");
3651 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
3652 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
3653 initial_define_key (meta_map
, 'v', "scroll-down");
3655 initial_define_key (global_map
, Ctl('L'), "recenter");
3656 initial_define_key (meta_map
, 'r', "move-to-window-line");