Merge from trunk.
[emacs.git] / src / window.c
blob60d17c74de37275def91434beea6489f7e766d41
1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985-1987, 1993-1998, 2000-2011
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 #include <config.h>
22 #include <stdio.h>
23 #include <setjmp.h>
25 #include "lisp.h"
26 #include "buffer.h"
27 #include "keyboard.h"
28 #include "keymap.h"
29 #include "frame.h"
30 #include "window.h"
31 #include "commands.h"
32 #include "indent.h"
33 #include "termchar.h"
34 #include "disptab.h"
35 #include "dispextern.h"
36 #include "blockinput.h"
37 #include "intervals.h"
38 #include "termhooks.h" /* For FRAME_TERMINAL. */
40 #ifdef HAVE_X_WINDOWS
41 #include "xterm.h"
42 #endif /* HAVE_X_WINDOWS */
43 #ifdef WINDOWSNT
44 #include "w32term.h"
45 #endif
46 #ifdef MSDOS
47 #include "msdos.h"
48 #endif
49 #ifdef HAVE_NS
50 #include "nsterm.h"
51 #endif
53 Lisp_Object Qwindowp, Qwindow_live_p;
54 static Lisp_Object Qwindow_configuration_p, Qrecord_window_buffer;
55 static Lisp_Object Qwindow_deletable_p, Qdelete_window, Qdisplay_buffer;
56 static Lisp_Object Qreplace_buffer_in_windows, Qget_mru_window;
57 static Lisp_Object Qwindow_resize_root_window, Qwindow_resize_root_window_vertically;
58 static Lisp_Object Qscroll_up, Qscroll_down, Qscroll_command;
59 static Lisp_Object Qsafe, Qabove, Qbelow;
60 static Lisp_Object Qauto_buffer_name;
62 static int displayed_window_lines (struct window *);
63 static struct window *decode_window (Lisp_Object);
64 static int count_windows (struct window *);
65 static int get_leaf_windows (struct window *, struct window **, int);
66 static void window_scroll (Lisp_Object, EMACS_INT, int, int);
67 static void window_scroll_pixel_based (Lisp_Object, int, int, int);
68 static void window_scroll_line_based (Lisp_Object, int, int, int);
69 static int freeze_window_start (struct window *, void *);
70 static Lisp_Object window_list (void);
71 static int add_window_to_list (struct window *, void *);
72 static int candidate_window_p (Lisp_Object, Lisp_Object, Lisp_Object,
73 Lisp_Object);
74 static Lisp_Object next_window (Lisp_Object, Lisp_Object,
75 Lisp_Object, int);
76 static void decode_next_window_args (Lisp_Object *, Lisp_Object *,
77 Lisp_Object *);
78 static void foreach_window (struct frame *,
79 int (* fn) (struct window *, void *),
80 void *);
81 static int foreach_window_1 (struct window *,
82 int (* fn) (struct window *, void *),
83 void *);
84 static Lisp_Object window_list_1 (Lisp_Object, Lisp_Object, Lisp_Object);
85 static int window_resize_check (struct window *, int);
86 static void window_resize_apply (struct window *, int);
87 static Lisp_Object select_window (Lisp_Object, Lisp_Object, int);
89 /* This is the window in which the terminal's cursor should
90 be left when nothing is being done with it. This must
91 always be a leaf window, and its buffer is selected by
92 the top level editing loop at the end of each command.
94 This value is always the same as
95 FRAME_SELECTED_WINDOW (selected_frame). */
96 Lisp_Object selected_window;
98 /* A list of all windows for use by next_window and Fwindow_list.
99 Functions creating or deleting windows should invalidate this cache
100 by setting it to nil. */
101 Lisp_Object Vwindow_list;
103 /* The mini-buffer window of the selected frame.
104 Note that you cannot test for mini-bufferness of an arbitrary window
105 by comparing against this; but you can test for mini-bufferness of
106 the selected window. */
107 Lisp_Object minibuf_window;
109 /* Non-nil means it is the window whose mode line should be
110 shown as the selected window when the minibuffer is selected. */
111 Lisp_Object minibuf_selected_window;
113 /* Hook run at end of temp_output_buffer_show. */
114 static Lisp_Object Qtemp_buffer_show_hook;
116 /* Incremented for each window created. */
117 static int sequence_number;
119 /* Nonzero after init_window_once has finished. */
120 static int window_initialized;
122 /* Hook to run when window config changes. */
123 static Lisp_Object Qwindow_configuration_change_hook;
125 /* Used by the function window_scroll_pixel_based */
126 static int window_scroll_pixel_based_preserve_x;
127 static int window_scroll_pixel_based_preserve_y;
129 /* Same for window_scroll_line_based. */
130 static EMACS_INT window_scroll_preserve_hpos;
131 static EMACS_INT window_scroll_preserve_vpos;
133 static struct window *
134 decode_window (register Lisp_Object window)
136 if (NILP (window))
137 return XWINDOW (selected_window);
139 CHECK_LIVE_WINDOW (window);
140 return XWINDOW (window);
143 static struct window *
144 decode_any_window (register Lisp_Object window)
146 if (NILP (window))
147 return XWINDOW (selected_window);
149 CHECK_WINDOW (window);
150 return XWINDOW (window);
153 DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0,
154 doc: /* Return t if OBJECT is a window and nil otherwise. */)
155 (Lisp_Object object)
157 return WINDOWP (object) ? Qt : Qnil;
160 DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0,
161 doc: /* Return t if OBJECT is a live window and nil otherwise.
162 A live window is a window that displays a buffer.
163 Internal windows and deleted windows are not live. */)
164 (Lisp_Object object)
166 return WINDOW_LIVE_P (object) ? Qt : Qnil;
169 /* Frames and windows. */
170 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
171 doc: /* Return the frame that window WINDOW is on.
172 If WINDOW is omitted or nil, it defaults to the selected window. */)
173 (Lisp_Object window)
175 return decode_any_window (window)->frame;
178 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
179 doc: /* Return the root window of FRAME-OR-WINDOW.
180 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
181 With a frame argument, return that frame's root window.
182 With a window argument, return the root window of that window's frame. */)
183 (Lisp_Object frame_or_window)
185 Lisp_Object window;
187 if (NILP (frame_or_window))
188 window = SELECTED_FRAME ()->root_window;
189 else if (WINDOWP (frame_or_window))
190 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->root_window;
191 else
193 CHECK_LIVE_FRAME (frame_or_window);
194 window = XFRAME (frame_or_window)->root_window;
197 return window;
200 DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0,
201 doc: /* Return the minibuffer window for frame FRAME.
202 If FRAME is omitted or nil, it defaults to the selected frame. */)
203 (Lisp_Object frame)
205 if (NILP (frame))
206 frame = selected_frame;
207 CHECK_LIVE_FRAME (frame);
208 return FRAME_MINIBUF_WINDOW (XFRAME (frame));
211 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p,
212 Swindow_minibuffer_p, 0, 1, 0,
213 doc: /* Return non-nil if WINDOW is a minibuffer window.
214 If WINDOW is omitted or nil, it defaults to the selected window. */)
215 (Lisp_Object window)
217 return MINI_WINDOW_P (decode_any_window (window)) ? Qt : Qnil;
220 /* Don't move this to window.el - this must be a safe routine. */
221 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
222 doc: /* Return the topmost, leftmost live window on FRAME-OR-WINDOW.
223 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
224 Else if FRAME-OR-WINDOW denotes any window, return the first window of
225 that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
226 the first window of that frame. */)
227 (Lisp_Object frame_or_window)
229 Lisp_Object window;
231 if (NILP (frame_or_window))
232 window = SELECTED_FRAME ()->root_window;
233 else if (WINDOWP (frame_or_window))
234 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->root_window;
235 else
237 CHECK_LIVE_FRAME (frame_or_window);
238 window = XFRAME (frame_or_window)->root_window;
241 while (NILP (XWINDOW (window)->buffer))
243 if (! NILP (XWINDOW (window)->hchild))
244 window = XWINDOW (window)->hchild;
245 else if (! NILP (XWINDOW (window)->vchild))
246 window = XWINDOW (window)->vchild;
247 else
248 abort ();
251 return window;
254 DEFUN ("frame-selected-window", Fframe_selected_window,
255 Sframe_selected_window, 0, 1, 0,
256 doc: /* Return the selected window of FRAME-OR-WINDOW.
257 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
258 Else if FRAME-OR-WINDOW denotes any window, return the selected window
259 of that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
260 the selected window of that frame. */)
261 (Lisp_Object frame_or_window)
263 Lisp_Object window;
265 if (NILP (frame_or_window))
266 window = SELECTED_FRAME ()->selected_window;
267 else if (WINDOWP (frame_or_window))
268 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->selected_window;
269 else
271 CHECK_LIVE_FRAME (frame_or_window);
272 window = XFRAME (frame_or_window)->selected_window;
275 return window;
278 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
279 Sset_frame_selected_window, 2, 3, 0,
280 doc: /* Set selected window of FRAME to WINDOW.
281 FRAME must be a live frame and defaults to the selected one. If FRAME
282 is the selected frame, this makes WINDOW the selected window. Optional
283 argument NORECORD non-nil means to neither change the order of recently
284 selected windows nor the buffer list. WINDOW must denote a live window.
285 Return WINDOW. */)
286 (Lisp_Object frame, Lisp_Object window, Lisp_Object norecord)
288 if (NILP (frame))
289 frame = selected_frame;
291 CHECK_LIVE_FRAME (frame);
292 CHECK_LIVE_WINDOW (window);
294 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
295 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
297 if (EQ (frame, selected_frame))
298 return Fselect_window (window, norecord);
299 else
300 return XFRAME (frame)->selected_window = window;
303 DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0,
304 doc: /* Return the selected window.
305 The selected window is the window in which the standard cursor for
306 selected windows appears and to which many commands apply. */)
307 (void)
309 return selected_window;
312 int window_select_count;
314 /* If select_window is called with inhibit_point_swap non-zero it will
315 not store point of the old selected window's buffer back into that
316 window's pointm slot. This is needed by Fset_window_configuration to
317 avoid that the display routine is called with selected_window set to
318 Qnil causing a subsequent crash. */
319 static Lisp_Object
320 select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
322 register struct window *w;
323 register struct window *ow;
324 struct frame *sf;
326 CHECK_LIVE_WINDOW (window);
328 w = XWINDOW (window);
329 w->frozen_window_start_p = 0;
331 if (NILP (norecord))
333 ++window_select_count;
334 XSETFASTINT (w->use_time, window_select_count);
335 record_buffer (w->buffer);
338 if (EQ (window, selected_window) && !inhibit_point_swap)
339 return window;
341 sf = SELECTED_FRAME ();
342 if (XFRAME (WINDOW_FRAME (w)) != sf)
344 XFRAME (WINDOW_FRAME (w))->selected_window = window;
345 /* Use this rather than Fhandle_switch_frame
346 so that FRAME_FOCUS_FRAME is moved appropriately as we
347 move around in the state where a minibuffer in a separate
348 frame is active. */
349 Fselect_frame (WINDOW_FRAME (w), norecord);
350 /* Fselect_frame called us back so we've done all the work already. */
351 eassert (EQ (window, selected_window));
352 return window;
354 else
355 sf->selected_window = window;
357 /* Store the current buffer's actual point into the
358 old selected window. It belongs to that window,
359 and when the window is not selected, must be in the window. */
360 if (!inhibit_point_swap)
362 ow = XWINDOW (selected_window);
363 if (! NILP (ow->buffer))
364 set_marker_both (ow->pointm, ow->buffer,
365 BUF_PT (XBUFFER (ow->buffer)),
366 BUF_PT_BYTE (XBUFFER (ow->buffer)));
369 selected_window = window;
371 Fset_buffer (w->buffer);
373 BVAR (XBUFFER (w->buffer), last_selected_window) = window;
375 /* Go to the point recorded in the window.
376 This is important when the buffer is in more
377 than one window. It also matters when
378 redisplay_window has altered point after scrolling,
379 because it makes the change only in the window. */
381 register ptrdiff_t new_point = marker_position (w->pointm);
382 if (new_point < BEGV)
383 SET_PT (BEGV);
384 else if (new_point > ZV)
385 SET_PT (ZV);
386 else
387 SET_PT (new_point);
390 windows_or_buffers_changed++;
391 return window;
394 DEFUN ("select-window", Fselect_window, Sselect_window, 1, 2, 0,
395 doc: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
396 Also make WINDOW's buffer current and make WINDOW the frame's selected
397 window. Return WINDOW.
399 Optional second arg NORECORD non-nil means do not put this buffer at the
400 front of the buffer list and do not make this window the most recently
401 selected one.
403 Note that the main editor command loop sets the current buffer to the
404 buffer of the selected window before each command. */)
405 (register Lisp_Object window, Lisp_Object norecord)
407 return select_window (window, norecord, 0);
410 DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0,
411 doc: /* Return the buffer displayed in window WINDOW.
412 If WINDOW is omitted or nil, it defaults to the selected window.
413 Return nil for an internal window or a deleted window. */)
414 (Lisp_Object window)
416 return decode_any_window (window)->buffer;
419 DEFUN ("window-parent", Fwindow_parent, Swindow_parent, 0, 1, 0,
420 doc: /* Return the parent window of window WINDOW.
421 If WINDOW is omitted or nil, it defaults to the selected window.
422 Return nil for a window with no parent (e.g. a root window). */)
423 (Lisp_Object window)
425 return decode_any_window (window)->parent;
428 DEFUN ("window-top-child", Fwindow_top_child, Swindow_top_child, 1, 1, 0,
429 doc: /* Return the topmost child window of window WINDOW.
430 Return nil if WINDOW is a live window (live windows have no children).
431 Return nil if WINDOW is an internal window whose children form a
432 horizontal combination. */)
433 (Lisp_Object window)
435 CHECK_WINDOW (window);
436 return decode_any_window (window)->vchild;
439 DEFUN ("window-left-child", Fwindow_left_child, Swindow_left_child, 1, 1, 0,
440 doc: /* Return the leftmost child window of window WINDOW.
441 Return nil if WINDOW is a live window (live windows have no children).
442 Return nil if WINDOW is an internal window whose children form a
443 vertical combination. */)
444 (Lisp_Object window)
446 CHECK_WINDOW (window);
447 return decode_any_window (window)->hchild;
450 DEFUN ("window-next-sibling", Fwindow_next_sibling, Swindow_next_sibling, 0, 1, 0,
451 doc: /* Return the next sibling window of window WINDOW.
452 If WINDOW is omitted or nil, it defaults to the selected window.
453 Return nil if WINDOW has no next sibling. */)
454 (Lisp_Object window)
456 return decode_any_window (window)->next;
459 DEFUN ("window-prev-sibling", Fwindow_prev_sibling, Swindow_prev_sibling, 0, 1, 0,
460 doc: /* Return the previous sibling window of window WINDOW.
461 If WINDOW is omitted or nil, it defaults to the selected window.
462 Return nil if WINDOW has no previous sibling. */)
463 (Lisp_Object window)
465 return decode_any_window (window)->prev;
468 DEFUN ("window-combination-limit", Fwindow_combination_limit, Swindow_combination_limit, 0, 1, 0,
469 doc: /* Return combination limit of window WINDOW.
470 If WINDOW is omitted or nil, it defaults to the selected window.
472 If the return value is nil, child windows of WINDOW can be recombined with
473 WINDOW's siblings. A return value of t means that child windows of
474 WINDOW are never \(re-)combined with WINDOW's siblings. */)
475 (Lisp_Object window)
477 return decode_any_window (window)->combination_limit;
480 DEFUN ("set-window-combination-limit", Fset_window_combination_limit, Sset_window_combination_limit, 2, 2, 0,
481 doc: /* Set combination limit of window WINDOW to STATUS; return STATUS.
482 If WINDOW is omitted or nil, it defaults to the selected window.
484 If STATUS is nil, child windows of WINDOW can be recombined with
485 WINDOW's siblings. STATUS t means that child windows of WINDOW are
486 never \(re-)combined with WINDOW's siblings. Other values are reserved
487 for future use. */)
488 (Lisp_Object window, Lisp_Object status)
490 register struct window *w = decode_any_window (window);
492 w->combination_limit = status;
494 return w->combination_limit;
497 DEFUN ("window-use-time", Fwindow_use_time, Swindow_use_time, 0, 1, 0,
498 doc: /* Return the use time of window WINDOW.
499 If WINDOW is omitted or nil, it defaults to the selected window.
500 The window with the highest use time is the most recently selected
501 one. The window with the lowest use time is the least recently
502 selected one. */)
503 (Lisp_Object window)
505 return decode_window (window)->use_time;
508 DEFUN ("window-total-height", Fwindow_total_height, Swindow_total_height, 0, 1, 0,
509 doc: /* Return the total height, in lines, of window WINDOW.
510 If WINDOW is omitted or nil, it defaults to the selected window.
512 The return value includes the mode line and header line, if any.
513 If WINDOW is an internal window, the total height is the height
514 of the screen areas spanned by its children.
516 On a graphical display, this total height is reported as an
517 integer multiple of the default character height. */)
518 (Lisp_Object window)
520 return decode_any_window (window)->total_lines;
523 DEFUN ("window-total-width", Fwindow_total_width, Swindow_total_width, 0, 1, 0,
524 doc: /* Return the total width, in columns, of window WINDOW.
525 If WINDOW is omitted or nil, it defaults to the selected window.
527 The return value includes any vertical dividers or scroll bars
528 belonging to WINDOW. If WINDOW is an internal window, the total width
529 is the width of the screen areas spanned by its children.
531 On a graphical display, this total width is reported as an
532 integer multiple of the default character width. */)
533 (Lisp_Object window)
535 return decode_any_window (window)->total_cols;
538 DEFUN ("window-new-total", Fwindow_new_total, Swindow_new_total, 0, 1, 0,
539 doc: /* Return the new total size of window WINDOW.
540 If WINDOW is omitted or nil, it defaults to the selected window. */)
541 (Lisp_Object window)
543 return decode_any_window (window)->new_total;
546 DEFUN ("window-normal-size", Fwindow_normal_size, Swindow_normal_size, 0, 2, 0,
547 doc: /* Return the normal height of window WINDOW.
548 If WINDOW is omitted or nil, it defaults to the selected window.
549 If HORIZONTAL is non-nil, return the normal width of WINDOW. */)
550 (Lisp_Object window, Lisp_Object horizontal)
552 if (NILP (horizontal))
553 return decode_any_window (window)->normal_lines;
554 else
555 return decode_any_window (window)->normal_cols;
558 DEFUN ("window-new-normal", Fwindow_new_normal, Swindow_new_normal, 0, 1, 0,
559 doc: /* Return new normal size of window WINDOW.
560 If WINDOW is omitted or nil, it defaults to the selected window. */)
561 (Lisp_Object window)
563 return decode_any_window (window)->new_normal;
566 DEFUN ("window-left-column", Fwindow_left_column, Swindow_left_column, 0, 1, 0,
567 doc: /* Return left column of window WINDOW.
568 This is the distance, in columns, between the left edge of WINDOW and
569 the left edge of the frame's window area. For instance, the return
570 value is 0 if there is no window to the left of WINDOW.
572 If WINDOW is omitted or nil, it defaults to the selected window. */)
573 (Lisp_Object window)
575 return decode_any_window (window)->left_col;
578 DEFUN ("window-top-line", Fwindow_top_line, Swindow_top_line, 0, 1, 0,
579 doc: /* Return top line of window WINDOW.
580 This is the distance, in lines, between the top of WINDOW and the top
581 of the frame's window area. For instance, the return value is 0 if
582 there is no window above WINDOW.
584 If WINDOW is omitted or nil, it defaults to the selected window. */)
585 (Lisp_Object window)
587 return decode_any_window (window)->top_line;
590 /* Return the number of lines of W's body. Don't count any mode or
591 header line of W. */
593 static int
594 window_body_lines (struct window *w)
596 int height = XFASTINT (w->total_lines);
598 if (!MINI_WINDOW_P (w))
600 if (WINDOW_WANTS_MODELINE_P (w))
601 --height;
602 if (WINDOW_WANTS_HEADER_LINE_P (w))
603 --height;
606 return height;
609 /* Return the number of columns of W's body. Don't count columns
610 occupied by the scroll bar or the vertical bar separating W from its
611 right sibling. On window-systems don't count fringes or display
612 margins either. */
615 window_body_cols (struct window *w)
617 struct frame *f = XFRAME (WINDOW_FRAME (w));
618 int width = XINT (w->total_cols);
620 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
621 /* Scroll bars occupy a few columns. */
622 width -= WINDOW_CONFIG_SCROLL_BAR_COLS (w);
623 else if (!FRAME_WINDOW_P (f)
624 && !WINDOW_RIGHTMOST_P (w) && !WINDOW_FULL_WIDTH_P (w))
625 /* The column of `|' characters separating side-by-side windows
626 occupies one column only. */
627 width -= 1;
629 if (FRAME_WINDOW_P (f))
630 /* On window-systems, fringes and display margins cannot be
631 used for normal text. */
632 width -= (WINDOW_FRINGE_COLS (w)
633 + WINDOW_LEFT_MARGIN_COLS (w)
634 + WINDOW_RIGHT_MARGIN_COLS (w));
636 return width;
639 DEFUN ("window-body-height", Fwindow_body_height, Swindow_body_height, 0, 1, 0,
640 doc: /* Return the height, in lines, of WINDOW's text area.
641 If WINDOW is omitted or nil, it defaults to the selected window.
642 Signal an error if the window is not live.
644 The returned height does not include the mode line or header line.
645 On a graphical display, the height is expressed as an integer multiple
646 of the default character height. If a line at the bottom of the text
647 area is only partially visible, that counts as a whole line; to
648 exclude partially-visible lines, use `window-text-height'. */)
649 (Lisp_Object window)
651 struct window *w = decode_window (window);
652 return make_number (window_body_lines (w));
655 DEFUN ("window-body-width", Fwindow_body_width, Swindow_body_width, 0, 1, 0,
656 doc: /* Return the width, in columns, of WINDOW's text area.
657 If WINDOW is omitted or nil, it defaults to the selected window.
658 Signal an error if the window is not live.
660 The return value does not include any vertical dividers, fringe or
661 marginal areas, or scroll bars. On a graphical display, the width is
662 expressed as an integer multiple of the default character width. */)
663 (Lisp_Object window)
665 struct window *w = decode_window (window);
666 return make_number (window_body_cols (w));
669 DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0,
670 doc: /* Return the number of columns by which WINDOW is scrolled from left margin.
671 WINDOW must be a live window and defaults to the selected one. */)
672 (Lisp_Object window)
674 return decode_window (window)->hscroll;
677 DEFUN ("set-window-hscroll", Fset_window_hscroll, Sset_window_hscroll, 2, 2, 0,
678 doc: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
679 If WINDOW is nil, the selected window is used.
680 Return NCOL. NCOL should be zero or positive.
682 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
683 window so that the location of point moves off-window. */)
684 (Lisp_Object window, Lisp_Object ncol)
686 struct window *w = decode_window (window);
687 ptrdiff_t hscroll;
689 CHECK_NUMBER (ncol);
690 hscroll = clip_to_bounds (0, XINT (ncol), PTRDIFF_MAX);
692 /* Prevent redisplay shortcuts when changing the hscroll. */
693 if (XINT (w->hscroll) != hscroll)
694 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
696 w->hscroll = make_number (hscroll);
697 return ncol;
700 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger,
701 Swindow_redisplay_end_trigger, 0, 1, 0,
702 doc: /* Return WINDOW's redisplay end trigger value.
703 WINDOW defaults to the selected window.
704 See `set-window-redisplay-end-trigger' for more information. */)
705 (Lisp_Object window)
707 return decode_window (window)->redisplay_end_trigger;
710 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger,
711 Sset_window_redisplay_end_trigger, 2, 2, 0,
712 doc: /* Set WINDOW's redisplay end trigger value to VALUE.
713 VALUE should be a buffer position (typically a marker) or nil.
714 If it is a buffer position, then if redisplay in WINDOW reaches a position
715 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
716 with two arguments: WINDOW, and the end trigger value.
717 Afterwards the end-trigger value is reset to nil. */)
718 (register Lisp_Object window, Lisp_Object value)
720 register struct window *w;
722 w = decode_window (window);
723 w->redisplay_end_trigger = value;
724 return value;
727 DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0,
728 doc: /* Return a list of the edge coordinates of WINDOW.
729 The list has the form (LEFT TOP RIGHT BOTTOM).
730 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
731 all relative to 0, 0 at top left corner of frame.
733 RIGHT is one more than the rightmost column occupied by WINDOW.
734 BOTTOM is one more than the bottommost row occupied by WINDOW.
735 The edges include the space used by WINDOW's scroll bar, display
736 margins, fringes, header line, and/or mode line. For the edges of
737 just the text area, use `window-inside-edges'. */)
738 (Lisp_Object window)
740 register struct window *w = decode_any_window (window);
742 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w)),
743 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w)),
744 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w)),
745 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w)),
746 Qnil))));
749 DEFUN ("window-pixel-edges", Fwindow_pixel_edges, Swindow_pixel_edges, 0, 1, 0,
750 doc: /* Return a list of the edge pixel coordinates of WINDOW.
751 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
752 the top left corner of the frame.
754 RIGHT is one more than the rightmost x position occupied by WINDOW.
755 BOTTOM is one more than the bottommost y position occupied by WINDOW.
756 The pixel edges include the space used by WINDOW's scroll bar, display
757 margins, fringes, header line, and/or mode line. For the pixel edges
758 of just the text area, use `window-inside-pixel-edges'. */)
759 (Lisp_Object window)
761 register struct window *w = decode_any_window (window);
763 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w)),
764 Fcons (make_number (WINDOW_TOP_EDGE_Y (w)),
765 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w)),
766 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w)),
767 Qnil))));
770 static void
771 calc_absolute_offset (struct window *w, int *add_x, int *add_y)
773 struct frame *f = XFRAME (w->frame);
774 *add_y = f->top_pos;
775 #ifdef FRAME_MENUBAR_HEIGHT
776 *add_y += FRAME_MENUBAR_HEIGHT (f);
777 #endif
778 #ifdef FRAME_TOOLBAR_TOP_HEIGHT
779 *add_y += FRAME_TOOLBAR_TOP_HEIGHT (f);
780 #elif FRAME_TOOLBAR_HEIGHT
781 *add_y += FRAME_TOOLBAR_HEIGHT (f);
782 #endif
783 #ifdef FRAME_NS_TITLEBAR_HEIGHT
784 *add_y += FRAME_NS_TITLEBAR_HEIGHT (f);
785 #endif
786 *add_x = f->left_pos;
787 #ifdef FRAME_TOOLBAR_LEFT_WIDTH
788 *add_x += FRAME_TOOLBAR_LEFT_WIDTH (f);
789 #endif
792 DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges,
793 Swindow_absolute_pixel_edges, 0, 1, 0,
794 doc: /* Return a list of the edge pixel coordinates of WINDOW.
795 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
796 the top left corner of the display.
798 RIGHT is one more than the rightmost x position occupied by WINDOW.
799 BOTTOM is one more than the bottommost y position occupied by WINDOW.
800 The pixel edges include the space used by WINDOW's scroll bar, display
801 margins, fringes, header line, and/or mode line. For the pixel edges
802 of just the text area, use `window-inside-absolute-pixel-edges'. */)
803 (Lisp_Object window)
805 register struct window *w = decode_any_window (window);
806 int add_x, add_y;
807 calc_absolute_offset (w, &add_x, &add_y);
809 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w) + add_x),
810 Fcons (make_number (WINDOW_TOP_EDGE_Y (w) + add_y),
811 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w) + add_x),
812 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w) + add_y),
813 Qnil))));
816 DEFUN ("window-inside-edges", Fwindow_inside_edges, Swindow_inside_edges, 0, 1, 0,
817 doc: /* Return a list of the edge coordinates of WINDOW.
818 The list has the form (LEFT TOP RIGHT BOTTOM).
819 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
820 all relative to 0, 0 at top left corner of frame.
822 RIGHT is one more than the rightmost column of WINDOW's text area.
823 BOTTOM is one more than the bottommost row of WINDOW's text area.
824 The inside edges do not include the space used by the WINDOW's scroll
825 bar, display margins, fringes, header line, and/or mode line. */)
826 (Lisp_Object window)
828 register struct window *w = decode_window (window);
830 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w)
831 + WINDOW_LEFT_MARGIN_COLS (w)
832 + WINDOW_LEFT_FRINGE_COLS (w)),
833 make_number (WINDOW_TOP_EDGE_LINE (w)
834 + WINDOW_HEADER_LINE_LINES (w)),
835 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w)
836 - WINDOW_RIGHT_MARGIN_COLS (w)
837 - WINDOW_RIGHT_FRINGE_COLS (w)),
838 make_number (WINDOW_BOTTOM_EDGE_LINE (w)
839 - WINDOW_MODE_LINE_LINES (w)));
842 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges, Swindow_inside_pixel_edges, 0, 1, 0,
843 doc: /* Return a list of the edge pixel coordinates of WINDOW's text area.
844 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to (0,0)
845 at the top left corner of the frame's window area.
847 RIGHT is one more than the rightmost x position of WINDOW's text area.
848 BOTTOM is one more than the bottommost y position of WINDOW's text area.
849 The inside edges do not include the space used by WINDOW's scroll bar,
850 display margins, fringes, header line, and/or mode line. */)
851 (Lisp_Object window)
853 register struct window *w = decode_window (window);
855 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w)
856 + WINDOW_LEFT_MARGIN_WIDTH (w)
857 + WINDOW_LEFT_FRINGE_WIDTH (w)),
858 make_number (WINDOW_TOP_EDGE_Y (w)
859 + WINDOW_HEADER_LINE_HEIGHT (w)),
860 make_number (WINDOW_BOX_RIGHT_EDGE_X (w)
861 - WINDOW_RIGHT_MARGIN_WIDTH (w)
862 - WINDOW_RIGHT_FRINGE_WIDTH (w)),
863 make_number (WINDOW_BOTTOM_EDGE_Y (w)
864 - WINDOW_MODE_LINE_HEIGHT (w)));
867 DEFUN ("window-inside-absolute-pixel-edges",
868 Fwindow_inside_absolute_pixel_edges,
869 Swindow_inside_absolute_pixel_edges, 0, 1, 0,
870 doc: /* Return a list of the edge pixel coordinates of WINDOW's text area.
871 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to (0,0)
872 at the top left corner of the frame's window area.
874 RIGHT is one more than the rightmost x position of WINDOW's text area.
875 BOTTOM is one more than the bottommost y position of WINDOW's text area.
876 The inside edges do not include the space used by WINDOW's scroll bar,
877 display margins, fringes, header line, and/or mode line. */)
878 (Lisp_Object window)
880 register struct window *w = decode_window (window);
881 int add_x, add_y;
882 calc_absolute_offset (w, &add_x, &add_y);
884 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w)
885 + WINDOW_LEFT_MARGIN_WIDTH (w)
886 + WINDOW_LEFT_FRINGE_WIDTH (w) + add_x),
887 make_number (WINDOW_TOP_EDGE_Y (w)
888 + WINDOW_HEADER_LINE_HEIGHT (w) + add_y),
889 make_number (WINDOW_BOX_RIGHT_EDGE_X (w)
890 - WINDOW_RIGHT_MARGIN_WIDTH (w)
891 - WINDOW_RIGHT_FRINGE_WIDTH (w) + add_x),
892 make_number (WINDOW_BOTTOM_EDGE_Y (w)
893 - WINDOW_MODE_LINE_HEIGHT (w) + add_y));
896 /* Test if the character at column X, row Y is within window W.
897 If it is not, return ON_NOTHING;
898 if it is in the window's text area, return ON_TEXT;
899 if it is on the window's modeline, return ON_MODE_LINE;
900 if it is on the border between the window and its right sibling,
901 return ON_VERTICAL_BORDER.
902 if it is on a scroll bar, return ON_SCROLL_BAR.
903 if it is on the window's top line, return ON_HEADER_LINE;
904 if it is in left or right fringe of the window,
905 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
906 if it is in the marginal area to the left/right of the window,
907 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN.
909 X and Y are frame relative pixel coordinates. */
911 static enum window_part
912 coordinates_in_window (register struct window *w, int x, int y)
914 struct frame *f = XFRAME (WINDOW_FRAME (w));
915 enum window_part part;
916 int ux = FRAME_COLUMN_WIDTH (f);
917 int left_x = WINDOW_LEFT_EDGE_X (w);
918 int right_x = WINDOW_RIGHT_EDGE_X (w);
919 int top_y = WINDOW_TOP_EDGE_Y (w);
920 int bottom_y = WINDOW_BOTTOM_EDGE_Y (w);
921 /* The width of the area where the vertical line can be dragged.
922 (Between mode lines for instance. */
923 int grabbable_width = ux;
924 int lmargin_width, rmargin_width, text_left, text_right;
926 /* Outside any interesting row or column? */
927 if (y < top_y || y >= bottom_y || x < left_x || x >= right_x)
928 return ON_NOTHING;
930 /* On the mode line or header line? */
931 if ((WINDOW_WANTS_MODELINE_P (w)
932 && y >= bottom_y - CURRENT_MODE_LINE_HEIGHT (w)
933 && (part = ON_MODE_LINE))
934 || (WINDOW_WANTS_HEADER_LINE_P (w)
935 && y < top_y + CURRENT_HEADER_LINE_HEIGHT (w)
936 && (part = ON_HEADER_LINE)))
938 /* If it's under/over the scroll bar portion of the mode/header
939 line, say it's on the vertical line. That's to be able to
940 resize windows horizontally in case we're using toolkit scroll
941 bars. Note: If scrollbars are on the left, the window that
942 must be eventually resized is that on the left of WINDOW. */
943 if ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)
944 && !WINDOW_LEFTMOST_P (w)
945 && eabs (x - left_x) < grabbable_width)
946 || (!WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)
947 && !WINDOW_RIGHTMOST_P (w)
948 && eabs (x - right_x) < grabbable_width))
949 return ON_VERTICAL_BORDER;
950 else
951 return part;
954 /* In what's below, we subtract 1 when computing right_x because we
955 want the rightmost pixel, which is given by left_pixel+width-1. */
956 if (w->pseudo_window_p)
958 left_x = 0;
959 right_x = WINDOW_TOTAL_WIDTH (w) - 1;
961 else
963 left_x = WINDOW_BOX_LEFT_EDGE_X (w);
964 right_x = WINDOW_BOX_RIGHT_EDGE_X (w) - 1;
967 /* Outside any interesting column? */
968 if (x < left_x || x > right_x)
969 return ON_SCROLL_BAR;
971 lmargin_width = window_box_width (w, LEFT_MARGIN_AREA);
972 rmargin_width = window_box_width (w, RIGHT_MARGIN_AREA);
974 text_left = window_box_left (w, TEXT_AREA);
975 text_right = text_left + window_box_width (w, TEXT_AREA);
977 if (FRAME_WINDOW_P (f))
979 if (!w->pseudo_window_p
980 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w)
981 && !WINDOW_RIGHTMOST_P (w)
982 && (eabs (x - right_x) < grabbable_width))
983 return ON_VERTICAL_BORDER;
985 /* Need to say "x > right_x" rather than >=, since on character
986 terminals, the vertical line's x coordinate is right_x. */
987 else if (!w->pseudo_window_p
988 && !WINDOW_RIGHTMOST_P (w)
989 && x > right_x - ux)
990 return ON_VERTICAL_BORDER;
992 if (x < text_left)
994 if (lmargin_width > 0
995 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
996 ? (x >= left_x + WINDOW_LEFT_FRINGE_WIDTH (w))
997 : (x < left_x + lmargin_width)))
998 return ON_LEFT_MARGIN;
1000 return ON_LEFT_FRINGE;
1003 if (x >= text_right)
1005 if (rmargin_width > 0
1006 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
1007 ? (x < right_x - WINDOW_RIGHT_FRINGE_WIDTH (w))
1008 : (x >= right_x - rmargin_width)))
1009 return ON_RIGHT_MARGIN;
1011 return ON_RIGHT_FRINGE;
1014 /* Everything special ruled out - must be on text area */
1015 return ON_TEXT;
1018 /* Take X is the frame-relative pixel x-coordinate, and return the
1019 x-coordinate relative to part PART of window W. */
1021 window_relative_x_coord (struct window *w, enum window_part part, int x)
1023 int left_x = (w->pseudo_window_p) ? 0 : WINDOW_BOX_LEFT_EDGE_X (w);
1025 switch (part)
1027 case ON_TEXT:
1028 return x - window_box_left (w, TEXT_AREA);
1030 case ON_LEFT_FRINGE:
1031 return x - left_x;
1033 case ON_RIGHT_FRINGE:
1034 return x - left_x - WINDOW_LEFT_FRINGE_WIDTH (w);
1036 case ON_LEFT_MARGIN:
1037 return (x - left_x
1038 - ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
1039 ? WINDOW_LEFT_FRINGE_WIDTH (w) : 0));
1041 case ON_RIGHT_MARGIN:
1042 return (x + 1
1043 - ((w->pseudo_window_p)
1044 ? WINDOW_TOTAL_WIDTH (w)
1045 : WINDOW_BOX_RIGHT_EDGE_X (w))
1046 + window_box_width (w, RIGHT_MARGIN_AREA)
1047 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
1048 ? WINDOW_RIGHT_FRINGE_WIDTH (w) : 0));
1051 /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */
1052 return 0;
1056 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
1057 Scoordinates_in_window_p, 2, 2, 0,
1058 doc: /* Return non-nil if COORDINATES are in WINDOW.
1059 COORDINATES is a cons of the form (X . Y), X and Y being distances
1060 measured in characters from the upper-left corner of the frame.
1061 \(0 . 0) denotes the character in the upper left corner of the
1062 frame.
1063 If COORDINATES are in the text portion of WINDOW,
1064 the coordinates relative to the window are returned.
1065 If they are in the mode line of WINDOW, `mode-line' is returned.
1066 If they are in the top mode line of WINDOW, `header-line' is returned.
1067 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1068 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1069 If they are on the border between WINDOW and its right sibling,
1070 `vertical-line' is returned.
1071 If they are in the windows's left or right marginal areas, `left-margin'\n\
1072 or `right-margin' is returned. */)
1073 (register Lisp_Object coordinates, Lisp_Object window)
1075 struct window *w;
1076 struct frame *f;
1077 int x, y;
1078 Lisp_Object lx, ly;
1080 CHECK_WINDOW (window);
1081 w = XWINDOW (window);
1082 f = XFRAME (w->frame);
1083 CHECK_CONS (coordinates);
1084 lx = Fcar (coordinates);
1085 ly = Fcdr (coordinates);
1086 CHECK_NUMBER_OR_FLOAT (lx);
1087 CHECK_NUMBER_OR_FLOAT (ly);
1088 x = FRAME_PIXEL_X_FROM_CANON_X (f, lx) + FRAME_INTERNAL_BORDER_WIDTH (f);
1089 y = FRAME_PIXEL_Y_FROM_CANON_Y (f, ly) + FRAME_INTERNAL_BORDER_WIDTH (f);
1091 switch (coordinates_in_window (w, x, y))
1093 case ON_NOTHING:
1094 return Qnil;
1096 case ON_TEXT:
1097 /* Convert X and Y to window relative pixel coordinates, and
1098 return the canonical char units. */
1099 x -= window_box_left (w, TEXT_AREA);
1100 y -= WINDOW_TOP_EDGE_Y (w);
1101 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f, x),
1102 FRAME_CANON_Y_FROM_PIXEL_Y (f, y));
1104 case ON_MODE_LINE:
1105 return Qmode_line;
1107 case ON_VERTICAL_BORDER:
1108 return Qvertical_line;
1110 case ON_HEADER_LINE:
1111 return Qheader_line;
1113 case ON_LEFT_FRINGE:
1114 return Qleft_fringe;
1116 case ON_RIGHT_FRINGE:
1117 return Qright_fringe;
1119 case ON_LEFT_MARGIN:
1120 return Qleft_margin;
1122 case ON_RIGHT_MARGIN:
1123 return Qright_margin;
1125 case ON_SCROLL_BAR:
1126 /* Historically we are supposed to return nil in this case. */
1127 return Qnil;
1129 default:
1130 abort ();
1135 /* Callback for foreach_window, used in window_from_coordinates.
1136 Check if window W contains coordinates specified by USER_DATA which
1137 is actually a pointer to a struct check_window_data CW.
1139 Check if window W contains coordinates *CW->x and *CW->y. If it
1140 does, return W in *CW->window, as Lisp_Object, and return in
1141 *CW->part the part of the window under coordinates *X,*Y. Return
1142 zero from this function to stop iterating over windows. */
1144 struct check_window_data
1146 Lisp_Object *window;
1147 int x, y;
1148 enum window_part *part;
1151 static int
1152 check_window_containing (struct window *w, void *user_data)
1154 struct check_window_data *cw = (struct check_window_data *) user_data;
1155 enum window_part found;
1156 int continue_p = 1;
1158 found = coordinates_in_window (w, cw->x, cw->y);
1159 if (found != ON_NOTHING)
1161 *cw->part = found;
1162 XSETWINDOW (*cw->window, w);
1163 continue_p = 0;
1166 return continue_p;
1170 /* Find the window containing frame-relative pixel position X/Y and
1171 return it as a Lisp_Object.
1173 If X, Y is on one of the window's special `window_part' elements,
1174 set *PART to the id of that element.
1176 If there is no window under X, Y return nil and leave *PART
1177 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1179 This function was previously implemented with a loop cycling over
1180 windows with Fnext_window, and starting with the frame's selected
1181 window. It turned out that this doesn't work with an
1182 implementation of next_window using Vwindow_list, because
1183 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1184 tree of F when this function is called asynchronously from
1185 note_mouse_highlight. The original loop didn't terminate in this
1186 case. */
1188 Lisp_Object
1189 window_from_coordinates (struct frame *f, int x, int y,
1190 enum window_part *part, int tool_bar_p)
1192 Lisp_Object window;
1193 struct check_window_data cw;
1194 enum window_part dummy;
1196 if (part == 0)
1197 part = &dummy;
1199 window = Qnil;
1200 cw.window = &window, cw.x = x, cw.y = y; cw.part = part;
1201 foreach_window (f, check_window_containing, &cw);
1203 /* If not found above, see if it's in the tool bar window, if a tool
1204 bar exists. */
1205 if (NILP (window)
1206 && tool_bar_p
1207 && WINDOWP (f->tool_bar_window)
1208 && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window)) > 0
1209 && (coordinates_in_window (XWINDOW (f->tool_bar_window), x, y)
1210 != ON_NOTHING))
1212 *part = ON_TEXT;
1213 window = f->tool_bar_window;
1216 return window;
1219 DEFUN ("window-at", Fwindow_at, Swindow_at, 2, 3, 0,
1220 doc: /* Return window containing coordinates X and Y on FRAME.
1221 FRAME must be a live frame and defaults to the selected one.
1222 The top left corner of the frame is considered to be row 0,
1223 column 0. */)
1224 (Lisp_Object x, Lisp_Object y, Lisp_Object frame)
1226 struct frame *f;
1228 if (NILP (frame))
1229 frame = selected_frame;
1230 CHECK_LIVE_FRAME (frame);
1231 f = XFRAME (frame);
1233 /* Check that arguments are integers or floats. */
1234 CHECK_NUMBER_OR_FLOAT (x);
1235 CHECK_NUMBER_OR_FLOAT (y);
1237 return window_from_coordinates (f,
1238 (FRAME_PIXEL_X_FROM_CANON_X (f, x)
1239 + FRAME_INTERNAL_BORDER_WIDTH (f)),
1240 (FRAME_PIXEL_Y_FROM_CANON_Y (f, y)
1241 + FRAME_INTERNAL_BORDER_WIDTH (f)),
1242 0, 0);
1245 DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0,
1246 doc: /* Return current value of point in WINDOW.
1247 WINDOW must be a live window and defaults to the selected one.
1249 For a nonselected window, this is the value point would have
1250 if that window were selected.
1252 Note that, when WINDOW is the selected window and its buffer
1253 is also currently selected, the value returned is the same as (point).
1254 It would be more strictly correct to return the `top-level' value
1255 of point, outside of any save-excursion forms.
1256 But that is hard to define. */)
1257 (Lisp_Object window)
1259 register struct window *w = decode_window (window);
1261 if (w == XWINDOW (selected_window)
1262 && current_buffer == XBUFFER (w->buffer))
1263 return Fpoint ();
1264 return Fmarker_position (w->pointm);
1267 DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0,
1268 doc: /* Return position at which display currently starts in WINDOW.
1269 WINDOW must be a live window and defaults to the selected one.
1270 This is updated by redisplay or by calling `set-window-start'. */)
1271 (Lisp_Object window)
1273 return Fmarker_position (decode_window (window)->start);
1276 /* This is text temporarily removed from the doc string below.
1278 This function returns nil if the position is not currently known.
1279 That happens when redisplay is preempted and doesn't finish.
1280 If in that case you want to compute where the end of the window would
1281 have been if redisplay had finished, do this:
1282 (save-excursion
1283 (goto-char (window-start window))
1284 (vertical-motion (1- (window-height window)) window)
1285 (point))") */
1287 DEFUN ("window-end", Fwindow_end, Swindow_end, 0, 2, 0,
1288 doc: /* Return position at which display currently ends in WINDOW.
1289 WINDOW must be a live window and defaults to the selected one.
1290 This is updated by redisplay, when it runs to completion.
1291 Simply changing the buffer text or setting `window-start'
1292 does not update this value.
1293 Return nil if there is no recorded value. (This can happen if the
1294 last redisplay of WINDOW was preempted, and did not finish.)
1295 If UPDATE is non-nil, compute the up-to-date position
1296 if it isn't already recorded. */)
1297 (Lisp_Object window, Lisp_Object update)
1299 Lisp_Object value;
1300 struct window *w = decode_window (window);
1301 Lisp_Object buf;
1302 struct buffer *b;
1304 buf = w->buffer;
1305 CHECK_BUFFER (buf);
1306 b = XBUFFER (buf);
1308 #if 0 /* This change broke some things. We should make it later. */
1309 /* If we don't know the end position, return nil.
1310 The user can compute it with vertical-motion if he wants to.
1311 It would be nicer to do it automatically,
1312 but that's so slow that it would probably bother people. */
1313 if (NILP (w->window_end_valid))
1314 return Qnil;
1315 #endif
1317 if (! NILP (update)
1318 && ! (! NILP (w->window_end_valid)
1319 && XFASTINT (w->last_modified) >= BUF_MODIFF (b)
1320 && XFASTINT (w->last_overlay_modified) >= BUF_OVERLAY_MODIFF (b))
1321 && !noninteractive)
1323 struct text_pos startp;
1324 struct it it;
1325 struct buffer *old_buffer = NULL;
1326 void *itdata = NULL;
1328 /* Cannot use Fvertical_motion because that function doesn't
1329 cope with variable-height lines. */
1330 if (b != current_buffer)
1332 old_buffer = current_buffer;
1333 set_buffer_internal (b);
1336 /* In case W->start is out of the range, use something
1337 reasonable. This situation occurred when loading a file with
1338 `-l' containing a call to `rmail' with subsequent other
1339 commands. At the end, W->start happened to be BEG, while
1340 rmail had already narrowed the buffer. */
1341 if (XMARKER (w->start)->charpos < BEGV)
1342 SET_TEXT_POS (startp, BEGV, BEGV_BYTE);
1343 else if (XMARKER (w->start)->charpos > ZV)
1344 SET_TEXT_POS (startp, ZV, ZV_BYTE);
1345 else
1346 SET_TEXT_POS_FROM_MARKER (startp, w->start);
1348 itdata = bidi_shelve_cache ();
1349 start_display (&it, w, startp);
1350 move_it_vertically (&it, window_box_height (w));
1351 if (it.current_y < it.last_visible_y)
1352 move_it_past_eol (&it);
1353 value = make_number (IT_CHARPOS (it));
1354 bidi_unshelve_cache (itdata, 0);
1356 if (old_buffer)
1357 set_buffer_internal (old_buffer);
1359 else
1360 XSETINT (value, BUF_Z (b) - XFASTINT (w->window_end_pos));
1362 return value;
1365 DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0,
1366 doc: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1367 Return POS. */)
1368 (Lisp_Object window, Lisp_Object pos)
1370 register struct window *w = decode_window (window);
1372 CHECK_NUMBER_COERCE_MARKER (pos);
1373 if (w == XWINDOW (selected_window)
1374 && XBUFFER (w->buffer) == current_buffer)
1375 Fgoto_char (pos);
1376 else
1377 set_marker_restricted (w->pointm, pos, w->buffer);
1379 /* We have to make sure that redisplay updates the window to show
1380 the new value of point. */
1381 if (!EQ (window, selected_window))
1382 ++windows_or_buffers_changed;
1384 return pos;
1387 DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0,
1388 doc: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1389 If WINDOW is nil, the selected window is used. Return POS.
1390 Optional third arg NOFORCE non-nil inhibits next redisplay from
1391 overriding motion of point in order to display at this exact start. */)
1392 (Lisp_Object window, Lisp_Object pos, Lisp_Object noforce)
1394 register struct window *w = decode_window (window);
1396 CHECK_NUMBER_COERCE_MARKER (pos);
1397 set_marker_restricted (w->start, pos, w->buffer);
1398 /* this is not right, but much easier than doing what is right. */
1399 w->start_at_line_beg = Qnil;
1400 if (NILP (noforce))
1401 w->force_start = Qt;
1402 w->update_mode_line = Qt;
1403 XSETFASTINT (w->last_modified, 0);
1404 XSETFASTINT (w->last_overlay_modified, 0);
1405 if (!EQ (window, selected_window))
1406 windows_or_buffers_changed++;
1408 return pos;
1411 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p,
1412 Spos_visible_in_window_p, 0, 3, 0,
1413 doc: /* Return non-nil if position POS is currently on the frame in WINDOW.
1414 Return nil if that position is scrolled vertically out of view.
1415 If a character is only partially visible, nil is returned, unless the
1416 optional argument PARTIALLY is non-nil.
1417 If POS is only out of view because of horizontal scrolling, return non-nil.
1418 If POS is t, it specifies the position of the last visible glyph in WINDOW.
1419 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
1421 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1422 return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
1423 where X and Y are the pixel coordinates relative to the top left corner
1424 of the window. The remaining elements are omitted if the character after
1425 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1426 off-window at the top and bottom of the row, ROWH is the height of the
1427 display row, and VPOS is the row number (0-based) containing POS. */)
1428 (Lisp_Object pos, Lisp_Object window, Lisp_Object partially)
1430 register struct window *w;
1431 register EMACS_INT posint;
1432 register struct buffer *buf;
1433 struct text_pos top;
1434 Lisp_Object in_window = Qnil;
1435 int rtop, rbot, rowh, vpos, fully_p = 1;
1436 int x, y;
1438 w = decode_window (window);
1439 buf = XBUFFER (w->buffer);
1440 SET_TEXT_POS_FROM_MARKER (top, w->start);
1442 if (EQ (pos, Qt))
1443 posint = -1;
1444 else if (!NILP (pos))
1446 CHECK_NUMBER_COERCE_MARKER (pos);
1447 posint = XINT (pos);
1449 else if (w == XWINDOW (selected_window))
1450 posint = PT;
1451 else
1452 posint = XMARKER (w->pointm)->charpos;
1454 /* If position is above window start or outside buffer boundaries,
1455 or if window start is out of range, position is not visible. */
1456 if ((EQ (pos, Qt)
1457 || (posint >= CHARPOS (top) && posint <= BUF_ZV (buf)))
1458 && CHARPOS (top) >= BUF_BEGV (buf)
1459 && CHARPOS (top) <= BUF_ZV (buf)
1460 && pos_visible_p (w, posint, &x, &y, &rtop, &rbot, &rowh, &vpos)
1461 && (fully_p = !rtop && !rbot, (!NILP (partially) || fully_p)))
1462 in_window = Qt;
1464 if (!NILP (in_window) && !NILP (partially))
1466 Lisp_Object part = Qnil;
1467 if (!fully_p)
1468 part = list4 (make_number (rtop), make_number (rbot),
1469 make_number (rowh), make_number (vpos));
1470 in_window = Fcons (make_number (x),
1471 Fcons (make_number (y), part));
1474 return in_window;
1477 DEFUN ("window-line-height", Fwindow_line_height,
1478 Swindow_line_height, 0, 2, 0,
1479 doc: /* Return height in pixels of text line LINE in window WINDOW.
1480 WINDOW defaults to the selected window.
1482 Return height of current line if LINE is omitted or nil. Return height of
1483 header or mode line if LINE is `header-line' or `mode-line'.
1484 Otherwise, LINE is a text line number starting from 0. A negative number
1485 counts from the end of the window.
1487 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
1488 in pixels of the visible part of the line, VPOS and YPOS are the
1489 vertical position in lines and pixels of the line, relative to the top
1490 of the first text line, and OFFBOT is the number of off-window pixels at
1491 the bottom of the text line. If there are off-window pixels at the top
1492 of the (first) text line, YPOS is negative.
1494 Return nil if window display is not up-to-date. In that case, use
1495 `pos-visible-in-window-p' to obtain the information. */)
1496 (Lisp_Object line, Lisp_Object window)
1498 register struct window *w;
1499 register struct buffer *b;
1500 struct glyph_row *row, *end_row;
1501 int max_y, crop, i;
1502 EMACS_INT n;
1504 w = decode_window (window);
1506 if (noninteractive || w->pseudo_window_p)
1507 return Qnil;
1509 CHECK_BUFFER (w->buffer);
1510 b = XBUFFER (w->buffer);
1512 /* Fail if current matrix is not up-to-date. */
1513 if (NILP (w->window_end_valid)
1514 || current_buffer->clip_changed
1515 || current_buffer->prevent_redisplay_optimizations_p
1516 || XFASTINT (w->last_modified) < BUF_MODIFF (b)
1517 || XFASTINT (w->last_overlay_modified) < BUF_OVERLAY_MODIFF (b))
1518 return Qnil;
1520 if (NILP (line))
1522 i = w->cursor.vpos;
1523 if (i < 0 || i >= w->current_matrix->nrows
1524 || (row = MATRIX_ROW (w->current_matrix, i), !row->enabled_p))
1525 return Qnil;
1526 max_y = window_text_bottom_y (w);
1527 goto found_row;
1530 if (EQ (line, Qheader_line))
1532 if (!WINDOW_WANTS_HEADER_LINE_P (w))
1533 return Qnil;
1534 row = MATRIX_HEADER_LINE_ROW (w->current_matrix);
1535 if (!row->enabled_p)
1536 return Qnil;
1537 return list4 (make_number (row->height),
1538 make_number (0), make_number (0),
1539 make_number (0));
1542 if (EQ (line, Qmode_line))
1544 row = MATRIX_MODE_LINE_ROW (w->current_matrix);
1545 if (!row->enabled_p)
1546 return Qnil;
1547 return list4 (make_number (row->height),
1548 make_number (0), /* not accurate */
1549 make_number (WINDOW_HEADER_LINE_HEIGHT (w)
1550 + window_text_bottom_y (w)),
1551 make_number (0));
1554 CHECK_NUMBER (line);
1555 n = XINT (line);
1557 row = MATRIX_FIRST_TEXT_ROW (w->current_matrix);
1558 end_row = MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w);
1559 max_y = window_text_bottom_y (w);
1560 i = 0;
1562 while ((n < 0 || i < n)
1563 && row <= end_row && row->enabled_p
1564 && row->y + row->height < max_y)
1565 row++, i++;
1567 if (row > end_row || !row->enabled_p)
1568 return Qnil;
1570 if (++n < 0)
1572 if (-n > i)
1573 return Qnil;
1574 row += n;
1575 i += n;
1578 found_row:
1579 crop = max (0, (row->y + row->height) - max_y);
1580 return list4 (make_number (row->height + min (0, row->y) - crop),
1581 make_number (i),
1582 make_number (row->y),
1583 make_number (crop));
1586 DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p,
1587 0, 1, 0,
1588 doc: /* Return non-nil when WINDOW is dedicated to its buffer.
1589 More precisely, return the value assigned by the last call of
1590 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1591 never called with WINDOW as its argument, or the value set by that
1592 function was internally reset since its last call. WINDOW defaults to
1593 the selected window.
1595 When a window is dedicated to its buffer, `display-buffer' will refrain
1596 from displaying another buffer in it. `get-lru-window' and
1597 `get-largest-window' treat dedicated windows specially.
1598 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1599 `kill-buffer' can delete a dedicated window and the containing frame.
1601 Functions like `set-window-buffer' may change the buffer displayed by a
1602 window, unless that window is "strongly" dedicated to its buffer, that
1603 is the value returned by `window-dedicated-p' is t. */)
1604 (Lisp_Object window)
1606 return decode_window (window)->dedicated;
1609 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p,
1610 Sset_window_dedicated_p, 2, 2, 0,
1611 doc: /* Mark WINDOW as dedicated according to FLAG.
1612 WINDOW must be a live window and defaults to the selected one. FLAG
1613 non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means
1614 mark WINDOW as non-dedicated. Return FLAG.
1616 When a window is dedicated to its buffer, `display-buffer' will refrain
1617 from displaying another buffer in it. `get-lru-window' and
1618 `get-largest-window' treat dedicated windows specially.
1619 `delete-windows-on', `replace-buffer-in-windows', `quit-window',
1620 `quit-restore-window' and `kill-buffer' can delete a dedicated window
1621 and the containing frame.
1623 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
1624 its buffer. Functions like `set-window-buffer' may change the buffer
1625 displayed by a window, unless that window is strongly dedicated to its
1626 buffer. If and when `set-window-buffer' displays another buffer in a
1627 window, it also makes sure that the window is no more dedicated. */)
1628 (Lisp_Object window, Lisp_Object flag)
1630 register struct window *w = decode_window (window);
1632 w->dedicated = flag;
1633 return w->dedicated;
1636 DEFUN ("window-prev-buffers", Fwindow_prev_buffers, Swindow_prev_buffers,
1637 0, 1, 0,
1638 doc: /* Return buffers previously shown in WINDOW.
1639 WINDOW must be a live window and defaults to the selected one.
1641 The return value is a list of elements (BUFFER WINDOW-START POS),
1642 where BUFFER is a buffer, WINDOW-START is the start position of the
1643 window for that buffer, and POS is a window-specific point value. */)
1644 (Lisp_Object window)
1646 return decode_window (window)->prev_buffers;
1649 DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers,
1650 Sset_window_prev_buffers, 2, 2, 0,
1651 doc: /* Set WINDOW's previous buffers to PREV-BUFFERS.
1652 WINDOW must be a live window and defaults to the selected one.
1654 PREV-BUFFERS should be a list of elements (BUFFER WINDOW-START POS),
1655 where BUFFER is a buffer, WINDOW-START is the start position of the
1656 window for that buffer, and POS is a window-specific point value. */)
1657 (Lisp_Object window, Lisp_Object prev_buffers)
1659 return decode_window (window)->prev_buffers = prev_buffers;
1662 DEFUN ("window-next-buffers", Fwindow_next_buffers, Swindow_next_buffers,
1663 0, 1, 0,
1664 doc: /* Return list of buffers recently re-shown in WINDOW.
1665 WINDOW must be a live window and defaults to the selected one. */)
1666 (Lisp_Object window)
1668 return decode_window (window)->next_buffers;
1671 DEFUN ("set-window-next-buffers", Fset_window_next_buffers,
1672 Sset_window_next_buffers, 2, 2, 0,
1673 doc: /* Set WINDOW's next buffers to NEXT-BUFFERS.
1674 WINDOW must be a live window and defaults to the selected one.
1675 NEXT-BUFFERS should be a list of buffers. */)
1676 (Lisp_Object window, Lisp_Object next_buffers)
1678 return decode_window (window)->next_buffers = next_buffers;
1681 DEFUN ("window-parameters", Fwindow_parameters, Swindow_parameters,
1682 0, 1, 0,
1683 doc: /* Return the parameters of WINDOW and their values.
1684 WINDOW defaults to the selected window. The return value is a list of
1685 elements of the form (PARAMETER . VALUE). */)
1686 (Lisp_Object window)
1688 return Fcopy_alist (decode_any_window (window)->window_parameters);
1691 DEFUN ("window-parameter", Fwindow_parameter, Swindow_parameter,
1692 2, 2, 0,
1693 doc: /* Return WINDOW's value for PARAMETER.
1694 WINDOW defaults to the selected window. */)
1695 (Lisp_Object window, Lisp_Object parameter)
1697 Lisp_Object result;
1699 result = Fassq (parameter, decode_any_window (window)->window_parameters);
1700 return CDR_SAFE (result);
1703 DEFUN ("set-window-parameter", Fset_window_parameter,
1704 Sset_window_parameter, 3, 3, 0,
1705 doc: /* Set WINDOW's value of PARAMETER to VALUE.
1706 WINDOW defaults to the selected window. Return VALUE. */)
1707 (Lisp_Object window, Lisp_Object parameter, Lisp_Object value)
1709 register struct window *w = decode_any_window (window);
1710 Lisp_Object old_alist_elt;
1712 old_alist_elt = Fassq (parameter, w->window_parameters);
1713 if (NILP (old_alist_elt))
1714 w->window_parameters = Fcons (Fcons (parameter, value), w->window_parameters);
1715 else
1716 Fsetcdr (old_alist_elt, value);
1717 return value;
1720 DEFUN ("window-display-table", Fwindow_display_table, Swindow_display_table,
1721 0, 1, 0,
1722 doc: /* Return the display-table that WINDOW is using.
1723 WINDOW defaults to the selected window. */)
1724 (Lisp_Object window)
1726 return decode_window (window)->display_table;
1729 /* Get the display table for use on window W. This is either W's
1730 display table or W's buffer's display table. Ignore the specified
1731 tables if they are not valid; if no valid table is specified,
1732 return 0. */
1734 struct Lisp_Char_Table *
1735 window_display_table (struct window *w)
1737 struct Lisp_Char_Table *dp = NULL;
1739 if (DISP_TABLE_P (w->display_table))
1740 dp = XCHAR_TABLE (w->display_table);
1741 else if (BUFFERP (w->buffer))
1743 struct buffer *b = XBUFFER (w->buffer);
1745 if (DISP_TABLE_P (BVAR (b, display_table)))
1746 dp = XCHAR_TABLE (BVAR (b, display_table));
1747 else if (DISP_TABLE_P (Vstandard_display_table))
1748 dp = XCHAR_TABLE (Vstandard_display_table);
1751 return dp;
1754 DEFUN ("set-window-display-table", Fset_window_display_table, Sset_window_display_table, 2, 2, 0,
1755 doc: /* Set WINDOW's display-table to TABLE. */)
1756 (register Lisp_Object window, Lisp_Object table)
1758 register struct window *w;
1760 w = decode_window (window);
1761 w->display_table = table;
1762 return table;
1765 /* Record info on buffer window W is displaying
1766 when it is about to cease to display that buffer. */
1767 static void
1768 unshow_buffer (register struct window *w)
1770 Lisp_Object buf;
1771 struct buffer *b;
1773 buf = w->buffer;
1774 b = XBUFFER (buf);
1775 if (b != XMARKER (w->pointm)->buffer)
1776 abort ();
1778 #if 0
1779 if (w == XWINDOW (selected_window)
1780 || ! EQ (buf, XWINDOW (selected_window)->buffer))
1781 /* Do this except when the selected window's buffer
1782 is being removed from some other window. */
1783 #endif
1784 /* last_window_start records the start position that this buffer
1785 had in the last window to be disconnected from it.
1786 Now that this statement is unconditional,
1787 it is possible for the buffer to be displayed in the
1788 selected window, while last_window_start reflects another
1789 window which was recently showing the same buffer.
1790 Some people might say that might be a good thing. Let's see. */
1791 b->last_window_start = marker_position (w->start);
1793 /* Point in the selected window's buffer
1794 is actually stored in that buffer, and the window's pointm isn't used.
1795 So don't clobber point in that buffer. */
1796 if (! EQ (buf, XWINDOW (selected_window)->buffer)
1797 /* This line helps to fix Horsley's testbug.el bug. */
1798 && !(WINDOWP (BVAR (b, last_selected_window))
1799 && w != XWINDOW (BVAR (b, last_selected_window))
1800 && EQ (buf, XWINDOW (BVAR (b, last_selected_window))->buffer)))
1801 temp_set_point_both (b,
1802 clip_to_bounds (BUF_BEGV (b),
1803 XMARKER (w->pointm)->charpos,
1804 BUF_ZV (b)),
1805 clip_to_bounds (BUF_BEGV_BYTE (b),
1806 marker_byte_position (w->pointm),
1807 BUF_ZV_BYTE (b)));
1809 if (WINDOWP (BVAR (b, last_selected_window))
1810 && w == XWINDOW (BVAR (b, last_selected_window)))
1811 BVAR (b, last_selected_window) = Qnil;
1814 /* Put NEW into the window structure in place of OLD. SETFLAG zero
1815 means change window structure only. Otherwise store geometry and
1816 other settings as well. */
1817 static void
1818 replace_window (Lisp_Object old, Lisp_Object new, int setflag)
1820 register Lisp_Object tem;
1821 register struct window *o = XWINDOW (old), *n = XWINDOW (new);
1823 /* If OLD is its frame's root window, then NEW is the new
1824 root window for that frame. */
1825 if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame))))
1826 FRAME_ROOT_WINDOW (XFRAME (o->frame)) = new;
1828 if (setflag)
1830 n->left_col = o->left_col;
1831 n->top_line = o->top_line;
1832 n->total_cols = o->total_cols;
1833 n->total_lines = o->total_lines;
1834 n->normal_cols = o->normal_cols;
1835 o->normal_cols = make_float (1.0);
1836 n->normal_lines = o->normal_lines;
1837 o->normal_lines = make_float (1.0);
1838 n->desired_matrix = n->current_matrix = 0;
1839 n->vscroll = 0;
1840 memset (&n->cursor, 0, sizeof (n->cursor));
1841 memset (&n->last_cursor, 0, sizeof (n->last_cursor));
1842 memset (&n->phys_cursor, 0, sizeof (n->phys_cursor));
1843 n->phys_cursor_type = -1;
1844 n->phys_cursor_width = -1;
1845 n->must_be_updated_p = 0;
1846 n->pseudo_window_p = 0;
1847 XSETFASTINT (n->window_end_vpos, 0);
1848 XSETFASTINT (n->window_end_pos, 0);
1849 n->window_end_valid = Qnil;
1850 n->frozen_window_start_p = 0;
1853 n->next = tem = o->next;
1854 if (!NILP (tem))
1855 XWINDOW (tem)->prev = new;
1857 n->prev = tem = o->prev;
1858 if (!NILP (tem))
1859 XWINDOW (tem)->next = new;
1861 n->parent = tem = o->parent;
1862 if (!NILP (tem))
1864 if (EQ (XWINDOW (tem)->vchild, old))
1865 XWINDOW (tem)->vchild = new;
1866 if (EQ (XWINDOW (tem)->hchild, old))
1867 XWINDOW (tem)->hchild = new;
1871 /* If window WINDOW and its parent window are iso-combined, merge
1872 WINDOW's children into those of its parent window and mark WINDOW as
1873 deleted. */
1875 static void
1876 recombine_windows (Lisp_Object window)
1878 struct window *w, *p, *c;
1879 Lisp_Object parent, child;
1880 int horflag;
1882 w = XWINDOW (window);
1883 parent = w->parent;
1884 if (!NILP (parent) && NILP (w->combination_limit))
1886 p = XWINDOW (parent);
1887 if (((!NILP (p->vchild) && !NILP (w->vchild))
1888 || (!NILP (p->hchild) && !NILP (w->hchild))))
1889 /* WINDOW and PARENT are both either a vertical or a horizontal
1890 combination. */
1892 horflag = NILP (w->vchild);
1893 child = horflag ? w->hchild : w->vchild;
1894 c = XWINDOW (child);
1896 /* Splice WINDOW's children into its parent's children and
1897 assign new normal sizes. */
1898 if (NILP (w->prev))
1899 if (horflag)
1900 p->hchild = child;
1901 else
1902 p->vchild = child;
1903 else
1905 c->prev = w->prev;
1906 XWINDOW (w->prev)->next = child;
1909 while (c)
1911 c->parent = parent;
1913 if (horflag)
1914 c->normal_cols
1915 = make_float (XFLOATINT (c->total_cols)
1916 / XFLOATINT (p->total_cols));
1917 else
1918 c->normal_lines
1919 = make_float (XFLOATINT (c->total_lines)
1920 / XFLOATINT (p->total_lines));
1922 if (NILP (c->next))
1924 if (!NILP (w->next))
1926 c->next = w->next;
1927 XWINDOW (c->next)->prev = child;
1930 c = 0;
1932 else
1934 child = c->next;
1935 c = XWINDOW (child);
1939 /* WINDOW can be deleted now. */
1940 w->vchild = w->hchild = Qnil;
1945 /* If WINDOW can be deleted, delete it. */
1946 static void
1947 delete_deletable_window (Lisp_Object window)
1949 if (!NILP (call1 (Qwindow_deletable_p, window)))
1950 call1 (Qdelete_window, window);
1953 /***********************************************************************
1954 Window List
1955 ***********************************************************************/
1957 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1958 pointer. This is a callback function for foreach_window, used in
1959 the window_list function. */
1961 static int
1962 add_window_to_list (struct window *w, void *user_data)
1964 Lisp_Object *list = (Lisp_Object *) user_data;
1965 Lisp_Object window;
1966 XSETWINDOW (window, w);
1967 *list = Fcons (window, *list);
1968 return 1;
1972 /* Return a list of all windows, for use by next_window. If
1973 Vwindow_list is a list, return that list. Otherwise, build a new
1974 list, cache it in Vwindow_list, and return that. */
1976 static Lisp_Object
1977 window_list (void)
1979 if (!CONSP (Vwindow_list))
1981 Lisp_Object tail;
1983 Vwindow_list = Qnil;
1984 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1986 Lisp_Object args[2];
1988 /* We are visiting windows in canonical order, and add
1989 new windows at the front of args[1], which means we
1990 have to reverse this list at the end. */
1991 args[1] = Qnil;
1992 foreach_window (XFRAME (XCAR (tail)), add_window_to_list, &args[1]);
1993 args[0] = Vwindow_list;
1994 args[1] = Fnreverse (args[1]);
1995 Vwindow_list = Fnconc (2, args);
1999 return Vwindow_list;
2003 /* Value is non-zero if WINDOW satisfies the constraints given by
2004 OWINDOW, MINIBUF and ALL_FRAMES.
2006 MINIBUF t means WINDOW may be minibuffer windows.
2007 `lambda' means WINDOW may not be a minibuffer window.
2008 a window means a specific minibuffer window
2010 ALL_FRAMES t means search all frames,
2011 nil means search just current frame,
2012 `visible' means search just visible frames on the
2013 current terminal,
2014 0 means search visible and iconified frames on the
2015 current terminal,
2016 a window means search the frame that window belongs to,
2017 a frame means consider windows on that frame, only. */
2019 static int
2020 candidate_window_p (Lisp_Object window, Lisp_Object owindow, Lisp_Object minibuf, Lisp_Object all_frames)
2022 struct window *w = XWINDOW (window);
2023 struct frame *f = XFRAME (w->frame);
2024 int candidate_p = 1;
2026 if (!BUFFERP (w->buffer))
2027 candidate_p = 0;
2028 else if (MINI_WINDOW_P (w)
2029 && (EQ (minibuf, Qlambda)
2030 || (WINDOWP (minibuf) && !EQ (minibuf, window))))
2032 /* If MINIBUF is `lambda' don't consider any mini-windows.
2033 If it is a window, consider only that one. */
2034 candidate_p = 0;
2036 else if (EQ (all_frames, Qt))
2037 candidate_p = 1;
2038 else if (NILP (all_frames))
2040 xassert (WINDOWP (owindow));
2041 candidate_p = EQ (w->frame, XWINDOW (owindow)->frame);
2043 else if (EQ (all_frames, Qvisible))
2045 FRAME_SAMPLE_VISIBILITY (f);
2046 candidate_p = FRAME_VISIBLE_P (f)
2047 && (FRAME_TERMINAL (XFRAME (w->frame))
2048 == FRAME_TERMINAL (XFRAME (selected_frame)));
2051 else if (INTEGERP (all_frames) && XINT (all_frames) == 0)
2053 FRAME_SAMPLE_VISIBILITY (f);
2054 candidate_p = (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f)
2055 #ifdef HAVE_X_WINDOWS
2056 /* Yuck!! If we've just created the frame and the
2057 window-manager requested the user to place it
2058 manually, the window may still not be considered
2059 `visible'. I'd argue it should be at least
2060 something like `iconified', but don't know how to do
2061 that yet. --Stef */
2062 || (FRAME_X_P (f) && f->output_data.x->asked_for_visible
2063 && !f->output_data.x->has_been_visible)
2064 #endif
2066 && (FRAME_TERMINAL (XFRAME (w->frame))
2067 == FRAME_TERMINAL (XFRAME (selected_frame)));
2069 else if (WINDOWP (all_frames))
2070 candidate_p = (EQ (FRAME_MINIBUF_WINDOW (f), all_frames)
2071 || EQ (XWINDOW (all_frames)->frame, w->frame)
2072 || EQ (XWINDOW (all_frames)->frame, FRAME_FOCUS_FRAME (f)));
2073 else if (FRAMEP (all_frames))
2074 candidate_p = EQ (all_frames, w->frame);
2076 return candidate_p;
2080 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2081 Fwindow_list. See candidate_window_p for the meaning of WINDOW,
2082 MINIBUF, and ALL_FRAMES. */
2084 static void
2085 decode_next_window_args (Lisp_Object *window, Lisp_Object *minibuf, Lisp_Object *all_frames)
2087 if (NILP (*window))
2088 *window = selected_window;
2089 else
2090 CHECK_LIVE_WINDOW (*window);
2092 /* MINIBUF nil may or may not include minibuffers. Decide if it
2093 does. */
2094 if (NILP (*minibuf))
2095 *minibuf = minibuf_level ? minibuf_window : Qlambda;
2096 else if (!EQ (*minibuf, Qt))
2097 *minibuf = Qlambda;
2099 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2100 => count none of them, or a specific minibuffer window (the
2101 active one) to count. */
2103 /* ALL_FRAMES nil doesn't specify which frames to include. */
2104 if (NILP (*all_frames))
2105 *all_frames = (!EQ (*minibuf, Qlambda)
2106 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window)->frame))
2107 : Qnil);
2108 else if (EQ (*all_frames, Qvisible))
2110 else if (EQ (*all_frames, make_number (0)))
2112 else if (FRAMEP (*all_frames))
2114 else if (!EQ (*all_frames, Qt))
2115 *all_frames = Qnil;
2119 /* Return the next or previous window of WINDOW in cyclic ordering
2120 of windows. NEXT_P non-zero means return the next window. See the
2121 documentation string of next-window for the meaning of MINIBUF and
2122 ALL_FRAMES. */
2124 static Lisp_Object
2125 next_window (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames, int next_p)
2127 decode_next_window_args (&window, &minibuf, &all_frames);
2129 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2130 return the first window on the frame. */
2131 if (FRAMEP (all_frames)
2132 && !EQ (all_frames, XWINDOW (window)->frame))
2133 return Fframe_first_window (all_frames);
2135 if (next_p)
2137 Lisp_Object list;
2139 /* Find WINDOW in the list of all windows. */
2140 list = Fmemq (window, window_list ());
2142 /* Scan forward from WINDOW to the end of the window list. */
2143 if (CONSP (list))
2144 for (list = XCDR (list); CONSP (list); list = XCDR (list))
2145 if (candidate_window_p (XCAR (list), window, minibuf, all_frames))
2146 break;
2148 /* Scan from the start of the window list up to WINDOW. */
2149 if (!CONSP (list))
2150 for (list = Vwindow_list;
2151 CONSP (list) && !EQ (XCAR (list), window);
2152 list = XCDR (list))
2153 if (candidate_window_p (XCAR (list), window, minibuf, all_frames))
2154 break;
2156 if (CONSP (list))
2157 window = XCAR (list);
2159 else
2161 Lisp_Object candidate, list;
2163 /* Scan through the list of windows for candidates. If there are
2164 candidate windows in front of WINDOW, the last one of these
2165 is the one we want. If there are candidates following WINDOW
2166 in the list, again the last one of these is the one we want. */
2167 candidate = Qnil;
2168 for (list = window_list (); CONSP (list); list = XCDR (list))
2170 if (EQ (XCAR (list), window))
2172 if (WINDOWP (candidate))
2173 break;
2175 else if (candidate_window_p (XCAR (list), window, minibuf,
2176 all_frames))
2177 candidate = XCAR (list);
2180 if (WINDOWP (candidate))
2181 window = candidate;
2184 return window;
2188 DEFUN ("next-window", Fnext_window, Snext_window, 0, 3, 0,
2189 doc: /* Return window following WINDOW in cyclic ordering of windows.
2190 WINDOW must be a live window and defaults to the selected one. The
2191 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2192 consider.
2194 MINIBUF nil or omitted means consider the minibuffer window only if the
2195 minibuffer is active. MINIBUF t means consider the minibuffer window
2196 even if the minibuffer is not active. Any other value means do not
2197 consider the minibuffer window even if the minibuffer is active.
2199 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2200 plus the minibuffer window if specified by the MINIBUF argument. If the
2201 minibuffer counts, consider all windows on all frames that share that
2202 minibuffer too. The following non-nil values of ALL-FRAMES have special
2203 meanings:
2205 - t means consider all windows on all existing frames.
2207 - `visible' means consider all windows on all visible frames.
2209 - 0 (the number zero) means consider all windows on all visible and
2210 iconified frames.
2212 - A frame means consider all windows on that frame only.
2214 Anything else means consider all windows on WINDOW's frame and no
2215 others.
2217 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2218 `next-window' to iterate through the entire cycle of acceptable
2219 windows, eventually ending up back at the window you started with.
2220 `previous-window' traverses the same cycle, in the reverse order. */)
2221 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2223 return next_window (window, minibuf, all_frames, 1);
2227 DEFUN ("previous-window", Fprevious_window, Sprevious_window, 0, 3, 0,
2228 doc: /* Return window preceding WINDOW in cyclic ordering of windows.
2229 WINDOW must be a live window and defaults to the selected one. The
2230 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2231 consider.
2233 MINIBUF nil or omitted means consider the minibuffer window only if the
2234 minibuffer is active. MINIBUF t means consider the minibuffer window
2235 even if the minibuffer is not active. Any other value means do not
2236 consider the minibuffer window even if the minibuffer is active.
2238 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2239 plus the minibuffer window if specified by the MINIBUF argument. If the
2240 minibuffer counts, consider all windows on all frames that share that
2241 minibuffer too. The following non-nil values of ALL-FRAMES have special
2242 meanings:
2244 - t means consider all windows on all existing frames.
2246 - `visible' means consider all windows on all visible frames.
2248 - 0 (the number zero) means consider all windows on all visible and
2249 iconified frames.
2251 - A frame means consider all windows on that frame only.
2253 Anything else means consider all windows on WINDOW's frame and no
2254 others.
2256 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2257 use `previous-window' to iterate through the entire cycle of
2258 acceptable windows, eventually ending up back at the window you
2259 started with. `next-window' traverses the same cycle, in the
2260 reverse order. */)
2261 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2263 return next_window (window, minibuf, all_frames, 0);
2267 /* Return a list of windows in cyclic ordering. Arguments are like
2268 for `next-window'. */
2270 static Lisp_Object
2271 window_list_1 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2273 Lisp_Object tail, list, rest;
2275 decode_next_window_args (&window, &minibuf, &all_frames);
2276 list = Qnil;
2278 for (tail = window_list (); CONSP (tail); tail = XCDR (tail))
2279 if (candidate_window_p (XCAR (tail), window, minibuf, all_frames))
2280 list = Fcons (XCAR (tail), list);
2282 /* Rotate the list to start with WINDOW. */
2283 list = Fnreverse (list);
2284 rest = Fmemq (window, list);
2285 if (!NILP (rest) && !EQ (rest, list))
2287 for (tail = list; !EQ (XCDR (tail), rest); tail = XCDR (tail))
2289 XSETCDR (tail, Qnil);
2290 list = nconc2 (rest, list);
2292 return list;
2296 DEFUN ("window-list", Fwindow_list, Swindow_list, 0, 3, 0,
2297 doc: /* Return a list of windows on FRAME, starting with WINDOW.
2298 FRAME nil or omitted means use the selected frame.
2299 WINDOW nil or omitted means use the window selected within FRAME.
2300 MINIBUF t means include the minibuffer window, even if it isn't active.
2301 MINIBUF nil or omitted means include the minibuffer window only
2302 if it's active.
2303 MINIBUF neither nil nor t means never include the minibuffer window. */)
2304 (Lisp_Object frame, Lisp_Object minibuf, Lisp_Object window)
2306 if (NILP (window))
2307 window = FRAMEP (frame) ? XFRAME (frame)->selected_window : selected_window;
2308 CHECK_WINDOW (window);
2309 if (NILP (frame))
2310 frame = selected_frame;
2312 if (!EQ (frame, XWINDOW (window)->frame))
2313 error ("Window is on a different frame");
2315 return window_list_1 (window, minibuf, frame);
2319 DEFUN ("window-list-1", Fwindow_list_1, Swindow_list_1, 0, 3, 0,
2320 doc: /* Return a list of all live windows.
2321 WINDOW specifies the first window to list and defaults to the selected
2322 window.
2324 Optional argument MINIBUF nil or omitted means consider the minibuffer
2325 window only if the minibuffer is active. MINIBUF t means consider the
2326 minibuffer window even if the minibuffer is not active. Any other value
2327 means do not consider the minibuffer window even if the minibuffer is
2328 active.
2330 Optional argument ALL-FRAMES nil or omitted means consider all windows
2331 on WINDOW's frame, plus the minibuffer window if specified by the
2332 MINIBUF argument. If the minibuffer counts, consider all windows on all
2333 frames that share that minibuffer too. The following non-nil values of
2334 ALL-FRAMES have special meanings:
2336 - t means consider all windows on all existing frames.
2338 - `visible' means consider all windows on all visible frames.
2340 - 0 (the number zero) means consider all windows on all visible and
2341 iconified frames.
2343 - A frame means consider all windows on that frame only.
2345 Anything else means consider all windows on WINDOW's frame and no
2346 others.
2348 If WINDOW is not on the list of windows returned, some other window will
2349 be listed first but no error is signaled. */)
2350 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2352 return window_list_1 (window, minibuf, all_frames);
2355 /* Look at all windows, performing an operation specified by TYPE
2356 with argument OBJ.
2357 If FRAMES is Qt, look at all frames;
2358 Qnil, look at just the selected frame;
2359 Qvisible, look at visible frames;
2360 a frame, just look at windows on that frame.
2361 If MINI is non-zero, perform the operation on minibuffer windows too. */
2363 enum window_loop
2365 WINDOW_LOOP_UNUSED,
2366 GET_BUFFER_WINDOW, /* Arg is buffer */
2367 REPLACE_BUFFER_IN_WINDOWS_SAFELY, /* Arg is buffer */
2368 REDISPLAY_BUFFER_WINDOWS, /* Arg is buffer */
2369 CHECK_ALL_WINDOWS
2372 static Lisp_Object
2373 window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frames)
2375 Lisp_Object window, windows, best_window, frame_arg;
2376 int frame_best_window_flag = 0;
2377 struct frame *f;
2378 struct gcpro gcpro1;
2380 /* If we're only looping through windows on a particular frame,
2381 frame points to that frame. If we're looping through windows
2382 on all frames, frame is 0. */
2383 if (FRAMEP (frames))
2384 f = XFRAME (frames);
2385 else if (NILP (frames))
2386 f = SELECTED_FRAME ();
2387 else
2388 f = NULL;
2390 if (f)
2391 frame_arg = Qlambda;
2392 else if (EQ (frames, make_number (0)))
2393 frame_arg = frames;
2394 else if (EQ (frames, Qvisible))
2395 frame_arg = frames;
2396 else
2397 frame_arg = Qt;
2399 /* frame_arg is Qlambda to stick to one frame,
2400 Qvisible to consider all visible frames,
2401 or Qt otherwise. */
2403 /* Pick a window to start with. */
2404 if (WINDOWP (obj))
2405 window = obj;
2406 else if (f)
2407 window = FRAME_SELECTED_WINDOW (f);
2408 else
2409 window = FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2411 windows = window_list_1 (window, mini ? Qt : Qnil, frame_arg);
2412 GCPRO1 (windows);
2413 best_window = Qnil;
2415 for (; CONSP (windows); windows = XCDR (windows))
2417 struct window *w;
2419 window = XCAR (windows);
2420 w = XWINDOW (window);
2422 /* Note that we do not pay attention here to whether the frame
2423 is visible, since Fwindow_list skips non-visible frames if
2424 that is desired, under the control of frame_arg. */
2425 if (!MINI_WINDOW_P (w)
2426 /* For REPLACE_BUFFER_IN_WINDOWS_SAFELY, we must always
2427 consider all windows. */
2428 || type == REPLACE_BUFFER_IN_WINDOWS_SAFELY
2429 || (mini && minibuf_level > 0))
2430 switch (type)
2432 case GET_BUFFER_WINDOW:
2433 if (EQ (w->buffer, obj)
2434 /* Don't find any minibuffer window except the one that
2435 is currently in use. */
2436 && (MINI_WINDOW_P (w) ? EQ (window, minibuf_window) : 1))
2438 if (EQ (window, selected_window))
2439 /* Preferably return the selected window. */
2440 RETURN_UNGCPRO (window);
2441 else if (EQ (XWINDOW (window)->frame, selected_frame)
2442 && !frame_best_window_flag)
2443 /* Prefer windows on the current frame (but don't
2444 choose another one if we have one already). */
2446 best_window = window;
2447 frame_best_window_flag = 1;
2449 else if (NILP (best_window))
2450 best_window = window;
2452 break;
2454 case REPLACE_BUFFER_IN_WINDOWS_SAFELY:
2455 /* We could simply check whether the buffer shown by window
2456 is live, and show another buffer in case it isn't. */
2457 if (EQ (w->buffer, obj))
2459 /* Undedicate WINDOW. */
2460 w->dedicated = Qnil;
2461 /* Make WINDOW show the buffer returned by
2462 other_buffer_safely, don't run any hooks. */
2463 set_window_buffer
2464 (window, other_buffer_safely (w->buffer), 0, 0);
2465 /* If WINDOW is the selected window, make its buffer
2466 current. But do so only if the window shows the
2467 current buffer (Bug#6454). */
2468 if (EQ (window, selected_window)
2469 && XBUFFER (w->buffer) == current_buffer)
2470 Fset_buffer (w->buffer);
2472 break;
2474 case REDISPLAY_BUFFER_WINDOWS:
2475 if (EQ (w->buffer, obj))
2477 mark_window_display_accurate (window, 0);
2478 w->update_mode_line = Qt;
2479 XBUFFER (obj)->prevent_redisplay_optimizations_p = 1;
2480 ++update_mode_lines;
2481 best_window = window;
2483 break;
2485 /* Check for a window that has a killed buffer. */
2486 case CHECK_ALL_WINDOWS:
2487 if (! NILP (w->buffer)
2488 && NILP (BVAR (XBUFFER (w->buffer), name)))
2489 abort ();
2490 break;
2492 case WINDOW_LOOP_UNUSED:
2493 break;
2497 UNGCPRO;
2498 return best_window;
2501 /* Used for debugging. Abort if any window has a dead buffer. */
2503 extern void check_all_windows (void) EXTERNALLY_VISIBLE;
2504 void
2505 check_all_windows (void)
2507 window_loop (CHECK_ALL_WINDOWS, Qnil, 1, Qt);
2510 DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 0, 2, 0,
2511 doc: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2512 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to
2513 the current buffer.
2515 The optional argument ALL-FRAMES specifies the frames to consider:
2517 - t means consider all windows on all existing frames.
2519 - `visible' means consider all windows on all visible frames.
2521 - 0 (the number zero) means consider all windows on all visible
2522 and iconified frames.
2524 - A frame means consider all windows on that frame only.
2526 Any other value of ALL-FRAMES means consider all windows on the
2527 selected frame and no others. */)
2528 (Lisp_Object buffer_or_name, Lisp_Object all_frames)
2530 Lisp_Object buffer;
2532 if (NILP (buffer_or_name))
2533 buffer = Fcurrent_buffer ();
2534 else
2535 buffer = Fget_buffer (buffer_or_name);
2537 if (BUFFERP (buffer))
2538 return window_loop (GET_BUFFER_WINDOW, buffer, 1, all_frames);
2539 else
2540 return Qnil;
2543 static Lisp_Object
2544 resize_root_window (Lisp_Object window, Lisp_Object delta, Lisp_Object horizontal, Lisp_Object ignore)
2546 return call4 (Qwindow_resize_root_window, window, delta, horizontal, ignore);
2550 DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal,
2551 Sdelete_other_windows_internal, 0, 2, "",
2552 doc: /* Make WINDOW fill its frame.
2553 Only the frame WINDOW is on is affected. WINDOW may be any window and
2554 defaults to the selected one.
2556 Optional argument ROOT, if non-nil, must specify an internal window such
2557 that WINDOW is in its window subtree. If this is the case, replace ROOT
2558 by WINDOW and leave alone any windows not part of ROOT's subtree.
2560 When WINDOW is live try to reduce display jumps by keeping the text
2561 previously visible in WINDOW in the same place on the frame. Doing this
2562 depends on the value of (window-start WINDOW), so if calling this
2563 function in a program gives strange scrolling, make sure the
2564 window-start value is reasonable when this function is called. */)
2565 (Lisp_Object window, Lisp_Object root)
2567 struct window *w, *r, *s;
2568 struct frame *f;
2569 Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta;
2570 ptrdiff_t startpos IF_LINT (= 0);
2571 int top IF_LINT (= 0), new_top, resize_failed;
2573 w = decode_any_window (window);
2574 XSETWINDOW (window, w);
2575 f = XFRAME (w->frame);
2577 if (NILP (root))
2578 /* ROOT is the frame's root window. */
2580 root = FRAME_ROOT_WINDOW (f);
2581 r = XWINDOW (root);
2583 else
2584 /* ROOT must be an ancestor of WINDOW. */
2586 r = decode_any_window (root);
2587 pwindow = XWINDOW (window)->parent;
2588 while (!NILP (pwindow))
2589 if (EQ (pwindow, root))
2590 break;
2591 else
2592 pwindow = XWINDOW (pwindow)->parent;
2593 if (!EQ (pwindow, root))
2594 error ("Specified root is not an ancestor of specified window");
2597 if (EQ (window, root))
2598 /* A noop. */
2599 return Qnil;
2600 /* I don't understand the "top > 0" part below. If we deal with a
2601 standalone minibuffer it would have been caught by the preceding
2602 test. */
2603 else if (MINI_WINDOW_P (w)) /* && top > 0) */
2604 error ("Can't expand minibuffer to full frame");
2606 if (!NILP (w->buffer))
2608 startpos = marker_position (w->start);
2609 top = WINDOW_TOP_EDGE_LINE (w)
2610 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w)));
2611 /* Make sure WINDOW is the frame's selected window. */
2612 if (!EQ (window, FRAME_SELECTED_WINDOW (f)))
2614 if (EQ (selected_frame, w->frame))
2615 Fselect_window (window, Qnil);
2616 else
2617 FRAME_SELECTED_WINDOW (f) = window;
2620 else
2622 /* See if the frame's selected window is a part of the window
2623 subtree rooted at WINDOW, by finding all the selected window's
2624 parents and comparing each one with WINDOW. If it isn't we
2625 need a new selected window for this frame. */
2626 swindow = FRAME_SELECTED_WINDOW (f);
2627 while (1)
2629 pwindow = swindow;
2630 while (!NILP (pwindow) && !EQ (window, pwindow))
2631 pwindow = XWINDOW (pwindow)->parent;
2633 if (EQ (window, pwindow))
2634 /* If WINDOW is an ancestor of SWINDOW, then SWINDOW is ok
2635 as the new selected window. */
2636 break;
2637 else
2638 /* Else try the previous window of SWINDOW. */
2639 swindow = Fprevious_window (swindow, Qlambda, Qnil);
2642 if (!EQ (swindow, FRAME_SELECTED_WINDOW (f)))
2644 if (EQ (selected_frame, w->frame))
2645 Fselect_window (swindow, Qnil);
2646 else
2647 FRAME_SELECTED_WINDOW (f) = swindow;
2651 BLOCK_INPUT;
2652 free_window_matrices (r);
2654 windows_or_buffers_changed++;
2655 Vwindow_list = Qnil;
2656 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
2657 resize_failed = 0;
2659 if (NILP (w->buffer))
2661 /* Resize child windows vertically. */
2662 XSETINT (delta, XINT (r->total_lines) - XINT (w->total_lines));
2663 w->top_line = r->top_line;
2664 resize_root_window (window, delta, Qnil, Qnil);
2665 if (window_resize_check (w, 0))
2666 window_resize_apply (w, 0);
2667 else
2669 resize_root_window (window, delta, Qnil, Qt);
2670 if (window_resize_check (w, 0))
2671 window_resize_apply (w, 0);
2672 else
2673 resize_failed = 1;
2676 /* Resize child windows horizontally. */
2677 if (!resize_failed)
2679 w->left_col = r->left_col;
2680 XSETINT (delta, XINT (r->total_cols) - XINT (w->total_cols));
2681 w->left_col = r->left_col;
2682 resize_root_window (window, delta, Qt, Qnil);
2683 if (window_resize_check (w, 1))
2684 window_resize_apply (w, 1);
2685 else
2687 resize_root_window (window, delta, Qt, Qt);
2688 if (window_resize_check (w, 1))
2689 window_resize_apply (w, 1);
2690 else
2691 resize_failed = 1;
2695 if (resize_failed)
2696 /* Play safe, if we still can ... */
2698 window = swindow;
2699 w = XWINDOW (window);
2703 /* Cleanly unlink WINDOW from window-tree. */
2704 if (!NILP (w->prev))
2705 /* Get SIBLING above (on the left of) WINDOW. */
2707 sibling = w->prev;
2708 s = XWINDOW (sibling);
2709 s->next = w->next;
2710 if (!NILP (s->next))
2711 XWINDOW (s->next)->prev = sibling;
2713 else
2714 /* Get SIBLING below (on the right of) WINDOW. */
2716 sibling = w->next;
2717 s = XWINDOW (sibling);
2718 s->prev = Qnil;
2719 if (!NILP (XWINDOW (w->parent)->vchild))
2720 XWINDOW (w->parent)->vchild = sibling;
2721 else
2722 XWINDOW (w->parent)->hchild = sibling;
2725 /* Delete ROOT and all child windows of ROOT. */
2726 if (!NILP (r->vchild))
2728 delete_all_child_windows (r->vchild);
2729 r->vchild = Qnil;
2731 else if (!NILP (r->hchild))
2733 delete_all_child_windows (r->hchild);
2734 r->hchild = Qnil;
2737 replace_window (root, window, 1);
2739 /* This must become SWINDOW anyway ....... */
2740 if (!NILP (w->buffer) && !resize_failed)
2742 /* Try to minimize scrolling, by setting the window start to the
2743 point will cause the text at the old window start to be at the
2744 same place on the frame. But don't try to do this if the
2745 window start is outside the visible portion (as might happen
2746 when the display is not current, due to typeahead). */
2747 new_top = WINDOW_TOP_EDGE_LINE (w) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w)));
2748 if (new_top != top
2749 && startpos >= BUF_BEGV (XBUFFER (w->buffer))
2750 && startpos <= BUF_ZV (XBUFFER (w->buffer)))
2752 struct position pos;
2753 struct buffer *obuf = current_buffer;
2755 Fset_buffer (w->buffer);
2756 /* This computation used to temporarily move point, but that
2757 can have unwanted side effects due to text properties. */
2758 pos = *vmotion (startpos, -top, w);
2760 set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos);
2761 w->window_end_valid = Qnil;
2762 w->start_at_line_beg = ((pos.bytepos == BEGV_BYTE
2763 || FETCH_BYTE (pos.bytepos - 1) == '\n') ? Qt
2764 : Qnil);
2765 /* We need to do this, so that the window-scroll-functions
2766 get called. */
2767 w->optional_new_start = Qt;
2769 set_buffer_internal (obuf);
2773 adjust_glyphs (f);
2774 UNBLOCK_INPUT;
2776 run_window_configuration_change_hook (f);
2778 return Qnil;
2782 void
2783 replace_buffer_in_windows (Lisp_Object buffer)
2785 call1 (Qreplace_buffer_in_windows, buffer);
2789 /* Safely replace BUFFER with some other buffer in all windows of all
2790 frames, even those on other keyboards. */
2792 void
2793 replace_buffer_in_windows_safely (Lisp_Object buffer)
2795 Lisp_Object tail, frame;
2797 /* A single call to window_loop won't do the job because it only
2798 considers frames on the current keyboard. So loop manually over
2799 frames, and handle each one. */
2800 FOR_EACH_FRAME (tail, frame)
2801 window_loop (REPLACE_BUFFER_IN_WINDOWS_SAFELY, buffer, 1, frame);
2804 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2805 minimum allowable size. */
2807 void
2808 check_frame_size (FRAME_PTR frame, int *rows, int *cols)
2810 /* For height, we have to see:
2811 how many windows the frame has at minimum (one or two),
2812 and whether it has a menu bar or other special stuff at the top. */
2813 int min_height
2814 = ((FRAME_MINIBUF_ONLY_P (frame) || ! FRAME_HAS_MINIBUF_P (frame))
2815 ? MIN_SAFE_WINDOW_HEIGHT
2816 : 2 * MIN_SAFE_WINDOW_HEIGHT);
2818 if (FRAME_TOP_MARGIN (frame) > 0)
2819 min_height += FRAME_TOP_MARGIN (frame);
2821 if (*rows < min_height)
2822 *rows = min_height;
2823 if (*cols < MIN_SAFE_WINDOW_WIDTH)
2824 *cols = MIN_SAFE_WINDOW_WIDTH;
2827 /* Adjust the margins of window W if text area is too small.
2828 Return 1 if window width is ok after adjustment; 0 if window
2829 is still too narrow. */
2831 static int
2832 adjust_window_margins (struct window *w)
2834 int box_cols = (WINDOW_TOTAL_COLS (w)
2835 - WINDOW_FRINGE_COLS (w)
2836 - WINDOW_SCROLL_BAR_COLS (w));
2837 int margin_cols = (WINDOW_LEFT_MARGIN_COLS (w)
2838 + WINDOW_RIGHT_MARGIN_COLS (w));
2840 if (box_cols - margin_cols >= MIN_SAFE_WINDOW_WIDTH)
2841 return 1;
2843 if (margin_cols < 0 || box_cols < MIN_SAFE_WINDOW_WIDTH)
2844 return 0;
2846 /* Window's text area is too narrow, but reducing the window
2847 margins will fix that. */
2848 margin_cols = box_cols - MIN_SAFE_WINDOW_WIDTH;
2849 if (WINDOW_RIGHT_MARGIN_COLS (w) > 0)
2851 if (WINDOW_LEFT_MARGIN_COLS (w) > 0)
2852 w->left_margin_cols = w->right_margin_cols
2853 = make_number (margin_cols/2);
2854 else
2855 w->right_margin_cols = make_number (margin_cols);
2857 else
2858 w->left_margin_cols = make_number (margin_cols);
2859 return 1;
2862 static Lisp_Object Fset_window_margins (Lisp_Object, Lisp_Object, Lisp_Object);
2863 static Lisp_Object Fset_window_fringes (Lisp_Object, Lisp_Object, Lisp_Object,
2864 Lisp_Object);
2865 static Lisp_Object Fset_window_scroll_bars (Lisp_Object, Lisp_Object,
2866 Lisp_Object, Lisp_Object);
2867 static Lisp_Object Fset_window_vscroll (Lisp_Object, Lisp_Object, Lisp_Object);
2869 /* The following three routines are needed for running a window's
2870 configuration change hook. */
2871 static void
2872 run_funs (Lisp_Object funs)
2874 for (; CONSP (funs); funs = XCDR (funs))
2875 if (!EQ (XCAR (funs), Qt))
2876 call0 (XCAR (funs));
2879 static Lisp_Object
2880 select_window_norecord (Lisp_Object window)
2882 return WINDOW_LIVE_P (window)
2883 ? Fselect_window (window, Qt) : selected_window;
2886 static Lisp_Object
2887 select_frame_norecord (Lisp_Object frame)
2889 return FRAME_LIVE_P (XFRAME (frame))
2890 ? Fselect_frame (frame, Qt) : selected_frame;
2893 void
2894 run_window_configuration_change_hook (struct frame *f)
2896 ptrdiff_t count = SPECPDL_INDEX ();
2897 Lisp_Object frame, global_wcch
2898 = Fdefault_value (Qwindow_configuration_change_hook);
2899 XSETFRAME (frame, f);
2901 if (NILP (Vrun_hooks))
2902 return;
2904 /* Use the right buffer. Matters when running the local hooks. */
2905 if (current_buffer != XBUFFER (Fwindow_buffer (Qnil)))
2907 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
2908 Fset_buffer (Fwindow_buffer (Qnil));
2911 if (SELECTED_FRAME () != f)
2913 record_unwind_protect (select_frame_norecord, Fselected_frame ());
2914 select_frame_norecord (frame);
2917 /* Look for buffer-local values. */
2919 Lisp_Object windows = Fwindow_list (frame, Qlambda, Qnil);
2920 for (; CONSP (windows); windows = XCDR (windows))
2922 Lisp_Object window = XCAR (windows);
2923 Lisp_Object buffer = Fwindow_buffer (window);
2924 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook,
2925 buffer)))
2927 ptrdiff_t inner_count = SPECPDL_INDEX ();
2928 record_unwind_protect (select_window_norecord, Fselected_window ());
2929 select_window_norecord (window);
2930 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook,
2931 buffer));
2932 unbind_to (inner_count, Qnil);
2937 run_funs (global_wcch);
2938 unbind_to (count, Qnil);
2941 DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook,
2942 Srun_window_configuration_change_hook, 1, 1, 0,
2943 doc: /* Run `window-configuration-change-hook' for FRAME. */)
2944 (Lisp_Object frame)
2946 CHECK_LIVE_FRAME (frame);
2947 run_window_configuration_change_hook (XFRAME (frame));
2948 return Qnil;
2951 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
2952 means it's allowed to run hooks. See make_frame for a case where
2953 it's not allowed. KEEP_MARGINS_P non-zero means that the current
2954 margins, fringes, and scroll-bar settings of the window are not
2955 reset from the buffer's local settings. */
2957 void
2958 set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int keep_margins_p)
2960 struct window *w = XWINDOW (window);
2961 struct buffer *b = XBUFFER (buffer);
2962 ptrdiff_t count = SPECPDL_INDEX ();
2963 int samebuf = EQ (buffer, w->buffer);
2965 w->buffer = buffer;
2967 if (EQ (window, selected_window))
2968 BVAR (b, last_selected_window) = window;
2970 /* Let redisplay errors through. */
2971 b->display_error_modiff = 0;
2973 /* Update time stamps of buffer display. */
2974 if (INTEGERP (BVAR (b, display_count)))
2975 XSETINT (BVAR (b, display_count), XINT (BVAR (b, display_count)) + 1);
2976 BVAR (b, display_time) = Fcurrent_time ();
2978 XSETFASTINT (w->window_end_pos, 0);
2979 XSETFASTINT (w->window_end_vpos, 0);
2980 memset (&w->last_cursor, 0, sizeof w->last_cursor);
2981 w->window_end_valid = Qnil;
2982 if (!(keep_margins_p && samebuf))
2983 { /* If we're not actually changing the buffer, don't reset hscroll and
2984 vscroll. This case happens for example when called from
2985 change_frame_size_1, where we use a dummy call to
2986 Fset_window_buffer on the frame's selected window (and no other)
2987 just in order to run window-configuration-change-hook.
2988 Resetting hscroll and vscroll here is problematic for things like
2989 image-mode and doc-view-mode since it resets the image's position
2990 whenever we resize the frame. */
2991 w->hscroll = w->min_hscroll = make_number (0);
2992 w->vscroll = 0;
2993 set_marker_both (w->pointm, buffer, BUF_PT (b), BUF_PT_BYTE (b));
2994 set_marker_restricted (w->start,
2995 make_number (b->last_window_start),
2996 buffer);
2997 w->start_at_line_beg = Qnil;
2998 w->force_start = Qnil;
2999 XSETFASTINT (w->last_modified, 0);
3000 XSETFASTINT (w->last_overlay_modified, 0);
3002 /* Maybe we could move this into the `if' but it's not obviously safe and
3003 I doubt it's worth the trouble. */
3004 windows_or_buffers_changed++;
3006 /* We must select BUFFER for running the window-scroll-functions. */
3007 /* We can't check ! NILP (Vwindow_scroll_functions) here
3008 because that might itself be a local variable. */
3009 if (window_initialized)
3011 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
3012 Fset_buffer (buffer);
3015 XMARKER (w->pointm)->insertion_type = !NILP (Vwindow_point_insertion_type);
3017 if (!keep_margins_p)
3019 /* Set left and right marginal area width etc. from buffer. */
3021 /* This may call adjust_window_margins three times, so
3022 temporarily disable window margins. */
3023 Lisp_Object save_left = w->left_margin_cols;
3024 Lisp_Object save_right = w->right_margin_cols;
3026 w->left_margin_cols = w->right_margin_cols = Qnil;
3028 Fset_window_fringes (window,
3029 BVAR (b, left_fringe_width), BVAR (b, right_fringe_width),
3030 BVAR (b, fringes_outside_margins));
3032 Fset_window_scroll_bars (window,
3033 BVAR (b, scroll_bar_width),
3034 BVAR (b, vertical_scroll_bar_type), Qnil);
3036 w->left_margin_cols = save_left;
3037 w->right_margin_cols = save_right;
3039 Fset_window_margins (window,
3040 BVAR (b, left_margin_cols), BVAR (b, right_margin_cols));
3043 if (run_hooks_p)
3045 if (! NILP (Vwindow_scroll_functions))
3046 run_hook_with_args_2 (Qwindow_scroll_functions, window,
3047 Fmarker_position (w->start));
3048 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w)));
3051 unbind_to (count, Qnil);
3054 DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 3, 0,
3055 doc: /* Make WINDOW display BUFFER-OR-NAME as its contents.
3056 WINDOW has to be a live window and defaults to the selected one.
3057 BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
3059 Optional third argument KEEP-MARGINS non-nil means that WINDOW's current
3060 display margins, fringe widths, and scroll bar settings are preserved;
3061 the default is to reset these from the local settings for BUFFER-OR-NAME
3062 or the frame defaults. Return nil.
3064 This function throws an error when WINDOW is strongly dedicated to its
3065 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3066 already display BUFFER-OR-NAME.
3068 This function runs `window-scroll-functions' before running
3069 `window-configuration-change-hook'. */)
3070 (register Lisp_Object window, Lisp_Object buffer_or_name, Lisp_Object keep_margins)
3072 register Lisp_Object tem, buffer;
3073 register struct window *w = decode_window (window);
3075 XSETWINDOW (window, w);
3076 buffer = Fget_buffer (buffer_or_name);
3077 CHECK_BUFFER (buffer);
3078 if (NILP (BVAR (XBUFFER (buffer), name)))
3079 error ("Attempt to display deleted buffer");
3081 tem = w->buffer;
3082 if (NILP (tem))
3083 error ("Window is deleted");
3084 else if (!EQ (tem, Qt))
3085 /* w->buffer is t when the window is first being set up. */
3087 if (!EQ (tem, buffer))
3089 if (EQ (w->dedicated, Qt))
3090 /* WINDOW is strongly dedicated to its buffer, signal an
3091 error. */
3092 error ("Window is dedicated to `%s'", SDATA (BVAR (XBUFFER (tem), name)));
3093 else
3094 /* WINDOW is weakly dedicated to its buffer, reset
3095 dedicatedness. */
3096 w->dedicated = Qnil;
3098 call1 (Qrecord_window_buffer, window);
3101 unshow_buffer (w);
3104 set_window_buffer (window, buffer, 1, !NILP (keep_margins));
3106 return Qnil;
3109 static Lisp_Object
3110 display_buffer (Lisp_Object buffer, Lisp_Object not_this_window_p, Lisp_Object override_frame)
3112 return call3 (Qdisplay_buffer, buffer, not_this_window_p, override_frame);
3115 DEFUN ("force-window-update", Fforce_window_update, Sforce_window_update,
3116 0, 1, 0,
3117 doc: /* Force all windows to be updated on next redisplay.
3118 If optional arg OBJECT is a window, force redisplay of that window only.
3119 If OBJECT is a buffer or buffer name, force redisplay of all windows
3120 displaying that buffer. */)
3121 (Lisp_Object object)
3123 if (NILP (object))
3125 windows_or_buffers_changed++;
3126 update_mode_lines++;
3127 return Qt;
3130 if (WINDOWP (object))
3132 struct window *w = XWINDOW (object);
3133 mark_window_display_accurate (object, 0);
3134 w->update_mode_line = Qt;
3135 if (BUFFERP (w->buffer))
3136 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
3137 ++update_mode_lines;
3138 return Qt;
3141 if (STRINGP (object))
3142 object = Fget_buffer (object);
3143 if (BUFFERP (object) && !NILP (BVAR (XBUFFER (object), name)))
3145 /* Walk all windows looking for buffer, and force update
3146 of each of those windows. */
3148 object = window_loop (REDISPLAY_BUFFER_WINDOWS, object, 0, Qvisible);
3149 return NILP (object) ? Qnil : Qt;
3152 /* If nothing suitable was found, just return.
3153 We could signal an error, but this feature will typically be used
3154 asynchronously in timers or process sentinels, so we don't. */
3155 return Qnil;
3159 void
3160 temp_output_buffer_show (register Lisp_Object buf)
3162 register struct buffer *old = current_buffer;
3163 register Lisp_Object window;
3164 register struct window *w;
3166 BVAR (XBUFFER (buf), directory) = BVAR (current_buffer, directory);
3168 Fset_buffer (buf);
3169 BUF_SAVE_MODIFF (XBUFFER (buf)) = MODIFF;
3170 BEGV = BEG;
3171 ZV = Z;
3172 SET_PT (BEG);
3173 set_buffer_internal (old);
3175 if (!NILP (Vtemp_buffer_show_function))
3176 call1 (Vtemp_buffer_show_function, buf);
3177 else
3179 window = display_buffer (buf, Qnil, Qnil);
3181 if (!EQ (XWINDOW (window)->frame, selected_frame))
3182 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
3183 Vminibuf_scroll_window = window;
3184 w = XWINDOW (window);
3185 XSETFASTINT (w->hscroll, 0);
3186 XSETFASTINT (w->min_hscroll, 0);
3187 set_marker_restricted_both (w->start, buf, BEG, BEG);
3188 set_marker_restricted_both (w->pointm, buf, BEG, BEG);
3190 /* Run temp-buffer-show-hook, with the chosen window selected
3191 and its buffer current. */
3193 ptrdiff_t count = SPECPDL_INDEX ();
3194 Lisp_Object prev_window, prev_buffer;
3195 prev_window = selected_window;
3196 XSETBUFFER (prev_buffer, old);
3198 /* Select the window that was chosen, for running the hook.
3199 Note: Both Fselect_window and select_window_norecord may
3200 set-buffer to the buffer displayed in the window,
3201 so we need to save the current buffer. --stef */
3202 record_unwind_protect (Fset_buffer, prev_buffer);
3203 record_unwind_protect (select_window_norecord, prev_window);
3204 Fselect_window (window, Qt);
3205 Fset_buffer (w->buffer);
3206 Frun_hooks (1, &Qtemp_buffer_show_hook);
3207 unbind_to (count, Qnil);
3212 DEFUN ("internal-temp-output-buffer-show",
3213 Ftemp_output_buffer_show, Stemp_output_buffer_show,
3214 1, 1, 0,
3215 doc: /* Internal function for `with-output-to-temp-buffer'. */)
3216 (Lisp_Object buf)
3218 temp_output_buffer_show (buf);
3219 return Qnil;
3222 /* Make new window, have it replace WINDOW in window-tree, and make
3223 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
3224 horizontal child). */
3225 static void
3226 make_parent_window (Lisp_Object window, int horflag)
3228 Lisp_Object parent;
3229 register struct window *o, *p;
3230 int i;
3232 o = XWINDOW (window);
3233 p = allocate_window ();
3234 for (i = 0; i < VECSIZE (struct window); ++i)
3235 ((struct Lisp_Vector *) p)->contents[i]
3236 = ((struct Lisp_Vector *) o)->contents[i];
3237 XSETWINDOW (parent, p);
3239 ++sequence_number;
3240 XSETFASTINT (p->sequence_number, sequence_number);
3242 replace_window (window, parent, 1);
3244 o->next = Qnil;
3245 o->prev = Qnil;
3246 o->parent = parent;
3248 p->hchild = horflag ? window : Qnil;
3249 p->vchild = horflag ? Qnil : window;
3250 p->start = Qnil;
3251 p->pointm = Qnil;
3252 p->buffer = Qnil;
3253 p->combination_limit = Qnil;
3254 p->window_parameters = Qnil;
3257 /* Make new window from scratch. */
3258 Lisp_Object
3259 make_window (void)
3261 Lisp_Object window;
3262 register struct window *w;
3264 w = allocate_window ();
3265 /* Initialize all Lisp data. */
3266 w->frame = w->mini_p = Qnil;
3267 w->next = w->prev = w->hchild = w->vchild = w->parent = Qnil;
3268 XSETFASTINT (w->left_col, 0);
3269 XSETFASTINT (w->top_line, 0);
3270 XSETFASTINT (w->total_lines, 0);
3271 XSETFASTINT (w->total_cols, 0);
3272 w->normal_lines = make_float (1.0);
3273 w->normal_cols = make_float (1.0);
3274 XSETFASTINT (w->new_total, 0);
3275 XSETFASTINT (w->new_normal, 0);
3276 w->buffer = Qnil;
3277 w->start = Fmake_marker ();
3278 w->pointm = Fmake_marker ();
3279 w->force_start = w->optional_new_start = Qnil;
3280 XSETFASTINT (w->hscroll, 0);
3281 XSETFASTINT (w->min_hscroll, 0);
3282 XSETFASTINT (w->use_time, 0);
3283 ++sequence_number;
3284 XSETFASTINT (w->sequence_number, sequence_number);
3285 w->temslot = w->last_modified = w->last_overlay_modified = Qnil;
3286 XSETFASTINT (w->last_point, 0);
3287 w->last_had_star = w->vertical_scroll_bar = Qnil;
3288 w->left_margin_cols = w->right_margin_cols = Qnil;
3289 w->left_fringe_width = w->right_fringe_width = Qnil;
3290 w->fringes_outside_margins = Qnil;
3291 w->scroll_bar_width = Qnil;
3292 w->vertical_scroll_bar_type = Qt;
3293 w->last_mark_x = w->last_mark_y = Qnil;
3294 XSETFASTINT (w->window_end_pos, 0);
3295 XSETFASTINT (w->window_end_vpos, 0);
3296 w->window_end_valid = w->update_mode_line = Qnil;
3297 w->start_at_line_beg = w->display_table = w->dedicated = Qnil;
3298 w->base_line_number = w->base_line_pos = w->region_showing = Qnil;
3299 w->column_number_displayed = w->redisplay_end_trigger = Qnil;
3300 w->combination_limit = w->window_parameters = Qnil;
3301 w->prev_buffers = w->next_buffers = Qnil;
3302 /* Initialize non-Lisp data. */
3303 w->desired_matrix = w->current_matrix = 0;
3304 w->nrows_scale_factor = w->ncols_scale_factor = 1;
3305 memset (&w->cursor, 0, sizeof (w->cursor));
3306 memset (&w->last_cursor, 0, sizeof (w->last_cursor));
3307 memset (&w->phys_cursor, 0, sizeof (w->phys_cursor));
3308 w->phys_cursor_type = -1;
3309 w->phys_cursor_width = -1;
3310 w->phys_cursor_on_p = 0;
3311 w->last_cursor_off_p = w->cursor_off_p = 0;
3312 w->must_be_updated_p = 0;
3313 w->pseudo_window_p = 0;
3314 w->frozen_window_start_p = 0;
3315 w->vscroll = 0;
3316 /* Reset window_list. */
3317 Vwindow_list = Qnil;
3318 /* Return window. */
3319 XSETWINDOW (window, w);
3320 return window;
3323 DEFUN ("set-window-new-total", Fset_window_new_total, Sset_window_new_total, 2, 3, 0,
3324 doc: /* Set new total size of WINDOW to SIZE.
3325 Return SIZE.
3327 Optional argument ADD non-nil means add SIZE to the new total size of
3328 WINDOW and return the sum.
3330 Note: This function does not operate on any child windows of WINDOW. */)
3331 (Lisp_Object window, Lisp_Object size, Lisp_Object add)
3333 struct window *w = decode_any_window (window);
3335 CHECK_NUMBER (size);
3336 if (NILP (add))
3337 XSETINT (w->new_total, XINT (size));
3338 else
3339 XSETINT (w->new_total, XINT (w->new_total) + XINT (size));
3341 return w->new_total;
3344 DEFUN ("set-window-new-normal", Fset_window_new_normal, Sset_window_new_normal, 1, 2, 0,
3345 doc: /* Set new normal size of WINDOW to SIZE.
3346 Return SIZE.
3348 Note: This function does not operate on any child windows of WINDOW. */)
3349 (Lisp_Object window, Lisp_Object size)
3351 struct window *w = decode_any_window (window);
3353 w->new_normal = size;
3354 return w->new_normal;
3357 /* Return 1 if setting w->total_lines (w->total_cols if HORFLAG is
3358 non-zero) to w->new_total would result in correct heights (widths)
3359 for window W and recursively all child windows of W.
3361 Note: This function does not check any of `window-fixed-size-p',
3362 `window-min-height' or `window-min-width'. It does check that window
3363 sizes do not drop below one line (two columns). */
3364 static int
3365 window_resize_check (struct window *w, int horflag)
3367 struct window *c;
3369 if (!NILP (w->vchild))
3370 /* W is a vertical combination. */
3372 c = XWINDOW (w->vchild);
3373 if (horflag)
3374 /* All child windows of W must have the same width as W. */
3376 while (c)
3378 if ((XINT (c->new_total) != XINT (w->new_total))
3379 || !window_resize_check (c, horflag))
3380 return 0;
3381 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3383 return 1;
3385 else
3386 /* The sum of the heights of the child windows of W must equal
3387 W's height. */
3389 int sum_of_sizes = 0;
3390 while (c)
3392 if (!window_resize_check (c, horflag))
3393 return 0;
3394 sum_of_sizes = sum_of_sizes + XINT (c->new_total);
3395 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3397 return (sum_of_sizes == XINT (w->new_total));
3400 else if (!NILP (w->hchild))
3401 /* W is a horizontal combination. */
3403 c = XWINDOW (w->hchild);
3404 if (horflag)
3405 /* The sum of the widths of the child windows of W must equal W's
3406 width. */
3408 int sum_of_sizes = 0;
3409 while (c)
3411 if (!window_resize_check (c, horflag))
3412 return 0;
3413 sum_of_sizes = sum_of_sizes + XINT (c->new_total);
3414 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3416 return (sum_of_sizes == XINT (w->new_total));
3418 else
3419 /* All child windows of W must have the same height as W. */
3421 while (c)
3423 if ((XINT (c->new_total) != XINT (w->new_total))
3424 || !window_resize_check (c, horflag))
3425 return 0;
3426 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3428 return 1;
3431 else
3432 /* A leaf window. Make sure it's not too small. The following
3433 hardcodes the values of `window-safe-min-width' (2) and
3434 `window-safe-min-height' (1) which are defined in window.el. */
3435 return XINT (w->new_total) >= (horflag ? 2 : 1);
3438 /* Set w->total_lines (w->total_cols if HORIZONTAL is non-zero) to
3439 w->new_total for window W and recursively all child windows of W.
3440 Also calculate and assign the new vertical (horizontal) start
3441 positions of each of these windows.
3443 This function does not perform any error checks. Make sure you have
3444 run window_resize_check on W before applying this function. */
3445 static void
3446 window_resize_apply (struct window *w, int horflag)
3448 struct window *c;
3449 int pos;
3451 /* Note: Assigning new_normal requires that the new total size of the
3452 parent window has been set *before*. */
3453 if (horflag)
3455 w->total_cols = w->new_total;
3456 if (NUMBERP (w->new_normal))
3457 w->normal_cols = w->new_normal;
3459 pos = XINT (w->left_col);
3461 else
3463 w->total_lines = w->new_total;
3464 if (NUMBERP (w->new_normal))
3465 w->normal_lines = w->new_normal;
3467 pos = XINT (w->top_line);
3470 if (!NILP (w->vchild))
3471 /* W is a vertical combination. */
3473 c = XWINDOW (w->vchild);
3474 while (c)
3476 if (horflag)
3477 XSETFASTINT (c->left_col, pos);
3478 else
3479 XSETFASTINT (c->top_line, pos);
3480 window_resize_apply (c, horflag);
3481 if (!horflag)
3482 pos = pos + XINT (c->total_lines);
3483 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3486 else if (!NILP (w->hchild))
3487 /* W is a horizontal combination. */
3489 c = XWINDOW (w->hchild);
3490 while (c)
3492 if (horflag)
3493 XSETFASTINT (c->left_col, pos);
3494 else
3495 XSETFASTINT (c->top_line, pos);
3496 window_resize_apply (c, horflag);
3497 if (horflag)
3498 pos = pos + XINT (c->total_cols);
3499 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3503 /* Clear out some redisplay caches. */
3504 XSETFASTINT (w->last_modified, 0);
3505 XSETFASTINT (w->last_overlay_modified, 0);
3509 DEFUN ("window-resize-apply", Fwindow_resize_apply, Swindow_resize_apply, 1, 2, 0,
3510 doc: /* Apply requested size values for window-tree of FRAME.
3511 Optional argument HORIZONTAL omitted or nil means apply requested height
3512 values. HORIZONTAL non-nil means apply requested width values.
3514 This function checks whether the requested values sum up to a valid
3515 window layout, recursively assigns the new sizes of all child windows
3516 and calculates and assigns the new start positions of these windows.
3518 Note: This function does not check any of `window-fixed-size-p',
3519 `window-min-height' or `window-min-width'. All these checks have to
3520 be applied on the Elisp level. */)
3521 (Lisp_Object frame, Lisp_Object horizontal)
3523 struct frame *f;
3524 struct window *r;
3525 int horflag = !NILP (horizontal);
3527 if (NILP (frame))
3528 frame = selected_frame;
3529 CHECK_LIVE_FRAME (frame);
3531 f = XFRAME (frame);
3532 r = XWINDOW (FRAME_ROOT_WINDOW (f));
3534 if (!window_resize_check (r, horflag)
3535 || ! EQ (r->new_total, (horflag ? r->total_cols : r->total_lines)))
3536 return Qnil;
3538 BLOCK_INPUT;
3539 window_resize_apply (r, horflag);
3541 windows_or_buffers_changed++;
3542 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
3544 adjust_glyphs (f);
3545 UNBLOCK_INPUT;
3547 run_window_configuration_change_hook (f);
3549 return Qt;
3553 /* Resize frame F's windows when number of lines of F is set to SIZE.
3554 HORFLAG 1 means resize windows when number of columns of F is set to
3555 SIZE.
3557 This function can delete all windows but the selected one in order to
3558 satisfy the request. The result will be meaningful if and only if
3559 F's windows have meaningful sizes when you call this. */
3560 void
3561 resize_frame_windows (struct frame *f, int size, int horflag)
3563 Lisp_Object root = f->root_window;
3564 struct window *r = XWINDOW (root);
3565 Lisp_Object mini = f->minibuffer_window;
3566 struct window *m;
3567 /* new_size is the new size of the frame's root window. */
3568 int new_size = (horflag
3569 ? size
3570 : (size
3571 - FRAME_TOP_MARGIN (f)
3572 - ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
3573 ? 1 : 0)));
3575 XSETFASTINT (r->top_line, FRAME_TOP_MARGIN (f));
3576 if (NILP (r->vchild) && NILP (r->hchild))
3577 /* For a leaf root window just set the size. */
3578 if (horflag)
3579 XSETFASTINT (r->total_cols, new_size);
3580 else
3581 XSETFASTINT (r->total_lines, new_size);
3582 else
3584 /* old_size is the old size of the frame's root window. */
3585 int old_size = XFASTINT (horflag ? r->total_cols : r->total_lines);
3586 Lisp_Object delta;
3588 XSETINT (delta, new_size - old_size);
3589 /* Try a "normal" resize first. */
3590 resize_root_window (root, delta, horflag ? Qt : Qnil, Qnil);
3591 if (window_resize_check (r, horflag) && new_size == XINT (r->new_total))
3592 window_resize_apply (r, horflag);
3593 else
3595 /* Try with "reasonable" minimum sizes next. */
3596 resize_root_window (root, delta, horflag ? Qt : Qnil, Qt);
3597 if (window_resize_check (r, horflag)
3598 && new_size == XINT (r->new_total))
3599 window_resize_apply (r, horflag);
3600 else
3602 /* Finally, try with "safe" minimum sizes. */
3603 resize_root_window (root, delta, horflag ? Qt : Qnil, Qsafe);
3604 if (window_resize_check (r, horflag)
3605 && new_size == XINT (r->new_total))
3606 window_resize_apply (r, horflag);
3607 else
3609 /* We lost. Delete all windows but the frame's
3610 selected one. */
3611 root = f->selected_window;
3612 Fdelete_other_windows_internal (root, Qnil);
3613 if (horflag)
3614 XSETFASTINT (XWINDOW (root)->total_cols, new_size);
3615 else
3616 XSETFASTINT (XWINDOW (root)->total_lines, new_size);
3622 if (FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
3624 m = XWINDOW (mini);
3625 if (horflag)
3626 XSETFASTINT (m->total_cols, size);
3627 else
3629 /* Are we sure we always want 1 line here? */
3630 XSETFASTINT (m->total_lines, 1);
3631 XSETFASTINT (m->top_line, XINT (r->top_line) + XINT (r->total_lines));
3637 DEFUN ("split-window-internal", Fsplit_window_internal, Ssplit_window_internal, 4, 4, 0,
3638 doc: /* Split window OLD.
3639 Second argument TOTAL-SIZE specifies the number of lines or columns of the
3640 new window. In any case TOTAL-SIZE must be a positive integer.
3642 Third argument SIDE nil (or `below') specifies that the new window shall
3643 be located below WINDOW. SIDE `above' means the new window shall be
3644 located above WINDOW. In both cases TOTAL-SIZE specifies the number of
3645 lines of the new window including space reserved for the mode and/or
3646 header line.
3648 SIDE t (or `right') specifies that the new window shall be located on
3649 the right side of WINDOW. SIDE `left' means the new window shall be
3650 located on the left of WINDOW. In both cases TOTAL-SIZE specifies the
3651 number of columns of the new window including space reserved for fringes
3652 and the scrollbar or a divider column.
3654 Fourth argument NORMAL-SIZE specifies the normal size of the new window
3655 according to the SIDE argument.
3657 The new total and normal sizes of all involved windows must have been
3658 set correctly. See the code of `split-window' for how this is done. */)
3659 (Lisp_Object old, Lisp_Object total_size, Lisp_Object side, Lisp_Object normal_size)
3661 /* OLD (*o) is the window we have to split. (*p) is either OLD's
3662 parent window or an internal window we have to install as OLD's new
3663 parent. REFERENCE (*r) must denote a live window, or is set to OLD
3664 provided OLD is a leaf window, or to the frame's selected window.
3665 NEW (*n) is the new window created with some parameters taken from
3666 REFERENCE (*r). */
3667 register Lisp_Object new, frame, reference;
3668 register struct window *o, *p, *n, *r;
3669 struct frame *f;
3670 int horflag
3671 /* HORFLAG is 1 when we split side-by-side, 0 otherwise. */
3672 = EQ (side, Qt) || EQ (side, Qleft) || EQ (side, Qright);
3673 int combination_limit = 0;
3675 CHECK_WINDOW (old);
3676 o = XWINDOW (old);
3677 frame = WINDOW_FRAME (o);
3678 f = XFRAME (frame);
3680 CHECK_NUMBER (total_size);
3682 /* Set combination_limit to 1 if we have to make a new parent window.
3683 We do that if either `window-combination-limit' is t, or OLD has no
3684 parent, or OLD is ortho-combined. */
3685 combination_limit =
3686 !NILP (Vwindow_combination_limit)
3687 || NILP (o->parent)
3688 || NILP (horflag
3689 ? (XWINDOW (o->parent)->hchild)
3690 : (XWINDOW (o->parent)->vchild));
3692 /* We need a live reference window to initialize some parameters. */
3693 if (WINDOW_LIVE_P (old))
3694 /* OLD is live, use it as reference window. */
3695 reference = old;
3696 else
3697 /* Use the frame's selected window as reference window. */
3698 reference = FRAME_SELECTED_WINDOW (f);
3699 r = XWINDOW (reference);
3701 /* The following bugs are caught by `split-window'. */
3702 if (MINI_WINDOW_P (o))
3703 error ("Attempt to split minibuffer window");
3704 else if (XINT (total_size) < (horflag ? 2 : 1))
3705 error ("Size of new window too small (after split)");
3706 else if (!combination_limit && !NILP (Vwindow_combination_resize))
3707 /* `window-combination-resize' non-nil means try to resize OLD's siblings
3708 proportionally. */
3710 p = XWINDOW (o->parent);
3711 /* Temporarily pretend we split the parent window. */
3712 XSETINT (p->new_total,
3713 XINT (horflag ? p->total_cols : p->total_lines)
3714 - XINT (total_size));
3715 if (!window_resize_check (p, horflag))
3716 error ("Window sizes don't fit");
3717 else
3718 /* Undo the temporary pretension. */
3719 p->new_total = horflag ? p->total_cols : p->total_lines;
3721 else
3723 if (!window_resize_check (o, horflag))
3724 error ("Resizing old window failed");
3725 else if (XINT (total_size) + XINT (o->new_total)
3726 != XINT (horflag ? o->total_cols : o->total_lines))
3727 error ("Sum of sizes of old and new window don't fit");
3730 /* This is our point of no return. */
3731 if (combination_limit)
3733 /* Save the old value of o->normal_cols/lines. It gets corrupted
3734 by make_parent_window and we need it below for assigning it to
3735 p->new_normal. */
3736 Lisp_Object new_normal = horflag ? o->normal_cols : o->normal_lines;
3738 make_parent_window (old, horflag);
3739 p = XWINDOW (o->parent);
3740 /* Store value of `window-combination-limit' in new parent's
3741 combination_limit slot. */
3742 p->combination_limit = Vwindow_combination_limit;
3743 /* These get applied below. */
3744 p->new_total = horflag ? o->total_cols : o->total_lines;
3745 p->new_normal = new_normal;
3747 else
3748 p = XWINDOW (o->parent);
3750 windows_or_buffers_changed++;
3751 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
3752 new = make_window ();
3753 n = XWINDOW (new);
3754 n->frame = frame;
3755 n->parent = o->parent;
3756 n->vchild = n->hchild = Qnil;
3758 if (EQ (side, Qabove) || EQ (side, Qleft))
3760 n->prev = o->prev;
3761 if (NILP (n->prev))
3762 if (horflag)
3763 p->hchild = new;
3764 else
3765 p->vchild = new;
3766 else
3767 XWINDOW (n->prev)->next = new;
3768 n->next = old;
3769 o->prev = new;
3771 else
3773 n->next = o->next;
3774 if (!NILP (n->next))
3775 XWINDOW (n->next)->prev = new;
3776 n->prev = old;
3777 o->next = new;
3780 n->buffer = Qt;
3781 n->window_end_valid = Qnil;
3782 memset (&n->last_cursor, 0, sizeof n->last_cursor);
3784 /* Get special geometry settings from reference window. */
3785 n->left_margin_cols = r->left_margin_cols;
3786 n->right_margin_cols = r->right_margin_cols;
3787 n->left_fringe_width = r->left_fringe_width;
3788 n->right_fringe_width = r->right_fringe_width;
3789 n->fringes_outside_margins = r->fringes_outside_margins;
3790 n->scroll_bar_width = r->scroll_bar_width;
3791 n->vertical_scroll_bar_type = r->vertical_scroll_bar_type;
3793 /* Directly assign orthogonal coordinates and sizes. */
3794 if (horflag)
3796 n->top_line = o->top_line;
3797 n->total_lines = o->total_lines;
3799 else
3801 n->left_col = o->left_col;
3802 n->total_cols = o->total_cols;
3805 /* Iso-coordinates and sizes are assigned by window_resize_apply,
3806 get them ready here. */
3807 n->new_total = total_size;
3808 n->new_normal = normal_size;
3810 BLOCK_INPUT;
3811 window_resize_apply (p, horflag);
3812 adjust_glyphs (f);
3813 /* Set buffer of NEW to buffer of reference window. Don't run
3814 any hooks. */
3815 set_window_buffer (new, r->buffer, 0, 1);
3816 UNBLOCK_INPUT;
3818 /* Maybe we should run the scroll functions in Elisp (which already
3819 runs the configuration change hook). */
3820 if (! NILP (Vwindow_scroll_functions))
3821 run_hook_with_args_2 (Qwindow_scroll_functions, new,
3822 Fmarker_position (n->start));
3823 /* Return NEW. */
3824 return new;
3828 DEFUN ("delete-window-internal", Fdelete_window_internal, Sdelete_window_internal, 1, 1, 0,
3829 doc: /* Remove WINDOW from its frame.
3830 WINDOW defaults to the selected window. Return nil.
3831 Signal an error when WINDOW is the only window on its frame. */)
3832 (register Lisp_Object window)
3834 register Lisp_Object parent, sibling, frame, root;
3835 struct window *w, *p, *s, *r;
3836 struct frame *f;
3837 int horflag;
3838 int before_sibling = 0;
3840 w = decode_any_window (window);
3841 XSETWINDOW (window, w);
3842 if (NILP (w->buffer) && NILP (w->hchild) && NILP (w->vchild))
3843 /* It's a no-op to delete an already deleted window. */
3844 return Qnil;
3846 parent = w->parent;
3847 if (NILP (parent))
3848 /* Never delete a minibuffer or frame root window. */
3849 error ("Attempt to delete minibuffer or sole ordinary window");
3850 else if (NILP (w->prev) && NILP (w->next))
3851 /* Rather bow out here, this case should be handled on the Elisp
3852 level. */
3853 error ("Attempt to delete sole window of parent");
3855 p = XWINDOW (parent);
3856 horflag = NILP (p->vchild);
3858 frame = WINDOW_FRAME (w);
3859 f = XFRAME (frame);
3861 root = FRAME_ROOT_WINDOW (f);
3862 r = XWINDOW (root);
3864 /* Unlink WINDOW from window tree. */
3865 if (NILP (w->prev))
3866 /* Get SIBLING below (on the right of) WINDOW. */
3868 /* before_sibling 1 means WINDOW is the first child of its
3869 parent and thus before the sibling. */
3870 before_sibling = 1;
3871 sibling = w->next;
3872 s = XWINDOW (sibling);
3873 s->prev = Qnil;
3874 if (horflag)
3875 p->hchild = sibling;
3876 else
3877 p->vchild = sibling;
3879 else
3880 /* Get SIBLING above (on the left of) WINDOW. */
3882 sibling = w->prev;
3883 s = XWINDOW (sibling);
3884 s->next = w->next;
3885 if (!NILP (s->next))
3886 XWINDOW (s->next)->prev = sibling;
3889 if (window_resize_check (r, horflag)
3890 && EQ (r->new_total, (horflag ? r->total_cols : r->total_lines)))
3891 /* We can delete WINDOW now. */
3893 /* Block input. */
3894 BLOCK_INPUT;
3895 window_resize_apply (p, horflag);
3897 windows_or_buffers_changed++;
3898 Vwindow_list = Qnil;
3899 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
3901 w->next = Qnil; /* Don't delete w->next too. */
3902 free_window_matrices (w);
3904 if (!NILP (w->vchild))
3906 delete_all_child_windows (w->vchild);
3907 w->vchild = Qnil;
3909 else if (!NILP (w->hchild))
3911 delete_all_child_windows (w->hchild);
3912 w->hchild = Qnil;
3914 else if (!NILP (w->buffer))
3916 unshow_buffer (w);
3917 unchain_marker (XMARKER (w->pointm));
3918 unchain_marker (XMARKER (w->start));
3919 w->buffer = Qnil;
3922 if (NILP (s->prev) && NILP (s->next))
3923 /* A matrjoshka where SIBLING has become the only child of
3924 PARENT. */
3926 /* Put SIBLING into PARENT's place. */
3927 replace_window (parent, sibling, 0);
3928 /* Have SIBLING inherit the following three slot values from
3929 PARENT (the combination_limit slot is not inherited). */
3930 s->normal_cols = p->normal_cols;
3931 s->normal_lines = p->normal_lines;
3932 /* Mark PARENT as deleted. */
3933 p->vchild = p->hchild = Qnil;
3934 /* Try to merge SIBLING into its new parent. */
3935 recombine_windows (sibling);
3938 adjust_glyphs (f);
3940 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f)))
3941 /* We deleted the frame's selected window. */
3943 /* Use the frame's first window as fallback ... */
3944 Lisp_Object new_selected_window = Fframe_first_window (frame);
3945 /* ... but preferably use its most recently used window. */
3946 Lisp_Object mru_window;
3948 /* `get-mru-window' might fail for some reason so play it safe
3949 - promote the first window _without recording it_ first. */
3950 if (EQ (FRAME_SELECTED_WINDOW (f), selected_window))
3951 Fselect_window (new_selected_window, Qt);
3952 else
3953 FRAME_SELECTED_WINDOW (f) = new_selected_window;
3955 UNBLOCK_INPUT;
3957 /* Now look whether `get-mru-window' gets us something. */
3958 mru_window = call1 (Qget_mru_window, frame);
3959 if (WINDOW_LIVE_P (mru_window)
3960 && EQ (XWINDOW (mru_window)->frame, frame))
3961 new_selected_window = mru_window;
3963 /* If all ended up well, we now promote the mru window. */
3964 if (EQ (FRAME_SELECTED_WINDOW (f), selected_window))
3965 Fselect_window (new_selected_window, Qnil);
3966 else
3967 FRAME_SELECTED_WINDOW (f) = new_selected_window;
3969 else
3970 UNBLOCK_INPUT;
3972 /* Must be run by the caller:
3973 run_window_configuration_change_hook (f); */
3975 else
3976 /* We failed: Relink WINDOW into window tree. */
3978 if (before_sibling)
3980 s->prev = window;
3981 if (horflag)
3982 p->hchild = window;
3983 else
3984 p->vchild = window;
3986 else
3988 s->next = window;
3989 if (!NILP (w->next))
3990 XWINDOW (w->next)->prev = window;
3992 error ("Deletion failed");
3995 return Qnil;
3998 /***********************************************************************
3999 Resizing Mini-Windows
4000 ***********************************************************************/
4002 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we
4003 can. */
4004 void
4005 grow_mini_window (struct window *w, int delta)
4007 struct frame *f = XFRAME (w->frame);
4008 struct window *r;
4009 Lisp_Object root, value;
4011 xassert (MINI_WINDOW_P (w));
4012 xassert (delta >= 0);
4014 root = FRAME_ROOT_WINDOW (f);
4015 r = XWINDOW (root);
4016 value = call2 (Qwindow_resize_root_window_vertically,
4017 root, make_number (- delta));
4018 if (INTEGERP (value) && window_resize_check (r, 0))
4020 BLOCK_INPUT;
4021 window_resize_apply (r, 0);
4023 /* Grow the mini-window. */
4024 XSETFASTINT (w->top_line, XFASTINT (r->top_line) + XFASTINT (r->total_lines));
4025 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - XINT (value));
4026 XSETFASTINT (w->last_modified, 0);
4027 XSETFASTINT (w->last_overlay_modified, 0);
4029 adjust_glyphs (f);
4030 UNBLOCK_INPUT;
4035 /* Shrink mini-window W. */
4036 void
4037 shrink_mini_window (struct window *w)
4039 struct frame *f = XFRAME (w->frame);
4040 struct window *r;
4041 Lisp_Object root, value;
4042 EMACS_INT size;
4044 xassert (MINI_WINDOW_P (w));
4046 size = XINT (w->total_lines);
4047 if (size > 1)
4049 root = FRAME_ROOT_WINDOW (f);
4050 r = XWINDOW (root);
4051 value = call2 (Qwindow_resize_root_window_vertically,
4052 root, make_number (size - 1));
4053 if (INTEGERP (value) && window_resize_check (r, 0))
4055 BLOCK_INPUT;
4056 window_resize_apply (r, 0);
4058 /* Shrink the mini-window. */
4059 XSETFASTINT (w->top_line, XFASTINT (r->top_line) + XFASTINT (r->total_lines));
4060 XSETFASTINT (w->total_lines, 1);
4062 XSETFASTINT (w->last_modified, 0);
4063 XSETFASTINT (w->last_overlay_modified, 0);
4065 adjust_glyphs (f);
4066 UNBLOCK_INPUT;
4068 /* If the above failed for whatever strange reason we must make a
4069 one window frame here. The same routine will be needed when
4070 shrinking the frame (and probably when making the initial
4071 *scratch* window). For the moment leave things as they are. */
4075 DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini_window_internal, 1, 1, 0,
4076 doc: /* Resize minibuffer window WINDOW. */)
4077 (Lisp_Object window)
4079 struct window *w = XWINDOW (window);
4080 struct window *r;
4081 struct frame *f;
4082 int height;
4084 CHECK_WINDOW (window);
4085 f = XFRAME (w->frame);
4087 if (!EQ (FRAME_MINIBUF_WINDOW (XFRAME (w->frame)), window))
4088 error ("Not a valid minibuffer window");
4089 else if (FRAME_MINIBUF_ONLY_P (f))
4090 error ("Cannot resize a minibuffer-only frame");
4092 r = XWINDOW (FRAME_ROOT_WINDOW (f));
4093 height = XINT (r->total_lines) + XINT (w->total_lines);
4094 if (window_resize_check (r, 0)
4095 && XINT (w->new_total) > 0
4096 && height == XINT (r->new_total) + XINT (w->new_total))
4098 BLOCK_INPUT;
4099 window_resize_apply (r, 0);
4101 w->total_lines = w->new_total;
4102 XSETFASTINT (w->top_line, XINT (r->top_line) + XINT (r->total_lines));
4104 windows_or_buffers_changed++;
4105 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
4106 adjust_glyphs (f);
4107 UNBLOCK_INPUT;
4109 run_window_configuration_change_hook (f);
4110 return Qt;
4112 else error ("Failed to resize minibuffer window");
4115 /* Mark window cursors off for all windows in the window tree rooted
4116 at W by setting their phys_cursor_on_p flag to zero. Called from
4117 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4118 the frame are cleared. */
4120 void
4121 mark_window_cursors_off (struct window *w)
4123 while (w)
4125 if (!NILP (w->hchild))
4126 mark_window_cursors_off (XWINDOW (w->hchild));
4127 else if (!NILP (w->vchild))
4128 mark_window_cursors_off (XWINDOW (w->vchild));
4129 else
4130 w->phys_cursor_on_p = 0;
4132 w = NILP (w->next) ? 0 : XWINDOW (w->next);
4137 /* Return number of lines of text (not counting mode lines) in W. */
4140 window_internal_height (struct window *w)
4142 int ht = XFASTINT (w->total_lines);
4144 if (!MINI_WINDOW_P (w))
4146 if (!NILP (w->parent)
4147 || !NILP (w->vchild)
4148 || !NILP (w->hchild)
4149 || !NILP (w->next)
4150 || !NILP (w->prev)
4151 || WINDOW_WANTS_MODELINE_P (w))
4152 --ht;
4154 if (WINDOW_WANTS_HEADER_LINE_P (w))
4155 --ht;
4158 return ht;
4161 /************************************************************************
4162 Window Scrolling
4163 ***********************************************************************/
4165 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4166 N screen-fulls, which is defined as the height of the window minus
4167 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4168 instead. Negative values of N mean scroll down. NOERROR non-zero
4169 means don't signal an error if we try to move over BEGV or ZV,
4170 respectively. */
4172 static void
4173 window_scroll (Lisp_Object window, EMACS_INT n, int whole, int noerror)
4175 immediate_quit = 1;
4176 n = clip_to_bounds (INT_MIN, n, INT_MAX);
4178 /* If we must, use the pixel-based version which is much slower than
4179 the line-based one but can handle varying line heights. */
4180 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window)->frame)))
4181 window_scroll_pixel_based (window, n, whole, noerror);
4182 else
4183 window_scroll_line_based (window, n, whole, noerror);
4185 immediate_quit = 0;
4189 /* Implementation of window_scroll that works based on pixel line
4190 heights. See the comment of window_scroll for parameter
4191 descriptions. */
4193 static void
4194 window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4196 struct it it;
4197 struct window *w = XWINDOW (window);
4198 struct text_pos start;
4199 int this_scroll_margin;
4200 /* True if we fiddled the window vscroll field without really scrolling. */
4201 int vscrolled = 0;
4202 int x, y, rtop, rbot, rowh, vpos;
4203 void *itdata = NULL;
4205 SET_TEXT_POS_FROM_MARKER (start, w->start);
4207 /* If PT is not visible in WINDOW, move back one half of
4208 the screen. Allow PT to be partially visible, otherwise
4209 something like (scroll-down 1) with PT in the line before
4210 the partially visible one would recenter. */
4212 if (!pos_visible_p (w, PT, &x, &y, &rtop, &rbot, &rowh, &vpos))
4214 itdata = bidi_shelve_cache ();
4215 /* Move backward half the height of the window. Performance note:
4216 vmotion used here is about 10% faster, but would give wrong
4217 results for variable height lines. */
4218 init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID);
4219 it.current_y = it.last_visible_y;
4220 move_it_vertically_backward (&it, window_box_height (w) / 2);
4222 /* The function move_iterator_vertically may move over more than
4223 the specified y-distance. If it->w is small, e.g. a
4224 mini-buffer window, we may end up in front of the window's
4225 display area. This is the case when Start displaying at the
4226 start of the line containing PT in this case. */
4227 if (it.current_y <= 0)
4229 init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID);
4230 move_it_vertically_backward (&it, 0);
4231 it.current_y = 0;
4234 start = it.current.pos;
4235 bidi_unshelve_cache (itdata, 0);
4237 else if (auto_window_vscroll_p)
4239 if (rtop || rbot) /* partially visible */
4241 int px;
4242 int dy = WINDOW_FRAME_LINE_HEIGHT (w);
4243 if (whole)
4244 dy = max ((window_box_height (w)
4245 - next_screen_context_lines * dy),
4246 dy);
4247 dy *= n;
4249 if (n < 0)
4251 /* Only vscroll backwards if already vscrolled forwards. */
4252 if (w->vscroll < 0 && rtop > 0)
4254 px = max (0, -w->vscroll - min (rtop, -dy));
4255 Fset_window_vscroll (window, make_number (px), Qt);
4256 return;
4259 if (n > 0)
4261 /* Do vscroll if already vscrolled or only display line. */
4262 if (rbot > 0 && (w->vscroll < 0 || vpos == 0))
4264 px = max (0, -w->vscroll + min (rbot, dy));
4265 Fset_window_vscroll (window, make_number (px), Qt);
4266 return;
4269 /* Maybe modify window start instead of scrolling. */
4270 if (rbot > 0 || w->vscroll < 0)
4272 ptrdiff_t spos;
4274 Fset_window_vscroll (window, make_number (0), Qt);
4275 /* If there are other text lines above the current row,
4276 move window start to current row. Else to next row. */
4277 if (rbot > 0)
4278 spos = XINT (Fline_beginning_position (Qnil));
4279 else
4280 spos = min (XINT (Fline_end_position (Qnil)) + 1, ZV);
4281 set_marker_restricted (w->start, make_number (spos),
4282 w->buffer);
4283 w->start_at_line_beg = Qt;
4284 w->update_mode_line = Qt;
4285 XSETFASTINT (w->last_modified, 0);
4286 XSETFASTINT (w->last_overlay_modified, 0);
4287 /* Set force_start so that redisplay_window will run the
4288 window-scroll-functions. */
4289 w->force_start = Qt;
4290 return;
4294 /* Cancel previous vscroll. */
4295 Fset_window_vscroll (window, make_number (0), Qt);
4298 itdata = bidi_shelve_cache ();
4299 /* If scroll_preserve_screen_position is non-nil, we try to set
4300 point in the same window line as it is now, so get that line. */
4301 if (!NILP (Vscroll_preserve_screen_position))
4303 /* We preserve the goal pixel coordinate across consecutive
4304 calls to scroll-up, scroll-down and other commands that
4305 have the `scroll-command' property. This avoids the
4306 possibility of point becoming "stuck" on a tall line when
4307 scrolling by one line. */
4308 if (window_scroll_pixel_based_preserve_y < 0
4309 || !SYMBOLP (KVAR (current_kboard, Vlast_command))
4310 || NILP (Fget (KVAR (current_kboard, Vlast_command), Qscroll_command)))
4312 start_display (&it, w, start);
4313 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
4314 window_scroll_pixel_based_preserve_y = it.current_y;
4315 window_scroll_pixel_based_preserve_x = it.current_x;
4318 else
4319 window_scroll_pixel_based_preserve_y
4320 = window_scroll_pixel_based_preserve_x = -1;
4322 /* Move iterator it from start the specified distance forward or
4323 backward. The result is the new window start. */
4324 start_display (&it, w, start);
4325 if (whole)
4327 ptrdiff_t start_pos = IT_CHARPOS (it);
4328 int dy = WINDOW_FRAME_LINE_HEIGHT (w);
4329 dy = max ((window_box_height (w)
4330 - next_screen_context_lines * dy),
4331 dy) * n;
4333 /* Note that move_it_vertically always moves the iterator to the
4334 start of a line. So, if the last line doesn't have a newline,
4335 we would end up at the start of the line ending at ZV. */
4336 if (dy <= 0)
4338 move_it_vertically_backward (&it, -dy);
4339 /* Ensure we actually do move, e.g. in case we are currently
4340 looking at an image that is taller that the window height. */
4341 while (start_pos == IT_CHARPOS (it)
4342 && start_pos > BEGV)
4343 move_it_by_lines (&it, -1);
4345 else if (dy > 0)
4347 move_it_to (&it, ZV, -1, it.current_y + dy, -1,
4348 MOVE_TO_POS | MOVE_TO_Y);
4349 /* Ensure we actually do move, e.g. in case we are currently
4350 looking at an image that is taller that the window height. */
4351 while (start_pos == IT_CHARPOS (it)
4352 && start_pos < ZV)
4353 move_it_by_lines (&it, 1);
4356 else
4357 move_it_by_lines (&it, n);
4359 /* We failed if we find ZV is already on the screen (scrolling up,
4360 means there's nothing past the end), or if we can't start any
4361 earlier (scrolling down, means there's nothing past the top). */
4362 if ((n > 0 && IT_CHARPOS (it) == ZV)
4363 || (n < 0 && IT_CHARPOS (it) == CHARPOS (start)))
4365 if (IT_CHARPOS (it) == ZV)
4367 if (it.current_y < it.last_visible_y
4368 && (it.current_y + it.max_ascent + it.max_descent
4369 > it.last_visible_y))
4371 /* The last line was only partially visible, make it fully
4372 visible. */
4373 w->vscroll = (it.last_visible_y
4374 - it.current_y + it.max_ascent + it.max_descent);
4375 adjust_glyphs (it.f);
4377 else
4379 bidi_unshelve_cache (itdata, 0);
4380 if (noerror)
4381 return;
4382 else if (n < 0) /* could happen with empty buffers */
4383 xsignal0 (Qbeginning_of_buffer);
4384 else
4385 xsignal0 (Qend_of_buffer);
4388 else
4390 if (w->vscroll != 0)
4391 /* The first line was only partially visible, make it fully
4392 visible. */
4393 w->vscroll = 0;
4394 else
4396 bidi_unshelve_cache (itdata, 0);
4397 if (noerror)
4398 return;
4399 else
4400 xsignal0 (Qbeginning_of_buffer);
4404 /* If control gets here, then we vscrolled. */
4406 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
4408 /* Don't try to change the window start below. */
4409 vscrolled = 1;
4412 if (! vscrolled)
4414 ptrdiff_t pos = IT_CHARPOS (it);
4415 ptrdiff_t bytepos;
4417 /* If in the middle of a multi-glyph character move forward to
4418 the next character. */
4419 if (in_display_vector_p (&it))
4421 ++pos;
4422 move_it_to (&it, pos, -1, -1, -1, MOVE_TO_POS);
4425 /* Set the window start, and set up the window for redisplay. */
4426 set_marker_restricted (w->start, make_number (pos),
4427 w->buffer);
4428 bytepos = XMARKER (w->start)->bytepos;
4429 w->start_at_line_beg = ((pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n')
4430 ? Qt : Qnil);
4431 w->update_mode_line = Qt;
4432 XSETFASTINT (w->last_modified, 0);
4433 XSETFASTINT (w->last_overlay_modified, 0);
4434 /* Set force_start so that redisplay_window will run the
4435 window-scroll-functions. */
4436 w->force_start = Qt;
4439 /* The rest of this function uses current_y in a nonstandard way,
4440 not including the height of the header line if any. */
4441 it.current_y = it.vpos = 0;
4443 /* Move PT out of scroll margins.
4444 This code wants current_y to be zero at the window start position
4445 even if there is a header line. */
4446 this_scroll_margin = max (0, scroll_margin);
4447 this_scroll_margin = min (this_scroll_margin, XFASTINT (w->total_lines) / 4);
4448 this_scroll_margin *= FRAME_LINE_HEIGHT (it.f);
4450 if (n > 0)
4452 /* We moved the window start towards ZV, so PT may be now
4453 in the scroll margin at the top. */
4454 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
4455 if (IT_CHARPOS (it) == PT && it.current_y >= this_scroll_margin
4456 && (NILP (Vscroll_preserve_screen_position)
4457 || EQ (Vscroll_preserve_screen_position, Qt)))
4458 /* We found PT at a legitimate height. Leave it alone. */
4460 else if (window_scroll_pixel_based_preserve_y >= 0)
4462 /* If we have a header line, take account of it.
4463 This is necessary because we set it.current_y to 0, above. */
4464 move_it_to (&it, -1,
4465 window_scroll_pixel_based_preserve_x,
4466 window_scroll_pixel_based_preserve_y
4467 - (WINDOW_WANTS_HEADER_LINE_P (w) ? 1 : 0 ),
4468 -1, MOVE_TO_Y | MOVE_TO_X);
4469 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4471 else
4473 while (it.current_y < this_scroll_margin)
4475 int prev = it.current_y;
4476 move_it_by_lines (&it, 1);
4477 if (prev == it.current_y)
4478 break;
4480 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4483 else if (n < 0)
4485 ptrdiff_t charpos, bytepos;
4486 int partial_p;
4488 /* Save our position, for the
4489 window_scroll_pixel_based_preserve_y case. */
4490 charpos = IT_CHARPOS (it);
4491 bytepos = IT_BYTEPOS (it);
4493 /* We moved the window start towards BEGV, so PT may be now
4494 in the scroll margin at the bottom. */
4495 move_it_to (&it, PT, -1,
4496 (it.last_visible_y - CURRENT_HEADER_LINE_HEIGHT (w)
4497 - this_scroll_margin - 1),
4499 MOVE_TO_POS | MOVE_TO_Y);
4501 /* Save our position, in case it's correct. */
4502 charpos = IT_CHARPOS (it);
4503 bytepos = IT_BYTEPOS (it);
4505 /* See if point is on a partially visible line at the end. */
4506 if (it.what == IT_EOB)
4507 partial_p = it.current_y + it.ascent + it.descent > it.last_visible_y;
4508 else
4510 move_it_by_lines (&it, 1);
4511 partial_p = it.current_y > it.last_visible_y;
4514 if (charpos == PT && !partial_p
4515 && (NILP (Vscroll_preserve_screen_position)
4516 || EQ (Vscroll_preserve_screen_position, Qt)))
4517 /* We found PT before we found the display margin, so PT is ok. */
4519 else if (window_scroll_pixel_based_preserve_y >= 0)
4521 SET_TEXT_POS_FROM_MARKER (start, w->start);
4522 start_display (&it, w, start);
4523 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
4524 here because we called start_display again and did not
4525 alter it.current_y this time. */
4526 move_it_to (&it, -1, window_scroll_pixel_based_preserve_x,
4527 window_scroll_pixel_based_preserve_y, -1,
4528 MOVE_TO_Y | MOVE_TO_X);
4529 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4531 else
4533 if (partial_p)
4534 /* The last line was only partially visible, so back up two
4535 lines to make sure we're on a fully visible line. */
4537 move_it_by_lines (&it, -2);
4538 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4540 else
4541 /* No, the position we saved is OK, so use it. */
4542 SET_PT_BOTH (charpos, bytepos);
4545 bidi_unshelve_cache (itdata, 0);
4549 /* Implementation of window_scroll that works based on screen lines.
4550 See the comment of window_scroll for parameter descriptions. */
4552 static void
4553 window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4555 register struct window *w = XWINDOW (window);
4556 /* Fvertical_motion enters redisplay, which can trigger
4557 fontification, which in turn can modify buffer text (e.g., if the
4558 fontification functions replace escape sequences with faces, as
4559 in `grep-mode-font-lock-keywords'). So we use a marker to record
4560 the old point position, to prevent crashes in SET_PT_BOTH. */
4561 Lisp_Object opoint_marker = Fpoint_marker ();
4562 register ptrdiff_t pos, pos_byte;
4563 register int ht = window_internal_height (w);
4564 register Lisp_Object tem;
4565 int lose;
4566 Lisp_Object bolp;
4567 ptrdiff_t startpos;
4568 Lisp_Object original_pos = Qnil;
4570 /* If scrolling screen-fulls, compute the number of lines to
4571 scroll from the window's height. */
4572 if (whole)
4573 n *= max (1, ht - next_screen_context_lines);
4575 startpos = marker_position (w->start);
4577 if (!NILP (Vscroll_preserve_screen_position))
4579 if (window_scroll_preserve_vpos <= 0
4580 || !SYMBOLP (KVAR (current_kboard, Vlast_command))
4581 || NILP (Fget (KVAR (current_kboard, Vlast_command), Qscroll_command)))
4583 struct position posit
4584 = *compute_motion (startpos, 0, 0, 0,
4585 PT, ht, 0,
4586 -1, XINT (w->hscroll),
4587 0, w);
4588 window_scroll_preserve_vpos = posit.vpos;
4589 window_scroll_preserve_hpos = posit.hpos + XINT (w->hscroll);
4592 original_pos = Fcons (make_number (window_scroll_preserve_hpos),
4593 make_number (window_scroll_preserve_vpos));
4596 XSETFASTINT (tem, PT);
4597 tem = Fpos_visible_in_window_p (tem, window, Qnil);
4599 if (NILP (tem))
4601 Fvertical_motion (make_number (- (ht / 2)), window);
4602 startpos = PT;
4605 SET_PT (startpos);
4606 lose = n < 0 && PT == BEGV;
4607 Fvertical_motion (make_number (n), window);
4608 pos = PT;
4609 pos_byte = PT_BYTE;
4610 bolp = Fbolp ();
4611 SET_PT_BOTH (marker_position (opoint_marker),
4612 marker_byte_position (opoint_marker));
4614 if (lose)
4616 if (noerror)
4617 return;
4618 else
4619 xsignal0 (Qbeginning_of_buffer);
4622 if (pos < ZV)
4624 /* Don't use a scroll margin that is negative or too large. */
4625 int this_scroll_margin =
4626 max (0, min (scroll_margin, XINT (w->total_lines) / 4));
4628 set_marker_restricted_both (w->start, w->buffer, pos, pos_byte);
4629 w->start_at_line_beg = bolp;
4630 w->update_mode_line = Qt;
4631 XSETFASTINT (w->last_modified, 0);
4632 XSETFASTINT (w->last_overlay_modified, 0);
4633 /* Set force_start so that redisplay_window will run
4634 the window-scroll-functions. */
4635 w->force_start = Qt;
4637 if (!NILP (Vscroll_preserve_screen_position)
4638 && (whole || !EQ (Vscroll_preserve_screen_position, Qt)))
4640 SET_PT_BOTH (pos, pos_byte);
4641 Fvertical_motion (original_pos, window);
4643 /* If we scrolled forward, put point enough lines down
4644 that it is outside the scroll margin. */
4645 else if (n > 0)
4647 int top_margin;
4649 if (this_scroll_margin > 0)
4651 SET_PT_BOTH (pos, pos_byte);
4652 Fvertical_motion (make_number (this_scroll_margin), window);
4653 top_margin = PT;
4655 else
4656 top_margin = pos;
4658 if (top_margin <= marker_position (opoint_marker))
4659 SET_PT_BOTH (marker_position (opoint_marker),
4660 marker_byte_position (opoint_marker));
4661 else if (!NILP (Vscroll_preserve_screen_position))
4663 SET_PT_BOTH (pos, pos_byte);
4664 Fvertical_motion (original_pos, window);
4666 else
4667 SET_PT (top_margin);
4669 else if (n < 0)
4671 int bottom_margin;
4673 /* If we scrolled backward, put point near the end of the window
4674 but not within the scroll margin. */
4675 SET_PT_BOTH (pos, pos_byte);
4676 tem = Fvertical_motion (make_number (ht - this_scroll_margin), window);
4677 if (XFASTINT (tem) == ht - this_scroll_margin)
4678 bottom_margin = PT;
4679 else
4680 bottom_margin = PT + 1;
4682 if (bottom_margin > marker_position (opoint_marker))
4683 SET_PT_BOTH (marker_position (opoint_marker),
4684 marker_byte_position (opoint_marker));
4685 else
4687 if (!NILP (Vscroll_preserve_screen_position))
4689 SET_PT_BOTH (pos, pos_byte);
4690 Fvertical_motion (original_pos, window);
4692 else
4693 Fvertical_motion (make_number (-1), window);
4697 else
4699 if (noerror)
4700 return;
4701 else
4702 xsignal0 (Qend_of_buffer);
4707 /* Scroll selected_window up or down. If N is nil, scroll a
4708 screen-full which is defined as the height of the window minus
4709 next_screen_context_lines. If N is the symbol `-', scroll.
4710 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4711 up. This is the guts of Fscroll_up and Fscroll_down. */
4713 static void
4714 scroll_command (Lisp_Object n, int direction)
4716 ptrdiff_t count = SPECPDL_INDEX ();
4718 xassert (eabs (direction) == 1);
4720 /* If selected window's buffer isn't current, make it current for
4721 the moment. But don't screw up if window_scroll gets an error. */
4722 if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
4724 record_unwind_protect (save_excursion_restore, save_excursion_save ());
4725 Fset_buffer (XWINDOW (selected_window)->buffer);
4727 /* Make redisplay consider other windows than just selected_window. */
4728 ++windows_or_buffers_changed;
4731 if (NILP (n))
4732 window_scroll (selected_window, direction, 1, 0);
4733 else if (EQ (n, Qminus))
4734 window_scroll (selected_window, -direction, 1, 0);
4735 else
4737 n = Fprefix_numeric_value (n);
4738 window_scroll (selected_window, XINT (n) * direction, 0, 0);
4741 unbind_to (count, Qnil);
4744 DEFUN ("scroll-up", Fscroll_up, Sscroll_up, 0, 1, "^P",
4745 doc: /* Scroll text of selected window upward ARG lines.
4746 If ARG is omitted or nil, scroll upward by a near full screen.
4747 A near full screen is `next-screen-context-lines' less than a full screen.
4748 Negative ARG means scroll downward.
4749 If ARG is the atom `-', scroll downward by nearly full screen.
4750 When calling from a program, supply as argument a number, nil, or `-'. */)
4751 (Lisp_Object arg)
4753 scroll_command (arg, 1);
4754 return Qnil;
4757 DEFUN ("scroll-down", Fscroll_down, Sscroll_down, 0, 1, "^P",
4758 doc: /* Scroll text of selected window down ARG lines.
4759 If ARG is omitted or nil, scroll down by a near full screen.
4760 A near full screen is `next-screen-context-lines' less than a full screen.
4761 Negative ARG means scroll upward.
4762 If ARG is the atom `-', scroll upward by nearly full screen.
4763 When calling from a program, supply as argument a number, nil, or `-'. */)
4764 (Lisp_Object arg)
4766 scroll_command (arg, -1);
4767 return Qnil;
4770 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling, Sother_window_for_scrolling, 0, 0, 0,
4771 doc: /* Return the other window for \"other window scroll\" commands.
4772 If `other-window-scroll-buffer' is non-nil, a window
4773 showing that buffer is used.
4774 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4775 specifies the window. This takes precedence over
4776 `other-window-scroll-buffer'. */)
4777 (void)
4779 Lisp_Object window;
4781 if (MINI_WINDOW_P (XWINDOW (selected_window))
4782 && !NILP (Vminibuf_scroll_window))
4783 window = Vminibuf_scroll_window;
4784 /* If buffer is specified, scroll that buffer. */
4785 else if (!NILP (Vother_window_scroll_buffer))
4787 window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil);
4788 if (NILP (window))
4789 window = display_buffer (Vother_window_scroll_buffer, Qt, Qnil);
4791 else
4793 /* Nothing specified; look for a neighboring window on the same
4794 frame. */
4795 window = Fnext_window (selected_window, Qnil, Qnil);
4797 if (EQ (window, selected_window))
4798 /* That didn't get us anywhere; look for a window on another
4799 visible frame. */
4801 window = Fnext_window (window, Qnil, Qt);
4802 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window))))
4803 && ! EQ (window, selected_window));
4806 CHECK_LIVE_WINDOW (window);
4808 if (EQ (window, selected_window))
4809 error ("There is no other window");
4811 return window;
4814 DEFUN ("scroll-other-window", Fscroll_other_window, Sscroll_other_window, 0, 1, "P",
4815 doc: /* Scroll next window upward ARG lines; or near full screen if no ARG.
4816 A near full screen is `next-screen-context-lines' less than a full screen.
4817 The next window is the one below the current one; or the one at the top
4818 if the current one is at the bottom. Negative ARG means scroll downward.
4819 If ARG is the atom `-', scroll downward by nearly full screen.
4820 When calling from a program, supply as argument a number, nil, or `-'.
4822 If `other-window-scroll-buffer' is non-nil, scroll the window
4823 showing that buffer, popping the buffer up if necessary.
4824 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4825 specifies the window to scroll. This takes precedence over
4826 `other-window-scroll-buffer'. */)
4827 (Lisp_Object arg)
4829 Lisp_Object window;
4830 struct window *w;
4831 ptrdiff_t count = SPECPDL_INDEX ();
4833 window = Fother_window_for_scrolling ();
4834 w = XWINDOW (window);
4836 /* Don't screw up if window_scroll gets an error. */
4837 record_unwind_protect (save_excursion_restore, save_excursion_save ());
4838 ++windows_or_buffers_changed;
4840 Fset_buffer (w->buffer);
4841 SET_PT (marker_position (w->pointm));
4843 if (NILP (arg))
4844 window_scroll (window, 1, 1, 1);
4845 else if (EQ (arg, Qminus))
4846 window_scroll (window, -1, 1, 1);
4847 else
4849 if (CONSP (arg))
4850 arg = Fcar (arg);
4851 CHECK_NUMBER (arg);
4852 window_scroll (window, XINT (arg), 0, 1);
4855 set_marker_both (w->pointm, Qnil, PT, PT_BYTE);
4856 unbind_to (count, Qnil);
4858 return Qnil;
4861 DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 2, "^P\np",
4862 doc: /* Scroll selected window display ARG columns left.
4863 Default for ARG is window width minus 2.
4864 Value is the total amount of leftward horizontal scrolling in
4865 effect after the change.
4866 If SET-MINIMUM is non-nil, the new scroll amount becomes the
4867 lower bound for automatic scrolling, i.e. automatic scrolling
4868 will not scroll a window to a column less than the value returned
4869 by this function. This happens in an interactive call. */)
4870 (register Lisp_Object arg, Lisp_Object set_minimum)
4872 Lisp_Object result;
4873 EMACS_INT hscroll;
4874 struct window *w = XWINDOW (selected_window);
4876 if (NILP (arg))
4877 XSETFASTINT (arg, window_body_cols (w) - 2);
4878 else
4879 arg = Fprefix_numeric_value (arg);
4881 hscroll = XINT (w->hscroll) + XINT (arg);
4882 result = Fset_window_hscroll (selected_window, make_number (hscroll));
4884 if (!NILP (set_minimum))
4885 w->min_hscroll = w->hscroll;
4887 return result;
4890 DEFUN ("scroll-right", Fscroll_right, Sscroll_right, 0, 2, "^P\np",
4891 doc: /* Scroll selected window display ARG columns right.
4892 Default for ARG is window width minus 2.
4893 Value is the total amount of leftward horizontal scrolling in
4894 effect after the change.
4895 If SET-MINIMUM is non-nil, the new scroll amount becomes the
4896 lower bound for automatic scrolling, i.e. automatic scrolling
4897 will not scroll a window to a column less than the value returned
4898 by this function. This happens in an interactive call. */)
4899 (register Lisp_Object arg, Lisp_Object set_minimum)
4901 Lisp_Object result;
4902 EMACS_INT hscroll;
4903 struct window *w = XWINDOW (selected_window);
4905 if (NILP (arg))
4906 XSETFASTINT (arg, window_body_cols (w) - 2);
4907 else
4908 arg = Fprefix_numeric_value (arg);
4910 hscroll = XINT (w->hscroll) - XINT (arg);
4911 result = Fset_window_hscroll (selected_window, make_number (hscroll));
4913 if (!NILP (set_minimum))
4914 w->min_hscroll = w->hscroll;
4916 return result;
4919 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window, Sminibuffer_selected_window, 0, 0, 0,
4920 doc: /* Return the window which was selected when entering the minibuffer.
4921 Returns nil, if selected window is not a minibuffer window. */)
4922 (void)
4924 if (minibuf_level > 0
4925 && MINI_WINDOW_P (XWINDOW (selected_window))
4926 && WINDOW_LIVE_P (minibuf_selected_window))
4927 return minibuf_selected_window;
4929 return Qnil;
4932 /* Value is the number of lines actually displayed in window W,
4933 as opposed to its height. */
4935 static int
4936 displayed_window_lines (struct window *w)
4938 struct it it;
4939 struct text_pos start;
4940 int height = window_box_height (w);
4941 struct buffer *old_buffer;
4942 int bottom_y;
4943 void *itdata = NULL;
4945 if (XBUFFER (w->buffer) != current_buffer)
4947 old_buffer = current_buffer;
4948 set_buffer_internal (XBUFFER (w->buffer));
4950 else
4951 old_buffer = NULL;
4953 /* In case W->start is out of the accessible range, do something
4954 reasonable. This happens in Info mode when Info-scroll-down
4955 calls (recenter -1) while W->start is 1. */
4956 if (XMARKER (w->start)->charpos < BEGV)
4957 SET_TEXT_POS (start, BEGV, BEGV_BYTE);
4958 else if (XMARKER (w->start)->charpos > ZV)
4959 SET_TEXT_POS (start, ZV, ZV_BYTE);
4960 else
4961 SET_TEXT_POS_FROM_MARKER (start, w->start);
4963 itdata = bidi_shelve_cache ();
4964 start_display (&it, w, start);
4965 move_it_vertically (&it, height);
4966 bottom_y = line_bottom_y (&it);
4967 bidi_unshelve_cache (itdata, 0);
4969 /* rms: On a non-window display,
4970 the value of it.vpos at the bottom of the screen
4971 seems to be 1 larger than window_box_height (w).
4972 This kludge fixes a bug whereby (move-to-window-line -1)
4973 when ZV is on the last screen line
4974 moves to the previous screen line instead of the last one. */
4975 if (! FRAME_WINDOW_P (XFRAME (w->frame)))
4976 height++;
4978 /* Add in empty lines at the bottom of the window. */
4979 if (bottom_y < height)
4981 int uy = FRAME_LINE_HEIGHT (it.f);
4982 it.vpos += (height - bottom_y + uy - 1) / uy;
4985 if (old_buffer)
4986 set_buffer_internal (old_buffer);
4988 return it.vpos;
4992 DEFUN ("recenter", Frecenter, Srecenter, 0, 1, "P",
4993 doc: /* Center point in selected window and maybe redisplay frame.
4994 With prefix argument ARG, recenter putting point on screen line ARG
4995 relative to the selected window. If ARG is negative, it counts up from the
4996 bottom of the window. (ARG should be less than the height of the window.)
4998 If ARG is omitted or nil, then recenter with point on the middle line of
4999 the selected window; if the variable `recenter-redisplay' is non-nil,
5000 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5001 is set to `grow-only', this resets the tool-bar's height to the minimum
5002 height needed); if `recenter-redisplay' has the special value `tty',
5003 then only tty frame are redrawn.
5005 Just C-u as prefix means put point in the center of the window
5006 and redisplay normally--don't erase and redraw the frame. */)
5007 (register Lisp_Object arg)
5009 struct window *w = XWINDOW (selected_window);
5010 struct buffer *buf = XBUFFER (w->buffer);
5011 struct buffer *obuf = current_buffer;
5012 int center_p = 0;
5013 ptrdiff_t charpos, bytepos;
5014 EMACS_INT iarg IF_LINT (= 0);
5015 int this_scroll_margin;
5017 /* If redisplay is suppressed due to an error, try again. */
5018 obuf->display_error_modiff = 0;
5020 if (NILP (arg))
5022 if (!NILP (Vrecenter_redisplay)
5023 && (!EQ (Vrecenter_redisplay, Qtty)
5024 || !NILP (Ftty_type (selected_frame))))
5026 ptrdiff_t i;
5028 /* Invalidate pixel data calculated for all compositions. */
5029 for (i = 0; i < n_compositions; i++)
5030 composition_table[i]->font = NULL;
5032 WINDOW_XFRAME (w)->minimize_tool_bar_window_p = 1;
5034 Fredraw_frame (WINDOW_FRAME (w));
5035 SET_FRAME_GARBAGED (WINDOW_XFRAME (w));
5038 center_p = 1;
5040 else if (CONSP (arg)) /* Just C-u. */
5041 center_p = 1;
5042 else
5044 arg = Fprefix_numeric_value (arg);
5045 CHECK_NUMBER (arg);
5046 iarg = XINT (arg);
5049 set_buffer_internal (buf);
5051 /* Do this after making BUF current
5052 in case scroll_margin is buffer-local. */
5053 this_scroll_margin =
5054 max (0, min (scroll_margin, XFASTINT (w->total_lines) / 4));
5056 /* Handle centering on a graphical frame specially. Such frames can
5057 have variable-height lines and centering point on the basis of
5058 line counts would lead to strange effects. */
5059 if (FRAME_WINDOW_P (XFRAME (w->frame)))
5061 if (center_p)
5063 struct it it;
5064 struct text_pos pt;
5065 void *itdata = bidi_shelve_cache ();
5067 SET_TEXT_POS (pt, PT, PT_BYTE);
5068 start_display (&it, w, pt);
5069 move_it_vertically_backward (&it, window_box_height (w) / 2);
5070 charpos = IT_CHARPOS (it);
5071 bytepos = IT_BYTEPOS (it);
5072 bidi_unshelve_cache (itdata, 0);
5074 else if (iarg < 0)
5076 struct it it;
5077 struct text_pos pt;
5078 ptrdiff_t nlines = min (PTRDIFF_MAX, -iarg);
5079 int extra_line_spacing;
5080 int h = window_box_height (w);
5081 void *itdata = bidi_shelve_cache ();
5083 iarg = - max (-iarg, this_scroll_margin);
5085 SET_TEXT_POS (pt, PT, PT_BYTE);
5086 start_display (&it, w, pt);
5088 /* Be sure we have the exact height of the full line containing PT. */
5089 move_it_by_lines (&it, 0);
5091 /* The amount of pixels we have to move back is the window
5092 height minus what's displayed in the line containing PT,
5093 and the lines below. */
5094 it.current_y = 0;
5095 it.vpos = 0;
5096 move_it_by_lines (&it, nlines);
5098 if (it.vpos == nlines)
5099 h -= it.current_y;
5100 else
5102 /* Last line has no newline */
5103 h -= line_bottom_y (&it);
5104 it.vpos++;
5107 /* Don't reserve space for extra line spacing of last line. */
5108 extra_line_spacing = it.max_extra_line_spacing;
5110 /* If we can't move down NLINES lines because we hit
5111 the end of the buffer, count in some empty lines. */
5112 if (it.vpos < nlines)
5114 nlines -= it.vpos;
5115 extra_line_spacing = it.extra_line_spacing;
5116 h -= nlines * (FRAME_LINE_HEIGHT (it.f) + extra_line_spacing);
5118 if (h <= 0)
5120 bidi_unshelve_cache (itdata, 0);
5121 return Qnil;
5124 /* Now find the new top line (starting position) of the window. */
5125 start_display (&it, w, pt);
5126 it.current_y = 0;
5127 move_it_vertically_backward (&it, h);
5129 /* If extra line spacing is present, we may move too far
5130 back. This causes the last line to be only partially
5131 visible (which triggers redisplay to recenter that line
5132 in the middle), so move forward.
5133 But ignore extra line spacing on last line, as it is not
5134 considered to be part of the visible height of the line.
5136 h += extra_line_spacing;
5137 while (-it.current_y > h)
5138 move_it_by_lines (&it, 1);
5140 charpos = IT_CHARPOS (it);
5141 bytepos = IT_BYTEPOS (it);
5143 bidi_unshelve_cache (itdata, 0);
5145 else
5147 struct position pos;
5149 iarg = max (iarg, this_scroll_margin);
5151 pos = *vmotion (PT, -iarg, w);
5152 charpos = pos.bufpos;
5153 bytepos = pos.bytepos;
5156 else
5158 struct position pos;
5159 int ht = window_internal_height (w);
5161 if (center_p)
5162 iarg = ht / 2;
5163 else if (iarg < 0)
5164 iarg += ht;
5166 /* Don't let it get into the margin at either top or bottom. */
5167 iarg = max (iarg, this_scroll_margin);
5168 iarg = min (iarg, ht - this_scroll_margin - 1);
5170 pos = *vmotion (PT, - iarg, w);
5171 charpos = pos.bufpos;
5172 bytepos = pos.bytepos;
5175 /* Set the new window start. */
5176 set_marker_both (w->start, w->buffer, charpos, bytepos);
5177 w->window_end_valid = Qnil;
5179 w->optional_new_start = Qt;
5181 if (bytepos == BEGV_BYTE || FETCH_BYTE (bytepos - 1) == '\n')
5182 w->start_at_line_beg = Qt;
5183 else
5184 w->start_at_line_beg = Qnil;
5186 set_buffer_internal (obuf);
5187 return Qnil;
5190 DEFUN ("window-text-height", Fwindow_text_height, Swindow_text_height,
5191 0, 1, 0,
5192 doc: /* Return the height in lines of the text display area of WINDOW.
5193 If WINDOW is omitted or nil, it defaults to the selected window.
5195 The returned height does not include the mode line, any header line,
5196 nor any partial-height lines at the bottom of the text area. */)
5197 (Lisp_Object window)
5199 struct window *w = decode_window (window);
5200 int pixel_height = window_box_height (w);
5201 int line_height = pixel_height / FRAME_LINE_HEIGHT (XFRAME (w->frame));
5202 return make_number (line_height);
5207 DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line,
5208 1, 1, "P",
5209 doc: /* Position point relative to window.
5210 ARG nil means position point at center of window.
5211 Else, ARG specifies vertical position within the window;
5212 zero means top of window, negative means relative to bottom of window. */)
5213 (Lisp_Object arg)
5215 struct window *w = XWINDOW (selected_window);
5216 int lines, start;
5217 Lisp_Object window;
5218 #if 0
5219 int this_scroll_margin;
5220 #endif
5222 if (!(BUFFERP (w->buffer)
5223 && XBUFFER (w->buffer) == current_buffer))
5224 /* This test is needed to make sure PT/PT_BYTE make sense in w->buffer
5225 when passed below to set_marker_both. */
5226 error ("move-to-window-line called from unrelated buffer");
5228 window = selected_window;
5229 start = marker_position (w->start);
5230 if (start < BEGV || start > ZV)
5232 int height = window_internal_height (w);
5233 Fvertical_motion (make_number (- (height / 2)), window);
5234 set_marker_both (w->start, w->buffer, PT, PT_BYTE);
5235 w->start_at_line_beg = Fbolp ();
5236 w->force_start = Qt;
5238 else
5239 Fgoto_char (w->start);
5241 lines = displayed_window_lines (w);
5243 #if 0
5244 this_scroll_margin = max (0, min (scroll_margin, lines / 4));
5245 #endif
5247 if (NILP (arg))
5248 XSETFASTINT (arg, lines / 2);
5249 else
5251 EMACS_INT iarg = XINT (Fprefix_numeric_value (arg));
5253 if (iarg < 0)
5254 iarg = iarg + lines;
5256 #if 0 /* This code would prevent move-to-window-line from moving point
5257 to a place inside the scroll margins (which would cause the
5258 next redisplay to scroll). I wrote this code, but then concluded
5259 it is probably better not to install it. However, it is here
5260 inside #if 0 so as not to lose it. -- rms. */
5262 /* Don't let it get into the margin at either top or bottom. */
5263 iarg = max (iarg, this_scroll_margin);
5264 iarg = min (iarg, lines - this_scroll_margin - 1);
5265 #endif
5267 arg = make_number (iarg);
5270 /* Skip past a partially visible first line. */
5271 if (w->vscroll)
5272 XSETINT (arg, XINT (arg) + 1);
5274 return Fvertical_motion (arg, window);
5279 /***********************************************************************
5280 Window Configuration
5281 ***********************************************************************/
5283 struct save_window_data
5285 struct vectorlike_header header;
5286 Lisp_Object selected_frame;
5287 Lisp_Object current_window;
5288 Lisp_Object current_buffer;
5289 Lisp_Object minibuf_scroll_window;
5290 Lisp_Object minibuf_selected_window;
5291 Lisp_Object root_window;
5292 Lisp_Object focus_frame;
5293 /* A vector, each of whose elements is a struct saved_window
5294 for one window. */
5295 Lisp_Object saved_windows;
5297 /* All fields above are traced by the GC.
5298 From `fame-cols' down, the fields are ignored by the GC. */
5300 int frame_cols, frame_lines, frame_menu_bar_lines;
5301 int frame_tool_bar_lines;
5304 /* This is saved as a Lisp_Vector */
5305 struct saved_window
5307 struct vectorlike_header header;
5309 Lisp_Object window, buffer, start, pointm, mark;
5310 Lisp_Object left_col, top_line, total_cols, total_lines;
5311 Lisp_Object normal_cols, normal_lines;
5312 Lisp_Object hscroll, min_hscroll;
5313 Lisp_Object parent, prev;
5314 Lisp_Object start_at_line_beg;
5315 Lisp_Object display_table;
5316 Lisp_Object left_margin_cols, right_margin_cols;
5317 Lisp_Object left_fringe_width, right_fringe_width, fringes_outside_margins;
5318 Lisp_Object scroll_bar_width, vertical_scroll_bar_type, dedicated;
5319 Lisp_Object combination_limit, window_parameters;
5322 #define SAVED_WINDOW_N(swv,n) \
5323 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5325 DEFUN ("window-configuration-p", Fwindow_configuration_p, Swindow_configuration_p, 1, 1, 0,
5326 doc: /* Return t if OBJECT is a window-configuration object. */)
5327 (Lisp_Object object)
5329 return WINDOW_CONFIGURATIONP (object) ? Qt : Qnil;
5332 DEFUN ("window-configuration-frame", Fwindow_configuration_frame, Swindow_configuration_frame, 1, 1, 0,
5333 doc: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5334 (Lisp_Object config)
5336 register struct save_window_data *data;
5337 struct Lisp_Vector *saved_windows;
5339 CHECK_WINDOW_CONFIGURATION (config);
5341 data = (struct save_window_data *) XVECTOR (config);
5342 saved_windows = XVECTOR (data->saved_windows);
5343 return XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame;
5346 DEFUN ("set-window-configuration", Fset_window_configuration,
5347 Sset_window_configuration, 1, 1, 0,
5348 doc: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5349 CONFIGURATION must be a value previously returned
5350 by `current-window-configuration' (which see).
5351 If CONFIGURATION was made from a frame that is now deleted,
5352 only frame-independent values can be restored. In this case,
5353 the return value is nil. Otherwise the value is t. */)
5354 (Lisp_Object configuration)
5356 register struct save_window_data *data;
5357 struct Lisp_Vector *saved_windows;
5358 Lisp_Object new_current_buffer;
5359 Lisp_Object frame;
5360 Lisp_Object auto_buffer_name;
5361 FRAME_PTR f;
5362 ptrdiff_t old_point = -1;
5364 CHECK_WINDOW_CONFIGURATION (configuration);
5366 data = (struct save_window_data *) XVECTOR (configuration);
5367 saved_windows = XVECTOR (data->saved_windows);
5369 new_current_buffer = data->current_buffer;
5370 if (NILP (BVAR (XBUFFER (new_current_buffer), name)))
5371 new_current_buffer = Qnil;
5372 else
5374 if (XBUFFER (new_current_buffer) == current_buffer)
5375 /* The code further down "preserves point" by saving here PT in
5376 old_point and then setting it later back into PT. When the
5377 current-selected-window and the final-selected-window both show
5378 the current buffer, this suffers from the problem that the
5379 current PT is the window-point of the current-selected-window,
5380 while the final PT is the point of the final-selected-window, so
5381 this copy from one PT to the other would end up moving the
5382 window-point of the final-selected-window to the window-point of
5383 the current-selected-window. So we have to be careful which
5384 point of the current-buffer we copy into old_point. */
5385 if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer)
5386 && WINDOWP (selected_window)
5387 && EQ (XWINDOW (selected_window)->buffer, new_current_buffer)
5388 && !EQ (selected_window, data->current_window))
5389 old_point = XMARKER (XWINDOW (data->current_window)->pointm)->charpos;
5390 else
5391 old_point = PT;
5392 else
5393 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
5394 point in new_current_buffer as of the last time this buffer was
5395 used. This can be non-deterministic since it can be changed by
5396 things like jit-lock by mere temporary selection of some random
5397 window that happens to show this buffer.
5398 So if possible we want this arbitrary choice of "which point" to
5399 be the one from the to-be-selected-window so as to prevent this
5400 window's cursor from being copied from another window. */
5401 if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer)
5402 /* If current_window = selected_window, its point is in BUF_PT. */
5403 && !EQ (selected_window, data->current_window))
5404 old_point = XMARKER (XWINDOW (data->current_window)->pointm)->charpos;
5405 else
5406 old_point = BUF_PT (XBUFFER (new_current_buffer));
5409 frame = XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame;
5410 f = XFRAME (frame);
5412 /* If f is a dead frame, don't bother rebuilding its window tree.
5413 However, there is other stuff we should still try to do below. */
5414 if (FRAME_LIVE_P (f))
5416 Lisp_Object window;
5417 Lisp_Object dead_windows = Qnil;
5418 register struct window *w;
5419 register struct saved_window *p;
5420 struct window *root_window;
5421 struct window **leaf_windows;
5422 int n_leaf_windows;
5423 ptrdiff_t k;
5424 int i, n;
5426 /* If the frame has been resized since this window configuration was
5427 made, we change the frame to the size specified in the
5428 configuration, restore the configuration, and then resize it
5429 back. We keep track of the prevailing height in these variables. */
5430 int previous_frame_lines = FRAME_LINES (f);
5431 int previous_frame_cols = FRAME_COLS (f);
5432 int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
5433 int previous_frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f);
5435 /* The mouse highlighting code could get screwed up
5436 if it runs during this. */
5437 BLOCK_INPUT;
5439 if (data->frame_lines != previous_frame_lines
5440 || data->frame_cols != previous_frame_cols)
5441 change_frame_size (f, data->frame_lines,
5442 data->frame_cols, 0, 0, 0);
5443 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5444 if (data->frame_menu_bar_lines
5445 != previous_frame_menu_bar_lines)
5446 x_set_menu_bar_lines (f, make_number (data->frame_menu_bar_lines),
5447 make_number (0));
5448 #ifdef HAVE_WINDOW_SYSTEM
5449 if (data->frame_tool_bar_lines
5450 != previous_frame_tool_bar_lines)
5451 x_set_tool_bar_lines (f, make_number (data->frame_tool_bar_lines),
5452 make_number (0));
5453 #endif
5454 #endif
5456 /* "Swap out" point from the selected window's buffer
5457 into the window itself. (Normally the pointm of the selected
5458 window holds garbage.) We do this now, before
5459 restoring the window contents, and prevent it from
5460 being done later on when we select a new window. */
5461 if (! NILP (XWINDOW (selected_window)->buffer))
5463 w = XWINDOW (selected_window);
5464 set_marker_both (w->pointm,
5465 w->buffer,
5466 BUF_PT (XBUFFER (w->buffer)),
5467 BUF_PT_BYTE (XBUFFER (w->buffer)));
5470 windows_or_buffers_changed++;
5471 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
5473 /* Problem: Freeing all matrices and later allocating them again
5474 is a serious redisplay flickering problem. What we would
5475 really like to do is to free only those matrices not reused
5476 below. */
5477 root_window = XWINDOW (FRAME_ROOT_WINDOW (f));
5478 leaf_windows
5479 = (struct window **) alloca (count_windows (root_window)
5480 * sizeof (struct window *));
5481 n_leaf_windows = get_leaf_windows (root_window, leaf_windows, 0);
5483 /* Kludge Alert!
5484 Mark all windows now on frame as "deleted".
5485 Restoring the new configuration "undeletes" any that are in it.
5487 Save their current buffers in their height fields, since we may
5488 need it later, if a buffer saved in the configuration is now
5489 dead. */
5490 delete_all_child_windows (FRAME_ROOT_WINDOW (f));
5492 for (k = 0; k < saved_windows->header.size; k++)
5494 p = SAVED_WINDOW_N (saved_windows, k);
5495 window = p->window;
5496 w = XWINDOW (window);
5497 w->next = Qnil;
5499 if (!NILP (p->parent))
5500 w->parent = SAVED_WINDOW_N (saved_windows,
5501 XFASTINT (p->parent))->window;
5502 else
5503 w->parent = Qnil;
5505 if (!NILP (p->prev))
5507 w->prev = SAVED_WINDOW_N (saved_windows,
5508 XFASTINT (p->prev))->window;
5509 XWINDOW (w->prev)->next = p->window;
5511 else
5513 w->prev = Qnil;
5514 if (!NILP (w->parent))
5516 if (EQ (p->total_cols, XWINDOW (w->parent)->total_cols))
5518 XWINDOW (w->parent)->vchild = p->window;
5519 XWINDOW (w->parent)->hchild = Qnil;
5521 else
5523 XWINDOW (w->parent)->hchild = p->window;
5524 XWINDOW (w->parent)->vchild = Qnil;
5529 /* If we squirreled away the buffer in the window's height,
5530 restore it now. */
5531 if (BUFFERP (w->total_lines))
5532 w->buffer = w->total_lines;
5533 w->left_col = p->left_col;
5534 w->top_line = p->top_line;
5535 w->total_cols = p->total_cols;
5536 w->total_lines = p->total_lines;
5537 w->normal_cols = p->normal_cols;
5538 w->normal_lines = p->normal_lines;
5539 w->hscroll = p->hscroll;
5540 w->min_hscroll = p->min_hscroll;
5541 w->display_table = p->display_table;
5542 w->left_margin_cols = p->left_margin_cols;
5543 w->right_margin_cols = p->right_margin_cols;
5544 w->left_fringe_width = p->left_fringe_width;
5545 w->right_fringe_width = p->right_fringe_width;
5546 w->fringes_outside_margins = p->fringes_outside_margins;
5547 w->scroll_bar_width = p->scroll_bar_width;
5548 w->vertical_scroll_bar_type = p->vertical_scroll_bar_type;
5549 w->dedicated = p->dedicated;
5550 w->combination_limit = p->combination_limit;
5551 w->window_parameters = p->window_parameters;
5552 XSETFASTINT (w->last_modified, 0);
5553 XSETFASTINT (w->last_overlay_modified, 0);
5555 /* Reinstall the saved buffer and pointers into it. */
5556 if (NILP (p->buffer))
5557 /* An internal window. */
5558 w->buffer = p->buffer;
5559 else if (!NILP (BVAR (XBUFFER (p->buffer), name)))
5560 /* If saved buffer is alive, install it. */
5562 w->buffer = p->buffer;
5563 w->start_at_line_beg = p->start_at_line_beg;
5564 set_marker_restricted (w->start, p->start, w->buffer);
5565 set_marker_restricted (w->pointm, p->pointm, w->buffer);
5566 Fset_marker (BVAR (XBUFFER (w->buffer), mark),
5567 p->mark, w->buffer);
5569 /* As documented in Fcurrent_window_configuration, don't
5570 restore the location of point in the buffer which was
5571 current when the window configuration was recorded. */
5572 if (!EQ (p->buffer, new_current_buffer)
5573 && XBUFFER (p->buffer) == current_buffer)
5574 Fgoto_char (w->pointm);
5576 else if (!NILP (w->buffer) && !NILP (BVAR (XBUFFER (w->buffer), name)))
5577 /* Keep window's old buffer; make sure the markers are
5578 real. */
5580 /* Set window markers at start of visible range. */
5581 if (XMARKER (w->start)->buffer == 0)
5582 set_marker_restricted (w->start, make_number (0),
5583 w->buffer);
5584 if (XMARKER (w->pointm)->buffer == 0)
5585 set_marker_restricted_both (w->pointm, w->buffer,
5586 BUF_PT (XBUFFER (w->buffer)),
5587 BUF_PT_BYTE (XBUFFER (w->buffer)));
5588 w->start_at_line_beg = Qt;
5590 else if (STRINGP (auto_buffer_name =
5591 Fwindow_parameter (window, Qauto_buffer_name))
5592 && SCHARS (auto_buffer_name) != 0
5593 && !NILP (w->buffer = Fget_buffer_create (auto_buffer_name)))
5595 set_marker_restricted (w->start, make_number (0), w->buffer);
5596 set_marker_restricted (w->pointm, make_number (0), w->buffer);
5597 w->start_at_line_beg = Qt;
5599 else
5600 /* Window has no live buffer, get one. */
5602 /* Get the buffer via other_buffer_safely in order to
5603 avoid showing an unimportant buffer and, if necessary, to
5604 recreate *scratch* in the course (part of Juanma's bs-show
5605 scenario from March 2011). */
5606 w->buffer = other_buffer_safely (Fcurrent_buffer ());
5607 /* This will set the markers to beginning of visible
5608 range. */
5609 set_marker_restricted (w->start, make_number (0), w->buffer);
5610 set_marker_restricted (w->pointm, make_number (0), w->buffer);
5611 w->start_at_line_beg = Qt;
5612 if (!NILP (w->dedicated))
5613 /* Record this window as dead. */
5614 dead_windows = Fcons (window, dead_windows);
5615 /* Make sure window is no more dedicated. */
5616 w->dedicated = Qnil;
5620 FRAME_ROOT_WINDOW (f) = data->root_window;
5621 /* Arrange *not* to restore point in the buffer that was
5622 current when the window configuration was saved. */
5623 if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer))
5624 set_marker_restricted (XWINDOW (data->current_window)->pointm,
5625 make_number (old_point),
5626 XWINDOW (data->current_window)->buffer);
5628 /* In the following call to `select-window', prevent "swapping out
5629 point" in the old selected window using the buffer that has
5630 been restored into it. We already swapped out that point from
5631 that window's old buffer. */
5632 select_window (data->current_window, Qnil, 1);
5633 BVAR (XBUFFER (XWINDOW (selected_window)->buffer), last_selected_window)
5634 = selected_window;
5636 if (NILP (data->focus_frame)
5637 || (FRAMEP (data->focus_frame)
5638 && FRAME_LIVE_P (XFRAME (data->focus_frame))))
5639 Fredirect_frame_focus (frame, data->focus_frame);
5641 /* Set the screen height to the value it had before this function. */
5642 if (previous_frame_lines != FRAME_LINES (f)
5643 || previous_frame_cols != FRAME_COLS (f))
5644 change_frame_size (f, previous_frame_lines, previous_frame_cols,
5645 0, 0, 0);
5646 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5647 if (previous_frame_menu_bar_lines != FRAME_MENU_BAR_LINES (f))
5648 x_set_menu_bar_lines (f, make_number (previous_frame_menu_bar_lines),
5649 make_number (0));
5650 #ifdef HAVE_WINDOW_SYSTEM
5651 if (previous_frame_tool_bar_lines != FRAME_TOOL_BAR_LINES (f))
5652 x_set_tool_bar_lines (f, make_number (previous_frame_tool_bar_lines),
5653 make_number (0));
5654 #endif
5655 #endif
5657 /* Now, free glyph matrices in windows that were not reused. */
5658 for (i = n = 0; i < n_leaf_windows; ++i)
5660 if (NILP (leaf_windows[i]->buffer))
5662 /* Assert it's not reused as a combination. */
5663 xassert (NILP (leaf_windows[i]->hchild)
5664 && NILP (leaf_windows[i]->vchild));
5665 free_window_matrices (leaf_windows[i]);
5667 else if (EQ (leaf_windows[i]->buffer, new_current_buffer))
5668 ++n;
5671 adjust_glyphs (f);
5672 UNBLOCK_INPUT;
5674 /* Scan dead buffer windows. */
5675 for (; CONSP (dead_windows); dead_windows = XCDR (dead_windows))
5677 window = XCAR (dead_windows);
5678 if (WINDOW_LIVE_P (window) && !EQ (window, FRAME_ROOT_WINDOW (f)))
5679 delete_deletable_window (window);
5682 /* Fselect_window will have made f the selected frame, so we
5683 reselect the proper frame here. Fhandle_switch_frame will change the
5684 selected window too, but that doesn't make the call to
5685 Fselect_window above totally superfluous; it still sets f's
5686 selected window. */
5687 if (FRAME_LIVE_P (XFRAME (data->selected_frame)))
5688 do_switch_frame (data->selected_frame, 0, 0, Qnil);
5690 run_window_configuration_change_hook (f);
5693 if (!NILP (new_current_buffer))
5694 Fset_buffer (new_current_buffer);
5696 Vminibuf_scroll_window = data->minibuf_scroll_window;
5697 minibuf_selected_window = data->minibuf_selected_window;
5699 return (FRAME_LIVE_P (f) ? Qt : Qnil);
5703 /* Recursively delete all child windows reachable via the next, vchild,
5704 and hchild slots of WINDOW. */
5705 void
5706 delete_all_child_windows (Lisp_Object window)
5708 register struct window *w;
5710 w = XWINDOW (window);
5712 if (!NILP (w->next))
5713 /* Delete WINDOW's siblings (we traverse postorderly). */
5714 delete_all_child_windows (w->next);
5716 w->total_lines = w->buffer; /* See Fset_window_configuration for excuse. */
5718 if (!NILP (w->vchild))
5720 delete_all_child_windows (w->vchild);
5721 w->vchild = Qnil;
5723 else if (!NILP (w->hchild))
5725 delete_all_child_windows (w->hchild);
5726 w->hchild = Qnil;
5728 else if (!NILP (w->buffer))
5730 unshow_buffer (w);
5731 unchain_marker (XMARKER (w->pointm));
5732 unchain_marker (XMARKER (w->start));
5733 w->buffer = Qnil;
5736 Vwindow_list = Qnil;
5739 static int
5740 count_windows (register struct window *window)
5742 register int count = 1;
5743 if (!NILP (window->next))
5744 count += count_windows (XWINDOW (window->next));
5745 if (!NILP (window->vchild))
5746 count += count_windows (XWINDOW (window->vchild));
5747 if (!NILP (window->hchild))
5748 count += count_windows (XWINDOW (window->hchild));
5749 return count;
5753 /* Fill vector FLAT with leaf windows under W, starting at index I.
5754 Value is last index + 1. */
5755 static int
5756 get_leaf_windows (struct window *w, struct window **flat, int i)
5758 while (w)
5760 if (!NILP (w->hchild))
5761 i = get_leaf_windows (XWINDOW (w->hchild), flat, i);
5762 else if (!NILP (w->vchild))
5763 i = get_leaf_windows (XWINDOW (w->vchild), flat, i);
5764 else
5765 flat[i++] = w;
5767 w = NILP (w->next) ? 0 : XWINDOW (w->next);
5770 return i;
5774 /* Return a pointer to the glyph W's physical cursor is on. Value is
5775 null if W's current matrix is invalid, so that no meaningfull glyph
5776 can be returned. */
5777 struct glyph *
5778 get_phys_cursor_glyph (struct window *w)
5780 struct glyph_row *row;
5781 struct glyph *glyph;
5783 if (w->phys_cursor.vpos >= 0
5784 && w->phys_cursor.vpos < w->current_matrix->nrows
5785 && (row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos),
5786 row->enabled_p)
5787 && row->used[TEXT_AREA] > w->phys_cursor.hpos)
5788 glyph = row->glyphs[TEXT_AREA] + w->phys_cursor.hpos;
5789 else
5790 glyph = NULL;
5792 return glyph;
5796 static int
5797 save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
5799 register struct saved_window *p;
5800 register struct window *w;
5801 register Lisp_Object tem;
5803 for (;!NILP (window); window = w->next)
5805 p = SAVED_WINDOW_N (vector, i);
5806 w = XWINDOW (window);
5808 XSETFASTINT (w->temslot, i); i++;
5809 p->window = window;
5810 p->buffer = w->buffer;
5811 p->left_col = w->left_col;
5812 p->top_line = w->top_line;
5813 p->total_cols = w->total_cols;
5814 p->total_lines = w->total_lines;
5815 p->normal_cols = w->normal_cols;
5816 p->normal_lines = w->normal_lines;
5817 p->hscroll = w->hscroll;
5818 p->min_hscroll = w->min_hscroll;
5819 p->display_table = w->display_table;
5820 p->left_margin_cols = w->left_margin_cols;
5821 p->right_margin_cols = w->right_margin_cols;
5822 p->left_fringe_width = w->left_fringe_width;
5823 p->right_fringe_width = w->right_fringe_width;
5824 p->fringes_outside_margins = w->fringes_outside_margins;
5825 p->scroll_bar_width = w->scroll_bar_width;
5826 p->vertical_scroll_bar_type = w->vertical_scroll_bar_type;
5827 p->dedicated = w->dedicated;
5828 p->combination_limit = w->combination_limit;
5829 p->window_parameters = w->window_parameters;
5830 if (!NILP (w->buffer))
5832 /* Save w's value of point in the window configuration.
5833 If w is the selected window, then get the value of point
5834 from the buffer; pointm is garbage in the selected window. */
5835 if (EQ (window, selected_window))
5837 p->pointm = Fmake_marker ();
5838 set_marker_both (p->pointm, w->buffer,
5839 BUF_PT (XBUFFER (w->buffer)),
5840 BUF_PT_BYTE (XBUFFER (w->buffer)));
5842 else
5843 p->pointm = Fcopy_marker (w->pointm, Qnil);
5845 p->start = Fcopy_marker (w->start, Qnil);
5846 p->start_at_line_beg = w->start_at_line_beg;
5848 tem = BVAR (XBUFFER (w->buffer), mark);
5849 p->mark = Fcopy_marker (tem, Qnil);
5851 else
5853 p->pointm = Qnil;
5854 p->start = Qnil;
5855 p->mark = Qnil;
5856 p->start_at_line_beg = Qnil;
5859 if (NILP (w->parent))
5860 p->parent = Qnil;
5861 else
5862 p->parent = XWINDOW (w->parent)->temslot;
5864 if (NILP (w->prev))
5865 p->prev = Qnil;
5866 else
5867 p->prev = XWINDOW (w->prev)->temslot;
5869 if (!NILP (w->vchild))
5870 i = save_window_save (w->vchild, vector, i);
5871 if (!NILP (w->hchild))
5872 i = save_window_save (w->hchild, vector, i);
5875 return i;
5878 DEFUN ("current-window-configuration", Fcurrent_window_configuration,
5879 Scurrent_window_configuration, 0, 1, 0,
5880 doc: /* Return an object representing the current window configuration of FRAME.
5881 If FRAME is nil or omitted, use the selected frame.
5882 This describes the number of windows, their sizes and current buffers,
5883 and for each displayed buffer, where display starts, and the positions of
5884 point and mark. An exception is made for point in the current buffer:
5885 its value is -not- saved.
5886 This also records the currently selected frame, and FRAME's focus
5887 redirection (see `redirect-frame-focus'). */)
5888 (Lisp_Object frame)
5890 register Lisp_Object tem;
5891 register int n_windows;
5892 register struct save_window_data *data;
5893 register int i;
5894 FRAME_PTR f;
5896 if (NILP (frame))
5897 frame = selected_frame;
5898 CHECK_LIVE_FRAME (frame);
5899 f = XFRAME (frame);
5901 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
5902 data = ALLOCATE_PSEUDOVECTOR (struct save_window_data, frame_cols,
5903 PVEC_WINDOW_CONFIGURATION);
5905 data->frame_cols = FRAME_COLS (f);
5906 data->frame_lines = FRAME_LINES (f);
5907 data->frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
5908 data->frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f);
5909 data->selected_frame = selected_frame;
5910 data->current_window = FRAME_SELECTED_WINDOW (f);
5911 XSETBUFFER (data->current_buffer, current_buffer);
5912 data->minibuf_scroll_window = minibuf_level > 0 ? Vminibuf_scroll_window : Qnil;
5913 data->minibuf_selected_window = minibuf_level > 0 ? minibuf_selected_window : Qnil;
5914 data->root_window = FRAME_ROOT_WINDOW (f);
5915 data->focus_frame = FRAME_FOCUS_FRAME (f);
5916 tem = Fmake_vector (make_number (n_windows), Qnil);
5917 data->saved_windows = tem;
5918 for (i = 0; i < n_windows; i++)
5919 XVECTOR (tem)->contents[i]
5920 = Fmake_vector (make_number (VECSIZE (struct saved_window)), Qnil);
5921 save_window_save (FRAME_ROOT_WINDOW (f), XVECTOR (tem), 0);
5922 XSETWINDOW_CONFIGURATION (tem, data);
5923 return (tem);
5926 /***********************************************************************
5927 Marginal Areas
5928 ***********************************************************************/
5930 DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins,
5931 2, 3, 0,
5932 doc: /* Set width of marginal areas of window WINDOW.
5933 If WINDOW is nil, set margins of the currently selected window.
5934 Second arg LEFT-WIDTH specifies the number of character cells to
5935 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
5936 does the same for the right marginal area. A nil width parameter
5937 means no margin. */)
5938 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width)
5940 struct window *w = decode_window (window);
5942 /* Translate negative or zero widths to nil.
5943 Margins that are too wide have to be checked elsewhere. */
5945 if (!NILP (left_width))
5947 CHECK_NUMBER (left_width);
5948 if (XINT (left_width) <= 0)
5949 left_width = Qnil;
5952 if (!NILP (right_width))
5954 CHECK_NUMBER (right_width);
5955 if (XINT (right_width) <= 0)
5956 right_width = Qnil;
5959 if (!EQ (w->left_margin_cols, left_width)
5960 || !EQ (w->right_margin_cols, right_width))
5962 w->left_margin_cols = left_width;
5963 w->right_margin_cols = right_width;
5965 adjust_window_margins (w);
5967 ++windows_or_buffers_changed;
5968 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
5971 return Qnil;
5975 DEFUN ("window-margins", Fwindow_margins, Swindow_margins,
5976 0, 1, 0,
5977 doc: /* Get width of marginal areas of window WINDOW.
5978 If WINDOW is omitted or nil, it defaults to the selected window.
5979 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
5980 If a marginal area does not exist, its width will be returned
5981 as nil. */)
5982 (Lisp_Object window)
5984 struct window *w = decode_window (window);
5985 return Fcons (w->left_margin_cols, w->right_margin_cols);
5990 /***********************************************************************
5991 Fringes
5992 ***********************************************************************/
5994 DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes,
5995 2, 4, 0,
5996 doc: /* Set the fringe widths of window WINDOW.
5997 If WINDOW is nil, set the fringe widths of the currently selected
5998 window.
5999 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6000 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6001 fringe width. If a fringe width arg is nil, that means to use the
6002 frame's default fringe width. Default fringe widths can be set with
6003 the command `set-fringe-style'.
6004 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6005 outside of the display margins. By default, fringes are drawn between
6006 display marginal areas and the text area. */)
6007 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width, Lisp_Object outside_margins)
6009 struct window *w = decode_window (window);
6011 if (!NILP (left_width))
6012 CHECK_NATNUM (left_width);
6013 if (!NILP (right_width))
6014 CHECK_NATNUM (right_width);
6016 /* Do nothing on a tty. */
6017 if (FRAME_WINDOW_P (WINDOW_XFRAME (w))
6018 && (!EQ (w->left_fringe_width, left_width)
6019 || !EQ (w->right_fringe_width, right_width)
6020 || !EQ (w->fringes_outside_margins, outside_margins)))
6022 w->left_fringe_width = left_width;
6023 w->right_fringe_width = right_width;
6024 w->fringes_outside_margins = outside_margins;
6026 adjust_window_margins (w);
6028 clear_glyph_matrix (w->current_matrix);
6029 w->window_end_valid = Qnil;
6031 ++windows_or_buffers_changed;
6032 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6035 return Qnil;
6039 DEFUN ("window-fringes", Fwindow_fringes, Swindow_fringes,
6040 0, 1, 0,
6041 doc: /* Get width of fringes of window WINDOW.
6042 If WINDOW is omitted or nil, it defaults to the selected window.
6043 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6044 (Lisp_Object window)
6046 struct window *w = decode_window (window);
6048 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w)),
6049 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w)),
6050 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
6051 ? Qt : Qnil), Qnil)));
6056 /***********************************************************************
6057 Scroll bars
6058 ***********************************************************************/
6060 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars,
6061 Sset_window_scroll_bars, 2, 4, 0,
6062 doc: /* Set width and type of scroll bars of window WINDOW.
6063 If window is nil, set scroll bars of the currently selected window.
6064 Second parameter WIDTH specifies the pixel width for the scroll bar;
6065 this is automatically adjusted to a multiple of the frame column width.
6066 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6067 bar: left, right, or nil.
6068 If WIDTH is nil, use the frame's scroll-bar width.
6069 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6070 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6071 (Lisp_Object window, Lisp_Object width, Lisp_Object vertical_type, Lisp_Object horizontal_type)
6073 struct window *w = decode_window (window);
6075 if (!NILP (width))
6077 CHECK_RANGED_INTEGER (0, width, INT_MAX);
6079 if (XINT (width) == 0)
6080 vertical_type = Qnil;
6083 if (!(NILP (vertical_type)
6084 || EQ (vertical_type, Qleft)
6085 || EQ (vertical_type, Qright)
6086 || EQ (vertical_type, Qt)))
6087 error ("Invalid type of vertical scroll bar");
6089 if (!EQ (w->scroll_bar_width, width)
6090 || !EQ (w->vertical_scroll_bar_type, vertical_type))
6092 w->scroll_bar_width = width;
6093 w->vertical_scroll_bar_type = vertical_type;
6095 adjust_window_margins (w);
6097 clear_glyph_matrix (w->current_matrix);
6098 w->window_end_valid = Qnil;
6100 ++windows_or_buffers_changed;
6101 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6104 return Qnil;
6108 DEFUN ("window-scroll-bars", Fwindow_scroll_bars, Swindow_scroll_bars,
6109 0, 1, 0,
6110 doc: /* Get width and type of scroll bars of window WINDOW.
6111 If WINDOW is omitted or nil, it defaults to the selected window.
6112 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6113 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6114 value. */)
6115 (Lisp_Object window)
6117 struct window *w = decode_window (window);
6118 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
6119 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
6120 : WINDOW_SCROLL_BAR_AREA_WIDTH (w))),
6121 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w)),
6122 Fcons (w->vertical_scroll_bar_type,
6123 Fcons (Qnil, Qnil))));
6128 /***********************************************************************
6129 Smooth scrolling
6130 ***********************************************************************/
6132 DEFUN ("window-vscroll", Fwindow_vscroll, Swindow_vscroll, 0, 2, 0,
6133 doc: /* Return the amount by which WINDOW is scrolled vertically.
6134 If WINDOW is omitted or nil, it defaults to the selected window.
6135 Normally, value is a multiple of the canonical character height of WINDOW;
6136 optional second arg PIXELS-P means value is measured in pixels. */)
6137 (Lisp_Object window, Lisp_Object pixels_p)
6139 Lisp_Object result;
6140 struct frame *f;
6141 struct window *w;
6143 if (NILP (window))
6144 window = selected_window;
6145 else
6146 CHECK_WINDOW (window);
6147 w = XWINDOW (window);
6148 f = XFRAME (w->frame);
6150 if (FRAME_WINDOW_P (f))
6151 result = (NILP (pixels_p)
6152 ? FRAME_CANON_Y_FROM_PIXEL_Y (f, -w->vscroll)
6153 : make_number (-w->vscroll));
6154 else
6155 result = make_number (0);
6156 return result;
6160 DEFUN ("set-window-vscroll", Fset_window_vscroll, Sset_window_vscroll,
6161 2, 3, 0,
6162 doc: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6163 WINDOW nil means use the selected window. Normally, VSCROLL is a
6164 non-negative multiple of the canonical character height of WINDOW;
6165 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
6166 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6167 corresponds to an integral number of pixels. The return value is the
6168 result of this rounding.
6169 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6170 (Lisp_Object window, Lisp_Object vscroll, Lisp_Object pixels_p)
6172 struct window *w;
6173 struct frame *f;
6175 if (NILP (window))
6176 window = selected_window;
6177 else
6178 CHECK_WINDOW (window);
6179 CHECK_NUMBER_OR_FLOAT (vscroll);
6181 w = XWINDOW (window);
6182 f = XFRAME (w->frame);
6184 if (FRAME_WINDOW_P (f))
6186 int old_dy = w->vscroll;
6188 w->vscroll = - (NILP (pixels_p)
6189 ? FRAME_LINE_HEIGHT (f) * XFLOATINT (vscroll)
6190 : XFLOATINT (vscroll));
6191 w->vscroll = min (w->vscroll, 0);
6193 if (w->vscroll != old_dy)
6195 /* Adjust glyph matrix of the frame if the virtual display
6196 area becomes larger than before. */
6197 if (w->vscroll < 0 && w->vscroll < old_dy)
6198 adjust_glyphs (f);
6200 /* Prevent redisplay shortcuts. */
6201 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
6205 return Fwindow_vscroll (window, pixels_p);
6209 /* Call FN for all leaf windows on frame F. FN is called with the
6210 first argument being a pointer to the leaf window, and with
6211 additional argument USER_DATA. Stops when FN returns 0. */
6213 static void
6214 foreach_window (struct frame *f, int (*fn) (struct window *, void *),
6215 void *user_data)
6217 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
6218 if (WINDOWP (FRAME_ROOT_WINDOW (f)))
6219 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f)), fn, user_data);
6223 /* Helper function for foreach_window. Call FN for all leaf windows
6224 reachable from W. FN is called with the first argument being a
6225 pointer to the leaf window, and with additional argument USER_DATA.
6226 Stop when FN returns 0. Value is 0 if stopped by FN. */
6228 static int
6229 foreach_window_1 (struct window *w, int (*fn) (struct window *, void *), void *user_data)
6231 int cont;
6233 for (cont = 1; w && cont;)
6235 if (!NILP (w->hchild))
6236 cont = foreach_window_1 (XWINDOW (w->hchild), fn, user_data);
6237 else if (!NILP (w->vchild))
6238 cont = foreach_window_1 (XWINDOW (w->vchild), fn, user_data);
6239 else
6240 cont = fn (w, user_data);
6242 w = NILP (w->next) ? 0 : XWINDOW (w->next);
6245 return cont;
6249 /* Freeze or unfreeze the window start of W unless it is a
6250 mini-window or the selected window. FREEZE_P non-null means freeze
6251 the window start. */
6253 static int
6254 freeze_window_start (struct window *w, void *freeze_p)
6256 if (MINI_WINDOW_P (w)
6257 || (WINDOWP (selected_window) /* Can be nil in corner cases. */
6258 && (w == XWINDOW (selected_window)
6259 || (MINI_WINDOW_P (XWINDOW (selected_window))
6260 && ! NILP (Vminibuf_scroll_window)
6261 && w == XWINDOW (Vminibuf_scroll_window)))))
6262 freeze_p = NULL;
6264 w->frozen_window_start_p = freeze_p != NULL;
6265 return 1;
6269 /* Freeze or unfreeze the window starts of all leaf windows on frame
6270 F, except the selected window and a mini-window. FREEZE_P non-zero
6271 means freeze the window start. */
6273 void
6274 freeze_window_starts (struct frame *f, int freeze_p)
6276 foreach_window (f, freeze_window_start, (void *) (freeze_p ? f : 0));
6280 /***********************************************************************
6281 Initialization
6282 ***********************************************************************/
6284 /* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2
6285 describe the same state of affairs. This is used by Fequal.
6287 ignore_positions non-zero means ignore non-matching scroll positions
6288 and the like.
6290 This ignores a couple of things like the dedicatedness status of
6291 window, combination_limit and the like. This might have to be
6292 fixed. */
6295 compare_window_configurations (Lisp_Object configuration1, Lisp_Object configuration2, int ignore_positions)
6297 register struct save_window_data *d1, *d2;
6298 struct Lisp_Vector *sws1, *sws2;
6299 ptrdiff_t i;
6301 CHECK_WINDOW_CONFIGURATION (configuration1);
6302 CHECK_WINDOW_CONFIGURATION (configuration2);
6304 d1 = (struct save_window_data *) XVECTOR (configuration1);
6305 d2 = (struct save_window_data *) XVECTOR (configuration2);
6306 sws1 = XVECTOR (d1->saved_windows);
6307 sws2 = XVECTOR (d2->saved_windows);
6309 /* Frame settings must match. */
6310 if (d1->frame_cols != d2->frame_cols
6311 || d1->frame_lines != d2->frame_lines
6312 || d1->frame_menu_bar_lines != d2->frame_menu_bar_lines
6313 || !EQ (d1->selected_frame, d2->selected_frame)
6314 || !EQ (d1->current_buffer, d2->current_buffer)
6315 || (!ignore_positions
6316 && (!EQ (d1->minibuf_scroll_window, d2->minibuf_scroll_window)
6317 || !EQ (d1->minibuf_selected_window, d2->minibuf_selected_window)))
6318 || !EQ (d1->focus_frame, d2->focus_frame)
6319 /* Verify that the two configurations have the same number of windows. */
6320 || sws1->header.size != sws2->header.size)
6321 return 0;
6323 for (i = 0; i < sws1->header.size; i++)
6325 struct saved_window *sw1, *sw2;
6327 sw1 = SAVED_WINDOW_N (sws1, i);
6328 sw2 = SAVED_WINDOW_N (sws2, i);
6330 if (
6331 /* The "current" windows in the two configurations must
6332 correspond to each other. */
6333 EQ (d1->current_window, sw1->window)
6334 != EQ (d2->current_window, sw2->window)
6335 /* Windows' buffers must match. */
6336 || !EQ (sw1->buffer, sw2->buffer)
6337 || !EQ (sw1->left_col, sw2->left_col)
6338 || !EQ (sw1->top_line, sw2->top_line)
6339 || !EQ (sw1->total_cols, sw2->total_cols)
6340 || !EQ (sw1->total_lines, sw2->total_lines)
6341 || !EQ (sw1->display_table, sw2->display_table)
6342 /* The next two disjuncts check the window structure for
6343 equality. */
6344 || !EQ (sw1->parent, sw2->parent)
6345 || !EQ (sw1->prev, sw2->prev)
6346 || (!ignore_positions
6347 && (!EQ (sw1->hscroll, sw2->hscroll)
6348 || !EQ (sw1->min_hscroll, sw2->min_hscroll)
6349 || !EQ (sw1->start_at_line_beg, sw2->start_at_line_beg)
6350 || NILP (Fequal (sw1->start, sw2->start))
6351 || NILP (Fequal (sw1->pointm, sw2->pointm))
6352 || NILP (Fequal (sw1->mark, sw2->mark))))
6353 || !EQ (sw1->left_margin_cols, sw2->left_margin_cols)
6354 || !EQ (sw1->right_margin_cols, sw2->right_margin_cols)
6355 || !EQ (sw1->left_fringe_width, sw2->left_fringe_width)
6356 || !EQ (sw1->right_fringe_width, sw2->right_fringe_width)
6357 || !EQ (sw1->fringes_outside_margins, sw2->fringes_outside_margins)
6358 || !EQ (sw1->scroll_bar_width, sw2->scroll_bar_width)
6359 || !EQ (sw1->vertical_scroll_bar_type, sw2->vertical_scroll_bar_type))
6360 return 0;
6363 return 1;
6366 DEFUN ("compare-window-configurations", Fcompare_window_configurations,
6367 Scompare_window_configurations, 2, 2, 0,
6368 doc: /* Compare two window configurations as regards the structure of windows.
6369 This function ignores details such as the values of point and mark
6370 and scrolling positions. */)
6371 (Lisp_Object x, Lisp_Object y)
6373 if (compare_window_configurations (x, y, 1))
6374 return Qt;
6375 return Qnil;
6378 void
6379 init_window_once (void)
6381 struct frame *f = make_initial_frame ();
6382 XSETFRAME (selected_frame, f);
6383 Vterminal_frame = selected_frame;
6384 minibuf_window = f->minibuffer_window;
6385 selected_window = f->selected_window;
6386 last_nonminibuf_frame = f;
6388 window_initialized = 1;
6391 void
6392 init_window (void)
6394 Vwindow_list = Qnil;
6397 void
6398 syms_of_window (void)
6400 DEFSYM (Qscroll_up, "scroll-up");
6401 DEFSYM (Qscroll_down, "scroll-down");
6402 DEFSYM (Qscroll_command, "scroll-command");
6404 Fput (Qscroll_up, Qscroll_command, Qt);
6405 Fput (Qscroll_down, Qscroll_command, Qt);
6407 DEFSYM (Qwindow_configuration_change_hook, "window-configuration-change-hook");
6408 DEFSYM (Qwindowp, "windowp");
6409 DEFSYM (Qwindow_configuration_p, "window-configuration-p");
6410 DEFSYM (Qwindow_live_p, "window-live-p");
6411 DEFSYM (Qwindow_deletable_p, "window-deletable-p");
6412 DEFSYM (Qdelete_window, "delete-window");
6413 DEFSYM (Qwindow_resize_root_window, "window--resize-root-window");
6414 DEFSYM (Qwindow_resize_root_window_vertically, "window--resize-root-window-vertically");
6415 DEFSYM (Qsafe, "safe");
6416 DEFSYM (Qdisplay_buffer, "display-buffer");
6417 DEFSYM (Qreplace_buffer_in_windows, "replace-buffer-in-windows");
6418 DEFSYM (Qrecord_window_buffer, "record-window-buffer");
6419 DEFSYM (Qget_mru_window, "get-mru-window");
6420 DEFSYM (Qtemp_buffer_show_hook, "temp-buffer-show-hook");
6421 DEFSYM (Qabove, "above");
6422 DEFSYM (Qbelow, "below");
6423 DEFSYM (Qauto_buffer_name, "auto-buffer-name");
6425 staticpro (&Vwindow_list);
6427 minibuf_selected_window = Qnil;
6428 staticpro (&minibuf_selected_window);
6430 window_scroll_pixel_based_preserve_x = -1;
6431 window_scroll_pixel_based_preserve_y = -1;
6432 window_scroll_preserve_hpos = -1;
6433 window_scroll_preserve_vpos = -1;
6435 DEFVAR_LISP ("temp-buffer-show-function", Vtemp_buffer_show_function,
6436 doc: /* Non-nil means call as function to display a help buffer.
6437 The function is called with one argument, the buffer to be displayed.
6438 Used by `with-output-to-temp-buffer'.
6439 If this function is used, then it must do the entire job of showing
6440 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6441 Vtemp_buffer_show_function = Qnil;
6443 DEFVAR_LISP ("minibuffer-scroll-window", Vminibuf_scroll_window,
6444 doc: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6445 Vminibuf_scroll_window = Qnil;
6447 DEFVAR_BOOL ("mode-line-in-non-selected-windows", mode_line_in_non_selected_windows,
6448 doc: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6449 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6450 is displayed in the `mode-line' face. */);
6451 mode_line_in_non_selected_windows = 1;
6453 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer,
6454 doc: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6455 Vother_window_scroll_buffer = Qnil;
6457 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p,
6458 doc: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
6459 auto_window_vscroll_p = 1;
6461 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines,
6462 doc: /* Number of lines of continuity when scrolling by screenfuls. */);
6463 next_screen_context_lines = 2;
6465 DEFVAR_LISP ("scroll-preserve-screen-position",
6466 Vscroll_preserve_screen_position,
6467 doc: /* Controls if scroll commands move point to keep its screen position unchanged.
6468 A value of nil means point does not keep its screen position except
6469 at the scroll margin or window boundary respectively.
6470 A value of t means point keeps its screen position if the scroll
6471 command moved it vertically out of the window, e.g. when scrolling
6472 by full screens.
6473 Any other value means point always keeps its screen position.
6474 Scroll commands should have the `scroll-command' property
6475 on their symbols to be controlled by this variable. */);
6476 Vscroll_preserve_screen_position = Qnil;
6478 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type,
6479 doc: /* Type of marker to use for `window-point'. */);
6480 Vwindow_point_insertion_type = Qnil;
6482 DEFVAR_LISP ("window-configuration-change-hook",
6483 Vwindow_configuration_change_hook,
6484 doc: /* Functions to call when window configuration changes.
6485 The buffer-local part is run once per window, with the relevant window
6486 selected; while the global part is run only once for the modified frame,
6487 with the relevant frame selected. */);
6488 Vwindow_configuration_change_hook = Qnil;
6490 DEFVAR_LISP ("recenter-redisplay", Vrecenter_redisplay,
6491 doc: /* If non-nil, then the `recenter' command with a nil argument
6492 will redraw the entire frame; the special value `tty' causes the
6493 frame to be redrawn only if it is a tty frame. */);
6494 Vrecenter_redisplay = Qtty;
6496 DEFVAR_LISP ("window-combination-resize", Vwindow_combination_resize,
6497 doc: /* Non-nil means resize window combinations proportionally.
6498 If this variable is nil, splitting a window gets the entire screen space
6499 for displaying the new window from the window to split. Deleting and
6500 resizing a window preferably resizes one adjacent window only.
6502 If this variable is non-nil, splitting a window tries to get the space
6503 proportionally from all windows in the same combination. This also
6504 allows to split a window that is otherwise too small or of fixed size.
6505 Resizing and deleting a window proportionally resize all windows in the
6506 same combination.
6508 This variable takes no effect if `window-combination-limit' is non-nil. */);
6509 Vwindow_combination_resize = Qnil;
6511 DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit,
6512 doc: /* Non-nil means splitting a window makes a new parent window.
6513 If this variable is nil, splitting a window will create a new parent
6514 window only if the window has no parent window or the window shall
6515 become a combination orthogonal to the one it is part of.
6517 If this variable is t, splitting a window always creates a new parent
6518 window. If all splits behave this way, each frame's window tree is a
6519 binary tree and every window but the frame's root window has exactly one
6520 sibling.
6522 Other values are reserved for future use.
6524 The value of this variable is also assigned to the combination-limit
6525 status of the new parent window. The combination-limit status of a
6526 window can be retrieved via the function `window-combination-limit' and
6527 altered by the function `set-window-combination-limit'. */);
6528 Vwindow_combination_limit = Qnil;
6530 defsubr (&Sselected_window);
6531 defsubr (&Sminibuffer_window);
6532 defsubr (&Swindow_minibuffer_p);
6533 defsubr (&Swindowp);
6534 defsubr (&Swindow_live_p);
6535 defsubr (&Swindow_frame);
6536 defsubr (&Sframe_root_window);
6537 defsubr (&Sframe_first_window);
6538 defsubr (&Sframe_selected_window);
6539 defsubr (&Sset_frame_selected_window);
6540 defsubr (&Spos_visible_in_window_p);
6541 defsubr (&Swindow_line_height);
6542 defsubr (&Swindow_buffer);
6543 defsubr (&Swindow_parent);
6544 defsubr (&Swindow_top_child);
6545 defsubr (&Swindow_left_child);
6546 defsubr (&Swindow_next_sibling);
6547 defsubr (&Swindow_prev_sibling);
6548 defsubr (&Swindow_combination_limit);
6549 defsubr (&Sset_window_combination_limit);
6550 defsubr (&Swindow_use_time);
6551 defsubr (&Swindow_top_line);
6552 defsubr (&Swindow_left_column);
6553 defsubr (&Swindow_total_height);
6554 defsubr (&Swindow_total_width);
6555 defsubr (&Swindow_normal_size);
6556 defsubr (&Swindow_new_total);
6557 defsubr (&Swindow_new_normal);
6558 defsubr (&Sset_window_new_total);
6559 defsubr (&Sset_window_new_normal);
6560 defsubr (&Swindow_resize_apply);
6561 defsubr (&Swindow_body_height);
6562 defsubr (&Swindow_body_width);
6563 defsubr (&Swindow_hscroll);
6564 defsubr (&Sset_window_hscroll);
6565 defsubr (&Swindow_redisplay_end_trigger);
6566 defsubr (&Sset_window_redisplay_end_trigger);
6567 defsubr (&Swindow_edges);
6568 defsubr (&Swindow_pixel_edges);
6569 defsubr (&Swindow_absolute_pixel_edges);
6570 defsubr (&Swindow_inside_edges);
6571 defsubr (&Swindow_inside_pixel_edges);
6572 defsubr (&Swindow_inside_absolute_pixel_edges);
6573 defsubr (&Scoordinates_in_window_p);
6574 defsubr (&Swindow_at);
6575 defsubr (&Swindow_point);
6576 defsubr (&Swindow_start);
6577 defsubr (&Swindow_end);
6578 defsubr (&Sset_window_point);
6579 defsubr (&Sset_window_start);
6580 defsubr (&Swindow_dedicated_p);
6581 defsubr (&Sset_window_dedicated_p);
6582 defsubr (&Swindow_display_table);
6583 defsubr (&Sset_window_display_table);
6584 defsubr (&Snext_window);
6585 defsubr (&Sprevious_window);
6586 defsubr (&Sget_buffer_window);
6587 defsubr (&Sdelete_other_windows_internal);
6588 defsubr (&Sdelete_window_internal);
6589 defsubr (&Sresize_mini_window_internal);
6590 defsubr (&Sset_window_buffer);
6591 defsubr (&Srun_window_configuration_change_hook);
6592 defsubr (&Sselect_window);
6593 defsubr (&Sforce_window_update);
6594 defsubr (&Stemp_output_buffer_show);
6595 defsubr (&Ssplit_window_internal);
6596 defsubr (&Sscroll_up);
6597 defsubr (&Sscroll_down);
6598 defsubr (&Sscroll_left);
6599 defsubr (&Sscroll_right);
6600 defsubr (&Sother_window_for_scrolling);
6601 defsubr (&Sscroll_other_window);
6602 defsubr (&Sminibuffer_selected_window);
6603 defsubr (&Srecenter);
6604 defsubr (&Swindow_text_height);
6605 defsubr (&Smove_to_window_line);
6606 defsubr (&Swindow_configuration_p);
6607 defsubr (&Swindow_configuration_frame);
6608 defsubr (&Sset_window_configuration);
6609 defsubr (&Scurrent_window_configuration);
6610 defsubr (&Sset_window_margins);
6611 defsubr (&Swindow_margins);
6612 defsubr (&Sset_window_fringes);
6613 defsubr (&Swindow_fringes);
6614 defsubr (&Sset_window_scroll_bars);
6615 defsubr (&Swindow_scroll_bars);
6616 defsubr (&Swindow_vscroll);
6617 defsubr (&Sset_window_vscroll);
6618 defsubr (&Scompare_window_configurations);
6619 defsubr (&Swindow_list);
6620 defsubr (&Swindow_list_1);
6621 defsubr (&Swindow_prev_buffers);
6622 defsubr (&Sset_window_prev_buffers);
6623 defsubr (&Swindow_next_buffers);
6624 defsubr (&Sset_window_next_buffers);
6625 defsubr (&Swindow_parameters);
6626 defsubr (&Swindow_parameter);
6627 defsubr (&Sset_window_parameter);
6630 void
6631 keys_of_window (void)
6633 initial_define_key (control_x_map, '<', "scroll-left");
6634 initial_define_key (control_x_map, '>', "scroll-right");
6636 initial_define_key (global_map, Ctl ('V'), "scroll-up-command");
6637 initial_define_key (meta_map, Ctl ('V'), "scroll-other-window");
6638 initial_define_key (meta_map, 'v', "scroll-down-command");