1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985-1987, 1993-1998, 2000-2011
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
35 #include "dispextern.h"
36 #include "blockinput.h"
37 #include "intervals.h"
38 #include "termhooks.h" /* For FRAME_TERMINAL. */
42 #endif /* HAVE_X_WINDOWS */
53 Lisp_Object Qwindowp
, Qwindow_live_p
;
54 static Lisp_Object Qwindow_configuration_p
, Qrecord_window_buffer
;
55 static Lisp_Object Qwindow_deletable_p
, Qdelete_window
, Qdisplay_buffer
;
56 static Lisp_Object Qreplace_buffer_in_windows
, Qget_mru_window
;
57 static Lisp_Object Qresize_root_window
, Qresize_root_window_vertically
;
58 static Lisp_Object Qscroll_up
, Qscroll_down
, Qscroll_command
;
59 static Lisp_Object Qsafe
, Qabove
, Qbelow
;
60 static Lisp_Object Qauto_buffer_name
;
62 static Lisp_Object Qwindow_size_fixed
;
64 static int displayed_window_lines (struct window
*);
65 static struct window
*decode_window (Lisp_Object
);
66 static int count_windows (struct window
*);
67 static int get_leaf_windows (struct window
*, struct window
**, int);
68 static void window_scroll (Lisp_Object
, int, int, int);
69 static void window_scroll_pixel_based (Lisp_Object
, int, int, int);
70 static void window_scroll_line_based (Lisp_Object
, int, int, int);
71 static int window_min_size_1 (struct window
*, int, int);
72 static int window_min_size_2 (struct window
*, int, int);
73 static int window_min_size (struct window
*, int, int, int, int *);
74 static void size_window (Lisp_Object
, int, int, int, int, int);
75 static int freeze_window_start (struct window
*, void *);
76 static int window_fixed_size_p (struct window
*, int, int);
77 static void enlarge_window (Lisp_Object
, int, int);
78 static Lisp_Object
window_list (void);
79 static int add_window_to_list (struct window
*, void *);
80 static int candidate_window_p (Lisp_Object
, Lisp_Object
, Lisp_Object
,
82 static Lisp_Object
next_window (Lisp_Object
, Lisp_Object
,
84 static void decode_next_window_args (Lisp_Object
*, Lisp_Object
*,
86 static void foreach_window (struct frame
*,
87 int (* fn
) (struct window
*, void *),
89 static int foreach_window_1 (struct window
*,
90 int (* fn
) (struct window
*, void *),
92 static Lisp_Object
window_list_1 (Lisp_Object
, Lisp_Object
, Lisp_Object
);
93 static void resize_window_apply (struct window
*, int);
94 static Lisp_Object
select_window (Lisp_Object
, Lisp_Object
, int);
96 /* This is the window in which the terminal's cursor should
97 be left when nothing is being done with it. This must
98 always be a leaf window, and its buffer is selected by
99 the top level editing loop at the end of each command.
101 This value is always the same as
102 FRAME_SELECTED_WINDOW (selected_frame). */
103 Lisp_Object selected_window
;
105 /* A list of all windows for use by next_window and Fwindow_list.
106 Functions creating or deleting windows should invalidate this cache
107 by setting it to nil. */
108 Lisp_Object Vwindow_list
;
110 /* The mini-buffer window of the selected frame.
111 Note that you cannot test for mini-bufferness of an arbitrary window
112 by comparing against this; but you can test for mini-bufferness of
113 the selected window. */
114 Lisp_Object minibuf_window
;
116 /* Non-nil means it is the window whose mode line should be
117 shown as the selected window when the minibuffer is selected. */
118 Lisp_Object minibuf_selected_window
;
120 /* Hook run at end of temp_output_buffer_show. */
121 static Lisp_Object Qtemp_buffer_show_hook
;
123 /* Incremented for each window created. */
124 static int sequence_number
;
126 /* Nonzero after init_window_once has finished. */
127 static int window_initialized
;
129 /* Hook to run when window config changes. */
130 static Lisp_Object Qwindow_configuration_change_hook
;
132 /* Incremented by 1 whenever a window is deleted. */
133 static int window_deletion_count
;
135 /* Used by the function window_scroll_pixel_based */
136 static int window_scroll_pixel_based_preserve_x
;
137 static int window_scroll_pixel_based_preserve_y
;
139 /* Same for window_scroll_line_based. */
140 static int window_scroll_preserve_hpos
;
141 static int window_scroll_preserve_vpos
;
143 static struct window
*
144 decode_window (register Lisp_Object window
)
147 return XWINDOW (selected_window
);
149 CHECK_LIVE_WINDOW (window
);
150 return XWINDOW (window
);
153 static struct window
*
154 decode_any_window (register Lisp_Object window
)
157 return XWINDOW (selected_window
);
159 CHECK_WINDOW (window
);
160 return XWINDOW (window
);
163 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
164 doc
: /* Return t if OBJECT is a window and nil otherwise. */)
167 return WINDOWP (object
) ? Qt
: Qnil
;
170 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
171 doc
: /* Return t if OBJECT is a live window and nil otherwise.
172 A live window is a window that displays a buffer. */)
175 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
178 /* Frames and windows. */
179 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 1, 1, 0,
180 doc
: /* Return the frame that window WINDOW is on.
181 WINDOW can be any window and defaults to the selected one. */)
184 return decode_any_window (window
)->frame
;
187 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
188 doc
: /* Return the root window of FRAME_OR_WINDOW.
189 If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
190 Else if FRAME_OR_WINDOW denotes any window, return the root window of
191 that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
192 the root window of that frame. */)
193 (Lisp_Object frame_or_window
)
197 if (NILP (frame_or_window
))
198 window
= SELECTED_FRAME ()->root_window
;
199 else if (WINDOWP (frame_or_window
))
200 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
203 CHECK_LIVE_FRAME (frame_or_window
);
204 window
= XFRAME (frame_or_window
)->root_window
;
210 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
211 doc
: /* Return the window used now for minibuffers.
212 If the optional argument FRAME is specified, return the minibuffer window
213 used by that frame. */)
217 frame
= selected_frame
;
218 CHECK_LIVE_FRAME (frame
);
219 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
222 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
,
223 Swindow_minibuffer_p
, 0, 1, 0,
224 doc
: /* Return non-nil if WINDOW is a minibuffer window.
225 WINDOW can be any window and defaults to the selected one. */)
228 return MINI_WINDOW_P (decode_any_window (window
)) ? Qt
: Qnil
;
231 /* Don't move this to window.el - this must be a safe routine. */
232 DEFUN ("frame-first-window", Fframe_first_window
, Sframe_first_window
, 0, 1, 0,
233 doc
: /* Return the topmost, leftmost live window on FRAME_OR_WINDOW.
234 If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
235 Else if FRAME_OR_WINDOW denotes any window, return the first window of
236 that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
237 the first window of that frame. */)
238 (Lisp_Object frame_or_window
)
242 if (NILP (frame_or_window
))
243 window
= SELECTED_FRAME ()->root_window
;
244 else if (WINDOWP (frame_or_window
))
245 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
248 CHECK_LIVE_FRAME (frame_or_window
);
249 window
= XFRAME (frame_or_window
)->root_window
;
252 while (NILP (XWINDOW (window
)->buffer
))
254 if (! NILP (XWINDOW (window
)->hchild
))
255 window
= XWINDOW (window
)->hchild
;
256 else if (! NILP (XWINDOW (window
)->vchild
))
257 window
= XWINDOW (window
)->vchild
;
265 DEFUN ("frame-selected-window", Fframe_selected_window
,
266 Sframe_selected_window
, 0, 1, 0,
267 doc
: /* Return the selected window of FRAME_OR_WINDOW.
268 If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
269 Else if FRAME_OR_WINDOW denotes any window, return the selected window
270 of that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
271 the selected window of that frame. */)
272 (Lisp_Object frame_or_window
)
276 if (NILP (frame_or_window
))
277 window
= SELECTED_FRAME ()->selected_window
;
278 else if (WINDOWP (frame_or_window
))
279 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->selected_window
;
282 CHECK_LIVE_FRAME (frame_or_window
);
283 window
= XFRAME (frame_or_window
)->selected_window
;
289 DEFUN ("set-frame-selected-window", Fset_frame_selected_window
,
290 Sset_frame_selected_window
, 2, 3, 0,
291 doc
: /* Set selected window of FRAME to WINDOW.
292 FRAME must be a live frame and defaults to the selected one. If FRAME
293 is the selected frame, this makes WINDOW the selected window. Optional
294 argument NORECORD non-nil means to neither change the order of recently
295 selected windows nor the buffer list. WINDOW must denote a live window.
297 (Lisp_Object frame
, Lisp_Object window
, Lisp_Object norecord
)
300 frame
= selected_frame
;
302 CHECK_LIVE_FRAME (frame
);
303 CHECK_LIVE_WINDOW (window
);
305 if (! EQ (frame
, WINDOW_FRAME (XWINDOW (window
))))
306 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
308 if (EQ (frame
, selected_frame
))
309 return Fselect_window (window
, norecord
);
311 return XFRAME (frame
)->selected_window
= window
;
314 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
315 doc
: /* Return the selected window.
316 The selected window is the window in which the standard cursor for
317 selected windows appears and to which many commands apply. */)
320 return selected_window
;
323 /* If select_window is called with inhibit_point_swap non-zero it will
324 not store point of the old selected window's buffer back into that
325 window's pointm slot. This is needed by Fset_window_configuration to
326 avoid that the display routine is called with selected_window set to
327 Qnil causing a subsequent crash. */
329 select_window (Lisp_Object window
, Lisp_Object norecord
, int inhibit_point_swap
)
331 register struct window
*w
;
332 register struct window
*ow
;
335 CHECK_LIVE_WINDOW (window
);
337 w
= XWINDOW (window
);
338 w
->frozen_window_start_p
= 0;
342 ++window_select_count
;
343 XSETFASTINT (w
->use_time
, window_select_count
);
344 record_buffer (w
->buffer
);
347 if (EQ (window
, selected_window
) && !inhibit_point_swap
)
350 sf
= SELECTED_FRAME ();
351 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
353 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
354 /* Use this rather than Fhandle_switch_frame
355 so that FRAME_FOCUS_FRAME is moved appropriately as we
356 move around in the state where a minibuffer in a separate
358 Fselect_frame (WINDOW_FRAME (w
), norecord
);
359 /* Fselect_frame called us back so we've done all the work already. */
360 eassert (EQ (window
, selected_window
));
364 sf
->selected_window
= window
;
366 /* Store the current buffer's actual point into the
367 old selected window. It belongs to that window,
368 and when the window is not selected, must be in the window. */
369 if (!inhibit_point_swap
)
371 ow
= XWINDOW (selected_window
);
372 if (! NILP (ow
->buffer
))
373 set_marker_both (ow
->pointm
, ow
->buffer
,
374 BUF_PT (XBUFFER (ow
->buffer
)),
375 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
378 selected_window
= window
;
380 Fset_buffer (w
->buffer
);
382 BVAR (XBUFFER (w
->buffer
), last_selected_window
) = window
;
384 /* Go to the point recorded in the window.
385 This is important when the buffer is in more
386 than one window. It also matters when
387 redisplay_window has altered point after scrolling,
388 because it makes the change only in the window. */
390 register EMACS_INT new_point
= marker_position (w
->pointm
);
391 if (new_point
< BEGV
)
393 else if (new_point
> ZV
)
399 windows_or_buffers_changed
++;
403 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
404 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
405 Also make WINDOW's buffer current and make WINDOW the frame's selected
406 window. Return WINDOW.
408 Optional second arg NORECORD non-nil means do not put this buffer at the
409 front of the buffer list and do not make this window the most recently
412 Note that the main editor command loop sets the current buffer to the
413 buffer of the selected window before each command. */)
414 (register Lisp_Object window
, Lisp_Object norecord
)
416 return select_window (window
, norecord
, 0);
419 DEFUN ("window-clone-number", Fwindow_clone_number
, Swindow_clone_number
, 0, 1, 0,
420 doc
: /* Return WINDOW's clone number.
421 WINDOW can be any window and defaults to the selected one. */)
424 return decode_any_window (window
)->clone_number
;
427 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
428 doc
: /* Return the buffer that WINDOW is displaying.
429 WINDOW can be any window and defaults to the selected one.
430 If WINDOW is an internal window return nil. */)
433 return decode_any_window (window
)->buffer
;
436 DEFUN ("window-parent", Fwindow_parent
, Swindow_parent
, 0, 1, 0,
437 doc
: /* Return WINDOW's parent window.
438 WINDOW can be any window and defaults to the selected one.
439 Return nil if WINDOW has no parent. */)
442 return decode_any_window (window
)->parent
;
445 DEFUN ("window-vchild", Fwindow_vchild
, Swindow_vchild
, 0, 1, 0,
446 doc
: /* Return WINDOW's first vertical child window.
447 WINDOW can be any window and defaults to the selected one.
448 Return nil if WINDOW has no vertical child. */)
451 return decode_any_window (window
)->vchild
;
454 DEFUN ("window-hchild", Fwindow_hchild
, Swindow_hchild
, 0, 1, 0,
455 doc
: /* Return WINDOW's first horizontal child window.
456 WINDOW can be any window and defaults to the selected one.
457 Return nil if WINDOW has no horizontal child. */)
460 return decode_any_window (window
)->hchild
;
463 DEFUN ("window-next", Fwindow_next
, Swindow_next
, 0, 1, 0,
464 doc
: /* Return WINDOW's right sibling window.
465 WINDOW can be any window and defaults to the selected one.
466 Return nil if WINDOW has no right sibling. */)
469 return decode_any_window (window
)->next
;
472 DEFUN ("window-prev", Fwindow_prev
, Swindow_prev
, 0, 1, 0,
473 doc
: /* Return WINDOW's left sibling window.
474 WINDOW can be any window and defaults to the selected one.
475 Return nil if WINDOW has no left sibling. */)
478 return decode_any_window (window
)->prev
;
481 DEFUN ("window-splits", Fwindow_splits
, Swindow_splits
, 0, 1, 0,
482 doc
: /* Return splits status for WINDOW.
483 WINDOW can be any window and defaults to the selected one.
485 If the value returned by this function is nil and WINDOW is resized, the
486 corresponding space is preferably taken from (or given to) WINDOW's
487 right sibling. When WINDOW is deleted, its space is given to its left
490 If the value returned by this function is non-nil, resizing and deleting
491 WINDOW may resize all windows in the same combination. */)
494 return decode_any_window (window
)->splits
;
497 DEFUN ("set-window-splits", Fset_window_splits
, Sset_window_splits
, 2, 2, 0,
498 doc
: /* Set splits status of WINDOW to STATUS.
499 WINDOW can be any window and defaults to the selected one. Return
502 If STATUS is nil and WINDOW is later resized, the corresponding space is
503 preferably taken from (or given to) WINDOW's right sibling. When WINDOW
504 is deleted, its space is given to its left sibling.
506 If STATUS is non-nil, resizing and deleting WINDOW may resize all
507 windows in the same combination. */)
508 (Lisp_Object window
, Lisp_Object status
)
510 register struct window
*w
= decode_any_window (window
);
517 DEFUN ("window-nest", Fwindow_nest
, Swindow_nest
, 0, 1, 0,
518 doc
: /* Return nest status of WINDOW.
519 WINDOW can be any window and defaults to the selected one.
521 If the return value is nil, subwindows of WINDOW can be recombined with
522 WINDOW's siblings. A return value of non-nil means that subwindows of
523 WINDOW are never \(re-)combined with WINDOW's siblings. */)
526 return decode_any_window (window
)->nest
;
529 DEFUN ("set-window-nest", Fset_window_nest
, Sset_window_nest
, 2, 2, 0,
530 doc
: /* Set nest status of WINDOW to STATUS.
531 WINDOW can be any window and defaults to the selected one. Return
534 If STATUS is nil, subwindows of WINDOW can be recombined with WINDOW's
535 siblings. STATUS non-nil means that subwindows of WINDOW are never
536 \(re-)combined with WINDOW's siblings. */)
537 (Lisp_Object window
, Lisp_Object status
)
539 register struct window
*w
= decode_any_window (window
);
546 DEFUN ("window-use-time", Fwindow_use_time
, Swindow_use_time
, 0, 1, 0,
547 doc
: /* Return WINDOW's use time.
548 WINDOW defaults to the selected window. The window with the highest use
549 time is the most recently selected one. The window with the lowest use
550 time is the least recently selected one. */)
553 return decode_window (window
)->use_time
;
556 DEFUN ("window-total-size", Fwindow_total_size
, Swindow_total_size
, 0, 2, 0,
557 doc
: /* Return the total number of lines of WINDOW.
558 WINDOW can be any window and defaults to the selected one. The return
559 value includes WINDOW's mode line and header line, if any. If WINDOW
560 is internal, the return value is the sum of the total number of lines
561 of WINDOW's child windows if these are vertically combined and the
562 height of WINDOW's first child otherwise.
564 Optional argument HORIZONTAL non-nil means return the total number of
565 columns of WINDOW. In this case the return value includes any vertical
566 dividers or scrollbars of WINDOW. If WINDOW is internal, the return
567 value is the sum of the total number of columns of WINDOW's child
568 windows if they are horizontally combined and the width of WINDOW's
569 first child otherwise. */)
570 (Lisp_Object window
, Lisp_Object horizontal
)
572 if (NILP (horizontal
))
573 return decode_any_window (window
)->total_lines
;
575 return decode_any_window (window
)->total_cols
;
578 DEFUN ("window-new-total", Fwindow_new_total
, Swindow_new_total
, 0, 1, 0,
579 doc
: /* Return new total size of WINDOW.
580 WINDOW defaults to the selected window. */)
583 return decode_any_window (window
)->new_total
;
586 DEFUN ("window-normal-size", Fwindow_normal_size
, Swindow_normal_size
, 0, 2, 0,
587 doc
: /* Return normal height of WINDOW.
588 WINDOW can be any window and defaults to the selected one. Optional
589 argument HORIZONTAL non-nil means return normal width of WINDOW. */)
590 (Lisp_Object window
, Lisp_Object horizontal
)
592 if (NILP (horizontal
))
593 return decode_any_window (window
)->normal_lines
;
595 return decode_any_window (window
)->normal_cols
;
598 DEFUN ("window-new-normal", Fwindow_new_normal
, Swindow_new_normal
, 0, 1, 0,
599 doc
: /* Return new normal size of WINDOW.
600 WINDOW can be any window and defaults to the selected one. */)
603 return decode_any_window (window
)->new_normal
;
606 DEFUN ("window-left-column", Fwindow_left_column
, Swindow_left_column
, 0, 1, 0,
607 doc
: /* Return left column of WINDOW.
608 WINDOW can be any window and defaults to the selected one. */)
611 return decode_any_window (window
)->left_col
;
614 DEFUN ("window-top-line", Fwindow_top_line
, Swindow_top_line
, 0, 1, 0,
615 doc
: /* Return top line of WINDOW.
616 WINDOW can be any window and defaults to the selected one. */)
619 return decode_any_window (window
)->top_line
;
622 /* Return the number of lines of W's body. Don't count any mode or
626 window_body_lines (struct window
*w
)
628 int height
= XFASTINT (w
->total_lines
);
630 if (!MINI_WINDOW_P (w
))
632 if (WINDOW_WANTS_MODELINE_P (w
))
634 if (WINDOW_WANTS_HEADER_LINE_P (w
))
641 /* Return the number of columns of W's body. Don't count columns
642 occupied by the scroll bar or the vertical bar separating W from its
643 right sibling. On window-systems don't count fringes or display
647 window_body_cols (struct window
*w
)
649 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
650 int width
= XINT (w
->total_cols
);
652 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
653 /* Scroll bars occupy a few columns. */
654 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
655 else if (!FRAME_WINDOW_P (f
)
656 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
657 /* The column of `|' characters separating side-by-side windows
658 occupies one column only. */
661 if (FRAME_WINDOW_P (f
))
662 /* On window-systems, fringes and display margins cannot be
663 used for normal text. */
664 width
-= (WINDOW_FRINGE_COLS (w
)
665 + WINDOW_LEFT_MARGIN_COLS (w
)
666 + WINDOW_RIGHT_MARGIN_COLS (w
));
671 DEFUN ("window-body-size", Fwindow_body_size
, Swindow_body_size
, 0, 2, 0,
672 doc
: /* Return the number of lines of WINDOW's body.
673 WINDOW must be a live window and defaults to the selected one. The
674 return value does not include WINDOW's mode line and header line, if
677 Optional argument HORIZONTAL non-nil means return the number of columns
678 of WINDOW's body. In this case, the return value does not include any
679 vertical dividers or scroll bars owned by WINDOW. On a window-system
680 the return value does not include the number of columns used for
681 WINDOW's fringes or display margins either. */)
682 (Lisp_Object window
, Lisp_Object horizontal
)
684 struct window
*w
= decode_any_window (window
);
686 if (NILP (horizontal
))
687 return make_number (window_body_lines (w
));
689 return make_number (window_body_cols (w
));
692 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
693 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
694 WINDOW must be a live window and defaults to the selected one. */)
697 return decode_window (window
)->hscroll
;
700 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
701 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
702 Return NCOL. NCOL should be zero or positive.
704 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
705 window so that the location of point moves off-window. */)
706 (Lisp_Object window
, Lisp_Object ncol
)
708 struct window
*w
= decode_window (window
);
712 hscroll
= max (0, XINT (ncol
));
714 /* Prevent redisplay shortcuts when changing the hscroll. */
715 if (XINT (w
->hscroll
) != hscroll
)
716 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
718 w
->hscroll
= make_number (hscroll
);
722 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
723 Swindow_redisplay_end_trigger
, 0, 1, 0,
724 doc
: /* Return WINDOW's redisplay end trigger value.
725 WINDOW defaults to the selected window.
726 See `set-window-redisplay-end-trigger' for more information. */)
729 return decode_window (window
)->redisplay_end_trigger
;
732 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
733 Sset_window_redisplay_end_trigger
, 2, 2, 0,
734 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
735 VALUE should be a buffer position (typically a marker) or nil.
736 If it is a buffer position, then if redisplay in WINDOW reaches a position
737 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
738 with two arguments: WINDOW, and the end trigger value.
739 Afterwards the end-trigger value is reset to nil. */)
740 (register Lisp_Object window
, Lisp_Object value
)
742 register struct window
*w
;
744 w
= decode_window (window
);
745 w
->redisplay_end_trigger
= value
;
749 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
750 doc
: /* Return a list of the edge coordinates of WINDOW.
751 The list has the form (LEFT TOP RIGHT BOTTOM).
752 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
753 all relative to 0, 0 at top left corner of frame.
755 RIGHT is one more than the rightmost column occupied by WINDOW.
756 BOTTOM is one more than the bottommost row occupied by WINDOW.
757 The edges include the space used by WINDOW's scroll bar, display
758 margins, fringes, header line, and/or mode line. For the edges of
759 just the text area, use `window-inside-edges'. */)
762 register struct window
*w
= decode_any_window (window
);
764 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w
)),
765 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w
)),
766 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w
)),
767 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w
)),
771 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
772 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
773 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
774 the top left corner of the frame.
776 RIGHT is one more than the rightmost x position occupied by WINDOW.
777 BOTTOM is one more than the bottommost y position occupied by WINDOW.
778 The pixel edges include the space used by WINDOW's scroll bar, display
779 margins, fringes, header line, and/or mode line. For the pixel edges
780 of just the text area, use `window-inside-pixel-edges'. */)
783 register struct window
*w
= decode_any_window (window
);
785 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
)),
786 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
)),
787 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
)),
788 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
)),
793 calc_absolute_offset(struct window
*w
, int *add_x
, int *add_y
)
795 struct frame
*f
= XFRAME (w
->frame
);
797 #ifdef FRAME_MENUBAR_HEIGHT
798 *add_y
+= FRAME_MENUBAR_HEIGHT (f
);
800 #ifdef FRAME_TOOLBAR_TOP_HEIGHT
801 *add_y
+= FRAME_TOOLBAR_TOP_HEIGHT (f
);
802 #elif FRAME_TOOLBAR_HEIGHT
803 *add_y
+= FRAME_TOOLBAR_HEIGHT (f
);
805 #ifdef FRAME_NS_TITLEBAR_HEIGHT
806 *add_y
+= FRAME_NS_TITLEBAR_HEIGHT (f
);
808 *add_x
= f
->left_pos
;
809 #ifdef FRAME_TOOLBAR_LEFT_WIDTH
810 *add_x
+= FRAME_TOOLBAR_LEFT_WIDTH (f
);
814 DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges
,
815 Swindow_absolute_pixel_edges
, 0, 1, 0,
816 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
817 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
818 the top left corner of the display.
820 RIGHT is one more than the rightmost x position occupied by WINDOW.
821 BOTTOM is one more than the bottommost y position occupied by WINDOW.
822 The pixel edges include the space used by WINDOW's scroll bar, display
823 margins, fringes, header line, and/or mode line. For the pixel edges
824 of just the text area, use `window-inside-absolute-pixel-edges'. */)
827 register struct window
*w
= decode_any_window (window
);
829 calc_absolute_offset (w
, &add_x
, &add_y
);
831 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
) + add_x
),
832 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
) + add_y
),
833 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
) + add_x
),
834 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
) + add_y
),
838 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
839 doc
: /* Return a list of the edge coordinates of WINDOW.
840 The list has the form (LEFT TOP RIGHT BOTTOM).
841 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
842 all relative to 0, 0 at top left corner of frame.
844 RIGHT is one more than the rightmost column of WINDOW's text area.
845 BOTTOM is one more than the bottommost row of WINDOW's text area.
846 The inside edges do not include the space used by the WINDOW's scroll
847 bar, display margins, fringes, header line, and/or mode line. */)
850 register struct window
*w
= decode_any_window (window
);
852 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w
)
853 + WINDOW_LEFT_MARGIN_COLS (w
)
854 + WINDOW_LEFT_FRINGE_COLS (w
)),
855 make_number (WINDOW_TOP_EDGE_LINE (w
)
856 + WINDOW_HEADER_LINE_LINES (w
)),
857 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w
)
858 - WINDOW_RIGHT_MARGIN_COLS (w
)
859 - WINDOW_RIGHT_FRINGE_COLS (w
)),
860 make_number (WINDOW_BOTTOM_EDGE_LINE (w
)
861 - WINDOW_MODE_LINE_LINES (w
)));
864 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
865 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
866 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
867 the top left corner of the frame.
869 RIGHT is one more than the rightmost x position of WINDOW's text area.
870 BOTTOM is one more than the bottommost y position of WINDOW's text area.
871 The inside edges do not include the space used by WINDOW's scroll bar,
872 display margins, fringes, header line, and/or mode line. */)
875 register struct window
*w
= decode_any_window (window
);
877 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
878 + WINDOW_LEFT_MARGIN_WIDTH (w
)
879 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
880 make_number (WINDOW_TOP_EDGE_Y (w
)
881 + WINDOW_HEADER_LINE_HEIGHT (w
)),
882 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
883 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
884 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
885 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
886 - WINDOW_MODE_LINE_HEIGHT (w
)));
889 DEFUN ("window-inside-absolute-pixel-edges",
890 Fwindow_inside_absolute_pixel_edges
,
891 Swindow_inside_absolute_pixel_edges
, 0, 1, 0,
892 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
893 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
894 the top left corner of the display.
896 RIGHT is one more than the rightmost x position of WINDOW's text area.
897 BOTTOM is one more than the bottommost y position of WINDOW's text area.
898 The inside edges do not include the space used by WINDOW's scroll bar,
899 display margins, fringes, header line, and/or mode line. */)
902 register struct window
*w
= decode_any_window (window
);
904 calc_absolute_offset (w
, &add_x
, &add_y
);
906 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
907 + WINDOW_LEFT_MARGIN_WIDTH (w
)
908 + WINDOW_LEFT_FRINGE_WIDTH (w
) + add_x
),
909 make_number (WINDOW_TOP_EDGE_Y (w
)
910 + WINDOW_HEADER_LINE_HEIGHT (w
) + add_y
),
911 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
912 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
913 - WINDOW_RIGHT_FRINGE_WIDTH (w
) + add_x
),
914 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
915 - WINDOW_MODE_LINE_HEIGHT (w
) + add_y
));
918 /* Test if the character at column X, row Y is within window W.
919 If it is not, return ON_NOTHING;
920 if it is in the window's text area, return ON_TEXT;
921 if it is on the window's modeline, return ON_MODE_LINE;
922 if it is on the border between the window and its right sibling,
923 return ON_VERTICAL_BORDER.
924 if it is on a scroll bar, return ON_SCROLL_BAR.
925 if it is on the window's top line, return ON_HEADER_LINE;
926 if it is in left or right fringe of the window,
927 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
928 if it is in the marginal area to the left/right of the window,
929 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN.
931 X and Y are frame relative pixel coordinates. */
933 static enum window_part
934 coordinates_in_window (register struct window
*w
, int x
, int y
)
936 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
938 enum window_part part
;
939 int ux
= FRAME_COLUMN_WIDTH (f
);
940 int x0
= WINDOW_LEFT_EDGE_X (w
);
941 int x1
= WINDOW_RIGHT_EDGE_X (w
);
942 /* The width of the area where the vertical line can be dragged.
943 (Between mode lines for instance. */
944 int grabbable_width
= ux
;
945 int lmargin_width
, rmargin_width
, text_left
, text_right
;
946 int top_y
= WINDOW_TOP_EDGE_Y (w
);
947 int bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
949 /* Outside any interesting row? */
950 if (y
< top_y
|| y
>= bottom_y
)
953 /* In what's below, we subtract 1 when computing right_x because we
954 want the rightmost pixel, which is given by left_pixel+width-1. */
955 if (w
->pseudo_window_p
)
958 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
962 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
963 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
966 /* On the mode line or header line? If it's near the start of
967 the mode or header line of window that's has a horizontal
968 sibling, say it's on the vertical line. That's to be able
969 to resize windows horizontally in case we're using toolkit
972 if (WINDOW_WANTS_MODELINE_P (w
)
973 && y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
977 header_vertical_border_check
:
978 /* We're somewhere on the mode line. We consider the place
979 between mode lines of horizontally adjacent mode lines
980 as the vertical border. If scroll bars on the left,
981 return the right window. */
982 if ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
983 || WINDOW_RIGHTMOST_P (w
))
984 && !WINDOW_LEFTMOST_P (w
)
985 && eabs (x
- x0
) < grabbable_width
)
986 return ON_VERTICAL_BORDER
;
988 /* Make sure we're not at the rightmost position of a
989 mode-/header-line and there's yet another window on the
991 else if ((WINDOW_RIGHTMOST_P (w
) || x
< x1
)
992 && eabs (x
- x1
) < grabbable_width
)
993 return ON_VERTICAL_BORDER
;
995 if (x
< x0
|| x
>= x1
)
1001 if (WINDOW_WANTS_HEADER_LINE_P (w
)
1002 && y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
))
1004 part
= ON_HEADER_LINE
;
1005 goto header_vertical_border_check
;
1008 if (x
< x0
|| x
>= x1
) return ON_NOTHING
;
1010 /* Outside any interesting column? */
1011 if (x
< left_x
|| x
> right_x
)
1012 return ON_SCROLL_BAR
;
1014 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
1015 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
1017 text_left
= window_box_left (w
, TEXT_AREA
);
1018 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
1020 if (FRAME_WINDOW_P (f
))
1022 if (!w
->pseudo_window_p
1023 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
1024 && !WINDOW_RIGHTMOST_P (w
)
1025 && (eabs (x
- right_x
) < grabbable_width
))
1026 return ON_VERTICAL_BORDER
;
1028 /* Need to say "x > right_x" rather than >=, since on character
1029 terminals, the vertical line's x coordinate is right_x. */
1030 else if (!w
->pseudo_window_p
1031 && !WINDOW_RIGHTMOST_P (w
)
1032 && x
> right_x
- ux
)
1033 return ON_VERTICAL_BORDER
;
1037 if (lmargin_width
> 0
1038 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1039 ? (x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
1040 : (x
< left_x
+ lmargin_width
)))
1041 return ON_LEFT_MARGIN
;
1043 return ON_LEFT_FRINGE
;
1046 if (x
>= text_right
)
1048 if (rmargin_width
> 0
1049 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1050 ? (x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
1051 : (x
>= right_x
- rmargin_width
)))
1052 return ON_RIGHT_MARGIN
;
1054 return ON_RIGHT_FRINGE
;
1057 /* Everything special ruled out - must be on text area */
1061 /* Take X is the frame-relative pixel x-coordinate, and return the
1062 x-coordinate relative to part PART of window W. */
1064 window_relative_x_coord (struct window
*w
, enum window_part part
, int x
)
1066 int left_x
= (w
->pseudo_window_p
) ? 0 : WINDOW_BOX_LEFT_EDGE_X (w
);
1071 return x
- window_box_left (w
, TEXT_AREA
);
1073 case ON_LEFT_FRINGE
:
1076 case ON_RIGHT_FRINGE
:
1077 return x
- left_x
- WINDOW_LEFT_FRINGE_WIDTH (w
);
1079 case ON_LEFT_MARGIN
:
1081 - ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1082 ? WINDOW_LEFT_FRINGE_WIDTH (w
) : 0));
1084 case ON_RIGHT_MARGIN
:
1086 - ((w
->pseudo_window_p
)
1087 ? WINDOW_TOTAL_WIDTH (w
)
1088 : WINDOW_BOX_RIGHT_EDGE_X (w
))
1089 + window_box_width (w
, RIGHT_MARGIN_AREA
)
1090 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1091 ? WINDOW_RIGHT_FRINGE_WIDTH (w
) : 0));
1094 /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */
1099 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
1100 Scoordinates_in_window_p
, 2, 2, 0,
1101 doc
: /* Return non-nil if COORDINATES are in WINDOW.
1102 COORDINATES is a cons of the form (X . Y), X and Y being distances
1103 measured in characters from the upper-left corner of the frame.
1104 \(0 . 0) denotes the character in the upper left corner of the
1106 If COORDINATES are in the text portion of WINDOW,
1107 the coordinates relative to the window are returned.
1108 If they are in the mode line of WINDOW, `mode-line' is returned.
1109 If they are in the top mode line of WINDOW, `header-line' is returned.
1110 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1111 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1112 If they are on the border between WINDOW and its right sibling,
1113 `vertical-line' is returned.
1114 If they are in the windows's left or right marginal areas, `left-margin'\n\
1115 or `right-margin' is returned. */)
1116 (register Lisp_Object coordinates
, Lisp_Object window
)
1123 CHECK_WINDOW (window
);
1124 w
= XWINDOW (window
);
1125 f
= XFRAME (w
->frame
);
1126 CHECK_CONS (coordinates
);
1127 lx
= Fcar (coordinates
);
1128 ly
= Fcdr (coordinates
);
1129 CHECK_NUMBER_OR_FLOAT (lx
);
1130 CHECK_NUMBER_OR_FLOAT (ly
);
1131 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1132 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1134 switch (coordinates_in_window (w
, x
, y
))
1140 /* Convert X and Y to window relative pixel coordinates, and
1141 return the canonical char units. */
1142 x
-= window_box_left (w
, TEXT_AREA
);
1143 y
-= WINDOW_TOP_EDGE_Y (w
);
1144 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
1145 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
1150 case ON_VERTICAL_BORDER
:
1151 return Qvertical_line
;
1153 case ON_HEADER_LINE
:
1154 return Qheader_line
;
1156 case ON_LEFT_FRINGE
:
1157 return Qleft_fringe
;
1159 case ON_RIGHT_FRINGE
:
1160 return Qright_fringe
;
1162 case ON_LEFT_MARGIN
:
1163 return Qleft_margin
;
1165 case ON_RIGHT_MARGIN
:
1166 return Qright_margin
;
1169 /* Historically we are supposed to return nil in this case. */
1178 /* Callback for foreach_window, used in window_from_coordinates.
1179 Check if window W contains coordinates specified by USER_DATA which
1180 is actually a pointer to a struct check_window_data CW.
1182 Check if window W contains coordinates *CW->x and *CW->y. If it
1183 does, return W in *CW->window, as Lisp_Object, and return in
1184 *CW->part the part of the window under coordinates *X,*Y. Return
1185 zero from this function to stop iterating over windows. */
1187 struct check_window_data
1189 Lisp_Object
*window
;
1191 enum window_part
*part
;
1195 check_window_containing (struct window
*w
, void *user_data
)
1197 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
1198 enum window_part found
;
1201 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1202 if (found
!= ON_NOTHING
)
1205 XSETWINDOW (*cw
->window
, w
);
1213 /* Find the window containing frame-relative pixel position X/Y and
1214 return it as a Lisp_Object.
1216 If X, Y is on one of the window's special `window_part' elements,
1217 set *PART to the id of that element.
1219 If there is no window under X, Y return nil and leave *PART
1220 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1222 This function was previously implemented with a loop cycling over
1223 windows with Fnext_window, and starting with the frame's selected
1224 window. It turned out that this doesn't work with an
1225 implementation of next_window using Vwindow_list, because
1226 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1227 tree of F when this function is called asynchronously from
1228 note_mouse_highlight. The original loop didn't terminate in this
1232 window_from_coordinates (struct frame
*f
, int x
, int y
,
1233 enum window_part
*part
, int tool_bar_p
)
1236 struct check_window_data cw
;
1237 enum window_part dummy
;
1243 cw
.window
= &window
, cw
.x
= x
, cw
.y
= y
; cw
.part
= part
;
1244 foreach_window (f
, check_window_containing
, &cw
);
1246 /* If not found above, see if it's in the tool bar window, if a tool
1250 && WINDOWP (f
->tool_bar_window
)
1251 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1252 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), x
, y
)
1256 window
= f
->tool_bar_window
;
1262 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1263 doc
: /* Return window containing coordinates X and Y on FRAME.
1264 FRAME must be a live frame and defaults to the selected one.
1265 The top left corner of the frame is considered to be row 0,
1267 (Lisp_Object x
, Lisp_Object y
, Lisp_Object frame
)
1272 frame
= selected_frame
;
1273 CHECK_LIVE_FRAME (frame
);
1276 /* Check that arguments are integers or floats. */
1277 CHECK_NUMBER_OR_FLOAT (x
);
1278 CHECK_NUMBER_OR_FLOAT (y
);
1280 return window_from_coordinates (f
,
1281 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1282 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1283 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1284 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1288 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1289 doc
: /* Return current value of point in WINDOW.
1290 WINDOW must be a live window and defaults to the selected one.
1292 For a nonselected window, this is the value point would have
1293 if that window were selected.
1295 Note that, when WINDOW is the selected window and its buffer
1296 is also currently selected, the value returned is the same as (point).
1297 It would be more strictly correct to return the `top-level' value
1298 of point, outside of any save-excursion forms.
1299 But that is hard to define. */)
1300 (Lisp_Object window
)
1302 register struct window
*w
= decode_window (window
);
1304 if (w
== XWINDOW (selected_window
)
1305 && current_buffer
== XBUFFER (w
->buffer
))
1307 return Fmarker_position (w
->pointm
);
1310 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1311 doc
: /* Return position at which display currently starts in WINDOW.
1312 WINDOW must be a live window and defaults to the selected one.
1313 This is updated by redisplay or by calling `set-window-start'. */)
1314 (Lisp_Object window
)
1316 return Fmarker_position (decode_window (window
)->start
);
1319 /* This is text temporarily removed from the doc string below.
1321 This function returns nil if the position is not currently known.
1322 That happens when redisplay is preempted and doesn't finish.
1323 If in that case you want to compute where the end of the window would
1324 have been if redisplay had finished, do this:
1326 (goto-char (window-start window))
1327 (vertical-motion (1- (window-height window)) window)
1330 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1331 doc
: /* Return position at which display currently ends in WINDOW.
1332 WINDOW must be a live window and defaults to the selected one.
1333 This is updated by redisplay, when it runs to completion.
1334 Simply changing the buffer text or setting `window-start'
1335 does not update this value.
1336 Return nil if there is no recorded value. \(This can happen if the
1337 last redisplay of WINDOW was preempted, and did not finish.)
1338 If UPDATE is non-nil, compute the up-to-date position
1339 if it isn't already recorded. */)
1340 (Lisp_Object window
, Lisp_Object update
)
1343 struct window
*w
= decode_window (window
);
1351 #if 0 /* This change broke some things. We should make it later. */
1352 /* If we don't know the end position, return nil.
1353 The user can compute it with vertical-motion if he wants to.
1354 It would be nicer to do it automatically,
1355 but that's so slow that it would probably bother people. */
1356 if (NILP (w
->window_end_valid
))
1361 && ! (! NILP (w
->window_end_valid
)
1362 && XFASTINT (w
->last_modified
) >= BUF_MODIFF (b
)
1363 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (b
))
1366 struct text_pos startp
;
1368 struct buffer
*old_buffer
= NULL
;
1370 /* Cannot use Fvertical_motion because that function doesn't
1371 cope with variable-height lines. */
1372 if (b
!= current_buffer
)
1374 old_buffer
= current_buffer
;
1375 set_buffer_internal (b
);
1378 /* In case W->start is out of the range, use something
1379 reasonable. This situation occurred when loading a file with
1380 `-l' containing a call to `rmail' with subsequent other
1381 commands. At the end, W->start happened to be BEG, while
1382 rmail had already narrowed the buffer. */
1383 if (XMARKER (w
->start
)->charpos
< BEGV
)
1384 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1385 else if (XMARKER (w
->start
)->charpos
> ZV
)
1386 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1388 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1390 start_display (&it
, w
, startp
);
1391 move_it_vertically (&it
, window_box_height (w
));
1392 if (it
.current_y
< it
.last_visible_y
)
1393 move_it_past_eol (&it
);
1394 value
= make_number (IT_CHARPOS (it
));
1397 set_buffer_internal (old_buffer
);
1400 XSETINT (value
, BUF_Z (b
) - XFASTINT (w
->window_end_pos
));
1405 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1406 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1408 (Lisp_Object window
, Lisp_Object pos
)
1410 register struct window
*w
= decode_window (window
);
1412 CHECK_NUMBER_COERCE_MARKER (pos
);
1413 if (w
== XWINDOW (selected_window
)
1414 && XBUFFER (w
->buffer
) == current_buffer
)
1417 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1419 /* We have to make sure that redisplay updates the window to show
1420 the new value of point. */
1421 if (!EQ (window
, selected_window
))
1422 ++windows_or_buffers_changed
;
1427 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1428 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1429 WINDOW defaults to the selected window. Return POS.
1430 Optional third arg NOFORCE non-nil inhibits next redisplay from
1431 overriding motion of point in order to display at this exact start. */)
1432 (Lisp_Object window
, Lisp_Object pos
, Lisp_Object noforce
)
1434 register struct window
*w
= decode_window (window
);
1436 CHECK_NUMBER_COERCE_MARKER (pos
);
1437 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1438 /* this is not right, but much easier than doing what is right. */
1439 w
->start_at_line_beg
= Qnil
;
1441 w
->force_start
= Qt
;
1442 w
->update_mode_line
= Qt
;
1443 XSETFASTINT (w
->last_modified
, 0);
1444 XSETFASTINT (w
->last_overlay_modified
, 0);
1445 if (!EQ (window
, selected_window
))
1446 windows_or_buffers_changed
++;
1451 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
1452 Spos_visible_in_window_p
, 0, 3, 0,
1453 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
1454 Return nil if that position is scrolled vertically out of view.
1455 If a character is only partially visible, nil is returned, unless the
1456 optional argument PARTIALLY is non-nil.
1457 If POS is only out of view because of horizontal scrolling, return non-nil.
1458 If POS is t, it specifies the position of the last visible glyph in WINDOW.
1459 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
1461 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1462 return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
1463 where X and Y are the pixel coordinates relative to the top left corner
1464 of the window. The remaining elements are omitted if the character after
1465 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1466 off-window at the top and bottom of the row, ROWH is the height of the
1467 display row, and VPOS is the row number (0-based) containing POS. */)
1468 (Lisp_Object pos
, Lisp_Object window
, Lisp_Object partially
)
1470 register struct window
*w
;
1471 register EMACS_INT posint
;
1472 register struct buffer
*buf
;
1473 struct text_pos top
;
1474 Lisp_Object in_window
= Qnil
;
1475 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
1478 w
= decode_window (window
);
1479 buf
= XBUFFER (w
->buffer
);
1480 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1484 else if (!NILP (pos
))
1486 CHECK_NUMBER_COERCE_MARKER (pos
);
1487 posint
= XINT (pos
);
1489 else if (w
== XWINDOW (selected_window
))
1492 posint
= XMARKER (w
->pointm
)->charpos
;
1494 /* If position is above window start or outside buffer boundaries,
1495 or if window start is out of range, position is not visible. */
1497 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
1498 && CHARPOS (top
) >= BUF_BEGV (buf
)
1499 && CHARPOS (top
) <= BUF_ZV (buf
)
1500 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
1501 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
1504 if (!NILP (in_window
) && !NILP (partially
))
1506 Lisp_Object part
= Qnil
;
1508 part
= list4 (make_number (rtop
), make_number (rbot
),
1509 make_number (rowh
), make_number (vpos
));
1510 in_window
= Fcons (make_number (x
),
1511 Fcons (make_number (y
), part
));
1517 DEFUN ("window-line-height", Fwindow_line_height
,
1518 Swindow_line_height
, 0, 2, 0,
1519 doc
: /* Return height in pixels of text line LINE in window WINDOW.
1520 WINDOW defaults to the selected window.
1522 Return height of current line if LINE is omitted or nil. Return height of
1523 header or mode line if LINE is `header-line' or `mode-line'.
1524 Otherwise, LINE is a text line number starting from 0. A negative number
1525 counts from the end of the window.
1527 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
1528 in pixels of the visible part of the line, VPOS and YPOS are the
1529 vertical position in lines and pixels of the line, relative to the top
1530 of the first text line, and OFFBOT is the number of off-window pixels at
1531 the bottom of the text line. If there are off-window pixels at the top
1532 of the (first) text line, YPOS is negative.
1534 Return nil if window display is not up-to-date. In that case, use
1535 `pos-visible-in-window-p' to obtain the information. */)
1536 (Lisp_Object line
, Lisp_Object window
)
1538 register struct window
*w
;
1539 register struct buffer
*b
;
1540 struct glyph_row
*row
, *end_row
;
1541 int max_y
, crop
, i
, n
;
1543 w
= decode_window (window
);
1545 if (noninteractive
|| w
->pseudo_window_p
)
1548 CHECK_BUFFER (w
->buffer
);
1549 b
= XBUFFER (w
->buffer
);
1551 /* Fail if current matrix is not up-to-date. */
1552 if (NILP (w
->window_end_valid
)
1553 || current_buffer
->clip_changed
1554 || current_buffer
->prevent_redisplay_optimizations_p
1555 || XFASTINT (w
->last_modified
) < BUF_MODIFF (b
)
1556 || XFASTINT (w
->last_overlay_modified
) < BUF_OVERLAY_MODIFF (b
))
1562 if (i
< 0 || i
>= w
->current_matrix
->nrows
1563 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
1565 max_y
= window_text_bottom_y (w
);
1569 if (EQ (line
, Qheader_line
))
1571 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
1573 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
1574 if (!row
->enabled_p
)
1576 return list4 (make_number (row
->height
),
1577 make_number (0), make_number (0),
1581 if (EQ (line
, Qmode_line
))
1583 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
1584 if (!row
->enabled_p
)
1586 return list4 (make_number (row
->height
),
1587 make_number (0), /* not accurate */
1588 make_number (WINDOW_HEADER_LINE_HEIGHT (w
)
1589 + window_text_bottom_y (w
)),
1593 CHECK_NUMBER (line
);
1596 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1597 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1598 max_y
= window_text_bottom_y (w
);
1601 while ((n
< 0 || i
< n
)
1602 && row
<= end_row
&& row
->enabled_p
1603 && row
->y
+ row
->height
< max_y
)
1606 if (row
> end_row
|| !row
->enabled_p
)
1618 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
1619 return list4 (make_number (row
->height
+ min (0, row
->y
) - crop
),
1621 make_number (row
->y
),
1622 make_number (crop
));
1625 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1627 doc
: /* Return non-nil when WINDOW is dedicated to its buffer.
1628 More precisely, return the value assigned by the last call of
1629 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1630 never called with WINDOW as its argument, or the value set by that
1631 function was internally reset since its last call. WINDOW defaults to
1632 the selected window.
1634 When a window is dedicated to its buffer, `display-buffer' will refrain
1635 from displaying another buffer in it. `get-lru-window' and
1636 `get-largest-window' treat dedicated windows specially.
1637 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1638 `kill-buffer' can delete a dedicated window and the containing frame.
1640 Functions like `set-window-buffer' may change the buffer displayed by a
1641 window, unless that window is "strongly" dedicated to its buffer, that
1642 is the value returned by `window-dedicated-p' is t. */)
1643 (Lisp_Object window
)
1645 return decode_window (window
)->dedicated
;
1648 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1649 Sset_window_dedicated_p
, 2, 2, 0,
1650 doc
: /* Mark WINDOW as dedicated according to FLAG.
1651 WINDOW must be a live window and defaults to the selected one. FLAG
1652 non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means
1653 mark WINDOW as non-dedicated. Return FLAG.
1655 When a window is dedicated to its buffer, `display-buffer' will refrain
1656 from displaying another buffer in it. `get-lru-window' and
1657 `get-largest-window' treat dedicated windows specially.
1658 `delete-windows-on', `replace-buffer-in-windows', `quit-window',
1659 `quit-restore-window' and `kill-buffer' can delete a dedicated window
1660 and the containing frame.
1662 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
1663 its buffer. Functions like `set-window-buffer' may change the buffer
1664 displayed by a window, unless that window is strongly dedicated to its
1665 buffer. If and when `set-window-buffer' displays another buffer in a
1666 window, it also makes sure that the window is no more dedicated. */)
1667 (Lisp_Object window
, Lisp_Object flag
)
1669 register struct window
*w
= decode_window (window
);
1671 w
->dedicated
= flag
;
1672 return w
->dedicated
;
1675 DEFUN ("window-prev-buffers", Fwindow_prev_buffers
, Swindow_prev_buffers
,
1677 doc
: /* Return buffers previously shown in WINDOW.
1678 WINDOW must be a live window and defaults to the selected one.
1680 The return value is either nil or a list of <buffer, window-start,
1681 window-point> triples where buffer was previously shown in WINDOW. */)
1682 (Lisp_Object window
)
1684 return decode_window (window
)->prev_buffers
;
1687 DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers
,
1688 Sset_window_prev_buffers
, 2, 2, 0,
1689 doc
: /* Set WINDOW's previous buffers to PREV-BUFFERS.
1690 WINDOW must be a live window and defaults to the selected one. Return
1693 PREV-BUFFERS should be either nil or a list of <buffer, window-start,
1694 window-point> triples where buffer was previously shown in WINDOW. */)
1695 (Lisp_Object window
, Lisp_Object prev_buffers
)
1697 return decode_any_window (window
)->prev_buffers
= prev_buffers
;
1700 DEFUN ("window-next-buffers", Fwindow_next_buffers
, Swindow_next_buffers
,
1702 doc
: /* Return list of buffers recently re-shown in WINDOW.
1703 WINDOW must be a live window and defaults to the selected one. */)
1704 (Lisp_Object window
)
1706 return decode_window (window
)->next_buffers
;
1709 DEFUN ("set-window-next-buffers", Fset_window_next_buffers
,
1710 Sset_window_next_buffers
, 2, 2, 0,
1711 doc
: /* Set WINDOW's next buffers to NEXT-BUFFERS.
1712 WINDOW must be a live window and defaults to the selected one. Return
1715 NEXT-BUFFERS should be either nil or a list of buffers that have been
1716 recently re-shown in WINDOW. */)
1717 (Lisp_Object window
, Lisp_Object next_buffers
)
1719 return decode_any_window (window
)->next_buffers
= next_buffers
;
1722 DEFUN ("window-parameters", Fwindow_parameters
, Swindow_parameters
,
1724 doc
: /* Return the parameters of WINDOW and their values.
1725 WINDOW defaults to the selected window. The return value is a list of
1726 elements of the form (PARAMETER . VALUE). */)
1727 (Lisp_Object window
)
1729 return Fcopy_alist (decode_any_window (window
)->window_parameters
);
1732 DEFUN ("window-parameter", Fwindow_parameter
, Swindow_parameter
,
1734 doc
: /* Return WINDOW's value for PARAMETER.
1735 WINDOW defaults to the selected window. */)
1736 (Lisp_Object window
, Lisp_Object parameter
)
1740 result
= Fassq (parameter
, decode_any_window (window
)->window_parameters
);
1741 return CDR_SAFE (result
);
1744 DEFUN ("set-window-parameter", Fset_window_parameter
,
1745 Sset_window_parameter
, 3, 3, 0,
1746 doc
: /* Set WINDOW's value of PARAMETER to VALUE.
1747 WINDOW defaults to the selected window. Return VALUE. */)
1748 (Lisp_Object window
, Lisp_Object parameter
, Lisp_Object value
)
1750 register struct window
*w
= decode_any_window (window
);
1751 Lisp_Object old_alist_elt
;
1753 old_alist_elt
= Fassq (parameter
, w
->window_parameters
);
1754 if (NILP (old_alist_elt
))
1755 w
->window_parameters
= Fcons (Fcons (parameter
, value
), w
->window_parameters
);
1757 Fsetcdr (old_alist_elt
, value
);
1761 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1763 doc
: /* Return the display-table that WINDOW is using.
1764 WINDOW defaults to the selected window. */)
1765 (Lisp_Object window
)
1767 return decode_window (window
)->display_table
;
1770 /* Get the display table for use on window W. This is either W's
1771 display table or W's buffer's display table. Ignore the specified
1772 tables if they are not valid; if no valid table is specified,
1775 struct Lisp_Char_Table
*
1776 window_display_table (struct window
*w
)
1778 struct Lisp_Char_Table
*dp
= NULL
;
1780 if (DISP_TABLE_P (w
->display_table
))
1781 dp
= XCHAR_TABLE (w
->display_table
);
1782 else if (BUFFERP (w
->buffer
))
1784 struct buffer
*b
= XBUFFER (w
->buffer
);
1786 if (DISP_TABLE_P (BVAR (b
, display_table
)))
1787 dp
= XCHAR_TABLE (BVAR (b
, display_table
));
1788 else if (DISP_TABLE_P (Vstandard_display_table
))
1789 dp
= XCHAR_TABLE (Vstandard_display_table
);
1795 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1796 doc
: /* Set WINDOW's display-table to TABLE. */)
1797 (register Lisp_Object window
, Lisp_Object table
)
1799 register struct window
*w
;
1801 w
= decode_window (window
);
1802 w
->display_table
= table
;
1806 static void delete_window (Lisp_Object
);
1808 /* Record info on buffer window w is displaying
1809 when it is about to cease to display that buffer. */
1811 unshow_buffer (register struct window
*w
)
1818 if (b
!= XMARKER (w
->pointm
)->buffer
)
1822 if (w
== XWINDOW (selected_window
)
1823 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1824 /* Do this except when the selected window's buffer
1825 is being removed from some other window. */
1827 /* last_window_start records the start position that this buffer
1828 had in the last window to be disconnected from it.
1829 Now that this statement is unconditional,
1830 it is possible for the buffer to be displayed in the
1831 selected window, while last_window_start reflects another
1832 window which was recently showing the same buffer.
1833 Some people might say that might be a good thing. Let's see. */
1834 b
->last_window_start
= marker_position (w
->start
);
1836 /* Point in the selected window's buffer
1837 is actually stored in that buffer, and the window's pointm isn't used.
1838 So don't clobber point in that buffer. */
1839 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1840 /* This line helps to fix Horsley's testbug.el bug. */
1841 && !(WINDOWP (BVAR (b
, last_selected_window
))
1842 && w
!= XWINDOW (BVAR (b
, last_selected_window
))
1843 && EQ (buf
, XWINDOW (BVAR (b
, last_selected_window
))->buffer
)))
1844 temp_set_point_both (b
,
1845 clip_to_bounds (BUF_BEGV (b
),
1846 XMARKER (w
->pointm
)->charpos
,
1848 clip_to_bounds (BUF_BEGV_BYTE (b
),
1849 marker_byte_position (w
->pointm
),
1852 if (WINDOWP (BVAR (b
, last_selected_window
))
1853 && w
== XWINDOW (BVAR (b
, last_selected_window
)))
1854 BVAR (b
, last_selected_window
) = Qnil
;
1857 /* Put NEW into the window structure in place of OLD. SETFLAG zero
1858 means change window structure only. Otherwise store geometry and
1859 other settings as well. */
1861 replace_window (Lisp_Object old
, Lisp_Object
new, int setflag
)
1863 register Lisp_Object tem
;
1864 register struct window
*o
= XWINDOW (old
), *n
= XWINDOW (new);
1866 /* If OLD is its frame's root window, then NEW is the new
1867 root window for that frame. */
1868 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1869 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = new;
1873 n
->left_col
= o
->left_col
;
1874 n
->top_line
= o
->top_line
;
1875 n
->total_cols
= o
->total_cols
;
1876 n
->total_lines
= o
->total_lines
;
1877 n
->normal_cols
= o
->normal_cols
;
1878 o
->normal_cols
= make_float (1.0);
1879 n
->normal_lines
= o
->normal_lines
;
1880 o
->normal_lines
= make_float (1.0);
1881 n
->desired_matrix
= n
->current_matrix
= 0;
1883 memset (&n
->cursor
, 0, sizeof (n
->cursor
));
1884 memset (&n
->last_cursor
, 0, sizeof (n
->last_cursor
));
1885 memset (&n
->phys_cursor
, 0, sizeof (n
->phys_cursor
));
1886 n
->phys_cursor_type
= -1;
1887 n
->phys_cursor_width
= -1;
1888 n
->must_be_updated_p
= 0;
1889 n
->pseudo_window_p
= 0;
1890 XSETFASTINT (n
->window_end_vpos
, 0);
1891 XSETFASTINT (n
->window_end_pos
, 0);
1892 n
->window_end_valid
= Qnil
;
1893 n
->frozen_window_start_p
= 0;
1894 n
->orig_top_line
= n
->orig_total_lines
= Qnil
;
1897 n
->next
= tem
= o
->next
;
1899 XWINDOW (tem
)->prev
= new;
1901 n
->prev
= tem
= o
->prev
;
1903 XWINDOW (tem
)->next
= new;
1905 n
->parent
= tem
= o
->parent
;
1908 if (EQ (XWINDOW (tem
)->vchild
, old
))
1909 XWINDOW (tem
)->vchild
= new;
1910 if (EQ (XWINDOW (tem
)->hchild
, old
))
1911 XWINDOW (tem
)->hchild
= new;
1915 /* If window WINDOW and its parent window are iso-combined, merge
1916 WINDOW's children into those of its parent window and mark WINDOW as
1920 recombine_windows (Lisp_Object window
)
1922 struct window
*w
, *p
, *c
;
1923 Lisp_Object parent
, child
;
1926 w
= XWINDOW (window
);
1928 if (!NILP (parent
) && NILP (w
->nest
))
1930 p
= XWINDOW (parent
);
1931 if (((!NILP (p
->vchild
) && !NILP (w
->vchild
))
1932 || (!NILP (p
->hchild
) && !NILP (w
->hchild
))))
1933 /* WINDOW and PARENT are both either a vertical or a horizontal
1936 horflag
= NILP (w
->vchild
);
1937 child
= horflag
? w
->hchild
: w
->vchild
;
1938 c
= XWINDOW (child
);
1940 /* Splice WINDOW's children into its parent's children and
1941 assign new normal sizes. */
1950 XWINDOW (w
->prev
)->next
= child
;
1959 = make_float (XFLOATINT (c
->total_cols
)
1960 / XFLOATINT (p
->total_cols
));
1963 = make_float (XFLOATINT (c
->total_lines
)
1964 / XFLOATINT (p
->total_lines
));
1968 if (!NILP (w
->next
))
1971 XWINDOW (c
->next
)->prev
= child
;
1979 c
= XWINDOW (child
);
1983 /* WINDOW can be deleted now. */
1984 w
->vchild
= w
->hchild
= Qnil
;
1989 /* If WINDOW can be deleted, delete it. */
1991 delete_deletable_window (Lisp_Object window
)
1993 if (!NILP (call1 (Qwindow_deletable_p
, window
)))
1994 call1 (Qdelete_window
, window
);
1997 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
1998 doc
: /* Remove WINDOW from its frame.
1999 WINDOW defaults to the selected window. Return nil.
2000 Signal an error when WINDOW is the only window on its frame. */)
2001 (register Lisp_Object window
)
2005 window
= selected_window
;
2007 CHECK_LIVE_WINDOW (window
);
2009 f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
2010 delete_window (window
);
2012 run_window_configuration_change_hook (f
);
2018 delete_window (register Lisp_Object window
)
2020 register Lisp_Object tem
, parent
, sib
;
2021 register struct window
*p
;
2022 register struct window
*par
;
2025 /* Because this function is called by other C code on non-leaf
2026 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
2027 so we can't decode_window here. */
2028 CHECK_WINDOW (window
);
2029 p
= XWINDOW (window
);
2031 /* It's a no-op to delete an already-deleted window. */
2032 if (NILP (p
->buffer
)
2034 && NILP (p
->vchild
))
2039 error ("Attempt to delete minibuffer or sole ordinary window");
2040 par
= XWINDOW (parent
);
2042 windows_or_buffers_changed
++;
2043 Vwindow_list
= Qnil
;
2044 f
= XFRAME (WINDOW_FRAME (p
));
2045 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
2047 /* Are we trying to delete any frame's selected window? */
2049 Lisp_Object swindow
, pwindow
;
2051 /* See if the frame's selected window is either WINDOW
2052 or any subwindow of it, by finding all that window's parents
2053 and comparing each one with WINDOW. */
2054 swindow
= FRAME_SELECTED_WINDOW (f
);
2059 while (!NILP (pwindow
))
2061 if (EQ (window
, pwindow
))
2063 pwindow
= XWINDOW (pwindow
)->parent
;
2066 /* If the window being deleted is not a parent of SWINDOW,
2067 then SWINDOW is ok as the new selected window. */
2068 if (!EQ (window
, pwindow
))
2070 /* Otherwise, try another window for SWINDOW. */
2071 swindow
= Fnext_window (swindow
, Qlambda
, Qnil
);
2073 /* If we get back to the frame's selected window,
2074 it means there was no acceptable alternative,
2075 so we cannot delete. */
2076 if (EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
2077 error ("Cannot delete window");
2080 /* If we need to change SWINDOW, do it. */
2081 if (! EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
2083 /* If we're about to delete the selected window on the
2084 selected frame, then we should use Fselect_window to select
2085 the new window. On the other hand, if we're about to
2086 delete the selected window on any other frame, we shouldn't do
2087 anything but set the frame's selected_window slot. */
2088 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
2089 Fselect_window (swindow
, Qnil
);
2091 FRAME_SELECTED_WINDOW (f
) = swindow
;
2095 /* Now we know we can delete this one. */
2096 window_deletion_count
++;
2099 /* tem is null for dummy parent windows
2100 (which have inferiors but not any contents themselves) */
2104 unchain_marker (XMARKER (p
->pointm
));
2105 unchain_marker (XMARKER (p
->start
));
2108 /* Free window glyph matrices. It is sure that they are allocated
2109 again when ADJUST_GLYPHS is called. Block input so that expose
2110 events and other events that access glyph matrices are not
2111 processed while we are changing them. */
2113 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2117 XWINDOW (tem
)->prev
= p
->prev
;
2121 XWINDOW (tem
)->next
= p
->next
;
2123 if (EQ (window
, par
->hchild
))
2124 par
->hchild
= p
->next
;
2125 if (EQ (window
, par
->vchild
))
2126 par
->vchild
= p
->next
;
2128 /* Find one of our siblings to give our space to. */
2132 /* If p gives its space to its next sibling, that sibling needs
2133 to have its top/left side pulled back to where p's is.
2134 set_window_{height,width} will re-position the sibling's
2137 XWINDOW (sib
)->top_line
= p
->top_line
;
2138 XWINDOW (sib
)->left_col
= p
->left_col
;
2141 /* Stretch that sibling. */
2142 if (!NILP (par
->vchild
))
2143 set_window_height (sib
,
2144 XFASTINT (XWINDOW (sib
)->total_lines
) + XFASTINT (p
->total_lines
),
2146 if (!NILP (par
->hchild
))
2147 set_window_width (sib
,
2148 XFASTINT (XWINDOW (sib
)->total_cols
) + XFASTINT (p
->total_cols
),
2151 /* If parent now has only one child,
2152 put the child into the parent's place. */
2156 if (NILP (XWINDOW (tem
)->next
)) {
2157 replace_window (parent
, tem
, 1);
2158 par
= XWINDOW (tem
);
2161 /* Since we may be deleting combination windows, we must make sure that
2162 not only p but all its children have been marked as deleted. */
2163 if (! NILP (p
->hchild
))
2164 delete_all_subwindows (p
->hchild
);
2165 else if (! NILP (p
->vchild
))
2166 delete_all_subwindows (p
->vchild
);
2168 /* Mark this window as deleted. */
2169 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
2171 if (! NILP (par
->parent
))
2172 par
= XWINDOW (par
->parent
);
2174 /* Check if we have a v/hchild with a v/hchild. In that case remove
2177 if (! NILP (par
->vchild
) && ! NILP (XWINDOW (par
->vchild
)->vchild
))
2179 p
= XWINDOW (par
->vchild
);
2180 par
->vchild
= p
->vchild
;
2183 else if (! NILP (par
->hchild
) && ! NILP (XWINDOW (par
->hchild
)->hchild
))
2185 p
= XWINDOW (par
->hchild
);
2186 par
->hchild
= p
->hchild
;
2194 while (! NILP (tem
)) {
2195 XWINDOW (tem
)->parent
= p
->parent
;
2196 if (NILP (XWINDOW (tem
)->next
))
2198 tem
= XWINDOW (tem
)->next
;
2201 /* The next of the v/hchild we are removing is now the next of the
2202 last child for the v/hchild:
2203 Before v/hchild -> v/hchild -> next1 -> next2
2206 After: v/hchild -> next1 -> next2 -> next3
2208 XWINDOW (tem
)->next
= p
->next
;
2209 if (! NILP (p
->next
))
2210 XWINDOW (p
->next
)->prev
= tem
;
2212 p
->next
= p
->prev
= p
->vchild
= p
->hchild
= p
->buffer
= Qnil
;
2216 /* Adjust glyph matrices. */
2223 /***********************************************************************
2225 ***********************************************************************/
2227 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
2228 pointer. This is a callback function for foreach_window, used in
2229 the window_list function. */
2232 add_window_to_list (struct window
*w
, void *user_data
)
2234 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
2236 XSETWINDOW (window
, w
);
2237 *list
= Fcons (window
, *list
);
2242 /* Return a list of all windows, for use by next_window. If
2243 Vwindow_list is a list, return that list. Otherwise, build a new
2244 list, cache it in Vwindow_list, and return that. */
2249 if (!CONSP (Vwindow_list
))
2253 Vwindow_list
= Qnil
;
2254 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
2256 Lisp_Object args
[2];
2258 /* We are visiting windows in canonical order, and add
2259 new windows at the front of args[1], which means we
2260 have to reverse this list at the end. */
2262 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
2263 args
[0] = Vwindow_list
;
2264 args
[1] = Fnreverse (args
[1]);
2265 Vwindow_list
= Fnconc (2, args
);
2269 return Vwindow_list
;
2273 /* Value is non-zero if WINDOW satisfies the constraints given by
2274 OWINDOW, MINIBUF and ALL_FRAMES.
2276 MINIBUF t means WINDOW may be minibuffer windows.
2277 `lambda' means WINDOW may not be a minibuffer window.
2278 a window means a specific minibuffer window
2280 ALL_FRAMES t means search all frames,
2281 nil means search just current frame,
2282 `visible' means search just visible frames on the
2284 0 means search visible and iconified frames on the
2286 a window means search the frame that window belongs to,
2287 a frame means consider windows on that frame, only. */
2290 candidate_window_p (Lisp_Object window
, Lisp_Object owindow
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2292 struct window
*w
= XWINDOW (window
);
2293 struct frame
*f
= XFRAME (w
->frame
);
2294 int candidate_p
= 1;
2296 if (!BUFFERP (w
->buffer
))
2298 else if (MINI_WINDOW_P (w
)
2299 && (EQ (minibuf
, Qlambda
)
2300 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
2302 /* If MINIBUF is `lambda' don't consider any mini-windows.
2303 If it is a window, consider only that one. */
2306 else if (EQ (all_frames
, Qt
))
2308 else if (NILP (all_frames
))
2310 xassert (WINDOWP (owindow
));
2311 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
2313 else if (EQ (all_frames
, Qvisible
))
2315 FRAME_SAMPLE_VISIBILITY (f
);
2316 candidate_p
= FRAME_VISIBLE_P (f
)
2317 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2318 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2321 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
2323 FRAME_SAMPLE_VISIBILITY (f
);
2324 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
2325 #ifdef HAVE_X_WINDOWS
2326 /* Yuck!! If we've just created the frame and the
2327 window-manager requested the user to place it
2328 manually, the window may still not be considered
2329 `visible'. I'd argue it should be at least
2330 something like `iconified', but don't know how to do
2332 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
2333 && !f
->output_data
.x
->has_been_visible
)
2336 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2337 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2339 else if (WINDOWP (all_frames
))
2340 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
2341 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
2342 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
2343 else if (FRAMEP (all_frames
))
2344 candidate_p
= EQ (all_frames
, w
->frame
);
2350 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2351 Fwindow_list. See candidate_window_p for the meaning of WINDOW,
2352 MINIBUF, and ALL_FRAMES. */
2355 decode_next_window_args (Lisp_Object
*window
, Lisp_Object
*minibuf
, Lisp_Object
*all_frames
)
2358 *window
= selected_window
;
2360 CHECK_LIVE_WINDOW (*window
);
2362 /* MINIBUF nil may or may not include minibuffers. Decide if it
2364 if (NILP (*minibuf
))
2365 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
2366 else if (!EQ (*minibuf
, Qt
))
2369 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2370 => count none of them, or a specific minibuffer window (the
2371 active one) to count. */
2373 /* ALL_FRAMES nil doesn't specify which frames to include. */
2374 if (NILP (*all_frames
))
2375 *all_frames
= (!EQ (*minibuf
, Qlambda
)
2376 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
2378 else if (EQ (*all_frames
, Qvisible
))
2380 else if (EQ (*all_frames
, make_number (0)))
2382 else if (FRAMEP (*all_frames
))
2384 else if (!EQ (*all_frames
, Qt
))
2389 /* Return the next or previous window of WINDOW in cyclic ordering
2390 of windows. NEXT_P non-zero means return the next window. See the
2391 documentation string of next-window for the meaning of MINIBUF and
2395 next_window (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
, int next_p
)
2397 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2399 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2400 return the first window on the frame. */
2401 if (FRAMEP (all_frames
)
2402 && !EQ (all_frames
, XWINDOW (window
)->frame
))
2403 return Fframe_first_window (all_frames
);
2409 /* Find WINDOW in the list of all windows. */
2410 list
= Fmemq (window
, window_list ());
2412 /* Scan forward from WINDOW to the end of the window list. */
2414 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
2415 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2418 /* Scan from the start of the window list up to WINDOW. */
2420 for (list
= Vwindow_list
;
2421 CONSP (list
) && !EQ (XCAR (list
), window
);
2423 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2427 window
= XCAR (list
);
2431 Lisp_Object candidate
, list
;
2433 /* Scan through the list of windows for candidates. If there are
2434 candidate windows in front of WINDOW, the last one of these
2435 is the one we want. If there are candidates following WINDOW
2436 in the list, again the last one of these is the one we want. */
2438 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
2440 if (EQ (XCAR (list
), window
))
2442 if (WINDOWP (candidate
))
2445 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
2447 candidate
= XCAR (list
);
2450 if (WINDOWP (candidate
))
2458 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
2459 doc
: /* Return window following WINDOW in cyclic ordering of windows.
2460 WINDOW defaults to the selected window. The optional arguments
2461 MINIBUF and ALL-FRAMES specify the set of windows to consider.
2463 MINIBUF t means consider the minibuffer window even if the
2464 minibuffer is not active. MINIBUF nil or omitted means consider
2465 the minibuffer window only if the minibuffer is active. Any
2466 other value means do not consider the minibuffer window even if
2467 the minibuffer is active.
2469 Several frames may share a single minibuffer; if the minibuffer
2470 is active, all windows on all frames that share that minibuffer
2471 are considered too. Therefore, if you are using a separate
2472 minibuffer frame and the minibuffer is active and MINIBUF says it
2473 counts, `next-window' considers the windows in the frame from
2474 which you entered the minibuffer, as well as the minibuffer
2477 ALL-FRAMES nil or omitted means consider all windows on WINDOW's
2478 frame, plus the minibuffer window if specified by the MINIBUF
2479 argument, see above. If the minibuffer counts, consider all
2480 windows on all frames that share that minibuffer too.
2481 ALL-FRAMES t means consider all windows on all existing frames.
2482 ALL-FRAMES `visible' means consider all windows on all visible
2483 frames on the current terminal.
2484 ALL-FRAMES 0 means consider all windows on all visible and
2485 iconified frames on the current terminal.
2486 ALL-FRAMES a frame means consider all windows on that frame only.
2487 Anything else means consider all windows on WINDOW's frame and no
2490 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2491 `next-window' to iterate through the entire cycle of acceptable
2492 windows, eventually ending up back at the window you started with.
2493 `previous-window' traverses the same cycle, in the reverse order. */)
2494 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2496 return next_window (window
, minibuf
, all_frames
, 1);
2500 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
2501 doc
: /* Return window preceding WINDOW in cyclic ordering of windows.
2502 WINDOW defaults to the selected window. The optional arguments
2503 MINIBUF and ALL-FRAMES specify the set of windows to consider.
2504 For the precise meaning of these arguments see `next-window'.
2506 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2507 use `previous-window' to iterate through the entire cycle of
2508 acceptable windows, eventually ending up back at the window you
2509 started with. `next-window' traverses the same cycle, in the
2511 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2513 return next_window (window
, minibuf
, all_frames
, 0);
2517 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
2518 doc
: /* Select another window in cyclic ordering of windows.
2519 COUNT specifies the number of windows to skip, starting with the
2520 selected window, before making the selection. If COUNT is
2521 positive, skip COUNT windows forwards. If COUNT is negative,
2522 skip -COUNT windows backwards. COUNT zero means do not skip any
2523 window, so select the selected window. In an interactive call,
2524 COUNT is the numeric prefix argument. Return nil.
2526 This function uses `next-window' for finding the window to select.
2527 The argument ALL-FRAMES has the same meaning as in `next-window',
2528 but the MINIBUF argument of `next-window' is always effectively
2530 (Lisp_Object count
, Lisp_Object all_frames
)
2535 CHECK_NUMBER (count
);
2536 window
= selected_window
;
2538 for (i
= XINT (count
); i
> 0; --i
)
2539 window
= Fnext_window (window
, Qnil
, all_frames
);
2541 window
= Fprevious_window (window
, Qnil
, all_frames
);
2543 Fselect_window (window
, Qnil
);
2548 /* Return a list of windows in cyclic ordering. Arguments are like
2549 for `next-window'. */
2552 window_list_1 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2554 Lisp_Object tail
, list
, rest
;
2556 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2559 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2560 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2561 list
= Fcons (XCAR (tail
), list
);
2563 /* Rotate the list to start with WINDOW. */
2564 list
= Fnreverse (list
);
2565 rest
= Fmemq (window
, list
);
2566 if (!NILP (rest
) && !EQ (rest
, list
))
2568 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2570 XSETCDR (tail
, Qnil
);
2571 list
= nconc2 (rest
, list
);
2577 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2578 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2579 FRAME nil or omitted means use the selected frame.
2580 WINDOW nil or omitted means use the selected window.
2581 MINIBUF t means include the minibuffer window, even if it isn't active.
2582 MINIBUF nil or omitted means include the minibuffer window only
2584 MINIBUF neither nil nor t means never include the minibuffer window. */)
2585 (Lisp_Object frame
, Lisp_Object minibuf
, Lisp_Object window
)
2588 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2589 CHECK_WINDOW (window
);
2591 frame
= selected_frame
;
2593 if (!EQ (frame
, XWINDOW (window
)->frame
))
2594 error ("Window is on a different frame");
2596 return window_list_1 (window
, minibuf
, frame
);
2600 DEFUN ("window-list-1", Fwindow_list_1
, Swindow_list_1
, 0, 3, 0,
2601 doc
: /* Return a list of all live windows.
2602 WINDOW specifies the first window to list and defaults to the selected
2605 Optional argument MINIBUF nil or omitted means consider the minibuffer
2606 window only if the minibuffer is active. MINIBUF t means consider the
2607 minibuffer window even if the minibuffer is not active. Any other value
2608 means do not consider the minibuffer window even if the minibuffer is
2611 Optional argument ALL-FRAMES nil or omitted means consider all windows
2612 on WINDOW's frame, plus the minibuffer window if specified by the
2613 MINIBUF argument. If the minibuffer counts, consider all windows on all
2614 frames that share that minibuffer too. The following non-nil values of
2615 ALL-FRAMES have special meanings:
2617 - t means consider all windows on all existing frames.
2619 - `visible' means consider all windows on all visible frames.
2621 - 0 (the number zero) means consider all windows on all visible and
2624 - A frame means consider all windows on that frame only.
2626 Anything else means consider all windows on WINDOW's frame and no
2629 If WINDOW is not on the list of windows returned, some other window will
2630 be listed first but no error is signalled. */)
2631 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2633 return window_list_1 (window
, minibuf
, all_frames
);
2636 /* Look at all windows, performing an operation specified by TYPE
2638 If FRAMES is Qt, look at all frames;
2639 Qnil, look at just the selected frame;
2640 Qvisible, look at visible frames;
2641 a frame, just look at windows on that frame.
2642 If MINI is non-zero, perform the operation on minibuffer windows too. */
2647 GET_BUFFER_WINDOW
, /* Arg is buffer */
2648 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
2649 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
2650 UNSHOW_BUFFER
, /* Arg is buffer */
2651 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2656 window_loop (enum window_loop type
, Lisp_Object obj
, int mini
, Lisp_Object frames
)
2658 Lisp_Object window
, windows
, best_window
, frame_arg
;
2660 struct gcpro gcpro1
;
2662 /* If we're only looping through windows on a particular frame,
2663 frame points to that frame. If we're looping through windows
2664 on all frames, frame is 0. */
2665 if (FRAMEP (frames
))
2666 f
= XFRAME (frames
);
2667 else if (NILP (frames
))
2668 f
= SELECTED_FRAME ();
2673 frame_arg
= Qlambda
;
2674 else if (EQ (frames
, make_number (0)))
2676 else if (EQ (frames
, Qvisible
))
2681 /* frame_arg is Qlambda to stick to one frame,
2682 Qvisible to consider all visible frames,
2685 /* Pick a window to start with. */
2689 window
= FRAME_SELECTED_WINDOW (f
);
2691 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2693 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2697 for (; CONSP (windows
); windows
= XCDR (windows
))
2701 window
= XCAR (windows
);
2702 w
= XWINDOW (window
);
2704 /* Note that we do not pay attention here to whether the frame
2705 is visible, since Fwindow_list skips non-visible frames if
2706 that is desired, under the control of frame_arg. */
2707 if (!MINI_WINDOW_P (w
)
2708 /* For UNSHOW_BUFFER, we must always consider all windows. */
2709 || type
== UNSHOW_BUFFER
2710 || (mini
&& minibuf_level
> 0))
2713 case GET_BUFFER_WINDOW
:
2714 if (EQ (w
->buffer
, obj
)
2715 /* Don't find any minibuffer window
2716 except the one that is currently in use. */
2717 && (MINI_WINDOW_P (w
)
2718 ? EQ (window
, minibuf_window
)
2721 if (NILP (best_window
))
2722 best_window
= window
;
2723 else if (EQ (window
, selected_window
))
2724 /* Prefer to return selected-window. */
2725 RETURN_UNGCPRO (window
);
2726 else if (EQ (Fwindow_frame (window
), selected_frame
))
2727 /* Prefer windows on the current frame. */
2728 best_window
= window
;
2732 case DELETE_OTHER_WINDOWS
:
2733 if (!EQ (window
, obj
))
2734 Fdelete_window (window
);
2737 case DELETE_BUFFER_WINDOWS
:
2738 if (EQ (w
->buffer
, obj
))
2740 struct frame
*fr
= XFRAME (WINDOW_FRAME (w
));
2742 /* If this window is dedicated, and in a frame of its own,
2744 if (EQ (window
, FRAME_ROOT_WINDOW (fr
))
2745 && !NILP (w
->dedicated
)
2746 && other_visible_frames (fr
))
2748 /* Skip the other windows on this frame.
2749 There might be one, the minibuffer! */
2750 while (CONSP (XCDR (windows
))
2751 && EQ (XWINDOW (XCAR (windows
))->frame
,
2752 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2753 windows
= XCDR (windows
);
2755 /* Now we can safely delete the frame. */
2756 delete_frame (w
->frame
, Qnil
);
2758 else if (NILP (w
->parent
))
2760 /* If we're deleting the buffer displayed in the
2761 only window on the frame, find a new buffer to
2764 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2765 /* Reset dedicated state of window. */
2766 w
->dedicated
= Qnil
;
2767 Fset_window_buffer (window
, buffer
, Qnil
);
2768 if (EQ (window
, selected_window
))
2769 Fset_buffer (w
->buffer
);
2772 Fdelete_window (window
);
2777 if (EQ (w
->buffer
, obj
))
2780 struct frame
*fr
= XFRAME (w
->frame
);
2782 /* Find another buffer to show in this window. */
2783 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2785 /* If this window is dedicated, and in a frame of its own,
2787 if (EQ (window
, FRAME_ROOT_WINDOW (fr
))
2788 && !NILP (w
->dedicated
)
2789 && other_visible_frames (fr
))
2791 /* Skip the other windows on this frame.
2792 There might be one, the minibuffer! */
2793 while (CONSP (XCDR (windows
))
2794 && EQ (XWINDOW (XCAR (windows
))->frame
,
2795 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2796 windows
= XCDR (windows
);
2798 /* Now we can safely delete the frame. */
2799 delete_frame (w
->frame
, Qnil
);
2801 else if (!NILP (w
->dedicated
) && !NILP (w
->parent
))
2803 Lisp_Object window_to_delete
;
2804 XSETWINDOW (window_to_delete
, w
);
2805 /* If this window is dedicated and not the only window
2806 in its frame, then kill it. */
2807 Fdelete_window (window_to_delete
);
2811 /* Otherwise show a different buffer in the window. */
2812 w
->dedicated
= Qnil
;
2813 Fset_window_buffer (window
, buffer
, Qnil
);
2814 if (EQ (window
, selected_window
))
2815 Fset_buffer (w
->buffer
);
2820 case REDISPLAY_BUFFER_WINDOWS
:
2821 if (EQ (w
->buffer
, obj
))
2823 mark_window_display_accurate (window
, 0);
2824 w
->update_mode_line
= Qt
;
2825 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2826 ++update_mode_lines
;
2827 best_window
= window
;
2831 /* Check for a window that has a killed buffer. */
2832 case CHECK_ALL_WINDOWS
:
2833 if (! NILP (w
->buffer
)
2834 && NILP (BVAR (XBUFFER (w
->buffer
), name
)))
2838 case WINDOW_LOOP_UNUSED
:
2847 /* Used for debugging. Abort if any window has a dead buffer. */
2849 extern void check_all_windows (void) EXTERNALLY_VISIBLE
;
2851 check_all_windows (void)
2853 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2856 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 0, 2, 0,
2857 doc
: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2858 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to
2861 The optional argument ALL-FRAMES specifies the frames to consider:
2863 - t means consider all windows on all existing frames.
2865 - `visible' means consider all windows on all visible frames.
2867 - 0 (the number zero) means consider all windows on all visible
2868 and iconified frames.
2870 - A frame means consider all windows on that frame only.
2872 Any other value of ALL-FRAMES means consider all windows on the
2873 selected frame and no others. */)
2874 (Lisp_Object buffer_or_name
, Lisp_Object all_frames
)
2878 if (NILP (buffer_or_name
))
2879 buffer
= Fcurrent_buffer ();
2881 buffer
= Fget_buffer (buffer_or_name
);
2883 if (BUFFERP (buffer
))
2884 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, all_frames
);
2890 resize_root_window (Lisp_Object window
, Lisp_Object delta
, Lisp_Object horizontal
, Lisp_Object ignore
)
2892 return call4 (Qresize_root_window
, window
, delta
, horizontal
, ignore
);
2896 DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal
,
2897 Sdelete_other_windows_internal
, 0, 2, "",
2898 doc
: /* Make WINDOW fill its frame.
2899 Only the frame WINDOW is on is affected. WINDOW may be any window and
2900 defaults to the selected one.
2902 Optional argument ROOT, if non-nil, must specify an internal window
2903 containing WINDOW as a subwindow. If this is the case, replace ROOT by
2904 WINDOW and leave alone any windows not contained in ROOT.
2906 When WINDOW is live try to reduce display jumps by keeping the text
2907 previously visible in WINDOW in the same place on the frame. Doing this
2908 depends on the value of (window-start WINDOW), so if calling this
2909 function in a program gives strange scrolling, make sure the
2910 window-start value is reasonable when this function is called. */)
2911 (Lisp_Object window
, Lisp_Object root
)
2913 struct window
*w
, *r
, *s
;
2915 Lisp_Object sibling
, pwindow
, swindow
, delta
;
2917 int top
, new_top
, resize_failed
;
2919 w
= decode_any_window (window
);
2920 XSETWINDOW (window
, w
);
2921 f
= XFRAME (w
->frame
);
2924 /* ROOT is the frame's root window. */
2926 root
= FRAME_ROOT_WINDOW (f
);
2930 /* ROOT must be an ancestor of WINDOW. */
2932 r
= decode_any_window (root
);
2933 pwindow
= XWINDOW (window
)->parent
;
2934 while (!NILP (pwindow
))
2935 if (EQ (pwindow
, root
))
2938 pwindow
= XWINDOW (pwindow
)->parent
;
2939 if (!EQ (pwindow
, root
))
2940 error ("Specified root is not an ancestor of specified window");
2943 if (EQ (window
, root
))
2946 /* I don't understand the "top > 0" part below. If we deal with a
2947 standalone minibuffer it would have been caught by the preceding
2949 else if (MINI_WINDOW_P (w
)) /* && top > 0) */
2950 error ("Can't expand minibuffer to full frame");
2952 if (!NILP (w
->buffer
))
2954 startpos
= marker_position (w
->start
);
2955 top
= WINDOW_TOP_EDGE_LINE (w
)
2956 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2957 /* Make sure WINDOW is the frame's selected window. */
2958 if (!EQ (window
, FRAME_SELECTED_WINDOW (f
)))
2960 if (EQ (selected_frame
, w
->frame
))
2961 Fselect_window (window
, Qnil
);
2963 FRAME_SELECTED_WINDOW (f
) = window
;
2968 /* See if the frame's selected window is a subwindow of WINDOW, by
2969 finding all the selected window's parents and comparing each
2970 one with WINDOW. If it isn't we need a new selected window for
2972 swindow
= FRAME_SELECTED_WINDOW (f
);
2976 while (!NILP (pwindow
) && !EQ (window
, pwindow
))
2977 pwindow
= XWINDOW (pwindow
)->parent
;
2979 if (EQ (window
, pwindow
))
2980 /* If WINDOW is an ancestor of SWINDOW, then SWINDOW is ok
2981 as the new selected window. */
2984 /* Else try the previous window of SWINDOW. */
2985 swindow
= Fprevious_window (swindow
, Qlambda
, Qnil
);
2988 if (!EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
2990 if (EQ (selected_frame
, w
->frame
))
2991 Fselect_window (swindow
, Qnil
);
2993 FRAME_SELECTED_WINDOW (f
) = swindow
;
2998 free_window_matrices (r
);
3000 windows_or_buffers_changed
++;
3001 Vwindow_list
= Qnil
;
3002 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3004 if (NILP (w
->buffer
))
3007 /* Resize subwindows vertically. */
3008 XSETINT (delta
, XINT (r
->total_lines
) - XINT (w
->total_lines
));
3009 w
->top_line
= r
->top_line
;
3010 resize_root_window (window
, delta
, Qnil
, Qnil
);
3011 if (resize_window_check (w
, 0))
3012 resize_window_apply (w
, 0);
3015 resize_root_window (window
, delta
, Qnil
, Qt
);
3016 if (resize_window_check (w
, 0))
3017 resize_window_apply (w
, 0);
3022 /* Resize subwindows horizontally. */
3025 w
->left_col
= r
->left_col
;
3026 XSETINT (delta
, XINT (r
->total_cols
) - XINT (w
->total_cols
));
3027 w
->left_col
= r
->left_col
;
3028 resize_root_window (window
, delta
, Qt
, Qnil
);
3029 if (resize_window_check (w
, 1))
3030 resize_window_apply (w
, 1);
3033 resize_root_window (window
, delta
, Qt
, Qt
);
3034 if (resize_window_check (w
, 1))
3035 resize_window_apply (w
, 1);
3042 /* Play safe, if we still can ... */
3045 w
= XWINDOW (window
);
3049 /* Cleanly unlink WINDOW from window-tree. */
3050 if (!NILP (w
->prev
))
3051 /* Get SIBLING above (on the left of) WINDOW. */
3054 s
= XWINDOW (sibling
);
3056 if (!NILP (s
->next
))
3057 XWINDOW (s
->next
)->prev
= sibling
;
3060 /* Get SIBLING below (on the right of) WINDOW. */
3063 s
= XWINDOW (sibling
);
3065 if (!NILP (XWINDOW (w
->parent
)->vchild
))
3066 XWINDOW (w
->parent
)->vchild
= sibling
;
3068 XWINDOW (w
->parent
)->hchild
= sibling
;
3071 /* Delete ROOT and all subwindows of ROOT. */
3072 if (!NILP (r
->vchild
))
3074 delete_all_subwindows (r
->vchild
);
3077 else if (!NILP (r
->hchild
))
3079 delete_all_subwindows (r
->hchild
);
3083 replace_window (root
, window
, 1);
3085 /* Reset WINDOW's splits status. */
3088 /* This must become SWINDOW anyway ....... */
3089 if (!NILP (w
->buffer
) && !resize_failed
)
3091 /* Try to minimize scrolling, by setting the window start to the
3092 point will cause the text at the old window start to be at the
3093 same place on the frame. But don't try to do this if the
3094 window start is outside the visible portion (as might happen
3095 when the display is not current, due to typeahead). */
3096 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
3098 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
3099 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
3101 struct position pos
;
3102 struct buffer
*obuf
= current_buffer
;
3104 Fset_buffer (w
->buffer
);
3105 /* This computation used to temporarily move point, but that
3106 can have unwanted side effects due to text properties. */
3107 pos
= *vmotion (startpos
, -top
, w
);
3109 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
3110 w
->window_end_valid
= Qnil
;
3111 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
3112 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
3114 /* We need to do this, so that the window-scroll-functions
3116 w
->optional_new_start
= Qt
;
3118 set_buffer_internal (obuf
);
3125 run_window_configuration_change_hook (f
);
3131 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
3133 doc
: /* Make WINDOW (or the selected window) fill its frame.
3134 Only the frame WINDOW is on is affected.
3135 This function tries to reduce display jumps by keeping the text
3136 previously visible in WINDOW in the same place on the frame. Doing this
3137 depends on the value of (window-start WINDOW), so if calling this
3138 function in a program gives strange scrolling, make sure the
3139 window-start value is reasonable when this function is called. */)
3140 (Lisp_Object window
)
3147 window
= selected_window
;
3149 CHECK_LIVE_WINDOW (window
);
3150 w
= XWINDOW (window
);
3152 startpos
= marker_position (w
->start
);
3153 top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
3155 if (MINI_WINDOW_P (w
) && top
> 0)
3156 error ("Can't expand minibuffer to full frame");
3158 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
3160 /* Try to minimize scrolling, by setting the window start to the point
3161 will cause the text at the old window start to be at the same place
3162 on the frame. But don't try to do this if the window start is
3163 outside the visible portion (as might happen when the display is
3164 not current, due to typeahead). */
3165 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
3167 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
3168 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
3170 struct position pos
;
3171 struct buffer
*obuf
= current_buffer
;
3173 Fset_buffer (w
->buffer
);
3174 /* This computation used to temporarily move point, but that can
3175 have unwanted side effects due to text properties. */
3176 pos
= *vmotion (startpos
, -top
, w
);
3178 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
3179 w
->window_end_valid
= Qnil
;
3180 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
3181 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
3183 /* We need to do this, so that the window-scroll-functions
3185 w
->optional_new_start
= Qt
;
3187 set_buffer_internal (obuf
);
3193 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
3194 0, 2, "bDelete windows on (buffer): ",
3195 doc
: /* Delete all windows showing BUFFER-OR-NAME.
3196 BUFFER-OR-NAME may be a buffer or the name of an existing buffer and
3197 defaults to the current buffer.
3199 Optional second argument FRAME controls which frames are affected.
3200 If optional argument FRAME is `visible', search all visible frames.
3201 If FRAME is 0, search all visible and iconified frames.
3202 If FRAME is nil, search all frames.
3203 If FRAME is t, search only the selected frame.
3204 If FRAME is a frame, search only that frame.
3205 When a window showing BUFFER-OR-NAME is dedicated and the only window of
3206 its frame, that frame is deleted when there are other frames left. */)
3207 (Lisp_Object buffer_or_name
, Lisp_Object frame
)
3211 /* FRAME uses t and nil to mean the opposite of what window_loop
3215 else if (EQ (frame
, Qt
))
3218 if (NILP (buffer_or_name
))
3219 buffer
= Fcurrent_buffer ();
3222 buffer
= Fget_buffer (buffer_or_name
);
3223 CHECK_BUFFER (buffer
);
3226 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
3231 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
3232 Sreplace_buffer_in_windows
,
3233 0, 1, "bReplace buffer in windows: ",
3234 doc
: /* Replace BUFFER-OR-NAME with some other buffer in all windows showing it.
3235 BUFFER-OR-NAME may be a buffer or the name of an existing buffer and
3236 defaults to the current buffer.
3238 When a window showing BUFFER-OR-NAME is dedicated that window is
3239 deleted. If that window is the only window on its frame, that frame is
3240 deleted too when there are other frames left. If there are no other
3241 frames left, some other buffer is displayed in that window. */)
3242 (Lisp_Object buffer_or_name
)
3246 if (NILP (buffer_or_name
))
3247 buffer
= Fcurrent_buffer ();
3250 buffer
= Fget_buffer (buffer_or_name
);
3251 CHECK_BUFFER (buffer
);
3254 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
3259 /* Replace BUFFER with some other buffer in all windows
3260 of all frames, even those on other keyboards. */
3263 replace_buffer_in_all_windows (Lisp_Object buffer
)
3265 Lisp_Object tail
, frame
;
3267 /* A single call to window_loop won't do the job
3268 because it only considers frames on the current keyboard.
3269 So loop manually over frames, and handle each one. */
3270 FOR_EACH_FRAME (tail
, frame
)
3271 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
3274 /* Set the height of WINDOW and all its inferiors. */
3276 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
3277 minimum allowable size. */
3280 check_frame_size (FRAME_PTR frame
, int *rows
, int *cols
)
3282 /* For height, we have to see:
3283 how many windows the frame has at minimum (one or two),
3284 and whether it has a menu bar or other special stuff at the top. */
3286 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
3287 ? MIN_SAFE_WINDOW_HEIGHT
3288 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
3290 if (FRAME_TOP_MARGIN (frame
) > 0)
3291 min_height
+= FRAME_TOP_MARGIN (frame
);
3293 if (*rows
< min_height
)
3295 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
3296 *cols
= MIN_SAFE_WINDOW_WIDTH
;
3299 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
3300 check if W's width can be changed, otherwise check W's height.
3301 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
3302 siblings, too. If none of the siblings is resizable, WINDOW isn't
3306 window_fixed_size_p (struct window
*w
, int width_p
, int check_siblings_p
)
3311 if (!NILP (w
->hchild
))
3313 c
= XWINDOW (w
->hchild
);
3317 /* A horizontal combination is fixed-width if all of if its
3319 while (c
&& window_fixed_size_p (c
, width_p
, 0))
3320 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
3321 fixed_p
= c
== NULL
;
3325 /* A horizontal combination is fixed-height if one of if its
3327 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
3328 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
3329 fixed_p
= c
!= NULL
;
3332 else if (!NILP (w
->vchild
))
3334 c
= XWINDOW (w
->vchild
);
3338 /* A vertical combination is fixed-width if one of if its
3340 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
3341 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
3342 fixed_p
= c
!= NULL
;
3346 /* A vertical combination is fixed-height if all of if its
3348 while (c
&& window_fixed_size_p (c
, width_p
, 0))
3349 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
3350 fixed_p
= c
== NULL
;
3353 else if (BUFFERP (w
->buffer
))
3355 struct buffer
*old
= current_buffer
;
3358 current_buffer
= XBUFFER (w
->buffer
);
3359 val
= find_symbol_value (Qwindow_size_fixed
);
3360 current_buffer
= old
;
3363 if (!EQ (val
, Qunbound
))
3365 fixed_p
= !NILP (val
);
3368 && ((EQ (val
, Qheight
) && width_p
)
3369 || (EQ (val
, Qwidth
) && !width_p
)))
3373 /* Can't tell if this one is resizable without looking at
3374 siblings. If all siblings are fixed-size this one is too. */
3375 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
3379 for (child
= w
->prev
; WINDOWP (child
); child
= XWINDOW (child
)->prev
)
3380 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
3384 for (child
= w
->next
; WINDOWP (child
); child
= XWINDOW (child
)->next
)
3385 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
3398 /* Return minimum size of leaf window W. WIDTH_P non-zero means return
3399 the minimum width of W, WIDTH_P zero means return the minimum height
3400 of W. SAFE_P non-zero means ignore window-min-height|width but just
3401 return values that won't crash Emacs and don't hide components like
3402 fringes, scrollbars, or modelines. If WIDTH_P is zero and W is the
3403 minibuffer window, always return 1. */
3406 window_min_size_2 (struct window
*w
, int width_p
, int safe_p
)
3408 /* We should consider buffer-local values of window_min_height and
3409 window_min_width here. */
3412 int safe_size
= (MIN_SAFE_WINDOW_WIDTH
3413 + WINDOW_FRINGE_COLS (w
)
3414 + WINDOW_SCROLL_BAR_COLS (w
));
3416 return safe_p
? safe_size
: max (window_min_width
, safe_size
);
3418 else if (MINI_WINDOW_P (w
))
3422 int safe_size
= (MIN_SAFE_WINDOW_HEIGHT
3423 + ((BUFFERP (w
->buffer
)
3424 && !NILP (BVAR (XBUFFER (w
->buffer
), mode_line_format
)))
3427 return safe_p
? safe_size
: max (window_min_height
, safe_size
);
3431 /* Return minimum size of window W, not taking fixed-width windows into
3432 account. WIDTH_P non-zero means return the minimum width, otherwise
3433 return the minimum height. SAFE_P non-zero means ignore
3434 window-min-height|width but just return values that won't crash Emacs
3435 and don't hide components like fringes, scrollbars, or modelines. If
3436 W is a combination window, compute the minimum size from the minimum
3437 sizes of W's children. */
3440 window_min_size_1 (struct window
*w
, int width_p
, int safe_p
)
3445 if (!NILP (w
->hchild
))
3447 /* W is a horizontal combination. */
3448 c
= XWINDOW (w
->hchild
);
3453 /* The minimum width of a horizontal combination is the sum of
3454 the minimum widths of its children. */
3457 size
+= window_min_size_1 (c
, 1, safe_p
);
3458 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
3463 /* The minimum height of a horizontal combination is the
3464 maximum of the minimum heights of its children. */
3467 size
= max (window_min_size_1 (c
, 0, safe_p
), size
);
3468 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
3472 else if (!NILP (w
->vchild
))
3474 /* W is a vertical combination. */
3475 c
= XWINDOW (w
->vchild
);
3480 /* The minimum width of a vertical combination is the maximum
3481 of the minimum widths of its children. */
3484 size
= max (window_min_size_1 (c
, 1, safe_p
), size
);
3485 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
3490 /* The minimum height of a vertical combination is the sum of
3491 the minimum height of its children. */
3494 size
+= window_min_size_1 (c
, 0, safe_p
);
3495 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
3500 /* W is a leaf window. */
3501 size
= window_min_size_2 (w
, width_p
, safe_p
);
3506 /* Return the minimum size of window W, taking fixed-size windows into
3507 account. WIDTH_P non-zero means return the minimum width, otherwise
3508 return the minimum height. SAFE_P non-zero means ignore
3509 window-min-height|width but just return values that won't crash Emacs
3510 and don't hide components like fringes, scrollbars, or modelines.
3511 IGNORE_FIXED_P non-zero means ignore if W is fixed-size. Set *FIXED
3512 to 1 if W is fixed-size unless FIXED is null. */
3515 window_min_size (struct window
*w
, int width_p
, int safe_p
, int ignore_fixed_p
, int *fixed
)
3522 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
3528 size
= WINDOW_TOTAL_SIZE (w
, width_p
);
3530 size
= window_min_size_1 (w
, width_p
, safe_p
);
3536 /* Adjust the margins of window W if text area is too small.
3537 Return 1 if window width is ok after adjustment; 0 if window
3538 is still too narrow. */
3541 adjust_window_margins (struct window
*w
)
3543 int box_cols
= (WINDOW_TOTAL_COLS (w
)
3544 - WINDOW_FRINGE_COLS (w
)
3545 - WINDOW_SCROLL_BAR_COLS (w
));
3546 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
3547 + WINDOW_RIGHT_MARGIN_COLS (w
));
3549 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
3552 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
3555 /* Window's text area is too narrow, but reducing the window
3556 margins will fix that. */
3557 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
3558 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
3560 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
3561 w
->left_margin_cols
= w
->right_margin_cols
3562 = make_number (margin_cols
/2);
3564 w
->right_margin_cols
= make_number (margin_cols
);
3567 w
->left_margin_cols
= make_number (margin_cols
);
3571 /* Calculate new sizes for windows in the list FORWARD when their
3572 compound size goes from TOTAL to SIZE. TOTAL must be greater than
3573 SIZE. The number of windows in FORWARD is NCHILDREN, and the number
3574 that can shrink is SHRINKABLE. Fixed-size windows may be shrunk if
3575 and only if RESIZE_FIXED_P is non-zero. WIDTH_P non-zero means
3576 shrink columns, otherwise shrink lines.
3578 SAFE_P zero means windows may be sized down to window-min-height
3579 lines (window-min-window columns for WIDTH_P non-zero). SAFE_P
3580 non-zero means windows may be sized down to their minimum safe sizes
3581 taking into account the space needed to display modelines, fringes,
3584 This function returns an allocated array of new sizes that the caller
3585 must free. A size -1 means the window is fixed and RESIZE_FIXED_P is
3586 zero. A size zero means the window shall be deleted. Array index 0
3587 refers to the first window in FORWARD, 1 to the second, and so on.
3589 This function resizes windows proportionally to their size. It also
3590 tries to preserve smaller windows by resizing larger windows before
3591 resizing any window to zero. If resize_proportionally is non-nil for
3592 a specific window, it will attempt to strictly resize that window
3593 proportionally, even at the expense of deleting smaller windows. */
3595 shrink_windows (int total
, int size
, int nchildren
, int shrinkable
,
3596 int resize_fixed_p
, Lisp_Object forward
, int width_p
, int safe_p
)
3598 int available_resize
= 0;
3599 int *new_sizes
, *min_sizes
;
3602 int smallest
= total
;
3603 int total_removed
= 0;
3604 int total_shrink
= total
- size
;
3607 new_sizes
= xmalloc (sizeof (*new_sizes
) * nchildren
);
3608 min_sizes
= xmalloc (sizeof (*min_sizes
) * nchildren
);
3610 for (i
= 0, child
= forward
; !NILP (child
); child
= c
->next
, ++i
)
3614 c
= XWINDOW (child
);
3615 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3617 if (!resize_fixed_p
&& window_fixed_size_p (c
, width_p
, 0))
3621 new_sizes
[i
] = child_size
;
3622 min_sizes
[i
] = window_min_size_1 (c
, width_p
, safe_p
);
3623 if (child_size
> min_sizes
[i
]
3624 && NILP (c
->resize_proportionally
))
3625 available_resize
+= child_size
- min_sizes
[i
];
3628 /* We might need to shrink some windows to zero. Find the smallest
3629 windows and set them to 0 until we can fulfil the new size. */
3631 while (shrinkable
> 1 && size
+ available_resize
< total
)
3633 for (i
= 0; i
< nchildren
; ++i
)
3634 if (new_sizes
[i
] > 0 && smallest
> new_sizes
[i
])
3635 smallest
= new_sizes
[i
];
3637 for (i
= 0; i
< nchildren
; ++i
)
3638 if (new_sizes
[i
] == smallest
)
3640 /* Resize this window down to zero. */
3642 if (smallest
> min_sizes
[i
])
3643 available_resize
-= smallest
- min_sizes
[i
];
3644 available_resize
+= smallest
;
3646 total_removed
+= smallest
;
3648 /* We don't know what the smallest is now. */
3651 /* Out of for, just remove one window at the time and
3652 check again if we have enough space. */
3657 /* Now, calculate the new sizes. Try to shrink each window
3658 proportional to its size. */
3659 for (i
= 0; i
< nchildren
; ++i
)
3661 if (new_sizes
[i
] > min_sizes
[i
])
3663 int to_shrink
= total_shrink
* new_sizes
[i
] / total
;
3665 if (new_sizes
[i
] - to_shrink
< min_sizes
[i
])
3666 to_shrink
= new_sizes
[i
] - min_sizes
[i
];
3667 new_sizes
[i
] -= to_shrink
;
3668 total_removed
+= to_shrink
;
3672 /* Any reminder due to rounding, we just subtract from windows
3673 that are left and still can be shrunk. */
3674 while (total_shrink
> total_removed
)
3676 int nonzero_sizes
= 0;
3678 for (i
= 0; i
< nchildren
; ++i
)
3679 if (new_sizes
[i
] > 0)
3682 for (i
= 0; i
< nchildren
; ++i
)
3683 if (new_sizes
[i
] > min_sizes
[i
])
3688 /* Out of for, just shrink one window at the time and
3689 check again if we have enough space. */
3693 /* Special case, only one window left. */
3694 if (nonzero_sizes
== 1)
3698 /* Any surplus due to rounding, we add to windows that are left. */
3699 while (total_shrink
< total_removed
)
3701 for (i
= 0; i
< nchildren
; ++i
)
3703 if (new_sizes
[i
] != 0 && total_shrink
< total_removed
)
3717 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
3718 WINDOW's width. Resize WINDOW's children, if any, so that they keep
3719 their proportionate size relative to WINDOW.
3721 If FIRST_ONLY is 1, change only the first of WINDOW's children when
3722 they are in series. If LAST_ONLY is 1, change only the last of
3723 WINDOW's children when they are in series.
3725 Propagate WINDOW's top or left edge position to children. Delete
3726 windows that become too small unless NODELETE_P is 1. When
3727 NODELETE_P equals 2 do not honor settings for window-min-height and
3728 window-min-width when resizing windows but use safe defaults instead.
3729 This should give better behavior when resizing frames. */
3732 size_window (Lisp_Object window
, int size
, int width_p
, int nodelete_p
, int first_only
, int last_only
)
3734 struct window
*w
= XWINDOW (window
);
3736 Lisp_Object child
, *forward
, *sideward
;
3737 int old_size
= WINDOW_TOTAL_SIZE (w
, width_p
);
3739 size
= max (0, size
);
3741 /* Delete WINDOW if it's too small. */
3742 if (nodelete_p
!= 1 && !NILP (w
->parent
)
3743 && size
< window_min_size_1 (w
, width_p
, nodelete_p
== 2))
3745 delete_window (window
);
3749 /* Set redisplay hints. */
3750 w
->last_modified
= make_number (0);
3751 w
->last_overlay_modified
= make_number (0);
3752 windows_or_buffers_changed
++;
3753 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w
->frame
)) = 1;
3757 sideward
= &w
->vchild
;
3758 forward
= &w
->hchild
;
3759 w
->total_cols
= make_number (size
);
3760 adjust_window_margins (w
);
3764 sideward
= &w
->hchild
;
3765 forward
= &w
->vchild
;
3766 w
->total_lines
= make_number (size
);
3767 w
->orig_total_lines
= Qnil
;
3770 if (!NILP (*sideward
))
3772 /* We have a chain of parallel siblings whose size should all change. */
3773 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
3775 c
= XWINDOW (child
);
3777 c
->left_col
= w
->left_col
;
3779 c
->top_line
= w
->top_line
;
3780 size_window (child
, size
, width_p
, nodelete_p
,
3781 first_only
, last_only
);
3784 else if (!NILP (*forward
) && last_only
)
3786 /* Change the last in a series of siblings. */
3787 Lisp_Object last_child
;
3793 c
= XWINDOW (child
);
3797 while (!NILP (child
));
3799 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3800 size_window (last_child
, size
- old_size
+ child_size
,
3801 width_p
, nodelete_p
, first_only
, last_only
);
3803 else if (!NILP (*forward
) && first_only
)
3805 /* Change the first in a series of siblings. */
3809 c
= XWINDOW (child
);
3812 c
->left_col
= w
->left_col
;
3814 c
->top_line
= w
->top_line
;
3816 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3817 size_window (child
, size
- old_size
+ child_size
,
3818 width_p
, nodelete_p
, first_only
, last_only
);
3820 else if (!NILP (*forward
))
3822 int fixed_size
, each
IF_LINT (= 0), extra
IF_LINT (= 0), n
;
3823 int resize_fixed_p
, nfixed
;
3824 int last_pos
, first_pos
, nchildren
, total
;
3825 int *new_sizes
= NULL
;
3827 /* Determine the fixed-size portion of this window, and the
3828 number of child windows. */
3829 fixed_size
= nchildren
= nfixed
= total
= 0;
3830 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
3834 c
= XWINDOW (child
);
3835 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3836 total
+= child_size
;
3838 if (window_fixed_size_p (c
, width_p
, 0))
3840 fixed_size
+= child_size
;
3845 /* If the new size is smaller than fixed_size, or if there
3846 aren't any resizable windows, allow resizing fixed-size
3848 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
3850 /* Compute how many lines/columns to add/remove to each child. The
3851 value of extra takes care of rounding errors. */
3852 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
3853 if (size
< total
&& n
> 1)
3854 new_sizes
= shrink_windows (total
, size
, nchildren
, n
,
3855 resize_fixed_p
, *forward
, width_p
,
3859 each
= (size
- total
) / n
;
3860 extra
= (size
- total
) - n
* each
;
3863 /* Compute new children heights and edge positions. */
3864 first_pos
= width_p
? XINT (w
->left_col
) : XINT (w
->top_line
);
3865 last_pos
= first_pos
;
3866 for (n
= 0, child
= *forward
; !NILP (child
); child
= c
->next
, ++n
)
3868 int new_child_size
, old_child_size
;
3870 c
= XWINDOW (child
);
3871 old_child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3872 new_child_size
= old_child_size
;
3874 /* The top or left edge position of this child equals the
3875 bottom or right edge of its predecessor. */
3877 c
->left_col
= make_number (last_pos
);
3879 c
->top_line
= make_number (last_pos
);
3881 /* If this child can be resized, do it. */
3882 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
3885 new_sizes
? new_sizes
[n
] : old_child_size
+ each
+ extra
;
3889 /* Set new size. Note that size_window also propagates
3890 edge positions to children, so it's not a no-op if we
3891 didn't change the child's size. */
3892 size_window (child
, new_child_size
, width_p
, 1,
3893 first_only
, last_only
);
3895 /* Remember the bottom/right edge position of this child; it
3896 will be used to set the top/left edge of the next child. */
3897 last_pos
+= new_child_size
;
3902 /* We should have covered the parent exactly with child windows. */
3903 xassert (size
== last_pos
- first_pos
);
3905 /* Now delete any children that became too small. */
3906 if (nodelete_p
!= 1)
3907 for (child
= *forward
; !NILP (child
); child
= c
->next
)
3911 c
= XWINDOW (child
);
3912 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3913 size_window (child
, child_size
, width_p
, nodelete_p
,
3914 first_only
, last_only
);
3919 /* Set WINDOW's height to HEIGHT, and recursively change the height of
3920 WINDOW's children. NODELETE zero means windows that have become
3921 smaller than window-min-height in the process may be deleted.
3922 NODELETE 1 means never delete windows that become too small in the
3923 process. (The caller should check later and do so if appropriate.)
3924 NODELETE 2 means delete only windows that have become too small to be
3925 displayed correctly. */
3928 set_window_height (Lisp_Object window
, int height
, int nodelete
)
3930 size_window (window
, height
, 0, nodelete
, 0, 0);
3933 /* Set WINDOW's width to WIDTH, and recursively change the width of
3934 WINDOW's children. NODELETE zero means windows that have become
3935 smaller than window-min-width in the process may be deleted.
3936 NODELETE 1 means never delete windows that become too small in the
3937 process. (The caller should check later and do so if appropriate.)
3938 NODELETE 2 means delete only windows that have become too small to be
3939 displayed correctly. */
3942 set_window_width (Lisp_Object window
, int width
, int nodelete
)
3944 size_window (window
, width
, 1, nodelete
, 0, 0);
3947 /* Change window heights in windows rooted in WINDOW by N lines. */
3950 change_window_heights (Lisp_Object window
, int n
)
3952 struct window
*w
= XWINDOW (window
);
3954 XSETFASTINT (w
->top_line
, XFASTINT (w
->top_line
) + n
);
3955 XSETFASTINT (w
->total_lines
, XFASTINT (w
->total_lines
) - n
);
3957 if (INTEGERP (w
->orig_top_line
))
3958 XSETFASTINT (w
->orig_top_line
, XFASTINT (w
->orig_top_line
) + n
);
3959 if (INTEGERP (w
->orig_total_lines
))
3960 XSETFASTINT (w
->orig_total_lines
, XFASTINT (w
->orig_total_lines
) - n
);
3962 /* Handle just the top child in a vertical split. */
3963 if (!NILP (w
->vchild
))
3964 change_window_heights (w
->vchild
, n
);
3966 /* Adjust all children in a horizontal split. */
3967 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
3969 w
= XWINDOW (window
);
3970 change_window_heights (window
, n
);
3975 int window_select_count
;
3977 static Lisp_Object
Fset_window_margins (Lisp_Object
, Lisp_Object
, Lisp_Object
);
3978 static Lisp_Object
Fset_window_fringes (Lisp_Object
, Lisp_Object
, Lisp_Object
,
3980 static Lisp_Object
Fset_window_scroll_bars (Lisp_Object
, Lisp_Object
,
3981 Lisp_Object
, Lisp_Object
);
3982 static Lisp_Object
Fset_window_vscroll (Lisp_Object
, Lisp_Object
, Lisp_Object
);
3985 run_funs (Lisp_Object funs
)
3987 for (; CONSP (funs
); funs
= XCDR (funs
))
3988 if (!EQ (XCAR (funs
), Qt
))
3989 call0 (XCAR (funs
));
3992 static Lisp_Object
select_window_norecord (Lisp_Object window
);
3993 static Lisp_Object
select_frame_norecord (Lisp_Object frame
);
3996 run_window_configuration_change_hook (struct frame
*f
)
3998 int count
= SPECPDL_INDEX ();
3999 Lisp_Object frame
, global_wcch
4000 = Fdefault_value (Qwindow_configuration_change_hook
);
4001 XSETFRAME (frame
, f
);
4003 if (NILP (Vrun_hooks
))
4006 /* Use the right buffer. Matters when running the local hooks. */
4007 if (current_buffer
!= XBUFFER (Fwindow_buffer (Qnil
)))
4009 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
4010 Fset_buffer (Fwindow_buffer (Qnil
));
4013 if (SELECTED_FRAME () != f
)
4015 record_unwind_protect (select_frame_norecord
, Fselected_frame ());
4016 select_frame_norecord (frame
);
4019 /* Look for buffer-local values. */
4021 Lisp_Object windows
= Fwindow_list (frame
, Qlambda
, Qnil
);
4022 for (; CONSP (windows
); windows
= XCDR (windows
))
4024 Lisp_Object window
= XCAR (windows
);
4025 Lisp_Object buffer
= Fwindow_buffer (window
);
4026 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook
,
4029 int count
= SPECPDL_INDEX ();
4030 record_unwind_protect (select_window_norecord
, Fselected_window ());
4031 select_window_norecord (window
);
4032 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook
,
4034 unbind_to (count
, Qnil
);
4039 run_funs (global_wcch
);
4040 unbind_to (count
, Qnil
);
4043 DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook
,
4044 Srun_window_configuration_change_hook
, 1, 1, 0,
4045 doc
: /* Run `window-configuration-change-hook' for FRAME. */)
4048 CHECK_LIVE_FRAME (frame
);
4049 run_window_configuration_change_hook (XFRAME (frame
));
4053 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
4054 means it's allowed to run hooks. See make_frame for a case where
4055 it's not allowed. KEEP_MARGINS_P non-zero means that the current
4056 margins, fringes, and scroll-bar settings of the window are not
4057 reset from the buffer's local settings. */
4060 set_window_buffer (Lisp_Object window
, Lisp_Object buffer
, int run_hooks_p
, int keep_margins_p
)
4062 struct window
*w
= XWINDOW (window
);
4063 struct buffer
*b
= XBUFFER (buffer
);
4064 int count
= SPECPDL_INDEX ();
4065 int samebuf
= EQ (buffer
, w
->buffer
);
4069 if (EQ (window
, selected_window
))
4070 BVAR (b
, last_selected_window
) = window
;
4072 /* Let redisplay errors through. */
4073 b
->display_error_modiff
= 0;
4075 /* Update time stamps of buffer display. */
4076 if (INTEGERP (BVAR (b
, display_count
)))
4077 XSETINT (BVAR (b
, display_count
), XINT (BVAR (b
, display_count
)) + 1);
4078 BVAR (b
, display_time
) = Fcurrent_time ();
4080 XSETFASTINT (w
->window_end_pos
, 0);
4081 XSETFASTINT (w
->window_end_vpos
, 0);
4082 memset (&w
->last_cursor
, 0, sizeof w
->last_cursor
);
4083 w
->window_end_valid
= Qnil
;
4084 if (!(keep_margins_p
&& samebuf
))
4085 { /* If we're not actually changing the buffer, don't reset hscroll and
4086 vscroll. This case happens for example when called from
4087 change_frame_size_1, where we use a dummy call to
4088 Fset_window_buffer on the frame's selected window (and no other)
4089 just in order to run window-configuration-change-hook.
4090 Resetting hscroll and vscroll here is problematic for things like
4091 image-mode and doc-view-mode since it resets the image's position
4092 whenever we resize the frame. */
4093 w
->hscroll
= w
->min_hscroll
= make_number (0);
4095 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
4096 set_marker_restricted (w
->start
,
4097 make_number (b
->last_window_start
),
4099 w
->start_at_line_beg
= Qnil
;
4100 w
->force_start
= Qnil
;
4101 XSETFASTINT (w
->last_modified
, 0);
4102 XSETFASTINT (w
->last_overlay_modified
, 0);
4104 /* Maybe we could move this into the `if' but it's not obviously safe and
4105 I doubt it's worth the trouble. */
4106 windows_or_buffers_changed
++;
4108 /* We must select BUFFER for running the window-scroll-functions. */
4109 /* We can't check ! NILP (Vwindow_scroll_functions) here
4110 because that might itself be a local variable. */
4111 if (window_initialized
)
4113 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
4114 Fset_buffer (buffer
);
4117 XMARKER (w
->pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
4119 if (!keep_margins_p
)
4121 /* Set left and right marginal area width etc. from buffer. */
4123 /* This may call adjust_window_margins three times, so
4124 temporarily disable window margins. */
4125 Lisp_Object save_left
= w
->left_margin_cols
;
4126 Lisp_Object save_right
= w
->right_margin_cols
;
4128 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
4130 Fset_window_fringes (window
,
4131 BVAR (b
, left_fringe_width
), BVAR (b
, right_fringe_width
),
4132 BVAR (b
, fringes_outside_margins
));
4134 Fset_window_scroll_bars (window
,
4135 BVAR (b
, scroll_bar_width
),
4136 BVAR (b
, vertical_scroll_bar_type
), Qnil
);
4138 w
->left_margin_cols
= save_left
;
4139 w
->right_margin_cols
= save_right
;
4141 Fset_window_margins (window
,
4142 BVAR (b
, left_margin_cols
), BVAR (b
, right_margin_cols
));
4147 if (! NILP (Vwindow_scroll_functions
))
4148 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
4149 Fmarker_position (w
->start
));
4150 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w
)));
4153 unbind_to (count
, Qnil
);
4156 DEFUN ("set-window-clone-number", Fset_window_clone_number
, Sset_window_clone_number
, 2, 2, 0,
4157 doc
: /* Set WINDOW's clone number to CLONE-NUMBER.
4158 WINDOW can be any window and defaults to the selected one. */)
4159 (Lisp_Object window
, Lisp_Object clone_number
)
4161 register struct window
*w
= decode_any_window (window
);
4163 CHECK_NUMBER (clone_number
);
4164 w
->clone_number
= clone_number
;
4165 return w
->clone_number
;
4168 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
4169 doc
: /* Make WINDOW display BUFFER-OR-NAME as its contents.
4170 WINDOW defaults to the selected window. BUFFER-OR-NAME must be a buffer
4171 or the name of an existing buffer. Optional third argument KEEP-MARGINS
4172 non-nil means that WINDOW's current display margins, fringe widths, and
4173 scroll bar settings are preserved; the default is to reset these from
4174 the local settings for BUFFER-OR-NAME or the frame defaults. Return nil.
4176 This function throws an error when WINDOW is strongly dedicated to its
4177 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
4178 already display BUFFER-OR-NAME.
4180 This function runs `window-scroll-functions' before running
4181 `window-configuration-change-hook'. */)
4182 (register Lisp_Object window
, Lisp_Object buffer_or_name
, Lisp_Object keep_margins
)
4184 register Lisp_Object tem
, buffer
;
4185 register struct window
*w
= decode_window (window
);
4187 XSETWINDOW (window
, w
);
4188 buffer
= Fget_buffer (buffer_or_name
);
4189 CHECK_BUFFER (buffer
);
4190 if (NILP (BVAR (XBUFFER (buffer
), name
)))
4191 error ("Attempt to display deleted buffer");
4195 error ("Window is deleted");
4196 else if (!EQ (tem
, Qt
))
4197 /* w->buffer is t when the window is first being set up. */
4199 if (EQ (tem
, buffer
))
4201 else if (EQ (w
->dedicated
, Qt
))
4202 error ("Window is dedicated to `%s'", SDATA (BVAR (XBUFFER (tem
), name
)));
4204 w
->dedicated
= Qnil
;
4209 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
4214 select_window_norecord (Lisp_Object window
)
4216 return WINDOW_LIVE_P (window
)
4217 ? Fselect_window (window
, Qt
) : selected_window
;
4221 select_frame_norecord (Lisp_Object frame
)
4223 return FRAME_LIVE_P (XFRAME (frame
))
4224 ? Fselect_frame (frame
, Qt
) : selected_frame
;
4228 display_buffer (Lisp_Object buffer
, Lisp_Object not_this_window_p
, Lisp_Object override_frame
)
4230 return call3 (Qdisplay_buffer
, buffer
, not_this_window_p
, override_frame
);
4233 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
4235 doc
: /* Force all windows to be updated on next redisplay.
4236 If optional arg OBJECT is a window, force redisplay of that window only.
4237 If OBJECT is a buffer or buffer name, force redisplay of all windows
4238 displaying that buffer. */)
4239 (Lisp_Object object
)
4243 windows_or_buffers_changed
++;
4244 update_mode_lines
++;
4248 if (WINDOWP (object
))
4250 struct window
*w
= XWINDOW (object
);
4251 mark_window_display_accurate (object
, 0);
4252 w
->update_mode_line
= Qt
;
4253 if (BUFFERP (w
->buffer
))
4254 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
4255 ++update_mode_lines
;
4259 if (STRINGP (object
))
4260 object
= Fget_buffer (object
);
4261 if (BUFFERP (object
) && !NILP (BVAR (XBUFFER (object
), name
)))
4263 /* Walk all windows looking for buffer, and force update
4264 of each of those windows. */
4266 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
4267 return NILP (object
) ? Qnil
: Qt
;
4270 /* If nothing suitable was found, just return.
4271 We could signal an error, but this feature will typically be used
4272 asynchronously in timers or process sentinels, so we don't. */
4278 temp_output_buffer_show (register Lisp_Object buf
)
4280 register struct buffer
*old
= current_buffer
;
4281 register Lisp_Object window
;
4282 register struct window
*w
;
4284 BVAR (XBUFFER (buf
), directory
) = BVAR (current_buffer
, directory
);
4287 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
4291 set_buffer_internal (old
);
4293 if (!NILP (Vtemp_buffer_show_function
))
4294 call1 (Vtemp_buffer_show_function
, buf
);
4297 window
= display_buffer (buf
, Qnil
, Qnil
);
4299 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
4300 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
4301 Vminibuf_scroll_window
= window
;
4302 w
= XWINDOW (window
);
4303 XSETFASTINT (w
->hscroll
, 0);
4304 XSETFASTINT (w
->min_hscroll
, 0);
4305 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
4306 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
4308 /* Run temp-buffer-show-hook, with the chosen window selected
4309 and its buffer current. */
4311 int count
= SPECPDL_INDEX ();
4312 Lisp_Object prev_window
, prev_buffer
;
4313 prev_window
= selected_window
;
4314 XSETBUFFER (prev_buffer
, old
);
4316 /* Select the window that was chosen, for running the hook.
4317 Note: Both Fselect_window and select_window_norecord may
4318 set-buffer to the buffer displayed in the window,
4319 so we need to save the current buffer. --stef */
4320 record_unwind_protect (Fset_buffer
, prev_buffer
);
4321 record_unwind_protect (select_window_norecord
, prev_window
);
4322 Fselect_window (window
, Qt
);
4323 Fset_buffer (w
->buffer
);
4324 Frun_hooks (1, &Qtemp_buffer_show_hook
);
4325 unbind_to (count
, Qnil
);
4330 DEFUN ("internal-temp-output-buffer-show",
4331 Ftemp_output_buffer_show
, Stemp_output_buffer_show
,
4333 doc
: /* Internal function for `with-output-to-temp-buffer''. */)
4336 temp_output_buffer_show (buf
);
4341 make_dummy_parent (Lisp_Object window
)
4344 register struct window
*o
, *p
;
4347 o
= XWINDOW (window
);
4348 p
= allocate_window ();
4349 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
4350 ((struct Lisp_Vector
*) p
)->contents
[i
]
4351 = ((struct Lisp_Vector
*)o
)->contents
[i
];
4352 XSETWINDOW (new, p
);
4355 XSETFASTINT (p
->sequence_number
, sequence_number
);
4356 XSETFASTINT (p
->clone_number
, sequence_number
);
4358 /* Put new into window structure in place of window */
4359 replace_window (window
, new, 1);
4373 p
->window_parameters
= Qnil
;
4377 /* Make new window, have it replace WINDOW in window-tree, and make
4378 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
4379 horizontal child). */
4381 make_parent_window (Lisp_Object window
, int horflag
)
4384 register struct window
*o
, *p
;
4387 o
= XWINDOW (window
);
4388 p
= allocate_window ();
4389 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
4390 ((struct Lisp_Vector
*) p
)->contents
[i
]
4391 = ((struct Lisp_Vector
*) o
)->contents
[i
];
4392 XSETWINDOW (parent
, p
);
4395 XSETFASTINT (p
->sequence_number
, sequence_number
);
4396 XSETFASTINT (p
->clone_number
, sequence_number
);
4398 replace_window (window
, parent
, 1);
4404 p
->hchild
= horflag
? window
: Qnil
;
4405 p
->vchild
= horflag
? Qnil
: window
;
4411 p
->window_parameters
= Qnil
;
4414 /* Make new window from scratch. */
4419 register struct window
*w
;
4421 w
= allocate_window ();
4422 /* Initialize all Lisp data. */
4423 w
->frame
= w
->mini_p
= Qnil
;
4424 w
->next
= w
->prev
= w
->hchild
= w
->vchild
= w
->parent
= Qnil
;
4425 XSETFASTINT (w
->left_col
, 0);
4426 XSETFASTINT (w
->top_line
, 0);
4427 XSETFASTINT (w
->total_lines
, 0);
4428 XSETFASTINT (w
->total_cols
, 0);
4429 w
->normal_lines
= make_float (1.0);
4430 w
->normal_cols
= make_float (1.0);
4431 XSETFASTINT (w
->new_total
, 0);
4432 XSETFASTINT (w
->new_normal
, 0);
4434 w
->start
= Fmake_marker ();
4435 w
->pointm
= Fmake_marker ();
4436 w
->force_start
= w
->optional_new_start
= Qnil
;
4437 XSETFASTINT (w
->hscroll
, 0);
4438 XSETFASTINT (w
->min_hscroll
, 0);
4439 XSETFASTINT (w
->use_time
, 0);
4441 XSETFASTINT (w
->sequence_number
, sequence_number
);
4442 XSETFASTINT (w
->clone_number
, sequence_number
);
4443 w
->temslot
= w
->last_modified
= w
->last_overlay_modified
= Qnil
;
4444 XSETFASTINT (w
->last_point
, 0);
4445 w
->last_had_star
= w
->vertical_scroll_bar
= Qnil
;
4446 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
4447 w
->left_fringe_width
= w
->right_fringe_width
= Qnil
;
4448 w
->fringes_outside_margins
= Qnil
;
4449 w
->scroll_bar_width
= Qnil
;
4450 w
->vertical_scroll_bar_type
= Qt
;
4451 w
->last_mark_x
= w
->last_mark_y
= Qnil
;
4452 XSETFASTINT (w
->window_end_pos
, 0);
4453 XSETFASTINT (w
->window_end_vpos
, 0);
4454 w
->window_end_valid
= w
->update_mode_line
= Qnil
;
4455 w
->start_at_line_beg
= w
->display_table
= w
->dedicated
= Qnil
;
4456 w
->base_line_number
= w
->base_line_pos
= w
->region_showing
= Qnil
;
4457 w
->column_number_displayed
= w
->redisplay_end_trigger
= Qnil
;
4458 w
->splits
= w
->nest
= w
->window_parameters
= Qnil
;
4459 w
->prev_buffers
= w
->next_buffers
= Qnil
;
4460 /* Initialize non-Lisp data. */
4461 w
->desired_matrix
= w
->current_matrix
= 0;
4462 w
->nrows_scale_factor
= w
->ncols_scale_factor
= 1;
4463 memset (&w
->cursor
, 0, sizeof (w
->cursor
));
4464 memset (&w
->last_cursor
, 0, sizeof (w
->last_cursor
));
4465 memset (&w
->phys_cursor
, 0, sizeof (w
->phys_cursor
));
4466 w
->phys_cursor_type
= -1;
4467 w
->phys_cursor_width
= -1;
4468 w
->last_cursor_off_p
= w
->cursor_off_p
= 0;
4469 w
->must_be_updated_p
= 0;
4470 w
->pseudo_window_p
= 0;
4471 w
->frozen_window_start_p
= 0;
4473 w
->resize_proportionally
= Qnil
;
4474 /* Reset window_list. */
4475 Vwindow_list
= Qnil
;
4476 /* Return window. */
4477 XSETWINDOW (window
, w
);
4481 DEFUN ("set-window-new-total", Fset_window_new_total
, Sset_window_new_total
, 2, 3, 0,
4482 doc
: /* Set new total size of WINDOW to SIZE.
4485 Optional argument ADD non-nil means add SIZE to the new total size of
4486 WINDOW and return the sum.
4488 Note: This function does not operate on any subwindows of WINDOW. */)
4489 (Lisp_Object window
, Lisp_Object size
, Lisp_Object add
)
4491 struct window
*w
= decode_any_window (window
);
4493 CHECK_NUMBER (size
);
4495 XSETINT (w
->new_total
, XINT (size
));
4497 XSETINT (w
->new_total
, XINT (w
->new_total
) + XINT (size
));
4499 return w
->new_total
;
4502 DEFUN ("set-window-new-normal", Fset_window_new_normal
, Sset_window_new_normal
, 1, 2, 0,
4503 doc
: /* Set new normal size of WINDOW to SIZE.
4506 Note: This function does not operate on any subwindows of WINDOW. */)
4507 (Lisp_Object window
, Lisp_Object size
)
4509 struct window
*w
= decode_any_window (window
);
4511 w
->new_normal
= size
;
4512 return w
->new_normal
;
4515 /* Return 1 if setting w->total_lines (w->total_cols if HORFLAG is
4516 non-zero) to w->new_total would result in correct heights (widths)
4517 for window W and recursively all subwindows of W.
4519 Note: This function does not check any of `window-fixed-size-p',
4520 `window-min-height' or `window-min-width'. It does check that window
4521 sizes do not drop below one line (two columns). */
4523 resize_window_check (struct window
*w
, int horflag
)
4527 if (!NILP (w
->vchild
))
4528 /* W is a vertical combination. */
4530 c
= XWINDOW (w
->vchild
);
4532 /* All subwindows of W must have the same width as W. */
4536 if ((XINT (c
->new_total
) != XINT (w
->new_total
))
4537 || !resize_window_check (c
, horflag
))
4539 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4544 /* The sum of the heights of the subwindows of W must equal W's
4547 int sum_of_sizes
= 0;
4550 if (!resize_window_check (c
, horflag
))
4552 sum_of_sizes
= sum_of_sizes
+ XINT (c
->new_total
);
4553 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4555 return (sum_of_sizes
== XINT (w
->new_total
));
4558 else if (!NILP (w
->hchild
))
4559 /* W is a horizontal combination. */
4561 c
= XWINDOW (w
->hchild
);
4563 /* The sum of the widths of the subwindows of W must equal W's
4566 int sum_of_sizes
= 0;
4569 if (!resize_window_check (c
, horflag
))
4571 sum_of_sizes
= sum_of_sizes
+ XINT (c
->new_total
);
4572 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4574 return (sum_of_sizes
== XINT (w
->new_total
));
4577 /* All subwindows of W must have the same height as W. */
4581 if ((XINT (c
->new_total
) != XINT (w
->new_total
))
4582 || !resize_window_check (c
, horflag
))
4584 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4590 /* A leaf window. Make sure it's not too small. The following
4591 hardcodes the values of `window-safe-min-width' (2) and
4592 `window-safe-min-height' (1) which are defined in window.el. */
4593 return XINT (w
->new_total
) >= (horflag
? 2 : 1);
4596 /* Set w->total_lines (w->total_cols if HORIZONTAL is non-zero) to
4597 w->new_total for window W and recursively all subwindows of W. Also
4598 calculate and assign the new vertical (horizontal) start positions of
4599 each of these windows.
4601 This function does not perform any error checks. Make sure you have
4602 run resize_window_check on W before applying this function. */
4604 resize_window_apply (struct window
*w
, int horflag
)
4606 struct window
*c
, *p
;
4609 /* Note: Assigning new_normal requires that the new total size of the
4610 parent window has been set *before*. */
4613 w
->total_cols
= w
->new_total
;
4614 if (NUMBERP (w
->new_normal
))
4615 w
->normal_cols
= w
->new_normal
;
4617 pos
= XINT (w
->left_col
);
4621 w
->total_lines
= w
->new_total
;
4622 if (NUMBERP (w
->new_normal
))
4623 w
->normal_lines
= w
->new_normal
;
4625 pos
= XINT (w
->top_line
);
4628 if (!NILP (w
->vchild
))
4629 /* W is a vertical combination. */
4631 c
= XWINDOW (w
->vchild
);
4635 XSETFASTINT (c
->left_col
, pos
);
4637 XSETFASTINT (c
->top_line
, pos
);
4638 resize_window_apply (c
, horflag
);
4640 pos
= pos
+ XINT (c
->total_lines
);
4641 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4644 else if (!NILP (w
->hchild
))
4645 /* W is a horizontal combination. */
4647 c
= XWINDOW (w
->hchild
);
4651 XSETFASTINT (c
->left_col
, pos
);
4653 XSETFASTINT (c
->top_line
, pos
);
4654 resize_window_apply (c
, horflag
);
4656 pos
= pos
+ XINT (c
->total_cols
);
4657 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4661 /* Clear out some redisplay caches. */
4662 XSETFASTINT (w
->last_modified
, 0);
4663 XSETFASTINT (w
->last_overlay_modified
, 0);
4667 DEFUN ("resize-window-apply", Fresize_window_apply
, Sresize_window_apply
, 1, 2, 0,
4668 doc
: /* Apply requested size values for window-tree of FRAME.
4669 Optional argument HORIZONTAL omitted or nil means apply requested height
4670 values. HORIZONTAL non-nil means apply requested width values.
4672 This function checks whether the requested values sum up to a valid
4673 window layout, recursively assigns the new sizes of all subwindows and
4674 calculates and assigns the new start positions of these windows.
4676 Note: This function does not check any of `window-fixed-size-p',
4677 `window-min-height' or `window-min-width'. All these checks have to
4678 be applied on the Elisp level. */)
4679 (Lisp_Object frame
, Lisp_Object horizontal
)
4683 int horflag
= !NILP (horizontal
);
4686 frame
= selected_frame
;
4687 CHECK_LIVE_FRAME (frame
);
4690 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4692 if (!resize_window_check (r
, horflag
)
4693 || ! EQ (r
->new_total
, (horflag
? r
->total_cols
: r
->total_lines
)))
4697 resize_window_apply (r
, horflag
);
4699 windows_or_buffers_changed
++;
4700 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4705 run_window_configuration_change_hook (f
);
4711 /* Resize frame F's windows when number of lines of F is set to SIZE.
4712 HORFLAG 1 means resize windows when number of columns of F is set to
4715 This function can delete all windows but the selected one in order to
4716 satisfy the request. The result will be meaningful if and only if
4717 F's windows have meaningful sizes when you call this. */
4719 resize_frame_windows (struct frame
*f
, int size
, int horflag
)
4721 Lisp_Object root
= f
->root_window
;
4722 struct window
*r
= XWINDOW (root
);
4723 Lisp_Object mini
= f
->minibuffer_window
;
4725 /* new_size is the new size of the frame's root window. */
4726 int new_size
= (horflag
4729 - FRAME_TOP_MARGIN (f
)
4730 - ((FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
4733 XSETFASTINT (r
->top_line
, FRAME_TOP_MARGIN (f
));
4734 if (NILP (r
->vchild
) && NILP (r
->hchild
))
4735 /* For a leaf root window just set the size. */
4737 XSETFASTINT (r
->total_cols
, new_size
);
4739 XSETFASTINT (r
->total_lines
, new_size
);
4742 /* old_size is the old size of the frame's root window. */
4743 int old_size
= XFASTINT (horflag
? r
->total_cols
: r
->total_lines
);
4746 XSETINT (delta
, new_size
- old_size
);
4747 /* Try a "normal" resize first. */
4748 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qnil
);
4749 if (resize_window_check (r
, horflag
) && new_size
== XINT (r
->new_total
))
4750 resize_window_apply (r
, horflag
);
4753 /* Try with "reasonable" minimum sizes next. */
4754 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qt
);
4755 if (resize_window_check (r
, horflag
)
4756 && new_size
== XINT (r
->new_total
))
4757 resize_window_apply (r
, horflag
);
4760 /* Finally, try with "safe" minimum sizes. */
4761 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qsafe
);
4762 if (resize_window_check (r
, horflag
)
4763 && new_size
== XINT (r
->new_total
))
4764 resize_window_apply (r
, horflag
);
4767 /* We lost. Delete all windows but the frame's
4769 root
= f
->selected_window
;
4770 Fdelete_other_windows_internal (root
, Qnil
);
4772 XSETFASTINT (XWINDOW (root
)->total_cols
, new_size
);
4774 XSETFASTINT (XWINDOW (root
)->total_lines
, new_size
);
4780 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
4784 XSETFASTINT (m
->total_cols
, size
);
4787 /* Are we sure we always want 1 line here? */
4788 XSETFASTINT (m
->total_lines
, 1);
4789 XSETFASTINT (m
->top_line
, XINT (r
->top_line
) + XINT (r
->total_lines
));
4795 DEFUN ("split-window-internal", Fsplit_window_internal
, Ssplit_window_internal
, 4, 4, 0,
4796 doc
: /* Split window OLD.
4797 Second argument TOTAL-SIZE specifies the number of lines or columns of the
4798 new window. In any case TOTAL-SIZE must be a positive integer
4800 Third argument SIDE nil (or `below') specifies that the new window shall
4801 be located below WINDOW. SIDE `above' means the new window shall be
4802 located above WINDOW. In both cases TOTAL-SIZE specifies the number of
4803 lines of the new window including space reserved for the mode and/or
4806 SIDE t (or `right') specifies that the new window shall be located on
4807 the right side of WINDOW. SIDE `left' means the new window shall be
4808 located on the left of WINDOW. In both cases TOTAL-SIZE specifies the
4809 number of columns of the new window including space reserved for fringes
4810 and the scrollbar or a divider column.
4812 Fourth argument NORMAL-SIZE specifies the normal size of the new window
4813 according to the SIDE argument.
4815 The new total and normal sizes of all involved windows must have been
4816 set correctly. See the code of `split-window' for how this is done. */)
4817 (Lisp_Object old
, Lisp_Object total_size
, Lisp_Object side
, Lisp_Object normal_size
)
4819 /* OLD (*o) is the window we have to split. (*p) is either OLD's
4820 parent window or an internal window we have to install as OLD's new
4821 parent. REFERENCE (*r) must denote a live window, or is set to OLD
4822 provided OLD is a leaf window, or to the frame's selected window.
4823 NEW (*n) is the new window created with some parameters taken from
4825 register Lisp_Object
new, frame
, reference
;
4826 register struct window
*o
, *p
, *n
, *r
;
4829 /* HORFLAG is 1 when we split side-by-side, 0 otherwise. */
4830 = EQ (side
, Qt
) || EQ (side
, Qleft
) || EQ (side
, Qright
);
4835 frame
= WINDOW_FRAME (o
);
4838 CHECK_NUMBER (total_size
);
4840 /* Set do_nest to 1 if we have to make a new parent window. We do
4841 that if either `window-nest' is non-nil, or OLD has no parent, or
4842 OLD is ortho-combined. */
4844 !NILP (Vwindow_nest
)
4847 ? (XWINDOW (o
->parent
)->hchild
)
4848 : (XWINDOW (o
->parent
)->vchild
));
4850 /* We need a live reference window to initialize some parameters. */
4851 if (WINDOW_LIVE_P (old
))
4852 /* OLD is live, use it as reference window. */
4855 /* Use the frame's selected window as reference window. */
4856 reference
= FRAME_SELECTED_WINDOW (f
);
4857 r
= XWINDOW (reference
);
4859 /* The following bugs are caught by `split-window'. */
4860 if (MINI_WINDOW_P (o
))
4861 error ("Attempt to split minibuffer window");
4862 else if (XINT (total_size
) < (horflag
? 2 : 1))
4863 error ("Size of new window too small (after split)");
4864 else if (!do_nest
&& !NILP (Vwindow_splits
))
4865 /* `window-splits' non-nil means try to resize OLD's siblings
4868 p
= XWINDOW (o
->parent
);
4869 /* Temporarily pretend we split the parent window. */
4870 XSETINT (p
->new_total
,
4871 XINT (horflag
? p
->total_cols
: p
->total_lines
)
4872 - XINT (total_size
));
4873 if (!resize_window_check (p
, horflag
))
4874 error ("Window sizes don't fit");
4876 /* Undo the temporary pretension. */
4877 p
->new_total
= horflag
? p
->total_cols
: p
->total_lines
;
4881 if (!resize_window_check (o
, horflag
))
4882 error ("Resizing old window failed");
4883 else if (XINT (total_size
) + XINT (o
->new_total
)
4884 != XINT (horflag
? o
->total_cols
: o
->total_lines
))
4885 error ("Sum of sizes of old and new window don't fit");
4888 /* This is our point of no return. */
4891 /* Save the old value of o->normal_cols/lines. It gets corrupted
4892 by make_parent_window and we need it below for assigning it to
4894 Lisp_Object new_normal
= horflag
? o
->normal_cols
: o
->normal_lines
;
4896 make_parent_window (old
, horflag
);
4897 p
= XWINDOW (o
->parent
);
4898 /* Store value of `window-nest' in new parent's nest slot. */
4899 p
->nest
= Vwindow_nest
;
4900 /* Have PARENT inherit splits slot value from OLD. */
4901 p
->splits
= o
->splits
;
4902 /* Store value of `window-splits' in OLD's splits slot. */
4903 o
->splits
= Vwindow_splits
;
4904 /* These get applied below. */
4905 p
->new_total
= horflag
? o
->total_cols
: o
->total_lines
;
4906 p
->new_normal
= new_normal
;
4909 p
= XWINDOW (o
->parent
);
4911 windows_or_buffers_changed
++;
4912 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4913 new = make_window ();
4916 n
->parent
= o
->parent
;
4917 n
->vchild
= n
->hchild
= Qnil
;
4919 if (EQ (side
, Qabove
) || EQ (side
, Qleft
))
4928 XWINDOW (n
->prev
)->next
= new;
4935 if (!NILP (n
->next
))
4936 XWINDOW (n
->next
)->prev
= new;
4942 n
->window_end_valid
= Qnil
;
4943 memset (&n
->last_cursor
, 0, sizeof n
->last_cursor
);
4945 /* Get special geometry settings from reference window. */
4946 n
->left_margin_cols
= r
->left_margin_cols
;
4947 n
->right_margin_cols
= r
->right_margin_cols
;
4948 n
->left_fringe_width
= r
->left_fringe_width
;
4949 n
->right_fringe_width
= r
->right_fringe_width
;
4950 n
->fringes_outside_margins
= r
->fringes_outside_margins
;
4951 n
->scroll_bar_width
= r
->scroll_bar_width
;
4952 n
->vertical_scroll_bar_type
= r
->vertical_scroll_bar_type
;
4954 /* Store `window-splits' in NEW's splits slot. */
4955 n
->splits
= Vwindow_splits
;
4957 /* Directly assign orthogonal coordinates and sizes. */
4960 n
->top_line
= o
->top_line
;
4961 n
->total_lines
= o
->total_lines
;
4965 n
->left_col
= o
->left_col
;
4966 n
->total_cols
= o
->total_cols
;
4969 /* Iso-coordinates and sizes are assigned by resize_window_apply,
4970 get them ready here. */
4971 n
->new_total
= total_size
;
4972 n
->new_normal
= normal_size
;
4975 resize_window_apply (p
, horflag
);
4977 /* Set buffer of NEW to buffer of reference window. Don't run
4979 set_window_buffer (new, r
->buffer
, 0, 1);
4982 /* Maybe we should run the scroll functions in Elisp (which already
4983 runs the configuration change hook). */
4984 if (! NILP (Vwindow_scroll_functions
))
4985 run_hook_with_args_2 (Qwindow_scroll_functions
, new,
4986 Fmarker_position (n
->start
));
4992 DEFUN ("delete-window-internal", Fdelete_window_internal
, Sdelete_window_internal
, 1, 1, 0,
4993 doc
: /* Remove WINDOW from its frame.
4994 WINDOW defaults to the selected window. Return nil. Signal an error
4995 when WINDOW is the only window on its frame. */)
4996 (register Lisp_Object window
)
4998 register Lisp_Object parent
, sibling
, frame
, root
;
4999 struct window
*w
, *p
, *s
, *r
;
5002 int before_sibling
= 0;
5004 w
= decode_any_window (window
);
5005 XSETWINDOW (window
, w
);
5006 if (NILP (w
->buffer
) && NILP (w
->hchild
) && NILP (w
->vchild
))
5007 /* It's a no-op to delete an already deleted window. */
5012 /* Never delete a minibuffer or frame root window. */
5013 error ("Attempt to delete minibuffer or sole ordinary window");
5014 else if (NILP (w
->prev
) && NILP (w
->next
))
5015 /* Rather bow out here, this case should be handled on the Elisp
5017 error ("Attempt to delete sole window of parent");
5019 p
= XWINDOW (parent
);
5020 horflag
= NILP (p
->vchild
);
5022 frame
= WINDOW_FRAME (w
);
5025 root
= FRAME_ROOT_WINDOW (f
);
5028 /* Unlink WINDOW from window tree. */
5030 /* Get SIBLING below (on the right of) WINDOW. */
5032 /* before_sibling 1 means WINDOW is the first child of its
5033 parent and thus before the sibling. */
5036 s
= XWINDOW (sibling
);
5039 p
->hchild
= sibling
;
5041 p
->vchild
= sibling
;
5044 /* Get SIBLING above (on the left of) WINDOW. */
5047 s
= XWINDOW (sibling
);
5049 if (!NILP (s
->next
))
5050 XWINDOW (s
->next
)->prev
= sibling
;
5053 if (resize_window_check (r
, horflag
)
5054 && EQ (r
->new_total
, (horflag
? r
->total_cols
: r
->total_lines
)))
5055 /* We can delete WINDOW now. */
5059 resize_window_apply (p
, horflag
);
5061 windows_or_buffers_changed
++;
5062 Vwindow_list
= Qnil
;
5063 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
5065 w
->next
= Qnil
; /* Don't delete w->next too. */
5066 free_window_matrices (w
);
5068 if (!NILP (w
->vchild
))
5070 delete_all_subwindows (w
->vchild
);
5073 else if (!NILP (w
->hchild
))
5075 delete_all_subwindows (w
->hchild
);
5078 else if (!NILP (w
->buffer
))
5081 unchain_marker (XMARKER (w
->pointm
));
5082 unchain_marker (XMARKER (w
->start
));
5086 if (NILP (s
->prev
) && NILP (s
->next
))
5087 /* A matrjoshka where SIBLING has become the only child of
5090 /* Put SIBLING into PARENT's place. */
5091 replace_window (parent
, sibling
, 0);
5092 /* Have SIBLING inherit the following three slot values from
5093 PARENT (the nest slot is not inherited). */
5094 s
->normal_cols
= p
->normal_cols
;
5095 s
->normal_lines
= p
->normal_lines
;
5096 s
->splits
= p
->splits
;
5097 /* Mark PARENT as deleted. */
5098 p
->vchild
= p
->hchild
= Qnil
;
5099 /* Try to merge SIBLING into its new parent. */
5100 recombine_windows (sibling
);
5105 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f
)))
5106 /* We deleted the frame's selected window. */
5108 /* Use the frame's first window as fallback ... */
5109 Lisp_Object new_selected_window
= Fframe_first_window (frame
);
5110 /* ... but preferably use its most recently used window. */
5111 Lisp_Object mru_window
;
5113 /* `get-mru-window' might fail for some reason so play it safe
5114 - promote the first window _without recording it_ first. */
5115 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
5116 Fselect_window (new_selected_window
, Qt
);
5118 FRAME_SELECTED_WINDOW (f
) = new_selected_window
;
5122 /* Now look whether `get-mru-window' gets us something. */
5123 mru_window
= call1 (Qget_mru_window
, frame
);
5124 if (WINDOW_LIVE_P (mru_window
)
5125 && EQ (XWINDOW (mru_window
)->frame
, frame
))
5126 new_selected_window
= mru_window
;
5128 /* If all ended up well, we now promote the mru window. */
5129 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
5130 Fselect_window (new_selected_window
, Qnil
);
5132 FRAME_SELECTED_WINDOW (f
) = new_selected_window
;
5137 /* Must be run by the caller:
5138 run_window_configuration_change_hook (f); */
5141 /* We failed: Relink WINDOW into window tree. */
5154 if (!NILP (w
->next
))
5155 XWINDOW (w
->next
)->prev
= window
;
5157 error ("Deletion failed");
5163 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
5164 doc
: /* Split WINDOW, putting SIZE lines in the first of the pair.
5165 WINDOW defaults to selected one and SIZE to half its size.
5166 If optional third arg HORIZONTAL is non-nil, split side by side and put
5167 SIZE columns in the first of the pair. In that case, SIZE includes that
5168 window's scroll bar, or the divider column to its right.
5169 Interactively, all arguments are nil.
5170 Returns the newly created window (which is the lower or rightmost one).
5171 The upper or leftmost window is the original one, and remains selected
5172 if it was selected before.
5174 See Info node `(elisp)Splitting Windows' for more details and examples. */)
5175 (Lisp_Object window
, Lisp_Object size
, Lisp_Object horizontal
)
5177 register Lisp_Object
new;
5178 register struct window
*o
, *p
;
5180 register int size_int
;
5183 window
= selected_window
;
5185 CHECK_LIVE_WINDOW (window
);
5187 o
= XWINDOW (window
);
5188 fo
= XFRAME (WINDOW_FRAME (o
));
5192 if (!NILP (horizontal
))
5193 /* Calculate the size of the left-hand window, by dividing
5194 the usable space in columns by two.
5195 We round up, since the left-hand window may include
5196 a dividing line, while the right-hand may not. */
5197 size_int
= (XFASTINT (o
->total_cols
) + 1) >> 1;
5199 size_int
= XFASTINT (o
->total_lines
) >> 1;
5203 CHECK_NUMBER (size
);
5204 size_int
= XINT (size
);
5207 if (MINI_WINDOW_P (o
))
5208 error ("Attempt to split minibuffer window");
5209 else if (window_fixed_size_p (o
, !NILP (horizontal
), 0))
5210 error ("Attempt to split fixed-size window");
5212 if (NILP (horizontal
))
5214 int window_safe_height
= window_min_size_2 (o
, 0, 0);
5216 if (size_int
< window_safe_height
)
5217 error ("Window height %d too small (after splitting)", size_int
);
5218 if (size_int
+ window_safe_height
> XFASTINT (o
->total_lines
))
5219 error ("Window height %d too small (after splitting)",
5220 (int) (XFASTINT (o
->total_lines
) - size_int
));
5221 if (NILP (o
->parent
)
5222 || NILP (XWINDOW (o
->parent
)->vchild
))
5224 make_dummy_parent (window
);
5226 XWINDOW (new)->vchild
= window
;
5231 int window_safe_width
= window_min_size_2 (o
, 1, 0);
5233 if (size_int
< window_safe_width
)
5234 error ("Window width %d too small (after splitting)", size_int
);
5235 if (size_int
+ window_safe_width
> XFASTINT (o
->total_cols
))
5236 error ("Window width %d too small (after splitting)",
5237 (int) (XFASTINT (o
->total_cols
) - size_int
));
5238 if (NILP (o
->parent
)
5239 || NILP (XWINDOW (o
->parent
)->hchild
))
5241 make_dummy_parent (window
);
5243 XWINDOW (new)->hchild
= window
;
5247 /* Now we know that window's parent is a vertical combination
5248 if we are dividing vertically, or a horizontal combination
5249 if we are making side-by-side windows */
5251 windows_or_buffers_changed
++;
5252 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
5253 new = make_window ();
5256 p
->frame
= o
->frame
;
5258 if (!NILP (p
->next
))
5259 XWINDOW (p
->next
)->prev
= new;
5262 p
->parent
= o
->parent
;
5264 p
->window_end_valid
= Qnil
;
5265 memset (&p
->last_cursor
, 0, sizeof p
->last_cursor
);
5267 /* Duplicate special geometry settings. */
5269 p
->left_margin_cols
= o
->left_margin_cols
;
5270 p
->right_margin_cols
= o
->right_margin_cols
;
5271 p
->left_fringe_width
= o
->left_fringe_width
;
5272 p
->right_fringe_width
= o
->right_fringe_width
;
5273 p
->fringes_outside_margins
= o
->fringes_outside_margins
;
5274 p
->scroll_bar_width
= o
->scroll_bar_width
;
5275 p
->vertical_scroll_bar_type
= o
->vertical_scroll_bar_type
;
5277 /* Apportion the available frame space among the two new windows */
5279 if (!NILP (horizontal
))
5281 p
->total_lines
= o
->total_lines
;
5282 p
->top_line
= o
->top_line
;
5283 XSETFASTINT (p
->total_cols
, XFASTINT (o
->total_cols
) - size_int
);
5284 XSETFASTINT (o
->total_cols
, size_int
);
5285 XSETFASTINT (p
->left_col
, XFASTINT (o
->left_col
) + size_int
);
5286 adjust_window_margins (p
);
5287 adjust_window_margins (o
);
5291 p
->left_col
= o
->left_col
;
5292 p
->total_cols
= o
->total_cols
;
5293 XSETFASTINT (p
->total_lines
, XFASTINT (o
->total_lines
) - size_int
);
5294 XSETFASTINT (o
->total_lines
, size_int
);
5295 XSETFASTINT (p
->top_line
, XFASTINT (o
->top_line
) + size_int
);
5298 /* Adjust glyph matrices. */
5301 Fset_window_buffer (new, o
->buffer
, Qt
);
5305 DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal
, Sresize_mini_window_internal
, 1, 1, 0,
5306 doc
: /* Resize minibuffer window WINDOW. */)
5307 (Lisp_Object window
)
5309 struct window
*w
= XWINDOW (window
);
5314 CHECK_WINDOW (window
);
5315 f
= XFRAME (w
->frame
);
5317 if (!EQ (FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
)), window
))
5318 error ("Not a valid minibuffer window");
5319 else if (FRAME_MINIBUF_ONLY_P (f
))
5320 error ("Cannot resize a minibuffer-only frame");
5322 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5323 height
= XINT (r
->total_lines
) + XINT (w
->total_lines
);
5324 if (resize_window_check (r
, 0)
5325 && XINT (w
->new_total
) > 0
5326 && height
== XINT (r
->new_total
) + XINT (w
->new_total
))
5329 resize_window_apply (r
, 0);
5331 w
->total_lines
= w
->new_total
;
5332 XSETFASTINT (w
->top_line
, XINT (r
->top_line
) + XINT (r
->total_lines
));
5334 windows_or_buffers_changed
++;
5335 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
5339 run_window_configuration_change_hook (f
);
5342 else error ("Failed to resize minibuffer window");
5345 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
5346 doc
: /* Make selected window SIZE lines taller.
5347 Interactively, if no argument is given, make the selected window one
5348 line taller. If optional argument HORIZONTAL is non-nil, make selected
5349 window wider by SIZE columns. If SIZE is negative, shrink the window by
5350 -SIZE lines or columns. Return nil.
5352 This function can delete windows if they get too small. The size of
5353 fixed size windows is not altered by this function. */)
5354 (Lisp_Object size
, Lisp_Object horizontal
)
5356 CHECK_NUMBER (size
);
5357 enlarge_window (selected_window
, XINT (size
), !NILP (horizontal
));
5359 run_window_configuration_change_hook (SELECTED_FRAME ());
5364 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
5365 doc
: /* Make selected window SIZE lines smaller.
5366 Interactively, if no argument is given, make the selected window one
5367 line smaller. If optional argument HORIZONTAL is non-nil, make the
5368 window narrower by SIZE columns. If SIZE is negative, enlarge selected
5369 window by -SIZE lines or columns. Return nil.
5371 This function can delete windows if they get too small. The size of
5372 fixed size windows is not altered by this function. */)
5373 (Lisp_Object size
, Lisp_Object horizontal
)
5375 CHECK_NUMBER (size
);
5376 enlarge_window (selected_window
, -XINT (size
), !NILP (horizontal
));
5378 run_window_configuration_change_hook (SELECTED_FRAME ());
5384 window_height (Lisp_Object window
)
5386 register struct window
*p
= XWINDOW (window
);
5387 return WINDOW_TOTAL_LINES (p
);
5391 window_width (Lisp_Object window
)
5393 register struct window
*p
= XWINDOW (window
);
5394 return WINDOW_TOTAL_COLS (p
);
5399 *(horiz_flag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line))
5401 #define CURSIZE(w) \
5402 *(horiz_flag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines))
5405 /* Enlarge WINDOW by DELTA. HORIZ_FLAG nonzero means enlarge it
5406 horizontally; zero means do it vertically.
5408 Siblings of the selected window are resized to fulfill the size
5409 request. If they become too small in the process, they may be
5413 enlarge_window (Lisp_Object window
, int delta
, int horiz_flag
)
5415 Lisp_Object parent
, next
, prev
;
5419 int (*sizefun
) (Lisp_Object
)
5420 = horiz_flag
? window_width
: window_height
;
5421 void (*setsizefun
) (Lisp_Object
, int, int)
5422 = (horiz_flag
? set_window_width
: set_window_height
);
5424 /* Give up if this window cannot be resized. */
5425 if (window_fixed_size_p (XWINDOW (window
), horiz_flag
, 1))
5426 error ("Window is not resizable");
5428 /* Find the parent of the selected window. */
5431 p
= XWINDOW (window
);
5437 error ("No other window to side of this one");
5442 ? !NILP (XWINDOW (parent
)->hchild
)
5443 : !NILP (XWINDOW (parent
)->vchild
))
5449 sizep
= &CURSIZE (window
);
5452 register int maxdelta
;
5454 /* Compute the maximum size increment this window can have. */
5456 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - XINT (*sizep
)
5457 /* This is a main window followed by a minibuffer. */
5458 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
5459 - window_min_size (XWINDOW (p
->next
),
5460 horiz_flag
, 0, 0, 0))
5461 /* This is a minibuffer following a main window. */
5462 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
5463 - window_min_size (XWINDOW (p
->prev
),
5464 horiz_flag
, 0, 0, 0))
5465 /* This is a frame with only one window, a minibuffer-only
5466 or a minibufferless frame. */
5469 if (delta
> maxdelta
)
5470 /* This case traps trying to make the minibuffer
5471 the full frame, or make the only window aside from the
5472 minibuffer the full frame. */
5476 if (XINT (*sizep
) + delta
< window_min_size (XWINDOW (window
),
5477 horiz_flag
, 0, 0, 0))
5479 delete_window (window
);
5486 /* Find the total we can get from other siblings without deleting them. */
5488 for (next
= p
->next
; WINDOWP (next
); next
= XWINDOW (next
)->next
)
5489 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
5490 horiz_flag
, 0, 0, 0);
5491 for (prev
= p
->prev
; WINDOWP (prev
); prev
= XWINDOW (prev
)->prev
)
5492 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
5493 horiz_flag
, 0, 0, 0);
5495 /* If we can get it all from them without deleting them, do so. */
5496 if (delta
<= maximum
)
5498 Lisp_Object first_unaffected
;
5499 Lisp_Object first_affected
;
5504 first_affected
= window
;
5505 /* Look at one sibling at a time,
5506 moving away from this window in both directions alternately,
5507 and take as much as we can get without deleting that sibling. */
5509 && (!NILP (next
) || !NILP (prev
)))
5513 int this_one
= ((*sizefun
) (next
)
5514 - window_min_size (XWINDOW (next
), horiz_flag
,
5518 if (this_one
> delta
)
5521 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
5522 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
5527 next
= XWINDOW (next
)->next
;
5535 int this_one
= ((*sizefun
) (prev
)
5536 - window_min_size (XWINDOW (prev
), horiz_flag
,
5540 if (this_one
> delta
)
5543 first_affected
= prev
;
5545 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
5546 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
5551 prev
= XWINDOW (prev
)->prev
;
5555 xassert (delta
== 0);
5557 /* Now recalculate the edge positions of all the windows affected,
5558 based on the new sizes. */
5559 first_unaffected
= next
;
5560 prev
= first_affected
;
5561 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
5562 prev
= next
, next
= XWINDOW (next
)->next
)
5564 XSETINT (CURBEG (next
), XINT (CURBEG (prev
)) + (*sizefun
) (prev
));
5565 /* This does not change size of NEXT,
5566 but it propagates the new top edge to its children */
5567 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
5572 register int delta1
;
5573 register int opht
= (*sizefun
) (parent
);
5575 if (opht
<= XINT (*sizep
) + delta
)
5577 /* If trying to grow this window to or beyond size of the parent,
5578 just delete all the sibling windows. */
5579 Lisp_Object start
, tem
;
5581 start
= XWINDOW (parent
)->vchild
;
5583 start
= XWINDOW (parent
)->hchild
;
5585 /* Delete any siblings that come after WINDOW. */
5586 tem
= XWINDOW (window
)->next
;
5587 while (! NILP (tem
))
5589 Lisp_Object next1
= XWINDOW (tem
)->next
;
5590 delete_window (tem
);
5594 /* Delete any siblings that come after WINDOW.
5595 Note that if START is not WINDOW, then WINDOW still
5596 has siblings, so WINDOW has not yet replaced its parent. */
5598 while (! EQ (tem
, window
))
5600 Lisp_Object next1
= XWINDOW (tem
)->next
;
5601 delete_window (tem
);
5607 /* Otherwise, make delta1 just right so that if we add
5608 delta1 lines to this window and to the parent, and then
5609 shrink the parent back to its original size, the new
5610 proportional size of this window will increase by delta.
5612 The function size_window will compute the new height h'
5613 of the window from delta1 as:
5616 x = delta1 - delta1/n * n for the 1st resizable child
5619 where n is the number of children that can be resized.
5620 We can ignore x by choosing a delta1 that is a multiple of
5621 n. We want the height of this window to come out as
5631 The number of children n equals the number of resizable
5632 children of this window + 1 because we know window itself
5633 is resizable (otherwise we would have signaled an error).
5635 This reasoning is not correct when other windows become too
5636 small and shrink_windows refuses to delete them. Below we
5637 use resize_proportionally to work around this problem. */
5639 struct window
*w
= XWINDOW (window
);
5643 for (s
= w
->next
; WINDOWP (s
); s
= XWINDOW (s
)->next
)
5644 if (!window_fixed_size_p (XWINDOW (s
), horiz_flag
, 0))
5646 for (s
= w
->prev
; WINDOWP (s
); s
= XWINDOW (s
)->prev
)
5647 if (!window_fixed_size_p (XWINDOW (s
), horiz_flag
, 0))
5652 /* Add delta1 lines or columns to this window, and to the parent,
5653 keeping things consistent while not affecting siblings. */
5654 XSETINT (CURSIZE (parent
), opht
+ delta1
);
5655 (*setsizefun
) (window
, XINT (*sizep
) + delta1
, 0);
5657 /* Squeeze out delta1 lines or columns from our parent,
5658 shrinking this window and siblings proportionately. This
5659 brings parent back to correct size. Delta1 was calculated
5660 so this makes this window the desired size, taking it all
5661 out of the siblings.
5663 Temporarily set resize_proportionally to Qt to assure that,
5664 if necessary, shrink_windows deletes smaller windows rather
5665 than shrink this window. */
5666 w
->resize_proportionally
= Qt
;
5667 (*setsizefun
) (parent
, opht
, 0);
5668 w
->resize_proportionally
= Qnil
;
5672 XSETFASTINT (p
->last_modified
, 0);
5673 XSETFASTINT (p
->last_overlay_modified
, 0);
5675 /* Adjust glyph matrices. */
5676 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
5680 /* Adjust the size of WINDOW by DELTA, moving only its trailing edge.
5681 HORIZ_FLAG nonzero means adjust the width, moving the right edge.
5682 zero means adjust the height, moving the bottom edge.
5684 Following siblings of the selected window are resized to fulfill
5685 the size request. If they become too small in the process, they
5686 are not deleted; instead, we signal an error. */
5689 adjust_window_trailing_edge (Lisp_Object window
, int delta
, int horiz_flag
)
5691 Lisp_Object parent
, child
;
5693 Lisp_Object old_config
= Fcurrent_window_configuration (Qnil
);
5694 int delcount
= window_deletion_count
;
5696 CHECK_WINDOW (window
);
5698 /* Give up if this window cannot be resized. */
5699 if (window_fixed_size_p (XWINDOW (window
), horiz_flag
, 1))
5700 error ("Window is not resizable");
5704 Lisp_Object first_parallel
= Qnil
;
5708 /* This happens if WINDOW on the previous iteration was
5709 at top level of the window tree. */
5710 Fset_window_configuration (old_config
);
5711 error ("Specified window edge is fixed");
5714 p
= XWINDOW (window
);
5717 /* See if this level has windows in parallel in the specified
5718 direction. If so, set FIRST_PARALLEL to the first one. */
5721 if (! NILP (parent
) && !NILP (XWINDOW (parent
)->vchild
))
5722 first_parallel
= XWINDOW (parent
)->vchild
;
5723 else if (NILP (parent
) && !NILP (p
->next
))
5725 /* Handle the vertical chain of main window and minibuffer
5726 which has no parent. */
5727 first_parallel
= window
;
5728 while (! NILP (XWINDOW (first_parallel
)->prev
))
5729 first_parallel
= XWINDOW (first_parallel
)->prev
;
5734 if (! NILP (parent
) && !NILP (XWINDOW (parent
)->hchild
))
5735 first_parallel
= XWINDOW (parent
)->hchild
;
5738 /* If this level's succession is in the desired dimension,
5739 and this window is the last one, and there is no higher level,
5740 its trailing edge is fixed. */
5741 if (NILP (XWINDOW (window
)->next
) && NILP (first_parallel
)
5744 Fset_window_configuration (old_config
);
5745 error ("Specified window edge is fixed");
5748 /* Don't make this window too small. */
5749 if (XINT (CURSIZE (window
)) + delta
5750 < window_min_size_2 (XWINDOW (window
), horiz_flag
, 0))
5752 Fset_window_configuration (old_config
);
5753 error ("Cannot adjust window size as specified");
5756 /* Clear out some redisplay caches. */
5757 XSETFASTINT (p
->last_modified
, 0);
5758 XSETFASTINT (p
->last_overlay_modified
, 0);
5760 /* Adjust this window's edge. */
5761 XSETINT (CURSIZE (window
),
5762 XINT (CURSIZE (window
)) + delta
);
5764 /* If this window has following siblings in the desired dimension,
5765 make them smaller, and exit the loop.
5767 (If we reach the top of the tree and can never do this,
5768 we will fail and report an error, above.) */
5769 if (NILP (first_parallel
))
5771 if (!NILP (p
->next
))
5773 /* This may happen for the minibuffer. In that case
5774 the window_deletion_count check below does not work. */
5775 if (XINT (CURSIZE (p
->next
)) - delta
<= 0)
5777 Fset_window_configuration (old_config
);
5778 error ("Cannot adjust window size as specified");
5781 XSETINT (CURBEG (p
->next
),
5782 XINT (CURBEG (p
->next
)) + delta
);
5783 size_window (p
->next
, XINT (CURSIZE (p
->next
)) - delta
,
5784 horiz_flag
, 0, 1, 0);
5789 /* Here we have a chain of parallel siblings, in the other dimension.
5790 Change the size of the other siblings. */
5791 for (child
= first_parallel
;
5793 child
= XWINDOW (child
)->next
)
5794 if (! EQ (child
, window
))
5795 size_window (child
, XINT (CURSIZE (child
)) + delta
,
5796 horiz_flag
, 0, 0, 1);
5801 /* If we made a window so small it got deleted,
5802 we failed. Report failure. */
5803 if (delcount
!= window_deletion_count
)
5805 Fset_window_configuration (old_config
);
5806 error ("Cannot adjust window size as specified");
5809 /* Adjust glyph matrices. */
5810 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
5816 DEFUN ("adjust-window-trailing-edge", Fadjust_window_trailing_edge
,
5817 Sadjust_window_trailing_edge
, 3, 3, 0,
5818 doc
: /* Adjust the bottom or right edge of WINDOW by DELTA.
5819 If HORIZONTAL is non-nil, that means adjust the width, moving the right edge.
5820 Otherwise, adjust the height, moving the bottom edge.
5822 Following siblings of the selected window are resized to fulfill
5823 the size request. If they become too small in the process, they
5824 are not deleted; instead, we signal an error. */)
5825 (Lisp_Object window
, Lisp_Object delta
, Lisp_Object horizontal
)
5827 CHECK_NUMBER (delta
);
5829 window
= selected_window
;
5830 adjust_window_trailing_edge (window
, XINT (delta
), !NILP (horizontal
));
5832 run_window_configuration_change_hook
5833 (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
5840 /***********************************************************************
5841 Resizing Mini-Windows
5842 ***********************************************************************/
5844 static void shrink_window_lowest_first (struct window
*, int);
5846 enum save_restore_action
5853 static int save_restore_orig_size (struct window
*,
5854 enum save_restore_action
);
5856 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
5857 from lowest windows first. */
5860 shrink_window_lowest_first (struct window
*w
, int height
)
5866 xassert (!MINI_WINDOW_P (w
));
5868 /* Set redisplay hints. */
5869 XSETFASTINT (w
->last_modified
, 0);
5870 XSETFASTINT (w
->last_overlay_modified
, 0);
5871 windows_or_buffers_changed
++;
5872 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
5874 old_height
= XFASTINT (w
->total_lines
);
5875 XSETFASTINT (w
->total_lines
, height
);
5877 if (!NILP (w
->hchild
))
5879 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
5881 c
= XWINDOW (child
);
5882 c
->top_line
= w
->top_line
;
5883 shrink_window_lowest_first (c
, height
);
5886 else if (!NILP (w
->vchild
))
5888 Lisp_Object last_child
;
5889 int delta
= old_height
- height
;
5894 /* Find the last child. We are taking space from lowest windows
5895 first, so we iterate over children from the last child
5897 for (child
= w
->vchild
; WINDOWP (child
); child
= XWINDOW (child
)->next
)
5900 /* Size children down to their safe heights. */
5901 for (child
= last_child
; delta
&& !NILP (child
); child
= c
->prev
)
5905 c
= XWINDOW (child
);
5906 this_one
= XFASTINT (c
->total_lines
) - window_min_size_1 (c
, 0, 1);
5908 if (this_one
> delta
)
5911 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
) - this_one
);
5915 /* Compute new positions. */
5916 last_top
= XINT (w
->top_line
);
5917 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
5919 c
= XWINDOW (child
);
5920 c
->top_line
= make_number (last_top
);
5921 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
));
5922 last_top
+= XFASTINT (c
->total_lines
);
5928 /* Save, restore, or check positions and sizes in the window tree
5929 rooted at W. ACTION says what to do.
5931 If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and
5932 orig_total_lines members are valid for all windows in the window
5933 tree. Value is non-zero if they are valid.
5935 If ACTION is SAVE_ORIG_SIZES, save members top and height in
5936 orig_top_line and orig_total_lines for all windows in the tree.
5938 If ACTION is RESTORE_ORIG_SIZES, restore top and height from values
5939 stored in orig_top_line and orig_total_lines for all windows. */
5942 save_restore_orig_size (struct window
*w
, enum save_restore_action action
)
5948 if (!NILP (w
->hchild
))
5950 if (!save_restore_orig_size (XWINDOW (w
->hchild
), action
))
5953 else if (!NILP (w
->vchild
))
5955 if (!save_restore_orig_size (XWINDOW (w
->vchild
), action
))
5961 case CHECK_ORIG_SIZES
:
5962 if (!INTEGERP (w
->orig_top_line
) || !INTEGERP (w
->orig_total_lines
))
5966 case SAVE_ORIG_SIZES
:
5967 w
->orig_top_line
= w
->top_line
;
5968 w
->orig_total_lines
= w
->total_lines
;
5969 XSETFASTINT (w
->last_modified
, 0);
5970 XSETFASTINT (w
->last_overlay_modified
, 0);
5973 case RESTORE_ORIG_SIZES
:
5974 xassert (INTEGERP (w
->orig_top_line
) && INTEGERP (w
->orig_total_lines
));
5975 w
->top_line
= w
->orig_top_line
;
5976 w
->total_lines
= w
->orig_total_lines
;
5977 w
->orig_total_lines
= w
->orig_top_line
= Qnil
;
5978 XSETFASTINT (w
->last_modified
, 0);
5979 XSETFASTINT (w
->last_overlay_modified
, 0);
5986 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
5993 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
5994 without deleting other windows. */
5997 grow_mini_window (struct window
*w
, int delta
)
5999 struct frame
*f
= XFRAME (w
->frame
);
6000 struct window
*root
;
6002 xassert (MINI_WINDOW_P (w
));
6003 /* Commenting out the following assertion goes against the stated interface
6004 of the function, but it currently does not seem to do anything useful.
6005 See discussion of this issue in the thread for bug#4534.
6006 xassert (delta >= 0); */
6008 /* Compute how much we can enlarge the mini-window without deleting
6010 root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6013 int min_height
= window_min_size (root
, 0, 0, 0, 0);
6014 if (XFASTINT (root
->total_lines
) - delta
< min_height
)
6015 /* Note that the root window may already be smaller than
6017 delta
= max (0, XFASTINT (root
->total_lines
) - min_height
);
6022 /* Save original window sizes and positions, if not already done. */
6023 if (!save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
6024 save_restore_orig_size (root
, SAVE_ORIG_SIZES
);
6026 /* Shrink other windows. */
6027 shrink_window_lowest_first (root
, XFASTINT (root
->total_lines
) - delta
);
6029 /* Grow the mini-window. */
6030 w
->top_line
= make_number (XFASTINT (root
->top_line
) + XFASTINT (root
->total_lines
));
6031 w
->total_lines
= make_number (XFASTINT (w
->total_lines
) + delta
);
6032 XSETFASTINT (w
->last_modified
, 0);
6033 XSETFASTINT (w
->last_overlay_modified
, 0);
6040 /* Shrink mini-window W. If there is recorded info about window sizes
6041 before a call to grow_mini_window, restore recorded window sizes.
6042 Otherwise, if the mini-window is higher than 1 line, resize it to 1
6046 shrink_mini_window (struct window
*w
)
6048 struct frame
*f
= XFRAME (w
->frame
);
6049 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6051 if (save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
6053 save_restore_orig_size (root
, RESTORE_ORIG_SIZES
);
6055 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
6056 windows_or_buffers_changed
= 1;
6058 else if (XFASTINT (w
->total_lines
) > 1)
6060 /* Distribute the additional lines of the mini-window
6061 among the other windows. */
6063 XSETWINDOW (window
, w
);
6064 enlarge_window (window
, 1 - XFASTINT (w
->total_lines
), 0);
6070 /* Mark window cursors off for all windows in the window tree rooted
6071 at W by setting their phys_cursor_on_p flag to zero. Called from
6072 xterm.c, e.g. when a frame is cleared and thereby all cursors on
6073 the frame are cleared. */
6076 mark_window_cursors_off (struct window
*w
)
6080 if (!NILP (w
->hchild
))
6081 mark_window_cursors_off (XWINDOW (w
->hchild
));
6082 else if (!NILP (w
->vchild
))
6083 mark_window_cursors_off (XWINDOW (w
->vchild
));
6085 w
->phys_cursor_on_p
= 0;
6087 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6092 /* Return number of lines of text (not counting mode lines) in W. */
6095 window_internal_height (struct window
*w
)
6097 int ht
= XFASTINT (w
->total_lines
);
6099 if (!MINI_WINDOW_P (w
))
6101 if (!NILP (w
->parent
)
6102 || !NILP (w
->vchild
)
6103 || !NILP (w
->hchild
)
6106 || WINDOW_WANTS_MODELINE_P (w
))
6109 if (WINDOW_WANTS_HEADER_LINE_P (w
))
6116 /************************************************************************
6118 ***********************************************************************/
6120 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
6121 N screen-fulls, which is defined as the height of the window minus
6122 next_screen_context_lines. If WHOLE is zero, scroll up N lines
6123 instead. Negative values of N mean scroll down. NOERROR non-zero
6124 means don't signal an error if we try to move over BEGV or ZV,
6128 window_scroll (Lisp_Object window
, int n
, int whole
, int noerror
)
6132 /* If we must, use the pixel-based version which is much slower than
6133 the line-based one but can handle varying line heights. */
6134 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
6135 window_scroll_pixel_based (window
, n
, whole
, noerror
);
6137 window_scroll_line_based (window
, n
, whole
, noerror
);
6143 /* Implementation of window_scroll that works based on pixel line
6144 heights. See the comment of window_scroll for parameter
6148 window_scroll_pixel_based (Lisp_Object window
, int n
, int whole
, int noerror
)
6151 struct window
*w
= XWINDOW (window
);
6152 struct text_pos start
;
6153 int this_scroll_margin
;
6154 /* True if we fiddled the window vscroll field without really scrolling. */
6156 int x
, y
, rtop
, rbot
, rowh
, vpos
;
6158 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
6160 /* If PT is not visible in WINDOW, move back one half of
6161 the screen. Allow PT to be partially visible, otherwise
6162 something like (scroll-down 1) with PT in the line before
6163 the partially visible one would recenter. */
6165 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
6167 /* Move backward half the height of the window. Performance note:
6168 vmotion used here is about 10% faster, but would give wrong
6169 results for variable height lines. */
6170 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6171 it
.current_y
= it
.last_visible_y
;
6172 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
6174 /* The function move_iterator_vertically may move over more than
6175 the specified y-distance. If it->w is small, e.g. a
6176 mini-buffer window, we may end up in front of the window's
6177 display area. This is the case when Start displaying at the
6178 start of the line containing PT in this case. */
6179 if (it
.current_y
<= 0)
6181 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6182 move_it_vertically_backward (&it
, 0);
6186 start
= it
.current
.pos
;
6188 else if (auto_window_vscroll_p
)
6190 if (rtop
|| rbot
) /* partially visible */
6193 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
6195 dy
= max ((window_box_height (w
)
6196 - next_screen_context_lines
* dy
),
6202 /* Only vscroll backwards if already vscrolled forwards. */
6203 if (w
->vscroll
< 0 && rtop
> 0)
6205 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
6206 Fset_window_vscroll (window
, make_number (px
), Qt
);
6212 /* Do vscroll if already vscrolled or only display line. */
6213 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
6215 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
6216 Fset_window_vscroll (window
, make_number (px
), Qt
);
6220 /* Maybe modify window start instead of scrolling. */
6221 if (rbot
> 0 || w
->vscroll
< 0)
6225 Fset_window_vscroll (window
, make_number (0), Qt
);
6226 /* If there are other text lines above the current row,
6227 move window start to current row. Else to next row. */
6229 spos
= XINT (Fline_beginning_position (Qnil
));
6231 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
6232 set_marker_restricted (w
->start
, make_number (spos
),
6234 w
->start_at_line_beg
= Qt
;
6235 w
->update_mode_line
= Qt
;
6236 XSETFASTINT (w
->last_modified
, 0);
6237 XSETFASTINT (w
->last_overlay_modified
, 0);
6238 /* Set force_start so that redisplay_window will run the
6239 window-scroll-functions. */
6240 w
->force_start
= Qt
;
6245 /* Cancel previous vscroll. */
6246 Fset_window_vscroll (window
, make_number (0), Qt
);
6249 /* If scroll_preserve_screen_position is non-nil, we try to set
6250 point in the same window line as it is now, so get that line. */
6251 if (!NILP (Vscroll_preserve_screen_position
))
6253 /* We preserve the goal pixel coordinate across consecutive
6254 calls to scroll-up, scroll-down and other commands that
6255 have the `scroll-command' property. This avoids the
6256 possibility of point becoming "stuck" on a tall line when
6257 scrolling by one line. */
6258 if (window_scroll_pixel_based_preserve_y
< 0
6259 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
6260 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
6262 start_display (&it
, w
, start
);
6263 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
6264 window_scroll_pixel_based_preserve_y
= it
.current_y
;
6265 window_scroll_pixel_based_preserve_x
= it
.current_x
;
6269 window_scroll_pixel_based_preserve_y
6270 = window_scroll_pixel_based_preserve_x
= -1;
6272 /* Move iterator it from start the specified distance forward or
6273 backward. The result is the new window start. */
6274 start_display (&it
, w
, start
);
6277 EMACS_INT start_pos
= IT_CHARPOS (it
);
6278 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
6279 dy
= max ((window_box_height (w
)
6280 - next_screen_context_lines
* dy
),
6283 /* Note that move_it_vertically always moves the iterator to the
6284 start of a line. So, if the last line doesn't have a newline,
6285 we would end up at the start of the line ending at ZV. */
6288 move_it_vertically_backward (&it
, -dy
);
6289 /* Ensure we actually do move, e.g. in case we are currently
6290 looking at an image that is taller that the window height. */
6291 while (start_pos
== IT_CHARPOS (it
)
6292 && start_pos
> BEGV
)
6293 move_it_by_lines (&it
, -1);
6297 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
6298 MOVE_TO_POS
| MOVE_TO_Y
);
6299 /* Ensure we actually do move, e.g. in case we are currently
6300 looking at an image that is taller that the window height. */
6301 while (start_pos
== IT_CHARPOS (it
)
6303 move_it_by_lines (&it
, 1);
6307 move_it_by_lines (&it
, n
);
6309 /* We failed if we find ZV is already on the screen (scrolling up,
6310 means there's nothing past the end), or if we can't start any
6311 earlier (scrolling down, means there's nothing past the top). */
6312 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
6313 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
6315 if (IT_CHARPOS (it
) == ZV
)
6317 if (it
.current_y
< it
.last_visible_y
6318 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
6319 > it
.last_visible_y
))
6321 /* The last line was only partially visible, make it fully
6323 w
->vscroll
= (it
.last_visible_y
6324 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
6325 adjust_glyphs (it
.f
);
6329 else if (n
< 0) /* could happen with empty buffers */
6330 xsignal0 (Qbeginning_of_buffer
);
6332 xsignal0 (Qend_of_buffer
);
6336 if (w
->vscroll
!= 0)
6337 /* The first line was only partially visible, make it fully
6343 xsignal0 (Qbeginning_of_buffer
);
6346 /* If control gets here, then we vscrolled. */
6348 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
6350 /* Don't try to change the window start below. */
6356 EMACS_INT pos
= IT_CHARPOS (it
);
6359 /* If in the middle of a multi-glyph character move forward to
6360 the next character. */
6361 if (in_display_vector_p (&it
))
6364 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
6367 /* Set the window start, and set up the window for redisplay. */
6368 set_marker_restricted (w
->start
, make_number (pos
),
6370 bytepos
= XMARKER (w
->start
)->bytepos
;
6371 w
->start_at_line_beg
= ((pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n')
6373 w
->update_mode_line
= Qt
;
6374 XSETFASTINT (w
->last_modified
, 0);
6375 XSETFASTINT (w
->last_overlay_modified
, 0);
6376 /* Set force_start so that redisplay_window will run the
6377 window-scroll-functions. */
6378 w
->force_start
= Qt
;
6381 /* The rest of this function uses current_y in a nonstandard way,
6382 not including the height of the header line if any. */
6383 it
.current_y
= it
.vpos
= 0;
6385 /* Move PT out of scroll margins.
6386 This code wants current_y to be zero at the window start position
6387 even if there is a header line. */
6388 this_scroll_margin
= max (0, scroll_margin
);
6389 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->total_lines
) / 4);
6390 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
6394 /* We moved the window start towards ZV, so PT may be now
6395 in the scroll margin at the top. */
6396 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
6397 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
6398 && (NILP (Vscroll_preserve_screen_position
)
6399 || EQ (Vscroll_preserve_screen_position
, Qt
)))
6400 /* We found PT at a legitimate height. Leave it alone. */
6402 else if (window_scroll_pixel_based_preserve_y
>= 0)
6404 /* If we have a header line, take account of it.
6405 This is necessary because we set it.current_y to 0, above. */
6406 move_it_to (&it
, -1,
6407 window_scroll_pixel_based_preserve_x
,
6408 window_scroll_pixel_based_preserve_y
6409 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
6410 -1, MOVE_TO_Y
| MOVE_TO_X
);
6411 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
6415 while (it
.current_y
< this_scroll_margin
)
6417 int prev
= it
.current_y
;
6418 move_it_by_lines (&it
, 1);
6419 if (prev
== it
.current_y
)
6422 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
6427 EMACS_INT charpos
, bytepos
;
6430 /* Save our position, for the
6431 window_scroll_pixel_based_preserve_y case. */
6432 charpos
= IT_CHARPOS (it
);
6433 bytepos
= IT_BYTEPOS (it
);
6435 /* We moved the window start towards BEGV, so PT may be now
6436 in the scroll margin at the bottom. */
6437 move_it_to (&it
, PT
, -1,
6438 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
6439 - this_scroll_margin
- 1),
6441 MOVE_TO_POS
| MOVE_TO_Y
);
6443 /* Save our position, in case it's correct. */
6444 charpos
= IT_CHARPOS (it
);
6445 bytepos
= IT_BYTEPOS (it
);
6447 /* See if point is on a partially visible line at the end. */
6448 if (it
.what
== IT_EOB
)
6449 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
6452 move_it_by_lines (&it
, 1);
6453 partial_p
= it
.current_y
> it
.last_visible_y
;
6456 if (charpos
== PT
&& !partial_p
6457 && (NILP (Vscroll_preserve_screen_position
)
6458 || EQ (Vscroll_preserve_screen_position
, Qt
)))
6459 /* We found PT before we found the display margin, so PT is ok. */
6461 else if (window_scroll_pixel_based_preserve_y
>= 0)
6463 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
6464 start_display (&it
, w
, start
);
6465 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
6466 here because we called start_display again and did not
6467 alter it.current_y this time. */
6468 move_it_to (&it
, -1, window_scroll_pixel_based_preserve_x
,
6469 window_scroll_pixel_based_preserve_y
, -1,
6470 MOVE_TO_Y
| MOVE_TO_X
);
6471 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
6476 /* The last line was only partially visible, so back up two
6477 lines to make sure we're on a fully visible line. */
6479 move_it_by_lines (&it
, -2);
6480 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
6483 /* No, the position we saved is OK, so use it. */
6484 SET_PT_BOTH (charpos
, bytepos
);
6490 /* Implementation of window_scroll that works based on screen lines.
6491 See the comment of window_scroll for parameter descriptions. */
6494 window_scroll_line_based (Lisp_Object window
, int n
, int whole
, int noerror
)
6496 register struct window
*w
= XWINDOW (window
);
6497 /* Fvertical_motion enters redisplay, which can trigger
6498 fontification, which in turn can modify buffer text (e.g., if the
6499 fontification functions replace escape sequences with faces, as
6500 in `grep-mode-font-lock-keywords'). So we use a marker to record
6501 the old point position, to prevent crashes in SET_PT_BOTH. */
6502 Lisp_Object opoint_marker
= Fpoint_marker ();
6503 register EMACS_INT pos
, pos_byte
;
6504 register int ht
= window_internal_height (w
);
6505 register Lisp_Object tem
;
6509 Lisp_Object original_pos
= Qnil
;
6511 /* If scrolling screen-fulls, compute the number of lines to
6512 scroll from the window's height. */
6514 n
*= max (1, ht
- next_screen_context_lines
);
6516 startpos
= marker_position (w
->start
);
6518 if (!NILP (Vscroll_preserve_screen_position
))
6520 if (window_scroll_preserve_vpos
<= 0
6521 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
6522 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
6524 struct position posit
6525 = *compute_motion (startpos
, 0, 0, 0,
6527 -1, XINT (w
->hscroll
),
6529 window_scroll_preserve_vpos
= posit
.vpos
;
6530 window_scroll_preserve_hpos
= posit
.hpos
+ XINT (w
->hscroll
);
6533 original_pos
= Fcons (make_number (window_scroll_preserve_hpos
),
6534 make_number (window_scroll_preserve_vpos
));
6537 XSETFASTINT (tem
, PT
);
6538 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
6542 Fvertical_motion (make_number (- (ht
/ 2)), window
);
6547 lose
= n
< 0 && PT
== BEGV
;
6548 Fvertical_motion (make_number (n
), window
);
6552 SET_PT_BOTH (marker_position (opoint_marker
),
6553 marker_byte_position (opoint_marker
));
6560 xsignal0 (Qbeginning_of_buffer
);
6565 int this_scroll_margin
= scroll_margin
;
6567 /* Don't use a scroll margin that is negative or too large. */
6568 if (this_scroll_margin
< 0)
6569 this_scroll_margin
= 0;
6571 if (XINT (w
->total_lines
) < 4 * scroll_margin
)
6572 this_scroll_margin
= XINT (w
->total_lines
) / 4;
6574 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
6575 w
->start_at_line_beg
= bolp
;
6576 w
->update_mode_line
= Qt
;
6577 XSETFASTINT (w
->last_modified
, 0);
6578 XSETFASTINT (w
->last_overlay_modified
, 0);
6579 /* Set force_start so that redisplay_window will run
6580 the window-scroll-functions. */
6581 w
->force_start
= Qt
;
6583 if (!NILP (Vscroll_preserve_screen_position
)
6584 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
6586 SET_PT_BOTH (pos
, pos_byte
);
6587 Fvertical_motion (original_pos
, window
);
6589 /* If we scrolled forward, put point enough lines down
6590 that it is outside the scroll margin. */
6595 if (this_scroll_margin
> 0)
6597 SET_PT_BOTH (pos
, pos_byte
);
6598 Fvertical_motion (make_number (this_scroll_margin
), window
);
6604 if (top_margin
<= marker_position (opoint_marker
))
6605 SET_PT_BOTH (marker_position (opoint_marker
),
6606 marker_byte_position (opoint_marker
));
6607 else if (!NILP (Vscroll_preserve_screen_position
))
6609 SET_PT_BOTH (pos
, pos_byte
);
6610 Fvertical_motion (original_pos
, window
);
6613 SET_PT (top_margin
);
6619 /* If we scrolled backward, put point near the end of the window
6620 but not within the scroll margin. */
6621 SET_PT_BOTH (pos
, pos_byte
);
6622 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
6623 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
6626 bottom_margin
= PT
+ 1;
6628 if (bottom_margin
> marker_position (opoint_marker
))
6629 SET_PT_BOTH (marker_position (opoint_marker
),
6630 marker_byte_position (opoint_marker
));
6633 if (!NILP (Vscroll_preserve_screen_position
))
6635 SET_PT_BOTH (pos
, pos_byte
);
6636 Fvertical_motion (original_pos
, window
);
6639 Fvertical_motion (make_number (-1), window
);
6648 xsignal0 (Qend_of_buffer
);
6653 /* Scroll selected_window up or down. If N is nil, scroll a
6654 screen-full which is defined as the height of the window minus
6655 next_screen_context_lines. If N is the symbol `-', scroll.
6656 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
6657 up. This is the guts of Fscroll_up and Fscroll_down. */
6660 scroll_command (Lisp_Object n
, int direction
)
6662 int count
= SPECPDL_INDEX ();
6664 xassert (eabs (direction
) == 1);
6666 /* If selected window's buffer isn't current, make it current for
6667 the moment. But don't screw up if window_scroll gets an error. */
6668 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
6670 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
6671 Fset_buffer (XWINDOW (selected_window
)->buffer
);
6673 /* Make redisplay consider other windows than just selected_window. */
6674 ++windows_or_buffers_changed
;
6678 window_scroll (selected_window
, direction
, 1, 0);
6679 else if (EQ (n
, Qminus
))
6680 window_scroll (selected_window
, -direction
, 1, 0);
6683 n
= Fprefix_numeric_value (n
);
6684 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
6687 unbind_to (count
, Qnil
);
6690 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "^P",
6691 doc
: /* Scroll text of selected window upward ARG lines.
6692 If ARG is omitted or nil, scroll upward by a near full screen.
6693 A near full screen is `next-screen-context-lines' less than a full screen.
6694 Negative ARG means scroll downward.
6695 If ARG is the atom `-', scroll downward by nearly full screen.
6696 When calling from a program, supply as argument a number, nil, or `-'. */)
6699 scroll_command (arg
, 1);
6703 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "^P",
6704 doc
: /* Scroll text of selected window down ARG lines.
6705 If ARG is omitted or nil, scroll down by a near full screen.
6706 A near full screen is `next-screen-context-lines' less than a full screen.
6707 Negative ARG means scroll upward.
6708 If ARG is the atom `-', scroll upward by nearly full screen.
6709 When calling from a program, supply as argument a number, nil, or `-'. */)
6712 scroll_command (arg
, -1);
6716 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
6717 doc
: /* Return the other window for \"other window scroll\" commands.
6718 If `other-window-scroll-buffer' is non-nil, a window
6719 showing that buffer is used.
6720 If in the minibuffer, `minibuffer-scroll-window' if non-nil
6721 specifies the window. This takes precedence over
6722 `other-window-scroll-buffer'. */)
6727 if (MINI_WINDOW_P (XWINDOW (selected_window
))
6728 && !NILP (Vminibuf_scroll_window
))
6729 window
= Vminibuf_scroll_window
;
6730 /* If buffer is specified, scroll that buffer. */
6731 else if (!NILP (Vother_window_scroll_buffer
))
6733 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
6735 window
= display_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
6739 /* Nothing specified; look for a neighboring window on the same
6741 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
6743 if (EQ (window
, selected_window
))
6744 /* That didn't get us anywhere; look for a window on another
6747 window
= Fnext_window (window
, Qnil
, Qt
);
6748 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
6749 && ! EQ (window
, selected_window
));
6752 CHECK_LIVE_WINDOW (window
);
6754 if (EQ (window
, selected_window
))
6755 error ("There is no other window");
6760 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
6761 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
6762 A near full screen is `next-screen-context-lines' less than a full screen.
6763 The next window is the one below the current one; or the one at the top
6764 if the current one is at the bottom. Negative ARG means scroll downward.
6765 If ARG is the atom `-', scroll downward by nearly full screen.
6766 When calling from a program, supply as argument a number, nil, or `-'.
6768 If `other-window-scroll-buffer' is non-nil, scroll the window
6769 showing that buffer, popping the buffer up if necessary.
6770 If in the minibuffer, `minibuffer-scroll-window' if non-nil
6771 specifies the window to scroll. This takes precedence over
6772 `other-window-scroll-buffer'. */)
6777 int count
= SPECPDL_INDEX ();
6779 window
= Fother_window_for_scrolling ();
6780 w
= XWINDOW (window
);
6782 /* Don't screw up if window_scroll gets an error. */
6783 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
6784 ++windows_or_buffers_changed
;
6786 Fset_buffer (w
->buffer
);
6787 SET_PT (marker_position (w
->pointm
));
6790 window_scroll (window
, 1, 1, 1);
6791 else if (EQ (arg
, Qminus
))
6792 window_scroll (window
, -1, 1, 1);
6798 window_scroll (window
, XINT (arg
), 0, 1);
6801 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
6802 unbind_to (count
, Qnil
);
6807 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "^P\np",
6808 doc
: /* Scroll selected window display ARG columns left.
6809 Default for ARG is window width minus 2.
6810 Value is the total amount of leftward horizontal scrolling in
6811 effect after the change.
6812 If SET-MINIMUM is non-nil, the new scroll amount becomes the
6813 lower bound for automatic scrolling, i.e. automatic scrolling
6814 will not scroll a window to a column less than the value returned
6815 by this function. This happens in an interactive call. */)
6816 (register Lisp_Object arg
, Lisp_Object set_minimum
)
6820 struct window
*w
= XWINDOW (selected_window
);
6823 XSETFASTINT (arg
, window_body_cols (w
) - 2);
6825 arg
= Fprefix_numeric_value (arg
);
6827 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
6828 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
6830 if (!NILP (set_minimum
))
6831 w
->min_hscroll
= w
->hscroll
;
6836 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "^P\np",
6837 doc
: /* Scroll selected window display ARG columns right.
6838 Default for ARG is window width minus 2.
6839 Value is the total amount of leftward horizontal scrolling in
6840 effect after the change.
6841 If SET-MINIMUM is non-nil, the new scroll amount becomes the
6842 lower bound for automatic scrolling, i.e. automatic scrolling
6843 will not scroll a window to a column less than the value returned
6844 by this function. This happens in an interactive call. */)
6845 (register Lisp_Object arg
, Lisp_Object set_minimum
)
6849 struct window
*w
= XWINDOW (selected_window
);
6852 XSETFASTINT (arg
, window_body_cols (w
) - 2);
6854 arg
= Fprefix_numeric_value (arg
);
6856 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
6857 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
6859 if (!NILP (set_minimum
))
6860 w
->min_hscroll
= w
->hscroll
;
6865 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
6866 doc
: /* Return the window which was selected when entering the minibuffer.
6867 Returns nil, if selected window is not a minibuffer window. */)
6870 if (minibuf_level
> 0
6871 && MINI_WINDOW_P (XWINDOW (selected_window
))
6872 && WINDOW_LIVE_P (minibuf_selected_window
))
6873 return minibuf_selected_window
;
6878 /* Value is the number of lines actually displayed in window W,
6879 as opposed to its height. */
6882 displayed_window_lines (struct window
*w
)
6885 struct text_pos start
;
6886 int height
= window_box_height (w
);
6887 struct buffer
*old_buffer
;
6890 if (XBUFFER (w
->buffer
) != current_buffer
)
6892 old_buffer
= current_buffer
;
6893 set_buffer_internal (XBUFFER (w
->buffer
));
6898 /* In case W->start is out of the accessible range, do something
6899 reasonable. This happens in Info mode when Info-scroll-down
6900 calls (recenter -1) while W->start is 1. */
6901 if (XMARKER (w
->start
)->charpos
< BEGV
)
6902 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6903 else if (XMARKER (w
->start
)->charpos
> ZV
)
6904 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
6906 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
6908 start_display (&it
, w
, start
);
6909 move_it_vertically (&it
, height
);
6910 bottom_y
= line_bottom_y (&it
);
6912 /* rms: On a non-window display,
6913 the value of it.vpos at the bottom of the screen
6914 seems to be 1 larger than window_box_height (w).
6915 This kludge fixes a bug whereby (move-to-window-line -1)
6916 when ZV is on the last screen line
6917 moves to the previous screen line instead of the last one. */
6918 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
6921 /* Add in empty lines at the bottom of the window. */
6922 if (bottom_y
< height
)
6924 int uy
= FRAME_LINE_HEIGHT (it
.f
);
6925 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
6929 set_buffer_internal (old_buffer
);
6935 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
6936 doc
: /* Center point in selected window and maybe redisplay frame.
6937 With prefix argument ARG, recenter putting point on screen line ARG
6938 relative to the selected window. If ARG is negative, it counts up from the
6939 bottom of the window. (ARG should be less than the height of the window.)
6941 If ARG is omitted or nil, then recenter with point on the middle line of
6942 the selected window; if the variable `recenter-redisplay' is non-nil,
6943 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
6944 is set to `grow-only', this resets the tool-bar's height to the minimum
6945 height needed); if `recenter-redisplay' has the special value `tty',
6946 then only tty frame are redrawn.
6948 Just C-u as prefix means put point in the center of the window
6949 and redisplay normally--don't erase and redraw the frame. */)
6950 (register Lisp_Object arg
)
6952 struct window
*w
= XWINDOW (selected_window
);
6953 struct buffer
*buf
= XBUFFER (w
->buffer
);
6954 struct buffer
*obuf
= current_buffer
;
6956 EMACS_INT charpos
, bytepos
;
6957 int iarg
IF_LINT (= 0);
6958 int this_scroll_margin
;
6960 /* If redisplay is suppressed due to an error, try again. */
6961 obuf
->display_error_modiff
= 0;
6965 if (!NILP (Vrecenter_redisplay
)
6966 && (!EQ (Vrecenter_redisplay
, Qtty
)
6967 || !NILP (Ftty_type (selected_frame
))))
6971 /* Invalidate pixel data calculated for all compositions. */
6972 for (i
= 0; i
< n_compositions
; i
++)
6973 composition_table
[i
]->font
= NULL
;
6975 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
6977 Fredraw_frame (WINDOW_FRAME (w
));
6978 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
6983 else if (CONSP (arg
)) /* Just C-u. */
6987 arg
= Fprefix_numeric_value (arg
);
6992 set_buffer_internal (buf
);
6994 /* Do this after making BUF current
6995 in case scroll_margin is buffer-local. */
6996 this_scroll_margin
= max (0, scroll_margin
);
6997 this_scroll_margin
= min (this_scroll_margin
,
6998 XFASTINT (w
->total_lines
) / 4);
7000 /* Handle centering on a graphical frame specially. Such frames can
7001 have variable-height lines and centering point on the basis of
7002 line counts would lead to strange effects. */
7003 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
7010 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
7011 start_display (&it
, w
, pt
);
7012 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
7013 charpos
= IT_CHARPOS (it
);
7014 bytepos
= IT_BYTEPOS (it
);
7021 int extra_line_spacing
;
7022 int h
= window_box_height (w
);
7024 iarg
= - max (-iarg
, this_scroll_margin
);
7026 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
7027 start_display (&it
, w
, pt
);
7029 /* Be sure we have the exact height of the full line containing PT. */
7030 move_it_by_lines (&it
, 0);
7032 /* The amount of pixels we have to move back is the window
7033 height minus what's displayed in the line containing PT,
7034 and the lines below. */
7037 move_it_by_lines (&it
, nlines
);
7039 if (it
.vpos
== nlines
)
7043 /* Last line has no newline */
7044 h
-= line_bottom_y (&it
);
7048 /* Don't reserve space for extra line spacing of last line. */
7049 extra_line_spacing
= it
.max_extra_line_spacing
;
7051 /* If we can't move down NLINES lines because we hit
7052 the end of the buffer, count in some empty lines. */
7053 if (it
.vpos
< nlines
)
7056 extra_line_spacing
= it
.extra_line_spacing
;
7057 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
7062 /* Now find the new top line (starting position) of the window. */
7063 start_display (&it
, w
, pt
);
7065 move_it_vertically_backward (&it
, h
);
7067 /* If extra line spacing is present, we may move too far
7068 back. This causes the last line to be only partially
7069 visible (which triggers redisplay to recenter that line
7070 in the middle), so move forward.
7071 But ignore extra line spacing on last line, as it is not
7072 considered to be part of the visible height of the line.
7074 h
+= extra_line_spacing
;
7075 while (-it
.current_y
> h
)
7076 move_it_by_lines (&it
, 1);
7078 charpos
= IT_CHARPOS (it
);
7079 bytepos
= IT_BYTEPOS (it
);
7083 struct position pos
;
7085 iarg
= max (iarg
, this_scroll_margin
);
7087 pos
= *vmotion (PT
, -iarg
, w
);
7088 charpos
= pos
.bufpos
;
7089 bytepos
= pos
.bytepos
;
7094 struct position pos
;
7095 int ht
= window_internal_height (w
);
7102 /* Don't let it get into the margin at either top or bottom. */
7103 iarg
= max (iarg
, this_scroll_margin
);
7104 iarg
= min (iarg
, ht
- this_scroll_margin
- 1);
7106 pos
= *vmotion (PT
, - iarg
, w
);
7107 charpos
= pos
.bufpos
;
7108 bytepos
= pos
.bytepos
;
7111 /* Set the new window start. */
7112 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
7113 w
->window_end_valid
= Qnil
;
7115 w
->optional_new_start
= Qt
;
7117 if (bytepos
== BEGV_BYTE
|| FETCH_BYTE (bytepos
- 1) == '\n')
7118 w
->start_at_line_beg
= Qt
;
7120 w
->start_at_line_beg
= Qnil
;
7122 set_buffer_internal (obuf
);
7127 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
7129 doc
: /* Return the height in lines of the text display area of WINDOW.
7130 WINDOW defaults to the selected window.
7132 The return value does not include the mode line, any header line, nor
7133 any partial-height lines in the text display area. */)
7134 (Lisp_Object window
)
7136 struct window
*w
= decode_window (window
);
7137 int pixel_height
= window_box_height (w
);
7138 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
7139 return make_number (line_height
);
7144 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
7146 doc
: /* Position point relative to window.
7147 With no argument, position point at center of window.
7148 An argument specifies vertical position within the window;
7149 zero means top of window, negative means relative to bottom of window. */)
7152 struct window
*w
= XWINDOW (selected_window
);
7156 int this_scroll_margin
;
7159 if (!(BUFFERP (w
->buffer
)
7160 && XBUFFER (w
->buffer
) == current_buffer
))
7161 /* This test is needed to make sure PT/PT_BYTE make sense in w->buffer
7162 when passed below to set_marker_both. */
7163 error ("move-to-window-line called from unrelated buffer");
7165 window
= selected_window
;
7166 start
= marker_position (w
->start
);
7167 if (start
< BEGV
|| start
> ZV
)
7169 int height
= window_internal_height (w
);
7170 Fvertical_motion (make_number (- (height
/ 2)), window
);
7171 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
7172 w
->start_at_line_beg
= Fbolp ();
7173 w
->force_start
= Qt
;
7176 Fgoto_char (w
->start
);
7178 lines
= displayed_window_lines (w
);
7181 this_scroll_margin
= max (0, scroll_margin
);
7182 this_scroll_margin
= min (this_scroll_margin
, lines
/ 4);
7186 XSETFASTINT (arg
, lines
/ 2);
7189 int iarg
= XINT (Fprefix_numeric_value (arg
));
7192 iarg
= iarg
+ lines
;
7194 #if 0 /* This code would prevent move-to-window-line from moving point
7195 to a place inside the scroll margins (which would cause the
7196 next redisplay to scroll). I wrote this code, but then concluded
7197 it is probably better not to install it. However, it is here
7198 inside #if 0 so as not to lose it. -- rms. */
7200 /* Don't let it get into the margin at either top or bottom. */
7201 iarg
= max (iarg
, this_scroll_margin
);
7202 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
7205 arg
= make_number (iarg
);
7208 /* Skip past a partially visible first line. */
7210 XSETINT (arg
, XINT (arg
) + 1);
7212 return Fvertical_motion (arg
, window
);
7217 /***********************************************************************
7218 Window Configuration
7219 ***********************************************************************/
7221 struct save_window_data
7223 struct vectorlike_header header
;
7224 Lisp_Object selected_frame
;
7225 Lisp_Object current_window
;
7226 Lisp_Object current_buffer
;
7227 Lisp_Object minibuf_scroll_window
;
7228 Lisp_Object minibuf_selected_window
;
7229 Lisp_Object root_window
;
7230 Lisp_Object focus_frame
;
7231 /* A vector, each of whose elements is a struct saved_window
7233 Lisp_Object saved_windows
;
7235 /* All fields above are traced by the GC.
7236 From `fame-cols' down, the fields are ignored by the GC. */
7238 int frame_cols
, frame_lines
, frame_menu_bar_lines
;
7239 int frame_tool_bar_lines
;
7242 /* This is saved as a Lisp_Vector */
7245 struct vectorlike_header header
;
7247 Lisp_Object window
, clone_number
;
7248 Lisp_Object buffer
, start
, pointm
, mark
;
7249 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
7250 Lisp_Object normal_cols
, normal_lines
;
7251 Lisp_Object hscroll
, min_hscroll
;
7252 Lisp_Object parent
, prev
;
7253 Lisp_Object start_at_line_beg
;
7254 Lisp_Object display_table
;
7255 Lisp_Object orig_top_line
, orig_total_lines
;
7256 Lisp_Object left_margin_cols
, right_margin_cols
;
7257 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
7258 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
;
7259 Lisp_Object dedicated
, resize_proportionally
;
7260 Lisp_Object splits
, nest
, window_parameters
;
7263 #define SAVED_WINDOW_N(swv,n) \
7264 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
7266 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
7267 doc
: /* Return t if OBJECT is a window-configuration object. */)
7268 (Lisp_Object object
)
7270 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
7273 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
7274 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
7275 (Lisp_Object config
)
7277 register struct save_window_data
*data
;
7278 struct Lisp_Vector
*saved_windows
;
7280 CHECK_WINDOW_CONFIGURATION (config
);
7282 data
= (struct save_window_data
*) XVECTOR (config
);
7283 saved_windows
= XVECTOR (data
->saved_windows
);
7284 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
7287 DEFUN ("set-window-configuration", Fset_window_configuration
,
7288 Sset_window_configuration
, 1, 1, 0,
7289 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
7290 CONFIGURATION must be a value previously returned
7291 by `current-window-configuration' (which see).
7292 If CONFIGURATION was made from a frame that is now deleted,
7293 only frame-independent values can be restored. In this case,
7294 the return value is nil. Otherwise the value is t. */)
7295 (Lisp_Object configuration
)
7297 register struct save_window_data
*data
;
7298 struct Lisp_Vector
*saved_windows
;
7299 Lisp_Object new_current_buffer
;
7302 EMACS_INT old_point
= -1;
7304 CHECK_WINDOW_CONFIGURATION (configuration
);
7306 data
= (struct save_window_data
*) XVECTOR (configuration
);
7307 saved_windows
= XVECTOR (data
->saved_windows
);
7309 new_current_buffer
= data
->current_buffer
;
7310 if (NILP (BVAR (XBUFFER (new_current_buffer
), name
)))
7311 new_current_buffer
= Qnil
;
7314 if (XBUFFER (new_current_buffer
) == current_buffer
)
7315 /* The code further down "preserves point" by saving here PT in
7316 old_point and then setting it later back into PT. When the
7317 current-selected-window and the final-selected-window both show
7318 the current buffer, this suffers from the problem that the
7319 current PT is the window-point of the current-selected-window,
7320 while the final PT is the point of the final-selected-window, so
7321 this copy from one PT to the other would end up moving the
7322 window-point of the final-selected-window to the window-point of
7323 the current-selected-window. So we have to be careful which
7324 point of the current-buffer we copy into old_point. */
7325 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
7326 && WINDOWP (selected_window
)
7327 && EQ (XWINDOW (selected_window
)->buffer
, new_current_buffer
)
7328 && !EQ (selected_window
, data
->current_window
))
7329 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
7333 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
7334 point in new_current_buffer as of the last time this buffer was
7335 used. This can be non-deterministic since it can be changed by
7336 things like jit-lock by mere temporary selection of some random
7337 window that happens to show this buffer.
7338 So if possible we want this arbitrary choice of "which point" to
7339 be the one from the to-be-selected-window so as to prevent this
7340 window's cursor from being copied from another window. */
7341 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
7342 /* If current_window = selected_window, its point is in BUF_PT. */
7343 && !EQ (selected_window
, data
->current_window
))
7344 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
7346 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
7349 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
7352 /* If f is a dead frame, don't bother rebuilding its window tree.
7353 However, there is other stuff we should still try to do below. */
7354 if (FRAME_LIVE_P (f
))
7356 register struct window
*w
;
7357 register struct saved_window
*p
;
7358 struct window
*root_window
;
7359 struct window
**leaf_windows
;
7363 /* If the frame has been resized since this window configuration was
7364 made, we change the frame to the size specified in the
7365 configuration, restore the configuration, and then resize it
7366 back. We keep track of the prevailing height in these variables. */
7367 int previous_frame_lines
= FRAME_LINES (f
);
7368 int previous_frame_cols
= FRAME_COLS (f
);
7369 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
7370 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
7372 /* The mouse highlighting code could get screwed up
7373 if it runs during this. */
7376 if (data
->frame_lines
!= previous_frame_lines
7377 || data
->frame_cols
!= previous_frame_cols
)
7378 change_frame_size (f
, data
->frame_lines
,
7379 data
->frame_cols
, 0, 0, 0);
7380 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
7381 if (data
->frame_menu_bar_lines
7382 != previous_frame_menu_bar_lines
)
7383 x_set_menu_bar_lines (f
, make_number (data
->frame_menu_bar_lines
),
7385 #ifdef HAVE_WINDOW_SYSTEM
7386 if (data
->frame_tool_bar_lines
7387 != previous_frame_tool_bar_lines
)
7388 x_set_tool_bar_lines (f
, make_number (data
->frame_tool_bar_lines
),
7393 /* "Swap out" point from the selected window's buffer
7394 into the window itself. (Normally the pointm of the selected
7395 window holds garbage.) We do this now, before
7396 restoring the window contents, and prevent it from
7397 being done later on when we select a new window. */
7398 if (! NILP (XWINDOW (selected_window
)->buffer
))
7400 w
= XWINDOW (selected_window
);
7401 set_marker_both (w
->pointm
,
7403 BUF_PT (XBUFFER (w
->buffer
)),
7404 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
7407 windows_or_buffers_changed
++;
7408 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
7410 /* Problem: Freeing all matrices and later allocating them again
7411 is a serious redisplay flickering problem. What we would
7412 really like to do is to free only those matrices not reused
7414 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7416 = (struct window
**) alloca (count_windows (root_window
)
7417 * sizeof (struct window
*));
7418 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
7421 Mark all windows now on frame as "deleted".
7422 Restoring the new configuration "undeletes" any that are in it.
7424 Save their current buffers in their height fields, since we may
7425 need it later, if a buffer saved in the configuration is now
7427 delete_all_subwindows (FRAME_ROOT_WINDOW (f
));
7429 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
7431 p
= SAVED_WINDOW_N (saved_windows
, k
);
7432 w
= XWINDOW (p
->window
);
7435 if (!NILP (p
->parent
))
7436 w
->parent
= SAVED_WINDOW_N (saved_windows
,
7437 XFASTINT (p
->parent
))->window
;
7441 if (!NILP (p
->prev
))
7443 w
->prev
= SAVED_WINDOW_N (saved_windows
,
7444 XFASTINT (p
->prev
))->window
;
7445 XWINDOW (w
->prev
)->next
= p
->window
;
7450 if (!NILP (w
->parent
))
7452 if (EQ (p
->total_cols
, XWINDOW (w
->parent
)->total_cols
))
7454 XWINDOW (w
->parent
)->vchild
= p
->window
;
7455 XWINDOW (w
->parent
)->hchild
= Qnil
;
7459 XWINDOW (w
->parent
)->hchild
= p
->window
;
7460 XWINDOW (w
->parent
)->vchild
= Qnil
;
7465 w
->clone_number
= p
->clone_number
;
7466 /* If we squirreled away the buffer in the window's height,
7468 if (BUFFERP (w
->total_lines
))
7469 w
->buffer
= w
->total_lines
;
7470 w
->left_col
= p
->left_col
;
7471 w
->top_line
= p
->top_line
;
7472 w
->total_cols
= p
->total_cols
;
7473 w
->total_lines
= p
->total_lines
;
7474 w
->normal_cols
= p
->normal_cols
;
7475 w
->normal_lines
= p
->normal_lines
;
7476 w
->hscroll
= p
->hscroll
;
7477 w
->min_hscroll
= p
->min_hscroll
;
7478 w
->display_table
= p
->display_table
;
7479 w
->orig_top_line
= p
->orig_top_line
;
7480 w
->orig_total_lines
= p
->orig_total_lines
;
7481 w
->left_margin_cols
= p
->left_margin_cols
;
7482 w
->right_margin_cols
= p
->right_margin_cols
;
7483 w
->left_fringe_width
= p
->left_fringe_width
;
7484 w
->right_fringe_width
= p
->right_fringe_width
;
7485 w
->fringes_outside_margins
= p
->fringes_outside_margins
;
7486 w
->scroll_bar_width
= p
->scroll_bar_width
;
7487 w
->vertical_scroll_bar_type
= p
->vertical_scroll_bar_type
;
7488 w
->dedicated
= p
->dedicated
;
7489 w
->splits
= p
->splits
;
7491 w
->window_parameters
= p
->window_parameters
;
7492 w
->resize_proportionally
= p
->resize_proportionally
;
7493 XSETFASTINT (w
->last_modified
, 0);
7494 XSETFASTINT (w
->last_overlay_modified
, 0);
7496 /* Reinstall the saved buffer and pointers into it. */
7497 if (NILP (p
->buffer
))
7498 w
->buffer
= p
->buffer
;
7501 if (!NILP (BVAR (XBUFFER (p
->buffer
), name
)))
7502 /* If saved buffer is alive, install it. */
7504 w
->buffer
= p
->buffer
;
7505 w
->start_at_line_beg
= p
->start_at_line_beg
;
7506 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
7507 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
7508 Fset_marker (BVAR (XBUFFER (w
->buffer
), mark
),
7509 p
->mark
, w
->buffer
);
7511 /* As documented in Fcurrent_window_configuration, don't
7512 restore the location of point in the buffer which was
7513 current when the window configuration was recorded. */
7514 if (!EQ (p
->buffer
, new_current_buffer
)
7515 && XBUFFER (p
->buffer
) == current_buffer
)
7516 Fgoto_char (w
->pointm
);
7518 else if (NILP (w
->buffer
) || NILP (BVAR (XBUFFER (w
->buffer
), name
)))
7519 /* Else unless window has a live buffer, get one. */
7521 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
7522 /* This will set the markers to beginning of visible
7524 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
7525 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
7526 w
->start_at_line_beg
= Qt
;
7529 /* Keeping window's old buffer; make sure the markers
7532 /* Set window markers at start of visible range. */
7533 if (XMARKER (w
->start
)->buffer
== 0)
7534 set_marker_restricted (w
->start
, make_number (0),
7536 if (XMARKER (w
->pointm
)->buffer
== 0)
7537 set_marker_restricted_both (w
->pointm
, w
->buffer
,
7538 BUF_PT (XBUFFER (w
->buffer
)),
7539 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
7540 w
->start_at_line_beg
= Qt
;
7545 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
7547 /* Arrange *not* to restore point in the buffer that was
7548 current when the window configuration was saved. */
7549 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
7550 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
7551 make_number (old_point
),
7552 XWINDOW (data
->current_window
)->buffer
);
7554 /* In the following call to `select-window, prevent "swapping
7555 out point" in the old selected window using the buffer that
7556 has been restored into it. We already swapped out that point
7557 from that window's old buffer. */
7558 select_window (data
->current_window
, Qnil
, 1);
7559 BVAR (XBUFFER (XWINDOW (selected_window
)->buffer
), last_selected_window
)
7562 if (NILP (data
->focus_frame
)
7563 || (FRAMEP (data
->focus_frame
)
7564 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
7565 Fredirect_frame_focus (frame
, data
->focus_frame
);
7567 /* Set the screen height to the value it had before this function. */
7568 if (previous_frame_lines
!= FRAME_LINES (f
)
7569 || previous_frame_cols
!= FRAME_COLS (f
))
7570 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
7572 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
7573 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
7574 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
7576 #ifdef HAVE_WINDOW_SYSTEM
7577 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
7578 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
7583 /* Now, free glyph matrices in windows that were not reused. */
7584 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
7586 if (NILP (leaf_windows
[i
]->buffer
))
7588 /* Assert it's not reused as a combination. */
7589 xassert (NILP (leaf_windows
[i
]->hchild
)
7590 && NILP (leaf_windows
[i
]->vchild
));
7591 free_window_matrices (leaf_windows
[i
]);
7593 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
7601 /* Fselect_window will have made f the selected frame, so we
7602 reselect the proper frame here. Fhandle_switch_frame will change the
7603 selected window too, but that doesn't make the call to
7604 Fselect_window above totally superfluous; it still sets f's
7606 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
7607 do_switch_frame (data
->selected_frame
, 0, 0, Qnil
);
7609 run_window_configuration_change_hook (f
);
7612 if (!NILP (new_current_buffer
))
7613 Fset_buffer (new_current_buffer
);
7615 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
7616 minibuf_selected_window
= data
->minibuf_selected_window
;
7618 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
7621 /* Delete all subwindows reachable via the next, vchild, and hchild
7624 delete_all_subwindows (Lisp_Object window
)
7626 register struct window
*w
;
7628 w
= XWINDOW (window
);
7630 if (!NILP (w
->next
))
7631 /* Delete WINDOW's siblings (we traverse postorderly). */
7632 delete_all_subwindows (w
->next
);
7634 w
->total_lines
= w
->buffer
; /* See Fset_window_configuration for excuse. */
7636 if (!NILP (w
->vchild
))
7638 delete_all_subwindows (w
->vchild
);
7641 else if (!NILP (w
->hchild
))
7643 delete_all_subwindows (w
->hchild
);
7646 else if (!NILP (w
->buffer
))
7649 unchain_marker (XMARKER (w
->pointm
));
7650 unchain_marker (XMARKER (w
->start
));
7654 Vwindow_list
= Qnil
;
7658 count_windows (register struct window
*window
)
7660 register int count
= 1;
7661 if (!NILP (window
->next
))
7662 count
+= count_windows (XWINDOW (window
->next
));
7663 if (!NILP (window
->vchild
))
7664 count
+= count_windows (XWINDOW (window
->vchild
));
7665 if (!NILP (window
->hchild
))
7666 count
+= count_windows (XWINDOW (window
->hchild
));
7671 /* Fill vector FLAT with leaf windows under W, starting at index I.
7672 Value is last index + 1. */
7675 get_leaf_windows (struct window
*w
, struct window
**flat
, int i
)
7679 if (!NILP (w
->hchild
))
7680 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
7681 else if (!NILP (w
->vchild
))
7682 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
7686 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
7693 /* Return a pointer to the glyph W's physical cursor is on. Value is
7694 null if W's current matrix is invalid, so that no meaningfull glyph
7698 get_phys_cursor_glyph (struct window
*w
)
7700 struct glyph_row
*row
;
7701 struct glyph
*glyph
;
7703 if (w
->phys_cursor
.vpos
>= 0
7704 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
7705 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
7707 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
7708 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
7717 save_window_save (Lisp_Object window
, struct Lisp_Vector
*vector
, int i
)
7719 register struct saved_window
*p
;
7720 register struct window
*w
;
7721 register Lisp_Object tem
;
7723 for (;!NILP (window
); window
= w
->next
)
7725 p
= SAVED_WINDOW_N (vector
, i
);
7726 w
= XWINDOW (window
);
7728 XSETFASTINT (w
->temslot
, i
); i
++;
7730 p
->clone_number
= w
->clone_number
;
7731 p
->buffer
= w
->buffer
;
7732 p
->left_col
= w
->left_col
;
7733 p
->top_line
= w
->top_line
;
7734 p
->total_cols
= w
->total_cols
;
7735 p
->total_lines
= w
->total_lines
;
7736 p
->normal_cols
= w
->normal_cols
;
7737 p
->normal_lines
= w
->normal_lines
;
7738 p
->hscroll
= w
->hscroll
;
7739 p
->min_hscroll
= w
->min_hscroll
;
7740 p
->display_table
= w
->display_table
;
7741 p
->orig_top_line
= w
->orig_top_line
;
7742 p
->orig_total_lines
= w
->orig_total_lines
;
7743 p
->left_margin_cols
= w
->left_margin_cols
;
7744 p
->right_margin_cols
= w
->right_margin_cols
;
7745 p
->left_fringe_width
= w
->left_fringe_width
;
7746 p
->right_fringe_width
= w
->right_fringe_width
;
7747 p
->fringes_outside_margins
= w
->fringes_outside_margins
;
7748 p
->scroll_bar_width
= w
->scroll_bar_width
;
7749 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
7750 p
->dedicated
= w
->dedicated
;
7751 p
->splits
= w
->splits
;
7753 p
->resize_proportionally
= w
->resize_proportionally
;
7754 p
->window_parameters
= w
->window_parameters
;
7755 if (!NILP (w
->buffer
))
7757 /* Save w's value of point in the window configuration.
7758 If w is the selected window, then get the value of point
7759 from the buffer; pointm is garbage in the selected window. */
7760 if (EQ (window
, selected_window
))
7762 p
->pointm
= Fmake_marker ();
7763 set_marker_both (p
->pointm
, w
->buffer
,
7764 BUF_PT (XBUFFER (w
->buffer
)),
7765 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
7768 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
7770 p
->start
= Fcopy_marker (w
->start
, Qnil
);
7771 p
->start_at_line_beg
= w
->start_at_line_beg
;
7773 tem
= BVAR (XBUFFER (w
->buffer
), mark
);
7774 p
->mark
= Fcopy_marker (tem
, Qnil
);
7781 p
->start_at_line_beg
= Qnil
;
7784 if (NILP (w
->parent
))
7787 p
->parent
= XWINDOW (w
->parent
)->temslot
;
7792 p
->prev
= XWINDOW (w
->prev
)->temslot
;
7794 if (!NILP (w
->vchild
))
7795 i
= save_window_save (w
->vchild
, vector
, i
);
7796 if (!NILP (w
->hchild
))
7797 i
= save_window_save (w
->hchild
, vector
, i
);
7803 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
7804 Scurrent_window_configuration
, 0, 1, 0,
7805 doc
: /* Return an object representing the current window configuration of FRAME.
7806 If FRAME is nil or omitted, use the selected frame.
7807 This describes the number of windows, their sizes and current buffers,
7808 and for each displayed buffer, where display starts, and the positions of
7809 point and mark. An exception is made for point in the current buffer:
7810 its value is -not- saved.
7811 This also records the currently selected frame, and FRAME's focus
7812 redirection (see `redirect-frame-focus'). */)
7815 register Lisp_Object tem
;
7816 register int n_windows
;
7817 register struct save_window_data
*data
;
7822 frame
= selected_frame
;
7823 CHECK_LIVE_FRAME (frame
);
7826 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
7827 data
= ALLOCATE_PSEUDOVECTOR (struct save_window_data
, frame_cols
,
7828 PVEC_WINDOW_CONFIGURATION
);
7830 data
->frame_cols
= FRAME_COLS (f
);
7831 data
->frame_lines
= FRAME_LINES (f
);
7832 data
->frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
7833 data
->frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
7834 data
->selected_frame
= selected_frame
;
7835 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
7836 XSETBUFFER (data
->current_buffer
, current_buffer
);
7837 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
7838 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
7839 data
->root_window
= FRAME_ROOT_WINDOW (f
);
7840 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
7841 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
7842 data
->saved_windows
= tem
;
7843 for (i
= 0; i
< n_windows
; i
++)
7844 XVECTOR (tem
)->contents
[i
]
7845 = Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
);
7846 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
7847 XSETWINDOW_CONFIGURATION (tem
, data
);
7852 /***********************************************************************
7854 ***********************************************************************/
7857 window_tree (struct window
*w
)
7859 Lisp_Object tail
= Qnil
;
7860 Lisp_Object result
= Qnil
;
7867 if (!NILP (w
->hchild
))
7868 wn
= Fcons (Qnil
, Fcons (Fwindow_edges (wn
),
7869 window_tree (XWINDOW (w
->hchild
))));
7870 else if (!NILP (w
->vchild
))
7871 wn
= Fcons (Qt
, Fcons (Fwindow_edges (wn
),
7872 window_tree (XWINDOW (w
->vchild
))));
7876 result
= tail
= Fcons (wn
, Qnil
);
7880 XSETCDR (tail
, Fcons (wn
, Qnil
));
7884 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
7892 DEFUN ("window-tree", Fwindow_tree
, Swindow_tree
,
7894 doc
: /* Return the window tree for frame FRAME.
7896 The return value is a list of the form (ROOT MINI), where ROOT
7897 represents the window tree of the frame's root window, and MINI
7898 is the frame's minibuffer window.
7900 If the root window is not split, ROOT is the root window itself.
7901 Otherwise, ROOT is a list (DIR EDGES W1 W2 ...) where DIR is nil for a
7902 horizontal split, and t for a vertical split, EDGES gives the combined
7903 size and position of the subwindows in the split, and the rest of the
7904 elements are the subwindows in the split. Each of the subwindows may
7905 again be a window or a list representing a window split, and so on.
7906 EDGES is a list \(LEFT TOP RIGHT BOTTOM) as returned by `window-edges'.
7908 If FRAME is nil or omitted, return information on the currently
7915 frame
= selected_frame
;
7917 CHECK_FRAME (frame
);
7920 if (!FRAME_LIVE_P (f
))
7923 return window_tree (XWINDOW (FRAME_ROOT_WINDOW (f
)));
7927 /***********************************************************************
7929 ***********************************************************************/
7931 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
7933 doc
: /* Set width of marginal areas of window WINDOW.
7934 If WINDOW is nil, set margins of the currently selected window.
7935 Second arg LEFT-WIDTH specifies the number of character cells to
7936 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
7937 does the same for the right marginal area. A nil width parameter
7938 means no margin. */)
7939 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
)
7941 struct window
*w
= decode_window (window
);
7943 /* Translate negative or zero widths to nil.
7944 Margins that are too wide have to be checked elsewhere. */
7946 if (!NILP (left_width
))
7948 CHECK_NUMBER (left_width
);
7949 if (XINT (left_width
) <= 0)
7953 if (!NILP (right_width
))
7955 CHECK_NUMBER (right_width
);
7956 if (XINT (right_width
) <= 0)
7960 if (!EQ (w
->left_margin_cols
, left_width
)
7961 || !EQ (w
->right_margin_cols
, right_width
))
7963 w
->left_margin_cols
= left_width
;
7964 w
->right_margin_cols
= right_width
;
7966 adjust_window_margins (w
);
7968 ++windows_or_buffers_changed
;
7969 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
7976 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
7978 doc
: /* Get width of marginal areas of window WINDOW.
7979 If WINDOW is omitted or nil, use the currently selected window.
7980 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
7981 If a marginal area does not exist, its width will be returned
7983 (Lisp_Object window
)
7985 struct window
*w
= decode_window (window
);
7986 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
7991 /***********************************************************************
7993 ***********************************************************************/
7995 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
7997 doc
: /* Set the fringe widths of window WINDOW.
7998 If WINDOW is nil, set the fringe widths of the currently selected
8000 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
8001 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
8002 fringe width. If a fringe width arg is nil, that means to use the
8003 frame's default fringe width. Default fringe widths can be set with
8004 the command `set-fringe-style'.
8005 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
8006 outside of the display margins. By default, fringes are drawn between
8007 display marginal areas and the text area. */)
8008 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
, Lisp_Object outside_margins
)
8010 struct window
*w
= decode_window (window
);
8012 if (!NILP (left_width
))
8013 CHECK_NATNUM (left_width
);
8014 if (!NILP (right_width
))
8015 CHECK_NATNUM (right_width
);
8017 /* Do nothing on a tty. */
8018 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
8019 && (!EQ (w
->left_fringe_width
, left_width
)
8020 || !EQ (w
->right_fringe_width
, right_width
)
8021 || !EQ (w
->fringes_outside_margins
, outside_margins
)))
8023 w
->left_fringe_width
= left_width
;
8024 w
->right_fringe_width
= right_width
;
8025 w
->fringes_outside_margins
= outside_margins
;
8027 adjust_window_margins (w
);
8029 clear_glyph_matrix (w
->current_matrix
);
8030 w
->window_end_valid
= Qnil
;
8032 ++windows_or_buffers_changed
;
8033 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
8040 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
8042 doc
: /* Get width of fringes of window WINDOW.
8043 If WINDOW is omitted or nil, use the currently selected window.
8044 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
8045 (Lisp_Object window
)
8047 struct window
*w
= decode_window (window
);
8049 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
8050 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
8051 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
8052 ? Qt
: Qnil
), Qnil
)));
8057 /***********************************************************************
8059 ***********************************************************************/
8061 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
,
8062 Sset_window_scroll_bars
, 2, 4, 0,
8063 doc
: /* Set width and type of scroll bars of window WINDOW.
8064 If window is nil, set scroll bars of the currently selected window.
8065 Second parameter WIDTH specifies the pixel width for the scroll bar;
8066 this is automatically adjusted to a multiple of the frame column width.
8067 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
8068 bar: left, right, or nil.
8069 If WIDTH is nil, use the frame's scroll-bar width.
8070 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
8071 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
8072 (Lisp_Object window
, Lisp_Object width
, Lisp_Object vertical_type
, Lisp_Object horizontal_type
)
8074 struct window
*w
= decode_window (window
);
8078 CHECK_NATNUM (width
);
8080 if (XINT (width
) == 0)
8081 vertical_type
= Qnil
;
8084 if (!(NILP (vertical_type
)
8085 || EQ (vertical_type
, Qleft
)
8086 || EQ (vertical_type
, Qright
)
8087 || EQ (vertical_type
, Qt
)))
8088 error ("Invalid type of vertical scroll bar");
8090 if (!EQ (w
->scroll_bar_width
, width
)
8091 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
8093 w
->scroll_bar_width
= width
;
8094 w
->vertical_scroll_bar_type
= vertical_type
;
8096 adjust_window_margins (w
);
8098 clear_glyph_matrix (w
->current_matrix
);
8099 w
->window_end_valid
= Qnil
;
8101 ++windows_or_buffers_changed
;
8102 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
8109 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
8111 doc
: /* Get width and type of scroll bars of window WINDOW.
8112 If WINDOW is omitted or nil, use the currently selected window.
8113 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
8114 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
8116 (Lisp_Object window
)
8118 struct window
*w
= decode_window (window
);
8119 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
8120 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
8121 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
8122 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
8123 Fcons (w
->vertical_scroll_bar_type
,
8124 Fcons (Qnil
, Qnil
))));
8129 /***********************************************************************
8131 ***********************************************************************/
8133 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
8134 doc
: /* Return the amount by which WINDOW is scrolled vertically.
8135 Use the selected window if WINDOW is nil or omitted.
8136 Normally, value is a multiple of the canonical character height of WINDOW;
8137 optional second arg PIXELS-P means value is measured in pixels. */)
8138 (Lisp_Object window
, Lisp_Object pixels_p
)
8145 window
= selected_window
;
8147 CHECK_WINDOW (window
);
8148 w
= XWINDOW (window
);
8149 f
= XFRAME (w
->frame
);
8151 if (FRAME_WINDOW_P (f
))
8152 result
= (NILP (pixels_p
)
8153 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
8154 : make_number (-w
->vscroll
));
8156 result
= make_number (0);
8161 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
8163 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
8164 WINDOW nil means use the selected window. Normally, VSCROLL is a
8165 non-negative multiple of the canonical character height of WINDOW;
8166 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
8167 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
8168 corresponds to an integral number of pixels. The return value is the
8169 result of this rounding.
8170 If PIXELS-P is non-nil, the return value is VSCROLL. */)
8171 (Lisp_Object window
, Lisp_Object vscroll
, Lisp_Object pixels_p
)
8177 window
= selected_window
;
8179 CHECK_WINDOW (window
);
8180 CHECK_NUMBER_OR_FLOAT (vscroll
);
8182 w
= XWINDOW (window
);
8183 f
= XFRAME (w
->frame
);
8185 if (FRAME_WINDOW_P (f
))
8187 int old_dy
= w
->vscroll
;
8189 w
->vscroll
= - (NILP (pixels_p
)
8190 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
8191 : XFLOATINT (vscroll
));
8192 w
->vscroll
= min (w
->vscroll
, 0);
8194 if (w
->vscroll
!= old_dy
)
8196 /* Adjust glyph matrix of the frame if the virtual display
8197 area becomes larger than before. */
8198 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
8201 /* Prevent redisplay shortcuts. */
8202 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8206 return Fwindow_vscroll (window
, pixels_p
);
8210 /* Call FN for all leaf windows on frame F. FN is called with the
8211 first argument being a pointer to the leaf window, and with
8212 additional argument USER_DATA. Stops when FN returns 0. */
8215 foreach_window (struct frame
*f
, int (*fn
) (struct window
*, void *),
8218 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
8219 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
8220 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
8224 /* Helper function for foreach_window. Call FN for all leaf windows
8225 reachable from W. FN is called with the first argument being a
8226 pointer to the leaf window, and with additional argument USER_DATA.
8227 Stop when FN returns 0. Value is 0 if stopped by FN. */
8230 foreach_window_1 (struct window
*w
, int (*fn
) (struct window
*, void *), void *user_data
)
8234 for (cont
= 1; w
&& cont
;)
8236 if (!NILP (w
->hchild
))
8237 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
8238 else if (!NILP (w
->vchild
))
8239 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
8241 cont
= fn (w
, user_data
);
8243 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
8250 /* Freeze or unfreeze the window start of W unless it is a
8251 mini-window or the selected window. FREEZE_P non-null means freeze
8252 the window start. */
8255 freeze_window_start (struct window
*w
, void *freeze_p
)
8257 if (MINI_WINDOW_P (w
)
8258 || (WINDOWP (selected_window
) /* Can be nil in corner cases. */
8259 && (w
== XWINDOW (selected_window
)
8260 || (MINI_WINDOW_P (XWINDOW (selected_window
))
8261 && ! NILP (Vminibuf_scroll_window
)
8262 && w
== XWINDOW (Vminibuf_scroll_window
)))))
8265 w
->frozen_window_start_p
= freeze_p
!= NULL
;
8270 /* Freeze or unfreeze the window starts of all leaf windows on frame
8271 F, except the selected window and a mini-window. FREEZE_P non-zero
8272 means freeze the window start. */
8275 freeze_window_starts (struct frame
*f
, int freeze_p
)
8277 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
8281 /***********************************************************************
8283 ***********************************************************************/
8285 /* Return 1 if window configurations C1 and C2
8286 describe the same state of affairs. This is used by Fequal. */
8289 compare_window_configurations (Lisp_Object c1
, Lisp_Object c2
, int ignore_positions
)
8291 register struct save_window_data
*d1
, *d2
;
8292 struct Lisp_Vector
*sw1
, *sw2
;
8295 CHECK_WINDOW_CONFIGURATION (c1
);
8296 CHECK_WINDOW_CONFIGURATION (c2
);
8298 d1
= (struct save_window_data
*) XVECTOR (c1
);
8299 d2
= (struct save_window_data
*) XVECTOR (c2
);
8300 sw1
= XVECTOR (d1
->saved_windows
);
8301 sw2
= XVECTOR (d2
->saved_windows
);
8303 if (d1
->frame_cols
!= d2
->frame_cols
)
8305 if (d1
->frame_lines
!= d2
->frame_lines
)
8307 if (d1
->frame_menu_bar_lines
!= d2
->frame_menu_bar_lines
)
8309 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
8311 /* Don't compare the current_window field directly.
8312 Instead see w1_is_current and w2_is_current, below. */
8313 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
8315 if (! ignore_positions
)
8317 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
8319 if (! EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
))
8322 /* Don't compare the root_window field.
8323 We don't require the two configurations
8324 to use the same window object,
8325 and the two root windows must be equivalent
8326 if everything else compares equal. */
8327 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
8330 /* Verify that the two confis have the same number of windows. */
8331 if (sw1
->header
.size
!= sw2
->header
.size
)
8334 for (i
= 0; i
< sw1
->header
.size
; i
++)
8336 struct saved_window
*p1
, *p2
;
8337 int w1_is_current
, w2_is_current
;
8339 p1
= SAVED_WINDOW_N (sw1
, i
);
8340 p2
= SAVED_WINDOW_N (sw2
, i
);
8342 /* Verify that the current windows in the two
8343 configurations correspond to each other. */
8344 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
8345 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
8347 if (w1_is_current
!= w2_is_current
)
8350 /* Verify that the corresponding windows do match. */
8351 if (! EQ (p1
->buffer
, p2
->buffer
))
8353 if (! EQ (p1
->left_col
, p2
->left_col
))
8355 if (! EQ (p1
->top_line
, p2
->top_line
))
8357 if (! EQ (p1
->total_cols
, p2
->total_cols
))
8359 if (! EQ (p1
->total_lines
, p2
->total_lines
))
8361 if (! EQ (p1
->display_table
, p2
->display_table
))
8363 if (! EQ (p1
->parent
, p2
->parent
))
8365 if (! EQ (p1
->prev
, p2
->prev
))
8367 if (! ignore_positions
)
8369 if (! EQ (p1
->hscroll
, p2
->hscroll
))
8371 if (!EQ (p1
->min_hscroll
, p2
->min_hscroll
))
8373 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
8375 if (NILP (Fequal (p1
->start
, p2
->start
)))
8377 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
8379 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
8382 if (! EQ (p1
->left_margin_cols
, p2
->left_margin_cols
))
8384 if (! EQ (p1
->right_margin_cols
, p2
->right_margin_cols
))
8386 if (! EQ (p1
->left_fringe_width
, p2
->left_fringe_width
))
8388 if (! EQ (p1
->right_fringe_width
, p2
->right_fringe_width
))
8390 if (! EQ (p1
->fringes_outside_margins
, p2
->fringes_outside_margins
))
8392 if (! EQ (p1
->scroll_bar_width
, p2
->scroll_bar_width
))
8394 if (! EQ (p1
->vertical_scroll_bar_type
, p2
->vertical_scroll_bar_type
))
8401 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
8402 Scompare_window_configurations
, 2, 2, 0,
8403 doc
: /* Compare two window configurations as regards the structure of windows.
8404 This function ignores details such as the values of point and mark
8405 and scrolling positions. */)
8406 (Lisp_Object x
, Lisp_Object y
)
8408 if (compare_window_configurations (x
, y
, 1))
8414 init_window_once (void)
8416 struct frame
*f
= make_initial_frame ();
8417 XSETFRAME (selected_frame
, f
);
8418 Vterminal_frame
= selected_frame
;
8419 minibuf_window
= f
->minibuffer_window
;
8420 selected_window
= f
->selected_window
;
8421 last_nonminibuf_frame
= f
;
8423 window_initialized
= 1;
8429 Vwindow_list
= Qnil
;
8433 syms_of_window (void)
8435 Qscroll_up
= intern_c_string ("scroll-up");
8436 staticpro (&Qscroll_up
);
8438 Qscroll_down
= intern_c_string ("scroll-down");
8439 staticpro (&Qscroll_down
);
8441 Qscroll_command
= intern_c_string ("scroll-command");
8442 staticpro (&Qscroll_command
);
8444 Fput (Qscroll_up
, Qscroll_command
, Qt
);
8445 Fput (Qscroll_down
, Qscroll_command
, Qt
);
8447 Qwindow_size_fixed
= intern_c_string ("window-size-fixed");
8448 staticpro (&Qwindow_size_fixed
);
8449 Fset (Qwindow_size_fixed
, Qnil
);
8451 staticpro (&Qwindow_configuration_change_hook
);
8452 Qwindow_configuration_change_hook
8453 = intern_c_string ("window-configuration-change-hook");
8455 Qwindowp
= intern_c_string ("windowp");
8456 staticpro (&Qwindowp
);
8458 Qwindow_configuration_p
= intern_c_string ("window-configuration-p");
8459 staticpro (&Qwindow_configuration_p
);
8461 Qwindow_live_p
= intern_c_string ("window-live-p");
8462 staticpro (&Qwindow_live_p
);
8464 Qwindow_deletable_p
= intern_c_string ("window-deletable-p");
8465 staticpro (&Qwindow_deletable_p
);
8467 Qdelete_window
= intern_c_string ("delete-window");
8468 staticpro (&Qdelete_window
);
8470 Qresize_root_window
= intern_c_string ("resize-root-window");
8471 staticpro (&Qresize_root_window
);
8473 Qresize_root_window_vertically
= intern_c_string ("resize-root-window-vertically");
8474 staticpro (&Qresize_root_window_vertically
);
8476 Qsafe
= intern_c_string ("safe");
8479 Qdisplay_buffer
= intern_c_string ("display-buffer");
8480 staticpro (&Qdisplay_buffer
);
8482 Qreplace_buffer_in_windows
= intern_c_string ("replace-buffer-in-windows");
8483 staticpro (&Qreplace_buffer_in_windows
);
8485 Qrecord_window_buffer
= intern_c_string ("record-window-buffer");
8486 staticpro (&Qrecord_window_buffer
);
8488 Qget_mru_window
= intern_c_string ("get-mru-window");
8489 staticpro (&Qget_mru_window
);
8491 Qtemp_buffer_show_hook
= intern_c_string ("temp-buffer-show-hook");
8492 staticpro (&Qtemp_buffer_show_hook
);
8494 Qabove
= intern_c_string ("above");
8495 staticpro (&Qabove
);
8497 Qbelow
= intern_c_string ("below");
8498 staticpro (&Qbelow
);
8500 Qauto_buffer_name
= intern_c_string ("auto-buffer-name");
8501 staticpro (&Qauto_buffer_name
);
8503 staticpro (&Vwindow_list
);
8505 minibuf_selected_window
= Qnil
;
8506 staticpro (&minibuf_selected_window
);
8508 window_scroll_pixel_based_preserve_x
= -1;
8509 window_scroll_pixel_based_preserve_y
= -1;
8510 window_scroll_preserve_hpos
= -1;
8511 window_scroll_preserve_vpos
= -1;
8513 DEFVAR_LISP ("temp-buffer-show-function", Vtemp_buffer_show_function
,
8514 doc
: /* Non-nil means call as function to display a help buffer.
8515 The function is called with one argument, the buffer to be displayed.
8516 Used by `with-output-to-temp-buffer'.
8517 If this function is used, then it must do the entire job of showing
8518 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
8519 Vtemp_buffer_show_function
= Qnil
;
8521 DEFVAR_LISP ("minibuffer-scroll-window", Vminibuf_scroll_window
,
8522 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
8523 Vminibuf_scroll_window
= Qnil
;
8525 DEFVAR_BOOL ("mode-line-in-non-selected-windows", mode_line_in_non_selected_windows
,
8526 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
8527 If the minibuffer is active, the `minibuffer-scroll-window' mode line
8528 is displayed in the `mode-line' face. */);
8529 mode_line_in_non_selected_windows
= 1;
8531 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer
,
8532 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
8533 Vother_window_scroll_buffer
= Qnil
;
8535 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p
,
8536 doc
: /* *Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
8537 auto_window_vscroll_p
= 1;
8539 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines
,
8540 doc
: /* *Number of lines of continuity when scrolling by screenfuls. */);
8541 next_screen_context_lines
= 2;
8543 DEFVAR_INT ("window-min-height", window_min_height
,
8544 doc
: /* Allow deleting windows less than this tall.
8545 The value is measured in line units. If a window wants a modeline it
8546 is counted as one line.
8548 Emacs honors settings of this variable when enlarging or shrinking
8549 windows vertically. A value less than 1 is invalid. */);
8550 window_min_height
= 4;
8552 DEFVAR_INT ("window-min-width", window_min_width
,
8553 doc
: /* Allow deleting windows less than this wide.
8554 The value is measured in characters and includes any fringes or
8557 Emacs honors settings of this variable when enlarging or shrinking
8558 windows horizontally. A value less than 2 is invalid. */);
8559 window_min_width
= 10;
8561 DEFVAR_LISP ("scroll-preserve-screen-position",
8562 Vscroll_preserve_screen_position
,
8563 doc
: /* *Controls if scroll commands move point to keep its screen position unchanged.
8564 A value of nil means point does not keep its screen position except
8565 at the scroll margin or window boundary respectively.
8566 A value of t means point keeps its screen position if the scroll
8567 command moved it vertically out of the window, e.g. when scrolling
8569 Any other value means point always keeps its screen position.
8570 Scroll commands should have the `scroll-command' property
8571 on their symbols to be controlled by this variable. */);
8572 Vscroll_preserve_screen_position
= Qnil
;
8574 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type
,
8575 doc
: /* Type of marker to use for `window-point'. */);
8576 Vwindow_point_insertion_type
= Qnil
;
8578 DEFVAR_LISP ("window-configuration-change-hook",
8579 Vwindow_configuration_change_hook
,
8580 doc
: /* Functions to call when window configuration changes.
8581 The buffer-local part is run once per window, with the relevant window
8582 selected; while the global part is run only once for the modified frame,
8583 with the relevant frame selected. */);
8584 Vwindow_configuration_change_hook
= Qnil
;
8586 DEFVAR_LISP ("recenter-redisplay", Vrecenter_redisplay
,
8587 doc
: /* If non-nil, then the `recenter' command with a nil argument
8588 will redraw the entire frame; the special value `tty' causes the
8589 frame to be redrawn only if it is a tty frame. */);
8590 Vrecenter_redisplay
= Qtty
;
8592 DEFVAR_LISP ("window-splits", Vwindow_splits
,
8593 doc
: /* Non-nil means splitting windows is handled specially.
8594 If this variable is nil, splitting a window gets the entire screen space
8595 for displaying the new window from the window to split. If this
8596 variable is non-nil, splitting a window may resize all windows in the
8597 same combination. This also allows to split a window that is otherwise
8598 too small or of fixed size.
8600 The value of this variable is also assigned to the split status of the
8601 new window and, provided the old and new window form a new combination,
8602 to the window that was split as well. The split status of a window can
8603 be retrieved with the function `window-splits' and altered by the
8604 function `set-window-splits'.
8606 If the value of the variable `window-nest' is non-nil, the space for the
8607 new window is exclusively taken from the window that shall be split, but
8608 the split status of the window that is split as well as that of the new
8609 window are still set to the value of this variable. */);
8610 Vwindow_splits
= Qnil
;
8612 DEFVAR_LISP ("window-nest", Vwindow_nest
,
8613 doc
: /* Non-nil means splitting a window makes a new parent window.
8614 If this variable is nil, splitting a window will create a new parent
8615 window only if the window has no parent window or the window shall
8616 become a combination orthogonal to the one it it is part of.
8618 If this variable is non-nil, splitting a window always creates a new
8619 parent window. If all splits behave this way, each frame's window tree
8620 is a binary tree and every window but the frame's root window has
8621 exactly one sibling.
8623 The value of this variable is also assigned to the nest status of the
8624 new parent window. The nest status of a window can be retrieved via the
8625 function `window-nest' and altered by the function `set-window-nest'. */);
8626 Vwindow_nest
= Qnil
;
8628 defsubr (&Sselected_window
);
8629 defsubr (&Sminibuffer_window
);
8630 defsubr (&Swindow_minibuffer_p
);
8631 defsubr (&Swindowp
);
8632 defsubr (&Swindow_live_p
);
8633 defsubr (&Swindow_frame
);
8634 defsubr (&Sframe_root_window
);
8635 defsubr (&Sframe_first_window
);
8636 defsubr (&Sframe_selected_window
);
8637 defsubr (&Sset_frame_selected_window
);
8638 defsubr (&Spos_visible_in_window_p
);
8639 defsubr (&Swindow_line_height
);
8640 defsubr (&Swindow_clone_number
);
8641 defsubr (&Swindow_buffer
);
8642 defsubr (&Swindow_parent
);
8643 defsubr (&Swindow_vchild
);
8644 defsubr (&Swindow_hchild
);
8645 defsubr (&Swindow_next
);
8646 defsubr (&Swindow_prev
);
8647 defsubr (&Swindow_splits
);
8648 defsubr (&Sset_window_splits
);
8649 defsubr (&Swindow_nest
);
8650 defsubr (&Sset_window_nest
);
8651 defsubr (&Swindow_use_time
);
8652 defsubr (&Swindow_top_line
);
8653 defsubr (&Swindow_left_column
);
8654 defsubr (&Swindow_total_size
);
8655 defsubr (&Swindow_normal_size
);
8656 defsubr (&Swindow_new_total
);
8657 defsubr (&Swindow_new_normal
);
8658 defsubr (&Sset_window_new_total
);
8659 defsubr (&Sset_window_new_normal
);
8660 defsubr (&Sresize_window_apply
);
8661 defsubr (&Swindow_body_size
);
8662 defsubr (&Swindow_hscroll
);
8663 defsubr (&Sset_window_hscroll
);
8664 defsubr (&Swindow_redisplay_end_trigger
);
8665 defsubr (&Sset_window_redisplay_end_trigger
);
8666 defsubr (&Swindow_edges
);
8667 defsubr (&Swindow_pixel_edges
);
8668 defsubr (&Swindow_absolute_pixel_edges
);
8669 defsubr (&Swindow_inside_edges
);
8670 defsubr (&Swindow_inside_pixel_edges
);
8671 defsubr (&Swindow_inside_absolute_pixel_edges
);
8672 defsubr (&Scoordinates_in_window_p
);
8673 defsubr (&Swindow_at
);
8674 defsubr (&Swindow_point
);
8675 defsubr (&Swindow_start
);
8676 defsubr (&Swindow_end
);
8677 defsubr (&Sset_window_point
);
8678 defsubr (&Sset_window_start
);
8679 defsubr (&Swindow_dedicated_p
);
8680 defsubr (&Sset_window_dedicated_p
);
8681 defsubr (&Swindow_display_table
);
8682 defsubr (&Sset_window_display_table
);
8683 defsubr (&Snext_window
);
8684 defsubr (&Sprevious_window
);
8685 defsubr (&Sother_window
);
8686 defsubr (&Sget_buffer_window
);
8687 defsubr (&Sdelete_other_windows
);
8688 defsubr (&Sdelete_windows_on
);
8689 defsubr (&Sreplace_buffer_in_windows
);
8690 defsubr (&Sdelete_window
);
8691 defsubr (&Sdelete_other_windows_internal
);
8692 defsubr (&Sdelete_window_internal
);
8693 defsubr (&Sresize_mini_window_internal
);
8694 defsubr (&Sset_window_buffer
);
8695 defsubr (&Sset_window_clone_number
);
8696 defsubr (&Srun_window_configuration_change_hook
);
8697 defsubr (&Sselect_window
);
8698 defsubr (&Sforce_window_update
);
8699 defsubr (&Stemp_output_buffer_show
);
8700 defsubr (&Ssplit_window
);
8701 defsubr (&Ssplit_window_internal
);
8702 defsubr (&Senlarge_window
);
8703 defsubr (&Sshrink_window
);
8704 defsubr (&Sadjust_window_trailing_edge
);
8705 defsubr (&Sscroll_up
);
8706 defsubr (&Sscroll_down
);
8707 defsubr (&Sscroll_left
);
8708 defsubr (&Sscroll_right
);
8709 defsubr (&Sother_window_for_scrolling
);
8710 defsubr (&Sscroll_other_window
);
8711 defsubr (&Sminibuffer_selected_window
);
8712 defsubr (&Srecenter
);
8713 defsubr (&Swindow_text_height
);
8714 defsubr (&Smove_to_window_line
);
8715 defsubr (&Swindow_configuration_p
);
8716 defsubr (&Swindow_configuration_frame
);
8717 defsubr (&Sset_window_configuration
);
8718 defsubr (&Scurrent_window_configuration
);
8719 defsubr (&Swindow_tree
);
8720 defsubr (&Sset_window_margins
);
8721 defsubr (&Swindow_margins
);
8722 defsubr (&Sset_window_fringes
);
8723 defsubr (&Swindow_fringes
);
8724 defsubr (&Sset_window_scroll_bars
);
8725 defsubr (&Swindow_scroll_bars
);
8726 defsubr (&Swindow_vscroll
);
8727 defsubr (&Sset_window_vscroll
);
8728 defsubr (&Scompare_window_configurations
);
8729 defsubr (&Swindow_list
);
8730 defsubr (&Swindow_list_1
);
8731 defsubr (&Swindow_prev_buffers
);
8732 defsubr (&Sset_window_prev_buffers
);
8733 defsubr (&Swindow_next_buffers
);
8734 defsubr (&Sset_window_next_buffers
);
8735 defsubr (&Swindow_parameters
);
8736 defsubr (&Swindow_parameter
);
8737 defsubr (&Sset_window_parameter
);
8741 keys_of_window (void)
8743 initial_define_key (control_x_map
, '1', "delete-other-windows");
8744 initial_define_key (control_x_map
, '2', "split-window");
8745 initial_define_key (control_x_map
, '0', "delete-window");
8746 initial_define_key (control_x_map
, 'o', "other-window");
8747 initial_define_key (control_x_map
, '^', "enlarge-window");
8748 initial_define_key (control_x_map
, '<', "scroll-left");
8749 initial_define_key (control_x_map
, '>', "scroll-right");
8751 initial_define_key (global_map
, Ctl ('V'), "scroll-up-command");
8752 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
8753 initial_define_key (meta_map
, 'v', "scroll-down-command");