Support MSVC build with newer versions of Visual Studio.
[emacs.git] / src / window.c
blob6b3b7f2a471c0a116d0f052e170d78e247347a32
1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985-1987, 1993-1998, 2000-2011
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/>. */
21 #include <config.h>
22 #include <stdio.h>
23 #include <setjmp.h>
25 #include "lisp.h"
26 #include "buffer.h"
27 #include "keyboard.h"
28 #include "keymap.h"
29 #include "frame.h"
30 #include "window.h"
31 #include "commands.h"
32 #include "indent.h"
33 #include "termchar.h"
34 #include "disptab.h"
35 #include "dispextern.h"
36 #include "blockinput.h"
37 #include "intervals.h"
38 #include "termhooks.h" /* For FRAME_TERMINAL. */
40 #ifdef HAVE_X_WINDOWS
41 #include "xterm.h"
42 #endif /* HAVE_X_WINDOWS */
43 #ifdef WINDOWSNT
44 #include "w32term.h"
45 #endif
46 #ifdef MSDOS
47 #include "msdos.h"
48 #endif
49 #ifdef HAVE_NS
50 #include "nsterm.h"
51 #endif
53 Lisp_Object Qwindowp, Qwindow_live_p;
54 static Lisp_Object Qwindow_configuration_p, Qrecord_window_buffer;
55 static Lisp_Object Qwindow_deletable_p, Qdelete_window, Qdisplay_buffer;
56 static Lisp_Object Qreplace_buffer_in_windows, Qget_mru_window;
57 static Lisp_Object Qwindow_resize_root_window, Qwindow_resize_root_window_vertically;
58 static Lisp_Object Qscroll_up, Qscroll_down, Qscroll_command;
59 static Lisp_Object Qsafe, Qabove, Qbelow;
60 static Lisp_Object Qauto_buffer_name;
62 static int displayed_window_lines (struct window *);
63 static struct window *decode_window (Lisp_Object);
64 static int count_windows (struct window *);
65 static int get_leaf_windows (struct window *, struct window **, int);
66 static void window_scroll (Lisp_Object, int, int, int);
67 static void window_scroll_pixel_based (Lisp_Object, int, int, int);
68 static void window_scroll_line_based (Lisp_Object, int, int, int);
69 static int freeze_window_start (struct window *, void *);
70 static Lisp_Object window_list (void);
71 static int add_window_to_list (struct window *, void *);
72 static int candidate_window_p (Lisp_Object, Lisp_Object, Lisp_Object,
73 Lisp_Object);
74 static Lisp_Object next_window (Lisp_Object, Lisp_Object,
75 Lisp_Object, int);
76 static void decode_next_window_args (Lisp_Object *, Lisp_Object *,
77 Lisp_Object *);
78 static void foreach_window (struct frame *,
79 int (* fn) (struct window *, void *),
80 void *);
81 static int foreach_window_1 (struct window *,
82 int (* fn) (struct window *, void *),
83 void *);
84 static Lisp_Object window_list_1 (Lisp_Object, Lisp_Object, Lisp_Object);
85 static int window_resize_check (struct window *, int);
86 static void window_resize_apply (struct window *, int);
87 static Lisp_Object select_window (Lisp_Object, Lisp_Object, int);
89 /* This is the window in which the terminal's cursor should
90 be left when nothing is being done with it. This must
91 always be a leaf window, and its buffer is selected by
92 the top level editing loop at the end of each command.
94 This value is always the same as
95 FRAME_SELECTED_WINDOW (selected_frame). */
96 Lisp_Object selected_window;
98 /* A list of all windows for use by next_window and Fwindow_list.
99 Functions creating or deleting windows should invalidate this cache
100 by setting it to nil. */
101 Lisp_Object Vwindow_list;
103 /* The mini-buffer window of the selected frame.
104 Note that you cannot test for mini-bufferness of an arbitrary window
105 by comparing against this; but you can test for mini-bufferness of
106 the selected window. */
107 Lisp_Object minibuf_window;
109 /* Non-nil means it is the window whose mode line should be
110 shown as the selected window when the minibuffer is selected. */
111 Lisp_Object minibuf_selected_window;
113 /* Hook run at end of temp_output_buffer_show. */
114 static Lisp_Object Qtemp_buffer_show_hook;
116 /* Incremented for each window created. */
117 static int sequence_number;
119 /* Nonzero after init_window_once has finished. */
120 static int window_initialized;
122 /* Hook to run when window config changes. */
123 static Lisp_Object Qwindow_configuration_change_hook;
125 /* Used by the function window_scroll_pixel_based */
126 static int window_scroll_pixel_based_preserve_x;
127 static int window_scroll_pixel_based_preserve_y;
129 /* Same for window_scroll_line_based. */
130 static int window_scroll_preserve_hpos;
131 static int window_scroll_preserve_vpos;
133 static struct window *
134 decode_window (register Lisp_Object window)
136 if (NILP (window))
137 return XWINDOW (selected_window);
139 CHECK_LIVE_WINDOW (window);
140 return XWINDOW (window);
143 static struct window *
144 decode_any_window (register Lisp_Object window)
146 if (NILP (window))
147 return XWINDOW (selected_window);
149 CHECK_WINDOW (window);
150 return XWINDOW (window);
153 DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0,
154 doc: /* Return t if OBJECT is a window and nil otherwise. */)
155 (Lisp_Object object)
157 return WINDOWP (object) ? Qt : Qnil;
160 DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0,
161 doc: /* Return t if OBJECT is a live window and nil otherwise.
162 A live window is a window that displays a buffer. */)
163 (Lisp_Object object)
165 return WINDOW_LIVE_P (object) ? Qt : Qnil;
168 /* Frames and windows. */
169 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
170 doc: /* Return the frame that window WINDOW is on.
171 WINDOW can be any window and defaults to the selected one. */)
172 (Lisp_Object window)
174 return decode_any_window (window)->frame;
177 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
178 doc: /* Return the root window of FRAME-OR-WINDOW.
179 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
180 Else if FRAME-OR-WINDOW denotes any window, return the root window of
181 that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
182 the root window of that frame. */)
183 (Lisp_Object frame_or_window)
185 Lisp_Object window;
187 if (NILP (frame_or_window))
188 window = SELECTED_FRAME ()->root_window;
189 else if (WINDOWP (frame_or_window))
190 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->root_window;
191 else
193 CHECK_LIVE_FRAME (frame_or_window);
194 window = XFRAME (frame_or_window)->root_window;
197 return window;
200 DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0,
201 doc: /* Return the window used now for minibuffers.
202 If the optional argument FRAME is specified, return the minibuffer window
203 used by that frame. */)
204 (Lisp_Object frame)
206 if (NILP (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 WINDOW can be any window and defaults to the selected one. */)
216 (Lisp_Object 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)
230 Lisp_Object 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;
236 else
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;
248 else
249 abort ();
252 return window;
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)
264 Lisp_Object 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;
270 else
272 CHECK_LIVE_FRAME (frame_or_window);
273 window = XFRAME (frame_or_window)->selected_window;
276 return 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.
286 Return WINDOW. */)
287 (Lisp_Object frame, Lisp_Object window, Lisp_Object norecord)
289 if (NILP (frame))
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);
300 else
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. */)
308 (void)
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. */
320 static Lisp_Object
321 select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
323 register struct window *w;
324 register struct window *ow;
325 struct frame *sf;
327 CHECK_LIVE_WINDOW (window);
329 w = XWINDOW (window);
330 w->frozen_window_start_p = 0;
332 if (NILP (norecord))
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)
340 return window;
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
349 frame is active. */
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));
353 return window;
355 else
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 EMACS_INT new_point = marker_position (w->pointm);
383 if (new_point < BEGV)
384 SET_PT (BEGV);
385 else if (new_point > ZV)
386 SET_PT (ZV);
387 else
388 SET_PT (new_point);
391 windows_or_buffers_changed++;
392 return window;
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
402 selected one.
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 that WINDOW is displaying.
413 WINDOW can be any window and defaults to the selected one.
414 If WINDOW is an internal window return nil. */)
415 (Lisp_Object window)
417 return decode_any_window (window)->buffer;
420 DEFUN ("window-parent", Fwindow_parent, Swindow_parent, 0, 1, 0,
421 doc: /* Return WINDOW's parent window.
422 WINDOW can be any window and defaults to the selected one.
423 Return nil if WINDOW has no parent. */)
424 (Lisp_Object window)
426 return decode_any_window (window)->parent;
429 DEFUN ("window-top-child", Fwindow_top_child, Swindow_top_child, 0, 1, 0,
430 doc: /* Return WINDOW's topmost child window.
431 WINDOW can be any window and defaults to the selected one.
432 Return nil if WINDOW is not a vertical combination. */)
433 (Lisp_Object window)
435 return decode_any_window (window)->vchild;
438 DEFUN ("window-left-child", Fwindow_left_child, Swindow_left_child, 0, 1, 0,
439 doc: /* Return WINDOW's leftmost child window.
440 WINDOW can be any window and defaults to the selected one.
441 Return nil if WINDOW is not a horizontal combination. */)
442 (Lisp_Object window)
444 return decode_any_window (window)->hchild;
447 DEFUN ("window-next-sibling", Fwindow_next_sibling, Swindow_next_sibling, 0, 1, 0,
448 doc: /* Return WINDOW's next sibling window.
449 WINDOW can be any window and defaults to the selected one.
450 Return nil if WINDOW has no next sibling. */)
451 (Lisp_Object window)
453 return decode_any_window (window)->next;
456 DEFUN ("window-prev-sibling", Fwindow_prev_sibling, Swindow_prev_sibling, 0, 1, 0,
457 doc: /* Return WINDOW's previous sibling window.
458 WINDOW can be any window and defaults to the selected one.
459 Return nil if WINDOW has no previous sibling. */)
460 (Lisp_Object window)
462 return decode_any_window (window)->prev;
465 DEFUN ("window-splits", Fwindow_splits, Swindow_splits, 0, 1, 0,
466 doc: /* Return splits status for WINDOW.
467 WINDOW can be any window and defaults to the selected one.
469 If the value returned by this function is nil and WINDOW is resized, the
470 corresponding space is preferably taken from (or given to) WINDOW's
471 right sibling. When WINDOW is deleted, its space is given to its left
472 sibling.
474 If the value returned by this function is non-nil, resizing and deleting
475 WINDOW may resize all windows in the same combination. */)
476 (Lisp_Object window)
478 return decode_any_window (window)->splits;
481 DEFUN ("set-window-splits", Fset_window_splits, Sset_window_splits, 2, 2, 0,
482 doc: /* Set splits status of WINDOW to STATUS.
483 WINDOW can be any window and defaults to the selected one. Return
484 STATUS.
486 If STATUS is nil and WINDOW is later resized, the corresponding space is
487 preferably taken from (or given to) WINDOW's right sibling. When WINDOW
488 is deleted, its space is given to its left sibling.
490 If STATUS is non-nil, resizing and deleting WINDOW may resize all
491 windows in the same combination. */)
492 (Lisp_Object window, Lisp_Object status)
494 register struct window *w = decode_any_window (window);
496 w->splits = status;
498 return w->splits;
501 DEFUN ("window-nest", Fwindow_nest, Swindow_nest, 0, 1, 0,
502 doc: /* Return nest status of WINDOW.
503 WINDOW can be any window and defaults to the selected one.
505 If the return value is nil, subwindows of WINDOW can be recombined with
506 WINDOW's siblings. A return value of non-nil means that subwindows of
507 WINDOW are never \(re-)combined with WINDOW's siblings. */)
508 (Lisp_Object window)
510 return decode_any_window (window)->nest;
513 DEFUN ("set-window-nest", Fset_window_nest, Sset_window_nest, 2, 2, 0,
514 doc: /* Set nest status of WINDOW to STATUS.
515 WINDOW can be any window and defaults to the selected one. Return
516 STATUS.
518 If STATUS is nil, subwindows of WINDOW can be recombined with WINDOW's
519 siblings. STATUS non-nil means that subwindows of WINDOW are never
520 \(re-)combined with WINDOW's siblings. */)
521 (Lisp_Object window, Lisp_Object status)
523 register struct window *w = decode_any_window (window);
525 w->nest = status;
527 return w->nest;
530 DEFUN ("window-use-time", Fwindow_use_time, Swindow_use_time, 0, 1, 0,
531 doc: /* Return WINDOW's use time.
532 WINDOW defaults to the selected window. The window with the highest use
533 time is the most recently selected one. The window with the lowest use
534 time is the least recently selected one. */)
535 (Lisp_Object window)
537 return decode_window (window)->use_time;
540 DEFUN ("window-total-size", Fwindow_total_size, Swindow_total_size, 0, 2, 0,
541 doc: /* Return the total number of lines of WINDOW.
542 WINDOW can be any window and defaults to the selected one. The return
543 value includes WINDOW's mode line and header line, if any. If WINDOW
544 is internal, the return value is the sum of the total number of lines
545 of WINDOW's child windows if these are vertically combined and the
546 height of WINDOW's first child otherwise.
548 Optional argument HORIZONTAL non-nil means return the total number of
549 columns of WINDOW. In this case the return value includes any vertical
550 dividers or scrollbars of WINDOW. If WINDOW is internal, the return
551 value is the sum of the total number of columns of WINDOW's child
552 windows if they are horizontally combined and the width of WINDOW's
553 first child otherwise. */)
554 (Lisp_Object window, Lisp_Object horizontal)
556 if (NILP (horizontal))
557 return decode_any_window (window)->total_lines;
558 else
559 return decode_any_window (window)->total_cols;
562 DEFUN ("window-new-total", Fwindow_new_total, Swindow_new_total, 0, 1, 0,
563 doc: /* Return new total size of WINDOW.
564 WINDOW defaults to the selected window. */)
565 (Lisp_Object window)
567 return decode_any_window (window)->new_total;
570 DEFUN ("window-normal-size", Fwindow_normal_size, Swindow_normal_size, 0, 2, 0,
571 doc: /* Return normal height of WINDOW.
572 WINDOW can be any window and defaults to the selected one. Optional
573 argument HORIZONTAL non-nil means return normal width of WINDOW. */)
574 (Lisp_Object window, Lisp_Object horizontal)
576 if (NILP (horizontal))
577 return decode_any_window (window)->normal_lines;
578 else
579 return decode_any_window (window)->normal_cols;
582 DEFUN ("window-new-normal", Fwindow_new_normal, Swindow_new_normal, 0, 1, 0,
583 doc: /* Return new normal size of WINDOW.
584 WINDOW can be any window and defaults to the selected one. */)
585 (Lisp_Object window)
587 return decode_any_window (window)->new_normal;
590 DEFUN ("window-left-column", Fwindow_left_column, Swindow_left_column, 0, 1, 0,
591 doc: /* Return left column of WINDOW.
592 WINDOW can be any window and defaults to the selected one. */)
593 (Lisp_Object window)
595 return decode_any_window (window)->left_col;
598 DEFUN ("window-top-line", Fwindow_top_line, Swindow_top_line, 0, 1, 0,
599 doc: /* Return top line of WINDOW.
600 WINDOW can be any window and defaults to the selected one. */)
601 (Lisp_Object window)
603 return decode_any_window (window)->top_line;
606 /* Return the number of lines of W's body. Don't count any mode or
607 header line of W. */
609 static int
610 window_body_lines (struct window *w)
612 int height = XFASTINT (w->total_lines);
614 if (!MINI_WINDOW_P (w))
616 if (WINDOW_WANTS_MODELINE_P (w))
617 --height;
618 if (WINDOW_WANTS_HEADER_LINE_P (w))
619 --height;
622 return height;
625 /* Return the number of columns of W's body. Don't count columns
626 occupied by the scroll bar or the vertical bar separating W from its
627 right sibling. On window-systems don't count fringes or display
628 margins either. */
631 window_body_cols (struct window *w)
633 struct frame *f = XFRAME (WINDOW_FRAME (w));
634 int width = XINT (w->total_cols);
636 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
637 /* Scroll bars occupy a few columns. */
638 width -= WINDOW_CONFIG_SCROLL_BAR_COLS (w);
639 else if (!FRAME_WINDOW_P (f)
640 && !WINDOW_RIGHTMOST_P (w) && !WINDOW_FULL_WIDTH_P (w))
641 /* The column of `|' characters separating side-by-side windows
642 occupies one column only. */
643 width -= 1;
645 if (FRAME_WINDOW_P (f))
646 /* On window-systems, fringes and display margins cannot be
647 used for normal text. */
648 width -= (WINDOW_FRINGE_COLS (w)
649 + WINDOW_LEFT_MARGIN_COLS (w)
650 + WINDOW_RIGHT_MARGIN_COLS (w));
652 return width;
655 DEFUN ("window-body-size", Fwindow_body_size, Swindow_body_size, 0, 2, 0,
656 doc: /* Return the number of lines or columns of WINDOW's body.
657 WINDOW must be a live window and defaults to the selected one.
659 If the optional argument HORIZONTAL is omitted or nil, the function
660 returns the number of WINDOW's lines, excluding the mode line and
661 header line, if any.
663 If HORIZONTAL is non-nil, the function returns the number of columns
664 excluding any vertical dividers or scroll bars owned by WINDOW. On a
665 window-system the return value also excludes the number of columns
666 used for WINDOW's fringes or display margins.
668 Note that the return value is measured in canonical units, i.e. for
669 the default frame's face. If the window shows some characters with
670 non-default face, e.g., if the font of some characters is larger or
671 smaller than the default font, the value returned by this function
672 will not match the actual number of lines or characters per line
673 shown in the window. To get the actual number of columns and lines,
674 use `posn-at-point'. */)
675 (Lisp_Object window, Lisp_Object horizontal)
677 struct window *w = decode_any_window (window);
679 if (NILP (horizontal))
680 return make_number (window_body_lines (w));
681 else
682 return make_number (window_body_cols (w));
685 DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0,
686 doc: /* Return the number of columns by which WINDOW is scrolled from left margin.
687 WINDOW must be a live window and defaults to the selected one. */)
688 (Lisp_Object window)
690 return decode_window (window)->hscroll;
693 DEFUN ("set-window-hscroll", Fset_window_hscroll, Sset_window_hscroll, 2, 2, 0,
694 doc: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
695 If WINDOW is nil, the selected window is used.
696 Return NCOL. NCOL should be zero or positive.
698 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
699 window so that the location of point moves off-window. */)
700 (Lisp_Object window, Lisp_Object ncol)
702 struct window *w = decode_window (window);
703 int hscroll;
705 CHECK_NUMBER (ncol);
706 hscroll = max (0, XINT (ncol));
708 /* Prevent redisplay shortcuts when changing the hscroll. */
709 if (XINT (w->hscroll) != hscroll)
710 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
712 w->hscroll = make_number (hscroll);
713 return ncol;
716 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger,
717 Swindow_redisplay_end_trigger, 0, 1, 0,
718 doc: /* Return WINDOW's redisplay end trigger value.
719 WINDOW defaults to the selected window.
720 See `set-window-redisplay-end-trigger' for more information. */)
721 (Lisp_Object window)
723 return decode_window (window)->redisplay_end_trigger;
726 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger,
727 Sset_window_redisplay_end_trigger, 2, 2, 0,
728 doc: /* Set WINDOW's redisplay end trigger value to VALUE.
729 VALUE should be a buffer position (typically a marker) or nil.
730 If it is a buffer position, then if redisplay in WINDOW reaches a position
731 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
732 with two arguments: WINDOW, and the end trigger value.
733 Afterwards the end-trigger value is reset to nil. */)
734 (register Lisp_Object window, Lisp_Object value)
736 register struct window *w;
738 w = decode_window (window);
739 w->redisplay_end_trigger = value;
740 return value;
743 DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0,
744 doc: /* Return a list of the edge coordinates of WINDOW.
745 The list has the form (LEFT TOP RIGHT BOTTOM).
746 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
747 all relative to 0, 0 at top left corner of frame.
749 RIGHT is one more than the rightmost column occupied by WINDOW.
750 BOTTOM is one more than the bottommost row occupied by WINDOW.
751 The edges include the space used by WINDOW's scroll bar, display
752 margins, fringes, header line, and/or mode line. For the edges of
753 just the text area, use `window-inside-edges'. */)
754 (Lisp_Object window)
756 register struct window *w = decode_any_window (window);
758 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w)),
759 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w)),
760 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w)),
761 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w)),
762 Qnil))));
765 DEFUN ("window-pixel-edges", Fwindow_pixel_edges, Swindow_pixel_edges, 0, 1, 0,
766 doc: /* Return a list of the edge pixel coordinates of WINDOW.
767 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
768 the top left corner of the frame.
770 RIGHT is one more than the rightmost x position occupied by WINDOW.
771 BOTTOM is one more than the bottommost y position occupied by WINDOW.
772 The pixel edges include the space used by WINDOW's scroll bar, display
773 margins, fringes, header line, and/or mode line. For the pixel edges
774 of just the text area, use `window-inside-pixel-edges'. */)
775 (Lisp_Object window)
777 register struct window *w = decode_any_window (window);
779 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w)),
780 Fcons (make_number (WINDOW_TOP_EDGE_Y (w)),
781 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w)),
782 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w)),
783 Qnil))));
786 static void
787 calc_absolute_offset (struct window *w, int *add_x, int *add_y)
789 struct frame *f = XFRAME (w->frame);
790 *add_y = f->top_pos;
791 #ifdef FRAME_MENUBAR_HEIGHT
792 *add_y += FRAME_MENUBAR_HEIGHT (f);
793 #endif
794 #ifdef FRAME_TOOLBAR_TOP_HEIGHT
795 *add_y += FRAME_TOOLBAR_TOP_HEIGHT (f);
796 #elif FRAME_TOOLBAR_HEIGHT
797 *add_y += FRAME_TOOLBAR_HEIGHT (f);
798 #endif
799 #ifdef FRAME_NS_TITLEBAR_HEIGHT
800 *add_y += FRAME_NS_TITLEBAR_HEIGHT (f);
801 #endif
802 *add_x = f->left_pos;
803 #ifdef FRAME_TOOLBAR_LEFT_WIDTH
804 *add_x += FRAME_TOOLBAR_LEFT_WIDTH (f);
805 #endif
808 DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges,
809 Swindow_absolute_pixel_edges, 0, 1, 0,
810 doc: /* Return a list of the edge pixel coordinates of WINDOW.
811 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
812 the top left corner of the display.
814 RIGHT is one more than the rightmost x position occupied by WINDOW.
815 BOTTOM is one more than the bottommost y position occupied by WINDOW.
816 The pixel edges include the space used by WINDOW's scroll bar, display
817 margins, fringes, header line, and/or mode line. For the pixel edges
818 of just the text area, use `window-inside-absolute-pixel-edges'. */)
819 (Lisp_Object window)
821 register struct window *w = decode_any_window (window);
822 int add_x, add_y;
823 calc_absolute_offset (w, &add_x, &add_y);
825 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w) + add_x),
826 Fcons (make_number (WINDOW_TOP_EDGE_Y (w) + add_y),
827 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w) + add_x),
828 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w) + add_y),
829 Qnil))));
832 DEFUN ("window-inside-edges", Fwindow_inside_edges, Swindow_inside_edges, 0, 1, 0,
833 doc: /* Return a list of the edge coordinates of WINDOW.
834 The list has the form (LEFT TOP RIGHT BOTTOM).
835 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
836 all relative to 0, 0 at top left corner of frame.
838 RIGHT is one more than the rightmost column of WINDOW's text area.
839 BOTTOM is one more than the bottommost row of WINDOW's text area.
840 The inside edges do not include the space used by the WINDOW's scroll
841 bar, display margins, fringes, header line, and/or mode line. */)
842 (Lisp_Object window)
844 register struct window *w = decode_any_window (window);
846 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w)
847 + WINDOW_LEFT_MARGIN_COLS (w)
848 + WINDOW_LEFT_FRINGE_COLS (w)),
849 make_number (WINDOW_TOP_EDGE_LINE (w)
850 + WINDOW_HEADER_LINE_LINES (w)),
851 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w)
852 - WINDOW_RIGHT_MARGIN_COLS (w)
853 - WINDOW_RIGHT_FRINGE_COLS (w)),
854 make_number (WINDOW_BOTTOM_EDGE_LINE (w)
855 - WINDOW_MODE_LINE_LINES (w)));
858 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges, Swindow_inside_pixel_edges, 0, 1, 0,
859 doc: /* Return a list of the edge pixel coordinates of WINDOW.
860 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
861 the top left corner of the frame.
863 RIGHT is one more than the rightmost x position of WINDOW's text area.
864 BOTTOM is one more than the bottommost y position of WINDOW's text area.
865 The inside edges do not include the space used by WINDOW's scroll bar,
866 display margins, fringes, header line, and/or mode line. */)
867 (Lisp_Object window)
869 register struct window *w = decode_any_window (window);
871 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w)
872 + WINDOW_LEFT_MARGIN_WIDTH (w)
873 + WINDOW_LEFT_FRINGE_WIDTH (w)),
874 make_number (WINDOW_TOP_EDGE_Y (w)
875 + WINDOW_HEADER_LINE_HEIGHT (w)),
876 make_number (WINDOW_BOX_RIGHT_EDGE_X (w)
877 - WINDOW_RIGHT_MARGIN_WIDTH (w)
878 - WINDOW_RIGHT_FRINGE_WIDTH (w)),
879 make_number (WINDOW_BOTTOM_EDGE_Y (w)
880 - WINDOW_MODE_LINE_HEIGHT (w)));
883 DEFUN ("window-inside-absolute-pixel-edges",
884 Fwindow_inside_absolute_pixel_edges,
885 Swindow_inside_absolute_pixel_edges, 0, 1, 0,
886 doc: /* Return a list of the edge pixel coordinates of WINDOW.
887 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
888 the top left corner of the display.
890 RIGHT is one more than the rightmost x position of WINDOW's text area.
891 BOTTOM is one more than the bottommost y position of WINDOW's text area.
892 The inside edges do not include the space used by WINDOW's scroll bar,
893 display margins, fringes, header line, and/or mode line. */)
894 (Lisp_Object window)
896 register struct window *w = decode_any_window (window);
897 int add_x, add_y;
898 calc_absolute_offset (w, &add_x, &add_y);
900 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w)
901 + WINDOW_LEFT_MARGIN_WIDTH (w)
902 + WINDOW_LEFT_FRINGE_WIDTH (w) + add_x),
903 make_number (WINDOW_TOP_EDGE_Y (w)
904 + WINDOW_HEADER_LINE_HEIGHT (w) + add_y),
905 make_number (WINDOW_BOX_RIGHT_EDGE_X (w)
906 - WINDOW_RIGHT_MARGIN_WIDTH (w)
907 - WINDOW_RIGHT_FRINGE_WIDTH (w) + add_x),
908 make_number (WINDOW_BOTTOM_EDGE_Y (w)
909 - WINDOW_MODE_LINE_HEIGHT (w) + add_y));
912 /* Test if the character at column X, row Y is within window W.
913 If it is not, return ON_NOTHING;
914 if it is in the window's text area, return ON_TEXT;
915 if it is on the window's modeline, return ON_MODE_LINE;
916 if it is on the border between the window and its right sibling,
917 return ON_VERTICAL_BORDER.
918 if it is on a scroll bar, return ON_SCROLL_BAR.
919 if it is on the window's top line, return ON_HEADER_LINE;
920 if it is in left or right fringe of the window,
921 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
922 if it is in the marginal area to the left/right of the window,
923 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN.
925 X and Y are frame relative pixel coordinates. */
927 static enum window_part
928 coordinates_in_window (register struct window *w, int x, int y)
930 struct frame *f = XFRAME (WINDOW_FRAME (w));
931 enum window_part part;
932 int ux = FRAME_COLUMN_WIDTH (f);
933 int left_x = WINDOW_LEFT_EDGE_X (w);
934 int right_x = WINDOW_RIGHT_EDGE_X (w);
935 int top_y = WINDOW_TOP_EDGE_Y (w);
936 int bottom_y = WINDOW_BOTTOM_EDGE_Y (w);
937 /* The width of the area where the vertical line can be dragged.
938 (Between mode lines for instance. */
939 int grabbable_width = ux;
940 int lmargin_width, rmargin_width, text_left, text_right;
942 /* Outside any interesting row or column? */
943 if (y < top_y || y >= bottom_y || x < left_x || x >= right_x)
944 return ON_NOTHING;
946 /* On the mode line or header line? */
947 if ((WINDOW_WANTS_MODELINE_P (w)
948 && y >= bottom_y - CURRENT_MODE_LINE_HEIGHT (w)
949 && (part = ON_MODE_LINE))
950 || (WINDOW_WANTS_HEADER_LINE_P (w)
951 && y < top_y + CURRENT_HEADER_LINE_HEIGHT (w)
952 && (part = ON_HEADER_LINE)))
954 /* If it's under/over the scroll bar portion of the mode/header
955 line, say it's on the vertical line. That's to be able to
956 resize windows horizontally in case we're using toolkit scroll
957 bars. Note: If scrollbars are on the left, the window that
958 must be eventually resized is that on the left of WINDOW. */
959 if ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)
960 && !WINDOW_LEFTMOST_P (w)
961 && eabs (x - left_x) < grabbable_width)
962 || (!WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)
963 && !WINDOW_RIGHTMOST_P (w)
964 && eabs (x - right_x) < grabbable_width))
965 return ON_VERTICAL_BORDER;
966 else
967 return part;
970 /* In what's below, we subtract 1 when computing right_x because we
971 want the rightmost pixel, which is given by left_pixel+width-1. */
972 if (w->pseudo_window_p)
974 left_x = 0;
975 right_x = WINDOW_TOTAL_WIDTH (w) - 1;
977 else
979 left_x = WINDOW_BOX_LEFT_EDGE_X (w);
980 right_x = WINDOW_BOX_RIGHT_EDGE_X (w) - 1;
983 /* Outside any interesting column? */
984 if (x < left_x || x > right_x)
985 return ON_SCROLL_BAR;
987 lmargin_width = window_box_width (w, LEFT_MARGIN_AREA);
988 rmargin_width = window_box_width (w, RIGHT_MARGIN_AREA);
990 text_left = window_box_left (w, TEXT_AREA);
991 text_right = text_left + window_box_width (w, TEXT_AREA);
993 if (FRAME_WINDOW_P (f))
995 if (!w->pseudo_window_p
996 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w)
997 && !WINDOW_RIGHTMOST_P (w)
998 && (eabs (x - right_x) < grabbable_width))
999 return ON_VERTICAL_BORDER;
1001 /* Need to say "x > right_x" rather than >=, since on character
1002 terminals, the vertical line's x coordinate is right_x. */
1003 else if (!w->pseudo_window_p
1004 && !WINDOW_RIGHTMOST_P (w)
1005 && x > right_x - ux)
1006 return ON_VERTICAL_BORDER;
1008 if (x < text_left)
1010 if (lmargin_width > 0
1011 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
1012 ? (x >= left_x + WINDOW_LEFT_FRINGE_WIDTH (w))
1013 : (x < left_x + lmargin_width)))
1014 return ON_LEFT_MARGIN;
1016 return ON_LEFT_FRINGE;
1019 if (x >= text_right)
1021 if (rmargin_width > 0
1022 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
1023 ? (x < right_x - WINDOW_RIGHT_FRINGE_WIDTH (w))
1024 : (x >= right_x - rmargin_width)))
1025 return ON_RIGHT_MARGIN;
1027 return ON_RIGHT_FRINGE;
1030 /* Everything special ruled out - must be on text area */
1031 return ON_TEXT;
1034 /* Take X is the frame-relative pixel x-coordinate, and return the
1035 x-coordinate relative to part PART of window W. */
1037 window_relative_x_coord (struct window *w, enum window_part part, int x)
1039 int left_x = (w->pseudo_window_p) ? 0 : WINDOW_BOX_LEFT_EDGE_X (w);
1041 switch (part)
1043 case ON_TEXT:
1044 return x - window_box_left (w, TEXT_AREA);
1046 case ON_LEFT_FRINGE:
1047 return x - left_x;
1049 case ON_RIGHT_FRINGE:
1050 return x - left_x - WINDOW_LEFT_FRINGE_WIDTH (w);
1052 case ON_LEFT_MARGIN:
1053 return (x - left_x
1054 - ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
1055 ? WINDOW_LEFT_FRINGE_WIDTH (w) : 0));
1057 case ON_RIGHT_MARGIN:
1058 return (x + 1
1059 - ((w->pseudo_window_p)
1060 ? WINDOW_TOTAL_WIDTH (w)
1061 : WINDOW_BOX_RIGHT_EDGE_X (w))
1062 + window_box_width (w, RIGHT_MARGIN_AREA)
1063 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
1064 ? WINDOW_RIGHT_FRINGE_WIDTH (w) : 0));
1067 /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */
1068 return 0;
1072 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
1073 Scoordinates_in_window_p, 2, 2, 0,
1074 doc: /* Return non-nil if COORDINATES are in WINDOW.
1075 COORDINATES is a cons of the form (X . Y), X and Y being distances
1076 measured in characters from the upper-left corner of the frame.
1077 \(0 . 0) denotes the character in the upper left corner of the
1078 frame.
1079 If COORDINATES are in the text portion of WINDOW,
1080 the coordinates relative to the window are returned.
1081 If they are in the mode line of WINDOW, `mode-line' is returned.
1082 If they are in the top mode line of WINDOW, `header-line' is returned.
1083 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1084 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1085 If they are on the border between WINDOW and its right sibling,
1086 `vertical-line' is returned.
1087 If they are in the windows's left or right marginal areas, `left-margin'\n\
1088 or `right-margin' is returned. */)
1089 (register Lisp_Object coordinates, Lisp_Object window)
1091 struct window *w;
1092 struct frame *f;
1093 int x, y;
1094 Lisp_Object lx, ly;
1096 CHECK_WINDOW (window);
1097 w = XWINDOW (window);
1098 f = XFRAME (w->frame);
1099 CHECK_CONS (coordinates);
1100 lx = Fcar (coordinates);
1101 ly = Fcdr (coordinates);
1102 CHECK_NUMBER_OR_FLOAT (lx);
1103 CHECK_NUMBER_OR_FLOAT (ly);
1104 x = FRAME_PIXEL_X_FROM_CANON_X (f, lx) + FRAME_INTERNAL_BORDER_WIDTH (f);
1105 y = FRAME_PIXEL_Y_FROM_CANON_Y (f, ly) + FRAME_INTERNAL_BORDER_WIDTH (f);
1107 switch (coordinates_in_window (w, x, y))
1109 case ON_NOTHING:
1110 return Qnil;
1112 case ON_TEXT:
1113 /* Convert X and Y to window relative pixel coordinates, and
1114 return the canonical char units. */
1115 x -= window_box_left (w, TEXT_AREA);
1116 y -= WINDOW_TOP_EDGE_Y (w);
1117 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f, x),
1118 FRAME_CANON_Y_FROM_PIXEL_Y (f, y));
1120 case ON_MODE_LINE:
1121 return Qmode_line;
1123 case ON_VERTICAL_BORDER:
1124 return Qvertical_line;
1126 case ON_HEADER_LINE:
1127 return Qheader_line;
1129 case ON_LEFT_FRINGE:
1130 return Qleft_fringe;
1132 case ON_RIGHT_FRINGE:
1133 return Qright_fringe;
1135 case ON_LEFT_MARGIN:
1136 return Qleft_margin;
1138 case ON_RIGHT_MARGIN:
1139 return Qright_margin;
1141 case ON_SCROLL_BAR:
1142 /* Historically we are supposed to return nil in this case. */
1143 return Qnil;
1145 default:
1146 abort ();
1151 /* Callback for foreach_window, used in window_from_coordinates.
1152 Check if window W contains coordinates specified by USER_DATA which
1153 is actually a pointer to a struct check_window_data CW.
1155 Check if window W contains coordinates *CW->x and *CW->y. If it
1156 does, return W in *CW->window, as Lisp_Object, and return in
1157 *CW->part the part of the window under coordinates *X,*Y. Return
1158 zero from this function to stop iterating over windows. */
1160 struct check_window_data
1162 Lisp_Object *window;
1163 int x, y;
1164 enum window_part *part;
1167 static int
1168 check_window_containing (struct window *w, void *user_data)
1170 struct check_window_data *cw = (struct check_window_data *) user_data;
1171 enum window_part found;
1172 int continue_p = 1;
1174 found = coordinates_in_window (w, cw->x, cw->y);
1175 if (found != ON_NOTHING)
1177 *cw->part = found;
1178 XSETWINDOW (*cw->window, w);
1179 continue_p = 0;
1182 return continue_p;
1186 /* Find the window containing frame-relative pixel position X/Y and
1187 return it as a Lisp_Object.
1189 If X, Y is on one of the window's special `window_part' elements,
1190 set *PART to the id of that element.
1192 If there is no window under X, Y return nil and leave *PART
1193 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1195 This function was previously implemented with a loop cycling over
1196 windows with Fnext_window, and starting with the frame's selected
1197 window. It turned out that this doesn't work with an
1198 implementation of next_window using Vwindow_list, because
1199 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1200 tree of F when this function is called asynchronously from
1201 note_mouse_highlight. The original loop didn't terminate in this
1202 case. */
1204 Lisp_Object
1205 window_from_coordinates (struct frame *f, int x, int y,
1206 enum window_part *part, int tool_bar_p)
1208 Lisp_Object window;
1209 struct check_window_data cw;
1210 enum window_part dummy;
1212 if (part == 0)
1213 part = &dummy;
1215 window = Qnil;
1216 cw.window = &window, cw.x = x, cw.y = y; cw.part = part;
1217 foreach_window (f, check_window_containing, &cw);
1219 /* If not found above, see if it's in the tool bar window, if a tool
1220 bar exists. */
1221 if (NILP (window)
1222 && tool_bar_p
1223 && WINDOWP (f->tool_bar_window)
1224 && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window)) > 0
1225 && (coordinates_in_window (XWINDOW (f->tool_bar_window), x, y)
1226 != ON_NOTHING))
1228 *part = ON_TEXT;
1229 window = f->tool_bar_window;
1232 return window;
1235 DEFUN ("window-at", Fwindow_at, Swindow_at, 2, 3, 0,
1236 doc: /* Return window containing coordinates X and Y on FRAME.
1237 FRAME must be a live frame and defaults to the selected one.
1238 The top left corner of the frame is considered to be row 0,
1239 column 0. */)
1240 (Lisp_Object x, Lisp_Object y, Lisp_Object frame)
1242 struct frame *f;
1244 if (NILP (frame))
1245 frame = selected_frame;
1246 CHECK_LIVE_FRAME (frame);
1247 f = XFRAME (frame);
1249 /* Check that arguments are integers or floats. */
1250 CHECK_NUMBER_OR_FLOAT (x);
1251 CHECK_NUMBER_OR_FLOAT (y);
1253 return window_from_coordinates (f,
1254 (FRAME_PIXEL_X_FROM_CANON_X (f, x)
1255 + FRAME_INTERNAL_BORDER_WIDTH (f)),
1256 (FRAME_PIXEL_Y_FROM_CANON_Y (f, y)
1257 + FRAME_INTERNAL_BORDER_WIDTH (f)),
1258 0, 0);
1261 DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0,
1262 doc: /* Return current value of point in WINDOW.
1263 WINDOW must be a live window and defaults to the selected one.
1265 For a nonselected window, this is the value point would have
1266 if that window were selected.
1268 Note that, when WINDOW is the selected window and its buffer
1269 is also currently selected, the value returned is the same as (point).
1270 It would be more strictly correct to return the `top-level' value
1271 of point, outside of any save-excursion forms.
1272 But that is hard to define. */)
1273 (Lisp_Object window)
1275 register struct window *w = decode_window (window);
1277 if (w == XWINDOW (selected_window)
1278 && current_buffer == XBUFFER (w->buffer))
1279 return Fpoint ();
1280 return Fmarker_position (w->pointm);
1283 DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0,
1284 doc: /* Return position at which display currently starts in WINDOW.
1285 WINDOW must be a live window and defaults to the selected one.
1286 This is updated by redisplay or by calling `set-window-start'. */)
1287 (Lisp_Object window)
1289 return Fmarker_position (decode_window (window)->start);
1292 /* This is text temporarily removed from the doc string below.
1294 This function returns nil if the position is not currently known.
1295 That happens when redisplay is preempted and doesn't finish.
1296 If in that case you want to compute where the end of the window would
1297 have been if redisplay had finished, do this:
1298 (save-excursion
1299 (goto-char (window-start window))
1300 (vertical-motion (1- (window-height window)) window)
1301 (point))") */
1303 DEFUN ("window-end", Fwindow_end, Swindow_end, 0, 2, 0,
1304 doc: /* Return position at which display currently ends in WINDOW.
1305 WINDOW must be a live window and defaults to the selected one.
1306 This is updated by redisplay, when it runs to completion.
1307 Simply changing the buffer text or setting `window-start'
1308 does not update this value.
1309 Return nil if there is no recorded value. (This can happen if the
1310 last redisplay of WINDOW was preempted, and did not finish.)
1311 If UPDATE is non-nil, compute the up-to-date position
1312 if it isn't already recorded. */)
1313 (Lisp_Object window, Lisp_Object update)
1315 Lisp_Object value;
1316 struct window *w = decode_window (window);
1317 Lisp_Object buf;
1318 struct buffer *b;
1320 buf = w->buffer;
1321 CHECK_BUFFER (buf);
1322 b = XBUFFER (buf);
1324 #if 0 /* This change broke some things. We should make it later. */
1325 /* If we don't know the end position, return nil.
1326 The user can compute it with vertical-motion if he wants to.
1327 It would be nicer to do it automatically,
1328 but that's so slow that it would probably bother people. */
1329 if (NILP (w->window_end_valid))
1330 return Qnil;
1331 #endif
1333 if (! NILP (update)
1334 && ! (! NILP (w->window_end_valid)
1335 && XFASTINT (w->last_modified) >= BUF_MODIFF (b)
1336 && XFASTINT (w->last_overlay_modified) >= BUF_OVERLAY_MODIFF (b))
1337 && !noninteractive)
1339 struct text_pos startp;
1340 struct it it;
1341 struct buffer *old_buffer = NULL;
1342 void *itdata = NULL;
1344 /* Cannot use Fvertical_motion because that function doesn't
1345 cope with variable-height lines. */
1346 if (b != current_buffer)
1348 old_buffer = current_buffer;
1349 set_buffer_internal (b);
1352 /* In case W->start is out of the range, use something
1353 reasonable. This situation occurred when loading a file with
1354 `-l' containing a call to `rmail' with subsequent other
1355 commands. At the end, W->start happened to be BEG, while
1356 rmail had already narrowed the buffer. */
1357 if (XMARKER (w->start)->charpos < BEGV)
1358 SET_TEXT_POS (startp, BEGV, BEGV_BYTE);
1359 else if (XMARKER (w->start)->charpos > ZV)
1360 SET_TEXT_POS (startp, ZV, ZV_BYTE);
1361 else
1362 SET_TEXT_POS_FROM_MARKER (startp, w->start);
1364 itdata = bidi_shelve_cache ();
1365 start_display (&it, w, startp);
1366 move_it_vertically (&it, window_box_height (w));
1367 if (it.current_y < it.last_visible_y)
1368 move_it_past_eol (&it);
1369 value = make_number (IT_CHARPOS (it));
1370 bidi_unshelve_cache (itdata, 0);
1372 if (old_buffer)
1373 set_buffer_internal (old_buffer);
1375 else
1376 XSETINT (value, BUF_Z (b) - XFASTINT (w->window_end_pos));
1378 return value;
1381 DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0,
1382 doc: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1383 Return POS. */)
1384 (Lisp_Object window, Lisp_Object pos)
1386 register struct window *w = decode_window (window);
1388 CHECK_NUMBER_COERCE_MARKER (pos);
1389 if (w == XWINDOW (selected_window)
1390 && XBUFFER (w->buffer) == current_buffer)
1391 Fgoto_char (pos);
1392 else
1393 set_marker_restricted (w->pointm, pos, w->buffer);
1395 /* We have to make sure that redisplay updates the window to show
1396 the new value of point. */
1397 if (!EQ (window, selected_window))
1398 ++windows_or_buffers_changed;
1400 return pos;
1403 DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0,
1404 doc: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1405 If WINDOW is nil, the selected window is used. Return POS.
1406 Optional third arg NOFORCE non-nil inhibits next redisplay from
1407 overriding motion of point in order to display at this exact start. */)
1408 (Lisp_Object window, Lisp_Object pos, Lisp_Object noforce)
1410 register struct window *w = decode_window (window);
1412 CHECK_NUMBER_COERCE_MARKER (pos);
1413 set_marker_restricted (w->start, pos, w->buffer);
1414 /* this is not right, but much easier than doing what is right. */
1415 w->start_at_line_beg = Qnil;
1416 if (NILP (noforce))
1417 w->force_start = Qt;
1418 w->update_mode_line = Qt;
1419 XSETFASTINT (w->last_modified, 0);
1420 XSETFASTINT (w->last_overlay_modified, 0);
1421 if (!EQ (window, selected_window))
1422 windows_or_buffers_changed++;
1424 return pos;
1427 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p,
1428 Spos_visible_in_window_p, 0, 3, 0,
1429 doc: /* Return non-nil if position POS is currently on the frame in WINDOW.
1430 Return nil if that position is scrolled vertically out of view.
1431 If a character is only partially visible, nil is returned, unless the
1432 optional argument PARTIALLY is non-nil.
1433 If POS is only out of view because of horizontal scrolling, return non-nil.
1434 If POS is t, it specifies the position of the last visible glyph in WINDOW.
1435 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
1437 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1438 return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
1439 where X and Y are the pixel coordinates relative to the top left corner
1440 of the window. The remaining elements are omitted if the character after
1441 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1442 off-window at the top and bottom of the row, ROWH is the height of the
1443 display row, and VPOS is the row number (0-based) containing POS. */)
1444 (Lisp_Object pos, Lisp_Object window, Lisp_Object partially)
1446 register struct window *w;
1447 register EMACS_INT posint;
1448 register struct buffer *buf;
1449 struct text_pos top;
1450 Lisp_Object in_window = Qnil;
1451 int rtop, rbot, rowh, vpos, fully_p = 1;
1452 int x, y;
1454 w = decode_window (window);
1455 buf = XBUFFER (w->buffer);
1456 SET_TEXT_POS_FROM_MARKER (top, w->start);
1458 if (EQ (pos, Qt))
1459 posint = -1;
1460 else if (!NILP (pos))
1462 CHECK_NUMBER_COERCE_MARKER (pos);
1463 posint = XINT (pos);
1465 else if (w == XWINDOW (selected_window))
1466 posint = PT;
1467 else
1468 posint = XMARKER (w->pointm)->charpos;
1470 /* If position is above window start or outside buffer boundaries,
1471 or if window start is out of range, position is not visible. */
1472 if ((EQ (pos, Qt)
1473 || (posint >= CHARPOS (top) && posint <= BUF_ZV (buf)))
1474 && CHARPOS (top) >= BUF_BEGV (buf)
1475 && CHARPOS (top) <= BUF_ZV (buf)
1476 && pos_visible_p (w, posint, &x, &y, &rtop, &rbot, &rowh, &vpos)
1477 && (fully_p = !rtop && !rbot, (!NILP (partially) || fully_p)))
1478 in_window = Qt;
1480 if (!NILP (in_window) && !NILP (partially))
1482 Lisp_Object part = Qnil;
1483 if (!fully_p)
1484 part = list4 (make_number (rtop), make_number (rbot),
1485 make_number (rowh), make_number (vpos));
1486 in_window = Fcons (make_number (x),
1487 Fcons (make_number (y), part));
1490 return in_window;
1493 DEFUN ("window-line-height", Fwindow_line_height,
1494 Swindow_line_height, 0, 2, 0,
1495 doc: /* Return height in pixels of text line LINE in window WINDOW.
1496 WINDOW defaults to the selected window.
1498 Return height of current line if LINE is omitted or nil. Return height of
1499 header or mode line if LINE is `header-line' or `mode-line'.
1500 Otherwise, LINE is a text line number starting from 0. A negative number
1501 counts from the end of the window.
1503 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
1504 in pixels of the visible part of the line, VPOS and YPOS are the
1505 vertical position in lines and pixels of the line, relative to the top
1506 of the first text line, and OFFBOT is the number of off-window pixels at
1507 the bottom of the text line. If there are off-window pixels at the top
1508 of the (first) text line, YPOS is negative.
1510 Return nil if window display is not up-to-date. In that case, use
1511 `pos-visible-in-window-p' to obtain the information. */)
1512 (Lisp_Object line, Lisp_Object window)
1514 register struct window *w;
1515 register struct buffer *b;
1516 struct glyph_row *row, *end_row;
1517 int max_y, crop, i, n;
1519 w = decode_window (window);
1521 if (noninteractive || w->pseudo_window_p)
1522 return Qnil;
1524 CHECK_BUFFER (w->buffer);
1525 b = XBUFFER (w->buffer);
1527 /* Fail if current matrix is not up-to-date. */
1528 if (NILP (w->window_end_valid)
1529 || current_buffer->clip_changed
1530 || current_buffer->prevent_redisplay_optimizations_p
1531 || XFASTINT (w->last_modified) < BUF_MODIFF (b)
1532 || XFASTINT (w->last_overlay_modified) < BUF_OVERLAY_MODIFF (b))
1533 return Qnil;
1535 if (NILP (line))
1537 i = w->cursor.vpos;
1538 if (i < 0 || i >= w->current_matrix->nrows
1539 || (row = MATRIX_ROW (w->current_matrix, i), !row->enabled_p))
1540 return Qnil;
1541 max_y = window_text_bottom_y (w);
1542 goto found_row;
1545 if (EQ (line, Qheader_line))
1547 if (!WINDOW_WANTS_HEADER_LINE_P (w))
1548 return Qnil;
1549 row = MATRIX_HEADER_LINE_ROW (w->current_matrix);
1550 if (!row->enabled_p)
1551 return Qnil;
1552 return list4 (make_number (row->height),
1553 make_number (0), make_number (0),
1554 make_number (0));
1557 if (EQ (line, Qmode_line))
1559 row = MATRIX_MODE_LINE_ROW (w->current_matrix);
1560 if (!row->enabled_p)
1561 return Qnil;
1562 return list4 (make_number (row->height),
1563 make_number (0), /* not accurate */
1564 make_number (WINDOW_HEADER_LINE_HEIGHT (w)
1565 + window_text_bottom_y (w)),
1566 make_number (0));
1569 CHECK_NUMBER (line);
1570 n = XINT (line);
1572 row = MATRIX_FIRST_TEXT_ROW (w->current_matrix);
1573 end_row = MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w);
1574 max_y = window_text_bottom_y (w);
1575 i = 0;
1577 while ((n < 0 || i < n)
1578 && row <= end_row && row->enabled_p
1579 && row->y + row->height < max_y)
1580 row++, i++;
1582 if (row > end_row || !row->enabled_p)
1583 return Qnil;
1585 if (++n < 0)
1587 if (-n > i)
1588 return Qnil;
1589 row += n;
1590 i += n;
1593 found_row:
1594 crop = max (0, (row->y + row->height) - max_y);
1595 return list4 (make_number (row->height + min (0, row->y) - crop),
1596 make_number (i),
1597 make_number (row->y),
1598 make_number (crop));
1601 DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p,
1602 0, 1, 0,
1603 doc: /* Return non-nil when WINDOW is dedicated to its buffer.
1604 More precisely, return the value assigned by the last call of
1605 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1606 never called with WINDOW as its argument, or the value set by that
1607 function was internally reset since its last call. WINDOW defaults to
1608 the selected window.
1610 When a window is dedicated to its buffer, `display-buffer' will refrain
1611 from displaying another buffer in it. `get-lru-window' and
1612 `get-largest-window' treat dedicated windows specially.
1613 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1614 `kill-buffer' can delete a dedicated window and the containing frame.
1616 Functions like `set-window-buffer' may change the buffer displayed by a
1617 window, unless that window is "strongly" dedicated to its buffer, that
1618 is the value returned by `window-dedicated-p' is t. */)
1619 (Lisp_Object window)
1621 return decode_window (window)->dedicated;
1624 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p,
1625 Sset_window_dedicated_p, 2, 2, 0,
1626 doc: /* Mark WINDOW as dedicated according to FLAG.
1627 WINDOW must be a live window and defaults to the selected one. FLAG
1628 non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means
1629 mark WINDOW as non-dedicated. Return FLAG.
1631 When a window is dedicated to its buffer, `display-buffer' will refrain
1632 from displaying another buffer in it. `get-lru-window' and
1633 `get-largest-window' treat dedicated windows specially.
1634 `delete-windows-on', `replace-buffer-in-windows', `quit-window',
1635 `quit-restore-window' and `kill-buffer' can delete a dedicated window
1636 and the containing frame.
1638 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
1639 its buffer. Functions like `set-window-buffer' may change the buffer
1640 displayed by a window, unless that window is strongly dedicated to its
1641 buffer. If and when `set-window-buffer' displays another buffer in a
1642 window, it also makes sure that the window is no more dedicated. */)
1643 (Lisp_Object window, Lisp_Object flag)
1645 register struct window *w = decode_window (window);
1647 w->dedicated = flag;
1648 return w->dedicated;
1651 DEFUN ("window-prev-buffers", Fwindow_prev_buffers, Swindow_prev_buffers,
1652 0, 1, 0,
1653 doc: /* Return buffers previously shown in WINDOW.
1654 WINDOW must be a live window and defaults to the selected one.
1656 The return value is a list of elements (BUFFER WINDOW-START POS),
1657 where BUFFER is a buffer, WINDOW-START is the start position of the
1658 window for that buffer, and POS is a window-specific point value. */)
1659 (Lisp_Object window)
1661 return decode_window (window)->prev_buffers;
1664 DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers,
1665 Sset_window_prev_buffers, 2, 2, 0,
1666 doc: /* Set WINDOW's previous buffers to PREV-BUFFERS.
1667 WINDOW must be a live window and defaults to the selected one.
1669 PREV-BUFFERS should be a list of elements (BUFFER WINDOW-START POS),
1670 where BUFFER is a buffer, WINDOW-START is the start position of the
1671 window for that buffer, and POS is a window-specific point value. */)
1672 (Lisp_Object window, Lisp_Object prev_buffers)
1674 return decode_window (window)->prev_buffers = prev_buffers;
1677 DEFUN ("window-next-buffers", Fwindow_next_buffers, Swindow_next_buffers,
1678 0, 1, 0,
1679 doc: /* Return list of buffers recently re-shown in WINDOW.
1680 WINDOW must be a live window and defaults to the selected one. */)
1681 (Lisp_Object window)
1683 return decode_window (window)->next_buffers;
1686 DEFUN ("set-window-next-buffers", Fset_window_next_buffers,
1687 Sset_window_next_buffers, 2, 2, 0,
1688 doc: /* Set WINDOW's next buffers to NEXT-BUFFERS.
1689 WINDOW must be a live window and defaults to the selected one.
1690 NEXT-BUFFERS should be a list of buffers. */)
1691 (Lisp_Object window, Lisp_Object next_buffers)
1693 return decode_window (window)->next_buffers = next_buffers;
1696 DEFUN ("window-parameters", Fwindow_parameters, Swindow_parameters,
1697 0, 1, 0,
1698 doc: /* Return the parameters of WINDOW and their values.
1699 WINDOW defaults to the selected window. The return value is a list of
1700 elements of the form (PARAMETER . VALUE). */)
1701 (Lisp_Object window)
1703 return Fcopy_alist (decode_any_window (window)->window_parameters);
1706 DEFUN ("window-parameter", Fwindow_parameter, Swindow_parameter,
1707 2, 2, 0,
1708 doc: /* Return WINDOW's value for PARAMETER.
1709 WINDOW defaults to the selected window. */)
1710 (Lisp_Object window, Lisp_Object parameter)
1712 Lisp_Object result;
1714 result = Fassq (parameter, decode_any_window (window)->window_parameters);
1715 return CDR_SAFE (result);
1718 DEFUN ("set-window-parameter", Fset_window_parameter,
1719 Sset_window_parameter, 3, 3, 0,
1720 doc: /* Set WINDOW's value of PARAMETER to VALUE.
1721 WINDOW defaults to the selected window. Return VALUE. */)
1722 (Lisp_Object window, Lisp_Object parameter, Lisp_Object value)
1724 register struct window *w = decode_any_window (window);
1725 Lisp_Object old_alist_elt;
1727 old_alist_elt = Fassq (parameter, w->window_parameters);
1728 if (NILP (old_alist_elt))
1729 w->window_parameters = Fcons (Fcons (parameter, value), w->window_parameters);
1730 else
1731 Fsetcdr (old_alist_elt, value);
1732 return value;
1735 DEFUN ("window-display-table", Fwindow_display_table, Swindow_display_table,
1736 0, 1, 0,
1737 doc: /* Return the display-table that WINDOW is using.
1738 WINDOW defaults to the selected window. */)
1739 (Lisp_Object window)
1741 return decode_window (window)->display_table;
1744 /* Get the display table for use on window W. This is either W's
1745 display table or W's buffer's display table. Ignore the specified
1746 tables if they are not valid; if no valid table is specified,
1747 return 0. */
1749 struct Lisp_Char_Table *
1750 window_display_table (struct window *w)
1752 struct Lisp_Char_Table *dp = NULL;
1754 if (DISP_TABLE_P (w->display_table))
1755 dp = XCHAR_TABLE (w->display_table);
1756 else if (BUFFERP (w->buffer))
1758 struct buffer *b = XBUFFER (w->buffer);
1760 if (DISP_TABLE_P (BVAR (b, display_table)))
1761 dp = XCHAR_TABLE (BVAR (b, display_table));
1762 else if (DISP_TABLE_P (Vstandard_display_table))
1763 dp = XCHAR_TABLE (Vstandard_display_table);
1766 return dp;
1769 DEFUN ("set-window-display-table", Fset_window_display_table, Sset_window_display_table, 2, 2, 0,
1770 doc: /* Set WINDOW's display-table to TABLE. */)
1771 (register Lisp_Object window, Lisp_Object table)
1773 register struct window *w;
1775 w = decode_window (window);
1776 w->display_table = table;
1777 return table;
1780 /* Record info on buffer window W is displaying
1781 when it is about to cease to display that buffer. */
1782 static void
1783 unshow_buffer (register struct window *w)
1785 Lisp_Object buf;
1786 struct buffer *b;
1788 buf = w->buffer;
1789 b = XBUFFER (buf);
1790 if (b != XMARKER (w->pointm)->buffer)
1791 abort ();
1793 #if 0
1794 if (w == XWINDOW (selected_window)
1795 || ! EQ (buf, XWINDOW (selected_window)->buffer))
1796 /* Do this except when the selected window's buffer
1797 is being removed from some other window. */
1798 #endif
1799 /* last_window_start records the start position that this buffer
1800 had in the last window to be disconnected from it.
1801 Now that this statement is unconditional,
1802 it is possible for the buffer to be displayed in the
1803 selected window, while last_window_start reflects another
1804 window which was recently showing the same buffer.
1805 Some people might say that might be a good thing. Let's see. */
1806 b->last_window_start = marker_position (w->start);
1808 /* Point in the selected window's buffer
1809 is actually stored in that buffer, and the window's pointm isn't used.
1810 So don't clobber point in that buffer. */
1811 if (! EQ (buf, XWINDOW (selected_window)->buffer)
1812 /* This line helps to fix Horsley's testbug.el bug. */
1813 && !(WINDOWP (BVAR (b, last_selected_window))
1814 && w != XWINDOW (BVAR (b, last_selected_window))
1815 && EQ (buf, XWINDOW (BVAR (b, last_selected_window))->buffer)))
1816 temp_set_point_both (b,
1817 clip_to_bounds (BUF_BEGV (b),
1818 XMARKER (w->pointm)->charpos,
1819 BUF_ZV (b)),
1820 clip_to_bounds (BUF_BEGV_BYTE (b),
1821 marker_byte_position (w->pointm),
1822 BUF_ZV_BYTE (b)));
1824 if (WINDOWP (BVAR (b, last_selected_window))
1825 && w == XWINDOW (BVAR (b, last_selected_window)))
1826 BVAR (b, last_selected_window) = Qnil;
1829 /* Put NEW into the window structure in place of OLD. SETFLAG zero
1830 means change window structure only. Otherwise store geometry and
1831 other settings as well. */
1832 static void
1833 replace_window (Lisp_Object old, Lisp_Object new, int setflag)
1835 register Lisp_Object tem;
1836 register struct window *o = XWINDOW (old), *n = XWINDOW (new);
1838 /* If OLD is its frame's root window, then NEW is the new
1839 root window for that frame. */
1840 if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame))))
1841 FRAME_ROOT_WINDOW (XFRAME (o->frame)) = new;
1843 if (setflag)
1845 n->left_col = o->left_col;
1846 n->top_line = o->top_line;
1847 n->total_cols = o->total_cols;
1848 n->total_lines = o->total_lines;
1849 n->normal_cols = o->normal_cols;
1850 o->normal_cols = make_float (1.0);
1851 n->normal_lines = o->normal_lines;
1852 o->normal_lines = make_float (1.0);
1853 n->desired_matrix = n->current_matrix = 0;
1854 n->vscroll = 0;
1855 memset (&n->cursor, 0, sizeof (n->cursor));
1856 memset (&n->last_cursor, 0, sizeof (n->last_cursor));
1857 memset (&n->phys_cursor, 0, sizeof (n->phys_cursor));
1858 n->phys_cursor_type = -1;
1859 n->phys_cursor_width = -1;
1860 n->must_be_updated_p = 0;
1861 n->pseudo_window_p = 0;
1862 XSETFASTINT (n->window_end_vpos, 0);
1863 XSETFASTINT (n->window_end_pos, 0);
1864 n->window_end_valid = Qnil;
1865 n->frozen_window_start_p = 0;
1868 n->next = tem = o->next;
1869 if (!NILP (tem))
1870 XWINDOW (tem)->prev = new;
1872 n->prev = tem = o->prev;
1873 if (!NILP (tem))
1874 XWINDOW (tem)->next = new;
1876 n->parent = tem = o->parent;
1877 if (!NILP (tem))
1879 if (EQ (XWINDOW (tem)->vchild, old))
1880 XWINDOW (tem)->vchild = new;
1881 if (EQ (XWINDOW (tem)->hchild, old))
1882 XWINDOW (tem)->hchild = new;
1886 /* If window WINDOW and its parent window are iso-combined, merge
1887 WINDOW's children into those of its parent window and mark WINDOW as
1888 deleted. */
1890 static void
1891 recombine_windows (Lisp_Object window)
1893 struct window *w, *p, *c;
1894 Lisp_Object parent, child;
1895 int horflag;
1897 w = XWINDOW (window);
1898 parent = w->parent;
1899 if (!NILP (parent) && NILP (w->nest))
1901 p = XWINDOW (parent);
1902 if (((!NILP (p->vchild) && !NILP (w->vchild))
1903 || (!NILP (p->hchild) && !NILP (w->hchild))))
1904 /* WINDOW and PARENT are both either a vertical or a horizontal
1905 combination. */
1907 horflag = NILP (w->vchild);
1908 child = horflag ? w->hchild : w->vchild;
1909 c = XWINDOW (child);
1911 /* Splice WINDOW's children into its parent's children and
1912 assign new normal sizes. */
1913 if (NILP (w->prev))
1914 if (horflag)
1915 p->hchild = child;
1916 else
1917 p->vchild = child;
1918 else
1920 c->prev = w->prev;
1921 XWINDOW (w->prev)->next = child;
1924 while (c)
1926 c->parent = parent;
1928 if (horflag)
1929 c->normal_cols
1930 = make_float (XFLOATINT (c->total_cols)
1931 / XFLOATINT (p->total_cols));
1932 else
1933 c->normal_lines
1934 = make_float (XFLOATINT (c->total_lines)
1935 / XFLOATINT (p->total_lines));
1937 if (NILP (c->next))
1939 if (!NILP (w->next))
1941 c->next = w->next;
1942 XWINDOW (c->next)->prev = child;
1945 c = 0;
1947 else
1949 child = c->next;
1950 c = XWINDOW (child);
1954 /* WINDOW can be deleted now. */
1955 w->vchild = w->hchild = Qnil;
1960 /* If WINDOW can be deleted, delete it. */
1961 static void
1962 delete_deletable_window (Lisp_Object window)
1964 if (!NILP (call1 (Qwindow_deletable_p, window)))
1965 call1 (Qdelete_window, window);
1968 /***********************************************************************
1969 Window List
1970 ***********************************************************************/
1972 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1973 pointer. This is a callback function for foreach_window, used in
1974 the window_list function. */
1976 static int
1977 add_window_to_list (struct window *w, void *user_data)
1979 Lisp_Object *list = (Lisp_Object *) user_data;
1980 Lisp_Object window;
1981 XSETWINDOW (window, w);
1982 *list = Fcons (window, *list);
1983 return 1;
1987 /* Return a list of all windows, for use by next_window. If
1988 Vwindow_list is a list, return that list. Otherwise, build a new
1989 list, cache it in Vwindow_list, and return that. */
1991 static Lisp_Object
1992 window_list (void)
1994 if (!CONSP (Vwindow_list))
1996 Lisp_Object tail;
1998 Vwindow_list = Qnil;
1999 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
2001 Lisp_Object args[2];
2003 /* We are visiting windows in canonical order, and add
2004 new windows at the front of args[1], which means we
2005 have to reverse this list at the end. */
2006 args[1] = Qnil;
2007 foreach_window (XFRAME (XCAR (tail)), add_window_to_list, &args[1]);
2008 args[0] = Vwindow_list;
2009 args[1] = Fnreverse (args[1]);
2010 Vwindow_list = Fnconc (2, args);
2014 return Vwindow_list;
2018 /* Value is non-zero if WINDOW satisfies the constraints given by
2019 OWINDOW, MINIBUF and ALL_FRAMES.
2021 MINIBUF t means WINDOW may be minibuffer windows.
2022 `lambda' means WINDOW may not be a minibuffer window.
2023 a window means a specific minibuffer window
2025 ALL_FRAMES t means search all frames,
2026 nil means search just current frame,
2027 `visible' means search just visible frames on the
2028 current terminal,
2029 0 means search visible and iconified frames on the
2030 current terminal,
2031 a window means search the frame that window belongs to,
2032 a frame means consider windows on that frame, only. */
2034 static int
2035 candidate_window_p (Lisp_Object window, Lisp_Object owindow, Lisp_Object minibuf, Lisp_Object all_frames)
2037 struct window *w = XWINDOW (window);
2038 struct frame *f = XFRAME (w->frame);
2039 int candidate_p = 1;
2041 if (!BUFFERP (w->buffer))
2042 candidate_p = 0;
2043 else if (MINI_WINDOW_P (w)
2044 && (EQ (minibuf, Qlambda)
2045 || (WINDOWP (minibuf) && !EQ (minibuf, window))))
2047 /* If MINIBUF is `lambda' don't consider any mini-windows.
2048 If it is a window, consider only that one. */
2049 candidate_p = 0;
2051 else if (EQ (all_frames, Qt))
2052 candidate_p = 1;
2053 else if (NILP (all_frames))
2055 xassert (WINDOWP (owindow));
2056 candidate_p = EQ (w->frame, XWINDOW (owindow)->frame);
2058 else if (EQ (all_frames, Qvisible))
2060 FRAME_SAMPLE_VISIBILITY (f);
2061 candidate_p = FRAME_VISIBLE_P (f)
2062 && (FRAME_TERMINAL (XFRAME (w->frame))
2063 == FRAME_TERMINAL (XFRAME (selected_frame)));
2066 else if (INTEGERP (all_frames) && XINT (all_frames) == 0)
2068 FRAME_SAMPLE_VISIBILITY (f);
2069 candidate_p = (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f)
2070 #ifdef HAVE_X_WINDOWS
2071 /* Yuck!! If we've just created the frame and the
2072 window-manager requested the user to place it
2073 manually, the window may still not be considered
2074 `visible'. I'd argue it should be at least
2075 something like `iconified', but don't know how to do
2076 that yet. --Stef */
2077 || (FRAME_X_P (f) && f->output_data.x->asked_for_visible
2078 && !f->output_data.x->has_been_visible)
2079 #endif
2081 && (FRAME_TERMINAL (XFRAME (w->frame))
2082 == FRAME_TERMINAL (XFRAME (selected_frame)));
2084 else if (WINDOWP (all_frames))
2085 candidate_p = (EQ (FRAME_MINIBUF_WINDOW (f), all_frames)
2086 || EQ (XWINDOW (all_frames)->frame, w->frame)
2087 || EQ (XWINDOW (all_frames)->frame, FRAME_FOCUS_FRAME (f)));
2088 else if (FRAMEP (all_frames))
2089 candidate_p = EQ (all_frames, w->frame);
2091 return candidate_p;
2095 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2096 Fwindow_list. See candidate_window_p for the meaning of WINDOW,
2097 MINIBUF, and ALL_FRAMES. */
2099 static void
2100 decode_next_window_args (Lisp_Object *window, Lisp_Object *minibuf, Lisp_Object *all_frames)
2102 if (NILP (*window))
2103 *window = selected_window;
2104 else
2105 CHECK_LIVE_WINDOW (*window);
2107 /* MINIBUF nil may or may not include minibuffers. Decide if it
2108 does. */
2109 if (NILP (*minibuf))
2110 *minibuf = minibuf_level ? minibuf_window : Qlambda;
2111 else if (!EQ (*minibuf, Qt))
2112 *minibuf = Qlambda;
2114 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2115 => count none of them, or a specific minibuffer window (the
2116 active one) to count. */
2118 /* ALL_FRAMES nil doesn't specify which frames to include. */
2119 if (NILP (*all_frames))
2120 *all_frames = (!EQ (*minibuf, Qlambda)
2121 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window)->frame))
2122 : Qnil);
2123 else if (EQ (*all_frames, Qvisible))
2125 else if (EQ (*all_frames, make_number (0)))
2127 else if (FRAMEP (*all_frames))
2129 else if (!EQ (*all_frames, Qt))
2130 *all_frames = Qnil;
2134 /* Return the next or previous window of WINDOW in cyclic ordering
2135 of windows. NEXT_P non-zero means return the next window. See the
2136 documentation string of next-window for the meaning of MINIBUF and
2137 ALL_FRAMES. */
2139 static Lisp_Object
2140 next_window (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames, int next_p)
2142 decode_next_window_args (&window, &minibuf, &all_frames);
2144 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2145 return the first window on the frame. */
2146 if (FRAMEP (all_frames)
2147 && !EQ (all_frames, XWINDOW (window)->frame))
2148 return Fframe_first_window (all_frames);
2150 if (next_p)
2152 Lisp_Object list;
2154 /* Find WINDOW in the list of all windows. */
2155 list = Fmemq (window, window_list ());
2157 /* Scan forward from WINDOW to the end of the window list. */
2158 if (CONSP (list))
2159 for (list = XCDR (list); CONSP (list); list = XCDR (list))
2160 if (candidate_window_p (XCAR (list), window, minibuf, all_frames))
2161 break;
2163 /* Scan from the start of the window list up to WINDOW. */
2164 if (!CONSP (list))
2165 for (list = Vwindow_list;
2166 CONSP (list) && !EQ (XCAR (list), window);
2167 list = XCDR (list))
2168 if (candidate_window_p (XCAR (list), window, minibuf, all_frames))
2169 break;
2171 if (CONSP (list))
2172 window = XCAR (list);
2174 else
2176 Lisp_Object candidate, list;
2178 /* Scan through the list of windows for candidates. If there are
2179 candidate windows in front of WINDOW, the last one of these
2180 is the one we want. If there are candidates following WINDOW
2181 in the list, again the last one of these is the one we want. */
2182 candidate = Qnil;
2183 for (list = window_list (); CONSP (list); list = XCDR (list))
2185 if (EQ (XCAR (list), window))
2187 if (WINDOWP (candidate))
2188 break;
2190 else if (candidate_window_p (XCAR (list), window, minibuf,
2191 all_frames))
2192 candidate = XCAR (list);
2195 if (WINDOWP (candidate))
2196 window = candidate;
2199 return window;
2203 DEFUN ("next-window", Fnext_window, Snext_window, 0, 3, 0,
2204 doc: /* Return window following WINDOW in cyclic ordering of windows.
2205 WINDOW must be a live window and defaults to the selected one. The
2206 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2207 consider.
2209 MINIBUF nil or omitted means consider the minibuffer window only if the
2210 minibuffer is active. MINIBUF t means consider the minibuffer window
2211 even if the minibuffer is not active. Any other value means do not
2212 consider the minibuffer window even if the minibuffer is active.
2214 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2215 plus the minibuffer window if specified by the MINIBUF argument. If the
2216 minibuffer counts, consider all windows on all frames that share that
2217 minibuffer too. The following non-nil values of ALL-FRAMES have special
2218 meanings:
2220 - t means consider all windows on all existing frames.
2222 - `visible' means consider all windows on all visible frames.
2224 - 0 (the number zero) means consider all windows on all visible and
2225 iconified frames.
2227 - A frame means consider all windows on that frame only.
2229 Anything else means consider all windows on WINDOW's frame and no
2230 others.
2232 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2233 `next-window' to iterate through the entire cycle of acceptable
2234 windows, eventually ending up back at the window you started with.
2235 `previous-window' traverses the same cycle, in the reverse order. */)
2236 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2238 return next_window (window, minibuf, all_frames, 1);
2242 DEFUN ("previous-window", Fprevious_window, Sprevious_window, 0, 3, 0,
2243 doc: /* Return window preceding WINDOW in cyclic ordering of windows.
2244 WINDOW must be a live window and defaults to the selected one. The
2245 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2246 consider.
2248 MINIBUF nil or omitted means consider the minibuffer window only if the
2249 minibuffer is active. MINIBUF t means consider the minibuffer window
2250 even if the minibuffer is not active. Any other value means do not
2251 consider the minibuffer window even if the minibuffer is active.
2253 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2254 plus the minibuffer window if specified by the MINIBUF argument. If the
2255 minibuffer counts, consider all windows on all frames that share that
2256 minibuffer too. The following non-nil values of ALL-FRAMES have special
2257 meanings:
2259 - t means consider all windows on all existing frames.
2261 - `visible' means consider all windows on all visible frames.
2263 - 0 (the number zero) means consider all windows on all visible and
2264 iconified frames.
2266 - A frame means consider all windows on that frame only.
2268 Anything else means consider all windows on WINDOW's frame and no
2269 others.
2271 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2272 use `previous-window' to iterate through the entire cycle of
2273 acceptable windows, eventually ending up back at the window you
2274 started with. `next-window' traverses the same cycle, in the
2275 reverse order. */)
2276 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2278 return next_window (window, minibuf, all_frames, 0);
2282 /* Return a list of windows in cyclic ordering. Arguments are like
2283 for `next-window'. */
2285 static Lisp_Object
2286 window_list_1 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2288 Lisp_Object tail, list, rest;
2290 decode_next_window_args (&window, &minibuf, &all_frames);
2291 list = Qnil;
2293 for (tail = window_list (); CONSP (tail); tail = XCDR (tail))
2294 if (candidate_window_p (XCAR (tail), window, minibuf, all_frames))
2295 list = Fcons (XCAR (tail), list);
2297 /* Rotate the list to start with WINDOW. */
2298 list = Fnreverse (list);
2299 rest = Fmemq (window, list);
2300 if (!NILP (rest) && !EQ (rest, list))
2302 for (tail = list; !EQ (XCDR (tail), rest); tail = XCDR (tail))
2304 XSETCDR (tail, Qnil);
2305 list = nconc2 (rest, list);
2307 return list;
2311 DEFUN ("window-list", Fwindow_list, Swindow_list, 0, 3, 0,
2312 doc: /* Return a list of windows on FRAME, starting with WINDOW.
2313 FRAME nil or omitted means use the selected frame.
2314 WINDOW nil or omitted means use the selected window.
2315 MINIBUF t means include the minibuffer window, even if it isn't active.
2316 MINIBUF nil or omitted means include the minibuffer window only
2317 if it's active.
2318 MINIBUF neither nil nor t means never include the minibuffer window. */)
2319 (Lisp_Object frame, Lisp_Object minibuf, Lisp_Object window)
2321 if (NILP (window))
2322 window = FRAMEP (frame) ? XFRAME (frame)->selected_window : selected_window;
2323 CHECK_WINDOW (window);
2324 if (NILP (frame))
2325 frame = selected_frame;
2327 if (!EQ (frame, XWINDOW (window)->frame))
2328 error ("Window is on a different frame");
2330 return window_list_1 (window, minibuf, frame);
2334 DEFUN ("window-list-1", Fwindow_list_1, Swindow_list_1, 0, 3, 0,
2335 doc: /* Return a list of all live windows.
2336 WINDOW specifies the first window to list and defaults to the selected
2337 window.
2339 Optional argument MINIBUF nil or omitted means consider the minibuffer
2340 window only if the minibuffer is active. MINIBUF t means consider the
2341 minibuffer window even if the minibuffer is not active. Any other value
2342 means do not consider the minibuffer window even if the minibuffer is
2343 active.
2345 Optional argument ALL-FRAMES nil or omitted means consider all windows
2346 on WINDOW's frame, plus the minibuffer window if specified by the
2347 MINIBUF argument. If the minibuffer counts, consider all windows on all
2348 frames that share that minibuffer too. The following non-nil values of
2349 ALL-FRAMES have special meanings:
2351 - t means consider all windows on all existing frames.
2353 - `visible' means consider all windows on all visible frames.
2355 - 0 (the number zero) means consider all windows on all visible and
2356 iconified frames.
2358 - A frame means consider all windows on that frame only.
2360 Anything else means consider all windows on WINDOW's frame and no
2361 others.
2363 If WINDOW is not on the list of windows returned, some other window will
2364 be listed first but no error is signalled. */)
2365 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2367 return window_list_1 (window, minibuf, all_frames);
2370 /* Look at all windows, performing an operation specified by TYPE
2371 with argument OBJ.
2372 If FRAMES is Qt, look at all frames;
2373 Qnil, look at just the selected frame;
2374 Qvisible, look at visible frames;
2375 a frame, just look at windows on that frame.
2376 If MINI is non-zero, perform the operation on minibuffer windows too. */
2378 enum window_loop
2380 WINDOW_LOOP_UNUSED,
2381 GET_BUFFER_WINDOW, /* Arg is buffer */
2382 REPLACE_BUFFER_IN_WINDOWS_SAFELY, /* Arg is buffer */
2383 REDISPLAY_BUFFER_WINDOWS, /* Arg is buffer */
2384 CHECK_ALL_WINDOWS
2387 static Lisp_Object
2388 window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frames)
2390 Lisp_Object window, windows, best_window, frame_arg;
2391 int frame_best_window_flag = 0;
2392 struct frame *f;
2393 struct gcpro gcpro1;
2395 /* If we're only looping through windows on a particular frame,
2396 frame points to that frame. If we're looping through windows
2397 on all frames, frame is 0. */
2398 if (FRAMEP (frames))
2399 f = XFRAME (frames);
2400 else if (NILP (frames))
2401 f = SELECTED_FRAME ();
2402 else
2403 f = NULL;
2405 if (f)
2406 frame_arg = Qlambda;
2407 else if (EQ (frames, make_number (0)))
2408 frame_arg = frames;
2409 else if (EQ (frames, Qvisible))
2410 frame_arg = frames;
2411 else
2412 frame_arg = Qt;
2414 /* frame_arg is Qlambda to stick to one frame,
2415 Qvisible to consider all visible frames,
2416 or Qt otherwise. */
2418 /* Pick a window to start with. */
2419 if (WINDOWP (obj))
2420 window = obj;
2421 else if (f)
2422 window = FRAME_SELECTED_WINDOW (f);
2423 else
2424 window = FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2426 windows = window_list_1 (window, mini ? Qt : Qnil, frame_arg);
2427 GCPRO1 (windows);
2428 best_window = Qnil;
2430 for (; CONSP (windows); windows = XCDR (windows))
2432 struct window *w;
2434 window = XCAR (windows);
2435 w = XWINDOW (window);
2437 /* Note that we do not pay attention here to whether the frame
2438 is visible, since Fwindow_list skips non-visible frames if
2439 that is desired, under the control of frame_arg. */
2440 if (!MINI_WINDOW_P (w)
2441 /* For REPLACE_BUFFER_IN_WINDOWS_SAFELY, we must always
2442 consider all windows. */
2443 || type == REPLACE_BUFFER_IN_WINDOWS_SAFELY
2444 || (mini && minibuf_level > 0))
2445 switch (type)
2447 case GET_BUFFER_WINDOW:
2448 if (EQ (w->buffer, obj)
2449 /* Don't find any minibuffer window except the one that
2450 is currently in use. */
2451 && (MINI_WINDOW_P (w) ? EQ (window, minibuf_window) : 1))
2453 if (EQ (window, selected_window))
2454 /* Preferably return the selected window. */
2455 RETURN_UNGCPRO (window);
2456 else if (EQ (XWINDOW (window)->frame, selected_frame)
2457 && !frame_best_window_flag)
2458 /* Prefer windows on the current frame (but don't
2459 choose another one if we have one already). */
2461 best_window = window;
2462 frame_best_window_flag = 1;
2464 else if (NILP (best_window))
2465 best_window = window;
2467 break;
2469 case REPLACE_BUFFER_IN_WINDOWS_SAFELY:
2470 /* We could simply check whether the buffer shown by window
2471 is live, and show another buffer in case it isn't. */
2472 if (EQ (w->buffer, obj))
2474 /* Undedicate WINDOW. */
2475 w->dedicated = Qnil;
2476 /* Make WINDOW show the buffer returned by
2477 other_buffer_safely, don't run any hooks. */
2478 set_window_buffer
2479 (window, other_buffer_safely (w->buffer), 0, 0);
2480 /* If WINDOW is the selected window, make its buffer
2481 current. But do so only if the window shows the
2482 current buffer (Bug#6454). */
2483 if (EQ (window, selected_window)
2484 && XBUFFER (w->buffer) == current_buffer)
2485 Fset_buffer (w->buffer);
2487 break;
2489 case REDISPLAY_BUFFER_WINDOWS:
2490 if (EQ (w->buffer, obj))
2492 mark_window_display_accurate (window, 0);
2493 w->update_mode_line = Qt;
2494 XBUFFER (obj)->prevent_redisplay_optimizations_p = 1;
2495 ++update_mode_lines;
2496 best_window = window;
2498 break;
2500 /* Check for a window that has a killed buffer. */
2501 case CHECK_ALL_WINDOWS:
2502 if (! NILP (w->buffer)
2503 && NILP (BVAR (XBUFFER (w->buffer), name)))
2504 abort ();
2505 break;
2507 case WINDOW_LOOP_UNUSED:
2508 break;
2512 UNGCPRO;
2513 return best_window;
2516 /* Used for debugging. Abort if any window has a dead buffer. */
2518 extern void check_all_windows (void) EXTERNALLY_VISIBLE;
2519 void
2520 check_all_windows (void)
2522 window_loop (CHECK_ALL_WINDOWS, Qnil, 1, Qt);
2525 DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 0, 2, 0,
2526 doc: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2527 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to
2528 the current buffer.
2530 The optional argument ALL-FRAMES specifies the frames to consider:
2532 - t means consider all windows on all existing frames.
2534 - `visible' means consider all windows on all visible frames.
2536 - 0 (the number zero) means consider all windows on all visible
2537 and iconified frames.
2539 - A frame means consider all windows on that frame only.
2541 Any other value of ALL-FRAMES means consider all windows on the
2542 selected frame and no others. */)
2543 (Lisp_Object buffer_or_name, Lisp_Object all_frames)
2545 Lisp_Object buffer;
2547 if (NILP (buffer_or_name))
2548 buffer = Fcurrent_buffer ();
2549 else
2550 buffer = Fget_buffer (buffer_or_name);
2552 if (BUFFERP (buffer))
2553 return window_loop (GET_BUFFER_WINDOW, buffer, 1, all_frames);
2554 else
2555 return Qnil;
2558 static Lisp_Object
2559 resize_root_window (Lisp_Object window, Lisp_Object delta, Lisp_Object horizontal, Lisp_Object ignore)
2561 return call4 (Qwindow_resize_root_window, window, delta, horizontal, ignore);
2565 DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal,
2566 Sdelete_other_windows_internal, 0, 2, "",
2567 doc: /* Make WINDOW fill its frame.
2568 Only the frame WINDOW is on is affected. WINDOW may be any window and
2569 defaults to the selected one.
2571 Optional argument ROOT, if non-nil, must specify an internal window
2572 containing WINDOW as a subwindow. If this is the case, replace ROOT by
2573 WINDOW and leave alone any windows not contained in ROOT.
2575 When WINDOW is live try to reduce display jumps by keeping the text
2576 previously visible in WINDOW in the same place on the frame. Doing this
2577 depends on the value of (window-start WINDOW), so if calling this
2578 function in a program gives strange scrolling, make sure the
2579 window-start value is reasonable when this function is called. */)
2580 (Lisp_Object window, Lisp_Object root)
2582 struct window *w, *r, *s;
2583 struct frame *f;
2584 Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta;
2585 EMACS_INT startpos IF_LINT (= 0);
2586 int top IF_LINT (= 0), new_top, resize_failed;
2588 w = decode_any_window (window);
2589 XSETWINDOW (window, w);
2590 f = XFRAME (w->frame);
2592 if (NILP (root))
2593 /* ROOT is the frame's root window. */
2595 root = FRAME_ROOT_WINDOW (f);
2596 r = XWINDOW (root);
2598 else
2599 /* ROOT must be an ancestor of WINDOW. */
2601 r = decode_any_window (root);
2602 pwindow = XWINDOW (window)->parent;
2603 while (!NILP (pwindow))
2604 if (EQ (pwindow, root))
2605 break;
2606 else
2607 pwindow = XWINDOW (pwindow)->parent;
2608 if (!EQ (pwindow, root))
2609 error ("Specified root is not an ancestor of specified window");
2612 if (EQ (window, root))
2613 /* A noop. */
2614 return Qnil;
2615 /* I don't understand the "top > 0" part below. If we deal with a
2616 standalone minibuffer it would have been caught by the preceding
2617 test. */
2618 else if (MINI_WINDOW_P (w)) /* && top > 0) */
2619 error ("Can't expand minibuffer to full frame");
2621 if (!NILP (w->buffer))
2623 startpos = marker_position (w->start);
2624 top = WINDOW_TOP_EDGE_LINE (w)
2625 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w)));
2626 /* Make sure WINDOW is the frame's selected window. */
2627 if (!EQ (window, FRAME_SELECTED_WINDOW (f)))
2629 if (EQ (selected_frame, w->frame))
2630 Fselect_window (window, Qnil);
2631 else
2632 FRAME_SELECTED_WINDOW (f) = window;
2635 else
2637 /* See if the frame's selected window is a subwindow of WINDOW, by
2638 finding all the selected window's parents and comparing each
2639 one with WINDOW. If it isn't we need a new selected window for
2640 this frame. */
2641 swindow = FRAME_SELECTED_WINDOW (f);
2642 while (1)
2644 pwindow = swindow;
2645 while (!NILP (pwindow) && !EQ (window, pwindow))
2646 pwindow = XWINDOW (pwindow)->parent;
2648 if (EQ (window, pwindow))
2649 /* If WINDOW is an ancestor of SWINDOW, then SWINDOW is ok
2650 as the new selected window. */
2651 break;
2652 else
2653 /* Else try the previous window of SWINDOW. */
2654 swindow = Fprevious_window (swindow, Qlambda, Qnil);
2657 if (!EQ (swindow, FRAME_SELECTED_WINDOW (f)))
2659 if (EQ (selected_frame, w->frame))
2660 Fselect_window (swindow, Qnil);
2661 else
2662 FRAME_SELECTED_WINDOW (f) = swindow;
2666 BLOCK_INPUT;
2667 free_window_matrices (r);
2669 windows_or_buffers_changed++;
2670 Vwindow_list = Qnil;
2671 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
2672 resize_failed = 0;
2674 if (NILP (w->buffer))
2676 /* Resize subwindows vertically. */
2677 XSETINT (delta, XINT (r->total_lines) - XINT (w->total_lines));
2678 w->top_line = r->top_line;
2679 resize_root_window (window, delta, Qnil, Qnil);
2680 if (window_resize_check (w, 0))
2681 window_resize_apply (w, 0);
2682 else
2684 resize_root_window (window, delta, Qnil, Qt);
2685 if (window_resize_check (w, 0))
2686 window_resize_apply (w, 0);
2687 else
2688 resize_failed = 1;
2691 /* Resize subwindows horizontally. */
2692 if (!resize_failed)
2694 w->left_col = r->left_col;
2695 XSETINT (delta, XINT (r->total_cols) - XINT (w->total_cols));
2696 w->left_col = r->left_col;
2697 resize_root_window (window, delta, Qt, Qnil);
2698 if (window_resize_check (w, 1))
2699 window_resize_apply (w, 1);
2700 else
2702 resize_root_window (window, delta, Qt, Qt);
2703 if (window_resize_check (w, 1))
2704 window_resize_apply (w, 1);
2705 else
2706 resize_failed = 1;
2710 if (resize_failed)
2711 /* Play safe, if we still can ... */
2713 window = swindow;
2714 w = XWINDOW (window);
2718 /* Cleanly unlink WINDOW from window-tree. */
2719 if (!NILP (w->prev))
2720 /* Get SIBLING above (on the left of) WINDOW. */
2722 sibling = w->prev;
2723 s = XWINDOW (sibling);
2724 s->next = w->next;
2725 if (!NILP (s->next))
2726 XWINDOW (s->next)->prev = sibling;
2728 else
2729 /* Get SIBLING below (on the right of) WINDOW. */
2731 sibling = w->next;
2732 s = XWINDOW (sibling);
2733 s->prev = Qnil;
2734 if (!NILP (XWINDOW (w->parent)->vchild))
2735 XWINDOW (w->parent)->vchild = sibling;
2736 else
2737 XWINDOW (w->parent)->hchild = sibling;
2740 /* Delete ROOT and all subwindows of ROOT. */
2741 if (!NILP (r->vchild))
2743 delete_all_subwindows (r->vchild);
2744 r->vchild = Qnil;
2746 else if (!NILP (r->hchild))
2748 delete_all_subwindows (r->hchild);
2749 r->hchild = Qnil;
2752 replace_window (root, window, 1);
2754 /* Reset WINDOW's splits status. */
2755 w->splits = Qnil;
2757 /* This must become SWINDOW anyway ....... */
2758 if (!NILP (w->buffer) && !resize_failed)
2760 /* Try to minimize scrolling, by setting the window start to the
2761 point will cause the text at the old window start to be at the
2762 same place on the frame. But don't try to do this if the
2763 window start is outside the visible portion (as might happen
2764 when the display is not current, due to typeahead). */
2765 new_top = WINDOW_TOP_EDGE_LINE (w) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w)));
2766 if (new_top != top
2767 && startpos >= BUF_BEGV (XBUFFER (w->buffer))
2768 && startpos <= BUF_ZV (XBUFFER (w->buffer)))
2770 struct position pos;
2771 struct buffer *obuf = current_buffer;
2773 Fset_buffer (w->buffer);
2774 /* This computation used to temporarily move point, but that
2775 can have unwanted side effects due to text properties. */
2776 pos = *vmotion (startpos, -top, w);
2778 set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos);
2779 w->window_end_valid = Qnil;
2780 w->start_at_line_beg = ((pos.bytepos == BEGV_BYTE
2781 || FETCH_BYTE (pos.bytepos - 1) == '\n') ? Qt
2782 : Qnil);
2783 /* We need to do this, so that the window-scroll-functions
2784 get called. */
2785 w->optional_new_start = Qt;
2787 set_buffer_internal (obuf);
2791 adjust_glyphs (f);
2792 UNBLOCK_INPUT;
2794 run_window_configuration_change_hook (f);
2796 return Qnil;
2800 void
2801 replace_buffer_in_windows (Lisp_Object buffer)
2803 call1 (Qreplace_buffer_in_windows, buffer);
2807 /* Safely replace BUFFER with some other buffer in all windows of all
2808 frames, even those on other keyboards. */
2810 void
2811 replace_buffer_in_windows_safely (Lisp_Object buffer)
2813 Lisp_Object tail, frame;
2815 /* A single call to window_loop won't do the job because it only
2816 considers frames on the current keyboard. So loop manually over
2817 frames, and handle each one. */
2818 FOR_EACH_FRAME (tail, frame)
2819 window_loop (REPLACE_BUFFER_IN_WINDOWS_SAFELY, buffer, 1, frame);
2822 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2823 minimum allowable size. */
2825 void
2826 check_frame_size (FRAME_PTR frame, int *rows, int *cols)
2828 /* For height, we have to see:
2829 how many windows the frame has at minimum (one or two),
2830 and whether it has a menu bar or other special stuff at the top. */
2831 int min_height
2832 = ((FRAME_MINIBUF_ONLY_P (frame) || ! FRAME_HAS_MINIBUF_P (frame))
2833 ? MIN_SAFE_WINDOW_HEIGHT
2834 : 2 * MIN_SAFE_WINDOW_HEIGHT);
2836 if (FRAME_TOP_MARGIN (frame) > 0)
2837 min_height += FRAME_TOP_MARGIN (frame);
2839 if (*rows < min_height)
2840 *rows = min_height;
2841 if (*cols < MIN_SAFE_WINDOW_WIDTH)
2842 *cols = MIN_SAFE_WINDOW_WIDTH;
2845 /* Adjust the margins of window W if text area is too small.
2846 Return 1 if window width is ok after adjustment; 0 if window
2847 is still too narrow. */
2849 static int
2850 adjust_window_margins (struct window *w)
2852 int box_cols = (WINDOW_TOTAL_COLS (w)
2853 - WINDOW_FRINGE_COLS (w)
2854 - WINDOW_SCROLL_BAR_COLS (w));
2855 int margin_cols = (WINDOW_LEFT_MARGIN_COLS (w)
2856 + WINDOW_RIGHT_MARGIN_COLS (w));
2858 if (box_cols - margin_cols >= MIN_SAFE_WINDOW_WIDTH)
2859 return 1;
2861 if (margin_cols < 0 || box_cols < MIN_SAFE_WINDOW_WIDTH)
2862 return 0;
2864 /* Window's text area is too narrow, but reducing the window
2865 margins will fix that. */
2866 margin_cols = box_cols - MIN_SAFE_WINDOW_WIDTH;
2867 if (WINDOW_RIGHT_MARGIN_COLS (w) > 0)
2869 if (WINDOW_LEFT_MARGIN_COLS (w) > 0)
2870 w->left_margin_cols = w->right_margin_cols
2871 = make_number (margin_cols/2);
2872 else
2873 w->right_margin_cols = make_number (margin_cols);
2875 else
2876 w->left_margin_cols = make_number (margin_cols);
2877 return 1;
2880 static Lisp_Object Fset_window_margins (Lisp_Object, Lisp_Object, Lisp_Object);
2881 static Lisp_Object Fset_window_fringes (Lisp_Object, Lisp_Object, Lisp_Object,
2882 Lisp_Object);
2883 static Lisp_Object Fset_window_scroll_bars (Lisp_Object, Lisp_Object,
2884 Lisp_Object, Lisp_Object);
2885 static Lisp_Object Fset_window_vscroll (Lisp_Object, Lisp_Object, Lisp_Object);
2887 /* The following three routines are needed for running a window's
2888 configuration change hook. */
2889 static void
2890 run_funs (Lisp_Object funs)
2892 for (; CONSP (funs); funs = XCDR (funs))
2893 if (!EQ (XCAR (funs), Qt))
2894 call0 (XCAR (funs));
2897 static Lisp_Object
2898 select_window_norecord (Lisp_Object window)
2900 return WINDOW_LIVE_P (window)
2901 ? Fselect_window (window, Qt) : selected_window;
2904 static Lisp_Object
2905 select_frame_norecord (Lisp_Object frame)
2907 return FRAME_LIVE_P (XFRAME (frame))
2908 ? Fselect_frame (frame, Qt) : selected_frame;
2911 void
2912 run_window_configuration_change_hook (struct frame *f)
2914 int count = SPECPDL_INDEX ();
2915 Lisp_Object frame, global_wcch
2916 = Fdefault_value (Qwindow_configuration_change_hook);
2917 XSETFRAME (frame, f);
2919 if (NILP (Vrun_hooks))
2920 return;
2922 /* Use the right buffer. Matters when running the local hooks. */
2923 if (current_buffer != XBUFFER (Fwindow_buffer (Qnil)))
2925 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
2926 Fset_buffer (Fwindow_buffer (Qnil));
2929 if (SELECTED_FRAME () != f)
2931 record_unwind_protect (select_frame_norecord, Fselected_frame ());
2932 select_frame_norecord (frame);
2935 /* Look for buffer-local values. */
2937 Lisp_Object windows = Fwindow_list (frame, Qlambda, Qnil);
2938 for (; CONSP (windows); windows = XCDR (windows))
2940 Lisp_Object window = XCAR (windows);
2941 Lisp_Object buffer = Fwindow_buffer (window);
2942 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook,
2943 buffer)))
2945 int inner_count = SPECPDL_INDEX ();
2946 record_unwind_protect (select_window_norecord, Fselected_window ());
2947 select_window_norecord (window);
2948 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook,
2949 buffer));
2950 unbind_to (inner_count, Qnil);
2955 run_funs (global_wcch);
2956 unbind_to (count, Qnil);
2959 DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook,
2960 Srun_window_configuration_change_hook, 1, 1, 0,
2961 doc: /* Run `window-configuration-change-hook' for FRAME. */)
2962 (Lisp_Object frame)
2964 CHECK_LIVE_FRAME (frame);
2965 run_window_configuration_change_hook (XFRAME (frame));
2966 return Qnil;
2969 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
2970 means it's allowed to run hooks. See make_frame for a case where
2971 it's not allowed. KEEP_MARGINS_P non-zero means that the current
2972 margins, fringes, and scroll-bar settings of the window are not
2973 reset from the buffer's local settings. */
2975 void
2976 set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int keep_margins_p)
2978 struct window *w = XWINDOW (window);
2979 struct buffer *b = XBUFFER (buffer);
2980 int count = SPECPDL_INDEX ();
2981 int samebuf = EQ (buffer, w->buffer);
2983 w->buffer = buffer;
2985 if (EQ (window, selected_window))
2986 BVAR (b, last_selected_window) = window;
2988 /* Let redisplay errors through. */
2989 b->display_error_modiff = 0;
2991 /* Update time stamps of buffer display. */
2992 if (INTEGERP (BVAR (b, display_count)))
2993 XSETINT (BVAR (b, display_count), XINT (BVAR (b, display_count)) + 1);
2994 BVAR (b, display_time) = Fcurrent_time ();
2996 XSETFASTINT (w->window_end_pos, 0);
2997 XSETFASTINT (w->window_end_vpos, 0);
2998 memset (&w->last_cursor, 0, sizeof w->last_cursor);
2999 w->window_end_valid = Qnil;
3000 if (!(keep_margins_p && samebuf))
3001 { /* If we're not actually changing the buffer, don't reset hscroll and
3002 vscroll. This case happens for example when called from
3003 change_frame_size_1, where we use a dummy call to
3004 Fset_window_buffer on the frame's selected window (and no other)
3005 just in order to run window-configuration-change-hook.
3006 Resetting hscroll and vscroll here is problematic for things like
3007 image-mode and doc-view-mode since it resets the image's position
3008 whenever we resize the frame. */
3009 w->hscroll = w->min_hscroll = make_number (0);
3010 w->vscroll = 0;
3011 set_marker_both (w->pointm, buffer, BUF_PT (b), BUF_PT_BYTE (b));
3012 set_marker_restricted (w->start,
3013 make_number (b->last_window_start),
3014 buffer);
3015 w->start_at_line_beg = Qnil;
3016 w->force_start = Qnil;
3017 XSETFASTINT (w->last_modified, 0);
3018 XSETFASTINT (w->last_overlay_modified, 0);
3020 /* Maybe we could move this into the `if' but it's not obviously safe and
3021 I doubt it's worth the trouble. */
3022 windows_or_buffers_changed++;
3024 /* We must select BUFFER for running the window-scroll-functions. */
3025 /* We can't check ! NILP (Vwindow_scroll_functions) here
3026 because that might itself be a local variable. */
3027 if (window_initialized)
3029 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
3030 Fset_buffer (buffer);
3033 XMARKER (w->pointm)->insertion_type = !NILP (Vwindow_point_insertion_type);
3035 if (!keep_margins_p)
3037 /* Set left and right marginal area width etc. from buffer. */
3039 /* This may call adjust_window_margins three times, so
3040 temporarily disable window margins. */
3041 Lisp_Object save_left = w->left_margin_cols;
3042 Lisp_Object save_right = w->right_margin_cols;
3044 w->left_margin_cols = w->right_margin_cols = Qnil;
3046 Fset_window_fringes (window,
3047 BVAR (b, left_fringe_width), BVAR (b, right_fringe_width),
3048 BVAR (b, fringes_outside_margins));
3050 Fset_window_scroll_bars (window,
3051 BVAR (b, scroll_bar_width),
3052 BVAR (b, vertical_scroll_bar_type), Qnil);
3054 w->left_margin_cols = save_left;
3055 w->right_margin_cols = save_right;
3057 Fset_window_margins (window,
3058 BVAR (b, left_margin_cols), BVAR (b, right_margin_cols));
3061 if (run_hooks_p)
3063 if (! NILP (Vwindow_scroll_functions))
3064 run_hook_with_args_2 (Qwindow_scroll_functions, window,
3065 Fmarker_position (w->start));
3066 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w)));
3069 unbind_to (count, Qnil);
3072 DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 3, 0,
3073 doc: /* Make WINDOW display BUFFER-OR-NAME as its contents.
3074 WINDOW has to be a live window and defaults to the selected one.
3075 BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
3077 Optional third argument KEEP-MARGINS non-nil means that WINDOW's current
3078 display margins, fringe widths, and scroll bar settings are preserved;
3079 the default is to reset these from the local settings for BUFFER-OR-NAME
3080 or the frame defaults. Return nil.
3082 This function throws an error when WINDOW is strongly dedicated to its
3083 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3084 already display BUFFER-OR-NAME.
3086 This function runs `window-scroll-functions' before running
3087 `window-configuration-change-hook'. */)
3088 (register Lisp_Object window, Lisp_Object buffer_or_name, Lisp_Object keep_margins)
3090 register Lisp_Object tem, buffer;
3091 register struct window *w = decode_window (window);
3093 XSETWINDOW (window, w);
3094 buffer = Fget_buffer (buffer_or_name);
3095 CHECK_BUFFER (buffer);
3096 if (NILP (BVAR (XBUFFER (buffer), name)))
3097 error ("Attempt to display deleted buffer");
3099 tem = w->buffer;
3100 if (NILP (tem))
3101 error ("Window is deleted");
3102 else if (!EQ (tem, Qt))
3103 /* w->buffer is t when the window is first being set up. */
3105 if (!EQ (tem, buffer))
3107 if (EQ (w->dedicated, Qt))
3108 /* WINDOW is strongly dedicated to its buffer, signal an
3109 error. */
3110 error ("Window is dedicated to `%s'", SDATA (BVAR (XBUFFER (tem), name)));
3111 else
3112 /* WINDOW is weakly dedicated to its buffer, reset
3113 dedicatedness. */
3114 w->dedicated = Qnil;
3116 call1 (Qrecord_window_buffer, window);
3119 unshow_buffer (w);
3122 set_window_buffer (window, buffer, 1, !NILP (keep_margins));
3124 return Qnil;
3127 static Lisp_Object
3128 display_buffer (Lisp_Object buffer, Lisp_Object not_this_window_p, Lisp_Object override_frame)
3130 return call3 (Qdisplay_buffer, buffer, not_this_window_p, override_frame);
3133 DEFUN ("force-window-update", Fforce_window_update, Sforce_window_update,
3134 0, 1, 0,
3135 doc: /* Force all windows to be updated on next redisplay.
3136 If optional arg OBJECT is a window, force redisplay of that window only.
3137 If OBJECT is a buffer or buffer name, force redisplay of all windows
3138 displaying that buffer. */)
3139 (Lisp_Object object)
3141 if (NILP (object))
3143 windows_or_buffers_changed++;
3144 update_mode_lines++;
3145 return Qt;
3148 if (WINDOWP (object))
3150 struct window *w = XWINDOW (object);
3151 mark_window_display_accurate (object, 0);
3152 w->update_mode_line = Qt;
3153 if (BUFFERP (w->buffer))
3154 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
3155 ++update_mode_lines;
3156 return Qt;
3159 if (STRINGP (object))
3160 object = Fget_buffer (object);
3161 if (BUFFERP (object) && !NILP (BVAR (XBUFFER (object), name)))
3163 /* Walk all windows looking for buffer, and force update
3164 of each of those windows. */
3166 object = window_loop (REDISPLAY_BUFFER_WINDOWS, object, 0, Qvisible);
3167 return NILP (object) ? Qnil : Qt;
3170 /* If nothing suitable was found, just return.
3171 We could signal an error, but this feature will typically be used
3172 asynchronously in timers or process sentinels, so we don't. */
3173 return Qnil;
3177 void
3178 temp_output_buffer_show (register Lisp_Object buf)
3180 register struct buffer *old = current_buffer;
3181 register Lisp_Object window;
3182 register struct window *w;
3184 BVAR (XBUFFER (buf), directory) = BVAR (current_buffer, directory);
3186 Fset_buffer (buf);
3187 BUF_SAVE_MODIFF (XBUFFER (buf)) = MODIFF;
3188 BEGV = BEG;
3189 ZV = Z;
3190 SET_PT (BEG);
3191 set_buffer_internal (old);
3193 if (!NILP (Vtemp_buffer_show_function))
3194 call1 (Vtemp_buffer_show_function, buf);
3195 else
3197 window = display_buffer (buf, Qnil, Qnil);
3199 if (!EQ (XWINDOW (window)->frame, selected_frame))
3200 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
3201 Vminibuf_scroll_window = window;
3202 w = XWINDOW (window);
3203 XSETFASTINT (w->hscroll, 0);
3204 XSETFASTINT (w->min_hscroll, 0);
3205 set_marker_restricted_both (w->start, buf, BEG, BEG);
3206 set_marker_restricted_both (w->pointm, buf, BEG, BEG);
3208 /* Run temp-buffer-show-hook, with the chosen window selected
3209 and its buffer current. */
3211 int count = SPECPDL_INDEX ();
3212 Lisp_Object prev_window, prev_buffer;
3213 prev_window = selected_window;
3214 XSETBUFFER (prev_buffer, old);
3216 /* Select the window that was chosen, for running the hook.
3217 Note: Both Fselect_window and select_window_norecord may
3218 set-buffer to the buffer displayed in the window,
3219 so we need to save the current buffer. --stef */
3220 record_unwind_protect (Fset_buffer, prev_buffer);
3221 record_unwind_protect (select_window_norecord, prev_window);
3222 Fselect_window (window, Qt);
3223 Fset_buffer (w->buffer);
3224 Frun_hooks (1, &Qtemp_buffer_show_hook);
3225 unbind_to (count, Qnil);
3230 DEFUN ("internal-temp-output-buffer-show",
3231 Ftemp_output_buffer_show, Stemp_output_buffer_show,
3232 1, 1, 0,
3233 doc: /* Internal function for `with-output-to-temp-buffer'. */)
3234 (Lisp_Object buf)
3236 temp_output_buffer_show (buf);
3237 return Qnil;
3240 /* Make new window, have it replace WINDOW in window-tree, and make
3241 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
3242 horizontal child). */
3243 static void
3244 make_parent_window (Lisp_Object window, int horflag)
3246 Lisp_Object parent;
3247 register struct window *o, *p;
3248 int i;
3250 o = XWINDOW (window);
3251 p = allocate_window ();
3252 for (i = 0; i < VECSIZE (struct window); ++i)
3253 ((struct Lisp_Vector *) p)->contents[i]
3254 = ((struct Lisp_Vector *) o)->contents[i];
3255 XSETWINDOW (parent, p);
3257 ++sequence_number;
3258 XSETFASTINT (p->sequence_number, sequence_number);
3260 replace_window (window, parent, 1);
3262 o->next = Qnil;
3263 o->prev = Qnil;
3264 o->parent = parent;
3266 p->hchild = horflag ? window : Qnil;
3267 p->vchild = horflag ? Qnil : window;
3268 p->start = Qnil;
3269 p->pointm = Qnil;
3270 p->buffer = Qnil;
3271 p->splits = Qnil;
3272 p->nest = Qnil;
3273 p->window_parameters = Qnil;
3276 /* Make new window from scratch. */
3277 Lisp_Object
3278 make_window (void)
3280 Lisp_Object window;
3281 register struct window *w;
3283 w = allocate_window ();
3284 /* Initialize all Lisp data. */
3285 w->frame = w->mini_p = Qnil;
3286 w->next = w->prev = w->hchild = w->vchild = w->parent = Qnil;
3287 XSETFASTINT (w->left_col, 0);
3288 XSETFASTINT (w->top_line, 0);
3289 XSETFASTINT (w->total_lines, 0);
3290 XSETFASTINT (w->total_cols, 0);
3291 w->normal_lines = make_float (1.0);
3292 w->normal_cols = make_float (1.0);
3293 XSETFASTINT (w->new_total, 0);
3294 XSETFASTINT (w->new_normal, 0);
3295 w->buffer = Qnil;
3296 w->start = Fmake_marker ();
3297 w->pointm = Fmake_marker ();
3298 w->force_start = w->optional_new_start = Qnil;
3299 XSETFASTINT (w->hscroll, 0);
3300 XSETFASTINT (w->min_hscroll, 0);
3301 XSETFASTINT (w->use_time, 0);
3302 ++sequence_number;
3303 XSETFASTINT (w->sequence_number, sequence_number);
3304 w->temslot = w->last_modified = w->last_overlay_modified = Qnil;
3305 XSETFASTINT (w->last_point, 0);
3306 w->last_had_star = w->vertical_scroll_bar = Qnil;
3307 w->left_margin_cols = w->right_margin_cols = Qnil;
3308 w->left_fringe_width = w->right_fringe_width = Qnil;
3309 w->fringes_outside_margins = Qnil;
3310 w->scroll_bar_width = Qnil;
3311 w->vertical_scroll_bar_type = Qt;
3312 w->last_mark_x = w->last_mark_y = Qnil;
3313 XSETFASTINT (w->window_end_pos, 0);
3314 XSETFASTINT (w->window_end_vpos, 0);
3315 w->window_end_valid = w->update_mode_line = Qnil;
3316 w->start_at_line_beg = w->display_table = w->dedicated = Qnil;
3317 w->base_line_number = w->base_line_pos = w->region_showing = Qnil;
3318 w->column_number_displayed = w->redisplay_end_trigger = Qnil;
3319 w->splits = w->nest = w->window_parameters = Qnil;
3320 w->prev_buffers = w->next_buffers = Qnil;
3321 /* Initialize non-Lisp data. */
3322 w->desired_matrix = w->current_matrix = 0;
3323 w->nrows_scale_factor = w->ncols_scale_factor = 1;
3324 memset (&w->cursor, 0, sizeof (w->cursor));
3325 memset (&w->last_cursor, 0, sizeof (w->last_cursor));
3326 memset (&w->phys_cursor, 0, sizeof (w->phys_cursor));
3327 w->phys_cursor_type = -1;
3328 w->phys_cursor_width = -1;
3329 w->phys_cursor_on_p = 0;
3330 w->last_cursor_off_p = w->cursor_off_p = 0;
3331 w->must_be_updated_p = 0;
3332 w->pseudo_window_p = 0;
3333 w->frozen_window_start_p = 0;
3334 w->vscroll = 0;
3335 /* Reset window_list. */
3336 Vwindow_list = Qnil;
3337 /* Return window. */
3338 XSETWINDOW (window, w);
3339 return window;
3342 DEFUN ("set-window-new-total", Fset_window_new_total, Sset_window_new_total, 2, 3, 0,
3343 doc: /* Set new total size of WINDOW to SIZE.
3344 Return SIZE.
3346 Optional argument ADD non-nil means add SIZE to the new total size of
3347 WINDOW and return the sum.
3349 Note: This function does not operate on any subwindows of WINDOW. */)
3350 (Lisp_Object window, Lisp_Object size, Lisp_Object add)
3352 struct window *w = decode_any_window (window);
3354 CHECK_NUMBER (size);
3355 if (NILP (add))
3356 XSETINT (w->new_total, XINT (size));
3357 else
3358 XSETINT (w->new_total, XINT (w->new_total) + XINT (size));
3360 return w->new_total;
3363 DEFUN ("set-window-new-normal", Fset_window_new_normal, Sset_window_new_normal, 1, 2, 0,
3364 doc: /* Set new normal size of WINDOW to SIZE.
3365 Return SIZE.
3367 Note: This function does not operate on any subwindows of WINDOW. */)
3368 (Lisp_Object window, Lisp_Object size)
3370 struct window *w = decode_any_window (window);
3372 w->new_normal = size;
3373 return w->new_normal;
3376 /* Return 1 if setting w->total_lines (w->total_cols if HORFLAG is
3377 non-zero) to w->new_total would result in correct heights (widths)
3378 for window W and recursively all subwindows of W.
3380 Note: This function does not check any of `window-fixed-size-p',
3381 `window-min-height' or `window-min-width'. It does check that window
3382 sizes do not drop below one line (two columns). */
3383 static int
3384 window_resize_check (struct window *w, int horflag)
3386 struct window *c;
3388 if (!NILP (w->vchild))
3389 /* W is a vertical combination. */
3391 c = XWINDOW (w->vchild);
3392 if (horflag)
3393 /* All subwindows of W must have the same width as W. */
3395 while (c)
3397 if ((XINT (c->new_total) != XINT (w->new_total))
3398 || !window_resize_check (c, horflag))
3399 return 0;
3400 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3402 return 1;
3404 else
3405 /* The sum of the heights of the subwindows of W must equal W's
3406 height. */
3408 int sum_of_sizes = 0;
3409 while (c)
3411 if (!window_resize_check (c, horflag))
3412 return 0;
3413 sum_of_sizes = sum_of_sizes + XINT (c->new_total);
3414 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3416 return (sum_of_sizes == XINT (w->new_total));
3419 else if (!NILP (w->hchild))
3420 /* W is a horizontal combination. */
3422 c = XWINDOW (w->hchild);
3423 if (horflag)
3424 /* The sum of the widths of the subwindows of W must equal W's
3425 width. */
3427 int sum_of_sizes = 0;
3428 while (c)
3430 if (!window_resize_check (c, horflag))
3431 return 0;
3432 sum_of_sizes = sum_of_sizes + XINT (c->new_total);
3433 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3435 return (sum_of_sizes == XINT (w->new_total));
3437 else
3438 /* All subwindows of W must have the same height as W. */
3440 while (c)
3442 if ((XINT (c->new_total) != XINT (w->new_total))
3443 || !window_resize_check (c, horflag))
3444 return 0;
3445 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3447 return 1;
3450 else
3451 /* A leaf window. Make sure it's not too small. The following
3452 hardcodes the values of `window-safe-min-width' (2) and
3453 `window-safe-min-height' (1) which are defined in window.el. */
3454 return XINT (w->new_total) >= (horflag ? 2 : 1);
3457 /* Set w->total_lines (w->total_cols if HORIZONTAL is non-zero) to
3458 w->new_total for window W and recursively all subwindows of W. Also
3459 calculate and assign the new vertical (horizontal) start positions of
3460 each of these windows.
3462 This function does not perform any error checks. Make sure you have
3463 run window_resize_check on W before applying this function. */
3464 static void
3465 window_resize_apply (struct window *w, int horflag)
3467 struct window *c;
3468 int pos;
3470 /* Note: Assigning new_normal requires that the new total size of the
3471 parent window has been set *before*. */
3472 if (horflag)
3474 w->total_cols = w->new_total;
3475 if (NUMBERP (w->new_normal))
3476 w->normal_cols = w->new_normal;
3478 pos = XINT (w->left_col);
3480 else
3482 w->total_lines = w->new_total;
3483 if (NUMBERP (w->new_normal))
3484 w->normal_lines = w->new_normal;
3486 pos = XINT (w->top_line);
3489 if (!NILP (w->vchild))
3490 /* W is a vertical combination. */
3492 c = XWINDOW (w->vchild);
3493 while (c)
3495 if (horflag)
3496 XSETFASTINT (c->left_col, pos);
3497 else
3498 XSETFASTINT (c->top_line, pos);
3499 window_resize_apply (c, horflag);
3500 if (!horflag)
3501 pos = pos + XINT (c->total_lines);
3502 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3505 else if (!NILP (w->hchild))
3506 /* W is a horizontal combination. */
3508 c = XWINDOW (w->hchild);
3509 while (c)
3511 if (horflag)
3512 XSETFASTINT (c->left_col, pos);
3513 else
3514 XSETFASTINT (c->top_line, pos);
3515 window_resize_apply (c, horflag);
3516 if (horflag)
3517 pos = pos + XINT (c->total_cols);
3518 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3522 /* Clear out some redisplay caches. */
3523 XSETFASTINT (w->last_modified, 0);
3524 XSETFASTINT (w->last_overlay_modified, 0);
3528 DEFUN ("window-resize-apply", Fwindow_resize_apply, Swindow_resize_apply, 1, 2, 0,
3529 doc: /* Apply requested size values for window-tree of FRAME.
3530 Optional argument HORIZONTAL omitted or nil means apply requested height
3531 values. HORIZONTAL non-nil means apply requested width values.
3533 This function checks whether the requested values sum up to a valid
3534 window layout, recursively assigns the new sizes of all subwindows and
3535 calculates and assigns the new start positions of these windows.
3537 Note: This function does not check any of `window-fixed-size-p',
3538 `window-min-height' or `window-min-width'. All these checks have to
3539 be applied on the Elisp level. */)
3540 (Lisp_Object frame, Lisp_Object horizontal)
3542 struct frame *f;
3543 struct window *r;
3544 int horflag = !NILP (horizontal);
3546 if (NILP (frame))
3547 frame = selected_frame;
3548 CHECK_LIVE_FRAME (frame);
3550 f = XFRAME (frame);
3551 r = XWINDOW (FRAME_ROOT_WINDOW (f));
3553 if (!window_resize_check (r, horflag)
3554 || ! EQ (r->new_total, (horflag ? r->total_cols : r->total_lines)))
3555 return Qnil;
3557 BLOCK_INPUT;
3558 window_resize_apply (r, horflag);
3560 windows_or_buffers_changed++;
3561 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
3563 adjust_glyphs (f);
3564 UNBLOCK_INPUT;
3566 run_window_configuration_change_hook (f);
3568 return Qt;
3572 /* Resize frame F's windows when number of lines of F is set to SIZE.
3573 HORFLAG 1 means resize windows when number of columns of F is set to
3574 SIZE.
3576 This function can delete all windows but the selected one in order to
3577 satisfy the request. The result will be meaningful if and only if
3578 F's windows have meaningful sizes when you call this. */
3579 void
3580 resize_frame_windows (struct frame *f, int size, int horflag)
3582 Lisp_Object root = f->root_window;
3583 struct window *r = XWINDOW (root);
3584 Lisp_Object mini = f->minibuffer_window;
3585 struct window *m;
3586 /* new_size is the new size of the frame's root window. */
3587 int new_size = (horflag
3588 ? size
3589 : (size
3590 - FRAME_TOP_MARGIN (f)
3591 - ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
3592 ? 1 : 0)));
3594 XSETFASTINT (r->top_line, FRAME_TOP_MARGIN (f));
3595 if (NILP (r->vchild) && NILP (r->hchild))
3596 /* For a leaf root window just set the size. */
3597 if (horflag)
3598 XSETFASTINT (r->total_cols, new_size);
3599 else
3600 XSETFASTINT (r->total_lines, new_size);
3601 else
3603 /* old_size is the old size of the frame's root window. */
3604 int old_size = XFASTINT (horflag ? r->total_cols : r->total_lines);
3605 Lisp_Object delta;
3607 XSETINT (delta, new_size - old_size);
3608 /* Try a "normal" resize first. */
3609 resize_root_window (root, delta, horflag ? Qt : Qnil, Qnil);
3610 if (window_resize_check (r, horflag) && new_size == XINT (r->new_total))
3611 window_resize_apply (r, horflag);
3612 else
3614 /* Try with "reasonable" minimum sizes next. */
3615 resize_root_window (root, delta, horflag ? Qt : Qnil, Qt);
3616 if (window_resize_check (r, horflag)
3617 && new_size == XINT (r->new_total))
3618 window_resize_apply (r, horflag);
3619 else
3621 /* Finally, try with "safe" minimum sizes. */
3622 resize_root_window (root, delta, horflag ? Qt : Qnil, Qsafe);
3623 if (window_resize_check (r, horflag)
3624 && new_size == XINT (r->new_total))
3625 window_resize_apply (r, horflag);
3626 else
3628 /* We lost. Delete all windows but the frame's
3629 selected one. */
3630 root = f->selected_window;
3631 Fdelete_other_windows_internal (root, Qnil);
3632 if (horflag)
3633 XSETFASTINT (XWINDOW (root)->total_cols, new_size);
3634 else
3635 XSETFASTINT (XWINDOW (root)->total_lines, new_size);
3641 if (FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
3643 m = XWINDOW (mini);
3644 if (horflag)
3645 XSETFASTINT (m->total_cols, size);
3646 else
3648 /* Are we sure we always want 1 line here? */
3649 XSETFASTINT (m->total_lines, 1);
3650 XSETFASTINT (m->top_line, XINT (r->top_line) + XINT (r->total_lines));
3656 DEFUN ("split-window-internal", Fsplit_window_internal, Ssplit_window_internal, 4, 4, 0,
3657 doc: /* Split window OLD.
3658 Second argument TOTAL-SIZE specifies the number of lines or columns of the
3659 new window. In any case TOTAL-SIZE must be a positive integer.
3661 Third argument SIDE nil (or `below') specifies that the new window shall
3662 be located below WINDOW. SIDE `above' means the new window shall be
3663 located above WINDOW. In both cases TOTAL-SIZE specifies the number of
3664 lines of the new window including space reserved for the mode and/or
3665 header line.
3667 SIDE t (or `right') specifies that the new window shall be located on
3668 the right side of WINDOW. SIDE `left' means the new window shall be
3669 located on the left of WINDOW. In both cases TOTAL-SIZE specifies the
3670 number of columns of the new window including space reserved for fringes
3671 and the scrollbar or a divider column.
3673 Fourth argument NORMAL-SIZE specifies the normal size of the new window
3674 according to the SIDE argument.
3676 The new total and normal sizes of all involved windows must have been
3677 set correctly. See the code of `split-window' for how this is done. */)
3678 (Lisp_Object old, Lisp_Object total_size, Lisp_Object side, Lisp_Object normal_size)
3680 /* OLD (*o) is the window we have to split. (*p) is either OLD's
3681 parent window or an internal window we have to install as OLD's new
3682 parent. REFERENCE (*r) must denote a live window, or is set to OLD
3683 provided OLD is a leaf window, or to the frame's selected window.
3684 NEW (*n) is the new window created with some parameters taken from
3685 REFERENCE (*r). */
3686 register Lisp_Object new, frame, reference;
3687 register struct window *o, *p, *n, *r;
3688 struct frame *f;
3689 int horflag
3690 /* HORFLAG is 1 when we split side-by-side, 0 otherwise. */
3691 = EQ (side, Qt) || EQ (side, Qleft) || EQ (side, Qright);
3692 int do_nest = 0;
3694 CHECK_WINDOW (old);
3695 o = XWINDOW (old);
3696 frame = WINDOW_FRAME (o);
3697 f = XFRAME (frame);
3699 CHECK_NUMBER (total_size);
3701 /* Set do_nest to 1 if we have to make a new parent window. We do
3702 that if either `window-nest' is non-nil, or OLD has no parent, or
3703 OLD is ortho-combined. */
3704 do_nest =
3705 !NILP (Vwindow_nest)
3706 || NILP (o->parent)
3707 || NILP (horflag
3708 ? (XWINDOW (o->parent)->hchild)
3709 : (XWINDOW (o->parent)->vchild));
3711 /* We need a live reference window to initialize some parameters. */
3712 if (WINDOW_LIVE_P (old))
3713 /* OLD is live, use it as reference window. */
3714 reference = old;
3715 else
3716 /* Use the frame's selected window as reference window. */
3717 reference = FRAME_SELECTED_WINDOW (f);
3718 r = XWINDOW (reference);
3720 /* The following bugs are caught by `split-window'. */
3721 if (MINI_WINDOW_P (o))
3722 error ("Attempt to split minibuffer window");
3723 else if (XINT (total_size) < (horflag ? 2 : 1))
3724 error ("Size of new window too small (after split)");
3725 else if (!do_nest && !NILP (Vwindow_splits))
3726 /* `window-splits' non-nil means try to resize OLD's siblings
3727 proportionally. */
3729 p = XWINDOW (o->parent);
3730 /* Temporarily pretend we split the parent window. */
3731 XSETINT (p->new_total,
3732 XINT (horflag ? p->total_cols : p->total_lines)
3733 - XINT (total_size));
3734 if (!window_resize_check (p, horflag))
3735 error ("Window sizes don't fit");
3736 else
3737 /* Undo the temporary pretension. */
3738 p->new_total = horflag ? p->total_cols : p->total_lines;
3740 else
3742 if (!window_resize_check (o, horflag))
3743 error ("Resizing old window failed");
3744 else if (XINT (total_size) + XINT (o->new_total)
3745 != XINT (horflag ? o->total_cols : o->total_lines))
3746 error ("Sum of sizes of old and new window don't fit");
3749 /* This is our point of no return. */
3750 if (do_nest)
3752 /* Save the old value of o->normal_cols/lines. It gets corrupted
3753 by make_parent_window and we need it below for assigning it to
3754 p->new_normal. */
3755 Lisp_Object new_normal = horflag ? o->normal_cols : o->normal_lines;
3757 make_parent_window (old, horflag);
3758 p = XWINDOW (o->parent);
3759 /* Store value of `window-nest' in new parent's nest slot. */
3760 p->nest = Vwindow_nest;
3761 /* Have PARENT inherit splits slot value from OLD. */
3762 p->splits = o->splits;
3763 /* Store value of `window-splits' in OLD's splits slot. */
3764 o->splits = Vwindow_splits;
3765 /* These get applied below. */
3766 p->new_total = horflag ? o->total_cols : o->total_lines;
3767 p->new_normal = new_normal;
3769 else
3770 p = XWINDOW (o->parent);
3772 windows_or_buffers_changed++;
3773 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
3774 new = make_window ();
3775 n = XWINDOW (new);
3776 n->frame = frame;
3777 n->parent = o->parent;
3778 n->vchild = n->hchild = Qnil;
3780 if (EQ (side, Qabove) || EQ (side, Qleft))
3782 n->prev = o->prev;
3783 if (NILP (n->prev))
3784 if (horflag)
3785 p->hchild = new;
3786 else
3787 p->vchild = new;
3788 else
3789 XWINDOW (n->prev)->next = new;
3790 n->next = old;
3791 o->prev = new;
3793 else
3795 n->next = o->next;
3796 if (!NILP (n->next))
3797 XWINDOW (n->next)->prev = new;
3798 n->prev = old;
3799 o->next = new;
3802 n->buffer = Qt;
3803 n->window_end_valid = Qnil;
3804 memset (&n->last_cursor, 0, sizeof n->last_cursor);
3806 /* Get special geometry settings from reference window. */
3807 n->left_margin_cols = r->left_margin_cols;
3808 n->right_margin_cols = r->right_margin_cols;
3809 n->left_fringe_width = r->left_fringe_width;
3810 n->right_fringe_width = r->right_fringe_width;
3811 n->fringes_outside_margins = r->fringes_outside_margins;
3812 n->scroll_bar_width = r->scroll_bar_width;
3813 n->vertical_scroll_bar_type = r->vertical_scroll_bar_type;
3815 /* Store `window-splits' in NEW's splits slot. */
3816 n->splits = Vwindow_splits;
3818 /* Directly assign orthogonal coordinates and sizes. */
3819 if (horflag)
3821 n->top_line = o->top_line;
3822 n->total_lines = o->total_lines;
3824 else
3826 n->left_col = o->left_col;
3827 n->total_cols = o->total_cols;
3830 /* Iso-coordinates and sizes are assigned by window_resize_apply,
3831 get them ready here. */
3832 n->new_total = total_size;
3833 n->new_normal = normal_size;
3835 BLOCK_INPUT;
3836 window_resize_apply (p, horflag);
3837 adjust_glyphs (f);
3838 /* Set buffer of NEW to buffer of reference window. Don't run
3839 any hooks. */
3840 set_window_buffer (new, r->buffer, 0, 1);
3841 UNBLOCK_INPUT;
3843 /* Maybe we should run the scroll functions in Elisp (which already
3844 runs the configuration change hook). */
3845 if (! NILP (Vwindow_scroll_functions))
3846 run_hook_with_args_2 (Qwindow_scroll_functions, new,
3847 Fmarker_position (n->start));
3848 /* Return NEW. */
3849 return new;
3853 DEFUN ("delete-window-internal", Fdelete_window_internal, Sdelete_window_internal, 1, 1, 0,
3854 doc: /* Remove WINDOW from its frame.
3855 WINDOW defaults to the selected window. Return nil.
3856 Signal an error when WINDOW is the only window on its frame. */)
3857 (register Lisp_Object window)
3859 register Lisp_Object parent, sibling, frame, root;
3860 struct window *w, *p, *s, *r;
3861 struct frame *f;
3862 int horflag;
3863 int before_sibling = 0;
3865 w = decode_any_window (window);
3866 XSETWINDOW (window, w);
3867 if (NILP (w->buffer) && NILP (w->hchild) && NILP (w->vchild))
3868 /* It's a no-op to delete an already deleted window. */
3869 return Qnil;
3871 parent = w->parent;
3872 if (NILP (parent))
3873 /* Never delete a minibuffer or frame root window. */
3874 error ("Attempt to delete minibuffer or sole ordinary window");
3875 else if (NILP (w->prev) && NILP (w->next))
3876 /* Rather bow out here, this case should be handled on the Elisp
3877 level. */
3878 error ("Attempt to delete sole window of parent");
3880 p = XWINDOW (parent);
3881 horflag = NILP (p->vchild);
3883 frame = WINDOW_FRAME (w);
3884 f = XFRAME (frame);
3886 root = FRAME_ROOT_WINDOW (f);
3887 r = XWINDOW (root);
3889 /* Unlink WINDOW from window tree. */
3890 if (NILP (w->prev))
3891 /* Get SIBLING below (on the right of) WINDOW. */
3893 /* before_sibling 1 means WINDOW is the first child of its
3894 parent and thus before the sibling. */
3895 before_sibling = 1;
3896 sibling = w->next;
3897 s = XWINDOW (sibling);
3898 s->prev = Qnil;
3899 if (horflag)
3900 p->hchild = sibling;
3901 else
3902 p->vchild = sibling;
3904 else
3905 /* Get SIBLING above (on the left of) WINDOW. */
3907 sibling = w->prev;
3908 s = XWINDOW (sibling);
3909 s->next = w->next;
3910 if (!NILP (s->next))
3911 XWINDOW (s->next)->prev = sibling;
3914 if (window_resize_check (r, horflag)
3915 && EQ (r->new_total, (horflag ? r->total_cols : r->total_lines)))
3916 /* We can delete WINDOW now. */
3918 /* Block input. */
3919 BLOCK_INPUT;
3920 window_resize_apply (p, horflag);
3922 windows_or_buffers_changed++;
3923 Vwindow_list = Qnil;
3924 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
3926 w->next = Qnil; /* Don't delete w->next too. */
3927 free_window_matrices (w);
3929 if (!NILP (w->vchild))
3931 delete_all_subwindows (w->vchild);
3932 w->vchild = Qnil;
3934 else if (!NILP (w->hchild))
3936 delete_all_subwindows (w->hchild);
3937 w->hchild = Qnil;
3939 else if (!NILP (w->buffer))
3941 unshow_buffer (w);
3942 unchain_marker (XMARKER (w->pointm));
3943 unchain_marker (XMARKER (w->start));
3944 w->buffer = Qnil;
3947 if (NILP (s->prev) && NILP (s->next))
3948 /* A matrjoshka where SIBLING has become the only child of
3949 PARENT. */
3951 /* Put SIBLING into PARENT's place. */
3952 replace_window (parent, sibling, 0);
3953 /* Have SIBLING inherit the following three slot values from
3954 PARENT (the nest slot is not inherited). */
3955 s->normal_cols = p->normal_cols;
3956 s->normal_lines = p->normal_lines;
3957 s->splits = p->splits;
3958 /* Mark PARENT as deleted. */
3959 p->vchild = p->hchild = Qnil;
3960 /* Try to merge SIBLING into its new parent. */
3961 recombine_windows (sibling);
3964 adjust_glyphs (f);
3966 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f)))
3967 /* We deleted the frame's selected window. */
3969 /* Use the frame's first window as fallback ... */
3970 Lisp_Object new_selected_window = Fframe_first_window (frame);
3971 /* ... but preferably use its most recently used window. */
3972 Lisp_Object mru_window;
3974 /* `get-mru-window' might fail for some reason so play it safe
3975 - promote the first window _without recording it_ first. */
3976 if (EQ (FRAME_SELECTED_WINDOW (f), selected_window))
3977 Fselect_window (new_selected_window, Qt);
3978 else
3979 FRAME_SELECTED_WINDOW (f) = new_selected_window;
3981 UNBLOCK_INPUT;
3983 /* Now look whether `get-mru-window' gets us something. */
3984 mru_window = call1 (Qget_mru_window, frame);
3985 if (WINDOW_LIVE_P (mru_window)
3986 && EQ (XWINDOW (mru_window)->frame, frame))
3987 new_selected_window = mru_window;
3989 /* If all ended up well, we now promote the mru window. */
3990 if (EQ (FRAME_SELECTED_WINDOW (f), selected_window))
3991 Fselect_window (new_selected_window, Qnil);
3992 else
3993 FRAME_SELECTED_WINDOW (f) = new_selected_window;
3995 else
3996 UNBLOCK_INPUT;
3998 /* Must be run by the caller:
3999 run_window_configuration_change_hook (f); */
4001 else
4002 /* We failed: Relink WINDOW into window tree. */
4004 if (before_sibling)
4006 s->prev = window;
4007 if (horflag)
4008 p->hchild = window;
4009 else
4010 p->vchild = window;
4012 else
4014 s->next = window;
4015 if (!NILP (w->next))
4016 XWINDOW (w->next)->prev = window;
4018 error ("Deletion failed");
4021 return Qnil;
4024 /***********************************************************************
4025 Resizing Mini-Windows
4026 ***********************************************************************/
4028 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we
4029 can. */
4030 void
4031 grow_mini_window (struct window *w, int delta)
4033 struct frame *f = XFRAME (w->frame);
4034 struct window *r;
4035 Lisp_Object root, value;
4037 xassert (MINI_WINDOW_P (w));
4038 xassert (delta >= 0);
4040 root = FRAME_ROOT_WINDOW (f);
4041 r = XWINDOW (root);
4042 value = call2 (Qwindow_resize_root_window_vertically,
4043 root, make_number (- delta));
4044 if (INTEGERP (value) && window_resize_check (r, 0))
4046 BLOCK_INPUT;
4047 window_resize_apply (r, 0);
4049 /* Grow the mini-window. */
4050 XSETFASTINT (w->top_line, XFASTINT (r->top_line) + XFASTINT (r->total_lines));
4051 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - XINT (value));
4052 XSETFASTINT (w->last_modified, 0);
4053 XSETFASTINT (w->last_overlay_modified, 0);
4055 adjust_glyphs (f);
4056 UNBLOCK_INPUT;
4061 /* Shrink mini-window W. */
4062 void
4063 shrink_mini_window (struct window *w)
4065 struct frame *f = XFRAME (w->frame);
4066 struct window *r;
4067 Lisp_Object root, value;
4068 EMACS_INT size;
4070 xassert (MINI_WINDOW_P (w));
4072 size = XINT (w->total_lines);
4073 if (size > 1)
4075 root = FRAME_ROOT_WINDOW (f);
4076 r = XWINDOW (root);
4077 value = call2 (Qwindow_resize_root_window_vertically,
4078 root, make_number (size - 1));
4079 if (INTEGERP (value) && window_resize_check (r, 0))
4081 BLOCK_INPUT;
4082 window_resize_apply (r, 0);
4084 /* Shrink the mini-window. */
4085 XSETFASTINT (w->top_line, XFASTINT (r->top_line) + XFASTINT (r->total_lines));
4086 XSETFASTINT (w->total_lines, 1);
4088 XSETFASTINT (w->last_modified, 0);
4089 XSETFASTINT (w->last_overlay_modified, 0);
4091 adjust_glyphs (f);
4092 UNBLOCK_INPUT;
4094 /* If the above failed for whatever strange reason we must make a
4095 one window frame here. The same routine will be needed when
4096 shrinking the frame (and probably when making the initial
4097 *scratch* window). For the moment leave things as they are. */
4101 DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini_window_internal, 1, 1, 0,
4102 doc: /* Resize minibuffer window WINDOW. */)
4103 (Lisp_Object window)
4105 struct window *w = XWINDOW (window);
4106 struct window *r;
4107 struct frame *f;
4108 int height;
4110 CHECK_WINDOW (window);
4111 f = XFRAME (w->frame);
4113 if (!EQ (FRAME_MINIBUF_WINDOW (XFRAME (w->frame)), window))
4114 error ("Not a valid minibuffer window");
4115 else if (FRAME_MINIBUF_ONLY_P (f))
4116 error ("Cannot resize a minibuffer-only frame");
4118 r = XWINDOW (FRAME_ROOT_WINDOW (f));
4119 height = XINT (r->total_lines) + XINT (w->total_lines);
4120 if (window_resize_check (r, 0)
4121 && XINT (w->new_total) > 0
4122 && height == XINT (r->new_total) + XINT (w->new_total))
4124 BLOCK_INPUT;
4125 window_resize_apply (r, 0);
4127 w->total_lines = w->new_total;
4128 XSETFASTINT (w->top_line, XINT (r->top_line) + XINT (r->total_lines));
4130 windows_or_buffers_changed++;
4131 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
4132 adjust_glyphs (f);
4133 UNBLOCK_INPUT;
4135 run_window_configuration_change_hook (f);
4136 return Qt;
4138 else error ("Failed to resize minibuffer window");
4141 /* Mark window cursors off for all windows in the window tree rooted
4142 at W by setting their phys_cursor_on_p flag to zero. Called from
4143 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4144 the frame are cleared. */
4146 void
4147 mark_window_cursors_off (struct window *w)
4149 while (w)
4151 if (!NILP (w->hchild))
4152 mark_window_cursors_off (XWINDOW (w->hchild));
4153 else if (!NILP (w->vchild))
4154 mark_window_cursors_off (XWINDOW (w->vchild));
4155 else
4156 w->phys_cursor_on_p = 0;
4158 w = NILP (w->next) ? 0 : XWINDOW (w->next);
4163 /* Return number of lines of text (not counting mode lines) in W. */
4166 window_internal_height (struct window *w)
4168 int ht = XFASTINT (w->total_lines);
4170 if (!MINI_WINDOW_P (w))
4172 if (!NILP (w->parent)
4173 || !NILP (w->vchild)
4174 || !NILP (w->hchild)
4175 || !NILP (w->next)
4176 || !NILP (w->prev)
4177 || WINDOW_WANTS_MODELINE_P (w))
4178 --ht;
4180 if (WINDOW_WANTS_HEADER_LINE_P (w))
4181 --ht;
4184 return ht;
4187 /************************************************************************
4188 Window Scrolling
4189 ***********************************************************************/
4191 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4192 N screen-fulls, which is defined as the height of the window minus
4193 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4194 instead. Negative values of N mean scroll down. NOERROR non-zero
4195 means don't signal an error if we try to move over BEGV or ZV,
4196 respectively. */
4198 static void
4199 window_scroll (Lisp_Object window, int n, int whole, int noerror)
4201 immediate_quit = 1;
4203 /* If we must, use the pixel-based version which is much slower than
4204 the line-based one but can handle varying line heights. */
4205 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window)->frame)))
4206 window_scroll_pixel_based (window, n, whole, noerror);
4207 else
4208 window_scroll_line_based (window, n, whole, noerror);
4210 immediate_quit = 0;
4214 /* Implementation of window_scroll that works based on pixel line
4215 heights. See the comment of window_scroll for parameter
4216 descriptions. */
4218 static void
4219 window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4221 struct it it;
4222 struct window *w = XWINDOW (window);
4223 struct text_pos start;
4224 int this_scroll_margin;
4225 /* True if we fiddled the window vscroll field without really scrolling. */
4226 int vscrolled = 0;
4227 int x, y, rtop, rbot, rowh, vpos;
4228 void *itdata = NULL;
4230 SET_TEXT_POS_FROM_MARKER (start, w->start);
4232 /* If PT is not visible in WINDOW, move back one half of
4233 the screen. Allow PT to be partially visible, otherwise
4234 something like (scroll-down 1) with PT in the line before
4235 the partially visible one would recenter. */
4237 if (!pos_visible_p (w, PT, &x, &y, &rtop, &rbot, &rowh, &vpos))
4239 itdata = bidi_shelve_cache ();
4240 /* Move backward half the height of the window. Performance note:
4241 vmotion used here is about 10% faster, but would give wrong
4242 results for variable height lines. */
4243 init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID);
4244 it.current_y = it.last_visible_y;
4245 move_it_vertically_backward (&it, window_box_height (w) / 2);
4247 /* The function move_iterator_vertically may move over more than
4248 the specified y-distance. If it->w is small, e.g. a
4249 mini-buffer window, we may end up in front of the window's
4250 display area. This is the case when Start displaying at the
4251 start of the line containing PT in this case. */
4252 if (it.current_y <= 0)
4254 init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID);
4255 move_it_vertically_backward (&it, 0);
4256 it.current_y = 0;
4259 start = it.current.pos;
4260 bidi_unshelve_cache (itdata, 0);
4262 else if (auto_window_vscroll_p)
4264 if (rtop || rbot) /* partially visible */
4266 int px;
4267 int dy = WINDOW_FRAME_LINE_HEIGHT (w);
4268 if (whole)
4269 dy = max ((window_box_height (w)
4270 - next_screen_context_lines * dy),
4271 dy);
4272 dy *= n;
4274 if (n < 0)
4276 /* Only vscroll backwards if already vscrolled forwards. */
4277 if (w->vscroll < 0 && rtop > 0)
4279 px = max (0, -w->vscroll - min (rtop, -dy));
4280 Fset_window_vscroll (window, make_number (px), Qt);
4281 return;
4284 if (n > 0)
4286 /* Do vscroll if already vscrolled or only display line. */
4287 if (rbot > 0 && (w->vscroll < 0 || vpos == 0))
4289 px = max (0, -w->vscroll + min (rbot, dy));
4290 Fset_window_vscroll (window, make_number (px), Qt);
4291 return;
4294 /* Maybe modify window start instead of scrolling. */
4295 if (rbot > 0 || w->vscroll < 0)
4297 EMACS_INT spos;
4299 Fset_window_vscroll (window, make_number (0), Qt);
4300 /* If there are other text lines above the current row,
4301 move window start to current row. Else to next row. */
4302 if (rbot > 0)
4303 spos = XINT (Fline_beginning_position (Qnil));
4304 else
4305 spos = min (XINT (Fline_end_position (Qnil)) + 1, ZV);
4306 set_marker_restricted (w->start, make_number (spos),
4307 w->buffer);
4308 w->start_at_line_beg = Qt;
4309 w->update_mode_line = Qt;
4310 XSETFASTINT (w->last_modified, 0);
4311 XSETFASTINT (w->last_overlay_modified, 0);
4312 /* Set force_start so that redisplay_window will run the
4313 window-scroll-functions. */
4314 w->force_start = Qt;
4315 return;
4319 /* Cancel previous vscroll. */
4320 Fset_window_vscroll (window, make_number (0), Qt);
4323 itdata = bidi_shelve_cache ();
4324 /* If scroll_preserve_screen_position is non-nil, we try to set
4325 point in the same window line as it is now, so get that line. */
4326 if (!NILP (Vscroll_preserve_screen_position))
4328 /* We preserve the goal pixel coordinate across consecutive
4329 calls to scroll-up, scroll-down and other commands that
4330 have the `scroll-command' property. This avoids the
4331 possibility of point becoming "stuck" on a tall line when
4332 scrolling by one line. */
4333 if (window_scroll_pixel_based_preserve_y < 0
4334 || !SYMBOLP (KVAR (current_kboard, Vlast_command))
4335 || NILP (Fget (KVAR (current_kboard, Vlast_command), Qscroll_command)))
4337 start_display (&it, w, start);
4338 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
4339 window_scroll_pixel_based_preserve_y = it.current_y;
4340 window_scroll_pixel_based_preserve_x = it.current_x;
4343 else
4344 window_scroll_pixel_based_preserve_y
4345 = window_scroll_pixel_based_preserve_x = -1;
4347 /* Move iterator it from start the specified distance forward or
4348 backward. The result is the new window start. */
4349 start_display (&it, w, start);
4350 if (whole)
4352 EMACS_INT start_pos = IT_CHARPOS (it);
4353 int dy = WINDOW_FRAME_LINE_HEIGHT (w);
4354 dy = max ((window_box_height (w)
4355 - next_screen_context_lines * dy),
4356 dy) * n;
4358 /* Note that move_it_vertically always moves the iterator to the
4359 start of a line. So, if the last line doesn't have a newline,
4360 we would end up at the start of the line ending at ZV. */
4361 if (dy <= 0)
4363 move_it_vertically_backward (&it, -dy);
4364 /* Ensure we actually do move, e.g. in case we are currently
4365 looking at an image that is taller that the window height. */
4366 while (start_pos == IT_CHARPOS (it)
4367 && start_pos > BEGV)
4368 move_it_by_lines (&it, -1);
4370 else if (dy > 0)
4372 move_it_to (&it, ZV, -1, it.current_y + dy, -1,
4373 MOVE_TO_POS | MOVE_TO_Y);
4374 /* Ensure we actually do move, e.g. in case we are currently
4375 looking at an image that is taller that the window height. */
4376 while (start_pos == IT_CHARPOS (it)
4377 && start_pos < ZV)
4378 move_it_by_lines (&it, 1);
4381 else
4382 move_it_by_lines (&it, n);
4384 /* We failed if we find ZV is already on the screen (scrolling up,
4385 means there's nothing past the end), or if we can't start any
4386 earlier (scrolling down, means there's nothing past the top). */
4387 if ((n > 0 && IT_CHARPOS (it) == ZV)
4388 || (n < 0 && IT_CHARPOS (it) == CHARPOS (start)))
4390 if (IT_CHARPOS (it) == ZV)
4392 if (it.current_y < it.last_visible_y
4393 && (it.current_y + it.max_ascent + it.max_descent
4394 > it.last_visible_y))
4396 /* The last line was only partially visible, make it fully
4397 visible. */
4398 w->vscroll = (it.last_visible_y
4399 - it.current_y + it.max_ascent + it.max_descent);
4400 adjust_glyphs (it.f);
4402 else
4404 bidi_unshelve_cache (itdata, 0);
4405 if (noerror)
4406 return;
4407 else if (n < 0) /* could happen with empty buffers */
4408 xsignal0 (Qbeginning_of_buffer);
4409 else
4410 xsignal0 (Qend_of_buffer);
4413 else
4415 if (w->vscroll != 0)
4416 /* The first line was only partially visible, make it fully
4417 visible. */
4418 w->vscroll = 0;
4419 else
4421 bidi_unshelve_cache (itdata, 0);
4422 if (noerror)
4423 return;
4424 else
4425 xsignal0 (Qbeginning_of_buffer);
4429 /* If control gets here, then we vscrolled. */
4431 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
4433 /* Don't try to change the window start below. */
4434 vscrolled = 1;
4437 if (! vscrolled)
4439 EMACS_INT pos = IT_CHARPOS (it);
4440 EMACS_INT bytepos;
4442 /* If in the middle of a multi-glyph character move forward to
4443 the next character. */
4444 if (in_display_vector_p (&it))
4446 ++pos;
4447 move_it_to (&it, pos, -1, -1, -1, MOVE_TO_POS);
4450 /* Set the window start, and set up the window for redisplay. */
4451 set_marker_restricted (w->start, make_number (pos),
4452 w->buffer);
4453 bytepos = XMARKER (w->start)->bytepos;
4454 w->start_at_line_beg = ((pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n')
4455 ? Qt : Qnil);
4456 w->update_mode_line = Qt;
4457 XSETFASTINT (w->last_modified, 0);
4458 XSETFASTINT (w->last_overlay_modified, 0);
4459 /* Set force_start so that redisplay_window will run the
4460 window-scroll-functions. */
4461 w->force_start = Qt;
4464 /* The rest of this function uses current_y in a nonstandard way,
4465 not including the height of the header line if any. */
4466 it.current_y = it.vpos = 0;
4468 /* Move PT out of scroll margins.
4469 This code wants current_y to be zero at the window start position
4470 even if there is a header line. */
4471 this_scroll_margin = max (0, scroll_margin);
4472 this_scroll_margin = min (this_scroll_margin, XFASTINT (w->total_lines) / 4);
4473 this_scroll_margin *= FRAME_LINE_HEIGHT (it.f);
4475 if (n > 0)
4477 /* We moved the window start towards ZV, so PT may be now
4478 in the scroll margin at the top. */
4479 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
4480 if (IT_CHARPOS (it) == PT && it.current_y >= this_scroll_margin
4481 && (NILP (Vscroll_preserve_screen_position)
4482 || EQ (Vscroll_preserve_screen_position, Qt)))
4483 /* We found PT at a legitimate height. Leave it alone. */
4485 else if (window_scroll_pixel_based_preserve_y >= 0)
4487 /* If we have a header line, take account of it.
4488 This is necessary because we set it.current_y to 0, above. */
4489 move_it_to (&it, -1,
4490 window_scroll_pixel_based_preserve_x,
4491 window_scroll_pixel_based_preserve_y
4492 - (WINDOW_WANTS_HEADER_LINE_P (w) ? 1 : 0 ),
4493 -1, MOVE_TO_Y | MOVE_TO_X);
4494 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4496 else
4498 while (it.current_y < this_scroll_margin)
4500 int prev = it.current_y;
4501 move_it_by_lines (&it, 1);
4502 if (prev == it.current_y)
4503 break;
4505 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4508 else if (n < 0)
4510 EMACS_INT charpos, bytepos;
4511 int partial_p;
4513 /* Save our position, for the
4514 window_scroll_pixel_based_preserve_y case. */
4515 charpos = IT_CHARPOS (it);
4516 bytepos = IT_BYTEPOS (it);
4518 /* We moved the window start towards BEGV, so PT may be now
4519 in the scroll margin at the bottom. */
4520 move_it_to (&it, PT, -1,
4521 (it.last_visible_y - CURRENT_HEADER_LINE_HEIGHT (w)
4522 - this_scroll_margin - 1),
4524 MOVE_TO_POS | MOVE_TO_Y);
4526 /* Save our position, in case it's correct. */
4527 charpos = IT_CHARPOS (it);
4528 bytepos = IT_BYTEPOS (it);
4530 /* See if point is on a partially visible line at the end. */
4531 if (it.what == IT_EOB)
4532 partial_p = it.current_y + it.ascent + it.descent > it.last_visible_y;
4533 else
4535 move_it_by_lines (&it, 1);
4536 partial_p = it.current_y > it.last_visible_y;
4539 if (charpos == PT && !partial_p
4540 && (NILP (Vscroll_preserve_screen_position)
4541 || EQ (Vscroll_preserve_screen_position, Qt)))
4542 /* We found PT before we found the display margin, so PT is ok. */
4544 else if (window_scroll_pixel_based_preserve_y >= 0)
4546 SET_TEXT_POS_FROM_MARKER (start, w->start);
4547 start_display (&it, w, start);
4548 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
4549 here because we called start_display again and did not
4550 alter it.current_y this time. */
4551 move_it_to (&it, -1, window_scroll_pixel_based_preserve_x,
4552 window_scroll_pixel_based_preserve_y, -1,
4553 MOVE_TO_Y | MOVE_TO_X);
4554 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4556 else
4558 if (partial_p)
4559 /* The last line was only partially visible, so back up two
4560 lines to make sure we're on a fully visible line. */
4562 move_it_by_lines (&it, -2);
4563 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4565 else
4566 /* No, the position we saved is OK, so use it. */
4567 SET_PT_BOTH (charpos, bytepos);
4570 bidi_unshelve_cache (itdata, 0);
4574 /* Implementation of window_scroll that works based on screen lines.
4575 See the comment of window_scroll for parameter descriptions. */
4577 static void
4578 window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4580 register struct window *w = XWINDOW (window);
4581 /* Fvertical_motion enters redisplay, which can trigger
4582 fontification, which in turn can modify buffer text (e.g., if the
4583 fontification functions replace escape sequences with faces, as
4584 in `grep-mode-font-lock-keywords'). So we use a marker to record
4585 the old point position, to prevent crashes in SET_PT_BOTH. */
4586 Lisp_Object opoint_marker = Fpoint_marker ();
4587 register EMACS_INT pos, pos_byte;
4588 register int ht = window_internal_height (w);
4589 register Lisp_Object tem;
4590 int lose;
4591 Lisp_Object bolp;
4592 EMACS_INT startpos;
4593 Lisp_Object original_pos = Qnil;
4595 /* If scrolling screen-fulls, compute the number of lines to
4596 scroll from the window's height. */
4597 if (whole)
4598 n *= max (1, ht - next_screen_context_lines);
4600 startpos = marker_position (w->start);
4602 if (!NILP (Vscroll_preserve_screen_position))
4604 if (window_scroll_preserve_vpos <= 0
4605 || !SYMBOLP (KVAR (current_kboard, Vlast_command))
4606 || NILP (Fget (KVAR (current_kboard, Vlast_command), Qscroll_command)))
4608 struct position posit
4609 = *compute_motion (startpos, 0, 0, 0,
4610 PT, ht, 0,
4611 -1, XINT (w->hscroll),
4612 0, w);
4613 window_scroll_preserve_vpos = posit.vpos;
4614 window_scroll_preserve_hpos = posit.hpos + XINT (w->hscroll);
4617 original_pos = Fcons (make_number (window_scroll_preserve_hpos),
4618 make_number (window_scroll_preserve_vpos));
4621 XSETFASTINT (tem, PT);
4622 tem = Fpos_visible_in_window_p (tem, window, Qnil);
4624 if (NILP (tem))
4626 Fvertical_motion (make_number (- (ht / 2)), window);
4627 startpos = PT;
4630 SET_PT (startpos);
4631 lose = n < 0 && PT == BEGV;
4632 Fvertical_motion (make_number (n), window);
4633 pos = PT;
4634 pos_byte = PT_BYTE;
4635 bolp = Fbolp ();
4636 SET_PT_BOTH (marker_position (opoint_marker),
4637 marker_byte_position (opoint_marker));
4639 if (lose)
4641 if (noerror)
4642 return;
4643 else
4644 xsignal0 (Qbeginning_of_buffer);
4647 if (pos < ZV)
4649 /* Don't use a scroll margin that is negative or too large. */
4650 int this_scroll_margin =
4651 max (0, min (scroll_margin, XINT (w->total_lines) / 4));
4653 set_marker_restricted_both (w->start, w->buffer, pos, pos_byte);
4654 w->start_at_line_beg = bolp;
4655 w->update_mode_line = Qt;
4656 XSETFASTINT (w->last_modified, 0);
4657 XSETFASTINT (w->last_overlay_modified, 0);
4658 /* Set force_start so that redisplay_window will run
4659 the window-scroll-functions. */
4660 w->force_start = Qt;
4662 if (!NILP (Vscroll_preserve_screen_position)
4663 && (whole || !EQ (Vscroll_preserve_screen_position, Qt)))
4665 SET_PT_BOTH (pos, pos_byte);
4666 Fvertical_motion (original_pos, window);
4668 /* If we scrolled forward, put point enough lines down
4669 that it is outside the scroll margin. */
4670 else if (n > 0)
4672 int top_margin;
4674 if (this_scroll_margin > 0)
4676 SET_PT_BOTH (pos, pos_byte);
4677 Fvertical_motion (make_number (this_scroll_margin), window);
4678 top_margin = PT;
4680 else
4681 top_margin = pos;
4683 if (top_margin <= marker_position (opoint_marker))
4684 SET_PT_BOTH (marker_position (opoint_marker),
4685 marker_byte_position (opoint_marker));
4686 else if (!NILP (Vscroll_preserve_screen_position))
4688 SET_PT_BOTH (pos, pos_byte);
4689 Fvertical_motion (original_pos, window);
4691 else
4692 SET_PT (top_margin);
4694 else if (n < 0)
4696 int bottom_margin;
4698 /* If we scrolled backward, put point near the end of the window
4699 but not within the scroll margin. */
4700 SET_PT_BOTH (pos, pos_byte);
4701 tem = Fvertical_motion (make_number (ht - this_scroll_margin), window);
4702 if (XFASTINT (tem) == ht - this_scroll_margin)
4703 bottom_margin = PT;
4704 else
4705 bottom_margin = PT + 1;
4707 if (bottom_margin > marker_position (opoint_marker))
4708 SET_PT_BOTH (marker_position (opoint_marker),
4709 marker_byte_position (opoint_marker));
4710 else
4712 if (!NILP (Vscroll_preserve_screen_position))
4714 SET_PT_BOTH (pos, pos_byte);
4715 Fvertical_motion (original_pos, window);
4717 else
4718 Fvertical_motion (make_number (-1), window);
4722 else
4724 if (noerror)
4725 return;
4726 else
4727 xsignal0 (Qend_of_buffer);
4732 /* Scroll selected_window up or down. If N is nil, scroll a
4733 screen-full which is defined as the height of the window minus
4734 next_screen_context_lines. If N is the symbol `-', scroll.
4735 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4736 up. This is the guts of Fscroll_up and Fscroll_down. */
4738 static void
4739 scroll_command (Lisp_Object n, int direction)
4741 int count = SPECPDL_INDEX ();
4743 xassert (eabs (direction) == 1);
4745 /* If selected window's buffer isn't current, make it current for
4746 the moment. But don't screw up if window_scroll gets an error. */
4747 if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
4749 record_unwind_protect (save_excursion_restore, save_excursion_save ());
4750 Fset_buffer (XWINDOW (selected_window)->buffer);
4752 /* Make redisplay consider other windows than just selected_window. */
4753 ++windows_or_buffers_changed;
4756 if (NILP (n))
4757 window_scroll (selected_window, direction, 1, 0);
4758 else if (EQ (n, Qminus))
4759 window_scroll (selected_window, -direction, 1, 0);
4760 else
4762 n = Fprefix_numeric_value (n);
4763 window_scroll (selected_window, XINT (n) * direction, 0, 0);
4766 unbind_to (count, Qnil);
4769 DEFUN ("scroll-up", Fscroll_up, Sscroll_up, 0, 1, "^P",
4770 doc: /* Scroll text of selected window upward ARG lines.
4771 If ARG is omitted or nil, scroll upward by a near full screen.
4772 A near full screen is `next-screen-context-lines' less than a full screen.
4773 Negative ARG means scroll downward.
4774 If ARG is the atom `-', scroll downward by nearly full screen.
4775 When calling from a program, supply as argument a number, nil, or `-'. */)
4776 (Lisp_Object arg)
4778 scroll_command (arg, 1);
4779 return Qnil;
4782 DEFUN ("scroll-down", Fscroll_down, Sscroll_down, 0, 1, "^P",
4783 doc: /* Scroll text of selected window down ARG lines.
4784 If ARG is omitted or nil, scroll down by a near full screen.
4785 A near full screen is `next-screen-context-lines' less than a full screen.
4786 Negative ARG means scroll upward.
4787 If ARG is the atom `-', scroll upward by nearly full screen.
4788 When calling from a program, supply as argument a number, nil, or `-'. */)
4789 (Lisp_Object arg)
4791 scroll_command (arg, -1);
4792 return Qnil;
4795 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling, Sother_window_for_scrolling, 0, 0, 0,
4796 doc: /* Return the other window for \"other window scroll\" commands.
4797 If `other-window-scroll-buffer' is non-nil, a window
4798 showing that buffer is used.
4799 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4800 specifies the window. This takes precedence over
4801 `other-window-scroll-buffer'. */)
4802 (void)
4804 Lisp_Object window;
4806 if (MINI_WINDOW_P (XWINDOW (selected_window))
4807 && !NILP (Vminibuf_scroll_window))
4808 window = Vminibuf_scroll_window;
4809 /* If buffer is specified, scroll that buffer. */
4810 else if (!NILP (Vother_window_scroll_buffer))
4812 window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil);
4813 if (NILP (window))
4814 window = display_buffer (Vother_window_scroll_buffer, Qt, Qnil);
4816 else
4818 /* Nothing specified; look for a neighboring window on the same
4819 frame. */
4820 window = Fnext_window (selected_window, Qnil, Qnil);
4822 if (EQ (window, selected_window))
4823 /* That didn't get us anywhere; look for a window on another
4824 visible frame. */
4826 window = Fnext_window (window, Qnil, Qt);
4827 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window))))
4828 && ! EQ (window, selected_window));
4831 CHECK_LIVE_WINDOW (window);
4833 if (EQ (window, selected_window))
4834 error ("There is no other window");
4836 return window;
4839 DEFUN ("scroll-other-window", Fscroll_other_window, Sscroll_other_window, 0, 1, "P",
4840 doc: /* Scroll next window upward ARG lines; or near full screen if no ARG.
4841 A near full screen is `next-screen-context-lines' less than a full screen.
4842 The next window is the one below the current one; or the one at the top
4843 if the current one is at the bottom. Negative ARG means scroll downward.
4844 If ARG is the atom `-', scroll downward by nearly full screen.
4845 When calling from a program, supply as argument a number, nil, or `-'.
4847 If `other-window-scroll-buffer' is non-nil, scroll the window
4848 showing that buffer, popping the buffer up if necessary.
4849 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4850 specifies the window to scroll. This takes precedence over
4851 `other-window-scroll-buffer'. */)
4852 (Lisp_Object arg)
4854 Lisp_Object window;
4855 struct window *w;
4856 int count = SPECPDL_INDEX ();
4858 window = Fother_window_for_scrolling ();
4859 w = XWINDOW (window);
4861 /* Don't screw up if window_scroll gets an error. */
4862 record_unwind_protect (save_excursion_restore, save_excursion_save ());
4863 ++windows_or_buffers_changed;
4865 Fset_buffer (w->buffer);
4866 SET_PT (marker_position (w->pointm));
4868 if (NILP (arg))
4869 window_scroll (window, 1, 1, 1);
4870 else if (EQ (arg, Qminus))
4871 window_scroll (window, -1, 1, 1);
4872 else
4874 if (CONSP (arg))
4875 arg = Fcar (arg);
4876 CHECK_NUMBER (arg);
4877 window_scroll (window, XINT (arg), 0, 1);
4880 set_marker_both (w->pointm, Qnil, PT, PT_BYTE);
4881 unbind_to (count, Qnil);
4883 return Qnil;
4886 DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 2, "^P\np",
4887 doc: /* Scroll selected window display ARG columns left.
4888 Default for ARG is window width minus 2.
4889 Value is the total amount of leftward horizontal scrolling in
4890 effect after the change.
4891 If SET-MINIMUM is non-nil, the new scroll amount becomes the
4892 lower bound for automatic scrolling, i.e. automatic scrolling
4893 will not scroll a window to a column less than the value returned
4894 by this function. This happens in an interactive call. */)
4895 (register Lisp_Object arg, Lisp_Object set_minimum)
4897 Lisp_Object result;
4898 int hscroll;
4899 struct window *w = XWINDOW (selected_window);
4901 if (NILP (arg))
4902 XSETFASTINT (arg, window_body_cols (w) - 2);
4903 else
4904 arg = Fprefix_numeric_value (arg);
4906 hscroll = XINT (w->hscroll) + XINT (arg);
4907 result = Fset_window_hscroll (selected_window, make_number (hscroll));
4909 if (!NILP (set_minimum))
4910 w->min_hscroll = w->hscroll;
4912 return result;
4915 DEFUN ("scroll-right", Fscroll_right, Sscroll_right, 0, 2, "^P\np",
4916 doc: /* Scroll selected window display ARG columns right.
4917 Default for ARG is window width minus 2.
4918 Value is the total amount of leftward horizontal scrolling in
4919 effect after the change.
4920 If SET-MINIMUM is non-nil, the new scroll amount becomes the
4921 lower bound for automatic scrolling, i.e. automatic scrolling
4922 will not scroll a window to a column less than the value returned
4923 by this function. This happens in an interactive call. */)
4924 (register Lisp_Object arg, Lisp_Object set_minimum)
4926 Lisp_Object result;
4927 int hscroll;
4928 struct window *w = XWINDOW (selected_window);
4930 if (NILP (arg))
4931 XSETFASTINT (arg, window_body_cols (w) - 2);
4932 else
4933 arg = Fprefix_numeric_value (arg);
4935 hscroll = XINT (w->hscroll) - XINT (arg);
4936 result = Fset_window_hscroll (selected_window, make_number (hscroll));
4938 if (!NILP (set_minimum))
4939 w->min_hscroll = w->hscroll;
4941 return result;
4944 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window, Sminibuffer_selected_window, 0, 0, 0,
4945 doc: /* Return the window which was selected when entering the minibuffer.
4946 Returns nil, if selected window is not a minibuffer window. */)
4947 (void)
4949 if (minibuf_level > 0
4950 && MINI_WINDOW_P (XWINDOW (selected_window))
4951 && WINDOW_LIVE_P (minibuf_selected_window))
4952 return minibuf_selected_window;
4954 return Qnil;
4957 /* Value is the number of lines actually displayed in window W,
4958 as opposed to its height. */
4960 static int
4961 displayed_window_lines (struct window *w)
4963 struct it it;
4964 struct text_pos start;
4965 int height = window_box_height (w);
4966 struct buffer *old_buffer;
4967 int bottom_y;
4968 void *itdata = NULL;
4970 if (XBUFFER (w->buffer) != current_buffer)
4972 old_buffer = current_buffer;
4973 set_buffer_internal (XBUFFER (w->buffer));
4975 else
4976 old_buffer = NULL;
4978 /* In case W->start is out of the accessible range, do something
4979 reasonable. This happens in Info mode when Info-scroll-down
4980 calls (recenter -1) while W->start is 1. */
4981 if (XMARKER (w->start)->charpos < BEGV)
4982 SET_TEXT_POS (start, BEGV, BEGV_BYTE);
4983 else if (XMARKER (w->start)->charpos > ZV)
4984 SET_TEXT_POS (start, ZV, ZV_BYTE);
4985 else
4986 SET_TEXT_POS_FROM_MARKER (start, w->start);
4988 itdata = bidi_shelve_cache ();
4989 start_display (&it, w, start);
4990 move_it_vertically (&it, height);
4991 bottom_y = line_bottom_y (&it);
4992 bidi_unshelve_cache (itdata, 0);
4994 /* rms: On a non-window display,
4995 the value of it.vpos at the bottom of the screen
4996 seems to be 1 larger than window_box_height (w).
4997 This kludge fixes a bug whereby (move-to-window-line -1)
4998 when ZV is on the last screen line
4999 moves to the previous screen line instead of the last one. */
5000 if (! FRAME_WINDOW_P (XFRAME (w->frame)))
5001 height++;
5003 /* Add in empty lines at the bottom of the window. */
5004 if (bottom_y < height)
5006 int uy = FRAME_LINE_HEIGHT (it.f);
5007 it.vpos += (height - bottom_y + uy - 1) / uy;
5010 if (old_buffer)
5011 set_buffer_internal (old_buffer);
5013 return it.vpos;
5017 DEFUN ("recenter", Frecenter, Srecenter, 0, 1, "P",
5018 doc: /* Center point in selected window and maybe redisplay frame.
5019 With prefix argument ARG, recenter putting point on screen line ARG
5020 relative to the selected window. If ARG is negative, it counts up from the
5021 bottom of the window. (ARG should be less than the height of the window.)
5023 If ARG is omitted or nil, then recenter with point on the middle line of
5024 the selected window; if the variable `recenter-redisplay' is non-nil,
5025 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5026 is set to `grow-only', this resets the tool-bar's height to the minimum
5027 height needed); if `recenter-redisplay' has the special value `tty',
5028 then only tty frame are redrawn.
5030 Just C-u as prefix means put point in the center of the window
5031 and redisplay normally--don't erase and redraw the frame. */)
5032 (register Lisp_Object arg)
5034 struct window *w = XWINDOW (selected_window);
5035 struct buffer *buf = XBUFFER (w->buffer);
5036 struct buffer *obuf = current_buffer;
5037 int center_p = 0;
5038 EMACS_INT charpos, bytepos;
5039 EMACS_INT iarg IF_LINT (= 0);
5040 int this_scroll_margin;
5042 /* If redisplay is suppressed due to an error, try again. */
5043 obuf->display_error_modiff = 0;
5045 if (NILP (arg))
5047 if (!NILP (Vrecenter_redisplay)
5048 && (!EQ (Vrecenter_redisplay, Qtty)
5049 || !NILP (Ftty_type (selected_frame))))
5051 ptrdiff_t i;
5053 /* Invalidate pixel data calculated for all compositions. */
5054 for (i = 0; i < n_compositions; i++)
5055 composition_table[i]->font = NULL;
5057 WINDOW_XFRAME (w)->minimize_tool_bar_window_p = 1;
5059 Fredraw_frame (WINDOW_FRAME (w));
5060 SET_FRAME_GARBAGED (WINDOW_XFRAME (w));
5063 center_p = 1;
5065 else if (CONSP (arg)) /* Just C-u. */
5066 center_p = 1;
5067 else
5069 arg = Fprefix_numeric_value (arg);
5070 CHECK_NUMBER (arg);
5071 iarg = XINT (arg);
5074 set_buffer_internal (buf);
5076 /* Do this after making BUF current
5077 in case scroll_margin is buffer-local. */
5078 this_scroll_margin =
5079 max (0, min (scroll_margin, XFASTINT (w->total_lines) / 4));
5081 /* Handle centering on a graphical frame specially. Such frames can
5082 have variable-height lines and centering point on the basis of
5083 line counts would lead to strange effects. */
5084 if (FRAME_WINDOW_P (XFRAME (w->frame)))
5086 if (center_p)
5088 struct it it;
5089 struct text_pos pt;
5090 void *itdata = bidi_shelve_cache ();
5092 SET_TEXT_POS (pt, PT, PT_BYTE);
5093 start_display (&it, w, pt);
5094 move_it_vertically_backward (&it, window_box_height (w) / 2);
5095 charpos = IT_CHARPOS (it);
5096 bytepos = IT_BYTEPOS (it);
5097 bidi_unshelve_cache (itdata, 0);
5099 else if (iarg < 0)
5101 struct it it;
5102 struct text_pos pt;
5103 int nlines = min (INT_MAX, -iarg);
5104 int extra_line_spacing;
5105 int h = window_box_height (w);
5106 void *itdata = bidi_shelve_cache ();
5108 iarg = - max (-iarg, this_scroll_margin);
5110 SET_TEXT_POS (pt, PT, PT_BYTE);
5111 start_display (&it, w, pt);
5113 /* Be sure we have the exact height of the full line containing PT. */
5114 move_it_by_lines (&it, 0);
5116 /* The amount of pixels we have to move back is the window
5117 height minus what's displayed in the line containing PT,
5118 and the lines below. */
5119 it.current_y = 0;
5120 it.vpos = 0;
5121 move_it_by_lines (&it, nlines);
5123 if (it.vpos == nlines)
5124 h -= it.current_y;
5125 else
5127 /* Last line has no newline */
5128 h -= line_bottom_y (&it);
5129 it.vpos++;
5132 /* Don't reserve space for extra line spacing of last line. */
5133 extra_line_spacing = it.max_extra_line_spacing;
5135 /* If we can't move down NLINES lines because we hit
5136 the end of the buffer, count in some empty lines. */
5137 if (it.vpos < nlines)
5139 nlines -= it.vpos;
5140 extra_line_spacing = it.extra_line_spacing;
5141 h -= nlines * (FRAME_LINE_HEIGHT (it.f) + extra_line_spacing);
5143 if (h <= 0)
5145 bidi_unshelve_cache (itdata, 0);
5146 return Qnil;
5149 /* Now find the new top line (starting position) of the window. */
5150 start_display (&it, w, pt);
5151 it.current_y = 0;
5152 move_it_vertically_backward (&it, h);
5154 /* If extra line spacing is present, we may move too far
5155 back. This causes the last line to be only partially
5156 visible (which triggers redisplay to recenter that line
5157 in the middle), so move forward.
5158 But ignore extra line spacing on last line, as it is not
5159 considered to be part of the visible height of the line.
5161 h += extra_line_spacing;
5162 while (-it.current_y > h)
5163 move_it_by_lines (&it, 1);
5165 charpos = IT_CHARPOS (it);
5166 bytepos = IT_BYTEPOS (it);
5168 bidi_unshelve_cache (itdata, 0);
5170 else
5172 struct position pos;
5174 iarg = max (iarg, this_scroll_margin);
5176 pos = *vmotion (PT, -iarg, w);
5177 charpos = pos.bufpos;
5178 bytepos = pos.bytepos;
5181 else
5183 struct position pos;
5184 int ht = window_internal_height (w);
5186 if (center_p)
5187 iarg = ht / 2;
5188 else if (iarg < 0)
5189 iarg += ht;
5191 /* Don't let it get into the margin at either top or bottom. */
5192 iarg = max (iarg, this_scroll_margin);
5193 iarg = min (iarg, ht - this_scroll_margin - 1);
5195 pos = *vmotion (PT, - iarg, w);
5196 charpos = pos.bufpos;
5197 bytepos = pos.bytepos;
5200 /* Set the new window start. */
5201 set_marker_both (w->start, w->buffer, charpos, bytepos);
5202 w->window_end_valid = Qnil;
5204 w->optional_new_start = Qt;
5206 if (bytepos == BEGV_BYTE || FETCH_BYTE (bytepos - 1) == '\n')
5207 w->start_at_line_beg = Qt;
5208 else
5209 w->start_at_line_beg = Qnil;
5211 set_buffer_internal (obuf);
5212 return Qnil;
5215 DEFUN ("window-text-height", Fwindow_text_height, Swindow_text_height,
5216 0, 1, 0,
5217 doc: /* Return the height in lines of the text display area of WINDOW.
5218 WINDOW defaults to the selected window.
5220 The return value does not include the mode line, any header line, nor
5221 any partial-height lines in the text display area. */)
5222 (Lisp_Object window)
5224 struct window *w = decode_window (window);
5225 int pixel_height = window_box_height (w);
5226 int line_height = pixel_height / FRAME_LINE_HEIGHT (XFRAME (w->frame));
5227 return make_number (line_height);
5232 DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line,
5233 1, 1, "P",
5234 doc: /* Position point relative to window.
5235 ARG nil means position point at center of window.
5236 Else, ARG specifies vertical position within the window;
5237 zero means top of window, negative means relative to bottom of window. */)
5238 (Lisp_Object arg)
5240 struct window *w = XWINDOW (selected_window);
5241 int lines, start;
5242 Lisp_Object window;
5243 #if 0
5244 int this_scroll_margin;
5245 #endif
5247 if (!(BUFFERP (w->buffer)
5248 && XBUFFER (w->buffer) == current_buffer))
5249 /* This test is needed to make sure PT/PT_BYTE make sense in w->buffer
5250 when passed below to set_marker_both. */
5251 error ("move-to-window-line called from unrelated buffer");
5253 window = selected_window;
5254 start = marker_position (w->start);
5255 if (start < BEGV || start > ZV)
5257 int height = window_internal_height (w);
5258 Fvertical_motion (make_number (- (height / 2)), window);
5259 set_marker_both (w->start, w->buffer, PT, PT_BYTE);
5260 w->start_at_line_beg = Fbolp ();
5261 w->force_start = Qt;
5263 else
5264 Fgoto_char (w->start);
5266 lines = displayed_window_lines (w);
5268 #if 0
5269 this_scroll_margin = max (0, min (scroll_margin, lines / 4));
5270 #endif
5272 if (NILP (arg))
5273 XSETFASTINT (arg, lines / 2);
5274 else
5276 EMACS_INT iarg = XINT (Fprefix_numeric_value (arg));
5278 if (iarg < 0)
5279 iarg = iarg + lines;
5281 #if 0 /* This code would prevent move-to-window-line from moving point
5282 to a place inside the scroll margins (which would cause the
5283 next redisplay to scroll). I wrote this code, but then concluded
5284 it is probably better not to install it. However, it is here
5285 inside #if 0 so as not to lose it. -- rms. */
5287 /* Don't let it get into the margin at either top or bottom. */
5288 iarg = max (iarg, this_scroll_margin);
5289 iarg = min (iarg, lines - this_scroll_margin - 1);
5290 #endif
5292 arg = make_number (iarg);
5295 /* Skip past a partially visible first line. */
5296 if (w->vscroll)
5297 XSETINT (arg, XINT (arg) + 1);
5299 return Fvertical_motion (arg, window);
5304 /***********************************************************************
5305 Window Configuration
5306 ***********************************************************************/
5308 struct save_window_data
5310 struct vectorlike_header header;
5311 Lisp_Object selected_frame;
5312 Lisp_Object current_window;
5313 Lisp_Object current_buffer;
5314 Lisp_Object minibuf_scroll_window;
5315 Lisp_Object minibuf_selected_window;
5316 Lisp_Object root_window;
5317 Lisp_Object focus_frame;
5318 /* A vector, each of whose elements is a struct saved_window
5319 for one window. */
5320 Lisp_Object saved_windows;
5322 /* All fields above are traced by the GC.
5323 From `fame-cols' down, the fields are ignored by the GC. */
5325 int frame_cols, frame_lines, frame_menu_bar_lines;
5326 int frame_tool_bar_lines;
5329 /* This is saved as a Lisp_Vector */
5330 struct saved_window
5332 struct vectorlike_header header;
5334 Lisp_Object window, buffer, start, pointm, mark;
5335 Lisp_Object left_col, top_line, total_cols, total_lines;
5336 Lisp_Object normal_cols, normal_lines;
5337 Lisp_Object hscroll, min_hscroll;
5338 Lisp_Object parent, prev;
5339 Lisp_Object start_at_line_beg;
5340 Lisp_Object display_table;
5341 Lisp_Object left_margin_cols, right_margin_cols;
5342 Lisp_Object left_fringe_width, right_fringe_width, fringes_outside_margins;
5343 Lisp_Object scroll_bar_width, vertical_scroll_bar_type, dedicated;
5344 Lisp_Object splits, nest, window_parameters;
5347 #define SAVED_WINDOW_N(swv,n) \
5348 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5350 DEFUN ("window-configuration-p", Fwindow_configuration_p, Swindow_configuration_p, 1, 1, 0,
5351 doc: /* Return t if OBJECT is a window-configuration object. */)
5352 (Lisp_Object object)
5354 return WINDOW_CONFIGURATIONP (object) ? Qt : Qnil;
5357 DEFUN ("window-configuration-frame", Fwindow_configuration_frame, Swindow_configuration_frame, 1, 1, 0,
5358 doc: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5359 (Lisp_Object config)
5361 register struct save_window_data *data;
5362 struct Lisp_Vector *saved_windows;
5364 CHECK_WINDOW_CONFIGURATION (config);
5366 data = (struct save_window_data *) XVECTOR (config);
5367 saved_windows = XVECTOR (data->saved_windows);
5368 return XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame;
5371 DEFUN ("set-window-configuration", Fset_window_configuration,
5372 Sset_window_configuration, 1, 1, 0,
5373 doc: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5374 CONFIGURATION must be a value previously returned
5375 by `current-window-configuration' (which see).
5376 If CONFIGURATION was made from a frame that is now deleted,
5377 only frame-independent values can be restored. In this case,
5378 the return value is nil. Otherwise the value is t. */)
5379 (Lisp_Object configuration)
5381 register struct save_window_data *data;
5382 struct Lisp_Vector *saved_windows;
5383 Lisp_Object new_current_buffer;
5384 Lisp_Object frame;
5385 Lisp_Object auto_buffer_name;
5386 FRAME_PTR f;
5387 EMACS_INT old_point = -1;
5389 CHECK_WINDOW_CONFIGURATION (configuration);
5391 data = (struct save_window_data *) XVECTOR (configuration);
5392 saved_windows = XVECTOR (data->saved_windows);
5394 new_current_buffer = data->current_buffer;
5395 if (NILP (BVAR (XBUFFER (new_current_buffer), name)))
5396 new_current_buffer = Qnil;
5397 else
5399 if (XBUFFER (new_current_buffer) == current_buffer)
5400 /* The code further down "preserves point" by saving here PT in
5401 old_point and then setting it later back into PT. When the
5402 current-selected-window and the final-selected-window both show
5403 the current buffer, this suffers from the problem that the
5404 current PT is the window-point of the current-selected-window,
5405 while the final PT is the point of the final-selected-window, so
5406 this copy from one PT to the other would end up moving the
5407 window-point of the final-selected-window to the window-point of
5408 the current-selected-window. So we have to be careful which
5409 point of the current-buffer we copy into old_point. */
5410 if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer)
5411 && WINDOWP (selected_window)
5412 && EQ (XWINDOW (selected_window)->buffer, new_current_buffer)
5413 && !EQ (selected_window, data->current_window))
5414 old_point = XMARKER (XWINDOW (data->current_window)->pointm)->charpos;
5415 else
5416 old_point = PT;
5417 else
5418 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
5419 point in new_current_buffer as of the last time this buffer was
5420 used. This can be non-deterministic since it can be changed by
5421 things like jit-lock by mere temporary selection of some random
5422 window that happens to show this buffer.
5423 So if possible we want this arbitrary choice of "which point" to
5424 be the one from the to-be-selected-window so as to prevent this
5425 window's cursor from being copied from another window. */
5426 if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer)
5427 /* If current_window = selected_window, its point is in BUF_PT. */
5428 && !EQ (selected_window, data->current_window))
5429 old_point = XMARKER (XWINDOW (data->current_window)->pointm)->charpos;
5430 else
5431 old_point = BUF_PT (XBUFFER (new_current_buffer));
5434 frame = XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame;
5435 f = XFRAME (frame);
5437 /* If f is a dead frame, don't bother rebuilding its window tree.
5438 However, there is other stuff we should still try to do below. */
5439 if (FRAME_LIVE_P (f))
5441 Lisp_Object window;
5442 Lisp_Object dead_windows = Qnil;
5443 register struct window *w;
5444 register struct saved_window *p;
5445 struct window *root_window;
5446 struct window **leaf_windows;
5447 int n_leaf_windows;
5448 ptrdiff_t k;
5449 int i, n;
5451 /* If the frame has been resized since this window configuration was
5452 made, we change the frame to the size specified in the
5453 configuration, restore the configuration, and then resize it
5454 back. We keep track of the prevailing height in these variables. */
5455 int previous_frame_lines = FRAME_LINES (f);
5456 int previous_frame_cols = FRAME_COLS (f);
5457 int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
5458 int previous_frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f);
5460 /* The mouse highlighting code could get screwed up
5461 if it runs during this. */
5462 BLOCK_INPUT;
5464 if (data->frame_lines != previous_frame_lines
5465 || data->frame_cols != previous_frame_cols)
5466 change_frame_size (f, data->frame_lines,
5467 data->frame_cols, 0, 0, 0);
5468 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5469 if (data->frame_menu_bar_lines
5470 != previous_frame_menu_bar_lines)
5471 x_set_menu_bar_lines (f, make_number (data->frame_menu_bar_lines),
5472 make_number (0));
5473 #ifdef HAVE_WINDOW_SYSTEM
5474 if (data->frame_tool_bar_lines
5475 != previous_frame_tool_bar_lines)
5476 x_set_tool_bar_lines (f, make_number (data->frame_tool_bar_lines),
5477 make_number (0));
5478 #endif
5479 #endif
5481 /* "Swap out" point from the selected window's buffer
5482 into the window itself. (Normally the pointm of the selected
5483 window holds garbage.) We do this now, before
5484 restoring the window contents, and prevent it from
5485 being done later on when we select a new window. */
5486 if (! NILP (XWINDOW (selected_window)->buffer))
5488 w = XWINDOW (selected_window);
5489 set_marker_both (w->pointm,
5490 w->buffer,
5491 BUF_PT (XBUFFER (w->buffer)),
5492 BUF_PT_BYTE (XBUFFER (w->buffer)));
5495 windows_or_buffers_changed++;
5496 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
5498 /* Problem: Freeing all matrices and later allocating them again
5499 is a serious redisplay flickering problem. What we would
5500 really like to do is to free only those matrices not reused
5501 below. */
5502 root_window = XWINDOW (FRAME_ROOT_WINDOW (f));
5503 leaf_windows
5504 = (struct window **) alloca (count_windows (root_window)
5505 * sizeof (struct window *));
5506 n_leaf_windows = get_leaf_windows (root_window, leaf_windows, 0);
5508 /* Kludge Alert!
5509 Mark all windows now on frame as "deleted".
5510 Restoring the new configuration "undeletes" any that are in it.
5512 Save their current buffers in their height fields, since we may
5513 need it later, if a buffer saved in the configuration is now
5514 dead. */
5515 delete_all_subwindows (FRAME_ROOT_WINDOW (f));
5517 for (k = 0; k < saved_windows->header.size; k++)
5519 p = SAVED_WINDOW_N (saved_windows, k);
5520 window = p->window;
5521 w = XWINDOW (window);
5522 w->next = Qnil;
5524 if (!NILP (p->parent))
5525 w->parent = SAVED_WINDOW_N (saved_windows,
5526 XFASTINT (p->parent))->window;
5527 else
5528 w->parent = Qnil;
5530 if (!NILP (p->prev))
5532 w->prev = SAVED_WINDOW_N (saved_windows,
5533 XFASTINT (p->prev))->window;
5534 XWINDOW (w->prev)->next = p->window;
5536 else
5538 w->prev = Qnil;
5539 if (!NILP (w->parent))
5541 if (EQ (p->total_cols, XWINDOW (w->parent)->total_cols))
5543 XWINDOW (w->parent)->vchild = p->window;
5544 XWINDOW (w->parent)->hchild = Qnil;
5546 else
5548 XWINDOW (w->parent)->hchild = p->window;
5549 XWINDOW (w->parent)->vchild = Qnil;
5554 /* If we squirreled away the buffer in the window's height,
5555 restore it now. */
5556 if (BUFFERP (w->total_lines))
5557 w->buffer = w->total_lines;
5558 w->left_col = p->left_col;
5559 w->top_line = p->top_line;
5560 w->total_cols = p->total_cols;
5561 w->total_lines = p->total_lines;
5562 w->normal_cols = p->normal_cols;
5563 w->normal_lines = p->normal_lines;
5564 w->hscroll = p->hscroll;
5565 w->min_hscroll = p->min_hscroll;
5566 w->display_table = p->display_table;
5567 w->left_margin_cols = p->left_margin_cols;
5568 w->right_margin_cols = p->right_margin_cols;
5569 w->left_fringe_width = p->left_fringe_width;
5570 w->right_fringe_width = p->right_fringe_width;
5571 w->fringes_outside_margins = p->fringes_outside_margins;
5572 w->scroll_bar_width = p->scroll_bar_width;
5573 w->vertical_scroll_bar_type = p->vertical_scroll_bar_type;
5574 w->dedicated = p->dedicated;
5575 w->splits = p->splits;
5576 w->nest = p->nest;
5577 w->window_parameters = p->window_parameters;
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 = 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
5604 real. */
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),
5609 w->buffer);
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 = Qt;
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 = Qt;
5625 else
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
5634 range. */
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 = Qt;
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)
5660 = 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,
5671 0, 0, 0);
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),
5675 make_number (0));
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),
5679 make_number (0));
5680 #endif
5681 #endif
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 xassert (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))
5694 ++n;
5697 adjust_glyphs (f);
5698 UNBLOCK_INPUT;
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
5712 selected window. */
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 /* Delete all subwindows reachable via the next, vchild, and hchild
5730 slots of WINDOW. */
5731 void
5732 delete_all_subwindows (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_subwindows (w->next);
5742 w->total_lines = w->buffer; /* See Fset_window_configuration for excuse. */
5744 if (!NILP (w->vchild))
5746 delete_all_subwindows (w->vchild);
5747 w->vchild = Qnil;
5749 else if (!NILP (w->hchild))
5751 delete_all_subwindows (w->hchild);
5752 w->hchild = Qnil;
5754 else if (!NILP (w->buffer))
5756 unshow_buffer (w);
5757 unchain_marker (XMARKER (w->pointm));
5758 unchain_marker (XMARKER (w->start));
5759 w->buffer = Qnil;
5762 Vwindow_list = Qnil;
5765 static int
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));
5775 return count;
5779 /* Fill vector FLAT with leaf windows under W, starting at index I.
5780 Value is last index + 1. */
5781 static int
5782 get_leaf_windows (struct window *w, struct window **flat, int i)
5784 while (w)
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);
5790 else
5791 flat[i++] = w;
5793 w = NILP (w->next) ? 0 : XWINDOW (w->next);
5796 return i;
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 meaningfull glyph
5802 can be returned. */
5803 struct glyph *
5804 get_phys_cursor_glyph (struct window *w)
5806 struct glyph_row *row;
5807 struct glyph *glyph;
5809 if (w->phys_cursor.vpos >= 0
5810 && w->phys_cursor.vpos < w->current_matrix->nrows
5811 && (row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos),
5812 row->enabled_p)
5813 && row->used[TEXT_AREA] > w->phys_cursor.hpos)
5814 glyph = row->glyphs[TEXT_AREA] + w->phys_cursor.hpos;
5815 else
5816 glyph = NULL;
5818 return glyph;
5822 static int
5823 save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
5825 register struct saved_window *p;
5826 register struct window *w;
5827 register Lisp_Object tem;
5829 for (;!NILP (window); window = w->next)
5831 p = SAVED_WINDOW_N (vector, i);
5832 w = XWINDOW (window);
5834 XSETFASTINT (w->temslot, i); i++;
5835 p->window = window;
5836 p->buffer = w->buffer;
5837 p->left_col = w->left_col;
5838 p->top_line = w->top_line;
5839 p->total_cols = w->total_cols;
5840 p->total_lines = w->total_lines;
5841 p->normal_cols = w->normal_cols;
5842 p->normal_lines = w->normal_lines;
5843 p->hscroll = w->hscroll;
5844 p->min_hscroll = w->min_hscroll;
5845 p->display_table = w->display_table;
5846 p->left_margin_cols = w->left_margin_cols;
5847 p->right_margin_cols = w->right_margin_cols;
5848 p->left_fringe_width = w->left_fringe_width;
5849 p->right_fringe_width = w->right_fringe_width;
5850 p->fringes_outside_margins = w->fringes_outside_margins;
5851 p->scroll_bar_width = w->scroll_bar_width;
5852 p->vertical_scroll_bar_type = w->vertical_scroll_bar_type;
5853 p->dedicated = w->dedicated;
5854 p->splits = w->splits;
5855 p->nest = w->nest;
5856 p->window_parameters = w->window_parameters;
5857 if (!NILP (w->buffer))
5859 /* Save w's value of point in the window configuration.
5860 If w is the selected window, then get the value of point
5861 from the buffer; pointm is garbage in the selected window. */
5862 if (EQ (window, selected_window))
5864 p->pointm = Fmake_marker ();
5865 set_marker_both (p->pointm, w->buffer,
5866 BUF_PT (XBUFFER (w->buffer)),
5867 BUF_PT_BYTE (XBUFFER (w->buffer)));
5869 else
5870 p->pointm = Fcopy_marker (w->pointm, Qnil);
5872 p->start = Fcopy_marker (w->start, Qnil);
5873 p->start_at_line_beg = w->start_at_line_beg;
5875 tem = BVAR (XBUFFER (w->buffer), mark);
5876 p->mark = Fcopy_marker (tem, Qnil);
5878 else
5880 p->pointm = Qnil;
5881 p->start = Qnil;
5882 p->mark = Qnil;
5883 p->start_at_line_beg = Qnil;
5886 if (NILP (w->parent))
5887 p->parent = Qnil;
5888 else
5889 p->parent = XWINDOW (w->parent)->temslot;
5891 if (NILP (w->prev))
5892 p->prev = Qnil;
5893 else
5894 p->prev = XWINDOW (w->prev)->temslot;
5896 if (!NILP (w->vchild))
5897 i = save_window_save (w->vchild, vector, i);
5898 if (!NILP (w->hchild))
5899 i = save_window_save (w->hchild, vector, i);
5902 return i;
5905 DEFUN ("current-window-configuration", Fcurrent_window_configuration,
5906 Scurrent_window_configuration, 0, 1, 0,
5907 doc: /* Return an object representing the current window configuration of FRAME.
5908 If FRAME is nil or omitted, use the selected frame.
5909 This describes the number of windows, their sizes and current buffers,
5910 and for each displayed buffer, where display starts, and the positions of
5911 point and mark. An exception is made for point in the current buffer:
5912 its value is -not- saved.
5913 This also records the currently selected frame, and FRAME's focus
5914 redirection (see `redirect-frame-focus'). */)
5915 (Lisp_Object frame)
5917 register Lisp_Object tem;
5918 register int n_windows;
5919 register struct save_window_data *data;
5920 register int i;
5921 FRAME_PTR f;
5923 if (NILP (frame))
5924 frame = selected_frame;
5925 CHECK_LIVE_FRAME (frame);
5926 f = XFRAME (frame);
5928 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
5929 data = ALLOCATE_PSEUDOVECTOR (struct save_window_data, frame_cols,
5930 PVEC_WINDOW_CONFIGURATION);
5932 data->frame_cols = FRAME_COLS (f);
5933 data->frame_lines = FRAME_LINES (f);
5934 data->frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
5935 data->frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f);
5936 data->selected_frame = selected_frame;
5937 data->current_window = FRAME_SELECTED_WINDOW (f);
5938 XSETBUFFER (data->current_buffer, current_buffer);
5939 data->minibuf_scroll_window = minibuf_level > 0 ? Vminibuf_scroll_window : Qnil;
5940 data->minibuf_selected_window = minibuf_level > 0 ? minibuf_selected_window : Qnil;
5941 data->root_window = FRAME_ROOT_WINDOW (f);
5942 data->focus_frame = FRAME_FOCUS_FRAME (f);
5943 tem = Fmake_vector (make_number (n_windows), Qnil);
5944 data->saved_windows = tem;
5945 for (i = 0; i < n_windows; i++)
5946 XVECTOR (tem)->contents[i]
5947 = Fmake_vector (make_number (VECSIZE (struct saved_window)), Qnil);
5948 save_window_save (FRAME_ROOT_WINDOW (f), XVECTOR (tem), 0);
5949 XSETWINDOW_CONFIGURATION (tem, data);
5950 return (tem);
5953 /***********************************************************************
5954 Marginal Areas
5955 ***********************************************************************/
5957 DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins,
5958 2, 3, 0,
5959 doc: /* Set width of marginal areas of window WINDOW.
5960 If WINDOW is nil, set margins of the currently selected window.
5961 Second arg LEFT-WIDTH specifies the number of character cells to
5962 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
5963 does the same for the right marginal area. A nil width parameter
5964 means no margin. */)
5965 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width)
5967 struct window *w = decode_window (window);
5969 /* Translate negative or zero widths to nil.
5970 Margins that are too wide have to be checked elsewhere. */
5972 if (!NILP (left_width))
5974 CHECK_NUMBER (left_width);
5975 if (XINT (left_width) <= 0)
5976 left_width = Qnil;
5979 if (!NILP (right_width))
5981 CHECK_NUMBER (right_width);
5982 if (XINT (right_width) <= 0)
5983 right_width = Qnil;
5986 if (!EQ (w->left_margin_cols, left_width)
5987 || !EQ (w->right_margin_cols, right_width))
5989 w->left_margin_cols = left_width;
5990 w->right_margin_cols = right_width;
5992 adjust_window_margins (w);
5994 ++windows_or_buffers_changed;
5995 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
5998 return Qnil;
6002 DEFUN ("window-margins", Fwindow_margins, Swindow_margins,
6003 0, 1, 0,
6004 doc: /* Get width of marginal areas of window WINDOW.
6005 If WINDOW is omitted or nil, use the currently selected window.
6006 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6007 If a marginal area does not exist, its width will be returned
6008 as nil. */)
6009 (Lisp_Object window)
6011 struct window *w = decode_window (window);
6012 return Fcons (w->left_margin_cols, w->right_margin_cols);
6017 /***********************************************************************
6018 Fringes
6019 ***********************************************************************/
6021 DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes,
6022 2, 4, 0,
6023 doc: /* Set the fringe widths of window WINDOW.
6024 If WINDOW is nil, set the fringe widths of the currently selected
6025 window.
6026 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6027 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6028 fringe width. If a fringe width arg is nil, that means to use the
6029 frame's default fringe width. Default fringe widths can be set with
6030 the command `set-fringe-style'.
6031 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6032 outside of the display margins. By default, fringes are drawn between
6033 display marginal areas and the text area. */)
6034 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width, Lisp_Object outside_margins)
6036 struct window *w = decode_window (window);
6038 if (!NILP (left_width))
6039 CHECK_NATNUM (left_width);
6040 if (!NILP (right_width))
6041 CHECK_NATNUM (right_width);
6043 /* Do nothing on a tty. */
6044 if (FRAME_WINDOW_P (WINDOW_XFRAME (w))
6045 && (!EQ (w->left_fringe_width, left_width)
6046 || !EQ (w->right_fringe_width, right_width)
6047 || !EQ (w->fringes_outside_margins, outside_margins)))
6049 w->left_fringe_width = left_width;
6050 w->right_fringe_width = right_width;
6051 w->fringes_outside_margins = outside_margins;
6053 adjust_window_margins (w);
6055 clear_glyph_matrix (w->current_matrix);
6056 w->window_end_valid = Qnil;
6058 ++windows_or_buffers_changed;
6059 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6062 return Qnil;
6066 DEFUN ("window-fringes", Fwindow_fringes, Swindow_fringes,
6067 0, 1, 0,
6068 doc: /* Get width of fringes of window WINDOW.
6069 If WINDOW is omitted or nil, use the currently selected window.
6070 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6071 (Lisp_Object window)
6073 struct window *w = decode_window (window);
6075 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w)),
6076 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w)),
6077 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
6078 ? Qt : Qnil), Qnil)));
6083 /***********************************************************************
6084 Scroll bars
6085 ***********************************************************************/
6087 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars,
6088 Sset_window_scroll_bars, 2, 4, 0,
6089 doc: /* Set width and type of scroll bars of window WINDOW.
6090 If window is nil, set scroll bars of the currently selected window.
6091 Second parameter WIDTH specifies the pixel width for the scroll bar;
6092 this is automatically adjusted to a multiple of the frame column width.
6093 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6094 bar: left, right, or nil.
6095 If WIDTH is nil, use the frame's scroll-bar width.
6096 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6097 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6098 (Lisp_Object window, Lisp_Object width, Lisp_Object vertical_type, Lisp_Object horizontal_type)
6100 struct window *w = decode_window (window);
6102 if (!NILP (width))
6104 CHECK_NATNUM (width);
6106 if (XINT (width) == 0)
6107 vertical_type = Qnil;
6110 if (!(NILP (vertical_type)
6111 || EQ (vertical_type, Qleft)
6112 || EQ (vertical_type, Qright)
6113 || EQ (vertical_type, Qt)))
6114 error ("Invalid type of vertical scroll bar");
6116 if (!EQ (w->scroll_bar_width, width)
6117 || !EQ (w->vertical_scroll_bar_type, vertical_type))
6119 w->scroll_bar_width = width;
6120 w->vertical_scroll_bar_type = vertical_type;
6122 adjust_window_margins (w);
6124 clear_glyph_matrix (w->current_matrix);
6125 w->window_end_valid = Qnil;
6127 ++windows_or_buffers_changed;
6128 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6131 return Qnil;
6135 DEFUN ("window-scroll-bars", Fwindow_scroll_bars, Swindow_scroll_bars,
6136 0, 1, 0,
6137 doc: /* Get width and type of scroll bars of window WINDOW.
6138 If WINDOW is omitted or nil, use the currently selected window.
6139 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6140 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6141 value. */)
6142 (Lisp_Object window)
6144 struct window *w = decode_window (window);
6145 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
6146 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
6147 : WINDOW_SCROLL_BAR_AREA_WIDTH (w))),
6148 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w)),
6149 Fcons (w->vertical_scroll_bar_type,
6150 Fcons (Qnil, Qnil))));
6155 /***********************************************************************
6156 Smooth scrolling
6157 ***********************************************************************/
6159 DEFUN ("window-vscroll", Fwindow_vscroll, Swindow_vscroll, 0, 2, 0,
6160 doc: /* Return the amount by which WINDOW is scrolled vertically.
6161 Use the selected window if WINDOW is nil or omitted.
6162 Normally, value is a multiple of the canonical character height of WINDOW;
6163 optional second arg PIXELS-P means value is measured in pixels. */)
6164 (Lisp_Object window, Lisp_Object pixels_p)
6166 Lisp_Object result;
6167 struct frame *f;
6168 struct window *w;
6170 if (NILP (window))
6171 window = selected_window;
6172 else
6173 CHECK_WINDOW (window);
6174 w = XWINDOW (window);
6175 f = XFRAME (w->frame);
6177 if (FRAME_WINDOW_P (f))
6178 result = (NILP (pixels_p)
6179 ? FRAME_CANON_Y_FROM_PIXEL_Y (f, -w->vscroll)
6180 : make_number (-w->vscroll));
6181 else
6182 result = make_number (0);
6183 return result;
6187 DEFUN ("set-window-vscroll", Fset_window_vscroll, Sset_window_vscroll,
6188 2, 3, 0,
6189 doc: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6190 WINDOW nil means use the selected window. Normally, VSCROLL is a
6191 non-negative multiple of the canonical character height of WINDOW;
6192 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
6193 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6194 corresponds to an integral number of pixels. The return value is the
6195 result of this rounding.
6196 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6197 (Lisp_Object window, Lisp_Object vscroll, Lisp_Object pixels_p)
6199 struct window *w;
6200 struct frame *f;
6202 if (NILP (window))
6203 window = selected_window;
6204 else
6205 CHECK_WINDOW (window);
6206 CHECK_NUMBER_OR_FLOAT (vscroll);
6208 w = XWINDOW (window);
6209 f = XFRAME (w->frame);
6211 if (FRAME_WINDOW_P (f))
6213 int old_dy = w->vscroll;
6215 w->vscroll = - (NILP (pixels_p)
6216 ? FRAME_LINE_HEIGHT (f) * XFLOATINT (vscroll)
6217 : XFLOATINT (vscroll));
6218 w->vscroll = min (w->vscroll, 0);
6220 if (w->vscroll != old_dy)
6222 /* Adjust glyph matrix of the frame if the virtual display
6223 area becomes larger than before. */
6224 if (w->vscroll < 0 && w->vscroll < old_dy)
6225 adjust_glyphs (f);
6227 /* Prevent redisplay shortcuts. */
6228 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
6232 return Fwindow_vscroll (window, pixels_p);
6236 /* Call FN for all leaf windows on frame F. FN is called with the
6237 first argument being a pointer to the leaf window, and with
6238 additional argument USER_DATA. Stops when FN returns 0. */
6240 static void
6241 foreach_window (struct frame *f, int (*fn) (struct window *, void *),
6242 void *user_data)
6244 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
6245 if (WINDOWP (FRAME_ROOT_WINDOW (f)))
6246 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f)), fn, user_data);
6250 /* Helper function for foreach_window. Call FN for all leaf windows
6251 reachable from W. FN is called with the first argument being a
6252 pointer to the leaf window, and with additional argument USER_DATA.
6253 Stop when FN returns 0. Value is 0 if stopped by FN. */
6255 static int
6256 foreach_window_1 (struct window *w, int (*fn) (struct window *, void *), void *user_data)
6258 int cont;
6260 for (cont = 1; w && cont;)
6262 if (!NILP (w->hchild))
6263 cont = foreach_window_1 (XWINDOW (w->hchild), fn, user_data);
6264 else if (!NILP (w->vchild))
6265 cont = foreach_window_1 (XWINDOW (w->vchild), fn, user_data);
6266 else
6267 cont = fn (w, user_data);
6269 w = NILP (w->next) ? 0 : XWINDOW (w->next);
6272 return cont;
6276 /* Freeze or unfreeze the window start of W unless it is a
6277 mini-window or the selected window. FREEZE_P non-null means freeze
6278 the window start. */
6280 static int
6281 freeze_window_start (struct window *w, void *freeze_p)
6283 if (MINI_WINDOW_P (w)
6284 || (WINDOWP (selected_window) /* Can be nil in corner cases. */
6285 && (w == XWINDOW (selected_window)
6286 || (MINI_WINDOW_P (XWINDOW (selected_window))
6287 && ! NILP (Vminibuf_scroll_window)
6288 && w == XWINDOW (Vminibuf_scroll_window)))))
6289 freeze_p = NULL;
6291 w->frozen_window_start_p = freeze_p != NULL;
6292 return 1;
6296 /* Freeze or unfreeze the window starts of all leaf windows on frame
6297 F, except the selected window and a mini-window. FREEZE_P non-zero
6298 means freeze the window start. */
6300 void
6301 freeze_window_starts (struct frame *f, int freeze_p)
6303 foreach_window (f, freeze_window_start, (void *) (freeze_p ? f : 0));
6307 /***********************************************************************
6308 Initialization
6309 ***********************************************************************/
6311 /* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2
6312 describe the same state of affairs. This is used by Fequal.
6314 ignore_positions non-zero means ignore non-matching scroll positions
6315 and the like.
6317 This ignores a couple of things like the dedicatedness status of
6318 window, splits, nest and the like. This might have to be fixed. */
6321 compare_window_configurations (Lisp_Object configuration1, Lisp_Object configuration2, int ignore_positions)
6323 register struct save_window_data *d1, *d2;
6324 struct Lisp_Vector *sws1, *sws2;
6325 ptrdiff_t i;
6327 CHECK_WINDOW_CONFIGURATION (configuration1);
6328 CHECK_WINDOW_CONFIGURATION (configuration2);
6330 d1 = (struct save_window_data *) XVECTOR (configuration1);
6331 d2 = (struct save_window_data *) XVECTOR (configuration2);
6332 sws1 = XVECTOR (d1->saved_windows);
6333 sws2 = XVECTOR (d2->saved_windows);
6335 /* Frame settings must match. */
6336 if (d1->frame_cols != d2->frame_cols
6337 || d1->frame_lines != d2->frame_lines
6338 || d1->frame_menu_bar_lines != d2->frame_menu_bar_lines
6339 || !EQ (d1->selected_frame, d2->selected_frame)
6340 || !EQ (d1->current_buffer, d2->current_buffer)
6341 || (!ignore_positions
6342 && (!EQ (d1->minibuf_scroll_window, d2->minibuf_scroll_window)
6343 || !EQ (d1->minibuf_selected_window, d2->minibuf_selected_window)))
6344 || !EQ (d1->focus_frame, d2->focus_frame)
6345 /* Verify that the two configurations have the same number of windows. */
6346 || sws1->header.size != sws2->header.size)
6347 return 0;
6349 for (i = 0; i < sws1->header.size; i++)
6351 struct saved_window *sw1, *sw2;
6353 sw1 = SAVED_WINDOW_N (sws1, i);
6354 sw2 = SAVED_WINDOW_N (sws2, i);
6356 if (
6357 /* The "current" windows in the two configurations must
6358 correspond to each other. */
6359 EQ (d1->current_window, sw1->window)
6360 != EQ (d2->current_window, sw2->window)
6361 /* Windows' buffers must match. */
6362 || !EQ (sw1->buffer, sw2->buffer)
6363 || !EQ (sw1->left_col, sw2->left_col)
6364 || !EQ (sw1->top_line, sw2->top_line)
6365 || !EQ (sw1->total_cols, sw2->total_cols)
6366 || !EQ (sw1->total_lines, sw2->total_lines)
6367 || !EQ (sw1->display_table, sw2->display_table)
6368 /* The next two disjuncts check the window structure for
6369 equality. */
6370 || !EQ (sw1->parent, sw2->parent)
6371 || !EQ (sw1->prev, sw2->prev)
6372 || (!ignore_positions
6373 && (!EQ (sw1->hscroll, sw2->hscroll)
6374 || !EQ (sw1->min_hscroll, sw2->min_hscroll)
6375 || !EQ (sw1->start_at_line_beg, sw2->start_at_line_beg)
6376 || NILP (Fequal (sw1->start, sw2->start))
6377 || NILP (Fequal (sw1->pointm, sw2->pointm))
6378 || NILP (Fequal (sw1->mark, sw2->mark))))
6379 || !EQ (sw1->left_margin_cols, sw2->left_margin_cols)
6380 || !EQ (sw1->right_margin_cols, sw2->right_margin_cols)
6381 || !EQ (sw1->left_fringe_width, sw2->left_fringe_width)
6382 || !EQ (sw1->right_fringe_width, sw2->right_fringe_width)
6383 || !EQ (sw1->fringes_outside_margins, sw2->fringes_outside_margins)
6384 || !EQ (sw1->scroll_bar_width, sw2->scroll_bar_width)
6385 || !EQ (sw1->vertical_scroll_bar_type, sw2->vertical_scroll_bar_type))
6386 return 0;
6389 return 1;
6392 DEFUN ("compare-window-configurations", Fcompare_window_configurations,
6393 Scompare_window_configurations, 2, 2, 0,
6394 doc: /* Compare two window configurations as regards the structure of windows.
6395 This function ignores details such as the values of point and mark
6396 and scrolling positions. */)
6397 (Lisp_Object x, Lisp_Object y)
6399 if (compare_window_configurations (x, y, 1))
6400 return Qt;
6401 return Qnil;
6404 void
6405 init_window_once (void)
6407 struct frame *f = make_initial_frame ();
6408 XSETFRAME (selected_frame, f);
6409 Vterminal_frame = selected_frame;
6410 minibuf_window = f->minibuffer_window;
6411 selected_window = f->selected_window;
6412 last_nonminibuf_frame = f;
6414 window_initialized = 1;
6417 void
6418 init_window (void)
6420 Vwindow_list = Qnil;
6423 void
6424 syms_of_window (void)
6426 DEFSYM (Qscroll_up, "scroll-up");
6427 DEFSYM (Qscroll_down, "scroll-down");
6428 DEFSYM (Qscroll_command, "scroll-command");
6430 Fput (Qscroll_up, Qscroll_command, Qt);
6431 Fput (Qscroll_down, Qscroll_command, Qt);
6433 DEFSYM (Qwindow_configuration_change_hook, "window-configuration-change-hook");
6434 DEFSYM (Qwindowp, "windowp");
6435 DEFSYM (Qwindow_configuration_p, "window-configuration-p");
6436 DEFSYM (Qwindow_live_p, "window-live-p");
6437 DEFSYM (Qwindow_deletable_p, "window-deletable-p");
6438 DEFSYM (Qdelete_window, "delete-window");
6439 DEFSYM (Qwindow_resize_root_window, "window--resize-root-window");
6440 DEFSYM (Qwindow_resize_root_window_vertically, "window--resize-root-window-vertically");
6441 DEFSYM (Qsafe, "safe");
6442 DEFSYM (Qdisplay_buffer, "display-buffer");
6443 DEFSYM (Qreplace_buffer_in_windows, "replace-buffer-in-windows");
6444 DEFSYM (Qrecord_window_buffer, "record-window-buffer");
6445 DEFSYM (Qget_mru_window, "get-mru-window");
6446 DEFSYM (Qtemp_buffer_show_hook, "temp-buffer-show-hook");
6447 DEFSYM (Qabove, "above");
6448 DEFSYM (Qbelow, "below");
6449 DEFSYM (Qauto_buffer_name, "auto-buffer-name");
6451 staticpro (&Vwindow_list);
6453 minibuf_selected_window = Qnil;
6454 staticpro (&minibuf_selected_window);
6456 window_scroll_pixel_based_preserve_x = -1;
6457 window_scroll_pixel_based_preserve_y = -1;
6458 window_scroll_preserve_hpos = -1;
6459 window_scroll_preserve_vpos = -1;
6461 DEFVAR_LISP ("temp-buffer-show-function", Vtemp_buffer_show_function,
6462 doc: /* Non-nil means call as function to display a help buffer.
6463 The function is called with one argument, the buffer to be displayed.
6464 Used by `with-output-to-temp-buffer'.
6465 If this function is used, then it must do the entire job of showing
6466 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6467 Vtemp_buffer_show_function = Qnil;
6469 DEFVAR_LISP ("minibuffer-scroll-window", Vminibuf_scroll_window,
6470 doc: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6471 Vminibuf_scroll_window = Qnil;
6473 DEFVAR_BOOL ("mode-line-in-non-selected-windows", mode_line_in_non_selected_windows,
6474 doc: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6475 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6476 is displayed in the `mode-line' face. */);
6477 mode_line_in_non_selected_windows = 1;
6479 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer,
6480 doc: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6481 Vother_window_scroll_buffer = Qnil;
6483 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p,
6484 doc: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
6485 auto_window_vscroll_p = 1;
6487 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines,
6488 doc: /* Number of lines of continuity when scrolling by screenfuls. */);
6489 next_screen_context_lines = 2;
6491 DEFVAR_LISP ("scroll-preserve-screen-position",
6492 Vscroll_preserve_screen_position,
6493 doc: /* Controls if scroll commands move point to keep its screen position unchanged.
6494 A value of nil means point does not keep its screen position except
6495 at the scroll margin or window boundary respectively.
6496 A value of t means point keeps its screen position if the scroll
6497 command moved it vertically out of the window, e.g. when scrolling
6498 by full screens.
6499 Any other value means point always keeps its screen position.
6500 Scroll commands should have the `scroll-command' property
6501 on their symbols to be controlled by this variable. */);
6502 Vscroll_preserve_screen_position = Qnil;
6504 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type,
6505 doc: /* Type of marker to use for `window-point'. */);
6506 Vwindow_point_insertion_type = Qnil;
6508 DEFVAR_LISP ("window-configuration-change-hook",
6509 Vwindow_configuration_change_hook,
6510 doc: /* Functions to call when window configuration changes.
6511 The buffer-local part is run once per window, with the relevant window
6512 selected; while the global part is run only once for the modified frame,
6513 with the relevant frame selected. */);
6514 Vwindow_configuration_change_hook = Qnil;
6516 DEFVAR_LISP ("recenter-redisplay", Vrecenter_redisplay,
6517 doc: /* If non-nil, then the `recenter' command with a nil argument
6518 will redraw the entire frame; the special value `tty' causes the
6519 frame to be redrawn only if it is a tty frame. */);
6520 Vrecenter_redisplay = Qtty;
6522 DEFVAR_LISP ("window-splits", Vwindow_splits,
6523 doc: /* Non-nil means splitting windows is handled specially.
6524 If this variable is nil, splitting a window gets the entire screen space
6525 for displaying the new window from the window to split. If this
6526 variable is non-nil, splitting a window may resize all windows in the
6527 same combination. This also allows to split a window that is otherwise
6528 too small or of fixed size.
6530 The value of this variable is also assigned to the split status of the
6531 new window and, provided the old and new window form a new combination,
6532 to the window that was split as well. The split status of a window can
6533 be retrieved with the function `window-splits' and altered by the
6534 function `set-window-splits'.
6536 If the value of the variable `window-nest' is non-nil, the space for the
6537 new window is exclusively taken from the window that shall be split, but
6538 the split status of the window that is split as well as that of the new
6539 window are still set to the value of this variable. */);
6540 Vwindow_splits = Qnil;
6542 DEFVAR_LISP ("window-nest", Vwindow_nest,
6543 doc: /* Non-nil means splitting a window makes a new parent window.
6544 If this variable is nil, splitting a window will create a new parent
6545 window only if the window has no parent window or the window shall
6546 become a combination orthogonal to the one it it is part of.
6548 If this variable is non-nil, splitting a window always creates a new
6549 parent window. If all splits behave this way, each frame's window tree
6550 is a binary tree and every window but the frame's root window has
6551 exactly one sibling.
6553 The value of this variable is also assigned to the nest status of the
6554 new parent window. The nest status of a window can be retrieved via the
6555 function `window-nest' and altered by the function `set-window-nest'. */);
6556 Vwindow_nest = Qnil;
6558 defsubr (&Sselected_window);
6559 defsubr (&Sminibuffer_window);
6560 defsubr (&Swindow_minibuffer_p);
6561 defsubr (&Swindowp);
6562 defsubr (&Swindow_live_p);
6563 defsubr (&Swindow_frame);
6564 defsubr (&Sframe_root_window);
6565 defsubr (&Sframe_first_window);
6566 defsubr (&Sframe_selected_window);
6567 defsubr (&Sset_frame_selected_window);
6568 defsubr (&Spos_visible_in_window_p);
6569 defsubr (&Swindow_line_height);
6570 defsubr (&Swindow_buffer);
6571 defsubr (&Swindow_parent);
6572 defsubr (&Swindow_top_child);
6573 defsubr (&Swindow_left_child);
6574 defsubr (&Swindow_next_sibling);
6575 defsubr (&Swindow_prev_sibling);
6576 defsubr (&Swindow_splits);
6577 defsubr (&Sset_window_splits);
6578 defsubr (&Swindow_nest);
6579 defsubr (&Sset_window_nest);
6580 defsubr (&Swindow_use_time);
6581 defsubr (&Swindow_top_line);
6582 defsubr (&Swindow_left_column);
6583 defsubr (&Swindow_total_size);
6584 defsubr (&Swindow_normal_size);
6585 defsubr (&Swindow_new_total);
6586 defsubr (&Swindow_new_normal);
6587 defsubr (&Sset_window_new_total);
6588 defsubr (&Sset_window_new_normal);
6589 defsubr (&Swindow_resize_apply);
6590 defsubr (&Swindow_body_size);
6591 defsubr (&Swindow_hscroll);
6592 defsubr (&Sset_window_hscroll);
6593 defsubr (&Swindow_redisplay_end_trigger);
6594 defsubr (&Sset_window_redisplay_end_trigger);
6595 defsubr (&Swindow_edges);
6596 defsubr (&Swindow_pixel_edges);
6597 defsubr (&Swindow_absolute_pixel_edges);
6598 defsubr (&Swindow_inside_edges);
6599 defsubr (&Swindow_inside_pixel_edges);
6600 defsubr (&Swindow_inside_absolute_pixel_edges);
6601 defsubr (&Scoordinates_in_window_p);
6602 defsubr (&Swindow_at);
6603 defsubr (&Swindow_point);
6604 defsubr (&Swindow_start);
6605 defsubr (&Swindow_end);
6606 defsubr (&Sset_window_point);
6607 defsubr (&Sset_window_start);
6608 defsubr (&Swindow_dedicated_p);
6609 defsubr (&Sset_window_dedicated_p);
6610 defsubr (&Swindow_display_table);
6611 defsubr (&Sset_window_display_table);
6612 defsubr (&Snext_window);
6613 defsubr (&Sprevious_window);
6614 defsubr (&Sget_buffer_window);
6615 defsubr (&Sdelete_other_windows_internal);
6616 defsubr (&Sdelete_window_internal);
6617 defsubr (&Sresize_mini_window_internal);
6618 defsubr (&Sset_window_buffer);
6619 defsubr (&Srun_window_configuration_change_hook);
6620 defsubr (&Sselect_window);
6621 defsubr (&Sforce_window_update);
6622 defsubr (&Stemp_output_buffer_show);
6623 defsubr (&Ssplit_window_internal);
6624 defsubr (&Sscroll_up);
6625 defsubr (&Sscroll_down);
6626 defsubr (&Sscroll_left);
6627 defsubr (&Sscroll_right);
6628 defsubr (&Sother_window_for_scrolling);
6629 defsubr (&Sscroll_other_window);
6630 defsubr (&Sminibuffer_selected_window);
6631 defsubr (&Srecenter);
6632 defsubr (&Swindow_text_height);
6633 defsubr (&Smove_to_window_line);
6634 defsubr (&Swindow_configuration_p);
6635 defsubr (&Swindow_configuration_frame);
6636 defsubr (&Sset_window_configuration);
6637 defsubr (&Scurrent_window_configuration);
6638 defsubr (&Sset_window_margins);
6639 defsubr (&Swindow_margins);
6640 defsubr (&Sset_window_fringes);
6641 defsubr (&Swindow_fringes);
6642 defsubr (&Sset_window_scroll_bars);
6643 defsubr (&Swindow_scroll_bars);
6644 defsubr (&Swindow_vscroll);
6645 defsubr (&Sset_window_vscroll);
6646 defsubr (&Scompare_window_configurations);
6647 defsubr (&Swindow_list);
6648 defsubr (&Swindow_list_1);
6649 defsubr (&Swindow_prev_buffers);
6650 defsubr (&Sset_window_prev_buffers);
6651 defsubr (&Swindow_next_buffers);
6652 defsubr (&Sset_window_next_buffers);
6653 defsubr (&Swindow_parameters);
6654 defsubr (&Swindow_parameter);
6655 defsubr (&Sset_window_parameter);
6658 void
6659 keys_of_window (void)
6661 initial_define_key (control_x_map, '<', "scroll-left");
6662 initial_define_key (control_x_map, '>', "scroll-right");
6664 initial_define_key (global_map, Ctl ('V'), "scroll-up-command");
6665 initial_define_key (meta_map, Ctl ('V'), "scroll-other-window");
6666 initial_define_key (meta_map, 'v', "scroll-down-command");