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 */
48 Lisp_Object Qwindowp
, Qwindow_live_p
;
49 static Lisp_Object Qwindow_valid_p
;
50 static Lisp_Object Qwindow_configuration_p
;
51 static Lisp_Object Qrecord_window_buffer
;
52 static Lisp_Object Qwindow_deletable_p
, Qdelete_window
, Qdisplay_buffer
;
53 static Lisp_Object Qreplace_buffer_in_windows
, Qget_mru_window
;
54 static Lisp_Object Qwindow_resize_root_window
, Qwindow_resize_root_window_vertically
;
55 static Lisp_Object Qwindow_sanitize_window_sizes
;
56 static Lisp_Object Qwindow_pixel_to_total
;
57 static Lisp_Object Qscroll_up
, Qscroll_down
, Qscroll_command
;
58 static Lisp_Object Qsafe
, Qabove
, Qbelow
, Qwindow_size
, Qclone_of
;
59 static Lisp_Object Qfloor
, Qceiling
;
60 static Lisp_Object Qwindow_point_insertion_type
;
62 static int displayed_window_lines (struct window
*);
63 static int count_windows (struct window
*);
64 static int get_leaf_windows (struct window
*, struct window
**, int);
65 static void window_scroll (Lisp_Object
, EMACS_INT
, bool, int);
66 static void window_scroll_pixel_based (Lisp_Object
, int, bool, int);
67 static void window_scroll_line_based (Lisp_Object
, int, bool, int);
68 static int add_window_to_list (struct window
*, void *);
69 static Lisp_Object
next_window (Lisp_Object
, Lisp_Object
,
71 static void decode_next_window_args (Lisp_Object
*, Lisp_Object
*,
73 static void foreach_window (struct frame
*,
74 int (* fn
) (struct window
*, void *),
76 static int foreach_window_1 (struct window
*,
77 int (* fn
) (struct window
*, void *),
79 static Lisp_Object
window_list_1 (Lisp_Object
, Lisp_Object
, Lisp_Object
);
80 static int window_resize_check (struct window
*, bool);
81 static void window_resize_apply (struct window
*, bool);
82 static void window_resize_apply_total (struct window
*, bool);
83 static Lisp_Object
select_window (Lisp_Object
, Lisp_Object
, int);
84 static void select_window_1 (Lisp_Object
, bool);
86 static struct window
*set_window_fringes (struct window
*, Lisp_Object
,
87 Lisp_Object
, Lisp_Object
);
88 static struct window
*set_window_margins (struct window
*, Lisp_Object
,
90 static struct window
*set_window_scroll_bars (struct window
*, Lisp_Object
,
91 Lisp_Object
, Lisp_Object
, Lisp_Object
);
92 static void apply_window_adjustment (struct window
*);
94 /* This is the window in which the terminal's cursor should
95 be left when nothing is being done with it. This must
96 always be a leaf window, and its buffer is selected by
97 the top level editing loop at the end of each command.
99 This value is always the same as
100 FRAME_SELECTED_WINDOW (selected_frame). */
101 Lisp_Object selected_window
;
103 /* A list of all windows for use by next_window and Fwindow_list.
104 Functions creating or deleting windows should invalidate this cache
105 by setting it to nil. */
106 Lisp_Object Vwindow_list
;
108 /* The mini-buffer window of the selected frame.
109 Note that you cannot test for mini-bufferness of an arbitrary window
110 by comparing against this; but you can test for mini-bufferness of
111 the selected window. */
112 Lisp_Object minibuf_window
;
114 /* Non-nil means it is the window whose mode line should be
115 shown as the selected window when the minibuffer is selected. */
116 Lisp_Object minibuf_selected_window
;
118 /* Hook run at end of temp_output_buffer_show. */
119 static Lisp_Object Qtemp_buffer_show_hook
;
121 /* Incremented for each window created. */
122 static int sequence_number
;
124 /* Hook to run when window config changes. */
125 static Lisp_Object Qwindow_configuration_change_hook
;
127 /* Used by the function window_scroll_pixel_based. */
128 static int window_scroll_pixel_based_preserve_x
;
129 static int window_scroll_pixel_based_preserve_y
;
131 /* Same for window_scroll_line_based. */
132 static EMACS_INT window_scroll_preserve_hpos
;
133 static EMACS_INT window_scroll_preserve_vpos
;
136 CHECK_WINDOW_CONFIGURATION (Lisp_Object x
)
138 CHECK_TYPE (WINDOW_CONFIGURATIONP (x
), Qwindow_configuration_p
, x
);
141 /* These setters are used only in this file, so they can be private. */
143 wset_combination_limit (struct window
*w
, Lisp_Object val
)
145 w
->combination_limit
= val
;
149 wset_dedicated (struct window
*w
, Lisp_Object val
)
155 wset_display_table (struct window
*w
, Lisp_Object val
)
157 w
->display_table
= val
;
161 wset_new_normal (struct window
*w
, Lisp_Object val
)
167 wset_new_total (struct window
*w
, Lisp_Object val
)
173 wset_normal_cols (struct window
*w
, Lisp_Object val
)
175 w
->normal_cols
= val
;
179 wset_normal_lines (struct window
*w
, Lisp_Object val
)
181 w
->normal_lines
= val
;
185 wset_parent (struct window
*w
, Lisp_Object val
)
191 wset_pointm (struct window
*w
, Lisp_Object val
)
197 wset_old_pointm (struct window
*w
, Lisp_Object val
)
203 wset_start (struct window
*w
, Lisp_Object val
)
209 wset_temslot (struct window
*w
, Lisp_Object val
)
215 wset_vertical_scroll_bar_type (struct window
*w
, Lisp_Object val
)
217 w
->vertical_scroll_bar_type
= val
;
221 wset_window_parameters (struct window
*w
, Lisp_Object val
)
223 w
->window_parameters
= val
;
227 wset_combination (struct window
*w
, bool horflag
, Lisp_Object val
)
229 /* Since leaf windows never becomes non-leaf, there should
230 be no buffer and markers in start and pointm fields of W. */
231 eassert (!BUFFERP (w
->contents
) && NILP (w
->start
) && NILP (w
->pointm
));
233 /* When an internal window is deleted and VAL is nil, HORFLAG
236 w
->horizontal
= horflag
;
239 /* Nonzero if leaf window W doesn't reflect the actual state
240 of displayed buffer due to its text or overlays change. */
243 window_outdated (struct window
*w
)
245 struct buffer
*b
= XBUFFER (w
->contents
);
246 return (w
->last_modified
< BUF_MODIFF (b
)
247 || w
->last_overlay_modified
< BUF_OVERLAY_MODIFF (b
));
251 decode_live_window (register Lisp_Object window
)
254 return XWINDOW (selected_window
);
256 CHECK_LIVE_WINDOW (window
);
257 return XWINDOW (window
);
261 decode_any_window (register Lisp_Object window
)
266 return XWINDOW (selected_window
);
268 CHECK_WINDOW (window
);
269 w
= XWINDOW (window
);
273 static struct window
*
274 decode_valid_window (register Lisp_Object window
)
279 return XWINDOW (selected_window
);
281 CHECK_VALID_WINDOW (window
);
282 w
= XWINDOW (window
);
286 /* Called when W's buffer slot is changed. ARG -1 means that W is about to
287 cease its buffer, and 1 means that W is about to set up the new one. */
290 adjust_window_count (struct window
*w
, int arg
)
292 eassert (eabs (arg
) == 1);
293 if (BUFFERP (w
->contents
))
295 struct buffer
*b
= XBUFFER (w
->contents
);
299 b
->window_count
+= arg
;
300 eassert (b
->window_count
>= 0);
301 /* These should be recalculated by redisplay code. */
302 w
->window_end_valid
= 0;
303 w
->base_line_pos
= 0;
307 /* Set W's buffer slot to VAL and recompute number
308 of windows showing VAL if it is a buffer. */
311 wset_buffer (struct window
*w
, Lisp_Object val
)
313 adjust_window_count (w
, -1);
315 /* Make sure that we do not assign the buffer
316 to an internal window. */
317 eassert (MARKERP (w
->start
) && MARKERP (w
->pointm
));
319 adjust_window_count (w
, 1);
322 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
323 doc
: /* Return t if OBJECT is a window and nil otherwise. */)
326 return WINDOWP (object
) ? Qt
: Qnil
;
329 DEFUN ("window-valid-p", Fwindow_valid_p
, Swindow_valid_p
, 1, 1, 0,
330 doc
: /* Return t if OBJECT is a valid window and nil otherwise.
331 A valid window is either a window that displays a buffer or an internal
332 window. Windows that have been deleted are not valid. */)
335 return WINDOW_VALID_P (object
) ? Qt
: Qnil
;
338 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
339 doc
: /* Return t if OBJECT is a live window and nil otherwise.
340 A live window is a window that displays a buffer.
341 Internal windows and deleted windows are not live. */)
344 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
347 /* Frames and windows. */
348 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 0, 1, 0,
349 doc
: /* Return the frame that window WINDOW is on.
350 WINDOW must be a valid window and defaults to the selected one. */)
353 return decode_valid_window (window
)->frame
;
356 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
357 doc
: /* Return the root window of FRAME-OR-WINDOW.
358 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
359 With a frame argument, return that frame's root window.
360 With a window argument, return the root window of that window's frame. */)
361 (Lisp_Object frame_or_window
)
365 if (NILP (frame_or_window
))
366 window
= SELECTED_FRAME ()->root_window
;
367 else if (WINDOW_VALID_P (frame_or_window
))
368 window
= XFRAME (XWINDOW (frame_or_window
)->frame
)->root_window
;
371 CHECK_LIVE_FRAME (frame_or_window
);
372 window
= XFRAME (frame_or_window
)->root_window
;
378 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
379 doc
: /* Return the minibuffer window for frame FRAME.
380 If FRAME is omitted or nil, it defaults to the selected frame. */)
383 return FRAME_MINIBUF_WINDOW (decode_live_frame (frame
));
386 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
,
387 Swindow_minibuffer_p
, 0, 1, 0,
388 doc
: /* Return non-nil if WINDOW is a minibuffer window.
389 WINDOW must be a valid window and defaults to the selected one. */)
392 return MINI_WINDOW_P (decode_valid_window (window
)) ? Qt
: Qnil
;
395 /* Don't move this to window.el - this must be a safe routine. */
396 DEFUN ("frame-first-window", Fframe_first_window
, Sframe_first_window
, 0, 1, 0,
397 doc
: /* Return the topmost, leftmost live window on FRAME-OR-WINDOW.
398 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
399 Else if FRAME-OR-WINDOW denotes a valid window, return the first window
400 of that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
401 the first window of that frame. */)
402 (Lisp_Object frame_or_window
)
406 if (NILP (frame_or_window
))
407 window
= SELECTED_FRAME ()->root_window
;
408 else if (WINDOW_VALID_P (frame_or_window
))
409 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
412 CHECK_LIVE_FRAME (frame_or_window
);
413 window
= XFRAME (frame_or_window
)->root_window
;
416 while (WINDOWP (XWINDOW (window
)->contents
))
417 window
= XWINDOW (window
)->contents
;
422 DEFUN ("frame-selected-window", Fframe_selected_window
,
423 Sframe_selected_window
, 0, 1, 0,
424 doc
: /* Return the selected window of FRAME-OR-WINDOW.
425 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
426 Else if FRAME-OR-WINDOW denotes a valid window, return the selected
427 window of that window's frame. If FRAME-OR-WINDOW denotes a live frame,
428 return the selected window of that frame. */)
429 (Lisp_Object frame_or_window
)
433 if (NILP (frame_or_window
))
434 window
= SELECTED_FRAME ()->selected_window
;
435 else if (WINDOW_VALID_P (frame_or_window
))
436 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->selected_window
;
439 CHECK_LIVE_FRAME (frame_or_window
);
440 window
= XFRAME (frame_or_window
)->selected_window
;
446 DEFUN ("set-frame-selected-window", Fset_frame_selected_window
,
447 Sset_frame_selected_window
, 2, 3, 0,
448 doc
: /* Set selected window of FRAME to WINDOW.
449 FRAME must be a live frame and defaults to the selected one. If FRAME
450 is the selected frame, this makes WINDOW the selected window. Optional
451 argument NORECORD non-nil means to neither change the order of recently
452 selected windows nor the buffer list. WINDOW must denote a live window.
454 (Lisp_Object frame
, Lisp_Object window
, Lisp_Object norecord
)
457 frame
= selected_frame
;
459 CHECK_LIVE_FRAME (frame
);
460 CHECK_LIVE_WINDOW (window
);
462 if (! EQ (frame
, WINDOW_FRAME (XWINDOW (window
))))
463 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
465 if (EQ (frame
, selected_frame
))
466 return Fselect_window (window
, norecord
);
469 fset_selected_window (XFRAME (frame
), window
);
474 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
475 doc
: /* Return the selected window.
476 The selected window is the window in which the standard cursor for
477 selected windows appears and to which many commands apply. */)
480 return selected_window
;
483 int window_select_count
;
485 /* If select_window is called with inhibit_point_swap non-zero it will
486 not store point of the old selected window's buffer back into that
487 window's pointm slot. This is needed by Fset_window_configuration to
488 avoid that the display routine is called with selected_window set to
489 Qnil causing a subsequent crash. */
491 select_window (Lisp_Object window
, Lisp_Object norecord
, int inhibit_point_swap
)
493 register struct window
*w
;
496 CHECK_LIVE_WINDOW (window
);
498 w
= XWINDOW (window
);
500 /* Make the selected window's buffer current. */
501 Fset_buffer (w
->contents
);
503 if (EQ (window
, selected_window
) && !inhibit_point_swap
)
504 /* `switch-to-buffer' uses (select-window (selected-window)) as a "clever"
505 way to call record_buffer from Elisp, so it's important that we call
506 record_buffer before returning here. */
507 goto record_and_return
;
510 { /* Mark the window for redisplay since the selected-window has
511 a different mode-line. */
512 wset_redisplay (XWINDOW (selected_window
));
516 redisplay_other_windows ();
518 sf
= SELECTED_FRAME ();
519 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
521 fset_selected_window (XFRAME (WINDOW_FRAME (w
)), window
);
522 /* Use this rather than Fhandle_switch_frame
523 so that FRAME_FOCUS_FRAME is moved appropriately as we
524 move around in the state where a minibuffer in a separate
526 Fselect_frame (WINDOW_FRAME (w
), norecord
);
527 /* Fselect_frame called us back so we've done all the work already. */
528 eassert (EQ (window
, selected_window
));
532 fset_selected_window (sf
, window
);
534 select_window_1 (window
, inhibit_point_swap
);
535 bset_last_selected_window (XBUFFER (w
->contents
), window
);
538 /* record_buffer can run QUIT, so make sure it is run only after we have
539 re-established the invariant between selected_window and selected_frame,
540 otherwise the temporary broken invariant might "escape" (bug#14161). */
543 w
->use_time
= ++window_select_count
;
544 record_buffer (w
->contents
);
550 /* Select window with a minimum of fuss, i.e. don't record the change anywhere
551 (not even for redisplay's benefit), and assume that the window's frame is
554 select_window_1 (Lisp_Object window
, bool inhibit_point_swap
)
556 /* Store the old selected window's buffer's point in pointm of the old
557 selected window. It belongs to that window, and when the window is
558 not selected, must be in the window. */
559 if (!inhibit_point_swap
)
561 struct window
*ow
= XWINDOW (selected_window
);
562 if (BUFFERP (ow
->contents
))
563 set_marker_both (ow
->pointm
, ow
->contents
,
564 BUF_PT (XBUFFER (ow
->contents
)),
565 BUF_PT_BYTE (XBUFFER (ow
->contents
)));
568 selected_window
= window
;
570 /* Go to the point recorded in the window.
571 This is important when the buffer is in more
572 than one window. It also matters when
573 redisplay_window has altered point after scrolling,
574 because it makes the change only in the window. */
575 set_point_from_marker (XWINDOW (window
)->pointm
);
578 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
579 doc
: /* Select WINDOW which must be a live window.
580 Also make WINDOW's frame the selected frame and WINDOW that frame's
581 selected window. In addition, make WINDOW's buffer current and set its
582 buffer's value of `point' to the value of WINDOW's `window-point'.
585 Optional second arg NORECORD non-nil means do not put this buffer at the
586 front of the buffer list and do not make this window the most recently
589 Run `buffer-list-update-hook' unless NORECORD is non-nil. Note that
590 applications and internal routines often select a window temporarily for
591 various purposes; mostly, to simplify coding. As a rule, such
592 selections should be not recorded and therefore will not pollute
593 `buffer-list-update-hook'. Selections that "really count" are those
594 causing a visible change in the next redisplay of WINDOW's frame and
595 should be always recorded. So if you think of running a function each
596 time a window gets selected put it on `buffer-list-update-hook'.
598 Also note that the main editor command loop sets the current buffer to
599 the buffer of the selected window before each command. */)
600 (register Lisp_Object window
, Lisp_Object norecord
)
602 return select_window (window
, norecord
, 0);
605 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
606 doc
: /* Return the buffer displayed in window WINDOW.
607 If WINDOW is omitted or nil, it defaults to the selected window.
608 Return nil for an internal window or a deleted window. */)
611 struct window
*w
= decode_any_window (window
);
612 return WINDOW_LEAF_P (w
) ? w
->contents
: Qnil
;
615 DEFUN ("window-parent", Fwindow_parent
, Swindow_parent
, 0, 1, 0,
616 doc
: /* Return the parent window of window WINDOW.
617 WINDOW must be a valid window and defaults to the selected one.
618 Return nil for a window with no parent (e.g. a root window). */)
621 return decode_valid_window (window
)->parent
;
624 DEFUN ("window-top-child", Fwindow_top_child
, Swindow_top_child
, 0, 1, 0,
625 doc
: /* Return the topmost child window of window WINDOW.
626 WINDOW must be a valid window and defaults to the selected one.
627 Return nil if WINDOW is a live window (live windows have no children).
628 Return nil if WINDOW is an internal window whose children form a
629 horizontal combination. */)
632 struct window
*w
= decode_valid_window (window
);
633 return WINDOW_VERTICAL_COMBINATION_P (w
) ? w
->contents
: Qnil
;
636 DEFUN ("window-left-child", Fwindow_left_child
, Swindow_left_child
, 0, 1, 0,
637 doc
: /* Return the leftmost child window of window WINDOW.
638 WINDOW must be a valid window and defaults to the selected one.
639 Return nil if WINDOW is a live window (live windows have no children).
640 Return nil if WINDOW is an internal window whose children form a
641 vertical combination. */)
644 struct window
*w
= decode_valid_window (window
);
645 return WINDOW_HORIZONTAL_COMBINATION_P (w
) ? w
->contents
: Qnil
;
648 DEFUN ("window-next-sibling", Fwindow_next_sibling
, Swindow_next_sibling
, 0, 1, 0,
649 doc
: /* Return the next sibling window of window WINDOW.
650 WINDOW must be a valid window and defaults to the selected one.
651 Return nil if WINDOW has no next sibling. */)
654 return decode_valid_window (window
)->next
;
657 DEFUN ("window-prev-sibling", Fwindow_prev_sibling
, Swindow_prev_sibling
, 0, 1, 0,
658 doc
: /* Return the previous sibling window of window WINDOW.
659 WINDOW must be a valid window and defaults to the selected one.
660 Return nil if WINDOW has no previous sibling. */)
663 return decode_valid_window (window
)->prev
;
666 DEFUN ("window-combination-limit", Fwindow_combination_limit
, Swindow_combination_limit
, 1, 1, 0,
667 doc
: /* Return combination limit of window WINDOW.
668 WINDOW must be a valid window used in horizontal or vertical combination.
669 If the return value is nil, child windows of WINDOW can be recombined with
670 WINDOW's siblings. A return value of t means that child windows of
671 WINDOW are never \(re-)combined with WINDOW's siblings. */)
676 CHECK_VALID_WINDOW (window
);
677 w
= XWINDOW (window
);
678 if (WINDOW_LEAF_P (w
))
679 error ("Combination limit is meaningful for internal windows only");
680 return w
->combination_limit
;
683 DEFUN ("set-window-combination-limit", Fset_window_combination_limit
, Sset_window_combination_limit
, 2, 2, 0,
684 doc
: /* Set combination limit of window WINDOW to LIMIT; return LIMIT.
685 WINDOW must be a valid window used in horizontal or vertical combination.
686 If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's
687 siblings. LIMIT t means that child windows of WINDOW are never
688 \(re-)combined with WINDOW's siblings. Other values are reserved for
690 (Lisp_Object window
, Lisp_Object limit
)
694 CHECK_VALID_WINDOW (window
);
695 w
= XWINDOW (window
);
696 if (WINDOW_LEAF_P (w
))
697 error ("Combination limit is meaningful for internal windows only");
698 wset_combination_limit (w
, limit
);
702 DEFUN ("window-use-time", Fwindow_use_time
, Swindow_use_time
, 0, 1, 0,
703 doc
: /* Return the use time of window WINDOW.
704 WINDOW must be a live window and defaults to the selected one.
705 The window with the highest use time is the most recently selected
706 one. The window with the lowest use time is the least recently
710 return make_number (decode_live_window (window
)->use_time
);
713 DEFUN ("window-pixel-width", Fwindow_pixel_width
, Swindow_pixel_width
, 0, 1, 0,
714 doc
: /* Return the width of window WINDOW in pixels.
715 WINDOW must be a valid window and defaults to the selected one.
717 The return value includes the fringes and margins of WINDOW as well as
718 any vertical dividers or scroll bars belonging to WINDOW. If WINDOW is
719 an internal window, its pixel width is the width of the screen areas
720 spanned by its children. */)
723 return make_number (decode_valid_window (window
)->pixel_width
);
726 DEFUN ("window-pixel-height", Fwindow_pixel_height
, Swindow_pixel_height
, 0, 1, 0,
727 doc
: /* Return the height of window WINDOW in pixels.
728 WINDOW must be a valid window and defaults to the selected one.
730 The return value includes the mode line and header line and the bottom
731 divider, if any. If WINDOW is an internal window, its pixel height is
732 the height of the screen areas spanned by its children. */)
735 return make_number (decode_valid_window (window
)->pixel_height
);
738 DEFUN ("window-total-height", Fwindow_total_height
, Swindow_total_height
, 0, 2, 0,
739 doc
: /* Return the height of window WINDOW in lines.
740 WINDOW must be a valid window and defaults to the selected one.
742 The return value includes the heights of WINDOW's mode and header line
743 and its bottom divider, if any. If WINDOW is an internal window, the
744 total height is the height of the screen areas spanned by its children.
746 If WINDOW's pixel height is not an integral multiple of its frame's
747 character height, the number of lines occupied by WINDOW is rounded
748 internally. This is done in a way such that, if WINDOW is a parent
749 window, the sum of the total heights of all its children internally
750 equals the total height of WINDOW.
752 If the optional argument ROUND is `ceiling', return the smallest integer
753 larger than WINDOW's pixel height divided by the character height of
754 WINDOW's frame. ROUND `floor' means to return the largest integer
755 smaller than WINDOW's pixel height divided by the character height of
756 WINDOW's frame. Any other value of ROUND means to return the internal
757 total height of WINDOW. */)
758 (Lisp_Object window
, Lisp_Object round
)
760 struct window
*w
= decode_valid_window (window
);
762 if (! EQ (round
, Qfloor
) && ! EQ (round
, Qceiling
))
763 return make_number (w
->total_lines
);
766 int unit
= FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
));
768 return make_number (EQ (round
, Qceiling
)
769 ? ((w
->pixel_height
+ unit
- 1) /unit
)
770 : (w
->pixel_height
/ unit
));
774 DEFUN ("window-total-width", Fwindow_total_width
, Swindow_total_width
, 0, 2, 0,
775 doc
: /* Return the total width of window WINDOW in columns.
776 WINDOW must be a valid window and defaults to the selected one.
778 The return value includes the widths of WINDOW's fringes, margins,
779 scroll bars and its right divider, if any. If WINDOW is an internal
780 window, the total width is the width of the screen areas spanned by its
783 If WINDOW's pixel width is not an integral multiple of its frame's
784 character width, the number of lines occupied by WINDOW is rounded
785 internally. This is done in a way such that, if WINDOW is a parent
786 window, the sum of the total widths of all its children internally
787 equals the total width of WINDOW.
789 If the optional argument ROUND is `ceiling', return the smallest integer
790 larger than WINDOW's pixel width divided by the character width of
791 WINDOW's frame. ROUND `floor' means to return the largest integer
792 smaller than WINDOW's pixel width divided by the character width of
793 WINDOW's frame. Any other value of ROUND means to return the internal
794 total width of WINDOW. */)
795 (Lisp_Object window
, Lisp_Object round
)
797 struct window
*w
= decode_valid_window (window
);
799 if (! EQ (round
, Qfloor
) && ! EQ (round
, Qceiling
))
800 return make_number (w
->total_cols
);
803 int unit
= FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
));
805 return make_number (EQ (round
, Qceiling
)
806 ? ((w
->pixel_width
+ unit
- 1) /unit
)
807 : (w
->pixel_width
/ unit
));
811 DEFUN ("window-new-total", Fwindow_new_total
, Swindow_new_total
, 0, 1, 0,
812 doc
: /* Return the new total size of window WINDOW.
813 WINDOW must be a valid window and defaults to the selected one.
815 The new total size of WINDOW is the value set by the last call of
816 `set-window-new-total' for WINDOW. If it is valid, it will be shortly
817 installed as WINDOW's total height (see `window-total-height') or total
818 width (see `window-total-width'). */)
821 return decode_valid_window (window
)->new_total
;
824 DEFUN ("window-normal-size", Fwindow_normal_size
, Swindow_normal_size
, 0, 2, 0,
825 doc
: /* Return the normal height of window WINDOW.
826 WINDOW must be a valid window and defaults to the selected one.
827 If HORIZONTAL is non-nil, return the normal width of WINDOW.
829 The normal height of a frame's root window or a window that is
830 horizontally combined (a window that has a left or right sibling) is
831 1.0. The normal height of a window that is vertically combined (has a
832 sibling above or below) is the fraction of the window's height with
833 respect to its parent. The sum of the normal heights of all windows in a
834 vertical combination equals 1.0.
836 Similarly, the normal width of a frame's root window or a window that is
837 vertically combined equals 1.0. The normal width of a window that is
838 horizontally combined is the fraction of the window's width with respect
839 to its parent. The sum of the normal widths of all windows in a
840 horizontal combination equals 1.0.
842 The normal sizes of windows are used to restore the proportional sizes
843 of windows after they have been shrunk to their minimum sizes; for
844 example when a frame is temporarily made very small and afterwards gets
845 re-enlarged to its previous size. */)
846 (Lisp_Object window
, Lisp_Object horizontal
)
848 struct window
*w
= decode_valid_window (window
);
850 return NILP (horizontal
) ? w
->normal_lines
: w
->normal_cols
;
853 DEFUN ("window-new-normal", Fwindow_new_normal
, Swindow_new_normal
, 0, 1, 0,
854 doc
: /* Return new normal size of window WINDOW.
855 WINDOW must be a valid window and defaults to the selected one.
857 The new normal size of WINDOW is the value set by the last call of
858 `set-window-new-normal' for WINDOW. If valid, it will be shortly
859 installed as WINDOW's normal size (see `window-normal-size'). */)
862 return decode_valid_window (window
)->new_normal
;
865 DEFUN ("window-new-pixel", Fwindow_new_pixel
, Swindow_new_pixel
, 0, 1, 0,
866 doc
: /* Return new pixel size of window WINDOW.
867 WINDOW must be a valid window and defaults to the selected one.
869 The new pixel size of WINDOW is the value set by the last call of
870 `set-window-new-pixel' for WINDOW. If it is valid, it will be shortly
871 installed as WINDOW's pixel height (see `window-pixel-height') or pixel
872 width (see `window-pixel-width'). */)
875 return decode_valid_window (window
)->new_pixel
;
878 DEFUN ("window-pixel-left", Fwindow_pixel_left
, Swindow_pixel_left
, 0, 1, 0,
879 doc
: /* Return left pixel edge of window WINDOW.
880 WINDOW must be a valid window and defaults to the selected one. */)
883 return make_number (decode_valid_window (window
)->pixel_left
);
886 DEFUN ("window-pixel-top", Fwindow_pixel_top
, Swindow_pixel_top
, 0, 1, 0,
887 doc
: /* Return top pixel edge of window WINDOW.
888 WINDOW must be a valid window and defaults to the selected one. */)
891 return make_number (decode_valid_window (window
)->pixel_top
);
894 DEFUN ("window-left-column", Fwindow_left_column
, Swindow_left_column
, 0, 1, 0,
895 doc
: /* Return left column of window WINDOW.
896 This is the distance, in columns, between the left edge of WINDOW and
897 the left edge of the frame's window area. For instance, the return
898 value is 0 if there is no window to the left of WINDOW.
900 WINDOW must be a valid window and defaults to the selected one. */)
903 return make_number (decode_valid_window (window
)->left_col
);
906 DEFUN ("window-top-line", Fwindow_top_line
, Swindow_top_line
, 0, 1, 0,
907 doc
: /* Return top line of window WINDOW.
908 This is the distance, in lines, between the top of WINDOW and the top
909 of the frame's window area. For instance, the return value is 0 if
910 there is no window above WINDOW.
912 WINDOW must be a valid window and defaults to the selected one. */)
915 return make_number (decode_valid_window (window
)->top_line
);
918 /* Return the number of lines/pixels of W's body. Don't count any mode
919 or header line or horizontal divider of W. Rounds down to nearest
920 integer when not working pixelwise. */
922 window_body_height (struct window
*w
, bool pixelwise
)
924 int height
= (w
->pixel_height
925 - WINDOW_HEADER_LINE_HEIGHT (w
)
926 - (WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
)
927 ? WINDOW_SCROLL_BAR_AREA_HEIGHT (w
)
929 - WINDOW_MODE_LINE_HEIGHT (w
)
930 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
));
932 /* Don't return a negative value. */
933 return max (pixelwise
935 : height
/ FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
)),
939 /* Return the number of columns/pixels of W's body. Don't count columns
940 occupied by the scroll bar or the divider/vertical bar separating W
941 from its right sibling or margins. On window-systems don't count
942 fringes either. Round down to nearest integer when not working
945 window_body_width (struct window
*w
, bool pixelwise
)
947 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
949 int width
= (w
->pixel_width
950 - WINDOW_RIGHT_DIVIDER_WIDTH (w
)
951 - (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
952 ? WINDOW_SCROLL_BAR_AREA_WIDTH (w
)
953 : ((!FRAME_WINDOW_P (f
)
954 && !WINDOW_RIGHTMOST_P (w
)
955 && !WINDOW_RIGHT_DIVIDER_WIDTH (w
))
956 /* A vertical bar is either 1 or 0. */
958 - WINDOW_MARGINS_WIDTH (w
)
959 - (FRAME_WINDOW_P (f
)
960 ? WINDOW_FRINGES_WIDTH (w
)
963 /* Don't return a negative value. */
964 return max (pixelwise
966 : width
/ FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
)),
970 DEFUN ("window-body-height", Fwindow_body_height
, Swindow_body_height
, 0, 2, 0,
971 doc
: /* Return the height of WINDOW's text area.
972 WINDOW must be a live window and defaults to the selected one. Optional
973 argument PIXELWISE non-nil means return the height of WINDOW's text area
974 in pixels. The return value does not include the mode line or header
975 line or any horizontal divider.
977 If PIXELWISE is nil, return the largest integer smaller than WINDOW's
978 pixel height divided by the character height of WINDOW's frame. This
979 means that if a line at the bottom of the text area is only partially
980 visible, that line is not counted. */)
981 (Lisp_Object window
, Lisp_Object pixelwise
)
983 return make_number (window_body_height (decode_live_window (window
),
984 NILP (pixelwise
) ? 0 : 1));
987 DEFUN ("window-body-width", Fwindow_body_width
, Swindow_body_width
, 0, 2, 0,
988 doc
: /* Return the width of WINDOW's text area.
989 WINDOW must be a live window and defaults to the selected one. Optional
990 argument PIXELWISE non-nil means return the width in pixels. The return
991 value does not include any vertical dividers, fringes or marginal areas,
994 If PIXELWISE is nil, return the largest integer smaller than WINDOW's
995 pixel width divided by the character width of WINDOW's frame. This
996 means that if a column at the right of the text area is only partially
997 visible, that column is not counted. */)
998 (Lisp_Object window
, Lisp_Object pixelwise
)
1000 return make_number (window_body_width (decode_live_window (window
),
1001 NILP (pixelwise
) ? 0 : 1));
1004 DEFUN ("window-mode-line-height", Fwindow_mode_line_height
,
1005 Swindow_mode_line_height
, 0, 1, 0,
1006 doc
: /* Return the height in pixels of WINDOW's mode-line.
1007 WINDOW must be a live window and defaults to the selected one. */)
1008 (Lisp_Object window
)
1010 return (make_number (WINDOW_MODE_LINE_HEIGHT (decode_live_window (window
))));
1013 DEFUN ("window-header-line-height", Fwindow_header_line_height
,
1014 Swindow_header_line_height
, 0, 1, 0,
1015 doc
: /* Return the height in pixels of WINDOW's header-line.
1016 WINDOW must be a live window and defaults to the selected one. */)
1017 (Lisp_Object window
)
1019 return (make_number (WINDOW_HEADER_LINE_HEIGHT (decode_live_window (window
))));
1022 DEFUN ("window-right-divider-width", Fwindow_right_divider_width
,
1023 Swindow_right_divider_width
, 0, 1, 0,
1024 doc
: /* Return the width in pixels of WINDOW's right divider.
1025 WINDOW must be a live window and defaults to the selected one. */)
1026 (Lisp_Object window
)
1028 return (make_number (WINDOW_RIGHT_DIVIDER_WIDTH (decode_live_window (window
))));
1031 DEFUN ("window-bottom-divider-width", Fwindow_bottom_divider_width
,
1032 Swindow_bottom_divider_width
, 0, 1, 0,
1033 doc
: /* Return the width in pixels of WINDOW's bottom divider.
1034 WINDOW must be a live window and defaults to the selected one. */)
1035 (Lisp_Object window
)
1037 return (make_number (WINDOW_BOTTOM_DIVIDER_WIDTH (decode_live_window (window
))));
1040 DEFUN ("window-scroll-bar-width", Fwindow_scroll_bar_width
,
1041 Swindow_scroll_bar_width
, 0, 1, 0,
1042 doc
: /* Return the width in pixels of WINDOW's vertical scrollbar.
1043 WINDOW must be a live window and defaults to the selected one. */)
1044 (Lisp_Object window
)
1046 return (make_number (WINDOW_SCROLL_BAR_AREA_WIDTH (decode_live_window (window
))));
1049 DEFUN ("window-scroll-bar-height", Fwindow_scroll_bar_height
,
1050 Swindow_scroll_bar_height
, 0, 1, 0,
1051 doc
: /* Return the height in pixels of WINDOW's horizontal scrollbar.
1052 WINDOW must be a live window and defaults to the selected one. */)
1053 (Lisp_Object window
)
1055 return (make_number (WINDOW_SCROLL_BAR_AREA_HEIGHT (decode_live_window (window
))));
1058 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
1059 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
1060 WINDOW must be a live window and defaults to the selected one. */)
1061 (Lisp_Object window
)
1063 return make_number (decode_live_window (window
)->hscroll
);
1066 /* Set W's horizontal scroll amount to HSCROLL clipped to a reasonable
1067 range, returning the new amount as a fixnum. */
1069 set_window_hscroll (struct window
*w
, EMACS_INT hscroll
)
1071 /* Horizontal scrolling has problems with large scroll amounts.
1072 It's too slow with long lines, and even with small lines the
1073 display can be messed up. For now, though, impose only the limits
1074 required by the internal representation: horizontal scrolling must
1075 fit in fixnum (since it's visible to Elisp) and into ptrdiff_t
1076 (since it's stored in a ptrdiff_t). */
1077 ptrdiff_t hscroll_max
= min (MOST_POSITIVE_FIXNUM
, PTRDIFF_MAX
);
1078 ptrdiff_t new_hscroll
= clip_to_bounds (0, hscroll
, hscroll_max
);
1080 /* Prevent redisplay shortcuts when changing the hscroll. */
1081 if (w
->hscroll
!= new_hscroll
)
1082 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
1084 w
->hscroll
= new_hscroll
;
1085 w
->suspend_auto_hscroll
= 1;
1087 return make_number (new_hscroll
);
1090 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
1091 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
1092 WINDOW must be a live window and defaults to the selected one.
1093 Clip the number to a reasonable value if out of range.
1094 Return the new number. NCOL should be zero or positive.
1096 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
1097 window so that the location of point moves off-window. */)
1098 (Lisp_Object window
, Lisp_Object ncol
)
1100 CHECK_NUMBER (ncol
);
1101 return set_window_hscroll (decode_live_window (window
), XINT (ncol
));
1104 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
1105 Swindow_redisplay_end_trigger
, 0, 1, 0,
1106 doc
: /* Return WINDOW's redisplay end trigger value.
1107 WINDOW must be a live window and defaults to the selected one.
1108 See `set-window-redisplay-end-trigger' for more information. */)
1109 (Lisp_Object window
)
1111 return decode_live_window (window
)->redisplay_end_trigger
;
1114 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
1115 Sset_window_redisplay_end_trigger
, 2, 2, 0,
1116 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
1117 WINDOW must be a live window and defaults to the selected one. VALUE
1118 should be a buffer position (typically a marker) or nil. If it is a
1119 buffer position, then if redisplay in WINDOW reaches a position beyond
1120 VALUE, the functions in `redisplay-end-trigger-functions' are called
1121 with two arguments: WINDOW, and the end trigger value. Afterwards the
1122 end-trigger value is reset to nil. */)
1123 (register Lisp_Object window
, Lisp_Object value
)
1125 wset_redisplay_end_trigger (decode_live_window (window
), value
);
1129 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
1130 doc
: /* Return a list of the edge coordinates of WINDOW.
1131 WINDOW must be a valid window and defaults to the selected one.
1133 The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
1134 count by lines, and LEFT and RIGHT count by columns, all relative to 0,
1135 0 at top left corner of frame.
1137 RIGHT is one more than the rightmost column occupied by WINDOW. BOTTOM
1138 is one more than the bottommost row occupied by WINDOW. The edges
1139 include the space used by WINDOW's scroll bar, display margins, fringes,
1140 header line, and/or mode line. For the edges of just the text area, use
1141 `window-inside-edges'. */)
1142 (Lisp_Object window
)
1144 register struct window
*w
= decode_valid_window (window
);
1146 return list4i (WINDOW_LEFT_EDGE_COL (w
), WINDOW_TOP_EDGE_LINE (w
),
1147 WINDOW_RIGHT_EDGE_COL (w
), WINDOW_BOTTOM_EDGE_LINE (w
));
1150 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
1151 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
1152 WINDOW must be a valid window and defaults to the selected one.
1154 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1155 0, 0 at the top left corner of the frame.
1157 RIGHT is one more than the rightmost x position occupied by WINDOW.
1158 BOTTOM is one more than the bottommost y position occupied by WINDOW.
1159 The pixel edges include the space used by WINDOW's scroll bar, display
1160 margins, fringes, header line, and/or mode line. For the pixel edges
1161 of just the text area, use `window-inside-pixel-edges'. */)
1162 (Lisp_Object window
)
1164 register struct window
*w
= decode_valid_window (window
);
1166 return list4i (WINDOW_LEFT_EDGE_X (w
), WINDOW_TOP_EDGE_Y (w
),
1167 WINDOW_RIGHT_EDGE_X (w
), WINDOW_BOTTOM_EDGE_Y (w
));
1171 calc_absolute_offset (struct window
*w
, int *add_x
, int *add_y
)
1173 struct frame
*f
= XFRAME (w
->frame
);
1174 *add_y
= f
->top_pos
;
1175 #ifdef FRAME_MENUBAR_HEIGHT
1176 *add_y
+= FRAME_MENUBAR_HEIGHT (f
);
1178 #ifdef FRAME_TOOLBAR_TOP_HEIGHT
1179 *add_y
+= FRAME_TOOLBAR_TOP_HEIGHT (f
);
1180 #elif defined (FRAME_TOOLBAR_HEIGHT)
1181 *add_y
+= FRAME_TOOLBAR_HEIGHT (f
);
1183 #ifdef FRAME_NS_TITLEBAR_HEIGHT
1184 *add_y
+= FRAME_NS_TITLEBAR_HEIGHT (f
);
1186 *add_x
= f
->left_pos
;
1187 #ifdef FRAME_TOOLBAR_LEFT_WIDTH
1188 *add_x
+= FRAME_TOOLBAR_LEFT_WIDTH (f
);
1192 DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges
,
1193 Swindow_absolute_pixel_edges
, 0, 1, 0,
1194 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
1195 WINDOW must be a valid window and defaults to the selected one.
1197 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1198 0, 0 at the top left corner of the display.
1200 RIGHT is one more than the rightmost x position occupied by WINDOW.
1201 BOTTOM is one more than the bottommost y position occupied by WINDOW.
1202 The pixel edges include the space used by WINDOW's scroll bar, display
1203 margins, fringes, header line, and/or mode line. For the pixel edges
1204 of just the text area, use `window-inside-absolute-pixel-edges'. */)
1205 (Lisp_Object window
)
1207 register struct window
*w
= decode_valid_window (window
);
1210 calc_absolute_offset (w
, &add_x
, &add_y
);
1212 return list4i (WINDOW_LEFT_EDGE_X (w
) + add_x
,
1213 WINDOW_TOP_EDGE_Y (w
) + add_y
,
1214 WINDOW_RIGHT_EDGE_X (w
) + add_x
,
1215 WINDOW_BOTTOM_EDGE_Y (w
) + add_y
);
1218 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
1219 doc
: /* Return a list of the edge coordinates of WINDOW.
1220 WINDOW must be a live window and defaults to the selected one.
1222 The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
1223 count by lines, and LEFT and RIGHT count by columns, all relative to 0,
1224 0 at top left corner of frame.
1226 RIGHT is one more than the rightmost column of WINDOW's text area.
1227 BOTTOM is one more than the bottommost row of WINDOW's text area. The
1228 inside edges do not include the space used by the WINDOW's scroll bar,
1229 display margins, fringes, header line, and/or mode line. */)
1230 (Lisp_Object window
)
1232 register struct window
*w
= decode_live_window (window
);
1234 return list4i ((WINDOW_BOX_LEFT_EDGE_COL (w
)
1235 + WINDOW_LEFT_MARGIN_COLS (w
)
1236 + ((WINDOW_LEFT_FRINGE_WIDTH (w
)
1237 + WINDOW_FRAME_COLUMN_WIDTH (w
) - 1)
1238 / WINDOW_FRAME_COLUMN_WIDTH (w
))),
1239 (WINDOW_TOP_EDGE_LINE (w
)
1240 + WINDOW_HEADER_LINE_LINES (w
)),
1241 (WINDOW_BOX_RIGHT_EDGE_COL (w
)
1242 - WINDOW_RIGHT_MARGIN_COLS (w
)
1243 - ((WINDOW_RIGHT_FRINGE_WIDTH (w
)
1244 + WINDOW_FRAME_COLUMN_WIDTH (w
) - 1)
1245 / WINDOW_FRAME_COLUMN_WIDTH (w
))),
1246 (WINDOW_BOTTOM_EDGE_LINE (w
)
1247 - WINDOW_MODE_LINE_LINES (w
)));
1250 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
1251 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1252 WINDOW must be a live window and defaults to the selected one.
1254 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1255 (0,0) at the top left corner of the frame's window area.
1257 RIGHT is one more than the rightmost x position of WINDOW's text area.
1258 BOTTOM is one more than the bottommost y position of WINDOW's text area.
1259 The inside edges do not include the space used by WINDOW's scroll bar,
1260 display margins, fringes, header line, and/or mode line. */)
1261 (Lisp_Object window
)
1263 register struct window
*w
= decode_live_window (window
);
1265 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w
)
1266 + WINDOW_LEFT_MARGIN_WIDTH (w
)
1267 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
1268 (WINDOW_TOP_EDGE_Y (w
)
1269 + WINDOW_HEADER_LINE_HEIGHT (w
)),
1270 (WINDOW_BOX_RIGHT_EDGE_X (w
)
1271 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
1272 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
1273 (WINDOW_BOTTOM_EDGE_Y (w
)
1274 - WINDOW_MODE_LINE_HEIGHT (w
)));
1277 DEFUN ("window-inside-absolute-pixel-edges",
1278 Fwindow_inside_absolute_pixel_edges
,
1279 Swindow_inside_absolute_pixel_edges
, 0, 1, 0,
1280 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1281 WINDOW must be a live window and defaults to the selected one.
1283 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1284 (0,0) at the top left corner of the frame's window area.
1286 RIGHT is one more than the rightmost x position of WINDOW's text area.
1287 BOTTOM is one more than the bottommost y position of WINDOW's text area.
1288 The inside edges do not include the space used by WINDOW's scroll bar,
1289 display margins, fringes, header line, and/or mode line. */)
1290 (Lisp_Object window
)
1292 register struct window
*w
= decode_live_window (window
);
1295 calc_absolute_offset (w
, &add_x
, &add_y
);
1297 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w
)
1298 + WINDOW_LEFT_MARGIN_WIDTH (w
)
1299 + WINDOW_LEFT_FRINGE_WIDTH (w
) + add_x
),
1300 (WINDOW_TOP_EDGE_Y (w
)
1301 + WINDOW_HEADER_LINE_HEIGHT (w
) + add_y
),
1302 (WINDOW_BOX_RIGHT_EDGE_X (w
)
1303 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
1304 - WINDOW_RIGHT_FRINGE_WIDTH (w
) + add_x
),
1305 (WINDOW_BOTTOM_EDGE_Y (w
)
1306 - WINDOW_MODE_LINE_HEIGHT (w
) + add_y
));
1309 /* Test if the character at column X, row Y is within window W.
1310 If it is not, return ON_NOTHING;
1311 if it is on the window's vertical divider, return
1313 if it is on the window's horizontal divider, return
1315 if it is in the window's text area, return ON_TEXT;
1316 if it is on the window's modeline, return ON_MODE_LINE;
1317 if it is on the border between the window and its right sibling,
1318 return ON_VERTICAL_BORDER;
1319 if it is on a scroll bar, return ON_SCROLL_BAR;
1320 if it is on the window's top line, return ON_HEADER_LINE;
1321 if it is in left or right fringe of the window,
1322 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
1323 if it is in the marginal area to the left/right of the window,
1324 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN.
1326 X and Y are frame relative pixel coordinates. */
1328 static enum window_part
1329 coordinates_in_window (register struct window
*w
, int x
, int y
)
1331 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1332 enum window_part part
;
1333 int ux
= FRAME_COLUMN_WIDTH (f
);
1334 int left_x
= WINDOW_LEFT_EDGE_X (w
);
1335 int right_x
= WINDOW_RIGHT_EDGE_X (w
);
1336 int top_y
= WINDOW_TOP_EDGE_Y (w
);
1337 int bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
1338 /* The width of the area where the vertical line can be dragged.
1339 (Between mode lines for instance. */
1340 int grabbable_width
= ux
;
1341 int lmargin_width
, rmargin_width
, text_left
, text_right
;
1343 /* Outside any interesting row or column? */
1344 if (y
< top_y
|| y
>= bottom_y
|| x
< left_x
|| x
>= right_x
)
1347 /* On the horizontal window divider (which prevails the vertical
1349 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
) > 0
1350 && y
>= (bottom_y
- WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
1352 return ON_BOTTOM_DIVIDER
;
1353 /* On vertical window divider? */
1354 else if (!WINDOW_RIGHTMOST_P (w
)
1355 && WINDOW_RIGHT_DIVIDER_WIDTH (w
) > 0
1356 && x
>= right_x
- WINDOW_RIGHT_DIVIDER_WIDTH (w
)
1358 return ON_RIGHT_DIVIDER
;
1359 /* On the horizontal scroll bar? (Including the empty space at its
1361 else if ((WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
)
1363 - WINDOW_SCROLL_BAR_AREA_HEIGHT (w
)
1364 - CURRENT_MODE_LINE_HEIGHT (w
)
1365 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
1367 - CURRENT_MODE_LINE_HEIGHT (w
)
1368 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
))))
1369 return ON_HORIZONTAL_SCROLL_BAR
;
1370 /* On the mode or header line? */
1371 else if ((WINDOW_WANTS_MODELINE_P (w
)
1373 - CURRENT_MODE_LINE_HEIGHT (w
)
1374 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
1375 && y
<= bottom_y
- WINDOW_BOTTOM_DIVIDER_WIDTH (w
)
1376 && (part
= ON_MODE_LINE
))
1377 || (WINDOW_WANTS_HEADER_LINE_P (w
)
1378 && y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
)
1379 && (part
= ON_HEADER_LINE
)))
1381 /* If it's under/over the scroll bar portion of the mode/header
1382 line, say it's on the vertical line. That's to be able to
1383 resize windows horizontally in case we're using toolkit scroll
1384 bars. Note: If scrollbars are on the left, the window that
1385 must be eventually resized is that on the left of WINDOW. */
1386 if ((WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0)
1387 && ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1388 && !WINDOW_LEFTMOST_P (w
)
1389 && eabs (x
- left_x
) < grabbable_width
)
1390 || (!WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1391 && !WINDOW_RIGHTMOST_P (w
)
1392 && eabs (x
- right_x
) < grabbable_width
)))
1393 return ON_VERTICAL_BORDER
;
1398 /* In what's below, we subtract 1 when computing right_x because we
1399 want the rightmost pixel, which is given by left_pixel+width-1. */
1400 if (w
->pseudo_window_p
)
1403 right_x
= WINDOW_PIXEL_WIDTH (w
) - 1;
1407 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
1408 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
1411 /* Outside any interesting column? */
1412 if (x
< left_x
|| x
> right_x
)
1413 return ON_VERTICAL_SCROLL_BAR
;
1415 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
1416 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
1418 text_left
= window_box_left (w
, TEXT_AREA
);
1419 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
1421 if (FRAME_WINDOW_P (f
))
1423 if (!w
->pseudo_window_p
1424 && WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0
1425 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
1426 && !WINDOW_RIGHTMOST_P (w
)
1427 && (eabs (x
- right_x
) < grabbable_width
))
1428 return ON_VERTICAL_BORDER
;
1430 /* Need to say "x > right_x" rather than >=, since on character
1431 terminals, the vertical line's x coordinate is right_x. */
1432 else if (!w
->pseudo_window_p
1433 && WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0
1434 && !WINDOW_RIGHTMOST_P (w
)
1435 /* Why check ux if we are not the rightmost window? Also
1436 shouldn't a pseudo window always be rightmost? */
1437 && x
> right_x
- ux
)
1438 return ON_VERTICAL_BORDER
;
1442 if (lmargin_width
> 0
1443 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1444 ? (x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
1445 : (x
< left_x
+ lmargin_width
)))
1446 return ON_LEFT_MARGIN
;
1448 return ON_LEFT_FRINGE
;
1451 if (x
>= text_right
)
1453 if (rmargin_width
> 0
1454 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1455 ? (x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
1456 : (x
>= right_x
- rmargin_width
)))
1457 return ON_RIGHT_MARGIN
;
1459 return ON_RIGHT_FRINGE
;
1462 /* Everything special ruled out - must be on text area */
1466 /* Take X is the frame-relative pixel x-coordinate, and return the
1467 x-coordinate relative to part PART of window W. */
1469 window_relative_x_coord (struct window
*w
, enum window_part part
, int x
)
1471 int left_x
= (w
->pseudo_window_p
) ? 0 : WINDOW_BOX_LEFT_EDGE_X (w
);
1476 return x
- window_box_left (w
, TEXT_AREA
);
1478 case ON_HEADER_LINE
:
1480 case ON_LEFT_FRINGE
:
1483 case ON_RIGHT_FRINGE
:
1484 return x
- left_x
- WINDOW_LEFT_FRINGE_WIDTH (w
);
1486 case ON_LEFT_MARGIN
:
1488 - ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1489 ? WINDOW_LEFT_FRINGE_WIDTH (w
) : 0));
1491 case ON_RIGHT_MARGIN
:
1493 - ((w
->pseudo_window_p
)
1494 ? WINDOW_PIXEL_WIDTH (w
)
1495 : WINDOW_BOX_RIGHT_EDGE_X (w
))
1496 + window_box_width (w
, RIGHT_MARGIN_AREA
)
1497 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1498 ? WINDOW_RIGHT_FRINGE_WIDTH (w
) : 0));
1501 /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */
1506 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
1507 Scoordinates_in_window_p
, 2, 2, 0,
1508 doc
: /* Return non-nil if COORDINATES are in WINDOW.
1509 WINDOW must be a live window and defaults to the selected one.
1510 COORDINATES is a cons of the form (X . Y), X and Y being distances
1511 measured in characters from the upper-left corner of the frame.
1512 \(0 . 0) denotes the character in the upper left corner of the
1514 If COORDINATES are in the text portion of WINDOW,
1515 the coordinates relative to the window are returned.
1516 If they are in the bottom divider of WINDOW, `bottom-divider' is returned.
1517 If they are in the right divider of WINDOW, `right-divider' is returned.
1518 If they are in the mode line of WINDOW, `mode-line' is returned.
1519 If they are in the header line of WINDOW, `header-line' is returned.
1520 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1521 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1522 If they are on the border between WINDOW and its right sibling,
1523 `vertical-line' is returned.
1524 If they are in the windows's left or right marginal areas, `left-margin'\n\
1525 or `right-margin' is returned. */)
1526 (register Lisp_Object coordinates
, Lisp_Object window
)
1533 w
= decode_live_window (window
);
1534 f
= XFRAME (w
->frame
);
1535 CHECK_CONS (coordinates
);
1536 lx
= Fcar (coordinates
);
1537 ly
= Fcdr (coordinates
);
1538 CHECK_NUMBER_OR_FLOAT (lx
);
1539 CHECK_NUMBER_OR_FLOAT (ly
);
1540 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1541 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1543 switch (coordinates_in_window (w
, x
, y
))
1549 /* Convert X and Y to window relative pixel coordinates, and
1550 return the canonical char units. */
1551 x
-= window_box_left (w
, TEXT_AREA
);
1552 y
-= WINDOW_TOP_EDGE_Y (w
);
1553 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
1554 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
1559 case ON_VERTICAL_BORDER
:
1560 return Qvertical_line
;
1562 case ON_HEADER_LINE
:
1563 return Qheader_line
;
1565 case ON_LEFT_FRINGE
:
1566 return Qleft_fringe
;
1568 case ON_RIGHT_FRINGE
:
1569 return Qright_fringe
;
1571 case ON_LEFT_MARGIN
:
1572 return Qleft_margin
;
1574 case ON_RIGHT_MARGIN
:
1575 return Qright_margin
;
1577 case ON_VERTICAL_SCROLL_BAR
:
1578 /* Historically we are supposed to return nil in this case. */
1581 case ON_HORIZONTAL_SCROLL_BAR
:
1584 case ON_RIGHT_DIVIDER
:
1585 return Qright_divider
;
1587 case ON_BOTTOM_DIVIDER
:
1588 return Qbottom_divider
;
1596 /* Callback for foreach_window, used in window_from_coordinates.
1597 Check if window W contains coordinates specified by USER_DATA which
1598 is actually a pointer to a struct check_window_data CW.
1600 Check if window W contains coordinates *CW->x and *CW->y. If it
1601 does, return W in *CW->window, as Lisp_Object, and return in
1602 *CW->part the part of the window under coordinates *X,*Y. Return
1603 zero from this function to stop iterating over windows. */
1605 struct check_window_data
1607 Lisp_Object
*window
;
1609 enum window_part
*part
;
1613 check_window_containing (struct window
*w
, void *user_data
)
1615 struct check_window_data
*cw
= user_data
;
1616 enum window_part found
;
1619 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1620 if (found
!= ON_NOTHING
)
1623 XSETWINDOW (*cw
->window
, w
);
1631 /* Find the window containing frame-relative pixel position X/Y and
1632 return it as a Lisp_Object.
1634 If X, Y is on one of the window's special `window_part' elements,
1635 set *PART to the id of that element.
1637 If there is no window under X, Y return nil and leave *PART
1638 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1640 This function was previously implemented with a loop cycling over
1641 windows with Fnext_window, and starting with the frame's selected
1642 window. It turned out that this doesn't work with an
1643 implementation of next_window using Vwindow_list, because
1644 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1645 tree of F when this function is called asynchronously from
1646 note_mouse_highlight. The original loop didn't terminate in this
1650 window_from_coordinates (struct frame
*f
, int x
, int y
,
1651 enum window_part
*part
, bool tool_bar_p
)
1654 struct check_window_data cw
;
1655 enum window_part dummy
;
1661 cw
.window
= &window
, cw
.x
= x
, cw
.y
= y
; cw
.part
= part
;
1662 foreach_window (f
, check_window_containing
, &cw
);
1664 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
1665 /* If not found above, see if it's in the tool bar window, if a tool
1669 && WINDOWP (f
->tool_bar_window
)
1670 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1671 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), x
, y
)
1675 window
= f
->tool_bar_window
;
1682 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1683 doc
: /* Return window containing coordinates X and Y on FRAME.
1684 FRAME must be a live frame and defaults to the selected one.
1685 The top left corner of the frame is considered to be row 0,
1687 (Lisp_Object x
, Lisp_Object y
, Lisp_Object frame
)
1689 struct frame
*f
= decode_live_frame (frame
);
1691 /* Check that arguments are integers or floats. */
1692 CHECK_NUMBER_OR_FLOAT (x
);
1693 CHECK_NUMBER_OR_FLOAT (y
);
1695 return window_from_coordinates (f
,
1696 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1697 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1698 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1699 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1703 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1704 doc
: /* Return current value of point in WINDOW.
1705 WINDOW must be a live window and defaults to the selected one.
1707 For a nonselected window, this is the value point would have if that
1708 window were selected.
1710 Note that, when WINDOW is selected, the value returned is the same as
1711 that returned by `point' for WINDOW's buffer. It would be more strictly
1712 correct to return the top-level value of `point', outside of any
1713 `save-excursion' forms. But that is hard to define. */)
1714 (Lisp_Object window
)
1716 register struct window
*w
= decode_live_window (window
);
1718 if (w
== XWINDOW (selected_window
))
1719 return make_number (BUF_PT (XBUFFER (w
->contents
)));
1721 return Fmarker_position (w
->pointm
);
1724 DEFUN ("window-old-point", Fwindow_old_point
, Swindow_old_point
, 0, 1, 0,
1725 doc
: /* Return old value of point in WINDOW.
1726 WINDOW must be a live window and defaults to the selected one. */)
1727 (Lisp_Object window
)
1729 return Fmarker_position (decode_live_window (window
)->old_pointm
);
1732 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1733 doc
: /* Return position at which display currently starts in WINDOW.
1734 WINDOW must be a live window and defaults to the selected one.
1735 This is updated by redisplay or by calling `set-window-start'. */)
1736 (Lisp_Object window
)
1738 return Fmarker_position (decode_live_window (window
)->start
);
1741 /* This is text temporarily removed from the doc string below.
1743 This function returns nil if the position is not currently known.
1744 That happens when redisplay is preempted and doesn't finish.
1745 If in that case you want to compute where the end of the window would
1746 have been if redisplay had finished, do this:
1748 (goto-char (window-start window))
1749 (vertical-motion (1- (window-height window)) window)
1752 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1753 doc
: /* Return position at which display currently ends in WINDOW.
1754 WINDOW must be a live window and defaults to the selected one.
1755 This is updated by redisplay, when it runs to completion.
1756 Simply changing the buffer text or setting `window-start'
1757 does not update this value.
1758 Return nil if there is no recorded value. (This can happen if the
1759 last redisplay of WINDOW was preempted, and did not finish.)
1760 If UPDATE is non-nil, compute the up-to-date position
1761 if it isn't already recorded. */)
1762 (Lisp_Object window
, Lisp_Object update
)
1765 struct window
*w
= decode_live_window (window
);
1774 && (windows_or_buffers_changed
1775 || !w
->window_end_valid
1777 || b
->prevent_redisplay_optimizations_p
1778 || window_outdated (w
))
1781 struct text_pos startp
;
1783 struct buffer
*old_buffer
= NULL
;
1784 void *itdata
= NULL
;
1786 /* Cannot use Fvertical_motion because that function doesn't
1787 cope with variable-height lines. */
1788 if (b
!= current_buffer
)
1790 old_buffer
= current_buffer
;
1791 set_buffer_internal (b
);
1794 /* In case W->start is out of the range, use something
1795 reasonable. This situation occurred when loading a file with
1796 `-l' containing a call to `rmail' with subsequent other
1797 commands. At the end, W->start happened to be BEG, while
1798 rmail had already narrowed the buffer. */
1799 CLIP_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1801 itdata
= bidi_shelve_cache ();
1802 start_display (&it
, w
, startp
);
1803 move_it_vertically (&it
, window_box_height (w
));
1804 if (it
.current_y
< it
.last_visible_y
)
1805 move_it_past_eol (&it
);
1806 value
= make_number (IT_CHARPOS (it
));
1807 bidi_unshelve_cache (itdata
, 0);
1810 set_buffer_internal (old_buffer
);
1813 XSETINT (value
, BUF_Z (b
) - w
->window_end_pos
);
1818 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1819 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1820 WINDOW must be a live window and defaults to the selected one.
1822 (Lisp_Object window
, Lisp_Object pos
)
1824 register struct window
*w
= decode_live_window (window
);
1826 /* Type of POS is checked by Fgoto_char or set_marker_restricted ... */
1828 if (w
== XWINDOW (selected_window
))
1830 if (XBUFFER (w
->contents
) == current_buffer
)
1834 struct buffer
*old_buffer
= current_buffer
;
1836 /* ... but here we want to catch type error before buffer change. */
1837 CHECK_NUMBER_COERCE_MARKER (pos
);
1838 set_buffer_internal (XBUFFER (w
->contents
));
1840 set_buffer_internal (old_buffer
);
1845 set_marker_restricted (w
->pointm
, pos
, w
->contents
);
1846 /* We have to make sure that redisplay updates the window to show
1847 the new value of point. */
1854 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1855 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1856 WINDOW must be a live window and defaults to the selected one. Return
1857 POS. Optional third arg NOFORCE non-nil inhibits next redisplay from
1858 overriding motion of point in order to display at this exact start. */)
1859 (Lisp_Object window
, Lisp_Object pos
, Lisp_Object noforce
)
1861 register struct window
*w
= decode_live_window (window
);
1863 set_marker_restricted (w
->start
, pos
, w
->contents
);
1864 /* This is not right, but much easier than doing what is right. */
1865 w
->start_at_line_beg
= 0;
1868 w
->update_mode_line
= 1;
1870 w
->window_end_valid
= 0;
1876 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
1877 Spos_visible_in_window_p
, 0, 3, 0,
1878 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
1879 WINDOW must be a live window and defaults to the selected one.
1881 Return nil if that position is scrolled vertically out of view. If a
1882 character is only partially visible, nil is returned, unless the
1883 optional argument PARTIALLY is non-nil. If POS is only out of view
1884 because of horizontal scrolling, return non-nil. If POS is t, it
1885 specifies the position of the last visible glyph in WINDOW. POS
1886 defaults to point in WINDOW; WINDOW defaults to the selected window.
1888 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1889 the return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
1890 where X and Y are the pixel coordinates relative to the top left corner
1891 of the window. The remaining elements are omitted if the character after
1892 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1893 off-window at the top and bottom of the screen line ("row") containing
1894 POS, ROWH is the visible height of that row, and VPOS is the row number
1896 (Lisp_Object pos
, Lisp_Object window
, Lisp_Object partially
)
1898 register struct window
*w
;
1899 register EMACS_INT posint
;
1900 register struct buffer
*buf
;
1901 struct text_pos top
;
1902 Lisp_Object in_window
= Qnil
;
1903 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
1906 w
= decode_live_window (window
);
1907 buf
= XBUFFER (w
->contents
);
1908 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1912 else if (!NILP (pos
))
1914 CHECK_NUMBER_COERCE_MARKER (pos
);
1915 posint
= XINT (pos
);
1917 else if (w
== XWINDOW (selected_window
))
1920 posint
= marker_position (w
->pointm
);
1922 /* If position is above window start or outside buffer boundaries,
1923 or if window start is out of range, position is not visible. */
1925 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
1926 && CHARPOS (top
) >= BUF_BEGV (buf
)
1927 && CHARPOS (top
) <= BUF_ZV (buf
)
1928 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
1929 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
1932 if (!NILP (in_window
) && !NILP (partially
))
1934 Lisp_Object part
= Qnil
;
1936 part
= list4i (rtop
, rbot
, rowh
, vpos
);
1937 in_window
= Fcons (make_number (x
),
1938 Fcons (make_number (y
), part
));
1944 DEFUN ("window-line-height", Fwindow_line_height
,
1945 Swindow_line_height
, 0, 2, 0,
1946 doc
: /* Return height in pixels of text line LINE in window WINDOW.
1947 WINDOW must be a live window and defaults to the selected one.
1949 Return height of current line if LINE is omitted or nil. Return height of
1950 header or mode line if LINE is `header-line' or `mode-line'.
1951 Otherwise, LINE is a text line number starting from 0. A negative number
1952 counts from the end of the window.
1954 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
1955 in pixels of the visible part of the line, VPOS and YPOS are the
1956 vertical position in lines and pixels of the line, relative to the top
1957 of the first text line, and OFFBOT is the number of off-window pixels at
1958 the bottom of the text line. If there are off-window pixels at the top
1959 of the (first) text line, YPOS is negative.
1961 Return nil if window display is not up-to-date. In that case, use
1962 `pos-visible-in-window-p' to obtain the information. */)
1963 (Lisp_Object line
, Lisp_Object window
)
1965 register struct window
*w
;
1966 register struct buffer
*b
;
1967 struct glyph_row
*row
, *end_row
;
1971 w
= decode_live_window (window
);
1973 if (noninteractive
|| w
->pseudo_window_p
)
1976 CHECK_BUFFER (w
->contents
);
1977 b
= XBUFFER (w
->contents
);
1979 /* Fail if current matrix is not up-to-date. */
1980 if (!w
->window_end_valid
1981 || windows_or_buffers_changed
1983 || b
->prevent_redisplay_optimizations_p
1984 || window_outdated (w
))
1990 if (i
< 0 || i
>= w
->current_matrix
->nrows
1991 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
1993 max_y
= window_text_bottom_y (w
);
1997 if (EQ (line
, Qheader_line
))
1999 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
2001 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
2002 return row
->enabled_p
? list4i (row
->height
, 0, 0, 0) : Qnil
;
2005 if (EQ (line
, Qmode_line
))
2007 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
2008 return (row
->enabled_p
?
2009 list4i (row
->height
,
2010 0, /* not accurate */
2011 (WINDOW_HEADER_LINE_HEIGHT (w
)
2012 + window_text_bottom_y (w
)),
2017 CHECK_NUMBER (line
);
2020 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2021 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2022 max_y
= window_text_bottom_y (w
);
2025 while ((n
< 0 || i
< n
)
2026 && row
<= end_row
&& row
->enabled_p
2027 && row
->y
+ row
->height
< max_y
)
2030 if (row
> end_row
|| !row
->enabled_p
)
2042 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
2043 return list4i (row
->height
+ min (0, row
->y
) - crop
, i
, row
->y
, crop
);
2046 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
2048 doc
: /* Return non-nil when WINDOW is dedicated to its buffer.
2049 More precisely, return the value assigned by the last call of
2050 `set-window-dedicated-p' for WINDOW. Return nil if that function was
2051 never called with WINDOW as its argument, or the value set by that
2052 function was internally reset since its last call. WINDOW must be a
2053 live window and defaults to the selected one.
2055 When a window is dedicated to its buffer, `display-buffer' will refrain
2056 from displaying another buffer in it. `get-lru-window' and
2057 `get-largest-window' treat dedicated windows specially.
2058 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
2059 `kill-buffer' can delete a dedicated window and the containing frame.
2061 Functions like `set-window-buffer' may change the buffer displayed by a
2062 window, unless that window is "strongly" dedicated to its buffer, that
2063 is the value returned by `window-dedicated-p' is t. */)
2064 (Lisp_Object window
)
2066 return decode_live_window (window
)->dedicated
;
2069 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
2070 Sset_window_dedicated_p
, 2, 2, 0,
2071 doc
: /* Mark WINDOW as dedicated according to FLAG.
2072 WINDOW must be a live window and defaults to the selected one. FLAG
2073 non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means
2074 mark WINDOW as non-dedicated. Return FLAG.
2076 When a window is dedicated to its buffer, `display-buffer' will refrain
2077 from displaying another buffer in it. `get-lru-window' and
2078 `get-largest-window' treat dedicated windows specially.
2079 `delete-windows-on', `replace-buffer-in-windows', `quit-window',
2080 `quit-restore-window' and `kill-buffer' can delete a dedicated window
2081 and the containing frame.
2083 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
2084 its buffer. Functions like `set-window-buffer' may change the buffer
2085 displayed by a window, unless that window is strongly dedicated to its
2086 buffer. If and when `set-window-buffer' displays another buffer in a
2087 window, it also makes sure that the window is no more dedicated. */)
2088 (Lisp_Object window
, Lisp_Object flag
)
2090 wset_dedicated (decode_live_window (window
), flag
);
2094 DEFUN ("window-prev-buffers", Fwindow_prev_buffers
, Swindow_prev_buffers
,
2096 doc
: /* Return buffers previously shown in WINDOW.
2097 WINDOW must be a live window and defaults to the selected one.
2099 The return value is a list of elements (BUFFER WINDOW-START POS),
2100 where BUFFER is a buffer, WINDOW-START is the start position of the
2101 window for that buffer, and POS is a window-specific point value. */)
2102 (Lisp_Object window
)
2104 return decode_live_window (window
)->prev_buffers
;
2107 DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers
,
2108 Sset_window_prev_buffers
, 2, 2, 0,
2109 doc
: /* Set WINDOW's previous buffers to PREV-BUFFERS.
2110 WINDOW must be a live window and defaults to the selected one.
2112 PREV-BUFFERS should be a list of elements (BUFFER WINDOW-START POS),
2113 where BUFFER is a buffer, WINDOW-START is the start position of the
2114 window for that buffer, and POS is a window-specific point value. */)
2115 (Lisp_Object window
, Lisp_Object prev_buffers
)
2117 wset_prev_buffers (decode_live_window (window
), prev_buffers
);
2118 return prev_buffers
;
2121 DEFUN ("window-next-buffers", Fwindow_next_buffers
, Swindow_next_buffers
,
2123 doc
: /* Return list of buffers recently re-shown in WINDOW.
2124 WINDOW must be a live window and defaults to the selected one. */)
2125 (Lisp_Object window
)
2127 return decode_live_window (window
)->next_buffers
;
2130 DEFUN ("set-window-next-buffers", Fset_window_next_buffers
,
2131 Sset_window_next_buffers
, 2, 2, 0,
2132 doc
: /* Set WINDOW's next buffers to NEXT-BUFFERS.
2133 WINDOW must be a live window and defaults to the selected one.
2134 NEXT-BUFFERS should be a list of buffers. */)
2135 (Lisp_Object window
, Lisp_Object next_buffers
)
2137 wset_next_buffers (decode_live_window (window
), next_buffers
);
2138 return next_buffers
;
2141 DEFUN ("window-parameters", Fwindow_parameters
, Swindow_parameters
,
2143 doc
: /* Return the parameters of WINDOW and their values.
2144 WINDOW must be a valid window and defaults to the selected one. The
2145 return value is a list of elements of the form (PARAMETER . VALUE). */)
2146 (Lisp_Object window
)
2148 return Fcopy_alist (decode_valid_window (window
)->window_parameters
);
2151 DEFUN ("window-parameter", Fwindow_parameter
, Swindow_parameter
,
2153 doc
: /* Return WINDOW's value for PARAMETER.
2154 WINDOW can be any window and defaults to the selected one. */)
2155 (Lisp_Object window
, Lisp_Object parameter
)
2159 result
= Fassq (parameter
, decode_any_window (window
)->window_parameters
);
2160 return CDR_SAFE (result
);
2163 DEFUN ("set-window-parameter", Fset_window_parameter
,
2164 Sset_window_parameter
, 3, 3, 0,
2165 doc
: /* Set WINDOW's value of PARAMETER to VALUE.
2166 WINDOW can be any window and defaults to the selected one.
2168 (Lisp_Object window
, Lisp_Object parameter
, Lisp_Object value
)
2170 register struct window
*w
= decode_any_window (window
);
2171 Lisp_Object old_alist_elt
;
2173 old_alist_elt
= Fassq (parameter
, w
->window_parameters
);
2174 if (NILP (old_alist_elt
))
2175 wset_window_parameters
2176 (w
, Fcons (Fcons (parameter
, value
), w
->window_parameters
));
2178 Fsetcdr (old_alist_elt
, value
);
2182 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
2184 doc
: /* Return the display-table that WINDOW is using.
2185 WINDOW must be a live window and defaults to the selected one. */)
2186 (Lisp_Object window
)
2188 return decode_live_window (window
)->display_table
;
2191 /* Get the display table for use on window W. This is either W's
2192 display table or W's buffer's display table. Ignore the specified
2193 tables if they are not valid; if no valid table is specified,
2196 struct Lisp_Char_Table
*
2197 window_display_table (struct window
*w
)
2199 struct Lisp_Char_Table
*dp
= NULL
;
2201 if (DISP_TABLE_P (w
->display_table
))
2202 dp
= XCHAR_TABLE (w
->display_table
);
2203 else if (BUFFERP (w
->contents
))
2205 struct buffer
*b
= XBUFFER (w
->contents
);
2207 if (DISP_TABLE_P (BVAR (b
, display_table
)))
2208 dp
= XCHAR_TABLE (BVAR (b
, display_table
));
2209 else if (DISP_TABLE_P (Vstandard_display_table
))
2210 dp
= XCHAR_TABLE (Vstandard_display_table
);
2216 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
2217 doc
: /* Set WINDOW's display-table to TABLE.
2218 WINDOW must be a live window and defaults to the selected one. */)
2219 (register Lisp_Object window
, Lisp_Object table
)
2221 wset_display_table (decode_live_window (window
), table
);
2225 /* Record info on buffer window W is displaying
2226 when it is about to cease to display that buffer. */
2228 unshow_buffer (register struct window
*w
)
2230 Lisp_Object buf
= w
->contents
;
2231 struct buffer
*b
= XBUFFER (buf
);
2233 eassert (b
== XMARKER (w
->pointm
)->buffer
);
2236 if (w
== XWINDOW (selected_window
)
2237 || ! EQ (buf
, XWINDOW (selected_window
)->contents
))
2238 /* Do this except when the selected window's buffer
2239 is being removed from some other window. */
2241 /* last_window_start records the start position that this buffer
2242 had in the last window to be disconnected from it.
2243 Now that this statement is unconditional,
2244 it is possible for the buffer to be displayed in the
2245 selected window, while last_window_start reflects another
2246 window which was recently showing the same buffer.
2247 Some people might say that might be a good thing. Let's see. */
2248 b
->last_window_start
= marker_position (w
->start
);
2250 /* Point in the selected window's buffer
2251 is actually stored in that buffer, and the window's pointm isn't used.
2252 So don't clobber point in that buffer. */
2253 if (! EQ (buf
, XWINDOW (selected_window
)->contents
)
2254 /* Don't clobber point in current buffer either (this could be
2255 useful in connection with bug#12208).
2256 && XBUFFER (buf) != current_buffer */
2257 /* This line helps to fix Horsley's testbug.el bug. */
2258 && !(WINDOWP (BVAR (b
, last_selected_window
))
2259 && w
!= XWINDOW (BVAR (b
, last_selected_window
))
2260 && EQ (buf
, XWINDOW (BVAR (b
, last_selected_window
))->contents
)))
2261 temp_set_point_both (b
,
2262 clip_to_bounds (BUF_BEGV (b
),
2263 marker_position (w
->pointm
),
2265 clip_to_bounds (BUF_BEGV_BYTE (b
),
2266 marker_byte_position (w
->pointm
),
2269 if (WINDOWP (BVAR (b
, last_selected_window
))
2270 && w
== XWINDOW (BVAR (b
, last_selected_window
)))
2271 bset_last_selected_window (b
, Qnil
);
2274 /* Put NEW into the window structure in place of OLD. SETFLAG zero
2275 means change window structure only. Otherwise store geometry and
2276 other settings as well. */
2278 replace_window (Lisp_Object old
, Lisp_Object
new, int setflag
)
2280 register Lisp_Object tem
;
2281 register struct window
*o
= XWINDOW (old
), *n
= XWINDOW (new);
2283 /* If OLD is its frame's root window, then NEW is the new
2284 root window for that frame. */
2285 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
2286 fset_root_window (XFRAME (o
->frame
), new);
2290 n
->pixel_left
= o
->pixel_left
;
2291 n
->pixel_top
= o
->pixel_top
;
2292 n
->pixel_width
= o
->pixel_width
;
2293 n
->pixel_height
= o
->pixel_height
;
2294 n
->left_col
= o
->left_col
;
2295 n
->top_line
= o
->top_line
;
2296 n
->total_cols
= o
->total_cols
;
2297 n
->total_lines
= o
->total_lines
;
2298 wset_normal_cols (n
, o
->normal_cols
);
2299 wset_normal_cols (o
, make_float (1.0));
2300 wset_normal_lines (n
, o
->normal_lines
);
2301 wset_normal_lines (o
, make_float (1.0));
2302 n
->desired_matrix
= n
->current_matrix
= 0;
2304 memset (&n
->cursor
, 0, sizeof (n
->cursor
));
2305 memset (&n
->phys_cursor
, 0, sizeof (n
->phys_cursor
));
2306 n
->last_cursor_vpos
= 0;
2307 #ifdef HAVE_WINDOW_SYSTEM
2308 n
->phys_cursor_type
= NO_CURSOR
;
2309 n
->phys_cursor_width
= -1;
2311 n
->must_be_updated_p
= 0;
2312 n
->pseudo_window_p
= 0;
2313 n
->window_end_vpos
= 0;
2314 n
->window_end_pos
= 0;
2315 n
->window_end_valid
= 0;
2321 wset_prev (XWINDOW (tem
), new);
2326 wset_next (XWINDOW (tem
), new);
2329 wset_parent (n
, tem
);
2330 if (!NILP (tem
) && EQ (XWINDOW (tem
)->contents
, old
))
2331 wset_combination (XWINDOW (tem
), XWINDOW (tem
)->horizontal
, new);
2334 /* If window WINDOW and its parent window are iso-combined, merge
2335 WINDOW's children into those of its parent window and mark WINDOW as
2339 recombine_windows (Lisp_Object window
)
2341 struct window
*w
, *p
, *c
;
2342 Lisp_Object parent
, child
;
2345 w
= XWINDOW (window
);
2347 if (!NILP (parent
) && NILP (w
->combination_limit
))
2349 p
= XWINDOW (parent
);
2350 if (WINDOWP (p
->contents
) && WINDOWP (w
->contents
)
2351 && p
->horizontal
== w
->horizontal
)
2352 /* WINDOW and PARENT are both either a vertical or a horizontal
2355 horflag
= WINDOW_HORIZONTAL_COMBINATION_P (w
);
2356 child
= w
->contents
;
2357 c
= XWINDOW (child
);
2359 /* Splice WINDOW's children into its parent's children and
2360 assign new normal sizes. */
2362 wset_combination (p
, horflag
, child
);
2365 wset_prev (c
, w
->prev
);
2366 wset_next (XWINDOW (w
->prev
), child
);
2371 wset_parent (c
, parent
);
2375 (c
, make_float ((double) c
->pixel_width
2376 / (double) p
->pixel_width
));
2379 (c
, make_float ((double) c
->pixel_height
2380 / (double) p
->pixel_height
));
2384 if (!NILP (w
->next
))
2386 wset_next (c
, w
->next
);
2387 wset_prev (XWINDOW (c
->next
), child
);
2395 c
= XWINDOW (child
);
2399 /* WINDOW can be deleted now. */
2400 wset_combination (w
, 0, Qnil
);
2405 /* If WINDOW can be deleted, delete it. */
2407 delete_deletable_window (Lisp_Object window
)
2409 if (!NILP (call1 (Qwindow_deletable_p
, window
)))
2410 call1 (Qdelete_window
, window
);
2413 /***********************************************************************
2415 ***********************************************************************/
2417 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
2418 pointer. This is a callback function for foreach_window, used in
2419 the window_list function. */
2422 add_window_to_list (struct window
*w
, void *user_data
)
2424 Lisp_Object
*list
= user_data
;
2426 XSETWINDOW (window
, w
);
2427 *list
= Fcons (window
, *list
);
2432 /* Return a list of all windows, for use by next_window. If
2433 Vwindow_list is a list, return that list. Otherwise, build a new
2434 list, cache it in Vwindow_list, and return that. */
2439 if (!CONSP (Vwindow_list
))
2441 Lisp_Object tail
, frame
;
2443 Vwindow_list
= Qnil
;
2444 FOR_EACH_FRAME (tail
, frame
)
2446 Lisp_Object args
[2];
2448 /* We are visiting windows in canonical order, and add
2449 new windows at the front of args[1], which means we
2450 have to reverse this list at the end. */
2452 foreach_window (XFRAME (frame
), add_window_to_list
, &args
[1]);
2453 args
[0] = Vwindow_list
;
2454 args
[1] = Fnreverse (args
[1]);
2455 Vwindow_list
= Fnconc (2, args
);
2459 return Vwindow_list
;
2463 /* Value is non-zero if WINDOW satisfies the constraints given by
2464 OWINDOW, MINIBUF and ALL_FRAMES.
2466 MINIBUF t means WINDOW may be minibuffer windows.
2467 `lambda' means WINDOW may not be a minibuffer window.
2468 a window means a specific minibuffer window
2470 ALL_FRAMES t means search all frames,
2471 nil means search just current frame,
2472 `visible' means search just visible frames on the
2474 0 means search visible and iconified frames on the
2476 a window means search the frame that window belongs to,
2477 a frame means consider windows on that frame, only. */
2480 candidate_window_p (Lisp_Object window
, Lisp_Object owindow
,
2481 Lisp_Object minibuf
, Lisp_Object all_frames
)
2483 struct window
*w
= XWINDOW (window
);
2484 struct frame
*f
= XFRAME (w
->frame
);
2485 bool candidate_p
= 1;
2487 if (!BUFFERP (w
->contents
))
2489 else if (MINI_WINDOW_P (w
)
2490 && (EQ (minibuf
, Qlambda
)
2491 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
2493 /* If MINIBUF is `lambda' don't consider any mini-windows.
2494 If it is a window, consider only that one. */
2497 else if (EQ (all_frames
, Qt
))
2499 else if (NILP (all_frames
))
2501 eassert (WINDOWP (owindow
));
2502 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
2504 else if (EQ (all_frames
, Qvisible
))
2506 candidate_p
= FRAME_VISIBLE_P (f
)
2507 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2508 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2511 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
2513 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
2514 #ifdef HAVE_X_WINDOWS
2515 /* Yuck!! If we've just created the frame and the
2516 window-manager requested the user to place it
2517 manually, the window may still not be considered
2518 `visible'. I'd argue it should be at least
2519 something like `iconified', but don't know how to do
2521 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
2522 && !f
->output_data
.x
->has_been_visible
)
2525 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2526 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2528 else if (WINDOWP (all_frames
))
2529 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
2530 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
2531 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
2532 else if (FRAMEP (all_frames
))
2533 candidate_p
= EQ (all_frames
, w
->frame
);
2539 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2540 Fwindow_list. See candidate_window_p for the meaning of WINDOW,
2541 MINIBUF, and ALL_FRAMES. */
2544 decode_next_window_args (Lisp_Object
*window
, Lisp_Object
*minibuf
, Lisp_Object
*all_frames
)
2546 struct window
*w
= decode_live_window (*window
);
2548 XSETWINDOW (*window
, w
);
2549 /* MINIBUF nil may or may not include minibuffers. Decide if it
2551 if (NILP (*minibuf
))
2552 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
2553 else if (!EQ (*minibuf
, Qt
))
2556 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2557 => count none of them, or a specific minibuffer window (the
2558 active one) to count. */
2560 /* ALL_FRAMES nil doesn't specify which frames to include. */
2561 if (NILP (*all_frames
))
2563 = (!EQ (*minibuf
, Qlambda
)
2564 ? FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
))
2566 else if (EQ (*all_frames
, Qvisible
))
2568 else if (EQ (*all_frames
, make_number (0)))
2570 else if (FRAMEP (*all_frames
))
2572 else if (!EQ (*all_frames
, Qt
))
2577 /* Return the next or previous window of WINDOW in cyclic ordering
2578 of windows. NEXT_P non-zero means return the next window. See the
2579 documentation string of next-window for the meaning of MINIBUF and
2583 next_window (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
, int next_p
)
2585 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2587 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2588 return the first window on the frame. */
2589 if (FRAMEP (all_frames
)
2590 && !EQ (all_frames
, XWINDOW (window
)->frame
))
2591 return Fframe_first_window (all_frames
);
2597 /* Find WINDOW in the list of all windows. */
2598 list
= Fmemq (window
, window_list ());
2600 /* Scan forward from WINDOW to the end of the window list. */
2602 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
2603 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2606 /* Scan from the start of the window list up to WINDOW. */
2608 for (list
= Vwindow_list
;
2609 CONSP (list
) && !EQ (XCAR (list
), window
);
2611 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2615 window
= XCAR (list
);
2619 Lisp_Object candidate
, list
;
2621 /* Scan through the list of windows for candidates. If there are
2622 candidate windows in front of WINDOW, the last one of these
2623 is the one we want. If there are candidates following WINDOW
2624 in the list, again the last one of these is the one we want. */
2626 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
2628 if (EQ (XCAR (list
), window
))
2630 if (WINDOWP (candidate
))
2633 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
2635 candidate
= XCAR (list
);
2638 if (WINDOWP (candidate
))
2646 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
2647 doc
: /* Return live window after WINDOW in the cyclic ordering of windows.
2648 WINDOW must be a live window and defaults to the selected one. The
2649 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2652 MINIBUF nil or omitted means consider the minibuffer window only if the
2653 minibuffer is active. MINIBUF t means consider the minibuffer window
2654 even if the minibuffer is not active. Any other value means do not
2655 consider the minibuffer window even if the minibuffer is active.
2657 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2658 plus the minibuffer window if specified by the MINIBUF argument. If the
2659 minibuffer counts, consider all windows on all frames that share that
2660 minibuffer too. The following non-nil values of ALL-FRAMES have special
2663 - t means consider all windows on all existing frames.
2665 - `visible' means consider all windows on all visible frames.
2667 - 0 (the number zero) means consider all windows on all visible and
2670 - A frame means consider all windows on that frame only.
2672 Anything else means consider all windows on WINDOW's frame and no
2675 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2676 `next-window' to iterate through the entire cycle of acceptable
2677 windows, eventually ending up back at the window you started with.
2678 `previous-window' traverses the same cycle, in the reverse order. */)
2679 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2681 return next_window (window
, minibuf
, all_frames
, 1);
2685 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
2686 doc
: /* Return live window before WINDOW in the cyclic ordering of windows.
2687 WINDOW must be a live window and defaults to the selected one. The
2688 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2691 MINIBUF nil or omitted means consider the minibuffer window only if the
2692 minibuffer is active. MINIBUF t means consider the minibuffer window
2693 even if the minibuffer is not active. Any other value means do not
2694 consider the minibuffer window even if the minibuffer is active.
2696 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2697 plus the minibuffer window if specified by the MINIBUF argument. If the
2698 minibuffer counts, consider all windows on all frames that share that
2699 minibuffer too. The following non-nil values of ALL-FRAMES have special
2702 - t means consider all windows on all existing frames.
2704 - `visible' means consider all windows on all visible frames.
2706 - 0 (the number zero) means consider all windows on all visible and
2709 - A frame means consider all windows on that frame only.
2711 Anything else means consider all windows on WINDOW's frame and no
2714 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2715 use `previous-window' to iterate through the entire cycle of
2716 acceptable windows, eventually ending up back at the window you
2717 started with. `next-window' traverses the same cycle, in the
2719 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2721 return next_window (window
, minibuf
, all_frames
, 0);
2725 /* Return a list of windows in cyclic ordering. Arguments are like
2726 for `next-window'. */
2729 window_list_1 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2731 Lisp_Object tail
, list
, rest
;
2733 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2736 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2737 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2738 list
= Fcons (XCAR (tail
), list
);
2740 /* Rotate the list to start with WINDOW. */
2741 list
= Fnreverse (list
);
2742 rest
= Fmemq (window
, list
);
2743 if (!NILP (rest
) && !EQ (rest
, list
))
2745 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2747 XSETCDR (tail
, Qnil
);
2748 list
= nconc2 (rest
, list
);
2754 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2755 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2756 FRAME nil or omitted means use the selected frame.
2757 WINDOW nil or omitted means use the window selected within FRAME.
2758 MINIBUF t means include the minibuffer window, even if it isn't active.
2759 MINIBUF nil or omitted means include the minibuffer window only
2761 MINIBUF neither nil nor t means never include the minibuffer window. */)
2762 (Lisp_Object frame
, Lisp_Object minibuf
, Lisp_Object window
)
2765 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2766 CHECK_WINDOW (window
);
2768 frame
= selected_frame
;
2770 if (!EQ (frame
, XWINDOW (window
)->frame
))
2771 error ("Window is on a different frame");
2773 return window_list_1 (window
, minibuf
, frame
);
2777 DEFUN ("window-list-1", Fwindow_list_1
, Swindow_list_1
, 0, 3, 0,
2778 doc
: /* Return a list of all live windows.
2779 WINDOW specifies the first window to list and defaults to the selected
2782 Optional argument MINIBUF nil or omitted means consider the minibuffer
2783 window only if the minibuffer is active. MINIBUF t means consider the
2784 minibuffer window even if the minibuffer is not active. Any other value
2785 means do not consider the minibuffer window even if the minibuffer is
2788 Optional argument ALL-FRAMES nil or omitted means consider all windows
2789 on WINDOW's frame, plus the minibuffer window if specified by the
2790 MINIBUF argument. If the minibuffer counts, consider all windows on all
2791 frames that share that minibuffer too. The following non-nil values of
2792 ALL-FRAMES have special meanings:
2794 - t means consider all windows on all existing frames.
2796 - `visible' means consider all windows on all visible frames.
2798 - 0 (the number zero) means consider all windows on all visible and
2801 - A frame means consider all windows on that frame only.
2803 Anything else means consider all windows on WINDOW's frame and no
2806 If WINDOW is not on the list of windows returned, some other window will
2807 be listed first but no error is signaled. */)
2808 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2810 return window_list_1 (window
, minibuf
, all_frames
);
2813 /* Look at all windows, performing an operation specified by TYPE
2815 If FRAMES is Qt, look at all frames;
2816 Qnil, look at just the selected frame;
2817 Qvisible, look at visible frames;
2818 a frame, just look at windows on that frame.
2819 If MINI is non-zero, perform the operation on minibuffer windows too. */
2824 GET_BUFFER_WINDOW
, /* Arg is buffer */
2825 REPLACE_BUFFER_IN_WINDOWS_SAFELY
, /* Arg is buffer */
2826 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2827 CHECK_ALL_WINDOWS
/* Arg is ignored */
2831 window_loop (enum window_loop type
, Lisp_Object obj
, int mini
, Lisp_Object frames
)
2833 Lisp_Object window
, windows
, best_window
, frame_arg
;
2834 int frame_best_window_flag
= 0;
2836 struct gcpro gcpro1
;
2838 /* If we're only looping through windows on a particular frame,
2839 frame points to that frame. If we're looping through windows
2840 on all frames, frame is 0. */
2841 if (FRAMEP (frames
))
2842 f
= XFRAME (frames
);
2843 else if (NILP (frames
))
2844 f
= SELECTED_FRAME ();
2849 frame_arg
= Qlambda
;
2850 else if (EQ (frames
, make_number (0)))
2852 else if (EQ (frames
, Qvisible
))
2857 /* frame_arg is Qlambda to stick to one frame,
2858 Qvisible to consider all visible frames,
2861 /* Pick a window to start with. */
2865 window
= FRAME_SELECTED_WINDOW (f
);
2867 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2869 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2873 for (; CONSP (windows
); windows
= XCDR (windows
))
2877 window
= XCAR (windows
);
2878 w
= XWINDOW (window
);
2880 /* Note that we do not pay attention here to whether the frame
2881 is visible, since Fwindow_list skips non-visible frames if
2882 that is desired, under the control of frame_arg. */
2883 if (!MINI_WINDOW_P (w
)
2884 /* For REPLACE_BUFFER_IN_WINDOWS_SAFELY, we must always
2885 consider all windows. */
2886 || type
== REPLACE_BUFFER_IN_WINDOWS_SAFELY
2887 || (mini
&& minibuf_level
> 0))
2890 case GET_BUFFER_WINDOW
:
2891 if (EQ (w
->contents
, obj
)
2892 /* Don't find any minibuffer window except the one that
2893 is currently in use. */
2894 && (MINI_WINDOW_P (w
) ? EQ (window
, minibuf_window
) : 1))
2896 if (EQ (window
, selected_window
))
2897 /* Preferably return the selected window. */
2898 RETURN_UNGCPRO (window
);
2899 else if (EQ (XWINDOW (window
)->frame
, selected_frame
)
2900 && !frame_best_window_flag
)
2901 /* Prefer windows on the current frame (but don't
2902 choose another one if we have one already). */
2904 best_window
= window
;
2905 frame_best_window_flag
= 1;
2907 else if (NILP (best_window
))
2908 best_window
= window
;
2912 case REPLACE_BUFFER_IN_WINDOWS_SAFELY
:
2913 /* We could simply check whether the buffer shown by window
2914 is live, and show another buffer in case it isn't. */
2915 if (EQ (w
->contents
, obj
))
2917 /* Undedicate WINDOW. */
2918 wset_dedicated (w
, Qnil
);
2919 /* Make WINDOW show the buffer returned by
2920 other_buffer_safely, don't run any hooks. */
2922 (window
, other_buffer_safely (w
->contents
), 0, 0);
2923 /* If WINDOW is the selected window, make its buffer
2924 current. But do so only if the window shows the
2925 current buffer (Bug#6454). */
2926 if (EQ (window
, selected_window
)
2927 && XBUFFER (w
->contents
) == current_buffer
)
2928 Fset_buffer (w
->contents
);
2932 case REDISPLAY_BUFFER_WINDOWS
:
2933 if (EQ (w
->contents
, obj
))
2935 mark_window_display_accurate (window
, 0);
2936 w
->update_mode_line
= 1;
2937 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2938 update_mode_lines
= 27;
2939 best_window
= window
;
2943 /* Check for a leaf window that has a killed buffer
2944 or broken markers. */
2945 case CHECK_ALL_WINDOWS
:
2946 if (BUFFERP (w
->contents
))
2948 struct buffer
*b
= XBUFFER (w
->contents
);
2950 if (!BUFFER_LIVE_P (b
))
2952 if (!MARKERP (w
->start
) || XMARKER (w
->start
)->buffer
!= b
)
2954 if (!MARKERP (w
->pointm
) || XMARKER (w
->pointm
)->buffer
!= b
)
2959 case WINDOW_LOOP_UNUSED
:
2968 /* Used for debugging. Abort if any window has a dead buffer. */
2970 extern void check_all_windows (void) EXTERNALLY_VISIBLE
;
2972 check_all_windows (void)
2974 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2977 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 0, 2, 0,
2978 doc
: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2979 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to
2982 The optional argument ALL-FRAMES specifies the frames to consider:
2984 - t means consider all windows on all existing frames.
2986 - `visible' means consider all windows on all visible frames.
2988 - 0 (the number zero) means consider all windows on all visible
2989 and iconified frames.
2991 - A frame means consider all windows on that frame only.
2993 Any other value of ALL-FRAMES means consider all windows on the
2994 selected frame and no others. */)
2995 (Lisp_Object buffer_or_name
, Lisp_Object all_frames
)
2999 if (NILP (buffer_or_name
))
3000 buffer
= Fcurrent_buffer ();
3002 buffer
= Fget_buffer (buffer_or_name
);
3004 if (BUFFERP (buffer
))
3005 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, all_frames
);
3012 resize_root_window (Lisp_Object window
, Lisp_Object delta
, Lisp_Object horizontal
, Lisp_Object ignore
, Lisp_Object pixelwise
)
3014 return call5 (Qwindow_resize_root_window
, window
, delta
, horizontal
, ignore
, pixelwise
);
3017 /* Placeholder used by temacs -nw before window.el is loaded. */
3018 DEFUN ("window--sanitize-window-sizes", Fwindow__sanitize_window_sizes
,
3019 Swindow__sanitize_window_sizes
, 2, 2, 0,
3021 (Lisp_Object frame
, Lisp_Object horizontal
)
3027 sanitize_window_sizes (Lisp_Object frame
, Lisp_Object horizontal
)
3029 return call2 (Qwindow_sanitize_window_sizes
, frame
, horizontal
);
3034 window_pixel_to_total (Lisp_Object frame
, Lisp_Object horizontal
)
3036 return call2 (Qwindow_pixel_to_total
, frame
, horizontal
);
3040 DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal
,
3041 Sdelete_other_windows_internal
, 0, 2, "",
3042 doc
: /* Make WINDOW fill its frame.
3043 Only the frame WINDOW is on is affected. WINDOW must be a valid window
3044 and defaults to the selected one.
3046 Optional argument ROOT, if non-nil, must specify an internal window such
3047 that WINDOW is in its window subtree. If this is the case, replace ROOT
3048 by WINDOW and leave alone any windows not part of ROOT's subtree.
3050 When WINDOW is live try to reduce display jumps by keeping the text
3051 previously visible in WINDOW in the same place on the frame. Doing this
3052 depends on the value of (window-start WINDOW), so if calling this
3053 function in a program gives strange scrolling, make sure the
3054 window-start value is reasonable when this function is called. */)
3055 (Lisp_Object window
, Lisp_Object root
)
3057 struct window
*w
, *r
, *s
;
3059 Lisp_Object sibling
, pwindow
, swindow
IF_LINT (= Qnil
), delta
;
3060 ptrdiff_t startpos
IF_LINT (= 0), startbyte
IF_LINT (= 0);
3061 int top
IF_LINT (= 0), new_top
, resize_failed
;
3063 w
= decode_valid_window (window
);
3064 XSETWINDOW (window
, w
);
3065 f
= XFRAME (w
->frame
);
3068 /* ROOT is the frame's root window. */
3070 root
= FRAME_ROOT_WINDOW (f
);
3074 /* ROOT must be an ancestor of WINDOW. */
3076 r
= decode_valid_window (root
);
3077 pwindow
= XWINDOW (window
)->parent
;
3078 while (!NILP (pwindow
))
3079 if (EQ (pwindow
, root
))
3082 pwindow
= XWINDOW (pwindow
)->parent
;
3083 if (!EQ (pwindow
, root
))
3084 error ("Specified root is not an ancestor of specified window");
3087 if (EQ (window
, root
))
3090 /* I don't understand the "top > 0" part below. If we deal with a
3091 standalone minibuffer it would have been caught by the preceding
3093 else if (MINI_WINDOW_P (w
)) /* && top > 0) */
3094 error ("Can't expand minibuffer to full frame");
3096 if (BUFFERP (w
->contents
))
3098 startpos
= marker_position (w
->start
);
3099 startbyte
= marker_byte_position (w
->start
);
3100 top
= (WINDOW_TOP_EDGE_LINE (w
)
3101 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
))));
3102 /* Make sure WINDOW is the frame's selected window. */
3103 if (!EQ (window
, FRAME_SELECTED_WINDOW (f
)))
3105 if (EQ (selected_frame
, w
->frame
))
3106 Fselect_window (window
, Qnil
);
3108 fset_selected_window (f
, window
);
3113 /* See if the frame's selected window is a part of the window
3114 subtree rooted at WINDOW, by finding all the selected window's
3115 parents and comparing each one with WINDOW. If it isn't we
3116 need a new selected window for this frame. */
3117 swindow
= FRAME_SELECTED_WINDOW (f
);
3121 while (!NILP (pwindow
) && !EQ (window
, pwindow
))
3122 pwindow
= XWINDOW (pwindow
)->parent
;
3124 if (EQ (window
, pwindow
))
3125 /* If WINDOW is an ancestor of SWINDOW, then SWINDOW is ok
3126 as the new selected window. */
3129 /* Else try the previous window of SWINDOW. */
3130 swindow
= Fprevious_window (swindow
, Qlambda
, Qnil
);
3133 if (!EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
3135 if (EQ (selected_frame
, w
->frame
))
3136 Fselect_window (swindow
, Qnil
);
3138 fset_selected_window (f
, swindow
);
3143 if (!FRAME_INITIAL_P (f
))
3145 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
3147 /* We are going to free the glyph matrices of WINDOW, and with
3148 that we might lose any information about glyph rows that have
3149 some of their glyphs highlighted in mouse face. (These rows
3150 are marked with a non-zero mouse_face_p flag.) If WINDOW
3151 indeed has some glyphs highlighted in mouse face, signal to
3152 frame's up-to-date hook that mouse highlight was overwritten,
3153 so that it will arrange for redisplaying the highlight. */
3154 if (EQ (hlinfo
->mouse_face_window
, window
))
3155 reset_mouse_highlight (hlinfo
);
3157 free_window_matrices (r
);
3160 Vwindow_list
= Qnil
;
3161 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3164 if (!WINDOW_LEAF_P (w
))
3166 /* Resize child windows vertically. */
3167 XSETINT (delta
, r
->pixel_height
- w
->pixel_height
);
3168 w
->pixel_top
= r
->pixel_top
;
3169 w
->top_line
= r
->top_line
;
3170 resize_root_window (window
, delta
, Qnil
, Qnil
, Qt
);
3171 if (window_resize_check (w
, 0))
3173 window_resize_apply (w
, 0);
3174 window_pixel_to_total (w
->frame
, Qnil
);
3178 resize_root_window (window
, delta
, Qnil
, Qt
, Qt
);
3179 if (window_resize_check (w
, 0))
3181 window_resize_apply (w
, 0);
3182 window_pixel_to_total (w
->frame
, Qnil
);
3188 /* Resize child windows horizontally. */
3191 w
->left_col
= r
->left_col
;
3192 w
->pixel_left
= r
->pixel_left
;
3193 XSETINT (delta
, r
->pixel_width
- w
->pixel_width
);
3194 resize_root_window (window
, delta
, Qt
, Qnil
, Qt
);
3195 if (window_resize_check (w
, 1))
3197 window_resize_apply (w
, 1);
3198 window_pixel_to_total (w
->frame
, Qt
);
3202 resize_root_window (window
, delta
, Qt
, Qt
, Qt
);
3203 if (window_resize_check (w
, 1))
3205 window_resize_apply (w
, 1);
3206 window_pixel_to_total (w
->frame
, Qt
);
3214 /* Play safe, if we still can ... */
3217 w
= XWINDOW (window
);
3221 /* Cleanly unlink WINDOW from window-tree. */
3222 if (!NILP (w
->prev
))
3223 /* Get SIBLING above (on the left of) WINDOW. */
3226 s
= XWINDOW (sibling
);
3227 wset_next (s
, w
->next
);
3228 if (!NILP (s
->next
))
3229 wset_prev (XWINDOW (s
->next
), sibling
);
3232 /* Get SIBLING below (on the right of) WINDOW. */
3235 s
= XWINDOW (sibling
);
3236 wset_prev (s
, Qnil
);
3237 wset_combination (XWINDOW (w
->parent
),
3238 XWINDOW (w
->parent
)->horizontal
, sibling
);
3241 /* Delete ROOT and all child windows of ROOT. */
3242 if (WINDOWP (r
->contents
))
3244 delete_all_child_windows (r
->contents
);
3245 wset_combination (r
, 0, Qnil
);
3248 replace_window (root
, window
, 1);
3250 /* This must become SWINDOW anyway ....... */
3251 if (BUFFERP (w
->contents
) && !resize_failed
)
3253 /* Try to minimize scrolling, by setting the window start to the
3254 point will cause the text at the old window start to be at the
3255 same place on the frame. But don't try to do this if the
3256 window start is outside the visible portion (as might happen
3257 when the display is not current, due to typeahead). */
3258 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
3260 && startpos
>= BUF_BEGV (XBUFFER (w
->contents
))
3261 && startpos
<= BUF_ZV (XBUFFER (w
->contents
)))
3263 struct position pos
;
3264 struct buffer
*obuf
= current_buffer
;
3266 Fset_buffer (w
->contents
);
3267 /* This computation used to temporarily move point, but that
3268 can have unwanted side effects due to text properties. */
3269 pos
= *vmotion (startpos
, startbyte
, -top
, w
);
3271 set_marker_both (w
->start
, w
->contents
, pos
.bufpos
, pos
.bytepos
);
3272 w
->window_end_valid
= 0;
3273 w
->start_at_line_beg
= (pos
.bytepos
== BEGV_BYTE
3274 || FETCH_BYTE (pos
.bytepos
- 1) == '\n');
3275 /* We need to do this, so that the window-scroll-functions
3277 w
->optional_new_start
= 1;
3279 set_buffer_internal (obuf
);
3283 adjust_frame_glyphs (f
);
3286 run_window_configuration_change_hook (f
);
3293 replace_buffer_in_windows (Lisp_Object buffer
)
3295 call1 (Qreplace_buffer_in_windows
, buffer
);
3298 /* If BUFFER is shown in a window, safely replace it with some other
3299 buffer in all windows of all frames, even those on other keyboards. */
3302 replace_buffer_in_windows_safely (Lisp_Object buffer
)
3304 if (buffer_window_count (XBUFFER (buffer
)))
3306 Lisp_Object tail
, frame
;
3308 /* A single call to window_loop won't do the job because it only
3309 considers frames on the current keyboard. So loop manually over
3310 frames, and handle each one. */
3311 FOR_EACH_FRAME (tail
, frame
)
3312 window_loop (REPLACE_BUFFER_IN_WINDOWS_SAFELY
, buffer
, 1, frame
);
3316 /* The following three routines are needed for running a window's
3317 configuration change hook. */
3319 run_funs (Lisp_Object funs
)
3321 for (; CONSP (funs
); funs
= XCDR (funs
))
3322 if (!EQ (XCAR (funs
), Qt
))
3323 call0 (XCAR (funs
));
3327 select_window_norecord (Lisp_Object window
)
3329 if (WINDOW_LIVE_P (window
))
3330 Fselect_window (window
, Qt
);
3334 select_frame_norecord (Lisp_Object frame
)
3336 if (FRAME_LIVE_P (XFRAME (frame
)))
3337 Fselect_frame (frame
, Qt
);
3341 run_window_configuration_change_hook (struct frame
*f
)
3343 ptrdiff_t count
= SPECPDL_INDEX ();
3344 Lisp_Object frame
, global_wcch
3345 = Fdefault_value (Qwindow_configuration_change_hook
);
3346 XSETFRAME (frame
, f
);
3348 if (NILP (Vrun_hooks
)
3349 || !(f
->can_x_set_window_size
)
3350 || !(f
->can_run_window_configuration_change_hook
))
3353 /* Use the right buffer. Matters when running the local hooks. */
3354 if (current_buffer
!= XBUFFER (Fwindow_buffer (Qnil
)))
3356 record_unwind_current_buffer ();
3357 Fset_buffer (Fwindow_buffer (Qnil
));
3360 if (SELECTED_FRAME () != f
)
3362 record_unwind_protect (select_frame_norecord
, selected_frame
);
3363 select_frame_norecord (frame
);
3366 /* Look for buffer-local values. */
3368 Lisp_Object windows
= Fwindow_list (frame
, Qlambda
, Qnil
);
3369 for (; CONSP (windows
); windows
= XCDR (windows
))
3371 Lisp_Object window
= XCAR (windows
);
3372 Lisp_Object buffer
= Fwindow_buffer (window
);
3373 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook
,
3376 ptrdiff_t inner_count
= SPECPDL_INDEX ();
3377 record_unwind_protect (select_window_norecord
, selected_window
);
3378 select_window_norecord (window
);
3379 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook
,
3381 unbind_to (inner_count
, Qnil
);
3386 run_funs (global_wcch
);
3387 unbind_to (count
, Qnil
);
3390 DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook
,
3391 Srun_window_configuration_change_hook
, 0, 1, 0,
3392 doc
: /* Run `window-configuration-change-hook' for FRAME.
3393 If FRAME is omitted or nil, it defaults to the selected frame. */)
3396 run_window_configuration_change_hook (decode_live_frame (frame
));
3400 DEFUN ("run-window-scroll-functions", Frun_window_scroll_functions
,
3401 Srun_window_scroll_functions
, 0, 1, 0,
3402 doc
: /* Run `window-scroll-functions' for WINDOW.
3403 If WINDOW is omitted or nil, it defaults to the selected window. */)
3404 (Lisp_Object window
)
3406 if (! NILP (Vwindow_scroll_functions
))
3407 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3408 Fmarker_position (decode_live_window (window
)->start
));
3412 /* Make WINDOW display BUFFER. RUN_HOOKS_P non-zero means it's allowed
3413 to run hooks. See make_frame for a case where it's not allowed.
3414 KEEP_MARGINS_P non-zero means that the current margins, fringes, and
3415 scroll-bar settings of the window are not reset from the buffer's
3419 set_window_buffer (Lisp_Object window
, Lisp_Object buffer
,
3420 bool run_hooks_p
, bool keep_margins_p
)
3422 struct window
*w
= XWINDOW (window
);
3423 struct buffer
*b
= XBUFFER (buffer
);
3424 ptrdiff_t count
= SPECPDL_INDEX ();
3425 bool samebuf
= EQ (buffer
, w
->contents
);
3427 wset_buffer (w
, buffer
);
3429 if (EQ (window
, selected_window
))
3430 bset_last_selected_window (b
, window
);
3432 /* Let redisplay errors through. */
3433 b
->display_error_modiff
= 0;
3435 /* Update time stamps of buffer display. */
3436 if (INTEGERP (BVAR (b
, display_count
)))
3437 bset_display_count (b
, make_number (XINT (BVAR (b
, display_count
)) + 1));
3438 bset_display_time (b
, Fcurrent_time ());
3440 w
->window_end_pos
= 0;
3441 w
->window_end_vpos
= 0;
3442 w
->last_cursor_vpos
= 0;
3444 if (!(keep_margins_p
&& samebuf
))
3445 { /* If we're not actually changing the buffer, don't reset hscroll
3446 and vscroll. This case happens for example when called from
3447 change_frame_size_1, where we use a dummy call to
3448 Fset_window_buffer on the frame's selected window (and no
3449 other) just in order to run window-configuration-change-hook
3450 (no longer true since change_frame_size_1 directly calls
3451 run_window_configuration_change_hook). Resetting hscroll and
3452 vscroll here is problematic for things like image-mode and
3453 doc-view-mode since it resets the image's position whenever we
3454 resize the frame. */
3455 w
->hscroll
= w
->min_hscroll
= w
->hscroll_whole
= 0;
3456 w
->suspend_auto_hscroll
= 0;
3458 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3459 set_marker_both (w
->old_pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3460 set_marker_restricted (w
->start
,
3461 make_number (b
->last_window_start
),
3463 w
->start_at_line_beg
= 0;
3466 /* Maybe we could move this into the `if' but it's not obviously safe and
3467 I doubt it's worth the trouble. */
3469 w
->update_mode_line
= true;
3471 /* We must select BUFFER to run the window-scroll-functions and to look up
3472 the buffer-local value of Vwindow_point_insertion_type. */
3473 record_unwind_current_buffer ();
3474 Fset_buffer (buffer
);
3476 XMARKER (w
->pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3477 XMARKER (w
->old_pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3479 if (!keep_margins_p
)
3481 /* Set left and right marginal area width etc. from buffer. */
3482 set_window_fringes (w
, BVAR (b
, left_fringe_width
),
3483 BVAR (b
, right_fringe_width
),
3484 BVAR (b
, fringes_outside_margins
));
3485 set_window_scroll_bars (w
, BVAR (b
, scroll_bar_width
),
3486 BVAR (b
, vertical_scroll_bar_type
),
3487 BVAR (b
, scroll_bar_height
),
3488 BVAR (b
, horizontal_scroll_bar_type
));
3489 set_window_margins (w
, BVAR (b
, left_margin_cols
),
3490 BVAR (b
, right_margin_cols
));
3491 apply_window_adjustment (w
);
3496 if (! NILP (Vwindow_scroll_functions
))
3497 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3498 Fmarker_position (w
->start
));
3500 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w
)));
3503 unbind_to (count
, Qnil
);
3506 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3507 doc
: /* Make WINDOW display BUFFER-OR-NAME.
3508 WINDOW must be a live window and defaults to the selected one.
3509 BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
3511 Optional third argument KEEP-MARGINS non-nil means that WINDOW's current
3512 display margins, fringe widths, and scroll bar settings are preserved;
3513 the default is to reset these from the local settings for BUFFER-OR-NAME
3514 or the frame defaults. Return nil.
3516 This function throws an error when WINDOW is strongly dedicated to its
3517 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3518 already display BUFFER-OR-NAME.
3520 This function runs `window-scroll-functions' before running
3521 `window-configuration-change-hook'. */)
3522 (register Lisp_Object window
, Lisp_Object buffer_or_name
, Lisp_Object keep_margins
)
3524 register Lisp_Object tem
, buffer
;
3525 register struct window
*w
= decode_live_window (window
);
3527 XSETWINDOW (window
, w
);
3528 buffer
= Fget_buffer (buffer_or_name
);
3529 CHECK_BUFFER (buffer
);
3530 if (!BUFFER_LIVE_P (XBUFFER (buffer
)))
3531 error ("Attempt to display deleted buffer");
3535 error ("Window is deleted");
3538 if (!EQ (tem
, buffer
))
3540 if (EQ (w
->dedicated
, Qt
))
3541 /* WINDOW is strongly dedicated to its buffer, signal an
3543 error ("Window is dedicated to `%s'", SDATA (BVAR (XBUFFER (tem
), name
)));
3545 /* WINDOW is weakly dedicated to its buffer, reset
3547 wset_dedicated (w
, Qnil
);
3549 call1 (Qrecord_window_buffer
, window
);
3555 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3561 display_buffer (Lisp_Object buffer
, Lisp_Object not_this_window_p
, Lisp_Object override_frame
)
3563 return call3 (Qdisplay_buffer
, buffer
, not_this_window_p
, override_frame
);
3566 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3568 doc
: /* Force all windows to be updated on next redisplay.
3569 If optional arg OBJECT is a window, force redisplay of that window only.
3570 If OBJECT is a buffer or buffer name, force redisplay of all windows
3571 displaying that buffer. */)
3572 (Lisp_Object object
)
3576 windows_or_buffers_changed
= 29;
3577 update_mode_lines
= 28;
3581 if (WINDOWP (object
))
3583 struct window
*w
= XWINDOW (object
);
3584 mark_window_display_accurate (object
, 0);
3585 w
->update_mode_line
= 1;
3586 if (BUFFERP (w
->contents
))
3587 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
3588 update_mode_lines
= 29;
3592 if (STRINGP (object
))
3593 object
= Fget_buffer (object
);
3594 if (BUFFERP (object
) && BUFFER_LIVE_P (XBUFFER (object
))
3595 && buffer_window_count (XBUFFER (object
)))
3597 /* If buffer is live and shown in at least one window, find
3598 all windows showing this buffer and force update of them. */
3599 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3600 return NILP (object
) ? Qnil
: Qt
;
3603 /* If nothing suitable was found, just return.
3604 We could signal an error, but this feature will typically be used
3605 asynchronously in timers or process sentinels, so we don't. */
3609 /* Obsolete since 24.3. */
3611 temp_output_buffer_show (register Lisp_Object buf
)
3613 register struct buffer
*old
= current_buffer
;
3614 register Lisp_Object window
;
3615 register struct window
*w
;
3617 bset_directory (XBUFFER (buf
), BVAR (current_buffer
, directory
));
3620 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3624 set_buffer_internal (old
);
3626 if (!NILP (Vtemp_buffer_show_function
))
3627 call1 (Vtemp_buffer_show_function
, buf
);
3628 else if (WINDOW_LIVE_P (window
= display_buffer (buf
, Qnil
, Qnil
)))
3630 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3631 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3632 Vminibuf_scroll_window
= window
;
3633 w
= XWINDOW (window
);
3634 w
->hscroll
= w
->min_hscroll
= w
->hscroll_whole
= 0;
3635 w
->suspend_auto_hscroll
= 0;
3636 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3637 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3638 set_marker_restricted_both (w
->old_pointm
, buf
, BEG
, BEG
);
3640 /* Run temp-buffer-show-hook, with the chosen window selected
3641 and its buffer current. */
3643 ptrdiff_t count
= SPECPDL_INDEX ();
3644 Lisp_Object prev_window
, prev_buffer
;
3645 prev_window
= selected_window
;
3646 XSETBUFFER (prev_buffer
, old
);
3648 /* Select the window that was chosen, for running the hook.
3649 Note: Both Fselect_window and select_window_norecord may
3650 set-buffer to the buffer displayed in the window,
3651 so we need to save the current buffer. --stef */
3652 record_unwind_protect (restore_buffer
, prev_buffer
);
3653 record_unwind_protect (select_window_norecord
, prev_window
);
3654 Fselect_window (window
, Qt
);
3655 Fset_buffer (w
->contents
);
3656 Frun_hooks (1, &Qtemp_buffer_show_hook
);
3657 unbind_to (count
, Qnil
);
3662 /* Make new window, have it replace WINDOW in window-tree, and make
3663 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
3664 horizontal child). */
3666 make_parent_window (Lisp_Object window
, bool horflag
)
3669 register struct window
*o
, *p
;
3671 o
= XWINDOW (window
);
3672 p
= allocate_window ();
3673 memcpy ((char *) p
+ sizeof (struct vectorlike_header
),
3674 (char *) o
+ sizeof (struct vectorlike_header
),
3675 word_size
* VECSIZE (struct window
));
3676 /* P's buffer slot may change from nil to a buffer... */
3677 adjust_window_count (p
, 1);
3678 XSETWINDOW (parent
, p
);
3680 p
->sequence_number
= ++sequence_number
;
3682 replace_window (window
, parent
, 1);
3684 wset_next (o
, Qnil
);
3685 wset_prev (o
, Qnil
);
3686 wset_parent (o
, parent
);
3687 /* ...but now P becomes an internal window. */
3688 wset_start (p
, Qnil
);
3689 wset_pointm (p
, Qnil
);
3690 wset_old_pointm (p
, Qnil
);
3691 wset_buffer (p
, Qnil
);
3692 wset_combination (p
, horflag
, window
);
3693 wset_combination_limit (p
, Qnil
);
3694 wset_window_parameters (p
, Qnil
);
3697 /* Make new window from scratch. */
3702 register struct window
*w
;
3704 w
= allocate_window ();
3705 /* Initialize Lisp data. Note that allocate_window initializes all
3706 Lisp data to nil, so do it only for slots which should not be nil. */
3707 wset_normal_lines (w
, make_float (1.0));
3708 wset_normal_cols (w
, make_float (1.0));
3709 wset_new_total (w
, make_number (0));
3710 wset_new_normal (w
, make_number (0));
3711 wset_new_pixel (w
, make_number (0));
3712 wset_start (w
, Fmake_marker ());
3713 wset_pointm (w
, Fmake_marker ());
3714 wset_old_pointm (w
, Fmake_marker ());
3715 wset_vertical_scroll_bar_type (w
, Qt
);
3716 wset_horizontal_scroll_bar_type (w
, Qt
);
3717 /* These Lisp fields are marked specially so they're not set to nil by
3719 wset_prev_buffers (w
, Qnil
);
3720 wset_next_buffers (w
, Qnil
);
3722 /* Initialize non-Lisp data. Note that allocate_window zeroes out all
3723 non-Lisp data, so do it only for slots which should not be zero. */
3724 w
->nrows_scale_factor
= w
->ncols_scale_factor
= 1;
3725 w
->left_fringe_width
= w
->right_fringe_width
= -1;
3726 w
->mode_line_height
= w
->header_line_height
= -1;
3727 #ifdef HAVE_WINDOW_SYSTEM
3728 w
->phys_cursor_type
= NO_CURSOR
;
3729 w
->phys_cursor_width
= -1;
3731 w
->sequence_number
= ++sequence_number
;
3732 w
->scroll_bar_width
= -1;
3733 w
->scroll_bar_height
= -1;
3734 w
->column_number_displayed
= -1;
3735 /* Reset window_list. */
3736 Vwindow_list
= Qnil
;
3737 /* Return window. */
3738 XSETWINDOW (window
, w
);
3742 DEFUN ("set-window-new-pixel", Fset_window_new_pixel
, Sset_window_new_pixel
, 2, 3, 0,
3743 doc
: /* Set new pixel size of WINDOW to SIZE.
3744 WINDOW must be a valid window and defaults to the selected one.
3747 Optional argument ADD non-nil means add SIZE to the new pixel size of
3748 WINDOW and return the sum.
3750 The new pixel size of WINDOW, if valid, will be shortly installed as
3751 WINDOW's pixel height (see `window-pixel-height') or pixel width (see
3752 `window-pixel-width').
3754 Note: This function does not operate on any child windows of WINDOW. */)
3755 (Lisp_Object window
, Lisp_Object size
, Lisp_Object add
)
3757 struct window
*w
= decode_valid_window (window
);
3758 EMACS_INT size_min
= NILP (add
) ? 0 : - XINT (w
->new_pixel
);
3759 EMACS_INT size_max
= size_min
+ min (INT_MAX
, MOST_POSITIVE_FIXNUM
);
3761 CHECK_RANGED_INTEGER (size
, size_min
, size_max
);
3763 wset_new_pixel (w
, size
);
3765 wset_new_pixel (w
, make_number (XINT (w
->new_pixel
) + XINT (size
)));
3767 return w
->new_pixel
;
3770 DEFUN ("set-window-new-total", Fset_window_new_total
, Sset_window_new_total
, 2, 3, 0,
3771 doc
: /* Set new total size of WINDOW to SIZE.
3772 WINDOW must be a valid window and defaults to the selected one.
3775 Optional argument ADD non-nil means add SIZE to the new total size of
3776 WINDOW and return the sum.
3778 The new total size of WINDOW, if valid, will be shortly installed as
3779 WINDOW's total height (see `window-total-height') or total width (see
3780 `window-total-width').
3782 Note: This function does not operate on any child windows of WINDOW. */)
3783 (Lisp_Object window
, Lisp_Object size
, Lisp_Object add
)
3785 struct window
*w
= decode_valid_window (window
);
3787 CHECK_NUMBER (size
);
3789 wset_new_total (w
, size
);
3791 wset_new_total (w
, make_number (XINT (w
->new_total
) + XINT (size
)));
3793 return w
->new_total
;
3796 DEFUN ("set-window-new-normal", Fset_window_new_normal
, Sset_window_new_normal
, 1, 2, 0,
3797 doc
: /* Set new normal size of WINDOW to SIZE.
3798 WINDOW must be a valid window and defaults to the selected one.
3801 The new normal size of WINDOW, if valid, will be shortly installed as
3802 WINDOW's normal size (see `window-normal-size').
3804 Note: This function does not operate on any child windows of WINDOW. */)
3805 (Lisp_Object window
, Lisp_Object size
)
3807 wset_new_normal (decode_valid_window (window
), size
);
3811 /* Return 1 if setting w->pixel_height (w->pixel_width if HORFLAG is
3812 non-zero) to w->new_pixel would result in correct heights (widths)
3813 for window W and recursively all child windows of W.
3815 Note: This function does not check any of `window-fixed-size-p',
3816 `window-min-height' or `window-min-width'. It does check that window
3817 sizes do not drop below one line (two columns). */
3819 window_resize_check (struct window
*w
, bool horflag
)
3821 struct frame
*f
= XFRAME (w
->frame
);
3824 if (WINDOW_VERTICAL_COMBINATION_P (w
))
3825 /* W is a vertical combination. */
3827 c
= XWINDOW (w
->contents
);
3829 /* All child windows of W must have the same width as W. */
3833 if (XINT (c
->new_pixel
) != XINT (w
->new_pixel
)
3834 || !window_resize_check (c
, horflag
))
3837 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3843 /* The sum of the heights of the child windows of W must equal
3846 int remaining_pixels
= XINT (w
->new_pixel
);
3850 if (!window_resize_check (c
, horflag
))
3853 remaining_pixels
-= XINT (c
->new_pixel
);
3854 if (remaining_pixels
< 0)
3856 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3859 return remaining_pixels
== 0;
3862 else if (WINDOW_HORIZONTAL_COMBINATION_P (w
))
3863 /* W is a horizontal combination. */
3865 c
= XWINDOW (w
->contents
);
3867 /* The sum of the widths of the child windows of W must equal W's
3870 int remaining_pixels
= XINT (w
->new_pixel
);
3874 if (!window_resize_check (c
, horflag
))
3877 remaining_pixels
-= XINT (c
->new_pixel
);
3878 if (remaining_pixels
< 0)
3880 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3883 return remaining_pixels
== 0;
3886 /* All child windows of W must have the same height as W. */
3890 if (XINT (c
->new_pixel
) != XINT (w
->new_pixel
)
3891 || !window_resize_check (c
, horflag
))
3894 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3901 /* A leaf window. Make sure it's not too small. The following
3902 hardcodes the values of `window-safe-min-width' (2) and
3903 `window-safe-min-height' (1) which are defined in window.el. */
3904 return (XINT (w
->new_pixel
) >= (horflag
3905 ? (2 * FRAME_COLUMN_WIDTH (f
))
3906 : FRAME_LINE_HEIGHT (f
)));
3910 /* Set w->pixel_height (w->pixel_width if HORFLAG is non-zero) to
3911 w->new_pixel for window W and recursively all child windows of W.
3912 Also calculate and assign the new vertical (horizontal) pixel start
3913 positions of each of these windows.
3915 This function does not perform any error checks. Make sure you have
3916 run window_resize_check on W before applying this function. */
3918 window_resize_apply (struct window
*w
, bool horflag
)
3923 ? FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
))
3924 : FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
)));
3926 /* Note: Assigning new_normal requires that the new total size of the
3927 parent window has been set *before*. */
3930 w
->pixel_width
= XFASTINT (w
->new_pixel
);
3931 w
->total_cols
= w
->pixel_width
/ unit
;
3932 if (NUMBERP (w
->new_normal
))
3933 wset_normal_cols (w
, w
->new_normal
);
3935 edge
= w
->pixel_left
;
3939 w
->pixel_height
= XFASTINT (w
->new_pixel
);
3940 w
->total_lines
= w
->pixel_height
/ unit
;
3941 if (NUMBERP (w
->new_normal
))
3942 wset_normal_lines (w
, w
->new_normal
);
3944 edge
= w
->pixel_top
;
3947 if (WINDOW_VERTICAL_COMBINATION_P (w
))
3948 /* W is a vertical combination. */
3950 c
= XWINDOW (w
->contents
);
3955 c
->pixel_left
= edge
;
3956 c
->left_col
= edge
/ unit
;
3960 c
->pixel_top
= edge
;
3961 c
->top_line
= edge
/ unit
;
3963 window_resize_apply (c
, horflag
);
3965 edge
= edge
+ c
->pixel_height
;
3967 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3970 else if (WINDOW_HORIZONTAL_COMBINATION_P (w
))
3971 /* W is a horizontal combination. */
3973 c
= XWINDOW (w
->contents
);
3978 c
->pixel_left
= edge
;
3979 c
->left_col
= edge
/ unit
;
3983 c
->pixel_top
= edge
;
3984 c
->top_line
= edge
/ unit
;
3987 window_resize_apply (c
, horflag
);
3989 edge
= edge
+ c
->pixel_width
;
3991 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3996 w
->window_end_valid
= 0;
4000 /* Set w->total_lines (w->total_cols if HORFLAG is non-zero) to
4001 w->new_total for window W and recursively all child windows of W.
4002 Also calculate and assign the new vertical (horizontal) start
4003 positions of each of these windows. */
4005 window_resize_apply_total (struct window
*w
, bool horflag
)
4010 /* Note: Assigning new_normal requires that the new total size of the
4011 parent window has been set *before*. */
4014 w
->total_cols
= XFASTINT (w
->new_total
);
4019 w
->total_lines
= XFASTINT (w
->new_total
);
4023 if (WINDOW_VERTICAL_COMBINATION_P (w
))
4024 /* W is a vertical combination. */
4026 c
= XWINDOW (w
->contents
);
4034 window_resize_apply_total (c
, horflag
);
4036 edge
= edge
+ c
->total_lines
;
4038 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4041 else if (WINDOW_HORIZONTAL_COMBINATION_P (w
))
4042 /* W is a horizontal combination. */
4044 c
= XWINDOW (w
->contents
);
4052 window_resize_apply_total (c
, horflag
);
4054 edge
= edge
+ c
->total_cols
;
4056 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4061 DEFUN ("window-resize-apply", Fwindow_resize_apply
, Swindow_resize_apply
, 0, 2, 0,
4062 doc
: /* Apply requested size values for window-tree of FRAME.
4063 If FRAME is omitted or nil, it defaults to the selected frame.
4065 Optional argument HORIZONTAL omitted or nil means apply requested
4066 height values. HORIZONTAL non-nil means apply requested width values.
4068 The requested size values are those set by `set-window-new-pixel' and
4069 `set-window-new-normal'. This function checks whether the requested
4070 values sum up to a valid window layout, recursively assigns the new
4071 sizes of all child windows and calculates and assigns the new start
4072 positions of these windows.
4074 Return t if the requested values have been applied correctly, nil
4077 Note: This function does not check any of `window-fixed-size-p',
4078 `window-min-height' or `window-min-width'. All these checks have to
4079 be applied on the Elisp level. */)
4080 (Lisp_Object frame
, Lisp_Object horizontal
)
4082 struct frame
*f
= decode_live_frame (frame
);
4083 struct window
*r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4084 bool horflag
= !NILP (horizontal
);
4086 if (!window_resize_check (r
, horflag
)
4087 || (XINT (r
->new_pixel
)
4088 != (horflag
? r
->pixel_width
: r
->pixel_height
)))
4092 window_resize_apply (r
, horflag
);
4095 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4097 adjust_frame_glyphs (f
);
4104 DEFUN ("window-resize-apply-total", Fwindow_resize_apply_total
, Swindow_resize_apply_total
, 0, 2, 0,
4105 doc
: /* Apply requested total size values for window-tree of FRAME.
4106 If FRAME is omitted or nil, it defaults to the selected frame.
4108 This function does not assign pixel or normal size values. You should
4109 have run `window-resize-apply' before running this.
4111 Optional argument HORIZONTAL omitted or nil means apply requested
4112 height values. HORIZONTAL non-nil means apply requested width
4114 (Lisp_Object frame
, Lisp_Object horizontal
)
4116 struct frame
*f
= decode_live_frame (frame
);
4117 struct window
*r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4120 /* Necessary when deleting the top-/or leftmost window. */
4122 r
->top_line
= FRAME_TOP_MARGIN (f
);
4123 window_resize_apply_total (r
, !NILP (horizontal
));
4124 /* Handle the mini window. */
4125 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
4127 struct window
*m
= XWINDOW (f
->minibuffer_window
);
4129 if (NILP (horizontal
))
4131 m
->top_line
= r
->top_line
+ r
->total_lines
;
4132 m
->total_lines
= XFASTINT (m
->new_total
);
4135 m
->total_cols
= XFASTINT (m
->new_total
);
4144 /* Resize frame F's windows when number of lines of F is set to SIZE.
4145 HORFLAG 1 means resize windows when number of columns of F is set to
4146 SIZE. PIXELWISE 1 means to interpret SIZE as pixels. */
4148 resize_frame_windows (struct frame
*f
, int size
, bool horflag
, bool pixelwise
)
4150 Lisp_Object root
= f
->root_window
;
4151 struct window
*r
= XWINDOW (root
);
4152 Lisp_Object mini
= f
->minibuffer_window
;
4154 /* old_size is the old size of the frame's root window. */
4155 int old_size
= horflag
? r
->total_cols
: r
->total_lines
;
4156 int old_pixel_size
= horflag
? r
->pixel_width
: r
->pixel_height
;
4157 int old_pixel_top
= r
->pixel_top
;
4158 /* new_size is the new size of the frame's root window. */
4159 int new_size
, new_pixel_size
;
4160 int unit
= horflag
? FRAME_COLUMN_WIDTH (f
) : FRAME_LINE_HEIGHT (f
);
4162 /* Don't let the size drop below one unit. This is more comforting
4163 when we are called from x_set_tool_bar_lines since the latter may
4164 have implicitly given us a zero or negative height. */
4167 /* Note: This does not include the size for internal borders
4168 since these are not part of the frame's text area. */
4169 new_pixel_size
= max (horflag
4172 - ((FRAME_HAS_MINIBUF_P (f
)
4173 && !FRAME_MINIBUF_ONLY_P (f
))
4174 ? FRAME_LINE_HEIGHT (f
) : 0)),
4176 new_size
= new_pixel_size
/ unit
;
4180 new_size
= max (horflag
4183 - ((FRAME_HAS_MINIBUF_P (f
)
4184 && !FRAME_MINIBUF_ONLY_P (f
))
4187 new_pixel_size
= new_size
* unit
;
4190 r
->top_line
= FRAME_TOP_MARGIN (f
);
4191 r
->pixel_top
= FRAME_TOP_MARGIN_HEIGHT (f
);
4193 if (new_pixel_size
== old_pixel_size
4194 && r
->pixel_top
== old_pixel_top
)
4196 else if (WINDOW_LEAF_P (r
))
4197 /* For a leaf root window just set the size. */
4200 r
->total_cols
= new_size
;
4201 r
->pixel_width
= new_pixel_size
;
4205 r
->total_lines
= new_size
;
4206 r
->pixel_height
= new_pixel_size
;
4213 XSETINT (delta
, new_pixel_size
- old_pixel_size
);
4215 XSETINT (delta
, new_size
- old_size
);
4217 /* Try a "normal" resize first. */
4218 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qnil
,
4219 pixelwise
? Qt
: Qnil
);
4220 if (window_resize_check (r
, horflag
)
4221 && new_pixel_size
== XINT (r
->new_pixel
))
4223 window_resize_apply (r
, horflag
);
4224 window_pixel_to_total (r
->frame
, horflag
? Qt
: Qnil
);
4228 /* Try with "reasonable" minimum sizes next. */
4229 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qt
,
4230 pixelwise
? Qt
: Qnil
);
4231 if (window_resize_check (r
, horflag
)
4232 && new_pixel_size
== XINT (r
->new_pixel
))
4234 window_resize_apply (r
, horflag
);
4235 window_pixel_to_total (r
->frame
, horflag
? Qt
: Qnil
);
4236 #if 0 /* Let's try without safe sizes and/or killing other windows. */
4240 /* Finally, try with "safe" minimum sizes. */
4241 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qsafe
,
4242 pixelwise
? Qt
: Qnil
);
4243 if (window_resize_check (r
, horflag
)
4244 && new_pixel_size
== XINT (r
->new_pixel
))
4246 window_resize_apply (r
, horflag
);
4247 window_pixel_to_total (r
->frame
, horflag
? Qt
: Qnil
);
4251 /* We lost. Delete all windows but the frame's
4253 root
= f
->selected_window
;
4254 Fdelete_other_windows_internal (root
, Qnil
);
4257 XWINDOW (root
)->total_cols
= new_size
;
4258 XWINDOW (root
)->pixel_width
= new_pixel_size
;
4262 XWINDOW (root
)->total_lines
= new_size
;
4263 XWINDOW (root
)->pixel_height
= new_pixel_size
;
4271 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
4276 m
->total_cols
= size
;
4277 m
->pixel_width
= new_pixel_size
;
4281 /* Are we sure we always want 1 line here? */
4283 m
->pixel_height
= FRAME_LINE_HEIGHT (f
);
4284 m
->top_line
= r
->top_line
+ r
->total_lines
;
4285 m
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4293 DEFUN ("split-window-internal", Fsplit_window_internal
, Ssplit_window_internal
, 4, 4, 0,
4294 doc
: /* Split window OLD.
4295 Second argument PIXEL-SIZE specifies the number of pixels of the
4296 new window. In any case TOTAL-SIZE must be a positive integer.
4298 Third argument SIDE nil (or `below') specifies that the new window shall
4299 be located below WINDOW. SIDE `above' means the new window shall be
4300 located above WINDOW. In both cases PIXEL-SIZE specifies the pixel
4301 height of the new window including space reserved for the mode and/or
4304 SIDE t (or `right') specifies that the new window shall be located on
4305 the right side of WINDOW. SIDE `left' means the new window shall be
4306 located on the left of WINDOW. In both cases PIXEL-SIZE specifies the
4307 width of the new window including space reserved for fringes and the
4308 scrollbar or a divider column.
4310 Fourth argument NORMAL-SIZE specifies the normal size of the new window
4311 according to the SIDE argument.
4313 The new pixel and normal sizes of all involved windows must have been
4314 set correctly. See the code of `split-window' for how this is done. */)
4315 (Lisp_Object old
, Lisp_Object pixel_size
, Lisp_Object side
, Lisp_Object normal_size
)
4317 /* OLD (*o) is the window we have to split. (*p) is either OLD's
4318 parent window or an internal window we have to install as OLD's new
4319 parent. REFERENCE (*r) must denote a live window, or is set to OLD
4320 provided OLD is a leaf window, or to the frame's selected window.
4321 NEW (*n) is the new window created with some parameters taken from
4323 register Lisp_Object
new, frame
, reference
;
4324 register struct window
*o
, *p
, *n
, *r
, *c
;
4327 /* HORFLAG is 1 when we split side-by-side, 0 otherwise. */
4328 = EQ (side
, Qt
) || EQ (side
, Qleft
) || EQ (side
, Qright
);
4329 int combination_limit
= 0, sum
= 0;
4334 frame
= WINDOW_FRAME (o
);
4337 CHECK_NUMBER (pixel_size
);
4339 = XINT (pixel_size
) / (horflag
4340 ? FRAME_COLUMN_WIDTH (f
)
4341 : FRAME_LINE_HEIGHT (f
));
4343 /* Set combination_limit to 1 if we have to make a new parent window.
4344 We do that if either `window-combination-limit' is t, or OLD has no
4345 parent, or OLD is ortho-combined. */
4347 EQ (Vwindow_combination_limit
, Qt
)
4350 ? WINDOW_VERTICAL_COMBINATION_P (XWINDOW (o
->parent
))
4351 : WINDOW_HORIZONTAL_COMBINATION_P (XWINDOW (o
->parent
)));
4353 /* We need a live reference window to initialize some parameters. */
4354 if (WINDOW_LIVE_P (old
))
4355 /* OLD is live, use it as reference window. */
4358 /* Use the frame's selected window as reference window. */
4359 reference
= FRAME_SELECTED_WINDOW (f
);
4360 r
= XWINDOW (reference
);
4362 /* The following bugs are caught by `split-window'. */
4363 if (MINI_WINDOW_P (o
))
4364 error ("Attempt to split minibuffer window");
4365 else if (total_size
< (horflag
? 2 : 1))
4366 error ("Size of new window too small (after split)");
4367 else if (!combination_limit
&& !NILP (Vwindow_combination_resize
))
4368 /* `window-combination-resize' non-nil means try to resize OLD's siblings
4371 p
= XWINDOW (o
->parent
);
4372 /* Temporarily pretend we split the parent window. */
4374 (p
, make_number ((horflag
? p
->pixel_width
: p
->pixel_height
)
4375 - XINT (pixel_size
)));
4376 if (!window_resize_check (p
, horflag
))
4377 error ("Window sizes don't fit");
4379 /* Undo the temporary pretension. */
4380 wset_new_pixel (p
, make_number (horflag
? p
->pixel_width
: p
->pixel_height
));
4384 if (!window_resize_check (o
, horflag
))
4385 error ("Resizing old window failed");
4386 else if (XINT (pixel_size
) + XINT (o
->new_pixel
)
4387 != (horflag
? o
->pixel_width
: o
->pixel_height
))
4388 error ("Sum of sizes of old and new window don't fit");
4391 /* This is our point of no return. */
4392 if (combination_limit
)
4394 /* Save the old value of o->normal_cols/lines. It gets corrupted
4395 by make_parent_window and we need it below for assigning it to
4397 Lisp_Object new_normal
4398 = horflag
? o
->normal_cols
: o
->normal_lines
;
4400 make_parent_window (old
, horflag
);
4401 p
= XWINDOW (o
->parent
);
4402 if (EQ (Vwindow_combination_limit
, Qt
))
4403 /* Store t in the new parent's combination_limit slot to avoid
4404 that its children get merged into another window. */
4405 wset_combination_limit (p
, Qt
);
4406 /* These get applied below. */
4408 (p
, make_number (horflag
? o
->pixel_width
: o
->pixel_height
));
4410 (p
, make_number (horflag
? o
->total_cols
: o
->total_lines
));
4411 wset_new_normal (p
, new_normal
);
4414 p
= XWINDOW (o
->parent
);
4417 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4418 new = make_window ();
4420 wset_frame (n
, frame
);
4421 wset_parent (n
, o
->parent
);
4423 if (EQ (side
, Qabove
) || EQ (side
, Qleft
))
4425 wset_prev (n
, o
->prev
);
4427 wset_combination (p
, horflag
, new);
4429 wset_next (XWINDOW (n
->prev
), new);
4435 wset_next (n
, o
->next
);
4436 if (!NILP (n
->next
))
4437 wset_prev (XWINDOW (n
->next
), new);
4442 n
->window_end_valid
= 0;
4443 n
->last_cursor_vpos
= 0;
4445 /* Get special geometry settings from reference window. */
4446 n
->left_margin_cols
= r
->left_margin_cols
;
4447 n
->right_margin_cols
= r
->right_margin_cols
;
4448 n
->left_fringe_width
= r
->left_fringe_width
;
4449 n
->right_fringe_width
= r
->right_fringe_width
;
4450 n
->fringes_outside_margins
= r
->fringes_outside_margins
;
4451 n
->scroll_bar_width
= r
->scroll_bar_width
;
4452 n
->scroll_bar_height
= r
->scroll_bar_height
;
4453 wset_vertical_scroll_bar_type (n
, r
->vertical_scroll_bar_type
);
4454 wset_horizontal_scroll_bar_type (n
, r
->horizontal_scroll_bar_type
);
4456 /* Directly assign orthogonal coordinates and sizes. */
4459 n
->pixel_top
= o
->pixel_top
;
4460 n
->top_line
= o
->top_line
;
4461 n
->pixel_height
= o
->pixel_height
;
4462 n
->total_lines
= o
->total_lines
;
4466 n
->pixel_left
= o
->pixel_left
;
4467 n
->left_col
= o
->left_col
;
4468 n
->pixel_width
= o
->pixel_width
;
4469 n
->total_cols
= o
->total_cols
;
4472 /* Iso-coordinates and sizes are assigned by window_resize_apply,
4473 get them ready here. */
4474 wset_new_pixel (n
, pixel_size
);
4475 c
= XWINDOW (p
->contents
);
4479 sum
= sum
+ XINT (c
->new_total
);
4480 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4482 wset_new_total (n
, make_number ((horflag
4486 wset_new_normal (n
, normal_size
);
4489 window_resize_apply (p
, horflag
);
4490 adjust_frame_glyphs (f
);
4491 /* Set buffer of NEW to buffer of reference window. Don't run
4493 set_window_buffer (new, r
->contents
, 0, 1);
4496 /* Maybe we should run the scroll functions in Elisp (which already
4497 runs the configuration change hook). */
4498 if (! NILP (Vwindow_scroll_functions
))
4499 run_hook_with_args_2 (Qwindow_scroll_functions
, new,
4500 Fmarker_position (n
->start
));
4506 DEFUN ("delete-window-internal", Fdelete_window_internal
, Sdelete_window_internal
, 1, 1, 0,
4507 doc
: /* Remove WINDOW from its frame.
4508 WINDOW defaults to the selected window. Return nil.
4509 Signal an error when WINDOW is the only window on its frame. */)
4510 (register Lisp_Object window
)
4512 register Lisp_Object parent
, sibling
, frame
, root
;
4513 struct window
*w
, *p
, *s
, *r
;
4515 bool horflag
, before_sibling
= 0;
4517 w
= decode_any_window (window
);
4518 XSETWINDOW (window
, w
);
4519 if (NILP (w
->contents
))
4520 /* It's a no-op to delete an already deleted window. */
4525 /* Never delete a minibuffer or frame root window. */
4526 error ("Attempt to delete minibuffer or sole ordinary window");
4527 else if (NILP (w
->prev
) && NILP (w
->next
))
4528 /* Rather bow out here, this case should be handled on the Elisp
4530 error ("Attempt to delete sole window of parent");
4532 p
= XWINDOW (parent
);
4533 horflag
= WINDOW_HORIZONTAL_COMBINATION_P (p
);
4535 frame
= WINDOW_FRAME (w
);
4538 root
= FRAME_ROOT_WINDOW (f
);
4541 /* Unlink WINDOW from window tree. */
4543 /* Get SIBLING below (on the right of) WINDOW. */
4545 /* before_sibling 1 means WINDOW is the first child of its
4546 parent and thus before the sibling. */
4549 s
= XWINDOW (sibling
);
4550 wset_prev (s
, Qnil
);
4551 wset_combination (p
, horflag
, sibling
);
4554 /* Get SIBLING above (on the left of) WINDOW. */
4557 s
= XWINDOW (sibling
);
4558 wset_next (s
, w
->next
);
4559 if (!NILP (s
->next
))
4560 wset_prev (XWINDOW (s
->next
), sibling
);
4563 if (window_resize_check (r
, horflag
)
4564 && (XINT (r
->new_pixel
)
4565 == (horflag
? r
->pixel_width
: r
->pixel_height
)))
4566 /* We can delete WINDOW now. */
4571 window_resize_apply (p
, horflag
);
4572 /* If this window is referred to by the dpyinfo's mouse
4573 highlight, invalidate that slot to be safe (Bug#9904). */
4574 if (!FRAME_INITIAL_P (f
))
4576 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
4578 if (EQ (hlinfo
->mouse_face_window
, window
))
4579 hlinfo
->mouse_face_window
= Qnil
;
4583 Vwindow_list
= Qnil
;
4584 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4586 wset_next (w
, Qnil
); /* Don't delete w->next too. */
4587 free_window_matrices (w
);
4589 if (WINDOWP (w
->contents
))
4591 delete_all_child_windows (w
->contents
);
4592 wset_combination (w
, 0, Qnil
);
4597 unchain_marker (XMARKER (w
->pointm
));
4598 unchain_marker (XMARKER (w
->old_pointm
));
4599 unchain_marker (XMARKER (w
->start
));
4600 wset_buffer (w
, Qnil
);
4603 if (NILP (s
->prev
) && NILP (s
->next
))
4604 /* A matrjoshka where SIBLING has become the only child of
4607 /* Put SIBLING into PARENT's place. */
4608 replace_window (parent
, sibling
, 0);
4609 /* Have SIBLING inherit the following three slot values from
4610 PARENT (the combination_limit slot is not inherited). */
4611 wset_normal_cols (s
, p
->normal_cols
);
4612 wset_normal_lines (s
, p
->normal_lines
);
4613 /* Mark PARENT as deleted. */
4614 wset_combination (p
, 0, Qnil
);
4615 /* Try to merge SIBLING into its new parent. */
4616 recombine_windows (sibling
);
4619 adjust_frame_glyphs (f
);
4621 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f
)))
4622 /* We deleted the frame's selected window. */
4624 /* Use the frame's first window as fallback ... */
4625 Lisp_Object new_selected_window
= Fframe_first_window (frame
);
4626 /* ... but preferably use its most recently used window. */
4627 Lisp_Object mru_window
;
4629 /* `get-mru-window' might fail for some reason so play it safe
4630 - promote the first window _without recording it_ first. */
4631 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4632 Fselect_window (new_selected_window
, Qt
);
4634 fset_selected_window (f
, new_selected_window
);
4638 /* Now look whether `get-mru-window' gets us something. */
4639 mru_window
= call1 (Qget_mru_window
, frame
);
4640 if (WINDOW_LIVE_P (mru_window
)
4641 && EQ (XWINDOW (mru_window
)->frame
, frame
))
4642 new_selected_window
= mru_window
;
4644 /* If all ended up well, we now promote the mru window. */
4645 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4646 Fselect_window (new_selected_window
, Qnil
);
4648 fset_selected_window (f
, new_selected_window
);
4653 /* Must be run by the caller:
4654 run_window_configuration_change_hook (f); */
4657 /* We failed: Relink WINDOW into window tree. */
4661 wset_prev (s
, window
);
4662 wset_combination (p
, horflag
, window
);
4666 wset_next (s
, window
);
4667 if (!NILP (w
->next
))
4668 wset_prev (XWINDOW (w
->next
), window
);
4670 error ("Deletion failed");
4676 /***********************************************************************
4677 Resizing Mini-Windows
4678 ***********************************************************************/
4680 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we
4683 grow_mini_window (struct window
*w
, int delta
, bool pixelwise
)
4685 struct frame
*f
= XFRAME (w
->frame
);
4687 Lisp_Object root
, height
;
4688 int line_height
, pixel_height
;
4690 eassert (MINI_WINDOW_P (w
));
4691 eassert (delta
>= 0);
4695 root
= FRAME_ROOT_WINDOW (f
);
4697 height
= call3 (Qwindow_resize_root_window_vertically
,
4698 root
, make_number (- delta
), pixelwise
? Qt
: Qnil
);
4699 if (INTEGERP (height
) && window_resize_check (r
, 0))
4702 window_resize_apply (r
, 0);
4706 pixel_height
= min (-XINT (height
), INT_MAX
- w
->pixel_height
);
4707 line_height
= pixel_height
/ FRAME_LINE_HEIGHT (f
);
4711 line_height
= min (-XINT (height
),
4712 ((INT_MAX
- w
->pixel_height
)
4713 / FRAME_LINE_HEIGHT (f
)));
4714 pixel_height
= line_height
* FRAME_LINE_HEIGHT (f
);
4717 /* Grow the mini-window. */
4718 w
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4719 w
->top_line
= r
->top_line
+ r
->total_lines
;
4720 /* Make sure the mini-window has always at least one line. */
4721 w
->pixel_height
= max (w
->pixel_height
+ pixel_height
,
4722 FRAME_LINE_HEIGHT (f
));
4723 w
->total_lines
= max (w
->total_lines
+ line_height
, 1);
4725 /* Enforce full redisplay of the frame. */
4726 /* FIXME: Shouldn't window--resize-root-window-vertically do it? */
4728 adjust_frame_glyphs (f
);
4734 /* Shrink mini-window W to one line. */
4736 shrink_mini_window (struct window
*w
, bool pixelwise
)
4738 struct frame
*f
= XFRAME (w
->frame
);
4740 Lisp_Object root
, delta
;
4741 EMACS_INT height
, unit
;
4743 eassert (MINI_WINDOW_P (w
));
4745 height
= pixelwise
? w
->pixel_height
: w
->total_lines
;
4746 unit
= pixelwise
? FRAME_LINE_HEIGHT (f
) : 1;
4749 root
= FRAME_ROOT_WINDOW (f
);
4751 delta
= call3 (Qwindow_resize_root_window_vertically
,
4752 root
, make_number (height
- unit
),
4753 pixelwise
? Qt
: Qnil
);
4754 if (INTEGERP (delta
) && window_resize_check (r
, 0))
4757 window_resize_apply (r
, 0);
4759 /* Shrink the mini-window. */
4760 w
->top_line
= r
->top_line
+ r
->total_lines
;
4762 w
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4763 w
->pixel_height
= FRAME_LINE_HEIGHT (f
);
4764 /* Enforce full redisplay of the frame. */
4765 /* FIXME: Shouldn't window--resize-root-window-vertically do it? */
4767 adjust_frame_glyphs (f
);
4770 /* If the above failed for whatever strange reason we must make a
4771 one window frame here. The same routine will be needed when
4772 shrinking the frame (and probably when making the initial
4773 *scratch* window). For the moment leave things as they are. */
4777 DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal
, Sresize_mini_window_internal
, 1, 1, 0,
4778 doc
: /* Resize minibuffer window WINDOW. */)
4779 (Lisp_Object window
)
4781 struct window
*w
= XWINDOW (window
);
4786 CHECK_WINDOW (window
);
4787 f
= XFRAME (w
->frame
);
4789 if (!EQ (FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
)), window
))
4790 error ("Not a valid minibuffer window");
4791 else if (FRAME_MINIBUF_ONLY_P (f
))
4792 error ("Cannot resize a minibuffer-only frame");
4794 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4795 height
= r
->pixel_height
+ w
->pixel_height
;
4796 if (window_resize_check (r
, 0)
4797 && XINT (w
->new_pixel
) > 0
4798 && height
== XINT (r
->new_pixel
) + XINT (w
->new_pixel
))
4801 window_resize_apply (r
, 0);
4803 w
->pixel_height
= XFASTINT (w
->new_pixel
);
4804 w
->total_lines
= w
->pixel_height
/ FRAME_LINE_HEIGHT (f
);
4805 w
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4806 w
->top_line
= r
->top_line
+ r
->total_lines
;
4809 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4810 adjust_frame_glyphs (f
);
4815 error ("Failed to resize minibuffer window");
4818 /* Mark window cursors off for all windows in the window tree rooted
4819 at W by setting their phys_cursor_on_p flag to zero. Called from
4820 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4821 the frame are cleared. */
4824 mark_window_cursors_off (struct window
*w
)
4828 if (WINDOWP (w
->contents
))
4829 mark_window_cursors_off (XWINDOW (w
->contents
));
4831 w
->phys_cursor_on_p
= 0;
4833 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4838 /* Return number of lines of text (not counting mode lines) in W. */
4841 window_internal_height (struct window
*w
)
4843 int ht
= w
->total_lines
;
4845 if (!MINI_WINDOW_P (w
))
4847 if (!NILP (w
->parent
)
4848 || WINDOWP (w
->contents
)
4851 || WINDOW_WANTS_MODELINE_P (w
))
4854 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4862 /************************************************************************
4864 ***********************************************************************/
4866 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4867 N screen-fulls, which is defined as the height of the window minus
4868 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4869 instead. Negative values of N mean scroll down. NOERROR non-zero
4870 means don't signal an error if we try to move over BEGV or ZV,
4874 window_scroll (Lisp_Object window
, EMACS_INT n
, bool whole
, int noerror
)
4876 ptrdiff_t count
= SPECPDL_INDEX ();
4879 n
= clip_to_bounds (INT_MIN
, n
, INT_MAX
);
4881 wset_redisplay (XWINDOW (window
));
4883 if (whole
&& Vfast_but_imprecise_scrolling
)
4884 specbind (Qfontification_functions
, Qnil
);
4886 /* If we must, use the pixel-based version which is much slower than
4887 the line-based one but can handle varying line heights. */
4888 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4889 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4891 window_scroll_line_based (window
, n
, whole
, noerror
);
4893 unbind_to (count
, Qnil
);
4896 XWINDOW (window
)->window_end_valid
= 0;
4901 /* Implementation of window_scroll that works based on pixel line
4902 heights. See the comment of window_scroll for parameter
4906 window_scroll_pixel_based (Lisp_Object window
, int n
, bool whole
, int noerror
)
4909 struct window
*w
= XWINDOW (window
);
4910 struct text_pos start
;
4911 int this_scroll_margin
;
4912 /* True if we fiddled the window vscroll field without really scrolling. */
4914 int x
, y
, rtop
, rbot
, rowh
, vpos
;
4915 void *itdata
= NULL
;
4916 int window_total_lines
;
4917 int frame_line_height
= default_line_pixel_height (w
);
4918 bool adjust_old_pointm
= !NILP (Fequal (Fwindow_point (window
),
4919 Fwindow_old_point (window
)));
4921 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4922 /* Scrolling a minibuffer window via scroll bar when the echo area
4923 shows long text sometimes resets the minibuffer contents behind
4925 if (CHARPOS (start
) > ZV
)
4926 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4928 /* If PT is not visible in WINDOW, move back one half of
4929 the screen. Allow PT to be partially visible, otherwise
4930 something like (scroll-down 1) with PT in the line before
4931 the partially visible one would recenter. */
4933 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
4935 itdata
= bidi_shelve_cache ();
4936 /* Move backward half the height of the window. Performance note:
4937 vmotion used here is about 10% faster, but would give wrong
4938 results for variable height lines. */
4939 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4940 it
.current_y
= it
.last_visible_y
;
4941 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4943 /* The function move_iterator_vertically may move over more than
4944 the specified y-distance. If it->w is small, e.g. a
4945 mini-buffer window, we may end up in front of the window's
4946 display area. Start displaying at the start of the line
4947 containing PT in this case. */
4948 if (it
.current_y
<= 0)
4950 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4951 move_it_vertically_backward (&it
, 0);
4955 start
= it
.current
.pos
;
4956 bidi_unshelve_cache (itdata
, 0);
4958 else if (auto_window_vscroll_p
)
4960 if (rtop
|| rbot
) /* Partially visible. */
4963 int dy
= frame_line_height
;
4964 /* In the below we divide the window box height by the
4965 frame's line height to make the result predictable when
4966 the window box is not an integral multiple of the line
4967 height. This is important to ensure we get back to the
4968 same position when scrolling up, then down. */
4970 dy
= max ((window_box_height (w
) / dy
4971 - next_screen_context_lines
) * dy
,
4977 /* Only vscroll backwards if already vscrolled forwards. */
4978 if (w
->vscroll
< 0 && rtop
> 0)
4980 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
4981 Fset_window_vscroll (window
, make_number (px
), Qt
);
4987 /* Do vscroll if already vscrolled or only display line. */
4988 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
4990 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
4991 Fset_window_vscroll (window
, make_number (px
), Qt
);
4995 /* Maybe modify window start instead of scrolling. */
4996 if (rbot
> 0 || w
->vscroll
< 0)
5000 Fset_window_vscroll (window
, make_number (0), Qt
);
5001 /* If there are other text lines above the current row,
5002 move window start to current row. Else to next row. */
5004 spos
= XINT (Fline_beginning_position (Qnil
));
5006 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
5007 set_marker_restricted (w
->start
, make_number (spos
),
5009 w
->start_at_line_beg
= 1;
5010 w
->update_mode_line
= 1;
5011 /* Set force_start so that redisplay_window will run the
5012 window-scroll-functions. */
5018 /* Cancel previous vscroll. */
5019 Fset_window_vscroll (window
, make_number (0), Qt
);
5022 itdata
= bidi_shelve_cache ();
5023 /* If scroll_preserve_screen_position is non-nil, we try to set
5024 point in the same window line as it is now, so get that line. */
5025 if (!NILP (Vscroll_preserve_screen_position
))
5027 /* We preserve the goal pixel coordinate across consecutive
5028 calls to scroll-up, scroll-down and other commands that
5029 have the `scroll-command' property. This avoids the
5030 possibility of point becoming "stuck" on a tall line when
5031 scrolling by one line. */
5032 if (window_scroll_pixel_based_preserve_y
< 0
5033 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
5034 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
5036 start_display (&it
, w
, start
);
5037 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5038 window_scroll_pixel_based_preserve_y
= it
.current_y
;
5039 window_scroll_pixel_based_preserve_x
= it
.current_x
;
5043 window_scroll_pixel_based_preserve_y
5044 = window_scroll_pixel_based_preserve_x
= -1;
5046 /* Move iterator it from start the specified distance forward or
5047 backward. The result is the new window start. */
5048 start_display (&it
, w
, start
);
5051 ptrdiff_t start_pos
= IT_CHARPOS (it
);
5052 int dy
= frame_line_height
;
5053 /* In the below we divide the window box height by the frame's
5054 line height to make the result predictable when the window
5055 box is not an integral multiple of the line height. This is
5056 important to ensure we get back to the same position when
5057 scrolling up, then down. */
5058 dy
= max ((window_box_height (w
) / dy
- next_screen_context_lines
) * dy
,
5061 /* Note that move_it_vertically always moves the iterator to the
5062 start of a line. So, if the last line doesn't have a newline,
5063 we would end up at the start of the line ending at ZV. */
5066 move_it_vertically_backward (&it
, -dy
);
5067 /* Ensure we actually do move, e.g. in case we are currently
5068 looking at an image that is taller that the window height. */
5069 while (start_pos
== IT_CHARPOS (it
)
5070 && start_pos
> BEGV
)
5071 move_it_by_lines (&it
, -1);
5075 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
5076 MOVE_TO_POS
| MOVE_TO_Y
);
5077 /* Ensure we actually do move, e.g. in case we are currently
5078 looking at an image that is taller that the window height. */
5079 while (start_pos
== IT_CHARPOS (it
)
5081 move_it_by_lines (&it
, 1);
5085 move_it_by_lines (&it
, n
);
5087 /* We failed if we find ZV is already on the screen (scrolling up,
5088 means there's nothing past the end), or if we can't start any
5089 earlier (scrolling down, means there's nothing past the top). */
5090 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
5091 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
5093 if (IT_CHARPOS (it
) == ZV
)
5095 if (it
.current_y
< it
.last_visible_y
5096 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
5097 > it
.last_visible_y
))
5099 /* The last line was only partially visible, make it fully
5101 w
->vscroll
= (it
.last_visible_y
5102 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
5103 adjust_frame_glyphs (it
.f
);
5107 bidi_unshelve_cache (itdata
, 0);
5110 else if (n
< 0) /* could happen with empty buffers */
5111 xsignal0 (Qbeginning_of_buffer
);
5113 xsignal0 (Qend_of_buffer
);
5118 if (w
->vscroll
!= 0)
5119 /* The first line was only partially visible, make it fully
5124 bidi_unshelve_cache (itdata
, 0);
5128 xsignal0 (Qbeginning_of_buffer
);
5132 /* If control gets here, then we vscrolled. */
5134 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
5136 /* Don't try to change the window start below. */
5142 ptrdiff_t pos
= IT_CHARPOS (it
);
5145 /* If in the middle of a multi-glyph character move forward to
5146 the next character. */
5147 if (in_display_vector_p (&it
))
5150 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
5153 /* Set the window start, and set up the window for redisplay. */
5154 set_marker_restricted_both (w
->start
, w
->contents
, IT_CHARPOS (it
),
5156 bytepos
= marker_byte_position (w
->start
);
5157 w
->start_at_line_beg
= (pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n');
5158 w
->update_mode_line
= 1;
5159 /* Set force_start so that redisplay_window will run the
5160 window-scroll-functions. */
5164 /* The rest of this function uses current_y in a nonstandard way,
5165 not including the height of the header line if any. */
5166 it
.current_y
= it
.vpos
= 0;
5168 /* Move PT out of scroll margins.
5169 This code wants current_y to be zero at the window start position
5170 even if there is a header line. */
5172 = w
->total_lines
* WINDOW_FRAME_LINE_HEIGHT (w
) / frame_line_height
;
5173 this_scroll_margin
= max (0, scroll_margin
);
5175 = min (this_scroll_margin
, window_total_lines
/ 4);
5176 this_scroll_margin
*= frame_line_height
;
5180 /* We moved the window start towards ZV, so PT may be now
5181 in the scroll margin at the top. */
5182 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5183 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
5184 && (NILP (Vscroll_preserve_screen_position
)
5185 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5186 /* We found PT at a legitimate height. Leave it alone. */
5188 else if (window_scroll_pixel_based_preserve_y
>= 0)
5190 /* If we have a header line, take account of it.
5191 This is necessary because we set it.current_y to 0, above. */
5192 move_it_to (&it
, -1,
5193 window_scroll_pixel_based_preserve_x
,
5194 window_scroll_pixel_based_preserve_y
5195 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
5196 -1, MOVE_TO_Y
| MOVE_TO_X
);
5197 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5201 while (it
.current_y
< this_scroll_margin
)
5203 int prev
= it
.current_y
;
5204 move_it_by_lines (&it
, 1);
5205 if (prev
== it
.current_y
)
5208 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5213 ptrdiff_t charpos
, bytepos
;
5216 /* Save our position, for the
5217 window_scroll_pixel_based_preserve_y case. */
5218 charpos
= IT_CHARPOS (it
);
5219 bytepos
= IT_BYTEPOS (it
);
5221 /* We moved the window start towards BEGV, so PT may be now
5222 in the scroll margin at the bottom. */
5223 move_it_to (&it
, PT
, -1,
5224 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
5225 - this_scroll_margin
- 1),
5227 MOVE_TO_POS
| MOVE_TO_Y
);
5229 /* Save our position, in case it's correct. */
5230 charpos
= IT_CHARPOS (it
);
5231 bytepos
= IT_BYTEPOS (it
);
5233 /* If PT is in the screen line at the last fully visible line,
5234 move_it_to will stop at X = 0 in that line, because the
5235 required Y coordinate is reached there. See if we can get to
5236 PT without descending lower in Y, and if we can, it means we
5237 reached PT before the scroll margin. */
5244 it_data
= bidi_shelve_cache ();
5245 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5246 if (IT_CHARPOS (it
) == PT
&& it
.current_y
== it2
.current_y
)
5248 charpos
= IT_CHARPOS (it
);
5249 bytepos
= IT_BYTEPOS (it
);
5250 bidi_unshelve_cache (it_data
, 1);
5255 bidi_unshelve_cache (it_data
, 0);
5259 /* See if point is on a partially visible line at the end. */
5260 if (it
.what
== IT_EOB
)
5261 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
5264 move_it_by_lines (&it
, 1);
5265 partial_p
= it
.current_y
> it
.last_visible_y
;
5268 if (charpos
== PT
&& !partial_p
5269 && (NILP (Vscroll_preserve_screen_position
)
5270 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5271 /* We found PT before we found the display margin, so PT is ok. */
5273 else if (window_scroll_pixel_based_preserve_y
>= 0)
5275 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5276 start_display (&it
, w
, start
);
5277 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
5278 here because we called start_display again and did not
5279 alter it.current_y this time. */
5280 move_it_to (&it
, -1, window_scroll_pixel_based_preserve_x
,
5281 window_scroll_pixel_based_preserve_y
, -1,
5282 MOVE_TO_Y
| MOVE_TO_X
);
5283 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5288 /* The last line was only partially visible, so back up two
5289 lines to make sure we're on a fully visible line. */
5291 move_it_by_lines (&it
, -2);
5292 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5295 /* No, the position we saved is OK, so use it. */
5296 SET_PT_BOTH (charpos
, bytepos
);
5299 bidi_unshelve_cache (itdata
, 0);
5301 if (adjust_old_pointm
)
5302 Fset_marker (w
->old_pointm
,
5303 ((w
== XWINDOW (selected_window
))
5304 ? make_number (BUF_PT (XBUFFER (w
->contents
)))
5305 : Fmarker_position (w
->pointm
)),
5310 /* Implementation of window_scroll that works based on screen lines.
5311 See the comment of window_scroll for parameter descriptions. */
5314 window_scroll_line_based (Lisp_Object window
, int n
, bool whole
, int noerror
)
5316 register struct window
*w
= XWINDOW (window
);
5317 /* Fvertical_motion enters redisplay, which can trigger
5318 fontification, which in turn can modify buffer text (e.g., if the
5319 fontification functions replace escape sequences with faces, as
5320 in `grep-mode-font-lock-keywords'). So we use a marker to record
5321 the old point position, to prevent crashes in SET_PT_BOTH. */
5322 Lisp_Object opoint_marker
= Fpoint_marker ();
5323 register ptrdiff_t pos
, pos_byte
;
5324 register int ht
= window_internal_height (w
);
5325 register Lisp_Object tem
;
5328 ptrdiff_t startpos
= marker_position (w
->start
);
5329 ptrdiff_t startbyte
= marker_byte_position (w
->start
);
5330 Lisp_Object original_pos
= Qnil
;
5331 bool adjust_old_pointm
= !NILP (Fequal (Fwindow_point (window
),
5332 Fwindow_old_point (window
)));
5334 /* If scrolling screen-fulls, compute the number of lines to
5335 scroll from the window's height. */
5337 n
*= max (1, ht
- next_screen_context_lines
);
5339 if (!NILP (Vscroll_preserve_screen_position
))
5341 if (window_scroll_preserve_vpos
<= 0
5342 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
5343 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
5345 struct position posit
5346 = *compute_motion (startpos
, startbyte
, 0, 0, 0,
5347 PT
, ht
, 0, -1, w
->hscroll
, 0, w
);
5349 window_scroll_preserve_vpos
= posit
.vpos
;
5350 window_scroll_preserve_hpos
= posit
.hpos
+ w
->hscroll
;
5353 original_pos
= Fcons (make_number (window_scroll_preserve_hpos
),
5354 make_number (window_scroll_preserve_vpos
));
5357 XSETFASTINT (tem
, PT
);
5358 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
5362 Fvertical_motion (make_number (- (ht
/ 2)), window
);
5364 startbyte
= PT_BYTE
;
5367 SET_PT_BOTH (startpos
, startbyte
);
5368 lose
= n
< 0 && PT
== BEGV
;
5369 Fvertical_motion (make_number (n
), window
);
5373 SET_PT_BOTH (marker_position (opoint_marker
),
5374 marker_byte_position (opoint_marker
));
5381 xsignal0 (Qbeginning_of_buffer
);
5386 /* Don't use a scroll margin that is negative or too large. */
5387 int this_scroll_margin
=
5388 max (0, min (scroll_margin
, w
->total_lines
/ 4));
5390 set_marker_restricted_both (w
->start
, w
->contents
, pos
, pos_byte
);
5391 w
->start_at_line_beg
= !NILP (bolp
);
5392 w
->update_mode_line
= 1;
5393 /* Set force_start so that redisplay_window will run
5394 the window-scroll-functions. */
5397 if (!NILP (Vscroll_preserve_screen_position
)
5398 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
5400 SET_PT_BOTH (pos
, pos_byte
);
5401 Fvertical_motion (original_pos
, window
);
5403 /* If we scrolled forward, put point enough lines down
5404 that it is outside the scroll margin. */
5409 if (this_scroll_margin
> 0)
5411 SET_PT_BOTH (pos
, pos_byte
);
5412 Fvertical_motion (make_number (this_scroll_margin
), window
);
5418 if (top_margin
<= marker_position (opoint_marker
))
5419 SET_PT_BOTH (marker_position (opoint_marker
),
5420 marker_byte_position (opoint_marker
));
5421 else if (!NILP (Vscroll_preserve_screen_position
))
5423 SET_PT_BOTH (pos
, pos_byte
);
5424 Fvertical_motion (original_pos
, window
);
5427 SET_PT (top_margin
);
5433 /* If we scrolled backward, put point near the end of the window
5434 but not within the scroll margin. */
5435 SET_PT_BOTH (pos
, pos_byte
);
5436 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
5437 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
5440 bottom_margin
= PT
+ 1;
5442 if (bottom_margin
> marker_position (opoint_marker
))
5443 SET_PT_BOTH (marker_position (opoint_marker
),
5444 marker_byte_position (opoint_marker
));
5447 if (!NILP (Vscroll_preserve_screen_position
))
5449 SET_PT_BOTH (pos
, pos_byte
);
5450 Fvertical_motion (original_pos
, window
);
5453 Fvertical_motion (make_number (-1), window
);
5462 xsignal0 (Qend_of_buffer
);
5465 if (adjust_old_pointm
)
5466 Fset_marker (w
->old_pointm
,
5467 ((w
== XWINDOW (selected_window
))
5468 ? make_number (BUF_PT (XBUFFER (w
->contents
)))
5469 : Fmarker_position (w
->pointm
)),
5474 /* Scroll selected_window up or down. If N is nil, scroll a
5475 screen-full which is defined as the height of the window minus
5476 next_screen_context_lines. If N is the symbol `-', scroll.
5477 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
5478 up. This is the guts of Fscroll_up and Fscroll_down. */
5481 scroll_command (Lisp_Object n
, int direction
)
5483 ptrdiff_t count
= SPECPDL_INDEX ();
5485 eassert (eabs (direction
) == 1);
5487 /* If selected window's buffer isn't current, make it current for
5488 the moment. But don't screw up if window_scroll gets an error. */
5489 if (XBUFFER (XWINDOW (selected_window
)->contents
) != current_buffer
)
5491 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5492 Fset_buffer (XWINDOW (selected_window
)->contents
);
5496 window_scroll (selected_window
, direction
, 1, 0);
5497 else if (EQ (n
, Qminus
))
5498 window_scroll (selected_window
, -direction
, 1, 0);
5501 n
= Fprefix_numeric_value (n
);
5502 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
5505 unbind_to (count
, Qnil
);
5508 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "^P",
5509 doc
: /* Scroll text of selected window upward ARG lines.
5510 If ARG is omitted or nil, scroll upward by a near full screen.
5511 A near full screen is `next-screen-context-lines' less than a full screen.
5512 Negative ARG means scroll downward.
5513 If ARG is the atom `-', scroll downward by nearly full screen.
5514 When calling from a program, supply as argument a number, nil, or `-'. */)
5517 scroll_command (arg
, 1);
5521 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "^P",
5522 doc
: /* Scroll text of selected window down ARG lines.
5523 If ARG is omitted or nil, scroll down by a near full screen.
5524 A near full screen is `next-screen-context-lines' less than a full screen.
5525 Negative ARG means scroll upward.
5526 If ARG is the atom `-', scroll upward by nearly full screen.
5527 When calling from a program, supply as argument a number, nil, or `-'. */)
5530 scroll_command (arg
, -1);
5534 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
5535 doc
: /* Return the other window for \"other window scroll\" commands.
5536 If `other-window-scroll-buffer' is non-nil, a window
5537 showing that buffer is used.
5538 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5539 specifies the window. This takes precedence over
5540 `other-window-scroll-buffer'. */)
5545 if (MINI_WINDOW_P (XWINDOW (selected_window
))
5546 && !NILP (Vminibuf_scroll_window
))
5547 window
= Vminibuf_scroll_window
;
5548 /* If buffer is specified and live, scroll that buffer. */
5549 else if (!NILP (Vother_window_scroll_buffer
)
5550 && BUFFERP (Vother_window_scroll_buffer
)
5551 && BUFFER_LIVE_P (XBUFFER (Vother_window_scroll_buffer
)))
5553 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
5555 window
= display_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
5559 /* Nothing specified; look for a neighboring window on the same
5561 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
5563 if (EQ (window
, selected_window
))
5564 /* That didn't get us anywhere; look for a window on another
5567 window
= Fnext_window (window
, Qnil
, Qt
);
5568 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
5569 && ! EQ (window
, selected_window
));
5572 CHECK_LIVE_WINDOW (window
);
5574 if (EQ (window
, selected_window
))
5575 error ("There is no other window");
5580 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
5581 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5582 A near full screen is `next-screen-context-lines' less than a full screen.
5583 The next window is the one below the current one; or the one at the top
5584 if the current one is at the bottom. Negative ARG means scroll downward.
5585 If ARG is the atom `-', scroll downward by nearly full screen.
5586 When calling from a program, supply as argument a number, nil, or `-'.
5588 If `other-window-scroll-buffer' is non-nil, scroll the window
5589 showing that buffer, popping the buffer up if necessary.
5590 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5591 specifies the window to scroll. This takes precedence over
5592 `other-window-scroll-buffer'. */)
5597 ptrdiff_t count
= SPECPDL_INDEX ();
5599 window
= Fother_window_for_scrolling ();
5600 w
= XWINDOW (window
);
5602 /* Don't screw up if window_scroll gets an error. */
5603 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5605 Fset_buffer (w
->contents
);
5606 SET_PT_BOTH (marker_position (w
->pointm
), marker_byte_position (w
->pointm
));
5607 SET_PT_BOTH (marker_position (w
->old_pointm
), marker_byte_position (w
->old_pointm
));
5610 window_scroll (window
, 1, 1, 1);
5611 else if (EQ (arg
, Qminus
))
5612 window_scroll (window
, -1, 1, 1);
5618 window_scroll (window
, XINT (arg
), 0, 1);
5621 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5622 set_marker_both (w
->old_pointm
, Qnil
, PT
, PT_BYTE
);
5623 unbind_to (count
, Qnil
);
5628 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "^P\np",
5629 doc
: /* Scroll selected window display ARG columns left.
5630 Default for ARG is window width minus 2.
5631 Value is the total amount of leftward horizontal scrolling in
5632 effect after the change.
5633 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5634 lower bound for automatic scrolling, i.e. automatic scrolling
5635 will not scroll a window to a column less than the value returned
5636 by this function. This happens in an interactive call. */)
5637 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5639 struct window
*w
= XWINDOW (selected_window
);
5640 EMACS_INT requested_arg
= (NILP (arg
)
5641 ? window_body_width (w
, 0) - 2
5642 : XINT (Fprefix_numeric_value (arg
)));
5643 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
+ requested_arg
);
5645 if (!NILP (set_minimum
))
5646 w
->min_hscroll
= w
->hscroll
;
5648 w
->suspend_auto_hscroll
= 1;
5653 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "^P\np",
5654 doc
: /* Scroll selected window display ARG columns right.
5655 Default for ARG is window width minus 2.
5656 Value is the total amount of leftward horizontal scrolling in
5657 effect after the change.
5658 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5659 lower bound for automatic scrolling, i.e. automatic scrolling
5660 will not scroll a window to a column less than the value returned
5661 by this function. This happens in an interactive call. */)
5662 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5664 struct window
*w
= XWINDOW (selected_window
);
5665 EMACS_INT requested_arg
= (NILP (arg
)
5666 ? window_body_width (w
, 0) - 2
5667 : XINT (Fprefix_numeric_value (arg
)));
5668 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
- requested_arg
);
5670 if (!NILP (set_minimum
))
5671 w
->min_hscroll
= w
->hscroll
;
5673 w
->suspend_auto_hscroll
= 1;
5678 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5679 doc
: /* Return the window which was selected when entering the minibuffer.
5680 Returns nil, if selected window is not a minibuffer window. */)
5683 if (minibuf_level
> 0
5684 && MINI_WINDOW_P (XWINDOW (selected_window
))
5685 && WINDOW_LIVE_P (minibuf_selected_window
))
5686 return minibuf_selected_window
;
5691 /* Value is the number of lines actually displayed in window W,
5692 as opposed to its height. */
5695 displayed_window_lines (struct window
*w
)
5698 struct text_pos start
;
5699 int height
= window_box_height (w
);
5700 struct buffer
*old_buffer
;
5702 void *itdata
= NULL
;
5704 if (XBUFFER (w
->contents
) != current_buffer
)
5706 old_buffer
= current_buffer
;
5707 set_buffer_internal (XBUFFER (w
->contents
));
5712 /* In case W->start is out of the accessible range, do something
5713 reasonable. This happens in Info mode when Info-scroll-down
5714 calls (recenter -1) while W->start is 1. */
5715 CLIP_TEXT_POS_FROM_MARKER (start
, w
->start
);
5717 itdata
= bidi_shelve_cache ();
5718 start_display (&it
, w
, start
);
5719 move_it_vertically (&it
, height
);
5720 bottom_y
= line_bottom_y (&it
);
5721 bidi_unshelve_cache (itdata
, 0);
5723 /* rms: On a non-window display,
5724 the value of it.vpos at the bottom of the screen
5725 seems to be 1 larger than window_box_height (w).
5726 This kludge fixes a bug whereby (move-to-window-line -1)
5727 when ZV is on the last screen line
5728 moves to the previous screen line instead of the last one. */
5729 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5732 /* Add in empty lines at the bottom of the window. */
5733 if (bottom_y
< height
)
5735 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5736 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5740 set_buffer_internal (old_buffer
);
5746 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5747 doc
: /* Center point in selected window and maybe redisplay frame.
5748 With a numeric prefix argument ARG, recenter putting point on screen line ARG
5749 relative to the selected window. If ARG is negative, it counts up from the
5750 bottom of the window. (ARG should be less than the height of the window.)
5752 If ARG is omitted or nil, then recenter with point on the middle line of
5753 the selected window; if the variable `recenter-redisplay' is non-nil,
5754 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5755 is set to `grow-only', this resets the tool-bar's height to the minimum
5756 height needed); if `recenter-redisplay' has the special value `tty',
5757 then only tty frames are redrawn.
5759 Just C-u as prefix means put point in the center of the window
5760 and redisplay normally--don't erase and redraw the frame. */)
5761 (register Lisp_Object arg
)
5763 struct window
*w
= XWINDOW (selected_window
);
5764 struct buffer
*buf
= XBUFFER (w
->contents
);
5766 ptrdiff_t charpos
, bytepos
;
5767 EMACS_INT iarg
IF_LINT (= 0);
5768 int this_scroll_margin
;
5770 if (buf
!= current_buffer
)
5771 error ("`recenter'ing a window that does not display current-buffer.");
5773 /* If redisplay is suppressed due to an error, try again. */
5774 buf
->display_error_modiff
= 0;
5778 if (!NILP (Vrecenter_redisplay
)
5779 && (!EQ (Vrecenter_redisplay
, Qtty
)
5780 || !NILP (Ftty_type (selected_frame
))))
5784 /* Invalidate pixel data calculated for all compositions. */
5785 for (i
= 0; i
< n_compositions
; i
++)
5786 composition_table
[i
]->font
= NULL
;
5787 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
5788 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5790 Fredraw_frame (WINDOW_FRAME (w
));
5791 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5796 else if (CONSP (arg
)) /* Just C-u. */
5800 arg
= Fprefix_numeric_value (arg
);
5805 /* Do this after making BUF current
5806 in case scroll_margin is buffer-local. */
5808 = max (0, min (scroll_margin
, w
->total_lines
/ 4));
5810 /* Handle centering on a graphical frame specially. Such frames can
5811 have variable-height lines and centering point on the basis of
5812 line counts would lead to strange effects. */
5813 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5819 void *itdata
= bidi_shelve_cache ();
5821 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5822 start_display (&it
, w
, pt
);
5823 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5824 charpos
= IT_CHARPOS (it
);
5825 bytepos
= IT_BYTEPOS (it
);
5826 bidi_unshelve_cache (itdata
, 0);
5832 ptrdiff_t nlines
= min (PTRDIFF_MAX
, -iarg
);
5833 int extra_line_spacing
;
5834 int h
= window_box_height (w
);
5835 void *itdata
= bidi_shelve_cache ();
5837 iarg
= - max (-iarg
, this_scroll_margin
);
5839 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5840 start_display (&it
, w
, pt
);
5842 /* Be sure we have the exact height of the full line containing PT. */
5843 move_it_by_lines (&it
, 0);
5845 /* The amount of pixels we have to move back is the window
5846 height minus what's displayed in the line containing PT,
5847 and the lines below. */
5850 move_it_by_lines (&it
, nlines
);
5852 if (it
.vpos
== nlines
)
5856 /* Last line has no newline. */
5857 h
-= line_bottom_y (&it
);
5861 /* Don't reserve space for extra line spacing of last line. */
5862 extra_line_spacing
= it
.max_extra_line_spacing
;
5864 /* If we can't move down NLINES lines because we hit
5865 the end of the buffer, count in some empty lines. */
5866 if (it
.vpos
< nlines
)
5869 extra_line_spacing
= it
.extra_line_spacing
;
5870 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5874 bidi_unshelve_cache (itdata
, 0);
5878 /* Now find the new top line (starting position) of the window. */
5879 start_display (&it
, w
, pt
);
5881 move_it_vertically_backward (&it
, h
);
5883 /* If extra line spacing is present, we may move too far
5884 back. This causes the last line to be only partially
5885 visible (which triggers redisplay to recenter that line
5886 in the middle), so move forward.
5887 But ignore extra line spacing on last line, as it is not
5888 considered to be part of the visible height of the line.
5890 h
+= extra_line_spacing
;
5891 while (-it
.current_y
> h
)
5892 move_it_by_lines (&it
, 1);
5894 charpos
= IT_CHARPOS (it
);
5895 bytepos
= IT_BYTEPOS (it
);
5897 bidi_unshelve_cache (itdata
, 0);
5901 struct position pos
;
5903 iarg
= max (iarg
, this_scroll_margin
);
5905 pos
= *vmotion (PT
, PT_BYTE
, -iarg
, w
);
5906 charpos
= pos
.bufpos
;
5907 bytepos
= pos
.bytepos
;
5912 struct position pos
;
5913 int ht
= window_internal_height (w
);
5920 /* Don't let it get into the margin at either top or bottom. */
5921 iarg
= clip_to_bounds (this_scroll_margin
, iarg
,
5922 ht
- this_scroll_margin
- 1);
5924 pos
= *vmotion (PT
, PT_BYTE
, - iarg
, w
);
5925 charpos
= pos
.bufpos
;
5926 bytepos
= pos
.bytepos
;
5929 /* Set the new window start. */
5930 set_marker_both (w
->start
, w
->contents
, charpos
, bytepos
);
5931 w
->window_end_valid
= 0;
5933 w
->optional_new_start
= 1;
5935 w
->start_at_line_beg
= (bytepos
== BEGV_BYTE
5936 || FETCH_BYTE (bytepos
- 1) == '\n');
5943 DEFUN ("window-text-width", Fwindow_text_width
, Swindow_text_width
,
5945 doc
: /* Return the width in columns of the text display area of WINDOW.
5946 WINDOW must be a live window and defaults to the selected one.
5948 The returned width does not include dividers, scrollbars, margins,
5949 fringes, nor any partial-width columns at the right of the text
5952 Optional argument PIXELWISE non-nil, means to return the width in
5954 (Lisp_Object window
, Lisp_Object pixelwise
)
5956 struct window
*w
= decode_live_window (window
);
5958 if (NILP (pixelwise
))
5959 return make_number (window_box_width (w
, TEXT_AREA
)
5960 / FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
)));
5962 return make_number (window_box_width (w
, TEXT_AREA
));
5965 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5967 doc
: /* Return the height in lines of the text display area of WINDOW.
5968 WINDOW must be a live window and defaults to the selected one.
5970 The returned height does not include dividers, the mode line, any header
5971 line, nor any partial-height lines at the bottom of the text area.
5973 Optional argument PIXELWISE non-nil, means to return the height in
5975 (Lisp_Object window
, Lisp_Object pixelwise
)
5977 struct window
*w
= decode_live_window (window
);
5979 if (NILP (pixelwise
))
5980 return make_number (window_box_height (w
)
5981 / FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
)));
5983 return make_number (window_box_height (w
));
5986 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5988 doc
: /* Position point relative to window.
5989 ARG nil means position point at center of window.
5990 Else, ARG specifies vertical position within the window;
5991 zero means top of window, negative means relative to bottom of window. */)
5994 struct window
*w
= XWINDOW (selected_window
);
5998 int this_scroll_margin
;
6001 if (!(BUFFERP (w
->contents
) && XBUFFER (w
->contents
) == current_buffer
))
6002 /* This test is needed to make sure PT/PT_BYTE make sense in w->contents
6003 when passed below to set_marker_both. */
6004 error ("move-to-window-line called from unrelated buffer");
6006 window
= selected_window
;
6007 start
= marker_position (w
->start
);
6008 if (start
< BEGV
|| start
> ZV
)
6010 int height
= window_internal_height (w
);
6011 Fvertical_motion (make_number (- (height
/ 2)), window
);
6012 set_marker_both (w
->start
, w
->contents
, PT
, PT_BYTE
);
6013 w
->start_at_line_beg
= !NILP (Fbolp ());
6017 Fgoto_char (w
->start
);
6019 lines
= displayed_window_lines (w
);
6022 this_scroll_margin
= max (0, min (scroll_margin
, lines
/ 4));
6026 XSETFASTINT (arg
, lines
/ 2);
6029 EMACS_INT iarg
= XINT (Fprefix_numeric_value (arg
));
6032 iarg
= iarg
+ lines
;
6034 #if 0 /* This code would prevent move-to-window-line from moving point
6035 to a place inside the scroll margins (which would cause the
6036 next redisplay to scroll). I wrote this code, but then concluded
6037 it is probably better not to install it. However, it is here
6038 inside #if 0 so as not to lose it. -- rms. */
6040 /* Don't let it get into the margin at either top or bottom. */
6041 iarg
= max (iarg
, this_scroll_margin
);
6042 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
6045 arg
= make_number (iarg
);
6048 /* Skip past a partially visible first line. */
6050 XSETINT (arg
, XINT (arg
) + 1);
6052 return Fvertical_motion (arg
, window
);
6057 /***********************************************************************
6058 Window Configuration
6059 ***********************************************************************/
6061 struct save_window_data
6063 struct vectorlike_header header
;
6064 Lisp_Object selected_frame
;
6065 Lisp_Object current_window
;
6066 Lisp_Object current_buffer
;
6067 Lisp_Object minibuf_scroll_window
;
6068 Lisp_Object minibuf_selected_window
;
6069 Lisp_Object root_window
;
6070 Lisp_Object focus_frame
;
6071 /* A vector, each of whose elements is a struct saved_window
6073 Lisp_Object saved_windows
;
6075 /* All fields above are traced by the GC.
6076 From `frame-cols' down, the fields are ignored by the GC. */
6077 /* We should be able to do without the following two. */
6078 int frame_cols
, frame_lines
;
6079 /* These two should get eventually replaced by their pixel
6081 int frame_menu_bar_lines
, frame_tool_bar_lines
;
6082 int frame_text_width
, frame_text_height
;
6083 /* These are currently unused. We need them as soon as we convert
6085 int frame_menu_bar_height
, frame_tool_bar_height
;
6088 /* This is saved as a Lisp_Vector. */
6091 struct vectorlike_header header
;
6093 Lisp_Object window
, buffer
, start
, pointm
, old_pointm
;
6094 Lisp_Object pixel_left
, pixel_top
, pixel_height
, pixel_width
;
6095 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
6096 Lisp_Object normal_cols
, normal_lines
;
6097 Lisp_Object hscroll
, min_hscroll
, hscroll_whole
, suspend_auto_hscroll
;
6098 Lisp_Object parent
, prev
;
6099 Lisp_Object start_at_line_beg
;
6100 Lisp_Object display_table
;
6101 Lisp_Object left_margin_cols
, right_margin_cols
;
6102 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
6103 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
, dedicated
;
6104 Lisp_Object scroll_bar_height
, horizontal_scroll_bar_type
;
6105 Lisp_Object combination_limit
, window_parameters
;
6108 #define SAVED_WINDOW_N(swv,n) \
6109 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
6111 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
6112 doc
: /* Return t if OBJECT is a window-configuration object. */)
6113 (Lisp_Object object
)
6115 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
6118 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
6119 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
6120 (Lisp_Object config
)
6122 register struct save_window_data
*data
;
6123 struct Lisp_Vector
*saved_windows
;
6125 CHECK_WINDOW_CONFIGURATION (config
);
6127 data
= (struct save_window_data
*) XVECTOR (config
);
6128 saved_windows
= XVECTOR (data
->saved_windows
);
6129 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6132 DEFUN ("set-window-configuration", Fset_window_configuration
,
6133 Sset_window_configuration
, 1, 1, 0,
6134 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
6135 CONFIGURATION must be a value previously returned
6136 by `current-window-configuration' (which see).
6137 If CONFIGURATION was made from a frame that is now deleted,
6138 only frame-independent values can be restored. In this case,
6139 the return value is nil. Otherwise the value is t. */)
6140 (Lisp_Object configuration
)
6142 register struct save_window_data
*data
;
6143 struct Lisp_Vector
*saved_windows
;
6144 Lisp_Object new_current_buffer
;
6147 ptrdiff_t old_point
= -1;
6150 CHECK_WINDOW_CONFIGURATION (configuration
);
6152 data
= (struct save_window_data
*) XVECTOR (configuration
);
6153 saved_windows
= XVECTOR (data
->saved_windows
);
6155 new_current_buffer
= data
->current_buffer
;
6156 if (!BUFFER_LIVE_P (XBUFFER (new_current_buffer
)))
6157 new_current_buffer
= Qnil
;
6160 if (XBUFFER (new_current_buffer
) == current_buffer
)
6161 /* The code further down "preserves point" by saving here PT in
6162 old_point and then setting it later back into PT. When the
6163 current-selected-window and the final-selected-window both show
6164 the current buffer, this suffers from the problem that the
6165 current PT is the window-point of the current-selected-window,
6166 while the final PT is the point of the final-selected-window, so
6167 this copy from one PT to the other would end up moving the
6168 window-point of the final-selected-window to the window-point of
6169 the current-selected-window. So we have to be careful which
6170 point of the current-buffer we copy into old_point. */
6171 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
)
6172 && WINDOWP (selected_window
)
6173 && EQ (XWINDOW (selected_window
)->contents
, new_current_buffer
)
6174 && !EQ (selected_window
, data
->current_window
))
6175 old_point
= marker_position (XWINDOW (data
->current_window
)->pointm
);
6179 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
6180 point in new_current_buffer as of the last time this buffer was
6181 used. This can be non-deterministic since it can be changed by
6182 things like jit-lock by mere temporary selection of some random
6183 window that happens to show this buffer.
6184 So if possible we want this arbitrary choice of "which point" to
6185 be the one from the to-be-selected-window so as to prevent this
6186 window's cursor from being copied from another window. */
6187 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
)
6188 /* If current_window = selected_window, its point is in BUF_PT. */
6189 && !EQ (selected_window
, data
->current_window
))
6190 old_point
= marker_position (XWINDOW (data
->current_window
)->pointm
);
6192 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
6195 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6198 /* If f is a dead frame, don't bother rebuilding its window tree.
6199 However, there is other stuff we should still try to do below. */
6200 if (FRAME_LIVE_P (f
))
6203 Lisp_Object dead_windows
= Qnil
;
6204 register Lisp_Object tem
, par
, pers
;
6205 register struct window
*w
;
6206 register struct saved_window
*p
;
6207 struct window
*root_window
;
6208 struct window
**leaf_windows
;
6213 /* Don't do this within the main loop below: This may call Lisp
6214 code and is thus potentially unsafe while input is blocked. */
6215 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
6217 p
= SAVED_WINDOW_N (saved_windows
, k
);
6219 w
= XWINDOW (window
);
6220 if (BUFFERP (w
->contents
)
6221 && !EQ (w
->contents
, p
->buffer
)
6222 && BUFFER_LIVE_P (XBUFFER (p
->buffer
)))
6223 /* If a window we restore gets another buffer, record the
6224 window's old buffer. */
6225 call1 (Qrecord_window_buffer
, window
);
6228 /* Disallow x_set_window_size, temporarily. */
6229 f
->can_x_set_window_size
= false;
6230 /* The mouse highlighting code could get screwed up
6231 if it runs during this. */
6234 /* "Swap out" point from the selected window's buffer
6235 into the window itself. (Normally the pointm of the selected
6236 window holds garbage.) We do this now, before
6237 restoring the window contents, and prevent it from
6238 being done later on when we select a new window. */
6239 if (! NILP (XWINDOW (selected_window
)->contents
))
6241 w
= XWINDOW (selected_window
);
6242 set_marker_both (w
->pointm
,
6244 BUF_PT (XBUFFER (w
->contents
)),
6245 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6249 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
6251 /* Problem: Freeing all matrices and later allocating them again
6252 is a serious redisplay flickering problem. What we would
6253 really like to do is to free only those matrices not reused
6255 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6256 int nwindows
= count_windows (root_window
);
6257 SAFE_NALLOCA (leaf_windows
, 1, nwindows
);
6258 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
6261 Mark all windows now on frame as "deleted".
6262 Restoring the new configuration "undeletes" any that are in it.
6264 Save their current buffers in their height fields, since we may
6265 need it later, if a buffer saved in the configuration is now
6267 delete_all_child_windows (FRAME_ROOT_WINDOW (f
));
6269 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
6271 p
= SAVED_WINDOW_N (saved_windows
, k
);
6273 w
= XWINDOW (window
);
6274 wset_next (w
, Qnil
);
6276 if (!NILP (p
->parent
))
6278 (w
, SAVED_WINDOW_N (saved_windows
, XFASTINT (p
->parent
))->window
);
6280 wset_parent (w
, Qnil
);
6282 if (!NILP (p
->prev
))
6285 (w
, SAVED_WINDOW_N (saved_windows
, XFASTINT (p
->prev
))->window
);
6286 wset_next (XWINDOW (w
->prev
), p
->window
);
6290 wset_prev (w
, Qnil
);
6291 if (!NILP (w
->parent
))
6292 wset_combination (XWINDOW (w
->parent
),
6293 (XINT (p
->total_cols
)
6294 != XWINDOW (w
->parent
)->total_cols
),
6298 /* If we squirreled away the buffer, restore it now. */
6299 if (BUFFERP (w
->combination_limit
))
6300 wset_buffer (w
, w
->combination_limit
);
6301 w
->pixel_left
= XFASTINT (p
->pixel_left
);
6302 w
->pixel_top
= XFASTINT (p
->pixel_top
);
6303 w
->pixel_width
= XFASTINT (p
->pixel_width
);
6304 w
->pixel_height
= XFASTINT (p
->pixel_height
);
6305 w
->left_col
= XFASTINT (p
->left_col
);
6306 w
->top_line
= XFASTINT (p
->top_line
);
6307 w
->total_cols
= XFASTINT (p
->total_cols
);
6308 w
->total_lines
= XFASTINT (p
->total_lines
);
6309 wset_normal_cols (w
, p
->normal_cols
);
6310 wset_normal_lines (w
, p
->normal_lines
);
6311 w
->hscroll
= XFASTINT (p
->hscroll
);
6312 w
->suspend_auto_hscroll
= !NILP (p
->suspend_auto_hscroll
);
6313 w
->min_hscroll
= XFASTINT (p
->min_hscroll
);
6314 w
->hscroll_whole
= XFASTINT (p
->hscroll_whole
);
6315 wset_display_table (w
, p
->display_table
);
6316 w
->left_margin_cols
= XINT (p
->left_margin_cols
);
6317 w
->right_margin_cols
= XINT (p
->right_margin_cols
);
6318 w
->left_fringe_width
= XINT (p
->left_fringe_width
);
6319 w
->right_fringe_width
= XINT (p
->right_fringe_width
);
6320 w
->fringes_outside_margins
= !NILP (p
->fringes_outside_margins
);
6321 w
->scroll_bar_width
= XINT (p
->scroll_bar_width
);
6322 w
->scroll_bar_height
= XINT (p
->scroll_bar_height
);
6323 wset_vertical_scroll_bar_type (w
, p
->vertical_scroll_bar_type
);
6324 wset_horizontal_scroll_bar_type (w
, p
->horizontal_scroll_bar_type
);
6325 wset_dedicated (w
, p
->dedicated
);
6326 wset_combination_limit (w
, p
->combination_limit
);
6327 /* Restore any window parameters that have been saved.
6328 Parameters that have not been saved are left alone. */
6329 for (tem
= p
->window_parameters
; CONSP (tem
); tem
= XCDR (tem
))
6334 if (NILP (XCDR (pers
)))
6336 par
= Fassq (XCAR (pers
), w
->window_parameters
);
6337 if (CONSP (par
) && !NILP (XCDR (par
)))
6338 /* Reset a parameter to nil if and only if it
6339 has a non-nil association. Don't make new
6341 Fsetcdr (par
, Qnil
);
6344 /* Always restore a non-nil value. */
6345 Fset_window_parameter (window
, XCAR (pers
), XCDR (pers
));
6349 if (BUFFERP (p
->buffer
) && BUFFER_LIVE_P (XBUFFER (p
->buffer
)))
6350 /* If saved buffer is alive, install it. */
6352 wset_buffer (w
, p
->buffer
);
6353 w
->start_at_line_beg
= !NILP (p
->start_at_line_beg
);
6354 set_marker_restricted (w
->start
, p
->start
, w
->contents
);
6355 set_marker_restricted (w
->pointm
, p
->pointm
, w
->contents
);
6356 set_marker_restricted (w
->old_pointm
, p
->old_pointm
, w
->contents
);
6357 /* As documented in Fcurrent_window_configuration, don't
6358 restore the location of point in the buffer which was
6359 current when the window configuration was recorded. */
6360 if (!EQ (p
->buffer
, new_current_buffer
)
6361 && XBUFFER (p
->buffer
) == current_buffer
)
6362 Fgoto_char (w
->pointm
);
6364 else if (BUFFERP (w
->contents
) && BUFFER_LIVE_P (XBUFFER (w
->contents
)))
6365 /* Keep window's old buffer; make sure the markers are real. */
6367 /* Set window markers at start of visible range. */
6368 if (XMARKER (w
->start
)->buffer
== 0)
6369 set_marker_restricted_both (w
->start
, w
->contents
, 0, 0);
6370 if (XMARKER (w
->pointm
)->buffer
== 0)
6371 set_marker_restricted_both
6372 (w
->pointm
, w
->contents
,
6373 BUF_PT (XBUFFER (w
->contents
)),
6374 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6375 if (XMARKER (w
->old_pointm
)->buffer
== 0)
6376 set_marker_restricted_both
6377 (w
->old_pointm
, w
->contents
,
6378 BUF_PT (XBUFFER (w
->contents
)),
6379 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6380 w
->start_at_line_beg
= 1;
6382 else if (!NILP (w
->start
))
6383 /* Leaf window has no live buffer, get one. */
6385 /* Get the buffer via other_buffer_safely in order to
6386 avoid showing an unimportant buffer and, if necessary, to
6387 recreate *scratch* in the course (part of Juanma's bs-show
6388 scenario from March 2011). */
6389 wset_buffer (w
, other_buffer_safely (Fcurrent_buffer ()));
6390 /* This will set the markers to beginning of visible
6392 set_marker_restricted_both (w
->start
, w
->contents
, 0, 0);
6393 set_marker_restricted_both (w
->pointm
, w
->contents
, 0, 0);
6394 set_marker_restricted_both (w
->old_pointm
, w
->contents
, 0, 0);
6395 w
->start_at_line_beg
= 1;
6396 if (!NILP (w
->dedicated
))
6397 /* Record this window as dead. */
6398 dead_windows
= Fcons (window
, dead_windows
);
6399 /* Make sure window is no more dedicated. */
6400 wset_dedicated (w
, Qnil
);
6404 fset_root_window (f
, data
->root_window
);
6405 /* Arrange *not* to restore point in the buffer that was
6406 current when the window configuration was saved. */
6407 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
))
6408 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
6409 make_number (old_point
),
6410 XWINDOW (data
->current_window
)->contents
);
6412 /* In the following call to `select-window', prevent "swapping out
6413 point" in the old selected window using the buffer that has
6414 been restored into it. We already swapped out that point from
6415 that window's old buffer.
6417 Do not record the buffer here. We do that in a separate call
6418 to select_window below. See also Bug#16207. */
6419 select_window (data
->current_window
, Qt
, 1);
6420 BVAR (XBUFFER (XWINDOW (selected_window
)->contents
),
6421 last_selected_window
)
6424 if (NILP (data
->focus_frame
)
6425 || (FRAMEP (data
->focus_frame
)
6426 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
6427 Fredirect_frame_focus (frame
, data
->focus_frame
);
6429 /* Now, free glyph matrices in windows that were not reused. */
6430 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
6432 if (NILP (leaf_windows
[i
]->contents
))
6433 free_window_matrices (leaf_windows
[i
]);
6434 else if (EQ (leaf_windows
[i
]->contents
, new_current_buffer
))
6438 /* Allow x_set_window_size again and apply frame size changes if
6440 f
->can_x_set_window_size
= true;
6441 adjust_frame_size (f
, -1, -1, 1, 0, Qnil
);
6443 adjust_frame_glyphs (f
);
6446 /* Scan dead buffer windows. */
6447 for (; CONSP (dead_windows
); dead_windows
= XCDR (dead_windows
))
6449 window
= XCAR (dead_windows
);
6450 if (WINDOW_LIVE_P (window
) && !EQ (window
, FRAME_ROOT_WINDOW (f
)))
6451 delete_deletable_window (window
);
6454 /* Record the selected window's buffer here. The window should
6455 already be the selected one from the call above. */
6456 select_window (data
->current_window
, Qnil
, 0);
6458 /* Fselect_window will have made f the selected frame, so we
6459 reselect the proper frame here. Fhandle_switch_frame will change the
6460 selected window too, but that doesn't make the call to
6461 Fselect_window above totally superfluous; it still sets f's
6463 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
6464 do_switch_frame (data
->selected_frame
, 0, 0, Qnil
);
6466 run_window_configuration_change_hook (f
);
6469 if (!NILP (new_current_buffer
))
6471 Fset_buffer (new_current_buffer
);
6472 /* If the new current buffer doesn't appear in the selected
6473 window, go to its old point (see bug#12208). */
6474 if (!EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
))
6475 Fgoto_char (make_number (old_point
));
6478 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
6479 minibuf_selected_window
= data
->minibuf_selected_window
;
6482 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
6487 restore_window_configuration (Lisp_Object configuration
)
6489 Fset_window_configuration (configuration
);
6493 /* If WINDOW is an internal window, recursively delete all child windows
6494 reachable via the next and contents slots of WINDOW. Otherwise setup
6495 WINDOW to not show any buffer. */
6498 delete_all_child_windows (Lisp_Object window
)
6500 register struct window
*w
;
6502 w
= XWINDOW (window
);
6504 if (!NILP (w
->next
))
6505 /* Delete WINDOW's siblings (we traverse postorderly). */
6506 delete_all_child_windows (w
->next
);
6508 if (WINDOWP (w
->contents
))
6510 delete_all_child_windows (w
->contents
);
6511 wset_combination (w
, 0, Qnil
);
6513 else if (BUFFERP (w
->contents
))
6516 unchain_marker (XMARKER (w
->pointm
));
6517 unchain_marker (XMARKER (w
->old_pointm
));
6518 unchain_marker (XMARKER (w
->start
));
6519 /* Since combination limit makes sense for an internal windows
6520 only, we use this slot to save the buffer for the sake of
6521 possible resurrection in Fset_window_configuration. */
6522 wset_combination_limit (w
, w
->contents
);
6523 wset_buffer (w
, Qnil
);
6526 Vwindow_list
= Qnil
;
6530 count_windows (register struct window
*window
)
6532 register int count
= 1;
6533 if (!NILP (window
->next
))
6534 count
+= count_windows (XWINDOW (window
->next
));
6535 if (WINDOWP (window
->contents
))
6536 count
+= count_windows (XWINDOW (window
->contents
));
6541 /* Fill vector FLAT with leaf windows under W, starting at index I.
6542 Value is last index + 1. */
6544 get_leaf_windows (struct window
*w
, struct window
**flat
, int i
)
6548 if (WINDOWP (w
->contents
))
6549 i
= get_leaf_windows (XWINDOW (w
->contents
), flat
, i
);
6553 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6560 /* Return a pointer to the glyph W's physical cursor is on. Value is
6561 null if W's current matrix is invalid, so that no meaningful glyph
6564 get_phys_cursor_glyph (struct window
*w
)
6566 struct glyph_row
*row
;
6567 struct glyph
*glyph
;
6568 int hpos
= w
->phys_cursor
.hpos
;
6570 if (!(w
->phys_cursor
.vpos
>= 0
6571 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
))
6574 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
6575 if (!row
->enabled_p
)
6580 /* When the window is hscrolled, cursor hpos can legitimately be
6581 out of bounds, but we draw the cursor at the corresponding
6582 window margin in that case. */
6583 if (!row
->reversed_p
&& hpos
< 0)
6585 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
6586 hpos
= row
->used
[TEXT_AREA
] - 1;
6589 if (0 <= hpos
&& hpos
< row
->used
[TEXT_AREA
])
6590 glyph
= row
->glyphs
[TEXT_AREA
] + hpos
;
6599 save_window_save (Lisp_Object window
, struct Lisp_Vector
*vector
, int i
)
6601 register struct saved_window
*p
;
6602 register struct window
*w
;
6603 register Lisp_Object tem
, pers
, par
;
6605 for (; !NILP (window
); window
= w
->next
)
6607 p
= SAVED_WINDOW_N (vector
, i
);
6608 w
= XWINDOW (window
);
6610 wset_temslot (w
, make_number (i
)); i
++;
6612 p
->buffer
= (WINDOW_LEAF_P (w
) ? w
->contents
: Qnil
);
6613 p
->pixel_left
= make_number (w
->pixel_left
);
6614 p
->pixel_top
= make_number (w
->pixel_top
);
6615 p
->pixel_width
= make_number (w
->pixel_width
);
6616 p
->pixel_height
= make_number (w
->pixel_height
);
6617 p
->left_col
= make_number (w
->left_col
);
6618 p
->top_line
= make_number (w
->top_line
);
6619 p
->total_cols
= make_number (w
->total_cols
);
6620 p
->total_lines
= make_number (w
->total_lines
);
6621 p
->normal_cols
= w
->normal_cols
;
6622 p
->normal_lines
= w
->normal_lines
;
6623 XSETFASTINT (p
->hscroll
, w
->hscroll
);
6624 p
->suspend_auto_hscroll
= w
->suspend_auto_hscroll
? Qt
: Qnil
;
6625 XSETFASTINT (p
->min_hscroll
, w
->min_hscroll
);
6626 XSETFASTINT (p
->hscroll_whole
, w
->hscroll_whole
);
6627 p
->display_table
= w
->display_table
;
6628 p
->left_margin_cols
= make_number (w
->left_margin_cols
);
6629 p
->right_margin_cols
= make_number (w
->right_margin_cols
);
6630 p
->left_fringe_width
= make_number (w
->left_fringe_width
);
6631 p
->right_fringe_width
= make_number (w
->right_fringe_width
);
6632 p
->fringes_outside_margins
= w
->fringes_outside_margins
? Qt
: Qnil
;
6633 p
->scroll_bar_width
= make_number (w
->scroll_bar_width
);
6634 p
->scroll_bar_height
= make_number (w
->scroll_bar_height
);
6635 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
6636 p
->horizontal_scroll_bar_type
= w
->horizontal_scroll_bar_type
;
6637 p
->dedicated
= w
->dedicated
;
6638 p
->combination_limit
= w
->combination_limit
;
6639 p
->window_parameters
= Qnil
;
6641 if (!NILP (Vwindow_persistent_parameters
))
6643 /* Run cycle detection on Vwindow_persistent_parameters. */
6644 Lisp_Object tortoise
, hare
;
6646 hare
= tortoise
= Vwindow_persistent_parameters
;
6647 while (CONSP (hare
))
6654 tortoise
= XCDR (tortoise
);
6656 if (EQ (hare
, tortoise
))
6657 /* Reset Vwindow_persistent_parameters to Qnil. */
6659 Vwindow_persistent_parameters
= Qnil
;
6664 for (tem
= Vwindow_persistent_parameters
; CONSP (tem
);
6668 /* Save values for persistent window parameters. */
6669 if (CONSP (pers
) && !NILP (XCDR (pers
)))
6671 par
= Fassq (XCAR (pers
), w
->window_parameters
);
6673 /* If the window has no value for the parameter,
6675 p
->window_parameters
= Fcons (Fcons (XCAR (pers
), Qnil
),
6676 p
->window_parameters
);
6678 /* If the window has a value for the parameter,
6680 p
->window_parameters
= Fcons (Fcons (XCAR (par
),
6682 p
->window_parameters
);
6687 if (BUFFERP (w
->contents
))
6689 /* Save w's value of point in the window configuration. If w
6690 is the selected window, then get the value of point from
6691 the buffer; pointm is garbage in the selected window. */
6692 if (EQ (window
, selected_window
))
6693 p
->pointm
= build_marker (XBUFFER (w
->contents
),
6694 BUF_PT (XBUFFER (w
->contents
)),
6695 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6697 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
6698 p
->old_pointm
= Fcopy_marker (w
->old_pointm
, Qnil
);
6699 XMARKER (p
->pointm
)->insertion_type
6700 = !NILP (buffer_local_value
/* Don't signal error if void. */
6701 (Qwindow_point_insertion_type
, w
->contents
));
6702 XMARKER (p
->old_pointm
)->insertion_type
6703 = !NILP (buffer_local_value
/* Don't signal error if void. */
6704 (Qwindow_point_insertion_type
, w
->contents
));
6706 p
->start
= Fcopy_marker (w
->start
, Qnil
);
6707 p
->start_at_line_beg
= w
->start_at_line_beg
? Qt
: Qnil
;
6712 p
->old_pointm
= Qnil
;
6714 p
->start_at_line_beg
= Qnil
;
6717 p
->parent
= NILP (w
->parent
) ? Qnil
: XWINDOW (w
->parent
)->temslot
;
6718 p
->prev
= NILP (w
->prev
) ? Qnil
: XWINDOW (w
->prev
)->temslot
;
6720 if (WINDOWP (w
->contents
))
6721 i
= save_window_save (w
->contents
, vector
, i
);
6727 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
6728 Scurrent_window_configuration
, 0, 1, 0,
6729 doc
: /* Return an object representing the current window configuration of FRAME.
6730 If FRAME is nil or omitted, use the selected frame.
6731 This describes the number of windows, their sizes and current buffers,
6732 and for each displayed buffer, where display starts, and the position of
6733 point. An exception is made for point in the current buffer:
6734 its value is -not- saved.
6735 This also records the currently selected frame, and FRAME's focus
6736 redirection (see `redirect-frame-focus'). The variable
6737 `window-persistent-parameters' specifies which window parameters are
6738 saved by this function. */)
6741 register Lisp_Object tem
;
6742 register int n_windows
;
6743 register struct save_window_data
*data
;
6745 struct frame
*f
= decode_live_frame (frame
);
6747 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6748 data
= ALLOCATE_PSEUDOVECTOR (struct save_window_data
, frame_cols
,
6749 PVEC_WINDOW_CONFIGURATION
);
6751 data
->frame_cols
= FRAME_COLS (f
);
6752 data
->frame_lines
= FRAME_LINES (f
);
6753 data
->frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6754 data
->frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6755 data
->frame_text_width
= FRAME_TEXT_WIDTH (f
);
6756 data
->frame_text_height
= FRAME_TEXT_HEIGHT (f
);
6757 data
->frame_menu_bar_height
= FRAME_MENU_BAR_HEIGHT (f
);
6758 data
->frame_tool_bar_height
= FRAME_TOOL_BAR_HEIGHT (f
);
6759 data
->selected_frame
= selected_frame
;
6760 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6761 XSETBUFFER (data
->current_buffer
, current_buffer
);
6762 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6763 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6764 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6765 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6766 tem
= make_uninit_vector (n_windows
);
6767 data
->saved_windows
= tem
;
6768 for (i
= 0; i
< n_windows
; i
++)
6770 Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
));
6771 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6772 XSETWINDOW_CONFIGURATION (tem
, data
);
6776 /* Called after W's margins, fringes or scroll bars was adjusted. */
6779 apply_window_adjustment (struct window
*w
)
6782 clear_glyph_matrix (w
->current_matrix
);
6783 w
->window_end_valid
= 0;
6784 windows_or_buffers_changed
= 30;
6786 adjust_frame_glyphs (XFRAME (WINDOW_FRAME (w
)));
6790 /***********************************************************************
6792 ***********************************************************************/
6794 static struct window
*
6795 set_window_margins (struct window
*w
, Lisp_Object left_width
,
6796 Lisp_Object right_width
)
6799 int unit
= WINDOW_FRAME_COLUMN_WIDTH (w
);
6801 left
= (NILP (left_width
) ? 0
6802 : (CHECK_NATNUM (left_width
), XINT (left_width
)));
6803 right
= (NILP (right_width
) ? 0
6804 : (CHECK_NATNUM (right_width
), XINT (right_width
)));
6806 if (w
->left_margin_cols
!= left
|| w
->right_margin_cols
!= right
)
6808 /* Don't change anything if new margins won't fit. */
6809 if ((WINDOW_PIXEL_WIDTH (w
)
6810 - WINDOW_FRINGES_WIDTH (w
)
6811 - WINDOW_SCROLL_BAR_AREA_WIDTH (w
)
6812 - (left
+ right
) * unit
)
6813 >= MIN_SAFE_WINDOW_PIXEL_WIDTH (w
))
6815 w
->left_margin_cols
= left
;
6816 w
->right_margin_cols
= right
;
6827 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6829 doc
: /* Set width of marginal areas of window WINDOW.
6830 WINDOW must be a live window and defaults to the selected one.
6832 Second arg LEFT-WIDTH specifies the number of character cells to
6833 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6834 does the same for the right marginal area. A nil width parameter
6837 Return t if any margin was actually changed and nil otherwise. */)
6838 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
)
6840 struct window
*w
= set_window_margins (decode_live_window (window
),
6841 left_width
, right_width
);
6842 return w
? (apply_window_adjustment (w
), Qt
) : Qnil
;
6846 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6848 doc
: /* Get width of marginal areas of window WINDOW.
6849 WINDOW must be a live window and defaults to the selected one.
6851 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6852 If a marginal area does not exist, its width will be returned
6854 (Lisp_Object window
)
6856 struct window
*w
= decode_live_window (window
);
6857 return Fcons (w
->left_margin_cols
6858 ? make_number (w
->left_margin_cols
) : Qnil
,
6859 w
->right_margin_cols
6860 ? make_number (w
->right_margin_cols
) : Qnil
);
6865 /***********************************************************************
6867 ***********************************************************************/
6869 static struct window
*
6870 set_window_fringes (struct window
*w
, Lisp_Object left_width
,
6871 Lisp_Object right_width
, Lisp_Object outside_margins
)
6873 int left
, right
, outside
= !NILP (outside_margins
);
6875 left
= (NILP (left_width
) ? -1
6876 : (CHECK_NATNUM (left_width
), XINT (left_width
)));
6877 right
= (NILP (right_width
) ? -1
6878 : (CHECK_NATNUM (right_width
), XINT (right_width
)));
6880 /* Do nothing on a tty or if nothing to actually change. */
6881 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6882 && (w
->left_fringe_width
!= left
6883 || w
->right_fringe_width
!= right
6884 || w
->fringes_outside_margins
!= outside
))
6886 if (left
> 0 || right
> 0)
6888 /* Don't change anything if new fringes don't fit. */
6889 if ((WINDOW_PIXEL_WIDTH (w
)
6890 - WINDOW_MARGINS_WIDTH (w
)
6891 - WINDOW_SCROLL_BAR_AREA_WIDTH (w
)
6892 - max (left
, 0) - max (right
, 0))
6893 < MIN_SAFE_WINDOW_PIXEL_WIDTH (w
))
6897 w
->left_fringe_width
= left
;
6898 w
->right_fringe_width
= right
;
6899 w
->fringes_outside_margins
= outside
;
6907 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6909 doc
: /* Set the fringe widths of window WINDOW.
6910 WINDOW must be a live window and defaults to the selected one.
6912 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6913 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6914 fringe width. If a fringe width arg is nil, that means to use the
6915 frame's default fringe width. Default fringe widths can be set with
6916 the command `set-fringe-style'.
6917 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6918 outside of the display margins. By default, fringes are drawn between
6919 display marginal areas and the text area.
6921 Return t if any fringe was actually changed and nil otherwise. */)
6922 (Lisp_Object window
, Lisp_Object left_width
,
6923 Lisp_Object right_width
, Lisp_Object outside_margins
)
6926 = set_window_fringes (decode_live_window (window
),
6927 left_width
, right_width
, outside_margins
);
6928 return w
? (apply_window_adjustment (w
), Qt
) : Qnil
;
6932 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6934 doc
: /* Get width of fringes of window WINDOW.
6935 WINDOW must be a live window and defaults to the selected one.
6937 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6938 (Lisp_Object window
)
6940 struct window
*w
= decode_live_window (window
);
6942 return list3 (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6943 make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6944 WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
) ? Qt
: Qnil
);
6949 /***********************************************************************
6951 ***********************************************************************/
6953 static struct window
*
6954 set_window_scroll_bars (struct window
*w
, Lisp_Object width
,
6955 Lisp_Object vertical_type
, Lisp_Object height
,
6956 Lisp_Object horizontal_type
)
6958 int iwidth
= (NILP (width
) ? -1 : (CHECK_NATNUM (width
), XINT (width
)));
6962 vertical_type
= Qnil
;
6964 if (!(NILP (vertical_type
)
6965 || EQ (vertical_type
, Qleft
)
6966 || EQ (vertical_type
, Qright
)
6967 || EQ (vertical_type
, Qt
)))
6968 error ("Invalid type of vertical scroll bar");
6970 if (w
->scroll_bar_width
!= iwidth
6971 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6973 /* Don't change anything if new scroll bar won't fit. */
6974 if ((WINDOW_PIXEL_WIDTH (w
)
6975 - WINDOW_MARGINS_WIDTH (w
)
6976 - WINDOW_FRINGES_WIDTH (w
)
6978 >= MIN_SAFE_WINDOW_PIXEL_WIDTH (w
))
6980 w
->scroll_bar_width
= iwidth
;
6981 wset_vertical_scroll_bar_type (w
, vertical_type
);
6986 #if USE_HORIZONTAL_SCROLL_BARS
6988 int iheight
= (NILP (height
) ? -1 : (CHECK_NATNUM (height
), XINT (height
)));
6990 if (MINI_WINDOW_P (w
) || iheight
== 0)
6991 horizontal_type
= Qnil
;
6993 if (!(NILP (horizontal_type
)
6994 || EQ (horizontal_type
, Qbottom
)
6995 || EQ (horizontal_type
, Qt
)))
6996 error ("Invalid type of horizontal scroll bar");
6998 if (w
->scroll_bar_height
!= iheight
6999 || !EQ (w
->horizontal_scroll_bar_type
, horizontal_type
))
7001 /* Don't change anything if new scroll bar won't fit. */
7002 if ((WINDOW_PIXEL_HEIGHT (w
)
7003 - WINDOW_HEADER_LINE_HEIGHT (w
)
7004 - WINDOW_MODE_LINE_HEIGHT (w
)
7006 >= MIN_SAFE_WINDOW_PIXEL_HEIGHT (w
))
7008 w
->scroll_bar_height
= iheight
;
7009 wset_horizontal_scroll_bar_type (w
, horizontal_type
);
7015 wset_horizontal_scroll_bar_type (w
, Qnil
);
7018 return changed
? w
: NULL
;
7021 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
,
7022 Sset_window_scroll_bars
, 1, 5, 0,
7023 doc
: /* Set width and type of scroll bars of window WINDOW.
7024 WINDOW must be a live window and defaults to the selected one.
7026 Second parameter WIDTH specifies the pixel width for the vertical scroll
7027 bar. If WIDTH is nil, use the scroll-bar width of WINDOW's frame.
7028 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
7029 bar: left, right, or nil. If VERTICAL-TYPE is t, this means use the
7030 frame's scroll-bar type.
7032 Fourth parameter HEIGHT specifies the pixel height for the horizontal
7033 scroll bar. If HEIGHT is nil, use the scroll-bar height of WINDOW's
7034 frame. Fifth parameter HORIZONTAL-TYPE specifies the type of the
7035 horizontal scroll bar: nil, bottom, or t. If HORIZONTAL-TYPE is t, this
7036 means to use the frame's horizontal scroll-bar type.
7038 Return t if scroll bars were actually changed and nil otherwise. */)
7039 (Lisp_Object window
, Lisp_Object width
, Lisp_Object vertical_type
,
7040 Lisp_Object height
, Lisp_Object horizontal_type
)
7043 = set_window_scroll_bars (decode_live_window (window
),
7044 width
, vertical_type
, height
, horizontal_type
);
7045 return w
? (apply_window_adjustment (w
), Qt
) : Qnil
;
7049 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
7051 doc
: /* Get width and type of scroll bars of window WINDOW.
7052 WINDOW must be a live window and defaults to the selected one.
7054 Value is a list of the form (WIDTH COLUMNS VERTICAL-TYPE HEIGHT LINES
7055 HORIZONTAL-TYPE). If WIDTH or HEIGHT is nil or VERTICAL-TYPE or
7056 HORIZONTAL-TYPE is t, the window is using the frame's corresponding
7058 (Lisp_Object window
)
7060 struct window
*w
= decode_live_window (window
);
7062 return Fcons (((w
->scroll_bar_width
>= 0)
7063 ? make_number (w
->scroll_bar_width
)
7065 list5 (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
7066 w
->vertical_scroll_bar_type
,
7067 ((w
->scroll_bar_height
>= 0)
7068 ? make_number (w
->scroll_bar_height
)
7070 make_number (WINDOW_SCROLL_BAR_LINES (w
)),
7071 w
->horizontal_scroll_bar_type
));
7074 /***********************************************************************
7076 ***********************************************************************/
7078 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
7079 doc
: /* Return the amount by which WINDOW is scrolled vertically.
7080 If WINDOW is omitted or nil, it defaults to the selected window.
7081 Normally, value is a multiple of the canonical character height of WINDOW;
7082 optional second arg PIXELS-P means value is measured in pixels. */)
7083 (Lisp_Object window
, Lisp_Object pixels_p
)
7086 struct window
*w
= decode_live_window (window
);
7087 struct frame
*f
= XFRAME (w
->frame
);
7089 if (FRAME_WINDOW_P (f
))
7090 result
= (NILP (pixels_p
)
7091 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
7092 : make_number (-w
->vscroll
));
7094 result
= make_number (0);
7099 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
7101 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
7102 WINDOW nil means use the selected window. Normally, VSCROLL is a
7103 non-negative multiple of the canonical character height of WINDOW;
7104 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
7105 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
7106 corresponds to an integral number of pixels. The return value is the
7107 result of this rounding.
7108 If PIXELS-P is non-nil, the return value is VSCROLL. */)
7109 (Lisp_Object window
, Lisp_Object vscroll
, Lisp_Object pixels_p
)
7111 struct window
*w
= decode_live_window (window
);
7112 struct frame
*f
= XFRAME (w
->frame
);
7114 CHECK_NUMBER_OR_FLOAT (vscroll
);
7116 if (FRAME_WINDOW_P (f
))
7118 int old_dy
= w
->vscroll
;
7120 w
->vscroll
= - (NILP (pixels_p
)
7121 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
7122 : XFLOATINT (vscroll
));
7123 w
->vscroll
= min (w
->vscroll
, 0);
7125 if (w
->vscroll
!= old_dy
)
7127 /* Adjust glyph matrix of the frame if the virtual display
7128 area becomes larger than before. */
7129 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
7130 adjust_frame_glyphs (f
);
7132 /* Prevent redisplay shortcuts. */
7133 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
7137 return Fwindow_vscroll (window
, pixels_p
);
7141 /* Call FN for all leaf windows on frame F. FN is called with the
7142 first argument being a pointer to the leaf window, and with
7143 additional argument USER_DATA. Stops when FN returns 0. */
7146 foreach_window (struct frame
*f
, int (*fn
) (struct window
*, void *),
7149 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
7150 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
7151 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
7155 /* Helper function for foreach_window. Call FN for all leaf windows
7156 reachable from W. FN is called with the first argument being a
7157 pointer to the leaf window, and with additional argument USER_DATA.
7158 Stop when FN returns 0. Value is 0 if stopped by FN. */
7161 foreach_window_1 (struct window
*w
, int (*fn
) (struct window
*, void *), void *user_data
)
7165 for (cont
= 1; w
&& cont
;)
7167 if (WINDOWP (w
->contents
))
7168 cont
= foreach_window_1 (XWINDOW (w
->contents
), fn
, user_data
);
7170 cont
= fn (w
, user_data
);
7172 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
7178 /***********************************************************************
7180 ***********************************************************************/
7182 /* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2
7183 describe the same state of affairs. This is used by Fequal.
7185 IGNORE_POSITIONS means ignore non-matching scroll positions
7188 This ignores a couple of things like the dedication status of
7189 window, combination_limit and the like. This might have to be
7193 compare_window_configurations (Lisp_Object configuration1
,
7194 Lisp_Object configuration2
,
7195 bool ignore_positions
)
7197 register struct save_window_data
*d1
, *d2
;
7198 struct Lisp_Vector
*sws1
, *sws2
;
7201 CHECK_WINDOW_CONFIGURATION (configuration1
);
7202 CHECK_WINDOW_CONFIGURATION (configuration2
);
7204 d1
= (struct save_window_data
*) XVECTOR (configuration1
);
7205 d2
= (struct save_window_data
*) XVECTOR (configuration2
);
7206 sws1
= XVECTOR (d1
->saved_windows
);
7207 sws2
= XVECTOR (d2
->saved_windows
);
7209 /* Frame settings must match. */
7210 if (d1
->frame_cols
!= d2
->frame_cols
7211 || d1
->frame_lines
!= d2
->frame_lines
7212 || d1
->frame_menu_bar_lines
!= d2
->frame_menu_bar_lines
7213 || !EQ (d1
->selected_frame
, d2
->selected_frame
)
7214 || !EQ (d1
->current_buffer
, d2
->current_buffer
)
7215 || (!ignore_positions
7216 && (!EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
)
7217 || !EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
)))
7218 || !EQ (d1
->focus_frame
, d2
->focus_frame
)
7219 /* Verify that the two configurations have the same number of windows. */
7220 || sws1
->header
.size
!= sws2
->header
.size
)
7223 for (i
= 0; i
< sws1
->header
.size
; i
++)
7225 struct saved_window
*sw1
, *sw2
;
7227 sw1
= SAVED_WINDOW_N (sws1
, i
);
7228 sw2
= SAVED_WINDOW_N (sws2
, i
);
7231 /* The "current" windows in the two configurations must
7232 correspond to each other. */
7233 EQ (d1
->current_window
, sw1
->window
)
7234 != EQ (d2
->current_window
, sw2
->window
)
7235 /* Windows' buffers must match. */
7236 || !EQ (sw1
->buffer
, sw2
->buffer
)
7237 || !EQ (sw1
->pixel_left
, sw2
->pixel_left
)
7238 || !EQ (sw1
->pixel_top
, sw2
->pixel_top
)
7239 || !EQ (sw1
->pixel_height
, sw2
->pixel_height
)
7240 || !EQ (sw1
->pixel_width
, sw2
->pixel_width
)
7241 || !EQ (sw1
->left_col
, sw2
->left_col
)
7242 || !EQ (sw1
->top_line
, sw2
->top_line
)
7243 || !EQ (sw1
->total_cols
, sw2
->total_cols
)
7244 || !EQ (sw1
->total_lines
, sw2
->total_lines
)
7245 || !EQ (sw1
->display_table
, sw2
->display_table
)
7246 /* The next two disjuncts check the window structure for
7248 || !EQ (sw1
->parent
, sw2
->parent
)
7249 || !EQ (sw1
->prev
, sw2
->prev
)
7250 || (!ignore_positions
7251 && (!EQ (sw1
->hscroll
, sw2
->hscroll
)
7252 || !EQ (sw1
->min_hscroll
, sw2
->min_hscroll
)
7253 || !EQ (sw1
->start_at_line_beg
, sw2
->start_at_line_beg
)
7254 || NILP (Fequal (sw1
->start
, sw2
->start
))
7255 || NILP (Fequal (sw1
->pointm
, sw2
->pointm
))))
7256 || !EQ (sw1
->left_margin_cols
, sw2
->left_margin_cols
)
7257 || !EQ (sw1
->right_margin_cols
, sw2
->right_margin_cols
)
7258 || !EQ (sw1
->left_fringe_width
, sw2
->left_fringe_width
)
7259 || !EQ (sw1
->right_fringe_width
, sw2
->right_fringe_width
)
7260 || !EQ (sw1
->fringes_outside_margins
, sw2
->fringes_outside_margins
)
7261 || !EQ (sw1
->scroll_bar_width
, sw2
->scroll_bar_width
)
7262 || !EQ (sw1
->scroll_bar_height
, sw2
->scroll_bar_height
)
7263 || !EQ (sw1
->vertical_scroll_bar_type
, sw2
->vertical_scroll_bar_type
)
7264 || !EQ (sw1
->horizontal_scroll_bar_type
, sw2
->horizontal_scroll_bar_type
))
7271 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
7272 Scompare_window_configurations
, 2, 2, 0,
7273 doc
: /* Compare two window configurations as regards the structure of windows.
7274 This function ignores details such as the values of point
7275 and scrolling positions. */)
7276 (Lisp_Object x
, Lisp_Object y
)
7278 if (compare_window_configurations (x
, y
, 1))
7284 init_window_once (void)
7286 struct frame
*f
= make_initial_frame ();
7287 XSETFRAME (selected_frame
, f
);
7288 Vterminal_frame
= selected_frame
;
7289 minibuf_window
= f
->minibuffer_window
;
7290 selected_window
= f
->selected_window
;
7296 Vwindow_list
= Qnil
;
7300 syms_of_window (void)
7302 DEFSYM (Qscroll_up
, "scroll-up");
7303 DEFSYM (Qscroll_down
, "scroll-down");
7304 DEFSYM (Qscroll_command
, "scroll-command");
7306 Fput (Qscroll_up
, Qscroll_command
, Qt
);
7307 Fput (Qscroll_down
, Qscroll_command
, Qt
);
7309 DEFSYM (Qwindow_configuration_change_hook
, "window-configuration-change-hook");
7310 DEFSYM (Qwindowp
, "windowp");
7311 DEFSYM (Qwindow_configuration_p
, "window-configuration-p");
7312 DEFSYM (Qwindow_live_p
, "window-live-p");
7313 DEFSYM (Qwindow_valid_p
, "window-valid-p");
7314 DEFSYM (Qwindow_deletable_p
, "window-deletable-p");
7315 DEFSYM (Qdelete_window
, "delete-window");
7316 DEFSYM (Qwindow_resize_root_window
, "window--resize-root-window");
7317 DEFSYM (Qwindow_resize_root_window_vertically
, "window--resize-root-window-vertically");
7318 DEFSYM (Qwindow_sanitize_window_sizes
, "window--sanitize-window-sizes");
7319 DEFSYM (Qwindow_pixel_to_total
, "window--pixel-to-total");
7320 DEFSYM (Qsafe
, "safe");
7321 DEFSYM (Qdisplay_buffer
, "display-buffer");
7322 DEFSYM (Qreplace_buffer_in_windows
, "replace-buffer-in-windows");
7323 DEFSYM (Qrecord_window_buffer
, "record-window-buffer");
7324 DEFSYM (Qget_mru_window
, "get-mru-window");
7325 DEFSYM (Qwindow_size
, "window-size");
7326 DEFSYM (Qtemp_buffer_show_hook
, "temp-buffer-show-hook");
7327 DEFSYM (Qabove
, "above");
7328 DEFSYM (Qbelow
, "below");
7329 DEFSYM (Qclone_of
, "clone-of");
7330 DEFSYM (Qfloor
, "floor");
7331 DEFSYM (Qceiling
, "ceiling");
7333 staticpro (&Vwindow_list
);
7335 minibuf_selected_window
= Qnil
;
7336 staticpro (&minibuf_selected_window
);
7338 window_scroll_pixel_based_preserve_x
= -1;
7339 window_scroll_pixel_based_preserve_y
= -1;
7340 window_scroll_preserve_hpos
= -1;
7341 window_scroll_preserve_vpos
= -1;
7343 DEFVAR_LISP ("temp-buffer-show-function", Vtemp_buffer_show_function
,
7344 doc
: /* Non-nil means call as function to display a help buffer.
7345 The function is called with one argument, the buffer to be displayed.
7346 Used by `with-output-to-temp-buffer'.
7347 If this function is used, then it must do the entire job of showing
7348 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
7349 Vtemp_buffer_show_function
= Qnil
;
7351 DEFVAR_LISP ("minibuffer-scroll-window", Vminibuf_scroll_window
,
7352 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
7353 Vminibuf_scroll_window
= Qnil
;
7355 DEFVAR_BOOL ("mode-line-in-non-selected-windows", mode_line_in_non_selected_windows
,
7356 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
7357 If the minibuffer is active, the `minibuffer-scroll-window' mode line
7358 is displayed in the `mode-line' face. */);
7359 mode_line_in_non_selected_windows
= true;
7361 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer
,
7362 doc
: /* If this is a live buffer, \\[scroll-other-window] should scroll its window. */);
7363 Vother_window_scroll_buffer
= Qnil
;
7365 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p
,
7366 doc
: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
7367 auto_window_vscroll_p
= true;
7369 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines
,
7370 doc
: /* Number of lines of continuity when scrolling by screenfuls. */);
7371 next_screen_context_lines
= 2;
7373 DEFVAR_LISP ("scroll-preserve-screen-position",
7374 Vscroll_preserve_screen_position
,
7375 doc
: /* Controls if scroll commands move point to keep its screen position unchanged.
7376 A value of nil means point does not keep its screen position except
7377 at the scroll margin or window boundary respectively.
7378 A value of t means point keeps its screen position if the scroll
7379 command moved it vertically out of the window, e.g. when scrolling
7381 Any other value means point always keeps its screen position.
7382 Scroll commands should have the `scroll-command' property
7383 on their symbols to be controlled by this variable. */);
7384 Vscroll_preserve_screen_position
= Qnil
;
7386 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type
,
7387 doc
: /* Type of marker to use for `window-point'. */);
7388 Vwindow_point_insertion_type
= Qnil
;
7389 DEFSYM (Qwindow_point_insertion_type
, "window_point_insertion_type");
7391 DEFVAR_LISP ("window-configuration-change-hook",
7392 Vwindow_configuration_change_hook
,
7393 doc
: /* Functions to call when window configuration changes.
7394 The buffer-local part is run once per window, with the relevant window
7395 selected; while the global part is run only once for the modified frame,
7396 with the relevant frame selected. */);
7397 Vwindow_configuration_change_hook
= Qnil
;
7399 DEFVAR_LISP ("recenter-redisplay", Vrecenter_redisplay
,
7400 doc
: /* Non-nil means `recenter' redraws entire frame.
7401 If this option is non-nil, then the `recenter' command with a nil
7402 argument will redraw the entire frame; the special value `tty' causes
7403 the frame to be redrawn only if it is a tty frame. */);
7404 Vrecenter_redisplay
= Qtty
;
7406 DEFVAR_LISP ("window-combination-resize", Vwindow_combination_resize
,
7407 doc
: /* If t, resize window combinations proportionally.
7408 If this variable is nil, splitting a window gets the entire screen space
7409 for displaying the new window from the window to split. Deleting and
7410 resizing a window preferably resizes one adjacent window only.
7412 If this variable is t, splitting a window tries to get the space
7413 proportionally from all windows in the same combination. This also
7414 allows to split a window that is otherwise too small or of fixed size.
7415 Resizing and deleting a window proportionally resize all windows in the
7418 Other values are reserved for future use.
7420 This variable takes no effect if the variable `window-combination-limit' is
7422 Vwindow_combination_resize
= Qnil
;
7424 DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit
,
7425 doc
: /* If non-nil, splitting a window makes a new parent window.
7426 The following values are recognized:
7428 nil means splitting a window will create a new parent window only if the
7429 window has no parent window or the window shall become part of a
7430 combination orthogonal to the one it is part of.
7432 `window-size' means that splitting a window for displaying a buffer
7433 makes a new parent window provided `display-buffer' is supposed to
7434 explicitly set the window's size due to the presence of a
7435 `window-height' or `window-width' entry in the alist used by
7436 `display-buffer'. Otherwise, this value is handled like nil.
7438 `temp-buffer' means that splitting a window for displaying a temporary
7439 buffer always makes a new parent window. Otherwise, this value is
7442 `display-buffer' means that splitting a window for displaying a buffer
7443 always makes a new parent window. Since temporary buffers are
7444 displayed by the function `display-buffer', this value is stronger
7445 than `temp-buffer'. Splitting a window for other purpose makes a
7446 new parent window only if needed.
7448 t means that splitting a window always creates a new parent window. If
7449 all splits behave this way, each frame's window tree is a binary
7450 tree and every window but the frame's root window has exactly one
7453 Other values are reserved for future use. */);
7454 Vwindow_combination_limit
= Qwindow_size
;
7456 DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters
,
7457 doc
: /* Alist of persistent window parameters.
7458 This alist specifies which window parameters shall get saved by
7459 `current-window-configuration' and `window-state-get' and subsequently
7460 restored to their previous values by `set-window-configuration' and
7463 The car of each entry of this alist is the symbol specifying the
7464 parameter. The cdr is one of the following:
7466 nil means the parameter is neither saved by `window-state-get' nor by
7467 `current-window-configuration'.
7469 t means the parameter is saved by `current-window-configuration' and,
7470 provided its WRITABLE argument is nil, by `window-state-get'.
7472 The symbol `writable' means the parameter is saved unconditionally by
7473 both `current-window-configuration' and `window-state-get'. Do not use
7474 this value for parameters without read syntax (like windows or frames).
7476 Parameters not saved by `current-window-configuration' or
7477 `window-state-get' are left alone by `set-window-configuration'
7478 respectively are not installed by `window-state-put'. */);
7479 Vwindow_persistent_parameters
= list1 (Fcons (Qclone_of
, Qt
));
7481 DEFVAR_BOOL ("window-resize-pixelwise", window_resize_pixelwise
,
7482 doc
: /* Non-nil means resize windows pixelwise.
7483 This currently affects the functions: `split-window', `maximize-window',
7484 `minimize-window', `fit-window-to-buffer' and `fit-frame-to-buffer', and
7485 all functions that symmetrically resize a parent window.
7487 Note that when a frame's pixel size is not a multiple of the
7488 frame's character size, at least one window may get resized
7489 pixelwise even if this option is nil. */);
7490 window_resize_pixelwise
= false;
7492 DEFVAR_BOOL ("fast-but-imprecise-scrolling",
7493 Vfast_but_imprecise_scrolling
,
7494 doc
: /* When non-nil, accelerate scrolling operations.
7495 This comes into play when scrolling rapidly over previously
7496 unfontified buffer regions. Only those portions of the buffer which
7497 are actually going to be displayed get fontified.
7499 Note that this optimization can cause the portion of the buffer
7500 displayed after a scrolling operation to be somewhat inaccurate. */);
7501 Vfast_but_imprecise_scrolling
= false;
7503 defsubr (&Sselected_window
);
7504 defsubr (&Sminibuffer_window
);
7505 defsubr (&Swindow_minibuffer_p
);
7506 defsubr (&Swindowp
);
7507 defsubr (&Swindow_valid_p
);
7508 defsubr (&Swindow_live_p
);
7509 defsubr (&Swindow_frame
);
7510 defsubr (&Sframe_root_window
);
7511 defsubr (&Sframe_first_window
);
7512 defsubr (&Sframe_selected_window
);
7513 defsubr (&Sset_frame_selected_window
);
7514 defsubr (&Spos_visible_in_window_p
);
7515 defsubr (&Swindow_line_height
);
7516 defsubr (&Swindow_buffer
);
7517 defsubr (&Swindow_parent
);
7518 defsubr (&Swindow_top_child
);
7519 defsubr (&Swindow_left_child
);
7520 defsubr (&Swindow_next_sibling
);
7521 defsubr (&Swindow_prev_sibling
);
7522 defsubr (&Swindow_combination_limit
);
7523 defsubr (&Sset_window_combination_limit
);
7524 defsubr (&Swindow_use_time
);
7525 defsubr (&Swindow_pixel_width
);
7526 defsubr (&Swindow_pixel_height
);
7527 defsubr (&Swindow_total_width
);
7528 defsubr (&Swindow_total_height
);
7529 defsubr (&Swindow_normal_size
);
7530 defsubr (&Swindow_new_pixel
);
7531 defsubr (&Swindow_new_total
);
7532 defsubr (&Swindow_new_normal
);
7533 defsubr (&Swindow_pixel_left
);
7534 defsubr (&Swindow_pixel_top
);
7535 defsubr (&Swindow_left_column
);
7536 defsubr (&Swindow_top_line
);
7537 defsubr (&Sset_window_new_pixel
);
7538 defsubr (&Sset_window_new_total
);
7539 defsubr (&Sset_window_new_normal
);
7540 defsubr (&Swindow_resize_apply
);
7541 defsubr (&Swindow_resize_apply_total
);
7542 defsubr (&Swindow_body_height
);
7543 defsubr (&Swindow_body_width
);
7544 defsubr (&Swindow_hscroll
);
7545 defsubr (&Sset_window_hscroll
);
7546 defsubr (&Swindow_redisplay_end_trigger
);
7547 defsubr (&Sset_window_redisplay_end_trigger
);
7548 defsubr (&Swindow_edges
);
7549 defsubr (&Swindow_pixel_edges
);
7550 defsubr (&Swindow_absolute_pixel_edges
);
7551 defsubr (&Swindow_mode_line_height
);
7552 defsubr (&Swindow_header_line_height
);
7553 defsubr (&Swindow_right_divider_width
);
7554 defsubr (&Swindow_bottom_divider_width
);
7555 defsubr (&Swindow_scroll_bar_width
);
7556 defsubr (&Swindow_scroll_bar_height
);
7557 defsubr (&Swindow_inside_edges
);
7558 defsubr (&Swindow_inside_pixel_edges
);
7559 defsubr (&Swindow_inside_absolute_pixel_edges
);
7560 defsubr (&Scoordinates_in_window_p
);
7561 defsubr (&Swindow_at
);
7562 defsubr (&Swindow_point
);
7563 defsubr (&Swindow_old_point
);
7564 defsubr (&Swindow_start
);
7565 defsubr (&Swindow_end
);
7566 defsubr (&Sset_window_point
);
7567 defsubr (&Sset_window_start
);
7568 defsubr (&Swindow_dedicated_p
);
7569 defsubr (&Sset_window_dedicated_p
);
7570 defsubr (&Swindow_display_table
);
7571 defsubr (&Sset_window_display_table
);
7572 defsubr (&Snext_window
);
7573 defsubr (&Sprevious_window
);
7574 defsubr (&Swindow__sanitize_window_sizes
);
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");