1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985-1987, 1993-1998, 2000-2012
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26 #include "character.h"
36 #include "dispextern.h"
37 #include "blockinput.h"
38 #include "intervals.h"
39 #include "termhooks.h" /* For FRAME_TERMINAL. */
43 #endif /* HAVE_X_WINDOWS */
54 Lisp_Object Qwindowp
, Qwindow_live_p
;
55 static Lisp_Object Qwindow_configuration_p
, Qrecord_window_buffer
;
56 static Lisp_Object Qwindow_deletable_p
, Qdelete_window
, Qdisplay_buffer
;
57 static Lisp_Object Qreplace_buffer_in_windows
, Qget_mru_window
;
58 static Lisp_Object Qwindow_resize_root_window
, Qwindow_resize_root_window_vertically
;
59 static Lisp_Object Qscroll_up
, Qscroll_down
, Qscroll_command
;
60 static Lisp_Object Qsafe
, Qabove
, Qbelow
;
61 static Lisp_Object Qauto_buffer_name
, Qclone_of
;
63 static int displayed_window_lines (struct window
*);
64 static struct window
*decode_window (Lisp_Object
);
65 static int count_windows (struct window
*);
66 static int get_leaf_windows (struct window
*, struct window
**, int);
67 static void window_scroll (Lisp_Object
, EMACS_INT
, int, int);
68 static void window_scroll_pixel_based (Lisp_Object
, int, int, int);
69 static void window_scroll_line_based (Lisp_Object
, int, int, int);
70 static int freeze_window_start (struct window
*, void *);
71 static Lisp_Object
window_list (void);
72 static int add_window_to_list (struct window
*, void *);
73 static int candidate_window_p (Lisp_Object
, Lisp_Object
, Lisp_Object
,
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
*, int);
87 static void window_resize_apply (struct window
*, int);
88 static Lisp_Object
select_window (Lisp_Object
, Lisp_Object
, int);
90 /* This is the window in which the terminal's cursor should
91 be left when nothing is being done with it. This must
92 always be a leaf window, and its buffer is selected by
93 the top level editing loop at the end of each command.
95 This value is always the same as
96 FRAME_SELECTED_WINDOW (selected_frame). */
97 Lisp_Object selected_window
;
99 /* A list of all windows for use by next_window and Fwindow_list.
100 Functions creating or deleting windows should invalidate this cache
101 by setting it to nil. */
102 Lisp_Object Vwindow_list
;
104 /* The mini-buffer window of the selected frame.
105 Note that you cannot test for mini-bufferness of an arbitrary window
106 by comparing against this; but you can test for mini-bufferness of
107 the selected window. */
108 Lisp_Object minibuf_window
;
110 /* Non-nil means it is the window whose mode line should be
111 shown as the selected window when the minibuffer is selected. */
112 Lisp_Object minibuf_selected_window
;
114 /* Hook run at end of temp_output_buffer_show. */
115 static Lisp_Object Qtemp_buffer_show_hook
;
117 /* Incremented for each window created. */
118 static int sequence_number
;
120 /* Nonzero after init_window_once has finished. */
121 static int window_initialized
;
123 /* Hook to run when window config changes. */
124 static Lisp_Object Qwindow_configuration_change_hook
;
126 /* Used by the function window_scroll_pixel_based */
127 static int window_scroll_pixel_based_preserve_x
;
128 static int window_scroll_pixel_based_preserve_y
;
130 /* Same for window_scroll_line_based. */
131 static EMACS_INT window_scroll_preserve_hpos
;
132 static EMACS_INT window_scroll_preserve_vpos
;
134 static struct window
*
135 decode_window (register Lisp_Object window
)
138 return XWINDOW (selected_window
);
140 CHECK_LIVE_WINDOW (window
);
141 return XWINDOW (window
);
144 static struct window
*
145 decode_any_window (register Lisp_Object window
)
148 return XWINDOW (selected_window
);
150 CHECK_WINDOW (window
);
151 return XWINDOW (window
);
154 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
155 doc
: /* Return t if OBJECT is a window and nil otherwise. */)
158 return WINDOWP (object
) ? Qt
: Qnil
;
161 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
162 doc
: /* Return t if OBJECT is a live window and nil otherwise.
163 A live window is a window that displays a buffer.
164 Internal windows and deleted windows are not live. */)
167 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
170 /* Frames and windows. */
171 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 1, 1, 0,
172 doc
: /* Return the frame that window WINDOW is on.
173 If WINDOW is omitted or nil, it defaults to the selected window. */)
176 return decode_any_window (window
)->frame
;
179 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
180 doc
: /* Return the root window of FRAME-OR-WINDOW.
181 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
182 With a frame argument, return that frame's root window.
183 With a window argument, return the root window of that window's frame. */)
184 (Lisp_Object frame_or_window
)
188 if (NILP (frame_or_window
))
189 window
= SELECTED_FRAME ()->root_window
;
190 else if (WINDOWP (frame_or_window
))
191 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
194 CHECK_LIVE_FRAME (frame_or_window
);
195 window
= XFRAME (frame_or_window
)->root_window
;
201 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
202 doc
: /* Return the minibuffer window for frame FRAME.
203 If FRAME is omitted or nil, it defaults to the selected frame. */)
207 frame
= selected_frame
;
208 CHECK_LIVE_FRAME (frame
);
209 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
212 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
,
213 Swindow_minibuffer_p
, 0, 1, 0,
214 doc
: /* Return non-nil if WINDOW is a minibuffer window.
215 If WINDOW is omitted or nil, it defaults to the selected window. */)
218 return MINI_WINDOW_P (decode_any_window (window
)) ? Qt
: Qnil
;
221 /* Don't move this to window.el - this must be a safe routine. */
222 DEFUN ("frame-first-window", Fframe_first_window
, Sframe_first_window
, 0, 1, 0,
223 doc
: /* Return the topmost, leftmost live window on FRAME-OR-WINDOW.
224 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
225 Else if FRAME-OR-WINDOW denotes any window, return the first window of
226 that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
227 the first window of that frame. */)
228 (Lisp_Object frame_or_window
)
232 if (NILP (frame_or_window
))
233 window
= SELECTED_FRAME ()->root_window
;
234 else if (WINDOWP (frame_or_window
))
235 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
238 CHECK_LIVE_FRAME (frame_or_window
);
239 window
= XFRAME (frame_or_window
)->root_window
;
242 while (NILP (XWINDOW (window
)->buffer
))
244 if (! NILP (XWINDOW (window
)->hchild
))
245 window
= XWINDOW (window
)->hchild
;
246 else if (! NILP (XWINDOW (window
)->vchild
))
247 window
= XWINDOW (window
)->vchild
;
255 DEFUN ("frame-selected-window", Fframe_selected_window
,
256 Sframe_selected_window
, 0, 1, 0,
257 doc
: /* Return the selected window of FRAME-OR-WINDOW.
258 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
259 Else if FRAME-OR-WINDOW denotes any window, return the selected window
260 of that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
261 the selected window of that frame. */)
262 (Lisp_Object frame_or_window
)
266 if (NILP (frame_or_window
))
267 window
= SELECTED_FRAME ()->selected_window
;
268 else if (WINDOWP (frame_or_window
))
269 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->selected_window
;
272 CHECK_LIVE_FRAME (frame_or_window
);
273 window
= XFRAME (frame_or_window
)->selected_window
;
279 DEFUN ("set-frame-selected-window", Fset_frame_selected_window
,
280 Sset_frame_selected_window
, 2, 3, 0,
281 doc
: /* Set selected window of FRAME to WINDOW.
282 FRAME must be a live frame and defaults to the selected one. If FRAME
283 is the selected frame, this makes WINDOW the selected window. Optional
284 argument NORECORD non-nil means to neither change the order of recently
285 selected windows nor the buffer list. WINDOW must denote a live window.
287 (Lisp_Object frame
, Lisp_Object window
, Lisp_Object norecord
)
290 frame
= selected_frame
;
292 CHECK_LIVE_FRAME (frame
);
293 CHECK_LIVE_WINDOW (window
);
295 if (! EQ (frame
, WINDOW_FRAME (XWINDOW (window
))))
296 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
298 if (EQ (frame
, selected_frame
))
299 return Fselect_window (window
, norecord
);
301 return XFRAME (frame
)->selected_window
= window
;
304 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
305 doc
: /* Return the selected window.
306 The selected window is the window in which the standard cursor for
307 selected windows appears and to which many commands apply. */)
310 return selected_window
;
313 int window_select_count
;
315 /* If select_window is called with inhibit_point_swap non-zero it will
316 not store point of the old selected window's buffer back into that
317 window's pointm slot. This is needed by Fset_window_configuration to
318 avoid that the display routine is called with selected_window set to
319 Qnil causing a subsequent crash. */
321 select_window (Lisp_Object window
, Lisp_Object norecord
, int inhibit_point_swap
)
323 register struct window
*w
;
324 register struct window
*ow
;
327 CHECK_LIVE_WINDOW (window
);
329 w
= XWINDOW (window
);
330 w
->frozen_window_start_p
= 0;
334 ++window_select_count
;
335 XSETFASTINT (w
->use_time
, window_select_count
);
336 record_buffer (w
->buffer
);
339 if (EQ (window
, selected_window
) && !inhibit_point_swap
)
342 sf
= SELECTED_FRAME ();
343 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
345 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
346 /* Use this rather than Fhandle_switch_frame
347 so that FRAME_FOCUS_FRAME is moved appropriately as we
348 move around in the state where a minibuffer in a separate
350 Fselect_frame (WINDOW_FRAME (w
), norecord
);
351 /* Fselect_frame called us back so we've done all the work already. */
352 eassert (EQ (window
, selected_window
));
356 sf
->selected_window
= window
;
358 /* Store the current buffer's actual point into the
359 old selected window. It belongs to that window,
360 and when the window is not selected, must be in the window. */
361 if (!inhibit_point_swap
)
363 ow
= XWINDOW (selected_window
);
364 if (! NILP (ow
->buffer
))
365 set_marker_both (ow
->pointm
, ow
->buffer
,
366 BUF_PT (XBUFFER (ow
->buffer
)),
367 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
370 selected_window
= window
;
372 Fset_buffer (w
->buffer
);
374 BVAR (XBUFFER (w
->buffer
), last_selected_window
) = window
;
376 /* Go to the point recorded in the window.
377 This is important when the buffer is in more
378 than one window. It also matters when
379 redisplay_window has altered point after scrolling,
380 because it makes the change only in the window. */
382 register ptrdiff_t new_point
= marker_position (w
->pointm
);
383 if (new_point
< BEGV
)
385 else if (new_point
> ZV
)
391 windows_or_buffers_changed
++;
395 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
396 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
397 Also make WINDOW's buffer current and make WINDOW the frame's selected
398 window. Return WINDOW.
400 Optional second arg NORECORD non-nil means do not put this buffer at the
401 front of the buffer list and do not make this window the most recently
404 Note that the main editor command loop sets the current buffer to the
405 buffer of the selected window before each command. */)
406 (register Lisp_Object window
, Lisp_Object norecord
)
408 return select_window (window
, norecord
, 0);
411 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
412 doc
: /* Return the buffer displayed in window WINDOW.
413 If WINDOW is omitted or nil, it defaults to the selected window.
414 Return nil for an internal window or a deleted window. */)
417 return decode_any_window (window
)->buffer
;
420 DEFUN ("window-parent", Fwindow_parent
, Swindow_parent
, 0, 1, 0,
421 doc
: /* Return the parent window of window WINDOW.
422 If WINDOW is omitted or nil, it defaults to the selected window.
423 Return nil for a window with no parent (e.g. a root window). */)
426 return decode_any_window (window
)->parent
;
429 DEFUN ("window-top-child", Fwindow_top_child
, Swindow_top_child
, 1, 1, 0,
430 doc
: /* Return the topmost child window of window WINDOW.
431 Return nil if WINDOW is a live window (live windows have no children).
432 Return nil if WINDOW is an internal window whose children form a
433 horizontal combination. */)
436 CHECK_WINDOW (window
);
437 return decode_any_window (window
)->vchild
;
440 DEFUN ("window-left-child", Fwindow_left_child
, Swindow_left_child
, 1, 1, 0,
441 doc
: /* Return the leftmost child window of window WINDOW.
442 Return nil if WINDOW is a live window (live windows have no children).
443 Return nil if WINDOW is an internal window whose children form a
444 vertical combination. */)
447 CHECK_WINDOW (window
);
448 return decode_any_window (window
)->hchild
;
451 DEFUN ("window-next-sibling", Fwindow_next_sibling
, Swindow_next_sibling
, 0, 1, 0,
452 doc
: /* Return the next sibling window of window WINDOW.
453 If WINDOW is omitted or nil, it defaults to the selected window.
454 Return nil if WINDOW has no next sibling. */)
457 return decode_any_window (window
)->next
;
460 DEFUN ("window-prev-sibling", Fwindow_prev_sibling
, Swindow_prev_sibling
, 0, 1, 0,
461 doc
: /* Return the previous sibling window of window WINDOW.
462 If WINDOW is omitted or nil, it defaults to the selected window.
463 Return nil if WINDOW has no previous sibling. */)
466 return decode_any_window (window
)->prev
;
469 DEFUN ("window-combination-limit", Fwindow_combination_limit
, Swindow_combination_limit
, 1, 1, 0,
470 doc
: /* Return combination limit of window WINDOW.
471 If the return value is nil, child windows of WINDOW can be recombined with
472 WINDOW's siblings. A return value of t means that child windows of
473 WINDOW are never \(re-)combined with WINDOW's siblings. */)
476 return decode_any_window (window
)->combination_limit
;
479 DEFUN ("set-window-combination-limit", Fset_window_combination_limit
, Sset_window_combination_limit
, 2, 2, 0,
480 doc
: /* Set combination limit of window WINDOW to LIMIT; return LIMIT.
481 If LIMIT is nil, child windows of WINDOW can be recombined with
482 WINDOW's siblings. LIMIT t means that child windows of WINDOW are
483 never \(re-)combined with WINDOW's siblings. Other values are reserved
485 (Lisp_Object window
, Lisp_Object limit
)
487 register struct window
*w
= decode_any_window (window
);
489 w
->combination_limit
= limit
;
491 return w
->combination_limit
;
494 DEFUN ("window-use-time", Fwindow_use_time
, Swindow_use_time
, 0, 1, 0,
495 doc
: /* Return the use time of window WINDOW.
496 If WINDOW is omitted or nil, it defaults to the selected window.
497 The window with the highest use time is the most recently selected
498 one. The window with the lowest use time is the least recently
502 return decode_window (window
)->use_time
;
505 DEFUN ("window-total-height", Fwindow_total_height
, Swindow_total_height
, 0, 1, 0,
506 doc
: /* Return the total height, in lines, of window WINDOW.
507 If WINDOW is omitted or nil, it defaults to the selected window.
509 The return value includes the mode line and header line, if any.
510 If WINDOW is an internal window, the total height is the height
511 of the screen areas spanned by its children.
513 On a graphical display, this total height is reported as an
514 integer multiple of the default character height. */)
517 return decode_any_window (window
)->total_lines
;
520 DEFUN ("window-total-width", Fwindow_total_width
, Swindow_total_width
, 0, 1, 0,
521 doc
: /* Return the total width, in columns, of window WINDOW.
522 If WINDOW is omitted or nil, it defaults to the selected window.
524 The return value includes any vertical dividers or scroll bars
525 belonging to WINDOW. If WINDOW is an internal window, the total width
526 is the width of the screen areas spanned by its children.
528 On a graphical display, this total width is reported as an
529 integer multiple of the default character width. */)
532 return decode_any_window (window
)->total_cols
;
535 DEFUN ("window-new-total", Fwindow_new_total
, Swindow_new_total
, 0, 1, 0,
536 doc
: /* Return the new total size of window WINDOW.
537 If WINDOW is omitted or nil, it defaults to the selected window. */)
540 return decode_any_window (window
)->new_total
;
543 DEFUN ("window-normal-size", Fwindow_normal_size
, Swindow_normal_size
, 0, 2, 0,
544 doc
: /* Return the normal height of window WINDOW.
545 If WINDOW is omitted or nil, it defaults to the selected window.
546 If HORIZONTAL is non-nil, return the normal width of WINDOW. */)
547 (Lisp_Object window
, Lisp_Object horizontal
)
549 if (NILP (horizontal
))
550 return decode_any_window (window
)->normal_lines
;
552 return decode_any_window (window
)->normal_cols
;
555 DEFUN ("window-new-normal", Fwindow_new_normal
, Swindow_new_normal
, 0, 1, 0,
556 doc
: /* Return new normal size of window WINDOW.
557 If WINDOW is omitted or nil, it defaults to the selected window. */)
560 return decode_any_window (window
)->new_normal
;
563 DEFUN ("window-left-column", Fwindow_left_column
, Swindow_left_column
, 0, 1, 0,
564 doc
: /* Return left column of window WINDOW.
565 This is the distance, in columns, between the left edge of WINDOW and
566 the left edge of the frame's window area. For instance, the return
567 value is 0 if there is no window to the left of WINDOW.
569 If WINDOW is omitted or nil, it defaults to the selected window. */)
572 return decode_any_window (window
)->left_col
;
575 DEFUN ("window-top-line", Fwindow_top_line
, Swindow_top_line
, 0, 1, 0,
576 doc
: /* Return top line of window WINDOW.
577 This is the distance, in lines, between the top of WINDOW and the top
578 of the frame's window area. For instance, the return value is 0 if
579 there is no window above WINDOW.
581 If WINDOW is omitted or nil, it defaults to the selected window. */)
584 return decode_any_window (window
)->top_line
;
587 /* Return the number of lines of W's body. Don't count any mode or
591 window_body_lines (struct window
*w
)
593 int height
= XFASTINT (w
->total_lines
);
595 if (!MINI_WINDOW_P (w
))
597 if (WINDOW_WANTS_MODELINE_P (w
))
599 if (WINDOW_WANTS_HEADER_LINE_P (w
))
606 /* Return the number of columns of W's body. Don't count columns
607 occupied by the scroll bar or the vertical bar separating W from its
608 right sibling. On window-systems don't count fringes or display
612 window_body_cols (struct window
*w
)
614 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
615 int width
= XINT (w
->total_cols
);
617 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
618 /* Scroll bars occupy a few columns. */
619 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
620 else if (!FRAME_WINDOW_P (f
)
621 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
622 /* The column of `|' characters separating side-by-side windows
623 occupies one column only. */
626 if (FRAME_WINDOW_P (f
))
627 /* On window-systems, fringes and display margins cannot be
628 used for normal text. */
629 width
-= (WINDOW_FRINGE_COLS (w
)
630 + WINDOW_LEFT_MARGIN_COLS (w
)
631 + WINDOW_RIGHT_MARGIN_COLS (w
));
636 DEFUN ("window-body-height", Fwindow_body_height
, Swindow_body_height
, 0, 1, 0,
637 doc
: /* Return the height, in lines, of WINDOW's text area.
638 If WINDOW is omitted or nil, it defaults to the selected window.
639 Signal an error if the window is not live.
641 The returned height does not include the mode line or header line.
642 On a graphical display, the height is expressed as an integer multiple
643 of the default character height. If a line at the bottom of the text
644 area is only partially visible, that counts as a whole line; to
645 exclude partially-visible lines, use `window-text-height'. */)
648 struct window
*w
= decode_window (window
);
649 return make_number (window_body_lines (w
));
652 DEFUN ("window-body-width", Fwindow_body_width
, Swindow_body_width
, 0, 1, 0,
653 doc
: /* Return the width, in columns, of WINDOW's text area.
654 If WINDOW is omitted or nil, it defaults to the selected window.
655 Signal an error if the window is not live.
657 The return value does not include any vertical dividers, fringe or
658 marginal areas, or scroll bars. On a graphical display, the width is
659 expressed as an integer multiple of the default character width. */)
662 struct window
*w
= decode_window (window
);
663 return make_number (window_body_cols (w
));
666 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
667 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
668 WINDOW must be a live window and defaults to the selected one. */)
671 return decode_window (window
)->hscroll
;
674 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
675 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
676 If WINDOW is nil, the selected window is used.
677 Return NCOL. NCOL should be zero or positive.
679 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
680 window so that the location of point moves off-window. */)
681 (Lisp_Object window
, Lisp_Object ncol
)
683 struct window
*w
= decode_window (window
);
687 hscroll
= clip_to_bounds (0, XINT (ncol
), PTRDIFF_MAX
);
689 /* Prevent redisplay shortcuts when changing the hscroll. */
690 if (XINT (w
->hscroll
) != hscroll
)
691 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
693 w
->hscroll
= make_number (hscroll
);
697 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
698 Swindow_redisplay_end_trigger
, 0, 1, 0,
699 doc
: /* Return WINDOW's redisplay end trigger value.
700 WINDOW defaults to the selected window.
701 See `set-window-redisplay-end-trigger' for more information. */)
704 return decode_window (window
)->redisplay_end_trigger
;
707 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
708 Sset_window_redisplay_end_trigger
, 2, 2, 0,
709 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
710 VALUE should be a buffer position (typically a marker) or nil.
711 If it is a buffer position, then if redisplay in WINDOW reaches a position
712 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
713 with two arguments: WINDOW, and the end trigger value.
714 Afterwards the end-trigger value is reset to nil. */)
715 (register Lisp_Object window
, Lisp_Object value
)
717 register struct window
*w
;
719 w
= decode_window (window
);
720 w
->redisplay_end_trigger
= value
;
724 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
725 doc
: /* Return a list of the edge coordinates of WINDOW.
726 The list has the form (LEFT TOP RIGHT BOTTOM).
727 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
728 all relative to 0, 0 at top left corner of frame.
730 RIGHT is one more than the rightmost column occupied by WINDOW.
731 BOTTOM is one more than the bottommost row occupied by WINDOW.
732 The edges include the space used by WINDOW's scroll bar, display
733 margins, fringes, header line, and/or mode line. For the edges of
734 just the text area, use `window-inside-edges'. */)
737 register struct window
*w
= decode_any_window (window
);
739 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w
)),
740 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w
)),
741 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w
)),
742 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w
)),
746 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
747 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
748 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
749 the top left corner of the frame.
751 RIGHT is one more than the rightmost x position occupied by WINDOW.
752 BOTTOM is one more than the bottommost y position occupied by WINDOW.
753 The pixel edges include the space used by WINDOW's scroll bar, display
754 margins, fringes, header line, and/or mode line. For the pixel edges
755 of just the text area, use `window-inside-pixel-edges'. */)
758 register struct window
*w
= decode_any_window (window
);
760 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
)),
761 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
)),
762 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
)),
763 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
)),
768 calc_absolute_offset (struct window
*w
, int *add_x
, int *add_y
)
770 struct frame
*f
= XFRAME (w
->frame
);
772 #ifdef FRAME_MENUBAR_HEIGHT
773 *add_y
+= FRAME_MENUBAR_HEIGHT (f
);
775 #ifdef FRAME_TOOLBAR_TOP_HEIGHT
776 *add_y
+= FRAME_TOOLBAR_TOP_HEIGHT (f
);
777 #elif FRAME_TOOLBAR_HEIGHT
778 *add_y
+= FRAME_TOOLBAR_HEIGHT (f
);
780 #ifdef FRAME_NS_TITLEBAR_HEIGHT
781 *add_y
+= FRAME_NS_TITLEBAR_HEIGHT (f
);
783 *add_x
= f
->left_pos
;
784 #ifdef FRAME_TOOLBAR_LEFT_WIDTH
785 *add_x
+= FRAME_TOOLBAR_LEFT_WIDTH (f
);
789 DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges
,
790 Swindow_absolute_pixel_edges
, 0, 1, 0,
791 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
792 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
793 the top left corner of the display.
795 RIGHT is one more than the rightmost x position occupied by WINDOW.
796 BOTTOM is one more than the bottommost y position occupied by WINDOW.
797 The pixel edges include the space used by WINDOW's scroll bar, display
798 margins, fringes, header line, and/or mode line. For the pixel edges
799 of just the text area, use `window-inside-absolute-pixel-edges'. */)
802 register struct window
*w
= decode_any_window (window
);
804 calc_absolute_offset (w
, &add_x
, &add_y
);
806 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
) + add_x
),
807 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
) + add_y
),
808 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
) + add_x
),
809 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
) + add_y
),
813 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
814 doc
: /* Return a list of the edge coordinates of WINDOW.
815 The list has the form (LEFT TOP RIGHT BOTTOM).
816 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
817 all relative to 0, 0 at top left corner of frame.
819 RIGHT is one more than the rightmost column of WINDOW's text area.
820 BOTTOM is one more than the bottommost row of WINDOW's text area.
821 The inside edges do not include the space used by the WINDOW's scroll
822 bar, display margins, fringes, header line, and/or mode line. */)
825 register struct window
*w
= decode_window (window
);
827 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w
)
828 + WINDOW_LEFT_MARGIN_COLS (w
)
829 + WINDOW_LEFT_FRINGE_COLS (w
)),
830 make_number (WINDOW_TOP_EDGE_LINE (w
)
831 + WINDOW_HEADER_LINE_LINES (w
)),
832 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w
)
833 - WINDOW_RIGHT_MARGIN_COLS (w
)
834 - WINDOW_RIGHT_FRINGE_COLS (w
)),
835 make_number (WINDOW_BOTTOM_EDGE_LINE (w
)
836 - WINDOW_MODE_LINE_LINES (w
)));
839 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
840 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
841 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to (0,0)
842 at the top left corner of the frame's window area.
844 RIGHT is one more than the rightmost x position of WINDOW's text area.
845 BOTTOM is one more than the bottommost y position of WINDOW's text area.
846 The inside edges do not include the space used by WINDOW's scroll bar,
847 display margins, fringes, header line, and/or mode line. */)
850 register struct window
*w
= decode_window (window
);
852 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
853 + WINDOW_LEFT_MARGIN_WIDTH (w
)
854 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
855 make_number (WINDOW_TOP_EDGE_Y (w
)
856 + WINDOW_HEADER_LINE_HEIGHT (w
)),
857 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
858 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
859 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
860 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
861 - WINDOW_MODE_LINE_HEIGHT (w
)));
864 DEFUN ("window-inside-absolute-pixel-edges",
865 Fwindow_inside_absolute_pixel_edges
,
866 Swindow_inside_absolute_pixel_edges
, 0, 1, 0,
867 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
868 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to (0,0)
869 at the top left corner of the frame's window area.
871 RIGHT is one more than the rightmost x position of WINDOW's text area.
872 BOTTOM is one more than the bottommost y position of WINDOW's text area.
873 The inside edges do not include the space used by WINDOW's scroll bar,
874 display margins, fringes, header line, and/or mode line. */)
877 register struct window
*w
= decode_window (window
);
879 calc_absolute_offset (w
, &add_x
, &add_y
);
881 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
882 + WINDOW_LEFT_MARGIN_WIDTH (w
)
883 + WINDOW_LEFT_FRINGE_WIDTH (w
) + add_x
),
884 make_number (WINDOW_TOP_EDGE_Y (w
)
885 + WINDOW_HEADER_LINE_HEIGHT (w
) + add_y
),
886 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
887 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
888 - WINDOW_RIGHT_FRINGE_WIDTH (w
) + add_x
),
889 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
890 - WINDOW_MODE_LINE_HEIGHT (w
) + add_y
));
893 /* Test if the character at column X, row Y is within window W.
894 If it is not, return ON_NOTHING;
895 if it is in the window's text area, return ON_TEXT;
896 if it is on the window's modeline, return ON_MODE_LINE;
897 if it is on the border between the window and its right sibling,
898 return ON_VERTICAL_BORDER.
899 if it is on a scroll bar, return ON_SCROLL_BAR.
900 if it is on the window's top line, return ON_HEADER_LINE;
901 if it is in left or right fringe of the window,
902 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
903 if it is in the marginal area to the left/right of the window,
904 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN.
906 X and Y are frame relative pixel coordinates. */
908 static enum window_part
909 coordinates_in_window (register struct window
*w
, int x
, int y
)
911 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
912 enum window_part part
;
913 int ux
= FRAME_COLUMN_WIDTH (f
);
914 int left_x
= WINDOW_LEFT_EDGE_X (w
);
915 int right_x
= WINDOW_RIGHT_EDGE_X (w
);
916 int top_y
= WINDOW_TOP_EDGE_Y (w
);
917 int bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
918 /* The width of the area where the vertical line can be dragged.
919 (Between mode lines for instance. */
920 int grabbable_width
= ux
;
921 int lmargin_width
, rmargin_width
, text_left
, text_right
;
923 /* Outside any interesting row or column? */
924 if (y
< top_y
|| y
>= bottom_y
|| x
< left_x
|| x
>= right_x
)
927 /* On the mode line or header line? */
928 if ((WINDOW_WANTS_MODELINE_P (w
)
929 && y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
)
930 && (part
= ON_MODE_LINE
))
931 || (WINDOW_WANTS_HEADER_LINE_P (w
)
932 && y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
)
933 && (part
= ON_HEADER_LINE
)))
935 /* If it's under/over the scroll bar portion of the mode/header
936 line, say it's on the vertical line. That's to be able to
937 resize windows horizontally in case we're using toolkit scroll
938 bars. Note: If scrollbars are on the left, the window that
939 must be eventually resized is that on the left of WINDOW. */
940 if ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
941 && !WINDOW_LEFTMOST_P (w
)
942 && eabs (x
- left_x
) < grabbable_width
)
943 || (!WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
944 && !WINDOW_RIGHTMOST_P (w
)
945 && eabs (x
- right_x
) < grabbable_width
))
946 return ON_VERTICAL_BORDER
;
951 /* In what's below, we subtract 1 when computing right_x because we
952 want the rightmost pixel, which is given by left_pixel+width-1. */
953 if (w
->pseudo_window_p
)
956 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
960 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
961 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
964 /* Outside any interesting column? */
965 if (x
< left_x
|| x
> right_x
)
966 return ON_SCROLL_BAR
;
968 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
969 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
971 text_left
= window_box_left (w
, TEXT_AREA
);
972 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
974 if (FRAME_WINDOW_P (f
))
976 if (!w
->pseudo_window_p
977 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
978 && !WINDOW_RIGHTMOST_P (w
)
979 && (eabs (x
- right_x
) < grabbable_width
))
980 return ON_VERTICAL_BORDER
;
982 /* Need to say "x > right_x" rather than >=, since on character
983 terminals, the vertical line's x coordinate is right_x. */
984 else if (!w
->pseudo_window_p
985 && !WINDOW_RIGHTMOST_P (w
)
987 return ON_VERTICAL_BORDER
;
991 if (lmargin_width
> 0
992 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
993 ? (x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
994 : (x
< left_x
+ lmargin_width
)))
995 return ON_LEFT_MARGIN
;
997 return ON_LEFT_FRINGE
;
1000 if (x
>= text_right
)
1002 if (rmargin_width
> 0
1003 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1004 ? (x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
1005 : (x
>= right_x
- rmargin_width
)))
1006 return ON_RIGHT_MARGIN
;
1008 return ON_RIGHT_FRINGE
;
1011 /* Everything special ruled out - must be on text area */
1015 /* Take X is the frame-relative pixel x-coordinate, and return the
1016 x-coordinate relative to part PART of window W. */
1018 window_relative_x_coord (struct window
*w
, enum window_part part
, int x
)
1020 int left_x
= (w
->pseudo_window_p
) ? 0 : WINDOW_BOX_LEFT_EDGE_X (w
);
1025 return x
- window_box_left (w
, TEXT_AREA
);
1027 case ON_LEFT_FRINGE
:
1030 case ON_RIGHT_FRINGE
:
1031 return x
- left_x
- WINDOW_LEFT_FRINGE_WIDTH (w
);
1033 case ON_LEFT_MARGIN
:
1035 - ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1036 ? WINDOW_LEFT_FRINGE_WIDTH (w
) : 0));
1038 case ON_RIGHT_MARGIN
:
1040 - ((w
->pseudo_window_p
)
1041 ? WINDOW_TOTAL_WIDTH (w
)
1042 : WINDOW_BOX_RIGHT_EDGE_X (w
))
1043 + window_box_width (w
, RIGHT_MARGIN_AREA
)
1044 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1045 ? WINDOW_RIGHT_FRINGE_WIDTH (w
) : 0));
1048 /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */
1053 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
1054 Scoordinates_in_window_p
, 2, 2, 0,
1055 doc
: /* Return non-nil if COORDINATES are in WINDOW.
1056 WINDOW must be a live window.
1057 COORDINATES is a cons of the form (X . Y), X and Y being distances
1058 measured in characters from the upper-left corner of the frame.
1059 \(0 . 0) denotes the character in the upper left corner of the
1061 If COORDINATES are in the text portion of WINDOW,
1062 the coordinates relative to the window are returned.
1063 If they are in the mode line of WINDOW, `mode-line' is returned.
1064 If they are in the top mode line of WINDOW, `header-line' is returned.
1065 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1066 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1067 If they are on the border between WINDOW and its right sibling,
1068 `vertical-line' is returned.
1069 If they are in the windows's left or right marginal areas, `left-margin'\n\
1070 or `right-margin' is returned. */)
1071 (register Lisp_Object coordinates
, Lisp_Object window
)
1078 CHECK_LIVE_WINDOW (window
);
1079 w
= XWINDOW (window
);
1080 f
= XFRAME (w
->frame
);
1081 CHECK_CONS (coordinates
);
1082 lx
= Fcar (coordinates
);
1083 ly
= Fcdr (coordinates
);
1084 CHECK_NUMBER_OR_FLOAT (lx
);
1085 CHECK_NUMBER_OR_FLOAT (ly
);
1086 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1087 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1089 switch (coordinates_in_window (w
, x
, y
))
1095 /* Convert X and Y to window relative pixel coordinates, and
1096 return the canonical char units. */
1097 x
-= window_box_left (w
, TEXT_AREA
);
1098 y
-= WINDOW_TOP_EDGE_Y (w
);
1099 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
1100 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
1105 case ON_VERTICAL_BORDER
:
1106 return Qvertical_line
;
1108 case ON_HEADER_LINE
:
1109 return Qheader_line
;
1111 case ON_LEFT_FRINGE
:
1112 return Qleft_fringe
;
1114 case ON_RIGHT_FRINGE
:
1115 return Qright_fringe
;
1117 case ON_LEFT_MARGIN
:
1118 return Qleft_margin
;
1120 case ON_RIGHT_MARGIN
:
1121 return Qright_margin
;
1124 /* Historically we are supposed to return nil in this case. */
1133 /* Callback for foreach_window, used in window_from_coordinates.
1134 Check if window W contains coordinates specified by USER_DATA which
1135 is actually a pointer to a struct check_window_data CW.
1137 Check if window W contains coordinates *CW->x and *CW->y. If it
1138 does, return W in *CW->window, as Lisp_Object, and return in
1139 *CW->part the part of the window under coordinates *X,*Y. Return
1140 zero from this function to stop iterating over windows. */
1142 struct check_window_data
1144 Lisp_Object
*window
;
1146 enum window_part
*part
;
1150 check_window_containing (struct window
*w
, void *user_data
)
1152 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
1153 enum window_part found
;
1156 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1157 if (found
!= ON_NOTHING
)
1160 XSETWINDOW (*cw
->window
, w
);
1168 /* Find the window containing frame-relative pixel position X/Y and
1169 return it as a Lisp_Object.
1171 If X, Y is on one of the window's special `window_part' elements,
1172 set *PART to the id of that element.
1174 If there is no window under X, Y return nil and leave *PART
1175 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1177 This function was previously implemented with a loop cycling over
1178 windows with Fnext_window, and starting with the frame's selected
1179 window. It turned out that this doesn't work with an
1180 implementation of next_window using Vwindow_list, because
1181 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1182 tree of F when this function is called asynchronously from
1183 note_mouse_highlight. The original loop didn't terminate in this
1187 window_from_coordinates (struct frame
*f
, int x
, int y
,
1188 enum window_part
*part
, int tool_bar_p
)
1191 struct check_window_data cw
;
1192 enum window_part dummy
;
1198 cw
.window
= &window
, cw
.x
= x
, cw
.y
= y
; cw
.part
= part
;
1199 foreach_window (f
, check_window_containing
, &cw
);
1201 /* If not found above, see if it's in the tool bar window, if a tool
1205 && WINDOWP (f
->tool_bar_window
)
1206 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1207 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), x
, y
)
1211 window
= f
->tool_bar_window
;
1217 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1218 doc
: /* Return window containing coordinates X and Y on FRAME.
1219 FRAME must be a live frame and defaults to the selected one.
1220 The top left corner of the frame is considered to be row 0,
1222 (Lisp_Object x
, Lisp_Object y
, Lisp_Object frame
)
1227 frame
= selected_frame
;
1228 CHECK_LIVE_FRAME (frame
);
1231 /* Check that arguments are integers or floats. */
1232 CHECK_NUMBER_OR_FLOAT (x
);
1233 CHECK_NUMBER_OR_FLOAT (y
);
1235 return window_from_coordinates (f
,
1236 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1237 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1238 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1239 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1243 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1244 doc
: /* Return current value of point in WINDOW.
1245 WINDOW must be a live window and defaults to the selected one.
1247 For a nonselected window, this is the value point would have
1248 if that window were selected.
1250 Note that, when WINDOW is the selected window and its buffer
1251 is also currently selected, the value returned is the same as (point).
1252 It would be more strictly correct to return the `top-level' value
1253 of point, outside of any save-excursion forms.
1254 But that is hard to define. */)
1255 (Lisp_Object window
)
1257 register struct window
*w
= decode_window (window
);
1259 if (w
== XWINDOW (selected_window
)
1260 && current_buffer
== XBUFFER (w
->buffer
))
1262 return Fmarker_position (w
->pointm
);
1265 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1266 doc
: /* Return position at which display currently starts in WINDOW.
1267 WINDOW must be a live window and defaults to the selected one.
1268 This is updated by redisplay or by calling `set-window-start'. */)
1269 (Lisp_Object window
)
1271 return Fmarker_position (decode_window (window
)->start
);
1274 /* This is text temporarily removed from the doc string below.
1276 This function returns nil if the position is not currently known.
1277 That happens when redisplay is preempted and doesn't finish.
1278 If in that case you want to compute where the end of the window would
1279 have been if redisplay had finished, do this:
1281 (goto-char (window-start window))
1282 (vertical-motion (1- (window-height window)) window)
1285 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1286 doc
: /* Return position at which display currently ends in WINDOW.
1287 WINDOW must be a live window and defaults to the selected one.
1288 This is updated by redisplay, when it runs to completion.
1289 Simply changing the buffer text or setting `window-start'
1290 does not update this value.
1291 Return nil if there is no recorded value. (This can happen if the
1292 last redisplay of WINDOW was preempted, and did not finish.)
1293 If UPDATE is non-nil, compute the up-to-date position
1294 if it isn't already recorded. */)
1295 (Lisp_Object window
, Lisp_Object update
)
1298 struct window
*w
= decode_window (window
);
1306 #if 0 /* This change broke some things. We should make it later. */
1307 /* If we don't know the end position, return nil.
1308 The user can compute it with vertical-motion if he wants to.
1309 It would be nicer to do it automatically,
1310 but that's so slow that it would probably bother people. */
1311 if (NILP (w
->window_end_valid
))
1316 && ! (! NILP (w
->window_end_valid
)
1317 && XFASTINT (w
->last_modified
) >= BUF_MODIFF (b
)
1318 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (b
))
1321 struct text_pos startp
;
1323 struct buffer
*old_buffer
= NULL
;
1324 void *itdata
= NULL
;
1326 /* Cannot use Fvertical_motion because that function doesn't
1327 cope with variable-height lines. */
1328 if (b
!= current_buffer
)
1330 old_buffer
= current_buffer
;
1331 set_buffer_internal (b
);
1334 /* In case W->start is out of the range, use something
1335 reasonable. This situation occurred when loading a file with
1336 `-l' containing a call to `rmail' with subsequent other
1337 commands. At the end, W->start happened to be BEG, while
1338 rmail had already narrowed the buffer. */
1339 if (XMARKER (w
->start
)->charpos
< BEGV
)
1340 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1341 else if (XMARKER (w
->start
)->charpos
> ZV
)
1342 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1344 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1346 itdata
= bidi_shelve_cache ();
1347 start_display (&it
, w
, startp
);
1348 move_it_vertically (&it
, window_box_height (w
));
1349 if (it
.current_y
< it
.last_visible_y
)
1350 move_it_past_eol (&it
);
1351 value
= make_number (IT_CHARPOS (it
));
1352 bidi_unshelve_cache (itdata
, 0);
1355 set_buffer_internal (old_buffer
);
1358 XSETINT (value
, BUF_Z (b
) - XFASTINT (w
->window_end_pos
));
1363 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1364 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1366 (Lisp_Object window
, Lisp_Object pos
)
1368 register struct window
*w
= decode_window (window
);
1370 CHECK_NUMBER_COERCE_MARKER (pos
);
1371 if (w
== XWINDOW (selected_window
)
1372 && XBUFFER (w
->buffer
) == current_buffer
)
1375 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1377 /* We have to make sure that redisplay updates the window to show
1378 the new value of point. */
1379 if (!EQ (window
, selected_window
))
1380 ++windows_or_buffers_changed
;
1385 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1386 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1387 If WINDOW is nil, the selected window is used. Return POS.
1388 Optional third arg NOFORCE non-nil inhibits next redisplay from
1389 overriding motion of point in order to display at this exact start. */)
1390 (Lisp_Object window
, Lisp_Object pos
, Lisp_Object noforce
)
1392 register struct window
*w
= decode_window (window
);
1394 CHECK_NUMBER_COERCE_MARKER (pos
);
1395 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1396 /* this is not right, but much easier than doing what is right. */
1397 w
->start_at_line_beg
= 0;
1400 w
->update_mode_line
= 1;
1401 XSETFASTINT (w
->last_modified
, 0);
1402 XSETFASTINT (w
->last_overlay_modified
, 0);
1403 if (!EQ (window
, selected_window
))
1404 windows_or_buffers_changed
++;
1409 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
1410 Spos_visible_in_window_p
, 0, 3, 0,
1411 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
1412 Return nil if that position is scrolled vertically out of view.
1413 If a character is only partially visible, nil is returned, unless the
1414 optional argument PARTIALLY is non-nil.
1415 If POS is only out of view because of horizontal scrolling, return non-nil.
1416 If POS is t, it specifies the position of the last visible glyph in WINDOW.
1417 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
1419 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1420 return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
1421 where X and Y are the pixel coordinates relative to the top left corner
1422 of the window. The remaining elements are omitted if the character after
1423 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1424 off-window at the top and bottom of the row, ROWH is the height of the
1425 display row, and VPOS is the row number (0-based) containing POS. */)
1426 (Lisp_Object pos
, Lisp_Object window
, Lisp_Object partially
)
1428 register struct window
*w
;
1429 register EMACS_INT posint
;
1430 register struct buffer
*buf
;
1431 struct text_pos top
;
1432 Lisp_Object in_window
= Qnil
;
1433 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
1436 w
= decode_window (window
);
1437 buf
= XBUFFER (w
->buffer
);
1438 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1442 else if (!NILP (pos
))
1444 CHECK_NUMBER_COERCE_MARKER (pos
);
1445 posint
= XINT (pos
);
1447 else if (w
== XWINDOW (selected_window
))
1450 posint
= XMARKER (w
->pointm
)->charpos
;
1452 /* If position is above window start or outside buffer boundaries,
1453 or if window start is out of range, position is not visible. */
1455 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
1456 && CHARPOS (top
) >= BUF_BEGV (buf
)
1457 && CHARPOS (top
) <= BUF_ZV (buf
)
1458 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
1459 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
1462 if (!NILP (in_window
) && !NILP (partially
))
1464 Lisp_Object part
= Qnil
;
1466 part
= list4 (make_number (rtop
), make_number (rbot
),
1467 make_number (rowh
), make_number (vpos
));
1468 in_window
= Fcons (make_number (x
),
1469 Fcons (make_number (y
), part
));
1475 DEFUN ("window-line-height", Fwindow_line_height
,
1476 Swindow_line_height
, 0, 2, 0,
1477 doc
: /* Return height in pixels of text line LINE in window WINDOW.
1478 WINDOW defaults to the selected window.
1480 Return height of current line if LINE is omitted or nil. Return height of
1481 header or mode line if LINE is `header-line' or `mode-line'.
1482 Otherwise, LINE is a text line number starting from 0. A negative number
1483 counts from the end of the window.
1485 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
1486 in pixels of the visible part of the line, VPOS and YPOS are the
1487 vertical position in lines and pixels of the line, relative to the top
1488 of the first text line, and OFFBOT is the number of off-window pixels at
1489 the bottom of the text line. If there are off-window pixels at the top
1490 of the (first) text line, YPOS is negative.
1492 Return nil if window display is not up-to-date. In that case, use
1493 `pos-visible-in-window-p' to obtain the information. */)
1494 (Lisp_Object line
, Lisp_Object window
)
1496 register struct window
*w
;
1497 register struct buffer
*b
;
1498 struct glyph_row
*row
, *end_row
;
1502 w
= decode_window (window
);
1504 if (noninteractive
|| w
->pseudo_window_p
)
1507 CHECK_BUFFER (w
->buffer
);
1508 b
= XBUFFER (w
->buffer
);
1510 /* Fail if current matrix is not up-to-date. */
1511 if (NILP (w
->window_end_valid
)
1512 || current_buffer
->clip_changed
1513 || current_buffer
->prevent_redisplay_optimizations_p
1514 || XFASTINT (w
->last_modified
) < BUF_MODIFF (b
)
1515 || XFASTINT (w
->last_overlay_modified
) < BUF_OVERLAY_MODIFF (b
))
1521 if (i
< 0 || i
>= w
->current_matrix
->nrows
1522 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
1524 max_y
= window_text_bottom_y (w
);
1528 if (EQ (line
, Qheader_line
))
1530 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
1532 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
1533 if (!row
->enabled_p
)
1535 return list4 (make_number (row
->height
),
1536 make_number (0), make_number (0),
1540 if (EQ (line
, Qmode_line
))
1542 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
1543 if (!row
->enabled_p
)
1545 return list4 (make_number (row
->height
),
1546 make_number (0), /* not accurate */
1547 make_number (WINDOW_HEADER_LINE_HEIGHT (w
)
1548 + window_text_bottom_y (w
)),
1552 CHECK_NUMBER (line
);
1555 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1556 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1557 max_y
= window_text_bottom_y (w
);
1560 while ((n
< 0 || i
< n
)
1561 && row
<= end_row
&& row
->enabled_p
1562 && row
->y
+ row
->height
< max_y
)
1565 if (row
> end_row
|| !row
->enabled_p
)
1577 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
1578 return list4 (make_number (row
->height
+ min (0, row
->y
) - crop
),
1580 make_number (row
->y
),
1581 make_number (crop
));
1584 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1586 doc
: /* Return non-nil when WINDOW is dedicated to its buffer.
1587 More precisely, return the value assigned by the last call of
1588 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1589 never called with WINDOW as its argument, or the value set by that
1590 function was internally reset since its last call. WINDOW defaults to
1591 the selected window.
1593 When a window is dedicated to its buffer, `display-buffer' will refrain
1594 from displaying another buffer in it. `get-lru-window' and
1595 `get-largest-window' treat dedicated windows specially.
1596 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1597 `kill-buffer' can delete a dedicated window and the containing frame.
1599 Functions like `set-window-buffer' may change the buffer displayed by a
1600 window, unless that window is "strongly" dedicated to its buffer, that
1601 is the value returned by `window-dedicated-p' is t. */)
1602 (Lisp_Object window
)
1604 return decode_window (window
)->dedicated
;
1607 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1608 Sset_window_dedicated_p
, 2, 2, 0,
1609 doc
: /* Mark WINDOW as dedicated according to FLAG.
1610 WINDOW must be a live window and defaults to the selected one. FLAG
1611 non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means
1612 mark WINDOW as non-dedicated. Return FLAG.
1614 When a window is dedicated to its buffer, `display-buffer' will refrain
1615 from displaying another buffer in it. `get-lru-window' and
1616 `get-largest-window' treat dedicated windows specially.
1617 `delete-windows-on', `replace-buffer-in-windows', `quit-window',
1618 `quit-restore-window' and `kill-buffer' can delete a dedicated window
1619 and the containing frame.
1621 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
1622 its buffer. Functions like `set-window-buffer' may change the buffer
1623 displayed by a window, unless that window is strongly dedicated to its
1624 buffer. If and when `set-window-buffer' displays another buffer in a
1625 window, it also makes sure that the window is no more dedicated. */)
1626 (Lisp_Object window
, Lisp_Object flag
)
1628 register struct window
*w
= decode_window (window
);
1630 w
->dedicated
= flag
;
1631 return w
->dedicated
;
1634 DEFUN ("window-prev-buffers", Fwindow_prev_buffers
, Swindow_prev_buffers
,
1636 doc
: /* Return buffers previously shown in WINDOW.
1637 WINDOW must be a live window and defaults to the selected one.
1639 The return value is a list of elements (BUFFER WINDOW-START POS),
1640 where BUFFER is a buffer, WINDOW-START is the start position of the
1641 window for that buffer, and POS is a window-specific point value. */)
1642 (Lisp_Object window
)
1644 return decode_window (window
)->prev_buffers
;
1647 DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers
,
1648 Sset_window_prev_buffers
, 2, 2, 0,
1649 doc
: /* Set WINDOW's previous buffers to PREV-BUFFERS.
1650 WINDOW must be a live window and defaults to the selected one.
1652 PREV-BUFFERS should be a list of elements (BUFFER WINDOW-START POS),
1653 where BUFFER is a buffer, WINDOW-START is the start position of the
1654 window for that buffer, and POS is a window-specific point value. */)
1655 (Lisp_Object window
, Lisp_Object prev_buffers
)
1657 return decode_window (window
)->prev_buffers
= prev_buffers
;
1660 DEFUN ("window-next-buffers", Fwindow_next_buffers
, Swindow_next_buffers
,
1662 doc
: /* Return list of buffers recently re-shown in WINDOW.
1663 WINDOW must be a live window and defaults to the selected one. */)
1664 (Lisp_Object window
)
1666 return decode_window (window
)->next_buffers
;
1669 DEFUN ("set-window-next-buffers", Fset_window_next_buffers
,
1670 Sset_window_next_buffers
, 2, 2, 0,
1671 doc
: /* Set WINDOW's next buffers to NEXT-BUFFERS.
1672 WINDOW must be a live window and defaults to the selected one.
1673 NEXT-BUFFERS should be a list of buffers. */)
1674 (Lisp_Object window
, Lisp_Object next_buffers
)
1676 return decode_window (window
)->next_buffers
= next_buffers
;
1679 DEFUN ("window-parameters", Fwindow_parameters
, Swindow_parameters
,
1681 doc
: /* Return the parameters of WINDOW and their values.
1682 WINDOW defaults to the selected window. The return value is a list of
1683 elements of the form (PARAMETER . VALUE). */)
1684 (Lisp_Object window
)
1686 return Fcopy_alist (decode_any_window (window
)->window_parameters
);
1689 DEFUN ("window-parameter", Fwindow_parameter
, Swindow_parameter
,
1691 doc
: /* Return WINDOW's value for PARAMETER.
1692 WINDOW defaults to the selected window. */)
1693 (Lisp_Object window
, Lisp_Object parameter
)
1697 result
= Fassq (parameter
, decode_any_window (window
)->window_parameters
);
1698 return CDR_SAFE (result
);
1701 DEFUN ("set-window-parameter", Fset_window_parameter
,
1702 Sset_window_parameter
, 3, 3, 0,
1703 doc
: /* Set WINDOW's value of PARAMETER to VALUE.
1704 WINDOW defaults to the selected window. Return VALUE. */)
1705 (Lisp_Object window
, Lisp_Object parameter
, Lisp_Object value
)
1707 register struct window
*w
= decode_any_window (window
);
1708 Lisp_Object old_alist_elt
;
1710 old_alist_elt
= Fassq (parameter
, w
->window_parameters
);
1711 if (NILP (old_alist_elt
))
1712 w
->window_parameters
= Fcons (Fcons (parameter
, value
), w
->window_parameters
);
1714 Fsetcdr (old_alist_elt
, value
);
1718 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1720 doc
: /* Return the display-table that WINDOW is using.
1721 WINDOW defaults to the selected window. */)
1722 (Lisp_Object window
)
1724 return decode_window (window
)->display_table
;
1727 /* Get the display table for use on window W. This is either W's
1728 display table or W's buffer's display table. Ignore the specified
1729 tables if they are not valid; if no valid table is specified,
1732 struct Lisp_Char_Table
*
1733 window_display_table (struct window
*w
)
1735 struct Lisp_Char_Table
*dp
= NULL
;
1737 if (DISP_TABLE_P (w
->display_table
))
1738 dp
= XCHAR_TABLE (w
->display_table
);
1739 else if (BUFFERP (w
->buffer
))
1741 struct buffer
*b
= XBUFFER (w
->buffer
);
1743 if (DISP_TABLE_P (BVAR (b
, display_table
)))
1744 dp
= XCHAR_TABLE (BVAR (b
, display_table
));
1745 else if (DISP_TABLE_P (Vstandard_display_table
))
1746 dp
= XCHAR_TABLE (Vstandard_display_table
);
1752 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1753 doc
: /* Set WINDOW's display-table to TABLE. */)
1754 (register Lisp_Object window
, Lisp_Object table
)
1756 register struct window
*w
;
1758 w
= decode_window (window
);
1759 w
->display_table
= table
;
1763 /* Record info on buffer window W is displaying
1764 when it is about to cease to display that buffer. */
1766 unshow_buffer (register struct window
*w
)
1773 if (b
!= XMARKER (w
->pointm
)->buffer
)
1777 if (w
== XWINDOW (selected_window
)
1778 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1779 /* Do this except when the selected window's buffer
1780 is being removed from some other window. */
1782 /* last_window_start records the start position that this buffer
1783 had in the last window to be disconnected from it.
1784 Now that this statement is unconditional,
1785 it is possible for the buffer to be displayed in the
1786 selected window, while last_window_start reflects another
1787 window which was recently showing the same buffer.
1788 Some people might say that might be a good thing. Let's see. */
1789 b
->last_window_start
= marker_position (w
->start
);
1791 /* Point in the selected window's buffer
1792 is actually stored in that buffer, and the window's pointm isn't used.
1793 So don't clobber point in that buffer. */
1794 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1795 /* This line helps to fix Horsley's testbug.el bug. */
1796 && !(WINDOWP (BVAR (b
, last_selected_window
))
1797 && w
!= XWINDOW (BVAR (b
, last_selected_window
))
1798 && EQ (buf
, XWINDOW (BVAR (b
, last_selected_window
))->buffer
)))
1799 temp_set_point_both (b
,
1800 clip_to_bounds (BUF_BEGV (b
),
1801 XMARKER (w
->pointm
)->charpos
,
1803 clip_to_bounds (BUF_BEGV_BYTE (b
),
1804 marker_byte_position (w
->pointm
),
1807 if (WINDOWP (BVAR (b
, last_selected_window
))
1808 && w
== XWINDOW (BVAR (b
, last_selected_window
)))
1809 BVAR (b
, last_selected_window
) = Qnil
;
1812 /* Put NEW into the window structure in place of OLD. SETFLAG zero
1813 means change window structure only. Otherwise store geometry and
1814 other settings as well. */
1816 replace_window (Lisp_Object old
, Lisp_Object
new, int setflag
)
1818 register Lisp_Object tem
;
1819 register struct window
*o
= XWINDOW (old
), *n
= XWINDOW (new);
1821 /* If OLD is its frame's root window, then NEW is the new
1822 root window for that frame. */
1823 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1824 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = new;
1828 n
->left_col
= o
->left_col
;
1829 n
->top_line
= o
->top_line
;
1830 n
->total_cols
= o
->total_cols
;
1831 n
->total_lines
= o
->total_lines
;
1832 n
->normal_cols
= o
->normal_cols
;
1833 o
->normal_cols
= make_float (1.0);
1834 n
->normal_lines
= o
->normal_lines
;
1835 o
->normal_lines
= make_float (1.0);
1836 n
->desired_matrix
= n
->current_matrix
= 0;
1838 memset (&n
->cursor
, 0, sizeof (n
->cursor
));
1839 memset (&n
->last_cursor
, 0, sizeof (n
->last_cursor
));
1840 memset (&n
->phys_cursor
, 0, sizeof (n
->phys_cursor
));
1841 n
->phys_cursor_type
= -1;
1842 n
->phys_cursor_width
= -1;
1843 n
->must_be_updated_p
= 0;
1844 n
->pseudo_window_p
= 0;
1845 XSETFASTINT (n
->window_end_vpos
, 0);
1846 XSETFASTINT (n
->window_end_pos
, 0);
1847 n
->window_end_valid
= Qnil
;
1848 n
->frozen_window_start_p
= 0;
1851 n
->next
= tem
= o
->next
;
1853 XWINDOW (tem
)->prev
= new;
1855 n
->prev
= tem
= o
->prev
;
1857 XWINDOW (tem
)->next
= new;
1859 n
->parent
= tem
= o
->parent
;
1862 if (EQ (XWINDOW (tem
)->vchild
, old
))
1863 XWINDOW (tem
)->vchild
= new;
1864 if (EQ (XWINDOW (tem
)->hchild
, old
))
1865 XWINDOW (tem
)->hchild
= new;
1869 /* If window WINDOW and its parent window are iso-combined, merge
1870 WINDOW's children into those of its parent window and mark WINDOW as
1874 recombine_windows (Lisp_Object window
)
1876 struct window
*w
, *p
, *c
;
1877 Lisp_Object parent
, child
;
1880 w
= XWINDOW (window
);
1882 if (!NILP (parent
) && NILP (w
->combination_limit
))
1884 p
= XWINDOW (parent
);
1885 if (((!NILP (p
->vchild
) && !NILP (w
->vchild
))
1886 || (!NILP (p
->hchild
) && !NILP (w
->hchild
))))
1887 /* WINDOW and PARENT are both either a vertical or a horizontal
1890 horflag
= NILP (w
->vchild
);
1891 child
= horflag
? w
->hchild
: w
->vchild
;
1892 c
= XWINDOW (child
);
1894 /* Splice WINDOW's children into its parent's children and
1895 assign new normal sizes. */
1904 XWINDOW (w
->prev
)->next
= child
;
1913 = make_float (XFLOATINT (c
->total_cols
)
1914 / XFLOATINT (p
->total_cols
));
1917 = make_float (XFLOATINT (c
->total_lines
)
1918 / XFLOATINT (p
->total_lines
));
1922 if (!NILP (w
->next
))
1925 XWINDOW (c
->next
)->prev
= child
;
1933 c
= XWINDOW (child
);
1937 /* WINDOW can be deleted now. */
1938 w
->vchild
= w
->hchild
= Qnil
;
1943 /* If WINDOW can be deleted, delete it. */
1945 delete_deletable_window (Lisp_Object window
)
1947 if (!NILP (call1 (Qwindow_deletable_p
, window
)))
1948 call1 (Qdelete_window
, window
);
1951 /***********************************************************************
1953 ***********************************************************************/
1955 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1956 pointer. This is a callback function for foreach_window, used in
1957 the window_list function. */
1960 add_window_to_list (struct window
*w
, void *user_data
)
1962 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1964 XSETWINDOW (window
, w
);
1965 *list
= Fcons (window
, *list
);
1970 /* Return a list of all windows, for use by next_window. If
1971 Vwindow_list is a list, return that list. Otherwise, build a new
1972 list, cache it in Vwindow_list, and return that. */
1977 if (!CONSP (Vwindow_list
))
1981 Vwindow_list
= Qnil
;
1982 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1984 Lisp_Object args
[2];
1986 /* We are visiting windows in canonical order, and add
1987 new windows at the front of args[1], which means we
1988 have to reverse this list at the end. */
1990 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1991 args
[0] = Vwindow_list
;
1992 args
[1] = Fnreverse (args
[1]);
1993 Vwindow_list
= Fnconc (2, args
);
1997 return Vwindow_list
;
2001 /* Value is non-zero if WINDOW satisfies the constraints given by
2002 OWINDOW, MINIBUF and ALL_FRAMES.
2004 MINIBUF t means WINDOW may be minibuffer windows.
2005 `lambda' means WINDOW may not be a minibuffer window.
2006 a window means a specific minibuffer window
2008 ALL_FRAMES t means search all frames,
2009 nil means search just current frame,
2010 `visible' means search just visible frames on the
2012 0 means search visible and iconified frames on the
2014 a window means search the frame that window belongs to,
2015 a frame means consider windows on that frame, only. */
2018 candidate_window_p (Lisp_Object window
, Lisp_Object owindow
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2020 struct window
*w
= XWINDOW (window
);
2021 struct frame
*f
= XFRAME (w
->frame
);
2022 int candidate_p
= 1;
2024 if (!BUFFERP (w
->buffer
))
2026 else if (MINI_WINDOW_P (w
)
2027 && (EQ (minibuf
, Qlambda
)
2028 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
2030 /* If MINIBUF is `lambda' don't consider any mini-windows.
2031 If it is a window, consider only that one. */
2034 else if (EQ (all_frames
, Qt
))
2036 else if (NILP (all_frames
))
2038 eassert (WINDOWP (owindow
));
2039 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
2041 else if (EQ (all_frames
, Qvisible
))
2043 FRAME_SAMPLE_VISIBILITY (f
);
2044 candidate_p
= FRAME_VISIBLE_P (f
)
2045 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2046 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2049 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
2051 FRAME_SAMPLE_VISIBILITY (f
);
2052 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
2053 #ifdef HAVE_X_WINDOWS
2054 /* Yuck!! If we've just created the frame and the
2055 window-manager requested the user to place it
2056 manually, the window may still not be considered
2057 `visible'. I'd argue it should be at least
2058 something like `iconified', but don't know how to do
2060 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
2061 && !f
->output_data
.x
->has_been_visible
)
2064 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2065 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2067 else if (WINDOWP (all_frames
))
2068 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
2069 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
2070 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
2071 else if (FRAMEP (all_frames
))
2072 candidate_p
= EQ (all_frames
, w
->frame
);
2078 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2079 Fwindow_list. See candidate_window_p for the meaning of WINDOW,
2080 MINIBUF, and ALL_FRAMES. */
2083 decode_next_window_args (Lisp_Object
*window
, Lisp_Object
*minibuf
, Lisp_Object
*all_frames
)
2086 *window
= selected_window
;
2088 CHECK_LIVE_WINDOW (*window
);
2090 /* MINIBUF nil may or may not include minibuffers. Decide if it
2092 if (NILP (*minibuf
))
2093 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
2094 else if (!EQ (*minibuf
, Qt
))
2097 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2098 => count none of them, or a specific minibuffer window (the
2099 active one) to count. */
2101 /* ALL_FRAMES nil doesn't specify which frames to include. */
2102 if (NILP (*all_frames
))
2103 *all_frames
= (!EQ (*minibuf
, Qlambda
)
2104 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
2106 else if (EQ (*all_frames
, Qvisible
))
2108 else if (EQ (*all_frames
, make_number (0)))
2110 else if (FRAMEP (*all_frames
))
2112 else if (!EQ (*all_frames
, Qt
))
2117 /* Return the next or previous window of WINDOW in cyclic ordering
2118 of windows. NEXT_P non-zero means return the next window. See the
2119 documentation string of next-window for the meaning of MINIBUF and
2123 next_window (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
, int next_p
)
2125 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2127 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2128 return the first window on the frame. */
2129 if (FRAMEP (all_frames
)
2130 && !EQ (all_frames
, XWINDOW (window
)->frame
))
2131 return Fframe_first_window (all_frames
);
2137 /* Find WINDOW in the list of all windows. */
2138 list
= Fmemq (window
, window_list ());
2140 /* Scan forward from WINDOW to the end of the window list. */
2142 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
2143 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2146 /* Scan from the start of the window list up to WINDOW. */
2148 for (list
= Vwindow_list
;
2149 CONSP (list
) && !EQ (XCAR (list
), window
);
2151 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2155 window
= XCAR (list
);
2159 Lisp_Object candidate
, list
;
2161 /* Scan through the list of windows for candidates. If there are
2162 candidate windows in front of WINDOW, the last one of these
2163 is the one we want. If there are candidates following WINDOW
2164 in the list, again the last one of these is the one we want. */
2166 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
2168 if (EQ (XCAR (list
), window
))
2170 if (WINDOWP (candidate
))
2173 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
2175 candidate
= XCAR (list
);
2178 if (WINDOWP (candidate
))
2186 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
2187 doc
: /* Return live window after WINDOW in the cyclic ordering of windows.
2188 WINDOW must be a live window and defaults to the selected one. The
2189 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2192 MINIBUF nil or omitted means consider the minibuffer window only if the
2193 minibuffer is active. MINIBUF t means consider the minibuffer window
2194 even if the minibuffer is not active. Any other value means do not
2195 consider the minibuffer window even if the minibuffer is active.
2197 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2198 plus the minibuffer window if specified by the MINIBUF argument. If the
2199 minibuffer counts, consider all windows on all frames that share that
2200 minibuffer too. The following non-nil values of ALL-FRAMES have special
2203 - t means consider all windows on all existing frames.
2205 - `visible' means consider all windows on all visible frames.
2207 - 0 (the number zero) means consider all windows on all visible and
2210 - A frame means consider all windows on that frame only.
2212 Anything else means consider all windows on WINDOW's frame and no
2215 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2216 `next-window' to iterate through the entire cycle of acceptable
2217 windows, eventually ending up back at the window you started with.
2218 `previous-window' traverses the same cycle, in the reverse order. */)
2219 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2221 return next_window (window
, minibuf
, all_frames
, 1);
2225 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
2226 doc
: /* Return live window before WINDOW in the cyclic ordering of windows.
2227 WINDOW must be a live window and defaults to the selected one. The
2228 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2231 MINIBUF nil or omitted means consider the minibuffer window only if the
2232 minibuffer is active. MINIBUF t means consider the minibuffer window
2233 even if the minibuffer is not active. Any other value means do not
2234 consider the minibuffer window even if the minibuffer is active.
2236 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2237 plus the minibuffer window if specified by the MINIBUF argument. If the
2238 minibuffer counts, consider all windows on all frames that share that
2239 minibuffer too. The following non-nil values of ALL-FRAMES have special
2242 - t means consider all windows on all existing frames.
2244 - `visible' means consider all windows on all visible frames.
2246 - 0 (the number zero) means consider all windows on all visible and
2249 - A frame means consider all windows on that frame only.
2251 Anything else means consider all windows on WINDOW's frame and no
2254 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2255 use `previous-window' to iterate through the entire cycle of
2256 acceptable windows, eventually ending up back at the window you
2257 started with. `next-window' traverses the same cycle, in the
2259 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2261 return next_window (window
, minibuf
, all_frames
, 0);
2265 /* Return a list of windows in cyclic ordering. Arguments are like
2266 for `next-window'. */
2269 window_list_1 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2271 Lisp_Object tail
, list
, rest
;
2273 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2276 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2277 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2278 list
= Fcons (XCAR (tail
), list
);
2280 /* Rotate the list to start with WINDOW. */
2281 list
= Fnreverse (list
);
2282 rest
= Fmemq (window
, list
);
2283 if (!NILP (rest
) && !EQ (rest
, list
))
2285 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2287 XSETCDR (tail
, Qnil
);
2288 list
= nconc2 (rest
, list
);
2294 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2295 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2296 FRAME nil or omitted means use the selected frame.
2297 WINDOW nil or omitted means use the window selected within FRAME.
2298 MINIBUF t means include the minibuffer window, even if it isn't active.
2299 MINIBUF nil or omitted means include the minibuffer window only
2301 MINIBUF neither nil nor t means never include the minibuffer window. */)
2302 (Lisp_Object frame
, Lisp_Object minibuf
, Lisp_Object window
)
2305 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2306 CHECK_WINDOW (window
);
2308 frame
= selected_frame
;
2310 if (!EQ (frame
, XWINDOW (window
)->frame
))
2311 error ("Window is on a different frame");
2313 return window_list_1 (window
, minibuf
, frame
);
2317 DEFUN ("window-list-1", Fwindow_list_1
, Swindow_list_1
, 0, 3, 0,
2318 doc
: /* Return a list of all live windows.
2319 WINDOW specifies the first window to list and defaults to the selected
2322 Optional argument MINIBUF nil or omitted means consider the minibuffer
2323 window only if the minibuffer is active. MINIBUF t means consider the
2324 minibuffer window even if the minibuffer is not active. Any other value
2325 means do not consider the minibuffer window even if the minibuffer is
2328 Optional argument ALL-FRAMES nil or omitted means consider all windows
2329 on WINDOW's frame, plus the minibuffer window if specified by the
2330 MINIBUF argument. If the minibuffer counts, consider all windows on all
2331 frames that share that minibuffer too. The following non-nil values of
2332 ALL-FRAMES have special meanings:
2334 - t means consider all windows on all existing frames.
2336 - `visible' means consider all windows on all visible frames.
2338 - 0 (the number zero) means consider all windows on all visible and
2341 - A frame means consider all windows on that frame only.
2343 Anything else means consider all windows on WINDOW's frame and no
2346 If WINDOW is not on the list of windows returned, some other window will
2347 be listed first but no error is signaled. */)
2348 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2350 return window_list_1 (window
, minibuf
, all_frames
);
2353 /* Look at all windows, performing an operation specified by TYPE
2355 If FRAMES is Qt, look at all frames;
2356 Qnil, look at just the selected frame;
2357 Qvisible, look at visible frames;
2358 a frame, just look at windows on that frame.
2359 If MINI is non-zero, perform the operation on minibuffer windows too. */
2364 GET_BUFFER_WINDOW
, /* Arg is buffer */
2365 REPLACE_BUFFER_IN_WINDOWS_SAFELY
, /* Arg is buffer */
2366 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2371 window_loop (enum window_loop type
, Lisp_Object obj
, int mini
, Lisp_Object frames
)
2373 Lisp_Object window
, windows
, best_window
, frame_arg
;
2374 int frame_best_window_flag
= 0;
2376 struct gcpro gcpro1
;
2378 /* If we're only looping through windows on a particular frame,
2379 frame points to that frame. If we're looping through windows
2380 on all frames, frame is 0. */
2381 if (FRAMEP (frames
))
2382 f
= XFRAME (frames
);
2383 else if (NILP (frames
))
2384 f
= SELECTED_FRAME ();
2389 frame_arg
= Qlambda
;
2390 else if (EQ (frames
, make_number (0)))
2392 else if (EQ (frames
, Qvisible
))
2397 /* frame_arg is Qlambda to stick to one frame,
2398 Qvisible to consider all visible frames,
2401 /* Pick a window to start with. */
2405 window
= FRAME_SELECTED_WINDOW (f
);
2407 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2409 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2413 for (; CONSP (windows
); windows
= XCDR (windows
))
2417 window
= XCAR (windows
);
2418 w
= XWINDOW (window
);
2420 /* Note that we do not pay attention here to whether the frame
2421 is visible, since Fwindow_list skips non-visible frames if
2422 that is desired, under the control of frame_arg. */
2423 if (!MINI_WINDOW_P (w
)
2424 /* For REPLACE_BUFFER_IN_WINDOWS_SAFELY, we must always
2425 consider all windows. */
2426 || type
== REPLACE_BUFFER_IN_WINDOWS_SAFELY
2427 || (mini
&& minibuf_level
> 0))
2430 case GET_BUFFER_WINDOW
:
2431 if (EQ (w
->buffer
, obj
)
2432 /* Don't find any minibuffer window except the one that
2433 is currently in use. */
2434 && (MINI_WINDOW_P (w
) ? EQ (window
, minibuf_window
) : 1))
2436 if (EQ (window
, selected_window
))
2437 /* Preferably return the selected window. */
2438 RETURN_UNGCPRO (window
);
2439 else if (EQ (XWINDOW (window
)->frame
, selected_frame
)
2440 && !frame_best_window_flag
)
2441 /* Prefer windows on the current frame (but don't
2442 choose another one if we have one already). */
2444 best_window
= window
;
2445 frame_best_window_flag
= 1;
2447 else if (NILP (best_window
))
2448 best_window
= window
;
2452 case REPLACE_BUFFER_IN_WINDOWS_SAFELY
:
2453 /* We could simply check whether the buffer shown by window
2454 is live, and show another buffer in case it isn't. */
2455 if (EQ (w
->buffer
, obj
))
2457 /* Undedicate WINDOW. */
2458 w
->dedicated
= Qnil
;
2459 /* Make WINDOW show the buffer returned by
2460 other_buffer_safely, don't run any hooks. */
2462 (window
, other_buffer_safely (w
->buffer
), 0, 0);
2463 /* If WINDOW is the selected window, make its buffer
2464 current. But do so only if the window shows the
2465 current buffer (Bug#6454). */
2466 if (EQ (window
, selected_window
)
2467 && XBUFFER (w
->buffer
) == current_buffer
)
2468 Fset_buffer (w
->buffer
);
2472 case REDISPLAY_BUFFER_WINDOWS
:
2473 if (EQ (w
->buffer
, obj
))
2475 mark_window_display_accurate (window
, 0);
2476 w
->update_mode_line
= 1;
2477 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2478 ++update_mode_lines
;
2479 best_window
= window
;
2483 /* Check for a window that has a killed buffer. */
2484 case CHECK_ALL_WINDOWS
:
2485 if (! NILP (w
->buffer
)
2486 && NILP (BVAR (XBUFFER (w
->buffer
), name
)))
2490 case WINDOW_LOOP_UNUSED
:
2499 /* Used for debugging. Abort if any window has a dead buffer. */
2501 extern void check_all_windows (void) EXTERNALLY_VISIBLE
;
2503 check_all_windows (void)
2505 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2508 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 0, 2, 0,
2509 doc
: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2510 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to
2513 The optional argument ALL-FRAMES specifies the frames to consider:
2515 - t means consider all windows on all existing frames.
2517 - `visible' means consider all windows on all visible frames.
2519 - 0 (the number zero) means consider all windows on all visible
2520 and iconified frames.
2522 - A frame means consider all windows on that frame only.
2524 Any other value of ALL-FRAMES means consider all windows on the
2525 selected frame and no others. */)
2526 (Lisp_Object buffer_or_name
, Lisp_Object all_frames
)
2530 if (NILP (buffer_or_name
))
2531 buffer
= Fcurrent_buffer ();
2533 buffer
= Fget_buffer (buffer_or_name
);
2535 if (BUFFERP (buffer
))
2536 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, all_frames
);
2542 resize_root_window (Lisp_Object window
, Lisp_Object delta
, Lisp_Object horizontal
, Lisp_Object ignore
)
2544 return call4 (Qwindow_resize_root_window
, window
, delta
, horizontal
, ignore
);
2548 DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal
,
2549 Sdelete_other_windows_internal
, 0, 2, "",
2550 doc
: /* Make WINDOW fill its frame.
2551 Only the frame WINDOW is on is affected. WINDOW may be any window and
2552 defaults to the selected one.
2554 Optional argument ROOT, if non-nil, must specify an internal window such
2555 that WINDOW is in its window subtree. If this is the case, replace ROOT
2556 by WINDOW and leave alone any windows not part of ROOT's subtree.
2558 When WINDOW is live try to reduce display jumps by keeping the text
2559 previously visible in WINDOW in the same place on the frame. Doing this
2560 depends on the value of (window-start WINDOW), so if calling this
2561 function in a program gives strange scrolling, make sure the
2562 window-start value is reasonable when this function is called. */)
2563 (Lisp_Object window
, Lisp_Object root
)
2565 struct window
*w
, *r
, *s
;
2567 Lisp_Object sibling
, pwindow
, swindow
IF_LINT (= Qnil
), delta
;
2568 ptrdiff_t startpos
IF_LINT (= 0);
2569 int top
IF_LINT (= 0), new_top
, resize_failed
;
2571 w
= decode_any_window (window
);
2572 XSETWINDOW (window
, w
);
2573 f
= XFRAME (w
->frame
);
2576 /* ROOT is the frame's root window. */
2578 root
= FRAME_ROOT_WINDOW (f
);
2582 /* ROOT must be an ancestor of WINDOW. */
2584 r
= decode_any_window (root
);
2585 pwindow
= XWINDOW (window
)->parent
;
2586 while (!NILP (pwindow
))
2587 if (EQ (pwindow
, root
))
2590 pwindow
= XWINDOW (pwindow
)->parent
;
2591 if (!EQ (pwindow
, root
))
2592 error ("Specified root is not an ancestor of specified window");
2595 if (EQ (window
, root
))
2598 /* I don't understand the "top > 0" part below. If we deal with a
2599 standalone minibuffer it would have been caught by the preceding
2601 else if (MINI_WINDOW_P (w
)) /* && top > 0) */
2602 error ("Can't expand minibuffer to full frame");
2604 if (!NILP (w
->buffer
))
2606 startpos
= marker_position (w
->start
);
2607 top
= WINDOW_TOP_EDGE_LINE (w
)
2608 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2609 /* Make sure WINDOW is the frame's selected window. */
2610 if (!EQ (window
, FRAME_SELECTED_WINDOW (f
)))
2612 if (EQ (selected_frame
, w
->frame
))
2613 Fselect_window (window
, Qnil
);
2615 FRAME_SELECTED_WINDOW (f
) = window
;
2620 /* See if the frame's selected window is a part of the window
2621 subtree rooted at WINDOW, by finding all the selected window's
2622 parents and comparing each one with WINDOW. If it isn't we
2623 need a new selected window for this frame. */
2624 swindow
= FRAME_SELECTED_WINDOW (f
);
2628 while (!NILP (pwindow
) && !EQ (window
, pwindow
))
2629 pwindow
= XWINDOW (pwindow
)->parent
;
2631 if (EQ (window
, pwindow
))
2632 /* If WINDOW is an ancestor of SWINDOW, then SWINDOW is ok
2633 as the new selected window. */
2636 /* Else try the previous window of SWINDOW. */
2637 swindow
= Fprevious_window (swindow
, Qlambda
, Qnil
);
2640 if (!EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
2642 if (EQ (selected_frame
, w
->frame
))
2643 Fselect_window (swindow
, Qnil
);
2645 FRAME_SELECTED_WINDOW (f
) = swindow
;
2650 if (!FRAME_INITIAL_P (f
))
2652 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
2654 /* We are going to free the glyph matrices of WINDOW, and with
2655 that we might lose any information about glyph rows that have
2656 some of their glyphs highlighted in mouse face. (These rows
2657 are marked with a non-zero mouse_face_p flag.) If WINDOW
2658 indeed has some glyphs highlighted in mouse face, signal to
2659 frame's up-to-date hook that mouse highlight was overwritten,
2660 so that it will arrange for redisplaying the highlight. */
2661 if (EQ (hlinfo
->mouse_face_window
, window
))
2663 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
2664 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
2665 hlinfo
->mouse_face_window
= Qnil
;
2668 free_window_matrices (r
);
2670 windows_or_buffers_changed
++;
2671 Vwindow_list
= Qnil
;
2672 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
2675 if (NILP (w
->buffer
))
2677 /* Resize child windows vertically. */
2678 XSETINT (delta
, XINT (r
->total_lines
) - XINT (w
->total_lines
));
2679 w
->top_line
= r
->top_line
;
2680 resize_root_window (window
, delta
, Qnil
, Qnil
);
2681 if (window_resize_check (w
, 0))
2682 window_resize_apply (w
, 0);
2685 resize_root_window (window
, delta
, Qnil
, Qt
);
2686 if (window_resize_check (w
, 0))
2687 window_resize_apply (w
, 0);
2692 /* Resize child windows horizontally. */
2695 w
->left_col
= r
->left_col
;
2696 XSETINT (delta
, XINT (r
->total_cols
) - XINT (w
->total_cols
));
2697 w
->left_col
= r
->left_col
;
2698 resize_root_window (window
, delta
, Qt
, Qnil
);
2699 if (window_resize_check (w
, 1))
2700 window_resize_apply (w
, 1);
2703 resize_root_window (window
, delta
, Qt
, Qt
);
2704 if (window_resize_check (w
, 1))
2705 window_resize_apply (w
, 1);
2712 /* Play safe, if we still can ... */
2715 w
= XWINDOW (window
);
2719 /* Cleanly unlink WINDOW from window-tree. */
2720 if (!NILP (w
->prev
))
2721 /* Get SIBLING above (on the left of) WINDOW. */
2724 s
= XWINDOW (sibling
);
2726 if (!NILP (s
->next
))
2727 XWINDOW (s
->next
)->prev
= sibling
;
2730 /* Get SIBLING below (on the right of) WINDOW. */
2733 s
= XWINDOW (sibling
);
2735 if (!NILP (XWINDOW (w
->parent
)->vchild
))
2736 XWINDOW (w
->parent
)->vchild
= sibling
;
2738 XWINDOW (w
->parent
)->hchild
= sibling
;
2741 /* Delete ROOT and all child windows of ROOT. */
2742 if (!NILP (r
->vchild
))
2744 delete_all_child_windows (r
->vchild
);
2747 else if (!NILP (r
->hchild
))
2749 delete_all_child_windows (r
->hchild
);
2753 replace_window (root
, window
, 1);
2755 /* This must become SWINDOW anyway ....... */
2756 if (!NILP (w
->buffer
) && !resize_failed
)
2758 /* Try to minimize scrolling, by setting the window start to the
2759 point will cause the text at the old window start to be at the
2760 same place on the frame. But don't try to do this if the
2761 window start is outside the visible portion (as might happen
2762 when the display is not current, due to typeahead). */
2763 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2765 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2766 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2768 struct position pos
;
2769 struct buffer
*obuf
= current_buffer
;
2771 Fset_buffer (w
->buffer
);
2772 /* This computation used to temporarily move point, but that
2773 can have unwanted side effects due to text properties. */
2774 pos
= *vmotion (startpos
, -top
, w
);
2776 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2777 w
->window_end_valid
= Qnil
;
2778 w
->start_at_line_beg
= (pos
.bytepos
== BEGV_BYTE
2779 || FETCH_BYTE (pos
.bytepos
- 1) == '\n');
2780 /* We need to do this, so that the window-scroll-functions
2782 w
->optional_new_start
= 1;
2784 set_buffer_internal (obuf
);
2791 run_window_configuration_change_hook (f
);
2798 replace_buffer_in_windows (Lisp_Object buffer
)
2800 call1 (Qreplace_buffer_in_windows
, buffer
);
2804 /* Safely replace BUFFER with some other buffer in all windows of all
2805 frames, even those on other keyboards. */
2808 replace_buffer_in_windows_safely (Lisp_Object buffer
)
2810 Lisp_Object tail
, frame
;
2812 /* A single call to window_loop won't do the job because it only
2813 considers frames on the current keyboard. So loop manually over
2814 frames, and handle each one. */
2815 FOR_EACH_FRAME (tail
, frame
)
2816 window_loop (REPLACE_BUFFER_IN_WINDOWS_SAFELY
, buffer
, 1, frame
);
2819 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2820 minimum allowable size. */
2823 check_frame_size (FRAME_PTR frame
, int *rows
, int *cols
)
2825 /* For height, we have to see:
2826 how many windows the frame has at minimum (one or two),
2827 and whether it has a menu bar or other special stuff at the top. */
2829 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
2830 ? MIN_SAFE_WINDOW_HEIGHT
2831 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
2833 if (FRAME_TOP_MARGIN (frame
) > 0)
2834 min_height
+= FRAME_TOP_MARGIN (frame
);
2836 if (*rows
< min_height
)
2838 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2839 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2842 /* Adjust the margins of window W if text area is too small.
2843 Return 1 if window width is ok after adjustment; 0 if window
2844 is still too narrow. */
2847 adjust_window_margins (struct window
*w
)
2849 int box_cols
= (WINDOW_TOTAL_COLS (w
)
2850 - WINDOW_FRINGE_COLS (w
)
2851 - WINDOW_SCROLL_BAR_COLS (w
));
2852 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
2853 + WINDOW_RIGHT_MARGIN_COLS (w
));
2855 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
2858 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
2861 /* Window's text area is too narrow, but reducing the window
2862 margins will fix that. */
2863 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
2864 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
2866 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
2867 w
->left_margin_cols
= w
->right_margin_cols
2868 = make_number (margin_cols
/2);
2870 w
->right_margin_cols
= make_number (margin_cols
);
2873 w
->left_margin_cols
= make_number (margin_cols
);
2877 static Lisp_Object
Fset_window_margins (Lisp_Object
, Lisp_Object
, Lisp_Object
);
2878 static Lisp_Object
Fset_window_fringes (Lisp_Object
, Lisp_Object
, Lisp_Object
,
2880 static Lisp_Object
Fset_window_scroll_bars (Lisp_Object
, Lisp_Object
,
2881 Lisp_Object
, Lisp_Object
);
2882 static Lisp_Object
Fset_window_vscroll (Lisp_Object
, Lisp_Object
, Lisp_Object
);
2884 /* The following three routines are needed for running a window's
2885 configuration change hook. */
2887 run_funs (Lisp_Object funs
)
2889 for (; CONSP (funs
); funs
= XCDR (funs
))
2890 if (!EQ (XCAR (funs
), Qt
))
2891 call0 (XCAR (funs
));
2895 select_window_norecord (Lisp_Object window
)
2897 return WINDOW_LIVE_P (window
)
2898 ? Fselect_window (window
, Qt
) : selected_window
;
2902 select_frame_norecord (Lisp_Object frame
)
2904 return FRAME_LIVE_P (XFRAME (frame
))
2905 ? Fselect_frame (frame
, Qt
) : selected_frame
;
2909 run_window_configuration_change_hook (struct frame
*f
)
2911 ptrdiff_t count
= SPECPDL_INDEX ();
2912 Lisp_Object frame
, global_wcch
2913 = Fdefault_value (Qwindow_configuration_change_hook
);
2914 XSETFRAME (frame
, f
);
2916 if (NILP (Vrun_hooks
) || !NILP (inhibit_lisp_code
))
2919 /* Use the right buffer. Matters when running the local hooks. */
2920 if (current_buffer
!= XBUFFER (Fwindow_buffer (Qnil
)))
2922 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
2923 Fset_buffer (Fwindow_buffer (Qnil
));
2926 if (SELECTED_FRAME () != f
)
2928 record_unwind_protect (select_frame_norecord
, Fselected_frame ());
2929 select_frame_norecord (frame
);
2932 /* Look for buffer-local values. */
2934 Lisp_Object windows
= Fwindow_list (frame
, Qlambda
, Qnil
);
2935 for (; CONSP (windows
); windows
= XCDR (windows
))
2937 Lisp_Object window
= XCAR (windows
);
2938 Lisp_Object buffer
= Fwindow_buffer (window
);
2939 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook
,
2942 ptrdiff_t inner_count
= SPECPDL_INDEX ();
2943 record_unwind_protect (select_window_norecord
, Fselected_window ());
2944 select_window_norecord (window
);
2945 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook
,
2947 unbind_to (inner_count
, Qnil
);
2952 run_funs (global_wcch
);
2953 unbind_to (count
, Qnil
);
2956 DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook
,
2957 Srun_window_configuration_change_hook
, 1, 1, 0,
2958 doc
: /* Run `window-configuration-change-hook' for FRAME. */)
2961 CHECK_LIVE_FRAME (frame
);
2962 run_window_configuration_change_hook (XFRAME (frame
));
2966 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
2967 means it's allowed to run hooks. See make_frame for a case where
2968 it's not allowed. KEEP_MARGINS_P non-zero means that the current
2969 margins, fringes, and scroll-bar settings of the window are not
2970 reset from the buffer's local settings. */
2973 set_window_buffer (Lisp_Object window
, Lisp_Object buffer
, int run_hooks_p
, int keep_margins_p
)
2975 struct window
*w
= XWINDOW (window
);
2976 struct buffer
*b
= XBUFFER (buffer
);
2977 ptrdiff_t count
= SPECPDL_INDEX ();
2978 int samebuf
= EQ (buffer
, w
->buffer
);
2982 if (EQ (window
, selected_window
))
2983 BVAR (b
, last_selected_window
) = window
;
2985 /* Let redisplay errors through. */
2986 b
->display_error_modiff
= 0;
2988 /* Update time stamps of buffer display. */
2989 if (INTEGERP (BVAR (b
, display_count
)))
2990 XSETINT (BVAR (b
, display_count
), XINT (BVAR (b
, display_count
)) + 1);
2991 BVAR (b
, display_time
) = Fcurrent_time ();
2993 XSETFASTINT (w
->window_end_pos
, 0);
2994 XSETFASTINT (w
->window_end_vpos
, 0);
2995 memset (&w
->last_cursor
, 0, sizeof w
->last_cursor
);
2996 w
->window_end_valid
= Qnil
;
2997 if (!(keep_margins_p
&& samebuf
))
2998 { /* If we're not actually changing the buffer, don't reset hscroll and
2999 vscroll. This case happens for example when called from
3000 change_frame_size_1, where we use a dummy call to
3001 Fset_window_buffer on the frame's selected window (and no other)
3002 just in order to run window-configuration-change-hook.
3003 Resetting hscroll and vscroll here is problematic for things like
3004 image-mode and doc-view-mode since it resets the image's position
3005 whenever we resize the frame. */
3006 w
->hscroll
= w
->min_hscroll
= make_number (0);
3008 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3009 set_marker_restricted (w
->start
,
3010 make_number (b
->last_window_start
),
3012 w
->start_at_line_beg
= 0;
3014 XSETFASTINT (w
->last_modified
, 0);
3015 XSETFASTINT (w
->last_overlay_modified
, 0);
3017 /* Maybe we could move this into the `if' but it's not obviously safe and
3018 I doubt it's worth the trouble. */
3019 windows_or_buffers_changed
++;
3021 /* We must select BUFFER for running the window-scroll-functions. */
3022 /* We can't check ! NILP (Vwindow_scroll_functions) here
3023 because that might itself be a local variable. */
3024 if (window_initialized
)
3026 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
3027 Fset_buffer (buffer
);
3030 XMARKER (w
->pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3032 if (!keep_margins_p
)
3034 /* Set left and right marginal area width etc. from buffer. */
3036 /* This may call adjust_window_margins three times, so
3037 temporarily disable window margins. */
3038 Lisp_Object save_left
= w
->left_margin_cols
;
3039 Lisp_Object save_right
= w
->right_margin_cols
;
3041 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
3043 Fset_window_fringes (window
,
3044 BVAR (b
, left_fringe_width
), BVAR (b
, right_fringe_width
),
3045 BVAR (b
, fringes_outside_margins
));
3047 Fset_window_scroll_bars (window
,
3048 BVAR (b
, scroll_bar_width
),
3049 BVAR (b
, vertical_scroll_bar_type
), Qnil
);
3051 w
->left_margin_cols
= save_left
;
3052 w
->right_margin_cols
= save_right
;
3054 Fset_window_margins (window
,
3055 BVAR (b
, left_margin_cols
), BVAR (b
, right_margin_cols
));
3060 if (! NILP (Vwindow_scroll_functions
))
3061 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3062 Fmarker_position (w
->start
));
3063 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w
)));
3066 unbind_to (count
, Qnil
);
3069 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3070 doc
: /* Make WINDOW display BUFFER-OR-NAME as its contents.
3071 WINDOW has to be a live window and defaults to the selected one.
3072 BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
3074 Optional third argument KEEP-MARGINS non-nil means that WINDOW's current
3075 display margins, fringe widths, and scroll bar settings are preserved;
3076 the default is to reset these from the local settings for BUFFER-OR-NAME
3077 or the frame defaults. Return nil.
3079 This function throws an error when WINDOW is strongly dedicated to its
3080 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3081 already display BUFFER-OR-NAME.
3083 This function runs `window-scroll-functions' before running
3084 `window-configuration-change-hook'. */)
3085 (register Lisp_Object window
, Lisp_Object buffer_or_name
, Lisp_Object keep_margins
)
3087 register Lisp_Object tem
, buffer
;
3088 register struct window
*w
= decode_window (window
);
3090 XSETWINDOW (window
, w
);
3091 buffer
= Fget_buffer (buffer_or_name
);
3092 CHECK_BUFFER (buffer
);
3093 if (NILP (BVAR (XBUFFER (buffer
), name
)))
3094 error ("Attempt to display deleted buffer");
3098 error ("Window is deleted");
3099 else if (!EQ (tem
, Qt
))
3100 /* w->buffer is t when the window is first being set up. */
3102 if (!EQ (tem
, buffer
))
3104 if (EQ (w
->dedicated
, Qt
))
3105 /* WINDOW is strongly dedicated to its buffer, signal an
3107 error ("Window is dedicated to `%s'", SDATA (BVAR (XBUFFER (tem
), name
)));
3109 /* WINDOW is weakly dedicated to its buffer, reset
3111 w
->dedicated
= Qnil
;
3113 call1 (Qrecord_window_buffer
, window
);
3119 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3125 display_buffer (Lisp_Object buffer
, Lisp_Object not_this_window_p
, Lisp_Object override_frame
)
3127 return call3 (Qdisplay_buffer
, buffer
, not_this_window_p
, override_frame
);
3130 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3132 doc
: /* Force all windows to be updated on next redisplay.
3133 If optional arg OBJECT is a window, force redisplay of that window only.
3134 If OBJECT is a buffer or buffer name, force redisplay of all windows
3135 displaying that buffer. */)
3136 (Lisp_Object object
)
3140 windows_or_buffers_changed
++;
3141 update_mode_lines
++;
3145 if (WINDOWP (object
))
3147 struct window
*w
= XWINDOW (object
);
3148 mark_window_display_accurate (object
, 0);
3149 w
->update_mode_line
= 1;
3150 if (BUFFERP (w
->buffer
))
3151 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
3152 ++update_mode_lines
;
3156 if (STRINGP (object
))
3157 object
= Fget_buffer (object
);
3158 if (BUFFERP (object
) && !NILP (BVAR (XBUFFER (object
), name
)))
3160 /* Walk all windows looking for buffer, and force update
3161 of each of those windows. */
3163 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3164 return NILP (object
) ? Qnil
: Qt
;
3167 /* If nothing suitable was found, just return.
3168 We could signal an error, but this feature will typically be used
3169 asynchronously in timers or process sentinels, so we don't. */
3175 temp_output_buffer_show (register Lisp_Object buf
)
3177 register struct buffer
*old
= current_buffer
;
3178 register Lisp_Object window
;
3179 register struct window
*w
;
3181 BVAR (XBUFFER (buf
), directory
) = BVAR (current_buffer
, directory
);
3184 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3188 set_buffer_internal (old
);
3190 if (!NILP (Vtemp_buffer_show_function
))
3191 call1 (Vtemp_buffer_show_function
, buf
);
3194 window
= display_buffer (buf
, Qnil
, Qnil
);
3196 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3197 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3198 Vminibuf_scroll_window
= window
;
3199 w
= XWINDOW (window
);
3200 XSETFASTINT (w
->hscroll
, 0);
3201 XSETFASTINT (w
->min_hscroll
, 0);
3202 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3203 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3205 /* Run temp-buffer-show-hook, with the chosen window selected
3206 and its buffer current. */
3208 ptrdiff_t count
= SPECPDL_INDEX ();
3209 Lisp_Object prev_window
, prev_buffer
;
3210 prev_window
= selected_window
;
3211 XSETBUFFER (prev_buffer
, old
);
3213 /* Select the window that was chosen, for running the hook.
3214 Note: Both Fselect_window and select_window_norecord may
3215 set-buffer to the buffer displayed in the window,
3216 so we need to save the current buffer. --stef */
3217 record_unwind_protect (Fset_buffer
, prev_buffer
);
3218 record_unwind_protect (select_window_norecord
, prev_window
);
3219 Fselect_window (window
, Qt
);
3220 Fset_buffer (w
->buffer
);
3221 Frun_hooks (1, &Qtemp_buffer_show_hook
);
3222 unbind_to (count
, Qnil
);
3227 DEFUN ("internal-temp-output-buffer-show",
3228 Ftemp_output_buffer_show
, Stemp_output_buffer_show
,
3230 doc
: /* Internal function for `with-output-to-temp-buffer'. */)
3233 temp_output_buffer_show (buf
);
3237 /* Make new window, have it replace WINDOW in window-tree, and make
3238 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
3239 horizontal child). */
3241 make_parent_window (Lisp_Object window
, int horflag
)
3244 register struct window
*o
, *p
;
3246 o
= XWINDOW (window
);
3247 p
= allocate_window ();
3248 memcpy ((char *) p
+ sizeof (struct vectorlike_header
),
3249 (char *) o
+ sizeof (struct vectorlike_header
),
3250 sizeof (Lisp_Object
) * VECSIZE (struct window
));
3251 XSETWINDOW (parent
, p
);
3254 XSETFASTINT (p
->sequence_number
, sequence_number
);
3256 replace_window (window
, parent
, 1);
3262 p
->hchild
= horflag
? window
: Qnil
;
3263 p
->vchild
= horflag
? Qnil
: window
;
3267 p
->combination_limit
= Qnil
;
3268 p
->window_parameters
= Qnil
;
3271 /* Make new window from scratch. */
3276 register struct window
*w
;
3278 w
= allocate_window ();
3279 /* Initialize Lisp data. Note that allocate_window initializes all
3280 Lisp data to nil, so do it only for slots which should not be nil. */
3281 XSETFASTINT (w
->left_col
, 0);
3282 XSETFASTINT (w
->top_line
, 0);
3283 XSETFASTINT (w
->total_lines
, 0);
3284 XSETFASTINT (w
->total_cols
, 0);
3285 w
->normal_lines
= make_float (1.0);
3286 w
->normal_cols
= make_float (1.0);
3287 XSETFASTINT (w
->new_total
, 0);
3288 XSETFASTINT (w
->new_normal
, 0);
3289 w
->start
= Fmake_marker ();
3290 w
->pointm
= Fmake_marker ();
3291 XSETFASTINT (w
->hscroll
, 0);
3292 XSETFASTINT (w
->min_hscroll
, 0);
3293 XSETFASTINT (w
->use_time
, 0);
3295 XSETFASTINT (w
->sequence_number
, sequence_number
);
3296 XSETFASTINT (w
->last_point
, 0);
3297 w
->vertical_scroll_bar_type
= Qt
;
3298 XSETFASTINT (w
->window_end_pos
, 0);
3299 XSETFASTINT (w
->window_end_vpos
, 0);
3301 /* Initialize non-Lisp data. Note that allocate_window zeroes out all
3302 non-Lisp data, so do it only for slots which should not be zero. */
3303 w
->nrows_scale_factor
= w
->ncols_scale_factor
= 1;
3304 w
->phys_cursor_type
= -1;
3305 w
->phys_cursor_width
= -1;
3307 /* Reset window_list. */
3308 Vwindow_list
= Qnil
;
3309 /* Return window. */
3310 XSETWINDOW (window
, w
);
3314 DEFUN ("set-window-new-total", Fset_window_new_total
, Sset_window_new_total
, 2, 3, 0,
3315 doc
: /* Set new total size of WINDOW to SIZE.
3318 Optional argument ADD non-nil means add SIZE to the new total size of
3319 WINDOW and return the sum.
3321 Note: This function does not operate on any child windows of WINDOW. */)
3322 (Lisp_Object window
, Lisp_Object size
, Lisp_Object add
)
3324 struct window
*w
= decode_any_window (window
);
3326 CHECK_NUMBER (size
);
3328 XSETINT (w
->new_total
, XINT (size
));
3330 XSETINT (w
->new_total
, XINT (w
->new_total
) + XINT (size
));
3332 return w
->new_total
;
3335 DEFUN ("set-window-new-normal", Fset_window_new_normal
, Sset_window_new_normal
, 1, 2, 0,
3336 doc
: /* Set new normal size of WINDOW to SIZE.
3339 Note: This function does not operate on any child windows of WINDOW. */)
3340 (Lisp_Object window
, Lisp_Object size
)
3342 struct window
*w
= decode_any_window (window
);
3344 w
->new_normal
= size
;
3345 return w
->new_normal
;
3348 /* Return 1 if setting w->total_lines (w->total_cols if HORFLAG is
3349 non-zero) to w->new_total would result in correct heights (widths)
3350 for window W and recursively all child windows of W.
3352 Note: This function does not check any of `window-fixed-size-p',
3353 `window-min-height' or `window-min-width'. It does check that window
3354 sizes do not drop below one line (two columns). */
3356 window_resize_check (struct window
*w
, int horflag
)
3360 if (!NILP (w
->vchild
))
3361 /* W is a vertical combination. */
3363 c
= XWINDOW (w
->vchild
);
3365 /* All child windows of W must have the same width as W. */
3369 if ((XINT (c
->new_total
) != XINT (w
->new_total
))
3370 || !window_resize_check (c
, horflag
))
3372 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3377 /* The sum of the heights of the child windows of W must equal
3380 int sum_of_sizes
= 0;
3383 if (!window_resize_check (c
, horflag
))
3385 sum_of_sizes
= sum_of_sizes
+ XINT (c
->new_total
);
3386 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3388 return (sum_of_sizes
== XINT (w
->new_total
));
3391 else if (!NILP (w
->hchild
))
3392 /* W is a horizontal combination. */
3394 c
= XWINDOW (w
->hchild
);
3396 /* The sum of the widths of the child windows of W must equal W's
3399 int sum_of_sizes
= 0;
3402 if (!window_resize_check (c
, horflag
))
3404 sum_of_sizes
= sum_of_sizes
+ XINT (c
->new_total
);
3405 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3407 return (sum_of_sizes
== XINT (w
->new_total
));
3410 /* All child windows of W must have the same height as W. */
3414 if ((XINT (c
->new_total
) != XINT (w
->new_total
))
3415 || !window_resize_check (c
, horflag
))
3417 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3423 /* A leaf window. Make sure it's not too small. The following
3424 hardcodes the values of `window-safe-min-width' (2) and
3425 `window-safe-min-height' (1) which are defined in window.el. */
3426 return XINT (w
->new_total
) >= (horflag
? 2 : 1);
3429 /* Set w->total_lines (w->total_cols if HORIZONTAL is non-zero) to
3430 w->new_total for window W and recursively all child windows of W.
3431 Also calculate and assign the new vertical (horizontal) start
3432 positions of each of these windows.
3434 This function does not perform any error checks. Make sure you have
3435 run window_resize_check on W before applying this function. */
3437 window_resize_apply (struct window
*w
, int horflag
)
3442 /* Note: Assigning new_normal requires that the new total size of the
3443 parent window has been set *before*. */
3446 w
->total_cols
= w
->new_total
;
3447 if (NUMBERP (w
->new_normal
))
3448 w
->normal_cols
= w
->new_normal
;
3450 pos
= XINT (w
->left_col
);
3454 w
->total_lines
= w
->new_total
;
3455 if (NUMBERP (w
->new_normal
))
3456 w
->normal_lines
= w
->new_normal
;
3458 pos
= XINT (w
->top_line
);
3461 if (!NILP (w
->vchild
))
3462 /* W is a vertical combination. */
3464 c
= XWINDOW (w
->vchild
);
3468 XSETFASTINT (c
->left_col
, pos
);
3470 XSETFASTINT (c
->top_line
, pos
);
3471 window_resize_apply (c
, horflag
);
3473 pos
= pos
+ XINT (c
->total_lines
);
3474 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3477 else if (!NILP (w
->hchild
))
3478 /* W is a horizontal combination. */
3480 c
= XWINDOW (w
->hchild
);
3484 XSETFASTINT (c
->left_col
, pos
);
3486 XSETFASTINT (c
->top_line
, pos
);
3487 window_resize_apply (c
, horflag
);
3489 pos
= pos
+ XINT (c
->total_cols
);
3490 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3494 /* Clear out some redisplay caches. */
3495 XSETFASTINT (w
->last_modified
, 0);
3496 XSETFASTINT (w
->last_overlay_modified
, 0);
3500 DEFUN ("window-resize-apply", Fwindow_resize_apply
, Swindow_resize_apply
, 1, 2, 0,
3501 doc
: /* Apply requested size values for window-tree of FRAME.
3502 Optional argument HORIZONTAL omitted or nil means apply requested height
3503 values. HORIZONTAL non-nil means apply requested width values.
3505 This function checks whether the requested values sum up to a valid
3506 window layout, recursively assigns the new sizes of all child windows
3507 and calculates and assigns the new start positions of these windows.
3509 Note: This function does not check any of `window-fixed-size-p',
3510 `window-min-height' or `window-min-width'. All these checks have to
3511 be applied on the Elisp level. */)
3512 (Lisp_Object frame
, Lisp_Object horizontal
)
3516 int horflag
= !NILP (horizontal
);
3519 frame
= selected_frame
;
3520 CHECK_LIVE_FRAME (frame
);
3523 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3525 if (!window_resize_check (r
, horflag
)
3526 || ! EQ (r
->new_total
, (horflag
? r
->total_cols
: r
->total_lines
)))
3530 window_resize_apply (r
, horflag
);
3532 windows_or_buffers_changed
++;
3533 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3538 run_window_configuration_change_hook (f
);
3544 /* Resize frame F's windows when number of lines of F is set to SIZE.
3545 HORFLAG 1 means resize windows when number of columns of F is set to
3548 This function can delete all windows but the selected one in order to
3549 satisfy the request. The result will be meaningful if and only if
3550 F's windows have meaningful sizes when you call this. */
3552 resize_frame_windows (struct frame
*f
, int size
, int horflag
)
3554 Lisp_Object root
= f
->root_window
;
3555 struct window
*r
= XWINDOW (root
);
3556 Lisp_Object mini
= f
->minibuffer_window
;
3558 /* new_size is the new size of the frame's root window. */
3559 int new_size
= (horflag
3562 - FRAME_TOP_MARGIN (f
)
3563 - ((FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
3566 XSETFASTINT (r
->top_line
, FRAME_TOP_MARGIN (f
));
3567 if (NILP (r
->vchild
) && NILP (r
->hchild
))
3568 /* For a leaf root window just set the size. */
3570 XSETFASTINT (r
->total_cols
, new_size
);
3572 XSETFASTINT (r
->total_lines
, new_size
);
3575 /* old_size is the old size of the frame's root window. */
3576 int old_size
= XFASTINT (horflag
? r
->total_cols
: r
->total_lines
);
3579 XSETINT (delta
, new_size
- old_size
);
3580 /* Try a "normal" resize first. */
3581 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qnil
);
3582 if (window_resize_check (r
, horflag
) && new_size
== XINT (r
->new_total
))
3583 window_resize_apply (r
, horflag
);
3586 /* Try with "reasonable" minimum sizes next. */
3587 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qt
);
3588 if (window_resize_check (r
, horflag
)
3589 && new_size
== XINT (r
->new_total
))
3590 window_resize_apply (r
, horflag
);
3593 /* Finally, try with "safe" minimum sizes. */
3594 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qsafe
);
3595 if (window_resize_check (r
, horflag
)
3596 && new_size
== XINT (r
->new_total
))
3597 window_resize_apply (r
, horflag
);
3600 /* We lost. Delete all windows but the frame's
3602 root
= f
->selected_window
;
3603 Fdelete_other_windows_internal (root
, Qnil
);
3605 XSETFASTINT (XWINDOW (root
)->total_cols
, new_size
);
3607 XSETFASTINT (XWINDOW (root
)->total_lines
, new_size
);
3613 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
3617 XSETFASTINT (m
->total_cols
, size
);
3620 /* Are we sure we always want 1 line here? */
3621 XSETFASTINT (m
->total_lines
, 1);
3622 XSETFASTINT (m
->top_line
, XINT (r
->top_line
) + XINT (r
->total_lines
));
3628 DEFUN ("split-window-internal", Fsplit_window_internal
, Ssplit_window_internal
, 4, 4, 0,
3629 doc
: /* Split window OLD.
3630 Second argument TOTAL-SIZE specifies the number of lines or columns of the
3631 new window. In any case TOTAL-SIZE must be a positive integer.
3633 Third argument SIDE nil (or `below') specifies that the new window shall
3634 be located below WINDOW. SIDE `above' means the new window shall be
3635 located above WINDOW. In both cases TOTAL-SIZE specifies the number of
3636 lines of the new window including space reserved for the mode and/or
3639 SIDE t (or `right') specifies that the new window shall be located on
3640 the right side of WINDOW. SIDE `left' means the new window shall be
3641 located on the left of WINDOW. In both cases TOTAL-SIZE specifies the
3642 number of columns of the new window including space reserved for fringes
3643 and the scrollbar or a divider column.
3645 Fourth argument NORMAL-SIZE specifies the normal size of the new window
3646 according to the SIDE argument.
3648 The new total and normal sizes of all involved windows must have been
3649 set correctly. See the code of `split-window' for how this is done. */)
3650 (Lisp_Object old
, Lisp_Object total_size
, Lisp_Object side
, Lisp_Object normal_size
)
3652 /* OLD (*o) is the window we have to split. (*p) is either OLD's
3653 parent window or an internal window we have to install as OLD's new
3654 parent. REFERENCE (*r) must denote a live window, or is set to OLD
3655 provided OLD is a leaf window, or to the frame's selected window.
3656 NEW (*n) is the new window created with some parameters taken from
3658 register Lisp_Object
new, frame
, reference
;
3659 register struct window
*o
, *p
, *n
, *r
;
3662 /* HORFLAG is 1 when we split side-by-side, 0 otherwise. */
3663 = EQ (side
, Qt
) || EQ (side
, Qleft
) || EQ (side
, Qright
);
3664 int combination_limit
= 0;
3668 frame
= WINDOW_FRAME (o
);
3671 CHECK_NUMBER (total_size
);
3673 /* Set combination_limit to 1 if we have to make a new parent window.
3674 We do that if either `window-combination-limit' is t, or OLD has no
3675 parent, or OLD is ortho-combined. */
3677 !NILP (Vwindow_combination_limit
)
3680 ? (XWINDOW (o
->parent
)->hchild
)
3681 : (XWINDOW (o
->parent
)->vchild
));
3683 /* We need a live reference window to initialize some parameters. */
3684 if (WINDOW_LIVE_P (old
))
3685 /* OLD is live, use it as reference window. */
3688 /* Use the frame's selected window as reference window. */
3689 reference
= FRAME_SELECTED_WINDOW (f
);
3690 r
= XWINDOW (reference
);
3692 /* The following bugs are caught by `split-window'. */
3693 if (MINI_WINDOW_P (o
))
3694 error ("Attempt to split minibuffer window");
3695 else if (XINT (total_size
) < (horflag
? 2 : 1))
3696 error ("Size of new window too small (after split)");
3697 else if (!combination_limit
&& !NILP (Vwindow_combination_resize
))
3698 /* `window-combination-resize' non-nil means try to resize OLD's siblings
3701 p
= XWINDOW (o
->parent
);
3702 /* Temporarily pretend we split the parent window. */
3703 XSETINT (p
->new_total
,
3704 XINT (horflag
? p
->total_cols
: p
->total_lines
)
3705 - XINT (total_size
));
3706 if (!window_resize_check (p
, horflag
))
3707 error ("Window sizes don't fit");
3709 /* Undo the temporary pretension. */
3710 p
->new_total
= horflag
? p
->total_cols
: p
->total_lines
;
3714 if (!window_resize_check (o
, horflag
))
3715 error ("Resizing old window failed");
3716 else if (XINT (total_size
) + XINT (o
->new_total
)
3717 != XINT (horflag
? o
->total_cols
: o
->total_lines
))
3718 error ("Sum of sizes of old and new window don't fit");
3721 /* This is our point of no return. */
3722 if (combination_limit
)
3724 /* Save the old value of o->normal_cols/lines. It gets corrupted
3725 by make_parent_window and we need it below for assigning it to
3727 Lisp_Object new_normal
= horflag
? o
->normal_cols
: o
->normal_lines
;
3729 make_parent_window (old
, horflag
);
3730 p
= XWINDOW (o
->parent
);
3731 /* Store value of `window-combination-limit' in new parent's
3732 combination_limit slot. */
3733 p
->combination_limit
= Vwindow_combination_limit
;
3734 /* These get applied below. */
3735 p
->new_total
= horflag
? o
->total_cols
: o
->total_lines
;
3736 p
->new_normal
= new_normal
;
3739 p
= XWINDOW (o
->parent
);
3741 windows_or_buffers_changed
++;
3742 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3743 new = make_window ();
3746 n
->parent
= o
->parent
;
3747 n
->vchild
= n
->hchild
= Qnil
;
3749 if (EQ (side
, Qabove
) || EQ (side
, Qleft
))
3758 XWINDOW (n
->prev
)->next
= new;
3765 if (!NILP (n
->next
))
3766 XWINDOW (n
->next
)->prev
= new;
3772 n
->window_end_valid
= Qnil
;
3773 memset (&n
->last_cursor
, 0, sizeof n
->last_cursor
);
3775 /* Get special geometry settings from reference window. */
3776 n
->left_margin_cols
= r
->left_margin_cols
;
3777 n
->right_margin_cols
= r
->right_margin_cols
;
3778 n
->left_fringe_width
= r
->left_fringe_width
;
3779 n
->right_fringe_width
= r
->right_fringe_width
;
3780 n
->fringes_outside_margins
= r
->fringes_outside_margins
;
3781 n
->scroll_bar_width
= r
->scroll_bar_width
;
3782 n
->vertical_scroll_bar_type
= r
->vertical_scroll_bar_type
;
3784 /* Directly assign orthogonal coordinates and sizes. */
3787 n
->top_line
= o
->top_line
;
3788 n
->total_lines
= o
->total_lines
;
3792 n
->left_col
= o
->left_col
;
3793 n
->total_cols
= o
->total_cols
;
3796 /* Iso-coordinates and sizes are assigned by window_resize_apply,
3797 get them ready here. */
3798 n
->new_total
= total_size
;
3799 n
->new_normal
= normal_size
;
3802 window_resize_apply (p
, horflag
);
3804 /* Set buffer of NEW to buffer of reference window. Don't run
3806 set_window_buffer (new, r
->buffer
, 0, 1);
3809 /* Maybe we should run the scroll functions in Elisp (which already
3810 runs the configuration change hook). */
3811 if (! NILP (Vwindow_scroll_functions
))
3812 run_hook_with_args_2 (Qwindow_scroll_functions
, new,
3813 Fmarker_position (n
->start
));
3819 DEFUN ("delete-window-internal", Fdelete_window_internal
, Sdelete_window_internal
, 1, 1, 0,
3820 doc
: /* Remove WINDOW from its frame.
3821 WINDOW defaults to the selected window. Return nil.
3822 Signal an error when WINDOW is the only window on its frame. */)
3823 (register Lisp_Object window
)
3825 register Lisp_Object parent
, sibling
, frame
, root
;
3826 struct window
*w
, *p
, *s
, *r
;
3829 int before_sibling
= 0;
3831 w
= decode_any_window (window
);
3832 XSETWINDOW (window
, w
);
3833 if (NILP (w
->buffer
) && NILP (w
->hchild
) && NILP (w
->vchild
))
3834 /* It's a no-op to delete an already deleted window. */
3839 /* Never delete a minibuffer or frame root window. */
3840 error ("Attempt to delete minibuffer or sole ordinary window");
3841 else if (NILP (w
->prev
) && NILP (w
->next
))
3842 /* Rather bow out here, this case should be handled on the Elisp
3844 error ("Attempt to delete sole window of parent");
3846 p
= XWINDOW (parent
);
3847 horflag
= NILP (p
->vchild
);
3849 frame
= WINDOW_FRAME (w
);
3852 root
= FRAME_ROOT_WINDOW (f
);
3855 /* Unlink WINDOW from window tree. */
3857 /* Get SIBLING below (on the right of) WINDOW. */
3859 /* before_sibling 1 means WINDOW is the first child of its
3860 parent and thus before the sibling. */
3863 s
= XWINDOW (sibling
);
3866 p
->hchild
= sibling
;
3868 p
->vchild
= sibling
;
3871 /* Get SIBLING above (on the left of) WINDOW. */
3874 s
= XWINDOW (sibling
);
3876 if (!NILP (s
->next
))
3877 XWINDOW (s
->next
)->prev
= sibling
;
3880 if (window_resize_check (r
, horflag
)
3881 && EQ (r
->new_total
, (horflag
? r
->total_cols
: r
->total_lines
)))
3882 /* We can delete WINDOW now. */
3887 window_resize_apply (p
, horflag
);
3889 /* If this window is referred to by the dpyinfo's mouse
3890 highlight, invalidate that slot to be safe (Bug#9904). */
3891 if (!FRAME_INITIAL_P (f
))
3893 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
3895 if (EQ (hlinfo
->mouse_face_window
, window
))
3896 hlinfo
->mouse_face_window
= Qnil
;
3899 windows_or_buffers_changed
++;
3900 Vwindow_list
= Qnil
;
3901 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3903 w
->next
= Qnil
; /* Don't delete w->next too. */
3904 free_window_matrices (w
);
3906 if (!NILP (w
->vchild
))
3908 delete_all_child_windows (w
->vchild
);
3911 else if (!NILP (w
->hchild
))
3913 delete_all_child_windows (w
->hchild
);
3916 else if (!NILP (w
->buffer
))
3919 unchain_marker (XMARKER (w
->pointm
));
3920 unchain_marker (XMARKER (w
->start
));
3924 if (NILP (s
->prev
) && NILP (s
->next
))
3925 /* A matrjoshka where SIBLING has become the only child of
3928 /* Put SIBLING into PARENT's place. */
3929 replace_window (parent
, sibling
, 0);
3930 /* Have SIBLING inherit the following three slot values from
3931 PARENT (the combination_limit slot is not inherited). */
3932 s
->normal_cols
= p
->normal_cols
;
3933 s
->normal_lines
= p
->normal_lines
;
3934 /* Mark PARENT as deleted. */
3935 p
->vchild
= p
->hchild
= Qnil
;
3936 /* Try to merge SIBLING into its new parent. */
3937 recombine_windows (sibling
);
3942 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f
)))
3943 /* We deleted the frame's selected window. */
3945 /* Use the frame's first window as fallback ... */
3946 Lisp_Object new_selected_window
= Fframe_first_window (frame
);
3947 /* ... but preferably use its most recently used window. */
3948 Lisp_Object mru_window
;
3950 /* `get-mru-window' might fail for some reason so play it safe
3951 - promote the first window _without recording it_ first. */
3952 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
3953 Fselect_window (new_selected_window
, Qt
);
3955 FRAME_SELECTED_WINDOW (f
) = new_selected_window
;
3959 /* Now look whether `get-mru-window' gets us something. */
3960 mru_window
= call1 (Qget_mru_window
, frame
);
3961 if (WINDOW_LIVE_P (mru_window
)
3962 && EQ (XWINDOW (mru_window
)->frame
, frame
))
3963 new_selected_window
= mru_window
;
3965 /* If all ended up well, we now promote the mru window. */
3966 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
3967 Fselect_window (new_selected_window
, Qnil
);
3969 FRAME_SELECTED_WINDOW (f
) = new_selected_window
;
3974 /* Must be run by the caller:
3975 run_window_configuration_change_hook (f); */
3978 /* We failed: Relink WINDOW into window tree. */
3991 if (!NILP (w
->next
))
3992 XWINDOW (w
->next
)->prev
= window
;
3994 error ("Deletion failed");
4000 /***********************************************************************
4001 Resizing Mini-Windows
4002 ***********************************************************************/
4004 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we
4007 grow_mini_window (struct window
*w
, int delta
)
4009 struct frame
*f
= XFRAME (w
->frame
);
4011 Lisp_Object root
, value
;
4013 eassert (MINI_WINDOW_P (w
));
4014 eassert (delta
>= 0);
4016 root
= FRAME_ROOT_WINDOW (f
);
4018 value
= call2 (Qwindow_resize_root_window_vertically
,
4019 root
, make_number (- delta
));
4020 if (INTEGERP (value
) && window_resize_check (r
, 0))
4023 window_resize_apply (r
, 0);
4025 /* Grow the mini-window. */
4026 XSETFASTINT (w
->top_line
, XFASTINT (r
->top_line
) + XFASTINT (r
->total_lines
));
4027 XSETFASTINT (w
->total_lines
, XFASTINT (w
->total_lines
) - XINT (value
));
4028 XSETFASTINT (w
->last_modified
, 0);
4029 XSETFASTINT (w
->last_overlay_modified
, 0);
4037 /* Shrink mini-window W. */
4039 shrink_mini_window (struct window
*w
)
4041 struct frame
*f
= XFRAME (w
->frame
);
4043 Lisp_Object root
, value
;
4046 eassert (MINI_WINDOW_P (w
));
4048 size
= XINT (w
->total_lines
);
4051 root
= FRAME_ROOT_WINDOW (f
);
4053 value
= call2 (Qwindow_resize_root_window_vertically
,
4054 root
, make_number (size
- 1));
4055 if (INTEGERP (value
) && window_resize_check (r
, 0))
4058 window_resize_apply (r
, 0);
4060 /* Shrink the mini-window. */
4061 XSETFASTINT (w
->top_line
, XFASTINT (r
->top_line
) + XFASTINT (r
->total_lines
));
4062 XSETFASTINT (w
->total_lines
, 1);
4064 XSETFASTINT (w
->last_modified
, 0);
4065 XSETFASTINT (w
->last_overlay_modified
, 0);
4070 /* If the above failed for whatever strange reason we must make a
4071 one window frame here. The same routine will be needed when
4072 shrinking the frame (and probably when making the initial
4073 *scratch* window). For the moment leave things as they are. */
4077 DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal
, Sresize_mini_window_internal
, 1, 1, 0,
4078 doc
: /* Resize minibuffer window WINDOW. */)
4079 (Lisp_Object window
)
4081 struct window
*w
= XWINDOW (window
);
4086 CHECK_WINDOW (window
);
4087 f
= XFRAME (w
->frame
);
4089 if (!EQ (FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
)), window
))
4090 error ("Not a valid minibuffer window");
4091 else if (FRAME_MINIBUF_ONLY_P (f
))
4092 error ("Cannot resize a minibuffer-only frame");
4094 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4095 height
= XINT (r
->total_lines
) + XINT (w
->total_lines
);
4096 if (window_resize_check (r
, 0)
4097 && XINT (w
->new_total
) > 0
4098 && height
== XINT (r
->new_total
) + XINT (w
->new_total
))
4101 window_resize_apply (r
, 0);
4103 w
->total_lines
= w
->new_total
;
4104 XSETFASTINT (w
->top_line
, XINT (r
->top_line
) + XINT (r
->total_lines
));
4106 windows_or_buffers_changed
++;
4107 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4111 run_window_configuration_change_hook (f
);
4114 else error ("Failed to resize minibuffer window");
4117 /* Mark window cursors off for all windows in the window tree rooted
4118 at W by setting their phys_cursor_on_p flag to zero. Called from
4119 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4120 the frame are cleared. */
4123 mark_window_cursors_off (struct window
*w
)
4127 if (!NILP (w
->hchild
))
4128 mark_window_cursors_off (XWINDOW (w
->hchild
));
4129 else if (!NILP (w
->vchild
))
4130 mark_window_cursors_off (XWINDOW (w
->vchild
));
4132 w
->phys_cursor_on_p
= 0;
4134 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4139 /* Return number of lines of text (not counting mode lines) in W. */
4142 window_internal_height (struct window
*w
)
4144 int ht
= XFASTINT (w
->total_lines
);
4146 if (!MINI_WINDOW_P (w
))
4148 if (!NILP (w
->parent
)
4149 || !NILP (w
->vchild
)
4150 || !NILP (w
->hchild
)
4153 || WINDOW_WANTS_MODELINE_P (w
))
4156 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4163 /************************************************************************
4165 ***********************************************************************/
4167 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4168 N screen-fulls, which is defined as the height of the window minus
4169 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4170 instead. Negative values of N mean scroll down. NOERROR non-zero
4171 means don't signal an error if we try to move over BEGV or ZV,
4175 window_scroll (Lisp_Object window
, EMACS_INT n
, int whole
, int noerror
)
4178 n
= clip_to_bounds (INT_MIN
, n
, INT_MAX
);
4180 /* If we must, use the pixel-based version which is much slower than
4181 the line-based one but can handle varying line heights. */
4182 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4183 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4185 window_scroll_line_based (window
, n
, whole
, noerror
);
4191 /* Implementation of window_scroll that works based on pixel line
4192 heights. See the comment of window_scroll for parameter
4196 window_scroll_pixel_based (Lisp_Object window
, int n
, int whole
, int noerror
)
4199 struct window
*w
= XWINDOW (window
);
4200 struct text_pos start
;
4201 int this_scroll_margin
;
4202 /* True if we fiddled the window vscroll field without really scrolling. */
4204 int x
, y
, rtop
, rbot
, rowh
, vpos
;
4205 void *itdata
= NULL
;
4207 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4208 /* Scrolling a minibuffer window via scroll bar when the echo area
4209 shows long text sometimes resets the minibuffer contents behind
4211 if (CHARPOS (start
) > ZV
)
4212 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4214 /* If PT is not visible in WINDOW, move back one half of
4215 the screen. Allow PT to be partially visible, otherwise
4216 something like (scroll-down 1) with PT in the line before
4217 the partially visible one would recenter. */
4219 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
4221 itdata
= bidi_shelve_cache ();
4222 /* Move backward half the height of the window. Performance note:
4223 vmotion used here is about 10% faster, but would give wrong
4224 results for variable height lines. */
4225 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4226 it
.current_y
= it
.last_visible_y
;
4227 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4229 /* The function move_iterator_vertically may move over more than
4230 the specified y-distance. If it->w is small, e.g. a
4231 mini-buffer window, we may end up in front of the window's
4232 display area. This is the case when Start displaying at the
4233 start of the line containing PT in this case. */
4234 if (it
.current_y
<= 0)
4236 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4237 move_it_vertically_backward (&it
, 0);
4241 start
= it
.current
.pos
;
4242 bidi_unshelve_cache (itdata
, 0);
4244 else if (auto_window_vscroll_p
)
4246 if (rtop
|| rbot
) /* partially visible */
4249 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4251 dy
= max ((window_box_height (w
)
4252 - next_screen_context_lines
* dy
),
4258 /* Only vscroll backwards if already vscrolled forwards. */
4259 if (w
->vscroll
< 0 && rtop
> 0)
4261 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
4262 Fset_window_vscroll (window
, make_number (px
), Qt
);
4268 /* Do vscroll if already vscrolled or only display line. */
4269 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
4271 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
4272 Fset_window_vscroll (window
, make_number (px
), Qt
);
4276 /* Maybe modify window start instead of scrolling. */
4277 if (rbot
> 0 || w
->vscroll
< 0)
4281 Fset_window_vscroll (window
, make_number (0), Qt
);
4282 /* If there are other text lines above the current row,
4283 move window start to current row. Else to next row. */
4285 spos
= XINT (Fline_beginning_position (Qnil
));
4287 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
4288 set_marker_restricted (w
->start
, make_number (spos
),
4290 w
->start_at_line_beg
= 1;
4291 w
->update_mode_line
= 1;
4292 XSETFASTINT (w
->last_modified
, 0);
4293 XSETFASTINT (w
->last_overlay_modified
, 0);
4294 /* Set force_start so that redisplay_window will run the
4295 window-scroll-functions. */
4301 /* Cancel previous vscroll. */
4302 Fset_window_vscroll (window
, make_number (0), Qt
);
4305 itdata
= bidi_shelve_cache ();
4306 /* If scroll_preserve_screen_position is non-nil, we try to set
4307 point in the same window line as it is now, so get that line. */
4308 if (!NILP (Vscroll_preserve_screen_position
))
4310 /* We preserve the goal pixel coordinate across consecutive
4311 calls to scroll-up, scroll-down and other commands that
4312 have the `scroll-command' property. This avoids the
4313 possibility of point becoming "stuck" on a tall line when
4314 scrolling by one line. */
4315 if (window_scroll_pixel_based_preserve_y
< 0
4316 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
4317 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
4319 start_display (&it
, w
, start
);
4320 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4321 window_scroll_pixel_based_preserve_y
= it
.current_y
;
4322 window_scroll_pixel_based_preserve_x
= it
.current_x
;
4326 window_scroll_pixel_based_preserve_y
4327 = window_scroll_pixel_based_preserve_x
= -1;
4329 /* Move iterator it from start the specified distance forward or
4330 backward. The result is the new window start. */
4331 start_display (&it
, w
, start
);
4334 ptrdiff_t start_pos
= IT_CHARPOS (it
);
4335 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4336 dy
= max ((window_box_height (w
)
4337 - next_screen_context_lines
* dy
),
4340 /* Note that move_it_vertically always moves the iterator to the
4341 start of a line. So, if the last line doesn't have a newline,
4342 we would end up at the start of the line ending at ZV. */
4345 move_it_vertically_backward (&it
, -dy
);
4346 /* Ensure we actually do move, e.g. in case we are currently
4347 looking at an image that is taller that the window height. */
4348 while (start_pos
== IT_CHARPOS (it
)
4349 && start_pos
> BEGV
)
4350 move_it_by_lines (&it
, -1);
4354 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4355 MOVE_TO_POS
| MOVE_TO_Y
);
4356 /* Ensure we actually do move, e.g. in case we are currently
4357 looking at an image that is taller that the window height. */
4358 while (start_pos
== IT_CHARPOS (it
)
4360 move_it_by_lines (&it
, 1);
4364 move_it_by_lines (&it
, n
);
4366 /* We failed if we find ZV is already on the screen (scrolling up,
4367 means there's nothing past the end), or if we can't start any
4368 earlier (scrolling down, means there's nothing past the top). */
4369 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4370 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4372 if (IT_CHARPOS (it
) == ZV
)
4374 if (it
.current_y
< it
.last_visible_y
4375 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4376 > it
.last_visible_y
))
4378 /* The last line was only partially visible, make it fully
4380 w
->vscroll
= (it
.last_visible_y
4381 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4382 adjust_glyphs (it
.f
);
4386 bidi_unshelve_cache (itdata
, 0);
4389 else if (n
< 0) /* could happen with empty buffers */
4390 xsignal0 (Qbeginning_of_buffer
);
4392 xsignal0 (Qend_of_buffer
);
4397 if (w
->vscroll
!= 0)
4398 /* The first line was only partially visible, make it fully
4403 bidi_unshelve_cache (itdata
, 0);
4407 xsignal0 (Qbeginning_of_buffer
);
4411 /* If control gets here, then we vscrolled. */
4413 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
4415 /* Don't try to change the window start below. */
4421 ptrdiff_t pos
= IT_CHARPOS (it
);
4424 /* If in the middle of a multi-glyph character move forward to
4425 the next character. */
4426 if (in_display_vector_p (&it
))
4429 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
4432 /* Set the window start, and set up the window for redisplay. */
4433 set_marker_restricted (w
->start
, make_number (pos
),
4435 bytepos
= XMARKER (w
->start
)->bytepos
;
4436 w
->start_at_line_beg
= (pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n');
4437 w
->update_mode_line
= 1;
4438 XSETFASTINT (w
->last_modified
, 0);
4439 XSETFASTINT (w
->last_overlay_modified
, 0);
4440 /* Set force_start so that redisplay_window will run the
4441 window-scroll-functions. */
4445 /* The rest of this function uses current_y in a nonstandard way,
4446 not including the height of the header line if any. */
4447 it
.current_y
= it
.vpos
= 0;
4449 /* Move PT out of scroll margins.
4450 This code wants current_y to be zero at the window start position
4451 even if there is a header line. */
4452 this_scroll_margin
= max (0, scroll_margin
);
4453 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->total_lines
) / 4);
4454 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
4458 /* We moved the window start towards ZV, so PT may be now
4459 in the scroll margin at the top. */
4460 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4461 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
4462 && (NILP (Vscroll_preserve_screen_position
)
4463 || EQ (Vscroll_preserve_screen_position
, Qt
)))
4464 /* We found PT at a legitimate height. Leave it alone. */
4466 else if (window_scroll_pixel_based_preserve_y
>= 0)
4468 /* If we have a header line, take account of it.
4469 This is necessary because we set it.current_y to 0, above. */
4470 move_it_to (&it
, -1,
4471 window_scroll_pixel_based_preserve_x
,
4472 window_scroll_pixel_based_preserve_y
4473 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
4474 -1, MOVE_TO_Y
| MOVE_TO_X
);
4475 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4479 while (it
.current_y
< this_scroll_margin
)
4481 int prev
= it
.current_y
;
4482 move_it_by_lines (&it
, 1);
4483 if (prev
== it
.current_y
)
4486 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4491 ptrdiff_t charpos
, bytepos
;
4494 /* Save our position, for the
4495 window_scroll_pixel_based_preserve_y case. */
4496 charpos
= IT_CHARPOS (it
);
4497 bytepos
= IT_BYTEPOS (it
);
4499 /* We moved the window start towards BEGV, so PT may be now
4500 in the scroll margin at the bottom. */
4501 move_it_to (&it
, PT
, -1,
4502 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
4503 - this_scroll_margin
- 1),
4505 MOVE_TO_POS
| MOVE_TO_Y
);
4507 /* Save our position, in case it's correct. */
4508 charpos
= IT_CHARPOS (it
);
4509 bytepos
= IT_BYTEPOS (it
);
4511 /* See if point is on a partially visible line at the end. */
4512 if (it
.what
== IT_EOB
)
4513 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
4516 move_it_by_lines (&it
, 1);
4517 partial_p
= it
.current_y
> it
.last_visible_y
;
4520 if (charpos
== PT
&& !partial_p
4521 && (NILP (Vscroll_preserve_screen_position
)
4522 || EQ (Vscroll_preserve_screen_position
, Qt
)))
4523 /* We found PT before we found the display margin, so PT is ok. */
4525 else if (window_scroll_pixel_based_preserve_y
>= 0)
4527 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4528 start_display (&it
, w
, start
);
4529 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
4530 here because we called start_display again and did not
4531 alter it.current_y this time. */
4532 move_it_to (&it
, -1, window_scroll_pixel_based_preserve_x
,
4533 window_scroll_pixel_based_preserve_y
, -1,
4534 MOVE_TO_Y
| MOVE_TO_X
);
4535 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4540 /* The last line was only partially visible, so back up two
4541 lines to make sure we're on a fully visible line. */
4543 move_it_by_lines (&it
, -2);
4544 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4547 /* No, the position we saved is OK, so use it. */
4548 SET_PT_BOTH (charpos
, bytepos
);
4551 bidi_unshelve_cache (itdata
, 0);
4555 /* Implementation of window_scroll that works based on screen lines.
4556 See the comment of window_scroll for parameter descriptions. */
4559 window_scroll_line_based (Lisp_Object window
, int n
, int whole
, int noerror
)
4561 register struct window
*w
= XWINDOW (window
);
4562 /* Fvertical_motion enters redisplay, which can trigger
4563 fontification, which in turn can modify buffer text (e.g., if the
4564 fontification functions replace escape sequences with faces, as
4565 in `grep-mode-font-lock-keywords'). So we use a marker to record
4566 the old point position, to prevent crashes in SET_PT_BOTH. */
4567 Lisp_Object opoint_marker
= Fpoint_marker ();
4568 register ptrdiff_t pos
, pos_byte
;
4569 register int ht
= window_internal_height (w
);
4570 register Lisp_Object tem
;
4574 Lisp_Object original_pos
= Qnil
;
4576 /* If scrolling screen-fulls, compute the number of lines to
4577 scroll from the window's height. */
4579 n
*= max (1, ht
- next_screen_context_lines
);
4581 startpos
= marker_position (w
->start
);
4583 if (!NILP (Vscroll_preserve_screen_position
))
4585 if (window_scroll_preserve_vpos
<= 0
4586 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
4587 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
4589 struct position posit
4590 = *compute_motion (startpos
, 0, 0, 0,
4592 -1, XINT (w
->hscroll
),
4594 window_scroll_preserve_vpos
= posit
.vpos
;
4595 window_scroll_preserve_hpos
= posit
.hpos
+ XINT (w
->hscroll
);
4598 original_pos
= Fcons (make_number (window_scroll_preserve_hpos
),
4599 make_number (window_scroll_preserve_vpos
));
4602 XSETFASTINT (tem
, PT
);
4603 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
4607 Fvertical_motion (make_number (- (ht
/ 2)), window
);
4612 lose
= n
< 0 && PT
== BEGV
;
4613 Fvertical_motion (make_number (n
), window
);
4617 SET_PT_BOTH (marker_position (opoint_marker
),
4618 marker_byte_position (opoint_marker
));
4625 xsignal0 (Qbeginning_of_buffer
);
4630 /* Don't use a scroll margin that is negative or too large. */
4631 int this_scroll_margin
=
4632 max (0, min (scroll_margin
, XINT (w
->total_lines
) / 4));
4634 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
4635 w
->start_at_line_beg
= !NILP (bolp
);
4636 w
->update_mode_line
= 1;
4637 XSETFASTINT (w
->last_modified
, 0);
4638 XSETFASTINT (w
->last_overlay_modified
, 0);
4639 /* Set force_start so that redisplay_window will run
4640 the window-scroll-functions. */
4643 if (!NILP (Vscroll_preserve_screen_position
)
4644 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
4646 SET_PT_BOTH (pos
, pos_byte
);
4647 Fvertical_motion (original_pos
, window
);
4649 /* If we scrolled forward, put point enough lines down
4650 that it is outside the scroll margin. */
4655 if (this_scroll_margin
> 0)
4657 SET_PT_BOTH (pos
, pos_byte
);
4658 Fvertical_motion (make_number (this_scroll_margin
), window
);
4664 if (top_margin
<= marker_position (opoint_marker
))
4665 SET_PT_BOTH (marker_position (opoint_marker
),
4666 marker_byte_position (opoint_marker
));
4667 else if (!NILP (Vscroll_preserve_screen_position
))
4669 SET_PT_BOTH (pos
, pos_byte
);
4670 Fvertical_motion (original_pos
, window
);
4673 SET_PT (top_margin
);
4679 /* If we scrolled backward, put point near the end of the window
4680 but not within the scroll margin. */
4681 SET_PT_BOTH (pos
, pos_byte
);
4682 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
4683 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
4686 bottom_margin
= PT
+ 1;
4688 if (bottom_margin
> marker_position (opoint_marker
))
4689 SET_PT_BOTH (marker_position (opoint_marker
),
4690 marker_byte_position (opoint_marker
));
4693 if (!NILP (Vscroll_preserve_screen_position
))
4695 SET_PT_BOTH (pos
, pos_byte
);
4696 Fvertical_motion (original_pos
, window
);
4699 Fvertical_motion (make_number (-1), window
);
4708 xsignal0 (Qend_of_buffer
);
4713 /* Scroll selected_window up or down. If N is nil, scroll a
4714 screen-full which is defined as the height of the window minus
4715 next_screen_context_lines. If N is the symbol `-', scroll.
4716 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4717 up. This is the guts of Fscroll_up and Fscroll_down. */
4720 scroll_command (Lisp_Object n
, int direction
)
4722 ptrdiff_t count
= SPECPDL_INDEX ();
4724 eassert (eabs (direction
) == 1);
4726 /* If selected window's buffer isn't current, make it current for
4727 the moment. But don't screw up if window_scroll gets an error. */
4728 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
4730 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4731 Fset_buffer (XWINDOW (selected_window
)->buffer
);
4733 /* Make redisplay consider other windows than just selected_window. */
4734 ++windows_or_buffers_changed
;
4738 window_scroll (selected_window
, direction
, 1, 0);
4739 else if (EQ (n
, Qminus
))
4740 window_scroll (selected_window
, -direction
, 1, 0);
4743 n
= Fprefix_numeric_value (n
);
4744 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
4747 unbind_to (count
, Qnil
);
4750 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "^P",
4751 doc
: /* Scroll text of selected window upward ARG lines.
4752 If ARG is omitted or nil, scroll upward by a near full screen.
4753 A near full screen is `next-screen-context-lines' less than a full screen.
4754 Negative ARG means scroll downward.
4755 If ARG is the atom `-', scroll downward by nearly full screen.
4756 When calling from a program, supply as argument a number, nil, or `-'. */)
4759 scroll_command (arg
, 1);
4763 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "^P",
4764 doc
: /* Scroll text of selected window down ARG lines.
4765 If ARG is omitted or nil, scroll down by a near full screen.
4766 A near full screen is `next-screen-context-lines' less than a full screen.
4767 Negative ARG means scroll upward.
4768 If ARG is the atom `-', scroll upward by nearly full screen.
4769 When calling from a program, supply as argument a number, nil, or `-'. */)
4772 scroll_command (arg
, -1);
4776 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
4777 doc
: /* Return the other window for \"other window scroll\" commands.
4778 If `other-window-scroll-buffer' is non-nil, a window
4779 showing that buffer is used.
4780 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4781 specifies the window. This takes precedence over
4782 `other-window-scroll-buffer'. */)
4787 if (MINI_WINDOW_P (XWINDOW (selected_window
))
4788 && !NILP (Vminibuf_scroll_window
))
4789 window
= Vminibuf_scroll_window
;
4790 /* If buffer is specified, scroll that buffer. */
4791 else if (!NILP (Vother_window_scroll_buffer
))
4793 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
4795 window
= display_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
4799 /* Nothing specified; look for a neighboring window on the same
4801 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
4803 if (EQ (window
, selected_window
))
4804 /* That didn't get us anywhere; look for a window on another
4807 window
= Fnext_window (window
, Qnil
, Qt
);
4808 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
4809 && ! EQ (window
, selected_window
));
4812 CHECK_LIVE_WINDOW (window
);
4814 if (EQ (window
, selected_window
))
4815 error ("There is no other window");
4820 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
4821 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
4822 A near full screen is `next-screen-context-lines' less than a full screen.
4823 The next window is the one below the current one; or the one at the top
4824 if the current one is at the bottom. Negative ARG means scroll downward.
4825 If ARG is the atom `-', scroll downward by nearly full screen.
4826 When calling from a program, supply as argument a number, nil, or `-'.
4828 If `other-window-scroll-buffer' is non-nil, scroll the window
4829 showing that buffer, popping the buffer up if necessary.
4830 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4831 specifies the window to scroll. This takes precedence over
4832 `other-window-scroll-buffer'. */)
4837 ptrdiff_t count
= SPECPDL_INDEX ();
4839 window
= Fother_window_for_scrolling ();
4840 w
= XWINDOW (window
);
4842 /* Don't screw up if window_scroll gets an error. */
4843 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4844 ++windows_or_buffers_changed
;
4846 Fset_buffer (w
->buffer
);
4847 SET_PT (marker_position (w
->pointm
));
4850 window_scroll (window
, 1, 1, 1);
4851 else if (EQ (arg
, Qminus
))
4852 window_scroll (window
, -1, 1, 1);
4858 window_scroll (window
, XINT (arg
), 0, 1);
4861 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
4862 unbind_to (count
, Qnil
);
4867 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "^P\np",
4868 doc
: /* Scroll selected window display ARG columns left.
4869 Default for ARG is window width minus 2.
4870 Value is the total amount of leftward horizontal scrolling in
4871 effect after the change.
4872 If SET-MINIMUM is non-nil, the new scroll amount becomes the
4873 lower bound for automatic scrolling, i.e. automatic scrolling
4874 will not scroll a window to a column less than the value returned
4875 by this function. This happens in an interactive call. */)
4876 (register Lisp_Object arg
, Lisp_Object set_minimum
)
4880 struct window
*w
= XWINDOW (selected_window
);
4883 XSETFASTINT (arg
, window_body_cols (w
) - 2);
4885 arg
= Fprefix_numeric_value (arg
);
4887 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
4888 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
4890 if (!NILP (set_minimum
))
4891 w
->min_hscroll
= w
->hscroll
;
4896 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "^P\np",
4897 doc
: /* Scroll selected window display ARG columns right.
4898 Default for ARG is window width minus 2.
4899 Value is the total amount of leftward horizontal scrolling in
4900 effect after the change.
4901 If SET-MINIMUM is non-nil, the new scroll amount becomes the
4902 lower bound for automatic scrolling, i.e. automatic scrolling
4903 will not scroll a window to a column less than the value returned
4904 by this function. This happens in an interactive call. */)
4905 (register Lisp_Object arg
, Lisp_Object set_minimum
)
4909 struct window
*w
= XWINDOW (selected_window
);
4912 XSETFASTINT (arg
, window_body_cols (w
) - 2);
4914 arg
= Fprefix_numeric_value (arg
);
4916 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
4917 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
4919 if (!NILP (set_minimum
))
4920 w
->min_hscroll
= w
->hscroll
;
4925 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
4926 doc
: /* Return the window which was selected when entering the minibuffer.
4927 Returns nil, if selected window is not a minibuffer window. */)
4930 if (minibuf_level
> 0
4931 && MINI_WINDOW_P (XWINDOW (selected_window
))
4932 && WINDOW_LIVE_P (minibuf_selected_window
))
4933 return minibuf_selected_window
;
4938 /* Value is the number of lines actually displayed in window W,
4939 as opposed to its height. */
4942 displayed_window_lines (struct window
*w
)
4945 struct text_pos start
;
4946 int height
= window_box_height (w
);
4947 struct buffer
*old_buffer
;
4949 void *itdata
= NULL
;
4951 if (XBUFFER (w
->buffer
) != current_buffer
)
4953 old_buffer
= current_buffer
;
4954 set_buffer_internal (XBUFFER (w
->buffer
));
4959 /* In case W->start is out of the accessible range, do something
4960 reasonable. This happens in Info mode when Info-scroll-down
4961 calls (recenter -1) while W->start is 1. */
4962 if (XMARKER (w
->start
)->charpos
< BEGV
)
4963 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4964 else if (XMARKER (w
->start
)->charpos
> ZV
)
4965 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
4967 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4969 itdata
= bidi_shelve_cache ();
4970 start_display (&it
, w
, start
);
4971 move_it_vertically (&it
, height
);
4972 bottom_y
= line_bottom_y (&it
);
4973 bidi_unshelve_cache (itdata
, 0);
4975 /* rms: On a non-window display,
4976 the value of it.vpos at the bottom of the screen
4977 seems to be 1 larger than window_box_height (w).
4978 This kludge fixes a bug whereby (move-to-window-line -1)
4979 when ZV is on the last screen line
4980 moves to the previous screen line instead of the last one. */
4981 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
4984 /* Add in empty lines at the bottom of the window. */
4985 if (bottom_y
< height
)
4987 int uy
= FRAME_LINE_HEIGHT (it
.f
);
4988 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
4992 set_buffer_internal (old_buffer
);
4998 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
4999 doc
: /* Center point in selected window and maybe redisplay frame.
5000 With prefix argument ARG, recenter putting point on screen line ARG
5001 relative to the selected window. If ARG is negative, it counts up from the
5002 bottom of the window. (ARG should be less than the height of the window.)
5004 If ARG is omitted or nil, then recenter with point on the middle line of
5005 the selected window; if the variable `recenter-redisplay' is non-nil,
5006 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5007 is set to `grow-only', this resets the tool-bar's height to the minimum
5008 height needed); if `recenter-redisplay' has the special value `tty',
5009 then only tty frames are redrawn.
5011 Just C-u as prefix means put point in the center of the window
5012 and redisplay normally--don't erase and redraw the frame. */)
5013 (register Lisp_Object arg
)
5015 struct window
*w
= XWINDOW (selected_window
);
5016 struct buffer
*buf
= XBUFFER (w
->buffer
);
5017 struct buffer
*obuf
= current_buffer
;
5019 ptrdiff_t charpos
, bytepos
;
5020 EMACS_INT iarg
IF_LINT (= 0);
5021 int this_scroll_margin
;
5023 /* If redisplay is suppressed due to an error, try again. */
5024 obuf
->display_error_modiff
= 0;
5028 if (!NILP (Vrecenter_redisplay
)
5029 && (!EQ (Vrecenter_redisplay
, Qtty
)
5030 || !NILP (Ftty_type (selected_frame
))))
5034 /* Invalidate pixel data calculated for all compositions. */
5035 for (i
= 0; i
< n_compositions
; i
++)
5036 composition_table
[i
]->font
= NULL
;
5038 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5040 Fredraw_frame (WINDOW_FRAME (w
));
5041 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5046 else if (CONSP (arg
)) /* Just C-u. */
5050 arg
= Fprefix_numeric_value (arg
);
5055 set_buffer_internal (buf
);
5057 /* Do this after making BUF current
5058 in case scroll_margin is buffer-local. */
5059 this_scroll_margin
=
5060 max (0, min (scroll_margin
, XFASTINT (w
->total_lines
) / 4));
5062 /* Handle centering on a graphical frame specially. Such frames can
5063 have variable-height lines and centering point on the basis of
5064 line counts would lead to strange effects. */
5065 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5071 void *itdata
= bidi_shelve_cache ();
5073 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5074 start_display (&it
, w
, pt
);
5075 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5076 charpos
= IT_CHARPOS (it
);
5077 bytepos
= IT_BYTEPOS (it
);
5078 bidi_unshelve_cache (itdata
, 0);
5084 ptrdiff_t nlines
= min (PTRDIFF_MAX
, -iarg
);
5085 int extra_line_spacing
;
5086 int h
= window_box_height (w
);
5087 void *itdata
= bidi_shelve_cache ();
5089 iarg
= - max (-iarg
, this_scroll_margin
);
5091 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5092 start_display (&it
, w
, pt
);
5094 /* Be sure we have the exact height of the full line containing PT. */
5095 move_it_by_lines (&it
, 0);
5097 /* The amount of pixels we have to move back is the window
5098 height minus what's displayed in the line containing PT,
5099 and the lines below. */
5102 move_it_by_lines (&it
, nlines
);
5104 if (it
.vpos
== nlines
)
5108 /* Last line has no newline */
5109 h
-= line_bottom_y (&it
);
5113 /* Don't reserve space for extra line spacing of last line. */
5114 extra_line_spacing
= it
.max_extra_line_spacing
;
5116 /* If we can't move down NLINES lines because we hit
5117 the end of the buffer, count in some empty lines. */
5118 if (it
.vpos
< nlines
)
5121 extra_line_spacing
= it
.extra_line_spacing
;
5122 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5126 bidi_unshelve_cache (itdata
, 0);
5130 /* Now find the new top line (starting position) of the window. */
5131 start_display (&it
, w
, pt
);
5133 move_it_vertically_backward (&it
, h
);
5135 /* If extra line spacing is present, we may move too far
5136 back. This causes the last line to be only partially
5137 visible (which triggers redisplay to recenter that line
5138 in the middle), so move forward.
5139 But ignore extra line spacing on last line, as it is not
5140 considered to be part of the visible height of the line.
5142 h
+= extra_line_spacing
;
5143 while (-it
.current_y
> h
)
5144 move_it_by_lines (&it
, 1);
5146 charpos
= IT_CHARPOS (it
);
5147 bytepos
= IT_BYTEPOS (it
);
5149 bidi_unshelve_cache (itdata
, 0);
5153 struct position pos
;
5155 iarg
= max (iarg
, this_scroll_margin
);
5157 pos
= *vmotion (PT
, -iarg
, w
);
5158 charpos
= pos
.bufpos
;
5159 bytepos
= pos
.bytepos
;
5164 struct position pos
;
5165 int ht
= window_internal_height (w
);
5172 /* Don't let it get into the margin at either top or bottom. */
5173 iarg
= max (iarg
, this_scroll_margin
);
5174 iarg
= min (iarg
, ht
- this_scroll_margin
- 1);
5176 pos
= *vmotion (PT
, - iarg
, w
);
5177 charpos
= pos
.bufpos
;
5178 bytepos
= pos
.bytepos
;
5181 /* Set the new window start. */
5182 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
5183 w
->window_end_valid
= Qnil
;
5185 w
->optional_new_start
= 1;
5187 w
->start_at_line_beg
= (bytepos
== BEGV_BYTE
||
5188 FETCH_BYTE (bytepos
- 1) == '\n');
5190 set_buffer_internal (obuf
);
5194 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5196 doc
: /* Return the height in lines of the text display area of WINDOW.
5197 If WINDOW is omitted or nil, it defaults to the selected window.
5199 The returned height does not include the mode line, any header line,
5200 nor any partial-height lines at the bottom of the text area. */)
5201 (Lisp_Object window
)
5203 struct window
*w
= decode_window (window
);
5204 int pixel_height
= window_box_height (w
);
5205 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5206 return make_number (line_height
);
5211 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5213 doc
: /* Position point relative to window.
5214 ARG nil means position point at center of window.
5215 Else, ARG specifies vertical position within the window;
5216 zero means top of window, negative means relative to bottom of window. */)
5219 struct window
*w
= XWINDOW (selected_window
);
5223 int this_scroll_margin
;
5226 if (!(BUFFERP (w
->buffer
)
5227 && XBUFFER (w
->buffer
) == current_buffer
))
5228 /* This test is needed to make sure PT/PT_BYTE make sense in w->buffer
5229 when passed below to set_marker_both. */
5230 error ("move-to-window-line called from unrelated buffer");
5232 window
= selected_window
;
5233 start
= marker_position (w
->start
);
5234 if (start
< BEGV
|| start
> ZV
)
5236 int height
= window_internal_height (w
);
5237 Fvertical_motion (make_number (- (height
/ 2)), window
);
5238 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
5239 w
->start_at_line_beg
= !NILP (Fbolp ());
5243 Fgoto_char (w
->start
);
5245 lines
= displayed_window_lines (w
);
5248 this_scroll_margin
= max (0, min (scroll_margin
, lines
/ 4));
5252 XSETFASTINT (arg
, lines
/ 2);
5255 EMACS_INT iarg
= XINT (Fprefix_numeric_value (arg
));
5258 iarg
= iarg
+ lines
;
5260 #if 0 /* This code would prevent move-to-window-line from moving point
5261 to a place inside the scroll margins (which would cause the
5262 next redisplay to scroll). I wrote this code, but then concluded
5263 it is probably better not to install it. However, it is here
5264 inside #if 0 so as not to lose it. -- rms. */
5266 /* Don't let it get into the margin at either top or bottom. */
5267 iarg
= max (iarg
, this_scroll_margin
);
5268 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
5271 arg
= make_number (iarg
);
5274 /* Skip past a partially visible first line. */
5276 XSETINT (arg
, XINT (arg
) + 1);
5278 return Fvertical_motion (arg
, window
);
5283 /***********************************************************************
5284 Window Configuration
5285 ***********************************************************************/
5287 struct save_window_data
5289 struct vectorlike_header header
;
5290 Lisp_Object selected_frame
;
5291 Lisp_Object current_window
;
5292 Lisp_Object current_buffer
;
5293 Lisp_Object minibuf_scroll_window
;
5294 Lisp_Object minibuf_selected_window
;
5295 Lisp_Object root_window
;
5296 Lisp_Object focus_frame
;
5297 /* A vector, each of whose elements is a struct saved_window
5299 Lisp_Object saved_windows
;
5301 /* All fields above are traced by the GC.
5302 From `fame-cols' down, the fields are ignored by the GC. */
5304 int frame_cols
, frame_lines
, frame_menu_bar_lines
;
5305 int frame_tool_bar_lines
;
5308 /* This is saved as a Lisp_Vector */
5311 struct vectorlike_header header
;
5313 Lisp_Object window
, buffer
, start
, pointm
, mark
;
5314 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5315 Lisp_Object normal_cols
, normal_lines
;
5316 Lisp_Object hscroll
, min_hscroll
;
5317 Lisp_Object parent
, prev
;
5318 Lisp_Object start_at_line_beg
;
5319 Lisp_Object display_table
;
5320 Lisp_Object left_margin_cols
, right_margin_cols
;
5321 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
5322 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
, dedicated
;
5323 Lisp_Object combination_limit
, window_parameters
;
5326 #define SAVED_WINDOW_N(swv,n) \
5327 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5329 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
5330 doc
: /* Return t if OBJECT is a window-configuration object. */)
5331 (Lisp_Object object
)
5333 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
5336 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
5337 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5338 (Lisp_Object config
)
5340 register struct save_window_data
*data
;
5341 struct Lisp_Vector
*saved_windows
;
5343 CHECK_WINDOW_CONFIGURATION (config
);
5345 data
= (struct save_window_data
*) XVECTOR (config
);
5346 saved_windows
= XVECTOR (data
->saved_windows
);
5347 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5350 DEFUN ("set-window-configuration", Fset_window_configuration
,
5351 Sset_window_configuration
, 1, 1, 0,
5352 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5353 CONFIGURATION must be a value previously returned
5354 by `current-window-configuration' (which see).
5355 If CONFIGURATION was made from a frame that is now deleted,
5356 only frame-independent values can be restored. In this case,
5357 the return value is nil. Otherwise the value is t. */)
5358 (Lisp_Object configuration
)
5360 register struct save_window_data
*data
;
5361 struct Lisp_Vector
*saved_windows
;
5362 Lisp_Object new_current_buffer
;
5364 Lisp_Object auto_buffer_name
;
5366 ptrdiff_t old_point
= -1;
5368 CHECK_WINDOW_CONFIGURATION (configuration
);
5370 data
= (struct save_window_data
*) XVECTOR (configuration
);
5371 saved_windows
= XVECTOR (data
->saved_windows
);
5373 new_current_buffer
= data
->current_buffer
;
5374 if (NILP (BVAR (XBUFFER (new_current_buffer
), name
)))
5375 new_current_buffer
= Qnil
;
5378 if (XBUFFER (new_current_buffer
) == current_buffer
)
5379 /* The code further down "preserves point" by saving here PT in
5380 old_point and then setting it later back into PT. When the
5381 current-selected-window and the final-selected-window both show
5382 the current buffer, this suffers from the problem that the
5383 current PT is the window-point of the current-selected-window,
5384 while the final PT is the point of the final-selected-window, so
5385 this copy from one PT to the other would end up moving the
5386 window-point of the final-selected-window to the window-point of
5387 the current-selected-window. So we have to be careful which
5388 point of the current-buffer we copy into old_point. */
5389 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
5390 && WINDOWP (selected_window
)
5391 && EQ (XWINDOW (selected_window
)->buffer
, new_current_buffer
)
5392 && !EQ (selected_window
, data
->current_window
))
5393 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
5397 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
5398 point in new_current_buffer as of the last time this buffer was
5399 used. This can be non-deterministic since it can be changed by
5400 things like jit-lock by mere temporary selection of some random
5401 window that happens to show this buffer.
5402 So if possible we want this arbitrary choice of "which point" to
5403 be the one from the to-be-selected-window so as to prevent this
5404 window's cursor from being copied from another window. */
5405 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
5406 /* If current_window = selected_window, its point is in BUF_PT. */
5407 && !EQ (selected_window
, data
->current_window
))
5408 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
5410 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
5413 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5416 /* If f is a dead frame, don't bother rebuilding its window tree.
5417 However, there is other stuff we should still try to do below. */
5418 if (FRAME_LIVE_P (f
))
5421 Lisp_Object dead_windows
= Qnil
;
5422 register Lisp_Object tem
, par
, pers
;
5423 register struct window
*w
;
5424 register struct saved_window
*p
;
5425 struct window
*root_window
;
5426 struct window
**leaf_windows
;
5431 /* If the frame has been resized since this window configuration was
5432 made, we change the frame to the size specified in the
5433 configuration, restore the configuration, and then resize it
5434 back. We keep track of the prevailing height in these variables. */
5435 int previous_frame_lines
= FRAME_LINES (f
);
5436 int previous_frame_cols
= FRAME_COLS (f
);
5437 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
5438 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
5440 /* The mouse highlighting code could get screwed up
5441 if it runs during this. */
5444 if (data
->frame_lines
!= previous_frame_lines
5445 || data
->frame_cols
!= previous_frame_cols
)
5446 change_frame_size (f
, data
->frame_lines
,
5447 data
->frame_cols
, 0, 0, 0);
5448 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5449 if (data
->frame_menu_bar_lines
5450 != previous_frame_menu_bar_lines
)
5451 x_set_menu_bar_lines (f
, make_number (data
->frame_menu_bar_lines
),
5453 #ifdef HAVE_WINDOW_SYSTEM
5454 if (data
->frame_tool_bar_lines
5455 != previous_frame_tool_bar_lines
)
5456 x_set_tool_bar_lines (f
, make_number (data
->frame_tool_bar_lines
),
5461 /* "Swap out" point from the selected window's buffer
5462 into the window itself. (Normally the pointm of the selected
5463 window holds garbage.) We do this now, before
5464 restoring the window contents, and prevent it from
5465 being done later on when we select a new window. */
5466 if (! NILP (XWINDOW (selected_window
)->buffer
))
5468 w
= XWINDOW (selected_window
);
5469 set_marker_both (w
->pointm
,
5471 BUF_PT (XBUFFER (w
->buffer
)),
5472 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5475 windows_or_buffers_changed
++;
5476 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
5478 /* Problem: Freeing all matrices and later allocating them again
5479 is a serious redisplay flickering problem. What we would
5480 really like to do is to free only those matrices not reused
5482 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5484 = (struct window
**) alloca (count_windows (root_window
)
5485 * sizeof (struct window
*));
5486 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
5489 Mark all windows now on frame as "deleted".
5490 Restoring the new configuration "undeletes" any that are in it.
5492 Save their current buffers in their height fields, since we may
5493 need it later, if a buffer saved in the configuration is now
5495 delete_all_child_windows (FRAME_ROOT_WINDOW (f
));
5497 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
5499 p
= SAVED_WINDOW_N (saved_windows
, k
);
5501 w
= XWINDOW (window
);
5504 if (!NILP (p
->parent
))
5505 w
->parent
= SAVED_WINDOW_N (saved_windows
,
5506 XFASTINT (p
->parent
))->window
;
5510 if (!NILP (p
->prev
))
5512 w
->prev
= SAVED_WINDOW_N (saved_windows
,
5513 XFASTINT (p
->prev
))->window
;
5514 XWINDOW (w
->prev
)->next
= p
->window
;
5519 if (!NILP (w
->parent
))
5521 if (EQ (p
->total_cols
, XWINDOW (w
->parent
)->total_cols
))
5523 XWINDOW (w
->parent
)->vchild
= p
->window
;
5524 XWINDOW (w
->parent
)->hchild
= Qnil
;
5528 XWINDOW (w
->parent
)->hchild
= p
->window
;
5529 XWINDOW (w
->parent
)->vchild
= Qnil
;
5534 /* If we squirreled away the buffer in the window's height,
5536 if (BUFFERP (w
->total_lines
))
5537 w
->buffer
= w
->total_lines
;
5538 w
->left_col
= p
->left_col
;
5539 w
->top_line
= p
->top_line
;
5540 w
->total_cols
= p
->total_cols
;
5541 w
->total_lines
= p
->total_lines
;
5542 w
->normal_cols
= p
->normal_cols
;
5543 w
->normal_lines
= p
->normal_lines
;
5544 w
->hscroll
= p
->hscroll
;
5545 w
->min_hscroll
= p
->min_hscroll
;
5546 w
->display_table
= p
->display_table
;
5547 w
->left_margin_cols
= p
->left_margin_cols
;
5548 w
->right_margin_cols
= p
->right_margin_cols
;
5549 w
->left_fringe_width
= p
->left_fringe_width
;
5550 w
->right_fringe_width
= p
->right_fringe_width
;
5551 w
->fringes_outside_margins
= p
->fringes_outside_margins
;
5552 w
->scroll_bar_width
= p
->scroll_bar_width
;
5553 w
->vertical_scroll_bar_type
= p
->vertical_scroll_bar_type
;
5554 w
->dedicated
= p
->dedicated
;
5555 w
->combination_limit
= p
->combination_limit
;
5556 /* Restore any window parameters that have been saved.
5557 Parameters that have not been saved are left alone. */
5558 for (tem
= p
->window_parameters
; CONSP (tem
); tem
= XCDR (tem
))
5563 if (NILP (XCDR (pers
)))
5565 par
= Fassq (XCAR (pers
), w
->window_parameters
);
5566 if (CONSP (par
) && !NILP (XCDR (par
)))
5567 /* Reset a parameter to nil if and only if it
5568 has a non-nil association. Don't make new
5570 Fsetcdr (par
, Qnil
);
5573 /* Always restore a non-nil value. */
5574 Fset_window_parameter (window
, XCAR (pers
), XCDR (pers
));
5578 XSETFASTINT (w
->last_modified
, 0);
5579 XSETFASTINT (w
->last_overlay_modified
, 0);
5581 /* Reinstall the saved buffer and pointers into it. */
5582 if (NILP (p
->buffer
))
5583 /* An internal window. */
5584 w
->buffer
= p
->buffer
;
5585 else if (!NILP (BVAR (XBUFFER (p
->buffer
), name
)))
5586 /* If saved buffer is alive, install it. */
5588 w
->buffer
= p
->buffer
;
5589 w
->start_at_line_beg
= !NILP (p
->start_at_line_beg
);
5590 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
5591 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
5592 Fset_marker (BVAR (XBUFFER (w
->buffer
), mark
),
5593 p
->mark
, w
->buffer
);
5595 /* As documented in Fcurrent_window_configuration, don't
5596 restore the location of point in the buffer which was
5597 current when the window configuration was recorded. */
5598 if (!EQ (p
->buffer
, new_current_buffer
)
5599 && XBUFFER (p
->buffer
) == current_buffer
)
5600 Fgoto_char (w
->pointm
);
5602 else if (!NILP (w
->buffer
) && !NILP (BVAR (XBUFFER (w
->buffer
), name
)))
5603 /* Keep window's old buffer; make sure the markers are
5606 /* Set window markers at start of visible range. */
5607 if (XMARKER (w
->start
)->buffer
== 0)
5608 set_marker_restricted (w
->start
, make_number (0),
5610 if (XMARKER (w
->pointm
)->buffer
== 0)
5611 set_marker_restricted_both (w
->pointm
, w
->buffer
,
5612 BUF_PT (XBUFFER (w
->buffer
)),
5613 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5614 w
->start_at_line_beg
= 1;
5616 else if (STRINGP (auto_buffer_name
=
5617 Fwindow_parameter (window
, Qauto_buffer_name
))
5618 && SCHARS (auto_buffer_name
) != 0
5619 && !NILP (w
->buffer
= Fget_buffer_create (auto_buffer_name
)))
5621 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
5622 set_marker_restricted (w
->pointm
, make_number (0), w
->buffer
);
5623 w
->start_at_line_beg
= 1;
5626 /* Window has no live buffer, get one. */
5628 /* Get the buffer via other_buffer_safely in order to
5629 avoid showing an unimportant buffer and, if necessary, to
5630 recreate *scratch* in the course (part of Juanma's bs-show
5631 scenario from March 2011). */
5632 w
->buffer
= other_buffer_safely (Fcurrent_buffer ());
5633 /* This will set the markers to beginning of visible
5635 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
5636 set_marker_restricted (w
->pointm
, make_number (0), w
->buffer
);
5637 w
->start_at_line_beg
= 1;
5638 if (!NILP (w
->dedicated
))
5639 /* Record this window as dead. */
5640 dead_windows
= Fcons (window
, dead_windows
);
5641 /* Make sure window is no more dedicated. */
5642 w
->dedicated
= Qnil
;
5646 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
5647 /* Arrange *not* to restore point in the buffer that was
5648 current when the window configuration was saved. */
5649 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
5650 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
5651 make_number (old_point
),
5652 XWINDOW (data
->current_window
)->buffer
);
5654 /* In the following call to `select-window', prevent "swapping out
5655 point" in the old selected window using the buffer that has
5656 been restored into it. We already swapped out that point from
5657 that window's old buffer. */
5658 select_window (data
->current_window
, Qnil
, 1);
5659 BVAR (XBUFFER (XWINDOW (selected_window
)->buffer
), last_selected_window
)
5662 if (NILP (data
->focus_frame
)
5663 || (FRAMEP (data
->focus_frame
)
5664 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
5665 Fredirect_frame_focus (frame
, data
->focus_frame
);
5667 /* Set the screen height to the value it had before this function. */
5668 if (previous_frame_lines
!= FRAME_LINES (f
)
5669 || previous_frame_cols
!= FRAME_COLS (f
))
5670 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
5672 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5673 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
5674 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
5676 #ifdef HAVE_WINDOW_SYSTEM
5677 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
5678 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
5683 /* Now, free glyph matrices in windows that were not reused. */
5684 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
5686 if (NILP (leaf_windows
[i
]->buffer
))
5688 /* Assert it's not reused as a combination. */
5689 eassert (NILP (leaf_windows
[i
]->hchild
)
5690 && NILP (leaf_windows
[i
]->vchild
));
5691 free_window_matrices (leaf_windows
[i
]);
5693 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
5700 /* Scan dead buffer windows. */
5701 for (; CONSP (dead_windows
); dead_windows
= XCDR (dead_windows
))
5703 window
= XCAR (dead_windows
);
5704 if (WINDOW_LIVE_P (window
) && !EQ (window
, FRAME_ROOT_WINDOW (f
)))
5705 delete_deletable_window (window
);
5708 /* Fselect_window will have made f the selected frame, so we
5709 reselect the proper frame here. Fhandle_switch_frame will change the
5710 selected window too, but that doesn't make the call to
5711 Fselect_window above totally superfluous; it still sets f's
5713 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
5714 do_switch_frame (data
->selected_frame
, 0, 0, Qnil
);
5716 run_window_configuration_change_hook (f
);
5719 if (!NILP (new_current_buffer
))
5720 Fset_buffer (new_current_buffer
);
5722 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
5723 minibuf_selected_window
= data
->minibuf_selected_window
;
5725 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
5729 /* Recursively delete all child windows reachable via the next, vchild,
5730 and hchild slots of WINDOW. */
5732 delete_all_child_windows (Lisp_Object window
)
5734 register struct window
*w
;
5736 w
= XWINDOW (window
);
5738 if (!NILP (w
->next
))
5739 /* Delete WINDOW's siblings (we traverse postorderly). */
5740 delete_all_child_windows (w
->next
);
5742 w
->total_lines
= w
->buffer
; /* See Fset_window_configuration for excuse. */
5744 if (!NILP (w
->vchild
))
5746 delete_all_child_windows (w
->vchild
);
5749 else if (!NILP (w
->hchild
))
5751 delete_all_child_windows (w
->hchild
);
5754 else if (!NILP (w
->buffer
))
5757 unchain_marker (XMARKER (w
->pointm
));
5758 unchain_marker (XMARKER (w
->start
));
5762 Vwindow_list
= Qnil
;
5766 count_windows (register struct window
*window
)
5768 register int count
= 1;
5769 if (!NILP (window
->next
))
5770 count
+= count_windows (XWINDOW (window
->next
));
5771 if (!NILP (window
->vchild
))
5772 count
+= count_windows (XWINDOW (window
->vchild
));
5773 if (!NILP (window
->hchild
))
5774 count
+= count_windows (XWINDOW (window
->hchild
));
5779 /* Fill vector FLAT with leaf windows under W, starting at index I.
5780 Value is last index + 1. */
5782 get_leaf_windows (struct window
*w
, struct window
**flat
, int i
)
5786 if (!NILP (w
->hchild
))
5787 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
5788 else if (!NILP (w
->vchild
))
5789 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
5793 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5800 /* Return a pointer to the glyph W's physical cursor is on. Value is
5801 null if W's current matrix is invalid, so that no meaningful glyph
5804 get_phys_cursor_glyph (struct window
*w
)
5806 struct glyph_row
*row
;
5807 struct glyph
*glyph
;
5808 int hpos
= w
->phys_cursor
.hpos
;
5810 if (!(w
->phys_cursor
.vpos
>= 0
5811 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
))
5814 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
5815 if (!row
->enabled_p
)
5818 if (XINT (w
->hscroll
))
5820 /* When the window is hscrolled, cursor hpos can legitimately be
5821 out of bounds, but we draw the cursor at the corresponding
5822 window margin in that case. */
5823 if (!row
->reversed_p
&& hpos
< 0)
5825 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
5826 hpos
= row
->used
[TEXT_AREA
] - 1;
5829 if (row
->used
[TEXT_AREA
] > hpos
5831 glyph
= row
->glyphs
[TEXT_AREA
] + hpos
;
5840 save_window_save (Lisp_Object window
, struct Lisp_Vector
*vector
, int i
)
5842 register struct saved_window
*p
;
5843 register struct window
*w
;
5844 register Lisp_Object tem
, pers
, par
;
5846 for (;!NILP (window
); window
= w
->next
)
5848 p
= SAVED_WINDOW_N (vector
, i
);
5849 w
= XWINDOW (window
);
5851 XSETFASTINT (w
->temslot
, i
); i
++;
5853 p
->buffer
= w
->buffer
;
5854 p
->left_col
= w
->left_col
;
5855 p
->top_line
= w
->top_line
;
5856 p
->total_cols
= w
->total_cols
;
5857 p
->total_lines
= w
->total_lines
;
5858 p
->normal_cols
= w
->normal_cols
;
5859 p
->normal_lines
= w
->normal_lines
;
5860 p
->hscroll
= w
->hscroll
;
5861 p
->min_hscroll
= w
->min_hscroll
;
5862 p
->display_table
= w
->display_table
;
5863 p
->left_margin_cols
= w
->left_margin_cols
;
5864 p
->right_margin_cols
= w
->right_margin_cols
;
5865 p
->left_fringe_width
= w
->left_fringe_width
;
5866 p
->right_fringe_width
= w
->right_fringe_width
;
5867 p
->fringes_outside_margins
= w
->fringes_outside_margins
;
5868 p
->scroll_bar_width
= w
->scroll_bar_width
;
5869 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
5870 p
->dedicated
= w
->dedicated
;
5871 p
->combination_limit
= w
->combination_limit
;
5872 p
->window_parameters
= Qnil
;
5874 if (!NILP (Vwindow_persistent_parameters
))
5876 /* Run cycle detection on Vwindow_persistent_parameters. */
5877 Lisp_Object tortoise
, hare
;
5879 hare
= tortoise
= Vwindow_persistent_parameters
;
5880 while (CONSP (hare
))
5887 tortoise
= XCDR (tortoise
);
5889 if (EQ (hare
, tortoise
))
5890 /* Reset Vwindow_persistent_parameters to Qnil. */
5892 Vwindow_persistent_parameters
= Qnil
;
5897 for (tem
= Vwindow_persistent_parameters
; CONSP (tem
);
5901 /* Save values for persistent window parameters. */
5902 if (CONSP (pers
) && !NILP (XCDR (pers
)))
5904 par
= Fassq (XCAR (pers
), w
->window_parameters
);
5906 /* If the window has no value for the parameter,
5908 p
->window_parameters
= Fcons (Fcons (XCAR (pers
), Qnil
),
5909 p
->window_parameters
);
5911 /* If the window has a value for the parameter,
5913 p
->window_parameters
= Fcons (Fcons (XCAR (par
),
5915 p
->window_parameters
);
5920 if (!NILP (w
->buffer
))
5922 /* Save w's value of point in the window configuration. If w
5923 is the selected window, then get the value of point from
5924 the buffer; pointm is garbage in the selected window. */
5925 if (EQ (window
, selected_window
))
5927 p
->pointm
= Fmake_marker ();
5928 set_marker_both (p
->pointm
, w
->buffer
,
5929 BUF_PT (XBUFFER (w
->buffer
)),
5930 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5933 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
5934 XMARKER (p
->pointm
)->insertion_type
5935 = !NILP (Vwindow_point_insertion_type
);
5937 p
->start
= Fcopy_marker (w
->start
, Qnil
);
5938 p
->start_at_line_beg
= w
->start_at_line_beg
? Qt
: Qnil
;
5940 tem
= BVAR (XBUFFER (w
->buffer
), mark
);
5941 p
->mark
= Fcopy_marker (tem
, Qnil
);
5948 p
->start_at_line_beg
= Qnil
;
5951 if (NILP (w
->parent
))
5954 p
->parent
= XWINDOW (w
->parent
)->temslot
;
5959 p
->prev
= XWINDOW (w
->prev
)->temslot
;
5961 if (!NILP (w
->vchild
))
5962 i
= save_window_save (w
->vchild
, vector
, i
);
5963 if (!NILP (w
->hchild
))
5964 i
= save_window_save (w
->hchild
, vector
, i
);
5970 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
5971 Scurrent_window_configuration
, 0, 1, 0,
5972 doc
: /* Return an object representing the current window configuration of FRAME.
5973 If FRAME is nil or omitted, use the selected frame.
5974 This describes the number of windows, their sizes and current buffers,
5975 and for each displayed buffer, where display starts, and the positions of
5976 point and mark. An exception is made for point in the current buffer:
5977 its value is -not- saved.
5978 This also records the currently selected frame, and FRAME's focus
5979 redirection (see `redirect-frame-focus'). The variable
5980 `window-persistent-parameters' specifies which window parameters are
5981 saved by this function. */)
5984 register Lisp_Object tem
;
5985 register int n_windows
;
5986 register struct save_window_data
*data
;
5991 frame
= selected_frame
;
5992 CHECK_LIVE_FRAME (frame
);
5995 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5996 data
= ALLOCATE_PSEUDOVECTOR (struct save_window_data
, frame_cols
,
5997 PVEC_WINDOW_CONFIGURATION
);
5999 data
->frame_cols
= FRAME_COLS (f
);
6000 data
->frame_lines
= FRAME_LINES (f
);
6001 data
->frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6002 data
->frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6003 data
->selected_frame
= selected_frame
;
6004 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6005 XSETBUFFER (data
->current_buffer
, current_buffer
);
6006 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6007 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6008 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6009 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6010 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
6011 data
->saved_windows
= tem
;
6012 for (i
= 0; i
< n_windows
; i
++)
6014 Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
));
6015 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6016 XSETWINDOW_CONFIGURATION (tem
, data
);
6020 /***********************************************************************
6022 ***********************************************************************/
6024 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6026 doc
: /* Set width of marginal areas of window WINDOW.
6027 If WINDOW is nil, set margins of the currently selected window.
6028 Second arg LEFT-WIDTH specifies the number of character cells to
6029 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6030 does the same for the right marginal area. A nil width parameter
6031 means no margin. */)
6032 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
)
6034 struct window
*w
= decode_window (window
);
6036 /* Translate negative or zero widths to nil.
6037 Margins that are too wide have to be checked elsewhere. */
6039 if (!NILP (left_width
))
6041 CHECK_NUMBER (left_width
);
6042 if (XINT (left_width
) <= 0)
6046 if (!NILP (right_width
))
6048 CHECK_NUMBER (right_width
);
6049 if (XINT (right_width
) <= 0)
6053 if (!EQ (w
->left_margin_cols
, left_width
)
6054 || !EQ (w
->right_margin_cols
, right_width
))
6056 w
->left_margin_cols
= left_width
;
6057 w
->right_margin_cols
= right_width
;
6059 adjust_window_margins (w
);
6061 ++windows_or_buffers_changed
;
6062 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6069 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6071 doc
: /* Get width of marginal areas of window WINDOW.
6072 If WINDOW is omitted or nil, it defaults to the selected window.
6073 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6074 If a marginal area does not exist, its width will be returned
6076 (Lisp_Object window
)
6078 struct window
*w
= decode_window (window
);
6079 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
6084 /***********************************************************************
6086 ***********************************************************************/
6088 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6090 doc
: /* Set the fringe widths of window WINDOW.
6091 If WINDOW is nil, set the fringe widths of the currently selected
6093 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6094 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6095 fringe width. If a fringe width arg is nil, that means to use the
6096 frame's default fringe width. Default fringe widths can be set with
6097 the command `set-fringe-style'.
6098 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6099 outside of the display margins. By default, fringes are drawn between
6100 display marginal areas and the text area. */)
6101 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
, Lisp_Object outside_margins
)
6103 struct window
*w
= decode_window (window
);
6105 if (!NILP (left_width
))
6106 CHECK_NATNUM (left_width
);
6107 if (!NILP (right_width
))
6108 CHECK_NATNUM (right_width
);
6110 /* Do nothing on a tty. */
6111 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6112 && (!EQ (w
->left_fringe_width
, left_width
)
6113 || !EQ (w
->right_fringe_width
, right_width
)
6114 || !EQ (w
->fringes_outside_margins
, outside_margins
)))
6116 w
->left_fringe_width
= left_width
;
6117 w
->right_fringe_width
= right_width
;
6118 w
->fringes_outside_margins
= outside_margins
;
6120 adjust_window_margins (w
);
6122 clear_glyph_matrix (w
->current_matrix
);
6123 w
->window_end_valid
= Qnil
;
6125 ++windows_or_buffers_changed
;
6126 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6133 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6135 doc
: /* Get width of fringes of window WINDOW.
6136 If WINDOW is omitted or nil, it defaults to the selected window.
6137 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6138 (Lisp_Object window
)
6140 struct window
*w
= decode_window (window
);
6142 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6143 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6144 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
6145 ? Qt
: Qnil
), Qnil
)));
6150 /***********************************************************************
6152 ***********************************************************************/
6154 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
,
6155 Sset_window_scroll_bars
, 2, 4, 0,
6156 doc
: /* Set width and type of scroll bars of window WINDOW.
6157 If window is nil, set scroll bars of the currently selected window.
6158 Second parameter WIDTH specifies the pixel width for the scroll bar;
6159 this is automatically adjusted to a multiple of the frame column width.
6160 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6161 bar: left, right, or nil.
6162 If WIDTH is nil, use the frame's scroll-bar width.
6163 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6164 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6165 (Lisp_Object window
, Lisp_Object width
, Lisp_Object vertical_type
, Lisp_Object horizontal_type
)
6167 struct window
*w
= decode_window (window
);
6171 CHECK_RANGED_INTEGER (0, width
, INT_MAX
);
6173 if (XINT (width
) == 0)
6174 vertical_type
= Qnil
;
6177 if (!(NILP (vertical_type
)
6178 || EQ (vertical_type
, Qleft
)
6179 || EQ (vertical_type
, Qright
)
6180 || EQ (vertical_type
, Qt
)))
6181 error ("Invalid type of vertical scroll bar");
6183 if (!EQ (w
->scroll_bar_width
, width
)
6184 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6186 w
->scroll_bar_width
= width
;
6187 w
->vertical_scroll_bar_type
= vertical_type
;
6189 adjust_window_margins (w
);
6191 clear_glyph_matrix (w
->current_matrix
);
6192 w
->window_end_valid
= Qnil
;
6194 ++windows_or_buffers_changed
;
6195 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6202 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6204 doc
: /* Get width and type of scroll bars of window WINDOW.
6205 If WINDOW is omitted or nil, it defaults to the selected window.
6206 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6207 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6209 (Lisp_Object window
)
6211 struct window
*w
= decode_window (window
);
6212 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6213 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6214 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6215 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6216 Fcons (w
->vertical_scroll_bar_type
,
6217 Fcons (Qnil
, Qnil
))));
6222 /***********************************************************************
6224 ***********************************************************************/
6226 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6227 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6228 If WINDOW is omitted or nil, it defaults to the selected window.
6229 Normally, value is a multiple of the canonical character height of WINDOW;
6230 optional second arg PIXELS-P means value is measured in pixels. */)
6231 (Lisp_Object window
, Lisp_Object pixels_p
)
6238 window
= selected_window
;
6240 CHECK_WINDOW (window
);
6241 w
= XWINDOW (window
);
6242 f
= XFRAME (w
->frame
);
6244 if (FRAME_WINDOW_P (f
))
6245 result
= (NILP (pixels_p
)
6246 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6247 : make_number (-w
->vscroll
));
6249 result
= make_number (0);
6254 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6256 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6257 WINDOW nil means use the selected window. Normally, VSCROLL is a
6258 non-negative multiple of the canonical character height of WINDOW;
6259 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
6260 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6261 corresponds to an integral number of pixels. The return value is the
6262 result of this rounding.
6263 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6264 (Lisp_Object window
, Lisp_Object vscroll
, Lisp_Object pixels_p
)
6270 window
= selected_window
;
6272 CHECK_WINDOW (window
);
6273 CHECK_NUMBER_OR_FLOAT (vscroll
);
6275 w
= XWINDOW (window
);
6276 f
= XFRAME (w
->frame
);
6278 if (FRAME_WINDOW_P (f
))
6280 int old_dy
= w
->vscroll
;
6282 w
->vscroll
= - (NILP (pixels_p
)
6283 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
6284 : XFLOATINT (vscroll
));
6285 w
->vscroll
= min (w
->vscroll
, 0);
6287 if (w
->vscroll
!= old_dy
)
6289 /* Adjust glyph matrix of the frame if the virtual display
6290 area becomes larger than before. */
6291 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
6294 /* Prevent redisplay shortcuts. */
6295 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
6299 return Fwindow_vscroll (window
, pixels_p
);
6303 /* Call FN for all leaf windows on frame F. FN is called with the
6304 first argument being a pointer to the leaf window, and with
6305 additional argument USER_DATA. Stops when FN returns 0. */
6308 foreach_window (struct frame
*f
, int (*fn
) (struct window
*, void *),
6311 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
6312 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
6313 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
6317 /* Helper function for foreach_window. Call FN for all leaf windows
6318 reachable from W. FN is called with the first argument being a
6319 pointer to the leaf window, and with additional argument USER_DATA.
6320 Stop when FN returns 0. Value is 0 if stopped by FN. */
6323 foreach_window_1 (struct window
*w
, int (*fn
) (struct window
*, void *), void *user_data
)
6327 for (cont
= 1; w
&& cont
;)
6329 if (!NILP (w
->hchild
))
6330 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
6331 else if (!NILP (w
->vchild
))
6332 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
6334 cont
= fn (w
, user_data
);
6336 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6343 /* Freeze or unfreeze the window start of W unless it is a
6344 mini-window or the selected window. FREEZE_P non-null means freeze
6345 the window start. */
6348 freeze_window_start (struct window
*w
, void *freeze_p
)
6350 if (MINI_WINDOW_P (w
)
6351 || (WINDOWP (selected_window
) /* Can be nil in corner cases. */
6352 && (w
== XWINDOW (selected_window
)
6353 || (MINI_WINDOW_P (XWINDOW (selected_window
))
6354 && ! NILP (Vminibuf_scroll_window
)
6355 && w
== XWINDOW (Vminibuf_scroll_window
)))))
6358 w
->frozen_window_start_p
= freeze_p
!= NULL
;
6363 /* Freeze or unfreeze the window starts of all leaf windows on frame
6364 F, except the selected window and a mini-window. FREEZE_P non-zero
6365 means freeze the window start. */
6368 freeze_window_starts (struct frame
*f
, int freeze_p
)
6370 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
6374 /***********************************************************************
6376 ***********************************************************************/
6378 /* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2
6379 describe the same state of affairs. This is used by Fequal.
6381 ignore_positions non-zero means ignore non-matching scroll positions
6384 This ignores a couple of things like the dedication status of
6385 window, combination_limit and the like. This might have to be
6389 compare_window_configurations (Lisp_Object configuration1
, Lisp_Object configuration2
, int ignore_positions
)
6391 register struct save_window_data
*d1
, *d2
;
6392 struct Lisp_Vector
*sws1
, *sws2
;
6395 CHECK_WINDOW_CONFIGURATION (configuration1
);
6396 CHECK_WINDOW_CONFIGURATION (configuration2
);
6398 d1
= (struct save_window_data
*) XVECTOR (configuration1
);
6399 d2
= (struct save_window_data
*) XVECTOR (configuration2
);
6400 sws1
= XVECTOR (d1
->saved_windows
);
6401 sws2
= XVECTOR (d2
->saved_windows
);
6403 /* Frame settings must match. */
6404 if (d1
->frame_cols
!= d2
->frame_cols
6405 || d1
->frame_lines
!= d2
->frame_lines
6406 || d1
->frame_menu_bar_lines
!= d2
->frame_menu_bar_lines
6407 || !EQ (d1
->selected_frame
, d2
->selected_frame
)
6408 || !EQ (d1
->current_buffer
, d2
->current_buffer
)
6409 || (!ignore_positions
6410 && (!EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
)
6411 || !EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
)))
6412 || !EQ (d1
->focus_frame
, d2
->focus_frame
)
6413 /* Verify that the two configurations have the same number of windows. */
6414 || sws1
->header
.size
!= sws2
->header
.size
)
6417 for (i
= 0; i
< sws1
->header
.size
; i
++)
6419 struct saved_window
*sw1
, *sw2
;
6421 sw1
= SAVED_WINDOW_N (sws1
, i
);
6422 sw2
= SAVED_WINDOW_N (sws2
, i
);
6425 /* The "current" windows in the two configurations must
6426 correspond to each other. */
6427 EQ (d1
->current_window
, sw1
->window
)
6428 != EQ (d2
->current_window
, sw2
->window
)
6429 /* Windows' buffers must match. */
6430 || !EQ (sw1
->buffer
, sw2
->buffer
)
6431 || !EQ (sw1
->left_col
, sw2
->left_col
)
6432 || !EQ (sw1
->top_line
, sw2
->top_line
)
6433 || !EQ (sw1
->total_cols
, sw2
->total_cols
)
6434 || !EQ (sw1
->total_lines
, sw2
->total_lines
)
6435 || !EQ (sw1
->display_table
, sw2
->display_table
)
6436 /* The next two disjuncts check the window structure for
6438 || !EQ (sw1
->parent
, sw2
->parent
)
6439 || !EQ (sw1
->prev
, sw2
->prev
)
6440 || (!ignore_positions
6441 && (!EQ (sw1
->hscroll
, sw2
->hscroll
)
6442 || !EQ (sw1
->min_hscroll
, sw2
->min_hscroll
)
6443 || !EQ (sw1
->start_at_line_beg
, sw2
->start_at_line_beg
)
6444 || NILP (Fequal (sw1
->start
, sw2
->start
))
6445 || NILP (Fequal (sw1
->pointm
, sw2
->pointm
))
6446 || NILP (Fequal (sw1
->mark
, sw2
->mark
))))
6447 || !EQ (sw1
->left_margin_cols
, sw2
->left_margin_cols
)
6448 || !EQ (sw1
->right_margin_cols
, sw2
->right_margin_cols
)
6449 || !EQ (sw1
->left_fringe_width
, sw2
->left_fringe_width
)
6450 || !EQ (sw1
->right_fringe_width
, sw2
->right_fringe_width
)
6451 || !EQ (sw1
->fringes_outside_margins
, sw2
->fringes_outside_margins
)
6452 || !EQ (sw1
->scroll_bar_width
, sw2
->scroll_bar_width
)
6453 || !EQ (sw1
->vertical_scroll_bar_type
, sw2
->vertical_scroll_bar_type
))
6460 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
6461 Scompare_window_configurations
, 2, 2, 0,
6462 doc
: /* Compare two window configurations as regards the structure of windows.
6463 This function ignores details such as the values of point and mark
6464 and scrolling positions. */)
6465 (Lisp_Object x
, Lisp_Object y
)
6467 if (compare_window_configurations (x
, y
, 1))
6473 init_window_once (void)
6475 struct frame
*f
= make_initial_frame ();
6476 XSETFRAME (selected_frame
, f
);
6477 Vterminal_frame
= selected_frame
;
6478 minibuf_window
= f
->minibuffer_window
;
6479 selected_window
= f
->selected_window
;
6480 last_nonminibuf_frame
= f
;
6482 window_initialized
= 1;
6488 Vwindow_list
= Qnil
;
6492 syms_of_window (void)
6494 DEFSYM (Qscroll_up
, "scroll-up");
6495 DEFSYM (Qscroll_down
, "scroll-down");
6496 DEFSYM (Qscroll_command
, "scroll-command");
6498 Fput (Qscroll_up
, Qscroll_command
, Qt
);
6499 Fput (Qscroll_down
, Qscroll_command
, Qt
);
6501 DEFSYM (Qwindow_configuration_change_hook
, "window-configuration-change-hook");
6502 DEFSYM (Qwindowp
, "windowp");
6503 DEFSYM (Qwindow_configuration_p
, "window-configuration-p");
6504 DEFSYM (Qwindow_live_p
, "window-live-p");
6505 DEFSYM (Qwindow_deletable_p
, "window-deletable-p");
6506 DEFSYM (Qdelete_window
, "delete-window");
6507 DEFSYM (Qwindow_resize_root_window
, "window--resize-root-window");
6508 DEFSYM (Qwindow_resize_root_window_vertically
, "window--resize-root-window-vertically");
6509 DEFSYM (Qsafe
, "safe");
6510 DEFSYM (Qdisplay_buffer
, "display-buffer");
6511 DEFSYM (Qreplace_buffer_in_windows
, "replace-buffer-in-windows");
6512 DEFSYM (Qrecord_window_buffer
, "record-window-buffer");
6513 DEFSYM (Qget_mru_window
, "get-mru-window");
6514 DEFSYM (Qtemp_buffer_show_hook
, "temp-buffer-show-hook");
6515 DEFSYM (Qabove
, "above");
6516 DEFSYM (Qbelow
, "below");
6517 DEFSYM (Qauto_buffer_name
, "auto-buffer-name");
6518 DEFSYM (Qclone_of
, "clone-of");
6520 staticpro (&Vwindow_list
);
6522 minibuf_selected_window
= Qnil
;
6523 staticpro (&minibuf_selected_window
);
6525 window_scroll_pixel_based_preserve_x
= -1;
6526 window_scroll_pixel_based_preserve_y
= -1;
6527 window_scroll_preserve_hpos
= -1;
6528 window_scroll_preserve_vpos
= -1;
6530 DEFVAR_LISP ("temp-buffer-show-function", Vtemp_buffer_show_function
,
6531 doc
: /* Non-nil means call as function to display a help buffer.
6532 The function is called with one argument, the buffer to be displayed.
6533 Used by `with-output-to-temp-buffer'.
6534 If this function is used, then it must do the entire job of showing
6535 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6536 Vtemp_buffer_show_function
= Qnil
;
6538 DEFVAR_LISP ("minibuffer-scroll-window", Vminibuf_scroll_window
,
6539 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6540 Vminibuf_scroll_window
= Qnil
;
6542 DEFVAR_BOOL ("mode-line-in-non-selected-windows", mode_line_in_non_selected_windows
,
6543 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6544 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6545 is displayed in the `mode-line' face. */);
6546 mode_line_in_non_selected_windows
= 1;
6548 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer
,
6549 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6550 Vother_window_scroll_buffer
= Qnil
;
6552 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p
,
6553 doc
: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
6554 auto_window_vscroll_p
= 1;
6556 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines
,
6557 doc
: /* Number of lines of continuity when scrolling by screenfuls. */);
6558 next_screen_context_lines
= 2;
6560 DEFVAR_LISP ("scroll-preserve-screen-position",
6561 Vscroll_preserve_screen_position
,
6562 doc
: /* Controls if scroll commands move point to keep its screen position unchanged.
6563 A value of nil means point does not keep its screen position except
6564 at the scroll margin or window boundary respectively.
6565 A value of t means point keeps its screen position if the scroll
6566 command moved it vertically out of the window, e.g. when scrolling
6568 Any other value means point always keeps its screen position.
6569 Scroll commands should have the `scroll-command' property
6570 on their symbols to be controlled by this variable. */);
6571 Vscroll_preserve_screen_position
= Qnil
;
6573 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type
,
6574 doc
: /* Type of marker to use for `window-point'. */);
6575 Vwindow_point_insertion_type
= Qnil
;
6577 DEFVAR_LISP ("window-configuration-change-hook",
6578 Vwindow_configuration_change_hook
,
6579 doc
: /* Functions to call when window configuration changes.
6580 The buffer-local part is run once per window, with the relevant window
6581 selected; while the global part is run only once for the modified frame,
6582 with the relevant frame selected. */);
6583 Vwindow_configuration_change_hook
= Qnil
;
6585 DEFVAR_LISP ("recenter-redisplay", Vrecenter_redisplay
,
6586 doc
: /* Non-nil means `recenter' redraws entire frame.
6587 If this option is non-nil, then the `recenter' command with a nil
6588 argument will redraw the entire frame; the special value `tty' causes
6589 the frame to be redrawn only if it is a tty frame. */);
6590 Vrecenter_redisplay
= Qtty
;
6592 DEFVAR_LISP ("window-combination-resize", Vwindow_combination_resize
,
6593 doc
: /* If t, resize window combinations proportionally.
6594 If this variable is nil, splitting a window gets the entire screen space
6595 for displaying the new window from the window to split. Deleting and
6596 resizing a window preferably resizes one adjacent window only.
6598 If this variable is t, splitting a window tries to get the space
6599 proportionally from all windows in the same combination. This also
6600 allows to split a window that is otherwise too small or of fixed size.
6601 Resizing and deleting a window proportionally resize all windows in the
6604 Other values are reserved for future use.
6606 This variable takes no effect if `window-combination-limit' is non-nil. */);
6607 Vwindow_combination_resize
= Qnil
;
6609 DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit
,
6610 doc
: /* If t, splitting a window makes a new parent window.
6611 If this variable is nil, splitting a window will create a new parent
6612 window only if the window has no parent window or the window shall
6613 become a combination orthogonal to the one it is part of.
6615 If this variable is t, splitting a window always creates a new parent
6616 window. If all splits behave this way, each frame's window tree is a
6617 binary tree and every window but the frame's root window has exactly one
6620 Other values are reserved for future use.
6622 The value of this variable is also assigned to the combination limit of
6623 the new parent window. The combination limit of a window can be
6624 retrieved via the function `window-combination-limit' and altered by the
6625 function `set-window-combination-limit'. */);
6626 Vwindow_combination_limit
= Qnil
;
6628 DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters
,
6629 doc
: /* Alist of persistent window parameters.
6630 This alist specifies which window parameters shall get saved by
6631 `current-window-configuration' and `window-state-get' and subsequently
6632 restored to their previous values by `set-window-configuration' and
6635 The car of each entry of this alist is the symbol specifying the
6636 parameter. The cdr is one of the following:
6638 nil means the parameter is neither saved by `window-state-get' nor by
6639 `current-window-configuration'.
6641 t means the parameter is saved by `current-window-configuration' and,
6642 provided its WRITABLE argument is nil, by `window-state-get'.
6644 The symbol `writable' means the parameter is saved unconditionally by
6645 both `current-window-configuration' and `window-state-get'. Do not use
6646 this value for parameters without read syntax (like windows or frames).
6648 Parameters not saved by `current-window-configuration' or
6649 `window-state-get' are left alone by `set-window-configuration'
6650 respectively are not installed by `window-state-put'. */);
6651 Vwindow_persistent_parameters
= list1 (Fcons (Qclone_of
, Qt
));
6653 defsubr (&Sselected_window
);
6654 defsubr (&Sminibuffer_window
);
6655 defsubr (&Swindow_minibuffer_p
);
6656 defsubr (&Swindowp
);
6657 defsubr (&Swindow_live_p
);
6658 defsubr (&Swindow_frame
);
6659 defsubr (&Sframe_root_window
);
6660 defsubr (&Sframe_first_window
);
6661 defsubr (&Sframe_selected_window
);
6662 defsubr (&Sset_frame_selected_window
);
6663 defsubr (&Spos_visible_in_window_p
);
6664 defsubr (&Swindow_line_height
);
6665 defsubr (&Swindow_buffer
);
6666 defsubr (&Swindow_parent
);
6667 defsubr (&Swindow_top_child
);
6668 defsubr (&Swindow_left_child
);
6669 defsubr (&Swindow_next_sibling
);
6670 defsubr (&Swindow_prev_sibling
);
6671 defsubr (&Swindow_combination_limit
);
6672 defsubr (&Sset_window_combination_limit
);
6673 defsubr (&Swindow_use_time
);
6674 defsubr (&Swindow_top_line
);
6675 defsubr (&Swindow_left_column
);
6676 defsubr (&Swindow_total_height
);
6677 defsubr (&Swindow_total_width
);
6678 defsubr (&Swindow_normal_size
);
6679 defsubr (&Swindow_new_total
);
6680 defsubr (&Swindow_new_normal
);
6681 defsubr (&Sset_window_new_total
);
6682 defsubr (&Sset_window_new_normal
);
6683 defsubr (&Swindow_resize_apply
);
6684 defsubr (&Swindow_body_height
);
6685 defsubr (&Swindow_body_width
);
6686 defsubr (&Swindow_hscroll
);
6687 defsubr (&Sset_window_hscroll
);
6688 defsubr (&Swindow_redisplay_end_trigger
);
6689 defsubr (&Sset_window_redisplay_end_trigger
);
6690 defsubr (&Swindow_edges
);
6691 defsubr (&Swindow_pixel_edges
);
6692 defsubr (&Swindow_absolute_pixel_edges
);
6693 defsubr (&Swindow_inside_edges
);
6694 defsubr (&Swindow_inside_pixel_edges
);
6695 defsubr (&Swindow_inside_absolute_pixel_edges
);
6696 defsubr (&Scoordinates_in_window_p
);
6697 defsubr (&Swindow_at
);
6698 defsubr (&Swindow_point
);
6699 defsubr (&Swindow_start
);
6700 defsubr (&Swindow_end
);
6701 defsubr (&Sset_window_point
);
6702 defsubr (&Sset_window_start
);
6703 defsubr (&Swindow_dedicated_p
);
6704 defsubr (&Sset_window_dedicated_p
);
6705 defsubr (&Swindow_display_table
);
6706 defsubr (&Sset_window_display_table
);
6707 defsubr (&Snext_window
);
6708 defsubr (&Sprevious_window
);
6709 defsubr (&Sget_buffer_window
);
6710 defsubr (&Sdelete_other_windows_internal
);
6711 defsubr (&Sdelete_window_internal
);
6712 defsubr (&Sresize_mini_window_internal
);
6713 defsubr (&Sset_window_buffer
);
6714 defsubr (&Srun_window_configuration_change_hook
);
6715 defsubr (&Sselect_window
);
6716 defsubr (&Sforce_window_update
);
6717 defsubr (&Stemp_output_buffer_show
);
6718 defsubr (&Ssplit_window_internal
);
6719 defsubr (&Sscroll_up
);
6720 defsubr (&Sscroll_down
);
6721 defsubr (&Sscroll_left
);
6722 defsubr (&Sscroll_right
);
6723 defsubr (&Sother_window_for_scrolling
);
6724 defsubr (&Sscroll_other_window
);
6725 defsubr (&Sminibuffer_selected_window
);
6726 defsubr (&Srecenter
);
6727 defsubr (&Swindow_text_height
);
6728 defsubr (&Smove_to_window_line
);
6729 defsubr (&Swindow_configuration_p
);
6730 defsubr (&Swindow_configuration_frame
);
6731 defsubr (&Sset_window_configuration
);
6732 defsubr (&Scurrent_window_configuration
);
6733 defsubr (&Sset_window_margins
);
6734 defsubr (&Swindow_margins
);
6735 defsubr (&Sset_window_fringes
);
6736 defsubr (&Swindow_fringes
);
6737 defsubr (&Sset_window_scroll_bars
);
6738 defsubr (&Swindow_scroll_bars
);
6739 defsubr (&Swindow_vscroll
);
6740 defsubr (&Sset_window_vscroll
);
6741 defsubr (&Scompare_window_configurations
);
6742 defsubr (&Swindow_list
);
6743 defsubr (&Swindow_list_1
);
6744 defsubr (&Swindow_prev_buffers
);
6745 defsubr (&Sset_window_prev_buffers
);
6746 defsubr (&Swindow_next_buffers
);
6747 defsubr (&Sset_window_next_buffers
);
6748 defsubr (&Swindow_parameters
);
6749 defsubr (&Swindow_parameter
);
6750 defsubr (&Sset_window_parameter
);
6754 keys_of_window (void)
6756 initial_define_key (control_x_map
, '<', "scroll-left");
6757 initial_define_key (control_x_map
, '>', "scroll-right");
6759 initial_define_key (global_map
, Ctl ('V'), "scroll-up-command");
6760 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
6761 initial_define_key (meta_map
, 'v', "scroll-down-command");