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
;
46 Lisp_Object Qfixed_window_size
, Qleft_bitmap_area
, Qright_bitmap_area
;
47 extern Lisp_Object Qheight
, Qwidth
;
49 static struct window
*decode_window
P_ ((Lisp_Object
));
50 static Lisp_Object select_window_1
P_ ((Lisp_Object
, int));
51 static int count_windows
P_ ((struct window
*));
52 static int get_leaf_windows
P_ ((struct window
*, struct window
**, int));
53 static void window_scroll
P_ ((Lisp_Object
, int, int, int));
54 static void window_scroll_pixel_based
P_ ((Lisp_Object
, int, int, int));
55 static void window_scroll_line_based
P_ ((Lisp_Object
, int, int, int));
56 static int window_min_size_1
P_ ((struct window
*, int));
57 static int window_min_size
P_ ((struct window
*, int, int *));
58 static int window_fixed_size_p
P_ ((struct window
*, int, int));
59 static void size_window
P_ ((Lisp_Object
, int, int, int));
62 /* This is the window in which the terminal's cursor should
63 be left when nothing is being done with it. This must
64 always be a leaf window, and its buffer is selected by
65 the top level editing loop at the end of each command.
67 This value is always the same as
68 FRAME_SELECTED_WINDOW (selected_frame). */
70 Lisp_Object selected_window
;
72 /* The mini-buffer window of the selected frame.
73 Note that you cannot test for mini-bufferness of an arbitrary window
74 by comparing against this; but you can test for mini-bufferness of
75 the selected window. */
77 Lisp_Object minibuf_window
;
79 /* Non-nil means it is the window for C-M-v to scroll
80 when the mini-buffer is selected. */
82 Lisp_Object Vminibuf_scroll_window
;
84 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
86 Lisp_Object Vother_window_scroll_buffer
;
88 /* Non-nil means it's function to call to display temp buffers. */
90 Lisp_Object Vtemp_buffer_show_function
;
92 /* If a window gets smaller than either of these, it is removed. */
94 int window_min_height
;
97 /* Nonzero implies Fdisplay_buffer should create windows. */
101 /* Nonzero implies make new frames for Fdisplay_buffer. */
105 /* Non-nil means use this function instead of default */
107 Lisp_Object Vpop_up_frame_function
;
109 /* Function to call to handle Fdisplay_buffer. */
111 Lisp_Object Vdisplay_buffer_function
;
113 /* List of buffer *names* for buffers that should have their own frames. */
115 Lisp_Object Vspecial_display_buffer_names
;
117 /* List of regexps for buffer names that should have their own frames. */
119 Lisp_Object Vspecial_display_regexps
;
121 /* Function to pop up a special frame. */
123 Lisp_Object Vspecial_display_function
;
125 /* List of buffer *names* for buffers to appear in selected window. */
127 Lisp_Object Vsame_window_buffer_names
;
129 /* List of regexps for buffer names to appear in selected window. */
131 Lisp_Object Vsame_window_regexps
;
133 /* Hook run at end of temp_output_buffer_show. */
135 Lisp_Object Qtemp_buffer_show_hook
;
137 /* Fdisplay_buffer always splits the largest window
138 if that window is more than this high. */
140 int split_height_threshold
;
142 /* Number of lines of continuity in scrolling by screenfuls. */
144 int next_screen_context_lines
;
146 /* Incremented for each window created. */
148 static int sequence_number
;
150 /* Nonzero after init_window_once has finished. */
152 static int window_initialized
;
154 /* Hook to run when window config changes. */
156 Lisp_Object Qwindow_configuration_change_hook
;
157 Lisp_Object Vwindow_configuration_change_hook
;
159 /* Nonzero means scroll commands try to put point
160 at the same screen height as previously. */
162 Lisp_Object Vscroll_preserve_screen_position
;
164 #if 0 /* This isn't used anywhere. */
165 /* Nonzero means we can split a frame even if it is "unsplittable". */
166 static int inhibit_frame_unsplittable
;
169 #define min(a, b) ((a) < (b) ? (a) : (b))
171 extern int scroll_margin
;
173 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
175 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
176 "Returns t if OBJECT is a window.")
180 return WINDOWP (object
) ? Qt
: Qnil
;
183 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
184 "Returns t if OBJECT is a window which is currently visible.")
188 return (WINDOWP (object
) && ! NILP (XWINDOW (object
)->buffer
) ? Qt
: Qnil
);
195 register struct window
*p
;
196 register struct Lisp_Vector
*vec
;
199 vec
= allocate_vectorlike ((EMACS_INT
) VECSIZE (struct window
));
200 for (i
= 0; i
< VECSIZE (struct window
); i
++)
201 vec
->contents
[i
] = Qnil
;
202 vec
->size
= VECSIZE (struct window
);
203 p
= (struct window
*) vec
;
204 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
205 XSETFASTINT (p
->left
, 0);
206 XSETFASTINT (p
->top
, 0);
207 XSETFASTINT (p
->height
, 0);
208 XSETFASTINT (p
->width
, 0);
209 XSETFASTINT (p
->hscroll
, 0);
210 p
->start
= Fmake_marker ();
211 p
->pointm
= Fmake_marker ();
212 XSETFASTINT (p
->use_time
, 0);
214 p
->display_table
= Qnil
;
216 p
->pseudo_window_p
= 0;
217 bzero (&p
->cursor
, sizeof (p
->cursor
));
218 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
219 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
220 p
->desired_matrix
= p
->current_matrix
= 0;
221 p
->phys_cursor_type
= -1;
222 p
->must_be_updated_p
= 0;
223 XSETFASTINT (p
->window_end_vpos
, 0);
224 XSETFASTINT (p
->window_end_pos
, 0);
225 p
->window_end_valid
= Qnil
;
228 XSETFASTINT (p
->last_point
, 0);
232 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
233 "Return the window that the cursor now appears in and commands apply to.")
236 return selected_window
;
239 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
240 "Return the window used now for minibuffers.\n\
241 If the optional argument FRAME is specified, return the minibuffer window\n\
242 used by that frame.")
247 XSETFRAME (frame
, selected_frame
);
249 CHECK_LIVE_FRAME (frame
, 0);
251 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
254 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
255 "Returns non-nil if WINDOW is a minibuffer window.")
259 struct window
*w
= decode_window (window
);
260 return (MINI_WINDOW_P (w
) ? Qt
: Qnil
);
263 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
264 Spos_visible_in_window_p
, 0, 2, 0,
265 "Return t if position POS is currently on the frame in WINDOW.\n\
266 Returns nil if that position is scrolled vertically out of view.\n\
267 POS defaults to point; WINDOW, to the selected window.")
269 Lisp_Object pos
, window
;
271 register struct window
*w
;
273 register struct buffer
*buf
;
275 Lisp_Object in_window
;
281 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
285 w
= decode_window (window
);
286 buf
= XBUFFER (w
->buffer
);
287 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
289 /* If position above window, it's not visible. */
290 if (posint
< CHARPOS (top
))
292 else if (XFASTINT (w
->last_modified
) >= BUF_MODIFF (buf
)
293 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (buf
)
294 && posint
< BUF_Z (buf
) - XFASTINT (w
->window_end_pos
))
295 /* If frame is up to date, and POSINT is < window end pos, use
296 that info. This doesn't work for POSINT == end pos, because
297 the window end pos is actually the position _after_ the last
298 char in the window. */
300 else if (posint
> BUF_ZV (buf
))
302 else if (CHARPOS (top
) < BUF_BEGV (buf
) || CHARPOS (top
) > BUF_ZV (buf
))
303 /* If window start is out of range, do something reasonable. */
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 in_window
= IT_CHARPOS (it
) == posint
? Qt
: Qnil
;
317 static struct window
*
318 decode_window (window
)
319 register Lisp_Object window
;
322 return XWINDOW (selected_window
);
324 CHECK_LIVE_WINDOW (window
, 0);
325 return XWINDOW (window
);
328 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
329 "Return the buffer that WINDOW is displaying.")
333 return decode_window (window
)->buffer
;
336 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
337 "Return the number of lines in WINDOW (including its mode line).")
341 return decode_window (window
)->height
;
344 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
345 "Return the number of display columns in WINDOW.\n\
346 This is the width that is usable columns available for text in WINDOW.\n\
347 If you want to find out how many columns WINDOW takes up,\n\
348 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))).")
352 return make_number (window_internal_width (decode_window (window
)));
355 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
356 "Return the number of columns by which WINDOW is scrolled from left margin.")
360 return decode_window (window
)->hscroll
;
363 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
364 "Set number of columns WINDOW is scrolled from left margin to NCOL.\n\
365 NCOL should be zero or positive.")
367 register Lisp_Object window
, ncol
;
369 register struct window
*w
;
371 CHECK_NUMBER (ncol
, 1);
372 if (XINT (ncol
) < 0) XSETFASTINT (ncol
, 0);
373 w
= decode_window (window
);
374 if (XINT (w
->hscroll
) != XINT (ncol
))
375 XBUFFER (w
->buffer
)->clip_changed
= 1; /* Prevent redisplay shortcuts */
380 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
381 Swindow_redisplay_end_trigger
, 0, 1, 0,
382 "Return WINDOW's redisplay end trigger value.\n\
383 See `set-window-redisplay-end-trigger' for more information.")
387 return decode_window (window
)->redisplay_end_trigger
;
390 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
391 Sset_window_redisplay_end_trigger
, 2, 2, 0,
392 "Set WINDOW's redisplay end trigger value to VALUE.\n\
393 VALUE should be a buffer position (typically a marker) or nil.\n\
394 If it is a buffer position, then if redisplay in WINDOW reaches a position\n\
395 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called\n\
396 with two arguments: WINDOW, and the end trigger value.\n\
397 Afterwards the end-trigger value is reset to nil.")
399 register Lisp_Object window
, value
;
401 register struct window
*w
;
403 w
= decode_window (window
);
404 w
->redisplay_end_trigger
= value
;
408 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
409 "Return a list of the edge coordinates of WINDOW.\n\
410 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.\n\
411 RIGHT is one more than the rightmost column used by WINDOW,\n\
412 and BOTTOM is one more than the bottommost row used by WINDOW\n\
417 register struct window
*w
= decode_window (window
);
419 return Fcons (w
->left
, Fcons (w
->top
,
420 Fcons (make_number (WINDOW_RIGHT_EDGE (w
)),
421 Fcons (make_number (XFASTINT (w
->top
)
422 + XFASTINT (w
->height
)),
426 /* Test if the character at column *X, row *Y is within window W.
427 If it is not, return 0;
428 if it is in the window's text area,
429 set *x and *y to its location relative to the upper left corner
432 if it is on the window's modeline, return 2;
433 if it is on the border between the window and its right sibling,
435 if it is on the window's top line, return 4;
436 if it is in the bitmap area to the left/right of the window,
437 return 5 or 6, and convert *X and *Y to window-relative corrdinates.
439 X and Y are frame relative pixel coordinates. */
442 coordinates_in_window (w
, x
, y
)
443 register struct window
*w
;
446 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
447 int left_x
, right_x
, top_y
, bottom_y
;
448 int flags_area_width
= FRAME_FLAGS_AREA_WIDTH (f
);
450 if (w
->pseudo_window_p
)
453 right_x
= XFASTINT (w
->width
) * CANON_Y_UNIT (f
);
454 top_y
= WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
);
455 bottom_y
= WINDOW_DISPLAY_BOTTOM_EDGE_PIXEL_Y (w
);
459 left_x
= WINDOW_DISPLAY_LEFT_EDGE_PIXEL_X (w
);
460 right_x
= WINDOW_DISPLAY_RIGHT_EDGE_PIXEL_X (w
);
461 top_y
= WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
);
462 bottom_y
= WINDOW_DISPLAY_BOTTOM_EDGE_PIXEL_Y (w
);
469 - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
)
471 || *x
> right_x
+ flags_area_width
)
472 /* Completely outside anything interesting. */
474 else if (WINDOW_WANTS_MODELINE_P (w
)
475 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
476 /* On the mode line. */
478 else if (WINDOW_WANTS_TOP_LINE_P (w
)
479 && *y
< top_y
+ CURRENT_TOP_LINE_HEIGHT (w
))
480 /* On the top line. */
482 else if (*x
< left_x
|| *x
>= right_x
)
484 /* Other lines than the mode line don't include flags areas and
485 scroll bars on the left. */
487 /* Convert X and Y to window-relative pixel coordinates. */
490 return *x
< left_x
? 5 : 6;
492 else if (!w
->pseudo_window_p
493 && !WINDOW_RIGHTMOST_P (w
)
494 && *x
>= right_x
- CANON_X_UNIT (f
))
495 /* On the border on the right side of the window? Assume that
496 this area begins at RIGHT_X minus a canonical char width. */
500 /* Convert X and Y to window-relative pixel coordinates. */
507 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
508 Scoordinates_in_window_p
, 2, 2, 0,
509 "Return non-nil if COORDINATES are in WINDOW.\n\
510 COORDINATES is a cons of the form (X . Y), X and Y being distances\n\
511 measured in characters from the upper-left corner of the frame.\n\
512 (0 . 0) denotes the character in the upper left corner of the\n\
514 If COORDINATES are in the text portion of WINDOW,\n\
515 the coordinates relative to the window are returned.\n\
516 If they are in the mode line of WINDOW, `mode-line' is returned.\n\
517 If they are in the top mode line of WINDOW, `top-line' is returned.\n\
518 If they are in the bitmap-area to the left of the window,\n\
519 `left-bitmap-area' is returned, if they are in the area on the right of\n\
520 the window, `right-bitmap-area' is returned.\n\
521 If they are on the border between WINDOW and its right sibling,\n\
522 `vertical-line' is returned.")
523 (coordinates
, window
)
524 register Lisp_Object coordinates
, window
;
531 CHECK_LIVE_WINDOW (window
, 0);
532 w
= XWINDOW (window
);
533 f
= XFRAME (w
->frame
);
534 CHECK_CONS (coordinates
, 1);
535 lx
= Fcar (coordinates
);
536 ly
= Fcdr (coordinates
);
537 CHECK_NUMBER_OR_FLOAT (lx
, 1);
538 CHECK_NUMBER_OR_FLOAT (ly
, 1);
539 x
= PIXEL_X_FROM_CANON_X (f
, lx
);
540 y
= PIXEL_Y_FROM_CANON_Y (f
, ly
);
542 switch (coordinates_in_window (w
, &x
, &y
))
544 case 0: /* NOT in window at all. */
547 case 1: /* In text part of window. */
548 /* X and Y are now window relative pixel coordinates.
549 Convert them to canonical char units before returning
551 return Fcons (CANON_X_FROM_PIXEL_X (f
, x
),
552 CANON_Y_FROM_PIXEL_Y (f
, y
));
554 case 2: /* In mode line of window. */
557 case 3: /* On right border of window. */
558 return Qvertical_line
;
564 return Qleft_bitmap_area
;
567 return Qright_bitmap_area
;
574 /* Find the window containing frame-relative pixel position X/Y and
575 return it as a Lisp_Object. If X, Y is on the window's modeline,
576 set *PART to 1; if it is on the separating line between the window
577 and its right sibling, set it to 2; otherwise set it to 0. If
578 there is no window under X, Y return nil and leave *PART
579 unmodified. TOOLBAR_P non-zero means detect toolbar windows. */
582 window_from_coordinates (frame
, x
, y
, part
, toolbar_p
)
588 register Lisp_Object tem
, first
;
591 tem
= first
= FRAME_SELECTED_WINDOW (frame
);
595 found
= coordinates_in_window (XWINDOW (tem
), &x
, &y
);
603 tem
= Fnext_window (tem
, Qt
, Qlambda
);
605 while (!EQ (tem
, first
));
607 /* See if it's in the toolbar window, if a toolbar exists. */
609 && WINDOWP (frame
->toolbar_window
)
610 && XFASTINT (XWINDOW (frame
->toolbar_window
)->height
)
611 && coordinates_in_window (XWINDOW (frame
->toolbar_window
), &x
, &y
))
614 return frame
->toolbar_window
;
620 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
621 "Return window containing coordinates X and Y on FRAME.\n\
622 If omitted, FRAME defaults to the currently selected frame.\n\
623 The top left corner of the frame is considered to be row 0,\n\
626 Lisp_Object x
, y
, frame
;
632 XSETFRAME (frame
, selected_frame
);
634 CHECK_LIVE_FRAME (frame
, 2);
637 /* Check that arguments are integers or floats. */
638 CHECK_NUMBER_OR_FLOAT (x
, 0);
639 CHECK_NUMBER_OR_FLOAT (y
, 1);
641 return window_from_coordinates (f
,
642 PIXEL_X_FROM_CANON_X (f
, x
),
643 PIXEL_Y_FROM_CANON_Y (f
, y
),
647 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
648 "Return current value of point in WINDOW.\n\
649 For a nonselected window, this is the value point would have\n\
650 if that window were selected.\n\
652 Note that, when WINDOW is the selected window and its buffer\n\
653 is also currently selected, the value returned is the same as (point).\n\
654 It would be more strictly correct to return the `top-level' value\n\
655 of point, outside of any save-excursion forms.\n\
656 But that is hard to define.")
660 register struct window
*w
= decode_window (window
);
662 if (w
== XWINDOW (selected_window
)
663 && current_buffer
== XBUFFER (w
->buffer
))
665 return Fmarker_position (w
->pointm
);
668 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
669 "Return position at which display currently starts in WINDOW.\n\
670 This is updated by redisplay or by calling `set-window-start'.")
674 return Fmarker_position (decode_window (window
)->start
);
677 /* This is text temporarily removed from the doc string below.
679 This function returns nil if the position is not currently known.\n\
680 That happens when redisplay is preempted and doesn't finish.\n\
681 If in that case you want to compute where the end of the window would\n\
682 have been if redisplay had finished, do this:\n\
684 (goto-char (window-start window))\n\
685 (vertical-motion (1- (window-height window)) window)\n\
688 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
689 "Return position at which display currently ends in WINDOW.\n\
690 This is updated by redisplay, when it runs to completion.\n\
691 Simply changing the buffer text or setting `window-start'\n\
692 does not update this value.\n\
693 If UP-TO-DATE is non-nil, compute the up-to-date position\n\
694 if it isn't already recorded.")
696 Lisp_Object window
, update
;
699 struct window
*w
= decode_window (window
);
703 CHECK_BUFFER (buf
, 0);
705 #if 0 /* This change broke some things. We should make it later. */
706 /* If we don't know the end position, return nil.
707 The user can compute it with vertical-motion if he wants to.
708 It would be nicer to do it automatically,
709 but that's so slow that it would probably bother people. */
710 if (NILP (w
->window_end_valid
))
715 && ! (! NILP (w
->window_end_valid
)
716 && XFASTINT (w
->last_modified
) >= MODIFF
))
718 int opoint
= PT
, opoint_byte
= PT_BYTE
;
719 TEMP_SET_PT_BOTH (XMARKER (w
->start
)->charpos
,
720 XMARKER (w
->start
)->bytepos
);
721 Fvertical_motion (make_number (window_internal_height (w
)), Qnil
);
723 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
727 BUF_Z (XBUFFER (buf
)) - XFASTINT (w
->window_end_pos
));
732 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
733 "Make point value in WINDOW be at position POS in WINDOW's buffer.")
735 Lisp_Object window
, pos
;
737 register struct window
*w
= decode_window (window
);
739 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
740 if (w
== XWINDOW (selected_window
)
741 && XBUFFER (w
->buffer
) == current_buffer
)
744 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
749 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
750 "Make display in WINDOW start at position POS in WINDOW's buffer.\n\
751 Optional third arg NOFORCE non-nil inhibits next redisplay\n\
752 from overriding motion of point in order to display at this exact start.")
753 (window
, pos
, noforce
)
754 Lisp_Object window
, pos
, noforce
;
756 register struct window
*w
= decode_window (window
);
758 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
759 set_marker_restricted (w
->start
, pos
, w
->buffer
);
760 /* this is not right, but much easier than doing what is right. */
761 w
->start_at_line_beg
= Qnil
;
764 w
->update_mode_line
= Qt
;
765 XSETFASTINT (w
->last_modified
, 0);
766 XSETFASTINT (w
->last_overlay_modified
, 0);
767 if (!EQ (window
, selected_window
))
768 windows_or_buffers_changed
++;
772 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
774 "Return WINDOW's dedicated object, usually t or nil.\n\
775 See also `set-window-dedicated-p'.")
779 return decode_window (window
)->dedicated
;
782 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
783 Sset_window_dedicated_p
, 2, 2, 0,
784 "Control whether WINDOW is dedicated to the buffer it displays.\n\
785 If it is dedicated, Emacs will not automatically change\n\
786 which buffer appears in it.\n\
787 The second argument is the new value for the dedication flag;\n\
790 Lisp_Object window
, arg
;
792 register struct window
*w
= decode_window (window
);
802 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
804 "Return the display-table that WINDOW is using.")
808 return decode_window (window
)->display_table
;
811 /* Get the display table for use on window W. This is either W's
812 display table or W's buffer's display table. Ignore the specified
813 tables if they are not valid; if no valid table is specified,
816 struct Lisp_Char_Table
*
817 window_display_table (w
)
821 tem
= w
->display_table
;
822 if (DISP_TABLE_P (tem
))
823 return XCHAR_TABLE (tem
);
824 if (NILP (w
->buffer
))
827 tem
= XBUFFER (w
->buffer
)->display_table
;
828 if (DISP_TABLE_P (tem
))
829 return XCHAR_TABLE (tem
);
830 tem
= Vstandard_display_table
;
831 if (DISP_TABLE_P (tem
))
832 return XCHAR_TABLE (tem
);
836 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
837 "Set WINDOW's display-table to TABLE.")
839 register Lisp_Object window
, table
;
841 register struct window
*w
;
843 w
= decode_window (window
);
844 w
->display_table
= table
;
848 /* Record info on buffer window w is displaying
849 when it is about to cease to display that buffer. */
852 register struct window
*w
;
859 if (b
!= XMARKER (w
->pointm
)->buffer
)
862 if (w
== XWINDOW (b
->last_selected_window
))
863 b
->last_selected_window
= Qnil
;
866 if (w
== XWINDOW (selected_window
)
867 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
868 /* Do this except when the selected window's buffer
869 is being removed from some other window. */
871 /* last_window_start records the start position that this buffer
872 had in the last window to be disconnected from it.
873 Now that this statement is unconditional,
874 it is possible for the buffer to be displayed in the
875 selected window, while last_window_start reflects another
876 window which was recently showing the same buffer.
877 Some people might say that might be a good thing. Let's see. */
878 b
->last_window_start
= marker_position (w
->start
);
880 /* Point in the selected window's buffer
881 is actually stored in that buffer, and the window's pointm isn't used.
882 So don't clobber point in that buffer. */
883 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
))
884 temp_set_point_both (b
,
885 clip_to_bounds (BUF_BEGV (b
),
886 XMARKER (w
->pointm
)->charpos
,
888 clip_to_bounds (BUF_BEGV_BYTE (b
),
889 marker_byte_position (w
->pointm
),
893 /* Put replacement into the window structure in place of old. */
895 replace_window (old
, replacement
)
896 Lisp_Object old
, replacement
;
898 register Lisp_Object tem
;
899 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
901 /* If OLD is its frame's root_window, then replacement is the new
902 root_window for that frame. */
904 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
905 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
910 p
->height
= o
->height
;
911 p
->desired_matrix
= p
->current_matrix
= 0;
913 bzero (&p
->cursor
, sizeof (p
->cursor
));
914 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
915 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
916 p
->phys_cursor_type
= -1;
917 p
->must_be_updated_p
= 0;
918 p
->pseudo_window_p
= 0;
919 XSETFASTINT (p
->window_end_vpos
, 0);
920 XSETFASTINT (p
->window_end_pos
, 0);
921 p
->window_end_valid
= Qnil
;
923 p
->next
= tem
= o
->next
;
925 XWINDOW (tem
)->prev
= replacement
;
927 p
->prev
= tem
= o
->prev
;
929 XWINDOW (tem
)->next
= replacement
;
931 p
->parent
= tem
= o
->parent
;
934 if (EQ (XWINDOW (tem
)->vchild
, old
))
935 XWINDOW (tem
)->vchild
= replacement
;
936 if (EQ (XWINDOW (tem
)->hchild
, old
))
937 XWINDOW (tem
)->hchild
= replacement
;
940 /*** Here, if replacement is a vertical combination
941 and so is its new parent, we should make replacement's
942 children be children of that parent instead. ***/
945 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
946 "Remove WINDOW from the display. Default is selected window.")
948 register Lisp_Object window
;
950 delete_window (window
);
952 if (! NILP (Vwindow_configuration_change_hook
)
953 && ! NILP (Vrun_hooks
))
954 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
960 delete_window (window
)
961 register Lisp_Object window
;
963 register Lisp_Object tem
, parent
, sib
;
964 register struct window
*p
;
965 register struct window
*par
;
968 /* Because this function is called by other C code on non-leaf
969 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
970 so we can't decode_window here. */
972 window
= selected_window
;
974 CHECK_WINDOW (window
, 0);
975 p
= XWINDOW (window
);
977 /* It's okay to delete an already-deleted window. */
985 error ("Attempt to delete minibuffer or sole ordinary window");
986 par
= XWINDOW (parent
);
988 windows_or_buffers_changed
++;
989 frame
= XFRAME (WINDOW_FRAME (p
));
990 FRAME_WINDOW_SIZES_CHANGED (frame
) = 1;
992 /* Are we trying to delete any frame's selected window? */
994 Lisp_Object frame
, pwindow
;
996 /* See if the frame's selected window is either WINDOW
997 or any subwindow of it, by finding all that window's parents
998 and comparing each one with WINDOW. */
999 frame
= WINDOW_FRAME (XWINDOW (window
));
1000 pwindow
= FRAME_SELECTED_WINDOW (XFRAME (frame
));
1002 while (!NILP (pwindow
))
1004 if (EQ (window
, pwindow
))
1006 pwindow
= XWINDOW (pwindow
)->parent
;
1009 if (EQ (window
, pwindow
))
1011 Lisp_Object alternative
;
1012 alternative
= Fnext_window (window
, Qlambda
, Qnil
);
1014 /* If we're about to delete the selected window on the
1015 selected frame, then we should use Fselect_window to select
1016 the new window. On the other hand, if we're about to
1017 delete the selected window on any other frame, we shouldn't do
1018 anything but set the frame's selected_window slot. */
1019 if (EQ (window
, selected_window
))
1020 Fselect_window (alternative
);
1022 FRAME_SELECTED_WINDOW (XFRAME (frame
)) = alternative
;
1027 /* tem is null for dummy parent windows
1028 (which have inferiors but not any contents themselves) */
1032 unchain_marker (p
->pointm
);
1033 unchain_marker (p
->start
);
1036 /* Free window glyph matrices.
1037 It is sure that they are allocated again when ADJUST_GLYPHS
1039 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (frame
)));
1043 XWINDOW (tem
)->prev
= p
->prev
;
1047 XWINDOW (tem
)->next
= p
->next
;
1049 if (EQ (window
, par
->hchild
))
1050 par
->hchild
= p
->next
;
1051 if (EQ (window
, par
->vchild
))
1052 par
->vchild
= p
->next
;
1054 /* Find one of our siblings to give our space to. */
1058 /* If p gives its space to its next sibling, that sibling needs
1059 to have its top/left side pulled back to where p's is.
1060 set_window_{height,width} will re-position the sibling's
1063 XWINDOW (sib
)->top
= p
->top
;
1064 XWINDOW (sib
)->left
= p
->left
;
1067 /* Stretch that sibling. */
1068 if (!NILP (par
->vchild
))
1069 set_window_height (sib
,
1070 XFASTINT (XWINDOW (sib
)->height
) + XFASTINT (p
->height
),
1072 if (!NILP (par
->hchild
))
1073 set_window_width (sib
,
1074 XFASTINT (XWINDOW (sib
)->width
) + XFASTINT (p
->width
),
1077 /* If parent now has only one child,
1078 put the child into the parent's place. */
1082 if (NILP (XWINDOW (tem
)->next
))
1083 replace_window (parent
, tem
);
1085 /* Since we may be deleting combination windows, we must make sure that
1086 not only p but all its children have been marked as deleted. */
1087 if (! NILP (p
->hchild
))
1088 delete_all_subwindows (XWINDOW (p
->hchild
));
1089 else if (! NILP (p
->vchild
))
1090 delete_all_subwindows (XWINDOW (p
->vchild
));
1092 /* Mark this window as deleted. */
1093 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1095 /* Adjust glyph matrices. */
1096 adjust_glyphs (frame
);
1100 extern Lisp_Object
next_frame (), prev_frame ();
1102 /* This comment supplies the doc string for `next-window',
1103 for make-docfile to see. We cannot put this in the real DEFUN
1104 due to limits in the Unix cpp.
1106 DEFUN ("next-window", Ffoo, Sfoo, 0, 3, 0,
1107 "Return next window after WINDOW in canonical ordering of windows.\n\
1108 If omitted, WINDOW defaults to the selected window.\n\
1110 Optional second arg MINIBUF t means count the minibuffer window even\n\
1111 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1112 it is active. MINIBUF neither t nor nil means not to count the\n\
1113 minibuffer even if it is active.\n\
1115 Several frames may share a single minibuffer; if the minibuffer\n\
1116 counts, all windows on all frames that share that minibuffer count\n\
1117 too. Therefore, `next-window' can be used to iterate through the\n\
1118 set of windows even when the minibuffer is on another frame. If the\n\
1119 minibuffer does not count, only windows from WINDOW's frame count.\n\
1121 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1122 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1123 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1124 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1125 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1126 Anything else means restrict to WINDOW's frame.\n\
1128 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1129 `next-window' to iterate through the entire cycle of acceptable\n\
1130 windows, eventually ending up back at the window you started with.\n\
1131 `previous-window' traverses the same cycle, in the reverse order.")
1132 (window, minibuf, all_frames) */
1134 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
1136 (window
, minibuf
, all_frames
)
1137 register Lisp_Object window
, minibuf
, all_frames
;
1139 register Lisp_Object tem
;
1140 Lisp_Object start_window
;
1143 window
= selected_window
;
1145 CHECK_LIVE_WINDOW (window
, 0);
1147 start_window
= window
;
1149 /* minibuf == nil may or may not include minibuffers.
1150 Decide if it does. */
1152 minibuf
= (minibuf_level
? minibuf_window
: Qlambda
);
1153 else if (! EQ (minibuf
, Qt
))
1155 /* Now minibuf can be t => count all minibuffer windows,
1156 lambda => count none of them,
1157 or a specific minibuffer window (the active one) to count. */
1159 /* all_frames == nil doesn't specify which frames to include. */
1160 if (NILP (all_frames
))
1161 all_frames
= (! EQ (minibuf
, Qlambda
)
1162 ? (FRAME_MINIBUF_WINDOW
1165 (XWINDOW (window
)))))
1167 else if (EQ (all_frames
, Qvisible
))
1169 else if (XFASTINT (all_frames
) == 0)
1171 else if (FRAMEP (all_frames
) && ! EQ (all_frames
, Fwindow_frame (window
)))
1172 /* If all_frames is a frame and window arg isn't on that frame, just
1173 return the first window on the frame. */
1174 return Fframe_first_window (all_frames
);
1175 else if (! EQ (all_frames
, Qt
))
1177 /* Now all_frames is t meaning search all frames,
1178 nil meaning search just current frame,
1179 visible meaning search just visible frames,
1180 0 meaning search visible and iconified frames,
1181 or a window, meaning search the frame that window belongs to. */
1183 /* Do this loop at least once, to get the next window, and perhaps
1184 again, if we hit the minibuffer and that is not acceptable. */
1187 /* Find a window that actually has a next one. This loop
1188 climbs up the tree. */
1189 while (tem
= XWINDOW (window
)->next
, NILP (tem
))
1190 if (tem
= XWINDOW (window
)->parent
, !NILP (tem
))
1194 /* We've reached the end of this frame.
1195 Which other frames are acceptable? */
1196 tem
= WINDOW_FRAME (XWINDOW (window
));
1197 if (! NILP (all_frames
))
1202 tem
= next_frame (tem
, all_frames
);
1203 /* In the case where the minibuffer is active,
1204 and we include its frame as well as the selected one,
1205 next_frame may get stuck in that frame.
1206 If that happens, go back to the selected frame
1207 so we can complete the cycle. */
1209 XSETFRAME (tem
, selected_frame
);
1211 tem
= FRAME_ROOT_WINDOW (XFRAME (tem
));
1218 /* If we're in a combination window, find its first child and
1219 recurse on that. Otherwise, we've found the window we want. */
1222 if (!NILP (XWINDOW (window
)->hchild
))
1223 window
= XWINDOW (window
)->hchild
;
1224 else if (!NILP (XWINDOW (window
)->vchild
))
1225 window
= XWINDOW (window
)->vchild
;
1229 /* Which windows are acceptable?
1230 Exit the loop and accept this window if
1231 this isn't a minibuffer window,
1232 or we're accepting all minibuffer windows,
1233 or this is the active minibuffer and we are accepting that one, or
1234 we've come all the way around and we're back at the original window. */
1235 while (MINI_WINDOW_P (XWINDOW (window
))
1236 && ! EQ (minibuf
, Qt
)
1237 && ! EQ (minibuf
, window
)
1238 && ! EQ (window
, start_window
));
1243 /* This comment supplies the doc string for `previous-window',
1244 for make-docfile to see. We cannot put this in the real DEFUN
1245 due to limits in the Unix cpp.
1247 DEFUN ("previous-window", Ffoo, Sfoo, 0, 3, 0,
1248 "Return the window preceding WINDOW in canonical ordering of windows.\n\
1249 If omitted, WINDOW defaults to the selected window.\n\
1251 Optional second arg MINIBUF t means count the minibuffer window even\n\
1252 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1253 it is active. MINIBUF neither t nor nil means not to count the\n\
1254 minibuffer even if it is active.\n\
1256 Several frames may share a single minibuffer; if the minibuffer\n\
1257 counts, all windows on all frames that share that minibuffer count\n\
1258 too. Therefore, `previous-window' can be used to iterate through\n\
1259 the set of windows even when the minibuffer is on another frame. If\n\
1260 the minibuffer does not count, only windows from WINDOW's frame count\n\
1262 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1263 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1264 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1265 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1266 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1267 Anything else means restrict to WINDOW's frame.\n\
1269 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1270 `previous-window' to iterate through the entire cycle of acceptable\n\
1271 windows, eventually ending up back at the window you started with.\n\
1272 `next-window' traverses the same cycle, in the reverse order.")
1273 (window, minibuf, all_frames) */
1276 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1278 (window
, minibuf
, all_frames
)
1279 register Lisp_Object window
, minibuf
, all_frames
;
1281 register Lisp_Object tem
;
1282 Lisp_Object start_window
;
1285 window
= selected_window
;
1287 CHECK_LIVE_WINDOW (window
, 0);
1289 start_window
= window
;
1291 /* minibuf == nil may or may not include minibuffers.
1292 Decide if it does. */
1294 minibuf
= (minibuf_level
? minibuf_window
: Qlambda
);
1295 else if (! EQ (minibuf
, Qt
))
1297 /* Now minibuf can be t => count all minibuffer windows,
1298 lambda => count none of them,
1299 or a specific minibuffer window (the active one) to count. */
1301 /* all_frames == nil doesn't specify which frames to include.
1302 Decide which frames it includes. */
1303 if (NILP (all_frames
))
1304 all_frames
= (! EQ (minibuf
, Qlambda
)
1305 ? (FRAME_MINIBUF_WINDOW
1308 (XWINDOW (window
)))))
1310 else if (EQ (all_frames
, Qvisible
))
1312 else if (XFASTINT (all_frames
) == 0)
1314 else if (FRAMEP (all_frames
) && ! EQ (all_frames
, Fwindow_frame (window
)))
1315 /* If all_frames is a frame and window arg isn't on that frame, just
1316 return the first window on the frame. */
1317 return Fframe_first_window (all_frames
);
1318 else if (! EQ (all_frames
, Qt
))
1320 /* Now all_frames is t meaning search all frames,
1321 nil meaning search just current frame,
1322 visible meaning search just visible frames,
1323 0 meaning search visible and iconified frames,
1324 or a window, meaning search the frame that window belongs to. */
1326 /* Do this loop at least once, to get the previous window, and perhaps
1327 again, if we hit the minibuffer and that is not acceptable. */
1330 /* Find a window that actually has a previous one. This loop
1331 climbs up the tree. */
1332 while (tem
= XWINDOW (window
)->prev
, NILP (tem
))
1333 if (tem
= XWINDOW (window
)->parent
, !NILP (tem
))
1337 /* We have found the top window on the frame.
1338 Which frames are acceptable? */
1339 tem
= WINDOW_FRAME (XWINDOW (window
));
1340 if (! NILP (all_frames
))
1341 /* It's actually important that we use prev_frame here,
1342 rather than next_frame. All the windows acceptable
1343 according to the given parameters should form a ring;
1344 Fnext_window and Fprevious_window should go back and
1345 forth around the ring. If we use next_frame here,
1346 then Fnext_window and Fprevious_window take different
1347 paths through the set of acceptable windows.
1348 window_loop assumes that these `ring' requirement are
1354 tem
= prev_frame (tem
, all_frames
);
1355 /* In the case where the minibuffer is active,
1356 and we include its frame as well as the selected one,
1357 next_frame may get stuck in that frame.
1358 If that happens, go back to the selected frame
1359 so we can complete the cycle. */
1361 XSETFRAME (tem
, selected_frame
);
1363 /* If this frame has a minibuffer, find that window first,
1364 because it is conceptually the last window in that frame. */
1365 if (FRAME_HAS_MINIBUF_P (XFRAME (tem
)))
1366 tem
= FRAME_MINIBUF_WINDOW (XFRAME (tem
));
1368 tem
= FRAME_ROOT_WINDOW (XFRAME (tem
));
1374 /* If we're in a combination window, find its last child and
1375 recurse on that. Otherwise, we've found the window we want. */
1378 if (!NILP (XWINDOW (window
)->hchild
))
1379 window
= XWINDOW (window
)->hchild
;
1380 else if (!NILP (XWINDOW (window
)->vchild
))
1381 window
= XWINDOW (window
)->vchild
;
1383 while (tem
= XWINDOW (window
)->next
, !NILP (tem
))
1387 /* Which windows are acceptable?
1388 Exit the loop and accept this window if
1389 this isn't a minibuffer window,
1390 or we're accepting all minibuffer windows,
1391 or this is the active minibuffer and we are accepting that one, or
1392 we've come all the way around and we're back at the original window. */
1393 while (MINI_WINDOW_P (XWINDOW (window
))
1394 && ! EQ (minibuf
, Qt
)
1395 && ! EQ (minibuf
, window
)
1396 && ! EQ (window
, start_window
));
1401 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1402 "Select the ARG'th different window on this frame.\n\
1403 All windows on current frame are arranged in a cyclic order.\n\
1404 This command selects the window ARG steps away in that order.\n\
1405 A negative ARG moves in the opposite order. If the optional second\n\
1406 argument ALL_FRAMES is non-nil, cycle through all frames.")
1408 register Lisp_Object arg
, all_frames
;
1411 register Lisp_Object w
;
1413 CHECK_NUMBER (arg
, 0);
1414 w
= selected_window
;
1419 w
= Fnext_window (w
, Qnil
, all_frames
);
1424 w
= Fprevious_window (w
, Qnil
, all_frames
);
1431 /* Look at all windows, performing an operation specified by TYPE
1433 If FRAMES is Qt, look at all frames;
1434 Qnil, look at just the selected frame;
1435 Qvisible, look at visible frames;
1436 a frame, just look at windows on that frame.
1437 If MINI is non-zero, perform the operation on minibuffer windows too.
1443 GET_BUFFER_WINDOW
, /* Arg is buffer */
1444 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1445 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1446 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1448 UNSHOW_BUFFER
, /* Arg is buffer */
1453 window_loop (type
, obj
, mini
, frames
)
1454 enum window_loop type
;
1455 register Lisp_Object obj
, frames
;
1458 register Lisp_Object w
;
1459 register Lisp_Object best_window
;
1460 register Lisp_Object next_window
;
1461 register Lisp_Object last_window
;
1463 Lisp_Object frame_arg
;
1466 /* If we're only looping through windows on a particular frame,
1467 frame points to that frame. If we're looping through windows
1468 on all frames, frame is 0. */
1469 if (FRAMEP (frames
))
1470 frame
= XFRAME (frames
);
1471 else if (NILP (frames
))
1472 frame
= selected_frame
;
1476 frame_arg
= Qlambda
;
1477 else if (XFASTINT (frames
) == 0)
1479 else if (EQ (frames
, Qvisible
))
1482 /* frame_arg is Qlambda to stick to one frame,
1483 Qvisible to consider all visible frames,
1486 /* Pick a window to start with. */
1490 w
= FRAME_SELECTED_WINDOW (frame
);
1492 w
= FRAME_SELECTED_WINDOW (selected_frame
);
1494 /* Figure out the last window we're going to mess with. Since
1495 Fnext_window, given the same options, is guaranteed to go in a
1496 ring, we can just use Fprevious_window to find the last one.
1498 We can't just wait until we hit the first window again, because
1499 it might be deleted. */
1501 last_window
= Fprevious_window (w
, mini
? Qt
: Qnil
, frame_arg
);
1506 /* Pick the next window now, since some operations will delete
1507 the current window. */
1508 next_window
= Fnext_window (w
, mini
? Qt
: Qnil
, frame_arg
);
1510 /* Note that we do not pay attention here to whether
1511 the frame is visible, since Fnext_window skips non-visible frames
1512 if that is desired, under the control of frame_arg. */
1513 if (! MINI_WINDOW_P (XWINDOW (w
))
1514 /* For UNSHOW_BUFFER, we must always consider all windows. */
1515 || type
== UNSHOW_BUFFER
1516 || (mini
&& minibuf_level
> 0))
1519 case GET_BUFFER_WINDOW
:
1520 if (XBUFFER (XWINDOW (w
)->buffer
) == XBUFFER (obj
)
1521 /* Don't find any minibuffer window
1522 except the one that is currently in use. */
1523 && (MINI_WINDOW_P (XWINDOW (w
))
1524 ? EQ (w
, minibuf_window
) : 1))
1528 case GET_LRU_WINDOW
:
1529 /* t as arg means consider only full-width windows */
1530 if (!NILP (obj
) && !WINDOW_FULL_WIDTH_P (XWINDOW (w
)))
1532 /* Ignore dedicated windows and minibuffers. */
1533 if (MINI_WINDOW_P (XWINDOW (w
))
1534 || !NILP (XWINDOW (w
)->dedicated
))
1536 if (NILP (best_window
)
1537 || (XFASTINT (XWINDOW (best_window
)->use_time
)
1538 > XFASTINT (XWINDOW (w
)->use_time
)))
1542 case DELETE_OTHER_WINDOWS
:
1543 if (XWINDOW (w
) != XWINDOW (obj
))
1547 case DELETE_BUFFER_WINDOWS
:
1548 if (EQ (XWINDOW (w
)->buffer
, obj
))
1550 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1552 /* If this window is dedicated, and in a frame of its own,
1554 if (EQ (w
, FRAME_ROOT_WINDOW (f
))
1555 && !NILP (XWINDOW (w
)->dedicated
)
1556 && other_visible_frames (f
))
1558 /* Skip the other windows on this frame.
1559 There might be one, the minibuffer! */
1560 if (! EQ (w
, last_window
))
1561 while (f
== XFRAME (WINDOW_FRAME (XWINDOW (next_window
))))
1563 /* As we go, check for the end of the loop.
1564 We mustn't start going around a second time. */
1565 if (EQ (next_window
, last_window
))
1570 next_window
= Fnext_window (next_window
,
1574 /* Now we can safely delete the frame. */
1575 Fdelete_frame (WINDOW_FRAME (XWINDOW (w
)), Qnil
);
1578 /* If we're deleting the buffer displayed in the only window
1579 on the frame, find a new buffer to display there. */
1580 if (NILP (XWINDOW (w
)->parent
))
1582 Lisp_Object new_buffer
;
1583 new_buffer
= Fother_buffer (obj
, Qnil
,
1584 XWINDOW (w
)->frame
);
1585 if (NILP (new_buffer
))
1587 = Fget_buffer_create (build_string ("*scratch*"));
1588 Fset_window_buffer (w
, new_buffer
);
1589 if (EQ (w
, selected_window
))
1590 Fset_buffer (XWINDOW (w
)->buffer
);
1597 case GET_LARGEST_WINDOW
:
1598 /* Ignore dedicated windows and minibuffers. */
1599 if (MINI_WINDOW_P (XWINDOW (w
))
1600 || !NILP (XWINDOW (w
)->dedicated
))
1603 struct window
*best_window_ptr
= XWINDOW (best_window
);
1604 struct window
*w_ptr
= XWINDOW (w
);
1605 if (NILP (best_window
)
1606 || (XFASTINT (w_ptr
->height
) * XFASTINT (w_ptr
->width
)
1607 > (XFASTINT (best_window_ptr
->height
)
1608 * XFASTINT (best_window_ptr
->width
))))
1614 if (EQ (XWINDOW (w
)->buffer
, obj
))
1616 /* Find another buffer to show in this window. */
1617 Lisp_Object another_buffer
;
1618 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1619 another_buffer
= Fother_buffer (obj
, Qnil
, XWINDOW (w
)->frame
);
1620 if (NILP (another_buffer
))
1622 = Fget_buffer_create (build_string ("*scratch*"));
1623 /* If this window is dedicated, and in a frame of its own,
1625 if (EQ (w
, FRAME_ROOT_WINDOW (f
))
1626 && !NILP (XWINDOW (w
)->dedicated
)
1627 && other_visible_frames (f
))
1629 /* Skip the other windows on this frame.
1630 There might be one, the minibuffer! */
1631 if (! EQ (w
, last_window
))
1632 while (f
== XFRAME (WINDOW_FRAME (XWINDOW (next_window
))))
1634 /* As we go, check for the end of the loop.
1635 We mustn't start going around a second time. */
1636 if (EQ (next_window
, last_window
))
1641 next_window
= Fnext_window (next_window
,
1645 /* Now we can safely delete the frame. */
1646 Fdelete_frame (WINDOW_FRAME (XWINDOW (w
)), Qnil
);
1650 /* Otherwise show a different buffer in the window. */
1651 XWINDOW (w
)->dedicated
= Qnil
;
1652 Fset_window_buffer (w
, another_buffer
);
1653 if (EQ (w
, selected_window
))
1654 Fset_buffer (XWINDOW (w
)->buffer
);
1659 /* Check for a window that has a killed buffer. */
1660 case CHECK_ALL_WINDOWS
:
1661 if (! NILP (XWINDOW (w
)->buffer
)
1662 && NILP (XBUFFER (XWINDOW (w
)->buffer
)->name
))
1666 if (EQ (w
, last_window
))
1675 /* Used for debugging. Abort if any window has a dead buffer. */
1678 check_all_windows ()
1680 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
1683 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 1, 0,
1684 "Return the window least recently selected or used for display.\n\
1685 If optional argument FRAME is `visible', search all visible frames.\n\
1686 If FRAME is 0, search all visible and iconified frames.\n\
1687 If FRAME is t, search all frames.\n\
1688 If FRAME is nil, search only the selected frame.\n\
1689 If FRAME is a frame, search only that frame.")
1693 register Lisp_Object w
;
1694 /* First try for a window that is full-width */
1695 w
= window_loop (GET_LRU_WINDOW
, Qt
, 0, frame
);
1696 if (!NILP (w
) && !EQ (w
, selected_window
))
1698 /* If none of them, try the rest */
1699 return window_loop (GET_LRU_WINDOW
, Qnil
, 0, frame
);
1702 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 1, 0,
1703 "Return the largest window in area.\n\
1704 If optional argument FRAME is `visible', search all visible frames.\n\
1705 If FRAME is 0, search all visible and iconified frames.\n\
1706 If FRAME is t, search all frames.\n\
1707 If FRAME is nil, search only the selected frame.\n\
1708 If FRAME is a frame, search only that frame.")
1712 return window_loop (GET_LARGEST_WINDOW
, Qnil
, 0,
1716 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
1717 "Return a window currently displaying BUFFER, or nil if none.\n\
1718 If optional argument FRAME is `visible', search all visible frames.\n\
1719 If optional argument FRAME is 0, search all visible and iconified frames.\n\
1720 If FRAME is t, search all frames.\n\
1721 If FRAME is nil, search only the selected frame.\n\
1722 If FRAME is a frame, search only that frame.")
1724 Lisp_Object buffer
, frame
;
1726 buffer
= Fget_buffer (buffer
);
1727 if (BUFFERP (buffer
))
1728 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
1733 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
1735 "Make WINDOW (or the selected window) fill its frame.\n\
1736 Only the frame WINDOW is on is affected.\n\
1737 This function tries to reduce display jumps\n\
1738 by keeping the text previously visible in WINDOW\n\
1739 in the same place on the frame. Doing this depends on\n\
1740 the value of (window-start WINDOW), so if calling this function\n\
1741 in a program gives strange scrolling, make sure the window-start\n\
1742 value is reasonable when this function is called.")
1751 window
= selected_window
;
1753 CHECK_LIVE_WINDOW (window
, 0);
1755 w
= XWINDOW (window
);
1757 startpos
= marker_position (w
->start
);
1758 top
= XFASTINT (w
->top
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
1760 if (MINI_WINDOW_P (w
) && top
> 0)
1761 error ("Can't expand minibuffer to full frame");
1763 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
1765 /* Try to minimize scrolling, by setting the window start to the point
1766 will cause the text at the old window start to be at the same place
1767 on the frame. But don't try to do this if the window start is
1768 outside the visible portion (as might happen when the display is
1769 not current, due to typeahead). */
1770 if (startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
1771 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
1773 struct position pos
;
1774 struct buffer
*obuf
= current_buffer
;
1776 Fset_buffer (w
->buffer
);
1777 /* This computation used to temporarily move point, but that can
1778 have unwanted side effects due to text properties. */
1779 pos
= *vmotion (startpos
, -top
, w
);
1781 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
1782 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
1783 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
1785 /* We need to do this, so that the window-scroll-functions
1787 w
->optional_new_start
= Qt
;
1789 set_buffer_internal (obuf
);
1795 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
1796 1, 2, "bDelete windows on (buffer): ",
1797 "Delete all windows showing BUFFER.\n\
1798 Optional second argument FRAME controls which frames are affected.\n\
1799 If optional argument FRAME is `visible', search all visible frames.\n\
1800 If FRAME is 0, search all visible and iconified frames.\n\
1801 If FRAME is nil, search all frames.\n\
1802 If FRAME is t, search only the selected frame.\n\
1803 If FRAME is a frame, search only that frame.")
1805 Lisp_Object buffer
, frame
;
1807 /* FRAME uses t and nil to mean the opposite of what window_loop
1811 else if (EQ (frame
, Qt
))
1816 buffer
= Fget_buffer (buffer
);
1817 CHECK_BUFFER (buffer
, 0);
1818 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
1824 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
1825 Sreplace_buffer_in_windows
,
1826 1, 1, "bReplace buffer in windows: ",
1827 "Replace BUFFER with some other buffer in all windows showing it.")
1833 buffer
= Fget_buffer (buffer
);
1834 CHECK_BUFFER (buffer
, 0);
1835 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
1840 /* Replace BUFFER with some other buffer in all windows
1841 of all frames, even those on other keyboards. */
1844 replace_buffer_in_all_windows (buffer
)
1848 Lisp_Object tail
, frame
;
1850 /* A single call to window_loop won't do the job
1851 because it only considers frames on the current keyboard.
1852 So loop manually over frames, and handle each one. */
1853 FOR_EACH_FRAME (tail
, frame
)
1854 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
1856 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
1860 /* Set the height of WINDOW and all its inferiors. */
1862 /* The smallest acceptable dimensions for a window. Anything smaller
1863 might crash Emacs. */
1865 #define MIN_SAFE_WINDOW_WIDTH (2)
1866 #define MIN_SAFE_WINDOW_HEIGHT (2)
1868 /* Make sure that window_min_height and window_min_width are
1869 not too small; if they are, set them to safe minima. */
1872 check_min_window_sizes ()
1874 /* Smaller values might permit a crash. */
1875 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
1876 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
1877 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
1878 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
1881 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
1882 minimum allowable size. */
1885 check_frame_size (frame
, rows
, cols
)
1889 /* For height, we have to see:
1890 whether the frame has a minibuffer,
1891 whether it wants a mode line, and
1892 whether it has a menu bar. */
1894 (FRAME_MINIBUF_ONLY_P (frame
) ? MIN_SAFE_WINDOW_HEIGHT
- 1
1895 : (! FRAME_HAS_MINIBUF_P (frame
)) ? MIN_SAFE_WINDOW_HEIGHT
1896 : 2 * MIN_SAFE_WINDOW_HEIGHT
- 1);
1898 if (FRAME_TOP_MARGIN (frame
) > 0)
1899 min_height
+= FRAME_TOP_MARGIN (frame
);
1901 if (*rows
< min_height
)
1903 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
1904 *cols
= MIN_SAFE_WINDOW_WIDTH
;
1908 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
1909 check if W's width can be changed, otherwise check W's height.
1910 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
1911 siblings, too. If none of the siblings is resizable, WINDOW isn't
1915 window_fixed_size_p (w
, width_p
, check_siblings_p
)
1917 int width_p
, check_siblings_p
;
1922 if (!NILP (w
->hchild
))
1924 c
= XWINDOW (w
->hchild
);
1928 /* A horiz. combination is fixed-width if all of if its
1930 while (c
&& window_fixed_size_p (c
, width_p
, 0))
1931 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
1932 fixed_p
= c
== NULL
;
1936 /* A horiz. combination is fixed-height if one of if its
1938 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
1939 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
1940 fixed_p
= c
!= NULL
;
1943 else if (!NILP (w
->vchild
))
1945 c
= XWINDOW (w
->vchild
);
1949 /* A vert. combination is fixed-width if one of if its
1951 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
1952 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
1953 fixed_p
= c
!= NULL
;
1957 /* A vert. combination is fixed-height if all of if its
1959 while (c
&& window_fixed_size_p (c
, width_p
, 0))
1960 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
1961 fixed_p
= c
== NULL
;
1964 else if (BUFFERP (w
->buffer
))
1967 struct buffer
*old
= current_buffer
;
1969 current_buffer
= XBUFFER (w
->buffer
);
1970 val
= find_symbol_value (Qfixed_window_size
);
1971 current_buffer
= old
;
1974 if (!EQ (val
, Qunbound
))
1976 fixed_p
= !NILP (val
);
1979 && ((EQ (val
, Qheight
) && width_p
)
1980 || (EQ (val
, Qwidth
) && !width_p
)))
1984 /* Can't tell if this one is resizable without looking at
1985 siblings. If all siblings are fixed-size this one is too. */
1986 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
1990 for (child
= w
->prev
; !NILP (child
); child
= XWINDOW (child
)->prev
)
1991 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
1995 for (child
= w
->next
; !NILP (child
); child
= XWINDOW (child
)->next
)
1996 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2010 /* Return the minimum size of window W, not taking fixed-width windows
2011 into account. WIDTH_P non-zero means return the minimum width,
2012 otherwise return the minimum height. If W is a combination window,
2013 compute the minimum size from the minimum sizes of W's children. */
2016 window_min_size_1 (w
, width_p
)
2023 if (!NILP (w
->hchild
))
2025 c
= XWINDOW (w
->hchild
);
2030 /* The min width of a horizontal combination is
2031 the sum of the min widths of its children. */
2034 size
+= window_min_size_1 (c
, width_p
);
2035 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2040 /* The min height a horizontal combination equals
2041 the maximum of all min height of its children. */
2044 int min_size
= window_min_size_1 (c
, width_p
);
2045 size
= max (min_size
, size
);
2046 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2050 else if (!NILP (w
->vchild
))
2052 c
= XWINDOW (w
->vchild
);
2057 /* The min width of a vertical combination is
2058 the maximum of the min widths of its children. */
2061 int min_size
= window_min_size_1 (c
, width_p
);
2062 size
= max (min_size
, size
);
2063 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2068 /* The min height of a vertical combination equals
2069 the sum of the min height of its children. */
2072 size
+= window_min_size_1 (c
, width_p
);
2073 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2080 size
= window_min_width
;
2083 if (MINI_WINDOW_P (w
)
2084 || (!WINDOW_WANTS_MODELINE_P (w
)
2085 && !WINDOW_WANTS_TOP_LINE_P (w
)))
2088 size
= window_min_height
;
2096 /* Return the minimum size of window W, taking fixed-size windows into
2097 account. WIDTH_P non-zero means return the minimum width,
2098 otherwise return the minimum height. Set *FIXED to 1 if W is
2099 fixed-size unless FIXED is null. */
2102 window_min_size (w
, width_p
, fixed
)
2104 int width_p
, *fixed
;
2108 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
2113 size
= width_p
? XFASTINT (w
->width
) : XFASTINT (w
->height
);
2115 size
= window_min_size_1 (w
, width_p
);
2121 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
2122 WINDOW's width. Resize WINDOW's children, if any, so that they
2123 keep their proportionate size relative to WINDOW. Propagate
2124 WINDOW's top or left edge position to children. Delete windows
2125 that become too small unless NODELETE_P is non-zero. */
2128 size_window (window
, size
, width_p
, nodelete_p
)
2130 int size
, width_p
, nodelete_p
;
2132 struct window
*w
= XWINDOW (window
);
2134 Lisp_Object child
, *forward
, *sideward
;
2135 int old_size
, min_size
;
2137 check_min_window_sizes ();
2139 /* If the window has been "too small" at one point,
2140 don't delete it for being "too small" in the future.
2141 Preserve it as long as that is at all possible. */
2144 old_size
= XFASTINT (w
->width
);
2145 min_size
= window_min_width
;
2149 old_size
= XFASTINT (w
->height
);
2150 min_size
= window_min_height
;
2153 if (old_size
< window_min_width
)
2154 w
->too_small_ok
= Qt
;
2156 /* Maybe delete WINDOW if it's too small. */
2157 if (!nodelete_p
&& !NILP (w
->parent
))
2161 if (!MINI_WINDOW_P (w
) && !NILP (w
->too_small_ok
))
2162 min_size
= width_p
? MIN_SAFE_WINDOW_WIDTH
: MIN_SAFE_WINDOW_HEIGHT
;
2164 min_size
= width_p
? window_min_width
: window_min_height
;
2166 if (size
< min_size
)
2168 delete_window (window
);
2173 /* Set redisplay hints. */
2174 XSETFASTINT (w
->last_modified
, 0);
2175 XSETFASTINT (w
->last_overlay_modified
, 0);
2176 windows_or_buffers_changed
++;
2177 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
2181 sideward
= &w
->vchild
;
2182 forward
= &w
->hchild
;
2183 XSETFASTINT (w
->width
, size
);
2187 sideward
= &w
->hchild
;
2188 forward
= &w
->vchild
;
2189 XSETFASTINT (w
->height
, size
);
2192 if (!NILP (*sideward
))
2194 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
2196 c
= XWINDOW (child
);
2201 size_window (child
, size
, width_p
, nodelete_p
);
2204 else if (!NILP (*forward
))
2206 int fixed_size
, each
, extra
, n
;
2207 int resize_fixed_p
, nfixed
;
2208 int last_pos
, first_pos
, nchildren
;
2210 /* Determine the fixed-size portion of the this window, and the
2211 number of child windows. */
2212 fixed_size
= nchildren
= nfixed
= 0;
2213 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
2215 c
= XWINDOW (child
);
2216 if (window_fixed_size_p (c
, width_p
, 0))
2218 fixed_size
+= (width_p
2219 ? XFASTINT (c
->width
) : XFASTINT (c
->height
));
2224 /* If the new size is smaller than fixed_size, or if there
2225 aren't any resizable windows, allow resizing fixed-size
2227 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
2229 /* Compute how many lines/columns to add to each child. The
2230 value of extra takes care of rounding errors. */
2231 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
2232 each
= (size
- old_size
) / n
;
2233 extra
= (size
- old_size
) - n
* each
;
2235 /* Compute new children heights and edge positions. */
2236 first_pos
= width_p
? XFASTINT (w
->left
) : XFASTINT (w
->top
);
2237 last_pos
= first_pos
;
2238 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2240 int new_size
, old_size
;
2242 c
= XWINDOW (child
);
2243 old_size
= width_p
? XFASTINT (c
->width
) : XFASTINT (c
->height
);
2244 new_size
= old_size
;
2246 /* The top or left edge position of this child equals the
2247 bottom or right edge of its predecessor. */
2249 c
->left
= make_number (last_pos
);
2251 c
->top
= make_number (last_pos
);
2253 /* If this child can be resized, do it. */
2254 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
2256 new_size
= old_size
+ each
+ extra
;
2260 /* Set new height. Note that size_window also propagates
2261 edge positions to children, so it's not a no-op if we
2262 didn't change the child's size. */
2263 size_window (child
, new_size
, width_p
, 1);
2265 /* Remember the bottom/right edge position of this child; it
2266 will be used to set the top/left edge of the next child. */
2267 last_pos
+= new_size
;
2270 /* We should have covered the parent exactly with child windows. */
2271 xassert (size
== last_pos
- first_pos
);
2273 /* Now delete any children that became too small. */
2275 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2278 c
= XWINDOW (child
);
2279 child_size
= width_p
? XFASTINT (c
->width
) : XFASTINT (c
->height
);
2280 size_window (child
, child_size
, width_p
, 0);
2285 /* Set WINDOW's height to HEIGHT, and recursively change the height of
2286 WINDOW's children. NODELETE non-zero means don't delete windows
2287 that become too small in the process. (The caller should check
2288 later and do so if appropriate.) */
2291 set_window_height (window
, height
, nodelete
)
2296 size_window (window
, height
, 0, nodelete
);
2300 /* Set WINDOW's width to WIDTH, and recursively change the width of
2301 WINDOW's children. NODELETE non-zero means don't delete windows
2302 that become too small in the process. (The caller should check
2303 later and do so if appropriate.) */
2306 set_window_width (window
, width
, nodelete
)
2311 size_window (window
, width
, 1, nodelete
);
2315 int window_select_count
;
2318 Fset_window_buffer_unwind (obuf
)
2326 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
2327 means it's allowed to run hooks. See make_frame for a case where
2328 it's not allowed. */
2331 set_window_buffer (window
, buffer
, run_hooks_p
)
2332 Lisp_Object window
, buffer
;
2335 struct window
*w
= XWINDOW (window
);
2336 struct buffer
*b
= XBUFFER (buffer
);
2337 int count
= specpdl_ptr
- specpdl
;
2341 if (EQ (window
, selected_window
))
2342 b
->last_selected_window
= window
;
2344 /* Update time stamps of buffer display. */
2345 if (INTEGERP (b
->display_count
))
2346 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
2347 b
->display_time
= Fcurrent_time ();
2349 XSETFASTINT (w
->window_end_pos
, 0);
2350 XSETFASTINT (w
->window_end_vpos
, 0);
2351 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
2352 w
->window_end_valid
= Qnil
;
2353 XSETFASTINT (w
->hscroll
, 0);
2354 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
2355 set_marker_restricted (w
->start
,
2356 make_number (b
->last_window_start
),
2358 w
->start_at_line_beg
= Qnil
;
2359 w
->force_start
= Qnil
;
2360 XSETFASTINT (w
->last_modified
, 0);
2361 XSETFASTINT (w
->last_overlay_modified
, 0);
2362 windows_or_buffers_changed
++;
2364 /* We must select BUFFER for running the window-scroll-functions.
2365 If WINDOW is selected, switch permanently.
2366 Otherwise, switch but go back to the ambient buffer afterward. */
2367 if (EQ (window
, selected_window
))
2368 Fset_buffer (buffer
);
2369 /* We can't check ! NILP (Vwindow_scroll_functions) here
2370 because that might itself be a local variable. */
2371 else if (window_initialized
)
2373 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
2374 Fset_buffer (buffer
);
2377 /* Set left and right marginal area width from buffer. */
2378 Fset_window_margins (b
->left_margin_width
, b
->right_margin_width
,
2383 if (! NILP (Vwindow_scroll_functions
))
2384 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2385 Fmarker_position (w
->start
));
2387 if (! NILP (Vwindow_configuration_change_hook
)
2388 && ! NILP (Vrun_hooks
))
2389 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2392 unbind_to (count
, Qnil
);
2396 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 2, 0,
2397 "Make WINDOW display BUFFER as its contents.\n\
2398 BUFFER can be a buffer or buffer name.")
2400 register Lisp_Object window
, buffer
;
2402 register Lisp_Object tem
;
2403 register struct window
*w
= decode_window (window
);
2406 buffer
= Fget_buffer (buffer
);
2407 CHECK_BUFFER (buffer
, 1);
2409 if (NILP (XBUFFER (buffer
)->name
))
2410 error ("Attempt to display deleted buffer");
2414 error ("Window is deleted");
2415 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
2416 is first being set up. */
2418 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
2419 error ("Window is dedicated to `%s'",
2420 XSTRING (XBUFFER (tem
)->name
)->data
);
2425 set_window_buffer (window
, buffer
, 1);
2429 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 1, 0,
2430 "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\
2431 If WINDOW is not already selected, also make WINDOW's buffer current.\n\
2432 Note that the main editor command loop\n\
2433 selects the buffer of the selected window before each command.")
2435 register Lisp_Object window
;
2437 return select_window_1 (window
, 1);
2441 select_window_1 (window
, recordflag
)
2442 register Lisp_Object window
;
2445 register struct window
*w
;
2446 register struct window
*ow
= XWINDOW (selected_window
);
2448 CHECK_LIVE_WINDOW (window
, 0);
2450 w
= XWINDOW (window
);
2452 if (NILP (w
->buffer
))
2453 error ("Trying to select deleted window or non-leaf window");
2455 XSETFASTINT (w
->use_time
, ++window_select_count
);
2456 if (EQ (window
, selected_window
))
2459 if (! NILP (ow
->buffer
))
2460 set_marker_both (ow
->pointm
, ow
->buffer
,
2461 BUF_PT (XBUFFER (ow
->buffer
)),
2462 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
2464 selected_window
= window
;
2465 if (XFRAME (WINDOW_FRAME (w
)) != selected_frame
)
2467 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
2468 /* Use this rather than Fhandle_switch_frame
2469 so that FRAME_FOCUS_FRAME is moved appropriately as we
2470 move around in the state where a minibuffer in a separate
2472 Fselect_frame (WINDOW_FRAME (w
), Qnil
);
2475 selected_frame
->selected_window
= window
;
2478 record_buffer (w
->buffer
);
2479 Fset_buffer (w
->buffer
);
2481 XBUFFER (w
->buffer
)->last_selected_window
= window
;
2483 /* Go to the point recorded in the window.
2484 This is important when the buffer is in more
2485 than one window. It also matters when
2486 redisplay_window has altered point after scrolling,
2487 because it makes the change only in the window. */
2489 register int new_point
= marker_position (w
->pointm
);
2490 if (new_point
< BEGV
)
2492 else if (new_point
> ZV
)
2498 windows_or_buffers_changed
++;
2502 /* Deiconify the frame containing the window WINDOW,
2503 unless it is the selected frame;
2506 The reason for the exception for the selected frame
2507 is that it seems better not to change the selected frames visibility
2508 merely because of displaying a different buffer in it.
2509 The deiconification is useful when a buffer gets shown in
2510 another frame that you were not using lately. */
2513 display_buffer_1 (window
)
2516 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
2517 FRAME_SAMPLE_VISIBILITY (f
);
2518 if (f
!= selected_frame
)
2520 if (FRAME_ICONIFIED_P (f
))
2521 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
2522 else if (FRAME_VISIBLE_P (f
))
2523 Fraise_frame (WINDOW_FRAME (XWINDOW (window
)));
2528 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
2529 "Returns non-nil if a buffer named BUFFER-NAME would be created specially.\n\
2530 The value is actually t if the frame should be called with default frame\n\
2531 parameters, and a list of frame parameters if they were specified.\n\
2532 See `special-display-buffer-names', and `special-display-regexps'.")
2534 Lisp_Object buffer_name
;
2538 CHECK_STRING (buffer_name
, 1);
2540 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
2544 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
2548 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2550 Lisp_Object car
= XCAR (tem
);
2552 && fast_string_match (car
, buffer_name
) >= 0)
2554 else if (CONSP (car
)
2555 && STRINGP (XCAR (car
))
2556 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2562 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
2563 "Returns non-nil if a new buffer named BUFFER-NAME would use the same window.\n\
2564 See `same-window-buffer-names' and `same-window-regexps'.")
2566 Lisp_Object buffer_name
;
2570 CHECK_STRING (buffer_name
, 1);
2572 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
2576 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
2580 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2582 Lisp_Object car
= XCAR (tem
);
2584 && fast_string_match (car
, buffer_name
) >= 0)
2586 else if (CONSP (car
)
2587 && STRINGP (XCAR (car
))
2588 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2594 /* Use B so the default is (other-buffer). */
2595 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
2596 "BDisplay buffer: \nP",
2597 "Make BUFFER appear in some window but don't select it.\n\
2598 BUFFER can be a buffer or a buffer name.\n\
2599 If BUFFER is shown already in some window, just use that one,\n\
2600 unless the window is the selected window and the optional second\n\
2601 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).\n\
2602 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.\n\
2603 Returns the window displaying BUFFER.\n\
2605 The variables `special-display-buffer-names', `special-display-regexps',\n\
2606 `same-window-buffer-names', and `same-window-regexps' customize how certain\n\
2607 buffer names are handled.\n\
2609 If optional argument FRAME is `visible', search all visible frames.\n\
2610 If FRAME is 0, search all visible and iconified frames.\n\
2611 If FRAME is t, search all frames.\n\
2612 If FRAME is a frame, search only that frame.\n\
2613 If FRAME is nil, search only the selected frame\n\
2614 (actually the last nonminibuffer frame),\n\
2615 unless `pop-up-frames' is non-nil,\n\
2616 which means search visible and iconified frames.")
2617 (buffer
, not_this_window
, frame
)
2618 register Lisp_Object buffer
, not_this_window
, frame
;
2620 register Lisp_Object window
, tem
, swp
;
2623 buffer
= Fget_buffer (buffer
);
2624 CHECK_BUFFER (buffer
, 0);
2626 if (!NILP (Vdisplay_buffer_function
))
2627 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
2629 if (NILP (not_this_window
)
2630 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
2631 return display_buffer_1 (selected_window
);
2633 /* See if the user has specified this buffer should appear
2634 in the selected window. */
2635 if (NILP (not_this_window
))
2637 swp
= Fsame_window_p (XBUFFER (buffer
)->name
);
2638 if (!NILP (swp
) && !no_switch_window (selected_window
))
2640 Fswitch_to_buffer (buffer
, Qnil
);
2641 return display_buffer_1 (selected_window
);
2645 /* If pop_up_frames,
2646 look for a window showing BUFFER on any visible or iconified frame.
2647 Otherwise search only the current frame. */
2650 else if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2651 XSETFASTINT (tem
, 0);
2653 XSETFRAME (tem
, last_nonminibuf_frame
);
2654 window
= Fget_buffer_window (buffer
, tem
);
2656 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
2658 return display_buffer_1 (window
);
2661 /* Certain buffer names get special handling. */
2662 if (!NILP (Vspecial_display_function
) && NILP (swp
))
2664 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
2666 return call1 (Vspecial_display_function
, buffer
);
2668 return call2 (Vspecial_display_function
, buffer
, tem
);
2671 /* If there are no frames open that have more than a minibuffer,
2672 we need to create a new frame. */
2673 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2675 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2676 Fset_window_buffer (window
, buffer
);
2677 return display_buffer_1 (window
);
2681 || FRAME_MINIBUF_ONLY_P (selected_frame
)
2682 /* If the current frame is a special display frame,
2683 don't try to reuse its windows. */
2684 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (selected_frame
))->dedicated
)
2690 if (FRAME_MINIBUF_ONLY_P (selected_frame
))
2691 XSETFRAME (frames
, last_nonminibuf_frame
);
2692 /* Don't try to create a window if would get an error */
2693 if (split_height_threshold
< window_min_height
<< 1)
2694 split_height_threshold
= window_min_height
<< 1;
2696 /* Note that both Fget_largest_window and Fget_lru_window
2697 ignore minibuffers and dedicated windows.
2698 This means they can return nil. */
2700 /* If the frame we would try to split cannot be split,
2701 try other frames. */
2702 if (FRAME_NO_SPLIT_P (NILP (frames
) ? selected_frame
2703 : last_nonminibuf_frame
))
2705 /* Try visible frames first. */
2706 window
= Fget_largest_window (Qvisible
);
2707 /* If that didn't work, try iconified frames. */
2709 window
= Fget_largest_window (make_number (0));
2711 window
= Fget_largest_window (Qt
);
2714 window
= Fget_largest_window (frames
);
2716 /* If we got a tall enough full-width window that can be split,
2719 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2720 && window_height (window
) >= split_height_threshold
2721 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
2722 window
= Fsplit_window (window
, Qnil
, Qnil
);
2725 Lisp_Object upper
, lower
, other
;
2727 window
= Fget_lru_window (frames
);
2728 /* If the LRU window is selected, and big enough,
2729 and can be split, split it. */
2731 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2732 && (EQ (window
, selected_window
)
2733 || EQ (XWINDOW (window
)->parent
, Qnil
))
2734 && window_height (window
) >= window_min_height
<< 1)
2735 window
= Fsplit_window (window
, Qnil
, Qnil
);
2736 /* If Fget_lru_window returned nil, try other approaches. */
2738 /* Try visible frames first. */
2740 window
= Fget_buffer_window (buffer
, Qvisible
);
2742 window
= Fget_largest_window (Qvisible
);
2743 /* If that didn't work, try iconified frames. */
2745 window
= Fget_buffer_window (buffer
, make_number (0));
2747 window
= Fget_largest_window (make_number (0));
2748 /* Try invisible frames. */
2750 window
= Fget_buffer_window (buffer
, Qt
);
2752 window
= Fget_largest_window (Qt
);
2753 /* As a last resort, make a new frame. */
2755 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2756 /* If window appears above or below another,
2757 even out their heights. */
2758 other
= upper
= lower
= Qnil
;
2759 if (!NILP (XWINDOW (window
)->prev
))
2760 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
2761 if (!NILP (XWINDOW (window
)->next
))
2762 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
2764 /* Check that OTHER and WINDOW are vertically arrayed. */
2765 && !EQ (XWINDOW (other
)->top
, XWINDOW (window
)->top
)
2766 && (XFASTINT (XWINDOW (other
)->height
)
2767 > XFASTINT (XWINDOW (window
)->height
)))
2769 int total
= (XFASTINT (XWINDOW (other
)->height
)
2770 + XFASTINT (XWINDOW (window
)->height
));
2771 Lisp_Object old_selected_window
;
2772 old_selected_window
= selected_window
;
2774 selected_window
= upper
;
2775 change_window_height ((total
/ 2
2776 - XFASTINT (XWINDOW (upper
)->height
)),
2778 selected_window
= old_selected_window
;
2783 window
= Fget_lru_window (Qnil
);
2785 Fset_window_buffer (window
, buffer
);
2786 return display_buffer_1 (window
);
2790 temp_output_buffer_show (buf
)
2791 register Lisp_Object buf
;
2793 register struct buffer
*old
= current_buffer
;
2794 register Lisp_Object window
;
2795 register struct window
*w
;
2797 XBUFFER (buf
)->directory
= current_buffer
->directory
;
2800 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
2804 XBUFFER (buf
)->clip_changed
= 1;
2805 set_buffer_internal (old
);
2807 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
2808 call1 (Vtemp_buffer_show_function
, buf
);
2811 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
2813 if (XFRAME (XWINDOW (window
)->frame
) != selected_frame
)
2814 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
2815 Vminibuf_scroll_window
= window
;
2816 w
= XWINDOW (window
);
2817 XSETFASTINT (w
->hscroll
, 0);
2818 set_marker_restricted_both (w
->start
, buf
, 1, 1);
2819 set_marker_restricted_both (w
->pointm
, buf
, 1, 1);
2821 /* Run temp-buffer-show-hook, with the chosen window selected
2822 and it sbuffer current. */
2823 if (!NILP (Vrun_hooks
))
2826 tem
= Fboundp (Qtemp_buffer_show_hook
);
2829 tem
= Fsymbol_value (Qtemp_buffer_show_hook
);
2832 int count
= specpdl_ptr
- specpdl
;
2833 Lisp_Object prev_window
;
2834 prev_window
= selected_window
;
2836 /* Select the window that was chosen, for running the hook. */
2837 record_unwind_protect (Fselect_window
, prev_window
);
2838 select_window_1 (window
, 0);
2839 Fset_buffer (w
->buffer
);
2840 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
2841 select_window_1 (prev_window
, 0);
2842 unbind_to (count
, Qnil
);
2850 make_dummy_parent (window
)
2854 register struct window
*o
, *p
;
2855 register struct Lisp_Vector
*vec
;
2858 o
= XWINDOW (window
);
2859 vec
= allocate_vectorlike ((EMACS_INT
)VECSIZE (struct window
));
2860 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
2861 vec
->contents
[i
] = ((struct Lisp_Vector
*)o
)->contents
[i
];
2862 vec
->size
= VECSIZE (struct window
);
2863 p
= (struct window
*)vec
;
2864 XSETWINDOW (new, p
);
2866 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
2868 /* Put new into window structure in place of window */
2869 replace_window (window
, new);
2882 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
2883 "Split WINDOW, putting SIZE lines in the first of the pair.\n\
2884 WINDOW defaults to selected one and SIZE to half its size.\n\
2885 If optional third arg HORFLAG is non-nil, split side by side\n\
2886 and put SIZE columns in the first of the pair. In that case,\n\
2887 SIZE includes that window's scroll bar, or the divider column to its right.")
2888 (window
, size
, horflag
)
2889 Lisp_Object window
, size
, horflag
;
2891 register Lisp_Object
new;
2892 register struct window
*o
, *p
;
2894 register int size_int
;
2897 window
= selected_window
;
2899 CHECK_LIVE_WINDOW (window
, 0);
2901 o
= XWINDOW (window
);
2902 fo
= XFRAME (WINDOW_FRAME (o
));
2906 if (!NILP (horflag
))
2907 /* Calculate the size of the left-hand window, by dividing
2908 the usable space in columns by two.
2909 We round up, since the left-hand window may include
2910 a dividing line, while the right-hand may not. */
2911 size_int
= (XFASTINT (o
->width
) + 1) >> 1;
2913 size_int
= XFASTINT (o
->height
) >> 1;
2917 CHECK_NUMBER (size
, 1);
2918 size_int
= XINT (size
);
2921 if (MINI_WINDOW_P (o
))
2922 error ("Attempt to split minibuffer window");
2923 else if (window_fixed_size_p (o
, !NILP (horflag
), 0))
2924 error ("Attempt to split fixed-size window");
2926 check_min_window_sizes ();
2930 if (size_int
< window_min_height
)
2931 error ("Window height %d too small (after splitting)", size_int
);
2932 if (size_int
+ window_min_height
> XFASTINT (o
->height
))
2933 error ("Window height %d too small (after splitting)",
2934 XFASTINT (o
->height
) - size_int
);
2935 if (NILP (o
->parent
)
2936 || NILP (XWINDOW (o
->parent
)->vchild
))
2938 make_dummy_parent (window
);
2940 XWINDOW (new)->vchild
= window
;
2945 if (size_int
< window_min_width
)
2946 error ("Window width %d too small (after splitting)", size_int
);
2948 if (size_int
+ window_min_width
> XFASTINT (o
->width
))
2949 error ("Window width %d too small (after splitting)",
2950 XFASTINT (o
->width
) - size_int
);
2951 if (NILP (o
->parent
)
2952 || NILP (XWINDOW (o
->parent
)->hchild
))
2954 make_dummy_parent (window
);
2956 XWINDOW (new)->hchild
= window
;
2960 /* Now we know that window's parent is a vertical combination
2961 if we are dividing vertically, or a horizontal combination
2962 if we are making side-by-side windows */
2964 windows_or_buffers_changed
++;
2965 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
2966 new = make_window ();
2969 p
->frame
= o
->frame
;
2971 if (!NILP (p
->next
))
2972 XWINDOW (p
->next
)->prev
= new;
2975 p
->parent
= o
->parent
;
2977 p
->window_end_valid
= Qnil
;
2978 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
2980 /* Apportion the available frame space among the two new windows */
2982 if (!NILP (horflag
))
2984 p
->height
= o
->height
;
2986 XSETFASTINT (p
->width
, XFASTINT (o
->width
) - size_int
);
2987 XSETFASTINT (o
->width
, size_int
);
2988 XSETFASTINT (p
->left
, XFASTINT (o
->left
) + size_int
);
2993 p
->width
= o
->width
;
2994 XSETFASTINT (p
->height
, XFASTINT (o
->height
) - size_int
);
2995 XSETFASTINT (o
->height
, size_int
);
2996 XSETFASTINT (p
->top
, XFASTINT (o
->top
) + size_int
);
2999 /* Adjust glyph matrices. */
3001 Fset_window_buffer (new, o
->buffer
);
3005 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
3006 "Make current window ARG lines bigger.\n\
3007 From program, optional second arg non-nil means grow sideways ARG columns.")
3009 register Lisp_Object arg
, side
;
3011 CHECK_NUMBER (arg
, 0);
3012 change_window_height (XINT (arg
), !NILP (side
));
3014 if (! NILP (Vwindow_configuration_change_hook
))
3015 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3020 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
3021 "Make current window ARG lines smaller.\n\
3022 From program, optional second arg non-nil means shrink sideways arg columns.")
3024 register Lisp_Object arg
, side
;
3026 CHECK_NUMBER (arg
, 0);
3027 change_window_height (-XINT (arg
), !NILP (side
));
3029 if (! NILP (Vwindow_configuration_change_hook
))
3030 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3036 window_height (window
)
3039 register struct window
*p
= XWINDOW (window
);
3040 return XFASTINT (p
->height
);
3044 window_width (window
)
3047 register struct window
*p
= XWINDOW (window
);
3048 return XFASTINT (p
->width
);
3053 *(widthflag ? (int *) &(XWINDOW (w)->left) : (int *) &(XWINDOW (w)->top))
3055 #define CURSIZE(w) \
3056 *(widthflag ? (int *) &(XWINDOW (w)->width) : (int *) &(XWINDOW (w)->height))
3059 /* Enlarge selected_window by DELTA. WIDTHFLAG non-zero means
3060 increase its width. Siblings of the selected window are resized to
3061 fullfil the size request. If they become too small in the process,
3062 they will be deleted. */
3065 change_window_height (delta
, widthflag
)
3066 int delta
, widthflag
;
3068 Lisp_Object parent
, window
, next
, prev
;
3070 int *sizep
, maximum
;
3071 int (*sizefun
) P_ ((Lisp_Object
))
3072 = widthflag
? window_width
: window_height
;
3073 void (*setsizefun
) P_ ((Lisp_Object
, int, int))
3074 = (widthflag
? set_window_width
: set_window_height
);
3076 /* Check values of window_min_width and window_min_height for
3078 check_min_window_sizes ();
3080 /* Give up if this window cannot be resized. */
3081 window
= selected_window
;
3082 if (window_fixed_size_p (XWINDOW (window
), widthflag
, 1))
3083 error ("Window is not resizable");
3085 /* Find the parent of the selected window. */
3088 p
= XWINDOW (window
);
3094 error ("No other window to side of this one");
3099 ? !NILP (XWINDOW (parent
)->hchild
)
3100 : !NILP (XWINDOW (parent
)->vchild
))
3106 sizep
= &CURSIZE (window
);
3109 register int maxdelta
;
3111 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - *sizep
3112 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
3113 - window_min_size (XWINDOW (p
->next
),
3115 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
3116 - window_min_size (XWINDOW (p
->prev
),
3118 /* This is a frame with only one window, a minibuffer-only
3119 or a minibufferless frame. */
3122 if (delta
> maxdelta
)
3123 /* This case traps trying to make the minibuffer
3124 the full frame, or make the only window aside from the
3125 minibuffer the full frame. */
3129 if (*sizep
+ delta
< window_min_size (XWINDOW (window
), widthflag
, 0))
3131 delete_window (window
);
3138 /* Find the total we can get from other siblings. */
3140 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
3141 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
3143 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
3144 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
3147 /* If we can get it all from them, do so. */
3148 if (delta
<= maximum
)
3150 Lisp_Object first_unaffected
;
3151 Lisp_Object first_affected
;
3156 first_affected
= window
;
3157 /* Look at one sibling at a time,
3158 moving away from this window in both directions alternately,
3159 and take as much as we can get without deleting that sibling. */
3160 while (delta
!= 0 && (!NILP (next
) || !NILP (prev
)))
3164 int this_one
= ((*sizefun
) (next
)
3165 - window_min_size (XWINDOW (next
),
3166 widthflag
, &fixed_p
));
3169 if (this_one
> delta
)
3172 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
3173 (*setsizefun
) (window
, *sizep
+ this_one
, 0);
3178 next
= XWINDOW (next
)->next
;
3186 int this_one
= ((*sizefun
) (prev
)
3187 - window_min_size (XWINDOW (prev
),
3188 widthflag
, &fixed_p
));
3191 if (this_one
> delta
)
3194 first_affected
= prev
;
3196 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
3197 (*setsizefun
) (window
, *sizep
+ this_one
, 0);
3202 prev
= XWINDOW (prev
)->prev
;
3206 xassert (delta
== 0);
3208 /* Now recalculate the edge positions of all the windows affected,
3209 based on the new sizes. */
3210 first_unaffected
= next
;
3211 prev
= first_affected
;
3212 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
3213 prev
= next
, next
= XWINDOW (next
)->next
)
3215 CURBEG (next
) = CURBEG (prev
) + (*sizefun
) (prev
);
3216 /* This does not change size of NEXT,
3217 but it propagates the new top edge to its children */
3218 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
3223 register int delta1
;
3224 register int opht
= (*sizefun
) (parent
);
3226 /* If trying to grow this window to or beyond size of the parent,
3227 make delta1 so big that, on shrinking back down,
3228 all the siblings end up with less than one line and are deleted. */
3229 if (opht
<= *sizep
+ delta
)
3230 delta1
= opht
* opht
* 2;
3233 /* Otherwise, make delta1 just right so that if we add
3234 delta1 lines to this window and to the parent, and then
3235 shrink the parent back to its original size, the new
3236 proportional size of this window will increase by delta.
3238 The function size_window will compute the new height h'
3239 of the window from delta1 as:
3242 x = delta1 - delta1/n * n for the 1st resizable child
3245 where n is the number of children that can be resized.
3246 We can ignore x by choosing a delta1 that is a multiple of
3247 n. We want the height of this window to come out as
3257 The number of children n rquals the number of resizable
3258 children of this window + 1 because we know window itself
3259 is resizable (otherwise we would have signalled an error. */
3261 struct window
*w
= XWINDOW (window
);
3265 for (s
= w
->next
; !NILP (s
); s
= XWINDOW (s
)->next
)
3266 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
3268 for (s
= w
->prev
; !NILP (s
); s
= XWINDOW (s
)->prev
)
3269 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
3275 /* Add delta1 lines or columns to this window, and to the parent,
3276 keeping things consistent while not affecting siblings. */
3277 CURSIZE (parent
) = opht
+ delta1
;
3278 (*setsizefun
) (window
, *sizep
+ delta1
, 0);
3280 /* Squeeze out delta1 lines or columns from our parent,
3281 shriking this window and siblings proportionately.
3282 This brings parent back to correct size.
3283 Delta1 was calculated so this makes this window the desired size,
3284 taking it all out of the siblings. */
3285 (*setsizefun
) (parent
, opht
, 0);
3288 XSETFASTINT (p
->last_modified
, 0);
3289 XSETFASTINT (p
->last_overlay_modified
, 0);
3291 /* Adjust glyph matrices. */
3292 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
3299 /* Mark window cursors off for all windows in the window tree rooted
3300 at W by setting their phys_cursor_on_p flag to zero. Called from
3301 xterm.c, e.g. when a frame is cleared and thereby all cursors on
3302 the frame are cleared. */
3305 mark_window_cursors_off (w
)
3310 if (!NILP (w
->hchild
))
3311 mark_window_cursors_off (XWINDOW (w
->hchild
));
3312 else if (!NILP (w
->vchild
))
3313 mark_window_cursors_off (XWINDOW (w
->vchild
));
3315 w
->phys_cursor_on_p
= 0;
3317 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3322 /* Return number of lines of text (not counting mode line) in W. */
3325 window_internal_height (w
)
3328 int ht
= XFASTINT (w
->height
);
3330 if (MINI_WINDOW_P (w
))
3333 if (!NILP (w
->parent
) || !NILP (w
->vchild
) || !NILP (w
->hchild
)
3334 || !NILP (w
->next
) || !NILP (w
->prev
)
3335 || FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (w
))))
3342 /* Return the number of columns in W.
3343 Don't count columns occupied by scroll bars or the vertical bar
3344 separating W from the sibling to its right. */
3347 window_internal_width (w
)
3350 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3351 int width
= XINT (w
->width
);
3353 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3354 /* Scroll bars occupy a few columns. */
3355 width
-= FRAME_SCROLL_BAR_COLS (f
);
3356 else if (!WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
3357 /* The column of `|' characters separating side-by-side windows
3358 occupies one column only. */
3361 /* On window-systems, areas to the left and right of the window
3362 are used to display bitmaps there. */
3363 if (FRAME_WINDOW_P (f
))
3364 width
-= 2 * FRAME_FLAGS_AREA_COLS (f
);
3370 /************************************************************************
3372 ***********************************************************************/
3374 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
3375 one screen-full, which is defined as the height of the window minus
3376 next_screen_context_lines. If WHOLE is zero, scroll up N lines
3377 instead. Negative values of N mean scroll down. NOERROR non-zero
3378 means don't signal an error if we try to move over BEGV or ZV,
3382 window_scroll (window
, n
, whole
, noerror
)
3388 /* If we must, use the pixel-based version which is much slower than
3389 the line-based one but can handle varying line heights. */
3390 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
3391 window_scroll_pixel_based (window
, n
, whole
, noerror
);
3393 window_scroll_line_based (window
, n
, whole
, noerror
);
3397 /* Implementation of window_scroll that works based on pixel line
3398 heights. See the comment of window_scroll for parameter
3402 window_scroll_pixel_based (window
, n
, whole
, noerror
)
3409 struct window
*w
= XWINDOW (window
);
3410 struct text_pos start
;
3412 int this_scroll_margin
;
3415 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
3417 /* If PT is not visible in WINDOW, move back one half of
3419 XSETFASTINT (tem
, PT
);
3420 tem
= Fpos_visible_in_window_p (tem
, window
);
3423 /* Move backward half the height of the window. Performance note:
3424 vmotion used here is about 10% faster, but would give wrong
3425 results for variable height lines. */
3426 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
3427 it
.current_y
= it
.last_visible_y
;
3428 move_it_vertically (&it
, -it
.last_visible_y
/ 2);
3430 /* The function move_iterator_vertically may move over more than
3431 the specified y-distance. If it->w is small, e.g. a
3432 mini-buffer window, we may end up in front of the window's
3433 display area. This is the case when Start displaying at the
3434 start of the line containing PT in this case. */
3435 if (it
.current_y
<= 0)
3437 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
3438 move_it_vertically (&it
, 0);
3442 start
= it
.current
.pos
;
3445 /* If scroll_preserve_screen_position is non-zero, we try to set
3446 point in the same window line as it is now, so get that line. */
3447 if (!NILP (Vscroll_preserve_screen_position
))
3449 start_display (&it
, w
, start
);
3450 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
3451 preserve_y
= it
.current_y
;
3456 /* Move iterator it from start the specified distance forward or
3457 backward. The result is the new window start. */
3458 start_display (&it
, w
, start
);
3461 int screen_full
= (it
.last_visible_y
3462 - next_screen_context_lines
* CANON_Y_UNIT (it
.f
));
3463 int direction
= n
< 0 ? -1 : 1;
3464 move_it_vertically (&it
, direction
* screen_full
);
3467 move_it_by_lines (&it
, n
, 1);
3469 /* End if we end up at ZV or BEGV. */
3470 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
3471 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
3475 else if (IT_CHARPOS (it
) == ZV
)
3476 Fsignal (Qend_of_buffer
, Qnil
);
3478 Fsignal (Qbeginning_of_buffer
, Qnil
);
3481 /* Set the window start, and set up the window for redisplay. */
3482 set_marker_restricted (w
->start
, make_number (IT_CHARPOS (it
)), w
->buffer
);
3483 w
->start_at_line_beg
= Fbolp ();
3484 w
->update_mode_line
= Qt
;
3485 XSETFASTINT (w
->last_modified
, 0);
3486 XSETFASTINT (w
->last_overlay_modified
, 0);
3487 /* Set force_start so that redisplay_window will run the
3488 window-scroll-functions. */
3489 w
->force_start
= Qt
;
3491 it
.current_y
= it
.vpos
= 0;
3493 /* Preserve the screen position if we must. */
3494 if (preserve_y
>= 0)
3496 move_it_to (&it
, -1, -1, preserve_y
, -1, MOVE_TO_Y
);
3497 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
3501 /* Move PT out of scroll margins. */
3502 this_scroll_margin
= max (0, scroll_margin
);
3503 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
3504 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
3508 /* We moved the window start towards ZV, so PT may be now
3509 in the scroll margin at the top. */
3510 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
3511 while (it
.current_y
< this_scroll_margin
)
3512 move_it_by_lines (&it
, 1, 1);
3513 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
3517 /* We moved the window start towards BEGV, so PT may be now
3518 in the scroll margin at the bottom. */
3519 move_it_to (&it
, PT
, -1,
3520 it
.last_visible_y
- this_scroll_margin
- 1, -1,
3521 MOVE_TO_POS
| MOVE_TO_Y
);
3523 /* Don't put point on a partially visible line at the end. */
3524 if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
3525 > it
.last_visible_y
)
3526 move_it_by_lines (&it
, -1, 0);
3528 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
3534 /* Implementation of window_scroll that works based on screen lines.
3535 See the comment of window_scroll for parameter descriptions. */
3538 window_scroll_line_based (window
, n
, whole
, noerror
)
3544 register struct window
*w
= XWINDOW (window
);
3545 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
3546 register int pos
, pos_byte
;
3547 register int ht
= window_internal_height (w
);
3548 register Lisp_Object tem
;
3552 struct position posit
;
3555 startpos
= marker_position (w
->start
);
3557 posit
= *compute_motion (startpos
, 0, 0, 0,
3559 window_internal_width (w
), XINT (w
->hscroll
),
3561 original_vpos
= posit
.vpos
;
3563 XSETFASTINT (tem
, PT
);
3564 tem
= Fpos_visible_in_window_p (tem
, window
);
3568 Fvertical_motion (make_number (- (ht
/ 2)), window
);
3573 lose
= n
< 0 && PT
== BEGV
;
3574 Fvertical_motion (make_number (n
), window
);
3578 SET_PT_BOTH (opoint
, opoint_byte
);
3585 Fsignal (Qbeginning_of_buffer
, Qnil
);
3590 int this_scroll_margin
= scroll_margin
;
3592 /* Don't use a scroll margin that is negative or too large. */
3593 if (this_scroll_margin
< 0)
3594 this_scroll_margin
= 0;
3596 if (XINT (w
->height
) < 4 * scroll_margin
)
3597 this_scroll_margin
= XINT (w
->height
) / 4;
3599 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
3600 w
->start_at_line_beg
= bolp
;
3601 w
->update_mode_line
= Qt
;
3602 XSETFASTINT (w
->last_modified
, 0);
3603 XSETFASTINT (w
->last_overlay_modified
, 0);
3604 /* Set force_start so that redisplay_window will run
3605 the window-scroll-functions. */
3606 w
->force_start
= Qt
;
3608 if (whole
&& !NILP (Vscroll_preserve_screen_position
))
3610 SET_PT_BOTH (pos
, pos_byte
);
3611 Fvertical_motion (make_number (original_vpos
), window
);
3613 /* If we scrolled forward, put point enough lines down
3614 that it is outside the scroll margin. */
3619 if (this_scroll_margin
> 0)
3621 SET_PT_BOTH (pos
, pos_byte
);
3622 Fvertical_motion (make_number (this_scroll_margin
), window
);
3628 if (top_margin
<= opoint
)
3629 SET_PT_BOTH (opoint
, opoint_byte
);
3630 else if (!NILP (Vscroll_preserve_screen_position
))
3632 SET_PT_BOTH (pos
, pos_byte
);
3633 Fvertical_motion (make_number (original_vpos
), window
);
3636 SET_PT (top_margin
);
3642 /* If we scrolled backward, put point near the end of the window
3643 but not within the scroll margin. */
3644 SET_PT_BOTH (pos
, pos_byte
);
3645 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
3646 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
3649 bottom_margin
= PT
+ 1;
3651 if (bottom_margin
> opoint
)
3652 SET_PT_BOTH (opoint
, opoint_byte
);
3655 if (!NILP (Vscroll_preserve_screen_position
))
3657 SET_PT_BOTH (pos
, pos_byte
);
3658 Fvertical_motion (make_number (original_vpos
), window
);
3661 Fvertical_motion (make_number (-1), window
);
3670 Fsignal (Qend_of_buffer
, Qnil
);
3675 /* Scroll selected_window up or down. If N is nil, scroll a
3676 screen-full which is defined as the height of the window minus
3677 next_screen_context_lines. If N is the symbol `-', scroll.
3678 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
3679 up. This is the guts of Fscroll_up and Fscroll_down. */
3682 scroll_command (n
, direction
)
3686 register int defalt
;
3687 int count
= specpdl_ptr
- specpdl
;
3689 xassert (abs (direction
) == 1);
3691 /* If selected window's buffer isn't current, make it current for
3692 the moment. But don't screw up if window_scroll gets an error. */
3693 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
3695 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
3696 Fset_buffer (XWINDOW (selected_window
)->buffer
);
3698 /* Make redisplay consider other windows than just selected_window. */
3699 ++windows_or_buffers_changed
;
3702 defalt
= (window_internal_height (XWINDOW (selected_window
))
3703 - next_screen_context_lines
);
3704 defalt
= direction
* (defalt
< 1 ? 1 : defalt
);
3707 window_scroll (selected_window
, defalt
, 1, 0);
3708 else if (EQ (n
, Qminus
))
3709 window_scroll (selected_window
, - defalt
, 1, 0);
3712 n
= Fprefix_numeric_value (n
);
3713 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
3716 unbind_to (count
, Qnil
);
3719 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
3720 "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\
3721 A near full screen is `next-screen-context-lines' less than a full screen.\n\
3722 Negative ARG means scroll downward.\n\
3723 If ARG is the atom `-', scroll downward by nearly full screen.\n\
3724 When calling from a program, supply as argument a number, nil, or `-'.")
3728 scroll_command (arg
, 1);
3732 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
3733 "Scroll text of current window down ARG lines; or near full screen if no ARG.\n\
3734 A near full screen is `next-screen-context-lines' less than a full screen.\n\
3735 Negative ARG means scroll upward.\n\
3736 If ARG is the atom `-', scroll upward by nearly full screen.\n\
3737 When calling from a program, supply as argument a number, nil, or `-'.")
3741 scroll_command (arg
, -1);
3745 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
3746 "Return the other window for \"other window scroll\" commands.\n\
3747 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
3748 specifies the window.\n\
3749 If `other-window-scroll-buffer' is non-nil, a window\n\
3750 showing that buffer is used.")
3755 if (MINI_WINDOW_P (XWINDOW (selected_window
))
3756 && !NILP (Vminibuf_scroll_window
))
3757 window
= Vminibuf_scroll_window
;
3758 /* If buffer is specified, scroll that buffer. */
3759 else if (!NILP (Vother_window_scroll_buffer
))
3761 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
3763 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
3767 /* Nothing specified; look for a neighboring window on the same
3769 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
3771 if (EQ (window
, selected_window
))
3772 /* That didn't get us anywhere; look for a window on another
3775 window
= Fnext_window (window
, Qnil
, Qt
);
3776 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
3777 && ! EQ (window
, selected_window
));
3780 CHECK_LIVE_WINDOW (window
, 0);
3782 if (EQ (window
, selected_window
))
3783 error ("There is no other window");
3788 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
3789 "Scroll next window upward ARG lines; or near full screen if no ARG.\n\
3790 A near full screen is `next-screen-context-lines' less than a full screen.\n\
3791 The next window is the one below the current one; or the one at the top\n\
3792 if the current one is at the bottom. Negative ARG means scroll downward.\n\
3793 If ARG is the atom `-', scroll downward by nearly full screen.\n\
3794 When calling from a program, supply as argument a number, nil, or `-'.\n\
3796 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
3797 specifies the window to scroll.\n\
3798 If `other-window-scroll-buffer' is non-nil, scroll the window\n\
3799 showing that buffer, popping the buffer up if necessary.")
3801 register Lisp_Object arg
;
3803 register Lisp_Object window
;
3804 register int defalt
;
3805 register struct window
*w
;
3806 register int count
= specpdl_ptr
- specpdl
;
3808 window
= Fother_window_for_scrolling ();
3810 w
= XWINDOW (window
);
3811 defalt
= window_internal_height (w
) - next_screen_context_lines
;
3812 if (defalt
< 1) defalt
= 1;
3814 /* Don't screw up if window_scroll gets an error. */
3815 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
3816 ++windows_or_buffers_changed
;
3818 Fset_buffer (w
->buffer
);
3819 SET_PT (marker_position (w
->pointm
));
3822 window_scroll (window
, defalt
, 1, 1);
3823 else if (EQ (arg
, Qminus
))
3824 window_scroll (window
, -defalt
, 1, 1);
3829 CHECK_NUMBER (arg
, 0);
3830 window_scroll (window
, XINT (arg
), 0, 1);
3833 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
3834 unbind_to (count
, Qnil
);
3839 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 1, "P",
3840 "Scroll selected window display ARG columns left.\n\
3841 Default for ARG is window width minus 2.")
3843 register Lisp_Object arg
;
3847 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
3849 arg
= Fprefix_numeric_value (arg
);
3852 Fset_window_hscroll (selected_window
,
3853 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
3857 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 1, "P",
3858 "Scroll selected window display ARG columns right.\n\
3859 Default for ARG is window width minus 2.")
3861 register Lisp_Object arg
;
3864 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
3866 arg
= Fprefix_numeric_value (arg
);
3869 Fset_window_hscroll (selected_window
,
3870 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
3874 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
3875 "Center point in window and redisplay frame. With ARG, put point on line ARG.\n\
3876 The desired position of point is always relative to the current window.\n\
3877 Just C-u as prefix means put point in the center of the window.\n\
3878 If ARG is omitted or nil, erases the entire frame and then\n\
3879 redraws with point in the center of the current window.")
3881 register Lisp_Object arg
;
3883 register struct window
*w
= XWINDOW (selected_window
);
3884 register int ht
= window_internal_height (w
);
3885 struct position pos
;
3886 struct buffer
*buf
= XBUFFER (w
->buffer
);
3887 struct buffer
*obuf
= current_buffer
;
3891 extern int frame_garbaged
;
3893 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
3894 XSETFASTINT (arg
, ht
/ 2);
3896 else if (CONSP (arg
)) /* Just C-u. */
3898 XSETFASTINT (arg
, ht
/ 2);
3902 arg
= Fprefix_numeric_value (arg
);
3903 CHECK_NUMBER (arg
, 0);
3907 XSETINT (arg
, XINT (arg
) + ht
);
3909 set_buffer_internal (buf
);
3910 pos
= *vmotion (PT
, - XINT (arg
), w
);
3912 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
3913 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
3914 || FETCH_BYTE (pos
.bytepos
- 1) == '\n')
3916 w
->force_start
= Qt
;
3917 set_buffer_internal (obuf
);
3922 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
3924 "Position point relative to window.\n\
3925 With no argument, position point at center of window.\n\
3926 An argument specifies vertical position within the window;\n\
3927 zero means top of window, negative means relative to bottom of window.")
3929 register Lisp_Object arg
;
3931 register struct window
*w
= XWINDOW (selected_window
);
3932 register int height
= window_internal_height (w
);
3937 XSETFASTINT (arg
, height
/ 2);
3940 arg
= Fprefix_numeric_value (arg
);
3942 XSETINT (arg
, XINT (arg
) + height
);
3945 start
= marker_position (w
->start
);
3946 XSETWINDOW (window
, w
);
3947 if (start
< BEGV
|| start
> ZV
)
3949 Fvertical_motion (make_number (- (height
/ 2)), window
);
3950 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
3951 w
->start_at_line_beg
= Fbolp ();
3952 w
->force_start
= Qt
;
3955 Fgoto_char (w
->start
);
3957 return Fvertical_motion (arg
, window
);
3962 /***********************************************************************
3963 Window Configuration
3964 ***********************************************************************/
3966 struct save_window_data
3968 EMACS_INT size_from_Lisp_Vector_struct
;
3969 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
3970 Lisp_Object frame_width
, frame_height
, frame_menu_bar_lines
;
3971 Lisp_Object frame_toolbar_lines
;
3972 Lisp_Object selected_frame
;
3973 Lisp_Object current_window
;
3974 Lisp_Object current_buffer
;
3975 Lisp_Object minibuf_scroll_window
;
3976 Lisp_Object root_window
;
3977 Lisp_Object focus_frame
;
3978 /* Record the values of window-min-width and window-min-height
3979 so that window sizes remain consistent with them. */
3980 Lisp_Object min_width
, min_height
;
3981 /* A vector, each of whose elements is a struct saved_window
3983 Lisp_Object saved_windows
;
3986 /* This is saved as a Lisp_Vector */
3989 /* these first two must agree with struct Lisp_Vector in lisp.h */
3990 EMACS_INT size_from_Lisp_Vector_struct
;
3991 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
3994 Lisp_Object buffer
, start
, pointm
, mark
;
3995 Lisp_Object left
, top
, width
, height
, hscroll
;
3996 Lisp_Object parent
, prev
;
3997 Lisp_Object start_at_line_beg
;
3998 Lisp_Object display_table
;
4000 #define SAVED_WINDOW_VECTOR_SIZE 14 /* Arg to Fmake_vector */
4002 #define SAVED_WINDOW_N(swv,n) \
4003 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
4005 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
4006 "Return t if OBJECT is a window-configuration object.")
4010 if (WINDOW_CONFIGURATIONP (object
))
4015 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
4016 "Return the frame that CONFIG, a window-configuration object, is about.")
4020 register struct save_window_data
*data
;
4021 struct Lisp_Vector
*saved_windows
;
4023 if (! WINDOW_CONFIGURATIONP (config
))
4024 wrong_type_argument (Qwindow_configuration_p
, config
);
4026 data
= (struct save_window_data
*) XVECTOR (config
);
4027 saved_windows
= XVECTOR (data
->saved_windows
);
4028 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
4031 DEFUN ("set-window-configuration", Fset_window_configuration
,
4032 Sset_window_configuration
, 1, 1, 0,
4033 "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\
4034 CONFIGURATION must be a value previously returned\n\
4035 by `current-window-configuration' (which see).\n\
4036 If CONFIGURATION was made from a frame that is now deleted,\n\
4037 only frame-independent values can be restored. In this case,\n\
4038 the return value is nil. Otherwise the value is t.")
4040 Lisp_Object configuration
;
4042 register struct save_window_data
*data
;
4043 struct Lisp_Vector
*saved_windows
;
4044 Lisp_Object new_current_buffer
;
4049 while (!WINDOW_CONFIGURATIONP (configuration
))
4050 wrong_type_argument (Qwindow_configuration_p
, configuration
);
4052 data
= (struct save_window_data
*) XVECTOR (configuration
);
4053 saved_windows
= XVECTOR (data
->saved_windows
);
4055 new_current_buffer
= data
->current_buffer
;
4056 if (NILP (XBUFFER (new_current_buffer
)->name
))
4057 new_current_buffer
= Qnil
;
4060 if (XBUFFER (new_current_buffer
) == current_buffer
)
4065 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
4068 /* If f is a dead frame, don't bother rebuilding its window tree.
4069 However, there is other stuff we should still try to do below. */
4070 if (FRAME_LIVE_P (f
))
4072 register struct window
*w
;
4073 register struct saved_window
*p
;
4074 struct window
*root_window
;
4075 struct window
**leaf_windows
;
4079 /* If the frame has been resized since this window configuration was
4080 made, we change the frame to the size specified in the
4081 configuration, restore the configuration, and then resize it
4082 back. We keep track of the prevailing height in these variables. */
4083 int previous_frame_height
= FRAME_HEIGHT (f
);
4084 int previous_frame_width
= FRAME_WIDTH (f
);
4085 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
4086 int previous_frame_toolbar_lines
= FRAME_TOOLBAR_LINES (f
);
4088 /* The mouse highlighting code could get screwed up
4089 if it runs during this. */
4092 if (XFASTINT (data
->frame_height
) != previous_frame_height
4093 || XFASTINT (data
->frame_width
) != previous_frame_width
)
4094 change_frame_size (f
, XFASTINT (data
->frame_height
),
4095 XFASTINT (data
->frame_width
), 0, 0);
4096 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
4097 if (XFASTINT (data
->frame_menu_bar_lines
)
4098 != previous_frame_menu_bar_lines
)
4099 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, make_number (0));
4100 #ifdef HAVE_WINDOW_SYSTEM
4101 if (XFASTINT (data
->frame_toolbar_lines
)
4102 != previous_frame_toolbar_lines
)
4103 x_set_toolbar_lines (f
, data
->frame_toolbar_lines
, make_number (0));
4107 if (! NILP (XWINDOW (selected_window
)->buffer
))
4109 w
= XWINDOW (selected_window
);
4110 set_marker_both (w
->pointm
,
4112 BUF_PT (XBUFFER (w
->buffer
)),
4113 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
4116 windows_or_buffers_changed
++;
4117 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4119 /* Problem: Freeing all matrices and later allocating them again
4120 is a serious redisplay flickering problem. What we would
4121 really like to do is to free only those matrices not reused
4123 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4125 = (struct window
**) alloca (count_windows (root_window
)
4126 * sizeof (struct window
*));
4127 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
4129 /* Temporarily avoid any problems with windows that are smaller
4130 than they are supposed to be. */
4131 window_min_height
= 1;
4132 window_min_width
= 1;
4135 Mark all windows now on frame as "deleted".
4136 Restoring the new configuration "undeletes" any that are in it.
4138 Save their current buffers in their height fields, since we may
4139 need it later, if a buffer saved in the configuration is now
4141 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4143 for (k
= 0; k
< saved_windows
->size
; k
++)
4145 p
= SAVED_WINDOW_N (saved_windows
, k
);
4146 w
= XWINDOW (p
->window
);
4149 if (!NILP (p
->parent
))
4150 w
->parent
= SAVED_WINDOW_N (saved_windows
,
4151 XFASTINT (p
->parent
))->window
;
4155 if (!NILP (p
->prev
))
4157 w
->prev
= SAVED_WINDOW_N (saved_windows
,
4158 XFASTINT (p
->prev
))->window
;
4159 XWINDOW (w
->prev
)->next
= p
->window
;
4164 if (!NILP (w
->parent
))
4166 if (EQ (p
->width
, XWINDOW (w
->parent
)->width
))
4168 XWINDOW (w
->parent
)->vchild
= p
->window
;
4169 XWINDOW (w
->parent
)->hchild
= Qnil
;
4173 XWINDOW (w
->parent
)->hchild
= p
->window
;
4174 XWINDOW (w
->parent
)->vchild
= Qnil
;
4179 /* If we squirreled away the buffer in the window's height,
4181 if (BUFFERP (w
->height
))
4182 w
->buffer
= w
->height
;
4185 w
->width
= p
->width
;
4186 w
->height
= p
->height
;
4187 w
->hscroll
= p
->hscroll
;
4188 w
->display_table
= p
->display_table
;
4189 XSETFASTINT (w
->last_modified
, 0);
4190 XSETFASTINT (w
->last_overlay_modified
, 0);
4192 /* Reinstall the saved buffer and pointers into it. */
4193 if (NILP (p
->buffer
))
4194 w
->buffer
= p
->buffer
;
4197 if (!NILP (XBUFFER (p
->buffer
)->name
))
4198 /* If saved buffer is alive, install it. */
4200 w
->buffer
= p
->buffer
;
4201 w
->start_at_line_beg
= p
->start_at_line_beg
;
4202 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
4203 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
4204 Fset_marker (XBUFFER (w
->buffer
)->mark
,
4205 p
->mark
, w
->buffer
);
4207 /* As documented in Fcurrent_window_configuration, don't
4208 save the location of point in the buffer which was current
4209 when the window configuration was recorded. */
4210 if (!EQ (p
->buffer
, new_current_buffer
)
4211 && XBUFFER (p
->buffer
) == current_buffer
)
4212 Fgoto_char (w
->pointm
);
4214 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
4215 /* Else unless window has a live buffer, get one. */
4217 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
4218 /* This will set the markers to beginning of visible
4220 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
4221 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
4222 w
->start_at_line_beg
= Qt
;
4225 /* Keeping window's old buffer; make sure the markers
4228 /* Set window markers at start of visible range. */
4229 if (XMARKER (w
->start
)->buffer
== 0)
4230 set_marker_restricted (w
->start
, make_number (0),
4232 if (XMARKER (w
->pointm
)->buffer
== 0)
4233 set_marker_restricted_both (w
->pointm
, w
->buffer
,
4234 BUF_PT (XBUFFER (w
->buffer
)),
4235 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
4236 w
->start_at_line_beg
= Qt
;
4241 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
4242 Fselect_window (data
->current_window
);
4243 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
4246 if (NILP (data
->focus_frame
)
4247 || (FRAMEP (data
->focus_frame
)
4248 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
4249 Fredirect_frame_focus (frame
, data
->focus_frame
);
4251 #if 0 /* I don't understand why this is needed, and it causes problems
4252 when the frame's old selected window has been deleted. */
4253 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
4254 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
4258 /* Set the screen height to the value it had before this function. */
4259 if (previous_frame_height
!= FRAME_HEIGHT (f
)
4260 || previous_frame_width
!= FRAME_WIDTH (f
))
4261 change_frame_size (f
, previous_frame_height
, previous_frame_width
,
4263 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
4264 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
4265 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
4267 #ifdef HAVE_WINDOW_SYSTEM
4268 if (previous_frame_toolbar_lines
!= FRAME_TOOLBAR_LINES (f
))
4269 x_set_toolbar_lines (f
, make_number (previous_frame_toolbar_lines
),
4274 /* Now, free glyph matrices in windows that were not reused. */
4275 for (i
= 0; i
< n_leaf_windows
; ++i
)
4276 if (NILP (leaf_windows
[i
]->buffer
))
4278 /* Assert it's not reused as a combination. */
4279 xassert (NILP (leaf_windows
[i
]->hchild
)
4280 && NILP (leaf_windows
[i
]->vchild
));
4281 free_window_matrices (leaf_windows
[i
]);
4282 SET_FRAME_GARBAGED (f
);
4289 /* Fselect_window will have made f the selected frame, so we
4290 reselect the proper frame here. Fhandle_switch_frame will change the
4291 selected window too, but that doesn't make the call to
4292 Fselect_window above totally superfluous; it still sets f's
4294 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
4295 do_switch_frame (data
->selected_frame
, Qnil
, 0);
4297 if (! NILP (Vwindow_configuration_change_hook
)
4298 && ! NILP (Vrun_hooks
))
4299 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
4302 if (!NILP (new_current_buffer
))
4304 Fset_buffer (new_current_buffer
);
4306 /* If the buffer that is current now is the same
4307 that was current before setting the window configuration,
4308 don't alter its PT. */
4313 /* Restore the minimum heights recorded in the configuration. */
4314 window_min_height
= XINT (data
->min_height
);
4315 window_min_width
= XINT (data
->min_width
);
4317 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
4319 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
4322 /* Mark all windows now on frame as deleted
4323 by setting their buffers to nil. */
4326 delete_all_subwindows (w
)
4327 register struct window
*w
;
4329 if (!NILP (w
->next
))
4330 delete_all_subwindows (XWINDOW (w
->next
));
4331 if (!NILP (w
->vchild
))
4332 delete_all_subwindows (XWINDOW (w
->vchild
));
4333 if (!NILP (w
->hchild
))
4334 delete_all_subwindows (XWINDOW (w
->hchild
));
4336 w
->height
= w
->buffer
; /* See Fset_window_configuration for excuse. */
4338 if (!NILP (w
->buffer
))
4341 /* We set all three of these fields to nil, to make sure that we can
4342 distinguish this dead window from any live window. Live leaf
4343 windows will have buffer set, and combination windows will have
4344 vchild or hchild set. */
4351 count_windows (window
)
4352 register struct window
*window
;
4354 register int count
= 1;
4355 if (!NILP (window
->next
))
4356 count
+= count_windows (XWINDOW (window
->next
));
4357 if (!NILP (window
->vchild
))
4358 count
+= count_windows (XWINDOW (window
->vchild
));
4359 if (!NILP (window
->hchild
))
4360 count
+= count_windows (XWINDOW (window
->hchild
));
4365 /* Fill vector FLAT with leaf windows under W, starting at index I.
4366 Value is last index + 1. */
4369 get_leaf_windows (w
, flat
, i
)
4371 struct window
**flat
;
4376 if (!NILP (w
->hchild
))
4377 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
4378 else if (!NILP (w
->vchild
))
4379 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
4383 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4390 /* Return a pointer to the glyph W's physical cursor is on. Value is
4391 null if W's current matrix is invalid, so that no meaningfull glyph
4395 get_phys_cursor_glyph (w
)
4398 struct glyph_row
*row
;
4399 struct glyph
*glyph
;
4401 if (w
->phys_cursor
.vpos
>= 0
4402 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
4403 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
4405 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
4406 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
4415 save_window_save (window
, vector
, i
)
4417 struct Lisp_Vector
*vector
;
4420 register struct saved_window
*p
;
4421 register struct window
*w
;
4422 register Lisp_Object tem
;
4424 for (;!NILP (window
); window
= w
->next
)
4426 p
= SAVED_WINDOW_N (vector
, i
);
4427 w
= XWINDOW (window
);
4429 XSETFASTINT (w
->temslot
, i
++);
4431 p
->buffer
= w
->buffer
;
4434 p
->width
= w
->width
;
4435 p
->height
= w
->height
;
4436 p
->hscroll
= w
->hscroll
;
4437 p
->display_table
= w
->display_table
;
4438 if (!NILP (w
->buffer
))
4440 /* Save w's value of point in the window configuration.
4441 If w is the selected window, then get the value of point
4442 from the buffer; pointm is garbage in the selected window. */
4443 if (EQ (window
, selected_window
))
4445 p
->pointm
= Fmake_marker ();
4446 set_marker_both (p
->pointm
, w
->buffer
,
4447 BUF_PT (XBUFFER (w
->buffer
)),
4448 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
4451 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
4453 p
->start
= Fcopy_marker (w
->start
, Qnil
);
4454 p
->start_at_line_beg
= w
->start_at_line_beg
;
4456 tem
= XBUFFER (w
->buffer
)->mark
;
4457 p
->mark
= Fcopy_marker (tem
, Qnil
);
4464 p
->start_at_line_beg
= Qnil
;
4467 if (NILP (w
->parent
))
4470 p
->parent
= XWINDOW (w
->parent
)->temslot
;
4475 p
->prev
= XWINDOW (w
->prev
)->temslot
;
4477 if (!NILP (w
->vchild
))
4478 i
= save_window_save (w
->vchild
, vector
, i
);
4479 if (!NILP (w
->hchild
))
4480 i
= save_window_save (w
->hchild
, vector
, i
);
4486 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
4487 Scurrent_window_configuration
, 0, 1, 0,
4488 "Return an object representing the current window configuration of FRAME.\n\
4489 If FRAME is nil or omitted, use the selected frame.\n\
4490 This describes the number of windows, their sizes and current buffers,\n\
4491 and for each displayed buffer, where display starts, and the positions of\n\
4492 point and mark. An exception is made for point in the current buffer:\n\
4493 its value is -not- saved.\n\
4494 This also records the currently selected frame, and FRAME's focus\n\
4495 redirection (see `redirect-frame-focus').")
4499 register Lisp_Object tem
;
4500 register int n_windows
;
4501 register struct save_window_data
*data
;
4502 register struct Lisp_Vector
*vec
;
4510 CHECK_LIVE_FRAME (frame
, 0);
4514 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4515 vec
= allocate_vectorlike (VECSIZE (struct save_window_data
));
4516 for (i
= 0; i
< VECSIZE (struct save_window_data
); i
++)
4517 vec
->contents
[i
] = Qnil
;
4518 vec
->size
= VECSIZE (struct save_window_data
);
4519 data
= (struct save_window_data
*)vec
;
4521 XSETFASTINT (data
->frame_width
, FRAME_WIDTH (f
));
4522 XSETFASTINT (data
->frame_height
, FRAME_HEIGHT (f
));
4523 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
4524 XSETFASTINT (data
->frame_toolbar_lines
, FRAME_TOOLBAR_LINES (f
));
4525 XSETFRAME (data
->selected_frame
, selected_frame
);
4526 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
4527 XSETBUFFER (data
->current_buffer
, current_buffer
);
4528 data
->minibuf_scroll_window
= Vminibuf_scroll_window
;
4529 data
->root_window
= FRAME_ROOT_WINDOW (f
);
4530 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
4531 XSETINT (data
->min_height
, window_min_height
);
4532 XSETINT (data
->min_width
, window_min_width
);
4533 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
4534 data
->saved_windows
= tem
;
4535 for (i
= 0; i
< n_windows
; i
++)
4536 XVECTOR (tem
)->contents
[i
]
4537 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
4538 save_window_save (FRAME_ROOT_WINDOW (f
),
4540 XSETWINDOW_CONFIGURATION (tem
, data
);
4544 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
4546 "Execute body, preserving window sizes and contents.\n\
4547 Restore which buffer appears in which window, where display starts,\n\
4548 and the value of point and mark for each window.\n\
4549 Also restore which buffer is current.\n\
4550 But do not preserve point in the current buffer.\n\
4551 Does not restore the value of point in current buffer.")
4555 register Lisp_Object val
;
4556 register int count
= specpdl_ptr
- specpdl
;
4558 record_unwind_protect (Fset_window_configuration
,
4559 Fcurrent_window_configuration (Qnil
));
4560 val
= Fprogn (args
);
4561 return unbind_to (count
, val
);
4565 /***********************************************************************
4567 ***********************************************************************/
4569 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
4571 "Set width of marginal areas of window WINDOW.\n\
4572 If window is nil or omitted, set margins of the currently selected window.\n\
4573 First parameter LEFT-WIDTH specifies the number of character\n\
4574 cells to reserve for the left marginal area. Second parameter\n\
4575 RIGHT-WIDTH does the same for the right marginal area.\n\
4576 A nil width parameter means no margin.")
4577 (left
, right
, window
)
4578 Lisp_Object window
, left
, right
;
4580 struct window
*w
= decode_window (window
);
4581 struct frame
*f
= XFRAME (w
->frame
);
4584 CHECK_NUMBER_OR_FLOAT (left
, 0);
4586 CHECK_NUMBER_OR_FLOAT (right
, 0);
4588 /* Check widths < 0 and translate a zero width to nil.
4589 Margins that are too wide have to be checked elsewhere. */
4590 if ((INTEGERP (left
) && XINT (left
) < 0)
4591 || (FLOATP (left
) && XFLOAT (left
)->data
<= 0))
4592 XSETFASTINT (left
, 0);
4593 if (INTEGERP (left
) && XFASTINT (left
) == 0)
4596 if ((INTEGERP (right
) && XINT (right
) < 0)
4597 || (FLOATP (right
) && XFLOAT (right
)->data
<= 0))
4598 XSETFASTINT (right
, 0);
4599 if (INTEGERP (right
) && XFASTINT (right
) == 0)
4602 w
->left_margin_width
= left
;
4603 w
->right_margin_width
= right
;
4605 ++windows_or_buffers_changed
;
4606 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
4611 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
4613 "Get width of marginal areas of window WINDOW.\n\
4614 If WINDOW is omitted or nil, use the currently selected window.\n\
4615 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).\n\
4616 If a marginal area does not exist, its width will be returned\n\
4621 struct window
*w
= decode_window (window
);
4622 return Fcons (w
->left_margin_width
, w
->right_margin_width
);
4627 /***********************************************************************
4629 ***********************************************************************/
4631 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 1, 0,
4632 "Return the amount by which WINDOW is scrolled vertically.\n\
4633 Use the selected window if WINDOW is nil or omitted.\n\
4634 Value is a multiple of the canonical character height of WINDOW.")
4642 window
= selected_window
;
4643 w
= XWINDOW (window
);
4644 f
= XFRAME (w
->frame
);
4646 if (FRAME_WINDOW_P (f
))
4647 return CANON_Y_FROM_PIXEL_Y (f
, w
->vscroll
);
4649 return make_number (0);
4653 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
4655 "Set amount by WINDOW should be scrolled vertically to VSCROLL.\n\
4656 WINDOW nil or omitted means use the selected window. VSCROLL is a\n\
4657 multiple of the canonical character height of WINDOW.")
4659 Lisp_Object vscroll
, window
;
4664 CHECK_NUMBER_OR_FLOAT (vscroll
, 0);
4667 window
= selected_window
;
4668 w
= XWINDOW (window
);
4669 f
= XFRAME (w
->frame
);
4671 if (FRAME_WINDOW_P (f
))
4673 int old_dy
= w
->vscroll
;
4674 w
->vscroll
= min (0, CANON_Y_UNIT (f
) * XFLOATINT (vscroll
));
4676 /* Adjust glyph matrix of the frame if the virtual display
4677 area becomes larger than before. */
4678 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
4681 /* Prevent redisplay shortcuts. */
4682 XBUFFER (w
->buffer
)->clip_changed
= 1;
4690 /***********************************************************************
4692 ***********************************************************************/
4694 /* Return 1 if window configurations C1 and C2
4695 describe the same state of affairs. This is used by Fequal. */
4698 compare_window_configurations (c1
, c2
, ignore_positions
)
4700 int ignore_positions
;
4702 register struct save_window_data
*d1
, *d2
;
4703 struct Lisp_Vector
*sw1
, *sw2
;
4706 d1
= (struct save_window_data
*) XVECTOR (c1
);
4707 d2
= (struct save_window_data
*) XVECTOR (c2
);
4708 sw1
= XVECTOR (d1
->saved_windows
);
4709 sw2
= XVECTOR (d2
->saved_windows
);
4711 if (! EQ (d1
->frame_width
, d2
->frame_width
))
4713 if (! EQ (d1
->frame_height
, d2
->frame_height
))
4715 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
4717 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
4719 /* Don't compare the current_window field directly.
4720 Instead see w1_is_current and w2_is_current, below. */
4721 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
4723 if (! ignore_positions
)
4724 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
4726 /* Don't compare the root_window field.
4727 We don't require the two configurations
4728 to use the same window object,
4729 and the two root windows must be equivalent
4730 if everything else compares equal. */
4731 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
4733 if (! EQ (d1
->min_width
, d2
->min_width
))
4735 if (! EQ (d1
->min_height
, d2
->min_height
))
4738 /* Verify that the two confis have the same number of windows. */
4739 if (sw1
->size
!= sw2
->size
)
4742 for (i
= 0; i
< sw1
->size
; i
++)
4744 struct saved_window
*p1
, *p2
;
4745 int w1_is_current
, w2_is_current
;
4747 p1
= SAVED_WINDOW_N (sw1
, i
);
4748 p2
= SAVED_WINDOW_N (sw2
, i
);
4750 /* Verify that the current windows in the two
4751 configurations correspond to each other. */
4752 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
4753 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
4755 if (w1_is_current
!= w2_is_current
)
4758 /* Verify that the corresponding windows do match. */
4759 if (! EQ (p1
->buffer
, p2
->buffer
))
4761 if (! EQ (p1
->left
, p2
->left
))
4763 if (! EQ (p1
->top
, p2
->top
))
4765 if (! EQ (p1
->width
, p2
->width
))
4767 if (! EQ (p1
->height
, p2
->height
))
4769 if (! EQ (p1
->display_table
, p2
->display_table
))
4771 if (! EQ (p1
->parent
, p2
->parent
))
4773 if (! EQ (p1
->prev
, p2
->prev
))
4775 if (! ignore_positions
)
4777 if (! EQ (p1
->hscroll
, p2
->hscroll
))
4779 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
4781 if (NILP (Fequal (p1
->start
, p2
->start
)))
4783 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
4785 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
4793 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
4794 Scompare_window_configurations
, 2, 2, 0,
4795 "Compare two window configurations as regards the structure of windows.\n\
4796 This function ignores details such as the values of point and mark\n\
4797 and scrolling positions.")
4801 if (compare_window_configurations (x
, y
, 1))
4809 selected_frame
= make_terminal_frame ();
4810 XSETFRAME (Vterminal_frame
, selected_frame
);
4811 minibuf_window
= selected_frame
->minibuffer_window
;
4812 selected_window
= selected_frame
->selected_window
;
4813 last_nonminibuf_frame
= selected_frame
;
4815 window_initialized
= 1;
4821 Qleft_bitmap_area
= intern ("left-bitmap-area");
4822 staticpro (&Qleft_bitmap_area
);
4823 Qright_bitmap_area
= intern ("right-bitmap-area");
4824 staticpro (&Qright_bitmap_area
);
4826 Qfixed_window_size
= intern ("fixed-window-size");
4827 staticpro (&Qfixed_window_size
);
4829 staticpro (&Qwindow_configuration_change_hook
);
4830 Qwindow_configuration_change_hook
4831 = intern ("window-configuration-change-hook");
4833 Qwindowp
= intern ("windowp");
4834 staticpro (&Qwindowp
);
4836 Qwindow_configuration_p
= intern ("window-configuration-p");
4837 staticpro (&Qwindow_configuration_p
);
4839 Qwindow_live_p
= intern ("window-live-p");
4840 staticpro (&Qwindow_live_p
);
4842 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
4843 staticpro (&Qtemp_buffer_show_hook
);
4845 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
4846 "Non-nil means call as function to display a help buffer.\n\
4847 The function is called with one argument, the buffer to be displayed.\n\
4848 Used by `with-output-to-temp-buffer'.\n\
4849 If this function is used, then it must do the entire job of showing\n\
4850 the buffer; `temp-buffer-show-hook' is not run unless this function runs it.");
4851 Vtemp_buffer_show_function
= Qnil
;
4853 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
4854 "If non-nil, function to call to handle `display-buffer'.\n\
4855 It will receive two args, the buffer and a flag which if non-nil means\n\
4856 that the currently selected window is not acceptable.\n\
4857 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\
4858 work using this function.");
4859 Vdisplay_buffer_function
= Qnil
;
4861 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
4862 "Non-nil means it is the window that C-M-v in minibuffer should scroll.");
4863 Vminibuf_scroll_window
= Qnil
;
4865 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
4866 "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.");
4867 Vother_window_scroll_buffer
= Qnil
;
4869 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
4870 "*Non-nil means `display-buffer' should make a separate frame.");
4873 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
4874 "Function to call to handle automatic new frame creation.\n\
4875 It is called with no arguments and should return a newly created frame.\n\
4877 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\
4878 where `pop-up-frame-alist' would hold the default frame parameters.");
4879 Vpop_up_frame_function
= Qnil
;
4881 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
4882 "*List of buffer names that should have their own special frames.\n\
4883 Displaying a buffer whose name is in this list makes a special frame for it\n\
4884 using `special-display-function'. See also `special-display-regexps'.\n\
4886 An element of the list can be a list instead of just a string.\n\
4887 There are two ways to use a list as an element:\n\
4888 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)\n\
4889 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
4890 In the latter case, FUNCTION is called with BUFFER as the first argument,\n\
4891 followed by OTHER-ARGS--it can display BUFFER in any way it likes.\n\
4892 All this is done by the function found in `special-display-function'.\n\
4894 If this variable appears \"not to work\", because you add a name to it\n\
4895 but that buffer still appears in the selected window, look at the\n\
4896 values of `same-window-buffer-names' and `same-window-regexps'.\n\
4897 Those variables take precedence over this one.");
4898 Vspecial_display_buffer_names
= Qnil
;
4900 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
4901 "*List of regexps saying which buffers should have their own special frames.\n\
4902 If a buffer name matches one of these regexps, it gets its own frame.\n\
4903 Displaying a buffer whose name is in this list makes a special frame for it\n\
4904 using `special-display-function'.\n\
4906 An element of the list can be a list instead of just a string.\n\
4907 There are two ways to use a list as an element:\n\
4908 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)\n\
4909 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
4910 In the latter case, FUNCTION is called with the buffer as first argument,\n\
4911 followed by OTHER-ARGS--it can display the buffer in any way it likes.\n\
4912 All this is done by the function found in `special-display-function'.\n\
4914 If this variable appears \"not to work\", because you add a regexp to it\n\
4915 but the matching buffers still appear in the selected window, look at the\n\
4916 values of `same-window-buffer-names' and `same-window-regexps'.\n\
4917 Those variables take precedence over this one.");
4918 Vspecial_display_regexps
= Qnil
;
4920 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
4921 "Function to call to make a new frame for a special buffer.\n\
4922 It is called with two arguments, the buffer and optional buffer specific\n\
4923 data, and should return a window displaying that buffer.\n\
4924 The default value makes a separate frame for the buffer,\n\
4925 using `special-display-frame-alist' to specify the frame parameters.\n\
4927 A buffer is special if its is listed in `special-display-buffer-names'\n\
4928 or matches a regexp in `special-display-regexps'.");
4929 Vspecial_display_function
= Qnil
;
4931 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
4932 "*List of buffer names that should appear in the selected window.\n\
4933 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'\n\
4934 switches to it in the selected window, rather than making it appear\n\
4935 in some other window.\n\
4937 An element of the list can be a cons cell instead of just a string.\n\
4938 Then the car must be a string, which specifies the buffer name.\n\
4939 This is for compatibility with `special-display-buffer-names';\n\
4940 the cdr of the cons cell is ignored.\n\
4942 See also `same-window-regexps'.");
4943 Vsame_window_buffer_names
= Qnil
;
4945 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
4946 "*List of regexps saying which buffers should appear in the selected window.\n\
4947 If a buffer name matches one of these regexps, then displaying it\n\
4948 using `display-buffer' or `pop-to-buffer' switches to it\n\
4949 in the selected window, rather than making it appear in some other window.\n\
4951 An element of the list can be a cons cell instead of just a string.\n\
4952 Then the car must be a string, which specifies the buffer name.\n\
4953 This is for compatibility with `special-display-buffer-names';\n\
4954 the cdr of the cons cell is ignored.\n\
4956 See also `same-window-buffer-names'.");
4957 Vsame_window_regexps
= Qnil
;
4959 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
4960 "*Non-nil means display-buffer should make new windows.");
4963 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
4964 "*Number of lines of continuity when scrolling by screenfuls.");
4965 next_screen_context_lines
= 2;
4967 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
4968 "*display-buffer would prefer to split the largest window if this large.\n\
4969 If there is only one window, it is split regardless of this value.");
4970 split_height_threshold
= 500;
4972 DEFVAR_INT ("window-min-height", &window_min_height
,
4973 "*Delete any window less than this tall (including its mode line).");
4974 window_min_height
= 4;
4976 DEFVAR_INT ("window-min-width", &window_min_width
,
4977 "*Delete any window less than this wide.");
4978 window_min_width
= 10;
4980 DEFVAR_LISP ("scroll-preserve-screen-position",
4981 &Vscroll_preserve_screen_position
,
4982 "*Nonzero means scroll commands move point to keep its screen line unchanged.");
4983 Vscroll_preserve_screen_position
= Qnil
;
4985 DEFVAR_LISP ("window-configuration-change-hook",
4986 &Vwindow_configuration_change_hook
,
4987 "Functions to call when window configuration changes.\n\
4988 The selected frame is the one whose configuration has changed.");
4989 Vwindow_configuration_change_hook
= Qnil
;
4991 defsubr (&Sselected_window
);
4992 defsubr (&Sminibuffer_window
);
4993 defsubr (&Swindow_minibuffer_p
);
4994 defsubr (&Swindowp
);
4995 defsubr (&Swindow_live_p
);
4996 defsubr (&Spos_visible_in_window_p
);
4997 defsubr (&Swindow_buffer
);
4998 defsubr (&Swindow_height
);
4999 defsubr (&Swindow_width
);
5000 defsubr (&Swindow_hscroll
);
5001 defsubr (&Sset_window_hscroll
);
5002 defsubr (&Swindow_redisplay_end_trigger
);
5003 defsubr (&Sset_window_redisplay_end_trigger
);
5004 defsubr (&Swindow_edges
);
5005 defsubr (&Scoordinates_in_window_p
);
5006 defsubr (&Swindow_at
);
5007 defsubr (&Swindow_point
);
5008 defsubr (&Swindow_start
);
5009 defsubr (&Swindow_end
);
5010 defsubr (&Sset_window_point
);
5011 defsubr (&Sset_window_start
);
5012 defsubr (&Swindow_dedicated_p
);
5013 defsubr (&Sset_window_dedicated_p
);
5014 defsubr (&Swindow_display_table
);
5015 defsubr (&Sset_window_display_table
);
5016 defsubr (&Snext_window
);
5017 defsubr (&Sprevious_window
);
5018 defsubr (&Sother_window
);
5019 defsubr (&Sget_lru_window
);
5020 defsubr (&Sget_largest_window
);
5021 defsubr (&Sget_buffer_window
);
5022 defsubr (&Sdelete_other_windows
);
5023 defsubr (&Sdelete_windows_on
);
5024 defsubr (&Sreplace_buffer_in_windows
);
5025 defsubr (&Sdelete_window
);
5026 defsubr (&Sset_window_buffer
);
5027 defsubr (&Sselect_window
);
5028 defsubr (&Sspecial_display_p
);
5029 defsubr (&Ssame_window_p
);
5030 defsubr (&Sdisplay_buffer
);
5031 defsubr (&Ssplit_window
);
5032 defsubr (&Senlarge_window
);
5033 defsubr (&Sshrink_window
);
5034 defsubr (&Sscroll_up
);
5035 defsubr (&Sscroll_down
);
5036 defsubr (&Sscroll_left
);
5037 defsubr (&Sscroll_right
);
5038 defsubr (&Sother_window_for_scrolling
);
5039 defsubr (&Sscroll_other_window
);
5040 defsubr (&Srecenter
);
5041 defsubr (&Smove_to_window_line
);
5042 defsubr (&Swindow_configuration_p
);
5043 defsubr (&Swindow_configuration_frame
);
5044 defsubr (&Sset_window_configuration
);
5045 defsubr (&Scurrent_window_configuration
);
5046 defsubr (&Ssave_window_excursion
);
5047 defsubr (&Sset_window_margins
);
5048 defsubr (&Swindow_margins
);
5049 defsubr (&Swindow_vscroll
);
5050 defsubr (&Sset_window_vscroll
);
5051 defsubr (&Scompare_window_configurations
);
5057 initial_define_key (control_x_map
, '1', "delete-other-windows");
5058 initial_define_key (control_x_map
, '2', "split-window");
5059 initial_define_key (control_x_map
, '0', "delete-window");
5060 initial_define_key (control_x_map
, 'o', "other-window");
5061 initial_define_key (control_x_map
, '^', "enlarge-window");
5062 initial_define_key (control_x_map
, '<', "scroll-left");
5063 initial_define_key (control_x_map
, '>', "scroll-right");
5065 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
5066 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
5067 initial_define_key (meta_map
, 'v', "scroll-down");
5069 initial_define_key (global_map
, Ctl('L'), "recenter");
5070 initial_define_key (meta_map
, 'r', "move-to-window-line");