New code for replacing buffers in windows, mostly in Elisp now.
[emacs.git] / src / window.c
blobecaadee7c89521fc72ae5bf2fb0575db64b53f67
1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
4 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 This file is part of GNU Emacs.
9 GNU Emacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 GNU Emacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 #include <config.h>
23 #include <stdio.h>
24 #include <setjmp.h>
26 #include "lisp.h"
27 #include "buffer.h"
28 #include "keyboard.h"
29 #include "keymap.h"
30 #include "frame.h"
31 #include "window.h"
32 #include "commands.h"
33 #include "indent.h"
34 #include "termchar.h"
35 #include "disptab.h"
36 #include "dispextern.h"
37 #include "blockinput.h"
38 #include "intervals.h"
39 #include "termhooks.h" /* For FRAME_TERMINAL. */
41 #ifdef HAVE_X_WINDOWS
42 #include "xterm.h"
43 #endif /* HAVE_X_WINDOWS */
44 #ifdef WINDOWSNT
45 #include "w32term.h"
46 #endif
47 #ifdef MSDOS
48 #include "msdos.h"
49 #endif
50 #ifdef HAVE_NS
51 #include "nsterm.h"
52 #endif
55 Lisp_Object Qwindowp, Qwindow_live_p, Qwindow_configuration_p;
56 Lisp_Object Qwindow_deletable_p, Qdelete_window, Qdisplay_buffer;
57 Lisp_Object Qreplace_buffer_in_windows, Qget_mru_window;
58 Lisp_Object Qrecord_window_buffer;
59 Lisp_Object Qresize_root_window, Qresize_root_window_vertically;
60 Lisp_Object Qscroll_up, Qscroll_down, Qscroll_command;
61 Lisp_Object Qset, Qabove, Qbelow, Qnest, Qgroup, Qresize;
63 extern Lisp_Object Qleft_margin, Qright_margin;
65 static int displayed_window_lines (struct window *);
66 static struct window *decode_window (Lisp_Object);
67 static int count_windows (struct window *);
68 static int get_leaf_windows (struct window *, struct window **, int);
69 static void window_scroll (Lisp_Object, int, int, int);
70 static void window_scroll_pixel_based (Lisp_Object, int, int, int);
71 static void window_scroll_line_based (Lisp_Object, int, int, int);
72 static int freeze_window_start (struct window *, void *);
73 static Lisp_Object window_list (void);
74 static int add_window_to_list (struct window *, void *);
75 static int candidate_window_p (Lisp_Object, Lisp_Object, Lisp_Object,
76 Lisp_Object);
77 static Lisp_Object next_window (Lisp_Object, Lisp_Object,
78 Lisp_Object, int);
79 static void decode_next_window_args (Lisp_Object *, Lisp_Object *,
80 Lisp_Object *);
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 void resize_window_apply (struct window *, int);
87 /* This is the window in which the terminal's cursor should
88 be left when nothing is being done with it. This must
89 always be a leaf window, and its buffer is selected by
90 the top level editing loop at the end of each command.
92 This value is always the same as
93 FRAME_SELECTED_WINDOW (selected_frame). */
94 Lisp_Object selected_window;
96 /* A list of all windows for use by next_window and Fwindow_list.
97 Functions creating or deleting windows should invalidate this cache
98 by setting it to nil. */
99 Lisp_Object Vwindow_list;
101 /* The mini-buffer window of the selected frame.
102 Note that you cannot test for mini-bufferness of an arbitrary window
103 by comparing against this; but you can test for mini-bufferness of
104 the selected window. */
105 Lisp_Object minibuf_window;
107 /* Non-nil means it is the window whose mode line should be
108 shown as the selected window when the minibuffer is selected. */
109 Lisp_Object minibuf_selected_window;
111 /* Non-nil means it is the window for C-M-v to scroll
112 when the mini-buffer is selected. */
113 Lisp_Object Vminibuf_scroll_window;
115 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
116 Lisp_Object Vother_window_scroll_buffer;
118 /* Non-nil means it's function to call to display temp buffers. */
119 Lisp_Object Vtemp_buffer_show_function;
121 /* Non-zero means line and page scrolling on tall lines (with images)
122 does partial scrolling by modifying window-vscroll. */
123 int auto_window_vscroll_p;
125 /* Non-zero means to use mode-line-inactive face in all windows but the
126 selected-window and the minibuffer-scroll-window when the
127 minibuffer is active. */
128 int mode_line_in_non_selected_windows;
130 /* Hook run at end of temp_output_buffer_show. */
131 Lisp_Object Qtemp_buffer_show_hook;
133 /* Number of lines of continuity in scrolling by screenfuls. */
134 EMACS_INT next_screen_context_lines;
136 /* Incremented for each window created. */
137 static int sequence_number;
139 /* Nonzero after init_window_once has finished. */
140 static int window_initialized;
142 /* Hook to run when window config changes. */
143 static Lisp_Object Qwindow_configuration_change_hook;
144 static Lisp_Object Vwindow_configuration_change_hook;
146 /* Non-nil means scroll commands try to put point
147 at the same screen height as previously. */
148 Lisp_Object Vscroll_preserve_screen_position;
150 /* Non-nil means that text is inserted before window's markers. */
151 Lisp_Object Vwindow_point_insertion_type;
153 /* Used by the function window_scroll_pixel_based */
154 static int window_scroll_pixel_based_preserve_x;
155 static int window_scroll_pixel_based_preserve_y;
157 /* Same for window_scroll_line_based. */
158 static int window_scroll_preserve_hpos;
159 static int window_scroll_preserve_vpos;
161 /* Whether splitting/deleting is handled specially. */
162 Lisp_Object Vwindow_splits;
164 extern EMACS_INT scroll_margin;
166 extern Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
168 /* If non-nil, then the `recenter' command with a nil argument causes
169 the entire frame to be redrawn; the special value `tty' causes the
170 frame to be redrawn only if it is a tty frame. */
171 static Lisp_Object Vrecenter_redisplay;
172 extern Lisp_Object Qtty;
174 static struct window *
175 decode_window (register Lisp_Object window)
177 if (NILP (window))
178 return XWINDOW (selected_window);
180 CHECK_LIVE_WINDOW (window);
181 return XWINDOW (window);
184 static struct window *
185 decode_any_window (register Lisp_Object window)
187 if (NILP (window))
188 return XWINDOW (selected_window);
190 CHECK_WINDOW (window);
191 return XWINDOW (window);
194 DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0,
195 doc: /* Return t if OBJECT is a window. */)
196 (Lisp_Object object)
198 return WINDOWP (object) ? Qt : Qnil;
201 DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0,
202 doc: /* Return t if OBJECT is a live window and nil otherwise.
203 A live window is a window that is currently used to display a
204 buffer. */)
205 (Lisp_Object object)
207 return WINDOW_LIVE_P (object) ? Qt : Qnil;
210 /* Frames and windows. */
211 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
212 doc: /* Return the frame that window WINDOW is on.
213 WINDOW can be any window and defaults to the selected one. */)
214 (Lisp_Object window)
216 return decode_any_window (window)->frame;
219 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
220 doc: /* Return the root window of FRAME_OR_WINDOW.
221 If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
222 Else if FRAME_OR_WINDOW denotes any window, return the root window of
223 that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
224 the root window of that frame. */)
225 (Lisp_Object frame_or_window)
227 Lisp_Object window;
229 if (NILP (frame_or_window))
230 window = SELECTED_FRAME ()->root_window;
231 else if (WINDOWP (frame_or_window))
232 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->root_window;
233 else
235 CHECK_LIVE_FRAME (frame_or_window);
236 window = XFRAME (frame_or_window)->root_window;
239 return window;
242 DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0,
243 doc: /* Return the window used now for minibuffers.
244 If the optional argument FRAME is specified, return the minibuffer window
245 used by that frame. */)
246 (Lisp_Object frame)
248 if (NILP (frame))
249 frame = selected_frame;
250 CHECK_LIVE_FRAME (frame);
251 return FRAME_MINIBUF_WINDOW (XFRAME (frame));
254 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, Swindow_minibuffer_p, 0, 1, 0,
255 doc: /* Return non-nil if WINDOW is a minibuffer window.
256 WINDOW can be any window and defaults to the selected one. */)
257 (Lisp_Object window)
259 return MINI_WINDOW_P (decode_any_window (window)) ? Qt : Qnil;
262 /* Don't move this to window.el - this must be a safe routine. */
263 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
264 doc: /* Return the topmost, leftmost live window on FRAME_OR_WINDOW.
265 If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
266 Else if FRAME_OR_WINDOW denotes any window, return the first window of
267 that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
268 the first window of that frame. */)
269 (Lisp_Object frame_or_window)
271 Lisp_Object window;
273 if (NILP (frame_or_window))
274 window = SELECTED_FRAME ()->root_window;
275 else if (WINDOWP (frame_or_window))
276 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->root_window;
277 else
279 CHECK_LIVE_FRAME (frame_or_window);
280 window = XFRAME (frame_or_window)->root_window;
283 while (NILP (XWINDOW (window)->buffer))
285 if (! NILP (XWINDOW (window)->hchild))
286 window = XWINDOW (window)->hchild;
287 else if (! NILP (XWINDOW (window)->vchild))
288 window = XWINDOW (window)->vchild;
289 else
290 abort ();
293 return window;
296 DEFUN ("frame-selected-window", Fframe_selected_window,
297 Sframe_selected_window, 0, 1, 0,
298 doc: /* Return the selected window of FRAME_OR_WINDOW.
299 If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
300 Else if FRAME_OR_WINDOW denotes any window, return the selected window
301 of that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
302 the selected window of that frame. */)
303 (Lisp_Object frame_or_window)
305 Lisp_Object window;
307 if (NILP (frame_or_window))
308 window = SELECTED_FRAME ()->selected_window;
309 else if (WINDOWP (frame_or_window))
310 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->selected_window;
311 else
313 CHECK_LIVE_FRAME (frame_or_window);
314 window = XFRAME (frame_or_window)->selected_window;
317 return window;
320 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
321 Sset_frame_selected_window, 2, 3, 0,
322 doc: /* Set selected window of FRAME to WINDOW.
323 FRAME must be a live frame and defaults to the selected one. If FRAME
324 is the selected frame, this makes WINDOW the selected window. Optional
325 argument NORECORD non-nil means to neither change the order of recently
326 selected windows nor the buffer list. WINDOW must denote a live window.
327 Return WINDOW. */)
328 (Lisp_Object frame, Lisp_Object window, Lisp_Object norecord)
330 if (NILP (frame))
331 frame = selected_frame;
333 CHECK_LIVE_FRAME (frame);
334 CHECK_LIVE_WINDOW (window);
336 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
337 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
339 if (EQ (frame, selected_frame))
340 return Fselect_window (window, norecord);
341 else
342 return XFRAME (frame)->selected_window = window;
345 DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0,
346 doc: /* Return the selected window.
347 The selected window is the window in which the standard cursor for
348 selected windows appears and to which many commands apply. */)
349 (void)
351 return selected_window;
354 int window_select_count;
356 /* Note that selected_window can be nil when this is called from
357 Fset_window_configuration. */
358 DEFUN ("select-window", Fselect_window, Sselect_window, 1, 2, 0,
359 doc: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
360 Also make WINDOW's buffer current and make WINDOW the frame's selected
361 window. Return WINDOW.
363 Optional second arg NORECORD non-nil means do not put this buffer at the
364 front of the buffer list and do not make this window the most recently
365 selected one.
367 Note that the main editor command loop sets the current buffer to the
368 buffer of the selected window before each command. */)
369 (register Lisp_Object window, Lisp_Object norecord)
371 register struct window *w;
372 register struct window *ow;
373 struct frame *sf;
374 int not_selected_before = !EQ (window, selected_window);
376 CHECK_LIVE_WINDOW (window);
378 w = XWINDOW (window);
379 w->frozen_window_start_p = 0;
381 if (not_selected_before)
383 sf = SELECTED_FRAME ();
384 if (XFRAME (WINDOW_FRAME (w)) != sf)
386 XFRAME (WINDOW_FRAME (w))->selected_window = window;
387 /* Use this rather than Fhandle_switch_frame
388 so that FRAME_FOCUS_FRAME is moved appropriately as we
389 move around in the state where a minibuffer in a separate
390 frame is active. */
391 Fselect_frame (WINDOW_FRAME (w), norecord);
392 /* Fselect_frame called us back so we've done all the work already. */
393 eassert (EQ (window, selected_window));
394 return window;
396 else
397 sf->selected_window = window;
399 /* Store the current buffer's actual point into the
400 old selected window. It belongs to that window,
401 and when the window is not selected, must be in the window. */
402 if (!NILP (selected_window))
404 ow = XWINDOW (selected_window);
405 if (! NILP (ow->buffer))
406 set_marker_both (ow->pointm, ow->buffer,
407 BUF_PT (XBUFFER (ow->buffer)),
408 BUF_PT_BYTE (XBUFFER (ow->buffer)));
411 selected_window = window;
414 Fset_buffer (w->buffer);
416 if (NILP (norecord))
418 ++window_select_count;
419 XSETFASTINT (w->use_time, window_select_count);
420 record_buffer (w->buffer);
423 XBUFFER (w->buffer)->last_selected_window = window;
425 /* Go to the point recorded in the window.
426 This is important when the buffer is in more
427 than one window. It also matters when
428 redisplay_window has altered point after scrolling,
429 because it makes the change only in the window. */
430 if (not_selected_before)
432 register int new_point = marker_position (w->pointm);
433 if (new_point < BEGV)
434 SET_PT (BEGV);
435 else if (new_point > ZV)
436 SET_PT (ZV);
437 else
438 SET_PT (new_point);
440 windows_or_buffers_changed++;
443 return window;
446 DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0,
447 doc: /* Return the buffer that WINDOW is displaying.
448 WINDOW can be any window and defaults to the selected one.
449 If WINDOW is an internal window return nil. */)
450 (Lisp_Object window)
452 return decode_any_window (window)->buffer;
455 DEFUN ("window-parent", Fwindow_parent, Swindow_parent, 0, 1, 0,
456 doc: /* Return WINDOW's parent window.
457 WINDOW can be any window and defaults to the selected one.
458 Return nil if WINDOW has no parent. */)
459 (Lisp_Object window)
461 return decode_any_window (window)->parent;
464 DEFUN ("window-vchild", Fwindow_vchild, Swindow_vchild, 0, 1, 0,
465 doc: /* Return WINDOW's first vertical child window.
466 WINDOW can be any window and defaults to the selected one.
467 Return nil if WINDOW has no vertical child. */)
468 (Lisp_Object window)
470 return decode_any_window (window)->vchild;
473 DEFUN ("window-hchild", Fwindow_hchild, Swindow_hchild, 0, 1, 0,
474 doc: /* Return WINDOW's first horizontal child window.
475 WINDOW can be any window and defaults to the selected one.
476 Return nil if WINDOW has no horizontal child. */)
477 (Lisp_Object window)
479 return decode_any_window (window)->hchild;
482 DEFUN ("window-next", Fwindow_next, Swindow_next, 0, 1, 0,
483 doc: /* Return WINDOW's right sibling window.
484 WINDOW can be any window and defaults to the selected one.
485 Return nil if WINDOW has no right sibling. */)
486 (Lisp_Object window)
488 return decode_any_window (window)->next;
491 DEFUN ("window-prev", Fwindow_prev, Swindow_prev, 0, 1, 0,
492 doc: /* Return WINDOW's left sibling window.
493 WINDOW can be any window and defaults to the selected one.
494 Return nil if WINDOW has no left sibling. */)
495 (Lisp_Object window)
497 return decode_any_window (window)->prev;
500 DEFUN ("window-use-time", Fwindow_use_time, Swindow_use_time, 0, 1, 0,
501 doc: /* Return WINDOW's use time.
502 WINDOW defaults to the selected window. The window with the highest use
503 time is the most recently selected one. The window with the lowest use
504 time is the least recently selected one. */)
505 (Lisp_Object window)
507 return decode_window (window)->use_time;
510 DEFUN ("window-total-size", Fwindow_total_size, Swindow_total_size, 0, 2, 0,
511 doc: /* Return the total number of lines of WINDOW.
512 WINDOW can be any window and defaults to the selected one. The return
513 value includes WINDOW's mode line and header line, if any. If WINDOW
514 is internal, the return value is the sum of the total number of lines
515 of WINDOW's child windows if these are vertically combined and the
516 height of WINDOW's first child otherwise.
518 Optional argument HORIZONTAL non-nil means return the total number of
519 columns of WINDOW. In this case the return value includes any vertical
520 dividers or scrollbars of WINDOW. If WINDOW is internal, the return
521 value is the sum of the total number of columns of WINDOW's child
522 windows if they are horizontally combined and the width of WINDOW's
523 first child otherwise. */)
524 (Lisp_Object window, Lisp_Object horizontal)
526 if (NILP (horizontal))
527 return decode_any_window (window)->total_lines;
528 else
529 return decode_any_window (window)->total_cols;
532 DEFUN ("window-new-total-size", Fwindow_new_total_size, Swindow_new_total_size, 0, 1, 0,
533 doc: /* Return new total size of WINDOW.
534 WINDOW defaults to the selected window. */)
535 (Lisp_Object window)
537 return decode_any_window (window)->new_total;
540 DEFUN ("window-normal-size", Fwindow_normal_size, Swindow_normal_size, 0, 2, 0,
541 doc: /* Return normal height of WINDOW.
542 WINDOW can be any window and defaults to the selected one. Optional
543 argument HORIZONTAL non-nil means return normal width of WINDOW. */)
544 (Lisp_Object window, Lisp_Object horizontal)
546 if (NILP (horizontal))
547 return decode_any_window (window)->normal_lines;
548 else
549 return decode_any_window (window)->normal_cols;
552 DEFUN ("window-new-normal-size", Fwindow_new_normal_size, Swindow_new_normal_size, 0, 1, 0,
553 doc: /* Return new normal size of WINDOW.
554 WINDOW can be any window and defaults to the selected one. */)
555 (Lisp_Object window)
557 return decode_any_window (window)->new_normal;
560 DEFUN ("window-left-column", Fwindow_left_column, Swindow_left_column, 0, 1, 0,
561 doc: /* Return left column of WINDOW.
562 WINDOW can be any window and defaults to the selected one. */)
563 (Lisp_Object window)
565 return decode_any_window (window)->left_col;
568 DEFUN ("window-top-line", Fwindow_top_line, Swindow_top_line, 0, 1, 0,
569 doc: /* Return top line of WINDOW.
570 WINDOW can be any window and defaults to the selected one. */)
571 (Lisp_Object window)
573 return decode_any_window (window)->top_line;
576 /* Return the number of lines of W's body. Don't count any mode or
577 header line of W. */
580 window_body_lines (struct window *w)
582 int height = XFASTINT (w->total_lines);
584 if (!MINI_WINDOW_P (w))
586 if (WINDOW_WANTS_MODELINE_P (w))
587 --height;
588 if (WINDOW_WANTS_HEADER_LINE_P (w))
589 --height;
592 return height;
595 /* Return the number of columns of W's body. Don't count columns
596 occupied by the scroll bar or the vertical bar separating W from its
597 right sibling. On window-systems don't count fringes or display
598 margins either. */
601 window_body_cols (struct window *w)
603 struct frame *f = XFRAME (WINDOW_FRAME (w));
604 int width = XINT (w->total_cols);
606 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
607 /* Scroll bars occupy a few columns. */
608 width -= WINDOW_CONFIG_SCROLL_BAR_COLS (w);
609 else if (!FRAME_WINDOW_P (f)
610 && !WINDOW_RIGHTMOST_P (w) && !WINDOW_FULL_WIDTH_P (w))
611 /* The column of `|' characters separating side-by-side windows
612 occupies one column only. */
613 width -= 1;
615 if (FRAME_WINDOW_P (f))
616 /* On window-systems, fringes and display margins cannot be
617 used for normal text. */
618 width -= (WINDOW_FRINGE_COLS (w)
619 + WINDOW_LEFT_MARGIN_COLS (w)
620 + WINDOW_RIGHT_MARGIN_COLS (w));
622 return width;
625 DEFUN ("window-body-size", Fwindow_body_size, Swindow_body_size, 0, 2, 0,
626 doc: /* Return the number of lines of WINDOW's body.
627 WINDOW must be a live window and defaults to the selected one. The
628 return value does not include WINDOW's mode line and header line, if
629 any.
631 Optional argument HORIZONTAL non-nil means return the number of columns
632 of WINDOW's body. In this case, the return value does not include any
633 vertical dividers or scroll bars owned by WINDOW. On a window-system
634 the return value does not include the number of columns used for
635 WINDOW's fringes or display margins either. */)
636 (Lisp_Object window, Lisp_Object horizontal)
638 struct window *w = decode_any_window (window);
640 if (NILP (horizontal))
641 return make_number (window_body_lines (w));
642 else
643 return make_number (window_body_cols (w));
646 DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0,
647 doc: /* Return the number of columns by which WINDOW is scrolled from left margin.
648 WINDOW must be a live window and defaults to the selected one. */)
649 (Lisp_Object window)
651 return decode_window (window)->hscroll;
654 DEFUN ("set-window-hscroll", Fset_window_hscroll, Sset_window_hscroll, 2, 2, 0,
655 doc: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
656 Return NCOL. NCOL should be zero or positive.
658 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
659 window so that the location of point moves off-window. */)
660 (Lisp_Object window, Lisp_Object ncol)
662 struct window *w = decode_window (window);
663 int hscroll;
665 CHECK_NUMBER (ncol);
666 hscroll = max (0, XINT (ncol));
668 /* Prevent redisplay shortcuts when changing the hscroll. */
669 if (XINT (w->hscroll) != hscroll)
670 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
672 w->hscroll = make_number (hscroll);
673 return ncol;
676 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger,
677 Swindow_redisplay_end_trigger, 0, 1, 0,
678 doc: /* Return WINDOW's redisplay end trigger value.
679 WINDOW defaults to the selected window.
680 See `set-window-redisplay-end-trigger' for more information. */)
681 (Lisp_Object window)
683 return decode_window (window)->redisplay_end_trigger;
686 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger,
687 Sset_window_redisplay_end_trigger, 2, 2, 0,
688 doc: /* Set WINDOW's redisplay end trigger value to VALUE.
689 VALUE should be a buffer position (typically a marker) or nil.
690 If it is a buffer position, then if redisplay in WINDOW reaches a position
691 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
692 with two arguments: WINDOW, and the end trigger value.
693 Afterwards the end-trigger value is reset to nil. */)
694 (register Lisp_Object window, Lisp_Object value)
696 register struct window *w;
698 w = decode_window (window);
699 w->redisplay_end_trigger = value;
700 return value;
703 DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0,
704 doc: /* Return a list of the edge coordinates of WINDOW.
705 The list has the form (LEFT TOP RIGHT BOTTOM).
706 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
707 all relative to 0, 0 at top left corner of frame.
709 RIGHT is one more than the rightmost column occupied by WINDOW.
710 BOTTOM is one more than the bottommost row occupied by WINDOW.
711 The edges include the space used by WINDOW's scroll bar, display
712 margins, fringes, header line, and/or mode line. For the edges of
713 just the text area, use `window-inside-edges'. */)
714 (Lisp_Object window)
716 register struct window *w = decode_any_window (window);
718 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w)),
719 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w)),
720 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w)),
721 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w)),
722 Qnil))));
725 DEFUN ("window-pixel-edges", Fwindow_pixel_edges, Swindow_pixel_edges, 0, 1, 0,
726 doc: /* Return a list of the edge pixel coordinates of WINDOW.
727 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
728 the top left corner of the frame.
730 RIGHT is one more than the rightmost x position occupied by WINDOW.
731 BOTTOM is one more than the bottommost y position occupied by WINDOW.
732 The pixel edges include the space used by WINDOW's scroll bar, display
733 margins, fringes, header line, and/or mode line. For the pixel edges
734 of just the text area, use `window-inside-pixel-edges'. */)
735 (Lisp_Object window)
737 register struct window *w = decode_any_window (window);
739 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w)),
740 Fcons (make_number (WINDOW_TOP_EDGE_Y (w)),
741 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w)),
742 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w)),
743 Qnil))));
746 static void
747 calc_absolute_offset(struct window *w, int *add_x, int *add_y)
749 struct frame *f = XFRAME (w->frame);
750 *add_y = f->top_pos;
751 #ifdef FRAME_MENUBAR_HEIGHT
752 *add_y += FRAME_MENUBAR_HEIGHT (f);
753 #endif
754 #ifdef FRAME_TOOLBAR_HEIGHT
755 *add_y += FRAME_TOOLBAR_HEIGHT (f);
756 #endif
757 #ifdef FRAME_NS_TITLEBAR_HEIGHT
758 *add_y += FRAME_NS_TITLEBAR_HEIGHT (f);
759 #endif
760 *add_x = f->left_pos;
763 DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges,
764 Swindow_absolute_pixel_edges, 0, 1, 0,
765 doc: /* Return a list of the edge pixel coordinates of WINDOW.
766 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
767 the top left corner of the display.
769 RIGHT is one more than the rightmost x position occupied by WINDOW.
770 BOTTOM is one more than the bottommost y position occupied by WINDOW.
771 The pixel edges include the space used by WINDOW's scroll bar, display
772 margins, fringes, header line, and/or mode line. For the pixel edges
773 of just the text area, use `window-inside-absolute-pixel-edges'. */)
774 (Lisp_Object window)
776 register struct window *w = decode_any_window (window);
777 int add_x, add_y;
778 calc_absolute_offset (w, &add_x, &add_y);
780 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w) + add_x),
781 Fcons (make_number (WINDOW_TOP_EDGE_Y (w) + add_y),
782 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w) + add_x),
783 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w) + add_y),
784 Qnil))));
787 DEFUN ("window-inside-edges", Fwindow_inside_edges, Swindow_inside_edges, 0, 1, 0,
788 doc: /* Return a list of the edge coordinates of WINDOW.
789 The list has the form (LEFT TOP RIGHT BOTTOM).
790 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
791 all relative to 0, 0 at top left corner of frame.
793 RIGHT is one more than the rightmost column of WINDOW's text area.
794 BOTTOM is one more than the bottommost row of WINDOW's text area.
795 The inside edges do not include the space used by the WINDOW's scroll
796 bar, display margins, fringes, header line, and/or mode line. */)
797 (Lisp_Object window)
799 register struct window *w = decode_any_window (window);
801 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w)
802 + WINDOW_LEFT_MARGIN_COLS (w)
803 + WINDOW_LEFT_FRINGE_COLS (w)),
804 make_number (WINDOW_TOP_EDGE_LINE (w)
805 + WINDOW_HEADER_LINE_LINES (w)),
806 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w)
807 - WINDOW_RIGHT_MARGIN_COLS (w)
808 - WINDOW_RIGHT_FRINGE_COLS (w)),
809 make_number (WINDOW_BOTTOM_EDGE_LINE (w)
810 - WINDOW_MODE_LINE_LINES (w)));
813 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges, Swindow_inside_pixel_edges, 0, 1, 0,
814 doc: /* Return a list of the edge pixel coordinates of WINDOW.
815 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
816 the top left corner of the frame.
818 RIGHT is one more than the rightmost x position of WINDOW's text area.
819 BOTTOM is one more than the bottommost y position of WINDOW's text area.
820 The inside edges do not include the space used by WINDOW's scroll bar,
821 display margins, fringes, header line, and/or mode line. */)
822 (Lisp_Object window)
824 register struct window *w = decode_any_window (window);
826 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w)
827 + WINDOW_LEFT_MARGIN_WIDTH (w)
828 + WINDOW_LEFT_FRINGE_WIDTH (w)),
829 make_number (WINDOW_TOP_EDGE_Y (w)
830 + WINDOW_HEADER_LINE_HEIGHT (w)),
831 make_number (WINDOW_BOX_RIGHT_EDGE_X (w)
832 - WINDOW_RIGHT_MARGIN_WIDTH (w)
833 - WINDOW_RIGHT_FRINGE_WIDTH (w)),
834 make_number (WINDOW_BOTTOM_EDGE_Y (w)
835 - WINDOW_MODE_LINE_HEIGHT (w)));
838 DEFUN ("window-inside-absolute-pixel-edges",
839 Fwindow_inside_absolute_pixel_edges,
840 Swindow_inside_absolute_pixel_edges, 0, 1, 0,
841 doc: /* Return a list of the edge pixel coordinates of WINDOW.
842 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
843 the top left corner of the display.
845 RIGHT is one more than the rightmost x position of WINDOW's text area.
846 BOTTOM is one more than the bottommost y position of WINDOW's text area.
847 The inside edges do not include the space used by WINDOW's scroll bar,
848 display margins, fringes, header line, and/or mode line. */)
849 (Lisp_Object window)
851 register struct window *w = decode_any_window (window);
852 int add_x, add_y;
853 calc_absolute_offset (w, &add_x, &add_y);
855 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w)
856 + WINDOW_LEFT_MARGIN_WIDTH (w)
857 + WINDOW_LEFT_FRINGE_WIDTH (w) + add_x),
858 make_number (WINDOW_TOP_EDGE_Y (w)
859 + WINDOW_HEADER_LINE_HEIGHT (w) + add_y),
860 make_number (WINDOW_BOX_RIGHT_EDGE_X (w)
861 - WINDOW_RIGHT_MARGIN_WIDTH (w)
862 - WINDOW_RIGHT_FRINGE_WIDTH (w) + add_x),
863 make_number (WINDOW_BOTTOM_EDGE_Y (w)
864 - WINDOW_MODE_LINE_HEIGHT (w) + add_y));
867 /* Test if the character at column *X, row *Y is within window W.
868 If it is not, return ON_NOTHING;
869 if it is in the window's text area,
870 set *x and *y to its location relative to the upper left corner
871 of the window, and
872 return ON_TEXT;
873 if it is on the window's modeline, return ON_MODE_LINE;
874 if it is on the border between the window and its right sibling,
875 return ON_VERTICAL_BORDER.
876 if it is on a scroll bar,
877 return ON_SCROLL_BAR.
878 if it is on the window's top line, return ON_HEADER_LINE;
879 if it is in left or right fringe of the window,
880 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y
881 to window-relative coordinates;
882 if it is in the marginal area to the left/right of the window,
883 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y
884 to window-relative coordinates.
886 X and Y are frame relative pixel coordinates. */
888 static enum window_part
889 coordinates_in_window (register struct window *w, register int *x, register int *y)
891 struct frame *f = XFRAME (WINDOW_FRAME (w));
892 int left_x, right_x, top_y, bottom_y;
893 enum window_part part;
894 int ux = FRAME_COLUMN_WIDTH (f);
895 int x0 = WINDOW_LEFT_EDGE_X (w);
896 int x1 = WINDOW_RIGHT_EDGE_X (w);
897 /* The width of the area where the vertical line can be dragged.
898 (Between mode lines for instance. */
899 int grabbable_width = ux;
900 int lmargin_width, rmargin_width, text_left, text_right;
902 /* In what's below, we subtract 1 when computing right_x because we
903 want the rightmost pixel, which is given by left_pixel+width-1. */
904 if (w->pseudo_window_p)
906 left_x = 0;
907 right_x = WINDOW_TOTAL_WIDTH (w) - 1;
908 top_y = WINDOW_TOP_EDGE_Y (w);
909 bottom_y = WINDOW_BOTTOM_EDGE_Y (w);
911 else
913 left_x = WINDOW_BOX_LEFT_EDGE_X (w);
914 right_x = WINDOW_BOX_RIGHT_EDGE_X (w) - 1;
915 top_y = WINDOW_TOP_EDGE_Y (w);
916 bottom_y = WINDOW_BOTTOM_EDGE_Y (w);
919 /* Outside any interesting row? */
920 if (*y < top_y || *y >= bottom_y)
921 return ON_NOTHING;
923 /* On the mode line or header line? If it's near the start of
924 the mode or header line of window that's has a horizontal
925 sibling, say it's on the vertical line. That's to be able
926 to resize windows horizontally in case we're using toolkit
927 scroll bars. */
929 if (WINDOW_WANTS_MODELINE_P (w)
930 && *y >= bottom_y - CURRENT_MODE_LINE_HEIGHT (w))
932 part = ON_MODE_LINE;
934 header_vertical_border_check:
935 /* We're somewhere on the mode line. We consider the place
936 between mode lines of horizontally adjacent mode lines
937 as the vertical border. If scroll bars on the left,
938 return the right window. */
939 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)
940 || WINDOW_RIGHTMOST_P (w))
942 if (!WINDOW_LEFTMOST_P (w) && eabs (*x - x0) < grabbable_width)
944 /* Convert X and Y to window relative coordinates.
945 Vertical border is at the left edge of window. */
946 *x = max (0, *x - x0);
947 *y -= top_y;
948 return ON_VERTICAL_BORDER;
951 else
953 /* Make sure we're not at the rightmost position of a
954 mode-/header-line and there's yet another window on
955 the right. (Bug#1372) */
956 if ((WINDOW_RIGHTMOST_P (w) || *x < x1)
957 && eabs (*x - x1) < grabbable_width)
959 /* Convert X and Y to window relative coordinates.
960 Vertical border is at the right edge of window. */
961 *x = min (x1, *x) - x0;
962 *y -= top_y;
963 return ON_VERTICAL_BORDER;
967 if (*x < x0 || *x >= x1)
968 return ON_NOTHING;
970 /* Convert X and Y to window relative coordinates.
971 Mode line starts at left edge of window. */
972 *x -= x0;
973 *y -= top_y;
974 return part;
977 if (WINDOW_WANTS_HEADER_LINE_P (w)
978 && *y < top_y + CURRENT_HEADER_LINE_HEIGHT (w))
980 part = ON_HEADER_LINE;
981 goto header_vertical_border_check;
984 if (*x < x0 || *x >= x1)
985 return ON_NOTHING;
987 /* Outside any interesting column? */
988 if (*x < left_x || *x > right_x)
990 *y -= top_y;
991 return ON_SCROLL_BAR;
994 lmargin_width = window_box_width (w, LEFT_MARGIN_AREA);
995 rmargin_width = window_box_width (w, RIGHT_MARGIN_AREA);
997 text_left = window_box_left (w, TEXT_AREA);
998 text_right = text_left + window_box_width (w, TEXT_AREA);
1000 if (FRAME_WINDOW_P (f))
1002 if (!w->pseudo_window_p
1003 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w)
1004 && !WINDOW_RIGHTMOST_P (w)
1005 && (eabs (*x - right_x) < grabbable_width))
1007 /* Convert X and Y to window relative coordinates.
1008 Vertical border is at the right edge of window. */
1009 *x = min (right_x, *x) - left_x;
1010 *y -= top_y;
1011 return ON_VERTICAL_BORDER;
1014 else
1016 /* Need to say "*x > right_x" rather than >=, since on character
1017 terminals, the vertical line's x coordinate is right_x. */
1018 if (!w->pseudo_window_p
1019 && !WINDOW_RIGHTMOST_P (w)
1020 && *x > right_x - ux)
1022 /* On the border on the right side of the window? Assume that
1023 this area begins at RIGHT_X minus a canonical char width. */
1024 *x = min (right_x, *x) - left_x;
1025 *y -= top_y;
1026 return ON_VERTICAL_BORDER;
1030 if (*x < text_left)
1032 if (lmargin_width > 0
1033 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
1034 ? (*x >= left_x + WINDOW_LEFT_FRINGE_WIDTH (w))
1035 : (*x < left_x + lmargin_width)))
1037 *x -= left_x;
1038 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
1039 *x -= WINDOW_LEFT_FRINGE_WIDTH (w);
1040 *y -= top_y;
1041 return ON_LEFT_MARGIN;
1044 /* Convert X and Y to window-relative pixel coordinates. */
1045 *x -= left_x;
1046 *y -= top_y;
1047 return ON_LEFT_FRINGE;
1050 if (*x >= text_right)
1052 if (rmargin_width > 0
1053 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
1054 ? (*x < right_x - WINDOW_RIGHT_FRINGE_WIDTH (w))
1055 : (*x >= right_x - rmargin_width)))
1057 *x -= right_x - rmargin_width;
1058 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
1059 *x += WINDOW_RIGHT_FRINGE_WIDTH (w);
1060 *y -= top_y;
1061 return ON_RIGHT_MARGIN;
1064 /* Convert X and Y to window-relative pixel coordinates. */
1065 *x -= left_x + WINDOW_LEFT_FRINGE_WIDTH (w);
1066 *y -= top_y;
1067 return ON_RIGHT_FRINGE;
1070 /* Everything special ruled out - must be on text area */
1071 *x -= text_left;
1072 *y -= top_y;
1073 return ON_TEXT;
1077 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
1078 Scoordinates_in_window_p, 2, 2, 0,
1079 doc: /* Return non-nil if COORDINATES are in WINDOW.
1080 COORDINATES is a cons of the form (X . Y), X and Y being distances
1081 measured in characters from the upper-left corner of the frame.
1082 \(0 . 0) denotes the character in the upper left corner of the
1083 frame.
1084 If COORDINATES are in the text portion of WINDOW,
1085 the coordinates relative to the window are returned.
1086 If they are in the mode line of WINDOW, `mode-line' is returned.
1087 If they are in the top mode line of WINDOW, `header-line' is returned.
1088 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1089 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1090 If they are on the border between WINDOW and its right sibling,
1091 `vertical-line' is returned.
1092 If they are in the windows's left or right marginal areas, `left-margin'\n\
1093 or `right-margin' is returned. */)
1094 (register Lisp_Object coordinates, Lisp_Object window)
1096 struct window *w;
1097 struct frame *f;
1098 int x, y;
1099 Lisp_Object lx, ly;
1101 CHECK_WINDOW (window);
1102 w = XWINDOW (window);
1103 f = XFRAME (w->frame);
1104 CHECK_CONS (coordinates);
1105 lx = Fcar (coordinates);
1106 ly = Fcdr (coordinates);
1107 CHECK_NUMBER_OR_FLOAT (lx);
1108 CHECK_NUMBER_OR_FLOAT (ly);
1109 x = FRAME_PIXEL_X_FROM_CANON_X (f, lx) + FRAME_INTERNAL_BORDER_WIDTH (f);
1110 y = FRAME_PIXEL_Y_FROM_CANON_Y (f, ly) + FRAME_INTERNAL_BORDER_WIDTH (f);
1112 switch (coordinates_in_window (w, &x, &y))
1114 case ON_NOTHING:
1115 return Qnil;
1117 case ON_TEXT:
1118 /* X and Y are now window relative pixel coordinates. Convert
1119 them to canonical char units before returning them. */
1120 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f, x),
1121 FRAME_CANON_Y_FROM_PIXEL_Y (f, y));
1123 case ON_MODE_LINE:
1124 return Qmode_line;
1126 case ON_VERTICAL_BORDER:
1127 return Qvertical_line;
1129 case ON_HEADER_LINE:
1130 return Qheader_line;
1132 case ON_LEFT_FRINGE:
1133 return Qleft_fringe;
1135 case ON_RIGHT_FRINGE:
1136 return Qright_fringe;
1138 case ON_LEFT_MARGIN:
1139 return Qleft_margin;
1141 case ON_RIGHT_MARGIN:
1142 return Qright_margin;
1144 case ON_SCROLL_BAR:
1145 /* Historically we are supposed to return nil in this case. */
1146 return Qnil;
1148 default:
1149 abort ();
1154 /* Callback for foreach_window, used in window_from_coordinates.
1155 Check if window W contains coordinates specified by USER_DATA which
1156 is actually a pointer to a struct check_window_data CW.
1158 Check if window W contains coordinates *CW->x and *CW->y. If it
1159 does, return W in *CW->window, as Lisp_Object, and return in
1160 *CW->part the part of the window under coordinates *X,*Y. Return
1161 zero from this function to stop iterating over windows. */
1163 struct check_window_data
1165 Lisp_Object *window;
1166 int *x, *y;
1167 enum window_part *part;
1170 static int
1171 check_window_containing (struct window *w, void *user_data)
1173 struct check_window_data *cw = (struct check_window_data *) user_data;
1174 enum window_part found;
1175 int continue_p = 1;
1177 found = coordinates_in_window (w, cw->x, cw->y);
1178 if (found != ON_NOTHING)
1180 *cw->part = found;
1181 XSETWINDOW (*cw->window, w);
1182 continue_p = 0;
1185 return continue_p;
1189 /* Find the window containing frame-relative pixel position X/Y and
1190 return it as a Lisp_Object.
1192 If X, Y is on one of the window's special `window_part' elements,
1193 set *PART to the id of that element, and return X and Y converted
1194 to window relative coordinates in WX and WY.
1196 If there is no window under X, Y return nil and leave *PART
1197 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1199 This function was previously implemented with a loop cycling over
1200 windows with Fnext_window, and starting with the frame's selected
1201 window. It turned out that this doesn't work with an
1202 implementation of next_window using Vwindow_list, because
1203 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1204 tree of F when this function is called asynchronously from
1205 note_mouse_highlight. The original loop didn't terminate in this
1206 case. */
1208 Lisp_Object
1209 window_from_coordinates (struct frame *f, int x, int y, enum window_part *part, int *wx, int *wy, int tool_bar_p)
1211 Lisp_Object window;
1212 struct check_window_data cw;
1213 enum window_part dummy;
1215 if (part == 0)
1216 part = &dummy;
1218 window = Qnil;
1219 cw.window = &window, cw.x = &x, cw.y = &y; cw.part = part;
1220 foreach_window (f, check_window_containing, &cw);
1222 /* If not found above, see if it's in the tool bar window, if a tool
1223 bar exists. */
1224 if (NILP (window)
1225 && tool_bar_p
1226 && WINDOWP (f->tool_bar_window)
1227 && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window)) > 0
1228 && (coordinates_in_window (XWINDOW (f->tool_bar_window), &x, &y)
1229 != ON_NOTHING))
1231 *part = ON_TEXT;
1232 window = f->tool_bar_window;
1235 if (wx) *wx = x;
1236 if (wy) *wy = y;
1238 return window;
1241 DEFUN ("window-at", Fwindow_at, Swindow_at, 2, 3, 0,
1242 doc: /* Return window containing coordinates X and Y on FRAME.
1243 FRAME must be a live frame and defaults to the selected one.
1244 The top left corner of the frame is considered to be row 0,
1245 column 0. */)
1246 (Lisp_Object x, Lisp_Object y, Lisp_Object frame)
1248 struct frame *f;
1250 if (NILP (frame))
1251 frame = selected_frame;
1252 CHECK_LIVE_FRAME (frame);
1253 f = XFRAME (frame);
1255 /* Check that arguments are integers or floats. */
1256 CHECK_NUMBER_OR_FLOAT (x);
1257 CHECK_NUMBER_OR_FLOAT (y);
1259 return window_from_coordinates (f,
1260 (FRAME_PIXEL_X_FROM_CANON_X (f, x)
1261 + FRAME_INTERNAL_BORDER_WIDTH (f)),
1262 (FRAME_PIXEL_Y_FROM_CANON_Y (f, y)
1263 + FRAME_INTERNAL_BORDER_WIDTH (f)),
1264 0, 0, 0, 0);
1267 DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0,
1268 doc: /* Return current value of point in WINDOW.
1269 WINDOW must be a live window and defaults to the selected one.
1271 For a nonselected window, this is the value point would have
1272 if that window were selected.
1274 Note that, when WINDOW is the selected window and its buffer
1275 is also currently selected, the value returned is the same as (point).
1276 It would be more strictly correct to return the `top-level' value
1277 of point, outside of any save-excursion forms.
1278 But that is hard to define. */)
1279 (Lisp_Object window)
1281 register struct window *w = decode_window (window);
1283 if (w == XWINDOW (selected_window)
1284 && current_buffer == XBUFFER (w->buffer))
1285 return Fpoint ();
1286 return Fmarker_position (w->pointm);
1289 DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0,
1290 doc: /* Return position at which display currently starts in WINDOW.
1291 WINDOW must be a live window and defaults to the selected one.
1292 This is updated by redisplay or by calling `set-window-start'. */)
1293 (Lisp_Object window)
1295 return Fmarker_position (decode_window (window)->start);
1298 /* This is text temporarily removed from the doc string below.
1300 This function returns nil if the position is not currently known.
1301 That happens when redisplay is preempted and doesn't finish.
1302 If in that case you want to compute where the end of the window would
1303 have been if redisplay had finished, do this:
1304 (save-excursion
1305 (goto-char (window-start window))
1306 (vertical-motion (1- (window-height window)) window)
1307 (point))") */
1309 DEFUN ("window-end", Fwindow_end, Swindow_end, 0, 2, 0,
1310 doc: /* Return position at which display currently ends in WINDOW.
1311 WINDOW must be a live window and defaults to the selected one.
1312 This is updated by redisplay, when it runs to completion.
1313 Simply changing the buffer text or setting `window-start'
1314 does not update this value.
1315 Return nil if there is no recorded value. \(This can happen if the
1316 last redisplay of WINDOW was preempted, and did not finish.)
1317 If UPDATE is non-nil, compute the up-to-date position
1318 if it isn't already recorded. */)
1319 (Lisp_Object window, Lisp_Object update)
1321 Lisp_Object value;
1322 struct window *w = decode_window (window);
1323 Lisp_Object buf;
1324 struct buffer *b;
1326 buf = w->buffer;
1327 CHECK_BUFFER (buf);
1328 b = XBUFFER (buf);
1330 #if 0 /* This change broke some things. We should make it later. */
1331 /* If we don't know the end position, return nil.
1332 The user can compute it with vertical-motion if he wants to.
1333 It would be nicer to do it automatically,
1334 but that's so slow that it would probably bother people. */
1335 if (NILP (w->window_end_valid))
1336 return Qnil;
1337 #endif
1339 if (! NILP (update)
1340 && ! (! NILP (w->window_end_valid)
1341 && XFASTINT (w->last_modified) >= BUF_MODIFF (b)
1342 && XFASTINT (w->last_overlay_modified) >= BUF_OVERLAY_MODIFF (b))
1343 && !noninteractive)
1345 struct text_pos startp;
1346 struct it it;
1347 struct buffer *old_buffer = NULL;
1349 /* Cannot use Fvertical_motion because that function doesn't
1350 cope with variable-height lines. */
1351 if (b != current_buffer)
1353 old_buffer = current_buffer;
1354 set_buffer_internal (b);
1357 /* In case W->start is out of the range, use something
1358 reasonable. This situation occurred when loading a file with
1359 `-l' containing a call to `rmail' with subsequent other
1360 commands. At the end, W->start happened to be BEG, while
1361 rmail had already narrowed the buffer. */
1362 if (XMARKER (w->start)->charpos < BEGV)
1363 SET_TEXT_POS (startp, BEGV, BEGV_BYTE);
1364 else if (XMARKER (w->start)->charpos > ZV)
1365 SET_TEXT_POS (startp, ZV, ZV_BYTE);
1366 else
1367 SET_TEXT_POS_FROM_MARKER (startp, w->start);
1369 start_display (&it, w, startp);
1370 move_it_vertically (&it, window_box_height (w));
1371 if (it.current_y < it.last_visible_y)
1372 move_it_past_eol (&it);
1373 value = make_number (IT_CHARPOS (it));
1375 if (old_buffer)
1376 set_buffer_internal (old_buffer);
1378 else
1379 XSETINT (value, BUF_Z (b) - XFASTINT (w->window_end_pos));
1381 return value;
1384 DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0,
1385 doc: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1386 Return POS. */)
1387 (Lisp_Object window, Lisp_Object pos)
1389 register struct window *w = decode_window (window);
1391 CHECK_NUMBER_COERCE_MARKER (pos);
1392 if (w == XWINDOW (selected_window)
1393 && XBUFFER (w->buffer) == current_buffer)
1394 Fgoto_char (pos);
1395 else
1396 set_marker_restricted (w->pointm, pos, w->buffer);
1398 /* We have to make sure that redisplay updates the window to show
1399 the new value of point. */
1400 if (!EQ (window, selected_window))
1401 ++windows_or_buffers_changed;
1403 return pos;
1406 DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0,
1407 doc: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1408 WINDOW defaults to the selected window. Return POS.
1409 Optional third arg NOFORCE non-nil inhibits next redisplay from
1410 overriding motion of point in order to display at this exact start. */)
1411 (Lisp_Object window, Lisp_Object pos, Lisp_Object noforce)
1413 register struct window *w = decode_window (window);
1415 CHECK_NUMBER_COERCE_MARKER (pos);
1416 set_marker_restricted (w->start, pos, w->buffer);
1417 /* this is not right, but much easier than doing what is right. */
1418 w->start_at_line_beg = Qnil;
1419 if (NILP (noforce))
1420 w->force_start = Qt;
1421 w->update_mode_line = Qt;
1422 XSETFASTINT (w->last_modified, 0);
1423 XSETFASTINT (w->last_overlay_modified, 0);
1424 if (!EQ (window, selected_window))
1425 windows_or_buffers_changed++;
1427 return pos;
1430 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p,
1431 Spos_visible_in_window_p, 0, 3, 0,
1432 doc: /* Return non-nil if position POS is currently in WINDOW.
1433 Return nil if that position is scrolled vertically out of view.
1434 If a character is only partially visible, nil is returned, unless the
1435 optional argument PARTIALLY is non-nil.
1436 If POS is only out of view because of horizontal scrolling, return non-nil.
1437 If POS is t, it specifies the position of the last visible glyph in WINDOW.
1438 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
1440 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1441 return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
1442 where X and Y are the pixel coordinates relative to the top left corner
1443 of the window. The remaining elements are omitted if the character after
1444 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1445 off-window at the top and bottom of the row, ROWH is the height of the
1446 display row, and VPOS is the row number (0-based) containing POS. */)
1447 (Lisp_Object pos, Lisp_Object window, Lisp_Object partially)
1449 register struct window *w;
1450 register int posint;
1451 register struct buffer *buf;
1452 struct text_pos top;
1453 Lisp_Object in_window = Qnil;
1454 int rtop, rbot, rowh, vpos, fully_p = 1;
1455 int x, y;
1457 w = decode_window (window);
1458 buf = XBUFFER (w->buffer);
1459 SET_TEXT_POS_FROM_MARKER (top, w->start);
1461 if (EQ (pos, Qt))
1462 posint = -1;
1463 else if (!NILP (pos))
1465 CHECK_NUMBER_COERCE_MARKER (pos);
1466 posint = XINT (pos);
1468 else if (w == XWINDOW (selected_window))
1469 posint = PT;
1470 else
1471 posint = XMARKER (w->pointm)->charpos;
1473 /* If position is above window start or outside buffer boundaries,
1474 or if window start is out of range, position is not visible. */
1475 if ((EQ (pos, Qt) || (posint >= CHARPOS (top) && posint <= BUF_ZV (buf)))
1476 && CHARPOS (top) >= BUF_BEGV (buf)
1477 && CHARPOS (top) <= BUF_ZV (buf)
1478 && pos_visible_p (w, posint, &x, &y, &rtop, &rbot, &rowh, &vpos)
1479 && (fully_p = !rtop && !rbot, (!NILP (partially) || fully_p)))
1480 in_window = Qt;
1482 if (!NILP (in_window) && !NILP (partially))
1484 Lisp_Object part = Qnil;
1485 if (!fully_p)
1486 part = list4 (make_number (rtop), make_number (rbot),
1487 make_number (rowh), make_number (vpos));
1488 in_window = Fcons (make_number (x),
1489 Fcons (make_number (y), part));
1492 return in_window;
1495 DEFUN ("window-line-height", Fwindow_line_height,
1496 Swindow_line_height, 0, 2, 0,
1497 doc: /* Return height in pixels of text line LINE in window WINDOW.
1498 WINDOW defaults to the selected window.
1500 Return height of current line if LINE is omitted or nil. Return height of
1501 header or mode line if LINE is `header-line' or `mode-line'.
1502 Otherwise, LINE is a text line number starting from 0. A negative number
1503 counts from the end of the window.
1505 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
1506 in pixels of the visible part of the line, VPOS and YPOS are the
1507 vertical position in lines and pixels of the line, relative to the top
1508 of the first text line, and OFFBOT is the number of off-window pixels at
1509 the bottom of the text line. If there are off-window pixels at the top
1510 of the (first) text line, YPOS is negative.
1512 Return nil if window display is not up-to-date. In that case, use
1513 `pos-visible-in-window-p' to obtain the information. */)
1514 (Lisp_Object line, Lisp_Object window)
1516 register struct window *w;
1517 register struct buffer *b;
1518 struct glyph_row *row, *end_row;
1519 int max_y, crop, i, n;
1521 w = decode_window (window);
1523 if (noninteractive || w->pseudo_window_p)
1524 return Qnil;
1526 CHECK_BUFFER (w->buffer);
1527 b = XBUFFER (w->buffer);
1529 /* Fail if current matrix is not up-to-date. */
1530 if (NILP (w->window_end_valid)
1531 || current_buffer->clip_changed
1532 || current_buffer->prevent_redisplay_optimizations_p
1533 || XFASTINT (w->last_modified) < BUF_MODIFF (b)
1534 || XFASTINT (w->last_overlay_modified) < BUF_OVERLAY_MODIFF (b))
1535 return Qnil;
1537 if (NILP (line))
1539 i = w->cursor.vpos;
1540 if (i < 0 || i >= w->current_matrix->nrows
1541 || (row = MATRIX_ROW (w->current_matrix, i), !row->enabled_p))
1542 return Qnil;
1543 max_y = window_text_bottom_y (w);
1544 goto found_row;
1547 if (EQ (line, Qheader_line))
1549 if (!WINDOW_WANTS_HEADER_LINE_P (w))
1550 return Qnil;
1551 row = MATRIX_HEADER_LINE_ROW (w->current_matrix);
1552 if (!row->enabled_p)
1553 return Qnil;
1554 return list4 (make_number (row->height),
1555 make_number (0), make_number (0),
1556 make_number (0));
1559 if (EQ (line, Qmode_line))
1561 row = MATRIX_MODE_LINE_ROW (w->current_matrix);
1562 if (!row->enabled_p)
1563 return Qnil;
1564 return list4 (make_number (row->height),
1565 make_number (0), /* not accurate */
1566 make_number (WINDOW_HEADER_LINE_HEIGHT (w)
1567 + window_text_bottom_y (w)),
1568 make_number (0));
1571 CHECK_NUMBER (line);
1572 n = XINT (line);
1574 row = MATRIX_FIRST_TEXT_ROW (w->current_matrix);
1575 end_row = MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w);
1576 max_y = window_text_bottom_y (w);
1577 i = 0;
1579 while ((n < 0 || i < n)
1580 && row <= end_row && row->enabled_p
1581 && row->y + row->height < max_y)
1582 row++, i++;
1584 if (row > end_row || !row->enabled_p)
1585 return Qnil;
1587 if (++n < 0)
1589 if (-n > i)
1590 return Qnil;
1591 row += n;
1592 i += n;
1595 found_row:
1596 crop = max (0, (row->y + row->height) - max_y);
1597 return list4 (make_number (row->height + min (0, row->y) - crop),
1598 make_number (i),
1599 make_number (row->y),
1600 make_number (crop));
1603 DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p,
1604 0, 1, 0,
1605 doc: /* Return non-nil when WINDOW is dedicated to its buffer.
1606 More precisely, return the value assigned by the last call of
1607 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1608 never called with WINDOW as its argument, or the value set by that
1609 function was internally reset since its last call. WINDOW defaults to
1610 the selected window.
1612 When a window is dedicated to its buffer, `display-buffer' will refrain
1613 from displaying another buffer in it. `get-lru-window' and
1614 `get-largest-window' treat dedicated windows specially.
1615 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1616 `kill-buffer' can delete a dedicated window and the containing frame.
1618 Functions like `set-window-buffer' may change the buffer displayed by a
1619 window, unless that window is "strongly" dedicated to its buffer, that
1620 is the value returned by `window-dedicated-p' is t. */)
1621 (Lisp_Object window)
1623 return decode_window (window)->dedicated;
1626 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p,
1627 Sset_window_dedicated_p, 2, 2, 0,
1628 doc: /* Mark WINDOW as dedicated according to FLAG.
1629 WINDOW must be a live window and defaults to the selected one. FLAG
1630 non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means
1631 mark WINDOW as non-dedicated. Return FLAG.
1633 When a window is dedicated to its buffer, `display-buffer' will refrain
1634 from displaying another buffer in it. `get-lru-window' and
1635 `get-largest-window' treat dedicated windows specially.
1636 `delete-windows-on', `replace-buffer-in-windows', `quit-window',
1637 `quit-restore-window' and `kill-buffer' can delete a dedicated window
1638 and the containing frame.
1640 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
1641 its buffer. Functions like `set-window-buffer' may change the buffer
1642 displayed by a window, unless that window is strongly dedicated to its
1643 buffer. If and when `set-window-buffer' displays another buffer in a
1644 window, it also makes sure that the window is no more dedicated. */)
1645 (Lisp_Object window, Lisp_Object flag)
1647 register struct window *w = decode_window (window);
1649 w->dedicated = flag;
1650 return w->dedicated;
1653 DEFUN ("window-prev-buffers", Fwindow_prev_buffers, Swindow_prev_buffers,
1654 0, 1, 0,
1655 doc: /* Return buffers previously shown in WINDOW.
1656 WINDOW must be a live window and defaults to the selected one.
1658 The return value is either nil or a list of <buffer, window-start,
1659 window-point> triples where buffer was previously shown in WINDOW. */)
1660 (Lisp_Object window)
1662 return decode_window (window)->prev_buffers;
1665 DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers,
1666 Sset_window_prev_buffers, 2, 2, 0,
1667 doc: /* Set WINDOW's previous buffers to PREV-BUFFERS.
1668 WINDOW must be a live window and defaults to the selected one. Return
1669 PREV-BUFFERS.
1671 PREV-BUFFERS should be either nil or a list of <buffer, window-start,
1672 window-point> triples where buffer was previously shown in WINDOW. */)
1673 (Lisp_Object window, Lisp_Object prev_buffers)
1675 return decode_any_window (window)->prev_buffers = prev_buffers;
1678 DEFUN ("window-next-buffers", Fwindow_next_buffers, Swindow_next_buffers,
1679 0, 1, 0,
1680 doc: /* Return list of buffers recently re-shown in WINDOW.
1681 WINDOW must be a live window and defaults to the selected one. */)
1682 (Lisp_Object window)
1684 return decode_window (window)->next_buffers;
1687 DEFUN ("set-window-next-buffers", Fset_window_next_buffers,
1688 Sset_window_next_buffers, 2, 2, 0,
1689 doc: /* Set WINDOW's next buffers to NEXT-BUFFERS.
1690 WINDOW must be a live window and defaults to the selected one. Return
1691 NEXT-BUFFERS.
1693 NEXT-BUFFERS should be either nil or a list of buffers that have been
1694 recently re-shown in WINDOW. */)
1695 (Lisp_Object window, Lisp_Object next_buffers)
1697 return decode_any_window (window)->next_buffers = next_buffers;
1700 DEFUN ("window-parameters", Fwindow_parameters, Swindow_parameters,
1701 0, 1, 0,
1702 doc: /* Return the parameters of WINDOW and their values.
1703 WINDOW defaults to the selected window. The return value is a list of
1704 elements of the form (PARAMETER . VALUE). */)
1705 (Lisp_Object window)
1707 return Fcopy_alist (decode_any_window (window)->window_parameters);
1710 DEFUN ("window-parameter", Fwindow_parameter, Swindow_parameter,
1711 2, 2, 0,
1712 doc: /* Return WINDOW's value for PARAMETER.
1713 WINDOW defaults to the selected window. */)
1714 (Lisp_Object window, Lisp_Object parameter)
1716 Lisp_Object result;
1718 result = Fassq (parameter, decode_any_window (window)->window_parameters);
1719 return CDR_SAFE (result);
1722 DEFUN ("set-window-parameter", Fset_window_parameter,
1723 Sset_window_parameter, 3, 3, 0,
1724 doc: /* Set WINDOW's value of PARAMETER to VALUE.
1725 WINDOW defaults to the selected window. Return VALUE. */)
1726 (Lisp_Object window, Lisp_Object parameter, Lisp_Object value)
1728 register struct window *w = decode_any_window (window);
1729 Lisp_Object old_alist_elt;
1731 old_alist_elt = Fassq (parameter, w->window_parameters);
1732 if (NILP (old_alist_elt))
1733 w->window_parameters = Fcons (Fcons (parameter, value), w->window_parameters);
1734 else
1735 Fsetcdr (old_alist_elt, value);
1736 return value;
1739 DEFUN ("window-display-table", Fwindow_display_table, Swindow_display_table,
1740 0, 1, 0,
1741 doc: /* Return the display-table that WINDOW is using.
1742 WINDOW defaults to the selected window. */)
1743 (Lisp_Object window)
1745 return decode_window (window)->display_table;
1748 /* Get the display table for use on window W. This is either W's
1749 display table or W's buffer's display table. Ignore the specified
1750 tables if they are not valid; if no valid table is specified,
1751 return 0. */
1753 struct Lisp_Char_Table *
1754 window_display_table (struct window *w)
1756 struct Lisp_Char_Table *dp = NULL;
1758 if (DISP_TABLE_P (w->display_table))
1759 dp = XCHAR_TABLE (w->display_table);
1760 else if (BUFFERP (w->buffer))
1762 struct buffer *b = XBUFFER (w->buffer);
1764 if (DISP_TABLE_P (b->display_table))
1765 dp = XCHAR_TABLE (b->display_table);
1766 else if (DISP_TABLE_P (Vstandard_display_table))
1767 dp = XCHAR_TABLE (Vstandard_display_table);
1770 return dp;
1773 DEFUN ("set-window-display-table", Fset_window_display_table, Sset_window_display_table, 2, 2, 0,
1774 doc: /* Set WINDOW's display-table to TABLE. */)
1775 (register Lisp_Object window, Lisp_Object table)
1777 register struct window *w;
1779 w = decode_window (window);
1780 w->display_table = table;
1781 return table;
1784 /* Record info on buffer window W is displaying
1785 when it is about to cease to display that buffer. */
1786 static void
1787 unshow_buffer (register struct window *w)
1789 Lisp_Object buf;
1790 struct buffer *b;
1792 buf = w->buffer;
1793 b = XBUFFER (buf);
1794 if (b != XMARKER (w->pointm)->buffer)
1795 abort ();
1797 #if 0
1798 if (w == XWINDOW (selected_window)
1799 || ! EQ (buf, XWINDOW (selected_window)->buffer))
1800 /* Do this except when the selected window's buffer
1801 is being removed from some other window. */
1802 #endif
1803 /* last_window_start records the start position that this buffer
1804 had in the last window to be disconnected from it.
1805 Now that this statement is unconditional,
1806 it is possible for the buffer to be displayed in the
1807 selected window, while last_window_start reflects another
1808 window which was recently showing the same buffer.
1809 Some people might say that might be a good thing. Let's see. */
1810 b->last_window_start = marker_position (w->start);
1812 /* Point in the selected window's buffer
1813 is actually stored in that buffer, and the window's pointm isn't used.
1814 So don't clobber point in that buffer. */
1815 if (! EQ (buf, XWINDOW (selected_window)->buffer)
1816 /* This line helps to fix Horsley's testbug.el bug. */
1817 && !(WINDOWP (b->last_selected_window)
1818 && w != XWINDOW (b->last_selected_window)
1819 && EQ (buf, XWINDOW (b->last_selected_window)->buffer)))
1820 temp_set_point_both (b,
1821 clip_to_bounds (BUF_BEGV (b),
1822 XMARKER (w->pointm)->charpos,
1823 BUF_ZV (b)),
1824 clip_to_bounds (BUF_BEGV_BYTE (b),
1825 marker_byte_position (w->pointm),
1826 BUF_ZV_BYTE (b)));
1828 if (WINDOWP (b->last_selected_window)
1829 && w == XWINDOW (b->last_selected_window))
1830 b->last_selected_window = Qnil;
1833 /* Put NEW into the window structure in place of OLD. SETFLAG zero
1834 means change window structure only. Otherwise store geometry and
1835 other settings as well. */
1836 static void
1837 replace_window (Lisp_Object old, Lisp_Object new, int setflag)
1839 register Lisp_Object tem;
1840 register struct window *o = XWINDOW (old), *n = XWINDOW (new);
1842 /* If OLD is its frame's root window, then NEW is the new
1843 root window for that frame. */
1844 if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame))))
1845 FRAME_ROOT_WINDOW (XFRAME (o->frame)) = new;
1847 if (setflag)
1849 n->left_col = o->left_col;
1850 n->top_line = o->top_line;
1851 n->total_cols = o->total_cols;
1852 n->total_lines = o->total_lines;
1853 n->normal_cols = o->normal_cols;
1854 XSETFASTINT (o->normal_cols, 1); /* !!! */
1855 n->normal_lines = o->normal_lines;
1856 XSETFASTINT (o->normal_lines, 1); /* !!! */
1857 n->desired_matrix = n->current_matrix = 0;
1858 n->vscroll = 0;
1859 memset (&n->cursor, 0, sizeof (n->cursor));
1860 memset (&n->last_cursor, 0, sizeof (n->last_cursor));
1861 memset (&n->phys_cursor, 0, sizeof (n->phys_cursor));
1862 n->phys_cursor_type = -1;
1863 n->phys_cursor_width = -1;
1864 n->must_be_updated_p = 0;
1865 n->pseudo_window_p = 0;
1866 XSETFASTINT (n->window_end_vpos, 0);
1867 XSETFASTINT (n->window_end_pos, 0);
1868 n->window_end_valid = Qnil;
1869 n->frozen_window_start_p = 0;
1872 n->next = tem = o->next;
1873 if (!NILP (tem))
1874 XWINDOW (tem)->prev = new;
1876 n->prev = tem = o->prev;
1877 if (!NILP (tem))
1878 XWINDOW (tem)->next = new;
1880 n->parent = tem = o->parent;
1881 if (!NILP (tem))
1883 if (EQ (XWINDOW (tem)->vchild, old))
1884 XWINDOW (tem)->vchild = new;
1885 if (EQ (XWINDOW (tem)->hchild, old))
1886 XWINDOW (tem)->hchild = new;
1890 /* If window WINDOW and its parent window are iso-combined, merge
1891 WINDOW's children into those of its parent window and mark WINDOW as
1892 deleted. */
1894 static void
1895 recombine_windows (Lisp_Object window)
1897 struct window *w, *p, *c;
1898 Lisp_Object parent, child;
1899 int horflag;
1901 w = XWINDOW (window);
1902 parent = w->parent;
1903 if (NILP (w->inhibit_recombine) && !NILP (parent))
1905 p = XWINDOW (parent);
1906 if (((!NILP (p->vchild) && !NILP (w->vchild))
1907 || (!NILP (p->hchild) && !NILP (w->hchild))))
1908 /* WINDOW and PARENT are both either a vertical or a horizontal
1909 combination. */
1911 horflag = NILP (w->vchild);
1912 child = horflag ? w->hchild : w->vchild;
1913 c = XWINDOW (child);
1915 /* Splice WINDOW's children into its parent's children and
1916 assign new normal sizes. */
1917 if (NILP (w->prev))
1918 if (horflag)
1919 p->hchild = child;
1920 else
1921 p->vchild = child;
1922 else
1924 c->prev = w->prev;
1925 XWINDOW (w->prev)->next = child;
1928 while (c)
1930 c->parent = parent;
1932 if (horflag)
1933 c->normal_cols
1934 = make_float (XFLOATINT (c->total_cols)
1935 / XFLOATINT (p->total_cols));
1936 else
1937 c->normal_lines
1938 = make_float (XFLOATINT (c->total_lines)
1939 / XFLOATINT (p->total_lines));
1941 if (NILP (c->next))
1943 if (!NILP (w->next))
1945 c->next = w->next;
1946 XWINDOW (c->next)->prev = child;
1949 c = 0;
1951 else
1953 child = c->next;
1954 c = XWINDOW (child);
1958 /* WINDOW can be deleted now. */
1959 w->vchild = w->hchild = Qnil;
1965 /* If WINDOW can be deleted, delete it. */
1966 Lisp_Object
1967 delete_deletable_window (Lisp_Object window)
1969 if (!NILP (call1 (Qwindow_deletable_p, window)))
1970 call1 (Qdelete_window, window);
1973 /***********************************************************************
1974 Window List
1975 ***********************************************************************/
1977 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1978 pointer. This is a callback function for foreach_window, used in
1979 the window_list function. */
1981 static int
1982 add_window_to_list (struct window *w, void *user_data)
1984 Lisp_Object *list = (Lisp_Object *) user_data;
1985 Lisp_Object window;
1986 XSETWINDOW (window, w);
1987 *list = Fcons (window, *list);
1988 return 1;
1992 /* Return a list of all windows, for use by next_window. If
1993 Vwindow_list is a list, return that list. Otherwise, build a new
1994 list, cache it in Vwindow_list, and return that. */
1996 static Lisp_Object
1997 window_list (void)
1999 if (!CONSP (Vwindow_list))
2001 Lisp_Object tail;
2003 Vwindow_list = Qnil;
2004 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
2006 Lisp_Object args[2];
2008 /* We are visiting windows in canonical order, and add
2009 new windows at the front of args[1], which means we
2010 have to reverse this list at the end. */
2011 args[1] = Qnil;
2012 foreach_window (XFRAME (XCAR (tail)), add_window_to_list, &args[1]);
2013 args[0] = Vwindow_list;
2014 args[1] = Fnreverse (args[1]);
2015 Vwindow_list = Fnconc (2, args);
2019 return Vwindow_list;
2023 /* Value is non-zero if WINDOW satisfies the constraints given by
2024 OWINDOW, MINIBUF and ALL_FRAMES.
2026 MINIBUF t means WINDOW may be minibuffer windows.
2027 `lambda' means WINDOW may not be a minibuffer window.
2028 a window means a specific minibuffer window
2030 ALL_FRAMES t means search all frames,
2031 nil means search just current frame,
2032 `visible' means search just visible frames,
2033 0 means search visible and iconified frames,
2034 a window means search the frame that window belongs to,
2035 a frame means consider windows on that frame, only. */
2037 static int
2038 candidate_window_p (Lisp_Object window, Lisp_Object owindow, Lisp_Object minibuf, Lisp_Object all_frames)
2040 struct window *w = XWINDOW (window);
2041 struct frame *f = XFRAME (w->frame);
2042 int candidate_p = 1;
2044 if (!BUFFERP (w->buffer))
2045 candidate_p = 0;
2046 else if (MINI_WINDOW_P (w)
2047 && (EQ (minibuf, Qlambda)
2048 || (WINDOWP (minibuf) && !EQ (minibuf, window))))
2050 /* If MINIBUF is `lambda' don't consider any mini-windows.
2051 If it is a window, consider only that one. */
2052 candidate_p = 0;
2054 else if (EQ (all_frames, Qt))
2055 candidate_p = 1;
2056 else if (NILP (all_frames))
2058 xassert (WINDOWP (owindow));
2059 candidate_p = EQ (w->frame, XWINDOW (owindow)->frame);
2061 else if (EQ (all_frames, Qvisible))
2063 FRAME_SAMPLE_VISIBILITY (f);
2064 candidate_p = FRAME_VISIBLE_P (f)
2065 && (FRAME_TERMINAL (XFRAME (w->frame))
2066 == FRAME_TERMINAL (XFRAME (selected_frame)));
2069 else if (INTEGERP (all_frames) && XINT (all_frames) == 0)
2071 FRAME_SAMPLE_VISIBILITY (f);
2072 candidate_p = (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f)
2073 #ifdef HAVE_X_WINDOWS
2074 /* Yuck!! If we've just created the frame and the
2075 window-manager requested the user to place it
2076 manually, the window may still not be considered
2077 `visible'. I'd argue it should be at least
2078 something like `iconified', but don't know how to do
2079 that yet. --Stef */
2080 || (FRAME_X_P (f) && f->output_data.x->asked_for_visible
2081 && !f->output_data.x->has_been_visible)
2082 #endif
2084 && (FRAME_TERMINAL (XFRAME (w->frame))
2085 == FRAME_TERMINAL (XFRAME (selected_frame)));
2087 else if (WINDOWP (all_frames))
2088 candidate_p = (EQ (FRAME_MINIBUF_WINDOW (f), all_frames)
2089 || EQ (XWINDOW (all_frames)->frame, w->frame)
2090 || EQ (XWINDOW (all_frames)->frame, FRAME_FOCUS_FRAME (f)));
2091 else if (FRAMEP (all_frames))
2092 candidate_p = EQ (all_frames, w->frame);
2094 return candidate_p;
2098 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2099 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
2100 ALL_FRAMES. */
2102 static void
2103 decode_next_window_args (Lisp_Object *window, Lisp_Object *minibuf, Lisp_Object *all_frames)
2105 if (NILP (*window))
2106 *window = selected_window;
2107 else
2108 CHECK_LIVE_WINDOW (*window);
2110 /* MINIBUF nil may or may not include minibuffers. Decide if it
2111 does. */
2112 if (NILP (*minibuf))
2113 *minibuf = minibuf_level ? minibuf_window : Qlambda;
2114 else if (!EQ (*minibuf, Qt))
2115 *minibuf = Qlambda;
2117 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2118 => count none of them, or a specific minibuffer window (the
2119 active one) to count. */
2121 /* ALL_FRAMES nil doesn't specify which frames to include. */
2122 if (NILP (*all_frames))
2123 *all_frames = (!EQ (*minibuf, Qlambda)
2124 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window)->frame))
2125 : Qnil);
2126 else if (EQ (*all_frames, Qvisible))
2128 else if (EQ (*all_frames, make_number (0)))
2130 else if (FRAMEP (*all_frames))
2132 else if (!EQ (*all_frames, Qt))
2133 *all_frames = Qnil;
2135 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
2136 search just current frame, `visible' meaning search just visible
2137 frames, 0 meaning search visible and iconified frames, or a
2138 window, meaning search the frame that window belongs to, or a
2139 frame, meaning consider windows on that frame, only. */
2143 /* Return the next or previous window of WINDOW in cyclic ordering
2144 of windows. NEXT_P non-zero means return the next window. See the
2145 documentation string of next-window for the meaning of MINIBUF and
2146 ALL_FRAMES. */
2148 static Lisp_Object
2149 next_window (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames, int next_p)
2151 decode_next_window_args (&window, &minibuf, &all_frames);
2153 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2154 return the first window on the frame. */
2155 if (FRAMEP (all_frames)
2156 && !EQ (all_frames, XWINDOW (window)->frame))
2157 return Fframe_first_window (all_frames);
2159 if (next_p)
2161 Lisp_Object list;
2163 /* Find WINDOW in the list of all windows. */
2164 list = Fmemq (window, window_list ());
2166 /* Scan forward from WINDOW to the end of the window list. */
2167 if (CONSP (list))
2168 for (list = XCDR (list); CONSP (list); list = XCDR (list))
2169 if (candidate_window_p (XCAR (list), window, minibuf, all_frames))
2170 break;
2172 /* Scan from the start of the window list up to WINDOW. */
2173 if (!CONSP (list))
2174 for (list = Vwindow_list;
2175 CONSP (list) && !EQ (XCAR (list), window);
2176 list = XCDR (list))
2177 if (candidate_window_p (XCAR (list), window, minibuf, all_frames))
2178 break;
2180 if (CONSP (list))
2181 window = XCAR (list);
2183 else
2185 Lisp_Object candidate, list;
2187 /* Scan through the list of windows for candidates. If there are
2188 candidate windows in front of WINDOW, the last one of these
2189 is the one we want. If there are candidates following WINDOW
2190 in the list, again the last one of these is the one we want. */
2191 candidate = Qnil;
2192 for (list = window_list (); CONSP (list); list = XCDR (list))
2194 if (EQ (XCAR (list), window))
2196 if (WINDOWP (candidate))
2197 break;
2199 else if (candidate_window_p (XCAR (list), window, minibuf,
2200 all_frames))
2201 candidate = XCAR (list);
2204 if (WINDOWP (candidate))
2205 window = candidate;
2208 return window;
2212 DEFUN ("next-window", Fnext_window, Snext_window, 0, 3, 0,
2213 doc: /* Return window following WINDOW in cyclic ordering of windows.
2214 WINDOW must be a live window and defaults to the selected one. The
2215 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2216 consider.
2218 MINIBUF nil or omitted means consider the minibuffer window only if the
2219 minibuffer is active. MINIBUF t means consider the minibuffer window
2220 even if the minibuffer is not active. Any other value means do not
2221 consider the minibuffer window even if the minibuffer is active.
2223 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2224 plus the minibuffer window if specified by the MINIBUF argument. If the
2225 minibuffer counts, consider all windows on all frames that share that
2226 minibuffer too. The following non-nil values of ALL-FRAMES have special
2227 meanings:
2229 - t means consider all windows on all existing frames.
2231 - `visible' means consider all windows on all visible frames.
2233 - 0 (the number zero) means consider all windows on all visible and
2234 iconified frames.
2236 - A frame means consider all windows on that frame only.
2238 Anything else means consider all windows on WINDOW's frame and no
2239 others.
2241 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2242 `next-window' to iterate through the entire cycle of acceptable
2243 windows, eventually ending up back at the window you started with.
2244 `previous-window' traverses the same cycle, in the reverse order. */)
2245 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2247 return next_window (window, minibuf, all_frames, 1);
2251 DEFUN ("previous-window", Fprevious_window, Sprevious_window, 0, 3, 0,
2252 doc: /* Return window preceding WINDOW in cyclic ordering of windows.
2253 WINDOW must be a live window and defaults to the selected one. The
2254 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2255 consider.
2257 MINIBUF nil or omitted means consider the minibuffer window only if the
2258 minibuffer is active. MINIBUF t means consider the minibuffer window
2259 even if the minibuffer is not active. Any other value means do not
2260 consider the minibuffer window even if the minibuffer is active.
2262 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2263 plus the minibuffer window if specified by the MINIBUF argument. If the
2264 minibuffer counts, consider all windows on all frames that share that
2265 minibuffer too. The following non-nil values of ALL-FRAMES have special
2266 meanings:
2268 - t means consider all windows on all existing frames.
2270 - `visible' means consider all windows on all visible frames.
2272 - 0 (the number zero) means consider all windows on all visible and
2273 iconified frames.
2275 - A frame means consider all windows on that frame only.
2277 Anything else means consider all windows on WINDOW's frame and no
2278 others.
2280 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2281 use `previous-window' to iterate through the entire cycle of
2282 acceptable windows, eventually ending up back at the window you
2283 started with. `next-window' traverses the same cycle, in the
2284 reverse order. */)
2285 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2287 return next_window (window, minibuf, all_frames, 0);
2291 /* Return a list of windows in cyclic ordering. Arguments are like
2292 for `next-window'. */
2294 static Lisp_Object
2295 window_list_1 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2297 Lisp_Object tail, list, rest;
2299 decode_next_window_args (&window, &minibuf, &all_frames);
2300 list = Qnil;
2302 for (tail = window_list (); CONSP (tail); tail = XCDR (tail))
2303 if (candidate_window_p (XCAR (tail), window, minibuf, all_frames))
2304 list = Fcons (XCAR (tail), list);
2306 /* Rotate the list to start with WINDOW. */
2307 list = Fnreverse (list);
2308 rest = Fmemq (window, list);
2309 if (!NILP (rest) && !EQ (rest, list))
2311 for (tail = list; !EQ (XCDR (tail), rest); tail = XCDR (tail))
2313 XSETCDR (tail, Qnil);
2314 list = nconc2 (rest, list);
2316 return list;
2320 DEFUN ("window-list", Fwindow_list, Swindow_list, 0, 3, 0,
2321 doc: /* Return a list of windows on FRAME, starting with WINDOW.
2322 FRAME nil or omitted means use the selected frame.
2323 WINDOW nil or omitted means use the selected window.
2324 MINIBUF t means include the minibuffer window, even if it isn't active.
2325 MINIBUF nil or omitted means include the minibuffer window only
2326 if it's active.
2327 MINIBUF neither nil nor t means never include the minibuffer window. */)
2328 (Lisp_Object frame, Lisp_Object minibuf, Lisp_Object window)
2330 if (NILP (window))
2331 window = FRAMEP (frame) ? XFRAME (frame)->selected_window : selected_window;
2332 CHECK_WINDOW (window);
2333 if (NILP (frame))
2334 frame = selected_frame;
2336 if (!EQ (frame, XWINDOW (window)->frame))
2337 error ("Window is on a different frame");
2339 return window_list_1 (window, minibuf, frame);
2343 DEFUN ("window-list-1", Fwindow_list_1, Swindow_list_1, 0, 3, 0,
2344 doc: /* Return a list of all live windows.
2345 WINDOW specifies the first window to list and defaults to the selected
2346 window.
2348 Optional argument MINIBUF nil or omitted means consider the minibuffer
2349 window only if the minibuffer is active. MINIBUF t means consider the
2350 minibuffer window even if the minibuffer is not active. Any other value
2351 means do not consider the minibuffer window even if the minibuffer is
2352 active.
2354 Optional argument ALL-FRAMES nil or omitted means consider all windows
2355 on WINDOW's frame, plus the minibuffer window if specified by the
2356 MINIBUF argument. If the minibuffer counts, consider all windows on all
2357 frames that share that minibuffer too. The following non-nil values of
2358 ALL-FRAMES have special meanings:
2360 - t means consider all windows on all existing frames.
2362 - `visible' means consider all windows on all visible frames.
2364 - 0 (the number zero) means consider all windows on all visible and
2365 iconified frames.
2367 - A frame means consider all windows on that frame only.
2369 Anything else means consider all windows on WINDOW's frame and no
2370 others.
2372 If WINDOW is not on the list of windows returned, some other window will
2373 be listed first but no error is signalled. */)
2374 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2376 return window_list_1 (window, minibuf, all_frames);
2379 /* Look at all windows, performing an operation specified by TYPE
2380 with argument OBJ.
2381 If FRAMES is Qt, look at all frames;
2382 Qnil, look at just the selected frame;
2383 Qvisible, look at visible frames;
2384 a frame, just look at windows on that frame.
2385 If MINI is non-zero, perform the operation on minibuffer windows too. */
2387 enum window_loop
2389 WINDOW_LOOP_UNUSED,
2390 GET_BUFFER_WINDOW, /* Arg is buffer */
2391 REPLACE_BUFFER_IN_WINDOWS_SAFELY, /* Arg is buffer */
2392 REDISPLAY_BUFFER_WINDOWS, /* Arg is buffer */
2393 CHECK_ALL_WINDOWS
2396 static Lisp_Object
2397 window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frames)
2399 Lisp_Object window, windows, best_window, frame_arg;
2400 int frame_best_window_flag = 0;
2401 struct frame *f;
2402 struct gcpro gcpro1;
2404 /* If we're only looping through windows on a particular frame,
2405 frame points to that frame. If we're looping through windows
2406 on all frames, frame is 0. */
2407 if (FRAMEP (frames))
2408 f = XFRAME (frames);
2409 else if (NILP (frames))
2410 f = SELECTED_FRAME ();
2411 else
2412 f = NULL;
2414 if (f)
2415 frame_arg = Qlambda;
2416 else if (EQ (frames, make_number (0)))
2417 frame_arg = frames;
2418 else if (EQ (frames, Qvisible))
2419 frame_arg = frames;
2420 else
2421 frame_arg = Qt;
2423 /* frame_arg is Qlambda to stick to one frame,
2424 Qvisible to consider all visible frames,
2425 or Qt otherwise. */
2427 /* Pick a window to start with. */
2428 if (WINDOWP (obj))
2429 window = obj;
2430 else if (f)
2431 window = FRAME_SELECTED_WINDOW (f);
2432 else
2433 window = FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2435 windows = window_list_1 (window, mini ? Qt : Qnil, frame_arg);
2436 GCPRO1 (windows);
2437 best_window = Qnil;
2439 for (; CONSP (windows); windows = XCDR (windows))
2441 struct window *w;
2443 window = XCAR (windows);
2444 w = XWINDOW (window);
2446 /* Note that we do not pay attention here to whether the frame
2447 is visible, since Fwindow_list skips non-visible frames if
2448 that is desired, under the control of frame_arg. */
2449 if (!MINI_WINDOW_P (w)
2450 /* For REPLACE_BUFFER_IN_WINDOWS_SAFELY, we must always
2451 consider all windows. */
2452 || type == REPLACE_BUFFER_IN_WINDOWS_SAFELY
2453 || (mini && minibuf_level > 0))
2454 switch (type)
2456 case GET_BUFFER_WINDOW:
2457 if (EQ (w->buffer, obj)
2458 /* Don't find any minibuffer window except the one that
2459 is currently in use. */
2460 && (MINI_WINDOW_P (w) ? EQ (window, minibuf_window) : 1))
2462 if (EQ (window, selected_window))
2463 /* Preferably return the selected window. */
2464 RETURN_UNGCPRO (window);
2465 else if (EQ (XWINDOW (window)->frame, selected_frame)
2466 && !frame_best_window_flag)
2467 /* Prefer windows on the current frame (but don't
2468 choose another one if we have one already). */
2470 best_window = window;
2471 frame_best_window_flag = 1;
2473 else if (NILP (best_window))
2474 best_window = window;
2476 break;
2478 case REPLACE_BUFFER_IN_WINDOWS_SAFELY:
2479 /* We could simply check whether the buffer shown by window
2480 is live, and show another buffer in case it isn't. */
2481 if (EQ (w->buffer, obj))
2483 /* Undedicate WINDOW. */
2484 w->dedicated = Qnil;
2485 /* Make WINDOW show the buffer returned by Fother_buffer
2486 but don't run any hooks. */
2487 set_window_buffer
2488 (window, Fother_buffer (w->buffer, Qnil, w->frame), 0, 0);
2489 /* If WINDOW is the selected window, make its buffer
2490 current. But do so only if the window shows the
2491 current buffer (Bug#6454). */
2492 if (EQ (window, selected_window)
2493 && XBUFFER (w->buffer) == current_buffer)
2494 Fset_buffer (w->buffer);
2496 break;
2498 case REDISPLAY_BUFFER_WINDOWS:
2499 if (EQ (w->buffer, obj))
2501 mark_window_display_accurate (window, 0);
2502 w->update_mode_line = Qt;
2503 XBUFFER (obj)->prevent_redisplay_optimizations_p = 1;
2504 ++update_mode_lines;
2505 best_window = window;
2507 break;
2509 /* Check for a window that has a killed buffer. */
2510 case CHECK_ALL_WINDOWS:
2511 if (! NILP (w->buffer)
2512 && NILP (XBUFFER (w->buffer)->name))
2513 abort ();
2514 break;
2516 case WINDOW_LOOP_UNUSED:
2517 break;
2521 UNGCPRO;
2522 return best_window;
2525 /* Used for debugging. Abort if any window has a dead buffer. */
2527 void
2528 check_all_windows (void)
2530 window_loop (CHECK_ALL_WINDOWS, Qnil, 1, Qt);
2533 DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 0, 2, 0,
2534 doc: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2535 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to
2536 the current buffer.
2538 The optional argument ALL-FRAMES specifies the frames to consider:
2540 - t means consider all windows on all existing frames.
2542 - `visible' means consider all windows on all visible frames.
2544 - 0 (the number zero) means consider all windows on all visible
2545 and iconified frames.
2547 - A frame means consider all windows on that frame only.
2549 Any other value of ALL-FRAMES means consider all windows on the
2550 selected frame and no others. */)
2551 (Lisp_Object buffer_or_name, Lisp_Object all_frames)
2553 Lisp_Object buffer;
2555 if (NILP (buffer_or_name))
2556 buffer = Fcurrent_buffer ();
2557 else
2558 buffer = Fget_buffer (buffer_or_name);
2560 if (BUFFERP (buffer))
2561 return window_loop (GET_BUFFER_WINDOW, buffer, 1, all_frames);
2562 else
2563 return Qnil;
2566 Lisp_Object
2567 resize_root_window (Lisp_Object window, Lisp_Object delta, Lisp_Object horizontal, Lisp_Object ignore)
2569 return call4 (Qresize_root_window, window, delta, horizontal, ignore);
2573 DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal,
2574 Sdelete_other_windows_internal, 0, 2, "",
2575 doc: /* Make WINDOW fill its frame.
2576 Only the frame WINDOW is on is affected. WINDOW may be any window and
2577 defaults to the selected one.
2579 Optional argument ROOT, if non-nil, must specify an internal window
2580 containing WINDOW as a subwindow. If this is the case, replace ROOT by
2581 WINDOW and leave alone any windows not contained in ROOT.
2583 When WINDOW is live try to reduce display jumps by keeping the text
2584 previously visible in WINDOW in the same place on the frame. Doing this
2585 depends on the value of (window-start WINDOW), so if calling this
2586 function in a program gives strange scrolling, make sure the
2587 window-start value is reasonable when this function is called. */)
2588 (Lisp_Object window, Lisp_Object root)
2590 struct window *w, *r, *s;
2591 struct frame *f;
2592 Lisp_Object sibling, pwindow, swindow, delta;
2593 int startpos, top, new_top, resize_failed;
2595 w = decode_any_window (window);
2596 XSETWINDOW (window, w);
2597 f = XFRAME (w->frame);
2599 if (NILP (root))
2600 /* ROOT is the frame's root window. */
2602 root = FRAME_ROOT_WINDOW (f);
2603 r = XWINDOW (root);
2605 else
2606 /* ROOT must be an ancestor of WINDOW. */
2608 r = decode_any_window (root);
2609 pwindow = XWINDOW (window)->parent;
2610 while (!NILP (pwindow))
2611 if (EQ (pwindow, root))
2612 break;
2613 else
2614 pwindow = XWINDOW (pwindow)->parent;
2615 if (!EQ (pwindow, root))
2616 error ("Specified root is not an ancestor of specified window");
2619 if (EQ (window, root))
2620 /* A noop. */
2621 return Qnil;
2622 /* I don't understand the "top > 0" part below. If we deal with a
2623 standalone minibuffer it would have been caught by the preceding
2624 test. */
2625 else if (MINI_WINDOW_P (w)) /* && top > 0) */
2626 error ("Can't expand minibuffer to full frame");
2628 if (!NILP (w->buffer))
2630 startpos = marker_position (w->start);
2631 top = WINDOW_TOP_EDGE_LINE (w)
2632 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w)));
2633 /* Make sure WINDOW is the frame's selected window. */
2634 if (!EQ (window, FRAME_SELECTED_WINDOW (f)))
2636 if (EQ (selected_frame, w->frame))
2637 Fselect_window (window, Qnil);
2638 else
2639 FRAME_SELECTED_WINDOW (f) = window;
2642 else
2644 /* See if the frame's selected window is a subwindow of WINDOW, by
2645 finding all the selected window's parents and comparing each
2646 one with WINDOW. If it isn't we need a new selected window for
2647 this frame. */
2648 swindow = FRAME_SELECTED_WINDOW (f);
2649 while (1)
2651 pwindow = swindow;
2652 while (!NILP (pwindow) && !EQ (window, pwindow))
2653 pwindow = XWINDOW (pwindow)->parent;
2655 if (EQ (window, pwindow))
2656 /* If WINDOW is an ancestor of SWINDOW, then SWINDOW is ok
2657 as the new selected window. */
2658 break;
2659 else
2660 /* Else try the previous window of SWINDOW. */
2661 swindow = Fprevious_window (swindow, Qlambda, Qnil);
2664 if (!EQ (swindow, FRAME_SELECTED_WINDOW (f)))
2666 if (EQ (selected_frame, w->frame))
2667 Fselect_window (swindow, Qnil);
2668 else
2669 FRAME_SELECTED_WINDOW (f) = swindow;
2673 BLOCK_INPUT;
2674 free_window_matrices (r);
2676 windows_or_buffers_changed++;
2677 Vwindow_list = Qnil;
2678 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
2680 if (NILP (w->buffer))
2682 resize_failed = 0;
2683 /* Resize subwindows vertically. */
2684 XSETINT (delta, XINT (r->total_lines) - XINT (w->total_lines));
2685 w->top_line = r->top_line;
2686 resize_root_window (window, delta, Qnil, Qnil);
2687 if (resize_window_check (w, 0))
2688 resize_window_apply (w, 0);
2689 else
2691 resize_root_window (window, delta, Qnil, Qt);
2692 if (resize_window_check (w, 0))
2693 resize_window_apply (w, 0);
2694 else
2695 resize_failed = 1;
2698 /* Resize subwindows horizontally. */
2699 if (!resize_failed)
2701 w->left_col = r->left_col;
2702 XSETINT (delta, XINT (r->total_cols) - XINT (w->total_cols));
2703 w->left_col = r->left_col;
2704 resize_root_window (window, delta, Qt, Qnil);
2705 if (resize_window_check (w, 1))
2706 resize_window_apply (w, 1);
2707 else
2709 resize_root_window (window, delta, Qt, Qt);
2710 if (resize_window_check (w, 1))
2711 resize_window_apply (w, 1);
2712 else
2713 resize_failed = 1;
2717 if (resize_failed)
2718 /* Play safe, if we still can ... */
2720 window = swindow;
2721 w = XWINDOW (window);
2725 /* Cleanly unlink WINDOW from window-tree. */
2726 if (!NILP (w->prev))
2727 /* Get SIBLING above (on the left of) WINDOW. */
2729 sibling = w->prev;
2730 s = XWINDOW (sibling);
2731 s->next = w->next;
2732 if (!NILP (s->next))
2733 XWINDOW (s->next)->prev = sibling;
2735 else
2736 /* Get SIBLING below (on the right of) WINDOW. */
2738 sibling = w->next;
2739 s = XWINDOW (sibling);
2740 s->prev = Qnil;
2741 if (!NILP (XWINDOW (w->parent)->vchild))
2742 XWINDOW (w->parent)->vchild = sibling;
2743 else
2744 XWINDOW (w->parent)->hchild = sibling;
2747 /* Delete ROOT and all subwindows of ROOT. */
2748 if (!NILP (r->vchild))
2750 delete_all_subwindows (r->vchild);
2751 r->vchild = Qnil;
2753 else if (!NILP (r->hchild))
2755 delete_all_subwindows (r->hchild);
2756 r->hchild = Qnil;
2759 replace_window (root, window, 1);
2761 /* This must become SWINDOW anyway ....... */
2762 if (!NILP (w->buffer) && !resize_failed)
2764 /* Try to minimize scrolling, by setting the window start to the
2765 point will cause the text at the old window start to be at the
2766 same place on the frame. But don't try to do this if the
2767 window start is outside the visible portion (as might happen
2768 when the display is not current, due to typeahead). */
2769 new_top = WINDOW_TOP_EDGE_LINE (w) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w)));
2770 if (new_top != top
2771 && startpos >= BUF_BEGV (XBUFFER (w->buffer))
2772 && startpos <= BUF_ZV (XBUFFER (w->buffer)))
2774 struct position pos;
2775 struct buffer *obuf = current_buffer;
2777 Fset_buffer (w->buffer);
2778 /* This computation used to temporarily move point, but that
2779 can have unwanted side effects due to text properties. */
2780 pos = *vmotion (startpos, -top, w);
2782 set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos);
2783 w->window_end_valid = Qnil;
2784 w->start_at_line_beg = ((pos.bytepos == BEGV_BYTE
2785 || FETCH_BYTE (pos.bytepos - 1) == '\n') ? Qt
2786 : Qnil);
2787 /* We need to do this, so that the window-scroll-functions
2788 get called. */
2789 w->optional_new_start = Qt;
2791 set_buffer_internal (obuf);
2795 adjust_glyphs (f);
2796 UNBLOCK_INPUT;
2798 run_window_configuration_change_hook (f);
2800 return Qnil;
2804 void
2805 replace_buffer_in_windows (Lisp_Object buffer)
2807 call1 (Qreplace_buffer_in_windows, buffer);
2811 /* Safely replace BUFFER with some other buffer in all windows of all
2812 frames, even those on other keyboards. */
2814 void
2815 replace_buffer_in_windows_safely (Lisp_Object buffer)
2817 Lisp_Object tail, frame;
2819 /* A single call to window_loop won't do the job because it only
2820 considers frames on the current keyboard. So loop manually over
2821 frames, and handle each one. */
2822 FOR_EACH_FRAME (tail, frame)
2823 window_loop (REPLACE_BUFFER_IN_WINDOWS_SAFELY, buffer, 1, frame);
2826 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2827 minimum allowable size. */
2829 void
2830 check_frame_size (FRAME_PTR frame, int *rows, int *cols)
2832 /* For height, we have to see:
2833 how many windows the frame has at minimum (one or two),
2834 and whether it has a menu bar or other special stuff at the top. */
2835 int min_height
2836 = ((FRAME_MINIBUF_ONLY_P (frame) || ! FRAME_HAS_MINIBUF_P (frame))
2837 ? MIN_SAFE_WINDOW_HEIGHT
2838 : 2 * MIN_SAFE_WINDOW_HEIGHT);
2840 if (FRAME_TOP_MARGIN (frame) > 0)
2841 min_height += FRAME_TOP_MARGIN (frame);
2843 if (*rows < min_height)
2844 *rows = min_height;
2845 if (*cols < MIN_SAFE_WINDOW_WIDTH)
2846 *cols = MIN_SAFE_WINDOW_WIDTH;
2849 /* Adjust the margins of window W if text area is too small.
2850 Return 1 if window width is ok after adjustment; 0 if window
2851 is still too narrow. */
2853 static int
2854 adjust_window_margins (struct window *w)
2856 int box_cols = (WINDOW_TOTAL_COLS (w)
2857 - WINDOW_FRINGE_COLS (w)
2858 - WINDOW_SCROLL_BAR_COLS (w));
2859 int margin_cols = (WINDOW_LEFT_MARGIN_COLS (w)
2860 + WINDOW_RIGHT_MARGIN_COLS (w));
2862 if (box_cols - margin_cols >= MIN_SAFE_WINDOW_WIDTH)
2863 return 1;
2865 if (margin_cols < 0 || box_cols < MIN_SAFE_WINDOW_WIDTH)
2866 return 0;
2868 /* Window's text area is too narrow, but reducing the window
2869 margins will fix that. */
2870 margin_cols = box_cols - MIN_SAFE_WINDOW_WIDTH;
2871 if (WINDOW_RIGHT_MARGIN_COLS (w) > 0)
2873 if (WINDOW_LEFT_MARGIN_COLS (w) > 0)
2874 w->left_margin_cols = w->right_margin_cols
2875 = make_number (margin_cols/2);
2876 else
2877 w->right_margin_cols = make_number (margin_cols);
2879 else
2880 w->left_margin_cols = make_number (margin_cols);
2881 return 1;
2884 EXFUN (Fset_window_fringes, 4);
2885 EXFUN (Fset_window_scroll_bars, 4);
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 if (SELECTED_FRAME () != f)
2924 record_unwind_protect (select_frame_norecord, Fselected_frame ());
2925 Fselect_frame (frame, Qt);
2928 /* Use the right buffer. Matters when running the local hooks. */
2929 if (current_buffer != XBUFFER (Fwindow_buffer (Qnil)))
2931 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
2932 Fset_buffer (Fwindow_buffer (Qnil));
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 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 (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 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 (b->display_count))
2993 XSETINT (b->display_count, XINT (b->display_count) + 1);
2994 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 b->left_fringe_width, b->right_fringe_width,
3048 b->fringes_outside_margins);
3050 Fset_window_scroll_bars (window,
3051 b->scroll_bar_width,
3052 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 b->left_margin_cols, 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 (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 (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 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 (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 XBUFFER (buf)->directory = 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 #if 0 /* rms: there should be no reason for this. */
3192 XBUFFER (buf)->prevent_redisplay_optimizations_p = 1;
3193 #endif
3194 set_buffer_internal (old);
3196 if (!NILP (Vtemp_buffer_show_function))
3197 call1 (Vtemp_buffer_show_function, buf);
3198 else
3200 window = display_buffer (buf, Qnil, Qnil);
3202 if (!EQ (XWINDOW (window)->frame, selected_frame))
3203 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
3204 Vminibuf_scroll_window = window;
3205 w = XWINDOW (window);
3206 XSETFASTINT (w->hscroll, 0);
3207 XSETFASTINT (w->min_hscroll, 0);
3208 set_marker_restricted_both (w->start, buf, BEG, BEG);
3209 set_marker_restricted_both (w->pointm, buf, BEG, BEG);
3211 /* Run temp-buffer-show-hook, with the chosen window selected
3212 and its buffer current. */
3214 if (!NILP (Vrun_hooks)
3215 && !NILP (Fboundp (Qtemp_buffer_show_hook))
3216 && !NILP (Fsymbol_value (Qtemp_buffer_show_hook)))
3218 int count = SPECPDL_INDEX ();
3219 Lisp_Object prev_window, prev_buffer;
3220 prev_window = selected_window;
3221 XSETBUFFER (prev_buffer, old);
3223 /* Select the window that was chosen, for running the hook.
3224 Note: Both Fselect_window and select_window_norecord may
3225 set-buffer to the buffer displayed in the window,
3226 so we need to save the current buffer. --stef */
3227 record_unwind_protect (Fset_buffer, prev_buffer);
3228 record_unwind_protect (select_window_norecord, prev_window);
3229 Fselect_window (window, Qt);
3230 Fset_buffer (w->buffer);
3231 call1 (Vrun_hooks, Qtemp_buffer_show_hook);
3232 unbind_to (count, Qnil);
3237 /* Make new window, have it replace WINDOW in window-tree, and make
3238 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
3239 horizontal child). */
3240 static void
3241 make_parent_window (Lisp_Object window, int horflag)
3243 Lisp_Object parent;
3244 register struct window *o, *p;
3245 int i;
3247 o = XWINDOW (window);
3248 p = allocate_window ();
3249 for (i = 0; i < VECSIZE (struct window); ++i)
3250 ((struct Lisp_Vector *) p)->contents[i]
3251 = ((struct Lisp_Vector *) o)->contents[i];
3252 XSETWINDOW (parent, p);
3254 ++sequence_number;
3255 XSETFASTINT (p->sequence_number, sequence_number);
3257 replace_window (window, parent, 1);
3259 o->next = Qnil;
3260 o->prev = Qnil;
3261 o->parent = parent;
3263 p->hchild = horflag ? window : Qnil;
3264 p->vchild = horflag ? Qnil : window;
3265 p->start = Qnil;
3266 p->pointm = Qnil;
3267 p->buffer = Qnil;
3268 p->window_parameters = Qnil;
3271 /* Make new window from scratch. */
3272 Lisp_Object
3273 make_window (void)
3275 Lisp_Object window;
3276 register struct window *w;
3278 w = allocate_window ();
3279 /* Initialize all Lisp data. */
3280 w->frame = w->mini_p = Qnil;
3281 w->next = w->prev = w->hchild = w->vchild = w->parent = Qnil;
3282 XSETFASTINT (w->left_col, 0);
3283 XSETFASTINT (w->top_line, 0);
3284 XSETFASTINT (w->total_lines, 0);
3285 XSETFASTINT (w->total_cols, 0);
3286 XSETFASTINT (w->normal_lines, 1);
3287 XSETFASTINT (w->normal_cols, 1);
3288 XSETFASTINT (w->new_total, 0);
3289 XSETFASTINT (w->new_normal, 0);
3290 w->buffer = Qnil;
3291 w->start = Fmake_marker ();
3292 w->pointm = Fmake_marker ();
3293 w->force_start = w->optional_new_start = Qnil;
3294 XSETFASTINT (w->hscroll, 0);
3295 XSETFASTINT (w->min_hscroll, 0);
3296 XSETFASTINT (w->use_time, 0);
3297 ++sequence_number;
3298 XSETFASTINT (w->sequence_number, sequence_number);
3299 w->temslot = w->last_modified = w->last_overlay_modified = Qnil;
3300 XSETFASTINT (w->last_point, 0);
3301 w->last_had_star = w->vertical_scroll_bar = Qnil;
3302 w->left_margin_cols = w->right_margin_cols = Qnil;
3303 w->left_fringe_width = w->right_fringe_width = Qnil;
3304 w->fringes_outside_margins = Qnil;
3305 w->scroll_bar_width = Qnil;
3306 w->vertical_scroll_bar_type = Qt;
3307 w->last_mark_x = w->last_mark_y = Qnil;
3308 XSETFASTINT (w->window_end_pos, 0);
3309 XSETFASTINT (w->window_end_vpos, 0);
3310 w->window_end_valid = w->update_mode_line = Qnil;
3311 w->start_at_line_beg = w->display_table = w->dedicated = Qnil;
3312 w->base_line_number = w->base_line_pos = w->region_showing = Qnil;
3313 w->column_number_displayed = w->redisplay_end_trigger = Qnil;
3314 w->inhibit_recombine = w->window_parameters = Qnil;
3315 w->prev_buffers = w->next_buffers = Qnil;
3316 /* Initialize non-Lisp data. */
3317 w->desired_matrix = w->current_matrix = 0;
3318 w->nrows_scale_factor = w->ncols_scale_factor = 1;
3319 memset (&w->cursor, 0, sizeof (w->cursor));
3320 memset (&w->last_cursor, 0, sizeof (w->last_cursor));
3321 memset (&w->phys_cursor, 0, sizeof (w->phys_cursor));
3322 w->phys_cursor_type = -1;
3323 w->phys_cursor_width = -1;
3324 w->last_cursor_off_p = w->cursor_off_p = 0;
3325 w->must_be_updated_p = 0;
3326 w->pseudo_window_p = 0;
3327 w->frozen_window_start_p = 0;
3328 w->vscroll = 0;
3329 /* Reset window_list. */
3330 Vwindow_list = Qnil;
3331 /* Return window. */
3332 XSETWINDOW (window, w);
3333 return window;
3336 DEFUN ("resize-window-total", Fresize_window_total, Sresize_window_total, 2, 3, 0,
3337 doc: /* Set new total size of WINDOW to SIZE.
3338 Return SIZE.
3340 Optional argument ADD non-nil means add SIZE to the new total size of
3341 WINDOW and return the sum.
3343 Note: This function does not operate on any subwindows of WINDOW. */)
3344 (Lisp_Object window, Lisp_Object size, Lisp_Object add)
3346 struct window *w = decode_any_window (window);
3348 CHECK_NUMBER (size);
3349 if (NILP (add))
3350 XSETINT (w->new_total, XINT (size));
3351 else
3352 XSETINT (w->new_total, XINT (w->new_total) + XINT (size));
3354 return w->new_total;
3357 DEFUN ("resize-window-normal", Fresize_window_normal, Sresize_window_normal, 1, 2, 0,
3358 doc: /* Set new normal size of WINDOW to SIZE.
3359 Return SIZE.
3361 Note: This function does not operate on any subwindows of WINDOW. */)
3362 (Lisp_Object window, Lisp_Object size)
3364 struct window *w = decode_any_window (window);
3366 w->new_normal = size;
3367 return w->new_normal;
3370 /* Return 1 if setting w->total_lines (w->total_cols if HORFLAG is
3371 non-zero) to w->new_total would result in correct heights (widths)
3372 for window W and recursively all subwindows of W.
3374 Note: This function does not check any of `window-fixed-size-p',
3375 `window-min-height' or `window-min-width'. It does check that window
3376 sizes do not drop below one line (two columns). */
3378 resize_window_check (struct window *w, int horflag)
3380 struct window *c;
3382 if (!NILP (w->vchild))
3383 /* W is a vertical combination. */
3385 c = XWINDOW (w->vchild);
3386 if (horflag)
3387 /* All subwindows of W must have the same width as W. */
3389 while (c)
3391 if ((XINT (c->new_total) != XINT (w->new_total))
3392 || !resize_window_check (c, horflag))
3393 return 0;
3394 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3396 return 1;
3398 else
3399 /* The sum of the heights of the subwindows of W must equal W's
3400 height. */
3402 int sum_of_sizes = 0;
3403 while (c)
3405 if (!resize_window_check (c, horflag))
3406 return 0;
3407 sum_of_sizes = sum_of_sizes + XINT (c->new_total);
3408 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3410 return (sum_of_sizes == XINT (w->new_total));
3413 else if (!NILP (w->hchild))
3414 /* W is a horizontal combination. */
3416 c = XWINDOW (w->hchild);
3417 if (horflag)
3418 /* The sum of the widths of the subwindows of W must equal W's
3419 width. */
3421 int sum_of_sizes = 0;
3422 while (c)
3424 if (!resize_window_check (c, horflag))
3425 return 0;
3426 sum_of_sizes = sum_of_sizes + XINT (c->new_total);
3427 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3429 return (sum_of_sizes == XINT (w->new_total));
3431 else
3432 /* All subwindows of W must have the same height as W. */
3434 while (c)
3436 if ((XINT (c->new_total) != XINT (w->new_total))
3437 || !resize_window_check (c, horflag))
3438 return 0;
3439 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3441 return 1;
3444 else
3445 /* A leaf window. Make sure it's not too small. The following
3446 hardcodes the values of `window-safe-min-width' (2) and
3447 `window-safe-min-height' (1) which are defined in window.el. */
3448 return XINT (w->new_total) >= (horflag ? 2 : 1);
3451 /* Set w->total_lines (w->total_cols if HORIZONTAL is non-zero) to
3452 w->new_total for window W and recursively all subwindows of W. Also
3453 calculate and assign the new vertical (horizontal) start positions of
3454 each of these windows.
3456 This function does not perform any error checks. Make sure you have
3457 run resize_window_check on W before applying this function. */
3458 void
3459 resize_window_apply (struct window *w, int horflag)
3461 struct window *c, *p;
3462 int pos;
3464 /* Note: Assigning new_normal requires that the new total size of the
3465 parent window has been set *before*. */
3466 if (horflag)
3468 w->total_cols = w->new_total;
3469 if (EQ (w->new_normal, Qset))
3471 if (NILP (w->parent))
3472 XSETFASTINT (w->normal_cols, 1);
3473 else
3474 w->normal_cols
3475 = make_float (XFLOATINT (w->total_cols)
3476 / XFLOATINT (XWINDOW (w->parent)->total_cols));
3478 else if (NUMBERP (w->new_normal))
3479 w->normal_cols = w->new_normal;
3481 pos = XINT (w->left_col);
3483 else
3485 w->total_lines = w->new_total;
3486 if (EQ (w->new_normal, Qset))
3488 if (NILP (w->parent))
3489 XSETFASTINT (w->normal_lines, 1);
3490 else
3491 w->normal_lines
3492 = make_float (XFLOATINT (w->total_lines)
3493 / XFLOATINT (XWINDOW (w->parent)->total_lines));
3495 else if (NUMBERP (w->new_normal))
3496 w->normal_lines = w->new_normal;
3498 pos = XINT (w->top_line);
3501 if (!NILP (w->vchild))
3502 /* W is a vertical combination. */
3504 c = XWINDOW (w->vchild);
3505 while (c)
3507 if (horflag)
3508 XSETFASTINT (c->left_col, pos);
3509 else
3510 XSETFASTINT (c->top_line, pos);
3511 resize_window_apply (c, horflag);
3512 if (!horflag)
3513 pos = pos + XINT (c->total_lines);
3514 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3517 else if (!NILP (w->hchild))
3518 /* W is a horizontal combination. */
3520 c = XWINDOW (w->hchild);
3521 while (c)
3523 if (horflag)
3524 XSETFASTINT (c->left_col, pos);
3525 else
3526 XSETFASTINT (c->top_line, pos);
3527 resize_window_apply (c, horflag);
3528 if (horflag)
3529 pos = pos + XINT (c->total_cols);
3530 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3534 /* Clear out some redisplay caches. */
3535 XSETFASTINT (w->last_modified, 0);
3536 XSETFASTINT (w->last_overlay_modified, 0);
3540 DEFUN ("resize-window-apply", Fresize_window_apply, Sresize_window_apply, 1, 2, 0,
3541 doc: /* Apply requested size values for window-tree of FRAME.
3542 Optional argument HORIZONTAL omitted or nil means apply requested height
3543 values. HORIZONTAL non-nil means apply requested width values.
3545 This function checks whether the requested values sum up to a valid
3546 window layout, recursively assigns the new sizes of all subwindows and
3547 calculates and assigns the new start positions of these windows.
3549 Note: This function does not check any of `window-fixed-size-p',
3550 `window-min-height' or `window-min-width'. All these checks have to
3551 be applied on the Elisp level. */)
3552 (Lisp_Object frame, Lisp_Object horizontal)
3554 struct frame *f;
3555 struct window *r;
3556 int horflag = !NILP (horizontal);
3558 if (NILP (frame))
3559 frame = selected_frame;
3560 CHECK_LIVE_FRAME (frame);
3562 f = XFRAME (frame);
3563 r = XWINDOW (FRAME_ROOT_WINDOW (f));
3565 if (!resize_window_check (r, horflag)
3566 || (r->new_total != (horflag ? r->total_cols : r->total_lines)))
3567 return Qnil;
3569 BLOCK_INPUT;
3570 resize_window_apply (r, horflag);
3572 windows_or_buffers_changed++;
3573 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
3575 adjust_glyphs (f);
3576 UNBLOCK_INPUT;
3578 run_window_configuration_change_hook (f);
3580 return Qt;
3584 /* Resize frame F's windows when number of lines of F is set to SIZE.
3585 HORFLAG 1 means resize windows when number of columns of F is set to
3586 SIZE.
3588 This function can delete all windows but the selected one in order to
3589 satisfy the request. The result will be meaningful if and only if
3590 F's windows have meaningful sizes when you call this. */
3591 void
3592 resize_frame_windows (struct frame *f, int size, int horflag)
3594 Lisp_Object root = f->root_window;
3595 struct window *r = XWINDOW (root);
3596 Lisp_Object mini = f->minibuffer_window;
3597 struct window *m;
3599 XSETFASTINT (r->top_line, FRAME_TOP_MARGIN (f));
3601 if (NILP (r->vchild) && NILP (r->hchild))
3602 /* For a leaf root window just set the size. */
3603 if (horflag)
3604 XSETFASTINT (r->total_cols, size);
3605 else
3606 XSETFASTINT (r->total_lines,
3607 /* Take menubar, toolbar, and minibuffer into account. */
3608 size
3609 - FRAME_TOP_MARGIN (f)
3610 - ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
3611 ? 1 : 0));
3612 else
3614 Lisp_Object delta;
3616 if (horflag)
3617 XSETINT (delta, size - XINT (r->total_cols));
3618 else
3620 /* Take menubar, toolbar, and minibuffer into account. */
3621 XSETINT (delta,
3622 size
3623 - FRAME_TOP_MARGIN (f)
3624 - ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
3625 ? 1 : 0)
3626 - XINT (r->total_lines));
3628 size = size - 1;
3631 resize_root_window (root, delta, horflag ? Qt : Qnil, Qnil);
3632 if (resize_window_check (r, horflag))
3633 resize_window_apply (r, horflag);
3634 else
3636 resize_root_window (root, delta, horflag ? Qt : Qnil, Qt);
3637 if (resize_window_check (r, horflag))
3638 resize_window_apply (r, horflag);
3639 else
3641 root = f->selected_window;
3642 Fdelete_other_windows_internal (root, Qnil);
3643 if (horflag)
3644 XSETFASTINT (r->total_cols, size);
3645 else
3646 XSETFASTINT (r->total_lines, size);
3651 if (FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
3653 m = XWINDOW (mini);
3654 if (horflag)
3655 XSETFASTINT (m->total_cols, size);
3656 else
3658 /* Are we sure we always want 1 line here? */
3659 XSETFASTINT (m->total_lines, 1);
3660 XSETFASTINT (m->top_line, XINT (r->top_line) + XINT (r->total_lines));
3666 DEFUN ("split-window-internal", Fsplit_window_internal, Ssplit_window_internal, 2, 3, 0,
3667 doc: /* Split window OLD vertically giving the new window SIZE lines.
3668 Optional argument HORIZONTAL non-nil means split OLD giving the new
3669 window SIZE columns. In any case SIZE must be a positive integer.
3671 Optional third argument HORIZONTAL nil (or `below') specifies that the
3672 new window shall be located below WINDOW. HORIZONTAL `above' means the
3673 new window shall be located above WINDOW. In these cases SIZE specifies
3674 the new number of lines for WINDOW (or the new window provided SIZE is
3675 negative) including space reserved for the mode and/or header line.
3677 HORIZONTAL t (or `right') specifies that the new window shall be located
3678 on the right side of WINDOW. HORIZONTAL `left' means the new window
3679 shall be located on the left of WINDOW. In these cases SIZE specifies
3680 the new number of columns for WINDOW (or the new window provided SIZE is
3681 negative) including space reserved for fringes and the scrollbar or a
3682 divder column. */)
3683 (Lisp_Object old, Lisp_Object size, Lisp_Object horizontal)
3685 /* OLD (*o) is the window we have to split. (*p) is either OLD's
3686 parent window or an internal window we have to install as OLD's new
3687 parent. REFERENCE (*r) must denote a live window, or is set to OLD
3688 provided OLD is a leaf window, or to the frame's selected window.
3689 NEW (*n) is the new window created with some parameters taken from
3690 REFERENCE (*r). */
3691 register Lisp_Object new, frame, reference;
3692 register struct window *o, *p, *n, *r;
3693 struct frame *f;
3694 int horflag
3695 /* HORFLAG is 1 when we split horizontally, 0 otherwise. */
3696 = EQ (horizontal, Qt) || EQ (horizontal, Qleft) || EQ (horizontal, Qright);
3697 int do_resize;
3699 CHECK_WINDOW (old);
3700 o = XWINDOW (old);
3701 frame = WINDOW_FRAME (o);
3702 f = XFRAME (frame);
3704 CHECK_NUMBER (size);
3706 /* Set do_resize to 1 iff we don't nest and OLD has an iso-combined
3707 parent window. */
3708 do_resize =
3709 EQ (Vwindow_splits, Qresize)
3710 && !NILP (o->parent)
3711 && (horflag
3712 ? !NILP (XWINDOW (o->parent)->hchild)
3713 : !NILP (XWINDOW (o->parent)->vchild));
3715 /* We may need a live reference window to copy some parameters. */
3716 if (WINDOW_LIVE_P (old))
3717 reference = old;
3718 else /* Neither REFERENCE nor OLD are alive. Use the frame's
3719 selected window as reference window. */
3720 reference = FRAME_SELECTED_WINDOW (f);
3721 r = XWINDOW (reference);
3723 /* The following bugs are caught by `split-window'. */
3724 if (MINI_WINDOW_P (o))
3725 error ("Attempt to split minibuffer window");
3726 else if (XINT (size) < (horflag ? 2 : 1))
3727 error ("Size of new window too small (after split)");
3728 else if (do_resize)
3730 p = XWINDOW (o->parent);
3731 /* Temporarily pretend we split the parent window. */
3732 XSETINT (p->new_total,
3733 XINT (horflag ? p->total_cols : p->total_lines) - XINT (size));
3734 if (!resize_window_check (p, horflag))
3735 error ("Sum of window sizes won't fit");
3736 else
3737 /* Undo the temporal pretension. */
3738 p->new_total = horflag ? p->total_cols : p->total_lines;
3740 else
3742 if (!resize_window_check (o, horflag))
3743 error ("Resizing old window failed");
3744 else if (XINT (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 (NILP (o->parent)
3751 || NILP (horflag
3752 ? (XWINDOW (o->parent)->hchild)
3753 : (XWINDOW (o->parent)->vchild))
3754 || EQ (Vwindow_splits, Qnest))
3755 /* Make a new parent window in the following cases:
3757 - OLD doesn't have a parent window, or
3759 - OLD is in a vertical (horizontal) combination and shall be
3760 split horizontally (vertically), or
3762 - we want to nest the new parent window.
3764 Note that the new parent window is a matrjoshka window; so any
3765 matrjoshka window invariants are temporarily invalid now. */
3767 /* Save the old value of o->normal_cols/lines. It gets corrupted
3768 by make_parent_window and we need it below for assigning it to
3769 p->new_normal. */
3770 Lisp_Object new_normal = horflag ? o->normal_cols : o->normal_lines;
3771 make_parent_window (old, horflag);
3772 p = XWINDOW (o->parent);
3773 if (EQ (Vwindow_splits, Qnest))
3774 /* Make sure that parent is not recombined. */
3775 p->inhibit_recombine = Qt;
3776 /* These get applied below. */
3777 p->new_total = horflag ? o->total_cols : o->total_lines;
3778 p->new_normal = new_normal;
3780 else
3781 p = XWINDOW (o->parent);
3783 windows_or_buffers_changed++;
3784 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
3785 new = make_window ();
3786 n = XWINDOW (new);
3787 n->frame = frame;
3788 n->parent = o->parent;
3789 n->vchild = n->hchild = Qnil;
3791 if (EQ (horizontal, Qabove) || EQ (horizontal, Qleft))
3793 n->prev = o->prev;
3794 if (NILP (n->prev))
3795 if (horflag)
3796 p->hchild = new;
3797 else
3798 p->vchild = new;
3799 else
3800 XWINDOW (n->prev)->next = new;
3801 n->next = old;
3802 o->prev = new;
3804 else
3806 n->next = o->next;
3807 if (!NILP (n->next))
3808 XWINDOW (n->next)->prev = new;
3809 n->prev = old;
3810 o->next = new;
3813 n->buffer = Qt;
3814 n->window_end_valid = Qnil;
3815 memset (&n->last_cursor, 0, sizeof n->last_cursor);
3817 /* Get special geometry settings from reference window. */
3818 n->left_margin_cols = r->left_margin_cols;
3819 n->right_margin_cols = r->right_margin_cols;
3820 n->left_fringe_width = r->left_fringe_width;
3821 n->right_fringe_width = r->right_fringe_width;
3822 n->fringes_outside_margins = r->fringes_outside_margins;
3823 n->scroll_bar_width = r->scroll_bar_width;
3824 n->vertical_scroll_bar_type = r->vertical_scroll_bar_type;
3826 if (horflag)
3828 n->top_line = o->top_line;
3829 n->total_lines = o->total_lines;
3831 else
3833 n->left_col = o->left_col;
3834 n->total_cols = o->total_cols;
3836 n->new_total = size;
3838 BLOCK_INPUT;
3839 resize_window_apply (p, horflag);
3841 if (!do_resize)
3843 /* Assign normal sizes for OLD. */
3844 if (horflag)
3845 o->normal_cols
3846 = make_float (XFLOATINT (o->total_cols) / XFLOATINT (p->total_cols));
3847 else
3848 o->normal_lines
3849 = make_float (XFLOATINT (o->total_lines) / XFLOATINT (p->total_lines));
3852 n->normal_lines
3853 = make_float (XFLOATINT (n->total_lines) / XFLOATINT (p->total_lines));
3854 n->normal_cols
3855 = make_float (XFLOATINT (n->total_cols) / XFLOATINT (p->total_cols));
3857 adjust_glyphs (f);
3858 UNBLOCK_INPUT;
3860 /* Use buffer of reference window. */
3861 set_window_buffer (new, r->buffer, 0, 1);
3862 /* Maybe we should run the scroll functions in Elisp (which already
3863 runs the configuration change hook). */
3864 if (! NILP (Vwindow_scroll_functions))
3865 run_hook_with_args_2 (Qwindow_scroll_functions, new,
3866 Fmarker_position (n->start));
3867 return new;
3871 DEFUN ("delete-window-internal", Fdelete_window_internal, Sdelete_window_internal, 1, 1, 0,
3872 doc: /* Remove WINDOW from its frame.
3873 WINDOW defaults to the selected window. Return nil. Signal an error
3874 when WINDOW is the only window on its frame. */)
3875 (register Lisp_Object window)
3877 register Lisp_Object parent, sibling, frame, root;
3878 struct window *w, *p, *s, *r;
3879 struct frame *f;
3880 int horflag;
3881 int bflag = 0;
3882 int before_sibling = 0;
3884 w = decode_any_window (window);
3885 XSETWINDOW (window, w);
3886 if (NILP (w->buffer) && NILP (w->hchild) && NILP (w->vchild))
3887 /* It's a no-op to delete an already deleted window. */
3888 return Qnil;
3890 parent = w->parent;
3891 if (NILP (parent))
3892 /* Never delete a minibuffer or frame root window. */
3893 error ("Attempt to delete minibuffer or sole ordinary window");
3894 else if (NILP (w->prev) && NILP (w->next))
3895 /* Rather bow out here, this case should be handled on the Elisp
3896 level. */
3897 error ("Attempt to delete sole window of parent");
3899 p = XWINDOW (parent);
3900 horflag = NILP (p->vchild);
3902 frame = WINDOW_FRAME (w);
3903 f = XFRAME (frame);
3905 root = FRAME_ROOT_WINDOW (f);
3906 r = XWINDOW (root);
3908 /* Unlink WINDOW from window tree. */
3909 if (NILP (w->prev))
3910 /* Get SIBLING below (on the right of) WINDOW. */
3912 /* before_sibling 1 means WINDOW is the first child of its
3913 parent and thus before the sibling. */
3914 before_sibling = 1;
3915 sibling = w->next;
3916 s = XWINDOW (sibling);
3917 s->prev = Qnil;
3918 if (horflag)
3919 p->hchild = sibling;
3920 else
3921 p->vchild = sibling;
3923 else
3924 /* Get SIBLING above (on the left of) WINDOW. */
3926 sibling = w->prev;
3927 s = XWINDOW (sibling);
3928 s->next = w->next;
3929 if (!NILP (s->next))
3930 XWINDOW (s->next)->prev = sibling;
3933 if (resize_window_check (r, horflag)
3934 && r->new_total == (horflag ? r->total_cols : r->total_lines))
3935 /* We can delete WINDOW now. */
3937 /* Block input. */
3938 BLOCK_INPUT;
3939 resize_window_apply (p, horflag);
3941 windows_or_buffers_changed++;
3942 Vwindow_list = Qnil;
3943 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
3945 w->next = Qnil; /* Don't delete w->next too. */
3946 free_window_matrices (w);
3948 if (!NILP (w->vchild))
3950 delete_all_subwindows (w->vchild);
3951 w->vchild = Qnil;
3953 else if (!NILP (w->hchild))
3955 delete_all_subwindows (w->hchild);
3956 w->hchild = Qnil;
3958 else if (!NILP (w->buffer))
3960 unshow_buffer (w);
3961 unchain_marker (XMARKER (w->pointm));
3962 unchain_marker (XMARKER (w->start));
3963 w->buffer = Qnil;
3966 if (NILP (s->prev) && NILP (s->next))
3967 /* A matrjoshka where SIBLING has become the only child of
3968 PARENT. */
3970 /* Put SIBLING into PARENT's place. */
3971 replace_window (parent, sibling, 0);
3972 /* Inherit these two. */
3973 s->normal_cols = p->normal_cols;
3974 s->normal_lines = p->normal_lines;
3975 /* Mark PARENT as deleted. */
3976 p->vchild = p->hchild = Qnil;
3977 /* Merge SIBLING's into its new parent unless we want binary
3978 trees. */
3979 if (!EQ (Vwindow_splits, Qnest))
3980 recombine_windows (sibling);
3983 adjust_glyphs (f);
3985 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f)))
3986 /* We deleted the frame's selected window. */
3988 /* Use the frame's first window as fallback ... */
3989 Lisp_Object new_selected_window = Fframe_first_window (frame);
3990 /* ... but preferably use its most recently used window. */
3991 Lisp_Object mru_window;
3993 /* `get-mru-window' might fail for some reason so play it safe
3994 - promote the first window _without recording it_ first. */
3995 if (EQ (FRAME_SELECTED_WINDOW (f), selected_window))
3996 Fselect_window (new_selected_window, Qt);
3997 else
3998 FRAME_SELECTED_WINDOW (f) = new_selected_window;
4000 UNBLOCK_INPUT;
4002 /* Now look whether `get-mru-window' gets us something. */
4003 mru_window = call1 (Qget_mru_window, frame);
4004 if (WINDOW_LIVE_P (mru_window)
4005 && XWINDOW (mru_window)->frame == frame)
4006 new_selected_window = mru_window;
4008 /* If all ended up well, we now promote the mru window. */
4009 if (EQ (FRAME_SELECTED_WINDOW (f), selected_window))
4010 Fselect_window (new_selected_window, Qnil);
4011 else
4012 FRAME_SELECTED_WINDOW (f) = new_selected_window;
4014 else
4015 UNBLOCK_INPUT;
4017 /* Must be run by the caller:
4018 run_window_configuration_change_hook (f); */
4020 else
4021 /* We failed: Relink WINDOW into window tree. */
4023 if (before_sibling)
4025 s->prev = window;
4026 if (horflag)
4027 p->hchild = window;
4028 else
4029 p->vchild = window;
4031 else
4033 s->next = window;
4034 if (!NILP (w->next))
4035 XWINDOW (w->next)->prev = window;
4037 error ("Deletion failed");
4040 return Qnil;
4043 /***********************************************************************
4044 Resizing Mini-Windows
4045 ***********************************************************************/
4047 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we
4048 can. */
4049 void
4050 grow_mini_window (struct window *w, int delta)
4052 struct frame *f = XFRAME (w->frame);
4053 struct window *r;
4054 Lisp_Object root, value;
4056 xassert (MINI_WINDOW_P (w));
4057 xassert (delta >= 0);
4059 root = FRAME_ROOT_WINDOW (f);
4060 r = XWINDOW (root);
4061 value = call2 (Qresize_root_window_vertically, root, make_number (- delta));
4062 if (INTEGERP (value) && resize_window_check (r, 0))
4064 BLOCK_INPUT;
4065 resize_window_apply (r, 0);
4067 /* Grow the mini-window. */
4068 XSETFASTINT (w->top_line, XFASTINT (r->top_line) + XFASTINT (r->total_lines));
4069 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - XINT (value));
4070 XSETFASTINT (w->last_modified, 0);
4071 XSETFASTINT (w->last_overlay_modified, 0);
4073 adjust_glyphs (f);
4074 UNBLOCK_INPUT;
4079 /* Shrink mini-window W. */
4080 void
4081 shrink_mini_window (struct window *w)
4083 struct frame *f = XFRAME (w->frame);
4084 struct window *r;
4085 Lisp_Object root, value, size;
4087 xassert (MINI_WINDOW_P (w));
4089 size = XINT (w->total_lines);
4090 if (size > 1)
4092 root = FRAME_ROOT_WINDOW (f);
4093 r = XWINDOW (root);
4094 value = call2 (Qresize_root_window_vertically,
4095 root, make_number (size - 1));
4096 if (INTEGERP (value) && resize_window_check (r, 0))
4098 BLOCK_INPUT;
4099 resize_window_apply (r, 0);
4101 /* Shrink the mini-window. */
4102 XSETFASTINT (w->top_line, XFASTINT (r->top_line) + XFASTINT (r->total_lines));
4103 XSETFASTINT (w->total_lines, 1);
4105 XSETFASTINT (w->last_modified, 0);
4106 XSETFASTINT (w->last_overlay_modified, 0);
4108 adjust_glyphs (f);
4109 UNBLOCK_INPUT;
4111 /* If the above failed for whatever strange reason we must make a
4112 one window frame here. The same routine will be needed when
4113 shrinking the frame (and probably when making the initial
4114 *scratch* window). For the moment leave things as they are. */
4118 DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini_window_internal, 1, 1, 0,
4119 doc: /* Resize minibuffer window WINDOW. */)
4120 (Lisp_Object window)
4122 struct window *w = XWINDOW (window);
4123 struct window *r;
4124 struct frame *f;
4125 int height;
4127 CHECK_WINDOW (window);
4128 f = XFRAME (w->frame);
4130 if (!EQ (FRAME_MINIBUF_WINDOW (XFRAME (w->frame)), window))
4131 error ("Not a valid minibuffer window");
4132 else if (FRAME_MINIBUF_ONLY_P (f))
4133 error ("Cannot resize a minibuffer-only frame");
4135 r = XWINDOW (FRAME_ROOT_WINDOW (f));
4136 height = XINT (r->total_lines) + XINT (w->total_lines);
4137 if (resize_window_check (r, 0)
4138 && XINT (w->new_total) > 0
4139 && height == XINT (r->new_total) + XINT (w->new_total))
4141 BLOCK_INPUT;
4142 resize_window_apply (r, 0);
4144 w->total_lines = w->new_total;
4145 XSETFASTINT (w->top_line, XINT (r->top_line) + XINT (r->total_lines));
4147 windows_or_buffers_changed++;
4148 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
4149 adjust_glyphs (f);
4150 UNBLOCK_INPUT;
4152 run_window_configuration_change_hook (f);
4153 return Qt;
4155 else error ("Failed to resize minibuffer window");
4158 /* Mark window cursors off for all windows in the window tree rooted
4159 at W by setting their phys_cursor_on_p flag to zero. Called from
4160 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4161 the frame are cleared. */
4163 void
4164 mark_window_cursors_off (struct window *w)
4166 while (w)
4168 if (!NILP (w->hchild))
4169 mark_window_cursors_off (XWINDOW (w->hchild));
4170 else if (!NILP (w->vchild))
4171 mark_window_cursors_off (XWINDOW (w->vchild));
4172 else
4173 w->phys_cursor_on_p = 0;
4175 w = NILP (w->next) ? 0 : XWINDOW (w->next);
4180 /* Return number of lines of text (not counting mode lines) in W. */
4183 window_internal_height (struct window *w)
4185 int ht = XFASTINT (w->total_lines);
4187 if (!MINI_WINDOW_P (w))
4189 if (!NILP (w->parent)
4190 || !NILP (w->vchild)
4191 || !NILP (w->hchild)
4192 || !NILP (w->next)
4193 || !NILP (w->prev)
4194 || WINDOW_WANTS_MODELINE_P (w))
4195 --ht;
4197 if (WINDOW_WANTS_HEADER_LINE_P (w))
4198 --ht;
4201 return ht;
4204 /************************************************************************
4205 Window Scrolling
4206 ***********************************************************************/
4208 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4209 N screen-fulls, which is defined as the height of the window minus
4210 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4211 instead. Negative values of N mean scroll down. NOERROR non-zero
4212 means don't signal an error if we try to move over BEGV or ZV,
4213 respectively. */
4215 static void
4216 window_scroll (Lisp_Object window, int n, int whole, int noerror)
4218 immediate_quit = 1;
4220 /* If we must, use the pixel-based version which is much slower than
4221 the line-based one but can handle varying line heights. */
4222 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window)->frame)))
4223 window_scroll_pixel_based (window, n, whole, noerror);
4224 else
4225 window_scroll_line_based (window, n, whole, noerror);
4227 immediate_quit = 0;
4231 /* Implementation of window_scroll that works based on pixel line
4232 heights. See the comment of window_scroll for parameter
4233 descriptions. */
4235 static void
4236 window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4238 struct it it;
4239 struct window *w = XWINDOW (window);
4240 struct text_pos start;
4241 int this_scroll_margin;
4242 /* True if we fiddled the window vscroll field without really scrolling. */
4243 int vscrolled = 0;
4244 int x, y, rtop, rbot, rowh, vpos;
4246 SET_TEXT_POS_FROM_MARKER (start, w->start);
4248 /* If PT is not visible in WINDOW, move back one half of
4249 the screen. Allow PT to be partially visible, otherwise
4250 something like (scroll-down 1) with PT in the line before
4251 the partially visible one would recenter. */
4253 if (!pos_visible_p (w, PT, &x, &y, &rtop, &rbot, &rowh, &vpos))
4255 /* Move backward half the height of the window. Performance note:
4256 vmotion used here is about 10% faster, but would give wrong
4257 results for variable height lines. */
4258 init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID);
4259 it.current_y = it.last_visible_y;
4260 move_it_vertically_backward (&it, window_box_height (w) / 2);
4262 /* The function move_iterator_vertically may move over more than
4263 the specified y-distance. If it->w is small, e.g. a
4264 mini-buffer window, we may end up in front of the window's
4265 display area. This is the case when Start displaying at the
4266 start of the line containing PT in this case. */
4267 if (it.current_y <= 0)
4269 init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID);
4270 move_it_vertically_backward (&it, 0);
4271 it.current_y = 0;
4274 start = it.current.pos;
4276 else if (auto_window_vscroll_p)
4278 if (rtop || rbot) /* partially visible */
4280 int px;
4281 int dy = WINDOW_FRAME_LINE_HEIGHT (w);
4282 if (whole)
4283 dy = max ((window_box_height (w)
4284 - next_screen_context_lines * dy),
4285 dy);
4286 dy *= n;
4288 if (n < 0)
4290 /* Only vscroll backwards if already vscrolled forwards. */
4291 if (w->vscroll < 0 && rtop > 0)
4293 px = max (0, -w->vscroll - min (rtop, -dy));
4294 Fset_window_vscroll (window, make_number (px), Qt);
4295 return;
4298 if (n > 0)
4300 /* Do vscroll if already vscrolled or only display line. */
4301 if (rbot > 0 && (w->vscroll < 0 || vpos == 0))
4303 px = max (0, -w->vscroll + min (rbot, dy));
4304 Fset_window_vscroll (window, make_number (px), Qt);
4305 return;
4308 /* Maybe modify window start instead of scrolling. */
4309 if (rbot > 0 || w->vscroll < 0)
4311 int spos;
4313 Fset_window_vscroll (window, make_number (0), Qt);
4314 /* If there are other text lines above the current row,
4315 move window start to current row. Else to next row. */
4316 if (rbot > 0)
4317 spos = XINT (Fline_beginning_position (Qnil));
4318 else
4319 spos = min (XINT (Fline_end_position (Qnil)) + 1, ZV);
4320 set_marker_restricted (w->start, make_number (spos),
4321 w->buffer);
4322 w->start_at_line_beg = Qt;
4323 w->update_mode_line = Qt;
4324 XSETFASTINT (w->last_modified, 0);
4325 XSETFASTINT (w->last_overlay_modified, 0);
4326 /* Set force_start so that redisplay_window will run the
4327 window-scroll-functions. */
4328 w->force_start = Qt;
4329 return;
4333 /* Cancel previous vscroll. */
4334 Fset_window_vscroll (window, make_number (0), Qt);
4337 /* If scroll_preserve_screen_position is non-nil, we try to set
4338 point in the same window line as it is now, so get that line. */
4339 if (!NILP (Vscroll_preserve_screen_position))
4341 /* We preserve the goal pixel coordinate across consecutive
4342 calls to scroll-up, scroll-down and other commands that
4343 have the `scroll-command' property. This avoids the
4344 possibility of point becoming "stuck" on a tall line when
4345 scrolling by one line. */
4346 if (window_scroll_pixel_based_preserve_y < 0
4347 || !SYMBOLP (current_kboard->Vlast_command)
4348 || NILP (Fget (current_kboard->Vlast_command, Qscroll_command)))
4350 start_display (&it, w, start);
4351 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
4352 window_scroll_pixel_based_preserve_y = it.current_y;
4353 window_scroll_pixel_based_preserve_x = it.current_x;
4356 else
4357 window_scroll_pixel_based_preserve_y
4358 = window_scroll_pixel_based_preserve_x = -1;
4360 /* Move iterator it from start the specified distance forward or
4361 backward. The result is the new window start. */
4362 start_display (&it, w, start);
4363 if (whole)
4365 int start_pos = IT_CHARPOS (it);
4366 int dy = WINDOW_FRAME_LINE_HEIGHT (w);
4367 dy = max ((window_box_height (w)
4368 - next_screen_context_lines * dy),
4369 dy) * n;
4371 /* Note that move_it_vertically always moves the iterator to the
4372 start of a line. So, if the last line doesn't have a newline,
4373 we would end up at the start of the line ending at ZV. */
4374 if (dy <= 0)
4376 move_it_vertically_backward (&it, -dy);
4377 /* Ensure we actually do move, e.g. in case we are currently
4378 looking at an image that is taller that the window height. */
4379 while (start_pos == IT_CHARPOS (it)
4380 && start_pos > BEGV)
4381 move_it_by_lines (&it, -1, 1);
4383 else if (dy > 0)
4385 move_it_to (&it, ZV, -1, it.current_y + dy, -1,
4386 MOVE_TO_POS | MOVE_TO_Y);
4387 /* Ensure we actually do move, e.g. in case we are currently
4388 looking at an image that is taller that the window height. */
4389 while (start_pos == IT_CHARPOS (it)
4390 && start_pos < ZV)
4391 move_it_by_lines (&it, 1, 1);
4394 else
4395 move_it_by_lines (&it, n, 1);
4397 /* We failed if we find ZV is already on the screen (scrolling up,
4398 means there's nothing past the end), or if we can't start any
4399 earlier (scrolling down, means there's nothing past the top). */
4400 if ((n > 0 && IT_CHARPOS (it) == ZV)
4401 || (n < 0 && IT_CHARPOS (it) == CHARPOS (start)))
4403 if (IT_CHARPOS (it) == ZV)
4405 if (it.current_y < it.last_visible_y
4406 && (it.current_y + it.max_ascent + it.max_descent
4407 > it.last_visible_y))
4409 /* The last line was only partially visible, make it fully
4410 visible. */
4411 w->vscroll = (it.last_visible_y
4412 - it.current_y + it.max_ascent + it.max_descent);
4413 adjust_glyphs (it.f);
4415 else if (noerror)
4416 return;
4417 else if (n < 0) /* could happen with empty buffers */
4418 xsignal0 (Qbeginning_of_buffer);
4419 else
4420 xsignal0 (Qend_of_buffer);
4422 else
4424 if (w->vscroll != 0)
4425 /* The first line was only partially visible, make it fully
4426 visible. */
4427 w->vscroll = 0;
4428 else if (noerror)
4429 return;
4430 else
4431 xsignal0 (Qbeginning_of_buffer);
4434 /* If control gets here, then we vscrolled. */
4436 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
4438 /* Don't try to change the window start below. */
4439 vscrolled = 1;
4442 if (! vscrolled)
4444 int pos = IT_CHARPOS (it);
4445 int bytepos;
4447 /* If in the middle of a multi-glyph character move forward to
4448 the next character. */
4449 if (in_display_vector_p (&it))
4451 ++pos;
4452 move_it_to (&it, pos, -1, -1, -1, MOVE_TO_POS);
4455 /* Set the window start, and set up the window for redisplay. */
4456 set_marker_restricted (w->start, make_number (pos),
4457 w->buffer);
4458 bytepos = XMARKER (w->start)->bytepos;
4459 w->start_at_line_beg = ((pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n')
4460 ? Qt : Qnil);
4461 w->update_mode_line = Qt;
4462 XSETFASTINT (w->last_modified, 0);
4463 XSETFASTINT (w->last_overlay_modified, 0);
4464 /* Set force_start so that redisplay_window will run the
4465 window-scroll-functions. */
4466 w->force_start = Qt;
4469 /* The rest of this function uses current_y in a nonstandard way,
4470 not including the height of the header line if any. */
4471 it.current_y = it.vpos = 0;
4473 /* Move PT out of scroll margins.
4474 This code wants current_y to be zero at the window start position
4475 even if there is a header line. */
4476 this_scroll_margin = max (0, scroll_margin);
4477 this_scroll_margin = min (this_scroll_margin, XFASTINT (w->total_lines) / 4);
4478 this_scroll_margin *= FRAME_LINE_HEIGHT (it.f);
4480 if (n > 0)
4482 /* We moved the window start towards ZV, so PT may be now
4483 in the scroll margin at the top. */
4484 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
4485 if (IT_CHARPOS (it) == PT && it.current_y >= this_scroll_margin
4486 && (NILP (Vscroll_preserve_screen_position)
4487 || EQ (Vscroll_preserve_screen_position, Qt)))
4488 /* We found PT at a legitimate height. Leave it alone. */
4490 else if (window_scroll_pixel_based_preserve_y >= 0)
4492 /* If we have a header line, take account of it.
4493 This is necessary because we set it.current_y to 0, above. */
4494 move_it_to (&it, -1,
4495 window_scroll_pixel_based_preserve_x,
4496 window_scroll_pixel_based_preserve_y
4497 - (WINDOW_WANTS_HEADER_LINE_P (w) ? 1 : 0 ),
4498 -1, MOVE_TO_Y | MOVE_TO_X);
4499 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4501 else
4503 while (it.current_y < this_scroll_margin)
4505 int prev = it.current_y;
4506 move_it_by_lines (&it, 1, 1);
4507 if (prev == it.current_y)
4508 break;
4510 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4513 else if (n < 0)
4515 int charpos, bytepos;
4516 int partial_p;
4518 /* Save our position, for the
4519 window_scroll_pixel_based_preserve_y case. */
4520 charpos = IT_CHARPOS (it);
4521 bytepos = IT_BYTEPOS (it);
4523 /* We moved the window start towards BEGV, so PT may be now
4524 in the scroll margin at the bottom. */
4525 move_it_to (&it, PT, -1,
4526 (it.last_visible_y - CURRENT_HEADER_LINE_HEIGHT (w)
4527 - this_scroll_margin - 1),
4529 MOVE_TO_POS | MOVE_TO_Y);
4531 /* Save our position, in case it's correct. */
4532 charpos = IT_CHARPOS (it);
4533 bytepos = IT_BYTEPOS (it);
4535 /* See if point is on a partially visible line at the end. */
4536 if (it.what == IT_EOB)
4537 partial_p = it.current_y + it.ascent + it.descent > it.last_visible_y;
4538 else
4540 move_it_by_lines (&it, 1, 1);
4541 partial_p = it.current_y > it.last_visible_y;
4544 if (charpos == PT && !partial_p
4545 && (NILP (Vscroll_preserve_screen_position)
4546 || EQ (Vscroll_preserve_screen_position, Qt)))
4547 /* We found PT before we found the display margin, so PT is ok. */
4549 else if (window_scroll_pixel_based_preserve_y >= 0)
4551 SET_TEXT_POS_FROM_MARKER (start, w->start);
4552 start_display (&it, w, start);
4553 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
4554 here because we called start_display again and did not
4555 alter it.current_y this time. */
4556 move_it_to (&it, -1, window_scroll_pixel_based_preserve_x,
4557 window_scroll_pixel_based_preserve_y, -1,
4558 MOVE_TO_Y | MOVE_TO_X);
4559 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4561 else
4563 if (partial_p)
4564 /* The last line was only partially visible, so back up two
4565 lines to make sure we're on a fully visible line. */
4567 move_it_by_lines (&it, -2, 0);
4568 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4570 else
4571 /* No, the position we saved is OK, so use it. */
4572 SET_PT_BOTH (charpos, bytepos);
4578 /* Implementation of window_scroll that works based on screen lines.
4579 See the comment of window_scroll for parameter descriptions. */
4581 static void
4582 window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4584 register struct window *w = XWINDOW (window);
4585 register int opoint = PT, opoint_byte = PT_BYTE;
4586 register int pos, pos_byte;
4587 register int ht = window_internal_height (w);
4588 register Lisp_Object tem;
4589 int lose;
4590 Lisp_Object bolp;
4591 int startpos;
4592 Lisp_Object original_pos = Qnil;
4594 /* If scrolling screen-fulls, compute the number of lines to
4595 scroll from the window's height. */
4596 if (whole)
4597 n *= max (1, ht - next_screen_context_lines);
4599 startpos = marker_position (w->start);
4601 if (!NILP (Vscroll_preserve_screen_position))
4603 if (window_scroll_preserve_vpos <= 0
4604 || !SYMBOLP (current_kboard->Vlast_command)
4605 || NILP (Fget (current_kboard->Vlast_command, Qscroll_command)))
4607 struct position posit
4608 = *compute_motion (startpos, 0, 0, 0,
4609 PT, ht, 0,
4610 -1, XINT (w->hscroll),
4611 0, w);
4612 window_scroll_preserve_vpos = posit.vpos;
4613 window_scroll_preserve_hpos = posit.hpos + XINT (w->hscroll);
4616 original_pos = Fcons (make_number (window_scroll_preserve_hpos),
4617 make_number (window_scroll_preserve_vpos));
4620 XSETFASTINT (tem, PT);
4621 tem = Fpos_visible_in_window_p (tem, window, Qnil);
4623 if (NILP (tem))
4625 Fvertical_motion (make_number (- (ht / 2)), window);
4626 startpos = PT;
4629 SET_PT (startpos);
4630 lose = n < 0 && PT == BEGV;
4631 Fvertical_motion (make_number (n), window);
4632 pos = PT;
4633 pos_byte = PT_BYTE;
4634 bolp = Fbolp ();
4635 SET_PT_BOTH (opoint, opoint_byte);
4637 if (lose)
4639 if (noerror)
4640 return;
4641 else
4642 xsignal0 (Qbeginning_of_buffer);
4645 if (pos < ZV)
4647 int this_scroll_margin = scroll_margin;
4649 /* Don't use a scroll margin that is negative or too large. */
4650 if (this_scroll_margin < 0)
4651 this_scroll_margin = 0;
4653 if (XINT (w->total_lines) < 4 * scroll_margin)
4654 this_scroll_margin = XINT (w->total_lines) / 4;
4656 set_marker_restricted_both (w->start, w->buffer, pos, pos_byte);
4657 w->start_at_line_beg = bolp;
4658 w->update_mode_line = Qt;
4659 XSETFASTINT (w->last_modified, 0);
4660 XSETFASTINT (w->last_overlay_modified, 0);
4661 /* Set force_start so that redisplay_window will run
4662 the window-scroll-functions. */
4663 w->force_start = Qt;
4665 if (!NILP (Vscroll_preserve_screen_position)
4666 && (whole || !EQ (Vscroll_preserve_screen_position, Qt)))
4668 SET_PT_BOTH (pos, pos_byte);
4669 Fvertical_motion (original_pos, window);
4671 /* If we scrolled forward, put point enough lines down
4672 that it is outside the scroll margin. */
4673 else if (n > 0)
4675 int top_margin;
4677 if (this_scroll_margin > 0)
4679 SET_PT_BOTH (pos, pos_byte);
4680 Fvertical_motion (make_number (this_scroll_margin), window);
4681 top_margin = PT;
4683 else
4684 top_margin = pos;
4686 if (top_margin <= opoint)
4687 SET_PT_BOTH (opoint, opoint_byte);
4688 else if (!NILP (Vscroll_preserve_screen_position))
4690 SET_PT_BOTH (pos, pos_byte);
4691 Fvertical_motion (original_pos, window);
4693 else
4694 SET_PT (top_margin);
4696 else if (n < 0)
4698 int bottom_margin;
4700 /* If we scrolled backward, put point near the end of the window
4701 but not within the scroll margin. */
4702 SET_PT_BOTH (pos, pos_byte);
4703 tem = Fvertical_motion (make_number (ht - this_scroll_margin), window);
4704 if (XFASTINT (tem) == ht - this_scroll_margin)
4705 bottom_margin = PT;
4706 else
4707 bottom_margin = PT + 1;
4709 if (bottom_margin > opoint)
4710 SET_PT_BOTH (opoint, opoint_byte);
4711 else
4713 if (!NILP (Vscroll_preserve_screen_position))
4715 SET_PT_BOTH (pos, pos_byte);
4716 Fvertical_motion (original_pos, window);
4718 else
4719 Fvertical_motion (make_number (-1), window);
4723 else
4725 if (noerror)
4726 return;
4727 else
4728 xsignal0 (Qend_of_buffer);
4733 /* Scroll selected_window up or down. If N is nil, scroll a
4734 screen-full which is defined as the height of the window minus
4735 next_screen_context_lines. If N is the symbol `-', scroll.
4736 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4737 up. This is the guts of Fscroll_up and Fscroll_down. */
4739 static void
4740 scroll_command (Lisp_Object n, int direction)
4742 int count = SPECPDL_INDEX ();
4744 xassert (eabs (direction) == 1);
4746 /* If selected window's buffer isn't current, make it current for
4747 the moment. But don't screw up if window_scroll gets an error. */
4748 if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
4750 record_unwind_protect (save_excursion_restore, save_excursion_save ());
4751 Fset_buffer (XWINDOW (selected_window)->buffer);
4753 /* Make redisplay consider other windows than just selected_window. */
4754 ++windows_or_buffers_changed;
4757 if (NILP (n))
4758 window_scroll (selected_window, direction, 1, 0);
4759 else if (EQ (n, Qminus))
4760 window_scroll (selected_window, -direction, 1, 0);
4761 else
4763 n = Fprefix_numeric_value (n);
4764 window_scroll (selected_window, XINT (n) * direction, 0, 0);
4767 unbind_to (count, Qnil);
4770 DEFUN ("scroll-up", Fscroll_up, Sscroll_up, 0, 1, "^P",
4771 doc: /* Scroll text of selected window upward ARG lines.
4772 If ARG is omitted or nil, scroll upward by a near full screen.
4773 A near full screen is `next-screen-context-lines' less than a full screen.
4774 Negative ARG means scroll downward.
4775 If ARG is the atom `-', scroll downward by nearly full screen.
4776 When calling from a program, supply as argument a number, nil, or `-'. */)
4777 (Lisp_Object arg)
4779 scroll_command (arg, 1);
4780 return Qnil;
4783 DEFUN ("scroll-down", Fscroll_down, Sscroll_down, 0, 1, "^P",
4784 doc: /* Scroll text of selected window down ARG lines.
4785 If ARG is omitted or nil, scroll down by a near full screen.
4786 A near full screen is `next-screen-context-lines' less than a full screen.
4787 Negative ARG means scroll upward.
4788 If ARG is the atom `-', scroll upward by nearly full screen.
4789 When calling from a program, supply as argument a number, nil, or `-'. */)
4790 (Lisp_Object arg)
4792 scroll_command (arg, -1);
4793 return Qnil;
4796 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling, Sother_window_for_scrolling, 0, 0, 0,
4797 doc: /* Return the other window for \"other window scroll\" commands.
4798 If `other-window-scroll-buffer' is non-nil, a window
4799 showing that buffer is used.
4800 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4801 specifies the window. This takes precedence over
4802 `other-window-scroll-buffer'. */)
4803 (void)
4805 Lisp_Object window;
4807 if (MINI_WINDOW_P (XWINDOW (selected_window))
4808 && !NILP (Vminibuf_scroll_window))
4809 window = Vminibuf_scroll_window;
4810 /* If buffer is specified, scroll that buffer. */
4811 else if (!NILP (Vother_window_scroll_buffer))
4813 window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil);
4814 if (NILP (window))
4815 window = display_buffer (Vother_window_scroll_buffer, Qt, Qnil);
4817 else
4819 /* Nothing specified; look for a neighboring window on the same
4820 frame. */
4821 window = Fnext_window (selected_window, Qnil, Qnil);
4823 if (EQ (window, selected_window))
4824 /* That didn't get us anywhere; look for a window on another
4825 visible frame. */
4827 window = Fnext_window (window, Qnil, Qt);
4828 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window))))
4829 && ! EQ (window, selected_window));
4832 CHECK_LIVE_WINDOW (window);
4834 if (EQ (window, selected_window))
4835 error ("There is no other window");
4837 return window;
4840 DEFUN ("scroll-other-window", Fscroll_other_window, Sscroll_other_window, 0, 1, "P",
4841 doc: /* Scroll next window upward ARG lines; or near full screen if no ARG.
4842 A near full screen is `next-screen-context-lines' less than a full screen.
4843 The next window is the one below the current one; or the one at the top
4844 if the current one is at the bottom. Negative ARG means scroll downward.
4845 If ARG is the atom `-', scroll downward by nearly full screen.
4846 When calling from a program, supply as argument a number, nil, or `-'.
4848 If `other-window-scroll-buffer' is non-nil, scroll the window
4849 showing that buffer, popping the buffer up if necessary.
4850 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4851 specifies the window to scroll. This takes precedence over
4852 `other-window-scroll-buffer'. */)
4853 (Lisp_Object arg)
4855 Lisp_Object window;
4856 struct window *w;
4857 int count = SPECPDL_INDEX ();
4859 window = Fother_window_for_scrolling ();
4860 w = XWINDOW (window);
4862 /* Don't screw up if window_scroll gets an error. */
4863 record_unwind_protect (save_excursion_restore, save_excursion_save ());
4864 ++windows_or_buffers_changed;
4866 Fset_buffer (w->buffer);
4867 SET_PT (marker_position (w->pointm));
4869 if (NILP (arg))
4870 window_scroll (window, 1, 1, 1);
4871 else if (EQ (arg, Qminus))
4872 window_scroll (window, -1, 1, 1);
4873 else
4875 if (CONSP (arg))
4876 arg = Fcar (arg);
4877 CHECK_NUMBER (arg);
4878 window_scroll (window, XINT (arg), 0, 1);
4881 set_marker_both (w->pointm, Qnil, PT, PT_BYTE);
4882 unbind_to (count, Qnil);
4884 return Qnil;
4887 DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 2, "^P\np",
4888 doc: /* Scroll selected window display ARG columns left.
4889 Default for ARG is window width minus 2.
4890 Value is the total amount of leftward horizontal scrolling in
4891 effect after the change.
4892 If SET-MINIMUM is non-nil, the new scroll amount becomes the
4893 lower bound for automatic scrolling, i.e. automatic scrolling
4894 will not scroll a window to a column less than the value returned
4895 by this function. This happens in an interactive call. */)
4896 (register Lisp_Object arg, Lisp_Object set_minimum)
4898 Lisp_Object result;
4899 int hscroll;
4900 struct window *w = XWINDOW (selected_window);
4902 if (NILP (arg))
4903 XSETFASTINT (arg, window_body_cols (w) - 2);
4904 else
4905 arg = Fprefix_numeric_value (arg);
4907 hscroll = XINT (w->hscroll) + XINT (arg);
4908 result = Fset_window_hscroll (selected_window, make_number (hscroll));
4910 if (!NILP (set_minimum))
4911 w->min_hscroll = w->hscroll;
4913 return result;
4916 DEFUN ("scroll-right", Fscroll_right, Sscroll_right, 0, 2, "^P\np",
4917 doc: /* Scroll selected window display ARG columns right.
4918 Default for ARG is window width minus 2.
4919 Value is the total amount of leftward horizontal scrolling in
4920 effect after the change.
4921 If SET-MINIMUM is non-nil, the new scroll amount becomes the
4922 lower bound for automatic scrolling, i.e. automatic scrolling
4923 will not scroll a window to a column less than the value returned
4924 by this function. This happens in an interactive call. */)
4925 (register Lisp_Object arg, Lisp_Object set_minimum)
4927 Lisp_Object result;
4928 int hscroll;
4929 struct window *w = XWINDOW (selected_window);
4931 if (NILP (arg))
4932 XSETFASTINT (arg, window_body_cols (w) - 2);
4933 else
4934 arg = Fprefix_numeric_value (arg);
4936 hscroll = XINT (w->hscroll) - XINT (arg);
4937 result = Fset_window_hscroll (selected_window, make_number (hscroll));
4939 if (!NILP (set_minimum))
4940 w->min_hscroll = w->hscroll;
4942 return result;
4945 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window, Sminibuffer_selected_window, 0, 0, 0,
4946 doc: /* Return the window which was selected when entering the minibuffer.
4947 Returns nil, if selected window is not a minibuffer window. */)
4948 (void)
4950 if (minibuf_level > 0
4951 && MINI_WINDOW_P (XWINDOW (selected_window))
4952 && WINDOW_LIVE_P (minibuf_selected_window))
4953 return minibuf_selected_window;
4955 return Qnil;
4958 /* Value is the number of lines actually displayed in window W,
4959 as opposed to its height. */
4961 static int
4962 displayed_window_lines (struct window *w)
4964 struct it it;
4965 struct text_pos start;
4966 int height = window_box_height (w);
4967 struct buffer *old_buffer;
4968 int bottom_y;
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 start_display (&it, w, start);
4989 move_it_vertically (&it, height);
4990 bottom_y = line_bottom_y (&it);
4992 /* rms: On a non-window display,
4993 the value of it.vpos at the bottom of the screen
4994 seems to be 1 larger than window_box_height (w).
4995 This kludge fixes a bug whereby (move-to-window-line -1)
4996 when ZV is on the last screen line
4997 moves to the previous screen line instead of the last one. */
4998 if (! FRAME_WINDOW_P (XFRAME (w->frame)))
4999 height++;
5001 /* Add in empty lines at the bottom of the window. */
5002 if (bottom_y < height)
5004 int uy = FRAME_LINE_HEIGHT (it.f);
5005 it.vpos += (height - bottom_y + uy - 1) / uy;
5008 if (old_buffer)
5009 set_buffer_internal (old_buffer);
5011 return it.vpos;
5015 DEFUN ("recenter", Frecenter, Srecenter, 0, 1, "P",
5016 doc: /* Center point in selected window and maybe redisplay frame.
5017 With prefix argument ARG, recenter putting point on screen line ARG
5018 relative to the selected window. If ARG is negative, it counts up from the
5019 bottom of the window. (ARG should be less than the height of the window.)
5021 If ARG is omitted or nil, then recenter with point on the middle line of
5022 the selected window; if the variable `recenter-redisplay' is non-nil,
5023 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5024 is set to `grow-only', this resets the tool-bar's height to the minimum
5025 height needed); if `recenter-redisplay' has the special value `tty',
5026 then only tty frame are redrawn.
5028 Just C-u as prefix means put point in the center of the window
5029 and redisplay normally--don't erase and redraw the frame. */)
5030 (register Lisp_Object arg)
5032 struct window *w = XWINDOW (selected_window);
5033 struct buffer *buf = XBUFFER (w->buffer);
5034 struct buffer *obuf = current_buffer;
5035 int center_p = 0;
5036 int charpos, bytepos;
5037 int iarg;
5038 int this_scroll_margin;
5040 /* If redisplay is suppressed due to an error, try again. */
5041 obuf->display_error_modiff = 0;
5043 if (NILP (arg))
5045 if (!NILP (Vrecenter_redisplay)
5046 && (!EQ (Vrecenter_redisplay, Qtty)
5047 || !NILP (Ftty_type (selected_frame))))
5049 int i;
5051 /* Invalidate pixel data calculated for all compositions. */
5052 for (i = 0; i < n_compositions; i++)
5053 composition_table[i]->font = NULL;
5055 WINDOW_XFRAME (w)->minimize_tool_bar_window_p = 1;
5057 Fredraw_frame (WINDOW_FRAME (w));
5058 SET_FRAME_GARBAGED (WINDOW_XFRAME (w));
5061 center_p = 1;
5063 else if (CONSP (arg)) /* Just C-u. */
5064 center_p = 1;
5065 else
5067 arg = Fprefix_numeric_value (arg);
5068 CHECK_NUMBER (arg);
5069 iarg = XINT (arg);
5072 set_buffer_internal (buf);
5074 /* Do this after making BUF current
5075 in case scroll_margin is buffer-local. */
5076 this_scroll_margin = max (0, scroll_margin);
5077 this_scroll_margin = min (this_scroll_margin,
5078 XFASTINT (w->total_lines) / 4);
5080 /* Handle centering on a graphical frame specially. Such frames can
5081 have variable-height lines and centering point on the basis of
5082 line counts would lead to strange effects. */
5083 if (FRAME_WINDOW_P (XFRAME (w->frame)))
5085 if (center_p)
5087 struct it it;
5088 struct text_pos pt;
5090 SET_TEXT_POS (pt, PT, PT_BYTE);
5091 start_display (&it, w, pt);
5092 move_it_vertically_backward (&it, window_box_height (w) / 2);
5093 charpos = IT_CHARPOS (it);
5094 bytepos = IT_BYTEPOS (it);
5096 else if (iarg < 0)
5098 struct it it;
5099 struct text_pos pt;
5100 int nlines = -iarg;
5101 int extra_line_spacing;
5102 int h = window_box_height (w);
5104 iarg = - max (-iarg, this_scroll_margin);
5106 SET_TEXT_POS (pt, PT, PT_BYTE);
5107 start_display (&it, w, pt);
5109 /* Be sure we have the exact height of the full line containing PT. */
5110 move_it_by_lines (&it, 0, 1);
5112 /* The amount of pixels we have to move back is the window
5113 height minus what's displayed in the line containing PT,
5114 and the lines below. */
5115 it.current_y = 0;
5116 it.vpos = 0;
5117 move_it_by_lines (&it, nlines, 1);
5119 if (it.vpos == nlines)
5120 h -= it.current_y;
5121 else
5123 /* Last line has no newline */
5124 h -= line_bottom_y (&it);
5125 it.vpos++;
5128 /* Don't reserve space for extra line spacing of last line. */
5129 extra_line_spacing = it.max_extra_line_spacing;
5131 /* If we can't move down NLINES lines because we hit
5132 the end of the buffer, count in some empty lines. */
5133 if (it.vpos < nlines)
5135 nlines -= it.vpos;
5136 extra_line_spacing = it.extra_line_spacing;
5137 h -= nlines * (FRAME_LINE_HEIGHT (it.f) + extra_line_spacing);
5139 if (h <= 0)
5140 return Qnil;
5142 /* Now find the new top line (starting position) of the window. */
5143 start_display (&it, w, pt);
5144 it.current_y = 0;
5145 move_it_vertically_backward (&it, h);
5147 /* If extra line spacing is present, we may move too far
5148 back. This causes the last line to be only partially
5149 visible (which triggers redisplay to recenter that line
5150 in the middle), so move forward.
5151 But ignore extra line spacing on last line, as it is not
5152 considered to be part of the visible height of the line.
5154 h += extra_line_spacing;
5155 while (-it.current_y > h)
5156 move_it_by_lines (&it, 1, 1);
5158 charpos = IT_CHARPOS (it);
5159 bytepos = IT_BYTEPOS (it);
5161 else
5163 struct position pos;
5165 iarg = max (iarg, this_scroll_margin);
5167 pos = *vmotion (PT, -iarg, w);
5168 charpos = pos.bufpos;
5169 bytepos = pos.bytepos;
5172 else
5174 struct position pos;
5175 int ht = window_internal_height (w);
5177 if (center_p)
5178 iarg = ht / 2;
5179 else if (iarg < 0)
5180 iarg += ht;
5182 /* Don't let it get into the margin at either top or bottom. */
5183 iarg = max (iarg, this_scroll_margin);
5184 iarg = min (iarg, ht - this_scroll_margin - 1);
5186 pos = *vmotion (PT, - iarg, w);
5187 charpos = pos.bufpos;
5188 bytepos = pos.bytepos;
5191 /* Set the new window start. */
5192 set_marker_both (w->start, w->buffer, charpos, bytepos);
5193 w->window_end_valid = Qnil;
5195 w->optional_new_start = Qt;
5197 if (bytepos == BEGV_BYTE || FETCH_BYTE (bytepos - 1) == '\n')
5198 w->start_at_line_beg = Qt;
5199 else
5200 w->start_at_line_beg = Qnil;
5202 set_buffer_internal (obuf);
5203 return Qnil;
5206 DEFUN ("window-text-height", Fwindow_text_height, Swindow_text_height,
5207 0, 1, 0,
5208 doc: /* Return the height in lines of the text display area of WINDOW.
5209 WINDOW defaults to the selected window.
5211 The return value does not include the mode line, any header line, nor
5212 any partial-height lines in the text display area. */)
5213 (Lisp_Object window)
5215 struct window *w = decode_window (window);
5216 int pixel_height = window_box_height (w);
5217 int line_height = pixel_height / FRAME_LINE_HEIGHT (XFRAME (w->frame));
5218 return make_number (line_height);
5223 DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line,
5224 1, 1, "P",
5225 doc: /* Position point relative to window.
5226 With no argument, position point at center of window.
5227 An argument specifies vertical position within the window;
5228 zero means top of window, negative means relative to bottom of window. */)
5229 (Lisp_Object arg)
5231 struct window *w = XWINDOW (selected_window);
5232 int lines, start;
5233 Lisp_Object window;
5234 #if 0
5235 int this_scroll_margin;
5236 #endif
5238 window = selected_window;
5239 start = marker_position (w->start);
5240 if (start < BEGV || start > ZV)
5242 int height = window_internal_height (w);
5243 Fvertical_motion (make_number (- (height / 2)), window);
5244 set_marker_both (w->start, w->buffer, PT, PT_BYTE);
5245 w->start_at_line_beg = Fbolp ();
5246 w->force_start = Qt;
5248 else
5249 Fgoto_char (w->start);
5251 lines = displayed_window_lines (w);
5253 #if 0
5254 this_scroll_margin = max (0, scroll_margin);
5255 this_scroll_margin = min (this_scroll_margin, lines / 4);
5256 #endif
5258 if (NILP (arg))
5259 XSETFASTINT (arg, lines / 2);
5260 else
5262 int iarg = XINT (Fprefix_numeric_value (arg));
5264 if (iarg < 0)
5265 iarg = iarg + lines;
5267 #if 0 /* This code would prevent move-to-window-line from moving point
5268 to a place inside the scroll margins (which would cause the
5269 next redisplay to scroll). I wrote this code, but then concluded
5270 it is probably better not to install it. However, it is here
5271 inside #if 0 so as not to lose it. -- rms. */
5273 /* Don't let it get into the margin at either top or bottom. */
5274 iarg = max (iarg, this_scroll_margin);
5275 iarg = min (iarg, lines - this_scroll_margin - 1);
5276 #endif
5278 arg = make_number (iarg);
5281 /* Skip past a partially visible first line. */
5282 if (w->vscroll)
5283 XSETINT (arg, XINT (arg) + 1);
5285 return Fvertical_motion (arg, window);
5290 /***********************************************************************
5291 Window Configuration
5292 ***********************************************************************/
5294 struct save_window_data
5296 EMACS_UINT size;
5297 struct Lisp_Vector *next_from_Lisp_Vector_struct;
5298 Lisp_Object selected_frame;
5299 Lisp_Object current_window;
5300 Lisp_Object current_buffer;
5301 Lisp_Object minibuf_scroll_window;
5302 Lisp_Object minibuf_selected_window;
5303 Lisp_Object root_window;
5304 Lisp_Object focus_frame;
5305 /* A vector, each of whose elements is a struct saved_window
5306 for one window. */
5307 Lisp_Object saved_windows;
5309 /* All fields above are traced by the GC.
5310 From `fame-cols' down, the fields are ignored by the GC. */
5312 int frame_cols, frame_lines, frame_menu_bar_lines;
5313 int frame_tool_bar_lines;
5316 /* This is saved as a Lisp_Vector */
5317 struct saved_window
5319 /* these first two must agree with struct Lisp_Vector in lisp.h */
5320 EMACS_UINT size;
5321 struct Lisp_Vector *next_from_Lisp_Vector_struct;
5323 Lisp_Object window;
5324 Lisp_Object buffer, start, pointm, mark;
5325 Lisp_Object left_col, top_line, total_cols, total_lines;
5326 Lisp_Object normal_cols, normal_lines;
5327 Lisp_Object hscroll, min_hscroll;
5328 Lisp_Object parent, prev;
5329 Lisp_Object start_at_line_beg;
5330 Lisp_Object display_table;
5331 Lisp_Object left_margin_cols, right_margin_cols;
5332 Lisp_Object left_fringe_width, right_fringe_width, fringes_outside_margins;
5333 Lisp_Object scroll_bar_width, vertical_scroll_bar_type, dedicated;
5334 Lisp_Object inhibit_recombine;
5335 Lisp_Object window_parameters;
5338 #define SAVED_WINDOW_N(swv,n) \
5339 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5341 DEFUN ("window-configuration-p", Fwindow_configuration_p, Swindow_configuration_p, 1, 1, 0,
5342 doc: /* Return t if OBJECT is a window-configuration object. */)
5343 (Lisp_Object object)
5345 return WINDOW_CONFIGURATIONP (object) ? Qt : Qnil;
5348 DEFUN ("window-configuration-frame", Fwindow_configuration_frame, Swindow_configuration_frame, 1, 1, 0,
5349 doc: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5350 (Lisp_Object config)
5352 register struct save_window_data *data;
5353 struct Lisp_Vector *saved_windows;
5355 CHECK_WINDOW_CONFIGURATION (config);
5357 data = (struct save_window_data *) XVECTOR (config);
5358 saved_windows = XVECTOR (data->saved_windows);
5359 return XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame;
5362 DEFUN ("set-window-configuration", Fset_window_configuration,
5363 Sset_window_configuration, 1, 1, 0,
5364 doc: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5365 CONFIGURATION must be a value previously returned
5366 by `current-window-configuration' (which see).
5367 If CONFIGURATION was made from a frame that is now deleted,
5368 only frame-independent values can be restored. In this case,
5369 the return value is nil. Otherwise the value is t. */)
5370 (Lisp_Object configuration)
5372 register struct save_window_data *data;
5373 struct Lisp_Vector *saved_windows;
5374 Lisp_Object new_current_buffer;
5375 Lisp_Object frame;
5376 FRAME_PTR f;
5377 int old_point = -1;
5379 CHECK_WINDOW_CONFIGURATION (configuration);
5381 data = (struct save_window_data *) XVECTOR (configuration);
5382 saved_windows = XVECTOR (data->saved_windows);
5384 new_current_buffer = data->current_buffer;
5385 if (NILP (XBUFFER (new_current_buffer)->name))
5386 new_current_buffer = Qnil;
5387 else
5389 if (XBUFFER (new_current_buffer) == current_buffer)
5390 /* The code further down "preserves point" by saving here PT in
5391 old_point and then setting it later back into PT. When the
5392 current-selected-window and the final-selected-window both show
5393 the current buffer, this suffers from the problem that the
5394 current PT is the window-point of the current-selected-window,
5395 while the final PT is the point of the final-selected-window, so
5396 this copy from one PT to the other would end up moving the
5397 window-point of the final-selected-window to the window-point of
5398 the current-selected-window. So we have to be careful which
5399 point of the current-buffer we copy into old_point. */
5400 if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer)
5401 && WINDOWP (selected_window)
5402 && EQ (XWINDOW (selected_window)->buffer, new_current_buffer)
5403 && !EQ (selected_window, data->current_window))
5404 old_point = XMARKER (XWINDOW (data->current_window)->pointm)->charpos;
5405 else
5406 old_point = PT;
5407 else
5408 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
5409 point in new_current_buffer as of the last time this buffer was
5410 used. This can be non-deterministic since it can be changed by
5411 things like jit-lock by mere temporary selection of some random
5412 window that happens to show this buffer.
5413 So if possible we want this arbitrary choice of "which point" to
5414 be the one from the to-be-selected-window so as to prevent this
5415 window's cursor from being copied from another window. */
5416 if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer)
5417 /* If current_window = selected_window, its point is in BUF_PT. */
5418 && !EQ (selected_window, data->current_window))
5419 old_point = XMARKER (XWINDOW (data->current_window)->pointm)->charpos;
5420 else
5421 old_point = BUF_PT (XBUFFER (new_current_buffer));
5424 frame = XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame;
5425 f = XFRAME (frame);
5427 /* If f is a dead frame, don't bother rebuilding its window tree.
5428 However, there is other stuff we should still try to do below. */
5429 if (FRAME_LIVE_P (f))
5431 Lisp_Object window;
5432 Lisp_Object dead_windows = Qnil;
5433 register struct window *w;
5434 register struct saved_window *p;
5435 struct window *root_window;
5436 struct window **leaf_windows;
5437 int n_leaf_windows;
5438 int k, i, n;
5440 /* If the frame has been resized since this window configuration was
5441 made, we change the frame to the size specified in the
5442 configuration, restore the configuration, and then resize it
5443 back. We keep track of the prevailing height in these variables. */
5444 int previous_frame_lines = FRAME_LINES (f);
5445 int previous_frame_cols = FRAME_COLS (f);
5446 int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
5447 int previous_frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f);
5449 /* The mouse highlighting code could get screwed up
5450 if it runs during this. */
5451 BLOCK_INPUT;
5453 if (data->frame_lines != previous_frame_lines
5454 || data->frame_cols != previous_frame_cols)
5455 change_frame_size (f, data->frame_lines,
5456 data->frame_cols, 0, 0, 0);
5457 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5458 if (data->frame_menu_bar_lines
5459 != previous_frame_menu_bar_lines)
5460 x_set_menu_bar_lines (f, make_number (data->frame_menu_bar_lines),
5461 make_number (0));
5462 #ifdef HAVE_WINDOW_SYSTEM
5463 if (data->frame_tool_bar_lines
5464 != previous_frame_tool_bar_lines)
5465 x_set_tool_bar_lines (f, make_number (data->frame_tool_bar_lines),
5466 make_number (0));
5467 #endif
5468 #endif
5470 /* "Swap out" point from the selected window's buffer
5471 into the window itself. (Normally the pointm of the selected
5472 window holds garbage.) We do this now, before
5473 restoring the window contents, and prevent it from
5474 being done later on when we select a new window. */
5475 if (! NILP (XWINDOW (selected_window)->buffer))
5477 w = XWINDOW (selected_window);
5478 set_marker_both (w->pointm,
5479 w->buffer,
5480 BUF_PT (XBUFFER (w->buffer)),
5481 BUF_PT_BYTE (XBUFFER (w->buffer)));
5484 windows_or_buffers_changed++;
5485 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
5487 /* Problem: Freeing all matrices and later allocating them again
5488 is a serious redisplay flickering problem. What we would
5489 really like to do is to free only those matrices not reused
5490 below. */
5491 root_window = XWINDOW (FRAME_ROOT_WINDOW (f));
5492 leaf_windows
5493 = (struct window **) alloca (count_windows (root_window)
5494 * sizeof (struct window *));
5495 n_leaf_windows = get_leaf_windows (root_window, leaf_windows, 0);
5497 /* Kludge Alert!
5498 Mark all windows now on frame as "deleted".
5499 Restoring the new configuration "undeletes" any that are in it.
5501 Save their current buffers in their height fields, since we may
5502 need it later, if a buffer saved in the configuration is now
5503 dead. */
5504 delete_all_subwindows (FRAME_ROOT_WINDOW (f));
5506 for (k = 0; k < saved_windows->size; k++)
5508 p = SAVED_WINDOW_N (saved_windows, k);
5509 window = p->window;
5510 w = XWINDOW (window);
5511 w->next = Qnil;
5513 if (!NILP (p->parent))
5514 w->parent = SAVED_WINDOW_N (saved_windows,
5515 XFASTINT (p->parent))->window;
5516 else
5517 w->parent = Qnil;
5519 if (!NILP (p->prev))
5521 w->prev = SAVED_WINDOW_N (saved_windows,
5522 XFASTINT (p->prev))->window;
5523 XWINDOW (w->prev)->next = p->window;
5525 else
5527 w->prev = Qnil;
5528 if (!NILP (w->parent))
5530 if (EQ (p->total_cols, XWINDOW (w->parent)->total_cols))
5532 XWINDOW (w->parent)->vchild = p->window;
5533 XWINDOW (w->parent)->hchild = Qnil;
5535 else
5537 XWINDOW (w->parent)->hchild = p->window;
5538 XWINDOW (w->parent)->vchild = Qnil;
5543 /* If we squirreled away the buffer in the window's height,
5544 restore it now. */
5545 if (BUFFERP (w->total_lines))
5546 w->buffer = w->total_lines;
5547 w->left_col = p->left_col;
5548 w->top_line = p->top_line;
5549 w->total_cols = p->total_cols;
5550 w->total_lines = p->total_lines;
5551 w->normal_cols = p->normal_cols;
5552 w->normal_lines = p->normal_lines;
5553 w->hscroll = p->hscroll;
5554 w->min_hscroll = p->min_hscroll;
5555 w->display_table = p->display_table;
5556 w->left_margin_cols = p->left_margin_cols;
5557 w->right_margin_cols = p->right_margin_cols;
5558 w->left_fringe_width = p->left_fringe_width;
5559 w->right_fringe_width = p->right_fringe_width;
5560 w->fringes_outside_margins = p->fringes_outside_margins;
5561 w->scroll_bar_width = p->scroll_bar_width;
5562 w->vertical_scroll_bar_type = p->vertical_scroll_bar_type;
5563 w->dedicated = p->dedicated;
5564 w->inhibit_recombine = p->inhibit_recombine;
5565 w->window_parameters = p->window_parameters;
5566 XSETFASTINT (w->last_modified, 0);
5567 XSETFASTINT (w->last_overlay_modified, 0);
5569 /* Reinstall the saved buffer and pointers into it. */
5570 if (NILP (p->buffer))
5571 /* An internal window. */
5572 w->buffer = p->buffer;
5573 else if (!NILP (XBUFFER (p->buffer)->name))
5574 /* If saved buffer is alive, install it. */
5576 w->buffer = p->buffer;
5577 w->start_at_line_beg = p->start_at_line_beg;
5578 set_marker_restricted (w->start, p->start, w->buffer);
5579 set_marker_restricted (w->pointm, p->pointm, w->buffer);
5580 Fset_marker (XBUFFER (w->buffer)->mark,
5581 p->mark, w->buffer);
5583 /* As documented in Fcurrent_window_configuration, don't
5584 restore the location of point in the buffer which was
5585 current when the window configuration was recorded. */
5586 if (!EQ (p->buffer, new_current_buffer)
5587 && XBUFFER (p->buffer) == current_buffer)
5588 Fgoto_char (w->pointm);
5590 else if (NILP (w->buffer) || NILP (XBUFFER (w->buffer)->name))
5591 /* Else unless window has a live buffer, get one. */
5593 w->buffer = Fcdr (Fcar (Vbuffer_alist));
5594 /* This will set the markers to beginning of visible
5595 range. */
5596 set_marker_restricted (w->start, make_number (0), w->buffer);
5597 set_marker_restricted (w->pointm, make_number (0), w->buffer);
5598 w->start_at_line_beg = Qt;
5599 if (!NILP (w->dedicated))
5600 /* Record this window as window as dead. */
5601 dead_windows = Fcons (window, dead_windows);
5602 /* Make sure window is no more dedicated. */
5603 w->dedicated = Qnil;
5605 else
5606 /* Keeping window's old buffer; make sure the markers
5607 are real. */
5609 /* Set window markers at start of visible range. */
5610 if (XMARKER (w->start)->buffer == 0)
5611 set_marker_restricted (w->start, make_number (0),
5612 w->buffer);
5613 if (XMARKER (w->pointm)->buffer == 0)
5614 set_marker_restricted_both (w->pointm, w->buffer,
5615 BUF_PT (XBUFFER (w->buffer)),
5616 BUF_PT_BYTE (XBUFFER (w->buffer)));
5617 w->start_at_line_beg = Qt;
5621 FRAME_ROOT_WINDOW (f) = data->root_window;
5622 /* Prevent "swapping out point" in the old selected window
5623 using the buffer that has been restored into it.
5624 We already swapped out point that from that window's old buffer. */
5625 selected_window = Qnil;
5627 /* Arrange *not* to restore point in the buffer that was
5628 current when the window configuration was saved. */
5629 if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer))
5630 set_marker_restricted (XWINDOW (data->current_window)->pointm,
5631 make_number (old_point),
5632 XWINDOW (data->current_window)->buffer);
5634 Fselect_window (data->current_window, Qnil);
5635 XBUFFER (XWINDOW (selected_window)->buffer)->last_selected_window
5636 = selected_window;
5638 if (NILP (data->focus_frame)
5639 || (FRAMEP (data->focus_frame)
5640 && FRAME_LIVE_P (XFRAME (data->focus_frame))))
5641 Fredirect_frame_focus (frame, data->focus_frame);
5643 #if 0 /* I don't understand why this is needed, and it causes problems
5644 when the frame's old selected window has been deleted. */
5645 if (f != selected_frame && FRAME_WINDOW_P (f))
5646 do_switch_frame (WINDOW_FRAME (XWINDOW (data->root_window)),
5647 0, 0, Qnil);
5648 #endif
5650 /* Set the screen height to the value it had before this function. */
5651 if (previous_frame_lines != FRAME_LINES (f)
5652 || previous_frame_cols != FRAME_COLS (f))
5653 change_frame_size (f, previous_frame_lines, previous_frame_cols,
5654 0, 0, 0);
5655 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5656 if (previous_frame_menu_bar_lines != FRAME_MENU_BAR_LINES (f))
5657 x_set_menu_bar_lines (f, make_number (previous_frame_menu_bar_lines),
5658 make_number (0));
5659 #ifdef HAVE_WINDOW_SYSTEM
5660 if (previous_frame_tool_bar_lines != FRAME_TOOL_BAR_LINES (f))
5661 x_set_tool_bar_lines (f, make_number (previous_frame_tool_bar_lines),
5662 make_number (0));
5663 #endif
5664 #endif
5666 /* Now, free glyph matrices in windows that were not reused. */
5667 for (i = n = 0; i < n_leaf_windows; ++i)
5669 if (NILP (leaf_windows[i]->buffer))
5671 /* Assert it's not reused as a combination. */
5672 xassert (NILP (leaf_windows[i]->hchild)
5673 && NILP (leaf_windows[i]->vchild));
5674 free_window_matrices (leaf_windows[i]);
5676 else if (EQ (leaf_windows[i]->buffer, new_current_buffer))
5677 ++n;
5680 adjust_glyphs (f);
5681 UNBLOCK_INPUT;
5683 /* Scan dead buffer windows. */
5684 for (; CONSP (dead_windows); dead_windows = XCDR (dead_windows))
5686 window = XCAR (dead_windows);
5687 if (WINDOW_LIVE_P (window) && !EQ (window, FRAME_ROOT_WINDOW (f)))
5688 delete_deletable_window (window);
5691 /* Fselect_window will have made f the selected frame, so we
5692 reselect the proper frame here. Fhandle_switch_frame will change the
5693 selected window too, but that doesn't make the call to
5694 Fselect_window above totally superfluous; it still sets f's
5695 selected window. */
5696 if (FRAME_LIVE_P (XFRAME (data->selected_frame)))
5697 do_switch_frame (data->selected_frame, 0, 0, Qnil);
5699 run_window_configuration_change_hook (f);
5702 if (!NILP (new_current_buffer))
5703 Fset_buffer (new_current_buffer);
5705 Vminibuf_scroll_window = data->minibuf_scroll_window;
5706 minibuf_selected_window = data->minibuf_selected_window;
5708 return (FRAME_LIVE_P (f) ? Qt : Qnil);
5712 /* Delete all subwindows of the parent window of WINDOW. */
5713 void
5714 delete_all_subwindows (Lisp_Object window)
5716 register struct window *w;
5718 w = XWINDOW (window);
5720 if (!NILP (w->next))
5721 /* Delete WINDOW's siblings (we traverse postorderly). */
5722 delete_all_subwindows (w->next);
5724 w->total_lines = w->buffer; /* See Fset_window_configuration for excuse. */
5726 if (!NILP (w->vchild))
5728 delete_all_subwindows (w->vchild);
5729 w->vchild = Qnil;
5731 else if (!NILP (w->hchild))
5733 delete_all_subwindows (w->hchild);
5734 w->hchild = Qnil;
5736 else if (!NILP (w->buffer))
5738 unshow_buffer (w);
5739 unchain_marker (XMARKER (w->pointm));
5740 unchain_marker (XMARKER (w->start));
5741 w->buffer = Qnil;
5744 Vwindow_list = Qnil;
5747 static int
5748 count_windows (register struct window *window)
5750 register int count = 1;
5751 if (!NILP (window->next))
5752 count += count_windows (XWINDOW (window->next));
5753 if (!NILP (window->vchild))
5754 count += count_windows (XWINDOW (window->vchild));
5755 if (!NILP (window->hchild))
5756 count += count_windows (XWINDOW (window->hchild));
5757 return count;
5761 /* Fill vector FLAT with leaf windows under W, starting at index I.
5762 Value is last index + 1. */
5763 static int
5764 get_leaf_windows (struct window *w, struct window **flat, int i)
5766 while (w)
5768 if (!NILP (w->hchild))
5769 i = get_leaf_windows (XWINDOW (w->hchild), flat, i);
5770 else if (!NILP (w->vchild))
5771 i = get_leaf_windows (XWINDOW (w->vchild), flat, i);
5772 else
5773 flat[i++] = w;
5775 w = NILP (w->next) ? 0 : XWINDOW (w->next);
5778 return i;
5782 /* Return a pointer to the glyph W's physical cursor is on. Value is
5783 null if W's current matrix is invalid, so that no meaningfull glyph
5784 can be returned. */
5785 struct glyph *
5786 get_phys_cursor_glyph (struct window *w)
5788 struct glyph_row *row;
5789 struct glyph *glyph;
5791 if (w->phys_cursor.vpos >= 0
5792 && w->phys_cursor.vpos < w->current_matrix->nrows
5793 && (row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos),
5794 row->enabled_p)
5795 && row->used[TEXT_AREA] > w->phys_cursor.hpos)
5796 glyph = row->glyphs[TEXT_AREA] + w->phys_cursor.hpos;
5797 else
5798 glyph = NULL;
5800 return glyph;
5804 static int
5805 save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
5807 register struct saved_window *p;
5808 register struct window *w;
5809 register Lisp_Object tem;
5811 for (;!NILP (window); window = w->next)
5813 p = SAVED_WINDOW_N (vector, i);
5814 w = XWINDOW (window);
5816 XSETFASTINT (w->temslot, i); i++;
5817 p->window = window;
5818 p->buffer = w->buffer;
5819 p->left_col = w->left_col;
5820 p->top_line = w->top_line;
5821 p->total_cols = w->total_cols;
5822 p->total_lines = w->total_lines;
5823 p->normal_cols = w->normal_cols;
5824 p->normal_lines = w->normal_lines;
5825 p->hscroll = w->hscroll;
5826 p->min_hscroll = w->min_hscroll;
5827 p->display_table = w->display_table;
5828 p->left_margin_cols = w->left_margin_cols;
5829 p->right_margin_cols = w->right_margin_cols;
5830 p->left_fringe_width = w->left_fringe_width;
5831 p->right_fringe_width = w->right_fringe_width;
5832 p->fringes_outside_margins = w->fringes_outside_margins;
5833 p->scroll_bar_width = w->scroll_bar_width;
5834 p->vertical_scroll_bar_type = w->vertical_scroll_bar_type;
5835 p->dedicated = w->dedicated;
5836 p->inhibit_recombine = w->inhibit_recombine;
5837 p->window_parameters = w->window_parameters;
5838 if (!NILP (w->buffer))
5840 /* Save w's value of point in the window configuration.
5841 If w is the selected window, then get the value of point
5842 from the buffer; pointm is garbage in the selected window. */
5843 if (EQ (window, selected_window))
5845 p->pointm = Fmake_marker ();
5846 set_marker_both (p->pointm, w->buffer,
5847 BUF_PT (XBUFFER (w->buffer)),
5848 BUF_PT_BYTE (XBUFFER (w->buffer)));
5850 else
5851 p->pointm = Fcopy_marker (w->pointm, Qnil);
5853 p->start = Fcopy_marker (w->start, Qnil);
5854 p->start_at_line_beg = w->start_at_line_beg;
5856 tem = XBUFFER (w->buffer)->mark;
5857 p->mark = Fcopy_marker (tem, Qnil);
5859 else
5861 p->pointm = Qnil;
5862 p->start = Qnil;
5863 p->mark = Qnil;
5864 p->start_at_line_beg = Qnil;
5867 if (NILP (w->parent))
5868 p->parent = Qnil;
5869 else
5870 p->parent = XWINDOW (w->parent)->temslot;
5872 if (NILP (w->prev))
5873 p->prev = Qnil;
5874 else
5875 p->prev = XWINDOW (w->prev)->temslot;
5877 if (!NILP (w->vchild))
5878 i = save_window_save (w->vchild, vector, i);
5879 if (!NILP (w->hchild))
5880 i = save_window_save (w->hchild, vector, i);
5883 return i;
5886 DEFUN ("current-window-configuration", Fcurrent_window_configuration,
5887 Scurrent_window_configuration, 0, 1, 0,
5888 doc: /* Return an object representing the current window configuration of FRAME.
5889 If FRAME is nil or omitted, use the selected frame.
5890 This describes the number of windows, their sizes and current buffers,
5891 and for each displayed buffer, where display starts, and the positions of
5892 point and mark. An exception is made for point in the current buffer:
5893 its value is -not- saved.
5894 This also records the currently selected frame, and FRAME's focus
5895 redirection (see `redirect-frame-focus'). */)
5896 (Lisp_Object frame)
5898 register Lisp_Object tem;
5899 register int n_windows;
5900 register struct save_window_data *data;
5901 register int i;
5902 FRAME_PTR f;
5904 if (NILP (frame))
5905 frame = selected_frame;
5906 CHECK_LIVE_FRAME (frame);
5907 f = XFRAME (frame);
5909 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
5910 data = ALLOCATE_PSEUDOVECTOR (struct save_window_data, frame_cols,
5911 PVEC_WINDOW_CONFIGURATION);
5913 data->frame_cols = FRAME_COLS (f);
5914 data->frame_lines = FRAME_LINES (f);
5915 data->frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
5916 data->frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f);
5917 data->selected_frame = selected_frame;
5918 data->current_window = FRAME_SELECTED_WINDOW (f);
5919 XSETBUFFER (data->current_buffer, current_buffer);
5920 data->minibuf_scroll_window = minibuf_level > 0 ? Vminibuf_scroll_window : Qnil;
5921 data->minibuf_selected_window = minibuf_level > 0 ? minibuf_selected_window : Qnil;
5922 data->root_window = FRAME_ROOT_WINDOW (f);
5923 data->focus_frame = FRAME_FOCUS_FRAME (f);
5924 tem = Fmake_vector (make_number (n_windows), Qnil);
5925 data->saved_windows = tem;
5926 for (i = 0; i < n_windows; i++)
5927 XVECTOR (tem)->contents[i]
5928 = Fmake_vector (make_number (VECSIZE (struct saved_window)), Qnil);
5929 save_window_save (FRAME_ROOT_WINDOW (f), XVECTOR (tem), 0);
5930 XSETWINDOW_CONFIGURATION (tem, data);
5931 return (tem);
5934 DEFUN ("save-window-excursion", Fsave_window_excursion, Ssave_window_excursion,
5935 0, UNEVALLED, 0,
5936 doc: /* Execute BODY, preserving window sizes and contents.
5937 Return the value of the last form in BODY.
5938 Restore which buffer appears in which window, where display starts,
5939 and the value of point and mark for each window.
5940 Also restore the choice of selected window.
5941 Also restore which buffer is current.
5942 Does not restore the value of point in current buffer.
5943 usage: (save-window-excursion BODY...) */)
5944 (Lisp_Object args)
5946 register Lisp_Object val;
5947 register int count = SPECPDL_INDEX ();
5949 record_unwind_protect (Fset_window_configuration,
5950 Fcurrent_window_configuration (Qnil));
5951 val = Fprogn (args);
5952 return unbind_to (count, val);
5955 /***********************************************************************
5956 Marginal Areas
5957 ***********************************************************************/
5959 DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins,
5960 2, 3, 0,
5961 doc: /* Set width of marginal areas of window WINDOW.
5962 If WINDOW is nil, set margins of the currently selected window.
5963 Second arg LEFT-WIDTH specifies the number of character cells to
5964 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
5965 does the same for the right marginal area. A nil width parameter
5966 means no margin. */)
5967 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width)
5969 struct window *w = decode_window (window);
5971 /* Translate negative or zero widths to nil.
5972 Margins that are too wide have to be checked elsewhere. */
5974 if (!NILP (left_width))
5976 CHECK_NUMBER (left_width);
5977 if (XINT (left_width) <= 0)
5978 left_width = Qnil;
5981 if (!NILP (right_width))
5983 CHECK_NUMBER (right_width);
5984 if (XINT (right_width) <= 0)
5985 right_width = Qnil;
5988 if (!EQ (w->left_margin_cols, left_width)
5989 || !EQ (w->right_margin_cols, right_width))
5991 w->left_margin_cols = left_width;
5992 w->right_margin_cols = right_width;
5994 adjust_window_margins (w);
5996 ++windows_or_buffers_changed;
5997 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6000 return Qnil;
6004 DEFUN ("window-margins", Fwindow_margins, Swindow_margins,
6005 0, 1, 0,
6006 doc: /* Get width of marginal areas of window WINDOW.
6007 If WINDOW is omitted or nil, use the currently selected window.
6008 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6009 If a marginal area does not exist, its width will be returned
6010 as nil. */)
6011 (Lisp_Object window)
6013 struct window *w = decode_window (window);
6014 return Fcons (w->left_margin_cols, w->right_margin_cols);
6019 /***********************************************************************
6020 Fringes
6021 ***********************************************************************/
6023 DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes,
6024 2, 4, 0,
6025 doc: /* Set the fringe widths of window WINDOW.
6026 If WINDOW is nil, set the fringe widths of the currently selected
6027 window.
6028 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6029 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6030 fringe width. If a fringe width arg is nil, that means to use the
6031 frame's default fringe width. Default fringe widths can be set with
6032 the command `set-fringe-style'.
6033 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6034 outside of the display margins. By default, fringes are drawn between
6035 display marginal areas and the text area. */)
6036 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width, Lisp_Object outside_margins)
6038 struct window *w = decode_window (window);
6040 if (!NILP (left_width))
6041 CHECK_NATNUM (left_width);
6042 if (!NILP (right_width))
6043 CHECK_NATNUM (right_width);
6045 /* Do nothing on a tty. */
6046 if (FRAME_WINDOW_P (WINDOW_XFRAME (w))
6047 && (!EQ (w->left_fringe_width, left_width)
6048 || !EQ (w->right_fringe_width, right_width)
6049 || !EQ (w->fringes_outside_margins, outside_margins)))
6051 w->left_fringe_width = left_width;
6052 w->right_fringe_width = right_width;
6053 w->fringes_outside_margins = outside_margins;
6055 adjust_window_margins (w);
6057 clear_glyph_matrix (w->current_matrix);
6058 w->window_end_valid = Qnil;
6060 ++windows_or_buffers_changed;
6061 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6064 return Qnil;
6068 DEFUN ("window-fringes", Fwindow_fringes, Swindow_fringes,
6069 0, 1, 0,
6070 doc: /* Get width of fringes of window WINDOW.
6071 If WINDOW is omitted or nil, use the currently selected window.
6072 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6073 (Lisp_Object window)
6075 struct window *w = decode_window (window);
6077 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w)),
6078 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w)),
6079 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
6080 ? Qt : Qnil), Qnil)));
6085 /***********************************************************************
6086 Scroll bars
6087 ***********************************************************************/
6089 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars, Sset_window_scroll_bars,
6090 2, 4, 0,
6091 doc: /* Set width and type of scroll bars of window WINDOW.
6092 If window is nil, set scroll bars of the currently selected window.
6093 Second parameter WIDTH specifies the pixel width for the scroll bar;
6094 this is automatically adjusted to a multiple of the frame column width.
6095 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6096 bar: left, right, or nil.
6097 If WIDTH is nil, use the frame's scroll-bar width.
6098 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6099 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6100 (Lisp_Object window, Lisp_Object width, Lisp_Object vertical_type, Lisp_Object horizontal_type)
6102 struct window *w = decode_window (window);
6104 if (!NILP (width))
6106 CHECK_NATNUM (width);
6108 if (XINT (width) == 0)
6109 vertical_type = Qnil;
6112 if (!(NILP (vertical_type)
6113 || EQ (vertical_type, Qleft)
6114 || EQ (vertical_type, Qright)
6115 || EQ (vertical_type, Qt)))
6116 error ("Invalid type of vertical scroll bar");
6118 if (!EQ (w->scroll_bar_width, width)
6119 || !EQ (w->vertical_scroll_bar_type, vertical_type))
6121 w->scroll_bar_width = width;
6122 w->vertical_scroll_bar_type = vertical_type;
6124 adjust_window_margins (w);
6126 clear_glyph_matrix (w->current_matrix);
6127 w->window_end_valid = Qnil;
6129 ++windows_or_buffers_changed;
6130 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6133 return Qnil;
6137 DEFUN ("window-scroll-bars", Fwindow_scroll_bars, Swindow_scroll_bars,
6138 0, 1, 0,
6139 doc: /* Get width and type of scroll bars of window WINDOW.
6140 If WINDOW is omitted or nil, use the currently selected window.
6141 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6142 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6143 value. */)
6144 (Lisp_Object window)
6146 struct window *w = decode_window (window);
6147 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
6148 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
6149 : WINDOW_SCROLL_BAR_AREA_WIDTH (w))),
6150 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w)),
6151 Fcons (w->vertical_scroll_bar_type,
6152 Fcons (Qnil, Qnil))));
6157 /***********************************************************************
6158 Smooth scrolling
6159 ***********************************************************************/
6161 DEFUN ("window-vscroll", Fwindow_vscroll, Swindow_vscroll, 0, 2, 0,
6162 doc: /* Return the amount by which WINDOW is scrolled vertically.
6163 Use the selected window if WINDOW is nil or omitted.
6164 Normally, value is a multiple of the canonical character height of WINDOW;
6165 optional second arg PIXELS-P means value is measured in pixels. */)
6166 (Lisp_Object window, Lisp_Object pixels_p)
6168 Lisp_Object result;
6169 struct frame *f;
6170 struct window *w;
6172 if (NILP (window))
6173 window = selected_window;
6174 else
6175 CHECK_WINDOW (window);
6176 w = XWINDOW (window);
6177 f = XFRAME (w->frame);
6179 if (FRAME_WINDOW_P (f))
6180 result = (NILP (pixels_p)
6181 ? FRAME_CANON_Y_FROM_PIXEL_Y (f, -w->vscroll)
6182 : make_number (-w->vscroll));
6183 else
6184 result = make_number (0);
6185 return result;
6189 DEFUN ("set-window-vscroll", Fset_window_vscroll, Sset_window_vscroll,
6190 2, 3, 0,
6191 doc: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6192 WINDOW nil means use the selected window. Normally, VSCROLL is a
6193 non-negative multiple of the canonical character height of WINDOW;
6194 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
6195 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6196 corresponds to an integral number of pixels. The return value is the
6197 result of this rounding.
6198 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6199 (Lisp_Object window, Lisp_Object vscroll, Lisp_Object pixels_p)
6201 struct window *w;
6202 struct frame *f;
6204 if (NILP (window))
6205 window = selected_window;
6206 else
6207 CHECK_WINDOW (window);
6208 CHECK_NUMBER_OR_FLOAT (vscroll);
6210 w = XWINDOW (window);
6211 f = XFRAME (w->frame);
6213 if (FRAME_WINDOW_P (f))
6215 int old_dy = w->vscroll;
6217 w->vscroll = - (NILP (pixels_p)
6218 ? FRAME_LINE_HEIGHT (f) * XFLOATINT (vscroll)
6219 : XFLOATINT (vscroll));
6220 w->vscroll = min (w->vscroll, 0);
6222 if (w->vscroll != old_dy)
6224 /* Adjust glyph matrix of the frame if the virtual display
6225 area becomes larger than before. */
6226 if (w->vscroll < 0 && w->vscroll < old_dy)
6227 adjust_glyphs (f);
6229 /* Prevent redisplay shortcuts. */
6230 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
6234 return Fwindow_vscroll (window, pixels_p);
6238 /* Call FN for all leaf windows on frame F. FN is called with the
6239 first argument being a pointer to the leaf window, and with
6240 additional argument USER_DATA. Stops when FN returns 0. */
6242 void
6243 foreach_window (struct frame *f, int (*fn) (struct window *, void *), void *user_data)
6245 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
6246 if (WINDOWP (FRAME_ROOT_WINDOW (f)))
6247 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f)), fn, user_data);
6251 /* Helper function for foreach_window. Call FN for all leaf windows
6252 reachable from W. FN is called with the first argument being a
6253 pointer to the leaf window, and with additional argument USER_DATA.
6254 Stop when FN returns 0. Value is 0 if stopped by FN. */
6256 static int
6257 foreach_window_1 (struct window *w, int (*fn) (struct window *, void *), void *user_data)
6259 int cont;
6261 for (cont = 1; w && cont;)
6263 if (!NILP (w->hchild))
6264 cont = foreach_window_1 (XWINDOW (w->hchild), fn, user_data);
6265 else if (!NILP (w->vchild))
6266 cont = foreach_window_1 (XWINDOW (w->vchild), fn, user_data);
6267 else
6268 cont = fn (w, user_data);
6270 w = NILP (w->next) ? 0 : XWINDOW (w->next);
6273 return cont;
6277 /* Freeze or unfreeze the window start of W unless it is a
6278 mini-window or the selected window. FREEZE_P non-null means freeze
6279 the window start. */
6281 static int
6282 freeze_window_start (struct window *w, void *freeze_p)
6284 if (MINI_WINDOW_P (w)
6285 || (WINDOWP (selected_window) /* Can be nil in corner cases. */
6286 && (w == XWINDOW (selected_window)
6287 || (MINI_WINDOW_P (XWINDOW (selected_window))
6288 && ! NILP (Vminibuf_scroll_window)
6289 && w == XWINDOW (Vminibuf_scroll_window)))))
6290 freeze_p = NULL;
6292 w->frozen_window_start_p = freeze_p != NULL;
6293 return 1;
6297 /* Freeze or unfreeze the window starts of all leaf windows on frame
6298 F, except the selected window and a mini-window. FREEZE_P non-zero
6299 means freeze the window start. */
6301 void
6302 freeze_window_starts (struct frame *f, int freeze_p)
6304 foreach_window (f, freeze_window_start, (void *) (freeze_p ? f : 0));
6308 /***********************************************************************
6309 Initialization
6310 ***********************************************************************/
6312 /* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2
6313 describe the same state of affairs. This is used by Fequal.
6315 ignore_positions non-zero means ignore non-matching scroll positions
6316 and the like.
6318 This ignores a couple of things like the dedicatedness status of
6319 window, inhibit_recombine and the like. This might have to be
6320 fixed. */
6323 compare_window_configurations (Lisp_Object configuration1, Lisp_Object configuration2, int ignore_positions)
6325 register struct save_window_data *d1, *d2;
6326 struct Lisp_Vector *sws1, *sws2;
6327 int i;
6329 CHECK_WINDOW_CONFIGURATION (configuration1);
6330 CHECK_WINDOW_CONFIGURATION (configuration2);
6332 d1 = (struct save_window_data *) XVECTOR (configuration1);
6333 d2 = (struct save_window_data *) XVECTOR (configuration2);
6334 sws1 = XVECTOR (d1->saved_windows);
6335 sws2 = XVECTOR (d2->saved_windows);
6337 /* Frame settings must match. */
6338 if (d1->frame_cols != d2->frame_cols
6339 || d1->frame_lines != d2->frame_lines
6340 || d1->frame_menu_bar_lines != d2->frame_menu_bar_lines
6341 || !EQ (d1->selected_frame, d2->selected_frame)
6342 || !EQ (d1->current_buffer, d2->current_buffer)
6343 || (!ignore_positions
6344 && (!EQ (d1->minibuf_scroll_window, d2->minibuf_scroll_window)
6345 || !EQ (d1->minibuf_selected_window, d2->minibuf_selected_window)))
6346 || !EQ (d1->focus_frame, d2->focus_frame)
6347 /* Verify that the two configurations have the same number of windows. */
6348 || sws1->size != sws2->size)
6349 return 0;
6351 for (i = 0; i < sws1->size; i++)
6353 struct saved_window *sw1, *sw2;
6354 int w1_is_current, w2_is_current;
6356 sw1 = SAVED_WINDOW_N (sws1, i);
6357 sw2 = SAVED_WINDOW_N (sws2, i);
6359 if (
6360 /* The "current" windows in the two configurations must
6361 correspond to each other. */
6362 EQ (d1->current_window, sw1->window)
6363 != EQ (d2->current_window, sw2->window)
6364 /* Windows' buffers must match. */
6365 || !EQ (sw1->buffer, sw2->buffer)
6366 || !EQ (sw1->left_col, sw2->left_col)
6367 || !EQ (sw1->top_line, sw2->top_line)
6368 || !EQ (sw1->total_cols, sw2->total_cols)
6369 || !EQ (sw1->total_lines, sw2->total_lines)
6370 || !EQ (sw1->display_table, sw2->display_table)
6371 /* The next two disjuncts check the window structure for
6372 equality. */
6373 || !EQ (sw1->parent, sw2->parent)
6374 || !EQ (sw1->prev, sw2->prev)
6375 || (!ignore_positions
6376 && (!EQ (sw1->hscroll, sw2->hscroll)
6377 || !EQ (sw1->min_hscroll, sw2->min_hscroll)
6378 || !EQ (sw1->start_at_line_beg, sw2->start_at_line_beg)
6379 || NILP (Fequal (sw1->start, sw2->start))
6380 || NILP (Fequal (sw1->pointm, sw2->pointm))
6381 || NILP (Fequal (sw1->mark, sw2->mark))))
6382 || !EQ (sw1->left_margin_cols, sw2->left_margin_cols)
6383 || !EQ (sw1->right_margin_cols, sw2->right_margin_cols)
6384 || !EQ (sw1->left_fringe_width, sw2->left_fringe_width)
6385 || !EQ (sw1->right_fringe_width, sw2->right_fringe_width)
6386 || !EQ (sw1->fringes_outside_margins, sw2->fringes_outside_margins)
6387 || !EQ (sw1->scroll_bar_width, sw2->scroll_bar_width)
6388 || !EQ (sw1->vertical_scroll_bar_type, sw2->vertical_scroll_bar_type))
6389 return 0;
6392 return 1;
6395 DEFUN ("compare-window-configurations", Fcompare_window_configurations,
6396 Scompare_window_configurations, 2, 2, 0,
6397 doc: /* Compare two window configurations as regards the structure of windows.
6398 This function ignores details such as the values of point and mark
6399 and scrolling positions. */)
6400 (Lisp_Object x, Lisp_Object y)
6402 if (compare_window_configurations (x, y, 1))
6403 return Qt;
6404 return Qnil;
6407 void
6408 init_window_once (void)
6410 struct frame *f = make_initial_frame ();
6411 XSETFRAME (selected_frame, f);
6412 Vterminal_frame = selected_frame;
6413 minibuf_window = f->minibuffer_window;
6414 selected_window = f->selected_window;
6415 last_nonminibuf_frame = f;
6417 window_initialized = 1;
6420 void
6421 init_window (void)
6423 Vwindow_list = Qnil;
6426 void
6427 syms_of_window (void)
6429 Qscroll_up = intern_c_string ("scroll-up");
6430 staticpro (&Qscroll_up);
6432 Qscroll_down = intern_c_string ("scroll-down");
6433 staticpro (&Qscroll_down);
6435 Qscroll_command = intern_c_string ("scroll-command");
6436 staticpro (&Qscroll_command);
6438 Fput (Qscroll_up, Qscroll_command, Qt);
6439 Fput (Qscroll_down, Qscroll_command, Qt);
6441 staticpro (&Qwindow_configuration_change_hook);
6442 Qwindow_configuration_change_hook
6443 = intern_c_string ("window-configuration-change-hook");
6445 Qwindowp = intern_c_string ("windowp");
6446 staticpro (&Qwindowp);
6448 Qwindow_configuration_p = intern_c_string ("window-configuration-p");
6449 staticpro (&Qwindow_configuration_p);
6451 Qwindow_live_p = intern_c_string ("window-live-p");
6452 staticpro (&Qwindow_live_p);
6454 Qwindow_deletable_p = intern_c_string ("window-deletable-p");
6455 staticpro (&Qwindow_deletable_p);
6457 Qdelete_window = intern_c_string ("delete-window");
6458 staticpro (&Qdelete_window);
6460 Qresize_root_window = intern_c_string ("resize-root-window");
6461 staticpro (&Qresize_root_window);
6463 Qresize_root_window_vertically = intern_c_string ("resize-root-window-vertically");
6464 staticpro (&Qresize_root_window_vertically);
6466 Qset = intern_c_string ("set");
6467 staticpro (&Qset);
6469 Qdisplay_buffer = intern_c_string ("display-buffer");
6470 staticpro (&Qdisplay_buffer);
6472 Qreplace_buffer_in_windows = intern_c_string ("replace-buffer-in-windows");
6473 staticpro (&Qreplace_buffer_in_windows);
6475 Qrecord_window_buffer = intern_c_string ("record-window-buffer");
6476 staticpro (&Qrecord_window_buffer);
6478 Qget_mru_window = intern_c_string ("get-mru-window");
6479 staticpro (&Qget_mru_window);
6481 Qtemp_buffer_show_hook = intern_c_string ("temp-buffer-show-hook");
6482 staticpro (&Qtemp_buffer_show_hook);
6484 Qabove = intern_c_string ("above");
6485 staticpro (&Qabove);
6487 Qbelow = intern_c_string ("below");
6488 staticpro (&Qbelow);
6490 Qnest = intern_c_string ("nest");
6491 staticpro (&Qnest);
6493 Qresize = intern_c_string ("resize");
6494 staticpro (&Qresize);
6496 Qgroup = intern_c_string ("group");
6497 staticpro (&Qgroup);
6499 staticpro (&Vwindow_list);
6501 minibuf_selected_window = Qnil;
6502 staticpro (&minibuf_selected_window);
6504 window_scroll_pixel_based_preserve_x = -1;
6505 window_scroll_pixel_based_preserve_y = -1;
6506 window_scroll_preserve_hpos = -1;
6507 window_scroll_preserve_vpos = -1;
6509 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function,
6510 doc: /* Non-nil means call as function to display a help buffer.
6511 The function is called with one argument, the buffer to be displayed.
6512 Used by `with-output-to-temp-buffer'.
6513 If this function is used, then it must do the entire job of showing
6514 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6515 Vtemp_buffer_show_function = Qnil;
6517 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window,
6518 doc: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6519 Vminibuf_scroll_window = Qnil;
6521 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows,
6522 doc: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6523 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6524 is displayed in the `mode-line' face. */);
6525 mode_line_in_non_selected_windows = 1;
6527 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer,
6528 doc: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6529 Vother_window_scroll_buffer = Qnil;
6531 DEFVAR_BOOL ("auto-window-vscroll", &auto_window_vscroll_p,
6532 doc: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
6533 auto_window_vscroll_p = 1;
6535 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines,
6536 doc: /* Number of lines of continuity when scrolling by screenfuls. */);
6537 next_screen_context_lines = 2;
6539 DEFVAR_LISP ("scroll-preserve-screen-position",
6540 &Vscroll_preserve_screen_position,
6541 doc: /* Controls if scroll commands move point to keep its screen position unchanged.
6542 A value of nil means point does not keep its screen position except
6543 at the scroll margin or window boundary respectively.
6544 A value of t means point keeps its screen position if the scroll
6545 command moved it vertically out of the window, e.g. when scrolling
6546 by full screens.
6547 Any other value means point always keeps its screen position.
6548 Scroll commands should have the `scroll-command' property
6549 on their symbols to be controlled by this variable. */);
6550 Vscroll_preserve_screen_position = Qnil;
6552 DEFVAR_LISP ("window-point-insertion-type", &Vwindow_point_insertion_type,
6553 doc: /* Type of marker to use for `window-point'. */);
6554 Vwindow_point_insertion_type = Qnil;
6556 DEFVAR_LISP ("window-configuration-change-hook",
6557 &Vwindow_configuration_change_hook,
6558 doc: /* Functions to call when window configuration changes.
6559 The buffer-local part is run once per window, with the relevant window
6560 selected; while the global part is run only once for the modified frame,
6561 with the relevant frame selected. */);
6562 Vwindow_configuration_change_hook = Qnil;
6564 DEFVAR_LISP ("recenter-redisplay", &Vrecenter_redisplay,
6565 doc: /* If non-nil, then the `recenter' command with a nil argument
6566 will redraw the entire frame; the special value `tty' causes the
6567 frame to be redrawn only if it is a tty frame. */);
6568 Vrecenter_redisplay = Qtty;
6570 DEFVAR_LISP ("window-splits", &Vwindow_splits,
6571 doc: /* Non-nil means splitting windows is handled specially.
6572 If this variable is nil, splitting a window WINDOW will create a new
6573 parent window only if WINDOW has no parent window or WINDOW shall be
6574 split in another direction than the combination WINDOW is part of.
6575 Resizing WINDOW preferably resizes WINDOW's right sibling. Deleting
6576 WINDOW will preferably return space to WINDOW's left sibling.
6578 If this variable equals `nest', splitting WINDOW always creates a new
6579 parent window. Consequently, any frame's window tree is a binary tree
6580 and every window has at most one (left or right) sibling. Resizing
6581 WINDOW will preferably resize WINDOW's sibling. Deleting WINDOW will
6582 preferably return space to WINDOW's sibling.
6584 If this variable equals `resize', splitting, resizing and deleting
6585 WINDOW will try to resize all windows in the same combination as WINDOW
6586 first. This setting allows to split windows that are otherwise too
6587 small or of fixed size. */);
6588 Vwindow_splits = Qnil;
6590 defsubr (&Sselected_window);
6591 defsubr (&Sminibuffer_window);
6592 defsubr (&Swindow_minibuffer_p);
6593 defsubr (&Swindowp);
6594 defsubr (&Swindow_live_p);
6595 defsubr (&Swindow_frame);
6596 defsubr (&Sframe_root_window);
6597 defsubr (&Sframe_first_window);
6598 defsubr (&Sframe_selected_window);
6599 defsubr (&Sset_frame_selected_window);
6600 defsubr (&Spos_visible_in_window_p);
6601 defsubr (&Swindow_line_height);
6602 defsubr (&Swindow_buffer);
6603 defsubr (&Swindow_parent);
6604 defsubr (&Swindow_vchild);
6605 defsubr (&Swindow_hchild);
6606 defsubr (&Swindow_next);
6607 defsubr (&Swindow_prev);
6608 defsubr (&Swindow_use_time);
6609 defsubr (&Swindow_top_line);
6610 defsubr (&Swindow_left_column);
6611 defsubr (&Swindow_total_size);
6612 defsubr (&Swindow_normal_size);
6613 defsubr (&Swindow_new_total_size);
6614 defsubr (&Swindow_new_normal_size);
6615 defsubr (&Sresize_window_total);
6616 defsubr (&Sresize_window_normal);
6617 defsubr (&Sresize_window_apply);
6618 defsubr (&Swindow_body_size);
6619 defsubr (&Swindow_hscroll);
6620 defsubr (&Sset_window_hscroll);
6621 defsubr (&Swindow_redisplay_end_trigger);
6622 defsubr (&Sset_window_redisplay_end_trigger);
6623 defsubr (&Swindow_edges);
6624 defsubr (&Swindow_pixel_edges);
6625 defsubr (&Swindow_absolute_pixel_edges);
6626 defsubr (&Swindow_inside_edges);
6627 defsubr (&Swindow_inside_pixel_edges);
6628 defsubr (&Swindow_inside_absolute_pixel_edges);
6629 defsubr (&Scoordinates_in_window_p);
6630 defsubr (&Swindow_at);
6631 defsubr (&Swindow_point);
6632 defsubr (&Swindow_start);
6633 defsubr (&Swindow_end);
6634 defsubr (&Sset_window_point);
6635 defsubr (&Sset_window_start);
6636 defsubr (&Swindow_dedicated_p);
6637 defsubr (&Sset_window_dedicated_p);
6638 defsubr (&Swindow_display_table);
6639 defsubr (&Sset_window_display_table);
6640 defsubr (&Snext_window);
6641 defsubr (&Sprevious_window);
6642 defsubr (&Sget_buffer_window);
6643 defsubr (&Sdelete_other_windows_internal);
6644 defsubr (&Sdelete_window_internal);
6645 defsubr (&Sresize_mini_window_internal);
6646 defsubr (&Sset_window_buffer);
6647 defsubr (&Srun_window_configuration_change_hook);
6648 defsubr (&Sselect_window);
6649 defsubr (&Sforce_window_update);
6650 defsubr (&Ssplit_window_internal);
6651 defsubr (&Sscroll_up);
6652 defsubr (&Sscroll_down);
6653 defsubr (&Sscroll_left);
6654 defsubr (&Sscroll_right);
6655 defsubr (&Sother_window_for_scrolling);
6656 defsubr (&Sscroll_other_window);
6657 defsubr (&Sminibuffer_selected_window);
6658 defsubr (&Srecenter);
6659 defsubr (&Swindow_text_height);
6660 defsubr (&Smove_to_window_line);
6661 defsubr (&Swindow_configuration_p);
6662 defsubr (&Swindow_configuration_frame);
6663 defsubr (&Sset_window_configuration);
6664 defsubr (&Scurrent_window_configuration);
6665 defsubr (&Ssave_window_excursion);
6666 defsubr (&Sset_window_margins);
6667 defsubr (&Swindow_margins);
6668 defsubr (&Sset_window_fringes);
6669 defsubr (&Swindow_fringes);
6670 defsubr (&Sset_window_scroll_bars);
6671 defsubr (&Swindow_scroll_bars);
6672 defsubr (&Swindow_vscroll);
6673 defsubr (&Sset_window_vscroll);
6674 defsubr (&Scompare_window_configurations);
6675 defsubr (&Swindow_list);
6676 defsubr (&Swindow_list_1);
6677 defsubr (&Swindow_prev_buffers);
6678 defsubr (&Sset_window_prev_buffers);
6679 defsubr (&Swindow_next_buffers);
6680 defsubr (&Sset_window_next_buffers);
6681 defsubr (&Swindow_parameters);
6682 defsubr (&Swindow_parameter);
6683 defsubr (&Sset_window_parameter);
6686 void
6687 keys_of_window (void)
6689 initial_define_key (control_x_map, '<', "scroll-left");
6690 initial_define_key (control_x_map, '>', "scroll-right");
6692 initial_define_key (global_map, Ctl ('V'), "scroll-up-command");
6693 initial_define_key (meta_map, Ctl ('V'), "scroll-other-window");
6694 initial_define_key (meta_map, 'v', "scroll-down-command");
6697 /* arch-tag: 90a9c576-0590-48f1-a5f1-6c96a0452d9f
6698 (do not change this comment) */