1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985-1987, 1993-1998, 2000-2013 Free Software
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/>. */
23 #define WINDOW_INLINE EXTERN_INLINE
28 #include "character.h"
38 #include "dispextern.h"
39 #include "blockinput.h"
40 #include "intervals.h"
41 #include "termhooks.h" /* For FRAME_TERMINAL. */
45 #endif /* HAVE_X_WINDOWS */
58 Lisp_Object Qwindowp
, Qwindow_live_p
, Qwindow_valid_p
;
59 static Lisp_Object Qwindow_configuration_p
, Qrecord_window_buffer
;
60 static Lisp_Object Qwindow_deletable_p
, Qdelete_window
, Qdisplay_buffer
;
61 static Lisp_Object Qreplace_buffer_in_windows
, Qget_mru_window
;
62 static Lisp_Object Qwindow_resize_root_window
, Qwindow_resize_root_window_vertically
;
63 static Lisp_Object Qscroll_up
, Qscroll_down
, Qscroll_command
;
64 static Lisp_Object Qsafe
, Qabove
, Qbelow
, Qwindow_size
, Qclone_of
;
66 static int displayed_window_lines (struct window
*);
67 static int count_windows (struct window
*);
68 static int get_leaf_windows (struct window
*, struct window
**, int);
69 static void window_scroll (Lisp_Object
, EMACS_INT
, int, int);
70 static void window_scroll_pixel_based (Lisp_Object
, int, int, int);
71 static void window_scroll_line_based (Lisp_Object
, int, int, int);
72 static int freeze_window_start (struct window
*, void *);
73 static Lisp_Object
window_list (void);
74 static int add_window_to_list (struct window
*, void *);
75 static int candidate_window_p (Lisp_Object
, Lisp_Object
, Lisp_Object
,
77 static Lisp_Object
next_window (Lisp_Object
, Lisp_Object
,
79 static void decode_next_window_args (Lisp_Object
*, Lisp_Object
*,
81 static void foreach_window (struct frame
*,
82 int (* fn
) (struct window
*, void *),
84 static int foreach_window_1 (struct window
*,
85 int (* fn
) (struct window
*, void *),
87 static Lisp_Object
window_list_1 (Lisp_Object
, Lisp_Object
, Lisp_Object
);
88 static int window_resize_check (struct window
*, bool);
89 static void window_resize_apply (struct window
*, bool);
90 static Lisp_Object
select_window (Lisp_Object
, Lisp_Object
, int);
91 static void select_window_1 (Lisp_Object
, bool);
93 /* This is the window in which the terminal's cursor should
94 be left when nothing is being done with it. This must
95 always be a leaf window, and its buffer is selected by
96 the top level editing loop at the end of each command.
98 This value is always the same as
99 FRAME_SELECTED_WINDOW (selected_frame). */
100 Lisp_Object selected_window
;
102 /* A list of all windows for use by next_window and Fwindow_list.
103 Functions creating or deleting windows should invalidate this cache
104 by setting it to nil. */
105 Lisp_Object Vwindow_list
;
107 /* The mini-buffer window of the selected frame.
108 Note that you cannot test for mini-bufferness of an arbitrary window
109 by comparing against this; but you can test for mini-bufferness of
110 the selected window. */
111 Lisp_Object minibuf_window
;
113 /* Non-nil means it is the window whose mode line should be
114 shown as the selected window when the minibuffer is selected. */
115 Lisp_Object minibuf_selected_window
;
117 /* Hook run at end of temp_output_buffer_show. */
118 static Lisp_Object Qtemp_buffer_show_hook
;
120 /* Nonzero after init_window_once has finished. */
121 static int window_initialized
;
123 /* Hook to run when window config changes. */
124 static Lisp_Object Qwindow_configuration_change_hook
;
126 /* Used by the function window_scroll_pixel_based */
127 static int window_scroll_pixel_based_preserve_x
;
128 static int window_scroll_pixel_based_preserve_y
;
130 /* Same for window_scroll_line_based. */
131 static EMACS_INT window_scroll_preserve_hpos
;
132 static EMACS_INT window_scroll_preserve_vpos
;
134 /* These setters are used only in this file, so they can be private. */
136 wset_combination_limit (struct window
*w
, Lisp_Object val
)
138 w
->combination_limit
= val
;
141 wset_dedicated (struct window
*w
, Lisp_Object val
)
146 wset_display_table (struct window
*w
, Lisp_Object val
)
148 w
->display_table
= val
;
151 wset_hchild (struct window
*w
, Lisp_Object val
)
156 wset_left_fringe_width (struct window
*w
, Lisp_Object val
)
158 w
->left_fringe_width
= val
;
161 wset_left_margin_cols (struct window
*w
, Lisp_Object val
)
163 w
->left_margin_cols
= val
;
166 wset_new_normal (struct window
*w
, Lisp_Object val
)
171 wset_new_total (struct window
*w
, Lisp_Object val
)
176 wset_normal_cols (struct window
*w
, Lisp_Object val
)
178 w
->normal_cols
= val
;
181 wset_normal_lines (struct window
*w
, Lisp_Object val
)
183 w
->normal_lines
= val
;
186 wset_parent (struct window
*w
, Lisp_Object val
)
191 wset_pointm (struct window
*w
, Lisp_Object val
)
196 wset_right_fringe_width (struct window
*w
, Lisp_Object val
)
198 w
->right_fringe_width
= val
;
201 wset_right_margin_cols (struct window
*w
, Lisp_Object val
)
203 w
->right_margin_cols
= val
;
206 wset_scroll_bar_width (struct window
*w
, Lisp_Object val
)
208 w
->scroll_bar_width
= val
;
211 wset_start (struct window
*w
, Lisp_Object val
)
216 wset_temslot (struct window
*w
, Lisp_Object val
)
221 wset_vchild (struct window
*w
, Lisp_Object val
)
226 wset_vertical_scroll_bar_type (struct window
*w
, Lisp_Object val
)
228 w
->vertical_scroll_bar_type
= val
;
231 wset_window_parameters (struct window
*w
, Lisp_Object val
)
233 w
->window_parameters
= val
;
237 decode_live_window (register Lisp_Object window
)
240 return XWINDOW (selected_window
);
242 CHECK_LIVE_WINDOW (window
);
243 return XWINDOW (window
);
247 decode_any_window (register Lisp_Object window
)
252 return XWINDOW (selected_window
);
254 CHECK_WINDOW (window
);
255 w
= XWINDOW (window
);
259 static struct window
*
260 decode_valid_window (register Lisp_Object window
)
265 return XWINDOW (selected_window
);
267 CHECK_VALID_WINDOW (window
);
268 w
= XWINDOW (window
);
272 /* Called when W's buffer slot is changed. ARG -1 means that W is about to
273 cease its buffer, and 1 means that W is about to set up the new one. */
276 adjust_window_count (struct window
*w
, int arg
)
278 eassert (eabs (arg
) == 1);
279 if (BUFFERP (w
->buffer
))
281 struct buffer
*b
= XBUFFER (w
->buffer
);
285 b
->window_count
+= arg
;
286 eassert (b
->window_count
>= 0);
287 /* These should be recalculated by redisplay code. */
288 w
->window_end_valid
= 0;
289 w
->base_line_pos
= 0;
293 /* Set W's buffer slot to VAL and recompute number
294 of windows showing VAL if it is a buffer. */
297 wset_buffer (struct window
*w
, Lisp_Object val
)
299 adjust_window_count (w
, -1);
301 adjust_window_count (w
, 1);
304 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
305 doc
: /* Return t if OBJECT is a window and nil otherwise. */)
308 return WINDOWP (object
) ? Qt
: Qnil
;
311 DEFUN ("window-valid-p", Fwindow_valid_p
, Swindow_valid_p
, 1, 1, 0,
312 doc
: /* Return t if OBJECT is a valid window and nil otherwise.
313 A valid window is either a window that displays a buffer or an internal
314 window. Deleted windows are not live. */)
317 return WINDOW_VALID_P (object
) ? Qt
: Qnil
;
320 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
321 doc
: /* Return t if OBJECT is a live window and nil otherwise.
322 A live window is a window that displays a buffer.
323 Internal windows and deleted windows are not live. */)
326 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
329 /* Frames and windows. */
330 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 0, 1, 0,
331 doc
: /* Return the frame that window WINDOW is on.
332 WINDOW must be a valid window and defaults to the selected one. */)
335 return decode_valid_window (window
)->frame
;
338 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
339 doc
: /* Return the root window of FRAME-OR-WINDOW.
340 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
341 With a frame argument, return that frame's root window.
342 With a window argument, return the root window of that window's frame. */)
343 (Lisp_Object frame_or_window
)
347 if (NILP (frame_or_window
))
348 window
= SELECTED_FRAME ()->root_window
;
349 else if (WINDOW_VALID_P (frame_or_window
))
350 window
= XFRAME (XWINDOW (frame_or_window
)->frame
)->root_window
;
353 CHECK_LIVE_FRAME (frame_or_window
);
354 window
= XFRAME (frame_or_window
)->root_window
;
360 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
361 doc
: /* Return the minibuffer window for frame FRAME.
362 If FRAME is omitted or nil, it defaults to the selected frame. */)
365 return FRAME_MINIBUF_WINDOW (decode_live_frame (frame
));
368 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
,
369 Swindow_minibuffer_p
, 0, 1, 0,
370 doc
: /* Return non-nil if WINDOW is a minibuffer window.
371 WINDOW must be a valid window and defaults to the selected one. */)
374 return MINI_WINDOW_P (decode_valid_window (window
)) ? Qt
: Qnil
;
377 /* Don't move this to window.el - this must be a safe routine. */
378 DEFUN ("frame-first-window", Fframe_first_window
, Sframe_first_window
, 0, 1, 0,
379 doc
: /* Return the topmost, leftmost live window on FRAME-OR-WINDOW.
380 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
381 Else if FRAME-OR-WINDOW denotes a valid window, return the first window
382 of that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
383 the first window of that frame. */)
384 (Lisp_Object frame_or_window
)
388 if (NILP (frame_or_window
))
389 window
= SELECTED_FRAME ()->root_window
;
390 else if (WINDOW_VALID_P (frame_or_window
))
391 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
394 CHECK_LIVE_FRAME (frame_or_window
);
395 window
= XFRAME (frame_or_window
)->root_window
;
398 while (NILP (XWINDOW (window
)->buffer
))
400 if (! NILP (XWINDOW (window
)->hchild
))
401 window
= XWINDOW (window
)->hchild
;
402 else if (! NILP (XWINDOW (window
)->vchild
))
403 window
= XWINDOW (window
)->vchild
;
411 DEFUN ("frame-selected-window", Fframe_selected_window
,
412 Sframe_selected_window
, 0, 1, 0,
413 doc
: /* Return the selected window of FRAME-OR-WINDOW.
414 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
415 Else if FRAME-OR-WINDOW denotes a valid window, return the selected
416 window of that window's frame. If FRAME-OR-WINDOW denotes a live frame,
417 return the selected window of that frame. */)
418 (Lisp_Object frame_or_window
)
422 if (NILP (frame_or_window
))
423 window
= SELECTED_FRAME ()->selected_window
;
424 else if (WINDOW_VALID_P (frame_or_window
))
425 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->selected_window
;
428 CHECK_LIVE_FRAME (frame_or_window
);
429 window
= XFRAME (frame_or_window
)->selected_window
;
435 DEFUN ("set-frame-selected-window", Fset_frame_selected_window
,
436 Sset_frame_selected_window
, 2, 3, 0,
437 doc
: /* Set selected window of FRAME to WINDOW.
438 FRAME must be a live frame and defaults to the selected one. If FRAME
439 is the selected frame, this makes WINDOW the selected window. Optional
440 argument NORECORD non-nil means to neither change the order of recently
441 selected windows nor the buffer list. WINDOW must denote a live window.
443 (Lisp_Object frame
, Lisp_Object window
, Lisp_Object norecord
)
446 frame
= selected_frame
;
448 CHECK_LIVE_FRAME (frame
);
449 CHECK_LIVE_WINDOW (window
);
451 if (! EQ (frame
, WINDOW_FRAME (XWINDOW (window
))))
452 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
454 if (EQ (frame
, selected_frame
))
455 return Fselect_window (window
, norecord
);
458 fset_selected_window (XFRAME (frame
), window
);
463 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
464 doc
: /* Return the selected window.
465 The selected window is the window in which the standard cursor for
466 selected windows appears and to which many commands apply. */)
469 return selected_window
;
472 int window_select_count
;
474 /* If select_window is called with inhibit_point_swap non-zero it will
475 not store point of the old selected window's buffer back into that
476 window's pointm slot. This is needed by Fset_window_configuration to
477 avoid that the display routine is called with selected_window set to
478 Qnil causing a subsequent crash. */
480 select_window (Lisp_Object window
, Lisp_Object norecord
, int inhibit_point_swap
)
482 register struct window
*w
;
485 CHECK_LIVE_WINDOW (window
);
487 w
= XWINDOW (window
);
488 w
->frozen_window_start_p
= 0;
492 w
->use_time
= ++window_select_count
;
493 record_buffer (w
->buffer
);
496 /* Make the selected window's buffer current. */
497 Fset_buffer (w
->buffer
);
499 if (EQ (window
, selected_window
) && !inhibit_point_swap
)
502 sf
= SELECTED_FRAME ();
503 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
505 fset_selected_window (XFRAME (WINDOW_FRAME (w
)), window
);
506 /* Use this rather than Fhandle_switch_frame
507 so that FRAME_FOCUS_FRAME is moved appropriately as we
508 move around in the state where a minibuffer in a separate
510 Fselect_frame (WINDOW_FRAME (w
), norecord
);
511 /* Fselect_frame called us back so we've done all the work already. */
512 eassert (EQ (window
, selected_window
));
516 fset_selected_window (sf
, window
);
518 select_window_1 (window
, inhibit_point_swap
);
520 bset_last_selected_window (XBUFFER (w
->buffer
), window
);
521 windows_or_buffers_changed
++;
525 /* Select window with a minimum of fuss, i.e. don't record the change anywhere
526 (not even for redisplay's benefit), and assume that the window's frame is
529 select_window_1 (Lisp_Object window
, bool inhibit_point_swap
)
531 /* Store the old selected window's buffer's point in pointm of the old
532 selected window. It belongs to that window, and when the window is
533 not selected, must be in the window. */
534 if (!inhibit_point_swap
)
536 struct window
*ow
= XWINDOW (selected_window
);
537 if (! NILP (ow
->buffer
))
538 set_marker_both (ow
->pointm
, ow
->buffer
,
539 BUF_PT (XBUFFER (ow
->buffer
)),
540 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
543 selected_window
= window
;
545 /* Go to the point recorded in the window.
546 This is important when the buffer is in more
547 than one window. It also matters when
548 redisplay_window has altered point after scrolling,
549 because it makes the change only in the window. */
551 register ptrdiff_t new_point
= marker_position (XWINDOW (window
)->pointm
);
552 if (new_point
< BEGV
)
554 else if (new_point
> ZV
)
561 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
562 doc
: /* Select WINDOW which must be a live window.
563 Also make WINDOW's frame the selected frame and WINDOW that frame's
564 selected window. In addition, make WINDOW's buffer current and set that
565 buffer's value of `point' to the value of WINDOW's `window-point'.
568 Optional second arg NORECORD non-nil means do not put this buffer at the
569 front of the buffer list and do not make this window the most recently
572 Note that the main editor command loop sets the current buffer to the
573 buffer of the selected window before each command. */)
574 (register Lisp_Object window
, Lisp_Object norecord
)
576 return select_window (window
, norecord
, 0);
579 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
580 doc
: /* Return the buffer displayed in window WINDOW.
581 If WINDOW is omitted or nil, it defaults to the selected window.
582 Return nil for an internal window or a deleted window. */)
585 return decode_any_window (window
)->buffer
;
588 DEFUN ("window-parent", Fwindow_parent
, Swindow_parent
, 0, 1, 0,
589 doc
: /* Return the parent window of window WINDOW.
590 WINDOW must be a valid window and defaults to the selected one.
591 Return nil for a window with no parent (e.g. a root window). */)
594 return decode_valid_window (window
)->parent
;
597 DEFUN ("window-top-child", Fwindow_top_child
, Swindow_top_child
, 0, 1, 0,
598 doc
: /* Return the topmost child window of window WINDOW.
599 WINDOW must be a valid window and defaults to the selected one.
600 Return nil if WINDOW is a live window (live windows have no children).
601 Return nil if WINDOW is an internal window whose children form a
602 horizontal combination. */)
605 return decode_valid_window (window
)->vchild
;
608 DEFUN ("window-left-child", Fwindow_left_child
, Swindow_left_child
, 0, 1, 0,
609 doc
: /* Return the leftmost child window of window WINDOW.
610 WINDOW must be a valid window and defaults to the selected one.
611 Return nil if WINDOW is a live window (live windows have no children).
612 Return nil if WINDOW is an internal window whose children form a
613 vertical combination. */)
616 return decode_valid_window (window
)->hchild
;
619 DEFUN ("window-next-sibling", Fwindow_next_sibling
, Swindow_next_sibling
, 0, 1, 0,
620 doc
: /* Return the next sibling window of window WINDOW.
621 WINDOW must be a valid window and defaults to the selected one.
622 Return nil if WINDOW has no next sibling. */)
625 return decode_valid_window (window
)->next
;
628 DEFUN ("window-prev-sibling", Fwindow_prev_sibling
, Swindow_prev_sibling
, 0, 1, 0,
629 doc
: /* Return the previous sibling window of window WINDOW.
630 WINDOW must be a valid window and defaults to the selected one.
631 Return nil if WINDOW has no previous sibling. */)
634 return decode_valid_window (window
)->prev
;
637 DEFUN ("window-combination-limit", Fwindow_combination_limit
, Swindow_combination_limit
, 1, 1, 0,
638 doc
: /* Return combination limit of window WINDOW.
639 WINDOW must be a valid window used in horizontal or vertical combination.
640 If the return value is nil, child windows of WINDOW can be recombined with
641 WINDOW's siblings. A return value of t means that child windows of
642 WINDOW are never \(re-)combined with WINDOW's siblings. */)
647 CHECK_VALID_WINDOW (window
);
648 w
= XWINDOW (window
);
649 if (!NILP (w
->buffer
))
650 error ("Combination limit is meaningful for internal windows only");
651 return XWINDOW (window
)->combination_limit
;
654 DEFUN ("set-window-combination-limit", Fset_window_combination_limit
, Sset_window_combination_limit
, 2, 2, 0,
655 doc
: /* Set combination limit of window WINDOW to LIMIT; return LIMIT.
656 WINDOW must be a valid window used in horizontal or vertical combination.
657 If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's
658 siblings. LIMIT t means that child windows of WINDOW are never
659 \(re-)combined with WINDOW's siblings. Other values are reserved for
661 (Lisp_Object window
, Lisp_Object limit
)
665 CHECK_VALID_WINDOW (window
);
666 w
= XWINDOW (window
);
667 if (!NILP (w
->buffer
))
668 error ("Combination limit is meaningful for internal windows only");
669 wset_combination_limit (w
, limit
);
673 DEFUN ("window-use-time", Fwindow_use_time
, Swindow_use_time
, 0, 1, 0,
674 doc
: /* Return the use time of window WINDOW.
675 WINDOW must be a live window and defaults to the selected one.
676 The window with the highest use time is the most recently selected
677 one. The window with the lowest use time is the least recently
681 return make_number (decode_live_window (window
)->use_time
);
684 DEFUN ("window-total-height", Fwindow_total_height
, Swindow_total_height
, 0, 1, 0,
685 doc
: /* Return the total height, in lines, of window WINDOW.
686 WINDOW must be a valid window and defaults to the selected one.
688 The return value includes the mode line and header line, if any.
689 If WINDOW is an internal window, the total height is the height
690 of the screen areas spanned by its children.
692 On a graphical display, this total height is reported as an
693 integer multiple of the default character height. */)
696 return make_number (decode_valid_window (window
)->total_lines
);
699 DEFUN ("window-total-width", Fwindow_total_width
, Swindow_total_width
, 0, 1, 0,
700 doc
: /* Return the total width, in columns, of window WINDOW.
701 WINDOW must be a valid window and defaults to the selected one.
703 The return value includes any vertical dividers or scroll bars
704 belonging to WINDOW. If WINDOW is an internal window, the total width
705 is the width of the screen areas spanned by its children.
707 On a graphical display, this total width is reported as an
708 integer multiple of the default character width. */)
711 return make_number (decode_valid_window (window
)->total_cols
);
714 DEFUN ("window-new-total", Fwindow_new_total
, Swindow_new_total
, 0, 1, 0,
715 doc
: /* Return the new total size of window WINDOW.
716 WINDOW must be a valid window and defaults to the selected one. */)
719 return decode_valid_window (window
)->new_total
;
722 DEFUN ("window-normal-size", Fwindow_normal_size
, Swindow_normal_size
, 0, 2, 0,
723 doc
: /* Return the normal height of window WINDOW.
724 WINDOW must be a valid window and defaults to the selected one.
725 If HORIZONTAL is non-nil, return the normal width of WINDOW. */)
726 (Lisp_Object window
, Lisp_Object horizontal
)
728 struct window
*w
= decode_valid_window (window
);
730 return NILP (horizontal
) ? w
->normal_lines
: w
->normal_cols
;
733 DEFUN ("window-new-normal", Fwindow_new_normal
, Swindow_new_normal
, 0, 1, 0,
734 doc
: /* Return new normal size of window WINDOW.
735 WINDOW must be a valid window and defaults to the selected one. */)
738 return decode_valid_window (window
)->new_normal
;
741 DEFUN ("window-left-column", Fwindow_left_column
, Swindow_left_column
, 0, 1, 0,
742 doc
: /* Return left column of window WINDOW.
743 This is the distance, in columns, between the left edge of WINDOW and
744 the left edge of the frame's window area. For instance, the return
745 value is 0 if there is no window to the left of WINDOW.
747 WINDOW must be a valid window and defaults to the selected one. */)
750 return make_number (decode_valid_window (window
)->left_col
);
753 DEFUN ("window-top-line", Fwindow_top_line
, Swindow_top_line
, 0, 1, 0,
754 doc
: /* Return top line of window WINDOW.
755 This is the distance, in lines, between the top of WINDOW and the top
756 of the frame's window area. For instance, the return value is 0 if
757 there is no window above WINDOW.
759 WINDOW must be a valid window and defaults to the selected one. */)
762 return make_number (decode_valid_window (window
)->top_line
);
765 /* Return the number of lines of W's body. Don't count any mode or
769 window_body_lines (struct window
*w
)
771 int height
= w
->total_lines
;
773 if (!MINI_WINDOW_P (w
))
775 if (WINDOW_WANTS_MODELINE_P (w
))
777 if (WINDOW_WANTS_HEADER_LINE_P (w
))
784 /* Return the number of columns of W's body. Don't count columns
785 occupied by the scroll bar or the vertical bar separating W from its
786 right sibling. On window-systems don't count fringes or display
790 window_body_cols (struct window
*w
)
792 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
793 int width
= w
->total_cols
;
795 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
796 /* Scroll bars occupy a few columns. */
797 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
798 else if (!FRAME_WINDOW_P (f
)
799 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
800 /* The column of `|' characters separating side-by-side windows
801 occupies one column only. */
804 /* Display margins cannot be used for normal text. */
805 width
-= WINDOW_LEFT_MARGIN_COLS (w
) + WINDOW_RIGHT_MARGIN_COLS (w
);
807 if (FRAME_WINDOW_P (f
))
808 /* On window-systems, fringes cannot be used for normal text. */
809 width
-= WINDOW_FRINGE_COLS (w
);
814 DEFUN ("window-body-height", Fwindow_body_height
, Swindow_body_height
, 0, 1, 0,
815 doc
: /* Return the height, in lines, of WINDOW's text area.
816 WINDOW must be a live window and defaults to the selected one.
818 The returned height does not include the mode line or header line.
819 On a graphical display, the height is expressed as an integer multiple
820 of the default character height. If a line at the bottom of the text
821 area is only partially visible, that counts as a whole line; to
822 exclude partially-visible lines, use `window-text-height'. */)
825 return make_number (window_body_lines (decode_live_window (window
)));
828 DEFUN ("window-body-width", Fwindow_body_width
, Swindow_body_width
, 0, 1, 0,
829 doc
: /* Return the width, in columns, of WINDOW's text area.
830 WINDOW must be a live window and defaults to the selected one.
832 The return value does not include any vertical dividers, fringe or
833 marginal areas, or scroll bars. On a graphical display, the width is
834 expressed as an integer multiple of the default character width. */)
837 return make_number (window_body_cols (decode_live_window (window
)));
840 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
841 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
842 WINDOW must be a live window and defaults to the selected one. */)
845 return make_number (decode_live_window (window
)->hscroll
);
848 /* Set W's horizontal scroll amount to HSCROLL clipped to a reasonable
849 range, returning the new amount as a fixnum. */
851 set_window_hscroll (struct window
*w
, EMACS_INT hscroll
)
853 /* Horizontal scrolling has problems with large scroll amounts.
854 It's too slow with long lines, and even with small lines the
855 display can be messed up. For now, though, impose only the limits
856 required by the internal representation: horizontal scrolling must
857 fit in fixnum (since it's visible to Elisp) and into ptrdiff_t
858 (since it's stored in a ptrdiff_t). */
859 ptrdiff_t hscroll_max
= min (MOST_POSITIVE_FIXNUM
, PTRDIFF_MAX
);
860 ptrdiff_t new_hscroll
= clip_to_bounds (0, hscroll
, hscroll_max
);
862 /* Prevent redisplay shortcuts when changing the hscroll. */
863 if (w
->hscroll
!= new_hscroll
)
864 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
866 w
->hscroll
= new_hscroll
;
867 return make_number (new_hscroll
);
870 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
871 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
872 WINDOW must be a live window and defaults to the selected one.
873 Clip the number to a reasonable value if out of range.
874 Return the new number. NCOL should be zero or positive.
876 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
877 window so that the location of point moves off-window. */)
878 (Lisp_Object window
, Lisp_Object ncol
)
881 return set_window_hscroll (decode_live_window (window
), XINT (ncol
));
884 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
885 Swindow_redisplay_end_trigger
, 0, 1, 0,
886 doc
: /* Return WINDOW's redisplay end trigger value.
887 WINDOW must be a live window and defaults to the selected one.
888 See `set-window-redisplay-end-trigger' for more information. */)
891 return decode_live_window (window
)->redisplay_end_trigger
;
894 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
895 Sset_window_redisplay_end_trigger
, 2, 2, 0,
896 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
897 WINDOW must be a live window and defaults to the selected one. VALUE
898 should be a buffer position (typically a marker) or nil. If it is a
899 buffer position, then if redisplay in WINDOW reaches a position beyond
900 VALUE, the functions in `redisplay-end-trigger-functions' are called
901 with two arguments: WINDOW, and the end trigger value. Afterwards the
902 end-trigger value is reset to nil. */)
903 (register Lisp_Object window
, Lisp_Object value
)
905 wset_redisplay_end_trigger (decode_live_window (window
), value
);
909 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
910 doc
: /* Return a list of the edge coordinates of WINDOW.
911 WINDOW must be a valid window and defaults to the selected one.
913 The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
914 count by lines, and LEFT and RIGHT count by columns, all relative to 0,
915 0 at top left corner of frame.
917 RIGHT is one more than the rightmost column occupied by WINDOW. BOTTOM
918 is one more than the bottommost row occupied by WINDOW. The edges
919 include the space used by WINDOW's scroll bar, display margins, fringes,
920 header line, and/or mode line. For the edges of just the text area, use
921 `window-inside-edges'. */)
924 register struct window
*w
= decode_valid_window (window
);
926 return list4i (WINDOW_LEFT_EDGE_COL (w
), WINDOW_TOP_EDGE_LINE (w
),
927 WINDOW_RIGHT_EDGE_COL (w
), WINDOW_BOTTOM_EDGE_LINE (w
));
930 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
931 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
932 WINDOW must be a valid window and defaults to the selected one.
934 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
935 0, 0 at the top left corner of the frame.
937 RIGHT is one more than the rightmost x position occupied by WINDOW.
938 BOTTOM is one more than the bottommost y position occupied by WINDOW.
939 The pixel edges include the space used by WINDOW's scroll bar, display
940 margins, fringes, header line, and/or mode line. For the pixel edges
941 of just the text area, use `window-inside-pixel-edges'. */)
944 register struct window
*w
= decode_valid_window (window
);
946 return list4i (WINDOW_LEFT_EDGE_X (w
), WINDOW_TOP_EDGE_Y (w
),
947 WINDOW_RIGHT_EDGE_X (w
), WINDOW_BOTTOM_EDGE_Y (w
));
951 calc_absolute_offset (struct window
*w
, int *add_x
, int *add_y
)
953 struct frame
*f
= XFRAME (w
->frame
);
955 #ifdef FRAME_MENUBAR_HEIGHT
956 *add_y
+= FRAME_MENUBAR_HEIGHT (f
);
958 #ifdef FRAME_TOOLBAR_TOP_HEIGHT
959 *add_y
+= FRAME_TOOLBAR_TOP_HEIGHT (f
);
960 #elif FRAME_TOOLBAR_HEIGHT
961 *add_y
+= FRAME_TOOLBAR_HEIGHT (f
);
963 #ifdef FRAME_NS_TITLEBAR_HEIGHT
964 *add_y
+= FRAME_NS_TITLEBAR_HEIGHT (f
);
966 *add_x
= f
->left_pos
;
967 #ifdef FRAME_TOOLBAR_LEFT_WIDTH
968 *add_x
+= FRAME_TOOLBAR_LEFT_WIDTH (f
);
972 DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges
,
973 Swindow_absolute_pixel_edges
, 0, 1, 0,
974 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
975 WINDOW must be a valid window and defaults to the selected one.
977 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
978 0, 0 at the top left corner of the display.
980 RIGHT is one more than the rightmost x position occupied by WINDOW.
981 BOTTOM is one more than the bottommost y position occupied by WINDOW.
982 The pixel edges include the space used by WINDOW's scroll bar, display
983 margins, fringes, header line, and/or mode line. For the pixel edges
984 of just the text area, use `window-inside-absolute-pixel-edges'. */)
987 register struct window
*w
= decode_valid_window (window
);
990 calc_absolute_offset (w
, &add_x
, &add_y
);
992 return list4i (WINDOW_LEFT_EDGE_X (w
) + add_x
,
993 WINDOW_TOP_EDGE_Y (w
) + add_y
,
994 WINDOW_RIGHT_EDGE_X (w
) + add_x
,
995 WINDOW_BOTTOM_EDGE_Y (w
) + add_y
);
998 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
999 doc
: /* Return a list of the edge coordinates of WINDOW.
1000 WINDOW must be a live window and defaults to the selected one.
1002 The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
1003 count by lines, and LEFT and RIGHT count by columns, all relative to 0,
1004 0 at top left corner of frame.
1006 RIGHT is one more than the rightmost column of WINDOW's text area.
1007 BOTTOM is one more than the bottommost row of WINDOW's text area. The
1008 inside edges do not include the space used by the WINDOW's scroll bar,
1009 display margins, fringes, header line, and/or mode line. */)
1010 (Lisp_Object window
)
1012 register struct window
*w
= decode_live_window (window
);
1014 return list4i ((WINDOW_BOX_LEFT_EDGE_COL (w
)
1015 + WINDOW_LEFT_MARGIN_COLS (w
)
1016 + WINDOW_LEFT_FRINGE_COLS (w
)),
1017 (WINDOW_TOP_EDGE_LINE (w
)
1018 + WINDOW_HEADER_LINE_LINES (w
)),
1019 (WINDOW_BOX_RIGHT_EDGE_COL (w
)
1020 - WINDOW_RIGHT_MARGIN_COLS (w
)
1021 - WINDOW_RIGHT_FRINGE_COLS (w
)),
1022 (WINDOW_BOTTOM_EDGE_LINE (w
)
1023 - WINDOW_MODE_LINE_LINES (w
)));
1026 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
1027 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1028 WINDOW must be a live window and defaults to the selected one.
1030 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1031 (0,0) at the top left corner of the frame's window area.
1033 RIGHT is one more than the rightmost x position of WINDOW's text area.
1034 BOTTOM is one more than the bottommost y position of WINDOW's text area.
1035 The inside edges do not include the space used by WINDOW's scroll bar,
1036 display margins, fringes, header line, and/or mode line. */)
1037 (Lisp_Object window
)
1039 register struct window
*w
= decode_live_window (window
);
1041 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w
)
1042 + WINDOW_LEFT_MARGIN_WIDTH (w
)
1043 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
1044 (WINDOW_TOP_EDGE_Y (w
)
1045 + WINDOW_HEADER_LINE_HEIGHT (w
)),
1046 (WINDOW_BOX_RIGHT_EDGE_X (w
)
1047 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
1048 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
1049 (WINDOW_BOTTOM_EDGE_Y (w
)
1050 - WINDOW_MODE_LINE_HEIGHT (w
)));
1053 DEFUN ("window-inside-absolute-pixel-edges",
1054 Fwindow_inside_absolute_pixel_edges
,
1055 Swindow_inside_absolute_pixel_edges
, 0, 1, 0,
1056 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1057 WINDOW must be a live window and defaults to the selected one.
1059 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1060 (0,0) at the top left corner of the frame's window area.
1062 RIGHT is one more than the rightmost x position of WINDOW's text area.
1063 BOTTOM is one more than the bottommost y position of WINDOW's text area.
1064 The inside edges do not include the space used by WINDOW's scroll bar,
1065 display margins, fringes, header line, and/or mode line. */)
1066 (Lisp_Object window
)
1068 register struct window
*w
= decode_live_window (window
);
1071 calc_absolute_offset (w
, &add_x
, &add_y
);
1073 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w
)
1074 + WINDOW_LEFT_MARGIN_WIDTH (w
)
1075 + WINDOW_LEFT_FRINGE_WIDTH (w
) + add_x
),
1076 (WINDOW_TOP_EDGE_Y (w
)
1077 + WINDOW_HEADER_LINE_HEIGHT (w
) + add_y
),
1078 (WINDOW_BOX_RIGHT_EDGE_X (w
)
1079 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
1080 - WINDOW_RIGHT_FRINGE_WIDTH (w
) + add_x
),
1081 (WINDOW_BOTTOM_EDGE_Y (w
)
1082 - WINDOW_MODE_LINE_HEIGHT (w
) + add_y
));
1085 /* Test if the character at column X, row Y is within window W.
1086 If it is not, return ON_NOTHING;
1087 if it is in the window's text area, return ON_TEXT;
1088 if it is on the window's modeline, return ON_MODE_LINE;
1089 if it is on the border between the window and its right sibling,
1090 return ON_VERTICAL_BORDER.
1091 if it is on a scroll bar, return ON_SCROLL_BAR.
1092 if it is on the window's top line, return ON_HEADER_LINE;
1093 if it is in left or right fringe of the window,
1094 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
1095 if it is in the marginal area to the left/right of the window,
1096 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN.
1098 X and Y are frame relative pixel coordinates. */
1100 static enum window_part
1101 coordinates_in_window (register struct window
*w
, int x
, int y
)
1103 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1104 enum window_part part
;
1105 int ux
= FRAME_COLUMN_WIDTH (f
);
1106 int left_x
= WINDOW_LEFT_EDGE_X (w
);
1107 int right_x
= WINDOW_RIGHT_EDGE_X (w
);
1108 int top_y
= WINDOW_TOP_EDGE_Y (w
);
1109 int bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
1110 /* The width of the area where the vertical line can be dragged.
1111 (Between mode lines for instance. */
1112 int grabbable_width
= ux
;
1113 int lmargin_width
, rmargin_width
, text_left
, text_right
;
1115 /* Outside any interesting row or column? */
1116 if (y
< top_y
|| y
>= bottom_y
|| x
< left_x
|| x
>= right_x
)
1119 /* On the mode line or header line? */
1120 if ((WINDOW_WANTS_MODELINE_P (w
)
1121 && y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
)
1122 && (part
= ON_MODE_LINE
))
1123 || (WINDOW_WANTS_HEADER_LINE_P (w
)
1124 && y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
)
1125 && (part
= ON_HEADER_LINE
)))
1127 /* If it's under/over the scroll bar portion of the mode/header
1128 line, say it's on the vertical line. That's to be able to
1129 resize windows horizontally in case we're using toolkit scroll
1130 bars. Note: If scrollbars are on the left, the window that
1131 must be eventually resized is that on the left of WINDOW. */
1132 if ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1133 && !WINDOW_LEFTMOST_P (w
)
1134 && eabs (x
- left_x
) < grabbable_width
)
1135 || (!WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1136 && !WINDOW_RIGHTMOST_P (w
)
1137 && eabs (x
- right_x
) < grabbable_width
))
1138 return ON_VERTICAL_BORDER
;
1143 /* In what's below, we subtract 1 when computing right_x because we
1144 want the rightmost pixel, which is given by left_pixel+width-1. */
1145 if (w
->pseudo_window_p
)
1148 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
1152 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
1153 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
1156 /* Outside any interesting column? */
1157 if (x
< left_x
|| x
> right_x
)
1158 return ON_SCROLL_BAR
;
1160 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
1161 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
1163 text_left
= window_box_left (w
, TEXT_AREA
);
1164 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
1166 if (FRAME_WINDOW_P (f
))
1168 if (!w
->pseudo_window_p
1169 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
1170 && !WINDOW_RIGHTMOST_P (w
)
1171 && (eabs (x
- right_x
) < grabbable_width
))
1172 return ON_VERTICAL_BORDER
;
1174 /* Need to say "x > right_x" rather than >=, since on character
1175 terminals, the vertical line's x coordinate is right_x. */
1176 else if (!w
->pseudo_window_p
1177 && !WINDOW_RIGHTMOST_P (w
)
1178 && x
> right_x
- ux
)
1179 return ON_VERTICAL_BORDER
;
1183 if (lmargin_width
> 0
1184 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1185 ? (x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
1186 : (x
< left_x
+ lmargin_width
)))
1187 return ON_LEFT_MARGIN
;
1189 return ON_LEFT_FRINGE
;
1192 if (x
>= text_right
)
1194 if (rmargin_width
> 0
1195 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1196 ? (x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
1197 : (x
>= right_x
- rmargin_width
)))
1198 return ON_RIGHT_MARGIN
;
1200 return ON_RIGHT_FRINGE
;
1203 /* Everything special ruled out - must be on text area */
1207 /* Take X is the frame-relative pixel x-coordinate, and return the
1208 x-coordinate relative to part PART of window W. */
1210 window_relative_x_coord (struct window
*w
, enum window_part part
, int x
)
1212 int left_x
= (w
->pseudo_window_p
) ? 0 : WINDOW_BOX_LEFT_EDGE_X (w
);
1217 return x
- window_box_left (w
, TEXT_AREA
);
1219 case ON_LEFT_FRINGE
:
1222 case ON_RIGHT_FRINGE
:
1223 return x
- left_x
- WINDOW_LEFT_FRINGE_WIDTH (w
);
1225 case ON_LEFT_MARGIN
:
1227 - ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1228 ? WINDOW_LEFT_FRINGE_WIDTH (w
) : 0));
1230 case ON_RIGHT_MARGIN
:
1232 - ((w
->pseudo_window_p
)
1233 ? WINDOW_TOTAL_WIDTH (w
)
1234 : WINDOW_BOX_RIGHT_EDGE_X (w
))
1235 + window_box_width (w
, RIGHT_MARGIN_AREA
)
1236 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1237 ? WINDOW_RIGHT_FRINGE_WIDTH (w
) : 0));
1240 /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */
1245 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
1246 Scoordinates_in_window_p
, 2, 2, 0,
1247 doc
: /* Return non-nil if COORDINATES are in WINDOW.
1248 WINDOW must be a live window and defaults to the selected one.
1249 COORDINATES is a cons of the form (X . Y), X and Y being distances
1250 measured in characters from the upper-left corner of the frame.
1251 \(0 . 0) denotes the character in the upper left corner of the
1253 If COORDINATES are in the text portion of WINDOW,
1254 the coordinates relative to the window are returned.
1255 If they are in the mode line of WINDOW, `mode-line' is returned.
1256 If they are in the top mode line of WINDOW, `header-line' is returned.
1257 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1258 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1259 If they are on the border between WINDOW and its right sibling,
1260 `vertical-line' is returned.
1261 If they are in the windows's left or right marginal areas, `left-margin'\n\
1262 or `right-margin' is returned. */)
1263 (register Lisp_Object coordinates
, Lisp_Object window
)
1270 w
= decode_live_window (window
);
1271 f
= XFRAME (w
->frame
);
1272 CHECK_CONS (coordinates
);
1273 lx
= Fcar (coordinates
);
1274 ly
= Fcdr (coordinates
);
1275 CHECK_NUMBER_OR_FLOAT (lx
);
1276 CHECK_NUMBER_OR_FLOAT (ly
);
1277 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1278 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1280 switch (coordinates_in_window (w
, x
, y
))
1286 /* Convert X and Y to window relative pixel coordinates, and
1287 return the canonical char units. */
1288 x
-= window_box_left (w
, TEXT_AREA
);
1289 y
-= WINDOW_TOP_EDGE_Y (w
);
1290 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
1291 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
1296 case ON_VERTICAL_BORDER
:
1297 return Qvertical_line
;
1299 case ON_HEADER_LINE
:
1300 return Qheader_line
;
1302 case ON_LEFT_FRINGE
:
1303 return Qleft_fringe
;
1305 case ON_RIGHT_FRINGE
:
1306 return Qright_fringe
;
1308 case ON_LEFT_MARGIN
:
1309 return Qleft_margin
;
1311 case ON_RIGHT_MARGIN
:
1312 return Qright_margin
;
1315 /* Historically we are supposed to return nil in this case. */
1324 /* Callback for foreach_window, used in window_from_coordinates.
1325 Check if window W contains coordinates specified by USER_DATA which
1326 is actually a pointer to a struct check_window_data CW.
1328 Check if window W contains coordinates *CW->x and *CW->y. If it
1329 does, return W in *CW->window, as Lisp_Object, and return in
1330 *CW->part the part of the window under coordinates *X,*Y. Return
1331 zero from this function to stop iterating over windows. */
1333 struct check_window_data
1335 Lisp_Object
*window
;
1337 enum window_part
*part
;
1341 check_window_containing (struct window
*w
, void *user_data
)
1343 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
1344 enum window_part found
;
1347 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1348 if (found
!= ON_NOTHING
)
1351 XSETWINDOW (*cw
->window
, w
);
1359 /* Find the window containing frame-relative pixel position X/Y and
1360 return it as a Lisp_Object.
1362 If X, Y is on one of the window's special `window_part' elements,
1363 set *PART to the id of that element.
1365 If there is no window under X, Y return nil and leave *PART
1366 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1368 This function was previously implemented with a loop cycling over
1369 windows with Fnext_window, and starting with the frame's selected
1370 window. It turned out that this doesn't work with an
1371 implementation of next_window using Vwindow_list, because
1372 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1373 tree of F when this function is called asynchronously from
1374 note_mouse_highlight. The original loop didn't terminate in this
1378 window_from_coordinates (struct frame
*f
, int x
, int y
,
1379 enum window_part
*part
, bool tool_bar_p
)
1382 struct check_window_data cw
;
1383 enum window_part dummy
;
1389 cw
.window
= &window
, cw
.x
= x
, cw
.y
= y
; cw
.part
= part
;
1390 foreach_window (f
, check_window_containing
, &cw
);
1392 /* If not found above, see if it's in the tool bar window, if a tool
1396 && WINDOWP (f
->tool_bar_window
)
1397 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1398 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), x
, y
)
1402 window
= f
->tool_bar_window
;
1408 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1409 doc
: /* Return window containing coordinates X and Y on FRAME.
1410 FRAME must be a live frame and defaults to the selected one.
1411 The top left corner of the frame is considered to be row 0,
1413 (Lisp_Object x
, Lisp_Object y
, Lisp_Object frame
)
1415 struct frame
*f
= decode_live_frame (frame
);
1417 /* Check that arguments are integers or floats. */
1418 CHECK_NUMBER_OR_FLOAT (x
);
1419 CHECK_NUMBER_OR_FLOAT (y
);
1421 return window_from_coordinates (f
,
1422 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1423 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1424 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1425 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1429 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1430 doc
: /* Return current value of point in WINDOW.
1431 WINDOW must be a live window and defaults to the selected one.
1433 For a nonselected window, this is the value point would have if that
1434 window were selected.
1436 Note that, when WINDOW is selected, the value returned is the same as
1437 that returned by `point' for WINDOW's buffer. It would be more strictly
1438 correct to return the top-level value of `point', outside of any
1439 `save-excursion' forms. But that is hard to define. */)
1440 (Lisp_Object window
)
1442 register struct window
*w
= decode_live_window (window
);
1444 if (w
== XWINDOW (selected_window
))
1445 return make_number (BUF_PT (XBUFFER (w
->buffer
)));
1447 return Fmarker_position (w
->pointm
);
1450 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1451 doc
: /* Return position at which display currently starts in WINDOW.
1452 WINDOW must be a live window and defaults to the selected one.
1453 This is updated by redisplay or by calling `set-window-start'. */)
1454 (Lisp_Object window
)
1456 return Fmarker_position (decode_live_window (window
)->start
);
1459 /* This is text temporarily removed from the doc string below.
1461 This function returns nil if the position is not currently known.
1462 That happens when redisplay is preempted and doesn't finish.
1463 If in that case you want to compute where the end of the window would
1464 have been if redisplay had finished, do this:
1466 (goto-char (window-start window))
1467 (vertical-motion (1- (window-height window)) window)
1470 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1471 doc
: /* Return position at which display currently ends in WINDOW.
1472 WINDOW must be a live window and defaults to the selected one.
1473 This is updated by redisplay, when it runs to completion.
1474 Simply changing the buffer text or setting `window-start'
1475 does not update this value.
1476 Return nil if there is no recorded value. (This can happen if the
1477 last redisplay of WINDOW was preempted, and did not finish.)
1478 If UPDATE is non-nil, compute the up-to-date position
1479 if it isn't already recorded. */)
1480 (Lisp_Object window
, Lisp_Object update
)
1483 struct window
*w
= decode_live_window (window
);
1492 && (windows_or_buffers_changed
|| !w
->window_end_valid
)
1495 struct text_pos startp
;
1496 ptrdiff_t charpos
= marker_position (w
->start
);
1498 struct buffer
*old_buffer
= NULL
;
1499 void *itdata
= NULL
;
1501 /* Cannot use Fvertical_motion because that function doesn't
1502 cope with variable-height lines. */
1503 if (b
!= current_buffer
)
1505 old_buffer
= current_buffer
;
1506 set_buffer_internal (b
);
1509 /* In case W->start is out of the range, use something
1510 reasonable. This situation occurred when loading a file with
1511 `-l' containing a call to `rmail' with subsequent other
1512 commands. At the end, W->start happened to be BEG, while
1513 rmail had already narrowed the buffer. */
1515 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1516 else if (charpos
> ZV
)
1517 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1519 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1521 itdata
= bidi_shelve_cache ();
1522 start_display (&it
, w
, startp
);
1523 move_it_vertically (&it
, window_box_height (w
));
1524 if (it
.current_y
< it
.last_visible_y
)
1525 move_it_past_eol (&it
);
1526 value
= make_number (IT_CHARPOS (it
));
1527 bidi_unshelve_cache (itdata
, 0);
1530 set_buffer_internal (old_buffer
);
1533 XSETINT (value
, BUF_Z (b
) - XFASTINT (w
->window_end_pos
));
1538 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1539 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1540 WINDOW must be a live window and defaults to the selected one.
1542 (Lisp_Object window
, Lisp_Object pos
)
1544 register struct window
*w
= decode_live_window (window
);
1546 /* Type of POS is checked by Fgoto_char or set_marker_restricted ... */
1548 if (w
== XWINDOW (selected_window
))
1550 if (XBUFFER (w
->buffer
) == current_buffer
)
1554 struct buffer
*old_buffer
= current_buffer
;
1556 /* ... but here we want to catch type error before buffer change. */
1557 CHECK_NUMBER_COERCE_MARKER (pos
);
1558 set_buffer_internal (XBUFFER (w
->buffer
));
1560 set_buffer_internal (old_buffer
);
1565 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1566 /* We have to make sure that redisplay updates the window to show
1567 the new value of point. */
1568 ++windows_or_buffers_changed
;
1574 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1575 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1576 WINDOW must be a live window and defaults to the selected one. Return
1577 POS. Optional third arg NOFORCE non-nil inhibits next redisplay from
1578 overriding motion of point in order to display at this exact start. */)
1579 (Lisp_Object window
, Lisp_Object pos
, Lisp_Object noforce
)
1581 register struct window
*w
= decode_live_window (window
);
1583 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1584 /* This is not right, but much easier than doing what is right. */
1585 w
->start_at_line_beg
= 0;
1588 w
->update_mode_line
= 1;
1589 w
->last_modified
= 0;
1590 w
->last_overlay_modified
= 0;
1591 if (!EQ (window
, selected_window
))
1592 windows_or_buffers_changed
++;
1597 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
1598 Spos_visible_in_window_p
, 0, 3, 0,
1599 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
1600 WINDOW must be a live window and defaults to the selected one.
1602 Return nil if that position is scrolled vertically out of view. If a
1603 character is only partially visible, nil is returned, unless the
1604 optional argument PARTIALLY is non-nil. If POS is only out of view
1605 because of horizontal scrolling, return non-nil. If POS is t, it
1606 specifies the position of the last visible glyph in WINDOW. POS
1607 defaults to point in WINDOW; WINDOW defaults to the selected window.
1609 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1610 return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
1611 where X and Y are the pixel coordinates relative to the top left corner
1612 of the window. The remaining elements are omitted if the character after
1613 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1614 off-window at the top and bottom of the row, ROWH is the height of the
1615 display row, and VPOS is the row number (0-based) containing POS. */)
1616 (Lisp_Object pos
, Lisp_Object window
, Lisp_Object partially
)
1618 register struct window
*w
;
1619 register EMACS_INT posint
;
1620 register struct buffer
*buf
;
1621 struct text_pos top
;
1622 Lisp_Object in_window
= Qnil
;
1623 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
1626 w
= decode_live_window (window
);
1627 buf
= XBUFFER (w
->buffer
);
1628 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1632 else if (!NILP (pos
))
1634 CHECK_NUMBER_COERCE_MARKER (pos
);
1635 posint
= XINT (pos
);
1637 else if (w
== XWINDOW (selected_window
))
1640 posint
= marker_position (w
->pointm
);
1642 /* If position is above window start or outside buffer boundaries,
1643 or if window start is out of range, position is not visible. */
1645 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
1646 && CHARPOS (top
) >= BUF_BEGV (buf
)
1647 && CHARPOS (top
) <= BUF_ZV (buf
)
1648 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
1649 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
1652 if (!NILP (in_window
) && !NILP (partially
))
1654 Lisp_Object part
= Qnil
;
1656 part
= list4i (rtop
, rbot
, rowh
, vpos
);
1657 in_window
= Fcons (make_number (x
),
1658 Fcons (make_number (y
), part
));
1664 DEFUN ("window-line-height", Fwindow_line_height
,
1665 Swindow_line_height
, 0, 2, 0,
1666 doc
: /* Return height in pixels of text line LINE in window WINDOW.
1667 WINDOW must be a live window and defaults to the selected one.
1669 Return height of current line if LINE is omitted or nil. Return height of
1670 header or mode line if LINE is `header-line' or `mode-line'.
1671 Otherwise, LINE is a text line number starting from 0. A negative number
1672 counts from the end of the window.
1674 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
1675 in pixels of the visible part of the line, VPOS and YPOS are the
1676 vertical position in lines and pixels of the line, relative to the top
1677 of the first text line, and OFFBOT is the number of off-window pixels at
1678 the bottom of the text line. If there are off-window pixels at the top
1679 of the (first) text line, YPOS is negative.
1681 Return nil if window display is not up-to-date. In that case, use
1682 `pos-visible-in-window-p' to obtain the information. */)
1683 (Lisp_Object line
, Lisp_Object window
)
1685 register struct window
*w
;
1686 register struct buffer
*b
;
1687 struct glyph_row
*row
, *end_row
;
1691 w
= decode_live_window (window
);
1693 if (noninteractive
|| w
->pseudo_window_p
)
1696 CHECK_BUFFER (w
->buffer
);
1697 b
= XBUFFER (w
->buffer
);
1699 /* Fail if current matrix is not up-to-date. */
1700 if (!w
->window_end_valid
1701 || current_buffer
->clip_changed
1702 || current_buffer
->prevent_redisplay_optimizations_p
1703 || w
->last_modified
< BUF_MODIFF (b
)
1704 || w
->last_overlay_modified
< BUF_OVERLAY_MODIFF (b
))
1710 if (i
< 0 || i
>= w
->current_matrix
->nrows
1711 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
1713 max_y
= window_text_bottom_y (w
);
1717 if (EQ (line
, Qheader_line
))
1719 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
1721 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
1722 return row
->enabled_p
? list4i (row
->height
, 0, 0, 0) : Qnil
;
1725 if (EQ (line
, Qmode_line
))
1727 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
1728 return (row
->enabled_p
?
1729 list4i (row
->height
,
1730 0, /* not accurate */
1731 (WINDOW_HEADER_LINE_HEIGHT (w
)
1732 + window_text_bottom_y (w
)),
1737 CHECK_NUMBER (line
);
1740 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1741 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1742 max_y
= window_text_bottom_y (w
);
1745 while ((n
< 0 || i
< n
)
1746 && row
<= end_row
&& row
->enabled_p
1747 && row
->y
+ row
->height
< max_y
)
1750 if (row
> end_row
|| !row
->enabled_p
)
1762 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
1763 return list4i (row
->height
+ min (0, row
->y
) - crop
, i
, row
->y
, crop
);
1766 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1768 doc
: /* Return non-nil when WINDOW is dedicated to its buffer.
1769 More precisely, return the value assigned by the last call of
1770 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1771 never called with WINDOW as its argument, or the value set by that
1772 function was internally reset since its last call. WINDOW must be a
1773 live window and defaults to the selected one.
1775 When a window is dedicated to its buffer, `display-buffer' will refrain
1776 from displaying another buffer in it. `get-lru-window' and
1777 `get-largest-window' treat dedicated windows specially.
1778 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1779 `kill-buffer' can delete a dedicated window and the containing frame.
1781 Functions like `set-window-buffer' may change the buffer displayed by a
1782 window, unless that window is "strongly" dedicated to its buffer, that
1783 is the value returned by `window-dedicated-p' is t. */)
1784 (Lisp_Object window
)
1786 return decode_live_window (window
)->dedicated
;
1789 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1790 Sset_window_dedicated_p
, 2, 2, 0,
1791 doc
: /* Mark WINDOW as dedicated according to FLAG.
1792 WINDOW must be a live window and defaults to the selected one. FLAG
1793 non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means
1794 mark WINDOW as non-dedicated. Return FLAG.
1796 When a window is dedicated to its buffer, `display-buffer' will refrain
1797 from displaying another buffer in it. `get-lru-window' and
1798 `get-largest-window' treat dedicated windows specially.
1799 `delete-windows-on', `replace-buffer-in-windows', `quit-window',
1800 `quit-restore-window' and `kill-buffer' can delete a dedicated window
1801 and the containing frame.
1803 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
1804 its buffer. Functions like `set-window-buffer' may change the buffer
1805 displayed by a window, unless that window is strongly dedicated to its
1806 buffer. If and when `set-window-buffer' displays another buffer in a
1807 window, it also makes sure that the window is no more dedicated. */)
1808 (Lisp_Object window
, Lisp_Object flag
)
1810 wset_dedicated (decode_live_window (window
), flag
);
1814 DEFUN ("window-prev-buffers", Fwindow_prev_buffers
, Swindow_prev_buffers
,
1816 doc
: /* Return buffers previously shown in WINDOW.
1817 WINDOW must be a live window and defaults to the selected one.
1819 The return value is a list of elements (BUFFER WINDOW-START POS),
1820 where BUFFER is a buffer, WINDOW-START is the start position of the
1821 window for that buffer, and POS is a window-specific point value. */)
1822 (Lisp_Object window
)
1824 return decode_live_window (window
)->prev_buffers
;
1827 DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers
,
1828 Sset_window_prev_buffers
, 2, 2, 0,
1829 doc
: /* Set WINDOW's previous buffers to PREV-BUFFERS.
1830 WINDOW must be a live window and defaults to the selected one.
1832 PREV-BUFFERS should be a list of elements (BUFFER WINDOW-START POS),
1833 where BUFFER is a buffer, WINDOW-START is the start position of the
1834 window for that buffer, and POS is a window-specific point value. */)
1835 (Lisp_Object window
, Lisp_Object prev_buffers
)
1837 wset_prev_buffers (decode_live_window (window
), prev_buffers
);
1838 return prev_buffers
;
1841 DEFUN ("window-next-buffers", Fwindow_next_buffers
, Swindow_next_buffers
,
1843 doc
: /* Return list of buffers recently re-shown in WINDOW.
1844 WINDOW must be a live window and defaults to the selected one. */)
1845 (Lisp_Object window
)
1847 return decode_live_window (window
)->next_buffers
;
1850 DEFUN ("set-window-next-buffers", Fset_window_next_buffers
,
1851 Sset_window_next_buffers
, 2, 2, 0,
1852 doc
: /* Set WINDOW's next buffers to NEXT-BUFFERS.
1853 WINDOW must be a live window and defaults to the selected one.
1854 NEXT-BUFFERS should be a list of buffers. */)
1855 (Lisp_Object window
, Lisp_Object next_buffers
)
1857 wset_next_buffers (decode_live_window (window
), next_buffers
);
1858 return next_buffers
;
1861 DEFUN ("window-parameters", Fwindow_parameters
, Swindow_parameters
,
1863 doc
: /* Return the parameters of WINDOW and their values.
1864 WINDOW must be a valid window and defaults to the selected one. The
1865 return value is a list of elements of the form (PARAMETER . VALUE). */)
1866 (Lisp_Object window
)
1868 return Fcopy_alist (decode_valid_window (window
)->window_parameters
);
1871 DEFUN ("window-parameter", Fwindow_parameter
, Swindow_parameter
,
1873 doc
: /* Return WINDOW's value for PARAMETER.
1874 WINDOW can be any window and defaults to the selected one. */)
1875 (Lisp_Object window
, Lisp_Object parameter
)
1879 result
= Fassq (parameter
, decode_any_window (window
)->window_parameters
);
1880 return CDR_SAFE (result
);
1883 DEFUN ("set-window-parameter", Fset_window_parameter
,
1884 Sset_window_parameter
, 3, 3, 0,
1885 doc
: /* Set WINDOW's value of PARAMETER to VALUE.
1886 WINDOW can be any window and defaults to the selected one.
1888 (Lisp_Object window
, Lisp_Object parameter
, Lisp_Object value
)
1890 register struct window
*w
= decode_any_window (window
);
1891 Lisp_Object old_alist_elt
;
1893 old_alist_elt
= Fassq (parameter
, w
->window_parameters
);
1894 if (NILP (old_alist_elt
))
1895 wset_window_parameters
1896 (w
, Fcons (Fcons (parameter
, value
), w
->window_parameters
));
1898 Fsetcdr (old_alist_elt
, value
);
1902 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1904 doc
: /* Return the display-table that WINDOW is using.
1905 WINDOW must be a live window and defaults to the selected one. */)
1906 (Lisp_Object window
)
1908 return decode_live_window (window
)->display_table
;
1911 /* Get the display table for use on window W. This is either W's
1912 display table or W's buffer's display table. Ignore the specified
1913 tables if they are not valid; if no valid table is specified,
1916 struct Lisp_Char_Table
*
1917 window_display_table (struct window
*w
)
1919 struct Lisp_Char_Table
*dp
= NULL
;
1921 if (DISP_TABLE_P (w
->display_table
))
1922 dp
= XCHAR_TABLE (w
->display_table
);
1923 else if (BUFFERP (w
->buffer
))
1925 struct buffer
*b
= XBUFFER (w
->buffer
);
1927 if (DISP_TABLE_P (BVAR (b
, display_table
)))
1928 dp
= XCHAR_TABLE (BVAR (b
, display_table
));
1929 else if (DISP_TABLE_P (Vstandard_display_table
))
1930 dp
= XCHAR_TABLE (Vstandard_display_table
);
1936 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1937 doc
: /* Set WINDOW's display-table to TABLE.
1938 WINDOW must be a live window and defaults to the selected one. */)
1939 (register Lisp_Object window
, Lisp_Object table
)
1941 wset_display_table (decode_live_window (window
), table
);
1945 /* Record info on buffer window W is displaying
1946 when it is about to cease to display that buffer. */
1948 unshow_buffer (register struct window
*w
)
1955 if (b
!= XMARKER (w
->pointm
)->buffer
)
1959 if (w
== XWINDOW (selected_window
)
1960 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1961 /* Do this except when the selected window's buffer
1962 is being removed from some other window. */
1964 /* last_window_start records the start position that this buffer
1965 had in the last window to be disconnected from it.
1966 Now that this statement is unconditional,
1967 it is possible for the buffer to be displayed in the
1968 selected window, while last_window_start reflects another
1969 window which was recently showing the same buffer.
1970 Some people might say that might be a good thing. Let's see. */
1971 b
->last_window_start
= marker_position (w
->start
);
1973 /* Point in the selected window's buffer
1974 is actually stored in that buffer, and the window's pointm isn't used.
1975 So don't clobber point in that buffer. */
1976 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1977 /* Don't clobber point in current buffer either (this could be
1978 useful in connection with bug#12208).
1979 && XBUFFER (buf) != current_buffer */
1980 /* This line helps to fix Horsley's testbug.el bug. */
1981 && !(WINDOWP (BVAR (b
, last_selected_window
))
1982 && w
!= XWINDOW (BVAR (b
, last_selected_window
))
1983 && EQ (buf
, XWINDOW (BVAR (b
, last_selected_window
))->buffer
)))
1984 temp_set_point_both (b
,
1985 clip_to_bounds (BUF_BEGV (b
),
1986 marker_position (w
->pointm
),
1988 clip_to_bounds (BUF_BEGV_BYTE (b
),
1989 marker_byte_position (w
->pointm
),
1992 if (WINDOWP (BVAR (b
, last_selected_window
))
1993 && w
== XWINDOW (BVAR (b
, last_selected_window
)))
1994 bset_last_selected_window (b
, Qnil
);
1997 /* Put NEW into the window structure in place of OLD. SETFLAG zero
1998 means change window structure only. Otherwise store geometry and
1999 other settings as well. */
2001 replace_window (Lisp_Object old
, Lisp_Object
new, int setflag
)
2003 register Lisp_Object tem
;
2004 register struct window
*o
= XWINDOW (old
), *n
= XWINDOW (new);
2006 /* If OLD is its frame's root window, then NEW is the new
2007 root window for that frame. */
2008 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
2009 fset_root_window (XFRAME (o
->frame
), new);
2013 n
->left_col
= o
->left_col
;
2014 n
->top_line
= o
->top_line
;
2015 n
->total_cols
= o
->total_cols
;
2016 n
->total_lines
= o
->total_lines
;
2017 wset_normal_cols (n
, o
->normal_cols
);
2018 wset_normal_cols (o
, make_float (1.0));
2019 wset_normal_lines (n
, o
->normal_lines
);
2020 wset_normal_lines (o
, make_float (1.0));
2021 n
->desired_matrix
= n
->current_matrix
= 0;
2023 memset (&n
->cursor
, 0, sizeof (n
->cursor
));
2024 memset (&n
->last_cursor
, 0, sizeof (n
->last_cursor
));
2025 memset (&n
->phys_cursor
, 0, sizeof (n
->phys_cursor
));
2026 n
->phys_cursor_type
= -1;
2027 n
->phys_cursor_width
= -1;
2028 n
->must_be_updated_p
= 0;
2029 n
->pseudo_window_p
= 0;
2030 wset_window_end_vpos (n
, make_number (0));
2031 wset_window_end_pos (n
, make_number (0));
2032 n
->window_end_valid
= 0;
2033 n
->frozen_window_start_p
= 0;
2039 wset_prev (XWINDOW (tem
), new);
2044 wset_next (XWINDOW (tem
), new);
2047 wset_parent (n
, tem
);
2050 if (EQ (XWINDOW (tem
)->vchild
, old
))
2051 wset_vchild (XWINDOW (tem
), new);
2052 if (EQ (XWINDOW (tem
)->hchild
, old
))
2053 wset_hchild (XWINDOW (tem
), new);
2057 /* If window WINDOW and its parent window are iso-combined, merge
2058 WINDOW's children into those of its parent window and mark WINDOW as
2062 recombine_windows (Lisp_Object window
)
2064 struct window
*w
, *p
, *c
;
2065 Lisp_Object parent
, child
;
2068 w
= XWINDOW (window
);
2070 if (!NILP (parent
) && NILP (w
->combination_limit
))
2072 p
= XWINDOW (parent
);
2073 if (((!NILP (p
->vchild
) && !NILP (w
->vchild
))
2074 || (!NILP (p
->hchild
) && !NILP (w
->hchild
))))
2075 /* WINDOW and PARENT are both either a vertical or a horizontal
2078 horflag
= NILP (w
->vchild
);
2079 child
= horflag
? w
->hchild
: w
->vchild
;
2080 c
= XWINDOW (child
);
2082 /* Splice WINDOW's children into its parent's children and
2083 assign new normal sizes. */
2086 wset_hchild (p
, child
);
2088 wset_vchild (p
, child
);
2091 wset_prev (c
, w
->prev
);
2092 wset_next (XWINDOW (w
->prev
), child
);
2097 wset_parent (c
, parent
);
2100 wset_normal_cols (c
,
2101 make_float ((double) c
->total_cols
2102 / (double) p
->total_cols
));
2104 wset_normal_lines (c
,
2105 make_float ((double) c
->total_lines
2106 / (double) p
->total_lines
));
2110 if (!NILP (w
->next
))
2112 wset_next (c
, w
->next
);
2113 wset_prev (XWINDOW (c
->next
), child
);
2121 c
= XWINDOW (child
);
2125 /* WINDOW can be deleted now. */
2126 wset_vchild (w
, Qnil
);
2127 wset_hchild (w
, Qnil
);
2132 /* If WINDOW can be deleted, delete it. */
2134 delete_deletable_window (Lisp_Object window
)
2136 if (!NILP (call1 (Qwindow_deletable_p
, window
)))
2137 call1 (Qdelete_window
, window
);
2140 /***********************************************************************
2142 ***********************************************************************/
2144 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
2145 pointer. This is a callback function for foreach_window, used in
2146 the window_list function. */
2149 add_window_to_list (struct window
*w
, void *user_data
)
2151 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
2153 XSETWINDOW (window
, w
);
2154 *list
= Fcons (window
, *list
);
2159 /* Return a list of all windows, for use by next_window. If
2160 Vwindow_list is a list, return that list. Otherwise, build a new
2161 list, cache it in Vwindow_list, and return that. */
2166 if (!CONSP (Vwindow_list
))
2168 Lisp_Object tail
, frame
;
2170 Vwindow_list
= Qnil
;
2171 FOR_EACH_FRAME (tail
, frame
)
2173 Lisp_Object args
[2];
2175 /* We are visiting windows in canonical order, and add
2176 new windows at the front of args[1], which means we
2177 have to reverse this list at the end. */
2179 foreach_window (XFRAME (frame
), add_window_to_list
, &args
[1]);
2180 args
[0] = Vwindow_list
;
2181 args
[1] = Fnreverse (args
[1]);
2182 Vwindow_list
= Fnconc (2, args
);
2186 return Vwindow_list
;
2190 /* Value is non-zero if WINDOW satisfies the constraints given by
2191 OWINDOW, MINIBUF and ALL_FRAMES.
2193 MINIBUF t means WINDOW may be minibuffer windows.
2194 `lambda' means WINDOW may not be a minibuffer window.
2195 a window means a specific minibuffer window
2197 ALL_FRAMES t means search all frames,
2198 nil means search just current frame,
2199 `visible' means search just visible frames on the
2201 0 means search visible and iconified frames on the
2203 a window means search the frame that window belongs to,
2204 a frame means consider windows on that frame, only. */
2207 candidate_window_p (Lisp_Object window
, Lisp_Object owindow
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2209 struct window
*w
= XWINDOW (window
);
2210 struct frame
*f
= XFRAME (w
->frame
);
2211 int candidate_p
= 1;
2213 if (!BUFFERP (w
->buffer
))
2215 else if (MINI_WINDOW_P (w
)
2216 && (EQ (minibuf
, Qlambda
)
2217 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
2219 /* If MINIBUF is `lambda' don't consider any mini-windows.
2220 If it is a window, consider only that one. */
2223 else if (EQ (all_frames
, Qt
))
2225 else if (NILP (all_frames
))
2227 eassert (WINDOWP (owindow
));
2228 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
2230 else if (EQ (all_frames
, Qvisible
))
2232 candidate_p
= FRAME_VISIBLE_P (f
)
2233 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2234 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2237 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
2239 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
2240 #ifdef HAVE_X_WINDOWS
2241 /* Yuck!! If we've just created the frame and the
2242 window-manager requested the user to place it
2243 manually, the window may still not be considered
2244 `visible'. I'd argue it should be at least
2245 something like `iconified', but don't know how to do
2247 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
2248 && !f
->output_data
.x
->has_been_visible
)
2251 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2252 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2254 else if (WINDOWP (all_frames
))
2255 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
2256 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
2257 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
2258 else if (FRAMEP (all_frames
))
2259 candidate_p
= EQ (all_frames
, w
->frame
);
2265 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2266 Fwindow_list. See candidate_window_p for the meaning of WINDOW,
2267 MINIBUF, and ALL_FRAMES. */
2270 decode_next_window_args (Lisp_Object
*window
, Lisp_Object
*minibuf
, Lisp_Object
*all_frames
)
2272 struct window
*w
= decode_live_window (*window
);
2274 XSETWINDOW (*window
, w
);
2275 /* MINIBUF nil may or may not include minibuffers. Decide if it
2277 if (NILP (*minibuf
))
2278 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
2279 else if (!EQ (*minibuf
, Qt
))
2282 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2283 => count none of them, or a specific minibuffer window (the
2284 active one) to count. */
2286 /* ALL_FRAMES nil doesn't specify which frames to include. */
2287 if (NILP (*all_frames
))
2289 = (!EQ (*minibuf
, Qlambda
)
2290 ? FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
))
2292 else if (EQ (*all_frames
, Qvisible
))
2294 else if (EQ (*all_frames
, make_number (0)))
2296 else if (FRAMEP (*all_frames
))
2298 else if (!EQ (*all_frames
, Qt
))
2303 /* Return the next or previous window of WINDOW in cyclic ordering
2304 of windows. NEXT_P non-zero means return the next window. See the
2305 documentation string of next-window for the meaning of MINIBUF and
2309 next_window (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
, int next_p
)
2311 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2313 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2314 return the first window on the frame. */
2315 if (FRAMEP (all_frames
)
2316 && !EQ (all_frames
, XWINDOW (window
)->frame
))
2317 return Fframe_first_window (all_frames
);
2323 /* Find WINDOW in the list of all windows. */
2324 list
= Fmemq (window
, window_list ());
2326 /* Scan forward from WINDOW to the end of the window list. */
2328 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
2329 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2332 /* Scan from the start of the window list up to WINDOW. */
2334 for (list
= Vwindow_list
;
2335 CONSP (list
) && !EQ (XCAR (list
), window
);
2337 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2341 window
= XCAR (list
);
2345 Lisp_Object candidate
, list
;
2347 /* Scan through the list of windows for candidates. If there are
2348 candidate windows in front of WINDOW, the last one of these
2349 is the one we want. If there are candidates following WINDOW
2350 in the list, again the last one of these is the one we want. */
2352 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
2354 if (EQ (XCAR (list
), window
))
2356 if (WINDOWP (candidate
))
2359 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
2361 candidate
= XCAR (list
);
2364 if (WINDOWP (candidate
))
2372 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
2373 doc
: /* Return live window after WINDOW in the cyclic ordering of windows.
2374 WINDOW must be a live window and defaults to the selected one. The
2375 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2378 MINIBUF nil or omitted means consider the minibuffer window only if the
2379 minibuffer is active. MINIBUF t means consider the minibuffer window
2380 even if the minibuffer is not active. Any other value means do not
2381 consider the minibuffer window even if the minibuffer is active.
2383 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2384 plus the minibuffer window if specified by the MINIBUF argument. If the
2385 minibuffer counts, consider all windows on all frames that share that
2386 minibuffer too. The following non-nil values of ALL-FRAMES have special
2389 - t means consider all windows on all existing frames.
2391 - `visible' means consider all windows on all visible frames.
2393 - 0 (the number zero) means consider all windows on all visible and
2396 - A frame means consider all windows on that frame only.
2398 Anything else means consider all windows on WINDOW's frame and no
2401 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2402 `next-window' to iterate through the entire cycle of acceptable
2403 windows, eventually ending up back at the window you started with.
2404 `previous-window' traverses the same cycle, in the reverse order. */)
2405 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2407 return next_window (window
, minibuf
, all_frames
, 1);
2411 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
2412 doc
: /* Return live window before WINDOW in the cyclic ordering of windows.
2413 WINDOW must be a live window and defaults to the selected one. The
2414 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2417 MINIBUF nil or omitted means consider the minibuffer window only if the
2418 minibuffer is active. MINIBUF t means consider the minibuffer window
2419 even if the minibuffer is not active. Any other value means do not
2420 consider the minibuffer window even if the minibuffer is active.
2422 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2423 plus the minibuffer window if specified by the MINIBUF argument. If the
2424 minibuffer counts, consider all windows on all frames that share that
2425 minibuffer too. The following non-nil values of ALL-FRAMES have special
2428 - t means consider all windows on all existing frames.
2430 - `visible' means consider all windows on all visible frames.
2432 - 0 (the number zero) means consider all windows on all visible and
2435 - A frame means consider all windows on that frame only.
2437 Anything else means consider all windows on WINDOW's frame and no
2440 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2441 use `previous-window' to iterate through the entire cycle of
2442 acceptable windows, eventually ending up back at the window you
2443 started with. `next-window' traverses the same cycle, in the
2445 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2447 return next_window (window
, minibuf
, all_frames
, 0);
2451 /* Return a list of windows in cyclic ordering. Arguments are like
2452 for `next-window'. */
2455 window_list_1 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2457 Lisp_Object tail
, list
, rest
;
2459 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2462 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2463 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2464 list
= Fcons (XCAR (tail
), list
);
2466 /* Rotate the list to start with WINDOW. */
2467 list
= Fnreverse (list
);
2468 rest
= Fmemq (window
, list
);
2469 if (!NILP (rest
) && !EQ (rest
, list
))
2471 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2473 XSETCDR (tail
, Qnil
);
2474 list
= nconc2 (rest
, list
);
2480 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2481 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2482 FRAME nil or omitted means use the selected frame.
2483 WINDOW nil or omitted means use the window selected within FRAME.
2484 MINIBUF t means include the minibuffer window, even if it isn't active.
2485 MINIBUF nil or omitted means include the minibuffer window only
2487 MINIBUF neither nil nor t means never include the minibuffer window. */)
2488 (Lisp_Object frame
, Lisp_Object minibuf
, Lisp_Object window
)
2491 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2492 CHECK_WINDOW (window
);
2494 frame
= selected_frame
;
2496 if (!EQ (frame
, XWINDOW (window
)->frame
))
2497 error ("Window is on a different frame");
2499 return window_list_1 (window
, minibuf
, frame
);
2503 DEFUN ("window-list-1", Fwindow_list_1
, Swindow_list_1
, 0, 3, 0,
2504 doc
: /* Return a list of all live windows.
2505 WINDOW specifies the first window to list and defaults to the selected
2508 Optional argument MINIBUF nil or omitted means consider the minibuffer
2509 window only if the minibuffer is active. MINIBUF t means consider the
2510 minibuffer window even if the minibuffer is not active. Any other value
2511 means do not consider the minibuffer window even if the minibuffer is
2514 Optional argument ALL-FRAMES nil or omitted means consider all windows
2515 on WINDOW's frame, plus the minibuffer window if specified by the
2516 MINIBUF argument. If the minibuffer counts, consider all windows on all
2517 frames that share that minibuffer too. The following non-nil values of
2518 ALL-FRAMES have special meanings:
2520 - t means consider all windows on all existing frames.
2522 - `visible' means consider all windows on all visible frames.
2524 - 0 (the number zero) means consider all windows on all visible and
2527 - A frame means consider all windows on that frame only.
2529 Anything else means consider all windows on WINDOW's frame and no
2532 If WINDOW is not on the list of windows returned, some other window will
2533 be listed first but no error is signaled. */)
2534 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2536 return window_list_1 (window
, minibuf
, all_frames
);
2539 /* Look at all windows, performing an operation specified by TYPE
2541 If FRAMES is Qt, look at all frames;
2542 Qnil, look at just the selected frame;
2543 Qvisible, look at visible frames;
2544 a frame, just look at windows on that frame.
2545 If MINI is non-zero, perform the operation on minibuffer windows too. */
2550 GET_BUFFER_WINDOW
, /* Arg is buffer */
2551 REPLACE_BUFFER_IN_WINDOWS_SAFELY
, /* Arg is buffer */
2552 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2557 window_loop (enum window_loop type
, Lisp_Object obj
, int mini
, Lisp_Object frames
)
2559 Lisp_Object window
, windows
, best_window
, frame_arg
;
2560 int frame_best_window_flag
= 0;
2562 struct gcpro gcpro1
;
2564 /* If we're only looping through windows on a particular frame,
2565 frame points to that frame. If we're looping through windows
2566 on all frames, frame is 0. */
2567 if (FRAMEP (frames
))
2568 f
= XFRAME (frames
);
2569 else if (NILP (frames
))
2570 f
= SELECTED_FRAME ();
2575 frame_arg
= Qlambda
;
2576 else if (EQ (frames
, make_number (0)))
2578 else if (EQ (frames
, Qvisible
))
2583 /* frame_arg is Qlambda to stick to one frame,
2584 Qvisible to consider all visible frames,
2587 /* Pick a window to start with. */
2591 window
= FRAME_SELECTED_WINDOW (f
);
2593 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2595 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2599 for (; CONSP (windows
); windows
= XCDR (windows
))
2603 window
= XCAR (windows
);
2604 w
= XWINDOW (window
);
2606 /* Note that we do not pay attention here to whether the frame
2607 is visible, since Fwindow_list skips non-visible frames if
2608 that is desired, under the control of frame_arg. */
2609 if (!MINI_WINDOW_P (w
)
2610 /* For REPLACE_BUFFER_IN_WINDOWS_SAFELY, we must always
2611 consider all windows. */
2612 || type
== REPLACE_BUFFER_IN_WINDOWS_SAFELY
2613 || (mini
&& minibuf_level
> 0))
2616 case GET_BUFFER_WINDOW
:
2617 if (EQ (w
->buffer
, obj
)
2618 /* Don't find any minibuffer window except the one that
2619 is currently in use. */
2620 && (MINI_WINDOW_P (w
) ? EQ (window
, minibuf_window
) : 1))
2622 if (EQ (window
, selected_window
))
2623 /* Preferably return the selected window. */
2624 RETURN_UNGCPRO (window
);
2625 else if (EQ (XWINDOW (window
)->frame
, selected_frame
)
2626 && !frame_best_window_flag
)
2627 /* Prefer windows on the current frame (but don't
2628 choose another one if we have one already). */
2630 best_window
= window
;
2631 frame_best_window_flag
= 1;
2633 else if (NILP (best_window
))
2634 best_window
= window
;
2638 case REPLACE_BUFFER_IN_WINDOWS_SAFELY
:
2639 /* We could simply check whether the buffer shown by window
2640 is live, and show another buffer in case it isn't. */
2641 if (EQ (w
->buffer
, obj
))
2643 /* Undedicate WINDOW. */
2644 wset_dedicated (w
, Qnil
);
2645 /* Make WINDOW show the buffer returned by
2646 other_buffer_safely, don't run any hooks. */
2648 (window
, other_buffer_safely (w
->buffer
), 0, 0);
2649 /* If WINDOW is the selected window, make its buffer
2650 current. But do so only if the window shows the
2651 current buffer (Bug#6454). */
2652 if (EQ (window
, selected_window
)
2653 && XBUFFER (w
->buffer
) == current_buffer
)
2654 Fset_buffer (w
->buffer
);
2658 case REDISPLAY_BUFFER_WINDOWS
:
2659 if (EQ (w
->buffer
, obj
))
2661 mark_window_display_accurate (window
, 0);
2662 w
->update_mode_line
= 1;
2663 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2664 ++update_mode_lines
;
2665 best_window
= window
;
2669 /* Check for a window that has a killed buffer. */
2670 case CHECK_ALL_WINDOWS
:
2671 if (! NILP (w
->buffer
)
2672 && !BUFFER_LIVE_P (XBUFFER (w
->buffer
)))
2676 case WINDOW_LOOP_UNUSED
:
2685 /* Used for debugging. Abort if any window has a dead buffer. */
2687 extern void check_all_windows (void) EXTERNALLY_VISIBLE
;
2689 check_all_windows (void)
2691 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2694 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 0, 2, 0,
2695 doc
: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2696 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to
2699 The optional argument ALL-FRAMES specifies the frames to consider:
2701 - t means consider all windows on all existing frames.
2703 - `visible' means consider all windows on all visible frames.
2705 - 0 (the number zero) means consider all windows on all visible
2706 and iconified frames.
2708 - A frame means consider all windows on that frame only.
2710 Any other value of ALL-FRAMES means consider all windows on the
2711 selected frame and no others. */)
2712 (Lisp_Object buffer_or_name
, Lisp_Object all_frames
)
2716 if (NILP (buffer_or_name
))
2717 buffer
= Fcurrent_buffer ();
2719 buffer
= Fget_buffer (buffer_or_name
);
2721 if (BUFFERP (buffer
))
2722 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, all_frames
);
2728 resize_root_window (Lisp_Object window
, Lisp_Object delta
, Lisp_Object horizontal
, Lisp_Object ignore
)
2730 return call4 (Qwindow_resize_root_window
, window
, delta
, horizontal
, ignore
);
2734 DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal
,
2735 Sdelete_other_windows_internal
, 0, 2, "",
2736 doc
: /* Make WINDOW fill its frame.
2737 Only the frame WINDOW is on is affected. WINDOW must be a valid window
2738 and defaults to the selected one.
2740 Optional argument ROOT, if non-nil, must specify an internal window such
2741 that WINDOW is in its window subtree. If this is the case, replace ROOT
2742 by WINDOW and leave alone any windows not part of ROOT's subtree.
2744 When WINDOW is live try to reduce display jumps by keeping the text
2745 previously visible in WINDOW in the same place on the frame. Doing this
2746 depends on the value of (window-start WINDOW), so if calling this
2747 function in a program gives strange scrolling, make sure the
2748 window-start value is reasonable when this function is called. */)
2749 (Lisp_Object window
, Lisp_Object root
)
2751 struct window
*w
, *r
, *s
;
2753 Lisp_Object sibling
, pwindow
, swindow
IF_LINT (= Qnil
), delta
;
2754 ptrdiff_t startpos
IF_LINT (= 0), startbyte
IF_LINT (= 0);
2755 int top
IF_LINT (= 0), new_top
, resize_failed
;
2757 w
= decode_valid_window (window
);
2758 XSETWINDOW (window
, w
);
2759 f
= XFRAME (w
->frame
);
2762 /* ROOT is the frame's root window. */
2764 root
= FRAME_ROOT_WINDOW (f
);
2768 /* ROOT must be an ancestor of WINDOW. */
2770 r
= decode_valid_window (root
);
2771 pwindow
= XWINDOW (window
)->parent
;
2772 while (!NILP (pwindow
))
2773 if (EQ (pwindow
, root
))
2776 pwindow
= XWINDOW (pwindow
)->parent
;
2777 if (!EQ (pwindow
, root
))
2778 error ("Specified root is not an ancestor of specified window");
2781 if (EQ (window
, root
))
2784 /* I don't understand the "top > 0" part below. If we deal with a
2785 standalone minibuffer it would have been caught by the preceding
2787 else if (MINI_WINDOW_P (w
)) /* && top > 0) */
2788 error ("Can't expand minibuffer to full frame");
2790 if (!NILP (w
->buffer
))
2792 startpos
= marker_position (w
->start
);
2793 startbyte
= marker_byte_position (w
->start
);
2794 top
= WINDOW_TOP_EDGE_LINE (w
)
2795 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2796 /* Make sure WINDOW is the frame's selected window. */
2797 if (!EQ (window
, FRAME_SELECTED_WINDOW (f
)))
2799 if (EQ (selected_frame
, w
->frame
))
2800 Fselect_window (window
, Qnil
);
2802 fset_selected_window (f
, window
);
2807 /* See if the frame's selected window is a part of the window
2808 subtree rooted at WINDOW, by finding all the selected window's
2809 parents and comparing each one with WINDOW. If it isn't we
2810 need a new selected window for this frame. */
2811 swindow
= FRAME_SELECTED_WINDOW (f
);
2815 while (!NILP (pwindow
) && !EQ (window
, pwindow
))
2816 pwindow
= XWINDOW (pwindow
)->parent
;
2818 if (EQ (window
, pwindow
))
2819 /* If WINDOW is an ancestor of SWINDOW, then SWINDOW is ok
2820 as the new selected window. */
2823 /* Else try the previous window of SWINDOW. */
2824 swindow
= Fprevious_window (swindow
, Qlambda
, Qnil
);
2827 if (!EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
2829 if (EQ (selected_frame
, w
->frame
))
2830 Fselect_window (swindow
, Qnil
);
2832 fset_selected_window (f
, swindow
);
2837 if (!FRAME_INITIAL_P (f
))
2839 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
2841 /* We are going to free the glyph matrices of WINDOW, and with
2842 that we might lose any information about glyph rows that have
2843 some of their glyphs highlighted in mouse face. (These rows
2844 are marked with a non-zero mouse_face_p flag.) If WINDOW
2845 indeed has some glyphs highlighted in mouse face, signal to
2846 frame's up-to-date hook that mouse highlight was overwritten,
2847 so that it will arrange for redisplaying the highlight. */
2848 if (EQ (hlinfo
->mouse_face_window
, window
))
2850 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
2851 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
2852 hlinfo
->mouse_face_window
= Qnil
;
2855 free_window_matrices (r
);
2857 windows_or_buffers_changed
++;
2858 Vwindow_list
= Qnil
;
2859 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
2862 if (NILP (w
->buffer
))
2864 /* Resize child windows vertically. */
2865 XSETINT (delta
, r
->total_lines
- w
->total_lines
);
2866 w
->top_line
= r
->top_line
;
2867 resize_root_window (window
, delta
, Qnil
, Qnil
);
2868 if (window_resize_check (w
, 0))
2869 window_resize_apply (w
, 0);
2872 resize_root_window (window
, delta
, Qnil
, Qt
);
2873 if (window_resize_check (w
, 0))
2874 window_resize_apply (w
, 0);
2879 /* Resize child windows horizontally. */
2882 w
->left_col
= r
->left_col
;
2883 XSETINT (delta
, r
->total_cols
- w
->total_cols
);
2884 resize_root_window (window
, delta
, Qt
, Qnil
);
2885 if (window_resize_check (w
, 1))
2886 window_resize_apply (w
, 1);
2889 resize_root_window (window
, delta
, Qt
, Qt
);
2890 if (window_resize_check (w
, 1))
2891 window_resize_apply (w
, 1);
2898 /* Play safe, if we still can ... */
2901 w
= XWINDOW (window
);
2905 /* Cleanly unlink WINDOW from window-tree. */
2906 if (!NILP (w
->prev
))
2907 /* Get SIBLING above (on the left of) WINDOW. */
2910 s
= XWINDOW (sibling
);
2911 wset_next (s
, w
->next
);
2912 if (!NILP (s
->next
))
2913 wset_prev (XWINDOW (s
->next
), sibling
);
2916 /* Get SIBLING below (on the right of) WINDOW. */
2919 s
= XWINDOW (sibling
);
2920 wset_prev (s
, Qnil
);
2921 if (!NILP (XWINDOW (w
->parent
)->vchild
))
2922 wset_vchild (XWINDOW (w
->parent
), sibling
);
2924 wset_hchild (XWINDOW (w
->parent
), sibling
);
2927 /* Delete ROOT and all child windows of ROOT. */
2928 if (!NILP (r
->vchild
))
2930 delete_all_child_windows (r
->vchild
);
2931 wset_vchild (r
, Qnil
);
2933 else if (!NILP (r
->hchild
))
2935 delete_all_child_windows (r
->hchild
);
2936 wset_hchild (r
, Qnil
);
2939 replace_window (root
, window
, 1);
2941 /* This must become SWINDOW anyway ....... */
2942 if (!NILP (w
->buffer
) && !resize_failed
)
2944 /* Try to minimize scrolling, by setting the window start to the
2945 point will cause the text at the old window start to be at the
2946 same place on the frame. But don't try to do this if the
2947 window start is outside the visible portion (as might happen
2948 when the display is not current, due to typeahead). */
2949 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2951 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2952 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2954 struct position pos
;
2955 struct buffer
*obuf
= current_buffer
;
2957 Fset_buffer (w
->buffer
);
2958 /* This computation used to temporarily move point, but that
2959 can have unwanted side effects due to text properties. */
2960 pos
= *vmotion (startpos
, startbyte
, -top
, w
);
2962 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2963 w
->window_end_valid
= 0;
2964 w
->start_at_line_beg
= (pos
.bytepos
== BEGV_BYTE
2965 || FETCH_BYTE (pos
.bytepos
- 1) == '\n');
2966 /* We need to do this, so that the window-scroll-functions
2968 w
->optional_new_start
= 1;
2970 set_buffer_internal (obuf
);
2977 run_window_configuration_change_hook (f
);
2984 replace_buffer_in_windows (Lisp_Object buffer
)
2986 call1 (Qreplace_buffer_in_windows
, buffer
);
2989 /* If BUFFER is shown in a window, safely replace it with some other
2990 buffer in all windows of all frames, even those on other keyboards. */
2993 replace_buffer_in_windows_safely (Lisp_Object buffer
)
2995 if (buffer_window_count (XBUFFER (buffer
)))
2997 Lisp_Object tail
, frame
;
2999 /* A single call to window_loop won't do the job because it only
3000 considers frames on the current keyboard. So loop manually over
3001 frames, and handle each one. */
3002 FOR_EACH_FRAME (tail
, frame
)
3003 window_loop (REPLACE_BUFFER_IN_WINDOWS_SAFELY
, buffer
, 1, frame
);
3007 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
3008 minimum allowable size. */
3011 check_frame_size (FRAME_PTR frame
, int *rows
, int *cols
)
3013 /* For height, we have to see:
3014 how many windows the frame has at minimum (one or two),
3015 and whether it has a menu bar or other special stuff at the top. */
3017 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
3018 ? MIN_SAFE_WINDOW_HEIGHT
3019 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
3021 if (FRAME_TOP_MARGIN (frame
) > 0)
3022 min_height
+= FRAME_TOP_MARGIN (frame
);
3024 if (*rows
< min_height
)
3026 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
3027 *cols
= MIN_SAFE_WINDOW_WIDTH
;
3030 /* Adjust the margins of window W if text area is too small.
3031 Return 1 if window width is ok after adjustment; 0 if window
3032 is still too narrow. */
3035 adjust_window_margins (struct window
*w
)
3037 int box_cols
= (WINDOW_TOTAL_COLS (w
)
3038 - WINDOW_FRINGE_COLS (w
)
3039 - WINDOW_SCROLL_BAR_COLS (w
));
3040 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
3041 + WINDOW_RIGHT_MARGIN_COLS (w
));
3043 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
3046 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
3049 /* Window's text area is too narrow, but reducing the window
3050 margins will fix that. */
3051 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
3052 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
3054 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
3056 wset_left_margin_cols (w
, make_number (margin_cols
/ 2));
3057 wset_right_margin_cols (w
, make_number (margin_cols
/ 2));
3060 wset_right_margin_cols (w
, make_number (margin_cols
));
3063 wset_left_margin_cols (w
, make_number (margin_cols
));
3067 /* The following three routines are needed for running a window's
3068 configuration change hook. */
3070 run_funs (Lisp_Object funs
)
3072 for (; CONSP (funs
); funs
= XCDR (funs
))
3073 if (!EQ (XCAR (funs
), Qt
))
3074 call0 (XCAR (funs
));
3078 select_window_norecord (Lisp_Object window
)
3080 return WINDOW_LIVE_P (window
)
3081 ? Fselect_window (window
, Qt
) : selected_window
;
3085 select_frame_norecord (Lisp_Object frame
)
3087 return FRAME_LIVE_P (XFRAME (frame
))
3088 ? Fselect_frame (frame
, Qt
) : selected_frame
;
3092 run_window_configuration_change_hook (struct frame
*f
)
3094 ptrdiff_t count
= SPECPDL_INDEX ();
3095 Lisp_Object frame
, global_wcch
3096 = Fdefault_value (Qwindow_configuration_change_hook
);
3097 XSETFRAME (frame
, f
);
3099 if (NILP (Vrun_hooks
) || !NILP (inhibit_lisp_code
))
3102 /* Use the right buffer. Matters when running the local hooks. */
3103 if (current_buffer
!= XBUFFER (Fwindow_buffer (Qnil
)))
3105 record_unwind_current_buffer ();
3106 Fset_buffer (Fwindow_buffer (Qnil
));
3109 if (SELECTED_FRAME () != f
)
3111 record_unwind_protect (select_frame_norecord
, Fselected_frame ());
3112 select_frame_norecord (frame
);
3115 /* Look for buffer-local values. */
3117 Lisp_Object windows
= Fwindow_list (frame
, Qlambda
, Qnil
);
3118 for (; CONSP (windows
); windows
= XCDR (windows
))
3120 Lisp_Object window
= XCAR (windows
);
3121 Lisp_Object buffer
= Fwindow_buffer (window
);
3122 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook
,
3125 ptrdiff_t inner_count
= SPECPDL_INDEX ();
3126 record_unwind_protect (select_window_norecord
, Fselected_window ());
3127 select_window_norecord (window
);
3128 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook
,
3130 unbind_to (inner_count
, Qnil
);
3135 run_funs (global_wcch
);
3136 unbind_to (count
, Qnil
);
3139 DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook
,
3140 Srun_window_configuration_change_hook
, 0, 1, 0,
3141 doc
: /* Run `window-configuration-change-hook' for FRAME.
3142 If FRAME is omitted or nil, it defaults to the selected frame. */)
3145 run_window_configuration_change_hook (decode_live_frame (frame
));
3149 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
3150 means it's allowed to run hooks. See make_frame for a case where
3151 it's not allowed. KEEP_MARGINS_P non-zero means that the current
3152 margins, fringes, and scroll-bar settings of the window are not
3153 reset from the buffer's local settings. */
3156 set_window_buffer (Lisp_Object window
, Lisp_Object buffer
,
3157 bool run_hooks_p
, bool keep_margins_p
)
3159 struct window
*w
= XWINDOW (window
);
3160 struct buffer
*b
= XBUFFER (buffer
);
3161 ptrdiff_t count
= SPECPDL_INDEX ();
3162 int samebuf
= EQ (buffer
, w
->buffer
);
3164 wset_buffer (w
, buffer
);
3166 if (EQ (window
, selected_window
))
3167 bset_last_selected_window (b
, window
);
3169 /* Let redisplay errors through. */
3170 b
->display_error_modiff
= 0;
3172 /* Update time stamps of buffer display. */
3173 if (INTEGERP (BVAR (b
, display_count
)))
3174 bset_display_count (b
, make_number (XINT (BVAR (b
, display_count
)) + 1));
3175 bset_display_time (b
, Fcurrent_time ());
3177 wset_window_end_pos (w
, make_number (0));
3178 wset_window_end_vpos (w
, make_number (0));
3179 memset (&w
->last_cursor
, 0, sizeof w
->last_cursor
);
3181 if (!(keep_margins_p
&& samebuf
))
3182 { /* If we're not actually changing the buffer, don't reset hscroll and
3183 vscroll. This case happens for example when called from
3184 change_frame_size_1, where we use a dummy call to
3185 Fset_window_buffer on the frame's selected window (and no other)
3186 just in order to run window-configuration-change-hook.
3187 Resetting hscroll and vscroll here is problematic for things like
3188 image-mode and doc-view-mode since it resets the image's position
3189 whenever we resize the frame. */
3190 w
->hscroll
= w
->min_hscroll
= 0;
3192 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3193 set_marker_restricted (w
->start
,
3194 make_number (b
->last_window_start
),
3196 w
->start_at_line_beg
= 0;
3198 w
->last_modified
= 0;
3199 w
->last_overlay_modified
= 0;
3201 /* Maybe we could move this into the `if' but it's not obviously safe and
3202 I doubt it's worth the trouble. */
3203 windows_or_buffers_changed
++;
3205 /* We must select BUFFER for running the window-scroll-functions. */
3206 /* We can't check ! NILP (Vwindow_scroll_functions) here
3207 because that might itself be a local variable. */
3208 if (window_initialized
)
3210 record_unwind_current_buffer ();
3211 Fset_buffer (buffer
);
3214 XMARKER (w
->pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3216 if (!keep_margins_p
)
3218 /* Set left and right marginal area width etc. from buffer. */
3220 /* This may call adjust_window_margins three times, so
3221 temporarily disable window margins. */
3222 Lisp_Object save_left
= w
->left_margin_cols
;
3223 Lisp_Object save_right
= w
->right_margin_cols
;
3225 wset_left_margin_cols (w
, Qnil
);
3226 wset_right_margin_cols (w
, Qnil
);
3228 Fset_window_fringes (window
,
3229 BVAR (b
, left_fringe_width
), BVAR (b
, right_fringe_width
),
3230 BVAR (b
, fringes_outside_margins
));
3232 Fset_window_scroll_bars (window
,
3233 BVAR (b
, scroll_bar_width
),
3234 BVAR (b
, vertical_scroll_bar_type
), Qnil
);
3236 wset_left_margin_cols (w
, save_left
);
3237 wset_right_margin_cols (w
, save_right
);
3239 Fset_window_margins (window
,
3240 BVAR (b
, left_margin_cols
), BVAR (b
, right_margin_cols
));
3245 if (! NILP (Vwindow_scroll_functions
))
3246 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3247 Fmarker_position (w
->start
));
3248 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w
)));
3251 unbind_to (count
, Qnil
);
3254 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3255 doc
: /* Make WINDOW display BUFFER-OR-NAME as its contents.
3256 WINDOW must be a live window and defaults to the selected one.
3257 BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
3259 Optional third argument KEEP-MARGINS non-nil means that WINDOW's current
3260 display margins, fringe widths, and scroll bar settings are preserved;
3261 the default is to reset these from the local settings for BUFFER-OR-NAME
3262 or the frame defaults. Return nil.
3264 This function throws an error when WINDOW is strongly dedicated to its
3265 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3266 already display BUFFER-OR-NAME.
3268 This function runs `window-scroll-functions' before running
3269 `window-configuration-change-hook'. */)
3270 (register Lisp_Object window
, Lisp_Object buffer_or_name
, Lisp_Object keep_margins
)
3272 register Lisp_Object tem
, buffer
;
3273 register struct window
*w
= decode_live_window (window
);
3275 XSETWINDOW (window
, w
);
3276 buffer
= Fget_buffer (buffer_or_name
);
3277 CHECK_BUFFER (buffer
);
3278 if (!BUFFER_LIVE_P (XBUFFER (buffer
)))
3279 error ("Attempt to display deleted buffer");
3283 error ("Window is deleted");
3286 if (!EQ (tem
, buffer
))
3288 if (EQ (w
->dedicated
, Qt
))
3289 /* WINDOW is strongly dedicated to its buffer, signal an
3291 error ("Window is dedicated to `%s'", SDATA (BVAR (XBUFFER (tem
), name
)));
3293 /* WINDOW is weakly dedicated to its buffer, reset
3295 wset_dedicated (w
, Qnil
);
3297 call1 (Qrecord_window_buffer
, window
);
3303 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3309 display_buffer (Lisp_Object buffer
, Lisp_Object not_this_window_p
, Lisp_Object override_frame
)
3311 return call3 (Qdisplay_buffer
, buffer
, not_this_window_p
, override_frame
);
3314 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3316 doc
: /* Force all windows to be updated on next redisplay.
3317 If optional arg OBJECT is a window, force redisplay of that window only.
3318 If OBJECT is a buffer or buffer name, force redisplay of all windows
3319 displaying that buffer. */)
3320 (Lisp_Object object
)
3324 windows_or_buffers_changed
++;
3325 update_mode_lines
++;
3329 if (WINDOWP (object
))
3331 struct window
*w
= XWINDOW (object
);
3332 mark_window_display_accurate (object
, 0);
3333 w
->update_mode_line
= 1;
3334 if (BUFFERP (w
->buffer
))
3335 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
3336 ++update_mode_lines
;
3340 if (STRINGP (object
))
3341 object
= Fget_buffer (object
);
3342 if (BUFFERP (object
) && BUFFER_LIVE_P (XBUFFER (object
))
3343 && buffer_window_count (XBUFFER (object
)))
3345 /* If buffer is live and shown in at least one window, find
3346 all windows showing this buffer and force update of them. */
3347 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3348 return NILP (object
) ? Qnil
: Qt
;
3351 /* If nothing suitable was found, just return.
3352 We could signal an error, but this feature will typically be used
3353 asynchronously in timers or process sentinels, so we don't. */
3357 /* Obsolete since 24.3. */
3359 temp_output_buffer_show (register Lisp_Object buf
)
3361 register struct buffer
*old
= current_buffer
;
3362 register Lisp_Object window
;
3363 register struct window
*w
;
3365 bset_directory (XBUFFER (buf
), BVAR (current_buffer
, directory
));
3368 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3372 set_buffer_internal (old
);
3374 if (!NILP (Vtemp_buffer_show_function
))
3375 call1 (Vtemp_buffer_show_function
, buf
);
3378 window
= display_buffer (buf
, Qnil
, Qnil
);
3380 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3381 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3382 Vminibuf_scroll_window
= window
;
3383 w
= XWINDOW (window
);
3386 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3387 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3389 /* Run temp-buffer-show-hook, with the chosen window selected
3390 and its buffer current. */
3392 ptrdiff_t count
= SPECPDL_INDEX ();
3393 Lisp_Object prev_window
, prev_buffer
;
3394 prev_window
= selected_window
;
3395 XSETBUFFER (prev_buffer
, old
);
3397 /* Select the window that was chosen, for running the hook.
3398 Note: Both Fselect_window and select_window_norecord may
3399 set-buffer to the buffer displayed in the window,
3400 so we need to save the current buffer. --stef */
3401 record_unwind_protect (Fset_buffer
, prev_buffer
);
3402 record_unwind_protect (select_window_norecord
, prev_window
);
3403 Fselect_window (window
, Qt
);
3404 Fset_buffer (w
->buffer
);
3405 Frun_hooks (1, &Qtemp_buffer_show_hook
);
3406 unbind_to (count
, Qnil
);
3411 /* Make new window, have it replace WINDOW in window-tree, and make
3412 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
3413 horizontal child). */
3415 make_parent_window (Lisp_Object window
, bool horflag
)
3418 register struct window
*o
, *p
;
3420 o
= XWINDOW (window
);
3421 p
= allocate_window ();
3422 memcpy ((char *) p
+ sizeof (struct vectorlike_header
),
3423 (char *) o
+ sizeof (struct vectorlike_header
),
3424 word_size
* VECSIZE (struct window
));
3425 /* P's buffer slot may change from nil to a buffer. */
3426 adjust_window_count (p
, 1);
3427 XSETWINDOW (parent
, p
);
3429 replace_window (window
, parent
, 1);
3431 wset_next (o
, Qnil
);
3432 wset_prev (o
, Qnil
);
3433 wset_parent (o
, parent
);
3435 wset_hchild (p
, horflag
? window
: Qnil
);
3436 wset_vchild (p
, horflag
? Qnil
: window
);
3437 wset_start (p
, Qnil
);
3438 wset_pointm (p
, Qnil
);
3439 wset_buffer (p
, Qnil
);
3440 wset_combination_limit (p
, Qnil
);
3441 wset_window_parameters (p
, Qnil
);
3444 /* Make new window from scratch. */
3449 register struct window
*w
;
3451 w
= allocate_window ();
3452 /* Initialize Lisp data. Note that allocate_window initializes all
3453 Lisp data to nil, so do it only for slots which should not be nil. */
3454 wset_normal_lines (w
, make_float (1.0));
3455 wset_normal_cols (w
, make_float (1.0));
3456 wset_new_total (w
, make_number (0));
3457 wset_new_normal (w
, make_number (0));
3458 wset_start (w
, Fmake_marker ());
3459 wset_pointm (w
, Fmake_marker ());
3460 wset_vertical_scroll_bar_type (w
, Qt
);
3461 wset_window_end_pos (w
, make_number (0));
3462 wset_window_end_vpos (w
, make_number (0));
3463 /* These Lisp fields are marked specially so they're not set to nil by
3465 wset_prev_buffers (w
, Qnil
);
3466 wset_next_buffers (w
, Qnil
);
3468 /* Initialize non-Lisp data. Note that allocate_window zeroes out all
3469 non-Lisp data, so do it only for slots which should not be zero. */
3470 w
->nrows_scale_factor
= w
->ncols_scale_factor
= 1;
3471 w
->phys_cursor_type
= -1;
3472 w
->phys_cursor_width
= -1;
3473 w
->column_number_displayed
= -1;
3475 /* Reset window_list. */
3476 Vwindow_list
= Qnil
;
3477 /* Return window. */
3478 XSETWINDOW (window
, w
);
3482 DEFUN ("set-window-new-total", Fset_window_new_total
, Sset_window_new_total
, 2, 3, 0,
3483 doc
: /* Set new total size of WINDOW to SIZE.
3484 WINDOW must be a valid window and defaults to the selected one.
3487 Optional argument ADD non-nil means add SIZE to the new total size of
3488 WINDOW and return the sum.
3490 Note: This function does not operate on any child windows of WINDOW. */)
3491 (Lisp_Object window
, Lisp_Object size
, Lisp_Object add
)
3493 struct window
*w
= decode_valid_window (window
);
3495 CHECK_NUMBER (size
);
3497 wset_new_total (w
, size
);
3499 wset_new_total (w
, make_number (XINT (w
->new_total
) + XINT (size
)));
3501 return w
->new_total
;
3504 DEFUN ("set-window-new-normal", Fset_window_new_normal
, Sset_window_new_normal
, 1, 2, 0,
3505 doc
: /* Set new normal size of WINDOW to SIZE.
3506 WINDOW must be a valid window and defaults to the selected one.
3509 Note: This function does not operate on any child windows of WINDOW. */)
3510 (Lisp_Object window
, Lisp_Object size
)
3512 wset_new_normal (decode_valid_window (window
), size
);
3516 /* Return 1 if setting w->total_lines (w->total_cols if HORFLAG is
3517 non-zero) to w->new_total would result in correct heights (widths)
3518 for window W and recursively all child windows of W.
3520 Note: This function does not check any of `window-fixed-size-p',
3521 `window-min-height' or `window-min-width'. It does check that window
3522 sizes do not drop below one line (two columns). */
3524 window_resize_check (struct window
*w
, bool horflag
)
3528 if (!NILP (w
->vchild
))
3529 /* W is a vertical combination. */
3531 c
= XWINDOW (w
->vchild
);
3533 /* All child windows of W must have the same width as W. */
3537 if ((XINT (c
->new_total
) != XINT (w
->new_total
))
3538 || !window_resize_check (c
, horflag
))
3540 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3545 /* The sum of the heights of the child windows of W must equal
3548 int sum_of_sizes
= 0;
3551 if (!window_resize_check (c
, horflag
))
3553 sum_of_sizes
= sum_of_sizes
+ XINT (c
->new_total
);
3554 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3556 return (sum_of_sizes
== XINT (w
->new_total
));
3559 else if (!NILP (w
->hchild
))
3560 /* W is a horizontal combination. */
3562 c
= XWINDOW (w
->hchild
);
3564 /* The sum of the widths of the child windows of W must equal W's
3567 int sum_of_sizes
= 0;
3570 if (!window_resize_check (c
, horflag
))
3572 sum_of_sizes
= sum_of_sizes
+ XINT (c
->new_total
);
3573 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3575 return (sum_of_sizes
== XINT (w
->new_total
));
3578 /* All child windows of W must have the same height as W. */
3582 if ((XINT (c
->new_total
) != XINT (w
->new_total
))
3583 || !window_resize_check (c
, horflag
))
3585 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3591 /* A leaf window. Make sure it's not too small. The following
3592 hardcodes the values of `window-safe-min-width' (2) and
3593 `window-safe-min-height' (1) which are defined in window.el. */
3594 return XINT (w
->new_total
) >= (horflag
? 2 : 1);
3597 /* Set w->total_lines (w->total_cols if HORIZONTAL is non-zero) to
3598 w->new_total for window W and recursively all child windows of W.
3599 Also calculate and assign the new vertical (horizontal) start
3600 positions of each of these windows.
3602 This function does not perform any error checks. Make sure you have
3603 run window_resize_check on W before applying this function. */
3605 window_resize_apply (struct window
*w
, bool horflag
)
3610 /* Note: Assigning new_normal requires that the new total size of the
3611 parent window has been set *before*. */
3614 w
->total_cols
= XFASTINT (w
->new_total
);
3615 if (NUMBERP (w
->new_normal
))
3616 wset_normal_cols (w
, w
->new_normal
);
3622 w
->total_lines
= XFASTINT (w
->new_total
);
3623 if (NUMBERP (w
->new_normal
))
3624 wset_normal_lines (w
, w
->new_normal
);
3629 if (!NILP (w
->vchild
))
3630 /* W is a vertical combination. */
3632 c
= XWINDOW (w
->vchild
);
3639 window_resize_apply (c
, horflag
);
3641 pos
= pos
+ c
->total_lines
;
3642 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3645 else if (!NILP (w
->hchild
))
3646 /* W is a horizontal combination. */
3648 c
= XWINDOW (w
->hchild
);
3655 window_resize_apply (c
, horflag
);
3657 pos
= pos
+ c
->total_cols
;
3658 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3662 /* Clear out some redisplay caches. */
3663 w
->last_modified
= 0;
3664 w
->last_overlay_modified
= 0;
3668 DEFUN ("window-resize-apply", Fwindow_resize_apply
, Swindow_resize_apply
, 0, 2, 0,
3669 doc
: /* Apply requested size values for window-tree of FRAME.
3670 If FRAME is omitted or nil, it defaults to the selected frame.
3672 Optional argument HORIZONTAL omitted or nil means apply requested
3673 height values. HORIZONTAL non-nil means apply requested width values.
3675 This function checks whether the requested values sum up to a valid
3676 window layout, recursively assigns the new sizes of all child windows
3677 and calculates and assigns the new start positions of these windows.
3679 Note: This function does not check any of `window-fixed-size-p',
3680 `window-min-height' or `window-min-width'. All these checks have to
3681 be applied on the Elisp level. */)
3682 (Lisp_Object frame
, Lisp_Object horizontal
)
3684 struct frame
*f
= decode_live_frame (frame
);
3685 struct window
*r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3686 bool horflag
= !NILP (horizontal
);
3688 if (!window_resize_check (r
, horflag
)
3689 || (XINT (r
->new_total
)
3690 != (horflag
? r
->total_cols
: r
->total_lines
)))
3694 window_resize_apply (r
, horflag
);
3696 windows_or_buffers_changed
++;
3697 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3702 run_window_configuration_change_hook (f
);
3708 /* Resize frame F's windows when number of lines of F is set to SIZE.
3709 HORFLAG 1 means resize windows when number of columns of F is set to
3712 This function can delete all windows but the selected one in order to
3713 satisfy the request. The result will be meaningful if and only if
3714 F's windows have meaningful sizes when you call this. */
3716 resize_frame_windows (struct frame
*f
, int size
, bool horflag
)
3718 Lisp_Object root
= f
->root_window
;
3719 struct window
*r
= XWINDOW (root
);
3720 Lisp_Object mini
= f
->minibuffer_window
;
3722 /* new_size is the new size of the frame's root window. */
3723 int new_size
= (horflag
3726 - FRAME_TOP_MARGIN (f
)
3727 - ((FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
3730 r
->top_line
= FRAME_TOP_MARGIN (f
);
3731 if (NILP (r
->vchild
) && NILP (r
->hchild
))
3732 /* For a leaf root window just set the size. */
3734 r
->total_cols
= new_size
;
3736 r
->total_lines
= new_size
;
3739 /* old_size is the old size of the frame's root window. */
3740 int old_size
= horflag
? r
->total_cols
: r
->total_lines
;
3743 XSETINT (delta
, new_size
- old_size
);
3744 /* Try a "normal" resize first. */
3745 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qnil
);
3746 if (window_resize_check (r
, horflag
)
3747 && new_size
== XINT (r
->new_total
))
3748 window_resize_apply (r
, horflag
);
3751 /* Try with "reasonable" minimum sizes next. */
3752 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qt
);
3753 if (window_resize_check (r
, horflag
)
3754 && new_size
== XINT (r
->new_total
))
3755 window_resize_apply (r
, horflag
);
3758 /* Finally, try with "safe" minimum sizes. */
3759 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qsafe
);
3760 if (window_resize_check (r
, horflag
)
3761 && new_size
== XINT (r
->new_total
))
3762 window_resize_apply (r
, horflag
);
3765 /* We lost. Delete all windows but the frame's
3767 root
= f
->selected_window
;
3768 Fdelete_other_windows_internal (root
, Qnil
);
3770 XWINDOW (root
)->total_cols
= new_size
;
3772 XWINDOW (root
)->total_lines
= new_size
;
3778 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
3782 m
->total_cols
= size
;
3785 /* Are we sure we always want 1 line here? */
3787 m
->top_line
= r
->top_line
+ r
->total_lines
;
3791 windows_or_buffers_changed
++;
3795 DEFUN ("split-window-internal", Fsplit_window_internal
, Ssplit_window_internal
, 4, 4, 0,
3796 doc
: /* Split window OLD.
3797 Second argument TOTAL-SIZE specifies the number of lines or columns of the
3798 new window. In any case TOTAL-SIZE must be a positive integer.
3800 Third argument SIDE nil (or `below') specifies that the new window shall
3801 be located below WINDOW. SIDE `above' means the new window shall be
3802 located above WINDOW. In both cases TOTAL-SIZE specifies the number of
3803 lines of the new window including space reserved for the mode and/or
3806 SIDE t (or `right') specifies that the new window shall be located on
3807 the right side of WINDOW. SIDE `left' means the new window shall be
3808 located on the left of WINDOW. In both cases TOTAL-SIZE specifies the
3809 number of columns of the new window including space reserved for fringes
3810 and the scrollbar or a divider column.
3812 Fourth argument NORMAL-SIZE specifies the normal size of the new window
3813 according to the SIDE argument.
3815 The new total and normal sizes of all involved windows must have been
3816 set correctly. See the code of `split-window' for how this is done. */)
3817 (Lisp_Object old
, Lisp_Object total_size
, Lisp_Object side
, Lisp_Object normal_size
)
3819 /* OLD (*o) is the window we have to split. (*p) is either OLD's
3820 parent window or an internal window we have to install as OLD's new
3821 parent. REFERENCE (*r) must denote a live window, or is set to OLD
3822 provided OLD is a leaf window, or to the frame's selected window.
3823 NEW (*n) is the new window created with some parameters taken from
3825 register Lisp_Object
new, frame
, reference
;
3826 register struct window
*o
, *p
, *n
, *r
;
3829 /* HORFLAG is 1 when we split side-by-side, 0 otherwise. */
3830 = EQ (side
, Qt
) || EQ (side
, Qleft
) || EQ (side
, Qright
);
3831 int combination_limit
= 0;
3835 frame
= WINDOW_FRAME (o
);
3838 CHECK_NUMBER (total_size
);
3840 /* Set combination_limit to 1 if we have to make a new parent window.
3841 We do that if either `window-combination-limit' is t, or OLD has no
3842 parent, or OLD is ortho-combined. */
3844 EQ (Vwindow_combination_limit
, Qt
)
3847 ? (XWINDOW (o
->parent
)->hchild
)
3848 : (XWINDOW (o
->parent
)->vchild
));
3850 /* We need a live reference window to initialize some parameters. */
3851 if (WINDOW_LIVE_P (old
))
3852 /* OLD is live, use it as reference window. */
3855 /* Use the frame's selected window as reference window. */
3856 reference
= FRAME_SELECTED_WINDOW (f
);
3857 r
= XWINDOW (reference
);
3859 /* The following bugs are caught by `split-window'. */
3860 if (MINI_WINDOW_P (o
))
3861 error ("Attempt to split minibuffer window");
3862 else if (XINT (total_size
) < (horflag
? 2 : 1))
3863 error ("Size of new window too small (after split)");
3864 else if (!combination_limit
&& !NILP (Vwindow_combination_resize
))
3865 /* `window-combination-resize' non-nil means try to resize OLD's siblings
3868 p
= XWINDOW (o
->parent
);
3869 /* Temporarily pretend we split the parent window. */
3871 (p
, make_number ((horflag
? p
->total_cols
: p
->total_lines
)
3872 - XINT (total_size
)));
3873 if (!window_resize_check (p
, horflag
))
3874 error ("Window sizes don't fit");
3876 /* Undo the temporary pretension. */
3877 wset_new_total (p
, make_number
3878 (horflag
? p
->total_cols
: p
->total_lines
));
3882 if (!window_resize_check (o
, horflag
))
3883 error ("Resizing old window failed");
3884 else if (XINT (total_size
) + XINT (o
->new_total
)
3885 != (horflag
? o
->total_cols
: o
->total_lines
))
3886 error ("Sum of sizes of old and new window don't fit");
3889 /* This is our point of no return. */
3890 if (combination_limit
)
3892 /* Save the old value of o->normal_cols/lines. It gets corrupted
3893 by make_parent_window and we need it below for assigning it to
3895 Lisp_Object new_normal
3896 = horflag
? o
->normal_cols
: o
->normal_lines
;
3898 make_parent_window (old
, horflag
);
3899 p
= XWINDOW (o
->parent
);
3900 if (EQ (Vwindow_combination_limit
, Qt
))
3901 /* Store t in the new parent's combination_limit slot to avoid
3902 that its children get merged into another window. */
3903 wset_combination_limit (p
, Qt
);
3904 /* These get applied below. */
3905 wset_new_total (p
, make_number
3906 (horflag
? o
->total_cols
: o
->total_lines
));
3907 wset_new_normal (p
, new_normal
);
3910 p
= XWINDOW (o
->parent
);
3912 windows_or_buffers_changed
++;
3913 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3914 new = make_window ();
3916 wset_frame (n
, frame
);
3917 wset_parent (n
, o
->parent
);
3918 wset_vchild (n
, Qnil
);
3919 wset_hchild (n
, Qnil
);
3921 if (EQ (side
, Qabove
) || EQ (side
, Qleft
))
3923 wset_prev (n
, o
->prev
);
3926 wset_hchild (p
, new);
3928 wset_vchild (p
, new);
3930 wset_next (XWINDOW (n
->prev
), new);
3936 wset_next (n
, o
->next
);
3937 if (!NILP (n
->next
))
3938 wset_prev (XWINDOW (n
->next
), new);
3943 n
->window_end_valid
= 0;
3944 memset (&n
->last_cursor
, 0, sizeof n
->last_cursor
);
3946 /* Get special geometry settings from reference window. */
3947 wset_left_margin_cols (n
, r
->left_margin_cols
);
3948 wset_right_margin_cols (n
, r
->right_margin_cols
);
3949 wset_left_fringe_width (n
, r
->left_fringe_width
);
3950 wset_right_fringe_width (n
, r
->right_fringe_width
);
3951 n
->fringes_outside_margins
= r
->fringes_outside_margins
;
3952 wset_scroll_bar_width (n
, r
->scroll_bar_width
);
3953 wset_vertical_scroll_bar_type (n
, r
->vertical_scroll_bar_type
);
3955 /* Directly assign orthogonal coordinates and sizes. */
3958 n
->top_line
= o
->top_line
;
3959 n
->total_lines
= o
->total_lines
;
3963 n
->left_col
= o
->left_col
;
3964 n
->total_cols
= o
->total_cols
;
3967 /* Iso-coordinates and sizes are assigned by window_resize_apply,
3968 get them ready here. */
3969 wset_new_total (n
, total_size
);
3970 wset_new_normal (n
, normal_size
);
3973 window_resize_apply (p
, horflag
);
3975 /* Set buffer of NEW to buffer of reference window. Don't run
3977 set_window_buffer (new, r
->buffer
, 0, 1);
3980 /* Maybe we should run the scroll functions in Elisp (which already
3981 runs the configuration change hook). */
3982 if (! NILP (Vwindow_scroll_functions
))
3983 run_hook_with_args_2 (Qwindow_scroll_functions
, new,
3984 Fmarker_position (n
->start
));
3990 DEFUN ("delete-window-internal", Fdelete_window_internal
, Sdelete_window_internal
, 1, 1, 0,
3991 doc
: /* Remove WINDOW from its frame.
3992 WINDOW defaults to the selected window. Return nil.
3993 Signal an error when WINDOW is the only window on its frame. */)
3994 (register Lisp_Object window
)
3996 register Lisp_Object parent
, sibling
, frame
, root
;
3997 struct window
*w
, *p
, *s
, *r
;
4000 int before_sibling
= 0;
4002 w
= decode_any_window (window
);
4003 XSETWINDOW (window
, w
);
4004 if (NILP (w
->buffer
)
4005 && NILP (w
->hchild
) && NILP (w
->vchild
))
4006 /* It's a no-op to delete an already deleted window. */
4011 /* Never delete a minibuffer or frame root window. */
4012 error ("Attempt to delete minibuffer or sole ordinary window");
4013 else if (NILP (w
->prev
) && NILP (w
->next
))
4014 /* Rather bow out here, this case should be handled on the Elisp
4016 error ("Attempt to delete sole window of parent");
4018 p
= XWINDOW (parent
);
4019 horflag
= NILP (p
->vchild
);
4021 frame
= WINDOW_FRAME (w
);
4024 root
= FRAME_ROOT_WINDOW (f
);
4027 /* Unlink WINDOW from window tree. */
4029 /* Get SIBLING below (on the right of) WINDOW. */
4031 /* before_sibling 1 means WINDOW is the first child of its
4032 parent and thus before the sibling. */
4035 s
= XWINDOW (sibling
);
4036 wset_prev (s
, Qnil
);
4038 wset_hchild (p
, sibling
);
4040 wset_vchild (p
, sibling
);
4043 /* Get SIBLING above (on the left of) WINDOW. */
4046 s
= XWINDOW (sibling
);
4047 wset_next (s
, w
->next
);
4048 if (!NILP (s
->next
))
4049 wset_prev (XWINDOW (s
->next
), sibling
);
4052 if (window_resize_check (r
, horflag
)
4053 && (XINT (r
->new_total
)
4054 == (horflag
? r
->total_cols
: r
->total_lines
)))
4055 /* We can delete WINDOW now. */
4060 #ifdef HAVE_XWIDGETS
4061 xwidget_view_delete_all_in_window(w
);
4063 window_resize_apply (p
, horflag
);
4065 /* If this window is referred to by the dpyinfo's mouse
4066 highlight, invalidate that slot to be safe (Bug#9904). */
4067 if (!FRAME_INITIAL_P (f
))
4069 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
4071 if (EQ (hlinfo
->mouse_face_window
, window
))
4072 hlinfo
->mouse_face_window
= Qnil
;
4075 windows_or_buffers_changed
++;
4076 Vwindow_list
= Qnil
;
4077 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4079 wset_next (w
, Qnil
); /* Don't delete w->next too. */
4080 free_window_matrices (w
);
4082 if (!NILP (w
->vchild
))
4084 delete_all_child_windows (w
->vchild
);
4085 wset_vchild (w
, Qnil
);
4087 else if (!NILP (w
->hchild
))
4089 delete_all_child_windows (w
->hchild
);
4090 wset_hchild (w
, Qnil
);
4092 else if (!NILP (w
->buffer
))
4095 unchain_marker (XMARKER (w
->pointm
));
4096 unchain_marker (XMARKER (w
->start
));
4097 wset_buffer (w
, Qnil
);
4100 if (NILP (s
->prev
) && NILP (s
->next
))
4101 /* A matrjoshka where SIBLING has become the only child of
4104 /* Put SIBLING into PARENT's place. */
4105 replace_window (parent
, sibling
, 0);
4106 /* Have SIBLING inherit the following three slot values from
4107 PARENT (the combination_limit slot is not inherited). */
4108 wset_normal_cols (s
, p
->normal_cols
);
4109 wset_normal_lines (s
, p
->normal_lines
);
4110 /* Mark PARENT as deleted. */
4111 wset_vchild (p
, Qnil
);
4112 wset_hchild (p
, Qnil
);
4113 /* Try to merge SIBLING into its new parent. */
4114 recombine_windows (sibling
);
4119 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f
)))
4120 /* We deleted the frame's selected window. */
4122 /* Use the frame's first window as fallback ... */
4123 Lisp_Object new_selected_window
= Fframe_first_window (frame
);
4124 /* ... but preferably use its most recently used window. */
4125 Lisp_Object mru_window
;
4127 /* `get-mru-window' might fail for some reason so play it safe
4128 - promote the first window _without recording it_ first. */
4129 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4130 Fselect_window (new_selected_window
, Qt
);
4132 fset_selected_window (f
, new_selected_window
);
4136 /* Now look whether `get-mru-window' gets us something. */
4137 mru_window
= call1 (Qget_mru_window
, frame
);
4138 if (WINDOW_LIVE_P (mru_window
)
4139 && EQ (XWINDOW (mru_window
)->frame
, frame
))
4140 new_selected_window
= mru_window
;
4142 /* If all ended up well, we now promote the mru window. */
4143 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4144 Fselect_window (new_selected_window
, Qnil
);
4146 fset_selected_window (f
, new_selected_window
);
4151 /* Must be run by the caller:
4152 run_window_configuration_change_hook (f); */
4155 /* We failed: Relink WINDOW into window tree. */
4159 wset_prev (s
, window
);
4161 wset_hchild (p
, window
);
4163 wset_vchild (p
, window
);
4167 wset_next (s
, window
);
4168 if (!NILP (w
->next
))
4169 wset_prev (XWINDOW (w
->next
), window
);
4171 error ("Deletion failed");
4177 /***********************************************************************
4178 Resizing Mini-Windows
4179 ***********************************************************************/
4181 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we
4184 grow_mini_window (struct window
*w
, int delta
)
4186 struct frame
*f
= XFRAME (w
->frame
);
4188 Lisp_Object root
, value
;
4190 eassert (MINI_WINDOW_P (w
));
4191 eassert (delta
>= 0);
4193 root
= FRAME_ROOT_WINDOW (f
);
4195 value
= call2 (Qwindow_resize_root_window_vertically
,
4196 root
, make_number (- delta
));
4197 if (INTEGERP (value
) && window_resize_check (r
, 0))
4200 window_resize_apply (r
, 0);
4202 /* Grow the mini-window. */
4203 w
->top_line
= r
->top_line
+ r
->total_lines
;
4204 w
->total_lines
-= XINT (value
);
4205 w
->last_modified
= 0;
4206 w
->last_overlay_modified
= 0;
4208 windows_or_buffers_changed
++;
4215 /* Shrink mini-window W. */
4217 shrink_mini_window (struct window
*w
)
4219 struct frame
*f
= XFRAME (w
->frame
);
4221 Lisp_Object root
, value
;
4224 eassert (MINI_WINDOW_P (w
));
4226 size
= w
->total_lines
;
4229 root
= FRAME_ROOT_WINDOW (f
);
4231 value
= call2 (Qwindow_resize_root_window_vertically
,
4232 root
, make_number (size
- 1));
4233 if (INTEGERP (value
) && window_resize_check (r
, 0))
4236 window_resize_apply (r
, 0);
4238 /* Shrink the mini-window. */
4239 w
->top_line
= r
->top_line
+ r
->total_lines
;
4242 w
->last_modified
= 0;
4243 w
->last_overlay_modified
= 0;
4245 windows_or_buffers_changed
++;
4249 /* If the above failed for whatever strange reason we must make a
4250 one window frame here. The same routine will be needed when
4251 shrinking the frame (and probably when making the initial
4252 *scratch* window). For the moment leave things as they are. */
4256 DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal
, Sresize_mini_window_internal
, 1, 1, 0,
4257 doc
: /* Resize minibuffer window WINDOW. */)
4258 (Lisp_Object window
)
4260 struct window
*w
= XWINDOW (window
);
4265 CHECK_WINDOW (window
);
4266 f
= XFRAME (w
->frame
);
4268 if (!EQ (FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
)), window
))
4269 error ("Not a valid minibuffer window");
4270 else if (FRAME_MINIBUF_ONLY_P (f
))
4271 error ("Cannot resize a minibuffer-only frame");
4273 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4274 height
= r
->total_lines
+ w
->total_lines
;
4275 if (window_resize_check (r
, 0)
4276 && XINT (w
->new_total
) > 0
4277 && height
== XINT (r
->new_total
) + XINT (w
->new_total
))
4280 window_resize_apply (r
, 0);
4282 w
->total_lines
= XFASTINT (w
->new_total
);
4283 w
->top_line
= r
->top_line
+ r
->total_lines
;
4285 windows_or_buffers_changed
++;
4286 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4290 run_window_configuration_change_hook (f
);
4293 else error ("Failed to resize minibuffer window");
4296 /* Mark window cursors off for all windows in the window tree rooted
4297 at W by setting their phys_cursor_on_p flag to zero. Called from
4298 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4299 the frame are cleared. */
4302 mark_window_cursors_off (struct window
*w
)
4306 if (!NILP (w
->hchild
))
4307 mark_window_cursors_off (XWINDOW (w
->hchild
));
4308 else if (!NILP (w
->vchild
))
4309 mark_window_cursors_off (XWINDOW (w
->vchild
));
4311 w
->phys_cursor_on_p
= 0;
4313 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4318 /* Return number of lines of text (not counting mode lines) in W. */
4321 window_internal_height (struct window
*w
)
4323 int ht
= w
->total_lines
;
4325 if (!MINI_WINDOW_P (w
))
4327 if (!NILP (w
->parent
)
4328 || !NILP (w
->vchild
)
4329 || !NILP (w
->hchild
)
4332 || WINDOW_WANTS_MODELINE_P (w
))
4335 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4342 /************************************************************************
4344 ***********************************************************************/
4346 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4347 N screen-fulls, which is defined as the height of the window minus
4348 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4349 instead. Negative values of N mean scroll down. NOERROR non-zero
4350 means don't signal an error if we try to move over BEGV or ZV,
4354 window_scroll (Lisp_Object window
, EMACS_INT n
, int whole
, int noerror
)
4357 n
= clip_to_bounds (INT_MIN
, n
, INT_MAX
);
4359 /* If we must, use the pixel-based version which is much slower than
4360 the line-based one but can handle varying line heights. */
4361 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4362 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4364 window_scroll_line_based (window
, n
, whole
, noerror
);
4370 /* Implementation of window_scroll that works based on pixel line
4371 heights. See the comment of window_scroll for parameter
4375 window_scroll_pixel_based (Lisp_Object window
, int n
, int whole
, int noerror
)
4378 struct window
*w
= XWINDOW (window
);
4379 struct text_pos start
;
4380 int this_scroll_margin
;
4381 /* True if we fiddled the window vscroll field without really scrolling. */
4383 int x
, y
, rtop
, rbot
, rowh
, vpos
;
4384 void *itdata
= NULL
;
4386 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4387 /* Scrolling a minibuffer window via scroll bar when the echo area
4388 shows long text sometimes resets the minibuffer contents behind
4390 if (CHARPOS (start
) > ZV
)
4391 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4393 /* If PT is not visible in WINDOW, move back one half of
4394 the screen. Allow PT to be partially visible, otherwise
4395 something like (scroll-down 1) with PT in the line before
4396 the partially visible one would recenter. */
4398 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
4400 itdata
= bidi_shelve_cache ();
4401 /* Move backward half the height of the window. Performance note:
4402 vmotion used here is about 10% faster, but would give wrong
4403 results for variable height lines. */
4404 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4405 it
.current_y
= it
.last_visible_y
;
4406 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4408 /* The function move_iterator_vertically may move over more than
4409 the specified y-distance. If it->w is small, e.g. a
4410 mini-buffer window, we may end up in front of the window's
4411 display area. This is the case when Start displaying at the
4412 start of the line containing PT in this case. */
4413 if (it
.current_y
<= 0)
4415 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4416 move_it_vertically_backward (&it
, 0);
4420 start
= it
.current
.pos
;
4421 bidi_unshelve_cache (itdata
, 0);
4423 else if (auto_window_vscroll_p
)
4425 if (rtop
|| rbot
) /* partially visible */
4428 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4430 dy
= max ((window_box_height (w
)
4431 - next_screen_context_lines
* dy
),
4437 /* Only vscroll backwards if already vscrolled forwards. */
4438 if (w
->vscroll
< 0 && rtop
> 0)
4440 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
4441 Fset_window_vscroll (window
, make_number (px
), Qt
);
4447 /* Do vscroll if already vscrolled or only display line. */
4448 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
4450 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
4451 Fset_window_vscroll (window
, make_number (px
), Qt
);
4455 /* Maybe modify window start instead of scrolling. */
4456 if (rbot
> 0 || w
->vscroll
< 0)
4460 Fset_window_vscroll (window
, make_number (0), Qt
);
4461 /* If there are other text lines above the current row,
4462 move window start to current row. Else to next row. */
4464 spos
= XINT (Fline_beginning_position (Qnil
));
4466 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
4467 set_marker_restricted (w
->start
, make_number (spos
),
4469 w
->start_at_line_beg
= 1;
4470 w
->update_mode_line
= 1;
4471 w
->last_modified
= 0;
4472 w
->last_overlay_modified
= 0;
4473 /* Set force_start so that redisplay_window will run the
4474 window-scroll-functions. */
4480 /* Cancel previous vscroll. */
4481 Fset_window_vscroll (window
, make_number (0), Qt
);
4484 itdata
= bidi_shelve_cache ();
4485 /* If scroll_preserve_screen_position is non-nil, we try to set
4486 point in the same window line as it is now, so get that line. */
4487 if (!NILP (Vscroll_preserve_screen_position
))
4489 /* We preserve the goal pixel coordinate across consecutive
4490 calls to scroll-up, scroll-down and other commands that
4491 have the `scroll-command' property. This avoids the
4492 possibility of point becoming "stuck" on a tall line when
4493 scrolling by one line. */
4494 if (window_scroll_pixel_based_preserve_y
< 0
4495 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
4496 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
4498 start_display (&it
, w
, start
);
4499 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4500 window_scroll_pixel_based_preserve_y
= it
.current_y
;
4501 window_scroll_pixel_based_preserve_x
= it
.current_x
;
4505 window_scroll_pixel_based_preserve_y
4506 = window_scroll_pixel_based_preserve_x
= -1;
4508 /* Move iterator it from start the specified distance forward or
4509 backward. The result is the new window start. */
4510 start_display (&it
, w
, start
);
4513 ptrdiff_t start_pos
= IT_CHARPOS (it
);
4514 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4515 dy
= max ((window_box_height (w
)
4516 - next_screen_context_lines
* dy
),
4519 /* Note that move_it_vertically always moves the iterator to the
4520 start of a line. So, if the last line doesn't have a newline,
4521 we would end up at the start of the line ending at ZV. */
4524 move_it_vertically_backward (&it
, -dy
);
4525 /* Ensure we actually do move, e.g. in case we are currently
4526 looking at an image that is taller that the window height. */
4527 while (start_pos
== IT_CHARPOS (it
)
4528 && start_pos
> BEGV
)
4529 move_it_by_lines (&it
, -1);
4533 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4534 MOVE_TO_POS
| MOVE_TO_Y
);
4535 /* Ensure we actually do move, e.g. in case we are currently
4536 looking at an image that is taller that the window height. */
4537 while (start_pos
== IT_CHARPOS (it
)
4539 move_it_by_lines (&it
, 1);
4543 move_it_by_lines (&it
, n
);
4545 /* We failed if we find ZV is already on the screen (scrolling up,
4546 means there's nothing past the end), or if we can't start any
4547 earlier (scrolling down, means there's nothing past the top). */
4548 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4549 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4551 if (IT_CHARPOS (it
) == ZV
)
4553 if (it
.current_y
< it
.last_visible_y
4554 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4555 > it
.last_visible_y
))
4557 /* The last line was only partially visible, make it fully
4559 w
->vscroll
= (it
.last_visible_y
4560 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4561 adjust_glyphs (it
.f
);
4565 bidi_unshelve_cache (itdata
, 0);
4568 else if (n
< 0) /* could happen with empty buffers */
4569 xsignal0 (Qbeginning_of_buffer
);
4571 xsignal0 (Qend_of_buffer
);
4576 if (w
->vscroll
!= 0)
4577 /* The first line was only partially visible, make it fully
4582 bidi_unshelve_cache (itdata
, 0);
4586 xsignal0 (Qbeginning_of_buffer
);
4590 /* If control gets here, then we vscrolled. */
4592 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
4594 /* Don't try to change the window start below. */
4600 ptrdiff_t pos
= IT_CHARPOS (it
);
4603 /* If in the middle of a multi-glyph character move forward to
4604 the next character. */
4605 if (in_display_vector_p (&it
))
4608 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
4611 /* Set the window start, and set up the window for redisplay. */
4612 set_marker_restricted_both (w
->start
, w
->buffer
, IT_CHARPOS (it
),
4614 bytepos
= marker_byte_position (w
->start
);
4615 w
->start_at_line_beg
= (pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n');
4616 w
->update_mode_line
= 1;
4617 w
->last_modified
= 0;
4618 w
->last_overlay_modified
= 0;
4619 /* Set force_start so that redisplay_window will run the
4620 window-scroll-functions. */
4624 /* The rest of this function uses current_y in a nonstandard way,
4625 not including the height of the header line if any. */
4626 it
.current_y
= it
.vpos
= 0;
4628 /* Move PT out of scroll margins.
4629 This code wants current_y to be zero at the window start position
4630 even if there is a header line. */
4631 this_scroll_margin
= max (0, scroll_margin
);
4633 = min (this_scroll_margin
, w
->total_lines
/ 4);
4634 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
4638 /* We moved the window start towards ZV, so PT may be now
4639 in the scroll margin at the top. */
4640 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4641 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
4642 && (NILP (Vscroll_preserve_screen_position
)
4643 || EQ (Vscroll_preserve_screen_position
, Qt
)))
4644 /* We found PT at a legitimate height. Leave it alone. */
4646 else if (window_scroll_pixel_based_preserve_y
>= 0)
4648 /* If we have a header line, take account of it.
4649 This is necessary because we set it.current_y to 0, above. */
4650 move_it_to (&it
, -1,
4651 window_scroll_pixel_based_preserve_x
,
4652 window_scroll_pixel_based_preserve_y
4653 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
4654 -1, MOVE_TO_Y
| MOVE_TO_X
);
4655 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4659 while (it
.current_y
< this_scroll_margin
)
4661 int prev
= it
.current_y
;
4662 move_it_by_lines (&it
, 1);
4663 if (prev
== it
.current_y
)
4666 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4671 ptrdiff_t charpos
, bytepos
;
4674 /* Save our position, for the
4675 window_scroll_pixel_based_preserve_y case. */
4676 charpos
= IT_CHARPOS (it
);
4677 bytepos
= IT_BYTEPOS (it
);
4679 /* We moved the window start towards BEGV, so PT may be now
4680 in the scroll margin at the bottom. */
4681 move_it_to (&it
, PT
, -1,
4682 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
4683 - this_scroll_margin
- 1),
4685 MOVE_TO_POS
| MOVE_TO_Y
);
4687 /* Save our position, in case it's correct. */
4688 charpos
= IT_CHARPOS (it
);
4689 bytepos
= IT_BYTEPOS (it
);
4691 /* See if point is on a partially visible line at the end. */
4692 if (it
.what
== IT_EOB
)
4693 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
4696 move_it_by_lines (&it
, 1);
4697 partial_p
= it
.current_y
> it
.last_visible_y
;
4700 if (charpos
== PT
&& !partial_p
4701 && (NILP (Vscroll_preserve_screen_position
)
4702 || EQ (Vscroll_preserve_screen_position
, Qt
)))
4703 /* We found PT before we found the display margin, so PT is ok. */
4705 else if (window_scroll_pixel_based_preserve_y
>= 0)
4707 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4708 start_display (&it
, w
, start
);
4709 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
4710 here because we called start_display again and did not
4711 alter it.current_y this time. */
4712 move_it_to (&it
, -1, window_scroll_pixel_based_preserve_x
,
4713 window_scroll_pixel_based_preserve_y
, -1,
4714 MOVE_TO_Y
| MOVE_TO_X
);
4715 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4720 /* The last line was only partially visible, so back up two
4721 lines to make sure we're on a fully visible line. */
4723 move_it_by_lines (&it
, -2);
4724 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4727 /* No, the position we saved is OK, so use it. */
4728 SET_PT_BOTH (charpos
, bytepos
);
4731 bidi_unshelve_cache (itdata
, 0);
4735 /* Implementation of window_scroll that works based on screen lines.
4736 See the comment of window_scroll for parameter descriptions. */
4739 window_scroll_line_based (Lisp_Object window
, int n
, int whole
, int noerror
)
4741 register struct window
*w
= XWINDOW (window
);
4742 /* Fvertical_motion enters redisplay, which can trigger
4743 fontification, which in turn can modify buffer text (e.g., if the
4744 fontification functions replace escape sequences with faces, as
4745 in `grep-mode-font-lock-keywords'). So we use a marker to record
4746 the old point position, to prevent crashes in SET_PT_BOTH. */
4747 Lisp_Object opoint_marker
= Fpoint_marker ();
4748 register ptrdiff_t pos
, pos_byte
;
4749 register int ht
= window_internal_height (w
);
4750 register Lisp_Object tem
;
4753 ptrdiff_t startpos
= marker_position (w
->start
);
4754 ptrdiff_t startbyte
= marker_byte_position (w
->start
);
4755 Lisp_Object original_pos
= Qnil
;
4757 /* If scrolling screen-fulls, compute the number of lines to
4758 scroll from the window's height. */
4760 n
*= max (1, ht
- next_screen_context_lines
);
4762 if (!NILP (Vscroll_preserve_screen_position
))
4764 if (window_scroll_preserve_vpos
<= 0
4765 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
4766 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
4768 struct position posit
4769 = *compute_motion (startpos
, startbyte
, 0, 0, 0,
4770 PT
, ht
, 0, -1, w
->hscroll
, 0, w
);
4771 window_scroll_preserve_vpos
= posit
.vpos
;
4772 window_scroll_preserve_hpos
= posit
.hpos
+ w
->hscroll
;
4775 original_pos
= Fcons (make_number (window_scroll_preserve_hpos
),
4776 make_number (window_scroll_preserve_vpos
));
4779 XSETFASTINT (tem
, PT
);
4780 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
4784 Fvertical_motion (make_number (- (ht
/ 2)), window
);
4786 startbyte
= PT_BYTE
;
4789 SET_PT_BOTH (startpos
, startbyte
);
4790 lose
= n
< 0 && PT
== BEGV
;
4791 Fvertical_motion (make_number (n
), window
);
4795 SET_PT_BOTH (marker_position (opoint_marker
),
4796 marker_byte_position (opoint_marker
));
4803 xsignal0 (Qbeginning_of_buffer
);
4808 /* Don't use a scroll margin that is negative or too large. */
4809 int this_scroll_margin
=
4810 max (0, min (scroll_margin
, w
->total_lines
/ 4));
4812 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
4813 w
->start_at_line_beg
= !NILP (bolp
);
4814 w
->update_mode_line
= 1;
4815 w
->last_modified
= 0;
4816 w
->last_overlay_modified
= 0;
4817 /* Set force_start so that redisplay_window will run
4818 the window-scroll-functions. */
4821 if (!NILP (Vscroll_preserve_screen_position
)
4822 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
4824 SET_PT_BOTH (pos
, pos_byte
);
4825 Fvertical_motion (original_pos
, window
);
4827 /* If we scrolled forward, put point enough lines down
4828 that it is outside the scroll margin. */
4833 if (this_scroll_margin
> 0)
4835 SET_PT_BOTH (pos
, pos_byte
);
4836 Fvertical_motion (make_number (this_scroll_margin
), window
);
4842 if (top_margin
<= marker_position (opoint_marker
))
4843 SET_PT_BOTH (marker_position (opoint_marker
),
4844 marker_byte_position (opoint_marker
));
4845 else if (!NILP (Vscroll_preserve_screen_position
))
4847 SET_PT_BOTH (pos
, pos_byte
);
4848 Fvertical_motion (original_pos
, window
);
4851 SET_PT (top_margin
);
4857 /* If we scrolled backward, put point near the end of the window
4858 but not within the scroll margin. */
4859 SET_PT_BOTH (pos
, pos_byte
);
4860 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
4861 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
4864 bottom_margin
= PT
+ 1;
4866 if (bottom_margin
> marker_position (opoint_marker
))
4867 SET_PT_BOTH (marker_position (opoint_marker
),
4868 marker_byte_position (opoint_marker
));
4871 if (!NILP (Vscroll_preserve_screen_position
))
4873 SET_PT_BOTH (pos
, pos_byte
);
4874 Fvertical_motion (original_pos
, window
);
4877 Fvertical_motion (make_number (-1), window
);
4886 xsignal0 (Qend_of_buffer
);
4891 /* Scroll selected_window up or down. If N is nil, scroll a
4892 screen-full which is defined as the height of the window minus
4893 next_screen_context_lines. If N is the symbol `-', scroll.
4894 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4895 up. This is the guts of Fscroll_up and Fscroll_down. */
4898 scroll_command (Lisp_Object n
, int direction
)
4900 ptrdiff_t count
= SPECPDL_INDEX ();
4902 eassert (eabs (direction
) == 1);
4904 /* If selected window's buffer isn't current, make it current for
4905 the moment. But don't screw up if window_scroll gets an error. */
4906 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
4908 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4909 Fset_buffer (XWINDOW (selected_window
)->buffer
);
4911 /* Make redisplay consider other windows than just selected_window. */
4912 ++windows_or_buffers_changed
;
4916 window_scroll (selected_window
, direction
, 1, 0);
4917 else if (EQ (n
, Qminus
))
4918 window_scroll (selected_window
, -direction
, 1, 0);
4921 n
= Fprefix_numeric_value (n
);
4922 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
4925 unbind_to (count
, Qnil
);
4928 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "^P",
4929 doc
: /* Scroll text of selected window upward ARG lines.
4930 If ARG is omitted or nil, scroll upward by a near full screen.
4931 A near full screen is `next-screen-context-lines' less than a full screen.
4932 Negative ARG means scroll downward.
4933 If ARG is the atom `-', scroll downward by nearly full screen.
4934 When calling from a program, supply as argument a number, nil, or `-'. */)
4937 scroll_command (arg
, 1);
4941 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "^P",
4942 doc
: /* Scroll text of selected window down ARG lines.
4943 If ARG is omitted or nil, scroll down by a near full screen.
4944 A near full screen is `next-screen-context-lines' less than a full screen.
4945 Negative ARG means scroll upward.
4946 If ARG is the atom `-', scroll upward by nearly full screen.
4947 When calling from a program, supply as argument a number, nil, or `-'. */)
4950 scroll_command (arg
, -1);
4954 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
4955 doc
: /* Return the other window for \"other window scroll\" commands.
4956 If `other-window-scroll-buffer' is non-nil, a window
4957 showing that buffer is used.
4958 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4959 specifies the window. This takes precedence over
4960 `other-window-scroll-buffer'. */)
4965 if (MINI_WINDOW_P (XWINDOW (selected_window
))
4966 && !NILP (Vminibuf_scroll_window
))
4967 window
= Vminibuf_scroll_window
;
4968 /* If buffer is specified, scroll that buffer. */
4969 else if (!NILP (Vother_window_scroll_buffer
))
4971 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
4973 window
= display_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
4977 /* Nothing specified; look for a neighboring window on the same
4979 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
4981 if (EQ (window
, selected_window
))
4982 /* That didn't get us anywhere; look for a window on another
4985 window
= Fnext_window (window
, Qnil
, Qt
);
4986 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
4987 && ! EQ (window
, selected_window
));
4990 CHECK_LIVE_WINDOW (window
);
4992 if (EQ (window
, selected_window
))
4993 error ("There is no other window");
4998 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
4999 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5000 A near full screen is `next-screen-context-lines' less than a full screen.
5001 The next window is the one below the current one; or the one at the top
5002 if the current one is at the bottom. Negative ARG means scroll downward.
5003 If ARG is the atom `-', scroll downward by nearly full screen.
5004 When calling from a program, supply as argument a number, nil, or `-'.
5006 If `other-window-scroll-buffer' is non-nil, scroll the window
5007 showing that buffer, popping the buffer up if necessary.
5008 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5009 specifies the window to scroll. This takes precedence over
5010 `other-window-scroll-buffer'. */)
5015 ptrdiff_t count
= SPECPDL_INDEX ();
5017 window
= Fother_window_for_scrolling ();
5018 w
= XWINDOW (window
);
5020 /* Don't screw up if window_scroll gets an error. */
5021 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5022 ++windows_or_buffers_changed
;
5024 Fset_buffer (w
->buffer
);
5025 SET_PT_BOTH (marker_position (w
->pointm
), marker_byte_position (w
->pointm
));
5028 window_scroll (window
, 1, 1, 1);
5029 else if (EQ (arg
, Qminus
))
5030 window_scroll (window
, -1, 1, 1);
5036 window_scroll (window
, XINT (arg
), 0, 1);
5039 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5040 unbind_to (count
, Qnil
);
5045 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "^P\np",
5046 doc
: /* Scroll selected window display ARG columns left.
5047 Default for ARG is window width minus 2.
5048 Value is the total amount of leftward horizontal scrolling in
5049 effect after the change.
5050 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5051 lower bound for automatic scrolling, i.e. automatic scrolling
5052 will not scroll a window to a column less than the value returned
5053 by this function. This happens in an interactive call. */)
5054 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5056 struct window
*w
= XWINDOW (selected_window
);
5057 EMACS_INT requested_arg
= (NILP (arg
)
5058 ? window_body_cols (w
) - 2
5059 : XINT (Fprefix_numeric_value (arg
)));
5060 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
+ requested_arg
);
5062 if (!NILP (set_minimum
))
5063 w
->min_hscroll
= w
->hscroll
;
5068 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "^P\np",
5069 doc
: /* Scroll selected window display ARG columns right.
5070 Default for ARG is window width minus 2.
5071 Value is the total amount of leftward horizontal scrolling in
5072 effect after the change.
5073 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5074 lower bound for automatic scrolling, i.e. automatic scrolling
5075 will not scroll a window to a column less than the value returned
5076 by this function. This happens in an interactive call. */)
5077 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5079 struct window
*w
= XWINDOW (selected_window
);
5080 EMACS_INT requested_arg
= (NILP (arg
)
5081 ? window_body_cols (w
) - 2
5082 : XINT (Fprefix_numeric_value (arg
)));
5083 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
- requested_arg
);
5085 if (!NILP (set_minimum
))
5086 w
->min_hscroll
= w
->hscroll
;
5091 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5092 doc
: /* Return the window which was selected when entering the minibuffer.
5093 Returns nil, if selected window is not a minibuffer window. */)
5096 if (minibuf_level
> 0
5097 && MINI_WINDOW_P (XWINDOW (selected_window
))
5098 && WINDOW_LIVE_P (minibuf_selected_window
))
5099 return minibuf_selected_window
;
5104 /* Value is the number of lines actually displayed in window W,
5105 as opposed to its height. */
5108 displayed_window_lines (struct window
*w
)
5111 struct text_pos start
;
5112 ptrdiff_t charpos
= marker_position (w
->start
);
5113 int height
= window_box_height (w
);
5114 struct buffer
*old_buffer
;
5116 void *itdata
= NULL
;
5118 if (XBUFFER (w
->buffer
) != current_buffer
)
5120 old_buffer
= current_buffer
;
5121 set_buffer_internal (XBUFFER (w
->buffer
));
5126 /* In case W->start is out of the accessible range, do something
5127 reasonable. This happens in Info mode when Info-scroll-down
5128 calls (recenter -1) while W->start is 1. */
5130 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5131 else if (charpos
> ZV
)
5132 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
5134 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5136 itdata
= bidi_shelve_cache ();
5137 start_display (&it
, w
, start
);
5138 move_it_vertically (&it
, height
);
5139 bottom_y
= line_bottom_y (&it
);
5140 bidi_unshelve_cache (itdata
, 0);
5142 /* rms: On a non-window display,
5143 the value of it.vpos at the bottom of the screen
5144 seems to be 1 larger than window_box_height (w).
5145 This kludge fixes a bug whereby (move-to-window-line -1)
5146 when ZV is on the last screen line
5147 moves to the previous screen line instead of the last one. */
5148 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5151 /* Add in empty lines at the bottom of the window. */
5152 if (bottom_y
< height
)
5154 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5155 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5159 set_buffer_internal (old_buffer
);
5165 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5166 doc
: /* Center point in selected window and maybe redisplay frame.
5167 With a numeric prefix argument ARG, recenter putting point on screen line ARG
5168 relative to the selected window. If ARG is negative, it counts up from the
5169 bottom of the window. (ARG should be less than the height of the window.)
5171 If ARG is omitted or nil, then recenter with point on the middle line of
5172 the selected window; if the variable `recenter-redisplay' is non-nil,
5173 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5174 is set to `grow-only', this resets the tool-bar's height to the minimum
5175 height needed); if `recenter-redisplay' has the special value `tty',
5176 then only tty frames are redrawn.
5178 Just C-u as prefix means put point in the center of the window
5179 and redisplay normally--don't erase and redraw the frame. */)
5180 (register Lisp_Object arg
)
5182 struct window
*w
= XWINDOW (selected_window
);
5183 struct buffer
*buf
= XBUFFER (w
->buffer
);
5184 struct buffer
*obuf
= current_buffer
;
5186 ptrdiff_t charpos
, bytepos
;
5187 EMACS_INT iarg
IF_LINT (= 0);
5188 int this_scroll_margin
;
5190 /* If redisplay is suppressed due to an error, try again. */
5191 obuf
->display_error_modiff
= 0;
5195 if (!NILP (Vrecenter_redisplay
)
5196 && (!EQ (Vrecenter_redisplay
, Qtty
)
5197 || !NILP (Ftty_type (selected_frame
))))
5201 /* Invalidate pixel data calculated for all compositions. */
5202 for (i
= 0; i
< n_compositions
; i
++)
5203 composition_table
[i
]->font
= NULL
;
5205 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5207 Fredraw_frame (WINDOW_FRAME (w
));
5208 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5213 else if (CONSP (arg
)) /* Just C-u. */
5217 arg
= Fprefix_numeric_value (arg
);
5222 set_buffer_internal (buf
);
5224 /* Do this after making BUF current
5225 in case scroll_margin is buffer-local. */
5226 this_scroll_margin
=
5227 max (0, min (scroll_margin
, w
->total_lines
/ 4));
5229 /* Handle centering on a graphical frame specially. Such frames can
5230 have variable-height lines and centering point on the basis of
5231 line counts would lead to strange effects. */
5232 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5238 void *itdata
= bidi_shelve_cache ();
5240 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5241 start_display (&it
, w
, pt
);
5242 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5243 charpos
= IT_CHARPOS (it
);
5244 bytepos
= IT_BYTEPOS (it
);
5245 bidi_unshelve_cache (itdata
, 0);
5251 ptrdiff_t nlines
= min (PTRDIFF_MAX
, -iarg
);
5252 int extra_line_spacing
;
5253 int h
= window_box_height (w
);
5254 void *itdata
= bidi_shelve_cache ();
5256 iarg
= - max (-iarg
, this_scroll_margin
);
5258 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5259 start_display (&it
, w
, pt
);
5261 /* Be sure we have the exact height of the full line containing PT. */
5262 move_it_by_lines (&it
, 0);
5264 /* The amount of pixels we have to move back is the window
5265 height minus what's displayed in the line containing PT,
5266 and the lines below. */
5269 move_it_by_lines (&it
, nlines
);
5271 if (it
.vpos
== nlines
)
5275 /* Last line has no newline */
5276 h
-= line_bottom_y (&it
);
5280 /* Don't reserve space for extra line spacing of last line. */
5281 extra_line_spacing
= it
.max_extra_line_spacing
;
5283 /* If we can't move down NLINES lines because we hit
5284 the end of the buffer, count in some empty lines. */
5285 if (it
.vpos
< nlines
)
5288 extra_line_spacing
= it
.extra_line_spacing
;
5289 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5293 bidi_unshelve_cache (itdata
, 0);
5297 /* Now find the new top line (starting position) of the window. */
5298 start_display (&it
, w
, pt
);
5300 move_it_vertically_backward (&it
, h
);
5302 /* If extra line spacing is present, we may move too far
5303 back. This causes the last line to be only partially
5304 visible (which triggers redisplay to recenter that line
5305 in the middle), so move forward.
5306 But ignore extra line spacing on last line, as it is not
5307 considered to be part of the visible height of the line.
5309 h
+= extra_line_spacing
;
5310 while (-it
.current_y
> h
)
5311 move_it_by_lines (&it
, 1);
5313 charpos
= IT_CHARPOS (it
);
5314 bytepos
= IT_BYTEPOS (it
);
5316 bidi_unshelve_cache (itdata
, 0);
5320 struct position pos
;
5322 iarg
= max (iarg
, this_scroll_margin
);
5324 pos
= *vmotion (PT
, PT_BYTE
, -iarg
, w
);
5325 charpos
= pos
.bufpos
;
5326 bytepos
= pos
.bytepos
;
5331 struct position pos
;
5332 int ht
= window_internal_height (w
);
5339 /* Don't let it get into the margin at either top or bottom. */
5340 iarg
= clip_to_bounds (this_scroll_margin
, iarg
,
5341 ht
- this_scroll_margin
- 1);
5343 pos
= *vmotion (PT
, PT_BYTE
, - iarg
, w
);
5344 charpos
= pos
.bufpos
;
5345 bytepos
= pos
.bytepos
;
5348 /* Set the new window start. */
5349 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
5350 w
->window_end_valid
= 0;
5352 w
->optional_new_start
= 1;
5354 w
->start_at_line_beg
= (bytepos
== BEGV_BYTE
||
5355 FETCH_BYTE (bytepos
- 1) == '\n');
5357 set_buffer_internal (obuf
);
5361 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5363 doc
: /* Return the height in lines of the text display area of WINDOW.
5364 WINDOW must be a live window and defaults to the selected one.
5366 The returned height does not include the mode line, any header line,
5367 nor any partial-height lines at the bottom of the text area. */)
5368 (Lisp_Object window
)
5370 struct window
*w
= decode_live_window (window
);
5371 int pixel_height
= window_box_height (w
);
5372 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5373 return make_number (line_height
);
5378 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5380 doc
: /* Position point relative to window.
5381 ARG nil means position point at center of window.
5382 Else, ARG specifies vertical position within the window;
5383 zero means top of window, negative means relative to bottom of window. */)
5386 struct window
*w
= XWINDOW (selected_window
);
5390 int this_scroll_margin
;
5393 if (!(BUFFERP (w
->buffer
)
5394 && XBUFFER (w
->buffer
) == current_buffer
))
5395 /* This test is needed to make sure PT/PT_BYTE make sense in w->buffer
5396 when passed below to set_marker_both. */
5397 error ("move-to-window-line called from unrelated buffer");
5399 window
= selected_window
;
5400 start
= marker_position (w
->start
);
5401 if (start
< BEGV
|| start
> ZV
)
5403 int height
= window_internal_height (w
);
5404 Fvertical_motion (make_number (- (height
/ 2)), window
);
5405 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
5406 w
->start_at_line_beg
= !NILP (Fbolp ());
5410 Fgoto_char (w
->start
);
5412 lines
= displayed_window_lines (w
);
5415 this_scroll_margin
= max (0, min (scroll_margin
, lines
/ 4));
5419 XSETFASTINT (arg
, lines
/ 2);
5422 EMACS_INT iarg
= XINT (Fprefix_numeric_value (arg
));
5425 iarg
= iarg
+ lines
;
5427 #if 0 /* This code would prevent move-to-window-line from moving point
5428 to a place inside the scroll margins (which would cause the
5429 next redisplay to scroll). I wrote this code, but then concluded
5430 it is probably better not to install it. However, it is here
5431 inside #if 0 so as not to lose it. -- rms. */
5433 /* Don't let it get into the margin at either top or bottom. */
5434 iarg
= max (iarg
, this_scroll_margin
);
5435 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
5438 arg
= make_number (iarg
);
5441 /* Skip past a partially visible first line. */
5443 XSETINT (arg
, XINT (arg
) + 1);
5445 return Fvertical_motion (arg
, window
);
5450 /***********************************************************************
5451 Window Configuration
5452 ***********************************************************************/
5454 struct save_window_data
5456 struct vectorlike_header header
;
5457 Lisp_Object selected_frame
;
5458 Lisp_Object current_window
;
5459 Lisp_Object current_buffer
;
5460 Lisp_Object minibuf_scroll_window
;
5461 Lisp_Object minibuf_selected_window
;
5462 Lisp_Object root_window
;
5463 Lisp_Object focus_frame
;
5464 /* A vector, each of whose elements is a struct saved_window
5466 Lisp_Object saved_windows
;
5468 /* All fields above are traced by the GC.
5469 From `fame-cols' down, the fields are ignored by the GC. */
5471 int frame_cols
, frame_lines
, frame_menu_bar_lines
;
5472 int frame_tool_bar_lines
;
5475 /* This is saved as a Lisp_Vector */
5478 struct vectorlike_header header
;
5480 Lisp_Object window
, buffer
, start
, pointm
, mark
;
5481 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5482 Lisp_Object normal_cols
, normal_lines
;
5483 Lisp_Object hscroll
, min_hscroll
;
5484 Lisp_Object parent
, prev
;
5485 Lisp_Object start_at_line_beg
;
5486 Lisp_Object display_table
;
5487 Lisp_Object left_margin_cols
, right_margin_cols
;
5488 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
5489 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
, dedicated
;
5490 Lisp_Object combination_limit
, window_parameters
;
5493 #define SAVED_WINDOW_N(swv,n) \
5494 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5496 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
5497 doc
: /* Return t if OBJECT is a window-configuration object. */)
5498 (Lisp_Object object
)
5500 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
5503 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
5504 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5505 (Lisp_Object config
)
5507 register struct save_window_data
*data
;
5508 struct Lisp_Vector
*saved_windows
;
5510 CHECK_WINDOW_CONFIGURATION (config
);
5512 data
= (struct save_window_data
*) XVECTOR (config
);
5513 saved_windows
= XVECTOR (data
->saved_windows
);
5514 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5517 DEFUN ("set-window-configuration", Fset_window_configuration
,
5518 Sset_window_configuration
, 1, 1, 0,
5519 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5520 CONFIGURATION must be a value previously returned
5521 by `current-window-configuration' (which see).
5522 If CONFIGURATION was made from a frame that is now deleted,
5523 only frame-independent values can be restored. In this case,
5524 the return value is nil. Otherwise the value is t. */)
5525 (Lisp_Object configuration
)
5527 register struct save_window_data
*data
;
5528 struct Lisp_Vector
*saved_windows
;
5529 Lisp_Object new_current_buffer
;
5532 ptrdiff_t old_point
= -1;
5534 CHECK_WINDOW_CONFIGURATION (configuration
);
5536 data
= (struct save_window_data
*) XVECTOR (configuration
);
5537 saved_windows
= XVECTOR (data
->saved_windows
);
5539 new_current_buffer
= data
->current_buffer
;
5540 if (!BUFFER_LIVE_P (XBUFFER (new_current_buffer
)))
5541 new_current_buffer
= Qnil
;
5544 if (XBUFFER (new_current_buffer
) == current_buffer
)
5545 /* The code further down "preserves point" by saving here PT in
5546 old_point and then setting it later back into PT. When the
5547 current-selected-window and the final-selected-window both show
5548 the current buffer, this suffers from the problem that the
5549 current PT is the window-point of the current-selected-window,
5550 while the final PT is the point of the final-selected-window, so
5551 this copy from one PT to the other would end up moving the
5552 window-point of the final-selected-window to the window-point of
5553 the current-selected-window. So we have to be careful which
5554 point of the current-buffer we copy into old_point. */
5555 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
5556 && WINDOWP (selected_window
)
5557 && EQ (XWINDOW (selected_window
)->buffer
, new_current_buffer
)
5558 && !EQ (selected_window
, data
->current_window
))
5559 old_point
= marker_position (XWINDOW (data
->current_window
)->pointm
);
5563 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
5564 point in new_current_buffer as of the last time this buffer was
5565 used. This can be non-deterministic since it can be changed by
5566 things like jit-lock by mere temporary selection of some random
5567 window that happens to show this buffer.
5568 So if possible we want this arbitrary choice of "which point" to
5569 be the one from the to-be-selected-window so as to prevent this
5570 window's cursor from being copied from another window. */
5571 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
5572 /* If current_window = selected_window, its point is in BUF_PT. */
5573 && !EQ (selected_window
, data
->current_window
))
5574 old_point
= marker_position (XWINDOW (data
->current_window
)->pointm
);
5576 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
5579 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5582 /* If f is a dead frame, don't bother rebuilding its window tree.
5583 However, there is other stuff we should still try to do below. */
5584 if (FRAME_LIVE_P (f
))
5587 Lisp_Object dead_windows
= Qnil
;
5588 register Lisp_Object tem
, par
, pers
;
5589 register struct window
*w
;
5590 register struct saved_window
*p
;
5591 struct window
*root_window
;
5592 struct window
**leaf_windows
;
5597 /* If the frame has been resized since this window configuration was
5598 made, we change the frame to the size specified in the
5599 configuration, restore the configuration, and then resize it
5600 back. We keep track of the prevailing height in these variables. */
5601 int previous_frame_lines
= FRAME_LINES (f
);
5602 int previous_frame_cols
= FRAME_COLS (f
);
5603 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
5604 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
5606 /* Don't do this within the main loop below: This may call Lisp
5607 code and is thus potentially unsafe while input is blocked. */
5608 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
5610 p
= SAVED_WINDOW_N (saved_windows
, k
);
5612 w
= XWINDOW (window
);
5613 if (!NILP (w
->buffer
)
5614 && !EQ (w
->buffer
, p
->buffer
)
5615 && BUFFER_LIVE_P (XBUFFER (p
->buffer
)))
5616 /* If a window we restore gets another buffer, record the
5617 window's old buffer. */
5618 call1 (Qrecord_window_buffer
, window
);
5621 /* The mouse highlighting code could get screwed up
5622 if it runs during this. */
5625 if (data
->frame_lines
!= previous_frame_lines
5626 || data
->frame_cols
!= previous_frame_cols
)
5627 change_frame_size (f
, data
->frame_lines
,
5628 data
->frame_cols
, 0, 0, 0);
5629 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5630 if (data
->frame_menu_bar_lines
5631 != previous_frame_menu_bar_lines
)
5632 x_set_menu_bar_lines (f
, make_number (data
->frame_menu_bar_lines
),
5634 #ifdef HAVE_WINDOW_SYSTEM
5635 if (data
->frame_tool_bar_lines
5636 != previous_frame_tool_bar_lines
)
5637 x_set_tool_bar_lines (f
, make_number (data
->frame_tool_bar_lines
),
5642 /* "Swap out" point from the selected window's buffer
5643 into the window itself. (Normally the pointm of the selected
5644 window holds garbage.) We do this now, before
5645 restoring the window contents, and prevent it from
5646 being done later on when we select a new window. */
5647 if (! NILP (XWINDOW (selected_window
)->buffer
))
5649 w
= XWINDOW (selected_window
);
5650 set_marker_both (w
->pointm
,
5652 BUF_PT (XBUFFER (w
->buffer
)),
5653 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5656 windows_or_buffers_changed
++;
5657 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
5659 /* Problem: Freeing all matrices and later allocating them again
5660 is a serious redisplay flickering problem. What we would
5661 really like to do is to free only those matrices not reused
5663 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5664 leaf_windows
= alloca (count_windows (root_window
)
5665 * sizeof *leaf_windows
);
5666 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
5669 Mark all windows now on frame as "deleted".
5670 Restoring the new configuration "undeletes" any that are in it.
5672 Save their current buffers in their height fields, since we may
5673 need it later, if a buffer saved in the configuration is now
5675 delete_all_child_windows (FRAME_ROOT_WINDOW (f
));
5677 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
5679 p
= SAVED_WINDOW_N (saved_windows
, k
);
5681 w
= XWINDOW (window
);
5682 wset_next (w
, Qnil
);
5684 if (!NILP (p
->parent
))
5686 (w
, SAVED_WINDOW_N (saved_windows
, XFASTINT (p
->parent
))->window
);
5688 wset_parent (w
, Qnil
);
5690 if (!NILP (p
->prev
))
5693 (w
, SAVED_WINDOW_N (saved_windows
, XFASTINT (p
->prev
))->window
);
5694 wset_next (XWINDOW (w
->prev
), p
->window
);
5698 wset_prev (w
, Qnil
);
5699 if (!NILP (w
->parent
))
5701 if (XINT (p
->total_cols
) == XWINDOW (w
->parent
)->total_cols
)
5703 wset_vchild (XWINDOW (w
->parent
), p
->window
);
5704 wset_hchild (XWINDOW (w
->parent
), Qnil
);
5708 wset_hchild (XWINDOW (w
->parent
), p
->window
);
5709 wset_vchild (XWINDOW (w
->parent
), Qnil
);
5714 /* If we squirreled away the buffer, restore it now. */
5715 if (BUFFERP (w
->combination_limit
))
5716 wset_buffer (w
, w
->combination_limit
);
5717 w
->left_col
= XFASTINT (p
->left_col
);
5718 w
->top_line
= XFASTINT (p
->top_line
);
5719 w
->total_cols
= XFASTINT (p
->total_cols
);
5720 w
->total_lines
= XFASTINT (p
->total_lines
);
5721 wset_normal_cols (w
, p
->normal_cols
);
5722 wset_normal_lines (w
, p
->normal_lines
);
5723 w
->hscroll
= XFASTINT (p
->hscroll
);
5724 w
->min_hscroll
= XFASTINT (p
->min_hscroll
);
5725 wset_display_table (w
, p
->display_table
);
5726 wset_left_margin_cols (w
, p
->left_margin_cols
);
5727 wset_right_margin_cols (w
, p
->right_margin_cols
);
5728 wset_left_fringe_width (w
, p
->left_fringe_width
);
5729 wset_right_fringe_width (w
, p
->right_fringe_width
);
5730 w
->fringes_outside_margins
= !NILP (p
->fringes_outside_margins
);
5731 wset_scroll_bar_width (w
, p
->scroll_bar_width
);
5732 wset_vertical_scroll_bar_type (w
, p
->vertical_scroll_bar_type
);
5733 wset_dedicated (w
, p
->dedicated
);
5734 wset_combination_limit (w
, p
->combination_limit
);
5735 /* Restore any window parameters that have been saved.
5736 Parameters that have not been saved are left alone. */
5737 for (tem
= p
->window_parameters
; CONSP (tem
); tem
= XCDR (tem
))
5742 if (NILP (XCDR (pers
)))
5744 par
= Fassq (XCAR (pers
), w
->window_parameters
);
5745 if (CONSP (par
) && !NILP (XCDR (par
)))
5746 /* Reset a parameter to nil if and only if it
5747 has a non-nil association. Don't make new
5749 Fsetcdr (par
, Qnil
);
5752 /* Always restore a non-nil value. */
5753 Fset_window_parameter (window
, XCAR (pers
), XCDR (pers
));
5757 w
->last_modified
= 0;
5758 w
->last_overlay_modified
= 0;
5760 /* Reinstall the saved buffer and pointers into it. */
5761 if (NILP (p
->buffer
))
5762 /* An internal window. */
5763 wset_buffer (w
, p
->buffer
);
5764 else if (BUFFER_LIVE_P (XBUFFER (p
->buffer
)))
5765 /* If saved buffer is alive, install it. */
5767 wset_buffer (w
, p
->buffer
);
5768 w
->start_at_line_beg
= !NILP (p
->start_at_line_beg
);
5769 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
5770 set_marker_restricted (w
->pointm
, p
->pointm
,
5772 Fset_marker (BVAR (XBUFFER (w
->buffer
), mark
),
5773 p
->mark
, w
->buffer
);
5775 /* As documented in Fcurrent_window_configuration, don't
5776 restore the location of point in the buffer which was
5777 current when the window configuration was recorded. */
5778 if (!EQ (p
->buffer
, new_current_buffer
)
5779 && XBUFFER (p
->buffer
) == current_buffer
)
5780 Fgoto_char (w
->pointm
);
5782 else if (!NILP (w
->buffer
)
5783 && BUFFER_LIVE_P (XBUFFER (w
->buffer
)))
5784 /* Keep window's old buffer; make sure the markers are
5787 /* Set window markers at start of visible range. */
5788 if (XMARKER (w
->start
)->buffer
== 0)
5789 set_marker_restricted_both (w
->start
, w
->buffer
, 0, 0);
5790 if (XMARKER (w
->pointm
)->buffer
== 0)
5791 set_marker_restricted_both
5792 (w
->pointm
, w
->buffer
,
5793 BUF_PT (XBUFFER (w
->buffer
)),
5794 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5795 w
->start_at_line_beg
= 1;
5798 /* Window has no live buffer, get one. */
5800 /* Get the buffer via other_buffer_safely in order to
5801 avoid showing an unimportant buffer and, if necessary, to
5802 recreate *scratch* in the course (part of Juanma's bs-show
5803 scenario from March 2011). */
5804 wset_buffer (w
, other_buffer_safely (Fcurrent_buffer ()));
5805 /* This will set the markers to beginning of visible
5807 set_marker_restricted_both (w
->start
, w
->buffer
, 0, 0);
5808 set_marker_restricted_both (w
->pointm
, w
->buffer
, 0, 0);
5809 w
->start_at_line_beg
= 1;
5810 if (!NILP (w
->dedicated
))
5811 /* Record this window as dead. */
5812 dead_windows
= Fcons (window
, dead_windows
);
5813 /* Make sure window is no more dedicated. */
5814 wset_dedicated (w
, Qnil
);
5818 fset_root_window (f
, data
->root_window
);
5819 /* Arrange *not* to restore point in the buffer that was
5820 current when the window configuration was saved. */
5821 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
5822 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
5823 make_number (old_point
),
5824 XWINDOW (data
->current_window
)->buffer
);
5826 /* In the following call to `select-window', prevent "swapping out
5827 point" in the old selected window using the buffer that has
5828 been restored into it. We already swapped out that point from
5829 that window's old buffer. */
5830 select_window (data
->current_window
, Qnil
, 1);
5831 BVAR (XBUFFER (XWINDOW (selected_window
)->buffer
), last_selected_window
)
5834 if (NILP (data
->focus_frame
)
5835 || (FRAMEP (data
->focus_frame
)
5836 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
5837 Fredirect_frame_focus (frame
, data
->focus_frame
);
5839 /* Set the screen height to the value it had before this function. */
5840 if (previous_frame_lines
!= FRAME_LINES (f
)
5841 || previous_frame_cols
!= FRAME_COLS (f
))
5842 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
5844 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5845 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
5846 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
5848 #ifdef HAVE_WINDOW_SYSTEM
5849 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
5850 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
5855 /* Now, free glyph matrices in windows that were not reused. */
5856 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
5858 if (NILP (leaf_windows
[i
]->buffer
))
5860 /* Assert it's not reused as a combination. */
5861 eassert (NILP (leaf_windows
[i
]->hchild
)
5862 && NILP (leaf_windows
[i
]->vchild
));
5863 free_window_matrices (leaf_windows
[i
]);
5865 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
5872 /* Scan dead buffer windows. */
5873 for (; CONSP (dead_windows
); dead_windows
= XCDR (dead_windows
))
5875 window
= XCAR (dead_windows
);
5876 if (WINDOW_LIVE_P (window
) && !EQ (window
, FRAME_ROOT_WINDOW (f
)))
5877 delete_deletable_window (window
);
5880 /* Fselect_window will have made f the selected frame, so we
5881 reselect the proper frame here. Fhandle_switch_frame will change the
5882 selected window too, but that doesn't make the call to
5883 Fselect_window above totally superfluous; it still sets f's
5885 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
5886 do_switch_frame (data
->selected_frame
, 0, 0, Qnil
);
5888 run_window_configuration_change_hook (f
);
5891 if (!NILP (new_current_buffer
))
5893 Fset_buffer (new_current_buffer
);
5894 /* If the new current buffer doesn't appear in the selected
5895 window, go to its old point (see bug#12208). */
5896 if (!EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
5897 Fgoto_char (make_number (old_point
));
5900 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
5901 minibuf_selected_window
= data
->minibuf_selected_window
;
5903 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
5907 /* Recursively delete all child windows reachable via the next, vchild,
5908 and hchild slots of WINDOW. */
5910 delete_all_child_windows (Lisp_Object window
)
5912 register struct window
*w
;
5914 w
= XWINDOW (window
);
5916 if (!NILP (w
->next
))
5917 /* Delete WINDOW's siblings (we traverse postorderly). */
5918 delete_all_child_windows (w
->next
);
5920 if (!NILP (w
->vchild
))
5922 delete_all_child_windows (w
->vchild
);
5923 wset_vchild (w
, Qnil
);
5925 else if (!NILP (w
->hchild
))
5927 delete_all_child_windows (w
->hchild
);
5928 wset_hchild (w
, Qnil
);
5930 else if (!NILP (w
->buffer
))
5933 unchain_marker (XMARKER (w
->pointm
));
5934 unchain_marker (XMARKER (w
->start
));
5935 /* Since combination limit makes sense for an internal windows
5936 only, we use this slot to save the buffer for the sake of
5937 possible resurrection in Fset_window_configuration. */
5938 wset_combination_limit (w
, w
->buffer
);
5939 wset_buffer (w
, Qnil
);
5942 Vwindow_list
= Qnil
;
5946 count_windows (register struct window
*window
)
5948 register int count
= 1;
5949 if (!NILP (window
->next
))
5950 count
+= count_windows (XWINDOW (window
->next
));
5951 if (!NILP (window
->vchild
))
5952 count
+= count_windows (XWINDOW (window
->vchild
));
5953 if (!NILP (window
->hchild
))
5954 count
+= count_windows (XWINDOW (window
->hchild
));
5959 /* Fill vector FLAT with leaf windows under W, starting at index I.
5960 Value is last index + 1. */
5962 get_leaf_windows (struct window
*w
, struct window
**flat
, int i
)
5966 if (!NILP (w
->hchild
))
5967 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
5968 else if (!NILP (w
->vchild
))
5969 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
5973 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5980 /* Return a pointer to the glyph W's physical cursor is on. Value is
5981 null if W's current matrix is invalid, so that no meaningful glyph
5984 get_phys_cursor_glyph (struct window
*w
)
5986 struct glyph_row
*row
;
5987 struct glyph
*glyph
;
5988 int hpos
= w
->phys_cursor
.hpos
;
5990 if (!(w
->phys_cursor
.vpos
>= 0
5991 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
))
5994 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
5995 if (!row
->enabled_p
)
6000 /* When the window is hscrolled, cursor hpos can legitimately be
6001 out of bounds, but we draw the cursor at the corresponding
6002 window margin in that case. */
6003 if (!row
->reversed_p
&& hpos
< 0)
6005 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
6006 hpos
= row
->used
[TEXT_AREA
] - 1;
6009 if (hpos
>= 0 && hpos
< row
->used
[TEXT_AREA
])
6010 glyph
= row
->glyphs
[TEXT_AREA
] + hpos
;
6019 save_window_save (Lisp_Object window
, struct Lisp_Vector
*vector
, int i
)
6021 register struct saved_window
*p
;
6022 register struct window
*w
;
6023 register Lisp_Object tem
, pers
, par
;
6025 for (;!NILP (window
); window
= w
->next
)
6027 p
= SAVED_WINDOW_N (vector
, i
);
6028 w
= XWINDOW (window
);
6030 wset_temslot (w
, make_number (i
)); i
++;
6032 p
->buffer
= w
->buffer
;
6033 p
->left_col
= make_number (w
->left_col
);
6034 p
->top_line
= make_number (w
->top_line
);
6035 p
->total_cols
= make_number (w
->total_cols
);
6036 p
->total_lines
= make_number (w
->total_lines
);
6037 p
->normal_cols
= w
->normal_cols
;
6038 p
->normal_lines
= w
->normal_lines
;
6039 XSETFASTINT (p
->hscroll
, w
->hscroll
);
6040 XSETFASTINT (p
->min_hscroll
, w
->min_hscroll
);
6041 p
->display_table
= w
->display_table
;
6042 p
->left_margin_cols
= w
->left_margin_cols
;
6043 p
->right_margin_cols
= w
->right_margin_cols
;
6044 p
->left_fringe_width
= w
->left_fringe_width
;
6045 p
->right_fringe_width
= w
->right_fringe_width
;
6046 p
->fringes_outside_margins
= w
->fringes_outside_margins
? Qt
: Qnil
;
6047 p
->scroll_bar_width
= w
->scroll_bar_width
;
6048 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
6049 p
->dedicated
= w
->dedicated
;
6050 p
->combination_limit
= w
->combination_limit
;
6051 p
->window_parameters
= Qnil
;
6053 if (!NILP (Vwindow_persistent_parameters
))
6055 /* Run cycle detection on Vwindow_persistent_parameters. */
6056 Lisp_Object tortoise
, hare
;
6058 hare
= tortoise
= Vwindow_persistent_parameters
;
6059 while (CONSP (hare
))
6066 tortoise
= XCDR (tortoise
);
6068 if (EQ (hare
, tortoise
))
6069 /* Reset Vwindow_persistent_parameters to Qnil. */
6071 Vwindow_persistent_parameters
= Qnil
;
6076 for (tem
= Vwindow_persistent_parameters
; CONSP (tem
);
6080 /* Save values for persistent window parameters. */
6081 if (CONSP (pers
) && !NILP (XCDR (pers
)))
6083 par
= Fassq (XCAR (pers
), w
->window_parameters
);
6085 /* If the window has no value for the parameter,
6087 p
->window_parameters
= Fcons (Fcons (XCAR (pers
), Qnil
),
6088 p
->window_parameters
);
6090 /* If the window has a value for the parameter,
6092 p
->window_parameters
= Fcons (Fcons (XCAR (par
),
6094 p
->window_parameters
);
6099 if (!NILP (w
->buffer
))
6101 /* Save w's value of point in the window configuration. If w
6102 is the selected window, then get the value of point from
6103 the buffer; pointm is garbage in the selected window. */
6104 if (EQ (window
, selected_window
))
6105 p
->pointm
= build_marker (XBUFFER (w
->buffer
),
6106 BUF_PT (XBUFFER (w
->buffer
)),
6107 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6109 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
6110 XMARKER (p
->pointm
)->insertion_type
6111 = !NILP (Vwindow_point_insertion_type
);
6113 p
->start
= Fcopy_marker (w
->start
, Qnil
);
6114 p
->start_at_line_beg
= w
->start_at_line_beg
? Qt
: Qnil
;
6116 tem
= BVAR (XBUFFER (w
->buffer
), mark
);
6117 p
->mark
= Fcopy_marker (tem
, Qnil
);
6124 p
->start_at_line_beg
= Qnil
;
6127 if (NILP (w
->parent
))
6130 p
->parent
= XWINDOW (w
->parent
)->temslot
;
6135 p
->prev
= XWINDOW (w
->prev
)->temslot
;
6137 if (!NILP (w
->vchild
))
6138 i
= save_window_save (w
->vchild
, vector
, i
);
6139 if (!NILP (w
->hchild
))
6140 i
= save_window_save (w
->hchild
, vector
, i
);
6146 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
6147 Scurrent_window_configuration
, 0, 1, 0,
6148 doc
: /* Return an object representing the current window configuration of FRAME.
6149 If FRAME is nil or omitted, use the selected frame.
6150 This describes the number of windows, their sizes and current buffers,
6151 and for each displayed buffer, where display starts, and the positions of
6152 point and mark. An exception is made for point in the current buffer:
6153 its value is -not- saved.
6154 This also records the currently selected frame, and FRAME's focus
6155 redirection (see `redirect-frame-focus'). The variable
6156 `window-persistent-parameters' specifies which window parameters are
6157 saved by this function. */)
6160 register Lisp_Object tem
;
6161 register int n_windows
;
6162 register struct save_window_data
*data
;
6164 struct frame
*f
= decode_live_frame (frame
);
6166 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6167 data
= ALLOCATE_PSEUDOVECTOR (struct save_window_data
, frame_cols
,
6168 PVEC_WINDOW_CONFIGURATION
);
6170 data
->frame_cols
= FRAME_COLS (f
);
6171 data
->frame_lines
= FRAME_LINES (f
);
6172 data
->frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6173 data
->frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6174 data
->selected_frame
= selected_frame
;
6175 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6176 XSETBUFFER (data
->current_buffer
, current_buffer
);
6177 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6178 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6179 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6180 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6181 tem
= make_uninit_vector (n_windows
);
6182 data
->saved_windows
= tem
;
6183 for (i
= 0; i
< n_windows
; i
++)
6185 Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
));
6186 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6187 XSETWINDOW_CONFIGURATION (tem
, data
);
6191 /***********************************************************************
6193 ***********************************************************************/
6195 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6197 doc
: /* Set width of marginal areas of window WINDOW.
6198 WINDOW must be a live window and defaults to the selected one.
6200 Second arg LEFT-WIDTH specifies the number of character cells to
6201 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6202 does the same for the right marginal area. A nil width parameter
6203 means no margin. */)
6204 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
)
6206 struct window
*w
= decode_live_window (window
);
6208 /* Translate negative or zero widths to nil.
6209 Margins that are too wide have to be checked elsewhere. */
6211 if (!NILP (left_width
))
6213 CHECK_NUMBER (left_width
);
6214 if (XINT (left_width
) <= 0)
6218 if (!NILP (right_width
))
6220 CHECK_NUMBER (right_width
);
6221 if (XINT (right_width
) <= 0)
6225 if (!EQ (w
->left_margin_cols
, left_width
)
6226 || !EQ (w
->right_margin_cols
, right_width
))
6228 wset_left_margin_cols (w
, left_width
);
6229 wset_right_margin_cols (w
, right_width
);
6231 adjust_window_margins (w
);
6233 ++windows_or_buffers_changed
;
6234 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6241 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6243 doc
: /* Get width of marginal areas of window WINDOW.
6244 WINDOW must be a live window and defaults to the selected one.
6246 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6247 If a marginal area does not exist, its width will be returned
6249 (Lisp_Object window
)
6251 struct window
*w
= decode_live_window (window
);
6252 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
6257 /***********************************************************************
6259 ***********************************************************************/
6261 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6263 doc
: /* Set the fringe widths of window WINDOW.
6264 WINDOW must be a live window and defaults to the selected one.
6266 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6267 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6268 fringe width. If a fringe width arg is nil, that means to use the
6269 frame's default fringe width. Default fringe widths can be set with
6270 the command `set-fringe-style'.
6271 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6272 outside of the display margins. By default, fringes are drawn between
6273 display marginal areas and the text area. */)
6274 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
, Lisp_Object outside_margins
)
6276 struct window
*w
= decode_live_window (window
);
6277 int outside
= !NILP (outside_margins
);
6279 if (!NILP (left_width
))
6280 CHECK_NATNUM (left_width
);
6281 if (!NILP (right_width
))
6282 CHECK_NATNUM (right_width
);
6284 /* Do nothing on a tty. */
6285 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6286 && (!EQ (w
->left_fringe_width
, left_width
)
6287 || !EQ (w
->right_fringe_width
, right_width
)
6288 || w
->fringes_outside_margins
!= outside
))
6290 wset_left_fringe_width (w
, left_width
);
6291 wset_right_fringe_width (w
, right_width
);
6292 w
->fringes_outside_margins
= outside
;
6294 adjust_window_margins (w
);
6296 clear_glyph_matrix (w
->current_matrix
);
6297 w
->window_end_valid
= 0;
6299 ++windows_or_buffers_changed
;
6300 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6307 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6309 doc
: /* Get width of fringes of window WINDOW.
6310 WINDOW must be a live window and defaults to the selected one.
6312 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6313 (Lisp_Object window
)
6315 struct window
*w
= decode_live_window (window
);
6317 return list3 (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6318 make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6319 WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
) ? Qt
: Qnil
);
6324 /***********************************************************************
6326 ***********************************************************************/
6328 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
,
6329 Sset_window_scroll_bars
, 2, 4, 0,
6330 doc
: /* Set width and type of scroll bars of window WINDOW.
6331 WINDOW must be a live window and defaults to the selected one.
6333 Second parameter WIDTH specifies the pixel width for the scroll bar;
6334 this is automatically adjusted to a multiple of the frame column width.
6335 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6336 bar: left, right, or nil.
6337 If WIDTH is nil, use the frame's scroll-bar width.
6338 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6339 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6340 (Lisp_Object window
, Lisp_Object width
, Lisp_Object vertical_type
, Lisp_Object horizontal_type
)
6342 struct window
*w
= decode_live_window (window
);
6346 CHECK_RANGED_INTEGER (width
, 0, INT_MAX
);
6348 if (XINT (width
) == 0)
6349 vertical_type
= Qnil
;
6352 if (!(NILP (vertical_type
)
6353 || EQ (vertical_type
, Qleft
)
6354 || EQ (vertical_type
, Qright
)
6355 || EQ (vertical_type
, Qt
)))
6356 error ("Invalid type of vertical scroll bar");
6358 if (!EQ (w
->scroll_bar_width
, width
)
6359 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6361 wset_scroll_bar_width (w
, width
);
6362 wset_vertical_scroll_bar_type (w
, vertical_type
);
6364 adjust_window_margins (w
);
6366 clear_glyph_matrix (w
->current_matrix
);
6367 w
->window_end_valid
= 0;
6369 ++windows_or_buffers_changed
;
6370 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6377 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6379 doc
: /* Get width and type of scroll bars of window WINDOW.
6380 WINDOW must be a live window and defaults to the selected one.
6382 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6383 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6385 (Lisp_Object window
)
6387 struct window
*w
= decode_live_window (window
);
6389 return list4 (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6390 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6391 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6392 make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6393 w
->vertical_scroll_bar_type
, Qnil
);
6398 /***********************************************************************
6400 ***********************************************************************/
6402 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6403 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6404 If WINDOW is omitted or nil, it defaults to the selected window.
6405 Normally, value is a multiple of the canonical character height of WINDOW;
6406 optional second arg PIXELS-P means value is measured in pixels. */)
6407 (Lisp_Object window
, Lisp_Object pixels_p
)
6410 struct window
*w
= decode_live_window (window
);
6411 struct frame
*f
= XFRAME (w
->frame
);
6413 if (FRAME_WINDOW_P (f
))
6414 result
= (NILP (pixels_p
)
6415 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6416 : make_number (-w
->vscroll
));
6418 result
= make_number (0);
6423 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6425 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6426 WINDOW nil means use the selected window. Normally, VSCROLL is a
6427 non-negative multiple of the canonical character height of WINDOW;
6428 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
6429 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6430 corresponds to an integral number of pixels. The return value is the
6431 result of this rounding.
6432 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6433 (Lisp_Object window
, Lisp_Object vscroll
, Lisp_Object pixels_p
)
6435 struct window
*w
= decode_live_window (window
);
6436 struct frame
*f
= XFRAME (w
->frame
);
6438 CHECK_NUMBER_OR_FLOAT (vscroll
);
6440 if (FRAME_WINDOW_P (f
))
6442 int old_dy
= w
->vscroll
;
6444 w
->vscroll
= - (NILP (pixels_p
)
6445 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
6446 : XFLOATINT (vscroll
));
6447 w
->vscroll
= min (w
->vscroll
, 0);
6449 if (w
->vscroll
!= old_dy
)
6451 /* Adjust glyph matrix of the frame if the virtual display
6452 area becomes larger than before. */
6453 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
6456 /* Prevent redisplay shortcuts. */
6457 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
6461 return Fwindow_vscroll (window
, pixels_p
);
6465 /* Call FN for all leaf windows on frame F. FN is called with the
6466 first argument being a pointer to the leaf window, and with
6467 additional argument USER_DATA. Stops when FN returns 0. */
6470 foreach_window (struct frame
*f
, int (*fn
) (struct window
*, void *),
6473 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
6474 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
6475 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
6479 /* Helper function for foreach_window. Call FN for all leaf windows
6480 reachable from W. FN is called with the first argument being a
6481 pointer to the leaf window, and with additional argument USER_DATA.
6482 Stop when FN returns 0. Value is 0 if stopped by FN. */
6485 foreach_window_1 (struct window
*w
, int (*fn
) (struct window
*, void *), void *user_data
)
6489 for (cont
= 1; w
&& cont
;)
6491 if (!NILP (w
->hchild
))
6492 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
6493 else if (!NILP (w
->vchild
))
6494 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
6496 cont
= fn (w
, user_data
);
6498 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6505 /* Freeze or unfreeze the window start of W unless it is a
6506 mini-window or the selected window. FREEZE_P non-null means freeze
6507 the window start. */
6510 freeze_window_start (struct window
*w
, void *freeze_p
)
6512 if (MINI_WINDOW_P (w
)
6513 || (WINDOWP (selected_window
) /* Can be nil in corner cases. */
6514 && (w
== XWINDOW (selected_window
)
6515 || (MINI_WINDOW_P (XWINDOW (selected_window
))
6516 && ! NILP (Vminibuf_scroll_window
)
6517 && w
== XWINDOW (Vminibuf_scroll_window
)))))
6520 w
->frozen_window_start_p
= freeze_p
!= NULL
;
6525 /* Freeze or unfreeze the window starts of all leaf windows on frame
6526 F, except the selected window and a mini-window. FREEZE_P non-zero
6527 means freeze the window start. */
6530 freeze_window_starts (struct frame
*f
, bool freeze_p
)
6532 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
6536 /***********************************************************************
6538 ***********************************************************************/
6540 /* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2
6541 describe the same state of affairs. This is used by Fequal.
6543 IGNORE_POSITIONS means ignore non-matching scroll positions
6546 This ignores a couple of things like the dedication status of
6547 window, combination_limit and the like. This might have to be
6551 compare_window_configurations (Lisp_Object configuration1
,
6552 Lisp_Object configuration2
,
6553 bool ignore_positions
)
6555 register struct save_window_data
*d1
, *d2
;
6556 struct Lisp_Vector
*sws1
, *sws2
;
6559 CHECK_WINDOW_CONFIGURATION (configuration1
);
6560 CHECK_WINDOW_CONFIGURATION (configuration2
);
6562 d1
= (struct save_window_data
*) XVECTOR (configuration1
);
6563 d2
= (struct save_window_data
*) XVECTOR (configuration2
);
6564 sws1
= XVECTOR (d1
->saved_windows
);
6565 sws2
= XVECTOR (d2
->saved_windows
);
6567 /* Frame settings must match. */
6568 if (d1
->frame_cols
!= d2
->frame_cols
6569 || d1
->frame_lines
!= d2
->frame_lines
6570 || d1
->frame_menu_bar_lines
!= d2
->frame_menu_bar_lines
6571 || !EQ (d1
->selected_frame
, d2
->selected_frame
)
6572 || !EQ (d1
->current_buffer
, d2
->current_buffer
)
6573 || (!ignore_positions
6574 && (!EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
)
6575 || !EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
)))
6576 || !EQ (d1
->focus_frame
, d2
->focus_frame
)
6577 /* Verify that the two configurations have the same number of windows. */
6578 || sws1
->header
.size
!= sws2
->header
.size
)
6581 for (i
= 0; i
< sws1
->header
.size
; i
++)
6583 struct saved_window
*sw1
, *sw2
;
6585 sw1
= SAVED_WINDOW_N (sws1
, i
);
6586 sw2
= SAVED_WINDOW_N (sws2
, i
);
6589 /* The "current" windows in the two configurations must
6590 correspond to each other. */
6591 EQ (d1
->current_window
, sw1
->window
)
6592 != EQ (d2
->current_window
, sw2
->window
)
6593 /* Windows' buffers must match. */
6594 || !EQ (sw1
->buffer
, sw2
->buffer
)
6595 || !EQ (sw1
->left_col
, sw2
->left_col
)
6596 || !EQ (sw1
->top_line
, sw2
->top_line
)
6597 || !EQ (sw1
->total_cols
, sw2
->total_cols
)
6598 || !EQ (sw1
->total_lines
, sw2
->total_lines
)
6599 || !EQ (sw1
->display_table
, sw2
->display_table
)
6600 /* The next two disjuncts check the window structure for
6602 || !EQ (sw1
->parent
, sw2
->parent
)
6603 || !EQ (sw1
->prev
, sw2
->prev
)
6604 || (!ignore_positions
6605 && (!EQ (sw1
->hscroll
, sw2
->hscroll
)
6606 || !EQ (sw1
->min_hscroll
, sw2
->min_hscroll
)
6607 || !EQ (sw1
->start_at_line_beg
, sw2
->start_at_line_beg
)
6608 || NILP (Fequal (sw1
->start
, sw2
->start
))
6609 || NILP (Fequal (sw1
->pointm
, sw2
->pointm
))
6610 || NILP (Fequal (sw1
->mark
, sw2
->mark
))))
6611 || !EQ (sw1
->left_margin_cols
, sw2
->left_margin_cols
)
6612 || !EQ (sw1
->right_margin_cols
, sw2
->right_margin_cols
)
6613 || !EQ (sw1
->left_fringe_width
, sw2
->left_fringe_width
)
6614 || !EQ (sw1
->right_fringe_width
, sw2
->right_fringe_width
)
6615 || !EQ (sw1
->fringes_outside_margins
, sw2
->fringes_outside_margins
)
6616 || !EQ (sw1
->scroll_bar_width
, sw2
->scroll_bar_width
)
6617 || !EQ (sw1
->vertical_scroll_bar_type
, sw2
->vertical_scroll_bar_type
))
6624 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
6625 Scompare_window_configurations
, 2, 2, 0,
6626 doc
: /* Compare two window configurations as regards the structure of windows.
6627 This function ignores details such as the values of point and mark
6628 and scrolling positions. */)
6629 (Lisp_Object x
, Lisp_Object y
)
6631 if (compare_window_configurations (x
, y
, 1))
6637 init_window_once (void)
6639 struct frame
*f
= make_initial_frame ();
6640 XSETFRAME (selected_frame
, f
);
6641 Vterminal_frame
= selected_frame
;
6642 minibuf_window
= f
->minibuffer_window
;
6643 selected_window
= f
->selected_window
;
6644 last_nonminibuf_frame
= f
;
6646 window_initialized
= 1;
6652 Vwindow_list
= Qnil
;
6656 syms_of_window (void)
6658 DEFSYM (Qscroll_up
, "scroll-up");
6659 DEFSYM (Qscroll_down
, "scroll-down");
6660 DEFSYM (Qscroll_command
, "scroll-command");
6662 Fput (Qscroll_up
, Qscroll_command
, Qt
);
6663 Fput (Qscroll_down
, Qscroll_command
, Qt
);
6665 DEFSYM (Qwindow_configuration_change_hook
, "window-configuration-change-hook");
6666 DEFSYM (Qwindowp
, "windowp");
6667 DEFSYM (Qwindow_configuration_p
, "window-configuration-p");
6668 DEFSYM (Qwindow_live_p
, "window-live-p");
6669 DEFSYM (Qwindow_valid_p
, "window-valid-p");
6670 DEFSYM (Qwindow_deletable_p
, "window-deletable-p");
6671 DEFSYM (Qdelete_window
, "delete-window");
6672 DEFSYM (Qwindow_resize_root_window
, "window--resize-root-window");
6673 DEFSYM (Qwindow_resize_root_window_vertically
, "window--resize-root-window-vertically");
6674 DEFSYM (Qsafe
, "safe");
6675 DEFSYM (Qdisplay_buffer
, "display-buffer");
6676 DEFSYM (Qreplace_buffer_in_windows
, "replace-buffer-in-windows");
6677 DEFSYM (Qrecord_window_buffer
, "record-window-buffer");
6678 DEFSYM (Qget_mru_window
, "get-mru-window");
6679 DEFSYM (Qwindow_size
, "window-size");
6680 DEFSYM (Qtemp_buffer_show_hook
, "temp-buffer-show-hook");
6681 DEFSYM (Qabove
, "above");
6682 DEFSYM (Qbelow
, "below");
6683 DEFSYM (Qclone_of
, "clone-of");
6685 staticpro (&Vwindow_list
);
6687 minibuf_selected_window
= Qnil
;
6688 staticpro (&minibuf_selected_window
);
6690 window_scroll_pixel_based_preserve_x
= -1;
6691 window_scroll_pixel_based_preserve_y
= -1;
6692 window_scroll_preserve_hpos
= -1;
6693 window_scroll_preserve_vpos
= -1;
6695 DEFVAR_LISP ("temp-buffer-show-function", Vtemp_buffer_show_function
,
6696 doc
: /* Non-nil means call as function to display a help buffer.
6697 The function is called with one argument, the buffer to be displayed.
6698 Used by `with-output-to-temp-buffer'.
6699 If this function is used, then it must do the entire job of showing
6700 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6701 Vtemp_buffer_show_function
= Qnil
;
6703 DEFVAR_LISP ("minibuffer-scroll-window", Vminibuf_scroll_window
,
6704 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6705 Vminibuf_scroll_window
= Qnil
;
6707 DEFVAR_BOOL ("mode-line-in-non-selected-windows", mode_line_in_non_selected_windows
,
6708 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6709 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6710 is displayed in the `mode-line' face. */);
6711 mode_line_in_non_selected_windows
= 1;
6713 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer
,
6714 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6715 Vother_window_scroll_buffer
= Qnil
;
6717 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p
,
6718 doc
: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
6719 auto_window_vscroll_p
= 1;
6721 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines
,
6722 doc
: /* Number of lines of continuity when scrolling by screenfuls. */);
6723 next_screen_context_lines
= 2;
6725 DEFVAR_LISP ("scroll-preserve-screen-position",
6726 Vscroll_preserve_screen_position
,
6727 doc
: /* Controls if scroll commands move point to keep its screen position unchanged.
6728 A value of nil means point does not keep its screen position except
6729 at the scroll margin or window boundary respectively.
6730 A value of t means point keeps its screen position if the scroll
6731 command moved it vertically out of the window, e.g. when scrolling
6733 Any other value means point always keeps its screen position.
6734 Scroll commands should have the `scroll-command' property
6735 on their symbols to be controlled by this variable. */);
6736 Vscroll_preserve_screen_position
= Qnil
;
6738 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type
,
6739 doc
: /* Type of marker to use for `window-point'. */);
6740 Vwindow_point_insertion_type
= Qnil
;
6742 DEFVAR_LISP ("window-configuration-change-hook",
6743 Vwindow_configuration_change_hook
,
6744 doc
: /* Functions to call when window configuration changes.
6745 The buffer-local part is run once per window, with the relevant window
6746 selected; while the global part is run only once for the modified frame,
6747 with the relevant frame selected. */);
6748 Vwindow_configuration_change_hook
= Qnil
;
6750 DEFVAR_LISP ("recenter-redisplay", Vrecenter_redisplay
,
6751 doc
: /* Non-nil means `recenter' redraws entire frame.
6752 If this option is non-nil, then the `recenter' command with a nil
6753 argument will redraw the entire frame; the special value `tty' causes
6754 the frame to be redrawn only if it is a tty frame. */);
6755 Vrecenter_redisplay
= Qtty
;
6757 DEFVAR_LISP ("window-combination-resize", Vwindow_combination_resize
,
6758 doc
: /* If t, resize window combinations proportionally.
6759 If this variable is nil, splitting a window gets the entire screen space
6760 for displaying the new window from the window to split. Deleting and
6761 resizing a window preferably resizes one adjacent window only.
6763 If this variable is t, splitting a window tries to get the space
6764 proportionally from all windows in the same combination. This also
6765 allows to split a window that is otherwise too small or of fixed size.
6766 Resizing and deleting a window proportionally resize all windows in the
6769 Other values are reserved for future use.
6771 This variable takes no effect if the variable `window-combination-limit' is
6773 Vwindow_combination_resize
= Qnil
;
6775 DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit
,
6776 doc
: /* If non-nil, splitting a window makes a new parent window.
6777 The following values are recognized:
6779 nil means splitting a window will create a new parent window only if the
6780 window has no parent window or the window shall become part of a
6781 combination orthogonal to the one it is part of.
6783 `window-size' means that splitting a window for displaying a buffer
6784 makes a new parent window provided `display-buffer' is supposed to
6785 explicitly set the window's size due to the presence of a
6786 `window-height' or `window-width' entry in the alist used by
6787 `display-buffer'. Otherwise, this value is handled like nil.
6789 `temp-buffer' means that splitting a window for displaying a temporary
6790 buffer always makes a new parent window. Otherwise, this value is
6793 `display-buffer' means that splitting a window for displaying a buffer
6794 always makes a new parent window. Since temporary buffers are
6795 displayed by the function `display-buffer', this value is stronger
6796 than `temp-buffer'. Splitting a window for other purpose makes a
6797 new parent window only if needed.
6799 t means that splitting a window always creates a new parent window. If
6800 all splits behave this way, each frame's window tree is a binary
6801 tree and every window but the frame's root window has exactly one
6804 Other values are reserved for future use. */);
6805 Vwindow_combination_limit
= Qwindow_size
;
6807 DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters
,
6808 doc
: /* Alist of persistent window parameters.
6809 This alist specifies which window parameters shall get saved by
6810 `current-window-configuration' and `window-state-get' and subsequently
6811 restored to their previous values by `set-window-configuration' and
6814 The car of each entry of this alist is the symbol specifying the
6815 parameter. The cdr is one of the following:
6817 nil means the parameter is neither saved by `window-state-get' nor by
6818 `current-window-configuration'.
6820 t means the parameter is saved by `current-window-configuration' and,
6821 provided its WRITABLE argument is nil, by `window-state-get'.
6823 The symbol `writable' means the parameter is saved unconditionally by
6824 both `current-window-configuration' and `window-state-get'. Do not use
6825 this value for parameters without read syntax (like windows or frames).
6827 Parameters not saved by `current-window-configuration' or
6828 `window-state-get' are left alone by `set-window-configuration'
6829 respectively are not installed by `window-state-put'. */);
6830 Vwindow_persistent_parameters
= list1 (Fcons (Qclone_of
, Qt
));
6832 defsubr (&Sselected_window
);
6833 defsubr (&Sminibuffer_window
);
6834 defsubr (&Swindow_minibuffer_p
);
6835 defsubr (&Swindowp
);
6836 defsubr (&Swindow_valid_p
);
6837 defsubr (&Swindow_live_p
);
6838 defsubr (&Swindow_frame
);
6839 defsubr (&Sframe_root_window
);
6840 defsubr (&Sframe_first_window
);
6841 defsubr (&Sframe_selected_window
);
6842 defsubr (&Sset_frame_selected_window
);
6843 defsubr (&Spos_visible_in_window_p
);
6844 defsubr (&Swindow_line_height
);
6845 defsubr (&Swindow_buffer
);
6846 defsubr (&Swindow_parent
);
6847 defsubr (&Swindow_top_child
);
6848 defsubr (&Swindow_left_child
);
6849 defsubr (&Swindow_next_sibling
);
6850 defsubr (&Swindow_prev_sibling
);
6851 defsubr (&Swindow_combination_limit
);
6852 defsubr (&Sset_window_combination_limit
);
6853 defsubr (&Swindow_use_time
);
6854 defsubr (&Swindow_top_line
);
6855 defsubr (&Swindow_left_column
);
6856 defsubr (&Swindow_total_height
);
6857 defsubr (&Swindow_total_width
);
6858 defsubr (&Swindow_normal_size
);
6859 defsubr (&Swindow_new_total
);
6860 defsubr (&Swindow_new_normal
);
6861 defsubr (&Sset_window_new_total
);
6862 defsubr (&Sset_window_new_normal
);
6863 defsubr (&Swindow_resize_apply
);
6864 defsubr (&Swindow_body_height
);
6865 defsubr (&Swindow_body_width
);
6866 defsubr (&Swindow_hscroll
);
6867 defsubr (&Sset_window_hscroll
);
6868 defsubr (&Swindow_redisplay_end_trigger
);
6869 defsubr (&Sset_window_redisplay_end_trigger
);
6870 defsubr (&Swindow_edges
);
6871 defsubr (&Swindow_pixel_edges
);
6872 defsubr (&Swindow_absolute_pixel_edges
);
6873 defsubr (&Swindow_inside_edges
);
6874 defsubr (&Swindow_inside_pixel_edges
);
6875 defsubr (&Swindow_inside_absolute_pixel_edges
);
6876 defsubr (&Scoordinates_in_window_p
);
6877 defsubr (&Swindow_at
);
6878 defsubr (&Swindow_point
);
6879 defsubr (&Swindow_start
);
6880 defsubr (&Swindow_end
);
6881 defsubr (&Sset_window_point
);
6882 defsubr (&Sset_window_start
);
6883 defsubr (&Swindow_dedicated_p
);
6884 defsubr (&Sset_window_dedicated_p
);
6885 defsubr (&Swindow_display_table
);
6886 defsubr (&Sset_window_display_table
);
6887 defsubr (&Snext_window
);
6888 defsubr (&Sprevious_window
);
6889 defsubr (&Sget_buffer_window
);
6890 defsubr (&Sdelete_other_windows_internal
);
6891 defsubr (&Sdelete_window_internal
);
6892 defsubr (&Sresize_mini_window_internal
);
6893 defsubr (&Sset_window_buffer
);
6894 defsubr (&Srun_window_configuration_change_hook
);
6895 defsubr (&Sselect_window
);
6896 defsubr (&Sforce_window_update
);
6897 defsubr (&Ssplit_window_internal
);
6898 defsubr (&Sscroll_up
);
6899 defsubr (&Sscroll_down
);
6900 defsubr (&Sscroll_left
);
6901 defsubr (&Sscroll_right
);
6902 defsubr (&Sother_window_for_scrolling
);
6903 defsubr (&Sscroll_other_window
);
6904 defsubr (&Sminibuffer_selected_window
);
6905 defsubr (&Srecenter
);
6906 defsubr (&Swindow_text_height
);
6907 defsubr (&Smove_to_window_line
);
6908 defsubr (&Swindow_configuration_p
);
6909 defsubr (&Swindow_configuration_frame
);
6910 defsubr (&Sset_window_configuration
);
6911 defsubr (&Scurrent_window_configuration
);
6912 defsubr (&Sset_window_margins
);
6913 defsubr (&Swindow_margins
);
6914 defsubr (&Sset_window_fringes
);
6915 defsubr (&Swindow_fringes
);
6916 defsubr (&Sset_window_scroll_bars
);
6917 defsubr (&Swindow_scroll_bars
);
6918 defsubr (&Swindow_vscroll
);
6919 defsubr (&Sset_window_vscroll
);
6920 defsubr (&Scompare_window_configurations
);
6921 defsubr (&Swindow_list
);
6922 defsubr (&Swindow_list_1
);
6923 defsubr (&Swindow_prev_buffers
);
6924 defsubr (&Sset_window_prev_buffers
);
6925 defsubr (&Swindow_next_buffers
);
6926 defsubr (&Sset_window_next_buffers
);
6927 defsubr (&Swindow_parameters
);
6928 defsubr (&Swindow_parameter
);
6929 defsubr (&Sset_window_parameter
);
6933 keys_of_window (void)
6935 initial_define_key (control_x_map
, '<', "scroll-left");
6936 initial_define_key (control_x_map
, '>', "scroll-right");
6938 initial_define_key (global_map
, Ctl ('V'), "scroll-up-command");
6939 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
6940 initial_define_key (meta_map
, 'v', "scroll-down-command");