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 */
56 Lisp_Object Qwindowp
, Qwindow_live_p
;
57 static Lisp_Object Qwindow_valid_p
;
58 static Lisp_Object Qwindow_configuration_p
, Qrecord_window_buffer
;
59 static Lisp_Object Qwindow_deletable_p
, Qdelete_window
, Qdisplay_buffer
;
60 static Lisp_Object Qreplace_buffer_in_windows
, Qget_mru_window
;
61 static Lisp_Object Qwindow_resize_root_window
, Qwindow_resize_root_window_vertically
;
62 static Lisp_Object Qscroll_up
, Qscroll_down
, Qscroll_command
;
63 static Lisp_Object Qsafe
, Qabove
, Qbelow
, Qwindow_size
, Qclone_of
;
65 static int displayed_window_lines (struct window
*);
66 static int count_windows (struct window
*);
67 static int get_leaf_windows (struct window
*, struct window
**, int);
68 static void window_scroll (Lisp_Object
, EMACS_INT
, int, int);
69 static void window_scroll_pixel_based (Lisp_Object
, int, int, int);
70 static void window_scroll_line_based (Lisp_Object
, int, int, int);
71 static int freeze_window_start (struct window
*, void *);
72 static Lisp_Object
window_list (void);
73 static int add_window_to_list (struct window
*, void *);
74 static int candidate_window_p (Lisp_Object
, Lisp_Object
, Lisp_Object
,
76 static Lisp_Object
next_window (Lisp_Object
, Lisp_Object
,
78 static void decode_next_window_args (Lisp_Object
*, Lisp_Object
*,
80 static void foreach_window (struct frame
*,
81 int (* fn
) (struct window
*, void *),
83 static int foreach_window_1 (struct window
*,
84 int (* fn
) (struct window
*, void *),
86 static Lisp_Object
window_list_1 (Lisp_Object
, Lisp_Object
, Lisp_Object
);
87 static int window_resize_check (struct window
*, int);
88 static void window_resize_apply (struct window
*, int);
89 static Lisp_Object
select_window (Lisp_Object
, Lisp_Object
, int);
90 static void select_window_1 (Lisp_Object
, bool);
92 /* This is the window in which the terminal's cursor should
93 be left when nothing is being done with it. This must
94 always be a leaf window, and its buffer is selected by
95 the top level editing loop at the end of each command.
97 This value is always the same as
98 FRAME_SELECTED_WINDOW (selected_frame). */
99 Lisp_Object selected_window
;
101 /* A list of all windows for use by next_window and Fwindow_list.
102 Functions creating or deleting windows should invalidate this cache
103 by setting it to nil. */
104 Lisp_Object Vwindow_list
;
106 /* The mini-buffer window of the selected frame.
107 Note that you cannot test for mini-bufferness of an arbitrary window
108 by comparing against this; but you can test for mini-bufferness of
109 the selected window. */
110 Lisp_Object minibuf_window
;
112 /* Non-nil means it is the window whose mode line should be
113 shown as the selected window when the minibuffer is selected. */
114 Lisp_Object minibuf_selected_window
;
116 /* Hook run at end of temp_output_buffer_show. */
117 static Lisp_Object Qtemp_buffer_show_hook
;
119 /* Incremented for each window created. */
120 static int sequence_number
;
122 /* Nonzero after init_window_once has finished. */
123 static int window_initialized
;
125 /* Hook to run when window config changes. */
126 static Lisp_Object Qwindow_configuration_change_hook
;
128 /* Used by the function window_scroll_pixel_based */
129 static int window_scroll_pixel_based_preserve_x
;
130 static int window_scroll_pixel_based_preserve_y
;
132 /* Same for window_scroll_line_based. */
133 static EMACS_INT window_scroll_preserve_hpos
;
134 static EMACS_INT window_scroll_preserve_vpos
;
136 /* These setters are used only in this file, so they can be private. */
138 wset_combination_limit (struct window
*w
, Lisp_Object val
)
140 w
->combination_limit
= val
;
143 wset_dedicated (struct window
*w
, Lisp_Object val
)
148 wset_display_table (struct window
*w
, Lisp_Object val
)
150 w
->display_table
= val
;
153 wset_hchild (struct window
*w
, Lisp_Object val
)
158 wset_left_fringe_width (struct window
*w
, Lisp_Object val
)
160 w
->left_fringe_width
= val
;
163 wset_left_margin_cols (struct window
*w
, Lisp_Object val
)
165 w
->left_margin_cols
= val
;
168 wset_new_normal (struct window
*w
, Lisp_Object val
)
173 wset_new_total (struct window
*w
, Lisp_Object val
)
178 wset_normal_cols (struct window
*w
, Lisp_Object val
)
180 w
->normal_cols
= val
;
183 wset_normal_lines (struct window
*w
, Lisp_Object val
)
185 w
->normal_lines
= val
;
188 wset_parent (struct window
*w
, Lisp_Object val
)
193 wset_pointm (struct window
*w
, Lisp_Object val
)
198 wset_right_fringe_width (struct window
*w
, Lisp_Object val
)
200 w
->right_fringe_width
= val
;
203 wset_right_margin_cols (struct window
*w
, Lisp_Object val
)
205 w
->right_margin_cols
= val
;
208 wset_scroll_bar_width (struct window
*w
, Lisp_Object val
)
210 w
->scroll_bar_width
= val
;
213 wset_start (struct window
*w
, Lisp_Object val
)
218 wset_temslot (struct window
*w
, Lisp_Object val
)
223 wset_vchild (struct window
*w
, Lisp_Object val
)
228 wset_vertical_scroll_bar_type (struct window
*w
, Lisp_Object val
)
230 w
->vertical_scroll_bar_type
= val
;
233 wset_window_parameters (struct window
*w
, Lisp_Object val
)
235 w
->window_parameters
= val
;
239 decode_live_window (register Lisp_Object window
)
242 return XWINDOW (selected_window
);
244 CHECK_LIVE_WINDOW (window
);
245 return XWINDOW (window
);
249 decode_any_window (register Lisp_Object window
)
254 return XWINDOW (selected_window
);
256 CHECK_WINDOW (window
);
257 w
= XWINDOW (window
);
261 static struct window
*
262 decode_valid_window (register Lisp_Object window
)
267 return XWINDOW (selected_window
);
269 CHECK_VALID_WINDOW (window
);
270 w
= XWINDOW (window
);
274 /* Called when W's buffer slot is changed. ARG -1 means that W is about to
275 cease its buffer, and 1 means that W is about to set up the new one. */
278 adjust_window_count (struct window
*w
, int arg
)
280 eassert (eabs (arg
) == 1);
281 if (BUFFERP (w
->buffer
))
283 struct buffer
*b
= XBUFFER (w
->buffer
);
287 b
->window_count
+= arg
;
288 eassert (b
->window_count
>= 0);
289 /* Catch redisplay's attention. */
290 w
->window_end_valid
= 0;
294 /* Set W's buffer slot to VAL and recompute number
295 of windows showing VAL if it is a buffer. */
298 wset_buffer (struct window
*w
, Lisp_Object val
)
300 adjust_window_count (w
, -1);
302 adjust_window_count (w
, 1);
305 /* Build a frequently used 4-integer (X Y W H) list. */
308 list4i (EMACS_INT x
, EMACS_INT y
, EMACS_INT w
, EMACS_INT h
)
310 return list4 (make_number (x
), make_number (y
),
311 make_number (w
), make_number (h
));
314 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
315 doc
: /* Return t if OBJECT is a window and nil otherwise. */)
318 return WINDOWP (object
) ? Qt
: Qnil
;
321 DEFUN ("window-valid-p", Fwindow_valid_p
, Swindow_valid_p
, 1, 1, 0,
322 doc
: /* Return t if OBJECT is a valid window and nil otherwise.
323 A valid window is either a window that displays a buffer or an internal
324 window. Deleted windows are not live. */)
327 return WINDOW_VALID_P (object
) ? Qt
: Qnil
;
330 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
331 doc
: /* Return t if OBJECT is a live window and nil otherwise.
332 A live window is a window that displays a buffer.
333 Internal windows and deleted windows are not live. */)
336 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
339 /* Frames and windows. */
340 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 0, 1, 0,
341 doc
: /* Return the frame that window WINDOW is on.
342 WINDOW must be a valid window and defaults to the selected one. */)
345 return decode_valid_window (window
)->frame
;
348 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
349 doc
: /* Return the root window of FRAME-OR-WINDOW.
350 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
351 With a frame argument, return that frame's root window.
352 With a window argument, return the root window of that window's frame. */)
353 (Lisp_Object frame_or_window
)
357 if (NILP (frame_or_window
))
358 window
= SELECTED_FRAME ()->root_window
;
359 else if (WINDOW_VALID_P (frame_or_window
))
360 window
= XFRAME (XWINDOW (frame_or_window
)->frame
)->root_window
;
363 CHECK_LIVE_FRAME (frame_or_window
);
364 window
= XFRAME (frame_or_window
)->root_window
;
370 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
371 doc
: /* Return the minibuffer window for frame FRAME.
372 If FRAME is omitted or nil, it defaults to the selected frame. */)
375 return FRAME_MINIBUF_WINDOW (decode_live_frame (frame
));
378 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
,
379 Swindow_minibuffer_p
, 0, 1, 0,
380 doc
: /* Return non-nil if WINDOW is a minibuffer window.
381 WINDOW must be a valid window and defaults to the selected one. */)
384 return MINI_WINDOW_P (decode_valid_window (window
)) ? Qt
: Qnil
;
387 /* Don't move this to window.el - this must be a safe routine. */
388 DEFUN ("frame-first-window", Fframe_first_window
, Sframe_first_window
, 0, 1, 0,
389 doc
: /* Return the topmost, leftmost live window on FRAME-OR-WINDOW.
390 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
391 Else if FRAME-OR-WINDOW denotes a valid window, return the first window
392 of that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
393 the first window of that frame. */)
394 (Lisp_Object frame_or_window
)
398 if (NILP (frame_or_window
))
399 window
= SELECTED_FRAME ()->root_window
;
400 else if (WINDOW_VALID_P (frame_or_window
))
401 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
404 CHECK_LIVE_FRAME (frame_or_window
);
405 window
= XFRAME (frame_or_window
)->root_window
;
408 while (NILP (XWINDOW (window
)->buffer
))
410 if (! NILP (XWINDOW (window
)->hchild
))
411 window
= XWINDOW (window
)->hchild
;
412 else if (! NILP (XWINDOW (window
)->vchild
))
413 window
= XWINDOW (window
)->vchild
;
421 DEFUN ("frame-selected-window", Fframe_selected_window
,
422 Sframe_selected_window
, 0, 1, 0,
423 doc
: /* Return the selected window of FRAME-OR-WINDOW.
424 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
425 Else if FRAME-OR-WINDOW denotes a valid window, return the selected
426 window of that window's frame. If FRAME-OR-WINDOW denotes a live frame,
427 return the selected window of that frame. */)
428 (Lisp_Object frame_or_window
)
432 if (NILP (frame_or_window
))
433 window
= SELECTED_FRAME ()->selected_window
;
434 else if (WINDOW_VALID_P (frame_or_window
))
435 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->selected_window
;
438 CHECK_LIVE_FRAME (frame_or_window
);
439 window
= XFRAME (frame_or_window
)->selected_window
;
445 DEFUN ("set-frame-selected-window", Fset_frame_selected_window
,
446 Sset_frame_selected_window
, 2, 3, 0,
447 doc
: /* Set selected window of FRAME to WINDOW.
448 FRAME must be a live frame and defaults to the selected one. If FRAME
449 is the selected frame, this makes WINDOW the selected window. Optional
450 argument NORECORD non-nil means to neither change the order of recently
451 selected windows nor the buffer list. WINDOW must denote a live window.
453 (Lisp_Object frame
, Lisp_Object window
, Lisp_Object norecord
)
456 frame
= selected_frame
;
458 CHECK_LIVE_FRAME (frame
);
459 CHECK_LIVE_WINDOW (window
);
461 if (! EQ (frame
, WINDOW_FRAME (XWINDOW (window
))))
462 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
464 if (EQ (frame
, selected_frame
))
465 return Fselect_window (window
, norecord
);
468 fset_selected_window (XFRAME (frame
), window
);
473 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
474 doc
: /* Return the selected window.
475 The selected window is the window in which the standard cursor for
476 selected windows appears and to which many commands apply. */)
479 return selected_window
;
482 int window_select_count
;
484 /* If select_window is called with inhibit_point_swap non-zero it will
485 not store point of the old selected window's buffer back into that
486 window's pointm slot. This is needed by Fset_window_configuration to
487 avoid that the display routine is called with selected_window set to
488 Qnil causing a subsequent crash. */
490 select_window (Lisp_Object window
, Lisp_Object norecord
, int inhibit_point_swap
)
492 register struct window
*w
;
495 CHECK_LIVE_WINDOW (window
);
497 w
= XWINDOW (window
);
498 w
->frozen_window_start_p
= 0;
502 w
->use_time
= ++window_select_count
;
503 record_buffer (w
->buffer
);
506 /* Make the selected window's buffer current. */
507 Fset_buffer (w
->buffer
);
509 if (EQ (window
, selected_window
) && !inhibit_point_swap
)
512 sf
= SELECTED_FRAME ();
513 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
515 fset_selected_window (XFRAME (WINDOW_FRAME (w
)), window
);
516 /* Use this rather than Fhandle_switch_frame
517 so that FRAME_FOCUS_FRAME is moved appropriately as we
518 move around in the state where a minibuffer in a separate
520 Fselect_frame (WINDOW_FRAME (w
), norecord
);
521 /* Fselect_frame called us back so we've done all the work already. */
522 eassert (EQ (window
, selected_window
));
526 fset_selected_window (sf
, window
);
528 select_window_1 (window
, inhibit_point_swap
);
530 bset_last_selected_window (XBUFFER (w
->buffer
), window
);
531 windows_or_buffers_changed
++;
535 /* Select window with a minimum of fuss, i.e. don't record the change anywhere
536 (not even for redisplay's benefit), and assume that the window's frame is
539 select_window_1 (Lisp_Object window
, bool inhibit_point_swap
)
541 /* Store the old selected window's buffer's point in pointm of the old
542 selected window. It belongs to that window, and when the window is
543 not selected, must be in the window. */
544 if (!inhibit_point_swap
)
546 struct window
*ow
= XWINDOW (selected_window
);
547 if (! NILP (ow
->buffer
))
548 set_marker_both (ow
->pointm
, ow
->buffer
,
549 BUF_PT (XBUFFER (ow
->buffer
)),
550 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
553 selected_window
= window
;
555 /* Go to the point recorded in the window.
556 This is important when the buffer is in more
557 than one window. It also matters when
558 redisplay_window has altered point after scrolling,
559 because it makes the change only in the window. */
561 register ptrdiff_t new_point
= marker_position (XWINDOW (window
)->pointm
);
562 if (new_point
< BEGV
)
564 else if (new_point
> ZV
)
571 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
572 doc
: /* Select WINDOW which must be a live window.
573 Also make WINDOW's frame the selected frame and WINDOW that frame's
574 selected window. In addition, make WINDOW's buffer current and set that
575 buffer's value of `point' to the value of WINDOW's `window-point'.
578 Optional second arg NORECORD non-nil means do not put this buffer at the
579 front of the buffer list and do not make this window the most recently
582 Note that the main editor command loop sets the current buffer to the
583 buffer of the selected window before each command. */)
584 (register Lisp_Object window
, Lisp_Object norecord
)
586 return select_window (window
, norecord
, 0);
589 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
590 doc
: /* Return the buffer displayed in window WINDOW.
591 If WINDOW is omitted or nil, it defaults to the selected window.
592 Return nil for an internal window or a deleted window. */)
595 return decode_any_window (window
)->buffer
;
598 DEFUN ("window-parent", Fwindow_parent
, Swindow_parent
, 0, 1, 0,
599 doc
: /* Return the parent window of window WINDOW.
600 WINDOW must be a valid window and defaults to the selected one.
601 Return nil for a window with no parent (e.g. a root window). */)
604 return decode_valid_window (window
)->parent
;
607 DEFUN ("window-top-child", Fwindow_top_child
, Swindow_top_child
, 0, 1, 0,
608 doc
: /* Return the topmost child window of window WINDOW.
609 WINDOW must be a valid window and defaults to the selected one.
610 Return nil if WINDOW is a live window (live windows have no children).
611 Return nil if WINDOW is an internal window whose children form a
612 horizontal combination. */)
615 return decode_valid_window (window
)->vchild
;
618 DEFUN ("window-left-child", Fwindow_left_child
, Swindow_left_child
, 0, 1, 0,
619 doc
: /* Return the leftmost child window of window WINDOW.
620 WINDOW must be a valid window and defaults to the selected one.
621 Return nil if WINDOW is a live window (live windows have no children).
622 Return nil if WINDOW is an internal window whose children form a
623 vertical combination. */)
626 return decode_valid_window (window
)->hchild
;
629 DEFUN ("window-next-sibling", Fwindow_next_sibling
, Swindow_next_sibling
, 0, 1, 0,
630 doc
: /* Return the next sibling window of window WINDOW.
631 WINDOW must be a valid window and defaults to the selected one.
632 Return nil if WINDOW has no next sibling. */)
635 return decode_valid_window (window
)->next
;
638 DEFUN ("window-prev-sibling", Fwindow_prev_sibling
, Swindow_prev_sibling
, 0, 1, 0,
639 doc
: /* Return the previous sibling window of window WINDOW.
640 WINDOW must be a valid window and defaults to the selected one.
641 Return nil if WINDOW has no previous sibling. */)
644 return decode_valid_window (window
)->prev
;
647 DEFUN ("window-combination-limit", Fwindow_combination_limit
, Swindow_combination_limit
, 1, 1, 0,
648 doc
: /* Return combination limit of window WINDOW.
649 If the return value is nil, child windows of WINDOW can be recombined with
650 WINDOW's siblings. A return value of t means that child windows of
651 WINDOW are never \(re-)combined with WINDOW's siblings.
653 WINDOW must be a valid window. The return value is meaningful for
654 internal windows only. */)
657 CHECK_VALID_WINDOW (window
);
658 return XWINDOW (window
)->combination_limit
;
661 DEFUN ("set-window-combination-limit", Fset_window_combination_limit
, Sset_window_combination_limit
, 2, 2, 0,
662 doc
: /* Set combination limit of window WINDOW to LIMIT; return LIMIT.
663 If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's
664 siblings. LIMIT t means that child windows of WINDOW are never
665 \(re-)combined with WINDOW's siblings. Other values are reserved for
668 WINDOW must be a valid window. Setting the combination limit is
669 meaningful for internal windows only. */)
670 (Lisp_Object window
, Lisp_Object limit
)
672 wset_combination_limit (decode_valid_window (window
), limit
);
676 DEFUN ("window-use-time", Fwindow_use_time
, Swindow_use_time
, 0, 1, 0,
677 doc
: /* Return the use time of window WINDOW.
678 WINDOW must be a live window and defaults to the selected one.
679 The window with the highest use time is the most recently selected
680 one. The window with the lowest use time is the least recently
684 return make_number (decode_live_window (window
)->use_time
);
687 DEFUN ("window-total-height", Fwindow_total_height
, Swindow_total_height
, 0, 1, 0,
688 doc
: /* Return the total height, in lines, of window WINDOW.
689 WINDOW must be a valid window and defaults to the selected one.
691 The return value includes the mode line and header line, if any.
692 If WINDOW is an internal window, the total height is the height
693 of the screen areas spanned by its children.
695 On a graphical display, this total height is reported as an
696 integer multiple of the default character height. */)
699 return decode_valid_window (window
)->total_lines
;
702 DEFUN ("window-total-width", Fwindow_total_width
, Swindow_total_width
, 0, 1, 0,
703 doc
: /* Return the total width, in columns, of window WINDOW.
704 WINDOW must be a valid window and defaults to the selected one.
706 The return value includes any vertical dividers or scroll bars
707 belonging to WINDOW. If WINDOW is an internal window, the total width
708 is the width of the screen areas spanned by its children.
710 On a graphical display, this total width is reported as an
711 integer multiple of the default character width. */)
714 return decode_valid_window (window
)->total_cols
;
717 DEFUN ("window-new-total", Fwindow_new_total
, Swindow_new_total
, 0, 1, 0,
718 doc
: /* Return the new total size of window WINDOW.
719 WINDOW must be a valid window and defaults to the selected one. */)
722 return decode_valid_window (window
)->new_total
;
725 DEFUN ("window-normal-size", Fwindow_normal_size
, Swindow_normal_size
, 0, 2, 0,
726 doc
: /* Return the normal height of window WINDOW.
727 WINDOW must be a valid window and defaults to the selected one.
728 If HORIZONTAL is non-nil, return the normal width of WINDOW. */)
729 (Lisp_Object window
, Lisp_Object horizontal
)
731 struct window
*w
= decode_valid_window (window
);
733 return NILP (horizontal
) ? w
->normal_lines
: w
->normal_cols
;
736 DEFUN ("window-new-normal", Fwindow_new_normal
, Swindow_new_normal
, 0, 1, 0,
737 doc
: /* Return new normal size of window WINDOW.
738 WINDOW must be a valid window and defaults to the selected one. */)
741 return decode_valid_window (window
)->new_normal
;
744 DEFUN ("window-left-column", Fwindow_left_column
, Swindow_left_column
, 0, 1, 0,
745 doc
: /* Return left column of window WINDOW.
746 This is the distance, in columns, between the left edge of WINDOW and
747 the left edge of the frame's window area. For instance, the return
748 value is 0 if there is no window to the left of WINDOW.
750 WINDOW must be a valid window and defaults to the selected one. */)
753 return decode_valid_window (window
)->left_col
;
756 DEFUN ("window-top-line", Fwindow_top_line
, Swindow_top_line
, 0, 1, 0,
757 doc
: /* Return top line of window WINDOW.
758 This is the distance, in lines, between the top of WINDOW and the top
759 of the frame's window area. For instance, the return value is 0 if
760 there is no window above WINDOW.
762 WINDOW must be a valid window and defaults to the selected one. */)
765 return decode_valid_window (window
)->top_line
;
768 /* Return the number of lines of W's body. Don't count any mode or
772 window_body_lines (struct window
*w
)
774 int height
= XFASTINT (w
->total_lines
);
776 if (!MINI_WINDOW_P (w
))
778 if (WINDOW_WANTS_MODELINE_P (w
))
780 if (WINDOW_WANTS_HEADER_LINE_P (w
))
787 /* Return the number of columns of W's body. Don't count columns
788 occupied by the scroll bar or the vertical bar separating W from its
789 right sibling. On window-systems don't count fringes or display
793 window_body_cols (struct window
*w
)
795 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
796 int width
= XINT (w
->total_cols
);
798 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
799 /* Scroll bars occupy a few columns. */
800 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
801 else if (!FRAME_WINDOW_P (f
)
802 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
803 /* The column of `|' characters separating side-by-side windows
804 occupies one column only. */
807 /* Display margins cannot be used for normal text. */
808 width
-= WINDOW_LEFT_MARGIN_COLS (w
) + WINDOW_RIGHT_MARGIN_COLS (w
);
810 if (FRAME_WINDOW_P (f
))
811 /* On window-systems, fringes cannot be used for normal text. */
812 width
-= WINDOW_FRINGE_COLS (w
);
817 DEFUN ("window-body-height", Fwindow_body_height
, Swindow_body_height
, 0, 1, 0,
818 doc
: /* Return the height, in lines, of WINDOW's text area.
819 WINDOW must be a live window and defaults to the selected one.
821 The returned height does not include the mode line or header line.
822 On a graphical display, the height is expressed as an integer multiple
823 of the default character height. If a line at the bottom of the text
824 area is only partially visible, that counts as a whole line; to
825 exclude partially-visible lines, use `window-text-height'. */)
828 return make_number (window_body_lines (decode_live_window (window
)));
831 DEFUN ("window-body-width", Fwindow_body_width
, Swindow_body_width
, 0, 1, 0,
832 doc
: /* Return the width, in columns, of WINDOW's text area.
833 WINDOW must be a live window and defaults to the selected one.
835 The return value does not include any vertical dividers, fringe or
836 marginal areas, or scroll bars. On a graphical display, the width is
837 expressed as an integer multiple of the default character width. */)
840 return make_number (window_body_cols (decode_live_window (window
)));
843 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
844 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
845 WINDOW must be a live window and defaults to the selected one. */)
848 return make_number (decode_live_window (window
)->hscroll
);
851 /* Set W's horizontal scroll amount to HSCROLL clipped to a reasonable
852 range, returning the new amount as a fixnum. */
854 set_window_hscroll (struct window
*w
, EMACS_INT hscroll
)
856 /* Horizontal scrolling has problems with large scroll amounts.
857 It's too slow with long lines, and even with small lines the
858 display can be messed up. For now, though, impose only the limits
859 required by the internal representation: horizontal scrolling must
860 fit in fixnum (since it's visible to Elisp) and into ptrdiff_t
861 (since it's stored in a ptrdiff_t). */
862 ptrdiff_t hscroll_max
= min (MOST_POSITIVE_FIXNUM
, PTRDIFF_MAX
);
863 ptrdiff_t new_hscroll
= clip_to_bounds (0, hscroll
, hscroll_max
);
865 /* Prevent redisplay shortcuts when changing the hscroll. */
866 if (w
->hscroll
!= new_hscroll
)
867 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
869 w
->hscroll
= new_hscroll
;
870 return make_number (new_hscroll
);
873 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
874 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
875 WINDOW must be a live window and defaults to the selected one.
876 Clip the number to a reasonable value if out of range.
877 Return the new number. NCOL should be zero or positive.
879 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
880 window so that the location of point moves off-window. */)
881 (Lisp_Object window
, Lisp_Object ncol
)
884 return set_window_hscroll (decode_live_window (window
), XINT (ncol
));
887 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
888 Swindow_redisplay_end_trigger
, 0, 1, 0,
889 doc
: /* Return WINDOW's redisplay end trigger value.
890 WINDOW must be a live window and defaults to the selected one.
891 See `set-window-redisplay-end-trigger' for more information. */)
894 return decode_live_window (window
)->redisplay_end_trigger
;
897 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
898 Sset_window_redisplay_end_trigger
, 2, 2, 0,
899 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
900 WINDOW must be a live window and defaults to the selected one. VALUE
901 should be a buffer position (typically a marker) or nil. If it is a
902 buffer position, then if redisplay in WINDOW reaches a position beyond
903 VALUE, the functions in `redisplay-end-trigger-functions' are called
904 with two arguments: WINDOW, and the end trigger value. Afterwards the
905 end-trigger value is reset to nil. */)
906 (register Lisp_Object window
, Lisp_Object value
)
908 wset_redisplay_end_trigger (decode_live_window (window
), value
);
912 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
913 doc
: /* Return a list of the edge coordinates of WINDOW.
914 WINDOW must be a valid window and defaults to the selected one.
916 The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
917 count by lines, and LEFT and RIGHT count by columns, all relative to 0,
918 0 at top left corner of frame.
920 RIGHT is one more than the rightmost column occupied by WINDOW. BOTTOM
921 is one more than the bottommost row occupied by WINDOW. The edges
922 include the space used by WINDOW's scroll bar, display margins, fringes,
923 header line, and/or mode line. For the edges of just the text area, use
924 `window-inside-edges'. */)
927 register struct window
*w
= decode_valid_window (window
);
929 return list4i (WINDOW_LEFT_EDGE_COL (w
), WINDOW_TOP_EDGE_LINE (w
),
930 WINDOW_RIGHT_EDGE_COL (w
), WINDOW_BOTTOM_EDGE_LINE (w
));
933 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
934 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
935 WINDOW must be a valid window and defaults to the selected one.
937 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
938 0, 0 at the top left corner of the frame.
940 RIGHT is one more than the rightmost x position occupied by WINDOW.
941 BOTTOM is one more than the bottommost y position occupied by WINDOW.
942 The pixel edges include the space used by WINDOW's scroll bar, display
943 margins, fringes, header line, and/or mode line. For the pixel edges
944 of just the text area, use `window-inside-pixel-edges'. */)
947 register struct window
*w
= decode_valid_window (window
);
949 return list4i (WINDOW_LEFT_EDGE_X (w
), WINDOW_TOP_EDGE_Y (w
),
950 WINDOW_RIGHT_EDGE_X (w
), WINDOW_BOTTOM_EDGE_Y (w
));
954 calc_absolute_offset (struct window
*w
, int *add_x
, int *add_y
)
956 struct frame
*f
= XFRAME (w
->frame
);
958 #ifdef FRAME_MENUBAR_HEIGHT
959 *add_y
+= FRAME_MENUBAR_HEIGHT (f
);
961 #ifdef FRAME_TOOLBAR_TOP_HEIGHT
962 *add_y
+= FRAME_TOOLBAR_TOP_HEIGHT (f
);
963 #elif FRAME_TOOLBAR_HEIGHT
964 *add_y
+= FRAME_TOOLBAR_HEIGHT (f
);
966 #ifdef FRAME_NS_TITLEBAR_HEIGHT
967 *add_y
+= FRAME_NS_TITLEBAR_HEIGHT (f
);
969 *add_x
= f
->left_pos
;
970 #ifdef FRAME_TOOLBAR_LEFT_WIDTH
971 *add_x
+= FRAME_TOOLBAR_LEFT_WIDTH (f
);
975 DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges
,
976 Swindow_absolute_pixel_edges
, 0, 1, 0,
977 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
978 WINDOW must be a valid window and defaults to the selected one.
980 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
981 0, 0 at the top left corner of the display.
983 RIGHT is one more than the rightmost x position occupied by WINDOW.
984 BOTTOM is one more than the bottommost y position occupied by WINDOW.
985 The pixel edges include the space used by WINDOW's scroll bar, display
986 margins, fringes, header line, and/or mode line. For the pixel edges
987 of just the text area, use `window-inside-absolute-pixel-edges'. */)
990 register struct window
*w
= decode_valid_window (window
);
993 calc_absolute_offset (w
, &add_x
, &add_y
);
995 return list4i (WINDOW_LEFT_EDGE_X (w
) + add_x
,
996 WINDOW_TOP_EDGE_Y (w
) + add_y
,
997 WINDOW_RIGHT_EDGE_X (w
) + add_x
,
998 WINDOW_BOTTOM_EDGE_Y (w
) + add_y
);
1001 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
1002 doc
: /* Return a list of the edge coordinates of WINDOW.
1003 WINDOW must be a live window and defaults to the selected one.
1005 The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
1006 count by lines, and LEFT and RIGHT count by columns, all relative to 0,
1007 0 at top left corner of frame.
1009 RIGHT is one more than the rightmost column of WINDOW's text area.
1010 BOTTOM is one more than the bottommost row of WINDOW's text area. The
1011 inside edges do not include the space used by the WINDOW's scroll bar,
1012 display margins, fringes, header line, and/or mode line. */)
1013 (Lisp_Object window
)
1015 register struct window
*w
= decode_live_window (window
);
1017 return list4i ((WINDOW_BOX_LEFT_EDGE_COL (w
)
1018 + WINDOW_LEFT_MARGIN_COLS (w
)
1019 + WINDOW_LEFT_FRINGE_COLS (w
)),
1020 (WINDOW_TOP_EDGE_LINE (w
)
1021 + WINDOW_HEADER_LINE_LINES (w
)),
1022 (WINDOW_BOX_RIGHT_EDGE_COL (w
)
1023 - WINDOW_RIGHT_MARGIN_COLS (w
)
1024 - WINDOW_RIGHT_FRINGE_COLS (w
)),
1025 (WINDOW_BOTTOM_EDGE_LINE (w
)
1026 - WINDOW_MODE_LINE_LINES (w
)));
1029 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
1030 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1031 WINDOW must be a live window and defaults to the selected one.
1033 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1034 (0,0) at the top left corner of the frame's window area.
1036 RIGHT is one more than the rightmost x position of WINDOW's text area.
1037 BOTTOM is one more than the bottommost y position of WINDOW's text area.
1038 The inside edges do not include the space used by WINDOW's scroll bar,
1039 display margins, fringes, header line, and/or mode line. */)
1040 (Lisp_Object window
)
1042 register struct window
*w
= decode_live_window (window
);
1044 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w
)
1045 + WINDOW_LEFT_MARGIN_WIDTH (w
)
1046 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
1047 (WINDOW_TOP_EDGE_Y (w
)
1048 + WINDOW_HEADER_LINE_HEIGHT (w
)),
1049 (WINDOW_BOX_RIGHT_EDGE_X (w
)
1050 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
1051 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
1052 (WINDOW_BOTTOM_EDGE_Y (w
)
1053 - WINDOW_MODE_LINE_HEIGHT (w
)));
1056 DEFUN ("window-inside-absolute-pixel-edges",
1057 Fwindow_inside_absolute_pixel_edges
,
1058 Swindow_inside_absolute_pixel_edges
, 0, 1, 0,
1059 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1060 WINDOW must be a live window and defaults to the selected one.
1062 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1063 (0,0) at the top left corner of the frame's window area.
1065 RIGHT is one more than the rightmost x position of WINDOW's text area.
1066 BOTTOM is one more than the bottommost y position of WINDOW's text area.
1067 The inside edges do not include the space used by WINDOW's scroll bar,
1068 display margins, fringes, header line, and/or mode line. */)
1069 (Lisp_Object window
)
1071 register struct window
*w
= decode_live_window (window
);
1074 calc_absolute_offset (w
, &add_x
, &add_y
);
1076 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w
)
1077 + WINDOW_LEFT_MARGIN_WIDTH (w
)
1078 + WINDOW_LEFT_FRINGE_WIDTH (w
) + add_x
),
1079 (WINDOW_TOP_EDGE_Y (w
)
1080 + WINDOW_HEADER_LINE_HEIGHT (w
) + add_y
),
1081 (WINDOW_BOX_RIGHT_EDGE_X (w
)
1082 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
1083 - WINDOW_RIGHT_FRINGE_WIDTH (w
) + add_x
),
1084 (WINDOW_BOTTOM_EDGE_Y (w
)
1085 - WINDOW_MODE_LINE_HEIGHT (w
) + add_y
));
1088 /* Test if the character at column X, row Y is within window W.
1089 If it is not, return ON_NOTHING;
1090 if it is in the window's text area, return ON_TEXT;
1091 if it is on the window's modeline, return ON_MODE_LINE;
1092 if it is on the border between the window and its right sibling,
1093 return ON_VERTICAL_BORDER.
1094 if it is on a scroll bar, return ON_SCROLL_BAR.
1095 if it is on the window's top line, return ON_HEADER_LINE;
1096 if it is in left or right fringe of the window,
1097 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
1098 if it is in the marginal area to the left/right of the window,
1099 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN.
1101 X and Y are frame relative pixel coordinates. */
1103 static enum window_part
1104 coordinates_in_window (register struct window
*w
, int x
, int y
)
1106 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1107 enum window_part part
;
1108 int ux
= FRAME_COLUMN_WIDTH (f
);
1109 int left_x
= WINDOW_LEFT_EDGE_X (w
);
1110 int right_x
= WINDOW_RIGHT_EDGE_X (w
);
1111 int top_y
= WINDOW_TOP_EDGE_Y (w
);
1112 int bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
1113 /* The width of the area where the vertical line can be dragged.
1114 (Between mode lines for instance. */
1115 int grabbable_width
= ux
;
1116 int lmargin_width
, rmargin_width
, text_left
, text_right
;
1118 /* Outside any interesting row or column? */
1119 if (y
< top_y
|| y
>= bottom_y
|| x
< left_x
|| x
>= right_x
)
1122 /* On the mode line or header line? */
1123 if ((WINDOW_WANTS_MODELINE_P (w
)
1124 && y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
)
1125 && (part
= ON_MODE_LINE
))
1126 || (WINDOW_WANTS_HEADER_LINE_P (w
)
1127 && y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
)
1128 && (part
= ON_HEADER_LINE
)))
1130 /* If it's under/over the scroll bar portion of the mode/header
1131 line, say it's on the vertical line. That's to be able to
1132 resize windows horizontally in case we're using toolkit scroll
1133 bars. Note: If scrollbars are on the left, the window that
1134 must be eventually resized is that on the left of WINDOW. */
1135 if ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1136 && !WINDOW_LEFTMOST_P (w
)
1137 && eabs (x
- left_x
) < grabbable_width
)
1138 || (!WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1139 && !WINDOW_RIGHTMOST_P (w
)
1140 && eabs (x
- right_x
) < grabbable_width
))
1141 return ON_VERTICAL_BORDER
;
1146 /* In what's below, we subtract 1 when computing right_x because we
1147 want the rightmost pixel, which is given by left_pixel+width-1. */
1148 if (w
->pseudo_window_p
)
1151 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
1155 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
1156 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
1159 /* Outside any interesting column? */
1160 if (x
< left_x
|| x
> right_x
)
1161 return ON_SCROLL_BAR
;
1163 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
1164 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
1166 text_left
= window_box_left (w
, TEXT_AREA
);
1167 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
1169 if (FRAME_WINDOW_P (f
))
1171 if (!w
->pseudo_window_p
1172 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
1173 && !WINDOW_RIGHTMOST_P (w
)
1174 && (eabs (x
- right_x
) < grabbable_width
))
1175 return ON_VERTICAL_BORDER
;
1177 /* Need to say "x > right_x" rather than >=, since on character
1178 terminals, the vertical line's x coordinate is right_x. */
1179 else if (!w
->pseudo_window_p
1180 && !WINDOW_RIGHTMOST_P (w
)
1181 && x
> right_x
- ux
)
1182 return ON_VERTICAL_BORDER
;
1186 if (lmargin_width
> 0
1187 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1188 ? (x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
1189 : (x
< left_x
+ lmargin_width
)))
1190 return ON_LEFT_MARGIN
;
1192 return ON_LEFT_FRINGE
;
1195 if (x
>= text_right
)
1197 if (rmargin_width
> 0
1198 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1199 ? (x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
1200 : (x
>= right_x
- rmargin_width
)))
1201 return ON_RIGHT_MARGIN
;
1203 return ON_RIGHT_FRINGE
;
1206 /* Everything special ruled out - must be on text area */
1210 /* Take X is the frame-relative pixel x-coordinate, and return the
1211 x-coordinate relative to part PART of window W. */
1213 window_relative_x_coord (struct window
*w
, enum window_part part
, int x
)
1215 int left_x
= (w
->pseudo_window_p
) ? 0 : WINDOW_BOX_LEFT_EDGE_X (w
);
1220 return x
- window_box_left (w
, TEXT_AREA
);
1222 case ON_LEFT_FRINGE
:
1225 case ON_RIGHT_FRINGE
:
1226 return x
- left_x
- WINDOW_LEFT_FRINGE_WIDTH (w
);
1228 case ON_LEFT_MARGIN
:
1230 - ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1231 ? WINDOW_LEFT_FRINGE_WIDTH (w
) : 0));
1233 case ON_RIGHT_MARGIN
:
1235 - ((w
->pseudo_window_p
)
1236 ? WINDOW_TOTAL_WIDTH (w
)
1237 : WINDOW_BOX_RIGHT_EDGE_X (w
))
1238 + window_box_width (w
, RIGHT_MARGIN_AREA
)
1239 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1240 ? WINDOW_RIGHT_FRINGE_WIDTH (w
) : 0));
1243 /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */
1248 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
1249 Scoordinates_in_window_p
, 2, 2, 0,
1250 doc
: /* Return non-nil if COORDINATES are in WINDOW.
1251 WINDOW must be a live window and defaults to the selected one.
1252 COORDINATES is a cons of the form (X . Y), X and Y being distances
1253 measured in characters from the upper-left corner of the frame.
1254 \(0 . 0) denotes the character in the upper left corner of the
1256 If COORDINATES are in the text portion of WINDOW,
1257 the coordinates relative to the window are returned.
1258 If they are in the mode line of WINDOW, `mode-line' is returned.
1259 If they are in the top mode line of WINDOW, `header-line' is returned.
1260 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1261 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1262 If they are on the border between WINDOW and its right sibling,
1263 `vertical-line' is returned.
1264 If they are in the windows's left or right marginal areas, `left-margin'\n\
1265 or `right-margin' is returned. */)
1266 (register Lisp_Object coordinates
, Lisp_Object window
)
1273 w
= decode_live_window (window
);
1274 f
= XFRAME (w
->frame
);
1275 CHECK_CONS (coordinates
);
1276 lx
= Fcar (coordinates
);
1277 ly
= Fcdr (coordinates
);
1278 CHECK_NUMBER_OR_FLOAT (lx
);
1279 CHECK_NUMBER_OR_FLOAT (ly
);
1280 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1281 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1283 switch (coordinates_in_window (w
, x
, y
))
1289 /* Convert X and Y to window relative pixel coordinates, and
1290 return the canonical char units. */
1291 x
-= window_box_left (w
, TEXT_AREA
);
1292 y
-= WINDOW_TOP_EDGE_Y (w
);
1293 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
1294 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
1299 case ON_VERTICAL_BORDER
:
1300 return Qvertical_line
;
1302 case ON_HEADER_LINE
:
1303 return Qheader_line
;
1305 case ON_LEFT_FRINGE
:
1306 return Qleft_fringe
;
1308 case ON_RIGHT_FRINGE
:
1309 return Qright_fringe
;
1311 case ON_LEFT_MARGIN
:
1312 return Qleft_margin
;
1314 case ON_RIGHT_MARGIN
:
1315 return Qright_margin
;
1318 /* Historically we are supposed to return nil in this case. */
1327 /* Callback for foreach_window, used in window_from_coordinates.
1328 Check if window W contains coordinates specified by USER_DATA which
1329 is actually a pointer to a struct check_window_data CW.
1331 Check if window W contains coordinates *CW->x and *CW->y. If it
1332 does, return W in *CW->window, as Lisp_Object, and return in
1333 *CW->part the part of the window under coordinates *X,*Y. Return
1334 zero from this function to stop iterating over windows. */
1336 struct check_window_data
1338 Lisp_Object
*window
;
1340 enum window_part
*part
;
1344 check_window_containing (struct window
*w
, void *user_data
)
1346 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
1347 enum window_part found
;
1350 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1351 if (found
!= ON_NOTHING
)
1354 XSETWINDOW (*cw
->window
, w
);
1362 /* Find the window containing frame-relative pixel position X/Y and
1363 return it as a Lisp_Object.
1365 If X, Y is on one of the window's special `window_part' elements,
1366 set *PART to the id of that element.
1368 If there is no window under X, Y return nil and leave *PART
1369 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1371 This function was previously implemented with a loop cycling over
1372 windows with Fnext_window, and starting with the frame's selected
1373 window. It turned out that this doesn't work with an
1374 implementation of next_window using Vwindow_list, because
1375 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1376 tree of F when this function is called asynchronously from
1377 note_mouse_highlight. The original loop didn't terminate in this
1381 window_from_coordinates (struct frame
*f
, int x
, int y
,
1382 enum window_part
*part
, int tool_bar_p
)
1385 struct check_window_data cw
;
1386 enum window_part dummy
;
1392 cw
.window
= &window
, cw
.x
= x
, cw
.y
= y
; cw
.part
= part
;
1393 foreach_window (f
, check_window_containing
, &cw
);
1395 /* If not found above, see if it's in the tool bar window, if a tool
1399 && WINDOWP (f
->tool_bar_window
)
1400 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1401 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), x
, y
)
1405 window
= f
->tool_bar_window
;
1411 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1412 doc
: /* Return window containing coordinates X and Y on FRAME.
1413 FRAME must be a live frame and defaults to the selected one.
1414 The top left corner of the frame is considered to be row 0,
1416 (Lisp_Object x
, Lisp_Object y
, Lisp_Object frame
)
1418 struct frame
*f
= decode_live_frame (frame
);
1420 /* Check that arguments are integers or floats. */
1421 CHECK_NUMBER_OR_FLOAT (x
);
1422 CHECK_NUMBER_OR_FLOAT (y
);
1424 return window_from_coordinates (f
,
1425 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1426 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1427 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1428 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1432 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1433 doc
: /* Return current value of point in WINDOW.
1434 WINDOW must be a live window and defaults to the selected one.
1436 For a nonselected window, this is the value point would have if that
1437 window were selected.
1439 Note that, when WINDOW is selected, the value returned is the same as
1440 that returned by `point' for WINDOW's buffer. It would be more strictly
1441 correct to return the top-level value of `point', outside of any
1442 `save-excursion' forms. But that is hard to define. */)
1443 (Lisp_Object window
)
1445 register struct window
*w
= decode_live_window (window
);
1447 if (w
== XWINDOW (selected_window
))
1448 return make_number (BUF_PT (XBUFFER (w
->buffer
)));
1450 return Fmarker_position (w
->pointm
);
1453 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1454 doc
: /* Return position at which display currently starts in WINDOW.
1455 WINDOW must be a live window and defaults to the selected one.
1456 This is updated by redisplay or by calling `set-window-start'. */)
1457 (Lisp_Object window
)
1459 return Fmarker_position (decode_live_window (window
)->start
);
1462 /* This is text temporarily removed from the doc string below.
1464 This function returns nil if the position is not currently known.
1465 That happens when redisplay is preempted and doesn't finish.
1466 If in that case you want to compute where the end of the window would
1467 have been if redisplay had finished, do this:
1469 (goto-char (window-start window))
1470 (vertical-motion (1- (window-height window)) window)
1473 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1474 doc
: /* Return position at which display currently ends in WINDOW.
1475 WINDOW must be a live window and defaults to the selected one.
1476 This is updated by redisplay, when it runs to completion.
1477 Simply changing the buffer text or setting `window-start'
1478 does not update this value.
1479 Return nil if there is no recorded value. (This can happen if the
1480 last redisplay of WINDOW was preempted, and did not finish.)
1481 If UPDATE is non-nil, compute the up-to-date position
1482 if it isn't already recorded. */)
1483 (Lisp_Object window
, Lisp_Object update
)
1486 struct window
*w
= decode_live_window (window
);
1495 && (windows_or_buffers_changed
|| !w
->window_end_valid
)
1498 struct text_pos startp
;
1499 ptrdiff_t charpos
= marker_position (w
->start
);
1501 struct buffer
*old_buffer
= NULL
;
1502 void *itdata
= NULL
;
1504 /* Cannot use Fvertical_motion because that function doesn't
1505 cope with variable-height lines. */
1506 if (b
!= current_buffer
)
1508 old_buffer
= current_buffer
;
1509 set_buffer_internal (b
);
1512 /* In case W->start is out of the range, use something
1513 reasonable. This situation occurred when loading a file with
1514 `-l' containing a call to `rmail' with subsequent other
1515 commands. At the end, W->start happened to be BEG, while
1516 rmail had already narrowed the buffer. */
1518 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1519 else if (charpos
> ZV
)
1520 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1522 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1524 itdata
= bidi_shelve_cache ();
1525 start_display (&it
, w
, startp
);
1526 move_it_vertically (&it
, window_box_height (w
));
1527 if (it
.current_y
< it
.last_visible_y
)
1528 move_it_past_eol (&it
);
1529 value
= make_number (IT_CHARPOS (it
));
1530 bidi_unshelve_cache (itdata
, 0);
1533 set_buffer_internal (old_buffer
);
1536 XSETINT (value
, BUF_Z (b
) - XFASTINT (w
->window_end_pos
));
1541 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1542 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1543 WINDOW must be a live window and defaults to the selected one.
1545 (Lisp_Object window
, Lisp_Object pos
)
1547 register struct window
*w
= decode_live_window (window
);
1549 CHECK_NUMBER_COERCE_MARKER (pos
);
1551 if (w
== XWINDOW (selected_window
))
1553 if (XBUFFER (w
->buffer
) == current_buffer
)
1557 struct buffer
*old_buffer
= current_buffer
;
1559 set_buffer_internal (XBUFFER (w
->buffer
));
1561 set_buffer_internal (old_buffer
);
1566 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1567 /* We have to make sure that redisplay updates the window to show
1568 the new value of point. */
1569 ++windows_or_buffers_changed
;
1575 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1576 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1577 WINDOW must be a live window and defaults to the selected one. Return
1578 POS. Optional third arg NOFORCE non-nil inhibits next redisplay from
1579 overriding motion of point in order to display at this exact start. */)
1580 (Lisp_Object window
, Lisp_Object pos
, Lisp_Object noforce
)
1582 register struct window
*w
= decode_live_window (window
);
1584 CHECK_NUMBER_COERCE_MARKER (pos
);
1585 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1586 /* this is not right, but much easier than doing what is right. */
1587 w
->start_at_line_beg
= 0;
1590 w
->update_mode_line
= 1;
1591 w
->last_modified
= 0;
1592 w
->last_overlay_modified
= 0;
1593 if (!EQ (window
, selected_window
))
1594 windows_or_buffers_changed
++;
1599 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
1600 Spos_visible_in_window_p
, 0, 3, 0,
1601 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
1602 WINDOW must be a live window and defaults to the selected one.
1604 Return nil if that position is scrolled vertically out of view. If a
1605 character is only partially visible, nil is returned, unless the
1606 optional argument PARTIALLY is non-nil. If POS is only out of view
1607 because of horizontal scrolling, return non-nil. If POS is t, it
1608 specifies the position of the last visible glyph in WINDOW. POS
1609 defaults to point in WINDOW; WINDOW defaults to the selected window.
1611 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1612 return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
1613 where X and Y are the pixel coordinates relative to the top left corner
1614 of the window. The remaining elements are omitted if the character after
1615 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1616 off-window at the top and bottom of the row, ROWH is the height of the
1617 display row, and VPOS is the row number (0-based) containing POS. */)
1618 (Lisp_Object pos
, Lisp_Object window
, Lisp_Object partially
)
1620 register struct window
*w
;
1621 register EMACS_INT posint
;
1622 register struct buffer
*buf
;
1623 struct text_pos top
;
1624 Lisp_Object in_window
= Qnil
;
1625 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
1628 w
= decode_live_window (window
);
1629 buf
= XBUFFER (w
->buffer
);
1630 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1634 else if (!NILP (pos
))
1636 CHECK_NUMBER_COERCE_MARKER (pos
);
1637 posint
= XINT (pos
);
1639 else if (w
== XWINDOW (selected_window
))
1642 posint
= marker_position (w
->pointm
);
1644 /* If position is above window start or outside buffer boundaries,
1645 or if window start is out of range, position is not visible. */
1647 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
1648 && CHARPOS (top
) >= BUF_BEGV (buf
)
1649 && CHARPOS (top
) <= BUF_ZV (buf
)
1650 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
1651 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
1654 if (!NILP (in_window
) && !NILP (partially
))
1656 Lisp_Object part
= Qnil
;
1658 part
= list4i (rtop
, rbot
, rowh
, vpos
);
1659 in_window
= Fcons (make_number (x
),
1660 Fcons (make_number (y
), part
));
1666 DEFUN ("window-line-height", Fwindow_line_height
,
1667 Swindow_line_height
, 0, 2, 0,
1668 doc
: /* Return height in pixels of text line LINE in window WINDOW.
1669 WINDOW must be a live window and defaults to the selected one.
1671 Return height of current line if LINE is omitted or nil. Return height of
1672 header or mode line if LINE is `header-line' or `mode-line'.
1673 Otherwise, LINE is a text line number starting from 0. A negative number
1674 counts from the end of the window.
1676 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
1677 in pixels of the visible part of the line, VPOS and YPOS are the
1678 vertical position in lines and pixels of the line, relative to the top
1679 of the first text line, and OFFBOT is the number of off-window pixels at
1680 the bottom of the text line. If there are off-window pixels at the top
1681 of the (first) text line, YPOS is negative.
1683 Return nil if window display is not up-to-date. In that case, use
1684 `pos-visible-in-window-p' to obtain the information. */)
1685 (Lisp_Object line
, Lisp_Object window
)
1687 register struct window
*w
;
1688 register struct buffer
*b
;
1689 struct glyph_row
*row
, *end_row
;
1693 w
= decode_live_window (window
);
1695 if (noninteractive
|| w
->pseudo_window_p
)
1698 CHECK_BUFFER (w
->buffer
);
1699 b
= XBUFFER (w
->buffer
);
1701 /* Fail if current matrix is not up-to-date. */
1702 if (!w
->window_end_valid
1703 || current_buffer
->clip_changed
1704 || current_buffer
->prevent_redisplay_optimizations_p
1705 || w
->last_modified
< BUF_MODIFF (b
)
1706 || w
->last_overlay_modified
< BUF_OVERLAY_MODIFF (b
))
1712 if (i
< 0 || i
>= w
->current_matrix
->nrows
1713 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
1715 max_y
= window_text_bottom_y (w
);
1719 if (EQ (line
, Qheader_line
))
1721 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
1723 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
1724 return row
->enabled_p
? list4i (row
->height
, 0, 0, 0) : Qnil
;
1727 if (EQ (line
, Qmode_line
))
1729 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
1730 return (row
->enabled_p
?
1731 list4i (row
->height
,
1732 0, /* not accurate */
1733 (WINDOW_HEADER_LINE_HEIGHT (w
)
1734 + window_text_bottom_y (w
)),
1739 CHECK_NUMBER (line
);
1742 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1743 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1744 max_y
= window_text_bottom_y (w
);
1747 while ((n
< 0 || i
< n
)
1748 && row
<= end_row
&& row
->enabled_p
1749 && row
->y
+ row
->height
< max_y
)
1752 if (row
> end_row
|| !row
->enabled_p
)
1764 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
1765 return list4i (row
->height
+ min (0, row
->y
) - crop
, i
, row
->y
, crop
);
1768 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1770 doc
: /* Return non-nil when WINDOW is dedicated to its buffer.
1771 More precisely, return the value assigned by the last call of
1772 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1773 never called with WINDOW as its argument, or the value set by that
1774 function was internally reset since its last call. WINDOW must be a
1775 live window and defaults to the selected one.
1777 When a window is dedicated to its buffer, `display-buffer' will refrain
1778 from displaying another buffer in it. `get-lru-window' and
1779 `get-largest-window' treat dedicated windows specially.
1780 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1781 `kill-buffer' can delete a dedicated window and the containing frame.
1783 Functions like `set-window-buffer' may change the buffer displayed by a
1784 window, unless that window is "strongly" dedicated to its buffer, that
1785 is the value returned by `window-dedicated-p' is t. */)
1786 (Lisp_Object window
)
1788 return decode_live_window (window
)->dedicated
;
1791 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1792 Sset_window_dedicated_p
, 2, 2, 0,
1793 doc
: /* Mark WINDOW as dedicated according to FLAG.
1794 WINDOW must be a live window and defaults to the selected one. FLAG
1795 non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means
1796 mark WINDOW as non-dedicated. Return FLAG.
1798 When a window is dedicated to its buffer, `display-buffer' will refrain
1799 from displaying another buffer in it. `get-lru-window' and
1800 `get-largest-window' treat dedicated windows specially.
1801 `delete-windows-on', `replace-buffer-in-windows', `quit-window',
1802 `quit-restore-window' and `kill-buffer' can delete a dedicated window
1803 and the containing frame.
1805 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
1806 its buffer. Functions like `set-window-buffer' may change the buffer
1807 displayed by a window, unless that window is strongly dedicated to its
1808 buffer. If and when `set-window-buffer' displays another buffer in a
1809 window, it also makes sure that the window is no more dedicated. */)
1810 (Lisp_Object window
, Lisp_Object flag
)
1812 wset_dedicated (decode_live_window (window
), flag
);
1816 DEFUN ("window-prev-buffers", Fwindow_prev_buffers
, Swindow_prev_buffers
,
1818 doc
: /* Return buffers previously shown in WINDOW.
1819 WINDOW must be a live window and defaults to the selected one.
1821 The return value is a list of elements (BUFFER WINDOW-START POS),
1822 where BUFFER is a buffer, WINDOW-START is the start position of the
1823 window for that buffer, and POS is a window-specific point value. */)
1824 (Lisp_Object window
)
1826 return decode_live_window (window
)->prev_buffers
;
1829 DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers
,
1830 Sset_window_prev_buffers
, 2, 2, 0,
1831 doc
: /* Set WINDOW's previous buffers to PREV-BUFFERS.
1832 WINDOW must be a live window and defaults to the selected one.
1834 PREV-BUFFERS should be a list of elements (BUFFER WINDOW-START POS),
1835 where BUFFER is a buffer, WINDOW-START is the start position of the
1836 window for that buffer, and POS is a window-specific point value. */)
1837 (Lisp_Object window
, Lisp_Object prev_buffers
)
1839 wset_prev_buffers (decode_live_window (window
), prev_buffers
);
1840 return prev_buffers
;
1843 DEFUN ("window-next-buffers", Fwindow_next_buffers
, Swindow_next_buffers
,
1845 doc
: /* Return list of buffers recently re-shown in WINDOW.
1846 WINDOW must be a live window and defaults to the selected one. */)
1847 (Lisp_Object window
)
1849 return decode_live_window (window
)->next_buffers
;
1852 DEFUN ("set-window-next-buffers", Fset_window_next_buffers
,
1853 Sset_window_next_buffers
, 2, 2, 0,
1854 doc
: /* Set WINDOW's next buffers to NEXT-BUFFERS.
1855 WINDOW must be a live window and defaults to the selected one.
1856 NEXT-BUFFERS should be a list of buffers. */)
1857 (Lisp_Object window
, Lisp_Object next_buffers
)
1859 wset_next_buffers (decode_live_window (window
), next_buffers
);
1860 return next_buffers
;
1863 DEFUN ("window-parameters", Fwindow_parameters
, Swindow_parameters
,
1865 doc
: /* Return the parameters of WINDOW and their values.
1866 WINDOW must be a valid window and defaults to the selected one. The
1867 return value is a list of elements of the form (PARAMETER . VALUE). */)
1868 (Lisp_Object window
)
1870 return Fcopy_alist (decode_valid_window (window
)->window_parameters
);
1873 DEFUN ("window-parameter", Fwindow_parameter
, Swindow_parameter
,
1875 doc
: /* Return WINDOW's value for PARAMETER.
1876 WINDOW can be any window and defaults to the selected one. */)
1877 (Lisp_Object window
, Lisp_Object parameter
)
1881 result
= Fassq (parameter
, decode_any_window (window
)->window_parameters
);
1882 return CDR_SAFE (result
);
1885 DEFUN ("set-window-parameter", Fset_window_parameter
,
1886 Sset_window_parameter
, 3, 3, 0,
1887 doc
: /* Set WINDOW's value of PARAMETER to VALUE.
1888 WINDOW can be any window and defaults to the selected one.
1890 (Lisp_Object window
, Lisp_Object parameter
, Lisp_Object value
)
1892 register struct window
*w
= decode_any_window (window
);
1893 Lisp_Object old_alist_elt
;
1895 old_alist_elt
= Fassq (parameter
, w
->window_parameters
);
1896 if (NILP (old_alist_elt
))
1897 wset_window_parameters
1898 (w
, Fcons (Fcons (parameter
, value
), w
->window_parameters
));
1900 Fsetcdr (old_alist_elt
, value
);
1904 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1906 doc
: /* Return the display-table that WINDOW is using.
1907 WINDOW must be a live window and defaults to the selected one. */)
1908 (Lisp_Object window
)
1910 return decode_live_window (window
)->display_table
;
1913 /* Get the display table for use on window W. This is either W's
1914 display table or W's buffer's display table. Ignore the specified
1915 tables if they are not valid; if no valid table is specified,
1918 struct Lisp_Char_Table
*
1919 window_display_table (struct window
*w
)
1921 struct Lisp_Char_Table
*dp
= NULL
;
1923 if (DISP_TABLE_P (w
->display_table
))
1924 dp
= XCHAR_TABLE (w
->display_table
);
1925 else if (BUFFERP (w
->buffer
))
1927 struct buffer
*b
= XBUFFER (w
->buffer
);
1929 if (DISP_TABLE_P (BVAR (b
, display_table
)))
1930 dp
= XCHAR_TABLE (BVAR (b
, display_table
));
1931 else if (DISP_TABLE_P (Vstandard_display_table
))
1932 dp
= XCHAR_TABLE (Vstandard_display_table
);
1938 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1939 doc
: /* Set WINDOW's display-table to TABLE.
1940 WINDOW must be a live window and defaults to the selected one. */)
1941 (register Lisp_Object window
, Lisp_Object table
)
1943 wset_display_table (decode_live_window (window
), table
);
1947 /* Record info on buffer window W is displaying
1948 when it is about to cease to display that buffer. */
1950 unshow_buffer (register struct window
*w
)
1957 if (b
!= XMARKER (w
->pointm
)->buffer
)
1961 if (w
== XWINDOW (selected_window
)
1962 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1963 /* Do this except when the selected window's buffer
1964 is being removed from some other window. */
1966 /* last_window_start records the start position that this buffer
1967 had in the last window to be disconnected from it.
1968 Now that this statement is unconditional,
1969 it is possible for the buffer to be displayed in the
1970 selected window, while last_window_start reflects another
1971 window which was recently showing the same buffer.
1972 Some people might say that might be a good thing. Let's see. */
1973 b
->last_window_start
= marker_position (w
->start
);
1975 /* Point in the selected window's buffer
1976 is actually stored in that buffer, and the window's pointm isn't used.
1977 So don't clobber point in that buffer. */
1978 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1979 /* Don't clobber point in current buffer either (this could be
1980 useful in connection with bug#12208).
1981 && XBUFFER (buf) != current_buffer */
1982 /* This line helps to fix Horsley's testbug.el bug. */
1983 && !(WINDOWP (BVAR (b
, last_selected_window
))
1984 && w
!= XWINDOW (BVAR (b
, last_selected_window
))
1985 && EQ (buf
, XWINDOW (BVAR (b
, last_selected_window
))->buffer
)))
1986 temp_set_point_both (b
,
1987 clip_to_bounds (BUF_BEGV (b
),
1988 marker_position (w
->pointm
),
1990 clip_to_bounds (BUF_BEGV_BYTE (b
),
1991 marker_byte_position (w
->pointm
),
1994 if (WINDOWP (BVAR (b
, last_selected_window
))
1995 && w
== XWINDOW (BVAR (b
, last_selected_window
)))
1996 bset_last_selected_window (b
, Qnil
);
1999 /* Put NEW into the window structure in place of OLD. SETFLAG zero
2000 means change window structure only. Otherwise store geometry and
2001 other settings as well. */
2003 replace_window (Lisp_Object old
, Lisp_Object
new, int setflag
)
2005 register Lisp_Object tem
;
2006 register struct window
*o
= XWINDOW (old
), *n
= XWINDOW (new);
2008 /* If OLD is its frame's root window, then NEW is the new
2009 root window for that frame. */
2010 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
2011 fset_root_window (XFRAME (o
->frame
), new);
2015 wset_left_col (n
, o
->left_col
);
2016 wset_top_line (n
, o
->top_line
);
2017 wset_total_cols (n
, o
->total_cols
);
2018 wset_total_lines (n
, o
->total_lines
);
2019 wset_normal_cols (n
, o
->normal_cols
);
2020 wset_normal_cols (o
, make_float (1.0));
2021 wset_normal_lines (n
, o
->normal_lines
);
2022 wset_normal_lines (o
, make_float (1.0));
2023 n
->desired_matrix
= n
->current_matrix
= 0;
2025 memset (&n
->cursor
, 0, sizeof (n
->cursor
));
2026 memset (&n
->last_cursor
, 0, sizeof (n
->last_cursor
));
2027 memset (&n
->phys_cursor
, 0, sizeof (n
->phys_cursor
));
2028 n
->phys_cursor_type
= -1;
2029 n
->phys_cursor_width
= -1;
2030 n
->must_be_updated_p
= 0;
2031 n
->pseudo_window_p
= 0;
2032 wset_window_end_vpos (n
, make_number (0));
2033 wset_window_end_pos (n
, make_number (0));
2034 n
->window_end_valid
= 0;
2035 n
->frozen_window_start_p
= 0;
2041 wset_prev (XWINDOW (tem
), new);
2046 wset_next (XWINDOW (tem
), new);
2049 wset_parent (n
, tem
);
2052 if (EQ (XWINDOW (tem
)->vchild
, old
))
2053 wset_vchild (XWINDOW (tem
), new);
2054 if (EQ (XWINDOW (tem
)->hchild
, old
))
2055 wset_hchild (XWINDOW (tem
), new);
2059 /* If window WINDOW and its parent window are iso-combined, merge
2060 WINDOW's children into those of its parent window and mark WINDOW as
2064 recombine_windows (Lisp_Object window
)
2066 struct window
*w
, *p
, *c
;
2067 Lisp_Object parent
, child
;
2070 w
= XWINDOW (window
);
2072 if (!NILP (parent
) && NILP (w
->combination_limit
))
2074 p
= XWINDOW (parent
);
2075 if (((!NILP (p
->vchild
) && !NILP (w
->vchild
))
2076 || (!NILP (p
->hchild
) && !NILP (w
->hchild
))))
2077 /* WINDOW and PARENT are both either a vertical or a horizontal
2080 horflag
= NILP (w
->vchild
);
2081 child
= horflag
? w
->hchild
: w
->vchild
;
2082 c
= XWINDOW (child
);
2084 /* Splice WINDOW's children into its parent's children and
2085 assign new normal sizes. */
2088 wset_hchild (p
, child
);
2090 wset_vchild (p
, child
);
2093 wset_prev (c
, w
->prev
);
2094 wset_next (XWINDOW (w
->prev
), child
);
2099 wset_parent (c
, parent
);
2102 wset_normal_cols (c
,
2103 make_float (XFLOATINT (c
->total_cols
)
2104 / XFLOATINT (p
->total_cols
)));
2106 wset_normal_lines (c
,
2107 make_float (XFLOATINT (c
->total_lines
)
2108 / XFLOATINT (p
->total_lines
)));
2112 if (!NILP (w
->next
))
2114 wset_next (c
, w
->next
);
2115 wset_prev (XWINDOW (c
->next
), child
);
2123 c
= XWINDOW (child
);
2127 /* WINDOW can be deleted now. */
2128 wset_vchild (w
, Qnil
);
2129 wset_hchild (w
, Qnil
);
2134 /* If WINDOW can be deleted, delete it. */
2136 delete_deletable_window (Lisp_Object window
)
2138 if (!NILP (call1 (Qwindow_deletable_p
, window
)))
2139 call1 (Qdelete_window
, window
);
2142 /***********************************************************************
2144 ***********************************************************************/
2146 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
2147 pointer. This is a callback function for foreach_window, used in
2148 the window_list function. */
2151 add_window_to_list (struct window
*w
, void *user_data
)
2153 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
2155 XSETWINDOW (window
, w
);
2156 *list
= Fcons (window
, *list
);
2161 /* Return a list of all windows, for use by next_window. If
2162 Vwindow_list is a list, return that list. Otherwise, build a new
2163 list, cache it in Vwindow_list, and return that. */
2168 if (!CONSP (Vwindow_list
))
2170 Lisp_Object tail
, frame
;
2172 Vwindow_list
= Qnil
;
2173 FOR_EACH_FRAME (tail
, frame
)
2175 Lisp_Object args
[2];
2177 /* We are visiting windows in canonical order, and add
2178 new windows at the front of args[1], which means we
2179 have to reverse this list at the end. */
2181 foreach_window (XFRAME (frame
), add_window_to_list
, &args
[1]);
2182 args
[0] = Vwindow_list
;
2183 args
[1] = Fnreverse (args
[1]);
2184 Vwindow_list
= Fnconc (2, args
);
2188 return Vwindow_list
;
2192 /* Value is non-zero if WINDOW satisfies the constraints given by
2193 OWINDOW, MINIBUF and ALL_FRAMES.
2195 MINIBUF t means WINDOW may be minibuffer windows.
2196 `lambda' means WINDOW may not be a minibuffer window.
2197 a window means a specific minibuffer window
2199 ALL_FRAMES t means search all frames,
2200 nil means search just current frame,
2201 `visible' means search just visible frames on the
2203 0 means search visible and iconified frames on the
2205 a window means search the frame that window belongs to,
2206 a frame means consider windows on that frame, only. */
2209 candidate_window_p (Lisp_Object window
, Lisp_Object owindow
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2211 struct window
*w
= XWINDOW (window
);
2212 struct frame
*f
= XFRAME (w
->frame
);
2213 int candidate_p
= 1;
2215 if (!BUFFERP (w
->buffer
))
2217 else if (MINI_WINDOW_P (w
)
2218 && (EQ (minibuf
, Qlambda
)
2219 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
2221 /* If MINIBUF is `lambda' don't consider any mini-windows.
2222 If it is a window, consider only that one. */
2225 else if (EQ (all_frames
, Qt
))
2227 else if (NILP (all_frames
))
2229 eassert (WINDOWP (owindow
));
2230 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
2232 else if (EQ (all_frames
, Qvisible
))
2234 FRAME_SAMPLE_VISIBILITY (f
);
2235 candidate_p
= FRAME_VISIBLE_P (f
)
2236 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2237 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2240 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
2242 FRAME_SAMPLE_VISIBILITY (f
);
2243 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
2244 #ifdef HAVE_X_WINDOWS
2245 /* Yuck!! If we've just created the frame and the
2246 window-manager requested the user to place it
2247 manually, the window may still not be considered
2248 `visible'. I'd argue it should be at least
2249 something like `iconified', but don't know how to do
2251 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
2252 && !f
->output_data
.x
->has_been_visible
)
2255 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2256 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2258 else if (WINDOWP (all_frames
))
2259 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
2260 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
2261 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
2262 else if (FRAMEP (all_frames
))
2263 candidate_p
= EQ (all_frames
, w
->frame
);
2269 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2270 Fwindow_list. See candidate_window_p for the meaning of WINDOW,
2271 MINIBUF, and ALL_FRAMES. */
2274 decode_next_window_args (Lisp_Object
*window
, Lisp_Object
*minibuf
, Lisp_Object
*all_frames
)
2276 struct window
*w
= decode_live_window (*window
);
2278 XSETWINDOW (*window
, w
);
2279 /* MINIBUF nil may or may not include minibuffers. Decide if it
2281 if (NILP (*minibuf
))
2282 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
2283 else if (!EQ (*minibuf
, Qt
))
2286 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2287 => count none of them, or a specific minibuffer window (the
2288 active one) to count. */
2290 /* ALL_FRAMES nil doesn't specify which frames to include. */
2291 if (NILP (*all_frames
))
2293 = (!EQ (*minibuf
, Qlambda
)
2294 ? FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
))
2296 else if (EQ (*all_frames
, Qvisible
))
2298 else if (EQ (*all_frames
, make_number (0)))
2300 else if (FRAMEP (*all_frames
))
2302 else if (!EQ (*all_frames
, Qt
))
2307 /* Return the next or previous window of WINDOW in cyclic ordering
2308 of windows. NEXT_P non-zero means return the next window. See the
2309 documentation string of next-window for the meaning of MINIBUF and
2313 next_window (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
, int next_p
)
2315 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2317 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2318 return the first window on the frame. */
2319 if (FRAMEP (all_frames
)
2320 && !EQ (all_frames
, XWINDOW (window
)->frame
))
2321 return Fframe_first_window (all_frames
);
2327 /* Find WINDOW in the list of all windows. */
2328 list
= Fmemq (window
, window_list ());
2330 /* Scan forward from WINDOW to the end of the window list. */
2332 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
2333 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2336 /* Scan from the start of the window list up to WINDOW. */
2338 for (list
= Vwindow_list
;
2339 CONSP (list
) && !EQ (XCAR (list
), window
);
2341 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2345 window
= XCAR (list
);
2349 Lisp_Object candidate
, list
;
2351 /* Scan through the list of windows for candidates. If there are
2352 candidate windows in front of WINDOW, the last one of these
2353 is the one we want. If there are candidates following WINDOW
2354 in the list, again the last one of these is the one we want. */
2356 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
2358 if (EQ (XCAR (list
), window
))
2360 if (WINDOWP (candidate
))
2363 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
2365 candidate
= XCAR (list
);
2368 if (WINDOWP (candidate
))
2376 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
2377 doc
: /* Return live window after WINDOW in the cyclic ordering of windows.
2378 WINDOW must be a live window and defaults to the selected one. The
2379 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2382 MINIBUF nil or omitted means consider the minibuffer window only if the
2383 minibuffer is active. MINIBUF t means consider the minibuffer window
2384 even if the minibuffer is not active. Any other value means do not
2385 consider the minibuffer window even if the minibuffer is active.
2387 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2388 plus the minibuffer window if specified by the MINIBUF argument. If the
2389 minibuffer counts, consider all windows on all frames that share that
2390 minibuffer too. The following non-nil values of ALL-FRAMES have special
2393 - t means consider all windows on all existing frames.
2395 - `visible' means consider all windows on all visible frames.
2397 - 0 (the number zero) means consider all windows on all visible and
2400 - A frame means consider all windows on that frame only.
2402 Anything else means consider all windows on WINDOW's frame and no
2405 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2406 `next-window' to iterate through the entire cycle of acceptable
2407 windows, eventually ending up back at the window you started with.
2408 `previous-window' traverses the same cycle, in the reverse order. */)
2409 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2411 return next_window (window
, minibuf
, all_frames
, 1);
2415 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
2416 doc
: /* Return live window before WINDOW in the cyclic ordering of windows.
2417 WINDOW must be a live window and defaults to the selected one. The
2418 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2421 MINIBUF nil or omitted means consider the minibuffer window only if the
2422 minibuffer is active. MINIBUF t means consider the minibuffer window
2423 even if the minibuffer is not active. Any other value means do not
2424 consider the minibuffer window even if the minibuffer is active.
2426 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2427 plus the minibuffer window if specified by the MINIBUF argument. If the
2428 minibuffer counts, consider all windows on all frames that share that
2429 minibuffer too. The following non-nil values of ALL-FRAMES have special
2432 - t means consider all windows on all existing frames.
2434 - `visible' means consider all windows on all visible frames.
2436 - 0 (the number zero) means consider all windows on all visible and
2439 - A frame means consider all windows on that frame only.
2441 Anything else means consider all windows on WINDOW's frame and no
2444 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2445 use `previous-window' to iterate through the entire cycle of
2446 acceptable windows, eventually ending up back at the window you
2447 started with. `next-window' traverses the same cycle, in the
2449 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2451 return next_window (window
, minibuf
, all_frames
, 0);
2455 /* Return a list of windows in cyclic ordering. Arguments are like
2456 for `next-window'. */
2459 window_list_1 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2461 Lisp_Object tail
, list
, rest
;
2463 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2466 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2467 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2468 list
= Fcons (XCAR (tail
), list
);
2470 /* Rotate the list to start with WINDOW. */
2471 list
= Fnreverse (list
);
2472 rest
= Fmemq (window
, list
);
2473 if (!NILP (rest
) && !EQ (rest
, list
))
2475 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2477 XSETCDR (tail
, Qnil
);
2478 list
= nconc2 (rest
, list
);
2484 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2485 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2486 FRAME nil or omitted means use the selected frame.
2487 WINDOW nil or omitted means use the window selected within FRAME.
2488 MINIBUF t means include the minibuffer window, even if it isn't active.
2489 MINIBUF nil or omitted means include the minibuffer window only
2491 MINIBUF neither nil nor t means never include the minibuffer window. */)
2492 (Lisp_Object frame
, Lisp_Object minibuf
, Lisp_Object window
)
2495 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2496 CHECK_WINDOW (window
);
2498 frame
= selected_frame
;
2500 if (!EQ (frame
, XWINDOW (window
)->frame
))
2501 error ("Window is on a different frame");
2503 return window_list_1 (window
, minibuf
, frame
);
2507 DEFUN ("window-list-1", Fwindow_list_1
, Swindow_list_1
, 0, 3, 0,
2508 doc
: /* Return a list of all live windows.
2509 WINDOW specifies the first window to list and defaults to the selected
2512 Optional argument MINIBUF nil or omitted means consider the minibuffer
2513 window only if the minibuffer is active. MINIBUF t means consider the
2514 minibuffer window even if the minibuffer is not active. Any other value
2515 means do not consider the minibuffer window even if the minibuffer is
2518 Optional argument ALL-FRAMES nil or omitted means consider all windows
2519 on WINDOW's frame, plus the minibuffer window if specified by the
2520 MINIBUF argument. If the minibuffer counts, consider all windows on all
2521 frames that share that minibuffer too. The following non-nil values of
2522 ALL-FRAMES have special meanings:
2524 - t means consider all windows on all existing frames.
2526 - `visible' means consider all windows on all visible frames.
2528 - 0 (the number zero) means consider all windows on all visible and
2531 - A frame means consider all windows on that frame only.
2533 Anything else means consider all windows on WINDOW's frame and no
2536 If WINDOW is not on the list of windows returned, some other window will
2537 be listed first but no error is signaled. */)
2538 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2540 return window_list_1 (window
, minibuf
, all_frames
);
2543 /* Look at all windows, performing an operation specified by TYPE
2545 If FRAMES is Qt, look at all frames;
2546 Qnil, look at just the selected frame;
2547 Qvisible, look at visible frames;
2548 a frame, just look at windows on that frame.
2549 If MINI is non-zero, perform the operation on minibuffer windows too. */
2554 GET_BUFFER_WINDOW
, /* Arg is buffer */
2555 REPLACE_BUFFER_IN_WINDOWS_SAFELY
, /* Arg is buffer */
2556 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2561 window_loop (enum window_loop type
, Lisp_Object obj
, int mini
, Lisp_Object frames
)
2563 Lisp_Object window
, windows
, best_window
, frame_arg
;
2564 int frame_best_window_flag
= 0;
2566 struct gcpro gcpro1
;
2568 /* If we're only looping through windows on a particular frame,
2569 frame points to that frame. If we're looping through windows
2570 on all frames, frame is 0. */
2571 if (FRAMEP (frames
))
2572 f
= XFRAME (frames
);
2573 else if (NILP (frames
))
2574 f
= SELECTED_FRAME ();
2579 frame_arg
= Qlambda
;
2580 else if (EQ (frames
, make_number (0)))
2582 else if (EQ (frames
, Qvisible
))
2587 /* frame_arg is Qlambda to stick to one frame,
2588 Qvisible to consider all visible frames,
2591 /* Pick a window to start with. */
2595 window
= FRAME_SELECTED_WINDOW (f
);
2597 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2599 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2603 for (; CONSP (windows
); windows
= XCDR (windows
))
2607 window
= XCAR (windows
);
2608 w
= XWINDOW (window
);
2610 /* Note that we do not pay attention here to whether the frame
2611 is visible, since Fwindow_list skips non-visible frames if
2612 that is desired, under the control of frame_arg. */
2613 if (!MINI_WINDOW_P (w
)
2614 /* For REPLACE_BUFFER_IN_WINDOWS_SAFELY, we must always
2615 consider all windows. */
2616 || type
== REPLACE_BUFFER_IN_WINDOWS_SAFELY
2617 || (mini
&& minibuf_level
> 0))
2620 case GET_BUFFER_WINDOW
:
2621 if (EQ (w
->buffer
, obj
)
2622 /* Don't find any minibuffer window except the one that
2623 is currently in use. */
2624 && (MINI_WINDOW_P (w
) ? EQ (window
, minibuf_window
) : 1))
2626 if (EQ (window
, selected_window
))
2627 /* Preferably return the selected window. */
2628 RETURN_UNGCPRO (window
);
2629 else if (EQ (XWINDOW (window
)->frame
, selected_frame
)
2630 && !frame_best_window_flag
)
2631 /* Prefer windows on the current frame (but don't
2632 choose another one if we have one already). */
2634 best_window
= window
;
2635 frame_best_window_flag
= 1;
2637 else if (NILP (best_window
))
2638 best_window
= window
;
2642 case REPLACE_BUFFER_IN_WINDOWS_SAFELY
:
2643 /* We could simply check whether the buffer shown by window
2644 is live, and show another buffer in case it isn't. */
2645 if (EQ (w
->buffer
, obj
))
2647 /* Undedicate WINDOW. */
2648 wset_dedicated (w
, Qnil
);
2649 /* Make WINDOW show the buffer returned by
2650 other_buffer_safely, don't run any hooks. */
2652 (window
, other_buffer_safely (w
->buffer
), 0, 0);
2653 /* If WINDOW is the selected window, make its buffer
2654 current. But do so only if the window shows the
2655 current buffer (Bug#6454). */
2656 if (EQ (window
, selected_window
)
2657 && XBUFFER (w
->buffer
) == current_buffer
)
2658 Fset_buffer (w
->buffer
);
2662 case REDISPLAY_BUFFER_WINDOWS
:
2663 if (EQ (w
->buffer
, obj
))
2665 mark_window_display_accurate (window
, 0);
2666 w
->update_mode_line
= 1;
2667 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2668 ++update_mode_lines
;
2669 best_window
= window
;
2673 /* Check for a window that has a killed buffer. */
2674 case CHECK_ALL_WINDOWS
:
2675 if (! NILP (w
->buffer
)
2676 && !BUFFER_LIVE_P (XBUFFER (w
->buffer
)))
2680 case WINDOW_LOOP_UNUSED
:
2689 /* Used for debugging. Abort if any window has a dead buffer. */
2691 extern void check_all_windows (void) EXTERNALLY_VISIBLE
;
2693 check_all_windows (void)
2695 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2698 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 0, 2, 0,
2699 doc
: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2700 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to
2703 The optional argument ALL-FRAMES specifies the frames to consider:
2705 - t means consider all windows on all existing frames.
2707 - `visible' means consider all windows on all visible frames.
2709 - 0 (the number zero) means consider all windows on all visible
2710 and iconified frames.
2712 - A frame means consider all windows on that frame only.
2714 Any other value of ALL-FRAMES means consider all windows on the
2715 selected frame and no others. */)
2716 (Lisp_Object buffer_or_name
, Lisp_Object all_frames
)
2720 if (NILP (buffer_or_name
))
2721 buffer
= Fcurrent_buffer ();
2723 buffer
= Fget_buffer (buffer_or_name
);
2725 if (BUFFERP (buffer
))
2726 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, all_frames
);
2732 resize_root_window (Lisp_Object window
, Lisp_Object delta
, Lisp_Object horizontal
, Lisp_Object ignore
)
2734 return call4 (Qwindow_resize_root_window
, window
, delta
, horizontal
, ignore
);
2738 DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal
,
2739 Sdelete_other_windows_internal
, 0, 2, "",
2740 doc
: /* Make WINDOW fill its frame.
2741 Only the frame WINDOW is on is affected. WINDOW must be a valid window
2742 and defaults to the selected one.
2744 Optional argument ROOT, if non-nil, must specify an internal window such
2745 that WINDOW is in its window subtree. If this is the case, replace ROOT
2746 by WINDOW and leave alone any windows not part of ROOT's subtree.
2748 When WINDOW is live try to reduce display jumps by keeping the text
2749 previously visible in WINDOW in the same place on the frame. Doing this
2750 depends on the value of (window-start WINDOW), so if calling this
2751 function in a program gives strange scrolling, make sure the
2752 window-start value is reasonable when this function is called. */)
2753 (Lisp_Object window
, Lisp_Object root
)
2755 struct window
*w
, *r
, *s
;
2757 Lisp_Object sibling
, pwindow
, swindow
IF_LINT (= Qnil
), delta
;
2758 ptrdiff_t startpos
IF_LINT (= 0);
2759 int top
IF_LINT (= 0), new_top
, resize_failed
;
2761 w
= decode_valid_window (window
);
2762 XSETWINDOW (window
, w
);
2763 f
= XFRAME (w
->frame
);
2766 /* ROOT is the frame's root window. */
2768 root
= FRAME_ROOT_WINDOW (f
);
2772 /* ROOT must be an ancestor of WINDOW. */
2774 r
= decode_valid_window (root
);
2775 pwindow
= XWINDOW (window
)->parent
;
2776 while (!NILP (pwindow
))
2777 if (EQ (pwindow
, root
))
2780 pwindow
= XWINDOW (pwindow
)->parent
;
2781 if (!EQ (pwindow
, root
))
2782 error ("Specified root is not an ancestor of specified window");
2785 if (EQ (window
, root
))
2788 /* I don't understand the "top > 0" part below. If we deal with a
2789 standalone minibuffer it would have been caught by the preceding
2791 else if (MINI_WINDOW_P (w
)) /* && top > 0) */
2792 error ("Can't expand minibuffer to full frame");
2794 if (!NILP (w
->buffer
))
2796 startpos
= marker_position (w
->start
);
2797 top
= WINDOW_TOP_EDGE_LINE (w
)
2798 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2799 /* Make sure WINDOW is the frame's selected window. */
2800 if (!EQ (window
, FRAME_SELECTED_WINDOW (f
)))
2802 if (EQ (selected_frame
, w
->frame
))
2803 Fselect_window (window
, Qnil
);
2805 fset_selected_window (f
, window
);
2810 /* See if the frame's selected window is a part of the window
2811 subtree rooted at WINDOW, by finding all the selected window's
2812 parents and comparing each one with WINDOW. If it isn't we
2813 need a new selected window for this frame. */
2814 swindow
= FRAME_SELECTED_WINDOW (f
);
2818 while (!NILP (pwindow
) && !EQ (window
, pwindow
))
2819 pwindow
= XWINDOW (pwindow
)->parent
;
2821 if (EQ (window
, pwindow
))
2822 /* If WINDOW is an ancestor of SWINDOW, then SWINDOW is ok
2823 as the new selected window. */
2826 /* Else try the previous window of SWINDOW. */
2827 swindow
= Fprevious_window (swindow
, Qlambda
, Qnil
);
2830 if (!EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
2832 if (EQ (selected_frame
, w
->frame
))
2833 Fselect_window (swindow
, Qnil
);
2835 fset_selected_window (f
, swindow
);
2840 if (!FRAME_INITIAL_P (f
))
2842 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
2844 /* We are going to free the glyph matrices of WINDOW, and with
2845 that we might lose any information about glyph rows that have
2846 some of their glyphs highlighted in mouse face. (These rows
2847 are marked with a non-zero mouse_face_p flag.) If WINDOW
2848 indeed has some glyphs highlighted in mouse face, signal to
2849 frame's up-to-date hook that mouse highlight was overwritten,
2850 so that it will arrange for redisplaying the highlight. */
2851 if (EQ (hlinfo
->mouse_face_window
, window
))
2853 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
2854 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
2855 hlinfo
->mouse_face_window
= Qnil
;
2858 free_window_matrices (r
);
2860 windows_or_buffers_changed
++;
2861 Vwindow_list
= Qnil
;
2862 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
2865 if (NILP (w
->buffer
))
2867 /* Resize child windows vertically. */
2868 XSETINT (delta
, XINT (r
->total_lines
)
2869 - XINT (w
->total_lines
));
2870 wset_top_line (w
, r
->top_line
);
2871 resize_root_window (window
, delta
, Qnil
, Qnil
);
2872 if (window_resize_check (w
, 0))
2873 window_resize_apply (w
, 0);
2876 resize_root_window (window
, delta
, Qnil
, Qt
);
2877 if (window_resize_check (w
, 0))
2878 window_resize_apply (w
, 0);
2883 /* Resize child windows horizontally. */
2886 wset_left_col (w
, r
->left_col
);
2888 XINT (r
->total_cols
) - XINT (w
->total_cols
));
2889 wset_left_col (w
, r
->left_col
);
2890 resize_root_window (window
, delta
, Qt
, Qnil
);
2891 if (window_resize_check (w
, 1))
2892 window_resize_apply (w
, 1);
2895 resize_root_window (window
, delta
, Qt
, Qt
);
2896 if (window_resize_check (w
, 1))
2897 window_resize_apply (w
, 1);
2904 /* Play safe, if we still can ... */
2907 w
= XWINDOW (window
);
2911 /* Cleanly unlink WINDOW from window-tree. */
2912 if (!NILP (w
->prev
))
2913 /* Get SIBLING above (on the left of) WINDOW. */
2916 s
= XWINDOW (sibling
);
2917 wset_next (s
, w
->next
);
2918 if (!NILP (s
->next
))
2919 wset_prev (XWINDOW (s
->next
), sibling
);
2922 /* Get SIBLING below (on the right of) WINDOW. */
2925 s
= XWINDOW (sibling
);
2926 wset_prev (s
, Qnil
);
2927 if (!NILP (XWINDOW (w
->parent
)->vchild
))
2928 wset_vchild (XWINDOW (w
->parent
), sibling
);
2930 wset_hchild (XWINDOW (w
->parent
), sibling
);
2933 /* Delete ROOT and all child windows of ROOT. */
2934 if (!NILP (r
->vchild
))
2936 delete_all_child_windows (r
->vchild
);
2937 wset_vchild (r
, Qnil
);
2939 else if (!NILP (r
->hchild
))
2941 delete_all_child_windows (r
->hchild
);
2942 wset_hchild (r
, Qnil
);
2945 replace_window (root
, window
, 1);
2947 /* This must become SWINDOW anyway ....... */
2948 if (!NILP (w
->buffer
) && !resize_failed
)
2950 /* Try to minimize scrolling, by setting the window start to the
2951 point will cause the text at the old window start to be at the
2952 same place on the frame. But don't try to do this if the
2953 window start is outside the visible portion (as might happen
2954 when the display is not current, due to typeahead). */
2955 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2957 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2958 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2960 struct position pos
;
2961 struct buffer
*obuf
= current_buffer
;
2963 Fset_buffer (w
->buffer
);
2964 /* This computation used to temporarily move point, but that
2965 can have unwanted side effects due to text properties. */
2966 pos
= *vmotion (startpos
, -top
, w
);
2968 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2969 w
->window_end_valid
= 0;
2970 w
->start_at_line_beg
= (pos
.bytepos
== BEGV_BYTE
2971 || FETCH_BYTE (pos
.bytepos
- 1) == '\n');
2972 /* We need to do this, so that the window-scroll-functions
2974 w
->optional_new_start
= 1;
2976 set_buffer_internal (obuf
);
2983 run_window_configuration_change_hook (f
);
2990 replace_buffer_in_windows (Lisp_Object buffer
)
2992 call1 (Qreplace_buffer_in_windows
, buffer
);
2995 /* If BUFFER is shown in a window, safely replace it with some other
2996 buffer in all windows of all frames, even those on other keyboards. */
2999 replace_buffer_in_windows_safely (Lisp_Object buffer
)
3001 if (buffer_window_count (XBUFFER (buffer
)))
3003 Lisp_Object tail
, frame
;
3005 /* A single call to window_loop won't do the job because it only
3006 considers frames on the current keyboard. So loop manually over
3007 frames, and handle each one. */
3008 FOR_EACH_FRAME (tail
, frame
)
3009 window_loop (REPLACE_BUFFER_IN_WINDOWS_SAFELY
, buffer
, 1, frame
);
3013 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
3014 minimum allowable size. */
3017 check_frame_size (FRAME_PTR frame
, int *rows
, int *cols
)
3019 /* For height, we have to see:
3020 how many windows the frame has at minimum (one or two),
3021 and whether it has a menu bar or other special stuff at the top. */
3023 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
3024 ? MIN_SAFE_WINDOW_HEIGHT
3025 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
3027 if (FRAME_TOP_MARGIN (frame
) > 0)
3028 min_height
+= FRAME_TOP_MARGIN (frame
);
3030 if (*rows
< min_height
)
3032 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
3033 *cols
= MIN_SAFE_WINDOW_WIDTH
;
3036 /* Adjust the margins of window W if text area is too small.
3037 Return 1 if window width is ok after adjustment; 0 if window
3038 is still too narrow. */
3041 adjust_window_margins (struct window
*w
)
3043 int box_cols
= (WINDOW_TOTAL_COLS (w
)
3044 - WINDOW_FRINGE_COLS (w
)
3045 - WINDOW_SCROLL_BAR_COLS (w
));
3046 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
3047 + WINDOW_RIGHT_MARGIN_COLS (w
));
3049 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
3052 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
3055 /* Window's text area is too narrow, but reducing the window
3056 margins will fix that. */
3057 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
3058 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
3060 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
3062 wset_left_margin_cols (w
, make_number (margin_cols
/ 2));
3063 wset_right_margin_cols (w
, make_number (margin_cols
/ 2));
3066 wset_right_margin_cols (w
, make_number (margin_cols
));
3069 wset_left_margin_cols (w
, make_number (margin_cols
));
3073 /* The following three routines are needed for running a window's
3074 configuration change hook. */
3076 run_funs (Lisp_Object funs
)
3078 for (; CONSP (funs
); funs
= XCDR (funs
))
3079 if (!EQ (XCAR (funs
), Qt
))
3080 call0 (XCAR (funs
));
3084 select_window_norecord (Lisp_Object window
)
3086 return WINDOW_LIVE_P (window
)
3087 ? Fselect_window (window
, Qt
) : selected_window
;
3091 select_frame_norecord (Lisp_Object frame
)
3093 return FRAME_LIVE_P (XFRAME (frame
))
3094 ? Fselect_frame (frame
, Qt
) : selected_frame
;
3098 run_window_configuration_change_hook (struct frame
*f
)
3100 ptrdiff_t count
= SPECPDL_INDEX ();
3101 Lisp_Object frame
, global_wcch
3102 = Fdefault_value (Qwindow_configuration_change_hook
);
3103 XSETFRAME (frame
, f
);
3105 if (NILP (Vrun_hooks
) || !NILP (inhibit_lisp_code
))
3108 /* Use the right buffer. Matters when running the local hooks. */
3109 if (current_buffer
!= XBUFFER (Fwindow_buffer (Qnil
)))
3111 record_unwind_current_buffer ();
3112 Fset_buffer (Fwindow_buffer (Qnil
));
3115 if (SELECTED_FRAME () != f
)
3117 record_unwind_protect (select_frame_norecord
, Fselected_frame ());
3118 select_frame_norecord (frame
);
3121 /* Look for buffer-local values. */
3123 Lisp_Object windows
= Fwindow_list (frame
, Qlambda
, Qnil
);
3124 for (; CONSP (windows
); windows
= XCDR (windows
))
3126 Lisp_Object window
= XCAR (windows
);
3127 Lisp_Object buffer
= Fwindow_buffer (window
);
3128 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook
,
3131 ptrdiff_t inner_count
= SPECPDL_INDEX ();
3132 record_unwind_protect (select_window_norecord
, Fselected_window ());
3133 select_window_norecord (window
);
3134 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook
,
3136 unbind_to (inner_count
, Qnil
);
3141 run_funs (global_wcch
);
3142 unbind_to (count
, Qnil
);
3145 DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook
,
3146 Srun_window_configuration_change_hook
, 0, 1, 0,
3147 doc
: /* Run `window-configuration-change-hook' for FRAME.
3148 If FRAME is omitted or nil, it defaults to the selected frame. */)
3151 run_window_configuration_change_hook (decode_live_frame (frame
));
3155 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
3156 means it's allowed to run hooks. See make_frame for a case where
3157 it's not allowed. KEEP_MARGINS_P non-zero means that the current
3158 margins, fringes, and scroll-bar settings of the window are not
3159 reset from the buffer's local settings. */
3162 set_window_buffer (Lisp_Object window
, Lisp_Object buffer
, int run_hooks_p
, int keep_margins_p
)
3164 struct window
*w
= XWINDOW (window
);
3165 struct buffer
*b
= XBUFFER (buffer
);
3166 ptrdiff_t count
= SPECPDL_INDEX ();
3167 int samebuf
= EQ (buffer
, w
->buffer
);
3169 wset_buffer (w
, buffer
);
3171 if (EQ (window
, selected_window
))
3172 bset_last_selected_window (b
, window
);
3174 /* Let redisplay errors through. */
3175 b
->display_error_modiff
= 0;
3177 /* Update time stamps of buffer display. */
3178 if (INTEGERP (BVAR (b
, display_count
)))
3179 bset_display_count (b
, make_number (XINT (BVAR (b
, display_count
)) + 1));
3180 bset_display_time (b
, Fcurrent_time ());
3182 wset_window_end_pos (w
, make_number (0));
3183 wset_window_end_vpos (w
, make_number (0));
3184 memset (&w
->last_cursor
, 0, sizeof w
->last_cursor
);
3186 if (!(keep_margins_p
&& samebuf
))
3187 { /* If we're not actually changing the buffer, don't reset hscroll and
3188 vscroll. This case happens for example when called from
3189 change_frame_size_1, where we use a dummy call to
3190 Fset_window_buffer on the frame's selected window (and no other)
3191 just in order to run window-configuration-change-hook.
3192 Resetting hscroll and vscroll here is problematic for things like
3193 image-mode and doc-view-mode since it resets the image's position
3194 whenever we resize the frame. */
3195 w
->hscroll
= w
->min_hscroll
= 0;
3197 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3198 set_marker_restricted (w
->start
,
3199 make_number (b
->last_window_start
),
3201 w
->start_at_line_beg
= 0;
3203 w
->last_modified
= 0;
3204 w
->last_overlay_modified
= 0;
3206 /* Maybe we could move this into the `if' but it's not obviously safe and
3207 I doubt it's worth the trouble. */
3208 windows_or_buffers_changed
++;
3210 /* We must select BUFFER for running the window-scroll-functions. */
3211 /* We can't check ! NILP (Vwindow_scroll_functions) here
3212 because that might itself be a local variable. */
3213 if (window_initialized
)
3215 record_unwind_current_buffer ();
3216 Fset_buffer (buffer
);
3219 XMARKER (w
->pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3221 if (!keep_margins_p
)
3223 /* Set left and right marginal area width etc. from buffer. */
3225 /* This may call adjust_window_margins three times, so
3226 temporarily disable window margins. */
3227 Lisp_Object save_left
= w
->left_margin_cols
;
3228 Lisp_Object save_right
= w
->right_margin_cols
;
3230 wset_left_margin_cols (w
, Qnil
);
3231 wset_right_margin_cols (w
, Qnil
);
3233 Fset_window_fringes (window
,
3234 BVAR (b
, left_fringe_width
), BVAR (b
, right_fringe_width
),
3235 BVAR (b
, fringes_outside_margins
));
3237 Fset_window_scroll_bars (window
,
3238 BVAR (b
, scroll_bar_width
),
3239 BVAR (b
, vertical_scroll_bar_type
), Qnil
);
3241 wset_left_margin_cols (w
, save_left
);
3242 wset_right_margin_cols (w
, save_right
);
3244 Fset_window_margins (window
,
3245 BVAR (b
, left_margin_cols
), BVAR (b
, right_margin_cols
));
3250 if (! NILP (Vwindow_scroll_functions
))
3251 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3252 Fmarker_position (w
->start
));
3253 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w
)));
3256 unbind_to (count
, Qnil
);
3259 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3260 doc
: /* Make WINDOW display BUFFER-OR-NAME as its contents.
3261 WINDOW must be a live window and defaults to the selected one.
3262 BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
3264 Optional third argument KEEP-MARGINS non-nil means that WINDOW's current
3265 display margins, fringe widths, and scroll bar settings are preserved;
3266 the default is to reset these from the local settings for BUFFER-OR-NAME
3267 or the frame defaults. Return nil.
3269 This function throws an error when WINDOW is strongly dedicated to its
3270 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3271 already display BUFFER-OR-NAME.
3273 This function runs `window-scroll-functions' before running
3274 `window-configuration-change-hook'. */)
3275 (register Lisp_Object window
, Lisp_Object buffer_or_name
, Lisp_Object keep_margins
)
3277 register Lisp_Object tem
, buffer
;
3278 register struct window
*w
= decode_live_window (window
);
3280 XSETWINDOW (window
, w
);
3281 buffer
= Fget_buffer (buffer_or_name
);
3282 CHECK_BUFFER (buffer
);
3283 if (!BUFFER_LIVE_P (XBUFFER (buffer
)))
3284 error ("Attempt to display deleted buffer");
3288 error ("Window is deleted");
3291 if (!EQ (tem
, buffer
))
3293 if (EQ (w
->dedicated
, Qt
))
3294 /* WINDOW is strongly dedicated to its buffer, signal an
3296 error ("Window is dedicated to `%s'", SDATA (BVAR (XBUFFER (tem
), name
)));
3298 /* WINDOW is weakly dedicated to its buffer, reset
3300 wset_dedicated (w
, Qnil
);
3302 call1 (Qrecord_window_buffer
, window
);
3308 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3314 display_buffer (Lisp_Object buffer
, Lisp_Object not_this_window_p
, Lisp_Object override_frame
)
3316 return call3 (Qdisplay_buffer
, buffer
, not_this_window_p
, override_frame
);
3319 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3321 doc
: /* Force all windows to be updated on next redisplay.
3322 If optional arg OBJECT is a window, force redisplay of that window only.
3323 If OBJECT is a buffer or buffer name, force redisplay of all windows
3324 displaying that buffer. */)
3325 (Lisp_Object object
)
3329 windows_or_buffers_changed
++;
3330 update_mode_lines
++;
3334 if (WINDOWP (object
))
3336 struct window
*w
= XWINDOW (object
);
3337 mark_window_display_accurate (object
, 0);
3338 w
->update_mode_line
= 1;
3339 if (BUFFERP (w
->buffer
))
3340 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
3341 ++update_mode_lines
;
3345 if (STRINGP (object
))
3346 object
= Fget_buffer (object
);
3347 if (BUFFERP (object
) && BUFFER_LIVE_P (XBUFFER (object
))
3348 && buffer_window_count (XBUFFER (object
)))
3350 /* If buffer is live and shown in at least one window, find
3351 all windows showing this buffer and force update of them. */
3352 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3353 return NILP (object
) ? Qnil
: Qt
;
3356 /* If nothing suitable was found, just return.
3357 We could signal an error, but this feature will typically be used
3358 asynchronously in timers or process sentinels, so we don't. */
3362 /* Obsolete since 24.3. */
3364 temp_output_buffer_show (register Lisp_Object buf
)
3366 register struct buffer
*old
= current_buffer
;
3367 register Lisp_Object window
;
3368 register struct window
*w
;
3370 bset_directory (XBUFFER (buf
), BVAR (current_buffer
, directory
));
3373 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3377 set_buffer_internal (old
);
3379 if (!NILP (Vtemp_buffer_show_function
))
3380 call1 (Vtemp_buffer_show_function
, buf
);
3383 window
= display_buffer (buf
, Qnil
, Qnil
);
3385 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3386 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3387 Vminibuf_scroll_window
= window
;
3388 w
= XWINDOW (window
);
3391 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3392 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3394 /* Run temp-buffer-show-hook, with the chosen window selected
3395 and its buffer current. */
3397 ptrdiff_t count
= SPECPDL_INDEX ();
3398 Lisp_Object prev_window
, prev_buffer
;
3399 prev_window
= selected_window
;
3400 XSETBUFFER (prev_buffer
, old
);
3402 /* Select the window that was chosen, for running the hook.
3403 Note: Both Fselect_window and select_window_norecord may
3404 set-buffer to the buffer displayed in the window,
3405 so we need to save the current buffer. --stef */
3406 record_unwind_protect (Fset_buffer
, prev_buffer
);
3407 record_unwind_protect (select_window_norecord
, prev_window
);
3408 Fselect_window (window
, Qt
);
3409 Fset_buffer (w
->buffer
);
3410 Frun_hooks (1, &Qtemp_buffer_show_hook
);
3411 unbind_to (count
, Qnil
);
3416 /* Make new window, have it replace WINDOW in window-tree, and make
3417 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
3418 horizontal child). */
3420 make_parent_window (Lisp_Object window
, int horflag
)
3423 register struct window
*o
, *p
;
3425 o
= XWINDOW (window
);
3426 p
= allocate_window ();
3427 memcpy ((char *) p
+ sizeof (struct vectorlike_header
),
3428 (char *) o
+ sizeof (struct vectorlike_header
),
3429 word_size
* VECSIZE (struct window
));
3430 /* P's buffer slot may change from nil to a buffer. */
3431 adjust_window_count (p
, 1);
3432 XSETWINDOW (parent
, p
);
3434 p
->sequence_number
= ++sequence_number
;
3436 replace_window (window
, parent
, 1);
3438 wset_next (o
, Qnil
);
3439 wset_prev (o
, Qnil
);
3440 wset_parent (o
, parent
);
3442 wset_hchild (p
, horflag
? window
: Qnil
);
3443 wset_vchild (p
, horflag
? Qnil
: window
);
3444 wset_start (p
, Qnil
);
3445 wset_pointm (p
, Qnil
);
3446 wset_buffer (p
, Qnil
);
3447 wset_combination_limit (p
, Qnil
);
3448 wset_window_parameters (p
, Qnil
);
3451 /* Make new window from scratch. */
3456 register struct window
*w
;
3458 w
= allocate_window ();
3459 /* Initialize Lisp data. Note that allocate_window initializes all
3460 Lisp data to nil, so do it only for slots which should not be nil. */
3461 wset_left_col (w
, make_number (0));
3462 wset_top_line (w
, make_number (0));
3463 wset_total_lines (w
, make_number (0));
3464 wset_total_cols (w
, make_number (0));
3465 wset_normal_lines (w
, make_float (1.0));
3466 wset_normal_cols (w
, make_float (1.0));
3467 wset_new_total (w
, make_number (0));
3468 wset_new_normal (w
, make_number (0));
3469 wset_start (w
, Fmake_marker ());
3470 wset_pointm (w
, Fmake_marker ());
3471 wset_vertical_scroll_bar_type (w
, Qt
);
3472 wset_window_end_pos (w
, make_number (0));
3473 wset_window_end_vpos (w
, make_number (0));
3474 /* These Lisp fields are marked specially so they're not set to nil by
3476 wset_prev_buffers (w
, Qnil
);
3477 wset_next_buffers (w
, Qnil
);
3479 /* Initialize non-Lisp data. Note that allocate_window zeroes out all
3480 non-Lisp data, so do it only for slots which should not be zero. */
3481 w
->nrows_scale_factor
= w
->ncols_scale_factor
= 1;
3482 w
->phys_cursor_type
= -1;
3483 w
->phys_cursor_width
= -1;
3484 w
->sequence_number
= ++sequence_number
;
3486 /* Reset window_list. */
3487 Vwindow_list
= Qnil
;
3488 /* Return window. */
3489 XSETWINDOW (window
, w
);
3493 DEFUN ("set-window-new-total", Fset_window_new_total
, Sset_window_new_total
, 2, 3, 0,
3494 doc
: /* Set new total size of WINDOW to SIZE.
3495 WINDOW must be a valid window and defaults to the selected one.
3498 Optional argument ADD non-nil means add SIZE to the new total size of
3499 WINDOW and return the sum.
3501 Note: This function does not operate on any child windows of WINDOW. */)
3502 (Lisp_Object window
, Lisp_Object size
, Lisp_Object add
)
3504 struct window
*w
= decode_valid_window (window
);
3506 CHECK_NUMBER (size
);
3508 wset_new_total (w
, size
);
3510 wset_new_total (w
, make_number (XINT (w
->new_total
) + XINT (size
)));
3512 return w
->new_total
;
3515 DEFUN ("set-window-new-normal", Fset_window_new_normal
, Sset_window_new_normal
, 1, 2, 0,
3516 doc
: /* Set new normal size of WINDOW to SIZE.
3517 WINDOW must be a valid window and defaults to the selected one.
3520 Note: This function does not operate on any child windows of WINDOW. */)
3521 (Lisp_Object window
, Lisp_Object size
)
3523 wset_new_normal (decode_valid_window (window
), size
);
3527 /* Return 1 if setting w->total_lines (w->total_cols if HORFLAG is
3528 non-zero) to w->new_total would result in correct heights (widths)
3529 for window W and recursively all child windows of W.
3531 Note: This function does not check any of `window-fixed-size-p',
3532 `window-min-height' or `window-min-width'. It does check that window
3533 sizes do not drop below one line (two columns). */
3535 window_resize_check (struct window
*w
, int horflag
)
3539 if (!NILP (w
->vchild
))
3540 /* W is a vertical combination. */
3542 c
= XWINDOW (w
->vchild
);
3544 /* All child windows of W must have the same width as W. */
3548 if ((XINT (c
->new_total
) != XINT (w
->new_total
))
3549 || !window_resize_check (c
, horflag
))
3551 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3556 /* The sum of the heights of the child windows of W must equal
3559 int sum_of_sizes
= 0;
3562 if (!window_resize_check (c
, horflag
))
3564 sum_of_sizes
= sum_of_sizes
+ XINT (c
->new_total
);
3565 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3567 return (sum_of_sizes
== XINT (w
->new_total
));
3570 else if (!NILP (w
->hchild
))
3571 /* W is a horizontal combination. */
3573 c
= XWINDOW (w
->hchild
);
3575 /* The sum of the widths of the child windows of W must equal W's
3578 int sum_of_sizes
= 0;
3581 if (!window_resize_check (c
, horflag
))
3583 sum_of_sizes
= sum_of_sizes
+ XINT (c
->new_total
);
3584 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3586 return (sum_of_sizes
== XINT (w
->new_total
));
3589 /* All child windows of W must have the same height as W. */
3593 if ((XINT (c
->new_total
) != XINT (w
->new_total
))
3594 || !window_resize_check (c
, horflag
))
3596 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3602 /* A leaf window. Make sure it's not too small. The following
3603 hardcodes the values of `window-safe-min-width' (2) and
3604 `window-safe-min-height' (1) which are defined in window.el. */
3605 return XINT (w
->new_total
) >= (horflag
? 2 : 1);
3608 /* Set w->total_lines (w->total_cols if HORIZONTAL is non-zero) to
3609 w->new_total for window W and recursively all child windows of W.
3610 Also calculate and assign the new vertical (horizontal) start
3611 positions of each of these windows.
3613 This function does not perform any error checks. Make sure you have
3614 run window_resize_check on W before applying this function. */
3616 window_resize_apply (struct window
*w
, int horflag
)
3621 /* Note: Assigning new_normal requires that the new total size of the
3622 parent window has been set *before*. */
3625 wset_total_cols (w
, w
->new_total
);
3626 if (NUMBERP (w
->new_normal
))
3627 wset_normal_cols (w
, w
->new_normal
);
3629 pos
= XINT (w
->left_col
);
3633 wset_total_lines (w
, w
->new_total
);
3634 if (NUMBERP (w
->new_normal
))
3635 wset_normal_lines (w
, w
->new_normal
);
3637 pos
= XINT (w
->top_line
);
3640 if (!NILP (w
->vchild
))
3641 /* W is a vertical combination. */
3643 c
= XWINDOW (w
->vchild
);
3647 wset_left_col (c
, make_number (pos
));
3649 wset_top_line (c
, make_number (pos
));
3650 window_resize_apply (c
, horflag
);
3652 pos
= pos
+ XINT (c
->total_lines
);
3653 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3656 else if (!NILP (w
->hchild
))
3657 /* W is a horizontal combination. */
3659 c
= XWINDOW (w
->hchild
);
3663 wset_left_col (c
, make_number (pos
));
3665 wset_top_line (c
, make_number (pos
));
3666 window_resize_apply (c
, horflag
);
3668 pos
= pos
+ XINT (c
->total_cols
);
3669 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3673 /* Clear out some redisplay caches. */
3674 w
->last_modified
= 0;
3675 w
->last_overlay_modified
= 0;
3679 DEFUN ("window-resize-apply", Fwindow_resize_apply
, Swindow_resize_apply
, 0, 2, 0,
3680 doc
: /* Apply requested size values for window-tree of FRAME.
3681 If FRAME is omitted or nil, it defaults to the selected frame.
3683 Optional argument HORIZONTAL omitted or nil means apply requested
3684 height values. HORIZONTAL non-nil means apply requested width values.
3686 This function checks whether the requested values sum up to a valid
3687 window layout, recursively assigns the new sizes of all child windows
3688 and calculates and assigns the new start positions of these windows.
3690 Note: This function does not check any of `window-fixed-size-p',
3691 `window-min-height' or `window-min-width'. All these checks have to
3692 be applied on the Elisp level. */)
3693 (Lisp_Object frame
, Lisp_Object horizontal
)
3695 struct frame
*f
= decode_live_frame (frame
);
3696 struct window
*r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3697 int horflag
= !NILP (horizontal
);
3699 if (!window_resize_check (r
, horflag
)
3700 || ! EQ (r
->new_total
,
3701 (horflag
? r
->total_cols
: r
->total_lines
)))
3705 window_resize_apply (r
, horflag
);
3707 windows_or_buffers_changed
++;
3708 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3713 run_window_configuration_change_hook (f
);
3719 /* Resize frame F's windows when number of lines of F is set to SIZE.
3720 HORFLAG 1 means resize windows when number of columns of F is set to
3723 This function can delete all windows but the selected one in order to
3724 satisfy the request. The result will be meaningful if and only if
3725 F's windows have meaningful sizes when you call this. */
3727 resize_frame_windows (struct frame
*f
, int size
, int horflag
)
3729 Lisp_Object root
= f
->root_window
;
3730 struct window
*r
= XWINDOW (root
);
3731 Lisp_Object mini
= f
->minibuffer_window
;
3733 /* new_size is the new size of the frame's root window. */
3734 int new_size
= (horflag
3737 - FRAME_TOP_MARGIN (f
)
3738 - ((FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
3741 wset_top_line (r
, make_number (FRAME_TOP_MARGIN (f
)));
3742 if (NILP (r
->vchild
) && NILP (r
->hchild
))
3743 /* For a leaf root window just set the size. */
3745 wset_total_cols (r
, make_number (new_size
));
3747 wset_total_lines (r
, make_number (new_size
));
3750 /* old_size is the old size of the frame's root window. */
3751 int old_size
= XFASTINT (horflag
? r
->total_cols
3755 XSETINT (delta
, new_size
- old_size
);
3756 /* Try a "normal" resize first. */
3757 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qnil
);
3758 if (window_resize_check (r
, horflag
)
3759 && new_size
== XINT (r
->new_total
))
3760 window_resize_apply (r
, horflag
);
3763 /* Try with "reasonable" minimum sizes next. */
3764 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qt
);
3765 if (window_resize_check (r
, horflag
)
3766 && new_size
== XINT (r
->new_total
))
3767 window_resize_apply (r
, horflag
);
3770 /* Finally, try with "safe" minimum sizes. */
3771 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qsafe
);
3772 if (window_resize_check (r
, horflag
)
3773 && new_size
== XINT (r
->new_total
))
3774 window_resize_apply (r
, horflag
);
3777 /* We lost. Delete all windows but the frame's
3779 root
= f
->selected_window
;
3780 Fdelete_other_windows_internal (root
, Qnil
);
3782 wset_total_cols (XWINDOW (root
), make_number (new_size
));
3784 wset_total_lines (XWINDOW (root
), make_number (new_size
));
3790 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
3794 wset_total_cols (m
, make_number (size
));
3797 /* Are we sure we always want 1 line here? */
3798 wset_total_lines (m
, make_number (1));
3800 (m
, make_number (XINT (r
->top_line
) + XINT (r
->total_lines
)));
3804 windows_or_buffers_changed
++;
3808 DEFUN ("split-window-internal", Fsplit_window_internal
, Ssplit_window_internal
, 4, 4, 0,
3809 doc
: /* Split window OLD.
3810 Second argument TOTAL-SIZE specifies the number of lines or columns of the
3811 new window. In any case TOTAL-SIZE must be a positive integer.
3813 Third argument SIDE nil (or `below') specifies that the new window shall
3814 be located below WINDOW. SIDE `above' means the new window shall be
3815 located above WINDOW. In both cases TOTAL-SIZE specifies the number of
3816 lines of the new window including space reserved for the mode and/or
3819 SIDE t (or `right') specifies that the new window shall be located on
3820 the right side of WINDOW. SIDE `left' means the new window shall be
3821 located on the left of WINDOW. In both cases TOTAL-SIZE specifies the
3822 number of columns of the new window including space reserved for fringes
3823 and the scrollbar or a divider column.
3825 Fourth argument NORMAL-SIZE specifies the normal size of the new window
3826 according to the SIDE argument.
3828 The new total and normal sizes of all involved windows must have been
3829 set correctly. See the code of `split-window' for how this is done. */)
3830 (Lisp_Object old
, Lisp_Object total_size
, Lisp_Object side
, Lisp_Object normal_size
)
3832 /* OLD (*o) is the window we have to split. (*p) is either OLD's
3833 parent window or an internal window we have to install as OLD's new
3834 parent. REFERENCE (*r) must denote a live window, or is set to OLD
3835 provided OLD is a leaf window, or to the frame's selected window.
3836 NEW (*n) is the new window created with some parameters taken from
3838 register Lisp_Object
new, frame
, reference
;
3839 register struct window
*o
, *p
, *n
, *r
;
3842 /* HORFLAG is 1 when we split side-by-side, 0 otherwise. */
3843 = EQ (side
, Qt
) || EQ (side
, Qleft
) || EQ (side
, Qright
);
3844 int combination_limit
= 0;
3848 frame
= WINDOW_FRAME (o
);
3851 CHECK_NUMBER (total_size
);
3853 /* Set combination_limit to 1 if we have to make a new parent window.
3854 We do that if either `window-combination-limit' is t, or OLD has no
3855 parent, or OLD is ortho-combined. */
3857 EQ (Vwindow_combination_limit
, Qt
)
3860 ? (XWINDOW (o
->parent
)->hchild
)
3861 : (XWINDOW (o
->parent
)->vchild
));
3863 /* We need a live reference window to initialize some parameters. */
3864 if (WINDOW_LIVE_P (old
))
3865 /* OLD is live, use it as reference window. */
3868 /* Use the frame's selected window as reference window. */
3869 reference
= FRAME_SELECTED_WINDOW (f
);
3870 r
= XWINDOW (reference
);
3872 /* The following bugs are caught by `split-window'. */
3873 if (MINI_WINDOW_P (o
))
3874 error ("Attempt to split minibuffer window");
3875 else if (XINT (total_size
) < (horflag
? 2 : 1))
3876 error ("Size of new window too small (after split)");
3877 else if (!combination_limit
&& !NILP (Vwindow_combination_resize
))
3878 /* `window-combination-resize' non-nil means try to resize OLD's siblings
3881 p
= XWINDOW (o
->parent
);
3882 /* Temporarily pretend we split the parent window. */
3884 (p
, make_number (XINT (horflag
? p
->total_cols
: p
->total_lines
)
3885 - XINT (total_size
)));
3886 if (!window_resize_check (p
, horflag
))
3887 error ("Window sizes don't fit");
3889 /* Undo the temporary pretension. */
3890 wset_new_total (p
, horflag
? p
->total_cols
: p
->total_lines
);
3894 if (!window_resize_check (o
, horflag
))
3895 error ("Resizing old window failed");
3896 else if (XINT (total_size
) + XINT (o
->new_total
)
3897 != XINT (horflag
? o
->total_cols
: o
->total_lines
))
3898 error ("Sum of sizes of old and new window don't fit");
3901 /* This is our point of no return. */
3902 if (combination_limit
)
3904 /* Save the old value of o->normal_cols/lines. It gets corrupted
3905 by make_parent_window and we need it below for assigning it to
3907 Lisp_Object new_normal
3908 = horflag
? o
->normal_cols
: o
->normal_lines
;
3910 make_parent_window (old
, horflag
);
3911 p
= XWINDOW (o
->parent
);
3912 if (EQ (Vwindow_combination_limit
, Qt
))
3913 /* Store t in the new parent's combination_limit slot to avoid
3914 that its children get merged into another window. */
3915 wset_combination_limit (p
, Qt
);
3916 /* These get applied below. */
3917 wset_new_total (p
, horflag
? o
->total_cols
: o
->total_lines
);
3918 wset_new_normal (p
, new_normal
);
3921 p
= XWINDOW (o
->parent
);
3923 windows_or_buffers_changed
++;
3924 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3925 new = make_window ();
3927 wset_frame (n
, frame
);
3928 wset_parent (n
, o
->parent
);
3929 wset_vchild (n
, Qnil
);
3930 wset_hchild (n
, Qnil
);
3932 if (EQ (side
, Qabove
) || EQ (side
, Qleft
))
3934 wset_prev (n
, o
->prev
);
3937 wset_hchild (p
, new);
3939 wset_vchild (p
, new);
3941 wset_next (XWINDOW (n
->prev
), new);
3947 wset_next (n
, o
->next
);
3948 if (!NILP (n
->next
))
3949 wset_prev (XWINDOW (n
->next
), new);
3954 n
->window_end_valid
= 0;
3955 memset (&n
->last_cursor
, 0, sizeof n
->last_cursor
);
3957 /* Get special geometry settings from reference window. */
3958 wset_left_margin_cols (n
, r
->left_margin_cols
);
3959 wset_right_margin_cols (n
, r
->right_margin_cols
);
3960 wset_left_fringe_width (n
, r
->left_fringe_width
);
3961 wset_right_fringe_width (n
, r
->right_fringe_width
);
3962 n
->fringes_outside_margins
= r
->fringes_outside_margins
;
3963 wset_scroll_bar_width (n
, r
->scroll_bar_width
);
3964 wset_vertical_scroll_bar_type (n
, r
->vertical_scroll_bar_type
);
3966 /* Directly assign orthogonal coordinates and sizes. */
3969 wset_top_line (n
, o
->top_line
);
3970 wset_total_lines (n
, o
->total_lines
);
3974 wset_left_col (n
, o
->left_col
);
3975 wset_total_cols (n
, o
->total_cols
);
3978 /* Iso-coordinates and sizes are assigned by window_resize_apply,
3979 get them ready here. */
3980 wset_new_total (n
, total_size
);
3981 wset_new_normal (n
, normal_size
);
3984 window_resize_apply (p
, horflag
);
3986 /* Set buffer of NEW to buffer of reference window. Don't run
3988 set_window_buffer (new, r
->buffer
, 0, 1);
3991 /* Maybe we should run the scroll functions in Elisp (which already
3992 runs the configuration change hook). */
3993 if (! NILP (Vwindow_scroll_functions
))
3994 run_hook_with_args_2 (Qwindow_scroll_functions
, new,
3995 Fmarker_position (n
->start
));
4001 DEFUN ("delete-window-internal", Fdelete_window_internal
, Sdelete_window_internal
, 1, 1, 0,
4002 doc
: /* Remove WINDOW from its frame.
4003 WINDOW defaults to the selected window. Return nil.
4004 Signal an error when WINDOW is the only window on its frame. */)
4005 (register Lisp_Object window
)
4007 register Lisp_Object parent
, sibling
, frame
, root
;
4008 struct window
*w
, *p
, *s
, *r
;
4011 int before_sibling
= 0;
4013 w
= decode_any_window (window
);
4014 XSETWINDOW (window
, w
);
4015 if (NILP (w
->buffer
)
4016 && NILP (w
->hchild
) && NILP (w
->vchild
))
4017 /* It's a no-op to delete an already deleted window. */
4022 /* Never delete a minibuffer or frame root window. */
4023 error ("Attempt to delete minibuffer or sole ordinary window");
4024 else if (NILP (w
->prev
) && NILP (w
->next
))
4025 /* Rather bow out here, this case should be handled on the Elisp
4027 error ("Attempt to delete sole window of parent");
4029 p
= XWINDOW (parent
);
4030 horflag
= NILP (p
->vchild
);
4032 frame
= WINDOW_FRAME (w
);
4035 root
= FRAME_ROOT_WINDOW (f
);
4038 /* Unlink WINDOW from window tree. */
4040 /* Get SIBLING below (on the right of) WINDOW. */
4042 /* before_sibling 1 means WINDOW is the first child of its
4043 parent and thus before the sibling. */
4046 s
= XWINDOW (sibling
);
4047 wset_prev (s
, Qnil
);
4049 wset_hchild (p
, sibling
);
4051 wset_vchild (p
, sibling
);
4054 /* Get SIBLING above (on the left of) WINDOW. */
4057 s
= XWINDOW (sibling
);
4058 wset_next (s
, w
->next
);
4059 if (!NILP (s
->next
))
4060 wset_prev (XWINDOW (s
->next
), sibling
);
4063 if (window_resize_check (r
, horflag
)
4064 && EQ (r
->new_total
,
4065 (horflag
? r
->total_cols
: r
->total_lines
)))
4066 /* We can delete WINDOW now. */
4071 window_resize_apply (p
, horflag
);
4073 /* If this window is referred to by the dpyinfo's mouse
4074 highlight, invalidate that slot to be safe (Bug#9904). */
4075 if (!FRAME_INITIAL_P (f
))
4077 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
4079 if (EQ (hlinfo
->mouse_face_window
, window
))
4080 hlinfo
->mouse_face_window
= Qnil
;
4083 windows_or_buffers_changed
++;
4084 Vwindow_list
= Qnil
;
4085 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4087 wset_next (w
, Qnil
); /* Don't delete w->next too. */
4088 free_window_matrices (w
);
4090 if (!NILP (w
->vchild
))
4092 delete_all_child_windows (w
->vchild
);
4093 wset_vchild (w
, Qnil
);
4095 else if (!NILP (w
->hchild
))
4097 delete_all_child_windows (w
->hchild
);
4098 wset_hchild (w
, Qnil
);
4100 else if (!NILP (w
->buffer
))
4103 unchain_marker (XMARKER (w
->pointm
));
4104 unchain_marker (XMARKER (w
->start
));
4105 wset_buffer (w
, Qnil
);
4108 if (NILP (s
->prev
) && NILP (s
->next
))
4109 /* A matrjoshka where SIBLING has become the only child of
4112 /* Put SIBLING into PARENT's place. */
4113 replace_window (parent
, sibling
, 0);
4114 /* Have SIBLING inherit the following three slot values from
4115 PARENT (the combination_limit slot is not inherited). */
4116 wset_normal_cols (s
, p
->normal_cols
);
4117 wset_normal_lines (s
, p
->normal_lines
);
4118 /* Mark PARENT as deleted. */
4119 wset_vchild (p
, Qnil
);
4120 wset_hchild (p
, Qnil
);
4121 /* Try to merge SIBLING into its new parent. */
4122 recombine_windows (sibling
);
4127 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f
)))
4128 /* We deleted the frame's selected window. */
4130 /* Use the frame's first window as fallback ... */
4131 Lisp_Object new_selected_window
= Fframe_first_window (frame
);
4132 /* ... but preferably use its most recently used window. */
4133 Lisp_Object mru_window
;
4135 /* `get-mru-window' might fail for some reason so play it safe
4136 - promote the first window _without recording it_ first. */
4137 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4138 Fselect_window (new_selected_window
, Qt
);
4140 fset_selected_window (f
, new_selected_window
);
4144 /* Now look whether `get-mru-window' gets us something. */
4145 mru_window
= call1 (Qget_mru_window
, frame
);
4146 if (WINDOW_LIVE_P (mru_window
)
4147 && EQ (XWINDOW (mru_window
)->frame
, frame
))
4148 new_selected_window
= mru_window
;
4150 /* If all ended up well, we now promote the mru window. */
4151 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4152 Fselect_window (new_selected_window
, Qnil
);
4154 fset_selected_window (f
, new_selected_window
);
4159 /* Must be run by the caller:
4160 run_window_configuration_change_hook (f); */
4163 /* We failed: Relink WINDOW into window tree. */
4167 wset_prev (s
, window
);
4169 wset_hchild (p
, window
);
4171 wset_vchild (p
, window
);
4175 wset_next (s
, window
);
4176 if (!NILP (w
->next
))
4177 wset_prev (XWINDOW (w
->next
), window
);
4179 error ("Deletion failed");
4185 /***********************************************************************
4186 Resizing Mini-Windows
4187 ***********************************************************************/
4189 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we
4192 grow_mini_window (struct window
*w
, int delta
)
4194 struct frame
*f
= XFRAME (w
->frame
);
4196 Lisp_Object root
, value
;
4198 eassert (MINI_WINDOW_P (w
));
4199 eassert (delta
>= 0);
4201 root
= FRAME_ROOT_WINDOW (f
);
4203 value
= call2 (Qwindow_resize_root_window_vertically
,
4204 root
, make_number (- delta
));
4205 if (INTEGERP (value
) && window_resize_check (r
, 0))
4208 window_resize_apply (r
, 0);
4210 /* Grow the mini-window. */
4212 (w
, make_number (XFASTINT (r
->top_line
) + XFASTINT (r
->total_lines
)));
4214 (w
, make_number (XFASTINT (w
->total_lines
) - XINT (value
)));
4215 w
->last_modified
= 0;
4216 w
->last_overlay_modified
= 0;
4218 windows_or_buffers_changed
++;
4225 /* Shrink mini-window W. */
4227 shrink_mini_window (struct window
*w
)
4229 struct frame
*f
= XFRAME (w
->frame
);
4231 Lisp_Object root
, value
;
4234 eassert (MINI_WINDOW_P (w
));
4236 size
= XINT (w
->total_lines
);
4239 root
= FRAME_ROOT_WINDOW (f
);
4241 value
= call2 (Qwindow_resize_root_window_vertically
,
4242 root
, make_number (size
- 1));
4243 if (INTEGERP (value
) && window_resize_check (r
, 0))
4246 window_resize_apply (r
, 0);
4248 /* Shrink the mini-window. */
4249 wset_top_line (w
, make_number (XFASTINT (r
->top_line
)
4250 + XFASTINT (r
->total_lines
)));
4251 wset_total_lines (w
, make_number (1));
4253 w
->last_modified
= 0;
4254 w
->last_overlay_modified
= 0;
4256 windows_or_buffers_changed
++;
4260 /* If the above failed for whatever strange reason we must make a
4261 one window frame here. The same routine will be needed when
4262 shrinking the frame (and probably when making the initial
4263 *scratch* window). For the moment leave things as they are. */
4267 DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal
, Sresize_mini_window_internal
, 1, 1, 0,
4268 doc
: /* Resize minibuffer window WINDOW. */)
4269 (Lisp_Object window
)
4271 struct window
*w
= XWINDOW (window
);
4276 CHECK_WINDOW (window
);
4277 f
= XFRAME (w
->frame
);
4279 if (!EQ (FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
)), window
))
4280 error ("Not a valid minibuffer window");
4281 else if (FRAME_MINIBUF_ONLY_P (f
))
4282 error ("Cannot resize a minibuffer-only frame");
4284 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4285 height
= XINT (r
->total_lines
) + XINT (w
->total_lines
);
4286 if (window_resize_check (r
, 0)
4287 && XINT (w
->new_total
) > 0
4288 && height
== XINT (r
->new_total
) + XINT (w
->new_total
))
4291 window_resize_apply (r
, 0);
4293 wset_total_lines (w
, w
->new_total
);
4294 wset_top_line (w
, make_number (XINT (r
->top_line
)
4295 + XINT (r
->total_lines
)));
4297 windows_or_buffers_changed
++;
4298 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4302 run_window_configuration_change_hook (f
);
4305 else error ("Failed to resize minibuffer window");
4308 /* Mark window cursors off for all windows in the window tree rooted
4309 at W by setting their phys_cursor_on_p flag to zero. Called from
4310 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4311 the frame are cleared. */
4314 mark_window_cursors_off (struct window
*w
)
4318 if (!NILP (w
->hchild
))
4319 mark_window_cursors_off (XWINDOW (w
->hchild
));
4320 else if (!NILP (w
->vchild
))
4321 mark_window_cursors_off (XWINDOW (w
->vchild
));
4323 w
->phys_cursor_on_p
= 0;
4325 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4330 /* Return number of lines of text (not counting mode lines) in W. */
4333 window_internal_height (struct window
*w
)
4335 int ht
= XFASTINT (w
->total_lines
);
4337 if (!MINI_WINDOW_P (w
))
4339 if (!NILP (w
->parent
)
4340 || !NILP (w
->vchild
)
4341 || !NILP (w
->hchild
)
4344 || WINDOW_WANTS_MODELINE_P (w
))
4347 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4354 /************************************************************************
4356 ***********************************************************************/
4358 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4359 N screen-fulls, which is defined as the height of the window minus
4360 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4361 instead. Negative values of N mean scroll down. NOERROR non-zero
4362 means don't signal an error if we try to move over BEGV or ZV,
4366 window_scroll (Lisp_Object window
, EMACS_INT n
, int whole
, int noerror
)
4369 n
= clip_to_bounds (INT_MIN
, n
, INT_MAX
);
4371 /* If we must, use the pixel-based version which is much slower than
4372 the line-based one but can handle varying line heights. */
4373 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4374 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4376 window_scroll_line_based (window
, n
, whole
, noerror
);
4382 /* Implementation of window_scroll that works based on pixel line
4383 heights. See the comment of window_scroll for parameter
4387 window_scroll_pixel_based (Lisp_Object window
, int n
, int whole
, int noerror
)
4390 struct window
*w
= XWINDOW (window
);
4391 struct text_pos start
;
4392 int this_scroll_margin
;
4393 /* True if we fiddled the window vscroll field without really scrolling. */
4395 int x
, y
, rtop
, rbot
, rowh
, vpos
;
4396 void *itdata
= NULL
;
4398 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4399 /* Scrolling a minibuffer window via scroll bar when the echo area
4400 shows long text sometimes resets the minibuffer contents behind
4402 if (CHARPOS (start
) > ZV
)
4403 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4405 /* If PT is not visible in WINDOW, move back one half of
4406 the screen. Allow PT to be partially visible, otherwise
4407 something like (scroll-down 1) with PT in the line before
4408 the partially visible one would recenter. */
4410 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
4412 itdata
= bidi_shelve_cache ();
4413 /* Move backward half the height of the window. Performance note:
4414 vmotion used here is about 10% faster, but would give wrong
4415 results for variable height lines. */
4416 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4417 it
.current_y
= it
.last_visible_y
;
4418 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4420 /* The function move_iterator_vertically may move over more than
4421 the specified y-distance. If it->w is small, e.g. a
4422 mini-buffer window, we may end up in front of the window's
4423 display area. This is the case when Start displaying at the
4424 start of the line containing PT in this case. */
4425 if (it
.current_y
<= 0)
4427 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4428 move_it_vertically_backward (&it
, 0);
4432 start
= it
.current
.pos
;
4433 bidi_unshelve_cache (itdata
, 0);
4435 else if (auto_window_vscroll_p
)
4437 if (rtop
|| rbot
) /* partially visible */
4440 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4442 dy
= max ((window_box_height (w
)
4443 - next_screen_context_lines
* dy
),
4449 /* Only vscroll backwards if already vscrolled forwards. */
4450 if (w
->vscroll
< 0 && rtop
> 0)
4452 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
4453 Fset_window_vscroll (window
, make_number (px
), Qt
);
4459 /* Do vscroll if already vscrolled or only display line. */
4460 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
4462 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
4463 Fset_window_vscroll (window
, make_number (px
), Qt
);
4467 /* Maybe modify window start instead of scrolling. */
4468 if (rbot
> 0 || w
->vscroll
< 0)
4472 Fset_window_vscroll (window
, make_number (0), Qt
);
4473 /* If there are other text lines above the current row,
4474 move window start to current row. Else to next row. */
4476 spos
= XINT (Fline_beginning_position (Qnil
));
4478 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
4479 set_marker_restricted (w
->start
, make_number (spos
),
4481 w
->start_at_line_beg
= 1;
4482 w
->update_mode_line
= 1;
4483 w
->last_modified
= 0;
4484 w
->last_overlay_modified
= 0;
4485 /* Set force_start so that redisplay_window will run the
4486 window-scroll-functions. */
4492 /* Cancel previous vscroll. */
4493 Fset_window_vscroll (window
, make_number (0), Qt
);
4496 itdata
= bidi_shelve_cache ();
4497 /* If scroll_preserve_screen_position is non-nil, we try to set
4498 point in the same window line as it is now, so get that line. */
4499 if (!NILP (Vscroll_preserve_screen_position
))
4501 /* We preserve the goal pixel coordinate across consecutive
4502 calls to scroll-up, scroll-down and other commands that
4503 have the `scroll-command' property. This avoids the
4504 possibility of point becoming "stuck" on a tall line when
4505 scrolling by one line. */
4506 if (window_scroll_pixel_based_preserve_y
< 0
4507 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
4508 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
4510 start_display (&it
, w
, start
);
4511 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4512 window_scroll_pixel_based_preserve_y
= it
.current_y
;
4513 window_scroll_pixel_based_preserve_x
= it
.current_x
;
4517 window_scroll_pixel_based_preserve_y
4518 = window_scroll_pixel_based_preserve_x
= -1;
4520 /* Move iterator it from start the specified distance forward or
4521 backward. The result is the new window start. */
4522 start_display (&it
, w
, start
);
4525 ptrdiff_t start_pos
= IT_CHARPOS (it
);
4526 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4527 dy
= max ((window_box_height (w
)
4528 - next_screen_context_lines
* dy
),
4531 /* Note that move_it_vertically always moves the iterator to the
4532 start of a line. So, if the last line doesn't have a newline,
4533 we would end up at the start of the line ending at ZV. */
4536 move_it_vertically_backward (&it
, -dy
);
4537 /* Ensure we actually do move, e.g. in case we are currently
4538 looking at an image that is taller that the window height. */
4539 while (start_pos
== IT_CHARPOS (it
)
4540 && start_pos
> BEGV
)
4541 move_it_by_lines (&it
, -1);
4545 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4546 MOVE_TO_POS
| MOVE_TO_Y
);
4547 /* Ensure we actually do move, e.g. in case we are currently
4548 looking at an image that is taller that the window height. */
4549 while (start_pos
== IT_CHARPOS (it
)
4551 move_it_by_lines (&it
, 1);
4555 move_it_by_lines (&it
, n
);
4557 /* We failed if we find ZV is already on the screen (scrolling up,
4558 means there's nothing past the end), or if we can't start any
4559 earlier (scrolling down, means there's nothing past the top). */
4560 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4561 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4563 if (IT_CHARPOS (it
) == ZV
)
4565 if (it
.current_y
< it
.last_visible_y
4566 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4567 > it
.last_visible_y
))
4569 /* The last line was only partially visible, make it fully
4571 w
->vscroll
= (it
.last_visible_y
4572 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4573 adjust_glyphs (it
.f
);
4577 bidi_unshelve_cache (itdata
, 0);
4580 else if (n
< 0) /* could happen with empty buffers */
4581 xsignal0 (Qbeginning_of_buffer
);
4583 xsignal0 (Qend_of_buffer
);
4588 if (w
->vscroll
!= 0)
4589 /* The first line was only partially visible, make it fully
4594 bidi_unshelve_cache (itdata
, 0);
4598 xsignal0 (Qbeginning_of_buffer
);
4602 /* If control gets here, then we vscrolled. */
4604 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
4606 /* Don't try to change the window start below. */
4612 ptrdiff_t pos
= IT_CHARPOS (it
);
4615 /* If in the middle of a multi-glyph character move forward to
4616 the next character. */
4617 if (in_display_vector_p (&it
))
4620 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
4623 /* Set the window start, and set up the window for redisplay. */
4624 set_marker_restricted (w
->start
, make_number (pos
),
4626 bytepos
= marker_byte_position (w
->start
);
4627 w
->start_at_line_beg
= (pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n');
4628 w
->update_mode_line
= 1;
4629 w
->last_modified
= 0;
4630 w
->last_overlay_modified
= 0;
4631 /* Set force_start so that redisplay_window will run the
4632 window-scroll-functions. */
4636 /* The rest of this function uses current_y in a nonstandard way,
4637 not including the height of the header line if any. */
4638 it
.current_y
= it
.vpos
= 0;
4640 /* Move PT out of scroll margins.
4641 This code wants current_y to be zero at the window start position
4642 even if there is a header line. */
4643 this_scroll_margin
= max (0, scroll_margin
);
4645 = min (this_scroll_margin
, XFASTINT (w
->total_lines
) / 4);
4646 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
4650 /* We moved the window start towards ZV, so PT may be now
4651 in the scroll margin at the top. */
4652 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4653 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
4654 && (NILP (Vscroll_preserve_screen_position
)
4655 || EQ (Vscroll_preserve_screen_position
, Qt
)))
4656 /* We found PT at a legitimate height. Leave it alone. */
4658 else if (window_scroll_pixel_based_preserve_y
>= 0)
4660 /* If we have a header line, take account of it.
4661 This is necessary because we set it.current_y to 0, above. */
4662 move_it_to (&it
, -1,
4663 window_scroll_pixel_based_preserve_x
,
4664 window_scroll_pixel_based_preserve_y
4665 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
4666 -1, MOVE_TO_Y
| MOVE_TO_X
);
4667 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4671 while (it
.current_y
< this_scroll_margin
)
4673 int prev
= it
.current_y
;
4674 move_it_by_lines (&it
, 1);
4675 if (prev
== it
.current_y
)
4678 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4683 ptrdiff_t charpos
, bytepos
;
4686 /* Save our position, for the
4687 window_scroll_pixel_based_preserve_y case. */
4688 charpos
= IT_CHARPOS (it
);
4689 bytepos
= IT_BYTEPOS (it
);
4691 /* We moved the window start towards BEGV, so PT may be now
4692 in the scroll margin at the bottom. */
4693 move_it_to (&it
, PT
, -1,
4694 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
4695 - this_scroll_margin
- 1),
4697 MOVE_TO_POS
| MOVE_TO_Y
);
4699 /* Save our position, in case it's correct. */
4700 charpos
= IT_CHARPOS (it
);
4701 bytepos
= IT_BYTEPOS (it
);
4703 /* See if point is on a partially visible line at the end. */
4704 if (it
.what
== IT_EOB
)
4705 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
4708 move_it_by_lines (&it
, 1);
4709 partial_p
= it
.current_y
> it
.last_visible_y
;
4712 if (charpos
== PT
&& !partial_p
4713 && (NILP (Vscroll_preserve_screen_position
)
4714 || EQ (Vscroll_preserve_screen_position
, Qt
)))
4715 /* We found PT before we found the display margin, so PT is ok. */
4717 else if (window_scroll_pixel_based_preserve_y
>= 0)
4719 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4720 start_display (&it
, w
, start
);
4721 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
4722 here because we called start_display again and did not
4723 alter it.current_y this time. */
4724 move_it_to (&it
, -1, window_scroll_pixel_based_preserve_x
,
4725 window_scroll_pixel_based_preserve_y
, -1,
4726 MOVE_TO_Y
| MOVE_TO_X
);
4727 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4732 /* The last line was only partially visible, so back up two
4733 lines to make sure we're on a fully visible line. */
4735 move_it_by_lines (&it
, -2);
4736 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4739 /* No, the position we saved is OK, so use it. */
4740 SET_PT_BOTH (charpos
, bytepos
);
4743 bidi_unshelve_cache (itdata
, 0);
4747 /* Implementation of window_scroll that works based on screen lines.
4748 See the comment of window_scroll for parameter descriptions. */
4751 window_scroll_line_based (Lisp_Object window
, int n
, int whole
, int noerror
)
4753 register struct window
*w
= XWINDOW (window
);
4754 /* Fvertical_motion enters redisplay, which can trigger
4755 fontification, which in turn can modify buffer text (e.g., if the
4756 fontification functions replace escape sequences with faces, as
4757 in `grep-mode-font-lock-keywords'). So we use a marker to record
4758 the old point position, to prevent crashes in SET_PT_BOTH. */
4759 Lisp_Object opoint_marker
= Fpoint_marker ();
4760 register ptrdiff_t pos
, pos_byte
;
4761 register int ht
= window_internal_height (w
);
4762 register Lisp_Object tem
;
4766 Lisp_Object original_pos
= Qnil
;
4768 /* If scrolling screen-fulls, compute the number of lines to
4769 scroll from the window's height. */
4771 n
*= max (1, ht
- next_screen_context_lines
);
4773 startpos
= marker_position (w
->start
);
4775 if (!NILP (Vscroll_preserve_screen_position
))
4777 if (window_scroll_preserve_vpos
<= 0
4778 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
4779 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
4781 struct position posit
4782 = *compute_motion (startpos
, 0, 0, 0,
4786 window_scroll_preserve_vpos
= posit
.vpos
;
4787 window_scroll_preserve_hpos
= posit
.hpos
+ w
->hscroll
;
4790 original_pos
= Fcons (make_number (window_scroll_preserve_hpos
),
4791 make_number (window_scroll_preserve_vpos
));
4794 XSETFASTINT (tem
, PT
);
4795 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
4799 Fvertical_motion (make_number (- (ht
/ 2)), window
);
4804 lose
= n
< 0 && PT
== BEGV
;
4805 Fvertical_motion (make_number (n
), window
);
4809 SET_PT_BOTH (marker_position (opoint_marker
),
4810 marker_byte_position (opoint_marker
));
4817 xsignal0 (Qbeginning_of_buffer
);
4822 /* Don't use a scroll margin that is negative or too large. */
4823 int this_scroll_margin
=
4824 max (0, min (scroll_margin
, XINT (w
->total_lines
) / 4));
4826 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
4827 w
->start_at_line_beg
= !NILP (bolp
);
4828 w
->update_mode_line
= 1;
4829 w
->last_modified
= 0;
4830 w
->last_overlay_modified
= 0;
4831 /* Set force_start so that redisplay_window will run
4832 the window-scroll-functions. */
4835 if (!NILP (Vscroll_preserve_screen_position
)
4836 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
4838 SET_PT_BOTH (pos
, pos_byte
);
4839 Fvertical_motion (original_pos
, window
);
4841 /* If we scrolled forward, put point enough lines down
4842 that it is outside the scroll margin. */
4847 if (this_scroll_margin
> 0)
4849 SET_PT_BOTH (pos
, pos_byte
);
4850 Fvertical_motion (make_number (this_scroll_margin
), window
);
4856 if (top_margin
<= marker_position (opoint_marker
))
4857 SET_PT_BOTH (marker_position (opoint_marker
),
4858 marker_byte_position (opoint_marker
));
4859 else if (!NILP (Vscroll_preserve_screen_position
))
4861 SET_PT_BOTH (pos
, pos_byte
);
4862 Fvertical_motion (original_pos
, window
);
4865 SET_PT (top_margin
);
4871 /* If we scrolled backward, put point near the end of the window
4872 but not within the scroll margin. */
4873 SET_PT_BOTH (pos
, pos_byte
);
4874 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
4875 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
4878 bottom_margin
= PT
+ 1;
4880 if (bottom_margin
> marker_position (opoint_marker
))
4881 SET_PT_BOTH (marker_position (opoint_marker
),
4882 marker_byte_position (opoint_marker
));
4885 if (!NILP (Vscroll_preserve_screen_position
))
4887 SET_PT_BOTH (pos
, pos_byte
);
4888 Fvertical_motion (original_pos
, window
);
4891 Fvertical_motion (make_number (-1), window
);
4900 xsignal0 (Qend_of_buffer
);
4905 /* Scroll selected_window up or down. If N is nil, scroll a
4906 screen-full which is defined as the height of the window minus
4907 next_screen_context_lines. If N is the symbol `-', scroll.
4908 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4909 up. This is the guts of Fscroll_up and Fscroll_down. */
4912 scroll_command (Lisp_Object n
, int direction
)
4914 ptrdiff_t count
= SPECPDL_INDEX ();
4916 eassert (eabs (direction
) == 1);
4918 /* If selected window's buffer isn't current, make it current for
4919 the moment. But don't screw up if window_scroll gets an error. */
4920 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
4922 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4923 Fset_buffer (XWINDOW (selected_window
)->buffer
);
4925 /* Make redisplay consider other windows than just selected_window. */
4926 ++windows_or_buffers_changed
;
4930 window_scroll (selected_window
, direction
, 1, 0);
4931 else if (EQ (n
, Qminus
))
4932 window_scroll (selected_window
, -direction
, 1, 0);
4935 n
= Fprefix_numeric_value (n
);
4936 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
4939 unbind_to (count
, Qnil
);
4942 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "^P",
4943 doc
: /* Scroll text of selected window upward ARG lines.
4944 If ARG is omitted or nil, scroll upward by a near full screen.
4945 A near full screen is `next-screen-context-lines' less than a full screen.
4946 Negative ARG means scroll downward.
4947 If ARG is the atom `-', scroll downward by nearly full screen.
4948 When calling from a program, supply as argument a number, nil, or `-'. */)
4951 scroll_command (arg
, 1);
4955 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "^P",
4956 doc
: /* Scroll text of selected window down ARG lines.
4957 If ARG is omitted or nil, scroll down by a near full screen.
4958 A near full screen is `next-screen-context-lines' less than a full screen.
4959 Negative ARG means scroll upward.
4960 If ARG is the atom `-', scroll upward by nearly full screen.
4961 When calling from a program, supply as argument a number, nil, or `-'. */)
4964 scroll_command (arg
, -1);
4968 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
4969 doc
: /* Return the other window for \"other window scroll\" commands.
4970 If `other-window-scroll-buffer' is non-nil, a window
4971 showing that buffer is used.
4972 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4973 specifies the window. This takes precedence over
4974 `other-window-scroll-buffer'. */)
4979 if (MINI_WINDOW_P (XWINDOW (selected_window
))
4980 && !NILP (Vminibuf_scroll_window
))
4981 window
= Vminibuf_scroll_window
;
4982 /* If buffer is specified, scroll that buffer. */
4983 else if (!NILP (Vother_window_scroll_buffer
))
4985 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
4987 window
= display_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
4991 /* Nothing specified; look for a neighboring window on the same
4993 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
4995 if (EQ (window
, selected_window
))
4996 /* That didn't get us anywhere; look for a window on another
4999 window
= Fnext_window (window
, Qnil
, Qt
);
5000 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
5001 && ! EQ (window
, selected_window
));
5004 CHECK_LIVE_WINDOW (window
);
5006 if (EQ (window
, selected_window
))
5007 error ("There is no other window");
5012 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
5013 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5014 A near full screen is `next-screen-context-lines' less than a full screen.
5015 The next window is the one below the current one; or the one at the top
5016 if the current one is at the bottom. Negative ARG means scroll downward.
5017 If ARG is the atom `-', scroll downward by nearly full screen.
5018 When calling from a program, supply as argument a number, nil, or `-'.
5020 If `other-window-scroll-buffer' is non-nil, scroll the window
5021 showing that buffer, popping the buffer up if necessary.
5022 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5023 specifies the window to scroll. This takes precedence over
5024 `other-window-scroll-buffer'. */)
5029 ptrdiff_t count
= SPECPDL_INDEX ();
5031 window
= Fother_window_for_scrolling ();
5032 w
= XWINDOW (window
);
5034 /* Don't screw up if window_scroll gets an error. */
5035 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5036 ++windows_or_buffers_changed
;
5038 Fset_buffer (w
->buffer
);
5039 SET_PT (marker_position (w
->pointm
));
5042 window_scroll (window
, 1, 1, 1);
5043 else if (EQ (arg
, Qminus
))
5044 window_scroll (window
, -1, 1, 1);
5050 window_scroll (window
, XINT (arg
), 0, 1);
5053 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5054 unbind_to (count
, Qnil
);
5059 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "^P\np",
5060 doc
: /* Scroll selected window display ARG columns left.
5061 Default for ARG is window width minus 2.
5062 Value is the total amount of leftward horizontal scrolling in
5063 effect after the change.
5064 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5065 lower bound for automatic scrolling, i.e. automatic scrolling
5066 will not scroll a window to a column less than the value returned
5067 by this function. This happens in an interactive call. */)
5068 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5070 struct window
*w
= XWINDOW (selected_window
);
5071 EMACS_INT requested_arg
= (NILP (arg
)
5072 ? window_body_cols (w
) - 2
5073 : XINT (Fprefix_numeric_value (arg
)));
5074 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
+ requested_arg
);
5076 if (!NILP (set_minimum
))
5077 w
->min_hscroll
= w
->hscroll
;
5082 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "^P\np",
5083 doc
: /* Scroll selected window display ARG columns right.
5084 Default for ARG is window width minus 2.
5085 Value is the total amount of leftward horizontal scrolling in
5086 effect after the change.
5087 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5088 lower bound for automatic scrolling, i.e. automatic scrolling
5089 will not scroll a window to a column less than the value returned
5090 by this function. This happens in an interactive call. */)
5091 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5093 struct window
*w
= XWINDOW (selected_window
);
5094 EMACS_INT requested_arg
= (NILP (arg
)
5095 ? window_body_cols (w
) - 2
5096 : XINT (Fprefix_numeric_value (arg
)));
5097 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
- requested_arg
);
5099 if (!NILP (set_minimum
))
5100 w
->min_hscroll
= w
->hscroll
;
5105 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5106 doc
: /* Return the window which was selected when entering the minibuffer.
5107 Returns nil, if selected window is not a minibuffer window. */)
5110 if (minibuf_level
> 0
5111 && MINI_WINDOW_P (XWINDOW (selected_window
))
5112 && WINDOW_LIVE_P (minibuf_selected_window
))
5113 return minibuf_selected_window
;
5118 /* Value is the number of lines actually displayed in window W,
5119 as opposed to its height. */
5122 displayed_window_lines (struct window
*w
)
5125 struct text_pos start
;
5126 ptrdiff_t charpos
= marker_position (w
->start
);
5127 int height
= window_box_height (w
);
5128 struct buffer
*old_buffer
;
5130 void *itdata
= NULL
;
5132 if (XBUFFER (w
->buffer
) != current_buffer
)
5134 old_buffer
= current_buffer
;
5135 set_buffer_internal (XBUFFER (w
->buffer
));
5140 /* In case W->start is out of the accessible range, do something
5141 reasonable. This happens in Info mode when Info-scroll-down
5142 calls (recenter -1) while W->start is 1. */
5144 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5145 else if (charpos
> ZV
)
5146 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
5148 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5150 itdata
= bidi_shelve_cache ();
5151 start_display (&it
, w
, start
);
5152 move_it_vertically (&it
, height
);
5153 bottom_y
= line_bottom_y (&it
);
5154 bidi_unshelve_cache (itdata
, 0);
5156 /* rms: On a non-window display,
5157 the value of it.vpos at the bottom of the screen
5158 seems to be 1 larger than window_box_height (w).
5159 This kludge fixes a bug whereby (move-to-window-line -1)
5160 when ZV is on the last screen line
5161 moves to the previous screen line instead of the last one. */
5162 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5165 /* Add in empty lines at the bottom of the window. */
5166 if (bottom_y
< height
)
5168 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5169 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5173 set_buffer_internal (old_buffer
);
5179 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5180 doc
: /* Center point in selected window and maybe redisplay frame.
5181 With prefix argument ARG, recenter putting point on screen line ARG
5182 relative to the selected window. If ARG is negative, it counts up from the
5183 bottom of the window. (ARG should be less than the height of the window.)
5185 If ARG is omitted or nil, then recenter with point on the middle line of
5186 the selected window; if the variable `recenter-redisplay' is non-nil,
5187 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5188 is set to `grow-only', this resets the tool-bar's height to the minimum
5189 height needed); if `recenter-redisplay' has the special value `tty',
5190 then only tty frames are redrawn.
5192 Just C-u as prefix means put point in the center of the window
5193 and redisplay normally--don't erase and redraw the frame. */)
5194 (register Lisp_Object arg
)
5196 struct window
*w
= XWINDOW (selected_window
);
5197 struct buffer
*buf
= XBUFFER (w
->buffer
);
5198 struct buffer
*obuf
= current_buffer
;
5200 ptrdiff_t charpos
, bytepos
;
5201 EMACS_INT iarg
IF_LINT (= 0);
5202 int this_scroll_margin
;
5204 /* If redisplay is suppressed due to an error, try again. */
5205 obuf
->display_error_modiff
= 0;
5209 if (!NILP (Vrecenter_redisplay
)
5210 && (!EQ (Vrecenter_redisplay
, Qtty
)
5211 || !NILP (Ftty_type (selected_frame
))))
5215 /* Invalidate pixel data calculated for all compositions. */
5216 for (i
= 0; i
< n_compositions
; i
++)
5217 composition_table
[i
]->font
= NULL
;
5219 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5221 Fredraw_frame (WINDOW_FRAME (w
));
5222 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5227 else if (CONSP (arg
)) /* Just C-u. */
5231 arg
= Fprefix_numeric_value (arg
);
5236 set_buffer_internal (buf
);
5238 /* Do this after making BUF current
5239 in case scroll_margin is buffer-local. */
5240 this_scroll_margin
=
5241 max (0, min (scroll_margin
, XFASTINT (w
->total_lines
) / 4));
5243 /* Handle centering on a graphical frame specially. Such frames can
5244 have variable-height lines and centering point on the basis of
5245 line counts would lead to strange effects. */
5246 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5252 void *itdata
= bidi_shelve_cache ();
5254 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5255 start_display (&it
, w
, pt
);
5256 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5257 charpos
= IT_CHARPOS (it
);
5258 bytepos
= IT_BYTEPOS (it
);
5259 bidi_unshelve_cache (itdata
, 0);
5265 ptrdiff_t nlines
= min (PTRDIFF_MAX
, -iarg
);
5266 int extra_line_spacing
;
5267 int h
= window_box_height (w
);
5268 void *itdata
= bidi_shelve_cache ();
5270 iarg
= - max (-iarg
, this_scroll_margin
);
5272 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5273 start_display (&it
, w
, pt
);
5275 /* Be sure we have the exact height of the full line containing PT. */
5276 move_it_by_lines (&it
, 0);
5278 /* The amount of pixels we have to move back is the window
5279 height minus what's displayed in the line containing PT,
5280 and the lines below. */
5283 move_it_by_lines (&it
, nlines
);
5285 if (it
.vpos
== nlines
)
5289 /* Last line has no newline */
5290 h
-= line_bottom_y (&it
);
5294 /* Don't reserve space for extra line spacing of last line. */
5295 extra_line_spacing
= it
.max_extra_line_spacing
;
5297 /* If we can't move down NLINES lines because we hit
5298 the end of the buffer, count in some empty lines. */
5299 if (it
.vpos
< nlines
)
5302 extra_line_spacing
= it
.extra_line_spacing
;
5303 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5307 bidi_unshelve_cache (itdata
, 0);
5311 /* Now find the new top line (starting position) of the window. */
5312 start_display (&it
, w
, pt
);
5314 move_it_vertically_backward (&it
, h
);
5316 /* If extra line spacing is present, we may move too far
5317 back. This causes the last line to be only partially
5318 visible (which triggers redisplay to recenter that line
5319 in the middle), so move forward.
5320 But ignore extra line spacing on last line, as it is not
5321 considered to be part of the visible height of the line.
5323 h
+= extra_line_spacing
;
5324 while (-it
.current_y
> h
)
5325 move_it_by_lines (&it
, 1);
5327 charpos
= IT_CHARPOS (it
);
5328 bytepos
= IT_BYTEPOS (it
);
5330 bidi_unshelve_cache (itdata
, 0);
5334 struct position pos
;
5336 iarg
= max (iarg
, this_scroll_margin
);
5338 pos
= *vmotion (PT
, -iarg
, w
);
5339 charpos
= pos
.bufpos
;
5340 bytepos
= pos
.bytepos
;
5345 struct position pos
;
5346 int ht
= window_internal_height (w
);
5353 /* Don't let it get into the margin at either top or bottom. */
5354 iarg
= clip_to_bounds (this_scroll_margin
, iarg
,
5355 ht
- this_scroll_margin
- 1);
5357 pos
= *vmotion (PT
, - iarg
, w
);
5358 charpos
= pos
.bufpos
;
5359 bytepos
= pos
.bytepos
;
5362 /* Set the new window start. */
5363 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
5364 w
->window_end_valid
= 0;
5366 w
->optional_new_start
= 1;
5368 w
->start_at_line_beg
= (bytepos
== BEGV_BYTE
||
5369 FETCH_BYTE (bytepos
- 1) == '\n');
5371 set_buffer_internal (obuf
);
5375 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5377 doc
: /* Return the height in lines of the text display area of WINDOW.
5378 WINDOW must be a live window and defaults to the selected one.
5380 The returned height does not include the mode line, any header line,
5381 nor any partial-height lines at the bottom of the text area. */)
5382 (Lisp_Object window
)
5384 struct window
*w
= decode_live_window (window
);
5385 int pixel_height
= window_box_height (w
);
5386 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5387 return make_number (line_height
);
5392 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5394 doc
: /* Position point relative to window.
5395 ARG nil means position point at center of window.
5396 Else, ARG specifies vertical position within the window;
5397 zero means top of window, negative means relative to bottom of window. */)
5400 struct window
*w
= XWINDOW (selected_window
);
5404 int this_scroll_margin
;
5407 if (!(BUFFERP (w
->buffer
)
5408 && XBUFFER (w
->buffer
) == current_buffer
))
5409 /* This test is needed to make sure PT/PT_BYTE make sense in w->buffer
5410 when passed below to set_marker_both. */
5411 error ("move-to-window-line called from unrelated buffer");
5413 window
= selected_window
;
5414 start
= marker_position (w
->start
);
5415 if (start
< BEGV
|| start
> ZV
)
5417 int height
= window_internal_height (w
);
5418 Fvertical_motion (make_number (- (height
/ 2)), window
);
5419 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
5420 w
->start_at_line_beg
= !NILP (Fbolp ());
5424 Fgoto_char (w
->start
);
5426 lines
= displayed_window_lines (w
);
5429 this_scroll_margin
= max (0, min (scroll_margin
, lines
/ 4));
5433 XSETFASTINT (arg
, lines
/ 2);
5436 EMACS_INT iarg
= XINT (Fprefix_numeric_value (arg
));
5439 iarg
= iarg
+ lines
;
5441 #if 0 /* This code would prevent move-to-window-line from moving point
5442 to a place inside the scroll margins (which would cause the
5443 next redisplay to scroll). I wrote this code, but then concluded
5444 it is probably better not to install it. However, it is here
5445 inside #if 0 so as not to lose it. -- rms. */
5447 /* Don't let it get into the margin at either top or bottom. */
5448 iarg
= max (iarg
, this_scroll_margin
);
5449 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
5452 arg
= make_number (iarg
);
5455 /* Skip past a partially visible first line. */
5457 XSETINT (arg
, XINT (arg
) + 1);
5459 return Fvertical_motion (arg
, window
);
5464 /***********************************************************************
5465 Window Configuration
5466 ***********************************************************************/
5468 struct save_window_data
5470 struct vectorlike_header header
;
5471 Lisp_Object selected_frame
;
5472 Lisp_Object current_window
;
5473 Lisp_Object current_buffer
;
5474 Lisp_Object minibuf_scroll_window
;
5475 Lisp_Object minibuf_selected_window
;
5476 Lisp_Object root_window
;
5477 Lisp_Object focus_frame
;
5478 /* A vector, each of whose elements is a struct saved_window
5480 Lisp_Object saved_windows
;
5482 /* All fields above are traced by the GC.
5483 From `fame-cols' down, the fields are ignored by the GC. */
5485 int frame_cols
, frame_lines
, frame_menu_bar_lines
;
5486 int frame_tool_bar_lines
;
5489 /* This is saved as a Lisp_Vector */
5492 struct vectorlike_header header
;
5494 Lisp_Object window
, buffer
, start
, pointm
, mark
;
5495 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5496 Lisp_Object normal_cols
, normal_lines
;
5497 Lisp_Object hscroll
, min_hscroll
;
5498 Lisp_Object parent
, prev
;
5499 Lisp_Object start_at_line_beg
;
5500 Lisp_Object display_table
;
5501 Lisp_Object left_margin_cols
, right_margin_cols
;
5502 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
5503 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
, dedicated
;
5504 Lisp_Object combination_limit
, window_parameters
;
5507 #define SAVED_WINDOW_N(swv,n) \
5508 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5510 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
5511 doc
: /* Return t if OBJECT is a window-configuration object. */)
5512 (Lisp_Object object
)
5514 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
5517 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
5518 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5519 (Lisp_Object config
)
5521 register struct save_window_data
*data
;
5522 struct Lisp_Vector
*saved_windows
;
5524 CHECK_WINDOW_CONFIGURATION (config
);
5526 data
= (struct save_window_data
*) XVECTOR (config
);
5527 saved_windows
= XVECTOR (data
->saved_windows
);
5528 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5531 DEFUN ("set-window-configuration", Fset_window_configuration
,
5532 Sset_window_configuration
, 1, 1, 0,
5533 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5534 CONFIGURATION must be a value previously returned
5535 by `current-window-configuration' (which see).
5536 If CONFIGURATION was made from a frame that is now deleted,
5537 only frame-independent values can be restored. In this case,
5538 the return value is nil. Otherwise the value is t. */)
5539 (Lisp_Object configuration
)
5541 register struct save_window_data
*data
;
5542 struct Lisp_Vector
*saved_windows
;
5543 Lisp_Object new_current_buffer
;
5546 ptrdiff_t old_point
= -1;
5548 CHECK_WINDOW_CONFIGURATION (configuration
);
5550 data
= (struct save_window_data
*) XVECTOR (configuration
);
5551 saved_windows
= XVECTOR (data
->saved_windows
);
5553 new_current_buffer
= data
->current_buffer
;
5554 if (!BUFFER_LIVE_P (XBUFFER (new_current_buffer
)))
5555 new_current_buffer
= Qnil
;
5558 if (XBUFFER (new_current_buffer
) == current_buffer
)
5559 /* The code further down "preserves point" by saving here PT in
5560 old_point and then setting it later back into PT. When the
5561 current-selected-window and the final-selected-window both show
5562 the current buffer, this suffers from the problem that the
5563 current PT is the window-point of the current-selected-window,
5564 while the final PT is the point of the final-selected-window, so
5565 this copy from one PT to the other would end up moving the
5566 window-point of the final-selected-window to the window-point of
5567 the current-selected-window. So we have to be careful which
5568 point of the current-buffer we copy into old_point. */
5569 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
5570 && WINDOWP (selected_window
)
5571 && EQ (XWINDOW (selected_window
)->buffer
, new_current_buffer
)
5572 && !EQ (selected_window
, data
->current_window
))
5573 old_point
= marker_position (XWINDOW (data
->current_window
)->pointm
);
5577 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
5578 point in new_current_buffer as of the last time this buffer was
5579 used. This can be non-deterministic since it can be changed by
5580 things like jit-lock by mere temporary selection of some random
5581 window that happens to show this buffer.
5582 So if possible we want this arbitrary choice of "which point" to
5583 be the one from the to-be-selected-window so as to prevent this
5584 window's cursor from being copied from another window. */
5585 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
5586 /* If current_window = selected_window, its point is in BUF_PT. */
5587 && !EQ (selected_window
, data
->current_window
))
5588 old_point
= marker_position (XWINDOW (data
->current_window
)->pointm
);
5590 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
5593 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5596 /* If f is a dead frame, don't bother rebuilding its window tree.
5597 However, there is other stuff we should still try to do below. */
5598 if (FRAME_LIVE_P (f
))
5601 Lisp_Object dead_windows
= Qnil
;
5602 register Lisp_Object tem
, par
, pers
;
5603 register struct window
*w
;
5604 register struct saved_window
*p
;
5605 struct window
*root_window
;
5606 struct window
**leaf_windows
;
5611 /* If the frame has been resized since this window configuration was
5612 made, we change the frame to the size specified in the
5613 configuration, restore the configuration, and then resize it
5614 back. We keep track of the prevailing height in these variables. */
5615 int previous_frame_lines
= FRAME_LINES (f
);
5616 int previous_frame_cols
= FRAME_COLS (f
);
5617 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
5618 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
5620 /* Don't do this within the main loop below: This may call Lisp
5621 code and is thus potentially unsafe while input is blocked. */
5622 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
5624 p
= SAVED_WINDOW_N (saved_windows
, k
);
5626 w
= XWINDOW (window
);
5627 if (!NILP (w
->buffer
)
5628 && !EQ (w
->buffer
, p
->buffer
)
5629 && BUFFER_LIVE_P (XBUFFER (p
->buffer
)))
5630 /* If a window we restore gets another buffer, record the
5631 window's old buffer. */
5632 call1 (Qrecord_window_buffer
, window
);
5635 /* The mouse highlighting code could get screwed up
5636 if it runs during this. */
5639 if (data
->frame_lines
!= previous_frame_lines
5640 || data
->frame_cols
!= previous_frame_cols
)
5641 change_frame_size (f
, data
->frame_lines
,
5642 data
->frame_cols
, 0, 0, 0);
5643 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5644 if (data
->frame_menu_bar_lines
5645 != previous_frame_menu_bar_lines
)
5646 x_set_menu_bar_lines (f
, make_number (data
->frame_menu_bar_lines
),
5648 #ifdef HAVE_WINDOW_SYSTEM
5649 if (data
->frame_tool_bar_lines
5650 != previous_frame_tool_bar_lines
)
5651 x_set_tool_bar_lines (f
, make_number (data
->frame_tool_bar_lines
),
5656 /* "Swap out" point from the selected window's buffer
5657 into the window itself. (Normally the pointm of the selected
5658 window holds garbage.) We do this now, before
5659 restoring the window contents, and prevent it from
5660 being done later on when we select a new window. */
5661 if (! NILP (XWINDOW (selected_window
)->buffer
))
5663 w
= XWINDOW (selected_window
);
5664 set_marker_both (w
->pointm
,
5666 BUF_PT (XBUFFER (w
->buffer
)),
5667 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5670 windows_or_buffers_changed
++;
5671 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
5673 /* Problem: Freeing all matrices and later allocating them again
5674 is a serious redisplay flickering problem. What we would
5675 really like to do is to free only those matrices not reused
5677 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5678 leaf_windows
= alloca (count_windows (root_window
)
5679 * sizeof *leaf_windows
);
5680 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
5683 Mark all windows now on frame as "deleted".
5684 Restoring the new configuration "undeletes" any that are in it.
5686 Save their current buffers in their height fields, since we may
5687 need it later, if a buffer saved in the configuration is now
5689 delete_all_child_windows (FRAME_ROOT_WINDOW (f
));
5691 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
5693 p
= SAVED_WINDOW_N (saved_windows
, k
);
5695 w
= XWINDOW (window
);
5696 wset_next (w
, Qnil
);
5698 if (!NILP (p
->parent
))
5700 (w
, SAVED_WINDOW_N (saved_windows
, XFASTINT (p
->parent
))->window
);
5702 wset_parent (w
, Qnil
);
5704 if (!NILP (p
->prev
))
5707 (w
, SAVED_WINDOW_N (saved_windows
, XFASTINT (p
->prev
))->window
);
5708 wset_next (XWINDOW (w
->prev
), p
->window
);
5712 wset_prev (w
, Qnil
);
5713 if (!NILP (w
->parent
))
5715 if (EQ (p
->total_cols
, XWINDOW (w
->parent
)->total_cols
))
5717 wset_vchild (XWINDOW (w
->parent
), p
->window
);
5718 wset_hchild (XWINDOW (w
->parent
), Qnil
);
5722 wset_hchild (XWINDOW (w
->parent
), p
->window
);
5723 wset_vchild (XWINDOW (w
->parent
), Qnil
);
5728 /* If we squirreled away the buffer in the window's height,
5730 if (BUFFERP (w
->total_lines
))
5731 wset_buffer (w
, w
->total_lines
);
5732 wset_left_col (w
, p
->left_col
);
5733 wset_top_line (w
, p
->top_line
);
5734 wset_total_cols (w
, p
->total_cols
);
5735 wset_total_lines (w
, p
->total_lines
);
5736 wset_normal_cols (w
, p
->normal_cols
);
5737 wset_normal_lines (w
, p
->normal_lines
);
5738 w
->hscroll
= XFASTINT (p
->hscroll
);
5739 w
->min_hscroll
= XFASTINT (p
->min_hscroll
);
5740 wset_display_table (w
, p
->display_table
);
5741 wset_left_margin_cols (w
, p
->left_margin_cols
);
5742 wset_right_margin_cols (w
, p
->right_margin_cols
);
5743 wset_left_fringe_width (w
, p
->left_fringe_width
);
5744 wset_right_fringe_width (w
, p
->right_fringe_width
);
5745 w
->fringes_outside_margins
= !NILP (p
->fringes_outside_margins
);
5746 wset_scroll_bar_width (w
, p
->scroll_bar_width
);
5747 wset_vertical_scroll_bar_type (w
, p
->vertical_scroll_bar_type
);
5748 wset_dedicated (w
, p
->dedicated
);
5749 wset_combination_limit (w
, p
->combination_limit
);
5750 /* Restore any window parameters that have been saved.
5751 Parameters that have not been saved are left alone. */
5752 for (tem
= p
->window_parameters
; CONSP (tem
); tem
= XCDR (tem
))
5757 if (NILP (XCDR (pers
)))
5759 par
= Fassq (XCAR (pers
), w
->window_parameters
);
5760 if (CONSP (par
) && !NILP (XCDR (par
)))
5761 /* Reset a parameter to nil if and only if it
5762 has a non-nil association. Don't make new
5764 Fsetcdr (par
, Qnil
);
5767 /* Always restore a non-nil value. */
5768 Fset_window_parameter (window
, XCAR (pers
), XCDR (pers
));
5772 w
->last_modified
= 0;
5773 w
->last_overlay_modified
= 0;
5775 /* Reinstall the saved buffer and pointers into it. */
5776 if (NILP (p
->buffer
))
5777 /* An internal window. */
5778 wset_buffer (w
, p
->buffer
);
5779 else if (BUFFER_LIVE_P (XBUFFER (p
->buffer
)))
5780 /* If saved buffer is alive, install it. */
5782 wset_buffer (w
, p
->buffer
);
5783 w
->start_at_line_beg
= !NILP (p
->start_at_line_beg
);
5784 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
5785 set_marker_restricted (w
->pointm
, p
->pointm
,
5787 Fset_marker (BVAR (XBUFFER (w
->buffer
), mark
),
5788 p
->mark
, w
->buffer
);
5790 /* As documented in Fcurrent_window_configuration, don't
5791 restore the location of point in the buffer which was
5792 current when the window configuration was recorded. */
5793 if (!EQ (p
->buffer
, new_current_buffer
)
5794 && XBUFFER (p
->buffer
) == current_buffer
)
5795 Fgoto_char (w
->pointm
);
5797 else if (!NILP (w
->buffer
)
5798 && BUFFER_LIVE_P (XBUFFER (w
->buffer
)))
5799 /* Keep window's old buffer; make sure the markers are
5802 /* Set window markers at start of visible range. */
5803 if (XMARKER (w
->start
)->buffer
== 0)
5804 set_marker_restricted (w
->start
, make_number (0),
5806 if (XMARKER (w
->pointm
)->buffer
== 0)
5807 set_marker_restricted_both
5808 (w
->pointm
, w
->buffer
,
5809 BUF_PT (XBUFFER (w
->buffer
)),
5810 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5811 w
->start_at_line_beg
= 1;
5814 /* Window has no live buffer, get one. */
5816 /* Get the buffer via other_buffer_safely in order to
5817 avoid showing an unimportant buffer and, if necessary, to
5818 recreate *scratch* in the course (part of Juanma's bs-show
5819 scenario from March 2011). */
5820 wset_buffer (w
, other_buffer_safely (Fcurrent_buffer ()));
5821 /* This will set the markers to beginning of visible
5823 set_marker_restricted (w
->start
,
5824 make_number (0), w
->buffer
);
5825 set_marker_restricted (w
->pointm
,
5826 make_number (0), w
->buffer
);
5827 w
->start_at_line_beg
= 1;
5828 if (!NILP (w
->dedicated
))
5829 /* Record this window as dead. */
5830 dead_windows
= Fcons (window
, dead_windows
);
5831 /* Make sure window is no more dedicated. */
5832 wset_dedicated (w
, Qnil
);
5836 fset_root_window (f
, data
->root_window
);
5837 /* Arrange *not* to restore point in the buffer that was
5838 current when the window configuration was saved. */
5839 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
5840 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
5841 make_number (old_point
),
5842 XWINDOW (data
->current_window
)->buffer
);
5844 /* In the following call to `select-window', prevent "swapping out
5845 point" in the old selected window using the buffer that has
5846 been restored into it. We already swapped out that point from
5847 that window's old buffer. */
5848 select_window (data
->current_window
, Qnil
, 1);
5849 BVAR (XBUFFER (XWINDOW (selected_window
)->buffer
), last_selected_window
)
5852 if (NILP (data
->focus_frame
)
5853 || (FRAMEP (data
->focus_frame
)
5854 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
5855 Fredirect_frame_focus (frame
, data
->focus_frame
);
5857 /* Set the screen height to the value it had before this function. */
5858 if (previous_frame_lines
!= FRAME_LINES (f
)
5859 || previous_frame_cols
!= FRAME_COLS (f
))
5860 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
5862 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5863 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
5864 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
5866 #ifdef HAVE_WINDOW_SYSTEM
5867 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
5868 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
5873 /* Now, free glyph matrices in windows that were not reused. */
5874 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
5876 if (NILP (leaf_windows
[i
]->buffer
))
5878 /* Assert it's not reused as a combination. */
5879 eassert (NILP (leaf_windows
[i
]->hchild
)
5880 && NILP (leaf_windows
[i
]->vchild
));
5881 free_window_matrices (leaf_windows
[i
]);
5883 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
5890 /* Scan dead buffer windows. */
5891 for (; CONSP (dead_windows
); dead_windows
= XCDR (dead_windows
))
5893 window
= XCAR (dead_windows
);
5894 if (WINDOW_LIVE_P (window
) && !EQ (window
, FRAME_ROOT_WINDOW (f
)))
5895 delete_deletable_window (window
);
5898 /* Fselect_window will have made f the selected frame, so we
5899 reselect the proper frame here. Fhandle_switch_frame will change the
5900 selected window too, but that doesn't make the call to
5901 Fselect_window above totally superfluous; it still sets f's
5903 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
5904 do_switch_frame (data
->selected_frame
, 0, 0, Qnil
);
5906 run_window_configuration_change_hook (f
);
5909 if (!NILP (new_current_buffer
))
5911 Fset_buffer (new_current_buffer
);
5912 /* If the new current buffer doesn't appear in the selected
5913 window, go to its old point (see bug#12208). */
5914 if (!EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
5915 Fgoto_char (make_number (old_point
));
5918 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
5919 minibuf_selected_window
= data
->minibuf_selected_window
;
5921 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
5925 /* Recursively delete all child windows reachable via the next, vchild,
5926 and hchild slots of WINDOW. */
5928 delete_all_child_windows (Lisp_Object window
)
5930 register struct window
*w
;
5932 w
= XWINDOW (window
);
5934 if (!NILP (w
->next
))
5935 /* Delete WINDOW's siblings (we traverse postorderly). */
5936 delete_all_child_windows (w
->next
);
5938 /* See Fset_window_configuration for excuse. */
5939 wset_total_lines (w
, w
->buffer
);
5941 if (!NILP (w
->vchild
))
5943 delete_all_child_windows (w
->vchild
);
5944 wset_vchild (w
, Qnil
);
5946 else if (!NILP (w
->hchild
))
5948 delete_all_child_windows (w
->hchild
);
5949 wset_hchild (w
, Qnil
);
5951 else if (!NILP (w
->buffer
))
5954 unchain_marker (XMARKER (w
->pointm
));
5955 unchain_marker (XMARKER (w
->start
));
5956 wset_buffer (w
, Qnil
);
5959 Vwindow_list
= Qnil
;
5963 count_windows (register struct window
*window
)
5965 register int count
= 1;
5966 if (!NILP (window
->next
))
5967 count
+= count_windows (XWINDOW (window
->next
));
5968 if (!NILP (window
->vchild
))
5969 count
+= count_windows (XWINDOW (window
->vchild
));
5970 if (!NILP (window
->hchild
))
5971 count
+= count_windows (XWINDOW (window
->hchild
));
5976 /* Fill vector FLAT with leaf windows under W, starting at index I.
5977 Value is last index + 1. */
5979 get_leaf_windows (struct window
*w
, struct window
**flat
, int i
)
5983 if (!NILP (w
->hchild
))
5984 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
5985 else if (!NILP (w
->vchild
))
5986 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
5990 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5997 /* Return a pointer to the glyph W's physical cursor is on. Value is
5998 null if W's current matrix is invalid, so that no meaningful glyph
6001 get_phys_cursor_glyph (struct window
*w
)
6003 struct glyph_row
*row
;
6004 struct glyph
*glyph
;
6005 int hpos
= w
->phys_cursor
.hpos
;
6007 if (!(w
->phys_cursor
.vpos
>= 0
6008 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
))
6011 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
6012 if (!row
->enabled_p
)
6017 /* When the window is hscrolled, cursor hpos can legitimately be
6018 out of bounds, but we draw the cursor at the corresponding
6019 window margin in that case. */
6020 if (!row
->reversed_p
&& hpos
< 0)
6022 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
6023 hpos
= row
->used
[TEXT_AREA
] - 1;
6026 if (row
->used
[TEXT_AREA
] > hpos
6028 glyph
= row
->glyphs
[TEXT_AREA
] + hpos
;
6037 save_window_save (Lisp_Object window
, struct Lisp_Vector
*vector
, int i
)
6039 register struct saved_window
*p
;
6040 register struct window
*w
;
6041 register Lisp_Object tem
, pers
, par
;
6043 for (;!NILP (window
); window
= w
->next
)
6045 p
= SAVED_WINDOW_N (vector
, i
);
6046 w
= XWINDOW (window
);
6048 wset_temslot (w
, make_number (i
)); i
++;
6050 p
->buffer
= w
->buffer
;
6051 p
->left_col
= w
->left_col
;
6052 p
->top_line
= w
->top_line
;
6053 p
->total_cols
= w
->total_cols
;
6054 p
->total_lines
= w
->total_lines
;
6055 p
->normal_cols
= w
->normal_cols
;
6056 p
->normal_lines
= w
->normal_lines
;
6057 XSETFASTINT (p
->hscroll
, w
->hscroll
);
6058 XSETFASTINT (p
->min_hscroll
, w
->min_hscroll
);
6059 p
->display_table
= w
->display_table
;
6060 p
->left_margin_cols
= w
->left_margin_cols
;
6061 p
->right_margin_cols
= w
->right_margin_cols
;
6062 p
->left_fringe_width
= w
->left_fringe_width
;
6063 p
->right_fringe_width
= w
->right_fringe_width
;
6064 p
->fringes_outside_margins
= w
->fringes_outside_margins
? Qt
: Qnil
;
6065 p
->scroll_bar_width
= w
->scroll_bar_width
;
6066 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
6067 p
->dedicated
= w
->dedicated
;
6068 p
->combination_limit
= w
->combination_limit
;
6069 p
->window_parameters
= Qnil
;
6071 if (!NILP (Vwindow_persistent_parameters
))
6073 /* Run cycle detection on Vwindow_persistent_parameters. */
6074 Lisp_Object tortoise
, hare
;
6076 hare
= tortoise
= Vwindow_persistent_parameters
;
6077 while (CONSP (hare
))
6084 tortoise
= XCDR (tortoise
);
6086 if (EQ (hare
, tortoise
))
6087 /* Reset Vwindow_persistent_parameters to Qnil. */
6089 Vwindow_persistent_parameters
= Qnil
;
6094 for (tem
= Vwindow_persistent_parameters
; CONSP (tem
);
6098 /* Save values for persistent window parameters. */
6099 if (CONSP (pers
) && !NILP (XCDR (pers
)))
6101 par
= Fassq (XCAR (pers
), w
->window_parameters
);
6103 /* If the window has no value for the parameter,
6105 p
->window_parameters
= Fcons (Fcons (XCAR (pers
), Qnil
),
6106 p
->window_parameters
);
6108 /* If the window has a value for the parameter,
6110 p
->window_parameters
= Fcons (Fcons (XCAR (par
),
6112 p
->window_parameters
);
6117 if (!NILP (w
->buffer
))
6119 /* Save w's value of point in the window configuration. If w
6120 is the selected window, then get the value of point from
6121 the buffer; pointm is garbage in the selected window. */
6122 if (EQ (window
, selected_window
))
6123 p
->pointm
= build_marker (XBUFFER (w
->buffer
),
6124 BUF_PT (XBUFFER (w
->buffer
)),
6125 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6127 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
6128 XMARKER (p
->pointm
)->insertion_type
6129 = !NILP (Vwindow_point_insertion_type
);
6131 p
->start
= Fcopy_marker (w
->start
, Qnil
);
6132 p
->start_at_line_beg
= w
->start_at_line_beg
? Qt
: Qnil
;
6134 tem
= BVAR (XBUFFER (w
->buffer
), mark
);
6135 p
->mark
= Fcopy_marker (tem
, Qnil
);
6142 p
->start_at_line_beg
= Qnil
;
6145 if (NILP (w
->parent
))
6148 p
->parent
= XWINDOW (w
->parent
)->temslot
;
6153 p
->prev
= XWINDOW (w
->prev
)->temslot
;
6155 if (!NILP (w
->vchild
))
6156 i
= save_window_save (w
->vchild
, vector
, i
);
6157 if (!NILP (w
->hchild
))
6158 i
= save_window_save (w
->hchild
, vector
, i
);
6164 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
6165 Scurrent_window_configuration
, 0, 1, 0,
6166 doc
: /* Return an object representing the current window configuration of FRAME.
6167 If FRAME is nil or omitted, use the selected frame.
6168 This describes the number of windows, their sizes and current buffers,
6169 and for each displayed buffer, where display starts, and the positions of
6170 point and mark. An exception is made for point in the current buffer:
6171 its value is -not- saved.
6172 This also records the currently selected frame, and FRAME's focus
6173 redirection (see `redirect-frame-focus'). The variable
6174 `window-persistent-parameters' specifies which window parameters are
6175 saved by this function. */)
6178 register Lisp_Object tem
;
6179 register int n_windows
;
6180 register struct save_window_data
*data
;
6182 struct frame
*f
= decode_live_frame (frame
);
6184 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6185 data
= ALLOCATE_PSEUDOVECTOR (struct save_window_data
, frame_cols
,
6186 PVEC_WINDOW_CONFIGURATION
);
6188 data
->frame_cols
= FRAME_COLS (f
);
6189 data
->frame_lines
= FRAME_LINES (f
);
6190 data
->frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6191 data
->frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6192 data
->selected_frame
= selected_frame
;
6193 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6194 XSETBUFFER (data
->current_buffer
, current_buffer
);
6195 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6196 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6197 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6198 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6199 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
6200 data
->saved_windows
= tem
;
6201 for (i
= 0; i
< n_windows
; i
++)
6203 Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
));
6204 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6205 XSETWINDOW_CONFIGURATION (tem
, data
);
6209 /***********************************************************************
6211 ***********************************************************************/
6213 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6215 doc
: /* Set width of marginal areas of window WINDOW.
6216 WINDOW must be a live window and defaults to the selected one.
6218 Second arg LEFT-WIDTH specifies the number of character cells to
6219 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6220 does the same for the right marginal area. A nil width parameter
6221 means no margin. */)
6222 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
)
6224 struct window
*w
= decode_live_window (window
);
6226 /* Translate negative or zero widths to nil.
6227 Margins that are too wide have to be checked elsewhere. */
6229 if (!NILP (left_width
))
6231 CHECK_NUMBER (left_width
);
6232 if (XINT (left_width
) <= 0)
6236 if (!NILP (right_width
))
6238 CHECK_NUMBER (right_width
);
6239 if (XINT (right_width
) <= 0)
6243 if (!EQ (w
->left_margin_cols
, left_width
)
6244 || !EQ (w
->right_margin_cols
, right_width
))
6246 wset_left_margin_cols (w
, left_width
);
6247 wset_right_margin_cols (w
, right_width
);
6249 adjust_window_margins (w
);
6251 ++windows_or_buffers_changed
;
6252 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6259 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6261 doc
: /* Get width of marginal areas of window WINDOW.
6262 WINDOW must be a live window and defaults to the selected one.
6264 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6265 If a marginal area does not exist, its width will be returned
6267 (Lisp_Object window
)
6269 struct window
*w
= decode_live_window (window
);
6270 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
6275 /***********************************************************************
6277 ***********************************************************************/
6279 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6281 doc
: /* Set the fringe widths of window WINDOW.
6282 WINDOW must be a live window and defaults to the selected one.
6284 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6285 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6286 fringe width. If a fringe width arg is nil, that means to use the
6287 frame's default fringe width. Default fringe widths can be set with
6288 the command `set-fringe-style'.
6289 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6290 outside of the display margins. By default, fringes are drawn between
6291 display marginal areas and the text area. */)
6292 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
, Lisp_Object outside_margins
)
6294 struct window
*w
= decode_live_window (window
);
6295 int outside
= !NILP (outside_margins
);
6297 if (!NILP (left_width
))
6298 CHECK_NATNUM (left_width
);
6299 if (!NILP (right_width
))
6300 CHECK_NATNUM (right_width
);
6302 /* Do nothing on a tty. */
6303 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6304 && (!EQ (w
->left_fringe_width
, left_width
)
6305 || !EQ (w
->right_fringe_width
, right_width
)
6306 || w
->fringes_outside_margins
!= outside
))
6308 wset_left_fringe_width (w
, left_width
);
6309 wset_right_fringe_width (w
, right_width
);
6310 w
->fringes_outside_margins
= outside
;
6312 adjust_window_margins (w
);
6314 clear_glyph_matrix (w
->current_matrix
);
6315 w
->window_end_valid
= 0;
6317 ++windows_or_buffers_changed
;
6318 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6325 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6327 doc
: /* Get width of fringes of window WINDOW.
6328 WINDOW must be a live window and defaults to the selected one.
6330 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6331 (Lisp_Object window
)
6333 struct window
*w
= decode_live_window (window
);
6335 return list3 (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6336 make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6337 WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
) ? Qt
: Qnil
);
6342 /***********************************************************************
6344 ***********************************************************************/
6346 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
,
6347 Sset_window_scroll_bars
, 2, 4, 0,
6348 doc
: /* Set width and type of scroll bars of window WINDOW.
6349 WINDOW must be a live window and defaults to the selected one.
6351 Second parameter WIDTH specifies the pixel width for the scroll bar;
6352 this is automatically adjusted to a multiple of the frame column width.
6353 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6354 bar: left, right, or nil.
6355 If WIDTH is nil, use the frame's scroll-bar width.
6356 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6357 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6358 (Lisp_Object window
, Lisp_Object width
, Lisp_Object vertical_type
, Lisp_Object horizontal_type
)
6360 struct window
*w
= decode_live_window (window
);
6364 CHECK_RANGED_INTEGER (width
, 0, INT_MAX
);
6366 if (XINT (width
) == 0)
6367 vertical_type
= Qnil
;
6370 if (!(NILP (vertical_type
)
6371 || EQ (vertical_type
, Qleft
)
6372 || EQ (vertical_type
, Qright
)
6373 || EQ (vertical_type
, Qt
)))
6374 error ("Invalid type of vertical scroll bar");
6376 if (!EQ (w
->scroll_bar_width
, width
)
6377 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6379 wset_scroll_bar_width (w
, width
);
6380 wset_vertical_scroll_bar_type (w
, vertical_type
);
6382 adjust_window_margins (w
);
6384 clear_glyph_matrix (w
->current_matrix
);
6385 w
->window_end_valid
= 0;
6387 ++windows_or_buffers_changed
;
6388 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6395 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6397 doc
: /* Get width and type of scroll bars of window WINDOW.
6398 WINDOW must be a live window and defaults to the selected one.
6400 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6401 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6403 (Lisp_Object window
)
6405 struct window
*w
= decode_live_window (window
);
6407 return list4 (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6408 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6409 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6410 make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6411 w
->vertical_scroll_bar_type
, Qnil
);
6416 /***********************************************************************
6418 ***********************************************************************/
6420 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6421 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6422 If WINDOW is omitted or nil, it defaults to the selected window.
6423 Normally, value is a multiple of the canonical character height of WINDOW;
6424 optional second arg PIXELS-P means value is measured in pixels. */)
6425 (Lisp_Object window
, Lisp_Object pixels_p
)
6428 struct window
*w
= decode_live_window (window
);
6429 struct frame
*f
= XFRAME (w
->frame
);
6431 if (FRAME_WINDOW_P (f
))
6432 result
= (NILP (pixels_p
)
6433 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6434 : make_number (-w
->vscroll
));
6436 result
= make_number (0);
6441 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6443 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6444 WINDOW nil means use the selected window. Normally, VSCROLL is a
6445 non-negative multiple of the canonical character height of WINDOW;
6446 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
6447 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6448 corresponds to an integral number of pixels. The return value is the
6449 result of this rounding.
6450 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6451 (Lisp_Object window
, Lisp_Object vscroll
, Lisp_Object pixels_p
)
6453 struct window
*w
= decode_live_window (window
);
6454 struct frame
*f
= XFRAME (w
->frame
);
6456 CHECK_NUMBER_OR_FLOAT (vscroll
);
6458 if (FRAME_WINDOW_P (f
))
6460 int old_dy
= w
->vscroll
;
6462 w
->vscroll
= - (NILP (pixels_p
)
6463 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
6464 : XFLOATINT (vscroll
));
6465 w
->vscroll
= min (w
->vscroll
, 0);
6467 if (w
->vscroll
!= old_dy
)
6469 /* Adjust glyph matrix of the frame if the virtual display
6470 area becomes larger than before. */
6471 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
6474 /* Prevent redisplay shortcuts. */
6475 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
6479 return Fwindow_vscroll (window
, pixels_p
);
6483 /* Call FN for all leaf windows on frame F. FN is called with the
6484 first argument being a pointer to the leaf window, and with
6485 additional argument USER_DATA. Stops when FN returns 0. */
6488 foreach_window (struct frame
*f
, int (*fn
) (struct window
*, void *),
6491 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
6492 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
6493 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
6497 /* Helper function for foreach_window. Call FN for all leaf windows
6498 reachable from W. FN is called with the first argument being a
6499 pointer to the leaf window, and with additional argument USER_DATA.
6500 Stop when FN returns 0. Value is 0 if stopped by FN. */
6503 foreach_window_1 (struct window
*w
, int (*fn
) (struct window
*, void *), void *user_data
)
6507 for (cont
= 1; w
&& cont
;)
6509 if (!NILP (w
->hchild
))
6510 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
6511 else if (!NILP (w
->vchild
))
6512 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
6514 cont
= fn (w
, user_data
);
6516 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6523 /* Freeze or unfreeze the window start of W unless it is a
6524 mini-window or the selected window. FREEZE_P non-null means freeze
6525 the window start. */
6528 freeze_window_start (struct window
*w
, void *freeze_p
)
6530 if (MINI_WINDOW_P (w
)
6531 || (WINDOWP (selected_window
) /* Can be nil in corner cases. */
6532 && (w
== XWINDOW (selected_window
)
6533 || (MINI_WINDOW_P (XWINDOW (selected_window
))
6534 && ! NILP (Vminibuf_scroll_window
)
6535 && w
== XWINDOW (Vminibuf_scroll_window
)))))
6538 w
->frozen_window_start_p
= freeze_p
!= NULL
;
6543 /* Freeze or unfreeze the window starts of all leaf windows on frame
6544 F, except the selected window and a mini-window. FREEZE_P non-zero
6545 means freeze the window start. */
6548 freeze_window_starts (struct frame
*f
, int freeze_p
)
6550 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
6554 /***********************************************************************
6556 ***********************************************************************/
6558 /* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2
6559 describe the same state of affairs. This is used by Fequal.
6561 IGNORE_POSITIONS means ignore non-matching scroll positions
6564 This ignores a couple of things like the dedication status of
6565 window, combination_limit and the like. This might have to be
6569 compare_window_configurations (Lisp_Object configuration1
,
6570 Lisp_Object configuration2
,
6571 bool ignore_positions
)
6573 register struct save_window_data
*d1
, *d2
;
6574 struct Lisp_Vector
*sws1
, *sws2
;
6577 CHECK_WINDOW_CONFIGURATION (configuration1
);
6578 CHECK_WINDOW_CONFIGURATION (configuration2
);
6580 d1
= (struct save_window_data
*) XVECTOR (configuration1
);
6581 d2
= (struct save_window_data
*) XVECTOR (configuration2
);
6582 sws1
= XVECTOR (d1
->saved_windows
);
6583 sws2
= XVECTOR (d2
->saved_windows
);
6585 /* Frame settings must match. */
6586 if (d1
->frame_cols
!= d2
->frame_cols
6587 || d1
->frame_lines
!= d2
->frame_lines
6588 || d1
->frame_menu_bar_lines
!= d2
->frame_menu_bar_lines
6589 || !EQ (d1
->selected_frame
, d2
->selected_frame
)
6590 || !EQ (d1
->current_buffer
, d2
->current_buffer
)
6591 || (!ignore_positions
6592 && (!EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
)
6593 || !EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
)))
6594 || !EQ (d1
->focus_frame
, d2
->focus_frame
)
6595 /* Verify that the two configurations have the same number of windows. */
6596 || sws1
->header
.size
!= sws2
->header
.size
)
6599 for (i
= 0; i
< sws1
->header
.size
; i
++)
6601 struct saved_window
*sw1
, *sw2
;
6603 sw1
= SAVED_WINDOW_N (sws1
, i
);
6604 sw2
= SAVED_WINDOW_N (sws2
, i
);
6607 /* The "current" windows in the two configurations must
6608 correspond to each other. */
6609 EQ (d1
->current_window
, sw1
->window
)
6610 != EQ (d2
->current_window
, sw2
->window
)
6611 /* Windows' buffers must match. */
6612 || !EQ (sw1
->buffer
, sw2
->buffer
)
6613 || !EQ (sw1
->left_col
, sw2
->left_col
)
6614 || !EQ (sw1
->top_line
, sw2
->top_line
)
6615 || !EQ (sw1
->total_cols
, sw2
->total_cols
)
6616 || !EQ (sw1
->total_lines
, sw2
->total_lines
)
6617 || !EQ (sw1
->display_table
, sw2
->display_table
)
6618 /* The next two disjuncts check the window structure for
6620 || !EQ (sw1
->parent
, sw2
->parent
)
6621 || !EQ (sw1
->prev
, sw2
->prev
)
6622 || (!ignore_positions
6623 && (!EQ (sw1
->hscroll
, sw2
->hscroll
)
6624 || !EQ (sw1
->min_hscroll
, sw2
->min_hscroll
)
6625 || !EQ (sw1
->start_at_line_beg
, sw2
->start_at_line_beg
)
6626 || NILP (Fequal (sw1
->start
, sw2
->start
))
6627 || NILP (Fequal (sw1
->pointm
, sw2
->pointm
))
6628 || NILP (Fequal (sw1
->mark
, sw2
->mark
))))
6629 || !EQ (sw1
->left_margin_cols
, sw2
->left_margin_cols
)
6630 || !EQ (sw1
->right_margin_cols
, sw2
->right_margin_cols
)
6631 || !EQ (sw1
->left_fringe_width
, sw2
->left_fringe_width
)
6632 || !EQ (sw1
->right_fringe_width
, sw2
->right_fringe_width
)
6633 || !EQ (sw1
->fringes_outside_margins
, sw2
->fringes_outside_margins
)
6634 || !EQ (sw1
->scroll_bar_width
, sw2
->scroll_bar_width
)
6635 || !EQ (sw1
->vertical_scroll_bar_type
, sw2
->vertical_scroll_bar_type
))
6642 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
6643 Scompare_window_configurations
, 2, 2, 0,
6644 doc
: /* Compare two window configurations as regards the structure of windows.
6645 This function ignores details such as the values of point and mark
6646 and scrolling positions. */)
6647 (Lisp_Object x
, Lisp_Object y
)
6649 if (compare_window_configurations (x
, y
, 1))
6655 init_window_once (void)
6657 struct frame
*f
= make_initial_frame ();
6658 XSETFRAME (selected_frame
, f
);
6659 Vterminal_frame
= selected_frame
;
6660 minibuf_window
= f
->minibuffer_window
;
6661 selected_window
= f
->selected_window
;
6662 last_nonminibuf_frame
= f
;
6664 window_initialized
= 1;
6670 Vwindow_list
= Qnil
;
6674 syms_of_window (void)
6676 DEFSYM (Qscroll_up
, "scroll-up");
6677 DEFSYM (Qscroll_down
, "scroll-down");
6678 DEFSYM (Qscroll_command
, "scroll-command");
6680 Fput (Qscroll_up
, Qscroll_command
, Qt
);
6681 Fput (Qscroll_down
, Qscroll_command
, Qt
);
6683 DEFSYM (Qwindow_configuration_change_hook
, "window-configuration-change-hook");
6684 DEFSYM (Qwindowp
, "windowp");
6685 DEFSYM (Qwindow_configuration_p
, "window-configuration-p");
6686 DEFSYM (Qwindow_live_p
, "window-live-p");
6687 DEFSYM (Qwindow_valid_p
, "window-valid-p");
6688 DEFSYM (Qwindow_deletable_p
, "window-deletable-p");
6689 DEFSYM (Qdelete_window
, "delete-window");
6690 DEFSYM (Qwindow_resize_root_window
, "window--resize-root-window");
6691 DEFSYM (Qwindow_resize_root_window_vertically
, "window--resize-root-window-vertically");
6692 DEFSYM (Qsafe
, "safe");
6693 DEFSYM (Qdisplay_buffer
, "display-buffer");
6694 DEFSYM (Qreplace_buffer_in_windows
, "replace-buffer-in-windows");
6695 DEFSYM (Qrecord_window_buffer
, "record-window-buffer");
6696 DEFSYM (Qget_mru_window
, "get-mru-window");
6697 DEFSYM (Qwindow_size
, "window-size");
6698 DEFSYM (Qtemp_buffer_show_hook
, "temp-buffer-show-hook");
6699 DEFSYM (Qabove
, "above");
6700 DEFSYM (Qbelow
, "below");
6701 DEFSYM (Qclone_of
, "clone-of");
6703 staticpro (&Vwindow_list
);
6705 minibuf_selected_window
= Qnil
;
6706 staticpro (&minibuf_selected_window
);
6708 window_scroll_pixel_based_preserve_x
= -1;
6709 window_scroll_pixel_based_preserve_y
= -1;
6710 window_scroll_preserve_hpos
= -1;
6711 window_scroll_preserve_vpos
= -1;
6713 DEFVAR_LISP ("temp-buffer-show-function", Vtemp_buffer_show_function
,
6714 doc
: /* Non-nil means call as function to display a help buffer.
6715 The function is called with one argument, the buffer to be displayed.
6716 Used by `with-output-to-temp-buffer'.
6717 If this function is used, then it must do the entire job of showing
6718 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6719 Vtemp_buffer_show_function
= Qnil
;
6721 DEFVAR_LISP ("minibuffer-scroll-window", Vminibuf_scroll_window
,
6722 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6723 Vminibuf_scroll_window
= Qnil
;
6725 DEFVAR_BOOL ("mode-line-in-non-selected-windows", mode_line_in_non_selected_windows
,
6726 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6727 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6728 is displayed in the `mode-line' face. */);
6729 mode_line_in_non_selected_windows
= 1;
6731 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer
,
6732 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6733 Vother_window_scroll_buffer
= Qnil
;
6735 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p
,
6736 doc
: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
6737 auto_window_vscroll_p
= 1;
6739 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines
,
6740 doc
: /* Number of lines of continuity when scrolling by screenfuls. */);
6741 next_screen_context_lines
= 2;
6743 DEFVAR_LISP ("scroll-preserve-screen-position",
6744 Vscroll_preserve_screen_position
,
6745 doc
: /* Controls if scroll commands move point to keep its screen position unchanged.
6746 A value of nil means point does not keep its screen position except
6747 at the scroll margin or window boundary respectively.
6748 A value of t means point keeps its screen position if the scroll
6749 command moved it vertically out of the window, e.g. when scrolling
6751 Any other value means point always keeps its screen position.
6752 Scroll commands should have the `scroll-command' property
6753 on their symbols to be controlled by this variable. */);
6754 Vscroll_preserve_screen_position
= Qnil
;
6756 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type
,
6757 doc
: /* Type of marker to use for `window-point'. */);
6758 Vwindow_point_insertion_type
= Qnil
;
6760 DEFVAR_LISP ("window-configuration-change-hook",
6761 Vwindow_configuration_change_hook
,
6762 doc
: /* Functions to call when window configuration changes.
6763 The buffer-local part is run once per window, with the relevant window
6764 selected; while the global part is run only once for the modified frame,
6765 with the relevant frame selected. */);
6766 Vwindow_configuration_change_hook
= Qnil
;
6768 DEFVAR_LISP ("recenter-redisplay", Vrecenter_redisplay
,
6769 doc
: /* Non-nil means `recenter' redraws entire frame.
6770 If this option is non-nil, then the `recenter' command with a nil
6771 argument will redraw the entire frame; the special value `tty' causes
6772 the frame to be redrawn only if it is a tty frame. */);
6773 Vrecenter_redisplay
= Qtty
;
6775 DEFVAR_LISP ("window-combination-resize", Vwindow_combination_resize
,
6776 doc
: /* If t, resize window combinations proportionally.
6777 If this variable is nil, splitting a window gets the entire screen space
6778 for displaying the new window from the window to split. Deleting and
6779 resizing a window preferably resizes one adjacent window only.
6781 If this variable is t, splitting a window tries to get the space
6782 proportionally from all windows in the same combination. This also
6783 allows to split a window that is otherwise too small or of fixed size.
6784 Resizing and deleting a window proportionally resize all windows in the
6787 Other values are reserved for future use.
6789 This variable takes no effect if the variable `window-combination-limit' is
6791 Vwindow_combination_resize
= Qnil
;
6793 DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit
,
6794 doc
: /* If non-nil, splitting a window makes a new parent window.
6795 The following values are recognized:
6797 nil means splitting a window will create a new parent window only if the
6798 window has no parent window or the window shall become part of a
6799 combination orthogonal to the one it is part of.
6801 `window-size' means that splitting a window for displaying a buffer
6802 makes a new parent window provided `display-buffer' is supposed to
6803 explicitly set the window's size due to the presence of a
6804 `window-height' or `window-width' entry in the alist used by
6805 `display-buffer'. Otherwise, this value is handled like nil.
6807 `temp-buffer' means that splitting a window for displaying a temporary
6808 buffer always makes a new parent window. Otherwise, this value is
6811 `display-buffer' means that splitting a window for displaying a buffer
6812 always makes a new parent window. Since temporary buffers are
6813 displayed by the function `display-buffer', this value is stronger
6814 than `temp-buffer'. Splitting a window for other purpose makes a
6815 new parent window only if needed.
6817 t means that splitting a window always creates a new parent window. If
6818 all splits behave this way, each frame's window tree is a binary
6819 tree and every window but the frame's root window has exactly one
6822 Other values are reserved for future use. */);
6823 Vwindow_combination_limit
= Qwindow_size
;
6825 DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters
,
6826 doc
: /* Alist of persistent window parameters.
6827 This alist specifies which window parameters shall get saved by
6828 `current-window-configuration' and `window-state-get' and subsequently
6829 restored to their previous values by `set-window-configuration' and
6832 The car of each entry of this alist is the symbol specifying the
6833 parameter. The cdr is one of the following:
6835 nil means the parameter is neither saved by `window-state-get' nor by
6836 `current-window-configuration'.
6838 t means the parameter is saved by `current-window-configuration' and,
6839 provided its WRITABLE argument is nil, by `window-state-get'.
6841 The symbol `writable' means the parameter is saved unconditionally by
6842 both `current-window-configuration' and `window-state-get'. Do not use
6843 this value for parameters without read syntax (like windows or frames).
6845 Parameters not saved by `current-window-configuration' or
6846 `window-state-get' are left alone by `set-window-configuration'
6847 respectively are not installed by `window-state-put'. */);
6848 Vwindow_persistent_parameters
= list1 (Fcons (Qclone_of
, Qt
));
6850 defsubr (&Sselected_window
);
6851 defsubr (&Sminibuffer_window
);
6852 defsubr (&Swindow_minibuffer_p
);
6853 defsubr (&Swindowp
);
6854 defsubr (&Swindow_valid_p
);
6855 defsubr (&Swindow_live_p
);
6856 defsubr (&Swindow_frame
);
6857 defsubr (&Sframe_root_window
);
6858 defsubr (&Sframe_first_window
);
6859 defsubr (&Sframe_selected_window
);
6860 defsubr (&Sset_frame_selected_window
);
6861 defsubr (&Spos_visible_in_window_p
);
6862 defsubr (&Swindow_line_height
);
6863 defsubr (&Swindow_buffer
);
6864 defsubr (&Swindow_parent
);
6865 defsubr (&Swindow_top_child
);
6866 defsubr (&Swindow_left_child
);
6867 defsubr (&Swindow_next_sibling
);
6868 defsubr (&Swindow_prev_sibling
);
6869 defsubr (&Swindow_combination_limit
);
6870 defsubr (&Sset_window_combination_limit
);
6871 defsubr (&Swindow_use_time
);
6872 defsubr (&Swindow_top_line
);
6873 defsubr (&Swindow_left_column
);
6874 defsubr (&Swindow_total_height
);
6875 defsubr (&Swindow_total_width
);
6876 defsubr (&Swindow_normal_size
);
6877 defsubr (&Swindow_new_total
);
6878 defsubr (&Swindow_new_normal
);
6879 defsubr (&Sset_window_new_total
);
6880 defsubr (&Sset_window_new_normal
);
6881 defsubr (&Swindow_resize_apply
);
6882 defsubr (&Swindow_body_height
);
6883 defsubr (&Swindow_body_width
);
6884 defsubr (&Swindow_hscroll
);
6885 defsubr (&Sset_window_hscroll
);
6886 defsubr (&Swindow_redisplay_end_trigger
);
6887 defsubr (&Sset_window_redisplay_end_trigger
);
6888 defsubr (&Swindow_edges
);
6889 defsubr (&Swindow_pixel_edges
);
6890 defsubr (&Swindow_absolute_pixel_edges
);
6891 defsubr (&Swindow_inside_edges
);
6892 defsubr (&Swindow_inside_pixel_edges
);
6893 defsubr (&Swindow_inside_absolute_pixel_edges
);
6894 defsubr (&Scoordinates_in_window_p
);
6895 defsubr (&Swindow_at
);
6896 defsubr (&Swindow_point
);
6897 defsubr (&Swindow_start
);
6898 defsubr (&Swindow_end
);
6899 defsubr (&Sset_window_point
);
6900 defsubr (&Sset_window_start
);
6901 defsubr (&Swindow_dedicated_p
);
6902 defsubr (&Sset_window_dedicated_p
);
6903 defsubr (&Swindow_display_table
);
6904 defsubr (&Sset_window_display_table
);
6905 defsubr (&Snext_window
);
6906 defsubr (&Sprevious_window
);
6907 defsubr (&Sget_buffer_window
);
6908 defsubr (&Sdelete_other_windows_internal
);
6909 defsubr (&Sdelete_window_internal
);
6910 defsubr (&Sresize_mini_window_internal
);
6911 defsubr (&Sset_window_buffer
);
6912 defsubr (&Srun_window_configuration_change_hook
);
6913 defsubr (&Sselect_window
);
6914 defsubr (&Sforce_window_update
);
6915 defsubr (&Ssplit_window_internal
);
6916 defsubr (&Sscroll_up
);
6917 defsubr (&Sscroll_down
);
6918 defsubr (&Sscroll_left
);
6919 defsubr (&Sscroll_right
);
6920 defsubr (&Sother_window_for_scrolling
);
6921 defsubr (&Sscroll_other_window
);
6922 defsubr (&Sminibuffer_selected_window
);
6923 defsubr (&Srecenter
);
6924 defsubr (&Swindow_text_height
);
6925 defsubr (&Smove_to_window_line
);
6926 defsubr (&Swindow_configuration_p
);
6927 defsubr (&Swindow_configuration_frame
);
6928 defsubr (&Sset_window_configuration
);
6929 defsubr (&Scurrent_window_configuration
);
6930 defsubr (&Sset_window_margins
);
6931 defsubr (&Swindow_margins
);
6932 defsubr (&Sset_window_fringes
);
6933 defsubr (&Swindow_fringes
);
6934 defsubr (&Sset_window_scroll_bars
);
6935 defsubr (&Swindow_scroll_bars
);
6936 defsubr (&Swindow_vscroll
);
6937 defsubr (&Sset_window_vscroll
);
6938 defsubr (&Scompare_window_configurations
);
6939 defsubr (&Swindow_list
);
6940 defsubr (&Swindow_list_1
);
6941 defsubr (&Swindow_prev_buffers
);
6942 defsubr (&Sset_window_prev_buffers
);
6943 defsubr (&Swindow_next_buffers
);
6944 defsubr (&Sset_window_next_buffers
);
6945 defsubr (&Swindow_parameters
);
6946 defsubr (&Swindow_parameter
);
6947 defsubr (&Sset_window_parameter
);
6951 keys_of_window (void)
6953 initial_define_key (control_x_map
, '<', "scroll-left");
6954 initial_define_key (control_x_map
, '>', "scroll-right");
6956 initial_define_key (global_map
, Ctl ('V'), "scroll-up-command");
6957 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
6958 initial_define_key (meta_map
, 'v', "scroll-down-command");