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
, swp
;
2332 buffer
= Fget_buffer (buffer
);
2333 CHECK_BUFFER (buffer
, 0);
2335 if (!NILP (Vdisplay_buffer_function
))
2336 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
2338 if (NILP (not_this_window
)
2339 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
2340 return display_buffer_1 (selected_window
);
2342 /* See if the user has specified this buffer should appear
2343 in the selected window. */
2344 if (NILP (not_this_window
))
2346 swp
= Fsame_window_p (XBUFFER (buffer
)->name
);
2347 if (!NILP (swp
) && !no_switch_window (selected_window
))
2349 Fswitch_to_buffer (buffer
, Qnil
);
2350 return display_buffer_1 (selected_window
);
2354 /* If pop_up_frames,
2355 look for a window showing BUFFER on any visible or iconified frame.
2356 Otherwise search only the current frame. */
2359 else if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2360 XSETFASTINT (tem
, 0);
2362 XSETFRAME (tem
, last_nonminibuf_frame
);
2363 window
= Fget_buffer_window (buffer
, tem
);
2365 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
2367 return display_buffer_1 (window
);
2370 /* Certain buffer names get special handling. */
2371 if (!NILP (Vspecial_display_function
) && NILP (swp
))
2373 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
2375 return call1 (Vspecial_display_function
, buffer
);
2377 return call2 (Vspecial_display_function
, buffer
, tem
);
2380 /* If there are no frames open that have more than a minibuffer,
2381 we need to create a new frame. */
2382 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2384 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2385 Fset_window_buffer (window
, buffer
);
2386 return display_buffer_1 (window
);
2390 || FRAME_MINIBUF_ONLY_P (selected_frame
)
2391 /* If the current frame is a special display frame,
2392 don't try to reuse its windows. */
2393 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (selected_frame
))->dedicated
)
2399 if (FRAME_MINIBUF_ONLY_P (selected_frame
))
2400 XSETFRAME (frames
, last_nonminibuf_frame
);
2401 /* Don't try to create a window if would get an error */
2402 if (split_height_threshold
< window_min_height
<< 1)
2403 split_height_threshold
= window_min_height
<< 1;
2405 /* Note that both Fget_largest_window and Fget_lru_window
2406 ignore minibuffers and dedicated windows.
2407 This means they can return nil. */
2409 /* If the frame we would try to split cannot be split,
2410 try other frames. */
2411 if (FRAME_NO_SPLIT_P (NILP (frames
) ? selected_frame
2412 : last_nonminibuf_frame
))
2414 /* Try visible frames first. */
2415 window
= Fget_largest_window (Qvisible
);
2416 /* If that didn't work, try iconified frames. */
2418 window
= Fget_largest_window (make_number (0));
2420 window
= Fget_largest_window (Qt
);
2423 window
= Fget_largest_window (frames
);
2425 /* If we got a tall enough full-width window that can be split,
2428 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2429 && window_height (window
) >= split_height_threshold
2430 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
2431 window
= Fsplit_window (window
, Qnil
, Qnil
);
2434 Lisp_Object upper
, lower
, other
;
2436 window
= Fget_lru_window (frames
);
2437 /* If the LRU window is selected, and big enough,
2438 and can be split, split it. */
2440 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2441 && (EQ (window
, selected_window
)
2442 || EQ (XWINDOW (window
)->parent
, Qnil
))
2443 && window_height (window
) >= window_min_height
<< 1)
2444 window
= Fsplit_window (window
, Qnil
, Qnil
);
2445 /* If Fget_lru_window returned nil, try other approaches. */
2447 /* Try visible frames first. */
2449 window
= Fget_buffer_window (buffer
, Qvisible
);
2451 window
= Fget_largest_window (Qvisible
);
2452 /* If that didn't work, try iconified frames. */
2454 window
= Fget_buffer_window (buffer
, make_number (0));
2456 window
= Fget_largest_window (make_number (0));
2457 /* Try invisible frames. */
2459 window
= Fget_buffer_window (buffer
, Qt
);
2461 window
= Fget_largest_window (Qt
);
2462 /* As a last resort, make a new frame. */
2464 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2465 /* If window appears above or below another,
2466 even out their heights. */
2467 other
= upper
= lower
= Qnil
;
2468 if (!NILP (XWINDOW (window
)->prev
))
2469 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
2470 if (!NILP (XWINDOW (window
)->next
))
2471 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
2473 /* Check that OTHER and WINDOW are vertically arrayed. */
2474 && !EQ (XWINDOW (other
)->top
, XWINDOW (window
)->top
)
2475 && (XFASTINT (XWINDOW (other
)->height
)
2476 > XFASTINT (XWINDOW (window
)->height
)))
2478 int total
= (XFASTINT (XWINDOW (other
)->height
)
2479 + XFASTINT (XWINDOW (window
)->height
));
2480 Lisp_Object old_selected_window
;
2481 old_selected_window
= selected_window
;
2483 selected_window
= upper
;
2484 change_window_height ((total
/ 2
2485 - XFASTINT (XWINDOW (upper
)->height
)),
2487 selected_window
= old_selected_window
;
2492 window
= Fget_lru_window (Qnil
);
2494 Fset_window_buffer (window
, buffer
);
2495 return display_buffer_1 (window
);
2499 temp_output_buffer_show (buf
)
2500 register Lisp_Object buf
;
2502 register struct buffer
*old
= current_buffer
;
2503 register Lisp_Object window
;
2504 register struct window
*w
;
2506 XBUFFER (buf
)->directory
= current_buffer
->directory
;
2509 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
2513 XBUFFER (buf
)->clip_changed
= 1;
2514 set_buffer_internal (old
);
2516 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
2517 call1 (Vtemp_buffer_show_function
, buf
);
2520 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
2522 if (XFRAME (XWINDOW (window
)->frame
) != selected_frame
)
2523 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
2524 Vminibuf_scroll_window
= window
;
2525 w
= XWINDOW (window
);
2526 XSETFASTINT (w
->hscroll
, 0);
2527 set_marker_restricted_both (w
->start
, buf
, 1, 1);
2528 set_marker_restricted_both (w
->pointm
, buf
, 1, 1);
2530 /* Run temp-buffer-show-hook, with the chosen window selected
2531 and it sbuffer current. */
2532 if (!NILP (Vrun_hooks
))
2535 tem
= Fboundp (Qtemp_buffer_show_hook
);
2538 tem
= Fsymbol_value (Qtemp_buffer_show_hook
);
2541 int count
= specpdl_ptr
- specpdl
;
2542 Lisp_Object prev_window
;
2543 prev_window
= selected_window
;
2545 /* Select the window that was chosen, for running the hook. */
2546 record_unwind_protect (Fselect_window
, prev_window
);
2547 select_window_1 (window
, 0);
2548 Fset_buffer (w
->buffer
);
2549 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
2550 select_window_1 (prev_window
, 0);
2551 unbind_to (count
, Qnil
);
2559 make_dummy_parent (window
)
2563 register struct window
*o
, *p
;
2564 register struct Lisp_Vector
*vec
;
2567 o
= XWINDOW (window
);
2568 vec
= allocate_vectorlike ((EMACS_INT
)VECSIZE (struct window
));
2569 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
2570 vec
->contents
[i
] = ((struct Lisp_Vector
*)o
)->contents
[i
];
2571 vec
->size
= VECSIZE (struct window
);
2572 p
= (struct window
*)vec
;
2573 XSETWINDOW (new, p
);
2575 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
2577 /* Put new into window structure in place of window */
2578 replace_window (window
, new);
2591 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
2592 "Split WINDOW, putting SIZE lines in the first of the pair.\n\
2593 WINDOW defaults to selected one and SIZE to half its size.\n\
2594 If optional third arg HORFLAG is non-nil, split side by side\n\
2595 and put SIZE columns in the first of the pair. In that case,\n\
2596 SIZE includes that window's scroll bar, or the divider column to its right.")
2597 (window
, size
, horflag
)
2598 Lisp_Object window
, size
, horflag
;
2600 register Lisp_Object
new;
2601 register struct window
*o
, *p
;
2603 register int size_int
;
2606 window
= selected_window
;
2608 CHECK_LIVE_WINDOW (window
, 0);
2610 o
= XWINDOW (window
);
2611 fo
= XFRAME (WINDOW_FRAME (o
));
2615 if (!NILP (horflag
))
2616 /* Calculate the size of the left-hand window, by dividing
2617 the usable space in columns by two.
2618 We round up, since the left-hand window may include
2619 a dividing line, while the right-hand may not. */
2620 size_int
= (XFASTINT (o
->width
) + 1) >> 1;
2622 size_int
= XFASTINT (o
->height
) >> 1;
2626 CHECK_NUMBER (size
, 1);
2627 size_int
= XINT (size
);
2630 if (MINI_WINDOW_P (o
))
2631 error ("Attempt to split minibuffer window");
2633 check_min_window_sizes ();
2637 if (size_int
< window_min_height
)
2638 error ("Window height %d too small (after splitting)", size_int
);
2639 if (size_int
+ window_min_height
> XFASTINT (o
->height
))
2640 error ("Window height %d too small (after splitting)",
2641 XFASTINT (o
->height
) - size_int
);
2642 if (NILP (o
->parent
)
2643 || NILP (XWINDOW (o
->parent
)->vchild
))
2645 make_dummy_parent (window
);
2647 XWINDOW (new)->vchild
= window
;
2652 if (size_int
< window_min_width
)
2653 error ("Window width %d too small (after splitting)", size_int
);
2655 if (size_int
+ window_min_width
> XFASTINT (o
->width
))
2656 error ("Window width %d too small (after splitting)",
2657 XFASTINT (o
->width
) - size_int
);
2658 if (NILP (o
->parent
)
2659 || NILP (XWINDOW (o
->parent
)->hchild
))
2661 make_dummy_parent (window
);
2663 XWINDOW (new)->hchild
= window
;
2667 /* Now we know that window's parent is a vertical combination
2668 if we are dividing vertically, or a horizontal combination
2669 if we are making side-by-side windows */
2671 windows_or_buffers_changed
++;
2672 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
2673 new = make_window ();
2676 p
->frame
= o
->frame
;
2678 if (!NILP (p
->next
))
2679 XWINDOW (p
->next
)->prev
= new;
2682 p
->parent
= o
->parent
;
2684 p
->window_end_valid
= Qnil
;
2685 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
2687 /* Apportion the available frame space among the two new windows */
2689 if (!NILP (horflag
))
2691 p
->height
= o
->height
;
2693 XSETFASTINT (p
->width
, XFASTINT (o
->width
) - size_int
);
2694 XSETFASTINT (o
->width
, size_int
);
2695 XSETFASTINT (p
->left
, XFASTINT (o
->left
) + size_int
);
2700 p
->width
= o
->width
;
2701 XSETFASTINT (p
->height
, XFASTINT (o
->height
) - size_int
);
2702 XSETFASTINT (o
->height
, size_int
);
2703 XSETFASTINT (p
->top
, XFASTINT (o
->top
) + size_int
);
2706 /* Adjust glyph matrices. */
2708 Fset_window_buffer (new, o
->buffer
);
2712 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
2713 "Make current window ARG lines bigger.\n\
2714 From program, optional second arg non-nil means grow sideways ARG columns.")
2716 register Lisp_Object arg
, side
;
2718 CHECK_NUMBER (arg
, 0);
2719 change_window_height (XINT (arg
), !NILP (side
));
2721 if (! NILP (Vwindow_configuration_change_hook
))
2722 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2727 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
2728 "Make current window ARG lines smaller.\n\
2729 From program, optional second arg non-nil means shrink sideways arg columns.")
2731 register Lisp_Object arg
, side
;
2733 CHECK_NUMBER (arg
, 0);
2734 change_window_height (-XINT (arg
), !NILP (side
));
2736 if (! NILP (Vwindow_configuration_change_hook
))
2737 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2743 window_height (window
)
2746 register struct window
*p
= XWINDOW (window
);
2747 return XFASTINT (p
->height
);
2751 window_width (window
)
2754 register struct window
*p
= XWINDOW (window
);
2755 return XFASTINT (p
->width
);
2758 #define MINSIZE(w) \
2760 ? window_min_width \
2761 : (MINI_WINDOW_P (XWINDOW (w)) ? 1 : window_min_height))
2764 *(widthflag ? (int *) &(XWINDOW (w)->left) : (int *) &(XWINDOW (w)->top))
2766 #define CURSIZE(w) \
2767 *(widthflag ? (int *) &(XWINDOW (w)->width) : (int *) &(XWINDOW (w)->height))
2769 /* Unlike set_window_height, this function
2770 also changes the heights of the siblings so as to
2771 keep everything consistent. */
2774 change_window_height (delta
, widthflag
)
2778 register Lisp_Object parent
;
2780 register struct window
*p
;
2782 int (*sizefun
) P_ ((Lisp_Object
))
2783 = widthflag
? window_width
: window_height
;
2784 register void (*setsizefun
) P_ ((Lisp_Object
, int, int))
2785 = (widthflag
? set_window_width
: set_window_height
);
2787 Lisp_Object next
, prev
;
2789 check_min_window_sizes ();
2791 window
= selected_window
;
2794 p
= XWINDOW (window
);
2799 error ("No other window to side of this one");
2802 if (widthflag
? !NILP (XWINDOW (parent
)->hchild
)
2803 : !NILP (XWINDOW (parent
)->vchild
))
2808 sizep
= &CURSIZE (window
);
2811 register int maxdelta
;
2813 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - *sizep
2814 : !NILP (p
->next
) ? (*sizefun
) (p
->next
) - MINSIZE (p
->next
)
2815 : !NILP (p
->prev
) ? (*sizefun
) (p
->prev
) - MINSIZE (p
->prev
)
2816 /* This is a frame with only one window, a minibuffer-only
2817 or a minibufferless frame. */
2820 if (delta
> maxdelta
)
2821 /* This case traps trying to make the minibuffer
2822 the full frame, or make the only window aside from the
2823 minibuffer the full frame. */
2827 if (*sizep
+ delta
< MINSIZE (window
))
2829 delete_window (window
);
2836 /* Find the total we can get from other siblings. */
2838 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
2839 maximum
+= (*sizefun
) (next
) - MINSIZE (next
);
2840 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
2841 maximum
+= (*sizefun
) (prev
) - MINSIZE (prev
);
2843 /* If we can get it all from them, do so. */
2844 if (delta
<= maximum
)
2846 Lisp_Object first_unaffected
;
2847 Lisp_Object first_affected
;
2851 first_affected
= window
;
2852 /* Look at one sibling at a time,
2853 moving away from this window in both directions alternately,
2854 and take as much as we can get without deleting that sibling. */
2861 int this_one
= (*sizefun
) (next
) - MINSIZE (next
);
2862 if (this_one
> delta
)
2865 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
2866 (*setsizefun
) (window
, *sizep
+ this_one
, 0);
2869 next
= XWINDOW (next
)->next
;
2875 int this_one
= (*sizefun
) (prev
) - MINSIZE (prev
);
2876 if (this_one
> delta
)
2879 first_affected
= prev
;
2881 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
2882 (*setsizefun
) (window
, *sizep
+ this_one
, 0);
2885 prev
= XWINDOW (prev
)->prev
;
2889 /* Now recalculate the edge positions of all the windows affected,
2890 based on the new sizes. */
2891 first_unaffected
= next
;
2892 prev
= first_affected
;
2893 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
2894 prev
= next
, next
= XWINDOW (next
)->next
)
2896 CURBEG (next
) = CURBEG (prev
) + (*sizefun
) (prev
);
2897 /* This does not change size of NEXT,
2898 but it propagates the new top edge to its children */
2899 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
2904 register int delta1
;
2905 register int opht
= (*sizefun
) (parent
);
2907 /* If trying to grow this window to or beyond size of the parent,
2908 make delta1 so big that, on shrinking back down,
2909 all the siblings end up with less than one line and are deleted. */
2910 if (opht
<= *sizep
+ delta
)
2911 delta1
= opht
* opht
* 2;
2912 /* Otherwise, make delta1 just right so that if we add delta1
2913 lines to this window and to the parent, and then shrink
2914 the parent back to its original size, the new proportional
2915 size of this window will increase by delta. */
2917 delta1
= (delta
* opht
* 100) / ((opht
- *sizep
- delta
) * 100);
2919 /* Add delta1 lines or columns to this window, and to the parent,
2920 keeping things consistent while not affecting siblings. */
2921 CURSIZE (parent
) = opht
+ delta1
;
2922 (*setsizefun
) (window
, *sizep
+ delta1
, 0);
2924 /* Squeeze out delta1 lines or columns from our parent,
2925 shriking this window and siblings proportionately.
2926 This brings parent back to correct size.
2927 Delta1 was calculated so this makes this window the desired size,
2928 taking it all out of the siblings. */
2929 (*setsizefun
) (parent
, opht
, 0);
2932 XSETFASTINT (p
->last_modified
, 0);
2933 XSETFASTINT (p
->last_overlay_modified
, 0);
2935 /* Adjust glyph matrices. */
2936 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
2943 /* Mark window cursors off for all windows in the window tree rooted
2944 at W by setting their phys_cursor_on_p flag to zero. Called from
2945 xterm.c, e.g. when a frame is cleared and thereby all cursors on
2946 the frame are cleared. */
2949 mark_window_cursors_off (w
)
2954 if (!NILP (w
->hchild
))
2955 mark_window_cursors_off (XWINDOW (w
->hchild
));
2956 else if (!NILP (w
->vchild
))
2957 mark_window_cursors_off (XWINDOW (w
->vchild
));
2959 w
->phys_cursor_on_p
= 0;
2961 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
2966 /* Return number of lines of text (not counting mode line) in W. */
2969 window_internal_height (w
)
2972 int ht
= XFASTINT (w
->height
);
2974 if (MINI_WINDOW_P (w
))
2977 if (!NILP (w
->parent
) || !NILP (w
->vchild
) || !NILP (w
->hchild
)
2978 || !NILP (w
->next
) || !NILP (w
->prev
)
2979 || FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (w
))))
2986 /* Return the number of columns in W.
2987 Don't count columns occupied by scroll bars or the vertical bar
2988 separating W from the sibling to its right. */
2991 window_internal_width (w
)
2994 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2995 int width
= XINT (w
->width
);
2997 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2998 /* Scroll bars occupy a few columns. */
2999 width
-= FRAME_SCROLL_BAR_COLS (f
);
3000 else if (!WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
3001 /* The column of `|' characters separating side-by-side windows
3002 occupies one column only. */
3005 /* On window-systems, areas to the left and right of the window
3006 are used to display bitmaps there. */
3007 if (FRAME_WINDOW_P (f
))
3008 width
-= 2 * FRAME_FLAGS_AREA_COLS (f
);
3014 /************************************************************************
3016 ***********************************************************************/
3018 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
3019 one screen-full, which is defined as the height of the window minus
3020 next_screen_context_lines. If WHOLE is zero, scroll up N lines
3021 instead. Negative values of N mean scroll down. NOERROR non-zero
3022 means don't signal an error if we try to move over BEGV or ZV,
3026 window_scroll (window
, n
, whole
, noerror
)
3032 /* If we must, use the pixel-based version which is much slower than
3033 the line-based one but can handle varying line heights. */
3034 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
3035 window_scroll_pixel_based (window
, n
, whole
, noerror
);
3037 window_scroll_line_based (window
, n
, whole
, noerror
);
3041 /* Implementation of window_scroll that works based on pixel line
3042 heights. See the comment of window_scroll for parameter
3046 window_scroll_pixel_based (window
, n
, whole
, noerror
)
3053 struct window
*w
= XWINDOW (window
);
3054 struct text_pos start
;
3056 int this_scroll_margin
;
3059 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
3061 /* If PT is not visible in WINDOW, move back one half of
3063 XSETFASTINT (tem
, PT
);
3064 tem
= Fpos_visible_in_window_p (tem
, window
);
3067 /* Move backward half the height of the window. Performance note:
3068 vmotion used here is about 10% faster, but would give wrong
3069 results for variable height lines. */
3070 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
3071 it
.current_y
= it
.last_visible_y
;
3072 move_it_vertically (&it
, -it
.last_visible_y
/ 2);
3074 /* The function move_iterator_vertically may move over more than
3075 the specified y-distance. If it->w is small, e.g. a
3076 mini-buffer window, we may end up in front of the window's
3077 display area. This is the case when Start displaying at the
3078 start of the line containing PT in this case. */
3079 if (it
.current_y
<= 0)
3081 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
3082 move_it_vertically (&it
, 0);
3086 start
= it
.current
.pos
;
3089 /* If scroll_preserve_screen_position is non-zero, we try to set
3090 point in the same window line as it is now, so get that line. */
3091 if (!NILP (Vscroll_preserve_screen_position
))
3093 start_display (&it
, w
, start
);
3094 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
3095 preserve_y
= it
.current_y
;
3100 /* Move iterator it from start the specified distance forward or
3101 backward. The result is the new window start. */
3102 start_display (&it
, w
, start
);
3105 int screen_full
= (it
.last_visible_y
3106 - next_screen_context_lines
* CANON_Y_UNIT (it
.f
));
3107 int direction
= n
< 0 ? -1 : 1;
3108 move_it_vertically (&it
, direction
* screen_full
);
3111 move_it_by_lines (&it
, n
, 1);
3113 /* End if we end up at ZV or BEGV. */
3114 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
3115 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
3119 else if (IT_CHARPOS (it
) == ZV
)
3120 Fsignal (Qend_of_buffer
, Qnil
);
3122 Fsignal (Qbeginning_of_buffer
, Qnil
);
3125 /* Set the window start, and set up the window for redisplay. */
3126 set_marker_restricted (w
->start
, make_number (IT_CHARPOS (it
)), w
->buffer
);
3127 w
->start_at_line_beg
= Fbolp ();
3128 w
->update_mode_line
= Qt
;
3129 XSETFASTINT (w
->last_modified
, 0);
3130 XSETFASTINT (w
->last_overlay_modified
, 0);
3131 /* Set force_start so that redisplay_window will run the
3132 window-scroll-functions. */
3133 w
->force_start
= Qt
;
3135 it
.current_y
= it
.vpos
= 0;
3137 /* Preserve the screen position if we must. */
3138 if (preserve_y
>= 0)
3140 move_it_to (&it
, -1, -1, preserve_y
, -1, MOVE_TO_Y
);
3141 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
3145 /* Move PT out of scroll margins. */
3146 this_scroll_margin
= max (0, scroll_margin
);
3147 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
3148 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
3152 /* We moved the window start towards ZV, so PT may be now
3153 in the scroll margin at the top. */
3154 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
3155 while (it
.current_y
< this_scroll_margin
)
3156 move_it_by_lines (&it
, 1, 1);
3157 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
3161 /* We moved the window start towards BEGV, so PT may be now
3162 in the scroll margin at the bottom. */
3163 move_it_to (&it
, PT
, -1,
3164 it
.last_visible_y
- this_scroll_margin
- 1, -1,
3165 MOVE_TO_POS
| MOVE_TO_Y
);
3167 /* Don't put point on a partially visible line at the end. */
3168 if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
3169 > it
.last_visible_y
)
3170 move_it_by_lines (&it
, -1, 0);
3172 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
3178 /* Implementation of window_scroll that works based on screen lines.
3179 See the comment of window_scroll for parameter descriptions. */
3182 window_scroll_line_based (window
, n
, whole
, noerror
)
3188 register struct window
*w
= XWINDOW (window
);
3189 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
3190 register int pos
, pos_byte
;
3191 register int ht
= window_internal_height (w
);
3192 register Lisp_Object tem
;
3196 struct position posit
;
3199 startpos
= marker_position (w
->start
);
3201 posit
= *compute_motion (startpos
, 0, 0, 0,
3203 window_internal_width (w
), XINT (w
->hscroll
),
3205 original_vpos
= posit
.vpos
;
3207 XSETFASTINT (tem
, PT
);
3208 tem
= Fpos_visible_in_window_p (tem
, window
);
3212 Fvertical_motion (make_number (- (ht
/ 2)), window
);
3217 lose
= n
< 0 && PT
== BEGV
;
3218 Fvertical_motion (make_number (n
), window
);
3222 SET_PT_BOTH (opoint
, opoint_byte
);
3229 Fsignal (Qbeginning_of_buffer
, Qnil
);
3234 int this_scroll_margin
= scroll_margin
;
3236 /* Don't use a scroll margin that is negative or too large. */
3237 if (this_scroll_margin
< 0)
3238 this_scroll_margin
= 0;
3240 if (XINT (w
->height
) < 4 * scroll_margin
)
3241 this_scroll_margin
= XINT (w
->height
) / 4;
3243 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
3244 w
->start_at_line_beg
= bolp
;
3245 w
->update_mode_line
= Qt
;
3246 XSETFASTINT (w
->last_modified
, 0);
3247 XSETFASTINT (w
->last_overlay_modified
, 0);
3248 /* Set force_start so that redisplay_window will run
3249 the window-scroll-functions. */
3250 w
->force_start
= Qt
;
3252 if (whole
&& !NILP (Vscroll_preserve_screen_position
))
3254 SET_PT_BOTH (pos
, pos_byte
);
3255 Fvertical_motion (make_number (original_vpos
), window
);
3257 /* If we scrolled forward, put point enough lines down
3258 that it is outside the scroll margin. */
3263 if (this_scroll_margin
> 0)
3265 SET_PT_BOTH (pos
, pos_byte
);
3266 Fvertical_motion (make_number (this_scroll_margin
), window
);
3272 if (top_margin
<= opoint
)
3273 SET_PT_BOTH (opoint
, opoint_byte
);
3274 else if (!NILP (Vscroll_preserve_screen_position
))
3276 SET_PT_BOTH (pos
, pos_byte
);
3277 Fvertical_motion (make_number (original_vpos
), window
);
3280 SET_PT (top_margin
);
3286 /* If we scrolled backward, put point near the end of the window
3287 but not within the scroll margin. */
3288 SET_PT_BOTH (pos
, pos_byte
);
3289 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
3290 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
3293 bottom_margin
= PT
+ 1;
3295 if (bottom_margin
> opoint
)
3296 SET_PT_BOTH (opoint
, opoint_byte
);
3299 if (!NILP (Vscroll_preserve_screen_position
))
3301 SET_PT_BOTH (pos
, pos_byte
);
3302 Fvertical_motion (make_number (original_vpos
), window
);
3305 Fvertical_motion (make_number (-1), window
);
3314 Fsignal (Qend_of_buffer
, Qnil
);
3319 /* Scroll selected_window up or down. If N is nil, scroll a
3320 screen-full which is defined as the height of the window minus
3321 next_screen_context_lines. If N is the symbol `-', scroll.
3322 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
3323 up. This is the guts of Fscroll_up and Fscroll_down. */
3326 scroll_command (n
, direction
)
3330 register int defalt
;
3331 int count
= specpdl_ptr
- specpdl
;
3333 xassert (abs (direction
) == 1);
3335 /* If selected window's buffer isn't current, make it current for
3336 the moment. But don't screw up if window_scroll gets an error. */
3337 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
3339 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
3340 Fset_buffer (XWINDOW (selected_window
)->buffer
);
3342 /* Make redisplay consider other windows than just selected_window. */
3343 ++windows_or_buffers_changed
;
3346 defalt
= (window_internal_height (XWINDOW (selected_window
))
3347 - next_screen_context_lines
);
3348 defalt
= direction
* (defalt
< 1 ? 1 : defalt
);
3351 window_scroll (selected_window
, defalt
, 1, 0);
3352 else if (EQ (n
, Qminus
))
3353 window_scroll (selected_window
, - defalt
, 1, 0);
3356 n
= Fprefix_numeric_value (n
);
3357 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
3360 unbind_to (count
, Qnil
);
3363 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
3364 "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\
3365 A near full screen is `next-screen-context-lines' less than a full screen.\n\
3366 Negative ARG means scroll downward.\n\
3367 If ARG is the atom `-', scroll downward by nearly full screen.\n\
3368 When calling from a program, supply as argument a number, nil, or `-'.")
3372 scroll_command (arg
, 1);
3376 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
3377 "Scroll text of current window down ARG lines; or near full screen if no ARG.\n\
3378 A near full screen is `next-screen-context-lines' less than a full screen.\n\
3379 Negative ARG means scroll upward.\n\
3380 If ARG is the atom `-', scroll upward by nearly full screen.\n\
3381 When calling from a program, supply as argument a number, nil, or `-'.")
3385 scroll_command (arg
, -1);
3389 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
3390 "Return the other window for \"other window scroll\" commands.\n\
3391 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
3392 specifies the window.\n\
3393 If `other-window-scroll-buffer' is non-nil, a window\n\
3394 showing that buffer is used.")
3399 if (MINI_WINDOW_P (XWINDOW (selected_window
))
3400 && !NILP (Vminibuf_scroll_window
))
3401 window
= Vminibuf_scroll_window
;
3402 /* If buffer is specified, scroll that buffer. */
3403 else if (!NILP (Vother_window_scroll_buffer
))
3405 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
3407 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
3411 /* Nothing specified; look for a neighboring window on the same
3413 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
3415 if (EQ (window
, selected_window
))
3416 /* That didn't get us anywhere; look for a window on another
3419 window
= Fnext_window (window
, Qnil
, Qt
);
3420 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
3421 && ! EQ (window
, selected_window
));
3424 CHECK_LIVE_WINDOW (window
, 0);
3426 if (EQ (window
, selected_window
))
3427 error ("There is no other window");
3432 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
3433 "Scroll next window upward ARG lines; or near full screen if no ARG.\n\
3434 A near full screen is `next-screen-context-lines' less than a full screen.\n\
3435 The next window is the one below the current one; or the one at the top\n\
3436 if the current one is at the bottom. Negative ARG means scroll downward.\n\
3437 If ARG is the atom `-', scroll downward by nearly full screen.\n\
3438 When calling from a program, supply as argument a number, nil, or `-'.\n\
3440 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
3441 specifies the window to scroll.\n\
3442 If `other-window-scroll-buffer' is non-nil, scroll the window\n\
3443 showing that buffer, popping the buffer up if necessary.")
3445 register Lisp_Object arg
;
3447 register Lisp_Object window
;
3448 register int defalt
;
3449 register struct window
*w
;
3450 register int count
= specpdl_ptr
- specpdl
;
3452 window
= Fother_window_for_scrolling ();
3454 w
= XWINDOW (window
);
3455 defalt
= window_internal_height (w
) - next_screen_context_lines
;
3456 if (defalt
< 1) defalt
= 1;
3458 /* Don't screw up if window_scroll gets an error. */
3459 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
3460 ++windows_or_buffers_changed
;
3462 Fset_buffer (w
->buffer
);
3463 SET_PT (marker_position (w
->pointm
));
3466 window_scroll (window
, defalt
, 1, 1);
3467 else if (EQ (arg
, Qminus
))
3468 window_scroll (window
, -defalt
, 1, 1);
3473 CHECK_NUMBER (arg
, 0);
3474 window_scroll (window
, XINT (arg
), 0, 1);
3477 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
3478 unbind_to (count
, Qnil
);
3483 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 1, "P",
3484 "Scroll selected window display ARG columns left.\n\
3485 Default for ARG is window width minus 2.")
3487 register Lisp_Object arg
;
3491 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
3493 arg
= Fprefix_numeric_value (arg
);
3496 Fset_window_hscroll (selected_window
,
3497 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
3501 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 1, "P",
3502 "Scroll selected window display ARG columns right.\n\
3503 Default for ARG is window width minus 2.")
3505 register Lisp_Object arg
;
3508 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
3510 arg
= Fprefix_numeric_value (arg
);
3513 Fset_window_hscroll (selected_window
,
3514 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
3518 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
3519 "Center point in window and redisplay frame. With ARG, put point on line ARG.\n\
3520 The desired position of point is always relative to the current window.\n\
3521 Just C-u as prefix means put point in the center of the window.\n\
3522 If ARG is omitted or nil, erases the entire frame and then\n\
3523 redraws with point in the center of the current window.")
3525 register Lisp_Object arg
;
3527 register struct window
*w
= XWINDOW (selected_window
);
3528 register int ht
= window_internal_height (w
);
3529 struct position pos
;
3530 struct buffer
*buf
= XBUFFER (w
->buffer
);
3531 struct buffer
*obuf
= current_buffer
;
3535 extern int frame_garbaged
;
3537 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
3538 XSETFASTINT (arg
, ht
/ 2);
3540 else if (CONSP (arg
)) /* Just C-u. */
3542 XSETFASTINT (arg
, ht
/ 2);
3546 arg
= Fprefix_numeric_value (arg
);
3547 CHECK_NUMBER (arg
, 0);
3551 XSETINT (arg
, XINT (arg
) + ht
);
3553 set_buffer_internal (buf
);
3554 pos
= *vmotion (PT
, - XINT (arg
), w
);
3556 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
3557 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
3558 || FETCH_BYTE (pos
.bytepos
- 1) == '\n')
3560 w
->force_start
= Qt
;
3561 set_buffer_internal (obuf
);
3566 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
3568 "Position point relative to window.\n\
3569 With no argument, position point at center of window.\n\
3570 An argument specifies vertical position within the window;\n\
3571 zero means top of window, negative means relative to bottom of window.")
3573 register Lisp_Object arg
;
3575 register struct window
*w
= XWINDOW (selected_window
);
3576 register int height
= window_internal_height (w
);
3581 XSETFASTINT (arg
, height
/ 2);
3584 arg
= Fprefix_numeric_value (arg
);
3586 XSETINT (arg
, XINT (arg
) + height
);
3589 start
= marker_position (w
->start
);
3590 XSETWINDOW (window
, w
);
3591 if (start
< BEGV
|| start
> ZV
)
3593 Fvertical_motion (make_number (- (height
/ 2)), window
);
3594 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
3595 w
->start_at_line_beg
= Fbolp ();
3596 w
->force_start
= Qt
;
3599 Fgoto_char (w
->start
);
3601 return Fvertical_motion (arg
, window
);
3606 /***********************************************************************
3607 Window Configuration
3608 ***********************************************************************/
3610 struct save_window_data
3612 EMACS_INT size_from_Lisp_Vector_struct
;
3613 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
3614 Lisp_Object frame_width
, frame_height
, frame_menu_bar_lines
;
3615 Lisp_Object frame_toolbar_lines
;
3616 Lisp_Object selected_frame
;
3617 Lisp_Object current_window
;
3618 Lisp_Object current_buffer
;
3619 Lisp_Object minibuf_scroll_window
;
3620 Lisp_Object root_window
;
3621 Lisp_Object focus_frame
;
3622 /* Record the values of window-min-width and window-min-height
3623 so that window sizes remain consistent with them. */
3624 Lisp_Object min_width
, min_height
;
3625 /* A vector, each of whose elements is a struct saved_window
3627 Lisp_Object saved_windows
;
3630 /* This is saved as a Lisp_Vector */
3633 /* these first two must agree with struct Lisp_Vector in lisp.h */
3634 EMACS_INT size_from_Lisp_Vector_struct
;
3635 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
3638 Lisp_Object buffer
, start
, pointm
, mark
;
3639 Lisp_Object left
, top
, width
, height
, hscroll
;
3640 Lisp_Object parent
, prev
;
3641 Lisp_Object start_at_line_beg
;
3642 Lisp_Object display_table
;
3644 #define SAVED_WINDOW_VECTOR_SIZE 14 /* Arg to Fmake_vector */
3646 #define SAVED_WINDOW_N(swv,n) \
3647 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
3649 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
3650 "Return t if OBJECT is a window-configuration object.")
3654 if (WINDOW_CONFIGURATIONP (object
))
3659 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
3660 "Return the frame that CONFIG, a window-configuration object, is about.")
3664 register struct save_window_data
*data
;
3665 struct Lisp_Vector
*saved_windows
;
3667 if (! WINDOW_CONFIGURATIONP (config
))
3668 wrong_type_argument (Qwindow_configuration_p
, config
);
3670 data
= (struct save_window_data
*) XVECTOR (config
);
3671 saved_windows
= XVECTOR (data
->saved_windows
);
3672 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
3675 DEFUN ("set-window-configuration", Fset_window_configuration
,
3676 Sset_window_configuration
, 1, 1, 0,
3677 "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\
3678 CONFIGURATION must be a value previously returned\n\
3679 by `current-window-configuration' (which see).\n\
3680 If CONFIGURATION was made from a frame that is now deleted,\n\
3681 only frame-independent values can be restored. In this case,\n\
3682 the return value is nil. Otherwise the value is t.")
3684 Lisp_Object configuration
;
3686 register struct save_window_data
*data
;
3687 struct Lisp_Vector
*saved_windows
;
3688 Lisp_Object new_current_buffer
;
3693 while (!WINDOW_CONFIGURATIONP (configuration
))
3694 wrong_type_argument (Qwindow_configuration_p
, configuration
);
3696 data
= (struct save_window_data
*) XVECTOR (configuration
);
3697 saved_windows
= XVECTOR (data
->saved_windows
);
3699 new_current_buffer
= data
->current_buffer
;
3700 if (NILP (XBUFFER (new_current_buffer
)->name
))
3701 new_current_buffer
= Qnil
;
3704 if (XBUFFER (new_current_buffer
) == current_buffer
)
3709 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
3712 /* If f is a dead frame, don't bother rebuilding its window tree.
3713 However, there is other stuff we should still try to do below. */
3714 if (FRAME_LIVE_P (f
))
3716 register struct window
*w
;
3717 register struct saved_window
*p
;
3718 struct window
*root_window
;
3719 struct window
**leaf_windows
;
3723 /* If the frame has been resized since this window configuration was
3724 made, we change the frame to the size specified in the
3725 configuration, restore the configuration, and then resize it
3726 back. We keep track of the prevailing height in these variables. */
3727 int previous_frame_height
= FRAME_HEIGHT (f
);
3728 int previous_frame_width
= FRAME_WIDTH (f
);
3729 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
3730 int previous_frame_toolbar_lines
= FRAME_TOOLBAR_LINES (f
);
3732 /* The mouse highlighting code could get screwed up
3733 if it runs during this. */
3736 if (XFASTINT (data
->frame_height
) != previous_frame_height
3737 || XFASTINT (data
->frame_width
) != previous_frame_width
)
3738 change_frame_size (f
, XFASTINT (data
->frame_height
),
3739 XFASTINT (data
->frame_width
), 0, 0);
3740 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
3741 if (XFASTINT (data
->frame_menu_bar_lines
)
3742 != previous_frame_menu_bar_lines
)
3743 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, make_number (0));
3744 #ifdef HAVE_WINDOW_SYSTEM
3745 if (XFASTINT (data
->frame_toolbar_lines
)
3746 != previous_frame_toolbar_lines
)
3747 x_set_toolbar_lines (f
, data
->frame_toolbar_lines
, make_number (0));
3751 if (! NILP (XWINDOW (selected_window
)->buffer
))
3753 w
= XWINDOW (selected_window
);
3754 set_marker_both (w
->pointm
,
3756 BUF_PT (XBUFFER (w
->buffer
)),
3757 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
3760 windows_or_buffers_changed
++;
3761 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3763 /* Problem: Freeing all matrices and later allocating them again
3764 is a serious redisplay flickering problem. What we would
3765 really like to do is to free only those matrices not reused
3767 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3769 = (struct window
**) alloca (count_windows (root_window
)
3770 * sizeof (struct window
*));
3771 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
3773 /* Temporarily avoid any problems with windows that are smaller
3774 than they are supposed to be. */
3775 window_min_height
= 1;
3776 window_min_width
= 1;
3779 Mark all windows now on frame as "deleted".
3780 Restoring the new configuration "undeletes" any that are in it.
3782 Save their current buffers in their height fields, since we may
3783 need it later, if a buffer saved in the configuration is now
3785 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3787 for (k
= 0; k
< saved_windows
->size
; k
++)
3789 p
= SAVED_WINDOW_N (saved_windows
, k
);
3790 w
= XWINDOW (p
->window
);
3793 if (!NILP (p
->parent
))
3794 w
->parent
= SAVED_WINDOW_N (saved_windows
,
3795 XFASTINT (p
->parent
))->window
;
3799 if (!NILP (p
->prev
))
3801 w
->prev
= SAVED_WINDOW_N (saved_windows
,
3802 XFASTINT (p
->prev
))->window
;
3803 XWINDOW (w
->prev
)->next
= p
->window
;
3808 if (!NILP (w
->parent
))
3810 if (EQ (p
->width
, XWINDOW (w
->parent
)->width
))
3812 XWINDOW (w
->parent
)->vchild
= p
->window
;
3813 XWINDOW (w
->parent
)->hchild
= Qnil
;
3817 XWINDOW (w
->parent
)->hchild
= p
->window
;
3818 XWINDOW (w
->parent
)->vchild
= Qnil
;
3823 /* If we squirreled away the buffer in the window's height,
3825 if (BUFFERP (w
->height
))
3826 w
->buffer
= w
->height
;
3829 w
->width
= p
->width
;
3830 w
->height
= p
->height
;
3831 w
->hscroll
= p
->hscroll
;
3832 w
->display_table
= p
->display_table
;
3833 XSETFASTINT (w
->last_modified
, 0);
3834 XSETFASTINT (w
->last_overlay_modified
, 0);
3836 /* Reinstall the saved buffer and pointers into it. */
3837 if (NILP (p
->buffer
))
3838 w
->buffer
= p
->buffer
;
3841 if (!NILP (XBUFFER (p
->buffer
)->name
))
3842 /* If saved buffer is alive, install it. */
3844 w
->buffer
= p
->buffer
;
3845 w
->start_at_line_beg
= p
->start_at_line_beg
;
3846 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
3847 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
3848 Fset_marker (XBUFFER (w
->buffer
)->mark
,
3849 p
->mark
, w
->buffer
);
3851 /* As documented in Fcurrent_window_configuration, don't
3852 save the location of point in the buffer which was current
3853 when the window configuration was recorded. */
3854 if (!EQ (p
->buffer
, new_current_buffer
)
3855 && XBUFFER (p
->buffer
) == current_buffer
)
3856 Fgoto_char (w
->pointm
);
3858 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
3859 /* Else unless window has a live buffer, get one. */
3861 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
3862 /* This will set the markers to beginning of visible
3864 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
3865 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
3866 w
->start_at_line_beg
= Qt
;
3869 /* Keeping window's old buffer; make sure the markers
3872 /* Set window markers at start of visible range. */
3873 if (XMARKER (w
->start
)->buffer
== 0)
3874 set_marker_restricted (w
->start
, make_number (0),
3876 if (XMARKER (w
->pointm
)->buffer
== 0)
3877 set_marker_restricted_both (w
->pointm
, w
->buffer
,
3878 BUF_PT (XBUFFER (w
->buffer
)),
3879 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
3880 w
->start_at_line_beg
= Qt
;
3885 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
3886 Fselect_window (data
->current_window
);
3887 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
3890 if (NILP (data
->focus_frame
)
3891 || (FRAMEP (data
->focus_frame
)
3892 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
3893 Fredirect_frame_focus (frame
, data
->focus_frame
);
3895 #if 0 /* I don't understand why this is needed, and it causes problems
3896 when the frame's old selected window has been deleted. */
3897 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
3898 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
3902 /* Set the screen height to the value it had before this function. */
3903 if (previous_frame_height
!= FRAME_HEIGHT (f
)
3904 || previous_frame_width
!= FRAME_WIDTH (f
))
3905 change_frame_size (f
, previous_frame_height
, previous_frame_width
,
3907 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
3908 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
3909 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
3911 #ifdef HAVE_WINDOW_SYSTEM
3912 if (previous_frame_toolbar_lines
!= FRAME_TOOLBAR_LINES (f
))
3913 x_set_toolbar_lines (f
, make_number (previous_frame_toolbar_lines
),
3918 /* Now, free glyph matrices in windows that were not reused. */
3919 for (i
= 0; i
< n_leaf_windows
; ++i
)
3920 if (NILP (leaf_windows
[i
]->buffer
))
3922 /* Assert it's not reused as a combination. */
3923 xassert (NILP (leaf_windows
[i
]->hchild
)
3924 && NILP (leaf_windows
[i
]->vchild
));
3925 free_window_matrices (leaf_windows
[i
]);
3926 SET_FRAME_GARBAGED (f
);
3933 /* Fselect_window will have made f the selected frame, so we
3934 reselect the proper frame here. Fhandle_switch_frame will change the
3935 selected window too, but that doesn't make the call to
3936 Fselect_window above totally superfluous; it still sets f's
3938 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
3939 do_switch_frame (data
->selected_frame
, Qnil
, 0);
3941 if (! NILP (Vwindow_configuration_change_hook
)
3942 && ! NILP (Vrun_hooks
))
3943 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3946 if (!NILP (new_current_buffer
))
3948 Fset_buffer (new_current_buffer
);
3950 /* If the buffer that is current now is the same
3951 that was current before setting the window configuration,
3952 don't alter its PT. */
3957 /* Restore the minimum heights recorded in the configuration. */
3958 window_min_height
= XINT (data
->min_height
);
3959 window_min_width
= XINT (data
->min_width
);
3961 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
3963 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
3966 /* Mark all windows now on frame as deleted
3967 by setting their buffers to nil. */
3970 delete_all_subwindows (w
)
3971 register struct window
*w
;
3973 if (!NILP (w
->next
))
3974 delete_all_subwindows (XWINDOW (w
->next
));
3975 if (!NILP (w
->vchild
))
3976 delete_all_subwindows (XWINDOW (w
->vchild
));
3977 if (!NILP (w
->hchild
))
3978 delete_all_subwindows (XWINDOW (w
->hchild
));
3980 w
->height
= w
->buffer
; /* See Fset_window_configuration for excuse. */
3982 if (!NILP (w
->buffer
))
3985 /* We set all three of these fields to nil, to make sure that we can
3986 distinguish this dead window from any live window. Live leaf
3987 windows will have buffer set, and combination windows will have
3988 vchild or hchild set. */
3995 count_windows (window
)
3996 register struct window
*window
;
3998 register int count
= 1;
3999 if (!NILP (window
->next
))
4000 count
+= count_windows (XWINDOW (window
->next
));
4001 if (!NILP (window
->vchild
))
4002 count
+= count_windows (XWINDOW (window
->vchild
));
4003 if (!NILP (window
->hchild
))
4004 count
+= count_windows (XWINDOW (window
->hchild
));
4009 /* Fill vector FLAT with leaf windows under W, starting at index I.
4010 Value is last index + 1. */
4013 get_leaf_windows (w
, flat
, i
)
4015 struct window
**flat
;
4020 if (!NILP (w
->hchild
))
4021 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
4022 else if (!NILP (w
->vchild
))
4023 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
4027 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4034 /* Return a pointer to the glyph W's physical cursor is on. Value is
4035 null if W's current matrix is invalid, so that no meaningfull glyph
4039 get_phys_cursor_glyph (w
)
4042 struct glyph_row
*row
;
4043 struct glyph
*glyph
;
4045 if (w
->phys_cursor
.vpos
>= 0
4046 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
4047 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
4049 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
4050 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
4059 save_window_save (window
, vector
, i
)
4061 struct Lisp_Vector
*vector
;
4064 register struct saved_window
*p
;
4065 register struct window
*w
;
4066 register Lisp_Object tem
;
4068 for (;!NILP (window
); window
= w
->next
)
4070 p
= SAVED_WINDOW_N (vector
, i
);
4071 w
= XWINDOW (window
);
4073 XSETFASTINT (w
->temslot
, i
++);
4075 p
->buffer
= w
->buffer
;
4078 p
->width
= w
->width
;
4079 p
->height
= w
->height
;
4080 p
->hscroll
= w
->hscroll
;
4081 p
->display_table
= w
->display_table
;
4082 if (!NILP (w
->buffer
))
4084 /* Save w's value of point in the window configuration.
4085 If w is the selected window, then get the value of point
4086 from the buffer; pointm is garbage in the selected window. */
4087 if (EQ (window
, selected_window
))
4089 p
->pointm
= Fmake_marker ();
4090 set_marker_both (p
->pointm
, w
->buffer
,
4091 BUF_PT (XBUFFER (w
->buffer
)),
4092 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
4095 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
4097 p
->start
= Fcopy_marker (w
->start
, Qnil
);
4098 p
->start_at_line_beg
= w
->start_at_line_beg
;
4100 tem
= XBUFFER (w
->buffer
)->mark
;
4101 p
->mark
= Fcopy_marker (tem
, Qnil
);
4108 p
->start_at_line_beg
= Qnil
;
4111 if (NILP (w
->parent
))
4114 p
->parent
= XWINDOW (w
->parent
)->temslot
;
4119 p
->prev
= XWINDOW (w
->prev
)->temslot
;
4121 if (!NILP (w
->vchild
))
4122 i
= save_window_save (w
->vchild
, vector
, i
);
4123 if (!NILP (w
->hchild
))
4124 i
= save_window_save (w
->hchild
, vector
, i
);
4130 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
4131 Scurrent_window_configuration
, 0, 1, 0,
4132 "Return an object representing the current window configuration of FRAME.\n\
4133 If FRAME is nil or omitted, use the selected frame.\n\
4134 This describes the number of windows, their sizes and current buffers,\n\
4135 and for each displayed buffer, where display starts, and the positions of\n\
4136 point and mark. An exception is made for point in the current buffer:\n\
4137 its value is -not- saved.\n\
4138 This also records the currently selected frame, and FRAME's focus\n\
4139 redirection (see `redirect-frame-focus').")
4143 register Lisp_Object tem
;
4144 register int n_windows
;
4145 register struct save_window_data
*data
;
4146 register struct Lisp_Vector
*vec
;
4154 CHECK_LIVE_FRAME (frame
, 0);
4158 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4159 vec
= allocate_vectorlike (VECSIZE (struct save_window_data
));
4160 for (i
= 0; i
< VECSIZE (struct save_window_data
); i
++)
4161 vec
->contents
[i
] = Qnil
;
4162 vec
->size
= VECSIZE (struct save_window_data
);
4163 data
= (struct save_window_data
*)vec
;
4165 XSETFASTINT (data
->frame_width
, FRAME_WIDTH (f
));
4166 XSETFASTINT (data
->frame_height
, FRAME_HEIGHT (f
));
4167 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
4168 XSETFASTINT (data
->frame_toolbar_lines
, FRAME_TOOLBAR_LINES (f
));
4169 XSETFRAME (data
->selected_frame
, selected_frame
);
4170 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
4171 XSETBUFFER (data
->current_buffer
, current_buffer
);
4172 data
->minibuf_scroll_window
= Vminibuf_scroll_window
;
4173 data
->root_window
= FRAME_ROOT_WINDOW (f
);
4174 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
4175 XSETINT (data
->min_height
, window_min_height
);
4176 XSETINT (data
->min_width
, window_min_width
);
4177 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
4178 data
->saved_windows
= tem
;
4179 for (i
= 0; i
< n_windows
; i
++)
4180 XVECTOR (tem
)->contents
[i
]
4181 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
4182 save_window_save (FRAME_ROOT_WINDOW (f
),
4184 XSETWINDOW_CONFIGURATION (tem
, data
);
4188 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
4190 "Execute body, preserving window sizes and contents.\n\
4191 Restore which buffer appears in which window, where display starts,\n\
4192 and the value of point and mark for each window.\n\
4193 Also restore which buffer is current.\n\
4194 But do not preserve point in the current buffer.\n\
4195 Does not restore the value of point in current buffer.")
4199 register Lisp_Object val
;
4200 register int count
= specpdl_ptr
- specpdl
;
4202 record_unwind_protect (Fset_window_configuration
,
4203 Fcurrent_window_configuration (Qnil
));
4204 val
= Fprogn (args
);
4205 return unbind_to (count
, val
);
4209 /***********************************************************************
4211 ***********************************************************************/
4213 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
4215 "Set width of marginal areas of window WINDOW.\n\
4216 If window is nil or omitted, set margins of the currently selected window.\n\
4217 First parameter LEFT-WIDTH specifies the number of character\n\
4218 cells to reserve for the left marginal area. Second parameter\n\
4219 RIGHT-WIDTH does the same for the right marginal area.\n\
4220 A nil width parameter means no margin.")
4221 (left
, right
, window
)
4222 Lisp_Object window
, left
, right
;
4224 struct window
*w
= decode_window (window
);
4225 struct frame
*f
= XFRAME (w
->frame
);
4228 CHECK_NUMBER_OR_FLOAT (left
, 0);
4230 CHECK_NUMBER_OR_FLOAT (right
, 0);
4232 /* Check widths < 0 and translate a zero width to nil.
4233 Margins that are too wide have to be checked elsewhere. */
4234 if ((INTEGERP (left
) && XINT (left
) < 0)
4235 || (FLOATP (left
) && XFLOAT (left
)->data
<= 0))
4236 XSETFASTINT (left
, 0);
4237 if (INTEGERP (left
) && XFASTINT (left
) == 0)
4240 if ((INTEGERP (right
) && XINT (right
) < 0)
4241 || (FLOATP (right
) && XFLOAT (right
)->data
<= 0))
4242 XSETFASTINT (right
, 0);
4243 if (INTEGERP (right
) && XFASTINT (right
) == 0)
4246 w
->left_margin_width
= left
;
4247 w
->right_margin_width
= right
;
4249 ++windows_or_buffers_changed
;
4250 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
4255 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
4257 "Get width of marginal areas of window WINDOW.\n\
4258 If WINDOW is omitted or nil, use the currently selected window.\n\
4259 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).\n\
4260 If a marginal area does not exist, its width will be returned\n\
4265 struct window
*w
= decode_window (window
);
4266 return Fcons (w
->left_margin_width
, w
->right_margin_width
);
4271 /***********************************************************************
4273 ***********************************************************************/
4275 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 1, 0,
4276 "Return the amount by which WINDOW is scrolled vertically.\n\
4277 Use the selected window if WINDOW is nil or omitted.\n\
4278 Value is a multiple of the canonical character height of WINDOW.")
4286 window
= selected_window
;
4287 w
= XWINDOW (window
);
4288 f
= XFRAME (w
->frame
);
4290 if (FRAME_WINDOW_P (f
))
4291 return CANON_Y_FROM_PIXEL_Y (f
, w
->vscroll
);
4293 return make_number (0);
4297 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
4299 "Set amount by WINDOW should be scrolled vertically to VSCROLL.\n\
4300 WINDOW nil or omitted means use the selected window. VSCROLL is a\n\
4301 multiple of the canonical character height of WINDOW.")
4303 Lisp_Object vscroll
, window
;
4308 CHECK_NUMBER_OR_FLOAT (vscroll
, 0);
4311 window
= selected_window
;
4312 w
= XWINDOW (window
);
4313 f
= XFRAME (w
->frame
);
4315 if (FRAME_WINDOW_P (f
))
4317 int old_dy
= w
->vscroll
;
4318 w
->vscroll
= min (0, CANON_Y_UNIT (f
) * XFLOATINT (vscroll
));
4320 /* Adjust glyph matrix of the frame if the virtual display
4321 area becomes larger than before. */
4322 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
4325 /* Prevent redisplay shortcuts. */
4326 XBUFFER (w
->buffer
)->clip_changed
= 1;
4334 /***********************************************************************
4336 ***********************************************************************/
4338 /* Return 1 if window configurations C1 and C2
4339 describe the same state of affairs. This is used by Fequal. */
4342 compare_window_configurations (c1
, c2
, ignore_positions
)
4344 int ignore_positions
;
4346 register struct save_window_data
*d1
, *d2
;
4347 struct Lisp_Vector
*sw1
, *sw2
;
4350 d1
= (struct save_window_data
*) XVECTOR (c1
);
4351 d2
= (struct save_window_data
*) XVECTOR (c2
);
4352 sw1
= XVECTOR (d1
->saved_windows
);
4353 sw2
= XVECTOR (d2
->saved_windows
);
4355 if (! EQ (d1
->frame_width
, d2
->frame_width
))
4357 if (! EQ (d1
->frame_height
, d2
->frame_height
))
4359 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
4361 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
4363 /* Don't compare the current_window field directly.
4364 Instead see w1_is_current and w2_is_current, below. */
4365 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
4367 if (! ignore_positions
)
4368 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
4370 /* Don't compare the root_window field.
4371 We don't require the two configurations
4372 to use the same window object,
4373 and the two root windows must be equivalent
4374 if everything else compares equal. */
4375 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
4377 if (! EQ (d1
->min_width
, d2
->min_width
))
4379 if (! EQ (d1
->min_height
, d2
->min_height
))
4382 /* Verify that the two confis have the same number of windows. */
4383 if (sw1
->size
!= sw2
->size
)
4386 for (i
= 0; i
< sw1
->size
; i
++)
4388 struct saved_window
*p1
, *p2
;
4389 int w1_is_current
, w2_is_current
;
4391 p1
= SAVED_WINDOW_N (sw1
, i
);
4392 p2
= SAVED_WINDOW_N (sw2
, i
);
4394 /* Verify that the current windows in the two
4395 configurations correspond to each other. */
4396 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
4397 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
4399 if (w1_is_current
!= w2_is_current
)
4402 /* Verify that the corresponding windows do match. */
4403 if (! EQ (p1
->buffer
, p2
->buffer
))
4405 if (! EQ (p1
->left
, p2
->left
))
4407 if (! EQ (p1
->top
, p2
->top
))
4409 if (! EQ (p1
->width
, p2
->width
))
4411 if (! EQ (p1
->height
, p2
->height
))
4413 if (! EQ (p1
->display_table
, p2
->display_table
))
4415 if (! EQ (p1
->parent
, p2
->parent
))
4417 if (! EQ (p1
->prev
, p2
->prev
))
4419 if (! ignore_positions
)
4421 if (! EQ (p1
->hscroll
, p2
->hscroll
))
4423 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
4425 if (NILP (Fequal (p1
->start
, p2
->start
)))
4427 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
4429 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
4437 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
4438 Scompare_window_configurations
, 2, 2, 0,
4439 "Compare two window configurations as regards the structure of windows.\n\
4440 This function ignores details such as the values of point and mark\n\
4441 and scrolling positions.")
4445 if (compare_window_configurations (x
, y
, 1))
4453 selected_frame
= make_terminal_frame ();
4454 XSETFRAME (Vterminal_frame
, selected_frame
);
4455 minibuf_window
= selected_frame
->minibuffer_window
;
4456 selected_window
= selected_frame
->selected_window
;
4457 last_nonminibuf_frame
= selected_frame
;
4459 window_initialized
= 1;
4465 staticpro (&Qwindow_configuration_change_hook
);
4466 Qwindow_configuration_change_hook
4467 = intern ("window-configuration-change-hook");
4469 Qwindowp
= intern ("windowp");
4470 staticpro (&Qwindowp
);
4472 Qwindow_configuration_p
= intern ("window-configuration-p");
4473 staticpro (&Qwindow_configuration_p
);
4475 Qwindow_live_p
= intern ("window-live-p");
4476 staticpro (&Qwindow_live_p
);
4478 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
4479 staticpro (&Qtemp_buffer_show_hook
);
4481 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
4482 "Non-nil means call as function to display a help buffer.\n\
4483 The function is called with one argument, the buffer to be displayed.\n\
4484 Used by `with-output-to-temp-buffer'.\n\
4485 If this function is used, then it must do the entire job of showing\n\
4486 the buffer; `temp-buffer-show-hook' is not run unless this function runs it.");
4487 Vtemp_buffer_show_function
= Qnil
;
4489 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
4490 "If non-nil, function to call to handle `display-buffer'.\n\
4491 It will receive two args, the buffer and a flag which if non-nil means\n\
4492 that the currently selected window is not acceptable.\n\
4493 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\
4494 work using this function.");
4495 Vdisplay_buffer_function
= Qnil
;
4497 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
4498 "Non-nil means it is the window that C-M-v in minibuffer should scroll.");
4499 Vminibuf_scroll_window
= Qnil
;
4501 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
4502 "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.");
4503 Vother_window_scroll_buffer
= Qnil
;
4505 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
4506 "*Non-nil means `display-buffer' should make a separate frame.");
4509 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
4510 "Function to call to handle automatic new frame creation.\n\
4511 It is called with no arguments and should return a newly created frame.\n\
4513 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\
4514 where `pop-up-frame-alist' would hold the default frame parameters.");
4515 Vpop_up_frame_function
= Qnil
;
4517 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
4518 "*List of buffer names that should have their own special frames.\n\
4519 Displaying a buffer whose name is in this list makes a special frame for it\n\
4520 using `special-display-function'. See also `special-display-regexps'.\n\
4522 An element of the list can be a list instead of just a string.\n\
4523 There are two ways to use a list as an element:\n\
4524 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)\n\
4525 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
4526 In the latter case, FUNCTION is called with BUFFER as the first argument,\n\
4527 followed by OTHER-ARGS--it can display BUFFER in any way it likes.\n\
4528 All this is done by the function found in `special-display-function'.\n\
4530 If this variable appears \"not to work\", because you add a name to it\n\
4531 but that buffer still appears in the selected window, look at the\n\
4532 values of `same-window-buffer-names' and `same-window-regexps'.\n\
4533 Those variables take precedence over this one.");
4534 Vspecial_display_buffer_names
= Qnil
;
4536 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
4537 "*List of regexps saying which buffers should have their own special frames.\n\
4538 If a buffer name matches one of these regexps, it gets its own frame.\n\
4539 Displaying a buffer whose name is in this list makes a special frame for it\n\
4540 using `special-display-function'.\n\
4542 An element of the list can be a list instead of just a string.\n\
4543 There are two ways to use a list as an element:\n\
4544 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)\n\
4545 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
4546 In the latter case, FUNCTION is called with the buffer as first argument,\n\
4547 followed by OTHER-ARGS--it can display the buffer in any way it likes.\n\
4548 All this is done by the function found in `special-display-function'.\n\
4550 If this variable appears \"not to work\", because you add a regexp to it\n\
4551 but the matching buffers still appear in the selected window, look at the\n\
4552 values of `same-window-buffer-names' and `same-window-regexps'.\n\
4553 Those variables take precedence over this one.");
4554 Vspecial_display_regexps
= Qnil
;
4556 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
4557 "Function to call to make a new frame for a special buffer.\n\
4558 It is called with two arguments, the buffer and optional buffer specific\n\
4559 data, and should return a window displaying that buffer.\n\
4560 The default value makes a separate frame for the buffer,\n\
4561 using `special-display-frame-alist' to specify the frame parameters.\n\
4563 A buffer is special if its is listed in `special-display-buffer-names'\n\
4564 or matches a regexp in `special-display-regexps'.");
4565 Vspecial_display_function
= Qnil
;
4567 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
4568 "*List of buffer names that should appear in the selected window.\n\
4569 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'\n\
4570 switches to it in the selected window, rather than making it appear\n\
4571 in some other window.\n\
4573 An element of the list can be a cons cell instead of just a string.\n\
4574 Then the car must be a string, which specifies the buffer name.\n\
4575 This is for compatibility with `special-display-buffer-names';\n\
4576 the cdr of the cons cell is ignored.\n\
4578 See also `same-window-regexps'.");
4579 Vsame_window_buffer_names
= Qnil
;
4581 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
4582 "*List of regexps saying which buffers should appear in the selected window.\n\
4583 If a buffer name matches one of these regexps, then displaying it\n\
4584 using `display-buffer' or `pop-to-buffer' switches to it\n\
4585 in the selected window, rather than making it appear in some other window.\n\
4587 An element of the list can be a cons cell instead of just a string.\n\
4588 Then the car must be a string, which specifies the buffer name.\n\
4589 This is for compatibility with `special-display-buffer-names';\n\
4590 the cdr of the cons cell is ignored.\n\
4592 See also `same-window-buffer-names'.");
4593 Vsame_window_regexps
= Qnil
;
4595 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
4596 "*Non-nil means display-buffer should make new windows.");
4599 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
4600 "*Number of lines of continuity when scrolling by screenfuls.");
4601 next_screen_context_lines
= 2;
4603 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
4604 "*display-buffer would prefer to split the largest window if this large.\n\
4605 If there is only one window, it is split regardless of this value.");
4606 split_height_threshold
= 500;
4608 DEFVAR_INT ("window-min-height", &window_min_height
,
4609 "*Delete any window less than this tall (including its mode line).");
4610 window_min_height
= 4;
4612 DEFVAR_INT ("window-min-width", &window_min_width
,
4613 "*Delete any window less than this wide.");
4614 window_min_width
= 10;
4616 DEFVAR_LISP ("scroll-preserve-screen-position",
4617 &Vscroll_preserve_screen_position
,
4618 "*Nonzero means scroll commands move point to keep its screen line unchanged.");
4619 Vscroll_preserve_screen_position
= Qnil
;
4621 DEFVAR_LISP ("window-configuration-change-hook",
4622 &Vwindow_configuration_change_hook
,
4623 "Functions to call when window configuration changes.\n\
4624 The selected frame is the one whose configuration has changed.");
4625 Vwindow_configuration_change_hook
= Qnil
;
4627 defsubr (&Sselected_window
);
4628 defsubr (&Sminibuffer_window
);
4629 defsubr (&Swindow_minibuffer_p
);
4630 defsubr (&Swindowp
);
4631 defsubr (&Swindow_live_p
);
4632 defsubr (&Spos_visible_in_window_p
);
4633 defsubr (&Swindow_buffer
);
4634 defsubr (&Swindow_height
);
4635 defsubr (&Swindow_width
);
4636 defsubr (&Swindow_hscroll
);
4637 defsubr (&Sset_window_hscroll
);
4638 defsubr (&Swindow_redisplay_end_trigger
);
4639 defsubr (&Sset_window_redisplay_end_trigger
);
4640 defsubr (&Swindow_edges
);
4641 defsubr (&Scoordinates_in_window_p
);
4642 defsubr (&Swindow_at
);
4643 defsubr (&Swindow_point
);
4644 defsubr (&Swindow_start
);
4645 defsubr (&Swindow_end
);
4646 defsubr (&Sset_window_point
);
4647 defsubr (&Sset_window_start
);
4648 defsubr (&Swindow_dedicated_p
);
4649 defsubr (&Sset_window_dedicated_p
);
4650 defsubr (&Swindow_display_table
);
4651 defsubr (&Sset_window_display_table
);
4652 defsubr (&Snext_window
);
4653 defsubr (&Sprevious_window
);
4654 defsubr (&Sother_window
);
4655 defsubr (&Sget_lru_window
);
4656 defsubr (&Sget_largest_window
);
4657 defsubr (&Sget_buffer_window
);
4658 defsubr (&Sdelete_other_windows
);
4659 defsubr (&Sdelete_windows_on
);
4660 defsubr (&Sreplace_buffer_in_windows
);
4661 defsubr (&Sdelete_window
);
4662 defsubr (&Sset_window_buffer
);
4663 defsubr (&Sselect_window
);
4664 defsubr (&Sspecial_display_p
);
4665 defsubr (&Ssame_window_p
);
4666 defsubr (&Sdisplay_buffer
);
4667 defsubr (&Ssplit_window
);
4668 defsubr (&Senlarge_window
);
4669 defsubr (&Sshrink_window
);
4670 defsubr (&Sscroll_up
);
4671 defsubr (&Sscroll_down
);
4672 defsubr (&Sscroll_left
);
4673 defsubr (&Sscroll_right
);
4674 defsubr (&Sother_window_for_scrolling
);
4675 defsubr (&Sscroll_other_window
);
4676 defsubr (&Srecenter
);
4677 defsubr (&Smove_to_window_line
);
4678 defsubr (&Swindow_configuration_p
);
4679 defsubr (&Swindow_configuration_frame
);
4680 defsubr (&Sset_window_configuration
);
4681 defsubr (&Scurrent_window_configuration
);
4682 defsubr (&Ssave_window_excursion
);
4683 defsubr (&Sset_window_margins
);
4684 defsubr (&Swindow_margins
);
4685 defsubr (&Swindow_vscroll
);
4686 defsubr (&Sset_window_vscroll
);
4687 defsubr (&Scompare_window_configurations
);
4693 initial_define_key (control_x_map
, '1', "delete-other-windows");
4694 initial_define_key (control_x_map
, '2', "split-window");
4695 initial_define_key (control_x_map
, '0', "delete-window");
4696 initial_define_key (control_x_map
, 'o', "other-window");
4697 initial_define_key (control_x_map
, '^', "enlarge-window");
4698 initial_define_key (control_x_map
, '<', "scroll-left");
4699 initial_define_key (control_x_map
, '>', "scroll-right");
4701 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
4702 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
4703 initial_define_key (meta_map
, 'v', "scroll-down");
4705 initial_define_key (global_map
, Ctl('L'), "recenter");
4706 initial_define_key (meta_map
, 'r', "move-to-window-line");