1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985-1987, 1993-1998, 2000-2014 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"
36 #include "dispextern.h"
37 #include "blockinput.h"
38 #include "intervals.h"
39 #include "termhooks.h" /* For FRAME_TERMINAL. */
40 #ifdef HAVE_WINDOW_SYSTEM
42 #endif /* HAVE_WINDOW_SYSTEM */
47 Lisp_Object Qwindowp
, Qwindow_live_p
;
48 static Lisp_Object Qwindow_valid_p
;
49 static Lisp_Object Qwindow_configuration_p
;
50 static Lisp_Object Qrecord_window_buffer
;
51 static Lisp_Object Qwindow_deletable_p
, Qdelete_window
, Qdisplay_buffer
;
52 static Lisp_Object Qreplace_buffer_in_windows
, Qget_mru_window
;
53 static Lisp_Object Qwindow_resize_root_window
, Qwindow_resize_root_window_vertically
;
54 static Lisp_Object Qwindow_pixel_to_total
;
55 static Lisp_Object Qscroll_up
, Qscroll_down
, Qscroll_command
;
56 static Lisp_Object Qsafe
, Qabove
, Qbelow
, Qwindow_size
, Qclone_of
;
57 static Lisp_Object Qfloor
, Qceiling
;
58 static Lisp_Object Qwindow_point_insertion_type
;
60 static int displayed_window_lines (struct window
*);
61 static int count_windows (struct window
*);
62 static int get_leaf_windows (struct window
*, struct window
**, int);
63 static void window_scroll (Lisp_Object
, EMACS_INT
, bool, int);
64 static void window_scroll_pixel_based (Lisp_Object
, int, bool, int);
65 static void window_scroll_line_based (Lisp_Object
, int, bool, int);
66 static int add_window_to_list (struct window
*, void *);
67 static Lisp_Object
next_window (Lisp_Object
, Lisp_Object
,
69 static void decode_next_window_args (Lisp_Object
*, Lisp_Object
*,
71 static void foreach_window (struct frame
*,
72 int (* fn
) (struct window
*, void *),
74 static int foreach_window_1 (struct window
*,
75 int (* fn
) (struct window
*, void *),
77 static Lisp_Object
window_list_1 (Lisp_Object
, Lisp_Object
, Lisp_Object
);
78 static int window_resize_check (struct window
*, bool);
79 static void window_resize_apply (struct window
*, bool);
80 static void window_resize_apply_total (struct window
*, bool);
81 static Lisp_Object
select_window (Lisp_Object
, Lisp_Object
, int);
82 static void select_window_1 (Lisp_Object
, bool);
84 static struct window
*set_window_fringes (struct window
*, Lisp_Object
,
85 Lisp_Object
, Lisp_Object
);
86 static struct window
*set_window_margins (struct window
*, Lisp_Object
,
88 static struct window
*set_window_scroll_bars (struct window
*, Lisp_Object
,
89 Lisp_Object
, Lisp_Object
);
90 static void apply_window_adjustment (struct window
*);
92 /* This is the window in which the terminal's cursor should
93 be left when nothing is being done with it. This must
94 always be a leaf window, and its buffer is selected by
95 the top level editing loop at the end of each command.
97 This value is always the same as
98 FRAME_SELECTED_WINDOW (selected_frame). */
99 Lisp_Object selected_window
;
101 /* A list of all windows for use by next_window and Fwindow_list.
102 Functions creating or deleting windows should invalidate this cache
103 by setting it to nil. */
104 Lisp_Object Vwindow_list
;
106 /* The mini-buffer window of the selected frame.
107 Note that you cannot test for mini-bufferness of an arbitrary window
108 by comparing against this; but you can test for mini-bufferness of
109 the selected window. */
110 Lisp_Object minibuf_window
;
112 /* Non-nil means it is the window whose mode line should be
113 shown as the selected window when the minibuffer is selected. */
114 Lisp_Object minibuf_selected_window
;
116 /* Hook run at end of temp_output_buffer_show. */
117 static Lisp_Object Qtemp_buffer_show_hook
;
119 /* Incremented for each window created. */
120 static int sequence_number
;
122 /* Nonzero after init_window_once has finished. */
123 static int window_initialized
;
125 /* Hook to run when window config changes. */
126 static Lisp_Object Qwindow_configuration_change_hook
;
128 /* Used by the function window_scroll_pixel_based. */
129 static int window_scroll_pixel_based_preserve_x
;
130 static int window_scroll_pixel_based_preserve_y
;
132 /* Same for window_scroll_line_based. */
133 static EMACS_INT window_scroll_preserve_hpos
;
134 static EMACS_INT window_scroll_preserve_vpos
;
137 CHECK_WINDOW_CONFIGURATION (Lisp_Object x
)
139 CHECK_TYPE (WINDOW_CONFIGURATIONP (x
), Qwindow_configuration_p
, x
);
142 /* These setters are used only in this file, so they can be private. */
144 wset_combination_limit (struct window
*w
, Lisp_Object val
)
146 w
->combination_limit
= val
;
149 wset_dedicated (struct window
*w
, Lisp_Object val
)
154 wset_display_table (struct window
*w
, Lisp_Object val
)
156 w
->display_table
= val
;
159 wset_new_normal (struct window
*w
, Lisp_Object val
)
164 wset_new_total (struct window
*w
, Lisp_Object val
)
169 wset_normal_cols (struct window
*w
, Lisp_Object val
)
171 w
->normal_cols
= val
;
174 wset_normal_lines (struct window
*w
, Lisp_Object val
)
176 w
->normal_lines
= val
;
179 wset_parent (struct window
*w
, Lisp_Object val
)
184 wset_pointm (struct window
*w
, Lisp_Object val
)
189 wset_start (struct window
*w
, Lisp_Object val
)
194 wset_temslot (struct window
*w
, Lisp_Object val
)
199 wset_vertical_scroll_bar_type (struct window
*w
, Lisp_Object val
)
201 w
->vertical_scroll_bar_type
= val
;
204 wset_window_parameters (struct window
*w
, Lisp_Object val
)
206 w
->window_parameters
= val
;
209 wset_combination (struct window
*w
, bool horflag
, Lisp_Object val
)
211 /* Since leaf windows never becomes non-leaf, there should
212 be no buffer and markers in start and pointm fields of W. */
213 eassert (!BUFFERP (w
->contents
) && NILP (w
->start
) && NILP (w
->pointm
));
215 /* When an internal window is deleted and VAL is nil, HORFLAG
218 w
->horizontal
= horflag
;
221 /* Nonzero if leaf window W doesn't reflect the actual state
222 of displayed buffer due to its text or overlays change. */
225 window_outdated (struct window
*w
)
227 struct buffer
*b
= XBUFFER (w
->contents
);
228 return (w
->last_modified
< BUF_MODIFF (b
)
229 || w
->last_overlay_modified
< BUF_OVERLAY_MODIFF (b
));
233 decode_live_window (register Lisp_Object window
)
236 return XWINDOW (selected_window
);
238 CHECK_LIVE_WINDOW (window
);
239 return XWINDOW (window
);
243 decode_any_window (register Lisp_Object window
)
248 return XWINDOW (selected_window
);
250 CHECK_WINDOW (window
);
251 w
= XWINDOW (window
);
255 static struct window
*
256 decode_valid_window (register Lisp_Object window
)
261 return XWINDOW (selected_window
);
263 CHECK_VALID_WINDOW (window
);
264 w
= XWINDOW (window
);
268 /* Called when W's buffer slot is changed. ARG -1 means that W is about to
269 cease its buffer, and 1 means that W is about to set up the new one. */
272 adjust_window_count (struct window
*w
, int arg
)
274 eassert (eabs (arg
) == 1);
275 if (BUFFERP (w
->contents
))
277 struct buffer
*b
= XBUFFER (w
->contents
);
281 b
->window_count
+= arg
;
282 eassert (b
->window_count
>= 0);
283 /* These should be recalculated by redisplay code. */
284 w
->window_end_valid
= 0;
285 w
->base_line_pos
= 0;
289 /* Set W's buffer slot to VAL and recompute number
290 of windows showing VAL if it is a buffer. */
293 wset_buffer (struct window
*w
, Lisp_Object val
)
295 adjust_window_count (w
, -1);
297 /* Make sure that we do not assign the buffer
298 to an internal window. */
299 eassert (MARKERP (w
->start
) && MARKERP (w
->pointm
));
301 adjust_window_count (w
, 1);
304 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
305 doc
: /* Return t if OBJECT is a window and nil otherwise. */)
308 return WINDOWP (object
) ? Qt
: Qnil
;
311 DEFUN ("window-valid-p", Fwindow_valid_p
, Swindow_valid_p
, 1, 1, 0,
312 doc
: /* Return t if OBJECT is a valid window and nil otherwise.
313 A valid window is either a window that displays a buffer or an internal
314 window. Windows that have been deleted are not valid. */)
317 return WINDOW_VALID_P (object
) ? Qt
: Qnil
;
320 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
321 doc
: /* Return t if OBJECT is a live window and nil otherwise.
322 A live window is a window that displays a buffer.
323 Internal windows and deleted windows are not live. */)
326 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
329 /* Frames and windows. */
330 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 0, 1, 0,
331 doc
: /* Return the frame that window WINDOW is on.
332 WINDOW must be a valid window and defaults to the selected one. */)
335 return decode_valid_window (window
)->frame
;
338 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
339 doc
: /* Return the root window of FRAME-OR-WINDOW.
340 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
341 With a frame argument, return that frame's root window.
342 With a window argument, return the root window of that window's frame. */)
343 (Lisp_Object frame_or_window
)
347 if (NILP (frame_or_window
))
348 window
= SELECTED_FRAME ()->root_window
;
349 else if (WINDOW_VALID_P (frame_or_window
))
350 window
= XFRAME (XWINDOW (frame_or_window
)->frame
)->root_window
;
353 CHECK_LIVE_FRAME (frame_or_window
);
354 window
= XFRAME (frame_or_window
)->root_window
;
360 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
361 doc
: /* Return the minibuffer window for frame FRAME.
362 If FRAME is omitted or nil, it defaults to the selected frame. */)
365 return FRAME_MINIBUF_WINDOW (decode_live_frame (frame
));
368 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
,
369 Swindow_minibuffer_p
, 0, 1, 0,
370 doc
: /* Return non-nil if WINDOW is a minibuffer window.
371 WINDOW must be a valid window and defaults to the selected one. */)
374 return MINI_WINDOW_P (decode_valid_window (window
)) ? Qt
: Qnil
;
377 /* Don't move this to window.el - this must be a safe routine. */
378 DEFUN ("frame-first-window", Fframe_first_window
, Sframe_first_window
, 0, 1, 0,
379 doc
: /* Return the topmost, leftmost live window on FRAME-OR-WINDOW.
380 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
381 Else if FRAME-OR-WINDOW denotes a valid window, return the first window
382 of that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
383 the first window of that frame. */)
384 (Lisp_Object frame_or_window
)
388 if (NILP (frame_or_window
))
389 window
= SELECTED_FRAME ()->root_window
;
390 else if (WINDOW_VALID_P (frame_or_window
))
391 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
394 CHECK_LIVE_FRAME (frame_or_window
);
395 window
= XFRAME (frame_or_window
)->root_window
;
398 while (WINDOWP (XWINDOW (window
)->contents
))
399 window
= XWINDOW (window
)->contents
;
404 DEFUN ("frame-selected-window", Fframe_selected_window
,
405 Sframe_selected_window
, 0, 1, 0,
406 doc
: /* Return the selected window of FRAME-OR-WINDOW.
407 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
408 Else if FRAME-OR-WINDOW denotes a valid window, return the selected
409 window of that window's frame. If FRAME-OR-WINDOW denotes a live frame,
410 return the selected window of that frame. */)
411 (Lisp_Object frame_or_window
)
415 if (NILP (frame_or_window
))
416 window
= SELECTED_FRAME ()->selected_window
;
417 else if (WINDOW_VALID_P (frame_or_window
))
418 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->selected_window
;
421 CHECK_LIVE_FRAME (frame_or_window
);
422 window
= XFRAME (frame_or_window
)->selected_window
;
428 DEFUN ("set-frame-selected-window", Fset_frame_selected_window
,
429 Sset_frame_selected_window
, 2, 3, 0,
430 doc
: /* Set selected window of FRAME to WINDOW.
431 FRAME must be a live frame and defaults to the selected one. If FRAME
432 is the selected frame, this makes WINDOW the selected window. Optional
433 argument NORECORD non-nil means to neither change the order of recently
434 selected windows nor the buffer list. WINDOW must denote a live window.
436 (Lisp_Object frame
, Lisp_Object window
, Lisp_Object norecord
)
439 frame
= selected_frame
;
441 CHECK_LIVE_FRAME (frame
);
442 CHECK_LIVE_WINDOW (window
);
444 if (! EQ (frame
, WINDOW_FRAME (XWINDOW (window
))))
445 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
447 if (EQ (frame
, selected_frame
))
448 return Fselect_window (window
, norecord
);
451 fset_selected_window (XFRAME (frame
), window
);
456 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
457 doc
: /* Return the selected window.
458 The selected window is the window in which the standard cursor for
459 selected windows appears and to which many commands apply. */)
462 return selected_window
;
465 int window_select_count
;
467 /* If select_window is called with inhibit_point_swap non-zero it will
468 not store point of the old selected window's buffer back into that
469 window's pointm slot. This is needed by Fset_window_configuration to
470 avoid that the display routine is called with selected_window set to
471 Qnil causing a subsequent crash. */
473 select_window (Lisp_Object window
, Lisp_Object norecord
, int inhibit_point_swap
)
475 register struct window
*w
;
478 CHECK_LIVE_WINDOW (window
);
480 w
= XWINDOW (window
);
482 /* Make the selected window's buffer current. */
483 Fset_buffer (w
->contents
);
485 if (EQ (window
, selected_window
) && !inhibit_point_swap
)
486 /* `switch-to-buffer' uses (select-window (selected-window)) as a "clever"
487 way to call record_buffer from Elisp, so it's important that we call
488 record_buffer before returning here. */
489 goto record_and_return
;
492 { /* Mark the window for redisplay since the selected-window has
493 a different mode-line. */
494 wset_redisplay (XWINDOW (selected_window
));
498 redisplay_other_windows ();
500 sf
= SELECTED_FRAME ();
501 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
503 fset_selected_window (XFRAME (WINDOW_FRAME (w
)), window
);
504 /* Use this rather than Fhandle_switch_frame
505 so that FRAME_FOCUS_FRAME is moved appropriately as we
506 move around in the state where a minibuffer in a separate
508 Fselect_frame (WINDOW_FRAME (w
), norecord
);
509 /* Fselect_frame called us back so we've done all the work already. */
510 eassert (EQ (window
, selected_window
));
514 fset_selected_window (sf
, window
);
516 select_window_1 (window
, inhibit_point_swap
);
517 bset_last_selected_window (XBUFFER (w
->contents
), window
);
520 /* record_buffer can run QUIT, so make sure it is run only after we have
521 re-established the invariant between selected_window and selected_frame,
522 otherwise the temporary broken invariant might "escape" (bug#14161). */
525 w
->use_time
= ++window_select_count
;
526 record_buffer (w
->contents
);
532 /* Select window with a minimum of fuss, i.e. don't record the change anywhere
533 (not even for redisplay's benefit), and assume that the window's frame is
536 select_window_1 (Lisp_Object window
, bool inhibit_point_swap
)
538 /* Store the old selected window's buffer's point in pointm of the old
539 selected window. It belongs to that window, and when the window is
540 not selected, must be in the window. */
541 if (!inhibit_point_swap
)
543 struct window
*ow
= XWINDOW (selected_window
);
544 if (BUFFERP (ow
->contents
))
545 set_marker_both (ow
->pointm
, ow
->contents
,
546 BUF_PT (XBUFFER (ow
->contents
)),
547 BUF_PT_BYTE (XBUFFER (ow
->contents
)));
550 selected_window
= window
;
552 /* Go to the point recorded in the window.
553 This is important when the buffer is in more
554 than one window. It also matters when
555 redisplay_window has altered point after scrolling,
556 because it makes the change only in the window. */
557 set_point_from_marker (XWINDOW (window
)->pointm
);
560 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
561 doc
: /* Select WINDOW which must be a live window.
562 Also make WINDOW's frame the selected frame and WINDOW that frame's
563 selected window. In addition, make WINDOW's buffer current and set its
564 buffer's value of `point' to the value of WINDOW's `window-point'.
567 Optional second arg NORECORD non-nil means do not put this buffer at the
568 front of the buffer list and do not make this window the most recently
571 Run `buffer-list-update-hook' unless NORECORD is non-nil. Note that
572 applications and internal routines often select a window temporarily for
573 various purposes; mostly, to simplify coding. As a rule, such
574 selections should be not recorded and therefore will not pollute
575 `buffer-list-update-hook'. Selections that "really count" are those
576 causing a visible change in the next redisplay of WINDOW's frame and
577 should be always recorded. So if you think of running a function each
578 time a window gets selected put it on `buffer-list-update-hook'.
580 Also note that the main editor command loop sets the current buffer to
581 the buffer of the selected window before each command. */)
582 (register Lisp_Object window
, Lisp_Object norecord
)
584 return select_window (window
, norecord
, 0);
587 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
588 doc
: /* Return the buffer displayed in window WINDOW.
589 If WINDOW is omitted or nil, it defaults to the selected window.
590 Return nil for an internal window or a deleted window. */)
593 struct window
*w
= decode_any_window (window
);
594 return WINDOW_LEAF_P (w
) ? w
->contents
: Qnil
;
597 DEFUN ("window-parent", Fwindow_parent
, Swindow_parent
, 0, 1, 0,
598 doc
: /* Return the parent window of window WINDOW.
599 WINDOW must be a valid window and defaults to the selected one.
600 Return nil for a window with no parent (e.g. a root window). */)
603 return decode_valid_window (window
)->parent
;
606 DEFUN ("window-top-child", Fwindow_top_child
, Swindow_top_child
, 0, 1, 0,
607 doc
: /* Return the topmost child window of window WINDOW.
608 WINDOW must be a valid window and defaults to the selected one.
609 Return nil if WINDOW is a live window (live windows have no children).
610 Return nil if WINDOW is an internal window whose children form a
611 horizontal combination. */)
614 struct window
*w
= decode_valid_window (window
);
615 return WINDOW_VERTICAL_COMBINATION_P (w
) ? w
->contents
: Qnil
;
618 DEFUN ("window-left-child", Fwindow_left_child
, Swindow_left_child
, 0, 1, 0,
619 doc
: /* Return the leftmost child window of window WINDOW.
620 WINDOW must be a valid window and defaults to the selected one.
621 Return nil if WINDOW is a live window (live windows have no children).
622 Return nil if WINDOW is an internal window whose children form a
623 vertical combination. */)
626 struct window
*w
= decode_valid_window (window
);
627 return WINDOW_HORIZONTAL_COMBINATION_P (w
) ? w
->contents
: Qnil
;
630 DEFUN ("window-next-sibling", Fwindow_next_sibling
, Swindow_next_sibling
, 0, 1, 0,
631 doc
: /* Return the next sibling window of window WINDOW.
632 WINDOW must be a valid window and defaults to the selected one.
633 Return nil if WINDOW has no next sibling. */)
636 return decode_valid_window (window
)->next
;
639 DEFUN ("window-prev-sibling", Fwindow_prev_sibling
, Swindow_prev_sibling
, 0, 1, 0,
640 doc
: /* Return the previous sibling window of window WINDOW.
641 WINDOW must be a valid window and defaults to the selected one.
642 Return nil if WINDOW has no previous sibling. */)
645 return decode_valid_window (window
)->prev
;
648 DEFUN ("window-combination-limit", Fwindow_combination_limit
, Swindow_combination_limit
, 1, 1, 0,
649 doc
: /* Return combination limit of window WINDOW.
650 WINDOW must be a valid window used in horizontal or vertical combination.
651 If the return value is nil, child windows of WINDOW can be recombined with
652 WINDOW's siblings. A return value of t means that child windows of
653 WINDOW are never \(re-)combined with WINDOW's siblings. */)
658 CHECK_VALID_WINDOW (window
);
659 w
= XWINDOW (window
);
660 if (WINDOW_LEAF_P (w
))
661 error ("Combination limit is meaningful for internal windows only");
662 return w
->combination_limit
;
665 DEFUN ("set-window-combination-limit", Fset_window_combination_limit
, Sset_window_combination_limit
, 2, 2, 0,
666 doc
: /* Set combination limit of window WINDOW to LIMIT; return LIMIT.
667 WINDOW must be a valid window used in horizontal or vertical combination.
668 If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's
669 siblings. LIMIT t means that child windows of WINDOW are never
670 \(re-)combined with WINDOW's siblings. Other values are reserved for
672 (Lisp_Object window
, Lisp_Object limit
)
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 wset_combination_limit (w
, limit
);
684 DEFUN ("window-use-time", Fwindow_use_time
, Swindow_use_time
, 0, 1, 0,
685 doc
: /* Return the use time of window WINDOW.
686 WINDOW must be a live window and defaults to the selected one.
687 The window with the highest use time is the most recently selected
688 one. The window with the lowest use time is the least recently
692 return make_number (decode_live_window (window
)->use_time
);
695 DEFUN ("window-pixel-width", Fwindow_pixel_width
, Swindow_pixel_width
, 0, 1, 0,
696 doc
: /* Return the width of window WINDOW in pixels.
697 WINDOW must be a valid window and defaults to the selected one.
699 The return value includes the fringes and margins of WINDOW as well as
700 any vertical dividers or scroll bars belonging to WINDOW. If WINDOW is
701 an internal window, its pixel width is the width of the screen areas
702 spanned by its children. */)
705 return make_number (decode_valid_window (window
)->pixel_width
);
708 DEFUN ("window-pixel-height", Fwindow_pixel_height
, Swindow_pixel_height
, 0, 1, 0,
709 doc
: /* Return the height of window WINDOW in pixels.
710 WINDOW must be a valid window and defaults to the selected one.
712 The return value includes the mode line and header line and the bottom
713 divider, if any. If WINDOW is an internal window, its pixel height is
714 the height of the screen areas spanned by its children. */)
717 return make_number (decode_valid_window (window
)->pixel_height
);
720 DEFUN ("window-total-height", Fwindow_total_height
, Swindow_total_height
, 0, 2, 0,
721 doc
: /* Return the height of window WINDOW in lines.
722 WINDOW must be a valid window and defaults to the selected one.
724 The return value includes the heights of WINDOW's mode and header line
725 and its bottom divider, if any. If WINDOW is an internal window, the
726 total height is the height of the screen areas spanned by its children.
728 If WINDOW's pixel height is not an integral multiple of its frame's
729 character height, the number of lines occupied by WINDOW is rounded
730 internally. This is done in a way such that, if WINDOW is a parent
731 window, the sum of the total heights of all its children internally
732 equals the total height of WINDOW.
734 If the optional argument ROUND is `ceiling', return the smallest integer
735 larger than WINDOW's pixel height divided by the character height of
736 WINDOW's frame. ROUND `floor' means to return the largest integer
737 smaller than WINDOW's pixel height divided by the character height of
738 WINDOW's frame. Any other value of ROUND means to return the internal
739 total height of WINDOW. */)
740 (Lisp_Object window
, Lisp_Object round
)
742 struct window
*w
= decode_valid_window (window
);
744 if (! EQ (round
, Qfloor
) && ! EQ (round
, Qceiling
))
745 return make_number (w
->total_lines
);
748 int unit
= FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
));
750 return make_number (EQ (round
, Qceiling
)
751 ? ((w
->pixel_height
+ unit
- 1) /unit
)
752 : (w
->pixel_height
/ unit
));
756 DEFUN ("window-total-width", Fwindow_total_width
, Swindow_total_width
, 0, 2, 0,
757 doc
: /* Return the total width of window WINDOW in columns.
758 WINDOW must be a valid window and defaults to the selected one.
760 The return value includes the widths of WINDOW's fringes, margins,
761 scroll bars and its right divider, if any. If WINDOW is an internal
762 window, the total width is the width of the screen areas spanned by its
765 If WINDOW's pixel width is not an integral multiple of its frame's
766 character width, the number of lines occupied by WINDOW is rounded
767 internally. This is done in a way such that, if WINDOW is a parent
768 window, the sum of the total widths of all its children internally
769 equals the total width of WINDOW.
771 If the optional argument ROUND is `ceiling', return the smallest integer
772 larger than WINDOW's pixel width divided by the character width of
773 WINDOW's frame. ROUND `floor' means to return the largest integer
774 smaller than WINDOW's pixel width divided by the character width of
775 WINDOW's frame. Any other value of ROUND means to return the internal
776 total width of WINDOW. */)
777 (Lisp_Object window
, Lisp_Object round
)
779 struct window
*w
= decode_valid_window (window
);
781 if (! EQ (round
, Qfloor
) && ! EQ (round
, Qceiling
))
782 return make_number (w
->total_cols
);
785 int unit
= FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
));
787 return make_number (EQ (round
, Qceiling
)
788 ? ((w
->pixel_width
+ unit
- 1) /unit
)
789 : (w
->pixel_width
/ unit
));
793 DEFUN ("window-new-total", Fwindow_new_total
, Swindow_new_total
, 0, 1, 0,
794 doc
: /* Return the new total size of window WINDOW.
795 WINDOW must be a valid window and defaults to the selected one.
797 The new total size of WINDOW is the value set by the last call of
798 `set-window-new-total' for WINDOW. If it is valid, it will be shortly
799 installed as WINDOW's total height (see `window-total-height') or total
800 width (see `window-total-width'). */)
803 return decode_valid_window (window
)->new_total
;
806 DEFUN ("window-normal-size", Fwindow_normal_size
, Swindow_normal_size
, 0, 2, 0,
807 doc
: /* Return the normal height of window WINDOW.
808 WINDOW must be a valid window and defaults to the selected one.
809 If HORIZONTAL is non-nil, return the normal width of WINDOW.
811 The normal height of a frame's root window or a window that is
812 horizontally combined (a window that has a left or right sibling) is
813 1.0. The normal height of a window that is vertically combined (has a
814 sibling above or below) is the fraction of the window's height with
815 respect to its parent. The sum of the normal heights of all windows in a
816 vertical combination equals 1.0.
818 Similarly, the normal width of a frame's root window or a window that is
819 vertically combined equals 1.0. The normal width of a window that is
820 horizontally combined is the fraction of the window's width with respect
821 to its parent. The sum of the normal widths of all windows in a
822 horizontal combination equals 1.0.
824 The normal sizes of windows are used to restore the proportional sizes
825 of windows after they have been shrunk to their minimum sizes; for
826 example when a frame is temporarily made very small and afterwards gets
827 re-enlarged to its previous size. */)
828 (Lisp_Object window
, Lisp_Object horizontal
)
830 struct window
*w
= decode_valid_window (window
);
832 return NILP (horizontal
) ? w
->normal_lines
: w
->normal_cols
;
835 DEFUN ("window-new-normal", Fwindow_new_normal
, Swindow_new_normal
, 0, 1, 0,
836 doc
: /* Return new normal size of window WINDOW.
837 WINDOW must be a valid window and defaults to the selected one.
839 The new normal size of WINDOW is the value set by the last call of
840 `set-window-new-normal' for WINDOW. If valid, it will be shortly
841 installed as WINDOW's normal size (see `window-normal-size'). */)
844 return decode_valid_window (window
)->new_normal
;
847 DEFUN ("window-new-pixel", Fwindow_new_pixel
, Swindow_new_pixel
, 0, 1, 0,
848 doc
: /* Return new pixel size of window WINDOW.
849 WINDOW must be a valid window and defaults to the selected one.
851 The new pixel size of WINDOW is the value set by the last call of
852 `set-window-new-pixel' for WINDOW. If it is valid, it will be shortly
853 installed as WINDOW's pixel height (see `window-pixel-height') or pixel
854 width (see `window-pixel-width'). */)
857 return decode_valid_window (window
)->new_pixel
;
860 DEFUN ("window-pixel-left", Fwindow_pixel_left
, Swindow_pixel_left
, 0, 1, 0,
861 doc
: /* Return left pixel edge of window WINDOW.
862 WINDOW must be a valid window and defaults to the selected one. */)
865 return make_number (decode_valid_window (window
)->pixel_left
);
868 DEFUN ("window-pixel-top", Fwindow_pixel_top
, Swindow_pixel_top
, 0, 1, 0,
869 doc
: /* Return top pixel edge of window WINDOW.
870 WINDOW must be a valid window and defaults to the selected one. */)
873 return make_number (decode_valid_window (window
)->pixel_top
);
876 DEFUN ("window-left-column", Fwindow_left_column
, Swindow_left_column
, 0, 1, 0,
877 doc
: /* Return left column of window WINDOW.
878 This is the distance, in columns, between the left edge of WINDOW and
879 the left edge of the frame's window area. For instance, the return
880 value is 0 if there is no window to the left of WINDOW.
882 WINDOW must be a valid window and defaults to the selected one. */)
885 return make_number (decode_valid_window (window
)->left_col
);
888 DEFUN ("window-top-line", Fwindow_top_line
, Swindow_top_line
, 0, 1, 0,
889 doc
: /* Return top line of window WINDOW.
890 This is the distance, in lines, between the top of WINDOW and the top
891 of the frame's window area. For instance, the return value is 0 if
892 there is no window above WINDOW.
894 WINDOW must be a valid window and defaults to the selected one. */)
897 return make_number (decode_valid_window (window
)->top_line
);
900 /* Return the number of lines/pixels of W's body. Don't count any mode
901 or header line or horizontal divider of W. Rounds down to nearest
902 integer when not working pixelwise. */
904 window_body_height (struct window
*w
, bool pixelwise
)
906 int height
= (w
->pixel_height
907 - WINDOW_HEADER_LINE_HEIGHT (w
)
908 - WINDOW_MODE_LINE_HEIGHT (w
)
909 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
));
911 /* Don't return a negative value. */
912 return max (pixelwise
914 : height
/ FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
)),
918 /* Return the number of columns/pixels of W's body. Don't count columns
919 occupied by the scroll bar or the divider/vertical bar separating W
920 from its right sibling or margins. On window-systems don't count
921 fringes either. Round down to nearest integer when not working
924 window_body_width (struct window
*w
, bool pixelwise
)
926 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
928 int width
= (w
->pixel_width
929 - WINDOW_RIGHT_DIVIDER_WIDTH (w
)
930 - (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
931 ? WINDOW_SCROLL_BAR_AREA_WIDTH (w
)
932 : ((!FRAME_WINDOW_P (f
)
933 && !WINDOW_RIGHTMOST_P (w
)
934 && !WINDOW_RIGHT_DIVIDER_WIDTH (w
))
935 /* A vertical bar is either 1 or 0. */
937 - WINDOW_MARGINS_WIDTH (w
)
938 - (FRAME_WINDOW_P (f
)
939 ? WINDOW_FRINGES_WIDTH (w
)
942 /* Don't return a negative value. */
943 return max (pixelwise
945 : width
/ FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
)),
949 DEFUN ("window-body-height", Fwindow_body_height
, Swindow_body_height
, 0, 2, 0,
950 doc
: /* Return the height of WINDOW's text area.
951 WINDOW must be a live window and defaults to the selected one. Optional
952 argument PIXELWISE non-nil means return the height of WINDOW's text area
953 in pixels. The return value does not include the mode line or header
954 line or any horizontal divider.
956 If PIXELWISE is nil, return the largest integer smaller than WINDOW's
957 pixel height divided by the character height of WINDOW's frame. This
958 means that if a line at the bottom of the text area is only partially
959 visible, that line is not counted. */)
960 (Lisp_Object window
, Lisp_Object pixelwise
)
962 return make_number (window_body_height (decode_live_window (window
),
963 NILP (pixelwise
) ? 0 : 1));
966 DEFUN ("window-body-width", Fwindow_body_width
, Swindow_body_width
, 0, 2, 0,
967 doc
: /* Return the width of WINDOW's text area.
968 WINDOW must be a live window and defaults to the selected one. Optional
969 argument PIXELWISE non-nil means return the width in pixels. The return
970 value does not include any vertical dividers, fringes or marginal areas,
973 If PIXELWISE is nil, return the largest integer smaller than WINDOW's
974 pixel width divided by the character width of WINDOW's frame. This
975 means that if a column at the right of the text area is only partially
976 visible, that column is not counted. */)
977 (Lisp_Object window
, Lisp_Object pixelwise
)
979 return make_number (window_body_width (decode_live_window (window
),
980 NILP (pixelwise
) ? 0 : 1));
983 DEFUN ("window-mode-line-height", Fwindow_mode_line_height
,
984 Swindow_mode_line_height
, 0, 1, 0,
985 doc
: /* Return the height in pixels of WINDOW's mode-line.
986 WINDOW must be a live window and defaults to the selected one. */)
989 return (make_number (WINDOW_MODE_LINE_HEIGHT (decode_live_window (window
))));
992 DEFUN ("window-header-line-height", Fwindow_header_line_height
,
993 Swindow_header_line_height
, 0, 1, 0,
994 doc
: /* Return the height in pixels of WINDOW's header-line.
995 WINDOW must be a live window and defaults to the selected one. */)
998 return (make_number (WINDOW_HEADER_LINE_HEIGHT (decode_live_window (window
))));
1001 DEFUN ("window-right-divider-width", Fwindow_right_divider_width
,
1002 Swindow_right_divider_width
, 0, 1, 0,
1003 doc
: /* Return the width in pixels of WINDOW's right divider.
1004 WINDOW must be a live window and defaults to the selected one. */)
1005 (Lisp_Object window
)
1007 return (make_number (WINDOW_RIGHT_DIVIDER_WIDTH (decode_live_window (window
))));
1010 DEFUN ("window-bottom-divider-width", Fwindow_bottom_divider_width
,
1011 Swindow_bottom_divider_width
, 0, 1, 0,
1012 doc
: /* Return the width in pixels of WINDOW's bottom divider.
1013 WINDOW must be a live window and defaults to the selected one. */)
1014 (Lisp_Object window
)
1016 return (make_number (WINDOW_BOTTOM_DIVIDER_WIDTH (decode_live_window (window
))));
1019 DEFUN ("window-scroll-bar-width", Fwindow_scroll_bar_width
,
1020 Swindow_scroll_bar_width
, 0, 1, 0,
1021 doc
: /* Return the width in pixels of WINDOW's vertical scrollbar.
1022 WINDOW must be a live window and defaults to the selected one. */)
1023 (Lisp_Object window
)
1025 return (make_number (WINDOW_SCROLL_BAR_AREA_WIDTH (decode_live_window (window
))));
1028 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
1029 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
1030 WINDOW must be a live window and defaults to the selected one. */)
1031 (Lisp_Object window
)
1033 return make_number (decode_live_window (window
)->hscroll
);
1036 /* Set W's horizontal scroll amount to HSCROLL clipped to a reasonable
1037 range, returning the new amount as a fixnum. */
1039 set_window_hscroll (struct window
*w
, EMACS_INT hscroll
)
1041 /* Horizontal scrolling has problems with large scroll amounts.
1042 It's too slow with long lines, and even with small lines the
1043 display can be messed up. For now, though, impose only the limits
1044 required by the internal representation: horizontal scrolling must
1045 fit in fixnum (since it's visible to Elisp) and into ptrdiff_t
1046 (since it's stored in a ptrdiff_t). */
1047 ptrdiff_t hscroll_max
= min (MOST_POSITIVE_FIXNUM
, PTRDIFF_MAX
);
1048 ptrdiff_t new_hscroll
= clip_to_bounds (0, hscroll
, hscroll_max
);
1050 /* Prevent redisplay shortcuts when changing the hscroll. */
1051 if (w
->hscroll
!= new_hscroll
)
1052 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
1054 w
->hscroll
= new_hscroll
;
1055 return make_number (new_hscroll
);
1058 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
1059 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
1060 WINDOW must be a live window and defaults to the selected one.
1061 Clip the number to a reasonable value if out of range.
1062 Return the new number. NCOL should be zero or positive.
1064 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
1065 window so that the location of point moves off-window. */)
1066 (Lisp_Object window
, Lisp_Object ncol
)
1068 CHECK_NUMBER (ncol
);
1069 return set_window_hscroll (decode_live_window (window
), XINT (ncol
));
1072 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
1073 Swindow_redisplay_end_trigger
, 0, 1, 0,
1074 doc
: /* Return WINDOW's redisplay end trigger value.
1075 WINDOW must be a live window and defaults to the selected one.
1076 See `set-window-redisplay-end-trigger' for more information. */)
1077 (Lisp_Object window
)
1079 return decode_live_window (window
)->redisplay_end_trigger
;
1082 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
1083 Sset_window_redisplay_end_trigger
, 2, 2, 0,
1084 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
1085 WINDOW must be a live window and defaults to the selected one. VALUE
1086 should be a buffer position (typically a marker) or nil. If it is a
1087 buffer position, then if redisplay in WINDOW reaches a position beyond
1088 VALUE, the functions in `redisplay-end-trigger-functions' are called
1089 with two arguments: WINDOW, and the end trigger value. Afterwards the
1090 end-trigger value is reset to nil. */)
1091 (register Lisp_Object window
, Lisp_Object value
)
1093 wset_redisplay_end_trigger (decode_live_window (window
), value
);
1097 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
1098 doc
: /* Return a list of the edge coordinates of WINDOW.
1099 WINDOW must be a valid window and defaults to the selected one.
1101 The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
1102 count by lines, and LEFT and RIGHT count by columns, all relative to 0,
1103 0 at top left corner of frame.
1105 RIGHT is one more than the rightmost column occupied by WINDOW. BOTTOM
1106 is one more than the bottommost row occupied by WINDOW. The edges
1107 include the space used by WINDOW's scroll bar, display margins, fringes,
1108 header line, and/or mode line. For the edges of just the text area, use
1109 `window-inside-edges'. */)
1110 (Lisp_Object window
)
1112 register struct window
*w
= decode_valid_window (window
);
1114 return list4i (WINDOW_LEFT_EDGE_COL (w
), WINDOW_TOP_EDGE_LINE (w
),
1115 WINDOW_RIGHT_EDGE_COL (w
), WINDOW_BOTTOM_EDGE_LINE (w
));
1118 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
1119 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
1120 WINDOW must be a valid window and defaults to the selected one.
1122 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1123 0, 0 at the top left corner of the frame.
1125 RIGHT is one more than the rightmost x position occupied by WINDOW.
1126 BOTTOM is one more than the bottommost y position occupied by WINDOW.
1127 The pixel edges include the space used by WINDOW's scroll bar, display
1128 margins, fringes, header line, and/or mode line. For the pixel edges
1129 of just the text area, use `window-inside-pixel-edges'. */)
1130 (Lisp_Object window
)
1132 register struct window
*w
= decode_valid_window (window
);
1134 return list4i (WINDOW_LEFT_EDGE_X (w
), WINDOW_TOP_EDGE_Y (w
),
1135 WINDOW_RIGHT_EDGE_X (w
), WINDOW_BOTTOM_EDGE_Y (w
));
1139 calc_absolute_offset (struct window
*w
, int *add_x
, int *add_y
)
1141 struct frame
*f
= XFRAME (w
->frame
);
1142 *add_y
= f
->top_pos
;
1143 #ifdef FRAME_MENUBAR_HEIGHT
1144 *add_y
+= FRAME_MENUBAR_HEIGHT (f
);
1146 #ifdef FRAME_TOOLBAR_TOP_HEIGHT
1147 *add_y
+= FRAME_TOOLBAR_TOP_HEIGHT (f
);
1148 #elif defined (FRAME_TOOLBAR_HEIGHT)
1149 *add_y
+= FRAME_TOOLBAR_HEIGHT (f
);
1151 #ifdef FRAME_NS_TITLEBAR_HEIGHT
1152 *add_y
+= FRAME_NS_TITLEBAR_HEIGHT (f
);
1154 *add_x
= f
->left_pos
;
1155 #ifdef FRAME_TOOLBAR_LEFT_WIDTH
1156 *add_x
+= FRAME_TOOLBAR_LEFT_WIDTH (f
);
1160 DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges
,
1161 Swindow_absolute_pixel_edges
, 0, 1, 0,
1162 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
1163 WINDOW must be a valid window and defaults to the selected one.
1165 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1166 0, 0 at the top left corner of the display.
1168 RIGHT is one more than the rightmost x position occupied by WINDOW.
1169 BOTTOM is one more than the bottommost y position occupied by WINDOW.
1170 The pixel edges include the space used by WINDOW's scroll bar, display
1171 margins, fringes, header line, and/or mode line. For the pixel edges
1172 of just the text area, use `window-inside-absolute-pixel-edges'. */)
1173 (Lisp_Object window
)
1175 register struct window
*w
= decode_valid_window (window
);
1178 calc_absolute_offset (w
, &add_x
, &add_y
);
1180 return list4i (WINDOW_LEFT_EDGE_X (w
) + add_x
,
1181 WINDOW_TOP_EDGE_Y (w
) + add_y
,
1182 WINDOW_RIGHT_EDGE_X (w
) + add_x
,
1183 WINDOW_BOTTOM_EDGE_Y (w
) + add_y
);
1186 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
1187 doc
: /* Return a list of the edge coordinates of WINDOW.
1188 WINDOW must be a live window and defaults to the selected one.
1190 The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
1191 count by lines, and LEFT and RIGHT count by columns, all relative to 0,
1192 0 at top left corner of frame.
1194 RIGHT is one more than the rightmost column of WINDOW's text area.
1195 BOTTOM is one more than the bottommost row of WINDOW's text area. The
1196 inside edges do not include the space used by the WINDOW's scroll bar,
1197 display margins, fringes, header line, and/or mode line. */)
1198 (Lisp_Object window
)
1200 register struct window
*w
= decode_live_window (window
);
1202 return list4i ((WINDOW_BOX_LEFT_EDGE_COL (w
)
1203 + WINDOW_LEFT_MARGIN_COLS (w
)
1204 + WINDOW_LEFT_FRINGE_COLS (w
)),
1205 (WINDOW_TOP_EDGE_LINE (w
)
1206 + WINDOW_HEADER_LINE_LINES (w
)),
1207 (WINDOW_BOX_RIGHT_EDGE_COL (w
)
1208 - WINDOW_RIGHT_MARGIN_COLS (w
)
1209 - WINDOW_RIGHT_FRINGE_COLS (w
)),
1210 (WINDOW_BOTTOM_EDGE_LINE (w
)
1211 - WINDOW_MODE_LINE_LINES (w
)));
1214 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
1215 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1216 WINDOW must be a live window and defaults to the selected one.
1218 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1219 (0,0) at the top left corner of the frame's window area.
1221 RIGHT is one more than the rightmost x position of WINDOW's text area.
1222 BOTTOM is one more than the bottommost y position of WINDOW's text area.
1223 The inside edges do not include the space used by WINDOW's scroll bar,
1224 display margins, fringes, header line, and/or mode line. */)
1225 (Lisp_Object window
)
1227 register struct window
*w
= decode_live_window (window
);
1229 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w
)
1230 + WINDOW_LEFT_MARGIN_WIDTH (w
)
1231 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
1232 (WINDOW_TOP_EDGE_Y (w
)
1233 + WINDOW_HEADER_LINE_HEIGHT (w
)),
1234 (WINDOW_BOX_RIGHT_EDGE_X (w
)
1235 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
1236 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
1237 (WINDOW_BOTTOM_EDGE_Y (w
)
1238 - WINDOW_MODE_LINE_HEIGHT (w
)));
1241 DEFUN ("window-inside-absolute-pixel-edges",
1242 Fwindow_inside_absolute_pixel_edges
,
1243 Swindow_inside_absolute_pixel_edges
, 0, 1, 0,
1244 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1245 WINDOW must be a live window and defaults to the selected one.
1247 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1248 (0,0) at the top left corner of the frame's window area.
1250 RIGHT is one more than the rightmost x position of WINDOW's text area.
1251 BOTTOM is one more than the bottommost y position of WINDOW's text area.
1252 The inside edges do not include the space used by WINDOW's scroll bar,
1253 display margins, fringes, header line, and/or mode line. */)
1254 (Lisp_Object window
)
1256 register struct window
*w
= decode_live_window (window
);
1259 calc_absolute_offset (w
, &add_x
, &add_y
);
1261 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w
)
1262 + WINDOW_LEFT_MARGIN_WIDTH (w
)
1263 + WINDOW_LEFT_FRINGE_WIDTH (w
) + add_x
),
1264 (WINDOW_TOP_EDGE_Y (w
)
1265 + WINDOW_HEADER_LINE_HEIGHT (w
) + add_y
),
1266 (WINDOW_BOX_RIGHT_EDGE_X (w
)
1267 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
1268 - WINDOW_RIGHT_FRINGE_WIDTH (w
) + add_x
),
1269 (WINDOW_BOTTOM_EDGE_Y (w
)
1270 - WINDOW_MODE_LINE_HEIGHT (w
) + add_y
));
1273 /* Test if the character at column X, row Y is within window W.
1274 If it is not, return ON_NOTHING;
1275 if it is on the window's vertical divider, return
1277 if it is on the window's horizontal divider, return
1279 if it is in the window's text area, return ON_TEXT;
1280 if it is on the window's modeline, return ON_MODE_LINE;
1281 if it is on the border between the window and its right sibling,
1282 return ON_VERTICAL_BORDER;
1283 if it is on a scroll bar, return ON_SCROLL_BAR;
1284 if it is on the window's top line, return ON_HEADER_LINE;
1285 if it is in left or right fringe of the window,
1286 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
1287 if it is in the marginal area to the left/right of the window,
1288 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN.
1290 X and Y are frame relative pixel coordinates. */
1292 static enum window_part
1293 coordinates_in_window (register struct window
*w
, int x
, int y
)
1295 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1296 enum window_part part
;
1297 int ux
= FRAME_COLUMN_WIDTH (f
);
1298 int left_x
= WINDOW_LEFT_EDGE_X (w
);
1299 int right_x
= WINDOW_RIGHT_EDGE_X (w
);
1300 int top_y
= WINDOW_TOP_EDGE_Y (w
);
1301 int bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
1302 /* The width of the area where the vertical line can be dragged.
1303 (Between mode lines for instance. */
1304 int grabbable_width
= ux
;
1305 int lmargin_width
, rmargin_width
, text_left
, text_right
;
1307 /* Outside any interesting row or column? */
1308 if (y
< top_y
|| y
>= bottom_y
|| x
< left_x
|| x
>= right_x
)
1311 /* On the horizontal window divider (which prevails the vertical
1313 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
) > 0
1314 && y
>= (bottom_y
- WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
1316 return ON_BOTTOM_DIVIDER
;
1317 /* On vertical window divider? */
1318 else if (!WINDOW_RIGHTMOST_P (w
)
1319 && WINDOW_RIGHT_DIVIDER_WIDTH (w
) > 0
1320 && x
>= right_x
- WINDOW_RIGHT_DIVIDER_WIDTH (w
)
1322 return ON_RIGHT_DIVIDER
;
1323 /* On the mode or header line? */
1324 else if ((WINDOW_WANTS_MODELINE_P (w
)
1326 - CURRENT_MODE_LINE_HEIGHT (w
)
1327 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
1328 && y
<= bottom_y
- WINDOW_BOTTOM_DIVIDER_WIDTH (w
)
1329 && (part
= ON_MODE_LINE
))
1330 || (WINDOW_WANTS_HEADER_LINE_P (w
)
1331 && y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
)
1332 && (part
= ON_HEADER_LINE
)))
1334 /* If it's under/over the scroll bar portion of the mode/header
1335 line, say it's on the vertical line. That's to be able to
1336 resize windows horizontally in case we're using toolkit scroll
1337 bars. Note: If scrollbars are on the left, the window that
1338 must be eventually resized is that on the left of WINDOW. */
1339 if ((WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0)
1340 && ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1341 && !WINDOW_LEFTMOST_P (w
)
1342 && eabs (x
- left_x
) < grabbable_width
)
1343 || (!WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1344 && !WINDOW_RIGHTMOST_P (w
)
1345 && eabs (x
- right_x
) < grabbable_width
)))
1346 return ON_VERTICAL_BORDER
;
1351 /* In what's below, we subtract 1 when computing right_x because we
1352 want the rightmost pixel, which is given by left_pixel+width-1. */
1353 if (w
->pseudo_window_p
)
1356 right_x
= WINDOW_PIXEL_WIDTH (w
) - 1;
1360 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
1361 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
1364 /* Outside any interesting column? */
1365 if (x
< left_x
|| x
> right_x
)
1366 return ON_SCROLL_BAR
;
1368 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
1369 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
1371 text_left
= window_box_left (w
, TEXT_AREA
);
1372 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
1374 if (FRAME_WINDOW_P (f
))
1376 if (!w
->pseudo_window_p
1377 && WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0
1378 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
1379 && !WINDOW_RIGHTMOST_P (w
)
1380 && (eabs (x
- right_x
) < grabbable_width
))
1381 return ON_VERTICAL_BORDER
;
1383 /* Need to say "x > right_x" rather than >=, since on character
1384 terminals, the vertical line's x coordinate is right_x. */
1385 else if (!w
->pseudo_window_p
1386 && WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0
1387 && !WINDOW_RIGHTMOST_P (w
)
1388 /* Why check ux if we are not the rightmost window? Also
1389 shouldn't a pseudo window always be rightmost? */
1390 && x
> right_x
- ux
)
1391 return ON_VERTICAL_BORDER
;
1395 if (lmargin_width
> 0
1396 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1397 ? (x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
1398 : (x
< left_x
+ lmargin_width
)))
1399 return ON_LEFT_MARGIN
;
1401 return ON_LEFT_FRINGE
;
1404 if (x
>= text_right
)
1406 if (rmargin_width
> 0
1407 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1408 ? (x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
1409 : (x
>= right_x
- rmargin_width
)))
1410 return ON_RIGHT_MARGIN
;
1412 return ON_RIGHT_FRINGE
;
1415 /* Everything special ruled out - must be on text area */
1419 /* Take X is the frame-relative pixel x-coordinate, and return the
1420 x-coordinate relative to part PART of window W. */
1422 window_relative_x_coord (struct window
*w
, enum window_part part
, int x
)
1424 int left_x
= (w
->pseudo_window_p
) ? 0 : WINDOW_BOX_LEFT_EDGE_X (w
);
1429 return x
- window_box_left (w
, TEXT_AREA
);
1431 case ON_HEADER_LINE
:
1433 case ON_LEFT_FRINGE
:
1436 case ON_RIGHT_FRINGE
:
1437 return x
- left_x
- WINDOW_LEFT_FRINGE_WIDTH (w
);
1439 case ON_LEFT_MARGIN
:
1441 - ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1442 ? WINDOW_LEFT_FRINGE_WIDTH (w
) : 0));
1444 case ON_RIGHT_MARGIN
:
1446 - ((w
->pseudo_window_p
)
1447 ? WINDOW_PIXEL_WIDTH (w
)
1448 : WINDOW_BOX_RIGHT_EDGE_X (w
))
1449 + window_box_width (w
, RIGHT_MARGIN_AREA
)
1450 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1451 ? WINDOW_RIGHT_FRINGE_WIDTH (w
) : 0));
1454 /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */
1459 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
1460 Scoordinates_in_window_p
, 2, 2, 0,
1461 doc
: /* Return non-nil if COORDINATES are in WINDOW.
1462 WINDOW must be a live window and defaults to the selected one.
1463 COORDINATES is a cons of the form (X . Y), X and Y being distances
1464 measured in characters from the upper-left corner of the frame.
1465 \(0 . 0) denotes the character in the upper left corner of the
1467 If COORDINATES are in the text portion of WINDOW,
1468 the coordinates relative to the window are returned.
1469 If they are in the bottom divider of WINDOW, `bottom-divider' is returned.
1470 If they are in the right divider of WINDOW, `right-divider' is returned.
1471 If they are in the mode line of WINDOW, `mode-line' is returned.
1472 If they are in the header line of WINDOW, `header-line' is returned.
1473 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1474 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1475 If they are on the border between WINDOW and its right sibling,
1476 `vertical-line' is returned.
1477 If they are in the windows's left or right marginal areas, `left-margin'\n\
1478 or `right-margin' is returned. */)
1479 (register Lisp_Object coordinates
, Lisp_Object window
)
1486 w
= decode_live_window (window
);
1487 f
= XFRAME (w
->frame
);
1488 CHECK_CONS (coordinates
);
1489 lx
= Fcar (coordinates
);
1490 ly
= Fcdr (coordinates
);
1491 CHECK_NUMBER_OR_FLOAT (lx
);
1492 CHECK_NUMBER_OR_FLOAT (ly
);
1493 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1494 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1496 switch (coordinates_in_window (w
, x
, y
))
1502 /* Convert X and Y to window relative pixel coordinates, and
1503 return the canonical char units. */
1504 x
-= window_box_left (w
, TEXT_AREA
);
1505 y
-= WINDOW_TOP_EDGE_Y (w
);
1506 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
1507 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
1512 case ON_VERTICAL_BORDER
:
1513 return Qvertical_line
;
1515 case ON_HEADER_LINE
:
1516 return Qheader_line
;
1518 case ON_LEFT_FRINGE
:
1519 return Qleft_fringe
;
1521 case ON_RIGHT_FRINGE
:
1522 return Qright_fringe
;
1524 case ON_LEFT_MARGIN
:
1525 return Qleft_margin
;
1527 case ON_RIGHT_MARGIN
:
1528 return Qright_margin
;
1531 /* Historically we are supposed to return nil in this case. */
1534 case ON_RIGHT_DIVIDER
:
1535 return Qright_divider
;
1537 case ON_BOTTOM_DIVIDER
:
1538 return Qbottom_divider
;
1546 /* Callback for foreach_window, used in window_from_coordinates.
1547 Check if window W contains coordinates specified by USER_DATA which
1548 is actually a pointer to a struct check_window_data CW.
1550 Check if window W contains coordinates *CW->x and *CW->y. If it
1551 does, return W in *CW->window, as Lisp_Object, and return in
1552 *CW->part the part of the window under coordinates *X,*Y. Return
1553 zero from this function to stop iterating over windows. */
1555 struct check_window_data
1557 Lisp_Object
*window
;
1559 enum window_part
*part
;
1563 check_window_containing (struct window
*w
, void *user_data
)
1565 struct check_window_data
*cw
= user_data
;
1566 enum window_part found
;
1569 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1570 if (found
!= ON_NOTHING
)
1573 XSETWINDOW (*cw
->window
, w
);
1581 /* Find the window containing frame-relative pixel position X/Y and
1582 return it as a Lisp_Object.
1584 If X, Y is on one of the window's special `window_part' elements,
1585 set *PART to the id of that element.
1587 If there is no window under X, Y return nil and leave *PART
1588 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1590 This function was previously implemented with a loop cycling over
1591 windows with Fnext_window, and starting with the frame's selected
1592 window. It turned out that this doesn't work with an
1593 implementation of next_window using Vwindow_list, because
1594 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1595 tree of F when this function is called asynchronously from
1596 note_mouse_highlight. The original loop didn't terminate in this
1600 window_from_coordinates (struct frame
*f
, int x
, int y
,
1601 enum window_part
*part
, bool tool_bar_p
)
1604 struct check_window_data cw
;
1605 enum window_part dummy
;
1611 cw
.window
= &window
, cw
.x
= x
, cw
.y
= y
; cw
.part
= part
;
1612 foreach_window (f
, check_window_containing
, &cw
);
1614 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
1615 /* If not found above, see if it's in the tool bar window, if a tool
1619 && WINDOWP (f
->tool_bar_window
)
1620 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1621 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), x
, y
)
1625 window
= f
->tool_bar_window
;
1632 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1633 doc
: /* Return window containing coordinates X and Y on FRAME.
1634 FRAME must be a live frame and defaults to the selected one.
1635 The top left corner of the frame is considered to be row 0,
1637 (Lisp_Object x
, Lisp_Object y
, Lisp_Object frame
)
1639 struct frame
*f
= decode_live_frame (frame
);
1641 /* Check that arguments are integers or floats. */
1642 CHECK_NUMBER_OR_FLOAT (x
);
1643 CHECK_NUMBER_OR_FLOAT (y
);
1645 return window_from_coordinates (f
,
1646 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1647 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1648 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1649 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1653 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1654 doc
: /* Return current value of point in WINDOW.
1655 WINDOW must be a live window and defaults to the selected one.
1657 For a nonselected window, this is the value point would have if that
1658 window were selected.
1660 Note that, when WINDOW is selected, the value returned is the same as
1661 that returned by `point' for WINDOW's buffer. It would be more strictly
1662 correct to return the top-level value of `point', outside of any
1663 `save-excursion' forms. But that is hard to define. */)
1664 (Lisp_Object window
)
1666 register struct window
*w
= decode_live_window (window
);
1668 if (w
== XWINDOW (selected_window
))
1669 return make_number (BUF_PT (XBUFFER (w
->contents
)));
1671 return Fmarker_position (w
->pointm
);
1674 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1675 doc
: /* Return position at which display currently starts in WINDOW.
1676 WINDOW must be a live window and defaults to the selected one.
1677 This is updated by redisplay or by calling `set-window-start'. */)
1678 (Lisp_Object window
)
1680 return Fmarker_position (decode_live_window (window
)->start
);
1683 /* This is text temporarily removed from the doc string below.
1685 This function returns nil if the position is not currently known.
1686 That happens when redisplay is preempted and doesn't finish.
1687 If in that case you want to compute where the end of the window would
1688 have been if redisplay had finished, do this:
1690 (goto-char (window-start window))
1691 (vertical-motion (1- (window-height window)) window)
1694 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1695 doc
: /* Return position at which display currently ends in WINDOW.
1696 WINDOW must be a live window and defaults to the selected one.
1697 This is updated by redisplay, when it runs to completion.
1698 Simply changing the buffer text or setting `window-start'
1699 does not update this value.
1700 Return nil if there is no recorded value. (This can happen if the
1701 last redisplay of WINDOW was preempted, and did not finish.)
1702 If UPDATE is non-nil, compute the up-to-date position
1703 if it isn't already recorded. */)
1704 (Lisp_Object window
, Lisp_Object update
)
1707 struct window
*w
= decode_live_window (window
);
1716 && (windows_or_buffers_changed
1717 || !w
->window_end_valid
1719 || b
->prevent_redisplay_optimizations_p
1720 || window_outdated (w
))
1723 struct text_pos startp
;
1725 struct buffer
*old_buffer
= NULL
;
1726 void *itdata
= NULL
;
1728 /* Cannot use Fvertical_motion because that function doesn't
1729 cope with variable-height lines. */
1730 if (b
!= current_buffer
)
1732 old_buffer
= current_buffer
;
1733 set_buffer_internal (b
);
1736 /* In case W->start is out of the range, use something
1737 reasonable. This situation occurred when loading a file with
1738 `-l' containing a call to `rmail' with subsequent other
1739 commands. At the end, W->start happened to be BEG, while
1740 rmail had already narrowed the buffer. */
1741 CLIP_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1743 itdata
= bidi_shelve_cache ();
1744 start_display (&it
, w
, startp
);
1745 move_it_vertically (&it
, window_box_height (w
));
1746 if (it
.current_y
< it
.last_visible_y
)
1747 move_it_past_eol (&it
);
1748 value
= make_number (IT_CHARPOS (it
));
1749 bidi_unshelve_cache (itdata
, 0);
1752 set_buffer_internal (old_buffer
);
1755 XSETINT (value
, BUF_Z (b
) - w
->window_end_pos
);
1760 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1761 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1762 WINDOW must be a live window and defaults to the selected one.
1764 (Lisp_Object window
, Lisp_Object pos
)
1766 register struct window
*w
= decode_live_window (window
);
1768 /* Type of POS is checked by Fgoto_char or set_marker_restricted ... */
1770 if (w
== XWINDOW (selected_window
))
1772 if (XBUFFER (w
->contents
) == current_buffer
)
1776 struct buffer
*old_buffer
= current_buffer
;
1778 /* ... but here we want to catch type error before buffer change. */
1779 CHECK_NUMBER_COERCE_MARKER (pos
);
1780 set_buffer_internal (XBUFFER (w
->contents
));
1782 set_buffer_internal (old_buffer
);
1787 set_marker_restricted (w
->pointm
, pos
, w
->contents
);
1788 /* We have to make sure that redisplay updates the window to show
1789 the new value of point. */
1796 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1797 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1798 WINDOW must be a live window and defaults to the selected one. Return
1799 POS. Optional third arg NOFORCE non-nil inhibits next redisplay from
1800 overriding motion of point in order to display at this exact start. */)
1801 (Lisp_Object window
, Lisp_Object pos
, Lisp_Object noforce
)
1803 register struct window
*w
= decode_live_window (window
);
1805 set_marker_restricted (w
->start
, pos
, w
->contents
);
1806 /* This is not right, but much easier than doing what is right. */
1807 w
->start_at_line_beg
= 0;
1810 w
->update_mode_line
= 1;
1812 w
->window_end_valid
= 0;
1818 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
1819 Spos_visible_in_window_p
, 0, 3, 0,
1820 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
1821 WINDOW must be a live window and defaults to the selected one.
1823 Return nil if that position is scrolled vertically out of view. If a
1824 character is only partially visible, nil is returned, unless the
1825 optional argument PARTIALLY is non-nil. If POS is only out of view
1826 because of horizontal scrolling, return non-nil. If POS is t, it
1827 specifies the position of the last visible glyph in WINDOW. POS
1828 defaults to point in WINDOW; WINDOW defaults to the selected window.
1830 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1831 the return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
1832 where X and Y are the pixel coordinates relative to the top left corner
1833 of the window. The remaining elements are omitted if the character after
1834 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1835 off-window at the top and bottom of the screen line ("row") containing
1836 POS, ROWH is the visible height of that row, and VPOS is the row number
1838 (Lisp_Object pos
, Lisp_Object window
, Lisp_Object partially
)
1840 register struct window
*w
;
1841 register EMACS_INT posint
;
1842 register struct buffer
*buf
;
1843 struct text_pos top
;
1844 Lisp_Object in_window
= Qnil
;
1845 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
1848 w
= decode_live_window (window
);
1849 buf
= XBUFFER (w
->contents
);
1850 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1854 else if (!NILP (pos
))
1856 CHECK_NUMBER_COERCE_MARKER (pos
);
1857 posint
= XINT (pos
);
1859 else if (w
== XWINDOW (selected_window
))
1862 posint
= marker_position (w
->pointm
);
1864 /* If position is above window start or outside buffer boundaries,
1865 or if window start is out of range, position is not visible. */
1867 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
1868 && CHARPOS (top
) >= BUF_BEGV (buf
)
1869 && CHARPOS (top
) <= BUF_ZV (buf
)
1870 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
1871 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
1874 if (!NILP (in_window
) && !NILP (partially
))
1876 Lisp_Object part
= Qnil
;
1878 part
= list4i (rtop
, rbot
, rowh
, vpos
);
1879 in_window
= Fcons (make_number (x
),
1880 Fcons (make_number (y
), part
));
1886 DEFUN ("window-line-height", Fwindow_line_height
,
1887 Swindow_line_height
, 0, 2, 0,
1888 doc
: /* Return height in pixels of text line LINE in window WINDOW.
1889 WINDOW must be a live window and defaults to the selected one.
1891 Return height of current line if LINE is omitted or nil. Return height of
1892 header or mode line if LINE is `header-line' or `mode-line'.
1893 Otherwise, LINE is a text line number starting from 0. A negative number
1894 counts from the end of the window.
1896 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
1897 in pixels of the visible part of the line, VPOS and YPOS are the
1898 vertical position in lines and pixels of the line, relative to the top
1899 of the first text line, and OFFBOT is the number of off-window pixels at
1900 the bottom of the text line. If there are off-window pixels at the top
1901 of the (first) text line, YPOS is negative.
1903 Return nil if window display is not up-to-date. In that case, use
1904 `pos-visible-in-window-p' to obtain the information. */)
1905 (Lisp_Object line
, Lisp_Object window
)
1907 register struct window
*w
;
1908 register struct buffer
*b
;
1909 struct glyph_row
*row
, *end_row
;
1913 w
= decode_live_window (window
);
1915 if (noninteractive
|| w
->pseudo_window_p
)
1918 CHECK_BUFFER (w
->contents
);
1919 b
= XBUFFER (w
->contents
);
1921 /* Fail if current matrix is not up-to-date. */
1922 if (!w
->window_end_valid
1923 || windows_or_buffers_changed
1925 || b
->prevent_redisplay_optimizations_p
1926 || window_outdated (w
))
1932 if (i
< 0 || i
>= w
->current_matrix
->nrows
1933 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
1935 max_y
= window_text_bottom_y (w
);
1939 if (EQ (line
, Qheader_line
))
1941 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
1943 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
1944 return row
->enabled_p
? list4i (row
->height
, 0, 0, 0) : Qnil
;
1947 if (EQ (line
, Qmode_line
))
1949 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
1950 return (row
->enabled_p
?
1951 list4i (row
->height
,
1952 0, /* not accurate */
1953 (WINDOW_HEADER_LINE_HEIGHT (w
)
1954 + window_text_bottom_y (w
)),
1959 CHECK_NUMBER (line
);
1962 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1963 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1964 max_y
= window_text_bottom_y (w
);
1967 while ((n
< 0 || i
< n
)
1968 && row
<= end_row
&& row
->enabled_p
1969 && row
->y
+ row
->height
< max_y
)
1972 if (row
> end_row
|| !row
->enabled_p
)
1984 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
1985 return list4i (row
->height
+ min (0, row
->y
) - crop
, i
, row
->y
, crop
);
1988 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1990 doc
: /* Return non-nil when WINDOW is dedicated to its buffer.
1991 More precisely, return the value assigned by the last call of
1992 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1993 never called with WINDOW as its argument, or the value set by that
1994 function was internally reset since its last call. WINDOW must be a
1995 live window and defaults to the selected one.
1997 When a window is dedicated to its buffer, `display-buffer' will refrain
1998 from displaying another buffer in it. `get-lru-window' and
1999 `get-largest-window' treat dedicated windows specially.
2000 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
2001 `kill-buffer' can delete a dedicated window and the containing frame.
2003 Functions like `set-window-buffer' may change the buffer displayed by a
2004 window, unless that window is "strongly" dedicated to its buffer, that
2005 is the value returned by `window-dedicated-p' is t. */)
2006 (Lisp_Object window
)
2008 return decode_live_window (window
)->dedicated
;
2011 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
2012 Sset_window_dedicated_p
, 2, 2, 0,
2013 doc
: /* Mark WINDOW as dedicated according to FLAG.
2014 WINDOW must be a live window and defaults to the selected one. FLAG
2015 non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means
2016 mark WINDOW as non-dedicated. Return FLAG.
2018 When a window is dedicated to its buffer, `display-buffer' will refrain
2019 from displaying another buffer in it. `get-lru-window' and
2020 `get-largest-window' treat dedicated windows specially.
2021 `delete-windows-on', `replace-buffer-in-windows', `quit-window',
2022 `quit-restore-window' and `kill-buffer' can delete a dedicated window
2023 and the containing frame.
2025 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
2026 its buffer. Functions like `set-window-buffer' may change the buffer
2027 displayed by a window, unless that window is strongly dedicated to its
2028 buffer. If and when `set-window-buffer' displays another buffer in a
2029 window, it also makes sure that the window is no more dedicated. */)
2030 (Lisp_Object window
, Lisp_Object flag
)
2032 wset_dedicated (decode_live_window (window
), flag
);
2036 DEFUN ("window-prev-buffers", Fwindow_prev_buffers
, Swindow_prev_buffers
,
2038 doc
: /* Return buffers previously shown in WINDOW.
2039 WINDOW must be a live window and defaults to the selected one.
2041 The return value is a list of elements (BUFFER WINDOW-START POS),
2042 where BUFFER is a buffer, WINDOW-START is the start position of the
2043 window for that buffer, and POS is a window-specific point value. */)
2044 (Lisp_Object window
)
2046 return decode_live_window (window
)->prev_buffers
;
2049 DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers
,
2050 Sset_window_prev_buffers
, 2, 2, 0,
2051 doc
: /* Set WINDOW's previous buffers to PREV-BUFFERS.
2052 WINDOW must be a live window and defaults to the selected one.
2054 PREV-BUFFERS should be a list of elements (BUFFER WINDOW-START POS),
2055 where BUFFER is a buffer, WINDOW-START is the start position of the
2056 window for that buffer, and POS is a window-specific point value. */)
2057 (Lisp_Object window
, Lisp_Object prev_buffers
)
2059 wset_prev_buffers (decode_live_window (window
), prev_buffers
);
2060 return prev_buffers
;
2063 DEFUN ("window-next-buffers", Fwindow_next_buffers
, Swindow_next_buffers
,
2065 doc
: /* Return list of buffers recently re-shown in WINDOW.
2066 WINDOW must be a live window and defaults to the selected one. */)
2067 (Lisp_Object window
)
2069 return decode_live_window (window
)->next_buffers
;
2072 DEFUN ("set-window-next-buffers", Fset_window_next_buffers
,
2073 Sset_window_next_buffers
, 2, 2, 0,
2074 doc
: /* Set WINDOW's next buffers to NEXT-BUFFERS.
2075 WINDOW must be a live window and defaults to the selected one.
2076 NEXT-BUFFERS should be a list of buffers. */)
2077 (Lisp_Object window
, Lisp_Object next_buffers
)
2079 wset_next_buffers (decode_live_window (window
), next_buffers
);
2080 return next_buffers
;
2083 DEFUN ("window-parameters", Fwindow_parameters
, Swindow_parameters
,
2085 doc
: /* Return the parameters of WINDOW and their values.
2086 WINDOW must be a valid window and defaults to the selected one. The
2087 return value is a list of elements of the form (PARAMETER . VALUE). */)
2088 (Lisp_Object window
)
2090 return Fcopy_alist (decode_valid_window (window
)->window_parameters
);
2093 DEFUN ("window-parameter", Fwindow_parameter
, Swindow_parameter
,
2095 doc
: /* Return WINDOW's value for PARAMETER.
2096 WINDOW can be any window and defaults to the selected one. */)
2097 (Lisp_Object window
, Lisp_Object parameter
)
2101 result
= Fassq (parameter
, decode_any_window (window
)->window_parameters
);
2102 return CDR_SAFE (result
);
2105 DEFUN ("set-window-parameter", Fset_window_parameter
,
2106 Sset_window_parameter
, 3, 3, 0,
2107 doc
: /* Set WINDOW's value of PARAMETER to VALUE.
2108 WINDOW can be any window and defaults to the selected one.
2110 (Lisp_Object window
, Lisp_Object parameter
, Lisp_Object value
)
2112 register struct window
*w
= decode_any_window (window
);
2113 Lisp_Object old_alist_elt
;
2115 old_alist_elt
= Fassq (parameter
, w
->window_parameters
);
2116 if (NILP (old_alist_elt
))
2117 wset_window_parameters
2118 (w
, Fcons (Fcons (parameter
, value
), w
->window_parameters
));
2120 Fsetcdr (old_alist_elt
, value
);
2124 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
2126 doc
: /* Return the display-table that WINDOW is using.
2127 WINDOW must be a live window and defaults to the selected one. */)
2128 (Lisp_Object window
)
2130 return decode_live_window (window
)->display_table
;
2133 /* Get the display table for use on window W. This is either W's
2134 display table or W's buffer's display table. Ignore the specified
2135 tables if they are not valid; if no valid table is specified,
2138 struct Lisp_Char_Table
*
2139 window_display_table (struct window
*w
)
2141 struct Lisp_Char_Table
*dp
= NULL
;
2143 if (DISP_TABLE_P (w
->display_table
))
2144 dp
= XCHAR_TABLE (w
->display_table
);
2145 else if (BUFFERP (w
->contents
))
2147 struct buffer
*b
= XBUFFER (w
->contents
);
2149 if (DISP_TABLE_P (BVAR (b
, display_table
)))
2150 dp
= XCHAR_TABLE (BVAR (b
, display_table
));
2151 else if (DISP_TABLE_P (Vstandard_display_table
))
2152 dp
= XCHAR_TABLE (Vstandard_display_table
);
2158 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
2159 doc
: /* Set WINDOW's display-table to TABLE.
2160 WINDOW must be a live window and defaults to the selected one. */)
2161 (register Lisp_Object window
, Lisp_Object table
)
2163 wset_display_table (decode_live_window (window
), table
);
2167 /* Record info on buffer window W is displaying
2168 when it is about to cease to display that buffer. */
2170 unshow_buffer (register struct window
*w
)
2172 Lisp_Object buf
= w
->contents
;
2173 struct buffer
*b
= XBUFFER (buf
);
2175 eassert (b
== XMARKER (w
->pointm
)->buffer
);
2178 if (w
== XWINDOW (selected_window
)
2179 || ! EQ (buf
, XWINDOW (selected_window
)->contents
))
2180 /* Do this except when the selected window's buffer
2181 is being removed from some other window. */
2183 /* last_window_start records the start position that this buffer
2184 had in the last window to be disconnected from it.
2185 Now that this statement is unconditional,
2186 it is possible for the buffer to be displayed in the
2187 selected window, while last_window_start reflects another
2188 window which was recently showing the same buffer.
2189 Some people might say that might be a good thing. Let's see. */
2190 b
->last_window_start
= marker_position (w
->start
);
2192 /* Point in the selected window's buffer
2193 is actually stored in that buffer, and the window's pointm isn't used.
2194 So don't clobber point in that buffer. */
2195 if (! EQ (buf
, XWINDOW (selected_window
)->contents
)
2196 /* Don't clobber point in current buffer either (this could be
2197 useful in connection with bug#12208).
2198 && XBUFFER (buf) != current_buffer */
2199 /* This line helps to fix Horsley's testbug.el bug. */
2200 && !(WINDOWP (BVAR (b
, last_selected_window
))
2201 && w
!= XWINDOW (BVAR (b
, last_selected_window
))
2202 && EQ (buf
, XWINDOW (BVAR (b
, last_selected_window
))->contents
)))
2203 temp_set_point_both (b
,
2204 clip_to_bounds (BUF_BEGV (b
),
2205 marker_position (w
->pointm
),
2207 clip_to_bounds (BUF_BEGV_BYTE (b
),
2208 marker_byte_position (w
->pointm
),
2211 if (WINDOWP (BVAR (b
, last_selected_window
))
2212 && w
== XWINDOW (BVAR (b
, last_selected_window
)))
2213 bset_last_selected_window (b
, Qnil
);
2216 /* Put NEW into the window structure in place of OLD. SETFLAG zero
2217 means change window structure only. Otherwise store geometry and
2218 other settings as well. */
2220 replace_window (Lisp_Object old
, Lisp_Object
new, int setflag
)
2222 register Lisp_Object tem
;
2223 register struct window
*o
= XWINDOW (old
), *n
= XWINDOW (new);
2225 /* If OLD is its frame's root window, then NEW is the new
2226 root window for that frame. */
2227 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
2228 fset_root_window (XFRAME (o
->frame
), new);
2232 n
->pixel_left
= o
->pixel_left
;
2233 n
->pixel_top
= o
->pixel_top
;
2234 n
->pixel_width
= o
->pixel_width
;
2235 n
->pixel_height
= o
->pixel_height
;
2236 n
->left_col
= o
->left_col
;
2237 n
->top_line
= o
->top_line
;
2238 n
->total_cols
= o
->total_cols
;
2239 n
->total_lines
= o
->total_lines
;
2240 wset_normal_cols (n
, o
->normal_cols
);
2241 wset_normal_cols (o
, make_float (1.0));
2242 wset_normal_lines (n
, o
->normal_lines
);
2243 wset_normal_lines (o
, make_float (1.0));
2244 n
->desired_matrix
= n
->current_matrix
= 0;
2246 memset (&n
->cursor
, 0, sizeof (n
->cursor
));
2247 memset (&n
->phys_cursor
, 0, sizeof (n
->phys_cursor
));
2248 n
->last_cursor_vpos
= 0;
2249 #ifdef HAVE_WINDOW_SYSTEM
2250 n
->phys_cursor_type
= NO_CURSOR
;
2251 n
->phys_cursor_width
= -1;
2253 n
->must_be_updated_p
= 0;
2254 n
->pseudo_window_p
= 0;
2255 n
->window_end_vpos
= 0;
2256 n
->window_end_pos
= 0;
2257 n
->window_end_valid
= 0;
2263 wset_prev (XWINDOW (tem
), new);
2268 wset_next (XWINDOW (tem
), new);
2271 wset_parent (n
, tem
);
2272 if (!NILP (tem
) && EQ (XWINDOW (tem
)->contents
, old
))
2273 wset_combination (XWINDOW (tem
), XWINDOW (tem
)->horizontal
, new);
2276 /* If window WINDOW and its parent window are iso-combined, merge
2277 WINDOW's children into those of its parent window and mark WINDOW as
2281 recombine_windows (Lisp_Object window
)
2283 struct window
*w
, *p
, *c
;
2284 Lisp_Object parent
, child
;
2287 w
= XWINDOW (window
);
2289 if (!NILP (parent
) && NILP (w
->combination_limit
))
2291 p
= XWINDOW (parent
);
2292 if (WINDOWP (p
->contents
) && WINDOWP (w
->contents
)
2293 && p
->horizontal
== w
->horizontal
)
2294 /* WINDOW and PARENT are both either a vertical or a horizontal
2297 horflag
= WINDOW_HORIZONTAL_COMBINATION_P (w
);
2298 child
= w
->contents
;
2299 c
= XWINDOW (child
);
2301 /* Splice WINDOW's children into its parent's children and
2302 assign new normal sizes. */
2304 wset_combination (p
, horflag
, child
);
2307 wset_prev (c
, w
->prev
);
2308 wset_next (XWINDOW (w
->prev
), child
);
2313 wset_parent (c
, parent
);
2317 (c
, make_float ((double) c
->pixel_width
2318 / (double) p
->pixel_width
));
2321 (c
, make_float ((double) c
->pixel_height
2322 / (double) p
->pixel_height
));
2326 if (!NILP (w
->next
))
2328 wset_next (c
, w
->next
);
2329 wset_prev (XWINDOW (c
->next
), child
);
2337 c
= XWINDOW (child
);
2341 /* WINDOW can be deleted now. */
2342 wset_combination (w
, 0, Qnil
);
2347 /* If WINDOW can be deleted, delete it. */
2349 delete_deletable_window (Lisp_Object window
)
2351 if (!NILP (call1 (Qwindow_deletable_p
, window
)))
2352 call1 (Qdelete_window
, window
);
2355 /***********************************************************************
2357 ***********************************************************************/
2359 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
2360 pointer. This is a callback function for foreach_window, used in
2361 the window_list function. */
2364 add_window_to_list (struct window
*w
, void *user_data
)
2366 Lisp_Object
*list
= user_data
;
2368 XSETWINDOW (window
, w
);
2369 *list
= Fcons (window
, *list
);
2374 /* Return a list of all windows, for use by next_window. If
2375 Vwindow_list is a list, return that list. Otherwise, build a new
2376 list, cache it in Vwindow_list, and return that. */
2381 if (!CONSP (Vwindow_list
))
2383 Lisp_Object tail
, frame
;
2385 Vwindow_list
= Qnil
;
2386 FOR_EACH_FRAME (tail
, frame
)
2388 Lisp_Object args
[2];
2390 /* We are visiting windows in canonical order, and add
2391 new windows at the front of args[1], which means we
2392 have to reverse this list at the end. */
2394 foreach_window (XFRAME (frame
), add_window_to_list
, &args
[1]);
2395 args
[0] = Vwindow_list
;
2396 args
[1] = Fnreverse (args
[1]);
2397 Vwindow_list
= Fnconc (2, args
);
2401 return Vwindow_list
;
2405 /* Value is non-zero if WINDOW satisfies the constraints given by
2406 OWINDOW, MINIBUF and ALL_FRAMES.
2408 MINIBUF t means WINDOW may be minibuffer windows.
2409 `lambda' means WINDOW may not be a minibuffer window.
2410 a window means a specific minibuffer window
2412 ALL_FRAMES t means search all frames,
2413 nil means search just current frame,
2414 `visible' means search just visible frames on the
2416 0 means search visible and iconified frames on the
2418 a window means search the frame that window belongs to,
2419 a frame means consider windows on that frame, only. */
2422 candidate_window_p (Lisp_Object window
, Lisp_Object owindow
,
2423 Lisp_Object minibuf
, Lisp_Object all_frames
)
2425 struct window
*w
= XWINDOW (window
);
2426 struct frame
*f
= XFRAME (w
->frame
);
2427 bool candidate_p
= 1;
2429 if (!BUFFERP (w
->contents
))
2431 else if (MINI_WINDOW_P (w
)
2432 && (EQ (minibuf
, Qlambda
)
2433 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
2435 /* If MINIBUF is `lambda' don't consider any mini-windows.
2436 If it is a window, consider only that one. */
2439 else if (EQ (all_frames
, Qt
))
2441 else if (NILP (all_frames
))
2443 eassert (WINDOWP (owindow
));
2444 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
2446 else if (EQ (all_frames
, Qvisible
))
2448 candidate_p
= FRAME_VISIBLE_P (f
)
2449 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2450 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2453 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
2455 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
2456 #ifdef HAVE_X_WINDOWS
2457 /* Yuck!! If we've just created the frame and the
2458 window-manager requested the user to place it
2459 manually, the window may still not be considered
2460 `visible'. I'd argue it should be at least
2461 something like `iconified', but don't know how to do
2463 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
2464 && !f
->output_data
.x
->has_been_visible
)
2467 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2468 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2470 else if (WINDOWP (all_frames
))
2471 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
2472 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
2473 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
2474 else if (FRAMEP (all_frames
))
2475 candidate_p
= EQ (all_frames
, w
->frame
);
2481 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2482 Fwindow_list. See candidate_window_p for the meaning of WINDOW,
2483 MINIBUF, and ALL_FRAMES. */
2486 decode_next_window_args (Lisp_Object
*window
, Lisp_Object
*minibuf
, Lisp_Object
*all_frames
)
2488 struct window
*w
= decode_live_window (*window
);
2490 XSETWINDOW (*window
, w
);
2491 /* MINIBUF nil may or may not include minibuffers. Decide if it
2493 if (NILP (*minibuf
))
2494 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
2495 else if (!EQ (*minibuf
, Qt
))
2498 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2499 => count none of them, or a specific minibuffer window (the
2500 active one) to count. */
2502 /* ALL_FRAMES nil doesn't specify which frames to include. */
2503 if (NILP (*all_frames
))
2505 = (!EQ (*minibuf
, Qlambda
)
2506 ? FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
))
2508 else if (EQ (*all_frames
, Qvisible
))
2510 else if (EQ (*all_frames
, make_number (0)))
2512 else if (FRAMEP (*all_frames
))
2514 else if (!EQ (*all_frames
, Qt
))
2519 /* Return the next or previous window of WINDOW in cyclic ordering
2520 of windows. NEXT_P non-zero means return the next window. See the
2521 documentation string of next-window for the meaning of MINIBUF and
2525 next_window (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
, int next_p
)
2527 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2529 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2530 return the first window on the frame. */
2531 if (FRAMEP (all_frames
)
2532 && !EQ (all_frames
, XWINDOW (window
)->frame
))
2533 return Fframe_first_window (all_frames
);
2539 /* Find WINDOW in the list of all windows. */
2540 list
= Fmemq (window
, window_list ());
2542 /* Scan forward from WINDOW to the end of the window list. */
2544 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
2545 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2548 /* Scan from the start of the window list up to WINDOW. */
2550 for (list
= Vwindow_list
;
2551 CONSP (list
) && !EQ (XCAR (list
), window
);
2553 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2557 window
= XCAR (list
);
2561 Lisp_Object candidate
, list
;
2563 /* Scan through the list of windows for candidates. If there are
2564 candidate windows in front of WINDOW, the last one of these
2565 is the one we want. If there are candidates following WINDOW
2566 in the list, again the last one of these is the one we want. */
2568 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
2570 if (EQ (XCAR (list
), window
))
2572 if (WINDOWP (candidate
))
2575 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
2577 candidate
= XCAR (list
);
2580 if (WINDOWP (candidate
))
2588 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
2589 doc
: /* Return live window after WINDOW in the cyclic ordering of windows.
2590 WINDOW must be a live window and defaults to the selected one. The
2591 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2594 MINIBUF nil or omitted means consider the minibuffer window only if the
2595 minibuffer is active. MINIBUF t means consider the minibuffer window
2596 even if the minibuffer is not active. Any other value means do not
2597 consider the minibuffer window even if the minibuffer is active.
2599 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2600 plus the minibuffer window if specified by the MINIBUF argument. If the
2601 minibuffer counts, consider all windows on all frames that share that
2602 minibuffer too. The following non-nil values of ALL-FRAMES have special
2605 - t means consider all windows on all existing frames.
2607 - `visible' means consider all windows on all visible frames.
2609 - 0 (the number zero) means consider all windows on all visible and
2612 - A frame means consider all windows on that frame only.
2614 Anything else means consider all windows on WINDOW's frame and no
2617 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2618 `next-window' to iterate through the entire cycle of acceptable
2619 windows, eventually ending up back at the window you started with.
2620 `previous-window' traverses the same cycle, in the reverse order. */)
2621 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2623 return next_window (window
, minibuf
, all_frames
, 1);
2627 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
2628 doc
: /* Return live window before WINDOW in the cyclic ordering of windows.
2629 WINDOW must be a live window and defaults to the selected one. The
2630 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2633 MINIBUF nil or omitted means consider the minibuffer window only if the
2634 minibuffer is active. MINIBUF t means consider the minibuffer window
2635 even if the minibuffer is not active. Any other value means do not
2636 consider the minibuffer window even if the minibuffer is active.
2638 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2639 plus the minibuffer window if specified by the MINIBUF argument. If the
2640 minibuffer counts, consider all windows on all frames that share that
2641 minibuffer too. The following non-nil values of ALL-FRAMES have special
2644 - t means consider all windows on all existing frames.
2646 - `visible' means consider all windows on all visible frames.
2648 - 0 (the number zero) means consider all windows on all visible and
2651 - A frame means consider all windows on that frame only.
2653 Anything else means consider all windows on WINDOW's frame and no
2656 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2657 use `previous-window' to iterate through the entire cycle of
2658 acceptable windows, eventually ending up back at the window you
2659 started with. `next-window' traverses the same cycle, in the
2661 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2663 return next_window (window
, minibuf
, all_frames
, 0);
2667 /* Return a list of windows in cyclic ordering. Arguments are like
2668 for `next-window'. */
2671 window_list_1 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2673 Lisp_Object tail
, list
, rest
;
2675 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2678 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2679 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2680 list
= Fcons (XCAR (tail
), list
);
2682 /* Rotate the list to start with WINDOW. */
2683 list
= Fnreverse (list
);
2684 rest
= Fmemq (window
, list
);
2685 if (!NILP (rest
) && !EQ (rest
, list
))
2687 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2689 XSETCDR (tail
, Qnil
);
2690 list
= nconc2 (rest
, list
);
2696 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2697 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2698 FRAME nil or omitted means use the selected frame.
2699 WINDOW nil or omitted means use the window selected within FRAME.
2700 MINIBUF t means include the minibuffer window, even if it isn't active.
2701 MINIBUF nil or omitted means include the minibuffer window only
2703 MINIBUF neither nil nor t means never include the minibuffer window. */)
2704 (Lisp_Object frame
, Lisp_Object minibuf
, Lisp_Object window
)
2707 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2708 CHECK_WINDOW (window
);
2710 frame
= selected_frame
;
2712 if (!EQ (frame
, XWINDOW (window
)->frame
))
2713 error ("Window is on a different frame");
2715 return window_list_1 (window
, minibuf
, frame
);
2719 DEFUN ("window-list-1", Fwindow_list_1
, Swindow_list_1
, 0, 3, 0,
2720 doc
: /* Return a list of all live windows.
2721 WINDOW specifies the first window to list and defaults to the selected
2724 Optional argument MINIBUF nil or omitted means consider the minibuffer
2725 window only if the minibuffer is active. MINIBUF t means consider the
2726 minibuffer window even if the minibuffer is not active. Any other value
2727 means do not consider the minibuffer window even if the minibuffer is
2730 Optional argument ALL-FRAMES nil or omitted means consider all windows
2731 on WINDOW's frame, plus the minibuffer window if specified by the
2732 MINIBUF argument. If the minibuffer counts, consider all windows on all
2733 frames that share that minibuffer too. The following non-nil values of
2734 ALL-FRAMES have special meanings:
2736 - t means consider all windows on all existing frames.
2738 - `visible' means consider all windows on all visible frames.
2740 - 0 (the number zero) means consider all windows on all visible and
2743 - A frame means consider all windows on that frame only.
2745 Anything else means consider all windows on WINDOW's frame and no
2748 If WINDOW is not on the list of windows returned, some other window will
2749 be listed first but no error is signaled. */)
2750 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2752 return window_list_1 (window
, minibuf
, all_frames
);
2755 /* Look at all windows, performing an operation specified by TYPE
2757 If FRAMES is Qt, look at all frames;
2758 Qnil, look at just the selected frame;
2759 Qvisible, look at visible frames;
2760 a frame, just look at windows on that frame.
2761 If MINI is non-zero, perform the operation on minibuffer windows too. */
2766 GET_BUFFER_WINDOW
, /* Arg is buffer */
2767 REPLACE_BUFFER_IN_WINDOWS_SAFELY
, /* Arg is buffer */
2768 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2769 CHECK_ALL_WINDOWS
/* Arg is ignored */
2773 window_loop (enum window_loop type
, Lisp_Object obj
, int mini
, Lisp_Object frames
)
2775 Lisp_Object window
, windows
, best_window
, frame_arg
;
2776 int frame_best_window_flag
= 0;
2778 struct gcpro gcpro1
;
2780 /* If we're only looping through windows on a particular frame,
2781 frame points to that frame. If we're looping through windows
2782 on all frames, frame is 0. */
2783 if (FRAMEP (frames
))
2784 f
= XFRAME (frames
);
2785 else if (NILP (frames
))
2786 f
= SELECTED_FRAME ();
2791 frame_arg
= Qlambda
;
2792 else if (EQ (frames
, make_number (0)))
2794 else if (EQ (frames
, Qvisible
))
2799 /* frame_arg is Qlambda to stick to one frame,
2800 Qvisible to consider all visible frames,
2803 /* Pick a window to start with. */
2807 window
= FRAME_SELECTED_WINDOW (f
);
2809 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2811 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2815 for (; CONSP (windows
); windows
= XCDR (windows
))
2819 window
= XCAR (windows
);
2820 w
= XWINDOW (window
);
2822 /* Note that we do not pay attention here to whether the frame
2823 is visible, since Fwindow_list skips non-visible frames if
2824 that is desired, under the control of frame_arg. */
2825 if (!MINI_WINDOW_P (w
)
2826 /* For REPLACE_BUFFER_IN_WINDOWS_SAFELY, we must always
2827 consider all windows. */
2828 || type
== REPLACE_BUFFER_IN_WINDOWS_SAFELY
2829 || (mini
&& minibuf_level
> 0))
2832 case GET_BUFFER_WINDOW
:
2833 if (EQ (w
->contents
, obj
)
2834 /* Don't find any minibuffer window except the one that
2835 is currently in use. */
2836 && (MINI_WINDOW_P (w
) ? EQ (window
, minibuf_window
) : 1))
2838 if (EQ (window
, selected_window
))
2839 /* Preferably return the selected window. */
2840 RETURN_UNGCPRO (window
);
2841 else if (EQ (XWINDOW (window
)->frame
, selected_frame
)
2842 && !frame_best_window_flag
)
2843 /* Prefer windows on the current frame (but don't
2844 choose another one if we have one already). */
2846 best_window
= window
;
2847 frame_best_window_flag
= 1;
2849 else if (NILP (best_window
))
2850 best_window
= window
;
2854 case REPLACE_BUFFER_IN_WINDOWS_SAFELY
:
2855 /* We could simply check whether the buffer shown by window
2856 is live, and show another buffer in case it isn't. */
2857 if (EQ (w
->contents
, obj
))
2859 /* Undedicate WINDOW. */
2860 wset_dedicated (w
, Qnil
);
2861 /* Make WINDOW show the buffer returned by
2862 other_buffer_safely, don't run any hooks. */
2864 (window
, other_buffer_safely (w
->contents
), 0, 0);
2865 /* If WINDOW is the selected window, make its buffer
2866 current. But do so only if the window shows the
2867 current buffer (Bug#6454). */
2868 if (EQ (window
, selected_window
)
2869 && XBUFFER (w
->contents
) == current_buffer
)
2870 Fset_buffer (w
->contents
);
2874 case REDISPLAY_BUFFER_WINDOWS
:
2875 if (EQ (w
->contents
, obj
))
2877 mark_window_display_accurate (window
, 0);
2878 w
->update_mode_line
= 1;
2879 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2880 update_mode_lines
= 27;
2881 best_window
= window
;
2885 /* Check for a leaf window that has a killed buffer
2886 or broken markers. */
2887 case CHECK_ALL_WINDOWS
:
2888 if (BUFFERP (w
->contents
))
2890 struct buffer
*b
= XBUFFER (w
->contents
);
2892 if (!BUFFER_LIVE_P (b
))
2894 if (!MARKERP (w
->start
) || XMARKER (w
->start
)->buffer
!= b
)
2896 if (!MARKERP (w
->pointm
) || XMARKER (w
->pointm
)->buffer
!= b
)
2901 case WINDOW_LOOP_UNUSED
:
2910 /* Used for debugging. Abort if any window has a dead buffer. */
2912 extern void check_all_windows (void) EXTERNALLY_VISIBLE
;
2914 check_all_windows (void)
2916 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2919 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 0, 2, 0,
2920 doc
: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2921 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to
2924 The optional argument ALL-FRAMES specifies the frames to consider:
2926 - t means consider all windows on all existing frames.
2928 - `visible' means consider all windows on all visible frames.
2930 - 0 (the number zero) means consider all windows on all visible
2931 and iconified frames.
2933 - A frame means consider all windows on that frame only.
2935 Any other value of ALL-FRAMES means consider all windows on the
2936 selected frame and no others. */)
2937 (Lisp_Object buffer_or_name
, Lisp_Object all_frames
)
2941 if (NILP (buffer_or_name
))
2942 buffer
= Fcurrent_buffer ();
2944 buffer
= Fget_buffer (buffer_or_name
);
2946 if (BUFFERP (buffer
))
2947 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, all_frames
);
2953 resize_root_window (Lisp_Object window
, Lisp_Object delta
, Lisp_Object horizontal
, Lisp_Object ignore
, Lisp_Object pixelwise
)
2955 return call5 (Qwindow_resize_root_window
, window
, delta
, horizontal
, ignore
, pixelwise
);
2960 window_pixel_to_total (Lisp_Object frame
, Lisp_Object horizontal
)
2962 return call2(Qwindow_pixel_to_total
, frame
, horizontal
);
2966 DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal
,
2967 Sdelete_other_windows_internal
, 0, 2, "",
2968 doc
: /* Make WINDOW fill its frame.
2969 Only the frame WINDOW is on is affected. WINDOW must be a valid window
2970 and defaults to the selected one.
2972 Optional argument ROOT, if non-nil, must specify an internal window such
2973 that WINDOW is in its window subtree. If this is the case, replace ROOT
2974 by WINDOW and leave alone any windows not part of ROOT's subtree.
2976 When WINDOW is live try to reduce display jumps by keeping the text
2977 previously visible in WINDOW in the same place on the frame. Doing this
2978 depends on the value of (window-start WINDOW), so if calling this
2979 function in a program gives strange scrolling, make sure the
2980 window-start value is reasonable when this function is called. */)
2981 (Lisp_Object window
, Lisp_Object root
)
2983 struct window
*w
, *r
, *s
;
2985 Lisp_Object sibling
, pwindow
, swindow
IF_LINT (= Qnil
), delta
;
2986 ptrdiff_t startpos
IF_LINT (= 0), startbyte
IF_LINT (= 0);
2987 int top
IF_LINT (= 0), new_top
, resize_failed
;
2989 w
= decode_valid_window (window
);
2990 XSETWINDOW (window
, w
);
2991 f
= XFRAME (w
->frame
);
2994 /* ROOT is the frame's root window. */
2996 root
= FRAME_ROOT_WINDOW (f
);
3000 /* ROOT must be an ancestor of WINDOW. */
3002 r
= decode_valid_window (root
);
3003 pwindow
= XWINDOW (window
)->parent
;
3004 while (!NILP (pwindow
))
3005 if (EQ (pwindow
, root
))
3008 pwindow
= XWINDOW (pwindow
)->parent
;
3009 if (!EQ (pwindow
, root
))
3010 error ("Specified root is not an ancestor of specified window");
3013 if (EQ (window
, root
))
3016 /* I don't understand the "top > 0" part below. If we deal with a
3017 standalone minibuffer it would have been caught by the preceding
3019 else if (MINI_WINDOW_P (w
)) /* && top > 0) */
3020 error ("Can't expand minibuffer to full frame");
3022 if (BUFFERP (w
->contents
))
3024 startpos
= marker_position (w
->start
);
3025 startbyte
= marker_byte_position (w
->start
);
3026 top
= (WINDOW_TOP_EDGE_LINE (w
)
3027 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
))));
3028 /* Make sure WINDOW is the frame's selected window. */
3029 if (!EQ (window
, FRAME_SELECTED_WINDOW (f
)))
3031 if (EQ (selected_frame
, w
->frame
))
3032 Fselect_window (window
, Qnil
);
3034 fset_selected_window (f
, window
);
3039 /* See if the frame's selected window is a part of the window
3040 subtree rooted at WINDOW, by finding all the selected window's
3041 parents and comparing each one with WINDOW. If it isn't we
3042 need a new selected window for this frame. */
3043 swindow
= FRAME_SELECTED_WINDOW (f
);
3047 while (!NILP (pwindow
) && !EQ (window
, pwindow
))
3048 pwindow
= XWINDOW (pwindow
)->parent
;
3050 if (EQ (window
, pwindow
))
3051 /* If WINDOW is an ancestor of SWINDOW, then SWINDOW is ok
3052 as the new selected window. */
3055 /* Else try the previous window of SWINDOW. */
3056 swindow
= Fprevious_window (swindow
, Qlambda
, Qnil
);
3059 if (!EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
3061 if (EQ (selected_frame
, w
->frame
))
3062 Fselect_window (swindow
, Qnil
);
3064 fset_selected_window (f
, swindow
);
3069 if (!FRAME_INITIAL_P (f
))
3071 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
3073 /* We are going to free the glyph matrices of WINDOW, and with
3074 that we might lose any information about glyph rows that have
3075 some of their glyphs highlighted in mouse face. (These rows
3076 are marked with a non-zero mouse_face_p flag.) If WINDOW
3077 indeed has some glyphs highlighted in mouse face, signal to
3078 frame's up-to-date hook that mouse highlight was overwritten,
3079 so that it will arrange for redisplaying the highlight. */
3080 if (EQ (hlinfo
->mouse_face_window
, window
))
3081 reset_mouse_highlight (hlinfo
);
3083 free_window_matrices (r
);
3086 Vwindow_list
= Qnil
;
3087 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3090 if (!WINDOW_LEAF_P (w
))
3092 /* Resize child windows vertically. */
3093 XSETINT (delta
, r
->pixel_height
- w
->pixel_height
);
3094 w
->pixel_top
= r
->pixel_top
;
3095 w
->top_line
= r
->top_line
;
3096 resize_root_window (window
, delta
, Qnil
, Qnil
, Qt
);
3097 if (window_resize_check (w
, 0))
3099 window_resize_apply (w
, 0);
3100 window_pixel_to_total (w
->frame
, Qnil
);
3104 resize_root_window (window
, delta
, Qnil
, Qt
, Qt
);
3105 if (window_resize_check (w
, 0))
3107 window_resize_apply (w
, 0);
3108 window_pixel_to_total (w
->frame
, Qnil
);
3114 /* Resize child windows horizontally. */
3117 w
->left_col
= r
->left_col
;
3118 w
->pixel_left
= r
->pixel_left
;
3119 XSETINT (delta
, r
->pixel_width
- w
->pixel_width
);
3120 resize_root_window (window
, delta
, Qt
, Qnil
, Qt
);
3121 if (window_resize_check (w
, 1))
3123 window_resize_apply (w
, 1);
3124 window_pixel_to_total (w
->frame
, Qt
);
3128 resize_root_window (window
, delta
, Qt
, Qt
, Qt
);
3129 if (window_resize_check (w
, 1))
3131 window_resize_apply (w
, 1);
3132 window_pixel_to_total (w
->frame
, Qt
);
3140 /* Play safe, if we still can ... */
3143 w
= XWINDOW (window
);
3147 /* Cleanly unlink WINDOW from window-tree. */
3148 if (!NILP (w
->prev
))
3149 /* Get SIBLING above (on the left of) WINDOW. */
3152 s
= XWINDOW (sibling
);
3153 wset_next (s
, w
->next
);
3154 if (!NILP (s
->next
))
3155 wset_prev (XWINDOW (s
->next
), sibling
);
3158 /* Get SIBLING below (on the right of) WINDOW. */
3161 s
= XWINDOW (sibling
);
3162 wset_prev (s
, Qnil
);
3163 wset_combination (XWINDOW (w
->parent
),
3164 XWINDOW (w
->parent
)->horizontal
, sibling
);
3167 /* Delete ROOT and all child windows of ROOT. */
3168 if (WINDOWP (r
->contents
))
3170 delete_all_child_windows (r
->contents
);
3171 wset_combination (r
, 0, Qnil
);
3174 replace_window (root
, window
, 1);
3176 /* This must become SWINDOW anyway ....... */
3177 if (BUFFERP (w
->contents
) && !resize_failed
)
3179 /* Try to minimize scrolling, by setting the window start to the
3180 point will cause the text at the old window start to be at the
3181 same place on the frame. But don't try to do this if the
3182 window start is outside the visible portion (as might happen
3183 when the display is not current, due to typeahead). */
3184 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
3186 && startpos
>= BUF_BEGV (XBUFFER (w
->contents
))
3187 && startpos
<= BUF_ZV (XBUFFER (w
->contents
)))
3189 struct position pos
;
3190 struct buffer
*obuf
= current_buffer
;
3192 Fset_buffer (w
->contents
);
3193 /* This computation used to temporarily move point, but that
3194 can have unwanted side effects due to text properties. */
3195 pos
= *vmotion (startpos
, startbyte
, -top
, w
);
3197 set_marker_both (w
->start
, w
->contents
, pos
.bufpos
, pos
.bytepos
);
3198 w
->window_end_valid
= 0;
3199 w
->start_at_line_beg
= (pos
.bytepos
== BEGV_BYTE
3200 || FETCH_BYTE (pos
.bytepos
- 1) == '\n');
3201 /* We need to do this, so that the window-scroll-functions
3203 w
->optional_new_start
= 1;
3205 set_buffer_internal (obuf
);
3209 adjust_frame_glyphs (f
);
3212 run_window_configuration_change_hook (f
);
3219 replace_buffer_in_windows (Lisp_Object buffer
)
3221 call1 (Qreplace_buffer_in_windows
, buffer
);
3224 /* If BUFFER is shown in a window, safely replace it with some other
3225 buffer in all windows of all frames, even those on other keyboards. */
3228 replace_buffer_in_windows_safely (Lisp_Object buffer
)
3230 if (buffer_window_count (XBUFFER (buffer
)))
3232 Lisp_Object tail
, frame
;
3234 /* A single call to window_loop won't do the job because it only
3235 considers frames on the current keyboard. So loop manually over
3236 frames, and handle each one. */
3237 FOR_EACH_FRAME (tail
, frame
)
3238 window_loop (REPLACE_BUFFER_IN_WINDOWS_SAFELY
, buffer
, 1, frame
);
3242 /* If *HEIGHT or *WIDTH are too small a size for FRAME, set them to the
3243 minimum allowable size. PIXELWISE means interpret these as pixel
3247 check_frame_size (struct frame
*frame
, int *width
, int *height
, bool pixelwise
)
3249 /* For height, we have to see:
3250 how many windows the frame has at minimum (one or two),
3251 and whether it has a menu bar or other special stuff at the top. */
3254 int min_height
= MIN_SAFE_WINDOW_HEIGHT
* FRAME_LINE_HEIGHT (frame
);
3255 int min_width
= MIN_SAFE_WINDOW_WIDTH
* FRAME_COLUMN_WIDTH (frame
);
3257 if (!FRAME_MINIBUF_ONLY_P (frame
) && FRAME_HAS_MINIBUF_P (frame
))
3258 min_height
= 2 * min_height
;
3260 min_height
+= FRAME_TOP_MARGIN_HEIGHT (frame
);
3261 min_height
+= FRAME_INTERNAL_BORDER_WIDTH (frame
);
3263 if (*height
< min_height
)
3264 *height
= min_height
;
3265 if (*width
< min_width
)
3271 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
3272 ? MIN_SAFE_WINDOW_HEIGHT
3273 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
3275 if (FRAME_TOP_MARGIN (frame
) > 0)
3276 min_height
+= FRAME_TOP_MARGIN (frame
);
3278 if (*height
< min_height
)
3279 *height
= min_height
;
3280 if (*width
< MIN_SAFE_WINDOW_WIDTH
)
3281 *width
= MIN_SAFE_WINDOW_WIDTH
;
3285 /* Adjust the margins of window W if text area is too small.
3286 Return 1 if window width is ok after adjustment; 0 if window
3287 is still too narrow. */
3290 adjust_window_margins (struct window
*w
)
3292 int box_width
= (WINDOW_PIXEL_WIDTH (w
)
3293 - WINDOW_FRINGES_WIDTH (w
)
3294 - WINDOW_SCROLL_BAR_AREA_WIDTH (w
));
3295 int margin_width
= WINDOW_MARGINS_WIDTH (w
);
3297 if (box_width
- margin_width
>= MIN_SAFE_WINDOW_PIXEL_WIDTH (w
))
3300 if (margin_width
< 0 || box_width
< MIN_SAFE_WINDOW_PIXEL_WIDTH (w
))
3303 /* Window's text area is too narrow, but reducing the window
3304 margins will fix that. */
3306 int unit
= WINDOW_FRAME_COLUMN_WIDTH (w
);
3308 margin_width
= box_width
- MIN_SAFE_WINDOW_PIXEL_WIDTH (w
);
3310 if (WINDOW_RIGHT_MARGIN_WIDTH (w
) > 0)
3312 if (WINDOW_LEFT_MARGIN_WIDTH (w
) > 0)
3313 w
->left_margin_cols
= w
->right_margin_cols
=
3314 margin_width
/ (2 * unit
);
3316 w
->right_margin_cols
= margin_width
/ unit
;
3319 w
->left_margin_cols
= margin_width
/ unit
;
3325 /* The following three routines are needed for running a window's
3326 configuration change hook. */
3328 run_funs (Lisp_Object funs
)
3330 for (; CONSP (funs
); funs
= XCDR (funs
))
3331 if (!EQ (XCAR (funs
), Qt
))
3332 call0 (XCAR (funs
));
3336 select_window_norecord (Lisp_Object window
)
3338 if (WINDOW_LIVE_P (window
))
3339 Fselect_window (window
, Qt
);
3343 select_frame_norecord (Lisp_Object frame
)
3345 if (FRAME_LIVE_P (XFRAME (frame
)))
3346 Fselect_frame (frame
, Qt
);
3350 run_window_configuration_change_hook (struct frame
*f
)
3352 ptrdiff_t count
= SPECPDL_INDEX ();
3353 Lisp_Object frame
, global_wcch
3354 = Fdefault_value (Qwindow_configuration_change_hook
);
3355 XSETFRAME (frame
, f
);
3357 if (NILP (Vrun_hooks
) || !NILP (inhibit_lisp_code
))
3360 /* Use the right buffer. Matters when running the local hooks. */
3361 if (current_buffer
!= XBUFFER (Fwindow_buffer (Qnil
)))
3363 record_unwind_current_buffer ();
3364 Fset_buffer (Fwindow_buffer (Qnil
));
3367 if (SELECTED_FRAME () != f
)
3369 record_unwind_protect (select_frame_norecord
, selected_frame
);
3370 select_frame_norecord (frame
);
3373 /* Look for buffer-local values. */
3375 Lisp_Object windows
= Fwindow_list (frame
, Qlambda
, Qnil
);
3376 for (; CONSP (windows
); windows
= XCDR (windows
))
3378 Lisp_Object window
= XCAR (windows
);
3379 Lisp_Object buffer
= Fwindow_buffer (window
);
3380 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook
,
3383 ptrdiff_t inner_count
= SPECPDL_INDEX ();
3384 record_unwind_protect (select_window_norecord
, selected_window
);
3385 select_window_norecord (window
);
3386 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook
,
3388 unbind_to (inner_count
, Qnil
);
3393 run_funs (global_wcch
);
3394 unbind_to (count
, Qnil
);
3397 DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook
,
3398 Srun_window_configuration_change_hook
, 0, 1, 0,
3399 doc
: /* Run `window-configuration-change-hook' for FRAME.
3400 If FRAME is omitted or nil, it defaults to the selected frame. */)
3403 run_window_configuration_change_hook (decode_live_frame (frame
));
3407 DEFUN ("run-window-scroll-functions", Frun_window_scroll_functions
,
3408 Srun_window_scroll_functions
, 0, 1, 0,
3409 doc
: /* Run `window-scroll-functions' for WINDOW.
3410 If WINDOW is omitted or nil, it defaults to the selected window. */)
3411 (Lisp_Object window
)
3413 if (! NILP (Vwindow_scroll_functions
))
3414 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3415 Fmarker_position (decode_live_window (window
)->start
));
3419 /* Make WINDOW display BUFFER. RUN_HOOKS_P non-zero means it's allowed
3420 to run hooks. See make_frame for a case where it's not allowed.
3421 KEEP_MARGINS_P non-zero means that the current margins, fringes, and
3422 scroll-bar settings of the window are not reset from the buffer's
3426 set_window_buffer (Lisp_Object window
, Lisp_Object buffer
,
3427 bool run_hooks_p
, bool keep_margins_p
)
3429 struct window
*w
= XWINDOW (window
);
3430 struct buffer
*b
= XBUFFER (buffer
);
3431 ptrdiff_t count
= SPECPDL_INDEX ();
3432 bool samebuf
= EQ (buffer
, w
->contents
);
3434 wset_buffer (w
, buffer
);
3436 if (EQ (window
, selected_window
))
3437 bset_last_selected_window (b
, window
);
3439 /* Let redisplay errors through. */
3440 b
->display_error_modiff
= 0;
3442 /* Update time stamps of buffer display. */
3443 if (INTEGERP (BVAR (b
, display_count
)))
3444 bset_display_count (b
, make_number (XINT (BVAR (b
, display_count
)) + 1));
3445 bset_display_time (b
, Fcurrent_time ());
3447 w
->window_end_pos
= 0;
3448 w
->window_end_vpos
= 0;
3449 w
->last_cursor_vpos
= 0;
3451 if (!(keep_margins_p
&& samebuf
))
3452 { /* If we're not actually changing the buffer, don't reset hscroll and
3453 vscroll. This case happens for example when called from
3454 change_frame_size_1, where we use a dummy call to
3455 Fset_window_buffer on the frame's selected window (and no other)
3456 just in order to run window-configuration-change-hook.
3457 Resetting hscroll and vscroll here is problematic for things like
3458 image-mode and doc-view-mode since it resets the image's position
3459 whenever we resize the frame. */
3460 w
->hscroll
= w
->min_hscroll
= 0;
3462 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3463 set_marker_restricted (w
->start
,
3464 make_number (b
->last_window_start
),
3466 w
->start_at_line_beg
= 0;
3469 /* Maybe we could move this into the `if' but it's not obviously safe and
3470 I doubt it's worth the trouble. */
3472 w
->update_mode_line
= true;
3474 /* We must select BUFFER for running the window-scroll-functions. */
3475 /* We can't check ! NILP (Vwindow_scroll_functions) here
3476 because that might itself be a local variable. */
3477 if (window_initialized
)
3479 record_unwind_current_buffer ();
3480 Fset_buffer (buffer
);
3483 XMARKER (w
->pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3485 if (!keep_margins_p
)
3487 /* Set left and right marginal area width etc. from buffer. */
3488 set_window_fringes (w
, BVAR (b
, left_fringe_width
),
3489 BVAR (b
, right_fringe_width
),
3490 BVAR (b
, fringes_outside_margins
));
3491 set_window_scroll_bars (w
, BVAR (b
, scroll_bar_width
),
3492 BVAR (b
, vertical_scroll_bar_type
), Qnil
);
3493 set_window_margins (w
, BVAR (b
, left_margin_cols
),
3494 BVAR (b
, right_margin_cols
));
3495 apply_window_adjustment (w
);
3500 if (! NILP (Vwindow_scroll_functions
))
3501 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3502 Fmarker_position (w
->start
));
3504 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w
)));
3507 unbind_to (count
, Qnil
);
3510 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3511 doc
: /* Make WINDOW display BUFFER-OR-NAME.
3512 WINDOW must be a live window and defaults to the selected one.
3513 BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
3515 Optional third argument KEEP-MARGINS non-nil means that WINDOW's current
3516 display margins, fringe widths, and scroll bar settings are preserved;
3517 the default is to reset these from the local settings for BUFFER-OR-NAME
3518 or the frame defaults. Return nil.
3520 This function throws an error when WINDOW is strongly dedicated to its
3521 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3522 already display BUFFER-OR-NAME.
3524 This function runs `window-scroll-functions' before running
3525 `window-configuration-change-hook'. */)
3526 (register Lisp_Object window
, Lisp_Object buffer_or_name
, Lisp_Object keep_margins
)
3528 register Lisp_Object tem
, buffer
;
3529 register struct window
*w
= decode_live_window (window
);
3531 XSETWINDOW (window
, w
);
3532 buffer
= Fget_buffer (buffer_or_name
);
3533 CHECK_BUFFER (buffer
);
3534 if (!BUFFER_LIVE_P (XBUFFER (buffer
)))
3535 error ("Attempt to display deleted buffer");
3539 error ("Window is deleted");
3542 if (!EQ (tem
, buffer
))
3544 if (EQ (w
->dedicated
, Qt
))
3545 /* WINDOW is strongly dedicated to its buffer, signal an
3547 error ("Window is dedicated to `%s'", SDATA (BVAR (XBUFFER (tem
), name
)));
3549 /* WINDOW is weakly dedicated to its buffer, reset
3551 wset_dedicated (w
, Qnil
);
3553 call1 (Qrecord_window_buffer
, window
);
3559 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3565 display_buffer (Lisp_Object buffer
, Lisp_Object not_this_window_p
, Lisp_Object override_frame
)
3567 return call3 (Qdisplay_buffer
, buffer
, not_this_window_p
, override_frame
);
3570 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3572 doc
: /* Force all windows to be updated on next redisplay.
3573 If optional arg OBJECT is a window, force redisplay of that window only.
3574 If OBJECT is a buffer or buffer name, force redisplay of all windows
3575 displaying that buffer. */)
3576 (Lisp_Object object
)
3580 windows_or_buffers_changed
= 29;
3581 update_mode_lines
= 28;
3585 if (WINDOWP (object
))
3587 struct window
*w
= XWINDOW (object
);
3588 mark_window_display_accurate (object
, 0);
3589 w
->update_mode_line
= 1;
3590 if (BUFFERP (w
->contents
))
3591 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
3592 update_mode_lines
= 29;
3596 if (STRINGP (object
))
3597 object
= Fget_buffer (object
);
3598 if (BUFFERP (object
) && BUFFER_LIVE_P (XBUFFER (object
))
3599 && buffer_window_count (XBUFFER (object
)))
3601 /* If buffer is live and shown in at least one window, find
3602 all windows showing this buffer and force update of them. */
3603 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3604 return NILP (object
) ? Qnil
: Qt
;
3607 /* If nothing suitable was found, just return.
3608 We could signal an error, but this feature will typically be used
3609 asynchronously in timers or process sentinels, so we don't. */
3613 /* Obsolete since 24.3. */
3615 temp_output_buffer_show (register Lisp_Object buf
)
3617 register struct buffer
*old
= current_buffer
;
3618 register Lisp_Object window
;
3619 register struct window
*w
;
3621 bset_directory (XBUFFER (buf
), BVAR (current_buffer
, directory
));
3624 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3628 set_buffer_internal (old
);
3630 if (!NILP (Vtemp_buffer_show_function
))
3631 call1 (Vtemp_buffer_show_function
, buf
);
3632 else if (WINDOW_LIVE_P (window
= display_buffer (buf
, Qnil
, Qnil
)))
3634 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3635 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3636 Vminibuf_scroll_window
= window
;
3637 w
= XWINDOW (window
);
3640 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3641 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3643 /* Run temp-buffer-show-hook, with the chosen window selected
3644 and its buffer current. */
3646 ptrdiff_t count
= SPECPDL_INDEX ();
3647 Lisp_Object prev_window
, prev_buffer
;
3648 prev_window
= selected_window
;
3649 XSETBUFFER (prev_buffer
, old
);
3651 /* Select the window that was chosen, for running the hook.
3652 Note: Both Fselect_window and select_window_norecord may
3653 set-buffer to the buffer displayed in the window,
3654 so we need to save the current buffer. --stef */
3655 record_unwind_protect (restore_buffer
, prev_buffer
);
3656 record_unwind_protect (select_window_norecord
, prev_window
);
3657 Fselect_window (window
, Qt
);
3658 Fset_buffer (w
->contents
);
3659 Frun_hooks (1, &Qtemp_buffer_show_hook
);
3660 unbind_to (count
, Qnil
);
3665 /* Make new window, have it replace WINDOW in window-tree, and make
3666 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
3667 horizontal child). */
3669 make_parent_window (Lisp_Object window
, bool horflag
)
3672 register struct window
*o
, *p
;
3674 o
= XWINDOW (window
);
3675 p
= allocate_window ();
3676 memcpy ((char *) p
+ sizeof (struct vectorlike_header
),
3677 (char *) o
+ sizeof (struct vectorlike_header
),
3678 word_size
* VECSIZE (struct window
));
3679 /* P's buffer slot may change from nil to a buffer... */
3680 adjust_window_count (p
, 1);
3681 XSETWINDOW (parent
, p
);
3683 p
->sequence_number
= ++sequence_number
;
3685 replace_window (window
, parent
, 1);
3687 wset_next (o
, Qnil
);
3688 wset_prev (o
, Qnil
);
3689 wset_parent (o
, parent
);
3690 /* ...but now P becomes an internal window. */
3691 wset_start (p
, Qnil
);
3692 wset_pointm (p
, Qnil
);
3693 wset_buffer (p
, Qnil
);
3694 wset_combination (p
, horflag
, window
);
3695 wset_combination_limit (p
, Qnil
);
3696 wset_window_parameters (p
, Qnil
);
3699 /* Make new window from scratch. */
3704 register struct window
*w
;
3706 w
= allocate_window ();
3707 /* Initialize Lisp data. Note that allocate_window initializes all
3708 Lisp data to nil, so do it only for slots which should not be nil. */
3709 wset_normal_lines (w
, make_float (1.0));
3710 wset_normal_cols (w
, make_float (1.0));
3711 wset_new_total (w
, make_number (0));
3712 wset_new_normal (w
, make_number (0));
3713 wset_new_pixel (w
, make_number (0));
3714 wset_start (w
, Fmake_marker ());
3715 wset_pointm (w
, Fmake_marker ());
3716 wset_vertical_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
->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 adjust_window_margins (w
);
3998 w
->window_end_valid
= 0;
4003 /* Set w->total_lines (w->total_cols if HORFLAG is non-zero) to
4004 w->new_total for window W and recursively all child windows of W.
4005 Also calculate and assign the new vertical (horizontal) start
4006 positions of each of these windows. */
4008 window_resize_apply_total (struct window
*w
, bool horflag
)
4013 /* Note: Assigning new_normal requires that the new total size of the
4014 parent window has been set *before*. */
4017 w
->total_cols
= XFASTINT (w
->new_total
);
4022 w
->total_lines
= XFASTINT (w
->new_total
);
4026 if (WINDOW_VERTICAL_COMBINATION_P (w
))
4027 /* W is a vertical combination. */
4029 c
= XWINDOW (w
->contents
);
4037 window_resize_apply_total (c
, horflag
);
4039 edge
= edge
+ c
->total_lines
;
4041 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4044 else if (WINDOW_HORIZONTAL_COMBINATION_P (w
))
4045 /* W is a horizontal combination. */
4047 c
= XWINDOW (w
->contents
);
4055 window_resize_apply_total (c
, horflag
);
4057 edge
= edge
+ c
->total_cols
;
4059 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4064 DEFUN ("window-resize-apply", Fwindow_resize_apply
, Swindow_resize_apply
, 0, 2, 0,
4065 doc
: /* Apply requested size values for window-tree of FRAME.
4066 If FRAME is omitted or nil, it defaults to the selected frame.
4068 Optional argument HORIZONTAL omitted or nil means apply requested
4069 height values. HORIZONTAL non-nil means apply requested width values.
4071 The requested size values are those set by `set-window-new-pixel' and
4072 `set-window-new-normal'. This function checks whether the requested
4073 values sum up to a valid window layout, recursively assigns the new
4074 sizes of all child windows and calculates and assigns the new start
4075 positions of these windows.
4077 Return t if the requested values have been applied correctly, nil
4080 Note: This function does not check any of `window-fixed-size-p',
4081 `window-min-height' or `window-min-width'. All these checks have to
4082 be applied on the Elisp level. */)
4083 (Lisp_Object frame
, Lisp_Object horizontal
)
4085 struct frame
*f
= decode_live_frame (frame
);
4086 struct window
*r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4087 bool horflag
= !NILP (horizontal
);
4089 if (!window_resize_check (r
, horflag
)
4090 || (XINT (r
->new_pixel
)
4091 != (horflag
? r
->pixel_width
: r
->pixel_height
)))
4095 window_resize_apply (r
, horflag
);
4098 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4100 adjust_frame_glyphs (f
);
4107 DEFUN ("window-resize-apply-total", Fwindow_resize_apply_total
, Swindow_resize_apply_total
, 0, 2, 0,
4108 doc
: /* Apply requested total size values for window-tree of FRAME.
4109 If FRAME is omitted or nil, it defaults to the selected frame.
4111 This function does not assign pixel or normal size values. You should
4112 have run `window-resize-apply' before running this.
4114 Optional argument HORIZONTAL omitted or nil means apply requested
4115 height values. HORIZONTAL non-nil means apply requested width
4117 (Lisp_Object frame
, Lisp_Object horizontal
)
4119 struct frame
*f
= decode_live_frame (frame
);
4120 struct window
*r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4123 /* Necessary when deleting the top-/or leftmost window. */
4125 r
->top_line
= FRAME_TOP_MARGIN (f
);
4126 window_resize_apply_total (r
, !NILP (horizontal
));
4127 /* Handle the mini window. */
4128 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
4130 struct window
*m
= XWINDOW (f
->minibuffer_window
);
4132 if (NILP (horizontal
))
4134 m
->top_line
= r
->top_line
+ r
->total_lines
;
4135 m
->total_lines
= XFASTINT (m
->new_total
);
4138 m
->total_cols
= XFASTINT (m
->new_total
);
4147 /* Resize frame F's windows when number of lines of F is set to SIZE.
4148 HORFLAG 1 means resize windows when number of columns of F is set to
4149 SIZE. PIXELWISE 1 means to interpret SIZE as pixels.
4151 This function can delete all windows but the selected one in order to
4152 satisfy the request. The result will be meaningful if and only if
4153 F's windows have meaningful sizes when you call this. */
4155 resize_frame_windows (struct frame
*f
, int size
, bool horflag
, bool pixelwise
)
4157 Lisp_Object root
= f
->root_window
;
4158 struct window
*r
= XWINDOW (root
);
4159 Lisp_Object mini
= f
->minibuffer_window
;
4161 /* old_size is the old size of the frame's root window. */
4162 int old_size
= horflag
? r
->total_cols
: r
->total_lines
;
4163 int old_pixel_size
= horflag
? r
->pixel_width
: r
->pixel_height
;
4164 /* new_size is the new size of the frame's root window. */
4165 int new_size
, new_pixel_size
;
4166 int unit
= horflag
? FRAME_COLUMN_WIDTH (f
) : FRAME_LINE_HEIGHT (f
);
4168 /* Don't let the size drop below one unit. This is more comforting
4169 when we are called from x_set_tool_bar_lines since the latter may
4170 have implicitly given us a zero or negative height. */
4173 /* Note: This does not include the size for internal borders
4174 since these are not part of the frame's text area. */
4175 new_pixel_size
= max (horflag
4178 - FRAME_TOP_MARGIN_HEIGHT (f
)
4179 - ((FRAME_HAS_MINIBUF_P (f
)
4180 && !FRAME_MINIBUF_ONLY_P (f
))
4181 ? FRAME_LINE_HEIGHT (f
) : 0)),
4183 new_size
= new_pixel_size
/ unit
;
4187 new_size
= max (horflag
4190 - FRAME_TOP_MARGIN (f
)
4191 - ((FRAME_HAS_MINIBUF_P (f
)
4192 && !FRAME_MINIBUF_ONLY_P (f
))
4195 new_pixel_size
= new_size
* unit
;
4198 r
->top_line
= FRAME_TOP_MARGIN (f
);
4199 r
->pixel_top
= FRAME_TOP_MARGIN_HEIGHT (f
);
4201 if (new_pixel_size
== old_pixel_size
)
4203 else if (WINDOW_LEAF_P (r
))
4204 /* For a leaf root window just set the size. */
4207 r
->total_cols
= new_size
;
4208 r
->pixel_width
= new_pixel_size
;
4212 r
->total_lines
= new_size
;
4213 r
->pixel_height
= new_pixel_size
;
4220 XSETINT (delta
, new_pixel_size
- old_pixel_size
);
4222 XSETINT (delta
, new_size
- old_size
);
4224 /* Try a "normal" resize first. */
4225 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qnil
,
4226 pixelwise
? Qt
: Qnil
);
4227 if (window_resize_check (r
, horflag
)
4228 && new_pixel_size
== XINT (r
->new_pixel
))
4230 window_resize_apply (r
, horflag
);
4231 window_pixel_to_total (r
->frame
, horflag
? Qt
: Qnil
);
4235 /* Try with "reasonable" minimum sizes next. */
4236 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qt
,
4237 pixelwise
? Qt
: Qnil
);
4238 if (window_resize_check (r
, horflag
)
4239 && new_pixel_size
== XINT (r
->new_pixel
))
4241 window_resize_apply (r
, horflag
);
4242 window_pixel_to_total (r
->frame
, horflag
? Qt
: Qnil
);
4246 /* Finally, try with "safe" minimum sizes. */
4247 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qsafe
,
4248 pixelwise
? Qt
: Qnil
);
4249 if (window_resize_check (r
, horflag
)
4250 && new_pixel_size
== XINT (r
->new_pixel
))
4252 window_resize_apply (r
, horflag
);
4253 window_pixel_to_total (r
->frame
, horflag
? Qt
: Qnil
);
4255 #if 0 /* Let's try without killing other windows. */
4258 /* We lost. Delete all windows but the frame's
4260 root
= f
->selected_window
;
4261 Fdelete_other_windows_internal (root
, Qnil
);
4264 XWINDOW (root
)->total_cols
= new_size
;
4265 XWINDOW (root
)->pixel_width
= new_pixel_size
;
4269 XWINDOW (root
)->total_lines
= new_size
;
4270 XWINDOW (root
)->pixel_height
= new_pixel_size
;
4278 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
4283 m
->total_cols
= size
;
4284 m
->pixel_width
= new_pixel_size
;
4288 /* Are we sure we always want 1 line here? */
4290 m
->pixel_height
= FRAME_LINE_HEIGHT (f
);
4291 m
->top_line
= r
->top_line
+ r
->total_lines
;
4292 m
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4300 DEFUN ("split-window-internal", Fsplit_window_internal
, Ssplit_window_internal
, 4, 4, 0,
4301 doc
: /* Split window OLD.
4302 Second argument PIXEL-SIZE specifies the number of pixels of the
4303 new window. In any case TOTAL-SIZE must be a positive integer.
4305 Third argument SIDE nil (or `below') specifies that the new window shall
4306 be located below WINDOW. SIDE `above' means the new window shall be
4307 located above WINDOW. In both cases PIXEL-SIZE specifies the pixel
4308 height of the new window including space reserved for the mode and/or
4311 SIDE t (or `right') specifies that the new window shall be located on
4312 the right side of WINDOW. SIDE `left' means the new window shall be
4313 located on the left of WINDOW. In both cases PIXEL-SIZE specifies the
4314 width of the new window including space reserved for fringes and the
4315 scrollbar or a divider column.
4317 Fourth argument NORMAL-SIZE specifies the normal size of the new window
4318 according to the SIDE argument.
4320 The new pixel and normal sizes of all involved windows must have been
4321 set correctly. See the code of `split-window' for how this is done. */)
4322 (Lisp_Object old
, Lisp_Object pixel_size
, Lisp_Object side
, Lisp_Object normal_size
)
4324 /* OLD (*o) is the window we have to split. (*p) is either OLD's
4325 parent window or an internal window we have to install as OLD's new
4326 parent. REFERENCE (*r) must denote a live window, or is set to OLD
4327 provided OLD is a leaf window, or to the frame's selected window.
4328 NEW (*n) is the new window created with some parameters taken from
4330 register Lisp_Object
new, frame
, reference
;
4331 register struct window
*o
, *p
, *n
, *r
, *c
;
4334 /* HORFLAG is 1 when we split side-by-side, 0 otherwise. */
4335 = EQ (side
, Qt
) || EQ (side
, Qleft
) || EQ (side
, Qright
);
4336 int combination_limit
= 0, sum
= 0;
4341 frame
= WINDOW_FRAME (o
);
4344 CHECK_NUMBER (pixel_size
);
4346 = XINT (pixel_size
) / (horflag
4347 ? FRAME_COLUMN_WIDTH (f
)
4348 : FRAME_LINE_HEIGHT (f
));
4350 /* Set combination_limit to 1 if we have to make a new parent window.
4351 We do that if either `window-combination-limit' is t, or OLD has no
4352 parent, or OLD is ortho-combined. */
4354 EQ (Vwindow_combination_limit
, Qt
)
4357 ? WINDOW_VERTICAL_COMBINATION_P (XWINDOW (o
->parent
))
4358 : WINDOW_HORIZONTAL_COMBINATION_P (XWINDOW (o
->parent
)));
4360 /* We need a live reference window to initialize some parameters. */
4361 if (WINDOW_LIVE_P (old
))
4362 /* OLD is live, use it as reference window. */
4365 /* Use the frame's selected window as reference window. */
4366 reference
= FRAME_SELECTED_WINDOW (f
);
4367 r
= XWINDOW (reference
);
4369 /* The following bugs are caught by `split-window'. */
4370 if (MINI_WINDOW_P (o
))
4371 error ("Attempt to split minibuffer window");
4372 else if (total_size
< (horflag
? 2 : 1))
4373 error ("Size of new window too small (after split)");
4374 else if (!combination_limit
&& !NILP (Vwindow_combination_resize
))
4375 /* `window-combination-resize' non-nil means try to resize OLD's siblings
4378 p
= XWINDOW (o
->parent
);
4379 /* Temporarily pretend we split the parent window. */
4381 (p
, make_number ((horflag
? p
->pixel_width
: p
->pixel_height
)
4382 - XINT (pixel_size
)));
4383 if (!window_resize_check (p
, horflag
))
4384 error ("Window sizes don't fit");
4386 /* Undo the temporary pretension. */
4387 wset_new_pixel (p
, make_number (horflag
? p
->pixel_width
: p
->pixel_height
));
4391 if (!window_resize_check (o
, horflag
))
4392 error ("Resizing old window failed");
4393 else if (XINT (pixel_size
) + XINT (o
->new_pixel
)
4394 != (horflag
? o
->pixel_width
: o
->pixel_height
))
4395 error ("Sum of sizes of old and new window don't fit");
4398 /* This is our point of no return. */
4399 if (combination_limit
)
4401 /* Save the old value of o->normal_cols/lines. It gets corrupted
4402 by make_parent_window and we need it below for assigning it to
4404 Lisp_Object new_normal
4405 = horflag
? o
->normal_cols
: o
->normal_lines
;
4407 make_parent_window (old
, horflag
);
4408 p
= XWINDOW (o
->parent
);
4409 if (EQ (Vwindow_combination_limit
, Qt
))
4410 /* Store t in the new parent's combination_limit slot to avoid
4411 that its children get merged into another window. */
4412 wset_combination_limit (p
, Qt
);
4413 /* These get applied below. */
4415 (p
, make_number (horflag
? o
->pixel_width
: o
->pixel_height
));
4417 (p
, make_number (horflag
? o
->total_cols
: o
->total_lines
));
4418 wset_new_normal (p
, new_normal
);
4421 p
= XWINDOW (o
->parent
);
4424 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4425 new = make_window ();
4427 wset_frame (n
, frame
);
4428 wset_parent (n
, o
->parent
);
4430 if (EQ (side
, Qabove
) || EQ (side
, Qleft
))
4432 wset_prev (n
, o
->prev
);
4434 wset_combination (p
, horflag
, new);
4436 wset_next (XWINDOW (n
->prev
), new);
4442 wset_next (n
, o
->next
);
4443 if (!NILP (n
->next
))
4444 wset_prev (XWINDOW (n
->next
), new);
4449 n
->window_end_valid
= 0;
4450 n
->last_cursor_vpos
= 0;
4452 /* Get special geometry settings from reference window. */
4453 n
->left_margin_cols
= r
->left_margin_cols
;
4454 n
->right_margin_cols
= r
->right_margin_cols
;
4455 n
->left_fringe_width
= r
->left_fringe_width
;
4456 n
->right_fringe_width
= r
->right_fringe_width
;
4457 n
->fringes_outside_margins
= r
->fringes_outside_margins
;
4458 n
->scroll_bar_width
= r
->scroll_bar_width
;
4459 wset_vertical_scroll_bar_type (n
, r
->vertical_scroll_bar_type
);
4461 /* Directly assign orthogonal coordinates and sizes. */
4464 n
->pixel_top
= o
->pixel_top
;
4465 n
->top_line
= o
->top_line
;
4466 n
->pixel_height
= o
->pixel_height
;
4467 n
->total_lines
= o
->total_lines
;
4471 n
->pixel_left
= o
->pixel_left
;
4472 n
->left_col
= o
->left_col
;
4473 n
->pixel_width
= o
->pixel_width
;
4474 n
->total_cols
= o
->total_cols
;
4477 /* Iso-coordinates and sizes are assigned by window_resize_apply,
4478 get them ready here. */
4479 wset_new_pixel (n
, pixel_size
);
4480 c
= XWINDOW (p
->contents
);
4484 sum
= sum
+ XINT (c
->new_total
);
4485 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4487 wset_new_total (n
, make_number ((horflag
4491 wset_new_normal (n
, normal_size
);
4494 window_resize_apply (p
, horflag
);
4495 adjust_frame_glyphs (f
);
4496 /* Set buffer of NEW to buffer of reference window. Don't run
4498 set_window_buffer (new, r
->contents
, 0, 1);
4501 /* Maybe we should run the scroll functions in Elisp (which already
4502 runs the configuration change hook). */
4503 if (! NILP (Vwindow_scroll_functions
))
4504 run_hook_with_args_2 (Qwindow_scroll_functions
, new,
4505 Fmarker_position (n
->start
));
4511 DEFUN ("delete-window-internal", Fdelete_window_internal
, Sdelete_window_internal
, 1, 1, 0,
4512 doc
: /* Remove WINDOW from its frame.
4513 WINDOW defaults to the selected window. Return nil.
4514 Signal an error when WINDOW is the only window on its frame. */)
4515 (register Lisp_Object window
)
4517 register Lisp_Object parent
, sibling
, frame
, root
;
4518 struct window
*w
, *p
, *s
, *r
;
4520 bool horflag
, before_sibling
= 0;
4522 w
= decode_any_window (window
);
4523 XSETWINDOW (window
, w
);
4524 if (NILP (w
->contents
))
4525 /* It's a no-op to delete an already deleted window. */
4530 /* Never delete a minibuffer or frame root window. */
4531 error ("Attempt to delete minibuffer or sole ordinary window");
4532 else if (NILP (w
->prev
) && NILP (w
->next
))
4533 /* Rather bow out here, this case should be handled on the Elisp
4535 error ("Attempt to delete sole window of parent");
4537 p
= XWINDOW (parent
);
4538 horflag
= WINDOW_HORIZONTAL_COMBINATION_P (p
);
4540 frame
= WINDOW_FRAME (w
);
4543 root
= FRAME_ROOT_WINDOW (f
);
4546 /* Unlink WINDOW from window tree. */
4548 /* Get SIBLING below (on the right of) WINDOW. */
4550 /* before_sibling 1 means WINDOW is the first child of its
4551 parent and thus before the sibling. */
4554 s
= XWINDOW (sibling
);
4555 wset_prev (s
, Qnil
);
4556 wset_combination (p
, horflag
, sibling
);
4559 /* Get SIBLING above (on the left of) WINDOW. */
4562 s
= XWINDOW (sibling
);
4563 wset_next (s
, w
->next
);
4564 if (!NILP (s
->next
))
4565 wset_prev (XWINDOW (s
->next
), sibling
);
4568 if (window_resize_check (r
, horflag
)
4569 && (XINT (r
->new_pixel
)
4570 == (horflag
? r
->pixel_width
: r
->pixel_height
)))
4571 /* We can delete WINDOW now. */
4576 window_resize_apply (p
, horflag
);
4577 /* If this window is referred to by the dpyinfo's mouse
4578 highlight, invalidate that slot to be safe (Bug#9904). */
4579 if (!FRAME_INITIAL_P (f
))
4581 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
4583 if (EQ (hlinfo
->mouse_face_window
, window
))
4584 hlinfo
->mouse_face_window
= Qnil
;
4588 Vwindow_list
= Qnil
;
4589 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4591 wset_next (w
, Qnil
); /* Don't delete w->next too. */
4592 free_window_matrices (w
);
4594 if (WINDOWP (w
->contents
))
4596 delete_all_child_windows (w
->contents
);
4597 wset_combination (w
, 0, Qnil
);
4602 unchain_marker (XMARKER (w
->pointm
));
4603 unchain_marker (XMARKER (w
->start
));
4604 wset_buffer (w
, Qnil
);
4607 if (NILP (s
->prev
) && NILP (s
->next
))
4608 /* A matrjoshka where SIBLING has become the only child of
4611 /* Put SIBLING into PARENT's place. */
4612 replace_window (parent
, sibling
, 0);
4613 /* Have SIBLING inherit the following three slot values from
4614 PARENT (the combination_limit slot is not inherited). */
4615 wset_normal_cols (s
, p
->normal_cols
);
4616 wset_normal_lines (s
, p
->normal_lines
);
4617 /* Mark PARENT as deleted. */
4618 wset_combination (p
, 0, Qnil
);
4619 /* Try to merge SIBLING into its new parent. */
4620 recombine_windows (sibling
);
4623 adjust_frame_glyphs (f
);
4625 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f
)))
4626 /* We deleted the frame's selected window. */
4628 /* Use the frame's first window as fallback ... */
4629 Lisp_Object new_selected_window
= Fframe_first_window (frame
);
4630 /* ... but preferably use its most recently used window. */
4631 Lisp_Object mru_window
;
4633 /* `get-mru-window' might fail for some reason so play it safe
4634 - promote the first window _without recording it_ first. */
4635 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4636 Fselect_window (new_selected_window
, Qt
);
4638 fset_selected_window (f
, new_selected_window
);
4642 /* Now look whether `get-mru-window' gets us something. */
4643 mru_window
= call1 (Qget_mru_window
, frame
);
4644 if (WINDOW_LIVE_P (mru_window
)
4645 && EQ (XWINDOW (mru_window
)->frame
, frame
))
4646 new_selected_window
= mru_window
;
4648 /* If all ended up well, we now promote the mru window. */
4649 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4650 Fselect_window (new_selected_window
, Qnil
);
4652 fset_selected_window (f
, new_selected_window
);
4657 /* Must be run by the caller:
4658 run_window_configuration_change_hook (f); */
4661 /* We failed: Relink WINDOW into window tree. */
4665 wset_prev (s
, window
);
4666 wset_combination (p
, horflag
, window
);
4670 wset_next (s
, window
);
4671 if (!NILP (w
->next
))
4672 wset_prev (XWINDOW (w
->next
), window
);
4674 error ("Deletion failed");
4680 /***********************************************************************
4681 Resizing Mini-Windows
4682 ***********************************************************************/
4684 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we
4687 grow_mini_window (struct window
*w
, int delta
, bool pixelwise
)
4689 struct frame
*f
= XFRAME (w
->frame
);
4691 Lisp_Object root
, height
;
4692 int line_height
, pixel_height
;
4694 eassert (MINI_WINDOW_P (w
));
4695 eassert (delta
>= 0);
4699 root
= FRAME_ROOT_WINDOW (f
);
4701 height
= call3 (Qwindow_resize_root_window_vertically
,
4702 root
, make_number (- delta
), pixelwise
? Qt
: Qnil
);
4703 if (INTEGERP (height
) && window_resize_check (r
, 0))
4706 window_resize_apply (r
, 0);
4710 pixel_height
= min (-XINT (height
), INT_MAX
- w
->pixel_height
);
4711 line_height
= pixel_height
/ FRAME_LINE_HEIGHT (f
);
4715 line_height
= min (-XINT (height
),
4716 ((INT_MAX
- w
->pixel_height
)
4717 / FRAME_LINE_HEIGHT (f
)));
4718 pixel_height
= line_height
* FRAME_LINE_HEIGHT (f
);
4721 /* Grow the mini-window. */
4722 w
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4723 w
->top_line
= r
->top_line
+ r
->total_lines
;
4724 /* Make sure the mini-window has always at least one line. */
4725 w
->pixel_height
= max (w
->pixel_height
+ pixel_height
,
4726 FRAME_LINE_HEIGHT (f
));
4727 w
->total_lines
= max (w
->total_lines
+ line_height
, 1);
4729 /* Enforce full redisplay of the frame. */
4730 /* FIXME: Shouldn't window--resize-root-window-vertically do it? */
4732 adjust_frame_glyphs (f
);
4738 /* Shrink mini-window W to one line. */
4740 shrink_mini_window (struct window
*w
, bool pixelwise
)
4742 struct frame
*f
= XFRAME (w
->frame
);
4744 Lisp_Object root
, delta
;
4745 EMACS_INT height
, unit
;
4747 eassert (MINI_WINDOW_P (w
));
4749 height
= pixelwise
? w
->pixel_height
: w
->total_lines
;
4750 unit
= pixelwise
? FRAME_LINE_HEIGHT (f
) : 1;
4753 root
= FRAME_ROOT_WINDOW (f
);
4755 delta
= call3 (Qwindow_resize_root_window_vertically
,
4756 root
, make_number (height
- unit
),
4757 pixelwise
? Qt
: Qnil
);
4758 if (INTEGERP (delta
) && window_resize_check (r
, 0))
4761 window_resize_apply (r
, 0);
4763 /* Shrink the mini-window. */
4764 w
->top_line
= r
->top_line
+ r
->total_lines
;
4766 w
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4767 w
->pixel_height
= FRAME_LINE_HEIGHT (f
);
4768 /* Enforce full redisplay of the frame. */
4769 /* FIXME: Shouldn't window--resize-root-window-vertically do it? */
4771 adjust_frame_glyphs (f
);
4774 /* If the above failed for whatever strange reason we must make a
4775 one window frame here. The same routine will be needed when
4776 shrinking the frame (and probably when making the initial
4777 *scratch* window). For the moment leave things as they are. */
4781 DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal
, Sresize_mini_window_internal
, 1, 1, 0,
4782 doc
: /* Resize minibuffer window WINDOW. */)
4783 (Lisp_Object window
)
4785 struct window
*w
= XWINDOW (window
);
4790 CHECK_WINDOW (window
);
4791 f
= XFRAME (w
->frame
);
4793 if (!EQ (FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
)), window
))
4794 error ("Not a valid minibuffer window");
4795 else if (FRAME_MINIBUF_ONLY_P (f
))
4796 error ("Cannot resize a minibuffer-only frame");
4798 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4799 height
= r
->pixel_height
+ w
->pixel_height
;
4800 if (window_resize_check (r
, 0)
4801 && XINT (w
->new_pixel
) > 0
4802 && height
== XINT (r
->new_pixel
) + XINT (w
->new_pixel
))
4805 window_resize_apply (r
, 0);
4807 w
->pixel_height
= XFASTINT (w
->new_pixel
);
4808 w
->total_lines
= w
->pixel_height
/ FRAME_LINE_HEIGHT (f
);
4809 w
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4810 w
->top_line
= r
->top_line
+ r
->total_lines
;
4813 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4814 adjust_frame_glyphs (f
);
4819 error ("Failed to resize minibuffer window");
4822 /* Mark window cursors off for all windows in the window tree rooted
4823 at W by setting their phys_cursor_on_p flag to zero. Called from
4824 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4825 the frame are cleared. */
4828 mark_window_cursors_off (struct window
*w
)
4832 if (WINDOWP (w
->contents
))
4833 mark_window_cursors_off (XWINDOW (w
->contents
));
4835 w
->phys_cursor_on_p
= 0;
4837 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4842 /* Return number of lines of text (not counting mode lines) in W. */
4845 window_internal_height (struct window
*w
)
4847 int ht
= w
->total_lines
;
4849 if (!MINI_WINDOW_P (w
))
4851 if (!NILP (w
->parent
)
4852 || WINDOWP (w
->contents
)
4855 || WINDOW_WANTS_MODELINE_P (w
))
4858 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4865 /************************************************************************
4867 ***********************************************************************/
4869 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4870 N screen-fulls, which is defined as the height of the window minus
4871 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4872 instead. Negative values of N mean scroll down. NOERROR non-zero
4873 means don't signal an error if we try to move over BEGV or ZV,
4877 window_scroll (Lisp_Object window
, EMACS_INT n
, bool whole
, int noerror
)
4880 n
= clip_to_bounds (INT_MIN
, n
, INT_MAX
);
4882 wset_redisplay (XWINDOW (window
));
4884 /* If we must, use the pixel-based version which is much slower than
4885 the line-based one but can handle varying line heights. */
4886 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4887 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4889 window_scroll_line_based (window
, n
, whole
, noerror
);
4892 XWINDOW (window
)->window_end_valid
= 0;
4897 /* Implementation of window_scroll that works based on pixel line
4898 heights. See the comment of window_scroll for parameter
4902 window_scroll_pixel_based (Lisp_Object window
, int n
, bool whole
, int noerror
)
4905 struct window
*w
= XWINDOW (window
);
4906 struct text_pos start
;
4907 int this_scroll_margin
;
4908 /* True if we fiddled the window vscroll field without really scrolling. */
4910 int x
, y
, rtop
, rbot
, rowh
, vpos
;
4911 void *itdata
= NULL
;
4912 int window_total_lines
;
4913 int frame_line_height
= default_line_pixel_height (w
);
4915 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4916 /* Scrolling a minibuffer window via scroll bar when the echo area
4917 shows long text sometimes resets the minibuffer contents behind
4919 if (CHARPOS (start
) > ZV
)
4920 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4922 /* If PT is not visible in WINDOW, move back one half of
4923 the screen. Allow PT to be partially visible, otherwise
4924 something like (scroll-down 1) with PT in the line before
4925 the partially visible one would recenter. */
4927 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
4929 itdata
= bidi_shelve_cache ();
4930 /* Move backward half the height of the window. Performance note:
4931 vmotion used here is about 10% faster, but would give wrong
4932 results for variable height lines. */
4933 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4934 it
.current_y
= it
.last_visible_y
;
4935 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4937 /* The function move_iterator_vertically may move over more than
4938 the specified y-distance. If it->w is small, e.g. a
4939 mini-buffer window, we may end up in front of the window's
4940 display area. Start displaying at the start of the line
4941 containing PT in this case. */
4942 if (it
.current_y
<= 0)
4944 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4945 move_it_vertically_backward (&it
, 0);
4949 start
= it
.current
.pos
;
4950 bidi_unshelve_cache (itdata
, 0);
4952 else if (auto_window_vscroll_p
)
4954 if (rtop
|| rbot
) /* partially visible */
4957 int dy
= frame_line_height
;
4958 /* In the below we divide the window box height by the
4959 frame's line height to make the result predictable when
4960 the window box is not an integral multiple of the line
4961 height. This is important to ensure we get back to the
4962 same position when scrolling up, then down. */
4964 dy
= max ((window_box_height (w
) / dy
4965 - next_screen_context_lines
) * dy
,
4971 /* Only vscroll backwards if already vscrolled forwards. */
4972 if (w
->vscroll
< 0 && rtop
> 0)
4974 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
4975 Fset_window_vscroll (window
, make_number (px
), Qt
);
4981 /* Do vscroll if already vscrolled or only display line. */
4982 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
4984 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
4985 Fset_window_vscroll (window
, make_number (px
), Qt
);
4989 /* Maybe modify window start instead of scrolling. */
4990 if (rbot
> 0 || w
->vscroll
< 0)
4994 Fset_window_vscroll (window
, make_number (0), Qt
);
4995 /* If there are other text lines above the current row,
4996 move window start to current row. Else to next row. */
4998 spos
= XINT (Fline_beginning_position (Qnil
));
5000 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
5001 set_marker_restricted (w
->start
, make_number (spos
),
5003 w
->start_at_line_beg
= 1;
5004 w
->update_mode_line
= 1;
5005 /* Set force_start so that redisplay_window will run the
5006 window-scroll-functions. */
5012 /* Cancel previous vscroll. */
5013 Fset_window_vscroll (window
, make_number (0), Qt
);
5016 itdata
= bidi_shelve_cache ();
5017 /* If scroll_preserve_screen_position is non-nil, we try to set
5018 point in the same window line as it is now, so get that line. */
5019 if (!NILP (Vscroll_preserve_screen_position
))
5021 /* We preserve the goal pixel coordinate across consecutive
5022 calls to scroll-up, scroll-down and other commands that
5023 have the `scroll-command' property. This avoids the
5024 possibility of point becoming "stuck" on a tall line when
5025 scrolling by one line. */
5026 if (window_scroll_pixel_based_preserve_y
< 0
5027 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
5028 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
5030 start_display (&it
, w
, start
);
5031 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5032 window_scroll_pixel_based_preserve_y
= it
.current_y
;
5033 window_scroll_pixel_based_preserve_x
= it
.current_x
;
5037 window_scroll_pixel_based_preserve_y
5038 = window_scroll_pixel_based_preserve_x
= -1;
5040 /* Move iterator it from start the specified distance forward or
5041 backward. The result is the new window start. */
5042 start_display (&it
, w
, start
);
5045 ptrdiff_t start_pos
= IT_CHARPOS (it
);
5046 int dy
= frame_line_height
;
5047 /* In the below we divide the window box height by the frame's
5048 line height to make the result predictable when the window
5049 box is not an integral multiple of the line height. This is
5050 important to ensure we get back to the same position when
5051 scrolling up, then down. */
5052 dy
= max ((window_box_height (w
) / dy
- next_screen_context_lines
) * dy
,
5055 /* Note that move_it_vertically always moves the iterator to the
5056 start of a line. So, if the last line doesn't have a newline,
5057 we would end up at the start of the line ending at ZV. */
5060 move_it_vertically_backward (&it
, -dy
);
5061 /* Ensure we actually do move, e.g. in case we are currently
5062 looking at an image that is taller that the window height. */
5063 while (start_pos
== IT_CHARPOS (it
)
5064 && start_pos
> BEGV
)
5065 move_it_by_lines (&it
, -1);
5069 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
5070 MOVE_TO_POS
| MOVE_TO_Y
);
5071 /* Ensure we actually do move, e.g. in case we are currently
5072 looking at an image that is taller that the window height. */
5073 while (start_pos
== IT_CHARPOS (it
)
5075 move_it_by_lines (&it
, 1);
5079 move_it_by_lines (&it
, n
);
5081 /* We failed if we find ZV is already on the screen (scrolling up,
5082 means there's nothing past the end), or if we can't start any
5083 earlier (scrolling down, means there's nothing past the top). */
5084 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
5085 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
5087 if (IT_CHARPOS (it
) == ZV
)
5089 if (it
.current_y
< it
.last_visible_y
5090 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
5091 > it
.last_visible_y
))
5093 /* The last line was only partially visible, make it fully
5095 w
->vscroll
= (it
.last_visible_y
5096 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
5097 adjust_frame_glyphs (it
.f
);
5101 bidi_unshelve_cache (itdata
, 0);
5104 else if (n
< 0) /* could happen with empty buffers */
5105 xsignal0 (Qbeginning_of_buffer
);
5107 xsignal0 (Qend_of_buffer
);
5112 if (w
->vscroll
!= 0)
5113 /* The first line was only partially visible, make it fully
5118 bidi_unshelve_cache (itdata
, 0);
5122 xsignal0 (Qbeginning_of_buffer
);
5126 /* If control gets here, then we vscrolled. */
5128 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
5130 /* Don't try to change the window start below. */
5136 ptrdiff_t pos
= IT_CHARPOS (it
);
5139 /* If in the middle of a multi-glyph character move forward to
5140 the next character. */
5141 if (in_display_vector_p (&it
))
5144 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
5147 /* Set the window start, and set up the window for redisplay. */
5148 set_marker_restricted_both (w
->start
, w
->contents
, IT_CHARPOS (it
),
5150 bytepos
= marker_byte_position (w
->start
);
5151 w
->start_at_line_beg
= (pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n');
5152 w
->update_mode_line
= 1;
5153 /* Set force_start so that redisplay_window will run the
5154 window-scroll-functions. */
5158 /* The rest of this function uses current_y in a nonstandard way,
5159 not including the height of the header line if any. */
5160 it
.current_y
= it
.vpos
= 0;
5162 /* Move PT out of scroll margins.
5163 This code wants current_y to be zero at the window start position
5164 even if there is a header line. */
5166 = w
->total_lines
* WINDOW_FRAME_LINE_HEIGHT (w
) / frame_line_height
;
5167 this_scroll_margin
= max (0, scroll_margin
);
5169 = min (this_scroll_margin
, window_total_lines
/ 4);
5170 this_scroll_margin
*= frame_line_height
;
5174 /* We moved the window start towards ZV, so PT may be now
5175 in the scroll margin at the top. */
5176 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5177 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
5178 && (NILP (Vscroll_preserve_screen_position
)
5179 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5180 /* We found PT at a legitimate height. Leave it alone. */
5182 else if (window_scroll_pixel_based_preserve_y
>= 0)
5184 /* If we have a header line, take account of it.
5185 This is necessary because we set it.current_y to 0, above. */
5186 move_it_to (&it
, -1,
5187 window_scroll_pixel_based_preserve_x
,
5188 window_scroll_pixel_based_preserve_y
5189 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
5190 -1, MOVE_TO_Y
| MOVE_TO_X
);
5191 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5195 while (it
.current_y
< this_scroll_margin
)
5197 int prev
= it
.current_y
;
5198 move_it_by_lines (&it
, 1);
5199 if (prev
== it
.current_y
)
5202 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5207 ptrdiff_t charpos
, bytepos
;
5210 /* Save our position, for the
5211 window_scroll_pixel_based_preserve_y case. */
5212 charpos
= IT_CHARPOS (it
);
5213 bytepos
= IT_BYTEPOS (it
);
5215 /* We moved the window start towards BEGV, so PT may be now
5216 in the scroll margin at the bottom. */
5217 move_it_to (&it
, PT
, -1,
5218 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
5219 - this_scroll_margin
- 1),
5221 MOVE_TO_POS
| MOVE_TO_Y
);
5223 /* Save our position, in case it's correct. */
5224 charpos
= IT_CHARPOS (it
);
5225 bytepos
= IT_BYTEPOS (it
);
5227 /* If PT is in the screen line at the last fully visible line,
5228 move_it_to will stop at X = 0 in that line, because the
5229 required Y coordinate is reached there. See if we can get to
5230 PT without descending lower in Y, and if we can, it means we
5231 reached PT before the scroll margin. */
5238 it_data
= bidi_shelve_cache ();
5239 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5240 if (IT_CHARPOS (it
) == PT
&& it
.current_y
== it2
.current_y
)
5242 charpos
= IT_CHARPOS (it
);
5243 bytepos
= IT_BYTEPOS (it
);
5244 bidi_unshelve_cache (it_data
, 1);
5249 bidi_unshelve_cache (it_data
, 0);
5253 /* See if point is on a partially visible line at the end. */
5254 if (it
.what
== IT_EOB
)
5255 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
5258 move_it_by_lines (&it
, 1);
5259 partial_p
= it
.current_y
> it
.last_visible_y
;
5262 if (charpos
== PT
&& !partial_p
5263 && (NILP (Vscroll_preserve_screen_position
)
5264 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5265 /* We found PT before we found the display margin, so PT is ok. */
5267 else if (window_scroll_pixel_based_preserve_y
>= 0)
5269 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5270 start_display (&it
, w
, start
);
5271 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
5272 here because we called start_display again and did not
5273 alter it.current_y this time. */
5274 move_it_to (&it
, -1, window_scroll_pixel_based_preserve_x
,
5275 window_scroll_pixel_based_preserve_y
, -1,
5276 MOVE_TO_Y
| MOVE_TO_X
);
5277 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5282 /* The last line was only partially visible, so back up two
5283 lines to make sure we're on a fully visible line. */
5285 move_it_by_lines (&it
, -2);
5286 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5289 /* No, the position we saved is OK, so use it. */
5290 SET_PT_BOTH (charpos
, bytepos
);
5293 bidi_unshelve_cache (itdata
, 0);
5297 /* Implementation of window_scroll that works based on screen lines.
5298 See the comment of window_scroll for parameter descriptions. */
5301 window_scroll_line_based (Lisp_Object window
, int n
, bool whole
, int noerror
)
5303 register struct window
*w
= XWINDOW (window
);
5304 /* Fvertical_motion enters redisplay, which can trigger
5305 fontification, which in turn can modify buffer text (e.g., if the
5306 fontification functions replace escape sequences with faces, as
5307 in `grep-mode-font-lock-keywords'). So we use a marker to record
5308 the old point position, to prevent crashes in SET_PT_BOTH. */
5309 Lisp_Object opoint_marker
= Fpoint_marker ();
5310 register ptrdiff_t pos
, pos_byte
;
5311 register int ht
= window_internal_height (w
);
5312 register Lisp_Object tem
;
5315 ptrdiff_t startpos
= marker_position (w
->start
);
5316 ptrdiff_t startbyte
= marker_byte_position (w
->start
);
5317 Lisp_Object original_pos
= Qnil
;
5319 /* If scrolling screen-fulls, compute the number of lines to
5320 scroll from the window's height. */
5322 n
*= max (1, ht
- next_screen_context_lines
);
5324 if (!NILP (Vscroll_preserve_screen_position
))
5326 if (window_scroll_preserve_vpos
<= 0
5327 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
5328 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
5330 struct position posit
5331 = *compute_motion (startpos
, startbyte
, 0, 0, 0,
5332 PT
, ht
, 0, -1, w
->hscroll
, 0, w
);
5333 window_scroll_preserve_vpos
= posit
.vpos
;
5334 window_scroll_preserve_hpos
= posit
.hpos
+ w
->hscroll
;
5337 original_pos
= Fcons (make_number (window_scroll_preserve_hpos
),
5338 make_number (window_scroll_preserve_vpos
));
5341 XSETFASTINT (tem
, PT
);
5342 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
5346 Fvertical_motion (make_number (- (ht
/ 2)), window
);
5348 startbyte
= PT_BYTE
;
5351 SET_PT_BOTH (startpos
, startbyte
);
5352 lose
= n
< 0 && PT
== BEGV
;
5353 Fvertical_motion (make_number (n
), window
);
5357 SET_PT_BOTH (marker_position (opoint_marker
),
5358 marker_byte_position (opoint_marker
));
5365 xsignal0 (Qbeginning_of_buffer
);
5370 /* Don't use a scroll margin that is negative or too large. */
5371 int this_scroll_margin
=
5372 max (0, min (scroll_margin
, w
->total_lines
/ 4));
5374 set_marker_restricted_both (w
->start
, w
->contents
, pos
, pos_byte
);
5375 w
->start_at_line_beg
= !NILP (bolp
);
5376 w
->update_mode_line
= 1;
5377 /* Set force_start so that redisplay_window will run
5378 the window-scroll-functions. */
5381 if (!NILP (Vscroll_preserve_screen_position
)
5382 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
5384 SET_PT_BOTH (pos
, pos_byte
);
5385 Fvertical_motion (original_pos
, window
);
5387 /* If we scrolled forward, put point enough lines down
5388 that it is outside the scroll margin. */
5393 if (this_scroll_margin
> 0)
5395 SET_PT_BOTH (pos
, pos_byte
);
5396 Fvertical_motion (make_number (this_scroll_margin
), window
);
5402 if (top_margin
<= marker_position (opoint_marker
))
5403 SET_PT_BOTH (marker_position (opoint_marker
),
5404 marker_byte_position (opoint_marker
));
5405 else if (!NILP (Vscroll_preserve_screen_position
))
5407 SET_PT_BOTH (pos
, pos_byte
);
5408 Fvertical_motion (original_pos
, window
);
5411 SET_PT (top_margin
);
5417 /* If we scrolled backward, put point near the end of the window
5418 but not within the scroll margin. */
5419 SET_PT_BOTH (pos
, pos_byte
);
5420 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
5421 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
5424 bottom_margin
= PT
+ 1;
5426 if (bottom_margin
> marker_position (opoint_marker
))
5427 SET_PT_BOTH (marker_position (opoint_marker
),
5428 marker_byte_position (opoint_marker
));
5431 if (!NILP (Vscroll_preserve_screen_position
))
5433 SET_PT_BOTH (pos
, pos_byte
);
5434 Fvertical_motion (original_pos
, window
);
5437 Fvertical_motion (make_number (-1), window
);
5446 xsignal0 (Qend_of_buffer
);
5451 /* Scroll selected_window up or down. If N is nil, scroll a
5452 screen-full which is defined as the height of the window minus
5453 next_screen_context_lines. If N is the symbol `-', scroll.
5454 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
5455 up. This is the guts of Fscroll_up and Fscroll_down. */
5458 scroll_command (Lisp_Object n
, int direction
)
5460 ptrdiff_t count
= SPECPDL_INDEX ();
5462 eassert (eabs (direction
) == 1);
5464 /* If selected window's buffer isn't current, make it current for
5465 the moment. But don't screw up if window_scroll gets an error. */
5466 if (XBUFFER (XWINDOW (selected_window
)->contents
) != current_buffer
)
5468 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5469 Fset_buffer (XWINDOW (selected_window
)->contents
);
5473 window_scroll (selected_window
, direction
, 1, 0);
5474 else if (EQ (n
, Qminus
))
5475 window_scroll (selected_window
, -direction
, 1, 0);
5478 n
= Fprefix_numeric_value (n
);
5479 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
5482 unbind_to (count
, Qnil
);
5485 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "^P",
5486 doc
: /* Scroll text of selected window upward ARG lines.
5487 If ARG is omitted or nil, scroll upward by a near full screen.
5488 A near full screen is `next-screen-context-lines' less than a full screen.
5489 Negative ARG means scroll downward.
5490 If ARG is the atom `-', scroll downward by nearly full screen.
5491 When calling from a program, supply as argument a number, nil, or `-'. */)
5494 scroll_command (arg
, 1);
5498 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "^P",
5499 doc
: /* Scroll text of selected window down ARG lines.
5500 If ARG is omitted or nil, scroll down by a near full screen.
5501 A near full screen is `next-screen-context-lines' less than a full screen.
5502 Negative ARG means scroll upward.
5503 If ARG is the atom `-', scroll upward by nearly full screen.
5504 When calling from a program, supply as argument a number, nil, or `-'. */)
5507 scroll_command (arg
, -1);
5511 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
5512 doc
: /* Return the other window for \"other window scroll\" commands.
5513 If `other-window-scroll-buffer' is non-nil, a window
5514 showing that buffer is used.
5515 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5516 specifies the window. This takes precedence over
5517 `other-window-scroll-buffer'. */)
5522 if (MINI_WINDOW_P (XWINDOW (selected_window
))
5523 && !NILP (Vminibuf_scroll_window
))
5524 window
= Vminibuf_scroll_window
;
5525 /* If buffer is specified and live, scroll that buffer. */
5526 else if (!NILP (Vother_window_scroll_buffer
)
5527 && BUFFERP (Vother_window_scroll_buffer
)
5528 && BUFFER_LIVE_P (XBUFFER (Vother_window_scroll_buffer
)))
5530 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
5532 window
= display_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
5536 /* Nothing specified; look for a neighboring window on the same
5538 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
5540 if (EQ (window
, selected_window
))
5541 /* That didn't get us anywhere; look for a window on another
5544 window
= Fnext_window (window
, Qnil
, Qt
);
5545 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
5546 && ! EQ (window
, selected_window
));
5549 CHECK_LIVE_WINDOW (window
);
5551 if (EQ (window
, selected_window
))
5552 error ("There is no other window");
5557 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
5558 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5559 A near full screen is `next-screen-context-lines' less than a full screen.
5560 The next window is the one below the current one; or the one at the top
5561 if the current one is at the bottom. Negative ARG means scroll downward.
5562 If ARG is the atom `-', scroll downward by nearly full screen.
5563 When calling from a program, supply as argument a number, nil, or `-'.
5565 If `other-window-scroll-buffer' is non-nil, scroll the window
5566 showing that buffer, popping the buffer up if necessary.
5567 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5568 specifies the window to scroll. This takes precedence over
5569 `other-window-scroll-buffer'. */)
5574 ptrdiff_t count
= SPECPDL_INDEX ();
5576 window
= Fother_window_for_scrolling ();
5577 w
= XWINDOW (window
);
5579 /* Don't screw up if window_scroll gets an error. */
5580 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5582 Fset_buffer (w
->contents
);
5583 SET_PT_BOTH (marker_position (w
->pointm
), marker_byte_position (w
->pointm
));
5586 window_scroll (window
, 1, 1, 1);
5587 else if (EQ (arg
, Qminus
))
5588 window_scroll (window
, -1, 1, 1);
5594 window_scroll (window
, XINT (arg
), 0, 1);
5597 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5598 unbind_to (count
, Qnil
);
5603 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "^P\np",
5604 doc
: /* Scroll selected window display ARG columns left.
5605 Default for ARG is window width minus 2.
5606 Value is the total amount of leftward horizontal scrolling in
5607 effect after the change.
5608 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5609 lower bound for automatic scrolling, i.e. automatic scrolling
5610 will not scroll a window to a column less than the value returned
5611 by this function. This happens in an interactive call. */)
5612 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5614 struct window
*w
= XWINDOW (selected_window
);
5615 EMACS_INT requested_arg
= (NILP (arg
)
5616 ? window_body_width (w
, 0) - 2
5617 : XINT (Fprefix_numeric_value (arg
)));
5618 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
+ requested_arg
);
5620 if (!NILP (set_minimum
))
5621 w
->min_hscroll
= w
->hscroll
;
5626 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "^P\np",
5627 doc
: /* Scroll selected window display ARG columns right.
5628 Default for ARG is window width minus 2.
5629 Value is the total amount of leftward horizontal scrolling in
5630 effect after the change.
5631 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5632 lower bound for automatic scrolling, i.e. automatic scrolling
5633 will not scroll a window to a column less than the value returned
5634 by this function. This happens in an interactive call. */)
5635 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5637 struct window
*w
= XWINDOW (selected_window
);
5638 EMACS_INT requested_arg
= (NILP (arg
)
5639 ? window_body_width (w
, 0) - 2
5640 : XINT (Fprefix_numeric_value (arg
)));
5641 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
- requested_arg
);
5643 if (!NILP (set_minimum
))
5644 w
->min_hscroll
= w
->hscroll
;
5649 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5650 doc
: /* Return the window which was selected when entering the minibuffer.
5651 Returns nil, if selected window is not a minibuffer window. */)
5654 if (minibuf_level
> 0
5655 && MINI_WINDOW_P (XWINDOW (selected_window
))
5656 && WINDOW_LIVE_P (minibuf_selected_window
))
5657 return minibuf_selected_window
;
5662 /* Value is the number of lines actually displayed in window W,
5663 as opposed to its height. */
5666 displayed_window_lines (struct window
*w
)
5669 struct text_pos start
;
5670 int height
= window_box_height (w
);
5671 struct buffer
*old_buffer
;
5673 void *itdata
= NULL
;
5675 if (XBUFFER (w
->contents
) != current_buffer
)
5677 old_buffer
= current_buffer
;
5678 set_buffer_internal (XBUFFER (w
->contents
));
5683 /* In case W->start is out of the accessible range, do something
5684 reasonable. This happens in Info mode when Info-scroll-down
5685 calls (recenter -1) while W->start is 1. */
5686 CLIP_TEXT_POS_FROM_MARKER (start
, w
->start
);
5688 itdata
= bidi_shelve_cache ();
5689 start_display (&it
, w
, start
);
5690 move_it_vertically (&it
, height
);
5691 bottom_y
= line_bottom_y (&it
);
5692 bidi_unshelve_cache (itdata
, 0);
5694 /* rms: On a non-window display,
5695 the value of it.vpos at the bottom of the screen
5696 seems to be 1 larger than window_box_height (w).
5697 This kludge fixes a bug whereby (move-to-window-line -1)
5698 when ZV is on the last screen line
5699 moves to the previous screen line instead of the last one. */
5700 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5703 /* Add in empty lines at the bottom of the window. */
5704 if (bottom_y
< height
)
5706 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5707 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5711 set_buffer_internal (old_buffer
);
5717 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5718 doc
: /* Center point in selected window and maybe redisplay frame.
5719 With a numeric prefix argument ARG, recenter putting point on screen line ARG
5720 relative to the selected window. If ARG is negative, it counts up from the
5721 bottom of the window. (ARG should be less than the height of the window.)
5723 If ARG is omitted or nil, then recenter with point on the middle line of
5724 the selected window; if the variable `recenter-redisplay' is non-nil,
5725 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5726 is set to `grow-only', this resets the tool-bar's height to the minimum
5727 height needed); if `recenter-redisplay' has the special value `tty',
5728 then only tty frames are redrawn.
5730 Just C-u as prefix means put point in the center of the window
5731 and redisplay normally--don't erase and redraw the frame. */)
5732 (register Lisp_Object arg
)
5734 struct window
*w
= XWINDOW (selected_window
);
5735 struct buffer
*buf
= XBUFFER (w
->contents
);
5736 struct buffer
*obuf
= current_buffer
;
5738 ptrdiff_t charpos
, bytepos
;
5739 EMACS_INT iarg
IF_LINT (= 0);
5740 int this_scroll_margin
;
5742 /* If redisplay is suppressed due to an error, try again. */
5743 obuf
->display_error_modiff
= 0;
5747 if (!NILP (Vrecenter_redisplay
)
5748 && (!EQ (Vrecenter_redisplay
, Qtty
)
5749 || !NILP (Ftty_type (selected_frame
))))
5753 /* Invalidate pixel data calculated for all compositions. */
5754 for (i
= 0; i
< n_compositions
; i
++)
5755 composition_table
[i
]->font
= NULL
;
5756 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
5757 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5759 Fredraw_frame (WINDOW_FRAME (w
));
5760 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5765 else if (CONSP (arg
)) /* Just C-u. */
5769 arg
= Fprefix_numeric_value (arg
);
5774 set_buffer_internal (buf
);
5776 /* Do this after making BUF current
5777 in case scroll_margin is buffer-local. */
5778 this_scroll_margin
=
5779 max (0, min (scroll_margin
, w
->total_lines
/ 4));
5781 /* Handle centering on a graphical frame specially. Such frames can
5782 have variable-height lines and centering point on the basis of
5783 line counts would lead to strange effects. */
5784 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5790 void *itdata
= bidi_shelve_cache ();
5792 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5793 start_display (&it
, w
, pt
);
5794 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5795 charpos
= IT_CHARPOS (it
);
5796 bytepos
= IT_BYTEPOS (it
);
5797 bidi_unshelve_cache (itdata
, 0);
5803 ptrdiff_t nlines
= min (PTRDIFF_MAX
, -iarg
);
5804 int extra_line_spacing
;
5805 int h
= window_box_height (w
);
5806 void *itdata
= bidi_shelve_cache ();
5808 iarg
= - max (-iarg
, this_scroll_margin
);
5810 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5811 start_display (&it
, w
, pt
);
5813 /* Be sure we have the exact height of the full line containing PT. */
5814 move_it_by_lines (&it
, 0);
5816 /* The amount of pixels we have to move back is the window
5817 height minus what's displayed in the line containing PT,
5818 and the lines below. */
5821 move_it_by_lines (&it
, nlines
);
5823 if (it
.vpos
== nlines
)
5827 /* Last line has no newline */
5828 h
-= line_bottom_y (&it
);
5832 /* Don't reserve space for extra line spacing of last line. */
5833 extra_line_spacing
= it
.max_extra_line_spacing
;
5835 /* If we can't move down NLINES lines because we hit
5836 the end of the buffer, count in some empty lines. */
5837 if (it
.vpos
< nlines
)
5840 extra_line_spacing
= it
.extra_line_spacing
;
5841 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5845 bidi_unshelve_cache (itdata
, 0);
5849 /* Now find the new top line (starting position) of the window. */
5850 start_display (&it
, w
, pt
);
5852 move_it_vertically_backward (&it
, h
);
5854 /* If extra line spacing is present, we may move too far
5855 back. This causes the last line to be only partially
5856 visible (which triggers redisplay to recenter that line
5857 in the middle), so move forward.
5858 But ignore extra line spacing on last line, as it is not
5859 considered to be part of the visible height of the line.
5861 h
+= extra_line_spacing
;
5862 while (-it
.current_y
> h
)
5863 move_it_by_lines (&it
, 1);
5865 charpos
= IT_CHARPOS (it
);
5866 bytepos
= IT_BYTEPOS (it
);
5868 bidi_unshelve_cache (itdata
, 0);
5872 struct position pos
;
5874 iarg
= max (iarg
, this_scroll_margin
);
5876 pos
= *vmotion (PT
, PT_BYTE
, -iarg
, w
);
5877 charpos
= pos
.bufpos
;
5878 bytepos
= pos
.bytepos
;
5883 struct position pos
;
5884 int ht
= window_internal_height (w
);
5891 /* Don't let it get into the margin at either top or bottom. */
5892 iarg
= clip_to_bounds (this_scroll_margin
, iarg
,
5893 ht
- this_scroll_margin
- 1);
5895 pos
= *vmotion (PT
, PT_BYTE
, - iarg
, w
);
5896 charpos
= pos
.bufpos
;
5897 bytepos
= pos
.bytepos
;
5900 /* Set the new window start. */
5901 set_marker_both (w
->start
, w
->contents
, charpos
, bytepos
);
5902 w
->window_end_valid
= 0;
5904 w
->optional_new_start
= 1;
5906 w
->start_at_line_beg
= (bytepos
== BEGV_BYTE
||
5907 FETCH_BYTE (bytepos
- 1) == '\n');
5911 set_buffer_internal (obuf
);
5915 DEFUN ("window-text-width", Fwindow_text_width
, Swindow_text_width
,
5917 doc
: /* Return the width in columns of the text display area of WINDOW.
5918 WINDOW must be a live window and defaults to the selected one.
5920 The returned width does not include dividers, scrollbars, margins,
5921 fringes, nor any partial-width columns at the right of the text
5923 (Lisp_Object window
)
5925 struct window
*w
= decode_live_window (window
);
5927 return make_number (window_box_width (w
, TEXT_AREA
)
5928 / FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
)));
5931 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5933 doc
: /* Return the height in lines of the text display area of WINDOW.
5934 WINDOW must be a live window and defaults to the selected one.
5936 The returned height does not include dividers, the mode line, any header
5937 line, nor any partial-height lines at the bottom of the text area. */)
5938 (Lisp_Object window
)
5940 struct window
*w
= decode_live_window (window
);
5942 return make_number (window_box_height (w
)
5943 / FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
)));
5946 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5948 doc
: /* Position point relative to window.
5949 ARG nil means position point at center of window.
5950 Else, ARG specifies vertical position within the window;
5951 zero means top of window, negative means relative to bottom of window. */)
5954 struct window
*w
= XWINDOW (selected_window
);
5958 int this_scroll_margin
;
5961 if (!(BUFFERP (w
->contents
) && XBUFFER (w
->contents
) == current_buffer
))
5962 /* This test is needed to make sure PT/PT_BYTE make sense in w->contents
5963 when passed below to set_marker_both. */
5964 error ("move-to-window-line called from unrelated buffer");
5966 window
= selected_window
;
5967 start
= marker_position (w
->start
);
5968 if (start
< BEGV
|| start
> ZV
)
5970 int height
= window_internal_height (w
);
5971 Fvertical_motion (make_number (- (height
/ 2)), window
);
5972 set_marker_both (w
->start
, w
->contents
, PT
, PT_BYTE
);
5973 w
->start_at_line_beg
= !NILP (Fbolp ());
5977 Fgoto_char (w
->start
);
5979 lines
= displayed_window_lines (w
);
5982 this_scroll_margin
= max (0, min (scroll_margin
, lines
/ 4));
5986 XSETFASTINT (arg
, lines
/ 2);
5989 EMACS_INT iarg
= XINT (Fprefix_numeric_value (arg
));
5992 iarg
= iarg
+ lines
;
5994 #if 0 /* This code would prevent move-to-window-line from moving point
5995 to a place inside the scroll margins (which would cause the
5996 next redisplay to scroll). I wrote this code, but then concluded
5997 it is probably better not to install it. However, it is here
5998 inside #if 0 so as not to lose it. -- rms. */
6000 /* Don't let it get into the margin at either top or bottom. */
6001 iarg
= max (iarg
, this_scroll_margin
);
6002 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
6005 arg
= make_number (iarg
);
6008 /* Skip past a partially visible first line. */
6010 XSETINT (arg
, XINT (arg
) + 1);
6012 return Fvertical_motion (arg
, window
);
6017 /***********************************************************************
6018 Window Configuration
6019 ***********************************************************************/
6021 struct save_window_data
6023 struct vectorlike_header header
;
6024 Lisp_Object selected_frame
;
6025 Lisp_Object current_window
;
6026 Lisp_Object current_buffer
;
6027 Lisp_Object minibuf_scroll_window
;
6028 Lisp_Object minibuf_selected_window
;
6029 Lisp_Object root_window
;
6030 Lisp_Object focus_frame
;
6031 /* A vector, each of whose elements is a struct saved_window
6033 Lisp_Object saved_windows
;
6035 /* All fields above are traced by the GC.
6036 From `frame-cols' down, the fields are ignored by the GC. */
6037 /* We should be able to do without the following two. */
6038 int frame_cols
, frame_lines
;
6039 /* These two should get eventually replaced by their pixel
6041 int frame_menu_bar_lines
, frame_tool_bar_lines
;
6042 int frame_text_width
, frame_text_height
;
6043 /* These are currently unused. We need them as soon as we convert
6045 int frame_menu_bar_height
, frame_tool_bar_height
;
6048 /* This is saved as a Lisp_Vector */
6051 struct vectorlike_header header
;
6053 Lisp_Object window
, buffer
, start
, pointm
, mark
;
6054 Lisp_Object pixel_left
, pixel_top
, pixel_height
, pixel_width
;
6055 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
6056 Lisp_Object normal_cols
, normal_lines
;
6057 Lisp_Object hscroll
, min_hscroll
;
6058 Lisp_Object parent
, prev
;
6059 Lisp_Object start_at_line_beg
;
6060 Lisp_Object display_table
;
6061 Lisp_Object left_margin_cols
, right_margin_cols
;
6062 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
6063 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
, dedicated
;
6064 Lisp_Object combination_limit
, window_parameters
;
6067 #define SAVED_WINDOW_N(swv,n) \
6068 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
6070 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
6071 doc
: /* Return t if OBJECT is a window-configuration object. */)
6072 (Lisp_Object object
)
6074 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
6077 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
6078 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
6079 (Lisp_Object config
)
6081 register struct save_window_data
*data
;
6082 struct Lisp_Vector
*saved_windows
;
6084 CHECK_WINDOW_CONFIGURATION (config
);
6086 data
= (struct save_window_data
*) XVECTOR (config
);
6087 saved_windows
= XVECTOR (data
->saved_windows
);
6088 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6091 /* From Chong's unwind_create_frame_1. */
6093 unwind_change_frame (Lisp_Object val
)
6095 inhibit_lisp_code
= val
;
6098 DEFUN ("set-window-configuration", Fset_window_configuration
,
6099 Sset_window_configuration
, 1, 1, 0,
6100 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
6101 CONFIGURATION must be a value previously returned
6102 by `current-window-configuration' (which see).
6103 If CONFIGURATION was made from a frame that is now deleted,
6104 only frame-independent values can be restored. In this case,
6105 the return value is nil. Otherwise the value is t. */)
6106 (Lisp_Object configuration
)
6108 register struct save_window_data
*data
;
6109 struct Lisp_Vector
*saved_windows
;
6110 Lisp_Object new_current_buffer
;
6113 ptrdiff_t old_point
= -1;
6115 CHECK_WINDOW_CONFIGURATION (configuration
);
6117 data
= (struct save_window_data
*) XVECTOR (configuration
);
6118 saved_windows
= XVECTOR (data
->saved_windows
);
6120 new_current_buffer
= data
->current_buffer
;
6121 if (!BUFFER_LIVE_P (XBUFFER (new_current_buffer
)))
6122 new_current_buffer
= Qnil
;
6125 if (XBUFFER (new_current_buffer
) == current_buffer
)
6126 /* The code further down "preserves point" by saving here PT in
6127 old_point and then setting it later back into PT. When the
6128 current-selected-window and the final-selected-window both show
6129 the current buffer, this suffers from the problem that the
6130 current PT is the window-point of the current-selected-window,
6131 while the final PT is the point of the final-selected-window, so
6132 this copy from one PT to the other would end up moving the
6133 window-point of the final-selected-window to the window-point of
6134 the current-selected-window. So we have to be careful which
6135 point of the current-buffer we copy into old_point. */
6136 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
)
6137 && WINDOWP (selected_window
)
6138 && EQ (XWINDOW (selected_window
)->contents
, new_current_buffer
)
6139 && !EQ (selected_window
, data
->current_window
))
6140 old_point
= marker_position (XWINDOW (data
->current_window
)->pointm
);
6144 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
6145 point in new_current_buffer as of the last time this buffer was
6146 used. This can be non-deterministic since it can be changed by
6147 things like jit-lock by mere temporary selection of some random
6148 window that happens to show this buffer.
6149 So if possible we want this arbitrary choice of "which point" to
6150 be the one from the to-be-selected-window so as to prevent this
6151 window's cursor from being copied from another window. */
6152 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
)
6153 /* If current_window = selected_window, its point is in BUF_PT. */
6154 && !EQ (selected_window
, data
->current_window
))
6155 old_point
= marker_position (XWINDOW (data
->current_window
)->pointm
);
6157 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
6160 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6163 /* If f is a dead frame, don't bother rebuilding its window tree.
6164 However, there is other stuff we should still try to do below. */
6165 if (FRAME_LIVE_P (f
))
6168 Lisp_Object dead_windows
= Qnil
;
6169 register Lisp_Object tem
, par
, pers
;
6170 register struct window
*w
;
6171 register struct saved_window
*p
;
6172 struct window
*root_window
;
6173 struct window
**leaf_windows
;
6177 ptrdiff_t count
= SPECPDL_INDEX ();
6178 /* If the frame has been resized since this window configuration was
6179 made, we change the frame to the size specified in the
6180 configuration, restore the configuration, and then resize it
6181 back. We keep track of the prevailing height in these variables. */
6182 int previous_frame_text_height
= FRAME_TEXT_HEIGHT (f
);
6183 int previous_frame_text_width
= FRAME_TEXT_WIDTH (f
);
6184 /* int previous_frame_menu_bar_height = FRAME_MENU_BAR_HEIGHT (f); */
6185 /* int previous_frame_tool_bar_height = FRAME_TOOL_BAR_HEIGHT (f); */
6186 /* int previous_frame_lines = FRAME_LINES (f); */
6187 /* int previous_frame_cols = FRAME_COLS (f); */
6188 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6189 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6191 /* Don't do this within the main loop below: This may call Lisp
6192 code and is thus potentially unsafe while input is blocked. */
6193 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
6195 p
= SAVED_WINDOW_N (saved_windows
, k
);
6197 w
= XWINDOW (window
);
6198 if (BUFFERP (w
->contents
)
6199 && !EQ (w
->contents
, p
->buffer
)
6200 && BUFFER_LIVE_P (XBUFFER (p
->buffer
)))
6201 /* If a window we restore gets another buffer, record the
6202 window's old buffer. */
6203 call1 (Qrecord_window_buffer
, window
);
6206 /* Don't run lisp in the following segment since the frame is in a
6207 completely inconsistent state. See Bug#16207. */
6208 record_unwind_protect (unwind_change_frame
, inhibit_lisp_code
);
6209 inhibit_lisp_code
= Qt
;
6210 /* The mouse highlighting code could get screwed up
6211 if it runs during this. */
6214 if (data
->frame_text_width
!= previous_frame_text_width
6215 || data
->frame_text_height
!= previous_frame_text_height
)
6216 change_frame_size (f
, data
->frame_text_width
,
6217 data
->frame_text_height
, 0, 0, 0, 1);
6219 if (data
->frame_menu_bar_lines
!= previous_frame_menu_bar_lines
)
6221 #ifdef HAVE_WINDOW_SYSTEM
6222 if (FRAME_WINDOW_P (f
))
6223 x_set_menu_bar_lines (f
, make_number (data
->frame_menu_bar_lines
),
6225 else /* TTY or MSDOS */
6227 set_menu_bar_lines (f
, make_number (data
->frame_menu_bar_lines
),
6230 #ifdef HAVE_WINDOW_SYSTEM
6231 if (data
->frame_tool_bar_lines
!= previous_frame_tool_bar_lines
)
6232 x_set_tool_bar_lines (f
, make_number (data
->frame_tool_bar_lines
),
6236 /* "Swap out" point from the selected window's buffer
6237 into the window itself. (Normally the pointm of the selected
6238 window holds garbage.) We do this now, before
6239 restoring the window contents, and prevent it from
6240 being done later on when we select a new window. */
6241 if (! NILP (XWINDOW (selected_window
)->contents
))
6243 w
= XWINDOW (selected_window
);
6244 set_marker_both (w
->pointm
,
6246 BUF_PT (XBUFFER (w
->contents
)),
6247 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6251 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
6253 /* Problem: Freeing all matrices and later allocating them again
6254 is a serious redisplay flickering problem. What we would
6255 really like to do is to free only those matrices not reused
6257 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6258 leaf_windows
= alloca (count_windows (root_window
)
6259 * sizeof *leaf_windows
);
6260 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
6263 Mark all windows now on frame as "deleted".
6264 Restoring the new configuration "undeletes" any that are in it.
6266 Save their current buffers in their height fields, since we may
6267 need it later, if a buffer saved in the configuration is now
6269 delete_all_child_windows (FRAME_ROOT_WINDOW (f
));
6271 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
6273 p
= SAVED_WINDOW_N (saved_windows
, k
);
6275 w
= XWINDOW (window
);
6276 wset_next (w
, Qnil
);
6278 if (!NILP (p
->parent
))
6280 (w
, SAVED_WINDOW_N (saved_windows
, XFASTINT (p
->parent
))->window
);
6282 wset_parent (w
, Qnil
);
6284 if (!NILP (p
->prev
))
6287 (w
, SAVED_WINDOW_N (saved_windows
, XFASTINT (p
->prev
))->window
);
6288 wset_next (XWINDOW (w
->prev
), p
->window
);
6292 wset_prev (w
, Qnil
);
6293 if (!NILP (w
->parent
))
6294 wset_combination (XWINDOW (w
->parent
),
6295 (XINT (p
->total_cols
)
6296 != XWINDOW (w
->parent
)->total_cols
),
6300 /* If we squirreled away the buffer, restore it now. */
6301 if (BUFFERP (w
->combination_limit
))
6302 wset_buffer (w
, w
->combination_limit
);
6303 w
->pixel_left
= XFASTINT (p
->pixel_left
);
6304 w
->pixel_top
= XFASTINT (p
->pixel_top
);
6305 w
->pixel_width
= XFASTINT (p
->pixel_width
);
6306 w
->pixel_height
= XFASTINT (p
->pixel_height
);
6307 w
->left_col
= XFASTINT (p
->left_col
);
6308 w
->top_line
= XFASTINT (p
->top_line
);
6309 w
->total_cols
= XFASTINT (p
->total_cols
);
6310 w
->total_lines
= XFASTINT (p
->total_lines
);
6311 wset_normal_cols (w
, p
->normal_cols
);
6312 wset_normal_lines (w
, p
->normal_lines
);
6313 w
->hscroll
= XFASTINT (p
->hscroll
);
6314 w
->min_hscroll
= XFASTINT (p
->min_hscroll
);
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 wset_vertical_scroll_bar_type (w
, p
->vertical_scroll_bar_type
);
6323 wset_dedicated (w
, p
->dedicated
);
6324 wset_combination_limit (w
, p
->combination_limit
);
6325 /* Restore any window parameters that have been saved.
6326 Parameters that have not been saved are left alone. */
6327 for (tem
= p
->window_parameters
; CONSP (tem
); tem
= XCDR (tem
))
6332 if (NILP (XCDR (pers
)))
6334 par
= Fassq (XCAR (pers
), w
->window_parameters
);
6335 if (CONSP (par
) && !NILP (XCDR (par
)))
6336 /* Reset a parameter to nil if and only if it
6337 has a non-nil association. Don't make new
6339 Fsetcdr (par
, Qnil
);
6342 /* Always restore a non-nil value. */
6343 Fset_window_parameter (window
, XCAR (pers
), XCDR (pers
));
6347 if (BUFFERP (p
->buffer
) && BUFFER_LIVE_P (XBUFFER (p
->buffer
)))
6348 /* If saved buffer is alive, install it. */
6350 wset_buffer (w
, p
->buffer
);
6351 w
->start_at_line_beg
= !NILP (p
->start_at_line_beg
);
6352 set_marker_restricted (w
->start
, p
->start
, w
->contents
);
6353 set_marker_restricted (w
->pointm
, p
->pointm
,
6355 Fset_marker (BVAR (XBUFFER (w
->contents
), mark
),
6356 p
->mark
, w
->contents
);
6358 /* As documented in Fcurrent_window_configuration, don't
6359 restore the location of point in the buffer which was
6360 current when the window configuration was recorded. */
6361 if (!EQ (p
->buffer
, new_current_buffer
)
6362 && XBUFFER (p
->buffer
) == current_buffer
)
6363 Fgoto_char (w
->pointm
);
6365 else if (BUFFERP (w
->contents
) && BUFFER_LIVE_P (XBUFFER (w
->contents
)))
6366 /* Keep window's old buffer; make sure the markers are real. */
6368 /* Set window markers at start of visible range. */
6369 if (XMARKER (w
->start
)->buffer
== 0)
6370 set_marker_restricted_both (w
->start
, w
->contents
, 0, 0);
6371 if (XMARKER (w
->pointm
)->buffer
== 0)
6372 set_marker_restricted_both
6373 (w
->pointm
, w
->contents
,
6374 BUF_PT (XBUFFER (w
->contents
)),
6375 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6376 w
->start_at_line_beg
= 1;
6378 else if (!NILP (w
->start
))
6379 /* Leaf window has no live buffer, get one. */
6381 /* Get the buffer via other_buffer_safely in order to
6382 avoid showing an unimportant buffer and, if necessary, to
6383 recreate *scratch* in the course (part of Juanma's bs-show
6384 scenario from March 2011). */
6385 wset_buffer (w
, other_buffer_safely (Fcurrent_buffer ()));
6386 /* This will set the markers to beginning of visible
6388 set_marker_restricted_both (w
->start
, w
->contents
, 0, 0);
6389 set_marker_restricted_both (w
->pointm
, w
->contents
, 0, 0);
6390 w
->start_at_line_beg
= 1;
6391 if (!NILP (w
->dedicated
))
6392 /* Record this window as dead. */
6393 dead_windows
= Fcons (window
, dead_windows
);
6394 /* Make sure window is no more dedicated. */
6395 wset_dedicated (w
, Qnil
);
6399 fset_root_window (f
, data
->root_window
);
6400 /* Arrange *not* to restore point in the buffer that was
6401 current when the window configuration was saved. */
6402 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
))
6403 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
6404 make_number (old_point
),
6405 XWINDOW (data
->current_window
)->contents
);
6407 /* In the following call to `select-window', prevent "swapping out
6408 point" in the old selected window using the buffer that has
6409 been restored into it. We already swapped out that point from
6410 that window's old buffer.
6412 Do not record the buffer here. We do that in a separate call
6413 to select_window below. See also Bug#16207. */
6414 select_window (data
->current_window
, Qt
, 1);
6415 BVAR (XBUFFER (XWINDOW (selected_window
)->contents
),
6416 last_selected_window
)
6419 if (NILP (data
->focus_frame
)
6420 || (FRAMEP (data
->focus_frame
)
6421 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
6422 Fredirect_frame_focus (frame
, data
->focus_frame
);
6424 /* Set the frame size to the value it had before this function. */
6425 if (previous_frame_text_width
!= FRAME_TEXT_WIDTH (f
)
6426 || previous_frame_text_height
!= FRAME_TEXT_HEIGHT (f
))
6427 change_frame_size (f
, previous_frame_text_width
,
6428 previous_frame_text_height
, 0, 0, 0, 1);
6430 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
6432 #ifdef HAVE_WINDOW_SYSTEM
6433 if (FRAME_WINDOW_P (f
))
6434 x_set_menu_bar_lines (f
,
6435 make_number (previous_frame_menu_bar_lines
),
6437 else /* TTY or MSDOS */
6439 set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
6442 #ifdef HAVE_WINDOW_SYSTEM
6443 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
6444 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
6448 /* Now, free glyph matrices in windows that were not reused. */
6449 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
6451 if (NILP (leaf_windows
[i
]->contents
))
6452 free_window_matrices (leaf_windows
[i
]);
6453 else if (EQ (leaf_windows
[i
]->contents
, new_current_buffer
))
6457 adjust_frame_glyphs (f
);
6459 unbind_to (count
, Qnil
);
6461 /* Scan dead buffer windows. */
6462 for (; CONSP (dead_windows
); dead_windows
= XCDR (dead_windows
))
6464 window
= XCAR (dead_windows
);
6465 if (WINDOW_LIVE_P (window
) && !EQ (window
, FRAME_ROOT_WINDOW (f
)))
6466 delete_deletable_window (window
);
6469 /* Record the selected window's buffer here. The window should
6470 already be the selected one from the call above. */
6471 select_window (data
->current_window
, Qnil
, 0);
6473 /* Fselect_window will have made f the selected frame, so we
6474 reselect the proper frame here. Fhandle_switch_frame will change the
6475 selected window too, but that doesn't make the call to
6476 Fselect_window above totally superfluous; it still sets f's
6478 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
6479 do_switch_frame (data
->selected_frame
, 0, 0, Qnil
);
6481 run_window_configuration_change_hook (f
);
6484 if (!NILP (new_current_buffer
))
6486 Fset_buffer (new_current_buffer
);
6487 /* If the new current buffer doesn't appear in the selected
6488 window, go to its old point (see bug#12208). */
6489 if (!EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
))
6490 Fgoto_char (make_number (old_point
));
6493 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
6494 minibuf_selected_window
= data
->minibuf_selected_window
;
6496 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
6500 restore_window_configuration (Lisp_Object configuration
)
6502 Fset_window_configuration (configuration
);
6506 /* If WINDOW is an internal window, recursively delete all child windows
6507 reachable via the next and contents slots of WINDOW. Otherwise setup
6508 WINDOW to not show any buffer. */
6511 delete_all_child_windows (Lisp_Object window
)
6513 register struct window
*w
;
6515 w
= XWINDOW (window
);
6517 if (!NILP (w
->next
))
6518 /* Delete WINDOW's siblings (we traverse postorderly). */
6519 delete_all_child_windows (w
->next
);
6521 if (WINDOWP (w
->contents
))
6523 delete_all_child_windows (w
->contents
);
6524 wset_combination (w
, 0, Qnil
);
6526 else if (BUFFERP (w
->contents
))
6529 unchain_marker (XMARKER (w
->pointm
));
6530 unchain_marker (XMARKER (w
->start
));
6531 /* Since combination limit makes sense for an internal windows
6532 only, we use this slot to save the buffer for the sake of
6533 possible resurrection in Fset_window_configuration. */
6534 wset_combination_limit (w
, w
->contents
);
6535 wset_buffer (w
, Qnil
);
6538 Vwindow_list
= Qnil
;
6542 count_windows (register struct window
*window
)
6544 register int count
= 1;
6545 if (!NILP (window
->next
))
6546 count
+= count_windows (XWINDOW (window
->next
));
6547 if (WINDOWP (window
->contents
))
6548 count
+= count_windows (XWINDOW (window
->contents
));
6553 /* Fill vector FLAT with leaf windows under W, starting at index I.
6554 Value is last index + 1. */
6556 get_leaf_windows (struct window
*w
, struct window
**flat
, int i
)
6560 if (WINDOWP (w
->contents
))
6561 i
= get_leaf_windows (XWINDOW (w
->contents
), flat
, i
);
6565 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6572 /* Return a pointer to the glyph W's physical cursor is on. Value is
6573 null if W's current matrix is invalid, so that no meaningful glyph
6576 get_phys_cursor_glyph (struct window
*w
)
6578 struct glyph_row
*row
;
6579 struct glyph
*glyph
;
6580 int hpos
= w
->phys_cursor
.hpos
;
6582 if (!(w
->phys_cursor
.vpos
>= 0
6583 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
))
6586 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
6587 if (!row
->enabled_p
)
6592 /* When the window is hscrolled, cursor hpos can legitimately be
6593 out of bounds, but we draw the cursor at the corresponding
6594 window margin in that case. */
6595 if (!row
->reversed_p
&& hpos
< 0)
6597 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
6598 hpos
= row
->used
[TEXT_AREA
] - 1;
6601 if (0 <= hpos
&& hpos
< row
->used
[TEXT_AREA
])
6602 glyph
= row
->glyphs
[TEXT_AREA
] + hpos
;
6611 save_window_save (Lisp_Object window
, struct Lisp_Vector
*vector
, int i
)
6613 register struct saved_window
*p
;
6614 register struct window
*w
;
6615 register Lisp_Object tem
, pers
, par
;
6617 for (; !NILP (window
); window
= w
->next
)
6619 p
= SAVED_WINDOW_N (vector
, i
);
6620 w
= XWINDOW (window
);
6622 wset_temslot (w
, make_number (i
)); i
++;
6624 p
->buffer
= (WINDOW_LEAF_P (w
) ? w
->contents
: Qnil
);
6625 p
->pixel_left
= make_number (w
->pixel_left
);
6626 p
->pixel_top
= make_number (w
->pixel_top
);
6627 p
->pixel_width
= make_number (w
->pixel_width
);
6628 p
->pixel_height
= make_number (w
->pixel_height
);
6629 p
->left_col
= make_number (w
->left_col
);
6630 p
->top_line
= make_number (w
->top_line
);
6631 p
->total_cols
= make_number (w
->total_cols
);
6632 p
->total_lines
= make_number (w
->total_lines
);
6633 p
->normal_cols
= w
->normal_cols
;
6634 p
->normal_lines
= w
->normal_lines
;
6635 XSETFASTINT (p
->hscroll
, w
->hscroll
);
6636 XSETFASTINT (p
->min_hscroll
, w
->min_hscroll
);
6637 p
->display_table
= w
->display_table
;
6638 p
->left_margin_cols
= make_number (w
->left_margin_cols
);
6639 p
->right_margin_cols
= make_number (w
->right_margin_cols
);
6640 p
->left_fringe_width
= make_number (w
->left_fringe_width
);
6641 p
->right_fringe_width
= make_number (w
->right_fringe_width
);
6642 p
->fringes_outside_margins
= w
->fringes_outside_margins
? Qt
: Qnil
;
6643 p
->scroll_bar_width
= make_number (w
->scroll_bar_width
);
6644 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
6645 p
->dedicated
= w
->dedicated
;
6646 p
->combination_limit
= w
->combination_limit
;
6647 p
->window_parameters
= Qnil
;
6649 if (!NILP (Vwindow_persistent_parameters
))
6651 /* Run cycle detection on Vwindow_persistent_parameters. */
6652 Lisp_Object tortoise
, hare
;
6654 hare
= tortoise
= Vwindow_persistent_parameters
;
6655 while (CONSP (hare
))
6662 tortoise
= XCDR (tortoise
);
6664 if (EQ (hare
, tortoise
))
6665 /* Reset Vwindow_persistent_parameters to Qnil. */
6667 Vwindow_persistent_parameters
= Qnil
;
6672 for (tem
= Vwindow_persistent_parameters
; CONSP (tem
);
6676 /* Save values for persistent window parameters. */
6677 if (CONSP (pers
) && !NILP (XCDR (pers
)))
6679 par
= Fassq (XCAR (pers
), w
->window_parameters
);
6681 /* If the window has no value for the parameter,
6683 p
->window_parameters
= Fcons (Fcons (XCAR (pers
), Qnil
),
6684 p
->window_parameters
);
6686 /* If the window has a value for the parameter,
6688 p
->window_parameters
= Fcons (Fcons (XCAR (par
),
6690 p
->window_parameters
);
6695 if (BUFFERP (w
->contents
))
6697 /* Save w's value of point in the window configuration. If w
6698 is the selected window, then get the value of point from
6699 the buffer; pointm is garbage in the selected window. */
6700 if (EQ (window
, selected_window
))
6701 p
->pointm
= build_marker (XBUFFER (w
->contents
),
6702 BUF_PT (XBUFFER (w
->contents
)),
6703 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6705 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
6706 XMARKER (p
->pointm
)->insertion_type
6707 = !NILP (buffer_local_value_1
/* Don't signal error if void. */
6708 (Qwindow_point_insertion_type
, w
->contents
));
6710 p
->start
= Fcopy_marker (w
->start
, Qnil
);
6711 p
->start_at_line_beg
= w
->start_at_line_beg
? Qt
: Qnil
;
6713 tem
= BVAR (XBUFFER (w
->contents
), mark
);
6714 p
->mark
= Fcopy_marker (tem
, Qnil
);
6721 p
->start_at_line_beg
= Qnil
;
6724 if (NILP (w
->parent
))
6727 p
->parent
= XWINDOW (w
->parent
)->temslot
;
6732 p
->prev
= XWINDOW (w
->prev
)->temslot
;
6734 if (WINDOWP (w
->contents
))
6735 i
= save_window_save (w
->contents
, vector
, i
);
6741 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
6742 Scurrent_window_configuration
, 0, 1, 0,
6743 doc
: /* Return an object representing the current window configuration of FRAME.
6744 If FRAME is nil or omitted, use the selected frame.
6745 This describes the number of windows, their sizes and current buffers,
6746 and for each displayed buffer, where display starts, and the positions of
6747 point and mark. An exception is made for point in the current buffer:
6748 its value is -not- saved.
6749 This also records the currently selected frame, and FRAME's focus
6750 redirection (see `redirect-frame-focus'). The variable
6751 `window-persistent-parameters' specifies which window parameters are
6752 saved by this function. */)
6755 register Lisp_Object tem
;
6756 register int n_windows
;
6757 register struct save_window_data
*data
;
6759 struct frame
*f
= decode_live_frame (frame
);
6761 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6762 data
= ALLOCATE_PSEUDOVECTOR (struct save_window_data
, frame_cols
,
6763 PVEC_WINDOW_CONFIGURATION
);
6765 data
->frame_cols
= FRAME_COLS (f
);
6766 data
->frame_lines
= FRAME_LINES (f
);
6767 data
->frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6768 data
->frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6769 data
->frame_text_width
= FRAME_TEXT_WIDTH (f
);
6770 data
->frame_text_height
= FRAME_TEXT_HEIGHT (f
);
6771 data
->frame_menu_bar_height
= FRAME_MENU_BAR_HEIGHT (f
);
6772 data
->frame_tool_bar_height
= FRAME_TOOL_BAR_HEIGHT (f
);
6773 data
->selected_frame
= selected_frame
;
6774 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6775 XSETBUFFER (data
->current_buffer
, current_buffer
);
6776 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6777 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6778 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6779 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6780 tem
= make_uninit_vector (n_windows
);
6781 data
->saved_windows
= tem
;
6782 for (i
= 0; i
< n_windows
; i
++)
6784 Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
));
6785 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6786 XSETWINDOW_CONFIGURATION (tem
, data
);
6790 /* Called after W's margins, fringes or scroll bars was adjusted. */
6793 apply_window_adjustment (struct window
*w
)
6796 adjust_window_margins (w
);
6797 clear_glyph_matrix (w
->current_matrix
);
6798 w
->window_end_valid
= 0;
6799 windows_or_buffers_changed
= 30;
6801 adjust_frame_glyphs (XFRAME (WINDOW_FRAME (w
)));
6805 /***********************************************************************
6807 ***********************************************************************/
6809 static struct window
*
6810 set_window_margins (struct window
*w
, Lisp_Object left_width
,
6811 Lisp_Object right_width
)
6815 /* FIXME: what about margins that are too wide? */
6816 left
= (NILP (left_width
) ? 0
6817 : (CHECK_NATNUM (left_width
), XINT (left_width
)));
6818 right
= (NILP (right_width
) ? 0
6819 : (CHECK_NATNUM (right_width
), XINT (right_width
)));
6821 if (w
->left_margin_cols
!= left
|| w
->right_margin_cols
!= right
)
6823 w
->left_margin_cols
= left
;
6824 w
->right_margin_cols
= right
;
6830 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6832 doc
: /* Set width of marginal areas of window WINDOW.
6833 WINDOW must be a live window and defaults to the selected one.
6835 Second arg LEFT-WIDTH specifies the number of character cells to
6836 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6837 does the same for the right marginal area. A nil width parameter
6840 Return t if any margin was actually changed and nil otherwise. */)
6841 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
)
6843 struct window
*w
= set_window_margins (decode_live_window (window
),
6844 left_width
, right_width
);
6845 return w
? (apply_window_adjustment (w
), Qt
) : Qnil
;
6849 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6851 doc
: /* Get width of marginal areas of window WINDOW.
6852 WINDOW must be a live window and defaults to the selected one.
6854 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6855 If a marginal area does not exist, its width will be returned
6857 (Lisp_Object window
)
6859 struct window
*w
= decode_live_window (window
);
6860 return Fcons (w
->left_margin_cols
6861 ? make_number (w
->left_margin_cols
) : Qnil
,
6862 w
->right_margin_cols
6863 ? make_number (w
->right_margin_cols
) : Qnil
);
6868 /***********************************************************************
6870 ***********************************************************************/
6872 static struct window
*
6873 set_window_fringes (struct window
*w
, Lisp_Object left_width
,
6874 Lisp_Object right_width
, Lisp_Object outside_margins
)
6876 int left
, right
, outside
= !NILP (outside_margins
);
6878 left
= (NILP (left_width
) ? -1
6879 : (CHECK_NATNUM (left_width
), XINT (left_width
)));
6880 right
= (NILP (right_width
) ? -1
6881 : (CHECK_NATNUM (right_width
), XINT (right_width
)));
6883 /* Do nothing on a tty or if nothing to actually change. */
6884 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6885 && (w
->left_fringe_width
!= left
6886 || w
->right_fringe_width
!= right
6887 || w
->fringes_outside_margins
!= outside
))
6889 w
->left_fringe_width
= left
;
6890 w
->right_fringe_width
= right
;
6891 w
->fringes_outside_margins
= outside
;
6897 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6899 doc
: /* Set the fringe widths of window WINDOW.
6900 WINDOW must be a live window and defaults to the selected one.
6902 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6903 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6904 fringe width. If a fringe width arg is nil, that means to use the
6905 frame's default fringe width. Default fringe widths can be set with
6906 the command `set-fringe-style'.
6907 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6908 outside of the display margins. By default, fringes are drawn between
6909 display marginal areas and the text area.
6911 Return t if any fringe was actually changed and nil otherwise. */)
6912 (Lisp_Object window
, Lisp_Object left_width
,
6913 Lisp_Object right_width
, Lisp_Object outside_margins
)
6916 = set_window_fringes (decode_live_window (window
),
6917 left_width
, right_width
, outside_margins
);
6918 return w
? (apply_window_adjustment (w
), Qt
) : Qnil
;
6922 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6924 doc
: /* Get width of fringes of window WINDOW.
6925 WINDOW must be a live window and defaults to the selected one.
6927 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6928 (Lisp_Object window
)
6930 struct window
*w
= decode_live_window (window
);
6932 return list3 (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6933 make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6934 WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
) ? Qt
: Qnil
);
6939 /***********************************************************************
6941 ***********************************************************************/
6943 static struct window
*
6944 set_window_scroll_bars (struct window
*w
, Lisp_Object width
,
6945 Lisp_Object vertical_type
, Lisp_Object horizontal_type
)
6947 int iwidth
= (NILP (width
) ? -1 : (CHECK_NATNUM (width
), XINT (width
)));
6950 vertical_type
= Qnil
;
6952 if (!(NILP (vertical_type
)
6953 || EQ (vertical_type
, Qleft
)
6954 || EQ (vertical_type
, Qright
)
6955 || EQ (vertical_type
, Qt
)))
6956 error ("Invalid type of vertical scroll bar");
6958 if (w
->scroll_bar_width
!= iwidth
6959 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6961 w
->scroll_bar_width
= iwidth
;
6962 wset_vertical_scroll_bar_type (w
, vertical_type
);
6968 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
,
6969 Sset_window_scroll_bars
, 2, 4, 0,
6970 doc
: /* Set width and type of scroll bars of window WINDOW.
6971 WINDOW must be a live window and defaults to the selected one.
6973 Second parameter WIDTH specifies the pixel width for the scroll bar.
6974 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6975 bar: left, right, or nil.
6976 If WIDTH is nil, use the frame's scroll-bar width.
6977 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6978 Fourth parameter HORIZONTAL-TYPE is currently unused.
6980 Return t if scroll bars were actually changed and nil otherwise. */)
6981 (Lisp_Object window
, Lisp_Object width
,
6982 Lisp_Object vertical_type
, Lisp_Object horizontal_type
)
6985 = set_window_scroll_bars (decode_live_window (window
),
6986 width
, vertical_type
, horizontal_type
);
6987 return w
? (apply_window_adjustment (w
), Qt
) : Qnil
;
6991 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6993 doc
: /* Get width and type of scroll bars of window WINDOW.
6994 WINDOW must be a live window and defaults to the selected one.
6996 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6997 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6999 (Lisp_Object window
)
7001 struct window
*w
= decode_live_window (window
);
7003 return list4 (make_number (WINDOW_SCROLL_BAR_AREA_WIDTH (w
)),
7004 make_number (WINDOW_SCROLL_BAR_COLS (w
)),
7005 w
->vertical_scroll_bar_type
, Qnil
);
7010 /***********************************************************************
7012 ***********************************************************************/
7014 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
7015 doc
: /* Return the amount by which WINDOW is scrolled vertically.
7016 If WINDOW is omitted or nil, it defaults to the selected window.
7017 Normally, value is a multiple of the canonical character height of WINDOW;
7018 optional second arg PIXELS-P means value is measured in pixels. */)
7019 (Lisp_Object window
, Lisp_Object pixels_p
)
7022 struct window
*w
= decode_live_window (window
);
7023 struct frame
*f
= XFRAME (w
->frame
);
7025 if (FRAME_WINDOW_P (f
))
7026 result
= (NILP (pixels_p
)
7027 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
7028 : make_number (-w
->vscroll
));
7030 result
= make_number (0);
7035 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
7037 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
7038 WINDOW nil means use the selected window. Normally, VSCROLL is a
7039 non-negative multiple of the canonical character height of WINDOW;
7040 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
7041 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
7042 corresponds to an integral number of pixels. The return value is the
7043 result of this rounding.
7044 If PIXELS-P is non-nil, the return value is VSCROLL. */)
7045 (Lisp_Object window
, Lisp_Object vscroll
, Lisp_Object pixels_p
)
7047 struct window
*w
= decode_live_window (window
);
7048 struct frame
*f
= XFRAME (w
->frame
);
7050 CHECK_NUMBER_OR_FLOAT (vscroll
);
7052 if (FRAME_WINDOW_P (f
))
7054 int old_dy
= w
->vscroll
;
7056 w
->vscroll
= - (NILP (pixels_p
)
7057 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
7058 : XFLOATINT (vscroll
));
7059 w
->vscroll
= min (w
->vscroll
, 0);
7061 if (w
->vscroll
!= old_dy
)
7063 /* Adjust glyph matrix of the frame if the virtual display
7064 area becomes larger than before. */
7065 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
7066 adjust_frame_glyphs (f
);
7068 /* Prevent redisplay shortcuts. */
7069 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
7073 return Fwindow_vscroll (window
, pixels_p
);
7077 /* Call FN for all leaf windows on frame F. FN is called with the
7078 first argument being a pointer to the leaf window, and with
7079 additional argument USER_DATA. Stops when FN returns 0. */
7082 foreach_window (struct frame
*f
, int (*fn
) (struct window
*, void *),
7085 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
7086 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
7087 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
7091 /* Helper function for foreach_window. Call FN for all leaf windows
7092 reachable from W. FN is called with the first argument being a
7093 pointer to the leaf window, and with additional argument USER_DATA.
7094 Stop when FN returns 0. Value is 0 if stopped by FN. */
7097 foreach_window_1 (struct window
*w
, int (*fn
) (struct window
*, void *), void *user_data
)
7101 for (cont
= 1; w
&& cont
;)
7103 if (WINDOWP (w
->contents
))
7104 cont
= foreach_window_1 (XWINDOW (w
->contents
), fn
, user_data
);
7106 cont
= fn (w
, user_data
);
7108 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
7114 /***********************************************************************
7116 ***********************************************************************/
7118 /* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2
7119 describe the same state of affairs. This is used by Fequal.
7121 IGNORE_POSITIONS means ignore non-matching scroll positions
7124 This ignores a couple of things like the dedication status of
7125 window, combination_limit and the like. This might have to be
7129 compare_window_configurations (Lisp_Object configuration1
,
7130 Lisp_Object configuration2
,
7131 bool ignore_positions
)
7133 register struct save_window_data
*d1
, *d2
;
7134 struct Lisp_Vector
*sws1
, *sws2
;
7137 CHECK_WINDOW_CONFIGURATION (configuration1
);
7138 CHECK_WINDOW_CONFIGURATION (configuration2
);
7140 d1
= (struct save_window_data
*) XVECTOR (configuration1
);
7141 d2
= (struct save_window_data
*) XVECTOR (configuration2
);
7142 sws1
= XVECTOR (d1
->saved_windows
);
7143 sws2
= XVECTOR (d2
->saved_windows
);
7145 /* Frame settings must match. */
7146 if (d1
->frame_cols
!= d2
->frame_cols
7147 || d1
->frame_lines
!= d2
->frame_lines
7148 || d1
->frame_menu_bar_lines
!= d2
->frame_menu_bar_lines
7149 || !EQ (d1
->selected_frame
, d2
->selected_frame
)
7150 || !EQ (d1
->current_buffer
, d2
->current_buffer
)
7151 || (!ignore_positions
7152 && (!EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
)
7153 || !EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
)))
7154 || !EQ (d1
->focus_frame
, d2
->focus_frame
)
7155 /* Verify that the two configurations have the same number of windows. */
7156 || sws1
->header
.size
!= sws2
->header
.size
)
7159 for (i
= 0; i
< sws1
->header
.size
; i
++)
7161 struct saved_window
*sw1
, *sw2
;
7163 sw1
= SAVED_WINDOW_N (sws1
, i
);
7164 sw2
= SAVED_WINDOW_N (sws2
, i
);
7167 /* The "current" windows in the two configurations must
7168 correspond to each other. */
7169 EQ (d1
->current_window
, sw1
->window
)
7170 != EQ (d2
->current_window
, sw2
->window
)
7171 /* Windows' buffers must match. */
7172 || !EQ (sw1
->buffer
, sw2
->buffer
)
7173 || !EQ (sw1
->pixel_left
, sw2
->pixel_left
)
7174 || !EQ (sw1
->pixel_top
, sw2
->pixel_top
)
7175 || !EQ (sw1
->pixel_height
, sw2
->pixel_height
)
7176 || !EQ (sw1
->pixel_width
, sw2
->pixel_width
)
7177 || !EQ (sw1
->left_col
, sw2
->left_col
)
7178 || !EQ (sw1
->top_line
, sw2
->top_line
)
7179 || !EQ (sw1
->total_cols
, sw2
->total_cols
)
7180 || !EQ (sw1
->total_lines
, sw2
->total_lines
)
7181 || !EQ (sw1
->display_table
, sw2
->display_table
)
7182 /* The next two disjuncts check the window structure for
7184 || !EQ (sw1
->parent
, sw2
->parent
)
7185 || !EQ (sw1
->prev
, sw2
->prev
)
7186 || (!ignore_positions
7187 && (!EQ (sw1
->hscroll
, sw2
->hscroll
)
7188 || !EQ (sw1
->min_hscroll
, sw2
->min_hscroll
)
7189 || !EQ (sw1
->start_at_line_beg
, sw2
->start_at_line_beg
)
7190 || NILP (Fequal (sw1
->start
, sw2
->start
))
7191 || NILP (Fequal (sw1
->pointm
, sw2
->pointm
))
7192 || NILP (Fequal (sw1
->mark
, sw2
->mark
))))
7193 || !EQ (sw1
->left_margin_cols
, sw2
->left_margin_cols
)
7194 || !EQ (sw1
->right_margin_cols
, sw2
->right_margin_cols
)
7195 || !EQ (sw1
->left_fringe_width
, sw2
->left_fringe_width
)
7196 || !EQ (sw1
->right_fringe_width
, sw2
->right_fringe_width
)
7197 || !EQ (sw1
->fringes_outside_margins
, sw2
->fringes_outside_margins
)
7198 || !EQ (sw1
->scroll_bar_width
, sw2
->scroll_bar_width
)
7199 || !EQ (sw1
->vertical_scroll_bar_type
, sw2
->vertical_scroll_bar_type
))
7206 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
7207 Scompare_window_configurations
, 2, 2, 0,
7208 doc
: /* Compare two window configurations as regards the structure of windows.
7209 This function ignores details such as the values of point and mark
7210 and scrolling positions. */)
7211 (Lisp_Object x
, Lisp_Object y
)
7213 if (compare_window_configurations (x
, y
, 1))
7219 init_window_once (void)
7221 struct frame
*f
= make_initial_frame ();
7222 XSETFRAME (selected_frame
, f
);
7223 Vterminal_frame
= selected_frame
;
7224 minibuf_window
= f
->minibuffer_window
;
7225 selected_window
= f
->selected_window
;
7227 window_initialized
= 1;
7233 Vwindow_list
= Qnil
;
7237 syms_of_window (void)
7239 DEFSYM (Qscroll_up
, "scroll-up");
7240 DEFSYM (Qscroll_down
, "scroll-down");
7241 DEFSYM (Qscroll_command
, "scroll-command");
7243 Fput (Qscroll_up
, Qscroll_command
, Qt
);
7244 Fput (Qscroll_down
, Qscroll_command
, Qt
);
7246 DEFSYM (Qwindow_configuration_change_hook
, "window-configuration-change-hook");
7247 DEFSYM (Qwindowp
, "windowp");
7248 DEFSYM (Qwindow_configuration_p
, "window-configuration-p");
7249 DEFSYM (Qwindow_live_p
, "window-live-p");
7250 DEFSYM (Qwindow_valid_p
, "window-valid-p");
7251 DEFSYM (Qwindow_deletable_p
, "window-deletable-p");
7252 DEFSYM (Qdelete_window
, "delete-window");
7253 DEFSYM (Qwindow_resize_root_window
, "window--resize-root-window");
7254 DEFSYM (Qwindow_resize_root_window_vertically
, "window--resize-root-window-vertically");
7255 DEFSYM (Qwindow_pixel_to_total
, "window--pixel-to-total");
7256 DEFSYM (Qsafe
, "safe");
7257 DEFSYM (Qdisplay_buffer
, "display-buffer");
7258 DEFSYM (Qreplace_buffer_in_windows
, "replace-buffer-in-windows");
7259 DEFSYM (Qrecord_window_buffer
, "record-window-buffer");
7260 DEFSYM (Qget_mru_window
, "get-mru-window");
7261 DEFSYM (Qwindow_size
, "window-size");
7262 DEFSYM (Qtemp_buffer_show_hook
, "temp-buffer-show-hook");
7263 DEFSYM (Qabove
, "above");
7264 DEFSYM (Qbelow
, "below");
7265 DEFSYM (Qclone_of
, "clone-of");
7266 DEFSYM (Qfloor
, "floor");
7267 DEFSYM (Qceiling
, "ceiling");
7269 staticpro (&Vwindow_list
);
7271 minibuf_selected_window
= Qnil
;
7272 staticpro (&minibuf_selected_window
);
7274 window_scroll_pixel_based_preserve_x
= -1;
7275 window_scroll_pixel_based_preserve_y
= -1;
7276 window_scroll_preserve_hpos
= -1;
7277 window_scroll_preserve_vpos
= -1;
7279 DEFVAR_LISP ("temp-buffer-show-function", Vtemp_buffer_show_function
,
7280 doc
: /* Non-nil means call as function to display a help buffer.
7281 The function is called with one argument, the buffer to be displayed.
7282 Used by `with-output-to-temp-buffer'.
7283 If this function is used, then it must do the entire job of showing
7284 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
7285 Vtemp_buffer_show_function
= Qnil
;
7287 DEFVAR_LISP ("minibuffer-scroll-window", Vminibuf_scroll_window
,
7288 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
7289 Vminibuf_scroll_window
= Qnil
;
7291 DEFVAR_BOOL ("mode-line-in-non-selected-windows", mode_line_in_non_selected_windows
,
7292 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
7293 If the minibuffer is active, the `minibuffer-scroll-window' mode line
7294 is displayed in the `mode-line' face. */);
7295 mode_line_in_non_selected_windows
= 1;
7297 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer
,
7298 doc
: /* If this is a live buffer, \\[scroll-other-window] should scroll its window. */);
7299 Vother_window_scroll_buffer
= Qnil
;
7301 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p
,
7302 doc
: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
7303 auto_window_vscroll_p
= 1;
7305 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines
,
7306 doc
: /* Number of lines of continuity when scrolling by screenfuls. */);
7307 next_screen_context_lines
= 2;
7309 DEFVAR_LISP ("scroll-preserve-screen-position",
7310 Vscroll_preserve_screen_position
,
7311 doc
: /* Controls if scroll commands move point to keep its screen position unchanged.
7312 A value of nil means point does not keep its screen position except
7313 at the scroll margin or window boundary respectively.
7314 A value of t means point keeps its screen position if the scroll
7315 command moved it vertically out of the window, e.g. when scrolling
7317 Any other value means point always keeps its screen position.
7318 Scroll commands should have the `scroll-command' property
7319 on their symbols to be controlled by this variable. */);
7320 Vscroll_preserve_screen_position
= Qnil
;
7322 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type
,
7323 doc
: /* Type of marker to use for `window-point'. */);
7324 Vwindow_point_insertion_type
= Qnil
;
7325 DEFSYM (Qwindow_point_insertion_type
, "window_point_insertion_type");
7327 DEFVAR_LISP ("window-configuration-change-hook",
7328 Vwindow_configuration_change_hook
,
7329 doc
: /* Functions to call when window configuration changes.
7330 The buffer-local part is run once per window, with the relevant window
7331 selected; while the global part is run only once for the modified frame,
7332 with the relevant frame selected. */);
7333 Vwindow_configuration_change_hook
= Qnil
;
7335 DEFVAR_LISP ("recenter-redisplay", Vrecenter_redisplay
,
7336 doc
: /* Non-nil means `recenter' redraws entire frame.
7337 If this option is non-nil, then the `recenter' command with a nil
7338 argument will redraw the entire frame; the special value `tty' causes
7339 the frame to be redrawn only if it is a tty frame. */);
7340 Vrecenter_redisplay
= Qtty
;
7342 DEFVAR_LISP ("window-combination-resize", Vwindow_combination_resize
,
7343 doc
: /* If t, resize window combinations proportionally.
7344 If this variable is nil, splitting a window gets the entire screen space
7345 for displaying the new window from the window to split. Deleting and
7346 resizing a window preferably resizes one adjacent window only.
7348 If this variable is t, splitting a window tries to get the space
7349 proportionally from all windows in the same combination. This also
7350 allows to split a window that is otherwise too small or of fixed size.
7351 Resizing and deleting a window proportionally resize all windows in the
7354 Other values are reserved for future use.
7356 This variable takes no effect if the variable `window-combination-limit' is
7358 Vwindow_combination_resize
= Qnil
;
7360 DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit
,
7361 doc
: /* If non-nil, splitting a window makes a new parent window.
7362 The following values are recognized:
7364 nil means splitting a window will create a new parent window only if the
7365 window has no parent window or the window shall become part of a
7366 combination orthogonal to the one it is part of.
7368 `window-size' means that splitting a window for displaying a buffer
7369 makes a new parent window provided `display-buffer' is supposed to
7370 explicitly set the window's size due to the presence of a
7371 `window-height' or `window-width' entry in the alist used by
7372 `display-buffer'. Otherwise, this value is handled like nil.
7374 `temp-buffer' means that splitting a window for displaying a temporary
7375 buffer always makes a new parent window. Otherwise, this value is
7378 `display-buffer' means that splitting a window for displaying a buffer
7379 always makes a new parent window. Since temporary buffers are
7380 displayed by the function `display-buffer', this value is stronger
7381 than `temp-buffer'. Splitting a window for other purpose makes a
7382 new parent window only if needed.
7384 t means that splitting a window always creates a new parent window. If
7385 all splits behave this way, each frame's window tree is a binary
7386 tree and every window but the frame's root window has exactly one
7389 Other values are reserved for future use. */);
7390 Vwindow_combination_limit
= Qwindow_size
;
7392 DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters
,
7393 doc
: /* Alist of persistent window parameters.
7394 This alist specifies which window parameters shall get saved by
7395 `current-window-configuration' and `window-state-get' and subsequently
7396 restored to their previous values by `set-window-configuration' and
7399 The car of each entry of this alist is the symbol specifying the
7400 parameter. The cdr is one of the following:
7402 nil means the parameter is neither saved by `window-state-get' nor by
7403 `current-window-configuration'.
7405 t means the parameter is saved by `current-window-configuration' and,
7406 provided its WRITABLE argument is nil, by `window-state-get'.
7408 The symbol `writable' means the parameter is saved unconditionally by
7409 both `current-window-configuration' and `window-state-get'. Do not use
7410 this value for parameters without read syntax (like windows or frames).
7412 Parameters not saved by `current-window-configuration' or
7413 `window-state-get' are left alone by `set-window-configuration'
7414 respectively are not installed by `window-state-put'. */);
7415 Vwindow_persistent_parameters
= list1 (Fcons (Qclone_of
, Qt
));
7417 DEFVAR_BOOL ("window-resize-pixelwise", window_resize_pixelwise
,
7418 doc
: /* Non-nil means resize windows pixelwise.
7419 This currently affects the functions: `split-window', `maximize-window',
7420 `minimize-window', `fit-window-to-buffer' and `fit-frame-to-buffer', and
7421 all functions that symmetrically resize a parent window.
7423 Note that when a frame's pixel size is not a multiple of the
7424 frame's character size, at least one window may get resized
7425 pixelwise even if this option is nil. */);
7426 window_resize_pixelwise
= 0;
7428 defsubr (&Sselected_window
);
7429 defsubr (&Sminibuffer_window
);
7430 defsubr (&Swindow_minibuffer_p
);
7431 defsubr (&Swindowp
);
7432 defsubr (&Swindow_valid_p
);
7433 defsubr (&Swindow_live_p
);
7434 defsubr (&Swindow_frame
);
7435 defsubr (&Sframe_root_window
);
7436 defsubr (&Sframe_first_window
);
7437 defsubr (&Sframe_selected_window
);
7438 defsubr (&Sset_frame_selected_window
);
7439 defsubr (&Spos_visible_in_window_p
);
7440 defsubr (&Swindow_line_height
);
7441 defsubr (&Swindow_buffer
);
7442 defsubr (&Swindow_parent
);
7443 defsubr (&Swindow_top_child
);
7444 defsubr (&Swindow_left_child
);
7445 defsubr (&Swindow_next_sibling
);
7446 defsubr (&Swindow_prev_sibling
);
7447 defsubr (&Swindow_combination_limit
);
7448 defsubr (&Sset_window_combination_limit
);
7449 defsubr (&Swindow_use_time
);
7450 defsubr (&Swindow_pixel_width
);
7451 defsubr (&Swindow_pixel_height
);
7452 defsubr (&Swindow_total_width
);
7453 defsubr (&Swindow_total_height
);
7454 defsubr (&Swindow_normal_size
);
7455 defsubr (&Swindow_new_pixel
);
7456 defsubr (&Swindow_new_total
);
7457 defsubr (&Swindow_new_normal
);
7458 defsubr (&Swindow_pixel_left
);
7459 defsubr (&Swindow_pixel_top
);
7460 defsubr (&Swindow_left_column
);
7461 defsubr (&Swindow_top_line
);
7462 defsubr (&Sset_window_new_pixel
);
7463 defsubr (&Sset_window_new_total
);
7464 defsubr (&Sset_window_new_normal
);
7465 defsubr (&Swindow_resize_apply
);
7466 defsubr (&Swindow_resize_apply_total
);
7467 defsubr (&Swindow_body_height
);
7468 defsubr (&Swindow_body_width
);
7469 defsubr (&Swindow_hscroll
);
7470 defsubr (&Sset_window_hscroll
);
7471 defsubr (&Swindow_redisplay_end_trigger
);
7472 defsubr (&Sset_window_redisplay_end_trigger
);
7473 defsubr (&Swindow_edges
);
7474 defsubr (&Swindow_pixel_edges
);
7475 defsubr (&Swindow_absolute_pixel_edges
);
7476 defsubr (&Swindow_mode_line_height
);
7477 defsubr (&Swindow_header_line_height
);
7478 defsubr (&Swindow_right_divider_width
);
7479 defsubr (&Swindow_bottom_divider_width
);
7480 defsubr (&Swindow_scroll_bar_width
);
7481 defsubr (&Swindow_inside_edges
);
7482 defsubr (&Swindow_inside_pixel_edges
);
7483 defsubr (&Swindow_inside_absolute_pixel_edges
);
7484 defsubr (&Scoordinates_in_window_p
);
7485 defsubr (&Swindow_at
);
7486 defsubr (&Swindow_point
);
7487 defsubr (&Swindow_start
);
7488 defsubr (&Swindow_end
);
7489 defsubr (&Sset_window_point
);
7490 defsubr (&Sset_window_start
);
7491 defsubr (&Swindow_dedicated_p
);
7492 defsubr (&Sset_window_dedicated_p
);
7493 defsubr (&Swindow_display_table
);
7494 defsubr (&Sset_window_display_table
);
7495 defsubr (&Snext_window
);
7496 defsubr (&Sprevious_window
);
7497 defsubr (&Sget_buffer_window
);
7498 defsubr (&Sdelete_other_windows_internal
);
7499 defsubr (&Sdelete_window_internal
);
7500 defsubr (&Sresize_mini_window_internal
);
7501 defsubr (&Sset_window_buffer
);
7502 defsubr (&Srun_window_configuration_change_hook
);
7503 defsubr (&Srun_window_scroll_functions
);
7504 defsubr (&Sselect_window
);
7505 defsubr (&Sforce_window_update
);
7506 defsubr (&Ssplit_window_internal
);
7507 defsubr (&Sscroll_up
);
7508 defsubr (&Sscroll_down
);
7509 defsubr (&Sscroll_left
);
7510 defsubr (&Sscroll_right
);
7511 defsubr (&Sother_window_for_scrolling
);
7512 defsubr (&Sscroll_other_window
);
7513 defsubr (&Sminibuffer_selected_window
);
7514 defsubr (&Srecenter
);
7515 defsubr (&Swindow_text_width
);
7516 defsubr (&Swindow_text_height
);
7517 defsubr (&Smove_to_window_line
);
7518 defsubr (&Swindow_configuration_p
);
7519 defsubr (&Swindow_configuration_frame
);
7520 defsubr (&Sset_window_configuration
);
7521 defsubr (&Scurrent_window_configuration
);
7522 defsubr (&Sset_window_margins
);
7523 defsubr (&Swindow_margins
);
7524 defsubr (&Sset_window_fringes
);
7525 defsubr (&Swindow_fringes
);
7526 defsubr (&Sset_window_scroll_bars
);
7527 defsubr (&Swindow_scroll_bars
);
7528 defsubr (&Swindow_vscroll
);
7529 defsubr (&Sset_window_vscroll
);
7530 defsubr (&Scompare_window_configurations
);
7531 defsubr (&Swindow_list
);
7532 defsubr (&Swindow_list_1
);
7533 defsubr (&Swindow_prev_buffers
);
7534 defsubr (&Sset_window_prev_buffers
);
7535 defsubr (&Swindow_next_buffers
);
7536 defsubr (&Sset_window_next_buffers
);
7537 defsubr (&Swindow_parameters
);
7538 defsubr (&Swindow_parameter
);
7539 defsubr (&Sset_window_parameter
);
7543 keys_of_window (void)
7545 initial_define_key (control_x_map
, '<', "scroll-left");
7546 initial_define_key (control_x_map
, '>', "scroll-right");
7548 initial_define_key (global_map
, Ctl ('V'), "scroll-up-command");
7549 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
7550 initial_define_key (meta_map
, 'v', "scroll-down-command");