1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985,86,87,93,94,95,96,97,1998 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
32 #include "dispextern.h"
33 #include "blockinput.h"
34 #include "intervals.h"
38 #endif /* HAVE_X_WINDOWS */
41 #define max(a, b) ((a) < (b) ? (b) : (a))
45 Lisp_Object Qwindowp
, Qwindow_live_p
, Qwindow_configuration_p
;
47 static struct window
*decode_window
P_ ((Lisp_Object
));
48 static Lisp_Object select_window_1
P_ ((Lisp_Object
, int));
49 static int count_windows
P_ ((struct window
*));
50 static int get_leaf_windows
P_ ((struct window
*, struct window
**, int));
51 static void window_scroll
P_ ((Lisp_Object
, int, int, int));
52 static void window_scroll_pixel_based
P_ ((Lisp_Object
, int, int, int));
53 static void window_scroll_line_based
P_ ((Lisp_Object
, int, int, int));
57 /* This is the window in which the terminal's cursor should
58 be left when nothing is being done with it. This must
59 always be a leaf window, and its buffer is selected by
60 the top level editing loop at the end of each command.
62 This value is always the same as
63 FRAME_SELECTED_WINDOW (selected_frame). */
65 Lisp_Object selected_window
;
67 /* The mini-buffer window of the selected frame.
68 Note that you cannot test for mini-bufferness of an arbitrary window
69 by comparing against this; but you can test for mini-bufferness of
70 the selected window. */
72 Lisp_Object minibuf_window
;
74 /* Non-nil means it is the window for C-M-v to scroll
75 when the mini-buffer is selected. */
77 Lisp_Object Vminibuf_scroll_window
;
79 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
81 Lisp_Object Vother_window_scroll_buffer
;
83 /* Non-nil means it's function to call to display temp buffers. */
85 Lisp_Object Vtemp_buffer_show_function
;
87 /* If a window gets smaller than either of these, it is removed. */
89 int window_min_height
;
92 /* Nonzero implies Fdisplay_buffer should create windows. */
96 /* Nonzero implies make new frames for Fdisplay_buffer. */
100 /* Non-nil means use this function instead of default */
102 Lisp_Object Vpop_up_frame_function
;
104 /* Function to call to handle Fdisplay_buffer. */
106 Lisp_Object Vdisplay_buffer_function
;
108 /* List of buffer *names* for buffers that should have their own frames. */
110 Lisp_Object Vspecial_display_buffer_names
;
112 /* List of regexps for buffer names that should have their own frames. */
114 Lisp_Object Vspecial_display_regexps
;
116 /* Function to pop up a special frame. */
118 Lisp_Object Vspecial_display_function
;
120 /* List of buffer *names* for buffers to appear in selected window. */
122 Lisp_Object Vsame_window_buffer_names
;
124 /* List of regexps for buffer names to appear in selected window. */
126 Lisp_Object Vsame_window_regexps
;
128 /* Hook run at end of temp_output_buffer_show. */
130 Lisp_Object Qtemp_buffer_show_hook
;
132 /* Fdisplay_buffer always splits the largest window
133 if that window is more than this high. */
135 int split_height_threshold
;
137 /* Number of lines of continuity in scrolling by screenfuls. */
139 int next_screen_context_lines
;
141 /* Incremented for each window created. */
143 static int sequence_number
;
145 /* Nonzero after init_window_once has finished. */
147 static int window_initialized
;
149 /* Hook to run when window config changes. */
151 Lisp_Object Qwindow_configuration_change_hook
;
152 Lisp_Object Vwindow_configuration_change_hook
;
154 /* Nonzero means scroll commands try to put point
155 at the same screen height as previously. */
157 Lisp_Object Vscroll_preserve_screen_position
;
159 #if 0 /* This isn't used anywhere. */
160 /* Nonzero means we can split a frame even if it is "unsplittable". */
161 static int inhibit_frame_unsplittable
;
164 #define min(a, b) ((a) < (b) ? (a) : (b))
166 extern int scroll_margin
;
168 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
170 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
171 "Returns t if OBJECT is a window.")
175 return WINDOWP (object
) ? Qt
: Qnil
;
178 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
179 "Returns t if OBJECT is a window which is currently visible.")
183 return (WINDOWP (object
) && ! NILP (XWINDOW (object
)->buffer
) ? Qt
: Qnil
);
190 register struct window
*p
;
191 register struct Lisp_Vector
*vec
;
194 vec
= allocate_vectorlike ((EMACS_INT
) VECSIZE (struct window
));
195 for (i
= 0; i
< VECSIZE (struct window
); i
++)
196 vec
->contents
[i
] = Qnil
;
197 vec
->size
= VECSIZE (struct window
);
198 p
= (struct window
*) vec
;
199 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
200 XSETFASTINT (p
->left
, 0);
201 XSETFASTINT (p
->top
, 0);
202 XSETFASTINT (p
->height
, 0);
203 XSETFASTINT (p
->width
, 0);
204 XSETFASTINT (p
->hscroll
, 0);
205 p
->start
= Fmake_marker ();
206 p
->pointm
= Fmake_marker ();
207 XSETFASTINT (p
->use_time
, 0);
209 p
->display_table
= Qnil
;
211 p
->pseudo_window_p
= 0;
212 bzero (&p
->cursor
, sizeof (p
->cursor
));
213 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
214 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
215 p
->desired_matrix
= p
->current_matrix
= 0;
216 p
->phys_cursor_type
= -1;
217 p
->must_be_updated_p
= 0;
218 XSETFASTINT (p
->window_end_vpos
, 0);
219 XSETFASTINT (p
->window_end_pos
, 0);
220 p
->window_end_valid
= Qnil
;
223 XSETFASTINT (p
->last_point
, 0);
227 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
228 "Return the window that the cursor now appears in and commands apply to.")
231 return selected_window
;
234 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
235 "Return the window used now for minibuffers.\n\
236 If the optional argument FRAME is specified, return the minibuffer window\n\
237 used by that frame.")
242 XSETFRAME (frame
, selected_frame
);
244 CHECK_LIVE_FRAME (frame
, 0);
246 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
249 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
250 "Returns non-nil if WINDOW is a minibuffer window.")
254 struct window
*w
= decode_window (window
);
255 return (MINI_WINDOW_P (w
) ? Qt
: Qnil
);
258 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
259 Spos_visible_in_window_p
, 0, 2, 0,
260 "Return t if position POS is currently on the frame in WINDOW.\n\
261 Returns nil if that position is scrolled vertically out of view.\n\
262 POS defaults to point; WINDOW, to the selected window.")
264 Lisp_Object pos
, window
;
266 register struct window
*w
;
269 register struct buffer
*buf
;
275 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
279 w
= decode_window (window
);
280 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
282 /* If position above window, it's not visible. */
283 if (posint
< CHARPOS (top
))
286 buf
= XBUFFER (w
->buffer
);
287 if (XFASTINT (w
->last_modified
) >= BUF_MODIFF (buf
)
288 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (buf
))
290 /* If frame is up to date,
291 use the info recorded about how much text fit on it. */
292 if (posint
< BUF_Z (buf
) - XFASTINT (w
->window_end_pos
))
300 if (posint
> BUF_ZV (buf
))
303 /* w->start can be out of range. If it is, do something reasonable. */
304 if (CHARPOS (top
) < BUF_BEGV (buf
)
305 || CHARPOS (top
) > BUF_ZV (buf
))
308 start_display (&it
, w
, top
);
309 move_it_to (&it
, posint
, 0, it
.last_visible_y
, -1,
310 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
311 return IT_CHARPOS (it
) == posint
? Qt
: Qnil
;
315 static struct window
*
316 decode_window (window
)
317 register Lisp_Object window
;
320 return XWINDOW (selected_window
);
322 CHECK_LIVE_WINDOW (window
, 0);
323 return XWINDOW (window
);
326 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
327 "Return the buffer that WINDOW is displaying.")
331 return decode_window (window
)->buffer
;
334 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
335 "Return the number of lines in WINDOW (including its mode line).")
339 return decode_window (window
)->height
;
342 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
343 "Return the number of display columns in WINDOW.\n\
344 This is the width that is usable columns available for text in WINDOW.\n\
345 If you want to find out how many columns WINDOW takes up,\n\
346 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))).")
350 return make_number (window_internal_width (decode_window (window
)));
353 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
354 "Return the number of columns by which WINDOW is scrolled from left margin.")
358 return decode_window (window
)->hscroll
;
361 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
362 "Set number of columns WINDOW is scrolled from left margin to NCOL.\n\
363 NCOL should be zero or positive.")
365 register Lisp_Object window
, ncol
;
367 register struct window
*w
;
369 CHECK_NUMBER (ncol
, 1);
370 if (XINT (ncol
) < 0) XSETFASTINT (ncol
, 0);
371 w
= decode_window (window
);
372 if (XINT (w
->hscroll
) != XINT (ncol
))
373 XBUFFER (w
->buffer
)->clip_changed
= 1; /* Prevent redisplay shortcuts */
378 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
379 Swindow_redisplay_end_trigger
, 0, 1, 0,
380 "Return WINDOW's redisplay end trigger value.\n\
381 See `set-window-redisplay-end-trigger' for more information.")
385 return decode_window (window
)->redisplay_end_trigger
;
388 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
389 Sset_window_redisplay_end_trigger
, 2, 2, 0,
390 "Set WINDOW's redisplay end trigger value to VALUE.\n\
391 VALUE should be a buffer position (typically a marker) or nil.\n\
392 If it is a buffer position, then if redisplay in WINDOW reaches a position\n\
393 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called\n\
394 with two arguments: WINDOW, and the end trigger value.\n\
395 Afterwards the end-trigger value is reset to nil.")
397 register Lisp_Object window
, value
;
399 register struct window
*w
;
401 w
= decode_window (window
);
402 w
->redisplay_end_trigger
= value
;
406 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
407 "Return a list of the edge coordinates of WINDOW.\n\
408 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.\n\
409 RIGHT is one more than the rightmost column used by WINDOW,\n\
410 and BOTTOM is one more than the bottommost row used by WINDOW\n\
415 register struct window
*w
= decode_window (window
);
417 return Fcons (w
->left
, Fcons (w
->top
,
418 Fcons (make_number (WINDOW_RIGHT_EDGE (w
)),
419 Fcons (make_number (XFASTINT (w
->top
)
420 + XFASTINT (w
->height
)),
424 /* Test if the character at column *x, row *y is within window *w.
425 If it is not, return 0;
426 if it is in the window's text area,
427 set *x and *y to its location relative to the upper left corner
430 if it is on the window's modeline, return 2;
431 if it is on the border between the window and its right sibling,
433 if it is on the window's top line, return 4;
435 X and Y are frame relative pixel coordinates. */
438 coordinates_in_window (w
, x
, y
)
439 register struct window
*w
;
442 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
443 int left_x
, right_x
, top_y
, bottom_y
;
444 int flags_area_width
= FRAME_FLAGS_AREA_WIDTH (f
);
446 if (w
->pseudo_window_p
)
449 right_x
= XFASTINT (w
->width
) * CANON_Y_UNIT (f
);
450 top_y
= WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
);
451 bottom_y
= WINDOW_DISPLAY_BOTTOM_EDGE_PIXEL_Y (w
);
455 left_x
= WINDOW_DISPLAY_LEFT_EDGE_PIXEL_X (w
);
456 right_x
= WINDOW_DISPLAY_RIGHT_EDGE_PIXEL_X (w
);
457 top_y
= WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
);
458 bottom_y
= WINDOW_DISPLAY_BOTTOM_EDGE_PIXEL_Y (w
);
465 - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
)
467 || *x
> right_x
+ flags_area_width
)
468 /* Completely outside anything interesting. */
470 else if (WINDOW_WANTS_MODELINE_P (w
)
471 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
472 /* On the mode line. */
474 else if (WINDOW_WANTS_TOP_LINE_P (w
)
475 && *y
< top_y
+ CURRENT_TOP_LINE_HEIGHT (w
))
476 /* On the top line. */
478 else if (*x
< left_x
|| *x
>= right_x
)
479 /* Other lines than the mode line don't include flags areas and
480 scroll bars on the left. */
482 else if (!w
->pseudo_window_p
483 && !WINDOW_RIGHTMOST_P (w
)
484 && *x
>= right_x
- CANON_X_UNIT (f
))
485 /* On the border on the right side of the window? Assume that
486 this area begins at RIGHT_X minus a canonical char width. */
490 /* Convert X and Y to window-relative pixel coordinates. */
497 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
498 Scoordinates_in_window_p
, 2, 2, 0,
499 "Return non-nil if COORDINATES are in WINDOW.\n\
500 COORDINATES is a cons of the form (X . Y), X and Y being distances\n\
501 measured in characters from the upper-left corner of the frame.\n\
502 (0 . 0) denotes the character in the upper left corner of the\n\
504 If COORDINATES are in the text portion of WINDOW,\n\
505 the coordinates relative to the window are returned.\n\
506 If they are in the mode line of WINDOW, `mode-line' is returned.\n\
507 If they are in the top mode line of WINDOW, `top-line' is returned.\n\
508 If they are on the border between WINDOW and its right sibling,\n\
509 `vertical-line' is returned.")
510 (coordinates
, window
)
511 register Lisp_Object coordinates
, window
;
518 CHECK_LIVE_WINDOW (window
, 0);
519 w
= XWINDOW (window
);
520 f
= XFRAME (w
->frame
);
521 CHECK_CONS (coordinates
, 1);
522 lx
= Fcar (coordinates
);
523 ly
= Fcdr (coordinates
);
524 CHECK_NUMBER_OR_FLOAT (lx
, 1);
525 CHECK_NUMBER_OR_FLOAT (ly
, 1);
526 x
= PIXEL_X_FROM_CANON_X (f
, lx
);
527 y
= PIXEL_Y_FROM_CANON_Y (f
, ly
);
529 switch (coordinates_in_window (w
, &x
, &y
))
531 case 0: /* NOT in window at all. */
534 case 1: /* In text part of window. */
535 /* X and Y are now window relative pixel coordinates.
536 Convert them to canonical char units before returning
538 return Fcons (CANON_X_FROM_PIXEL_X (f
, x
),
539 CANON_Y_FROM_PIXEL_Y (f
, y
));
541 case 2: /* In mode line of window. */
544 case 3: /* On right border of window. */
545 return Qvertical_line
;
555 /* Find the window containing frame-relative pixel position X/Y and
556 return it as a Lisp_Object. If X, Y is on the window's modeline,
557 set *PART to 1; if it is on the separating line between the window
558 and its right sibling, set it to 2; otherwise set it to 0. If
559 there is no window under X, Y return nil and leave *PART
560 unmodified. TOOLBAR_P non-zero means detect toolbar windows. */
563 window_from_coordinates (frame
, x
, y
, part
, toolbar_p
)
569 register Lisp_Object tem
, first
;
572 tem
= first
= FRAME_SELECTED_WINDOW (frame
);
576 found
= coordinates_in_window (XWINDOW (tem
), &x
, &y
);
584 tem
= Fnext_window (tem
, Qt
, Qlambda
);
586 while (!EQ (tem
, first
));
588 /* See if it's in the toolbar window, if a toolbar exists. */
590 && WINDOWP (frame
->toolbar_window
)
591 && XFASTINT (XWINDOW (frame
->toolbar_window
)->height
)
592 && coordinates_in_window (XWINDOW (frame
->toolbar_window
), &x
, &y
))
595 return frame
->toolbar_window
;
601 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
602 "Return window containing coordinates X and Y on FRAME.\n\
603 If omitted, FRAME defaults to the currently selected frame.\n\
604 The top left corner of the frame is considered to be row 0,\n\
607 Lisp_Object x
, y
, frame
;
613 XSETFRAME (frame
, selected_frame
);
615 CHECK_LIVE_FRAME (frame
, 2);
618 /* Check that arguments are integers or floats. */
619 CHECK_NUMBER_OR_FLOAT (x
, 0);
620 CHECK_NUMBER_OR_FLOAT (y
, 1);
622 return window_from_coordinates (f
,
623 PIXEL_X_FROM_CANON_X (f
, x
),
624 PIXEL_Y_FROM_CANON_Y (f
, y
),
628 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
629 "Return current value of point in WINDOW.\n\
630 For a nonselected window, this is the value point would have\n\
631 if that window were selected.\n\
633 Note that, when WINDOW is the selected window and its buffer\n\
634 is also currently selected, the value returned is the same as (point).\n\
635 It would be more strictly correct to return the `top-level' value\n\
636 of point, outside of any save-excursion forms.\n\
637 But that is hard to define.")
641 register struct window
*w
= decode_window (window
);
643 if (w
== XWINDOW (selected_window
)
644 && current_buffer
== XBUFFER (w
->buffer
))
646 return Fmarker_position (w
->pointm
);
649 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
650 "Return position at which display currently starts in WINDOW.\n\
651 This is updated by redisplay or by calling `set-window-start'.")
655 return Fmarker_position (decode_window (window
)->start
);
658 /* This is text temporarily removed from the doc string below.
660 This function returns nil if the position is not currently known.\n\
661 That happens when redisplay is preempted and doesn't finish.\n\
662 If in that case you want to compute where the end of the window would\n\
663 have been if redisplay had finished, do this:\n\
665 (goto-char (window-start window))\n\
666 (vertical-motion (1- (window-height window)) window)\n\
669 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
670 "Return position at which display currently ends in WINDOW.\n\
671 This is updated by redisplay, when it runs to completion.\n\
672 Simply changing the buffer text or setting `window-start'\n\
673 does not update this value.\n\
674 If UP-TO-DATE is non-nil, compute the up-to-date position\n\
675 if it isn't already recorded.")
677 Lisp_Object window
, update
;
680 struct window
*w
= decode_window (window
);
684 CHECK_BUFFER (buf
, 0);
686 #if 0 /* This change broke some things. We should make it later. */
687 /* If we don't know the end position, return nil.
688 The user can compute it with vertical-motion if he wants to.
689 It would be nicer to do it automatically,
690 but that's so slow that it would probably bother people. */
691 if (NILP (w
->window_end_valid
))
696 && ! (! NILP (w
->window_end_valid
)
697 && XFASTINT (w
->last_modified
) >= MODIFF
))
699 int opoint
= PT
, opoint_byte
= PT_BYTE
;
700 TEMP_SET_PT_BOTH (XMARKER (w
->start
)->charpos
,
701 XMARKER (w
->start
)->bytepos
);
702 Fvertical_motion (make_number (window_internal_height (w
)), Qnil
);
704 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
708 BUF_Z (XBUFFER (buf
)) - XFASTINT (w
->window_end_pos
));
713 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
714 "Make point value in WINDOW be at position POS in WINDOW's buffer.")
716 Lisp_Object window
, pos
;
718 register struct window
*w
= decode_window (window
);
720 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
721 if (w
== XWINDOW (selected_window
)
722 && XBUFFER (w
->buffer
) == current_buffer
)
725 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
730 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
731 "Make display in WINDOW start at position POS in WINDOW's buffer.\n\
732 Optional third arg NOFORCE non-nil inhibits next redisplay\n\
733 from overriding motion of point in order to display at this exact start.")
734 (window
, pos
, noforce
)
735 Lisp_Object window
, pos
, noforce
;
737 register struct window
*w
= decode_window (window
);
739 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
740 set_marker_restricted (w
->start
, pos
, w
->buffer
);
741 /* this is not right, but much easier than doing what is right. */
742 w
->start_at_line_beg
= Qnil
;
745 w
->update_mode_line
= Qt
;
746 XSETFASTINT (w
->last_modified
, 0);
747 XSETFASTINT (w
->last_overlay_modified
, 0);
748 if (!EQ (window
, selected_window
))
749 windows_or_buffers_changed
++;
753 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
755 "Return WINDOW's dedicated object, usually t or nil.\n\
756 See also `set-window-dedicated-p'.")
760 return decode_window (window
)->dedicated
;
763 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
764 Sset_window_dedicated_p
, 2, 2, 0,
765 "Control whether WINDOW is dedicated to the buffer it displays.\n\
766 If it is dedicated, Emacs will not automatically change\n\
767 which buffer appears in it.\n\
768 The second argument is the new value for the dedication flag;\n\
771 Lisp_Object window
, arg
;
773 register struct window
*w
= decode_window (window
);
783 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
785 "Return the display-table that WINDOW is using.")
789 return decode_window (window
)->display_table
;
792 /* Get the display table for use on window W. This is either W's
793 display table or W's buffer's display table. Ignore the specified
794 tables if they are not valid; if no valid table is specified,
797 struct Lisp_Char_Table
*
798 window_display_table (w
)
802 tem
= w
->display_table
;
803 if (DISP_TABLE_P (tem
))
804 return XCHAR_TABLE (tem
);
805 if (NILP (w
->buffer
))
808 tem
= XBUFFER (w
->buffer
)->display_table
;
809 if (DISP_TABLE_P (tem
))
810 return XCHAR_TABLE (tem
);
811 tem
= Vstandard_display_table
;
812 if (DISP_TABLE_P (tem
))
813 return XCHAR_TABLE (tem
);
817 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
818 "Set WINDOW's display-table to TABLE.")
820 register Lisp_Object window
, table
;
822 register struct window
*w
;
824 w
= decode_window (window
);
825 w
->display_table
= table
;
829 /* Record info on buffer window w is displaying
830 when it is about to cease to display that buffer. */
833 register struct window
*w
;
840 if (b
!= XMARKER (w
->pointm
)->buffer
)
843 if (w
== XWINDOW (b
->last_selected_window
))
844 b
->last_selected_window
= Qnil
;
847 if (w
== XWINDOW (selected_window
)
848 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
849 /* Do this except when the selected window's buffer
850 is being removed from some other window. */
852 /* last_window_start records the start position that this buffer
853 had in the last window to be disconnected from it.
854 Now that this statement is unconditional,
855 it is possible for the buffer to be displayed in the
856 selected window, while last_window_start reflects another
857 window which was recently showing the same buffer.
858 Some people might say that might be a good thing. Let's see. */
859 b
->last_window_start
= marker_position (w
->start
);
861 /* Point in the selected window's buffer
862 is actually stored in that buffer, and the window's pointm isn't used.
863 So don't clobber point in that buffer. */
864 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
))
865 temp_set_point_both (b
,
866 clip_to_bounds (BUF_BEGV (b
),
867 XMARKER (w
->pointm
)->charpos
,
869 clip_to_bounds (BUF_BEGV_BYTE (b
),
870 marker_byte_position (w
->pointm
),
874 /* Put replacement into the window structure in place of old. */
876 replace_window (old
, replacement
)
877 Lisp_Object old
, replacement
;
879 register Lisp_Object tem
;
880 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
882 /* If OLD is its frame's root_window, then replacement is the new
883 root_window for that frame. */
885 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
886 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
891 p
->height
= o
->height
;
892 p
->desired_matrix
= p
->current_matrix
= 0;
894 bzero (&p
->cursor
, sizeof (p
->cursor
));
895 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
896 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
897 p
->phys_cursor_type
= -1;
898 p
->must_be_updated_p
= 0;
899 p
->pseudo_window_p
= 0;
900 XSETFASTINT (p
->window_end_vpos
, 0);
901 XSETFASTINT (p
->window_end_pos
, 0);
902 p
->window_end_valid
= Qnil
;
904 p
->next
= tem
= o
->next
;
906 XWINDOW (tem
)->prev
= replacement
;
908 p
->prev
= tem
= o
->prev
;
910 XWINDOW (tem
)->next
= replacement
;
912 p
->parent
= tem
= o
->parent
;
915 if (EQ (XWINDOW (tem
)->vchild
, old
))
916 XWINDOW (tem
)->vchild
= replacement
;
917 if (EQ (XWINDOW (tem
)->hchild
, old
))
918 XWINDOW (tem
)->hchild
= replacement
;
921 /*** Here, if replacement is a vertical combination
922 and so is its new parent, we should make replacement's
923 children be children of that parent instead. ***/
926 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
927 "Remove WINDOW from the display. Default is selected window.")
929 register Lisp_Object window
;
931 delete_window (window
);
933 if (! NILP (Vwindow_configuration_change_hook
)
934 && ! NILP (Vrun_hooks
))
935 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
941 delete_window (window
)
942 register Lisp_Object window
;
944 register Lisp_Object tem
, parent
, sib
;
945 register struct window
*p
;
946 register struct window
*par
;
949 /* Because this function is called by other C code on non-leaf
950 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
951 so we can't decode_window here. */
953 window
= selected_window
;
955 CHECK_WINDOW (window
, 0);
956 p
= XWINDOW (window
);
958 /* It's okay to delete an already-deleted window. */
966 error ("Attempt to delete minibuffer or sole ordinary window");
967 par
= XWINDOW (parent
);
969 windows_or_buffers_changed
++;
970 frame
= XFRAME (WINDOW_FRAME (p
));
971 FRAME_WINDOW_SIZES_CHANGED (frame
) = 1;
973 /* Are we trying to delete any frame's selected window? */
975 Lisp_Object frame
, pwindow
;
977 /* See if the frame's selected window is either WINDOW
978 or any subwindow of it, by finding all that window's parents
979 and comparing each one with WINDOW. */
980 frame
= WINDOW_FRAME (XWINDOW (window
));
981 pwindow
= FRAME_SELECTED_WINDOW (XFRAME (frame
));
983 while (!NILP (pwindow
))
985 if (EQ (window
, pwindow
))
987 pwindow
= XWINDOW (pwindow
)->parent
;
990 if (EQ (window
, pwindow
))
992 Lisp_Object alternative
;
993 alternative
= Fnext_window (window
, Qlambda
, Qnil
);
995 /* If we're about to delete the selected window on the
996 selected frame, then we should use Fselect_window to select
997 the new window. On the other hand, if we're about to
998 delete the selected window on any other frame, we shouldn't do
999 anything but set the frame's selected_window slot. */
1000 if (EQ (window
, selected_window
))
1001 Fselect_window (alternative
);
1003 FRAME_SELECTED_WINDOW (XFRAME (frame
)) = alternative
;
1008 /* tem is null for dummy parent windows
1009 (which have inferiors but not any contents themselves) */
1013 unchain_marker (p
->pointm
);
1014 unchain_marker (p
->start
);
1017 /* Free window glyph matrices.
1018 It is sure that they are allocated again when ADJUST_GLYPHS
1020 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (frame
)));
1024 XWINDOW (tem
)->prev
= p
->prev
;
1028 XWINDOW (tem
)->next
= p
->next
;
1030 if (EQ (window
, par
->hchild
))
1031 par
->hchild
= p
->next
;
1032 if (EQ (window
, par
->vchild
))
1033 par
->vchild
= p
->next
;
1035 /* Find one of our siblings to give our space to. */
1039 /* If p gives its space to its next sibling, that sibling needs
1040 to have its top/left side pulled back to where p's is.
1041 set_window_{height,width} will re-position the sibling's
1044 XWINDOW (sib
)->top
= p
->top
;
1045 XWINDOW (sib
)->left
= p
->left
;
1048 /* Stretch that sibling. */
1049 if (!NILP (par
->vchild
))
1050 set_window_height (sib
,
1051 XFASTINT (XWINDOW (sib
)->height
) + XFASTINT (p
->height
),
1053 if (!NILP (par
->hchild
))
1054 set_window_width (sib
,
1055 XFASTINT (XWINDOW (sib
)->width
) + XFASTINT (p
->width
),
1058 /* If parent now has only one child,
1059 put the child into the parent's place. */
1063 if (NILP (XWINDOW (tem
)->next
))
1064 replace_window (parent
, tem
);
1066 /* Since we may be deleting combination windows, we must make sure that
1067 not only p but all its children have been marked as deleted. */
1068 if (! NILP (p
->hchild
))
1069 delete_all_subwindows (XWINDOW (p
->hchild
));
1070 else if (! NILP (p
->vchild
))
1071 delete_all_subwindows (XWINDOW (p
->vchild
));
1073 /* Mark this window as deleted. */
1074 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1076 /* Adjust glyph matrices. */
1077 adjust_glyphs (frame
);
1081 extern Lisp_Object
next_frame (), prev_frame ();
1083 /* This comment supplies the doc string for `next-window',
1084 for make-docfile to see. We cannot put this in the real DEFUN
1085 due to limits in the Unix cpp.
1087 DEFUN ("next-window", Ffoo, Sfoo, 0, 3, 0,
1088 "Return next window after WINDOW in canonical ordering of windows.\n\
1089 If omitted, WINDOW defaults to the selected window.\n\
1091 Optional second arg MINIBUF t means count the minibuffer window even\n\
1092 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1093 it is active. MINIBUF neither t nor nil means not to count the\n\
1094 minibuffer even if it is active.\n\
1096 Several frames may share a single minibuffer; if the minibuffer\n\
1097 counts, all windows on all frames that share that minibuffer count\n\
1098 too. Therefore, `next-window' can be used to iterate through the\n\
1099 set of windows even when the minibuffer is on another frame. If the\n\
1100 minibuffer does not count, only windows from WINDOW's frame count.\n\
1102 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1103 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1104 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1105 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1106 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1107 Anything else means restrict to WINDOW's frame.\n\
1109 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1110 `next-window' to iterate through the entire cycle of acceptable\n\
1111 windows, eventually ending up back at the window you started with.\n\
1112 `previous-window' traverses the same cycle, in the reverse order.")
1113 (window, minibuf, all_frames) */
1115 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
1117 (window
, minibuf
, all_frames
)
1118 register Lisp_Object window
, minibuf
, all_frames
;
1120 register Lisp_Object tem
;
1121 Lisp_Object start_window
;
1124 window
= selected_window
;
1126 CHECK_LIVE_WINDOW (window
, 0);
1128 start_window
= window
;
1130 /* minibuf == nil may or may not include minibuffers.
1131 Decide if it does. */
1133 minibuf
= (minibuf_level
? minibuf_window
: Qlambda
);
1134 else if (! EQ (minibuf
, Qt
))
1136 /* Now minibuf can be t => count all minibuffer windows,
1137 lambda => count none of them,
1138 or a specific minibuffer window (the active one) to count. */
1140 /* all_frames == nil doesn't specify which frames to include. */
1141 if (NILP (all_frames
))
1142 all_frames
= (! EQ (minibuf
, Qlambda
)
1143 ? (FRAME_MINIBUF_WINDOW
1146 (XWINDOW (window
)))))
1148 else if (EQ (all_frames
, Qvisible
))
1150 else if (XFASTINT (all_frames
) == 0)
1152 else if (FRAMEP (all_frames
) && ! EQ (all_frames
, Fwindow_frame (window
)))
1153 /* If all_frames is a frame and window arg isn't on that frame, just
1154 return the first window on the frame. */
1155 return Fframe_first_window (all_frames
);
1156 else if (! EQ (all_frames
, Qt
))
1158 /* Now all_frames is t meaning search all frames,
1159 nil meaning search just current frame,
1160 visible meaning search just visible frames,
1161 0 meaning search visible and iconified frames,
1162 or a window, meaning search the frame that window belongs to. */
1164 /* Do this loop at least once, to get the next window, and perhaps
1165 again, if we hit the minibuffer and that is not acceptable. */
1168 /* Find a window that actually has a next one. This loop
1169 climbs up the tree. */
1170 while (tem
= XWINDOW (window
)->next
, NILP (tem
))
1171 if (tem
= XWINDOW (window
)->parent
, !NILP (tem
))
1175 /* We've reached the end of this frame.
1176 Which other frames are acceptable? */
1177 tem
= WINDOW_FRAME (XWINDOW (window
));
1178 if (! NILP (all_frames
))
1183 tem
= next_frame (tem
, all_frames
);
1184 /* In the case where the minibuffer is active,
1185 and we include its frame as well as the selected one,
1186 next_frame may get stuck in that frame.
1187 If that happens, go back to the selected frame
1188 so we can complete the cycle. */
1190 XSETFRAME (tem
, selected_frame
);
1192 tem
= FRAME_ROOT_WINDOW (XFRAME (tem
));
1199 /* If we're in a combination window, find its first child and
1200 recurse on that. Otherwise, we've found the window we want. */
1203 if (!NILP (XWINDOW (window
)->hchild
))
1204 window
= XWINDOW (window
)->hchild
;
1205 else if (!NILP (XWINDOW (window
)->vchild
))
1206 window
= XWINDOW (window
)->vchild
;
1210 /* Which windows are acceptable?
1211 Exit the loop and accept this window if
1212 this isn't a minibuffer window,
1213 or we're accepting all minibuffer windows,
1214 or this is the active minibuffer and we are accepting that one, or
1215 we've come all the way around and we're back at the original window. */
1216 while (MINI_WINDOW_P (XWINDOW (window
))
1217 && ! EQ (minibuf
, Qt
)
1218 && ! EQ (minibuf
, window
)
1219 && ! EQ (window
, start_window
));
1224 /* This comment supplies the doc string for `previous-window',
1225 for make-docfile to see. We cannot put this in the real DEFUN
1226 due to limits in the Unix cpp.
1228 DEFUN ("previous-window", Ffoo, Sfoo, 0, 3, 0,
1229 "Return the window preceding WINDOW in canonical ordering of windows.\n\
1230 If omitted, WINDOW defaults to the selected window.\n\
1232 Optional second arg MINIBUF t means count the minibuffer window even\n\
1233 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1234 it is active. MINIBUF neither t nor nil means not to count the\n\
1235 minibuffer even if it is active.\n\
1237 Several frames may share a single minibuffer; if the minibuffer\n\
1238 counts, all windows on all frames that share that minibuffer count\n\
1239 too. Therefore, `previous-window' can be used to iterate through\n\
1240 the set of windows even when the minibuffer is on another frame. If\n\
1241 the minibuffer does not count, only windows from WINDOW's frame count\n\
1243 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1244 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1245 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1246 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1247 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1248 Anything else means restrict to WINDOW's frame.\n\
1250 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1251 `previous-window' to iterate through the entire cycle of acceptable\n\
1252 windows, eventually ending up back at the window you started with.\n\
1253 `next-window' traverses the same cycle, in the reverse order.")
1254 (window, minibuf, all_frames) */
1257 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1259 (window
, minibuf
, all_frames
)
1260 register Lisp_Object window
, minibuf
, all_frames
;
1262 register Lisp_Object tem
;
1263 Lisp_Object start_window
;
1266 window
= selected_window
;
1268 CHECK_LIVE_WINDOW (window
, 0);
1270 start_window
= window
;
1272 /* minibuf == nil may or may not include minibuffers.
1273 Decide if it does. */
1275 minibuf
= (minibuf_level
? minibuf_window
: Qlambda
);
1276 else if (! EQ (minibuf
, Qt
))
1278 /* Now minibuf can be t => count all minibuffer windows,
1279 lambda => count none of them,
1280 or a specific minibuffer window (the active one) to count. */
1282 /* all_frames == nil doesn't specify which frames to include.
1283 Decide which frames it includes. */
1284 if (NILP (all_frames
))
1285 all_frames
= (! EQ (minibuf
, Qlambda
)
1286 ? (FRAME_MINIBUF_WINDOW
1289 (XWINDOW (window
)))))
1291 else if (EQ (all_frames
, Qvisible
))
1293 else if (XFASTINT (all_frames
) == 0)
1295 else if (FRAMEP (all_frames
) && ! EQ (all_frames
, Fwindow_frame (window
)))
1296 /* If all_frames is a frame and window arg isn't on that frame, just
1297 return the first window on the frame. */
1298 return Fframe_first_window (all_frames
);
1299 else if (! EQ (all_frames
, Qt
))
1301 /* Now all_frames is t meaning search all frames,
1302 nil meaning search just current frame,
1303 visible meaning search just visible frames,
1304 0 meaning search visible and iconified frames,
1305 or a window, meaning search the frame that window belongs to. */
1307 /* Do this loop at least once, to get the previous window, and perhaps
1308 again, if we hit the minibuffer and that is not acceptable. */
1311 /* Find a window that actually has a previous one. This loop
1312 climbs up the tree. */
1313 while (tem
= XWINDOW (window
)->prev
, NILP (tem
))
1314 if (tem
= XWINDOW (window
)->parent
, !NILP (tem
))
1318 /* We have found the top window on the frame.
1319 Which frames are acceptable? */
1320 tem
= WINDOW_FRAME (XWINDOW (window
));
1321 if (! NILP (all_frames
))
1322 /* It's actually important that we use prev_frame here,
1323 rather than next_frame. All the windows acceptable
1324 according to the given parameters should form a ring;
1325 Fnext_window and Fprevious_window should go back and
1326 forth around the ring. If we use next_frame here,
1327 then Fnext_window and Fprevious_window take different
1328 paths through the set of acceptable windows.
1329 window_loop assumes that these `ring' requirement are
1335 tem
= prev_frame (tem
, all_frames
);
1336 /* In the case where the minibuffer is active,
1337 and we include its frame as well as the selected one,
1338 next_frame may get stuck in that frame.
1339 If that happens, go back to the selected frame
1340 so we can complete the cycle. */
1342 XSETFRAME (tem
, selected_frame
);
1344 /* If this frame has a minibuffer, find that window first,
1345 because it is conceptually the last window in that frame. */
1346 if (FRAME_HAS_MINIBUF_P (XFRAME (tem
)))
1347 tem
= FRAME_MINIBUF_WINDOW (XFRAME (tem
));
1349 tem
= FRAME_ROOT_WINDOW (XFRAME (tem
));
1355 /* If we're in a combination window, find its last child and
1356 recurse on that. Otherwise, we've found the window we want. */
1359 if (!NILP (XWINDOW (window
)->hchild
))
1360 window
= XWINDOW (window
)->hchild
;
1361 else if (!NILP (XWINDOW (window
)->vchild
))
1362 window
= XWINDOW (window
)->vchild
;
1364 while (tem
= XWINDOW (window
)->next
, !NILP (tem
))
1368 /* Which windows are acceptable?
1369 Exit the loop and accept this window if
1370 this isn't a minibuffer window,
1371 or we're accepting all minibuffer windows,
1372 or this is the active minibuffer and we are accepting that one, or
1373 we've come all the way around and we're back at the original window. */
1374 while (MINI_WINDOW_P (XWINDOW (window
))
1375 && ! EQ (minibuf
, Qt
)
1376 && ! EQ (minibuf
, window
)
1377 && ! EQ (window
, start_window
));
1382 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1383 "Select the ARG'th different window on this frame.\n\
1384 All windows on current frame are arranged in a cyclic order.\n\
1385 This command selects the window ARG steps away in that order.\n\
1386 A negative ARG moves in the opposite order. If the optional second\n\
1387 argument ALL_FRAMES is non-nil, cycle through all frames.")
1389 register Lisp_Object arg
, all_frames
;
1392 register Lisp_Object w
;
1394 CHECK_NUMBER (arg
, 0);
1395 w
= selected_window
;
1400 w
= Fnext_window (w
, Qnil
, all_frames
);
1405 w
= Fprevious_window (w
, Qnil
, all_frames
);
1412 /* Look at all windows, performing an operation specified by TYPE
1414 If FRAMES is Qt, look at all frames;
1415 Qnil, look at just the selected frame;
1416 Qvisible, look at visible frames;
1417 a frame, just look at windows on that frame.
1418 If MINI is non-zero, perform the operation on minibuffer windows too.
1424 GET_BUFFER_WINDOW
, /* Arg is buffer */
1425 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1426 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1427 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1429 UNSHOW_BUFFER
, /* Arg is buffer */
1434 window_loop (type
, obj
, mini
, frames
)
1435 enum window_loop type
;
1436 register Lisp_Object obj
, frames
;
1439 register Lisp_Object w
;
1440 register Lisp_Object best_window
;
1441 register Lisp_Object next_window
;
1442 register Lisp_Object last_window
;
1444 Lisp_Object frame_arg
;
1447 /* If we're only looping through windows on a particular frame,
1448 frame points to that frame. If we're looping through windows
1449 on all frames, frame is 0. */
1450 if (FRAMEP (frames
))
1451 frame
= XFRAME (frames
);
1452 else if (NILP (frames
))
1453 frame
= selected_frame
;
1457 frame_arg
= Qlambda
;
1458 else if (XFASTINT (frames
) == 0)
1460 else if (EQ (frames
, Qvisible
))
1463 /* frame_arg is Qlambda to stick to one frame,
1464 Qvisible to consider all visible frames,
1467 /* Pick a window to start with. */
1471 w
= FRAME_SELECTED_WINDOW (frame
);
1473 w
= FRAME_SELECTED_WINDOW (selected_frame
);
1475 /* Figure out the last window we're going to mess with. Since
1476 Fnext_window, given the same options, is guaranteed to go in a
1477 ring, we can just use Fprevious_window to find the last one.
1479 We can't just wait until we hit the first window again, because
1480 it might be deleted. */
1482 last_window
= Fprevious_window (w
, mini
? Qt
: Qnil
, frame_arg
);
1487 /* Pick the next window now, since some operations will delete
1488 the current window. */
1489 next_window
= Fnext_window (w
, mini
? Qt
: Qnil
, frame_arg
);
1491 /* Note that we do not pay attention here to whether
1492 the frame is visible, since Fnext_window skips non-visible frames
1493 if that is desired, under the control of frame_arg. */
1494 if (! MINI_WINDOW_P (XWINDOW (w
))
1495 /* For UNSHOW_BUFFER, we must always consider all windows. */
1496 || type
== UNSHOW_BUFFER
1497 || (mini
&& minibuf_level
> 0))
1500 case GET_BUFFER_WINDOW
:
1501 if (XBUFFER (XWINDOW (w
)->buffer
) == XBUFFER (obj
)
1502 /* Don't find any minibuffer window
1503 except the one that is currently in use. */
1504 && (MINI_WINDOW_P (XWINDOW (w
))
1505 ? EQ (w
, minibuf_window
) : 1))
1509 case GET_LRU_WINDOW
:
1510 /* t as arg means consider only full-width windows */
1511 if (!NILP (obj
) && !WINDOW_FULL_WIDTH_P (XWINDOW (w
)))
1513 /* Ignore dedicated windows and minibuffers. */
1514 if (MINI_WINDOW_P (XWINDOW (w
))
1515 || !NILP (XWINDOW (w
)->dedicated
))
1517 if (NILP (best_window
)
1518 || (XFASTINT (XWINDOW (best_window
)->use_time
)
1519 > XFASTINT (XWINDOW (w
)->use_time
)))
1523 case DELETE_OTHER_WINDOWS
:
1524 if (XWINDOW (w
) != XWINDOW (obj
))
1528 case DELETE_BUFFER_WINDOWS
:
1529 if (EQ (XWINDOW (w
)->buffer
, obj
))
1531 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1533 /* If this window is dedicated, and in a frame of its own,
1535 if (EQ (w
, FRAME_ROOT_WINDOW (f
))
1536 && !NILP (XWINDOW (w
)->dedicated
)
1537 && other_visible_frames (f
))
1539 /* Skip the other windows on this frame.
1540 There might be one, the minibuffer! */
1541 if (! EQ (w
, last_window
))
1542 while (f
== XFRAME (WINDOW_FRAME (XWINDOW (next_window
))))
1544 /* As we go, check for the end of the loop.
1545 We mustn't start going around a second time. */
1546 if (EQ (next_window
, last_window
))
1551 next_window
= Fnext_window (next_window
,
1555 /* Now we can safely delete the frame. */
1556 Fdelete_frame (WINDOW_FRAME (XWINDOW (w
)), Qnil
);
1559 /* If we're deleting the buffer displayed in the only window
1560 on the frame, find a new buffer to display there. */
1561 if (NILP (XWINDOW (w
)->parent
))
1563 Lisp_Object new_buffer
;
1564 new_buffer
= Fother_buffer (obj
, Qnil
,
1565 XWINDOW (w
)->frame
);
1566 if (NILP (new_buffer
))
1568 = Fget_buffer_create (build_string ("*scratch*"));
1569 Fset_window_buffer (w
, new_buffer
);
1570 if (EQ (w
, selected_window
))
1571 Fset_buffer (XWINDOW (w
)->buffer
);
1578 case GET_LARGEST_WINDOW
:
1579 /* Ignore dedicated windows and minibuffers. */
1580 if (MINI_WINDOW_P (XWINDOW (w
))
1581 || !NILP (XWINDOW (w
)->dedicated
))
1584 struct window
*best_window_ptr
= XWINDOW (best_window
);
1585 struct window
*w_ptr
= XWINDOW (w
);
1586 if (NILP (best_window
)
1587 || (XFASTINT (w_ptr
->height
) * XFASTINT (w_ptr
->width
)
1588 > (XFASTINT (best_window_ptr
->height
)
1589 * XFASTINT (best_window_ptr
->width
))))
1595 if (EQ (XWINDOW (w
)->buffer
, obj
))
1597 /* Find another buffer to show in this window. */
1598 Lisp_Object another_buffer
;
1599 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1600 another_buffer
= Fother_buffer (obj
, Qnil
, XWINDOW (w
)->frame
);
1601 if (NILP (another_buffer
))
1603 = Fget_buffer_create (build_string ("*scratch*"));
1604 /* If this window is dedicated, and in a frame of its own,
1606 if (EQ (w
, FRAME_ROOT_WINDOW (f
))
1607 && !NILP (XWINDOW (w
)->dedicated
)
1608 && other_visible_frames (f
))
1610 /* Skip the other windows on this frame.
1611 There might be one, the minibuffer! */
1612 if (! EQ (w
, last_window
))
1613 while (f
== XFRAME (WINDOW_FRAME (XWINDOW (next_window
))))
1615 /* As we go, check for the end of the loop.
1616 We mustn't start going around a second time. */
1617 if (EQ (next_window
, last_window
))
1622 next_window
= Fnext_window (next_window
,
1626 /* Now we can safely delete the frame. */
1627 Fdelete_frame (WINDOW_FRAME (XWINDOW (w
)), Qnil
);
1631 /* Otherwise show a different buffer in the window. */
1632 XWINDOW (w
)->dedicated
= Qnil
;
1633 Fset_window_buffer (w
, another_buffer
);
1634 if (EQ (w
, selected_window
))
1635 Fset_buffer (XWINDOW (w
)->buffer
);
1640 /* Check for a window that has a killed buffer. */
1641 case CHECK_ALL_WINDOWS
:
1642 if (! NILP (XWINDOW (w
)->buffer
)
1643 && NILP (XBUFFER (XWINDOW (w
)->buffer
)->name
))
1647 if (EQ (w
, last_window
))
1656 /* Used for debugging. Abort if any window has a dead buffer. */
1658 check_all_windows ()
1660 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
1663 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 1, 0,
1664 "Return the window least recently selected or used for display.\n\
1665 If optional argument FRAME is `visible', search all visible frames.\n\
1666 If FRAME is 0, search all visible and iconified frames.\n\
1667 If FRAME is t, search all frames.\n\
1668 If FRAME is nil, search only the selected frame.\n\
1669 If FRAME is a frame, search only that frame.")
1673 register Lisp_Object w
;
1674 /* First try for a window that is full-width */
1675 w
= window_loop (GET_LRU_WINDOW
, Qt
, 0, frame
);
1676 if (!NILP (w
) && !EQ (w
, selected_window
))
1678 /* If none of them, try the rest */
1679 return window_loop (GET_LRU_WINDOW
, Qnil
, 0, frame
);
1682 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 1, 0,
1683 "Return the largest window in area.\n\
1684 If optional argument FRAME is `visible', search all visible frames.\n\
1685 If FRAME is 0, search all visible and iconified frames.\n\
1686 If FRAME is t, search all frames.\n\
1687 If FRAME is nil, search only the selected frame.\n\
1688 If FRAME is a frame, search only that frame.")
1692 return window_loop (GET_LARGEST_WINDOW
, Qnil
, 0,
1696 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
1697 "Return a window currently displaying BUFFER, or nil if none.\n\
1698 If optional argument FRAME is `visible', search all visible frames.\n\
1699 If optional argument FRAME is 0, search all visible and iconified frames.\n\
1700 If FRAME is t, search all frames.\n\
1701 If FRAME is nil, search only the selected frame.\n\
1702 If FRAME is a frame, search only that frame.")
1704 Lisp_Object buffer
, frame
;
1706 buffer
= Fget_buffer (buffer
);
1707 if (BUFFERP (buffer
))
1708 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
1713 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
1715 "Make WINDOW (or the selected window) fill its frame.\n\
1716 Only the frame WINDOW is on is affected.\n\
1717 This function tries to reduce display jumps\n\
1718 by keeping the text previously visible in WINDOW\n\
1719 in the same place on the frame. Doing this depends on\n\
1720 the value of (window-start WINDOW), so if calling this function\n\
1721 in a program gives strange scrolling, make sure the window-start\n\
1722 value is reasonable when this function is called.")
1731 window
= selected_window
;
1733 CHECK_LIVE_WINDOW (window
, 0);
1735 w
= XWINDOW (window
);
1737 startpos
= marker_position (w
->start
);
1738 top
= XFASTINT (w
->top
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
1740 if (MINI_WINDOW_P (w
) && top
> 0)
1741 error ("Can't expand minibuffer to full frame");
1743 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
1745 /* Try to minimize scrolling, by setting the window start to the point
1746 will cause the text at the old window start to be at the same place
1747 on the frame. But don't try to do this if the window start is
1748 outside the visible portion (as might happen when the display is
1749 not current, due to typeahead). */
1750 if (startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
1751 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
1753 struct position pos
;
1754 struct buffer
*obuf
= current_buffer
;
1756 Fset_buffer (w
->buffer
);
1757 /* This computation used to temporarily move point, but that can
1758 have unwanted side effects due to text properties. */
1759 pos
= *vmotion (startpos
, -top
, w
);
1761 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
1762 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
1763 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
1765 /* We need to do this, so that the window-scroll-functions
1767 w
->optional_new_start
= Qt
;
1769 set_buffer_internal (obuf
);
1775 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
1776 1, 2, "bDelete windows on (buffer): ",
1777 "Delete all windows showing BUFFER.\n\
1778 Optional second argument FRAME controls which frames are affected.\n\
1779 If optional argument FRAME is `visible', search all visible frames.\n\
1780 If FRAME is 0, search all visible and iconified frames.\n\
1781 If FRAME is nil, search all frames.\n\
1782 If FRAME is t, search only the selected frame.\n\
1783 If FRAME is a frame, search only that frame.")
1785 Lisp_Object buffer
, frame
;
1787 /* FRAME uses t and nil to mean the opposite of what window_loop
1791 else if (EQ (frame
, Qt
))
1796 buffer
= Fget_buffer (buffer
);
1797 CHECK_BUFFER (buffer
, 0);
1798 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
1804 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
1805 Sreplace_buffer_in_windows
,
1806 1, 1, "bReplace buffer in windows: ",
1807 "Replace BUFFER with some other buffer in all windows showing it.")
1813 buffer
= Fget_buffer (buffer
);
1814 CHECK_BUFFER (buffer
, 0);
1815 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
1820 /* Replace BUFFER with some other buffer in all windows
1821 of all frames, even those on other keyboards. */
1824 replace_buffer_in_all_windows (buffer
)
1828 Lisp_Object tail
, frame
;
1830 /* A single call to window_loop won't do the job
1831 because it only considers frames on the current keyboard.
1832 So loop manually over frames, and handle each one. */
1833 FOR_EACH_FRAME (tail
, frame
)
1834 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
1836 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
1840 /* Set the height of WINDOW and all its inferiors. */
1842 /* The smallest acceptable dimensions for a window. Anything smaller
1843 might crash Emacs. */
1845 #define MIN_SAFE_WINDOW_WIDTH (2)
1846 #define MIN_SAFE_WINDOW_HEIGHT (2)
1848 /* Make sure that window_min_height and window_min_width are
1849 not too small; if they are, set them to safe minima. */
1852 check_min_window_sizes ()
1854 /* Smaller values might permit a crash. */
1855 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
1856 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
1857 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
1858 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
1861 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
1862 minimum allowable size. */
1865 check_frame_size (frame
, rows
, cols
)
1869 /* For height, we have to see:
1870 whether the frame has a minibuffer,
1871 whether it wants a mode line, and
1872 whether it has a menu bar. */
1874 (FRAME_MINIBUF_ONLY_P (frame
) ? MIN_SAFE_WINDOW_HEIGHT
- 1
1875 : (! FRAME_HAS_MINIBUF_P (frame
)) ? MIN_SAFE_WINDOW_HEIGHT
1876 : 2 * MIN_SAFE_WINDOW_HEIGHT
- 1);
1878 if (FRAME_TOP_MARGIN (frame
) > 0)
1879 min_height
+= FRAME_TOP_MARGIN (frame
);
1881 if (*rows
< min_height
)
1883 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
1884 *cols
= MIN_SAFE_WINDOW_WIDTH
;
1887 /* Normally the window is deleted if it gets too small. nodelete
1888 nonzero means do not do this. (The caller should check later and
1889 do so if appropriate) */
1892 set_window_height (window
, height
, nodelete
)
1897 register struct window
*w
= XWINDOW (window
);
1898 register struct window
*c
;
1899 int oheight
= XFASTINT (w
->height
);
1900 int top
, pos
, lastbot
, opos
, lastobot
;
1903 check_min_window_sizes ();
1906 && ! NILP (w
->parent
)
1907 && (MINI_WINDOW_P (w
)
1909 : height
< window_min_height
))
1911 delete_window (window
);
1915 XSETFASTINT (w
->last_modified
, 0);
1916 XSETFASTINT (w
->last_overlay_modified
, 0);
1917 windows_or_buffers_changed
++;
1918 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
1920 XSETFASTINT (w
->height
, height
);
1921 if (!NILP (w
->hchild
))
1923 for (child
= w
->hchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1925 XWINDOW (child
)->top
= w
->top
;
1926 set_window_height (child
, height
, nodelete
);
1929 else if (!NILP (w
->vchild
))
1931 lastbot
= top
= XFASTINT (w
->top
);
1933 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
1935 c
= XWINDOW (child
);
1937 opos
= lastobot
+ XFASTINT (c
->height
);
1939 XSETFASTINT (c
->top
, lastbot
);
1941 pos
= (((opos
* height
) << 1) + oheight
) / (oheight
<< 1);
1943 /* Avoid confusion: inhibit deletion of child if becomes too small */
1944 set_window_height (child
, pos
+ top
- lastbot
, 1);
1946 /* Now advance child to next window,
1947 and set lastbot if child was not just deleted. */
1948 lastbot
= pos
+ top
;
1951 /* Now delete any children that became too small. */
1953 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1955 set_window_height (child
, XINT (XWINDOW (child
)->height
), 0);
1960 /* Recursively set width of WINDOW and its inferiors. */
1963 set_window_width (window
, width
, nodelete
)
1968 register struct window
*w
= XWINDOW (window
);
1969 register struct window
*c
;
1970 int owidth
= XFASTINT (w
->width
);
1971 int left
, pos
, lastright
, opos
, lastoright
;
1974 if (!nodelete
&& width
< window_min_width
&& !NILP (w
->parent
))
1976 delete_window (window
);
1980 XSETFASTINT (w
->last_modified
, 0);
1981 XSETFASTINT (w
->last_overlay_modified
, 0);
1982 windows_or_buffers_changed
++;
1983 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
1985 XSETFASTINT (w
->width
, width
);
1986 if (!NILP (w
->vchild
))
1988 for (child
= w
->vchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
1990 XWINDOW (child
)->left
= w
->left
;
1991 set_window_width (child
, width
, nodelete
);
1994 else if (!NILP (w
->hchild
))
1996 lastright
= left
= XFASTINT (w
->left
);
1998 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
2000 c
= XWINDOW (child
);
2002 opos
= lastoright
+ XFASTINT (c
->width
);
2004 XSETFASTINT (c
->left
, lastright
);
2006 pos
= (((opos
* width
) << 1) + owidth
) / (owidth
<< 1);
2008 /* Inhibit deletion for becoming too small */
2009 set_window_width (child
, pos
+ left
- lastright
, 1);
2011 /* Now advance child to next window,
2012 and set lastright if child was not just deleted. */
2013 lastright
= pos
+ left
, lastoright
= opos
;
2015 /* Delete children that became too small */
2017 for (child
= w
->hchild
; !NILP (child
); child
= XWINDOW (child
)->next
)
2019 set_window_width (child
, XINT (XWINDOW (child
)->width
), 0);
2024 int window_select_count
;
2027 Fset_window_buffer_unwind (obuf
)
2035 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
2036 means it's allowed to run hooks. See make_frame for a case where
2037 it's not allowed. */
2040 set_window_buffer (window
, buffer
, run_hooks_p
)
2041 Lisp_Object window
, buffer
;
2044 struct window
*w
= XWINDOW (window
);
2045 struct buffer
*b
= XBUFFER (buffer
);
2046 int count
= specpdl_ptr
- specpdl
;
2050 if (EQ (window
, selected_window
))
2051 b
->last_selected_window
= window
;
2053 /* Update time stamps of buffer display. */
2054 if (INTEGERP (b
->display_count
))
2055 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
2056 b
->display_time
= Fcurrent_time ();
2058 XSETFASTINT (w
->window_end_pos
, 0);
2059 XSETFASTINT (w
->window_end_vpos
, 0);
2060 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
2061 w
->window_end_valid
= Qnil
;
2062 XSETFASTINT (w
->hscroll
, 0);
2063 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
2064 set_marker_restricted (w
->start
,
2065 make_number (b
->last_window_start
),
2067 w
->start_at_line_beg
= Qnil
;
2068 w
->force_start
= Qnil
;
2069 XSETFASTINT (w
->last_modified
, 0);
2070 XSETFASTINT (w
->last_overlay_modified
, 0);
2071 windows_or_buffers_changed
++;
2073 /* We must select BUFFER for running the window-scroll-functions.
2074 If WINDOW is selected, switch permanently.
2075 Otherwise, switch but go back to the ambient buffer afterward. */
2076 if (EQ (window
, selected_window
))
2077 Fset_buffer (buffer
);
2078 /* We can't check ! NILP (Vwindow_scroll_functions) here
2079 because that might itself be a local variable. */
2080 else if (window_initialized
)
2082 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
2083 Fset_buffer (buffer
);
2086 /* Set left and right marginal area width from buffer. */
2087 Fset_window_margins (b
->left_margin_width
, b
->right_margin_width
,
2092 if (! NILP (Vwindow_scroll_functions
))
2093 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2094 Fmarker_position (w
->start
));
2096 if (! NILP (Vwindow_configuration_change_hook
)
2097 && ! NILP (Vrun_hooks
))
2098 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2101 unbind_to (count
, Qnil
);
2105 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 2, 0,
2106 "Make WINDOW display BUFFER as its contents.\n\
2107 BUFFER can be a buffer or buffer name.")
2109 register Lisp_Object window
, buffer
;
2111 register Lisp_Object tem
;
2112 register struct window
*w
= decode_window (window
);
2115 buffer
= Fget_buffer (buffer
);
2116 CHECK_BUFFER (buffer
, 1);
2118 if (NILP (XBUFFER (buffer
)->name
))
2119 error ("Attempt to display deleted buffer");
2123 error ("Window is deleted");
2124 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
2125 is first being set up. */
2127 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
2128 error ("Window is dedicated to `%s'",
2129 XSTRING (XBUFFER (tem
)->name
)->data
);
2134 set_window_buffer (window
, buffer
, 1);
2138 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 1, 0,
2139 "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\
2140 If WINDOW is not already selected, also make WINDOW's buffer current.\n\
2141 Note that the main editor command loop\n\
2142 selects the buffer of the selected window before each command.")
2144 register Lisp_Object window
;
2146 return select_window_1 (window
, 1);
2150 select_window_1 (window
, recordflag
)
2151 register Lisp_Object window
;
2154 register struct window
*w
;
2155 register struct window
*ow
= XWINDOW (selected_window
);
2157 CHECK_LIVE_WINDOW (window
, 0);
2159 w
= XWINDOW (window
);
2161 if (NILP (w
->buffer
))
2162 error ("Trying to select deleted window or non-leaf window");
2164 XSETFASTINT (w
->use_time
, ++window_select_count
);
2165 if (EQ (window
, selected_window
))
2168 if (! NILP (ow
->buffer
))
2169 set_marker_both (ow
->pointm
, ow
->buffer
,
2170 BUF_PT (XBUFFER (ow
->buffer
)),
2171 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
2173 selected_window
= window
;
2174 if (XFRAME (WINDOW_FRAME (w
)) != selected_frame
)
2176 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
2177 /* Use this rather than Fhandle_switch_frame
2178 so that FRAME_FOCUS_FRAME is moved appropriately as we
2179 move around in the state where a minibuffer in a separate
2181 Fselect_frame (WINDOW_FRAME (w
), Qnil
);
2184 selected_frame
->selected_window
= window
;
2187 record_buffer (w
->buffer
);
2188 Fset_buffer (w
->buffer
);
2190 XBUFFER (w
->buffer
)->last_selected_window
= window
;
2192 /* Go to the point recorded in the window.
2193 This is important when the buffer is in more
2194 than one window. It also matters when
2195 redisplay_window has altered point after scrolling,
2196 because it makes the change only in the window. */
2198 register int new_point
= marker_position (w
->pointm
);
2199 if (new_point
< BEGV
)
2201 else if (new_point
> ZV
)
2207 windows_or_buffers_changed
++;
2211 /* Deiconify the frame containing the window WINDOW,
2212 unless it is the selected frame;
2215 The reason for the exception for the selected frame
2216 is that it seems better not to change the selected frames visibility
2217 merely because of displaying a different buffer in it.
2218 The deiconification is useful when a buffer gets shown in
2219 another frame that you were not using lately. */
2222 display_buffer_1 (window
)
2225 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
2226 FRAME_SAMPLE_VISIBILITY (f
);
2227 if (f
!= selected_frame
)
2229 if (FRAME_ICONIFIED_P (f
))
2230 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
2231 else if (FRAME_VISIBLE_P (f
))
2232 Fraise_frame (WINDOW_FRAME (XWINDOW (window
)));
2237 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
2238 "Returns non-nil if a buffer named BUFFER-NAME would be created specially.\n\
2239 The value is actually t if the frame should be called with default frame\n\
2240 parameters, and a list of frame parameters if they were specified.\n\
2241 See `special-display-buffer-names', and `special-display-regexps'.")
2243 Lisp_Object buffer_name
;
2247 CHECK_STRING (buffer_name
, 1);
2249 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
2253 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
2257 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2259 Lisp_Object car
= XCAR (tem
);
2261 && fast_string_match (car
, buffer_name
) >= 0)
2263 else if (CONSP (car
)
2264 && STRINGP (XCAR (car
))
2265 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2271 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
2272 "Returns non-nil if a new buffer named BUFFER-NAME would use the same window.\n\
2273 See `same-window-buffer-names' and `same-window-regexps'.")
2275 Lisp_Object buffer_name
;
2279 CHECK_STRING (buffer_name
, 1);
2281 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
2285 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
2289 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2291 Lisp_Object car
= XCAR (tem
);
2293 && fast_string_match (car
, buffer_name
) >= 0)
2295 else if (CONSP (car
)
2296 && STRINGP (XCAR (car
))
2297 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2303 /* Use B so the default is (other-buffer). */
2304 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
2305 "BDisplay buffer: \nP",
2306 "Make BUFFER appear in some window but don't select it.\n\
2307 BUFFER can be a buffer or a buffer name.\n\
2308 If BUFFER is shown already in some window, just use that one,\n\
2309 unless the window is the selected window and the optional second\n\
2310 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).\n\
2311 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.\n\
2312 Returns the window displaying BUFFER.\n\
2314 The variables `special-display-buffer-names', `special-display-regexps',\n\
2315 `same-window-buffer-names', and `same-window-regexps' customize how certain\n\
2316 buffer names are handled.\n\
2318 If optional argument FRAME is `visible', search all visible frames.\n\
2319 If FRAME is 0, search all visible and iconified frames.\n\
2320 If FRAME is t, search all frames.\n\
2321 If FRAME is a frame, search only that frame.\n\
2322 If FRAME is nil, search only the selected frame\n\
2323 (actually the last nonminibuffer frame),\n\
2324 unless `pop-up-frames' is non-nil,\n\
2325 which means search visible and iconified frames.")
2326 (buffer
, not_this_window
, frame
)
2327 register Lisp_Object buffer
, not_this_window
, frame
;
2329 register Lisp_Object window
, tem
;
2331 buffer
= Fget_buffer (buffer
);
2332 CHECK_BUFFER (buffer
, 0);
2334 if (!NILP (Vdisplay_buffer_function
))
2335 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
2337 if (NILP (not_this_window
)
2338 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
2339 return display_buffer_1 (selected_window
);
2341 /* See if the user has specified this buffer should appear
2342 in the selected window. */
2343 if (NILP (not_this_window
))
2345 tem
= Fsame_window_p (XBUFFER (buffer
)->name
);
2348 Fswitch_to_buffer (buffer
, Qnil
);
2349 return display_buffer_1 (selected_window
);
2353 /* If pop_up_frames,
2354 look for a window showing BUFFER on any visible or iconified frame.
2355 Otherwise search only the current frame. */
2358 else if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2359 XSETFASTINT (tem
, 0);
2361 XSETFRAME (tem
, last_nonminibuf_frame
);
2362 window
= Fget_buffer_window (buffer
, tem
);
2364 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
2366 return display_buffer_1 (window
);
2369 /* Certain buffer names get special handling. */
2370 if (!NILP (Vspecial_display_function
))
2372 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
2374 return call1 (Vspecial_display_function
, buffer
);
2376 return call2 (Vspecial_display_function
, buffer
, tem
);
2379 /* If there are no frames open that have more than a minibuffer,
2380 we need to create a new frame. */
2381 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2383 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2384 Fset_window_buffer (window
, buffer
);
2385 return display_buffer_1 (window
);
2389 || FRAME_MINIBUF_ONLY_P (selected_frame
)
2390 /* If the current frame is a special display frame,
2391 don't try to reuse its windows. */
2392 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (selected_frame
))->dedicated
)
2398 if (FRAME_MINIBUF_ONLY_P (selected_frame
))
2399 XSETFRAME (frames
, last_nonminibuf_frame
);
2400 /* Don't try to create a window if would get an error */
2401 if (split_height_threshold
< window_min_height
<< 1)
2402 split_height_threshold
= window_min_height
<< 1;
2404 /* Note that both Fget_largest_window and Fget_lru_window
2405 ignore minibuffers and dedicated windows.
2406 This means they can return nil. */
2408 /* If the frame we would try to split cannot be split,
2409 try other frames. */
2410 if (FRAME_NO_SPLIT_P (NILP (frames
) ? selected_frame
2411 : last_nonminibuf_frame
))
2413 /* Try visible frames first. */
2414 window
= Fget_largest_window (Qvisible
);
2415 /* If that didn't work, try iconified frames. */
2417 window
= Fget_largest_window (make_number (0));
2419 window
= Fget_largest_window (Qt
);
2422 window
= Fget_largest_window (frames
);
2424 /* If we got a tall enough full-width window that can be split,
2427 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2428 && window_height (window
) >= split_height_threshold
2429 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
2430 window
= Fsplit_window (window
, Qnil
, Qnil
);
2433 Lisp_Object upper
, lower
, other
;
2435 window
= Fget_lru_window (frames
);
2436 /* If the LRU window is selected, and big enough,
2437 and can be split, split it. */
2439 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2440 && (EQ (window
, selected_window
)
2441 || EQ (XWINDOW (window
)->parent
, Qnil
))
2442 && window_height (window
) >= window_min_height
<< 1)
2443 window
= Fsplit_window (window
, Qnil
, Qnil
);
2444 /* If Fget_lru_window returned nil, try other approaches. */
2446 /* Try visible frames first. */
2448 window
= Fget_buffer_window (buffer
, Qvisible
);
2450 window
= Fget_largest_window (Qvisible
);
2451 /* If that didn't work, try iconified frames. */
2453 window
= Fget_buffer_window (buffer
, make_number (0));
2455 window
= Fget_largest_window (make_number (0));
2456 /* Try invisible frames. */
2458 window
= Fget_buffer_window (buffer
, Qt
);
2460 window
= Fget_largest_window (Qt
);
2461 /* As a last resort, make a new frame. */
2463 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2464 /* If window appears above or below another,
2465 even out their heights. */
2466 other
= upper
= lower
= Qnil
;
2467 if (!NILP (XWINDOW (window
)->prev
))
2468 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
2469 if (!NILP (XWINDOW (window
)->next
))
2470 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
2472 /* Check that OTHER and WINDOW are vertically arrayed. */
2473 && !EQ (XWINDOW (other
)->top
, XWINDOW (window
)->top
)
2474 && (XFASTINT (XWINDOW (other
)->height
)
2475 > XFASTINT (XWINDOW (window
)->height
)))
2477 int total
= (XFASTINT (XWINDOW (other
)->height
)
2478 + XFASTINT (XWINDOW (window
)->height
));
2479 Lisp_Object old_selected_window
;
2480 old_selected_window
= selected_window
;
2482 selected_window
= upper
;
2483 change_window_height ((total
/ 2
2484 - XFASTINT (XWINDOW (upper
)->height
)),
2486 selected_window
= old_selected_window
;
2491 window
= Fget_lru_window (Qnil
);
2493 Fset_window_buffer (window
, buffer
);
2494 return display_buffer_1 (window
);
2498 temp_output_buffer_show (buf
)
2499 register Lisp_Object buf
;
2501 register struct buffer
*old
= current_buffer
;
2502 register Lisp_Object window
;
2503 register struct window
*w
;
2505 XBUFFER (buf
)->directory
= current_buffer
->directory
;
2508 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
2512 XBUFFER (buf
)->clip_changed
= 1;
2513 set_buffer_internal (old
);
2515 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
2516 call1 (Vtemp_buffer_show_function
, buf
);
2519 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
2521 if (XFRAME (XWINDOW (window
)->frame
) != selected_frame
)
2522 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
2523 Vminibuf_scroll_window
= window
;
2524 w
= XWINDOW (window
);
2525 XSETFASTINT (w
->hscroll
, 0);
2526 set_marker_restricted_both (w
->start
, buf
, 1, 1);
2527 set_marker_restricted_both (w
->pointm
, buf
, 1, 1);
2529 /* Run temp-buffer-show-hook, with the chosen window selected
2530 and it sbuffer current. */
2531 if (!NILP (Vrun_hooks
))
2534 tem
= Fboundp (Qtemp_buffer_show_hook
);
2537 tem
= Fsymbol_value (Qtemp_buffer_show_hook
);
2540 int count
= specpdl_ptr
- specpdl
;
2541 Lisp_Object prev_window
;
2542 prev_window
= selected_window
;
2544 /* Select the window that was chosen, for running the hook. */
2545 record_unwind_protect (Fselect_window
, prev_window
);
2546 select_window_1 (window
, 0);
2547 Fset_buffer (w
->buffer
);
2548 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
2549 select_window_1 (prev_window
, 0);
2550 unbind_to (count
, Qnil
);
2558 make_dummy_parent (window
)
2562 register struct window
*o
, *p
;
2563 register struct Lisp_Vector
*vec
;
2566 o
= XWINDOW (window
);
2567 vec
= allocate_vectorlike ((EMACS_INT
)VECSIZE (struct window
));
2568 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
2569 vec
->contents
[i
] = ((struct Lisp_Vector
*)o
)->contents
[i
];
2570 vec
->size
= VECSIZE (struct window
);
2571 p
= (struct window
*)vec
;
2572 XSETWINDOW (new, p
);
2574 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
2576 /* Put new into window structure in place of window */
2577 replace_window (window
, new);
2590 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
2591 "Split WINDOW, putting SIZE lines in the first of the pair.\n\
2592 WINDOW defaults to selected one and SIZE to half its size.\n\
2593 If optional third arg HORFLAG is non-nil, split side by side\n\
2594 and put SIZE columns in the first of the pair. In that case,\n\
2595 SIZE includes that window's scroll bar, or the divider column to its right.")
2596 (window
, size
, horflag
)
2597 Lisp_Object window
, size
, horflag
;
2599 register Lisp_Object
new;
2600 register struct window
*o
, *p
;
2602 register int size_int
;
2605 window
= selected_window
;
2607 CHECK_LIVE_WINDOW (window
, 0);
2609 o
= XWINDOW (window
);
2610 fo
= XFRAME (WINDOW_FRAME (o
));
2614 if (!NILP (horflag
))
2615 /* Calculate the size of the left-hand window, by dividing
2616 the usable space in columns by two.
2617 We round up, since the left-hand window may include
2618 a dividing line, while the right-hand may not. */
2619 size_int
= (XFASTINT (o
->width
) + 1) >> 1;
2621 size_int
= XFASTINT (o
->height
) >> 1;
2625 CHECK_NUMBER (size
, 1);
2626 size_int
= XINT (size
);
2629 if (MINI_WINDOW_P (o
))
2630 error ("Attempt to split minibuffer window");
2632 check_min_window_sizes ();
2636 if (size_int
< window_min_height
)
2637 error ("Window height %d too small (after splitting)", size_int
);
2638 if (size_int
+ window_min_height
> XFASTINT (o
->height
))
2639 error ("Window height %d too small (after splitting)",
2640 XFASTINT (o
->height
) - size_int
);
2641 if (NILP (o
->parent
)
2642 || NILP (XWINDOW (o
->parent
)->vchild
))
2644 make_dummy_parent (window
);
2646 XWINDOW (new)->vchild
= window
;
2651 if (size_int
< window_min_width
)
2652 error ("Window width %d too small (after splitting)", size_int
);
2654 if (size_int
+ window_min_width
> XFASTINT (o
->width
))
2655 error ("Window width %d too small (after splitting)",
2656 XFASTINT (o
->width
) - size_int
);
2657 if (NILP (o
->parent
)
2658 || NILP (XWINDOW (o
->parent
)->hchild
))
2660 make_dummy_parent (window
);
2662 XWINDOW (new)->hchild
= window
;
2666 /* Now we know that window's parent is a vertical combination
2667 if we are dividing vertically, or a horizontal combination
2668 if we are making side-by-side windows */
2670 windows_or_buffers_changed
++;
2671 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
2672 new = make_window ();
2675 p
->frame
= o
->frame
;
2677 if (!NILP (p
->next
))
2678 XWINDOW (p
->next
)->prev
= new;
2681 p
->parent
= o
->parent
;
2683 p
->window_end_valid
= Qnil
;
2684 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
2686 /* Apportion the available frame space among the two new windows */
2688 if (!NILP (horflag
))
2690 p
->height
= o
->height
;
2692 XSETFASTINT (p
->width
, XFASTINT (o
->width
) - size_int
);
2693 XSETFASTINT (o
->width
, size_int
);
2694 XSETFASTINT (p
->left
, XFASTINT (o
->left
) + size_int
);
2699 p
->width
= o
->width
;
2700 XSETFASTINT (p
->height
, XFASTINT (o
->height
) - size_int
);
2701 XSETFASTINT (o
->height
, size_int
);
2702 XSETFASTINT (p
->top
, XFASTINT (o
->top
) + size_int
);
2705 /* Adjust glyph matrices. */
2707 Fset_window_buffer (new, o
->buffer
);
2711 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
2712 "Make current window ARG lines bigger.\n\
2713 From program, optional second arg non-nil means grow sideways ARG columns.")
2715 register Lisp_Object arg
, side
;
2717 CHECK_NUMBER (arg
, 0);
2718 change_window_height (XINT (arg
), !NILP (side
));
2720 if (! NILP (Vwindow_configuration_change_hook
))
2721 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2726 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
2727 "Make current window ARG lines smaller.\n\
2728 From program, optional second arg non-nil means shrink sideways arg columns.")
2730 register Lisp_Object arg
, side
;
2732 CHECK_NUMBER (arg
, 0);
2733 change_window_height (-XINT (arg
), !NILP (side
));
2735 if (! NILP (Vwindow_configuration_change_hook
))
2736 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2742 window_height (window
)
2745 register struct window
*p
= XWINDOW (window
);
2746 return XFASTINT (p
->height
);
2750 window_width (window
)
2753 register struct window
*p
= XWINDOW (window
);
2754 return XFASTINT (p
->width
);
2757 #define MINSIZE(w) \
2759 ? window_min_width \
2760 : (MINI_WINDOW_P (XWINDOW (w)) ? 1 : window_min_height))
2763 *(widthflag ? (int *) &(XWINDOW (w)->left) : (int *) &(XWINDOW (w)->top))
2765 #define CURSIZE(w) \
2766 *(widthflag ? (int *) &(XWINDOW (w)->width) : (int *) &(XWINDOW (w)->height))
2768 /* Unlike set_window_height, this function
2769 also changes the heights of the siblings so as to
2770 keep everything consistent. */
2773 change_window_height (delta
, widthflag
)
2777 register Lisp_Object parent
;
2779 register struct window
*p
;
2781 int (*sizefun
) P_ ((Lisp_Object
))
2782 = widthflag
? window_width
: window_height
;
2783 register void (*setsizefun
) P_ ((Lisp_Object
, int, int))
2784 = (widthflag
? set_window_width
: set_window_height
);
2786 Lisp_Object next
, prev
;
2788 check_min_window_sizes ();
2790 window
= selected_window
;
2793 p
= XWINDOW (window
);
2798 error ("No other window to side of this one");
2801 if (widthflag
? !NILP (XWINDOW (parent
)->hchild
)
2802 : !NILP (XWINDOW (parent
)->vchild
))
2807 sizep
= &CURSIZE (window
);
2810 register int maxdelta
;
2812 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - *sizep
2813 : !NILP (p
->next
) ? (*sizefun
) (p
->next
) - MINSIZE (p
->next
)
2814 : !NILP (p
->prev
) ? (*sizefun
) (p
->prev
) - MINSIZE (p
->prev
)
2815 /* This is a frame with only one window, a minibuffer-only
2816 or a minibufferless frame. */
2819 if (delta
> maxdelta
)
2820 /* This case traps trying to make the minibuffer
2821 the full frame, or make the only window aside from the
2822 minibuffer the full frame. */
2826 if (*sizep
+ delta
< MINSIZE (window
))
2828 delete_window (window
);
2835 /* Find the total we can get from other siblings. */
2837 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
2838 maximum
+= (*sizefun
) (next
) - MINSIZE (next
);
2839 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
2840 maximum
+= (*sizefun
) (prev
) - MINSIZE (prev
);
2842 /* If we can get it all from them, do so. */
2843 if (delta
<= maximum
)
2845 Lisp_Object first_unaffected
;
2846 Lisp_Object first_affected
;
2850 first_affected
= window
;
2851 /* Look at one sibling at a time,
2852 moving away from this window in both directions alternately,
2853 and take as much as we can get without deleting that sibling. */
2860 int this_one
= (*sizefun
) (next
) - MINSIZE (next
);
2861 if (this_one
> delta
)
2864 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
2865 (*setsizefun
) (window
, *sizep
+ this_one
, 0);
2868 next
= XWINDOW (next
)->next
;
2874 int this_one
= (*sizefun
) (prev
) - MINSIZE (prev
);
2875 if (this_one
> delta
)
2878 first_affected
= prev
;
2880 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
2881 (*setsizefun
) (window
, *sizep
+ this_one
, 0);
2884 prev
= XWINDOW (prev
)->prev
;
2888 /* Now recalculate the edge positions of all the windows affected,
2889 based on the new sizes. */
2890 first_unaffected
= next
;
2891 prev
= first_affected
;
2892 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
2893 prev
= next
, next
= XWINDOW (next
)->next
)
2895 CURBEG (next
) = CURBEG (prev
) + (*sizefun
) (prev
);
2896 /* This does not change size of NEXT,
2897 but it propagates the new top edge to its children */
2898 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
2903 register int delta1
;
2904 register int opht
= (*sizefun
) (parent
);
2906 /* If trying to grow this window to or beyond size of the parent,
2907 make delta1 so big that, on shrinking back down,
2908 all the siblings end up with less than one line and are deleted. */
2909 if (opht
<= *sizep
+ delta
)
2910 delta1
= opht
* opht
* 2;
2911 /* Otherwise, make delta1 just right so that if we add delta1
2912 lines to this window and to the parent, and then shrink
2913 the parent back to its original size, the new proportional
2914 size of this window will increase by delta. */
2916 delta1
= (delta
* opht
* 100) / ((opht
- *sizep
- delta
) * 100);
2918 /* Add delta1 lines or columns to this window, and to the parent,
2919 keeping things consistent while not affecting siblings. */
2920 CURSIZE (parent
) = opht
+ delta1
;
2921 (*setsizefun
) (window
, *sizep
+ delta1
, 0);
2923 /* Squeeze out delta1 lines or columns from our parent,
2924 shriking this window and siblings proportionately.
2925 This brings parent back to correct size.
2926 Delta1 was calculated so this makes this window the desired size,
2927 taking it all out of the siblings. */
2928 (*setsizefun
) (parent
, opht
, 0);
2931 XSETFASTINT (p
->last_modified
, 0);
2932 XSETFASTINT (p
->last_overlay_modified
, 0);
2934 /* Adjust glyph matrices. */
2935 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
2942 /* Mark window cursors off for all windows in the window tree rooted
2943 at W by setting their phys_cursor_on_p flag to zero. Called from
2944 xterm.c, e.g. when a frame is cleared and thereby all cursors on
2945 the frame are cleared. */
2948 mark_window_cursors_off (w
)
2953 if (!NILP (w
->hchild
))
2954 mark_window_cursors_off (XWINDOW (w
->hchild
));
2955 else if (!NILP (w
->vchild
))
2956 mark_window_cursors_off (XWINDOW (w
->vchild
));
2958 w
->phys_cursor_on_p
= 0;
2960 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
2965 /* Return number of lines of text (not counting mode line) in W. */
2968 window_internal_height (w
)
2971 int ht
= XFASTINT (w
->height
);
2973 if (MINI_WINDOW_P (w
))
2976 if (!NILP (w
->parent
) || !NILP (w
->vchild
) || !NILP (w
->hchild
)
2977 || !NILP (w
->next
) || !NILP (w
->prev
)
2978 || FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (w
))))
2985 /* Return the number of columns in W.
2986 Don't count columns occupied by scroll bars or the vertical bar
2987 separating W from the sibling to its right. */
2990 window_internal_width (w
)
2993 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2994 int width
= XINT (w
->width
);
2996 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2997 /* Scroll bars occupy a few columns. */
2998 width
-= FRAME_SCROLL_BAR_COLS (f
);
2999 else if (!WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
3000 /* The column of `|' characters separating side-by-side windows
3001 occupies one column only. */
3004 /* On window-systems, areas to the left and right of the window
3005 are used to display bitmaps there. */
3006 if (FRAME_WINDOW_P (f
))
3007 width
-= 2 * FRAME_FLAGS_AREA_COLS (f
);
3013 /************************************************************************
3015 ***********************************************************************/
3017 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
3018 one screen-full, which is defined as the height of the window minus
3019 next_screen_context_lines. If WHOLE is zero, scroll up N lines
3020 instead. Negative values of N mean scroll down. NOERROR non-zero
3021 means don't signal an error if we try to move over BEGV or ZV,
3025 window_scroll (window
, n
, whole
, noerror
)
3031 /* If we must, use the pixel-based version which is much slower than
3032 the line-based one but can handle varying line heights. */
3033 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
3034 window_scroll_pixel_based (window
, n
, whole
, noerror
);
3036 window_scroll_line_based (window
, n
, whole
, noerror
);
3040 /* Implementation of window_scroll that works based on pixel line
3041 heights. See the comment of window_scroll for parameter
3045 window_scroll_pixel_based (window
, n
, whole
, noerror
)
3052 struct window
*w
= XWINDOW (window
);
3053 struct text_pos start
;
3055 int this_scroll_margin
;
3058 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
3060 /* If PT is not visible in WINDOW, move back one half of
3062 XSETFASTINT (tem
, PT
);
3063 tem
= Fpos_visible_in_window_p (tem
, window
);
3066 /* Move backward half the height of the window. Performance note:
3067 vmotion used here is about 10% faster, but would give wrong
3068 results for variable height lines. */
3069 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
3070 it
.current_y
= it
.last_visible_y
;
3071 move_it_vertically (&it
, -it
.last_visible_y
/ 2);
3073 /* The function move_iterator_vertically may move over more than
3074 the specified y-distance. If it->w is small, e.g. a
3075 mini-buffer window, we may end up in front of the window's
3076 display area. This is the case when Start displaying at the
3077 start of the line containing PT in this case. */
3078 if (it
.current_y
<= 0)
3080 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
3081 move_it_vertically (&it
, 0);
3085 start
= it
.current
.pos
;
3088 /* If scroll_preserve_screen_position is non-zero, we try to set
3089 point in the same window line as it is now, so get that line. */
3090 if (!NILP (Vscroll_preserve_screen_position
))
3092 start_display (&it
, w
, start
);
3093 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
3094 preserve_y
= it
.current_y
;
3099 /* Move iterator it from start the specified distance forward or
3100 backward. The result is the new window start. */
3101 start_display (&it
, w
, start
);
3104 int screen_full
= (it
.last_visible_y
3105 - next_screen_context_lines
* CANON_Y_UNIT (it
.f
));
3106 int direction
= n
< 0 ? -1 : 1;
3107 move_it_vertically (&it
, direction
* screen_full
);
3110 move_it_by_lines (&it
, n
, 1);
3112 /* End if we end up at ZV or BEGV. */
3113 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
3114 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
3118 else if (IT_CHARPOS (it
) == ZV
)
3119 Fsignal (Qend_of_buffer
, Qnil
);
3121 Fsignal (Qbeginning_of_buffer
, Qnil
);
3124 /* Set the window start, and set up the window for redisplay. */
3125 set_marker_restricted (w
->start
, make_number (IT_CHARPOS (it
)), w
->buffer
);
3126 w
->start_at_line_beg
= Fbolp ();
3127 w
->update_mode_line
= Qt
;
3128 XSETFASTINT (w
->last_modified
, 0);
3129 XSETFASTINT (w
->last_overlay_modified
, 0);
3130 /* Set force_start so that redisplay_window will run the
3131 window-scroll-functions. */
3132 w
->force_start
= Qt
;
3134 it
.current_y
= it
.vpos
= 0;
3136 /* Preserve the screen position if we must. */
3137 if (preserve_y
>= 0)
3139 move_it_to (&it
, -1, -1, preserve_y
, -1, MOVE_TO_Y
);
3140 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
3144 /* Move PT out of scroll margins. */
3145 this_scroll_margin
= max (0, scroll_margin
);
3146 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
3147 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
3151 /* We moved the window start towards ZV, so PT may be now
3152 in the scroll margin at the top. */
3153 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
3154 while (it
.current_y
< this_scroll_margin
)
3155 move_it_by_lines (&it
, 1, 1);
3156 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
3160 /* We moved the window start towards BEGV, so PT may be now
3161 in the scroll margin at the bottom. */
3162 move_it_to (&it
, PT
, -1,
3163 it
.last_visible_y
- this_scroll_margin
- 1, -1,
3164 MOVE_TO_POS
| MOVE_TO_Y
);
3166 /* Don't put point on a partially visible line at the end. */
3167 if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
3168 > it
.last_visible_y
)
3169 move_it_by_lines (&it
, -1, 0);
3171 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
3177 /* Implementation of window_scroll that works based on screen lines.
3178 See the comment of window_scroll for parameter descriptions. */
3181 window_scroll_line_based (window
, n
, whole
, noerror
)
3187 register struct window
*w
= XWINDOW (window
);
3188 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
3189 register int pos
, pos_byte
;
3190 register int ht
= window_internal_height (w
);
3191 register Lisp_Object tem
;
3195 struct position posit
;
3198 startpos
= marker_position (w
->start
);
3200 posit
= *compute_motion (startpos
, 0, 0, 0,
3202 window_internal_width (w
), XINT (w
->hscroll
),
3204 original_vpos
= posit
.vpos
;
3206 XSETFASTINT (tem
, PT
);
3207 tem
= Fpos_visible_in_window_p (tem
, window
);
3211 Fvertical_motion (make_number (- (ht
/ 2)), window
);
3216 lose
= n
< 0 && PT
== BEGV
;
3217 Fvertical_motion (make_number (n
), window
);
3221 SET_PT_BOTH (opoint
, opoint_byte
);
3228 Fsignal (Qbeginning_of_buffer
, Qnil
);
3233 int this_scroll_margin
= scroll_margin
;
3235 /* Don't use a scroll margin that is negative or too large. */
3236 if (this_scroll_margin
< 0)
3237 this_scroll_margin
= 0;
3239 if (XINT (w
->height
) < 4 * scroll_margin
)
3240 this_scroll_margin
= XINT (w
->height
) / 4;
3242 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
3243 w
->start_at_line_beg
= bolp
;
3244 w
->update_mode_line
= Qt
;
3245 XSETFASTINT (w
->last_modified
, 0);
3246 XSETFASTINT (w
->last_overlay_modified
, 0);
3247 /* Set force_start so that redisplay_window will run
3248 the window-scroll-functions. */
3249 w
->force_start
= Qt
;
3251 if (whole
&& !NILP (Vscroll_preserve_screen_position
))
3253 SET_PT_BOTH (pos
, pos_byte
);
3254 Fvertical_motion (make_number (original_vpos
), window
);
3256 /* If we scrolled forward, put point enough lines down
3257 that it is outside the scroll margin. */
3262 if (this_scroll_margin
> 0)
3264 SET_PT_BOTH (pos
, pos_byte
);
3265 Fvertical_motion (make_number (this_scroll_margin
), window
);
3271 if (top_margin
<= opoint
)
3272 SET_PT_BOTH (opoint
, opoint_byte
);
3273 else if (!NILP (Vscroll_preserve_screen_position
))
3275 SET_PT_BOTH (pos
, pos_byte
);
3276 Fvertical_motion (make_number (original_vpos
), window
);
3279 SET_PT (top_margin
);
3285 /* If we scrolled backward, put point near the end of the window
3286 but not within the scroll margin. */
3287 SET_PT_BOTH (pos
, pos_byte
);
3288 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
3289 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
3292 bottom_margin
= PT
+ 1;
3294 if (bottom_margin
> opoint
)
3295 SET_PT_BOTH (opoint
, opoint_byte
);
3298 if (!NILP (Vscroll_preserve_screen_position
))
3300 SET_PT_BOTH (pos
, pos_byte
);
3301 Fvertical_motion (make_number (original_vpos
), window
);
3304 Fvertical_motion (make_number (-1), window
);
3313 Fsignal (Qend_of_buffer
, Qnil
);
3318 /* Scroll selected_window up or down. If N is nil, scroll a
3319 screen-full which is defined as the height of the window minus
3320 next_screen_context_lines. If N is the symbol `-', scroll.
3321 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
3322 up. This is the guts of Fscroll_up and Fscroll_down. */
3325 scroll_command (n
, direction
)
3329 register int defalt
;
3330 int count
= specpdl_ptr
- specpdl
;
3332 xassert (abs (direction
) == 1);
3334 /* If selected window's buffer isn't current, make it current for
3335 the moment. But don't screw up if window_scroll gets an error. */
3336 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
3338 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
3339 Fset_buffer (XWINDOW (selected_window
)->buffer
);
3341 /* Make redisplay consider other windows than just selected_window. */
3342 ++windows_or_buffers_changed
;
3345 defalt
= (window_internal_height (XWINDOW (selected_window
))
3346 - next_screen_context_lines
);
3347 defalt
= direction
* (defalt
< 1 ? 1 : defalt
);
3350 window_scroll (selected_window
, defalt
, 1, 0);
3351 else if (EQ (n
, Qminus
))
3352 window_scroll (selected_window
, - defalt
, 1, 0);
3355 n
= Fprefix_numeric_value (n
);
3356 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
3359 unbind_to (count
, Qnil
);
3362 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
3363 "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\
3364 A near full screen is `next-screen-context-lines' less than a full screen.\n\
3365 Negative ARG means scroll downward.\n\
3366 If ARG is the atom `-', scroll downward by nearly full screen.\n\
3367 When calling from a program, supply as argument a number, nil, or `-'.")
3371 scroll_command (arg
, 1);
3375 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
3376 "Scroll text of current window down ARG lines; or near full screen if no ARG.\n\
3377 A near full screen is `next-screen-context-lines' less than a full screen.\n\
3378 Negative ARG means scroll upward.\n\
3379 If ARG is the atom `-', scroll upward by nearly full screen.\n\
3380 When calling from a program, supply as argument a number, nil, or `-'.")
3384 scroll_command (arg
, -1);
3388 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
3389 "Return the other window for \"other window scroll\" commands.\n\
3390 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
3391 specifies the window.\n\
3392 If `other-window-scroll-buffer' is non-nil, a window\n\
3393 showing that buffer is used.")
3398 if (MINI_WINDOW_P (XWINDOW (selected_window
))
3399 && !NILP (Vminibuf_scroll_window
))
3400 window
= Vminibuf_scroll_window
;
3401 /* If buffer is specified, scroll that buffer. */
3402 else if (!NILP (Vother_window_scroll_buffer
))
3404 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
3406 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
3410 /* Nothing specified; look for a neighboring window on the same
3412 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
3414 if (EQ (window
, selected_window
))
3415 /* That didn't get us anywhere; look for a window on another
3418 window
= Fnext_window (window
, Qnil
, Qt
);
3419 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
3420 && ! EQ (window
, selected_window
));
3423 CHECK_LIVE_WINDOW (window
, 0);
3425 if (EQ (window
, selected_window
))
3426 error ("There is no other window");
3431 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
3432 "Scroll next window upward ARG lines; or near full screen if no ARG.\n\
3433 A near full screen is `next-screen-context-lines' less than a full screen.\n\
3434 The next window is the one below the current one; or the one at the top\n\
3435 if the current one is at the bottom. Negative ARG means scroll downward.\n\
3436 If ARG is the atom `-', scroll downward by nearly full screen.\n\
3437 When calling from a program, supply as argument a number, nil, or `-'.\n\
3439 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
3440 specifies the window to scroll.\n\
3441 If `other-window-scroll-buffer' is non-nil, scroll the window\n\
3442 showing that buffer, popping the buffer up if necessary.")
3444 register Lisp_Object arg
;
3446 register Lisp_Object window
;
3447 register int defalt
;
3448 register struct window
*w
;
3449 register int count
= specpdl_ptr
- specpdl
;
3451 window
= Fother_window_for_scrolling ();
3453 w
= XWINDOW (window
);
3454 defalt
= window_internal_height (w
) - next_screen_context_lines
;
3455 if (defalt
< 1) defalt
= 1;
3457 /* Don't screw up if window_scroll gets an error. */
3458 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
3459 ++windows_or_buffers_changed
;
3461 Fset_buffer (w
->buffer
);
3462 SET_PT (marker_position (w
->pointm
));
3465 window_scroll (window
, defalt
, 1, 1);
3466 else if (EQ (arg
, Qminus
))
3467 window_scroll (window
, -defalt
, 1, 1);
3472 CHECK_NUMBER (arg
, 0);
3473 window_scroll (window
, XINT (arg
), 0, 1);
3476 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
3477 unbind_to (count
, Qnil
);
3482 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 1, "P",
3483 "Scroll selected window display ARG columns left.\n\
3484 Default for ARG is window width minus 2.")
3486 register Lisp_Object arg
;
3490 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
3492 arg
= Fprefix_numeric_value (arg
);
3495 Fset_window_hscroll (selected_window
,
3496 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
3500 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 1, "P",
3501 "Scroll selected window display ARG columns right.\n\
3502 Default for ARG is window width minus 2.")
3504 register Lisp_Object arg
;
3507 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
3509 arg
= Fprefix_numeric_value (arg
);
3512 Fset_window_hscroll (selected_window
,
3513 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
3517 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
3518 "Center point in window and redisplay frame. With ARG, put point on line ARG.\n\
3519 The desired position of point is always relative to the current window.\n\
3520 Just C-u as prefix means put point in the center of the window.\n\
3521 If ARG is omitted or nil, erases the entire frame and then\n\
3522 redraws with point in the center of the current window.")
3524 register Lisp_Object arg
;
3526 register struct window
*w
= XWINDOW (selected_window
);
3527 register int ht
= window_internal_height (w
);
3528 struct position pos
;
3529 struct buffer
*buf
= XBUFFER (w
->buffer
);
3530 struct buffer
*obuf
= current_buffer
;
3534 extern int frame_garbaged
;
3536 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
3537 XSETFASTINT (arg
, ht
/ 2);
3539 else if (CONSP (arg
)) /* Just C-u. */
3541 XSETFASTINT (arg
, ht
/ 2);
3545 arg
= Fprefix_numeric_value (arg
);
3546 CHECK_NUMBER (arg
, 0);
3550 XSETINT (arg
, XINT (arg
) + ht
);
3552 set_buffer_internal (buf
);
3553 pos
= *vmotion (PT
, - XINT (arg
), w
);
3555 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
3556 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
3557 || FETCH_BYTE (pos
.bytepos
- 1) == '\n')
3559 w
->force_start
= Qt
;
3560 set_buffer_internal (obuf
);
3565 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
3567 "Position point relative to window.\n\
3568 With no argument, position point at center of window.\n\
3569 An argument specifies vertical position within the window;\n\
3570 zero means top of window, negative means relative to bottom of window.")
3572 register Lisp_Object arg
;
3574 register struct window
*w
= XWINDOW (selected_window
);
3575 register int height
= window_internal_height (w
);
3580 XSETFASTINT (arg
, height
/ 2);
3583 arg
= Fprefix_numeric_value (arg
);
3585 XSETINT (arg
, XINT (arg
) + height
);
3588 start
= marker_position (w
->start
);
3589 XSETWINDOW (window
, w
);
3590 if (start
< BEGV
|| start
> ZV
)
3592 Fvertical_motion (make_number (- (height
/ 2)), window
);
3593 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
3594 w
->start_at_line_beg
= Fbolp ();
3595 w
->force_start
= Qt
;
3598 Fgoto_char (w
->start
);
3600 return Fvertical_motion (arg
, window
);
3605 /***********************************************************************
3606 Window Configuration
3607 ***********************************************************************/
3609 struct save_window_data
3611 EMACS_INT size_from_Lisp_Vector_struct
;
3612 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
3613 Lisp_Object frame_width
, frame_height
, frame_menu_bar_lines
;
3614 Lisp_Object frame_toolbar_lines
;
3615 Lisp_Object selected_frame
;
3616 Lisp_Object current_window
;
3617 Lisp_Object current_buffer
;
3618 Lisp_Object minibuf_scroll_window
;
3619 Lisp_Object root_window
;
3620 Lisp_Object focus_frame
;
3621 /* Record the values of window-min-width and window-min-height
3622 so that window sizes remain consistent with them. */
3623 Lisp_Object min_width
, min_height
;
3624 /* A vector, each of whose elements is a struct saved_window
3626 Lisp_Object saved_windows
;
3629 /* This is saved as a Lisp_Vector */
3632 /* these first two must agree with struct Lisp_Vector in lisp.h */
3633 EMACS_INT size_from_Lisp_Vector_struct
;
3634 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
3637 Lisp_Object buffer
, start
, pointm
, mark
;
3638 Lisp_Object left
, top
, width
, height
, hscroll
;
3639 Lisp_Object parent
, prev
;
3640 Lisp_Object start_at_line_beg
;
3641 Lisp_Object display_table
;
3643 #define SAVED_WINDOW_VECTOR_SIZE 14 /* Arg to Fmake_vector */
3645 #define SAVED_WINDOW_N(swv,n) \
3646 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
3648 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
3649 "Return t if OBJECT is a window-configuration object.")
3653 if (WINDOW_CONFIGURATIONP (object
))
3658 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
3659 "Return the frame that CONFIG, a window-configuration object, is about.")
3663 register struct save_window_data
*data
;
3664 struct Lisp_Vector
*saved_windows
;
3666 if (! WINDOW_CONFIGURATIONP (config
))
3667 wrong_type_argument (Qwindow_configuration_p
, config
);
3669 data
= (struct save_window_data
*) XVECTOR (config
);
3670 saved_windows
= XVECTOR (data
->saved_windows
);
3671 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
3674 DEFUN ("set-window-configuration", Fset_window_configuration
,
3675 Sset_window_configuration
, 1, 1, 0,
3676 "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\
3677 CONFIGURATION must be a value previously returned\n\
3678 by `current-window-configuration' (which see).\n\
3679 If CONFIGURATION was made from a frame that is now deleted,\n\
3680 only frame-independent values can be restored. In this case,\n\
3681 the return value is nil. Otherwise the value is t.")
3683 Lisp_Object configuration
;
3685 register struct save_window_data
*data
;
3686 struct Lisp_Vector
*saved_windows
;
3687 Lisp_Object new_current_buffer
;
3692 while (!WINDOW_CONFIGURATIONP (configuration
))
3693 wrong_type_argument (Qwindow_configuration_p
, configuration
);
3695 data
= (struct save_window_data
*) XVECTOR (configuration
);
3696 saved_windows
= XVECTOR (data
->saved_windows
);
3698 new_current_buffer
= data
->current_buffer
;
3699 if (NILP (XBUFFER (new_current_buffer
)->name
))
3700 new_current_buffer
= Qnil
;
3703 if (XBUFFER (new_current_buffer
) == current_buffer
)
3708 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
3711 /* If f is a dead frame, don't bother rebuilding its window tree.
3712 However, there is other stuff we should still try to do below. */
3713 if (FRAME_LIVE_P (f
))
3715 register struct window
*w
;
3716 register struct saved_window
*p
;
3717 struct window
*root_window
;
3718 struct window
**leaf_windows
;
3722 /* If the frame has been resized since this window configuration was
3723 made, we change the frame to the size specified in the
3724 configuration, restore the configuration, and then resize it
3725 back. We keep track of the prevailing height in these variables. */
3726 int previous_frame_height
= FRAME_HEIGHT (f
);
3727 int previous_frame_width
= FRAME_WIDTH (f
);
3728 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
3729 int previous_frame_toolbar_lines
= FRAME_TOOLBAR_LINES (f
);
3731 /* The mouse highlighting code could get screwed up
3732 if it runs during this. */
3735 if (XFASTINT (data
->frame_height
) != previous_frame_height
3736 || XFASTINT (data
->frame_width
) != previous_frame_width
)
3737 change_frame_size (f
, XFASTINT (data
->frame_height
),
3738 XFASTINT (data
->frame_width
), 0, 0);
3739 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
3740 if (XFASTINT (data
->frame_menu_bar_lines
)
3741 != previous_frame_menu_bar_lines
)
3742 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, make_number (0));
3743 if (XFASTINT (data
->frame_toolbar_lines
)
3744 != previous_frame_toolbar_lines
)
3745 x_set_toolbar_lines (f
, data
->frame_toolbar_lines
, make_number (0));
3748 if (! NILP (XWINDOW (selected_window
)->buffer
))
3750 w
= XWINDOW (selected_window
);
3751 set_marker_both (w
->pointm
,
3753 BUF_PT (XBUFFER (w
->buffer
)),
3754 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
3757 windows_or_buffers_changed
++;
3758 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3760 /* Problem: Freeing all matrices and later allocating them again
3761 is a serious redisplay flickering problem. What we would
3762 really like to do is to free only those matrices not reused
3764 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3766 = (struct window
**) alloca (count_windows (root_window
)
3767 * sizeof (struct window
*));
3768 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
3770 /* Temporarily avoid any problems with windows that are smaller
3771 than they are supposed to be. */
3772 window_min_height
= 1;
3773 window_min_width
= 1;
3776 Mark all windows now on frame as "deleted".
3777 Restoring the new configuration "undeletes" any that are in it.
3779 Save their current buffers in their height fields, since we may
3780 need it later, if a buffer saved in the configuration is now
3782 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3784 for (k
= 0; k
< saved_windows
->size
; k
++)
3786 p
= SAVED_WINDOW_N (saved_windows
, k
);
3787 w
= XWINDOW (p
->window
);
3790 if (!NILP (p
->parent
))
3791 w
->parent
= SAVED_WINDOW_N (saved_windows
,
3792 XFASTINT (p
->parent
))->window
;
3796 if (!NILP (p
->prev
))
3798 w
->prev
= SAVED_WINDOW_N (saved_windows
,
3799 XFASTINT (p
->prev
))->window
;
3800 XWINDOW (w
->prev
)->next
= p
->window
;
3805 if (!NILP (w
->parent
))
3807 if (EQ (p
->width
, XWINDOW (w
->parent
)->width
))
3809 XWINDOW (w
->parent
)->vchild
= p
->window
;
3810 XWINDOW (w
->parent
)->hchild
= Qnil
;
3814 XWINDOW (w
->parent
)->hchild
= p
->window
;
3815 XWINDOW (w
->parent
)->vchild
= Qnil
;
3820 /* If we squirreled away the buffer in the window's height,
3822 if (BUFFERP (w
->height
))
3823 w
->buffer
= w
->height
;
3826 w
->width
= p
->width
;
3827 w
->height
= p
->height
;
3828 w
->hscroll
= p
->hscroll
;
3829 w
->display_table
= p
->display_table
;
3830 XSETFASTINT (w
->last_modified
, 0);
3831 XSETFASTINT (w
->last_overlay_modified
, 0);
3833 /* Reinstall the saved buffer and pointers into it. */
3834 if (NILP (p
->buffer
))
3835 w
->buffer
= p
->buffer
;
3838 if (!NILP (XBUFFER (p
->buffer
)->name
))
3839 /* If saved buffer is alive, install it. */
3841 w
->buffer
= p
->buffer
;
3842 w
->start_at_line_beg
= p
->start_at_line_beg
;
3843 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
3844 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
3845 Fset_marker (XBUFFER (w
->buffer
)->mark
,
3846 p
->mark
, w
->buffer
);
3848 /* As documented in Fcurrent_window_configuration, don't
3849 save the location of point in the buffer which was current
3850 when the window configuration was recorded. */
3851 if (!EQ (p
->buffer
, new_current_buffer
)
3852 && XBUFFER (p
->buffer
) == current_buffer
)
3853 Fgoto_char (w
->pointm
);
3855 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
3856 /* Else unless window has a live buffer, get one. */
3858 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
3859 /* This will set the markers to beginning of visible
3861 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
3862 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
3863 w
->start_at_line_beg
= Qt
;
3866 /* Keeping window's old buffer; make sure the markers
3869 /* Set window markers at start of visible range. */
3870 if (XMARKER (w
->start
)->buffer
== 0)
3871 set_marker_restricted (w
->start
, make_number (0),
3873 if (XMARKER (w
->pointm
)->buffer
== 0)
3874 set_marker_restricted_both (w
->pointm
, w
->buffer
,
3875 BUF_PT (XBUFFER (w
->buffer
)),
3876 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
3877 w
->start_at_line_beg
= Qt
;
3882 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
3883 Fselect_window (data
->current_window
);
3884 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
3887 if (NILP (data
->focus_frame
)
3888 || (FRAMEP (data
->focus_frame
)
3889 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
3890 Fredirect_frame_focus (frame
, data
->focus_frame
);
3892 #if 0 /* I don't understand why this is needed, and it causes problems
3893 when the frame's old selected window has been deleted. */
3894 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
3895 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
3899 /* Set the screen height to the value it had before this function. */
3900 if (previous_frame_height
!= FRAME_HEIGHT (f
)
3901 || previous_frame_width
!= FRAME_WIDTH (f
))
3902 change_frame_size (f
, previous_frame_height
, previous_frame_width
,
3904 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
3905 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
3906 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
3908 if (previous_frame_toolbar_lines
!= FRAME_TOOLBAR_LINES (f
))
3909 x_set_toolbar_lines (f
, make_number (previous_frame_toolbar_lines
),
3913 /* Now, free glyph matrices in windows that were not reused. */
3914 for (i
= 0; i
< n_leaf_windows
; ++i
)
3915 if (NILP (leaf_windows
[i
]->buffer
))
3917 /* Assert it's not reused as a combination. */
3918 xassert (NILP (leaf_windows
[i
]->hchild
)
3919 && NILP (leaf_windows
[i
]->vchild
));
3920 free_window_matrices (leaf_windows
[i
]);
3921 SET_FRAME_GARBAGED (f
);
3928 /* Fselect_window will have made f the selected frame, so we
3929 reselect the proper frame here. Fhandle_switch_frame will change the
3930 selected window too, but that doesn't make the call to
3931 Fselect_window above totally superfluous; it still sets f's
3933 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
3934 do_switch_frame (data
->selected_frame
, Qnil
, 0);
3936 if (! NILP (Vwindow_configuration_change_hook
)
3937 && ! NILP (Vrun_hooks
))
3938 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3941 if (!NILP (new_current_buffer
))
3943 Fset_buffer (new_current_buffer
);
3945 /* If the buffer that is current now is the same
3946 that was current before setting the window configuration,
3947 don't alter its PT. */
3952 /* Restore the minimum heights recorded in the configuration. */
3953 window_min_height
= XINT (data
->min_height
);
3954 window_min_width
= XINT (data
->min_width
);
3956 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
3958 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
3961 /* Mark all windows now on frame as deleted
3962 by setting their buffers to nil. */
3965 delete_all_subwindows (w
)
3966 register struct window
*w
;
3968 if (!NILP (w
->next
))
3969 delete_all_subwindows (XWINDOW (w
->next
));
3970 if (!NILP (w
->vchild
))
3971 delete_all_subwindows (XWINDOW (w
->vchild
));
3972 if (!NILP (w
->hchild
))
3973 delete_all_subwindows (XWINDOW (w
->hchild
));
3975 w
->height
= w
->buffer
; /* See Fset_window_configuration for excuse. */
3977 if (!NILP (w
->buffer
))
3980 /* We set all three of these fields to nil, to make sure that we can
3981 distinguish this dead window from any live window. Live leaf
3982 windows will have buffer set, and combination windows will have
3983 vchild or hchild set. */
3990 count_windows (window
)
3991 register struct window
*window
;
3993 register int count
= 1;
3994 if (!NILP (window
->next
))
3995 count
+= count_windows (XWINDOW (window
->next
));
3996 if (!NILP (window
->vchild
))
3997 count
+= count_windows (XWINDOW (window
->vchild
));
3998 if (!NILP (window
->hchild
))
3999 count
+= count_windows (XWINDOW (window
->hchild
));
4004 /* Fill vector FLAT with leaf windows under W, starting at index I.
4005 Value is last index + 1. */
4008 get_leaf_windows (w
, flat
, i
)
4010 struct window
**flat
;
4015 if (!NILP (w
->hchild
))
4016 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
4017 else if (!NILP (w
->vchild
))
4018 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
4022 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4029 /* Return a pointer to the glyph W's physical cursor is on. Value is
4030 null if W's current matrix is invalid, so that no meaningfull glyph
4034 get_phys_cursor_glyph (w
)
4037 struct glyph_row
*row
;
4038 struct glyph
*glyph
;
4040 if (w
->phys_cursor
.vpos
>= 0
4041 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
4042 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
4044 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
4045 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
4054 save_window_save (window
, vector
, i
)
4056 struct Lisp_Vector
*vector
;
4059 register struct saved_window
*p
;
4060 register struct window
*w
;
4061 register Lisp_Object tem
;
4063 for (;!NILP (window
); window
= w
->next
)
4065 p
= SAVED_WINDOW_N (vector
, i
);
4066 w
= XWINDOW (window
);
4068 XSETFASTINT (w
->temslot
, i
++);
4070 p
->buffer
= w
->buffer
;
4073 p
->width
= w
->width
;
4074 p
->height
= w
->height
;
4075 p
->hscroll
= w
->hscroll
;
4076 p
->display_table
= w
->display_table
;
4077 if (!NILP (w
->buffer
))
4079 /* Save w's value of point in the window configuration.
4080 If w is the selected window, then get the value of point
4081 from the buffer; pointm is garbage in the selected window. */
4082 if (EQ (window
, selected_window
))
4084 p
->pointm
= Fmake_marker ();
4085 set_marker_both (p
->pointm
, w
->buffer
,
4086 BUF_PT (XBUFFER (w
->buffer
)),
4087 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
4090 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
4092 p
->start
= Fcopy_marker (w
->start
, Qnil
);
4093 p
->start_at_line_beg
= w
->start_at_line_beg
;
4095 tem
= XBUFFER (w
->buffer
)->mark
;
4096 p
->mark
= Fcopy_marker (tem
, Qnil
);
4103 p
->start_at_line_beg
= Qnil
;
4106 if (NILP (w
->parent
))
4109 p
->parent
= XWINDOW (w
->parent
)->temslot
;
4114 p
->prev
= XWINDOW (w
->prev
)->temslot
;
4116 if (!NILP (w
->vchild
))
4117 i
= save_window_save (w
->vchild
, vector
, i
);
4118 if (!NILP (w
->hchild
))
4119 i
= save_window_save (w
->hchild
, vector
, i
);
4125 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
4126 Scurrent_window_configuration
, 0, 1, 0,
4127 "Return an object representing the current window configuration of FRAME.\n\
4128 If FRAME is nil or omitted, use the selected frame.\n\
4129 This describes the number of windows, their sizes and current buffers,\n\
4130 and for each displayed buffer, where display starts, and the positions of\n\
4131 point and mark. An exception is made for point in the current buffer:\n\
4132 its value is -not- saved.\n\
4133 This also records the currently selected frame, and FRAME's focus\n\
4134 redirection (see `redirect-frame-focus').")
4138 register Lisp_Object tem
;
4139 register int n_windows
;
4140 register struct save_window_data
*data
;
4141 register struct Lisp_Vector
*vec
;
4149 CHECK_LIVE_FRAME (frame
, 0);
4153 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4154 vec
= allocate_vectorlike (VECSIZE (struct save_window_data
));
4155 for (i
= 0; i
< VECSIZE (struct save_window_data
); i
++)
4156 vec
->contents
[i
] = Qnil
;
4157 vec
->size
= VECSIZE (struct save_window_data
);
4158 data
= (struct save_window_data
*)vec
;
4160 XSETFASTINT (data
->frame_width
, FRAME_WIDTH (f
));
4161 XSETFASTINT (data
->frame_height
, FRAME_HEIGHT (f
));
4162 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
4163 XSETFASTINT (data
->frame_toolbar_lines
, FRAME_TOOLBAR_LINES (f
));
4164 XSETFRAME (data
->selected_frame
, selected_frame
);
4165 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
4166 XSETBUFFER (data
->current_buffer
, current_buffer
);
4167 data
->minibuf_scroll_window
= Vminibuf_scroll_window
;
4168 data
->root_window
= FRAME_ROOT_WINDOW (f
);
4169 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
4170 XSETINT (data
->min_height
, window_min_height
);
4171 XSETINT (data
->min_width
, window_min_width
);
4172 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
4173 data
->saved_windows
= tem
;
4174 for (i
= 0; i
< n_windows
; i
++)
4175 XVECTOR (tem
)->contents
[i
]
4176 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
4177 save_window_save (FRAME_ROOT_WINDOW (f
),
4179 XSETWINDOW_CONFIGURATION (tem
, data
);
4183 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
4185 "Execute body, preserving window sizes and contents.\n\
4186 Restore which buffer appears in which window, where display starts,\n\
4187 and the value of point and mark for each window.\n\
4188 Also restore which buffer is current.\n\
4189 But do not preserve point in the current buffer.\n\
4190 Does not restore the value of point in current buffer.")
4194 register Lisp_Object val
;
4195 register int count
= specpdl_ptr
- specpdl
;
4197 record_unwind_protect (Fset_window_configuration
,
4198 Fcurrent_window_configuration (Qnil
));
4199 val
= Fprogn (args
);
4200 return unbind_to (count
, val
);
4204 /***********************************************************************
4206 ***********************************************************************/
4208 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
4210 "Set width of marginal areas of window WINDOW.\n\
4211 If window is nil or omitted, set margins of the currently selected window.\n\
4212 First parameter LEFT-WIDTH specifies the number of character\n\
4213 cells to reserve for the left marginal area. Second parameter\n\
4214 RIGHT-WIDTH does the same for the right marginal area.\n\
4215 A nil width parameter means no margin.")
4216 (left
, right
, window
)
4217 Lisp_Object window
, left
, right
;
4219 struct window
*w
= decode_window (window
);
4220 struct frame
*f
= XFRAME (w
->frame
);
4223 CHECK_NUMBER_OR_FLOAT (left
, 0);
4225 CHECK_NUMBER_OR_FLOAT (right
, 0);
4227 /* Check widths < 0 and translate a zero width to nil.
4228 Margins that are too wide have to be checked elsewhere. */
4229 if ((INTEGERP (left
) && XINT (left
) < 0)
4230 || (FLOATP (left
) && XFLOAT (left
)->data
<= 0))
4231 XSETFASTINT (left
, 0);
4232 if (INTEGERP (left
) && XFASTINT (left
) == 0)
4235 if ((INTEGERP (right
) && XINT (right
) < 0)
4236 || (FLOATP (right
) && XFLOAT (right
)->data
<= 0))
4237 XSETFASTINT (right
, 0);
4238 if (INTEGERP (right
) && XFASTINT (right
) == 0)
4241 w
->left_margin_width
= left
;
4242 w
->right_margin_width
= right
;
4244 ++windows_or_buffers_changed
;
4245 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
4250 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
4252 "Get width of marginal areas of window WINDOW.\n\
4253 If WINDOW is omitted or nil, use the currently selected window.\n\
4254 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).\n\
4255 If a marginal area does not exist, its width will be returned\n\
4260 struct window
*w
= decode_window (window
);
4261 return Fcons (w
->left_margin_width
, w
->right_margin_width
);
4266 /***********************************************************************
4268 ***********************************************************************/
4270 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 1, 0,
4271 "Return the amount by which WINDOW is scrolled vertically.\n\
4272 Use the selected window if WINDOW is nil or omitted.\n\
4273 Value is a multiple of the canonical character height of WINDOW.")
4281 window
= selected_window
;
4282 w
= XWINDOW (window
);
4283 f
= XFRAME (w
->frame
);
4285 if (FRAME_WINDOW_P (f
))
4286 return CANON_Y_FROM_PIXEL_Y (f
, w
->vscroll
);
4288 return make_number (0);
4292 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
4294 "Set amount by WINDOW should be scrolled vertically to VSCROLL.\n\
4295 WINDOW nil or omitted means use the selected window. VSCROLL is a\n\
4296 multiple of the canonical character height of WINDOW.")
4298 Lisp_Object vscroll
, window
;
4303 CHECK_NUMBER_OR_FLOAT (vscroll
, 0);
4306 window
= selected_window
;
4307 w
= XWINDOW (window
);
4308 f
= XFRAME (w
->frame
);
4310 if (FRAME_WINDOW_P (f
))
4312 int old_dy
= w
->vscroll
;
4313 w
->vscroll
= min (0, CANON_Y_UNIT (f
) * XFLOATINT (vscroll
));
4315 /* Adjust glyph matrix of the frame if the virtual display
4316 area becomes larger than before. */
4317 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
4320 /* Prevent redisplay shortcuts. */
4321 XBUFFER (w
->buffer
)->clip_changed
= 1;
4329 /***********************************************************************
4331 ***********************************************************************/
4333 /* Return 1 if window configurations C1 and C2
4334 describe the same state of affairs. This is used by Fequal. */
4337 compare_window_configurations (c1
, c2
, ignore_positions
)
4339 int ignore_positions
;
4341 register struct save_window_data
*d1
, *d2
;
4342 struct Lisp_Vector
*sw1
, *sw2
;
4345 d1
= (struct save_window_data
*) XVECTOR (c1
);
4346 d2
= (struct save_window_data
*) XVECTOR (c2
);
4347 sw1
= XVECTOR (d1
->saved_windows
);
4348 sw2
= XVECTOR (d2
->saved_windows
);
4350 if (! EQ (d1
->frame_width
, d2
->frame_width
))
4352 if (! EQ (d1
->frame_height
, d2
->frame_height
))
4354 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
4356 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
4358 /* Don't compare the current_window field directly.
4359 Instead see w1_is_current and w2_is_current, below. */
4360 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
4362 if (! ignore_positions
)
4363 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
4365 /* Don't compare the root_window field.
4366 We don't require the two configurations
4367 to use the same window object,
4368 and the two root windows must be equivalent
4369 if everything else compares equal. */
4370 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
4372 if (! EQ (d1
->min_width
, d2
->min_width
))
4374 if (! EQ (d1
->min_height
, d2
->min_height
))
4377 /* Verify that the two confis have the same number of windows. */
4378 if (sw1
->size
!= sw2
->size
)
4381 for (i
= 0; i
< sw1
->size
; i
++)
4383 struct saved_window
*p1
, *p2
;
4384 int w1_is_current
, w2_is_current
;
4386 p1
= SAVED_WINDOW_N (sw1
, i
);
4387 p2
= SAVED_WINDOW_N (sw2
, i
);
4389 /* Verify that the current windows in the two
4390 configurations correspond to each other. */
4391 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
4392 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
4394 if (w1_is_current
!= w2_is_current
)
4397 /* Verify that the corresponding windows do match. */
4398 if (! EQ (p1
->buffer
, p2
->buffer
))
4400 if (! EQ (p1
->left
, p2
->left
))
4402 if (! EQ (p1
->top
, p2
->top
))
4404 if (! EQ (p1
->width
, p2
->width
))
4406 if (! EQ (p1
->height
, p2
->height
))
4408 if (! EQ (p1
->display_table
, p2
->display_table
))
4410 if (! EQ (p1
->parent
, p2
->parent
))
4412 if (! EQ (p1
->prev
, p2
->prev
))
4414 if (! ignore_positions
)
4416 if (! EQ (p1
->hscroll
, p2
->hscroll
))
4418 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
4420 if (NILP (Fequal (p1
->start
, p2
->start
)))
4422 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
4424 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
4432 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
4433 Scompare_window_configurations
, 2, 2, 0,
4434 "Compare two window configurations as regards the structure of windows.\n\
4435 This function ignores details such as the values of point and mark\n\
4436 and scrolling positions.")
4440 if (compare_window_configurations (x
, y
, 1))
4448 selected_frame
= make_terminal_frame ();
4449 XSETFRAME (Vterminal_frame
, selected_frame
);
4450 minibuf_window
= selected_frame
->minibuffer_window
;
4451 selected_window
= selected_frame
->selected_window
;
4452 last_nonminibuf_frame
= selected_frame
;
4454 window_initialized
= 1;
4460 staticpro (&Qwindow_configuration_change_hook
);
4461 Qwindow_configuration_change_hook
4462 = intern ("window-configuration-change-hook");
4464 Qwindowp
= intern ("windowp");
4465 staticpro (&Qwindowp
);
4467 Qwindow_configuration_p
= intern ("window-configuration-p");
4468 staticpro (&Qwindow_configuration_p
);
4470 Qwindow_live_p
= intern ("window-live-p");
4471 staticpro (&Qwindow_live_p
);
4473 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
4474 staticpro (&Qtemp_buffer_show_hook
);
4476 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
4477 "Non-nil means call as function to display a help buffer.\n\
4478 The function is called with one argument, the buffer to be displayed.\n\
4479 Used by `with-output-to-temp-buffer'.\n\
4480 If this function is used, then it must do the entire job of showing\n\
4481 the buffer; `temp-buffer-show-hook' is not run unless this function runs it.");
4482 Vtemp_buffer_show_function
= Qnil
;
4484 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
4485 "If non-nil, function to call to handle `display-buffer'.\n\
4486 It will receive two args, the buffer and a flag which if non-nil means\n\
4487 that the currently selected window is not acceptable.\n\
4488 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\
4489 work using this function.");
4490 Vdisplay_buffer_function
= Qnil
;
4492 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
4493 "Non-nil means it is the window that C-M-v in minibuffer should scroll.");
4494 Vminibuf_scroll_window
= Qnil
;
4496 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
4497 "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.");
4498 Vother_window_scroll_buffer
= Qnil
;
4500 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
4501 "*Non-nil means `display-buffer' should make a separate frame.");
4504 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
4505 "Function to call to handle automatic new frame creation.\n\
4506 It is called with no arguments and should return a newly created frame.\n\
4508 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\
4509 where `pop-up-frame-alist' would hold the default frame parameters.");
4510 Vpop_up_frame_function
= Qnil
;
4512 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
4513 "*List of buffer names that should have their own special frames.\n\
4514 Displaying a buffer whose name is in this list makes a special frame for it\n\
4515 using `special-display-function'. See also `special-display-regexps'.\n\
4517 An element of the list can be a list instead of just a string.\n\
4518 There are two ways to use a list as an element:\n\
4519 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)\n\
4520 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
4521 In the latter case, FUNCTION is called with BUFFER as the first argument,\n\
4522 followed by OTHER-ARGS--it can display BUFFER in any way it likes.\n\
4523 All this is done by the function found in `special-display-function'.\n\
4525 If this variable appears \"not to work\", because you add a name to it\n\
4526 but that buffer still appears in the selected window, look at the\n\
4527 values of `same-window-buffer-names' and `same-window-regexps'.\n\
4528 Those variables take precedence over this one.");
4529 Vspecial_display_buffer_names
= Qnil
;
4531 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
4532 "*List of regexps saying which buffers should have their own special frames.\n\
4533 If a buffer name matches one of these regexps, it gets its own frame.\n\
4534 Displaying a buffer whose name is in this list makes a special frame for it\n\
4535 using `special-display-function'.\n\
4537 An element of the list can be a list instead of just a string.\n\
4538 There are two ways to use a list as an element:\n\
4539 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)\n\
4540 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
4541 In the latter case, FUNCTION is called with the buffer as first argument,\n\
4542 followed by OTHER-ARGS--it can display the buffer in any way it likes.\n\
4543 All this is done by the function found in `special-display-function'.\n\
4545 If this variable appears \"not to work\", because you add a regexp to it\n\
4546 but the matching buffers still appear in the selected window, look at the\n\
4547 values of `same-window-buffer-names' and `same-window-regexps'.\n\
4548 Those variables take precedence over this one.");
4549 Vspecial_display_regexps
= Qnil
;
4551 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
4552 "Function to call to make a new frame for a special buffer.\n\
4553 It is called with two arguments, the buffer and optional buffer specific\n\
4554 data, and should return a window displaying that buffer.\n\
4555 The default value makes a separate frame for the buffer,\n\
4556 using `special-display-frame-alist' to specify the frame parameters.\n\
4558 A buffer is special if its is listed in `special-display-buffer-names'\n\
4559 or matches a regexp in `special-display-regexps'.");
4560 Vspecial_display_function
= Qnil
;
4562 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
4563 "*List of buffer names that should appear in the selected window.\n\
4564 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'\n\
4565 switches to it in the selected window, rather than making it appear\n\
4566 in some other window.\n\
4568 An element of the list can be a cons cell instead of just a string.\n\
4569 Then the car must be a string, which specifies the buffer name.\n\
4570 This is for compatibility with `special-display-buffer-names';\n\
4571 the cdr of the cons cell is ignored.\n\
4573 See also `same-window-regexps'.");
4574 Vsame_window_buffer_names
= Qnil
;
4576 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
4577 "*List of regexps saying which buffers should appear in the selected window.\n\
4578 If a buffer name matches one of these regexps, then displaying it\n\
4579 using `display-buffer' or `pop-to-buffer' switches to it\n\
4580 in the selected window, rather than making it appear in some other window.\n\
4582 An element of the list can be a cons cell instead of just a string.\n\
4583 Then the car must be a string, which specifies the buffer name.\n\
4584 This is for compatibility with `special-display-buffer-names';\n\
4585 the cdr of the cons cell is ignored.\n\
4587 See also `same-window-buffer-names'.");
4588 Vsame_window_regexps
= Qnil
;
4590 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
4591 "*Non-nil means display-buffer should make new windows.");
4594 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
4595 "*Number of lines of continuity when scrolling by screenfuls.");
4596 next_screen_context_lines
= 2;
4598 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
4599 "*display-buffer would prefer to split the largest window if this large.\n\
4600 If there is only one window, it is split regardless of this value.");
4601 split_height_threshold
= 500;
4603 DEFVAR_INT ("window-min-height", &window_min_height
,
4604 "*Delete any window less than this tall (including its mode line).");
4605 window_min_height
= 4;
4607 DEFVAR_INT ("window-min-width", &window_min_width
,
4608 "*Delete any window less than this wide.");
4609 window_min_width
= 10;
4611 DEFVAR_LISP ("scroll-preserve-screen-position",
4612 &Vscroll_preserve_screen_position
,
4613 "*Nonzero means scroll commands move point to keep its screen line unchanged.");
4614 Vscroll_preserve_screen_position
= Qnil
;
4616 DEFVAR_LISP ("window-configuration-change-hook",
4617 &Vwindow_configuration_change_hook
,
4618 "Functions to call when window configuration changes.\n\
4619 The selected frame is the one whose configuration has changed.");
4620 Vwindow_configuration_change_hook
= Qnil
;
4622 defsubr (&Sselected_window
);
4623 defsubr (&Sminibuffer_window
);
4624 defsubr (&Swindow_minibuffer_p
);
4625 defsubr (&Swindowp
);
4626 defsubr (&Swindow_live_p
);
4627 defsubr (&Spos_visible_in_window_p
);
4628 defsubr (&Swindow_buffer
);
4629 defsubr (&Swindow_height
);
4630 defsubr (&Swindow_width
);
4631 defsubr (&Swindow_hscroll
);
4632 defsubr (&Sset_window_hscroll
);
4633 defsubr (&Swindow_redisplay_end_trigger
);
4634 defsubr (&Sset_window_redisplay_end_trigger
);
4635 defsubr (&Swindow_edges
);
4636 defsubr (&Scoordinates_in_window_p
);
4637 defsubr (&Swindow_at
);
4638 defsubr (&Swindow_point
);
4639 defsubr (&Swindow_start
);
4640 defsubr (&Swindow_end
);
4641 defsubr (&Sset_window_point
);
4642 defsubr (&Sset_window_start
);
4643 defsubr (&Swindow_dedicated_p
);
4644 defsubr (&Sset_window_dedicated_p
);
4645 defsubr (&Swindow_display_table
);
4646 defsubr (&Sset_window_display_table
);
4647 defsubr (&Snext_window
);
4648 defsubr (&Sprevious_window
);
4649 defsubr (&Sother_window
);
4650 defsubr (&Sget_lru_window
);
4651 defsubr (&Sget_largest_window
);
4652 defsubr (&Sget_buffer_window
);
4653 defsubr (&Sdelete_other_windows
);
4654 defsubr (&Sdelete_windows_on
);
4655 defsubr (&Sreplace_buffer_in_windows
);
4656 defsubr (&Sdelete_window
);
4657 defsubr (&Sset_window_buffer
);
4658 defsubr (&Sselect_window
);
4659 defsubr (&Sspecial_display_p
);
4660 defsubr (&Ssame_window_p
);
4661 defsubr (&Sdisplay_buffer
);
4662 defsubr (&Ssplit_window
);
4663 defsubr (&Senlarge_window
);
4664 defsubr (&Sshrink_window
);
4665 defsubr (&Sscroll_up
);
4666 defsubr (&Sscroll_down
);
4667 defsubr (&Sscroll_left
);
4668 defsubr (&Sscroll_right
);
4669 defsubr (&Sother_window_for_scrolling
);
4670 defsubr (&Sscroll_other_window
);
4671 defsubr (&Srecenter
);
4672 defsubr (&Smove_to_window_line
);
4673 defsubr (&Swindow_configuration_p
);
4674 defsubr (&Swindow_configuration_frame
);
4675 defsubr (&Sset_window_configuration
);
4676 defsubr (&Scurrent_window_configuration
);
4677 defsubr (&Ssave_window_excursion
);
4678 defsubr (&Sset_window_margins
);
4679 defsubr (&Swindow_margins
);
4680 defsubr (&Swindow_vscroll
);
4681 defsubr (&Sset_window_vscroll
);
4682 defsubr (&Scompare_window_configurations
);
4688 initial_define_key (control_x_map
, '1', "delete-other-windows");
4689 initial_define_key (control_x_map
, '2', "split-window");
4690 initial_define_key (control_x_map
, '0', "delete-window");
4691 initial_define_key (control_x_map
, 'o', "other-window");
4692 initial_define_key (control_x_map
, '^', "enlarge-window");
4693 initial_define_key (control_x_map
, '<', "scroll-left");
4694 initial_define_key (control_x_map
, '>', "scroll-right");
4696 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
4697 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
4698 initial_define_key (meta_map
, 'v', "scroll-down");
4700 initial_define_key (global_map
, Ctl('L'), "recenter");
4701 initial_define_key (meta_map
, 'r', "move-to-window-line");