1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985-1987, 1993-1998, 2000-2015 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/>. */
26 #include "character.h"
37 #include "dispextern.h"
38 #include "blockinput.h"
39 #include "intervals.h"
40 #include "termhooks.h" /* For FRAME_TERMINAL. */
41 #ifdef HAVE_WINDOW_SYSTEM
43 #endif /* HAVE_WINDOW_SYSTEM */
54 Lisp_Object Qwindowp
, Qwindow_live_p
;
55 static Lisp_Object Qwindow_valid_p
;
56 static Lisp_Object Qwindow_configuration_p
;
57 static Lisp_Object Qrecord_window_buffer
;
58 static Lisp_Object Qwindow_deletable_p
, Qdelete_window
, Qdisplay_buffer
;
59 static Lisp_Object Qreplace_buffer_in_windows
, Qget_mru_window
;
60 static Lisp_Object Qwindow_resize_root_window
, Qwindow_resize_root_window_vertically
;
61 static Lisp_Object Qwindow_sanitize_window_sizes
;
62 static Lisp_Object Qwindow_pixel_to_total
;
63 static Lisp_Object Qscroll_up
, Qscroll_down
, Qscroll_command
;
64 static Lisp_Object Qsafe
, Qabove
, Qbelow
, Qwindow_size
, Qclone_of
;
65 static Lisp_Object Qfloor
, Qceiling
;
66 static Lisp_Object Qwindow_point_insertion_type
;
68 static int displayed_window_lines (struct window
*);
69 static int count_windows (struct window
*);
70 static int get_leaf_windows (struct window
*, struct window
**, int);
71 static void window_scroll (Lisp_Object
, EMACS_INT
, bool, int);
72 static void window_scroll_pixel_based (Lisp_Object
, int, bool, int);
73 static void window_scroll_line_based (Lisp_Object
, int, bool, int);
74 static int add_window_to_list (struct window
*, void *);
75 static Lisp_Object
next_window (Lisp_Object
, Lisp_Object
,
77 static void decode_next_window_args (Lisp_Object
*, Lisp_Object
*,
79 static void foreach_window (struct frame
*,
80 int (* fn
) (struct window
*, void *),
82 static int foreach_window_1 (struct window
*,
83 int (* fn
) (struct window
*, void *),
85 static Lisp_Object
window_list_1 (Lisp_Object
, Lisp_Object
, Lisp_Object
);
86 static int window_resize_check (struct window
*, bool);
87 static void window_resize_apply (struct window
*, bool);
88 static void window_resize_apply_total (struct window
*, bool);
89 static Lisp_Object
select_window (Lisp_Object
, Lisp_Object
, int);
90 static void select_window_1 (Lisp_Object
, bool);
92 static struct window
*set_window_fringes (struct window
*, Lisp_Object
,
93 Lisp_Object
, Lisp_Object
);
94 static struct window
*set_window_margins (struct window
*, Lisp_Object
,
96 static struct window
*set_window_scroll_bars (struct window
*, Lisp_Object
,
97 Lisp_Object
, Lisp_Object
, Lisp_Object
);
98 static void apply_window_adjustment (struct window
*);
100 /* This is the window in which the terminal's cursor should
101 be left when nothing is being done with it. This must
102 always be a leaf window, and its buffer is selected by
103 the top level editing loop at the end of each command.
105 This value is always the same as
106 FRAME_SELECTED_WINDOW (selected_frame). */
107 Lisp_Object selected_window
;
109 /* A list of all windows for use by next_window and Fwindow_list.
110 Functions creating or deleting windows should invalidate this cache
111 by setting it to nil. */
112 Lisp_Object Vwindow_list
;
114 /* The mini-buffer window of the selected frame.
115 Note that you cannot test for mini-bufferness of an arbitrary window
116 by comparing against this; but you can test for mini-bufferness of
117 the selected window. */
118 Lisp_Object minibuf_window
;
120 /* Non-nil means it is the window whose mode line should be
121 shown as the selected window when the minibuffer is selected. */
122 Lisp_Object minibuf_selected_window
;
124 /* Hook run at end of temp_output_buffer_show. */
125 static Lisp_Object Qtemp_buffer_show_hook
;
127 /* Incremented for each window created. */
128 static int sequence_number
;
130 /* Hook to run when window config changes. */
131 static Lisp_Object Qwindow_configuration_change_hook
;
133 /* Used by the function window_scroll_pixel_based. */
134 static int window_scroll_pixel_based_preserve_x
;
135 static int window_scroll_pixel_based_preserve_y
;
137 /* Same for window_scroll_line_based. */
138 static EMACS_INT window_scroll_preserve_hpos
;
139 static EMACS_INT window_scroll_preserve_vpos
;
142 CHECK_WINDOW_CONFIGURATION (Lisp_Object x
)
144 CHECK_TYPE (WINDOW_CONFIGURATIONP (x
), Qwindow_configuration_p
, x
);
147 /* These setters are used only in this file, so they can be private. */
149 wset_combination_limit (struct window
*w
, Lisp_Object val
)
151 w
->combination_limit
= val
;
155 wset_dedicated (struct window
*w
, Lisp_Object val
)
161 wset_display_table (struct window
*w
, Lisp_Object val
)
163 w
->display_table
= val
;
167 wset_new_normal (struct window
*w
, Lisp_Object val
)
173 wset_new_total (struct window
*w
, Lisp_Object val
)
179 wset_normal_cols (struct window
*w
, Lisp_Object val
)
181 w
->normal_cols
= val
;
185 wset_normal_lines (struct window
*w
, Lisp_Object val
)
187 w
->normal_lines
= val
;
191 wset_parent (struct window
*w
, Lisp_Object val
)
197 wset_pointm (struct window
*w
, Lisp_Object val
)
203 wset_old_pointm (struct window
*w
, Lisp_Object val
)
209 wset_start (struct window
*w
, Lisp_Object val
)
215 wset_temslot (struct window
*w
, Lisp_Object val
)
221 wset_vertical_scroll_bar_type (struct window
*w
, Lisp_Object val
)
223 w
->vertical_scroll_bar_type
= val
;
227 wset_window_parameters (struct window
*w
, Lisp_Object val
)
229 w
->window_parameters
= val
;
233 wset_combination (struct window
*w
, bool horflag
, Lisp_Object val
)
235 /* Since leaf windows never becomes non-leaf, there should
236 be no buffer and markers in start and pointm fields of W. */
237 eassert (!BUFFERP (w
->contents
) && NILP (w
->start
) && NILP (w
->pointm
));
239 /* When an internal window is deleted and VAL is nil, HORFLAG
242 w
->horizontal
= horflag
;
245 /* Nonzero if leaf window W doesn't reflect the actual state
246 of displayed buffer due to its text or overlays change. */
249 window_outdated (struct window
*w
)
251 struct buffer
*b
= XBUFFER (w
->contents
);
252 return (w
->last_modified
< BUF_MODIFF (b
)
253 || w
->last_overlay_modified
< BUF_OVERLAY_MODIFF (b
));
257 decode_live_window (register Lisp_Object window
)
260 return XWINDOW (selected_window
);
262 CHECK_LIVE_WINDOW (window
);
263 return XWINDOW (window
);
267 decode_any_window (register Lisp_Object window
)
272 return XWINDOW (selected_window
);
274 CHECK_WINDOW (window
);
275 w
= XWINDOW (window
);
279 static struct window
*
280 decode_valid_window (register Lisp_Object window
)
285 return XWINDOW (selected_window
);
287 CHECK_VALID_WINDOW (window
);
288 w
= XWINDOW (window
);
292 /* Called when W's buffer slot is changed. ARG -1 means that W is about to
293 cease its buffer, and 1 means that W is about to set up the new one. */
296 adjust_window_count (struct window
*w
, int arg
)
298 eassert (eabs (arg
) == 1);
299 if (BUFFERP (w
->contents
))
301 struct buffer
*b
= XBUFFER (w
->contents
);
305 b
->window_count
+= arg
;
306 eassert (b
->window_count
>= 0);
307 /* These should be recalculated by redisplay code. */
308 w
->window_end_valid
= 0;
309 w
->base_line_pos
= 0;
313 /* Set W's buffer slot to VAL and recompute number
314 of windows showing VAL if it is a buffer. */
317 wset_buffer (struct window
*w
, Lisp_Object val
)
319 adjust_window_count (w
, -1);
321 /* Make sure that we do not assign the buffer
322 to an internal window. */
323 eassert (MARKERP (w
->start
) && MARKERP (w
->pointm
));
325 adjust_window_count (w
, 1);
328 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
329 doc
: /* Return t if OBJECT is a window and nil otherwise. */)
332 return WINDOWP (object
) ? Qt
: Qnil
;
335 DEFUN ("window-valid-p", Fwindow_valid_p
, Swindow_valid_p
, 1, 1, 0,
336 doc
: /* Return t if OBJECT is a valid window and nil otherwise.
337 A valid window is either a window that displays a buffer or an internal
338 window. Windows that have been deleted are not valid. */)
341 return WINDOW_VALID_P (object
) ? Qt
: Qnil
;
344 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
345 doc
: /* Return t if OBJECT is a live window and nil otherwise.
346 A live window is a window that displays a buffer.
347 Internal windows and deleted windows are not live. */)
350 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
353 /* Frames and windows. */
354 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 0, 1, 0,
355 doc
: /* Return the frame that window WINDOW is on.
356 WINDOW must be a valid window and defaults to the selected one. */)
359 return decode_valid_window (window
)->frame
;
362 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
363 doc
: /* Return the root window of FRAME-OR-WINDOW.
364 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
365 With a frame argument, return that frame's root window.
366 With a window argument, return the root window of that window's frame. */)
367 (Lisp_Object frame_or_window
)
371 if (NILP (frame_or_window
))
372 window
= SELECTED_FRAME ()->root_window
;
373 else if (WINDOW_VALID_P (frame_or_window
))
374 window
= XFRAME (XWINDOW (frame_or_window
)->frame
)->root_window
;
377 CHECK_LIVE_FRAME (frame_or_window
);
378 window
= XFRAME (frame_or_window
)->root_window
;
384 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
385 doc
: /* Return the minibuffer window for frame FRAME.
386 If FRAME is omitted or nil, it defaults to the selected frame. */)
389 return FRAME_MINIBUF_WINDOW (decode_live_frame (frame
));
392 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
,
393 Swindow_minibuffer_p
, 0, 1, 0,
394 doc
: /* Return non-nil if WINDOW is a minibuffer window.
395 WINDOW must be a valid window and defaults to the selected one. */)
398 return MINI_WINDOW_P (decode_valid_window (window
)) ? Qt
: Qnil
;
401 /* Don't move this to window.el - this must be a safe routine. */
402 DEFUN ("frame-first-window", Fframe_first_window
, Sframe_first_window
, 0, 1, 0,
403 doc
: /* Return the topmost, leftmost live window on FRAME-OR-WINDOW.
404 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
405 Else if FRAME-OR-WINDOW denotes a valid window, return the first window
406 of that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
407 the first window of that frame. */)
408 (Lisp_Object frame_or_window
)
412 if (NILP (frame_or_window
))
413 window
= SELECTED_FRAME ()->root_window
;
414 else if (WINDOW_VALID_P (frame_or_window
))
415 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
418 CHECK_LIVE_FRAME (frame_or_window
);
419 window
= XFRAME (frame_or_window
)->root_window
;
422 while (WINDOWP (XWINDOW (window
)->contents
))
423 window
= XWINDOW (window
)->contents
;
428 DEFUN ("frame-selected-window", Fframe_selected_window
,
429 Sframe_selected_window
, 0, 1, 0,
430 doc
: /* Return the selected window of FRAME-OR-WINDOW.
431 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
432 Else if FRAME-OR-WINDOW denotes a valid window, return the selected
433 window of that window's frame. If FRAME-OR-WINDOW denotes a live frame,
434 return the selected window of that frame. */)
435 (Lisp_Object frame_or_window
)
439 if (NILP (frame_or_window
))
440 window
= SELECTED_FRAME ()->selected_window
;
441 else if (WINDOW_VALID_P (frame_or_window
))
442 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->selected_window
;
445 CHECK_LIVE_FRAME (frame_or_window
);
446 window
= XFRAME (frame_or_window
)->selected_window
;
452 DEFUN ("set-frame-selected-window", Fset_frame_selected_window
,
453 Sset_frame_selected_window
, 2, 3, 0,
454 doc
: /* Set selected window of FRAME to WINDOW.
455 FRAME must be a live frame and defaults to the selected one. If FRAME
456 is the selected frame, this makes WINDOW the selected window. Optional
457 argument NORECORD non-nil means to neither change the order of recently
458 selected windows nor the buffer list. WINDOW must denote a live window.
460 (Lisp_Object frame
, Lisp_Object window
, Lisp_Object norecord
)
463 frame
= selected_frame
;
465 CHECK_LIVE_FRAME (frame
);
466 CHECK_LIVE_WINDOW (window
);
468 if (! EQ (frame
, WINDOW_FRAME (XWINDOW (window
))))
469 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
471 if (EQ (frame
, selected_frame
))
472 return Fselect_window (window
, norecord
);
475 fset_selected_window (XFRAME (frame
), window
);
480 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
481 doc
: /* Return the selected window.
482 The selected window is the window in which the standard cursor for
483 selected windows appears and to which many commands apply. */)
486 return selected_window
;
489 int window_select_count
;
491 /* If select_window is called with inhibit_point_swap non-zero it will
492 not store point of the old selected window's buffer back into that
493 window's pointm slot. This is needed by Fset_window_configuration to
494 avoid that the display routine is called with selected_window set to
495 Qnil causing a subsequent crash. */
497 select_window (Lisp_Object window
, Lisp_Object norecord
, int inhibit_point_swap
)
499 register struct window
*w
;
502 CHECK_LIVE_WINDOW (window
);
504 w
= XWINDOW (window
);
506 /* Make the selected window's buffer current. */
507 Fset_buffer (w
->contents
);
509 if (EQ (window
, selected_window
) && !inhibit_point_swap
)
510 /* `switch-to-buffer' uses (select-window (selected-window)) as a "clever"
511 way to call record_buffer from Elisp, so it's important that we call
512 record_buffer before returning here. */
513 goto record_and_return
;
516 { /* Mark the window for redisplay since the selected-window has
517 a different mode-line. */
518 wset_redisplay (XWINDOW (selected_window
));
522 redisplay_other_windows ();
524 sf
= SELECTED_FRAME ();
525 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
527 fset_selected_window (XFRAME (WINDOW_FRAME (w
)), window
);
528 /* Use this rather than Fhandle_switch_frame
529 so that FRAME_FOCUS_FRAME is moved appropriately as we
530 move around in the state where a minibuffer in a separate
532 Fselect_frame (WINDOW_FRAME (w
), norecord
);
533 /* Fselect_frame called us back so we've done all the work already. */
534 eassert (EQ (window
, selected_window
));
538 fset_selected_window (sf
, window
);
540 select_window_1 (window
, inhibit_point_swap
);
541 bset_last_selected_window (XBUFFER (w
->contents
), window
);
544 /* record_buffer can run QUIT, so make sure it is run only after we have
545 re-established the invariant between selected_window and selected_frame,
546 otherwise the temporary broken invariant might "escape" (bug#14161). */
549 w
->use_time
= ++window_select_count
;
550 record_buffer (w
->contents
);
556 /* Select window with a minimum of fuss, i.e. don't record the change anywhere
557 (not even for redisplay's benefit), and assume that the window's frame is
560 select_window_1 (Lisp_Object window
, bool inhibit_point_swap
)
562 /* Store the old selected window's buffer's point in pointm of the old
563 selected window. It belongs to that window, and when the window is
564 not selected, must be in the window. */
565 if (!inhibit_point_swap
)
567 struct window
*ow
= XWINDOW (selected_window
);
568 if (BUFFERP (ow
->contents
))
569 set_marker_both (ow
->pointm
, ow
->contents
,
570 BUF_PT (XBUFFER (ow
->contents
)),
571 BUF_PT_BYTE (XBUFFER (ow
->contents
)));
574 selected_window
= window
;
576 /* Go to the point recorded in the window.
577 This is important when the buffer is in more
578 than one window. It also matters when
579 redisplay_window has altered point after scrolling,
580 because it makes the change only in the window. */
581 set_point_from_marker (XWINDOW (window
)->pointm
);
584 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
585 doc
: /* Select WINDOW which must be a live window.
586 Also make WINDOW's frame the selected frame and WINDOW that frame's
587 selected window. In addition, make WINDOW's buffer current and set its
588 buffer's value of `point' to the value of WINDOW's `window-point'.
591 Optional second arg NORECORD non-nil means do not put this buffer at the
592 front of the buffer list and do not make this window the most recently
595 Run `buffer-list-update-hook' unless NORECORD is non-nil. Note that
596 applications and internal routines often select a window temporarily for
597 various purposes; mostly, to simplify coding. As a rule, such
598 selections should be not recorded and therefore will not pollute
599 `buffer-list-update-hook'. Selections that "really count" are those
600 causing a visible change in the next redisplay of WINDOW's frame and
601 should be always recorded. So if you think of running a function each
602 time a window gets selected put it on `buffer-list-update-hook'.
604 Also note that the main editor command loop sets the current buffer to
605 the buffer of the selected window before each command. */)
606 (register Lisp_Object window
, Lisp_Object norecord
)
608 return select_window (window
, norecord
, 0);
611 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
612 doc
: /* Return the buffer displayed in window WINDOW.
613 If WINDOW is omitted or nil, it defaults to the selected window.
614 Return nil for an internal window or a deleted window. */)
617 struct window
*w
= decode_any_window (window
);
618 return WINDOW_LEAF_P (w
) ? w
->contents
: Qnil
;
621 DEFUN ("window-parent", Fwindow_parent
, Swindow_parent
, 0, 1, 0,
622 doc
: /* Return the parent window of window WINDOW.
623 WINDOW must be a valid window and defaults to the selected one.
624 Return nil for a window with no parent (e.g. a root window). */)
627 return decode_valid_window (window
)->parent
;
630 DEFUN ("window-top-child", Fwindow_top_child
, Swindow_top_child
, 0, 1, 0,
631 doc
: /* Return the topmost child window of window WINDOW.
632 WINDOW must be a valid window and defaults to the selected one.
633 Return nil if WINDOW is a live window (live windows have no children).
634 Return nil if WINDOW is an internal window whose children form a
635 horizontal combination. */)
638 struct window
*w
= decode_valid_window (window
);
639 return WINDOW_VERTICAL_COMBINATION_P (w
) ? w
->contents
: Qnil
;
642 DEFUN ("window-left-child", Fwindow_left_child
, Swindow_left_child
, 0, 1, 0,
643 doc
: /* Return the leftmost child window of window WINDOW.
644 WINDOW must be a valid window and defaults to the selected one.
645 Return nil if WINDOW is a live window (live windows have no children).
646 Return nil if WINDOW is an internal window whose children form a
647 vertical combination. */)
650 struct window
*w
= decode_valid_window (window
);
651 return WINDOW_HORIZONTAL_COMBINATION_P (w
) ? w
->contents
: Qnil
;
654 DEFUN ("window-next-sibling", Fwindow_next_sibling
, Swindow_next_sibling
, 0, 1, 0,
655 doc
: /* Return the next sibling window of window WINDOW.
656 WINDOW must be a valid window and defaults to the selected one.
657 Return nil if WINDOW has no next sibling. */)
660 return decode_valid_window (window
)->next
;
663 DEFUN ("window-prev-sibling", Fwindow_prev_sibling
, Swindow_prev_sibling
, 0, 1, 0,
664 doc
: /* Return the previous sibling window of window WINDOW.
665 WINDOW must be a valid window and defaults to the selected one.
666 Return nil if WINDOW has no previous sibling. */)
669 return decode_valid_window (window
)->prev
;
672 DEFUN ("window-combination-limit", Fwindow_combination_limit
, Swindow_combination_limit
, 1, 1, 0,
673 doc
: /* Return combination limit of window WINDOW.
674 WINDOW must be a valid window used in horizontal or vertical combination.
675 If the return value is nil, child windows of WINDOW can be recombined with
676 WINDOW's siblings. A return value of t means that child windows of
677 WINDOW are never \(re-)combined with WINDOW's siblings. */)
682 CHECK_VALID_WINDOW (window
);
683 w
= XWINDOW (window
);
684 if (WINDOW_LEAF_P (w
))
685 error ("Combination limit is meaningful for internal windows only");
686 return w
->combination_limit
;
689 DEFUN ("set-window-combination-limit", Fset_window_combination_limit
, Sset_window_combination_limit
, 2, 2, 0,
690 doc
: /* Set combination limit of window WINDOW to LIMIT; return LIMIT.
691 WINDOW must be a valid window used in horizontal or vertical combination.
692 If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's
693 siblings. LIMIT t means that child windows of WINDOW are never
694 \(re-)combined with WINDOW's siblings. Other values are reserved for
696 (Lisp_Object window
, Lisp_Object limit
)
700 CHECK_VALID_WINDOW (window
);
701 w
= XWINDOW (window
);
702 if (WINDOW_LEAF_P (w
))
703 error ("Combination limit is meaningful for internal windows only");
704 wset_combination_limit (w
, limit
);
708 DEFUN ("window-use-time", Fwindow_use_time
, Swindow_use_time
, 0, 1, 0,
709 doc
: /* Return the use time of window WINDOW.
710 WINDOW must be a live window and defaults to the selected one.
711 The window with the highest use time is the most recently selected
712 one. The window with the lowest use time is the least recently
716 return make_number (decode_live_window (window
)->use_time
);
719 DEFUN ("window-pixel-width", Fwindow_pixel_width
, Swindow_pixel_width
, 0, 1, 0,
720 doc
: /* Return the width of window WINDOW in pixels.
721 WINDOW must be a valid window and defaults to the selected one.
723 The return value includes the fringes and margins of WINDOW as well as
724 any vertical dividers or scroll bars belonging to WINDOW. If WINDOW is
725 an internal window, its pixel width is the width of the screen areas
726 spanned by its children. */)
729 return make_number (decode_valid_window (window
)->pixel_width
);
732 DEFUN ("window-pixel-height", Fwindow_pixel_height
, Swindow_pixel_height
, 0, 1, 0,
733 doc
: /* Return the height of window WINDOW in pixels.
734 WINDOW must be a valid window and defaults to the selected one.
736 The return value includes the mode line and header line and the bottom
737 divider, if any. If WINDOW is an internal window, its pixel height is
738 the height of the screen areas spanned by its children. */)
741 return make_number (decode_valid_window (window
)->pixel_height
);
744 DEFUN ("window-total-height", Fwindow_total_height
, Swindow_total_height
, 0, 2, 0,
745 doc
: /* Return the height of window WINDOW in lines.
746 WINDOW must be a valid window and defaults to the selected one.
748 The return value includes the heights of WINDOW's mode and header line
749 and its bottom divider, if any. If WINDOW is an internal window, the
750 total height is the height of the screen areas spanned by its children.
752 If WINDOW's pixel height is not an integral multiple of its frame's
753 character height, the number of lines occupied by WINDOW is rounded
754 internally. This is done in a way such that, if WINDOW is a parent
755 window, the sum of the total heights of all its children internally
756 equals the total height of WINDOW.
758 If the optional argument ROUND is `ceiling', return the smallest integer
759 larger than WINDOW's pixel height divided by the character height of
760 WINDOW's frame. ROUND `floor' means to return the largest integer
761 smaller than WINDOW's pixel height divided by the character height of
762 WINDOW's frame. Any other value of ROUND means to return the internal
763 total height of WINDOW. */)
764 (Lisp_Object window
, Lisp_Object round
)
766 struct window
*w
= decode_valid_window (window
);
768 if (! EQ (round
, Qfloor
) && ! EQ (round
, Qceiling
))
769 return make_number (w
->total_lines
);
772 int unit
= FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
));
774 return make_number (EQ (round
, Qceiling
)
775 ? ((w
->pixel_height
+ unit
- 1) /unit
)
776 : (w
->pixel_height
/ unit
));
780 DEFUN ("window-total-width", Fwindow_total_width
, Swindow_total_width
, 0, 2, 0,
781 doc
: /* Return the total width of window WINDOW in columns.
782 WINDOW must be a valid window and defaults to the selected one.
784 The return value includes the widths of WINDOW's fringes, margins,
785 scroll bars and its right divider, if any. If WINDOW is an internal
786 window, the total width is the width of the screen areas spanned by its
789 If WINDOW's pixel width is not an integral multiple of its frame's
790 character width, the number of lines occupied by WINDOW is rounded
791 internally. This is done in a way such that, if WINDOW is a parent
792 window, the sum of the total widths of all its children internally
793 equals the total width of WINDOW.
795 If the optional argument ROUND is `ceiling', return the smallest integer
796 larger than WINDOW's pixel width divided by the character width of
797 WINDOW's frame. ROUND `floor' means to return the largest integer
798 smaller than WINDOW's pixel width divided by the character width of
799 WINDOW's frame. Any other value of ROUND means to return the internal
800 total width of WINDOW. */)
801 (Lisp_Object window
, Lisp_Object round
)
803 struct window
*w
= decode_valid_window (window
);
805 if (! EQ (round
, Qfloor
) && ! EQ (round
, Qceiling
))
806 return make_number (w
->total_cols
);
809 int unit
= FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
));
811 return make_number (EQ (round
, Qceiling
)
812 ? ((w
->pixel_width
+ unit
- 1) /unit
)
813 : (w
->pixel_width
/ unit
));
817 DEFUN ("window-new-total", Fwindow_new_total
, Swindow_new_total
, 0, 1, 0,
818 doc
: /* Return the new total size of window WINDOW.
819 WINDOW must be a valid window and defaults to the selected one.
821 The new total size of WINDOW is the value set by the last call of
822 `set-window-new-total' for WINDOW. If it is valid, it will be shortly
823 installed as WINDOW's total height (see `window-total-height') or total
824 width (see `window-total-width'). */)
827 return decode_valid_window (window
)->new_total
;
830 DEFUN ("window-normal-size", Fwindow_normal_size
, Swindow_normal_size
, 0, 2, 0,
831 doc
: /* Return the normal height of window WINDOW.
832 WINDOW must be a valid window and defaults to the selected one.
833 If HORIZONTAL is non-nil, return the normal width of WINDOW.
835 The normal height of a frame's root window or a window that is
836 horizontally combined (a window that has a left or right sibling) is
837 1.0. The normal height of a window that is vertically combined (has a
838 sibling above or below) is the fraction of the window's height with
839 respect to its parent. The sum of the normal heights of all windows in a
840 vertical combination equals 1.0.
842 Similarly, the normal width of a frame's root window or a window that is
843 vertically combined equals 1.0. The normal width of a window that is
844 horizontally combined is the fraction of the window's width with respect
845 to its parent. The sum of the normal widths of all windows in a
846 horizontal combination equals 1.0.
848 The normal sizes of windows are used to restore the proportional sizes
849 of windows after they have been shrunk to their minimum sizes; for
850 example when a frame is temporarily made very small and afterwards gets
851 re-enlarged to its previous size. */)
852 (Lisp_Object window
, Lisp_Object horizontal
)
854 struct window
*w
= decode_valid_window (window
);
856 return NILP (horizontal
) ? w
->normal_lines
: w
->normal_cols
;
859 DEFUN ("window-new-normal", Fwindow_new_normal
, Swindow_new_normal
, 0, 1, 0,
860 doc
: /* Return new normal size of window WINDOW.
861 WINDOW must be a valid window and defaults to the selected one.
863 The new normal size of WINDOW is the value set by the last call of
864 `set-window-new-normal' for WINDOW. If valid, it will be shortly
865 installed as WINDOW's normal size (see `window-normal-size'). */)
868 return decode_valid_window (window
)->new_normal
;
871 DEFUN ("window-new-pixel", Fwindow_new_pixel
, Swindow_new_pixel
, 0, 1, 0,
872 doc
: /* Return new pixel size of window WINDOW.
873 WINDOW must be a valid window and defaults to the selected one.
875 The new pixel size of WINDOW is the value set by the last call of
876 `set-window-new-pixel' for WINDOW. If it is valid, it will be shortly
877 installed as WINDOW's pixel height (see `window-pixel-height') or pixel
878 width (see `window-pixel-width'). */)
881 return decode_valid_window (window
)->new_pixel
;
884 DEFUN ("window-pixel-left", Fwindow_pixel_left
, Swindow_pixel_left
, 0, 1, 0,
885 doc
: /* Return left pixel edge of window WINDOW.
886 WINDOW must be a valid window and defaults to the selected one. */)
889 return make_number (decode_valid_window (window
)->pixel_left
);
892 DEFUN ("window-pixel-top", Fwindow_pixel_top
, Swindow_pixel_top
, 0, 1, 0,
893 doc
: /* Return top pixel edge of window WINDOW.
894 WINDOW must be a valid window and defaults to the selected one. */)
897 return make_number (decode_valid_window (window
)->pixel_top
);
900 DEFUN ("window-left-column", Fwindow_left_column
, Swindow_left_column
, 0, 1, 0,
901 doc
: /* Return left column of window WINDOW.
902 This is the distance, in columns, between the left edge of WINDOW and
903 the left edge of the frame's window area. For instance, the return
904 value is 0 if there is no window to the left of WINDOW.
906 WINDOW must be a valid window and defaults to the selected one. */)
909 return make_number (decode_valid_window (window
)->left_col
);
912 DEFUN ("window-top-line", Fwindow_top_line
, Swindow_top_line
, 0, 1, 0,
913 doc
: /* Return top line of window WINDOW.
914 This is the distance, in lines, between the top of WINDOW and the top
915 of the frame's window area. For instance, the return value is 0 if
916 there is no window above WINDOW.
918 WINDOW must be a valid window and defaults to the selected one. */)
921 return make_number (decode_valid_window (window
)->top_line
);
924 /* Return the number of lines/pixels of W's body. Don't count any mode
925 or header line or horizontal divider of W. Rounds down to nearest
926 integer when not working pixelwise. */
928 window_body_height (struct window
*w
, bool pixelwise
)
930 int height
= (w
->pixel_height
931 - WINDOW_HEADER_LINE_HEIGHT (w
)
932 - (WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
)
933 ? WINDOW_SCROLL_BAR_AREA_HEIGHT (w
)
935 - WINDOW_MODE_LINE_HEIGHT (w
)
936 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
));
938 /* Don't return a negative value. */
939 return max (pixelwise
941 : height
/ FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
)),
945 /* Return the number of columns/pixels of W's body. Don't count columns
946 occupied by the scroll bar or the divider/vertical bar separating W
947 from its right sibling or margins. On window-systems don't count
948 fringes either. Round down to nearest integer when not working
951 window_body_width (struct window
*w
, bool pixelwise
)
953 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
955 int width
= (w
->pixel_width
956 - WINDOW_RIGHT_DIVIDER_WIDTH (w
)
957 - (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
958 ? WINDOW_SCROLL_BAR_AREA_WIDTH (w
)
959 : ((!FRAME_WINDOW_P (f
)
960 && !WINDOW_RIGHTMOST_P (w
)
961 && !WINDOW_RIGHT_DIVIDER_WIDTH (w
))
962 /* A vertical bar is either 1 or 0. */
964 - WINDOW_MARGINS_WIDTH (w
)
965 - (FRAME_WINDOW_P (f
)
966 ? WINDOW_FRINGES_WIDTH (w
)
969 /* Don't return a negative value. */
970 return max (pixelwise
972 : width
/ FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
)),
976 DEFUN ("window-body-height", Fwindow_body_height
, Swindow_body_height
, 0, 2, 0,
977 doc
: /* Return the height of WINDOW's text area.
978 WINDOW must be a live window and defaults to the selected one. Optional
979 argument PIXELWISE non-nil means return the height of WINDOW's text area
980 in pixels. The return value does not include the mode line or header
981 line or any horizontal divider.
983 If PIXELWISE is nil, return the largest integer smaller than WINDOW's
984 pixel height divided by the character height of WINDOW's frame. This
985 means that if a line at the bottom of the text area is only partially
986 visible, that line is not counted. */)
987 (Lisp_Object window
, Lisp_Object pixelwise
)
989 return make_number (window_body_height (decode_live_window (window
),
990 NILP (pixelwise
) ? 0 : 1));
993 DEFUN ("window-body-width", Fwindow_body_width
, Swindow_body_width
, 0, 2, 0,
994 doc
: /* Return the width of WINDOW's text area.
995 WINDOW must be a live window and defaults to the selected one. Optional
996 argument PIXELWISE non-nil means return the width in pixels. The return
997 value does not include any vertical dividers, fringes or marginal areas,
1000 If PIXELWISE is nil, return the largest integer smaller than WINDOW's
1001 pixel width divided by the character width of WINDOW's frame. This
1002 means that if a column at the right of the text area is only partially
1003 visible, that column is not counted. */)
1004 (Lisp_Object window
, Lisp_Object pixelwise
)
1006 return make_number (window_body_width (decode_live_window (window
),
1007 NILP (pixelwise
) ? 0 : 1));
1010 DEFUN ("window-mode-line-height", Fwindow_mode_line_height
,
1011 Swindow_mode_line_height
, 0, 1, 0,
1012 doc
: /* Return the height in pixels of WINDOW's mode-line.
1013 WINDOW must be a live window and defaults to the selected one. */)
1014 (Lisp_Object window
)
1016 return (make_number (WINDOW_MODE_LINE_HEIGHT (decode_live_window (window
))));
1019 DEFUN ("window-header-line-height", Fwindow_header_line_height
,
1020 Swindow_header_line_height
, 0, 1, 0,
1021 doc
: /* Return the height in pixels of WINDOW's header-line.
1022 WINDOW must be a live window and defaults to the selected one. */)
1023 (Lisp_Object window
)
1025 return (make_number (WINDOW_HEADER_LINE_HEIGHT (decode_live_window (window
))));
1028 DEFUN ("window-right-divider-width", Fwindow_right_divider_width
,
1029 Swindow_right_divider_width
, 0, 1, 0,
1030 doc
: /* Return the width in pixels of WINDOW's right divider.
1031 WINDOW must be a live window and defaults to the selected one. */)
1032 (Lisp_Object window
)
1034 return (make_number (WINDOW_RIGHT_DIVIDER_WIDTH (decode_live_window (window
))));
1037 DEFUN ("window-bottom-divider-width", Fwindow_bottom_divider_width
,
1038 Swindow_bottom_divider_width
, 0, 1, 0,
1039 doc
: /* Return the width in pixels of WINDOW's bottom divider.
1040 WINDOW must be a live window and defaults to the selected one. */)
1041 (Lisp_Object window
)
1043 return (make_number (WINDOW_BOTTOM_DIVIDER_WIDTH (decode_live_window (window
))));
1046 DEFUN ("window-scroll-bar-width", Fwindow_scroll_bar_width
,
1047 Swindow_scroll_bar_width
, 0, 1, 0,
1048 doc
: /* Return the width in pixels of WINDOW's vertical scrollbar.
1049 WINDOW must be a live window and defaults to the selected one. */)
1050 (Lisp_Object window
)
1052 return (make_number (WINDOW_SCROLL_BAR_AREA_WIDTH (decode_live_window (window
))));
1055 DEFUN ("window-scroll-bar-height", Fwindow_scroll_bar_height
,
1056 Swindow_scroll_bar_height
, 0, 1, 0,
1057 doc
: /* Return the height in pixels of WINDOW's horizontal scrollbar.
1058 WINDOW must be a live window and defaults to the selected one. */)
1059 (Lisp_Object window
)
1061 return (make_number (WINDOW_SCROLL_BAR_AREA_HEIGHT (decode_live_window (window
))));
1064 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
1065 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
1066 WINDOW must be a live window and defaults to the selected one. */)
1067 (Lisp_Object window
)
1069 return make_number (decode_live_window (window
)->hscroll
);
1072 /* Set W's horizontal scroll amount to HSCROLL clipped to a reasonable
1073 range, returning the new amount as a fixnum. */
1075 set_window_hscroll (struct window
*w
, EMACS_INT hscroll
)
1077 /* Horizontal scrolling has problems with large scroll amounts.
1078 It's too slow with long lines, and even with small lines the
1079 display can be messed up. For now, though, impose only the limits
1080 required by the internal representation: horizontal scrolling must
1081 fit in fixnum (since it's visible to Elisp) and into ptrdiff_t
1082 (since it's stored in a ptrdiff_t). */
1083 ptrdiff_t hscroll_max
= min (MOST_POSITIVE_FIXNUM
, PTRDIFF_MAX
);
1084 ptrdiff_t new_hscroll
= clip_to_bounds (0, hscroll
, hscroll_max
);
1086 /* Prevent redisplay shortcuts when changing the hscroll. */
1087 if (w
->hscroll
!= new_hscroll
)
1088 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
1090 w
->hscroll
= new_hscroll
;
1091 w
->suspend_auto_hscroll
= 1;
1093 return make_number (new_hscroll
);
1096 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
1097 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
1098 WINDOW must be a live window and defaults to the selected one.
1099 Clip the number to a reasonable value if out of range.
1100 Return the new number. NCOL should be zero or positive.
1102 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
1103 window so that the location of point moves off-window. */)
1104 (Lisp_Object window
, Lisp_Object ncol
)
1106 CHECK_NUMBER (ncol
);
1107 return set_window_hscroll (decode_live_window (window
), XINT (ncol
));
1110 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
1111 Swindow_redisplay_end_trigger
, 0, 1, 0,
1112 doc
: /* Return WINDOW's redisplay end trigger value.
1113 WINDOW must be a live window and defaults to the selected one.
1114 See `set-window-redisplay-end-trigger' for more information. */)
1115 (Lisp_Object window
)
1117 return decode_live_window (window
)->redisplay_end_trigger
;
1120 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
1121 Sset_window_redisplay_end_trigger
, 2, 2, 0,
1122 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
1123 WINDOW must be a live window and defaults to the selected one. VALUE
1124 should be a buffer position (typically a marker) or nil. If it is a
1125 buffer position, then if redisplay in WINDOW reaches a position beyond
1126 VALUE, the functions in `redisplay-end-trigger-functions' are called
1127 with two arguments: WINDOW, and the end trigger value. Afterwards the
1128 end-trigger value is reset to nil. */)
1129 (register Lisp_Object window
, Lisp_Object value
)
1131 wset_redisplay_end_trigger (decode_live_window (window
), value
);
1135 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
1136 doc
: /* Return a list of the edge coordinates of WINDOW.
1137 WINDOW must be a valid window and defaults to the selected one.
1139 The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
1140 count by lines, and LEFT and RIGHT count by columns, all relative to 0,
1141 0 at top left corner of frame.
1143 RIGHT is one more than the rightmost column occupied by WINDOW. BOTTOM
1144 is one more than the bottommost row occupied by WINDOW. The edges
1145 include the space used by WINDOW's scroll bar, display margins, fringes,
1146 header line, and/or mode line. For the edges of just the text area, use
1147 `window-inside-edges'. */)
1148 (Lisp_Object window
)
1150 register struct window
*w
= decode_valid_window (window
);
1152 return list4i (WINDOW_LEFT_EDGE_COL (w
), WINDOW_TOP_EDGE_LINE (w
),
1153 WINDOW_RIGHT_EDGE_COL (w
), WINDOW_BOTTOM_EDGE_LINE (w
));
1156 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
1157 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
1158 WINDOW must be a valid window and defaults to the selected one.
1160 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1161 0, 0 at the top left corner of the frame.
1163 RIGHT is one more than the rightmost x position occupied by WINDOW.
1164 BOTTOM is one more than the bottommost y position occupied by WINDOW.
1165 The pixel edges include the space used by WINDOW's scroll bar, display
1166 margins, fringes, header line, and/or mode line. For the pixel edges
1167 of just the text area, use `window-inside-pixel-edges'. */)
1168 (Lisp_Object window
)
1170 register struct window
*w
= decode_valid_window (window
);
1172 return list4i (WINDOW_LEFT_EDGE_X (w
), WINDOW_TOP_EDGE_Y (w
),
1173 WINDOW_RIGHT_EDGE_X (w
), WINDOW_BOTTOM_EDGE_Y (w
));
1177 calc_absolute_offset (struct window
*w
, int *add_x
, int *add_y
)
1179 struct frame
*f
= XFRAME (w
->frame
);
1180 *add_y
= f
->top_pos
;
1181 #ifdef FRAME_MENUBAR_HEIGHT
1182 *add_y
+= FRAME_MENUBAR_HEIGHT (f
);
1184 #ifdef FRAME_TOOLBAR_TOP_HEIGHT
1185 *add_y
+= FRAME_TOOLBAR_TOP_HEIGHT (f
);
1186 #elif defined (FRAME_TOOLBAR_HEIGHT)
1187 *add_y
+= FRAME_TOOLBAR_HEIGHT (f
);
1189 #ifdef FRAME_NS_TITLEBAR_HEIGHT
1190 *add_y
+= FRAME_NS_TITLEBAR_HEIGHT (f
);
1192 *add_x
= f
->left_pos
;
1193 #ifdef FRAME_TOOLBAR_LEFT_WIDTH
1194 *add_x
+= FRAME_TOOLBAR_LEFT_WIDTH (f
);
1198 DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges
,
1199 Swindow_absolute_pixel_edges
, 0, 1, 0,
1200 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
1201 WINDOW must be a valid window and defaults to the selected one.
1203 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1204 0, 0 at the top left corner of the display.
1206 RIGHT is one more than the rightmost x position occupied by WINDOW.
1207 BOTTOM is one more than the bottommost y position occupied by WINDOW.
1208 The pixel edges include the space used by WINDOW's scroll bar, display
1209 margins, fringes, header line, and/or mode line. For the pixel edges
1210 of just the text area, use `window-inside-absolute-pixel-edges'. */)
1211 (Lisp_Object window
)
1213 register struct window
*w
= decode_valid_window (window
);
1216 calc_absolute_offset (w
, &add_x
, &add_y
);
1218 return list4i (WINDOW_LEFT_EDGE_X (w
) + add_x
,
1219 WINDOW_TOP_EDGE_Y (w
) + add_y
,
1220 WINDOW_RIGHT_EDGE_X (w
) + add_x
,
1221 WINDOW_BOTTOM_EDGE_Y (w
) + add_y
);
1224 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
1225 doc
: /* Return a list of the edge coordinates of WINDOW.
1226 WINDOW must be a live window and defaults to the selected one.
1228 The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
1229 count by lines, and LEFT and RIGHT count by columns, all relative to 0,
1230 0 at top left corner of frame.
1232 RIGHT is one more than the rightmost column of WINDOW's text area.
1233 BOTTOM is one more than the bottommost row of WINDOW's text area. The
1234 inside edges do not include the space used by the WINDOW's scroll bar,
1235 display margins, fringes, header line, and/or mode line. */)
1236 (Lisp_Object window
)
1238 register struct window
*w
= decode_live_window (window
);
1240 return list4i ((WINDOW_BOX_LEFT_EDGE_COL (w
)
1241 + WINDOW_LEFT_MARGIN_COLS (w
)
1242 + ((WINDOW_LEFT_FRINGE_WIDTH (w
)
1243 + WINDOW_FRAME_COLUMN_WIDTH (w
) - 1)
1244 / WINDOW_FRAME_COLUMN_WIDTH (w
))),
1245 (WINDOW_TOP_EDGE_LINE (w
)
1246 + WINDOW_HEADER_LINE_LINES (w
)),
1247 (WINDOW_BOX_RIGHT_EDGE_COL (w
)
1248 - WINDOW_RIGHT_MARGIN_COLS (w
)
1249 - ((WINDOW_RIGHT_FRINGE_WIDTH (w
)
1250 + WINDOW_FRAME_COLUMN_WIDTH (w
) - 1)
1251 / WINDOW_FRAME_COLUMN_WIDTH (w
))),
1252 (WINDOW_BOTTOM_EDGE_LINE (w
)
1253 - WINDOW_MODE_LINE_LINES (w
)));
1256 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
1257 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1258 WINDOW must be a live window and defaults to the selected one.
1260 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1261 (0,0) at the top left corner of the frame's window area.
1263 RIGHT is one more than the rightmost x position of WINDOW's text area.
1264 BOTTOM is one more than the bottommost y position of WINDOW's text area.
1265 The inside edges do not include the space used by WINDOW's scroll bar,
1266 display margins, fringes, header line, and/or mode line. */)
1267 (Lisp_Object window
)
1269 register struct window
*w
= decode_live_window (window
);
1271 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w
)
1272 + WINDOW_LEFT_MARGIN_WIDTH (w
)
1273 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
1274 (WINDOW_TOP_EDGE_Y (w
)
1275 + WINDOW_HEADER_LINE_HEIGHT (w
)),
1276 (WINDOW_BOX_RIGHT_EDGE_X (w
)
1277 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
1278 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
1279 (WINDOW_BOTTOM_EDGE_Y (w
)
1280 - WINDOW_MODE_LINE_HEIGHT (w
)));
1283 DEFUN ("window-inside-absolute-pixel-edges",
1284 Fwindow_inside_absolute_pixel_edges
,
1285 Swindow_inside_absolute_pixel_edges
, 0, 1, 0,
1286 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1287 WINDOW must be a live window and defaults to the selected one.
1289 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1290 (0,0) at the top left corner of the frame's window area.
1292 RIGHT is one more than the rightmost x position of WINDOW's text area.
1293 BOTTOM is one more than the bottommost y position of WINDOW's text area.
1294 The inside edges do not include the space used by WINDOW's scroll bar,
1295 display margins, fringes, header line, and/or mode line. */)
1296 (Lisp_Object window
)
1298 register struct window
*w
= decode_live_window (window
);
1301 calc_absolute_offset (w
, &add_x
, &add_y
);
1303 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w
)
1304 + WINDOW_LEFT_MARGIN_WIDTH (w
)
1305 + WINDOW_LEFT_FRINGE_WIDTH (w
) + add_x
),
1306 (WINDOW_TOP_EDGE_Y (w
)
1307 + WINDOW_HEADER_LINE_HEIGHT (w
) + add_y
),
1308 (WINDOW_BOX_RIGHT_EDGE_X (w
)
1309 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
1310 - WINDOW_RIGHT_FRINGE_WIDTH (w
) + add_x
),
1311 (WINDOW_BOTTOM_EDGE_Y (w
)
1312 - WINDOW_MODE_LINE_HEIGHT (w
) + add_y
));
1315 /* Test if the character at column X, row Y is within window W.
1316 If it is not, return ON_NOTHING;
1317 if it is on the window's vertical divider, return
1319 if it is on the window's horizontal divider, return
1321 if it is in the window's text area, return ON_TEXT;
1322 if it is on the window's modeline, return ON_MODE_LINE;
1323 if it is on the border between the window and its right sibling,
1324 return ON_VERTICAL_BORDER;
1325 if it is on a scroll bar, return ON_SCROLL_BAR;
1326 if it is on the window's top line, return ON_HEADER_LINE;
1327 if it is in left or right fringe of the window,
1328 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
1329 if it is in the marginal area to the left/right of the window,
1330 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN.
1332 X and Y are frame relative pixel coordinates. */
1334 static enum window_part
1335 coordinates_in_window (register struct window
*w
, int x
, int y
)
1337 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1338 enum window_part part
;
1339 int ux
= FRAME_COLUMN_WIDTH (f
);
1340 int left_x
= WINDOW_LEFT_EDGE_X (w
);
1341 int right_x
= WINDOW_RIGHT_EDGE_X (w
);
1342 int top_y
= WINDOW_TOP_EDGE_Y (w
);
1343 int bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
1344 /* The width of the area where the vertical line can be dragged.
1345 (Between mode lines for instance. */
1346 int grabbable_width
= ux
;
1347 int lmargin_width
, rmargin_width
, text_left
, text_right
;
1349 /* Outside any interesting row or column? */
1350 if (y
< top_y
|| y
>= bottom_y
|| x
< left_x
|| x
>= right_x
)
1353 /* On the horizontal window divider (which prevails the vertical
1355 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
) > 0
1356 && y
>= (bottom_y
- WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
1358 return ON_BOTTOM_DIVIDER
;
1359 /* On vertical window divider? */
1360 else if (!WINDOW_RIGHTMOST_P (w
)
1361 && WINDOW_RIGHT_DIVIDER_WIDTH (w
) > 0
1362 && x
>= right_x
- WINDOW_RIGHT_DIVIDER_WIDTH (w
)
1364 return ON_RIGHT_DIVIDER
;
1365 /* On the horizontal scroll bar? (Including the empty space at its
1367 else if ((WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
)
1369 - WINDOW_SCROLL_BAR_AREA_HEIGHT (w
)
1370 - CURRENT_MODE_LINE_HEIGHT (w
)
1371 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
1373 - CURRENT_MODE_LINE_HEIGHT (w
)
1374 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
))))
1375 return ON_HORIZONTAL_SCROLL_BAR
;
1376 /* On the mode or header line? */
1377 else if ((WINDOW_WANTS_MODELINE_P (w
)
1379 - CURRENT_MODE_LINE_HEIGHT (w
)
1380 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
1381 && y
<= bottom_y
- WINDOW_BOTTOM_DIVIDER_WIDTH (w
)
1382 && (part
= ON_MODE_LINE
))
1383 || (WINDOW_WANTS_HEADER_LINE_P (w
)
1384 && y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
)
1385 && (part
= ON_HEADER_LINE
)))
1387 /* If it's under/over the scroll bar portion of the mode/header
1388 line, say it's on the vertical line. That's to be able to
1389 resize windows horizontally in case we're using toolkit scroll
1390 bars. Note: If scrollbars are on the left, the window that
1391 must be eventually resized is that on the left of WINDOW. */
1392 if ((WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0)
1393 && ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1394 && !WINDOW_LEFTMOST_P (w
)
1395 && eabs (x
- left_x
) < grabbable_width
)
1396 || (!WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1397 && !WINDOW_RIGHTMOST_P (w
)
1398 && eabs (x
- right_x
) < grabbable_width
)))
1399 return ON_VERTICAL_BORDER
;
1404 /* In what's below, we subtract 1 when computing right_x because we
1405 want the rightmost pixel, which is given by left_pixel+width-1. */
1406 if (w
->pseudo_window_p
)
1409 right_x
= WINDOW_PIXEL_WIDTH (w
) - 1;
1413 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
1414 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
1417 /* Outside any interesting column? */
1418 if (x
< left_x
|| x
> right_x
)
1419 return ON_VERTICAL_SCROLL_BAR
;
1421 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
1422 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
1424 text_left
= window_box_left (w
, TEXT_AREA
);
1425 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
1427 if (FRAME_WINDOW_P (f
))
1429 if (!w
->pseudo_window_p
1430 && WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0
1431 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
1432 && !WINDOW_RIGHTMOST_P (w
)
1433 && (eabs (x
- right_x
) < grabbable_width
))
1434 return ON_VERTICAL_BORDER
;
1436 /* Need to say "x > right_x" rather than >=, since on character
1437 terminals, the vertical line's x coordinate is right_x. */
1438 else if (!w
->pseudo_window_p
1439 && WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0
1440 && !WINDOW_RIGHTMOST_P (w
)
1441 /* Why check ux if we are not the rightmost window? Also
1442 shouldn't a pseudo window always be rightmost? */
1443 && x
> right_x
- ux
)
1444 return ON_VERTICAL_BORDER
;
1448 if (lmargin_width
> 0
1449 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1450 ? (x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
1451 : (x
< left_x
+ lmargin_width
)))
1452 return ON_LEFT_MARGIN
;
1454 return ON_LEFT_FRINGE
;
1457 if (x
>= text_right
)
1459 if (rmargin_width
> 0
1460 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1461 ? (x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
1462 : (x
>= right_x
- rmargin_width
)))
1463 return ON_RIGHT_MARGIN
;
1465 return ON_RIGHT_FRINGE
;
1468 /* Everything special ruled out - must be on text area */
1472 /* Take X is the frame-relative pixel x-coordinate, and return the
1473 x-coordinate relative to part PART of window W. */
1475 window_relative_x_coord (struct window
*w
, enum window_part part
, int x
)
1477 int left_x
= (w
->pseudo_window_p
) ? 0 : WINDOW_BOX_LEFT_EDGE_X (w
);
1482 return x
- window_box_left (w
, TEXT_AREA
);
1484 case ON_HEADER_LINE
:
1486 case ON_LEFT_FRINGE
:
1489 case ON_RIGHT_FRINGE
:
1490 return x
- left_x
- WINDOW_LEFT_FRINGE_WIDTH (w
);
1492 case ON_LEFT_MARGIN
:
1494 - ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1495 ? WINDOW_LEFT_FRINGE_WIDTH (w
) : 0));
1497 case ON_RIGHT_MARGIN
:
1499 - ((w
->pseudo_window_p
)
1500 ? WINDOW_PIXEL_WIDTH (w
)
1501 : WINDOW_BOX_RIGHT_EDGE_X (w
))
1502 + window_box_width (w
, RIGHT_MARGIN_AREA
)
1503 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1504 ? WINDOW_RIGHT_FRINGE_WIDTH (w
) : 0));
1507 /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */
1512 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
1513 Scoordinates_in_window_p
, 2, 2, 0,
1514 doc
: /* Return non-nil if COORDINATES are in WINDOW.
1515 WINDOW must be a live window and defaults to the selected one.
1516 COORDINATES is a cons of the form (X . Y), X and Y being distances
1517 measured in characters from the upper-left corner of the frame.
1518 \(0 . 0) denotes the character in the upper left corner of the
1520 If COORDINATES are in the text portion of WINDOW,
1521 the coordinates relative to the window are returned.
1522 If they are in the bottom divider of WINDOW, `bottom-divider' is returned.
1523 If they are in the right divider of WINDOW, `right-divider' is returned.
1524 If they are in the mode line of WINDOW, `mode-line' is returned.
1525 If they are in the header line of WINDOW, `header-line' is returned.
1526 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1527 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1528 If they are on the border between WINDOW and its right sibling,
1529 `vertical-line' is returned.
1530 If they are in the windows's left or right marginal areas, `left-margin'\n\
1531 or `right-margin' is returned. */)
1532 (register Lisp_Object coordinates
, Lisp_Object window
)
1539 w
= decode_live_window (window
);
1540 f
= XFRAME (w
->frame
);
1541 CHECK_CONS (coordinates
);
1542 lx
= Fcar (coordinates
);
1543 ly
= Fcdr (coordinates
);
1544 CHECK_NUMBER_OR_FLOAT (lx
);
1545 CHECK_NUMBER_OR_FLOAT (ly
);
1546 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1547 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1549 switch (coordinates_in_window (w
, x
, y
))
1555 /* Convert X and Y to window relative pixel coordinates, and
1556 return the canonical char units. */
1557 x
-= window_box_left (w
, TEXT_AREA
);
1558 y
-= WINDOW_TOP_EDGE_Y (w
);
1559 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
1560 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
1565 case ON_VERTICAL_BORDER
:
1566 return Qvertical_line
;
1568 case ON_HEADER_LINE
:
1569 return Qheader_line
;
1571 case ON_LEFT_FRINGE
:
1572 return Qleft_fringe
;
1574 case ON_RIGHT_FRINGE
:
1575 return Qright_fringe
;
1577 case ON_LEFT_MARGIN
:
1578 return Qleft_margin
;
1580 case ON_RIGHT_MARGIN
:
1581 return Qright_margin
;
1583 case ON_VERTICAL_SCROLL_BAR
:
1584 /* Historically we are supposed to return nil in this case. */
1587 case ON_HORIZONTAL_SCROLL_BAR
:
1590 case ON_RIGHT_DIVIDER
:
1591 return Qright_divider
;
1593 case ON_BOTTOM_DIVIDER
:
1594 return Qbottom_divider
;
1602 /* Callback for foreach_window, used in window_from_coordinates.
1603 Check if window W contains coordinates specified by USER_DATA which
1604 is actually a pointer to a struct check_window_data CW.
1606 Check if window W contains coordinates *CW->x and *CW->y. If it
1607 does, return W in *CW->window, as Lisp_Object, and return in
1608 *CW->part the part of the window under coordinates *X,*Y. Return
1609 zero from this function to stop iterating over windows. */
1611 struct check_window_data
1613 Lisp_Object
*window
;
1615 enum window_part
*part
;
1619 check_window_containing (struct window
*w
, void *user_data
)
1621 struct check_window_data
*cw
= user_data
;
1622 enum window_part found
;
1625 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1626 if (found
!= ON_NOTHING
)
1629 XSETWINDOW (*cw
->window
, w
);
1637 /* Find the window containing frame-relative pixel position X/Y and
1638 return it as a Lisp_Object.
1640 If X, Y is on one of the window's special `window_part' elements,
1641 set *PART to the id of that element.
1643 If there is no window under X, Y return nil and leave *PART
1644 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1646 This function was previously implemented with a loop cycling over
1647 windows with Fnext_window, and starting with the frame's selected
1648 window. It turned out that this doesn't work with an
1649 implementation of next_window using Vwindow_list, because
1650 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1651 tree of F when this function is called asynchronously from
1652 note_mouse_highlight. The original loop didn't terminate in this
1656 window_from_coordinates (struct frame
*f
, int x
, int y
,
1657 enum window_part
*part
, bool tool_bar_p
)
1660 struct check_window_data cw
;
1661 enum window_part dummy
;
1667 cw
.window
= &window
, cw
.x
= x
, cw
.y
= y
; cw
.part
= part
;
1668 foreach_window (f
, check_window_containing
, &cw
);
1670 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
1671 /* If not found above, see if it's in the tool bar window, if a tool
1675 && WINDOWP (f
->tool_bar_window
)
1676 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1677 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), x
, y
)
1681 window
= f
->tool_bar_window
;
1688 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1689 doc
: /* Return window containing coordinates X and Y on FRAME.
1690 FRAME must be a live frame and defaults to the selected one.
1691 The top left corner of the frame is considered to be row 0,
1693 (Lisp_Object x
, Lisp_Object y
, Lisp_Object frame
)
1695 struct frame
*f
= decode_live_frame (frame
);
1697 /* Check that arguments are integers or floats. */
1698 CHECK_NUMBER_OR_FLOAT (x
);
1699 CHECK_NUMBER_OR_FLOAT (y
);
1701 return window_from_coordinates (f
,
1702 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1703 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1704 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1705 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1709 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1710 doc
: /* Return current value of point in WINDOW.
1711 WINDOW must be a live window and defaults to the selected one.
1713 For a nonselected window, this is the value point would have if that
1714 window were selected.
1716 Note that, when WINDOW is selected, the value returned is the same as
1717 that returned by `point' for WINDOW's buffer. It would be more strictly
1718 correct to return the top-level value of `point', outside of any
1719 `save-excursion' forms. But that is hard to define. */)
1720 (Lisp_Object window
)
1722 register struct window
*w
= decode_live_window (window
);
1724 if (w
== XWINDOW (selected_window
))
1725 return make_number (BUF_PT (XBUFFER (w
->contents
)));
1727 return Fmarker_position (w
->pointm
);
1730 DEFUN ("window-old-point", Fwindow_old_point
, Swindow_old_point
, 0, 1, 0,
1731 doc
: /* Return old value of point in WINDOW.
1732 WINDOW must be a live window and defaults to the selected one. */)
1733 (Lisp_Object window
)
1735 return Fmarker_position (decode_live_window (window
)->old_pointm
);
1738 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1739 doc
: /* Return position at which display currently starts in WINDOW.
1740 WINDOW must be a live window and defaults to the selected one.
1741 This is updated by redisplay or by calling `set-window-start'. */)
1742 (Lisp_Object window
)
1744 return Fmarker_position (decode_live_window (window
)->start
);
1747 /* This is text temporarily removed from the doc string below.
1749 This function returns nil if the position is not currently known.
1750 That happens when redisplay is preempted and doesn't finish.
1751 If in that case you want to compute where the end of the window would
1752 have been if redisplay had finished, do this:
1754 (goto-char (window-start window))
1755 (vertical-motion (1- (window-height window)) window)
1758 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1759 doc
: /* Return position at which display currently ends in WINDOW.
1760 WINDOW must be a live window and defaults to the selected one.
1761 This is updated by redisplay, when it runs to completion.
1762 Simply changing the buffer text or setting `window-start'
1763 does not update this value.
1764 Return nil if there is no recorded value. (This can happen if the
1765 last redisplay of WINDOW was preempted, and did not finish.)
1766 If UPDATE is non-nil, compute the up-to-date position
1767 if it isn't already recorded. */)
1768 (Lisp_Object window
, Lisp_Object update
)
1771 struct window
*w
= decode_live_window (window
);
1780 && (windows_or_buffers_changed
1781 || !w
->window_end_valid
1783 || b
->prevent_redisplay_optimizations_p
1784 || window_outdated (w
))
1787 struct text_pos startp
;
1789 struct buffer
*old_buffer
= NULL
;
1790 void *itdata
= NULL
;
1792 /* Cannot use Fvertical_motion because that function doesn't
1793 cope with variable-height lines. */
1794 if (b
!= current_buffer
)
1796 old_buffer
= current_buffer
;
1797 set_buffer_internal (b
);
1800 /* In case W->start is out of the range, use something
1801 reasonable. This situation occurred when loading a file with
1802 `-l' containing a call to `rmail' with subsequent other
1803 commands. At the end, W->start happened to be BEG, while
1804 rmail had already narrowed the buffer. */
1805 CLIP_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1807 itdata
= bidi_shelve_cache ();
1808 start_display (&it
, w
, startp
);
1809 move_it_vertically (&it
, window_box_height (w
));
1810 if (it
.current_y
< it
.last_visible_y
)
1811 move_it_past_eol (&it
);
1812 value
= make_number (IT_CHARPOS (it
));
1813 bidi_unshelve_cache (itdata
, 0);
1816 set_buffer_internal (old_buffer
);
1819 XSETINT (value
, BUF_Z (b
) - w
->window_end_pos
);
1824 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1825 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1826 WINDOW must be a live window and defaults to the selected one.
1828 (Lisp_Object window
, Lisp_Object pos
)
1830 register struct window
*w
= decode_live_window (window
);
1832 /* Type of POS is checked by Fgoto_char or set_marker_restricted ... */
1834 if (w
== XWINDOW (selected_window
))
1836 if (XBUFFER (w
->contents
) == current_buffer
)
1840 struct buffer
*old_buffer
= current_buffer
;
1842 /* ... but here we want to catch type error before buffer change. */
1843 CHECK_NUMBER_COERCE_MARKER (pos
);
1844 set_buffer_internal (XBUFFER (w
->contents
));
1846 set_buffer_internal (old_buffer
);
1851 set_marker_restricted (w
->pointm
, pos
, w
->contents
);
1852 /* We have to make sure that redisplay updates the window to show
1853 the new value of point. */
1860 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1861 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1862 WINDOW must be a live window and defaults to the selected one. Return
1863 POS. Optional third arg NOFORCE non-nil inhibits next redisplay from
1864 overriding motion of point in order to display at this exact start. */)
1865 (Lisp_Object window
, Lisp_Object pos
, Lisp_Object noforce
)
1867 register struct window
*w
= decode_live_window (window
);
1869 set_marker_restricted (w
->start
, pos
, w
->contents
);
1870 /* This is not right, but much easier than doing what is right. */
1871 w
->start_at_line_beg
= 0;
1874 w
->update_mode_line
= 1;
1876 w
->window_end_valid
= 0;
1882 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
1883 Spos_visible_in_window_p
, 0, 3, 0,
1884 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
1885 WINDOW must be a live window and defaults to the selected one.
1887 Return nil if that position is scrolled vertically out of view. If a
1888 character is only partially visible, nil is returned, unless the
1889 optional argument PARTIALLY is non-nil. If POS is only out of view
1890 because of horizontal scrolling, return non-nil. If POS is t, it
1891 specifies the position of the last visible glyph in WINDOW. POS
1892 defaults to point in WINDOW; WINDOW defaults to the selected window.
1894 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1895 the return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
1896 where X and Y are the pixel coordinates relative to the top left corner
1897 of the window. The remaining elements are omitted if the character after
1898 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1899 off-window at the top and bottom of the screen line ("row") containing
1900 POS, ROWH is the visible height of that row, and VPOS is the row number
1902 (Lisp_Object pos
, Lisp_Object window
, Lisp_Object partially
)
1904 register struct window
*w
;
1905 register EMACS_INT posint
;
1906 register struct buffer
*buf
;
1907 struct text_pos top
;
1908 Lisp_Object in_window
= Qnil
;
1909 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
1912 w
= decode_live_window (window
);
1913 buf
= XBUFFER (w
->contents
);
1914 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1918 else if (!NILP (pos
))
1920 CHECK_NUMBER_COERCE_MARKER (pos
);
1921 posint
= XINT (pos
);
1923 else if (w
== XWINDOW (selected_window
))
1926 posint
= marker_position (w
->pointm
);
1928 /* If position is above window start or outside buffer boundaries,
1929 or if window start is out of range, position is not visible. */
1931 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
1932 && CHARPOS (top
) >= BUF_BEGV (buf
)
1933 && CHARPOS (top
) <= BUF_ZV (buf
)
1934 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
1935 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
1938 if (!NILP (in_window
) && !NILP (partially
))
1940 Lisp_Object part
= Qnil
;
1942 part
= list4i (rtop
, rbot
, rowh
, vpos
);
1943 in_window
= Fcons (make_number (x
),
1944 Fcons (make_number (y
), part
));
1950 DEFUN ("window-line-height", Fwindow_line_height
,
1951 Swindow_line_height
, 0, 2, 0,
1952 doc
: /* Return height in pixels of text line LINE in window WINDOW.
1953 WINDOW must be a live window and defaults to the selected one.
1955 Return height of current line if LINE is omitted or nil. Return height of
1956 header or mode line if LINE is `header-line' or `mode-line'.
1957 Otherwise, LINE is a text line number starting from 0. A negative number
1958 counts from the end of the window.
1960 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
1961 in pixels of the visible part of the line, VPOS and YPOS are the
1962 vertical position in lines and pixels of the line, relative to the top
1963 of the first text line, and OFFBOT is the number of off-window pixels at
1964 the bottom of the text line. If there are off-window pixels at the top
1965 of the (first) text line, YPOS is negative.
1967 Return nil if window display is not up-to-date. In that case, use
1968 `pos-visible-in-window-p' to obtain the information. */)
1969 (Lisp_Object line
, Lisp_Object window
)
1971 register struct window
*w
;
1972 register struct buffer
*b
;
1973 struct glyph_row
*row
, *end_row
;
1977 w
= decode_live_window (window
);
1979 if (noninteractive
|| w
->pseudo_window_p
)
1982 CHECK_BUFFER (w
->contents
);
1983 b
= XBUFFER (w
->contents
);
1985 /* Fail if current matrix is not up-to-date. */
1986 if (!w
->window_end_valid
1987 || windows_or_buffers_changed
1989 || b
->prevent_redisplay_optimizations_p
1990 || window_outdated (w
))
1996 if (i
< 0 || i
>= w
->current_matrix
->nrows
1997 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
1999 max_y
= window_text_bottom_y (w
);
2003 if (EQ (line
, Qheader_line
))
2005 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
2007 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
2008 return row
->enabled_p
? list4i (row
->height
, 0, 0, 0) : Qnil
;
2011 if (EQ (line
, Qmode_line
))
2013 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
2014 return (row
->enabled_p
?
2015 list4i (row
->height
,
2016 0, /* not accurate */
2017 (WINDOW_HEADER_LINE_HEIGHT (w
)
2018 + window_text_bottom_y (w
)),
2023 CHECK_NUMBER (line
);
2026 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2027 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2028 max_y
= window_text_bottom_y (w
);
2031 while ((n
< 0 || i
< n
)
2032 && row
<= end_row
&& row
->enabled_p
2033 && row
->y
+ row
->height
< max_y
)
2036 if (row
> end_row
|| !row
->enabled_p
)
2048 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
2049 return list4i (row
->height
+ min (0, row
->y
) - crop
, i
, row
->y
, crop
);
2052 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
2054 doc
: /* Return non-nil when WINDOW is dedicated to its buffer.
2055 More precisely, return the value assigned by the last call of
2056 `set-window-dedicated-p' for WINDOW. Return nil if that function was
2057 never called with WINDOW as its argument, or the value set by that
2058 function was internally reset since its last call. WINDOW must be a
2059 live window and defaults to the selected one.
2061 When a window is dedicated to its buffer, `display-buffer' will refrain
2062 from displaying another buffer in it. `get-lru-window' and
2063 `get-largest-window' treat dedicated windows specially.
2064 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
2065 `kill-buffer' can delete a dedicated window and the containing frame.
2067 Functions like `set-window-buffer' may change the buffer displayed by a
2068 window, unless that window is "strongly" dedicated to its buffer, that
2069 is the value returned by `window-dedicated-p' is t. */)
2070 (Lisp_Object window
)
2072 return decode_live_window (window
)->dedicated
;
2075 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
2076 Sset_window_dedicated_p
, 2, 2, 0,
2077 doc
: /* Mark WINDOW as dedicated according to FLAG.
2078 WINDOW must be a live window and defaults to the selected one. FLAG
2079 non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means
2080 mark WINDOW as non-dedicated. Return FLAG.
2082 When a window is dedicated to its buffer, `display-buffer' will refrain
2083 from displaying another buffer in it. `get-lru-window' and
2084 `get-largest-window' treat dedicated windows specially.
2085 `delete-windows-on', `replace-buffer-in-windows', `quit-window',
2086 `quit-restore-window' and `kill-buffer' can delete a dedicated window
2087 and the containing frame.
2089 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
2090 its buffer. Functions like `set-window-buffer' may change the buffer
2091 displayed by a window, unless that window is strongly dedicated to its
2092 buffer. If and when `set-window-buffer' displays another buffer in a
2093 window, it also makes sure that the window is no more dedicated. */)
2094 (Lisp_Object window
, Lisp_Object flag
)
2096 wset_dedicated (decode_live_window (window
), flag
);
2100 DEFUN ("window-prev-buffers", Fwindow_prev_buffers
, Swindow_prev_buffers
,
2102 doc
: /* Return buffers previously shown in WINDOW.
2103 WINDOW must be a live window and defaults to the selected one.
2105 The return value is a list of elements (BUFFER WINDOW-START POS),
2106 where BUFFER is a buffer, WINDOW-START is the start position of the
2107 window for that buffer, and POS is a window-specific point value. */)
2108 (Lisp_Object window
)
2110 return decode_live_window (window
)->prev_buffers
;
2113 DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers
,
2114 Sset_window_prev_buffers
, 2, 2, 0,
2115 doc
: /* Set WINDOW's previous buffers to PREV-BUFFERS.
2116 WINDOW must be a live window and defaults to the selected one.
2118 PREV-BUFFERS should be a list of elements (BUFFER WINDOW-START POS),
2119 where BUFFER is a buffer, WINDOW-START is the start position of the
2120 window for that buffer, and POS is a window-specific point value. */)
2121 (Lisp_Object window
, Lisp_Object prev_buffers
)
2123 wset_prev_buffers (decode_live_window (window
), prev_buffers
);
2124 return prev_buffers
;
2127 DEFUN ("window-next-buffers", Fwindow_next_buffers
, Swindow_next_buffers
,
2129 doc
: /* Return list of buffers recently re-shown in WINDOW.
2130 WINDOW must be a live window and defaults to the selected one. */)
2131 (Lisp_Object window
)
2133 return decode_live_window (window
)->next_buffers
;
2136 DEFUN ("set-window-next-buffers", Fset_window_next_buffers
,
2137 Sset_window_next_buffers
, 2, 2, 0,
2138 doc
: /* Set WINDOW's next buffers to NEXT-BUFFERS.
2139 WINDOW must be a live window and defaults to the selected one.
2140 NEXT-BUFFERS should be a list of buffers. */)
2141 (Lisp_Object window
, Lisp_Object next_buffers
)
2143 wset_next_buffers (decode_live_window (window
), next_buffers
);
2144 return next_buffers
;
2147 DEFUN ("window-parameters", Fwindow_parameters
, Swindow_parameters
,
2149 doc
: /* Return the parameters of WINDOW and their values.
2150 WINDOW must be a valid window and defaults to the selected one. The
2151 return value is a list of elements of the form (PARAMETER . VALUE). */)
2152 (Lisp_Object window
)
2154 return Fcopy_alist (decode_valid_window (window
)->window_parameters
);
2157 DEFUN ("window-parameter", Fwindow_parameter
, Swindow_parameter
,
2159 doc
: /* Return WINDOW's value for PARAMETER.
2160 WINDOW can be any window and defaults to the selected one. */)
2161 (Lisp_Object window
, Lisp_Object parameter
)
2165 result
= Fassq (parameter
, decode_any_window (window
)->window_parameters
);
2166 return CDR_SAFE (result
);
2169 DEFUN ("set-window-parameter", Fset_window_parameter
,
2170 Sset_window_parameter
, 3, 3, 0,
2171 doc
: /* Set WINDOW's value of PARAMETER to VALUE.
2172 WINDOW can be any window and defaults to the selected one.
2174 (Lisp_Object window
, Lisp_Object parameter
, Lisp_Object value
)
2176 register struct window
*w
= decode_any_window (window
);
2177 Lisp_Object old_alist_elt
;
2179 old_alist_elt
= Fassq (parameter
, w
->window_parameters
);
2180 if (NILP (old_alist_elt
))
2181 wset_window_parameters
2182 (w
, Fcons (Fcons (parameter
, value
), w
->window_parameters
));
2184 Fsetcdr (old_alist_elt
, value
);
2188 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
2190 doc
: /* Return the display-table that WINDOW is using.
2191 WINDOW must be a live window and defaults to the selected one. */)
2192 (Lisp_Object window
)
2194 return decode_live_window (window
)->display_table
;
2197 /* Get the display table for use on window W. This is either W's
2198 display table or W's buffer's display table. Ignore the specified
2199 tables if they are not valid; if no valid table is specified,
2202 struct Lisp_Char_Table
*
2203 window_display_table (struct window
*w
)
2205 struct Lisp_Char_Table
*dp
= NULL
;
2207 if (DISP_TABLE_P (w
->display_table
))
2208 dp
= XCHAR_TABLE (w
->display_table
);
2209 else if (BUFFERP (w
->contents
))
2211 struct buffer
*b
= XBUFFER (w
->contents
);
2213 if (DISP_TABLE_P (BVAR (b
, display_table
)))
2214 dp
= XCHAR_TABLE (BVAR (b
, display_table
));
2215 else if (DISP_TABLE_P (Vstandard_display_table
))
2216 dp
= XCHAR_TABLE (Vstandard_display_table
);
2222 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
2223 doc
: /* Set WINDOW's display-table to TABLE.
2224 WINDOW must be a live window and defaults to the selected one. */)
2225 (register Lisp_Object window
, Lisp_Object table
)
2227 wset_display_table (decode_live_window (window
), table
);
2231 /* Record info on buffer window W is displaying
2232 when it is about to cease to display that buffer. */
2234 unshow_buffer (register struct window
*w
)
2236 Lisp_Object buf
= w
->contents
;
2237 struct buffer
*b
= XBUFFER (buf
);
2239 eassert (b
== XMARKER (w
->pointm
)->buffer
);
2242 if (w
== XWINDOW (selected_window
)
2243 || ! EQ (buf
, XWINDOW (selected_window
)->contents
))
2244 /* Do this except when the selected window's buffer
2245 is being removed from some other window. */
2247 /* last_window_start records the start position that this buffer
2248 had in the last window to be disconnected from it.
2249 Now that this statement is unconditional,
2250 it is possible for the buffer to be displayed in the
2251 selected window, while last_window_start reflects another
2252 window which was recently showing the same buffer.
2253 Some people might say that might be a good thing. Let's see. */
2254 b
->last_window_start
= marker_position (w
->start
);
2256 /* Point in the selected window's buffer
2257 is actually stored in that buffer, and the window's pointm isn't used.
2258 So don't clobber point in that buffer. */
2259 if (! EQ (buf
, XWINDOW (selected_window
)->contents
)
2260 /* Don't clobber point in current buffer either (this could be
2261 useful in connection with bug#12208).
2262 && XBUFFER (buf) != current_buffer */
2263 /* This line helps to fix Horsley's testbug.el bug. */
2264 && !(WINDOWP (BVAR (b
, last_selected_window
))
2265 && w
!= XWINDOW (BVAR (b
, last_selected_window
))
2266 && EQ (buf
, XWINDOW (BVAR (b
, last_selected_window
))->contents
)))
2267 temp_set_point_both (b
,
2268 clip_to_bounds (BUF_BEGV (b
),
2269 marker_position (w
->pointm
),
2271 clip_to_bounds (BUF_BEGV_BYTE (b
),
2272 marker_byte_position (w
->pointm
),
2275 if (WINDOWP (BVAR (b
, last_selected_window
))
2276 && w
== XWINDOW (BVAR (b
, last_selected_window
)))
2277 bset_last_selected_window (b
, Qnil
);
2280 /* Put NEW into the window structure in place of OLD. SETFLAG zero
2281 means change window structure only. Otherwise store geometry and
2282 other settings as well. */
2284 replace_window (Lisp_Object old
, Lisp_Object
new, int setflag
)
2286 register Lisp_Object tem
;
2287 register struct window
*o
= XWINDOW (old
), *n
= XWINDOW (new);
2289 /* If OLD is its frame's root window, then NEW is the new
2290 root window for that frame. */
2291 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
2292 fset_root_window (XFRAME (o
->frame
), new);
2296 n
->pixel_left
= o
->pixel_left
;
2297 n
->pixel_top
= o
->pixel_top
;
2298 n
->pixel_width
= o
->pixel_width
;
2299 n
->pixel_height
= o
->pixel_height
;
2300 n
->left_col
= o
->left_col
;
2301 n
->top_line
= o
->top_line
;
2302 n
->total_cols
= o
->total_cols
;
2303 n
->total_lines
= o
->total_lines
;
2304 wset_normal_cols (n
, o
->normal_cols
);
2305 wset_normal_cols (o
, make_float (1.0));
2306 wset_normal_lines (n
, o
->normal_lines
);
2307 wset_normal_lines (o
, make_float (1.0));
2308 n
->desired_matrix
= n
->current_matrix
= 0;
2310 memset (&n
->cursor
, 0, sizeof (n
->cursor
));
2311 memset (&n
->phys_cursor
, 0, sizeof (n
->phys_cursor
));
2312 n
->last_cursor_vpos
= 0;
2313 #ifdef HAVE_WINDOW_SYSTEM
2314 n
->phys_cursor_type
= NO_CURSOR
;
2315 n
->phys_cursor_width
= -1;
2317 n
->must_be_updated_p
= 0;
2318 n
->pseudo_window_p
= 0;
2319 n
->window_end_vpos
= 0;
2320 n
->window_end_pos
= 0;
2321 n
->window_end_valid
= 0;
2327 wset_prev (XWINDOW (tem
), new);
2332 wset_next (XWINDOW (tem
), new);
2335 wset_parent (n
, tem
);
2336 if (!NILP (tem
) && EQ (XWINDOW (tem
)->contents
, old
))
2337 wset_combination (XWINDOW (tem
), XWINDOW (tem
)->horizontal
, new);
2340 /* If window WINDOW and its parent window are iso-combined, merge
2341 WINDOW's children into those of its parent window and mark WINDOW as
2345 recombine_windows (Lisp_Object window
)
2347 struct window
*w
, *p
, *c
;
2348 Lisp_Object parent
, child
;
2351 w
= XWINDOW (window
);
2353 if (!NILP (parent
) && NILP (w
->combination_limit
))
2355 p
= XWINDOW (parent
);
2356 if (WINDOWP (p
->contents
) && WINDOWP (w
->contents
)
2357 && p
->horizontal
== w
->horizontal
)
2358 /* WINDOW and PARENT are both either a vertical or a horizontal
2361 horflag
= WINDOW_HORIZONTAL_COMBINATION_P (w
);
2362 child
= w
->contents
;
2363 c
= XWINDOW (child
);
2365 /* Splice WINDOW's children into its parent's children and
2366 assign new normal sizes. */
2368 wset_combination (p
, horflag
, child
);
2371 wset_prev (c
, w
->prev
);
2372 wset_next (XWINDOW (w
->prev
), child
);
2377 wset_parent (c
, parent
);
2381 (c
, make_float ((double) c
->pixel_width
2382 / (double) p
->pixel_width
));
2385 (c
, make_float ((double) c
->pixel_height
2386 / (double) p
->pixel_height
));
2390 if (!NILP (w
->next
))
2392 wset_next (c
, w
->next
);
2393 wset_prev (XWINDOW (c
->next
), child
);
2401 c
= XWINDOW (child
);
2405 /* WINDOW can be deleted now. */
2406 wset_combination (w
, 0, Qnil
);
2411 /* If WINDOW can be deleted, delete it. */
2413 delete_deletable_window (Lisp_Object window
)
2415 if (!NILP (call1 (Qwindow_deletable_p
, window
)))
2416 call1 (Qdelete_window
, window
);
2419 /***********************************************************************
2421 ***********************************************************************/
2423 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
2424 pointer. This is a callback function for foreach_window, used in
2425 the window_list function. */
2428 add_window_to_list (struct window
*w
, void *user_data
)
2430 Lisp_Object
*list
= user_data
;
2432 XSETWINDOW (window
, w
);
2433 *list
= Fcons (window
, *list
);
2438 /* Return a list of all windows, for use by next_window. If
2439 Vwindow_list is a list, return that list. Otherwise, build a new
2440 list, cache it in Vwindow_list, and return that. */
2445 if (!CONSP (Vwindow_list
))
2447 Lisp_Object tail
, frame
;
2449 Vwindow_list
= Qnil
;
2450 FOR_EACH_FRAME (tail
, frame
)
2452 Lisp_Object args
[2];
2454 /* We are visiting windows in canonical order, and add
2455 new windows at the front of args[1], which means we
2456 have to reverse this list at the end. */
2458 foreach_window (XFRAME (frame
), add_window_to_list
, &args
[1]);
2459 args
[0] = Vwindow_list
;
2460 args
[1] = Fnreverse (args
[1]);
2461 Vwindow_list
= Fnconc (2, args
);
2465 return Vwindow_list
;
2469 /* Value is non-zero if WINDOW satisfies the constraints given by
2470 OWINDOW, MINIBUF and ALL_FRAMES.
2472 MINIBUF t means WINDOW may be minibuffer windows.
2473 `lambda' means WINDOW may not be a minibuffer window.
2474 a window means a specific minibuffer window
2476 ALL_FRAMES t means search all frames,
2477 nil means search just current frame,
2478 `visible' means search just visible frames on the
2480 0 means search visible and iconified frames on the
2482 a window means search the frame that window belongs to,
2483 a frame means consider windows on that frame, only. */
2486 candidate_window_p (Lisp_Object window
, Lisp_Object owindow
,
2487 Lisp_Object minibuf
, Lisp_Object all_frames
)
2489 struct window
*w
= XWINDOW (window
);
2490 struct frame
*f
= XFRAME (w
->frame
);
2491 bool candidate_p
= 1;
2493 if (!BUFFERP (w
->contents
))
2495 else if (MINI_WINDOW_P (w
)
2496 && (EQ (minibuf
, Qlambda
)
2497 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
2499 /* If MINIBUF is `lambda' don't consider any mini-windows.
2500 If it is a window, consider only that one. */
2503 else if (EQ (all_frames
, Qt
))
2505 else if (NILP (all_frames
))
2507 eassert (WINDOWP (owindow
));
2508 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
2510 else if (EQ (all_frames
, Qvisible
))
2512 candidate_p
= FRAME_VISIBLE_P (f
)
2513 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2514 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2517 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
2519 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
2520 #ifdef HAVE_X_WINDOWS
2521 /* Yuck!! If we've just created the frame and the
2522 window-manager requested the user to place it
2523 manually, the window may still not be considered
2524 `visible'. I'd argue it should be at least
2525 something like `iconified', but don't know how to do
2527 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
2528 && !f
->output_data
.x
->has_been_visible
)
2531 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2532 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2534 else if (WINDOWP (all_frames
))
2535 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
2536 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
2537 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
2538 else if (FRAMEP (all_frames
))
2539 candidate_p
= EQ (all_frames
, w
->frame
);
2545 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2546 Fwindow_list. See candidate_window_p for the meaning of WINDOW,
2547 MINIBUF, and ALL_FRAMES. */
2550 decode_next_window_args (Lisp_Object
*window
, Lisp_Object
*minibuf
, Lisp_Object
*all_frames
)
2552 struct window
*w
= decode_live_window (*window
);
2554 XSETWINDOW (*window
, w
);
2555 /* MINIBUF nil may or may not include minibuffers. Decide if it
2557 if (NILP (*minibuf
))
2558 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
2559 else if (!EQ (*minibuf
, Qt
))
2562 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2563 => count none of them, or a specific minibuffer window (the
2564 active one) to count. */
2566 /* ALL_FRAMES nil doesn't specify which frames to include. */
2567 if (NILP (*all_frames
))
2569 = (!EQ (*minibuf
, Qlambda
)
2570 ? FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
))
2572 else if (EQ (*all_frames
, Qvisible
))
2574 else if (EQ (*all_frames
, make_number (0)))
2576 else if (FRAMEP (*all_frames
))
2578 else if (!EQ (*all_frames
, Qt
))
2583 /* Return the next or previous window of WINDOW in cyclic ordering
2584 of windows. NEXT_P non-zero means return the next window. See the
2585 documentation string of next-window for the meaning of MINIBUF and
2589 next_window (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
, int next_p
)
2591 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2593 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2594 return the first window on the frame. */
2595 if (FRAMEP (all_frames
)
2596 && !EQ (all_frames
, XWINDOW (window
)->frame
))
2597 return Fframe_first_window (all_frames
);
2603 /* Find WINDOW in the list of all windows. */
2604 list
= Fmemq (window
, window_list ());
2606 /* Scan forward from WINDOW to the end of the window list. */
2608 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
2609 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2612 /* Scan from the start of the window list up to WINDOW. */
2614 for (list
= Vwindow_list
;
2615 CONSP (list
) && !EQ (XCAR (list
), window
);
2617 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2621 window
= XCAR (list
);
2625 Lisp_Object candidate
, list
;
2627 /* Scan through the list of windows for candidates. If there are
2628 candidate windows in front of WINDOW, the last one of these
2629 is the one we want. If there are candidates following WINDOW
2630 in the list, again the last one of these is the one we want. */
2632 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
2634 if (EQ (XCAR (list
), window
))
2636 if (WINDOWP (candidate
))
2639 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
2641 candidate
= XCAR (list
);
2644 if (WINDOWP (candidate
))
2652 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
2653 doc
: /* Return live window after WINDOW in the cyclic ordering of windows.
2654 WINDOW must be a live window and defaults to the selected one. The
2655 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2658 MINIBUF nil or omitted means consider the minibuffer window only if the
2659 minibuffer is active. MINIBUF t means consider the minibuffer window
2660 even if the minibuffer is not active. Any other value means do not
2661 consider the minibuffer window even if the minibuffer is active.
2663 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2664 plus the minibuffer window if specified by the MINIBUF argument. If the
2665 minibuffer counts, consider all windows on all frames that share that
2666 minibuffer too. The following non-nil values of ALL-FRAMES have special
2669 - t means consider all windows on all existing frames.
2671 - `visible' means consider all windows on all visible frames.
2673 - 0 (the number zero) means consider all windows on all visible and
2676 - A frame means consider all windows on that frame only.
2678 Anything else means consider all windows on WINDOW's frame and no
2681 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2682 `next-window' to iterate through the entire cycle of acceptable
2683 windows, eventually ending up back at the window you started with.
2684 `previous-window' traverses the same cycle, in the reverse order. */)
2685 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2687 return next_window (window
, minibuf
, all_frames
, 1);
2691 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
2692 doc
: /* Return live window before WINDOW in the cyclic ordering of windows.
2693 WINDOW must be a live window and defaults to the selected one. The
2694 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2697 MINIBUF nil or omitted means consider the minibuffer window only if the
2698 minibuffer is active. MINIBUF t means consider the minibuffer window
2699 even if the minibuffer is not active. Any other value means do not
2700 consider the minibuffer window even if the minibuffer is active.
2702 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2703 plus the minibuffer window if specified by the MINIBUF argument. If the
2704 minibuffer counts, consider all windows on all frames that share that
2705 minibuffer too. The following non-nil values of ALL-FRAMES have special
2708 - t means consider all windows on all existing frames.
2710 - `visible' means consider all windows on all visible frames.
2712 - 0 (the number zero) means consider all windows on all visible and
2715 - A frame means consider all windows on that frame only.
2717 Anything else means consider all windows on WINDOW's frame and no
2720 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2721 use `previous-window' to iterate through the entire cycle of
2722 acceptable windows, eventually ending up back at the window you
2723 started with. `next-window' traverses the same cycle, in the
2725 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2727 return next_window (window
, minibuf
, all_frames
, 0);
2731 /* Return a list of windows in cyclic ordering. Arguments are like
2732 for `next-window'. */
2735 window_list_1 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2737 Lisp_Object tail
, list
, rest
;
2739 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2742 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2743 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2744 list
= Fcons (XCAR (tail
), list
);
2746 /* Rotate the list to start with WINDOW. */
2747 list
= Fnreverse (list
);
2748 rest
= Fmemq (window
, list
);
2749 if (!NILP (rest
) && !EQ (rest
, list
))
2751 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2753 XSETCDR (tail
, Qnil
);
2754 list
= nconc2 (rest
, list
);
2760 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2761 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2762 FRAME nil or omitted means use the selected frame.
2763 WINDOW nil or omitted means use the window selected within FRAME.
2764 MINIBUF t means include the minibuffer window, even if it isn't active.
2765 MINIBUF nil or omitted means include the minibuffer window only
2767 MINIBUF neither nil nor t means never include the minibuffer window. */)
2768 (Lisp_Object frame
, Lisp_Object minibuf
, Lisp_Object window
)
2771 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2772 CHECK_WINDOW (window
);
2774 frame
= selected_frame
;
2776 if (!EQ (frame
, XWINDOW (window
)->frame
))
2777 error ("Window is on a different frame");
2779 return window_list_1 (window
, minibuf
, frame
);
2783 DEFUN ("window-list-1", Fwindow_list_1
, Swindow_list_1
, 0, 3, 0,
2784 doc
: /* Return a list of all live windows.
2785 WINDOW specifies the first window to list and defaults to the selected
2788 Optional argument MINIBUF nil or omitted means consider the minibuffer
2789 window only if the minibuffer is active. MINIBUF t means consider the
2790 minibuffer window even if the minibuffer is not active. Any other value
2791 means do not consider the minibuffer window even if the minibuffer is
2794 Optional argument ALL-FRAMES nil or omitted means consider all windows
2795 on WINDOW's frame, plus the minibuffer window if specified by the
2796 MINIBUF argument. If the minibuffer counts, consider all windows on all
2797 frames that share that minibuffer too. The following non-nil values of
2798 ALL-FRAMES have special meanings:
2800 - t means consider all windows on all existing frames.
2802 - `visible' means consider all windows on all visible frames.
2804 - 0 (the number zero) means consider all windows on all visible and
2807 - A frame means consider all windows on that frame only.
2809 Anything else means consider all windows on WINDOW's frame and no
2812 If WINDOW is not on the list of windows returned, some other window will
2813 be listed first but no error is signaled. */)
2814 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2816 return window_list_1 (window
, minibuf
, all_frames
);
2819 /* Look at all windows, performing an operation specified by TYPE
2821 If FRAMES is Qt, look at all frames;
2822 Qnil, look at just the selected frame;
2823 Qvisible, look at visible frames;
2824 a frame, just look at windows on that frame.
2825 If MINI is non-zero, perform the operation on minibuffer windows too. */
2830 GET_BUFFER_WINDOW
, /* Arg is buffer */
2831 REPLACE_BUFFER_IN_WINDOWS_SAFELY
, /* Arg is buffer */
2832 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2833 CHECK_ALL_WINDOWS
/* Arg is ignored */
2837 window_loop (enum window_loop type
, Lisp_Object obj
, int mini
, Lisp_Object frames
)
2839 Lisp_Object window
, windows
, best_window
, frame_arg
;
2840 int frame_best_window_flag
= 0;
2842 struct gcpro gcpro1
;
2844 /* If we're only looping through windows on a particular frame,
2845 frame points to that frame. If we're looping through windows
2846 on all frames, frame is 0. */
2847 if (FRAMEP (frames
))
2848 f
= XFRAME (frames
);
2849 else if (NILP (frames
))
2850 f
= SELECTED_FRAME ();
2855 frame_arg
= Qlambda
;
2856 else if (EQ (frames
, make_number (0)))
2858 else if (EQ (frames
, Qvisible
))
2863 /* frame_arg is Qlambda to stick to one frame,
2864 Qvisible to consider all visible frames,
2867 /* Pick a window to start with. */
2871 window
= FRAME_SELECTED_WINDOW (f
);
2873 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2875 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2879 for (; CONSP (windows
); windows
= XCDR (windows
))
2883 window
= XCAR (windows
);
2884 w
= XWINDOW (window
);
2886 /* Note that we do not pay attention here to whether the frame
2887 is visible, since Fwindow_list skips non-visible frames if
2888 that is desired, under the control of frame_arg. */
2889 if (!MINI_WINDOW_P (w
)
2890 /* For REPLACE_BUFFER_IN_WINDOWS_SAFELY, we must always
2891 consider all windows. */
2892 || type
== REPLACE_BUFFER_IN_WINDOWS_SAFELY
2893 || (mini
&& minibuf_level
> 0))
2896 case GET_BUFFER_WINDOW
:
2897 if (EQ (w
->contents
, obj
)
2898 /* Don't find any minibuffer window except the one that
2899 is currently in use. */
2900 && (MINI_WINDOW_P (w
) ? EQ (window
, minibuf_window
) : 1))
2902 if (EQ (window
, selected_window
))
2903 /* Preferably return the selected window. */
2904 RETURN_UNGCPRO (window
);
2905 else if (EQ (XWINDOW (window
)->frame
, selected_frame
)
2906 && !frame_best_window_flag
)
2907 /* Prefer windows on the current frame (but don't
2908 choose another one if we have one already). */
2910 best_window
= window
;
2911 frame_best_window_flag
= 1;
2913 else if (NILP (best_window
))
2914 best_window
= window
;
2918 case REPLACE_BUFFER_IN_WINDOWS_SAFELY
:
2919 /* We could simply check whether the buffer shown by window
2920 is live, and show another buffer in case it isn't. */
2921 if (EQ (w
->contents
, obj
))
2923 /* Undedicate WINDOW. */
2924 wset_dedicated (w
, Qnil
);
2925 /* Make WINDOW show the buffer returned by
2926 other_buffer_safely, don't run any hooks. */
2928 (window
, other_buffer_safely (w
->contents
), 0, 0);
2929 /* If WINDOW is the selected window, make its buffer
2930 current. But do so only if the window shows the
2931 current buffer (Bug#6454). */
2932 if (EQ (window
, selected_window
)
2933 && XBUFFER (w
->contents
) == current_buffer
)
2934 Fset_buffer (w
->contents
);
2938 case REDISPLAY_BUFFER_WINDOWS
:
2939 if (EQ (w
->contents
, obj
))
2941 mark_window_display_accurate (window
, 0);
2942 w
->update_mode_line
= 1;
2943 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2944 update_mode_lines
= 27;
2945 best_window
= window
;
2949 /* Check for a leaf window that has a killed buffer
2950 or broken markers. */
2951 case CHECK_ALL_WINDOWS
:
2952 if (BUFFERP (w
->contents
))
2954 struct buffer
*b
= XBUFFER (w
->contents
);
2956 if (!BUFFER_LIVE_P (b
))
2958 if (!MARKERP (w
->start
) || XMARKER (w
->start
)->buffer
!= b
)
2960 if (!MARKERP (w
->pointm
) || XMARKER (w
->pointm
)->buffer
!= b
)
2965 case WINDOW_LOOP_UNUSED
:
2974 /* Used for debugging. Abort if any window has a dead buffer. */
2976 extern void check_all_windows (void) EXTERNALLY_VISIBLE
;
2978 check_all_windows (void)
2980 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2983 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 0, 2, 0,
2984 doc
: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2985 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to
2988 The optional argument ALL-FRAMES specifies the frames to consider:
2990 - t means consider all windows on all existing frames.
2992 - `visible' means consider all windows on all visible frames.
2994 - 0 (the number zero) means consider all windows on all visible
2995 and iconified frames.
2997 - A frame means consider all windows on that frame only.
2999 Any other value of ALL-FRAMES means consider all windows on the
3000 selected frame and no others. */)
3001 (Lisp_Object buffer_or_name
, Lisp_Object all_frames
)
3005 if (NILP (buffer_or_name
))
3006 buffer
= Fcurrent_buffer ();
3008 buffer
= Fget_buffer (buffer_or_name
);
3010 if (BUFFERP (buffer
))
3011 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, all_frames
);
3018 resize_root_window (Lisp_Object window
, Lisp_Object delta
, Lisp_Object horizontal
, Lisp_Object ignore
, Lisp_Object pixelwise
)
3020 return call5 (Qwindow_resize_root_window
, window
, delta
, horizontal
, ignore
, pixelwise
);
3025 sanitize_window_sizes (Lisp_Object frame
, Lisp_Object horizontal
)
3027 return call2 (Qwindow_sanitize_window_sizes
, frame
, horizontal
);
3032 window_pixel_to_total (Lisp_Object frame
, Lisp_Object horizontal
)
3034 return call2 (Qwindow_pixel_to_total
, frame
, horizontal
);
3038 DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal
,
3039 Sdelete_other_windows_internal
, 0, 2, "",
3040 doc
: /* Make WINDOW fill its frame.
3041 Only the frame WINDOW is on is affected. WINDOW must be a valid window
3042 and defaults to the selected one.
3044 Optional argument ROOT, if non-nil, must specify an internal window such
3045 that WINDOW is in its window subtree. If this is the case, replace ROOT
3046 by WINDOW and leave alone any windows not part of ROOT's subtree.
3048 When WINDOW is live try to reduce display jumps by keeping the text
3049 previously visible in WINDOW in the same place on the frame. Doing this
3050 depends on the value of (window-start WINDOW), so if calling this
3051 function in a program gives strange scrolling, make sure the
3052 window-start value is reasonable when this function is called. */)
3053 (Lisp_Object window
, Lisp_Object root
)
3055 struct window
*w
, *r
, *s
;
3057 Lisp_Object sibling
, pwindow
, swindow
IF_LINT (= Qnil
), delta
;
3058 ptrdiff_t startpos
IF_LINT (= 0), startbyte
IF_LINT (= 0);
3059 int top
IF_LINT (= 0), new_top
, resize_failed
;
3061 w
= decode_valid_window (window
);
3062 XSETWINDOW (window
, w
);
3063 f
= XFRAME (w
->frame
);
3066 /* ROOT is the frame's root window. */
3068 root
= FRAME_ROOT_WINDOW (f
);
3072 /* ROOT must be an ancestor of WINDOW. */
3074 r
= decode_valid_window (root
);
3075 pwindow
= XWINDOW (window
)->parent
;
3076 while (!NILP (pwindow
))
3077 if (EQ (pwindow
, root
))
3080 pwindow
= XWINDOW (pwindow
)->parent
;
3081 if (!EQ (pwindow
, root
))
3082 error ("Specified root is not an ancestor of specified window");
3085 if (EQ (window
, root
))
3088 /* I don't understand the "top > 0" part below. If we deal with a
3089 standalone minibuffer it would have been caught by the preceding
3091 else if (MINI_WINDOW_P (w
)) /* && top > 0) */
3092 error ("Can't expand minibuffer to full frame");
3094 if (BUFFERP (w
->contents
))
3096 startpos
= marker_position (w
->start
);
3097 startbyte
= marker_byte_position (w
->start
);
3098 top
= (WINDOW_TOP_EDGE_LINE (w
)
3099 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
))));
3100 /* Make sure WINDOW is the frame's selected window. */
3101 if (!EQ (window
, FRAME_SELECTED_WINDOW (f
)))
3103 if (EQ (selected_frame
, w
->frame
))
3104 Fselect_window (window
, Qnil
);
3106 fset_selected_window (f
, window
);
3111 /* See if the frame's selected window is a part of the window
3112 subtree rooted at WINDOW, by finding all the selected window's
3113 parents and comparing each one with WINDOW. If it isn't we
3114 need a new selected window for this frame. */
3115 swindow
= FRAME_SELECTED_WINDOW (f
);
3119 while (!NILP (pwindow
) && !EQ (window
, pwindow
))
3120 pwindow
= XWINDOW (pwindow
)->parent
;
3122 if (EQ (window
, pwindow
))
3123 /* If WINDOW is an ancestor of SWINDOW, then SWINDOW is ok
3124 as the new selected window. */
3127 /* Else try the previous window of SWINDOW. */
3128 swindow
= Fprevious_window (swindow
, Qlambda
, Qnil
);
3131 if (!EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
3133 if (EQ (selected_frame
, w
->frame
))
3134 Fselect_window (swindow
, Qnil
);
3136 fset_selected_window (f
, swindow
);
3141 if (!FRAME_INITIAL_P (f
))
3143 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
3145 /* We are going to free the glyph matrices of WINDOW, and with
3146 that we might lose any information about glyph rows that have
3147 some of their glyphs highlighted in mouse face. (These rows
3148 are marked with a non-zero mouse_face_p flag.) If WINDOW
3149 indeed has some glyphs highlighted in mouse face, signal to
3150 frame's up-to-date hook that mouse highlight was overwritten,
3151 so that it will arrange for redisplaying the highlight. */
3152 if (EQ (hlinfo
->mouse_face_window
, window
))
3153 reset_mouse_highlight (hlinfo
);
3155 free_window_matrices (r
);
3158 Vwindow_list
= Qnil
;
3159 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3162 if (!WINDOW_LEAF_P (w
))
3164 /* Resize child windows vertically. */
3165 XSETINT (delta
, r
->pixel_height
- w
->pixel_height
);
3166 w
->pixel_top
= r
->pixel_top
;
3167 w
->top_line
= r
->top_line
;
3168 resize_root_window (window
, delta
, Qnil
, Qnil
, Qt
);
3169 if (window_resize_check (w
, 0))
3171 window_resize_apply (w
, 0);
3172 window_pixel_to_total (w
->frame
, Qnil
);
3176 resize_root_window (window
, delta
, Qnil
, Qt
, Qt
);
3177 if (window_resize_check (w
, 0))
3179 window_resize_apply (w
, 0);
3180 window_pixel_to_total (w
->frame
, Qnil
);
3186 /* Resize child windows horizontally. */
3189 w
->left_col
= r
->left_col
;
3190 w
->pixel_left
= r
->pixel_left
;
3191 XSETINT (delta
, r
->pixel_width
- w
->pixel_width
);
3192 resize_root_window (window
, delta
, Qt
, Qnil
, Qt
);
3193 if (window_resize_check (w
, 1))
3195 window_resize_apply (w
, 1);
3196 window_pixel_to_total (w
->frame
, Qt
);
3200 resize_root_window (window
, delta
, Qt
, Qt
, Qt
);
3201 if (window_resize_check (w
, 1))
3203 window_resize_apply (w
, 1);
3204 window_pixel_to_total (w
->frame
, Qt
);
3212 /* Play safe, if we still can ... */
3215 w
= XWINDOW (window
);
3219 /* Cleanly unlink WINDOW from window-tree. */
3220 if (!NILP (w
->prev
))
3221 /* Get SIBLING above (on the left of) WINDOW. */
3224 s
= XWINDOW (sibling
);
3225 wset_next (s
, w
->next
);
3226 if (!NILP (s
->next
))
3227 wset_prev (XWINDOW (s
->next
), sibling
);
3230 /* Get SIBLING below (on the right of) WINDOW. */
3233 s
= XWINDOW (sibling
);
3234 wset_prev (s
, Qnil
);
3235 wset_combination (XWINDOW (w
->parent
),
3236 XWINDOW (w
->parent
)->horizontal
, sibling
);
3239 /* Delete ROOT and all child windows of ROOT. */
3240 if (WINDOWP (r
->contents
))
3242 delete_all_child_windows (r
->contents
);
3243 wset_combination (r
, 0, Qnil
);
3246 replace_window (root
, window
, 1);
3248 /* This must become SWINDOW anyway ....... */
3249 if (BUFFERP (w
->contents
) && !resize_failed
)
3251 /* Try to minimize scrolling, by setting the window start to the
3252 point will cause the text at the old window start to be at the
3253 same place on the frame. But don't try to do this if the
3254 window start is outside the visible portion (as might happen
3255 when the display is not current, due to typeahead). */
3256 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
3258 && startpos
>= BUF_BEGV (XBUFFER (w
->contents
))
3259 && startpos
<= BUF_ZV (XBUFFER (w
->contents
)))
3261 struct position pos
;
3262 struct buffer
*obuf
= current_buffer
;
3264 Fset_buffer (w
->contents
);
3265 /* This computation used to temporarily move point, but that
3266 can have unwanted side effects due to text properties. */
3267 pos
= *vmotion (startpos
, startbyte
, -top
, w
);
3269 set_marker_both (w
->start
, w
->contents
, pos
.bufpos
, pos
.bytepos
);
3270 w
->window_end_valid
= 0;
3271 w
->start_at_line_beg
= (pos
.bytepos
== BEGV_BYTE
3272 || FETCH_BYTE (pos
.bytepos
- 1) == '\n');
3273 /* We need to do this, so that the window-scroll-functions
3275 w
->optional_new_start
= 1;
3277 set_buffer_internal (obuf
);
3281 adjust_frame_glyphs (f
);
3284 run_window_configuration_change_hook (f
);
3291 replace_buffer_in_windows (Lisp_Object buffer
)
3293 call1 (Qreplace_buffer_in_windows
, buffer
);
3296 /* If BUFFER is shown in a window, safely replace it with some other
3297 buffer in all windows of all frames, even those on other keyboards. */
3300 replace_buffer_in_windows_safely (Lisp_Object buffer
)
3302 if (buffer_window_count (XBUFFER (buffer
)))
3304 Lisp_Object tail
, frame
;
3306 /* A single call to window_loop won't do the job because it only
3307 considers frames on the current keyboard. So loop manually over
3308 frames, and handle each one. */
3309 FOR_EACH_FRAME (tail
, frame
)
3310 window_loop (REPLACE_BUFFER_IN_WINDOWS_SAFELY
, buffer
, 1, frame
);
3314 /* The following three routines are needed for running a window's
3315 configuration change hook. */
3317 run_funs (Lisp_Object funs
)
3319 for (; CONSP (funs
); funs
= XCDR (funs
))
3320 if (!EQ (XCAR (funs
), Qt
))
3321 call0 (XCAR (funs
));
3325 select_window_norecord (Lisp_Object window
)
3327 if (WINDOW_LIVE_P (window
))
3328 Fselect_window (window
, Qt
);
3332 select_frame_norecord (Lisp_Object frame
)
3334 if (FRAME_LIVE_P (XFRAME (frame
)))
3335 Fselect_frame (frame
, Qt
);
3339 run_window_configuration_change_hook (struct frame
*f
)
3341 ptrdiff_t count
= SPECPDL_INDEX ();
3342 Lisp_Object frame
, global_wcch
3343 = Fdefault_value (Qwindow_configuration_change_hook
);
3344 XSETFRAME (frame
, f
);
3346 if (NILP (Vrun_hooks
)
3347 || !(f
->can_x_set_window_size
)
3348 || !(f
->can_run_window_configuration_change_hook
))
3351 /* Use the right buffer. Matters when running the local hooks. */
3352 if (current_buffer
!= XBUFFER (Fwindow_buffer (Qnil
)))
3354 record_unwind_current_buffer ();
3355 Fset_buffer (Fwindow_buffer (Qnil
));
3358 if (SELECTED_FRAME () != f
)
3360 record_unwind_protect (select_frame_norecord
, selected_frame
);
3361 select_frame_norecord (frame
);
3364 /* Look for buffer-local values. */
3366 Lisp_Object windows
= Fwindow_list (frame
, Qlambda
, Qnil
);
3367 for (; CONSP (windows
); windows
= XCDR (windows
))
3369 Lisp_Object window
= XCAR (windows
);
3370 Lisp_Object buffer
= Fwindow_buffer (window
);
3371 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook
,
3374 ptrdiff_t inner_count
= SPECPDL_INDEX ();
3375 record_unwind_protect (select_window_norecord
, selected_window
);
3376 select_window_norecord (window
);
3377 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook
,
3379 unbind_to (inner_count
, Qnil
);
3384 run_funs (global_wcch
);
3385 unbind_to (count
, Qnil
);
3388 DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook
,
3389 Srun_window_configuration_change_hook
, 0, 1, 0,
3390 doc
: /* Run `window-configuration-change-hook' for FRAME.
3391 If FRAME is omitted or nil, it defaults to the selected frame. */)
3394 run_window_configuration_change_hook (decode_live_frame (frame
));
3398 DEFUN ("run-window-scroll-functions", Frun_window_scroll_functions
,
3399 Srun_window_scroll_functions
, 0, 1, 0,
3400 doc
: /* Run `window-scroll-functions' for WINDOW.
3401 If WINDOW is omitted or nil, it defaults to the selected window. */)
3402 (Lisp_Object window
)
3404 if (! NILP (Vwindow_scroll_functions
))
3405 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3406 Fmarker_position (decode_live_window (window
)->start
));
3410 /* Make WINDOW display BUFFER. RUN_HOOKS_P non-zero means it's allowed
3411 to run hooks. See make_frame for a case where it's not allowed.
3412 KEEP_MARGINS_P non-zero means that the current margins, fringes, and
3413 scroll-bar settings of the window are not reset from the buffer's
3417 set_window_buffer (Lisp_Object window
, Lisp_Object buffer
,
3418 bool run_hooks_p
, bool keep_margins_p
)
3420 struct window
*w
= XWINDOW (window
);
3421 struct buffer
*b
= XBUFFER (buffer
);
3422 ptrdiff_t count
= SPECPDL_INDEX ();
3423 bool samebuf
= EQ (buffer
, w
->contents
);
3425 wset_buffer (w
, buffer
);
3427 if (EQ (window
, selected_window
))
3428 bset_last_selected_window (b
, window
);
3430 /* Let redisplay errors through. */
3431 b
->display_error_modiff
= 0;
3433 /* Update time stamps of buffer display. */
3434 if (INTEGERP (BVAR (b
, display_count
)))
3435 bset_display_count (b
, make_number (XINT (BVAR (b
, display_count
)) + 1));
3436 bset_display_time (b
, Fcurrent_time ());
3438 w
->window_end_pos
= 0;
3439 w
->window_end_vpos
= 0;
3440 w
->last_cursor_vpos
= 0;
3442 if (!(keep_margins_p
&& samebuf
))
3443 { /* If we're not actually changing the buffer, don't reset hscroll
3444 and vscroll. This case happens for example when called from
3445 change_frame_size_1, where we use a dummy call to
3446 Fset_window_buffer on the frame's selected window (and no
3447 other) just in order to run window-configuration-change-hook
3448 (no longer true since change_frame_size_1 directly calls
3449 run_window_configuration_change_hook). Resetting hscroll and
3450 vscroll here is problematic for things like image-mode and
3451 doc-view-mode since it resets the image's position whenever we
3452 resize the frame. */
3453 w
->hscroll
= w
->min_hscroll
= w
->hscroll_whole
= 0;
3454 w
->suspend_auto_hscroll
= 0;
3456 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3457 set_marker_both (w
->old_pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3458 set_marker_restricted (w
->start
,
3459 make_number (b
->last_window_start
),
3461 w
->start_at_line_beg
= 0;
3464 /* Maybe we could move this into the `if' but it's not obviously safe and
3465 I doubt it's worth the trouble. */
3467 w
->update_mode_line
= true;
3469 /* We must select BUFFER to run the window-scroll-functions and to look up
3470 the buffer-local value of Vwindow_point_insertion_type. */
3471 record_unwind_current_buffer ();
3472 Fset_buffer (buffer
);
3474 XMARKER (w
->pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3475 XMARKER (w
->old_pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3477 if (!keep_margins_p
)
3479 /* Set left and right marginal area width etc. from buffer. */
3480 set_window_fringes (w
, BVAR (b
, left_fringe_width
),
3481 BVAR (b
, right_fringe_width
),
3482 BVAR (b
, fringes_outside_margins
));
3483 set_window_scroll_bars (w
, BVAR (b
, scroll_bar_width
),
3484 BVAR (b
, vertical_scroll_bar_type
),
3485 BVAR (b
, scroll_bar_height
),
3486 BVAR (b
, horizontal_scroll_bar_type
));
3487 set_window_margins (w
, BVAR (b
, left_margin_cols
),
3488 BVAR (b
, right_margin_cols
));
3489 apply_window_adjustment (w
);
3494 if (! NILP (Vwindow_scroll_functions
))
3495 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3496 Fmarker_position (w
->start
));
3498 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w
)));
3501 unbind_to (count
, Qnil
);
3504 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3505 doc
: /* Make WINDOW display BUFFER-OR-NAME.
3506 WINDOW must be a live window and defaults to the selected one.
3507 BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
3509 Optional third argument KEEP-MARGINS non-nil means that WINDOW's current
3510 display margins, fringe widths, and scroll bar settings are preserved;
3511 the default is to reset these from the local settings for BUFFER-OR-NAME
3512 or the frame defaults. Return nil.
3514 This function throws an error when WINDOW is strongly dedicated to its
3515 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3516 already display BUFFER-OR-NAME.
3518 This function runs `window-scroll-functions' before running
3519 `window-configuration-change-hook'. */)
3520 (register Lisp_Object window
, Lisp_Object buffer_or_name
, Lisp_Object keep_margins
)
3522 register Lisp_Object tem
, buffer
;
3523 register struct window
*w
= decode_live_window (window
);
3525 XSETWINDOW (window
, w
);
3526 buffer
= Fget_buffer (buffer_or_name
);
3527 CHECK_BUFFER (buffer
);
3528 if (!BUFFER_LIVE_P (XBUFFER (buffer
)))
3529 error ("Attempt to display deleted buffer");
3533 error ("Window is deleted");
3536 if (!EQ (tem
, buffer
))
3538 if (EQ (w
->dedicated
, Qt
))
3539 /* WINDOW is strongly dedicated to its buffer, signal an
3541 error ("Window is dedicated to `%s'", SDATA (BVAR (XBUFFER (tem
), name
)));
3543 /* WINDOW is weakly dedicated to its buffer, reset
3545 wset_dedicated (w
, Qnil
);
3547 call1 (Qrecord_window_buffer
, window
);
3553 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3559 display_buffer (Lisp_Object buffer
, Lisp_Object not_this_window_p
, Lisp_Object override_frame
)
3561 return call3 (Qdisplay_buffer
, buffer
, not_this_window_p
, override_frame
);
3564 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3566 doc
: /* Force all windows to be updated on next redisplay.
3567 If optional arg OBJECT is a window, force redisplay of that window only.
3568 If OBJECT is a buffer or buffer name, force redisplay of all windows
3569 displaying that buffer. */)
3570 (Lisp_Object object
)
3574 windows_or_buffers_changed
= 29;
3575 update_mode_lines
= 28;
3579 if (WINDOWP (object
))
3581 struct window
*w
= XWINDOW (object
);
3582 mark_window_display_accurate (object
, 0);
3583 w
->update_mode_line
= 1;
3584 if (BUFFERP (w
->contents
))
3585 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
3586 update_mode_lines
= 29;
3590 if (STRINGP (object
))
3591 object
= Fget_buffer (object
);
3592 if (BUFFERP (object
) && BUFFER_LIVE_P (XBUFFER (object
))
3593 && buffer_window_count (XBUFFER (object
)))
3595 /* If buffer is live and shown in at least one window, find
3596 all windows showing this buffer and force update of them. */
3597 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3598 return NILP (object
) ? Qnil
: Qt
;
3601 /* If nothing suitable was found, just return.
3602 We could signal an error, but this feature will typically be used
3603 asynchronously in timers or process sentinels, so we don't. */
3607 /* Obsolete since 24.3. */
3609 temp_output_buffer_show (register Lisp_Object buf
)
3611 register struct buffer
*old
= current_buffer
;
3612 register Lisp_Object window
;
3613 register struct window
*w
;
3615 bset_directory (XBUFFER (buf
), BVAR (current_buffer
, directory
));
3618 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3622 set_buffer_internal (old
);
3624 if (!NILP (Vtemp_buffer_show_function
))
3625 call1 (Vtemp_buffer_show_function
, buf
);
3626 else if (WINDOW_LIVE_P (window
= display_buffer (buf
, Qnil
, Qnil
)))
3628 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3629 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3630 Vminibuf_scroll_window
= window
;
3631 w
= XWINDOW (window
);
3632 w
->hscroll
= w
->min_hscroll
= w
->hscroll_whole
= 0;
3633 w
->suspend_auto_hscroll
= 0;
3634 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3635 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3636 set_marker_restricted_both (w
->old_pointm
, buf
, BEG
, BEG
);
3638 /* Run temp-buffer-show-hook, with the chosen window selected
3639 and its buffer current. */
3641 ptrdiff_t count
= SPECPDL_INDEX ();
3642 Lisp_Object prev_window
, prev_buffer
;
3643 prev_window
= selected_window
;
3644 XSETBUFFER (prev_buffer
, old
);
3646 /* Select the window that was chosen, for running the hook.
3647 Note: Both Fselect_window and select_window_norecord may
3648 set-buffer to the buffer displayed in the window,
3649 so we need to save the current buffer. --stef */
3650 record_unwind_protect (restore_buffer
, prev_buffer
);
3651 record_unwind_protect (select_window_norecord
, prev_window
);
3652 Fselect_window (window
, Qt
);
3653 Fset_buffer (w
->contents
);
3654 Frun_hooks (1, &Qtemp_buffer_show_hook
);
3655 unbind_to (count
, Qnil
);
3660 /* Make new window, have it replace WINDOW in window-tree, and make
3661 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
3662 horizontal child). */
3664 make_parent_window (Lisp_Object window
, bool horflag
)
3667 register struct window
*o
, *p
;
3669 o
= XWINDOW (window
);
3670 p
= allocate_window ();
3671 memcpy ((char *) p
+ sizeof (struct vectorlike_header
),
3672 (char *) o
+ sizeof (struct vectorlike_header
),
3673 word_size
* VECSIZE (struct window
));
3674 /* P's buffer slot may change from nil to a buffer... */
3675 adjust_window_count (p
, 1);
3676 XSETWINDOW (parent
, p
);
3678 p
->sequence_number
= ++sequence_number
;
3680 replace_window (window
, parent
, 1);
3682 wset_next (o
, Qnil
);
3683 wset_prev (o
, Qnil
);
3684 wset_parent (o
, parent
);
3685 /* ...but now P becomes an internal window. */
3686 wset_start (p
, Qnil
);
3687 wset_pointm (p
, Qnil
);
3688 wset_old_pointm (p
, Qnil
);
3689 wset_buffer (p
, Qnil
);
3690 wset_combination (p
, horflag
, window
);
3691 wset_combination_limit (p
, Qnil
);
3692 wset_window_parameters (p
, Qnil
);
3695 /* Make new window from scratch. */
3700 register struct window
*w
;
3702 w
= allocate_window ();
3703 /* Initialize Lisp data. Note that allocate_window initializes all
3704 Lisp data to nil, so do it only for slots which should not be nil. */
3705 wset_normal_lines (w
, make_float (1.0));
3706 wset_normal_cols (w
, make_float (1.0));
3707 wset_new_total (w
, make_number (0));
3708 wset_new_normal (w
, make_number (0));
3709 wset_new_pixel (w
, make_number (0));
3710 wset_start (w
, Fmake_marker ());
3711 wset_pointm (w
, Fmake_marker ());
3712 wset_old_pointm (w
, Fmake_marker ());
3713 wset_vertical_scroll_bar_type (w
, Qt
);
3714 wset_horizontal_scroll_bar_type (w
, Qt
);
3715 /* These Lisp fields are marked specially so they're not set to nil by
3717 wset_prev_buffers (w
, Qnil
);
3718 wset_next_buffers (w
, Qnil
);
3720 /* Initialize non-Lisp data. Note that allocate_window zeroes out all
3721 non-Lisp data, so do it only for slots which should not be zero. */
3722 w
->nrows_scale_factor
= w
->ncols_scale_factor
= 1;
3723 w
->left_fringe_width
= w
->right_fringe_width
= -1;
3724 w
->mode_line_height
= w
->header_line_height
= -1;
3725 #ifdef HAVE_WINDOW_SYSTEM
3726 w
->phys_cursor_type
= NO_CURSOR
;
3727 w
->phys_cursor_width
= -1;
3729 w
->sequence_number
= ++sequence_number
;
3730 w
->scroll_bar_width
= -1;
3731 w
->scroll_bar_height
= -1;
3732 w
->column_number_displayed
= -1;
3733 /* Reset window_list. */
3734 Vwindow_list
= Qnil
;
3735 /* Return window. */
3736 XSETWINDOW (window
, w
);
3740 DEFUN ("set-window-new-pixel", Fset_window_new_pixel
, Sset_window_new_pixel
, 2, 3, 0,
3741 doc
: /* Set new pixel size of WINDOW to SIZE.
3742 WINDOW must be a valid window and defaults to the selected one.
3745 Optional argument ADD non-nil means add SIZE to the new pixel size of
3746 WINDOW and return the sum.
3748 The new pixel size of WINDOW, if valid, will be shortly installed as
3749 WINDOW's pixel height (see `window-pixel-height') or pixel width (see
3750 `window-pixel-width').
3752 Note: This function does not operate on any child windows of WINDOW. */)
3753 (Lisp_Object window
, Lisp_Object size
, Lisp_Object add
)
3755 struct window
*w
= decode_valid_window (window
);
3756 EMACS_INT size_min
= NILP (add
) ? 0 : - XINT (w
->new_pixel
);
3757 EMACS_INT size_max
= size_min
+ min (INT_MAX
, MOST_POSITIVE_FIXNUM
);
3759 CHECK_RANGED_INTEGER (size
, size_min
, size_max
);
3761 wset_new_pixel (w
, size
);
3763 wset_new_pixel (w
, make_number (XINT (w
->new_pixel
) + XINT (size
)));
3765 return w
->new_pixel
;
3768 DEFUN ("set-window-new-total", Fset_window_new_total
, Sset_window_new_total
, 2, 3, 0,
3769 doc
: /* Set new total size of WINDOW to SIZE.
3770 WINDOW must be a valid window and defaults to the selected one.
3773 Optional argument ADD non-nil means add SIZE to the new total size of
3774 WINDOW and return the sum.
3776 The new total size of WINDOW, if valid, will be shortly installed as
3777 WINDOW's total height (see `window-total-height') or total width (see
3778 `window-total-width').
3780 Note: This function does not operate on any child windows of WINDOW. */)
3781 (Lisp_Object window
, Lisp_Object size
, Lisp_Object add
)
3783 struct window
*w
= decode_valid_window (window
);
3785 CHECK_NUMBER (size
);
3787 wset_new_total (w
, size
);
3789 wset_new_total (w
, make_number (XINT (w
->new_total
) + XINT (size
)));
3791 return w
->new_total
;
3794 DEFUN ("set-window-new-normal", Fset_window_new_normal
, Sset_window_new_normal
, 1, 2, 0,
3795 doc
: /* Set new normal size of WINDOW to SIZE.
3796 WINDOW must be a valid window and defaults to the selected one.
3799 The new normal size of WINDOW, if valid, will be shortly installed as
3800 WINDOW's normal size (see `window-normal-size').
3802 Note: This function does not operate on any child windows of WINDOW. */)
3803 (Lisp_Object window
, Lisp_Object size
)
3805 wset_new_normal (decode_valid_window (window
), size
);
3809 /* Return 1 if setting w->pixel_height (w->pixel_width if HORFLAG is
3810 non-zero) to w->new_pixel would result in correct heights (widths)
3811 for window W and recursively all child windows of W.
3813 Note: This function does not check any of `window-fixed-size-p',
3814 `window-min-height' or `window-min-width'. It does check that window
3815 sizes do not drop below one line (two columns). */
3817 window_resize_check (struct window
*w
, bool horflag
)
3819 struct frame
*f
= XFRAME (w
->frame
);
3822 if (WINDOW_VERTICAL_COMBINATION_P (w
))
3823 /* W is a vertical combination. */
3825 c
= XWINDOW (w
->contents
);
3827 /* All child windows of W must have the same width as W. */
3831 if (XINT (c
->new_pixel
) != XINT (w
->new_pixel
)
3832 || !window_resize_check (c
, horflag
))
3835 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3841 /* The sum of the heights of the child windows of W must equal
3844 int remaining_pixels
= XINT (w
->new_pixel
);
3848 if (!window_resize_check (c
, horflag
))
3851 remaining_pixels
-= XINT (c
->new_pixel
);
3852 if (remaining_pixels
< 0)
3854 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3857 return remaining_pixels
== 0;
3860 else if (WINDOW_HORIZONTAL_COMBINATION_P (w
))
3861 /* W is a horizontal combination. */
3863 c
= XWINDOW (w
->contents
);
3865 /* The sum of the widths of the child windows of W must equal W's
3868 int remaining_pixels
= XINT (w
->new_pixel
);
3872 if (!window_resize_check (c
, horflag
))
3875 remaining_pixels
-= XINT (c
->new_pixel
);
3876 if (remaining_pixels
< 0)
3878 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3881 return remaining_pixels
== 0;
3884 /* All child windows of W must have the same height as W. */
3888 if (XINT (c
->new_pixel
) != XINT (w
->new_pixel
)
3889 || !window_resize_check (c
, horflag
))
3892 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3899 /* A leaf window. Make sure it's not too small. The following
3900 hardcodes the values of `window-safe-min-width' (2) and
3901 `window-safe-min-height' (1) which are defined in window.el. */
3902 return (XINT (w
->new_pixel
) >= (horflag
3903 ? (2 * FRAME_COLUMN_WIDTH (f
))
3904 : FRAME_LINE_HEIGHT (f
)));
3908 /* Set w->pixel_height (w->pixel_width if HORFLAG is non-zero) to
3909 w->new_pixel for window W and recursively all child windows of W.
3910 Also calculate and assign the new vertical (horizontal) pixel start
3911 positions of each of these windows.
3913 This function does not perform any error checks. Make sure you have
3914 run window_resize_check on W before applying this function. */
3916 window_resize_apply (struct window
*w
, bool horflag
)
3921 ? FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
))
3922 : FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
)));
3924 /* Note: Assigning new_normal requires that the new total size of the
3925 parent window has been set *before*. */
3928 w
->pixel_width
= XFASTINT (w
->new_pixel
);
3929 w
->total_cols
= w
->pixel_width
/ unit
;
3930 if (NUMBERP (w
->new_normal
))
3931 wset_normal_cols (w
, w
->new_normal
);
3933 edge
= w
->pixel_left
;
3937 w
->pixel_height
= XFASTINT (w
->new_pixel
);
3938 w
->total_lines
= w
->pixel_height
/ unit
;
3939 if (NUMBERP (w
->new_normal
))
3940 wset_normal_lines (w
, w
->new_normal
);
3942 edge
= w
->pixel_top
;
3945 if (WINDOW_VERTICAL_COMBINATION_P (w
))
3946 /* W is a vertical combination. */
3948 c
= XWINDOW (w
->contents
);
3953 c
->pixel_left
= edge
;
3954 c
->left_col
= edge
/ unit
;
3958 c
->pixel_top
= edge
;
3959 c
->top_line
= edge
/ unit
;
3961 window_resize_apply (c
, horflag
);
3963 edge
= edge
+ c
->pixel_height
;
3965 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3968 else if (WINDOW_HORIZONTAL_COMBINATION_P (w
))
3969 /* W is a horizontal combination. */
3971 c
= XWINDOW (w
->contents
);
3976 c
->pixel_left
= edge
;
3977 c
->left_col
= edge
/ unit
;
3981 c
->pixel_top
= edge
;
3982 c
->top_line
= edge
/ unit
;
3985 window_resize_apply (c
, horflag
);
3987 edge
= edge
+ c
->pixel_width
;
3989 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3994 w
->window_end_valid
= 0;
3998 /* Set w->total_lines (w->total_cols if HORFLAG is non-zero) to
3999 w->new_total for window W and recursively all child windows of W.
4000 Also calculate and assign the new vertical (horizontal) start
4001 positions of each of these windows. */
4003 window_resize_apply_total (struct window
*w
, bool horflag
)
4008 /* Note: Assigning new_normal requires that the new total size of the
4009 parent window has been set *before*. */
4012 w
->total_cols
= XFASTINT (w
->new_total
);
4017 w
->total_lines
= XFASTINT (w
->new_total
);
4021 if (WINDOW_VERTICAL_COMBINATION_P (w
))
4022 /* W is a vertical combination. */
4024 c
= XWINDOW (w
->contents
);
4032 window_resize_apply_total (c
, horflag
);
4034 edge
= edge
+ c
->total_lines
;
4036 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4039 else if (WINDOW_HORIZONTAL_COMBINATION_P (w
))
4040 /* W is a horizontal combination. */
4042 c
= XWINDOW (w
->contents
);
4050 window_resize_apply_total (c
, horflag
);
4052 edge
= edge
+ c
->total_cols
;
4054 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4059 DEFUN ("window-resize-apply", Fwindow_resize_apply
, Swindow_resize_apply
, 0, 2, 0,
4060 doc
: /* Apply requested size values for window-tree of FRAME.
4061 If FRAME is omitted or nil, it defaults to the selected frame.
4063 Optional argument HORIZONTAL omitted or nil means apply requested
4064 height values. HORIZONTAL non-nil means apply requested width values.
4066 The requested size values are those set by `set-window-new-pixel' and
4067 `set-window-new-normal'. This function checks whether the requested
4068 values sum up to a valid window layout, recursively assigns the new
4069 sizes of all child windows and calculates and assigns the new start
4070 positions of these windows.
4072 Return t if the requested values have been applied correctly, nil
4075 Note: This function does not check any of `window-fixed-size-p',
4076 `window-min-height' or `window-min-width'. All these checks have to
4077 be applied on the Elisp level. */)
4078 (Lisp_Object frame
, Lisp_Object horizontal
)
4080 struct frame
*f
= decode_live_frame (frame
);
4081 struct window
*r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4082 bool horflag
= !NILP (horizontal
);
4084 if (!window_resize_check (r
, horflag
)
4085 || (XINT (r
->new_pixel
)
4086 != (horflag
? r
->pixel_width
: r
->pixel_height
)))
4090 window_resize_apply (r
, horflag
);
4093 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4095 adjust_frame_glyphs (f
);
4102 DEFUN ("window-resize-apply-total", Fwindow_resize_apply_total
, Swindow_resize_apply_total
, 0, 2, 0,
4103 doc
: /* Apply requested total size values for window-tree of FRAME.
4104 If FRAME is omitted or nil, it defaults to the selected frame.
4106 This function does not assign pixel or normal size values. You should
4107 have run `window-resize-apply' before running this.
4109 Optional argument HORIZONTAL omitted or nil means apply requested
4110 height values. HORIZONTAL non-nil means apply requested width
4112 (Lisp_Object frame
, Lisp_Object horizontal
)
4114 struct frame
*f
= decode_live_frame (frame
);
4115 struct window
*r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4118 /* Necessary when deleting the top-/or leftmost window. */
4120 r
->top_line
= FRAME_TOP_MARGIN (f
);
4121 window_resize_apply_total (r
, !NILP (horizontal
));
4122 /* Handle the mini window. */
4123 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
4125 struct window
*m
= XWINDOW (f
->minibuffer_window
);
4127 if (NILP (horizontal
))
4129 m
->top_line
= r
->top_line
+ r
->total_lines
;
4130 m
->total_lines
= XFASTINT (m
->new_total
);
4133 m
->total_cols
= XFASTINT (m
->new_total
);
4142 /* Resize frame F's windows when number of lines of F is set to SIZE.
4143 HORFLAG 1 means resize windows when number of columns of F is set to
4144 SIZE. PIXELWISE 1 means to interpret SIZE as pixels. */
4146 resize_frame_windows (struct frame
*f
, int size
, bool horflag
, bool pixelwise
)
4148 Lisp_Object root
= f
->root_window
;
4149 struct window
*r
= XWINDOW (root
);
4150 Lisp_Object mini
= f
->minibuffer_window
;
4152 /* old_size is the old size of the frame's root window. */
4153 int old_size
= horflag
? r
->total_cols
: r
->total_lines
;
4154 int old_pixel_size
= horflag
? r
->pixel_width
: r
->pixel_height
;
4155 int old_pixel_top
= r
->pixel_top
;
4156 /* new_size is the new size of the frame's root window. */
4157 int new_size
, new_pixel_size
;
4158 int unit
= horflag
? FRAME_COLUMN_WIDTH (f
) : FRAME_LINE_HEIGHT (f
);
4160 /* Don't let the size drop below one unit. This is more comforting
4161 when we are called from x_set_tool_bar_lines since the latter may
4162 have implicitly given us a zero or negative height. */
4165 /* Note: This does not include the size for internal borders
4166 since these are not part of the frame's text area. */
4167 new_pixel_size
= max (horflag
4170 - ((FRAME_HAS_MINIBUF_P (f
)
4171 && !FRAME_MINIBUF_ONLY_P (f
))
4172 ? FRAME_LINE_HEIGHT (f
) : 0)),
4174 new_size
= new_pixel_size
/ unit
;
4178 new_size
= max (horflag
4181 - ((FRAME_HAS_MINIBUF_P (f
)
4182 && !FRAME_MINIBUF_ONLY_P (f
))
4185 new_pixel_size
= new_size
* unit
;
4188 r
->top_line
= FRAME_TOP_MARGIN (f
);
4189 r
->pixel_top
= FRAME_TOP_MARGIN_HEIGHT (f
);
4191 if (new_pixel_size
== old_pixel_size
4192 && r
->pixel_top
== old_pixel_top
)
4194 else if (WINDOW_LEAF_P (r
))
4195 /* For a leaf root window just set the size. */
4198 r
->total_cols
= new_size
;
4199 r
->pixel_width
= new_pixel_size
;
4203 r
->total_lines
= new_size
;
4204 r
->pixel_height
= new_pixel_size
;
4211 XSETINT (delta
, new_pixel_size
- old_pixel_size
);
4213 XSETINT (delta
, new_size
- old_size
);
4215 /* Try a "normal" resize first. */
4216 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qnil
,
4217 pixelwise
? Qt
: Qnil
);
4218 if (window_resize_check (r
, horflag
)
4219 && new_pixel_size
== XINT (r
->new_pixel
))
4221 window_resize_apply (r
, horflag
);
4222 window_pixel_to_total (r
->frame
, horflag
? Qt
: Qnil
);
4226 /* Try with "reasonable" minimum sizes next. */
4227 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qt
,
4228 pixelwise
? Qt
: Qnil
);
4229 if (window_resize_check (r
, horflag
)
4230 && new_pixel_size
== XINT (r
->new_pixel
))
4232 window_resize_apply (r
, horflag
);
4233 window_pixel_to_total (r
->frame
, horflag
? Qt
: Qnil
);
4234 #if 0 /* Let's try without safe sizes and/or killing other windows. */
4238 /* Finally, try with "safe" minimum sizes. */
4239 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qsafe
,
4240 pixelwise
? Qt
: Qnil
);
4241 if (window_resize_check (r
, horflag
)
4242 && new_pixel_size
== XINT (r
->new_pixel
))
4244 window_resize_apply (r
, horflag
);
4245 window_pixel_to_total (r
->frame
, horflag
? Qt
: Qnil
);
4249 /* We lost. Delete all windows but the frame's
4251 root
= f
->selected_window
;
4252 Fdelete_other_windows_internal (root
, Qnil
);
4255 XWINDOW (root
)->total_cols
= new_size
;
4256 XWINDOW (root
)->pixel_width
= new_pixel_size
;
4260 XWINDOW (root
)->total_lines
= new_size
;
4261 XWINDOW (root
)->pixel_height
= new_pixel_size
;
4269 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
4274 m
->total_cols
= size
;
4275 m
->pixel_width
= new_pixel_size
;
4279 /* Are we sure we always want 1 line here? */
4281 m
->pixel_height
= FRAME_LINE_HEIGHT (f
);
4282 m
->top_line
= r
->top_line
+ r
->total_lines
;
4283 m
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4291 DEFUN ("split-window-internal", Fsplit_window_internal
, Ssplit_window_internal
, 4, 4, 0,
4292 doc
: /* Split window OLD.
4293 Second argument PIXEL-SIZE specifies the number of pixels of the
4294 new window. In any case TOTAL-SIZE must be a positive integer.
4296 Third argument SIDE nil (or `below') specifies that the new window shall
4297 be located below WINDOW. SIDE `above' means the new window shall be
4298 located above WINDOW. In both cases PIXEL-SIZE specifies the pixel
4299 height of the new window including space reserved for the mode and/or
4302 SIDE t (or `right') specifies that the new window shall be located on
4303 the right side of WINDOW. SIDE `left' means the new window shall be
4304 located on the left of WINDOW. In both cases PIXEL-SIZE specifies the
4305 width of the new window including space reserved for fringes and the
4306 scrollbar or a divider column.
4308 Fourth argument NORMAL-SIZE specifies the normal size of the new window
4309 according to the SIDE argument.
4311 The new pixel and normal sizes of all involved windows must have been
4312 set correctly. See the code of `split-window' for how this is done. */)
4313 (Lisp_Object old
, Lisp_Object pixel_size
, Lisp_Object side
, Lisp_Object normal_size
)
4315 /* OLD (*o) is the window we have to split. (*p) is either OLD's
4316 parent window or an internal window we have to install as OLD's new
4317 parent. REFERENCE (*r) must denote a live window, or is set to OLD
4318 provided OLD is a leaf window, or to the frame's selected window.
4319 NEW (*n) is the new window created with some parameters taken from
4321 register Lisp_Object
new, frame
, reference
;
4322 register struct window
*o
, *p
, *n
, *r
, *c
;
4325 /* HORFLAG is 1 when we split side-by-side, 0 otherwise. */
4326 = EQ (side
, Qt
) || EQ (side
, Qleft
) || EQ (side
, Qright
);
4327 int combination_limit
= 0, sum
= 0;
4332 frame
= WINDOW_FRAME (o
);
4335 CHECK_NUMBER (pixel_size
);
4337 = XINT (pixel_size
) / (horflag
4338 ? FRAME_COLUMN_WIDTH (f
)
4339 : FRAME_LINE_HEIGHT (f
));
4341 /* Set combination_limit to 1 if we have to make a new parent window.
4342 We do that if either `window-combination-limit' is t, or OLD has no
4343 parent, or OLD is ortho-combined. */
4345 EQ (Vwindow_combination_limit
, Qt
)
4348 ? WINDOW_VERTICAL_COMBINATION_P (XWINDOW (o
->parent
))
4349 : WINDOW_HORIZONTAL_COMBINATION_P (XWINDOW (o
->parent
)));
4351 /* We need a live reference window to initialize some parameters. */
4352 if (WINDOW_LIVE_P (old
))
4353 /* OLD is live, use it as reference window. */
4356 /* Use the frame's selected window as reference window. */
4357 reference
= FRAME_SELECTED_WINDOW (f
);
4358 r
= XWINDOW (reference
);
4360 /* The following bugs are caught by `split-window'. */
4361 if (MINI_WINDOW_P (o
))
4362 error ("Attempt to split minibuffer window");
4363 else if (total_size
< (horflag
? 2 : 1))
4364 error ("Size of new window too small (after split)");
4365 else if (!combination_limit
&& !NILP (Vwindow_combination_resize
))
4366 /* `window-combination-resize' non-nil means try to resize OLD's siblings
4369 p
= XWINDOW (o
->parent
);
4370 /* Temporarily pretend we split the parent window. */
4372 (p
, make_number ((horflag
? p
->pixel_width
: p
->pixel_height
)
4373 - XINT (pixel_size
)));
4374 if (!window_resize_check (p
, horflag
))
4375 error ("Window sizes don't fit");
4377 /* Undo the temporary pretension. */
4378 wset_new_pixel (p
, make_number (horflag
? p
->pixel_width
: p
->pixel_height
));
4382 if (!window_resize_check (o
, horflag
))
4383 error ("Resizing old window failed");
4384 else if (XINT (pixel_size
) + XINT (o
->new_pixel
)
4385 != (horflag
? o
->pixel_width
: o
->pixel_height
))
4386 error ("Sum of sizes of old and new window don't fit");
4389 /* This is our point of no return. */
4390 if (combination_limit
)
4392 /* Save the old value of o->normal_cols/lines. It gets corrupted
4393 by make_parent_window and we need it below for assigning it to
4395 Lisp_Object new_normal
4396 = horflag
? o
->normal_cols
: o
->normal_lines
;
4398 make_parent_window (old
, horflag
);
4399 p
= XWINDOW (o
->parent
);
4400 if (EQ (Vwindow_combination_limit
, Qt
))
4401 /* Store t in the new parent's combination_limit slot to avoid
4402 that its children get merged into another window. */
4403 wset_combination_limit (p
, Qt
);
4404 /* These get applied below. */
4406 (p
, make_number (horflag
? o
->pixel_width
: o
->pixel_height
));
4408 (p
, make_number (horflag
? o
->total_cols
: o
->total_lines
));
4409 wset_new_normal (p
, new_normal
);
4412 p
= XWINDOW (o
->parent
);
4415 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4416 new = make_window ();
4418 wset_frame (n
, frame
);
4419 wset_parent (n
, o
->parent
);
4421 if (EQ (side
, Qabove
) || EQ (side
, Qleft
))
4423 wset_prev (n
, o
->prev
);
4425 wset_combination (p
, horflag
, new);
4427 wset_next (XWINDOW (n
->prev
), new);
4433 wset_next (n
, o
->next
);
4434 if (!NILP (n
->next
))
4435 wset_prev (XWINDOW (n
->next
), new);
4440 n
->window_end_valid
= 0;
4441 n
->last_cursor_vpos
= 0;
4443 /* Get special geometry settings from reference window. */
4444 n
->left_margin_cols
= r
->left_margin_cols
;
4445 n
->right_margin_cols
= r
->right_margin_cols
;
4446 n
->left_fringe_width
= r
->left_fringe_width
;
4447 n
->right_fringe_width
= r
->right_fringe_width
;
4448 n
->fringes_outside_margins
= r
->fringes_outside_margins
;
4449 n
->scroll_bar_width
= r
->scroll_bar_width
;
4450 n
->scroll_bar_height
= r
->scroll_bar_height
;
4451 wset_vertical_scroll_bar_type (n
, r
->vertical_scroll_bar_type
);
4452 wset_horizontal_scroll_bar_type (n
, r
->horizontal_scroll_bar_type
);
4454 /* Directly assign orthogonal coordinates and sizes. */
4457 n
->pixel_top
= o
->pixel_top
;
4458 n
->top_line
= o
->top_line
;
4459 n
->pixel_height
= o
->pixel_height
;
4460 n
->total_lines
= o
->total_lines
;
4464 n
->pixel_left
= o
->pixel_left
;
4465 n
->left_col
= o
->left_col
;
4466 n
->pixel_width
= o
->pixel_width
;
4467 n
->total_cols
= o
->total_cols
;
4470 /* Iso-coordinates and sizes are assigned by window_resize_apply,
4471 get them ready here. */
4472 wset_new_pixel (n
, pixel_size
);
4473 c
= XWINDOW (p
->contents
);
4477 sum
= sum
+ XINT (c
->new_total
);
4478 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4480 wset_new_total (n
, make_number ((horflag
4484 wset_new_normal (n
, normal_size
);
4487 window_resize_apply (p
, horflag
);
4488 adjust_frame_glyphs (f
);
4489 /* Set buffer of NEW to buffer of reference window. Don't run
4491 set_window_buffer (new, r
->contents
, 0, 1);
4494 /* Maybe we should run the scroll functions in Elisp (which already
4495 runs the configuration change hook). */
4496 if (! NILP (Vwindow_scroll_functions
))
4497 run_hook_with_args_2 (Qwindow_scroll_functions
, new,
4498 Fmarker_position (n
->start
));
4504 DEFUN ("delete-window-internal", Fdelete_window_internal
, Sdelete_window_internal
, 1, 1, 0,
4505 doc
: /* Remove WINDOW from its frame.
4506 WINDOW defaults to the selected window. Return nil.
4507 Signal an error when WINDOW is the only window on its frame. */)
4508 (register Lisp_Object window
)
4510 register Lisp_Object parent
, sibling
, frame
, root
;
4511 struct window
*w
, *p
, *s
, *r
;
4513 bool horflag
, before_sibling
= 0;
4515 w
= decode_any_window (window
);
4516 XSETWINDOW (window
, w
);
4517 if (NILP (w
->contents
))
4518 /* It's a no-op to delete an already deleted window. */
4523 /* Never delete a minibuffer or frame root window. */
4524 error ("Attempt to delete minibuffer or sole ordinary window");
4525 else if (NILP (w
->prev
) && NILP (w
->next
))
4526 /* Rather bow out here, this case should be handled on the Elisp
4528 error ("Attempt to delete sole window of parent");
4530 p
= XWINDOW (parent
);
4531 horflag
= WINDOW_HORIZONTAL_COMBINATION_P (p
);
4533 frame
= WINDOW_FRAME (w
);
4536 root
= FRAME_ROOT_WINDOW (f
);
4539 /* Unlink WINDOW from window tree. */
4541 /* Get SIBLING below (on the right of) WINDOW. */
4543 /* before_sibling 1 means WINDOW is the first child of its
4544 parent and thus before the sibling. */
4547 s
= XWINDOW (sibling
);
4548 wset_prev (s
, Qnil
);
4549 wset_combination (p
, horflag
, sibling
);
4552 /* Get SIBLING above (on the left of) WINDOW. */
4555 s
= XWINDOW (sibling
);
4556 wset_next (s
, w
->next
);
4557 if (!NILP (s
->next
))
4558 wset_prev (XWINDOW (s
->next
), sibling
);
4561 if (window_resize_check (r
, horflag
)
4562 && (XINT (r
->new_pixel
)
4563 == (horflag
? r
->pixel_width
: r
->pixel_height
)))
4564 /* We can delete WINDOW now. */
4569 #ifdef HAVE_XWIDGETS
4570 xwidget_view_delete_all_in_window(w
);
4572 window_resize_apply (p
, horflag
);
4573 /* If this window is referred to by the dpyinfo's mouse
4574 highlight, invalidate that slot to be safe (Bug#9904). */
4575 if (!FRAME_INITIAL_P (f
))
4577 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
4579 if (EQ (hlinfo
->mouse_face_window
, window
))
4580 hlinfo
->mouse_face_window
= Qnil
;
4584 Vwindow_list
= Qnil
;
4585 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4587 wset_next (w
, Qnil
); /* Don't delete w->next too. */
4588 free_window_matrices (w
);
4590 if (WINDOWP (w
->contents
))
4592 delete_all_child_windows (w
->contents
);
4593 wset_combination (w
, 0, Qnil
);
4598 unchain_marker (XMARKER (w
->pointm
));
4599 unchain_marker (XMARKER (w
->old_pointm
));
4600 unchain_marker (XMARKER (w
->start
));
4601 wset_buffer (w
, Qnil
);
4604 if (NILP (s
->prev
) && NILP (s
->next
))
4605 /* A matrjoshka where SIBLING has become the only child of
4608 /* Put SIBLING into PARENT's place. */
4609 replace_window (parent
, sibling
, 0);
4610 /* Have SIBLING inherit the following three slot values from
4611 PARENT (the combination_limit slot is not inherited). */
4612 wset_normal_cols (s
, p
->normal_cols
);
4613 wset_normal_lines (s
, p
->normal_lines
);
4614 /* Mark PARENT as deleted. */
4615 wset_combination (p
, 0, Qnil
);
4616 /* Try to merge SIBLING into its new parent. */
4617 recombine_windows (sibling
);
4620 adjust_frame_glyphs (f
);
4622 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f
)))
4623 /* We deleted the frame's selected window. */
4625 /* Use the frame's first window as fallback ... */
4626 Lisp_Object new_selected_window
= Fframe_first_window (frame
);
4627 /* ... but preferably use its most recently used window. */
4628 Lisp_Object mru_window
;
4630 /* `get-mru-window' might fail for some reason so play it safe
4631 - promote the first window _without recording it_ first. */
4632 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4633 Fselect_window (new_selected_window
, Qt
);
4635 fset_selected_window (f
, new_selected_window
);
4639 /* Now look whether `get-mru-window' gets us something. */
4640 mru_window
= call1 (Qget_mru_window
, frame
);
4641 if (WINDOW_LIVE_P (mru_window
)
4642 && EQ (XWINDOW (mru_window
)->frame
, frame
))
4643 new_selected_window
= mru_window
;
4645 /* If all ended up well, we now promote the mru window. */
4646 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4647 Fselect_window (new_selected_window
, Qnil
);
4649 fset_selected_window (f
, new_selected_window
);
4654 /* Must be run by the caller:
4655 run_window_configuration_change_hook (f); */
4658 /* We failed: Relink WINDOW into window tree. */
4662 wset_prev (s
, window
);
4663 wset_combination (p
, horflag
, window
);
4667 wset_next (s
, window
);
4668 if (!NILP (w
->next
))
4669 wset_prev (XWINDOW (w
->next
), window
);
4671 error ("Deletion failed");
4677 /***********************************************************************
4678 Resizing Mini-Windows
4679 ***********************************************************************/
4681 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we
4684 grow_mini_window (struct window
*w
, int delta
, bool pixelwise
)
4686 struct frame
*f
= XFRAME (w
->frame
);
4688 Lisp_Object root
, height
;
4689 int line_height
, pixel_height
;
4691 eassert (MINI_WINDOW_P (w
));
4692 eassert (delta
>= 0);
4696 root
= FRAME_ROOT_WINDOW (f
);
4698 height
= call3 (Qwindow_resize_root_window_vertically
,
4699 root
, make_number (- delta
), pixelwise
? Qt
: Qnil
);
4700 if (INTEGERP (height
) && window_resize_check (r
, 0))
4703 window_resize_apply (r
, 0);
4707 pixel_height
= min (-XINT (height
), INT_MAX
- w
->pixel_height
);
4708 line_height
= pixel_height
/ FRAME_LINE_HEIGHT (f
);
4712 line_height
= min (-XINT (height
),
4713 ((INT_MAX
- w
->pixel_height
)
4714 / FRAME_LINE_HEIGHT (f
)));
4715 pixel_height
= line_height
* FRAME_LINE_HEIGHT (f
);
4718 /* Grow the mini-window. */
4719 w
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4720 w
->top_line
= r
->top_line
+ r
->total_lines
;
4721 /* Make sure the mini-window has always at least one line. */
4722 w
->pixel_height
= max (w
->pixel_height
+ pixel_height
,
4723 FRAME_LINE_HEIGHT (f
));
4724 w
->total_lines
= max (w
->total_lines
+ line_height
, 1);
4726 /* Enforce full redisplay of the frame. */
4727 /* FIXME: Shouldn't window--resize-root-window-vertically do it? */
4729 adjust_frame_glyphs (f
);
4735 /* Shrink mini-window W to one line. */
4737 shrink_mini_window (struct window
*w
, bool pixelwise
)
4739 struct frame
*f
= XFRAME (w
->frame
);
4741 Lisp_Object root
, delta
;
4742 EMACS_INT height
, unit
;
4744 eassert (MINI_WINDOW_P (w
));
4746 height
= pixelwise
? w
->pixel_height
: w
->total_lines
;
4747 unit
= pixelwise
? FRAME_LINE_HEIGHT (f
) : 1;
4750 root
= FRAME_ROOT_WINDOW (f
);
4752 delta
= call3 (Qwindow_resize_root_window_vertically
,
4753 root
, make_number (height
- unit
),
4754 pixelwise
? Qt
: Qnil
);
4755 if (INTEGERP (delta
) && window_resize_check (r
, 0))
4758 window_resize_apply (r
, 0);
4760 /* Shrink the mini-window. */
4761 w
->top_line
= r
->top_line
+ r
->total_lines
;
4763 w
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4764 w
->pixel_height
= FRAME_LINE_HEIGHT (f
);
4765 /* Enforce full redisplay of the frame. */
4766 /* FIXME: Shouldn't window--resize-root-window-vertically do it? */
4768 adjust_frame_glyphs (f
);
4771 /* If the above failed for whatever strange reason we must make a
4772 one window frame here. The same routine will be needed when
4773 shrinking the frame (and probably when making the initial
4774 *scratch* window). For the moment leave things as they are. */
4778 DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal
, Sresize_mini_window_internal
, 1, 1, 0,
4779 doc
: /* Resize minibuffer window WINDOW. */)
4780 (Lisp_Object window
)
4782 struct window
*w
= XWINDOW (window
);
4787 CHECK_WINDOW (window
);
4788 f
= XFRAME (w
->frame
);
4790 if (!EQ (FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
)), window
))
4791 error ("Not a valid minibuffer window");
4792 else if (FRAME_MINIBUF_ONLY_P (f
))
4793 error ("Cannot resize a minibuffer-only frame");
4795 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4796 height
= r
->pixel_height
+ w
->pixel_height
;
4797 if (window_resize_check (r
, 0)
4798 && XINT (w
->new_pixel
) > 0
4799 && height
== XINT (r
->new_pixel
) + XINT (w
->new_pixel
))
4802 window_resize_apply (r
, 0);
4804 w
->pixel_height
= XFASTINT (w
->new_pixel
);
4805 w
->total_lines
= w
->pixel_height
/ FRAME_LINE_HEIGHT (f
);
4806 w
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4807 w
->top_line
= r
->top_line
+ r
->total_lines
;
4810 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4811 adjust_frame_glyphs (f
);
4816 error ("Failed to resize minibuffer window");
4819 /* Mark window cursors off for all windows in the window tree rooted
4820 at W by setting their phys_cursor_on_p flag to zero. Called from
4821 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4822 the frame are cleared. */
4825 mark_window_cursors_off (struct window
*w
)
4829 if (WINDOWP (w
->contents
))
4830 mark_window_cursors_off (XWINDOW (w
->contents
));
4832 w
->phys_cursor_on_p
= 0;
4834 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4839 /* Return number of lines of text (not counting mode lines) in W. */
4842 window_internal_height (struct window
*w
)
4844 int ht
= w
->total_lines
;
4846 if (!MINI_WINDOW_P (w
))
4848 if (!NILP (w
->parent
)
4849 || WINDOWP (w
->contents
)
4852 || WINDOW_WANTS_MODELINE_P (w
))
4855 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4863 /************************************************************************
4865 ***********************************************************************/
4867 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4868 N screen-fulls, which is defined as the height of the window minus
4869 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4870 instead. Negative values of N mean scroll down. NOERROR non-zero
4871 means don't signal an error if we try to move over BEGV or ZV,
4875 window_scroll (Lisp_Object window
, EMACS_INT n
, bool whole
, int noerror
)
4877 ptrdiff_t count
= SPECPDL_INDEX ();
4880 n
= clip_to_bounds (INT_MIN
, n
, INT_MAX
);
4882 wset_redisplay (XWINDOW (window
));
4884 if (whole
&& Vfast_but_imprecise_scrolling
)
4885 specbind (Qfontification_functions
, Qnil
);
4887 /* If we must, use the pixel-based version which is much slower than
4888 the line-based one but can handle varying line heights. */
4889 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4890 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4892 window_scroll_line_based (window
, n
, whole
, noerror
);
4894 unbind_to (count
, Qnil
);
4897 XWINDOW (window
)->window_end_valid
= 0;
4902 /* Implementation of window_scroll that works based on pixel line
4903 heights. See the comment of window_scroll for parameter
4907 window_scroll_pixel_based (Lisp_Object window
, int n
, bool whole
, int noerror
)
4910 struct window
*w
= XWINDOW (window
);
4911 struct text_pos start
;
4912 int this_scroll_margin
;
4913 /* True if we fiddled the window vscroll field without really scrolling. */
4915 int x
, y
, rtop
, rbot
, rowh
, vpos
;
4916 void *itdata
= NULL
;
4917 int window_total_lines
;
4918 int frame_line_height
= default_line_pixel_height (w
);
4919 bool adjust_old_pointm
= !NILP (Fequal (Fwindow_point (window
),
4920 Fwindow_old_point (window
)));
4922 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4923 /* Scrolling a minibuffer window via scroll bar when the echo area
4924 shows long text sometimes resets the minibuffer contents behind
4926 if (CHARPOS (start
) > ZV
)
4927 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4929 /* If PT is not visible in WINDOW, move back one half of
4930 the screen. Allow PT to be partially visible, otherwise
4931 something like (scroll-down 1) with PT in the line before
4932 the partially visible one would recenter. */
4934 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
4936 itdata
= bidi_shelve_cache ();
4937 /* Move backward half the height of the window. Performance note:
4938 vmotion used here is about 10% faster, but would give wrong
4939 results for variable height lines. */
4940 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4941 it
.current_y
= it
.last_visible_y
;
4942 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4944 /* The function move_iterator_vertically may move over more than
4945 the specified y-distance. If it->w is small, e.g. a
4946 mini-buffer window, we may end up in front of the window's
4947 display area. Start displaying at the start of the line
4948 containing PT in this case. */
4949 if (it
.current_y
<= 0)
4951 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4952 move_it_vertically_backward (&it
, 0);
4956 start
= it
.current
.pos
;
4957 bidi_unshelve_cache (itdata
, 0);
4959 else if (auto_window_vscroll_p
)
4961 if (rtop
|| rbot
) /* Partially visible. */
4964 int dy
= frame_line_height
;
4965 /* In the below we divide the window box height by the
4966 frame's line height to make the result predictable when
4967 the window box is not an integral multiple of the line
4968 height. This is important to ensure we get back to the
4969 same position when scrolling up, then down. */
4971 dy
= max ((window_box_height (w
) / dy
4972 - next_screen_context_lines
) * dy
,
4978 /* Only vscroll backwards if already vscrolled forwards. */
4979 if (w
->vscroll
< 0 && rtop
> 0)
4981 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
4982 Fset_window_vscroll (window
, make_number (px
), Qt
);
4988 /* Do vscroll if already vscrolled or only display line. */
4989 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
4991 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
4992 Fset_window_vscroll (window
, make_number (px
), Qt
);
4996 /* Maybe modify window start instead of scrolling. */
4997 if (rbot
> 0 || w
->vscroll
< 0)
5001 Fset_window_vscroll (window
, make_number (0), Qt
);
5002 /* If there are other text lines above the current row,
5003 move window start to current row. Else to next row. */
5005 spos
= XINT (Fline_beginning_position (Qnil
));
5007 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
5008 set_marker_restricted (w
->start
, make_number (spos
),
5010 w
->start_at_line_beg
= 1;
5011 w
->update_mode_line
= 1;
5012 /* Set force_start so that redisplay_window will run the
5013 window-scroll-functions. */
5019 /* Cancel previous vscroll. */
5020 Fset_window_vscroll (window
, make_number (0), Qt
);
5023 itdata
= bidi_shelve_cache ();
5024 /* If scroll_preserve_screen_position is non-nil, we try to set
5025 point in the same window line as it is now, so get that line. */
5026 if (!NILP (Vscroll_preserve_screen_position
))
5028 /* We preserve the goal pixel coordinate across consecutive
5029 calls to scroll-up, scroll-down and other commands that
5030 have the `scroll-command' property. This avoids the
5031 possibility of point becoming "stuck" on a tall line when
5032 scrolling by one line. */
5033 if (window_scroll_pixel_based_preserve_y
< 0
5034 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
5035 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
5037 start_display (&it
, w
, start
);
5038 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5039 window_scroll_pixel_based_preserve_y
= it
.current_y
;
5040 window_scroll_pixel_based_preserve_x
= it
.current_x
;
5044 window_scroll_pixel_based_preserve_y
5045 = window_scroll_pixel_based_preserve_x
= -1;
5047 /* Move iterator it from start the specified distance forward or
5048 backward. The result is the new window start. */
5049 start_display (&it
, w
, start
);
5052 ptrdiff_t start_pos
= IT_CHARPOS (it
);
5053 int dy
= frame_line_height
;
5054 /* In the below we divide the window box height by the frame's
5055 line height to make the result predictable when the window
5056 box is not an integral multiple of the line height. This is
5057 important to ensure we get back to the same position when
5058 scrolling up, then down. */
5059 dy
= max ((window_box_height (w
) / dy
- next_screen_context_lines
) * dy
,
5062 /* Note that move_it_vertically always moves the iterator to the
5063 start of a line. So, if the last line doesn't have a newline,
5064 we would end up at the start of the line ending at ZV. */
5067 move_it_vertically_backward (&it
, -dy
);
5068 /* Ensure we actually do move, e.g. in case we are currently
5069 looking at an image that is taller that the window height. */
5070 while (start_pos
== IT_CHARPOS (it
)
5071 && start_pos
> BEGV
)
5072 move_it_by_lines (&it
, -1);
5076 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
5077 MOVE_TO_POS
| MOVE_TO_Y
);
5078 /* Ensure we actually do move, e.g. in case we are currently
5079 looking at an image that is taller that the window height. */
5080 while (start_pos
== IT_CHARPOS (it
)
5082 move_it_by_lines (&it
, 1);
5086 move_it_by_lines (&it
, n
);
5088 /* We failed if we find ZV is already on the screen (scrolling up,
5089 means there's nothing past the end), or if we can't start any
5090 earlier (scrolling down, means there's nothing past the top). */
5091 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
5092 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
5094 if (IT_CHARPOS (it
) == ZV
)
5096 if (it
.current_y
< it
.last_visible_y
5097 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
5098 > it
.last_visible_y
))
5100 /* The last line was only partially visible, make it fully
5102 w
->vscroll
= (it
.last_visible_y
5103 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
5104 adjust_frame_glyphs (it
.f
);
5108 bidi_unshelve_cache (itdata
, 0);
5111 else if (n
< 0) /* could happen with empty buffers */
5112 xsignal0 (Qbeginning_of_buffer
);
5114 xsignal0 (Qend_of_buffer
);
5119 if (w
->vscroll
!= 0)
5120 /* The first line was only partially visible, make it fully
5125 bidi_unshelve_cache (itdata
, 0);
5129 xsignal0 (Qbeginning_of_buffer
);
5133 /* If control gets here, then we vscrolled. */
5135 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
5137 /* Don't try to change the window start below. */
5143 ptrdiff_t pos
= IT_CHARPOS (it
);
5146 /* If in the middle of a multi-glyph character move forward to
5147 the next character. */
5148 if (in_display_vector_p (&it
))
5151 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
5154 /* Set the window start, and set up the window for redisplay. */
5155 set_marker_restricted_both (w
->start
, w
->contents
, IT_CHARPOS (it
),
5157 bytepos
= marker_byte_position (w
->start
);
5158 w
->start_at_line_beg
= (pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n');
5159 w
->update_mode_line
= 1;
5160 /* Set force_start so that redisplay_window will run the
5161 window-scroll-functions. */
5165 /* The rest of this function uses current_y in a nonstandard way,
5166 not including the height of the header line if any. */
5167 it
.current_y
= it
.vpos
= 0;
5169 /* Move PT out of scroll margins.
5170 This code wants current_y to be zero at the window start position
5171 even if there is a header line. */
5173 = w
->total_lines
* WINDOW_FRAME_LINE_HEIGHT (w
) / frame_line_height
;
5174 this_scroll_margin
= max (0, scroll_margin
);
5176 = min (this_scroll_margin
, window_total_lines
/ 4);
5177 this_scroll_margin
*= frame_line_height
;
5181 /* We moved the window start towards ZV, so PT may be now
5182 in the scroll margin at the top. */
5183 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5184 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
5185 && (NILP (Vscroll_preserve_screen_position
)
5186 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5187 /* We found PT at a legitimate height. Leave it alone. */
5189 else if (window_scroll_pixel_based_preserve_y
>= 0)
5191 /* If we have a header line, take account of it.
5192 This is necessary because we set it.current_y to 0, above. */
5193 move_it_to (&it
, -1,
5194 window_scroll_pixel_based_preserve_x
,
5195 window_scroll_pixel_based_preserve_y
5196 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
5197 -1, MOVE_TO_Y
| MOVE_TO_X
);
5198 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5202 while (it
.current_y
< this_scroll_margin
)
5204 int prev
= it
.current_y
;
5205 move_it_by_lines (&it
, 1);
5206 if (prev
== it
.current_y
)
5209 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5214 ptrdiff_t charpos
, bytepos
;
5217 /* Save our position, for the
5218 window_scroll_pixel_based_preserve_y case. */
5219 charpos
= IT_CHARPOS (it
);
5220 bytepos
= IT_BYTEPOS (it
);
5222 /* We moved the window start towards BEGV, so PT may be now
5223 in the scroll margin at the bottom. */
5224 move_it_to (&it
, PT
, -1,
5225 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
5226 - this_scroll_margin
- 1),
5228 MOVE_TO_POS
| MOVE_TO_Y
);
5230 /* Save our position, in case it's correct. */
5231 charpos
= IT_CHARPOS (it
);
5232 bytepos
= IT_BYTEPOS (it
);
5234 /* If PT is in the screen line at the last fully visible line,
5235 move_it_to will stop at X = 0 in that line, because the
5236 required Y coordinate is reached there. See if we can get to
5237 PT without descending lower in Y, and if we can, it means we
5238 reached PT before the scroll margin. */
5245 it_data
= bidi_shelve_cache ();
5246 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5247 if (IT_CHARPOS (it
) == PT
&& it
.current_y
== it2
.current_y
)
5249 charpos
= IT_CHARPOS (it
);
5250 bytepos
= IT_BYTEPOS (it
);
5251 bidi_unshelve_cache (it_data
, 1);
5256 bidi_unshelve_cache (it_data
, 0);
5260 /* See if point is on a partially visible line at the end. */
5261 if (it
.what
== IT_EOB
)
5262 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
5265 move_it_by_lines (&it
, 1);
5266 partial_p
= it
.current_y
> it
.last_visible_y
;
5269 if (charpos
== PT
&& !partial_p
5270 && (NILP (Vscroll_preserve_screen_position
)
5271 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5272 /* We found PT before we found the display margin, so PT is ok. */
5274 else if (window_scroll_pixel_based_preserve_y
>= 0)
5276 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5277 start_display (&it
, w
, start
);
5278 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
5279 here because we called start_display again and did not
5280 alter it.current_y this time. */
5281 move_it_to (&it
, -1, window_scroll_pixel_based_preserve_x
,
5282 window_scroll_pixel_based_preserve_y
, -1,
5283 MOVE_TO_Y
| MOVE_TO_X
);
5284 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5289 /* The last line was only partially visible, so back up two
5290 lines to make sure we're on a fully visible line. */
5292 move_it_by_lines (&it
, -2);
5293 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5296 /* No, the position we saved is OK, so use it. */
5297 SET_PT_BOTH (charpos
, bytepos
);
5300 bidi_unshelve_cache (itdata
, 0);
5302 if (adjust_old_pointm
)
5303 Fset_marker (w
->old_pointm
,
5304 ((w
== XWINDOW (selected_window
))
5305 ? make_number (BUF_PT (XBUFFER (w
->contents
)))
5306 : Fmarker_position (w
->pointm
)),
5311 /* Implementation of window_scroll that works based on screen lines.
5312 See the comment of window_scroll for parameter descriptions. */
5315 window_scroll_line_based (Lisp_Object window
, int n
, bool whole
, int noerror
)
5317 register struct window
*w
= XWINDOW (window
);
5318 /* Fvertical_motion enters redisplay, which can trigger
5319 fontification, which in turn can modify buffer text (e.g., if the
5320 fontification functions replace escape sequences with faces, as
5321 in `grep-mode-font-lock-keywords'). So we use a marker to record
5322 the old point position, to prevent crashes in SET_PT_BOTH. */
5323 Lisp_Object opoint_marker
= Fpoint_marker ();
5324 register ptrdiff_t pos
, pos_byte
;
5325 register int ht
= window_internal_height (w
);
5326 register Lisp_Object tem
;
5329 ptrdiff_t startpos
= marker_position (w
->start
);
5330 ptrdiff_t startbyte
= marker_byte_position (w
->start
);
5331 Lisp_Object original_pos
= Qnil
;
5332 bool adjust_old_pointm
= !NILP (Fequal (Fwindow_point (window
),
5333 Fwindow_old_point (window
)));
5335 /* If scrolling screen-fulls, compute the number of lines to
5336 scroll from the window's height. */
5338 n
*= max (1, ht
- next_screen_context_lines
);
5340 if (!NILP (Vscroll_preserve_screen_position
))
5342 if (window_scroll_preserve_vpos
<= 0
5343 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
5344 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
5346 struct position posit
5347 = *compute_motion (startpos
, startbyte
, 0, 0, 0,
5348 PT
, ht
, 0, -1, w
->hscroll
, 0, w
);
5350 window_scroll_preserve_vpos
= posit
.vpos
;
5351 window_scroll_preserve_hpos
= posit
.hpos
+ w
->hscroll
;
5354 original_pos
= Fcons (make_number (window_scroll_preserve_hpos
),
5355 make_number (window_scroll_preserve_vpos
));
5358 XSETFASTINT (tem
, PT
);
5359 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
5363 Fvertical_motion (make_number (- (ht
/ 2)), window
);
5365 startbyte
= PT_BYTE
;
5368 SET_PT_BOTH (startpos
, startbyte
);
5369 lose
= n
< 0 && PT
== BEGV
;
5370 Fvertical_motion (make_number (n
), window
);
5374 SET_PT_BOTH (marker_position (opoint_marker
),
5375 marker_byte_position (opoint_marker
));
5382 xsignal0 (Qbeginning_of_buffer
);
5387 /* Don't use a scroll margin that is negative or too large. */
5388 int this_scroll_margin
=
5389 max (0, min (scroll_margin
, w
->total_lines
/ 4));
5391 set_marker_restricted_both (w
->start
, w
->contents
, pos
, pos_byte
);
5392 w
->start_at_line_beg
= !NILP (bolp
);
5393 w
->update_mode_line
= 1;
5394 /* Set force_start so that redisplay_window will run
5395 the window-scroll-functions. */
5398 if (!NILP (Vscroll_preserve_screen_position
)
5399 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
5401 SET_PT_BOTH (pos
, pos_byte
);
5402 Fvertical_motion (original_pos
, window
);
5404 /* If we scrolled forward, put point enough lines down
5405 that it is outside the scroll margin. */
5410 if (this_scroll_margin
> 0)
5412 SET_PT_BOTH (pos
, pos_byte
);
5413 Fvertical_motion (make_number (this_scroll_margin
), window
);
5419 if (top_margin
<= marker_position (opoint_marker
))
5420 SET_PT_BOTH (marker_position (opoint_marker
),
5421 marker_byte_position (opoint_marker
));
5422 else if (!NILP (Vscroll_preserve_screen_position
))
5424 SET_PT_BOTH (pos
, pos_byte
);
5425 Fvertical_motion (original_pos
, window
);
5428 SET_PT (top_margin
);
5434 /* If we scrolled backward, put point near the end of the window
5435 but not within the scroll margin. */
5436 SET_PT_BOTH (pos
, pos_byte
);
5437 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
5438 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
5441 bottom_margin
= PT
+ 1;
5443 if (bottom_margin
> marker_position (opoint_marker
))
5444 SET_PT_BOTH (marker_position (opoint_marker
),
5445 marker_byte_position (opoint_marker
));
5448 if (!NILP (Vscroll_preserve_screen_position
))
5450 SET_PT_BOTH (pos
, pos_byte
);
5451 Fvertical_motion (original_pos
, window
);
5454 Fvertical_motion (make_number (-1), window
);
5463 xsignal0 (Qend_of_buffer
);
5466 if (adjust_old_pointm
)
5467 Fset_marker (w
->old_pointm
,
5468 ((w
== XWINDOW (selected_window
))
5469 ? make_number (BUF_PT (XBUFFER (w
->contents
)))
5470 : Fmarker_position (w
->pointm
)),
5475 /* Scroll selected_window up or down. If N is nil, scroll a
5476 screen-full which is defined as the height of the window minus
5477 next_screen_context_lines. If N is the symbol `-', scroll.
5478 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
5479 up. This is the guts of Fscroll_up and Fscroll_down. */
5482 scroll_command (Lisp_Object n
, int direction
)
5484 ptrdiff_t count
= SPECPDL_INDEX ();
5486 eassert (eabs (direction
) == 1);
5488 /* If selected window's buffer isn't current, make it current for
5489 the moment. But don't screw up if window_scroll gets an error. */
5490 if (XBUFFER (XWINDOW (selected_window
)->contents
) != current_buffer
)
5492 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5493 Fset_buffer (XWINDOW (selected_window
)->contents
);
5497 window_scroll (selected_window
, direction
, 1, 0);
5498 else if (EQ (n
, Qminus
))
5499 window_scroll (selected_window
, -direction
, 1, 0);
5502 n
= Fprefix_numeric_value (n
);
5503 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
5506 unbind_to (count
, Qnil
);
5509 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "^P",
5510 doc
: /* Scroll text of selected window upward ARG lines.
5511 If ARG is omitted or nil, scroll upward by a near full screen.
5512 A near full screen is `next-screen-context-lines' less than a full screen.
5513 Negative ARG means scroll downward.
5514 If ARG is the atom `-', scroll downward by nearly full screen.
5515 When calling from a program, supply as argument a number, nil, or `-'. */)
5518 scroll_command (arg
, 1);
5522 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "^P",
5523 doc
: /* Scroll text of selected window down ARG lines.
5524 If ARG is omitted or nil, scroll down by a near full screen.
5525 A near full screen is `next-screen-context-lines' less than a full screen.
5526 Negative ARG means scroll upward.
5527 If ARG is the atom `-', scroll upward by nearly full screen.
5528 When calling from a program, supply as argument a number, nil, or `-'. */)
5531 scroll_command (arg
, -1);
5535 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
5536 doc
: /* Return the other window for \"other window scroll\" commands.
5537 If `other-window-scroll-buffer' is non-nil, a window
5538 showing that buffer is used.
5539 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5540 specifies the window. This takes precedence over
5541 `other-window-scroll-buffer'. */)
5546 if (MINI_WINDOW_P (XWINDOW (selected_window
))
5547 && !NILP (Vminibuf_scroll_window
))
5548 window
= Vminibuf_scroll_window
;
5549 /* If buffer is specified and live, scroll that buffer. */
5550 else if (!NILP (Vother_window_scroll_buffer
)
5551 && BUFFERP (Vother_window_scroll_buffer
)
5552 && BUFFER_LIVE_P (XBUFFER (Vother_window_scroll_buffer
)))
5554 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
5556 window
= display_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
5560 /* Nothing specified; look for a neighboring window on the same
5562 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
5564 if (EQ (window
, selected_window
))
5565 /* That didn't get us anywhere; look for a window on another
5568 window
= Fnext_window (window
, Qnil
, Qt
);
5569 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
5570 && ! EQ (window
, selected_window
));
5573 CHECK_LIVE_WINDOW (window
);
5575 if (EQ (window
, selected_window
))
5576 error ("There is no other window");
5581 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
5582 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5583 A near full screen is `next-screen-context-lines' less than a full screen.
5584 The next window is the one below the current one; or the one at the top
5585 if the current one is at the bottom. Negative ARG means scroll downward.
5586 If ARG is the atom `-', scroll downward by nearly full screen.
5587 When calling from a program, supply as argument a number, nil, or `-'.
5589 If `other-window-scroll-buffer' is non-nil, scroll the window
5590 showing that buffer, popping the buffer up if necessary.
5591 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5592 specifies the window to scroll. This takes precedence over
5593 `other-window-scroll-buffer'. */)
5598 ptrdiff_t count
= SPECPDL_INDEX ();
5600 window
= Fother_window_for_scrolling ();
5601 w
= XWINDOW (window
);
5603 /* Don't screw up if window_scroll gets an error. */
5604 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5606 Fset_buffer (w
->contents
);
5607 SET_PT_BOTH (marker_position (w
->pointm
), marker_byte_position (w
->pointm
));
5608 SET_PT_BOTH (marker_position (w
->old_pointm
), marker_byte_position (w
->old_pointm
));
5611 window_scroll (window
, 1, 1, 1);
5612 else if (EQ (arg
, Qminus
))
5613 window_scroll (window
, -1, 1, 1);
5619 window_scroll (window
, XINT (arg
), 0, 1);
5622 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5623 set_marker_both (w
->old_pointm
, Qnil
, PT
, PT_BYTE
);
5624 unbind_to (count
, Qnil
);
5629 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "^P\np",
5630 doc
: /* Scroll selected window display ARG columns left.
5631 Default for ARG is window width minus 2.
5632 Value is the total amount of leftward horizontal scrolling in
5633 effect after the change.
5634 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5635 lower bound for automatic scrolling, i.e. automatic scrolling
5636 will not scroll a window to a column less than the value returned
5637 by this function. This happens in an interactive call. */)
5638 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5640 struct window
*w
= XWINDOW (selected_window
);
5641 EMACS_INT requested_arg
= (NILP (arg
)
5642 ? window_body_width (w
, 0) - 2
5643 : XINT (Fprefix_numeric_value (arg
)));
5644 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
+ requested_arg
);
5646 if (!NILP (set_minimum
))
5647 w
->min_hscroll
= w
->hscroll
;
5649 w
->suspend_auto_hscroll
= 1;
5654 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "^P\np",
5655 doc
: /* Scroll selected window display ARG columns right.
5656 Default for ARG is window width minus 2.
5657 Value is the total amount of leftward horizontal scrolling in
5658 effect after the change.
5659 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5660 lower bound for automatic scrolling, i.e. automatic scrolling
5661 will not scroll a window to a column less than the value returned
5662 by this function. This happens in an interactive call. */)
5663 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5665 struct window
*w
= XWINDOW (selected_window
);
5666 EMACS_INT requested_arg
= (NILP (arg
)
5667 ? window_body_width (w
, 0) - 2
5668 : XINT (Fprefix_numeric_value (arg
)));
5669 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
- requested_arg
);
5671 if (!NILP (set_minimum
))
5672 w
->min_hscroll
= w
->hscroll
;
5674 w
->suspend_auto_hscroll
= 1;
5679 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5680 doc
: /* Return the window which was selected when entering the minibuffer.
5681 Returns nil, if selected window is not a minibuffer window. */)
5684 if (minibuf_level
> 0
5685 && MINI_WINDOW_P (XWINDOW (selected_window
))
5686 && WINDOW_LIVE_P (minibuf_selected_window
))
5687 return minibuf_selected_window
;
5692 /* Value is the number of lines actually displayed in window W,
5693 as opposed to its height. */
5696 displayed_window_lines (struct window
*w
)
5699 struct text_pos start
;
5700 int height
= window_box_height (w
);
5701 struct buffer
*old_buffer
;
5703 void *itdata
= NULL
;
5705 if (XBUFFER (w
->contents
) != current_buffer
)
5707 old_buffer
= current_buffer
;
5708 set_buffer_internal (XBUFFER (w
->contents
));
5713 /* In case W->start is out of the accessible range, do something
5714 reasonable. This happens in Info mode when Info-scroll-down
5715 calls (recenter -1) while W->start is 1. */
5716 CLIP_TEXT_POS_FROM_MARKER (start
, w
->start
);
5718 itdata
= bidi_shelve_cache ();
5719 start_display (&it
, w
, start
);
5720 move_it_vertically (&it
, height
);
5721 bottom_y
= line_bottom_y (&it
);
5722 bidi_unshelve_cache (itdata
, 0);
5724 /* rms: On a non-window display,
5725 the value of it.vpos at the bottom of the screen
5726 seems to be 1 larger than window_box_height (w).
5727 This kludge fixes a bug whereby (move-to-window-line -1)
5728 when ZV is on the last screen line
5729 moves to the previous screen line instead of the last one. */
5730 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5733 /* Add in empty lines at the bottom of the window. */
5734 if (bottom_y
< height
)
5736 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5737 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5741 set_buffer_internal (old_buffer
);
5747 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5748 doc
: /* Center point in selected window and maybe redisplay frame.
5749 With a numeric prefix argument ARG, recenter putting point on screen line ARG
5750 relative to the selected window. If ARG is negative, it counts up from the
5751 bottom of the window. (ARG should be less than the height of the window.)
5753 If ARG is omitted or nil, then recenter with point on the middle line of
5754 the selected window; if the variable `recenter-redisplay' is non-nil,
5755 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5756 is set to `grow-only', this resets the tool-bar's height to the minimum
5757 height needed); if `recenter-redisplay' has the special value `tty',
5758 then only tty frames are redrawn.
5760 Just C-u as prefix means put point in the center of the window
5761 and redisplay normally--don't erase and redraw the frame. */)
5762 (register Lisp_Object arg
)
5764 struct window
*w
= XWINDOW (selected_window
);
5765 struct buffer
*buf
= XBUFFER (w
->contents
);
5767 ptrdiff_t charpos
, bytepos
;
5768 EMACS_INT iarg
IF_LINT (= 0);
5769 int this_scroll_margin
;
5771 if (buf
!= current_buffer
)
5772 error ("`recenter'ing a window that does not display current-buffer.");
5774 /* If redisplay is suppressed due to an error, try again. */
5775 buf
->display_error_modiff
= 0;
5779 if (!NILP (Vrecenter_redisplay
)
5780 && (!EQ (Vrecenter_redisplay
, Qtty
)
5781 || !NILP (Ftty_type (selected_frame
))))
5785 /* Invalidate pixel data calculated for all compositions. */
5786 for (i
= 0; i
< n_compositions
; i
++)
5787 composition_table
[i
]->font
= NULL
;
5788 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
5789 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5791 Fredraw_frame (WINDOW_FRAME (w
));
5792 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5797 else if (CONSP (arg
)) /* Just C-u. */
5801 arg
= Fprefix_numeric_value (arg
);
5806 /* Do this after making BUF current
5807 in case scroll_margin is buffer-local. */
5809 = max (0, min (scroll_margin
, w
->total_lines
/ 4));
5811 /* Handle centering on a graphical frame specially. Such frames can
5812 have variable-height lines and centering point on the basis of
5813 line counts would lead to strange effects. */
5814 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5820 void *itdata
= bidi_shelve_cache ();
5822 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5823 start_display (&it
, w
, pt
);
5824 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5825 charpos
= IT_CHARPOS (it
);
5826 bytepos
= IT_BYTEPOS (it
);
5827 bidi_unshelve_cache (itdata
, 0);
5833 ptrdiff_t nlines
= min (PTRDIFF_MAX
, -iarg
);
5834 int extra_line_spacing
;
5835 int h
= window_box_height (w
);
5836 void *itdata
= bidi_shelve_cache ();
5838 iarg
= - max (-iarg
, this_scroll_margin
);
5840 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5841 start_display (&it
, w
, pt
);
5843 /* Be sure we have the exact height of the full line containing PT. */
5844 move_it_by_lines (&it
, 0);
5846 /* The amount of pixels we have to move back is the window
5847 height minus what's displayed in the line containing PT,
5848 and the lines below. */
5851 move_it_by_lines (&it
, nlines
);
5853 if (it
.vpos
== nlines
)
5857 /* Last line has no newline. */
5858 h
-= line_bottom_y (&it
);
5862 /* Don't reserve space for extra line spacing of last line. */
5863 extra_line_spacing
= it
.max_extra_line_spacing
;
5865 /* If we can't move down NLINES lines because we hit
5866 the end of the buffer, count in some empty lines. */
5867 if (it
.vpos
< nlines
)
5870 extra_line_spacing
= it
.extra_line_spacing
;
5871 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5875 bidi_unshelve_cache (itdata
, 0);
5879 /* Now find the new top line (starting position) of the window. */
5880 start_display (&it
, w
, pt
);
5882 move_it_vertically_backward (&it
, h
);
5884 /* If extra line spacing is present, we may move too far
5885 back. This causes the last line to be only partially
5886 visible (which triggers redisplay to recenter that line
5887 in the middle), so move forward.
5888 But ignore extra line spacing on last line, as it is not
5889 considered to be part of the visible height of the line.
5891 h
+= extra_line_spacing
;
5892 while (-it
.current_y
> h
)
5893 move_it_by_lines (&it
, 1);
5895 charpos
= IT_CHARPOS (it
);
5896 bytepos
= IT_BYTEPOS (it
);
5898 bidi_unshelve_cache (itdata
, 0);
5902 struct position pos
;
5904 iarg
= max (iarg
, this_scroll_margin
);
5906 pos
= *vmotion (PT
, PT_BYTE
, -iarg
, w
);
5907 charpos
= pos
.bufpos
;
5908 bytepos
= pos
.bytepos
;
5913 struct position pos
;
5914 int ht
= window_internal_height (w
);
5921 /* Don't let it get into the margin at either top or bottom. */
5922 iarg
= clip_to_bounds (this_scroll_margin
, iarg
,
5923 ht
- this_scroll_margin
- 1);
5925 pos
= *vmotion (PT
, PT_BYTE
, - iarg
, w
);
5926 charpos
= pos
.bufpos
;
5927 bytepos
= pos
.bytepos
;
5930 /* Set the new window start. */
5931 set_marker_both (w
->start
, w
->contents
, charpos
, bytepos
);
5932 w
->window_end_valid
= 0;
5934 w
->optional_new_start
= 1;
5936 w
->start_at_line_beg
= (bytepos
== BEGV_BYTE
5937 || FETCH_BYTE (bytepos
- 1) == '\n');
5944 DEFUN ("window-text-width", Fwindow_text_width
, Swindow_text_width
,
5946 doc
: /* Return the width in columns of the text display area of WINDOW.
5947 WINDOW must be a live window and defaults to the selected one.
5949 The returned width does not include dividers, scrollbars, margins,
5950 fringes, nor any partial-width columns at the right of the text
5953 Optional argument PIXELWISE non-nil, means to return the width in
5955 (Lisp_Object window
, Lisp_Object pixelwise
)
5957 struct window
*w
= decode_live_window (window
);
5959 if (NILP (pixelwise
))
5960 return make_number (window_box_width (w
, TEXT_AREA
)
5961 / FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
)));
5963 return make_number (window_box_width (w
, TEXT_AREA
));
5966 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5968 doc
: /* Return the height in lines of the text display area of WINDOW.
5969 WINDOW must be a live window and defaults to the selected one.
5971 The returned height does not include dividers, the mode line, any header
5972 line, nor any partial-height lines at the bottom of the text area.
5974 Optional argument PIXELWISE non-nil, means to return the height in
5976 (Lisp_Object window
, Lisp_Object pixelwise
)
5978 struct window
*w
= decode_live_window (window
);
5980 if (NILP (pixelwise
))
5981 return make_number (window_box_height (w
)
5982 / FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
)));
5984 return make_number (window_box_height (w
));
5987 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5989 doc
: /* Position point relative to window.
5990 ARG nil means position point at center of window.
5991 Else, ARG specifies vertical position within the window;
5992 zero means top of window, negative means relative to bottom of window. */)
5995 struct window
*w
= XWINDOW (selected_window
);
5999 int this_scroll_margin
;
6002 if (!(BUFFERP (w
->contents
) && XBUFFER (w
->contents
) == current_buffer
))
6003 /* This test is needed to make sure PT/PT_BYTE make sense in w->contents
6004 when passed below to set_marker_both. */
6005 error ("move-to-window-line called from unrelated buffer");
6007 window
= selected_window
;
6008 start
= marker_position (w
->start
);
6009 if (start
< BEGV
|| start
> ZV
)
6011 int height
= window_internal_height (w
);
6012 Fvertical_motion (make_number (- (height
/ 2)), window
);
6013 set_marker_both (w
->start
, w
->contents
, PT
, PT_BYTE
);
6014 w
->start_at_line_beg
= !NILP (Fbolp ());
6018 Fgoto_char (w
->start
);
6020 lines
= displayed_window_lines (w
);
6023 this_scroll_margin
= max (0, min (scroll_margin
, lines
/ 4));
6027 XSETFASTINT (arg
, lines
/ 2);
6030 EMACS_INT iarg
= XINT (Fprefix_numeric_value (arg
));
6033 iarg
= iarg
+ lines
;
6035 #if 0 /* This code would prevent move-to-window-line from moving point
6036 to a place inside the scroll margins (which would cause the
6037 next redisplay to scroll). I wrote this code, but then concluded
6038 it is probably better not to install it. However, it is here
6039 inside #if 0 so as not to lose it. -- rms. */
6041 /* Don't let it get into the margin at either top or bottom. */
6042 iarg
= max (iarg
, this_scroll_margin
);
6043 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
6046 arg
= make_number (iarg
);
6049 /* Skip past a partially visible first line. */
6051 XSETINT (arg
, XINT (arg
) + 1);
6053 return Fvertical_motion (arg
, window
);
6058 /***********************************************************************
6059 Window Configuration
6060 ***********************************************************************/
6062 struct save_window_data
6064 struct vectorlike_header header
;
6065 Lisp_Object selected_frame
;
6066 Lisp_Object current_window
;
6067 Lisp_Object current_buffer
;
6068 Lisp_Object minibuf_scroll_window
;
6069 Lisp_Object minibuf_selected_window
;
6070 Lisp_Object root_window
;
6071 Lisp_Object focus_frame
;
6072 /* A vector, each of whose elements is a struct saved_window
6074 Lisp_Object saved_windows
;
6076 /* All fields above are traced by the GC.
6077 From `frame-cols' down, the fields are ignored by the GC. */
6078 /* We should be able to do without the following two. */
6079 int frame_cols
, frame_lines
;
6080 /* These two should get eventually replaced by their pixel
6082 int frame_menu_bar_lines
, frame_tool_bar_lines
;
6083 int frame_text_width
, frame_text_height
;
6084 /* These are currently unused. We need them as soon as we convert
6086 int frame_menu_bar_height
, frame_tool_bar_height
;
6089 /* This is saved as a Lisp_Vector. */
6092 struct vectorlike_header header
;
6094 Lisp_Object window
, buffer
, start
, pointm
, old_pointm
;
6095 Lisp_Object pixel_left
, pixel_top
, pixel_height
, pixel_width
;
6096 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
6097 Lisp_Object normal_cols
, normal_lines
;
6098 Lisp_Object hscroll
, min_hscroll
, hscroll_whole
, suspend_auto_hscroll
;
6099 Lisp_Object parent
, prev
;
6100 Lisp_Object start_at_line_beg
;
6101 Lisp_Object display_table
;
6102 Lisp_Object left_margin_cols
, right_margin_cols
;
6103 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
6104 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
, dedicated
;
6105 Lisp_Object scroll_bar_height
, horizontal_scroll_bar_type
;
6106 Lisp_Object combination_limit
, window_parameters
;
6109 #define SAVED_WINDOW_N(swv,n) \
6110 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
6112 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
6113 doc
: /* Return t if OBJECT is a window-configuration object. */)
6114 (Lisp_Object object
)
6116 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
6119 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
6120 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
6121 (Lisp_Object config
)
6123 register struct save_window_data
*data
;
6124 struct Lisp_Vector
*saved_windows
;
6126 CHECK_WINDOW_CONFIGURATION (config
);
6128 data
= (struct save_window_data
*) XVECTOR (config
);
6129 saved_windows
= XVECTOR (data
->saved_windows
);
6130 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6133 DEFUN ("set-window-configuration", Fset_window_configuration
,
6134 Sset_window_configuration
, 1, 1, 0,
6135 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
6136 CONFIGURATION must be a value previously returned
6137 by `current-window-configuration' (which see).
6138 If CONFIGURATION was made from a frame that is now deleted,
6139 only frame-independent values can be restored. In this case,
6140 the return value is nil. Otherwise the value is t. */)
6141 (Lisp_Object configuration
)
6143 register struct save_window_data
*data
;
6144 struct Lisp_Vector
*saved_windows
;
6145 Lisp_Object new_current_buffer
;
6148 ptrdiff_t old_point
= -1;
6151 CHECK_WINDOW_CONFIGURATION (configuration
);
6153 data
= (struct save_window_data
*) XVECTOR (configuration
);
6154 saved_windows
= XVECTOR (data
->saved_windows
);
6156 new_current_buffer
= data
->current_buffer
;
6157 if (!BUFFER_LIVE_P (XBUFFER (new_current_buffer
)))
6158 new_current_buffer
= Qnil
;
6161 if (XBUFFER (new_current_buffer
) == current_buffer
)
6162 /* The code further down "preserves point" by saving here PT in
6163 old_point and then setting it later back into PT. When the
6164 current-selected-window and the final-selected-window both show
6165 the current buffer, this suffers from the problem that the
6166 current PT is the window-point of the current-selected-window,
6167 while the final PT is the point of the final-selected-window, so
6168 this copy from one PT to the other would end up moving the
6169 window-point of the final-selected-window to the window-point of
6170 the current-selected-window. So we have to be careful which
6171 point of the current-buffer we copy into old_point. */
6172 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
)
6173 && WINDOWP (selected_window
)
6174 && EQ (XWINDOW (selected_window
)->contents
, new_current_buffer
)
6175 && !EQ (selected_window
, data
->current_window
))
6176 old_point
= marker_position (XWINDOW (data
->current_window
)->pointm
);
6180 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
6181 point in new_current_buffer as of the last time this buffer was
6182 used. This can be non-deterministic since it can be changed by
6183 things like jit-lock by mere temporary selection of some random
6184 window that happens to show this buffer.
6185 So if possible we want this arbitrary choice of "which point" to
6186 be the one from the to-be-selected-window so as to prevent this
6187 window's cursor from being copied from another window. */
6188 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
)
6189 /* If current_window = selected_window, its point is in BUF_PT. */
6190 && !EQ (selected_window
, data
->current_window
))
6191 old_point
= marker_position (XWINDOW (data
->current_window
)->pointm
);
6193 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
6196 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6199 /* If f is a dead frame, don't bother rebuilding its window tree.
6200 However, there is other stuff we should still try to do below. */
6201 if (FRAME_LIVE_P (f
))
6204 Lisp_Object dead_windows
= Qnil
;
6205 register Lisp_Object tem
, par
, pers
;
6206 register struct window
*w
;
6207 register struct saved_window
*p
;
6208 struct window
*root_window
;
6209 struct window
**leaf_windows
;
6214 /* Don't do this within the main loop below: This may call Lisp
6215 code and is thus potentially unsafe while input is blocked. */
6216 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
6218 p
= SAVED_WINDOW_N (saved_windows
, k
);
6220 w
= XWINDOW (window
);
6221 if (BUFFERP (w
->contents
)
6222 && !EQ (w
->contents
, p
->buffer
)
6223 && BUFFER_LIVE_P (XBUFFER (p
->buffer
)))
6224 /* If a window we restore gets another buffer, record the
6225 window's old buffer. */
6226 call1 (Qrecord_window_buffer
, window
);
6229 /* Disallow x_set_window_size, temporarily. */
6230 f
->can_x_set_window_size
= false;
6231 /* The mouse highlighting code could get screwed up
6232 if it runs during this. */
6235 /* "Swap out" point from the selected window's buffer
6236 into the window itself. (Normally the pointm of the selected
6237 window holds garbage.) We do this now, before
6238 restoring the window contents, and prevent it from
6239 being done later on when we select a new window. */
6240 if (! NILP (XWINDOW (selected_window
)->contents
))
6242 w
= XWINDOW (selected_window
);
6243 set_marker_both (w
->pointm
,
6245 BUF_PT (XBUFFER (w
->contents
)),
6246 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6250 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
6252 /* Problem: Freeing all matrices and later allocating them again
6253 is a serious redisplay flickering problem. What we would
6254 really like to do is to free only those matrices not reused
6256 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6257 int nwindows
= count_windows (root_window
);
6258 SAFE_NALLOCA (leaf_windows
, 1, nwindows
);
6259 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
6262 Mark all windows now on frame as "deleted".
6263 Restoring the new configuration "undeletes" any that are in it.
6265 Save their current buffers in their height fields, since we may
6266 need it later, if a buffer saved in the configuration is now
6268 delete_all_child_windows (FRAME_ROOT_WINDOW (f
));
6270 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
6272 p
= SAVED_WINDOW_N (saved_windows
, k
);
6274 w
= XWINDOW (window
);
6275 wset_next (w
, Qnil
);
6277 if (!NILP (p
->parent
))
6279 (w
, SAVED_WINDOW_N (saved_windows
, XFASTINT (p
->parent
))->window
);
6281 wset_parent (w
, Qnil
);
6283 if (!NILP (p
->prev
))
6286 (w
, SAVED_WINDOW_N (saved_windows
, XFASTINT (p
->prev
))->window
);
6287 wset_next (XWINDOW (w
->prev
), p
->window
);
6291 wset_prev (w
, Qnil
);
6292 if (!NILP (w
->parent
))
6293 wset_combination (XWINDOW (w
->parent
),
6294 (XINT (p
->total_cols
)
6295 != XWINDOW (w
->parent
)->total_cols
),
6299 /* If we squirreled away the buffer, restore it now. */
6300 if (BUFFERP (w
->combination_limit
))
6301 wset_buffer (w
, w
->combination_limit
);
6302 w
->pixel_left
= XFASTINT (p
->pixel_left
);
6303 w
->pixel_top
= XFASTINT (p
->pixel_top
);
6304 w
->pixel_width
= XFASTINT (p
->pixel_width
);
6305 w
->pixel_height
= XFASTINT (p
->pixel_height
);
6306 w
->left_col
= XFASTINT (p
->left_col
);
6307 w
->top_line
= XFASTINT (p
->top_line
);
6308 w
->total_cols
= XFASTINT (p
->total_cols
);
6309 w
->total_lines
= XFASTINT (p
->total_lines
);
6310 wset_normal_cols (w
, p
->normal_cols
);
6311 wset_normal_lines (w
, p
->normal_lines
);
6312 w
->hscroll
= XFASTINT (p
->hscroll
);
6313 w
->suspend_auto_hscroll
= !NILP (p
->suspend_auto_hscroll
);
6314 w
->min_hscroll
= XFASTINT (p
->min_hscroll
);
6315 w
->hscroll_whole
= XFASTINT (p
->hscroll_whole
);
6316 wset_display_table (w
, p
->display_table
);
6317 w
->left_margin_cols
= XINT (p
->left_margin_cols
);
6318 w
->right_margin_cols
= XINT (p
->right_margin_cols
);
6319 w
->left_fringe_width
= XINT (p
->left_fringe_width
);
6320 w
->right_fringe_width
= XINT (p
->right_fringe_width
);
6321 w
->fringes_outside_margins
= !NILP (p
->fringes_outside_margins
);
6322 w
->scroll_bar_width
= XINT (p
->scroll_bar_width
);
6323 w
->scroll_bar_height
= XINT (p
->scroll_bar_height
);
6324 wset_vertical_scroll_bar_type (w
, p
->vertical_scroll_bar_type
);
6325 wset_horizontal_scroll_bar_type (w
, p
->horizontal_scroll_bar_type
);
6326 wset_dedicated (w
, p
->dedicated
);
6327 wset_combination_limit (w
, p
->combination_limit
);
6328 /* Restore any window parameters that have been saved.
6329 Parameters that have not been saved are left alone. */
6330 for (tem
= p
->window_parameters
; CONSP (tem
); tem
= XCDR (tem
))
6335 if (NILP (XCDR (pers
)))
6337 par
= Fassq (XCAR (pers
), w
->window_parameters
);
6338 if (CONSP (par
) && !NILP (XCDR (par
)))
6339 /* Reset a parameter to nil if and only if it
6340 has a non-nil association. Don't make new
6342 Fsetcdr (par
, Qnil
);
6345 /* Always restore a non-nil value. */
6346 Fset_window_parameter (window
, XCAR (pers
), XCDR (pers
));
6350 if (BUFFERP (p
->buffer
) && BUFFER_LIVE_P (XBUFFER (p
->buffer
)))
6351 /* If saved buffer is alive, install it. */
6353 wset_buffer (w
, p
->buffer
);
6354 w
->start_at_line_beg
= !NILP (p
->start_at_line_beg
);
6355 set_marker_restricted (w
->start
, p
->start
, w
->contents
);
6356 set_marker_restricted (w
->pointm
, p
->pointm
, w
->contents
);
6357 set_marker_restricted (w
->old_pointm
, p
->old_pointm
, w
->contents
);
6358 /* As documented in Fcurrent_window_configuration, don't
6359 restore the location of point in the buffer which was
6360 current when the window configuration was recorded. */
6361 if (!EQ (p
->buffer
, new_current_buffer
)
6362 && XBUFFER (p
->buffer
) == current_buffer
)
6363 Fgoto_char (w
->pointm
);
6365 else if (BUFFERP (w
->contents
) && BUFFER_LIVE_P (XBUFFER (w
->contents
)))
6366 /* Keep window's old buffer; make sure the markers are real. */
6368 /* Set window markers at start of visible range. */
6369 if (XMARKER (w
->start
)->buffer
== 0)
6370 set_marker_restricted_both (w
->start
, w
->contents
, 0, 0);
6371 if (XMARKER (w
->pointm
)->buffer
== 0)
6372 set_marker_restricted_both
6373 (w
->pointm
, w
->contents
,
6374 BUF_PT (XBUFFER (w
->contents
)),
6375 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6376 if (XMARKER (w
->old_pointm
)->buffer
== 0)
6377 set_marker_restricted_both
6378 (w
->old_pointm
, w
->contents
,
6379 BUF_PT (XBUFFER (w
->contents
)),
6380 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6381 w
->start_at_line_beg
= 1;
6383 else if (!NILP (w
->start
))
6384 /* Leaf window has no live buffer, get one. */
6386 /* Get the buffer via other_buffer_safely in order to
6387 avoid showing an unimportant buffer and, if necessary, to
6388 recreate *scratch* in the course (part of Juanma's bs-show
6389 scenario from March 2011). */
6390 wset_buffer (w
, other_buffer_safely (Fcurrent_buffer ()));
6391 /* This will set the markers to beginning of visible
6393 set_marker_restricted_both (w
->start
, w
->contents
, 0, 0);
6394 set_marker_restricted_both (w
->pointm
, w
->contents
, 0, 0);
6395 set_marker_restricted_both (w
->old_pointm
, w
->contents
, 0, 0);
6396 w
->start_at_line_beg
= 1;
6397 if (!NILP (w
->dedicated
))
6398 /* Record this window as dead. */
6399 dead_windows
= Fcons (window
, dead_windows
);
6400 /* Make sure window is no more dedicated. */
6401 wset_dedicated (w
, Qnil
);
6405 fset_root_window (f
, data
->root_window
);
6406 /* Arrange *not* to restore point in the buffer that was
6407 current when the window configuration was saved. */
6408 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
))
6409 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
6410 make_number (old_point
),
6411 XWINDOW (data
->current_window
)->contents
);
6413 /* In the following call to `select-window', prevent "swapping out
6414 point" in the old selected window using the buffer that has
6415 been restored into it. We already swapped out that point from
6416 that window's old buffer.
6418 Do not record the buffer here. We do that in a separate call
6419 to select_window below. See also Bug#16207. */
6420 select_window (data
->current_window
, Qt
, 1);
6421 BVAR (XBUFFER (XWINDOW (selected_window
)->contents
),
6422 last_selected_window
)
6425 if (NILP (data
->focus_frame
)
6426 || (FRAMEP (data
->focus_frame
)
6427 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
6428 Fredirect_frame_focus (frame
, data
->focus_frame
);
6430 /* Now, free glyph matrices in windows that were not reused. */
6431 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
6433 if (NILP (leaf_windows
[i
]->contents
))
6434 free_window_matrices (leaf_windows
[i
]);
6435 else if (EQ (leaf_windows
[i
]->contents
, new_current_buffer
))
6439 /* Allow x_set_window_size again and apply frame size changes if
6441 f
->can_x_set_window_size
= true;
6442 adjust_frame_size (f
, -1, -1, 1, 0, Qnil
);
6444 adjust_frame_glyphs (f
);
6447 /* Scan dead buffer windows. */
6448 for (; CONSP (dead_windows
); dead_windows
= XCDR (dead_windows
))
6450 window
= XCAR (dead_windows
);
6451 if (WINDOW_LIVE_P (window
) && !EQ (window
, FRAME_ROOT_WINDOW (f
)))
6452 delete_deletable_window (window
);
6455 /* Record the selected window's buffer here. The window should
6456 already be the selected one from the call above. */
6457 select_window (data
->current_window
, Qnil
, 0);
6459 /* Fselect_window will have made f the selected frame, so we
6460 reselect the proper frame here. Fhandle_switch_frame will change the
6461 selected window too, but that doesn't make the call to
6462 Fselect_window above totally superfluous; it still sets f's
6464 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
6465 do_switch_frame (data
->selected_frame
, 0, 0, Qnil
);
6467 run_window_configuration_change_hook (f
);
6470 if (!NILP (new_current_buffer
))
6472 Fset_buffer (new_current_buffer
);
6473 /* If the new current buffer doesn't appear in the selected
6474 window, go to its old point (see bug#12208). */
6475 if (!EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
))
6476 Fgoto_char (make_number (old_point
));
6479 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
6480 minibuf_selected_window
= data
->minibuf_selected_window
;
6483 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
6488 restore_window_configuration (Lisp_Object configuration
)
6490 Fset_window_configuration (configuration
);
6494 /* If WINDOW is an internal window, recursively delete all child windows
6495 reachable via the next and contents slots of WINDOW. Otherwise setup
6496 WINDOW to not show any buffer. */
6499 delete_all_child_windows (Lisp_Object window
)
6501 register struct window
*w
;
6503 w
= XWINDOW (window
);
6505 if (!NILP (w
->next
))
6506 /* Delete WINDOW's siblings (we traverse postorderly). */
6507 delete_all_child_windows (w
->next
);
6509 if (WINDOWP (w
->contents
))
6511 delete_all_child_windows (w
->contents
);
6512 wset_combination (w
, 0, Qnil
);
6514 else if (BUFFERP (w
->contents
))
6517 unchain_marker (XMARKER (w
->pointm
));
6518 unchain_marker (XMARKER (w
->old_pointm
));
6519 unchain_marker (XMARKER (w
->start
));
6520 /* Since combination limit makes sense for an internal windows
6521 only, we use this slot to save the buffer for the sake of
6522 possible resurrection in Fset_window_configuration. */
6523 wset_combination_limit (w
, w
->contents
);
6524 wset_buffer (w
, Qnil
);
6527 Vwindow_list
= Qnil
;
6531 count_windows (register struct window
*window
)
6533 register int count
= 1;
6534 if (!NILP (window
->next
))
6535 count
+= count_windows (XWINDOW (window
->next
));
6536 if (WINDOWP (window
->contents
))
6537 count
+= count_windows (XWINDOW (window
->contents
));
6542 /* Fill vector FLAT with leaf windows under W, starting at index I.
6543 Value is last index + 1. */
6545 get_leaf_windows (struct window
*w
, struct window
**flat
, int i
)
6549 if (WINDOWP (w
->contents
))
6550 i
= get_leaf_windows (XWINDOW (w
->contents
), flat
, i
);
6554 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6561 /* Return a pointer to the glyph W's physical cursor is on. Value is
6562 null if W's current matrix is invalid, so that no meaningful glyph
6565 get_phys_cursor_glyph (struct window
*w
)
6567 struct glyph_row
*row
;
6568 struct glyph
*glyph
;
6569 int hpos
= w
->phys_cursor
.hpos
;
6571 if (!(w
->phys_cursor
.vpos
>= 0
6572 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
))
6575 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
6576 if (!row
->enabled_p
)
6581 /* When the window is hscrolled, cursor hpos can legitimately be
6582 out of bounds, but we draw the cursor at the corresponding
6583 window margin in that case. */
6584 if (!row
->reversed_p
&& hpos
< 0)
6586 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
6587 hpos
= row
->used
[TEXT_AREA
] - 1;
6590 if (0 <= hpos
&& hpos
< row
->used
[TEXT_AREA
])
6591 glyph
= row
->glyphs
[TEXT_AREA
] + hpos
;
6600 save_window_save (Lisp_Object window
, struct Lisp_Vector
*vector
, int i
)
6602 register struct saved_window
*p
;
6603 register struct window
*w
;
6604 register Lisp_Object tem
, pers
, par
;
6606 for (; !NILP (window
); window
= w
->next
)
6608 p
= SAVED_WINDOW_N (vector
, i
);
6609 w
= XWINDOW (window
);
6611 wset_temslot (w
, make_number (i
)); i
++;
6613 p
->buffer
= (WINDOW_LEAF_P (w
) ? w
->contents
: Qnil
);
6614 p
->pixel_left
= make_number (w
->pixel_left
);
6615 p
->pixel_top
= make_number (w
->pixel_top
);
6616 p
->pixel_width
= make_number (w
->pixel_width
);
6617 p
->pixel_height
= make_number (w
->pixel_height
);
6618 p
->left_col
= make_number (w
->left_col
);
6619 p
->top_line
= make_number (w
->top_line
);
6620 p
->total_cols
= make_number (w
->total_cols
);
6621 p
->total_lines
= make_number (w
->total_lines
);
6622 p
->normal_cols
= w
->normal_cols
;
6623 p
->normal_lines
= w
->normal_lines
;
6624 XSETFASTINT (p
->hscroll
, w
->hscroll
);
6625 p
->suspend_auto_hscroll
= w
->suspend_auto_hscroll
? Qt
: Qnil
;
6626 XSETFASTINT (p
->min_hscroll
, w
->min_hscroll
);
6627 XSETFASTINT (p
->hscroll_whole
, w
->hscroll_whole
);
6628 p
->display_table
= w
->display_table
;
6629 p
->left_margin_cols
= make_number (w
->left_margin_cols
);
6630 p
->right_margin_cols
= make_number (w
->right_margin_cols
);
6631 p
->left_fringe_width
= make_number (w
->left_fringe_width
);
6632 p
->right_fringe_width
= make_number (w
->right_fringe_width
);
6633 p
->fringes_outside_margins
= w
->fringes_outside_margins
? Qt
: Qnil
;
6634 p
->scroll_bar_width
= make_number (w
->scroll_bar_width
);
6635 p
->scroll_bar_height
= make_number (w
->scroll_bar_height
);
6636 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
6637 p
->horizontal_scroll_bar_type
= w
->horizontal_scroll_bar_type
;
6638 p
->dedicated
= w
->dedicated
;
6639 p
->combination_limit
= w
->combination_limit
;
6640 p
->window_parameters
= Qnil
;
6642 if (!NILP (Vwindow_persistent_parameters
))
6644 /* Run cycle detection on Vwindow_persistent_parameters. */
6645 Lisp_Object tortoise
, hare
;
6647 hare
= tortoise
= Vwindow_persistent_parameters
;
6648 while (CONSP (hare
))
6655 tortoise
= XCDR (tortoise
);
6657 if (EQ (hare
, tortoise
))
6658 /* Reset Vwindow_persistent_parameters to Qnil. */
6660 Vwindow_persistent_parameters
= Qnil
;
6665 for (tem
= Vwindow_persistent_parameters
; CONSP (tem
);
6669 /* Save values for persistent window parameters. */
6670 if (CONSP (pers
) && !NILP (XCDR (pers
)))
6672 par
= Fassq (XCAR (pers
), w
->window_parameters
);
6674 /* If the window has no value for the parameter,
6676 p
->window_parameters
= Fcons (Fcons (XCAR (pers
), Qnil
),
6677 p
->window_parameters
);
6679 /* If the window has a value for the parameter,
6681 p
->window_parameters
= Fcons (Fcons (XCAR (par
),
6683 p
->window_parameters
);
6688 if (BUFFERP (w
->contents
))
6690 /* Save w's value of point in the window configuration. If w
6691 is the selected window, then get the value of point from
6692 the buffer; pointm is garbage in the selected window. */
6693 if (EQ (window
, selected_window
))
6694 p
->pointm
= build_marker (XBUFFER (w
->contents
),
6695 BUF_PT (XBUFFER (w
->contents
)),
6696 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6698 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
6699 p
->old_pointm
= Fcopy_marker (w
->old_pointm
, Qnil
);
6700 XMARKER (p
->pointm
)->insertion_type
6701 = !NILP (buffer_local_value
/* Don't signal error if void. */
6702 (Qwindow_point_insertion_type
, w
->contents
));
6703 XMARKER (p
->old_pointm
)->insertion_type
6704 = !NILP (buffer_local_value
/* Don't signal error if void. */
6705 (Qwindow_point_insertion_type
, w
->contents
));
6707 p
->start
= Fcopy_marker (w
->start
, Qnil
);
6708 p
->start_at_line_beg
= w
->start_at_line_beg
? Qt
: Qnil
;
6713 p
->old_pointm
= Qnil
;
6715 p
->start_at_line_beg
= Qnil
;
6718 p
->parent
= NILP (w
->parent
) ? Qnil
: XWINDOW (w
->parent
)->temslot
;
6719 p
->prev
= NILP (w
->prev
) ? Qnil
: XWINDOW (w
->prev
)->temslot
;
6721 if (WINDOWP (w
->contents
))
6722 i
= save_window_save (w
->contents
, vector
, i
);
6728 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
6729 Scurrent_window_configuration
, 0, 1, 0,
6730 doc
: /* Return an object representing the current window configuration of FRAME.
6731 If FRAME is nil or omitted, use the selected frame.
6732 This describes the number of windows, their sizes and current buffers,
6733 and for each displayed buffer, where display starts, and the position of
6734 point. An exception is made for point in the current buffer:
6735 its value is -not- saved.
6736 This also records the currently selected frame, and FRAME's focus
6737 redirection (see `redirect-frame-focus'). The variable
6738 `window-persistent-parameters' specifies which window parameters are
6739 saved by this function. */)
6742 register Lisp_Object tem
;
6743 register int n_windows
;
6744 register struct save_window_data
*data
;
6746 struct frame
*f
= decode_live_frame (frame
);
6748 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6749 data
= ALLOCATE_PSEUDOVECTOR (struct save_window_data
, frame_cols
,
6750 PVEC_WINDOW_CONFIGURATION
);
6752 data
->frame_cols
= FRAME_COLS (f
);
6753 data
->frame_lines
= FRAME_LINES (f
);
6754 data
->frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6755 data
->frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6756 data
->frame_text_width
= FRAME_TEXT_WIDTH (f
);
6757 data
->frame_text_height
= FRAME_TEXT_HEIGHT (f
);
6758 data
->frame_menu_bar_height
= FRAME_MENU_BAR_HEIGHT (f
);
6759 data
->frame_tool_bar_height
= FRAME_TOOL_BAR_HEIGHT (f
);
6760 data
->selected_frame
= selected_frame
;
6761 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6762 XSETBUFFER (data
->current_buffer
, current_buffer
);
6763 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6764 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6765 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6766 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6767 tem
= make_uninit_vector (n_windows
);
6768 data
->saved_windows
= tem
;
6769 for (i
= 0; i
< n_windows
; i
++)
6771 Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
));
6772 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6773 XSETWINDOW_CONFIGURATION (tem
, data
);
6777 /* Called after W's margins, fringes or scroll bars was adjusted. */
6780 apply_window_adjustment (struct window
*w
)
6783 clear_glyph_matrix (w
->current_matrix
);
6784 w
->window_end_valid
= 0;
6785 windows_or_buffers_changed
= 30;
6787 adjust_frame_glyphs (XFRAME (WINDOW_FRAME (w
)));
6791 /***********************************************************************
6793 ***********************************************************************/
6795 static struct window
*
6796 set_window_margins (struct window
*w
, Lisp_Object left_width
,
6797 Lisp_Object right_width
)
6800 int unit
= WINDOW_FRAME_COLUMN_WIDTH (w
);
6802 left
= (NILP (left_width
) ? 0
6803 : (CHECK_NATNUM (left_width
), XINT (left_width
)));
6804 right
= (NILP (right_width
) ? 0
6805 : (CHECK_NATNUM (right_width
), XINT (right_width
)));
6807 if (w
->left_margin_cols
!= left
|| w
->right_margin_cols
!= right
)
6809 /* Don't change anything if new margins won't fit. */
6810 if ((WINDOW_PIXEL_WIDTH (w
)
6811 - WINDOW_FRINGES_WIDTH (w
)
6812 - WINDOW_SCROLL_BAR_AREA_WIDTH (w
)
6813 - (left
+ right
) * unit
)
6814 >= MIN_SAFE_WINDOW_PIXEL_WIDTH (w
))
6816 w
->left_margin_cols
= left
;
6817 w
->right_margin_cols
= right
;
6828 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6830 doc
: /* Set width of marginal areas of window WINDOW.
6831 WINDOW must be a live window and defaults to the selected one.
6833 Second arg LEFT-WIDTH specifies the number of character cells to
6834 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6835 does the same for the right marginal area. A nil width parameter
6838 Return t if any margin was actually changed and nil otherwise. */)
6839 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
)
6841 struct window
*w
= set_window_margins (decode_live_window (window
),
6842 left_width
, right_width
);
6843 return w
? (apply_window_adjustment (w
), Qt
) : Qnil
;
6847 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6849 doc
: /* Get width of marginal areas of window WINDOW.
6850 WINDOW must be a live window and defaults to the selected one.
6852 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6853 If a marginal area does not exist, its width will be returned
6855 (Lisp_Object window
)
6857 struct window
*w
= decode_live_window (window
);
6858 return Fcons (w
->left_margin_cols
6859 ? make_number (w
->left_margin_cols
) : Qnil
,
6860 w
->right_margin_cols
6861 ? make_number (w
->right_margin_cols
) : Qnil
);
6866 /***********************************************************************
6868 ***********************************************************************/
6870 static struct window
*
6871 set_window_fringes (struct window
*w
, Lisp_Object left_width
,
6872 Lisp_Object right_width
, Lisp_Object outside_margins
)
6874 int left
, right
, outside
= !NILP (outside_margins
);
6876 left
= (NILP (left_width
) ? -1
6877 : (CHECK_NATNUM (left_width
), XINT (left_width
)));
6878 right
= (NILP (right_width
) ? -1
6879 : (CHECK_NATNUM (right_width
), XINT (right_width
)));
6881 /* Do nothing on a tty or if nothing to actually change. */
6882 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6883 && (w
->left_fringe_width
!= left
6884 || w
->right_fringe_width
!= right
6885 || w
->fringes_outside_margins
!= outside
))
6887 if (left
> 0 || right
> 0)
6889 /* Don't change anything if new fringes don't fit. */
6890 if ((WINDOW_PIXEL_WIDTH (w
)
6891 - WINDOW_MARGINS_WIDTH (w
)
6892 - WINDOW_SCROLL_BAR_AREA_WIDTH (w
)
6893 - max (left
, 0) - max (right
, 0))
6894 < MIN_SAFE_WINDOW_PIXEL_WIDTH (w
))
6898 w
->left_fringe_width
= left
;
6899 w
->right_fringe_width
= right
;
6900 w
->fringes_outside_margins
= outside
;
6908 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6910 doc
: /* Set the fringe widths of window WINDOW.
6911 WINDOW must be a live window and defaults to the selected one.
6913 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6914 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6915 fringe width. If a fringe width arg is nil, that means to use the
6916 frame's default fringe width. Default fringe widths can be set with
6917 the command `set-fringe-style'.
6918 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6919 outside of the display margins. By default, fringes are drawn between
6920 display marginal areas and the text area.
6922 Return t if any fringe was actually changed and nil otherwise. */)
6923 (Lisp_Object window
, Lisp_Object left_width
,
6924 Lisp_Object right_width
, Lisp_Object outside_margins
)
6927 = set_window_fringes (decode_live_window (window
),
6928 left_width
, right_width
, outside_margins
);
6929 return w
? (apply_window_adjustment (w
), Qt
) : Qnil
;
6933 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6935 doc
: /* Get width of fringes of window WINDOW.
6936 WINDOW must be a live window and defaults to the selected one.
6938 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6939 (Lisp_Object window
)
6941 struct window
*w
= decode_live_window (window
);
6943 return list3 (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6944 make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6945 WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
) ? Qt
: Qnil
);
6950 /***********************************************************************
6952 ***********************************************************************/
6954 static struct window
*
6955 set_window_scroll_bars (struct window
*w
, Lisp_Object width
,
6956 Lisp_Object vertical_type
, Lisp_Object height
,
6957 Lisp_Object horizontal_type
)
6959 int iwidth
= (NILP (width
) ? -1 : (CHECK_NATNUM (width
), XINT (width
)));
6963 vertical_type
= Qnil
;
6965 if (!(NILP (vertical_type
)
6966 || EQ (vertical_type
, Qleft
)
6967 || EQ (vertical_type
, Qright
)
6968 || EQ (vertical_type
, Qt
)))
6969 error ("Invalid type of vertical scroll bar");
6971 if (w
->scroll_bar_width
!= iwidth
6972 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6974 /* Don't change anything if new scroll bar won't fit. */
6975 if ((WINDOW_PIXEL_WIDTH (w
)
6976 - WINDOW_MARGINS_WIDTH (w
)
6977 - WINDOW_FRINGES_WIDTH (w
)
6979 >= MIN_SAFE_WINDOW_PIXEL_WIDTH (w
))
6981 w
->scroll_bar_width
= iwidth
;
6982 wset_vertical_scroll_bar_type (w
, vertical_type
);
6987 #if USE_HORIZONTAL_SCROLL_BARS
6989 int iheight
= (NILP (height
) ? -1 : (CHECK_NATNUM (height
), XINT (height
)));
6991 if (MINI_WINDOW_P (w
) || iheight
== 0)
6992 horizontal_type
= Qnil
;
6994 if (!(NILP (horizontal_type
)
6995 || EQ (horizontal_type
, Qbottom
)
6996 || EQ (horizontal_type
, Qt
)))
6997 error ("Invalid type of horizontal scroll bar");
6999 if (w
->scroll_bar_height
!= iheight
7000 || !EQ (w
->horizontal_scroll_bar_type
, horizontal_type
))
7002 /* Don't change anything if new scroll bar won't fit. */
7003 if ((WINDOW_PIXEL_HEIGHT (w
)
7004 - WINDOW_HEADER_LINE_HEIGHT (w
)
7005 - WINDOW_MODE_LINE_HEIGHT (w
)
7007 >= MIN_SAFE_WINDOW_PIXEL_HEIGHT (w
))
7009 w
->scroll_bar_height
= iheight
;
7010 wset_horizontal_scroll_bar_type (w
, horizontal_type
);
7016 wset_horizontal_scroll_bar_type (w
, Qnil
);
7019 return changed
? w
: NULL
;
7022 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
,
7023 Sset_window_scroll_bars
, 1, 5, 0,
7024 doc
: /* Set width and type of scroll bars of window WINDOW.
7025 WINDOW must be a live window and defaults to the selected one.
7027 Second parameter WIDTH specifies the pixel width for the vertical scroll
7028 bar. If WIDTH is nil, use the scroll-bar width of WINDOW's frame.
7029 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
7030 bar: left, right, or nil. If VERTICAL-TYPE is t, this means use the
7031 frame's scroll-bar type.
7033 Fourth parameter HEIGHT specifies the pixel height for the horizontal
7034 scroll bar. If HEIGHT is nil, use the scroll-bar height of WINDOW's
7035 frame. Fifth parameter HORIZONTAL-TYPE specifies the type of the
7036 horizontal scroll bar: nil, bottom, or t. If HORIZONTAL-TYPE is t, this
7037 means to use the frame's horizontal scroll-bar type.
7039 Return t if scroll bars were actually changed and nil otherwise. */)
7040 (Lisp_Object window
, Lisp_Object width
, Lisp_Object vertical_type
,
7041 Lisp_Object height
, Lisp_Object horizontal_type
)
7044 = set_window_scroll_bars (decode_live_window (window
),
7045 width
, vertical_type
, height
, horizontal_type
);
7046 return w
? (apply_window_adjustment (w
), Qt
) : Qnil
;
7050 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
7052 doc
: /* Get width and type of scroll bars of window WINDOW.
7053 WINDOW must be a live window and defaults to the selected one.
7055 Value is a list of the form (WIDTH COLUMNS VERTICAL-TYPE HEIGHT LINES
7056 HORIZONTAL-TYPE). If WIDTH or HEIGHT is nil or VERTICAL-TYPE or
7057 HORIZONTAL-TYPE is t, the window is using the frame's corresponding
7059 (Lisp_Object window
)
7061 struct window
*w
= decode_live_window (window
);
7063 return Fcons (((w
->scroll_bar_width
>= 0)
7064 ? make_number (w
->scroll_bar_width
)
7066 list5 (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
7067 w
->vertical_scroll_bar_type
,
7068 ((w
->scroll_bar_height
>= 0)
7069 ? make_number (w
->scroll_bar_height
)
7071 make_number (WINDOW_SCROLL_BAR_LINES (w
)),
7072 w
->horizontal_scroll_bar_type
));
7075 /***********************************************************************
7077 ***********************************************************************/
7079 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
7080 doc
: /* Return the amount by which WINDOW is scrolled vertically.
7081 If WINDOW is omitted or nil, it defaults to the selected window.
7082 Normally, value is a multiple of the canonical character height of WINDOW;
7083 optional second arg PIXELS-P means value is measured in pixels. */)
7084 (Lisp_Object window
, Lisp_Object pixels_p
)
7087 struct window
*w
= decode_live_window (window
);
7088 struct frame
*f
= XFRAME (w
->frame
);
7090 if (FRAME_WINDOW_P (f
))
7091 result
= (NILP (pixels_p
)
7092 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
7093 : make_number (-w
->vscroll
));
7095 result
= make_number (0);
7100 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
7102 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
7103 WINDOW nil means use the selected window. Normally, VSCROLL is a
7104 non-negative multiple of the canonical character height of WINDOW;
7105 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
7106 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
7107 corresponds to an integral number of pixels. The return value is the
7108 result of this rounding.
7109 If PIXELS-P is non-nil, the return value is VSCROLL. */)
7110 (Lisp_Object window
, Lisp_Object vscroll
, Lisp_Object pixels_p
)
7112 struct window
*w
= decode_live_window (window
);
7113 struct frame
*f
= XFRAME (w
->frame
);
7115 CHECK_NUMBER_OR_FLOAT (vscroll
);
7117 if (FRAME_WINDOW_P (f
))
7119 int old_dy
= w
->vscroll
;
7121 w
->vscroll
= - (NILP (pixels_p
)
7122 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
7123 : XFLOATINT (vscroll
));
7124 w
->vscroll
= min (w
->vscroll
, 0);
7126 if (w
->vscroll
!= old_dy
)
7128 /* Adjust glyph matrix of the frame if the virtual display
7129 area becomes larger than before. */
7130 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
7131 adjust_frame_glyphs (f
);
7133 /* Prevent redisplay shortcuts. */
7134 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
7138 return Fwindow_vscroll (window
, pixels_p
);
7142 /* Call FN for all leaf windows on frame F. FN is called with the
7143 first argument being a pointer to the leaf window, and with
7144 additional argument USER_DATA. Stops when FN returns 0. */
7147 foreach_window (struct frame
*f
, int (*fn
) (struct window
*, void *),
7150 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
7151 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
7152 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
7156 /* Helper function for foreach_window. Call FN for all leaf windows
7157 reachable from W. FN is called with the first argument being a
7158 pointer to the leaf window, and with additional argument USER_DATA.
7159 Stop when FN returns 0. Value is 0 if stopped by FN. */
7162 foreach_window_1 (struct window
*w
, int (*fn
) (struct window
*, void *), void *user_data
)
7166 for (cont
= 1; w
&& cont
;)
7168 if (WINDOWP (w
->contents
))
7169 cont
= foreach_window_1 (XWINDOW (w
->contents
), fn
, user_data
);
7171 cont
= fn (w
, user_data
);
7173 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
7179 /***********************************************************************
7181 ***********************************************************************/
7183 /* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2
7184 describe the same state of affairs. This is used by Fequal.
7186 IGNORE_POSITIONS means ignore non-matching scroll positions
7189 This ignores a couple of things like the dedication status of
7190 window, combination_limit and the like. This might have to be
7194 compare_window_configurations (Lisp_Object configuration1
,
7195 Lisp_Object configuration2
,
7196 bool ignore_positions
)
7198 register struct save_window_data
*d1
, *d2
;
7199 struct Lisp_Vector
*sws1
, *sws2
;
7202 CHECK_WINDOW_CONFIGURATION (configuration1
);
7203 CHECK_WINDOW_CONFIGURATION (configuration2
);
7205 d1
= (struct save_window_data
*) XVECTOR (configuration1
);
7206 d2
= (struct save_window_data
*) XVECTOR (configuration2
);
7207 sws1
= XVECTOR (d1
->saved_windows
);
7208 sws2
= XVECTOR (d2
->saved_windows
);
7210 /* Frame settings must match. */
7211 if (d1
->frame_cols
!= d2
->frame_cols
7212 || d1
->frame_lines
!= d2
->frame_lines
7213 || d1
->frame_menu_bar_lines
!= d2
->frame_menu_bar_lines
7214 || !EQ (d1
->selected_frame
, d2
->selected_frame
)
7215 || !EQ (d1
->current_buffer
, d2
->current_buffer
)
7216 || (!ignore_positions
7217 && (!EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
)
7218 || !EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
)))
7219 || !EQ (d1
->focus_frame
, d2
->focus_frame
)
7220 /* Verify that the two configurations have the same number of windows. */
7221 || sws1
->header
.size
!= sws2
->header
.size
)
7224 for (i
= 0; i
< sws1
->header
.size
; i
++)
7226 struct saved_window
*sw1
, *sw2
;
7228 sw1
= SAVED_WINDOW_N (sws1
, i
);
7229 sw2
= SAVED_WINDOW_N (sws2
, i
);
7232 /* The "current" windows in the two configurations must
7233 correspond to each other. */
7234 EQ (d1
->current_window
, sw1
->window
)
7235 != EQ (d2
->current_window
, sw2
->window
)
7236 /* Windows' buffers must match. */
7237 || !EQ (sw1
->buffer
, sw2
->buffer
)
7238 || !EQ (sw1
->pixel_left
, sw2
->pixel_left
)
7239 || !EQ (sw1
->pixel_top
, sw2
->pixel_top
)
7240 || !EQ (sw1
->pixel_height
, sw2
->pixel_height
)
7241 || !EQ (sw1
->pixel_width
, sw2
->pixel_width
)
7242 || !EQ (sw1
->left_col
, sw2
->left_col
)
7243 || !EQ (sw1
->top_line
, sw2
->top_line
)
7244 || !EQ (sw1
->total_cols
, sw2
->total_cols
)
7245 || !EQ (sw1
->total_lines
, sw2
->total_lines
)
7246 || !EQ (sw1
->display_table
, sw2
->display_table
)
7247 /* The next two disjuncts check the window structure for
7249 || !EQ (sw1
->parent
, sw2
->parent
)
7250 || !EQ (sw1
->prev
, sw2
->prev
)
7251 || (!ignore_positions
7252 && (!EQ (sw1
->hscroll
, sw2
->hscroll
)
7253 || !EQ (sw1
->min_hscroll
, sw2
->min_hscroll
)
7254 || !EQ (sw1
->start_at_line_beg
, sw2
->start_at_line_beg
)
7255 || NILP (Fequal (sw1
->start
, sw2
->start
))
7256 || NILP (Fequal (sw1
->pointm
, sw2
->pointm
))))
7257 || !EQ (sw1
->left_margin_cols
, sw2
->left_margin_cols
)
7258 || !EQ (sw1
->right_margin_cols
, sw2
->right_margin_cols
)
7259 || !EQ (sw1
->left_fringe_width
, sw2
->left_fringe_width
)
7260 || !EQ (sw1
->right_fringe_width
, sw2
->right_fringe_width
)
7261 || !EQ (sw1
->fringes_outside_margins
, sw2
->fringes_outside_margins
)
7262 || !EQ (sw1
->scroll_bar_width
, sw2
->scroll_bar_width
)
7263 || !EQ (sw1
->scroll_bar_height
, sw2
->scroll_bar_height
)
7264 || !EQ (sw1
->vertical_scroll_bar_type
, sw2
->vertical_scroll_bar_type
)
7265 || !EQ (sw1
->horizontal_scroll_bar_type
, sw2
->horizontal_scroll_bar_type
))
7272 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
7273 Scompare_window_configurations
, 2, 2, 0,
7274 doc
: /* Compare two window configurations as regards the structure of windows.
7275 This function ignores details such as the values of point
7276 and scrolling positions. */)
7277 (Lisp_Object x
, Lisp_Object y
)
7279 if (compare_window_configurations (x
, y
, 1))
7285 init_window_once (void)
7287 struct frame
*f
= make_initial_frame ();
7288 XSETFRAME (selected_frame
, f
);
7289 Vterminal_frame
= selected_frame
;
7290 minibuf_window
= f
->minibuffer_window
;
7291 selected_window
= f
->selected_window
;
7297 Vwindow_list
= Qnil
;
7301 syms_of_window (void)
7303 DEFSYM (Qscroll_up
, "scroll-up");
7304 DEFSYM (Qscroll_down
, "scroll-down");
7305 DEFSYM (Qscroll_command
, "scroll-command");
7307 Fput (Qscroll_up
, Qscroll_command
, Qt
);
7308 Fput (Qscroll_down
, Qscroll_command
, Qt
);
7310 DEFSYM (Qwindow_configuration_change_hook
, "window-configuration-change-hook");
7311 DEFSYM (Qwindowp
, "windowp");
7312 DEFSYM (Qwindow_configuration_p
, "window-configuration-p");
7313 DEFSYM (Qwindow_live_p
, "window-live-p");
7314 DEFSYM (Qwindow_valid_p
, "window-valid-p");
7315 DEFSYM (Qwindow_deletable_p
, "window-deletable-p");
7316 DEFSYM (Qdelete_window
, "delete-window");
7317 DEFSYM (Qwindow_resize_root_window
, "window--resize-root-window");
7318 DEFSYM (Qwindow_resize_root_window_vertically
, "window--resize-root-window-vertically");
7319 DEFSYM (Qwindow_sanitize_window_sizes
, "window--sanitize-window-sizes");
7320 DEFSYM (Qwindow_pixel_to_total
, "window--pixel-to-total");
7321 DEFSYM (Qsafe
, "safe");
7322 DEFSYM (Qdisplay_buffer
, "display-buffer");
7323 DEFSYM (Qreplace_buffer_in_windows
, "replace-buffer-in-windows");
7324 DEFSYM (Qrecord_window_buffer
, "record-window-buffer");
7325 DEFSYM (Qget_mru_window
, "get-mru-window");
7326 DEFSYM (Qwindow_size
, "window-size");
7327 DEFSYM (Qtemp_buffer_show_hook
, "temp-buffer-show-hook");
7328 DEFSYM (Qabove
, "above");
7329 DEFSYM (Qbelow
, "below");
7330 DEFSYM (Qclone_of
, "clone-of");
7331 DEFSYM (Qfloor
, "floor");
7332 DEFSYM (Qceiling
, "ceiling");
7334 staticpro (&Vwindow_list
);
7336 minibuf_selected_window
= Qnil
;
7337 staticpro (&minibuf_selected_window
);
7339 window_scroll_pixel_based_preserve_x
= -1;
7340 window_scroll_pixel_based_preserve_y
= -1;
7341 window_scroll_preserve_hpos
= -1;
7342 window_scroll_preserve_vpos
= -1;
7344 DEFVAR_LISP ("temp-buffer-show-function", Vtemp_buffer_show_function
,
7345 doc
: /* Non-nil means call as function to display a help buffer.
7346 The function is called with one argument, the buffer to be displayed.
7347 Used by `with-output-to-temp-buffer'.
7348 If this function is used, then it must do the entire job of showing
7349 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
7350 Vtemp_buffer_show_function
= Qnil
;
7352 DEFVAR_LISP ("minibuffer-scroll-window", Vminibuf_scroll_window
,
7353 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
7354 Vminibuf_scroll_window
= Qnil
;
7356 DEFVAR_BOOL ("mode-line-in-non-selected-windows", mode_line_in_non_selected_windows
,
7357 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
7358 If the minibuffer is active, the `minibuffer-scroll-window' mode line
7359 is displayed in the `mode-line' face. */);
7360 mode_line_in_non_selected_windows
= true;
7362 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer
,
7363 doc
: /* If this is a live buffer, \\[scroll-other-window] should scroll its window. */);
7364 Vother_window_scroll_buffer
= Qnil
;
7366 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p
,
7367 doc
: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
7368 auto_window_vscroll_p
= true;
7370 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines
,
7371 doc
: /* Number of lines of continuity when scrolling by screenfuls. */);
7372 next_screen_context_lines
= 2;
7374 DEFVAR_LISP ("scroll-preserve-screen-position",
7375 Vscroll_preserve_screen_position
,
7376 doc
: /* Controls if scroll commands move point to keep its screen position unchanged.
7377 A value of nil means point does not keep its screen position except
7378 at the scroll margin or window boundary respectively.
7379 A value of t means point keeps its screen position if the scroll
7380 command moved it vertically out of the window, e.g. when scrolling
7382 Any other value means point always keeps its screen position.
7383 Scroll commands should have the `scroll-command' property
7384 on their symbols to be controlled by this variable. */);
7385 Vscroll_preserve_screen_position
= Qnil
;
7387 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type
,
7388 doc
: /* Type of marker to use for `window-point'. */);
7389 Vwindow_point_insertion_type
= Qnil
;
7390 DEFSYM (Qwindow_point_insertion_type
, "window_point_insertion_type");
7392 DEFVAR_LISP ("window-configuration-change-hook",
7393 Vwindow_configuration_change_hook
,
7394 doc
: /* Functions to call when window configuration changes.
7395 The buffer-local part is run once per window, with the relevant window
7396 selected; while the global part is run only once for the modified frame,
7397 with the relevant frame selected. */);
7398 Vwindow_configuration_change_hook
= Qnil
;
7400 DEFVAR_LISP ("recenter-redisplay", Vrecenter_redisplay
,
7401 doc
: /* Non-nil means `recenter' redraws entire frame.
7402 If this option is non-nil, then the `recenter' command with a nil
7403 argument will redraw the entire frame; the special value `tty' causes
7404 the frame to be redrawn only if it is a tty frame. */);
7405 Vrecenter_redisplay
= Qtty
;
7407 DEFVAR_LISP ("window-combination-resize", Vwindow_combination_resize
,
7408 doc
: /* If t, resize window combinations proportionally.
7409 If this variable is nil, splitting a window gets the entire screen space
7410 for displaying the new window from the window to split. Deleting and
7411 resizing a window preferably resizes one adjacent window only.
7413 If this variable is t, splitting a window tries to get the space
7414 proportionally from all windows in the same combination. This also
7415 allows to split a window that is otherwise too small or of fixed size.
7416 Resizing and deleting a window proportionally resize all windows in the
7419 Other values are reserved for future use.
7421 This variable takes no effect if the variable `window-combination-limit' is
7423 Vwindow_combination_resize
= Qnil
;
7425 DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit
,
7426 doc
: /* If non-nil, splitting a window makes a new parent window.
7427 The following values are recognized:
7429 nil means splitting a window will create a new parent window only if the
7430 window has no parent window or the window shall become part of a
7431 combination orthogonal to the one it is part of.
7433 `window-size' means that splitting a window for displaying a buffer
7434 makes a new parent window provided `display-buffer' is supposed to
7435 explicitly set the window's size due to the presence of a
7436 `window-height' or `window-width' entry in the alist used by
7437 `display-buffer'. Otherwise, this value is handled like nil.
7439 `temp-buffer' means that splitting a window for displaying a temporary
7440 buffer always makes a new parent window. Otherwise, this value is
7443 `display-buffer' means that splitting a window for displaying a buffer
7444 always makes a new parent window. Since temporary buffers are
7445 displayed by the function `display-buffer', this value is stronger
7446 than `temp-buffer'. Splitting a window for other purpose makes a
7447 new parent window only if needed.
7449 t means that splitting a window always creates a new parent window. If
7450 all splits behave this way, each frame's window tree is a binary
7451 tree and every window but the frame's root window has exactly one
7454 Other values are reserved for future use. */);
7455 Vwindow_combination_limit
= Qwindow_size
;
7457 DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters
,
7458 doc
: /* Alist of persistent window parameters.
7459 This alist specifies which window parameters shall get saved by
7460 `current-window-configuration' and `window-state-get' and subsequently
7461 restored to their previous values by `set-window-configuration' and
7464 The car of each entry of this alist is the symbol specifying the
7465 parameter. The cdr is one of the following:
7467 nil means the parameter is neither saved by `window-state-get' nor by
7468 `current-window-configuration'.
7470 t means the parameter is saved by `current-window-configuration' and,
7471 provided its WRITABLE argument is nil, by `window-state-get'.
7473 The symbol `writable' means the parameter is saved unconditionally by
7474 both `current-window-configuration' and `window-state-get'. Do not use
7475 this value for parameters without read syntax (like windows or frames).
7477 Parameters not saved by `current-window-configuration' or
7478 `window-state-get' are left alone by `set-window-configuration'
7479 respectively are not installed by `window-state-put'. */);
7480 Vwindow_persistent_parameters
= list1 (Fcons (Qclone_of
, Qt
));
7482 DEFVAR_BOOL ("window-resize-pixelwise", window_resize_pixelwise
,
7483 doc
: /* Non-nil means resize windows pixelwise.
7484 This currently affects the functions: `split-window', `maximize-window',
7485 `minimize-window', `fit-window-to-buffer' and `fit-frame-to-buffer', and
7486 all functions that symmetrically resize a parent window.
7488 Note that when a frame's pixel size is not a multiple of the
7489 frame's character size, at least one window may get resized
7490 pixelwise even if this option is nil. */);
7491 window_resize_pixelwise
= false;
7493 DEFVAR_BOOL ("fast-but-imprecise-scrolling",
7494 Vfast_but_imprecise_scrolling
,
7495 doc
: /* When non-nil, accelerate scrolling operations.
7496 This comes into play when scrolling rapidly over previously
7497 unfontified buffer regions. Only those portions of the buffer which
7498 are actually going to be displayed get fontified.
7500 Note that this optimization can cause the portion of the buffer
7501 displayed after a scrolling operation to be somewhat inaccurate. */);
7502 Vfast_but_imprecise_scrolling
= false;
7504 defsubr (&Sselected_window
);
7505 defsubr (&Sminibuffer_window
);
7506 defsubr (&Swindow_minibuffer_p
);
7507 defsubr (&Swindowp
);
7508 defsubr (&Swindow_valid_p
);
7509 defsubr (&Swindow_live_p
);
7510 defsubr (&Swindow_frame
);
7511 defsubr (&Sframe_root_window
);
7512 defsubr (&Sframe_first_window
);
7513 defsubr (&Sframe_selected_window
);
7514 defsubr (&Sset_frame_selected_window
);
7515 defsubr (&Spos_visible_in_window_p
);
7516 defsubr (&Swindow_line_height
);
7517 defsubr (&Swindow_buffer
);
7518 defsubr (&Swindow_parent
);
7519 defsubr (&Swindow_top_child
);
7520 defsubr (&Swindow_left_child
);
7521 defsubr (&Swindow_next_sibling
);
7522 defsubr (&Swindow_prev_sibling
);
7523 defsubr (&Swindow_combination_limit
);
7524 defsubr (&Sset_window_combination_limit
);
7525 defsubr (&Swindow_use_time
);
7526 defsubr (&Swindow_pixel_width
);
7527 defsubr (&Swindow_pixel_height
);
7528 defsubr (&Swindow_total_width
);
7529 defsubr (&Swindow_total_height
);
7530 defsubr (&Swindow_normal_size
);
7531 defsubr (&Swindow_new_pixel
);
7532 defsubr (&Swindow_new_total
);
7533 defsubr (&Swindow_new_normal
);
7534 defsubr (&Swindow_pixel_left
);
7535 defsubr (&Swindow_pixel_top
);
7536 defsubr (&Swindow_left_column
);
7537 defsubr (&Swindow_top_line
);
7538 defsubr (&Sset_window_new_pixel
);
7539 defsubr (&Sset_window_new_total
);
7540 defsubr (&Sset_window_new_normal
);
7541 defsubr (&Swindow_resize_apply
);
7542 defsubr (&Swindow_resize_apply_total
);
7543 defsubr (&Swindow_body_height
);
7544 defsubr (&Swindow_body_width
);
7545 defsubr (&Swindow_hscroll
);
7546 defsubr (&Sset_window_hscroll
);
7547 defsubr (&Swindow_redisplay_end_trigger
);
7548 defsubr (&Sset_window_redisplay_end_trigger
);
7549 defsubr (&Swindow_edges
);
7550 defsubr (&Swindow_pixel_edges
);
7551 defsubr (&Swindow_absolute_pixel_edges
);
7552 defsubr (&Swindow_mode_line_height
);
7553 defsubr (&Swindow_header_line_height
);
7554 defsubr (&Swindow_right_divider_width
);
7555 defsubr (&Swindow_bottom_divider_width
);
7556 defsubr (&Swindow_scroll_bar_width
);
7557 defsubr (&Swindow_scroll_bar_height
);
7558 defsubr (&Swindow_inside_edges
);
7559 defsubr (&Swindow_inside_pixel_edges
);
7560 defsubr (&Swindow_inside_absolute_pixel_edges
);
7561 defsubr (&Scoordinates_in_window_p
);
7562 defsubr (&Swindow_at
);
7563 defsubr (&Swindow_point
);
7564 defsubr (&Swindow_old_point
);
7565 defsubr (&Swindow_start
);
7566 defsubr (&Swindow_end
);
7567 defsubr (&Sset_window_point
);
7568 defsubr (&Sset_window_start
);
7569 defsubr (&Swindow_dedicated_p
);
7570 defsubr (&Sset_window_dedicated_p
);
7571 defsubr (&Swindow_display_table
);
7572 defsubr (&Sset_window_display_table
);
7573 defsubr (&Snext_window
);
7574 defsubr (&Sprevious_window
);
7575 defsubr (&Sget_buffer_window
);
7576 defsubr (&Sdelete_other_windows_internal
);
7577 defsubr (&Sdelete_window_internal
);
7578 defsubr (&Sresize_mini_window_internal
);
7579 defsubr (&Sset_window_buffer
);
7580 defsubr (&Srun_window_configuration_change_hook
);
7581 defsubr (&Srun_window_scroll_functions
);
7582 defsubr (&Sselect_window
);
7583 defsubr (&Sforce_window_update
);
7584 defsubr (&Ssplit_window_internal
);
7585 defsubr (&Sscroll_up
);
7586 defsubr (&Sscroll_down
);
7587 defsubr (&Sscroll_left
);
7588 defsubr (&Sscroll_right
);
7589 defsubr (&Sother_window_for_scrolling
);
7590 defsubr (&Sscroll_other_window
);
7591 defsubr (&Sminibuffer_selected_window
);
7592 defsubr (&Srecenter
);
7593 defsubr (&Swindow_text_width
);
7594 defsubr (&Swindow_text_height
);
7595 defsubr (&Smove_to_window_line
);
7596 defsubr (&Swindow_configuration_p
);
7597 defsubr (&Swindow_configuration_frame
);
7598 defsubr (&Sset_window_configuration
);
7599 defsubr (&Scurrent_window_configuration
);
7600 defsubr (&Sset_window_margins
);
7601 defsubr (&Swindow_margins
);
7602 defsubr (&Sset_window_fringes
);
7603 defsubr (&Swindow_fringes
);
7604 defsubr (&Sset_window_scroll_bars
);
7605 defsubr (&Swindow_scroll_bars
);
7606 defsubr (&Swindow_vscroll
);
7607 defsubr (&Sset_window_vscroll
);
7608 defsubr (&Scompare_window_configurations
);
7609 defsubr (&Swindow_list
);
7610 defsubr (&Swindow_list_1
);
7611 defsubr (&Swindow_prev_buffers
);
7612 defsubr (&Sset_window_prev_buffers
);
7613 defsubr (&Swindow_next_buffers
);
7614 defsubr (&Sset_window_next_buffers
);
7615 defsubr (&Swindow_parameters
);
7616 defsubr (&Swindow_parameter
);
7617 defsubr (&Sset_window_parameter
);
7621 keys_of_window (void)
7623 initial_define_key (control_x_map
, '<', "scroll-left");
7624 initial_define_key (control_x_map
, '>', "scroll-right");
7626 initial_define_key (global_map
, Ctl ('V'), "scroll-up-command");
7627 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
7628 initial_define_key (meta_map
, 'v', "scroll-down-command");