1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985-1987, 1993-1998, 2000-2015 Free Software
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
35 #include "dispextern.h"
36 #include "blockinput.h"
37 #include "termhooks.h" /* For FRAME_TERMINAL. */
38 #ifdef HAVE_WINDOW_SYSTEM
40 #endif /* HAVE_WINDOW_SYSTEM */
45 static ptrdiff_t count_windows (struct window
*);
46 static ptrdiff_t get_leaf_windows (struct window
*, struct window
**,
48 static void window_scroll_pixel_based (Lisp_Object
, int, bool, bool);
49 static void window_scroll_line_based (Lisp_Object
, int, bool, bool);
50 static void foreach_window (struct frame
*,
51 bool (* fn
) (struct window
*, void *),
53 static bool foreach_window_1 (struct window
*,
54 bool (* fn
) (struct window
*, void *),
56 static bool window_resize_check (struct window
*, bool);
57 static void window_resize_apply (struct window
*, bool);
58 static void select_window_1 (Lisp_Object
, bool);
60 static struct window
*set_window_fringes (struct window
*, Lisp_Object
,
61 Lisp_Object
, Lisp_Object
);
62 static struct window
*set_window_margins (struct window
*, Lisp_Object
,
64 static struct window
*set_window_scroll_bars (struct window
*, Lisp_Object
,
65 Lisp_Object
, Lisp_Object
,
67 static void apply_window_adjustment (struct window
*);
69 /* This is the window in which the terminal's cursor should
70 be left when nothing is being done with it. This must
71 always be a leaf window, and its buffer is selected by
72 the top level editing loop at the end of each command.
74 This value is always the same as
75 FRAME_SELECTED_WINDOW (selected_frame). */
76 Lisp_Object selected_window
;
78 /* A list of all windows for use by next_window and Fwindow_list.
79 Functions creating or deleting windows should invalidate this cache
80 by setting it to nil. */
81 Lisp_Object Vwindow_list
;
83 /* The mini-buffer window of the selected frame.
84 Note that you cannot test for mini-bufferness of an arbitrary window
85 by comparing against this; but you can test for mini-bufferness of
86 the selected window. */
87 Lisp_Object minibuf_window
;
89 /* Non-nil means it is the window whose mode line should be
90 shown as the selected window when the minibuffer is selected. */
91 Lisp_Object minibuf_selected_window
;
93 /* Incremented for each window created. */
94 static EMACS_INT sequence_number
;
96 /* Used by the function window_scroll_pixel_based. */
97 static int window_scroll_pixel_based_preserve_x
;
98 static int window_scroll_pixel_based_preserve_y
;
100 /* Same for window_scroll_line_based. */
101 static EMACS_INT window_scroll_preserve_hpos
;
102 static EMACS_INT window_scroll_preserve_vpos
;
105 CHECK_WINDOW_CONFIGURATION (Lisp_Object x
)
107 CHECK_TYPE (WINDOW_CONFIGURATIONP (x
), Qwindow_configuration_p
, x
);
110 /* These setters are used only in this file, so they can be private. */
112 wset_combination_limit (struct window
*w
, Lisp_Object val
)
114 w
->combination_limit
= val
;
118 wset_dedicated (struct window
*w
, Lisp_Object val
)
124 wset_display_table (struct window
*w
, Lisp_Object val
)
126 w
->display_table
= val
;
130 wset_new_normal (struct window
*w
, Lisp_Object val
)
136 wset_new_total (struct window
*w
, Lisp_Object val
)
142 wset_normal_cols (struct window
*w
, Lisp_Object val
)
144 w
->normal_cols
= val
;
148 wset_normal_lines (struct window
*w
, Lisp_Object val
)
150 w
->normal_lines
= val
;
154 wset_parent (struct window
*w
, Lisp_Object val
)
160 wset_pointm (struct window
*w
, Lisp_Object val
)
166 wset_old_pointm (struct window
*w
, Lisp_Object val
)
172 wset_start (struct window
*w
, Lisp_Object val
)
178 wset_temslot (struct window
*w
, Lisp_Object val
)
184 wset_vertical_scroll_bar_type (struct window
*w
, Lisp_Object val
)
186 w
->vertical_scroll_bar_type
= val
;
190 wset_window_parameters (struct window
*w
, Lisp_Object val
)
192 w
->window_parameters
= val
;
196 wset_combination (struct window
*w
, bool horflag
, Lisp_Object val
)
198 /* Since leaf windows never becomes non-leaf, there should
199 be no buffer and markers in start and pointm fields of W. */
200 eassert (!BUFFERP (w
->contents
) && NILP (w
->start
) && NILP (w
->pointm
));
202 /* When an internal window is deleted and VAL is nil, HORFLAG
205 w
->horizontal
= horflag
;
209 wset_update_mode_line (struct window
*w
)
211 /* If this window is the selected window on its frame, set the
212 global variable update_mode_lines, so that x_consider_frame_title
213 will consider this frame's title for redisplay. */
214 Lisp_Object fselected_window
= XFRAME (WINDOW_FRAME (w
))->selected_window
;
216 if (WINDOWP (fselected_window
) && XWINDOW (fselected_window
) == w
)
217 update_mode_lines
= 42;
219 w
->update_mode_line
= true;
222 /* True if leaf window W doesn't reflect the actual state
223 of displayed buffer due to its text or overlays change. */
226 window_outdated (struct window
*w
)
228 struct buffer
*b
= XBUFFER (w
->contents
);
229 return (w
->last_modified
< BUF_MODIFF (b
)
230 || w
->last_overlay_modified
< BUF_OVERLAY_MODIFF (b
));
234 decode_live_window (register Lisp_Object window
)
237 return XWINDOW (selected_window
);
239 CHECK_LIVE_WINDOW (window
);
240 return XWINDOW (window
);
244 decode_any_window (register Lisp_Object window
)
249 return XWINDOW (selected_window
);
251 CHECK_WINDOW (window
);
252 w
= XWINDOW (window
);
256 static struct window
*
257 decode_valid_window (register Lisp_Object window
)
262 return XWINDOW (selected_window
);
264 CHECK_VALID_WINDOW (window
);
265 w
= XWINDOW (window
);
269 /* Called when W's buffer slot is changed. ARG -1 means that W is about to
270 cease its buffer, and 1 means that W is about to set up the new one. */
273 adjust_window_count (struct window
*w
, int arg
)
275 eassert (eabs (arg
) == 1);
276 if (BUFFERP (w
->contents
))
278 struct buffer
*b
= XBUFFER (w
->contents
);
282 b
->window_count
+= arg
;
283 eassert (b
->window_count
>= 0);
284 /* These should be recalculated by redisplay code. */
285 w
->window_end_valid
= false;
286 w
->base_line_pos
= 0;
290 /* Set W's buffer slot to VAL and recompute number
291 of windows showing VAL if it is a buffer. */
294 wset_buffer (struct window
*w
, Lisp_Object val
)
296 adjust_window_count (w
, -1);
298 /* Make sure that we do not assign the buffer
299 to an internal window. */
300 eassert (MARKERP (w
->start
) && MARKERP (w
->pointm
));
302 adjust_window_count (w
, 1);
305 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
306 doc
: /* Return t if OBJECT is a window and nil otherwise. */)
309 return WINDOWP (object
) ? Qt
: Qnil
;
312 DEFUN ("window-valid-p", Fwindow_valid_p
, Swindow_valid_p
, 1, 1, 0,
313 doc
: /* Return t if OBJECT is a valid window and nil otherwise.
314 A valid window is either a window that displays a buffer or an internal
315 window. Windows that have been deleted are not valid. */)
318 return WINDOW_VALID_P (object
) ? Qt
: Qnil
;
321 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
322 doc
: /* Return t if OBJECT is a live window and nil otherwise.
323 A live window is a window that displays a buffer.
324 Internal windows and deleted windows are not live. */)
327 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
330 /* Frames and windows. */
331 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 0, 1, 0,
332 doc
: /* Return the frame that window WINDOW is on.
333 WINDOW must be a valid window and defaults to the selected one. */)
336 return decode_valid_window (window
)->frame
;
339 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
340 doc
: /* Return the root window of FRAME-OR-WINDOW.
341 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
342 With a frame argument, return that frame's root window.
343 With a window argument, return the root window of that window's frame. */)
344 (Lisp_Object frame_or_window
)
348 if (NILP (frame_or_window
))
349 window
= SELECTED_FRAME ()->root_window
;
350 else if (WINDOW_VALID_P (frame_or_window
))
351 window
= XFRAME (XWINDOW (frame_or_window
)->frame
)->root_window
;
354 CHECK_LIVE_FRAME (frame_or_window
);
355 window
= XFRAME (frame_or_window
)->root_window
;
361 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
362 doc
: /* Return the minibuffer window for frame FRAME.
363 If FRAME is omitted or nil, it defaults to the selected frame. */)
366 return FRAME_MINIBUF_WINDOW (decode_live_frame (frame
));
369 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
,
370 Swindow_minibuffer_p
, 0, 1, 0,
371 doc
: /* Return non-nil if WINDOW is a minibuffer window.
372 WINDOW must be a valid window and defaults to the selected one. */)
375 return MINI_WINDOW_P (decode_valid_window (window
)) ? Qt
: Qnil
;
378 /* Don't move this to window.el - this must be a safe routine. */
379 DEFUN ("frame-first-window", Fframe_first_window
, Sframe_first_window
, 0, 1, 0,
380 doc
: /* Return the topmost, leftmost live window on FRAME-OR-WINDOW.
381 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
382 Else if FRAME-OR-WINDOW denotes a valid window, return the first window
383 of that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
384 the first window of that frame. */)
385 (Lisp_Object frame_or_window
)
389 if (NILP (frame_or_window
))
390 window
= SELECTED_FRAME ()->root_window
;
391 else if (WINDOW_VALID_P (frame_or_window
))
392 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
395 CHECK_LIVE_FRAME (frame_or_window
);
396 window
= XFRAME (frame_or_window
)->root_window
;
399 while (WINDOWP (XWINDOW (window
)->contents
))
400 window
= XWINDOW (window
)->contents
;
405 DEFUN ("frame-selected-window", Fframe_selected_window
,
406 Sframe_selected_window
, 0, 1, 0,
407 doc
: /* Return the selected window of FRAME-OR-WINDOW.
408 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
409 Else if FRAME-OR-WINDOW denotes a valid window, return the selected
410 window of that window's frame. If FRAME-OR-WINDOW denotes a live frame,
411 return the selected window of that frame. */)
412 (Lisp_Object frame_or_window
)
416 if (NILP (frame_or_window
))
417 window
= SELECTED_FRAME ()->selected_window
;
418 else if (WINDOW_VALID_P (frame_or_window
))
419 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->selected_window
;
422 CHECK_LIVE_FRAME (frame_or_window
);
423 window
= XFRAME (frame_or_window
)->selected_window
;
429 DEFUN ("set-frame-selected-window", Fset_frame_selected_window
,
430 Sset_frame_selected_window
, 2, 3, 0,
431 doc
: /* Set selected window of FRAME to WINDOW.
432 FRAME must be a live frame and defaults to the selected one. If FRAME
433 is the selected frame, this makes WINDOW the selected window. Optional
434 argument NORECORD non-nil means to neither change the order of recently
435 selected windows nor the buffer list. WINDOW must denote a live window.
437 (Lisp_Object frame
, Lisp_Object window
, Lisp_Object norecord
)
440 frame
= selected_frame
;
442 CHECK_LIVE_FRAME (frame
);
443 CHECK_LIVE_WINDOW (window
);
445 if (! EQ (frame
, WINDOW_FRAME (XWINDOW (window
))))
446 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
448 if (EQ (frame
, selected_frame
))
449 return Fselect_window (window
, norecord
);
452 fset_selected_window (XFRAME (frame
), window
);
457 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
458 doc
: /* Return the selected window.
459 The selected window is the window in which the standard cursor for
460 selected windows appears and to which many commands apply. */)
463 return selected_window
;
466 EMACS_INT window_select_count
;
468 /* If select_window is called with inhibit_point_swap true it will
469 not store point of the old selected window's buffer back into that
470 window's pointm slot. This is needed by Fset_window_configuration to
471 avoid that the display routine is called with selected_window set to
472 Qnil causing a subsequent crash. */
474 select_window (Lisp_Object window
, Lisp_Object norecord
,
475 bool inhibit_point_swap
)
480 CHECK_LIVE_WINDOW (window
);
482 w
= XWINDOW (window
);
484 /* Make the selected window's buffer current. */
485 Fset_buffer (w
->contents
);
487 if (EQ (window
, selected_window
) && !inhibit_point_swap
)
488 /* `switch-to-buffer' uses (select-window (selected-window)) as a "clever"
489 way to call record_buffer from Elisp, so it's important that we call
490 record_buffer before returning here. */
491 goto record_and_return
;
494 { /* Mark the window for redisplay since the selected-window has
495 a different mode-line. */
496 wset_redisplay (XWINDOW (selected_window
));
500 redisplay_other_windows ();
502 sf
= SELECTED_FRAME ();
503 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
505 fset_selected_window (XFRAME (WINDOW_FRAME (w
)), window
);
506 /* Use this rather than Fhandle_switch_frame
507 so that FRAME_FOCUS_FRAME is moved appropriately as we
508 move around in the state where a minibuffer in a separate
510 Fselect_frame (WINDOW_FRAME (w
), norecord
);
511 /* Fselect_frame called us back so we've done all the work already. */
512 eassert (EQ (window
, selected_window
));
516 fset_selected_window (sf
, window
);
518 select_window_1 (window
, inhibit_point_swap
);
519 bset_last_selected_window (XBUFFER (w
->contents
), window
);
522 /* record_buffer can run QUIT, so make sure it is run only after we have
523 re-established the invariant between selected_window and selected_frame,
524 otherwise the temporary broken invariant might "escape" (bug#14161). */
527 w
->use_time
= ++window_select_count
;
528 record_buffer (w
->contents
);
534 /* Select window with a minimum of fuss, i.e. don't record the change anywhere
535 (not even for redisplay's benefit), and assume that the window's frame is
538 select_window_1 (Lisp_Object window
, bool inhibit_point_swap
)
540 /* Store the old selected window's buffer's point in pointm of the old
541 selected window. It belongs to that window, and when the window is
542 not selected, must be in the window. */
543 if (!inhibit_point_swap
)
545 struct window
*ow
= XWINDOW (selected_window
);
546 if (BUFFERP (ow
->contents
))
547 set_marker_both (ow
->pointm
, ow
->contents
,
548 BUF_PT (XBUFFER (ow
->contents
)),
549 BUF_PT_BYTE (XBUFFER (ow
->contents
)));
552 selected_window
= window
;
554 /* Go to the point recorded in the window.
555 This is important when the buffer is in more
556 than one window. It also matters when
557 redisplay_window has altered point after scrolling,
558 because it makes the change only in the window. */
559 set_point_from_marker (XWINDOW (window
)->pointm
);
562 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
563 doc
: /* Select WINDOW which must be a live window.
564 Also make WINDOW's frame the selected frame and WINDOW that frame's
565 selected window. In addition, make WINDOW's buffer current and set its
566 buffer's value of `point' to the value of WINDOW's `window-point'.
569 Optional second arg NORECORD non-nil means do not put this buffer at the
570 front of the buffer list and do not make this window the most recently
573 Run `buffer-list-update-hook' unless NORECORD is non-nil. Note that
574 applications and internal routines often select a window temporarily for
575 various purposes; mostly, to simplify coding. As a rule, such
576 selections should be not recorded and therefore will not pollute
577 `buffer-list-update-hook'. Selections that "really count" are those
578 causing a visible change in the next redisplay of WINDOW's frame and
579 should be always recorded. So if you think of running a function each
580 time a window gets selected put it on `buffer-list-update-hook'.
582 Also note that the main editor command loop sets the current buffer to
583 the buffer of the selected window before each command. */)
584 (Lisp_Object window
, Lisp_Object norecord
)
586 return select_window (window
, norecord
, false);
589 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
590 doc
: /* Return the buffer displayed in window WINDOW.
591 If WINDOW is omitted or nil, it defaults to the selected window.
592 Return nil for an internal window or a deleted window. */)
595 struct window
*w
= decode_any_window (window
);
596 return WINDOW_LEAF_P (w
) ? w
->contents
: Qnil
;
599 DEFUN ("window-parent", Fwindow_parent
, Swindow_parent
, 0, 1, 0,
600 doc
: /* Return the parent window of window WINDOW.
601 WINDOW must be a valid window and defaults to the selected one.
602 Return nil for a window with no parent (e.g. a root window). */)
605 return decode_valid_window (window
)->parent
;
608 DEFUN ("window-top-child", Fwindow_top_child
, Swindow_top_child
, 0, 1, 0,
609 doc
: /* Return the topmost child window of window WINDOW.
610 WINDOW must be a valid window and defaults to the selected one.
611 Return nil if WINDOW is a live window (live windows have no children).
612 Return nil if WINDOW is an internal window whose children form a
613 horizontal combination. */)
616 struct window
*w
= decode_valid_window (window
);
617 return WINDOW_VERTICAL_COMBINATION_P (w
) ? w
->contents
: Qnil
;
620 DEFUN ("window-left-child", Fwindow_left_child
, Swindow_left_child
, 0, 1, 0,
621 doc
: /* Return the leftmost child window of window WINDOW.
622 WINDOW must be a valid window and defaults to the selected one.
623 Return nil if WINDOW is a live window (live windows have no children).
624 Return nil if WINDOW is an internal window whose children form a
625 vertical combination. */)
628 struct window
*w
= decode_valid_window (window
);
629 return WINDOW_HORIZONTAL_COMBINATION_P (w
) ? w
->contents
: Qnil
;
632 DEFUN ("window-next-sibling", Fwindow_next_sibling
, Swindow_next_sibling
, 0, 1, 0,
633 doc
: /* Return the next sibling window of window WINDOW.
634 WINDOW must be a valid window and defaults to the selected one.
635 Return nil if WINDOW has no next sibling. */)
638 return decode_valid_window (window
)->next
;
641 DEFUN ("window-prev-sibling", Fwindow_prev_sibling
, Swindow_prev_sibling
, 0, 1, 0,
642 doc
: /* Return the previous sibling window of window WINDOW.
643 WINDOW must be a valid window and defaults to the selected one.
644 Return nil if WINDOW has no previous sibling. */)
647 return decode_valid_window (window
)->prev
;
650 DEFUN ("window-combination-limit", Fwindow_combination_limit
, Swindow_combination_limit
, 1, 1, 0,
651 doc
: /* Return combination limit of window WINDOW.
652 WINDOW must be a valid window used in horizontal or vertical combination.
653 If the return value is nil, child windows of WINDOW can be recombined with
654 WINDOW's siblings. A return value of t means that child windows of
655 WINDOW are never (re-)combined with WINDOW's siblings. */)
660 CHECK_VALID_WINDOW (window
);
661 w
= XWINDOW (window
);
662 if (WINDOW_LEAF_P (w
))
663 error ("Combination limit is meaningful for internal windows only");
664 return w
->combination_limit
;
667 DEFUN ("set-window-combination-limit", Fset_window_combination_limit
, Sset_window_combination_limit
, 2, 2, 0,
668 doc
: /* Set combination limit of window WINDOW to LIMIT; return LIMIT.
669 WINDOW must be a valid window used in horizontal or vertical combination.
670 If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's
671 siblings. LIMIT t means that child windows of WINDOW are never
672 (re-)combined with WINDOW's siblings. Other values are reserved for
674 (Lisp_Object window
, Lisp_Object limit
)
678 CHECK_VALID_WINDOW (window
);
679 w
= XWINDOW (window
);
680 if (WINDOW_LEAF_P (w
))
681 error ("Combination limit is meaningful for internal windows only");
682 wset_combination_limit (w
, limit
);
686 DEFUN ("window-use-time", Fwindow_use_time
, Swindow_use_time
, 0, 1, 0,
687 doc
: /* Return the use time of window WINDOW.
688 WINDOW must be a live window and defaults to the selected one.
689 The window with the highest use time is the most recently selected
690 one. The window with the lowest use time is the least recently
694 return make_number (decode_live_window (window
)->use_time
);
697 DEFUN ("window-pixel-width", Fwindow_pixel_width
, Swindow_pixel_width
, 0, 1, 0,
698 doc
: /* Return the width of window WINDOW in pixels.
699 WINDOW must be a valid window and defaults to the selected one.
701 The return value includes the fringes and margins of WINDOW as well as
702 any vertical dividers or scroll bars belonging to WINDOW. If WINDOW is
703 an internal window, its pixel width is the width of the screen areas
704 spanned by its children. */)
707 return make_number (decode_valid_window (window
)->pixel_width
);
710 DEFUN ("window-pixel-height", Fwindow_pixel_height
, Swindow_pixel_height
, 0, 1, 0,
711 doc
: /* Return the height of window WINDOW in pixels.
712 WINDOW must be a valid window and defaults to the selected one.
714 The return value includes the mode line and header line and the bottom
715 divider, if any. If WINDOW is an internal window, its pixel height is
716 the height of the screen areas spanned by its children. */)
719 return make_number (decode_valid_window (window
)->pixel_height
);
722 DEFUN ("window-total-height", Fwindow_total_height
, Swindow_total_height
, 0, 2, 0,
723 doc
: /* Return the height of window WINDOW in lines.
724 WINDOW must be a valid window and defaults to the selected one.
726 The return value includes the heights of WINDOW's mode and header line
727 and its bottom divider, if any. If WINDOW is an internal window, the
728 total height is the height of the screen areas spanned by its children.
730 If WINDOW's pixel height is not an integral multiple of its frame's
731 character height, the number of lines occupied by WINDOW is rounded
732 internally. This is done in a way such that, if WINDOW is a parent
733 window, the sum of the total heights of all its children internally
734 equals the total height of WINDOW.
736 If the optional argument ROUND is `ceiling', return the smallest integer
737 larger than WINDOW's pixel height divided by the character height of
738 WINDOW's frame. ROUND `floor' means to return the largest integer
739 smaller than WINDOW's pixel height divided by the character height of
740 WINDOW's frame. Any other value of ROUND means to return the internal
741 total height of WINDOW. */)
742 (Lisp_Object window
, Lisp_Object round
)
744 struct window
*w
= decode_valid_window (window
);
746 if (! EQ (round
, Qfloor
) && ! EQ (round
, Qceiling
))
747 return make_number (w
->total_lines
);
750 int unit
= FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
));
752 return make_number (EQ (round
, Qceiling
)
753 ? ((w
->pixel_height
+ unit
- 1) /unit
)
754 : (w
->pixel_height
/ unit
));
758 DEFUN ("window-total-width", Fwindow_total_width
, Swindow_total_width
, 0, 2, 0,
759 doc
: /* Return the total width of window WINDOW in columns.
760 WINDOW must be a valid window and defaults to the selected one.
762 The return value includes the widths of WINDOW's fringes, margins,
763 scroll bars and its right divider, if any. If WINDOW is an internal
764 window, the total width is the width of the screen areas spanned by its
767 If WINDOW's pixel width is not an integral multiple of its frame's
768 character width, the number of lines occupied by WINDOW is rounded
769 internally. This is done in a way such that, if WINDOW is a parent
770 window, the sum of the total widths of all its children internally
771 equals the total width of WINDOW.
773 If the optional argument ROUND is `ceiling', return the smallest integer
774 larger than WINDOW's pixel width divided by the character width of
775 WINDOW's frame. ROUND `floor' means to return the largest integer
776 smaller than WINDOW's pixel width divided by the character width of
777 WINDOW's frame. Any other value of ROUND means to return the internal
778 total width of WINDOW. */)
779 (Lisp_Object window
, Lisp_Object round
)
781 struct window
*w
= decode_valid_window (window
);
783 if (! EQ (round
, Qfloor
) && ! EQ (round
, Qceiling
))
784 return make_number (w
->total_cols
);
787 int unit
= FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
));
789 return make_number (EQ (round
, Qceiling
)
790 ? ((w
->pixel_width
+ unit
- 1) /unit
)
791 : (w
->pixel_width
/ unit
));
795 DEFUN ("window-new-total", Fwindow_new_total
, Swindow_new_total
, 0, 1, 0,
796 doc
: /* Return the new total size of window WINDOW.
797 WINDOW must be a valid window and defaults to the selected one.
799 The new total size of WINDOW is the value set by the last call of
800 `set-window-new-total' for WINDOW. If it is valid, it will be shortly
801 installed as WINDOW's total height (see `window-total-height') or total
802 width (see `window-total-width'). */)
805 return decode_valid_window (window
)->new_total
;
808 DEFUN ("window-normal-size", Fwindow_normal_size
, Swindow_normal_size
, 0, 2, 0,
809 doc
: /* Return the normal height of window WINDOW.
810 WINDOW must be a valid window and defaults to the selected one.
811 If HORIZONTAL is non-nil, return the normal width of WINDOW.
813 The normal height of a frame's root window or a window that is
814 horizontally combined (a window that has a left or right sibling) is
815 1.0. The normal height of a window that is vertically combined (has a
816 sibling above or below) is the fraction of the window's height with
817 respect to its parent. The sum of the normal heights of all windows in a
818 vertical combination equals 1.0.
820 Similarly, the normal width of a frame's root window or a window that is
821 vertically combined equals 1.0. The normal width of a window that is
822 horizontally combined is the fraction of the window's width with respect
823 to its parent. The sum of the normal widths of all windows in a
824 horizontal combination equals 1.0.
826 The normal sizes of windows are used to restore the proportional sizes
827 of windows after they have been shrunk to their minimum sizes; for
828 example when a frame is temporarily made very small and afterwards gets
829 re-enlarged to its previous size. */)
830 (Lisp_Object window
, Lisp_Object horizontal
)
832 struct window
*w
= decode_valid_window (window
);
834 return NILP (horizontal
) ? w
->normal_lines
: w
->normal_cols
;
837 DEFUN ("window-new-normal", Fwindow_new_normal
, Swindow_new_normal
, 0, 1, 0,
838 doc
: /* Return new normal size of window WINDOW.
839 WINDOW must be a valid window and defaults to the selected one.
841 The new normal size of WINDOW is the value set by the last call of
842 `set-window-new-normal' for WINDOW. If valid, it will be shortly
843 installed as WINDOW's normal size (see `window-normal-size'). */)
846 return decode_valid_window (window
)->new_normal
;
849 DEFUN ("window-new-pixel", Fwindow_new_pixel
, Swindow_new_pixel
, 0, 1, 0,
850 doc
: /* Return new pixel size of window WINDOW.
851 WINDOW must be a valid window and defaults to the selected one.
853 The new pixel size of WINDOW is the value set by the last call of
854 `set-window-new-pixel' for WINDOW. If it is valid, it will be shortly
855 installed as WINDOW's pixel height (see `window-pixel-height') or pixel
856 width (see `window-pixel-width'). */)
859 return decode_valid_window (window
)->new_pixel
;
862 DEFUN ("window-pixel-left", Fwindow_pixel_left
, Swindow_pixel_left
, 0, 1, 0,
863 doc
: /* Return left pixel edge of window WINDOW.
864 WINDOW must be a valid window and defaults to the selected one. */)
867 return make_number (decode_valid_window (window
)->pixel_left
);
870 DEFUN ("window-pixel-top", Fwindow_pixel_top
, Swindow_pixel_top
, 0, 1, 0,
871 doc
: /* Return top pixel edge of window WINDOW.
872 WINDOW must be a valid window and defaults to the selected one. */)
875 return make_number (decode_valid_window (window
)->pixel_top
);
878 DEFUN ("window-left-column", Fwindow_left_column
, Swindow_left_column
, 0, 1, 0,
879 doc
: /* Return left column of window WINDOW.
880 This is the distance, in columns, between the left edge of WINDOW and
881 the left edge of the frame's window area. For instance, the return
882 value is 0 if there is no window to the left of WINDOW.
884 WINDOW must be a valid window and defaults to the selected one. */)
887 return make_number (decode_valid_window (window
)->left_col
);
890 DEFUN ("window-top-line", Fwindow_top_line
, Swindow_top_line
, 0, 1, 0,
891 doc
: /* Return top line of window WINDOW.
892 This is the distance, in lines, between the top of WINDOW and the top
893 of the frame's window area. For instance, the return value is 0 if
894 there is no window above WINDOW.
896 WINDOW must be a valid window and defaults to the selected one. */)
899 return make_number (decode_valid_window (window
)->top_line
);
902 /* Return the number of lines/pixels of W's body. Don't count any mode
903 or header line or horizontal divider of W. Rounds down to nearest
904 integer when not working pixelwise. */
906 window_body_height (struct window
*w
, bool pixelwise
)
908 int height
= (w
->pixel_height
909 - WINDOW_HEADER_LINE_HEIGHT (w
)
910 - (WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
)
911 ? WINDOW_SCROLL_BAR_AREA_HEIGHT (w
)
913 - WINDOW_MODE_LINE_HEIGHT (w
)
914 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
));
916 /* Don't return a negative value. */
917 return max (pixelwise
919 : height
/ FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
)),
923 /* Return the number of columns/pixels of W's body. Don't count columns
924 occupied by the scroll bar or the divider/vertical bar separating W
925 from its right sibling or margins. On window-systems don't count
926 fringes either. Round down to nearest integer when not working
929 window_body_width (struct window
*w
, bool pixelwise
)
931 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
933 int width
= (w
->pixel_width
934 - WINDOW_RIGHT_DIVIDER_WIDTH (w
)
935 - (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
936 ? WINDOW_SCROLL_BAR_AREA_WIDTH (w
)
937 : (/* A vertical bar is either 1 or 0. */
939 && !WINDOW_RIGHTMOST_P (w
)
940 && !WINDOW_RIGHT_DIVIDER_WIDTH (w
)))
941 - WINDOW_MARGINS_WIDTH (w
)
942 - (FRAME_WINDOW_P (f
)
943 ? WINDOW_FRINGES_WIDTH (w
)
946 /* Don't return a negative value. */
947 return max (pixelwise
949 : width
/ FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
)),
953 DEFUN ("window-body-height", Fwindow_body_height
, Swindow_body_height
, 0, 2, 0,
954 doc
: /* Return the height of WINDOW's text area.
955 WINDOW must be a live window and defaults to the selected one. Optional
956 argument PIXELWISE non-nil means return the height of WINDOW's text area
957 in pixels. The return value does not include the mode line or header
958 line or any horizontal divider.
960 If PIXELWISE is nil, return the largest integer smaller than WINDOW's
961 pixel height divided by the character height of WINDOW's frame. This
962 means that if a line at the bottom of the text area is only partially
963 visible, that line is not counted. */)
964 (Lisp_Object window
, Lisp_Object pixelwise
)
966 return make_number (window_body_height (decode_live_window (window
),
970 DEFUN ("window-body-width", Fwindow_body_width
, Swindow_body_width
, 0, 2, 0,
971 doc
: /* Return the width of WINDOW's text area.
972 WINDOW must be a live window and defaults to the selected one. Optional
973 argument PIXELWISE non-nil means return the width in pixels. The return
974 value does not include any vertical dividers, fringes or marginal areas,
977 If PIXELWISE is nil, return the largest integer smaller than WINDOW's
978 pixel width divided by the character width of WINDOW's frame. This
979 means that if a column at the right of the text area is only partially
980 visible, that column is not counted.
982 Note that the returned value includes the column reserved for the
983 continuation glyph. */)
984 (Lisp_Object window
, Lisp_Object pixelwise
)
986 return make_number (window_body_width (decode_live_window (window
),
990 DEFUN ("window-mode-line-height", Fwindow_mode_line_height
,
991 Swindow_mode_line_height
, 0, 1, 0,
992 doc
: /* Return the height in pixels of WINDOW's mode-line.
993 WINDOW must be a live window and defaults to the selected one. */)
996 return (make_number (WINDOW_MODE_LINE_HEIGHT (decode_live_window (window
))));
999 DEFUN ("window-header-line-height", Fwindow_header_line_height
,
1000 Swindow_header_line_height
, 0, 1, 0,
1001 doc
: /* Return the height in pixels of WINDOW's header-line.
1002 WINDOW must be a live window and defaults to the selected one. */)
1003 (Lisp_Object window
)
1005 return (make_number (WINDOW_HEADER_LINE_HEIGHT (decode_live_window (window
))));
1008 DEFUN ("window-right-divider-width", Fwindow_right_divider_width
,
1009 Swindow_right_divider_width
, 0, 1, 0,
1010 doc
: /* Return the width in pixels of WINDOW's right divider.
1011 WINDOW must be a live window and defaults to the selected one. */)
1012 (Lisp_Object window
)
1014 return (make_number (WINDOW_RIGHT_DIVIDER_WIDTH (decode_live_window (window
))));
1017 DEFUN ("window-bottom-divider-width", Fwindow_bottom_divider_width
,
1018 Swindow_bottom_divider_width
, 0, 1, 0,
1019 doc
: /* Return the width in pixels of WINDOW's bottom divider.
1020 WINDOW must be a live window and defaults to the selected one. */)
1021 (Lisp_Object window
)
1023 return (make_number (WINDOW_BOTTOM_DIVIDER_WIDTH (decode_live_window (window
))));
1026 DEFUN ("window-scroll-bar-width", Fwindow_scroll_bar_width
,
1027 Swindow_scroll_bar_width
, 0, 1, 0,
1028 doc
: /* Return the width in pixels of WINDOW's vertical scrollbar.
1029 WINDOW must be a live window and defaults to the selected one. */)
1030 (Lisp_Object window
)
1032 return (make_number (WINDOW_SCROLL_BAR_AREA_WIDTH (decode_live_window (window
))));
1035 DEFUN ("window-scroll-bar-height", Fwindow_scroll_bar_height
,
1036 Swindow_scroll_bar_height
, 0, 1, 0,
1037 doc
: /* Return the height in pixels of WINDOW's horizontal scrollbar.
1038 WINDOW must be a live window and defaults to the selected one. */)
1039 (Lisp_Object window
)
1041 return (make_number (WINDOW_SCROLL_BAR_AREA_HEIGHT (decode_live_window (window
))));
1044 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
1045 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
1046 WINDOW must be a live window and defaults to the selected one. */)
1047 (Lisp_Object window
)
1049 return make_number (decode_live_window (window
)->hscroll
);
1052 /* Set W's horizontal scroll amount to HSCROLL clipped to a reasonable
1053 range, returning the new amount as a fixnum. */
1055 set_window_hscroll (struct window
*w
, EMACS_INT hscroll
)
1057 /* Horizontal scrolling has problems with large scroll amounts.
1058 It's too slow with long lines, and even with small lines the
1059 display can be messed up. For now, though, impose only the limits
1060 required by the internal representation: horizontal scrolling must
1061 fit in fixnum (since it's visible to Elisp) and into ptrdiff_t
1062 (since it's stored in a ptrdiff_t). */
1063 ptrdiff_t hscroll_max
= min (MOST_POSITIVE_FIXNUM
, PTRDIFF_MAX
);
1064 ptrdiff_t new_hscroll
= clip_to_bounds (0, hscroll
, hscroll_max
);
1066 /* Prevent redisplay shortcuts when changing the hscroll. */
1067 if (w
->hscroll
!= new_hscroll
)
1068 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= true;
1070 w
->hscroll
= new_hscroll
;
1071 w
->suspend_auto_hscroll
= true;
1073 return make_number (new_hscroll
);
1076 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
1077 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
1078 WINDOW must be a live window and defaults to the selected one.
1079 Clip the number to a reasonable value if out of range.
1080 Return the new number. NCOL should be zero or positive.
1082 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
1083 window so that the location of point moves off-window. */)
1084 (Lisp_Object window
, Lisp_Object ncol
)
1086 CHECK_NUMBER (ncol
);
1087 return set_window_hscroll (decode_live_window (window
), XINT (ncol
));
1090 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
1091 Swindow_redisplay_end_trigger
, 0, 1, 0,
1092 doc
: /* Return WINDOW's redisplay end trigger value.
1093 WINDOW must be a live window and defaults to the selected one.
1094 See `set-window-redisplay-end-trigger' for more information. */)
1095 (Lisp_Object window
)
1097 return decode_live_window (window
)->redisplay_end_trigger
;
1100 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
1101 Sset_window_redisplay_end_trigger
, 2, 2, 0,
1102 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
1103 WINDOW must be a live window and defaults to the selected one. VALUE
1104 should be a buffer position (typically a marker) or nil. If it is a
1105 buffer position, then if redisplay in WINDOW reaches a position beyond
1106 VALUE, the functions in `redisplay-end-trigger-functions' are called
1107 with two arguments: WINDOW, and the end trigger value. Afterwards the
1108 end-trigger value is reset to nil. */)
1109 (register Lisp_Object window
, Lisp_Object value
)
1111 wset_redisplay_end_trigger (decode_live_window (window
), value
);
1115 /* Test if the character at column X, row Y is within window W.
1116 If it is not, return ON_NOTHING;
1117 if it is on the window's vertical divider, return
1119 if it is on the window's horizontal divider, return
1121 if it is in the window's text area, return ON_TEXT;
1122 if it is on the window's modeline, return ON_MODE_LINE;
1123 if it is on the border between the window and its right sibling,
1124 return ON_VERTICAL_BORDER;
1125 if it is on a scroll bar, return ON_SCROLL_BAR;
1126 if it is on the window's top line, return ON_HEADER_LINE;
1127 if it is in left or right fringe of the window,
1128 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
1129 if it is in the marginal area to the left/right of the window,
1130 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN.
1132 X and Y are frame relative pixel coordinates. */
1134 static enum window_part
1135 coordinates_in_window (register struct window
*w
, int x
, int y
)
1137 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1138 enum window_part part
;
1139 int ux
= FRAME_COLUMN_WIDTH (f
);
1140 int left_x
= WINDOW_LEFT_EDGE_X (w
);
1141 int right_x
= WINDOW_RIGHT_EDGE_X (w
);
1142 int top_y
= WINDOW_TOP_EDGE_Y (w
);
1143 int bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
1144 /* The width of the area where the vertical line can be dragged.
1145 (Between mode lines for instance. */
1146 int grabbable_width
= ux
;
1147 int lmargin_width
, rmargin_width
, text_left
, text_right
;
1149 /* Outside any interesting row or column? */
1150 if (y
< top_y
|| y
>= bottom_y
|| x
< left_x
|| x
>= right_x
)
1153 /* On the horizontal window divider (which prevails the vertical
1155 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
) > 0
1156 && y
>= (bottom_y
- WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
1158 return ON_BOTTOM_DIVIDER
;
1159 /* On vertical window divider? */
1160 else if (!WINDOW_RIGHTMOST_P (w
)
1161 && WINDOW_RIGHT_DIVIDER_WIDTH (w
) > 0
1162 && x
>= right_x
- WINDOW_RIGHT_DIVIDER_WIDTH (w
)
1164 return ON_RIGHT_DIVIDER
;
1165 /* On the horizontal scroll bar? (Including the empty space at its
1167 else if ((WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
)
1169 - WINDOW_SCROLL_BAR_AREA_HEIGHT (w
)
1170 - CURRENT_MODE_LINE_HEIGHT (w
)
1171 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
1173 - CURRENT_MODE_LINE_HEIGHT (w
)
1174 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
))))
1175 return ON_HORIZONTAL_SCROLL_BAR
;
1176 /* On the mode or header line? */
1177 else if ((WINDOW_WANTS_MODELINE_P (w
)
1179 - CURRENT_MODE_LINE_HEIGHT (w
)
1180 - WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
1181 && y
<= bottom_y
- WINDOW_BOTTOM_DIVIDER_WIDTH (w
)
1182 && (part
= ON_MODE_LINE
))
1183 || (WINDOW_WANTS_HEADER_LINE_P (w
)
1184 && y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
)
1185 && (part
= ON_HEADER_LINE
)))
1187 /* If it's under/over the scroll bar portion of the mode/header
1188 line, say it's on the vertical line. That's to be able to
1189 resize windows horizontally in case we're using toolkit scroll
1190 bars. Note: If scrollbars are on the left, the window that
1191 must be eventually resized is that on the left of WINDOW. */
1192 if ((WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0)
1193 && ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1194 && !WINDOW_LEFTMOST_P (w
)
1195 && eabs (x
- left_x
) < grabbable_width
)
1196 || (!WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1197 && !WINDOW_RIGHTMOST_P (w
)
1198 && eabs (x
- right_x
) < grabbable_width
)))
1199 return ON_VERTICAL_BORDER
;
1204 /* In what's below, we subtract 1 when computing right_x because we
1205 want the rightmost pixel, which is given by left_pixel+width-1. */
1206 if (w
->pseudo_window_p
)
1209 right_x
= WINDOW_PIXEL_WIDTH (w
) - 1;
1213 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
1214 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
1217 /* Outside any interesting column? */
1218 if (x
< left_x
|| x
> right_x
)
1219 return ON_VERTICAL_SCROLL_BAR
;
1221 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
1222 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
1224 text_left
= window_box_left (w
, TEXT_AREA
);
1225 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
1227 if (FRAME_WINDOW_P (f
))
1229 if (!w
->pseudo_window_p
1230 && WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0
1231 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
1232 && !WINDOW_RIGHTMOST_P (w
)
1233 && (eabs (x
- right_x
) < grabbable_width
))
1234 return ON_VERTICAL_BORDER
;
1236 /* Need to say "x > right_x" rather than >=, since on character
1237 terminals, the vertical line's x coordinate is right_x. */
1238 else if (!w
->pseudo_window_p
1239 && WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0
1240 && !WINDOW_RIGHTMOST_P (w
)
1241 /* Why check ux if we are not the rightmost window? Also
1242 shouldn't a pseudo window always be rightmost? */
1243 && x
> right_x
- ux
)
1244 return ON_VERTICAL_BORDER
;
1248 if (lmargin_width
> 0
1249 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1250 ? (x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
1251 : (x
< left_x
+ lmargin_width
)))
1252 return ON_LEFT_MARGIN
;
1254 return ON_LEFT_FRINGE
;
1257 if (x
>= text_right
)
1259 if (rmargin_width
> 0
1260 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1261 ? (x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
1262 : (x
>= right_x
- rmargin_width
)))
1263 return ON_RIGHT_MARGIN
;
1265 return ON_RIGHT_FRINGE
;
1268 /* Everything special ruled out - must be on text area */
1272 /* Take X is the frame-relative pixel x-coordinate, and return the
1273 x-coordinate relative to part PART of window W. */
1275 window_relative_x_coord (struct window
*w
, enum window_part part
, int x
)
1277 int left_x
= (w
->pseudo_window_p
) ? 0 : WINDOW_BOX_LEFT_EDGE_X (w
);
1282 return x
- window_box_left (w
, TEXT_AREA
);
1284 case ON_HEADER_LINE
:
1286 case ON_LEFT_FRINGE
:
1289 case ON_RIGHT_FRINGE
:
1290 return x
- left_x
- WINDOW_LEFT_FRINGE_WIDTH (w
);
1292 case ON_LEFT_MARGIN
:
1294 - ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1295 ? WINDOW_LEFT_FRINGE_WIDTH (w
) : 0));
1297 case ON_RIGHT_MARGIN
:
1299 - ((w
->pseudo_window_p
)
1300 ? WINDOW_PIXEL_WIDTH (w
)
1301 : WINDOW_BOX_RIGHT_EDGE_X (w
))
1302 + window_box_width (w
, RIGHT_MARGIN_AREA
)
1303 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1304 ? WINDOW_RIGHT_FRINGE_WIDTH (w
) : 0));
1307 case ON_VERTICAL_BORDER
:
1308 case ON_VERTICAL_SCROLL_BAR
:
1309 case ON_HORIZONTAL_SCROLL_BAR
:
1310 case ON_RIGHT_DIVIDER
:
1311 case ON_BOTTOM_DIVIDER
:
1320 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
1321 Scoordinates_in_window_p
, 2, 2, 0,
1322 doc
: /* Return non-nil if COORDINATES are in WINDOW.
1323 WINDOW must be a live window and defaults to the selected one.
1324 COORDINATES is a cons of the form (X . Y), X and Y being distances
1325 measured in characters from the upper-left corner of the frame.
1326 (0 . 0) denotes the character in the upper left corner of the
1328 If COORDINATES are in the text portion of WINDOW,
1329 the coordinates relative to the window are returned.
1330 If they are in the bottom divider of WINDOW, `bottom-divider' is returned.
1331 If they are in the right divider of WINDOW, `right-divider' is returned.
1332 If they are in the mode line of WINDOW, `mode-line' is returned.
1333 If they are in the header line of WINDOW, `header-line' is returned.
1334 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1335 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1336 If they are on the border between WINDOW and its right sibling,
1337 `vertical-line' is returned.
1338 If they are in the windows's left or right marginal areas, `left-margin'\n\
1339 or `right-margin' is returned. */)
1340 (register Lisp_Object coordinates
, Lisp_Object window
)
1347 w
= decode_live_window (window
);
1348 f
= XFRAME (w
->frame
);
1349 CHECK_CONS (coordinates
);
1350 lx
= Fcar (coordinates
);
1351 ly
= Fcdr (coordinates
);
1352 CHECK_NUMBER_OR_FLOAT (lx
);
1353 CHECK_NUMBER_OR_FLOAT (ly
);
1354 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1355 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1357 switch (coordinates_in_window (w
, x
, y
))
1363 /* Convert X and Y to window relative pixel coordinates, and
1364 return the canonical char units. */
1365 x
-= window_box_left (w
, TEXT_AREA
);
1366 y
-= WINDOW_TOP_EDGE_Y (w
);
1367 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
1368 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
1373 case ON_VERTICAL_BORDER
:
1374 return Qvertical_line
;
1376 case ON_HEADER_LINE
:
1377 return Qheader_line
;
1379 case ON_LEFT_FRINGE
:
1380 return Qleft_fringe
;
1382 case ON_RIGHT_FRINGE
:
1383 return Qright_fringe
;
1385 case ON_LEFT_MARGIN
:
1386 return Qleft_margin
;
1388 case ON_RIGHT_MARGIN
:
1389 return Qright_margin
;
1391 case ON_VERTICAL_SCROLL_BAR
:
1392 /* Historically we are supposed to return nil in this case. */
1395 case ON_HORIZONTAL_SCROLL_BAR
:
1398 case ON_RIGHT_DIVIDER
:
1399 return Qright_divider
;
1401 case ON_BOTTOM_DIVIDER
:
1402 return Qbottom_divider
;
1410 /* Callback for foreach_window, used in window_from_coordinates.
1411 Check if window W contains coordinates specified by USER_DATA which
1412 is actually a pointer to a struct check_window_data CW.
1414 Check if window W contains coordinates *CW->x and *CW->y. If it
1415 does, return W in *CW->window, as Lisp_Object, and return in
1416 *CW->part the part of the window under coordinates *X,*Y. Return
1417 false from this function to stop iterating over windows. */
1419 struct check_window_data
1421 Lisp_Object
*window
;
1423 enum window_part
*part
;
1427 check_window_containing (struct window
*w
, void *user_data
)
1429 struct check_window_data
*cw
= user_data
;
1430 enum window_part found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1431 if (found
== ON_NOTHING
)
1436 XSETWINDOW (*cw
->window
, w
);
1442 /* Find the window containing frame-relative pixel position X/Y and
1443 return it as a Lisp_Object.
1445 If X, Y is on one of the window's special `window_part' elements,
1446 set *PART to the id of that element.
1448 If there is no window under X, Y return nil and leave *PART
1449 unmodified. TOOL_BAR_P means detect tool-bar windows.
1451 This function was previously implemented with a loop cycling over
1452 windows with Fnext_window, and starting with the frame's selected
1453 window. It turned out that this doesn't work with an
1454 implementation of next_window using Vwindow_list, because
1455 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1456 tree of F when this function is called asynchronously from
1457 note_mouse_highlight. The original loop didn't terminate in this
1461 window_from_coordinates (struct frame
*f
, int x
, int y
,
1462 enum window_part
*part
, bool tool_bar_p
)
1465 struct check_window_data cw
;
1466 enum window_part dummy
;
1472 cw
.window
= &window
, cw
.x
= x
, cw
.y
= y
; cw
.part
= part
;
1473 foreach_window (f
, check_window_containing
, &cw
);
1475 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
1476 /* If not found above, see if it's in the tool bar window, if a tool
1480 && WINDOWP (f
->tool_bar_window
)
1481 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1482 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), x
, y
)
1486 window
= f
->tool_bar_window
;
1493 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1494 doc
: /* Return window containing coordinates X and Y on FRAME.
1495 FRAME must be a live frame and defaults to the selected one.
1496 The top left corner of the frame is considered to be row 0,
1498 (Lisp_Object x
, Lisp_Object y
, Lisp_Object frame
)
1500 struct frame
*f
= decode_live_frame (frame
);
1502 /* Check that arguments are integers or floats. */
1503 CHECK_NUMBER_OR_FLOAT (x
);
1504 CHECK_NUMBER_OR_FLOAT (y
);
1506 return window_from_coordinates (f
,
1507 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1508 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1509 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1510 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1514 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1515 doc
: /* Return current value of point in WINDOW.
1516 WINDOW must be a live window and defaults to the selected one.
1518 For a nonselected window, this is the value point would have if that
1519 window were selected.
1521 Note that, when WINDOW is selected, the value returned is the same as
1522 that returned by `point' for WINDOW's buffer. It would be more strictly
1523 correct to return the top-level value of `point', outside of any
1524 `save-excursion' forms. But that is hard to define. */)
1525 (Lisp_Object window
)
1527 register struct window
*w
= decode_live_window (window
);
1529 if (w
== XWINDOW (selected_window
))
1530 return make_number (BUF_PT (XBUFFER (w
->contents
)));
1532 return Fmarker_position (w
->pointm
);
1535 DEFUN ("window-old-point", Fwindow_old_point
, Swindow_old_point
, 0, 1, 0,
1536 doc
: /* Return old value of point in WINDOW.
1537 WINDOW must be a live window and defaults to the selected one. */)
1538 (Lisp_Object window
)
1540 return Fmarker_position (decode_live_window (window
)->old_pointm
);
1543 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 2, 0,
1544 doc
: /* Return position at which display currently starts in WINDOW.
1545 WINDOW must be a live window and defaults to the selected one.
1546 This is updated by redisplay or by calling `set-window-start'.
1548 If GROUP is non-nil, and WINDOW is part of a group of windows collectively
1549 displaying a buffer (such as with Follow Mode), return the start position of
1550 the group rather than of the individual WINDOW. This condition holds when
1551 `window-start-group-function' is set to a function, in which case
1552 `window-start' calls the function with the argument WINDOW, then returns its
1553 result, instead of doing its normal processing. */)
1554 (Lisp_Object window
, Lisp_Object group
)
1556 return (!NILP (group
)
1557 && FUNCTIONP (Vwindow_start_group_function
))
1558 ? call1 (Vwindow_start_group_function
, window
)
1559 : Fmarker_position (decode_live_window (window
)->start
);
1562 /* This is text temporarily removed from the doc string below.
1564 This function returns nil if the position is not currently known.
1565 That happens when redisplay is preempted and doesn't finish.
1566 If in that case you want to compute where the end of the window would
1567 have been if redisplay had finished, do this:
1569 (goto-char (window-start window))
1570 (vertical-motion (1- (window-height window)) window)
1573 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 3, 0,
1574 doc
: /* Return position at which display currently ends in WINDOW.
1575 WINDOW must be a live window and defaults to the selected one.
1576 This is updated by redisplay, when it runs to completion.
1577 Simply changing the buffer text or setting `window-start'
1578 does not update this value.
1579 Return nil if there is no recorded value. (This can happen if the
1580 last redisplay of WINDOW was preempted, and did not finish.)
1581 If UPDATE is non-nil, compute the up-to-date position
1582 if it isn't already recorded.
1584 If GROUP is non-nil, and WINDOW is part of a group of windows collectively
1585 displaying a buffer (such as with Follow Mode), return the end position of
1586 the group rather than of the individual WINDOW. This condition holds when
1587 `window-end-group-function' is set to a function, in which case `window-end'
1588 calls the function with the two arguments WINDOW and UPDATE, then returns its
1589 result, instead of doing its normal processing. */)
1590 (Lisp_Object window
, Lisp_Object update
, Lisp_Object group
)
1593 && FUNCTIONP (Vwindow_end_group_function
))
1594 return call2 (Vwindow_end_group_function
, window
, update
);
1597 struct window
*w
= decode_live_window (window
);
1606 && (windows_or_buffers_changed
1607 || !w
->window_end_valid
1609 || b
->prevent_redisplay_optimizations_p
1610 || window_outdated (w
))
1611 /* Don't call display routines if we didn't yet create any real
1612 frames, because the glyph matrices are not yet allocated in
1613 that case. This could happen in some code that runs in the
1614 daemon during initialization (e.g., see bug#20565). */
1615 && !(noninteractive
|| FRAME_INITIAL_P (WINDOW_XFRAME (w
))))
1617 struct text_pos startp
;
1619 struct buffer
*old_buffer
= NULL
;
1620 void *itdata
= NULL
;
1622 /* Cannot use Fvertical_motion because that function doesn't
1623 cope with variable-height lines. */
1624 if (b
!= current_buffer
)
1626 old_buffer
= current_buffer
;
1627 set_buffer_internal (b
);
1630 /* In case W->start is out of the range, use something
1631 reasonable. This situation occurred when loading a file with
1632 `-l' containing a call to `rmail' with subsequent other
1633 commands. At the end, W->start happened to be BEG, while
1634 rmail had already narrowed the buffer. */
1635 CLIP_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1637 itdata
= bidi_shelve_cache ();
1638 start_display (&it
, w
, startp
);
1639 move_it_vertically (&it
, window_box_height (w
));
1640 if (it
.current_y
< it
.last_visible_y
)
1641 move_it_past_eol (&it
);
1642 value
= make_number (IT_CHARPOS (it
));
1643 bidi_unshelve_cache (itdata
, false);
1646 set_buffer_internal (old_buffer
);
1649 XSETINT (value
, BUF_Z (b
) - w
->window_end_pos
);
1655 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1656 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1657 WINDOW must be a live window and defaults to the selected one.
1659 (Lisp_Object window
, Lisp_Object pos
)
1661 register struct window
*w
= decode_live_window (window
);
1663 /* Type of POS is checked by Fgoto_char or set_marker_restricted ... */
1665 if (w
== XWINDOW (selected_window
))
1667 if (XBUFFER (w
->contents
) == current_buffer
)
1671 struct buffer
*old_buffer
= current_buffer
;
1673 /* ... but here we want to catch type error before buffer change. */
1674 CHECK_NUMBER_COERCE_MARKER (pos
);
1675 set_buffer_internal (XBUFFER (w
->contents
));
1677 set_buffer_internal (old_buffer
);
1682 set_marker_restricted (w
->pointm
, pos
, w
->contents
);
1683 /* We have to make sure that redisplay updates the window to show
1684 the new value of point. */
1691 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 4, 0,
1692 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1693 WINDOW must be a live window and defaults to the selected one. Return
1694 POS. Optional third arg NOFORCE non-nil inhibits next redisplay from
1695 overriding motion of point in order to display at this exact start.
1697 If GROUP is non-nil, and WINDOW is part of a group of windows collectively
1698 displaying a buffer (such as with Follow Mode), set the start position of
1699 the group rather than of the individual WINDOW. This condition holds when
1700 `set-window-start-group-function' is set to a function, in which case
1701 `set-window-start' calls the function with the three arguments WINDOW, POS,
1702 and NOFORCE, then returns its result, instead of doing its normal
1704 (Lisp_Object window
, Lisp_Object pos
, Lisp_Object noforce
, Lisp_Object group
)
1707 && FUNCTIONP (Vset_window_start_group_function
))
1708 return call3 (Vset_window_start_group_function
, window
, pos
, noforce
);
1710 register struct window
*w
= decode_live_window (window
);
1712 set_marker_restricted (w
->start
, pos
, w
->contents
);
1713 /* This is not right, but much easier than doing what is right. */
1714 w
->start_at_line_beg
= false;
1716 w
->force_start
= true;
1717 wset_update_mode_line (w
);
1719 w
->window_end_valid
= false;
1726 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
1727 Spos_visible_in_window_p
, 0, 4, 0,
1728 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
1729 WINDOW must be a live window and defaults to the selected one.
1731 Return nil if that position is scrolled vertically out of view. If a
1732 character is only partially visible, nil is returned, unless the
1733 optional argument PARTIALLY is non-nil. If POS is only out of view
1734 because of horizontal scrolling, return non-nil. If POS is t, it
1735 specifies either the first position displayed on the last visible
1736 screen line in WINDOW, or the end-of-buffer position, whichever comes
1737 first. POS defaults to point in WINDOW; WINDOW defaults to the
1740 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1741 the return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
1742 where X and Y are the pixel coordinates relative to the top left corner
1743 of the window. The remaining elements are omitted if the character after
1744 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1745 off-window at the top and bottom of the screen line ("row") containing
1746 POS, ROWH is the visible height of that row, and VPOS is the row number
1749 If GROUP is non-nil, and WINDOW is part of a group of windows collectively
1750 displaying a buffer (such as with Follow Mode), test whether POS is visible
1751 in the group of windows rather than in the individual WINDOW. This
1752 condition holds when `pos-visible-in-window-p-function' is set to a
1753 function, in which case `pos-visible-in-window-p' calls the function with
1754 the three arguments POS, WINDOW, and PARTIALLY, then returns its result,
1755 instead of doing its normal processing. */)
1756 (Lisp_Object pos
, Lisp_Object window
, Lisp_Object partially
, Lisp_Object group
)
1759 && FUNCTIONP (Vpos_visible_in_window_p_group_function
))
1760 return call3 (Vpos_visible_in_window_p_group_function
, pos
, window
, partially
);
1765 struct text_pos top
;
1766 Lisp_Object in_window
= Qnil
;
1767 int rtop
, rbot
, rowh
, vpos
;
1768 bool fully_p
= true;
1771 w
= decode_live_window (window
);
1772 buf
= XBUFFER (w
->contents
);
1773 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1777 else if (!NILP (pos
))
1779 CHECK_NUMBER_COERCE_MARKER (pos
);
1780 posint
= XINT (pos
);
1782 else if (w
== XWINDOW (selected_window
))
1785 posint
= marker_position (w
->pointm
);
1787 /* If position is above window start or outside buffer boundaries,
1788 or if window start is out of range, position is not visible. */
1790 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
1791 && CHARPOS (top
) >= BUF_BEGV (buf
)
1792 && CHARPOS (top
) <= BUF_ZV (buf
)
1793 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
1795 fully_p
= !rtop
&& !rbot
;
1796 if (!NILP (partially
) || fully_p
)
1800 if (!NILP (in_window
) && !NILP (partially
))
1802 Lisp_Object part
= Qnil
;
1804 part
= list4i (rtop
, rbot
, rowh
, vpos
);
1805 in_window
= Fcons (make_number (x
),
1806 Fcons (make_number (y
), part
));
1813 DEFUN ("window-line-height", Fwindow_line_height
,
1814 Swindow_line_height
, 0, 2, 0,
1815 doc
: /* Return height in pixels of text line LINE in window WINDOW.
1816 WINDOW must be a live window and defaults to the selected one.
1818 Return height of current line if LINE is omitted or nil. Return height of
1819 header or mode line if LINE is `header-line' or `mode-line'.
1820 Otherwise, LINE is a text line number starting from 0. A negative number
1821 counts from the end of the window.
1823 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
1824 in pixels of the visible part of the line, VPOS and YPOS are the
1825 vertical position in lines and pixels of the line, relative to the top
1826 of the first text line, and OFFBOT is the number of off-window pixels at
1827 the bottom of the text line. If there are off-window pixels at the top
1828 of the (first) text line, YPOS is negative.
1830 Return nil if window display is not up-to-date. In that case, use
1831 `pos-visible-in-window-p' to obtain the information. */)
1832 (Lisp_Object line
, Lisp_Object window
)
1834 register struct window
*w
;
1835 register struct buffer
*b
;
1836 struct glyph_row
*row
, *end_row
;
1840 w
= decode_live_window (window
);
1842 if (noninteractive
|| w
->pseudo_window_p
)
1845 CHECK_BUFFER (w
->contents
);
1846 b
= XBUFFER (w
->contents
);
1848 /* Fail if current matrix is not up-to-date. */
1849 if (!w
->window_end_valid
1850 || windows_or_buffers_changed
1852 || b
->prevent_redisplay_optimizations_p
1853 || window_outdated (w
))
1859 if (i
< 0 || i
>= w
->current_matrix
->nrows
1860 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
1862 max_y
= window_text_bottom_y (w
);
1866 if (EQ (line
, Qheader_line
))
1868 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
1870 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
1871 return row
->enabled_p
? list4i (row
->height
, 0, 0, 0) : Qnil
;
1874 if (EQ (line
, Qmode_line
))
1876 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
1877 return (row
->enabled_p
?
1878 list4i (row
->height
,
1879 0, /* not accurate */
1880 (WINDOW_HEADER_LINE_HEIGHT (w
)
1881 + window_text_bottom_y (w
)),
1886 CHECK_NUMBER (line
);
1889 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1890 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1891 max_y
= window_text_bottom_y (w
);
1894 while ((n
< 0 || i
< n
)
1895 && row
<= end_row
&& row
->enabled_p
1896 && row
->y
+ row
->height
< max_y
)
1899 if (row
> end_row
|| !row
->enabled_p
)
1911 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
1912 return list4i (row
->height
+ min (0, row
->y
) - crop
, i
, row
->y
, crop
);
1915 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1917 doc
: /* Return non-nil when WINDOW is dedicated to its buffer.
1918 More precisely, return the value assigned by the last call of
1919 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1920 never called with WINDOW as its argument, or the value set by that
1921 function was internally reset since its last call. WINDOW must be a
1922 live window and defaults to the selected one.
1924 When a window is dedicated to its buffer, `display-buffer' will refrain
1925 from displaying another buffer in it. `get-lru-window' and
1926 `get-largest-window' treat dedicated windows specially.
1927 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1928 `kill-buffer' can delete a dedicated window and the containing frame.
1930 Functions like `set-window-buffer' may change the buffer displayed by a
1931 window, unless that window is "strongly" dedicated to its buffer, that
1932 is the value returned by `window-dedicated-p' is t. */)
1933 (Lisp_Object window
)
1935 return decode_live_window (window
)->dedicated
;
1938 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1939 Sset_window_dedicated_p
, 2, 2, 0,
1940 doc
: /* Mark WINDOW as dedicated according to FLAG.
1941 WINDOW must be a live window and defaults to the selected one. FLAG
1942 non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means
1943 mark WINDOW as non-dedicated. Return FLAG.
1945 When a window is dedicated to its buffer, `display-buffer' will refrain
1946 from displaying another buffer in it. `get-lru-window' and
1947 `get-largest-window' treat dedicated windows specially.
1948 `delete-windows-on', `replace-buffer-in-windows', `quit-window',
1949 `quit-restore-window' and `kill-buffer' can delete a dedicated window
1950 and the containing frame.
1952 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
1953 its buffer. Functions like `set-window-buffer' may change the buffer
1954 displayed by a window, unless that window is strongly dedicated to its
1955 buffer. If and when `set-window-buffer' displays another buffer in a
1956 window, it also makes sure that the window is no more dedicated. */)
1957 (Lisp_Object window
, Lisp_Object flag
)
1959 wset_dedicated (decode_live_window (window
), flag
);
1963 DEFUN ("window-prev-buffers", Fwindow_prev_buffers
, Swindow_prev_buffers
,
1965 doc
: /* Return buffers previously shown in WINDOW.
1966 WINDOW must be a live window and defaults to the selected one.
1968 The return value is a list of elements (BUFFER WINDOW-START POS),
1969 where BUFFER is a buffer, WINDOW-START is the start position of the
1970 window for that buffer, and POS is a window-specific point value. */)
1971 (Lisp_Object window
)
1973 return decode_live_window (window
)->prev_buffers
;
1976 DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers
,
1977 Sset_window_prev_buffers
, 2, 2, 0,
1978 doc
: /* Set WINDOW's previous buffers to PREV-BUFFERS.
1979 WINDOW must be a live window and defaults to the selected one.
1981 PREV-BUFFERS should be a list of elements (BUFFER WINDOW-START POS),
1982 where BUFFER is a buffer, WINDOW-START is the start position of the
1983 window for that buffer, and POS is a window-specific point value. */)
1984 (Lisp_Object window
, Lisp_Object prev_buffers
)
1986 wset_prev_buffers (decode_live_window (window
), prev_buffers
);
1987 return prev_buffers
;
1990 DEFUN ("window-next-buffers", Fwindow_next_buffers
, Swindow_next_buffers
,
1992 doc
: /* Return list of buffers recently re-shown in WINDOW.
1993 WINDOW must be a live window and defaults to the selected one. */)
1994 (Lisp_Object window
)
1996 return decode_live_window (window
)->next_buffers
;
1999 DEFUN ("set-window-next-buffers", Fset_window_next_buffers
,
2000 Sset_window_next_buffers
, 2, 2, 0,
2001 doc
: /* Set WINDOW's next buffers to NEXT-BUFFERS.
2002 WINDOW must be a live window and defaults to the selected one.
2003 NEXT-BUFFERS should be a list of buffers. */)
2004 (Lisp_Object window
, Lisp_Object next_buffers
)
2006 wset_next_buffers (decode_live_window (window
), next_buffers
);
2007 return next_buffers
;
2010 DEFUN ("window-parameters", Fwindow_parameters
, Swindow_parameters
,
2012 doc
: /* Return the parameters of WINDOW and their values.
2013 WINDOW must be a valid window and defaults to the selected one. The
2014 return value is a list of elements of the form (PARAMETER . VALUE). */)
2015 (Lisp_Object window
)
2017 return Fcopy_alist (decode_valid_window (window
)->window_parameters
);
2020 DEFUN ("window-parameter", Fwindow_parameter
, Swindow_parameter
,
2022 doc
: /* Return WINDOW's value for PARAMETER.
2023 WINDOW can be any window and defaults to the selected one. */)
2024 (Lisp_Object window
, Lisp_Object parameter
)
2028 result
= Fassq (parameter
, decode_any_window (window
)->window_parameters
);
2029 return CDR_SAFE (result
);
2032 DEFUN ("set-window-parameter", Fset_window_parameter
,
2033 Sset_window_parameter
, 3, 3, 0,
2034 doc
: /* Set WINDOW's value of PARAMETER to VALUE.
2035 WINDOW can be any window and defaults to the selected one.
2037 (Lisp_Object window
, Lisp_Object parameter
, Lisp_Object value
)
2039 register struct window
*w
= decode_any_window (window
);
2040 Lisp_Object old_alist_elt
;
2042 old_alist_elt
= Fassq (parameter
, w
->window_parameters
);
2043 if (NILP (old_alist_elt
))
2044 wset_window_parameters
2045 (w
, Fcons (Fcons (parameter
, value
), w
->window_parameters
));
2047 Fsetcdr (old_alist_elt
, value
);
2051 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
2053 doc
: /* Return the display-table that WINDOW is using.
2054 WINDOW must be a live window and defaults to the selected one. */)
2055 (Lisp_Object window
)
2057 return decode_live_window (window
)->display_table
;
2060 /* Get the display table for use on window W. This is either W's
2061 display table or W's buffer's display table. Ignore the specified
2062 tables if they are not valid; if no valid table is specified,
2065 struct Lisp_Char_Table
*
2066 window_display_table (struct window
*w
)
2068 struct Lisp_Char_Table
*dp
= NULL
;
2070 if (DISP_TABLE_P (w
->display_table
))
2071 dp
= XCHAR_TABLE (w
->display_table
);
2072 else if (BUFFERP (w
->contents
))
2074 struct buffer
*b
= XBUFFER (w
->contents
);
2076 if (DISP_TABLE_P (BVAR (b
, display_table
)))
2077 dp
= XCHAR_TABLE (BVAR (b
, display_table
));
2078 else if (DISP_TABLE_P (Vstandard_display_table
))
2079 dp
= XCHAR_TABLE (Vstandard_display_table
);
2085 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
2086 doc
: /* Set WINDOW's display-table to TABLE.
2087 WINDOW must be a live window and defaults to the selected one. */)
2088 (register Lisp_Object window
, Lisp_Object table
)
2090 wset_display_table (decode_live_window (window
), table
);
2094 /* Record info on buffer window W is displaying
2095 when it is about to cease to display that buffer. */
2097 unshow_buffer (register struct window
*w
)
2099 Lisp_Object buf
= w
->contents
;
2100 struct buffer
*b
= XBUFFER (buf
);
2102 eassert (b
== XMARKER (w
->pointm
)->buffer
);
2105 if (w
== XWINDOW (selected_window
)
2106 || ! EQ (buf
, XWINDOW (selected_window
)->contents
))
2107 /* Do this except when the selected window's buffer
2108 is being removed from some other window. */
2110 /* last_window_start records the start position that this buffer
2111 had in the last window to be disconnected from it.
2112 Now that this statement is unconditional,
2113 it is possible for the buffer to be displayed in the
2114 selected window, while last_window_start reflects another
2115 window which was recently showing the same buffer.
2116 Some people might say that might be a good thing. Let's see. */
2117 b
->last_window_start
= marker_position (w
->start
);
2119 /* Point in the selected window's buffer
2120 is actually stored in that buffer, and the window's pointm isn't used.
2121 So don't clobber point in that buffer. */
2122 if (! EQ (buf
, XWINDOW (selected_window
)->contents
)
2123 /* Don't clobber point in current buffer either (this could be
2124 useful in connection with bug#12208).
2125 && XBUFFER (buf) != current_buffer */
2126 /* This line helps to fix Horsley's testbug.el bug. */
2127 && !(WINDOWP (BVAR (b
, last_selected_window
))
2128 && w
!= XWINDOW (BVAR (b
, last_selected_window
))
2129 && EQ (buf
, XWINDOW (BVAR (b
, last_selected_window
))->contents
)))
2130 temp_set_point_both (b
,
2131 clip_to_bounds (BUF_BEGV (b
),
2132 marker_position (w
->pointm
),
2134 clip_to_bounds (BUF_BEGV_BYTE (b
),
2135 marker_byte_position (w
->pointm
),
2138 if (WINDOWP (BVAR (b
, last_selected_window
))
2139 && w
== XWINDOW (BVAR (b
, last_selected_window
)))
2140 bset_last_selected_window (b
, Qnil
);
2143 /* Put NEW into the window structure in place of OLD. SETFLAG false
2144 means change window structure only. Otherwise store geometry and
2145 other settings as well. */
2147 replace_window (Lisp_Object old
, Lisp_Object
new, bool setflag
)
2150 struct window
*o
= XWINDOW (old
), *n
= XWINDOW (new);
2152 /* If OLD is its frame's root window, then NEW is the new
2153 root window for that frame. */
2154 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
2155 fset_root_window (XFRAME (o
->frame
), new);
2159 n
->pixel_left
= o
->pixel_left
;
2160 n
->pixel_top
= o
->pixel_top
;
2161 n
->pixel_width
= o
->pixel_width
;
2162 n
->pixel_height
= o
->pixel_height
;
2163 n
->left_col
= o
->left_col
;
2164 n
->top_line
= o
->top_line
;
2165 n
->total_cols
= o
->total_cols
;
2166 n
->total_lines
= o
->total_lines
;
2167 wset_normal_cols (n
, o
->normal_cols
);
2168 wset_normal_cols (o
, make_float (1.0));
2169 wset_normal_lines (n
, o
->normal_lines
);
2170 wset_normal_lines (o
, make_float (1.0));
2171 n
->desired_matrix
= n
->current_matrix
= 0;
2173 memset (&n
->cursor
, 0, sizeof (n
->cursor
));
2174 memset (&n
->phys_cursor
, 0, sizeof (n
->phys_cursor
));
2175 n
->last_cursor_vpos
= 0;
2176 #ifdef HAVE_WINDOW_SYSTEM
2177 n
->phys_cursor_type
= NO_CURSOR
;
2178 n
->phys_cursor_width
= -1;
2180 n
->must_be_updated_p
= false;
2181 n
->pseudo_window_p
= false;
2182 n
->window_end_vpos
= 0;
2183 n
->window_end_pos
= 0;
2184 n
->window_end_valid
= false;
2190 wset_prev (XWINDOW (tem
), new);
2195 wset_next (XWINDOW (tem
), new);
2198 wset_parent (n
, tem
);
2199 if (!NILP (tem
) && EQ (XWINDOW (tem
)->contents
, old
))
2200 wset_combination (XWINDOW (tem
), XWINDOW (tem
)->horizontal
, new);
2203 /* If window WINDOW and its parent window are iso-combined, merge
2204 WINDOW's children into those of its parent window and mark WINDOW as
2208 recombine_windows (Lisp_Object window
)
2210 struct window
*w
, *p
, *c
;
2211 Lisp_Object parent
, child
;
2214 w
= XWINDOW (window
);
2216 if (!NILP (parent
) && NILP (w
->combination_limit
))
2218 p
= XWINDOW (parent
);
2219 if (WINDOWP (p
->contents
) && WINDOWP (w
->contents
)
2220 && p
->horizontal
== w
->horizontal
)
2221 /* WINDOW and PARENT are both either a vertical or a horizontal
2224 horflag
= WINDOW_HORIZONTAL_COMBINATION_P (w
);
2225 child
= w
->contents
;
2226 c
= XWINDOW (child
);
2228 /* Splice WINDOW's children into its parent's children and
2229 assign new normal sizes. */
2231 wset_combination (p
, horflag
, child
);
2234 wset_prev (c
, w
->prev
);
2235 wset_next (XWINDOW (w
->prev
), child
);
2240 wset_parent (c
, parent
);
2244 (c
, make_float ((double) c
->pixel_width
2245 / (double) p
->pixel_width
));
2248 (c
, make_float ((double) c
->pixel_height
2249 / (double) p
->pixel_height
));
2253 if (!NILP (w
->next
))
2255 wset_next (c
, w
->next
);
2256 wset_prev (XWINDOW (c
->next
), child
);
2264 c
= XWINDOW (child
);
2268 /* WINDOW can be deleted now. */
2269 wset_combination (w
, false, Qnil
);
2274 /* If WINDOW can be deleted, delete it. */
2276 delete_deletable_window (Lisp_Object window
)
2278 if (!NILP (call1 (Qwindow_deletable_p
, window
)))
2279 call1 (Qdelete_window
, window
);
2282 /***********************************************************************
2284 ***********************************************************************/
2286 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
2287 pointer. This is a callback function for foreach_window, used in
2288 the window_list function. */
2291 add_window_to_list (struct window
*w
, void *user_data
)
2293 Lisp_Object
*list
= user_data
;
2295 XSETWINDOW (window
, w
);
2296 *list
= Fcons (window
, *list
);
2301 /* Return a list of all windows, for use by next_window. If
2302 Vwindow_list is a list, return that list. Otherwise, build a new
2303 list, cache it in Vwindow_list, and return that. */
2308 if (!CONSP (Vwindow_list
))
2310 Lisp_Object tail
, frame
;
2312 Vwindow_list
= Qnil
;
2313 FOR_EACH_FRAME (tail
, frame
)
2315 Lisp_Object arglist
= Qnil
;
2317 /* We are visiting windows in canonical order, and add
2318 new windows at the front of args[1], which means we
2319 have to reverse this list at the end. */
2320 foreach_window (XFRAME (frame
), add_window_to_list
, &arglist
);
2321 arglist
= Fnreverse (arglist
);
2322 Vwindow_list
= CALLN (Fnconc
, Vwindow_list
, arglist
);
2326 return Vwindow_list
;
2330 /* Value is true if WINDOW satisfies the constraints given by
2331 OWINDOW, MINIBUF and ALL_FRAMES.
2333 MINIBUF t means WINDOW may be minibuffer windows.
2334 `lambda' means WINDOW may not be a minibuffer window.
2335 a window means a specific minibuffer window
2337 ALL_FRAMES t means search all frames,
2338 nil means search just current frame,
2339 `visible' means search just visible frames on the
2341 0 means search visible and iconified frames on the
2343 a window means search the frame that window belongs to,
2344 a frame means consider windows on that frame, only. */
2347 candidate_window_p (Lisp_Object window
, Lisp_Object owindow
,
2348 Lisp_Object minibuf
, Lisp_Object all_frames
)
2350 struct window
*w
= XWINDOW (window
);
2351 struct frame
*f
= XFRAME (w
->frame
);
2352 bool candidate_p
= true;
2354 if (!BUFFERP (w
->contents
))
2355 candidate_p
= false;
2356 else if (MINI_WINDOW_P (w
)
2357 && (EQ (minibuf
, Qlambda
)
2358 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
2360 /* If MINIBUF is `lambda' don't consider any mini-windows.
2361 If it is a window, consider only that one. */
2362 candidate_p
= false;
2364 else if (EQ (all_frames
, Qt
))
2366 else if (NILP (all_frames
))
2368 eassert (WINDOWP (owindow
));
2369 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
2371 else if (EQ (all_frames
, Qvisible
))
2373 candidate_p
= FRAME_VISIBLE_P (f
)
2374 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2375 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2378 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
2380 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
2381 #ifdef HAVE_X_WINDOWS
2382 /* Yuck!! If we've just created the frame and the
2383 window-manager requested the user to place it
2384 manually, the window may still not be considered
2385 `visible'. I'd argue it should be at least
2386 something like `iconified', but don't know how to do
2388 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
2389 && !f
->output_data
.x
->has_been_visible
)
2392 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2393 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2395 else if (WINDOWP (all_frames
))
2396 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
2397 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
2398 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
2399 else if (FRAMEP (all_frames
))
2400 candidate_p
= EQ (all_frames
, w
->frame
);
2406 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2407 Fwindow_list. See candidate_window_p for the meaning of WINDOW,
2408 MINIBUF, and ALL_FRAMES. */
2411 decode_next_window_args (Lisp_Object
*window
, Lisp_Object
*minibuf
, Lisp_Object
*all_frames
)
2413 struct window
*w
= decode_live_window (*window
);
2415 XSETWINDOW (*window
, w
);
2416 /* MINIBUF nil may or may not include minibuffers. Decide if it
2418 if (NILP (*minibuf
))
2419 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
2420 else if (!EQ (*minibuf
, Qt
))
2423 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2424 => count none of them, or a specific minibuffer window (the
2425 active one) to count. */
2427 /* ALL_FRAMES nil doesn't specify which frames to include. */
2428 if (NILP (*all_frames
))
2430 = (!EQ (*minibuf
, Qlambda
)
2431 ? FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
))
2433 else if (EQ (*all_frames
, Qvisible
))
2435 else if (EQ (*all_frames
, make_number (0)))
2437 else if (FRAMEP (*all_frames
))
2439 else if (!EQ (*all_frames
, Qt
))
2444 /* Return the next or previous window of WINDOW in cyclic ordering
2445 of windows. NEXT_P means return the next window. See the
2446 documentation string of next-window for the meaning of MINIBUF and
2450 next_window (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
,
2453 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2455 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2456 return the first window on the frame. */
2457 if (FRAMEP (all_frames
)
2458 && !EQ (all_frames
, XWINDOW (window
)->frame
))
2459 return Fframe_first_window (all_frames
);
2465 /* Find WINDOW in the list of all windows. */
2466 list
= Fmemq (window
, window_list ());
2468 /* Scan forward from WINDOW to the end of the window list. */
2470 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
2471 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2474 /* Scan from the start of the window list up to WINDOW. */
2476 for (list
= Vwindow_list
;
2477 CONSP (list
) && !EQ (XCAR (list
), window
);
2479 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2483 window
= XCAR (list
);
2487 Lisp_Object candidate
, list
;
2489 /* Scan through the list of windows for candidates. If there are
2490 candidate windows in front of WINDOW, the last one of these
2491 is the one we want. If there are candidates following WINDOW
2492 in the list, again the last one of these is the one we want. */
2494 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
2496 if (EQ (XCAR (list
), window
))
2498 if (WINDOWP (candidate
))
2501 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
2503 candidate
= XCAR (list
);
2506 if (WINDOWP (candidate
))
2514 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
2515 doc
: /* Return live window after WINDOW in the cyclic ordering of windows.
2516 WINDOW must be a live window and defaults to the selected one. The
2517 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2520 MINIBUF nil or omitted means consider the minibuffer window only if the
2521 minibuffer is active. MINIBUF t means consider the minibuffer window
2522 even if the minibuffer is not active. Any other value means do not
2523 consider the minibuffer window even if the minibuffer is active.
2525 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2526 plus the minibuffer window if specified by the MINIBUF argument. If the
2527 minibuffer counts, consider all windows on all frames that share that
2528 minibuffer too. The following non-nil values of ALL-FRAMES have special
2531 - t means consider all windows on all existing frames.
2533 - `visible' means consider all windows on all visible frames.
2535 - 0 (the number zero) means consider all windows on all visible and
2538 - A frame means consider all windows on that frame only.
2540 Anything else means consider all windows on WINDOW's frame and no
2543 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2544 `next-window' to iterate through the entire cycle of acceptable
2545 windows, eventually ending up back at the window you started with.
2546 `previous-window' traverses the same cycle, in the reverse order. */)
2547 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2549 return next_window (window
, minibuf
, all_frames
, true);
2553 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
2554 doc
: /* Return live window before WINDOW in the cyclic ordering of windows.
2555 WINDOW must be a live window and defaults to the selected one. The
2556 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2559 MINIBUF nil or omitted means consider the minibuffer window only if the
2560 minibuffer is active. MINIBUF t means consider the minibuffer window
2561 even if the minibuffer is not active. Any other value means do not
2562 consider the minibuffer window even if the minibuffer is active.
2564 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2565 plus the minibuffer window if specified by the MINIBUF argument. If the
2566 minibuffer counts, consider all windows on all frames that share that
2567 minibuffer too. The following non-nil values of ALL-FRAMES have special
2570 - t means consider all windows on all existing frames.
2572 - `visible' means consider all windows on all visible frames.
2574 - 0 (the number zero) means consider all windows on all visible and
2577 - A frame means consider all windows on that frame only.
2579 Anything else means consider all windows on WINDOW's frame and no
2582 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2583 use `previous-window' to iterate through the entire cycle of
2584 acceptable windows, eventually ending up back at the window you
2585 started with. `next-window' traverses the same cycle, in the
2587 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2589 return next_window (window
, minibuf
, all_frames
, false);
2593 /* Return a list of windows in cyclic ordering. Arguments are like
2594 for `next-window'. */
2597 window_list_1 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2599 Lisp_Object tail
, list
, rest
;
2601 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2604 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2605 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2606 list
= Fcons (XCAR (tail
), list
);
2608 /* Rotate the list to start with WINDOW. */
2609 list
= Fnreverse (list
);
2610 rest
= Fmemq (window
, list
);
2611 if (!NILP (rest
) && !EQ (rest
, list
))
2613 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2615 XSETCDR (tail
, Qnil
);
2616 list
= nconc2 (rest
, list
);
2622 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2623 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2624 FRAME nil or omitted means use the selected frame.
2625 WINDOW nil or omitted means use the window selected within FRAME.
2626 MINIBUF t means include the minibuffer window, even if it isn't active.
2627 MINIBUF nil or omitted means include the minibuffer window only
2629 MINIBUF neither nil nor t means never include the minibuffer window. */)
2630 (Lisp_Object frame
, Lisp_Object minibuf
, Lisp_Object window
)
2633 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2634 CHECK_WINDOW (window
);
2636 frame
= selected_frame
;
2638 if (!EQ (frame
, XWINDOW (window
)->frame
))
2639 error ("Window is on a different frame");
2641 return window_list_1 (window
, minibuf
, frame
);
2645 DEFUN ("window-list-1", Fwindow_list_1
, Swindow_list_1
, 0, 3, 0,
2646 doc
: /* Return a list of all live windows.
2647 WINDOW specifies the first window to list and defaults to the selected
2650 Optional argument MINIBUF nil or omitted means consider the minibuffer
2651 window only if the minibuffer is active. MINIBUF t means consider the
2652 minibuffer window even if the minibuffer is not active. Any other value
2653 means do not consider the minibuffer window even if the minibuffer is
2656 Optional argument ALL-FRAMES nil or omitted means consider all windows
2657 on WINDOW's frame, plus the minibuffer window if specified by the
2658 MINIBUF argument. If the minibuffer counts, consider all windows on all
2659 frames that share that minibuffer too. The following non-nil values of
2660 ALL-FRAMES have special meanings:
2662 - t means consider all windows on all existing frames.
2664 - `visible' means consider all windows on all visible frames.
2666 - 0 (the number zero) means consider all windows on all visible and
2669 - A frame means consider all windows on that frame only.
2671 Anything else means consider all windows on WINDOW's frame and no
2674 If WINDOW is not on the list of windows returned, some other window will
2675 be listed first but no error is signaled. */)
2676 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2678 return window_list_1 (window
, minibuf
, all_frames
);
2681 /* Look at all windows, performing an operation specified by TYPE
2683 If FRAMES is Qt, look at all frames;
2684 Qnil, look at just the selected frame;
2685 Qvisible, look at visible frames;
2686 a frame, just look at windows on that frame.
2687 If MINI, perform the operation on minibuffer windows too. */
2692 GET_BUFFER_WINDOW
, /* Arg is buffer */
2693 REPLACE_BUFFER_IN_WINDOWS_SAFELY
, /* Arg is buffer */
2694 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2695 CHECK_ALL_WINDOWS
/* Arg is ignored */
2699 window_loop (enum window_loop type
, Lisp_Object obj
, bool mini
,
2702 Lisp_Object window
, windows
, best_window
, frame_arg
;
2703 bool frame_best_window_flag
= false;
2706 /* If we're only looping through windows on a particular frame,
2707 frame points to that frame. If we're looping through windows
2708 on all frames, frame is 0. */
2709 if (FRAMEP (frames
))
2710 f
= XFRAME (frames
);
2711 else if (NILP (frames
))
2712 f
= SELECTED_FRAME ();
2717 frame_arg
= Qlambda
;
2718 else if (EQ (frames
, make_number (0)))
2720 else if (EQ (frames
, Qvisible
))
2725 /* frame_arg is Qlambda to stick to one frame,
2726 Qvisible to consider all visible frames,
2729 /* Pick a window to start with. */
2733 window
= FRAME_SELECTED_WINDOW (f
);
2735 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2737 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2740 for (; CONSP (windows
); windows
= XCDR (windows
))
2744 window
= XCAR (windows
);
2745 w
= XWINDOW (window
);
2747 /* Note that we do not pay attention here to whether the frame
2748 is visible, since Fwindow_list skips non-visible frames if
2749 that is desired, under the control of frame_arg. */
2750 if (!MINI_WINDOW_P (w
)
2751 /* For REPLACE_BUFFER_IN_WINDOWS_SAFELY, we must always
2752 consider all windows. */
2753 || type
== REPLACE_BUFFER_IN_WINDOWS_SAFELY
2754 || (mini
&& minibuf_level
> 0))
2757 case GET_BUFFER_WINDOW
:
2758 if (EQ (w
->contents
, obj
)
2759 /* Don't find any minibuffer window except the one that
2760 is currently in use. */
2761 && (!MINI_WINDOW_P (w
) || EQ (window
, minibuf_window
)))
2763 if (EQ (window
, selected_window
))
2764 /* Preferably return the selected window. */
2766 else if (EQ (XWINDOW (window
)->frame
, selected_frame
)
2767 && !frame_best_window_flag
)
2768 /* Prefer windows on the current frame (but don't
2769 choose another one if we have one already). */
2771 best_window
= window
;
2772 frame_best_window_flag
= true;
2774 else if (NILP (best_window
))
2775 best_window
= window
;
2779 case REPLACE_BUFFER_IN_WINDOWS_SAFELY
:
2780 /* We could simply check whether the buffer shown by window
2781 is live, and show another buffer in case it isn't. */
2782 if (EQ (w
->contents
, obj
))
2784 /* Undedicate WINDOW. */
2785 wset_dedicated (w
, Qnil
);
2786 /* Make WINDOW show the buffer returned by
2787 other_buffer_safely, don't run any hooks. */
2789 (window
, other_buffer_safely (w
->contents
), false, false);
2790 /* If WINDOW is the selected window, make its buffer
2791 current. But do so only if the window shows the
2792 current buffer (Bug#6454). */
2793 if (EQ (window
, selected_window
)
2794 && XBUFFER (w
->contents
) == current_buffer
)
2795 Fset_buffer (w
->contents
);
2799 case REDISPLAY_BUFFER_WINDOWS
:
2800 if (EQ (w
->contents
, obj
))
2802 mark_window_display_accurate (window
, false);
2803 w
->update_mode_line
= true;
2804 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= true;
2805 update_mode_lines
= 27;
2806 best_window
= window
;
2810 /* Check for a leaf window that has a killed buffer
2811 or broken markers. */
2812 case CHECK_ALL_WINDOWS
:
2813 if (BUFFERP (w
->contents
))
2815 struct buffer
*b
= XBUFFER (w
->contents
);
2817 if (!BUFFER_LIVE_P (b
))
2819 if (!MARKERP (w
->start
) || XMARKER (w
->start
)->buffer
!= b
)
2821 if (!MARKERP (w
->pointm
) || XMARKER (w
->pointm
)->buffer
!= b
)
2826 case WINDOW_LOOP_UNUSED
:
2834 /* Used for debugging. Abort if any window has a dead buffer. */
2836 extern void check_all_windows (void) EXTERNALLY_VISIBLE
;
2838 check_all_windows (void)
2840 window_loop (CHECK_ALL_WINDOWS
, Qnil
, true, Qt
);
2843 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 0, 2, 0,
2844 doc
: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2845 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to
2848 The optional argument ALL-FRAMES specifies the frames to consider:
2850 - t means consider all windows on all existing frames.
2852 - `visible' means consider all windows on all visible frames.
2854 - 0 (the number zero) means consider all windows on all visible
2855 and iconified frames.
2857 - A frame means consider all windows on that frame only.
2859 Any other value of ALL-FRAMES means consider all windows on the
2860 selected frame and no others. */)
2861 (Lisp_Object buffer_or_name
, Lisp_Object all_frames
)
2865 if (NILP (buffer_or_name
))
2866 buffer
= Fcurrent_buffer ();
2868 buffer
= Fget_buffer (buffer_or_name
);
2870 if (BUFFERP (buffer
))
2871 return window_loop (GET_BUFFER_WINDOW
, buffer
, true, all_frames
);
2878 resize_root_window (Lisp_Object window
, Lisp_Object delta
, Lisp_Object horizontal
, Lisp_Object ignore
, Lisp_Object pixelwise
)
2880 return call5 (Qwindow_resize_root_window
, window
, delta
, horizontal
, ignore
, pixelwise
);
2883 /* Placeholder used by temacs -nw before window.el is loaded. */
2884 DEFUN ("window--sanitize-window-sizes", Fwindow__sanitize_window_sizes
,
2885 Swindow__sanitize_window_sizes
, 2, 2, 0,
2888 (Lisp_Object frame
, Lisp_Object horizontal
)
2894 sanitize_window_sizes (Lisp_Object frame
, Lisp_Object horizontal
)
2896 return call2 (Qwindow_sanitize_window_sizes
, frame
, horizontal
);
2901 window_pixel_to_total (Lisp_Object frame
, Lisp_Object horizontal
)
2903 return call2 (Qwindow_pixel_to_total
, frame
, horizontal
);
2907 DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal
,
2908 Sdelete_other_windows_internal
, 0, 2, "",
2909 doc
: /* Make WINDOW fill its frame.
2910 Only the frame WINDOW is on is affected. WINDOW must be a valid window
2911 and defaults to the selected one.
2913 Optional argument ROOT, if non-nil, must specify an internal window such
2914 that WINDOW is in its window subtree. If this is the case, replace ROOT
2915 by WINDOW and leave alone any windows not part of ROOT's subtree.
2917 When WINDOW is live try to reduce display jumps by keeping the text
2918 previously visible in WINDOW in the same place on the frame. Doing this
2919 depends on the value of (window-start WINDOW), so if calling this
2920 function in a program gives strange scrolling, make sure the
2921 window-start value is reasonable when this function is called. */)
2922 (Lisp_Object window
, Lisp_Object root
)
2924 struct window
*w
, *r
, *s
;
2926 Lisp_Object sibling
, pwindow
, swindow
IF_LINT (= Qnil
), delta
;
2927 ptrdiff_t startpos
IF_LINT (= 0), startbyte
IF_LINT (= 0);
2928 int top
IF_LINT (= 0), new_top
;
2930 w
= decode_valid_window (window
);
2931 XSETWINDOW (window
, w
);
2932 f
= XFRAME (w
->frame
);
2935 /* ROOT is the frame's root window. */
2937 root
= FRAME_ROOT_WINDOW (f
);
2941 /* ROOT must be an ancestor of WINDOW. */
2943 r
= decode_valid_window (root
);
2944 pwindow
= XWINDOW (window
)->parent
;
2945 while (!NILP (pwindow
))
2946 if (EQ (pwindow
, root
))
2949 pwindow
= XWINDOW (pwindow
)->parent
;
2950 if (!EQ (pwindow
, root
))
2951 error ("Specified root is not an ancestor of specified window");
2954 if (EQ (window
, root
))
2957 /* I don't understand the "top > 0" part below. If we deal with a
2958 standalone minibuffer it would have been caught by the preceding
2960 else if (MINI_WINDOW_P (w
)) /* && top > 0) */
2961 error ("Can't expand minibuffer to full frame");
2963 if (BUFFERP (w
->contents
))
2965 startpos
= marker_position (w
->start
);
2966 startbyte
= marker_byte_position (w
->start
);
2967 top
= (WINDOW_TOP_EDGE_LINE (w
)
2968 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
))));
2969 /* Make sure WINDOW is the frame's selected window. */
2970 if (!EQ (window
, FRAME_SELECTED_WINDOW (f
)))
2972 if (EQ (selected_frame
, w
->frame
))
2973 Fselect_window (window
, Qnil
);
2975 fset_selected_window (f
, window
);
2980 /* See if the frame's selected window is a part of the window
2981 subtree rooted at WINDOW, by finding all the selected window's
2982 parents and comparing each one with WINDOW. If it isn't we
2983 need a new selected window for this frame. */
2984 swindow
= FRAME_SELECTED_WINDOW (f
);
2988 while (!NILP (pwindow
) && !EQ (window
, pwindow
))
2989 pwindow
= XWINDOW (pwindow
)->parent
;
2991 if (EQ (window
, pwindow
))
2992 /* If WINDOW is an ancestor of SWINDOW, then SWINDOW is ok
2993 as the new selected window. */
2996 /* Else try the previous window of SWINDOW. */
2997 swindow
= Fprevious_window (swindow
, Qlambda
, Qnil
);
3000 if (!EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
3002 if (EQ (selected_frame
, w
->frame
))
3003 Fselect_window (swindow
, Qnil
);
3005 fset_selected_window (f
, swindow
);
3010 if (!FRAME_INITIAL_P (f
))
3012 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
3014 /* We are going to free the glyph matrices of WINDOW, and with
3015 that we might lose any information about glyph rows that have
3016 some of their glyphs highlighted in mouse face. (These rows
3017 are marked with a mouse_face_p flag.) If WINDOW
3018 indeed has some glyphs highlighted in mouse face, signal to
3019 frame's up-to-date hook that mouse highlight was overwritten,
3020 so that it will arrange for redisplaying the highlight. */
3021 if (EQ (hlinfo
->mouse_face_window
, window
))
3022 reset_mouse_highlight (hlinfo
);
3024 free_window_matrices (r
);
3027 Vwindow_list
= Qnil
;
3028 FRAME_WINDOW_SIZES_CHANGED (f
) = true;
3029 bool resize_failed
= false;
3031 if (!WINDOW_LEAF_P (w
))
3033 /* Resize child windows vertically. */
3034 XSETINT (delta
, r
->pixel_height
- w
->pixel_height
);
3035 w
->pixel_top
= r
->pixel_top
;
3036 w
->top_line
= r
->top_line
;
3037 resize_root_window (window
, delta
, Qnil
, Qnil
, Qt
);
3038 if (window_resize_check (w
, false))
3040 window_resize_apply (w
, false);
3041 window_pixel_to_total (w
->frame
, Qnil
);
3045 resize_root_window (window
, delta
, Qnil
, Qt
, Qt
);
3046 if (window_resize_check (w
, false))
3048 window_resize_apply (w
, false);
3049 window_pixel_to_total (w
->frame
, Qnil
);
3052 resize_failed
= true;
3055 /* Resize child windows horizontally. */
3058 w
->left_col
= r
->left_col
;
3059 w
->pixel_left
= r
->pixel_left
;
3060 XSETINT (delta
, r
->pixel_width
- w
->pixel_width
);
3061 resize_root_window (window
, delta
, Qt
, Qnil
, Qt
);
3062 if (window_resize_check (w
, true))
3064 window_resize_apply (w
, true);
3065 window_pixel_to_total (w
->frame
, Qt
);
3069 resize_root_window (window
, delta
, Qt
, Qt
, Qt
);
3070 if (window_resize_check (w
, true))
3072 window_resize_apply (w
, true);
3073 window_pixel_to_total (w
->frame
, Qt
);
3076 resize_failed
= true;
3081 /* Play safe, if we still can ... */
3084 w
= XWINDOW (window
);
3088 /* Cleanly unlink WINDOW from window-tree. */
3089 if (!NILP (w
->prev
))
3090 /* Get SIBLING above (on the left of) WINDOW. */
3093 s
= XWINDOW (sibling
);
3094 wset_next (s
, w
->next
);
3095 if (!NILP (s
->next
))
3096 wset_prev (XWINDOW (s
->next
), sibling
);
3099 /* Get SIBLING below (on the right of) WINDOW. */
3102 s
= XWINDOW (sibling
);
3103 wset_prev (s
, Qnil
);
3104 wset_combination (XWINDOW (w
->parent
),
3105 XWINDOW (w
->parent
)->horizontal
, sibling
);
3108 /* Delete ROOT and all child windows of ROOT. */
3109 if (WINDOWP (r
->contents
))
3111 delete_all_child_windows (r
->contents
);
3112 wset_combination (r
, false, Qnil
);
3115 replace_window (root
, window
, true);
3117 /* This must become SWINDOW anyway ....... */
3118 if (BUFFERP (w
->contents
) && !resize_failed
)
3120 /* Try to minimize scrolling, by setting the window start to the
3121 point will cause the text at the old window start to be at the
3122 same place on the frame. But don't try to do this if the
3123 window start is outside the visible portion (as might happen
3124 when the display is not current, due to typeahead). */
3125 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
3127 && startpos
>= BUF_BEGV (XBUFFER (w
->contents
))
3128 && startpos
<= BUF_ZV (XBUFFER (w
->contents
)))
3130 struct position pos
;
3131 struct buffer
*obuf
= current_buffer
;
3133 Fset_buffer (w
->contents
);
3134 /* This computation used to temporarily move point, but that
3135 can have unwanted side effects due to text properties. */
3136 pos
= *vmotion (startpos
, startbyte
, -top
, w
);
3138 set_marker_both (w
->start
, w
->contents
, pos
.bufpos
, pos
.bytepos
);
3139 w
->window_end_valid
= false;
3140 w
->start_at_line_beg
= (pos
.bytepos
== BEGV_BYTE
3141 || FETCH_BYTE (pos
.bytepos
- 1) == '\n');
3142 /* We need to do this, so that the window-scroll-functions
3144 w
->optional_new_start
= true;
3146 set_buffer_internal (obuf
);
3150 adjust_frame_glyphs (f
);
3153 run_window_configuration_change_hook (f
);
3160 replace_buffer_in_windows (Lisp_Object buffer
)
3162 call1 (Qreplace_buffer_in_windows
, buffer
);
3165 /* If BUFFER is shown in a window, safely replace it with some other
3166 buffer in all windows of all frames, even those on other keyboards. */
3169 replace_buffer_in_windows_safely (Lisp_Object buffer
)
3171 if (buffer_window_count (XBUFFER (buffer
)))
3173 Lisp_Object tail
, frame
;
3175 /* A single call to window_loop won't do the job because it only
3176 considers frames on the current keyboard. So loop manually over
3177 frames, and handle each one. */
3178 FOR_EACH_FRAME (tail
, frame
)
3179 window_loop (REPLACE_BUFFER_IN_WINDOWS_SAFELY
, buffer
, true, frame
);
3183 /* The following three routines are needed for running a window's
3184 configuration change hook. */
3186 run_funs (Lisp_Object funs
)
3188 for (; CONSP (funs
); funs
= XCDR (funs
))
3189 if (!EQ (XCAR (funs
), Qt
))
3190 call0 (XCAR (funs
));
3194 select_window_norecord (Lisp_Object window
)
3196 if (WINDOW_LIVE_P (window
))
3197 Fselect_window (window
, Qt
);
3201 select_frame_norecord (Lisp_Object frame
)
3203 if (FRAME_LIVE_P (XFRAME (frame
)))
3204 Fselect_frame (frame
, Qt
);
3208 run_window_configuration_change_hook (struct frame
*f
)
3210 ptrdiff_t count
= SPECPDL_INDEX ();
3211 Lisp_Object frame
, global_wcch
3212 = Fdefault_value (Qwindow_configuration_change_hook
);
3213 XSETFRAME (frame
, f
);
3215 if (NILP (Vrun_hooks
)
3216 || !(f
->can_x_set_window_size
)
3217 || !(f
->after_make_frame
))
3220 /* Use the right buffer. Matters when running the local hooks. */
3221 if (current_buffer
!= XBUFFER (Fwindow_buffer (Qnil
)))
3223 record_unwind_current_buffer ();
3224 Fset_buffer (Fwindow_buffer (Qnil
));
3227 if (SELECTED_FRAME () != f
)
3229 record_unwind_protect (select_frame_norecord
, selected_frame
);
3230 select_frame_norecord (frame
);
3233 /* Look for buffer-local values. */
3235 Lisp_Object windows
= Fwindow_list (frame
, Qlambda
, Qnil
);
3236 for (; CONSP (windows
); windows
= XCDR (windows
))
3238 Lisp_Object window
= XCAR (windows
);
3239 Lisp_Object buffer
= Fwindow_buffer (window
);
3240 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook
,
3243 ptrdiff_t inner_count
= SPECPDL_INDEX ();
3244 record_unwind_protect (select_window_norecord
, selected_window
);
3245 select_window_norecord (window
);
3246 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook
,
3248 unbind_to (inner_count
, Qnil
);
3253 run_funs (global_wcch
);
3254 unbind_to (count
, Qnil
);
3257 DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook
,
3258 Srun_window_configuration_change_hook
, 0, 1, 0,
3259 doc
: /* Run `window-configuration-change-hook' for FRAME.
3260 If FRAME is omitted or nil, it defaults to the selected frame. */)
3263 run_window_configuration_change_hook (decode_live_frame (frame
));
3267 DEFUN ("run-window-scroll-functions", Frun_window_scroll_functions
,
3268 Srun_window_scroll_functions
, 0, 1, 0,
3269 doc
: /* Run `window-scroll-functions' for WINDOW.
3270 If WINDOW is omitted or nil, it defaults to the selected window. */)
3271 (Lisp_Object window
)
3273 if (! NILP (Vwindow_scroll_functions
))
3274 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3275 Fmarker_position (decode_live_window (window
)->start
));
3279 /* Make WINDOW display BUFFER. RUN_HOOKS_P means it's allowed
3280 to run hooks. See make_frame for a case where it's not allowed.
3281 KEEP_MARGINS_P means that the current margins, fringes, and
3282 scroll-bar settings of the window are not reset from the buffer's
3286 set_window_buffer (Lisp_Object window
, Lisp_Object buffer
,
3287 bool run_hooks_p
, bool keep_margins_p
)
3289 struct window
*w
= XWINDOW (window
);
3290 struct buffer
*b
= XBUFFER (buffer
);
3291 ptrdiff_t count
= SPECPDL_INDEX ();
3292 bool samebuf
= EQ (buffer
, w
->contents
);
3294 wset_buffer (w
, buffer
);
3296 if (EQ (window
, selected_window
))
3297 bset_last_selected_window (b
, window
);
3299 /* Let redisplay errors through. */
3300 b
->display_error_modiff
= 0;
3302 /* Update time stamps of buffer display. */
3303 if (INTEGERP (BVAR (b
, display_count
)))
3304 bset_display_count (b
, make_number (XINT (BVAR (b
, display_count
)) + 1));
3305 bset_display_time (b
, Fcurrent_time ());
3307 w
->window_end_pos
= 0;
3308 w
->window_end_vpos
= 0;
3309 w
->last_cursor_vpos
= 0;
3311 if (!(keep_margins_p
&& samebuf
))
3312 { /* If we're not actually changing the buffer, don't reset hscroll
3313 and vscroll. This case happens for example when called from
3314 change_frame_size_1, where we use a dummy call to
3315 Fset_window_buffer on the frame's selected window (and no
3316 other) just in order to run window-configuration-change-hook
3317 (no longer true since change_frame_size_1 directly calls
3318 run_window_configuration_change_hook). Resetting hscroll and
3319 vscroll here is problematic for things like image-mode and
3320 doc-view-mode since it resets the image's position whenever we
3321 resize the frame. */
3322 w
->hscroll
= w
->min_hscroll
= w
->hscroll_whole
= 0;
3323 w
->suspend_auto_hscroll
= false;
3325 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3326 set_marker_both (w
->old_pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3327 set_marker_restricted (w
->start
,
3328 make_number (b
->last_window_start
),
3330 w
->start_at_line_beg
= false;
3331 w
->force_start
= false;
3333 /* Maybe we could move this into the `if' but it's not obviously safe and
3334 I doubt it's worth the trouble. */
3337 wset_update_mode_line (w
);
3339 /* We must select BUFFER to run the window-scroll-functions and to look up
3340 the buffer-local value of Vwindow_point_insertion_type. */
3341 record_unwind_current_buffer ();
3342 Fset_buffer (buffer
);
3344 XMARKER (w
->pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3345 XMARKER (w
->old_pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3347 if (!keep_margins_p
)
3349 /* Set left and right marginal area width etc. from buffer. */
3350 set_window_fringes (w
, BVAR (b
, left_fringe_width
),
3351 BVAR (b
, right_fringe_width
),
3352 BVAR (b
, fringes_outside_margins
));
3353 set_window_scroll_bars (w
, BVAR (b
, scroll_bar_width
),
3354 BVAR (b
, vertical_scroll_bar_type
),
3355 BVAR (b
, scroll_bar_height
),
3356 BVAR (b
, horizontal_scroll_bar_type
));
3357 set_window_margins (w
, BVAR (b
, left_margin_cols
),
3358 BVAR (b
, right_margin_cols
));
3359 apply_window_adjustment (w
);
3364 if (! NILP (Vwindow_scroll_functions
))
3365 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3366 Fmarker_position (w
->start
));
3368 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w
)));
3371 unbind_to (count
, Qnil
);
3374 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3375 doc
: /* Make WINDOW display BUFFER-OR-NAME.
3376 WINDOW must be a live window and defaults to the selected one.
3377 BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
3379 Optional third argument KEEP-MARGINS non-nil means that WINDOW's current
3380 display margins, fringe widths, and scroll bar settings are preserved;
3381 the default is to reset these from the local settings for BUFFER-OR-NAME
3382 or the frame defaults. Return nil.
3384 This function throws an error when WINDOW is strongly dedicated to its
3385 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3386 already display BUFFER-OR-NAME.
3388 This function runs `window-scroll-functions' before running
3389 `window-configuration-change-hook'. */)
3390 (register Lisp_Object window
, Lisp_Object buffer_or_name
, Lisp_Object keep_margins
)
3392 register Lisp_Object tem
, buffer
;
3393 register struct window
*w
= decode_live_window (window
);
3395 XSETWINDOW (window
, w
);
3396 buffer
= Fget_buffer (buffer_or_name
);
3397 CHECK_BUFFER (buffer
);
3398 if (!BUFFER_LIVE_P (XBUFFER (buffer
)))
3399 error ("Attempt to display deleted buffer");
3403 error ("Window is deleted");
3406 if (!EQ (tem
, buffer
))
3408 if (EQ (w
->dedicated
, Qt
))
3409 /* WINDOW is strongly dedicated to its buffer, signal an
3411 error ("Window is dedicated to `%s'", SDATA (BVAR (XBUFFER (tem
), name
)));
3413 /* WINDOW is weakly dedicated to its buffer, reset
3415 wset_dedicated (w
, Qnil
);
3417 call1 (Qrecord_window_buffer
, window
);
3423 set_window_buffer (window
, buffer
, true, !NILP (keep_margins
));
3429 display_buffer (Lisp_Object buffer
, Lisp_Object not_this_window_p
, Lisp_Object override_frame
)
3431 return call3 (Qdisplay_buffer
, buffer
, not_this_window_p
, override_frame
);
3434 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3436 doc
: /* Force all windows to be updated on next redisplay.
3437 If optional arg OBJECT is a window, force redisplay of that window only.
3438 If OBJECT is a buffer or buffer name, force redisplay of all windows
3439 displaying that buffer. */)
3440 (Lisp_Object object
)
3444 windows_or_buffers_changed
= 29;
3445 update_mode_lines
= 28;
3449 if (WINDOWP (object
))
3451 struct window
*w
= XWINDOW (object
);
3452 mark_window_display_accurate (object
, false);
3453 w
->update_mode_line
= true;
3454 if (BUFFERP (w
->contents
))
3455 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= true;
3456 update_mode_lines
= 29;
3460 if (STRINGP (object
))
3461 object
= Fget_buffer (object
);
3462 if (BUFFERP (object
) && BUFFER_LIVE_P (XBUFFER (object
))
3463 && buffer_window_count (XBUFFER (object
)))
3465 /* If buffer is live and shown in at least one window, find
3466 all windows showing this buffer and force update of them. */
3467 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, false, Qvisible
);
3468 return NILP (object
) ? Qnil
: Qt
;
3471 /* If nothing suitable was found, just return.
3472 We could signal an error, but this feature will typically be used
3473 asynchronously in timers or process sentinels, so we don't. */
3477 /* Obsolete since 24.3. */
3479 temp_output_buffer_show (register Lisp_Object buf
)
3481 register struct buffer
*old
= current_buffer
;
3482 register Lisp_Object window
;
3483 register struct window
*w
;
3485 bset_directory (XBUFFER (buf
), BVAR (current_buffer
, directory
));
3488 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3492 set_buffer_internal (old
);
3494 if (!NILP (Vtemp_buffer_show_function
))
3495 call1 (Vtemp_buffer_show_function
, buf
);
3496 else if (WINDOW_LIVE_P (window
= display_buffer (buf
, Qnil
, Qnil
)))
3498 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3499 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3500 Vminibuf_scroll_window
= window
;
3501 w
= XWINDOW (window
);
3502 w
->hscroll
= w
->min_hscroll
= w
->hscroll_whole
= 0;
3503 w
->suspend_auto_hscroll
= false;
3504 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3505 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3506 set_marker_restricted_both (w
->old_pointm
, buf
, BEG
, BEG
);
3508 /* Run temp-buffer-show-hook, with the chosen window selected
3509 and its buffer current. */
3511 ptrdiff_t count
= SPECPDL_INDEX ();
3512 Lisp_Object prev_window
, prev_buffer
;
3513 prev_window
= selected_window
;
3514 XSETBUFFER (prev_buffer
, old
);
3516 /* Select the window that was chosen, for running the hook.
3517 Note: Both Fselect_window and select_window_norecord may
3518 set-buffer to the buffer displayed in the window,
3519 so we need to save the current buffer. --stef */
3520 record_unwind_protect (restore_buffer
, prev_buffer
);
3521 record_unwind_protect (select_window_norecord
, prev_window
);
3522 Fselect_window (window
, Qt
);
3523 Fset_buffer (w
->contents
);
3524 run_hook (Qtemp_buffer_show_hook
);
3525 unbind_to (count
, Qnil
);
3530 /* Allocate basically initialized window. */
3532 static struct window
*
3533 allocate_window (void)
3535 return ALLOCATE_ZEROED_PSEUDOVECTOR
3536 (struct window
, current_matrix
, PVEC_WINDOW
);
3539 /* Make new window, have it replace WINDOW in window-tree, and make
3540 WINDOW its only vertical child (HORFLAG means make WINDOW its only
3541 horizontal child). */
3543 make_parent_window (Lisp_Object window
, bool horflag
)
3546 register struct window
*o
, *p
;
3548 o
= XWINDOW (window
);
3549 p
= allocate_window ();
3550 memcpy ((char *) p
+ sizeof (struct vectorlike_header
),
3551 (char *) o
+ sizeof (struct vectorlike_header
),
3552 word_size
* VECSIZE (struct window
));
3553 /* P's buffer slot may change from nil to a buffer... */
3554 adjust_window_count (p
, 1);
3555 XSETWINDOW (parent
, p
);
3557 p
->sequence_number
= ++sequence_number
;
3559 replace_window (window
, parent
, true);
3561 wset_next (o
, Qnil
);
3562 wset_prev (o
, Qnil
);
3563 wset_parent (o
, parent
);
3564 /* ...but now P becomes an internal window. */
3565 wset_start (p
, Qnil
);
3566 wset_pointm (p
, Qnil
);
3567 wset_old_pointm (p
, Qnil
);
3568 wset_buffer (p
, Qnil
);
3569 wset_combination (p
, horflag
, window
);
3570 wset_combination_limit (p
, Qnil
);
3571 wset_window_parameters (p
, Qnil
);
3574 /* Make new window from scratch. */
3579 register struct window
*w
;
3581 w
= allocate_window ();
3582 /* Initialize Lisp data. Note that allocate_window initializes all
3583 Lisp data to nil, so do it only for slots which should not be nil. */
3584 wset_normal_lines (w
, make_float (1.0));
3585 wset_normal_cols (w
, make_float (1.0));
3586 wset_new_total (w
, make_number (0));
3587 wset_new_normal (w
, make_number (0));
3588 wset_new_pixel (w
, make_number (0));
3589 wset_start (w
, Fmake_marker ());
3590 wset_pointm (w
, Fmake_marker ());
3591 wset_old_pointm (w
, Fmake_marker ());
3592 wset_vertical_scroll_bar_type (w
, Qt
);
3593 wset_horizontal_scroll_bar_type (w
, Qt
);
3594 /* These Lisp fields are marked specially so they're not set to nil by
3596 wset_prev_buffers (w
, Qnil
);
3597 wset_next_buffers (w
, Qnil
);
3599 /* Initialize non-Lisp data. Note that allocate_window zeroes out all
3600 non-Lisp data, so do it only for slots which should not be zero. */
3601 w
->nrows_scale_factor
= w
->ncols_scale_factor
= 1;
3602 w
->left_fringe_width
= w
->right_fringe_width
= -1;
3603 w
->mode_line_height
= w
->header_line_height
= -1;
3604 #ifdef HAVE_WINDOW_SYSTEM
3605 w
->phys_cursor_type
= NO_CURSOR
;
3606 w
->phys_cursor_width
= -1;
3608 w
->sequence_number
= ++sequence_number
;
3609 w
->scroll_bar_width
= -1;
3610 w
->scroll_bar_height
= -1;
3611 w
->column_number_displayed
= -1;
3612 /* Reset window_list. */
3613 Vwindow_list
= Qnil
;
3614 /* Return window. */
3615 XSETWINDOW (window
, w
);
3619 DEFUN ("set-window-new-pixel", Fset_window_new_pixel
, Sset_window_new_pixel
, 2, 3, 0,
3620 doc
: /* Set new pixel size of WINDOW to SIZE.
3621 WINDOW must be a valid window and defaults to the selected one.
3624 Optional argument ADD non-nil means add SIZE to the new pixel size of
3625 WINDOW and return the sum.
3627 The new pixel size of WINDOW, if valid, will be shortly installed as
3628 WINDOW's pixel height (see `window-pixel-height') or pixel width (see
3629 `window-pixel-width').
3631 Note: This function does not operate on any child windows of WINDOW. */)
3632 (Lisp_Object window
, Lisp_Object size
, Lisp_Object add
)
3634 struct window
*w
= decode_valid_window (window
);
3635 EMACS_INT size_min
= NILP (add
) ? 0 : - XINT (w
->new_pixel
);
3636 EMACS_INT size_max
= size_min
+ min (INT_MAX
, MOST_POSITIVE_FIXNUM
);
3638 CHECK_RANGED_INTEGER (size
, size_min
, size_max
);
3640 wset_new_pixel (w
, size
);
3642 wset_new_pixel (w
, make_number (XINT (w
->new_pixel
) + XINT (size
)));
3644 return w
->new_pixel
;
3647 DEFUN ("set-window-new-total", Fset_window_new_total
, Sset_window_new_total
, 2, 3, 0,
3648 doc
: /* Set new total size of WINDOW to SIZE.
3649 WINDOW must be a valid window and defaults to the selected one.
3652 Optional argument ADD non-nil means add SIZE to the new total size of
3653 WINDOW and return the sum.
3655 The new total size of WINDOW, if valid, will be shortly installed as
3656 WINDOW's total height (see `window-total-height') or total width (see
3657 `window-total-width').
3659 Note: This function does not operate on any child windows of WINDOW. */)
3660 (Lisp_Object window
, Lisp_Object size
, Lisp_Object add
)
3662 struct window
*w
= decode_valid_window (window
);
3664 CHECK_NUMBER (size
);
3666 wset_new_total (w
, size
);
3668 wset_new_total (w
, make_number (XINT (w
->new_total
) + XINT (size
)));
3670 return w
->new_total
;
3673 DEFUN ("set-window-new-normal", Fset_window_new_normal
, Sset_window_new_normal
, 1, 2, 0,
3674 doc
: /* Set new normal size of WINDOW to SIZE.
3675 WINDOW must be a valid window and defaults to the selected one.
3678 The new normal size of WINDOW, if valid, will be shortly installed as
3679 WINDOW's normal size (see `window-normal-size').
3681 Note: This function does not operate on any child windows of WINDOW. */)
3682 (Lisp_Object window
, Lisp_Object size
)
3684 wset_new_normal (decode_valid_window (window
), size
);
3688 /* Return true if setting w->pixel_height (w->pixel_width if HORFLAG)
3689 to w->new_pixel would result in correct heights (widths)
3690 for window W and recursively all child windows of W.
3692 Note: This function does not check any of `window-fixed-size-p',
3693 `window-min-height' or `window-min-width'. It does check that window
3694 sizes do not drop below one line (two columns). */
3696 window_resize_check (struct window
*w
, bool horflag
)
3698 struct frame
*f
= XFRAME (w
->frame
);
3701 if (WINDOW_VERTICAL_COMBINATION_P (w
))
3702 /* W is a vertical combination. */
3704 c
= XWINDOW (w
->contents
);
3706 /* All child windows of W must have the same width as W. */
3710 if (XINT (c
->new_pixel
) != XINT (w
->new_pixel
)
3711 || !window_resize_check (c
, horflag
))
3714 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3720 /* The sum of the heights of the child windows of W must equal
3723 int remaining_pixels
= XINT (w
->new_pixel
);
3727 if (!window_resize_check (c
, horflag
))
3730 remaining_pixels
-= XINT (c
->new_pixel
);
3731 if (remaining_pixels
< 0)
3733 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3736 return remaining_pixels
== 0;
3739 else if (WINDOW_HORIZONTAL_COMBINATION_P (w
))
3740 /* W is a horizontal combination. */
3742 c
= XWINDOW (w
->contents
);
3744 /* The sum of the widths of the child windows of W must equal W's
3747 int remaining_pixels
= XINT (w
->new_pixel
);
3751 if (!window_resize_check (c
, horflag
))
3754 remaining_pixels
-= XINT (c
->new_pixel
);
3755 if (remaining_pixels
< 0)
3757 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3760 return remaining_pixels
== 0;
3763 /* All child windows of W must have the same height as W. */
3767 if (XINT (c
->new_pixel
) != XINT (w
->new_pixel
)
3768 || !window_resize_check (c
, horflag
))
3771 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3778 /* A leaf window. Make sure it's not too small. The following
3779 hardcodes the values of `window-safe-min-width' (2) and
3780 `window-safe-min-height' (1) which are defined in window.el. */
3781 return (XINT (w
->new_pixel
) >= (horflag
3782 ? (2 * FRAME_COLUMN_WIDTH (f
))
3783 : FRAME_LINE_HEIGHT (f
)));
3787 /* Set w->pixel_height (w->pixel_width if HORFLAG) to
3788 w->new_pixel for window W and recursively all child windows of W.
3789 Also calculate and assign the new vertical (horizontal) pixel start
3790 positions of each of these windows.
3792 This function does not perform any error checks. Make sure you have
3793 run window_resize_check on W before applying this function. */
3795 window_resize_apply (struct window
*w
, bool horflag
)
3800 ? FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
))
3801 : FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
)));
3803 /* Note: Assigning new_normal requires that the new total size of the
3804 parent window has been set *before*. */
3807 w
->pixel_width
= XFASTINT (w
->new_pixel
);
3808 w
->total_cols
= w
->pixel_width
/ unit
;
3809 if (NUMBERP (w
->new_normal
))
3810 wset_normal_cols (w
, w
->new_normal
);
3812 edge
= w
->pixel_left
;
3816 w
->pixel_height
= XFASTINT (w
->new_pixel
);
3817 w
->total_lines
= w
->pixel_height
/ unit
;
3818 if (NUMBERP (w
->new_normal
))
3819 wset_normal_lines (w
, w
->new_normal
);
3821 edge
= w
->pixel_top
;
3824 if (WINDOW_VERTICAL_COMBINATION_P (w
))
3825 /* W is a vertical combination. */
3827 c
= XWINDOW (w
->contents
);
3832 c
->pixel_left
= edge
;
3833 c
->left_col
= edge
/ unit
;
3837 c
->pixel_top
= edge
;
3838 c
->top_line
= edge
/ unit
;
3840 window_resize_apply (c
, horflag
);
3842 edge
= edge
+ c
->pixel_height
;
3844 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3847 else if (WINDOW_HORIZONTAL_COMBINATION_P (w
))
3848 /* W is a horizontal combination. */
3850 c
= XWINDOW (w
->contents
);
3855 c
->pixel_left
= edge
;
3856 c
->left_col
= edge
/ unit
;
3860 c
->pixel_top
= edge
;
3861 c
->top_line
= edge
/ unit
;
3864 window_resize_apply (c
, horflag
);
3866 edge
= edge
+ c
->pixel_width
;
3868 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3873 w
->window_end_valid
= false;
3877 /* Set w->total_lines (w->total_cols if HORFLAG) to
3878 w->new_total for window W and recursively all child windows of W.
3879 Also calculate and assign the new vertical (horizontal) start
3880 positions of each of these windows. */
3882 window_resize_apply_total (struct window
*w
, bool horflag
)
3887 /* Note: Assigning new_normal requires that the new total size of the
3888 parent window has been set *before*. */
3891 w
->total_cols
= XFASTINT (w
->new_total
);
3896 w
->total_lines
= XFASTINT (w
->new_total
);
3900 if (WINDOW_VERTICAL_COMBINATION_P (w
))
3901 /* W is a vertical combination. */
3903 c
= XWINDOW (w
->contents
);
3911 window_resize_apply_total (c
, horflag
);
3913 edge
= edge
+ c
->total_lines
;
3915 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3918 else if (WINDOW_HORIZONTAL_COMBINATION_P (w
))
3919 /* W is a horizontal combination. */
3921 c
= XWINDOW (w
->contents
);
3929 window_resize_apply_total (c
, horflag
);
3931 edge
= edge
+ c
->total_cols
;
3933 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3938 DEFUN ("window-resize-apply", Fwindow_resize_apply
, Swindow_resize_apply
, 0, 2, 0,
3939 doc
: /* Apply requested size values for window-tree of FRAME.
3940 If FRAME is omitted or nil, it defaults to the selected frame.
3942 Optional argument HORIZONTAL omitted or nil means apply requested
3943 height values. HORIZONTAL non-nil means apply requested width values.
3945 The requested size values are those set by `set-window-new-pixel' and
3946 `set-window-new-normal'. This function checks whether the requested
3947 values sum up to a valid window layout, recursively assigns the new
3948 sizes of all child windows and calculates and assigns the new start
3949 positions of these windows.
3951 Return t if the requested values have been applied correctly, nil
3954 Note: This function does not check any of `window-fixed-size-p',
3955 `window-min-height' or `window-min-width'. All these checks have to
3956 be applied on the Elisp level. */)
3957 (Lisp_Object frame
, Lisp_Object horizontal
)
3959 struct frame
*f
= decode_live_frame (frame
);
3960 struct window
*r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3961 bool horflag
= !NILP (horizontal
);
3963 if (!window_resize_check (r
, horflag
)
3964 || (XINT (r
->new_pixel
)
3965 != (horflag
? r
->pixel_width
: r
->pixel_height
)))
3969 window_resize_apply (r
, horflag
);
3972 FRAME_WINDOW_SIZES_CHANGED (f
) = true;
3974 adjust_frame_glyphs (f
);
3981 DEFUN ("window-resize-apply-total", Fwindow_resize_apply_total
, Swindow_resize_apply_total
, 0, 2, 0,
3982 doc
: /* Apply requested total size values for window-tree of FRAME.
3983 If FRAME is omitted or nil, it defaults to the selected frame.
3985 This function does not assign pixel or normal size values. You should
3986 have run `window-resize-apply' before running this.
3988 Optional argument HORIZONTAL omitted or nil means apply requested
3989 height values. HORIZONTAL non-nil means apply requested width
3991 (Lisp_Object frame
, Lisp_Object horizontal
)
3993 struct frame
*f
= decode_live_frame (frame
);
3994 struct window
*r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3997 /* Necessary when deleting the top-/or leftmost window. */
3999 r
->top_line
= FRAME_TOP_MARGIN (f
);
4000 window_resize_apply_total (r
, !NILP (horizontal
));
4001 /* Handle the mini window. */
4002 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
4004 struct window
*m
= XWINDOW (f
->minibuffer_window
);
4006 if (NILP (horizontal
))
4008 m
->top_line
= r
->top_line
+ r
->total_lines
;
4009 m
->total_lines
= XFASTINT (m
->new_total
);
4012 m
->total_cols
= XFASTINT (m
->new_total
);
4021 /* Resize frame F's windows when number of lines of F is set to SIZE.
4022 HORFLAG means resize windows when number of columns of F is set to
4023 SIZE. PIXELWISE means to interpret SIZE as pixels. */
4025 resize_frame_windows (struct frame
*f
, int size
, bool horflag
, bool pixelwise
)
4027 Lisp_Object root
= f
->root_window
;
4028 struct window
*r
= XWINDOW (root
);
4029 Lisp_Object mini
= f
->minibuffer_window
;
4031 /* old_size is the old size of the frame's root window. */
4032 int old_size
= horflag
? r
->total_cols
: r
->total_lines
;
4033 int old_pixel_size
= horflag
? r
->pixel_width
: r
->pixel_height
;
4034 /* new_size is the new size of the frame's root window. */
4035 int new_size
, new_pixel_size
;
4036 int unit
= horflag
? FRAME_COLUMN_WIDTH (f
) : FRAME_LINE_HEIGHT (f
);
4038 /* Don't let the size drop below one unit. This is more comforting
4039 when we are called from x_set_tool_bar_lines since the latter may
4040 have implicitly given us a zero or negative height. */
4043 /* Note: This does not include the size for internal borders
4044 since these are not part of the frame's text area. */
4045 new_pixel_size
= max (horflag
4048 - ((FRAME_HAS_MINIBUF_P (f
)
4049 && !FRAME_MINIBUF_ONLY_P (f
))
4050 ? FRAME_LINE_HEIGHT (f
) : 0)),
4052 new_size
= new_pixel_size
/ unit
;
4056 new_size
= max (size
- (!horflag
4057 && FRAME_HAS_MINIBUF_P (f
)
4058 && !FRAME_MINIBUF_ONLY_P (f
)),
4060 new_pixel_size
= new_size
* unit
;
4063 if (new_pixel_size
== old_pixel_size
4064 && (horflag
|| r
->pixel_top
== FRAME_TOP_MARGIN_HEIGHT (f
)))
4066 else if (WINDOW_LEAF_P (r
))
4067 /* For a leaf root window just set the size. */
4070 r
->total_cols
= new_size
;
4071 r
->pixel_width
= new_pixel_size
;
4075 r
->top_line
= FRAME_TOP_MARGIN (f
);
4076 r
->pixel_top
= FRAME_TOP_MARGIN_HEIGHT (f
);
4078 r
->total_lines
= new_size
;
4079 r
->pixel_height
= new_pixel_size
;
4087 r
->top_line
= FRAME_TOP_MARGIN (f
);
4088 r
->pixel_top
= FRAME_TOP_MARGIN_HEIGHT (f
);
4092 XSETINT (delta
, new_pixel_size
- old_pixel_size
);
4094 XSETINT (delta
, new_size
- old_size
);
4096 /* Try a "normal" resize first. */
4097 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qnil
,
4098 pixelwise
? Qt
: Qnil
);
4099 if (window_resize_check (r
, horflag
)
4100 && new_pixel_size
== XINT (r
->new_pixel
))
4102 window_resize_apply (r
, horflag
);
4103 window_pixel_to_total (r
->frame
, horflag
? Qt
: Qnil
);
4107 /* Try with "reasonable" minimum sizes next. */
4108 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qt
,
4109 pixelwise
? Qt
: Qnil
);
4110 if (window_resize_check (r
, horflag
)
4111 && new_pixel_size
== XINT (r
->new_pixel
))
4113 window_resize_apply (r
, horflag
);
4114 window_pixel_to_total (r
->frame
, horflag
? Qt
: Qnil
);
4119 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
4124 m
->total_cols
= size
;
4125 m
->pixel_width
= new_pixel_size
;
4129 /* Are we sure we always want 1 line here? */
4131 m
->pixel_height
= FRAME_LINE_HEIGHT (f
);
4132 m
->top_line
= r
->top_line
+ r
->total_lines
;
4133 m
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4137 FRAME_WINDOW_SIZES_CHANGED (f
) = true;
4142 DEFUN ("split-window-internal", Fsplit_window_internal
, Ssplit_window_internal
, 4, 4, 0,
4143 doc
: /* Split window OLD.
4144 Second argument PIXEL-SIZE specifies the number of pixels of the
4145 new window. It must be a positive integer.
4147 Third argument SIDE nil (or `below') specifies that the new window shall
4148 be located below WINDOW. SIDE `above' means the new window shall be
4149 located above WINDOW. In both cases PIXEL-SIZE specifies the pixel
4150 height of the new window including space reserved for the mode and/or
4153 SIDE t (or `right') specifies that the new window shall be located on
4154 the right side of WINDOW. SIDE `left' means the new window shall be
4155 located on the left of WINDOW. In both cases PIXEL-SIZE specifies the
4156 width of the new window including space reserved for fringes and the
4157 scrollbar or a divider column.
4159 Fourth argument NORMAL-SIZE specifies the normal size of the new window
4160 according to the SIDE argument.
4162 The new pixel and normal sizes of all involved windows must have been
4163 set correctly. See the code of `split-window' for how this is done. */)
4164 (Lisp_Object old
, Lisp_Object pixel_size
, Lisp_Object side
, Lisp_Object normal_size
)
4166 /* OLD (*o) is the window we have to split. (*p) is either OLD's
4167 parent window or an internal window we have to install as OLD's new
4168 parent. REFERENCE (*r) must denote a live window, or is set to OLD
4169 provided OLD is a leaf window, or to the frame's selected window.
4170 NEW (*n) is the new window created with some parameters taken from
4172 Lisp_Object
new, frame
, reference
;
4173 struct window
*o
, *p
, *n
, *r
, *c
;
4176 /* HORFLAG is true when we split side-by-side, false otherwise. */
4177 = EQ (side
, Qt
) || EQ (side
, Qleft
) || EQ (side
, Qright
);
4181 frame
= WINDOW_FRAME (o
);
4184 CHECK_NUMBER (pixel_size
);
4185 EMACS_INT total_size
4186 = XINT (pixel_size
) / (horflag
4187 ? FRAME_COLUMN_WIDTH (f
)
4188 : FRAME_LINE_HEIGHT (f
));
4190 /* Set combination_limit if we have to make a new parent window.
4191 We do that if either `window-combination-limit' is t, or OLD has no
4192 parent, or OLD is ortho-combined. */
4193 bool combination_limit
4194 = (EQ (Vwindow_combination_limit
, Qt
)
4197 ? WINDOW_VERTICAL_COMBINATION_P (XWINDOW (o
->parent
))
4198 : WINDOW_HORIZONTAL_COMBINATION_P (XWINDOW (o
->parent
))));
4200 /* We need a live reference window to initialize some parameters. */
4201 if (WINDOW_LIVE_P (old
))
4202 /* OLD is live, use it as reference window. */
4205 /* Use the frame's selected window as reference window. */
4206 reference
= FRAME_SELECTED_WINDOW (f
);
4207 r
= XWINDOW (reference
);
4209 /* The following bugs are caught by `split-window'. */
4210 if (MINI_WINDOW_P (o
))
4211 error ("Attempt to split minibuffer window");
4212 else if (total_size
< (horflag
? 2 : 1))
4213 error ("Size of new window too small (after split)");
4214 else if (!combination_limit
&& !NILP (Vwindow_combination_resize
))
4215 /* `window-combination-resize' non-nil means try to resize OLD's siblings
4218 p
= XWINDOW (o
->parent
);
4219 /* Temporarily pretend we split the parent window. */
4221 (p
, make_number ((horflag
? p
->pixel_width
: p
->pixel_height
)
4222 - XINT (pixel_size
)));
4223 if (!window_resize_check (p
, horflag
))
4224 error ("Window sizes don't fit");
4226 /* Undo the temporary pretension. */
4227 wset_new_pixel (p
, make_number (horflag
? p
->pixel_width
: p
->pixel_height
));
4231 if (!window_resize_check (o
, horflag
))
4232 error ("Resizing old window failed");
4233 else if (XINT (pixel_size
) + XINT (o
->new_pixel
)
4234 != (horflag
? o
->pixel_width
: o
->pixel_height
))
4235 error ("Sum of sizes of old and new window don't fit");
4238 /* This is our point of no return. */
4239 if (combination_limit
)
4241 /* Save the old value of o->normal_cols/lines. It gets corrupted
4242 by make_parent_window and we need it below for assigning it to
4244 Lisp_Object new_normal
4245 = horflag
? o
->normal_cols
: o
->normal_lines
;
4247 make_parent_window (old
, horflag
);
4248 p
= XWINDOW (o
->parent
);
4249 if (EQ (Vwindow_combination_limit
, Qt
))
4250 /* Store t in the new parent's combination_limit slot to avoid
4251 that its children get merged into another window. */
4252 wset_combination_limit (p
, Qt
);
4253 /* These get applied below. */
4255 (p
, make_number (horflag
? o
->pixel_width
: o
->pixel_height
));
4257 (p
, make_number (horflag
? o
->total_cols
: o
->total_lines
));
4258 wset_new_normal (p
, new_normal
);
4261 p
= XWINDOW (o
->parent
);
4264 FRAME_WINDOW_SIZES_CHANGED (f
) = true;
4265 new = make_window ();
4267 wset_frame (n
, frame
);
4268 wset_parent (n
, o
->parent
);
4270 if (EQ (side
, Qabove
) || EQ (side
, Qleft
))
4272 wset_prev (n
, o
->prev
);
4274 wset_combination (p
, horflag
, new);
4276 wset_next (XWINDOW (n
->prev
), new);
4282 wset_next (n
, o
->next
);
4283 if (!NILP (n
->next
))
4284 wset_prev (XWINDOW (n
->next
), new);
4289 n
->window_end_valid
= false;
4290 n
->last_cursor_vpos
= 0;
4292 /* Get special geometry settings from reference window. */
4293 n
->left_margin_cols
= r
->left_margin_cols
;
4294 n
->right_margin_cols
= r
->right_margin_cols
;
4295 n
->left_fringe_width
= r
->left_fringe_width
;
4296 n
->right_fringe_width
= r
->right_fringe_width
;
4297 n
->fringes_outside_margins
= r
->fringes_outside_margins
;
4298 n
->scroll_bar_width
= r
->scroll_bar_width
;
4299 n
->scroll_bar_height
= r
->scroll_bar_height
;
4300 wset_vertical_scroll_bar_type (n
, r
->vertical_scroll_bar_type
);
4301 wset_horizontal_scroll_bar_type (n
, r
->horizontal_scroll_bar_type
);
4303 /* Directly assign orthogonal coordinates and sizes. */
4306 n
->pixel_top
= o
->pixel_top
;
4307 n
->top_line
= o
->top_line
;
4308 n
->pixel_height
= o
->pixel_height
;
4309 n
->total_lines
= o
->total_lines
;
4313 n
->pixel_left
= o
->pixel_left
;
4314 n
->left_col
= o
->left_col
;
4315 n
->pixel_width
= o
->pixel_width
;
4316 n
->total_cols
= o
->total_cols
;
4319 /* Iso-coordinates and sizes are assigned by window_resize_apply,
4320 get them ready here. */
4321 wset_new_pixel (n
, pixel_size
);
4323 c
= XWINDOW (p
->contents
);
4327 sum
= sum
+ XINT (c
->new_total
);
4328 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
4330 wset_new_total (n
, make_number ((horflag
4334 wset_new_normal (n
, normal_size
);
4337 window_resize_apply (p
, horflag
);
4338 adjust_frame_glyphs (f
);
4339 /* Set buffer of NEW to buffer of reference window. Don't run
4341 set_window_buffer (new, r
->contents
, false, true);
4344 /* Maybe we should run the scroll functions in Elisp (which already
4345 runs the configuration change hook). */
4346 if (! NILP (Vwindow_scroll_functions
))
4347 run_hook_with_args_2 (Qwindow_scroll_functions
, new,
4348 Fmarker_position (n
->start
));
4354 DEFUN ("delete-window-internal", Fdelete_window_internal
, Sdelete_window_internal
, 1, 1, 0,
4355 doc
: /* Remove WINDOW from its frame.
4356 WINDOW defaults to the selected window. Return nil.
4357 Signal an error when WINDOW is the only window on its frame. */)
4358 (Lisp_Object window
)
4360 Lisp_Object parent
, sibling
, frame
, root
;
4361 struct window
*w
, *p
, *s
, *r
;
4363 bool horflag
, before_sibling
= false;
4365 w
= decode_any_window (window
);
4366 XSETWINDOW (window
, w
);
4367 if (NILP (w
->contents
))
4368 /* It's a no-op to delete an already deleted window. */
4373 /* Never delete a minibuffer or frame root window. */
4374 error ("Attempt to delete minibuffer or sole ordinary window");
4375 else if (NILP (w
->prev
) && NILP (w
->next
))
4376 /* Rather bow out here, this case should be handled on the Elisp
4378 error ("Attempt to delete sole window of parent");
4380 p
= XWINDOW (parent
);
4381 horflag
= WINDOW_HORIZONTAL_COMBINATION_P (p
);
4383 frame
= WINDOW_FRAME (w
);
4386 root
= FRAME_ROOT_WINDOW (f
);
4389 /* Unlink WINDOW from window tree. */
4391 /* Get SIBLING below (on the right of) WINDOW. */
4393 /* before_sibling means WINDOW is the first child of its
4394 parent and thus before the sibling. */
4395 before_sibling
= true;
4397 s
= XWINDOW (sibling
);
4398 wset_prev (s
, Qnil
);
4399 wset_combination (p
, horflag
, sibling
);
4402 /* Get SIBLING above (on the left of) WINDOW. */
4405 s
= XWINDOW (sibling
);
4406 wset_next (s
, w
->next
);
4407 if (!NILP (s
->next
))
4408 wset_prev (XWINDOW (s
->next
), sibling
);
4411 if (window_resize_check (r
, horflag
)
4412 && (XINT (r
->new_pixel
)
4413 == (horflag
? r
->pixel_width
: r
->pixel_height
)))
4414 /* We can delete WINDOW now. */
4419 window_resize_apply (p
, horflag
);
4420 /* If this window is referred to by the dpyinfo's mouse
4421 highlight, invalidate that slot to be safe (Bug#9904). */
4422 if (!FRAME_INITIAL_P (f
))
4424 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
4426 if (EQ (hlinfo
->mouse_face_window
, window
))
4427 hlinfo
->mouse_face_window
= Qnil
;
4431 Vwindow_list
= Qnil
;
4432 FRAME_WINDOW_SIZES_CHANGED (f
) = true;
4434 wset_next (w
, Qnil
); /* Don't delete w->next too. */
4435 free_window_matrices (w
);
4437 if (WINDOWP (w
->contents
))
4439 delete_all_child_windows (w
->contents
);
4440 wset_combination (w
, false, Qnil
);
4445 unchain_marker (XMARKER (w
->pointm
));
4446 unchain_marker (XMARKER (w
->old_pointm
));
4447 unchain_marker (XMARKER (w
->start
));
4448 wset_buffer (w
, Qnil
);
4451 if (NILP (s
->prev
) && NILP (s
->next
))
4452 /* A matrjoshka where SIBLING has become the only child of
4455 /* Put SIBLING into PARENT's place. */
4456 replace_window (parent
, sibling
, false);
4457 /* Have SIBLING inherit the following three slot values from
4458 PARENT (the combination_limit slot is not inherited). */
4459 wset_normal_cols (s
, p
->normal_cols
);
4460 wset_normal_lines (s
, p
->normal_lines
);
4461 /* Mark PARENT as deleted. */
4462 wset_combination (p
, false, Qnil
);
4463 /* Try to merge SIBLING into its new parent. */
4464 recombine_windows (sibling
);
4467 adjust_frame_glyphs (f
);
4469 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f
)))
4470 /* We deleted the frame's selected window. */
4472 /* Use the frame's first window as fallback ... */
4473 Lisp_Object new_selected_window
= Fframe_first_window (frame
);
4474 /* ... but preferably use its most recently used window. */
4475 Lisp_Object mru_window
;
4477 /* `get-mru-window' might fail for some reason so play it safe
4478 - promote the first window _without recording it_ first. */
4479 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4480 Fselect_window (new_selected_window
, Qt
);
4482 fset_selected_window (f
, new_selected_window
);
4486 /* Now look whether `get-mru-window' gets us something. */
4487 mru_window
= call1 (Qget_mru_window
, frame
);
4488 if (WINDOW_LIVE_P (mru_window
)
4489 && EQ (XWINDOW (mru_window
)->frame
, frame
))
4490 new_selected_window
= mru_window
;
4492 /* If all ended up well, we now promote the mru window. */
4493 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4494 Fselect_window (new_selected_window
, Qnil
);
4496 fset_selected_window (f
, new_selected_window
);
4501 /* Must be run by the caller:
4502 run_window_configuration_change_hook (f); */
4505 /* We failed: Relink WINDOW into window tree. */
4509 wset_prev (s
, window
);
4510 wset_combination (p
, horflag
, window
);
4514 wset_next (s
, window
);
4515 if (!NILP (w
->next
))
4516 wset_prev (XWINDOW (w
->next
), window
);
4518 error ("Deletion failed");
4524 /***********************************************************************
4525 Resizing Mini-Windows
4526 ***********************************************************************/
4528 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we
4531 grow_mini_window (struct window
*w
, int delta
, bool pixelwise
)
4533 struct frame
*f
= XFRAME (w
->frame
);
4535 Lisp_Object root
, height
;
4536 int line_height
, pixel_height
;
4538 eassert (MINI_WINDOW_P (w
));
4539 eassert (delta
>= 0);
4543 root
= FRAME_ROOT_WINDOW (f
);
4545 height
= call3 (Qwindow_resize_root_window_vertically
,
4546 root
, make_number (- delta
), pixelwise
? Qt
: Qnil
);
4547 if (INTEGERP (height
) && window_resize_check (r
, false))
4550 window_resize_apply (r
, false);
4554 pixel_height
= min (-XINT (height
), INT_MAX
- w
->pixel_height
);
4555 line_height
= pixel_height
/ FRAME_LINE_HEIGHT (f
);
4559 line_height
= min (-XINT (height
),
4560 ((INT_MAX
- w
->pixel_height
)
4561 / FRAME_LINE_HEIGHT (f
)));
4562 pixel_height
= line_height
* FRAME_LINE_HEIGHT (f
);
4565 /* Grow the mini-window. */
4566 w
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4567 w
->top_line
= r
->top_line
+ r
->total_lines
;
4568 /* Make sure the mini-window has always at least one line. */
4569 w
->pixel_height
= max (w
->pixel_height
+ pixel_height
,
4570 FRAME_LINE_HEIGHT (f
));
4571 w
->total_lines
= max (w
->total_lines
+ line_height
, 1);
4573 /* Enforce full redisplay of the frame. */
4574 /* FIXME: Shouldn't window--resize-root-window-vertically do it? */
4576 FRAME_WINDOW_SIZES_CHANGED (f
) = true;
4577 adjust_frame_glyphs (f
);
4583 /* Shrink mini-window W to one line. */
4585 shrink_mini_window (struct window
*w
, bool pixelwise
)
4587 struct frame
*f
= XFRAME (w
->frame
);
4589 Lisp_Object root
, delta
;
4590 EMACS_INT height
, unit
;
4592 eassert (MINI_WINDOW_P (w
));
4594 height
= pixelwise
? w
->pixel_height
: w
->total_lines
;
4595 unit
= pixelwise
? FRAME_LINE_HEIGHT (f
) : 1;
4598 root
= FRAME_ROOT_WINDOW (f
);
4600 delta
= call3 (Qwindow_resize_root_window_vertically
,
4601 root
, make_number (height
- unit
),
4602 pixelwise
? Qt
: Qnil
);
4603 if (INTEGERP (delta
) && window_resize_check (r
, false))
4606 window_resize_apply (r
, false);
4608 /* Shrink the mini-window. */
4609 w
->top_line
= r
->top_line
+ r
->total_lines
;
4611 w
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4612 w
->pixel_height
= FRAME_LINE_HEIGHT (f
);
4613 /* Enforce full redisplay of the frame. */
4614 /* FIXME: Shouldn't window--resize-root-window-vertically do it? */
4616 FRAME_WINDOW_SIZES_CHANGED (f
) = true;
4617 adjust_frame_glyphs (f
);
4620 /* If the above failed for whatever strange reason we must make a
4621 one window frame here. The same routine will be needed when
4622 shrinking the frame (and probably when making the initial
4623 *scratch* window). For the moment leave things as they are. */
4627 DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal
, Sresize_mini_window_internal
, 1, 1, 0,
4628 doc
: /* Resize minibuffer window WINDOW. */)
4629 (Lisp_Object window
)
4631 struct window
*w
= XWINDOW (window
);
4636 CHECK_WINDOW (window
);
4637 f
= XFRAME (w
->frame
);
4639 if (!EQ (FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
)), window
))
4640 error ("Not a valid minibuffer window");
4641 else if (FRAME_MINIBUF_ONLY_P (f
))
4642 error ("Cannot resize a minibuffer-only frame");
4644 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4645 height
= r
->pixel_height
+ w
->pixel_height
;
4646 if (window_resize_check (r
, false)
4647 && XINT (w
->new_pixel
) > 0
4648 && height
== XINT (r
->new_pixel
) + XINT (w
->new_pixel
))
4651 window_resize_apply (r
, false);
4653 w
->pixel_height
= XFASTINT (w
->new_pixel
);
4654 w
->total_lines
= w
->pixel_height
/ FRAME_LINE_HEIGHT (f
);
4655 w
->pixel_top
= r
->pixel_top
+ r
->pixel_height
;
4656 w
->top_line
= r
->top_line
+ r
->total_lines
;
4659 FRAME_WINDOW_SIZES_CHANGED (f
) = true;
4660 adjust_frame_glyphs (f
);
4665 error ("Failed to resize minibuffer window");
4668 /* Mark window cursors off for all windows in the window tree rooted
4669 at W by setting their phys_cursor_on_p flag to zero. Called from
4670 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4671 the frame are cleared. */
4674 mark_window_cursors_off (struct window
*w
)
4678 if (WINDOWP (w
->contents
))
4679 mark_window_cursors_off (XWINDOW (w
->contents
));
4681 w
->phys_cursor_on_p
= false;
4683 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4688 /* Return number of lines of text (not counting mode lines) in W. */
4691 window_internal_height (struct window
*w
)
4693 int ht
= w
->total_lines
;
4695 if (!MINI_WINDOW_P (w
))
4697 if (!NILP (w
->parent
)
4698 || WINDOWP (w
->contents
)
4701 || WINDOW_WANTS_MODELINE_P (w
))
4704 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4712 /************************************************************************
4714 ***********************************************************************/
4716 /* Scroll contents of window WINDOW up. If WHOLE, scroll
4717 N screen-fulls, which is defined as the height of the window minus
4718 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4719 instead. Negative values of N mean scroll down. NOERROR
4720 means don't signal an error if we try to move over BEGV or ZV,
4724 window_scroll (Lisp_Object window
, EMACS_INT n
, bool whole
, bool noerror
)
4726 ptrdiff_t count
= SPECPDL_INDEX ();
4728 immediate_quit
= true;
4729 n
= clip_to_bounds (INT_MIN
, n
, INT_MAX
);
4731 wset_redisplay (XWINDOW (window
));
4733 if (whole
&& Vfast_but_imprecise_scrolling
)
4734 specbind (Qfontification_functions
, Qnil
);
4736 /* If we must, use the pixel-based version which is much slower than
4737 the line-based one but can handle varying line heights. */
4738 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4739 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4741 window_scroll_line_based (window
, n
, whole
, noerror
);
4743 unbind_to (count
, Qnil
);
4746 XWINDOW (window
)->window_end_valid
= false;
4747 immediate_quit
= false;
4751 /* Implementation of window_scroll that works based on pixel line
4752 heights. See the comment of window_scroll for parameter
4756 window_scroll_pixel_based (Lisp_Object window
, int n
, bool whole
, bool noerror
)
4759 struct window
*w
= XWINDOW (window
);
4760 struct text_pos start
;
4761 int this_scroll_margin
;
4762 /* True if we fiddled the window vscroll field without really scrolling. */
4763 bool vscrolled
= false;
4764 int x
, y
, rtop
, rbot
, rowh
, vpos
;
4765 void *itdata
= NULL
;
4766 int window_total_lines
;
4767 int frame_line_height
= default_line_pixel_height (w
);
4768 bool adjust_old_pointm
= !NILP (Fequal (Fwindow_point (window
),
4769 Fwindow_old_point (window
)));
4771 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4772 /* Scrolling a minibuffer window via scroll bar when the echo area
4773 shows long text sometimes resets the minibuffer contents behind
4775 if (CHARPOS (start
) > ZV
)
4776 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4778 /* If PT is not visible in WINDOW, move back one half of
4779 the screen. Allow PT to be partially visible, otherwise
4780 something like (scroll-down 1) with PT in the line before
4781 the partially visible one would recenter. */
4783 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
4785 itdata
= bidi_shelve_cache ();
4786 /* Move backward half the height of the window. Performance note:
4787 vmotion used here is about 10% faster, but would give wrong
4788 results for variable height lines. */
4789 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4790 it
.current_y
= it
.last_visible_y
;
4791 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4793 /* The function move_iterator_vertically may move over more than
4794 the specified y-distance. If it->w is small, e.g. a
4795 mini-buffer window, we may end up in front of the window's
4796 display area. Start displaying at the start of the line
4797 containing PT in this case. */
4798 if (it
.current_y
<= 0)
4800 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4801 move_it_vertically_backward (&it
, 0);
4805 start
= it
.current
.pos
;
4806 bidi_unshelve_cache (itdata
, false);
4808 else if (auto_window_vscroll_p
)
4810 if (rtop
|| rbot
) /* Partially visible. */
4813 int dy
= frame_line_height
;
4814 /* In the below we divide the window box height by the
4815 frame's line height to make the result predictable when
4816 the window box is not an integral multiple of the line
4817 height. This is important to ensure we get back to the
4818 same position when scrolling up, then down. */
4820 dy
= max ((window_box_height (w
) / dy
4821 - next_screen_context_lines
) * dy
,
4827 /* Only vscroll backwards if already vscrolled forwards. */
4828 if (w
->vscroll
< 0 && rtop
> 0)
4830 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
4831 Fset_window_vscroll (window
, make_number (px
), Qt
);
4837 /* Do vscroll if already vscrolled or only display line. */
4838 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
4840 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
4841 Fset_window_vscroll (window
, make_number (px
), Qt
);
4845 /* Maybe modify window start instead of scrolling. */
4846 if (rbot
> 0 || w
->vscroll
< 0)
4850 Fset_window_vscroll (window
, make_number (0), Qt
);
4851 /* If there are other text lines above the current row,
4852 move window start to current row. Else to next row. */
4854 spos
= XINT (Fline_beginning_position (Qnil
));
4856 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
4857 set_marker_restricted (w
->start
, make_number (spos
),
4859 w
->start_at_line_beg
= true;
4860 wset_update_mode_line (w
);
4861 /* Set force_start so that redisplay_window will run the
4862 window-scroll-functions. */
4863 w
->force_start
= true;
4868 /* Cancel previous vscroll. */
4869 Fset_window_vscroll (window
, make_number (0), Qt
);
4872 itdata
= bidi_shelve_cache ();
4873 /* If scroll_preserve_screen_position is non-nil, we try to set
4874 point in the same window line as it is now, so get that line. */
4875 if (!NILP (Vscroll_preserve_screen_position
))
4877 /* We preserve the goal pixel coordinate across consecutive
4878 calls to scroll-up, scroll-down and other commands that
4879 have the `scroll-command' property. This avoids the
4880 possibility of point becoming "stuck" on a tall line when
4881 scrolling by one line. */
4882 if (window_scroll_pixel_based_preserve_y
< 0
4883 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
4884 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
4886 start_display (&it
, w
, start
);
4887 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4888 window_scroll_pixel_based_preserve_y
= it
.current_y
;
4889 window_scroll_pixel_based_preserve_x
= it
.current_x
;
4893 window_scroll_pixel_based_preserve_y
4894 = window_scroll_pixel_based_preserve_x
= -1;
4896 /* Move iterator it from start the specified distance forward or
4897 backward. The result is the new window start. */
4898 start_display (&it
, w
, start
);
4901 ptrdiff_t start_pos
= IT_CHARPOS (it
);
4902 int dy
= frame_line_height
;
4903 /* In the below we divide the window box height by the frame's
4904 line height to make the result predictable when the window
4905 box is not an integral multiple of the line height. This is
4906 important to ensure we get back to the same position when
4907 scrolling up, then down. */
4908 dy
= max ((window_box_height (w
) / dy
- next_screen_context_lines
) * dy
,
4911 /* Note that move_it_vertically always moves the iterator to the
4912 start of a line. So, if the last line doesn't have a newline,
4913 we would end up at the start of the line ending at ZV. */
4916 move_it_vertically_backward (&it
, -dy
);
4917 /* Ensure we actually do move, e.g. in case we are currently
4918 looking at an image that is taller that the window height. */
4919 while (start_pos
== IT_CHARPOS (it
)
4920 && start_pos
> BEGV
)
4921 move_it_by_lines (&it
, -1);
4925 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4926 MOVE_TO_POS
| MOVE_TO_Y
);
4927 /* Ensure we actually do move, e.g. in case we are currently
4928 looking at an image that is taller that the window height. */
4929 while (start_pos
== IT_CHARPOS (it
)
4931 move_it_by_lines (&it
, 1);
4935 move_it_by_lines (&it
, n
);
4937 /* We failed if we find ZV is already on the screen (scrolling up,
4938 means there's nothing past the end), or if we can't start any
4939 earlier (scrolling down, means there's nothing past the top). */
4940 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4941 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4943 if (IT_CHARPOS (it
) == ZV
)
4945 if (it
.current_y
< it
.last_visible_y
4946 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4947 > it
.last_visible_y
))
4949 /* The last line was only partially visible, make it fully
4951 w
->vscroll
= (it
.last_visible_y
4952 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4953 adjust_frame_glyphs (it
.f
);
4957 bidi_unshelve_cache (itdata
, false);
4960 else if (n
< 0) /* could happen with empty buffers */
4961 xsignal0 (Qbeginning_of_buffer
);
4963 xsignal0 (Qend_of_buffer
);
4968 if (w
->vscroll
!= 0)
4969 /* The first line was only partially visible, make it fully
4974 bidi_unshelve_cache (itdata
, false);
4978 xsignal0 (Qbeginning_of_buffer
);
4982 /* If control gets here, then we vscrolled. */
4984 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= true;
4986 /* Don't try to change the window start below. */
4992 ptrdiff_t pos
= IT_CHARPOS (it
);
4995 /* If in the middle of a multi-glyph character move forward to
4996 the next character. */
4997 if (in_display_vector_p (&it
))
5000 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
5003 /* Set the window start, and set up the window for redisplay. */
5004 set_marker_restricted_both (w
->start
, w
->contents
, IT_CHARPOS (it
),
5006 bytepos
= marker_byte_position (w
->start
);
5007 w
->start_at_line_beg
= (pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n');
5008 wset_update_mode_line (w
);
5009 /* Set force_start so that redisplay_window will run the
5010 window-scroll-functions. */
5011 w
->force_start
= true;
5014 /* The rest of this function uses current_y in a nonstandard way,
5015 not including the height of the header line if any. */
5016 it
.current_y
= it
.vpos
= 0;
5018 /* Move PT out of scroll margins.
5019 This code wants current_y to be zero at the window start position
5020 even if there is a header line. */
5022 = w
->total_lines
* WINDOW_FRAME_LINE_HEIGHT (w
) / frame_line_height
;
5023 this_scroll_margin
= max (0, scroll_margin
);
5025 = min (this_scroll_margin
, window_total_lines
/ 4);
5026 this_scroll_margin
*= frame_line_height
;
5030 /* We moved the window start towards ZV, so PT may be now
5031 in the scroll margin at the top. */
5032 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5033 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
5034 && (NILP (Vscroll_preserve_screen_position
)
5035 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5036 /* We found PT at a legitimate height. Leave it alone. */
5038 else if (window_scroll_pixel_based_preserve_y
>= 0)
5040 /* If we have a header line, take account of it.
5041 This is necessary because we set it.current_y to 0, above. */
5042 move_it_to (&it
, -1,
5043 window_scroll_pixel_based_preserve_x
,
5044 (window_scroll_pixel_based_preserve_y
5045 - WINDOW_WANTS_HEADER_LINE_P (w
)),
5046 -1, MOVE_TO_Y
| MOVE_TO_X
);
5047 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5051 while (it
.current_y
< this_scroll_margin
)
5053 int prev
= it
.current_y
;
5054 move_it_by_lines (&it
, 1);
5055 if (prev
== it
.current_y
)
5058 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5063 ptrdiff_t charpos
, bytepos
;
5066 /* Save our position, for the
5067 window_scroll_pixel_based_preserve_y case. */
5068 charpos
= IT_CHARPOS (it
);
5069 bytepos
= IT_BYTEPOS (it
);
5071 /* We moved the window start towards BEGV, so PT may be now
5072 in the scroll margin at the bottom. */
5073 move_it_to (&it
, PT
, -1,
5074 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
5075 - this_scroll_margin
- 1),
5077 MOVE_TO_POS
| MOVE_TO_Y
);
5079 /* Save our position, in case it's correct. */
5080 charpos
= IT_CHARPOS (it
);
5081 bytepos
= IT_BYTEPOS (it
);
5083 /* If PT is in the screen line at the last fully visible line,
5084 move_it_to will stop at X = 0 in that line, because the
5085 required Y coordinate is reached there. See if we can get to
5086 PT without descending lower in Y, and if we can, it means we
5087 reached PT before the scroll margin. */
5094 it_data
= bidi_shelve_cache ();
5095 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5096 if (IT_CHARPOS (it
) == PT
&& it
.current_y
== it2
.current_y
)
5098 charpos
= IT_CHARPOS (it
);
5099 bytepos
= IT_BYTEPOS (it
);
5100 bidi_unshelve_cache (it_data
, true);
5105 bidi_unshelve_cache (it_data
, false);
5109 /* See if point is on a partially visible line at the end. */
5110 if (it
.what
== IT_EOB
)
5111 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
5114 move_it_by_lines (&it
, 1);
5115 partial_p
= it
.current_y
> it
.last_visible_y
;
5118 if (charpos
== PT
&& !partial_p
5119 && (NILP (Vscroll_preserve_screen_position
)
5120 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5121 /* We found PT before we found the display margin, so PT is ok. */
5123 else if (window_scroll_pixel_based_preserve_y
>= 0)
5125 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5126 start_display (&it
, w
, start
);
5127 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
5128 here because we called start_display again and did not
5129 alter it.current_y this time. */
5130 move_it_to (&it
, -1, window_scroll_pixel_based_preserve_x
,
5131 window_scroll_pixel_based_preserve_y
, -1,
5132 MOVE_TO_Y
| MOVE_TO_X
);
5133 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5138 /* The last line was only partially visible, so back up two
5139 lines to make sure we're on a fully visible line. */
5141 move_it_by_lines (&it
, -2);
5142 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5145 /* No, the position we saved is OK, so use it. */
5146 SET_PT_BOTH (charpos
, bytepos
);
5149 bidi_unshelve_cache (itdata
, false);
5151 if (adjust_old_pointm
)
5152 Fset_marker (w
->old_pointm
,
5153 ((w
== XWINDOW (selected_window
))
5154 ? make_number (BUF_PT (XBUFFER (w
->contents
)))
5155 : Fmarker_position (w
->pointm
)),
5160 /* Implementation of window_scroll that works based on screen lines.
5161 See the comment of window_scroll for parameter descriptions. */
5164 window_scroll_line_based (Lisp_Object window
, int n
, bool whole
, bool noerror
)
5166 struct window
*w
= XWINDOW (window
);
5167 /* Fvertical_motion enters redisplay, which can trigger
5168 fontification, which in turn can modify buffer text (e.g., if the
5169 fontification functions replace escape sequences with faces, as
5170 in `grep-mode-font-lock-keywords'). So we use a marker to record
5171 the old point position, to prevent crashes in SET_PT_BOTH. */
5172 Lisp_Object opoint_marker
= Fpoint_marker ();
5173 register ptrdiff_t pos
, pos_byte
;
5174 register int ht
= window_internal_height (w
);
5175 register Lisp_Object tem
;
5178 ptrdiff_t startpos
= marker_position (w
->start
);
5179 ptrdiff_t startbyte
= marker_byte_position (w
->start
);
5180 Lisp_Object original_pos
= Qnil
;
5181 bool adjust_old_pointm
= !NILP (Fequal (Fwindow_point (window
),
5182 Fwindow_old_point (window
)));
5184 /* If scrolling screen-fulls, compute the number of lines to
5185 scroll from the window's height. */
5187 n
*= max (1, ht
- next_screen_context_lines
);
5189 if (!NILP (Vscroll_preserve_screen_position
))
5191 if (window_scroll_preserve_vpos
<= 0
5192 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
5193 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
5195 struct position posit
5196 = *compute_motion (startpos
, startbyte
, 0, 0, false,
5197 PT
, ht
, 0, -1, w
->hscroll
, 0, w
);
5199 window_scroll_preserve_vpos
= posit
.vpos
;
5200 window_scroll_preserve_hpos
= posit
.hpos
+ w
->hscroll
;
5203 original_pos
= Fcons (make_number (window_scroll_preserve_hpos
),
5204 make_number (window_scroll_preserve_vpos
));
5207 XSETFASTINT (tem
, PT
);
5208 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
, Qnil
);
5212 Fvertical_motion (make_number (- (ht
/ 2)), window
, Qnil
);
5214 startbyte
= PT_BYTE
;
5217 SET_PT_BOTH (startpos
, startbyte
);
5218 lose
= n
< 0 && PT
== BEGV
;
5219 Fvertical_motion (make_number (n
), window
, Qnil
);
5223 SET_PT_BOTH (marker_position (opoint_marker
),
5224 marker_byte_position (opoint_marker
));
5231 xsignal0 (Qbeginning_of_buffer
);
5236 /* Don't use a scroll margin that is negative or too large. */
5237 int this_scroll_margin
=
5238 max (0, min (scroll_margin
, w
->total_lines
/ 4));
5240 set_marker_restricted_both (w
->start
, w
->contents
, pos
, pos_byte
);
5241 w
->start_at_line_beg
= !NILP (bolp
);
5242 wset_update_mode_line (w
);
5243 /* Set force_start so that redisplay_window will run
5244 the window-scroll-functions. */
5245 w
->force_start
= true;
5247 if (!NILP (Vscroll_preserve_screen_position
)
5248 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
5250 SET_PT_BOTH (pos
, pos_byte
);
5251 Fvertical_motion (original_pos
, window
, Qnil
);
5253 /* If we scrolled forward, put point enough lines down
5254 that it is outside the scroll margin. */
5259 if (this_scroll_margin
> 0)
5261 SET_PT_BOTH (pos
, pos_byte
);
5262 Fvertical_motion (make_number (this_scroll_margin
), window
, Qnil
);
5268 if (top_margin
<= marker_position (opoint_marker
))
5269 SET_PT_BOTH (marker_position (opoint_marker
),
5270 marker_byte_position (opoint_marker
));
5271 else if (!NILP (Vscroll_preserve_screen_position
))
5273 SET_PT_BOTH (pos
, pos_byte
);
5274 Fvertical_motion (original_pos
, window
, Qnil
);
5277 SET_PT (top_margin
);
5283 /* If we scrolled backward, put point near the end of the window
5284 but not within the scroll margin. */
5285 SET_PT_BOTH (pos
, pos_byte
);
5286 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
,
5288 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
5291 bottom_margin
= PT
+ 1;
5293 if (bottom_margin
> marker_position (opoint_marker
))
5294 SET_PT_BOTH (marker_position (opoint_marker
),
5295 marker_byte_position (opoint_marker
));
5298 if (!NILP (Vscroll_preserve_screen_position
))
5300 SET_PT_BOTH (pos
, pos_byte
);
5301 Fvertical_motion (original_pos
, window
, Qnil
);
5304 Fvertical_motion (make_number (-1), window
, Qnil
);
5313 xsignal0 (Qend_of_buffer
);
5316 if (adjust_old_pointm
)
5317 Fset_marker (w
->old_pointm
,
5318 ((w
== XWINDOW (selected_window
))
5319 ? make_number (BUF_PT (XBUFFER (w
->contents
)))
5320 : Fmarker_position (w
->pointm
)),
5325 /* Scroll selected_window up or down. If N is nil, scroll a
5326 screen-full which is defined as the height of the window minus
5327 next_screen_context_lines. If N is the symbol `-', scroll.
5328 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
5329 up. This is the guts of Fscroll_up and Fscroll_down. */
5332 scroll_command (Lisp_Object n
, int direction
)
5334 ptrdiff_t count
= SPECPDL_INDEX ();
5336 eassert (eabs (direction
) == 1);
5338 /* If selected window's buffer isn't current, make it current for
5339 the moment. But don't screw up if window_scroll gets an error. */
5340 if (XBUFFER (XWINDOW (selected_window
)->contents
) != current_buffer
)
5342 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5343 Fset_buffer (XWINDOW (selected_window
)->contents
);
5347 window_scroll (selected_window
, direction
, true, false);
5348 else if (EQ (n
, Qminus
))
5349 window_scroll (selected_window
, -direction
, true, false);
5352 n
= Fprefix_numeric_value (n
);
5353 window_scroll (selected_window
, XINT (n
) * direction
, false, false);
5356 unbind_to (count
, Qnil
);
5359 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "^P",
5360 doc
: /* Scroll text of selected window upward ARG lines.
5361 If ARG is omitted or nil, scroll upward by a near full screen.
5362 A near full screen is `next-screen-context-lines' less than a full screen.
5363 Negative ARG means scroll downward.
5364 If ARG is the atom `-', scroll downward by nearly full screen.
5365 When calling from a program, supply as argument a number, nil, or `-'. */)
5368 scroll_command (arg
, 1);
5372 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "^P",
5373 doc
: /* Scroll text of selected window down ARG lines.
5374 If ARG is omitted or nil, scroll down by a near full screen.
5375 A near full screen is `next-screen-context-lines' less than a full screen.
5376 Negative ARG means scroll upward.
5377 If ARG is the atom `-', scroll upward by nearly full screen.
5378 When calling from a program, supply as argument a number, nil, or `-'. */)
5381 scroll_command (arg
, -1);
5385 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
5386 doc
: /* Return the other window for \"other window scroll\" commands.
5387 If `other-window-scroll-buffer' is non-nil, a window
5388 showing that buffer is used.
5389 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5390 specifies the window. This takes precedence over
5391 `other-window-scroll-buffer'. */)
5396 if (MINI_WINDOW_P (XWINDOW (selected_window
))
5397 && !NILP (Vminibuf_scroll_window
))
5398 window
= Vminibuf_scroll_window
;
5399 /* If buffer is specified and live, scroll that buffer. */
5400 else if (!NILP (Vother_window_scroll_buffer
)
5401 && BUFFERP (Vother_window_scroll_buffer
)
5402 && BUFFER_LIVE_P (XBUFFER (Vother_window_scroll_buffer
)))
5404 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
5406 window
= display_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
5410 /* Nothing specified; look for a neighboring window on the same
5412 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
5414 if (EQ (window
, selected_window
))
5415 /* That didn't get us anywhere; look for a window on another
5418 window
= Fnext_window (window
, Qnil
, Qt
);
5419 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
5420 && ! EQ (window
, selected_window
));
5423 CHECK_LIVE_WINDOW (window
);
5425 if (EQ (window
, selected_window
))
5426 error ("There is no other window");
5431 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
5432 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5433 A near full screen is `next-screen-context-lines' less than a full screen.
5434 The next window is the one below the current one; or the one at the top
5435 if the current one is at the bottom. Negative ARG means scroll downward.
5436 If ARG is the atom `-', scroll downward by nearly full screen.
5437 When calling from a program, supply as argument a number, nil, or `-'.
5439 If `other-window-scroll-buffer' is non-nil, scroll the window
5440 showing that buffer, popping the buffer up if necessary.
5441 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5442 specifies the window to scroll. This takes precedence over
5443 `other-window-scroll-buffer'. */)
5448 ptrdiff_t count
= SPECPDL_INDEX ();
5450 window
= Fother_window_for_scrolling ();
5451 w
= XWINDOW (window
);
5453 /* Don't screw up if window_scroll gets an error. */
5454 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5456 Fset_buffer (w
->contents
);
5457 SET_PT_BOTH (marker_position (w
->pointm
), marker_byte_position (w
->pointm
));
5458 SET_PT_BOTH (marker_position (w
->old_pointm
), marker_byte_position (w
->old_pointm
));
5461 window_scroll (window
, 1, true, true);
5462 else if (EQ (arg
, Qminus
))
5463 window_scroll (window
, -1, true, true);
5469 window_scroll (window
, XINT (arg
), false, true);
5472 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5473 set_marker_both (w
->old_pointm
, Qnil
, PT
, PT_BYTE
);
5474 unbind_to (count
, Qnil
);
5479 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "^P\np",
5480 doc
: /* Scroll selected window display ARG columns left.
5481 Default for ARG is window width minus 2.
5482 Value is the total amount of leftward horizontal scrolling in
5483 effect after the change.
5484 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5485 lower bound for automatic scrolling, i.e. automatic scrolling
5486 will not scroll a window to a column less than the value returned
5487 by this function. This happens in an interactive call. */)
5488 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5490 struct window
*w
= XWINDOW (selected_window
);
5491 EMACS_INT requested_arg
= (NILP (arg
)
5492 ? window_body_width (w
, 0) - 2
5493 : XINT (Fprefix_numeric_value (arg
)));
5494 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
+ requested_arg
);
5496 if (!NILP (set_minimum
))
5497 w
->min_hscroll
= w
->hscroll
;
5499 w
->suspend_auto_hscroll
= true;
5504 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "^P\np",
5505 doc
: /* Scroll selected window display ARG columns right.
5506 Default for ARG is window width minus 2.
5507 Value is the total amount of leftward horizontal scrolling in
5508 effect after the change.
5509 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5510 lower bound for automatic scrolling, i.e. automatic scrolling
5511 will not scroll a window to a column less than the value returned
5512 by this function. This happens in an interactive call. */)
5513 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5515 struct window
*w
= XWINDOW (selected_window
);
5516 EMACS_INT requested_arg
= (NILP (arg
)
5517 ? window_body_width (w
, 0) - 2
5518 : XINT (Fprefix_numeric_value (arg
)));
5519 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
- requested_arg
);
5521 if (!NILP (set_minimum
))
5522 w
->min_hscroll
= w
->hscroll
;
5524 w
->suspend_auto_hscroll
= true;
5529 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5530 doc
: /* Return the window which was selected when entering the minibuffer.
5531 Returns nil, if selected window is not a minibuffer window. */)
5534 if (minibuf_level
> 0
5535 && MINI_WINDOW_P (XWINDOW (selected_window
))
5536 && WINDOW_LIVE_P (minibuf_selected_window
))
5537 return minibuf_selected_window
;
5542 /* Value is the number of lines actually displayed in window W,
5543 as opposed to its height. */
5546 displayed_window_lines (struct window
*w
)
5549 struct text_pos start
;
5550 int height
= window_box_height (w
);
5551 struct buffer
*old_buffer
;
5553 void *itdata
= NULL
;
5555 if (XBUFFER (w
->contents
) != current_buffer
)
5557 old_buffer
= current_buffer
;
5558 set_buffer_internal (XBUFFER (w
->contents
));
5563 /* In case W->start is out of the accessible range, do something
5564 reasonable. This happens in Info mode when Info-scroll-down
5565 calls (recenter -1) while W->start is 1. */
5566 CLIP_TEXT_POS_FROM_MARKER (start
, w
->start
);
5568 itdata
= bidi_shelve_cache ();
5569 start_display (&it
, w
, start
);
5570 move_it_vertically (&it
, height
);
5571 bottom_y
= line_bottom_y (&it
);
5572 bidi_unshelve_cache (itdata
, false);
5574 /* rms: On a non-window display,
5575 the value of it.vpos at the bottom of the screen
5576 seems to be 1 larger than window_box_height (w).
5577 This kludge fixes a bug whereby (move-to-window-line -1)
5578 when ZV is on the last screen line
5579 moves to the previous screen line instead of the last one. */
5580 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5583 /* Add in empty lines at the bottom of the window. */
5584 if (bottom_y
< height
)
5586 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5587 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5591 set_buffer_internal (old_buffer
);
5597 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 2, "P\ni",
5598 doc
: /* Center point in selected window and maybe redisplay frame.
5599 With a numeric prefix argument ARG, recenter putting point on screen line ARG
5600 relative to the selected window. If ARG is negative, it counts up from the
5601 bottom of the window. (ARG should be less than the height of the window.)
5603 If ARG is omitted or nil, then recenter with point on the middle line of
5604 the selected window; if the variable `recenter-redisplay' is non-nil,
5605 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5606 is set to `grow-only', this resets the tool-bar's height to the minimum
5607 height needed); if `recenter-redisplay' has the special value `tty',
5608 then only tty frames are redrawn.
5610 Just C-u as prefix means put point in the center of the window
5611 and redisplay normally--don't erase and redraw the frame.
5613 When `recenter' is called from a program, GROUP is non-nil, and WINDOW is
5614 part of a group of windows collectively displaying a buffer (such as with
5615 Follow Mode), perform `recenter''s actions on the group rather than on the
5616 individual WINDOW. This condition holds when `recenter-group-function' is
5617 set to a function, in which case `recenter' calls the function with the
5618 argument ARG, then returns its value, instead of doing its normal
5620 (register Lisp_Object arg
, Lisp_Object group
)
5623 && FUNCTIONP (Vrecenter_group_function
))
5624 return call1 (Vrecenter_group_function
, arg
);
5626 struct window
*w
= XWINDOW (selected_window
);
5627 struct buffer
*buf
= XBUFFER (w
->contents
);
5628 bool center_p
= false;
5629 ptrdiff_t charpos
, bytepos
;
5630 EMACS_INT iarg
IF_LINT (= 0);
5631 int this_scroll_margin
;
5633 if (buf
!= current_buffer
)
5634 error ("`recenter'ing a window that does not display current-buffer.");
5636 /* If redisplay is suppressed due to an error, try again. */
5637 buf
->display_error_modiff
= 0;
5641 if (!NILP (Vrecenter_redisplay
)
5642 && (!EQ (Vrecenter_redisplay
, Qtty
)
5643 || !NILP (Ftty_type (selected_frame
))))
5647 /* Invalidate pixel data calculated for all compositions. */
5648 for (i
= 0; i
< n_compositions
; i
++)
5649 composition_table
[i
]->font
= NULL
;
5650 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
5651 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5653 Fredraw_frame (WINDOW_FRAME (w
));
5654 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5659 else if (CONSP (arg
)) /* Just C-u. */
5663 arg
= Fprefix_numeric_value (arg
);
5668 /* Do this after making BUF current
5669 in case scroll_margin is buffer-local. */
5671 = max (0, min (scroll_margin
, w
->total_lines
/ 4));
5673 /* Don't use redisplay code for initial frames, as the necessary
5674 data structures might not be set up yet then. */
5675 if (!FRAME_INITIAL_P (XFRAME (w
->frame
)))
5681 void *itdata
= bidi_shelve_cache ();
5683 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5684 start_display (&it
, w
, pt
);
5685 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5686 charpos
= IT_CHARPOS (it
);
5687 bytepos
= IT_BYTEPOS (it
);
5688 bidi_unshelve_cache (itdata
, false);
5694 ptrdiff_t nlines
= min (PTRDIFF_MAX
, -iarg
);
5695 int extra_line_spacing
;
5696 int h
= window_box_height (w
);
5697 int ht
= window_internal_height (w
);
5698 void *itdata
= bidi_shelve_cache ();
5700 nlines
= clip_to_bounds (this_scroll_margin
+ 1, nlines
,
5701 ht
- this_scroll_margin
);
5703 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5704 start_display (&it
, w
, pt
);
5706 /* Be sure we have the exact height of the full line containing PT. */
5707 move_it_by_lines (&it
, 0);
5709 /* The amount of pixels we have to move back is the window
5710 height minus what's displayed in the line containing PT,
5711 and the lines below. */
5714 move_it_by_lines (&it
, nlines
);
5716 if (it
.vpos
== nlines
)
5720 /* Last line has no newline. */
5721 h
-= line_bottom_y (&it
);
5725 /* Don't reserve space for extra line spacing of last line. */
5726 extra_line_spacing
= it
.max_extra_line_spacing
;
5728 /* If we can't move down NLINES lines because we hit
5729 the end of the buffer, count in some empty lines. */
5730 if (it
.vpos
< nlines
)
5733 extra_line_spacing
= it
.extra_line_spacing
;
5734 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5738 bidi_unshelve_cache (itdata
, false);
5742 /* Now find the new top line (starting position) of the window. */
5743 start_display (&it
, w
, pt
);
5745 move_it_vertically_backward (&it
, h
);
5747 /* If extra line spacing is present, we may move too far
5748 back. This causes the last line to be only partially
5749 visible (which triggers redisplay to recenter that line
5750 in the middle), so move forward.
5751 But ignore extra line spacing on last line, as it is not
5752 considered to be part of the visible height of the line.
5754 h
+= extra_line_spacing
;
5755 while (-it
.current_y
> h
)
5756 move_it_by_lines (&it
, 1);
5758 charpos
= IT_CHARPOS (it
);
5759 bytepos
= IT_BYTEPOS (it
);
5761 bidi_unshelve_cache (itdata
, false);
5767 ptrdiff_t nlines
= min (PTRDIFF_MAX
, iarg
);
5768 int ht
= window_internal_height (w
);
5769 void *itdata
= bidi_shelve_cache ();
5771 nlines
= clip_to_bounds (this_scroll_margin
, nlines
,
5772 ht
- this_scroll_margin
- 1);
5774 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5775 start_display (&it
, w
, pt
);
5777 /* Move to the beginning of screen line containing PT. */
5778 move_it_by_lines (&it
, 0);
5780 /* Move back to find the point which is ARG screen lines above PT. */
5785 move_it_by_lines (&it
, -nlines
);
5788 charpos
= IT_CHARPOS (it
);
5789 bytepos
= IT_BYTEPOS (it
);
5791 bidi_unshelve_cache (itdata
, false);
5796 struct position pos
;
5797 int ht
= window_internal_height (w
);
5804 /* Don't let it get into the margin at either top or bottom. */
5805 iarg
= clip_to_bounds (this_scroll_margin
, iarg
,
5806 ht
- this_scroll_margin
- 1);
5808 pos
= *vmotion (PT
, PT_BYTE
, - iarg
, w
);
5809 charpos
= pos
.bufpos
;
5810 bytepos
= pos
.bytepos
;
5813 /* Set the new window start. */
5814 set_marker_both (w
->start
, w
->contents
, charpos
, bytepos
);
5815 w
->window_end_valid
= false;
5817 w
->optional_new_start
= true;
5819 w
->start_at_line_beg
= (bytepos
== BEGV_BYTE
5820 || FETCH_BYTE (bytepos
- 1) == '\n');
5828 DEFUN ("window-text-width", Fwindow_text_width
, Swindow_text_width
,
5830 doc
: /* Return the width in columns of the text display area of WINDOW.
5831 WINDOW must be a live window and defaults to the selected one.
5833 The returned width does not include dividers, scrollbars, margins,
5834 fringes, nor any partial-width columns at the right of the text
5837 Optional argument PIXELWISE non-nil, means to return the width in
5839 (Lisp_Object window
, Lisp_Object pixelwise
)
5841 struct window
*w
= decode_live_window (window
);
5843 if (NILP (pixelwise
))
5844 return make_number (window_box_width (w
, TEXT_AREA
)
5845 / FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
)));
5847 return make_number (window_box_width (w
, TEXT_AREA
));
5850 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5852 doc
: /* Return the height in lines of the text display area of WINDOW.
5853 WINDOW must be a live window and defaults to the selected one.
5855 The returned height does not include dividers, the mode line, any header
5856 line, nor any partial-height lines at the bottom of the text area.
5858 Optional argument PIXELWISE non-nil, means to return the height in
5860 (Lisp_Object window
, Lisp_Object pixelwise
)
5862 struct window
*w
= decode_live_window (window
);
5864 if (NILP (pixelwise
))
5865 return make_number (window_box_height (w
)
5866 / FRAME_LINE_HEIGHT (WINDOW_XFRAME (w
)));
5868 return make_number (window_box_height (w
));
5871 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5873 doc
: /* Position point relative to window.
5874 ARG nil means position point at center of window.
5875 Else, ARG specifies vertical position within the window;
5876 zero means top of window, negative means relative to bottom of window.
5878 When GROUP is non-nil, and `move-to-window-line-group-function' is set to a
5879 function, then instead of the above, that function is called with the
5880 single argument ARG, and its result returned.
5882 If GROUP is non-nil, and WINDOW is part of a group of windows collectively
5883 displaying a buffer (such as with Follow Mode), position point relative to
5884 the group of windows as a whole rather than the individual WINDOW. This
5885 condition holds when `move-to-window-line-group-function' is set to a
5886 function, in which case `move-to-window-line' calls the function with the
5887 argument ARG, then returns its result, instead of doing its normal
5889 (Lisp_Object arg
, Lisp_Object group
)
5892 && FUNCTIONP (Vmove_to_window_line_group_function
))
5893 return call1 (Vmove_to_window_line_group_function
, arg
);
5895 struct window
*w
= XWINDOW (selected_window
);
5899 int this_scroll_margin
;
5902 if (!(BUFFERP (w
->contents
) && XBUFFER (w
->contents
) == current_buffer
))
5903 /* This test is needed to make sure PT/PT_BYTE make sense in w->contents
5904 when passed below to set_marker_both. */
5905 error ("move-to-window-line called from unrelated buffer");
5907 window
= selected_window
;
5908 start
= marker_position (w
->start
);
5909 if (start
< BEGV
|| start
> ZV
)
5911 int height
= window_internal_height (w
);
5912 Fvertical_motion (make_number (- (height
/ 2)), window
, Qnil
);
5913 set_marker_both (w
->start
, w
->contents
, PT
, PT_BYTE
);
5914 w
->start_at_line_beg
= !NILP (Fbolp ());
5915 w
->force_start
= true;
5918 Fgoto_char (w
->start
);
5920 lines
= displayed_window_lines (w
);
5923 this_scroll_margin
= max (0, min (scroll_margin
, lines
/ 4));
5927 XSETFASTINT (arg
, lines
/ 2);
5930 EMACS_INT iarg
= XINT (Fprefix_numeric_value (arg
));
5933 iarg
= iarg
+ lines
;
5935 #if false /* This code would prevent move-to-window-line from moving point
5936 to a place inside the scroll margins (which would cause the
5937 next redisplay to scroll). I wrote this code, but then concluded
5938 it is probably better not to install it. However, it is here
5939 inside #if false so as not to lose it. -- rms. */
5941 /* Don't let it get into the margin at either top or bottom. */
5942 iarg
= max (iarg
, this_scroll_margin
);
5943 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
5946 arg
= make_number (iarg
);
5949 /* Skip past a partially visible first line. */
5951 XSETINT (arg
, XINT (arg
) + 1);
5953 return Fvertical_motion (arg
, window
, Qnil
);
5959 /***********************************************************************
5960 Window Configuration
5961 ***********************************************************************/
5963 struct save_window_data
5965 struct vectorlike_header header
;
5966 Lisp_Object selected_frame
;
5967 Lisp_Object current_window
;
5968 Lisp_Object current_buffer
;
5969 Lisp_Object minibuf_scroll_window
;
5970 Lisp_Object minibuf_selected_window
;
5971 Lisp_Object root_window
;
5972 Lisp_Object focus_frame
;
5973 /* A vector, each of whose elements is a struct saved_window
5975 Lisp_Object saved_windows
;
5977 /* All fields above are traced by the GC.
5978 From `frame-cols' down, the fields are ignored by the GC. */
5979 /* We should be able to do without the following two. */
5980 int frame_cols
, frame_lines
;
5981 /* These two should get eventually replaced by their pixel
5983 int frame_menu_bar_lines
, frame_tool_bar_lines
;
5984 int frame_text_width
, frame_text_height
;
5985 /* These are currently unused. We need them as soon as we convert
5987 int frame_menu_bar_height
, frame_tool_bar_height
;
5990 /* This is saved as a Lisp_Vector. */
5993 struct vectorlike_header header
;
5995 Lisp_Object window
, buffer
, start
, pointm
, old_pointm
;
5996 Lisp_Object pixel_left
, pixel_top
, pixel_height
, pixel_width
;
5997 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5998 Lisp_Object normal_cols
, normal_lines
;
5999 Lisp_Object hscroll
, min_hscroll
, hscroll_whole
, suspend_auto_hscroll
;
6000 Lisp_Object parent
, prev
;
6001 Lisp_Object start_at_line_beg
;
6002 Lisp_Object display_table
;
6003 Lisp_Object left_margin_cols
, right_margin_cols
;
6004 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
6005 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
, dedicated
;
6006 Lisp_Object scroll_bar_height
, horizontal_scroll_bar_type
;
6007 Lisp_Object combination_limit
, window_parameters
;
6010 #define SAVED_WINDOW_N(swv,n) \
6011 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
6013 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
6014 doc
: /* Return t if OBJECT is a window-configuration object. */)
6015 (Lisp_Object object
)
6017 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
6020 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
6021 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
6022 (Lisp_Object config
)
6024 register struct save_window_data
*data
;
6025 struct Lisp_Vector
*saved_windows
;
6027 CHECK_WINDOW_CONFIGURATION (config
);
6029 data
= (struct save_window_data
*) XVECTOR (config
);
6030 saved_windows
= XVECTOR (data
->saved_windows
);
6031 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6034 DEFUN ("set-window-configuration", Fset_window_configuration
,
6035 Sset_window_configuration
, 1, 1, 0,
6036 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
6037 CONFIGURATION must be a value previously returned
6038 by `current-window-configuration' (which see).
6039 If CONFIGURATION was made from a frame that is now deleted,
6040 only frame-independent values can be restored. In this case,
6041 the return value is nil. Otherwise the value is t. */)
6042 (Lisp_Object configuration
)
6044 register struct save_window_data
*data
;
6045 struct Lisp_Vector
*saved_windows
;
6046 Lisp_Object new_current_buffer
;
6049 ptrdiff_t old_point
= -1;
6052 CHECK_WINDOW_CONFIGURATION (configuration
);
6054 data
= (struct save_window_data
*) XVECTOR (configuration
);
6055 saved_windows
= XVECTOR (data
->saved_windows
);
6057 new_current_buffer
= data
->current_buffer
;
6058 if (!BUFFER_LIVE_P (XBUFFER (new_current_buffer
)))
6059 new_current_buffer
= Qnil
;
6062 if (XBUFFER (new_current_buffer
) == current_buffer
)
6063 /* The code further down "preserves point" by saving here PT in
6064 old_point and then setting it later back into PT. When the
6065 current-selected-window and the final-selected-window both show
6066 the current buffer, this suffers from the problem that the
6067 current PT is the window-point of the current-selected-window,
6068 while the final PT is the point of the final-selected-window, so
6069 this copy from one PT to the other would end up moving the
6070 window-point of the final-selected-window to the window-point of
6071 the current-selected-window. So we have to be careful which
6072 point of the current-buffer we copy into old_point. */
6073 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
)
6074 && WINDOWP (selected_window
)
6075 && EQ (XWINDOW (selected_window
)->contents
, new_current_buffer
)
6076 && !EQ (selected_window
, data
->current_window
))
6077 old_point
= marker_position (XWINDOW (data
->current_window
)->pointm
);
6081 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
6082 point in new_current_buffer as of the last time this buffer was
6083 used. This can be non-deterministic since it can be changed by
6084 things like jit-lock by mere temporary selection of some random
6085 window that happens to show this buffer.
6086 So if possible we want this arbitrary choice of "which point" to
6087 be the one from the to-be-selected-window so as to prevent this
6088 window's cursor from being copied from another window. */
6089 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
)
6090 /* If current_window = selected_window, its point is in BUF_PT. */
6091 && !EQ (selected_window
, data
->current_window
))
6092 old_point
= marker_position (XWINDOW (data
->current_window
)->pointm
);
6094 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
6097 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6100 /* If f is a dead frame, don't bother rebuilding its window tree.
6101 However, there is other stuff we should still try to do below. */
6102 if (FRAME_LIVE_P (f
))
6105 Lisp_Object dead_windows
= Qnil
;
6106 Lisp_Object tem
, par
, pers
;
6108 struct saved_window
*p
;
6109 struct window
*root_window
;
6110 struct window
**leaf_windows
;
6111 ptrdiff_t i
, k
, n_leaf_windows
;
6113 /* Don't do this within the main loop below: This may call Lisp
6114 code and is thus potentially unsafe while input is blocked. */
6115 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
6117 p
= SAVED_WINDOW_N (saved_windows
, k
);
6119 w
= XWINDOW (window
);
6120 if (BUFFERP (w
->contents
)
6121 && !EQ (w
->contents
, p
->buffer
)
6122 && BUFFER_LIVE_P (XBUFFER (p
->buffer
)))
6123 /* If a window we restore gets another buffer, record the
6124 window's old buffer. */
6125 call1 (Qrecord_window_buffer
, window
);
6128 /* Disallow x_set_window_size, temporarily. */
6129 f
->can_x_set_window_size
= false;
6130 /* The mouse highlighting code could get screwed up
6131 if it runs during this. */
6134 /* "Swap out" point from the selected window's buffer
6135 into the window itself. (Normally the pointm of the selected
6136 window holds garbage.) We do this now, before
6137 restoring the window contents, and prevent it from
6138 being done later on when we select a new window. */
6139 if (! NILP (XWINDOW (selected_window
)->contents
))
6141 w
= XWINDOW (selected_window
);
6142 set_marker_both (w
->pointm
,
6144 BUF_PT (XBUFFER (w
->contents
)),
6145 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6149 FRAME_WINDOW_SIZES_CHANGED (f
) = true;
6151 /* Problem: Freeing all matrices and later allocating them again
6152 is a serious redisplay flickering problem. What we would
6153 really like to do is to free only those matrices not reused
6155 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6156 ptrdiff_t nwindows
= count_windows (root_window
);
6157 SAFE_NALLOCA (leaf_windows
, 1, nwindows
);
6158 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
6161 Mark all windows now on frame as "deleted".
6162 Restoring the new configuration "undeletes" any that are in it.
6164 Save their current buffers in their height fields, since we may
6165 need it later, if a buffer saved in the configuration is now
6167 delete_all_child_windows (FRAME_ROOT_WINDOW (f
));
6169 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
6171 p
= SAVED_WINDOW_N (saved_windows
, k
);
6173 w
= XWINDOW (window
);
6174 wset_next (w
, Qnil
);
6176 if (!NILP (p
->parent
))
6178 (w
, SAVED_WINDOW_N (saved_windows
, XFASTINT (p
->parent
))->window
);
6180 wset_parent (w
, Qnil
);
6182 if (!NILP (p
->prev
))
6185 (w
, SAVED_WINDOW_N (saved_windows
, XFASTINT (p
->prev
))->window
);
6186 wset_next (XWINDOW (w
->prev
), p
->window
);
6190 wset_prev (w
, Qnil
);
6191 if (!NILP (w
->parent
))
6192 wset_combination (XWINDOW (w
->parent
),
6193 (XINT (p
->total_cols
)
6194 != XWINDOW (w
->parent
)->total_cols
),
6198 /* If we squirreled away the buffer, restore it now. */
6199 if (BUFFERP (w
->combination_limit
))
6200 wset_buffer (w
, w
->combination_limit
);
6201 w
->pixel_left
= XFASTINT (p
->pixel_left
);
6202 w
->pixel_top
= XFASTINT (p
->pixel_top
);
6203 w
->pixel_width
= XFASTINT (p
->pixel_width
);
6204 w
->pixel_height
= XFASTINT (p
->pixel_height
);
6205 w
->left_col
= XFASTINT (p
->left_col
);
6206 w
->top_line
= XFASTINT (p
->top_line
);
6207 w
->total_cols
= XFASTINT (p
->total_cols
);
6208 w
->total_lines
= XFASTINT (p
->total_lines
);
6209 wset_normal_cols (w
, p
->normal_cols
);
6210 wset_normal_lines (w
, p
->normal_lines
);
6211 w
->hscroll
= XFASTINT (p
->hscroll
);
6212 w
->suspend_auto_hscroll
= !NILP (p
->suspend_auto_hscroll
);
6213 w
->min_hscroll
= XFASTINT (p
->min_hscroll
);
6214 w
->hscroll_whole
= XFASTINT (p
->hscroll_whole
);
6215 wset_display_table (w
, p
->display_table
);
6216 w
->left_margin_cols
= XINT (p
->left_margin_cols
);
6217 w
->right_margin_cols
= XINT (p
->right_margin_cols
);
6218 w
->left_fringe_width
= XINT (p
->left_fringe_width
);
6219 w
->right_fringe_width
= XINT (p
->right_fringe_width
);
6220 w
->fringes_outside_margins
= !NILP (p
->fringes_outside_margins
);
6221 w
->scroll_bar_width
= XINT (p
->scroll_bar_width
);
6222 w
->scroll_bar_height
= XINT (p
->scroll_bar_height
);
6223 wset_vertical_scroll_bar_type (w
, p
->vertical_scroll_bar_type
);
6224 wset_horizontal_scroll_bar_type (w
, p
->horizontal_scroll_bar_type
);
6225 wset_dedicated (w
, p
->dedicated
);
6226 wset_combination_limit (w
, p
->combination_limit
);
6227 /* Restore any window parameters that have been saved.
6228 Parameters that have not been saved are left alone. */
6229 for (tem
= p
->window_parameters
; CONSP (tem
); tem
= XCDR (tem
))
6234 if (NILP (XCDR (pers
)))
6236 par
= Fassq (XCAR (pers
), w
->window_parameters
);
6237 if (CONSP (par
) && !NILP (XCDR (par
)))
6238 /* Reset a parameter to nil if and only if it
6239 has a non-nil association. Don't make new
6241 Fsetcdr (par
, Qnil
);
6244 /* Always restore a non-nil value. */
6245 Fset_window_parameter (window
, XCAR (pers
), XCDR (pers
));
6249 if (BUFFERP (p
->buffer
) && BUFFER_LIVE_P (XBUFFER (p
->buffer
)))
6250 /* If saved buffer is alive, install it. */
6252 wset_buffer (w
, p
->buffer
);
6253 w
->start_at_line_beg
= !NILP (p
->start_at_line_beg
);
6254 set_marker_restricted (w
->start
, p
->start
, w
->contents
);
6255 set_marker_restricted (w
->pointm
, p
->pointm
, w
->contents
);
6256 set_marker_restricted (w
->old_pointm
, p
->old_pointm
, w
->contents
);
6257 /* As documented in Fcurrent_window_configuration, don't
6258 restore the location of point in the buffer which was
6259 current when the window configuration was recorded. */
6260 if (!EQ (p
->buffer
, new_current_buffer
)
6261 && XBUFFER (p
->buffer
) == current_buffer
)
6262 Fgoto_char (w
->pointm
);
6264 else if (BUFFERP (w
->contents
) && BUFFER_LIVE_P (XBUFFER (w
->contents
)))
6265 /* Keep window's old buffer; make sure the markers are real. */
6267 /* Set window markers at start of visible range. */
6268 if (XMARKER (w
->start
)->buffer
== 0)
6269 set_marker_restricted_both (w
->start
, w
->contents
, 0, 0);
6270 if (XMARKER (w
->pointm
)->buffer
== 0)
6271 set_marker_restricted_both
6272 (w
->pointm
, w
->contents
,
6273 BUF_PT (XBUFFER (w
->contents
)),
6274 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6275 if (XMARKER (w
->old_pointm
)->buffer
== 0)
6276 set_marker_restricted_both
6277 (w
->old_pointm
, w
->contents
,
6278 BUF_PT (XBUFFER (w
->contents
)),
6279 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6280 w
->start_at_line_beg
= true;
6282 else if (!NILP (w
->start
))
6283 /* Leaf window has no live buffer, get one. */
6285 /* Get the buffer via other_buffer_safely in order to
6286 avoid showing an unimportant buffer and, if necessary, to
6287 recreate *scratch* in the course (part of Juanma's bs-show
6288 scenario from March 2011). */
6289 wset_buffer (w
, other_buffer_safely (Fcurrent_buffer ()));
6290 /* This will set the markers to beginning of visible
6292 set_marker_restricted_both (w
->start
, w
->contents
, 0, 0);
6293 set_marker_restricted_both (w
->pointm
, w
->contents
, 0, 0);
6294 set_marker_restricted_both (w
->old_pointm
, w
->contents
, 0, 0);
6295 w
->start_at_line_beg
= true;
6296 if (!NILP (w
->dedicated
))
6297 /* Record this window as dead. */
6298 dead_windows
= Fcons (window
, dead_windows
);
6299 /* Make sure window is no more dedicated. */
6300 wset_dedicated (w
, Qnil
);
6304 fset_root_window (f
, data
->root_window
);
6305 /* Arrange *not* to restore point in the buffer that was
6306 current when the window configuration was saved. */
6307 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
))
6308 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
6309 make_number (old_point
),
6310 XWINDOW (data
->current_window
)->contents
);
6312 /* In the following call to `select-window', prevent "swapping out
6313 point" in the old selected window using the buffer that has
6314 been restored into it. We already swapped out that point from
6315 that window's old buffer.
6317 Do not record the buffer here. We do that in a separate call
6318 to select_window below. See also Bug#16207. */
6319 select_window (data
->current_window
, Qt
, true);
6320 BVAR (XBUFFER (XWINDOW (selected_window
)->contents
),
6321 last_selected_window
)
6324 if (NILP (data
->focus_frame
)
6325 || (FRAMEP (data
->focus_frame
)
6326 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
6327 Fredirect_frame_focus (frame
, data
->focus_frame
);
6329 /* Now, free glyph matrices in windows that were not reused. */
6330 for (i
= 0; i
< n_leaf_windows
; i
++)
6331 if (NILP (leaf_windows
[i
]->contents
))
6332 free_window_matrices (leaf_windows
[i
]);
6334 /* Allow x_set_window_size again and apply frame size changes if
6336 f
->can_x_set_window_size
= true;
6337 adjust_frame_size (f
, -1, -1, 1, false, Qset_window_configuration
);
6339 adjust_frame_glyphs (f
);
6342 /* Scan dead buffer windows. */
6343 for (; CONSP (dead_windows
); dead_windows
= XCDR (dead_windows
))
6345 window
= XCAR (dead_windows
);
6346 if (WINDOW_LIVE_P (window
) && !EQ (window
, FRAME_ROOT_WINDOW (f
)))
6347 delete_deletable_window (window
);
6350 /* Record the selected window's buffer here. The window should
6351 already be the selected one from the call above. */
6352 select_window (data
->current_window
, Qnil
, false);
6354 /* Fselect_window will have made f the selected frame, so we
6355 reselect the proper frame here. Fhandle_switch_frame will change the
6356 selected window too, but that doesn't make the call to
6357 Fselect_window above totally superfluous; it still sets f's
6359 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
6360 do_switch_frame (data
->selected_frame
, 0, 0, Qnil
);
6362 run_window_configuration_change_hook (f
);
6365 if (!NILP (new_current_buffer
))
6367 Fset_buffer (new_current_buffer
);
6368 /* If the new current buffer doesn't appear in the selected
6369 window, go to its old point (see bug#12208). */
6370 if (!EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
))
6371 Fgoto_char (make_number (old_point
));
6374 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
6375 minibuf_selected_window
= data
->minibuf_selected_window
;
6378 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
6383 restore_window_configuration (Lisp_Object configuration
)
6385 Fset_window_configuration (configuration
);
6389 /* If WINDOW is an internal window, recursively delete all child windows
6390 reachable via the next and contents slots of WINDOW. Otherwise setup
6391 WINDOW to not show any buffer. */
6394 delete_all_child_windows (Lisp_Object window
)
6396 register struct window
*w
;
6398 w
= XWINDOW (window
);
6400 if (!NILP (w
->next
))
6401 /* Delete WINDOW's siblings (we traverse postorderly). */
6402 delete_all_child_windows (w
->next
);
6404 if (WINDOWP (w
->contents
))
6406 delete_all_child_windows (w
->contents
);
6407 wset_combination (w
, false, Qnil
);
6409 else if (BUFFERP (w
->contents
))
6412 unchain_marker (XMARKER (w
->pointm
));
6413 unchain_marker (XMARKER (w
->old_pointm
));
6414 unchain_marker (XMARKER (w
->start
));
6415 /* Since combination limit makes sense for an internal windows
6416 only, we use this slot to save the buffer for the sake of
6417 possible resurrection in Fset_window_configuration. */
6418 wset_combination_limit (w
, w
->contents
);
6419 wset_buffer (w
, Qnil
);
6422 Vwindow_list
= Qnil
;
6426 count_windows (struct window
*window
)
6428 ptrdiff_t count
= 1;
6429 if (!NILP (window
->next
))
6430 count
+= count_windows (XWINDOW (window
->next
));
6431 if (WINDOWP (window
->contents
))
6432 count
+= count_windows (XWINDOW (window
->contents
));
6437 /* Fill vector FLAT with leaf windows under W, starting at index I.
6438 Value is last index + 1. */
6440 get_leaf_windows (struct window
*w
, struct window
**flat
, ptrdiff_t i
)
6444 if (WINDOWP (w
->contents
))
6445 i
= get_leaf_windows (XWINDOW (w
->contents
), flat
, i
);
6449 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6456 /* Return a pointer to the glyph W's physical cursor is on. Value is
6457 null if W's current matrix is invalid, so that no meaningful glyph
6460 get_phys_cursor_glyph (struct window
*w
)
6462 struct glyph_row
*row
;
6463 struct glyph
*glyph
;
6464 int hpos
= w
->phys_cursor
.hpos
;
6466 if (!(w
->phys_cursor
.vpos
>= 0
6467 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
))
6470 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
6471 if (!row
->enabled_p
)
6476 /* When the window is hscrolled, cursor hpos can legitimately be
6477 out of bounds, but we draw the cursor at the corresponding
6478 window margin in that case. */
6479 if (!row
->reversed_p
&& hpos
< 0)
6481 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
6482 hpos
= row
->used
[TEXT_AREA
] - 1;
6485 if (0 <= hpos
&& hpos
< row
->used
[TEXT_AREA
])
6486 glyph
= row
->glyphs
[TEXT_AREA
] + hpos
;
6495 save_window_save (Lisp_Object window
, struct Lisp_Vector
*vector
, ptrdiff_t i
)
6497 struct saved_window
*p
;
6499 Lisp_Object tem
, pers
, par
;
6501 for (; !NILP (window
); window
= w
->next
)
6503 p
= SAVED_WINDOW_N (vector
, i
);
6504 w
= XWINDOW (window
);
6506 wset_temslot (w
, make_number (i
)); i
++;
6508 p
->buffer
= (WINDOW_LEAF_P (w
) ? w
->contents
: Qnil
);
6509 p
->pixel_left
= make_number (w
->pixel_left
);
6510 p
->pixel_top
= make_number (w
->pixel_top
);
6511 p
->pixel_width
= make_number (w
->pixel_width
);
6512 p
->pixel_height
= make_number (w
->pixel_height
);
6513 p
->left_col
= make_number (w
->left_col
);
6514 p
->top_line
= make_number (w
->top_line
);
6515 p
->total_cols
= make_number (w
->total_cols
);
6516 p
->total_lines
= make_number (w
->total_lines
);
6517 p
->normal_cols
= w
->normal_cols
;
6518 p
->normal_lines
= w
->normal_lines
;
6519 XSETFASTINT (p
->hscroll
, w
->hscroll
);
6520 p
->suspend_auto_hscroll
= w
->suspend_auto_hscroll
? Qt
: Qnil
;
6521 XSETFASTINT (p
->min_hscroll
, w
->min_hscroll
);
6522 XSETFASTINT (p
->hscroll_whole
, w
->hscroll_whole
);
6523 p
->display_table
= w
->display_table
;
6524 p
->left_margin_cols
= make_number (w
->left_margin_cols
);
6525 p
->right_margin_cols
= make_number (w
->right_margin_cols
);
6526 p
->left_fringe_width
= make_number (w
->left_fringe_width
);
6527 p
->right_fringe_width
= make_number (w
->right_fringe_width
);
6528 p
->fringes_outside_margins
= w
->fringes_outside_margins
? Qt
: Qnil
;
6529 p
->scroll_bar_width
= make_number (w
->scroll_bar_width
);
6530 p
->scroll_bar_height
= make_number (w
->scroll_bar_height
);
6531 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
6532 p
->horizontal_scroll_bar_type
= w
->horizontal_scroll_bar_type
;
6533 p
->dedicated
= w
->dedicated
;
6534 p
->combination_limit
= w
->combination_limit
;
6535 p
->window_parameters
= Qnil
;
6537 if (!NILP (Vwindow_persistent_parameters
))
6539 /* Run cycle detection on Vwindow_persistent_parameters. */
6540 Lisp_Object tortoise
, hare
;
6542 hare
= tortoise
= Vwindow_persistent_parameters
;
6543 while (CONSP (hare
))
6550 tortoise
= XCDR (tortoise
);
6552 if (EQ (hare
, tortoise
))
6553 /* Reset Vwindow_persistent_parameters to Qnil. */
6555 Vwindow_persistent_parameters
= Qnil
;
6560 for (tem
= Vwindow_persistent_parameters
; CONSP (tem
);
6564 /* Save values for persistent window parameters. */
6565 if (CONSP (pers
) && !NILP (XCDR (pers
)))
6567 par
= Fassq (XCAR (pers
), w
->window_parameters
);
6569 /* If the window has no value for the parameter,
6571 p
->window_parameters
= Fcons (Fcons (XCAR (pers
), Qnil
),
6572 p
->window_parameters
);
6574 /* If the window has a value for the parameter,
6576 p
->window_parameters
= Fcons (Fcons (XCAR (par
),
6578 p
->window_parameters
);
6583 if (BUFFERP (w
->contents
))
6585 /* Save w's value of point in the window configuration. If w
6586 is the selected window, then get the value of point from
6587 the buffer; pointm is garbage in the selected window. */
6588 if (EQ (window
, selected_window
))
6589 p
->pointm
= build_marker (XBUFFER (w
->contents
),
6590 BUF_PT (XBUFFER (w
->contents
)),
6591 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6593 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
6594 p
->old_pointm
= Fcopy_marker (w
->old_pointm
, Qnil
);
6595 XMARKER (p
->pointm
)->insertion_type
6596 = !NILP (buffer_local_value
/* Don't signal error if void. */
6597 (Qwindow_point_insertion_type
, w
->contents
));
6598 XMARKER (p
->old_pointm
)->insertion_type
6599 = !NILP (buffer_local_value
/* Don't signal error if void. */
6600 (Qwindow_point_insertion_type
, w
->contents
));
6602 p
->start
= Fcopy_marker (w
->start
, Qnil
);
6603 p
->start_at_line_beg
= w
->start_at_line_beg
? Qt
: Qnil
;
6608 p
->old_pointm
= Qnil
;
6610 p
->start_at_line_beg
= Qnil
;
6613 p
->parent
= NILP (w
->parent
) ? Qnil
: XWINDOW (w
->parent
)->temslot
;
6614 p
->prev
= NILP (w
->prev
) ? Qnil
: XWINDOW (w
->prev
)->temslot
;
6616 if (WINDOWP (w
->contents
))
6617 i
= save_window_save (w
->contents
, vector
, i
);
6623 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
6624 Scurrent_window_configuration
, 0, 1, 0,
6625 doc
: /* Return an object representing the current window configuration of FRAME.
6626 If FRAME is nil or omitted, use the selected frame.
6627 This describes the number of windows, their sizes and current buffers,
6628 and for each displayed buffer, where display starts, and the position of
6629 point. An exception is made for point in the current buffer:
6630 its value is -not- saved.
6631 This also records the currently selected frame, and FRAME's focus
6632 redirection (see `redirect-frame-focus'). The variable
6633 `window-persistent-parameters' specifies which window parameters are
6634 saved by this function. */)
6638 ptrdiff_t i
, n_windows
;
6639 struct save_window_data
*data
;
6640 struct frame
*f
= decode_live_frame (frame
);
6642 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6643 data
= ALLOCATE_PSEUDOVECTOR (struct save_window_data
, frame_cols
,
6644 PVEC_WINDOW_CONFIGURATION
);
6646 data
->frame_cols
= FRAME_COLS (f
);
6647 data
->frame_lines
= FRAME_LINES (f
);
6648 data
->frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6649 data
->frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6650 data
->frame_text_width
= FRAME_TEXT_WIDTH (f
);
6651 data
->frame_text_height
= FRAME_TEXT_HEIGHT (f
);
6652 data
->frame_menu_bar_height
= FRAME_MENU_BAR_HEIGHT (f
);
6653 data
->frame_tool_bar_height
= FRAME_TOOL_BAR_HEIGHT (f
);
6654 data
->selected_frame
= selected_frame
;
6655 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6656 XSETBUFFER (data
->current_buffer
, current_buffer
);
6657 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6658 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6659 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6660 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6661 tem
= make_uninit_vector (n_windows
);
6662 data
->saved_windows
= tem
;
6663 for (i
= 0; i
< n_windows
; i
++)
6665 Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
));
6666 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6667 XSETWINDOW_CONFIGURATION (tem
, data
);
6671 /* Called after W's margins, fringes or scroll bars was adjusted. */
6674 apply_window_adjustment (struct window
*w
)
6677 clear_glyph_matrix (w
->current_matrix
);
6678 w
->window_end_valid
= false;
6680 adjust_frame_glyphs (XFRAME (WINDOW_FRAME (w
)));
6684 /***********************************************************************
6686 ***********************************************************************/
6689 extract_dimension (Lisp_Object dimension
)
6691 if (NILP (dimension
))
6693 CHECK_RANGED_INTEGER (dimension
, 0, INT_MAX
);
6694 return XINT (dimension
);
6697 static struct window
*
6698 set_window_margins (struct window
*w
, Lisp_Object left_width
,
6699 Lisp_Object right_width
)
6701 int unit
= WINDOW_FRAME_COLUMN_WIDTH (w
);
6702 int left
= NILP (left_width
) ? 0 : extract_dimension (left_width
);
6703 int right
= NILP (right_width
) ? 0 : extract_dimension (right_width
);
6705 if (w
->left_margin_cols
!= left
|| w
->right_margin_cols
!= right
)
6707 /* Don't change anything if new margins won't fit. */
6708 if ((WINDOW_PIXEL_WIDTH (w
)
6709 - WINDOW_FRINGES_WIDTH (w
)
6710 - WINDOW_SCROLL_BAR_AREA_WIDTH (w
)
6711 - (left
+ right
) * unit
)
6712 >= MIN_SAFE_WINDOW_PIXEL_WIDTH (w
))
6714 w
->left_margin_cols
= left
;
6715 w
->right_margin_cols
= right
;
6726 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6728 doc
: /* Set width of marginal areas of window WINDOW.
6729 WINDOW must be a live window and defaults to the selected one.
6731 Second arg LEFT-WIDTH specifies the number of character cells to
6732 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6733 does the same for the right marginal area. A nil width parameter
6736 Return t if any margin was actually changed and nil otherwise. */)
6737 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
)
6739 struct window
*w
= set_window_margins (decode_live_window (window
),
6740 left_width
, right_width
);
6741 return w
? (apply_window_adjustment (w
), Qt
) : Qnil
;
6745 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6747 doc
: /* Get width of marginal areas of window WINDOW.
6748 WINDOW must be a live window and defaults to the selected one.
6750 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6751 If a marginal area does not exist, its width will be returned
6753 (Lisp_Object window
)
6755 struct window
*w
= decode_live_window (window
);
6756 return Fcons (w
->left_margin_cols
6757 ? make_number (w
->left_margin_cols
) : Qnil
,
6758 w
->right_margin_cols
6759 ? make_number (w
->right_margin_cols
) : Qnil
);
6764 /***********************************************************************
6766 ***********************************************************************/
6768 static struct window
*
6769 set_window_fringes (struct window
*w
, Lisp_Object left_width
,
6770 Lisp_Object right_width
, Lisp_Object outside_margins
)
6772 bool outside
= !NILP (outside_margins
);
6773 int left
= extract_dimension (left_width
);
6774 int right
= extract_dimension (right_width
);
6776 /* Do nothing on a tty or if nothing to actually change. */
6777 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6778 && (w
->left_fringe_width
!= left
6779 || w
->right_fringe_width
!= right
6780 || w
->fringes_outside_margins
!= outside
))
6782 if (left
> 0 || right
> 0)
6784 /* Don't change anything if new fringes don't fit. */
6785 if ((WINDOW_PIXEL_WIDTH (w
)
6786 - WINDOW_MARGINS_WIDTH (w
)
6787 - WINDOW_SCROLL_BAR_AREA_WIDTH (w
)
6788 - max (left
, 0) - max (right
, 0))
6789 < MIN_SAFE_WINDOW_PIXEL_WIDTH (w
))
6793 w
->left_fringe_width
= left
;
6794 w
->right_fringe_width
= right
;
6795 w
->fringes_outside_margins
= outside
;
6803 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6805 doc
: /* Set the fringe widths of window WINDOW.
6806 WINDOW must be a live window and defaults to the selected one.
6808 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6809 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6810 fringe width. If a fringe width arg is nil, that means to use the
6811 frame's default fringe width. Default fringe widths can be set with
6812 the command `set-fringe-style'.
6813 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6814 outside of the display margins. By default, fringes are drawn between
6815 display marginal areas and the text area.
6817 Return t if any fringe was actually changed and nil otherwise. */)
6818 (Lisp_Object window
, Lisp_Object left_width
,
6819 Lisp_Object right_width
, Lisp_Object outside_margins
)
6822 = set_window_fringes (decode_live_window (window
),
6823 left_width
, right_width
, outside_margins
);
6824 return w
? (apply_window_adjustment (w
), Qt
) : Qnil
;
6828 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6830 doc
: /* Get width of fringes of window WINDOW.
6831 WINDOW must be a live window and defaults to the selected one.
6833 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6834 (Lisp_Object window
)
6836 struct window
*w
= decode_live_window (window
);
6838 return list3 (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6839 make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6840 WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
) ? Qt
: Qnil
);
6845 /***********************************************************************
6847 ***********************************************************************/
6849 static struct window
*
6850 set_window_scroll_bars (struct window
*w
, Lisp_Object width
,
6851 Lisp_Object vertical_type
, Lisp_Object height
,
6852 Lisp_Object horizontal_type
)
6854 int iwidth
= extract_dimension (width
);
6855 bool changed
= false;
6858 vertical_type
= Qnil
;
6860 if (!(NILP (vertical_type
)
6861 || EQ (vertical_type
, Qleft
)
6862 || EQ (vertical_type
, Qright
)
6863 || EQ (vertical_type
, Qt
)))
6864 error ("Invalid type of vertical scroll bar");
6866 if (w
->scroll_bar_width
!= iwidth
6867 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6869 /* Don't change anything if new scroll bar won't fit. */
6870 if ((WINDOW_PIXEL_WIDTH (w
)
6871 - WINDOW_MARGINS_WIDTH (w
)
6872 - WINDOW_FRINGES_WIDTH (w
)
6874 >= MIN_SAFE_WINDOW_PIXEL_WIDTH (w
))
6876 w
->scroll_bar_width
= iwidth
;
6877 wset_vertical_scroll_bar_type (w
, vertical_type
);
6882 #if USE_HORIZONTAL_SCROLL_BARS
6884 int iheight
= extract_dimension (height
);
6886 if (MINI_WINDOW_P (w
) || iheight
== 0)
6887 horizontal_type
= Qnil
;
6889 if (!(NILP (horizontal_type
)
6890 || EQ (horizontal_type
, Qbottom
)
6891 || EQ (horizontal_type
, Qt
)))
6892 error ("Invalid type of horizontal scroll bar");
6894 if (w
->scroll_bar_height
!= iheight
6895 || !EQ (w
->horizontal_scroll_bar_type
, horizontal_type
))
6897 /* Don't change anything if new scroll bar won't fit. */
6898 if ((WINDOW_PIXEL_HEIGHT (w
)
6899 - WINDOW_HEADER_LINE_HEIGHT (w
)
6900 - WINDOW_MODE_LINE_HEIGHT (w
)
6902 >= MIN_SAFE_WINDOW_PIXEL_HEIGHT (w
))
6904 w
->scroll_bar_height
= iheight
;
6905 wset_horizontal_scroll_bar_type (w
, horizontal_type
);
6911 wset_horizontal_scroll_bar_type (w
, Qnil
);
6914 return changed
? w
: NULL
;
6917 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
,
6918 Sset_window_scroll_bars
, 1, 5, 0,
6919 doc
: /* Set width and type of scroll bars of window WINDOW.
6920 WINDOW must be a live window and defaults to the selected one.
6922 Second parameter WIDTH specifies the pixel width for the vertical scroll
6923 bar. If WIDTH is nil, use the scroll-bar width of WINDOW's frame.
6924 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6925 bar: left, right, or nil. If VERTICAL-TYPE is t, this means use the
6926 frame's scroll-bar type.
6928 Fourth parameter HEIGHT specifies the pixel height for the horizontal
6929 scroll bar. If HEIGHT is nil, use the scroll-bar height of WINDOW's
6930 frame. Fifth parameter HORIZONTAL-TYPE specifies the type of the
6931 horizontal scroll bar: nil, bottom, or t. If HORIZONTAL-TYPE is t, this
6932 means to use the frame's horizontal scroll-bar type.
6934 Return t if scroll bars were actually changed and nil otherwise. */)
6935 (Lisp_Object window
, Lisp_Object width
, Lisp_Object vertical_type
,
6936 Lisp_Object height
, Lisp_Object horizontal_type
)
6939 = set_window_scroll_bars (decode_live_window (window
),
6940 width
, vertical_type
, height
, horizontal_type
);
6941 return w
? (apply_window_adjustment (w
), Qt
) : Qnil
;
6945 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6947 doc
: /* Get width and type of scroll bars of window WINDOW.
6948 WINDOW must be a live window and defaults to the selected one.
6950 Value is a list of the form (WIDTH COLUMNS VERTICAL-TYPE HEIGHT LINES
6951 HORIZONTAL-TYPE). If WIDTH or HEIGHT is nil or VERTICAL-TYPE or
6952 HORIZONTAL-TYPE is t, the window is using the frame's corresponding
6954 (Lisp_Object window
)
6956 struct window
*w
= decode_live_window (window
);
6958 return Fcons (((w
->scroll_bar_width
>= 0)
6959 ? make_number (w
->scroll_bar_width
)
6961 list5 (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6962 w
->vertical_scroll_bar_type
,
6963 ((w
->scroll_bar_height
>= 0)
6964 ? make_number (w
->scroll_bar_height
)
6966 make_number (WINDOW_SCROLL_BAR_LINES (w
)),
6967 w
->horizontal_scroll_bar_type
));
6970 /***********************************************************************
6972 ***********************************************************************/
6974 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6975 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6976 If WINDOW is omitted or nil, it defaults to the selected window.
6977 Normally, value is a multiple of the canonical character height of WINDOW;
6978 optional second arg PIXELS-P means value is measured in pixels. */)
6979 (Lisp_Object window
, Lisp_Object pixels_p
)
6982 struct window
*w
= decode_live_window (window
);
6983 struct frame
*f
= XFRAME (w
->frame
);
6985 if (FRAME_WINDOW_P (f
))
6986 result
= (NILP (pixels_p
)
6987 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6988 : make_number (-w
->vscroll
));
6990 result
= make_number (0);
6995 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6997 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6998 WINDOW nil means use the selected window. Normally, VSCROLL is a
6999 non-negative multiple of the canonical character height of WINDOW;
7000 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
7001 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
7002 corresponds to an integral number of pixels. The return value is the
7003 result of this rounding.
7004 If PIXELS-P is non-nil, the return value is VSCROLL. */)
7005 (Lisp_Object window
, Lisp_Object vscroll
, Lisp_Object pixels_p
)
7007 struct window
*w
= decode_live_window (window
);
7008 struct frame
*f
= XFRAME (w
->frame
);
7010 CHECK_NUMBER_OR_FLOAT (vscroll
);
7012 if (FRAME_WINDOW_P (f
))
7014 int old_dy
= w
->vscroll
;
7016 w
->vscroll
= - (NILP (pixels_p
)
7017 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
7018 : XFLOATINT (vscroll
));
7019 w
->vscroll
= min (w
->vscroll
, 0);
7021 if (w
->vscroll
!= old_dy
)
7023 /* Adjust glyph matrix of the frame if the virtual display
7024 area becomes larger than before. */
7025 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
7026 adjust_frame_glyphs (f
);
7028 /* Prevent redisplay shortcuts. */
7029 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= true;
7033 return Fwindow_vscroll (window
, pixels_p
);
7037 /* Call FN for all leaf windows on frame F. FN is called with the
7038 first argument being a pointer to the leaf window, and with
7039 additional argument USER_DATA. Stops when FN returns 0. */
7042 foreach_window (struct frame
*f
, bool (*fn
) (struct window
*, void *),
7045 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
7046 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
7047 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
7051 /* Helper function for foreach_window. Call FN for all leaf windows
7052 reachable from W. FN is called with the first argument being a
7053 pointer to the leaf window, and with additional argument USER_DATA.
7054 Stop when FN returns false. Value is false if stopped by FN. */
7057 foreach_window_1 (struct window
*w
, bool (*fn
) (struct window
*, void *),
7062 for (cont
= true; w
&& cont
;)
7064 if (WINDOWP (w
->contents
))
7065 cont
= foreach_window_1 (XWINDOW (w
->contents
), fn
, user_data
);
7067 cont
= fn (w
, user_data
);
7069 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
7075 /***********************************************************************
7077 ***********************************************************************/
7079 /* Return true if window configurations CONFIGURATION1 and CONFIGURATION2
7080 describe the same state of affairs. This is used by Fequal.
7082 IGNORE_POSITIONS means ignore non-matching scroll positions
7085 This ignores a couple of things like the dedication status of
7086 window, combination_limit and the like. This might have to be
7090 compare_window_configurations (Lisp_Object configuration1
,
7091 Lisp_Object configuration2
,
7092 bool ignore_positions
)
7094 register struct save_window_data
*d1
, *d2
;
7095 struct Lisp_Vector
*sws1
, *sws2
;
7098 CHECK_WINDOW_CONFIGURATION (configuration1
);
7099 CHECK_WINDOW_CONFIGURATION (configuration2
);
7101 d1
= (struct save_window_data
*) XVECTOR (configuration1
);
7102 d2
= (struct save_window_data
*) XVECTOR (configuration2
);
7103 sws1
= XVECTOR (d1
->saved_windows
);
7104 sws2
= XVECTOR (d2
->saved_windows
);
7106 /* Frame settings must match. */
7107 if (d1
->frame_cols
!= d2
->frame_cols
7108 || d1
->frame_lines
!= d2
->frame_lines
7109 || d1
->frame_menu_bar_lines
!= d2
->frame_menu_bar_lines
7110 || !EQ (d1
->selected_frame
, d2
->selected_frame
)
7111 || !EQ (d1
->current_buffer
, d2
->current_buffer
)
7112 || (!ignore_positions
7113 && (!EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
)
7114 || !EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
)))
7115 || !EQ (d1
->focus_frame
, d2
->focus_frame
)
7116 /* Verify that the two configurations have the same number of windows. */
7117 || sws1
->header
.size
!= sws2
->header
.size
)
7120 for (i
= 0; i
< sws1
->header
.size
; i
++)
7122 struct saved_window
*sw1
, *sw2
;
7124 sw1
= SAVED_WINDOW_N (sws1
, i
);
7125 sw2
= SAVED_WINDOW_N (sws2
, i
);
7128 /* The "current" windows in the two configurations must
7129 correspond to each other. */
7130 EQ (d1
->current_window
, sw1
->window
)
7131 != EQ (d2
->current_window
, sw2
->window
)
7132 /* Windows' buffers must match. */
7133 || !EQ (sw1
->buffer
, sw2
->buffer
)
7134 || !EQ (sw1
->pixel_left
, sw2
->pixel_left
)
7135 || !EQ (sw1
->pixel_top
, sw2
->pixel_top
)
7136 || !EQ (sw1
->pixel_height
, sw2
->pixel_height
)
7137 || !EQ (sw1
->pixel_width
, sw2
->pixel_width
)
7138 || !EQ (sw1
->left_col
, sw2
->left_col
)
7139 || !EQ (sw1
->top_line
, sw2
->top_line
)
7140 || !EQ (sw1
->total_cols
, sw2
->total_cols
)
7141 || !EQ (sw1
->total_lines
, sw2
->total_lines
)
7142 || !EQ (sw1
->display_table
, sw2
->display_table
)
7143 /* The next two disjuncts check the window structure for
7145 || !EQ (sw1
->parent
, sw2
->parent
)
7146 || !EQ (sw1
->prev
, sw2
->prev
)
7147 || (!ignore_positions
7148 && (!EQ (sw1
->hscroll
, sw2
->hscroll
)
7149 || !EQ (sw1
->min_hscroll
, sw2
->min_hscroll
)
7150 || !EQ (sw1
->start_at_line_beg
, sw2
->start_at_line_beg
)
7151 || NILP (Fequal (sw1
->start
, sw2
->start
))
7152 || NILP (Fequal (sw1
->pointm
, sw2
->pointm
))))
7153 || !EQ (sw1
->left_margin_cols
, sw2
->left_margin_cols
)
7154 || !EQ (sw1
->right_margin_cols
, sw2
->right_margin_cols
)
7155 || !EQ (sw1
->left_fringe_width
, sw2
->left_fringe_width
)
7156 || !EQ (sw1
->right_fringe_width
, sw2
->right_fringe_width
)
7157 || !EQ (sw1
->fringes_outside_margins
, sw2
->fringes_outside_margins
)
7158 || !EQ (sw1
->scroll_bar_width
, sw2
->scroll_bar_width
)
7159 || !EQ (sw1
->scroll_bar_height
, sw2
->scroll_bar_height
)
7160 || !EQ (sw1
->vertical_scroll_bar_type
, sw2
->vertical_scroll_bar_type
)
7161 || !EQ (sw1
->horizontal_scroll_bar_type
, sw2
->horizontal_scroll_bar_type
))
7168 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
7169 Scompare_window_configurations
, 2, 2, 0,
7170 doc
: /* Compare two window configurations as regards the structure of windows.
7171 This function ignores details such as the values of point
7172 and scrolling positions. */)
7173 (Lisp_Object x
, Lisp_Object y
)
7175 if (compare_window_configurations (x
, y
, true))
7181 init_window_once (void)
7183 struct frame
*f
= make_initial_frame ();
7184 XSETFRAME (selected_frame
, f
);
7185 Vterminal_frame
= selected_frame
;
7186 minibuf_window
= f
->minibuffer_window
;
7187 selected_window
= f
->selected_window
;
7193 Vwindow_list
= Qnil
;
7197 syms_of_window (void)
7199 DEFSYM (Qscroll_up
, "scroll-up");
7200 DEFSYM (Qscroll_down
, "scroll-down");
7201 DEFSYM (Qscroll_command
, "scroll-command");
7203 Fput (Qscroll_up
, Qscroll_command
, Qt
);
7204 Fput (Qscroll_down
, Qscroll_command
, Qt
);
7206 DEFSYM (Qwindow_configuration_change_hook
, "window-configuration-change-hook");
7207 DEFSYM (Qwindowp
, "windowp");
7208 DEFSYM (Qwindow_configuration_p
, "window-configuration-p");
7209 DEFSYM (Qwindow_live_p
, "window-live-p");
7210 DEFSYM (Qwindow_valid_p
, "window-valid-p");
7211 DEFSYM (Qwindow_deletable_p
, "window-deletable-p");
7212 DEFSYM (Qdelete_window
, "delete-window");
7213 DEFSYM (Qwindow_resize_root_window
, "window--resize-root-window");
7214 DEFSYM (Qwindow_resize_root_window_vertically
, "window--resize-root-window-vertically");
7215 DEFSYM (Qwindow_sanitize_window_sizes
, "window--sanitize-window-sizes");
7216 DEFSYM (Qwindow_pixel_to_total
, "window--pixel-to-total");
7217 DEFSYM (Qsafe
, "safe");
7218 DEFSYM (Qdisplay_buffer
, "display-buffer");
7219 DEFSYM (Qreplace_buffer_in_windows
, "replace-buffer-in-windows");
7220 DEFSYM (Qrecord_window_buffer
, "record-window-buffer");
7221 DEFSYM (Qget_mru_window
, "get-mru-window");
7222 DEFSYM (Qwindow_size
, "window-size");
7223 DEFSYM (Qtemp_buffer_show_hook
, "temp-buffer-show-hook");
7224 DEFSYM (Qabove
, "above");
7225 DEFSYM (Qclone_of
, "clone-of");
7226 DEFSYM (Qfloor
, "floor");
7227 DEFSYM (Qceiling
, "ceiling");
7228 DEFSYM (Qwindow_start_group_function
, "window-start-group-function");
7229 DEFSYM (Qwindow_end_group_function
, "window-end-group-function");
7230 DEFSYM (Qset_window_start_group_function
, "set-window-start-group-function");
7231 DEFSYM (Qrecenter_group_function
, "recenter-group-function");
7232 DEFSYM (Qpos_visible_in_window_p_group_function
, "pos-visible-in-window-p-group-function");
7233 DEFSYM (Qmove_to_window_line_group_function
, "move-to-window-line-group-function");
7235 staticpro (&Vwindow_list
);
7237 minibuf_selected_window
= Qnil
;
7238 staticpro (&minibuf_selected_window
);
7240 window_scroll_pixel_based_preserve_x
= -1;
7241 window_scroll_pixel_based_preserve_y
= -1;
7242 window_scroll_preserve_hpos
= -1;
7243 window_scroll_preserve_vpos
= -1;
7245 DEFVAR_LISP ("temp-buffer-show-function", Vtemp_buffer_show_function
,
7246 doc
: /* Non-nil means call as function to display a help buffer.
7247 The function is called with one argument, the buffer to be displayed.
7248 Used by `with-output-to-temp-buffer'.
7249 If this function is used, then it must do the entire job of showing
7250 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
7251 Vtemp_buffer_show_function
= Qnil
;
7253 DEFVAR_LISP ("minibuffer-scroll-window", Vminibuf_scroll_window
,
7254 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
7255 Vminibuf_scroll_window
= Qnil
;
7257 DEFVAR_BOOL ("mode-line-in-non-selected-windows", mode_line_in_non_selected_windows
,
7258 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
7259 If the minibuffer is active, the `minibuffer-scroll-window' mode line
7260 is displayed in the `mode-line' face. */);
7261 mode_line_in_non_selected_windows
= true;
7263 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer
,
7264 doc
: /* If this is a live buffer, \\[scroll-other-window] should scroll its window. */);
7265 Vother_window_scroll_buffer
= Qnil
;
7267 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p
,
7268 doc
: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
7269 auto_window_vscroll_p
= true;
7271 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines
,
7272 doc
: /* Number of lines of continuity when scrolling by screenfuls. */);
7273 next_screen_context_lines
= 2;
7275 DEFVAR_LISP ("scroll-preserve-screen-position",
7276 Vscroll_preserve_screen_position
,
7277 doc
: /* Controls if scroll commands move point to keep its screen position unchanged.
7278 A value of nil means point does not keep its screen position except
7279 at the scroll margin or window boundary respectively.
7280 A value of t means point keeps its screen position if the scroll
7281 command moved it vertically out of the window, e.g. when scrolling
7283 Any other value means point always keeps its screen position.
7284 Scroll commands should have the `scroll-command' property
7285 on their symbols to be controlled by this variable. */);
7286 Vscroll_preserve_screen_position
= Qnil
;
7288 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type
,
7289 doc
: /* Type of marker to use for `window-point'. */);
7290 Vwindow_point_insertion_type
= Qnil
;
7291 DEFSYM (Qwindow_point_insertion_type
, "window_point_insertion_type");
7293 DEFVAR_LISP ("window-configuration-change-hook",
7294 Vwindow_configuration_change_hook
,
7295 doc
: /* Functions to call when window configuration changes.
7296 The buffer-local part is run once per window, with the relevant window
7297 selected; while the global part is run only once for the modified frame,
7298 with the relevant frame selected. */);
7299 Vwindow_configuration_change_hook
= Qnil
;
7301 DEFVAR_LISP ("recenter-redisplay", Vrecenter_redisplay
,
7302 doc
: /* Non-nil means `recenter' redraws entire frame.
7303 If this option is non-nil, then the `recenter' command with a nil
7304 argument will redraw the entire frame; the special value `tty' causes
7305 the frame to be redrawn only if it is a tty frame. */);
7306 Vrecenter_redisplay
= Qtty
;
7308 DEFVAR_LISP ("window-combination-resize", Vwindow_combination_resize
,
7309 doc
: /* If t, resize window combinations proportionally.
7310 If this variable is nil, splitting a window gets the entire screen space
7311 for displaying the new window from the window to split. Deleting and
7312 resizing a window preferably resizes one adjacent window only.
7314 If this variable is t, splitting a window tries to get the space
7315 proportionally from all windows in the same combination. This also
7316 allows to split a window that is otherwise too small or of fixed size.
7317 Resizing and deleting a window proportionally resize all windows in the
7320 Other values are reserved for future use.
7322 This variable takes no effect if the variable `window-combination-limit' is
7324 Vwindow_combination_resize
= Qnil
;
7326 DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit
,
7327 doc
: /* If non-nil, splitting a window makes a new parent window.
7328 The following values are recognized:
7330 nil means splitting a window will create a new parent window only if the
7331 window has no parent window or the window shall become part of a
7332 combination orthogonal to the one it is part of.
7334 `window-size' means that splitting a window for displaying a buffer
7335 makes a new parent window provided `display-buffer' is supposed to
7336 explicitly set the window's size due to the presence of a
7337 `window-height' or `window-width' entry in the alist used by
7338 `display-buffer'. Otherwise, this value is handled like nil.
7340 `temp-buffer' means that splitting a window for displaying a temporary
7341 buffer always makes a new parent window. Otherwise, this value is
7344 `display-buffer' means that splitting a window for displaying a buffer
7345 always makes a new parent window. Since temporary buffers are
7346 displayed by the function `display-buffer', this value is stronger
7347 than `temp-buffer'. Splitting a window for other purpose makes a
7348 new parent window only if needed.
7350 t means that splitting a window always creates a new parent window. If
7351 all splits behave this way, each frame's window tree is a binary
7352 tree and every window but the frame's root window has exactly one
7355 Other values are reserved for future use. */);
7356 Vwindow_combination_limit
= Qwindow_size
;
7358 DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters
,
7359 doc
: /* Alist of persistent window parameters.
7360 This alist specifies which window parameters shall get saved by
7361 `current-window-configuration' and `window-state-get' and subsequently
7362 restored to their previous values by `set-window-configuration' and
7365 The car of each entry of this alist is the symbol specifying the
7366 parameter. The cdr is one of the following:
7368 nil means the parameter is neither saved by `window-state-get' nor by
7369 `current-window-configuration'.
7371 t means the parameter is saved by `current-window-configuration' and,
7372 provided its WRITABLE argument is nil, by `window-state-get'.
7374 The symbol `writable' means the parameter is saved unconditionally by
7375 both `current-window-configuration' and `window-state-get'. Do not use
7376 this value for parameters without read syntax (like windows or frames).
7378 Parameters not saved by `current-window-configuration' or
7379 `window-state-get' are left alone by `set-window-configuration'
7380 respectively are not installed by `window-state-put'. */);
7381 Vwindow_persistent_parameters
= list1 (Fcons (Qclone_of
, Qt
));
7383 DEFVAR_BOOL ("window-resize-pixelwise", window_resize_pixelwise
,
7384 doc
: /* Non-nil means resize windows pixelwise.
7385 This currently affects the functions: `split-window', `maximize-window',
7386 `minimize-window', `fit-window-to-buffer' and `fit-frame-to-buffer', and
7387 all functions that symmetrically resize a parent window.
7389 Note that when a frame's pixel size is not a multiple of the
7390 frame's character size, at least one window may get resized
7391 pixelwise even if this option is nil. */);
7392 window_resize_pixelwise
= false;
7394 DEFVAR_BOOL ("fast-but-imprecise-scrolling",
7395 Vfast_but_imprecise_scrolling
,
7396 doc
: /* When non-nil, accelerate scrolling operations.
7397 This comes into play when scrolling rapidly over previously
7398 unfontified buffer regions. Only those portions of the buffer which
7399 are actually going to be displayed get fontified.
7401 Note that this optimization can cause the portion of the buffer
7402 displayed after a scrolling operation to be somewhat inaccurate. */);
7403 Vfast_but_imprecise_scrolling
= false;
7405 DEFVAR_LISP ("window-start-group-function", Vwindow_start_group_function
,
7406 doc
: /* Function to call for `window-start' when its GROUP parameter is non-nil.
7407 When this variable contains a function, and `window-start' is called with a
7408 non-nil GROUP parameter, the function is called instead of `window-start''s
7409 normal action. `window-start' passes the function its argument WINDOW, which
7410 might be nil. The function may recursively call `window-start'. */);
7411 Vwindow_start_group_function
= Qnil
;
7412 Fmake_variable_buffer_local (Qwindow_start_group_function
);
7413 Fput (Qwindow_start_group_function
, Qpermanent_local
, Qt
);
7415 DEFVAR_LISP ("window-end-group-function", Vwindow_end_group_function
,
7416 doc
: /* Function to call for `window-end' if its GROUP parameter is non-nil.
7417 When this variable contains a function, and `window-end' is called with a
7418 non-nil GROUP parameter, the function is called instead of `window-end''s
7419 normal action. `window-end' passes the function its two parameters WINDOW,
7420 and UPDATE. The function may call `window-end' recursively. */);
7421 Vwindow_end_group_function
= Qnil
;
7422 Fmake_variable_buffer_local (Qwindow_end_group_function
);
7423 Fput (Qwindow_end_group_function
, Qpermanent_local
, Qt
);
7425 DEFVAR_LISP ("set-window-start-group-function",
7426 Vset_window_start_group_function
,
7427 doc
: /* The function to call for `set-window-start' when its GROUP parameter is non-nil.
7428 When this variable contains a function, and `set-window-start' is called
7429 with a non-nil GROUP parameter, the function is called instead of
7430 `set-window-start''s normal action. `set-window-start' passes the function
7431 its three parameters WINDOW, POS, and NOFORCE. The function may call
7432 `set-window-start' recursively. */);
7433 Vset_window_start_group_function
= Qnil
;
7434 Fmake_variable_buffer_local (Qset_window_start_group_function
);
7435 Fput (Qset_window_start_group_function
, Qpermanent_local
, Qt
);
7437 DEFVAR_LISP ("recenter-group-function", Vrecenter_group_function
,
7438 doc
: /* Function to call for `recenter' when its GROUP parameter is non-nil.
7439 When this variable contains a function, and `recenter' is called with a
7440 non-nil GROUP parameter, the function is called instead of `recenter''s
7441 normal action. `recenter' passes the function its parameter ARG. The
7442 function may call `recenter' recursively. */);
7443 Vrecenter_group_function
= Qnil
;
7444 Fmake_variable_buffer_local (Qrecenter_group_function
);
7445 Fput (Qrecenter_group_function
, Qpermanent_local
, Qt
);
7447 DEFVAR_LISP ("pos-visible-in-window-p-group-function",
7448 Vpos_visible_in_window_p_group_function
,
7449 doc
: /* Function for `pos-visible-in-window-p' when its GROUP parameter is non-nil.
7450 When this variable contains a function, and `pos-visible-in-window-p' is
7451 called with a non-nil GROUP parameter, the function is called instead of
7452 `pos-visible-in-window-p''s normal action. `pos-visible-in-window-p'
7453 passes the function its three parameters POS, WINDOW, and PARTIALLY. The
7454 function may call `pos-visible-in-window-p' recursively. */);
7455 Vpos_visible_in_window_p_group_function
= Qnil
;
7456 Fmake_variable_buffer_local (Qpos_visible_in_window_p_group_function
);
7457 Fput (Qpos_visible_in_window_p_group_function
, Qpermanent_local
, Qt
);
7459 DEFVAR_LISP ("move-to-window-line-group-function",
7460 Vmove_to_window_line_group_function
,
7461 doc
: /* Function for `move-to-window-line' when its GROUP parameter is non-nil.
7462 When this variable contains a function, and `move-to-window-line' is
7463 called with a non-nil GROUP parameter, the function is called instead of
7464 `move-to-window-line''s normal action. `move-to-window-line' passes the
7465 function its parameter ARG. The function may call `move-to-window-line'
7467 Vmove_to_window_line_group_function
= Qnil
;
7468 Fmake_variable_buffer_local (Qmove_to_window_line_group_function
);
7469 Fput (Qmove_to_window_line_group_function
, Qpermanent_local
, Qt
);
7471 defsubr (&Sselected_window
);
7472 defsubr (&Sminibuffer_window
);
7473 defsubr (&Swindow_minibuffer_p
);
7474 defsubr (&Swindowp
);
7475 defsubr (&Swindow_valid_p
);
7476 defsubr (&Swindow_live_p
);
7477 defsubr (&Swindow_frame
);
7478 defsubr (&Sframe_root_window
);
7479 defsubr (&Sframe_first_window
);
7480 defsubr (&Sframe_selected_window
);
7481 defsubr (&Sset_frame_selected_window
);
7482 defsubr (&Spos_visible_in_window_p
);
7483 defsubr (&Swindow_line_height
);
7484 defsubr (&Swindow_buffer
);
7485 defsubr (&Swindow_parent
);
7486 defsubr (&Swindow_top_child
);
7487 defsubr (&Swindow_left_child
);
7488 defsubr (&Swindow_next_sibling
);
7489 defsubr (&Swindow_prev_sibling
);
7490 defsubr (&Swindow_combination_limit
);
7491 defsubr (&Sset_window_combination_limit
);
7492 defsubr (&Swindow_use_time
);
7493 defsubr (&Swindow_pixel_width
);
7494 defsubr (&Swindow_pixel_height
);
7495 defsubr (&Swindow_total_width
);
7496 defsubr (&Swindow_total_height
);
7497 defsubr (&Swindow_normal_size
);
7498 defsubr (&Swindow_new_pixel
);
7499 defsubr (&Swindow_new_total
);
7500 defsubr (&Swindow_new_normal
);
7501 defsubr (&Swindow_pixel_left
);
7502 defsubr (&Swindow_pixel_top
);
7503 defsubr (&Swindow_left_column
);
7504 defsubr (&Swindow_top_line
);
7505 defsubr (&Sset_window_new_pixel
);
7506 defsubr (&Sset_window_new_total
);
7507 defsubr (&Sset_window_new_normal
);
7508 defsubr (&Swindow_resize_apply
);
7509 defsubr (&Swindow_resize_apply_total
);
7510 defsubr (&Swindow_body_height
);
7511 defsubr (&Swindow_body_width
);
7512 defsubr (&Swindow_hscroll
);
7513 defsubr (&Sset_window_hscroll
);
7514 defsubr (&Swindow_redisplay_end_trigger
);
7515 defsubr (&Sset_window_redisplay_end_trigger
);
7516 defsubr (&Swindow_mode_line_height
);
7517 defsubr (&Swindow_header_line_height
);
7518 defsubr (&Swindow_right_divider_width
);
7519 defsubr (&Swindow_bottom_divider_width
);
7520 defsubr (&Swindow_scroll_bar_width
);
7521 defsubr (&Swindow_scroll_bar_height
);
7522 defsubr (&Scoordinates_in_window_p
);
7523 defsubr (&Swindow_at
);
7524 defsubr (&Swindow_point
);
7525 defsubr (&Swindow_old_point
);
7526 defsubr (&Swindow_start
);
7527 defsubr (&Swindow_end
);
7528 defsubr (&Sset_window_point
);
7529 defsubr (&Sset_window_start
);
7530 defsubr (&Swindow_dedicated_p
);
7531 defsubr (&Sset_window_dedicated_p
);
7532 defsubr (&Swindow_display_table
);
7533 defsubr (&Sset_window_display_table
);
7534 defsubr (&Snext_window
);
7535 defsubr (&Sprevious_window
);
7536 defsubr (&Swindow__sanitize_window_sizes
);
7537 defsubr (&Sget_buffer_window
);
7538 defsubr (&Sdelete_other_windows_internal
);
7539 defsubr (&Sdelete_window_internal
);
7540 defsubr (&Sresize_mini_window_internal
);
7541 defsubr (&Sset_window_buffer
);
7542 defsubr (&Srun_window_configuration_change_hook
);
7543 defsubr (&Srun_window_scroll_functions
);
7544 defsubr (&Sselect_window
);
7545 defsubr (&Sforce_window_update
);
7546 defsubr (&Ssplit_window_internal
);
7547 defsubr (&Sscroll_up
);
7548 defsubr (&Sscroll_down
);
7549 defsubr (&Sscroll_left
);
7550 defsubr (&Sscroll_right
);
7551 defsubr (&Sother_window_for_scrolling
);
7552 defsubr (&Sscroll_other_window
);
7553 defsubr (&Sminibuffer_selected_window
);
7554 defsubr (&Srecenter
);
7555 defsubr (&Swindow_text_width
);
7556 defsubr (&Swindow_text_height
);
7557 defsubr (&Smove_to_window_line
);
7558 defsubr (&Swindow_configuration_p
);
7559 defsubr (&Swindow_configuration_frame
);
7560 defsubr (&Sset_window_configuration
);
7561 defsubr (&Scurrent_window_configuration
);
7562 defsubr (&Sset_window_margins
);
7563 defsubr (&Swindow_margins
);
7564 defsubr (&Sset_window_fringes
);
7565 defsubr (&Swindow_fringes
);
7566 defsubr (&Sset_window_scroll_bars
);
7567 defsubr (&Swindow_scroll_bars
);
7568 defsubr (&Swindow_vscroll
);
7569 defsubr (&Sset_window_vscroll
);
7570 defsubr (&Scompare_window_configurations
);
7571 defsubr (&Swindow_list
);
7572 defsubr (&Swindow_list_1
);
7573 defsubr (&Swindow_prev_buffers
);
7574 defsubr (&Sset_window_prev_buffers
);
7575 defsubr (&Swindow_next_buffers
);
7576 defsubr (&Sset_window_next_buffers
);
7577 defsubr (&Swindow_parameters
);
7578 defsubr (&Swindow_parameter
);
7579 defsubr (&Sset_window_parameter
);
7583 keys_of_window (void)
7585 initial_define_key (control_x_map
, '<', "scroll-left");
7586 initial_define_key (control_x_map
, '>', "scroll-right");
7588 initial_define_key (global_map
, Ctl ('V'), "scroll-up-command");
7589 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
7590 initial_define_key (meta_map
, 'v', "scroll-down-command");