1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985-1987, 1993-1998, 2000-2013 Free Software
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
23 #define WINDOW_INLINE EXTERN_INLINE
28 #include "character.h"
38 #include "dispextern.h"
39 #include "blockinput.h"
40 #include "intervals.h"
41 #include "termhooks.h" /* For FRAME_TERMINAL. */
45 #endif /* HAVE_X_WINDOWS */
56 Lisp_Object Qwindowp
, Qwindow_live_p
;
57 static Lisp_Object Qwindow_valid_p
;
58 static Lisp_Object Qwindow_configuration_p
;
59 static Lisp_Object Qrecord_window_buffer
;
60 static Lisp_Object Qwindow_deletable_p
, Qdelete_window
, Qdisplay_buffer
;
61 static Lisp_Object Qreplace_buffer_in_windows
, Qget_mru_window
;
62 static Lisp_Object Qwindow_resize_root_window
, Qwindow_resize_root_window_vertically
;
63 static Lisp_Object Qscroll_up
, Qscroll_down
, Qscroll_command
;
64 static Lisp_Object Qsafe
, Qabove
, Qbelow
, Qwindow_size
, Qclone_of
;
66 static int displayed_window_lines (struct window
*);
67 static int count_windows (struct window
*);
68 static int get_leaf_windows (struct window
*, struct window
**, int);
69 static void window_scroll (Lisp_Object
, EMACS_INT
, bool, int);
70 static void window_scroll_pixel_based (Lisp_Object
, int, bool, int);
71 static void window_scroll_line_based (Lisp_Object
, int, bool, int);
72 static int freeze_window_start (struct window
*, void *);
73 static Lisp_Object
window_list (void);
74 static int add_window_to_list (struct window
*, void *);
75 static Lisp_Object
next_window (Lisp_Object
, Lisp_Object
,
77 static void decode_next_window_args (Lisp_Object
*, Lisp_Object
*,
79 static void foreach_window (struct frame
*,
80 int (* fn
) (struct window
*, void *),
82 static int foreach_window_1 (struct window
*,
83 int (* fn
) (struct window
*, void *),
85 static Lisp_Object
window_list_1 (Lisp_Object
, Lisp_Object
, Lisp_Object
);
86 static int window_resize_check (struct window
*, bool);
87 static void window_resize_apply (struct window
*, bool);
88 static Lisp_Object
select_window (Lisp_Object
, Lisp_Object
, int);
89 static void select_window_1 (Lisp_Object
, bool);
91 /* This is the window in which the terminal's cursor should
92 be left when nothing is being done with it. This must
93 always be a leaf window, and its buffer is selected by
94 the top level editing loop at the end of each command.
96 This value is always the same as
97 FRAME_SELECTED_WINDOW (selected_frame). */
98 Lisp_Object selected_window
;
100 /* A list of all windows for use by next_window and Fwindow_list.
101 Functions creating or deleting windows should invalidate this cache
102 by setting it to nil. */
103 Lisp_Object Vwindow_list
;
105 /* The mini-buffer window of the selected frame.
106 Note that you cannot test for mini-bufferness of an arbitrary window
107 by comparing against this; but you can test for mini-bufferness of
108 the selected window. */
109 Lisp_Object minibuf_window
;
111 /* Non-nil means it is the window whose mode line should be
112 shown as the selected window when the minibuffer is selected. */
113 Lisp_Object minibuf_selected_window
;
115 /* Hook run at end of temp_output_buffer_show. */
116 static Lisp_Object Qtemp_buffer_show_hook
;
118 /* Nonzero after init_window_once has finished. */
119 static int window_initialized
;
121 /* Hook to run when window config changes. */
122 static Lisp_Object Qwindow_configuration_change_hook
;
124 /* Used by the function window_scroll_pixel_based */
125 static int window_scroll_pixel_based_preserve_x
;
126 static int window_scroll_pixel_based_preserve_y
;
128 /* Same for window_scroll_line_based. */
129 static EMACS_INT window_scroll_preserve_hpos
;
130 static EMACS_INT window_scroll_preserve_vpos
;
133 CHECK_WINDOW_CONFIGURATION (Lisp_Object x
)
135 CHECK_TYPE (WINDOW_CONFIGURATIONP (x
), Qwindow_configuration_p
, x
);
138 /* These setters are used only in this file, so they can be private. */
140 wset_combination_limit (struct window
*w
, Lisp_Object val
)
142 w
->combination_limit
= val
;
145 wset_dedicated (struct window
*w
, Lisp_Object val
)
150 wset_display_table (struct window
*w
, Lisp_Object val
)
152 w
->display_table
= val
;
155 wset_left_fringe_width (struct window
*w
, Lisp_Object val
)
157 w
->left_fringe_width
= val
;
160 wset_left_margin_cols (struct window
*w
, Lisp_Object val
)
162 w
->left_margin_cols
= val
;
165 wset_new_normal (struct window
*w
, Lisp_Object val
)
170 wset_new_total (struct window
*w
, Lisp_Object val
)
175 wset_normal_cols (struct window
*w
, Lisp_Object val
)
177 w
->normal_cols
= val
;
180 wset_normal_lines (struct window
*w
, Lisp_Object val
)
182 w
->normal_lines
= val
;
185 wset_parent (struct window
*w
, Lisp_Object val
)
190 wset_pointm (struct window
*w
, Lisp_Object val
)
195 wset_right_fringe_width (struct window
*w
, Lisp_Object val
)
197 w
->right_fringe_width
= val
;
200 wset_right_margin_cols (struct window
*w
, Lisp_Object val
)
202 w
->right_margin_cols
= val
;
205 wset_scroll_bar_width (struct window
*w
, Lisp_Object val
)
207 w
->scroll_bar_width
= val
;
210 wset_start (struct window
*w
, Lisp_Object val
)
215 wset_temslot (struct window
*w
, Lisp_Object val
)
220 wset_vertical_scroll_bar_type (struct window
*w
, Lisp_Object val
)
222 w
->vertical_scroll_bar_type
= val
;
225 wset_window_parameters (struct window
*w
, Lisp_Object val
)
227 w
->window_parameters
= val
;
230 wset_combination (struct window
*w
, bool horflag
, Lisp_Object val
)
232 /* Since leaf windows never becomes non-leaf, there should
233 be no buffer and markers in start and pointm fields of W. */
234 eassert (!BUFFERP (w
->contents
) && NILP (w
->start
) && NILP (w
->pointm
));
236 /* When an internal window is deleted and VAL is nil, HORFLAG
239 w
->horizontal
= horflag
;
242 /* Nonzero if leaf window W doesn't reflect the actual state
243 of displayed buffer due to its text or overlays change. */
246 window_outdated (struct window
*w
)
248 struct buffer
*b
= XBUFFER (w
->contents
);
249 return (w
->last_modified
< BUF_MODIFF (b
)
250 || w
->last_overlay_modified
< BUF_OVERLAY_MODIFF (b
));
254 decode_live_window (register Lisp_Object window
)
257 return XWINDOW (selected_window
);
259 CHECK_LIVE_WINDOW (window
);
260 return XWINDOW (window
);
264 decode_any_window (register Lisp_Object window
)
269 return XWINDOW (selected_window
);
271 CHECK_WINDOW (window
);
272 w
= XWINDOW (window
);
276 static struct window
*
277 decode_valid_window (register Lisp_Object window
)
282 return XWINDOW (selected_window
);
284 CHECK_VALID_WINDOW (window
);
285 w
= XWINDOW (window
);
289 /* Called when W's buffer slot is changed. ARG -1 means that W is about to
290 cease its buffer, and 1 means that W is about to set up the new one. */
293 adjust_window_count (struct window
*w
, int arg
)
295 eassert (eabs (arg
) == 1);
296 if (BUFFERP (w
->contents
))
298 struct buffer
*b
= XBUFFER (w
->contents
);
302 b
->window_count
+= arg
;
303 eassert (b
->window_count
>= 0);
304 /* These should be recalculated by redisplay code. */
305 w
->window_end_valid
= 0;
306 w
->base_line_pos
= 0;
310 /* Set W's buffer slot to VAL and recompute number
311 of windows showing VAL if it is a buffer. */
314 wset_buffer (struct window
*w
, Lisp_Object val
)
316 adjust_window_count (w
, -1);
318 /* Make sure that we do not assign the buffer
319 to an internal window. */
320 eassert (MARKERP (w
->start
) && MARKERP (w
->pointm
));
322 adjust_window_count (w
, 1);
325 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
326 doc
: /* Return t if OBJECT is a window and nil otherwise. */)
329 return WINDOWP (object
) ? Qt
: Qnil
;
332 DEFUN ("window-valid-p", Fwindow_valid_p
, Swindow_valid_p
, 1, 1, 0,
333 doc
: /* Return t if OBJECT is a valid window and nil otherwise.
334 A valid window is either a window that displays a buffer or an internal
335 window. Deleted windows are not live. */)
338 return WINDOW_VALID_P (object
) ? Qt
: Qnil
;
341 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
342 doc
: /* Return t if OBJECT is a live window and nil otherwise.
343 A live window is a window that displays a buffer.
344 Internal windows and deleted windows are not live. */)
347 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
350 /* Frames and windows. */
351 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 0, 1, 0,
352 doc
: /* Return the frame that window WINDOW is on.
353 WINDOW must be a valid window and defaults to the selected one. */)
356 return decode_valid_window (window
)->frame
;
359 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
360 doc
: /* Return the root window of FRAME-OR-WINDOW.
361 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
362 With a frame argument, return that frame's root window.
363 With a window argument, return the root window of that window's frame. */)
364 (Lisp_Object frame_or_window
)
368 if (NILP (frame_or_window
))
369 window
= SELECTED_FRAME ()->root_window
;
370 else if (WINDOW_VALID_P (frame_or_window
))
371 window
= XFRAME (XWINDOW (frame_or_window
)->frame
)->root_window
;
374 CHECK_LIVE_FRAME (frame_or_window
);
375 window
= XFRAME (frame_or_window
)->root_window
;
381 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
382 doc
: /* Return the minibuffer window for frame FRAME.
383 If FRAME is omitted or nil, it defaults to the selected frame. */)
386 return FRAME_MINIBUF_WINDOW (decode_live_frame (frame
));
389 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
,
390 Swindow_minibuffer_p
, 0, 1, 0,
391 doc
: /* Return non-nil if WINDOW is a minibuffer window.
392 WINDOW must be a valid window and defaults to the selected one. */)
395 return MINI_WINDOW_P (decode_valid_window (window
)) ? Qt
: Qnil
;
398 /* Don't move this to window.el - this must be a safe routine. */
399 DEFUN ("frame-first-window", Fframe_first_window
, Sframe_first_window
, 0, 1, 0,
400 doc
: /* Return the topmost, leftmost live window on FRAME-OR-WINDOW.
401 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
402 Else if FRAME-OR-WINDOW denotes a valid window, return the first window
403 of that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
404 the first window of that frame. */)
405 (Lisp_Object frame_or_window
)
409 if (NILP (frame_or_window
))
410 window
= SELECTED_FRAME ()->root_window
;
411 else if (WINDOW_VALID_P (frame_or_window
))
412 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
415 CHECK_LIVE_FRAME (frame_or_window
);
416 window
= XFRAME (frame_or_window
)->root_window
;
419 while (WINDOWP (XWINDOW (window
)->contents
))
420 window
= XWINDOW (window
)->contents
;
425 DEFUN ("frame-selected-window", Fframe_selected_window
,
426 Sframe_selected_window
, 0, 1, 0,
427 doc
: /* Return the selected window of FRAME-OR-WINDOW.
428 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
429 Else if FRAME-OR-WINDOW denotes a valid window, return the selected
430 window of that window's frame. If FRAME-OR-WINDOW denotes a live frame,
431 return the selected window of that frame. */)
432 (Lisp_Object frame_or_window
)
436 if (NILP (frame_or_window
))
437 window
= SELECTED_FRAME ()->selected_window
;
438 else if (WINDOW_VALID_P (frame_or_window
))
439 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->selected_window
;
442 CHECK_LIVE_FRAME (frame_or_window
);
443 window
= XFRAME (frame_or_window
)->selected_window
;
449 DEFUN ("set-frame-selected-window", Fset_frame_selected_window
,
450 Sset_frame_selected_window
, 2, 3, 0,
451 doc
: /* Set selected window of FRAME to WINDOW.
452 FRAME must be a live frame and defaults to the selected one. If FRAME
453 is the selected frame, this makes WINDOW the selected window. Optional
454 argument NORECORD non-nil means to neither change the order of recently
455 selected windows nor the buffer list. WINDOW must denote a live window.
457 (Lisp_Object frame
, Lisp_Object window
, Lisp_Object norecord
)
460 frame
= selected_frame
;
462 CHECK_LIVE_FRAME (frame
);
463 CHECK_LIVE_WINDOW (window
);
465 if (! EQ (frame
, WINDOW_FRAME (XWINDOW (window
))))
466 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
468 if (EQ (frame
, selected_frame
))
469 return Fselect_window (window
, norecord
);
472 fset_selected_window (XFRAME (frame
), window
);
477 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
478 doc
: /* Return the selected window.
479 The selected window is the window in which the standard cursor for
480 selected windows appears and to which many commands apply. */)
483 return selected_window
;
486 int window_select_count
;
488 /* If select_window is called with inhibit_point_swap non-zero it will
489 not store point of the old selected window's buffer back into that
490 window's pointm slot. This is needed by Fset_window_configuration to
491 avoid that the display routine is called with selected_window set to
492 Qnil causing a subsequent crash. */
494 select_window (Lisp_Object window
, Lisp_Object norecord
, int inhibit_point_swap
)
496 register struct window
*w
;
499 CHECK_LIVE_WINDOW (window
);
501 w
= XWINDOW (window
);
502 w
->frozen_window_start_p
= 0;
504 /* Make the selected window's buffer current. */
505 Fset_buffer (w
->contents
);
507 if (EQ (window
, selected_window
) && !inhibit_point_swap
)
508 /* `switch-to-buffer' uses (select-window (selected-window)) as a "clever"
509 way to call record_buffer from Elisp, so it's important that we call
510 record_buffer before returning here. */
511 goto record_and_return
;
513 sf
= SELECTED_FRAME ();
514 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
516 fset_selected_window (XFRAME (WINDOW_FRAME (w
)), window
);
517 /* Use this rather than Fhandle_switch_frame
518 so that FRAME_FOCUS_FRAME is moved appropriately as we
519 move around in the state where a minibuffer in a separate
521 Fselect_frame (WINDOW_FRAME (w
), norecord
);
522 /* Fselect_frame called us back so we've done all the work already. */
523 eassert (EQ (window
, selected_window
));
527 fset_selected_window (sf
, window
);
529 select_window_1 (window
, inhibit_point_swap
);
530 bset_last_selected_window (XBUFFER (w
->contents
), window
);
531 windows_or_buffers_changed
++;
534 /* record_buffer can run QUIT, so make sure it is run only after we have
535 re-established the invariant between selected_window and selected_frame,
536 otherwise the temporary broken invariant might "escape" (bug#14161). */
539 w
->use_time
= ++window_select_count
;
540 record_buffer (w
->contents
);
546 /* Select window with a minimum of fuss, i.e. don't record the change anywhere
547 (not even for redisplay's benefit), and assume that the window's frame is
550 select_window_1 (Lisp_Object window
, bool inhibit_point_swap
)
552 /* Store the old selected window's buffer's point in pointm of the old
553 selected window. It belongs to that window, and when the window is
554 not selected, must be in the window. */
555 if (!inhibit_point_swap
)
557 struct window
*ow
= XWINDOW (selected_window
);
558 if (BUFFERP (ow
->contents
))
559 set_marker_both (ow
->pointm
, ow
->contents
,
560 BUF_PT (XBUFFER (ow
->contents
)),
561 BUF_PT_BYTE (XBUFFER (ow
->contents
)));
564 selected_window
= window
;
566 /* Go to the point recorded in the window.
567 This is important when the buffer is in more
568 than one window. It also matters when
569 redisplay_window has altered point after scrolling,
570 because it makes the change only in the window. */
572 register ptrdiff_t new_point
= marker_position (XWINDOW (window
)->pointm
);
573 if (new_point
< BEGV
)
575 else if (new_point
> ZV
)
582 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
583 doc
: /* Select WINDOW which must be a live window.
584 Also make WINDOW's frame the selected frame and WINDOW that frame's
585 selected window. In addition, make WINDOW's buffer current and set that
586 buffer's value of `point' to the value of WINDOW's `window-point'.
589 Optional second arg NORECORD non-nil means do not put this buffer at the
590 front of the buffer list and do not make this window the most recently
593 Note that the main editor command loop sets the current buffer to the
594 buffer of the selected window before each command. */)
595 (register Lisp_Object window
, Lisp_Object norecord
)
597 return select_window (window
, norecord
, 0);
600 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
601 doc
: /* Return the buffer displayed in window WINDOW.
602 If WINDOW is omitted or nil, it defaults to the selected window.
603 Return nil for an internal window or a deleted window. */)
606 struct window
*w
= decode_any_window (window
);
607 return WINDOW_LEAF_P (w
) ? w
->contents
: Qnil
;
610 DEFUN ("window-parent", Fwindow_parent
, Swindow_parent
, 0, 1, 0,
611 doc
: /* Return the parent window of window WINDOW.
612 WINDOW must be a valid window and defaults to the selected one.
613 Return nil for a window with no parent (e.g. a root window). */)
616 return decode_valid_window (window
)->parent
;
619 DEFUN ("window-top-child", Fwindow_top_child
, Swindow_top_child
, 0, 1, 0,
620 doc
: /* Return the topmost child window of window WINDOW.
621 WINDOW must be a valid window and defaults to the selected one.
622 Return nil if WINDOW is a live window (live windows have no children).
623 Return nil if WINDOW is an internal window whose children form a
624 horizontal combination. */)
627 struct window
*w
= decode_valid_window (window
);
628 return WINDOW_VERTICAL_COMBINATION_P (w
) ? w
->contents
: Qnil
;
631 DEFUN ("window-left-child", Fwindow_left_child
, Swindow_left_child
, 0, 1, 0,
632 doc
: /* Return the leftmost child window of window WINDOW.
633 WINDOW must be a valid window and defaults to the selected one.
634 Return nil if WINDOW is a live window (live windows have no children).
635 Return nil if WINDOW is an internal window whose children form a
636 vertical combination. */)
639 struct window
*w
= decode_valid_window (window
);
640 return WINDOW_HORIZONTAL_COMBINATION_P (w
) ? w
->contents
: Qnil
;
643 DEFUN ("window-next-sibling", Fwindow_next_sibling
, Swindow_next_sibling
, 0, 1, 0,
644 doc
: /* Return the next sibling window of window WINDOW.
645 WINDOW must be a valid window and defaults to the selected one.
646 Return nil if WINDOW has no next sibling. */)
649 return decode_valid_window (window
)->next
;
652 DEFUN ("window-prev-sibling", Fwindow_prev_sibling
, Swindow_prev_sibling
, 0, 1, 0,
653 doc
: /* Return the previous sibling window of window WINDOW.
654 WINDOW must be a valid window and defaults to the selected one.
655 Return nil if WINDOW has no previous sibling. */)
658 return decode_valid_window (window
)->prev
;
661 DEFUN ("window-combination-limit", Fwindow_combination_limit
, Swindow_combination_limit
, 1, 1, 0,
662 doc
: /* Return combination limit of window WINDOW.
663 WINDOW must be a valid window used in horizontal or vertical combination.
664 If the return value is nil, child windows of WINDOW can be recombined with
665 WINDOW's siblings. A return value of t means that child windows of
666 WINDOW are never \(re-)combined with WINDOW's siblings. */)
671 CHECK_VALID_WINDOW (window
);
672 w
= XWINDOW (window
);
673 if (WINDOW_LEAF_P (w
))
674 error ("Combination limit is meaningful for internal windows only");
675 return w
->combination_limit
;
678 DEFUN ("set-window-combination-limit", Fset_window_combination_limit
, Sset_window_combination_limit
, 2, 2, 0,
679 doc
: /* Set combination limit of window WINDOW to LIMIT; return LIMIT.
680 WINDOW must be a valid window used in horizontal or vertical combination.
681 If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's
682 siblings. LIMIT t means that child windows of WINDOW are never
683 \(re-)combined with WINDOW's siblings. Other values are reserved for
685 (Lisp_Object window
, Lisp_Object limit
)
689 CHECK_VALID_WINDOW (window
);
690 w
= XWINDOW (window
);
691 if (WINDOW_LEAF_P (w
))
692 error ("Combination limit is meaningful for internal windows only");
693 wset_combination_limit (w
, limit
);
697 DEFUN ("window-use-time", Fwindow_use_time
, Swindow_use_time
, 0, 1, 0,
698 doc
: /* Return the use time of window WINDOW.
699 WINDOW must be a live window and defaults to the selected one.
700 The window with the highest use time is the most recently selected
701 one. The window with the lowest use time is the least recently
705 return make_number (decode_live_window (window
)->use_time
);
708 DEFUN ("window-total-height", Fwindow_total_height
, Swindow_total_height
, 0, 1, 0,
709 doc
: /* Return the total height, in lines, of window WINDOW.
710 WINDOW must be a valid window and defaults to the selected one.
712 The return value includes the mode line and header line, if any.
713 If WINDOW is an internal window, the total height is the height
714 of the screen areas spanned by its children.
716 On a graphical display, this total height is reported as an
717 integer multiple of the default character height. */)
720 return make_number (decode_valid_window (window
)->total_lines
);
723 DEFUN ("window-total-width", Fwindow_total_width
, Swindow_total_width
, 0, 1, 0,
724 doc
: /* Return the total width, in columns, of window WINDOW.
725 WINDOW must be a valid window and defaults to the selected one.
727 The return value includes any vertical dividers or scroll bars
728 belonging to WINDOW. If WINDOW is an internal window, the total width
729 is the width of the screen areas spanned by its children.
731 On a graphical display, this total width is reported as an
732 integer multiple of the default character width. */)
735 return make_number (decode_valid_window (window
)->total_cols
);
738 DEFUN ("window-new-total", Fwindow_new_total
, Swindow_new_total
, 0, 1, 0,
739 doc
: /* Return the new total size of window WINDOW.
740 WINDOW must be a valid window and defaults to the selected one. */)
743 return decode_valid_window (window
)->new_total
;
746 DEFUN ("window-normal-size", Fwindow_normal_size
, Swindow_normal_size
, 0, 2, 0,
747 doc
: /* Return the normal height of window WINDOW.
748 WINDOW must be a valid window and defaults to the selected one.
749 If HORIZONTAL is non-nil, return the normal width of WINDOW. */)
750 (Lisp_Object window
, Lisp_Object horizontal
)
752 struct window
*w
= decode_valid_window (window
);
754 return NILP (horizontal
) ? w
->normal_lines
: w
->normal_cols
;
757 DEFUN ("window-new-normal", Fwindow_new_normal
, Swindow_new_normal
, 0, 1, 0,
758 doc
: /* Return new normal size of window WINDOW.
759 WINDOW must be a valid window and defaults to the selected one. */)
762 return decode_valid_window (window
)->new_normal
;
765 DEFUN ("window-left-column", Fwindow_left_column
, Swindow_left_column
, 0, 1, 0,
766 doc
: /* Return left column of window WINDOW.
767 This is the distance, in columns, between the left edge of WINDOW and
768 the left edge of the frame's window area. For instance, the return
769 value is 0 if there is no window to the left of WINDOW.
771 WINDOW must be a valid window and defaults to the selected one. */)
774 return make_number (decode_valid_window (window
)->left_col
);
777 DEFUN ("window-top-line", Fwindow_top_line
, Swindow_top_line
, 0, 1, 0,
778 doc
: /* Return top line of window WINDOW.
779 This is the distance, in lines, between the top of WINDOW and the top
780 of the frame's window area. For instance, the return value is 0 if
781 there is no window above WINDOW.
783 WINDOW must be a valid window and defaults to the selected one. */)
786 return make_number (decode_valid_window (window
)->top_line
);
789 /* Return the number of lines of W's body. Don't count any mode or
793 window_body_lines (struct window
*w
)
795 int height
= w
->total_lines
;
797 if (!MINI_WINDOW_P (w
))
799 if (WINDOW_WANTS_MODELINE_P (w
))
801 if (WINDOW_WANTS_HEADER_LINE_P (w
))
808 /* Return the number of columns of W's body. Don't count columns
809 occupied by the scroll bar or the vertical bar separating W from its
810 right sibling. On window-systems don't count fringes or display
814 window_body_cols (struct window
*w
)
816 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
817 int width
= w
->total_cols
;
819 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
820 /* Scroll bars occupy a few columns. */
821 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
822 else if (!FRAME_WINDOW_P (f
)
823 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
824 /* The column of `|' characters separating side-by-side windows
825 occupies one column only. */
828 /* Display margins cannot be used for normal text. */
829 width
-= WINDOW_LEFT_MARGIN_COLS (w
) + WINDOW_RIGHT_MARGIN_COLS (w
);
831 if (FRAME_WINDOW_P (f
))
832 /* On window-systems, fringes cannot be used for normal text. */
833 width
-= WINDOW_FRINGE_COLS (w
);
838 DEFUN ("window-body-height", Fwindow_body_height
, Swindow_body_height
, 0, 1, 0,
839 doc
: /* Return the height, in lines, of WINDOW's text area.
840 WINDOW must be a live window and defaults to the selected one.
842 The returned height does not include the mode line or header line.
843 On a graphical display, the height is expressed as an integer multiple
844 of the default character height. If a line at the bottom of the text
845 area is only partially visible, that counts as a whole line; to
846 exclude partially-visible lines, use `window-text-height'. */)
849 return make_number (window_body_lines (decode_live_window (window
)));
852 DEFUN ("window-body-width", Fwindow_body_width
, Swindow_body_width
, 0, 1, 0,
853 doc
: /* Return the width, in columns, of WINDOW's text area.
854 WINDOW must be a live window and defaults to the selected one.
856 The return value does not include any vertical dividers, fringe or
857 marginal areas, or scroll bars. On a graphical display, the width is
858 expressed as an integer multiple of the default character width. */)
861 return make_number (window_body_cols (decode_live_window (window
)));
864 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
865 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
866 WINDOW must be a live window and defaults to the selected one. */)
869 return make_number (decode_live_window (window
)->hscroll
);
872 /* Set W's horizontal scroll amount to HSCROLL clipped to a reasonable
873 range, returning the new amount as a fixnum. */
875 set_window_hscroll (struct window
*w
, EMACS_INT hscroll
)
877 /* Horizontal scrolling has problems with large scroll amounts.
878 It's too slow with long lines, and even with small lines the
879 display can be messed up. For now, though, impose only the limits
880 required by the internal representation: horizontal scrolling must
881 fit in fixnum (since it's visible to Elisp) and into ptrdiff_t
882 (since it's stored in a ptrdiff_t). */
883 ptrdiff_t hscroll_max
= min (MOST_POSITIVE_FIXNUM
, PTRDIFF_MAX
);
884 ptrdiff_t new_hscroll
= clip_to_bounds (0, hscroll
, hscroll_max
);
886 /* Prevent redisplay shortcuts when changing the hscroll. */
887 if (w
->hscroll
!= new_hscroll
)
888 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
890 w
->hscroll
= new_hscroll
;
891 return make_number (new_hscroll
);
894 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
895 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
896 WINDOW must be a live window and defaults to the selected one.
897 Clip the number to a reasonable value if out of range.
898 Return the new number. NCOL should be zero or positive.
900 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
901 window so that the location of point moves off-window. */)
902 (Lisp_Object window
, Lisp_Object ncol
)
905 return set_window_hscroll (decode_live_window (window
), XINT (ncol
));
908 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
909 Swindow_redisplay_end_trigger
, 0, 1, 0,
910 doc
: /* Return WINDOW's redisplay end trigger value.
911 WINDOW must be a live window and defaults to the selected one.
912 See `set-window-redisplay-end-trigger' for more information. */)
915 return decode_live_window (window
)->redisplay_end_trigger
;
918 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
919 Sset_window_redisplay_end_trigger
, 2, 2, 0,
920 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
921 WINDOW must be a live window and defaults to the selected one. VALUE
922 should be a buffer position (typically a marker) or nil. If it is a
923 buffer position, then if redisplay in WINDOW reaches a position beyond
924 VALUE, the functions in `redisplay-end-trigger-functions' are called
925 with two arguments: WINDOW, and the end trigger value. Afterwards the
926 end-trigger value is reset to nil. */)
927 (register Lisp_Object window
, Lisp_Object value
)
929 wset_redisplay_end_trigger (decode_live_window (window
), value
);
933 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
934 doc
: /* Return a list of the edge coordinates of WINDOW.
935 WINDOW must be a valid window and defaults to the selected one.
937 The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
938 count by lines, and LEFT and RIGHT count by columns, all relative to 0,
939 0 at top left corner of frame.
941 RIGHT is one more than the rightmost column occupied by WINDOW. BOTTOM
942 is one more than the bottommost row occupied by WINDOW. The edges
943 include the space used by WINDOW's scroll bar, display margins, fringes,
944 header line, and/or mode line. For the edges of just the text area, use
945 `window-inside-edges'. */)
948 register struct window
*w
= decode_valid_window (window
);
950 return list4i (WINDOW_LEFT_EDGE_COL (w
), WINDOW_TOP_EDGE_LINE (w
),
951 WINDOW_RIGHT_EDGE_COL (w
), WINDOW_BOTTOM_EDGE_LINE (w
));
954 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
955 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
956 WINDOW must be a valid window and defaults to the selected one.
958 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
959 0, 0 at the top left corner of the frame.
961 RIGHT is one more than the rightmost x position occupied by WINDOW.
962 BOTTOM is one more than the bottommost y position occupied by WINDOW.
963 The pixel edges include the space used by WINDOW's scroll bar, display
964 margins, fringes, header line, and/or mode line. For the pixel edges
965 of just the text area, use `window-inside-pixel-edges'. */)
968 register struct window
*w
= decode_valid_window (window
);
970 return list4i (WINDOW_LEFT_EDGE_X (w
), WINDOW_TOP_EDGE_Y (w
),
971 WINDOW_RIGHT_EDGE_X (w
), WINDOW_BOTTOM_EDGE_Y (w
));
975 calc_absolute_offset (struct window
*w
, int *add_x
, int *add_y
)
977 struct frame
*f
= XFRAME (w
->frame
);
979 #ifdef FRAME_MENUBAR_HEIGHT
980 *add_y
+= FRAME_MENUBAR_HEIGHT (f
);
982 #ifdef FRAME_TOOLBAR_TOP_HEIGHT
983 *add_y
+= FRAME_TOOLBAR_TOP_HEIGHT (f
);
984 #elif FRAME_TOOLBAR_HEIGHT
985 *add_y
+= FRAME_TOOLBAR_HEIGHT (f
);
987 #ifdef FRAME_NS_TITLEBAR_HEIGHT
988 *add_y
+= FRAME_NS_TITLEBAR_HEIGHT (f
);
990 *add_x
= f
->left_pos
;
991 #ifdef FRAME_TOOLBAR_LEFT_WIDTH
992 *add_x
+= FRAME_TOOLBAR_LEFT_WIDTH (f
);
996 DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges
,
997 Swindow_absolute_pixel_edges
, 0, 1, 0,
998 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
999 WINDOW must be a valid window and defaults to the selected one.
1001 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1002 0, 0 at the top left corner of the display.
1004 RIGHT is one more than the rightmost x position occupied by WINDOW.
1005 BOTTOM is one more than the bottommost y position occupied by WINDOW.
1006 The pixel edges include the space used by WINDOW's scroll bar, display
1007 margins, fringes, header line, and/or mode line. For the pixel edges
1008 of just the text area, use `window-inside-absolute-pixel-edges'. */)
1009 (Lisp_Object window
)
1011 register struct window
*w
= decode_valid_window (window
);
1014 calc_absolute_offset (w
, &add_x
, &add_y
);
1016 return list4i (WINDOW_LEFT_EDGE_X (w
) + add_x
,
1017 WINDOW_TOP_EDGE_Y (w
) + add_y
,
1018 WINDOW_RIGHT_EDGE_X (w
) + add_x
,
1019 WINDOW_BOTTOM_EDGE_Y (w
) + add_y
);
1022 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
1023 doc
: /* Return a list of the edge coordinates of WINDOW.
1024 WINDOW must be a live window and defaults to the selected one.
1026 The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
1027 count by lines, and LEFT and RIGHT count by columns, all relative to 0,
1028 0 at top left corner of frame.
1030 RIGHT is one more than the rightmost column of WINDOW's text area.
1031 BOTTOM is one more than the bottommost row of WINDOW's text area. The
1032 inside edges do not include the space used by the WINDOW's scroll bar,
1033 display margins, fringes, header line, and/or mode line. */)
1034 (Lisp_Object window
)
1036 register struct window
*w
= decode_live_window (window
);
1038 return list4i ((WINDOW_BOX_LEFT_EDGE_COL (w
)
1039 + WINDOW_LEFT_MARGIN_COLS (w
)
1040 + WINDOW_LEFT_FRINGE_COLS (w
)),
1041 (WINDOW_TOP_EDGE_LINE (w
)
1042 + WINDOW_HEADER_LINE_LINES (w
)),
1043 (WINDOW_BOX_RIGHT_EDGE_COL (w
)
1044 - WINDOW_RIGHT_MARGIN_COLS (w
)
1045 - WINDOW_RIGHT_FRINGE_COLS (w
)),
1046 (WINDOW_BOTTOM_EDGE_LINE (w
)
1047 - WINDOW_MODE_LINE_LINES (w
)));
1050 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
1051 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1052 WINDOW must be a live window and defaults to the selected one.
1054 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1055 (0,0) at the top left corner of the frame's window area.
1057 RIGHT is one more than the rightmost x position of WINDOW's text area.
1058 BOTTOM is one more than the bottommost y position of WINDOW's text area.
1059 The inside edges do not include the space used by WINDOW's scroll bar,
1060 display margins, fringes, header line, and/or mode line. */)
1061 (Lisp_Object window
)
1063 register struct window
*w
= decode_live_window (window
);
1065 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w
)
1066 + WINDOW_LEFT_MARGIN_WIDTH (w
)
1067 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
1068 (WINDOW_TOP_EDGE_Y (w
)
1069 + WINDOW_HEADER_LINE_HEIGHT (w
)),
1070 (WINDOW_BOX_RIGHT_EDGE_X (w
)
1071 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
1072 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
1073 (WINDOW_BOTTOM_EDGE_Y (w
)
1074 - WINDOW_MODE_LINE_HEIGHT (w
)));
1077 DEFUN ("window-inside-absolute-pixel-edges",
1078 Fwindow_inside_absolute_pixel_edges
,
1079 Swindow_inside_absolute_pixel_edges
, 0, 1, 0,
1080 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1081 WINDOW must be a live window and defaults to the selected one.
1083 The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1084 (0,0) at the top left corner of the frame's window area.
1086 RIGHT is one more than the rightmost x position of WINDOW's text area.
1087 BOTTOM is one more than the bottommost y position of WINDOW's text area.
1088 The inside edges do not include the space used by WINDOW's scroll bar,
1089 display margins, fringes, header line, and/or mode line. */)
1090 (Lisp_Object window
)
1092 register struct window
*w
= decode_live_window (window
);
1095 calc_absolute_offset (w
, &add_x
, &add_y
);
1097 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w
)
1098 + WINDOW_LEFT_MARGIN_WIDTH (w
)
1099 + WINDOW_LEFT_FRINGE_WIDTH (w
) + add_x
),
1100 (WINDOW_TOP_EDGE_Y (w
)
1101 + WINDOW_HEADER_LINE_HEIGHT (w
) + add_y
),
1102 (WINDOW_BOX_RIGHT_EDGE_X (w
)
1103 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
1104 - WINDOW_RIGHT_FRINGE_WIDTH (w
) + add_x
),
1105 (WINDOW_BOTTOM_EDGE_Y (w
)
1106 - WINDOW_MODE_LINE_HEIGHT (w
) + add_y
));
1109 /* Test if the character at column X, row Y is within window W.
1110 If it is not, return ON_NOTHING;
1111 if it is in the window's text area, return ON_TEXT;
1112 if it is on the window's modeline, return ON_MODE_LINE;
1113 if it is on the border between the window and its right sibling,
1114 return ON_VERTICAL_BORDER.
1115 if it is on a scroll bar, return ON_SCROLL_BAR.
1116 if it is on the window's top line, return ON_HEADER_LINE;
1117 if it is in left or right fringe of the window,
1118 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
1119 if it is in the marginal area to the left/right of the window,
1120 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN.
1122 X and Y are frame relative pixel coordinates. */
1124 static enum window_part
1125 coordinates_in_window (register struct window
*w
, int x
, int y
)
1127 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1128 enum window_part part
;
1129 int ux
= FRAME_COLUMN_WIDTH (f
);
1130 int left_x
= WINDOW_LEFT_EDGE_X (w
);
1131 int right_x
= WINDOW_RIGHT_EDGE_X (w
);
1132 int top_y
= WINDOW_TOP_EDGE_Y (w
);
1133 int bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
1134 /* The width of the area where the vertical line can be dragged.
1135 (Between mode lines for instance. */
1136 int grabbable_width
= ux
;
1137 int lmargin_width
, rmargin_width
, text_left
, text_right
;
1139 /* Outside any interesting row or column? */
1140 if (y
< top_y
|| y
>= bottom_y
|| x
< left_x
|| x
>= right_x
)
1143 /* On the mode line or header line? */
1144 if ((WINDOW_WANTS_MODELINE_P (w
)
1145 && y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
)
1146 && (part
= ON_MODE_LINE
))
1147 || (WINDOW_WANTS_HEADER_LINE_P (w
)
1148 && y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
)
1149 && (part
= ON_HEADER_LINE
)))
1151 /* If it's under/over the scroll bar portion of the mode/header
1152 line, say it's on the vertical line. That's to be able to
1153 resize windows horizontally in case we're using toolkit scroll
1154 bars. Note: If scrollbars are on the left, the window that
1155 must be eventually resized is that on the left of WINDOW. */
1156 if ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1157 && !WINDOW_LEFTMOST_P (w
)
1158 && eabs (x
- left_x
) < grabbable_width
)
1159 || (!WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1160 && !WINDOW_RIGHTMOST_P (w
)
1161 && eabs (x
- right_x
) < grabbable_width
))
1162 return ON_VERTICAL_BORDER
;
1167 /* In what's below, we subtract 1 when computing right_x because we
1168 want the rightmost pixel, which is given by left_pixel+width-1. */
1169 if (w
->pseudo_window_p
)
1172 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
1176 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
1177 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
1180 /* Outside any interesting column? */
1181 if (x
< left_x
|| x
> right_x
)
1182 return ON_SCROLL_BAR
;
1184 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
1185 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
1187 text_left
= window_box_left (w
, TEXT_AREA
);
1188 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
1190 if (FRAME_WINDOW_P (f
))
1192 if (!w
->pseudo_window_p
1193 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
1194 && !WINDOW_RIGHTMOST_P (w
)
1195 && (eabs (x
- right_x
) < grabbable_width
))
1196 return ON_VERTICAL_BORDER
;
1198 /* Need to say "x > right_x" rather than >=, since on character
1199 terminals, the vertical line's x coordinate is right_x. */
1200 else if (!w
->pseudo_window_p
1201 && !WINDOW_RIGHTMOST_P (w
)
1202 && x
> right_x
- ux
)
1203 return ON_VERTICAL_BORDER
;
1207 if (lmargin_width
> 0
1208 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1209 ? (x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
1210 : (x
< left_x
+ lmargin_width
)))
1211 return ON_LEFT_MARGIN
;
1213 return ON_LEFT_FRINGE
;
1216 if (x
>= text_right
)
1218 if (rmargin_width
> 0
1219 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1220 ? (x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
1221 : (x
>= right_x
- rmargin_width
)))
1222 return ON_RIGHT_MARGIN
;
1224 return ON_RIGHT_FRINGE
;
1227 /* Everything special ruled out - must be on text area */
1231 /* Take X is the frame-relative pixel x-coordinate, and return the
1232 x-coordinate relative to part PART of window W. */
1234 window_relative_x_coord (struct window
*w
, enum window_part part
, int x
)
1236 int left_x
= (w
->pseudo_window_p
) ? 0 : WINDOW_BOX_LEFT_EDGE_X (w
);
1241 return x
- window_box_left (w
, TEXT_AREA
);
1243 case ON_LEFT_FRINGE
:
1246 case ON_RIGHT_FRINGE
:
1247 return x
- left_x
- WINDOW_LEFT_FRINGE_WIDTH (w
);
1249 case ON_LEFT_MARGIN
:
1251 - ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1252 ? WINDOW_LEFT_FRINGE_WIDTH (w
) : 0));
1254 case ON_RIGHT_MARGIN
:
1256 - ((w
->pseudo_window_p
)
1257 ? WINDOW_TOTAL_WIDTH (w
)
1258 : WINDOW_BOX_RIGHT_EDGE_X (w
))
1259 + window_box_width (w
, RIGHT_MARGIN_AREA
)
1260 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1261 ? WINDOW_RIGHT_FRINGE_WIDTH (w
) : 0));
1264 /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */
1269 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
1270 Scoordinates_in_window_p
, 2, 2, 0,
1271 doc
: /* Return non-nil if COORDINATES are in WINDOW.
1272 WINDOW must be a live window and defaults to the selected one.
1273 COORDINATES is a cons of the form (X . Y), X and Y being distances
1274 measured in characters from the upper-left corner of the frame.
1275 \(0 . 0) denotes the character in the upper left corner of the
1277 If COORDINATES are in the text portion of WINDOW,
1278 the coordinates relative to the window are returned.
1279 If they are in the mode line of WINDOW, `mode-line' is returned.
1280 If they are in the top mode line of WINDOW, `header-line' is returned.
1281 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1282 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1283 If they are on the border between WINDOW and its right sibling,
1284 `vertical-line' is returned.
1285 If they are in the windows's left or right marginal areas, `left-margin'\n\
1286 or `right-margin' is returned. */)
1287 (register Lisp_Object coordinates
, Lisp_Object window
)
1294 w
= decode_live_window (window
);
1295 f
= XFRAME (w
->frame
);
1296 CHECK_CONS (coordinates
);
1297 lx
= Fcar (coordinates
);
1298 ly
= Fcdr (coordinates
);
1299 CHECK_NUMBER_OR_FLOAT (lx
);
1300 CHECK_NUMBER_OR_FLOAT (ly
);
1301 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1302 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1304 switch (coordinates_in_window (w
, x
, y
))
1310 /* Convert X and Y to window relative pixel coordinates, and
1311 return the canonical char units. */
1312 x
-= window_box_left (w
, TEXT_AREA
);
1313 y
-= WINDOW_TOP_EDGE_Y (w
);
1314 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
1315 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
1320 case ON_VERTICAL_BORDER
:
1321 return Qvertical_line
;
1323 case ON_HEADER_LINE
:
1324 return Qheader_line
;
1326 case ON_LEFT_FRINGE
:
1327 return Qleft_fringe
;
1329 case ON_RIGHT_FRINGE
:
1330 return Qright_fringe
;
1332 case ON_LEFT_MARGIN
:
1333 return Qleft_margin
;
1335 case ON_RIGHT_MARGIN
:
1336 return Qright_margin
;
1339 /* Historically we are supposed to return nil in this case. */
1348 /* Callback for foreach_window, used in window_from_coordinates.
1349 Check if window W contains coordinates specified by USER_DATA which
1350 is actually a pointer to a struct check_window_data CW.
1352 Check if window W contains coordinates *CW->x and *CW->y. If it
1353 does, return W in *CW->window, as Lisp_Object, and return in
1354 *CW->part the part of the window under coordinates *X,*Y. Return
1355 zero from this function to stop iterating over windows. */
1357 struct check_window_data
1359 Lisp_Object
*window
;
1361 enum window_part
*part
;
1365 check_window_containing (struct window
*w
, void *user_data
)
1367 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
1368 enum window_part found
;
1371 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1372 if (found
!= ON_NOTHING
)
1375 XSETWINDOW (*cw
->window
, w
);
1383 /* Find the window containing frame-relative pixel position X/Y and
1384 return it as a Lisp_Object.
1386 If X, Y is on one of the window's special `window_part' elements,
1387 set *PART to the id of that element.
1389 If there is no window under X, Y return nil and leave *PART
1390 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1392 This function was previously implemented with a loop cycling over
1393 windows with Fnext_window, and starting with the frame's selected
1394 window. It turned out that this doesn't work with an
1395 implementation of next_window using Vwindow_list, because
1396 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1397 tree of F when this function is called asynchronously from
1398 note_mouse_highlight. The original loop didn't terminate in this
1402 window_from_coordinates (struct frame
*f
, int x
, int y
,
1403 enum window_part
*part
, bool tool_bar_p
)
1406 struct check_window_data cw
;
1407 enum window_part dummy
;
1413 cw
.window
= &window
, cw
.x
= x
, cw
.y
= y
; cw
.part
= part
;
1414 foreach_window (f
, check_window_containing
, &cw
);
1416 /* If not found above, see if it's in the tool bar window, if a tool
1420 && WINDOWP (f
->tool_bar_window
)
1421 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1422 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), x
, y
)
1426 window
= f
->tool_bar_window
;
1432 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1433 doc
: /* Return window containing coordinates X and Y on FRAME.
1434 FRAME must be a live frame and defaults to the selected one.
1435 The top left corner of the frame is considered to be row 0,
1437 (Lisp_Object x
, Lisp_Object y
, Lisp_Object frame
)
1439 struct frame
*f
= decode_live_frame (frame
);
1441 /* Check that arguments are integers or floats. */
1442 CHECK_NUMBER_OR_FLOAT (x
);
1443 CHECK_NUMBER_OR_FLOAT (y
);
1445 return window_from_coordinates (f
,
1446 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1447 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1448 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1449 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1453 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1454 doc
: /* Return current value of point in WINDOW.
1455 WINDOW must be a live window and defaults to the selected one.
1457 For a nonselected window, this is the value point would have if that
1458 window were selected.
1460 Note that, when WINDOW is selected, the value returned is the same as
1461 that returned by `point' for WINDOW's buffer. It would be more strictly
1462 correct to return the top-level value of `point', outside of any
1463 `save-excursion' forms. But that is hard to define. */)
1464 (Lisp_Object window
)
1466 register struct window
*w
= decode_live_window (window
);
1468 if (w
== XWINDOW (selected_window
))
1469 return make_number (BUF_PT (XBUFFER (w
->contents
)));
1471 return Fmarker_position (w
->pointm
);
1474 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1475 doc
: /* Return position at which display currently starts in WINDOW.
1476 WINDOW must be a live window and defaults to the selected one.
1477 This is updated by redisplay or by calling `set-window-start'. */)
1478 (Lisp_Object window
)
1480 return Fmarker_position (decode_live_window (window
)->start
);
1483 /* This is text temporarily removed from the doc string below.
1485 This function returns nil if the position is not currently known.
1486 That happens when redisplay is preempted and doesn't finish.
1487 If in that case you want to compute where the end of the window would
1488 have been if redisplay had finished, do this:
1490 (goto-char (window-start window))
1491 (vertical-motion (1- (window-height window)) window)
1494 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1495 doc
: /* Return position at which display currently ends in WINDOW.
1496 WINDOW must be a live window and defaults to the selected one.
1497 This is updated by redisplay, when it runs to completion.
1498 Simply changing the buffer text or setting `window-start'
1499 does not update this value.
1500 Return nil if there is no recorded value. (This can happen if the
1501 last redisplay of WINDOW was preempted, and did not finish.)
1502 If UPDATE is non-nil, compute the up-to-date position
1503 if it isn't already recorded. */)
1504 (Lisp_Object window
, Lisp_Object update
)
1507 struct window
*w
= decode_live_window (window
);
1516 && (windows_or_buffers_changed
1517 || !w
->window_end_valid
1519 || b
->prevent_redisplay_optimizations_p
1520 || window_outdated (w
))
1523 struct text_pos startp
;
1524 ptrdiff_t charpos
= marker_position (w
->start
);
1526 struct buffer
*old_buffer
= NULL
;
1527 void *itdata
= NULL
;
1529 /* Cannot use Fvertical_motion because that function doesn't
1530 cope with variable-height lines. */
1531 if (b
!= current_buffer
)
1533 old_buffer
= current_buffer
;
1534 set_buffer_internal (b
);
1537 /* In case W->start is out of the range, use something
1538 reasonable. This situation occurred when loading a file with
1539 `-l' containing a call to `rmail' with subsequent other
1540 commands. At the end, W->start happened to be BEG, while
1541 rmail had already narrowed the buffer. */
1543 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1544 else if (charpos
> ZV
)
1545 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1547 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1549 itdata
= bidi_shelve_cache ();
1550 start_display (&it
, w
, startp
);
1551 move_it_vertically (&it
, window_box_height (w
));
1552 if (it
.current_y
< it
.last_visible_y
)
1553 move_it_past_eol (&it
);
1554 value
= make_number (IT_CHARPOS (it
));
1555 bidi_unshelve_cache (itdata
, 0);
1558 set_buffer_internal (old_buffer
);
1561 XSETINT (value
, BUF_Z (b
) - XFASTINT (w
->window_end_pos
));
1566 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1567 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1568 WINDOW must be a live window and defaults to the selected one.
1570 (Lisp_Object window
, Lisp_Object pos
)
1572 register struct window
*w
= decode_live_window (window
);
1574 /* Type of POS is checked by Fgoto_char or set_marker_restricted ... */
1576 if (w
== XWINDOW (selected_window
))
1578 if (XBUFFER (w
->contents
) == current_buffer
)
1582 struct buffer
*old_buffer
= current_buffer
;
1584 /* ... but here we want to catch type error before buffer change. */
1585 CHECK_NUMBER_COERCE_MARKER (pos
);
1586 set_buffer_internal (XBUFFER (w
->contents
));
1588 set_buffer_internal (old_buffer
);
1593 set_marker_restricted (w
->pointm
, pos
, w
->contents
);
1594 /* We have to make sure that redisplay updates the window to show
1595 the new value of point. */
1596 ++windows_or_buffers_changed
;
1602 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1603 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1604 WINDOW must be a live window and defaults to the selected one. Return
1605 POS. Optional third arg NOFORCE non-nil inhibits next redisplay from
1606 overriding motion of point in order to display at this exact start. */)
1607 (Lisp_Object window
, Lisp_Object pos
, Lisp_Object noforce
)
1609 register struct window
*w
= decode_live_window (window
);
1611 set_marker_restricted (w
->start
, pos
, w
->contents
);
1612 /* This is not right, but much easier than doing what is right. */
1613 w
->start_at_line_beg
= 0;
1616 w
->update_mode_line
= 1;
1617 if (!EQ (window
, selected_window
))
1618 /* Enforce full redisplay. FIXME: make it more selective. */
1619 windows_or_buffers_changed
++;
1624 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
1625 Spos_visible_in_window_p
, 0, 3, 0,
1626 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
1627 WINDOW must be a live window and defaults to the selected one.
1629 Return nil if that position is scrolled vertically out of view. If a
1630 character is only partially visible, nil is returned, unless the
1631 optional argument PARTIALLY is non-nil. If POS is only out of view
1632 because of horizontal scrolling, return non-nil. If POS is t, it
1633 specifies the position of the last visible glyph in WINDOW. POS
1634 defaults to point in WINDOW; WINDOW defaults to the selected window.
1636 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1637 the return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
1638 where X and Y are the pixel coordinates relative to the top left corner
1639 of the window. The remaining elements are omitted if the character after
1640 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1641 off-window at the top and bottom of the screen line ("row") containing
1642 POS, ROWH is the visible height of that row, and VPOS is the row number
1644 (Lisp_Object pos
, Lisp_Object window
, Lisp_Object partially
)
1646 register struct window
*w
;
1647 register EMACS_INT posint
;
1648 register struct buffer
*buf
;
1649 struct text_pos top
;
1650 Lisp_Object in_window
= Qnil
;
1651 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
1654 w
= decode_live_window (window
);
1655 buf
= XBUFFER (w
->contents
);
1656 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1660 else if (!NILP (pos
))
1662 CHECK_NUMBER_COERCE_MARKER (pos
);
1663 posint
= XINT (pos
);
1665 else if (w
== XWINDOW (selected_window
))
1668 posint
= marker_position (w
->pointm
);
1670 /* If position is above window start or outside buffer boundaries,
1671 or if window start is out of range, position is not visible. */
1673 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
1674 && CHARPOS (top
) >= BUF_BEGV (buf
)
1675 && CHARPOS (top
) <= BUF_ZV (buf
)
1676 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
1677 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
1680 if (!NILP (in_window
) && !NILP (partially
))
1682 Lisp_Object part
= Qnil
;
1684 part
= list4i (rtop
, rbot
, rowh
, vpos
);
1685 in_window
= Fcons (make_number (x
),
1686 Fcons (make_number (y
), part
));
1692 DEFUN ("window-line-height", Fwindow_line_height
,
1693 Swindow_line_height
, 0, 2, 0,
1694 doc
: /* Return height in pixels of text line LINE in window WINDOW.
1695 WINDOW must be a live window and defaults to the selected one.
1697 Return height of current line if LINE is omitted or nil. Return height of
1698 header or mode line if LINE is `header-line' or `mode-line'.
1699 Otherwise, LINE is a text line number starting from 0. A negative number
1700 counts from the end of the window.
1702 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
1703 in pixels of the visible part of the line, VPOS and YPOS are the
1704 vertical position in lines and pixels of the line, relative to the top
1705 of the first text line, and OFFBOT is the number of off-window pixels at
1706 the bottom of the text line. If there are off-window pixels at the top
1707 of the (first) text line, YPOS is negative.
1709 Return nil if window display is not up-to-date. In that case, use
1710 `pos-visible-in-window-p' to obtain the information. */)
1711 (Lisp_Object line
, Lisp_Object window
)
1713 register struct window
*w
;
1714 register struct buffer
*b
;
1715 struct glyph_row
*row
, *end_row
;
1719 w
= decode_live_window (window
);
1721 if (noninteractive
|| w
->pseudo_window_p
)
1724 CHECK_BUFFER (w
->contents
);
1725 b
= XBUFFER (w
->contents
);
1727 /* Fail if current matrix is not up-to-date. */
1728 if (!w
->window_end_valid
1729 || windows_or_buffers_changed
1731 || b
->prevent_redisplay_optimizations_p
1732 || window_outdated (w
))
1738 if (i
< 0 || i
>= w
->current_matrix
->nrows
1739 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
1741 max_y
= window_text_bottom_y (w
);
1745 if (EQ (line
, Qheader_line
))
1747 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
1749 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
1750 return row
->enabled_p
? list4i (row
->height
, 0, 0, 0) : Qnil
;
1753 if (EQ (line
, Qmode_line
))
1755 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
1756 return (row
->enabled_p
?
1757 list4i (row
->height
,
1758 0, /* not accurate */
1759 (WINDOW_HEADER_LINE_HEIGHT (w
)
1760 + window_text_bottom_y (w
)),
1765 CHECK_NUMBER (line
);
1768 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1769 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1770 max_y
= window_text_bottom_y (w
);
1773 while ((n
< 0 || i
< n
)
1774 && row
<= end_row
&& row
->enabled_p
1775 && row
->y
+ row
->height
< max_y
)
1778 if (row
> end_row
|| !row
->enabled_p
)
1790 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
1791 return list4i (row
->height
+ min (0, row
->y
) - crop
, i
, row
->y
, crop
);
1794 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1796 doc
: /* Return non-nil when WINDOW is dedicated to its buffer.
1797 More precisely, return the value assigned by the last call of
1798 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1799 never called with WINDOW as its argument, or the value set by that
1800 function was internally reset since its last call. WINDOW must be a
1801 live window and defaults to the selected one.
1803 When a window is dedicated to its buffer, `display-buffer' will refrain
1804 from displaying another buffer in it. `get-lru-window' and
1805 `get-largest-window' treat dedicated windows specially.
1806 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1807 `kill-buffer' can delete a dedicated window and the containing frame.
1809 Functions like `set-window-buffer' may change the buffer displayed by a
1810 window, unless that window is "strongly" dedicated to its buffer, that
1811 is the value returned by `window-dedicated-p' is t. */)
1812 (Lisp_Object window
)
1814 return decode_live_window (window
)->dedicated
;
1817 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1818 Sset_window_dedicated_p
, 2, 2, 0,
1819 doc
: /* Mark WINDOW as dedicated according to FLAG.
1820 WINDOW must be a live window and defaults to the selected one. FLAG
1821 non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means
1822 mark WINDOW as non-dedicated. Return FLAG.
1824 When a window is dedicated to its buffer, `display-buffer' will refrain
1825 from displaying another buffer in it. `get-lru-window' and
1826 `get-largest-window' treat dedicated windows specially.
1827 `delete-windows-on', `replace-buffer-in-windows', `quit-window',
1828 `quit-restore-window' and `kill-buffer' can delete a dedicated window
1829 and the containing frame.
1831 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
1832 its buffer. Functions like `set-window-buffer' may change the buffer
1833 displayed by a window, unless that window is strongly dedicated to its
1834 buffer. If and when `set-window-buffer' displays another buffer in a
1835 window, it also makes sure that the window is no more dedicated. */)
1836 (Lisp_Object window
, Lisp_Object flag
)
1838 wset_dedicated (decode_live_window (window
), flag
);
1842 DEFUN ("window-prev-buffers", Fwindow_prev_buffers
, Swindow_prev_buffers
,
1844 doc
: /* Return buffers previously shown in WINDOW.
1845 WINDOW must be a live window and defaults to the selected one.
1847 The return value is a list of elements (BUFFER WINDOW-START POS),
1848 where BUFFER is a buffer, WINDOW-START is the start position of the
1849 window for that buffer, and POS is a window-specific point value. */)
1850 (Lisp_Object window
)
1852 return decode_live_window (window
)->prev_buffers
;
1855 DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers
,
1856 Sset_window_prev_buffers
, 2, 2, 0,
1857 doc
: /* Set WINDOW's previous buffers to PREV-BUFFERS.
1858 WINDOW must be a live window and defaults to the selected one.
1860 PREV-BUFFERS should be a list of elements (BUFFER WINDOW-START POS),
1861 where BUFFER is a buffer, WINDOW-START is the start position of the
1862 window for that buffer, and POS is a window-specific point value. */)
1863 (Lisp_Object window
, Lisp_Object prev_buffers
)
1865 wset_prev_buffers (decode_live_window (window
), prev_buffers
);
1866 return prev_buffers
;
1869 DEFUN ("window-next-buffers", Fwindow_next_buffers
, Swindow_next_buffers
,
1871 doc
: /* Return list of buffers recently re-shown in WINDOW.
1872 WINDOW must be a live window and defaults to the selected one. */)
1873 (Lisp_Object window
)
1875 return decode_live_window (window
)->next_buffers
;
1878 DEFUN ("set-window-next-buffers", Fset_window_next_buffers
,
1879 Sset_window_next_buffers
, 2, 2, 0,
1880 doc
: /* Set WINDOW's next buffers to NEXT-BUFFERS.
1881 WINDOW must be a live window and defaults to the selected one.
1882 NEXT-BUFFERS should be a list of buffers. */)
1883 (Lisp_Object window
, Lisp_Object next_buffers
)
1885 wset_next_buffers (decode_live_window (window
), next_buffers
);
1886 return next_buffers
;
1889 DEFUN ("window-parameters", Fwindow_parameters
, Swindow_parameters
,
1891 doc
: /* Return the parameters of WINDOW and their values.
1892 WINDOW must be a valid window and defaults to the selected one. The
1893 return value is a list of elements of the form (PARAMETER . VALUE). */)
1894 (Lisp_Object window
)
1896 return Fcopy_alist (decode_valid_window (window
)->window_parameters
);
1899 DEFUN ("window-parameter", Fwindow_parameter
, Swindow_parameter
,
1901 doc
: /* Return WINDOW's value for PARAMETER.
1902 WINDOW can be any window and defaults to the selected one. */)
1903 (Lisp_Object window
, Lisp_Object parameter
)
1907 result
= Fassq (parameter
, decode_any_window (window
)->window_parameters
);
1908 return CDR_SAFE (result
);
1911 DEFUN ("set-window-parameter", Fset_window_parameter
,
1912 Sset_window_parameter
, 3, 3, 0,
1913 doc
: /* Set WINDOW's value of PARAMETER to VALUE.
1914 WINDOW can be any window and defaults to the selected one.
1916 (Lisp_Object window
, Lisp_Object parameter
, Lisp_Object value
)
1918 register struct window
*w
= decode_any_window (window
);
1919 Lisp_Object old_alist_elt
;
1921 old_alist_elt
= Fassq (parameter
, w
->window_parameters
);
1922 if (NILP (old_alist_elt
))
1923 wset_window_parameters
1924 (w
, Fcons (Fcons (parameter
, value
), w
->window_parameters
));
1926 Fsetcdr (old_alist_elt
, value
);
1930 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1932 doc
: /* Return the display-table that WINDOW is using.
1933 WINDOW must be a live window and defaults to the selected one. */)
1934 (Lisp_Object window
)
1936 return decode_live_window (window
)->display_table
;
1939 /* Get the display table for use on window W. This is either W's
1940 display table or W's buffer's display table. Ignore the specified
1941 tables if they are not valid; if no valid table is specified,
1944 struct Lisp_Char_Table
*
1945 window_display_table (struct window
*w
)
1947 struct Lisp_Char_Table
*dp
= NULL
;
1949 if (DISP_TABLE_P (w
->display_table
))
1950 dp
= XCHAR_TABLE (w
->display_table
);
1951 else if (BUFFERP (w
->contents
))
1953 struct buffer
*b
= XBUFFER (w
->contents
);
1955 if (DISP_TABLE_P (BVAR (b
, display_table
)))
1956 dp
= XCHAR_TABLE (BVAR (b
, display_table
));
1957 else if (DISP_TABLE_P (Vstandard_display_table
))
1958 dp
= XCHAR_TABLE (Vstandard_display_table
);
1964 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1965 doc
: /* Set WINDOW's display-table to TABLE.
1966 WINDOW must be a live window and defaults to the selected one. */)
1967 (register Lisp_Object window
, Lisp_Object table
)
1969 wset_display_table (decode_live_window (window
), table
);
1973 /* Record info on buffer window W is displaying
1974 when it is about to cease to display that buffer. */
1976 unshow_buffer (register struct window
*w
)
1978 Lisp_Object buf
= w
->contents
;
1979 struct buffer
*b
= XBUFFER (buf
);
1981 eassert (b
== XMARKER (w
->pointm
)->buffer
);
1984 if (w
== XWINDOW (selected_window
)
1985 || ! EQ (buf
, XWINDOW (selected_window
)->contents
))
1986 /* Do this except when the selected window's buffer
1987 is being removed from some other window. */
1989 /* last_window_start records the start position that this buffer
1990 had in the last window to be disconnected from it.
1991 Now that this statement is unconditional,
1992 it is possible for the buffer to be displayed in the
1993 selected window, while last_window_start reflects another
1994 window which was recently showing the same buffer.
1995 Some people might say that might be a good thing. Let's see. */
1996 b
->last_window_start
= marker_position (w
->start
);
1998 /* Point in the selected window's buffer
1999 is actually stored in that buffer, and the window's pointm isn't used.
2000 So don't clobber point in that buffer. */
2001 if (! EQ (buf
, XWINDOW (selected_window
)->contents
)
2002 /* Don't clobber point in current buffer either (this could be
2003 useful in connection with bug#12208).
2004 && XBUFFER (buf) != current_buffer */
2005 /* This line helps to fix Horsley's testbug.el bug. */
2006 && !(WINDOWP (BVAR (b
, last_selected_window
))
2007 && w
!= XWINDOW (BVAR (b
, last_selected_window
))
2008 && EQ (buf
, XWINDOW (BVAR (b
, last_selected_window
))->contents
)))
2009 temp_set_point_both (b
,
2010 clip_to_bounds (BUF_BEGV (b
),
2011 marker_position (w
->pointm
),
2013 clip_to_bounds (BUF_BEGV_BYTE (b
),
2014 marker_byte_position (w
->pointm
),
2017 if (WINDOWP (BVAR (b
, last_selected_window
))
2018 && w
== XWINDOW (BVAR (b
, last_selected_window
)))
2019 bset_last_selected_window (b
, Qnil
);
2022 /* Put NEW into the window structure in place of OLD. SETFLAG zero
2023 means change window structure only. Otherwise store geometry and
2024 other settings as well. */
2026 replace_window (Lisp_Object old
, Lisp_Object
new, int setflag
)
2028 register Lisp_Object tem
;
2029 register struct window
*o
= XWINDOW (old
), *n
= XWINDOW (new);
2031 /* If OLD is its frame's root window, then NEW is the new
2032 root window for that frame. */
2033 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
2034 fset_root_window (XFRAME (o
->frame
), new);
2038 n
->left_col
= o
->left_col
;
2039 n
->top_line
= o
->top_line
;
2040 n
->total_cols
= o
->total_cols
;
2041 n
->total_lines
= o
->total_lines
;
2042 wset_normal_cols (n
, o
->normal_cols
);
2043 wset_normal_cols (o
, make_float (1.0));
2044 wset_normal_lines (n
, o
->normal_lines
);
2045 wset_normal_lines (o
, make_float (1.0));
2046 n
->desired_matrix
= n
->current_matrix
= 0;
2048 memset (&n
->cursor
, 0, sizeof (n
->cursor
));
2049 memset (&n
->last_cursor
, 0, sizeof (n
->last_cursor
));
2050 memset (&n
->phys_cursor
, 0, sizeof (n
->phys_cursor
));
2051 n
->phys_cursor_type
= -1;
2052 n
->phys_cursor_width
= -1;
2053 n
->must_be_updated_p
= 0;
2054 n
->pseudo_window_p
= 0;
2055 wset_window_end_vpos (n
, make_number (0));
2056 wset_window_end_pos (n
, make_number (0));
2057 n
->window_end_valid
= 0;
2058 n
->frozen_window_start_p
= 0;
2064 wset_prev (XWINDOW (tem
), new);
2069 wset_next (XWINDOW (tem
), new);
2072 wset_parent (n
, tem
);
2073 if (!NILP (tem
) && EQ (XWINDOW (tem
)->contents
, old
))
2074 wset_combination (XWINDOW (tem
), XWINDOW (tem
)->horizontal
, new);
2077 /* If window WINDOW and its parent window are iso-combined, merge
2078 WINDOW's children into those of its parent window and mark WINDOW as
2082 recombine_windows (Lisp_Object window
)
2084 struct window
*w
, *p
, *c
;
2085 Lisp_Object parent
, child
;
2088 w
= XWINDOW (window
);
2090 if (!NILP (parent
) && NILP (w
->combination_limit
))
2092 p
= XWINDOW (parent
);
2093 if (WINDOWP (p
->contents
) && WINDOWP (w
->contents
)
2094 && p
->horizontal
== w
->horizontal
)
2095 /* WINDOW and PARENT are both either a vertical or a horizontal
2098 horflag
= WINDOW_HORIZONTAL_COMBINATION_P (w
);
2099 child
= w
->contents
;
2100 c
= XWINDOW (child
);
2102 /* Splice WINDOW's children into its parent's children and
2103 assign new normal sizes. */
2105 wset_combination (p
, horflag
, child
);
2108 wset_prev (c
, w
->prev
);
2109 wset_next (XWINDOW (w
->prev
), child
);
2114 wset_parent (c
, parent
);
2117 wset_normal_cols (c
,
2118 make_float ((double) c
->total_cols
2119 / (double) p
->total_cols
));
2121 wset_normal_lines (c
,
2122 make_float ((double) c
->total_lines
2123 / (double) p
->total_lines
));
2127 if (!NILP (w
->next
))
2129 wset_next (c
, w
->next
);
2130 wset_prev (XWINDOW (c
->next
), child
);
2138 c
= XWINDOW (child
);
2142 /* WINDOW can be deleted now. */
2143 wset_combination (w
, 0, Qnil
);
2148 /* If WINDOW can be deleted, delete it. */
2150 delete_deletable_window (Lisp_Object window
)
2152 if (!NILP (call1 (Qwindow_deletable_p
, window
)))
2153 call1 (Qdelete_window
, window
);
2156 /***********************************************************************
2158 ***********************************************************************/
2160 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
2161 pointer. This is a callback function for foreach_window, used in
2162 the window_list function. */
2165 add_window_to_list (struct window
*w
, void *user_data
)
2167 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
2169 XSETWINDOW (window
, w
);
2170 *list
= Fcons (window
, *list
);
2175 /* Return a list of all windows, for use by next_window. If
2176 Vwindow_list is a list, return that list. Otherwise, build a new
2177 list, cache it in Vwindow_list, and return that. */
2182 if (!CONSP (Vwindow_list
))
2184 Lisp_Object tail
, frame
;
2186 Vwindow_list
= Qnil
;
2187 FOR_EACH_FRAME (tail
, frame
)
2189 Lisp_Object args
[2];
2191 /* We are visiting windows in canonical order, and add
2192 new windows at the front of args[1], which means we
2193 have to reverse this list at the end. */
2195 foreach_window (XFRAME (frame
), add_window_to_list
, &args
[1]);
2196 args
[0] = Vwindow_list
;
2197 args
[1] = Fnreverse (args
[1]);
2198 Vwindow_list
= Fnconc (2, args
);
2202 return Vwindow_list
;
2206 /* Value is non-zero if WINDOW satisfies the constraints given by
2207 OWINDOW, MINIBUF and ALL_FRAMES.
2209 MINIBUF t means WINDOW may be minibuffer windows.
2210 `lambda' means WINDOW may not be a minibuffer window.
2211 a window means a specific minibuffer window
2213 ALL_FRAMES t means search all frames,
2214 nil means search just current frame,
2215 `visible' means search just visible frames on the
2217 0 means search visible and iconified frames on the
2219 a window means search the frame that window belongs to,
2220 a frame means consider windows on that frame, only. */
2223 candidate_window_p (Lisp_Object window
, Lisp_Object owindow
,
2224 Lisp_Object minibuf
, Lisp_Object all_frames
)
2226 struct window
*w
= XWINDOW (window
);
2227 struct frame
*f
= XFRAME (w
->frame
);
2228 bool candidate_p
= 1;
2230 if (!BUFFERP (w
->contents
))
2232 else if (MINI_WINDOW_P (w
)
2233 && (EQ (minibuf
, Qlambda
)
2234 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
2236 /* If MINIBUF is `lambda' don't consider any mini-windows.
2237 If it is a window, consider only that one. */
2240 else if (EQ (all_frames
, Qt
))
2242 else if (NILP (all_frames
))
2244 eassert (WINDOWP (owindow
));
2245 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
2247 else if (EQ (all_frames
, Qvisible
))
2249 candidate_p
= FRAME_VISIBLE_P (f
)
2250 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2251 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2254 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
2256 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
2257 #ifdef HAVE_X_WINDOWS
2258 /* Yuck!! If we've just created the frame and the
2259 window-manager requested the user to place it
2260 manually, the window may still not be considered
2261 `visible'. I'd argue it should be at least
2262 something like `iconified', but don't know how to do
2264 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
2265 && !f
->output_data
.x
->has_been_visible
)
2268 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2269 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2271 else if (WINDOWP (all_frames
))
2272 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
2273 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
2274 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
2275 else if (FRAMEP (all_frames
))
2276 candidate_p
= EQ (all_frames
, w
->frame
);
2282 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2283 Fwindow_list. See candidate_window_p for the meaning of WINDOW,
2284 MINIBUF, and ALL_FRAMES. */
2287 decode_next_window_args (Lisp_Object
*window
, Lisp_Object
*minibuf
, Lisp_Object
*all_frames
)
2289 struct window
*w
= decode_live_window (*window
);
2291 XSETWINDOW (*window
, w
);
2292 /* MINIBUF nil may or may not include minibuffers. Decide if it
2294 if (NILP (*minibuf
))
2295 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
2296 else if (!EQ (*minibuf
, Qt
))
2299 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2300 => count none of them, or a specific minibuffer window (the
2301 active one) to count. */
2303 /* ALL_FRAMES nil doesn't specify which frames to include. */
2304 if (NILP (*all_frames
))
2306 = (!EQ (*minibuf
, Qlambda
)
2307 ? FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
))
2309 else if (EQ (*all_frames
, Qvisible
))
2311 else if (EQ (*all_frames
, make_number (0)))
2313 else if (FRAMEP (*all_frames
))
2315 else if (!EQ (*all_frames
, Qt
))
2320 /* Return the next or previous window of WINDOW in cyclic ordering
2321 of windows. NEXT_P non-zero means return the next window. See the
2322 documentation string of next-window for the meaning of MINIBUF and
2326 next_window (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
, int next_p
)
2328 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2330 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2331 return the first window on the frame. */
2332 if (FRAMEP (all_frames
)
2333 && !EQ (all_frames
, XWINDOW (window
)->frame
))
2334 return Fframe_first_window (all_frames
);
2340 /* Find WINDOW in the list of all windows. */
2341 list
= Fmemq (window
, window_list ());
2343 /* Scan forward from WINDOW to the end of the window list. */
2345 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
2346 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2349 /* Scan from the start of the window list up to WINDOW. */
2351 for (list
= Vwindow_list
;
2352 CONSP (list
) && !EQ (XCAR (list
), window
);
2354 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2358 window
= XCAR (list
);
2362 Lisp_Object candidate
, list
;
2364 /* Scan through the list of windows for candidates. If there are
2365 candidate windows in front of WINDOW, the last one of these
2366 is the one we want. If there are candidates following WINDOW
2367 in the list, again the last one of these is the one we want. */
2369 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
2371 if (EQ (XCAR (list
), window
))
2373 if (WINDOWP (candidate
))
2376 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
2378 candidate
= XCAR (list
);
2381 if (WINDOWP (candidate
))
2389 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
2390 doc
: /* Return live window after WINDOW in the cyclic ordering of windows.
2391 WINDOW must be a live window and defaults to the selected one. The
2392 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2395 MINIBUF nil or omitted means consider the minibuffer window only if the
2396 minibuffer is active. MINIBUF t means consider the minibuffer window
2397 even if the minibuffer is not active. Any other value means do not
2398 consider the minibuffer window even if the minibuffer is active.
2400 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2401 plus the minibuffer window if specified by the MINIBUF argument. If the
2402 minibuffer counts, consider all windows on all frames that share that
2403 minibuffer too. The following non-nil values of ALL-FRAMES have special
2406 - t means consider all windows on all existing frames.
2408 - `visible' means consider all windows on all visible frames.
2410 - 0 (the number zero) means consider all windows on all visible and
2413 - A frame means consider all windows on that frame only.
2415 Anything else means consider all windows on WINDOW's frame and no
2418 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2419 `next-window' to iterate through the entire cycle of acceptable
2420 windows, eventually ending up back at the window you started with.
2421 `previous-window' traverses the same cycle, in the reverse order. */)
2422 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2424 return next_window (window
, minibuf
, all_frames
, 1);
2428 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
2429 doc
: /* Return live window before WINDOW in the cyclic ordering of windows.
2430 WINDOW must be a live window and defaults to the selected one. The
2431 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2434 MINIBUF nil or omitted means consider the minibuffer window only if the
2435 minibuffer is active. MINIBUF t means consider the minibuffer window
2436 even if the minibuffer is not active. Any other value means do not
2437 consider the minibuffer window even if the minibuffer is active.
2439 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2440 plus the minibuffer window if specified by the MINIBUF argument. If the
2441 minibuffer counts, consider all windows on all frames that share that
2442 minibuffer too. The following non-nil values of ALL-FRAMES have special
2445 - t means consider all windows on all existing frames.
2447 - `visible' means consider all windows on all visible frames.
2449 - 0 (the number zero) means consider all windows on all visible and
2452 - A frame means consider all windows on that frame only.
2454 Anything else means consider all windows on WINDOW's frame and no
2457 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2458 use `previous-window' to iterate through the entire cycle of
2459 acceptable windows, eventually ending up back at the window you
2460 started with. `next-window' traverses the same cycle, in the
2462 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2464 return next_window (window
, minibuf
, all_frames
, 0);
2468 /* Return a list of windows in cyclic ordering. Arguments are like
2469 for `next-window'. */
2472 window_list_1 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2474 Lisp_Object tail
, list
, rest
;
2476 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2479 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2480 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2481 list
= Fcons (XCAR (tail
), list
);
2483 /* Rotate the list to start with WINDOW. */
2484 list
= Fnreverse (list
);
2485 rest
= Fmemq (window
, list
);
2486 if (!NILP (rest
) && !EQ (rest
, list
))
2488 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2490 XSETCDR (tail
, Qnil
);
2491 list
= nconc2 (rest
, list
);
2497 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2498 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2499 FRAME nil or omitted means use the selected frame.
2500 WINDOW nil or omitted means use the window selected within FRAME.
2501 MINIBUF t means include the minibuffer window, even if it isn't active.
2502 MINIBUF nil or omitted means include the minibuffer window only
2504 MINIBUF neither nil nor t means never include the minibuffer window. */)
2505 (Lisp_Object frame
, Lisp_Object minibuf
, Lisp_Object window
)
2508 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2509 CHECK_WINDOW (window
);
2511 frame
= selected_frame
;
2513 if (!EQ (frame
, XWINDOW (window
)->frame
))
2514 error ("Window is on a different frame");
2516 return window_list_1 (window
, minibuf
, frame
);
2520 DEFUN ("window-list-1", Fwindow_list_1
, Swindow_list_1
, 0, 3, 0,
2521 doc
: /* Return a list of all live windows.
2522 WINDOW specifies the first window to list and defaults to the selected
2525 Optional argument MINIBUF nil or omitted means consider the minibuffer
2526 window only if the minibuffer is active. MINIBUF t means consider the
2527 minibuffer window even if the minibuffer is not active. Any other value
2528 means do not consider the minibuffer window even if the minibuffer is
2531 Optional argument ALL-FRAMES nil or omitted means consider all windows
2532 on WINDOW's frame, plus the minibuffer window if specified by the
2533 MINIBUF argument. If the minibuffer counts, consider all windows on all
2534 frames that share that minibuffer too. The following non-nil values of
2535 ALL-FRAMES have special meanings:
2537 - t means consider all windows on all existing frames.
2539 - `visible' means consider all windows on all visible frames.
2541 - 0 (the number zero) means consider all windows on all visible and
2544 - A frame means consider all windows on that frame only.
2546 Anything else means consider all windows on WINDOW's frame and no
2549 If WINDOW is not on the list of windows returned, some other window will
2550 be listed first but no error is signaled. */)
2551 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2553 return window_list_1 (window
, minibuf
, all_frames
);
2556 /* Look at all windows, performing an operation specified by TYPE
2558 If FRAMES is Qt, look at all frames;
2559 Qnil, look at just the selected frame;
2560 Qvisible, look at visible frames;
2561 a frame, just look at windows on that frame.
2562 If MINI is non-zero, perform the operation on minibuffer windows too. */
2567 GET_BUFFER_WINDOW
, /* Arg is buffer */
2568 REPLACE_BUFFER_IN_WINDOWS_SAFELY
, /* Arg is buffer */
2569 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2570 CHECK_ALL_WINDOWS
/* Arg is ignored */
2574 window_loop (enum window_loop type
, Lisp_Object obj
, int mini
, Lisp_Object frames
)
2576 Lisp_Object window
, windows
, best_window
, frame_arg
;
2577 int frame_best_window_flag
= 0;
2579 struct gcpro gcpro1
;
2581 /* If we're only looping through windows on a particular frame,
2582 frame points to that frame. If we're looping through windows
2583 on all frames, frame is 0. */
2584 if (FRAMEP (frames
))
2585 f
= XFRAME (frames
);
2586 else if (NILP (frames
))
2587 f
= SELECTED_FRAME ();
2592 frame_arg
= Qlambda
;
2593 else if (EQ (frames
, make_number (0)))
2595 else if (EQ (frames
, Qvisible
))
2600 /* frame_arg is Qlambda to stick to one frame,
2601 Qvisible to consider all visible frames,
2604 /* Pick a window to start with. */
2608 window
= FRAME_SELECTED_WINDOW (f
);
2610 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2612 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2616 for (; CONSP (windows
); windows
= XCDR (windows
))
2620 window
= XCAR (windows
);
2621 w
= XWINDOW (window
);
2623 /* Note that we do not pay attention here to whether the frame
2624 is visible, since Fwindow_list skips non-visible frames if
2625 that is desired, under the control of frame_arg. */
2626 if (!MINI_WINDOW_P (w
)
2627 /* For REPLACE_BUFFER_IN_WINDOWS_SAFELY, we must always
2628 consider all windows. */
2629 || type
== REPLACE_BUFFER_IN_WINDOWS_SAFELY
2630 || (mini
&& minibuf_level
> 0))
2633 case GET_BUFFER_WINDOW
:
2634 if (EQ (w
->contents
, obj
)
2635 /* Don't find any minibuffer window except the one that
2636 is currently in use. */
2637 && (MINI_WINDOW_P (w
) ? EQ (window
, minibuf_window
) : 1))
2639 if (EQ (window
, selected_window
))
2640 /* Preferably return the selected window. */
2641 RETURN_UNGCPRO (window
);
2642 else if (EQ (XWINDOW (window
)->frame
, selected_frame
)
2643 && !frame_best_window_flag
)
2644 /* Prefer windows on the current frame (but don't
2645 choose another one if we have one already). */
2647 best_window
= window
;
2648 frame_best_window_flag
= 1;
2650 else if (NILP (best_window
))
2651 best_window
= window
;
2655 case REPLACE_BUFFER_IN_WINDOWS_SAFELY
:
2656 /* We could simply check whether the buffer shown by window
2657 is live, and show another buffer in case it isn't. */
2658 if (EQ (w
->contents
, obj
))
2660 /* Undedicate WINDOW. */
2661 wset_dedicated (w
, Qnil
);
2662 /* Make WINDOW show the buffer returned by
2663 other_buffer_safely, don't run any hooks. */
2665 (window
, other_buffer_safely (w
->contents
), 0, 0);
2666 /* If WINDOW is the selected window, make its buffer
2667 current. But do so only if the window shows the
2668 current buffer (Bug#6454). */
2669 if (EQ (window
, selected_window
)
2670 && XBUFFER (w
->contents
) == current_buffer
)
2671 Fset_buffer (w
->contents
);
2675 case REDISPLAY_BUFFER_WINDOWS
:
2676 if (EQ (w
->contents
, obj
))
2678 mark_window_display_accurate (window
, 0);
2679 w
->update_mode_line
= 1;
2680 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2681 ++update_mode_lines
;
2682 best_window
= window
;
2686 /* Check for a leaf window that has a killed buffer
2687 or broken markers. */
2688 case CHECK_ALL_WINDOWS
:
2689 if (BUFFERP (w
->contents
))
2691 struct buffer
*b
= XBUFFER (w
->contents
);
2693 if (!BUFFER_LIVE_P (b
))
2695 if (!MARKERP (w
->start
) || XMARKER (w
->start
)->buffer
!= b
)
2697 if (!MARKERP (w
->pointm
) || XMARKER (w
->pointm
)->buffer
!= b
)
2702 case WINDOW_LOOP_UNUSED
:
2711 /* Used for debugging. Abort if any window has a dead buffer. */
2713 extern void check_all_windows (void) EXTERNALLY_VISIBLE
;
2715 check_all_windows (void)
2717 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2720 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 0, 2, 0,
2721 doc
: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2722 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to
2725 The optional argument ALL-FRAMES specifies the frames to consider:
2727 - t means consider all windows on all existing frames.
2729 - `visible' means consider all windows on all visible frames.
2731 - 0 (the number zero) means consider all windows on all visible
2732 and iconified frames.
2734 - A frame means consider all windows on that frame only.
2736 Any other value of ALL-FRAMES means consider all windows on the
2737 selected frame and no others. */)
2738 (Lisp_Object buffer_or_name
, Lisp_Object all_frames
)
2742 if (NILP (buffer_or_name
))
2743 buffer
= Fcurrent_buffer ();
2745 buffer
= Fget_buffer (buffer_or_name
);
2747 if (BUFFERP (buffer
))
2748 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, all_frames
);
2754 resize_root_window (Lisp_Object window
, Lisp_Object delta
, Lisp_Object horizontal
, Lisp_Object ignore
)
2756 return call4 (Qwindow_resize_root_window
, window
, delta
, horizontal
, ignore
);
2760 DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal
,
2761 Sdelete_other_windows_internal
, 0, 2, "",
2762 doc
: /* Make WINDOW fill its frame.
2763 Only the frame WINDOW is on is affected. WINDOW must be a valid window
2764 and defaults to the selected one.
2766 Optional argument ROOT, if non-nil, must specify an internal window such
2767 that WINDOW is in its window subtree. If this is the case, replace ROOT
2768 by WINDOW and leave alone any windows not part of ROOT's subtree.
2770 When WINDOW is live try to reduce display jumps by keeping the text
2771 previously visible in WINDOW in the same place on the frame. Doing this
2772 depends on the value of (window-start WINDOW), so if calling this
2773 function in a program gives strange scrolling, make sure the
2774 window-start value is reasonable when this function is called. */)
2775 (Lisp_Object window
, Lisp_Object root
)
2777 struct window
*w
, *r
, *s
;
2779 Lisp_Object sibling
, pwindow
, swindow
IF_LINT (= Qnil
), delta
;
2780 ptrdiff_t startpos
IF_LINT (= 0), startbyte
IF_LINT (= 0);
2781 int top
IF_LINT (= 0), new_top
, resize_failed
;
2783 w
= decode_valid_window (window
);
2784 XSETWINDOW (window
, w
);
2785 f
= XFRAME (w
->frame
);
2788 /* ROOT is the frame's root window. */
2790 root
= FRAME_ROOT_WINDOW (f
);
2794 /* ROOT must be an ancestor of WINDOW. */
2796 r
= decode_valid_window (root
);
2797 pwindow
= XWINDOW (window
)->parent
;
2798 while (!NILP (pwindow
))
2799 if (EQ (pwindow
, root
))
2802 pwindow
= XWINDOW (pwindow
)->parent
;
2803 if (!EQ (pwindow
, root
))
2804 error ("Specified root is not an ancestor of specified window");
2807 if (EQ (window
, root
))
2810 /* I don't understand the "top > 0" part below. If we deal with a
2811 standalone minibuffer it would have been caught by the preceding
2813 else if (MINI_WINDOW_P (w
)) /* && top > 0) */
2814 error ("Can't expand minibuffer to full frame");
2816 if (BUFFERP (w
->contents
))
2818 startpos
= marker_position (w
->start
);
2819 startbyte
= marker_byte_position (w
->start
);
2820 top
= WINDOW_TOP_EDGE_LINE (w
)
2821 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2822 /* Make sure WINDOW is the frame's selected window. */
2823 if (!EQ (window
, FRAME_SELECTED_WINDOW (f
)))
2825 if (EQ (selected_frame
, w
->frame
))
2826 Fselect_window (window
, Qnil
);
2828 fset_selected_window (f
, window
);
2833 /* See if the frame's selected window is a part of the window
2834 subtree rooted at WINDOW, by finding all the selected window's
2835 parents and comparing each one with WINDOW. If it isn't we
2836 need a new selected window for this frame. */
2837 swindow
= FRAME_SELECTED_WINDOW (f
);
2841 while (!NILP (pwindow
) && !EQ (window
, pwindow
))
2842 pwindow
= XWINDOW (pwindow
)->parent
;
2844 if (EQ (window
, pwindow
))
2845 /* If WINDOW is an ancestor of SWINDOW, then SWINDOW is ok
2846 as the new selected window. */
2849 /* Else try the previous window of SWINDOW. */
2850 swindow
= Fprevious_window (swindow
, Qlambda
, Qnil
);
2853 if (!EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
2855 if (EQ (selected_frame
, w
->frame
))
2856 Fselect_window (swindow
, Qnil
);
2858 fset_selected_window (f
, swindow
);
2863 if (!FRAME_INITIAL_P (f
))
2865 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
2867 /* We are going to free the glyph matrices of WINDOW, and with
2868 that we might lose any information about glyph rows that have
2869 some of their glyphs highlighted in mouse face. (These rows
2870 are marked with a non-zero mouse_face_p flag.) If WINDOW
2871 indeed has some glyphs highlighted in mouse face, signal to
2872 frame's up-to-date hook that mouse highlight was overwritten,
2873 so that it will arrange for redisplaying the highlight. */
2874 if (EQ (hlinfo
->mouse_face_window
, window
))
2876 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
2877 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
2878 hlinfo
->mouse_face_window
= Qnil
;
2881 free_window_matrices (r
);
2883 windows_or_buffers_changed
++;
2884 Vwindow_list
= Qnil
;
2885 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
2888 if (!WINDOW_LEAF_P (w
))
2890 /* Resize child windows vertically. */
2891 XSETINT (delta
, r
->total_lines
- w
->total_lines
);
2892 w
->top_line
= r
->top_line
;
2893 resize_root_window (window
, delta
, Qnil
, Qnil
);
2894 if (window_resize_check (w
, 0))
2895 window_resize_apply (w
, 0);
2898 resize_root_window (window
, delta
, Qnil
, Qt
);
2899 if (window_resize_check (w
, 0))
2900 window_resize_apply (w
, 0);
2905 /* Resize child windows horizontally. */
2908 w
->left_col
= r
->left_col
;
2909 XSETINT (delta
, r
->total_cols
- w
->total_cols
);
2910 resize_root_window (window
, delta
, Qt
, Qnil
);
2911 if (window_resize_check (w
, 1))
2912 window_resize_apply (w
, 1);
2915 resize_root_window (window
, delta
, Qt
, Qt
);
2916 if (window_resize_check (w
, 1))
2917 window_resize_apply (w
, 1);
2924 /* Play safe, if we still can ... */
2927 w
= XWINDOW (window
);
2931 /* Cleanly unlink WINDOW from window-tree. */
2932 if (!NILP (w
->prev
))
2933 /* Get SIBLING above (on the left of) WINDOW. */
2936 s
= XWINDOW (sibling
);
2937 wset_next (s
, w
->next
);
2938 if (!NILP (s
->next
))
2939 wset_prev (XWINDOW (s
->next
), sibling
);
2942 /* Get SIBLING below (on the right of) WINDOW. */
2945 s
= XWINDOW (sibling
);
2946 wset_prev (s
, Qnil
);
2947 wset_combination (XWINDOW (w
->parent
),
2948 XWINDOW (w
->parent
)->horizontal
, sibling
);
2951 /* Delete ROOT and all child windows of ROOT. */
2952 if (WINDOWP (r
->contents
))
2954 delete_all_child_windows (r
->contents
);
2955 wset_combination (r
, 0, Qnil
);
2958 replace_window (root
, window
, 1);
2960 /* This must become SWINDOW anyway ....... */
2961 if (BUFFERP (w
->contents
) && !resize_failed
)
2963 /* Try to minimize scrolling, by setting the window start to the
2964 point will cause the text at the old window start to be at the
2965 same place on the frame. But don't try to do this if the
2966 window start is outside the visible portion (as might happen
2967 when the display is not current, due to typeahead). */
2968 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2970 && startpos
>= BUF_BEGV (XBUFFER (w
->contents
))
2971 && startpos
<= BUF_ZV (XBUFFER (w
->contents
)))
2973 struct position pos
;
2974 struct buffer
*obuf
= current_buffer
;
2976 Fset_buffer (w
->contents
);
2977 /* This computation used to temporarily move point, but that
2978 can have unwanted side effects due to text properties. */
2979 pos
= *vmotion (startpos
, startbyte
, -top
, w
);
2981 set_marker_both (w
->start
, w
->contents
, pos
.bufpos
, pos
.bytepos
);
2982 w
->window_end_valid
= 0;
2983 w
->start_at_line_beg
= (pos
.bytepos
== BEGV_BYTE
2984 || FETCH_BYTE (pos
.bytepos
- 1) == '\n');
2985 /* We need to do this, so that the window-scroll-functions
2987 w
->optional_new_start
= 1;
2989 set_buffer_internal (obuf
);
2996 run_window_configuration_change_hook (f
);
3003 replace_buffer_in_windows (Lisp_Object buffer
)
3005 call1 (Qreplace_buffer_in_windows
, buffer
);
3008 /* If BUFFER is shown in a window, safely replace it with some other
3009 buffer in all windows of all frames, even those on other keyboards. */
3012 replace_buffer_in_windows_safely (Lisp_Object buffer
)
3014 if (buffer_window_count (XBUFFER (buffer
)))
3016 Lisp_Object tail
, frame
;
3018 /* A single call to window_loop won't do the job because it only
3019 considers frames on the current keyboard. So loop manually over
3020 frames, and handle each one. */
3021 FOR_EACH_FRAME (tail
, frame
)
3022 window_loop (REPLACE_BUFFER_IN_WINDOWS_SAFELY
, buffer
, 1, frame
);
3026 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
3027 minimum allowable size. */
3030 check_frame_size (struct frame
*frame
, int *rows
, int *cols
)
3032 /* For height, we have to see:
3033 how many windows the frame has at minimum (one or two),
3034 and whether it has a menu bar or other special stuff at the top. */
3036 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
3037 ? MIN_SAFE_WINDOW_HEIGHT
3038 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
3040 if (FRAME_TOP_MARGIN (frame
) > 0)
3041 min_height
+= FRAME_TOP_MARGIN (frame
);
3043 if (*rows
< min_height
)
3045 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
3046 *cols
= MIN_SAFE_WINDOW_WIDTH
;
3049 /* Adjust the margins of window W if text area is too small.
3050 Return 1 if window width is ok after adjustment; 0 if window
3051 is still too narrow. */
3054 adjust_window_margins (struct window
*w
)
3056 int box_cols
= (WINDOW_TOTAL_COLS (w
)
3057 - WINDOW_FRINGE_COLS (w
)
3058 - WINDOW_SCROLL_BAR_COLS (w
));
3059 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
3060 + WINDOW_RIGHT_MARGIN_COLS (w
));
3062 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
3065 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
3068 /* Window's text area is too narrow, but reducing the window
3069 margins will fix that. */
3070 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
3071 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
3073 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
3075 wset_left_margin_cols (w
, make_number (margin_cols
/ 2));
3076 wset_right_margin_cols (w
, make_number (margin_cols
/ 2));
3079 wset_right_margin_cols (w
, make_number (margin_cols
));
3082 wset_left_margin_cols (w
, make_number (margin_cols
));
3086 /* The following three routines are needed for running a window's
3087 configuration change hook. */
3089 run_funs (Lisp_Object funs
)
3091 for (; CONSP (funs
); funs
= XCDR (funs
))
3092 if (!EQ (XCAR (funs
), Qt
))
3093 call0 (XCAR (funs
));
3097 select_window_norecord (Lisp_Object window
)
3099 if (WINDOW_LIVE_P (window
))
3100 Fselect_window (window
, Qt
);
3104 select_frame_norecord (Lisp_Object frame
)
3106 if (FRAME_LIVE_P (XFRAME (frame
)))
3107 Fselect_frame (frame
, Qt
);
3111 run_window_configuration_change_hook (struct frame
*f
)
3113 ptrdiff_t count
= SPECPDL_INDEX ();
3114 Lisp_Object frame
, global_wcch
3115 = Fdefault_value (Qwindow_configuration_change_hook
);
3116 XSETFRAME (frame
, f
);
3118 if (NILP (Vrun_hooks
) || !NILP (inhibit_lisp_code
))
3121 /* Use the right buffer. Matters when running the local hooks. */
3122 if (current_buffer
!= XBUFFER (Fwindow_buffer (Qnil
)))
3124 record_unwind_current_buffer ();
3125 Fset_buffer (Fwindow_buffer (Qnil
));
3128 if (SELECTED_FRAME () != f
)
3130 record_unwind_protect (select_frame_norecord
, selected_frame
);
3131 select_frame_norecord (frame
);
3134 /* Look for buffer-local values. */
3136 Lisp_Object windows
= Fwindow_list (frame
, Qlambda
, Qnil
);
3137 for (; CONSP (windows
); windows
= XCDR (windows
))
3139 Lisp_Object window
= XCAR (windows
);
3140 Lisp_Object buffer
= Fwindow_buffer (window
);
3141 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook
,
3144 ptrdiff_t inner_count
= SPECPDL_INDEX ();
3145 record_unwind_protect (select_window_norecord
, selected_window
);
3146 select_window_norecord (window
);
3147 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook
,
3149 unbind_to (inner_count
, Qnil
);
3154 run_funs (global_wcch
);
3155 unbind_to (count
, Qnil
);
3158 DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook
,
3159 Srun_window_configuration_change_hook
, 0, 1, 0,
3160 doc
: /* Run `window-configuration-change-hook' for FRAME.
3161 If FRAME is omitted or nil, it defaults to the selected frame. */)
3164 run_window_configuration_change_hook (decode_live_frame (frame
));
3168 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
3169 means it's allowed to run hooks. See make_frame for a case where
3170 it's not allowed. KEEP_MARGINS_P non-zero means that the current
3171 margins, fringes, and scroll-bar settings of the window are not
3172 reset from the buffer's local settings. */
3175 set_window_buffer (Lisp_Object window
, Lisp_Object buffer
,
3176 bool run_hooks_p
, bool keep_margins_p
)
3178 struct window
*w
= XWINDOW (window
);
3179 struct buffer
*b
= XBUFFER (buffer
);
3180 ptrdiff_t count
= SPECPDL_INDEX ();
3181 int samebuf
= EQ (buffer
, w
->contents
);
3183 wset_buffer (w
, buffer
);
3185 if (EQ (window
, selected_window
))
3186 bset_last_selected_window (b
, window
);
3188 /* Let redisplay errors through. */
3189 b
->display_error_modiff
= 0;
3191 /* Update time stamps of buffer display. */
3192 if (INTEGERP (BVAR (b
, display_count
)))
3193 bset_display_count (b
, make_number (XINT (BVAR (b
, display_count
)) + 1));
3194 bset_display_time (b
, Fcurrent_time ());
3196 wset_window_end_pos (w
, make_number (0));
3197 wset_window_end_vpos (w
, make_number (0));
3198 memset (&w
->last_cursor
, 0, sizeof w
->last_cursor
);
3200 if (!(keep_margins_p
&& samebuf
))
3201 { /* If we're not actually changing the buffer, don't reset hscroll and
3202 vscroll. This case happens for example when called from
3203 change_frame_size_1, where we use a dummy call to
3204 Fset_window_buffer on the frame's selected window (and no other)
3205 just in order to run window-configuration-change-hook.
3206 Resetting hscroll and vscroll here is problematic for things like
3207 image-mode and doc-view-mode since it resets the image's position
3208 whenever we resize the frame. */
3209 w
->hscroll
= w
->min_hscroll
= 0;
3211 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3212 set_marker_restricted (w
->start
,
3213 make_number (b
->last_window_start
),
3215 w
->start_at_line_beg
= 0;
3218 /* Maybe we could move this into the `if' but it's not obviously safe and
3219 I doubt it's worth the trouble. */
3220 windows_or_buffers_changed
++;
3222 /* We must select BUFFER for running the window-scroll-functions. */
3223 /* We can't check ! NILP (Vwindow_scroll_functions) here
3224 because that might itself be a local variable. */
3225 if (window_initialized
)
3227 record_unwind_current_buffer ();
3228 Fset_buffer (buffer
);
3231 XMARKER (w
->pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3233 if (!keep_margins_p
)
3235 /* Set left and right marginal area width etc. from buffer. */
3237 /* This may call adjust_window_margins three times, so
3238 temporarily disable window margins. */
3239 Lisp_Object save_left
= w
->left_margin_cols
;
3240 Lisp_Object save_right
= w
->right_margin_cols
;
3242 wset_left_margin_cols (w
, Qnil
);
3243 wset_right_margin_cols (w
, Qnil
);
3245 Fset_window_fringes (window
,
3246 BVAR (b
, left_fringe_width
), BVAR (b
, right_fringe_width
),
3247 BVAR (b
, fringes_outside_margins
));
3249 Fset_window_scroll_bars (window
,
3250 BVAR (b
, scroll_bar_width
),
3251 BVAR (b
, vertical_scroll_bar_type
), Qnil
);
3253 wset_left_margin_cols (w
, save_left
);
3254 wset_right_margin_cols (w
, save_right
);
3256 Fset_window_margins (window
,
3257 BVAR (b
, left_margin_cols
), BVAR (b
, right_margin_cols
));
3262 if (! NILP (Vwindow_scroll_functions
))
3263 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3264 Fmarker_position (w
->start
));
3265 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w
)));
3268 unbind_to (count
, Qnil
);
3271 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3272 doc
: /* Make WINDOW display BUFFER-OR-NAME as its contents.
3273 WINDOW must be a live window and defaults to the selected one.
3274 BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
3276 Optional third argument KEEP-MARGINS non-nil means that WINDOW's current
3277 display margins, fringe widths, and scroll bar settings are preserved;
3278 the default is to reset these from the local settings for BUFFER-OR-NAME
3279 or the frame defaults. Return nil.
3281 This function throws an error when WINDOW is strongly dedicated to its
3282 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3283 already display BUFFER-OR-NAME.
3285 This function runs `window-scroll-functions' before running
3286 `window-configuration-change-hook'. */)
3287 (register Lisp_Object window
, Lisp_Object buffer_or_name
, Lisp_Object keep_margins
)
3289 register Lisp_Object tem
, buffer
;
3290 register struct window
*w
= decode_live_window (window
);
3292 XSETWINDOW (window
, w
);
3293 buffer
= Fget_buffer (buffer_or_name
);
3294 CHECK_BUFFER (buffer
);
3295 if (!BUFFER_LIVE_P (XBUFFER (buffer
)))
3296 error ("Attempt to display deleted buffer");
3300 error ("Window is deleted");
3303 if (!EQ (tem
, buffer
))
3305 if (EQ (w
->dedicated
, Qt
))
3306 /* WINDOW is strongly dedicated to its buffer, signal an
3308 error ("Window is dedicated to `%s'", SDATA (BVAR (XBUFFER (tem
), name
)));
3310 /* WINDOW is weakly dedicated to its buffer, reset
3312 wset_dedicated (w
, Qnil
);
3314 call1 (Qrecord_window_buffer
, window
);
3320 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3326 display_buffer (Lisp_Object buffer
, Lisp_Object not_this_window_p
, Lisp_Object override_frame
)
3328 return call3 (Qdisplay_buffer
, buffer
, not_this_window_p
, override_frame
);
3331 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3333 doc
: /* Force all windows to be updated on next redisplay.
3334 If optional arg OBJECT is a window, force redisplay of that window only.
3335 If OBJECT is a buffer or buffer name, force redisplay of all windows
3336 displaying that buffer. */)
3337 (Lisp_Object object
)
3341 windows_or_buffers_changed
++;
3342 update_mode_lines
++;
3346 if (WINDOWP (object
))
3348 struct window
*w
= XWINDOW (object
);
3349 mark_window_display_accurate (object
, 0);
3350 w
->update_mode_line
= 1;
3351 if (BUFFERP (w
->contents
))
3352 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
3353 ++update_mode_lines
;
3357 if (STRINGP (object
))
3358 object
= Fget_buffer (object
);
3359 if (BUFFERP (object
) && BUFFER_LIVE_P (XBUFFER (object
))
3360 && buffer_window_count (XBUFFER (object
)))
3362 /* If buffer is live and shown in at least one window, find
3363 all windows showing this buffer and force update of them. */
3364 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3365 return NILP (object
) ? Qnil
: Qt
;
3368 /* If nothing suitable was found, just return.
3369 We could signal an error, but this feature will typically be used
3370 asynchronously in timers or process sentinels, so we don't. */
3374 /* Obsolete since 24.3. */
3376 temp_output_buffer_show (register Lisp_Object buf
)
3378 register struct buffer
*old
= current_buffer
;
3379 register Lisp_Object window
;
3380 register struct window
*w
;
3382 bset_directory (XBUFFER (buf
), BVAR (current_buffer
, directory
));
3385 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3389 set_buffer_internal (old
);
3391 if (!NILP (Vtemp_buffer_show_function
))
3392 call1 (Vtemp_buffer_show_function
, buf
);
3395 window
= display_buffer (buf
, Qnil
, Qnil
);
3397 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3398 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3399 Vminibuf_scroll_window
= window
;
3400 w
= XWINDOW (window
);
3403 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3404 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3406 /* Run temp-buffer-show-hook, with the chosen window selected
3407 and its buffer current. */
3409 ptrdiff_t count
= SPECPDL_INDEX ();
3410 Lisp_Object prev_window
, prev_buffer
;
3411 prev_window
= selected_window
;
3412 XSETBUFFER (prev_buffer
, old
);
3414 /* Select the window that was chosen, for running the hook.
3415 Note: Both Fselect_window and select_window_norecord may
3416 set-buffer to the buffer displayed in the window,
3417 so we need to save the current buffer. --stef */
3418 record_unwind_protect (restore_buffer
, prev_buffer
);
3419 record_unwind_protect (select_window_norecord
, prev_window
);
3420 Fselect_window (window
, Qt
);
3421 Fset_buffer (w
->contents
);
3422 Frun_hooks (1, &Qtemp_buffer_show_hook
);
3423 unbind_to (count
, Qnil
);
3428 /* Make new window, have it replace WINDOW in window-tree, and make
3429 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
3430 horizontal child). */
3432 make_parent_window (Lisp_Object window
, bool horflag
)
3435 register struct window
*o
, *p
;
3437 o
= XWINDOW (window
);
3438 p
= allocate_window ();
3439 memcpy ((char *) p
+ sizeof (struct vectorlike_header
),
3440 (char *) o
+ sizeof (struct vectorlike_header
),
3441 word_size
* VECSIZE (struct window
));
3442 /* P's buffer slot may change from nil to a buffer... */
3443 adjust_window_count (p
, 1);
3444 XSETWINDOW (parent
, p
);
3446 replace_window (window
, parent
, 1);
3448 wset_next (o
, Qnil
);
3449 wset_prev (o
, Qnil
);
3450 wset_parent (o
, parent
);
3451 /* ...but now P becomes an internal window. */
3452 wset_start (p
, Qnil
);
3453 wset_pointm (p
, Qnil
);
3454 wset_buffer (p
, Qnil
);
3455 wset_combination (p
, horflag
, window
);
3456 wset_combination_limit (p
, Qnil
);
3457 wset_window_parameters (p
, Qnil
);
3460 /* Make new window from scratch. */
3465 register struct window
*w
;
3467 w
= allocate_window ();
3468 /* Initialize Lisp data. Note that allocate_window initializes all
3469 Lisp data to nil, so do it only for slots which should not be nil. */
3470 wset_normal_lines (w
, make_float (1.0));
3471 wset_normal_cols (w
, make_float (1.0));
3472 wset_new_total (w
, make_number (0));
3473 wset_new_normal (w
, make_number (0));
3474 wset_start (w
, Fmake_marker ());
3475 wset_pointm (w
, Fmake_marker ());
3476 wset_vertical_scroll_bar_type (w
, Qt
);
3477 wset_window_end_pos (w
, make_number (0));
3478 wset_window_end_vpos (w
, make_number (0));
3479 /* These Lisp fields are marked specially so they're not set to nil by
3481 wset_prev_buffers (w
, Qnil
);
3482 wset_next_buffers (w
, Qnil
);
3484 /* Initialize non-Lisp data. Note that allocate_window zeroes out all
3485 non-Lisp data, so do it only for slots which should not be zero. */
3486 w
->nrows_scale_factor
= w
->ncols_scale_factor
= 1;
3487 w
->phys_cursor_type
= -1;
3488 w
->phys_cursor_width
= -1;
3489 w
->column_number_displayed
= -1;
3491 /* Reset window_list. */
3492 Vwindow_list
= Qnil
;
3493 /* Return window. */
3494 XSETWINDOW (window
, w
);
3498 DEFUN ("set-window-new-total", Fset_window_new_total
, Sset_window_new_total
, 2, 3, 0,
3499 doc
: /* Set new total size of WINDOW to SIZE.
3500 WINDOW must be a valid window and defaults to the selected one.
3503 Optional argument ADD non-nil means add SIZE to the new total size of
3504 WINDOW and return the sum.
3506 Note: This function does not operate on any child windows of WINDOW. */)
3507 (Lisp_Object window
, Lisp_Object size
, Lisp_Object add
)
3509 struct window
*w
= decode_valid_window (window
);
3511 CHECK_NUMBER (size
);
3513 wset_new_total (w
, size
);
3515 wset_new_total (w
, make_number (XINT (w
->new_total
) + XINT (size
)));
3517 return w
->new_total
;
3520 DEFUN ("set-window-new-normal", Fset_window_new_normal
, Sset_window_new_normal
, 1, 2, 0,
3521 doc
: /* Set new normal size of WINDOW to SIZE.
3522 WINDOW must be a valid window and defaults to the selected one.
3525 Note: This function does not operate on any child windows of WINDOW. */)
3526 (Lisp_Object window
, Lisp_Object size
)
3528 wset_new_normal (decode_valid_window (window
), size
);
3532 /* Return 1 if setting w->total_lines (w->total_cols if HORFLAG is
3533 non-zero) to w->new_total would result in correct heights (widths)
3534 for window W and recursively all child windows of W.
3536 Note: This function does not check any of `window-fixed-size-p',
3537 `window-min-height' or `window-min-width'. It does check that window
3538 sizes do not drop below one line (two columns). */
3540 window_resize_check (struct window
*w
, bool horflag
)
3544 if (WINDOW_VERTICAL_COMBINATION_P (w
))
3545 /* W is a vertical combination. */
3547 c
= XWINDOW (w
->contents
);
3549 /* All child windows of W must have the same width as W. */
3553 if ((XINT (c
->new_total
) != XINT (w
->new_total
))
3554 || !window_resize_check (c
, horflag
))
3556 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3561 /* The sum of the heights of the child windows of W must equal
3564 int sum_of_sizes
= 0;
3567 if (!window_resize_check (c
, horflag
))
3569 sum_of_sizes
= sum_of_sizes
+ XINT (c
->new_total
);
3570 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3572 return (sum_of_sizes
== XINT (w
->new_total
));
3575 else if (WINDOW_HORIZONTAL_COMBINATION_P (w
))
3576 /* W is a horizontal combination. */
3578 c
= XWINDOW (w
->contents
);
3580 /* The sum of the widths of the child windows of W must equal W's
3583 int sum_of_sizes
= 0;
3586 if (!window_resize_check (c
, horflag
))
3588 sum_of_sizes
= sum_of_sizes
+ XINT (c
->new_total
);
3589 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3591 return (sum_of_sizes
== XINT (w
->new_total
));
3594 /* All child windows of W must have the same height as W. */
3598 if ((XINT (c
->new_total
) != XINT (w
->new_total
))
3599 || !window_resize_check (c
, horflag
))
3601 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3607 /* A leaf window. Make sure it's not too small. The following
3608 hardcodes the values of `window-safe-min-width' (2) and
3609 `window-safe-min-height' (1) which are defined in window.el. */
3610 return XINT (w
->new_total
) >= (horflag
? 2 : 1);
3613 /* Set w->total_lines (w->total_cols if HORIZONTAL is non-zero) to
3614 w->new_total for window W and recursively all child windows of W.
3615 Also calculate and assign the new vertical (horizontal) start
3616 positions of each of these windows.
3618 This function does not perform any error checks. Make sure you have
3619 run window_resize_check on W before applying this function. */
3621 window_resize_apply (struct window
*w
, bool horflag
)
3626 /* Note: Assigning new_normal requires that the new total size of the
3627 parent window has been set *before*. */
3630 w
->total_cols
= XFASTINT (w
->new_total
);
3631 if (NUMBERP (w
->new_normal
))
3632 wset_normal_cols (w
, w
->new_normal
);
3638 w
->total_lines
= XFASTINT (w
->new_total
);
3639 if (NUMBERP (w
->new_normal
))
3640 wset_normal_lines (w
, w
->new_normal
);
3645 if (WINDOW_VERTICAL_COMBINATION_P (w
))
3646 /* W is a vertical combination. */
3648 c
= XWINDOW (w
->contents
);
3655 window_resize_apply (c
, horflag
);
3657 pos
= pos
+ c
->total_lines
;
3658 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3661 else if (WINDOW_HORIZONTAL_COMBINATION_P (w
))
3662 /* W is a horizontal combination. */
3664 c
= XWINDOW (w
->contents
);
3671 window_resize_apply (c
, horflag
);
3673 pos
= pos
+ c
->total_cols
;
3674 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3680 DEFUN ("window-resize-apply", Fwindow_resize_apply
, Swindow_resize_apply
, 0, 2, 0,
3681 doc
: /* Apply requested size values for window-tree of FRAME.
3682 If FRAME is omitted or nil, it defaults to the selected frame.
3684 Optional argument HORIZONTAL omitted or nil means apply requested
3685 height values. HORIZONTAL non-nil means apply requested width values.
3687 This function checks whether the requested values sum up to a valid
3688 window layout, recursively assigns the new sizes of all child windows
3689 and calculates and assigns the new start positions of these windows.
3691 Note: This function does not check any of `window-fixed-size-p',
3692 `window-min-height' or `window-min-width'. All these checks have to
3693 be applied on the Elisp level. */)
3694 (Lisp_Object frame
, Lisp_Object horizontal
)
3696 struct frame
*f
= decode_live_frame (frame
);
3697 struct window
*r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3698 bool horflag
= !NILP (horizontal
);
3700 if (!window_resize_check (r
, horflag
)
3701 || (XINT (r
->new_total
)
3702 != (horflag
? r
->total_cols
: r
->total_lines
)))
3706 window_resize_apply (r
, horflag
);
3708 windows_or_buffers_changed
++;
3709 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3714 run_window_configuration_change_hook (f
);
3720 /* Resize frame F's windows when number of lines of F is set to SIZE.
3721 HORFLAG 1 means resize windows when number of columns of F is set to
3724 This function can delete all windows but the selected one in order to
3725 satisfy the request. The result will be meaningful if and only if
3726 F's windows have meaningful sizes when you call this. */
3728 resize_frame_windows (struct frame
*f
, int size
, bool horflag
)
3730 Lisp_Object root
= f
->root_window
;
3731 struct window
*r
= XWINDOW (root
);
3732 Lisp_Object mini
= f
->minibuffer_window
;
3734 /* new_size is the new size of the frame's root window. */
3735 int new_size
= (horflag
3738 - FRAME_TOP_MARGIN (f
)
3739 - ((FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
3742 r
->top_line
= FRAME_TOP_MARGIN (f
);
3743 if (WINDOW_LEAF_P (r
))
3744 /* For a leaf root window just set the size. */
3746 r
->total_cols
= new_size
;
3748 r
->total_lines
= new_size
;
3751 /* old_size is the old size of the frame's root window. */
3752 int old_size
= horflag
? r
->total_cols
: r
->total_lines
;
3755 XSETINT (delta
, new_size
- old_size
);
3756 /* Try a "normal" resize first. */
3757 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qnil
);
3758 if (window_resize_check (r
, horflag
)
3759 && new_size
== XINT (r
->new_total
))
3760 window_resize_apply (r
, horflag
);
3763 /* Try with "reasonable" minimum sizes next. */
3764 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qt
);
3765 if (window_resize_check (r
, horflag
)
3766 && new_size
== XINT (r
->new_total
))
3767 window_resize_apply (r
, horflag
);
3770 /* Finally, try with "safe" minimum sizes. */
3771 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qsafe
);
3772 if (window_resize_check (r
, horflag
)
3773 && new_size
== XINT (r
->new_total
))
3774 window_resize_apply (r
, horflag
);
3777 /* We lost. Delete all windows but the frame's
3779 root
= f
->selected_window
;
3780 Fdelete_other_windows_internal (root
, Qnil
);
3782 XWINDOW (root
)->total_cols
= new_size
;
3784 XWINDOW (root
)->total_lines
= new_size
;
3790 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
3794 m
->total_cols
= size
;
3797 /* Are we sure we always want 1 line here? */
3799 m
->top_line
= r
->top_line
+ r
->total_lines
;
3803 windows_or_buffers_changed
++;
3807 DEFUN ("split-window-internal", Fsplit_window_internal
, Ssplit_window_internal
, 4, 4, 0,
3808 doc
: /* Split window OLD.
3809 Second argument TOTAL-SIZE specifies the number of lines or columns of the
3810 new window. In any case TOTAL-SIZE must be a positive integer.
3812 Third argument SIDE nil (or `below') specifies that the new window shall
3813 be located below WINDOW. SIDE `above' means the new window shall be
3814 located above WINDOW. In both cases TOTAL-SIZE specifies the number of
3815 lines of the new window including space reserved for the mode and/or
3818 SIDE t (or `right') specifies that the new window shall be located on
3819 the right side of WINDOW. SIDE `left' means the new window shall be
3820 located on the left of WINDOW. In both cases TOTAL-SIZE specifies the
3821 number of columns of the new window including space reserved for fringes
3822 and the scrollbar or a divider column.
3824 Fourth argument NORMAL-SIZE specifies the normal size of the new window
3825 according to the SIDE argument.
3827 The new total and normal sizes of all involved windows must have been
3828 set correctly. See the code of `split-window' for how this is done. */)
3829 (Lisp_Object old
, Lisp_Object total_size
, Lisp_Object side
, Lisp_Object normal_size
)
3831 /* OLD (*o) is the window we have to split. (*p) is either OLD's
3832 parent window or an internal window we have to install as OLD's new
3833 parent. REFERENCE (*r) must denote a live window, or is set to OLD
3834 provided OLD is a leaf window, or to the frame's selected window.
3835 NEW (*n) is the new window created with some parameters taken from
3837 register Lisp_Object
new, frame
, reference
;
3838 register struct window
*o
, *p
, *n
, *r
;
3841 /* HORFLAG is 1 when we split side-by-side, 0 otherwise. */
3842 = EQ (side
, Qt
) || EQ (side
, Qleft
) || EQ (side
, Qright
);
3843 int combination_limit
= 0;
3847 frame
= WINDOW_FRAME (o
);
3850 CHECK_NUMBER (total_size
);
3852 /* Set combination_limit to 1 if we have to make a new parent window.
3853 We do that if either `window-combination-limit' is t, or OLD has no
3854 parent, or OLD is ortho-combined. */
3856 EQ (Vwindow_combination_limit
, Qt
)
3859 ? WINDOW_VERTICAL_COMBINATION_P (XWINDOW (o
->parent
))
3860 : WINDOW_HORIZONTAL_COMBINATION_P (XWINDOW (o
->parent
)));
3862 /* We need a live reference window to initialize some parameters. */
3863 if (WINDOW_LIVE_P (old
))
3864 /* OLD is live, use it as reference window. */
3867 /* Use the frame's selected window as reference window. */
3868 reference
= FRAME_SELECTED_WINDOW (f
);
3869 r
= XWINDOW (reference
);
3871 /* The following bugs are caught by `split-window'. */
3872 if (MINI_WINDOW_P (o
))
3873 error ("Attempt to split minibuffer window");
3874 else if (XINT (total_size
) < (horflag
? 2 : 1))
3875 error ("Size of new window too small (after split)");
3876 else if (!combination_limit
&& !NILP (Vwindow_combination_resize
))
3877 /* `window-combination-resize' non-nil means try to resize OLD's siblings
3880 p
= XWINDOW (o
->parent
);
3881 /* Temporarily pretend we split the parent window. */
3883 (p
, make_number ((horflag
? p
->total_cols
: p
->total_lines
)
3884 - XINT (total_size
)));
3885 if (!window_resize_check (p
, horflag
))
3886 error ("Window sizes don't fit");
3888 /* Undo the temporary pretension. */
3889 wset_new_total (p
, make_number
3890 (horflag
? p
->total_cols
: p
->total_lines
));
3894 if (!window_resize_check (o
, horflag
))
3895 error ("Resizing old window failed");
3896 else if (XINT (total_size
) + XINT (o
->new_total
)
3897 != (horflag
? o
->total_cols
: o
->total_lines
))
3898 error ("Sum of sizes of old and new window don't fit");
3901 /* This is our point of no return. */
3902 if (combination_limit
)
3904 /* Save the old value of o->normal_cols/lines. It gets corrupted
3905 by make_parent_window and we need it below for assigning it to
3907 Lisp_Object new_normal
3908 = horflag
? o
->normal_cols
: o
->normal_lines
;
3910 make_parent_window (old
, horflag
);
3911 p
= XWINDOW (o
->parent
);
3912 if (EQ (Vwindow_combination_limit
, Qt
))
3913 /* Store t in the new parent's combination_limit slot to avoid
3914 that its children get merged into another window. */
3915 wset_combination_limit (p
, Qt
);
3916 /* These get applied below. */
3917 wset_new_total (p
, make_number
3918 (horflag
? o
->total_cols
: o
->total_lines
));
3919 wset_new_normal (p
, new_normal
);
3922 p
= XWINDOW (o
->parent
);
3924 windows_or_buffers_changed
++;
3925 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3926 new = make_window ();
3928 wset_frame (n
, frame
);
3929 wset_parent (n
, o
->parent
);
3931 if (EQ (side
, Qabove
) || EQ (side
, Qleft
))
3933 wset_prev (n
, o
->prev
);
3935 wset_combination (p
, horflag
, new);
3937 wset_next (XWINDOW (n
->prev
), new);
3943 wset_next (n
, o
->next
);
3944 if (!NILP (n
->next
))
3945 wset_prev (XWINDOW (n
->next
), new);
3950 n
->window_end_valid
= 0;
3951 memset (&n
->last_cursor
, 0, sizeof n
->last_cursor
);
3953 /* Get special geometry settings from reference window. */
3954 wset_left_margin_cols (n
, r
->left_margin_cols
);
3955 wset_right_margin_cols (n
, r
->right_margin_cols
);
3956 wset_left_fringe_width (n
, r
->left_fringe_width
);
3957 wset_right_fringe_width (n
, r
->right_fringe_width
);
3958 n
->fringes_outside_margins
= r
->fringes_outside_margins
;
3959 wset_scroll_bar_width (n
, r
->scroll_bar_width
);
3960 wset_vertical_scroll_bar_type (n
, r
->vertical_scroll_bar_type
);
3962 /* Directly assign orthogonal coordinates and sizes. */
3965 n
->top_line
= o
->top_line
;
3966 n
->total_lines
= o
->total_lines
;
3970 n
->left_col
= o
->left_col
;
3971 n
->total_cols
= o
->total_cols
;
3974 /* Iso-coordinates and sizes are assigned by window_resize_apply,
3975 get them ready here. */
3976 wset_new_total (n
, total_size
);
3977 wset_new_normal (n
, normal_size
);
3980 window_resize_apply (p
, horflag
);
3982 /* Set buffer of NEW to buffer of reference window. Don't run
3984 set_window_buffer (new, r
->contents
, 0, 1);
3987 /* Maybe we should run the scroll functions in Elisp (which already
3988 runs the configuration change hook). */
3989 if (! NILP (Vwindow_scroll_functions
))
3990 run_hook_with_args_2 (Qwindow_scroll_functions
, new,
3991 Fmarker_position (n
->start
));
3997 DEFUN ("delete-window-internal", Fdelete_window_internal
, Sdelete_window_internal
, 1, 1, 0,
3998 doc
: /* Remove WINDOW from its frame.
3999 WINDOW defaults to the selected window. Return nil.
4000 Signal an error when WINDOW is the only window on its frame. */)
4001 (register Lisp_Object window
)
4003 register Lisp_Object parent
, sibling
, frame
, root
;
4004 struct window
*w
, *p
, *s
, *r
;
4006 bool horflag
, before_sibling
= 0;
4008 w
= decode_any_window (window
);
4009 XSETWINDOW (window
, w
);
4010 if (NILP (w
->contents
))
4011 /* It's a no-op to delete an already deleted window. */
4016 /* Never delete a minibuffer or frame root window. */
4017 error ("Attempt to delete minibuffer or sole ordinary window");
4018 else if (NILP (w
->prev
) && NILP (w
->next
))
4019 /* Rather bow out here, this case should be handled on the Elisp
4021 error ("Attempt to delete sole window of parent");
4023 p
= XWINDOW (parent
);
4024 horflag
= WINDOW_HORIZONTAL_COMBINATION_P (p
);
4026 frame
= WINDOW_FRAME (w
);
4029 root
= FRAME_ROOT_WINDOW (f
);
4032 /* Unlink WINDOW from window tree. */
4034 /* Get SIBLING below (on the right of) WINDOW. */
4036 /* before_sibling 1 means WINDOW is the first child of its
4037 parent and thus before the sibling. */
4040 s
= XWINDOW (sibling
);
4041 wset_prev (s
, Qnil
);
4042 wset_combination (p
, horflag
, sibling
);
4045 /* Get SIBLING above (on the left of) WINDOW. */
4048 s
= XWINDOW (sibling
);
4049 wset_next (s
, w
->next
);
4050 if (!NILP (s
->next
))
4051 wset_prev (XWINDOW (s
->next
), sibling
);
4054 if (window_resize_check (r
, horflag
)
4055 && (XINT (r
->new_total
)
4056 == (horflag
? r
->total_cols
: r
->total_lines
)))
4057 /* We can delete WINDOW now. */
4062 window_resize_apply (p
, horflag
);
4064 /* If this window is referred to by the dpyinfo's mouse
4065 highlight, invalidate that slot to be safe (Bug#9904). */
4066 if (!FRAME_INITIAL_P (f
))
4068 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
4070 if (EQ (hlinfo
->mouse_face_window
, window
))
4071 hlinfo
->mouse_face_window
= Qnil
;
4074 windows_or_buffers_changed
++;
4075 Vwindow_list
= Qnil
;
4076 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4078 wset_next (w
, Qnil
); /* Don't delete w->next too. */
4079 free_window_matrices (w
);
4081 if (WINDOWP (w
->contents
))
4083 delete_all_child_windows (w
->contents
);
4084 wset_combination (w
, 0, Qnil
);
4089 unchain_marker (XMARKER (w
->pointm
));
4090 unchain_marker (XMARKER (w
->start
));
4091 wset_buffer (w
, Qnil
);
4094 if (NILP (s
->prev
) && NILP (s
->next
))
4095 /* A matrjoshka where SIBLING has become the only child of
4098 /* Put SIBLING into PARENT's place. */
4099 replace_window (parent
, sibling
, 0);
4100 /* Have SIBLING inherit the following three slot values from
4101 PARENT (the combination_limit slot is not inherited). */
4102 wset_normal_cols (s
, p
->normal_cols
);
4103 wset_normal_lines (s
, p
->normal_lines
);
4104 /* Mark PARENT as deleted. */
4105 wset_combination (p
, 0, Qnil
);
4106 /* Try to merge SIBLING into its new parent. */
4107 recombine_windows (sibling
);
4112 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f
)))
4113 /* We deleted the frame's selected window. */
4115 /* Use the frame's first window as fallback ... */
4116 Lisp_Object new_selected_window
= Fframe_first_window (frame
);
4117 /* ... but preferably use its most recently used window. */
4118 Lisp_Object mru_window
;
4120 /* `get-mru-window' might fail for some reason so play it safe
4121 - promote the first window _without recording it_ first. */
4122 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4123 Fselect_window (new_selected_window
, Qt
);
4125 fset_selected_window (f
, new_selected_window
);
4129 /* Now look whether `get-mru-window' gets us something. */
4130 mru_window
= call1 (Qget_mru_window
, frame
);
4131 if (WINDOW_LIVE_P (mru_window
)
4132 && EQ (XWINDOW (mru_window
)->frame
, frame
))
4133 new_selected_window
= mru_window
;
4135 /* If all ended up well, we now promote the mru window. */
4136 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4137 Fselect_window (new_selected_window
, Qnil
);
4139 fset_selected_window (f
, new_selected_window
);
4144 /* Must be run by the caller:
4145 run_window_configuration_change_hook (f); */
4148 /* We failed: Relink WINDOW into window tree. */
4152 wset_prev (s
, window
);
4153 wset_combination (p
, horflag
, window
);
4157 wset_next (s
, window
);
4158 if (!NILP (w
->next
))
4159 wset_prev (XWINDOW (w
->next
), window
);
4161 error ("Deletion failed");
4167 /***********************************************************************
4168 Resizing Mini-Windows
4169 ***********************************************************************/
4171 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we
4174 grow_mini_window (struct window
*w
, int delta
)
4176 struct frame
*f
= XFRAME (w
->frame
);
4178 Lisp_Object root
, value
;
4180 eassert (MINI_WINDOW_P (w
));
4181 eassert (delta
>= 0);
4183 root
= FRAME_ROOT_WINDOW (f
);
4185 value
= call2 (Qwindow_resize_root_window_vertically
,
4186 root
, make_number (- delta
));
4187 if (INTEGERP (value
) && window_resize_check (r
, 0))
4190 window_resize_apply (r
, 0);
4192 /* Grow the mini-window. */
4193 w
->top_line
= r
->top_line
+ r
->total_lines
;
4194 w
->total_lines
-= XINT (value
);
4195 /* Enforce full redisplay. FIXME: make it more selective. */
4196 windows_or_buffers_changed
++;
4203 /* Shrink mini-window W. */
4205 shrink_mini_window (struct window
*w
)
4207 struct frame
*f
= XFRAME (w
->frame
);
4209 Lisp_Object root
, value
;
4212 eassert (MINI_WINDOW_P (w
));
4214 size
= w
->total_lines
;
4217 root
= FRAME_ROOT_WINDOW (f
);
4219 value
= call2 (Qwindow_resize_root_window_vertically
,
4220 root
, make_number (size
- 1));
4221 if (INTEGERP (value
) && window_resize_check (r
, 0))
4224 window_resize_apply (r
, 0);
4226 /* Shrink the mini-window. */
4227 w
->top_line
= r
->top_line
+ r
->total_lines
;
4229 /* Enforce full redisplay. FIXME: make it more selective. */
4230 windows_or_buffers_changed
++;
4234 /* If the above failed for whatever strange reason we must make a
4235 one window frame here. The same routine will be needed when
4236 shrinking the frame (and probably when making the initial
4237 *scratch* window). For the moment leave things as they are. */
4241 DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal
, Sresize_mini_window_internal
, 1, 1, 0,
4242 doc
: /* Resize minibuffer window WINDOW. */)
4243 (Lisp_Object window
)
4245 struct window
*w
= XWINDOW (window
);
4250 CHECK_WINDOW (window
);
4251 f
= XFRAME (w
->frame
);
4253 if (!EQ (FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
)), window
))
4254 error ("Not a valid minibuffer window");
4255 else if (FRAME_MINIBUF_ONLY_P (f
))
4256 error ("Cannot resize a minibuffer-only frame");
4258 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4259 height
= r
->total_lines
+ w
->total_lines
;
4260 if (window_resize_check (r
, 0)
4261 && XINT (w
->new_total
) > 0
4262 && height
== XINT (r
->new_total
) + XINT (w
->new_total
))
4265 window_resize_apply (r
, 0);
4267 w
->total_lines
= XFASTINT (w
->new_total
);
4268 w
->top_line
= r
->top_line
+ r
->total_lines
;
4270 windows_or_buffers_changed
++;
4271 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4275 run_window_configuration_change_hook (f
);
4278 else error ("Failed to resize minibuffer window");
4281 /* Mark window cursors off for all windows in the window tree rooted
4282 at W by setting their phys_cursor_on_p flag to zero. Called from
4283 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4284 the frame are cleared. */
4287 mark_window_cursors_off (struct window
*w
)
4291 if (WINDOWP (w
->contents
))
4292 mark_window_cursors_off (XWINDOW (w
->contents
));
4294 w
->phys_cursor_on_p
= 0;
4296 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4301 /* Return number of lines of text (not counting mode lines) in W. */
4304 window_internal_height (struct window
*w
)
4306 int ht
= w
->total_lines
;
4308 if (!MINI_WINDOW_P (w
))
4310 if (!NILP (w
->parent
)
4311 || WINDOWP (w
->contents
)
4314 || WINDOW_WANTS_MODELINE_P (w
))
4317 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4324 /************************************************************************
4326 ***********************************************************************/
4328 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4329 N screen-fulls, which is defined as the height of the window minus
4330 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4331 instead. Negative values of N mean scroll down. NOERROR non-zero
4332 means don't signal an error if we try to move over BEGV or ZV,
4336 window_scroll (Lisp_Object window
, EMACS_INT n
, bool whole
, int noerror
)
4339 n
= clip_to_bounds (INT_MIN
, n
, INT_MAX
);
4341 /* If we must, use the pixel-based version which is much slower than
4342 the line-based one but can handle varying line heights. */
4343 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4344 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4346 window_scroll_line_based (window
, n
, whole
, noerror
);
4352 /* Implementation of window_scroll that works based on pixel line
4353 heights. See the comment of window_scroll for parameter
4357 window_scroll_pixel_based (Lisp_Object window
, int n
, bool whole
, int noerror
)
4360 struct window
*w
= XWINDOW (window
);
4361 struct text_pos start
;
4362 int this_scroll_margin
;
4363 /* True if we fiddled the window vscroll field without really scrolling. */
4365 int x
, y
, rtop
, rbot
, rowh
, vpos
;
4366 void *itdata
= NULL
;
4367 int window_total_lines
;
4368 int frame_line_height
= default_line_pixel_height (w
);
4370 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4371 /* Scrolling a minibuffer window via scroll bar when the echo area
4372 shows long text sometimes resets the minibuffer contents behind
4374 if (CHARPOS (start
) > ZV
)
4375 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4377 /* If PT is not visible in WINDOW, move back one half of
4378 the screen. Allow PT to be partially visible, otherwise
4379 something like (scroll-down 1) with PT in the line before
4380 the partially visible one would recenter. */
4382 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
4384 itdata
= bidi_shelve_cache ();
4385 /* Move backward half the height of the window. Performance note:
4386 vmotion used here is about 10% faster, but would give wrong
4387 results for variable height lines. */
4388 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4389 it
.current_y
= it
.last_visible_y
;
4390 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4392 /* The function move_iterator_vertically may move over more than
4393 the specified y-distance. If it->w is small, e.g. a
4394 mini-buffer window, we may end up in front of the window's
4395 display area. This is the case when Start displaying at the
4396 start of the line containing PT in this case. */
4397 if (it
.current_y
<= 0)
4399 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4400 move_it_vertically_backward (&it
, 0);
4404 start
= it
.current
.pos
;
4405 bidi_unshelve_cache (itdata
, 0);
4407 else if (auto_window_vscroll_p
)
4409 if (rtop
|| rbot
) /* partially visible */
4412 int dy
= frame_line_height
;
4414 dy
= max ((window_box_height (w
)
4415 - next_screen_context_lines
* dy
),
4421 /* Only vscroll backwards if already vscrolled forwards. */
4422 if (w
->vscroll
< 0 && rtop
> 0)
4424 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
4425 Fset_window_vscroll (window
, make_number (px
), Qt
);
4431 /* Do vscroll if already vscrolled or only display line. */
4432 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
4434 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
4435 Fset_window_vscroll (window
, make_number (px
), Qt
);
4439 /* Maybe modify window start instead of scrolling. */
4440 if (rbot
> 0 || w
->vscroll
< 0)
4444 Fset_window_vscroll (window
, make_number (0), Qt
);
4445 /* If there are other text lines above the current row,
4446 move window start to current row. Else to next row. */
4448 spos
= XINT (Fline_beginning_position (Qnil
));
4450 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
4451 set_marker_restricted (w
->start
, make_number (spos
),
4453 w
->start_at_line_beg
= 1;
4454 w
->update_mode_line
= 1;
4455 /* Set force_start so that redisplay_window will run the
4456 window-scroll-functions. */
4462 /* Cancel previous vscroll. */
4463 Fset_window_vscroll (window
, make_number (0), Qt
);
4466 itdata
= bidi_shelve_cache ();
4467 /* If scroll_preserve_screen_position is non-nil, we try to set
4468 point in the same window line as it is now, so get that line. */
4469 if (!NILP (Vscroll_preserve_screen_position
))
4471 /* We preserve the goal pixel coordinate across consecutive
4472 calls to scroll-up, scroll-down and other commands that
4473 have the `scroll-command' property. This avoids the
4474 possibility of point becoming "stuck" on a tall line when
4475 scrolling by one line. */
4476 if (window_scroll_pixel_based_preserve_y
< 0
4477 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
4478 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
4480 start_display (&it
, w
, start
);
4481 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4482 window_scroll_pixel_based_preserve_y
= it
.current_y
;
4483 window_scroll_pixel_based_preserve_x
= it
.current_x
;
4487 window_scroll_pixel_based_preserve_y
4488 = window_scroll_pixel_based_preserve_x
= -1;
4490 /* Move iterator it from start the specified distance forward or
4491 backward. The result is the new window start. */
4492 start_display (&it
, w
, start
);
4495 ptrdiff_t start_pos
= IT_CHARPOS (it
);
4496 int dy
= frame_line_height
;
4497 dy
= max ((window_box_height (w
)
4498 - next_screen_context_lines
* dy
),
4501 /* Note that move_it_vertically always moves the iterator to the
4502 start of a line. So, if the last line doesn't have a newline,
4503 we would end up at the start of the line ending at ZV. */
4506 move_it_vertically_backward (&it
, -dy
);
4507 /* Ensure we actually do move, e.g. in case we are currently
4508 looking at an image that is taller that the window height. */
4509 while (start_pos
== IT_CHARPOS (it
)
4510 && start_pos
> BEGV
)
4511 move_it_by_lines (&it
, -1);
4515 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4516 MOVE_TO_POS
| MOVE_TO_Y
);
4517 /* Ensure we actually do move, e.g. in case we are currently
4518 looking at an image that is taller that the window height. */
4519 while (start_pos
== IT_CHARPOS (it
)
4521 move_it_by_lines (&it
, 1);
4525 move_it_by_lines (&it
, n
);
4527 /* We failed if we find ZV is already on the screen (scrolling up,
4528 means there's nothing past the end), or if we can't start any
4529 earlier (scrolling down, means there's nothing past the top). */
4530 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4531 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4533 if (IT_CHARPOS (it
) == ZV
)
4535 if (it
.current_y
< it
.last_visible_y
4536 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4537 > it
.last_visible_y
))
4539 /* The last line was only partially visible, make it fully
4541 w
->vscroll
= (it
.last_visible_y
4542 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4543 adjust_glyphs (it
.f
);
4547 bidi_unshelve_cache (itdata
, 0);
4550 else if (n
< 0) /* could happen with empty buffers */
4551 xsignal0 (Qbeginning_of_buffer
);
4553 xsignal0 (Qend_of_buffer
);
4558 if (w
->vscroll
!= 0)
4559 /* The first line was only partially visible, make it fully
4564 bidi_unshelve_cache (itdata
, 0);
4568 xsignal0 (Qbeginning_of_buffer
);
4572 /* If control gets here, then we vscrolled. */
4574 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
4576 /* Don't try to change the window start below. */
4582 ptrdiff_t pos
= IT_CHARPOS (it
);
4585 /* If in the middle of a multi-glyph character move forward to
4586 the next character. */
4587 if (in_display_vector_p (&it
))
4590 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
4593 /* Set the window start, and set up the window for redisplay. */
4594 set_marker_restricted_both (w
->start
, w
->contents
, IT_CHARPOS (it
),
4596 bytepos
= marker_byte_position (w
->start
);
4597 w
->start_at_line_beg
= (pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n');
4598 w
->update_mode_line
= 1;
4599 /* Set force_start so that redisplay_window will run the
4600 window-scroll-functions. */
4604 /* The rest of this function uses current_y in a nonstandard way,
4605 not including the height of the header line if any. */
4606 it
.current_y
= it
.vpos
= 0;
4608 /* Move PT out of scroll margins.
4609 This code wants current_y to be zero at the window start position
4610 even if there is a header line. */
4612 = w
->total_lines
* WINDOW_FRAME_LINE_HEIGHT (w
) / frame_line_height
;
4613 this_scroll_margin
= max (0, scroll_margin
);
4615 = min (this_scroll_margin
, window_total_lines
/ 4);
4616 this_scroll_margin
*= frame_line_height
;
4620 /* We moved the window start towards ZV, so PT may be now
4621 in the scroll margin at the top. */
4622 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4623 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
4624 && (NILP (Vscroll_preserve_screen_position
)
4625 || EQ (Vscroll_preserve_screen_position
, Qt
)))
4626 /* We found PT at a legitimate height. Leave it alone. */
4628 else if (window_scroll_pixel_based_preserve_y
>= 0)
4630 /* If we have a header line, take account of it.
4631 This is necessary because we set it.current_y to 0, above. */
4632 move_it_to (&it
, -1,
4633 window_scroll_pixel_based_preserve_x
,
4634 window_scroll_pixel_based_preserve_y
4635 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
4636 -1, MOVE_TO_Y
| MOVE_TO_X
);
4637 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4641 while (it
.current_y
< this_scroll_margin
)
4643 int prev
= it
.current_y
;
4644 move_it_by_lines (&it
, 1);
4645 if (prev
== it
.current_y
)
4648 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4653 ptrdiff_t charpos
, bytepos
;
4656 /* Save our position, for the
4657 window_scroll_pixel_based_preserve_y case. */
4658 charpos
= IT_CHARPOS (it
);
4659 bytepos
= IT_BYTEPOS (it
);
4661 /* We moved the window start towards BEGV, so PT may be now
4662 in the scroll margin at the bottom. */
4663 move_it_to (&it
, PT
, -1,
4664 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
4665 - this_scroll_margin
- 1),
4667 MOVE_TO_POS
| MOVE_TO_Y
);
4669 /* Save our position, in case it's correct. */
4670 charpos
= IT_CHARPOS (it
);
4671 bytepos
= IT_BYTEPOS (it
);
4673 /* See if point is on a partially visible line at the end. */
4674 if (it
.what
== IT_EOB
)
4675 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
4678 move_it_by_lines (&it
, 1);
4679 partial_p
= it
.current_y
> it
.last_visible_y
;
4682 if (charpos
== PT
&& !partial_p
4683 && (NILP (Vscroll_preserve_screen_position
)
4684 || EQ (Vscroll_preserve_screen_position
, Qt
)))
4685 /* We found PT before we found the display margin, so PT is ok. */
4687 else if (window_scroll_pixel_based_preserve_y
>= 0)
4689 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4690 start_display (&it
, w
, start
);
4691 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
4692 here because we called start_display again and did not
4693 alter it.current_y this time. */
4694 move_it_to (&it
, -1, window_scroll_pixel_based_preserve_x
,
4695 window_scroll_pixel_based_preserve_y
, -1,
4696 MOVE_TO_Y
| MOVE_TO_X
);
4697 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4702 /* The last line was only partially visible, so back up two
4703 lines to make sure we're on a fully visible line. */
4705 move_it_by_lines (&it
, -2);
4706 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4709 /* No, the position we saved is OK, so use it. */
4710 SET_PT_BOTH (charpos
, bytepos
);
4713 bidi_unshelve_cache (itdata
, 0);
4717 /* Implementation of window_scroll that works based on screen lines.
4718 See the comment of window_scroll for parameter descriptions. */
4721 window_scroll_line_based (Lisp_Object window
, int n
, bool whole
, int noerror
)
4723 register struct window
*w
= XWINDOW (window
);
4724 /* Fvertical_motion enters redisplay, which can trigger
4725 fontification, which in turn can modify buffer text (e.g., if the
4726 fontification functions replace escape sequences with faces, as
4727 in `grep-mode-font-lock-keywords'). So we use a marker to record
4728 the old point position, to prevent crashes in SET_PT_BOTH. */
4729 Lisp_Object opoint_marker
= Fpoint_marker ();
4730 register ptrdiff_t pos
, pos_byte
;
4731 register int ht
= window_internal_height (w
);
4732 register Lisp_Object tem
;
4735 ptrdiff_t startpos
= marker_position (w
->start
);
4736 ptrdiff_t startbyte
= marker_byte_position (w
->start
);
4737 Lisp_Object original_pos
= Qnil
;
4739 /* If scrolling screen-fulls, compute the number of lines to
4740 scroll from the window's height. */
4742 n
*= max (1, ht
- next_screen_context_lines
);
4744 if (!NILP (Vscroll_preserve_screen_position
))
4746 if (window_scroll_preserve_vpos
<= 0
4747 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
4748 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
4750 struct position posit
4751 = *compute_motion (startpos
, startbyte
, 0, 0, 0,
4752 PT
, ht
, 0, -1, w
->hscroll
, 0, w
);
4753 window_scroll_preserve_vpos
= posit
.vpos
;
4754 window_scroll_preserve_hpos
= posit
.hpos
+ w
->hscroll
;
4757 original_pos
= Fcons (make_number (window_scroll_preserve_hpos
),
4758 make_number (window_scroll_preserve_vpos
));
4761 XSETFASTINT (tem
, PT
);
4762 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
4766 Fvertical_motion (make_number (- (ht
/ 2)), window
);
4768 startbyte
= PT_BYTE
;
4771 SET_PT_BOTH (startpos
, startbyte
);
4772 lose
= n
< 0 && PT
== BEGV
;
4773 Fvertical_motion (make_number (n
), window
);
4777 SET_PT_BOTH (marker_position (opoint_marker
),
4778 marker_byte_position (opoint_marker
));
4785 xsignal0 (Qbeginning_of_buffer
);
4790 /* Don't use a scroll margin that is negative or too large. */
4791 int this_scroll_margin
=
4792 max (0, min (scroll_margin
, w
->total_lines
/ 4));
4794 set_marker_restricted_both (w
->start
, w
->contents
, pos
, pos_byte
);
4795 w
->start_at_line_beg
= !NILP (bolp
);
4796 w
->update_mode_line
= 1;
4797 /* Set force_start so that redisplay_window will run
4798 the window-scroll-functions. */
4801 if (!NILP (Vscroll_preserve_screen_position
)
4802 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
4804 SET_PT_BOTH (pos
, pos_byte
);
4805 Fvertical_motion (original_pos
, window
);
4807 /* If we scrolled forward, put point enough lines down
4808 that it is outside the scroll margin. */
4813 if (this_scroll_margin
> 0)
4815 SET_PT_BOTH (pos
, pos_byte
);
4816 Fvertical_motion (make_number (this_scroll_margin
), window
);
4822 if (top_margin
<= marker_position (opoint_marker
))
4823 SET_PT_BOTH (marker_position (opoint_marker
),
4824 marker_byte_position (opoint_marker
));
4825 else if (!NILP (Vscroll_preserve_screen_position
))
4827 SET_PT_BOTH (pos
, pos_byte
);
4828 Fvertical_motion (original_pos
, window
);
4831 SET_PT (top_margin
);
4837 /* If we scrolled backward, put point near the end of the window
4838 but not within the scroll margin. */
4839 SET_PT_BOTH (pos
, pos_byte
);
4840 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
4841 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
4844 bottom_margin
= PT
+ 1;
4846 if (bottom_margin
> marker_position (opoint_marker
))
4847 SET_PT_BOTH (marker_position (opoint_marker
),
4848 marker_byte_position (opoint_marker
));
4851 if (!NILP (Vscroll_preserve_screen_position
))
4853 SET_PT_BOTH (pos
, pos_byte
);
4854 Fvertical_motion (original_pos
, window
);
4857 Fvertical_motion (make_number (-1), window
);
4866 xsignal0 (Qend_of_buffer
);
4871 /* Scroll selected_window up or down. If N is nil, scroll a
4872 screen-full which is defined as the height of the window minus
4873 next_screen_context_lines. If N is the symbol `-', scroll.
4874 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4875 up. This is the guts of Fscroll_up and Fscroll_down. */
4878 scroll_command (Lisp_Object n
, int direction
)
4880 ptrdiff_t count
= SPECPDL_INDEX ();
4882 eassert (eabs (direction
) == 1);
4884 /* If selected window's buffer isn't current, make it current for
4885 the moment. But don't screw up if window_scroll gets an error. */
4886 if (XBUFFER (XWINDOW (selected_window
)->contents
) != current_buffer
)
4888 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4889 Fset_buffer (XWINDOW (selected_window
)->contents
);
4891 /* Make redisplay consider other windows than just selected_window. */
4892 ++windows_or_buffers_changed
;
4896 window_scroll (selected_window
, direction
, 1, 0);
4897 else if (EQ (n
, Qminus
))
4898 window_scroll (selected_window
, -direction
, 1, 0);
4901 n
= Fprefix_numeric_value (n
);
4902 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
4905 unbind_to (count
, Qnil
);
4908 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "^P",
4909 doc
: /* Scroll text of selected window upward ARG lines.
4910 If ARG is omitted or nil, scroll upward by a near full screen.
4911 A near full screen is `next-screen-context-lines' less than a full screen.
4912 Negative ARG means scroll downward.
4913 If ARG is the atom `-', scroll downward by nearly full screen.
4914 When calling from a program, supply as argument a number, nil, or `-'. */)
4917 scroll_command (arg
, 1);
4921 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "^P",
4922 doc
: /* Scroll text of selected window down ARG lines.
4923 If ARG is omitted or nil, scroll down by a near full screen.
4924 A near full screen is `next-screen-context-lines' less than a full screen.
4925 Negative ARG means scroll upward.
4926 If ARG is the atom `-', scroll upward by nearly full screen.
4927 When calling from a program, supply as argument a number, nil, or `-'. */)
4930 scroll_command (arg
, -1);
4934 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
4935 doc
: /* Return the other window for \"other window scroll\" commands.
4936 If `other-window-scroll-buffer' is non-nil, a window
4937 showing that buffer is used.
4938 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4939 specifies the window. This takes precedence over
4940 `other-window-scroll-buffer'. */)
4945 if (MINI_WINDOW_P (XWINDOW (selected_window
))
4946 && !NILP (Vminibuf_scroll_window
))
4947 window
= Vminibuf_scroll_window
;
4948 /* If buffer is specified, scroll that buffer. */
4949 else if (!NILP (Vother_window_scroll_buffer
))
4951 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
4953 window
= display_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
4957 /* Nothing specified; look for a neighboring window on the same
4959 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
4961 if (EQ (window
, selected_window
))
4962 /* That didn't get us anywhere; look for a window on another
4965 window
= Fnext_window (window
, Qnil
, Qt
);
4966 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
4967 && ! EQ (window
, selected_window
));
4970 CHECK_LIVE_WINDOW (window
);
4972 if (EQ (window
, selected_window
))
4973 error ("There is no other window");
4978 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
4979 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
4980 A near full screen is `next-screen-context-lines' less than a full screen.
4981 The next window is the one below the current one; or the one at the top
4982 if the current one is at the bottom. Negative ARG means scroll downward.
4983 If ARG is the atom `-', scroll downward by nearly full screen.
4984 When calling from a program, supply as argument a number, nil, or `-'.
4986 If `other-window-scroll-buffer' is non-nil, scroll the window
4987 showing that buffer, popping the buffer up if necessary.
4988 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4989 specifies the window to scroll. This takes precedence over
4990 `other-window-scroll-buffer'. */)
4995 ptrdiff_t count
= SPECPDL_INDEX ();
4997 window
= Fother_window_for_scrolling ();
4998 w
= XWINDOW (window
);
5000 /* Don't screw up if window_scroll gets an error. */
5001 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5002 ++windows_or_buffers_changed
;
5004 Fset_buffer (w
->contents
);
5005 SET_PT_BOTH (marker_position (w
->pointm
), marker_byte_position (w
->pointm
));
5008 window_scroll (window
, 1, 1, 1);
5009 else if (EQ (arg
, Qminus
))
5010 window_scroll (window
, -1, 1, 1);
5016 window_scroll (window
, XINT (arg
), 0, 1);
5019 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5020 unbind_to (count
, Qnil
);
5025 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "^P\np",
5026 doc
: /* Scroll selected window display ARG columns left.
5027 Default for ARG is window width minus 2.
5028 Value is the total amount of leftward horizontal scrolling in
5029 effect after the change.
5030 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5031 lower bound for automatic scrolling, i.e. automatic scrolling
5032 will not scroll a window to a column less than the value returned
5033 by this function. This happens in an interactive call. */)
5034 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5036 struct window
*w
= XWINDOW (selected_window
);
5037 EMACS_INT requested_arg
= (NILP (arg
)
5038 ? window_body_cols (w
) - 2
5039 : XINT (Fprefix_numeric_value (arg
)));
5040 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
+ requested_arg
);
5042 if (!NILP (set_minimum
))
5043 w
->min_hscroll
= w
->hscroll
;
5048 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "^P\np",
5049 doc
: /* Scroll selected window display ARG columns right.
5050 Default for ARG is window width minus 2.
5051 Value is the total amount of leftward horizontal scrolling in
5052 effect after the change.
5053 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5054 lower bound for automatic scrolling, i.e. automatic scrolling
5055 will not scroll a window to a column less than the value returned
5056 by this function. This happens in an interactive call. */)
5057 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5059 struct window
*w
= XWINDOW (selected_window
);
5060 EMACS_INT requested_arg
= (NILP (arg
)
5061 ? window_body_cols (w
) - 2
5062 : XINT (Fprefix_numeric_value (arg
)));
5063 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
- requested_arg
);
5065 if (!NILP (set_minimum
))
5066 w
->min_hscroll
= w
->hscroll
;
5071 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5072 doc
: /* Return the window which was selected when entering the minibuffer.
5073 Returns nil, if selected window is not a minibuffer window. */)
5076 if (minibuf_level
> 0
5077 && MINI_WINDOW_P (XWINDOW (selected_window
))
5078 && WINDOW_LIVE_P (minibuf_selected_window
))
5079 return minibuf_selected_window
;
5084 /* Value is the number of lines actually displayed in window W,
5085 as opposed to its height. */
5088 displayed_window_lines (struct window
*w
)
5091 struct text_pos start
;
5092 ptrdiff_t charpos
= marker_position (w
->start
);
5093 int height
= window_box_height (w
);
5094 struct buffer
*old_buffer
;
5096 void *itdata
= NULL
;
5098 if (XBUFFER (w
->contents
) != current_buffer
)
5100 old_buffer
= current_buffer
;
5101 set_buffer_internal (XBUFFER (w
->contents
));
5106 /* In case W->start is out of the accessible range, do something
5107 reasonable. This happens in Info mode when Info-scroll-down
5108 calls (recenter -1) while W->start is 1. */
5110 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5111 else if (charpos
> ZV
)
5112 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
5114 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5116 itdata
= bidi_shelve_cache ();
5117 start_display (&it
, w
, start
);
5118 move_it_vertically (&it
, height
);
5119 bottom_y
= line_bottom_y (&it
);
5120 bidi_unshelve_cache (itdata
, 0);
5122 /* rms: On a non-window display,
5123 the value of it.vpos at the bottom of the screen
5124 seems to be 1 larger than window_box_height (w).
5125 This kludge fixes a bug whereby (move-to-window-line -1)
5126 when ZV is on the last screen line
5127 moves to the previous screen line instead of the last one. */
5128 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5131 /* Add in empty lines at the bottom of the window. */
5132 if (bottom_y
< height
)
5134 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5135 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5139 set_buffer_internal (old_buffer
);
5145 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5146 doc
: /* Center point in selected window and maybe redisplay frame.
5147 With a numeric prefix argument ARG, recenter putting point on screen line ARG
5148 relative to the selected window. If ARG is negative, it counts up from the
5149 bottom of the window. (ARG should be less than the height of the window.)
5151 If ARG is omitted or nil, then recenter with point on the middle line of
5152 the selected window; if the variable `recenter-redisplay' is non-nil,
5153 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5154 is set to `grow-only', this resets the tool-bar's height to the minimum
5155 height needed); if `recenter-redisplay' has the special value `tty',
5156 then only tty frames are redrawn.
5158 Just C-u as prefix means put point in the center of the window
5159 and redisplay normally--don't erase and redraw the frame. */)
5160 (register Lisp_Object arg
)
5162 struct window
*w
= XWINDOW (selected_window
);
5163 struct buffer
*buf
= XBUFFER (w
->contents
);
5164 struct buffer
*obuf
= current_buffer
;
5166 ptrdiff_t charpos
, bytepos
;
5167 EMACS_INT iarg
IF_LINT (= 0);
5168 int this_scroll_margin
;
5170 /* If redisplay is suppressed due to an error, try again. */
5171 obuf
->display_error_modiff
= 0;
5175 if (!NILP (Vrecenter_redisplay
)
5176 && (!EQ (Vrecenter_redisplay
, Qtty
)
5177 || !NILP (Ftty_type (selected_frame
))))
5181 /* Invalidate pixel data calculated for all compositions. */
5182 for (i
= 0; i
< n_compositions
; i
++)
5183 composition_table
[i
]->font
= NULL
;
5185 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5187 Fredraw_frame (WINDOW_FRAME (w
));
5188 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5193 else if (CONSP (arg
)) /* Just C-u. */
5197 arg
= Fprefix_numeric_value (arg
);
5202 set_buffer_internal (buf
);
5204 /* Do this after making BUF current
5205 in case scroll_margin is buffer-local. */
5206 this_scroll_margin
=
5207 max (0, min (scroll_margin
, w
->total_lines
/ 4));
5209 /* Handle centering on a graphical frame specially. Such frames can
5210 have variable-height lines and centering point on the basis of
5211 line counts would lead to strange effects. */
5212 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5218 void *itdata
= bidi_shelve_cache ();
5220 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5221 start_display (&it
, w
, pt
);
5222 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5223 charpos
= IT_CHARPOS (it
);
5224 bytepos
= IT_BYTEPOS (it
);
5225 bidi_unshelve_cache (itdata
, 0);
5231 ptrdiff_t nlines
= min (PTRDIFF_MAX
, -iarg
);
5232 int extra_line_spacing
;
5233 int h
= window_box_height (w
);
5234 void *itdata
= bidi_shelve_cache ();
5236 iarg
= - max (-iarg
, this_scroll_margin
);
5238 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5239 start_display (&it
, w
, pt
);
5241 /* Be sure we have the exact height of the full line containing PT. */
5242 move_it_by_lines (&it
, 0);
5244 /* The amount of pixels we have to move back is the window
5245 height minus what's displayed in the line containing PT,
5246 and the lines below. */
5249 move_it_by_lines (&it
, nlines
);
5251 if (it
.vpos
== nlines
)
5255 /* Last line has no newline */
5256 h
-= line_bottom_y (&it
);
5260 /* Don't reserve space for extra line spacing of last line. */
5261 extra_line_spacing
= it
.max_extra_line_spacing
;
5263 /* If we can't move down NLINES lines because we hit
5264 the end of the buffer, count in some empty lines. */
5265 if (it
.vpos
< nlines
)
5268 extra_line_spacing
= it
.extra_line_spacing
;
5269 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5273 bidi_unshelve_cache (itdata
, 0);
5277 /* Now find the new top line (starting position) of the window. */
5278 start_display (&it
, w
, pt
);
5280 move_it_vertically_backward (&it
, h
);
5282 /* If extra line spacing is present, we may move too far
5283 back. This causes the last line to be only partially
5284 visible (which triggers redisplay to recenter that line
5285 in the middle), so move forward.
5286 But ignore extra line spacing on last line, as it is not
5287 considered to be part of the visible height of the line.
5289 h
+= extra_line_spacing
;
5290 while (-it
.current_y
> h
)
5291 move_it_by_lines (&it
, 1);
5293 charpos
= IT_CHARPOS (it
);
5294 bytepos
= IT_BYTEPOS (it
);
5296 bidi_unshelve_cache (itdata
, 0);
5300 struct position pos
;
5302 iarg
= max (iarg
, this_scroll_margin
);
5304 pos
= *vmotion (PT
, PT_BYTE
, -iarg
, w
);
5305 charpos
= pos
.bufpos
;
5306 bytepos
= pos
.bytepos
;
5311 struct position pos
;
5312 int ht
= window_internal_height (w
);
5319 /* Don't let it get into the margin at either top or bottom. */
5320 iarg
= clip_to_bounds (this_scroll_margin
, iarg
,
5321 ht
- this_scroll_margin
- 1);
5323 pos
= *vmotion (PT
, PT_BYTE
, - iarg
, w
);
5324 charpos
= pos
.bufpos
;
5325 bytepos
= pos
.bytepos
;
5328 /* Set the new window start. */
5329 set_marker_both (w
->start
, w
->contents
, charpos
, bytepos
);
5330 w
->window_end_valid
= 0;
5332 w
->optional_new_start
= 1;
5334 w
->start_at_line_beg
= (bytepos
== BEGV_BYTE
||
5335 FETCH_BYTE (bytepos
- 1) == '\n');
5337 set_buffer_internal (obuf
);
5341 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5343 doc
: /* Return the height in lines of the text display area of WINDOW.
5344 WINDOW must be a live window and defaults to the selected one.
5346 The returned height does not include the mode line, any header line,
5347 nor any partial-height lines at the bottom of the text area. */)
5348 (Lisp_Object window
)
5350 struct window
*w
= decode_live_window (window
);
5351 int pixel_height
= window_box_height (w
);
5352 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5353 return make_number (line_height
);
5358 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5360 doc
: /* Position point relative to window.
5361 ARG nil means position point at center of window.
5362 Else, ARG specifies vertical position within the window;
5363 zero means top of window, negative means relative to bottom of window. */)
5366 struct window
*w
= XWINDOW (selected_window
);
5370 int this_scroll_margin
;
5373 if (!(BUFFERP (w
->contents
) && XBUFFER (w
->contents
) == current_buffer
))
5374 /* This test is needed to make sure PT/PT_BYTE make sense in w->contents
5375 when passed below to set_marker_both. */
5376 error ("move-to-window-line called from unrelated buffer");
5378 window
= selected_window
;
5379 start
= marker_position (w
->start
);
5380 if (start
< BEGV
|| start
> ZV
)
5382 int height
= window_internal_height (w
);
5383 Fvertical_motion (make_number (- (height
/ 2)), window
);
5384 set_marker_both (w
->start
, w
->contents
, PT
, PT_BYTE
);
5385 w
->start_at_line_beg
= !NILP (Fbolp ());
5389 Fgoto_char (w
->start
);
5391 lines
= displayed_window_lines (w
);
5394 this_scroll_margin
= max (0, min (scroll_margin
, lines
/ 4));
5398 XSETFASTINT (arg
, lines
/ 2);
5401 EMACS_INT iarg
= XINT (Fprefix_numeric_value (arg
));
5404 iarg
= iarg
+ lines
;
5406 #if 0 /* This code would prevent move-to-window-line from moving point
5407 to a place inside the scroll margins (which would cause the
5408 next redisplay to scroll). I wrote this code, but then concluded
5409 it is probably better not to install it. However, it is here
5410 inside #if 0 so as not to lose it. -- rms. */
5412 /* Don't let it get into the margin at either top or bottom. */
5413 iarg
= max (iarg
, this_scroll_margin
);
5414 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
5417 arg
= make_number (iarg
);
5420 /* Skip past a partially visible first line. */
5422 XSETINT (arg
, XINT (arg
) + 1);
5424 return Fvertical_motion (arg
, window
);
5429 /***********************************************************************
5430 Window Configuration
5431 ***********************************************************************/
5433 struct save_window_data
5435 struct vectorlike_header header
;
5436 Lisp_Object selected_frame
;
5437 Lisp_Object current_window
;
5438 Lisp_Object current_buffer
;
5439 Lisp_Object minibuf_scroll_window
;
5440 Lisp_Object minibuf_selected_window
;
5441 Lisp_Object root_window
;
5442 Lisp_Object focus_frame
;
5443 /* A vector, each of whose elements is a struct saved_window
5445 Lisp_Object saved_windows
;
5447 /* All fields above are traced by the GC.
5448 From `fame-cols' down, the fields are ignored by the GC. */
5450 int frame_cols
, frame_lines
, frame_menu_bar_lines
;
5451 int frame_tool_bar_lines
;
5454 /* This is saved as a Lisp_Vector */
5457 struct vectorlike_header header
;
5459 Lisp_Object window
, buffer
, start
, pointm
, mark
;
5460 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5461 Lisp_Object normal_cols
, normal_lines
;
5462 Lisp_Object hscroll
, min_hscroll
;
5463 Lisp_Object parent
, prev
;
5464 Lisp_Object start_at_line_beg
;
5465 Lisp_Object display_table
;
5466 Lisp_Object left_margin_cols
, right_margin_cols
;
5467 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
5468 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
, dedicated
;
5469 Lisp_Object combination_limit
, window_parameters
;
5472 #define SAVED_WINDOW_N(swv,n) \
5473 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5475 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
5476 doc
: /* Return t if OBJECT is a window-configuration object. */)
5477 (Lisp_Object object
)
5479 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
5482 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
5483 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5484 (Lisp_Object config
)
5486 register struct save_window_data
*data
;
5487 struct Lisp_Vector
*saved_windows
;
5489 CHECK_WINDOW_CONFIGURATION (config
);
5491 data
= (struct save_window_data
*) XVECTOR (config
);
5492 saved_windows
= XVECTOR (data
->saved_windows
);
5493 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5496 DEFUN ("set-window-configuration", Fset_window_configuration
,
5497 Sset_window_configuration
, 1, 1, 0,
5498 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5499 CONFIGURATION must be a value previously returned
5500 by `current-window-configuration' (which see).
5501 If CONFIGURATION was made from a frame that is now deleted,
5502 only frame-independent values can be restored. In this case,
5503 the return value is nil. Otherwise the value is t. */)
5504 (Lisp_Object configuration
)
5506 register struct save_window_data
*data
;
5507 struct Lisp_Vector
*saved_windows
;
5508 Lisp_Object new_current_buffer
;
5511 ptrdiff_t old_point
= -1;
5513 CHECK_WINDOW_CONFIGURATION (configuration
);
5515 data
= (struct save_window_data
*) XVECTOR (configuration
);
5516 saved_windows
= XVECTOR (data
->saved_windows
);
5518 new_current_buffer
= data
->current_buffer
;
5519 if (!BUFFER_LIVE_P (XBUFFER (new_current_buffer
)))
5520 new_current_buffer
= Qnil
;
5523 if (XBUFFER (new_current_buffer
) == current_buffer
)
5524 /* The code further down "preserves point" by saving here PT in
5525 old_point and then setting it later back into PT. When the
5526 current-selected-window and the final-selected-window both show
5527 the current buffer, this suffers from the problem that the
5528 current PT is the window-point of the current-selected-window,
5529 while the final PT is the point of the final-selected-window, so
5530 this copy from one PT to the other would end up moving the
5531 window-point of the final-selected-window to the window-point of
5532 the current-selected-window. So we have to be careful which
5533 point of the current-buffer we copy into old_point. */
5534 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
)
5535 && WINDOWP (selected_window
)
5536 && EQ (XWINDOW (selected_window
)->contents
, new_current_buffer
)
5537 && !EQ (selected_window
, data
->current_window
))
5538 old_point
= marker_position (XWINDOW (data
->current_window
)->pointm
);
5542 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
5543 point in new_current_buffer as of the last time this buffer was
5544 used. This can be non-deterministic since it can be changed by
5545 things like jit-lock by mere temporary selection of some random
5546 window that happens to show this buffer.
5547 So if possible we want this arbitrary choice of "which point" to
5548 be the one from the to-be-selected-window so as to prevent this
5549 window's cursor from being copied from another window. */
5550 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
)
5551 /* If current_window = selected_window, its point is in BUF_PT. */
5552 && !EQ (selected_window
, data
->current_window
))
5553 old_point
= marker_position (XWINDOW (data
->current_window
)->pointm
);
5555 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
5558 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5561 /* If f is a dead frame, don't bother rebuilding its window tree.
5562 However, there is other stuff we should still try to do below. */
5563 if (FRAME_LIVE_P (f
))
5566 Lisp_Object dead_windows
= Qnil
;
5567 register Lisp_Object tem
, par
, pers
;
5568 register struct window
*w
;
5569 register struct saved_window
*p
;
5570 struct window
*root_window
;
5571 struct window
**leaf_windows
;
5576 /* If the frame has been resized since this window configuration was
5577 made, we change the frame to the size specified in the
5578 configuration, restore the configuration, and then resize it
5579 back. We keep track of the prevailing height in these variables. */
5580 int previous_frame_lines
= FRAME_LINES (f
);
5581 int previous_frame_cols
= FRAME_COLS (f
);
5582 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
5583 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
5585 /* Don't do this within the main loop below: This may call Lisp
5586 code and is thus potentially unsafe while input is blocked. */
5587 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
5589 p
= SAVED_WINDOW_N (saved_windows
, k
);
5591 w
= XWINDOW (window
);
5592 if (BUFFERP (w
->contents
)
5593 && !EQ (w
->contents
, p
->buffer
)
5594 && BUFFER_LIVE_P (XBUFFER (p
->buffer
)))
5595 /* If a window we restore gets another buffer, record the
5596 window's old buffer. */
5597 call1 (Qrecord_window_buffer
, window
);
5600 /* The mouse highlighting code could get screwed up
5601 if it runs during this. */
5604 if (data
->frame_lines
!= previous_frame_lines
5605 || data
->frame_cols
!= previous_frame_cols
)
5606 change_frame_size (f
, data
->frame_lines
,
5607 data
->frame_cols
, 0, 0, 0);
5608 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5609 if (data
->frame_menu_bar_lines
5610 != previous_frame_menu_bar_lines
)
5611 x_set_menu_bar_lines (f
, make_number (data
->frame_menu_bar_lines
),
5613 #ifdef HAVE_WINDOW_SYSTEM
5614 if (data
->frame_tool_bar_lines
5615 != previous_frame_tool_bar_lines
)
5616 x_set_tool_bar_lines (f
, make_number (data
->frame_tool_bar_lines
),
5621 /* "Swap out" point from the selected window's buffer
5622 into the window itself. (Normally the pointm of the selected
5623 window holds garbage.) We do this now, before
5624 restoring the window contents, and prevent it from
5625 being done later on when we select a new window. */
5626 if (! NILP (XWINDOW (selected_window
)->contents
))
5628 w
= XWINDOW (selected_window
);
5629 set_marker_both (w
->pointm
,
5631 BUF_PT (XBUFFER (w
->contents
)),
5632 BUF_PT_BYTE (XBUFFER (w
->contents
)));
5635 windows_or_buffers_changed
++;
5636 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
5638 /* Problem: Freeing all matrices and later allocating them again
5639 is a serious redisplay flickering problem. What we would
5640 really like to do is to free only those matrices not reused
5642 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5643 leaf_windows
= alloca (count_windows (root_window
)
5644 * sizeof *leaf_windows
);
5645 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
5648 Mark all windows now on frame as "deleted".
5649 Restoring the new configuration "undeletes" any that are in it.
5651 Save their current buffers in their height fields, since we may
5652 need it later, if a buffer saved in the configuration is now
5654 delete_all_child_windows (FRAME_ROOT_WINDOW (f
));
5656 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
5658 p
= SAVED_WINDOW_N (saved_windows
, k
);
5660 w
= XWINDOW (window
);
5661 wset_next (w
, Qnil
);
5663 if (!NILP (p
->parent
))
5665 (w
, SAVED_WINDOW_N (saved_windows
, XFASTINT (p
->parent
))->window
);
5667 wset_parent (w
, Qnil
);
5669 if (!NILP (p
->prev
))
5672 (w
, SAVED_WINDOW_N (saved_windows
, XFASTINT (p
->prev
))->window
);
5673 wset_next (XWINDOW (w
->prev
), p
->window
);
5677 wset_prev (w
, Qnil
);
5678 if (!NILP (w
->parent
))
5679 wset_combination (XWINDOW (w
->parent
),
5680 (XINT (p
->total_cols
)
5681 != XWINDOW (w
->parent
)->total_cols
),
5685 /* If we squirreled away the buffer, restore it now. */
5686 if (BUFFERP (w
->combination_limit
))
5687 wset_buffer (w
, w
->combination_limit
);
5688 w
->left_col
= XFASTINT (p
->left_col
);
5689 w
->top_line
= XFASTINT (p
->top_line
);
5690 w
->total_cols
= XFASTINT (p
->total_cols
);
5691 w
->total_lines
= XFASTINT (p
->total_lines
);
5692 wset_normal_cols (w
, p
->normal_cols
);
5693 wset_normal_lines (w
, p
->normal_lines
);
5694 w
->hscroll
= XFASTINT (p
->hscroll
);
5695 w
->min_hscroll
= XFASTINT (p
->min_hscroll
);
5696 wset_display_table (w
, p
->display_table
);
5697 wset_left_margin_cols (w
, p
->left_margin_cols
);
5698 wset_right_margin_cols (w
, p
->right_margin_cols
);
5699 wset_left_fringe_width (w
, p
->left_fringe_width
);
5700 wset_right_fringe_width (w
, p
->right_fringe_width
);
5701 w
->fringes_outside_margins
= !NILP (p
->fringes_outside_margins
);
5702 wset_scroll_bar_width (w
, p
->scroll_bar_width
);
5703 wset_vertical_scroll_bar_type (w
, p
->vertical_scroll_bar_type
);
5704 wset_dedicated (w
, p
->dedicated
);
5705 wset_combination_limit (w
, p
->combination_limit
);
5706 /* Restore any window parameters that have been saved.
5707 Parameters that have not been saved are left alone. */
5708 for (tem
= p
->window_parameters
; CONSP (tem
); tem
= XCDR (tem
))
5713 if (NILP (XCDR (pers
)))
5715 par
= Fassq (XCAR (pers
), w
->window_parameters
);
5716 if (CONSP (par
) && !NILP (XCDR (par
)))
5717 /* Reset a parameter to nil if and only if it
5718 has a non-nil association. Don't make new
5720 Fsetcdr (par
, Qnil
);
5723 /* Always restore a non-nil value. */
5724 Fset_window_parameter (window
, XCAR (pers
), XCDR (pers
));
5728 if (BUFFERP (p
->buffer
) && BUFFER_LIVE_P (XBUFFER (p
->buffer
)))
5729 /* If saved buffer is alive, install it. */
5731 wset_buffer (w
, p
->buffer
);
5732 w
->start_at_line_beg
= !NILP (p
->start_at_line_beg
);
5733 set_marker_restricted (w
->start
, p
->start
, w
->contents
);
5734 set_marker_restricted (w
->pointm
, p
->pointm
,
5736 Fset_marker (BVAR (XBUFFER (w
->contents
), mark
),
5737 p
->mark
, w
->contents
);
5739 /* As documented in Fcurrent_window_configuration, don't
5740 restore the location of point in the buffer which was
5741 current when the window configuration was recorded. */
5742 if (!EQ (p
->buffer
, new_current_buffer
)
5743 && XBUFFER (p
->buffer
) == current_buffer
)
5744 Fgoto_char (w
->pointm
);
5746 else if (BUFFERP (w
->contents
) && BUFFER_LIVE_P (XBUFFER (w
->contents
)))
5747 /* Keep window's old buffer; make sure the markers are real. */
5749 /* Set window markers at start of visible range. */
5750 if (XMARKER (w
->start
)->buffer
== 0)
5751 set_marker_restricted_both (w
->start
, w
->contents
, 0, 0);
5752 if (XMARKER (w
->pointm
)->buffer
== 0)
5753 set_marker_restricted_both
5754 (w
->pointm
, w
->contents
,
5755 BUF_PT (XBUFFER (w
->contents
)),
5756 BUF_PT_BYTE (XBUFFER (w
->contents
)));
5757 w
->start_at_line_beg
= 1;
5759 else if (!NILP (w
->start
))
5760 /* Leaf window has no live buffer, get one. */
5762 /* Get the buffer via other_buffer_safely in order to
5763 avoid showing an unimportant buffer and, if necessary, to
5764 recreate *scratch* in the course (part of Juanma's bs-show
5765 scenario from March 2011). */
5766 wset_buffer (w
, other_buffer_safely (Fcurrent_buffer ()));
5767 /* This will set the markers to beginning of visible
5769 set_marker_restricted_both (w
->start
, w
->contents
, 0, 0);
5770 set_marker_restricted_both (w
->pointm
, w
->contents
, 0, 0);
5771 w
->start_at_line_beg
= 1;
5772 if (!NILP (w
->dedicated
))
5773 /* Record this window as dead. */
5774 dead_windows
= Fcons (window
, dead_windows
);
5775 /* Make sure window is no more dedicated. */
5776 wset_dedicated (w
, Qnil
);
5780 fset_root_window (f
, data
->root_window
);
5781 /* Arrange *not* to restore point in the buffer that was
5782 current when the window configuration was saved. */
5783 if (EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
))
5784 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
5785 make_number (old_point
),
5786 XWINDOW (data
->current_window
)->contents
);
5788 /* In the following call to `select-window', prevent "swapping out
5789 point" in the old selected window using the buffer that has
5790 been restored into it. We already swapped out that point from
5791 that window's old buffer. */
5792 select_window (data
->current_window
, Qnil
, 1);
5793 BVAR (XBUFFER (XWINDOW (selected_window
)->contents
), last_selected_window
)
5796 if (NILP (data
->focus_frame
)
5797 || (FRAMEP (data
->focus_frame
)
5798 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
5799 Fredirect_frame_focus (frame
, data
->focus_frame
);
5801 /* Set the screen height to the value it had before this function. */
5802 if (previous_frame_lines
!= FRAME_LINES (f
)
5803 || previous_frame_cols
!= FRAME_COLS (f
))
5804 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
5806 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5807 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
5808 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
5810 #ifdef HAVE_WINDOW_SYSTEM
5811 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
5812 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
5817 /* Now, free glyph matrices in windows that were not reused. */
5818 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
5820 if (NILP (leaf_windows
[i
]->contents
))
5821 free_window_matrices (leaf_windows
[i
]);
5822 else if (EQ (leaf_windows
[i
]->contents
, new_current_buffer
))
5829 /* Scan dead buffer windows. */
5830 for (; CONSP (dead_windows
); dead_windows
= XCDR (dead_windows
))
5832 window
= XCAR (dead_windows
);
5833 if (WINDOW_LIVE_P (window
) && !EQ (window
, FRAME_ROOT_WINDOW (f
)))
5834 delete_deletable_window (window
);
5837 /* Fselect_window will have made f the selected frame, so we
5838 reselect the proper frame here. Fhandle_switch_frame will change the
5839 selected window too, but that doesn't make the call to
5840 Fselect_window above totally superfluous; it still sets f's
5842 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
5843 do_switch_frame (data
->selected_frame
, 0, 0, Qnil
);
5845 run_window_configuration_change_hook (f
);
5848 if (!NILP (new_current_buffer
))
5850 Fset_buffer (new_current_buffer
);
5851 /* If the new current buffer doesn't appear in the selected
5852 window, go to its old point (see bug#12208). */
5853 if (!EQ (XWINDOW (data
->current_window
)->contents
, new_current_buffer
))
5854 Fgoto_char (make_number (old_point
));
5857 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
5858 minibuf_selected_window
= data
->minibuf_selected_window
;
5860 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
5864 restore_window_configuration (Lisp_Object configuration
)
5866 Fset_window_configuration (configuration
);
5870 /* If WINDOW is an internal window, recursively delete all child windows
5871 reachable via the next and contents slots of WINDOW. Otherwise setup
5872 WINDOW to not show any buffer. */
5875 delete_all_child_windows (Lisp_Object window
)
5877 register struct window
*w
;
5879 w
= XWINDOW (window
);
5881 if (!NILP (w
->next
))
5882 /* Delete WINDOW's siblings (we traverse postorderly). */
5883 delete_all_child_windows (w
->next
);
5885 if (WINDOWP (w
->contents
))
5887 delete_all_child_windows (w
->contents
);
5888 wset_combination (w
, 0, Qnil
);
5890 else if (BUFFERP (w
->contents
))
5893 unchain_marker (XMARKER (w
->pointm
));
5894 unchain_marker (XMARKER (w
->start
));
5895 /* Since combination limit makes sense for an internal windows
5896 only, we use this slot to save the buffer for the sake of
5897 possible resurrection in Fset_window_configuration. */
5898 wset_combination_limit (w
, w
->contents
);
5899 wset_buffer (w
, Qnil
);
5902 Vwindow_list
= Qnil
;
5906 count_windows (register struct window
*window
)
5908 register int count
= 1;
5909 if (!NILP (window
->next
))
5910 count
+= count_windows (XWINDOW (window
->next
));
5911 if (WINDOWP (window
->contents
))
5912 count
+= count_windows (XWINDOW (window
->contents
));
5917 /* Fill vector FLAT with leaf windows under W, starting at index I.
5918 Value is last index + 1. */
5920 get_leaf_windows (struct window
*w
, struct window
**flat
, int i
)
5924 if (WINDOWP (w
->contents
))
5925 i
= get_leaf_windows (XWINDOW (w
->contents
), flat
, i
);
5929 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5936 /* Return a pointer to the glyph W's physical cursor is on. Value is
5937 null if W's current matrix is invalid, so that no meaningful glyph
5940 get_phys_cursor_glyph (struct window
*w
)
5942 struct glyph_row
*row
;
5943 struct glyph
*glyph
;
5944 int hpos
= w
->phys_cursor
.hpos
;
5946 if (!(w
->phys_cursor
.vpos
>= 0
5947 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
))
5950 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
5951 if (!row
->enabled_p
)
5956 /* When the window is hscrolled, cursor hpos can legitimately be
5957 out of bounds, but we draw the cursor at the corresponding
5958 window margin in that case. */
5959 if (!row
->reversed_p
&& hpos
< 0)
5961 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
5962 hpos
= row
->used
[TEXT_AREA
] - 1;
5965 if (0 <= hpos
&& hpos
< row
->used
[TEXT_AREA
])
5966 glyph
= row
->glyphs
[TEXT_AREA
] + hpos
;
5975 save_window_save (Lisp_Object window
, struct Lisp_Vector
*vector
, int i
)
5977 register struct saved_window
*p
;
5978 register struct window
*w
;
5979 register Lisp_Object tem
, pers
, par
;
5981 for (; !NILP (window
); window
= w
->next
)
5983 p
= SAVED_WINDOW_N (vector
, i
);
5984 w
= XWINDOW (window
);
5986 wset_temslot (w
, make_number (i
)); i
++;
5988 p
->buffer
= (WINDOW_LEAF_P (w
) ? w
->contents
: Qnil
);
5989 p
->left_col
= make_number (w
->left_col
);
5990 p
->top_line
= make_number (w
->top_line
);
5991 p
->total_cols
= make_number (w
->total_cols
);
5992 p
->total_lines
= make_number (w
->total_lines
);
5993 p
->normal_cols
= w
->normal_cols
;
5994 p
->normal_lines
= w
->normal_lines
;
5995 XSETFASTINT (p
->hscroll
, w
->hscroll
);
5996 XSETFASTINT (p
->min_hscroll
, w
->min_hscroll
);
5997 p
->display_table
= w
->display_table
;
5998 p
->left_margin_cols
= w
->left_margin_cols
;
5999 p
->right_margin_cols
= w
->right_margin_cols
;
6000 p
->left_fringe_width
= w
->left_fringe_width
;
6001 p
->right_fringe_width
= w
->right_fringe_width
;
6002 p
->fringes_outside_margins
= w
->fringes_outside_margins
? Qt
: Qnil
;
6003 p
->scroll_bar_width
= w
->scroll_bar_width
;
6004 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
6005 p
->dedicated
= w
->dedicated
;
6006 p
->combination_limit
= w
->combination_limit
;
6007 p
->window_parameters
= Qnil
;
6009 if (!NILP (Vwindow_persistent_parameters
))
6011 /* Run cycle detection on Vwindow_persistent_parameters. */
6012 Lisp_Object tortoise
, hare
;
6014 hare
= tortoise
= Vwindow_persistent_parameters
;
6015 while (CONSP (hare
))
6022 tortoise
= XCDR (tortoise
);
6024 if (EQ (hare
, tortoise
))
6025 /* Reset Vwindow_persistent_parameters to Qnil. */
6027 Vwindow_persistent_parameters
= Qnil
;
6032 for (tem
= Vwindow_persistent_parameters
; CONSP (tem
);
6036 /* Save values for persistent window parameters. */
6037 if (CONSP (pers
) && !NILP (XCDR (pers
)))
6039 par
= Fassq (XCAR (pers
), w
->window_parameters
);
6041 /* If the window has no value for the parameter,
6043 p
->window_parameters
= Fcons (Fcons (XCAR (pers
), Qnil
),
6044 p
->window_parameters
);
6046 /* If the window has a value for the parameter,
6048 p
->window_parameters
= Fcons (Fcons (XCAR (par
),
6050 p
->window_parameters
);
6055 if (BUFFERP (w
->contents
))
6057 /* Save w's value of point in the window configuration. If w
6058 is the selected window, then get the value of point from
6059 the buffer; pointm is garbage in the selected window. */
6060 if (EQ (window
, selected_window
))
6061 p
->pointm
= build_marker (XBUFFER (w
->contents
),
6062 BUF_PT (XBUFFER (w
->contents
)),
6063 BUF_PT_BYTE (XBUFFER (w
->contents
)));
6065 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
6066 XMARKER (p
->pointm
)->insertion_type
6067 = !NILP (Vwindow_point_insertion_type
);
6069 p
->start
= Fcopy_marker (w
->start
, Qnil
);
6070 p
->start_at_line_beg
= w
->start_at_line_beg
? Qt
: Qnil
;
6072 tem
= BVAR (XBUFFER (w
->contents
), mark
);
6073 p
->mark
= Fcopy_marker (tem
, Qnil
);
6080 p
->start_at_line_beg
= Qnil
;
6083 if (NILP (w
->parent
))
6086 p
->parent
= XWINDOW (w
->parent
)->temslot
;
6091 p
->prev
= XWINDOW (w
->prev
)->temslot
;
6093 if (WINDOWP (w
->contents
))
6094 i
= save_window_save (w
->contents
, vector
, i
);
6100 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
6101 Scurrent_window_configuration
, 0, 1, 0,
6102 doc
: /* Return an object representing the current window configuration of FRAME.
6103 If FRAME is nil or omitted, use the selected frame.
6104 This describes the number of windows, their sizes and current buffers,
6105 and for each displayed buffer, where display starts, and the positions of
6106 point and mark. An exception is made for point in the current buffer:
6107 its value is -not- saved.
6108 This also records the currently selected frame, and FRAME's focus
6109 redirection (see `redirect-frame-focus'). The variable
6110 `window-persistent-parameters' specifies which window parameters are
6111 saved by this function. */)
6114 register Lisp_Object tem
;
6115 register int n_windows
;
6116 register struct save_window_data
*data
;
6118 struct frame
*f
= decode_live_frame (frame
);
6120 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6121 data
= ALLOCATE_PSEUDOVECTOR (struct save_window_data
, frame_cols
,
6122 PVEC_WINDOW_CONFIGURATION
);
6124 data
->frame_cols
= FRAME_COLS (f
);
6125 data
->frame_lines
= FRAME_LINES (f
);
6126 data
->frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6127 data
->frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6128 data
->selected_frame
= selected_frame
;
6129 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6130 XSETBUFFER (data
->current_buffer
, current_buffer
);
6131 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6132 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6133 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6134 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6135 tem
= make_uninit_vector (n_windows
);
6136 data
->saved_windows
= tem
;
6137 for (i
= 0; i
< n_windows
; i
++)
6139 Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
));
6140 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6141 XSETWINDOW_CONFIGURATION (tem
, data
);
6145 /***********************************************************************
6147 ***********************************************************************/
6149 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6151 doc
: /* Set width of marginal areas of window WINDOW.
6152 WINDOW must be a live window and defaults to the selected one.
6154 Second arg LEFT-WIDTH specifies the number of character cells to
6155 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6156 does the same for the right marginal area. A nil width parameter
6157 means no margin. */)
6158 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
)
6160 struct window
*w
= decode_live_window (window
);
6162 /* Translate negative or zero widths to nil.
6163 Margins that are too wide have to be checked elsewhere. */
6165 if (!NILP (left_width
))
6167 CHECK_NUMBER (left_width
);
6168 if (XINT (left_width
) <= 0)
6172 if (!NILP (right_width
))
6174 CHECK_NUMBER (right_width
);
6175 if (XINT (right_width
) <= 0)
6179 if (!EQ (w
->left_margin_cols
, left_width
)
6180 || !EQ (w
->right_margin_cols
, right_width
))
6182 wset_left_margin_cols (w
, left_width
);
6183 wset_right_margin_cols (w
, right_width
);
6185 adjust_window_margins (w
);
6187 ++windows_or_buffers_changed
;
6188 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6195 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6197 doc
: /* Get width of marginal areas of window WINDOW.
6198 WINDOW must be a live window and defaults to the selected one.
6200 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6201 If a marginal area does not exist, its width will be returned
6203 (Lisp_Object window
)
6205 struct window
*w
= decode_live_window (window
);
6206 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
6211 /***********************************************************************
6213 ***********************************************************************/
6215 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6217 doc
: /* Set the fringe widths of window WINDOW.
6218 WINDOW must be a live window and defaults to the selected one.
6220 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6221 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6222 fringe width. If a fringe width arg is nil, that means to use the
6223 frame's default fringe width. Default fringe widths can be set with
6224 the command `set-fringe-style'.
6225 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6226 outside of the display margins. By default, fringes are drawn between
6227 display marginal areas and the text area. */)
6228 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
, Lisp_Object outside_margins
)
6230 struct window
*w
= decode_live_window (window
);
6231 int outside
= !NILP (outside_margins
);
6233 if (!NILP (left_width
))
6234 CHECK_NATNUM (left_width
);
6235 if (!NILP (right_width
))
6236 CHECK_NATNUM (right_width
);
6238 /* Do nothing on a tty. */
6239 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6240 && (!EQ (w
->left_fringe_width
, left_width
)
6241 || !EQ (w
->right_fringe_width
, right_width
)
6242 || w
->fringes_outside_margins
!= outside
))
6244 wset_left_fringe_width (w
, left_width
);
6245 wset_right_fringe_width (w
, right_width
);
6246 w
->fringes_outside_margins
= outside
;
6248 adjust_window_margins (w
);
6250 clear_glyph_matrix (w
->current_matrix
);
6251 w
->window_end_valid
= 0;
6253 ++windows_or_buffers_changed
;
6254 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6261 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6263 doc
: /* Get width of fringes of window WINDOW.
6264 WINDOW must be a live window and defaults to the selected one.
6266 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6267 (Lisp_Object window
)
6269 struct window
*w
= decode_live_window (window
);
6271 return list3 (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6272 make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6273 WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
) ? Qt
: Qnil
);
6278 /***********************************************************************
6280 ***********************************************************************/
6282 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
,
6283 Sset_window_scroll_bars
, 2, 4, 0,
6284 doc
: /* Set width and type of scroll bars of window WINDOW.
6285 WINDOW must be a live window and defaults to the selected one.
6287 Second parameter WIDTH specifies the pixel width for the scroll bar;
6288 this is automatically adjusted to a multiple of the frame column width.
6289 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6290 bar: left, right, or nil.
6291 If WIDTH is nil, use the frame's scroll-bar width.
6292 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6293 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6294 (Lisp_Object window
, Lisp_Object width
, Lisp_Object vertical_type
, Lisp_Object horizontal_type
)
6296 struct window
*w
= decode_live_window (window
);
6300 CHECK_RANGED_INTEGER (width
, 0, INT_MAX
);
6302 if (XINT (width
) == 0)
6303 vertical_type
= Qnil
;
6306 if (!(NILP (vertical_type
)
6307 || EQ (vertical_type
, Qleft
)
6308 || EQ (vertical_type
, Qright
)
6309 || EQ (vertical_type
, Qt
)))
6310 error ("Invalid type of vertical scroll bar");
6312 if (!EQ (w
->scroll_bar_width
, width
)
6313 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6315 wset_scroll_bar_width (w
, width
);
6316 wset_vertical_scroll_bar_type (w
, vertical_type
);
6318 adjust_window_margins (w
);
6320 clear_glyph_matrix (w
->current_matrix
);
6321 w
->window_end_valid
= 0;
6323 ++windows_or_buffers_changed
;
6324 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6331 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6333 doc
: /* Get width and type of scroll bars of window WINDOW.
6334 WINDOW must be a live window and defaults to the selected one.
6336 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6337 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6339 (Lisp_Object window
)
6341 struct window
*w
= decode_live_window (window
);
6343 return list4 (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6344 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6345 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6346 make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6347 w
->vertical_scroll_bar_type
, Qnil
);
6352 /***********************************************************************
6354 ***********************************************************************/
6356 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6357 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6358 If WINDOW is omitted or nil, it defaults to the selected window.
6359 Normally, value is a multiple of the canonical character height of WINDOW;
6360 optional second arg PIXELS-P means value is measured in pixels. */)
6361 (Lisp_Object window
, Lisp_Object pixels_p
)
6364 struct window
*w
= decode_live_window (window
);
6365 struct frame
*f
= XFRAME (w
->frame
);
6367 if (FRAME_WINDOW_P (f
))
6368 result
= (NILP (pixels_p
)
6369 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6370 : make_number (-w
->vscroll
));
6372 result
= make_number (0);
6377 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6379 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6380 WINDOW nil means use the selected window. Normally, VSCROLL is a
6381 non-negative multiple of the canonical character height of WINDOW;
6382 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
6383 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6384 corresponds to an integral number of pixels. The return value is the
6385 result of this rounding.
6386 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6387 (Lisp_Object window
, Lisp_Object vscroll
, Lisp_Object pixels_p
)
6389 struct window
*w
= decode_live_window (window
);
6390 struct frame
*f
= XFRAME (w
->frame
);
6392 CHECK_NUMBER_OR_FLOAT (vscroll
);
6394 if (FRAME_WINDOW_P (f
))
6396 int old_dy
= w
->vscroll
;
6398 w
->vscroll
= - (NILP (pixels_p
)
6399 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
6400 : XFLOATINT (vscroll
));
6401 w
->vscroll
= min (w
->vscroll
, 0);
6403 if (w
->vscroll
!= old_dy
)
6405 /* Adjust glyph matrix of the frame if the virtual display
6406 area becomes larger than before. */
6407 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
6410 /* Prevent redisplay shortcuts. */
6411 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
6415 return Fwindow_vscroll (window
, pixels_p
);
6419 /* Call FN for all leaf windows on frame F. FN is called with the
6420 first argument being a pointer to the leaf window, and with
6421 additional argument USER_DATA. Stops when FN returns 0. */
6424 foreach_window (struct frame
*f
, int (*fn
) (struct window
*, void *),
6427 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
6428 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
6429 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
6433 /* Helper function for foreach_window. Call FN for all leaf windows
6434 reachable from W. FN is called with the first argument being a
6435 pointer to the leaf window, and with additional argument USER_DATA.
6436 Stop when FN returns 0. Value is 0 if stopped by FN. */
6439 foreach_window_1 (struct window
*w
, int (*fn
) (struct window
*, void *), void *user_data
)
6443 for (cont
= 1; w
&& cont
;)
6445 if (WINDOWP (w
->contents
))
6446 cont
= foreach_window_1 (XWINDOW (w
->contents
), fn
, user_data
);
6448 cont
= fn (w
, user_data
);
6450 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6457 /* Freeze or unfreeze the window start of W unless it is a
6458 mini-window or the selected window. FREEZE_P non-null means freeze
6459 the window start. */
6462 freeze_window_start (struct window
*w
, void *freeze_p
)
6464 if (MINI_WINDOW_P (w
)
6465 || (WINDOWP (selected_window
) /* Can be nil in corner cases. */
6466 && (w
== XWINDOW (selected_window
)
6467 || (MINI_WINDOW_P (XWINDOW (selected_window
))
6468 && ! NILP (Vminibuf_scroll_window
)
6469 && w
== XWINDOW (Vminibuf_scroll_window
)))))
6472 w
->frozen_window_start_p
= freeze_p
!= NULL
;
6477 /* Freeze or unfreeze the window starts of all leaf windows on frame
6478 F, except the selected window and a mini-window. FREEZE_P non-zero
6479 means freeze the window start. */
6482 freeze_window_starts (struct frame
*f
, bool freeze_p
)
6484 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
6488 /***********************************************************************
6490 ***********************************************************************/
6492 /* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2
6493 describe the same state of affairs. This is used by Fequal.
6495 IGNORE_POSITIONS means ignore non-matching scroll positions
6498 This ignores a couple of things like the dedication status of
6499 window, combination_limit and the like. This might have to be
6503 compare_window_configurations (Lisp_Object configuration1
,
6504 Lisp_Object configuration2
,
6505 bool ignore_positions
)
6507 register struct save_window_data
*d1
, *d2
;
6508 struct Lisp_Vector
*sws1
, *sws2
;
6511 CHECK_WINDOW_CONFIGURATION (configuration1
);
6512 CHECK_WINDOW_CONFIGURATION (configuration2
);
6514 d1
= (struct save_window_data
*) XVECTOR (configuration1
);
6515 d2
= (struct save_window_data
*) XVECTOR (configuration2
);
6516 sws1
= XVECTOR (d1
->saved_windows
);
6517 sws2
= XVECTOR (d2
->saved_windows
);
6519 /* Frame settings must match. */
6520 if (d1
->frame_cols
!= d2
->frame_cols
6521 || d1
->frame_lines
!= d2
->frame_lines
6522 || d1
->frame_menu_bar_lines
!= d2
->frame_menu_bar_lines
6523 || !EQ (d1
->selected_frame
, d2
->selected_frame
)
6524 || !EQ (d1
->current_buffer
, d2
->current_buffer
)
6525 || (!ignore_positions
6526 && (!EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
)
6527 || !EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
)))
6528 || !EQ (d1
->focus_frame
, d2
->focus_frame
)
6529 /* Verify that the two configurations have the same number of windows. */
6530 || sws1
->header
.size
!= sws2
->header
.size
)
6533 for (i
= 0; i
< sws1
->header
.size
; i
++)
6535 struct saved_window
*sw1
, *sw2
;
6537 sw1
= SAVED_WINDOW_N (sws1
, i
);
6538 sw2
= SAVED_WINDOW_N (sws2
, i
);
6541 /* The "current" windows in the two configurations must
6542 correspond to each other. */
6543 EQ (d1
->current_window
, sw1
->window
)
6544 != EQ (d2
->current_window
, sw2
->window
)
6545 /* Windows' buffers must match. */
6546 || !EQ (sw1
->buffer
, sw2
->buffer
)
6547 || !EQ (sw1
->left_col
, sw2
->left_col
)
6548 || !EQ (sw1
->top_line
, sw2
->top_line
)
6549 || !EQ (sw1
->total_cols
, sw2
->total_cols
)
6550 || !EQ (sw1
->total_lines
, sw2
->total_lines
)
6551 || !EQ (sw1
->display_table
, sw2
->display_table
)
6552 /* The next two disjuncts check the window structure for
6554 || !EQ (sw1
->parent
, sw2
->parent
)
6555 || !EQ (sw1
->prev
, sw2
->prev
)
6556 || (!ignore_positions
6557 && (!EQ (sw1
->hscroll
, sw2
->hscroll
)
6558 || !EQ (sw1
->min_hscroll
, sw2
->min_hscroll
)
6559 || !EQ (sw1
->start_at_line_beg
, sw2
->start_at_line_beg
)
6560 || NILP (Fequal (sw1
->start
, sw2
->start
))
6561 || NILP (Fequal (sw1
->pointm
, sw2
->pointm
))
6562 || NILP (Fequal (sw1
->mark
, sw2
->mark
))))
6563 || !EQ (sw1
->left_margin_cols
, sw2
->left_margin_cols
)
6564 || !EQ (sw1
->right_margin_cols
, sw2
->right_margin_cols
)
6565 || !EQ (sw1
->left_fringe_width
, sw2
->left_fringe_width
)
6566 || !EQ (sw1
->right_fringe_width
, sw2
->right_fringe_width
)
6567 || !EQ (sw1
->fringes_outside_margins
, sw2
->fringes_outside_margins
)
6568 || !EQ (sw1
->scroll_bar_width
, sw2
->scroll_bar_width
)
6569 || !EQ (sw1
->vertical_scroll_bar_type
, sw2
->vertical_scroll_bar_type
))
6576 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
6577 Scompare_window_configurations
, 2, 2, 0,
6578 doc
: /* Compare two window configurations as regards the structure of windows.
6579 This function ignores details such as the values of point and mark
6580 and scrolling positions. */)
6581 (Lisp_Object x
, Lisp_Object y
)
6583 if (compare_window_configurations (x
, y
, 1))
6589 init_window_once (void)
6591 struct frame
*f
= make_initial_frame ();
6592 XSETFRAME (selected_frame
, f
);
6593 Vterminal_frame
= selected_frame
;
6594 minibuf_window
= f
->minibuffer_window
;
6595 selected_window
= f
->selected_window
;
6596 last_nonminibuf_frame
= f
;
6598 window_initialized
= 1;
6604 Vwindow_list
= Qnil
;
6608 syms_of_window (void)
6610 DEFSYM (Qscroll_up
, "scroll-up");
6611 DEFSYM (Qscroll_down
, "scroll-down");
6612 DEFSYM (Qscroll_command
, "scroll-command");
6614 Fput (Qscroll_up
, Qscroll_command
, Qt
);
6615 Fput (Qscroll_down
, Qscroll_command
, Qt
);
6617 DEFSYM (Qwindow_configuration_change_hook
, "window-configuration-change-hook");
6618 DEFSYM (Qwindowp
, "windowp");
6619 DEFSYM (Qwindow_configuration_p
, "window-configuration-p");
6620 DEFSYM (Qwindow_live_p
, "window-live-p");
6621 DEFSYM (Qwindow_valid_p
, "window-valid-p");
6622 DEFSYM (Qwindow_deletable_p
, "window-deletable-p");
6623 DEFSYM (Qdelete_window
, "delete-window");
6624 DEFSYM (Qwindow_resize_root_window
, "window--resize-root-window");
6625 DEFSYM (Qwindow_resize_root_window_vertically
, "window--resize-root-window-vertically");
6626 DEFSYM (Qsafe
, "safe");
6627 DEFSYM (Qdisplay_buffer
, "display-buffer");
6628 DEFSYM (Qreplace_buffer_in_windows
, "replace-buffer-in-windows");
6629 DEFSYM (Qrecord_window_buffer
, "record-window-buffer");
6630 DEFSYM (Qget_mru_window
, "get-mru-window");
6631 DEFSYM (Qwindow_size
, "window-size");
6632 DEFSYM (Qtemp_buffer_show_hook
, "temp-buffer-show-hook");
6633 DEFSYM (Qabove
, "above");
6634 DEFSYM (Qbelow
, "below");
6635 DEFSYM (Qclone_of
, "clone-of");
6637 staticpro (&Vwindow_list
);
6639 minibuf_selected_window
= Qnil
;
6640 staticpro (&minibuf_selected_window
);
6642 window_scroll_pixel_based_preserve_x
= -1;
6643 window_scroll_pixel_based_preserve_y
= -1;
6644 window_scroll_preserve_hpos
= -1;
6645 window_scroll_preserve_vpos
= -1;
6647 DEFVAR_LISP ("temp-buffer-show-function", Vtemp_buffer_show_function
,
6648 doc
: /* Non-nil means call as function to display a help buffer.
6649 The function is called with one argument, the buffer to be displayed.
6650 Used by `with-output-to-temp-buffer'.
6651 If this function is used, then it must do the entire job of showing
6652 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6653 Vtemp_buffer_show_function
= Qnil
;
6655 DEFVAR_LISP ("minibuffer-scroll-window", Vminibuf_scroll_window
,
6656 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6657 Vminibuf_scroll_window
= Qnil
;
6659 DEFVAR_BOOL ("mode-line-in-non-selected-windows", mode_line_in_non_selected_windows
,
6660 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6661 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6662 is displayed in the `mode-line' face. */);
6663 mode_line_in_non_selected_windows
= 1;
6665 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer
,
6666 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6667 Vother_window_scroll_buffer
= Qnil
;
6669 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p
,
6670 doc
: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
6671 auto_window_vscroll_p
= 1;
6673 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines
,
6674 doc
: /* Number of lines of continuity when scrolling by screenfuls. */);
6675 next_screen_context_lines
= 2;
6677 DEFVAR_LISP ("scroll-preserve-screen-position",
6678 Vscroll_preserve_screen_position
,
6679 doc
: /* Controls if scroll commands move point to keep its screen position unchanged.
6680 A value of nil means point does not keep its screen position except
6681 at the scroll margin or window boundary respectively.
6682 A value of t means point keeps its screen position if the scroll
6683 command moved it vertically out of the window, e.g. when scrolling
6685 Any other value means point always keeps its screen position.
6686 Scroll commands should have the `scroll-command' property
6687 on their symbols to be controlled by this variable. */);
6688 Vscroll_preserve_screen_position
= Qnil
;
6690 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type
,
6691 doc
: /* Type of marker to use for `window-point'. */);
6692 Vwindow_point_insertion_type
= Qnil
;
6694 DEFVAR_LISP ("window-configuration-change-hook",
6695 Vwindow_configuration_change_hook
,
6696 doc
: /* Functions to call when window configuration changes.
6697 The buffer-local part is run once per window, with the relevant window
6698 selected; while the global part is run only once for the modified frame,
6699 with the relevant frame selected. */);
6700 Vwindow_configuration_change_hook
= Qnil
;
6702 DEFVAR_LISP ("recenter-redisplay", Vrecenter_redisplay
,
6703 doc
: /* Non-nil means `recenter' redraws entire frame.
6704 If this option is non-nil, then the `recenter' command with a nil
6705 argument will redraw the entire frame; the special value `tty' causes
6706 the frame to be redrawn only if it is a tty frame. */);
6707 Vrecenter_redisplay
= Qtty
;
6709 DEFVAR_LISP ("window-combination-resize", Vwindow_combination_resize
,
6710 doc
: /* If t, resize window combinations proportionally.
6711 If this variable is nil, splitting a window gets the entire screen space
6712 for displaying the new window from the window to split. Deleting and
6713 resizing a window preferably resizes one adjacent window only.
6715 If this variable is t, splitting a window tries to get the space
6716 proportionally from all windows in the same combination. This also
6717 allows to split a window that is otherwise too small or of fixed size.
6718 Resizing and deleting a window proportionally resize all windows in the
6721 Other values are reserved for future use.
6723 This variable takes no effect if the variable `window-combination-limit' is
6725 Vwindow_combination_resize
= Qnil
;
6727 DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit
,
6728 doc
: /* If non-nil, splitting a window makes a new parent window.
6729 The following values are recognized:
6731 nil means splitting a window will create a new parent window only if the
6732 window has no parent window or the window shall become part of a
6733 combination orthogonal to the one it is part of.
6735 `window-size' means that splitting a window for displaying a buffer
6736 makes a new parent window provided `display-buffer' is supposed to
6737 explicitly set the window's size due to the presence of a
6738 `window-height' or `window-width' entry in the alist used by
6739 `display-buffer'. Otherwise, this value is handled like nil.
6741 `temp-buffer' means that splitting a window for displaying a temporary
6742 buffer always makes a new parent window. Otherwise, this value is
6745 `display-buffer' means that splitting a window for displaying a buffer
6746 always makes a new parent window. Since temporary buffers are
6747 displayed by the function `display-buffer', this value is stronger
6748 than `temp-buffer'. Splitting a window for other purpose makes a
6749 new parent window only if needed.
6751 t means that splitting a window always creates a new parent window. If
6752 all splits behave this way, each frame's window tree is a binary
6753 tree and every window but the frame's root window has exactly one
6756 Other values are reserved for future use. */);
6757 Vwindow_combination_limit
= Qwindow_size
;
6759 DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters
,
6760 doc
: /* Alist of persistent window parameters.
6761 This alist specifies which window parameters shall get saved by
6762 `current-window-configuration' and `window-state-get' and subsequently
6763 restored to their previous values by `set-window-configuration' and
6766 The car of each entry of this alist is the symbol specifying the
6767 parameter. The cdr is one of the following:
6769 nil means the parameter is neither saved by `window-state-get' nor by
6770 `current-window-configuration'.
6772 t means the parameter is saved by `current-window-configuration' and,
6773 provided its WRITABLE argument is nil, by `window-state-get'.
6775 The symbol `writable' means the parameter is saved unconditionally by
6776 both `current-window-configuration' and `window-state-get'. Do not use
6777 this value for parameters without read syntax (like windows or frames).
6779 Parameters not saved by `current-window-configuration' or
6780 `window-state-get' are left alone by `set-window-configuration'
6781 respectively are not installed by `window-state-put'. */);
6782 Vwindow_persistent_parameters
= list1 (Fcons (Qclone_of
, Qt
));
6784 defsubr (&Sselected_window
);
6785 defsubr (&Sminibuffer_window
);
6786 defsubr (&Swindow_minibuffer_p
);
6787 defsubr (&Swindowp
);
6788 defsubr (&Swindow_valid_p
);
6789 defsubr (&Swindow_live_p
);
6790 defsubr (&Swindow_frame
);
6791 defsubr (&Sframe_root_window
);
6792 defsubr (&Sframe_first_window
);
6793 defsubr (&Sframe_selected_window
);
6794 defsubr (&Sset_frame_selected_window
);
6795 defsubr (&Spos_visible_in_window_p
);
6796 defsubr (&Swindow_line_height
);
6797 defsubr (&Swindow_buffer
);
6798 defsubr (&Swindow_parent
);
6799 defsubr (&Swindow_top_child
);
6800 defsubr (&Swindow_left_child
);
6801 defsubr (&Swindow_next_sibling
);
6802 defsubr (&Swindow_prev_sibling
);
6803 defsubr (&Swindow_combination_limit
);
6804 defsubr (&Sset_window_combination_limit
);
6805 defsubr (&Swindow_use_time
);
6806 defsubr (&Swindow_top_line
);
6807 defsubr (&Swindow_left_column
);
6808 defsubr (&Swindow_total_height
);
6809 defsubr (&Swindow_total_width
);
6810 defsubr (&Swindow_normal_size
);
6811 defsubr (&Swindow_new_total
);
6812 defsubr (&Swindow_new_normal
);
6813 defsubr (&Sset_window_new_total
);
6814 defsubr (&Sset_window_new_normal
);
6815 defsubr (&Swindow_resize_apply
);
6816 defsubr (&Swindow_body_height
);
6817 defsubr (&Swindow_body_width
);
6818 defsubr (&Swindow_hscroll
);
6819 defsubr (&Sset_window_hscroll
);
6820 defsubr (&Swindow_redisplay_end_trigger
);
6821 defsubr (&Sset_window_redisplay_end_trigger
);
6822 defsubr (&Swindow_edges
);
6823 defsubr (&Swindow_pixel_edges
);
6824 defsubr (&Swindow_absolute_pixel_edges
);
6825 defsubr (&Swindow_inside_edges
);
6826 defsubr (&Swindow_inside_pixel_edges
);
6827 defsubr (&Swindow_inside_absolute_pixel_edges
);
6828 defsubr (&Scoordinates_in_window_p
);
6829 defsubr (&Swindow_at
);
6830 defsubr (&Swindow_point
);
6831 defsubr (&Swindow_start
);
6832 defsubr (&Swindow_end
);
6833 defsubr (&Sset_window_point
);
6834 defsubr (&Sset_window_start
);
6835 defsubr (&Swindow_dedicated_p
);
6836 defsubr (&Sset_window_dedicated_p
);
6837 defsubr (&Swindow_display_table
);
6838 defsubr (&Sset_window_display_table
);
6839 defsubr (&Snext_window
);
6840 defsubr (&Sprevious_window
);
6841 defsubr (&Sget_buffer_window
);
6842 defsubr (&Sdelete_other_windows_internal
);
6843 defsubr (&Sdelete_window_internal
);
6844 defsubr (&Sresize_mini_window_internal
);
6845 defsubr (&Sset_window_buffer
);
6846 defsubr (&Srun_window_configuration_change_hook
);
6847 defsubr (&Sselect_window
);
6848 defsubr (&Sforce_window_update
);
6849 defsubr (&Ssplit_window_internal
);
6850 defsubr (&Sscroll_up
);
6851 defsubr (&Sscroll_down
);
6852 defsubr (&Sscroll_left
);
6853 defsubr (&Sscroll_right
);
6854 defsubr (&Sother_window_for_scrolling
);
6855 defsubr (&Sscroll_other_window
);
6856 defsubr (&Sminibuffer_selected_window
);
6857 defsubr (&Srecenter
);
6858 defsubr (&Swindow_text_height
);
6859 defsubr (&Smove_to_window_line
);
6860 defsubr (&Swindow_configuration_p
);
6861 defsubr (&Swindow_configuration_frame
);
6862 defsubr (&Sset_window_configuration
);
6863 defsubr (&Scurrent_window_configuration
);
6864 defsubr (&Sset_window_margins
);
6865 defsubr (&Swindow_margins
);
6866 defsubr (&Sset_window_fringes
);
6867 defsubr (&Swindow_fringes
);
6868 defsubr (&Sset_window_scroll_bars
);
6869 defsubr (&Swindow_scroll_bars
);
6870 defsubr (&Swindow_vscroll
);
6871 defsubr (&Sset_window_vscroll
);
6872 defsubr (&Scompare_window_configurations
);
6873 defsubr (&Swindow_list
);
6874 defsubr (&Swindow_list_1
);
6875 defsubr (&Swindow_prev_buffers
);
6876 defsubr (&Sset_window_prev_buffers
);
6877 defsubr (&Swindow_next_buffers
);
6878 defsubr (&Sset_window_next_buffers
);
6879 defsubr (&Swindow_parameters
);
6880 defsubr (&Swindow_parameter
);
6881 defsubr (&Sset_window_parameter
);
6885 keys_of_window (void)
6887 initial_define_key (control_x_map
, '<', "scroll-left");
6888 initial_define_key (control_x_map
, '>', "scroll-right");
6890 initial_define_key (global_map
, Ctl ('V'), "scroll-up-command");
6891 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
6892 initial_define_key (meta_map
, 'v', "scroll-down-command");